56 Commits
Author SHA1 Message Date
Baptiste MOINE 6e72741878 Add a late HPD dock mode 2026-11-13 13:38:17 +01:00
Baptiste MOINE afc3dfe28a Add dock clone modes 2026-11-13 01:41:31 +01:00
Baptiste MOINE 41245dc22b Add fake Bluetooth controllers and USBSERFILE 2026-11-08 00:16:48 +01:00
Baptiste MOINE e17c315f87 Add a USB serial host 2026-11-06 13:00:50 +01:00
Baptiste MOINE a9b184d0ea Fix the left Joy-Con rail reading as attached 2026-11-06 13:00:49 +01:00
Baptiste MOINE 61e1fb981a Add a dock and TV model 2026-11-05 23:46:09 +01:00
Baptiste MOINE 20949b4242 Boot Linux on CPU0 2026-11-05 23:45:44 +01:00
Baptiste MOINE 4177e98dfb Add fault injection for chips and rails 2026-10-31 17:30:05 +01:00
Claude f84caeaacc Let the USB host write, and serve a gadget's disk over NBD
The emulated PC only ever read a mass storage disk and then ejected it, so
the write path through a gadget went untested and the disk could not be
used from the machine running the emulator.

The default session now asks MODE SENSE(6) for the write-protect bit and,
on a writable disk whose read checked out, writes the last 8 sectors back
as read (WRITE(10), SYNCHRONIZE CACHE) and reads them again.

--usb-host nbd[:port] (or [usb] nbd_port, or the config window) locks the
medium and serves the disk on 127.0.0.1 with a small non-blocking NBD
server (t210/nbd.cpp: fixed newstyle handshake, READ/WRITE/FLUSH/DISC).
Requests become READ(10)/WRITE(10)s of up to 64 KiB, a quiet client gets
a TEST UNIT READY every second, a write-protected disk is exported
read-only, and when the client disconnects the host ejects the disk.

Serving Nyx exposed a controller model bug: a device transfer shorter than
the host's request was taken as a short packet, so bdk's 64 KiB READ(10),
sent as two 32 KiB transfers, lost the second half. Only a short or
zero-length packet (the USB2 controller's own ZLP unless the queue head
disables it) now ends the host's transfer.

tests/usb grows a write-protected scenario, WRITE(10), MODE SENSE and
SYNCHRONIZE CACHE on its RAM disk (reads sent in 32 KiB transfers, as bdk
does), and three NBD runs driven by a Python client. Checked with Nyx SD
UMS on Erista and Mariko: nbdinfo negotiates, qemu-img convert copies the
256 MiB disk byte for byte, and a qemu-io write lands in the SD image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-26 11:09:57 +00:00
Claude 0c7f12a83b Store the last three CRLF headers with LF
.gitattributes normalises text to LF, but t210/memory_map.h, mmio.h and
tegra_bl.h were committed with CRLF before it was added, so any edit to
them either rewrote every line or had to be staged around the filter.
Line endings only; no content changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-26 10:31:55 +00:00
Claude d661f2738c Model USB device mode, with an emulated PC on the cable
Both USB controllers were plain register caches: USBCMD.RESET never
cleared, so bdk's usb_device_init() timed out and none of Nyx's USB
tools could even wait for a cable.

