drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / util / chromeos / extract_blobs.sh
blobca0bdeeee6f1c67f946869842c786936868e308c
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
12 if [[ "$2" = "" ]]; then
13 # create new dir '$IMAGE-blobs' (less file extension)
14 DIR=$(basename $IMAGE)
15 DIR="${DIR%.*}-blobs"
16 else
17 DIR=$2
19 mkdir -p $DIR
21 if [ -f ./cbfstool ]; then
22 CBFSTOOL="./cbfstool"
23 else
24 CBFSTOOL=$(command -v cbfstool)
26 if [[ "$CBFSTOOL" = "" ]]; then
27 echo "Error: cbfstool must be in your path or exist locally"
28 exit 1
31 if [ -f ./ifdtool ]; then
32 IFDTOOL="./ifdtool"
33 else
34 IFDTOOL=$(which ifdtool)
36 if [[ "$IFDTOOL" = "" ]]; then
37 echo "Error: ifdtool must be in your path or exist locally"
38 exit 1
41 # ensure valid coreboot image / get list of CBFS contents
42 # try using RW_MAIN_A region first as it may contain newer
43 # files / files not present in the COREBOOT region
44 if $CBFSTOOL $IMAGE print -r FW_MAIN_A >$DIR/cbfs.txt 2>/dev/null; then
45 REGION="FW_MAIN_A"
46 elif $CBFSTOOL $IMAGE print -r COREBOOT >$DIR/cbfs.txt; then
47 # use COREBOOT region
48 REGION="COREBOOT"
49 elif $CBFSTOOL $IMAGE print -r BOOT_STUB >$DIR/cbfs.txt; then
50 # use BOOT_STUB region
51 REGION="BOOT_STUB"
52 else
53 echo "Error reading CBFS: $IMAGE is not a valid coreboot image"
54 exit 1
57 echo ""
58 echo "Extracting blobs from region $REGION..."
59 echo ""
61 # extract flash regions
62 if ! $IFDTOOL -x $IMAGE >/dev/null; then
63 echo "Error reading flash descriptor/extracting flash regions"
64 exit 1
66 # rename to normal convention; drop unused regions
67 mv flashregion_0_flashdescriptor.bin $DIR/flashdescriptor.bin
68 [ -f flashregion_2_intel_me.bin ] && mv flashregion_2_intel_me.bin $DIR/me.bin
69 rm flashregion_*.bin
71 # extract microcode
72 $CBFSTOOL $IMAGE extract -r $REGION -n cpu_microcode_blob.bin -f $DIR/cpu_microcode_blob.bin
74 # extract VGA BIOS
75 VGA=$(grep pci $DIR/cbfs.txt | cut -f1 -d\ )
76 if [ "$VGA" != "" ]; then
77 $CBFSTOOL $IMAGE extract -r $REGION -n $VGA -f $DIR/vgabios.bin
80 # extract MRC.bin
81 MRC=$(grep mrc.bin $DIR/cbfs.txt | cut -f1 -d\ )
82 if [ "$MRC" != "" ]; then
83 $CBFSTOOL $IMAGE extract -r $REGION -n "$MRC" -f "$DIR/$MRC"
86 # extract refcode
87 REF=$(grep refcode $DIR/cbfs.txt | cut -f1 -d\ )
88 if [ "$REF" != "" ]; then
89 $CBFSTOOL $IMAGE extract -r $REGION -n fallback/refcode -f "$DIR/refcode.elf" -m x86
92 # extract FSP blobs
93 for FSP in $(grep fsp $DIR/cbfs.txt | cut -f1 -d\ ); do
94 $CBFSTOOL $IMAGE extract -r $REGION -n $FSP -f $DIR/$FSP
95 done
97 # extract audio blobs
98 for AUD in $(grep -e "-2ch-" -e "-4ch-" $DIR/cbfs.txt | cut -f1 -d\ ); do
99 $CBFSTOOL $IMAGE extract -r $REGION -n $AUD -f $DIR/$AUD
100 done
102 # extract VBTs
103 for VBT in $(grep vbt $DIR/cbfs.txt | cut -f1 -d\ ); do
104 $CBFSTOOL $IMAGE extract -r $REGION -n $VBT -f $DIR/$VBT
105 done
107 # extract IFWI
108 IFWI=$(cbfstool $IMAGE layout -w | grep IFWI)
109 if [ "$IFWI" != "" ]; then
110 $CBFSTOOL $IMAGE read -r IFWI -f $DIR/ifwi.bin
113 # generate hashes
115 cd $DIR
116 : >hashes.txt
117 for FILE in $(ls *.{bin,elf} 2>/dev/null); do
118 sha256sum $FILE >>hashes.txt
119 done
122 # a little housekeeping
123 rm $DIR/cbfs.txt
125 echo ""
126 echo "All done"