sb/amd/common: Fix some white spaces issues
[coreboot.git] / util / chromeos / extract_blobs.sh
blob74b52205eaa716c15db0716c1c1b45216273e660
1 #!/usr/bin/env bash
3 # SPDX-License-Identifier: GPL-2.0-only
5 if [ ! -f "$1" ]; then
6 echo "Error: You must provide a valid filename"
7 exit 1
8 fi
10 IMAGE=$1
11 # create new dir '$IMAGE-blobs' (less file extension)
12 DIR=$(basename $IMAGE)
13 DIR="${DIR%.*}-blobs"
14 mkdir -p $DIR
16 if [ -f ./cbfstool ]; then
17 CBFSTOOL="./cbfstool"
18 else
19 CBFSTOOL=$(command -v cbfstool)
21 if [[ "$CBFSTOOL" = "" ]]; then
22 echo "Error: cbfstool must be in your path or exist locally"
23 exit 1
26 if [ -f ./ifdtool ]; then
27 IFDTOOL="./ifdtool"
28 else
29 IFDTOOL=$(which ifdtool)
31 if [[ "$IFDTOOL" = "" ]]; then
32 echo "Error: ifdtool must be in your path or exist locally"
33 exit 1
36 # ensure valid coreboot image / get list of main COREBOOT CBFS contents
37 REGION=""
38 if ! $CBFSTOOL $IMAGE print >$DIR/cbfs.txt 2>/dev/null; then
39 # try using BOOT_STUB region
40 if ! $CBFSTOOL $IMAGE print -r BOOT_STUB >$DIR/cbfs.txt; then
41 echo "Error reading CBFS: $IMAGE is not a valid coreboot image"
42 exit 1
43 else
44 REGION="-r BOOT_STUB"
48 echo ""
49 echo "Extracting blobs..."
50 echo ""
52 # extract flash regions
53 if ! $IFDTOOL -x $IMAGE >/dev/null; then
54 echo "Error reading flash descriptor/extracting flash regions"
55 exit 1
57 # rename to normal convention; drop unused regions
58 mv flashregion_0_flashdescriptor.bin $DIR/flashdescriptor.bin
59 [ -f flashregion_2_intel_me.bin ] && mv flashregion_2_intel_me.bin $DIR/me.bin
60 rm flashregion_*.bin
62 # extract microcode
63 $CBFSTOOL $IMAGE extract $REGION -n cpu_microcode_blob.bin -f $DIR/cpu_microcode_blob.bin
65 # extract VGA BIOS
66 VGA=$(grep pci $DIR/cbfs.txt | cut -f1 -d\ )
67 if [ "$VGA" != "" ]; then
68 $CBFSTOOL $IMAGE extract $REGION -n $VGA -f $DIR/vgabios.bin
71 # extract MRC.bin
72 MRC=$(grep mrc.bin $DIR/cbfs.txt | cut -f1 -d\ )
73 if [ "$MRC" != "" ]; then
74 $CBFSTOOL $IMAGE extract $REGION -n "$MRC" -f "$DIR/$MRC"
77 # extract refcode
78 REF=$(grep refcode $DIR/cbfs.txt | cut -f1 -d\ )
79 if [ "$REF" != "" ]; then
80 $CBFSTOOL $IMAGE extract $REGION -n fallback/refcode -f "$DIR/refcode.elf" -m x86
83 # extract FSP blobs
84 for FSP in $(grep fsp $DIR/cbfs.txt | cut -f1 -d\ ); do
85 $CBFSTOOL $IMAGE extract $REGION -n $FSP -f $DIR/$FSP
86 done
88 # extract audio blobs
89 for AUD in $(grep -e "-2ch-" -e "-4ch-" $DIR/cbfs.txt | cut -f1 -d\ ); do
90 $CBFSTOOL $IMAGE extract $REGION -n $AUD -f $DIR/$AUD
91 done
93 # extract VBTs
94 for VBT in $(grep vbt $DIR/cbfs.txt | cut -f1 -d\ ); do
95 $CBFSTOOL $IMAGE extract $REGION -n $VBT -f $DIR/$VBT
96 done
98 # extract IFWI
99 IFWI=$(cbfstool $IMAGE layout -w | grep IFWI)
100 if [ "$IFWI" != "" ]; then
101 $CBFSTOOL $IMAGE read -r IFWI -f $DIR/ifwi.bin
104 # generate hashes
106 cd $DIR
107 : >hashes.txt
108 for FILE in $(ls *.{bin,elf} 2>/dev/null); do
109 sha256sum $FILE >>hashes.txt
110 done
113 # a little housekeeping
114 rm $DIR/cbfs.txt
116 echo ""
117 echo "All done"