util/chromeos: Update extract_blobs script

- Handle older CrOS firmware which lacks a COREBOOT FMAP region
- Add support for all blobs used in CrOS firmware 2013 to current
- Put extracted blobs in their own directory

Change-Id: Idaa39eca3be68a9327cead9b21c35a6c7a3a8166
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/59266
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Matt DeVillier 2021-11-12 10:23:21 -06:00 committed by Felix Held
parent ef8a1390b2
commit 648a44acbc
1 changed files with 101 additions and 25 deletions

View File

@ -2,40 +2,116 @@
# #
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
set -x if [ ! -f "$1" ]; then
echo "Error: You must provide a valid filename"
exit 1
fi
IMAGE=$1 IMAGE=$1
# create new dir '$IMAGE-blobs' (less file extension)
DIR=$(basename $IMAGE)
DIR="${DIR%.*}-blobs"
mkdir -p $DIR
if [ ! -r "$IMAGE" ]; then if [ -f ./cbfstool ]; then
echo "Can't find image $IMAGE." CBFSTOOL="./cbfstool"
exit 1 else
CBFSTOOL=$(command -v cbfstool)
fi
if [[ "$CBFSTOOL" = "" ]]; then
echo "Error: cbfstool must be in your path or exist locally"
exit 1
fi fi
CBFSTOOL=$(which cbfstool) if [ -f ./ifdtool ]; then
if [ $? != 0 ]; then IFDTOOL="./ifdtool"
echo "Can't find cbfstool." else
exit 1 IFDTOOL=$(which ifdtool)
fi
if [[ "$IFDTOOL" = "" ]]; then
echo "Error: ifdtool must be in your path or exist locally"
exit 1
fi fi
IFDTOOL=$(which ifdtool) # ensure valid coreboot image / get list of main COREBOOT CBFS contents
if [ $? != 0 ]; then REGION=""
echo "Can't find ifdtool." if ! $CBFSTOOL $IMAGE print >$DIR/cbfs.txt 2>/dev/null; then
exit 1 # try using BOOT_STUB region
if ! $CBFSTOOL $IMAGE print -r BOOT_STUB >$DIR/cbfs.txt; then
echo "Error reading CBFS: $IMAGE is not a valid coreboot image"
exit 1
else
REGION="-r BOOT_STUB"
fi
fi fi
$CBFSTOOL $IMAGE print echo ""
echo "Extracting blobs..."
echo ""
if [ $? -ne 0 ]; then # extract flash regions
echo "Not a coreboot image: $IMAGE" if ! $IFDTOOL -x $IMAGE >/dev/null; then
exit 1 echo "Error reading flash descriptor/extracting flash regions"
exit 1
fi fi
# rename to normal convention; drop unused regions
PCI=$($CBFSTOOL $IMAGE print|grep pci|cut -f1 -d\ ) mv flashregion_0_flashdescriptor.bin $DIR/flashdescriptor.bin
MRC=$($CBFSTOOL $IMAGE print|grep mrc.bin|cut -f1 -d\ ) [ -f flashregion_2_intel_me.bin ] && mv flashregion_2_intel_me.bin $DIR/me.bin
$CBFSTOOL $IMAGE extract -n $PCI -f $PCI
$CBFSTOOL $IMAGE extract -n $MRC -f $MRC
$IFDTOOL -x $IMAGE
mv flashregion_0_flashdescriptor.bin flashdescriptor.bin
mv flashregion_2_intel_me.bin me.bin
rm flashregion_*.bin rm flashregion_*.bin
# extract microcode
$CBFSTOOL $IMAGE extract $REGION -n cpu_microcode_blob.bin -f $DIR/cpu_microcode_blob.bin
# extract VGA BIOS
VGA=$(grep pci $DIR/cbfs.txt | cut -f1 -d\ )
if [ "$VGA" != "" ]; then
$CBFSTOOL $IMAGE extract $REGION -n $VGA -f $DIR/vgabios.bin
fi
# extract MRC.bin
MRC=$(grep mrc.bin $DIR/cbfs.txt | cut -f1 -d\ )
if [ "$MRC" != "" ]; then
$CBFSTOOL $IMAGE extract $REGION -n "$MRC" -f "$DIR/$MRC"
fi
# extract refcode
REF=$(grep refcode $DIR/cbfs.txt | cut -f1 -d\ )
if [ "$REF" != "" ]; then
$CBFSTOOL $IMAGE extract $REGION -n fallback/refcode -f "$DIR/refcode.elf" -m x86
fi
# extract FSP blobs
for FSP in $(grep fsp $DIR/cbfs.txt | cut -f1 -d\ ); do
$CBFSTOOL $IMAGE extract $REGION -n $FSP -f $DIR/$FSP
done
# extract audio blobs
for AUD in $(grep -e "-2ch-" -e "-4ch-" $DIR/cbfs.txt | cut -f1 -d\ ); do
$CBFSTOOL $IMAGE extract $REGION -n $AUD -f $DIR/$AUD
done
# extract VBTs
for VBT in $(grep vbt $DIR/cbfs.txt | cut -f1 -d\ ); do
$CBFSTOOL $IMAGE extract $REGION -n $VBT -f $DIR/$VBT
done
# extract IFWI
IFWI=$(cbfstool $IMAGE layout -w | grep IFWI)
if [ "$IFWI" != "" ]; then
$CBFSTOOL $IMAGE read -r IFWI -f $DIR/ifwi.bin
fi
# generate hashes
(
cd $DIR
: >hashes.txt
for FILE in $(ls *.{bin,elf} 2>/dev/null); do
sha256sum $FILE >>hashes.txt
done
)
# a little housekeeping
rm $DIR/cbfs.txt
echo ""
echo "All done"