@typecad/framework-zephyr 1.0.0-alpha.13 → 1.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +22 -35
  2. package/dist/as-built.d.ts +33 -0
  3. package/dist/as-built.js +188 -0
  4. package/dist/async/timer-polyfill.js +1 -1
  5. package/dist/boardgen.d.ts +128 -0
  6. package/dist/boardgen.js +1366 -0
  7. package/dist/chips/board-overrides.d.ts +7 -0
  8. package/dist/chips/board-overrides.js +11 -0
  9. package/dist/chips/controllers.d.ts +28 -8
  10. package/dist/chips/controllers.js +49 -12
  11. package/dist/chips/esp32s3.js +49 -0
  12. package/dist/chips/index.d.ts +6 -12
  13. package/dist/chips/index.js +18 -34
  14. package/dist/chips/resolve.d.ts +16 -2
  15. package/dist/chips/resolve.js +298 -15
  16. package/dist/chips/soc/.d.ts +2 -0
  17. package/dist/chips/soc/.js +129 -0
  18. package/dist/chips/soc/esp32.d.ts +2 -0
  19. package/dist/chips/soc/esp32.js +120 -0
  20. package/dist/chips/soc/esp32c3.d.ts +2 -0
  21. package/dist/chips/soc/esp32c3.js +90 -0
  22. package/dist/chips/soc/esp32c6.d.ts +2 -0
  23. package/dist/chips/soc/esp32c6.js +109 -0
  24. package/dist/chips/soc/esp32s3.d.ts +2 -0
  25. package/dist/chips/soc/esp32s3.js +189 -0
  26. package/dist/chips/soc/index.d.ts +2 -0
  27. package/dist/chips/soc/index.js +23 -0
  28. package/dist/chips/soc/nrf52840.d.ts +2 -0
  29. package/dist/chips/soc/nrf52840.js +130 -0
  30. package/dist/chips/soc/rp2040.d.ts +2 -0
  31. package/dist/chips/soc/rp2040.js +141 -0
  32. package/dist/chips/soc/rp2350a.d.ts +2 -0
  33. package/dist/chips/soc/rp2350a.js +145 -0
  34. package/dist/chips/soc/samd21g18a.d.ts +2 -0
  35. package/dist/chips/soc/samd21g18a.js +143 -0
  36. package/dist/chips/soc/stm32f411xe.d.ts +2 -0
  37. package/dist/chips/soc/stm32f411xe.js +251 -0
  38. package/dist/chips/types.d.ts +382 -12
  39. package/dist/chips/xiao-ble.js +33 -0
  40. package/dist/display/profiles.js +1 -1
  41. package/dist/doctor.js +38 -4
  42. package/dist/dt-config/custom-board.d.ts +23 -0
  43. package/dist/dt-config/custom-board.js +227 -0
  44. package/dist/dt-config/kconfig.d.ts +83 -1
  45. package/dist/dt-config/kconfig.js +116 -27
  46. package/dist/dt-config/overlay.js +623 -18
  47. package/dist/framework.manifest.d.ts +20 -30
  48. package/dist/framework.manifest.js +124 -178
  49. package/dist/index.d.ts +4 -1
  50. package/dist/index.js +8 -2
  51. package/dist/lowering/adc.d.ts +26 -5
  52. package/dist/lowering/adc.js +137 -31
  53. package/dist/lowering/ble.js +31 -28
  54. package/dist/lowering/dac.js +9 -9
  55. package/dist/lowering/fs.js +18 -10
  56. package/dist/lowering/gpio.d.ts +2 -0
  57. package/dist/lowering/gpio.js +90 -10
  58. package/dist/lowering/http.js +39 -14
  59. package/dist/lowering/hwtimer.d.ts +4 -0
  60. package/dist/lowering/hwtimer.js +35 -10
  61. package/dist/lowering/i2c.js +46 -54
  62. package/dist/lowering/index.d.ts +5 -5
  63. package/dist/lowering/index.js +15 -16
  64. package/dist/lowering/interrupts.d.ts +22 -5
  65. package/dist/lowering/interrupts.js +104 -22
  66. package/dist/lowering/mqtt.js +12 -6
  67. package/dist/lowering/power.js +0 -4
  68. package/dist/lowering/preferences.js +49 -77
  69. package/dist/lowering/pulse.js +5 -36
  70. package/dist/lowering/pwm.d.ts +32 -3
  71. package/dist/lowering/pwm.js +105 -17
  72. package/dist/lowering/random.js +3 -3
  73. package/dist/lowering/sensor.d.ts +37 -0
  74. package/dist/lowering/sensor.js +119 -0
  75. package/dist/lowering/spi.d.ts +12 -0
  76. package/dist/lowering/spi.js +65 -40
  77. package/dist/lowering/thread.d.ts +14 -0
  78. package/dist/lowering/thread.js +55 -0
  79. package/dist/lowering/timing.js +20 -46
  80. package/dist/lowering/tone.js +18 -5
  81. package/dist/lowering/uart.d.ts +13 -0
  82. package/dist/lowering/uart.js +72 -51
  83. package/dist/lowering/usb.d.ts +34 -0
  84. package/dist/lowering/usb.js +206 -0
  85. package/dist/lowering/wdt.d.ts +1 -1
  86. package/dist/lowering/wdt.js +17 -7
  87. package/dist/lowering/wifi.d.ts +3 -2
  88. package/dist/lowering/wifi.js +120 -111
  89. package/dist/sdk/board-catalog-sync.d.ts +16 -0
  90. package/dist/sdk/board-catalog-sync.js +41 -0
  91. package/dist/sdk/board-data.generated.d.ts +2 -0
  92. package/dist/sdk/board-data.generated.js +4 -0
  93. package/dist/sdk/catalog-walker.d.ts +90 -0
  94. package/dist/sdk/catalog-walker.js +682 -0
  95. package/dist/sdk/dts-reader.d.ts +83 -0
  96. package/dist/sdk/dts-reader.js +596 -0
  97. package/dist/strategy.d.ts +136 -17
  98. package/dist/strategy.js +881 -212
  99. package/dist/toolchain/bossac-touch.d.ts +18 -0
  100. package/dist/toolchain/bossac-touch.js +88 -0
  101. package/dist/toolchain/compat.d.ts +2 -2
  102. package/dist/toolchain/compat.js +8 -3
  103. package/dist/toolchain/debug-config.d.ts +21 -26
  104. package/dist/toolchain/debug-config.js +212 -72
  105. package/dist/toolchain/env-check.d.ts +4 -4
  106. package/dist/toolchain/env-check.js +5 -5
  107. package/dist/toolchain/index.d.ts +66 -1
  108. package/dist/toolchain/index.js +713 -58
  109. package/dist/toolchain/scaffold.d.ts +9 -0
  110. package/dist/toolchain/scaffold.js +84 -7
  111. package/dist/toolchain/west-discover.d.ts +8 -1
  112. package/dist/toolchain/west-discover.js +19 -6
  113. package/dist/toolchain/west-spawn.js +17 -5
  114. package/installer/CHANGELOG.md +473 -0
  115. package/installer/README.md +328 -0
  116. package/installer/environment.yml +46 -0
  117. package/installer/etc/conda/activate.d/zephyr.bat +7 -0
  118. package/installer/etc/conda/activate.d/zephyr.ps1 +12 -0
  119. package/installer/etc/conda/activate.d/zephyr.sh +20 -0
  120. package/installer/etc/conda/deactivate.d/zephyr.bat +6 -0
  121. package/installer/etc/conda/deactivate.d/zephyr.ps1 +6 -0
  122. package/installer/etc/conda/deactivate.d/zephyr.sh +4 -0
  123. package/installer/install.mjs +580 -0
  124. package/installer/install.ps1 +619 -0
  125. package/installer/install.sh +310 -0
  126. package/installer/lib/detect-platform.sh +62 -0
  127. package/installer/lib/fetch-sdk.sh +304 -0
  128. package/installer/lib/init-workspace.sh +153 -0
  129. package/installer/lib/write-activation.sh +76 -0
  130. package/installer/patches/tfm-c-include-separators.patch +19 -0
  131. package/installer/patches/zephyr-tfm-nordic-zephyr-include.patch +24 -0
  132. package/installer/templates/project/.typecad/activate-zephyr.ps1 +31 -0
  133. package/installer/templates/project/.typecad/activate-zephyr.sh +31 -0
  134. package/installer/templates/project/.vscode/settings.json +30 -0
  135. package/installer/templates/project/README.md +58 -0
  136. package/installer/versions.env +110 -0
  137. package/package.json +16 -16
  138. package/src/as-built.ts +206 -0
  139. package/src/boardgen.ts +1428 -0
  140. package/src/chips/controllers.ts +61 -12
  141. package/src/chips/index.ts +35 -54
  142. package/src/chips/resolve.ts +316 -14
  143. package/src/chips/types.ts +388 -13
  144. package/src/display/profiles.ts +1 -1
  145. package/src/doctor.ts +110 -77
  146. package/src/dt-config/custom-board.ts +325 -0
  147. package/src/dt-config/kconfig.ts +177 -19
  148. package/src/dt-config/overlay.ts +1058 -450
  149. package/src/framework.manifest.ts +125 -178
  150. package/src/index.ts +57 -41
  151. package/src/lowering/adc.ts +222 -102
  152. package/src/lowering/ble.ts +32 -28
  153. package/src/lowering/dac.ts +82 -82
  154. package/src/lowering/fs.ts +18 -10
  155. package/src/lowering/gpio.ts +242 -152
  156. package/src/lowering/http.ts +512 -488
  157. package/src/lowering/hwtimer.ts +139 -101
  158. package/src/lowering/i2c.ts +116 -126
  159. package/src/lowering/index.ts +91 -93
  160. package/src/lowering/interrupts.ts +113 -21
  161. package/src/lowering/mqtt.ts +12 -6
  162. package/src/lowering/preferences.ts +327 -354
  163. package/src/lowering/pwm.ts +167 -74
  164. package/src/lowering/random.ts +3 -3
  165. package/src/lowering/sensor.ts +155 -0
  166. package/src/lowering/spi.ts +164 -124
  167. package/src/lowering/thread.ts +63 -0
  168. package/src/lowering/timing.ts +46 -72
  169. package/src/lowering/uart.ts +73 -51
  170. package/src/lowering/usb.ts +221 -0
  171. package/src/lowering/wdt.ts +95 -84
  172. package/src/lowering/wifi.ts +120 -111
  173. package/src/sdk/board-catalog-sync.ts +62 -0
  174. package/src/strategy.ts +888 -229
  175. package/src/toolchain/bossac-touch.ts +112 -0
  176. package/src/toolchain/compat.ts +8 -3
  177. package/src/toolchain/debug-config.ts +666 -522
  178. package/src/toolchain/env-check.ts +9 -9
  179. package/src/toolchain/index.ts +765 -44
  180. package/src/toolchain/scaffold.ts +81 -7
  181. package/src/toolchain/west-discover.ts +334 -316
  182. package/src/toolchain/west-spawn.ts +17 -5
  183. package/src/async/timer-polyfill.ts +0 -107
  184. package/src/chips/esp32.ts +0 -74
  185. package/src/chips/esp32s3.ts +0 -57
  186. package/src/chips/xiao-ble.ts +0 -70
  187. package/src/lowering/power.ts +0 -70
  188. package/src/lowering/pulse.ts +0 -93
  189. package/src/lowering/tone.ts +0 -60
  190. package/src/lowering/worker-backing.ts +0 -94
  191. package/src/lowering/worker.ts +0 -17
