From 6ebab10caa5be6fc1cfd244e745851687d4bd70d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 27 Mar 2024 01:19:39 +0000 Subject: 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 --- build | 33 +++++++++--------- include/err.sh | 25 ++++---------- include/git.sh | 42 +++++++++++------------ include/mrc.sh | 22 ++++++------ include/option.sh | 9 +++-- script/build/roms | 36 ++++++++++---------- script/build/serprog | 6 ++-- script/update/release | 92 +++++++++++++++++++++++++------------------------- script/update/trees | 30 ++++++++-------- script/vendor/download | 54 ++++++++++++++--------------- script/vendor/inject | 44 ++++++++++++------------ 11 files changed, 191 insertions(+), 202 deletions(-) diff --git a/build b/build index 214cec30..38d1694c 100755 --- a/build +++ b/build @@ -14,6 +14,7 @@ export LC_ALL=C . "include/option.sh" eval "$(setvars "" option aur_notice tmpdir)" +err="fail" tmpdir_was_set="y" set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n" @@ -35,10 +36,10 @@ buildpath="./script/${linkname}" main() { - xx_ id -u 1>/dev/null 2>/dev/null - [ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help" + x_ id -u 1>/dev/null 2>/dev/null + [ $# -lt 1 ] && $err "Too few arguments. Try: ${0} help" - [ "$1" = "dependencies" ] && xx_ install_packages $@ && lbmk_exit 0 + [ "$1" = "dependencies" ] && x_ install_packages $@ && lbmk_exit 0 for cmd in initcmd check_git check_project git_init excmd; do eval "${cmd} \$@" @@ -48,7 +49,7 @@ main() initcmd() { - [ "$(id -u)" != "0" ] || fail "this command as root is not permitted" + [ "$(id -u)" != "0" ] || $err "this command as root is not permitted" check_project @@ -69,14 +70,14 @@ install_packages() printf "You must specify a distro, namely:\n" 1>&2 printf "Look at files under config/dependencies/\n" 1>&2 printf "Example: ./build dependencies debian\n" 1>&2 - fail "install_packages: target not specified" + $err "install_packages: target not specified" fi - [ -f "config/dependencies/${2}" ] || fail "Unsupported target" + [ -f "config/dependencies/${2}" ] || $err "Unsupported target" . "config/dependencies/${2}" - xx_ ${pkg_add} ${pkglist} + x_ ${pkg_add} ${pkglist} [ -z "${aur_notice}" ] && return 0 printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2 } @@ -85,24 +86,24 @@ install_packages() # lbmk can be run from lbmk.git, or an archive. git_init() { - [ -L ".git" ] && fail "Reference .git is a symlink" + [ -L ".git" ] && $err "Reference .git is a symlink" [ -e ".git" ] && return 0 eval "$(setvars "$(date -Rd @${versiondate})" cdate _nogit)" - git init || fail "${PWD}: cannot initialise Git repository" - git add -A . || fail "${PWD}: cannot add files to Git repository" + git init || $err "${PWD}: cannot initialise Git repository" + git add -A . || $err "${PWD}: cannot add files to Git repository" git commit -m "${projectname} ${version}" --date "${cdate}" \ --author="lbmk " || \ - fail "$PWD: can't commit ${projectname}/${version}, date $cdate" + $err "$PWD: can't commit ${projectname}/${version}, date $cdate" git tag -a "${version}" -m "${projectname} ${version}" || \ - fail "${PWD}: cannot git-tag ${projectname}/${version}" + $err "${PWD}: cannot git-tag ${projectname}/${version}" } excmd() { lbmkcmd="${buildpath}/${option}" - [ -f "${lbmkcmd}" ] || fail "Invalid command. Run: ${linkpath} help" - shift 1; "$lbmkcmd" $@ || fail "excmd: ${lbmkcmd} ${@}" + [ -f "${lbmkcmd}" ] || $err "Invalid command. Run: ${linkpath} help" + shift 1; "$lbmkcmd" $@ || $err "excmd: ${lbmkcmd} ${@}" } usage() @@ -131,14 +132,14 @@ mkversion() lbmk_exit() { - tmp_cleanup || err "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir" + tmp_cleanup || err_ "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir" exit $1 } fail() { tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "$tmpdir" 1>&2 - err "${1}" + err_ "${1}" } tmp_cleanup() diff --git a/include/err.sh b/include/err.sh index cab81d02..5b66c999 100755 --- a/include/err.sh +++ b/include/err.sh @@ -2,19 +2,10 @@ # SPDX-FileCopyrightText: 2022, 2023 Leah Rowe version=""; versiondate=""; projectname=""; _nogit="" +err="err_" x_() { - [ $# -lt 1 ] || ${@} || err_exit err ${@} -} -xx_() { - [ $# -lt 1 ] || ${@} || err_exit fail ${@} -} - -err_exit() -{ - _fail="${1}" && shift 1 - echo "Non-zero exit: $@" - $_fail "Unhandled error" + [ $# -lt 1 ] || ${@} || $err "Unhandled non-zero exit: $@"; return 0 } check_git() @@ -30,8 +21,7 @@ check_git() git_err() { printf "You need to set git name/email, like so:\n%s\n\n" "$1" 1>&2 - fail "Git name/email not configured" || \ - err "Git name/email not configured" + $err "Git name/email not configured" } check_project() @@ -49,9 +39,8 @@ check_project() --pretty='%ct' HEAD)" || versiondate="${versiondate_}" for p in projectname version versiondate; do - eval "[ -n \"\$$p\" ] || fail \"$p unset\" || err \"$p unset\"" - p_="x_ printf \"%s\\n\" \"\$$p\" > $p" - eval "x$p_ || $p_" + eval "[ -n \"\$$p\" ] || $err \"$p unset\"" + eval "x_ printf \"%s\\n\" \"\$$p\" > $p" done export LOCALVERSION="-${projectname}-${version%%-*}" } @@ -59,7 +48,7 @@ check_project() setvars() { _setvars="" - [ $# -lt 2 ] && err "setvars: too few arguments" + [ $# -lt 2 ] && $err "setvars: too few arguments" val="${1}" && shift 1 for var in $@; do _setvars="${var}=\"${val}\"; ${_setvars}" @@ -67,7 +56,7 @@ setvars() printf "%s\n" "${_setvars% }" } -err() +err_() { printf "ERROR %s: %s\n" "${0}" "${1}" 1>&2 exit 1 diff --git a/include/git.sh b/include/git.sh index 1fb8046d..5c456706 100755 --- a/include/git.sh +++ b/include/git.sh @@ -29,7 +29,7 @@ fetch_from_upstream() fetch_config() { - rm -f "${cfgsdir}/"*/seen || err "fetch_config ${cfgsdir}: !rm seen" + rm -f "${cfgsdir}/"*/seen || $err "fetch_config ${cfgsdir}: !rm seen" eval "$(setvars "" xtree tree_depend)" while true; do eval "$(setvars "" rev tree)" @@ -44,12 +44,12 @@ fetch_config() load_target_config() { - [ -f "$cfgsdir/$1/target.cfg" ] || err "$1: target.cfg missing" + [ -f "$cfgsdir/$1/target.cfg" ] || $err "$1: target.cfg missing" [ -f "${cfgsdir}/${1}/seen" ] && \ - err "${_xm} check: infinite loop in tree definitions" + $err "${_xm} check: infinite loop in tree definitions" - . "$cfgsdir/$1/target.cfg" || err "load_target_config !$cfgsdir/$1" - touch "$cfgsdir/$1/seen" || err "load_config $cfgsdir/$1: !mk seen" + . "$cfgsdir/$1/target.cfg" || $err "load_target_config !$cfgsdir/$1" + touch "$cfgsdir/$1/seen" || $err "load_config $cfgsdir/$1: !mk seen" } prepare_new_tree() @@ -57,7 +57,7 @@ prepare_new_tree() printf "Creating %s tree %s (%s)\n" "$project" "$tree" "$_target" cp -R "src/${project}/${project}" "${tmpgit}" || \ - err "prepare_new_tree ${project}/${tree}: can't make tmpclone" + $err "prepare_new_tree ${project}/${tree}: can't make tmpclone" git_prep "$PWD/$cfgsdir/$tree/patches" "src/$project/$tree" "update" } @@ -65,15 +65,15 @@ fetch_project_repo() { eval "$(setvars "" xtree tree_depend)" - scan_config "${project}" "config/git" "err" - [ -z "${loc+x}" ] && err "fetch_project_repo $project: loc not set" - [ -z "${url+x}" ] && err "fetch_project_repo $project: url not set" + scan_config "${project}" "config/git" + [ -z "${loc+x}" ] && $err "fetch_project_repo $project: loc not set" + [ -z "${url+x}" ] && $err "fetch_project_repo $project: url not set" clone_project [ -z "${depend}" ] || for d in ${depend} ; do x_ ./update trees -f ${d} done - rm -Rf "${tmpgit}" || err "fetch_repo: !rm -Rf ${tmpgit}" + rm -Rf "${tmpgit}" || $err "fetch_repo: !rm -Rf ${tmpgit}" } clone_project() @@ -86,7 +86,7 @@ clone_project() fi git clone $url "$tmpgit" || git clone $bkup_url "$tmpgit" \ - || err "clone_project: could not download ${project}" + || $err "clone_project: could not download ${project}" git_prep "$PWD/config/$project/patches" "$loc" } @@ -95,26 +95,26 @@ git_prep() _patchdir="$1" _loc="$2" - [ -z "${rev+x}" ] && err "git_prep $_loc: rev not set" - git -C "$tmpgit" reset --hard $rev || err "git -C $_loc: !reset $rev" - git_am_patches "$tmpgit" "$_patchdir" || err "!am $_loc $_patchdir" + [ -z "${rev+x}" ] && $err "git_prep $_loc: rev not set" + git -C "$tmpgit" reset --hard $rev || $err "git -C $_loc: !reset $rev" + git_am_patches "$tmpgit" "$_patchdir" || $err "!am $_loc $_patchdir" if [ "$project" != "coreboot" ] || [ $# -gt 2 ]; then [ ! -f "$tmpgit/.gitmodules" ] || git -C "$tmpgit" submodule \ - update --init --checkout || err "git_prep $_loc: !submod" + update --init --checkout || $err "git_prep $_loc: !submod" if [ "$project" = "coreboot" ] && [ -n "$xtree" ] && \ [ "$xtree" != "$tree" ]; then ( - cd "$tmpgit/util" || err "prep $_loc: !cd $tmpgit/util" - rm -Rf crossgcc || err "prep $_loc: !rm xgcc" + cd "$tmpgit/util" || $err "prep $_loc: !cd $tmpgit/util" + rm -Rf crossgcc || $err "prep $_loc: !rm xgcc" ln -s "../../$xtree/util/crossgcc" crossgcc || \ - err "prep $_loc: can't create xgcc symlink" - ) || err "prep $_loc: can't create xgcc symlink" + $err "prep $_loc: can't create xgcc symlink" + ) || $err "prep $_loc: can't create xgcc symlink" fi fi [ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}" - mv "$tmpgit" "$_loc" || err "git_prep: !mv $tmpgit $_loc" + mv "$tmpgit" "$_loc" || $err "git_prep: !mv $tmpgit $_loc" [ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \ x_ ./update project trees -f coreboot "$xtree"; return 0 } @@ -123,7 +123,7 @@ git_am_patches() { for _patch in "$2/"*; do [ -L "$_patch" ] || [ ! -f "$_patch" ] || git -C "$1" am \ - "$_patch" || err "git_am $1 $2: !git am $_patch"; continue + "$_patch" || $err "git_am $1 $2: !git am $_patch"; continue done for _patches in "$2/"*; do [ ! -L "$_patches" ] && [ -d "$_patches" ] && \ diff --git a/include/mrc.sh b/include/mrc.sh index 32c68a83..901a3c3b 100755 --- a/include/mrc.sh +++ b/include/mrc.sh @@ -14,7 +14,7 @@ extract_ref() # but refcode is downloaded alongside mrc. in cases where lbmk # erred, downloading only mrc, we must ensure downloading refcode [ -n "$CONFIG_MRC_FILE" ] || \ - err "extract_ref $board: CONFIG_MRC_FILE not defined" + $err "extract_ref $board: CONFIG_MRC_FILE not defined" # the extract_mrc function actually downloads the refcode fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE" @@ -22,9 +22,9 @@ extract_ref() extract_mrc() { - [ -z "$MRC_board" ] && err "extract_mrc $MRC_hash: MRC_board not set" + [ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set" [ -z "${CONFIG_MRC_FILE}" ] && \ - err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set" + $err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set" SHELLBALL="chromeos-firmwareupdate-${MRC_board}" @@ -32,10 +32,10 @@ extract_mrc() x_ cd "${appdir}" extract_partition "${MRC_url##*/}" extract_archive "${SHELLBALL}" . - ) || err "mrc download/extract failure" + ) || $err "mrc download/extract failure" "${cbfstool}" "${appdir}/"bios.bin extract -n mrc.bin \ - -f "$_dest" -r RO_SECTION || err "extract_mrc: cbfstool $_dest" + -f "$_dest" -r RO_SECTION || $err "extract_mrc: cbfstool $_dest" [ -n "$CONFIG_REFCODE_BLOB_FILE" ] && extract_refcode; return 0 } @@ -51,10 +51,10 @@ extract_partition() dd if="${1%.zip}" of="root-a.ext2" bs=1024 \ skip=$(( ${START} / 1024 )) count=$(( ${SIZE} / 1024 )) || \ - err "extract_partition, dd ${1%.zip}, root-a.ext2" + $err "extract_partition, dd ${1%.zip}, root-a.ext2" printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \ - | debugfs "root-a.ext2" || err "can't extract shellball" + | debugfs "root-a.ext2" || $err "can't extract shellball" } extract_refcode() @@ -66,16 +66,16 @@ extract_refcode() # incompatible with older versions before coreboot 4.14, # so we need coreboot 4.13 cbfstool for certain refcode files [ -n "$cbfstoolref" ] || \ - err "extract_refcode $board: MRC_refcode_cbtree not set" + $err "extract_refcode $board: MRC_refcode_cbtree not set" mkdir -p "${_refdest%/*}" || \ - err "extract_refcode $board: !mkdir -p ${_refdest%/*}" + $err "extract_refcode $board: !mkdir -p ${_refdest%/*}" "$cbfstoolref" "$appdir/bios.bin" extract \ -m x86 -n fallback/refcode -f "$_refdest" -r RO_SECTION \ - || err "extract_refcode $board: !cbfstoolref $_refdest" + || $err "extract_refcode $board: !cbfstoolref $_refdest" # enable the Intel GbE device, if told by offset MRC_refcode_gbe [ -z "$MRC_refcode_gbe" ] || dd if="config/ifd/hp820g2/1.bin" \ of="$_refdest" bs=1 seek=$MRC_refcode_gbe count=1 conv=notrunc || \ - err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0 + $err "extract_refcode $_refdest: byte $MRC_refcode_gbe"; return 0 } diff --git a/include/option.sh b/include/option.sh index 2284fb0b..64442d15 100755 --- a/include/option.sh +++ b/include/option.sh @@ -43,10 +43,9 @@ scan_config() { awkstr=" /\{.*${1}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }" confdir="${2}" - _fail="${3}" revfile="$(mktemp -t sources.XXXXXXXXXX)" cat "${confdir}/"* > "${revfile}" || \ - "${_fail}" "scan_config ${confdir}: Cannot concatenate files" + $err "scan_config ${confdir}: Cannot concatenate files" while read -r line ; do set ${line} 1>/dev/null 2>/dev/null || : if [ "${1%:}" = "depend" ]; then @@ -57,7 +56,7 @@ scan_config() done << EOF $(eval "awk '${awkstr}' \"${revfile}\"") EOF - rm -f "$revfile" || "$_fail" "scan_config: Cannot remove tmpfile" + rm -f "$revfile" || $err "scan_config: Cannot remove tmpfile" } check_defconfig() @@ -81,6 +80,6 @@ handle_coreboot_utils() remkdir() { - rm -Rf "${1}" || err "remkdir: !rm -Rf \"${1}\"" - mkdir -p "${1}" || err "remkdir: !mkdir -p \"${1}\"" + rm -Rf "${1}" || $err "remkdir: !rm -Rf \"${1}\"" + mkdir -p "${1}" || $err "remkdir: !mkdir -p \"${1}\"" } diff --git a/script/build/roms b/script/build/roms index 9e7c69ee..a90e1daa 100755 --- a/script/build/roms +++ b/script/build/roms @@ -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) diff --git a/script/build/serprog b/script/build/serprog index 8b003add..ea2c02bf 100755 --- a/script/build/serprog +++ b/script/build/serprog @@ -17,8 +17,8 @@ usage="usage: ./build firmware serprog [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 $@ diff --git a/script/update/release b/script/update/release index 357840c2..c4101b5a 100755 --- a/script/update/release +++ b/script/update/release @@ -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 $@ diff --git a/script/update/trees b/script/update/trees index 51ea821c..40ff1878 100755 --- a/script/update/trees +++ b/script/update/trees @@ -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() diff --git a/script/vendor/download b/script/vendor/download index 42cb16ab..b40810cc 100755 --- a/script/vendor/download +++ b/script/vendor/download @@ -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 $@ diff --git a/script/vendor/inject b/script/vendor/inject index 4ac2753f..dc12d7b5 100755 --- a/script/vendor/inject +++ b/script/vendor/inject @@ -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 } -- cgit v1.2.1