Fix mkimage -B probe defeated by pipefail

The probe piped the candidate binary into grep to look for -B support.
mkimage with no arguments prints usage and exits non-zero, and this script
runs under `set -euo pipefail`, so the pipeline reported failure even when
grep matched. Every candidate was rejected and the script failed closed with
"no mkimage on PATH supports -B" while a capable mkimage 2025.01 sat first
on PATH, making it impossible to build a boot.img at all.

Neutralise the probed command's exit status before the pipe. Sentinel
comments now bracket the probe so the new regression test extracts and
exercises the shipping code rather than a copy of it.

Closes #17

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2D2KtdgwbhbF6Mo64eUrn
This commit is contained in:
Noah
2026-09-04 17:06:54 -06:00
co-authored by Claude Opus 5
parent caa12d17ff
commit f0204f2b53
2 changed files with 99 additions and 7 deletions
+29 -7
View File
@@ -159,14 +159,36 @@ ITS
# already 512-aligns, so omitting the flag there is correct rather than a
# fallback. project/build.sh prepends the SDK tool dir to PATH, so that
# binary IS what a build inside the SDK environment resolves.
if mkimage 2>&1 | grep -q -- '-B '; then
_align_flag="-B 0x200"
else
_align_flag=""
echo "== mkimage has no -B (vendor 2017.09); it 512-aligns natively"
# A -B-capable mkimage is REQUIRED, not preferred. The SDK vendors 2017.09,
# which has no -B, and project/build.sh:64 puts it first on PATH -- so the
# wrong one is what a build inside the SDK environment picks up. Measured:
# that binary produces metadata of 1064 bytes here, not a multiple of 512,
# so FIT_ALIGN rounds it up and every payload is read late. It does NOT
# 512-align this .its natively. Rather than silently emit an image that
# fails on a panel, pick the first mkimage on PATH that supports -B and say
# plainly when there is none.
# >>> mkimage-probe (extracted verbatim by tests/mk-bootimg/run-probe-tests.sh)
MKIMAGE=""
_IFS_SAVE="$IFS"; IFS=:
for _d in $PATH; do
_c="$_d/mkimage"
[ -x "$_c" ] || continue
# mkimage with no args prints its usage and exits non-zero; under the
# pipefail set at the top of this file that failure would sink the whole
# pipeline, so the probe would reject every mkimage including good ones.
if { "$_c" 2>&1 || true; } | grep -q -- '-B '; then MKIMAGE="$_c"; break; fi
done
IFS="$_IFS_SAVE"
# <<< mkimage-probe
if [ -z "$MKIMAGE" ]; then
echo "FATAL: no mkimage on PATH supports -B (sub-image alignment)." >&2
echo " The SDK vendors mkimage 2017.09, which does not, and its output" >&2
echo " is not 512-aligned here. Install u-boot-tools (2025.01 works)" >&2
echo " and make sure it precedes the SDK tools on PATH." >&2
exit 1
fi
echo "== FIT (external data, -E -p 0x800 ${_align_flag:-no -B})"
( cd "$WORKDIR" && mkimage -f boot.its -E -p 0x800 ${_align_flag} boot.img >/dev/null )
echo "== FIT (external data, -E -p 0x800 -B 0x200) using $MKIMAGE"
( cd "$WORKDIR" && "$MKIMAGE" -f boot.its -E -p 0x800 -B 0x200 boot.img >/dev/null )
# Assert what U-Boot actually requires, on every build: the failure is silent --
# a misread offset does not fail the build, it fails on a panel, and sometimes