@@ -1,3 +1,33 @@
1
+ import { SENSOR_PART_INFO } from '@typecad/hal';
2
+
3
+ /** A sensor part's catalog facts, as the exceptions helper consumes them. */
4
+ interface SensorKconfigSource {
5
+ kconfig: readonly string[];
6
+ }
7
+
8
+ /**
9
+ * Apply the per-part Kconfig exceptions the generated catalog records, for
10
+ * exactly the parts the program constructs. Lines are CONFIG_<SYM>=<value>
11
+ * strings parsed into the map; a symbol the user set explicitly in
12
+ * zephyr.kconfig is left alone (scaffold.ts already skips user overrides for
13
+ * auto symbols, and Map.set idempotence covers the rest). The lookup is a
14
+ * parameter so tests can drive it with a synthetic catalog.
15
+ */
16
+ export function applySensorKconfigExceptions(
17
+ m: Map<string, string>,
18
+ parts: readonly { part: string }[] | undefined,
19
+ lookup: Readonly<Record<string, SensorKconfigSource>> = SENSOR_PART_INFO,
20
+ ): void {
21
+ if (!parts) return;
22
+ for (const sp of parts) {
23
+ for (const line of lookup[sp.part]?.kconfig ?? []) {
24
+ const eq = line.indexOf('=');
25
+ if (eq <= 0) continue;
26
+ m.set(line.slice(0, eq), line.slice(eq + 1));
27
+ }
28
+ }
29
+ }
30
+
1
31
  // ---------------------------------------------------------------------------