- The Erista USB2 controller (USB1, 0x7D000000, bdk usbd.c): queue
  heads at ENDPOINTLISTADDR (bdk's are in the controller at +0x1000),
  transfer descriptors in DRAM, ENDPTPRIME / ENDPTSTATUS /
  ENDPTCOMPLETE, SETUP packets in queue head 0 with ENDPTSETUPSTAT,
  a self-clearing controller reset and the PHY's clock-valid bit. Byte
  and halfword accesses work, since bdk memcpy()s SETUP packets out.
- The Mariko XUSB device controller (0x700D0000, bdk xusbd.c): endpoint
  contexts and TRB rings with Link TRBs and cycle bits, the doorbell, a
  two-segment event ring with Port Status Change, Setup and Transfer
  events, EP_HALT / EP_STCHG, EP_RELOAD, and PORTSC's write-1-to-clear
  changes and link-state writes.
- The host (--usb-host, [usb] host, or the config window) plays the PC
  on whichever controller attaches: debounce, bus reset at high speed,
  enumeration with SET_ADDRESS recovery, then after 100 ms for its class
  driver to bind - bdk's XUSB driver stalls an early GET_MAX_LUN - the
  class. For mass storage it runs Bulk-Only Transport: GET_MAX_LUN,
  INQUIRY, TEST UNIT READY with REQUEST SENSE for the unit attention,
  READ CAPACITY, READ(10) of the first 64 and last 8 blocks with their
  CRC32s, checked against the SD image when the size matches, then allow
  removal, eject, and poll until the gadget detaches. For HID it reads
  the report descriptor, sets idle 0 and polls the interrupt endpoint.
  It only reads, and it runs on the controllers' register accesses, so
  runs repeat. [usb-host] lines log it; RCM_USB_TRACE=1 logs every
  descriptor, TRB and doorbell.

With hekate 6.5.3, Nyx's SD card mass storage enumerates as 11EC:A7E0,
reads back identical to the SD image and ends at "Disk ejected" on both
Erista and Mariko; the gamepad enumerates and serves its report
descriptor (with no Joy-Cons it has nothing to report). Without a host
Nyx waits and reports a timeout, as with no cable.

tests/usb/ runs a mass storage gadget over a RAM disk on each controller
and a HID gadget on the USB2 one, checks what the host logs - the
enumeration, the SCSI commands, CRC32s equal to the payload's, the eject
and the detach - and a run with nothing on the cable.

The Windows pread/pwrite shim moves from mmio.cpp to platform.h, as the
host reads the SD image too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-26 10:25:29 +00:00
Claude 33d16976fe Model the CPU complex's reset view and per-core clock stop
RST_CPU_CMPLX_SET/CLR (0x340/0x344) and CLK_CPUG_CMPLX_SET/CLR
(0x460/0x464) read back the last value written, like plain registers.

- RST_CPU_CMPLX_SET has RST_CPUG_CMPLX's fields and reset value (TRM
  5.2.113): it is the active cluster's view, and the Switch runs the G
  cluster. It and its CLR partner now act on the same reset state as the
  CPUG pair, releasing and stopping CPU0 alike, and read it back.
- CLK_CPUG_CMPLX (0x378, TRM 5.2.122) and its SET/CLR strobes track
  CPUGn_CLK_STP, and all three read the register. A stopped CPU0 keeps
  its state and executes nothing while emulated time passes; clearing
  the stop resumes it where it was.

The CCPLEX test now releases CPU0 with its clock stopped, checks it does
not run and that the registers read back, then clears the stop. Against
the previous binary those three checks fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-26 10:23:45 +00:00
Claude 803729580b Report the EMC DLL's code from its calibration start value
EMC_DIG_DLL_STATUS.DLL_OUT (10:0) read 0. TRM 18.11.2.219 gives the
basis the earlier note said was missing: EMC_DLL_CFG_1's
DDLLCAL_CTRL_START_TRIM (10:0, reset 0x20) is the DLL calibration's
start value, which the timing table sets per frequency. With no delay
line to drift, calibration has nothing to move it by, so DLL_OUT now
reports the channel's start trim once the DLL locks. EMC_DLL_CFG_1
reads its reset value until written.

Minerva's _digital_dll_prelock() returns the value and nothing reads it
further; DRAM training and the 800/1600 MHz switching are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-26 10:23:31 +00:00
Claude 6d5ccb5328 Lock PLLC4 and the other PLLs bdk waits on, and the USB PLL
TegraExplorer hung for good the first time it touched the eMMC. Moving
SDMMC4 to HS200 enables PLLC4, and TegraExplorer's bdk waits for
PLLC4_BASE.LOCK with no timeout; the CAR model had no PLLC4, so the
bit never came. On Erista that stopped it at startup, before its key
dump; on both SoCs "Browse EMMC" hung. hekate's newer bdk times the
wait out, which is why nothing else showed it.

- PLLC4 locks once enabled and out of IDDQ (bit 18), setting LOCK and
  FREQLOCK (27, 28); LOCK_OVERRIDE (24) forces them.
- PLLC2, PLLC3, PLLDP and PLLA1 lock on ENABLE like PLLC/A/X/D2 (bit
  27; PLLA1 also 26, PLLDP also 28). The read-only lock bits are no
  longer stored from a payload's read-modify-write.
- UTMIPLL_HW_PWRDN_CFG0.LOCK is set unless software holds the USB PLL
  in IDDQ, its reset state, so clock_enable_utmipll() sees the lock
  instead of timing out.

TegraExplorer now reaches its main menu on both SoCs and lists the
eMMC's partitions under "Browse EMMC". With no BOOT0 image it cannot
read package1, so the Erista key dump falls back to prod.keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 22:40:33 +00:00
Claude e592ec2d88 Make every CAR reset and clock-enable bank live
Only bank U followed the payload's writes. L, H and X read fixed values,
RST_DEVICES_L read 0, and every SET/CLR strobe read 0 - but TRM 5.2.100
says any of the three registers reads back the bank, and bdk relies on
it: clock_sdmmc_is_active() reads RST_DEV_L_SET and CLK_ENB_L_SET.

