Repository navigation
Recover a U64-II over Wi-Fi from a signed manifest - #1012
Conversation
Hold the power switch down for 3 s while off; control module 1.18.
|
This is a truly amazing new feature @GideonZ . Thanks a lot. I already tried it on my C64U FE and it works great. |
|
Recovering a bricked board over Wi-Fi and JTAG in 6–7 seconds without a cable or USB stick is a really nice feature! Since the
|
|
Some points I (with assistence of AI) have found: Great feature. One practical gap, though: many of us run the U64-II on wired LAN because streaming does not work over Wi-Fi. The Wi-Fi credentials in the module are then never used and silently go stale (new router, changed password, WPA3-only, 2.4 GHz switched off). You find out only when recovery fails with blink code 1, and then you are locked out of recovery for good. A user locked out of recovery costs far more in support than one who needs it explained, so I'd suggest closing this before 1.18 ships, since recovery has to work with whatever module version is on the board when it bricks:
Recommended usage, for the docs. How someone sets up the fallback network is up to them, but the docs could recommend: Use a spare access point, not the main router, so the public PSK never opens the home network. Showing the module’s MAC (CMD_WIFI_GETMAC) in the menu would make the MAC filter easier to set up, but can come later. |
|
@UltimateC64Ultimate64fan @markusC64 Thanks for the suggestions! Since we're keen to release soon, I'd focus on the changes that make a real difference to recovery.
Before release, I'd also make sure we test invalid signatures, interrupted recovery and the 100T variant, as mentioned in the PR. Overall, I'd keep the scope small, but I think fallback Wi-Fi is worth including if we can implement and test it without significantly delaying the release. |
|
Thanks, glad the fallback Wi-Fi made it in, that’s the part that matters most to me.
|
|
@chrisgleissner, @markusC64: 1. Adding owned domains to
|
|
Thanks @UltimateC64Ultimate64fan . May I ask who is behind this handle as you show no real human name on your profile. Your analysis appears to sound and thanks for having added additional options to the mix. I have an Android phone and I am not affected by this, but I can see how other users may have trouble. I think the current approach is sound as a first cut and clearly much better than what we have in place right now. Users who don't want to benefit from it can use the old approach and buy a JTAG adapter. All of this is ultimately @GideonZ 's call. |
|
Ha, this is great. I just saw this a day after I had set up an ESP32 dev board to be my JTAG programmer for my C64U. Network recovery from the control module is a great addition. Two questions, since it touches things I'm working on for the Elite II / C64U module:
Also: #953 put On #996: I'll keep the module builds moving to ESP-IDF 6 (raw_u64 in #996, u64ctrl to follow, raw_c3 as well) and rebase the u64ctrl port onto this PR once it's in. |
GideonZ's open PR GideonZ#1012 gives the control module (u64ctrl) CMD_SET_RECOVERY_URL 0x1A and CMD_GET_RECOVERY_URL 0x1B, and u64ctrl appends its own commands from 0x13 upward, so 0x1A collides with ours. CMD_GET_RANDOM, which both modules serve from rpc_shared.h, takes 0x20: free in every map (the active ones, the commented-out socket sets of raw_u64 and raw_c3, and the TLS block at 0x30) and clear of the 0x1C-0x1F that u64ctrl's run can grow into. It is also the number of the UCI command, which reads well. Only the module RPC number changes. The UCI command NET_CMD_GET_RANDOM ($20), its wire format and the C64-facing behavior are unchanged. The tests name the command by its constant and need no edit. IDENT_MINOR is not bumped: the 1.8/1.18 that introduced CMD_GET_RANDOM is not released. A module flashed from an earlier build of this branch still answers 0x1A and needs a forced reflash. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When your contribution gets merged, we will surely fix the IDs of both the version and the commands.
Well, I cannot change updaters retrospectively, but newer updaters will not downgrade the ESP32 module.
We'll fix that once we merge. Or yes, you could do a push to your own PR, too.
I would prefer to stay on ESP-IDF 5 for now, because otherwise I will have to update the docker image as well that builds the firmware for Commodore. Of course, UNLESS there is a compelling reason to switch to a newer ESP-IDF? |
@UltimateC64Ultimate64fan:
True, but they need to point somewhere sensible. Unless it's possible to have recovery.ultimate64.com point to another server than just ultimate64.com, I wouldn't know how to use that.
Haha that sounds like an Apple-only problem then. A minority of users. Borrow a real phone from a sensible friend, problem solved.
I have thought about this as well, but honestly I find this solution much harder, as it requires an app to be installed on the phone, or a webserver to be installed in the ESP32. The latter might be beneficial for other reasons, but still.. meh.
It cannot, becaues the FPGA will also need firmware to do anything with the USB / SDCard. We could, however, also upload a small ultimate application to do that. I think that could easily fit alongside of the compressed FPGA image. BUT.... the drawback of this solution is two-fold:
I can test with the 100T boards, but I am 99.99% sure it works, as the tests that are run offline confirm that the switch between 50T and 100T work. Plus, the serial number pattern also works, and hence distinction between the 100T for C77 and 100T for non-C77 can also be made.
The more machines in the field without the update feature, the less well it helps. It can always be improved in 1.19, 1.20, 1.21, etc.. Better than nothing. |
|
Thanks, that answers everything. On ESP-IDF 6, the reasons in short:
Obviously none of this should hold up 1.18. I'll rebase the u64ctrl port onto this PR after it's merged. |
|
Thanks for the clear explanation, @GideonZ! The factory programming time (
Yes, that is 100% possible in DNS without touching the server that runs In the domain registrar's DNS control panel for
(or an The main |
|
@GideonZ I want to add a reinforcement note for moving to newer IDF because of a security issue that impacts something like fetching firmware over the internet. This was more of a theoretical issue when I went with the approach I proposed of vendoring in Mozilla's CA store instead of using the randomly ancient ones that come with ESP-IDF's mbedTLS, but now it is real in a way that puts almost all modern infrastructure at risk and will likely have a long tail before everything everywhere no longer is vulnerable. Now that this has happened I am wondering if my approach was not good enough and the ESP32 should have CRL checks and be able to update its CA store without a new firmware flash. See: https://blog.cloudflare.com/emudhra-certificate-compromise/ |
|
Merging this as requested by @GideonZ |

Holding the power switch down for three seconds while the machine is off makes the control module (ESP32, module 1.18) recover a U64-II or C64U over Wi-Fi, with no USB stick and no JTAG cable. It asks a recovery server which package fits the board, streams the runtime bitstream into the FPGA over JTAG and the updater into memory, and starts the updater, which asks before it flashes anything.
Works end to end on a C64U (XC7A50T), over plain HTTP from a LAN server and over HTTPS from the public server at
https://ultimate64.ddns.net. The 2.2 MB bitstream loads in 6 to 7 s with direct GPIO register writes; the same load throughgpio_set_level()took over 40 s.How it stays safe
recovery_trust.c, whichever server sent them; with no key there, it refuses everything. A manifest names the FPGA it is for, and may name a serial pattern.http://server set from the menu) could start an FPGA design of their own. A recovery only runs while someone holds the power switch down at the machine, normally its owner, which is why this is accepted for this product. Storing the bitstream in the ESP32's flash and checking it before loading would close the gap, at about ten seconds per recovery. The comments onFPGA_HOLDBACKinrecovery.cand at the top ofrecovery.hsay the same.CMD_MODEM_ONis refused, so firmware still on the board cannot take over the Wi-Fi interface the download uses.recovery.h).The three commits
software/u64ctrl/main/recovery*.c, the trigger inbutton_handler.c, streaming JTAG injtag.c, and a Recovery Server setting under Power Settings (config item0x65, RPC0x1A/0x1B) that the module asks before its built-in list.UPDATE_FPGA=both|50t|100tintarget/u64ii/riscv/update.make u64iialso writesrecovery_50t.cfw(5.2 MB) andrecovery_100t.cfw(6.8 MB) next toupdate.cfw(9.0 MB). They carry one bitstream, refuse to run on the other FPGA, and set the VIC to NTSC and HDMI to 640x480 themselves, because recovery starts them straight from the bootloader.bothbuilds the same updater as before.Size
43 files, 3145 lines added: 2090 of firmware and build files, 1055 of host tests.
Testing
make host_tests, with three new suites:recoverymanifest(65 checks): the C reader against manifests signed by the server'smanifest.py, built against the mbedtls that ESP-IDF ships.recoveryimage(34 checks): optionally also against real release images.recoveryurl(28 checks).make u64ii. The changed shared files (wifi_cmd.cc,wifi.cc,u64_config.cc) compile without warnings for U64-II, U64 (Nios and RISC-V) and U2+L, in their applications and updaters.recovery_50t.cfw.Not yet tried on a board: the refusals (tampered bitstream, wrong key), switching off mid-recovery, a 100T board, and the updater's ESP32 rule for a module that is equal or newer.
For review
recovery_trust.cholds the owner's public key and the built-in server.software/test/recovery_manifest/make_vectors.pyuses it to regenerate the test vectors; it finds it next to this repository, or throughRECOVERY_SERVER.🤖 Generated with Claude Code