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
32 changes: 31 additions & 1 deletion tests/extract-vendor-firmware
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# reused output directory keeps no firmware or sensor registry file from
# an earlier run (another device's, or one the new image doesn't have),
# and leaves the rest of the directory alone; a husky run drops an earlier
# registry; a successful run's checksum list names exactly the mapped
# registry; a panther run adds the video codec's firmware and reports its
# version, and refuses one that doesn't start with an ARM vector table; a successful run's checksum list names exactly the mapped
# 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
Expand Down Expand Up @@ -119,10 +120,20 @@ make_vendor() {
echo '3,1,3' > "$v/firmware/fast_switch4.txt"
echo "{\"accel\": \"$g\"}" > "$v/etc/sensors/registry/fictional_accel.json"
echo "apex $g" > "$v/apex/com.google.pixel.camera.hal.apex"
mfc_fw "$g" > "$v/firmware/mfc_fw.bin"
}
# A 4 KiB stand-in MFC firmware: eight ARM branches (0xea top bytes), the
# generation padded with spaces, and the version word 0x44250901 last
mfc_fw() {
local i
for i in 1 2 3 4 5 6 7 8; do printf '\001\000\000\352'; done
printf '%-4060s' "$1"
printf '\001\011\045\104'
}
make_vendor "$t/v1" cheetah gen1
make_vendor "$t/v2" cheetah gen2
make_vendor "$t/husky" husky gen3
make_vendor "$t/panther" panther gen4

FW=usr/lib/firmware/updates
REG=usr/share/omamobile/sensors/registry
Expand Down Expand Up @@ -217,7 +228,26 @@ else
cat "$t/log"; fail "husky: a run over a cheetah generation succeeds"
fi

o=$t/panther-out n=$failed
rm -rf "$o"
if run "$t/panther" "$t/ext4.img" -d panther -o "$o"; then
[[ $(listed "$o") == "$( (printf '%s\n' "$CHEETAH_FILES" | sed 's/cheetah/panther/g'; echo s5p-mfc-v15.fw) | LC_ALL=C sort)" ]] ||
fail "panther: the checksum list names cheetah's files under panther's names, and the MFC firmware"
cmp -s "$t/panther/firmware/mfc_fw.bin" "$o/$FW/s5p-mfc-v15.fw" || fail "panther: s5p-mfc-v15.fw is mfc_fw.bin"
grep -qF 'Video codec firmware: s5p-mfc-v15.fw (version 0x44250901)' "$t/log" ||
fail "panther: the MFC firmware's version is reported"
pass_since "$n" "panther: a run stages the MFC firmware as s5p-mfc-v15.fw"
else
cat "$t/log"; fail "panther: a run succeeds"
fi

