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

36 lines · 2369 bytes Raw Blame History
1#!/bin/sh
2# ck_fat_boot_test.sh -- host test of the AIENOS boot section: the EFI System
3# Partition added in unused space (native/kernel/dev/gpt_add.c) and the FAT32
4# volume holding \EFI\BOOT\BOOTX64.EFI (native/kernel/dev/fat_boot.c), with
5# power cuts. See native/kernel/dev/tests/fat_boot_test.c. The volumes it
6# writes are then read by outside tools as judges: fsck.fat must find nothing
7# to repair and mtools must read back BOOTX64.EFI byte for byte. Hosted only.
8# Ends with "AIENOS_FAT_BOOT: PASS" or "AIENOS_FAT_BOOT: FAIL <why>".
9set -u
10cd "$(dirname "$0")/.."
11K=native/kernel
12N=native
13W=$(mktemp -d "${TMPDIR:-/tmp}/ck_fat_boot.XXXXXX")
14trap 'rm -rf "$W"' EXIT
15fail() { echo "AIENOS_FAT_BOOT: FAIL $*"; exit 1; }
16CC=${HOSTCC:-cc}
17$CC -std=c11 -D_DEFAULT_SOURCE -O2 -Wall -Wextra -Werror -I$K/dev -I$K/tools -I$N/disk -I$N/argus \
18 -o "$W/test" $K/dev/tests/fat_boot_test.c $K/dev/fat_boot.c $K/dev/gpt_add.c $K/dev/disk_part.c \
19 $K/tools/gpt_write.c $N/disk/disk.c $N/disk/disk_file.c $N/argus/sha256.c || fail "test does not build"
20"$W/test" "$W" || fail "boot section checks"
21FSCK=$(command -v fsck.fat || echo /usr/sbin/fsck.fat)
22for v in part1 part2 part3; do
23 "$FSCK" -n "$W/$v.img" >"$W/$v.fsck" 2>&1 || { cat "$W/$v.fsck"; fail "fsck.fat finds faults in $v"; }
24done
25"$FSCK" -n -v "$W/part1.img" | grep -q "2 FATs, 32 bit entries" || fail "fsck.fat does not see FAT32"
26export MTOOLS_SKIP_CHECK=1
27mtype -i "$W/part1.img" ::/EFI/BOOT/BOOTX64.EFI >"$W/got1" || fail "mtools cannot read BOOTX64.EFI (part1)"
28cmp -s "$W/got1" "$W/img1.bin" || fail "BOOTX64.EFI read by mtools differs from the image (part1)"
29mtype -i "$W/part2.img" ::/EFI/BOOT/BOOTX64.EFI >"$W/got2" || fail "mtools cannot read BOOTX64.EFI (part2)"
30cmp -s "$W/got2" "$W/img2.bin" || fail "BOOTX64.EFI read by mtools differs from the image (part2)"
31mtype -i "$W/part3.img" ::/EFI/BOOT/BOOTX64.EFI >"$W/got3" || fail "mtools cannot read BOOTX64.EFI (part3)"
32cmp -s "$W/got3" "$W/img1.bin" || fail "BOOTX64.EFI read by mtools differs from the image (part3)"
33mdir -i "$W/part2.img" -b ::/EFI/BOOT | grep -qx "::/EFI/BOOT/BOOTX64.MAN" || fail "no BOOTX64.MAN"
34[ "$(mdir -i "$W/part2.img" -b ::/EFI/BOOT | wc -l)" = 2 ] || fail "\\EFI\\BOOT holds more than the two files"
35echo "note: fsck.fat clean on all three volumes; mtools reads BOOTX64.EFI exactly"
36echo "AIENOS_FAT_BOOT: PASS"