ci / quality (push) Successful in 2m25s
ci / badges (push) Skipped
ci / mcdc (push) Successful in 29s
ci / prune-artifacts (push) Skipped
ci / test (push) Successful in 13s
ci / bench (push) Successful in 10s
ci / patches-apply (push) Successful in 24s
ci / kernel-build (push) Skipped
ci / mcdc (pull_request) Successful in 21s
ci / bench (pull_request) Successful in 17s
ci / test (pull_request) Successful in 14s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / qemu-tools (push) Successful in 4m32s
ci / kernel-symbols (push) Successful in 4m28s
ci / patches-apply (pull_request) Successful in 57s
ci / qemu-tools (pull_request) Successful in 3m8s
ci / kernel-symbols (pull_request) Successful in 6m42s
ci / quality (pull_request) Successful in 2m19s
ci / badges (pull_request) Skipped
The rig runs busybox.net's 1.31.0 multiarch binary, not the image's 1.37.0 with its applet config, so a script calling an applet or option the panel lacks (#1903 setpriv --reuid, #2002 stat, #1349 flock -w) passes in the rig and breaks on a panel. - qemu/busybox/panel.config: the image's config, rebuilt from Buildroot 2025.02.8 busybox.config plus 0001-busybox-applets.patch, resolved for 1.37.0 as Buildroot does. patches/: Buildroot's 11 busybox patches. rig.fragment: static link and BusyBox's own passwd readers only. applets.txt and help.txt: the bench a capture (image 417a66b). - qemu/build-busybox.sh: pinned 1.37.0 source, fails on any Kconfig rewrite of the config, an applet list other than the panel's, or a dynamic binary. - qemu/lib.sh: RIG_BUSYBOX=panel selects it (default stays multiarch); the bounded verified download is now qemu_fetch_verified. - warden.shell uses warden_console_shell: cttyhack where it exists, else setsid -c on the console tty (the panel's BusyBox has no cttyhack). - CI: offline tests in qemu-tools, a build there checked against every applet's --help from the panel through qemu-user, and a second boot smoke with the panel initramfs in kernel-build. Refs flare-edge#2210 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
147 lines
5.6 KiB
Bash
147 lines
5.6 KiB
Bash
# shellcheck shell=bash
|
|
# Shared helpers for the qemu/ device-sim build scripts. Sourced, not executed.
|
|
# Callers must run under `set -euo pipefail` and define QEMU_DIR (the qemu/ dir).
|
|
|
|
BB_VER=1.31.0
|
|
BB_URL="https://busybox.net/downloads/binaries/${BB_VER}-defconfig-multiarch-musl/busybox-armv7l"
|
|
|
|
qemu_log() { printf '\033[36m== %s\033[0m\n' "$*"; }
|
|
|
|
# Download URL to DEST and verify it against the sha256 WANT. A DEST that
|
|
# already matches is kept. FAILS CLOSED: three bounded attempts, then exit 1;
|
|
# a mismatching download never lands at DEST.
|
|
# Usage: qemu_fetch_verified URL WANT DEST LABEL
|
|
qemu_fetch_verified() {
|
|
local url="$1" want="$2" dest="$3" label="$4" got
|
|
if [ -f "$dest" ]; then
|
|
got="$(sha256sum "$dest" | awk '{print $1}')"
|
|
if [ "$want" = "$got" ]; then
|
|
qemu_log "$label sha256 verified"
|
|
return
|
|
fi
|
|
qemu_log "cached $label failed verification; fetching a clean copy"
|
|
fi
|
|
|
|
# Every attempt is bounded: a server that answers and then stalls would
|
|
# otherwise hold the job until its own timeout, with no retry (#1588). Below
|
|
# 1 KiB/s for the stall window, or past the total cap, curl gives up and the
|
|
# loop moves on. Defaults cap the worst case near 6 minutes; the tests
|
|
# shorten them through the environment.
|
|
local stall="${BB_FETCH_STALL_SECS:-20}" max="${BB_FETCH_MAX_SECS:-60}"
|
|
local delay="${BB_FETCH_RETRY_DELAY:-5}"
|
|
local attempt tmp="${dest}.download.$$"
|
|
rm -f "$tmp"
|
|
for attempt in 1 2 3; do
|
|
qemu_log "downloading $url (attempt $attempt/3)"
|
|
if curl --retry 1 --retry-delay "$delay" --retry-connrefused \
|
|
--connect-timeout "$stall" --speed-limit 1024 --speed-time "$stall" \
|
|
--max-time "$max" -fSL "$url" -o "$tmp"; then
|
|
got="$(sha256sum "$tmp" | awk '{print $1}')"
|
|
if [ "$want" = "$got" ]; then
|
|
mv -f "$tmp" "$dest"
|
|
qemu_log "$label sha256 verified"
|
|
return
|
|
fi
|
|
echo "$label sha256 mismatch on attempt $attempt: want $want got $got" >&2
|
|
fi
|
|
rm -f "$tmp"
|
|
done
|
|
echo "FATAL: could not fetch pinned $label after 3 verified attempts" >&2
|
|
exit 1
|
|
}
|
|
|
|
# Provide the rig's static armv7 busybox and set $BB to its path.
|
|
#
|
|
# RIG_BUSYBOX picks which one (flare-edge#2210):
|
|
# multiarch (default) the busybox.net $BB_VER defconfig-multiarch-musl
|
|
# binary, fetched (or accepted via $BUSYBOX) and
|
|
# 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)
|
|
# 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.
|
|
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
|
|
}
|
|
OUT="$out" bash "$QEMU_DIR/build-busybox.sh"
|
|
BB="$out/busybox-armv7l-panel"
|
|
return
|
|
;;
|
|
*)
|
|
echo "FATAL: RIG_BUSYBOX must be multiarch or panel, not '${RIG_BUSYBOX}'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
local sha_file="$QEMU_DIR/busybox.sha256"
|
|
BB="${BUSYBOX:-$out/busybox-armv7l}"
|
|
# Pin first: a missing pin refuses BEFORE downloading, same ordering as
|
|
# build/fetch-kernel-tarball.sh.
|
|
[ -f "$sha_file" ] || {
|
|
echo "FATAL: no pinned sha256 for busybox (expected $sha_file): refusing to build from an unverified binary" >&2
|
|
exit 1
|
|
}
|
|
qemu_fetch_verified "$BB_URL" "$(cat "$sha_file")" "$BB" busybox
|
|
}
|
|
|
|
# Stage the shared rootfs skeleton (qemu/rootfs/ + busybox) into $1.
|
|
# Requires qemu_get_busybox to have run (uses $BB).
|
|
qemu_stage_rootfs() {
|
|
local root="$1"
|
|
mkdir -p "$root/bin" "$root/sbin" "$root/dev" "$root/proc" "$root/sys" \
|
|
"$root/etc" "$root/tmp" "$root/mnt" "$root/userdata" "$root/oem" \
|
|
"$root/usr/bin" "$root/usr/share/udhcpc"
|
|
install -m 0755 "$BB" "$root/bin/busybox"
|
|
cp -a "$QEMU_DIR/rootfs/." "$root/"
|
|
chmod 0755 "$root/init" "$root/sbin/init" "$root/etc/rc" \
|
|
"$root/usr/share/udhcpc/default.script"
|
|
# git only tracks the executable bit, so a checkout lands etc/shadow at
|
|
# whatever the umask gives a non-executable file (644 under the common
|
|
# 022) -- root's crypt hash world-readable. Force the normal shadow mode
|
|
# here, once, for every caller (mkimage.sh and mkinitramfs.sh both stage
|
|
# through this function).
|
|
chmod 0600 "$root/etc/shadow"
|
|
}
|
|
|
|
# Parse a "SIZE[@OFFSET](NAME)" blkdevparts entry list (without the "vda:"
|
|
# prefix) and invoke a callback `$1 name offset_bytes size_bytes` per entry.
|
|
qemu_each_partition() {
|
|
local cb="$1" parts entry size_s off_s name size off
|
|
parts="${WARDEN_BLKDEVPARTS#*:}"
|
|
off=0
|
|
local IFS=','
|
|
for entry in $parts; do
|
|
name="${entry##*(}"; name="${name%)}"
|
|
size_s="${entry%%(*}"
|
|
if [ "${size_s#*@}" != "$size_s" ]; then
|
|
off_s="${size_s#*@}"; size_s="${size_s%@*}"
|
|
off="$(qemu_to_bytes "$off_s")"
|
|
fi
|
|
size="$(qemu_to_bytes "$size_s")"
|
|
"$cb" "$name" "$off" "$size"
|
|
off=$((off + size))
|
|
done
|
|
}
|
|
|
|
qemu_to_bytes() {
|
|
local v="$1" n mult=1
|
|
case "$v" in
|
|
*K) n="${v%K}"; mult=1024 ;;
|
|
*M) n="${v%M}"; mult=1048576 ;;
|
|
*G) n="${v%G}"; mult=1073741824 ;;
|
|
*) n="$v" ;;
|
|
esac
|
|
case "$n" in
|
|
''|*[!0-9]*) echo "FATAL: bad blkdevparts size/offset token: '$v'" >&2; exit 1 ;;
|
|
esac
|
|
echo $((n * mult))
|
|
}
|