# --- Failed runs leave the previous generation ----------------------------------
rm -rf "$t/panther-badmfc"; cp -r "$t/panther" "$t/panther-badmfc"
printf 'not a firmware %4096s' x > "$t/panther-badmfc/firmware/mfc_fw.bin"
refuses "panther: an MFC firmware without an ARM vector table" "mfc_fw.bin does not start with an ARM vector table" \
"$t/panther-badmfc" "$t/ext4.img" -d panther
rm -rf "$t/panther-nomfc"; cp -r "$t/panther" "$t/panther-nomfc"; rm "$t/panther-nomfc/firmware/mfc_fw.bin"
refuses "panther: a missing MFC firmware" "/vendor/firmware/mfc_fw.bin is missing" "$t/panther-nomfc" "$t/ext4.img" -d panther
# husky's BCM.hcd names the module and board, not the chip: another phone's
# patch (here the 7 Pro's) is refused
rm -rf "$t/husky-otherbt"; cp -r "$t/husky" "$t/husky-otherbt"; echo "BCM4389C1 fictional" > "$t/husky-otherbt/firmware/brcm/BCM.hcd"
Expand Down
28 changes: 27 additions & 1 deletion tools/extract-vendor-firmware
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
# missing tuning fails to load instead of falling back to the other speaker's
# (or to linux-firmware's generic cirrus/cs35l41-dsp1-spk-prot.bin).
#
# The Pixel 7 (-d panther; <board> is "google,gs201-panther") takes the same
# files as cheetah under its own names, and also the video codec's:
#
# vendor/firmware/mfc_fw.bin -> s5p-mfc-v15.fw (s5p-mfc, the MFC v15.6 decoder)
#
# mfc_fw.bin is the MFC's RISC core firmware, plain and unsigned. It starts
# with that core's vector table (eight ARM branch instructions) and ends with
# its version word, the one the MFC reports in FW_VERSION once it runs
# (0x44250901 in the image this was tested with).
#
# The Pixel 9a (-d tegu; <board> is "google,zumapro-tegu"):
#
# vendor/firmware/fw_bcmdhd.bin -> brcm/brcmfmac4383-pcie.<board>.bin (brcmfmac)
Expand Down Expand Up @@ -189,7 +199,10 @@ case $DEVICE_OPT in
BOARD="google,gs201-panther"
DEVICE="panther"
MAP=("${MAP[@]//google,gs201-cheetah/$BOARD}")
MAP=("${MAP[@]//cheetah/$DEVICE}") ;;
MAP=("${MAP[@]//cheetah/$DEVICE}")
# The video codec (kernel: s5p-mfc's google,gs201-mfc), described for
# panther only so far
MAP+=("firmware/mfc_fw.bin|s5p-mfc-v15.fw") ;;
raven)
# Pixel 6 Pro: Wi-Fi, Bluetooth, the AoC, the speaker amplifiers'
# protection firmware and the AoC's sensor registry (device/raven/WIFI-PLAN.md,
Expand Down Expand Up @@ -497,6 +510,17 @@ if [[ $DEVICE == cheetah || $DEVICE == panther || $DEVICE == tegu || $DEVICE ==
done
fi

# The MFC firmware: a vector table of eight ARM branches (cond AL, opcode
# 0xea in each word's top byte), and its version as the last word
if [[ $DEVICE == panther ]]; then
od -An -tx1 -w32 -N32 "$dest/s5p-mfc-v15.fw" |
awk '{ for (i = 4; i <= 32; i += 4) if ($i != "ea") exit 1 } END { if (NR != 1) exit 1 }' ||
die "mfc_fw.bin does not start with an ARM vector table"
mfc_size=$(stat -c %s "$dest/s5p-mfc-v15.fw")
(( mfc_size >= 4096 && mfc_size % 4 == 0 )) || die "mfc_fw.bin is not a whole number of words"
mfc_ver=$(od -An -tx4 -j $((mfc_size - 4)) -N4 "$dest/s5p-mfc-v15.fw" | tr -d ' ')
fi

ver=$(grep -ao 'Version=[0-9.]* ([^)]*)' "$brcm/$FW_BASE.$BOARD.bin" | head -1)
bt=""
[[ -z $BT_CHIP ]] || bt=$(grep -ao "$BT_CHIP [^[]*" "$brcm/BCM.$BOARD.hcd" | head -1)
Expand All @@ -514,6 +538,8 @@ fi
[[ -z $BT_CHIP ]] || say "Bluetooth patch: ${bt:-unknown version}"
[[ $DEVICE == cheetah || $DEVICE == panther || $DEVICE == tegu || $DEVICE == husky ]] &&
say "Haptics firmware: cs40l26.wmfw ($(stat -c %s "$dest/cs40l26.wmfw") bytes) and its wavetable"
[[ $DEVICE == panther ]] &&
say "Video codec firmware: s5p-mfc-v15.fw (version 0x$mfc_ver)"
[[ $DEVICE == tegu ]] &&
say "AoC firmware: aoc-tegu.bin ($(stat -c %s "$dest/aoc-tegu.bin") bytes)"
[[ $DEVICE == cheetah || $DEVICE == panther || $DEVICE == raven ]] &&
Expand Down