build: unpack the pinned Buildroot tree into the vendor SDK
ci / badges (push) Skipped
ci / mcdc (push) Successful in 18s
ci / test (push) Successful in 17s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 41s
ci / patches-apply (push) Successful in 20s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 31s
ci / test (pull_request) Successful in 15s
ci / mcdc (pull_request) Successful in 13s
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 39s
ci / patches-apply (pull_request) Successful in 14s
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (pull_request) Skipped
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped

build/unpack-buildroot.sh fetches buildroot-2025.02.8 through
fetch-buildroot-tarball.sh (sha256-pinned) and unpacks it to
sysdrv/source/buildroot/buildroot-2025.02.8, the tree the patched
project/build.sh and sysdrv/Makefile select. It refuses an SDK whose
selectors are not patched, leaves an existing tree alone, and never leaves a
partial tree at the final path. flare-edge's build-firmware.sh calls it right
after applying luckfox-sdk-patches/.

Offline regression tests cover the fresh unpack, the existing-tree no-op and
every refusal path; the qemu-tools job runs and shellchecks them.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
This commit is contained in:
Noah
2026-09-28 11:10:53 -06:00
co-authored by Claude Opus 5.5
parent 5f36beb44a
commit 67da1141a0
7 changed files with 233 additions and 10 deletions
+7 -1
View File
@@ -111,7 +111,8 @@ jobs:
shellcheck -x qemu/*.sh qemu/tests/*.sh build/*.sh \
qemu/rootfs/etc/warden-lib.sh qemu/rootfs/etc/rc \
qemu/rootfs/sbin/init qemu/rootfs/init tests/mk-bootimg/*.sh \
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh \
tests/unpack-buildroot/*.sh
- name: cache apt archives (python3-pil)
# Same cost class as the busybox binary cached below: a system package
# plus its libjpeg/libpng transitive deps, downloaded fresh on every
@@ -166,6 +167,11 @@ jobs:
# Retry-on-mismatch, cleanup, and the already-verified
# short-circuit, against a fake curl on PATH: no network.
run: bash tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh
- name: unpack-buildroot regression tests
# Fresh unpack, leave-existing-tree-alone, and every refusal path
# (unpatched selectors, bad tarball, half-present tree, failed
# fetch), against a stub fetch script: no network (issue #4).
run: bash tests/unpack-buildroot/run-unpack-buildroot-tests.sh
- name: mk-bootimg boot.img validation regression tests
# Guards issue #22 (a missing/erroring fdtget silently skipping the
# data-position check) plus the FIT metadata and per-image
+3 -7
View File
@@ -12,13 +12,9 @@
# Same shape as fetch-kernel-tarball.sh, deliberately: a version bump edits this
# file and the pin beside it, nothing else. FAILS CLOSED on a missing pin.
#
# Not wired into build-firmware.sh or CI yet -- tools/build-firmware.sh stages
# sdk-patches/buildroot/ onto whatever buildroot tree the vendor SDK already
# has, it does not yet extract this pinned tarball over it. Exercised today by
# tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh and by
# running the script by hand; wiring it into the real build path is a separate
# change (it has to reconcile the pristine tree with the existing SDK buildroot
# checkout first).
# Called by build/unpack-buildroot.sh, which flare-edge's
# tools/build-firmware.sh runs after applying luckfox-sdk-patches/ (issue #4).
# Tested by tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh.
#
# Usage: fetch-buildroot-tarball.sh <destination-path>
set -euo pipefail
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# Unpack the pinned Buildroot tree where the vendor SDK builds it.
#
# The vendor SDK ships buildroot-2023.02.6. WardenOS builds against
# buildroot-2025.02.8, which is not in the vendor checkout, so a clean checkout
# plus luckfox-sdk-patches/ had nothing to build (blueflare/bfe-core1106-sdk#4).
# This script closes that gap: it fetches the tarball with
# fetch-buildroot-tarball.sh (sha256-pinned, fails closed) and unpacks it to
# sysdrv/source/buildroot/buildroot-<ver>, the path the patched project/build.sh
# and sysdrv/Makefile select.
#
# Idempotent. An SDK that already has the tree is left alone, so the
# persistent CI SDK and the workstation SDK are untouched. A partial unpack
# never lands at the final path: the tarball is unpacked into a scratch
# directory beside it and moved into place only when complete.
#
# Our own Buildroot delta (defconfigs, package patches, the busybox applet
# patch) is NOT applied here. flare-edge's tools/build-firmware.sh stages it
# after this script runs, the same way it applies the rest of the series.
#
# Usage: unpack-buildroot.sh <vendor-sdk-dir>
#
# The tarball is cached at sysdrv/source/buildroot/buildroot-<ver>.tar.xz
# (inside a directory the vendor .gitignore already ignores); set
# WARDEN_BUILDROOT_TARBALL to use another path.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
FETCH="$HERE/fetch-buildroot-tarball.sh"
SDK="${1:?usage: unpack-buildroot.sh <vendor-sdk-dir>}"
die() { echo "unpack-buildroot: FATAL: $*" >&2; exit 1; }
[ -f "$FETCH" ] || die "missing $FETCH"
BRVER="$(sed -n 's/^BRVER=//p' "$FETCH" | head -1)"
case "$BRVER" in
''|*[!0-9.]*) die "cannot read BRVER from $FETCH" ;;
esac
# The SDK must already select this version. Both selectors come from
# luckfox-sdk-patches/board/ (0006 for project/build.sh, 0009 for
# sysdrv/Makefile); if either still names another tree the series has not
# been applied, and unpacking would only hide that.
BUILD_SH="$SDK/project/build.sh"
MAKEFILE="$SDK/sysdrv/Makefile"
[ -f "$BUILD_SH" ] || die "no vendor SDK at $SDK (missing project/build.sh)"
[ -f "$MAKEFILE" ] || die "no vendor SDK at $SDK (missing sysdrv/Makefile)"
# shellcheck disable=SC2016 # the literal ${SDK_SYSDRV_DIR} text in build.sh
sel_build="$(sed -n 's|^BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/||p' "$BUILD_SH" | head -1)"
sel_make="$(sed -n 's/^BUILDROOT_VER[[:space:]]*?=[[:space:]]*//p' "$MAKEFILE" | head -1)"
[ "$sel_build" = "buildroot-$BRVER" ] ||
die "project/build.sh selects '${sel_build:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
[ "$sel_make" = "buildroot-$BRVER" ] ||
die "sysdrv/Makefile selects '${sel_make:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
PARENT="$SDK/sysdrv/source/buildroot"
TREE="$PARENT/buildroot-$BRVER"
TB="${WARDEN_BUILDROOT_TARBALL:-$PARENT/buildroot-$BRVER.tar.xz}"
if [ -f "$TREE/Makefile" ] && [ -d "$TREE/configs" ] && [ -d "$TREE/package" ]; then
echo "buildroot-$BRVER: tree already present at ${TREE#"$SDK"/}"
exit 0
fi
# Something is at the path but it is not a Buildroot tree. Deleting it here
# could destroy build output in a shared SDK, so say so and stop.
[ ! -e "$TREE" ] || die "$TREE exists but is not a complete Buildroot tree; remove it and rerun"
mkdir -p "$PARENT"
bash "$FETCH" "$TB"
SCRATCH="$(mktemp -d "$PARENT/.unpack-buildroot.XXXXXX")"
[ -d "$SCRATCH" ] || die "mktemp failed under $PARENT"
cleanup() { rm -rf "$SCRATCH"; }
trap cleanup EXIT
echo "== unpacking buildroot-$BRVER into ${TREE#"$SDK"/}"
tar -xJf "$TB" -C "$SCRATCH"
[ -f "$SCRATCH/buildroot-$BRVER/Makefile" ] ||
die "tarball did not contain buildroot-$BRVER/Makefile"
mv "$SCRATCH/buildroot-$BRVER" "$TREE"
echo "buildroot-$BRVER: unpacked"
+2 -1
View File
@@ -17,7 +17,8 @@
# release tarball has no commit to name:
#
# linux-6.18.46 build/fetch-kernel-tarball.sh
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh (unpacked into the
# vendor SDK by build/unpack-buildroot.sh)
#
# The buildroot one matters more than it looks. The firmware builds against
# sysdrv/source/buildroot/buildroot-2025.02.8 inside the vendor SDK, and the
+1 -1
View File
@@ -13,7 +13,7 @@ execute code on private infrastructure (ADR-0007).
| `mcdc` | ubuntu-latest | 100% MC/DC enforced on every `drivers/*/test` (gcc-14 `-fcondition-coverage`). |
| `bench` | ubuntu-latest | Smoke-runs the sim + rs485-bridge micro-benchmarks; emits ns/op trend JSON. |
| `patches-apply` | ubuntu-latest | Fetches pristine linux-6.18.46 (cached, sha256-verified) and applies `patches/*` in order. |
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`, `tests/unpack-buildroot/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, unpack-buildroot, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
| `quality` | ubuntu-latest | Codacy-style grade computed in-pipeline: clippy, cppcheck, shellcheck, ruff, lizard, jscpd, cargo-audit feed `tools/quality/score.py` (SQALE debt ratio + a separate worst-of security axis; SonarQube's published thresholds). Uploads `quality.json`; fails if the security grade is worse than C. |
| `kernel-build` | ubuntu-latest, **dispatch-only** | apt-installs the cross toolchain + qemu, `build/build-kernel.sh` -> `zImage` + `rv1106-warden.dtb`, QEMU `-M virt` boot smoke (fail-closed), artifact upload (best-effort). Trigger: `gh workflow run ci.yml`. |
| `prune-artifacts` | ubuntu-latest, dispatch-only | Deletes `kernel-rv1106` artifacts beyond the newest 3. |
+1
View File
@@ -37,6 +37,7 @@ scripts=(
"qemu/tests/stage-rootfs-perms.sh"
"tests/fetch-vendor/run-fetch-vendor-tests.sh"
"tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh"
"tests/unpack-buildroot/run-unpack-buildroot-tests.sh"
"tests/mk-bootimg/run-boot-img-validate-tests.sh"
"tests/mk-bootimg/run-help-tests.sh"
"tests/mk-bootimg/run-ci-wiring-tests.sh"
+138
View File
@@ -0,0 +1,138 @@
#!/usr/bin/env bash
# Regression tests for build/unpack-buildroot.sh (blueflare/bfe-core1106-sdk#4).
#
# A clean vendor checkout plus luckfox-sdk-patches/ could not build WardenOS
# because nothing put buildroot-2025.02.8 where the SDK builds it. The unpack
# script is now the thing that does, and the persistent CI SDK depends on it
# leaving an existing tree alone. These cases pin both halves: a fresh SDK
# gets a complete tree, an existing tree is never touched or re-fetched, and
# every refusal (unpatched selectors, a bad tarball, a half-present tree, a
# failed fetch) leaves no tree and no scratch directory behind.
#
# Runs the real script, copied beside a stub fetch-buildroot-tarball.sh that
# copies a local fixture tarball instead of downloading. No network, no SDK.
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="$HERE/../../build/unpack-buildroot.sh"
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
FAIL=0
ok() { printf '[PASS] %s\n' "$1"; }
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
TMP="$(mktemp -d)" || { echo "FAIL: mktemp -d failed"; exit 1; }
[ -d "$TMP" ] || { echo "FAIL: mktemp -d failed"; exit 1; }
trap 'rm -rf "$TMP"' EXIT
VER=2025.02.8
# Fixture tarballs: a minimal Buildroot-shaped tree, and one without Makefile.
mk_tarball() { # mk_tarball <out.tar.xz> <with-makefile:0|1>
local out="$1" mf="$2" src
src="$(mktemp -d "$TMP/src.XXXXXX")"
mkdir -p "$src/buildroot-$VER/configs" "$src/buildroot-$VER/package/busybox"
printf 'CONFIG\n' > "$src/buildroot-$VER/package/busybox/busybox.config"
[ "$mf" = 1 ] && printf 'all:\n' > "$src/buildroot-$VER/Makefile"
tar -cJf "$out" -C "$src" "buildroot-$VER"
}
mk_tarball "$TMP/good.tar.xz" 1
mk_tarball "$TMP/nomakefile.tar.xz" 0
# setup <case> <tarball-or-FAIL> -> fixture dir holding build/ and sdk/
setup() {
local dir="$TMP/$1" src="$2"
mkdir -p "$dir/build" "$dir/sdk/project" "$dir/sdk/sysdrv/source/buildroot"
cp "$SCRIPT" "$dir/build/unpack-buildroot.sh"
{
echo '#!/usr/bin/env bash'
echo "BRVER=$VER"
echo "echo fetch-called >> \"$dir/fetch-calls\""
if [ "$src" = FAIL ]; then echo 'exit 1'; else echo "cp \"$src\" \"\$1\""; fi
} > "$dir/build/fetch-buildroot-tarball.sh"
# shellcheck disable=SC2016 # build.sh carries the literal text
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-%s\n' "$VER" \
> "$dir/sdk/project/build.sh"
printf 'BUILDROOT_VER ?= buildroot-%s\n' "$VER" > "$dir/sdk/sysdrv/Makefile"
printf '%s' "$dir"
}
run() { # run <dir> -> $OUT, $RC
OUT="$(bash "$1/build/unpack-buildroot.sh" "$1/sdk" 2>&1)"; RC=$?
}
tree() { printf '%s' "$1/sdk/sysdrv/source/buildroot/buildroot-$VER"; }
fetches() { [ -f "$1/fetch-calls" ] && wc -l < "$1/fetch-calls" || echo 0; }
no_scratch() { ! compgen -G "$1/sdk/sysdrv/source/buildroot/.unpack-buildroot.*" >/dev/null; }
# A. Fresh SDK: fetched once, unpacked to the selected path, no scratch left.
d="$(setup fresh "$TMP/good.tar.xz")"; run "$d"
if [ "$RC" -eq 0 ] && [ -f "$(tree "$d")/Makefile" ] && [ -f "$(tree "$d")/package/busybox/busybox.config" ] \
&& [ "$(fetches "$d")" -eq 1 ] && no_scratch "$d"; then
ok "fresh SDK: tree unpacked, one fetch, no scratch left"
else
bad "fresh SDK: tree unpacked, one fetch, no scratch left (rc=$RC, out=$OUT)"
fi
# B. Rerun on that SDK: already present, no second fetch, content untouched.
printf 'LOCAL\n' > "$(tree "$d")/package/busybox/busybox.config"
run "$d"
if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q 'tree already present' \
&& [ "$(fetches "$d")" -eq 1 ] && grep -qx LOCAL "$(tree "$d")/package/busybox/busybox.config"; then
ok "existing tree: left alone, not re-fetched"
else
bad "existing tree: left alone, not re-fetched (rc=$RC, out=$OUT)"
fi
# C. project/build.sh still selects the vendor tree: refuse, fetch nothing.
d="$(setup unpatched-build "$TMP/good.tar.xz")"
# shellcheck disable=SC2016 # build.sh carries the literal text
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6\n' > "$d/sdk/project/build.sh"
run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'project/build.sh selects' \
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
ok "unpatched project/build.sh: refused before fetching"
else
bad "unpatched project/build.sh: refused before fetching (rc=$RC, out=$OUT)"
fi
# D. sysdrv/Makefile still selects the vendor tree: refuse, fetch nothing.
d="$(setup unpatched-make "$TMP/good.tar.xz")"
printf 'BUILDROOT_VER ?= buildroot-2023.02.6\n' > "$d/sdk/sysdrv/Makefile"
run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'sysdrv/Makefile selects' \
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
ok "unpatched sysdrv/Makefile: refused before fetching"
else
bad "unpatched sysdrv/Makefile: refused before fetching (rc=$RC, out=$OUT)"
fi
# E. Tarball without a Buildroot Makefile: refuse, no tree, no scratch.
d="$(setup bad-tarball "$TMP/nomakefile.tar.xz")"; run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'did not contain' \
&& [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
ok "tarball without Makefile: refused, nothing left behind"
else
bad "tarball without Makefile: refused, nothing left behind (rc=$RC, out=$OUT)"
fi
# F. A half-present tree (an interrupted hand unpack): refuse, keep it as is.
d="$(setup half-tree "$TMP/good.tar.xz")"
mkdir -p "$(tree "$d")/output"; printf 'keep\n' > "$(tree "$d")/output/marker"
run "$d"
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'not a complete Buildroot tree' \
&& [ -f "$(tree "$d")/output/marker" ] && [ "$(fetches "$d")" -eq 0 ]; then
ok "half-present tree: refused and left untouched"
else
bad "half-present tree: refused and left untouched (rc=$RC, out=$OUT)"
fi
# G. Fetch fails (network down, sha256 mismatch): nonzero, no tree.
d="$(setup fetch-fails FAIL)"; run "$d"
if [ "$RC" -ne 0 ] && [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
ok "failed fetch: nonzero, no tree"
else
bad "failed fetch: nonzero, no tree (rc=$RC, out=$OUT)"
fi
if [ "$FAIL" -eq 0 ]; then echo "ALL UNPACK-BUILDROOT TESTS PASSED"; else echo "UNPACK-BUILDROOT TESTS FAILED"; fi
exit "$FAIL"