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 / qemu_ck_pi5_diag_test.sh

119 lines · 6505 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# qemu_ck_pi5_diag_test.sh -- QEMU test for PI5DIAG.EFI (AIENOS-PI5-BOOT-0,
18# native/boot/diag_main.c). QEMU is an emulator: a PASS here qualifies nothing
19# about a Raspberry Pi 5.
20#
21# Builds PI5DIAG.EFI, puts it on a FAT image as EFI/BOOT/BOOTAA64.EFI, boots it in
22# QEMU AArch64 with AAVMF (-no-reboot), waits for the app to cold-reset QEMU,
23# reads \EFI\AIENOS\PI5BOOT0.TXT and every \EFI\AIENOS\ACPI\*.BIN back with mtools and
24# checks: the title and vendor lines, a firmware table line (ACPI or Device Tree),
25# the memory summary, "DONE", and that the app wrote the file (serial says so).
26# Needs qemu-system-aarch64, AAVMF, mtools. Final line:
27# AIENOS_PI5_DIAG: PASS|FAIL|NOT_RUN [(...)] exit 0 / 1 / 2 (tools) / 3 (NOT_RUN)
28set -euo pipefail
29repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
30cd "${repo_root}"
31tag="AIENOS_PI5_DIAG"
32code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
33vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
34for t in qemu-system-aarch64 mformat mmd mcopy; do
35 command -v "${t}" >/dev/null || { echo "${tag}: NOT_RUN (${t} missing)"; exit 2; }
36done
37[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "${tag}: NOT_RUN (no AAVMF)"; exit 2; }
38cross=""
39if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi
40out="${PI5DIAG_OUT:-${repo_root}/target/native-kernel-pi5-diag}"
41make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="$(git rev-parse HEAD 2>/dev/null || echo unknown)" pi5-diag >/dev/null
42
43. "${repo_root}/scripts/lib_gate_hold.sh"
44if ! gh_quiet_check || ! gh_lock_take qemu_ck_pi5_diag_test "${AIENOS_GATE_MINUTES:-60}"; then
45 echo "${tag}: NOT_RUN (${gh_why})"
46 exit 3
47fi
48work="$(mktemp -d)"
49cleanup() {
50 [[ -z "${qpid:-}" ]] || kill "${qpid}" 2>/dev/null || true
51 rm -rf "${work}"
52 gh_lock_release
53}
54trap cleanup EXIT
55
56img="${work}/esp.img"
57truncate -s 64M "${img}"
58mformat -i "${img}" -F ::
59mmd -i "${img}" ::/EFI ::/EFI/BOOT
60mcopy -i "${img}" "${out}/PI5DIAG.EFI" ::/EFI/BOOT/BOOTAA64.EFI
61cp "${vars_fd}" "${work}/vars.fd"
62qemu-system-aarch64 -M virt -accel tcg -cpu max -m 1024 \
63 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \
64 -drive if=pflash,format=raw,file="${work}/vars.fd" \
65 -drive if=none,id=esp,format=raw,file="${img}" -device virtio-blk-pci,drive=esp \
66 -display none -nic none -serial file:"${work}/serial.log" -no-reboot &
67qpid=$!
68done_seen=0
69self_exit=0
70for _ in $(seq 1 ${AIENOS_PI5_DIAG_WAIT:-240}); do
71 grep -aq "AIENOS-PI5-BOOT-0 DONE" "${work}/serial.log" 2>/dev/null && done_seen=1
72 if ! kill -0 "${qpid}" 2>/dev/null; then self_exit=1; break; fi
73 sleep 1
74done
75kill "${qpid}" 2>/dev/null || true
76wait "${qpid}" 2>/dev/null || true
77qpid=""
78
79fails=0
80chk() { # description, file, pattern
81 if grep -aqE -- "$3" "$2"; then echo "PASS $1"; else echo "FAIL $1 (no match for: $3)"; fails=$((fails + 1)); fi
82}
83tr -d '\r' <"${work}/serial.log" >"${work}/serial.txt" 2>/dev/null || : >"${work}/serial.txt"
84[[ ${done_seen} == 1 ]] || { echo "FAIL serial never showed DONE"; fails=$((fails + 1)); }
85chk "serial: report_file written" "${work}/serial.txt" '^report_file: written '
86chk "serial: cold reset requested" "${work}/serial.txt" "^reset: cold\$"
87[[ ${self_exit} == 1 ]] && echo "PASS QEMU stopped by itself after the reset (-no-reboot)" || { echo "FAIL QEMU still running: ResetSystem did not reset"; fails=$((fails + 1)); }
88if mcopy -i "${img}" ::/EFI/AIENOS/PI5BOOT0.TXT "${work}/PI5BOOT0.TXT" 2>/dev/null; then
89 echo "PASS PI5BOOT0.TXT read back from the image"
90 chk "file: title" "${work}/PI5BOOT0.TXT" '^AIENOS-PI5-BOOT-0$'
91 chk "file: vendor line" "${work}/PI5BOOT0.TXT" '^firmware_vendor: .+'
92 chk "file: UEFI spec revision" "${work}/PI5BOOT0.TXT" '^uefi_spec_revision: [0-9]+\.[0-9]+$'
93 chk "file: current EL" "${work}/PI5BOOT0.TXT" '^current_el: EL[0-3]$'
94 chk "file: memory summary" "${work}/PI5BOOT0.TXT" '^memory_map: entries=[0-9]+ conventional_mib=[0-9]+ map_key=0x[0-9a-f]+$'
95 chk "file: ACPI or Device Tree table line" "${work}/PI5BOOT0.TXT" '^table [0-9]+: .* (ACPI 1\.0|ACPI 2\.0|Device Tree) at 0x'
96 chk "file: DONE" "${work}/PI5BOOT0.TXT" '^AIENOS-PI5-BOOT-0 DONE$'
97 chk "file: milestone line" "${work}/PI5BOOT0.TXT" "^milestone: AIENOS-PI5-ACPI-0\$"
98 chk "file: RSDP line" "${work}/PI5BOOT0.TXT" "^acpi_rsdp: rev=[0-9]+ .* xsdt=0x[0-9a-f]+\$"
99 chk "file: MADT copied" "${work}/PI5BOOT0.TXT" "^acpi_table: APIC .* checksum=ok via XSDT file=APIC.BIN written\$"
100 chk "file: DSDT copied via FADT" "${work}/PI5BOOT0.TXT" "^acpi_table: DSDT .* checksum=ok via FADT file=DSDT.BIN written\$"
101 chk "file: no table failed" "${work}/PI5BOOT0.TXT" "^acpi_dump: copied=[0-9]+ failed=0\$"
102 # Every table file named in the report is on the image, starts with its
103 # signature and is exactly the length the report and its own header give.
104 while read -r sig len file; do
105 if mcopy -n -i "${img}" "::/EFI/AIENOS/ACPI/${file}" "${work}/${file}" 2>/dev/null \
106 && [[ "$(head -c 4 "${work}/${file}")" == "${sig}" ]] \
107 && [[ "$(stat -c %s "${work}/${file}")" == "${len}" ]] \
108 && [[ "$(od -An -tu4 -j4 -N4 "${work}/${file}" | tr -d " ")" == "${len}" ]]; then
109 echo "PASS ACPI/${file}: signature ${sig}, ${len} bytes"
110 else
111 echo "FAIL ACPI/${file}: missing, wrong signature or wrong length"; fails=$((fails + 1))
112 fi
113 done < <(sed -nE "s/^acpi_table: ([A-Z0-9_]{4}) rev=[0-9]+ len=([0-9]+) .* file=([A-Z0-9_]+\.BIN) written\$/\1 \2 \3/p" "${work}/PI5BOOT0.TXT")
114 echo "---- PI5BOOT0.TXT ----"; cat "${work}/PI5BOOT0.TXT"; echo "----"
115else
116 echo "FAIL PI5BOOT0.TXT not found in the image"; fails=$((fails + 1))
117fi
118if [[ ${fails} == 0 ]]; then echo "${tag}: PASS"; exit 0; fi
119echo "${tag}: FAIL (${fails} checks)"; exit 1