2022-12-28 18:29:18 +00:00
|
|
|
#!/usr/bin/env sh
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
2022-12-28 18:29:18 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
|
2023-04-23 04:52:16 +00:00
|
|
|
# SPDX-FileCopyrightText: 2023 Leah Rowe <info@minifree.org>
|
2022-11-14 00:51:12 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-11-26 19:45:40 +00:00
|
|
|
Fail(){
|
2022-11-14 00:51:12 +00:00
|
|
|
if [ ! -z ${@+x} ]; then
|
2022-11-26 19:45:40 +00:00
|
|
|
printf "\nERROR: ${@}\n"
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<- EOF
|
|
|
|
USAGE: ./blobutil inject -r [/path/to/rom] -b [boardname] -m [macaddress]
|
|
|
|
Example: ./blobutil inject -r x230_12mb.rom -b x230_12mb
|
|
|
|
|
|
|
|
Adding a macadress to the gbe is optional.
|
|
|
|
If the [-m] parameter is left blank, the gbe will not be touched.
|
|
|
|
|
|
|
|
Type './blobutil inject listboards' to get a list of valid boards
|
|
|
|
EOF
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
Modify_gbe(){
|
2023-04-03 00:06:46 +00:00
|
|
|
rom=${1}
|
2022-11-14 00:51:12 +00:00
|
|
|
printf "changing mac address in gbe to ${new_mac}\n"
|
|
|
|
_gbe_location=${CONFIG_GBE_BIN_PATH#../../}
|
|
|
|
|
2022-11-17 12:07:09 +00:00
|
|
|
if [ ! -f util/nvmutil/nvm ]; then
|
2023-01-10 03:48:46 +00:00
|
|
|
make -C util/nvmutil || Fail 'failed to build nvmutil'
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
_gbe_tmp=$(mktemp -t gbeXXXX.bin)
|
|
|
|
cp ${_gbe_location} ${_gbe_tmp}
|
2022-11-26 19:45:40 +00:00
|
|
|
./util/nvmutil/nvm ${_gbe_tmp} setmac ${new_mac} || Fail 'failed to modify mac address\nmake sure the mac address in the correct format'
|
2022-11-14 00:51:12 +00:00
|
|
|
|
|
|
|
./coreboot/default/util/ifdtool/ifdtool -i GbE:${_gbe_tmp} ${rom} -O ${rom} || exit 1
|
|
|
|
|
|
|
|
rm ${_gbe_tmp}
|
|
|
|
}
|
|
|
|
|
|
|
|
listboards() {
|
|
|
|
for boarddir in resources/coreboot/*; do
|
|
|
|
if [ ! -d "${boarddir}" ]; then continue; fi
|
2023-04-23 04:55:16 +00:00
|
|
|
board="${boarddir##resources/coreboot/}"
|
2022-11-14 00:51:12 +00:00
|
|
|
board="${board%/}"
|
|
|
|
printf '%s\n' "${board##*/}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function tries to determine the board from the filename of the rom.
|
|
|
|
# It will only succeed if the filename is not changed from the build/download
|
|
|
|
Detect_board(){
|
2023-04-03 00:06:46 +00:00
|
|
|
path=${1}
|
|
|
|
filename=$(basename ${path})
|
2022-11-14 00:51:12 +00:00
|
|
|
case ${filename} in
|
|
|
|
grub_*)
|
2022-12-28 18:29:18 +00:00
|
|
|
board=$(echo "${filename}" | cut -d '_' -f2-3)
|
2022-11-14 00:51:12 +00:00
|
|
|
;;
|
build/roms: remove seabios_grubfirst logic
the intended use-case scenario was one in which vga rom initialisation
would be used, on desktop configurations, but without coreboot itself
handling vga rom initialisation, instead leaving that task to seabios
it was assumed that grub, when running on the bare metal with
build option "--with-platform=coreboot" would be able to display
like this, but it is not so when tested
in such setups (add-on gpu with grub payload), it is necessary to
extract the video bios and insert it into the coreboot rom, having
coreboot handle such execution. this is beyond the scope of lbmk,
in context of automated building, because we cannot reliably predict
things such as PCI IDs
do away with this build option entirely, for it does not serve the
intended purpose. it will be necessary to run PC GRUB instead (build
option --with-platform=i386-pc). PC GRUB can still read from CBFS,
and you could provide it as a floppy image file inside CBFS for
SeaBIOS to execute. in this setup, GRUB would function as originally
intended by the seabios_withgrub option; such a configuration is
referred to as "SeaGRUB" by the libreboot project, and experimentation
was done with it in the past, to no avail
it's better to keep things simple, in the libreboot project. simpler
for users, that is
2022-11-22 22:45:18 +00:00
|
|
|
seabios_withgrub_*)
|
2022-12-28 18:29:18 +00:00
|
|
|
board=$(echo "${filename}" | cut -d '_' -f3-4)
|
2022-11-14 00:51:12 +00:00
|
|
|
;;
|
2023-04-03 00:06:46 +00:00
|
|
|
*.tar.xz)
|
|
|
|
_stripped_prefix=${filename#*_}
|
|
|
|
board="${_stripped_prefix%.tar.xz}"
|
|
|
|
;;
|
2022-11-14 00:51:12 +00:00
|
|
|
*)
|
|
|
|
return 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -d "resources/coreboot/${board}/" ]; then
|
|
|
|
printf '%s\n' "${board}"
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
Patch(){
|
2023-04-03 00:06:46 +00:00
|
|
|
rom="${1}"
|
2022-11-14 00:51:12 +00:00
|
|
|
set -- "resources/coreboot/${board}/config/*"
|
|
|
|
. ${1} 2>/dev/null
|
|
|
|
. "resources/coreboot/${board}/board.cfg"
|
|
|
|
|
2023-03-18 15:20:03 +00:00
|
|
|
if [ "$CONFIG_HAVE_MRC" = "y" ]; then
|
|
|
|
printf 'adding mrc\n'
|
2023-03-24 07:10:44 +00:00
|
|
|
./coreboot/default/util/cbfstool/cbfstool ${rom} add -f mrc/haswell/mrc.bin -n mrc.bin -t mrc -b 0x78fe00 || exit 1
|
2023-03-18 15:20:03 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
if [ "${CONFIG_HAVE_ME_BIN}" = "y" ]; then
|
|
|
|
_me_location=${CONFIG_ME_BIN_PATH#../../}
|
|
|
|
printf 'adding intel management engine\n'
|
|
|
|
./coreboot/default/util/ifdtool/ifdtool -i me:${_me_location} ${rom} -O ${rom} || exit 1
|
|
|
|
fi
|
|
|
|
|
2023-04-23 04:52:16 +00:00
|
|
|
if [ "${CONFIG_KBC1126_FIRMWARE}" = "y" ]; then
|
|
|
|
_ec1_location="${CONFIG_KBC1126_FW1#../../}"
|
|
|
|
_ec1_offset="${CONFIG_KBC1126_FW1_OFFSET}"
|
|
|
|
_ec2_location="${CONFIG_KBC1126_FW2#../../}"
|
|
|
|
_ec2_offset="${CONFIG_KBC1126_FW2_OFFSET}"
|
|
|
|
printf "adding hp kbc1126 ec firmware\n"
|
|
|
|
if [ "${_ec1_offset}" = "" ] || [ "${_ec1_offset}" = "" ];
|
|
|
|
then
|
|
|
|
printf "EC offsets not declared for board: %s\n" \
|
|
|
|
"${board}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "${_ec1_location}" = "" ] || [ "${_ec2_location}" = "" ];
|
|
|
|
then
|
|
|
|
printf "EC firmware path not declared for board: %s\n" \
|
|
|
|
"${board}"
|
|
|
|
fi
|
|
|
|
if [ ! -f "${_ec1_location}" ] || [ ! -f "${_ec2_location}" ];
|
|
|
|
then
|
|
|
|
printf "EC firmware not downloaded for board: %s\n" \
|
|
|
|
"${board}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
./coreboot/default/util/cbfstool/cbfstool "${rom}" add -f ${_ec1_location} -n ecfw1.bin -b ${_ec1_offset} -t raw || exit 1
|
|
|
|
./coreboot/default/util/cbfstool/cbfstool "${rom}" add -f ${_ec2_location} -n ecfw2.bin -b ${_ec2_offset} -t raw || exit 1
|
|
|
|
fi
|
|
|
|
|
2023-04-03 00:06:46 +00:00
|
|
|
if [ "${modifygbe}" = "true" ] && ! [ "${release}" = "true" ]; then
|
|
|
|
Modify_gbe ${rom}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
Patch_release(){
|
|
|
|
_tmpdir=$(mktemp -d "/tmp/${board}_tmpXXXX")
|
|
|
|
tar xf "${releasearchive}" -C "${_tmpdir}" || \
|
|
|
|
Fail 'could not extract release archive'
|
|
|
|
|
|
|
|
for rom in ${_tmpdir}/bin/*/*.rom ; do
|
|
|
|
echo "patching rom $rom"
|
|
|
|
Patch ${rom} || \
|
|
|
|
Fail "could not patch ${rom}"
|
|
|
|
done
|
|
|
|
|
|
|
|
( cd ${_tmpdir}/bin/*
|
|
|
|
sha1sum --status -c blobhashes || \
|
|
|
|
Fail 'ROMs did not match expected hashes'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
if [ "${modifygbe}" = "true" ]; then
|
2023-04-03 00:06:46 +00:00
|
|
|
for rom in ${_tmpdir}/bin/*/*.rom ; do
|
|
|
|
Modify_gbe ${rom}
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -d bin/release ]; then
|
|
|
|
mkdir -p bin/release
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
2023-04-03 00:06:46 +00:00
|
|
|
|
|
|
|
mv ${_tmpdir}/bin/* bin/release/ && \
|
|
|
|
printf '%s\n' 'Success! Your ROMs are in bin/release'
|
|
|
|
|
|
|
|
rm -r "${_tmpdir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
Check_release(){
|
|
|
|
if ! [ -f ${1} ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
_filetype=$(file -b "${1}")
|
|
|
|
|
|
|
|
if [ "${_filetype%%,*}" = "XZ compressed data" ]; then
|
|
|
|
printf "%s\n" "Release archive ${1} detected"
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2022-11-14 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "${1}" = "listboards" ]; then
|
|
|
|
listboards
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Implementing parameter parsing now so more options can be added later
|
|
|
|
while getopts r:b:m: option
|
|
|
|
do
|
|
|
|
case "${option}"
|
|
|
|
in
|
|
|
|
r)rom=${OPTARG};;
|
|
|
|
b)board=${OPTARG};;
|
|
|
|
m)
|
|
|
|
modifygbe=true
|
|
|
|
new_mac=${OPTARG}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-04-03 00:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ! Check_release ${1} ; then
|
|
|
|
if [ ! -f "${rom}" ]; then
|
|
|
|
Fail "${rom} is not a valid path"
|
|
|
|
elif [ -z ${rom+x} ]; then
|
|
|
|
Fail 'no rom specified'
|
|
|
|
elif [ -z ${board+x} ]; then
|
|
|
|
board=$(Detect_board ${rom}) || \
|
|
|
|
Fail 'no board specified'
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
release=true
|
|
|
|
releasearchive="${1}"
|
|
|
|
board=$(Detect_board ${1}) || \
|
|
|
|
Fail 'Could not detect board type'
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-03 00:06:46 +00:00
|
|
|
|
2022-11-14 00:51:12 +00:00
|
|
|
if [ ! -d "resources/coreboot/${board}/" ]; then
|
2022-11-26 19:45:40 +00:00
|
|
|
Fail "board ${board} not found"
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d coreboot/default ]; then
|
|
|
|
printf "downloading coreboot\n"
|
|
|
|
./download coreboot default
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "coreboot/default/util/ifdtool/ifdtool" ]; then
|
|
|
|
printf "building ifdtool from coreboot\n"
|
2023-03-05 14:00:06 +00:00
|
|
|
./build module cbutils default || Fail 'could not build ifdtool'
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "coreboot/default/util/cbfstool/cbfstool" ]; then
|
|
|
|
printf "building cbfstool from coreboot\n"
|
2023-03-05 14:00:06 +00:00
|
|
|
./build module cbutils default || Fail 'could not build cbfstool'
|
2022-11-14 00:51:12 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-03 00:06:46 +00:00
|
|
|
./blobutil download ${board} || \
|
|
|
|
Fail "Could not download blobs for ${board}, check network connection"
|
|
|
|
|
|
|
|
if [ "${release}" = "true" ]; then
|
|
|
|
echo 'patching release file'
|
|
|
|
Patch_release
|
|
|
|
else
|
|
|
|
Patch ${rom}
|
|
|
|
fi
|