blob: d648d090b2cc05e7e12faa2e00aff87cc18b20f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!/usr/bin/env sh
# script to automate extracting blobs from an existing vendor bios
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
# SPDX-License-Identifier: GPL-3.0-only
sname=""
board=""
vendor_rom=""
cbdir="coreboot/default"
cbcfgsdir="resources/coreboot"
ifdtool="${cbdir}/util/ifdtool/ifdtool"
boarddir=""
main()
{
sname=${0}
if [ $# -lt 2 ]; then
fail "Missing arguments (less than two)."
fi
board="${1}"
vendor_rom="${2}"
boarddir="${cbcfgsdir}/${board}"
check_board
build_dependencies
extract_blobs
}
check_board()
{
if [ ! -f "${vendor_rom}" ] ; then
fail "file does not exist: ${vendor_rom}"
elif [ ! -d "${boarddir}" ]; then
fail "build/roms ${board}: target not defined"
elif [ ! -f "${boarddir}/board.cfg" ]; then
fail "build/roms ${board}: missing board.cfg"
fi
}
build_dependencies()
{
if [ ! -d me_cleaner ]; then
printf "downloading me_cleaner\n"
./download me_cleaner || fail 'could not download me_cleaner'
else
printf "me_cleaner already downloaded. Skipping.\n"
printf "run ./download me_cleaner to manually overwrite\n"
fi
if [ ! -d ${cbdir} ]; then
printf "downloading coreboot\n"
./download coreboot default \
|| fail "could not download coreboot"
else
printf "coreboot already downloaded. Skipping.\n"
printf "run ./download coreboot to manually overwrite\n"
fi
if ! [ -f ${ifdtool} ]; then
printf "building ifdtool from coreboot\n"
make -C "${ifdtool%/ifdtool}" \
|| fail "could not build ifdtool"
fi
}
extract_blobs()
{
# TODO: split up this function, it's a mess
printf "extracting blobs for %s from %s\n" ${board} ${vendor_rom}
set -- "${boarddir}/config/"*
. ${1} 2>/dev/null
. "${boarddir}/board.cfg"
if [ "$CONFIG_HAVE_MRC" = "y" ]; then
printf 'haswell board detected, downloading mrc\n'
./download mrc || fail "could not download mrc"
fi
_me_destination=${CONFIG_ME_BIN_PATH#../../}
_gbe_destination=${CONFIG_GBE_BIN_PATH#../../}
_ifd_destination=${CONFIG_IFD_BIN_PATH#../../}
printf "extracting clean ime and modified ifd\n"
./me_cleaner/me_cleaner.py -D ${_ifd_destination} \
-M ${_me_destination} ${vendor_rom} -t -r -S || \
./resources/blobs/me7_update_parser.py
-O ${_me_destination} ${vendor_rom} \
|| fail 'me_cleaner failed to extract blobs from rom'
printf "extracting gigabit ethernet firmware"
./${ifdtool} -x ${vendor_rom}
mv flashregion*gbe.bin ${_gbe_destination} \
|| fail 'could not extract gbe'
# Cleans up other files extracted with ifdtool
rm flashregion*.bin 2> /dev/null
if [ -f ${_ifd_destination} ]; then
printf "gbe, ifd, and me extracted to ${_me_destination%/*}\n"
else
printf "WARNING: Intel firmware descriptor could not "
printf "be extracted with modified me\n"
fi
}
fail()
{
print_help
printf "\n%s: ERROR: %s\n" ${sname} $@
exit 1
}
print_help()
{
printf "Usage: ./blobutil extract {boardname} {path/to/vendor_rom}\n"
printf "Example: ./blobutil extract x230 12mb_flash.bin\n"
printf "\nYou need to specify exactly 2 arguments\n"
}
main $@
|