code wiki / _hdl_build / nx_fw_robust_flash.nx

nx_fw_robust_flash.nx

buildroot/runtime/_hdl_build/nx_fw_robust_flash.nx

7123 B125 linesdepth 6pulls 7 transitivereach 1 importersview sourcekind tooltopic fw
docsdependenciesstructsconstsfunctions

about

nx_fw_robust_flash.nx -- S-CLASS never-brick: survives suboptimal/adverse conditions. module: nishi-core.genealogy.fw_robust_flash capability: CORE_COMPUTE (never-brick that holds through power loss at ANY step + double faults) THE PROBLEM (operator 2026-06-16: "make our never brick s class even in suboptimal situations"): nx_fw_safeflash's golden recovery assumes the golden anchor is always intact and the recovery itself completes. Real devices brick from the SUBOPTIMAL cases: power loss MID-flash, power loss MID-recovery, a corrupted recovery copy, torn writes, double faults. S-class never-brick must survive ALL of them. The proven field design (dual-BIOS + flashback ROM) is modeled here: * TWO banks A/B + an IMMUTABLE FACTORY anchor (the write-protected last resort). * A flash writes ONLY the INACTIVE bank, verifies it (sha256), then ATOMICALLY flips a tiny selector (write-temp + rename -- power loss leaves it fully-old or fully-new, never torn). The ACTIVE bank is NEVER overwritten, so a crash before the commit leaves the OLD image selected = still bootable. * rf_select (what firmware runs at power-on): preferred bank -> the other bank (self-heal) -> the immutable factory. It returns a BOOTABLE image unless EVEN THE FACTORY is gone. INVARIANT (S-class never-brick): as long as the immutable factory survives (it is write- protected by design), rf_select returns a bootable image after ANY interruption sequence. Sandboxed (/tmp only). Sovereign: reuses nx_fw_safeflash image+sha256 primitives. license_tier: ORIGINAL

dependencies 2 imports · 1 importers

nx_fw_safeflash.nx nx_syscalls.nx nx_fw_robust_flash.nx nx_fw_robust_gate.nx

imports: nx_fw_safeflash.nxnx_syscalls.nx

imported by: nx_fw_robust_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main fw_puts sys_write sys_now_realtime_sec sys_mmap sys_clock_gettime_real sys_mmap ↻ fw_path fw_cat fw_catn sys_mmap ↻ fw_make sys_mmap ↻ fw_wr_u32 sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word blk_byte sha256_final blk_set_byte ↻ sha256_compress ↻ fw_write_bytes sys_openat_wr sys_write ↻ sys_close rf_write_sel_atomic fw_is_sandbox sys_mmap ↻ rf_tmp fw_cat ↻ fw_write_bytes ↻ sys_renameat

structs

none

consts

26const RF_HELD: i64 = 6 // inactive write failed verify -> NOT committed, active retained (no brick)
27const RF_BANK_A: i64 = 65 // 'A'
28const RF_BANK_B: i64 = 66 // 'B'

functions

30func rf_tmp(sel: *u8, out: *u8) -> i64
called by 1: rf_write_sel_atomic calls 1: fw_cat
38func rf_read_sel(sel: *u8) -> i64
51func rf_write_sel_atomic(sel: *u8, bankc: i64) -> i64
60func rf_other(bankc: i64) -> i64 { if bankc == RF_BANK_B { return RF_BANK_A } return RF_BANK_B }
called by 1: rf_safe_flash
64func rf_select(sel: *u8, ba: *u8, bb: *u8, fac: *u8) -> *u8
71func rf_selectable(sel: *u8, ba: *u8, bb: *u8, fac: *u8) -> i64
called by 2: mainmain calls 1: rf_select
78func rf_safe_flash(sel: *u8, ba: *u8, bb: *u8, fac: *u8, newimg: *u8, corrupt: i64) -> i64
100func main() -> i64