code wiki / (root) / nx_printer_fw_sim.nx

nx_printer_fw_sim.nx

buildroot/runtime/nx_printer_fw_sim.nx

4464 B78 linesdepth 0pulls 0 transitivereach 1 importersview sourcekind librarytopic printer
docsdependenciesstructsconstsfunctions

about

nx_printer_fw_sim.nx -- VIRTUAL printer firmware/flash SIMULATOR. The operator wants to let a user flash OUR firmware to escape vendor DRM -- but FLASHING WRITES PERSISTENT HARDWARE STATE, the exact hazard global rule #26 (NEVER BRICK THE ELECTRONICS -- brand-critical, ABSOLUTE) governs. So we model the printer + the flash process IN SOFTWARE, iterate here (a simulator cannot brick anything), and PROVE the flash is fail-safe BY CONSTRUCTION before any real device is touched. **NO real hardware is written by this file.** NEVER-BRICK ARCHITECTURE = A/B DUAL-BANK (the only safe way to field-flash): write the INACTIVE bank, verify its signature, then ATOMICALLY flip the boot pointer. The ACTIVE (running) bank is NEVER modified during a flash, so a power loss at ANY step leaves a bootable bank -> never bricked. A bad-signature image is rejected before the flip; an image that doesn't boot is rolled back by the bootloader to the prior bank. The gate injects power loss at EVERY step x EVERY firmware quality and proves the printer ALWAYS boots something -- the #26 guarantee proven MECHANICALLY, not asserted -- with a NAIVE in-place flash as the negative control (it CAN brick, proving A/B is what saves us). State = i64[9]: [0]=active_bank(0=A,1=B); bank b at base (1 + b*4) = [present, sig_valid, boots, version]. PURE (caller-owned state, no syscalls) -> safe by construction. license_tier: ORIGINAL genealogy_id: project-printer-management-ipp-sclass-2026-06-20 ; honors global rule #26.

dependencies 0 imports · 1 importers

nx_printer_fw_sim.nx nx_printer_fw_sim_test.nx

imports: none

imported by: nx_printer_fw_sim_test.nx

structs

none

consts

19const NX_FW_BRICKED: i64 = 0 - 1

functions

21func fw_base(b: i64) -> i64 { return 1 + b * 4 }
23func fw_set_bank(st: *i64, b: i64, present: i64, sig: i64, boots: i64, ver: i64) -> i64
called by 2: scenariomain calls 1: fw_base
30func fw_bank_bootable(st: *i64, b: i64) -> i64
called by 1: fw_boot calls 1: fw_base
40func fw_boot(st: *i64) -> i64
called by 2: scenariomain calls 1: fw_bank_bootable
51func fw_flash_ab(st: *i64, new_ver: i64, new_sig: i64, new_boots: i64, power_loss_step: i64) -> i64
called by 2: scenariomain calls 1: fw_base
69func fw_flash_naive(st: *i64, new_ver: i64, new_sig: i64, new_boots: i64, power_loss_step: i64) -> i64
called by 1: main calls 1: fw_base