summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-09-17 09:30:52 +0100
committerLeah Rowe <leah@libreboot.org>2026-09-17 10:33:43 +0100
commit69875b8e10fb1ae53c4f6aba38b4f604276d3f5b (patch)
tree654e72aff10775a926a1707df0479463be790fa2
parent1722964f66562c690bfcc749674d08c2ad89badb (diff)
xbmk: general cleanup
note: mecleaner check removed in vendor.sh, because it's already guaranteed to be fetched. the check will never indicate failure, so we can just assume that the me cleaner python script exists. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--include/env/get.sh30
-rw-r--r--include/env/init.sh6
-rw-r--r--include/fw/inject.sh26
-rw-r--r--include/fw/vendor.sh55
-rw-r--r--include/lib.sh5
-rwxr-xr-xmk100
6 files changed, 74 insertions, 148 deletions
diff --git a/include/env/get.sh b/include/env/get.sh
index 0863615b..9cd88174 100644
--- a/include/env/get.sh
+++ b/include/env/get.sh
@@ -39,14 +39,12 @@ single_tree_fetch()
x_ "$mk" -f $d
done
- clone_project
+ $if_single_tree \
+ clone_project; :
}
clone_project()
{
- singletree "$project" || \
- return 0
-
loc="src/$project"
[ -d "$loc" ] && \
return 0
@@ -174,10 +172,8 @@ try_fetch_curl()
try_$2 "$cached" "$@" || \
return 1
- [ -f "$5" ] && \
- if bad_checksum "$6" "$5" 2>/dev/null; then
- x_ cp "$cached" "$5"
- fi
+ [ -f "$5" ] && bad_checksum "$6" "$5" 2>/dev/null && \
+ x_ cp "$cached" "$5"
if [ ! -f "$cached" ]; then
return 1
@@ -202,8 +198,7 @@ try_curl()
ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
( x_ curl --location --retry 3 -A "$ua" "$2" -o "$1" ) \
- || ( x_ wget --tries 3 -U "$ua" "$2" -O "$1" ) \
- || return 1; :
+ || ( x_ wget --tries 3 -U "$ua" "$2" -O "$1" ) || return 1; :
}
try_copy()
@@ -230,15 +225,9 @@ try_git()
x_ mv "$tmpgitcache" "$gitdest"
fi
- if git -C "$gitdest" show "$7" 1>/dev/null 2>/dev/null && \
- [ "$forcepull" != "y" ]; then
- # don't try to pull the latest changes if the given target
- # revision already exists locally. this saves a lot of time
- # during release builds, and reduces the chance that we will
- # interact with grub.git or gnulib.git overall during runtime
-
- return 0
- fi
+ git -C "$gitdest" show "$7" 1>/dev/null 2>/dev/null && \
+ [ "$forcepull" != "y" ] && \
+ return 0 # don't pull changes if target rev exists locally
if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
( x_ git -C "$gitdest" fetch ) || :; :
@@ -250,9 +239,8 @@ try_git()
bad_checksum()
{
- if e "$2" f missing; then
+ e "$2" f missing && \
return 0
- fi
build_sbase
csum="$(x_ "$sha512sum" "$2" | awk '{print $1}')" || \
diff --git a/include/env/init.sh b/include/env/init.sh
index d17b5fb8..d04474e3 100644
--- a/include/env/init.sh
+++ b/include/env/init.sh
@@ -165,13 +165,11 @@ xbmk_parent_set_env()
x_ chmod -w "$xbmklock"
- xbmk_parent_set_export
- xbmk_set_version
+ forx 'xbmk_%s' parent_set_export set_version
remkdir "$xbtmp" "$xbtmp/xbmkpath"
- xbmk_set_pyver
- xbmk_set_mirror
+ forx 'xbmk_set_%s' pyver mirror
}
xbmk_parent_check_tmp()
diff --git a/include/fw/inject.sh b/include/fw/inject.sh
index adff3861..900d2a5d 100644
--- a/include/fw/inject.sh
+++ b/include/fw/inject.sh
@@ -18,8 +18,7 @@ inject()
{
remkdir "$tmpromdel"
- [ $# -lt 1 ] && \
- err "No options specified" "inject" "$@"
+ [ $# -lt 1 ] && err "No options specified" "inject" "$@"
archive="$1";
new_mac="xx:xx:xx:xx:xx:xx"
@@ -58,9 +57,8 @@ check_release()
{
[ -L "$archive" ] && \
err "'$archive' is a symlink" "check_release" "$@"
- if e "$archive" f missing; then
+ e "$archive" f missing && \
err "'$archive' missing" "check_release" "$@"
- fi
archivename="`basename "$archive" || err "Can't get '$archive' name"`" \
|| err "can't get '$archive' name" "check_release" "$@"
@@ -100,7 +98,6 @@ check_target()
x_ "$mk" -d coreboot "$tree"
ifdtool="elf/coreboot/$tree/ifdtool"
-
[ -n "$IFD_platform" ] && \
ifdprefix="-p $IFD_platform"; :
}
@@ -125,8 +122,7 @@ patch_release()
fi
done
- readkconfig || \
- return 1
+ readkconfig || return 1
[ -n "$new_mac" ] && [ -n "$CONFIG_GBE_BIN_PATH" ] && \
modify_mac; :
@@ -137,15 +133,13 @@ readkconfig()
x_ rm -f "$xbtmp/cbcfg"
fx_ scankconfig x_ find "$boarddir/config" -type f
- if e "$xbtmp/cbcfg" f missing; then
+ e "$xbtmp/cbcfg" f missing && \
return 1
- fi
. "$xbtmp/cbcfg" || \
err "Can't read '$xbtmp/cbcfg'" "readkconfig" "$@"
- setvfile "$@" || \
- return 1; :
+ setvfile "$@" || return 1; :
}
scankconfig()
@@ -173,10 +167,9 @@ modify_mac()
newmac()
{
- if e "$1" f; then
- xchanged="y"
- x_ "$ifdtool" $ifdprefix -i GbE:"$xbtmp/gbe" "$1" -O "$1"
- fi
+ e "$1" f || return 0
+ xchanged="y"
+ x_ "$ifdtool" $ifdprefix -i GbE:"$xbtmp/gbe" "$1" -O "$1"
}
remktar()
@@ -190,6 +183,5 @@ remktar()
) || err "Cannot re-generate '$archive'" "remktar" "$@"
mv "${tmpromdir%"/bin/$board"}/bin/${relname}_${board}.tar.xz" \
- "$archive" || \
- err "'$archive' -> Can't overwrite" "remktar" "$@"; :
+ "$archive" || err "'$archive' -> Can't overwrite" "remktar" "$@"; :
}
diff --git a/include/fw/vendor.sh b/include/fw/vendor.sh
index 41c51e09..05f8b226 100644
--- a/include/fw/vendor.sh
+++ b/include/fw/vendor.sh
@@ -51,14 +51,12 @@ eval "`newvar DL_hash DL_url DL_url_bkup E6400_VGA_bin_hash E6400_VGA_DL_hash \
download()
{
- [ $# -lt 1 ] && \
- err "No argument given" "download" "$@"
+ [ $# -lt 1 ] && err "No argument given" "download" "$@"
export PATH="$PATH:/sbin"
board="$1"
- check_target || return 0
- readkconfig download
+ check_target && readkconfig download; :
}
getfiles()
@@ -108,14 +106,12 @@ fetch()
dlop="$6"
binsum="$7"
- [ -z "$binsum" ] && \
- err "binsum is empty (no checksum)" "fetch" "$@"
+ [ -z "$binsum" ] && err "binsum is empty (no checksum)" "fetch" "$@"
_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
- [ "$5" = "/dev/null" ] && \
- return 0
+ [ "$5" = "/dev/null" ] && return 0 # fetch/extract disabled
# an extracted vendor file will be placed in pre_dest first, for
# verifying its checksum. if it matches, it is later moved to _dest
@@ -160,32 +156,24 @@ fetch()
[ ! -f "$_dest" ] || \
return 0; :
- [ -z "$binsum" ] && \
- printf "WARNING: %s: checksum undefined\n" "$_dest" 1>&2
-
x_ rm -f "$_dest"
+ [ -z "$binsum" ] && printf "WARNING: %s: no checksum\n" "$_dest" 1>&2
err "Can't safely extract '$_dest', for board '$board'" "fetch" "$@"
}
mkdst()
{
- if bad_checksum "$1" "$2" 2>/dev/null; then
- x_ rm -f "$2"
- else
+ if ! bad_checksum "$1" "$2" 2>/dev/null; then
x_ mv "$2" "$_dl_bin"
x_ cp "$_dl_bin" "$_dest"
-
exit 1
fi
+ x_ rm -f "$2"
}
extract_intel_me()
{
- if e "$mecleaner" f missing; then
- err "$cbdir: me_cleaner missing" "extract_intel_me" "$@"
- fi
-
mfs=""
_7ztest="$xbtmp/metmp/a"
_metmp="$xbtmp/me.bin"
@@ -228,10 +216,8 @@ extract_intel_me()
# must be called inside a subshell.
find_me()
{
- [ -f "$_metmp" ] && \
- exit 1 # me.bin found
- [ -L "$1" ] && \
- return 0 # symlinks disabled for security reasons
+ [ -f "$_metmp" ] && exit 1 # me.bin found
+ [ -L "$1" ] && return 0 # symlinks disabled for security reasons
_7ztest="${_7ztest}a"
@@ -268,8 +254,7 @@ find_me()
return 0 # can't extract, so try the next file
fi
- [ -f "$_metmp" ] && \
- exit 1 # me.bin found
+ [ -f "$_metmp" ] && exit 1 # me.bin found
( fx_ find_me x_ find "$_7ztest" -type f ) || exit 1; : # 1==me found
}
@@ -318,8 +303,7 @@ extract_kbc1126ec_dump()
unar -D 68*.CAB Rom.bin || \
err "!kbc1126 unar" "extract_kbc1126ec" "$@"
- [ ! -f "ec.bin" ] && \
- x_ mv Rom.bin ec.bin
+ [ -f "ec.bin" ] || x_ mv Rom.bin ec.bin
x_ e ec.bin f
x_ "$kbc1126_ec_dump" ec.bin
@@ -365,8 +349,7 @@ 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()
{
- [ -z "$TBFW_size" ] && \
- err "$board: TBFW_size unset" "extract_tbfw" "$@"
+ [ -z "$TBFW_size" ] && err "$board: TBFW_size unset" extract_tbfw "$@"
fx_ copytb x_ find "$appdir" -type f -name "TBT.bin"
}
@@ -415,12 +398,8 @@ getvfile()
bootstrap
if [ $# -gt 0 ]; then
- # download vendor files
-
- getfiles
- else
- # inject vendor files
-
+ getfiles # ./mk download
+ else # ./mk inject
fx_ prep x_ find "$tmpromdir" -mindepth 1 -maxdepth 1 \
-type f -name "*.rom"
( check_vendor_hashes ) || \
@@ -484,8 +463,7 @@ prep()
( mksha512 "$_xrom" "vendorhashes" ) || err; :
fi
- add_vfiles "$_xrom" || \
- return 1 # no need to insert files
+ add_vfiles "$_xrom" || return 1 # no need to insert files
if [ "$nuke" = "nuke" ]; then
pad_one_byte "$_xrom"
@@ -548,8 +526,7 @@ add_vfiles()
vfile()
{
- [ "$2" = "/dev/null" ] && \
- return 0
+ [ "$2" = "/dev/null" ] && return 0
cbfsname="$1"
_dest="${2##*../}"
diff --git a/include/lib.sh b/include/lib.sh
index 63a82084..03758982 100644
--- a/include/lib.sh
+++ b/include/lib.sh
@@ -80,8 +80,6 @@ e()
printf "%s %s\n" "$1" "$es2" 1>&2
}
-# return 0 if project is single-tree, otherwise 1
-# e.g. coreboot is multi-tree, so 1
singletree()
{
( fx_ "eval exit 1 && err" find "config/$1/"*/ -type f \
@@ -116,8 +114,7 @@ unpad_one_byte()
build_sbase()
{
- [ ! -f "$sha512sum" ] && \
- x_ make -C "$xbmkpwd/util/sbase"; :
+ [ ! -f "$sha512sum" ] && x_ make -C "$xbmkpwd/util/sbase"; :
}
remkdir()
diff --git a/mk b/mk
index a6525310..0611231e 100755
--- a/mk
+++ b/mk
@@ -76,25 +76,17 @@ shift 1 2>/dev/null || :
eval "$(printf "version release download inject\n" | awk '{ for (i=1; i<=NF; \
i++) $i = "[ \""$i"\" = \"$_f\" ] && x_ "$i" \"$@\" && exit 0;"; print }')"
-# flag e.g. "$mk" -b <-- mkflag would be "b"
-flag=""
-
# macros, overridden depending on the flag
-# : means false
-if_do_make=""
-if_not_do_make=":"
+if_not_do_make=":" # : means false
if_make_config=":"
-if_not_make_config=""
if_build=":" # can be false even if make is true
-if_not_build=""
if_dry_build=":"
-if_not_dry_build=""
-
if_single_tree=":"
+eval "`newvar if_do_make if_not_make_config if_not_build if_not_dry_build`"
eval "`newvar configureargs autogenargs badhash badtghash bootstrapargs \
build_depend buildtype cleanargs cmakedir cmd defconfig dest_dir elfdir \
- forcepull listfile makeargs mdir mkhelper mkhelpercfg mode postmake \
+ flag forcepull listfile makeargs mdir mkhelper mkhelpercfg mode postmake \
premake project release rev srcdir target target_dir tree xarch xgcctree \
xlang`"
@@ -119,9 +111,8 @@ main()
if_not_dry_build=":"
;;
-f|-F) # download source code for a project
+ eval "`newvar if_not_do_make if_dry_build`"
if_do_make=":"
- if_not_do_make=""
- if_dry_build=""
if_not_dry_build=":"
[ "$flag" = "-F" ] && \
forcepull="y"; : # never skip git fetch/pull
@@ -180,10 +171,10 @@ main()
fi
if singletree "$project"; then
- cmd="single_tree_build"
+ cmd="mk_single_tree"
if_single_tree=""
else
- cmd="multi_tree_build"
+ cmd="mk_multi_tree"
fi
remkdir "${tmpgit%/*}"
@@ -193,27 +184,24 @@ main()
$cmd "$@"
}
-single_tree_build()
+mk_single_tree()
{
configure_project "$configdir" || \
return 0
- [ ! -f "$listfile" ] || \
- $if_not_dry_build elfcheck || \
- return 0
+ [ ! -f "$listfile" ] || $if_not_dry_build \
+ elfcheck || return 0
- run_make_command && \
- $if_build $if_not_dry_build \
+ run_make_command && $if_build $if_not_dry_build \
copy_elf; :
}
-multi_tree_build()
+mk_multi_tree()
{
- [ ! -d "$configdir" ] && \
- err "dir '$configdir' doesn't exist" multi_tree_build "$@"
- [ $# -lt 1 ] && \
- fx_ multi_tree_build find "$configdir" \
+ [ ! -d "$configdir" ] && err "missing '$configdir'" mk_multi_tree "$@"
+ [ $# -lt 1 ] && fx_ mk_multi_tree find "$configdir" \
-mindepth 1 -maxdepth 1 -type d
+
[ $# -gt 0 ] && for x in "$@"
do
unset CROSS_COMPILE
@@ -245,8 +233,7 @@ handle_defconfig()
configure_project "$target_dir" || \
return 0
- [ -z "$tree" ] && \
- err "$configdir: 'tree' not set" "handle_defconfig" "$@"
+ [ -z "$tree" ] && err "$configdir: 'tree' unset" handle_defconfig "$@"
srcdir="src/$project/$tree"
@@ -256,18 +243,16 @@ handle_defconfig()
$if_not_dry_build \
continue
- $if_not_dry_build \
- eval defconfig="$y"
+ $if_not_dry_build eval \
+ defconfig="$y"
$if_build \
- prep_multi_tree_build || \
- continue
+ prep_mk_multi_tree || continue
handle_makefile
- $if_build \
- $if_not_dry_build \
- copy_elf; :
+ $if_build $if_not_dry_build \
+ copy_elf; :
done; :
}
@@ -279,8 +264,7 @@ configure_project()
build_depend buildtype cleanargs makeargs mkhelper postmake \
premake release xarch xgcctree xlang`"
- [ ! -f "$_tcfg" ] && \
- buildtype="auto"
+ [ ! -f "$_tcfg" ] && buildtype="auto"
# globally initialise all variables for a source tree / target:
if e "$datadir/mkhelper.cfg" f; then
@@ -290,16 +274,15 @@ configure_project()
fi
# override target/tree specific variables from per-target config:
- while e "$_tcfg" f || [ "$cmd" != "single_tree_build" ]
+ while e "$_tcfg" f || [ "$cmd" != "mk_single_tree" ]
do
printf "Loading %s config: %s\n" "$project" "$_tcfg"
eval "`newvar rev tree`"
- . "$_tcfg" || \
- err "Can't read '$_tcfg'" "configure_project" "$@"
+ . "$_tcfg" || err "Can't read '$_tcfg'" configure_project "$@"
- $if_dry_build \
- eval build_depend=""
+ $if_dry_build eval \
+ build_depend=""
$if_single_tree \
break
@@ -313,22 +296,19 @@ configure_project()
[ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && \
return 1
- [ -n "$buildtype" ] && \
- $if_make_config \
- return 1
+ [ -n "$buildtype" ] && $if_make_config \
+ return 1
- $if_build \
- $if_not_dry_build \
- build_dependencies
+ $if_build $if_not_dry_build \
+ build_dependencies
mdir="$xbmkpwd/config/submodule/$project"
- [ -n "$tree" ] && \
- mdir="$mdir/$tree"
+ [ -n "$tree" ] && mdir="$mdir/$tree"
if [ ! -f "CHANGELOG" ]; then
delete_old_project_files
$if_not_do_make \
- ${cmd%_build}_fetch
+ ${cmd#mk_}_fetch
fi
$if_not_do_make \
return 1
@@ -434,7 +414,7 @@ project_up_to_date()
eval "[ \"\$$badhashvar\" = \"y\" ] && return 1"; :
}
-prep_multi_tree_build()
+prep_mk_multi_tree()
{
dest_dir="$elfdir/$tree/$target/${defconfig#"$target_dir/config/"}"
@@ -455,8 +435,7 @@ check_xgcc()
cbelfdir="elf${cbdir#src}"
xfix="${1%-*}"
- [ "$xfix" = "x86_64" ] && \
- xfix="x64"
+ [ "$xfix" = "x86_64" ] && xfix="x64"
xgccfile="$cbelfdir/xgcc_${xfix}_was_compiled"
xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
@@ -472,10 +451,8 @@ check_xgcc()
[ -n "$xlang" ] && \
export BUILD_LANGUAGES="$xlang"
- [ -f "$xgccfile" ] && \
- return 0 # build exists already, so skip building
+ [ -f "$xgccfile" ] && return 0 # skip (build already exists)
- # it sometimes fails for like, no reason
make -C "$cbdir" $xgccargs || x_ make -C "$cbdir" $xgccargs
x_ touch "$xgccfile" # prevent unnecessary re-build operations
@@ -484,15 +461,13 @@ check_xgcc()
elfcheck()
{
# TODO: *STILL* very hacky check. do it properly (based on build.list)
-
( fx_ "eval exit 1 && err" find "$dest_dir" -type f ) || return 1; :
}
handle_makefile()
{
- check_makefile "$srcdir" && \
- $if_not_dry_build \
- x_ make -C "$srcdir" clean $cleanargs
+ check_makefile "$srcdir" && $if_not_dry_build \
+ x_ make -C "$srcdir" clean $cleanargs
[ -f "$defconfig" ] && \
x_ cp "$defconfig" "$srcdir/.config"
@@ -546,8 +521,7 @@ check_autoconf()
check_makefile()
{
[ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \
- [ ! -f "$1/GNUmakefile" ] && \
- return 1; :
+ [ ! -f "$1/GNUmakefile" ] && return 1; :
}
copy_elf()