Files
bfe-core1106-sdk/build/unpack-buildroot.sh
T
NoahandClaude Opus 5.5 67da1141a0
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 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:10:53 -06:00

82 lines
3.7 KiB
Bash
Executable File

#!/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"