Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions tests/extract-vendor-firmware
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
# files; a failed run (a missing file or registry, debugfs reporting a
# short write, also under a file size limit, a failed sanity check, a
# missing camera APEX) leaves the previous outputs and the -c file byte
# for byte, so an older file can't pass for a missing one; a -c that is a
# directory or inside the outputs is refused; an -o that resolves to / is
# refused before anything is written; and a move that fails while
# publishing puts the previous outputs back. With mkfs.ext4
# and debugfs on the host, the same on a real ext4 image whose registry
# belongs to root, work and output paths with a space and a double quote
# in them, and a copy that a file size limit cuts short. EVF=path
# for byte, so an older file can't pass for a missing one; an image whose
# build.prop is missing or empty is refused, as its device can't be
# checked, and staged with -f; a -c that is a directory or inside the
# outputs is refused; an -o that resolves to / is refused before anything
# is written; and a move that fails while publishing puts the previous
# outputs back. With mkfs.ext4 and debugfs on the host, the same on a real
# ext4 image whose registry belongs to root, work and output paths with a
# space and a double quote in them, a copy that a file size limit cuts
# short, and an image without build.prop. EVF=path
# runs another copy of the tool (a negative control), so every check runs
# and the failures are counted rather than stopping at the first.
set -euo pipefail
Expand Down Expand Up @@ -233,6 +235,20 @@ elif [[ $(snap "$o") != "$before" ]]; then
fi
pass_since "$n" "a registry short write under a file size limit: refused, the previous outputs untouched"

# Without a readable build.prop the device check can't run: refused, unless -f
rm -rf "$t/v2-noprop"; cp -r "$t/v2" "$t/v2-noprop"; rm "$t/v2-noprop/build.prop"
rm -rf "$t/v2-emptyprop"; cp -r "$t/v2" "$t/v2-emptyprop"; : > "$t/v2-emptyprop/build.prop"
refuses "no build.prop (ext4)" "vendor.img has no build.prop" "$t/v2-noprop" "$t/ext4.img"
refuses "no build.prop (EROFS)" "vendor.img has no build.prop" "$t/v2-noprop" "$t/erofs.img"
refuses "an empty build.prop" "vendor.img has no build.prop" "$t/v2-emptyprop" "$t/ext4.img"
o=$t/noprop-forced
seed "$o"
if run "$t/v2-noprop" "$t/ext4.img" -f -o "$o" && [[ $(listed "$o") == "$CHEETAH_FILES" ]]; then
pass "no build.prop with -f: staged"
else
cat "$t/log"; fail "no build.prop with -f: staged"
fi

rm -rf "$t/v2-same"; cp -r "$t/v2" "$t/v2-same"
cp "$t/v2-same/firmware/cs35l41-dsp1-spk-prot.bin" "$t/v2-same/firmware/R-cs35l41-dsp1-spk-prot.bin"
refuses "a sanity check failing after every copy" "the top and bottom speaker tunings are the same file" "$t/v2-same" "$t/ext4.img"
Expand Down Expand Up @@ -326,6 +342,7 @@ rm -rf "$t/v2-big"; cp -r "$t/v2" "$t/v2-big"; head -c 9216 /dev/zero | tr '\0'
if realdfs=$(command -v debugfs) && mkfs.ext4 -q -F -d "$t/v2" "$t/real.img" 8M >/dev/null 2>&1 &&
mkfs.ext4 -q -F -d "$t/v2-missing" "$t/real-missing.img" 8M >/dev/null 2>&1 &&
mkfs.ext4 -q -F -d "$t/v2-big" "$t/real-big.img" 8M >/dev/null 2>&1 &&
mkfs.ext4 -q -F -d "$t/v2-noprop" "$t/real-noprop.img" 8M >/dev/null 2>&1 &&
debugfs -w -R "sif /etc/sensors/registry uid 0" "$t/real.img" >/dev/null 2>&1 &&
debugfs -w -R "sif /etc/sensors/registry/fictional_accel.json uid 0" "$t/real.img" >/dev/null 2>&1; then
mkdir -p "$t/limited"
Expand Down Expand Up @@ -358,6 +375,14 @@ if realdfs=$(command -v debugfs) && mkfs.ext4 -q -F -d "$t/v2" "$t/real.img" 8M
pass "real ext4: a missing file with an older copy in OUT is refused, the previous outputs untouched"
fi
before=$(snap "$o")
if "$EVF" -w "$t/work" -o "$o" "$t/real-noprop.img" > "$t/log" 2>&1; then
fail "real ext4: an image without build.prop is refused"
elif ! grep -qF "vendor.img has no build.prop" "$t/log" || [[ $(snap "$o") != "$before" ]]; then
cat "$t/log"; fail "real ext4: an image without build.prop is refused, the previous outputs untouched"
else
pass "real ext4: an image without build.prop is refused, the previous outputs untouched"
fi
before=$(snap "$o")
if PATH=$t/limited:$PATH "$EVF" -w "$t/work" -o "$o" "$t/real-big.img" > "$t/log" 2>&1; then
fail "real ext4: a copy cut short by debugfs is refused"
elif ! grep -qF "/vendor/firmware/aoc.bin is missing" "$t/log" || [[ $(snap "$o") != "$before" ]]; then
Expand Down
4 changes: 3 additions & 1 deletion tools/extract-vendor-firmware
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Usage: extract-vendor-firmware [-o OUTDIR] [-w WORKDIR] [-f] SOURCE
-w DIR scratch directory for the ~1 GB vendor.img (default: a temp dir in \$TMPDIR)
-d DEV cheetah (default), panther, raven, tegu or husky
-s SKU husky: the hardware SKU (androidboot.hardware.sku), which picks the NVRAM
-f skip the android-info.txt board=$DEVICE check
-f skip the device checks (android-info.txt board=$DEVICE, the vendor build.prop)
-c FILE also copy the camera HAL APEX (/vendor/apex/com.google.pixel.camera.hal.apex)
to FILE, for tools/extract-camera-data --apex (tools/phone-provision uses it)

Expand Down Expand Up @@ -394,6 +394,8 @@ if get_file build.prop "$WORK/build.prop"; then
[[ "$dev" == "$DEVICE" || -n "$FORCE" ]] ||
die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override"
say "Vendor partition: $(sed -n 's/^ro.vendor.build.fingerprint=//p' "$WORK/build.prop" | head -1)"
else
[[ -n "$FORCE" ]] || die "vendor.img has no build.prop; use -f to override"
fi

# The new generation: everything below is written into $new, which starts
Expand Down