From 67da1141a0f23202f28ce46fa46340d0d6f0430c Mon Sep 17 00:00:00 2001 From: Noah Date: Mon, 28 Sep 2026 11:10:53 -0600 Subject: [PATCH] build: unpack the pinned Buildroot tree into the vendor SDK 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 Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg --- .github/workflows/ci.yml | 8 +- build/fetch-buildroot-tarball.sh | 10 +- build/unpack-buildroot.sh | 81 ++++++++++ build/vendor.manifest | 3 +- docs/ci-cd.md | 2 +- tests/mk-bootimg/run-ci-wiring-tests.sh | 1 + .../run-unpack-buildroot-tests.sh | 138 ++++++++++++++++++ 7 files changed, 233 insertions(+), 10 deletions(-) create mode 100755 build/unpack-buildroot.sh create mode 100755 tests/unpack-buildroot/run-unpack-buildroot-tests.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c68e5f6..0d6efc6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/build/fetch-buildroot-tarball.sh b/build/fetch-buildroot-tarball.sh index 21e37da..92bd1ff 100755 --- a/build/fetch-buildroot-tarball.sh +++ b/build/fetch-buildroot-tarball.sh @@ -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 set -euo pipefail diff --git a/build/unpack-buildroot.sh b/build/unpack-buildroot.sh new file mode 100755 index 0000000..76bd069 --- /dev/null +++ b/build/unpack-buildroot.sh @@ -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-, 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 +# +# The tarball is cached at sysdrv/source/buildroot/buildroot-.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 }" + +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" diff --git a/build/vendor.manifest b/build/vendor.manifest index b0922ed..bae7d57 100644 --- a/build/vendor.manifest +++ b/build/vendor.manifest @@ -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 diff --git a/docs/ci-cd.md b/docs/ci-cd.md index 7eb5b6f..d51a024 100644 --- a/docs/ci-cd.md +++ b/docs/ci-cd.md @@ -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. | diff --git a/tests/mk-bootimg/run-ci-wiring-tests.sh b/tests/mk-bootimg/run-ci-wiring-tests.sh index 0d71f80..489cac1 100755 --- a/tests/mk-bootimg/run-ci-wiring-tests.sh +++ b/tests/mk-bootimg/run-ci-wiring-tests.sh @@ -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" diff --git a/tests/unpack-buildroot/run-unpack-buildroot-tests.sh b/tests/unpack-buildroot/run-unpack-buildroot-tests.sh new file mode 100755 index 0000000..7611fc0 --- /dev/null +++ b/tests/unpack-buildroot/run-unpack-buildroot-tests.sh @@ -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 + 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 -> 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 -> $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"