From 820af4baaa5c037ff836f7e59e66ae0d665a23af Mon Sep 17 00:00:00 2001 From: BFE Engineering Date: Thu, 29 Oct 2026 08:34:45 -0600 Subject: [PATCH 1/2] qemu: let a job without the cross compiler use a prebuilt panel BusyBox (flare-edge#2210) The flare-edge flow jobs get the rig BusyBox from the image build job's artifact and have no cross compiler, so RIG_BUSYBOX=panel, which always ran build-busybox.sh, could not be used there. - qemu/lib.sh: qemu_busybox_panel_inputs, one sha256 over the source pin and every committed input under qemu/busybox/ (no compiler). With RIG_BUSYBOX=panel and BUSYBOX set, qemu_get_busybox takes that binary only when BUSYBOX.inputs equals the value for this tree; otherwise it fails closed. The source pin moved here from build-busybox.sh. - qemu/build-busybox.sh writes .inputs next to the binary (also on the up-to-date path) and removes a stale one before a rebuild. - busybox-panel-test.sh: missing, foreign and matching .inputs, a missing binary, and a config or patch edit changing the inputs. - CI qemu-tools: a panel initramfs from the prebuilt binary. Refs flare-edge#2210 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG --- .github/workflows/ci.yml | 3 ++ qemu/README.md | 2 +- qemu/build-busybox.sh | 22 +++++++------- qemu/busybox/README.md | 8 ++++++ qemu/lib.sh | 48 +++++++++++++++++++++++++++---- qemu/mkimage.sh | 3 +- qemu/mkinitramfs.sh | 3 +- qemu/tests/busybox-panel-test.sh | 49 ++++++++++++++++++++++++++++++-- 8 files changed, 116 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d17dca..92855a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -274,6 +274,9 @@ jobs: bash qemu/build-busybox.sh QEMU_USER="qemu-arm" bash qemu/tests/busybox-panel-help.sh RIG_BUSYBOX=panel bash qemu/mkinitramfs.sh + # A job without the cross compiler takes the binary as BUSYBOX, + # checked by its .inputs (flare-edge flow jobs). + RIG_BUSYBOX=panel BUSYBOX=qemu/out/busybox-armv7l-panel bash qemu/mkinitramfs.sh kernel-symbols: # The symbol gate (rebuild M0, kernel_symbols_exist): expand the real diff --git a/qemu/README.md b/qemu/README.md index 56921d0..fd9292e 100644 --- a/qemu/README.md +++ b/qemu/README.md @@ -137,7 +137,7 @@ All take the virt-fragment ``; `FLARE_EDGE=` where noted. | `rootfs-overlay.sh` | - | offline, no VM: `mkimage.sh`'s `ROOTFS_OVERLAY` hook lays a directory of panel files (flare-edge's S03warden-accounts, S99lvgl, warden-ui-run) over the rootfs of both slots with their modes kept, beside the skeleton's own files; without it there is no `/etc/init.d`; an overlay that is not a directory, names anything but `etc/` and `usr/` at its top, or holds a symlink fails closed and writes no image; `ui-drive.sh --init-chain` refuses a missing directory or one without `etc/init.d/S99lvgl` before boot | | `init-chain-test.sh` | - | offline, no VM: `warden_init_chain` (rootfs/etc/warden-lib.sh) starts the executable `S*` scripts of a number range in name order, names a failing one and goes on, and counts them; `warden_rig_bus_owners` hands a bus credential to its account only when the rootfs has it; sbin/init runs S00-S09 before the bus and S10-S99 instead of the direct UI start on a `warden.initchain` boot (flare-edge #2210) | | `run-sh-args-test.sh` | - | offline, no VM: a fake `qemu-system-arm` captures run.sh's own argv and pins the ctl/rs485 pci-serial ordering contract rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on -- the ctl device always enumerates before rs485, warden.ctl only lands on the cmdline when --ctl is given, and an rs485 pci-serial device (real or null-backed) is always present so the port count never shifts | -| `busybox-panel-test.sh` | - | offline, no VM: the panel BusyBox inputs (qemu/busybox/). panel.config carries every setting of the image's applet patch, rig.fragment changes only STATIC, USE_BB_PWD_GRP and USE_BB_SHADOW, a Kconfig rewrite of any setting and an applet the panel lacks fail the build, applets.txt and help.txt agree, and RIG_BUSYBOX refuses an unknown value or a prebuilt `BUSYBOX` (flare-edge#2210) | +| `busybox-panel-test.sh` | - | offline, no VM: the panel BusyBox inputs (qemu/busybox/). panel.config carries every setting of the image's applet patch, rig.fragment changes only STATIC, USE_BB_PWD_GRP and USE_BB_SHADOW, a Kconfig rewrite of any setting and an applet the panel lacks fail the build, applets.txt and help.txt agree, and RIG_BUSYBOX refuses an unknown value, and accepts a prebuilt panel `BUSYBOX` only when its `.inputs` match this tree (flare-edge#2210) | | `busybox-panel-help.sh [BIN]` | an ARM runner (binfmt or `QEMU_USER=qemu-arm`) | the built panel BusyBox against the bench capture: its applet list and every applet's `--help` equal the panel's own binary's. CI runs it in qemu-tools after `build-busybox.sh` | | `console-shell-test.sh` | - | offline, no VM: `warden_console_shell` (warden.shell) runs `setsid cttyhack sh` where cttyhack exists, else `setsid -c sh` on the console tty read from sysfs (the panel BusyBox has no cttyhack), else a plain sh. CI runs it under bash's `sh` and busybox `sh` | | `ctl-bridge-test.sh` | - | offline, no VM: runs the control bridge (`warden_ctl_bridge` in rootfs/etc/warden-lib.sh) against a fake warden-ui that answers some commands late. A reply slower than the old 5 s bound still arrives (the bound is now 30 s, `WARDEN_CTL_WAIT_S`), a timeout answers `bridge: no reply from warden-ui ...` (qmp.py raises it as a rig fault), and a timed-out command's late reply is drained instead of being read as the next command's answer (flare-edge #1448). A fake `wthctl` stands in for the hook client behind `@hookdoc`/`@hook` (flare-edge #2054): the pieces join into one request whose args are used once, only plain words reach the client, and a missing client or a request with no reply answers a `bridge:` line. CI runs it under bash's `sh` and busybox `sh` | diff --git a/qemu/build-busybox.sh b/qemu/build-busybox.sh index 9374799..01d5add 100644 --- a/qemu/build-busybox.sh +++ b/qemu/build-busybox.sh @@ -6,7 +6,9 @@ # # Env: # OUT output dir (default qemu/out); the binary lands at -# $OUT/busybox-armv7l-panel, its input key next to it +# $OUT/busybox-armv7l-panel, its rebuild key (.key) and its +# source inputs (.inputs, see qemu_busybox_panel_inputs in +# lib.sh) next to it # CROSS_COMPILE cross toolchain prefix (default arm-linux-gnueabihf-) # BB_SRC_TARBALL a local busybox-$BB_SRC_VER.tar.bz2 (skips the download; # still verified against BB_SRC_SHA256) @@ -29,12 +31,8 @@ set -euo pipefail QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BB_DIR="$QEMU_DIR/busybox" -BB_SRC_VER=1.37.0 -BB_SRC_URL="https://busybox.net/downloads/busybox-${BB_SRC_VER}.tar.bz2" -# From https://busybox.net/downloads/busybox-1.37.0.tar.bz2.sha256, the same -# pin as Buildroot 2025.02.8 package/busybox/busybox.hash. -BB_SRC_SHA256=3311dff32e746499f4df0d5df04d7eb396382d7e108bb9250e7b519b837043a4 - +# The source pin (BB_SRC_VER, BB_SRC_URL, BB_SRC_SHA256) lives in lib.sh, +# beside qemu_busybox_panel_inputs, which a prebuilt binary is checked by. # shellcheck source=qemu/lib.sh disable=SC1091 . "$QEMU_DIR/lib.sh" @@ -95,9 +93,7 @@ bb_check_applets() { bb_input_key() { local cc="$1" { - echo "busybox $BB_SRC_VER $BB_SRC_SHA256" - sha256sum "$BB_DIR/panel.config" "$BB_DIR/rig.fragment" "$BB_DIR/applets.txt" \ - "$BB_DIR"/patches/*.patch | awk '{print $1}' + qemu_busybox_panel_inputs echo "$cc" "${cc}gcc" --version | head -n 1 } | sha256sum | awk '{print $1}' @@ -117,9 +113,12 @@ bb_main() { mkdir -p "$out" key="$(bb_input_key "$cc")" if [ -f "$bin" ] && [ "$(cat "$bin.key" 2>/dev/null)" = "$key" ]; then + qemu_busybox_panel_inputs > "$bin.inputs" qemu_log "panel busybox up to date ($bin)" return fi + # A stale .inputs must never vouch for a binary while it is rebuilt. + rm -f "$bin.inputs" tar="${BB_SRC_TARBALL:-$out/busybox-${BB_SRC_VER}.tar.bz2}" qemu_fetch_verified "$BB_SRC_URL" "$BB_SRC_SHA256" "$tar" "busybox ${BB_SRC_VER} source" @@ -171,6 +170,9 @@ bb_main() { install -m 0755 "$src/busybox" "$bin.tmp" mv -f "$bin.tmp" "$bin" printf '%s\n' "$key" > "$bin.key" + # For a job without the cross compiler: qemu_get_busybox accepts this + # binary as BUSYBOX under RIG_BUSYBOX=panel when the inputs match its tree. + qemu_busybox_panel_inputs > "$bin.inputs" qemu_log "panel busybox: $bin ($(sha256sum "$bin" | awk '{print $1}'))" } diff --git a/qemu/busybox/README.md b/qemu/busybox/README.md index bb1a2ca..ff2886a 100644 --- a/qemu/busybox/README.md +++ b/qemu/busybox/README.md @@ -26,3 +26,11 @@ The inputs are pinned (source tarball sha256, these files); the output is not, because each host's compiler gives a different binary. The cache key in `$OUT/busybox-armv7l-panel.key` covers the tarball, these files and the compiler version. + +A job without the cross compiler (a flare-edge flow job, given the binary its +image build job made) sets `RIG_BUSYBOX=panel BUSYBOX=`. The build +writes `.inputs` next to it: one sha256 over the source pin and these +files, without the compiler (`qemu_busybox_panel_inputs` in qemu/lib.sh). +`qemu_get_busybox` takes the prebuilt binary only when that file equals the +value for its own tree, so a binary built from another config is refused +rather than booted. diff --git a/qemu/lib.sh b/qemu/lib.sh index b9e7d65..4ca3798 100644 --- a/qemu/lib.sh +++ b/qemu/lib.sh @@ -4,6 +4,14 @@ BB_VER=1.31.0 BB_URL="https://busybox.net/downloads/binaries/${BB_VER}-defconfig-multiarch-musl/busybox-armv7l" +# The panel BusyBox source (RIG_BUSYBOX=panel, qemu/build-busybox.sh). From +# https://busybox.net/downloads/busybox-1.37.0.tar.bz2.sha256, the same pin as +# Buildroot 2025.02.8 package/busybox/busybox.hash. +BB_SRC_VER=1.37.0 +# Read by build-busybox.sh, which sources this file. +# shellcheck disable=SC2034 +BB_SRC_URL="https://busybox.net/downloads/busybox-${BB_SRC_VER}.tar.bz2" +BB_SRC_SHA256=3311dff32e746499f4df0d5df04d7eb396382d7e108bb9250e7b519b837043a4 qemu_log() { printf '\033[36m== %s\033[0m\n' "$*"; } @@ -50,6 +58,19 @@ qemu_fetch_verified() { exit 1 } +# The source inputs of the panel BusyBox, as one sha256: the pinned source +# tarball and every committed file under qemu/busybox/ the build reads. The +# compiler is not part of it (build-busybox.sh keys its rebuild on that too), +# so a job without the cross compiler can check a binary another job built. +# build-busybox.sh writes it next to the binary as .inputs. +qemu_busybox_panel_inputs() { + local d="$QEMU_DIR/busybox" + { + echo "busybox $BB_SRC_VER $BB_SRC_SHA256" + (cd "$d" && sha256sum panel.config rig.fragment applets.txt patches/*.patch) + } | sha256sum | awk '{print $1}' +} + # Provide the rig's static armv7 busybox and set $BB to its path. # # RIG_BUSYBOX picks which one (flare-edge#2210): @@ -58,20 +79,35 @@ qemu_fetch_verified() { # verified against qemu/busybox.sha256 # panel the image's BusyBox version and applet config, built # from source by qemu/build-busybox.sh (needs a cross -# compiler; checked by its applet list, see there) +# compiler; checked by its applet list, see there). +# With $BUSYBOX set, that prebuilt panel binary is used +# instead (a job without the cross compiler, given the +# binary an earlier build job made): it is accepted only +# when its $BUSYBOX.inputs, written by build-busybox.sh, +# equals qemu_busybox_panel_inputs of this tree, so a +# binary built from other config files is refused. # FAILS CLOSED: a missing pin refuses to build, never silently skips # verification, mirroring build/build-kernel.sh's tarball handling; an -# unknown RIG_BUSYBOX, or $BUSYBOX with the panel build, is refused. +# unknown RIG_BUSYBOX, or a prebuilt panel binary without matching inputs, +# is refused. qemu_get_busybox() { local out="${OUT:-$QEMU_DIR/out}" mkdir -p "$out" case "${RIG_BUSYBOX:-multiarch}" in multiarch) ;; panel) - [ -z "${BUSYBOX:-}" ] || { - echo "FATAL: BUSYBOX=$BUSYBOX names a prebuilt binary; RIG_BUSYBOX=panel builds its own (unset one of them)" >&2 - exit 1 - } + if [ -n "${BUSYBOX:-}" ]; then + local want got + want="$(qemu_busybox_panel_inputs)" + got="$(cat "$BUSYBOX.inputs" 2>/dev/null || true)" + [ -f "$BUSYBOX" ] && [ "$got" = "$want" ] || { + echo "FATAL: BUSYBOX=$BUSYBOX is not a panel BusyBox built from this tree's qemu/busybox/ ($BUSYBOX.inputs '${got:-missing}', want '$want'): run qemu/build-busybox.sh" >&2 + exit 1 + } + BB="$BUSYBOX" + qemu_log "panel busybox: prebuilt $BB (inputs $want)" + return + fi OUT="$out" bash "$QEMU_DIR/build-busybox.sh" BB="$out/busybox-armv7l-panel" return diff --git a/qemu/mkimage.sh b/qemu/mkimage.sh index 1f766c8..b7ac9f9 100755 --- a/qemu/mkimage.sh +++ b/qemu/mkimage.sh @@ -15,7 +15,8 @@ # flare-edge build's rootfs.img/oem.img matched pair) into slot A instead of # the busybox skeleton; slot B keeps the skeleton as a known-good fallback. # Env: -# BUSYBOX path to a local busybox binary (skips the download; still verified) +# BUSYBOX path to a local busybox binary (skips the download; still verified; +# with RIG_BUSYBOX=panel a prebuilt panel binary, checked by its .inputs) # RIG_BUSYBOX multiarch (default) or panel: the image's own BusyBox, built by # qemu/build-busybox.sh (see qemu/busybox/README.md) # OUT output dir (default: qemu/out); image at $OUT/disk.img diff --git a/qemu/mkinitramfs.sh b/qemu/mkinitramfs.sh index ff11e9d..b4086a5 100755 --- a/qemu/mkinitramfs.sh +++ b/qemu/mkinitramfs.sh @@ -4,7 +4,8 @@ # see qemu/lib.sh). # # Env: -# BUSYBOX path to a local busybox binary (skips the download; still verified) +# BUSYBOX path to a local busybox binary (skips the download; still verified; +# with RIG_BUSYBOX=panel a prebuilt panel binary, checked by its .inputs) # RIG_BUSYBOX multiarch (default) or panel: the image's own BusyBox, built by # qemu/build-busybox.sh (see qemu/busybox/README.md) # OUT output dir (default: qemu/out); initramfs at $OUT/initramfs.cpio.gz diff --git a/qemu/tests/busybox-panel-test.sh b/qemu/tests/busybox-panel-test.sh index f1d2c57..fcc737e 100644 --- a/qemu/tests/busybox-panel-test.sh +++ b/qemu/tests/busybox-panel-test.sh @@ -108,10 +108,53 @@ if ! RIG_BUSYBOX=bogus run_get && grep -q 'RIG_BUSYBOX must be multiarch or pane else fail "an unknown RIG_BUSYBOX was accepted" fi -if ! RIG_BUSYBOX=panel BUSYBOX=/nonexistent run_get && grep -q 'names a prebuilt binary' "$SCRATCH/get.err"; then - pass "RIG_BUSYBOX=panel with BUSYBOX set is refused" + +# 7b. A prebuilt panel binary (a flow job without the cross compiler) is taken +# only with a .inputs equal to this tree's qemu_busybox_panel_inputs. +inputs="$(QEMU_DIR="$QEMU_DIR" qemu_busybox_panel_inputs)" +if [[ "$inputs" =~ ^[0-9a-f]{64}$ ]]; then + pass "qemu_busybox_panel_inputs is one sha256" else - fail "RIG_BUSYBOX=panel accepted a prebuilt BUSYBOX" + fail "qemu_busybox_panel_inputs gave '$inputs'" +fi +mkdir -p "$SCRATCH/pre" +printf 'stand-in\n' > "$SCRATCH/pre/bb" +if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err" && + grep -q "inputs 'missing'" "$SCRATCH/get.err"; then + pass "a prebuilt panel BUSYBOX without .inputs is refused" +else + fail "a prebuilt panel BUSYBOX without .inputs was accepted" +fi +printf '%s\n' "$(printf '%s' "$inputs" | tr '0-9a-f' '1-9a-f0')" > "$SCRATCH/pre/bb.inputs" +if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err"; then + pass "a prebuilt panel BUSYBOX built from other inputs is refused" +else + fail "a prebuilt panel BUSYBOX with other inputs was accepted" +fi +printf '%s\n' "$inputs" > "$SCRATCH/pre/bb.inputs" +got_bb="$(RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" QEMU_DIR="$QEMU_DIR" OUT="$SCRATCH/out" \ + bash -c '. "$QEMU_DIR/lib.sh"; set -euo pipefail; qemu_get_busybox >/dev/null; printf %s "$BB"' 2>"$SCRATCH/get.err")" +if [ "$got_bb" = "$SCRATCH/pre/bb" ] && [ ! -e "$SCRATCH/out/busybox-armv7l-panel" ]; then + pass "a prebuilt panel BUSYBOX with matching .inputs is used as is, nothing built" +else + fail "a prebuilt panel BUSYBOX with matching .inputs was not used (BB='$got_bb': $(cat "$SCRATCH/get.err"))" +fi +if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/none" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err"; then + pass "a prebuilt panel BUSYBOX that does not exist is refused" +else + fail "a missing prebuilt panel BUSYBOX was accepted" +fi +# Every committed input file is in the inputs hash: a config edit changes it. +mkdir -p "$SCRATCH/qcopy" +cp -a "$QEMU_DIR/busybox" "$SCRATCH/qcopy/" +printf '# CONFIG_TIMEOUT is not set\n' >> "$SCRATCH/qcopy/busybox/panel.config" +other="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)" +printf 'x\n' >> "$SCRATCH/qcopy/busybox/patches/$(ls "$QEMU_DIR/busybox/patches" | head -n 1)" +other2="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)" +if [ "$other" != "$inputs" ] && [ "$other2" != "$other" ]; then + pass "a panel.config or patch edit changes qemu_busybox_panel_inputs" +else + fail "qemu_busybox_panel_inputs ignored a panel.config or patch edit" fi # 8. No cross compiler: the build fails closed, it never falls back. -- 2.54.0 From 8fc32976a5b296de17c4eae6f3f87ceeee4f4d53 Mon Sep 17 00:00:00 2001 From: BFE Engineering Date: Thu, 29 Oct 2026 09:10:37 -0600 Subject: [PATCH 2/2] qemu: clear the two shellcheck notes in the prebuilt BusyBox check (flare-edge#2210) CI's shellcheck 0.9.0 failed qemu-tools on #38: SC2015 on the `[ -f ] && [ = ] || { ... }` refusal in qemu_get_busybox (now an if), and SC2012 on the `ls | head` that picks a patch to edit in busybox-panel-test.sh (now find | sort | head). No behaviour change. Refs flare-edge#2210 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG --- qemu/lib.sh | 4 ++-- qemu/tests/busybox-panel-test.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/qemu/lib.sh b/qemu/lib.sh index 4ca3798..cff57f2 100644 --- a/qemu/lib.sh +++ b/qemu/lib.sh @@ -100,10 +100,10 @@ qemu_get_busybox() { local want got want="$(qemu_busybox_panel_inputs)" got="$(cat "$BUSYBOX.inputs" 2>/dev/null || true)" - [ -f "$BUSYBOX" ] && [ "$got" = "$want" ] || { + if [ ! -f "$BUSYBOX" ] || [ "$got" != "$want" ]; then echo "FATAL: BUSYBOX=$BUSYBOX is not a panel BusyBox built from this tree's qemu/busybox/ ($BUSYBOX.inputs '${got:-missing}', want '$want'): run qemu/build-busybox.sh" >&2 exit 1 - } + fi BB="$BUSYBOX" qemu_log "panel busybox: prebuilt $BB (inputs $want)" return diff --git a/qemu/tests/busybox-panel-test.sh b/qemu/tests/busybox-panel-test.sh index fcc737e..d52c1fd 100644 --- a/qemu/tests/busybox-panel-test.sh +++ b/qemu/tests/busybox-panel-test.sh @@ -149,7 +149,8 @@ mkdir -p "$SCRATCH/qcopy" cp -a "$QEMU_DIR/busybox" "$SCRATCH/qcopy/" printf '# CONFIG_TIMEOUT is not set\n' >> "$SCRATCH/qcopy/busybox/panel.config" other="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)" -printf 'x\n' >> "$SCRATCH/qcopy/busybox/patches/$(ls "$QEMU_DIR/busybox/patches" | head -n 1)" +first_patch="$(find "$SCRATCH/qcopy/busybox/patches" -maxdepth 1 -type f -name '*.patch' | sort | head -n 1)" +printf 'x\n' >> "$first_patch" other2="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)" if [ "$other" != "$inputs" ] && [ "$other2" != "$other" ]; then pass "a panel.config or patch edit changes qemu_busybox_panel_inputs" -- 2.54.0