diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/get.sh | 82 | ||||
-rw-r--r-- | include/init.sh | 61 | ||||
-rw-r--r-- | include/inject.sh | 50 | ||||
-rw-r--r-- | include/lib.sh | 51 | ||||
-rw-r--r-- | include/mrc.sh | 14 | ||||
-rw-r--r-- | include/release.sh | 16 | ||||
-rw-r--r-- | include/rom.sh | 77 | ||||
-rw-r--r-- | include/tree.sh | 232 | ||||
-rw-r--r-- | include/vendor.sh | 194 |
9 files changed, 572 insertions, 205 deletions
diff --git a/include/get.sh b/include/get.sh index 9b1c69b4..3c30b6d3 100644 --- a/include/get.sh +++ b/include/get.sh @@ -3,8 +3,15 @@ # Copyright (c) 2020-2021,2023-2025 Leah Rowe <leah@libreboot.org> # Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com> -eval "`setvars "" loc url bkup_url subcurl subhash subgit subgit_bkup \ - depend subcurl_bkup`" +depend="" +loc="" +url="" +bkup_url="" +subgit="" +subgit_bkup="" +subcurl="" +subcurl_bkup="" +subhash="" tmpgit="$xbtmp/gitclone" tmpgitcache="$xbtmp/tmpgit" @@ -20,14 +27,19 @@ fetch_targets() fetch_project() { - xtree="" + xgcctree="" - eval "`setcfg "config/git/$project/pkg.cfg"`" + . "config/git/$project/pkg.cfg" || \ + err "Can't read config 'config/git/$project/pkg.cfg'" \ + "fetch_project" "@" - chkvars url bkup_url + if [ -z "$url" ] || [ -z "$bkup_url" ]; then + err "url/bkup_url not both set 'config/git/$project/pkg.cfg'" \ + "fetch_project" "$@" + fi - if [ -n "$xtree" ]; then - x_ ./mk -f coreboot "$xtree" + if [ -n "$xgcctree" ]; then + x_ ./mk -f coreboot "$xgcctree" fi if [ -n "$depend" ]; then for d in $depend ; do @@ -59,7 +71,9 @@ git_prep() _patchdir="$3" _loc="$4" # $1 and $2 are gitrepo and gitrepo_backup - chkvars rev + if [ -z "$rev" ]; then + err "$project/$tree: rev not set" "git_prep" "$@" + fi xbget git "$1" "$2" "$tmpgit" "$rev" "$_patchdir" if singletree "$project" || [ $# -gt 4 ]; then @@ -76,10 +90,18 @@ fetch_submodule() { mcfgdir="$mdir/${1##*/}" - eval \ - "`setvars "" subhash subgit subgit_bkup subcurl subcurl_bkup st`" + subhash="" + subgit="" + subgit_bkup="" + subcurl="" + subcurl_bkup="" + st="" - eval "`setcfg "$mcfgdir/module.cfg" 0`" + if e "$mcfgdir/module.cfg" f missing; then + return 0 + fi + . "$mcfgdir/module.cfg" || \ + err "Can't read '$mcfgdir/module.cfg'" "fetch_submodules" "$@" if [ -n "$subgit" ] || [ -n "$subgit_bkup" ]; then st="$st git" @@ -97,7 +119,16 @@ fetch_submodule() return 0 fi - chkvars "sub${st}" "sub${st}_bkup" "subhash" + if [ "$st" = "curl" ]; then + if [ -z "$subcurl" ] || [ -z "$subcurl_bkup" ]; then + err "subcurl/subcurl_bkup not both set" \ + "fetch_submodule" "$@" + fi + elif [ -z "$subgit" ] || [ -z "$subgit_bkup" ]; then + err "subgit/subgit_bkup not both set" "fetch_submodule" "$@" + elif [ -z "$subhash" ]; then + err "subhash not set" "fetch_submodule" "$@" + fi if [ "$st" = "git" ]; then x_ rm -Rf "$tmpgit/$1" @@ -212,6 +243,7 @@ try_fetch_file() return 1 elif bad_checksum "$6" "$cached"; then x_ rm -f "$cached" + return 1 fi @@ -221,6 +253,7 @@ try_fetch_file() if bad_checksum "$6" "$5"; then x_ rm -f "$5" + return 1 elif [ ! -f "$5" ]; then return 1 @@ -280,7 +313,8 @@ bad_checksum() return 0 fi - csum="$(x_ sha512sum "$2" | awk '{print $1}')" || \ + build_sbase + csum="$(x_ "$sha512sum" "$2" | awk '{print $1}')" || \ err "!sha512 '$2' $1" bad_checksum "$@" if [ "$csum" = "$1" ]; then @@ -295,5 +329,25 @@ tmpclone() { ( x_ git clone "$1" "$2" ) || return 1 ( x_ git -C "$2" reset --hard "$3" ) || return 1 - ( fx_ "eval x_ git -C \"$2\" am" find "$4" -type f ) || return 1; : + + if [ ! -d "$4" ]; then + return 0 + fi + + tmpclone_patchlist="`mktemp || err "Can't create tmp patch list"`" || \ + err "Can't create tmp patch list" "tmpclone" "$@" + + x_ find "$4" -type f | sort > "$tmpclone_patchlist" || \ + err "Can't write patch names to '$tmpclone_patchlist'" \ + "tmpclone" "$@" + + while read -r tmpclone_patch; do + + ( x_ git -C "$2" am "$tmpclone_patch" ) || \ + err "Can't apply '$tmpclone_patch'" "tmpclone" "$@"; : + + done < "$tmpclone_patchlist" || \ + err "Can't read '$tmpclone_patchlist'" "tmpclone" "$@" + + x_ rm -f "$tmpclone_patchlist" } diff --git a/include/init.sh b/include/init.sh index f14fa5ab..72af26c3 100644 --- a/include/init.sh +++ b/include/init.sh @@ -12,21 +12,41 @@ projectname="libreboot" projectsite="https://libreboot.org/" if [ -z "${PATH+x}" ]; then -export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" + export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" fi -eval "`setvars "" board reinstall versiondate aur_notice configdir xbmkpath \ - datadir version xbmkpwd relname xbmkpwd xbtmp python pyver xbmklock \ - cvxbmk cvchk is_child basetmp`" +board="" +reinstall="" +version="" +versiondate="" +aur_notice="" +configdir="" +xbmkpath="" +datadir="" +xbmkpwd="" +relname="" +xbmkpwd="" +xbtmp="" +python="" +pyver="" +xbmklock="" +checkvarsxbmk="" +checkvarschk="" +is_child="" +basetmp="" + +sha512sum="util/sbase/sha512sum" xbmk_init() { xbmkpwd="`pwd || err "Cannot generate PWD"`" || err "!" xbmk_init "$@" xbmklock="$xbmkpwd/lock" basetmp="$xbmkpwd/xbmkwd" + sha512sum="$xbmkpwd/util/sbase/sha512sum" if [ $# -gt 0 ] && [ "$1" = "dependencies" ]; then x_ xbmkpkg "$@" + exit 0 fi @@ -55,9 +75,13 @@ xbmkpkg() reinstall="$3" fi - eval "`setcfg "config/dependencies/$2"`" + . "config/dependencies/$2" || \ + err "Can't read 'config/dependencies/$2'" "xbmkpkg" "$@" + + if [ -z "$pkg_add" ] || [ -z "$pkglist" ]; then + err "pkg_add/pkglist not both set" "xbmkpkg" "$@" + fi - chkvars pkg_add pkglist x_ $pkg_add $pkglist if [ -n "$aur_notice" ]; then @@ -76,11 +100,11 @@ xbmk_get_version() err "can't read versiondate" xbmk_get_version "$@" fi - if [ -f ".version" ]; then - chkvars version + if [ -f ".version" ] && [ -z "$version" ]; then + err "version not set" "xbmk_get_version" "$@" fi - if [ -f ".versiondate" ]; then - chkvars versiondate + if [ -f ".versiondate" ] && [ -z "$versiondate" ]; then + err "versiondate not set" "xbmk_get_version" "$@" fi if [ ! -e ".git" ] && [ ! -f ".version" ]; then @@ -279,7 +303,10 @@ xbmk_set_version() --pretty='%ct' HEAD)" || versiondate="$versiondate_" fi - chkvars version versiondate + if [ -z "$version" ] || [ -z "$versiondate" ]; then + err "version and/or versiondate unset" "xbmk_set_version" "$@" + fi + update_xbmkver "." relname="$projectname-$version" @@ -353,7 +380,9 @@ pybin() if [ -e "$pypath" ] && [ ! -d "$pypath" ] && \ [ -x "$pypath" ]; then + printf "%s\n" "$pypath" + return 0 fi fi @@ -363,7 +392,9 @@ pybin() [ $venv -gt 0 ] && for pypath in "/usr/local/bin" "/usr/bin"; do if [ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \ [ -x "$pypath/$1" ]; then + printf "%s/%s\n" "$pypath" "$1" + return 0 fi done && return 1 @@ -377,9 +408,11 @@ pybin() xbmk_git_init() { for gitarg in "--global user.name" "--global user.email"; do - gitcmd="git config $gitarg"; $gitcmd 1>/dev/null 2>/dev/null \ - || err "Run this first: $gitcmd \"your ${gitcmd##*.}\"" \ - "xbmk_git_init" "$@" + gitcmd="git config $gitarg" + if ! $gitcmd 1>/dev/null 2>/dev/null; then + err "Run this first: $gitcmd \"your ${gitcmd##*.}\"" \ + "xbmk_git_init" "$@" + fi done if [ -L ".git" ]; then diff --git a/include/inject.sh b/include/inject.sh index 444915a1..90528ac0 100644 --- a/include/inject.sh +++ b/include/inject.sh @@ -9,16 +9,25 @@ tmpromdel="$XBMK_CACHE/DO_NOT_FLASH" nvm="util/nvmutil/nvm" ifdtool="elf/coreboot/default/ifdtool" -cv="CONFIG_GBE_BIN_PATH" -if [ -n "$cvxbmk" ]; then - cv="$cv $cvxbmk" +checkvars="CONFIG_GBE_BIN_PATH" +if [ -n "$checkvarsxbmk" ]; then + checkvars="$checkvars $checkvarsxbmk" fi -if [ -n "$cvchk" ]; then - cv="$cv $cvchk" +if [ -n "$checkvarschk" ]; then + checkvars="$checkvars $checkvarschk" fi -eval "`setvars "" archive boarddir IFD_platform ifdprefix tree new_mac \ - tmpromdir board xchanged $cv`" +archive="" +boarddir="" +IFD_platform="" +ifdprefix="" +tree="" +new_mac="" +tmpromdir="" +board="" +xchanged="" + +eval "`setvars "" $checkvars`" inject() { @@ -58,7 +67,9 @@ inject() check_release if check_target; then - patch_release || return 0 + if ! patch_release; then + return 0 + fi fi if [ "$xchanged" = "y" ]; then remktar @@ -113,8 +124,12 @@ check_target() boarddir="$cbcfgsdir/$board" - eval "`setcfg "$boarddir/target.cfg"`" - chkvars tree + . "$boarddir/target.cfg" || \ + err "Can't read '$boarddir/target.cfg'" "check_target" "$@" + + if [ -z "$tree" ]; then + err "tree unset in '$boarddir/target.cfg'" "check_target" "$@" + fi x_ ./mk -d coreboot "$tree" @@ -141,6 +156,7 @@ patch_release() if e "$tmpromdir/$_hashes" f; then has_hashes="y" hashfile="$_hashes" + break fi done @@ -157,14 +173,22 @@ readkconfig() x_ rm -f "$xbtmp/cbcfg" fx_ scankconfig x_ find "$boarddir/config" -type f - eval "`setcfg "$xbtmp/cbcfg" 1`" - setvfile "$@" || return 1; : + if e "$xbtmp/cbcfg" f missing; then + return 1 + fi + + . "$xbtmp/cbcfg" || \ + err "Can't read '$xbtmp/cbcfg'" "readkconfig" "$@" + + if ! setvfile "$@"; then + return 1 + fi } scankconfig() { - for cbc in $cv; do + for cbc in $checkvars; do grep "$cbc" "$1" 2>/dev/null 1>>"$xbtmp/cbcfg" || : done } diff --git a/include/lib.sh b/include/lib.sh index 2ff410eb..3d205fa9 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -91,36 +91,21 @@ setvars() _setvars="" if [ $# -lt 2 ]; then - printf "err \"setvars: too few args\\n\"" + return 0 else val="$1" + shift 1 + while [ $# -gt 0 ]; do printf "%s=\"%s\"\n" "$1" "$val" + shift 1 done fi } -setcfg() -{ - if [ $# -gt 1 ]; then - printf "e \"%s\" f missing && return %s;\n" "$1" "$2" - else - printf "e \"%s\" f not && err \"Missing config '$1'\";\n" "$1" - fi - printf ". \"%s\" || err \"Could not read config '$1'\";\n" "$1" -} - -chkvars() -{ - while [ $# -gt 0 ]; do - eval "[ -n \"\${$1+x}\" ] || err \"$1 unset\"" - eval "[ -n \"\$$1\" ] || err \"$1 unset\"; shift 1; :" - done; : -} - # return 0 if project is single-tree, otherwise 1 # e.g. coreboot is multi-tree, so 1 singletree() @@ -145,6 +130,7 @@ findpath() fi printf "%s\n" "$found" + shift 1 done } @@ -176,6 +162,13 @@ unpad_one_byte() x_ mv "$unpaddedfile" "$1" } +build_sbase() +{ + if [ ! -f "$sha512sum" ]; then + x_ make -C "$xbmkpwd/util/sbase" + fi +} + fx_() { xchk fx_ "$@" @@ -184,7 +177,9 @@ fx_() xfile="`mktemp || err "can't create tmpfile"`" || \ err "can't make tmpfile" "fx_" "$@" - x_ rm -f "$xfile" && x_ touch "$xfile" + x_ rm -f "$xfile" + x_ touch "$xfile" + shift 1 "$@" 2>/dev/null | sort 1>"$xfile" 2>/dev/null || \ @@ -197,7 +192,12 @@ fx_() dx_() { xchk dx_ "$@" - [ ! -f "$2" ] || while read -r fx; do + + if [ ! -f "$2" ]; then + return 0 + fi + + while read -r fx; do $1 "$fx" || return 1; : done < "$2" || err "cannot read '$2'" "dx_" "$@"; : } @@ -227,13 +227,13 @@ err() if [ $# -eq 1 ]; then printf "ERROR %s: %s\n" "$0" "$1" 1>&2 || : elif [ $# -gt 1 ]; then - printf "ERROR %s: %s: in command/function with arguments: " \ - "$0" "$1" 1>&2 + printf "ERROR %s: %s: in command with args: " "$0" "$1" 1>&2 shift 1 xprintf "$@" 1>&2 else printf "ERROR, but no arguments provided to err\n" 1>&2 fi + exit 1 } @@ -242,8 +242,11 @@ xprintf() xprintfargs=0 while [ $# -gt 0 ]; do printf "\"%s\"" "$1" + if [ $# -gt 1 ]; then + printf " " + fi + xprintfargs=1 - [ $# -gt 1 ] && printf " "; : shift 1 done if [ $xprintfargs -gt 0 ]; then diff --git a/include/mrc.sh b/include/mrc.sh index 6bc8632c..92241b22 100644 --- a/include/mrc.sh +++ b/include/mrc.sh @@ -18,7 +18,10 @@ 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: - chkvars cbfstoolref + if [ -z "$cbfstoolref" ]; then + err "cbfstoolref not set" "extract_refcode" "$@" + fi + x_ mkdir -p "${_pre_dest%/*}" x_ "$cbfstoolref" "$appdir/bios.bin" extract \ @@ -35,7 +38,12 @@ extract_refcode() extract_mrc() { - chkvars "MRC_board" "CONFIG_MRC_FILE" + if [ -z "$MRC_board" ]; then + err "MRC_board unset" "extract_mrc" "$@" + elif [ -z "$CONFIG_MRC_FILE" ]; then + err "CONFIG_MRC_FILE unset" "extract_mrc" "$@" + fi + SHELLBALL="chromeos-firmwareupdate-$MRC_board" ( @@ -52,10 +60,12 @@ extract_mrc() extract_partition() { printf "Extracting ROOT-A partition\n" + ROOTP=$( printf "unit\nB\nprint\nquit\n" | \ parted "${1%.zip}" 2>/dev/null | grep "ROOT-A" ) START=$(( $( echo $ROOTP | cut -f2 -d\ | tr -d "B" ) )) + SIZE=$(( $( echo $ROOTP | cut -f4 -d\ | tr -d "B" ) )) x_ dd if="${1%.zip}" of="root-a.ext2" bs=1024 skip=$(( $START / 1024 )) \ diff --git a/include/release.sh b/include/release.sh index b4a9ea98..35a9c711 100644 --- a/include/release.sh +++ b/include/release.sh @@ -2,7 +2,11 @@ # Copyright (c) 2023-2025 Leah Rowe <leah@libreboot.org> -eval "`setvars "" reldir reldest vdir rsrc relmode`" +reldir="" +reldest="" +vdir="" +rsrc="" +relmode="" release() { @@ -10,7 +14,8 @@ release() reldir="release" - while getopts m: option; do + while getopts m: option + do if [ -z "$OPTARG" ]; then err "empty argument not allowed" "release" "$@" fi @@ -71,6 +76,8 @@ prep_release() prep_release_src() { + x_ cp -R "util/sbase" "util/sbase2" + x_ ./mk -f fx_ "x_ rm -Rf" x_ find . -name ".git" @@ -87,7 +94,7 @@ nuke() if [ -d "${r%/*}" ]; then x_ cd "${r%/*}" - dx_ "eval [ -L \"\$fx\" ] || x_ rm -Rf" "$rsrc/$1" + dx_ "x_ rm -Rf" "$rsrc/$1" fi } @@ -98,7 +105,8 @@ prep_release_tarball() err "can't create '$rsrc/CHANGELOG'" "prep_release_tarball" "$@" x_ rm -f "$rsrc/lock" "$rsrc/cache" - x_ rm -Rf "$rsrc/xbmkwd" + x_ rm -Rf "$rsrc/xbmkwd" "$rsrc/util/sbase" + x_ mv "$rsrc/util/sbase2" "$rsrc/util/sbase" ( x_ cd "${rsrc%/*}" diff --git a/include/rom.sh b/include/rom.sh index 2dd16c70..4de49eee 100644 --- a/include/rom.sh +++ b/include/rom.sh @@ -12,11 +12,11 @@ buildser() { if [ "$1" = "pico" ]; then x_ cmake -DPICO_BOARD="$2" \ - -DPICO_SDK_PATH="$picosdk" -B "$sersrc/build" "$sersrc" && \ - x_ cmake --build "$sersrc/build" + -DPICO_SDK_PATH="$picosdk" -B "$sersrc/build" "$sersrc" + x_ cmake --build "$sersrc/build" elif [ "$1" = "stm32" ]; then - x_ make -C "$sersrc" libopencm3-just-make \ - BOARD=$2 && x_ make -C "$sersrc" BOARD=$2 + x_ make -C "$sersrc" libopencm3-just-make BOARD=$2 + x_ make -C "$sersrc" BOARD=$2 fi x_ mkdir -p "bin/serprog_$1" @@ -25,7 +25,7 @@ buildser() copyps1bios() { - if [ "$dry" = ":" ]; then + if [ "$if_not_dry_build" = ":" ]; then return 0 fi @@ -45,11 +45,16 @@ mkpayload_grub() grub_modules="" grub_install_modules="" - $dry eval "`setcfg "$grubdata/module/$tree"`" + if [ "$if_not_dry_build" = ":" ]; then + return 0 + fi - $dry x_ rm -f "$srcdir/grub.elf" + . "$grubdata/module/$tree" || \ + err "Can't read '$grubdata/module/$tree'" "mkpayload_grub" "$@" - $dry x_ "$srcdir/grub-mkstandalone" \ + x_ rm -f "$srcdir/grub.elf" + + x_ "$srcdir/grub-mkstandalone" \ --grub-mkimage="$srcdir/grub-mkimage" \ -O i386-coreboot -o "$srcdir/grub.elf" -d "${srcdir}/grub-core/" \ --fonts= --themes= --locales= --modules="$grub_modules" \ @@ -64,7 +69,9 @@ corebootpremake() return 0 fi - $dry cook_coreboot_config + $if_not_dry_build \ + cook_coreboot_config + fx_ check_coreboot_util printf "cbfstool\nifdtool\n" printf "%s\n" "${version%%-*}" > "$srcdir/.coreboot-version" || \ @@ -106,6 +113,7 @@ check_coreboot_util() # TODO: is this rm command needed? x_ rm -Rf "$utilelfdir" + return 0 elif [ -n "$mode" ] || [ -f "$utilelfdir/$1" ]; then return 0 @@ -125,7 +133,8 @@ coreboot_pad_one_byte() return 0 fi - $dry pad_one_byte "$srcdir/build/coreboot.rom" + $if_not_dry_build \ + pad_one_byte "$srcdir/build/coreboot.rom" } mkcorebootbin() @@ -134,8 +143,11 @@ mkcorebootbin() return 0 fi - $dry check_coreboot_util cbfstool - $dry check_coreboot_util ifdtool + $if_not_dry_build \ + check_coreboot_util cbfstool + + $if_not_dry_build \ + check_coreboot_util ifdtool for y in "$target_dir/config"/*; do defconfig="$y" @@ -169,8 +181,11 @@ mkcorebootbin_real() fi elfrom="$elfrom/coreboot.rom" - $dry x_ cp "$elfrom" "$tmprom" - $dry unpad_one_byte "$tmprom" + $if_not_dry_build \ + x_ cp "$elfrom" "$tmprom" + + $if_not_dry_build \ + unpad_one_byte "$tmprom" if [ -n "$payload_uboot" ] && [ "$payload_uboot" != "amd64" ] && \ [ "$payload_uboot" != "i386" ] && [ "$payload_uboot" != "arm64" ] @@ -190,8 +205,9 @@ mkcorebootbin_real() payload_seabios="y" fi if [ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "arm64" ]; then - $dry err "$target: U-Boot(arm) and SeaBIOS/GRUB both enabled" \ - "mkcorebootbin_real" "$@" + $if_not_dry_build \ + err "$target: U-Boot arm and SeaBIOS/GRUB both enabled" \ + "mkcorebootbin_real" "$@" fi if [ -z "$grub_scan_disk" ]; then @@ -216,18 +232,21 @@ mkcorebootbin_real() payload_grubsea="n" fi - if $dry grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then + if $if_not_dry_build grep "CONFIG_PAYLOAD_NONE=y" "$defconfig"; then if [ "$payload_seabios" = "y" ]; then pname="seabios" - $dry add_seabios + $if_not_dry_build \ + add_seabios fi if [ "$payload_uboot" = "arm64" ]; then pname="uboot" - $dry add_uboot + $if_not_dry_build \ + add_uboot fi else pname="custom" - $dry cprom + $if_not_dry_build \ + cprom fi; : } @@ -244,7 +263,8 @@ add_seabios() # we must add u-boot first, because it's added as a flat # binary at a specific offset for secondary program loader - $dry add_uboot + $if_not_dry_build \ + add_uboot fi _seabioself="elf/seabios/default/default/$initmode/bios.bin.elf" @@ -341,12 +361,13 @@ mkseagrub() add_uboot() { if [ "$displaymode" = "txtmode" ]; then - printf "cb/%s: Cannot use U-Boot in text mode\n" \ - "$target" 1>&2 + printf "cb/%s: Can't use U-Boot in text mode\n" "$target" 1>&2 + return 0 elif [ "$initmode" = "normal" ]; then - printf "cb/%s: Cannot use U-Boot in normal initmode\n" \ + printf "cb/%s: Can't use U-Boot in normal initmode\n" \ "$target" 1>&2 + return 0 fi @@ -458,7 +479,11 @@ mkcoreboottar() { if [ "$target" != "$tree" ] && [ "$XBMK_RELEASE" = "y" ] && \ [ "$release" != "n" ]; then - $dry mkrom_tarball "bin/$target" && \ - $dry x_ ./mk inject "bin/${relname}_${target}.tar.xz" nuke; : + + $if_not_dry_build \ + mkrom_tarball "bin/$target" + + $if_not_dry_build \ + x_ ./mk inject "bin/${relname}_${target}.tar.xz" nuke fi } diff --git a/include/tree.sh b/include/tree.sh index 8b126240..254f738d 100644 --- a/include/tree.sh +++ b/include/tree.sh @@ -4,11 +4,50 @@ # Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com> # Copyright (c) 2023-2025 Leah Rowe <leah@libreboot.org> -eval "`setvars "" xarch srcdir premake gnatdir xlang mode makeargs elfdir cmd \ - project target target_dir targets xtree _f release bootstrapargs mkhelper \ - autoconfargs listfile autogenargs btype rev build_depend gccdir cmakedir \ - defconfig postmake mkhelpercfg dry dest_dir mdir cleanargs gccver gccfull \ - gnatver gnatfull do_make badhash badtghash tree forcepull`" +# flag e.g. ./mk -b <-- mkflag would be "b" +flag="" + +xarch="" +srcdir="" +premake="" +gnatdir="" +xlang="" +mode="" +makeargs="" +elfdir="" +cmd="" +project="" +target="" +target_dir="" +targets="" +xgcctree="" +release="" +bootstrapargs="" +mkhelper="" +autoconfargs="" +listfile="" +autogenargs="" +buildtype="" +rev="" +build_depend="" +gccdir="" +cmakedir="" +defconfig="" +postmake="" +mkhelpercfg="" +if_not_dry_build="" +dest_dir="" +mdir="" +cleanargs="" +gccver="" +gccfull="" +gnatver="" +gnatfull="" +do_make="" +badhash="" +badtghash="" +tree="" +forcepull="" trees() { @@ -16,24 +55,24 @@ trees() while getopts $flags option do - if [ -n "$_f" ]; then + if [ -n "$flag" ]; then err "only one flag is permitted" "trees" "$@" fi - _f="$1" + flag="$1" # the "mode" variable is affixed to a make command, example: # ./mk -m coreboot does: make menuconfig -C src/coreboot/tree - case "$_f" in + case "$flag" in -d) # -d is similar to -b, except that # a large number of operations will be - # skipped. these are "dry build" scenarios + # skipped. these are "if_not_dry_build build" scenarios # where only a subset of build tasks are done, - # and $dry is prefixed to skipped commands + # and $if_not_dry_build is prefixed to skipped commands - dry=":" + if_not_dry_build=":" ;; -b) : ;; -u) mode="oldconfig" ;; @@ -42,11 +81,11 @@ trees() -x) mode="crossgcc-clean" ;; -f) # download source code for a project do_make="n" # lets us know not to build anything - dry=":" + if_not_dry_build=":" ;; -F) # same as -F, but don't skip git fetch/pull on cache do_make="n" # lets us know not to build anything - dry=":" + if_not_dry_build=":" forcepull="y" ;; -s) mode="savedefconfig" ;; @@ -57,6 +96,7 @@ trees() if [ -z "${OPTARG+x}" ]; then shift 1 + break fi @@ -66,11 +106,13 @@ trees() shift 2 done - if [ -z "$_f" ]; then + if [ -z "$flag" ]; then err "missing flag ($flags)" "trees" "$@" elif [ -z "$project" ]; then - fx_ "x_ ./mk $_f" x_ ls -1 config/git + 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 @@ -94,7 +136,9 @@ trees() targets="$*" cmd="build_targets $targets" - singletree "$project" && cmd="build_project" + if singletree "$project"; then + cmd="build_project" + fi remkdir "${tmpgit%/*}" } @@ -104,17 +148,22 @@ build_project() if ! configure_project "$configdir"; then return 0 elif [ -f "$listfile" ]; then - $dry elfcheck || return 0; : + if ! $if_not_dry_build elfcheck; then + return 0 + fi fi if [ "$mode" = "distclean" ]; then mode="clean" fi - run_make_command || return 0 + if ! run_make_command; then + return 0 + fi if [ -z "$mode" ]; then - $dry copy_elf; : + $if_not_dry_build \ + copy_elf; : fi } @@ -134,7 +183,9 @@ build_targets() if [ "$x" = "list" ]; then x_ ls -1 "config/$project" + listfile="" + break fi @@ -161,7 +212,10 @@ handle_defconfig() return 0 fi - chkvars tree + if [ -z "$tree" ]; then + err "$configdir: 'tree' not set" "handle_defconfig" "$@" + fi + srcdir="src/$project/$tree" if [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ]; then @@ -170,9 +224,9 @@ handle_defconfig() for y in "$target_dir/config"/* do - if [ "$_f" != "-d" ] && [ ! -f "$y" ]; then + if [ "$flag" != "-d" ] && [ ! -f "$y" ]; then continue - elif [ "$_f" != "-d" ]; then + elif [ "$flag" != "-d" ]; then defconfig="$y" fi @@ -182,9 +236,9 @@ handle_defconfig() if [ -z "$mode" ]; then for _xarch in $xarch; do - if [ -n "$_xarch" ] - then - $dry check_cross_compiler "$_xarch" + if [ -n "$_xarch" ]; then + $if_not_dry_build \ + check_cross_compiler "$_xarch" fi done; : fi @@ -192,27 +246,42 @@ handle_defconfig() handle_makefile if [ -z "$mode" ]; then - $dry copy_elf + $if_not_dry_build \ + copy_elf fi done; : } configure_project() { - eval "`setvars "" cleanargs build_depend autoconfargs xtree postmake \ - makeargs btype mkhelper bootstrapargs premake release xlang xarch \ - badhash badtghash`" + cleanargs="" + build_depend="" + autoconfargs="" + xgcctree="" + postmake="" + makeargs="" + buildtype="" + mkhelper="" + bootstrapargs="" + premake="" + release="" + xlang="" + xarch="" + badhash="" + badtghash="" _tcfg="$1/target.cfg" if [ ! -f "$_tcfg" ]; then - btype="auto" + buildtype="auto" fi # globally initialise all variables for a source tree / target: if e "$datadir/mkhelper.cfg" f; then - eval "`setcfg "$datadir/mkhelper.cfg"`" + . "$datadir/mkhelper.cfg" || \ + err "Can't read '$datadir/mkhelper.cfg'" \ + "configure_project" "$@" fi # override target/tree specific variables from per-target config: @@ -231,9 +300,10 @@ configure_project() rev="" tree="" - eval "`setcfg "$_tcfg"`" + . "$_tcfg" || \ + err "Can't read '$_tcfg'" "configure_project" "$@" - if [ "$_f" = "-d" ]; then + if [ "$flag" = "-d" ]; then build_depend="" # dry run fi if [ "$cmd" = "build_project" ]; then @@ -263,12 +333,13 @@ configure_project() if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then return 1 fi - if [ -n "$btype" ] && [ "${mode%config}" != "$mode" ]; then + if [ -n "$buildtype" ] && [ "${mode%config}" != "$mode" ]; then return 1 fi if [ -z "$mode" ]; then - $dry build_dependencies; : + $if_not_dry_build \ + build_dependencies fi mdir="$xbmkpwd/config/submodule/$project" @@ -301,14 +372,16 @@ build_dependencies() bd_tree="${bd##*/}" if [ -z "$bd_project" ]; then - $dry err "$project/$tree: !bd '$bd'" \ - "build_dependencies" "$@" + $if_not_dry_build \ + err "$project/$tree: !bd '$bd'" \ + "build_dependencies" "$@" fi if [ "${bd##*/}" = "$bd" ]; then bd_tree="" fi if [ -n "$bd_project" ]; then - $dry x_ ./mk -b $bd_project $bd_tree; : + $if_not_dry_build \ + x_ ./mk -b $bd_project $bd_tree; : fi done; : } @@ -362,19 +435,20 @@ project_up_to_date() x_ mkdir -p "$XBMK_CACHE/$hashdir" if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then - read -r old_hash < \ - "$XBMK_CACHE/$hashdir/$project$hashname" \ + read -r old_hash < "$XBMK_CACHE/$hashdir/$project$hashname" \ || err \ "$hashdir: err '$XBMK_CACHE/$hashdir/$project$hashname'" \ "project_up_to_date" "$hashdir" "$hashname" "$badhashvar" \ "$@" fi - fx_ "x_ sha512sum" find "$@" -type f -not -path "*/.git*/*" | awk \ - '{print $1}' > "$xbtmp/tmp.hash" || err "!h $project $hashdir" \ + build_sbase + fx_ "x_ util/sbase/sha512sum" find "$@" -type f -not -path \ + "*/.git*/*" | awk '{print $1}' > "$xbtmp/tmp.hash" || \ + err "!h $project $hashdir" \ "project_up_to_date" "$hashdir" "$hashname" "$badhashvar" "$@" - hash="$(x_ sha512sum "$xbtmp/tmp.hash" | awk '{print $1}' || \ + hash="$(x_ "$sha512sum" "$xbtmp/tmp.hash" | awk '{print $1}' || \ err)" || err "$hashname: Can't read sha512 of '$xbtmp/tmp.hash'" \ "project_up_to_date" "$hashdir" "$hashname" "$badhashvar" "$@" @@ -397,8 +471,8 @@ check_cross_compiler() if [ "$project" != "coreboot" ]; then cbdir="src/coreboot/default" fi - if [ -n "$xtree" ]; then - cbdir="src/coreboot/$xtree" + if [ -n "$xgcctree" ]; then + cbdir="src/coreboot/$xgcctree" fi xfix="${1%-*}" @@ -421,14 +495,19 @@ check_cross_compiler() fi if [ -f "$xgccfile" ]; then - return 0 # a build already exists + # skip the build, because a build already exists: + + return 0 fi 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" - remkdir "$xbtmp/gnupath" # reset hostcc + # reset hostcc in PATH: + remkdir "$xbtmp/gnupath" } # fix mismatching gcc/gnat versions on debian trixie/sid. as of december 2024, @@ -538,13 +617,17 @@ gnu_setver() check_defconfig() { if [ ! -f "$defconfig" ]; then - $dry err "$project/$target: missing defconfig" \ - "check_defconfig" "$@" + $if_not_dry_build \ + err "$project/$target: no config" "check_defconfig" "$@" fi dest_dir="$elfdir/$tree/$target/${defconfig#"$target_dir/config/"}" - $dry elfcheck || return 1; : # skip build if a previous one exists + # skip build if a previous one exists: + + if ! $if_not_dry_build elfcheck; then + return 1 + fi } elfcheck() @@ -556,8 +639,10 @@ elfcheck() handle_makefile() { - $dry check_makefile "$srcdir" && \ - $dry x_ make -C "$srcdir" $cleanargs clean + if $if_not_dry_build check_makefile "$srcdir"; then + $if_not_dry_build \ + x_ make -C "$srcdir" $cleanargs clean + fi if [ -f "$defconfig" ]; then x_ cp "$defconfig" "$srcdir/.config" @@ -573,12 +658,14 @@ handle_makefile() fi if [ "${mode%config}" != "$mode" ]; then - $dry x_ cp "$srcdir/$_copy" "$defconfig"; : + $if_not_dry_build \ + x_ cp "$srcdir/$_copy" "$defconfig"; : fi if [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \ [ "$mode" = "distclean" ]; then - $dry x_ git -C "$srcdir" $cleanargs clean -fdx; : + $if_not_dry_build \ + x_ git -C "$srcdir" $cleanargs clean -fdx; : fi } @@ -588,30 +675,46 @@ run_make_command() x_ $premake fi - $dry check_cmake "$srcdir" && [ -z "$mode" ] && \ - $dry check_autoconf "$srcdir" - $dry check_makefile "$srcdir" || return 1 + if $if_not_dry_build check_cmake "$srcdir"; then + if [ -z "$mode" ]; then + $if_not_dry_build \ + check_autoconf "$srcdir" + fi + fi + if ! $if_not_dry_build check_makefile "$srcdir"; then + return 1 + fi - $dry x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs + $if_not_dry_build \ + x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs if [ -z "$mode" ]; then x_ $mkhelper fi - check_makefile "$srcdir" || return 0 + if ! check_makefile "$srcdir"; then + return 0 + fi if [ "$mode" = "clean" ]; then - $dry make -C "$srcdir" $cleanargs distclean || \ - $dry x_ make -C "$srcdir" $cleanargs clean; : + $if_not_dry_build \ + make -C "$srcdir" $cleanargs distclean || \ + $if_not_dry_build \ + x_ make -C "$srcdir" $cleanargs clean; : fi } check_cmake() { if [ -n "$cmakedir" ]; then - $dry check_makefile "$1" || cmake -B "$1" \ - "$1/$cmakedir" || $dry x_ check_makefile "$1" - $dry x_ check_makefile "$1"; : + if ! $if_not_dry_build check_makefile "$1"; then + if ! cmake -B "$1" "$1/$cmakedir"; then + $if_not_dry_build \ + x_ check_makefile "$1" + fi + fi + $if_not_dry_build \ + x_ check_makefile "$1"; : fi } @@ -637,6 +740,7 @@ check_makefile() { if [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \ [ ! -f "$1/GNUmakefile" ]; then + return 1 fi } diff --git a/include/vendor.sh b/include/vendor.sh index 9e0eb731..2a3ea26a 100644 --- a/include/vendor.sh +++ b/include/vendor.sh @@ -23,29 +23,77 @@ vendir="vendorfiles" appdir="$vendir/app" vfix="DO_NOT_FLASH_YET._FIRST,_INJECT_FILES_VIA_INSTRUCTIONS_ON_LIBREBOOT.ORG_" -# lbmk-specific extension to the "cv" variable (not suitable for cbmk) -cvchk="CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN \ +# lbmk-specific extension to the "checkvars" variable (not suitable for cbmk) +checkvarschk="CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN \ CONFIG_LENOVO_TBFW_BIN CONFIG_VGA_BIOS_FILE CONFIG_FSP_M_FILE \ CONFIG_FSP_S_FILE CONFIG_KBC1126_FW1 CONFIG_KBC1126_FW2" -# lbmk-specific extensions to the "cv" variable (not suitable for cbmk) -cvxbmk="CONFIG_ME_BIN_PATH CONFIG_SMSC_SCH5545_EC_FW_FILE CONFIG_FSP_FULL_FD \ +# lbmk-specific extensions to the "checkvars" variable (not suitable for cbmk) +checkvarsxbmk="CONFIG_ME_BIN_PATH CONFIG_SMSC_SCH5545_EC_FW_FILE CONFIG_FSP_FULL_FD \ CONFIG_KBC1126_FW1_OFFSET CONFIG_KBC1126_FW2_OFFSET CONFIG_FSP_USE_REPO \ CONFIG_VGA_BIOS_ID CONFIG_BOARD_DELL_E6400 CONFIG_FSP_S_CBFS \ CONFIG_HAVE_REFCODE_BLOB CONFIG_REFCODE_BLOB_FILE CONFIG_FSP_FD_PATH \ CONFIG_IFD_BIN_PATH CONFIG_MRC_FILE CONFIG_FSP_M_CBFS" -# lbmk-specific extensions; mostly used for downloading vendor files -eval "`setvars "" has_hashes EC_hash DL_hash DL_url_bkup MRC_refcode_gbe vcfg \ - E6400_VGA_DL_hash E6400_VGA_DL_url E6400_VGA_DL_url_bkup E6400_VGA_offset \ - E6400_VGA_romname SCH5545EC_DL_url_bkup SCH5545EC_DL_hash _dest mecleaner \ - kbc1126_ec_dump MRC_refcode_cbtree _dl SCH5545EC_DL_url EC_url rom DL_url \ - nuke cbfstoolref FSPFD_hash _7ztest ME11bootguard ME11delta xromsize \ - ME11version ME11sku ME11pch _me _metmp mfs TBFW_url_bkup TBFW_url cbdir \ - TBFW_hash TBFW_size hashfile EC_url_bkup FSPM_bin_hash FSPS_bin_hash \ - EC_FW1_hash EC_FW2_hash ME_bin_hash MRC_bin_hash REF_bin_hash _dl_bin \ - SCH5545EC_bin_hash TBFW_bin_hash E6400_VGA_bin_hash _pre_dest \ - XBMKmecleaner MEclean`" +# lbmk-specific extensions; general variables +_dest="" +has_hashes="" +vcfg="" +mecleaner="" +kbc1126_ec_dump="" +_dl="" +rom="" +nuke="" +_7ztest="" +cbfstoolref="" +_me="" +_metmp="" +mfs="" +cbdir="" +hashfile="" +_dl_bin="" +_pre_dest="" +xromsize="" + +# lbmk-specific extensions; declared in pkg.cfg files in config/vendor/ +EC_hash="" +DL_hash="" +DL_url_bkup="" +MRC_refcode_gbe="" +E6400_VGA_DL_hash="" +E6400_VGA_DL_url="" +E6400_VGA_DL_url_bkup="" +E6400_VGA_offset="" +E6400_VGA_romname="" +SCH5545EC_DL_url_bkup="" +SCH5545EC_DL_hash="" +MRC_refcode_cbtree="" +SCH5545EC_DL_url="" +EC_url="" +DL_url="" +FSPFD_hash="" +ME11bootguard="" +ME11delta="" +ME11version="" +ME11sku="" +ME11pch="" +TBFW_url_bkup="" +TBFW_url="" +TBFW_hash="" +TBFW_size="" +EC_url_bkup="" +FSPM_bin_hash="" +FSPS_bin_hash="" +EC_FW1_hash="" +EC_FW2_hash="" +ME_bin_hash="" +MRC_bin_hash="" +REF_bin_hash="" +SCH5545EC_bin_hash="" +TBFW_bin_hash="" +E6400_VGA_bin_hash="" +XBMKmecleaner="" +MEclean="" download() { @@ -118,6 +166,10 @@ fetch() dlop="$6" binsum="$7" + if [ -z "$binsum" ]; then + 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 @@ -130,17 +182,36 @@ fetch() remkdir "${_pre_dest%/*}" "$appdir" # HACK: if grabbing fsp from coreboot, fix the path for lbmk - [ "$dl_type" = "fsp" ] && for _cdl in dl dl_bkup; do - eval "$_cdl=\"\${$_cdl##*../}\"; _cdp=\"\$$_cdl\"" - [ -f "$_cdp" ] || _cdp="$cbdir/$_cdp" - [ -f "$_cdp" ] && eval "$_cdl=\"$_cdp\""; : - done; : + if [ "$dl_type" = "fsp" ] + then + dl="${dl##*../}" + _cdp="$dl" + + if [ ! -f "$_cdp" ]; then + _cdp="$cbdir/$_cdp" + fi + if [ -f "$_cdp" ]; then + dl="$_cdp" + fi + + dl_bkup="${dl_bkup##*../}" + _cdp="$dl_bkup" + + if [ ! -f "$_cdp" ]; then + _cdp="$cbdir/$_cdp" + fi + if [ -f "$_cdp" ]; then + dl_bkup="$_cdp"; : + fi + fi + + # download the file (from the internet) to extract from: - # download the file (from the internet) to extract from xbget "$dlop" "$dl" "$dl_bkup" "$_dl" "$dlsum" x_ rm -Rf "${_dl}_extracted" - # skip extraction if a cached extracted file exists + # skip extraction if a cached extracted file exists: + ( xbget copy "$_dl_bin" "$_dl_bin" "$_dest" "$binsum" 2>/dev/null ) || : if [ -f "$_dest" ]; then return 0 @@ -160,7 +231,7 @@ fetch() # some functions don't output directly to the given file, _pre_dest. # instead, they put multiple files there, but we need the one matching # the given hashsum. So, search for a matching file via bruteforce: - ( fx_ "eval mkdst \"$binsum\"" x_ find "${_pre_dest%/*}" -type f ) || : + ( fx_ "mkdst $binsum" x_ find "${_pre_dest%/*}" -type f ) || : if ! bad_checksum "$binsum" "$_dest"; then if [ -f "$_dest" ]; then @@ -178,8 +249,7 @@ fetch() x_ rm -f "$_dest" fi - err "Could not safely extract '$_dest', for board '$board'" \ - "fetch" "$@" + err "Can't safely extract '$_dest', for board '$board'" "fetch" "$@" } mkdst() @@ -208,8 +278,14 @@ extract_intel_me() x_ rm -Rf "$_7ztest" if [ "$ME11bootguard" = "y" ]; then - mfs="--whitelist MFS" && \ - chkvars ME11delta ME11version ME11sku ME11pch + mfs="--whitelist MFS" + + if [ -z "$ME11delta" ] || [ -z "$ME11version" ] || \ + [ -z "$ME11sku" ] || [ -z "$ME11pch" ]; then + err "$board: ME11delta/ME11version/ME11sku/ME11pch" \ + "extract_intel_me" "$@" + fi + x_ ./mk -f deguard fi @@ -232,6 +308,8 @@ extract_intel_me() find_me() { if [ -f "$_metmp" ]; then + # we found me.bin, so we stop searching + exit 1 elif [ -L "$1" ]; then return 0 @@ -273,7 +351,8 @@ find_me() fi if [ -f "$_metmp" ]; then - # we found me.bin + # we found me.bin, so we stop searching + exit 1 else # if the subshell does exit 1, we found me.bin, so exit 1 @@ -351,7 +430,11 @@ extract_kbc1126ec_dump() extract_e6400vga() { set +u +e - chkvars E6400_VGA_offset E6400_VGA_romname + + if [ -z "$E6400_VGA_offset" ] || [ -z "$E6400_VGA_romname" ]; then + err "$board: E6400_VGA_romname/E6400_VGA_offset unset" \ + "extract_e6400vga" "$@" + fi tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || : @@ -382,7 +465,10 @@ 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() { - chkvars TBFW_size + if [ -z "$TBFW_size" ]; then + err "$board: TBFW_size unset" "extract_tbfw" "$@" + fi + fx_ copytb x_ find "$appdir" -type f -name "TBT.bin" } @@ -391,6 +477,7 @@ copytb() if [ -f "$1" ] && [ ! -L "$1" ]; then x_ dd if=/dev/null of="$1" bs=1 seek=$TBFW_size x_ mv "$1" "$_pre_dest" + return 1 fi } @@ -403,7 +490,7 @@ extract_fsp() setvfile() { - [ -n "$vcfg" ] && for c in $cvchk; do + [ -n "$vcfg" ] && for c in $checkvarschk; do vcmd="[ \"\${$c}\" != \"/dev/null\" ] && [ -n \"\${$c}\" ]" eval "$vcmd && getvfile \"\$@\" && return 0" done && return 1; : @@ -411,7 +498,12 @@ setvfile() getvfile() { - eval "`setcfg "config/vendor/$vcfg/pkg.cfg" 1`" + if e "config/vendor/$vcfg/pkg.cfg" f missing; then + return 1 + fi + + . "config/vendor/$vcfg/pkg.cfg" || \ + err "Can't read 'config/vendor/$vcfg/pkg.cfg'" "getvfile" "$@" bootstrap @@ -480,6 +572,7 @@ prep() # Remove the prefix and 1-byte pad if [ "${_xromname#"$vfix"}" != "$_xromname" ] \ && [ "$nuke" != "nuke" ]; then + unpad_one_byte "$_xrom" x_ mv "$_xrom" "$_xromnew" @@ -490,20 +583,28 @@ prep() ( mksha512 "$_xrom" "vendorhashes" ) || err; : fi - add_vfiles "$_xrom" || return 1 # we still change the MAC if needed + if ! add_vfiles "$_xrom"; then + # no need to insert files. we will later + # still process MAC addresses as required + + return 1 + fi if [ "$nuke" = "nuke" ]; then - pad_one_byte "$_xrom" && x_ mv "$_xrom" "$_xromnew" + pad_one_byte "$_xrom" + x_ mv "$_xrom" "$_xromnew" fi } mksha512() { + build_sbase + if [ "${1%/*}" != "$1" ]; then x_ cd "${1%/*}" fi - x_ sha512sum ./"${1##*/}" >> "$2" || \ + x_ "$sha512sum" ./"${1##*/}" >> "$2" || \ err "!sha512sum \"$1\" > \"$2\"" "mksha512" "$@" } @@ -513,9 +614,11 @@ 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 @@ -566,11 +669,11 @@ vfile() cbfsname="$1" _dest="${2##*../}" - _t="$3" + blobtype="$3" _offset="" - if [ "$_t" = "fsp" ] && [ $# -gt 3 ]; then + if [ "$blobtype" = "fsp" ] && [ $# -gt 3 ]; then _offset="$4" elif [ $# -gt 3 ] && _offset="-b $4" && [ -z "$4" ]; then err "$rom: offset given but empty (undefined)" "vfile" "$@" @@ -582,34 +685,37 @@ vfile() if [ "$cbfsname" = "IFD" ]; then if [ "$nuke" = "nuke" ]; then - x_ "$ifdtool" $ifdprefix --nuke $_t "$rom" -O "$rom" + x_ "$ifdtool" $ifdprefix --nuke $blobtype "$rom" \ + -O "$rom" else - x_ "$ifdtool" $ifdprefix -i $_t:$_dest "$rom" -O "$rom" + x_ "$ifdtool" $ifdprefix -i $blobtype:$_dest "$rom" \ + -O "$rom" fi elif [ "$nuke" = "nuke" ]; then x_ "$cbfstool" "$rom" remove -n "$cbfsname" - elif [ "$_t" = "stage" ]; then # the only stage we handle is refcode + elif [ "$blobtype" = "stage" ]; then # the only stage we handle is refcode x_ rm -f "$xbtmp/refcode" x_ "$rmodtool" -i "$_dest" -o "$xbtmp/refcode" x_ "$cbfstool" "$rom" add-stage -f "$xbtmp/refcode" \ -n "$cbfsname" -t stage else x_ "$cbfstool" "$rom" add -f "$_dest" -n "$cbfsname" \ - -t $_t $_offset + -t $blobtype $_offset fi xchanged="y" - : } # must be called from a subshell check_vendor_hashes() { + build_sbase + x_ cd "$tmpromdir" if [ "$has_hashes" != "n" ] && [ "$nuke" != "nuke" ]; then - sha512sum --status -c "$hashfile" || x_ sha1sum --status \ - -c "$hashfile" + ( x_ "$sha512sum" -c "$hashfile" ) || \ + x_ sha1sum -c "$hashfile" fi x_ rm -f "$hashfile" |