diff options
author | Leah Rowe <leah@libreboot.org> | 2023-08-23 19:56:01 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-08-23 21:34:02 +0100 |
commit | 4c6c7d1088eb9dc0c9b2eeeb64febeeb78038583 (patch) | |
tree | 1966a4f85069b3dd3e214d9724dcc0f059d1e6de /resources | |
parent | 52f3fd359e04caf9dd7bc89889dfc326f5ae9352 (diff) |
scripts: never exit 1, always call err instead
this same change has been applied, selectively, to
certain return statements. the general rule is this:
the return statement should only be used to direct
logic within a script, where certain non-errors
states are used to skip certain actions; the exit
command should *never* be used to return non-zero,
except by err(). in so doing, we ensure easier
debugging of the build system
also: strip_rom_image in build/release/roms was
running "continue" when a rom file didn't exist,
despite not being a while/for loop. i make it
return (non-error condition) instead
it's ok for a script to exit 0, where appropriate,
but perhaps a function could also be written for it
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'resources')
-rwxr-xr-x | resources/scripts/build/boot/roms | 2 | ||||
-rwxr-xr-x | resources/scripts/build/boot/roms_helper | 53 | ||||
-rwxr-xr-x | resources/scripts/build/clean/seabios | 6 | ||||
-rwxr-xr-x | resources/scripts/build/coreboot/utils | 6 | ||||
-rwxr-xr-x | resources/scripts/build/grub/utils | 2 | ||||
-rwxr-xr-x | resources/scripts/build/release/roms | 28 | ||||
-rwxr-xr-x | resources/scripts/handle/config/file | 10 | ||||
-rwxr-xr-x | resources/scripts/update/blobs/download | 10 | ||||
-rwxr-xr-x | resources/scripts/update/blobs/inject | 52 | ||||
-rwxr-xr-x | resources/scripts/update/blobs/mrc | 23 |
10 files changed, 103 insertions, 89 deletions
diff --git a/resources/scripts/build/boot/roms b/resources/scripts/build/boot/roms index f634918e..966750a2 100755 --- a/resources/scripts/build/boot/roms +++ b/resources/scripts/build/boot/roms @@ -38,7 +38,7 @@ firstoption="" main() { - [ $# -lt 1 ] && usage && exit 1 + [ $# -lt 1 ] && usage && err "target not specified" firstoption="${1}" [ "${firstoption}" = "help" ] && usage && exit 0 diff --git a/resources/scripts/build/boot/roms_helper b/resources/scripts/build/boot/roms_helper index 462b9403..6136e708 100755 --- a/resources/scripts/build/boot/roms_helper +++ b/resources/scripts/build/boot/roms_helper @@ -115,10 +115,7 @@ if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] && \ [ "${payload_uboot}" != "y" ]; then for configfile in "resources/coreboot/${board}/config/"*; do [ ! -e "${configfile}" ] && continue - printf "ERROR build/roms: Target '%s' defines no payload. " \ - ${board} - printf "Exiting.\n" - exit 1 + err "target '${board}' defines no payload" done fi @@ -155,7 +152,7 @@ cbfstool="cbutils/${tree}/cbfstool" corebootrom="${cbdir}/build/coreboot.rom" seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin" -./build coreboot utils ${tree} || exit 1 +./build coreboot utils ${tree} || err "cannot build cbutils/${tree}" if [ ! -f "${seavgabiosrom}" ] \ || [ ! -f elf/seabios/default/libgfxinit/bios.bin.elf ] \ @@ -275,16 +272,18 @@ moverom() { if [ "${microcode_required}" = "n" ]; then _newrom_b="${newrompath%.rom}_nomicrocode.rom" - cp "${newrompath}" "${_newrom_b}" || exit 1 + cp "${newrompath}" "${_newrom_b}" || \ + err "cannot do: cp \"${newrompath}\" \"${_newrom_b}\"" microcode_present="y" "${cbfstool}" "${_newrom_b}" remove -n \ cpu_microcode_blob.bin || microcode_present="n" if [ "${microcode_present}" = "n" ]; then - rm -f "${_newrom_b}" || exit 1 + rm -f "${_newrom_b}" || err "cannot remove ${_newrom_b}" printf "REMARK: '%s' already lacks microcode\n" \ ${newrompath} printf "Renaming default ROM file instead.\n" - mv "${newrompath}" "${_newrom_b}" || exit 1 + mv "${newrompath}" "${_newrom_b}" || \ + err "fail: mv \"${newrompath}\" \"${_newrom_b}\"" fi fi } @@ -303,26 +302,30 @@ mkSeabiosRom() { cp "${target_cbrom}" "${tmprom}" "${cbfstool}" "${tmprom}" add-payload -f "${target_seabioself}" \ - -n ${target_seabios_cbfs_path} -c lzma || exit 1 + -n ${target_seabios_cbfs_path} -c lzma || \ + err "cannot add payload, ${target_seabioself}, to tmprom, ${tmprom}" "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup \ - || exit 1 + || err "cannot add-int etc/ps2-keyboard-spinup to tmprom, ${tmprom}" if [ "${target_initmode}" = "normal" ] || \ [ "${target_initmode}" = "libgfxinit" ]; then "${cbfstool}" "${tmprom}" add-int -i 2 \ - -n etc/pci-optionrom-exec || exit 1 + -n etc/pci-optionrom-exec || \ + err "cannot add-int etc/pci-optionrom-exec 2 to tmprom" elif [ "${target_initmode}" = "vgarom" ]; then # coreboot executes it "${cbfstool}" "${tmprom}" add-int -i 0 \ - -n etc/pci-optionrom-exec || exit 1 + -n etc/pci-optionrom-exec || \ + err "cannot add-int etc/pci-optionrom-exec 0 to tmprom" fi # for undefined modes, don't add this integer. use SeaBIOS defaults "${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum || \ - exit 1 + err "cannot add-int etc/optionroms-checksum 0 to tmprom" [ "${target_initmode}" != "libgfxinit" ] || \ "${cbfstool}" "${tmprom}" add -f "${seavgabiosrom}" \ - -n vgaroms/seavgabios.bin -t raw || exit 1 + -n vgaroms/seavgabios.bin -t raw || \ + err "cannot add vgaroms/seavgabios.bin to tmprom" printf "%s\n" "${tmprom}" } @@ -346,7 +349,8 @@ mkUbootRom() { cp "${target_cbrom}" "${tmprom}" "${cbfstool}" "${tmprom}" add-payload -f "${target_ubootelf}" \ - -n ${target_uboot_cbfs_path} -c lzma || exit 1 + -n ${target_uboot_cbfs_path} -c lzma || \ + err "cannot add u-boot to tmprom" printf "%s\n" "${tmprom}" } @@ -361,11 +365,14 @@ mkGrubRom() { grubcfg="elf/grub/grub_${target_keymap}.cfg" grubtestcfg="elf/grub/grub_${target_keymap}_test.cfg" - tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || exit 1 - cp "${target_cbrom}" "${tmprom}" || exit 1 + tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || \ + err "mkGrubRom: cannot create tmprom" + cp "${target_cbrom}" "${tmprom}" || \ + err "mkGrubRom: cannot copy to tmprom" "${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" \ - -n ${target_grubelf_cbfs_path} -c lzma || exit 1 + -n ${target_grubelf_cbfs_path} -c lzma || \ + err "mkGrubRom: cannot add grub payload to tmprom" tmpgrubcfg=$(mktemp -t grub.cfg.XXXXXXXXXX) tmpgrubtestcfg=$(mktemp -t grubtest.cfg.XXXXXXXXXX) @@ -389,10 +396,10 @@ mkGrubRom() { fi "${cbfstool}" "${tmprom}" add -f "${tmpgrubcfg}" -n grub.cfg -t raw || \ - exit 1 + err "mkGrubRom: cannot add grub.cfg to tmprom" "${cbfstool}" "${tmprom}" add -f "${tmpgrubtestcfg}" -n grubtest.cfg \ - -t raw || exit 1 + -t raw || err "mkGrubRom: cannot add grubtest.cfg to tmprom" rm -f "${tmpgrubcfg}" "${tmpgrubtestcfg}" backgroundfile="background1280x800.png" @@ -402,7 +409,7 @@ mkGrubRom() { fi backgroundfile="resources/grub/background/${backgroundfile}" "${cbfstool}" "${tmprom}" add -f ${backgroundfile} -n background.png \ - -t raw || exit 1 + -t raw || err "mkGrubRom: cannot add background.png to tmprom" printf "%s\n" "${tmprom}" } @@ -491,8 +498,8 @@ mkRoms() if [ "${payload_memtest}" = "y" ]; then "${cbfstool}" "${corebootrom}" add-payload \ - -f ${memtest_bin} -n img/memtest \ - -c lzma || exit 1 + -f ${memtest_bin} -n img/memtest -c lzma || \ + err "mkRoms: cannot add img/memtest to coreboot rom" fi if [ "${payload_seabios}" = "y" ]; then diff --git a/resources/scripts/build/clean/seabios b/resources/scripts/build/clean/seabios index b8b17068..e9b11e5b 100755 --- a/resources/scripts/build/clean/seabios +++ b/resources/scripts/build/clean/seabios @@ -21,16 +21,18 @@ [ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e +. "include/err.sh" + # clean bucts # -------------------------------------------------------- printf "Cleaning the previous builds of seabios\n" -rm -Rf elf/seabios || exit 1 +[ ! -d "elf/seabios" ] || rm -Rf elf/seabios || err "cannot remove elf/seabios" [ ! -d "seabios/" ] && exit 0 for x in seabios/*; do [ "${x}" = "seabios/seabios" ] && continue [ ! -d "${x}" ] && continue - make -C "${x}" distclean || exit 1 + make -C "${x}" distclean || err "cannot distclean tree, ${x}" done diff --git a/resources/scripts/build/coreboot/utils b/resources/scripts/build/coreboot/utils index a21da691..e24378d3 100755 --- a/resources/scripts/build/coreboot/utils +++ b/resources/scripts/build/coreboot/utils @@ -27,12 +27,14 @@ main() { if [ $# -gt 0 ]; then for board in "${@}"; do - build_for_mainboard ${board} || exit 1 + build_for_mainboard ${board} || \ + err "cannot build cbutils for target, ${board}" done else for boarddir in resources/coreboot/*; do [ ! -d "${boarddir}" ] && continue - build_for_mainboard ${boarddir##*/} || exit 1 + build_for_mainboard ${boarddir##*/} || \ + err "cannot build cbutils for target, ${board}" done fi } diff --git a/resources/scripts/build/grub/utils b/resources/scripts/build/grub/utils index dbe14bc0..3ef78227 100755 --- a/resources/scripts/build/grub/utils +++ b/resources/scripts/build/grub/utils @@ -27,7 +27,7 @@ set -u -e main() { printf "Building GRUB\n" - [ -d "grub/" ] || ./fetch grub || exit 1 + [ -d "grub/" ] || ./fetch grub || err "cannot fetch grub" build_grub } diff --git a/resources/scripts/build/release/roms b/resources/scripts/build/release/roms index 2f9524c5..8afba9bf 100755 --- a/resources/scripts/build/release/roms +++ b/resources/scripts/build/release/roms @@ -116,8 +116,10 @@ strip_archive() romdir=${1} [ -d coreboot/${tree} ] || \ - ./fetch_trees coreboot ${tree} || exit 1 - ./build coreboot utils ${tree} || exit 1 + ./fetch_trees coreboot ${tree} || \ + err "cannot fetch source tree, coreboot/${tree}" + ./build coreboot utils ${tree} || \ + err "cannot build utils for coreboot/${tree}" rm -Rf "${romdir}_tmp" # dirty hack, to reduce disk io later # rather than using /tmp, which might not be tmpfs @@ -141,30 +143,36 @@ strip_rom_image() { romfile=${1} - [ -f "${romfile}" ] || continue + [ -f "${romfile}" ] || return 0 if [ "${CONFIG_HAVE_ME_BIN}" = "y" ]; then - ${ifdtool} --nuke me "${romfile}" || exit 1 + ${ifdtool} --nuke me "${romfile}" || \ + err "cannot nuke Intel ME region on file, ${romfile}" mv "${romfile}" "${romdir}_tmp"/ mv "${romfile}.new" "${romfile}" fi if [ "${CONFIG_HAVE_MRC}" = "y" ]; then - ${cbfstool} "${romfile}" remove -n mrc.bin || exit 1 - ${cbfstool} "${romfile}" print + ${cbfstool} "${romfile}" remove -n mrc.bin || \ + err "cannot remove mrc.bin from file, ${romfile}" + ${cbfstool} "${romfile}" print || : fi if [ "${CONFIG_KBC1126_FIRMWARE}" = "y" ]; then - ${cbfstool} "${romfile}" remove -n ecfw1.bin || exit 1 - ${cbfstool} "${romfile}" remove -n ecfw2.bin || exit 1 + ${cbfstool} "${romfile}" remove -n ecfw1.bin || \ + err "cannot remove ecfw1.bin from file, ${romfile}" + ${cbfstool} "${romfile}" remove -n ecfw2.bin || \ + err "cannot remove ecfw2.bin from file, ${romfile}" fi [ "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" != "y" ] || \ - ${cbfstool} "${romfile}" remove -n sch5545_ecfw.bin || exit 1 + ${cbfstool} "${romfile}" remove -n sch5545_ecfw.bin || \ + err "cannot remove sch5545_ecfw.bin from file, ${romfile}" # TODO: replace this board-specific hack [ "${target}" != "e6400nvidia_4mb" ] || \ - ${cbfstool} "${romfile}" remove -n "pci10de,06eb.rom" || exit 1 + ${cbfstool} "${romfile}" remove -n "pci10de,06eb.rom" || \ + err "cannot remove pci10de,06eb.rom from file, ${romfile}" } main $@ diff --git a/resources/scripts/handle/config/file b/resources/scripts/handle/config/file index f488dccb..6dc0dbeb 100755 --- a/resources/scripts/handle/config/file +++ b/resources/scripts/handle/config/file @@ -93,7 +93,7 @@ main() "${mode}" "${project}" "${target}" [ "${project}" != "coreboot" ] || [ "${mode}" != "all" ] || \ ./update blobs download ${target} || fail "blobutil" - handle_defconfig || exit 1 + handle_defconfig || err "error handling config file" done [ "${mode}" = "all" ] && \ @@ -102,10 +102,11 @@ main() handle_defconfig() { - handle_dependencies "${target}" || return 1 + handle_dependencies "${target}" || \ + fail "handle_defconfig: failed call to handle_dependencies" for y in "${target_dir}/config"/*; do - [ ! -f "${y}" ] && continue + [ -f "${y}" ] || continue config="${y}" config_name="${config#$target_dir/config/}" @@ -139,7 +140,8 @@ handle_dependencies() codedir="${project}/${tree}" [ -d "${codedir}" ] || \ - ./fetch_trees "${project}" "$target" || exit 1 + ./fetch_trees "${project}" "$target" || \ + fail "cannot fetch source tree, ${project}/${target}" # u-boot and coreboot are both compiled with coreboot's crossgcc if [ "${project}" = "coreboot" ] || [ "${project}" = "u-boot" ]; then diff --git a/resources/scripts/update/blobs/download b/resources/scripts/update/blobs/download index 9d623604..c1babd13 100755 --- a/resources/scripts/update/blobs/download +++ b/resources/scripts/update/blobs/download @@ -237,7 +237,7 @@ bruteforce_extract_blob_intel_me() ( printf "Entering %s\n" "${cdir}" - cd "${cdir}" || exit 1 + cd "${cdir}" || err "cannot enter directory, ${cdir}" for i in *; do if [ -f "${_me_destination}" ]; then # me.bin found, so avoid needless further traversal @@ -406,7 +406,8 @@ extract_sch5545ec() mkdir -p "${appdir}/" cp "${dl_path}" "${appdir}/" - python "${pfs_extract}" "${appdir}/${dlsum}" -e || exit 1 + python "${pfs_extract}" "${appdir}/${dlsum}" -e || \ + err "cannot extract archive (dell, sch5545)" # full system ROM (UEFI), to extract with UEFIExtract: _bios="${appdir}/${dlsum}_extracted/Firmware" @@ -418,9 +419,10 @@ extract_sch5545ec() _sch5545ec_fw="${_sch5545ec_fw}/0 Raw section/body.bin" # <-- this! # this makes the file defined by _sch5545ec_fw available to copy - "${uefiextract}" "${_bios}" || exit 1 + "${uefiextract}" "${_bios}" || err "cannot extract dell uefi image" - cp "${_sch5545ec_fw}" "${_sch5545ec_destination}" || exit 1 + cp "${_sch5545ec_fw}" "${_sch5545ec_destination}" || \ + err "cannot copy sch5545ec firmware file" } fetch_update() diff --git a/resources/scripts/update/blobs/inject b/resources/scripts/update/blobs/inject index 496d845c..a6f6c007 100755 --- a/resources/scripts/update/blobs/inject +++ b/resources/scripts/update/blobs/inject @@ -74,17 +74,16 @@ check_board() { if ! check_release ${archive} ; then [ -f "${rom}" ] || \ - err "${rom} is not a valid path" + err "\"${rom}\" is not a valid path" [ -z ${rom+x} ] && \ - err 'no rom specified' + err "no rom specified" [ ! -z ${board+x} ] || \ board=$(detect_board ${rom}) || \ - err 'no board specified' + err "no board specified" else release=true releasearchive="${archive}" - board=$(detect_board ${archive}) || \ - err 'Could not detect board type' + board=$(detect_board ${archive}) fi boarddir="${cbcfgsdir}/${board}" @@ -113,9 +112,10 @@ detect_board() _stripped_prefix=${filename#*_} board="${_stripped_prefix%.tar.xz}" ;; *) - return 1 + err "detect_board: could not detect board type" esac - [ -d "${boarddir}/" ] || return 1 + [ -d "${boarddir}/" ] || \ + err "detect_board: dir, ${boarddir}, doesn't exist" printf '%s\n' "${board}" } @@ -216,7 +216,7 @@ inject_blob_intel_mrc() # TODO: this logic should be tweaked to handle more platforms ${cbfstool} ${rom} add -f mrc/haswell/mrc.bin -n mrc.bin -t mrc \ - -b 0xfffa0000 || exit 1 + -b 0xfffa0000 || err "cannot insert mrc.bin" } inject_blob_intel_me() @@ -231,7 +231,8 @@ inject_blob_intel_me() [ ! -f "${_me_location}" ] && \ err "CONFIG_ME_BIN_PATH points to missing file" - ${ifdtool} -i me:${_me_location} ${rom} -O ${rom} || exit 1 + ${ifdtool} -i me:${_me_location} ${rom} -O ${rom} || \ + err "cannot insert me.bin" } inject_blob_hp_kbc1126_ec() @@ -246,24 +247,19 @@ inject_blob_hp_kbc1126_ec() 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 + err "EC offsets not declared for board, ${board}" fi if [ "${_ec1_location}" = "" ] || [ "${_ec2_location}" = "" ]; then - printf "EC firmware path not declared for board: %s\n" \ - "${board}" + err "EC firmware path not declared for board, ${board}" fi if [ ! -f "${_ec1_location}" ] || [ ! -f "${_ec2_location}" ]; then - printf "EC firmware not downloaded for board: %s\n" \ - "${board}" - exit 1 + err "EC firmware not downloaded for board: ${board}" fi ${cbfstool} "${rom}" add -f ${_ec1_location} -n ecfw1.bin \ - -b ${_ec1_offset} -t raw || exit 1 + -b ${_ec1_offset} -t raw || err "cannot insert ecfw1.bin" ${cbfstool} "${rom}" add -f ${_ec2_location} -n ecfw2.bin \ - -b ${_ec2_offset} -t raw || exit 1 + -b ${_ec2_offset} -t raw || err "cannot insert ecfw2.bin" } inject_blob_dell_e6400_vgarom_nvidia() @@ -277,17 +273,15 @@ inject_blob_dell_e6400_vgarom_nvidia() printf "adding pci option rom\n" if [ "${_vga_dir}" != "${pciromsdir}" ]; then - printf "Invalid PCI ROM directory: %s\n" ${_vga_dir} - exit 1 + err "Invalid PCI ROM directory, ${_vga_dir}" fi if [ ! -f "${_vga_location}" ]; then - printf "No such file exists: %s\n" ${_vga_location} - exit 1 + err "No such file exists, ${_vga_location}" fi ${cbfstool} ${rom} add -f "${_vga_location}" \ - -n "pci${CONFIG_VGA_BIOS_ID}.rom" \ - -t optionrom || exit 1 + -n "pci${CONFIG_VGA_BIOS_ID}.rom" -t optionrom || \ + err "cannot insert e6400 nvidia rom" } inject_blob_smsc_sch5545_ec() @@ -297,12 +291,11 @@ inject_blob_smsc_sch5545_ec() _sch5545ec_location="${CONFIG_SMSC_SCH5545_EC_FW_FILE#../../}" if [ ! -f "${_sch5545ec_location}" ]; then - printf "SCH5545 firmware file missing\n" 1>&2 - exit 1 + err "SCH5545 firmware file missing" fi "${cbfstool}" "${rom}" add -f "${_sch5545ec_location}" \ - -n sch5545_ecfw.bin -t raw || exit 1 + -n sch5545_ecfw.bin -t raw || err "cannot insert sch5545_ecfw.bin" } modify_gbe() @@ -326,7 +319,8 @@ modify_gbe() ${nvmutil} "${_gbe_tmp}" setmac ${new_mac} || \ err 'failed to modify mac address' - ${ifdtool} -i GbE:${_gbe_tmp} "${rom}" -O "${rom}" || exit 1 + ${ifdtool} -i GbE:${_gbe_tmp} "${rom}" -O "${rom}" || \ + err "cannot insert modified gbe.bin" rm -f ${_gbe_tmp} } diff --git a/resources/scripts/update/blobs/mrc b/resources/scripts/update/blobs/mrc index b4502c14..57cbede6 100755 --- a/resources/scripts/update/blobs/mrc +++ b/resources/scripts/update/blobs/mrc @@ -53,33 +53,33 @@ main() sname=${0} printf "Downloading Intel MRC blobs\n" - check_existing && exit 0 - build_dependencies || err "could not build dependencies" + check_existing || return 0 + build_dependencies fetch_mrc || err "could not fetch mrc.bin" } check_existing() { [ -f ${_mrc_complete} ] || \ - return 1 + return 0 printf 'found existing mrc.bin\n' [ "$(sha1sum ${_mrc_complete} | awk '{print $1}')" \ = "${_mrc_complete_hash}" ] && \ - return 0 + return 1 printf 'hashes did not match, starting over\n' - return 1 } build_dependencies() { - [ -d "${cbdir}/" ] || ./fetch_trees coreboot default || return 1 - ./build coreboot utils default || return 1 - return 0 + [ -d "${cbdir}/" ] || ./fetch_trees coreboot default || \ + err "cannot fetch coreboot/default" + ./build coreboot utils default || \ + err "cannot build cbutils/default" } fetch_mrc() { - mkdir -p mrc/haswell/ || return 1 + mkdir -p mrc/haswell/ || err "cannot mkdir mrc/haswell" ( cd mrc/haswell/ @@ -102,8 +102,6 @@ fetch_mrc() printf "\n\nmrc.bin saved to ${_mrc_complete}\n\n" ) - - return 0 } download_image() @@ -122,8 +120,7 @@ download_image() return 0 fi rm "${_file}.zip" - printf "Bad checksum. Recovery image deleted.\n" - return 1 + err "Bad checksum. Recovery image deleted" } extract_partition() |