From 15204cda6364afe4e50b3dfe365b4638910a3334 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 11 Sep 2026 14:41:18 +0100 Subject: [PATCH] xbmk: re-introduce condensed if statements i've been careful to makely only use it on AND operations, not onse that use OR. a lot of blocks are not condensed, unlike previously when this design was used. i removed the condensed design because it made the code allegedly easier to read, but i found it harder to read and found the code looked dirty. this change makes it clean again, but i've done it in a way where the shorthand conditional statements are easy to understand for most people. this strikes a compromise; i would go further. Signed-off-by: Leah Rowe --- include/get.sh | 67 +++++--------- include/init.sh | 126 +++++++++---------------- include/inject.sh | 31 +++---- include/lib.sh | 61 +++++-------- include/mrc.sh | 11 +-- include/release.sh | 16 ++-- include/rom.sh | 125 +++++++++---------------- include/tree.sh | 223 +++++++++++++++------------------------------ include/vendor.sh | 189 +++++++++++++------------------------- 9 files changed, 292 insertions(+), 557 deletions(-) diff --git a/include/get.sh b/include/get.sh index 5eaa677d..bc47a075 100644 --- a/include/get.sh +++ b/include/get.sh @@ -11,9 +11,8 @@ tmpgitcache="$xbtmp/tmpgit" fetch_targets() { - if [ -d "src/$project/$tree" ]; then + [ -d "src/$project/$tree" ] && \ return 0 - fi git_prep "$url" "$bkup_url" "$xbmkpwd/$configdir/$tree/patches" \ "src/$project/$tree" "submod" @@ -32,14 +31,13 @@ fetch_project() "fetch_project" "$@" fi - if [ -n "$xgcctree" ]; then + [ -n "$xgcctree" ] && \ x_ ./mk -f coreboot "$xgcctree" - fi - if [ -n "$depend" ]; then + + [ -n "$depend" ] && \ for d in $depend ; do x_ ./mk -f $d done - fi clone_project } @@ -52,9 +50,8 @@ clone_project() loc="src/$project" - if [ -d "$loc" ]; then + [ -d "$loc" ] && \ return 0 - fi remkdir "${tmpgit%/*}" git_prep "$url" "$bkup_url" "$xbmkpwd/config/$project/patches" "$loc" @@ -67,18 +64,16 @@ git_prep() _patchdir="$3" _loc="$4" # $1 and $2 are gitrepo and gitrepo_backup - if [ -z "$rev" ]; then + [ -z "$rev" ] && \ err "$project/$tree: rev not set" "git_prep" "$@" - fi xbget git "$1" "$2" "$tmpgit" "$rev" "$_patchdir" if singletree "$project" || [ $# -gt 4 ]; then dx_ fetch_submodule "$mdir/module.list" fi - if [ "$_loc" != "${_loc%/*}" ]; then + [ "$_loc" != "${_loc%/*}" ] && \ x_ xbmkdir "${_loc%/*}" - fi x_ mv "$tmpgit" "$_loc" } @@ -108,13 +103,11 @@ fetch_submodule() fi st="${st# }" - if [ "$st" = "git curl" ]; then + [ "$st" = "git curl" ] && \ err "$mdir: git+curl defined" "fetch_submodule" "$@" - fi - if [ -z "$st" ]; then + [ -z "$st" ] && \ return 0 - fi if [ "$st" = "curl" ]; then if [ -z "$subcurl" ] || [ -z "$subcurl_bkup" ]; then @@ -143,9 +136,8 @@ fetch_submodule() xbget() { - if [ "$1" != "curl" ] && [ "$1" != "copy" ] && [ "$1" != "git" ]; then + [ "$1" != "curl" ] && [ "$1" != "copy" ] && [ "$1" != "git" ] && \ err "Bad dlop (arg 1)" "xbget" "$@" - fi for url in "$2" "$3" do @@ -157,14 +149,12 @@ xbget() case "$1" in git) - if [ ! -d "$4" ]; then + [ ! -d "$4" ] && \ continue - fi ;; *) - if [ ! -f "$4" ]; then + [ ! -f "$4" ] && \ continue - fi ;; esac return 0 # successful download/copy @@ -192,11 +182,9 @@ try_fetch_git() # let's say it was https://foo.example.com/repo, then cached # directories becomes cache/mirror/foo.example.com/repo - if [ "$XBMK_CACHE_MIRROR" = "y" ]; then + cached="clone" + [ "$XBMK_CACHE_MIRROR" = "y" ] && \ cached="mirror" - else - cached="clone" - fi cached="$cached/${1#*://}" cached="$XBMK_CACHE/$cached" @@ -213,9 +201,8 @@ try_fetch_git() err "Can't clone final repo" "try_fetch" "$@"; : fi - if [ ! -d "$5" ]; then - return 1 - fi + [ ! -d "$5" ] && \ + return 1; : } try_fetch_file() @@ -229,17 +216,15 @@ try_fetch_file() x_ rm -f "$cached" fi - if [ ! -f "$cached" ]; then + [ ! -f "$cached" ] && \ if ! try_$2 "$cached" "$@"; then return 1 fi - fi - if [ -f "$5" ]; then + [ -f "$5" ] && \ if bad_checksum "$6" "$5" 2>/dev/null; then x_ cp "$cached" "$5" fi - fi if [ ! -f "$cached" ]; then return 1 @@ -249,13 +234,11 @@ try_fetch_file() return 1 fi - if [ "$cached" != "$5" ]; then + [ "$cached" != "$5" ] && \ x_ cp "$cached" "$5" - fi if bad_checksum "$6" "$5"; then x_ rm -f "$5" - return 1 elif [ ! -f "$5" ]; then return 1 @@ -330,12 +313,11 @@ bad_checksum() csum="$(x_ "$sha512sum" "$2" | awk '{print $1}')" || \ err "!sha512 '$2' $1" bad_checksum "$@" - if [ "$csum" = "$1" ]; then + [ "$csum" = "$1" ] && \ return 1 - else - x_ rm -f "$2" - printf "BAD SHA512 %s, '%s'; need %s\n" "$csum" "$2" "$1" 1>&2 - fi + + x_ rm -f "$2" + printf "BAD SHA512 %s, '%s'; need %s\n" "$csum" "$2" "$1" 1>&2 } tmpclone() @@ -343,9 +325,8 @@ tmpclone() ( x_ git clone "$1" "$2" ) || return 1 ( x_ git -C "$2" reset --hard "$3" ) || return 1 - if [ ! -d "$4" ]; then + [ ! -d "$4" ] && \ return 0 - fi tmpclone_patchlist="`mktemp || err "Can't create tmp patch list"`" || \ err "Can't create tmp patch list" "tmpclone" "$@" diff --git a/include/init.sh b/include/init.sh index 284b4c3f..6f9254dc 100644 --- a/include/init.sh +++ b/include/init.sh @@ -27,9 +27,8 @@ projectname="libreboot" projectsite="https://libreboot.org/" # TODO: consider just erroring here instead of hardcoding a default -if [ -z "${PATH+x}" ]; then +[ -z "${PATH+x}" ] && \ export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" -fi sha512sum="util/sbase/sha512sum" @@ -46,23 +45,20 @@ xbmk_init() if [ $# -gt 0 ] && [ "$1" = "dependencies" ]; then x_ xbmkpkg "$@" - exit 0 fi id -u 1>/dev/null 2>/dev/null || \ err "suid check failed" "xbmk_init" "$@" - if [ "$(id -u)" = "0" ]; then + [ "$(id -u)" = "0" ] && \ err "this command as root is not permitted" "xbmk_init" "$@" - fi export PWD="$xbmkpwd" x_ xbmkdir "$basetmp" - if [ ! -e "cache" ]; then + [ ! -e "cache" ] && \ x_ xbmkdir "cache" - fi for init_cmd in get_version set_env set_threads git_init child_exec; do if ! xbmk_$init_cmd "$@"; then @@ -75,9 +71,8 @@ xbmkpkg() { xchk xbmkpkg "$@" - if [ $# -gt 2 ]; then + [ $# -gt 2 ] && \ reinstall="$3" - fi . "config/dependencies/$2" || \ err "Can't read 'config/dependencies/$2'" "xbmkpkg" "$@" @@ -95,50 +90,41 @@ xbmkpkg() printf "Updating package use...\n" printf "Writing into %s" "$pkg_use_file..." - if [ ! -d "`dirname $pkg_use_file`" ]; then + [ ! -d "`dirname $pkg_use_file`" ] && \ x_ mkdir -p "`dirname $pkg_use_file`" - fi printf "%s\n" "$pkg_use" >> "$pkg_use_file" fi x_ $pkg_add $pkglist - if [ -n "$aur_notice" ]; then - printf "You need AUR packages: %s\n" "$aur_notice" 1>&2 - fi + [ -n "$aur_notice" ] && \ + printf "You need AUR packages: %s\n" "$aur_notice" 1>&2; : } xbmk_get_version() { - if [ -f ".version" ]; then + [ ! -f ".version" ] || \ read -r version < ".version" || \ err "can't read version file" "xbmk_get_version" "$@" - fi - if [ -f ".versiondate" ]; then + [ ! -f ".versiondate" ] || \ read -r versiondate < ".versiondate" || \ err "can't read versiondate" xbmk_get_version "$@" - fi - if [ -f ".version" ] && [ -z "$version" ]; then + [ -f ".version" ] && [ -z "$version" ] && \ err "version not set" "xbmk_get_version" "$@" - fi - if [ -f ".versiondate" ] && [ -z "$versiondate" ]; then + [ -f ".versiondate" ] && [ -z "$versiondate" ] && \ err "versiondate not set" "xbmk_get_version" "$@" - fi - if [ ! -e ".git" ] && [ ! -f ".version" ]; then + [ ! -e ".git" ] && [ ! -f ".version" ] && \ version="unknown" - fi - if [ ! -e ".git" ] && [ ! -f ".versiondate" ]; then + [ ! -e ".git" ] && [ ! -f ".versiondate" ] && \ versiondate="1716415872" - fi xbmk_sanitize_version - if [ -n "$version" ]; then - relname="$projectname-$version" - fi + [ -n "$version" ] && \ + relname="$projectname-$version"; : } # a parent instance will cause this function to return 0. @@ -151,16 +137,14 @@ xbmk_set_env() xbmkpath="$PATH" # unify all temporary files/directories in a single TMPDIR - if [ -n "${TMPDIR+x}" ] && [ "${TMPDIR%_*}" != "$basetmp/xbmk" ]; then + [ -n "${TMPDIR+x}" ] && [ "${TMPDIR%_*}" != "$basetmp/xbmk" ] && \ unset TMPDIR - fi if [ -n "${TMPDIR+x}" ]; then export TMPDIR="$TMPDIR" xbtmp="$TMPDIR" fi - if [ -n "${TMPDIR+x}" ]; then + [ -n "${TMPDIR+x}" ] && \ is_child="y" - fi if [ "$is_child" = "y" ] then @@ -186,15 +170,12 @@ xbmk_child_set_env() { xbmk_child_set_tmp - if [ -z "${XBMK_CACHE+x}" ]; then + [ -z "${XBMK_CACHE+x}" ] && \ err "XBMK_CACHE unset on child" "xbmk_set_env" "$@" - fi - if [ -z "${XBMK_THREADS+x}" ]; then - xbmk_set_threads; : - fi - if [ -z "${XBMK_CACHE_MIRROR+x}" ]; then - xbmk_set_mirror - fi + [ -z "${XBMK_THREADS+x}" ] && \ + xbmk_set_threads + [ -z "${XBMK_CACHE_MIRROR+x}" ] && \ + xbmk_set_mirror; : } xbmk_child_set_tmp() @@ -266,9 +247,8 @@ xbmk_parent_check_tmp() xbtmp="$TMPDIR" while read -r xtmpdir; do - if [ "$xtmpdir" = "$xbtmp" ]; then - err "pre-existing '$xbtmp'" "xbmk_parent_check_tmp" "$@" - fi + [ "$xtmpdir" = "$xbtmp" ] && \ + err "pre-existing $xbtmp" xbmk_parent_check_tmp "$@"; : done < "$xbmklist" || \ err "Can't read xbmklist: '$xbmklist'" "xbmk_parent_check_tmp" "$@" @@ -279,10 +259,9 @@ xbmk_parent_set_export() { export XBMK_CACHE="$xbmkpwd/cache" - if [ -e "$XBMK_CACHE" ] && [ ! -d "$XBMK_CACHE" ]; then + [ -e "$XBMK_CACHE" ] && [ ! -d "$XBMK_CACHE" ] && \ err "cachedir '$XBMK_CACHE' is a file" \ "xbmk_parent_set_export" "$@" - fi export PATH="$xbtmp/xbmkpath:$xbtmp/gnupath:$PATH" xbmkpath="$PATH" @@ -290,42 +269,35 @@ xbmk_parent_set_export() # if "y": a coreboot target won't be built if target.cfg says release=n # (this is used to exclude certain build targets from releases) - if [ -z "${XBMK_RELEASE+x}" ]; then + [ -z "${XBMK_RELEASE+x}" ] && \ export XBMK_RELEASE="n" - fi - if [ "$XBMK_RELEASE" = "Y" ]; then + [ "$XBMK_RELEASE" = "Y" ] && \ export XBMK_RELEASE="y" - fi - if [ "$XBMK_RELEASE" != "y" ]; then - export XBMK_RELEASE="n" - fi + [ "$XBMK_RELEASE" != "y" ] && \ + export XBMK_RELEASE="n"; : } xbmk_set_threads() { - if [ -z "${XBMK_THREADS+x}" ]; then + [ -z "${XBMK_THREADS+x}" ] && \ export XBMK_THREADS=1 - fi - if ! expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \ - 1>/dev/null 2>/dev/null; then - export XBMK_THREADS=1 - fi + expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \ + 1>/dev/null 2>/dev/null || \ + export XBMK_THREADS=1; : } xbmk_set_version() { version_="$version" - if [ -e ".git" ]; then + [ ! -e ".git" ] || \ version="$(git describe --tags HEAD 2>&1)" || \ version="git-$(git rev-parse HEAD 2>&1)" || \ version="$version_" - fi versiondate_="$versiondate" - if [ -e ".git" ]; then + [ ! -e ".git" ] || \ versiondate="$(git show --no-patch --no-notes \ --pretty='%ct' HEAD)" || versiondate="$versiondate_" - fi if [ -z "$version" ] || [ -z "$versiondate" ]; then err "version and/or versiondate unset" "xbmk_set_version" "$@" @@ -346,25 +318,22 @@ xbmk_set_pyver() if ! pybin python3 1>/dev/null; then python="python" fi - if [ "$python" = "python3" ]; then + [ "$python" = "python3" ] && \ pyver="3" - fi if ! pybin "$python" 1>/dev/null; then pyver="" fi - if [ -n "$pyver" ]; then + [ -z "$pyver" ] || \ "`x_ pybin "$python"`" -c "$pyv" 1>/dev/null \ 2>/dev/null || \ err "Can't detect Python version." "xbmk_set_pyver" "$@" - fi if [ -n "$pyver" ]; then pyver="$("$(pybin "$python")" -c "$pyv" | awk '{print $1}')" pyver="${pyver#(}" pyver="${pyver%,}" fi - if [ "${pyver%%.*}" != "3" ]; then + [ "${pyver%%.*}" != "3" ] && \ err "Bad python version (must by 3.x)" "xbmk_set_pyver" "$@" - fi # set up python in PATH (environmental variable): @@ -389,11 +358,10 @@ pybin() if ! command -v "$1" 1>/dev/null 2>/dev/null; then venv=0 fi - if [ $venv -gt 0 ]; then + [ $venv -gt 0 ] && \ if ! "$1" -c "$py" 1>/dev/null 2>/dev/null; then venv=0 fi - fi # ideally, don't rely on PATH or hardcoded paths if python venv. # use the *real*, direct executable linked to by the venv symlink: @@ -406,7 +374,6 @@ pybin() [ -x "$pypath" ]; then printf "%s\n" "$pypath" - return 0 fi fi @@ -418,7 +385,6 @@ pybin() [ -x "$pypath/$1" ]; then printf "%s/%s\n" "$pypath" "$1" - return 0 fi done && return 1 @@ -439,12 +405,10 @@ xbmk_set_mirror() # it's slower, and uses more disk space, and some upstreams might not # appreciate it, so it should only be used for development or archival - if [ -z "${XBMK_CACHE_MIRROR+x}" ]; then + [ -z "${XBMK_CACHE_MIRROR+x}" ] && \ export XBMK_CACHE_MIRROR="n" - fi - if [ "$XBMK_CACHE_MIRROR" != "y" ]; then - export XBMK_CACHE_MIRROR="n" - fi + [ "$XBMK_CACHE_MIRROR" != "y" ] && \ + export XBMK_CACHE_MIRROR="n"; : } xbmk_git_init() @@ -459,12 +423,10 @@ xbmk_git_init() fi done - if [ -L ".git" ]; then + [ -L ".git" ] && \ err "'$xbmkpwd/.git' is a symlink" "xbmk_git_init" "$@" - fi - if [ -e ".git" ]; then + [ -e ".git" ] && \ return 0 - fi # GNU-specific extensions of date are used. # TODO: that is a bug. fix it! diff --git a/include/inject.sh b/include/inject.sh index b915fb66..b037d2c5 100644 --- a/include/inject.sh +++ b/include/inject.sh @@ -18,9 +18,8 @@ inject() { remkdir "$tmpromdel" - if [ $# -lt 1 ]; then + [ $# -lt 1 ] && \ err "No options specified" "inject" "$@" - fi archive="$1"; new_mac="xx:xx:xx:xx:xx:xx" @@ -36,18 +35,16 @@ inject() setmac) if [ $# -gt 2 ]; then new_mac="$3" && \ - if [ -z "$new_mac" ]; then - err "Empty MAC address specified" "inject" "$@" - fi + [ -z "$new_mac" ] && \ + err "Empty MAC address" "inject" "$@"; : fi ;; *) err "Unrecognised inject mode: '$2'" "inject" "$@" ;; esac - if [ "$new_mac" = "keep" ]; then + [ "$new_mac" = "keep" ] && \ new_mac="" - fi check_release if check_target; then @@ -55,9 +52,8 @@ inject() return 0 fi fi - if [ "$xchanged" = "y" ]; then + [ "$xchanged" = "y" ] && \ remktar - fi if [ "$xchanged" = "y" ]; then printf "\n'%s' was modified\n" "$archive" 1>&2 @@ -70,9 +66,8 @@ inject() check_release() { - if [ -L "$archive" ]; then + [ -L "$archive" ] && \ err "'$archive' is a symlink" "check_release" "$@" - fi if e "$archive" f missing; then err "'$archive' missing" "check_release" "$@" fi @@ -80,9 +75,8 @@ check_release() archivename="`basename "$archive" || err "Can't get '$archive' name"`" \ || err "can't get '$archive' name" "check_release" "$@" - if [ -z "$archivename" ]; then + [ -z "$archivename" ] && \ err "Can't determine archive name" "check_release" "$@" - fi case "$archivename" in *_src.tar.xz) @@ -102,9 +96,8 @@ check_release() check_target() { - if [ "$board" != "${board#serprog_}" ]; then + [ "$board" != "${board#serprog_}" ] && \ return 1 - fi boarddir="$cbcfgsdir/$board" @@ -119,16 +112,14 @@ check_target() ifdtool="elf/coreboot/$tree/ifdtool" - if [ -n "$IFD_platform" ]; then - ifdprefix="-p $IFD_platform" - fi + [ -n "$IFD_platform" ] && \ + ifdprefix="-p $IFD_platform"; : } patch_release() { - if [ "$nuke" != "nuke" ]; then + [ "$nuke" != "nuke" ] && \ x_ ./mk download "$board" - fi has_hashes="n" tmpromdir="$tmpromdel/bin/$board" diff --git a/include/lib.sh b/include/lib.sh index 4ed8b5a0..781ff877 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -40,9 +40,8 @@ version() xbmk_sanitize_version() { - if [ -z "$version" ]; then + [ -z "$version" ] && \ return 0 - fi version="`printf "%s\n" "$version" | sed -e 's/\t//g'`" version="`printf "%s\n" "$version" | sed -e 's/\ //g'`" @@ -52,19 +51,17 @@ xbmk_sanitize_version() version="${version#-}" - if [ -z "$version" ]; then + [ -z "$version" ] && \ err "'version' empty after sanitization" \ - "xbmk_sanitize_version" "$@" - fi + "xbmk_sanitize_version" "$@"; : } mktarball() { printf "Creating tar archive '%s' from directory '%s'\n" "$2" "$1" - if [ "${2%/*}" != "$2" ]; then + [ "${2%/*}" != "$2" ] && \ x_ xbmkdir "${2%/*}" - fi x_ tar -c "$1" | xz -T$XBMK_THREADS -9e > "$2" || \ err "can't make tarball '$1'" "mktarball" "$@" @@ -73,10 +70,8 @@ mktarball() e() { es_t="e" - - if [ $# -gt 1 ]; then + [ $# -gt 1 ] && \ es_t="$2" - fi es2="already exists" estr="[ -$es_t \"\$1\" ] || return 1" @@ -101,9 +96,8 @@ singletree() findpath() { - if [ $# -lt 1 ]; then + [ $# -lt 1 ] && \ err "findpath: No arguments provided" "findpath" "$@" - fi while [ $# -gt 0 ] do @@ -136,9 +130,8 @@ unpad_one_byte() xromsize="$(expr $(stat -c '%s' "$1") - 1)" || \ err "can't increment file size" "unpad_one_byte" "$@" - if [ $xromsize -lt 524288 ]; then + [ $xromsize -lt 524288 ] && \ err "too small, $xromsize: $1" "unpad_one_byte" "$@" - fi unpaddedfile="`mktemp || err "mktemp unpad_one_byte"`" || \ err "can't make tmp file" "unpad_one_byte" "$@" @@ -149,9 +142,8 @@ unpad_one_byte() build_sbase() { - if [ ! -f "$sha512sum" ]; then - x_ make -C "$xbmkpwd/util/sbase" - fi + [ ! -f "$sha512sum" ] && \ + x_ make -C "$xbmkpwd/util/sbase"; : } remkdir() @@ -162,11 +154,9 @@ remkdir() xbmkdir() { - while [ $# -gt 0 ] - do - if [ ! -d "$1" ]; then + while [ $# -gt 0 ]; do + [ ! -d "$1" ] && \ x_ mkdir -p "$1" - fi shift 1 done @@ -196,9 +186,8 @@ dx_() { xchk dx_ "$@" - if [ ! -f "$2" ]; then + [ ! -f "$2" ] && \ return 0 - fi while read -r fx; do $1 "$fx" || return 1; : @@ -207,20 +196,19 @@ dx_() x_() { - if [ $# -lt 1 ]; then + [ $# -lt 1 ] && \ return 0 - elif [ -z "$1" ]; then + [ -z "$1" ] && \ err "Empty first arg" "x_" "$@" - else - "$@" || err "Unhandled error" "x_" "$@" - fi + + "$@" || err "Unhandled error" "x_" "$@" } xeq() { - if [ $# -lt 2 ]; then + [ $# -lt 2 ] && \ err "no args" xeq - fi + xbcmd="$1" chk="$2" shift 2 @@ -231,9 +219,8 @@ xeq() ;; *) for eq in "$@"; do - if [ "$chk" = "$eq" ]; then - return 0 - fi + [ "$chk" = "$eq" ] && \ + return 0; : done ;; esac @@ -270,14 +257,12 @@ xprintf() xprintfargs=0 while [ $# -gt 0 ]; do printf "\"%s\"" "$1" - if [ $# -gt 1 ]; then + [ $# -gt 1 ] && \ printf " " - fi xprintfargs=1 shift 1 done - if [ $xprintfargs -gt 0 ]; then - printf "\n" - fi + [ $xprintfargs -gt 0 ] && \ + printf "\n"; : } diff --git a/include/mrc.sh b/include/mrc.sh index 9c50af5c..c83cda7b 100644 --- a/include/mrc.sh +++ b/include/mrc.sh @@ -18,9 +18,8 @@ extract_refcode() # and refcode is extracted from an image using the old scheme. we use # cbfstool from coreboot 4.11_branch, the tree used by ASUS KGPE-D16: - if [ -z "$cbfstoolref" ]; then + [ -z "$cbfstoolref" ] && \ err "cbfstoolref not set" "extract_refcode" "$@" - fi x_ xbmkdir "${_pre_dest%/*}" @@ -28,21 +27,19 @@ extract_refcode() -m x86 -n fallback/refcode -f "$appdir/ref" -r RO_SECTION # enable the Intel GbE device, if told by offset MRC_refcode_gbe - if [ -n "$MRC_refcode_gbe" ]; then + [ -n "$MRC_refcode_gbe" ] && \ x_ dd if="config/ifd/hp820g2/1.bin" of="$appdir/ref" bs=1 \ seek=$MRC_refcode_gbe count=1 conv=notrunc; : - fi x_ mv "$appdir/ref" "$_pre_dest" } extract_mrc() { - if [ -z "$MRC_board" ]; then + [ -z "$MRC_board" ] && \ err "MRC_board unset" "extract_mrc" "$@" - elif [ -z "$CONFIG_MRC_FILE" ]; then + [ -z "$CONFIG_MRC_FILE" ] && \ err "CONFIG_MRC_FILE unset" "extract_mrc" "$@" - fi SHELLBALL="chromeos-firmwareupdate-$MRC_board" diff --git a/include/release.sh b/include/release.sh index e9017a05..d0b35edd 100644 --- a/include/release.sh +++ b/include/release.sh @@ -16,9 +16,8 @@ release() while getopts m: option do - if [ -z "$OPTARG" ]; then + [ -z "$OPTARG" ] && \ err "empty argument not allowed" "release" "$@" - fi case "$option" in m) @@ -31,9 +30,8 @@ release() done reldest="$reldir/$version" - if [ -e "$reldest" ]; then + [ -e "$reldest" ] && \ err "already exists: \"$reldest\"" "release" "$@" - fi vdir="`mktemp -d || err "can't make vdir"`" || \ err "can't make tmp vdir" "release" "$@" @@ -47,9 +45,9 @@ release() prep_release src prep_release tarball - if [ "$relmode" != "src" ]; then + [ "$relmode" != "src" ] && \ prep_release bin - fi + x_ rm -Rf "$rsrc" x_ xbmkdir "$reldir" @@ -64,9 +62,8 @@ prep_release() ( if [ "$1" != "tarball" ]; then x_ cd "$rsrc" - if [ ! -e "cache" ]; then - x_ ln -s "$XBMK_CACHE" "cache" - fi + [ ! -e "cache" ] && \ + x_ ln -s "$XBMK_CACHE" "cache"; : fi prep_release_$1 @@ -93,7 +90,6 @@ nuke() if [ -d "${r%/*}" ]; then x_ cd "${r%/*}" - dx_ "x_ rm -Rf" "$rsrc/$1" fi } diff --git a/include/rom.sh b/include/rom.sh index 6f0e3529..bb5606f9 100644 --- a/include/rom.sh +++ b/include/rom.sh @@ -63,9 +63,8 @@ mkpayload_grub() corebootpremake() { - if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then + [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && \ return 0 - fi $if_not_dry_build \ cook_coreboot_config @@ -75,9 +74,8 @@ corebootpremake() printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \ err "!mk $srcdir .coreboot-version" "corebootpremake" "$@" - if [ -z "$mode" ] && [ "$target" != "$tree" ]; then - x_ ./mk download "$target" - fi + [ -z "$mode" ] && [ "$target" != "$tree" ] && \ + x_ ./mk download "$target"; : } cook_coreboot_config() @@ -90,9 +88,8 @@ cook_coreboot_config() check_coreboot_util() { - if [ "$badhash" = "y" ]; then + [ "$badhash" = "y" ] && \ x_ rm -f "elf/coreboot/$tree/$1" - fi if e "elf/coreboot/$tree/$1" f; then return 0 fi @@ -101,9 +98,8 @@ check_coreboot_util() utilsrcdir="src/coreboot/$tree/util/$1" utilmode="" - if [ -n "$mode" ]; then + [ -n "$mode" ] && \ utilmode="clean" - fi x_ make -C "$utilsrcdir" $utilmode -j$XBMK_THREADS $makeargs @@ -120,16 +116,14 @@ check_coreboot_util() x_ xbmkdir "$utilelfdir" x_ cp "$utilsrcdir/$1" "$utilelfdir" - if [ "$1" = "cbfstool" ]; then - x_ cp "$utilsrcdir/rmodtool" "$utilelfdir" - fi + [ "$1" = "cbfstool" ] && \ + x_ cp "$utilsrcdir/rmodtool" "$utilelfdir"; : } coreboot_pad_one_byte() { - if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then + [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && \ return 0 - fi $if_not_dry_build \ pad_one_byte "$srcdir/build/coreboot.rom" @@ -137,9 +131,8 @@ coreboot_pad_one_byte() mkcorebootbin() { - if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then + [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && \ return 0 - fi $if_not_dry_build \ check_coreboot_util cbfstool @@ -157,9 +150,8 @@ mkcorebootbin() mkcorebootbin_real() { - if [ "$target" = "$tree" ]; then + [ "$target" = "$tree" ] && \ return 0 - fi tmprom="$xbtmp/coreboot.rom" @@ -177,9 +169,8 @@ mkcorebootbin_real() cbfscfg="config/coreboot/$target/cbfs.cfg" elfrom="elf/coreboot/$tree/$target/$initmode" - if [ -n "$displaymode" ]; then + [ -n "$displaymode" ] && \ elfrom="${elfrom}_$displaymode" - fi elfrom="$elfrom/coreboot.rom" $if_not_dry_build \ @@ -188,57 +179,44 @@ mkcorebootbin_real() $if_not_dry_build \ unpad_one_byte "$tmprom" - if [ -n "$payload_uboot" ] && [ "$payload_uboot" != "amd64" ] && \ - [ "$payload_uboot" != "i386" ] && [ "$payload_uboot" != "arm64" ] - then - err "'$target' defines bad u-boot type '$payload_uboot'" \ + [ -n "$payload_uboot" ] && [ "$payload_uboot" != "amd64" ] && \ + [ "$payload_uboot" != "i386" ] && [ "$payload_uboot" != "arm64" ] \ + && err "'$target' defines bad u-boot type '$payload_uboot'" \ "mkcorebootbin_real" "$@" - fi - if [ -n "$payload_uboot" ] && [ "$payload_uboot" != "arm64" ]; then + [ -n "$payload_uboot" ] && [ "$payload_uboot" != "arm64" ] && \ payload_seabios="y" - fi - if [ -z "$uboot_config" ]; then + [ -z "$uboot_config" ] && \ uboot_config="default" - fi - if [ "$payload_grub" = "y" ]; then + [ "$payload_grub" = "y" ] && \ payload_seabios="y" - fi - if [ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "arm64" ]; then + [ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "arm64" ] && \ $if_not_dry_build \ err "$target: U-Boot arm / SeaBIOS/GRUB both enabled" \ "mkcorebootbin_real" "$@" - fi - if [ -z "$grub_scan_disk" ]; then + [ -z "$grub_scan_disk" ] && \ grub_scan_disk="nvme ahci ata" - fi - if [ -z "$grubtree" ]; then + [ -z "$grubtree" ] && \ grubtree="default" - fi grubelf="elf/grub/$grubtree/$grubtree/payload/grub.elf" - if [ "$payload_memtest" != "y" ]; then + [ "$payload_memtest" != "y" ] && \ payload_memtest="n" - fi - if [ "$(uname -m)" != "x86_64" ]; then + [ "$(uname -m)" != "x86_64" ] && \ payload_memtest="n" - fi - if [ "$payload_grubsea" = "y" ] && [ "$initmode" = "normal" ]; then + [ "$payload_grubsea" = "y" ] && [ "$initmode" = "normal" ] && \ payload_grubsea="n" - fi - if [ "$payload_grub" != "y" ]; then + [ "$payload_grub" != "y" ] && \ payload_grubsea="n" - fi $if_dry_build \ return 0 - if [ -f "$cbfscfg" ]; then + [ -f "$cbfscfg" ] && \ dx_ add_cbfs_option "$cbfscfg" - fi if grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then if [ "$payload_seabios" = "y" ]; then @@ -283,31 +261,25 @@ add_cbfs_option() add_seabios() { - if [ -n "$payload_uboot" ] && [ "$payload_uboot" != "arm64" ]; then - # we must add u-boot first, because it's added as a flat - # binary at a specific offset for secondary program loader - + [ -n "$payload_uboot" ] && [ "$payload_uboot" != "arm64" ] && \ $if_not_dry_build \ - add_uboot - fi + add_uboot # add u-boot first, due to fixed cbfs offset _seabioself="elf/seabios/default/default/$initmode/bios.bin.elf" [ "$initmode" = "fspgop" ] && \ _seabioself="elf/seabios/default/default/libgfxinit/bios.bin.elf" _seaname="fallback/payload" - if [ "$payload_grubsea" = "y" ]; then + [ "$payload_grubsea" = "y" ] && \ _seaname="seabios.elf" - fi cbfs "$tmprom" "$_seabioself" "$_seaname" x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup opexec="2" - if [ "$initmode" = "vgarom" ]; then + [ "$initmode" = "vgarom" ] && \ opexec="0" - fi x_ "$cbfstool" "$tmprom" add-int -i $opexec -n etc/pci-optionrom-exec x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum @@ -315,26 +287,17 @@ add_seabios() cbfs "$tmprom" "$seavgabiosrom" vgaroms/seavgabios.bin raw fi - if [ "$payload_memtest" = "y" ]; then - # because why not have memtest? - + [ "$payload_memtest" = "y" ] && \ cbfs "$tmprom" "elf/memtest86plus/memtest.bin" img/memtest - fi - if [ "$payload_grub" = "y" ]; then + [ "$payload_grub" = "y" ] && \ add_grub - fi - if [ "$payload_grubsea" != "y" ]; then - # ROM image where SeaBIOS doesn't load grub/u-boot first. - # U-Boot/GRUB available in ESC menu if enabled for the board + [ "$payload_grubsea" != "y" ] && \ + cprom # seabios, but don't load grub/u-boot first - cprom - fi - - # now make "SeaUBoot" and "SeaGRUB" images, where SeaBIOS auto-loads - # SeaBIOS or U-Boot first; users can bypass this by pressing ESC - # in the SeaBIOS menu, to boot devices using SeaBIOS itself instead + # now make seauboot(u-boot loaded by seabios) and SeaGRUB (GRUB loaded + # by SeaBIOS) images; users can bypass via ESC to boot from SeaBIOS if [ "$payload_uboot" = "amd64" ] && \ [ "$displaymode" != "txtmode" ] && \ @@ -353,9 +316,8 @@ add_grub() { # path in CBFS for the GRUB payload _grubname="img/grub2" - if [ "$payload_grubsea" = "y" ]; then + [ "$payload_grubsea" = "y" ] && \ _grubname="fallback/payload" - fi cbfs "$tmprom" "$grubelf" "$_grubname" @@ -365,10 +327,9 @@ add_grub() cbfs "$tmprom" "$xbtmp/tmpcfg" scan.cfg raw - if [ "$initmode" != "normal" ] && [ "$displaymode" != "txtmode" ]; then + [ "$initmode" != "normal" ] && [ "$displaymode" != "txtmode" ] && \ cbfs "$tmprom" "$grubdata/background/background1280x800.png" \ - "background.png" raw - fi + "background.png" raw; : } mkseagrub() @@ -386,12 +347,10 @@ add_uboot() { if [ "$displaymode" = "txtmode" ]; then printf "cb/%s: Can't use U-Boot in text mode\n" "$target" 1>&2 - return 0 elif [ "$initmode" = "normal" ]; then printf "cb/%s: Can't use U-Boot in normal initmode\n" \ "$target" 1>&2 - return 0 fi @@ -438,9 +397,8 @@ add_uboot() fi cbfs "$tmprom" "$ubootelf" "$ubpath" $ubcbfsargs - if [ "$payload_seabios" != "y" ]; then - cprom - fi + [ "$payload_seabios" != "y" ] && \ + cprom; : } # prepare the final image in bin/ for user installation: @@ -452,9 +410,8 @@ cprom() tmpnew="" newrom="bin/$target/${pname}_${target}_$initmode.rom" - if [ -n "$displaymode" ]; then + [ -n "$displaymode" ] && \ newrom="${newrom%.rom}_$displaymode.rom" - fi if [ $# -gt 0 ] && [ "${1%.gkb}" != "$1" ]; then tmpnew="${1##*/}" newrom="${newrom%.rom}_${tmpnew%.gkb}.rom" diff --git a/include/tree.sh b/include/tree.sh index 30d0ecc6..bb28f0e0 100644 --- a/include/tree.sh +++ b/include/tree.sh @@ -25,9 +25,8 @@ trees() while getopts $flags option do - if [ -n "$flag" ]; then + [ -n "$flag" ] && \ err "only one flag is permitted" "trees" "$@" - fi flag="$1" @@ -70,7 +69,6 @@ trees() if [ -z "${OPTARG+x}" ]; then shift 1 - break fi @@ -84,9 +82,7 @@ trees() err "missing flag ($flags)" "trees" "$@" elif [ -z "$project" ]; then fx_ "x_ ./mk $flag" x_ ls -1 config/git - return 1 - elif [ ! -f "config/git/$project/pkg.cfg" ]; then err "config/git/$project/pkg.cfg missing" "trees" "$@" fi @@ -98,9 +94,8 @@ trees() dest_dir="$elfdir" listfile="$datadir/build.list" - if [ ! -f "$listfile" ]; then + [ ! -f "$listfile" ] && \ listfile="" # build.list is optional on all projects - fi mkhelpercfg="$datadir/mkhelper.cfg" if e "$mkhelpercfg" f missing; then @@ -127,18 +122,16 @@ build_project() fi fi - if [ "$mode" = "distclean" ]; then + [ "$mode" = "distclean" ] && \ mode="clean" - fi if ! run_make_command; then return 0 fi - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ $if_not_dry_build \ copy_elf; : - fi } build_targets() @@ -157,9 +150,7 @@ build_targets() if [ "$x" = "list" ]; then x_ ls -1 "config/$project" - listfile="" - break fi @@ -169,9 +160,8 @@ build_targets() x_ handle_defconfig - if [ -z "$mode" ]; then - x_ $postmake - fi + [ -z "$mode" ] && \ + x_ $postmake; : done; : } @@ -179,51 +169,44 @@ handle_defconfig() { target_dir="$configdir/$target" - if [ ! -f "CHANGELOG" ]; then + [ ! -f "CHANGELOG" ] && \ fetch_project "$project" - fi if ! configure_project "$target_dir"; then return 0 fi - if [ -z "$tree" ]; then + [ -z "$tree" ] && \ err "$configdir: 'tree' not set" "handle_defconfig" "$@" - fi srcdir="src/$project/$tree" - if [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ]; then + [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ] && \ return 0 - fi for y in "$target_dir/config"/* do - if [ "$flag" != "-d" ] && [ ! -f "$y" ]; then + [ "$flag" != "-d" ] && [ ! -f "$y" ] && \ continue - elif [ "$flag" != "-d" ]; then + [ "$flag" != "-d" ] && \ defconfig="$y" - fi if [ -z "$mode" ]; then check_defconfig || continue; : fi - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ for _xarch in $xarch; do $if_dry_build \ break - if [ -n "$_xarch" ]; then - check_cross_compiler "$_xarch" - fi + [ -n "$_xarch" ] && \ + check_cross_compiler "$_xarch"; : done; : - fi handle_makefile - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ $if_not_dry_build \ - copy_elf - fi + copy_elf; : done; : } @@ -235,12 +218,10 @@ configure_project() build_depend buildtype cleanargs makeargs mkhelper postmake \ premake release xarch xgcctree xlang`" - if [ ! -f "$_tcfg" ]; then + [ ! -f "$_tcfg" ] && \ buildtype="auto" - fi # globally initialise all variables for a source tree / target: - if e "$datadir/mkhelper.cfg" f; then . "$datadir/mkhelper.cfg" || \ err "Can't read '$datadir/mkhelper.cfg'" \ @@ -248,62 +229,42 @@ configure_project() fi # override target/tree specific variables from per-target config: - while e "$_tcfg" f || [ "$cmd" != "build_project" ] do - # TODO: implement infinite loop detection here, caused - # by project targets pointing to other targets/trees - # when then ultimate point back repeatedly; this is - # currently avoided simply by careful configuration. - # temporary files per tree/target name could be created - # per iteration, and then checked the next time + # TODO: detect infinine loops and throw err. + # (currently mitigated by virtue of configuration) printf "Loading %s config: %s\n" "$project" "$_tcfg" - eval "`newvar rev tree`" . "$_tcfg" || \ err "Can't read '$_tcfg'" "configure_project" "$@" - if [ "$flag" = "-d" ]; then + [ "$flag" = "-d" ] && \ build_depend="" # dry run - fi - if [ "$cmd" = "build_project" ]; then - # single-tree, so it can't be a target pointing - # to a main source tree - break - fi + [ "$cmd" = "build_project" ] && \ + break # single-tree, so targeting is unnecessary $if_do_make \ break - if [ "${_tcfg%/*/target.cfg}" = "${_tcfg%"/$tree/target.cfg"}" ] - then - # we have found the main source tree that - # a given target uses; no need to continue - - break - else - _tcfg="${_tcfg%/*/target.cfg}/$tree/target.cfg" - fi + [ "${_tcfg%/*/target.cfg}" = "${_tcfg%"/$tree/target.cfg"}" ] \ + && break # target and tree matching was successful + _tcfg="${_tcfg%/*/target.cfg}/$tree/target.cfg" # try next done - if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then + [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && \ return 1 - fi - if [ -n "$buildtype" ] && [ "${mode%config}" != "$mode" ]; then + [ -n "$buildtype" ] && [ "${mode%config}" != "$mode" ] && \ return 1 - fi - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ $if_not_dry_build \ build_dependencies - fi mdir="$xbmkpwd/config/submodule/$project" - if [ -n "$tree" ]; then + [ -n "$tree" ] && \ mdir="$mdir/$tree" - fi if [ ! -f "CHANGELOG" ]; then delete_old_project_files @@ -326,18 +287,15 @@ build_dependencies() bd_project="${bd%%/*}" bd_tree="${bd##*/}" - if [ -z "$bd_project" ]; then + [ -z "$bd_project" ] && \ $if_not_dry_build \ err "$project/$tree: !bd '$bd'" \ "build_dependencies" "$@" - fi - if [ "${bd##*/}" = "$bd" ]; then + [ "${bd##*/}" = "$bd" ] && \ bd_tree="" - fi - if [ -n "$bd_project" ]; then + [ -n "$bd_project" ] && \ $if_not_dry_build \ x_ ./mk -b $bd_project $bd_tree; : - fi done; : } @@ -422,18 +380,14 @@ check_cross_compiler() { cbdir="src/coreboot/$tree" - if [ "$project" != "coreboot" ]; then + [ "$project" != "coreboot" ] && \ cbdir="src/coreboot/default" - fi - if [ -n "$xgcctree" ]; then + [ -n "$xgcctree" ] && \ cbdir="src/coreboot/$xgcctree" - fi xfix="${1%-*}" - - if [ "$xfix" = "x86_64" ]; then + [ "$xfix" = "x86_64" ] && \ xfix="x64" - fi xgccfile="elf/coreboot/$tree/xgcc_${xfix}_was_compiled" xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" @@ -441,27 +395,22 @@ check_cross_compiler() x_ ./mk -f coreboot "${cbdir#src/coreboot/}" x_ xbmkdir "elf/coreboot/$tree" # TODO: is this needed? + # tell build systems what cross-compiler to use export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH" - export CROSS_COMPILE="${xarch% *}-" + export CROSS_COMPILE="${xarch% *}-" # used by e.g. u-boot - if [ -n "$xlang" ]; then + # coreboot-specific (we disable gnat on some trees) + [ -n "$xlang" ] && \ export BUILD_LANGUAGES="$xlang" - fi - if [ -f "$xgccfile" ]; then - # skip the build, because a build already exists: - - return 0 - fi + [ -f "$xgccfile" ] && \ + return 0 # build exists already, so skip building check_gnu_path gcc gnat || x_ check_gnu_path gnat gcc make -C "$cbdir" $xgccargs || x_ make -C "$cbdir" $xgccargs - # this tells subsequent runs that the build was already done: - x_ touch "$xgccfile" - - # reset hostcc in PATH: - remkdir "$xbtmp/gnupath" + x_ touch "$xgccfile" # prevent unnecessary re-build operations + remkdir "$xbtmp/gnupath" # reset hostcc } # fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024, @@ -495,11 +444,8 @@ host_gcc_gnat_match() eval "[ -z \"\$$1ver\" ] && err \"Cannot detect host '$1' version\"" - if [ "$gnatfull" != "$gccfull" ]; then - # non-matching gcc/gnat versions - - return 1 - fi + [ "$gnatfull" != "$gccfull" ] && \ + return 1; : # mismatched gcc/gnat versions } # find all gcc/gnat versions, matching them up in PATH: @@ -510,8 +456,7 @@ match_gcc_gnat_versions() eval "_gnudir=\"\$$1dir\"" eval "_gnuver=\"\$$1ver\"" - for _bin in "$_gnudir/$2-"* - do + for _bin in "$_gnudir/$2-"*; do if [ "${_bin#"$_gnudir/$2-"}" = "$_gnuver" ] && [ -x "$_bin" ] then _gnuver="${_bin#"$_gnudir/$2-"}" @@ -543,9 +488,8 @@ link_gcc_gnat_versions() for _gnubin in "$_gnudir/$2"*"-$_gnuver" do _gnuutil="${_gnubin##*/}" - if [ -e "$_gnubin" ]; then - x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}" - fi + [ -e "$_gnubin" ] && \ + x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"; : done } @@ -563,10 +507,9 @@ gnu_setver() check_defconfig() { - if [ ! -f "$defconfig" ]; then + [ ! -f "$defconfig" ] && \ $if_not_dry_build \ - err "$project/$target: no config" "check_defconfig" "$@" - fi + err "$project/$target: no config" check_defconfig "$@" dest_dir="$elfdir/$tree/$target/${defconfig#"$target_dir/config/"}" @@ -574,9 +517,8 @@ check_defconfig() $if_dry_build \ return 0 - if ! elfcheck; then - return 1 - fi + elfcheck || \ + return 1; : } elfcheck() @@ -593,42 +535,36 @@ handle_makefile() x_ make -C "$srcdir" $cleanargs clean fi - if [ -f "$defconfig" ]; then + [ -f "$defconfig" ] && \ x_ cp "$defconfig" "$srcdir/.config" - fi run_make_command || \ err "no makefile!" "handle_makefile" "$@" _copy=".config" - if [ "$mode" = "savedefconfig" ]; then + [ "$mode" = "savedefconfig" ] && \ _copy="defconfig" - fi - if [ "${mode%config}" != "$mode" ]; then + [ "${mode%config}" != "$mode" ] && \ $if_not_dry_build \ x_ cp "$srcdir/$_copy" "$defconfig"; : - fi - if [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \ - [ "$mode" = "distclean" ]; then + [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \ + [ "$mode" = "distclean" ] && \ $if_not_dry_build \ x_ git -C "$srcdir" $cleanargs clean -fdx; : - fi } run_make_command() { - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ x_ $premake - fi if $if_not_dry_build check_cmake "$srcdir"; then - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ $if_not_dry_build \ - check_autoconf "$srcdir" - fi + check_autoconf "$srcdir"; : fi if ! $if_not_dry_build check_makefile "$srcdir"; then return 1 @@ -637,9 +573,8 @@ run_make_command() $if_not_dry_build \ x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs - if [ -z "$mode" ]; then + [ -z "$mode" ] && \ x_ $mkhelper - fi if ! check_makefile "$srcdir"; then return 0 @@ -671,42 +606,34 @@ check_cmake() check_autoconf() { ( - x_ cd "$1" + x_ cd "$1" - if [ -f "bootstrap" ]; then - x_ ./bootstrap $bootstrapargs - fi - if [ -f "autogen.sh" ]; then - x_ ./autogen.sh $autogenargs - fi - if [ -f "configure" ]; then - x_ ./configure $autoconfargs; : - fi + [ -f "bootstrap" ] && \ + x_ ./bootstrap $bootstrapargs + [ -f "autogen.sh" ] && \ + x_ ./autogen.sh $autogenargs + [ -f "configure" ] && \ + x_ ./configure $autoconfargs; : ) || err "can't bootstrap project: $1" "check_autoconf" "$@"; : } check_makefile() { - if [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \ - [ ! -f "$1/GNUmakefile" ]; then - - return 1 - fi + [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \ + [ ! -f "$1/GNUmakefile" ] && \ + return 1; : } copy_elf() { - if [ -f "$listfile" ]; then + [ -f "$listfile" ] && \ x_ xbmkdir "$dest_dir" - fi if [ -f "$listfile" ]; then - while read -r f - do - if [ -f "$srcdir/$f" ]; then - x_ cp "$srcdir/$f" "$dest_dir" - fi + while read -r f; do + [ -f "$srcdir/$f" ] && \ + x_ cp "$srcdir/$f" "$dest_dir"; : done < "$listfile" || err \ "cannot read '$listfile'" "copy_elf" "$@"; : diff --git a/include/vendor.sh b/include/vendor.sh index 0101f517..b3ab60b1 100644 --- a/include/vendor.sh +++ b/include/vendor.sh @@ -51,9 +51,8 @@ eval "`newvar DL_hash DL_url DL_url_bkup E6400_VGA_bin_hash E6400_VGA_DL_hash \ download() { - if [ $# -lt 1 ]; then + [ $# -lt 1 ] && \ err "No argument given" "download" "$@" - fi export PATH="$PATH:/sbin" board="$1" @@ -65,48 +64,38 @@ download() getfiles() { - if [ -n "$CONFIG_HAVE_ME_BIN" ];then + [ -n "$CONFIG_HAVE_ME_BIN" ] && \ fetch intel_me "$DL_url" "$DL_url_bkup" "$DL_hash" \ "$CONFIG_ME_BIN_PATH" curl "$ME_bin_hash" - fi - if [ -n "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" ]; then + [ -n "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" ] && \ fetch sch5545ec "$SCH5545EC_DL_url" "$SCH5545EC_DL_url_bkup" \ "$SCH5545EC_DL_hash" "$CONFIG_SMSC_SCH5545_EC_FW_FILE" \ "curl" "$SCH5545EC_bin_hash" - fi - if [ -n "$CONFIG_KBC1126_FW1" ]; then + [ -n "$CONFIG_KBC1126_FW1" ] && \ fetch kbc1126ec "$EC_url" "$EC_url_bkup" "$EC_hash" \ "$CONFIG_KBC1126_FW1" curl "$EC_FW1_hash" - fi - if [ -n "$CONFIG_KBC1126_FW2" ]; then + [ -n "$CONFIG_KBC1126_FW2" ] && \ fetch kbc1126ec "$EC_url" "$EC_url_bkup" "$EC_hash" \ "$CONFIG_KBC1126_FW2" curl "$EC_FW2_hash" - fi - if [ -n "$CONFIG_VGA_BIOS_FILE" ]; then + [ -n "$CONFIG_VGA_BIOS_FILE" ] && \ fetch e6400vga "$E6400_VGA_DL_url" "$E6400_VGA_DL_url_bkup" \ "$E6400_VGA_DL_hash" "$CONFIG_VGA_BIOS_FILE" "curl" \ "$E6400_VGA_bin_hash" - fi - if [ -n "$CONFIG_HAVE_MRC" ]; then + [ -n "$CONFIG_HAVE_MRC" ] && \ fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" \ "$CONFIG_MRC_FILE" "curl" "$MRC_bin_hash" - fi - if [ -n "$CONFIG_REFCODE_BLOB_FILE" ]; then + [ -n "$CONFIG_REFCODE_BLOB_FILE" ] && \ fetch "refcode" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" \ "$CONFIG_REFCODE_BLOB_FILE" "curl" "$REF_bin_hash" - fi - if [ -n "$CONFIG_LENOVO_TBFW_BIN" ]; then + [ -n "$CONFIG_LENOVO_TBFW_BIN" ] && \ fetch "tbfw" "$TBFW_url" "$TBFW_url_bkup" "$TBFW_hash" \ "$CONFIG_LENOVO_TBFW_BIN" "curl" "$TBFW_bin_hash" - fi - if [ -n "$CONFIG_FSP_M_FILE" ]; then + [ -n "$CONFIG_FSP_M_FILE" ] && \ fetch "fsp" "$CONFIG_FSP_FD_PATH" "$CONFIG_FSP_FD_PATH" \ "$FSPFD_hash" "$CONFIG_FSP_M_FILE" "copy" "$FSPM_bin_hash" - fi - if [ -n "$CONFIG_FSP_S_FILE" ]; then + [ -n "$CONFIG_FSP_S_FILE" ] && \ fetch "fsp" "$CONFIG_FSP_FD_PATH" "$CONFIG_FSP_FD_PATH" \ - "$FSPFD_hash" "$CONFIG_FSP_S_FILE" "copy" "$FSPS_bin_hash" - fi + "$FSPFD_hash" "$CONFIG_FSP_S_FILE" copy "$FSPS_bin_hash"; : } fetch() @@ -120,16 +109,14 @@ fetch() dlop="$6" binsum="$7" - if [ -z "$binsum" ]; then + [ -z "$binsum" ] && \ err "binsum is empty (no checksum)" "fetch" "$@" - fi _dl="$XBMK_CACHE/file/$dlsum" # internet file to extract from e.g. .exe _dl_bin="$XBMK_CACHE/file/$binsum" # extracted file e.g. me.bin - if [ "$5" = "/dev/null" ]; then + [ "$5" = "/dev/null" ] && \ return 0 - fi # an extracted vendor file will be placed in pre_dest first, for # verifying its checksum. if it matches, it is later moved to _dest @@ -141,22 +128,18 @@ fetch() dl="${dl##*../}" _cdp="$dl" - if [ ! -f "$_cdp" ]; then + [ ! -f "$_cdp" ] && \ _cdp="$cbdir/$_cdp" - fi - if [ -f "$_cdp" ]; then + [ -f "$_cdp" ] && \ dl="$_cdp" - fi dl_bkup="${dl_bkup##*../}" _cdp="$dl_bkup" - if [ ! -f "$_cdp" ]; then + [ ! -f "$_cdp" ] && \ _cdp="$cbdir/$_cdp" - fi - if [ -f "$_cdp" ]; then + [ -f "$_cdp" ] && \ dl_bkup="$_cdp"; : - fi fi # download the file (from the internet) to extract from: @@ -167,9 +150,8 @@ fetch() # skip extraction if a cached extracted file exists: ( xbget copy "$_dl_bin" "$_dl_bin" "$_dest" "$binsum" 2>/dev/null ) || : - if [ -f "$_dest" ]; then + [ -f "$_dest" ] && \ return 0 - fi x_ xbmkdir "${_dest%/*}" @@ -188,14 +170,12 @@ fetch() ( fx_ "mkdst $binsum" x_ find "${_pre_dest%/*}" -type f ) || : if ! bad_checksum "$binsum" "$_dest"; then - if [ -f "$_dest" ]; then - return 0 - fi + [ -f "$_dest" ] && \ + return 0; : fi - if [ -z "$binsum" ]; then + [ -z "$binsum" ] && \ printf "'%s': checksum undefined\n" "$_dest" 1>&2 - fi if [ -L "$_dest" ]; then printf "WARNING: '%s' is a link!\n" "$_dest" 1>&2 @@ -233,12 +213,10 @@ extract_intel_me() # maintain compatibility with older configs # because in the past, shrink was assumed - if [ -z "$MEshrink" ]; then + [ -z "$MEshrink" ] && \ MEshrink="y" - fi - if [ "$MEshrink" != "y" ] && [ "$MEshrink" != "n" ]; then + [ "$MEshrink" != "y" ] && [ "$MEshrink" != "n" ] && \ err "MEshrink set badly on '$board' vendor config" - fi if [ "$ME11bootguard" = "y" ]; then if [ -z "$ME11delta" ] || [ -z "$ME11version" ] || \ @@ -268,13 +246,10 @@ extract_intel_me() # must be called inside a subshell. find_me() { - if [ -f "$_metmp" ]; then - # we found me.bin, so we stop searching - - exit 1 - elif [ -L "$1" ]; then - return 0 - fi + [ -f "$_metmp" ] && \ + exit 1 # me.bin found + [ -L "$1" ] && \ + return 0 # symlinks disabled for security reasons _7ztest="${_7ztest}a" @@ -283,9 +258,8 @@ find_me() _r="-r" # re-locate modules _trunc="-t" # -t: truncate the ME size - if [ "$ME11bootguard" = "y" ]; then + [ "$ME11bootguard" = "y" ] && \ mfs="--whitelist MFS" - fi if [ "$MEclean" = "n" ]; then MEshrink="n" @@ -301,40 +275,29 @@ find_me() _r="" # don't re-locate ME modules _trunc="" # don't shrink the me.bin file size fi - if [ "$MEcheck" = "n" ]; then + [ "$MEcheck" = "n" ] && \ _pass="-p" # skip fptr check - fi - if [ -n "$mfs" ]; then + [ -n "$mfs" ] && \ _r="" # cannot re-locate modules if using --whitelist MFS - fi if "$mecleaner" $mfs $_r $_keep $_pass $_trunc -O "$xbtmp/a" \ -M "$_metmp" "$1" || [ -f "$_metmp" ]; then - # me.bin extracted from a full image with ifd, then shrunk - : + : # me.bin extracted from a full image with ifd, then shrunk elif "$mecleaner" $mfs $_r $_pass $_keep $_trunc -O "$_metmp" "$1" || \ [ -f "$_metmp" ]; then - # me.bin image already present, and we shrunk it - : + : # me.bin image already present, and we shrunk it elif "$me7updateparser" $_keep -O "$_metmp" "$1"; then - # thinkpad sandybridge me.bin image e.g. x220/t420 - : + : # thinkpad sandybridge me.bin image e.g. x220/t420 elif extract_archive "$1" "$_7ztest"; then - # scan newly extracted archive within extracted archive - : + : # scan newly extracted archive within extracted archive else - # could not extract anything, so we'll try the next file - return 0 + return 0 # can't extract, so try the next file fi - if [ -f "$_metmp" ]; then - # we found me.bin, so we stop searching + [ -f "$_metmp" ] && \ + exit 1 # me.bin found - exit 1 - else - # if the subshell does exit 1, we found me.bin, so exit 1 - ( fx_ find_me x_ find "$_7ztest" -type f ) || exit 1; : - fi + ( fx_ find_me x_ find "$_7ztest" -type f ) || exit 1; : # 1==me found } apply_deguard_hack() @@ -362,9 +325,8 @@ extract_archive() return 1 fi - if [ -d "${_dl}_extracted" ]; then - x_ cp -R "${_dl}_extracted" "$2" - fi + [ -d "${_dl}_extracted" ] && \ + x_ cp -R "${_dl}_extracted" "$2"; : } extract_kbc1126ec() @@ -395,9 +357,8 @@ extract_kbc1126ec_dump() err "!kbc1126 unar" "extract_kbc1126ec" "$@" fi - if [ ! -f "ec.bin" ]; then + [ ! -f "ec.bin" ] && \ x_ mv Rom.bin ec.bin - fi if x_ e ec.bin f; then x_ "$kbc1126_ec_dump" ec.bin @@ -442,9 +403,8 @@ extract_sch5545ec() # https://pcsupport.lenovo.com/us/en/products/laptops-and-netbooks/thinkpad-t-series-laptops/thinkpad-t480-type-20l5-20l6/20l5/solutions/ht508988 extract_tbfw() { - if [ -z "$TBFW_size" ]; then + [ -z "$TBFW_size" ] && \ err "$board: TBFW_size unset" "extract_tbfw" "$@" - fi fx_ copytb x_ find "$appdir" -type f -name "TBT.bin" } @@ -474,11 +434,10 @@ setvfile() eval "$vcmd && do_getvfile=\"y\"" - if [ "$do_getvfile" = "y" ]; then + [ "$do_getvfile" = "y" ] && \ if getvfile "$@"; then return 0 - fi - fi + fi; : done && return 1; : } @@ -527,9 +486,8 @@ bootstrap() x_ ./mk -b uefitool x_ ./mk -b libarchive # for bsdtar and bsdunzip - if [ -d "${kbc1126_ec_dump%/*}" ]; then + [ -d "${kbc1126_ec_dump%/*}" ] && \ x_ make -C "$cbdir/util/kbc1126" - fi if [ -n "$MRC_refcode_cbtree" ]; then cbfstoolref="elf/coreboot/$MRC_refcode_cbtree/cbfstool" @@ -543,17 +501,15 @@ prep() _xromname="${1##*/}" _xromnew="${_xrom%/*}/${_xromname#"$vfix"}" - if [ "$nuke" = "nuke" ]; then + [ "$nuke" = "nuke" ] && \ _xromnew="${_xrom%/*}/$vfix${_xrom##*/}" - fi if e "$_xrom" f missing; then return 0 fi - if [ -z "${_xromname#"$vfix"}" ]; then + [ -z "${_xromname#"$vfix"}" ] && \ err "$_xromname / $vfix: name match" "prep" "$@" - fi # Remove the prefix and 1-byte pad if [ "${_xromname#"$vfix"}" != "$_xromname" ] \ @@ -570,10 +526,7 @@ prep() fi if ! add_vfiles "$_xrom"; then - # no need to insert files. we will later - # still process MAC addresses as required - - return 1 + return 1 # no need to insert files fi if [ "$nuke" = "nuke" ]; then @@ -586,9 +539,8 @@ mksha512() { build_sbase - if [ "${1%/*}" != "$1" ]; then + [ "${1%/*}" != "$1" ] && \ x_ cd "${1%/*}" - fi x_ "$sha512sum" ./"${1##*/}" >> "$2" || \ err "!sha512sum \"$1\" > \"$2\"" "mksha512" "$@" @@ -600,47 +552,36 @@ add_vfiles() if [ "$has_hashes" != "y" ] && [ "$nuke" != "nuke" ]; then printf "'%s' has no hash file. Skipping.\n" "$archive" 1>&2 - return 1 elif [ "$has_hashes" = "y" ] && [ "$nuke" = "nuke" ]; then printf "'%s' has a hash file. Skipping nuke.\n" "$archive" 1>&2 - return 1 fi - if [ -n "$CONFIG_HAVE_REFCODE_BLOB" ]; then + [ -n "$CONFIG_HAVE_REFCODE_BLOB" ] && \ vfile "fallback/refcode" "$CONFIG_REFCODE_BLOB_FILE" "stage" - fi - if [ "$CONFIG_HAVE_MRC" = "y" ]; then + [ "$CONFIG_HAVE_MRC" = "y" ] && \ vfile "mrc.bin" "$CONFIG_MRC_FILE" "mrc" "0xfffa0000" - fi - if [ "$CONFIG_HAVE_ME_BIN" = "y" ]; then + [ "$CONFIG_HAVE_ME_BIN" = "y" ] && \ vfile IFD "$CONFIG_ME_BIN_PATH" me - fi - if [ -n "$CONFIG_KBC1126_FW1" ]; then + [ -n "$CONFIG_KBC1126_FW1" ] && \ vfile ecfw1.bin "$CONFIG_KBC1126_FW1" raw \ "$CONFIG_KBC1126_FW1_OFFSET" - fi - if [ -n "$CONFIG_KBC1126_FW2" ]; then + [ -n "$CONFIG_KBC1126_FW2" ] && \ vfile ecfw2.bin "$CONFIG_KBC1126_FW2" raw \ "$CONFIG_KBC1126_FW2_OFFSET" - fi - if [ -n "$CONFIG_VGA_BIOS_FILE" ] && [ -n "$CONFIG_VGA_BIOS_ID" ]; then + [ -n "$CONFIG_VGA_BIOS_FILE" ] && [ -n "$CONFIG_VGA_BIOS_ID" ] && \ vfile "pci$CONFIG_VGA_BIOS_ID.rom" "$CONFIG_VGA_BIOS_FILE" \ optionrom - fi - if [ "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" = "y" ] && \ - [ -n "$CONFIG_SMSC_SCH5545_EC_FW_FILE" ]; then + [ "$CONFIG_INCLUDE_SMSC_SCH5545_EC_FW" = "y" ] && \ + [ -n "$CONFIG_SMSC_SCH5545_EC_FW_FILE" ] && \ vfile sch5545_ecfw.bin "$CONFIG_SMSC_SCH5545_EC_FW_FILE" raw - fi - if [ -z "$CONFIG_FSP_USE_REPO" ] && [ -z "$CONFIG_FSP_FULL_FD" ] && \ - [ -n "$CONFIG_FSP_M_FILE" ]; then + [ -z "$CONFIG_FSP_USE_REPO" ] && [ -z "$CONFIG_FSP_FULL_FD" ] && \ + [ -n "$CONFIG_FSP_M_FILE" ] && \ vfile "$CONFIG_FSP_M_CBFS" "$CONFIG_FSP_M_FILE" fsp --xip - fi - if [ -z "$CONFIG_FSP_USE_REPO" ] && [ -z "$CONFIG_FSP_FULL_FD" ] && \ - [ -n "$CONFIG_FSP_S_FILE" ]; then + [ -z "$CONFIG_FSP_USE_REPO" ] && [ -z "$CONFIG_FSP_FULL_FD" ] && \ + [ -n "$CONFIG_FSP_S_FILE" ] && \ vfile "$CONFIG_FSP_S_CBFS" "$CONFIG_FSP_S_FILE" fsp - fi xchanged="y" @@ -649,9 +590,8 @@ add_vfiles() vfile() { - if [ "$2" = "/dev/null" ]; then + [ "$2" = "/dev/null" ] && \ return 0 - fi cbfsname="$1" _dest="${2##*../}" @@ -665,9 +605,8 @@ vfile() err "$rom: offset given but empty (undefined)" "vfile" "$@" fi - if [ "$nuke" != "nuke" ]; then + [ "$nuke" != "nuke" ] && \ x_ e "$_dest" f - fi if [ "$cbfsname" = "IFD" ]; then if [ "$nuke" = "nuke" ]; then