2
32
  // Kconfig fragment resolver — extracts the prj.conf symbol logic
3
33
  //
@@ -17,24 +47,77 @@ export interface KconfigUsage {
17
47
  usesI2c?: boolean;
18
48
  usesSpi?: boolean;
19
49
  usesUart?: boolean;
50
+ /** USB CDC-ACM serial used (usb.* ops). Selects the "next" USB device
51
+ * stack + CDC class; the class instances themselves are composed in the
52
+ * DT overlay and auto-default on once the node exists (assigning the
53
+ * class symbol keeps prj.conf explicit and survives DT-only probes). */
54
+ usesUsb?: boolean;
20
55
  usesWdt?: boolean;
21
56
  usesBle?: boolean;
22
57
  usesDisplay?: boolean;
23
- usesPower?: boolean;
24
58
  usesWifi?: boolean;
25
59
  usesHttp?: boolean;
26
60
  usesMqtt?: boolean;
27
61
  usesPreferences?: boolean;
28
62
  usesRandom?: boolean;
63
+ /** A printf-family format specifier with a float conversion (%f, %.2f, %e,
64
+ * …) appears in the emitted source — Zephyr's cbprintf only links float
65
+ * conversions with FP_SUPPORT (which itself needs the COMPLETE impl). */
66
+ usesFloatFormat?: boolean;
67
+ /** DT-bound sensor parts used (sensor.* ops — the generic catalog). The
68
+ * umbrella under which every driver sensor Kconfig lives (`if SENSOR`);
69
+ * the per-driver symbols default on from their DT node presence. */
70
+ usesSensor?: boolean;
71
+ /** Distinct constructed sensors — only the overlay generator consumes this
72
+ * (one DT child node per entry, on the given I2C controller index); prj.conf
73
+ * ignores it. Same adcReadPins/pwmUsedPins pattern. */
74
+ sensorParts?: readonly { part: string; busIndex: number; port: number; busKind: 'i2c' | 'spi'; spiHz?: number; spiMode?: number; alertPin?: number }[];
75
+ /** Distinct thin SPI targets (hal/spi-target.ts) — one DT child node per
76
+ * entry (no compatible — a raw spi_dt_spec peer), appended after sensor
77
+ * CS entries in the controller's merged cs-gpios. */
78
+ spiTargets?: readonly { busIndex: number; cs: number; hz?: number; mode?: number }[];
29
79
  /** Touch controller referenced (UI touch adapter emits DT_NODELABEL(ft6336u)
30
80
  * or DT_NODELABEL(xpt2046)). Selects the bus driver the node needs. */
31
81
  usesTouch?: boolean;
32
82
  /** Which touch controller the program uses — FT6336U rides I2C, XPT2046
33
83
  * rides the display's SPI bus. Only meaningful with usesTouch. */
34
84
  touchController?: 'ft6336u' | 'xpt2046';
85
+ /** The emitted shim carries the STM32F4 DBGMCU keep-SWD-alive init
86
+ * (__tc_stm32_dbgmcu token). Selects Zephyr's own "debugger attach in
87
+ * stop/sleep" init (sets DBG_STOP via the LL headers); the shim's raw
88
+ * register poke additionally covers DBG_SLEEP, which the Zephyr F4 path
89
+ * does not set. */
90
+ usesStm32DebugSleep?: boolean;
35
91
  /** PSRAM type ('opi' | 'quad') when the target board has PSRAM. Emits the
36
92
  * CONFIG_SPIRAM symbols so the ESP heap serves PSRAM for canvas allocations. */
37
93
  psram?: 'opi' | 'quad';
94
+ /** HAL pin numbers the program reads with adc.* — scanned from the emitted
95
+ * `__tc_adc<N>_setup()` calls at compile time. Only the overlay generator
96
+ * consumes this (to rewrite the ADC node's pinctrl-0 to the used channels
97
+ * on SoCs that need pad muxing, e.g. STM32); prj.conf ignores it. */
98
+ adcReadPins?: readonly number[];
99
+ /** HAL pin numbers the program drives with dac.* — scanned from the
100
+ * emitted lazy-setup guards (__tc_dact<pin>_done) at compile time. Only
101
+ * the overlay generator consumes this (the DAC node's pinctrl-0 lists
102
+ * the used channels); prj.conf ignores it. */
103
+ dacWritePins?: readonly number[];
104
+ /** HAL pin numbers the program drives with pwm.* — scanned from the
105
+ * emitted `__tc_pwm_*` spec references at compile time. Only the overlay
106
+ * generator consumes this (synthesized pwm-leds consumers + aliases are
107
+ * emitted per used pin, so the DT carries no dead channels); prj.conf
108
+ * ignores it. */
109
+ pwmUsedPins?: readonly number[];
110
+ /** Controller indexes per bus the program actually drives — scanned from
111
+ * the emitted `__tc_<bus><N>_dev` state blocks at compile time. The
112
+ * overlay enables only those controllers (an enabled-but-unused
113
+ * controller claims its default pins — e.g. i2c0's GP4/GP5 on the Pico —
114
+ * which a program using the OTHER controller may want as GPIO). Absent
115
+ * (prepare-time overlays, driver-API-only users like the display
116
+ * adapter) → every declared controller is enabled, preserving the old
117
+ * behavior. prj.conf ignores these. */
118
+ i2cUsedInstances?: readonly number[];
119
+ spiUsedInstances?: readonly number[];
120
+ uartUsedInstances?: readonly number[];
38
121
  }
