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