interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / collect_boot_report.sh

104 lines · 5119 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Collect and judge the evidence from an AIENOS first-boot attempt. Read-only.
18# Run under `aien-proof hold --resource machine-1` so the full output becomes
19# an audit event in the hardware-test ledger.
20#
21# Gate (M2 first native boot): Machine 1 left firmware, entered native AIENOS
22# code with no Linux underneath, left independently recoverable evidence, and
23# returned to the existing system without damaging it.
24set -uo pipefail
25
26esp="${AIENOS_ESP_DIR:-/boot/efi/EFI/AIENOS}"
27staged_file="${esp}/STAGED.TXT"
28report_file="${esp}/BOOTREPORT.TXT"
29image="${esp}/aienos-handoff.efi"
30report_var="${AIENOS_REPORT_VAR:-/sys/firmware/efi/efivars/AienosBootReportV1-a1e05b0e-7c3d-4f51-9b6a-2d8e4c1f0a37}"
31
32field() { sed -n "s/^$1: //p" <<<"$2" | head -1; }
33check() { # name, pass(0/1), detail
34 if [[ "$2" == 1 ]]; then echo "PASS $1: $3"; else echo "FAIL $1: $3"; failed=1; fi
35}
36failed=0
37
38echo "== staging record (${staged_file})"
39staged="$(cat "${staged_file}" 2>/dev/null)"
40if [[ -z "${staged}" ]]; then
41 echo "missing: nothing was staged, or the file is unreadable"
42 echo "M2_GATE: UNPROVEN"
43 exit 1
44fi
45printf '%s\n' "${staged}"
46commit="$(field aienos_commit "${staged}")"
47
48echo "== staged image"
49digest_now="$(sha256sum "${image}" 2>/dev/null | cut -d' ' -f1)"
50echo "sha256: ${digest_now:-missing}"
51
52echo "== pre-exit report (${report_file})"
53pre="$(cat "${report_file}" 2>/dev/null)"
54printf '%s\n' "${pre:-missing}"
55
56echo "== native firmware-variable report"
57native=""
58if [[ -r "${report_var}" ]]; then
59 # efivarfs prefixes the value with 4 bytes of attributes.
60 # efivarfs files cannot seek, so stream the value instead of `tail` on the path.
61 native="$(cat "${report_var}" 2>/dev/null | tail -c +5)"
62fi
63printf '%s\n' "${native:-missing}"
64
65echo "== current boot state"
66boot_state="$(efibootmgr)"
67printf '%s\n' "${boot_state}" | sed -n '1,4p'
68echo "kernel: $(uname -r)"
69echo "root: $(findmnt -no OPTIONS / | cut -d, -f1)"
70
71echo "== verdict"
72check "image_unchanged" "$([[ -n "${digest_now}" && "${digest_now}" == "$(field image_sha256 "${staged}")" ]] && echo 1 || echo 0)" \
73 "staged ${commit:0:12}, image ${digest_now:0:16}"
74# Either report proves the firmware ran this image; the variable is written only
75# after ExitBootServices, so it alone also proves firmware exit.
76check "left_firmware_into_aienos" "$([[ "$(field aienos_commit "${pre}")" == "${commit}" || "$(field aienos_commit "${native}")" == "${commit}" ]] && echo 1 || echo 0)" \
77 "pre-exit file: $([[ -n "${pre}" ]] && echo present || echo missing), native report: $([[ -n "${native}" ]] && echo present || echo missing)"
78check "native_code_after_firmware_exit" "$([[ -n "${native}" && "$(field aienos_commit "${native}")" == "${commit}" ]] && echo 1 || echo 0)" \
79 "firmware variable written by AIENOS after ExitBootServices (kind $(field report_kind "${native}"))"
80check "kernel_alive" "$(grep -qx "kernel: alive" <<<"${native}" && echo 1 || echo 0)" \
81 "last stage $(field last_stage "${native}")"
82check "boot_next_consumed" "$(grep -q "^BootNext:" <<<"${boot_state}" && echo 0 || echo 1)" \
83 "no pending one-time boot"
84# Firmware may append entries for removable media it finds (a USB stick). The
85# gate is that the original entries keep their order and AIENOS never joined.
86order_before="$(field boot_order_before "${staged}")"
87order_now="$(field BootOrder "${boot_state}")"
88kept="$(tr ',' '\n' <<<"${order_now}" | grep -Fx -f <(tr ',' '\n' <<<"${order_before}") | paste -sd,)"
89added="$(tr ',' '\n' <<<"${order_now}" | grep -Fvx -f <(tr ',' '\n' <<<"${order_before}") | paste -sd,)"
90aienos_in_order="$(tr ',' '\n' <<<"${order_now}" | grep -Fxc "$(field aienos_boot_entry "${staged}")")"
91check "boot_order_preserved" "$([[ "${kept}" == "${order_before}" && "${aienos_in_order}" == 0 ]] && echo 1 || echo 0)" \
92 "before ${order_before}, now ${order_now}${added:+ (added by firmware: ${added})}"
93check "linux_entry_booted" "$([[ "$(field BootCurrent "${boot_state}")" == "$(field boot_current_before "${staged}")" ]] && echo 1 || echo 0)" \
94 "BootCurrent $(field BootCurrent "${boot_state}")"
95check "linux_kernel_unchanged" "$([[ "$(uname -r)" == "$(field linux_kernel_before "${staged}")" ]] && echo 1 || echo 0)" \
96 "$(uname -r)"
97check "root_filesystem_writable" "$([[ "$(findmnt -no OPTIONS / | cut -d, -f1)" == "rw" ]] && echo 1 || echo 0)" "/"
98
99if [[ "${failed}" == 0 ]]; then
100 echo "M2_GATE: PASS"
101else
102 echo "M2_GATE: FAIL"
103 exit 1
104fi