Self-update writes the new build to SD, then boots known-good /boot.dol

Previous version launched the image it had just received, which is the one
thing that cannot be made safe: a broken build hangs the console and the
checks can only catch a truncated or non-DOL image, never a plausible but
broken one.

The flow is now receive -> write to SD -> boot /boot.dol:
  - netboot_sd_write() mounts the card (auto-detecting SD2SP2, then SD Gecko
    slot B, then slot A), writes the image to the path the host asked for,
    and READS IT BACK AND COMPARES.  A half-written .dol that still parses is
    exactly the failure this design exists to avoid, and the card is the one
    component here with no other integrity check.
  - netboot_boot_file() then loads /boot.dol -- a known-good Swiss -- and
    launches that instead.

So the only image this ever jumps into is one that was already known good.  A
broken test build costs nothing: Swiss comes up and can load anything,
including the previous build.  If the SD write or verify fails, nothing is
launched at all and the menu is still there.

The destination path travels in the DONE frame rather than being baked in, so
the host decides where the build lands (send-dol.py --dest, default
/gc_bba_test.dol).

libfat is unmounted before the jump: leaving the card mounted hands the next
image a filesystem libfat still thinks it owns, on an EXI channel it is about
to reinitialise.

Note the SD Gecko in memory-card slot A shares EXI channel 0 with the BBA
(channel 0, device 2).  libogc arbitrates, but SD2SP2 is on its own channel
and avoids the question -- hence the detection order.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 11:23:38 +02:00
parent 4fd337fb24
commit 30563b166d
6 changed files with 263 additions and 60 deletions
+24
View File
@@ -45,6 +45,30 @@ void *netboot_reserve(u32 *out_max);
int netboot_receive(void *dst, u32 maxlen,
void (*status)(const char *msg));
/* Mount whichever SD interface is present (SD Gecko slot A or B, or SD2SP2)
* and write `len` bytes to `path` (e.g. "/gc_bba_test.dol"), verifying the
* result by reading it back. Returns 0 on success, <0 on error.
*
* NOTE the SD Gecko in memory-card slot A shares EXI channel 0 with the BBA
* (which is channel 0, device 2). libogc arbitrates, but SD2SP2 -- on its own
* channel -- avoids the question entirely. */
int netboot_sd_write(const char *path, const void *buf, u32 len,
void (*status)(const char *msg));
/* Read `path` off the SD card into `dst` and launch it. Does not return on
* success. Returns <0 if it cannot be read or is not a plausible DOL.
*
* This is how the update completes: we NEVER jump into the image we just
* received, only into a known-good /boot.dol (Swiss). A broken test build
* therefore costs nothing -- Swiss still comes up and can load whatever you
* want, including the previous build. */
int netboot_boot_file(const char *path, void *dst, u32 maxlen,
void (*status)(const char *msg));
/* Destination path the host asked for in its DONE frame (default
* "/gc_bba_test.dol"). */
const char *netboot_dest_path(void);
/* Launch a .dol image already in memory. Does not return on success.
* Returns <0 if the image is not a plausible DOL. */
int netboot_launch(const void *dol);