code wiki / _hdl_build / nx_nishi_usb_install.nx
nx_nishi_usb_install.nx
buildroot/runtime/_hdl_build/nx_nishi_usb_install.nx
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
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
structs
| none |
consts
| 30 | const IMG_MAGIC_200000: i64 = 200000 |
| 31 | const IMG_MAGIC_32767: i64 = 32767 |
| 32 | const IMG_MAGIC_65536: i64 = 65536 |
| 33 | const IMG_MAGIC_1024: i64 = 1024 |
| 123 | const IMG_SZ: i64 = 1536 |
| 124 | const PART_TYPE_NISHI: i64 = 0x9E |
| 125 | const INST_OK: i64 = 0 |
| 126 | const INST_RECOVERED: i64 = 2 |
| 127 | const INST_UNSAFE: i64 = 7 |
| 128 | const INST_FATAL: i64 = 5 |
functions
| 35 | func 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 } |
| 36 | func 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 } |
| 37 | func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64 called by 1: main |
| 49 | func 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 |
| 50 | func 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 } |
| 53 | func wr_u32_le(img: *u8, off: i64, v: i64) -> i64 called by 1: build_image |
| 59 | func fl_safe(target: *u8) -> i64 |
| 63 | func 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 } |
| 65 | func fl_verify(img: *u8, n: i64, target: *u8) -> i64 |
| 79 | func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64 called by 1: boot_image |
| 131 | func build_image(img: *u8) -> i64 |
| 196 | func boot_image(img: *u8, console: *u8, clen: *i64, loaded: *i64) -> i64 |
| 212 | func nx_install(src: *u8, n: i64, target: *u8, golden: *u8, corrupt: i64) -> i64 |
| 234 | func main() -> i64 |