omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / docs / baremetal / SPARK-LIVE-BOOT.md
| 1 | # DGX Spark Bare-Metal Live-Boot Operator Runbook (`SPARK.EFI`) |
| 2 | |
| 3 | **Status:** |
| 4 | - **Host / QEMU / Staging Tooling:** `HOST_VERIFIED` (Phase 2 Slices A–F approved; staging scripts syntax + dry-run + refusal-tested). |
| 5 | - **Spark Silicon Live Boot:** `NOT_RUN` / `BLOCKED_HARDWARE` (requires an attended Window 0 with physical console + UART `0x16A00000` access). |
| 6 | |
| 7 | > **Hard Safety Rules (Read Before Proceeding)** |
| 8 | > 1. **Never warm-reboot after `nvidia.ko` has been loaded.** GB20B GSP-FMC (`sec2.om`) requires a **full cold power-cycle** (`sudo poweroff` + AC disconnect for 10 s). Never issue a PCIe FLR on `000f:01:00.0`. |
| 9 | > 2. **Never modify `BootOrder` or `Boot0001` (`ubuntu`).** Stage only `\EFI\AIENOS\SPARK.EFI` via **one-shot `BootNext`**, so any power-cycle or PSCI `SYSTEM_RESET` (`0x84000009`) automatically returns to Ubuntu Linux. |
| 10 | > 3. **Zero NVMe writes & zero partition changes.** `nvme0n1p2` fills flush to the backup GPT (`8,001,573,518`). `SPARK.EFI` uses strictly read-only NVMe (`Admin 0x06/0x05/0x01`, `I/O Read 0x02` only) and read-only `ext4_ro.om` over `nvme0n1p2`. |
| 11 | > 4. **Zero firmware bytes in git or `HANDOFFS/`.** All `fwprep` / `pack_bundle` artifacts live in a local `0700` directory only. |
| 12 | > 5. **Thermal / Power Gate (Window 0).** DGX Spark hard-cuts power at ~88–92 W (`nvidia-gb10` Trap #14). Verify EC fan spin and GSP thermal/DPM telemetry in Window 0 before any sustained inference (never run with `CBKDPM=0`/`CBKPW2=0`). |
| 13 | |
| 14 | --- |
| 15 | |
| 16 | ## (a) Build `SPARK.EFI` |
| 17 | |
| 18 | Build the unified bare-metal PE32+ ARM64 image (`target a64efi`, zero Linux syscalls, zero embedded firmware bytes, no 184 MiB static host-sim `.bss`): |
| 19 | |
| 20 | ```sh |
| 21 | sh aienux/spark/build_spark_efi.sh |
| 22 | ``` |
| 23 | |
| 24 | Default output path: `build/spark/SPARK.EFI` (or `aienux/spark/out/SPARK.EFI`). |
| 25 | Verify PE32+ ARM64 header (`0xaa64`, PE32+ `0x020b`, EFI Application subsystem `10`, `SizeOfImage <= 64 MiB`) and record its SHA-256 via `preflight.sh` in step (c). |
| 26 | |
| 27 | --- |
| 28 | |
| 29 | ## (b) Pack `GspFwBundle` (`OMFWBND1`) Offline into a Local `0700` Path |
| 30 | |
| 31 | Never commit `gsp_ga10x.bin`, extracted bindata blobs, or `spark-bundle.img` to git or `HANDOFFS/`. |
| 32 | |
| 33 | ### 1. Build `fwprep` and `pack_bundle` on Spark (AArch64 Linux) |
| 34 | |
| 35 | ```sh |
| 36 | # Build pure-Omega fwprep (OM-1) |
| 37 | cat gpu/driver/gsp/sha2.om gpu/driver/gsp/inflate.om \ |
| 38 | gpu/driver/gsp/fw.om gpu/driver/gsp/bindata.om \ |
| 39 | gpu/driver/fwprep.om | ./seed/out/omc > /tmp/fwprep |
| 40 | chmod +x /tmp/fwprep |
| 41 | |
| 42 | # Build pure-Omega OMFWBND1 packer |
| 43 | cat aienux/disk/sha256_bare.om aienux/disk/pack_bundle.om | ./seed/out/omc > /tmp/pack_bundle |
| 44 | chmod +x /tmp/pack_bundle |
| 45 | ``` |
| 46 | |
| 47 | ### 2. Extract GB20B `580.173.02` Bindata & Pack `OMFWBND1` into a `0700` Directory |
| 48 | |
| 49 | `gpu/driver/fwprep.om` writes the 5 GB20B bindata blobs (`bl.img` `212,992 B`, `fmc.img` `212,296 B`, `fmc.hash` `48 B`, `fmc.pubkey` `384 B`, `fmc.sig` `384 B`) plus the text manifest `fw.gb20b.manifest` (which records `bl_desc` fields including `app_version`). On Spark (`nvme0n1p2`), create a root/operator-only `0700` staging directory and pack `gsp_ga10x.bin` (`75,012,080 B`) + the 5 extracted binary blobs (and optional `fw.gb20b.manifest` as kind `7`): |
| 50 | |
| 51 | ```sh |
| 52 | FW_WORK="$HOME/.local/state/aienos-fw-580.173.02" |
| 53 | install -d -m 0700 "$FW_WORK" |
| 54 | |
| 55 | # Extract the 5 GB20B bindata blobs + fw.gb20b.manifest from pinned open-gpu-kernel-modules-580.173.02 |
| 56 | /tmp/fwprep \ |
| 57 | /lib/firmware/nvidia/580.173.02/gsp_ga10x.bin \ |
| 58 | "$OGKM_580_173_02_DIR" \ |
| 59 | "$FW_WORK" \ |
| 60 | gb20b |
| 61 | |
| 62 | # Read app_version recorded by fwprep in fw.gb20b.manifest |
| 63 | APP_VER=$(awk '/^bl_desc / { for (i=1;i<=NF;i++) if ($i ~ /^app_version=/) { sub(/^app_version=/,"",$i); print $i; exit } }' "$FW_WORK/fw.gb20b.manifest") |
| 64 | echo "fwprep app_version=${APP_VER:?missing app_version in fw.gb20b.manifest}" |
| 65 | |
| 66 | # Pack 4 KiB-aligned OMFWBND1 bundle with per-entry SHA-256 TOC |
| 67 | sudo install -d -m 0700 /aienos |
| 68 | /tmp/pack_bundle "$FW_WORK/spark-bundle.img" "$APP_VER" \ |
| 69 | 1 /lib/firmware/nvidia/580.173.02/gsp_ga10x.bin \ |
| 70 | 2 "$FW_WORK/bl.img" \ |
| 71 | 3 "$FW_WORK/fmc.img" \ |
| 72 | 4 "$FW_WORK/fmc.hash" \ |
| 73 | 5 "$FW_WORK/fmc.pubkey" \ |
| 74 | 6 "$FW_WORK/fmc.sig" \ |
| 75 | 7 "$FW_WORK/fw.gb20b.manifest" |
| 76 | |
| 77 | sudo install -m 0600 "$FW_WORK/spark-bundle.img" /aienos/spark-bundle.img |
| 78 | sha256sum /aienos/spark-bundle.img |
| 79 | rm -f /tmp/fwprep /tmp/pack_bundle |
| 80 | ``` |
| 81 | |
| 82 | `ext4_ro.om` reads `/aienos/spark-bundle.img` directly from `nvme0n1p2` using read-only ext4 extent walks and verifies every entry's SHA-256 fail-closed before passing the bundle to `fw_bm.om`. |
| 83 | |
| 84 | --- |
| 85 | |
| 86 | ## (c) Run Strictly Read-Only Preflight (`preflight.sh --check-spark`) |
| 87 | |
| 88 | `tools/spark-boot/preflight.sh` performs **zero writes** to disk, ESP, NVRAM, or `/dev/nvidia*`: |
| 89 | |
| 90 | ```sh |
| 91 | tools/spark-boot/preflight.sh --spark-efi build/spark/SPARK.EFI --check-spark |
| 92 | ``` |
| 93 | |
| 94 | What it verifies: |
| 95 | 1. Local `SPARK.EFI`: valid PE32+ ARM64 (`0xaa64`, `0x020b`, EFI Application `10`, `SizeOfImage <= 64 MiB`), prints size + SHA-256. |
| 96 | 2. Pi 5 `pi_drive_omtk`: verifies existing AArch64 ELF64 binary (or compile-checks `aienux/net/wire/omtk.om` + `tools/pi-drive-27b/pi_drive_omtk.om` in an ephemeral temp dir; pass `--build-pi-drive` to emit `build/spark/pi_drive_omtk`). |
| 97 | 3. Spark UEFI NVRAM: `Boot0001` (`ubuntu`, `\EFI\ubuntu\shimaa64.efi`) intact and `BootOrder` starts with `0001`. |
| 98 | 4. Spark ESP (`/boot/efi`): free space `>= 64 MiB` and `/boot/efi/EFI/ubuntu/shimaa64.efi` present. |
| 99 | 5. Spark `nvme0n1p2` ext4: `4096 B` blocks, `extent` enabled, and **none** of `ext4_ro.om`'s unsupported incompat features (`compression`, `meta_bg`, `inline_data`, `encrypt`). |
| 100 | 6. Spark firmware & weights: `/lib/firmware/nvidia/580.173.02/gsp_ga10x.bin` (`75,012,080 B`) and `~/models/specialist-transfer/qwen3.8-27b-fp8-*` (`~28.77 GiB`). |
| 101 | 7. Spark RTL8127 NIC: `0007:01:00.0` (`r8127`, e.g. `enP7s7` `UP`, IPv4 `192.168.1.108/24`). |
| 102 | 8. Read-only `/dev/nvidia*` idle check (via `/proc/[0-9]*/fd/*` symlinks — never opens `/dev/nvidia*`). |
| 103 | |
| 104 | Do not proceed until `VERDICT: PASS`. |
| 105 | |
| 106 | --- |
| 107 | |
| 108 | ## (d) Stage `\EFI\AIENOS\SPARK.EFI` + One-Shot `BootNext` |
| 109 | |
| 110 | `tools/spark-boot/stage_bootnext.sh` is **dry-run by default** and refuses to modify anything unless **both** `--apply` and `--i-am-at-the-console` are explicitly passed. |
| 111 | |
| 112 | ### 1. Dry-run first (zero changes) |
| 113 | |
| 114 | ```sh |
| 115 | tools/spark-boot/stage_bootnext.sh --spark-efi build/spark/SPARK.EFI --dry-run |
| 116 | ``` |
| 117 | |
| 118 | ### 2. Apply staging (at physical Spark console + UART) |
| 119 | |
| 120 | ```sh |
| 121 | tools/spark-boot/stage_bootnext.sh \ |
| 122 | --spark-efi build/spark/SPARK.EFI \ |
| 123 | --apply \ |
| 124 | --i-am-at-the-console |
| 125 | ``` |
| 126 | |
| 127 | Safety checks enforced automatically: |
| 128 | - Re-validates local `SPARK.EFI` PE32+ ARM64 header & SHA-256. |
| 129 | - Refuses if any process holds `/dev/nvidia*` open (override only with `--force-while-gpu-busy`). |
| 130 | - Copies atomically to `/boot/efi/EFI/AIENOS/SPARK.EFI` and verifies remote SHA-256 (Ubuntu's `\EFI\ubuntu\shimaa64.efi` and GRUB are never touched). |
| 131 | - Creates/reuses the UEFI entry for `\EFI\AIENOS\SPARK.EFI` via `efibootmgr --create-only` (leaving `BootOrder` untouched) and sets **one-shot `BootNext` ONLY**. |
| 132 | - Re-reads `efibootmgr -v` and verifies `BootOrder` and `Boot0001` are byte-identical to pre-staging (automatically restores `BootOrder` and clears `BootNext` if any discrepancy is detected). |
| 133 | - **Never reboots automatically.** |
| 134 | |
| 135 | --- |
| 136 | |
| 137 | ## (e) Cold Power-Cycle (NEVER Warm-Reboot After `nvidia.ko`) |
| 138 | |
| 139 | > **CRITICAL:** Do **NOT** run `sudo reboot` after Linux `nvidia.ko` has been loaded. GB20B's SEC2/GSP-FMC cold-boot path requires clean silicon power-on reset; warm-booting after `nvidia.ko` leaves GPU/GSP state dirty and can hang or fault GSP init. |
| 140 | |
| 141 | 1. Attach the serial console to Spark UART `0x16A00000` (`115200 8N1`). |
| 142 | 2. Cleanly shut down Ubuntu: |
| 143 | ```sh |
| 144 | ssh spark 'sudo poweroff' |
| 145 | ``` |
| 146 | 3. Wait until the power LED is completely off, **disconnect AC power for 10 seconds**, then reconnect AC and power Spark back on. |
| 147 | 4. UEFI consumes the one-shot `BootNext` and launches `\EFI\AIENOS\SPARK.EFI`. |
| 148 | |
| 149 | --- |
| 150 | |
| 151 | ## (f) UART `0x16A00000` Expected Boot Log & Window 0 Thermal Check |
| 152 | |
| 153 | Watch the `0x16A00000` serial log for the six sequential stage markers: |
| 154 | |
| 155 | | Stage | Expected UART Marker & Key Milestones | |
| 156 | |---|---| |
| 157 | | **1/6** | `[SPARK 1/6]` — `ExitBootServices`, ACPI (XSDT/MADT/FADT/MCFG/IORT), EL2→EL1h (`HCR_EL2.E2H=0` + `ISB`, `CNTVOFF_EL2=0`), `MAIR=0x440004FF` + pre-carved 512 MiB Normal-NC DMA pool, GICv3 + ITS (`GICV3_OK`, `ITS_OK`), 20-core PSCI SMP (`SMP_ONLINE 20/20`). | |
| 158 | | **2/6** | `[SPARK 2/6]` — PCIe MCFG segs 4/7/15 probe (`Device-nGnRnE` XN), unused PCIe `CMD.BME=0` quiesce, SMMUv3 A/B/C fail-closed (`GBPA.ABORT`, per-stream disjoint Normal-NC DMA: SID `0x50100` NVMe, `0x80100` RTL8127, `0x100` GB20B + 3 mandatory RMRs; SMMUv3 C aborted), GB20B BAR0 (`0x24000000`) `BOOT_0`/`BOOT_42` probe, `iqmode=2` polling + CrashCat armed. | |
| 159 | | **3/6** | `[SPARK 3/6]` — Read-only NVMe (`0x62100000`, `MDTS <= 128 KiB`, `I/O Read 0x02` only) + GPT + `ext4_ro.om` load & SHA-256 verification of `/aienos/spark-bundle.img` (`OMFWBND1`) and `qwen3.8-27b-fp8` weights; RTL8127 (`0x6e900000`) `PHYSTAT` link-up check. | |
| 160 | | **4/6** | `[SPARK 4/6]` — Cold-boot GB20B GSP-FMC (`sec2.om` + `seqcore.om` opcodes `5..8` + `sccfg`) → `GSP_INIT_DONE` → `RPC 54/79` (`SET_PAGE_DIRECTORY`) → live `0xca6f`/`0xcec0` compute channel + bit-30 doorbell `0x00BB0090` + 2 MiB GMMU mappings (disjoint GPU VA map: LPDDR5x `0x00_8000_0000..0x3F_FFFF_FFFF`, shared `0x70_0000_0000`, local `0x72_0000_0000`). | |
| 161 | | **5/6** | `[SPARK 5/6]` — Pure-`.om` `sm_121` SASS codegen + `DC CIVAC` + `DSB SY` + `q38_run.om` init + `q38_reset_kv(0)` GPU-side zero + L2 flush. | |
| 162 | | **6/6** | `[SPARK 6/6]` — Zero-userspace `wire_loop.om` (`OMTK v1`) listening on RTL8127 TCP port `18100`. | |
| 163 | |
| 164 | **Fail-Closed Post-EBS Behavior:** If any hardware probe, SHA-256 check, SMMU `CMD_SYNC`, GSP timeout, or CrashCat HALT triggers after `ExitBootServices()`, the `post_ebs` trap guard logs the exact stage, error code, and `ESR`/`ELR`/`FAR` to UART `0x16A00000` and halts (or invokes PSCI `SYSTEM_RESET`) without ever calling dead UEFI Boot Services. |
| 165 | |
| 166 | ### Window 0 EC Fan & Thermal Gate (Mandatory Before Sustained Inference) |
| 167 | - Immediately after `[SPARK 4/6]` (`GSP_INIT_DONE`), verify audible/tachometer **EC fan spin** and confirm GSP thermal/DPM telemetry is active (no `CBKDPM=0`/`CBKPW2=0` override). |
| 168 | - Run a single `ping` + `reset 0` + 1-token `infer` first while watching package power and exhaust temperature. If fan speed fails to ramp or thermal telemetry is absent, **abort immediately** (power-cycle back to Ubuntu) to avoid the ~88–92 W hard power cut. |
| 169 | |
| 170 | --- |
| 171 | |
| 172 | ## (g) Drive Inference from Raspberry Pi 5 (`pi_drive_omtk`) |
| 173 | |
| 174 | ### 1. Build `pi_drive_omtk` on Raspberry Pi 5 (AArch64 Linux, zero C/Python/JSON) |
| 175 | |
| 176 | ```sh |
| 177 | { printf 'om2\n'; cat aienux/net/wire/omtk.om tools/pi-drive-27b/pi_drive_omtk.om; } | ./seed/out/omc > pi_drive_omtk |
| 178 | chmod +x pi_drive_omtk |
| 179 | ``` |
| 180 | |
| 181 | *(Alternatively, run `tools/spark-boot/preflight.sh --build-pi-drive` on an AArch64 host and `scp build/spark/pi_drive_omtk` to the Pi 5.)* |
| 182 | |
| 183 | ### 2. Exercise `OMTK v1` over RTL8127 (`192.168.1.108:18100`) |
| 184 | |
| 185 | ```sh |
| 186 | SPARK_IP=192.168.1.108 |
| 187 | SPARK_PORT=18100 |
| 188 | |
| 189 | # 1. Health & state probe (expects: PONG state=... kv=0 max_ctx=131072 gpu_err=0) |
| 190 | ./pi_drive_omtk "$SPARK_IP" "$SPARK_PORT" ping |
| 191 | |
| 192 | # 2. Reset KV cache / GDN state (keep_pos=0; triggers GPU zero + L2 flush) |
| 193 | ./pi_drive_omtk "$SPARK_IP" "$SPARK_PORT" reset 0 |
| 194 | |
| 195 | # 3. Run token-ID prefill + greedy decode: |
| 196 | # infer <max_tokens> <eos_id> <tok0> [tok1 ...] |
| 197 | ./pi_drive_omtk "$SPARK_IP" "$SPARK_PORT" infer 32 151645 9707 11 1265 |
| 198 | ``` |
| 199 | |
| 200 | Expected output lines: |
| 201 | - `PONG state=0 kv=0 max_ctx=131072 gpu_err=0` |
| 202 | - `DONE kv=0 reason=4` (after `reset 0`) |
| 203 | - `TOKEN <id>` per generated token, ending with `DONE kv=<pos> reason=<0|1|2>` (or `ERR code=<code> detail=<n>` on any fail-closed refusal). |
| 204 | |
| 205 | --- |
| 206 | |
| 207 | ## (h) Instant Ubuntu Fallback & Cleanup |
| 208 | |
| 209 | Because `stage_bootnext.sh` sets **one-shot `BootNext` only** and leaves `BootOrder` (`0001,...`) and `Boot0001` (`ubuntu`) untouched: |
| 210 | |
| 211 | - **Immediate return to Ubuntu:** Press the power button / cold power-cycle (or let `SPARK.EFI` invoke PSCI `SYSTEM_RESET`). UEFI automatically boots `Boot0001` (`ubuntu`, `\EFI\ubuntu\shimaa64.efi`). |
| 212 | - **Cancel a pending `BootNext` before powering off:** |
| 213 | ```sh |
| 214 | ssh spark 'sudo efibootmgr -N' |
| 215 | ``` |
| 216 | - **Optional full cleanup after testing (once back in Ubuntu):** |
| 217 | ```sh |
| 218 | ssh spark ' |
| 219 | sudo efibootmgr -N || true |
| 220 | sudo rm -f /boot/efi/EFI/AIENOS/SPARK.EFI |
| 221 | # Optional: remove the BootXXXX entry for \EFI\AIENOS\SPARK.EFI (never touch Boot0001!) |
| 222 | BOOTNUM=$(efibootmgr -v | awk "/^Boot[0-9A-Fa-f]{4}/ && index(\$0, \"\\\\EFI\\\\AIENOS\\\\SPARK.EFI\")>0 {print substr(\$1,5,4); exit}") |
| 223 | [ -n "$BOOTNUM" ] && [ "$BOOTNUM" != "0001" ] && sudo efibootmgr -b "$BOOTNUM" -B |
| 224 | efibootmgr -v |
| 225 | ' |
| 226 | ``` |
| 227 | |
| 228 | --- |
| 229 | |
| 230 | ## Post-Boot Optimization Plan (Phase 4 — Strictly After Window 0 First-Boot & Token Parity) |
| 231 | |
| 232 | Do **not** mix these optimizations into Window 0 bring-up. Land and benchmark them only after bare-metal first-boot, EC fan/thermal verification, and bit-exact Qwen3.8-27B token parity pass: |
| 233 | |
| 234 | 1. **Projection Overlap & Barrier Tuning (`gpu/driver/gsp/q38_run.om`):** |
| 235 | - Port `OVERLAP_AB` (overlap independent projections) and configurable barrier modes (`WFI` vs `WFI+CBICALL`) in `q38_run.om`. |
| 236 | - Measure per-stage latency directly via GPU `PTIMER` stamps. |
| 237 | 2. **GPU-Side Embedding Gather & Multi-Token Pushbuffer Batching (`N=4..8`):** |
| 238 | - Move embedding gather onto the GPU and batch `N=4..8` greedy `OMTK v1` decode tokens per pushbuffer submission to eliminate per-token C3 `L2_FLUSH_DIRTY` + semaphore host round-trips, while preserving prompt `EOS` and `CANCEL` responsiveness. |
| 239 | 3. **Long-Context `attn256` Optimization (`32k–128k`):** |
| 240 | - Optimize long-context KV scan / reduction paths in `cg_attn256.om` across `32k–128k` contexts. |
| 241 | 4. **Explicit Skips (Do Not Implement for Dense 27B):** |
| 242 | - **Weight L2 caching:** thrashes GB10's 24 MiB L2 cache on 27B streaming weights. |
| 243 | - **`o_proj` prefetch:** 30B-only optimization; skip for 27B. |
| 244 | - **Range-syncing:** already reduced to a single `dsb sy` no-op on bare-metal ARM64. |
| 245 | - **`AIEN_OMEGA_FP8_GROUPED_WAVE=1`:** 35B MoE grouped-expert path only; not applicable to dense Qwen3.8-27B. |