Skip to content

Build the Elite II / C64 Ultimate control module (u64ctrl) with ESP-IDF 6.1.1 - #1028

Open
JC-000 wants to merge 18 commits into
GideonZ:masterfrom
JC-000:pr/idf6-u64ctrl
Open

JC-000 wants to merge 18 commits into
GideonZ:masterfrom
JC-000:pr/idf6-u64ctrl

Conversation

@JC-000

@JC-000 JC-000 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Base: master (3db34d2, which has #1012, #1027 and #1034). Commits 1 to 11 move the module to ESP-IDF 6, and commits 12 to 15 move it on to 6.1.1.

This is the first of three ESP-IDF 6 PRs, each built on the one before: this one (u64ctrl), then #996 (raw_u64), then #1029 (raw_c3, draft). If they are accepted, this one should merge first. #1027 (SSID and password terminators, in all three modules) is already on master.

It takes #1034's custom certificate bundle: sdkconfig keeps CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE=y, CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y and the path ca/cacert.pem, and tests/lib/u64ctrl_ca_test.py passes on this head.

Why move

The pin is ESP-IDF 6.1.1: espressif/idf:v6.1.1, by digest (sha256:2b4f966c37eaedc19542b0637a5f850b2eff9478d8e858192aa0073d92c2dc91). Its Mbed TLS is the same 4.1.1 commit as in 6.0.3 (espressif/mbedtls ce3f3485a121). The closed Wi-Fi libraries are newer than in 6.0.3; the PHY library is identical.

The move changes the toolchain of the whole module: its power, button and keepalive handling as well as its Wi-Fi. So the commits are split by behaviour change, and each one says what it keeps the same as 5.3.1.

The Wi-Fi recovery code from #1012 did not compile under mbedTLS 4, which has no public mbedtls/sha256.h and no mbedtls_pk_get_type(). The first commit ports it. A valid or an invalid manifest gives the same result as before; only crypto-library failures are reported differently. I read the rest of what #1012 added (recovery_trust.c, wifi_modem.c, and recovery.c apart from the streaming hash described below) for crypto API use and found none.

Commits

Commits 1 to 11 were written and first built against ESP-IDF 6.0.3, and their names say so. Commits 12 to 15 move the pin to 6.1.1; the head is what CI builds.

1. Build u64ctrl with ESP-IDF 6.0.3

This is one commit because none of its parts builds alone.

  • my_uart.c. uart_periph.h moved from soc/ to hal/, and uart_isr_handle_t is gone. These are the same two changes Build the U64 WiFi module firmware (raw_u64) with ESP-IDF 6.1.1 #996 makes for raw_u64.
  • CMakeLists.txt. Configure stops on an ESP-IDF older than 6.
  • sdkconfig. It was regenerated by idf.py build from the 5.3.1 file.
    • Values present in both versions are carried. Of the 1,498 options in the old file, 1,313 are still in the file at the head, and 8 of those changed value. Six are changes ESP-IDF 6 makes: the esptool before/after spelling (two options), the DHCP option length, the X509 trusted-certificate callback (ESP-IDF 6's cross-signed bundle check selects it), ESP_NETIF_RECEIVE_REPORT_ERRORS (forced on by ESP-IDF 6) and a read-only chip constant, SOC_CPU_WATCHPOINT_MAX_REGION_SIZE. Commits 2 and 10 set the other two, MBEDTLS_THREADING_C and ESP_WIFI_EXTRA_IRAM_OPT.
    • New options take ESP-IDF 6's defaults. Among them: picolibc replaces newlib, FreeRTOS and ring-buffer functions run from flash rather than IRAM (commit 7 puts them back), and WPA3-compatible mode is compiled in.
    • The brownout level and the 100 Hz tick are carried.
    • The certificate bundle lines from Trust Mozilla's current root list in u64ctrl's network recovery (fixes the emSign roots) #1034 are kept (default bundle off, custom bundle ca/cacert.pem), and tests/lib/u64ctrl_ca_test.py passes.
  • rpc_dispatch.h. The module version is the next minor above master's, so the updater installs the module. Renumber it at merge if you prefer. The updater only installs a newer module (update_u64ii.cc), so a module change numbered below this version would not be installed on units that have this one.
  • CI. It builds u64ctrl in espressif/idf:v6.1.1 (commit 12; commit 1 used 6.0.3), pinned by digest in $IDF6_IMAGE. raw_u64 and raw_c3 (U2+L) stay in my_docker_image and are untouched by this PR: their sources and sdkconfig files are unchanged, and they are built in the same image, now by target name (make esp32_raw_u64 esp32_raw_c3), so nothing is stranded. The ESP32 cache key names both images. README.txt and software/u64ctrl/README.md say how to build u64ctrl.
  • The recovery port (recovery_verify.c):
    • The key type comes from mbedtls_pk_get_key_type().
    • The manifest is hashed with psa_hash_compute().
    • psa_crypto_init() is always called.
    • A crypto library that fails to start is reported as a new result, RECOVERY_ERR_CRYPTO, not as a bad signature.
    • The signature is still checked by mbedtls_pk_verify() on a DER ECDSA signature.
  • The download hash. The streaming hash of a downloaded file moves out of recovery.c into recovery_hash_*(), so the host test can run it. The checks, their order and the log line for a differing hash are as before.
  • Result codes. Two are added after the existing ones.

2. Lock the mbedTLS key store (MBEDTLS_THREADING_C)

On mbedTLS 4, PSA key slots are mutex-protected only with this option. It is ESP-IDF 6's default, but the regenerated sdkconfig had carried 5.3.1's "not set". The Wi-Fi supplicant now imports and destroys PSA keys.

3. Keep dropping Wi-Fi packets quietly when there is no UART buffer

On 5.3.1 the driver was told OK after the packet was freed. On 6, esp_netif_receive() passes the error on. The hook now frees the packet and returns ERR_OK, so this path behaves as before.

4. Keep the pull-ups on the UART RX and CTS pins

5.3.1's uart_set_pin() put a pull-up on RXD and CTS. 6's never touches pulls, so RXD could stay pulled down while the FPGA configures and read as a break. One helper sets the pull-ups and then routes the pins, in the 5.3.1 order, and both call sites use it.

5. Stop UART1 flow control in the brownout interrupt

ESP-IDF 6's brownout handler waits for every enabled UART to drain before it resets. 5.3.1 reset at once. When the FPGA loses power, CTS idles high, so the wait ran into the 300 ms interrupt watchdog and ended in a panic reset instead of a brownout reset. A brownout callback, which runs in IRAM, now turns CTS flow control off first.

6. Test the keys the module ships with

The host test used only keys of its own. Now it also checks:

  • every key in recovery_trusted_keys loads as an EC public key;
  • a spare ships next to the main key;
  • no two shipped keys are the same;
  • a manifest signed by a key placed behind all of them is verified.

7. Keep FreeRTOS and the ring buffer in IRAM

ESP-IDF 6 moved the FreeRTOS queue and task functions and the ring buffer to flash by default (CONFIG_FREERTOS_IN_IRAM and CONFIG_RINGBUF_IN_IRAM are off). 5.3.1 had them in IRAM. Every frame passes them in both directions, so each call can wait on a flash cache miss. This commit sets both options, which are the only two lines it changes. On 6.0.3 it cost 12,140 bytes of shared IRAM/DRAM and took 13,024 bytes out of flash code; the totals at the head are under "Memory".

The same change on the U64 Elite's ESP32 module (#996) brought the WiFi write latency back to the 5.3.1 range on a quiet channel. For this module, see "Tested on hardware": two idle runs that are not worse than master's, with no speed claim.

8. Run the UART interrupt and dispatch on core 1, out of flash

The WiFi driver runs on core 0. esp_intr_alloc() binds an interrupt to the core it is called on, so my_uart_init() now runs from a short task pinned to core 1, which keeps the UART interrupt off the core (and cache) the WiFi driver uses. my_uart, cmd_buffer, hacked_recv(), dispatch() and cmd_send_eth_packet() go to IRAM with a linker fragment (main/linker.lf, noflash). The interrupt flags stay 0, so the interrupt stays masked while the flash cache is off. The dispatch task is pinned to core 1 at priority 19, where the interrupt feeds it. The init semaphore and the task create are checked.

Because the whole of my_uart is in IRAM, my_uart_connect_pins() is too. It runs from task context and calls flash functions, which is fine. The brownout callback was already in IRAM; it is now registered from the core-1 task, and the brownout interrupt is a separate system interrupt that does not depend on the core. The FPGA pin routing and the brownout code are otherwise unchanged. About 3.4 KB of shared IRAM/DRAM.

9. Lower the UART FIFO thresholds

Receive 120 to 64, transmit 10 to 64. The flow-control threshold stays at 122. The time budget between the receive interrupt and the sender being stopped goes from 2 bytes to 58 bytes of line time; the margin after RTS is raised stays 6 bytes. I chose the values from the interrupt timing, not from a sweep. The receive interrupt fires about twice as often, now on core 1. No memory cost.

10. Keep more of the WiFi driver in IRAM (CONFIG_ESP_WIFI_EXTRA_IRAM_OPT)

One sdkconfig line. It moves the WiFi transmit path (ieee80211_output_do, esf_buf_alloc_dynamic) and some WiFi library code to IRAM. About 4.6 KB.

11. Run the netif, pbuf and heap path from IRAM

noflash entries for the per-frame functions between the WiFi driver and the UART: esp_netif_transmit/receive/free_rx_buffer, wlanif_input, esp_pbuf_allocate/free, pbuf_free, pbuf_alloced_custom, pbuf_init_alloced_pbuf, wifi_transmit, wifi_free, mem_malloc, mem_free, sys_arch_protect/unprotect, sys_mutex_lock/unlock (sys_arch_protect calls sys_mutex_lock, so moving only the first would not help) and esp_wifi_internal_free_rx_buffer. I checked the linked ELF with objdump: none of these functions calls into flash on the packet path. What stays in flash is not per packet: the command handlers, uart_hal_rxfifo_rst on a FIFO overflow (that interrupt is not enabled), and esp_event_post behind a runtime flag that is off.

12. Build the control module with ESP-IDF 6.1.1

CI and the build instructions move from the 6.0.3 image to espressif/idf:v6.1.1, pinned by digest. sdkconfig is regenerated by 6.1.1. Every value the module sets is unchanged, including FREERTOS_IN_IRAM, RINGBUF_IN_IRAM and ESP_WIFI_EXTRA_IRAM_OPT. 6.1.1 adds about 100 options with its defaults, drops a few (FREERTOS_SMP and some SOC_* constants), and turns ESP_WIFI_REMOTE_ENABLED on by default; no wifi-remote object is linked into the module. The Mbed TLS is the same 4.1.1 commit as in 6.0.3.

13. and 14. Say 6.1.1 in two comments

The module's version history said it was built with ESP-IDF 6.0.3, and it now says 6.1.1. The comment on the Wi-Fi password-failure reason codes (WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT, _AUTH_FAIL, _HANDSHAKE_TIMEOUT) now names 6.1.1: they keep the values 15, 202 and 204. Comments only.

15. Leave the Wi-Fi OWE soft-AP support out of the control module

ESP-IDF 6.1.1 added CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_SOFTAP, which defaults to y. 6.0.3 had no such option and the module only runs as a station, so it is set to n. That keeps the 6.0.3 behaviour, does not link soft-AP code, and saves about 1.5 KB of flash.

Not in this PR: -O2

The other modules in the series build with -O2; this one does not. It does not build at -O2 as it stands: jtag.c fails -Werror=maybe-uninitialized (user_id), and the recovery hotspot strncpy calls into ssid[33] and pw[68] fail stringop-truncation. The jtag.c bit-bang also depends on call timing that its own comment calls proven, it runs only during a Wi-Fi recovery, and I cannot exercise that safely. So I left it out.

Memory

From idf.py size (the 6.1.1 row is read from the linker map of the head):

shared IRAM/DRAM used / free (of 341,760) flash code
6.0.3, only the ESP-IDF 6 port (before commits 7-11) 184,609 / 157,151 712,210
6.0.3, with commits 7-11 193,888 / 147,872 706,258
6.1.1, head 196,320 / 145,440 725,274

u64ctrl.bin is 1,086,944 bytes (1,072,656 on 6.0.3); 65% of the 3 MB partition is free. The 16 KB IRAM block stays full, as before. The 6.1.1 build prints 5 CMake warnings and some Kconfig deprecation notes from ESP-IDF itself; the module's own code adds none.

TLS under mbedTLS 4

Key exchange. mbedTLS 4 has no static-RSA or static-ECDH key exchange, so the module's TLS 1.2 now offers ECDHE only. TLS 1.3 stays off, as on master; enabling it, along with DTLS, is left to the TLS offload work that builds on this port. CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y is still in sdkconfig but no longer does anything.

The built-in servers. On 23 October, openssl s_client showed that both recovery.ultimate64.com and ultimate64.ddns.net:

  • negotiate ECDHE-ECDSA-AES128-GCM-SHA256 on P-256;
  • refuse static RSA and static ECDH.

So the built-in servers are unaffected. A recovery server set from the menu has to offer ECDHE.

Certificates. They are now checked through the certificate bundle's trusted-certificate callback. Both servers' chains end at ISRG Root X1/X2, and both roots are in the custom bundle (ca/cacert.pem).

Tests

The new host test. make host_tests_idf6 is a new target, and a new CI step runs it in the ESP-IDF 6 image: recoverymanifest, 102 checks.

  • It moved out of make host_tests, which CI runs in ESP-IDF 5.3.1, because it links TF-PSA-Crypto from ESP-IDF 6.
  • It builds TF-PSA-Crypto with that library's default configuration, so it tests the code, not the module's hardware SHA driver.

Cases, named by the error they expect:

  • A valid manifest is accepted.

  • The wrong key, a tampered manifest, and a manifest correctly signed by an RSA key (rsa512.manifest, new) are refused as a bad signature.

  • These are refused as a hash mismatch:

    • a changed or truncated image or bitstream;
    • a manifest hash that differs in its first, middle or last byte.
  • These are reported as a crypto failure, never as a bad signature or a match:

    • a crypto library that will not start;
    • a hash that fails in update or finish.

    The test forces these with --wrap on psa_crypto_init, psa_hash_update and psa_hash_finish, so the product code carries no test hook.

  • The shipped keys (commit 6).

Written first. The tests are red against the unported code, because recovery_verify.c cannot include mbedtls/sha256.h under ESP-IDF 6.

Mutants. I also mutated the product code.

  • The host test catches 16 of 17 hand-made mutants of recovery_verify.c. The survivor keeps the old MBEDTLS_USE_PSA_CRYPTO guard around psa_crypto_init(). It is equivalent, because that macro is still defined.
  • 5 mutants of the shipped key list are all caught: a corrupt spare, no spare, a verify loop that skips the last key, a test key shipped, and a spare equal to the main key.

Per commit. Each of the first 6 commits builds u64ctrl under ESP-IDF 6.0.3 and passes make host_tests in the riscv build image. The ESP-IDF 5.3.1 image still refuses to configure u64ctrl, by design (the version check). For commits 7-11, the head and commits 8 and 11 were built; commits 9 and 10 only change two threshold lines and one sdkconfig line, and were not built one by one. I did not run make host_tests on them (no code under test changed). The only compiler warning is the old unused variable _err in rpc_dispatch.c.

The two new CI commands. I ran them locally exactly as written in build.yml, in espressif/idf:v6.1.1 under amd64 emulation, at the head:

  • the host test: 102 checks, 0 failed;
  • idf.py build: OK, and sdkconfig is unchanged by the build.

The same two ran on 6.0.3 for commits 1 to 11 with the same results.

Local builds

After this PR, u64ctrl needs ESP-IDF 6 while raw_u64 and raw_c3 still need 5.3.1.

Overlaps with other PRs:

Host tests on the 6.1.1 head (CI image, as build.yml runs them): make host_tests_idf6 RC=0 (102 checks, 0 failed), tests/lib/u64ctrl_ca_test.py OK, lint OK. The u64ctrl module build finishes with RC=0. make host_tests runs in the riscv image (ESP-IDF 5.3.1), which the move to 6.1.1 does not touch; it passed on the 6.0.3 head (2026-10-30).

Tested on hardware

ESP-IDF 6.1.1

Bench image. One work-in-progress build (git hash 1a0778724) carries this PR together with the stack above it (#997, #1095, #953), #835 and test-only fixes that belong to no PR here. It was installed on the C64U with the updater, the ROMs were written back, and the configuration was reset. The build before it (git hash 59672246e) had the 6.0.3 module; the 6.0.3 figures in brackets are from it, on the same device and the same bench network. The 6.1.1 image also carries the #1095 changes made since that build.

The move from 6.0.3 to 6.1.1 is a toolchain change, so again there is no red/green pair. The closed Wi-Fi library changed between the two versions, so the suites and the soak were repeated. Hardware: C64 Ultimate (C64U), firmware 3.15a, core 1.50.

Step Result
Install Flashed with the updater; the machine came back on the new firmware, WiFi Link Up on its own address.
run-tests --e2e --profile quick 34 of 37 at first. The three failing input suites (input, browser-cbm-names, usb-mouse) failed because an object was resting on a key; with it removed they pass 3 of 3, and they also passed inside the standard profile below.
Cold power cycle REST answered again 20 s after it went down.
Power cycle from the menu, twice REST back after 12 s both times.
run-tests --e2e --profile standard All 73 suite runs passed (the 6.0.3 runs on the #1095 branch reported 72 of 73, one failure from the test host in observability).
uci-net-target, deep profile Exit 0 over Ethernet and over WiFi (2 suite runs each).
Soak over WiFi, 3600 s, Ethernet cable out 3602 s, 0 FAIL, 510 iterations, ident median / p90 / p99 24 / 44 / 83 ms. The 6.0.3 image of the earlier round below: 510 iterations, 27 / 52 / 106 ms.

WiFi throughput, ESP-IDF 6.0.3 module against 6.1.1, one run each, recorded, not a speed claim:

metric 6.0.3 6.1.1
ping x100, -i 0.2, avg 19.5 ms 13.0 ms
link_bench rtt n=200 mean / p50 / p90 / p99 73.9 / 65.4 / 100.9 / 245.9 ms 75.9 / 69.8 / 118.3 / 187.0 ms
bulk get, kB/s (3 runs) 318, 387, 381 375 to 404
bulk put, kB/s (2 runs) 169, 209 203 to 207

TLS on this module is #1095; the TLS results of this image are there.

Earlier round, ESP-IDF 6.0.3

Bench image. One work-in-progress build (git hash fdb59b059) carried the whole stack for Round B: this PR and every PR below it in the stack, the WiFi PR (#1041), #953 and #997, plus test-only commits that belong to no PR here (the lwIP pbuf pool change that fixes SEND ERROR: 12, #1035, and #835). All six PR heads are ancestors of that commit, so the patches of each PR are the bench's patches; the WiFi PR was rebased onto this stack for the build and git range-diff shows only conflict resolutions and module version numbers against its own branch. The hardware rows below therefore test this PR together with the others, and say so. Module version numbers are placeholders for the maintainer to assign at merge.

Before the flash. Each device was on the previous work-in-progress build (git hash 492c587e9): ESP-IDF 5.3.1 modules, no TLS commands, no GET_RANDOM. After the flash the config was reset and only the settings each run needs were set.

This PR is a toolchain move, so there is no red/green pair for it: the check is that the same steps and suites give the same results on the ESP-IDF 6 module as on the 5.3.1 one. The module in this PR is u64ctrl, so the machine is the C64 Ultimate (C64U): firmware 3.15a, core 1.50. The C64U ran the module of this PR together with the WiFi PR and #953 (both also change u64ctrl); the rows do not separate them.

Step Result
Install Flashed from the SD card with the updater. The updater showed the previous module version and "Flashing ESP32 Success!"; the machine came back on the new firmware by itself (read by a person from the screen). The ROMs were written back afterwards.
Cold boot Plug pulled and the front switch tapped: REST was back 19 s later, no "Low input voltage" popup in a 90 s watch, BASIC V2 READY, WiFi Link Up on its own address by itself.
Joins by itself Link Up by itself after the flash and after the cold boot. After a user-initiated forget, the stored list was empty and stayed Link Down; the bench network was then entered by hand and Link Up.
run-tests --e2e --profile quick All 37 suite runs passed. The pre-flash reference run had 5 failures from the test host (missing Python modules, multicast routing); with that environment fixed they did not repeat, so this says "no regression", not "the same set".
uci-net-target, deep profile Exit 0 over Ethernet and over WiFi ("all 2 suite runs passed"), 0 x SEND ERROR: 12. The image carries the lwIP change that fixes that error, so this row partly measures the lwIP change, not this PR.
Soak over WiFi, 3600 s, Ethernet cable out 0 FAIL, 510 iterations (pre-flash reference 500), ident median / p90 / p99 27 / 52 / 106 ms, ping 3593 replies in 3588 s with no loss seen. One run each; recorded, not a claim.
Wake on WiFi 3/3 woke on the first magic packet (7 s each). With the menu Disable set, three packets over 60 s did not wake it, as on master.

WiFi throughput, ESP-IDF 5.3.1 module (before, same day, same position) against this stack (after), one run each, recorded, not a speed claim:

metric before (IDF 5.3.1) after (IDF 6)
ping x100, -i 0.2 0% loss, avg 14.7 ms (max 103.7) 0% loss, avg 15.3 ms
link_bench rtt n=200 mean / p50 / p99 65.1 / 61.0 / 238.7 ms 72.6 / 72.0 / 241.6 ms
bulk get, kB/s (3 runs) 335, 323, 382 354, 344, 352
bulk put, kB/s (2 runs) 187, 169 196, 179

The earlier measurements on this PR's previous heads (the 27 October runs of commits 7-11, with ping, REST, FTP and writemem figures) were on a different day and set of images; they are superseded by the table above and are not repeated here.

No result is claimed for:

  • the WiFi recovery download (manifest fetch, signature check, hotspot fallback). Chris ran it on his C64U (Trust Mozilla's current root list in u64ctrl's network recovery (fixes the emSign roots) #1034); re-running it reflashes the module from the internet, so I did not.
  • the brownout reset path, and the power button during a WiFi recovery. The front switch's hold-to-off was not used; power-off was by the test harness.
  • WPA3 networks: there is no WPA3 AP on the bench.
  • network time (CMD_GET_TIME, now on picolibc): nothing in the Ultimate calls it, and the test harness cannot read it.
  • the Elite II (same u64ctrl and target/u64ii as the C64U).
  • this PR alone on hardware: both rounds ran it together with the PRs above it.

Written with Claude Opus 5.5 in Claude Code.

JC-000 and others added 11 commits October 30, 2026 14:29
…DF 6.0.3

u64ctrl moves to ESP-IDF 6.0.3 (mbedTLS 4) and bumps the module version
so the updater installs it. This changes the toolchain of the C64
Ultimate's power controller, not only of its WiFi: the module runs
power, button and keepalive handling. It is one commit because none of
its parts builds alone: the CMake check stops CI's ESP-IDF 5.3.1 build,
and the recovery code does not compile under mbedTLS 4.

- my_uart.c: uart_periph.h moved from soc/ to hal/, and
  uart_isr_handle_t (a typedef of intr_handle_t) is gone. The same two
  changes GideonZ#996 makes for raw_u64.
- CMakeLists.txt: configure stops on an ESP-IDF older than 6.
- sdkconfig: regenerated by idf.py build from the ESP-IDF 5.3.1 file.
  Values present in both versions are carried; of the 1498 options in
  the 5.3.1 file only the esptool before/after spelling, DHCP option
  length (68 to 69), X509 trusted cert callback and
  ESP_NETIF_RECEIVE_REPORT_ERRORS changed value (SOC_ constants aside).
  Options that are new take ESP-IDF 6's defaults, among them picolibc
  instead of newlib and the FreeRTOS and ring-buffer functions running
  from flash rather than IRAM. Brownout level 7 and the 100 Hz tick are
  carried.
- rpc_dispatch.h: the module version is the next minor above master's,
  see the history line. The maintainer assigns the number at merge.
- CI builds u64ctrl in espressif/idf:v6.0.3, pinned by digest in
  $IDF6_IMAGE; raw_u64 and raw_c3 stay in my_docker_image. The ESP32
  cache key names both images. README.txt and software/u64ctrl/README.md
  say how to build it.

The recovery code from the Wi-Fi recovery change is ported to mbedTLS 4
and PSA Crypto, because it did not compile: mbedTLS 4 has no public
mbedtls/sha256.h and no mbedtls_pk_get_type(). The mbedTLS 4 port is of
code written for mbedTLS 3.

- recovery_verify.c: the key type comes from mbedtls_pk_get_key_type()
  (an ECC public key); the manifest hash is psa_hash_compute();
  psa_crypto_init() is always called, so the init does not depend on
  MBEDTLS_USE_PSA_CRYPTO, which is still defined as a legacy symbol that
  is slated for removal. A failure to start is reported as
  RECOVERY_ERR_CRYPTO ("crypto library failed"), not as a bad signature.
  The signature itself is still checked by mbedtls_pk_verify() with a DER
  ECDSA signature, as before.
- recovery_verify.h, recovery_verify.c: the streaming hash of a
  downloaded file moves out of recovery.c into recovery_hash_*(), on
  psa_hash_*(), so the host test can run it. It also holds the compare
  with the manifest's hash, reported as RECOVERY_ERR_HASH_MISMATCH.
- recovery.c: stream_file() uses it. The checks, their order and the log
  line for a differing hash are as before; a failure of the crypto
  library is logged by name.
- Two result codes are added after the existing ones; nothing that was
  returned before changes.
- The host test links TF-PSA-Crypto from ESP-IDF 6, so it moves out of
  make host_tests, which CI runs in ESP-IDF 5.3.1, into host_tests_idf6
  and its own CI step in $IDF6_IMAGE.

Tests, written first and red against the unported code (recovery_verify.c
cannot include mbedtls/sha256.h under ESP-IDF 6), check by the error each
case names:

- a valid manifest is accepted;
- the wrong key, a tampered manifest, and a manifest correctly signed by
  an RSA key (rsa512.manifest) are refused as a bad signature;
- a changed or truncated image or bitstream is refused as a hash
  mismatch, and so is a file whose manifest hash differs in its first,
  middle or last byte, which a compare that stopped early would accept;
- a crypto library that will not start, or a hash that fails in its
  update or finish, is reported as such, never as a bad signature or a
  match. The test forces these through --wrap=psa_crypto_init,
  psa_hash_update and psa_hash_finish, so the product code carries no
  test hook.
The signed vectors are unchanged; the two RSA files are new.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
On mbedTLS 4, PSA's key slots are protected by a mutex only with
MBEDTLS_THREADING_C. It is ESP-IDF 6's default; the regenerated
sdkconfig had carried 5.3.1's "not set". The WiFi supplicant
(ESP_WIFI_MBEDTLS_CRYPTO, on in this project) imports and destroys PSA
keys now, and it runs next to anything else that uses PSA. The pthread
implementation comes with it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…T buffer

When no UART buffer is free, the receive hook returned ERR_BUF and
wlanif_input() freed the packet. On ESP-IDF 5.3.1 the WiFi driver was
then told ESP_OK; on ESP-IDF 6 esp_netif_receive() passes the error
on, so the driver would see ESP_FAIL on this path. Stock ESP-IDF 6
already returns ESP_FAIL whenever lwIP's input mailbox is full, so the
driver handles it; free the packet here and return ERR_OK only to
leave this path exactly as before. The packet is dropped either way.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
UART1 is routed to the FPGA pins in two places: at boot, in
setup_modem(), and whenever the machine is switched on, in
regulator_enable(). Before either, the pins hold their reset state or,
after check_fpga() or a power off, a pull-down (check_fpga() sets it on
RXD only; the power-off path sets it on all four). ESP-IDF 5.3.1's
uart_set_pin() put a pull-up on RXD and CTS before connecting them,
replacing it. ESP-IDF 6's uart_set_pin() never touches pulls, so RXD
would stay pulled down and CTS at its reset state while the FPGA
configures, reading as a break and as clear to send where 5.3.1 read
idle and not clear.

One helper, my_uart_connect_pins(), sets the pull-ups and then routes
the pins, in that order as 5.3.1 did, and both places call it. While
the machine is off RX and CTS stay routed, pulled down; a boot that
stays off has the pull-ups on for about 100 ms until
regulator_enable(0), the same as on 5.3.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ESP-IDF 6's brownout interrupt waits for every enabled UART's
transmitter to drain before it resets the chip; 5.3.1 reset at once.
UART1 honours CTS, and CTS idles high through its pull-up when the FPGA
loses power with the machine, so bytes left in the transmit FIFO would
never leave and the wait would last until the 300 ms interrupt
watchdog, ending in a panic reset instead of a brownout reset.

Register a brownout callback, which runs in IRAM ahead of that wait,
that turns CTS flow control off so the FIFO drains. A failed
registration is logged and does not stop the boot.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The host test only used keys of its own. Load every key in
recovery_trusted_keys as an EC public key, require a spare next to the main
key, require that no two shipped keys are the same, and check that a manifest
is verified by a key placed behind all of them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ESP-IDF 6 moved the FreeRTOS queue/task and ring buffer functions to
flash by default (CONFIG_FREERTOS_IN_IRAM and CONFIG_RINGBUF_IN_IRAM are
off); ESP-IDF 5.3.1 had them in IRAM. Every frame passes
xQueueGenericSend, xQueueReceive and xRingbufferReceive in both
directions, so each call can wait on a flash cache miss. Set both options
to put them back in IRAM (12,140 B more shared IRAM/DRAM, 157,151 B of 341,760 stay free; flash code drops by 13,024 B).

The effect was measured on the U64E's classic ESP32 module only (raw_u64:
writemem p50/p90/p99 back in the IDF 5.3.1 range, the REST probe and FTP
get not fully). On this module it is not measured yet; the C64U bench run is pending.
The change is the same two sdkconfig lines.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…flash

The WiFi task runs on core 0. esp_intr_alloc() binds an interrupt to the core it is called on, so my_uart_init() now runs from a short task pinned to core 1, which keeps the UART ISR off the core the WiFi driver is using. The ISR, the UART buffer code, hacked_recv(), dispatch() and cmd_send_eth_packet() move to IRAM with a linker fragment (noflash). The ISR flags stay 0, so the interrupt is masked while the flash cache is off (NVS writes) and nothing in the handler has to be safe to run then; the overflow branch calls the flash function uart_hal_rxfifo_rst(), but RXFIFO_OVF is not in the enable mask, so it does not run. The dispatch task is pinned to core 1 at priority 19 so it runs where the ISR feeds it. Also check the init semaphore and the task create.

The whole of my_uart.c is noflash, so my_uart_connect_pins() and the brownout callback now sit in IRAM too (the callback already was IRAM_ATTR), and the callback is registered from the core 1 task. Neither depends on the core: the brownout interrupt is a separate system interrupt, and the pin routing is called as before from task context. This is harmless.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The RX full threshold drops from 120 to 64 and the TX empty threshold from 10 to 64 (the hardware flow control threshold of 122 is unchanged). At 5 Mbaud the interrupt latency budget before RTS asserts goes from 2 bytes (4 us) to 58 bytes (116 us), and the TX FIFO has 128 us instead of 20 us to be refilled. The margin after RTS asserts stays 6 bytes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…IFI_EXTRA_IRAM_OPT)

The option is off by default for the ESP32-S3 and places more of the WiFi driver send and receive code in IRAM.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Place esp_netif_transmit/receive/free_rx_buffer, wlanif_input, esp_pbuf_allocate/free, wifi_transmit/free, esp_wifi_internal_free_rx_buffer, pbuf_free, pbuf_alloced_custom, pbuf_init_alloced_pbuf, mem_malloc, mem_free, sys_arch_protect/unprotect and sys_mutex_lock/unlock in IRAM (noflash), so the per-packet path between the WiFi driver and the UART bridge no longer calls flash-resident code. What is left in flash is off that path: the one-time sys_mutex_new, the esp_event_post calls guarded by the runtime tx_rx_events_enabled flag, and the command handlers that dispatch() calls for non-packet commands.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@chrisgleissner chrisgleissner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JC-000 thanks for the ESP-IDF 6 migration. The branch conflicts with master. Please merge or rebase master.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 10, 2026
Brings in GideonZ#1028's updated branch, which already holds master.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 10, 2026
Brings in GideonZ#996's updated branch, which already holds master and GideonZ#1028.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 10, 2026
Brings in GideonZ#1029's updated branch, which already holds master and GideonZ#1028/GideonZ#996.
The tree was merged against the old WiFi series tip so that GideonZ#953's own changes
apply on top of the merged GideonZ#1041, not on the earlier copy of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 10, 2026
Brings in GideonZ#953's updated branch, which already holds master, GideonZ#1028, GideonZ#996 and GideonZ#1029.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

# Conflicts:
#	Makefile
@JC-000

JC-000 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Merged the current master into this branch (50aa426). The only conflict was in the Makefile's host_tests list: master added the new uart_tests, and this PR keeps the manifest check in host_tests_idf6, so the merge keeps both. The module version is still above master's, and the diff is still only this PR's own change. make host_tests and make host_tests_idf6 pass, and u64ctrl builds in the pinned ESP-IDF 6.0.3 image.

Written with Claude Sonnet 5.5 in Claude Code.

JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 12, 2026
…ideonZ#996)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 12, 2026
…(base update for GideonZ#1029)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 12, 2026
…ci-net-get-random (base update for GideonZ#953)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

# Conflicts:
#	software/io/network/network_target.h
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 13, 2026
…aster) into pr/3-tls-r1 (base update for GideonZ#997)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 and others added 4 commits November 16, 2026 14:25
CI and the build instructions move from the 6.0.3 image to espressif/idf:v6.1.1, pinned by digest. The sdkconfig is regenerated by 6.1.1; every value the module sets is unchanged, including the IRAM placement options (FreeRTOS, ring buffer and Wi-Fi in IRAM). Its mbedTLS is the same Mbed TLS 4.1.1 commit as 6.0.3.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason codes WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT, _AUTH_FAIL and
_HANDSHAKE_TIMEOUT keep the values 15, 202 and 204 in ESP-IDF 6.1.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 1.31 line of the version history said the module was built with ESP-IDF 6.0.3. It is now built with 6.1.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ESP-IDF 6.1.1 added CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_SOFTAP, which defaults to y. 6.0.3 had no such option, and the module only runs as a station, so it is set to n to keep the 6.0.3 behavior and not link soft-AP code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@JC-000 JC-000 changed the title Build the Elite II / C64 Ultimate control module (u64ctrl) with ESP-IDF 6.0.3 Build the Elite II / C64 Ultimate control module (u64ctrl) with ESP-IDF 6.1.1 Nov 17, 2026
@chrisgleissner chrisgleissner added the build Build and CI infrastructure label Nov 20, 2026
Conflicts resolved:
- software/u64ctrl/main/rpc_dispatch.h: master's GideonZ#1097 took V1.30 for the root list
  change; this branch keeps its own V1.31 (ESP-IDF 6.1.1) and carries master's
  1.30 history note below it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Build and CI infrastructure enhancement New functionality or an improvement to existing behavior, including formats and developer tooling. network Networking and remote services: REST, Socket DMA, FTP, Telnet, and online access.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants