code wiki / _hdl_build / nx_nishi_usb_install.nx

nx_nishi_usb_install.nx

buildroot/runtime/_hdl_build/nx_nishi_usb_install.nx

16819 B293 linesdepth 5pulls 5 transitivereach 0 importersview sourcekind tooltopic nishi
docsdependenciesstructsconstsfunctions

about

nx_nishi_usb_install.nx -- x86 ladder C3 (installer/disk side): the NISHI INSTALLER PROGRAM. The capstone proved "a kernel that runs a userland"; C1 gave the bootable image a real MBR partition table. This rung is the PUBLISHER'S actual tool: a program that installs the partitioned OS onto a target disk WITHOUT EVER BRICKING IT. It composes two proven never-brick primitives: * nx_flash (runtime/nx_flash_test.nx): REFUSE the system disk (/dev/sda) BY CONSTRUCTION, then WRITE + READ-BACK + sha256 HASH-VERIFY byte-for-byte (never write blind, unlike dd/Rufus). * nx_fw_safeflash (golden recovery): keep a known-good GOLDEN anchor; if the write goes bad, AUTO-RESTORE from golden so the target is left BOOTABLE, never bricked. and adds the OS-install specifics: the source IS the C1 partitioned image, and the installed target is PROVEN bootable (executed on the sovereign 16-bit/INT13h emu -> 'NISHIOS KERNEL') and still carries its partition table. KAT: (T1) install to a safe target -> OK + sha256 byte-perfect; (T2) never-brick: refuse /dev/sda; (T3) the refusal is DISCRIMINATING (allows /dev/sdb + files, so T2 is a real check not refuse-all); (T4) the installed target BOOTS to 'NISHIOS KERNEL'; (T5) it keeps the C1 partition table (0x80/0x9E); (T6) golden recovery: a corrupt write -> RECOVERED + the target STILL boots (never bricked); (T7, liar-kill) verifying a TAMPERED target returns mismatch (<0), so "verified" is a real sha256 match, not a hardcoded PASS. NEVER-BRICK (Rule 26): refuses the system disk by construction; all writes go to /tmp/ FILES (never a real device); golden recovery guarantees a bootable target. A real install targets /dev/sdX -- the operator runs it with the device + this safety guard (R10). No real-device writes here. nx_sha256 + nx_syscalls are imported (the proven combo from nx_flash_test / nx_fw_safeflash); the emu + image author + boot harness are inlined from the proven nx_nishi_usb_image / _parttable (the standalone-main import exception the codebase already uses). expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sha256.nx nx_nishi_usb_install.nx

imports: nx_syscalls.nxnx_sha256.nx

imported by: nobody (leaf or entry point)

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

main ui_puts sys_write sys_mmap build_image wr_u32_le 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 ↻ ui_num sys_mmap ↻ sys_write ↻ fl_hexb sys_mmap ↻ sys_write ↻ nx_install fl_safe fl_write sys_openat_wr sys_write ↻ sys_close sys_mmap ↻ fl_verify sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻

structs

none

consts

30const IMG_MAGIC_200000: i64 = 200000
31const IMG_MAGIC_32767: i64 = 32767
32const IMG_MAGIC_65536: i64 = 65536
33const IMG_MAGIC_1024: i64 = 1024
123const IMG_SZ: i64 = 1536
124const PART_TYPE_NISHI: i64 = 0x9E
125const INST_OK: i64 = 0
126const INST_RECOVERED: i64 = 2
127const INST_UNSAFE: i64 = 7
128const INST_FATAL: i64 = 5

functions

35func ui_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
36func ui_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
37func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64
called by 1: main
49func fl_h32eq(a: *u8, b: *u8) -> i64 { var i: i64=0; while i<32 { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 1: fl_verify
50func fl_hexb(v: i64) -> i64 { let hi: i64=(v>>4)&15; let lo: i64=v&15; var c1: i64=48+hi; if hi>9 { c1=87+hi } var c2: i64=48+lo; if lo>9 { c2=87+lo } let o: *u8=sys_mmap(4); o[0]=c1 as u8; o[1]=c2 as u8; sys_write(1,o,2); return 0 }
called by 1: main calls 2: sys_mmapsys_write
53func wr_u32_le(img: *u8, off: i64, v: i64) -> i64
called by 1: build_image
59func fl_safe(target: *u8) -> i64
called by 2: nx_installmain
63func fl_write(path: *u8, buf: *u8, n: i64) -> i64 { let fd: i64=sys_openat_wr(path, 0x1a4); if fd<=0 { return 0-1 } sys_write(fd, buf, n); sys_close(fd); return 0 }
65func fl_verify(img: *u8, n: i64, target: *u8) -> i64
79func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64
called by 1: boot_image
131func build_image(img: *u8) -> i64
called by 1: main calls 1: wr_u32_le
196func boot_image(img: *u8, console: *u8, clen: *i64, loaded: *i64) -> i64
called by 1: main calls 2: sys_mmapemu_x86_real16_disk
212func nx_install(src: *u8, n: i64, target: *u8, golden: *u8, corrupt: i64) -> i64
234func main() -> i64