The fixed CLK_OUT_ENB_L/H/X values were real-console readings taken
after a payload had brought the display up. So every payload found
DISP1 already clocked at RCM entry, and bdk's display_init() began each
boot by tearing down a panel that was never on.

The banks now follow direct writes and SET/CLR strobes, and all three
read the bank. The rest start at the TRM reset values, unknown bits as
0; bank U keeps its real-console reading. The PCIe and CPU models still
hold reset banks V, W and Y and clock bank V, since their preconditions
depend on them; reads of those banks' strobes go to them.

hwtest's report is unchanged apart from fan-tach phase, and hekate into
Nyx gives the same frame as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 22:40:19 +00:00
Claude 1aa0ee9f23 Model the SE's RSA and random number generator
Both ops finished with OP_DONE and produced nothing. se_rng_pseudo()
left its buffer as it was, so Nyx's partition manager wrote whatever
was on the stack into GPT partition GUIDs, and the SD benchmark drew
its random offsets from uninitialised memory. se_rsa_exp_mod() read
back zeros.

- RSA, as Lockpick's bdk drives it: two keyslots of up to 2048 bits
  loaded through SE_RSA_KEYTABLE_ADDR/DATA, KEY_SIZE in 512-bit steps,
  EXP_SIZE in words, the input a little-endian number over DMA and the
  result in SE_RSA_OUTPUT (or memory). Montgomery multiplication on
  32-bit words; an even modulus fails the op.
- RNG into memory or a keyslot quad, LAST_BLOCK + 1 blocks cut to the
  buffer. The bytes come from SplitMix64 with a fixed seed, reset with
  the SE, so runs stay reproducible.

tests/se/ is a new make test payload: RSA-2048 and RSA-1024 in the two
slots, each m^d and s^e checked against Python (gen_vectors.py writes
vectors.h), SHA-256 one-shot and in two parts, AES-128 ECB, and the
RNG filling a zeroed buffer, changing between calls and stopping at
the size asked for. Run against the previous binary it fails the RSA
and RNG checks. The README's "RSA, RNG and chunked SHA are stubs" is
gone; chunked SHA was already modelled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 22:40:08 +00:00
Claude fd98939cca Make the SD card a UHS-I card, so bdk runs it at SDR104
The SD card ran at 3.3 V High Speed, 48 MHz. It never offered 1.8 V in
ACMD41, CMD11 was not handled, and CMD6 always reported High Speed as
selected whatever was asked. It also carried the eMMC's CSD, so hwtest
saw an 896128 MiB card without application commands, and its SD status
was never read.

- ACMD41 answers S18A to S18R while the card signals at 3.3 V, and
  CMD11 moves it to 1.8 V. It stays there until its supply GPIO (PE4)
  drops or the SoC resets; a card re-initialised without a power cycle
  answers S18A = 0.
- CMD6 reports and selects functions per group, per SD 4.3.10: bus speed
  (SDR50, SDR104 and DDR50 added at 1.8 V), driver strength and power
  limit. CMD0 resets the functions, not the voltage.
- The CSD is an SD CSD 2.0 sized from the image, with command class 8.
  ACMD13 reports the bus width set and a Class 10, U1, V10 card, and
  the SCR sets SD_SPEC3.

hwtest now reports the SD card at 199.68 MHz after SDR104 tuning, with
the image's real size, and LDO2 at 1.8 V. Nyx boots with it, including
after cold and warm reboots, each of which re-runs the voltage switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 21:21:56 +00:00
Claude fae29019ae Model DC window address offsets and block-linear VIC surfaces, with a test
- DC: a window's fetch starts at ADDR_V_OFFSET * LINE_STRIDE +
  ADDR_H_OFFSET (TRM 24.11.1). That is the window's top-left pixel, or
  top-right with H_DIRECTION, or bottom-left with V_DIRECTION, and the
  fetch walks away from it; before, the offsets were ignored and flips
  mirrored within the window. HOS's column-scan offset (0x13FF) and
  hekate's inverted-pitch offset (1279) both land where they should.
  Layer order is documented: the TRM sorts windows by depth without
  saying which way.
- VIC: slot and output surfaces may be block linear (BlkKind 1, 2^BlkHeight
  GOBs per block) as well as pitch.
