aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / docs / NATIVE_BOOT_ROLLBACK_CONTRACT.md
| 1 | # AIENOS Native-Boot Rollback Contract |
| 2 | |
| 3 | ## 1. Scope & Purpose |
| 4 | |
| 5 | This contract specifies the deterministic lifecycle, state machine, and safety invariants for one-time native boots of AIENOS candidates on UEFI platforms (including physical NVIDIA DGX Spark / Machine 1 and QEMU AArch64 reference emulators). |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## 2. Core Invariant |
| 10 | |
| 11 | > **A candidate may consume exactly one boot attempt. It may never promote itself into the persistent default boot path.** |
| 12 | |
| 13 | Under no circumstances—whether normal completion, kernel panic, CPU exception, infinite loop/timeout, binary rejection, or power loss—may the platform enter an unrecoverable boot loop, and under no circumstances may the candidate modify the persistent boot priority of the system. |
| 14 | |
| 15 | --- |
| 16 | |
| 17 | ## 3. Subsystem Separation of Concerns |
| 18 | |
| 19 | 1. **Permanent Default Boot Configuration:** |
| 20 | - The primary operating system (e.g. Ubuntu Linux under GRUB/shim on Machine 1, or default reference OS in QEMU) is represented by persistent boot variable `Boot0001` (or existing default `BootCurrent`). |
| 21 | - The UEFI `BootOrder` variable lists default entries in priority order (e.g. `0001,0003`). |
| 22 | - The default boot configuration is immutable with respect to candidate execution. |
| 23 | - Secure Boot state is unchanged across the run. It is OFF for development as of 2026-10-01 (owner decision) and is recorded as an observed fact; a release gate requires `SecureBoot=1`. |
| 24 | - TPM PCR policies and sealed volume secrets remain intact. |
| 25 | |
| 26 | 2. **One-Time Candidate Selection:** |
| 27 | - Candidates are staged into dedicated, non-default paths on the EFI System Partition (e.g. `\EFI\AIENOS\aienos-candidate.efi`). |
| 28 | - A non-default boot entry is allocated (e.g. `Boot0000`). |
| 29 | - The candidate is selected **strictly** through the UEFI `BootNext` variable (`BootNext = 0000`). |
| 30 | - `BootOrder` is **never modified** when staging a candidate. |
| 31 | |
| 32 | 3. **Candidate Consumption by Firmware:** |
| 33 | - Per UEFI Specification §3.1.1, the platform firmware must consume (delete) `BootNext` prior to transferring control to the candidate binary. |
| 34 | - Once firmware starts the candidate, `BootNext` no longer exists in NVRAM. |
| 35 | |
| 36 | 4. **Candidate Execution Termination Modes:** |
| 37 | - **Orderly Termination:** The candidate finishes execution, prints diagnostic reports to screen/UART, and initiates cold system reset (via PSCI or UEFI Runtime Services `ResetSystem(ResetCold)`). |
| 38 | - **Panic / CPU Fault:** Upon encountering an exception, panic, or unhandled trap, the exception vector records fault registers (ESR, ELR, FAR, SPSR) to diagnostics and triggers cold reset. |
| 39 | - **Hang / Timeout:** If the candidate hangs or loops, an external hardware/emulator watchdog or an operator power-cycle triggers cold reset. |
| 40 | - **Firmware Rejection / Malformed Image:** If the image PE header is invalid or fails signature checks, firmware refuses execution and drops to the next option in `BootOrder` or returns to BDS. |
| 41 | - **Absent Image:** If the file referenced by `Boot0000` is missing, firmware drops to `BootOrder`. |
| 42 | |
| 43 | 5. **Fallback to Default Boot:** |
| 44 | - Because `BootNext` was consumed by firmware before or during the candidate launch, any subsequent reset or firmware boot evaluation encounters an empty `BootNext`. |
| 45 | - Firmware evaluates `BootOrder` and immediately launches the permanent default bootloader (`Boot0001`). |
| 46 | |
| 47 | 6. **Out-of-Band Recovery Fallback:** |
| 48 | - If the internal storage or default bootloader is corrupted by external factors, the dedicated, proved recovery USB media (`Boot0004` / `AIENOSRECOV`) remains bootable via the firmware interactive boot menu (`F11`/`BDS`), operating 100% in RAM with zero hard disk dependencies. |
| 49 | |
| 50 | --- |
| 51 | |
| 52 | ## 4. Formal Finite State Machine (FSM) |
| 53 | |
| 54 | ``` |
| 55 | +-------------------------------------------------------------+ |
| 56 | | DefaultReady | |
| 57 | | (Linux running, BootOrder=[0001,...], BootNext unset) | |
| 58 | +-------------------------------------------------------------+ |
| 59 | | |
| 60 | | [Operator stages candidate] |
| 61 | v |
| 62 | +-------------------------------------------------------------+ |
| 63 | | CandidateStaged | |
| 64 | | (Image on ESP, Boot0000 created, BootOrder UNTOUCHED) | |
| 65 | +-------------------------------------------------------------+ |
| 66 | | |
| 67 | | [efibootmgr --bootnext 0000] |
| 68 | v |
| 69 | +-------------------------------------------------------------+ |
| 70 | | CandidateSelectedOnce | |
| 71 | | (BootNext=0000, BootOrder=[0001,...]) | |
| 72 | +-------------------------------------------------------------+ |
| 73 | | |
| 74 | | [System reboot] |
| 75 | v |
| 76 | Firmware consumes & deletes BootNext in NVRAM |
| 77 | | |
| 78 | +-----------------------+-----------------------+ |
| 79 | | | |
| 80 | | [Valid binary] | [Corrupt/Missing/Rejected] |
| 81 | v v |
| 82 | +----------------------+ +-------------------+ |
| 83 | | CandidateRunning | | CandidateRejected | |
| 84 | | (EL2/EL1, native) | | (BDS fails load) | |
| 85 | +----------------------+ +-------------------+ |
| 86 | | | |
| 87 | +--------------------+ | |
| 88 | | | | |
| 89 | [Normal Exit] [Fault/Panic/Timeout] | |
| 90 | | | | |
| 91 | v v v |
| 92 | +--------------+ +----------------+ | |
| 93 | | ResetOrExit | | Watchdog/Reset | | |
| 94 | +--------------+ +----------------+ | |
| 95 | | | | |
| 96 | +--------------------+--------------------------+ |
| 97 | | |
| 98 | | [System cold reset / fallback] |
| 99 | v |
| 100 | Firmware evaluates BootOrder (BootNext=NONE) |
| 101 | | |
| 102 | v |
| 103 | +-------------------------------------------------------------+ |
| 104 | | DefaultReturned | |
| 105 | | (Linux running, BootCurrent=0001, BootOrder unchanged) | |
| 106 | +-------------------------------------------------------------+ |
| 107 | | |
| 108 | | [Subsequent reboot(s)] |
| 109 | v |
| 110 | +-------------------------------------------------------------+ |
| 111 | | DefaultReady | |
| 112 | | (System stays on Linux permanently; no candidate recurrence)| |
| 113 | +-------------------------------------------------------------+ |
| 114 | ``` |
| 115 | |
| 116 | --- |
| 117 | |
| 118 | ## 5. Transition Rules & Invariants |
| 119 | |
| 120 | 1. **Deterministic Return Invariant:** |
| 121 | $\forall s \in \{\text{NormalExit}, \text{Fault}, \text{Timeout}, \text{Rejected}, \text{Missing}\}, \quad \text{NextBoot}(s) = \text{DefaultBoot}$ |
| 122 | |
| 123 | 2. **Non-Promotion Invariant:** |
| 124 | Under no execution path may `Boot0000` be inserted into `BootOrder`. |
| 125 | $\text{BootOrder}_{\text{post}} = \text{BootOrder}_{\text{pre}}$ |
| 126 | |
| 127 | 3. **Single-Attempt Invariant:** |
| 128 | $\text{BootNext}_{\text{post}} = \emptyset$ |
| 129 | |
| 130 | 4. **No Autonomous Staging:** |
| 131 | No software component running within `CandidateRunning` or `DefaultReturned` may set `BootNext` or stage another candidate without explicit, authenticated operator dispatch. |
| 132 | |
| 133 | 5. **Storage & Trust Isolation:** |
| 134 | - Candidate execution must not mutate internal Linux root partition UUIDs or filesystem structures. |
| 135 | - Candidate execution must not alter UEFI Secure Boot configuration or TPM NVRAM allocations. |