blob: 74b52205eaa716c15db0716c1c1b45216273e660 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Joe Pillow9a4881a2016-02-19 15:18:14 -08002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
Joe Pillow9a4881a2016-02-19 15:18:14 -08004
Matt DeVillier648a44a2021-11-12 10:23:21 -06005if [ ! -f "$1" ]; then
6 echo "Error: You must provide a valid filename"
7 exit 1
8fi
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00009
Joe Pillow9a4881a2016-02-19 15:18:14 -080010IMAGE=$1
Matt DeVillier648a44a2021-11-12 10:23:21 -060011# create new dir '$IMAGE-blobs' (less file extension)
12DIR=$(basename $IMAGE)
13DIR="${DIR%.*}-blobs"
14mkdir -p $DIR
Joe Pillow9a4881a2016-02-19 15:18:14 -080015
Matt DeVillier648a44a2021-11-12 10:23:21 -060016if [ -f ./cbfstool ]; then
17 CBFSTOOL="./cbfstool"
18else
19 CBFSTOOL=$(command -v cbfstool)
20fi
21if [[ "$CBFSTOOL" = "" ]]; then
22 echo "Error: cbfstool must be in your path or exist locally"
23 exit 1
Joe Pillow9a4881a2016-02-19 15:18:14 -080024fi
25
Matt DeVillier648a44a2021-11-12 10:23:21 -060026if [ -f ./ifdtool ]; then
27 IFDTOOL="./ifdtool"
28else
29 IFDTOOL=$(which ifdtool)
30fi
31if [[ "$IFDTOOL" = "" ]]; then
32 echo "Error: ifdtool must be in your path or exist locally"
33 exit 1
Joe Pillow9a4881a2016-02-19 15:18:14 -080034fi
35
Matt DeVillier648a44a2021-11-12 10:23:21 -060036# ensure valid coreboot image / get list of main COREBOOT CBFS contents
37REGION=""
38if ! $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"
45 fi
Joe Pillow9a4881a2016-02-19 15:18:14 -080046fi
47
Matt DeVillier648a44a2021-11-12 10:23:21 -060048echo ""
49echo "Extracting blobs..."
50echo ""
Joe Pillow9a4881a2016-02-19 15:18:14 -080051
Matt DeVillier648a44a2021-11-12 10:23:21 -060052# extract flash regions
53if ! $IFDTOOL -x $IMAGE >/dev/null; then
54 echo "Error reading flash descriptor/extracting flash regions"
55 exit 1
Joe Pillow9a4881a2016-02-19 15:18:14 -080056fi
Matt DeVillier648a44a2021-11-12 10:23:21 -060057# rename to normal convention; drop unused regions
58mv flashregion_0_flashdescriptor.bin $DIR/flashdescriptor.bin
59[ -f flashregion_2_intel_me.bin ] && mv flashregion_2_intel_me.bin $DIR/me.bin
Joe Pillow9a4881a2016-02-19 15:18:14 -080060rm flashregion_*.bin
Matt DeVillier648a44a2021-11-12 10:23:21 -060061
62# extract microcode
63$CBFSTOOL $IMAGE extract $REGION -n cpu_microcode_blob.bin -f $DIR/cpu_microcode_blob.bin
64
65# extract VGA BIOS
66VGA=$(grep pci $DIR/cbfs.txt | cut -f1 -d\ )
67if [ "$VGA" != "" ]; then
68 $CBFSTOOL $IMAGE extract $REGION -n $VGA -f $DIR/vgabios.bin
69fi
70
71# extract MRC.bin
72MRC=$(grep mrc.bin $DIR/cbfs.txt | cut -f1 -d\ )
73if [ "$MRC" != "" ]; then
74 $CBFSTOOL $IMAGE extract $REGION -n "$MRC" -f "$DIR/$MRC"
75fi
76
77# extract refcode
78REF=$(grep refcode $DIR/cbfs.txt | cut -f1 -d\ )
79if [ "$REF" != "" ]; then
80 $CBFSTOOL $IMAGE extract $REGION -n fallback/refcode -f "$DIR/refcode.elf" -m x86
81fi
82
83# extract FSP blobs
84for FSP in $(grep fsp $DIR/cbfs.txt | cut -f1 -d\ ); do
85 $CBFSTOOL $IMAGE extract $REGION -n $FSP -f $DIR/$FSP
86done
87
88# extract audio blobs
89for AUD in $(grep -e "-2ch-" -e "-4ch-" $DIR/cbfs.txt | cut -f1 -d\ ); do
90 $CBFSTOOL $IMAGE extract $REGION -n $AUD -f $DIR/$AUD
91done
92
93# extract VBTs
94for VBT in $(grep vbt $DIR/cbfs.txt | cut -f1 -d\ ); do
95 $CBFSTOOL $IMAGE extract $REGION -n $VBT -f $DIR/$VBT
96done
97
98# extract IFWI
99IFWI=$(cbfstool $IMAGE layout -w | grep IFWI)
100if [ "$IFWI" != "" ]; then
101 $CBFSTOOL $IMAGE read -r IFWI -f $DIR/ifwi.bin
102fi
103
104# generate hashes
105(
106 cd $DIR
107 : >hashes.txt
108 for FILE in $(ls *.{bin,elf} 2>/dev/null); do
109 sha256sum $FILE >>hashes.txt
110 done
111)
112
113# a little housekeeping
114rm $DIR/cbfs.txt
115
116echo ""
117echo "All done"