2022-12-28 18:29:18 +00:00
|
|
|
#!/usr/bin/env sh
|
2022-11-14 00:51:12 +00:00
|
|
|
# script to automate extracting blobs from an existing vendor bios
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
2023-05-14 08:09:14 +00:00
|
|
|
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
|
2022-11-14 00:51:12 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2023-05-14 08:19:44 +00:00
|
|
|
sname=""
|
|
|
|
board=""
|
|
|
|
vendor_rom=""
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
cbdir="coreboot/default"
|
|
|
|
cbcfgsdir="resources/coreboot"
|
|
|
|
ifdtool="${cbdir}/util/ifdtool/ifdtool"
|
2023-05-14 08:57:34 +00:00
|
|
|
mecleaner="me_cleaner/me_cleaner.py"
|
|
|
|
me7updateparser="resources/blobs/me7_update_parser.py"
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
boarddir=""
|
|
|
|
|
2023-05-14 08:50:48 +00:00
|
|
|
CONFIG_HAVE_MRC=""
|
|
|
|
CONFIG_ME_BIN_PATH=""
|
|
|
|
CONFIG_GBE_BIN_PATH=""
|
|
|
|
CONFIG_IFD_BIN_PATH=""
|
|
|
|
|
|
|
|
_me_destination=""
|
|
|
|
_gbe_destination=""
|
|
|
|
_ifd_destination=""
|
|
|
|
|
2023-05-14 08:19:44 +00:00
|
|
|
main()
|
|
|
|
{
|
|
|
|
sname=${0}
|
|
|
|
if [ $# -lt 2 ]; then
|
2023-05-14 08:39:25 +00:00
|
|
|
fail "Missing arguments (less than two)."
|
2023-05-14 08:19:44 +00:00
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-14 08:19:44 +00:00
|
|
|
board="${1}"
|
|
|
|
vendor_rom="${2}"
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
boarddir="${cbcfgsdir}/${board}"
|
|
|
|
|
|
|
|
check_board
|
|
|
|
build_dependencies
|
|
|
|
extract_blobs
|
2022-11-21 03:14:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
check_board()
|
2023-05-14 08:24:31 +00:00
|
|
|
{
|
|
|
|
if [ ! -f "${vendor_rom}" ] ; then
|
2023-05-14 08:39:25 +00:00
|
|
|
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"
|
2023-05-14 08:24:31 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
build_dependencies()
|
|
|
|
{
|
2022-11-14 00:51:12 +00:00
|
|
|
if [ ! -d me_cleaner ]; then
|
|
|
|
printf "downloading me_cleaner\n"
|
2023-05-14 08:39:25 +00:00
|
|
|
./download me_cleaner || fail 'could not download me_cleaner'
|
2022-11-14 00:51:12 +00:00
|
|
|
else
|
|
|
|
printf "me_cleaner already downloaded. Skipping.\n"
|
|
|
|
printf "run ./download me_cleaner to manually overwrite\n"
|
|
|
|
fi
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
if [ ! -d ${cbdir} ]; then
|
2022-11-14 00:51:12 +00:00
|
|
|
printf "downloading coreboot\n"
|
2023-05-14 08:09:14 +00:00
|
|
|
./download coreboot default \
|
2023-05-14 08:39:25 +00:00
|
|
|
|| fail "could not download coreboot"
|
2022-11-14 00:51:12 +00:00
|
|
|
else
|
|
|
|
printf "coreboot already downloaded. Skipping.\n"
|
|
|
|
printf "run ./download coreboot to manually overwrite\n"
|
|
|
|
fi
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
if ! [ -f ${ifdtool} ]; then
|
2022-11-21 03:14:22 +00:00
|
|
|
printf "building ifdtool from coreboot\n"
|
2023-05-14 08:39:25 +00:00
|
|
|
make -C "${ifdtool%/ifdtool}" \
|
|
|
|
|| fail "could not build ifdtool"
|
2022-11-21 03:14:22 +00:00
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
extract_blobs()
|
|
|
|
{
|
2023-05-14 08:19:44 +00:00
|
|
|
printf "extracting blobs for %s from %s\n" ${board} ${vendor_rom}
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
set -- "${boarddir}/config/"*
|
2022-11-14 00:51:12 +00:00
|
|
|
. ${1} 2>/dev/null
|
2023-05-14 08:39:25 +00:00
|
|
|
. "${boarddir}/board.cfg"
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-03-18 15:20:03 +00:00
|
|
|
if [ "$CONFIG_HAVE_MRC" = "y" ]; then
|
|
|
|
printf 'haswell board detected, downloading mrc\n'
|
2023-05-14 08:39:25 +00:00
|
|
|
./download mrc || fail "could not download mrc"
|
2023-03-18 15:20:03 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
_me_destination=${CONFIG_ME_BIN_PATH#../../}
|
|
|
|
_gbe_destination=${CONFIG_GBE_BIN_PATH#../../}
|
|
|
|
_ifd_destination=${CONFIG_IFD_BIN_PATH#../../}
|
|
|
|
|
2023-05-14 08:50:48 +00:00
|
|
|
extract_blob_intel_me
|
|
|
|
extract_blob_intel_gbe_nvm
|
|
|
|
|
|
|
|
# Cleans up other files extracted with ifdtool
|
|
|
|
rm -f flashregion*.bin 2> /dev/null
|
|
|
|
|
|
|
|
if [ -f ${_ifd_destination} ]; then
|
2023-05-14 08:57:34 +00:00
|
|
|
printf "gbe, ifd, and me extracted to %s\n" \
|
|
|
|
${_me_destination%/*}
|
2023-05-14 08:50:48 +00:00
|
|
|
else
|
|
|
|
printf "WARNING: Intel firmware descriptor could not "
|
|
|
|
printf "be extracted with modified me\n"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_blob_intel_me()
|
|
|
|
{
|
2022-11-14 00:51:12 +00:00
|
|
|
printf "extracting clean ime and modified ifd\n"
|
2023-05-14 08:57:34 +00:00
|
|
|
|
|
|
|
${mecleaner} -D ${_ifd_destination} \
|
|
|
|
-M ${_me_destination} ${vendor_rom} -t -r -S \
|
|
|
|
|| ${me7updateparser} \
|
|
|
|
-O ${_me_destination} ${vendor_rom} \
|
|
|
|
|| fail \
|
|
|
|
"me_cleaner failed to extract blobs from rom"
|
2023-05-14 08:50:48 +00:00
|
|
|
}
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-14 08:50:48 +00:00
|
|
|
extract_blob_intel_gbe_nvm()
|
|
|
|
{
|
2022-11-14 00:51:12 +00:00
|
|
|
printf "extracting gigabit ethernet firmware"
|
2023-05-14 08:39:25 +00:00
|
|
|
./${ifdtool} -x ${vendor_rom}
|
2023-05-14 08:09:14 +00:00
|
|
|
mv flashregion*gbe.bin ${_gbe_destination} \
|
2023-05-14 08:39:25 +00:00
|
|
|
|| fail 'could not extract gbe'
|
2022-11-14 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
fail()
|
|
|
|
{
|
|
|
|
print_help
|
|
|
|
|
2023-05-14 08:19:44 +00:00
|
|
|
printf "\n%s: ERROR: %s\n" ${sname} $@
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-14 00:51:12 +00:00
|
|
|
|
2023-05-14 08:39:25 +00:00
|
|
|
print_help()
|
|
|
|
{
|
2023-05-14 08:24:31 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2023-05-14 08:19:44 +00:00
|
|
|
main $@
|