Gate the OS image payloads against the formats a board can actually boot
The SDK refuses a bad payload before writing it; this is the same rule on the producing side, so a release cannot ship an image that would not boot or would not fit the partition it targets. Checks every payload artefact it can find: magic must match the claimed format (FDT d00dfeed, legacy uImage 27051956, raw ARM zImage 016f2818 at 0x24) and the size must fit the partition. Absent artefacts pass with a note, so the gate can be wired before the first image exists. Proven both ways: it accepts the four payload files that actually installed OurOS, and rejects a zImage renamed to the ramdisk slot on size.
This commit is contained in:
@@ -26,6 +26,8 @@ jobs:
|
||||
apt-get install -y -qq --no-install-recommends openssh-client
|
||||
- name: Install Rust quality tools
|
||||
run: rustup component add rustfmt clippy
|
||||
- name: Image safety gate
|
||||
run: sh ci/check-image-safety.sh
|
||||
- name: Formatting
|
||||
run: cargo fmt --check
|
||||
- name: Last-attempt badge checks
|
||||
|
||||
@@ -15,6 +15,8 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Image safety gate
|
||||
run: sh ci/check-image-safety.sh
|
||||
- name: Build release candidate
|
||||
run: cargo build --release --offline --locked
|
||||
- name: Select candidate version
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
#!/bin/sh
|
||||
# Refuse to publish an OS image whose payload would not fit, or would not boot,
|
||||
# on the board it claims to target.
|
||||
#
|
||||
# The SDK's planner refuses a bad payload before it is ever written; this is the
|
||||
# other half of the same rule, applied to the artefacts the OS repo produces. A
|
||||
# wrongly-formatted image is not a firmware bug a board survives: the vendor SPL
|
||||
# only parses a legacy uImage, stock U-Boot only parses a legacy uImage, and a
|
||||
# raw zImage in the wrong slot boots nothing.
|
||||
#
|
||||
# Checks, per payload file found:
|
||||
# * magic matches the format its name claims
|
||||
# * size fits the target partition
|
||||
# A file that is present but unreadable, or that claims a format it does not
|
||||
# have, fails the gate. When no payload artefacts exist yet the gate says so and
|
||||
# passes, so it can be wired into CI before the first image is built.
|
||||
set -eu
|
||||
|
||||
fail=0
|
||||
note() { printf ' %s\n' "$*"; }
|
||||
bad() { printf ' FAIL %s\n' "$*"; fail=1; }
|
||||
|
||||
# name-glob|format|max-bytes
|
||||
RULES='
|
||||
kernel-mtd8.zImage|zimage|20971520
|
||||
zImage|zimage|20971520
|
||||
Image|zimage|16777216
|
||||
dtb-mtd6.dtb|fdt|131072
|
||||
am335x-alkane.dtb|fdt|131072
|
||||
meson-axg-alkane.dtb|fdt|131072
|
||||
ramdisk-mtd7.uimg|uimage|5242880
|
||||
uramdisk.image.gz|uimage|8388608
|
||||
uboot-mtd4.img|uimage|1835008
|
||||
'
|
||||
|
||||
check_file() {
|
||||
file=$1
|
||||
name=$(basename "$file")
|
||||
size=$(wc -c < "$file")
|
||||
rule=$(printf '%s\n' "$RULES" | awk -F'|' -v n="$name" '$1 == n { print; exit }')
|
||||
if [ -z "$rule" ]; then
|
||||
return 0
|
||||
fi
|
||||
format=$(printf '%s' "$rule" | cut -d'|' -f2)
|
||||
limit=$(printf '%s' "$rule" | cut -d'|' -f3)
|
||||
if [ "$size" -gt "$limit" ]; then
|
||||
bad "$name is $size bytes, larger than its $limit-byte partition"
|
||||
return 0
|
||||
fi
|
||||
magic=$(od -An -tx1 -N4 "$file" | tr -d ' \n')
|
||||
case "$format" in
|
||||
fdt)
|
||||
[ "$magic" = "d00dfeed" ] || bad "$name does not start with the FDT magic (got $magic)"
|
||||
;;
|
||||
uimage)
|
||||
[ "$magic" = "27051956" ] || bad "$name is not a legacy uImage (got $magic)"
|
||||
;;
|
||||
zimage)
|
||||
# ARM zImage: 0x016f2818 at offset 0x24, stored little-endian on disk.
|
||||
z=$(od -An -tx1 -j36 -N4 "$file" | tr -d ' \n')
|
||||
[ "$z" = "18286f01" ] || bad "$name is not a raw ARM zImage (got $z at 0x24)"
|
||||
;;
|
||||
esac
|
||||
note "$name: $format, $size bytes"
|
||||
}
|
||||
|
||||
echo "image-safety: scanning for payload artefacts"
|
||||
|
||||
found=0
|
||||
for dir in "${1:-.}" dist build/out target/payload; do
|
||||
[ -d "$dir" ] || continue
|
||||
for file in $(find "$dir" -maxdepth 3 -type f \
|
||||
\( -name 'kernel-mtd8.zImage' -o -name 'zImage' -o -name 'Image' \
|
||||
-o -name 'dtb-mtd6.dtb' -o -name 'am335x-alkane.dtb' \
|
||||
-o -name 'meson-axg-alkane.dtb' -o -name 'ramdisk-mtd7.uimg' \
|
||||
-o -name 'uramdisk.image.gz' -o -name 'uboot-mtd4.img' \) 2>/dev/null); do
|
||||
found=$((found + 1))
|
||||
check_file "$file"
|
||||
done
|
||||
done
|
||||
|
||||
if [ "$found" -eq 0 ]; then
|
||||
note "no payload artefacts present in this checkout"
|
||||
else
|
||||
note "$found payload file(s) checked"
|
||||
fi
|
||||
|
||||
if [ "$fail" -ne 0 ]; then
|
||||
echo "image-safety: FAILED - do not publish this image" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "image-safety: OK"
|
||||
Reference in New Issue
Block a user