39
122
 
40
123
  /**
@@ -55,11 +138,54 @@ export function resolveKconfigFragments(
55
138
  m.set('CONFIG_CONSOLE', 'y');
56
139
 
57
140
  if (usage.usesAdc) m.set('CONFIG_ADC', 'y');
141
+ // Sensors: only the umbrella — each in-tree driver is `default y` on its
142
+ // DT_HAS_<COMPAT>_ENABLED, so the overlay's child node enables the driver.
143
+ if (usage.usesSensor) m.set('CONFIG_SENSOR', 'y');
144
+ // The rare driver that is NOT DT-default-on: the catalog records its
145
+ // Kconfig lines (from the driver's own Kconfig) and they are applied for
146
+ // exactly the parts the program constructs. Empty for every in-tree part
147
+ // today — this path is insurance for the next exception.
148
+ applySensorKconfigExceptions(m, usage.sensorParts);
149
+ // Float formatting: cbprintf builds float conversions only under
150
+ // FP_SUPPORT, which depends on the COMPLETE implementation — without these,
151
+ // %f silently prints garbage instead of the value.
152
+ if (usage.usesFloatFormat) {
153
+ m.set('CONFIG_CBPRINTF_COMPLETE', 'y');
154
+ m.set('CONFIG_CBPRINTF_FP_SUPPORT', 'y');
155
+ }
58
156
  if (usage.usesPwm) m.set('CONFIG_PWM', 'y');
59
157
  if (usage.usesDac) m.set('CONFIG_DAC', 'y');
60
158
  if (usage.usesI2c) m.set('CONFIG_I2C', 'y');
61
159
  if (usage.usesSpi) m.set('CONFIG_SPI', 'y');
160
+ // USB CDC-ACM serial: the "next" USB device stack + the CDC-ACM class.
161
+ // Symbol names verified against Zephyr 4.3 (subsys/usb/device_next/Kconfig):
162
+ // - USB_DEVICE_STACK_NEXT is the new stack (selects UDC_DRIVER);
163
+ // USB_DEVICE_STACK is the LEGACY stack — deprecated in 4.3 (selects
164
+ // DEPRECATED) and its assignment is what trips the build.
165
+ // - USBD_CDC_ACM_CLASS is the class (note the USBD_ prefix — a bare
166
+ // CDC_ACM_CLASS is an undefined symbol). It depends on SERIAL +
167
+ // DT_HAS_ZEPHYR_CDC_ACM_UART_ENABLED (the overlay's cdc-acm-uart node)
168
+ // and selects UART_INTERRUPT_DRIVEN/RING_BUFFER itself; assigning it
169
+ // keeps prj.conf explicit.
170
+ // - UART_LINE_CTRL gates the driver's line_ctrl_get — usb.connected()
171
+ // polls DTR through it.
172
+ if (usage.usesUsb) {
173
+ m.set('CONFIG_USB_DEVICE_STACK_NEXT', 'y');
174
+ m.set('CONFIG_USBD_CDC_ACM_CLASS', 'y');
175
+ m.set('CONFIG_UART_LINE_CTRL', 'y');
176
+ m.set('CONFIG_SERIAL', 'y');
177
+ // The device presents a serial-number string descriptor sourced from
178
+ // hwinfo (the SoC's unique ID). Without it Windows keys the CDC devnode
179
+ // on the physical USB port: replugs reuse stale nodes and repeated flash
180
+ // cycles wedge them into permanent "access denied" opens. A serial makes
181
+ // the instance path identity-based — stable across ports, immune to the
182
+ // port-keyed ghost pool.
183
+ m.set('CONFIG_HWINFO', 'y');
184
+ }
62
185
  if (usage.usesWdt) m.set('CONFIG_WATCHDOG', 'y');
186
+ // STM32: keep the debugger attachable in sleep/stop (see the shim's
187
+ // DBGMCU init — this covers the Zephyr-side DBG_STOP bit via LL headers).
188
+ if (usage.usesStm32DebugSleep) m.set('CONFIG_STM32_ENABLE_DEBUG_SLEEP_STOP', 'y');
63
189
  // Hardware timers via the counter driver.
64
190
  if (usage.usesHwtimer) m.set('CONFIG_COUNTER', 'y');
65
191
  if (usage.usesDisplay) {
@@ -113,24 +239,19 @@ export function resolveKconfigFragments(
113
239
  m.set('CONFIG_SPIRAM_MODE_QUAD', 'y');
114
240
  }
115
241
  }
116
- // deep_sleep_pin wake needs PM + PM_DEVICE.
117
- if (usage.usesPower) {
118
- m.set('CONFIG_PM', 'y');
119
- m.set('CONFIG_PM_DEVICE', 'y');
120
- }
121
242
  if (usage.usesWifi) {
122
243
  // Master networking switch — every CONFIG_NET_* symbol depends on NETWORKING
123
244
  // (without it, Kconfig silently forces them all to n).
124
245
  m.set('CONFIG_NETWORKING', 'y');
125
246
  m.set('CONFIG_WIFI', 'y');
126
- m.set('CONFIG_WIFI_ESP32', 'y'); // ESP32-specific driver (sole WiFi target)
247
+ m.set('CONFIG_WIFI_ESP32', 'y'); // family-wide ESP32 driver (esp32/s3/c3/c6)
127
248
  m.set('CONFIG_NET_L2_ETHERNET', 'y');
128
249
  m.set('CONFIG_NET_IPV4', 'y');
129
250
  m.set('CONFIG_NET_UDP', 'y'); // transitive dep of NET_DHCPV4
130
251
  m.set('CONFIG_NET_DHCPV4', 'y');
131
252
  // NOT CONFIG_NET_CONFIG_SETTINGS: that runs net_config_init() at boot which
132
253
  // BLOCKS up to NET_CONFIG_INIT_TIMEOUT (default 30s) waiting for the iface
133
- // to come up — but our shim brings the iface up itself in setup() (connect),
254
+ // to come up — but our shim brings the iface up itself in main() (connect),
134
255
  // so net_config waits the full 30s, then the dual management of the same
135
256
  // iface crashes the driver. Our shim owns connectivity (net_mgmt connect/
136
257
  // disconnect + conn_mgr monitor for L4), exactly like the standalone Zephyr
@@ -215,13 +336,26 @@ export function resolveKconfigFragments(
215
336
  // server's RSA cert (rsa:2048) and is widely offered; add more ciphersuites
216
337
  // here to broaden server compatibility.
217
338
  m.set('CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256', 'y');
339
+ // Ciphersuites only *depend on* X509_CRT_PARSE_C (they don't select it) —
340
+ // without it sockets_tls.c compiles out mbedtls_x509_crt_parse and every
341
+ // pinned-CA handshake fails with EPERM at connect (the insecure path
342
+ // skips verification, so it works either way).
343
+ m.set('CONFIG_MBEDTLS_X509_CRT_PARSE_C', 'y');
344
+ // KNOWN LIMITATION on this Zephyr tree: pinned-CA (verified TLS) fails at
345
+ // connect — the tf-psa-crypto mbedTLS needs a wider symbol matrix
346
+ // (RSA public-key parse + PEM/DER glue) than the single-ciphersuite
347
+ // select pulls in, and forcing the extra symbols regresses the insecure
348
+ // path. insecure() HTTPS is fully verified; caCert() chain verification
349
+ // stays open until the upstream matrix is mapped.
218
350
  // Handshake/protocol buffers allocate from the mbedTLS heap; MBEDTLS_HEAP_SIZE
219
351
  // must hold ~2x MBEDTLS_SSL_MAX_CONTENT_LEN plus working state. 65000 fits on
220
352
  // the ESP32; mbedTLS requires the full libc and PEM (not DER) cert format.
221
353
  m.set('CONFIG_MBEDTLS_ENABLE_HEAP', 'y');
222
- m.set('CONFIG_MBEDTLS_HEAP_SIZE', '65000');
354
+ // 2x SSL_MAX_CONTENT_LEN record buffers + CA-chain parse state +
355
+ // handshake working memory. 65000 fit insecure-mode handshakes but the
356
+ // pinned-CA path (verification state) overflowed → EPERM at connect.
357
+ m.set('CONFIG_MBEDTLS_HEAP_SIZE', '100000');
223
358
  m.set('CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN', '16384');
224
- m.set('CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT', 'y');
225
359
  m.set('CONFIG_PSA_CRYPTO', 'y');
226
360
  m.set('CONFIG_REQUIRES_FULL_LIBC', 'y');
227
361
  // The http client + TLS handshake are stack-hungry; mirror the wifi bumps
@@ -244,6 +378,12 @@ export function resolveKconfigFragments(
244
378
  m.set('CONFIG_NET_SOCKETS', 'y');
245
379
  m.set('CONFIG_MQTT_LIB', 'y');
246
380
  m.set('CONFIG_MQTT_LIB_TLS', 'y');
381
+ // The shim getaddrinfo-resolves the broker host — without the DNS
382
+ // resolver linked, getaddrinfo fails numeric AND hostname lookups with
383
+ // EAI_FAIL even while plain HTTP (which selects DNS via its own block)
384
+ // works.
385
+ m.set('CONFIG_DNS_RESOLVER', 'y');
386
+ m.set('CONFIG_DNS_SERVER_IP_ADDRESSES', 'y');
247
387
  // NET_MAX_CONTEXTS / NET_MAX_CONN: same exhaustion risk as HTTP — sequential
248
388
  // connections linger after close. Give the broker session + headroom.
249
389
  m.set('CONFIG_NET_MAX_CONTEXTS', '16');
@@ -255,10 +395,23 @@ export function resolveKconfigFragments(
255
395
  m.set('CONFIG_MBEDTLS', 'y');
256
396
  m.set('CONFIG_MBEDTLS_BUILTIN', 'y');
257
397
  m.set('CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256', 'y');
398
+ // Ciphersuites only *depend on* X509_CRT_PARSE_C (they don't select it) —
399
+ // without it sockets_tls.c compiles out mbedtls_x509_crt_parse and every
400
+ // pinned-CA handshake fails with EPERM at connect (the insecure path
401
+ // skips verification, so it works either way).
402
+ m.set('CONFIG_MBEDTLS_X509_CRT_PARSE_C', 'y');
403
+ // KNOWN LIMITATION on this Zephyr tree: pinned-CA (verified TLS) fails at
404
+ // connect — the tf-psa-crypto mbedTLS needs a wider symbol matrix
405
+ // (RSA public-key parse + PEM/DER glue) than the single-ciphersuite
406
+ // select pulls in, and forcing the extra symbols regresses the insecure
407
+ // path. insecure() HTTPS is fully verified; caCert() chain verification
408
+ // stays open until the upstream matrix is mapped.
258
409
  m.set('CONFIG_MBEDTLS_ENABLE_HEAP', 'y');
259
- m.set('CONFIG_MBEDTLS_HEAP_SIZE', '65000');
410
+ // 2x SSL_MAX_CONTENT_LEN record buffers + CA-chain parse state +
411
+ // handshake working memory. 65000 fit insecure-mode handshakes but the
412
+ // pinned-CA path (verification state) overflowed → EPERM at connect.
413
+ m.set('CONFIG_MBEDTLS_HEAP_SIZE', '100000');
260
414
  m.set('CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN', '16384');
261
- m.set('CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT', 'y');
262
415
  m.set('CONFIG_PSA_CRYPTO', 'y');
263
416
  m.set('CONFIG_REQUIRES_FULL_LIBC', 'y');
264
417
  m.set('CONFIG_NET_TX_STACK_SIZE', '2048');
@@ -295,19 +448,24 @@ export function resolveKconfigFragments(
295
448
  m.set('CONFIG_FLASH_MAP', 'y');
296
449
  m.set('CONFIG_FILE_SYSTEM', 'y');
297
450
  m.set('CONFIG_FILE_SYSTEM_LITTLEFS', 'y');
451
+ // fs_mkfs (the lazy first-use format in the shim) is gated behind this —
452
+ // without it the mount path links fine but the format call is undefined.
453
+ m.set('CONFIG_FILE_SYSTEM_MKFS', 'y');
298
454
  }
299
455
  // usesUart: the board enables the console UART by default; the overlay (not
300
456
  // Kconfig) is where a UART node would be enabled, so no symbol here.
301
457
  // Random: <zephyr/random/random.h> sys_rand_get is backed by the random
302
- // generator subsystem. CONFIG_RANDOM_GENERATOR is the umbrella that selects a
303
- // working backend for the board (nRF52840 hardware RNG via the entropy
304
- // driver; QEMU/host → the test generator). CONFIG_ENTROPY_GENERATOR is its
305
- // hard dependency on hardware targets. Both default on for most boards, but
306
- // setting them explicitly keeps the symbol set honest and survives a board
307
- // whose defconfig leaves them off.
458
+ // generator subsystem's RNG_GENERATOR_CHOICE. There is no umbrella symbol
459
+ // CONFIG_RANDOM_GENERATOR is a phantom in 4.x (assigning an undefined symbol
460
+ // aborts the build). The choice defaults to the entropy-device generator
461
+ // when the board has a driver (ENTROPY_HAS_DRIVER: nRF52840, ESP32, …);
462
+ // RNG-less SoCs (STM32F411 has no hardware RNG) need
463
+ // CONFIG_TEST_RANDOM_GENERATOR to unlock the timer-clock fallback, which
464
+ // the choice then picks by default. Setting both keys gets the best
465
+ // available source per board.
308
466
  if (usage.usesRandom) {
309
467
  m.set('CONFIG_ENTROPY_GENERATOR', 'y');
310
- m.set('CONFIG_RANDOM_GENERATOR', 'y');
468
+ m.set('CONFIG_TEST_RANDOM_GENERATOR', 'y');
311
469
  }
312
470
 
313
471
  // System workqueue — bumped for worker-offload AND timer callbacks. The