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
This commit is contained in:
Claude committed 2026-09-25 17:45:02 +00:00
1 parent 11ad2e4d9f
commit 6753c5f3db
26 files changed
+1615 -588

No files matched your search

+13 -9
View File
@@ -67,7 +67,10 @@ constexpr uint64_t I2C2_BASE = 0x7000C400; // GEN2_I2C, Rohm BH1730 ALS at slave
constexpr uint64_t I2C2_SIZE = 0x100;
constexpr uint64_t I2C3_BASE = 0x7000C500; // GEN3_I2C, used by STMFTS touchscreen at slave 0x49
constexpr uint64_t I2C5_BASE = 0x7000D000;
constexpr uint64_t I2C_SIZE = 0x1000;
constexpr uint64_t I2C_SIZE = 0x1000; // the MMIO page: I2C5, I2C6, SPI2B
constexpr uint64_t I2C_CTRL_SIZE = 0x100; // one controller's registers
constexpr uint64_t I2C4_BASE = 0x7000C700;
constexpr uint64_t I2C6_BASE = 0x7000D100;
constexpr uint64_t I2C3_SIZE = 0x100;
// PWM
@@ -203,12 +206,13 @@ constexpr uint64_t XUSB_PADCTL_SIZE = 0x1000;
// bdk's MMU table defines DRAM and IRAM entries only and leaves the fallback
// entry RWX, so PCIe space is reachable and uncached.
//
// Only the windows a payload actually touches are mapped: 16 KiB covering
// both root ports plus PADS and AFI, 128 KiB of configuration aperture (bus
// 0 and bus 1 are all that exist), and one 4 KiB page of downstream memory
// for the endpoint's BAR0 register window. Mapping the architectural sizes
// (256 MiB of config, 208 MiB of memory) would cost the host gigabytes for
// address ranges nothing ever reads.
// These are MMIO windows (callbacks, no backing memory), so they are mapped
// at their architectural sizes: the whole 256 MiB configuration aperture -
// extended registers sit at AXI[27:24] - and the non-prefetchable memory
// window to the end of PCIE_A2, wherever software places the endpoint's BARs.
// A smaller map left a CPU0 access to, say, config offset 0x100 or BAR0 +
// 0x2000 unmapped: nothing answered and the core wedged, where silicon
// returns data or all-ones.
constexpr uint64_t PCIE_RP0_BASE = 0x01000000; // root port 0 registers
constexpr uint64_t PCIE_RP1_BASE = 0x01001000; // root port 1 registers
constexpr uint64_t PCIE_PADS_BASE = 0x01003000;
@@ -216,9 +220,9 @@ constexpr uint64_t PCIE_AFI_BASE = 0x01003800;
constexpr uint64_t PCIE_BLOCK_BASE = 0x01000000;
constexpr uint64_t PCIE_BLOCK_SIZE = 0x4000;
constexpr uint64_t PCIE_CS_BASE = 0x02000000; // type-1 extended config
constexpr uint64_t PCIE_CS_MODEL_SIZE = 0x20000; // buses 0 and 1 only
constexpr uint64_t PCIE_CS_MODEL_SIZE = 0x10000000; // all of it: 256 MiB
constexpr uint64_t PCIE_MEM_BASE = 0x13000000; // non-prefetchable window
constexpr uint64_t PCIE_MEM_MODEL_SIZE = 0x1000;
constexpr uint64_t PCIE_MEM_MODEL_SIZE = 0x0D000000; // up to the end of A2
// TSEC (Falcon control regs are in the 0x1000–0x11FF window within TSEC_BASE)
constexpr uint64_t TSEC_BASE = 0x54500000;