Files
RCM-Emulator/README.md
T

437 lines
25 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RCM-Emulator
![Hekate running in the emulator](img/hekate.png)
A host-side emulator for Nintendo Switch RCM (Recovery Mode) payloads. Loads a
precompiled `.bin` (Hekate, Lockpick_RCM, TegraExplorer, custom payloads) and
executes its ARM32 code on an emulated Tegra X1 (T210) environment, with a
windowed framebuffer and keyboard input mapped to the Switch hardware buttons.
It is **not** a console emulator. The BPMP (Boot and Power Management
Processor) bootloader stage is what is modelled, plus CPU0 of the main CPU
cluster for payloads that boot it to run bare-metal AArch64 code. You will not
boot Horizon, run NSPs, or load games. The intended use is payload development and scripted
verification, plus security research where iterating on real hardware would be
slow or destructive.
## What it can do
- Run **Hekate** (CTCaer) through the IPL (Initial Program Loader) warning into
the Nyx GUI.
- Run **Lockpick_RCM** through key derivation. The `--prod-keys` shortcut
bypasses the parts of the chain that aren't fully modelled.
- Run **TegraExplorer**, including `.te` script execution from an emulated SD
card.
- Run **hwtest-rcm**'s complete hardware sweep in a few seconds, including its
Wi-Fi probe, which boots **CPU0** (Cortex-A57, AArch64) to bring up PCIe and
enumerate the CYW4356 - PCIe answers a CPU-complex master only. See
[CCPLEX CPU0](#ccplex-cpu0).
- Replay deterministic button sequences via `--auto-pin-recovery` or
`--auto-te-script`, so a payload flow can be exercised from a CI run or a
one-shot script. `--input-script` scripts buttons and touchscreen taps for
any payload, and can save the screen at a given point of a run.
- Plug an emulated PC into the USB-C port (`--usb-host`): Nyx's USB mass
storage and gamepad gadgets enumerate on both the Erista (USB2) and Mariko
(XUSB) device controllers, and the PC reads a mass storage disk back,
checks it against the SD image, writes a few sectors back unchanged and
ejects it. With `--usb-host nbd` the PC serves the disk over NBD instead,
so it can be mounted on the machine running the emulator.
- Boot a Linux kernel on CPU0 (switchroot's L4T 4.9), with a GIC-400, the
generic timer, PSCI and the clock controller's reset values for it. See
[Booting Linux on CPU0](#booting-linux-on-cpu0).
- Put a dock on the USB-C port (`--dock`): a Nintendo dock, a third-party
USB-C adapter or a Nintendo charger on the BM92T36, the dock's
DisplayPort-to-HDMI converter on DPAUX1, and a TV in a second window that
shows what display head B sends through SOR1. hwtest-rcm's Dock Test runs
its whole handshake and TV link against it.
- Tweak emulated hardware live (battery, charger, thermal, USB-PD, PMIC,
fuses, SD insertion, the USB host) from a side window. See [Live hardware tweaks](#live-hardware-tweaks).
- Inspect each Tegra UART port (TX history) and inject keystrokes into the
payload's RX FIFO from a separate console window. See [UART console](#uart-console).
- Read real eMMC (embedded MMC) dumps (`BOOT0`, multi-part `rawnand.bin.NN`)
and decrypt them with XTS-AES-128 (XEX-based Tweaked-codebook with ciphertext
stealing) against keys from `prod.keys`.
- Serve a real FAT32 SD image to the payload (`--sd sd.img`). Without one the
SD slot is empty.
## Quick start
### Build (Linux / WSL)
```bash
sudo apt-get install -y build-essential libunicorn-dev libsdl2-dev
make
```
Booting a kernel on CPU0 needs Unicorn 2.1 or later: 2.0.x, which some
distributions still ship, checks guest accesses by virtual address once the
guest MMU is on. Build one into a prefix and point the Makefile at it, which
links it statically (`make clean` first when switching):
```bash
make UNICORN_DIR=$HOME/opt/unicorn-2.1
ldd rcm_emu | grep unicorn # prints nothing when the static one is in
```
### Build (Docker)
```bash
docker build -t rcm-emulator .
docker run --rm -v "$(pwd):/work" rcm-emulator
```
### Build an SD image
`make_sd.py` packages a source folder into a FAT32 image you can pass to
`--sd`. It uses Docker (alpine + dosfstools + mtools), so no `sudo` or loop
mounts are needed.
```bash
python3 make_sd.py --src ./sd_root --out sd.img --size-mb 512
```
`./sd_root` is your usual SD card layout (`bootloader/`, `switch/`, etc.).
The result drops in directly as `--sd sd.img`.
#### Build the SD from scratch (HATS + Parental-PIN-RCM)
This produces a fully populated `sd_root` (Hekate + TegraExplorer + the
PIN-recovery script) and bakes it into `sd.img`:
```bash
# 1. Pull the latest HATS release from sthetix.
HATS_URL=$(curl -s https://api.github.com/repos/sthetix/HATS/releases/latest \
| grep -oE '"browser_download_url": "[^"]+\.zip"' \
| head -1 | cut -d'"' -f4)
curl -L -o hats.zip "$HATS_URL"
mkdir -p sd_root
unzip -q hats.zip -d sd_root
# 2. Drop the recover_pin.te script into the path TegraExplorer reads
# (HATS puts it at sd:/scripts/).
git clone --depth 1 https://github.com/Creased/Parental-PIN-RCM
mkdir -p sd_root/scripts
cp Parental-PIN-RCM/recover_pin.te sd_root/scripts/
# 3. Bake everything into a FAT32 image.
python3 make_sd.py --src ./sd_root --out sd.img --size-mb 512
```
HATS already ships `TegraExplorer.bin` under `bootloader/payloads/`, so no
extra payload download is needed.
### Demo: PIN recovery
The screenshot below shows a full parental-PIN recovery run inside the
emulator. Setup:
- `sd.img` was built from a HATS-by-sthetix archive (extracted, then packaged
with `make_sd.py`).
- The `recover_pin.te` script under `scripts/` on that SD comes
from [Creased/Parental-PIN-RCM](https://github.com/Creased/Parental-PIN-RCM).
- `backup/BOOT0` and `backup/rawnand.bin.NN` are an eMMC dump produced by
Hekate (Tools, Backup eMMC).
- `backup/prod.keys` is the keyfile produced by running Lockpick_RCM on the
same console.
Boot Hekate, then chain-load TegraExplorer from the SD and run the script:
```bash
./rcm_emu ./hekate_ctcaer_6.5.2.bin \
--sd ./sd.img \
--boot0 ./backup/BOOT0 \
--rawnand ./backup/rawnand.bin \
--prod-keys ./backup/prod.keys
```
In the Nyx GUI: Tools, Launch payload, pick `TegraExplorer.bin`. From the TE
main menu: Scripts, `recover_pin.te`, Recover from sysmmc. The PIN appears in
green:
![PIN recovery demo](img/pin_recovery_demo.png)
### Running without arguments
Starting the emulator with no payload opens a small window that takes a
dropped `.bin`, or press **O** for the system file dialog (zenity or kdialog
on Linux). Dragging a payload onto the executable itself still works and
skips the picker - it arrives as `argv[1]`.
### Build (Windows)
Cross-compiled from Linux in a container, because neither dependency has a
MinGW package: SDL2 ships a devel tarball and unicorn has to be compiled.
```sh
docker build -f Dockerfile.windows -t rcm_emu_win .
docker run --rm -v "$PWD:/work" rcm_emu_win # produces rcm_emu.exe
```
The result is statically linked - one `rcm_emu.exe` with no DLLs beside it.
Audio goes to WASAPI on Windows and ALSA/PulseAudio on Linux; SDL picks the
backend, so nothing in the emulator cares which. `RCM_EMU_NO_AUDIO=1` skips
playback entirely, which is what CI uses since a runner has no sound device.
## CCPLEX CPU0
A payload can boot the first Cortex-A57 exactly as bdk's `ccplex_boot_cpu0()`
does - CPU rail, PLLX, CCLK, the CRAIL/C0NC/CE0 partitions, RAM repair, the
AArch64 vector in `SB_AA64_RESET_LOW/HIGH`, then `RST_CPUG_CMPLX_CLR` - and the
emulator runs it: AArch64, entered at EL3 with the MMU off at the vector,
sharing IRAM, DRAM and every peripheral with the BPMP, in lockstep with it on
the emulated clock. Output is prefixed `[ccplex]`:
```
[ccplex] CPU0 released: AArch64 EL3, MMU off, entry 0xA0000000 (boot #1)
[pcie] root port 1: link UP, gen1 x1 (healthy WLAN)
[uartB] CPU0 : ran to completion (hb=613)
[uartB] AFI (CPU) : cfg=00103025 witness=A5A50000 -> APERTURE LIVE
[uartB] RP1 link : UP, DL active (LNKSTA=3011 gen1 x1)
[uartB] EP config : 14E4:43EC Broadcom BCM/CYW4356 WLAN
[uartB] Result : WLAN core enumerated on the PCIe bus
[ccplex] CPU0 stopped (held in reset) after 19402985 instructions, 4846717 bus accesses
```
A release with something missing does not run the core - silicon would not -
and says what was missing, e.g. `[ccplex] CPU0 released from reset but cannot
run: CPU rail off (MAX77621 VOUT_EN / MAX77620 GPIO5 EN pin)`. PCIe and
MSELECT answer CPU0 only; the BPMP reads all ones from them, as measured on
real consoles. Details in [DESIGN.md](DESIGN.md#ccplex-cpu0).
### Booting Linux on CPU0
`linux/` boots an arm64 kernel Image, switchroot's L4T 4.9 for instance, the
way a bootloader would hand over to it:
```bash
linux/build.sh # linux/boot.bin (arm-none-eabi + aarch64 gcc)
linux/mkdtb.sh tegra210-odin.dtb odin-emu.dtb # console on UART-B, one CPU
linux/run.sh Image odin-emu.dtb boot.log 120
```
`--load FILE@ADDR` places the Image at 0x80080000 and the device tree at
0x83000000 before the payload starts; `linux/boot.bin` sets the clocks and
the CPU rail, releases CPU0 into `linux/shim.S`, which drops to EL1 with the
device tree in x0, and halts the BPMP. For the kernel, CPU0 has a GIC-400
(distributor and CPU interface), the generic timer counting emulated time
at 19.2 MHz, interrupts taken at block boundaries, BRK and undefined
instructions taken to its own vectors (WARN and BUG), PSCI on SMC, WFI
sleeping to the next timer, TMR10..13 as clock event timers, and every
unmodelled page of the peripheral band mapped as plain registers on first
access. The clock controller's registers read their TRM reset values until
written ([t210/car_reset.h](t210/car_reset.h)), since the kernel's clock
driver walks hundreds of them. `RCM_EMU_CPU0_PROFILE=1` prints where CPU0 is
once a second of real time, to tell a hung kernel from a slow one. The
console comes out on UART-B; the saved runs reach the kernel's core
initialisation.
## Tests
```bash
make test # CCPLEX, kernel CPU, SE, USB + display regression payloads (arm-none-eabi-gcc, aarch64 gcc, python3)
tests/hwtest/build.sh build-hwtest # build hwtest-rcm (+ gcc-aarch64-linux-gnu)
tests/hwtest/run.sh ./rcm_emu build-hwtest/hwtest-rcm/build/hwtest.bin
```
`make test` runs small self-contained payloads: one boots CPU0 and checks the
refusal of an unpowered release, the EL3 entry, the mailbox, a stopped clock,
WFE parking and the reset, then runs again with a dead CPU rail and dead
bucks (`--fault`) and checks the RAM repair is held and the core stays dark;
one drops CPU0 to EL1 and checks it takes timer interrupts through the GIC,
a BRK into its own vector and a PSCI call over SMC;
one checks the Security Engine's RSA, SHA-256, AES
and RNG against vectors computed in Python; one brings up a USB mass storage
gadget on each device controller (and a HID gadget) for the `--usb-host` PC to
enumerate, read back and write, and serves it over NBD to a Python client;
one drives the display controller and VIC and
compares the frame pixel for pixel. The hwtest scripts run hwtest-rcm's whole
hardware sweep headless and check that the CPU0-driven Wi-Fi probe enumerates
the endpoint. CI runs both.
## Mounting a gadget's disk
`--usb-host nbd` turns the emulated PC into a bridge: when a mass storage
gadget attaches - Nyx's SD card, eMMC or emuMMC under USB tools - the PC
locks the medium (PREVENT MEDIUM REMOVAL, so Nyx will not unload it from its
side) and serves it with the NBD protocol on 127.0.0.1, port 10809 or the one
given as `nbd:<port>`. Every NBD read, write and flush becomes SCSI
commands to the gadget, so what reaches the SD image goes through bdk's UMS
code as it would from a real PC. A write-protected disk (Nyx's eMMC in its
default read-only mode) is exported read-only.
```sh
./rcm_emu hekate.bin --sd sd.img --usb-host nbd
# in Nyx: Tools > USB Tools > SD Card, then on the host:
sudo modprobe nbd max_part=8
sudo nbd-client 127.0.0.1 10809 /dev/nbd0 -b 512
sudo mount /dev/nbd0p1 /mnt # ... use it ...
sudo umount /mnt && sudo nbd-client -d /dev/nbd0 # the disk is ejected
```
Without root, `qemu-img convert nbd://127.0.0.1:10809 copy.img` takes a
copy, `qemu-io nbd://127.0.0.1:10809` reads and writes sectors, and
`nbdfuse` exposes the disk as a file. The session ends when the client
disconnects: the PC allows removal and ejects, and Nyx reports "Disk
ejected". The port only listens while a disk is being served. In the config
window, the USB device mode section has the same switch and port.
## Live hardware tweaks
Press `M` in the main window to open a second window that exposes the values
the payload reads from the emulated chips. Edits apply on the next register
read, with no restart and no recompile. Use it to exercise payload code that
branches on hardware state (low-battery warnings, thermal throttling, charger
detect, SD eject, OEM-specific PMIC forks, and similar) without needing the
state to occur on real hardware.
![Live hardware-config window](img/config_menu.png)
What's tweakable, grouped by chip:
| Chip | Bus / addr | Tweakable |
| ----------------------- | --------------- | ----------------------------------------------------------------------------------------------- |
| **MAX17050** fuel gauge | I2C\_1 @ 0x36 | SOC %, VCELL, OCV, Temp, Current, RepCap, FullCAP, DesignCap, V\_empty, Min/Max volt, Age, Cycles |
| **TMP451** thermal | I2C\_1 @ 0x4C | SoC die temp, PCB temp |
| **BQ24193** charger | I2C\_1 @ 0x6B | VBUS, charge state, power-good, input current/voltage limit, system min, fast-charge current, charge voltage limit, thermal regulation |
| **BM92T36** USB-PD | I2C\_1 @ 0x18 | Cable-inserted, PDO voltage, PDO amperage |
| **MAX77620** main PMIC | I2C\_5 @ 0x3C | OTP (Erista / Mariko), silicon revision |
| **MAX77621** CPU/GPU PMIC | I2C\_5 @ 0x1B | Chip ID |
| **Tegra fuses** | FUSE 0x7000F800 | 30+ fuse offsets: PRODUCTION/SKU/IDDQ/SPEEDO, OPT_FT/CP_REV, RESERVED_SW, RESERVED_ODM0..ODM7 (incl. anti-downgrade presets for HOS 13.2.1 / 22.0.0), VENDOR/FAB/LOT/WAFER, GPU_IDDQ, PK0..7, SBK + DK |
| **DRAM modules** | EMC 0xEC (MR5-8)| Vendor (MR5), Rev ID 1/2 (MR6/MR7), per-die density (MR8 5:2) |
| **GPIO** | Port Z bit 1 | SD card insert / eject |
| **Display** | EmuState | Backlight, rotation override |
| **Emulation** | EmuState | Pause / resume, button visualization |
A few example tweaks:
- Drag SOC % down to 5%. The Hekate "low battery" branch fires.
- Drop SoC temp to 95 °C. The thermal-throttle path triggers.
- Toggle VBUS to None and Power good off. Hekate flips to the "no charger"
state.
- Set Charge voltage limit to 4096 mV. The Battery Info screen reflects it
on the next poll.
- Toggle SD card inserted off mid-boot. The SD-detect path sees no card,
which is useful for testing failure handling.
- Switch PMIC OTP to Mariko (0x53). The OEM-detection branch prints
"Mariko OTP" instead of "Erista OTP".
The full layout (sliders, combos, hex inputs for fuses) lives in
[display/config_window.cpp](display/config_window.cpp). Encoding logic that
maps each user-facing decoded value back to the chip's raw register format
is in [t210/mmio.cpp](t210/mmio.cpp). Each encoder mirrors a corresponding
`*_get_property()` formula in the Hekate `bdk/power/` tree.
## UART console
Press `C` in the main window to open a third SDL window that exposes the
Tegra UART block. It lets you:
- Pick which port (UART_A..UART_E) to inspect from a combo box. The TX
history pane shows every byte the payload has written to that port's
THR (Transmit Holding Register), auto-scrolled.
- Type bytes into the input line and "Send" them; they land in the
emulator's RX FIFO so the next CPU-side `uart_recv()` returns them.
Useful for paged probes that ask the user for input over UART (e.g.
hwtest's pager keys `n` / `p` / `r` / `s` / `q` and the CR / LF
shortcut buttons next to the input field).
Implementation in [display/console_window.cpp](display/console_window.cpp).
Per-port TX log + RX FIFO storage lives in
[emu_state.h](emu_state.h)::EmuState. Both the CPU emulation and ImGui
rendering run on the main thread between SDL polls, so no locking is
needed.
## Controls
| Key | Switch button / action |
| -------------- | ------------------------------- |
| `↑` / `↓` | VOL+ / VOL– |
| `Enter` | POWER |
| Mouse click | Touch (Nyx, TE menus) |
| `M` | Open / close hardware-config window (see [Live hardware tweaks](#live-hardware-tweaks)) |
| `C` | Open / close UART console window (see [UART console](#uart-console)) |
| `R` | Soft reboot |
| `P` | Pause or resume emulation |
| `Ctrl+R` / `Ctrl+Shift+R` | Cycle display rotation CW / CCW |
| `S` | Cycle swizzle override |
| `Esc` | Quit |
## Command-line flags
| Flag | Argument | Purpose |
| --------------------- | ------------- | --------------------------------------------------------- |
| `--sd` | `sd.img` | Back the SD card (SDMMC1) with this raw FAT32 image. Without it (and with no `sd.img` in the working directory) the slot is empty. |
| `--boot0` | `BOOT0` | eMMC BOOT0 partition file (SDMMC4). |
| `--rawnand` | `rawnand.bin` | eMMC GPP partition prefix (auto-detects `.00`, `.01`, …). |
| `--prod-keys` | `prod.keys` | Override BIS keys from a Lockpick-style key file. |
| `--oem` | `erista` \| `mariko` | Switch SoC generation. Drives `APB_MISC_GP_HIDREV` so Hekate's `h_cfg.t210b01` matches and pkg1 identification skips the right OEM header. Default `erista`. |
| `--bt-radio` | `healthy` \| `faulty` \| `absent` | Broadcom CYW4356 behaviour on UART-D. `healthy` powers up on the `BT_REG_ON` edge, holds `BT_HOST_WAKE` high, asserts `RTS_N` and answers HCI; `faulty` reproduces the 2110-1118 console (module fitted, never leaves POR); `absent` additionally leaves `BT_UART_RXD` in a break condition. Overrides `[bluetooth] radio` in the ini. Default `healthy`. |
| `--wifi-radio` | `healthy` \| `faulty` \| `absent` | The WLAN half of the same CYW4356: a PCI Express endpoint on root port 1, reachable only from CPU0 (the BPMP reads all ones, as on silicon). `healthy` trains the link, enumerates as `14E4:43EC` and answers a ChipCommon ChipID read with `0x4356`; `faulty` still trains and enumerates but reads all ones on the backplane (live PCIe front-end, dead radio die); `absent` never leaves detect. The model also enforces the datasheet's power-up ordering, so a payload that releases PERST# too early gets a link that stays down and a `[pcie]` line naming the reason. Overrides `[wifi] radio` in the ini. Default `healthy`. |
| `--fault` | `NAME[,NAME…]` \| `list` | Break a chip or a rail; repeatable. A **chip** fault (`max77812`, `max77621_cpu`, `max77621_gpu`, `bq24193`, `max17050`, `tmp451`, `bm92t36`) makes the part NAK its I2C address, refuse writes and take every rail it supplies down with it. A **rail** fault (`vdd_cpu`) leaves the regulator answering and reading back as enabled while its output never comes up, so only what the rail feeds notices: the CPU RAM repair never completes and CPU0 cannot run. `list` prints the names and exits. Faults survive a payload reboot, like the hardware they model, and add to `[faults]` in the ini (`NAME=dead`). See [DESIGN.md](DESIGN.md#fault-injection). |
| `--usb-host` | `nbd[:port]` (optional) | A PC on the USB-C port. It enumerates whatever USB gadget the payload brings up; a mass storage disk is read back (checked against the SD image), its last 8 sectors are written back unchanged and read again unless it is write-protected, and it is ejected; HID reports are polled. With `nbd` the disk is served over NBD on 127.0.0.1 (port 10809 by default) until the client disconnects, then ejected - see [Mounting a gadget's disk](#mounting-a-gadgets-disk). Logged as `[usb-host]`; `RCM_USB_TRACE=1` traces every transfer. Overrides `[usb] host` and `[usb] nbd_port` in the ini. |
| `--load` | `FILE@ADDR` | Place a file in DRAM before the payload starts, the way a bootloader leaves a kernel and its device tree; repeatable. See [Booting Linux on CPU0](#booting-linux-on-cpu0). |
| `--dock` | `nintendo` \| `thirdparty` \| `charger` \| `none`, `:notv` | What is on the USB-C port, behind the BM92T36: a Nintendo dock (057E:2003, 15 V, Nintendo's alt mode, DisplayPort on pin D), a third-party adapter (Fresco Logic 1D5C:7102, four power profiles, the DisplayPort SVID) or the Nintendo charger (057E:2004, no video). A dock's DisplayPort-to-HDMI converter answers on DPAUX1 (DPCD 1.2, the TV's EDID over I2C-over-AUX), and SOR1 judges link training lane by lane against the board's wiring; once trained, head B's frames show in a TV window. `:notv` leaves the dock's HDMI empty. `RCM_EMU_TV_SNAP=file` saves the TV picture, `RCM_EMU_DPTRACE=file` traces DPAUX1 and SOR1. Overrides `[dock] kind` and `[dock] tv` in the ini. Default `none`. |
| `--input-script` | file or spec | Scripted input keyed to emulated time: `<ms> P\|U\|D [hold_ms]` presses POWER / VOL+ / VOL-, `<ms> TAP <x> <y> [hold_ms]` taps the touchscreen at (x, y) in the 1280x720 picture, `<ms> SNAP <file>` saves the next displayed frame to `<file>` (raw B, G, R, A like `last_fb.rgba`, size in the matching `.meta`), `+N` times an event N ms after the previous one. Events are separated by `,`, `;` or newlines. |
| `--auto-pin-recovery` | (none) | Drive the Lockpick PIN-recovery menu without user input. |
| `--auto-te-script` | (none) | Drive `recover_pin.te` in TegraExplorer without input. |
## Repo layout
```mermaid
flowchart LR
root["RCM-Emulator/"]
root --> top["main.cpp<br/>emu_state.h<br/>Makefile<br/>Dockerfile<br/>README.md / DESIGN.md"]
root --> t210["t210/<br/>(SoC peripheral models)"]
root --> display["display/"]
root --> linux["linux/<br/>kernel boot: boot.c, shim.S, run.sh"]
root --> tests["tests/<br/>ccplex/, kernelcpu/, se/, usb/, display/, hwtest/"]
t210 --> mmio["mmio.{h,cpp}<br/>memory_map.h<br/>regcache.h, tegra_bl.h"]
t210 --> cpus["bpmp.{h,cpp} BPMP clock<br/>ccplex.{h,cpp} CPU0 (A57)<br/>gic.{h,cpp} GIC-400"]
t210 --> pcie["pcie.{h,cpp}<br/>root complex + CYW4356"]
t210 --> se["se_engine.{h,cpp}<br/>AES-128, SHA-256, RSA, RNG"]
t210 --> i2c["i2c3.{h,cpp}<br/>STMFTS / FTS4 touch"]
t210 --> usb["usb.{h,cpp}<br/>USB device controllers + host PC"]
t210 --> dock["dock.{h,cpp}<br/>BM92T36, the dock, DPAUX1, SOR1"]
display --> sdl["sdl_display.{h,cpp}<br/>DC window scan-out<br/>+ SDL2"]
```
For implementation details, see [DESIGN.md](DESIGN.md).
## Limitations
- **BPMP plus one A57.** CPU0 runs bare-metal AArch64 handed to it by a
payload; there is no GIC, no generic timer, no secondary cores and no guest
exception delivery (a fault halts CPU0 and says so). Horizon and Atmosphère
are out of reach.
- **Subset of MMIO (Memory-Mapped I/O).** Peripherals are modelled to the depth
required by the payloads above. New payloads may exercise registers that fall
through to the default catch-all and need handlers added.
- **Key derivation chain is partial.** The TSEC (Tegra Security Co-processor)
firmware and the full master-key unwrapping flow are not faithfully emulated.
`--prod-keys` is a pragmatic shortcut: when Lockpick writes a derived BIS
(Boot Image Storage) key into a keyslot, the value from the user-supplied key
file is substituted. The random number generator starts from a fixed
seed, so runs repeat.
- **Single-threaded.** Both cores run in batches on the main thread between
SDL event polls. That is also what keeps them deterministic.
- **The USB host drives mass storage and HID only.** A gadget of another
class is enumerated and left configured. Over NBD, one client has the disk
per session: when it disconnects - `nbdinfo` and `qemu-img info` do so as
soon as they have their answer - the disk is ejected, as a PC ejects a
disk it has unmounted.
## Acknowledgements
Heavy reliance on the work of:
- [Unicorn Engine](https://www.unicorn-engine.org/) for CPU emulation.
- [Hekate / BDK](https://github.com/CTCaer/hekate) as peripheral and
key-derivation reference.
- [Lockpick_RCM](https://github.com/shchmue/Lockpick_RCM) for keyslot
semantics.
- [TegraExplorer](https://github.com/suchmememanyskill/TegraExplorer) for the
`.te` script harness.
- TinyAES (kokke) for the AES-128 reference implementation.