Files
bfe-core1106-sdk/qemu/mkinitramfs.sh
T
NoahandClaude Sonnet 5.5 445b2082f5
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / kernel-symbols (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / badges (push) Canceled after 0s
qemu: check the kernel contract at boot and run a staged script (warden.run)
init verifies build/required-symbols.txt against the guest's /proc/config.gz,
the cgroup v2 controllers and PSI and prints markers; boot-smoke.sh fails when a
marker is missing. mkinitramfs.sh stages the list and merges EXTRA_DIR; run.sh
--append passes warden.run=<path>, which init runs before powering off (used by the
flare-edge M0 limit tests). README notes the symbol lists.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
2026-10-09 10:45:22 -06:00

37 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the QEMU device-sim initramfs: the pinned static busybox + qemu/rootfs/.
# The busybox binary is the ONLY external input (sha256-pinned, fail-closed:
# see qemu/lib.sh).
#
# Env:
# BUSYBOX path to a local busybox binary (skips the download; still verified)
# OUT output dir (default: qemu/out); initramfs at $OUT/initramfs.cpio.gz
# EXTRA_DIR a directory merged into the initramfs root (a test's scripts and
# static binaries; init runs one on warden.run=<path>)
set -euo pipefail
QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=qemu/lib.sh disable=SC1091
. "$QEMU_DIR/lib.sh"
OUT="${OUT:-$QEMU_DIR/out}"
qemu_get_busybox
# Assemble in a scratch dir, removed on exit (scratch-dir leaks were a past
# review finding in this repo).
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/warden-qemu-initramfs.XXXXXX")"
trap 'rm -rf "$SCRATCH"' EXIT
qemu_stage_rootfs "$SCRATCH/root"
# The kernel symbol list, so init can check it against /proc/config.gz.
install -D -m 0644 "$QEMU_DIR/../build/required-symbols.txt" "$SCRATCH/root/etc/required-symbols.txt"
if [ -n "${EXTRA_DIR:-}" ]; then
[ -d "$EXTRA_DIR" ] || { echo "FATAL: EXTRA_DIR is not a directory: $EXTRA_DIR" >&2; exit 1; }
cp -a "$EXTRA_DIR/." "$SCRATCH/root/"
fi
# Pack (newc cpio, gzip). No device nodes required: /init mounts devtmpfs and
# reopens the console itself, so the archive builds unprivileged.
( cd "$SCRATCH/root" && find . -print0 | cpio -0 -o -H newc -R +0:+0 2>/dev/null ) \
| gzip -9 > "$OUT/initramfs.cpio.gz"
qemu_log "initramfs: $OUT/initramfs.cpio.gz ($(du -h "$OUT/initramfs.cpio.gz" | cut -f1))"