2022-11-14 00:51:12 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# script to automate extracting blobs from an existing vendor bios
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
|
|
board="${1}"
|
|
|
|
vendor_rom="${2}"
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2022-11-21 03:14:22 +00:00
|
|
|
Fail(){
|
|
|
|
printf "\nERROR: $@\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
Build_deps(){
|
|
|
|
if [ ! -d me_cleaner ]; then
|
|
|
|
printf "downloading me_cleaner\n"
|
2022-11-21 03:14:22 +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
|
|
|
|
|
|
|
|
if [ ! -d coreboot/default ]; then
|
|
|
|
printf "downloading coreboot\n"
|
2022-11-21 03:14:22 +00:00
|
|
|
./download coreboot default || 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
|
|
|
|
|
2022-11-21 03:14:22 +00:00
|
|
|
if ! [ -f coreboot/default/util/ifdtool/ifdtool ]; then
|
|
|
|
printf "building ifdtool from coreboot\n"
|
|
|
|
make -C coreboot/default/util/ifdtool || Fail 'could not build ifdtool'
|
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Extract_blobs(){
|
|
|
|
# TODO: find a better way to know which coreboot config to source
|
|
|
|
set -- "resources/coreboot/${board}/config/*"
|
|
|
|
. ${1} 2>/dev/null
|
|
|
|
. "resources/coreboot/${board}/board.cfg"
|
|
|
|
|
|
|
|
if [ "$CONFIG_HAVE_MRC" = "y" ]; then
|
|
|
|
printf 'haswell board detected, downloading mrc\n'
|
2022-11-21 03:14:22 +00:00
|
|
|
./download mrc || Fail 'could not download mrc, check network connection'
|
2022-11-14 00:51:12 +00:00
|
|
|
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"
|
2022-11-21 03:14:22 +00:00
|
|
|
./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'
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
printf "extracting gigabit ethernet firmware"
|
|
|
|
./coreboot/default/util/ifdtool/ifdtool -x ${vendor_rom}
|
2022-11-21 03:14:22 +00:00
|
|
|
mv flashregion*gbe.bin ${_gbe_destination} || Fail 'could not extract gbe'
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
# Cleans up other files extracted with ifdtool
|
|
|
|
rm flashregion*.bin 2> /dev/null
|
2022-11-21 03:14:22 +00:00
|
|
|
|
|
|
|
if [ -f ${_ifd_destination} ]; then
|
|
|
|
printf "gbe, ifd, and me extracted to ${_me_destination%/*}\n"
|
|
|
|
else
|
|
|
|
printf "WARNING: Intel firmware descriptor could not be extracted with modified me\n"
|
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -f "${vendor_rom}" ] ; then
|
|
|
|
Print_help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "resources/coreboot/${board}" ]; then
|
|
|
|
Print_help
|
|
|
|
printf "build/roms: Target %s does not exist in the %s build system. Skipping build.\n" "${projectname}" "${board}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "resources/coreboot/${board}/board.cfg" ]; then
|
|
|
|
Print_help
|
|
|
|
printf "build/roms: Target %s does not have a board.cfg. Skipping build.\n" "${board}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "extracting blobs for ${board} from ${vendor_rom}\n"
|
|
|
|
Build_deps
|
|
|
|
Extract_blobs
|