- GOB addressing moves to t210/block_linear.h, shared by the scan-out
  and VIC.
- tests/display: one bare-metal payload built per scenario (a pitch
  window, Nyx's VIC turn into pitch and into block-linear surfaces, a
  block-linear VIC source, the DC's own column scan with an address
  offset, a mirrored window with window D blended over). check.py
  compares every pixel of the frame the emulator shows with the picture
  drawn. It runs in make test and in CI.

hwtest's frame is unchanged, and Nyx's differs only in its clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 21:21:44 +00:00
Claude c6b532fdbd Read back CAR and MC registers, and measure the EMC at its modelled clock
Most CAR registers the model does not handle, and every MC register but
two, read 0 even after a write. Payloads saw a CLK_SOURCE divider, a
PLL misc word or an audio clock source they had just programmed come
back as 0.

- CAR: the fallthrough returns what was written. The SET/CLR alias
  registers are write strobes and keep reading 0. No CAR poll in bdk or
  hwtest waits for hardware to clear a bit it wrote, so read-back cannot
  turn a poll into a hang.
- MC: configuration registers read back (no MC register is polled).
- The PTO counter measures the EMC at the clock CAR and the PLLs give
  it, so it follows Minerva to 1600 MHz. At the 204 MHz boot clock it
  keeps the measured 203.991 / 204.001 MHz.

hwtest now reports the AUD_MCLK source, PLLA misc word and a clock
source divider it programs. Its verdict is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 21:21:30 +00:00
Claude 4f42e04f6e Model PLLMB and the EMC so Minerva can train and switch the DRAM clock
hekate 6.5.3 with the stock bootloader folder never reached Nyx. Nyx
trains the DRAM itself with Minerva, and Minerva spun forever on
PLLMB_BASE.LOCK: the CAR model had no PLLMB and read it as 0. Behind
that poll were more. Every EMC register but three read 0, so Minerva
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.

- CAR: PLLMB_BASE/MISC1 per TRM 5.2.230-231, locking once enabled.
  CLK_SOURCE_EMC, _EMC_DLL and _EMC_SAFE read back what was written,
  from their TRM resets. A written PLLM or PLLU reads back its
  dividers, which were dropped before while ENABLE was clear.
- EMC: a register file with broadcast and per-channel banks, plus:
  - MRW capture and MRR data/MRR_DIVLD per channel.
  - MR4 at normal temperature, and MR18/MR19 computed from MR23's run
    time at the current DRAM clock over 2 x tDQS2DQ.
  - DLL lock.
  - The CAR/EMC clock-change handshake: a new CLK_SOURCE_EMC source or
    divisor replays the CCFIFO and raises CLKCHANGE_COMPLETE.

With the stock folder, Nyx now trains 204, 800 and 1600 MHz and runs
its 800/1600 MHz power-saving loop, on Erista and Mariko. hwtest's
output is unchanged. The WDT cookie that keeps hekate's IPL from
training is kept; its comments no longer claim the EMC can't do it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 19:13:08 +00:00
Claude e32052ffd5 Model the DC windows and VIC compose, and scan out what they describe
The display model took each window's line stride from PRESCALED_SIZE
rather than LINE_STRIDE, and kept one set of window parameters for all
four windows, so window D's 656-pixel log window leaked into window A.
Its block-linear decoder also had two GOB address bits swapped. The mock
VIC only memcpy'd, so Nyx's rotated frame never existed. The renderer
papered over all of this with per-address heuristics: a "known menu
stride" of 2624, forced block-linear decoding of the IPL carveout, and a
hard-coded 1280x720 geometry for Nyx's framebuffer.

- DC: a register file per window (A-D), reached through the indirect
  pages per DISPLAY_WINDOW_HEADER or the A/B/C direct ranges. Writes
  land in the assembly copy, and WIN_x_ACT_REQ promotes it to the active
  copy the scan-out reads. Other DC registers read back what was
  written. STATE_CONTROL reads 0, and INT_STATUS reports frame end and
  vblank, which bdk polls before DSI commands.
- VIC: on COMPOSE_START, read bdk's vic_config_t from guest memory and
  draw the enabled pitch slots into the target, with scaling, clipping
  and the output flip/transpose. Nyx's 270-degree rotation now happens.
- Scan-out: fetch each enabled window per SURFACE_KIND (pitch, tiled or
  block linear, per TRM 20.1.2 Figure 47), LINE_STRIDE and COLOR_DEPTH,
  turn it per WIN_OPTIONS (H/V direction, SCAN_COLUMN), scale it from
  PRESCALED_SIZE to SIZE, place it at POSITION, and stack and blend the
  windows by depth and BLEND_*. When the surface on show was turned on
  its way to the panel, by the DC or by VIC, the view undoes the turn,
  so Nyx still shows landscape. All the heuristics are gone.

