error handling code cleanup and fixes

in some cases, use of x_ or xx_ can be error-prone,
due to the way $@ is handled; commands requiring
quotes, or with funny file names as arguments such
as spaces in the file name, or other special
characters, can make the x/xx functions break.

in those cases, where x/xx must not be used, the
commands use || err instead

in other cases, use of x/xx is superfluous, and has
been removed in some commands.

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-10-20 04:10:50 +01:00
parent 4e54a051ef
commit 6af65ad430
5 changed files with 48 additions and 47 deletions

View File

@ -24,7 +24,7 @@ fetch_from_upstream()
[ -d "src/${project}/${project}" ] && return 0 [ -d "src/${project}/${project}" ] && return 0
x_ mkdir -p "src/${project}" x_ mkdir -p "src/${project}"
x_ fetch_project_repo "${project}" fetch_project_repo "${project}"
} }
fetch_config() fetch_config()
@ -57,14 +57,13 @@ prepare_new_tree()
printf "Creating %s tree %s (%s)\n" "${project}" "${tree}" "${_target}" printf "Creating %s tree %s (%s)\n" "${project}" "${tree}" "${_target}"
x_ cp -R "src/${project}/${project}" "src/${project}/${tree}" x_ cp -R "src/${project}/${project}" "src/${project}/${tree}"
x_ git_reset_rev "src/${project}/${tree}" "${rev}" git_reset_rev "src/${project}/${tree}" "${rev}"
( (
x_ cd "src/${project}/${tree}" x_ cd "src/${project}/${tree}"
git submodule update --init --checkout || \ git submodule update --init --checkout || \
err "prepare_new_tree ${project}/${tree}: can't update git modules" err "prepare_new_tree ${project}/${tree}: can't update git modules"
) )
git_am_patches "${PWD}/src/${project}/${tree}" \ git_am_patches "$PWD/src/$project/$tree" "$PWD/$cfgsdir/$tree/patches"
"${PWD}/${cfgsdir}/${tree}/patches"
} }
fetch_project_repo() fetch_project_repo()
@ -76,7 +75,7 @@ fetch_project_repo()
[ -z "${depend}" ] || for d in ${depend} ; do [ -z "${depend}" ] || for d in ${depend} ; do
x_ ./update trees -f ${d} x_ ./update trees -f ${d}
done done
x_ rm -Rf "${tmp_git_dir}" rm -Rf "${tmp_git_dir}" || err "fetch_repo: !rm -Rf ${tmp_git_dir}"
} }
verify_config() verify_config()
@ -89,8 +88,9 @@ verify_config()
clone_project() clone_project()
{ {
x_ rm -Rf "${tmp_git_dir}" rm -Rf "${tmp_git_dir}" || err "clone_project: !rm -Rf ${tmp_git_dir}"
x_ mkdir -p "${tmp_git_dir%/*}" mkdir -p "${tmp_git_dir%/*}" || \
err "clone_project: !mkdir -p ${tmp_git_dir%/*}"
loc="${loc#src/}" loc="${loc#src/}"
loc="src/${loc}" loc="src/${loc}"
@ -98,24 +98,20 @@ clone_project()
git clone ${url} "${tmp_git_dir}" || \ git clone ${url} "${tmp_git_dir}" || \
git clone ${bkup_url} "${tmp_git_dir}" || \ git clone ${bkup_url} "${tmp_git_dir}" || \
err "clone_project: could not download ${project}" err "clone_project: could not download ${project}"
git_reset_rev "${tmp_git_dir}" "${rev}" || \ git_reset_rev "${tmp_git_dir}" "${rev}"
err "clone_project ${loc}/: cannot reset <- ${rev}" git_am_patches "${tmp_git_dir}" "${PWD}/config/${project}/patches"
git_am_patches "${tmp_git_dir}" "${PWD}/config/${project}/patches" || \
err "clone_project ${loc}/: cannot apply patches"
x_ rm -Rf "${loc}" x_ rm -Rf "${loc}"
[ "${loc}" = "${loc%/*}" ] || x_ mkdir -p ${loc%/*} [ "${loc}" = "${loc%/*}" ] || x_ mkdir -p ${loc%/*}
x_ mv "${tmp_git_dir}" "${loc}" mv "${tmp_git_dir}" "${loc}" || \
err "clone_project: !mv ${tmp_git_dir} ${loc}"
} }
git_reset_rev() git_reset_rev()
{ {
sdir="${1}"
_rev="${2}"
( (
x_ cd "${sdir}" cd "${1}" || err "git_reset_rev: !cd ${1}"
git reset --hard ${_rev} || \ git reset --hard ${2} || err "!git reset ${1} <- ${2}"
err "cannot git reset ${sdir} <- ${rev}"
) )
} }
@ -124,7 +120,7 @@ git_am_patches()
sdir="${1}" # assumed to be absolute path sdir="${1}" # assumed to be absolute path
patchdir="${2}" # ditto patchdir="${2}" # ditto
( (
x_ cd "${sdir}" cd "${sdir}" || err "git_am_patches: !cd ${sdir}"
for patch in "${patchdir}/"*; do for patch in "${patchdir}/"*; do
[ -L "${patch}" ] && continue [ -L "${patch}" ] && continue
[ -f "${patch}" ] || continue [ -f "${patch}" ] || continue
@ -136,8 +132,6 @@ git_am_patches()
) )
for patches in "${patchdir}/"*; do for patches in "${patchdir}/"*; do
[ -L "${patches}" ] && continue [ -L "${patches}" ] && continue
[ ! -d "${patches}" ] || \ [ -d "${patches}" ] && git_am_patches "${sdir}" "${patches}"
git_am_patches "${sdir}" "${patches}" err || \
err "apply_patches: !${sdir}/ ${patches}/"
done done
} }

View File

@ -67,8 +67,7 @@ handle_coreboot_utils()
x_ mkdir -p "cbutils/${1}" && \ x_ mkdir -p "cbutils/${1}" && \
x_ cp "src/coreboot/${1}/util/${util}/${util}" \ x_ cp "src/coreboot/${1}/util/${util}/${util}" \
"cbutils/${1}" "cbutils/${1}"
[ -z "${mode}" ] || \ [ -z "${mode}" ] || x_ rm -Rf "cbutils/${1}"
x_ rm -Rf "cbutils/${1}"
done done
} }

View File

@ -18,8 +18,7 @@ eval "$(setvars "" arch cfgsdir codedir config config_name crossgcc_ada mode \
main() main()
{ {
while getopts f:b:m:u:c:x:s:l:n: option while getopts f:b:m:u:c:x:s:l:n: option; do
do
_f="${1}" _f="${1}"
case "${1}" in case "${1}" in
-b) : ;; -b) : ;;
@ -38,11 +37,8 @@ main()
[ -z "${_f}" ] && err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)" [ -z "${_f}" ] && err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
[ -z "${project}" ] && err "project name not specified" [ -z "${project}" ] && err "project name not specified"
if [ ! -f "config/${project}/build.list" ]; then [ -f "config/${project}/build.list" ] && build_targets $@ && return 0
build_projects $@ build_projects $@
else
build_targets $@
fi
} }
build_projects() build_projects()
@ -209,7 +205,7 @@ check_cross_compiler()
fi fi
# we *must* ensure that u-boot's build system uses crossgcc first # we *must* ensure that u-boot's build system uses crossgcc first
export PATH="$(pwd)/${cbdir}/util/crossgcc/xgcc/bin:$PATH" export PATH="${PWD}/${cbdir}/util/crossgcc/xgcc/bin:$PATH"
} }
check_config() check_config()

View File

@ -134,7 +134,7 @@ mkdirs()
{ {
[ -f "${1}" ] && \ [ -f "${1}" ] && \
printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1 printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1
x_ mkdir -p "${1%/*}" mkdir -p "${1%/*}" || err "mkdirs: !mkdir -p ${1%/*}"
x_ rm -Rf "${appdir}" x_ rm -Rf "${appdir}"
x_ mkdir -p "${appdir}/" x_ mkdir -p "${appdir}/"
extract_archive "${_dl}" "${appdir}" || \ extract_archive "${_dl}" "${appdir}" || \
@ -190,7 +190,7 @@ extract_kbc1126ec()
mv Rompaq/68*.BIN ec.bin || : mv Rompaq/68*.BIN ec.bin || :
if [ ! -f ec.bin ]; then if [ ! -f ec.bin ]; then
unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \ unar -D ROM.CAB Rom.bin || unar -D Rom.CAB Rom.bin || \
x_ unar -D 68*.CAB Rom.bin unar -D 68*.CAB Rom.bin || err "can't extract Rom.bin"
x_ mv Rom.bin ec.bin x_ mv Rom.bin ec.bin
fi fi
[ -f ec.bin ] || err "extract_kbc1126_ec ${board}: can't extract" [ -f ec.bin ] || err "extract_kbc1126_ec ${board}: can't extract"
@ -203,7 +203,8 @@ extract_kbc1126ec()
done done
[ "${ec_ex}" = "y" ] || \ [ "${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"
x_ cp "${appdir}/"ec.bin.fw* "${_dest%/*}/" cp "${appdir}/"ec.bin.fw* "${_dest%/*}/" || \
err "extract_kbc1126_ec ${board}: can't copy ec binaries"
} }
extract_e6400vga() extract_e6400vga()
@ -221,7 +222,8 @@ extract_e6400vga()
[ -f "${E6400_VGA_romname}" ] || \ [ -f "${E6400_VGA_romname}" ] || \
err "extract_e6400vga: can't extract vga rom from bios.bin" err "extract_e6400vga: can't extract vga rom from bios.bin"
) )
x_ cp "${appdir}/${E6400_VGA_romname}" "${_dest}" cp "${appdir}/${E6400_VGA_romname}" "${_dest}" || \
err "extract_e6400vga ${board}: can't copy vga rom to ${_dest}"
} }
extract_sch5545ec() extract_sch5545ec()

34
script/vendor/inject vendored
View File

@ -78,7 +78,7 @@ detect_board()
_stripped_prefix=${filename#*_} _stripped_prefix=${filename#*_}
board="${_stripped_prefix%.tar.xz}" ;; board="${_stripped_prefix%.tar.xz}" ;;
*) *)
err "detect_board: could not detect board type" err "detect_board $filename: could not detect board type"
esac esac
[ -d "${boarddir}/" ] || \ [ -d "${boarddir}/" ] || \
err "detect_board: dir, ${boarddir}, doesn't exist" err "detect_board: dir, ${boarddir}, doesn't exist"
@ -98,7 +98,10 @@ build_dependencies()
inject_vendorfiles() inject_vendorfiles()
{ {
[ "${release}" != "y" ] && x_ patch_rom "${rom}" && return 0 if [ "${release}" != "y" ]; then
patch_rom "${rom}"
return 0
fi
printf "patching release images\n" printf "patching release images\n"
patch_release_roms patch_release_roms
} }
@ -108,11 +111,12 @@ patch_release_roms()
_tmpdir="tmp/romdir" _tmpdir="tmp/romdir"
x_ rm -Rf "${_tmpdir}" x_ rm -Rf "${_tmpdir}"
x_ mkdir -p "${_tmpdir}" x_ mkdir -p "${_tmpdir}"
x_ tar -xf "${archive}" -C "${_tmpdir}" tar -xf "${archive}" -C "${_tmpdir}" || \
err "patch_release_roms: !tar -xf \"${archive}\" -C \"${_tmpdir}\""
for x in "${_tmpdir}"/bin/*/*.rom ; do for x in "${_tmpdir}"/bin/*/*.rom ; do
printf "patching rom: %s\n" "$x" printf "patching rom: %s\n" "$x"
x_ patch_rom "${x}" patch_rom "${x}"
done done
for x in "${_tmpdir}"/bin/*/*_nomicrocode.rom ; do for x in "${_tmpdir}"/bin/*/*_nomicrocode.rom ; do
[ -f "${x}" ] || continue [ -f "${x}" ] || continue
@ -123,7 +127,7 @@ patch_release_roms()
done done
( (
x_ cd "${_tmpdir}/bin/"* x_ cd "${_tmpdir}/bin/"* # TODO: very dodgy, re-write accordingly
# NOTE: For compatibility with older rom releases, defer to sha1 # NOTE: For compatibility with older rom releases, defer to sha1
[ "${nukemode}" = "nuke" ] || \ [ "${nukemode}" = "nuke" ] || \
@ -211,22 +215,28 @@ inject()
if [ "${_t}" = "GbE" ]; then if [ "${_t}" = "GbE" ]; then
x_ mkdir -p tmp x_ mkdir -p tmp
x_ cp "${_dest}" "tmp/gbe.bin" cp "${_dest}" "tmp/gbe.bin" || \
err "inject: !cp \"${_dest}\" \"tmp/gbe.bin\""
_dest="tmp/gbe.bin" _dest="tmp/gbe.bin"
x_ "${nvmutil}" "${_dest}" setmac "${new_mac}" "${nvmutil}" "${_dest}" setmac "${new_mac}" || \
err "inject ${_dest}: can't change mac address"
fi fi
if [ "${cbfsname}" = "IFD" ]; then if [ "${cbfsname}" = "IFD" ]; then
if [ "${nukemode}" != "nuke" ]; then if [ "${nukemode}" != "nuke" ]; then
x_ "${ifdtool}" -i ${_t}:${_dest} "${rom}" -O "$rom" "${ifdtool}" -i ${_t}:${_dest} "${rom}" -O "$rom" || \
err "inject: can't insert $_t ($dest) into $rom"
else else
x_ "${ifdtool}" --nuke ${_t} "${rom}" -O "${rom}" "${ifdtool}" --nuke ${_t} "${rom}" -O "${rom}" || \
err "inject ${rom}: can't nuke ${_t} in IFD"
fi fi
else else
if [ "${nukemode}" != "nuke" ]; then if [ "${nukemode}" != "nuke" ]; then
x_ "${cbfstool}" "${rom}" add -f "${_dest}" \ "${cbfstool}" "${rom}" add -f "${_dest}" \
-n "${cbfsname}" -t ${_t} ${_offset} -n "${cbfsname}" -t ${_t} ${_offset} || \
err "inject $rom: can't insert $_t file $_dest"
else else
x_ "${cbfstool}" "${rom}" remove -n "${cbfsname}" "${cbfstool}" "${rom}" remove -n "${cbfsname}" || \
err "inject $rom: can't remove ${cbfsname}"
fi fi
fi fi