safer, simpler error handling in lbmk

in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".

in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.

in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.

lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.

in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:

err="fail"

this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err

example:

	rm -f "$filename" || err "could not delete file"

this would now be:

	rm -f "$filename" || $err "could not delete file"

overriding of err= must be done *after* including err.sh. for
example:

err="fail"
. "include/err.sh"

^ this is wrong. instead, one must do:

. "include/err.sh"
err="fail"

this is because err is set as a global variable under err.sh

the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2024-03-27 01:19:39 +00:00
parent 6b11f1b055
commit 6ebab10caa
11 changed files with 191 additions and 202 deletions
+18 -18
View File
@@ -49,7 +49,7 @@ main()
done
[ "${all}" != "y" ] || boards=$(items config/coreboot) || \
err "Cannot generate list of boards for building"
$err "Cannot generate list of boards for building"
for x in ${boards}; do
eval "$(setvars "n" ${pv}) $(setvars "" ${v})"
@@ -62,7 +62,7 @@ main()
targets="* bin/${board}\n${targets}"
done
[ -z "${targets}" ] && err "No ROM images were compiled"
[ -z "${targets}" ] && $err "No ROM images were compiled"
printf "\nROM images available in these directories:\n"
eval "printf \"${targets}\""
printf "^^ ROM images available in these directories.\n\n"
@@ -74,7 +74,7 @@ configure_target()
{
targetdir="${cfgsdir}/${board}"
[ -f "${targetdir}/target.cfg" ] || \
err "Missing target.cfg for target: ${board}"
$err "Missing target.cfg for target: ${board}"
# Override the above defaults using target.cfg
. "${targetdir}/target.cfg"
@@ -84,7 +84,7 @@ configure_target()
&& [ "${grub_scan_disk}" != "ahci" ] && \
grub_scan_disk="both"
[ -z "$tree" ] && err "$board: tree not defined"
[ -z "$tree" ] && $err "$board: tree not defined"
[ "${payload_memtest}" != "y" ] && payload_memtest="n"
[ "${payload_grub_withseabios}" = "y" ] && payload_grub="y"
@@ -101,7 +101,7 @@ configure_target()
[ "${payload_uboot}" != "y" ] && \
for configfile in "${targetdir}/config/"*; do
[ -e "${configfile}" ] || continue
err "target '${board}' defines no payload"
$err "target '${board}' defines no payload"
done
[ "$payload_uboot" != "n" ] && [ "$payload_uboot" != "y" ] && \
@@ -149,7 +149,7 @@ build_grub_payload()
keymaps="${keymaps} ${keymapfile}"
done
[ -z "$_keyboard" ] || [ -f "$grubcfgsdir/keymap/$_keyboard.gkb" ] || \
err "build_grub_payload: $_keyboard layout not defined"
$err "build_grub_payload: $_keyboard layout not defined"
[ -n "$_keyboard" ] && keymaps="${grubcfgsdir}/keymap/${_keyboard}.gkb"
[ -f "$grubelf" ] && return 0
[ -f "src/grub/grub-mkstandalone" ] || x_ ./update trees -b grub
@@ -164,7 +164,7 @@ build_grub_payload()
--install-modules="${grub_install_modules}" \
"/boot/grub/grub.cfg=${grubcfgsdir}/config/grub_memdisk.cfg" \
"/boot/grub/grub_default.cfg=${grubcfgsdir}/config/grub.cfg" || \
err "could not generate grub.elf"
$err "could not generate grub.elf"
}
build_uboot_payload()
@@ -175,12 +175,12 @@ build_uboot_payload()
[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot" ] && \
ubootelf="${ubdir}/u-boot"
[ -f "${ubootelf}" ] && return 0
err "Can't find u-boot build for board, $board";
$err "Can't find u-boot build for board, $board";
}
build_target_mainboard()
{
rm -f "${romdir}/"* || err "!prepare, rm files, ${romdir}"
rm -f "${romdir}/"* || $err "!prepare, rm files, ${romdir}"
for x in "normal" "vgarom" "libgfxinit"; do
initmode="${x}"
@@ -237,7 +237,7 @@ build_seabios_roms()
x_ build_grub_roms "${t}" "seabios_withgrub"
else
t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \
err "build_seabios_roms: cannot build tmprom"
$err "build_seabios_roms: cannot build tmprom"
newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}"
[ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \
&& newrom="${newrom}_${board}_${initmode}"
@@ -256,13 +256,13 @@ build_grub_roms()
if [ "$payload1" = "grub" ] && [ "$payload_grub_withseabios" = "y" ]
then
_tmpmvrom=$(mkSeabiosRom "$tmprom" "seabios.elf") || \
err "build_grub_roms 1 $board: can't build tmprom"
$err "build_grub_roms 1 $board: can't build tmprom"
x_ mv "$_tmpmvrom" "$tmprom"
elif [ "$payload1" != "grub" ] && [ "$payload_seabios_withgrub" = "y" ]
then
grub_cbfs="img/grub2"
_tmpmvrom=$(mkSeabiosRom "$tmprom" fallback/payload) || \
err "build_grub_roms 2 $board: can't build tmprom"
$err "build_grub_roms 2 $board: can't build tmprom"
x_ mv "$_tmpmvrom" "$tmprom"
fi
@@ -276,16 +276,16 @@ build_grub_roms()
backgroundfile="config/grub/background/${grub_background}"
"${cbfstool}" "${tmprom}" add -f ${backgroundfile} \
-n background.png -t raw || \
err "insert background, ${backgroundfile}"
$err "insert background, ${backgroundfile}"
fi
tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX)
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" >"$tmpcfg" \
|| err "set grub_scandisk, $grub_scan_disk, $tmpcfg"
|| $err "set grub_scandisk, $grub_scan_disk, $tmpcfg"
[ "${grub_scan_disk}" = "both" ] || \
x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \
err "set timeout, ${grub_timeout}, ${tmpcfg}"
$err "set timeout, ${grub_timeout}, ${tmpcfg}"
[ -z "${grub_timeout}" ] || x_ "${cbfstool}" "${tmprom}" add \
-f "${tmpcfg}" -n timeout.cfg -t raw
x_ rm -f "${tmpcfg}"
@@ -344,7 +344,7 @@ mkSeabiosGrubonlyRom()
tmpbootorder=$(mktemp -t coreboot_rom.XXXXXXXXXX)
# only load grub, by inserting a custom bootorder file
printf "/rom@img/grub2\n" > "$tmpbootorder" || err "printf bootorder"
printf "/rom@img/grub2\n" > "$tmpbootorder" || $err "printf bootorder"
x_ "${cbfstool}" "${_grubrom}" \
add -f "${tmpbootorder}" -n bootorder -t raw
x_ rm -f "${tmpbootorder}"
@@ -356,7 +356,7 @@ mkSeabiosGrubonlyRom()
build_uboot_roms()
{
tmprom=$(mkUbootRom "${cbrom}" "fallback/payload") || \
err "build_uboot_roms $board: could not create tmprom"
$err "build_uboot_roms $board: could not create tmprom"
newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
x_ moverom "${tmprom}" "${newrom}"
x_ rm -f "${tmprom}"
@@ -370,7 +370,7 @@ mkUbootRom() {
_ubdir="elf/u-boot/${board}/${uboot_config}"
_ubootelf="${_ubdir}/u-boot.elf"
[ -f "${_ubootelf}" ] || _ubootelf="${_ubdir}/u-boot"
[ -f "$_ubootelf" ] || err "mkUbootRom: $board: cant find u-boot"
[ -f "$_ubootelf" ] || $err "mkUbootRom: $board: cant find u-boot"
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
+3 -3
View File
@@ -17,8 +17,8 @@ usage="usage: ./build firmware serprog <rp2040|stm32> [board]"
main()
{
[ -z "${1+x}" ] && err "${usage}"
[ "$1" != "rp2040" ] && [ "$1" != "stm32" ] && err "$usage"
[ -z "${1+x}" ] && $err "${usage}"
[ "$1" != "rp2040" ] && [ "$1" != "stm32" ] && $err "$usage"
if [ "${1}" = "rp2040" ]; then
boards_dir=${pico_sdk_dir}/src/boards/include/boards
[ -d "$pico_src_dir" ] || x_ ./update trees -f "pico-serprog"
@@ -71,7 +71,7 @@ print_boards()
list_boards()
{
basename -a -s .h "${1}/"*.h || err "list_boards $1: can't list boards"
basename -a -s .h "${1}/"*.h || $err "list_boards $1: can't list boards"
}
main $@
+46 -46
View File
@@ -13,11 +13,11 @@ main()
{
vdir="release"
while getopts d:m: option; do
[ -z "${OPTARG}" ] && err "Empty argument not allowed"
[ -z "${OPTARG}" ] && $err "Empty argument not allowed"
case "${option}" in
d) vdir="${OPTARG}" ;;
m) mode="${OPTARG}" ;;
*) err "Invalid option" ;;
*) $err "Invalid option" ;;
esac
done
@@ -29,7 +29,7 @@ main()
src_dirname="${relname}_src"
srcdir="${vdir}/${src_dirname}"
[ -e "${vdir}" ] && err "already exists: \"${vdir}\""
[ -e "${vdir}" ] && $err "already exists: \"${vdir}\""
mkvdir
build_release
@@ -39,45 +39,45 @@ main()
mkvdir()
{
mkdir -p "${vdir}" || err "mkvdir: !mkdir -p \"${vdir}\""
git clone . "${srcdir}" || err "mkdir: !gitclone \"${srcdir}\""
insert_version_files "$srcdir" || err "mkvdir $srcdir: versionfile"
mkdir -p "${vdir}" || $err "mkvdir: !mkdir -p \"${vdir}\""
git clone . "${srcdir}" || $err "mkdir: !gitclone \"${srcdir}\""
insert_version_files "$srcdir" || $err "mkvdir $srcdir: versionfile"
}
build_release()
{
_xm="build_release ${vdir}"
(
cd "${srcdir}" || err "${_xm}: !cd \"${srcdir}\""
cd "${srcdir}" || $err "${_xm}: !cd \"${srcdir}\""
fetch_trees
[ "${mode}" = "u-boot" ] || x_ mv src/docs docs
) || err "can't create release files"
) || $err "can't create release files"
git log --graph --pretty=format:'%Cred%h%Creset %s %Creset' \
--abbrev-commit > "${srcdir}/CHANGELOG" || \
err "build_release $srcdir: couldn't generate changelog"
$err "build_release $srcdir: couldn't generate changelog"
(
if [ "${mode}" = "u-boot" ]; then
cd "${srcdir}/src/" || err "${_xm}: mktarball \"${srcdir}\""
cd "${srcdir}/src/" || $err "${_xm}: mktarball \"${srcdir}\""
mktarball u-boot "../../${srcdir##*/}.tar.xz" || \
err "$_xm: mksrc"
$err "$_xm: mksrc"
# make a src archive containing only u-boot
else
cd "${srcdir%/*}" || err "${_xm}: mktarball \"${srcdir}\""
cd "${srcdir%/*}" || $err "${_xm}: mktarball \"${srcdir}\""
mktarball "${srcdir##*/}" "${srcdir##*/}.tar.xz" || \
err "$_xm: mksrc"
$err "$_xm: mksrc"
fi
) || err "can't create src tarball"
) || $err "can't create src tarball"
[ "${mode}" = "src" ] && return 0
[ "${mode}" = "u-boot" ] && return 0
(
cd "${srcdir}" || err "${_xm}: 2 !cd \"${srcdir}\""
cd "${srcdir}" || $err "${_xm}: 2 !cd \"${srcdir}\""
mkrom_images
) || err "can't build rom images"
) || $err "can't build rom images"
rm -Rf "${srcdir}" || err "!rm -Rf ${srcdir}"
rm -Rf "${srcdir}" || $err "!rm -Rf ${srcdir}"
}
fetch_trees()
@@ -85,7 +85,7 @@ fetch_trees()
for x in config/git/*; do
[ "${mode}" = "u-boot" ] && break
[ ! -f "${x}" ] || ./update trees -f "${x#config/git/}" || \
err "${_xm}: fetch ${x#config/git/}"
$err "${_xm}: fetch ${x#config/git/}"
done
[ "${mode}" = "u-boot" ] && x_ ./update trees -f u-boot
@@ -93,56 +93,56 @@ fetch_trees()
[ -f "${x}" ] || continue
xp="${x#*/}"; xp="${xp%/*}"
[ -L "${xp}" ] || rm -Rf "src/${xp}/${xp}" || \
err "!rm -Rf \"src/${xp}/${xp}\""
$err "!rm -Rf \"src/${xp}/${xp}\""
done
find . -name ".git" -exec rm -Rf {} + || err "$_xm: rm .git"
find . -name ".gitmodules" -exec rm -Rf {} + || err "$_xm: rm .gitmod"
find . -name ".git" -exec rm -Rf {} + || $err "$_xm: rm .git"
find . -name ".gitmodules" -exec rm -Rf {} + || $err "$_xm: rm .gitmod"
x_ rm -Rf tmp .git
}
mkrom_images()
{
./build roms all || err "${_xm}: roms-all"
./build serprog rp2040 || err "${_xm}: rp2040"
./build serprog stm32 || err "${_xm}: stm32"
./build roms all || $err "${_xm}: roms-all"
./build serprog rp2040 || $err "${_xm}: rp2040"
./build serprog stm32 || $err "${_xm}: stm32"
for rombuild in bin/*; do
[ -d "${rombuild}" ] || continue
handle_rom_archive "${rombuild}"
done
mv "release/${version}/roms/" ../roms || err "${_xm}: copy roms/"
mv "release/${version}/roms/" ../roms || $err "${_xm}: copy roms/"
}
handle_rom_archive()
{
builddir="${1}"
romdir="tmp/romdir"
rm -Rf "${romdir}" || err "!rm romdir, handle_rom_archive"
rm -Rf "${romdir}" || $err "!rm romdir, handle_rom_archive"
target="${builddir##*/}"
if [ ! -f "config/coreboot/${target}/target.cfg" ]; then
# No config, just make a tarball
tarball="release/${version}/roms/${relname}_${target}.tar.xz"
insert_copying_files "${builddir}" || \
err "!insert copy, handle, ${builddir}"
$err "!insert copy, handle, ${builddir}"
mktarball "${builddir}" "${tarball}"
return 0
fi
romdir="${romdir}/bin/${target}"
mkdir -p "${romdir}" || err "!mkdir -p romdir, handle_rom_archive"
cp "$builddir/"* "$romdir" || err "!cp romdir, handle_rom_archive"
mkdir -p "${romdir}" || $err "!mkdir -p romdir, handle_rom_archive"
cp "$builddir/"* "$romdir" || $err "!cp romdir, handle_rom_archive"
nukerom
printf "Generating release/%s/roms/%s-%s_%s.tar.xz\n" \
"${version}" "${projectname}" "${version}" "${target##*/}"
insert_version_files "${romdir}" || \
err "mkrom_tarball ${romdir}: versionfile"
$err "mkrom_tarball ${romdir}: versionfile"
insert_copying_files "$romdir" || err "!insert copy, handle 2, $romdir"
insert_copying_files "$romdir" || $err "!insert copy, handle 2, $romdir"
mkrom_tarball
}
@@ -152,18 +152,18 @@ nukerom()
# Hash the images before removing vendor files
# which "./vendor inject" uses for verification
rm -f "${romdir}/vendorhashes" || err "!rm ${romdir}/vendorhashes"
touch "${romdir}/vendorhashes" || err "!touch ${romdir}/vendorhashes"
rm -f "${romdir}/vendorhashes" || $err "!rm ${romdir}/vendorhashes"
touch "${romdir}/vendorhashes" || $err "!touch ${romdir}/vendorhashes"
(
cd "${romdir}" || err "!cd romdir ${romdir}, nukerom"
cd "${romdir}" || $err "!cd romdir ${romdir}, nukerom"
sha512sum ./*.rom >> vendorhashes || \
err "!create vendorhashes, nukerom"
) || err "can't create vendor hashes"
$err "!create vendorhashes, nukerom"
) || $err "can't create vendor hashes"
for romfile in "${romdir}"/*.rom; do
[ -f "${romfile}" ] || continue
./vendor inject -r "$romfile" -b "$target" -n nuke || \
err "!vendor inject (nuke) ${romfile}, nukerom"
$err "!vendor inject (nuke) ${romfile}, nukerom"
done
}
@@ -188,13 +188,13 @@ mkrom_tarball()
{
archivename="${relname}_${target##*/}"
f="release/${version}/roms/${archivename}"
mkdir -p "${f%/*}" || err "mkrom_tarball: !mkdir -p ${f%/*}"
mkdir -p "${f%/*}" || $err "mkrom_tarball: !mkdir -p ${f%/*}"
(
cd "${romdir%"/bin/$target"}" || err "!cd ${romdir%"/bin/$target"}"
cd "${romdir%"/bin/$target"}" || $err "!cd ${romdir%"/bin/$target"}"
mktarball "bin/${target}" "${archivename}.tar.xz"
) || err "can't create rom tarball"
) || $err "can't create rom tarball"
mv "${romdir%"/bin/${target}"}/${archivename}.tar.xz"* "${f%/*}" || \
err "mktar ${f%/*}/${romdir%"/bin/$target"}/$archivename.tar.xz"
$err "mktar ${f%/*}/${romdir%"/bin/$target"}/$archivename.tar.xz"
printf "Created ROM archive: %s" "${f%/*}/${archivename}.tar.xz"
}
@@ -212,20 +212,20 @@ mktarball()
tar_implementation=$(tar --version | head -n1) || :
[ "${2%/*}" = "${2}" ] || \
mkdir -p "${2%/*}" || err "mk, !mkdir -p \"${2%/*}\""
mkdir -p "${2%/*}" || $err "mk, !mkdir -p \"${2%/*}\""
if [ "${tar_implementation% *}" = "tar (GNU tar)" ]; then
tar --sort=name --owner=root:0 --group=root:0 \
--mtime="UTC 2024-02-25" -c "$1" | xz -T0 -9e > "$2" || \
err "mktarball 1, ${1}"
$err "mktarball 1, ${1}"
else
# TODO: reproducible tarballs on non-GNU systems
tar -c "$1" | xz -T0 -9e > "$2" || err "mktarball 2, $1"
tar -c "$1" | xz -T0 -9e > "$2" || $err "mktarball 2, $1"
fi
(
[ "${2%/*}" != "${2}" ] && x_ cd "${2%/*}"
sha512sum "${2##*/}" > "${2##*/}.sha512" || \
err "!sha512sum \"${2##*/}\" > \"${2##*/}.sha512\""
) || err "failed to create tarball checksum"
$err "!sha512sum \"${2##*/}\" > \"${2##*/}.sha512\""
) || $err "failed to create tarball checksum"
}
main $@
+15 -15
View File
@@ -28,12 +28,12 @@ main()
-s) mode="savedefconfig" ;;
-l) mode="olddefconfig" ;;
-n) mode="nconfig" ;;
*) err "Invalid option" ;;
*) $err "Invalid option" ;;
esac
shift; project="${OPTARG#src/}"; shift
done
[ -z "$_f" ] && err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
[ -z "$project" ] && err "project name not specified"
[ -z "$_f" ] && $err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
[ -z "$project" ] && $err "project name not specified"
elfdir="elf/${project}"
cfgsdir="config/${project}"
@@ -66,17 +66,17 @@ build_targets()
[ "$elfdir" = "elf/coreboot" ] && \
elfdir="elf/coreboot_nopayload_DO_NOT_FLASH"
[ -d "$cfgsdir" ] || err "directory, $cfgsdir, does not exist"
[ -d "$cfgsdir" ] || $err "directory, $cfgsdir, does not exist"
listfile="${cfgsdir}/build.list"
[ -f "$listfile" ] || err "list file, $listfile, does not exist"
[ -f "$listfile" ] || $err "list file, $listfile, does not exist"
# Build for all targets if no argument is given
[ $# -gt 0 ] && target1="$1"
[ "$target1" = "utils" ] && [ "$project" = "coreboot" ] && \
shift 1
targets=$(items "$cfgsdir") || \
err "Cannot get options for $cfgsdir"
$err "Cannot get options for $cfgsdir"
[ $# -gt 0 ] && targets=$@
[ -z "$mode" ] && x_ mkdir -p "$elfdir"
@@ -130,7 +130,7 @@ handle_src_tree()
x_ mkdir -p "${elfdir}/${target}"
[ -z "$tree" ] && err "handle_src_tree $project/$tree: tree unset"
[ -z "$tree" ] && $err "handle_src_tree $project/$tree: tree unset"
codedir="src/${project}/${tree}"
@@ -155,7 +155,7 @@ load_project_config()
[ -f "${1}/target.cfg" ] || return 0
. "${1}/target.cfg" || \
err "load_project_config ${1}: cannot load target.cfg"; return 0
$err "load_project_config ${1}: cannot load target.cfg"; return 0
}
check_cross_compiler()
@@ -178,7 +178,7 @@ check_cross_compiler()
check_config()
{
[ -f "$config" ] || err "check_config: ${project}/${target}: no config"
[ -f "$config" ] || $err "check_config: ${project}/${target}: no config"
dest_dir="${elfdir}/${target}/${config_name}"
# TODO: very hacky check. do it properly (based on build.list)
@@ -197,7 +197,7 @@ handle_makefile()
[ -n "$mode" ] || make -C "$codedir" silentoldconfig || \
make -C "$codedir" oldconfig || :
run_make_command || err "handle_makefile $codedir: no makefile!"
run_make_command || $err "handle_makefile $codedir: no makefile!"
if [ -e "${codedir}/.git" ] && [ "$project" = "u-boot" ] && \
[ "$mode" = "distclean" ]; then
@@ -220,7 +220,7 @@ run_make_command()
printf "%s\n" "${version%%-*}" > "$codedir/.coreboot-version"
make $mode -j$(nproc) $makeargs -C "$codedir" || \
err "run_make $codedir: !make $mode"
$err "run_make $codedir: !make $mode"
[ "$mode" != "clean" ] && return 0
make -C "$codedir" distclean 2>/dev/null || :
@@ -232,9 +232,9 @@ check_cmake()
check_makefile "${1}" || \
cmake -B "${1}" "${1}/${cmakedir}" || \
check_makefile "${1}" || \
err "check_cmake ${1}: can't cmake ${cmakedir}"
$err "check_cmake ${1}: can't cmake ${cmakedir}"
[ -z "${cmakedir}" ] || check_makefile "${1}" || \
err "check_cmake ${1}: could not generate Makefile"
$err "check_cmake ${1}: could not generate Makefile"
return 0
}
@@ -242,11 +242,11 @@ check_autoconf()
{
(
_cfgopt=""
cd "${1}" || err "!cd $1"
cd "${1}" || $err "!cd $1"
[ -f "bootstrap" ] && x_ ./bootstrap $bootstrapargs
[ -f "autogen.sh" ] && x_ ./autogen.sh ${autogenargs}
[ -f "configure" ] && x_ ./configure $autoconfargs; return 0
) || err "can't bootstrap project: $1"
) || $err "can't bootstrap project: $1"
}
check_makefile()
+27 -27
View File
@@ -25,14 +25,14 @@ eval "$(setvars "" _b _dl EC_url EC_url_bkup EC_hash DL_hash DL_url DL_url_bkup
main()
{
[ $# -gt 0 ] || err "No argument given"
[ $# -gt 0 ] || $err "No argument given"
board="${1}"
boarddir="${cbcfgsdir}/${board}"
_b="${board%%_*mb}" # shorthand (no duplication per rom size)
check_defconfig "${boarddir}" && exit 0
detect_firmware && exit 0
scan_config "${_b}" "config/vendor" "err"
scan_config "${_b}" "config/vendor"
build_dependencies
download_vendorfiles
@@ -49,7 +49,7 @@ detect_firmware()
set -- "${boarddir}/config/"*
. "${1}" 2>/dev/null
. "${boarddir}/target.cfg" 2>/dev/null
[ -z "$tree" ] && err "detect_firmware $boarddir: tree undefined"
[ -z "$tree" ] && $err "detect_firmware $boarddir: tree undefined"
cbdir="src/coreboot/$tree"
cbfstool="cbutils/$tree/cbfstool"
@@ -110,8 +110,8 @@ fetch()
dl_bkup="${3}"
dlsum="${4}"
[ "${5}" = "/dev/null" ] && return 0
[ "${5# }" = "$5" ] || err "fetch: space not allowed in _dest: '$5'"
[ "${5#/}" = "$5" ] || err "fetch: absolute path not allowed: '$5'"
[ "${5# }" = "$5" ] || $err "fetch: space not allowed in _dest: '$5'"
[ "${5#/}" = "$5" ] || $err "fetch: absolute path not allowed: '$5'"
_dest="${5##*../}"
_dl="${vendir}/cache/${dlsum}"
dl_fail="n"
@@ -129,14 +129,14 @@ fetch()
vendor_checksum "${dlsum}" "${_dl}" || dl_fail="n"
done
[ "${dl_fail}" = "y" ] && \
err "fetch ${dlsum}: matched file unavailable"
$err "fetch ${dlsum}: matched file unavailable"
x_ rm -Rf "${_dl}_extracted"
mkdirs "${_dest}" "extract_${dl_type}" || return 0
eval "extract_${dl_type}"
[ -f "${_dest}" ] && return 0
err "extract_${dl_type} (fetch): missing file: '${_dest}'"
$err "extract_${dl_type} (fetch): missing file: '${_dest}'"
}
vendor_checksum()
@@ -152,17 +152,17 @@ mkdirs()
printf "mkdirs %s %s: already downloaded\n" "$1" "$2" 1>&2
return 1
fi
mkdir -p "${1%/*}" || err "mkdirs: !mkdir -p ${1%/*}"
mkdir -p "${1%/*}" || $err "mkdirs: !mkdir -p ${1%/*}"
remkdir "${appdir}"
extract_archive "${_dl}" "${appdir}" || \
[ "${2}" = "extract_e6400vga" ] || \
err "mkdirs ${1} ${2}: !extract"
$err "mkdirs ${1} ${2}: !extract"
}
extract_intel_me()
{
[ ! -f "$mecleaner" ] && \
err "extract_intel_me $cbdir: me_cleaner missing"
$err "extract_intel_me $cbdir: me_cleaner missing"
_me="${PWD}/${_dest}" # must always be an absolute path
cdir="${PWD}/${appdir}" # must always be an absolute path
@@ -170,10 +170,10 @@ extract_intel_me()
[ -f "${_me}" ] && return 0
sdir="$(mktemp -d)"
mkdir -p "$sdir" || err "extract_intel_me: !mkdir -p \"$sdir\""
mkdir -p "$sdir" || $err "extract_intel_me: !mkdir -p \"$sdir\""
(
[ "${cdir#/a}" != "$cdir" ] && cdir="${cdir#/}"
cd "$cdir" || err "extract_intel_me: !cd \"$cdir\""
cd "$cdir" || $err "extract_intel_me: !cd \"$cdir\""
for i in *; do
[ -f "$_me" ] && break
[ -L "$i" ] && continue
@@ -195,7 +195,7 @@ extract_intel_me()
cd "${cdir}" || :
done
)
rm -Rf "${sdir}" || err "extract_intel_me: !rm -Rf ${sdir}"
rm -Rf "${sdir}" || $err "extract_intel_me: !rm -Rf ${sdir}"
}
extract_archive()
@@ -207,44 +207,44 @@ extract_archive()
extract_kbc1126ec()
{
[ ! -f "$kbc1126_ec_dump" ] && \
err "extract_kbc1126ec $cbdir: kbc1126_ec_dump missing"
$err "extract_kbc1126ec $cbdir: kbc1126_ec_dump missing"
(
x_ cd "${appdir}/"
mv Rompaq/68*.BIN ec.bin || :
if [ ! -f ec.bin ]; then
unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \
unar -D 68*.CAB Rom.bin || err "can't extract Rom.bin"
unar -D 68*.CAB Rom.bin || $err "can't extract Rom.bin"
x_ mv Rom.bin ec.bin
fi
[ -f ec.bin ] || err "extract_kbc1126_ec ${board}: can't extract"
[ -f ec.bin ] || $err "extract_kbc1126_ec ${board}: can't extract"
"${kbc1126_ec_dump}" ec.bin || \
err "extract_kbc1126_ec ${board}: can't extract ecfw1/2.bin"
) || err "can't extract kbc1126 ec firmware"
$err "extract_kbc1126_ec ${board}: can't extract ecfw1/2.bin"
) || $err "can't extract kbc1126 ec firmware"
ec_ex="y"
for i in 1 2; do
[ -f "${appdir}/ec.bin.fw${i}" ] || ec_ex="n"
done
[ "${ec_ex}" = "y" ] || \
err "extract_kbc1126_ec ${board}: didn't extract ecfw1/2.bin"
$err "extract_kbc1126_ec ${board}: didn't extract ecfw1/2.bin"
cp "${appdir}/"ec.bin.fw* "${_dest%/*}/" || \
err "extract_kbc1126_ec ${board}: can't copy ec binaries"
$err "extract_kbc1126_ec ${board}: can't copy ec binaries"
}
extract_e6400vga()
{
for v in E6400_VGA_offset E6400_VGA_romname; do
eval "[ -z \"\$$v\" ] && err \"extract_e6400vga: $v undefined\""
eval "[ -z \"\$$v\" ] && $err \"extract_e6400vga: $v undefined\""
done
tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || :
(
x_ cd "${appdir}"
[ -f "bios.bin" ] || err "extract_e6400vga: can't extract bios.bin"
[ -f "bios.bin" ] || $err "extract_e6400vga: can't extract bios.bin"
"${e6400_unpack}" bios.bin || printf "TODO: fix dell extract util\n"
[ -f "${E6400_VGA_romname}" ] || \
err "extract_e6400vga: can't extract vga rom from bios.bin"
) || err "can't extract e6400 vga rom"
$err "extract_e6400vga: can't extract vga rom from bios.bin"
) || $err "can't extract e6400 vga rom"
cp "${appdir}/${E6400_VGA_romname}" "${_dest}" || \
err "extract_e6400vga ${board}: can't copy vga rom to ${_dest}"
$err "extract_e6400vga ${board}: can't copy vga rom to ${_dest}"
}
extract_sch5545ec()
@@ -258,9 +258,9 @@ extract_sch5545ec()
# this makes the file defined by _sch5545ec_fw available to copy
"${uefiextract}" "${_bios}" || \
err "extract_sch5545ec: cannot extract from uefi image"
$err "extract_sch5545ec: cannot extract from uefi image"
cp "${_sch5545ec_fw}" "${_dest}" || \
err "extract_sch5545ec: cannot copy sch5545ec firmware file"
$err "extract_sch5545ec: cannot copy sch5545ec firmware file"
}
main $@
+22 -22
View File
@@ -13,7 +13,7 @@ eval "$(setvars "" archive rom modifygbe nukemode release new_mac tree)"
main()
{
[ $# -lt 1 ] && err "No options specified."
[ $# -lt 1 ] && $err "No options specified."
[ "${1}" = "listboards" ] && eval "items config/coreboot || :; exit 0"
archive="${1}"
@@ -42,8 +42,8 @@ check_board()
failcheck="n"
check_release "${archive}" || failcheck="y"
if [ "${failcheck}" = "y" ]; then
[ -f "$rom" ] || err "check_board \"$rom\": invalid path"
[ -z "${rom+x}" ] && err "check_board: no rom specified"
[ -f "$rom" ] || $err "check_board \"$rom\": invalid path"
[ -z "${rom+x}" ] && $err "check_board: no rom specified"
[ -n "${board+x}" ] || board=$(detect_board "${rom}")
else
release="y"
@@ -51,11 +51,11 @@ check_board()
fi
boarddir="${cbcfgsdir}/${board}"
[ -d "$boarddir" ] || err "check_board: board $board missing"
[ -d "$boarddir" ] || $err "check_board: board $board missing"
[ -f "$boarddir/target.cfg" ] || \
err "check_board $board: target.cfg missing"
$err "check_board $board: target.cfg missing"
. "$boarddir/target.cfg" 2>/dev/null
[ -z "$tree" ] && err "check_board $board: tree undefined"; return 0
[ -z "$tree" ] && $err "check_board $board: tree undefined"; return 0
}
check_release()
@@ -80,7 +80,7 @@ detect_board()
_stripped_prefix=${filename#*_}
board="${_stripped_prefix%.tar.xz}" ;;
*)
err "detect_board $filename: could not detect board type"
$err "detect_board $filename: could not detect board type"
esac
printf "%s\n" "${board}"
}
@@ -109,7 +109,7 @@ patch_release_roms()
_tmpdir="tmp/romdir"
remkdir "${_tmpdir}"
tar -xf "${archive}" -C "${_tmpdir}" || \
err "patch_release_roms: !tar -xf \"$archive\" -C \"$_tmpdir\""
$err "patch_release_roms: !tar -xf \"$archive\" -C \"$_tmpdir\""
for x in "${_tmpdir}"/bin/*/*.rom ; do
printf "patching rom: %s\n" "$x"
@@ -118,14 +118,14 @@ patch_release_roms()
(
cd "${_tmpdir}/bin/"* || \
err "patch_release_roms: !cd ${_tmpdir}/bin/*"
$err "patch_release_roms: !cd ${_tmpdir}/bin/*"
# NOTE: For compatibility with older rom releases, defer to sha1
[ "${nukemode}" = "nuke" ] || sha512sum --status -c vendorhashes || \
sha1sum --status -c vendorhashes || sha512sum --status -c \
blobhashes || sha1sum --status -c blobhashes || \
err "patch_release_roms: ROMs did not match expected hashes"
) || err "can't verify vendor hashes"
$err "patch_release_roms: ROMs did not match expected hashes"
) || $err "can't verify vendor hashes"
[ "${modifygbe}" = "true" ] && \
for x in "${_tmpdir}"/bin/*/*.rom ; do
@@ -143,7 +143,7 @@ patch_rom()
{
rom="${1}"
check_defconfig "$boarddir" && err "patch_rom $boarddir: no configs"
check_defconfig "$boarddir" && $err "patch_rom $boarddir: no configs"
set -- "${boarddir}/config/"*
. "${1}" 2>/dev/null
@@ -174,18 +174,18 @@ patch_rom()
inject()
{
[ $# -lt 3 ] && \
err "inject $@, $rom: usage: inject name path type (offset)"
$err "inject $@, $rom: usage: inject name path type (offset)"
eval "$(setvars "" cbfsname _dest _t _offset)"
cbfsname="${1}"
_dest="${2##*../}"
_t="${3}"
[ $# -gt 3 ] && _offset="-b ${4}" && [ -z "${4}" ] && \
err "inject $@, $rom: offset passed, but empty (not defined)"
$err "inject $@, $rom: offset passed, but empty (not defined)"
[ -z "${_dest}" ] && err "inject $@, ${rom}: empty destination path"
[ -z "${_dest}" ] && $err "inject $@, ${rom}: empty destination path"
[ ! -f "${_dest}" ] && [ "${nukemode}" != "nuke" ] && \
err "inject_${dl_type}: file missing, ${_dest}"
$err "inject_${dl_type}: file missing, ${_dest}"
[ "$nukemode" = "nuke" ] || \
printf "Inserting %s/%s in file: %s\n" "$cbfsname" "$_t" "$rom"
@@ -193,18 +193,18 @@ inject()
if [ "${_t}" = "GbE" ]; then
x_ mkdir -p tmp
cp "${_dest}" "tmp/gbe.bin" || \
err "inject: !cp \"${_dest}\" \"tmp/gbe.bin\""
$err "inject: !cp \"${_dest}\" \"tmp/gbe.bin\""
_dest="tmp/gbe.bin"
"${nvmutil}" "${_dest}" setmac "${new_mac}" || \
err "inject ${_dest}: can't change mac address"
$err "inject ${_dest}: can't change mac address"
fi
if [ "${cbfsname}" = "IFD" ]; then
if [ "${nukemode}" != "nuke" ]; then
"$ifdtool" -i ${_t}:${_dest} "$rom" -O "$rom" || \
err "inject: can't insert $_t ($dest) into $rom"
$err "inject: can't insert $_t ($dest) into $rom"
else
"$ifdtool" --nuke $_t "$rom" -O "$rom" || \
err "inject $rom: can't nuke $_t in IFD"
$err "inject $rom: can't nuke $_t in IFD"
fi
else
if [ "${nukemode}" != "nuke" ]; then
@@ -214,11 +214,11 @@ inject()
else
"$cbfstool" "$rom" add -f "$_dest" \
-n "$cbfsname" -t $_t $_offset || \
err "$rom: can't insert $_t file $_dest"
$err "$rom: can't insert $_t file $_dest"
fi
else
"$cbfstool" "$rom" remove -n "$cbfsname" || \
err "inject $rom: can't remove $cbfsname"
$err "inject $rom: can't remove $cbfsname"
fi
fi
}