hwtest's frame and Nyx's home screen are pixel-identical to before.
Nyx's error console (window D over window A) now shows; before, it was
invisible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 18:40:26 +00:00
Claude 39bfad6a0b Model the SDMMC host registers, eMMC HS200 tuning and HS400
The SDHCI power, clock, reset and HOST_CONTROL2 registers and Tegra's
vendor block all read 0, whatever was written. bdk picks the eMMC bus
mode from them: POWER_CONTROL reading "off" made it fall back to HS52,
so the eMMC ran at 51 MHz while its EXT_CSD claimed HS400.

- Keep a register file per controller for 0x28-0x3F and 0x100-0x1FF,
  with the TRM reset values. INTERNAL_CLK_STABLE follows INT_CLK_EN,
  the SW_RESET bits self-clear (RESET_ALL resets the standard registers,
  RESET_CMD/RESET_DATA clear their line's status), and the pad
  auto-calibration and DLL calibration complete at once.
- Model the tuning circuit (TRM 32.9.2.14). EXECUTE_TUNING starts it,
  each CMD19/CMD21 tries one tap against a fixed data eye, and after
  NUM_TUNING_ITERATIONS commands the final tap is set per MUL_M/DIV_N.
  The tuning block's BUFFER_READ_READY waits for the card clock to be
  re-enabled, which is the order bdk waits in.
- Keep EXT_CSD as one array per power cycle. CMD6 SWITCH updates its
  writable bytes, CMD8 reads them back, and CMD0 resets the card
  fields. BOOT0/BOOT1 and RPMB are 4 MiB, as on a Switch.

hwtest now tunes the eMMC in 128 iterations and reports a 199.68 MHz
HS400 card clock. The hwtest check asserts both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 18:37:38 +00:00
Claude 6753c5f3db Fix defects found in a code sweep and a TRM cross-check
Security Engine: CTR ignored its input and returned the raw keystream;
CBC encrypt skipped the IV on the first block and saved the wrong
chaining value, so every CMAC over more than one block was wrong; OFB
was broken. The datapath now follows INPUT_SEL/XOR_POS/VCTRAM_SEL the
way bdk drives it, and matches OpenSSL for ECB, CBC, OFB, CTR and
CMAC. SHA-256 works in parts (SHA_CONTINUE), SE_OP_CTX_SAVE reads keys
back as se_aes_ctx_get_keys() expects, unwrap honours the word quad,
guest block counts and LL sizes are bounded, and unreachable buffers
end the op with an error.

Soft reboot now resets the whole SoC (GPIO/pinmux cache, UARTs, I2C,
PMC, CAR, flow controller, SE, touch, SDMMC, display, ACTMON, ...)
while keeping what hardware keeps (PMC SCRATCH0, the RTC, and the PMIC
unless the reboot is a power cycle). DRAM gets fresh zero pages
instead of a memset that made all 2 GB resident; stale BPMP
translations are dropped; CPSR returns to SVC; scripts restart.

Execution: a branch to address 0 no longer hangs the emulator
(until=0 made PC 0 an exit); bdk's reset-then-bpmp_halt() reboots
instead of exiting; an untimed halt with CPU0 running parks the BPMP
and lets CPU0 continue; CPU0 starts in the same batch it is released
in; CPU0 drops translations of pages the BPMP rewrote; shared models
no longer see time run backwards.

TRM cross-check: RST_CPUG_CMPLX resets to 0x2000feef and CPU0 runs on
CPURESET0/CORERESET0/L2RESET/NONCPURESET (bit names corrected); RAM
repair clears REQ and sets STS, and is no longer a run condition;
refused releases are re-evaluated; MSELECT ENABLE_PCIE_APERTURE gates
PCIe; RST_DEVICES_W/Y direct writes land; DL_UP is read-only; the
whole config aperture and memory window decode; OSC_CTRL reports
38.4 MHz; PLLE/PLLREFE no longer get bit 27 forced into a divider;
PMC is a R/W register file; RTC SECONDS counts; FLOW halt modes follow
17.2.2 and STOP_UNTIL_IRQ wakes on the armed TMR; UART IIR/IER/
loopback MSR; I2C NOACK code and empty I2C4/I2C6 buses; pinmux reset
values; the COP ACTMON counts halt time.

Peripherals: MAX77620 LDO power-good follows the rail (hwtest's
gamecard probe no longer fails), the Erista GPU MAX77621 answers at
0x1C, regulators ACK per generation, RTC CONTROL is binary/24h, PS3
card detect reads "slot empty", packet-mode I2C parses 4 bytes per
word, rawnand I/O splits at part boundaries, eMMC returns to its user
area on CMD0, ADMA2 descriptors decode per spec, SD CMD6/ACMD13 data
reaches the programmed buffer, ERR_INTERRUPT is reported, R1 follows
block commands.

Frontend and tooling: touch events queue instead of overwriting each
other, map through rotation overrides and bdk's edge offset, and use
finger ID 0; a scripted press is always seen before its release;
zeroed fuses persist in the ini; dropped UTF-8 paths open on Windows;
bad --input-script is an error; test scripts check exit status and
missing arguments; make_sd.py quotes names and picks a FAT32-valid
cluster size; the Dockerfile marks the mount safe for git.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 17:45:02 +00:00
Claude f19a52b779 Run CCPLEX CPU0 so hwtest's PCIe probe completes, and speed up the core
hwtest-rcm's Wi-Fi probe hands PCIe to an AArch64 stub on CPU0, because
PCIe and MSELECT answer a CPU-complex master only. The emulator had no
CCPLEX, so the stub never reported; and the sweep never got that far
anyway, because it hung in the fan test.

CPU0 (t210/ccplex.cpp)
- A second Unicorn engine, AArch64, Cortex-A57, sharing IRAM, DRAM, TZRAM
  and every peripheral model with the BPMP. It starts when
  RST_CPUG_CMPLX_CLR releases CPU0 with every precondition of bdk's
  ccplex_boot_cpu0() met: CPU rail (MAX77621 + MAX77620 GPIO5 on Erista,
  MAX77812 EN_M4 on Mariko), CRAIL/C0NC/CE0, CPUG clock, PLLX, MSELECT,
  RAM repair, an AArch64 vector in SB_AA64_RESET_LOW/HIGH. A release that
  misses one is refused and the reason printed.
- Entered at EL3, MMU off, like silicon. Unicorn builds its ARM64 core at
  EL1 and neither a PSTATE write (stale hflags) nor an exception (never
  delivered) moves it, so a one-instruction ERET trampoline does.
- Its own clock (1 ns/instruction, 250 ns/bus access), run in 250 us
  lockstep slices behind the BPMP; WFE/WFI park it to the slice end.
- PCIe is master-aware: the BPMP still reads all ones, CPU0 is served.
  MSELECT, AFI_PCIE_CONFIG, LNKSTA, the endpoint class/BAR, the PCIE
  partition, PEX_L1 pinmux and PMC_GLB_AMAP_CFG take their measured values.

hwtest now runs its whole sweep and reports "WLAN core enumerated on the
PCIe bus" / "Wireless : pass", matching the healthy-console capture in
its README.

Performance
- No per-instruction hooks. Three UC_HOOK_CODE callbacks (one registered
  twice, one doing a uc_mem_read per instruction) are replaced by a block
  hook that counts each block's instructions once (cached), credited when
  it has run - the same totals, so the clock is unchanged.
- Peripherals are uc_mmio_map() windows instead of memory hooks, which
  had forced every guest load/store onto Unicorn's slow path; the register
  cache is a paged array instead of a std::map.
- The display reads the framebuffer straight from host DRAM, reuses its
  buffers, skips unchanged frames, and no renderer uses PRESENTVSYNC (a
  vsync'd present could stall the emulated CPU for a whole frame).
Reaching hwtest's fan test: 2.7 s -> 0.8 s; whole sweep ~3 s.

Reliability
- TIMERUS poll pacing: bdk's fan_get_speed() waits for TIMERUS to EQUAL a
  deadline (int - u32 is unsigned, so `> 0` is `!= 0`), and the dilated
  clock stepped past it, so the loop spun until TIMERUS wrapped. Polls at
  most 200 instructions apart now advance the clock by at most 1 us.
- MAX77621/MAX77812 are register files: bdk's hw_init() disabling the
  Erista CPU/GPU bucks used to be ignored and read back as enabled.
- Mariko reads FUSE_RESERVED_ODM28_B01 bit 0 set, so bdk addresses the
  retail MAX77812 at 0x33 instead of the NAK'd 0x31.
- Windows: disk images are opened O_BINARY (MinGW defaults to text mode,
  corrupting sectors) and rawnand chunks are sized with _fstati64.
- Soft reboot resets CPU0 and the PCIe root complex; the payload is
  loaded once, size-checked; an empty/unreadable payload is rejected; the
  NOP-slide check no longer trips on a counter that never reset; the M/C
  windows fall back to a software renderer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 15:55:48 +00:00
Baptiste MOINE 9f6e96001c Do not freeze the emulator while the melody plays
Playback waited for the sound card to drain before returning, and that runs
on the emulation thread: the whole emulator stopped for the length of the
take - 7.8 s of a 24.7 s hwtest run, measured - with the window not
repainting, which Windows paints as a hung application. Dropping a payload
on the picker looked like it had wedged.

Nothing needs the wait. The entire buffer is queued in one call before
playback starts, so SDL drains it in the background with no risk of
underrun; the device is simply left open for it. Same run is now 17.5 s with
no gap over 0.1 s, and the melody still plays in full.
2026-08-20 10:50:24 +02:00
Baptiste MOINE a71ccdf682 Take a dropped payload, and stop drowning the console
Double-clicking the emulator printed a usage line to a console nobody sees
and exited. It now opens a window that accepts a dropped .bin, with O for the
system file dialog - GetOpenFileName on Windows, zenity or kdialog on Linux,
since there is no such thing there without dragging in a toolkit. The window
draws a dashed frame and an upload glyph from rectangles and one filled
triangle; no text, because a font would have to be vendored for a screen that
lives a few seconds and the instruction is on the title bar already. It is
created and destroyed before the emulator's own display comes up, so it
cannot interfere with the framebuffer window. A headless or toolkit-less
machine falls back to the old usage message, and dragging a payload onto the
executable still skips all of it - that arrives as argv[1].

Dropping a payload was then unusably slow, and the reason had nothing to do
with the picker. A full hwtest sweep printed 52,452 lines, of which about
51,900 were per-register-access traces: 29,673 [gpio], 16,707 [mmio], 5,430
[sdmmc]. Redirected to a file that is merely wasteful, which is why it went
unnoticed - every scripted run here redirects. On a Windows console it is
not: each line goes through conhost one write at a time. Those traces now
need --trace or RCM_EMU_TRACE=1, which drops default output to 578 lines -
the payload's own UART plus the handful of [emu], [display], [pcie] and
[audio] lines worth seeing. The flag brings all 48,354 back when a
register-level question needs answering.

Also adds RCM_EMU_PICK, which runs the picker's window lifecycle and returns
a path as if it had been dropped, so that path can be tested by a script
instead of only by a human dragging a file.
2026-08-20 10:29:28 +02:00
Baptiste MOINE 390d64abe6 Play the emulated audio, and build for Windows
Two things, both about being able to check the emulator's work rather than
infer it.

Sound. The samples a payload pushes through the ADMAIF PIO port were being
discarded; now they are written to last_audio.wav and played on the host.
Each FIFO word is already a stereo frame, so the capture needs only a header.
The take is played after it is complete rather than streamed while it is
produced: the emulator generates samples in bursts and stalls entirely
between phrases while the payload talks to the codec over I2C, so a live
stream underruns wherever the producer falls behind the sound card, heard as
flicker. Queueing the finished buffer removes the producer from the timing
path. The rate comes from the I2S_TIMING the payload programmed, not a
nominal 48 kHz, or the melody replays at the wrong pitch.

Windows. Cross-compiled in a container, since neither dependency has a MinGW
package. Three things had to be fixed to get there, none of them findable
without actually trying it:

  - mingw GCC 13 hits an internal compiler error on unicorn's
    qemu/softmmu/memory.c at -O2, so unicorn is built at -O1.
  - pread/pwrite are POSIX and absent on MinGW. The SD/eMMC image access now
    has a seek-then-read shim, which is equivalent here because the emulated
    storage is only touched from the CPU thread.
  - SDL renames main on Windows, so SDL2main must be linked before SDL2 with
    SDL_MAIN_HANDLED, and unicorn's threads need winpthread.

The .exe is static: one file, no DLLs beside it. Verified running natively -
it emulates a full hwtest sweep and plays the melody through WASAPI.

CI covers both platforms, and a third job runs the .exe on a Windows runner,
because a cross-build only proves it links. Builds on push and PR, not just
tags: the Windows build broke in three separate ways the first time it was
attempted, and a Linux-only workflow would have shown none of them.
2026-08-20 10:05:33 +02:00
Baptiste MOINE 6782304549 Model the radios, the PCIe root port and the audio hub
Enough of the T210 to run the whole hwtest sweep. Before this the run died
partway through the audio pages, so Display, Inputs, Raw state and the
Diagnostics verdict never executed at all - 30 pages of 42.

Bluetooth: the CYW4356 as a state machine behind UART-D, with the strap and
power-on sequencing the real part needs, plus the PINMUX, GPIO port H and
UART plumbing it hangs off. Selectable healthy / faulty / absent, so the
failure paths a working console will not produce can still be exercised.

PCIe: MSELECT, the XUSB pad controller and the root port, with the WLAN
endpoint answering config reads. The apertures sit below every other
peripheral, so they need their own hook range.

Audio: the APE hub - I2S, ADMAIF and ADMA - and the ALC5639 codec on I2C_1.
Three details matter. ADMAIF was not dispatched at all, so the ~224k PIO
sample writes of one melody each fell through to the logging arm and the run
drowned in its own output. I2S registers returned 0 rather than what was
programmed, which turned "64 bclk/frame, fs 23437 Hz" into "2 bclk/frame,
fs 750000 Hz". And the codec is big-endian on the wire while bdk packs the
buffer little-endian, so its registers are byte-swapped on the way out.

I2C now NAKs addresses with nothing behind them. Answering every address
made a bus census report all 112 as populated, and made a headphone amp that
is not fitted on this board look present - hwtest then decoded its zeroed
registers as real readings. An emulator that says yes to everything cannot
test a probe whose job is deciding what is there.
2026-08-20 09:18:54 +02:00
Baptiste MOINE 7693df269a Model measured Erista identity, rails, clocks and PLLs 2026-08-08 00:20:56 +02:00
Baptiste MOINE 7f2dbefa5d Model fan tachometer and fix the Port Z IN offset 2026-08-08 00:20:56 +02:00
Baptiste MOINE a3ab1b193f Report SDMMC bus width and measured EXT_CSD capabilities 2026-08-08 00:20:56 +02:00
Baptiste MOINE 7ee0c52763 Model the BH1730 ambient light sensor on I2C2 2026-08-08 00:20:56 +02:00
Baptiste MOINE bc2f03a6a6 Honour UART DLAB and mirror UART config registers 2026-08-08 00:20:56 +02:00
Baptiste MOINE 2b5a5c9cb0 Model PLL state, PTO clock counter and OSC detect 2026-08-08 00:20:55 +02:00
Baptiste MOINE 7c1ab28563 Model measured Mariko PMIC, HIDREV and KFUSE state 2026-08-08 00:20:55 +02:00
Baptiste MOINE 6fb2aecd20 Stop the RTC window from shadowing the PMC block 2026-08-08 00:20:55 +02:00
Baptiste MOINE 265ca5404c Serve measured MAX77620 CID3 and CID5 as whole bytes 2026-08-08 00:20:55 +02:00
Baptiste MOINE 5caa4d5e2d Model SD1 and SD2 per SoC generation 2026-08-08 00:20:55 +02:00
Baptiste MOINE 1cc1e88bcc Complete FLOW_CTLR RAM repair handshake 2026-08-08 00:20:55 +02:00
Baptiste MOINE da5370b2ec Model SOC_THERM on-die thermal sensors 2026-08-04 01:17:52 +02:00
Baptiste MOINE 16cbccde47 Map DRAM as one contiguous window 2026-08-04 01:17:52 +02:00
Baptiste MOINE b5b610fbc2 Model ACTMON activity monitor 2026-08-04 01:17:52 +02:00
Baptiste MOINE 1efbc945cf Resume BPMP on timed FLOW_CTLR halts 2026-08-04 01:17:52 +02:00
Baptiste MOINE 8c4fa8d98b Serve KFUSE key block and report DRAM size 2026-08-04 01:17:52 +02:00
Baptiste MOINE 895779c00c Model PMIC and RTC I2C registers, persist writes 2026-08-04 01:17:51 +02:00
Baptiste MOINE dc6d3364d7 Extend GPIO mirror to CNF / OE / OUT reads 2026-05-03 10:09:16 +02:00
Baptiste MOINE ef5870b6f0 Mirror MMIO writes for PINMUX, PWM, and GPIO IN read-back 2026-05-03 09:42:43 +02:00
Baptiste MOINE 1da383f8d2 React to PMIC PWR_OFF / SFT_RST and PMC MAIN_RST 2026-05-03 09:42:43 +02:00
Baptiste MOINE e527872acb Track per-port UART TX log and host-injected RX FIFO 2026-05-03 09:42:42 +02:00
Baptiste MOINE 8559909f2d Populate fuse defaults and unblock Dump fuses 2026-05-03 09:42:42 +02:00