Stop planting hekate's watchdog cookie in IRAM

The emulator wrote hekate's "watchdog fired" magic (0x544457 at
0x4003FF18) before every boot. hekate then took its post-watchdog path
and skipped LP0 and Minerva, because the EMC could not support DRAM
training. It can now, so the cookie only made the boot differ from
hardware, and it never covered Nyx, which trains the DRAM itself when
it finds Minerva uninitialised.

With the cookie gone, hekate's IPL saves the LP0 SDRAM config and
trains 204, 800 and 1600 MHz itself, and Nyx takes over the trained
context. An SD image without bootloader/sys now gets hekate's real
"Missing LP0/Minerva lib" screen, which waits for a key press.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
This commit is contained in:
Claude committed 2026-09-25 19:29:24 +00:00
1 parent 4f42e04f6e
commit 306a86dbcb
3 files changed
+22 -39

No files matched your search

+20 -20
View File
@@ -48,26 +48,23 @@ same peripheral models through one dispatch (see [CCPLEX CPU0](#ccplex-cpu0)).
## Boot flow (Hekate as the example)
1. The payload is loaded into IRAM (Internal RAM) at `0x40010000` via
`uc_mem_write`. We also pre-write the 4-byte cookie `0x544457` ("WDT") at
IRAM offset `0x4003FF18`. Hekate reads that location during early boot.
When the cookie is present, it takes the `goto skip_lp0_minerva_config`
branch and skips loading `libsys_lp0.bso` and training the DRAM with the
Minerva module, as it does on hardware after a watchdog reset. The EMC
model runs Minerva (see [EMC and DRAM clock](#emc-and-dram-clock)), and
Nyx trains the DRAM itself when it starts; the cookie only spares a
minimal SD image the IPL's "missing lib" errors and shortens the boot.
The matching exception-enable cookie at `0x4003FF1C` stays zero, so the
"hang detected" warning is suppressed.
`uc_mem_write`. Nothing else is planted: IRAM holds what it holds after a
cold boot.
2. PC is set to `0x40010000`, SP to `IPL_STACK_ADDR`. CPSR enters ARM mode.
3. The IPL (Initial Program Loader) initialises clocks, fuses, the DRAM
(`sdram_init`, at 204 MHz) and the display, then continues into the boot
menu without loading LP0 or Minerva.
(`sdram_init`, at 204 MHz) and the display, mounts the SD card, loads
`bootloader/sys/libsys_lp0.bso` (it saves the LP0 SDRAM config to PMC
scratch) and trains the DRAM with Minerva
(`bootloader/sys/libsys_minerva.bso`) at 204, 800 and 1600 MHz, all as on
hardware (see [EMC and DRAM clock](#emc-and-dram-clock)). An SD image
without those modules gets hekate's "Missing LP0 (sleep) lib! / Missing
Minerva lib!" screen, which waits for a key press before the menu.
4. Hekate self-relocates into DRAM (`0xC0000000+`) and continues. It points
DC (Display Controller) window A at its portrait framebuffer and draws its
boot logo and menus there, sideways, for the landscape-mounted panel.
5. Nyx (the LVGL GUI) loads Minerva, trains the DRAM at 204, 800 and
1600 MHz, and from then on alternates 1600 and 800 MHz on every GUI loop
to save power. It draws landscape into a second framebuffer and has VIC
5. Nyx (the LVGL GUI) takes over the trained Minerva context and from then
on alternates the DRAM between 1600 and 800 MHz on every GUI loop to save
power. It draws landscape into a second framebuffer and has VIC
turn every frame into the portrait surface that window A scans out. The
display follows the DC's windows, whatever they point at (see Display
pipeline).
@@ -194,9 +191,9 @@ frequency-switching module, depend on:
- **Status.** `EMC_EMC_STATUS` otherwise reports timing updates done, the
DRAM active and the state machines idle.
With the stock `bootloader/` folder, Nyx trains 204, 800 and 1600 MHz and
then switches between 800 and 1600 MHz on every GUI loop, each switch a full
handshake with a CCFIFO replay.
With the stock `bootloader/` folder, hekate's IPL trains 204, 800 and
1600 MHz, and Nyx then switches between 800 and 1600 MHz on every GUI loop,
each switch a full handshake with a CCFIFO replay.
### Security Engine (`t210/se_engine.cpp`)
@@ -652,13 +649,16 @@ don't repeat the diagnosis:
- **Minerva DRAM training** hangs in a `PLL_BASE.LOCK` poll. Fix: report
LOCK once the PLL is enabled.
- **Minerva hung Nyx** (hekate 6.5.3 with the stock `bootloader/` folder
never reached its GUI). Nyx trains the DRAM itself, and Minerva spun on
never reached its GUI). The emulator planted hekate's "watchdog fired"
cookie in IRAM so the IPL would skip Minerva; Nyx then trained the DRAM
itself, and Minerva spun on
`PLLMB_BASE.LOCK` (the CAR model had no PLLMB and read it as 0). Behind
that it would have spun on the DLL-enable bit it writes to
`EMC_CFG_DIG_DLL` and on `EMC_DIG_DLL_STATUS` lock, timed out on the
clock-change handshake, and divided by a zero MR18/MR19 oscillator count,
because every EMC register but three read 0. Fix: PLLMB, and the EMC
model described in [EMC and DRAM clock](#emc-and-dram-clock).
model described in [EMC and DRAM clock](#emc-and-dram-clock). With
Minerva working, the cookie is gone too, and hekate boots as on hardware.
- **`kfuse_wait_ready`** loops on `STATE.DONE`. Fix: stub `DONE | CRCPASS`.
- **AMS keygen** retries `tsec_query` 15 times until timeout. Fix: stub
`STATUS = 0xB0B0B0B0`.
+1 -1
View File
@@ -642,7 +642,7 @@ bool sdl_display_poll_events(EmuState *state, uc_engine *uc) {
case SDLK_r: {
if (!ctrl) {
// Plain R: soft reboot. Same path as the config window's "Reboot"
// button — re-prime IRAM payload + WDT cookie, wipe DRAM, reset PC.
// button — reload the payload into IRAM, wipe DRAM, reset PC.
state->reboot_cold = true; // the user's reset is a power cycle
state->reboot_requested = true;
printf("[diag] Reboot requested (R)\n");
+1 -18
View File
@@ -151,20 +151,6 @@ static uc_engine *setup_emulation(EmuState *state, uint8_t *payload, size_t payl
(unsigned long long)(IRAM_BASE + IRAM_SIZE),
(unsigned)(IRAM_SIZE / 1024));
// Pre-set Hekate's "watchdog fired" magic at IRAM 0x4003FF18 (cookie "WDT")
// so its early boot does `goto skip_lp0_minerva_config`, skipping both
// libsys_lp0.bso and the IPL's Minerva DRAM training - the same path
// Hekate takes on hardware after a WDT reset. The matching EXCP_EN_ADDR
// (0x4003FF1C) is intentionally left zeroed so ERR_EXCEPTION is *not* set
// and the user doesn't see a "hang detected" warning screen. The EMC
// model runs Minerva fine (Nyx trains the DRAM itself when it starts);
// this only spares a minimal SD image the IPL's "missing lib" errors and
// shortens the boot.
{
uint32_t wdt_magic = 0x544457; // "WDT"
uc_mem_write(uc, 0x4003FF18, &wdt_magic, sizeof(wdt_magic));
}
// ---- Map DRAM as one contiguous region ----
// 0x80000000 .. 0x100000000, i.e. the whole 32-bit-addressable DRAM window
// the BPMP can reach. This used to be two islands (256 MB at 0x80000000
@@ -495,8 +481,7 @@ int main(int argc, char *argv[]) {
if (!sdl_display_poll_events(&state, uc)) break;
// Soft reboot: re-write the payload to IRAM, wipe DRAM (so Nyx and
// the bootloader's file-static caches reset), reset PC/SP/clock and
// re-prime the WDT cookie so Hekate's IPL skips LP0/Minerva again.
// the bootloader's file-static caches reset) and reset PC/SP/clock.
if (state.reboot_requested.exchange(false)) {
uc_emu_stop(uc);
bool cold = state.reboot_cold.exchange(false);
@@ -513,8 +498,6 @@ int main(int argc, char *argv[]) {
if (reload > IRAM_SIZE - (IPL_LOAD_ADDR - IRAM_BASE))
reload = IRAM_SIZE - (IPL_LOAD_ADDR - IRAM_BASE);
uc_mem_write(uc, IPL_LOAD_ADDR, state.payload_ptr, reload);
uint32_t wdt_magic = 0x544457;
uc_mem_write(uc, 0x4003FF18, &wdt_magic, sizeof(wdt_magic));
// Neither the zeroed DRAM nor uc_mem_write() reaches the engine's
// code cache, so what the last run translated - a payload it
// chainloaded over this one's load address, Nyx in DRAM - would