#!/usr/bin/env sh # script to automate extracting blobs from an existing vendor bios # SPDX-FileCopyrightText: 2022 Caleb La Grange # SPDX-FileCopyrightText: 2023 Leah Rowe # SPDX-License-Identifier: GPL-3.0-only . "include/err.sh" sname="" board="" vendor_rom="" cbdir="coreboot/default" cbcfgsdir="resources/coreboot" ifdtool="${cbdir}/util/ifdtool/ifdtool" mecleaner="me_cleaner/me_cleaner.py" me7updateparser="resources/blobs/me7_update_parser.py" boarddir="" CONFIG_HAVE_MRC="" CONFIG_ME_BIN_PATH="" CONFIG_GBE_BIN_PATH="" CONFIG_IFD_BIN_PATH="" _me_destination="" _gbe_destination="" _ifd_destination="" main() { sname=${0} [ $# -lt 2 ] && err "Missing arguments (fewer than two)." board="${1}" vendor_rom="${2}" boarddir="${cbcfgsdir}/${board}" check_board build_dependencies extract_blobs } check_board() { [ -f "${vendor_rom}" ] || \ err "file does not exist: ${vendor_rom}" [ -d "${boarddir}" ] || \ err "build/roms ${board}: target not defined" [ -f "${boarddir}/target.cfg" ] || \ err "build/roms ${board}: missing target.cfg" } build_dependencies() { [ -d me_cleaner ] || \ ./fetch me_cleaner || err "can't fetch me_cleaner" [ -d ${cbdir} ] || \ ./fetch_trees coreboot default || err "can't fetch coreboot" [ -f ${ifdtool} ] || \ make -C "${ifdtool%/ifdtool}" || err "can't build ifdtool" } extract_blobs() { printf "extracting blobs for %s from %s\n" ${board} ${vendor_rom} set -- "${boarddir}/config/"* . ${1} 2>/dev/null . "${boarddir}/target.cfg" [ "$CONFIG_HAVE_MRC" != "y" ] || \ ./update blobs mrc || err "could not download mrc" _me_destination=${CONFIG_ME_BIN_PATH#../../} _gbe_destination=${CONFIG_GBE_BIN_PATH#../../} _ifd_destination=${CONFIG_IFD_BIN_PATH#../../} extract_blob_intel_me extract_blob_intel_gbe_nvm # Cleans up other files extracted with ifdtool rm -f flashregion*.bin 2> /dev/null [ -f ${_ifd_destination} ] || err "Could not extract IFD" printf "gbe, ifd, and me extracted to %s\n" \ ${_me_destination%/*} } extract_blob_intel_me() { printf "extracting clean ime and modified ifd\n" ${mecleaner} -D ${_ifd_destination} \ -M ${_me_destination} ${vendor_rom} -t -r -S || \ ${me7updateparser} \ -O ${_me_destination} ${vendor_rom} || \ err "me_cleaner failed to extract blobs from rom" } extract_blob_intel_gbe_nvm() { printf "extracting gigabit ethernet firmware" ./${ifdtool} -x ${vendor_rom} mv flashregion*gbe.bin ${_gbe_destination} || \ err 'could not extract gbe' } print_help() { printf "Usage: ./update blobs extract {boardname} {path/to/vendor_rom}\n" printf "Example: ./update blobs extract x230 12mb_flash.bin\n" printf "\nYou need to specify exactly 2 arguments\n" } main $@