mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
xbmk: general cleanup: unroll condensed code lines
i overlooked a number of lines, during previous cleanup Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -212,6 +212,7 @@ try_fetch_file()
|
||||
return 1
|
||||
elif bad_checksum "$6" "$cached"; then
|
||||
x_ rm -f "$cached"
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -221,6 +222,7 @@ try_fetch_file()
|
||||
|
||||
if bad_checksum "$6" "$5"; then
|
||||
x_ rm -f "$5"
|
||||
|
||||
return 1
|
||||
elif [ ! -f "$5" ]; then
|
||||
return 1
|
||||
|
||||
@@ -27,6 +27,7 @@ xbmk_init()
|
||||
|
||||
if [ $# -gt 0 ] && [ "$1" = "dependencies" ]; then
|
||||
x_ xbmkpkg "$@"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -353,7 +354,9 @@ pybin()
|
||||
|
||||
if [ -e "$pypath" ] && [ ! -d "$pypath" ] && \
|
||||
[ -x "$pypath" ]; then
|
||||
|
||||
printf "%s\n" "$pypath"
|
||||
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
@@ -363,7 +366,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
|
||||
|
||||
+7
-2
@@ -58,7 +58,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
|
||||
@@ -141,6 +143,7 @@ patch_release()
|
||||
if e "$tmpromdir/$_hashes" f; then
|
||||
has_hashes="y"
|
||||
hashfile="$_hashes"
|
||||
|
||||
break
|
||||
fi
|
||||
done
|
||||
@@ -159,7 +162,9 @@ readkconfig()
|
||||
fx_ scankconfig x_ find "$boarddir/config" -type f
|
||||
eval "`setcfg "$xbtmp/cbcfg" 1`"
|
||||
|
||||
setvfile "$@" || return 1; :
|
||||
if ! setvfile "$@"; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
scankconfig()
|
||||
|
||||
+20
-5
@@ -92,12 +92,16 @@ 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
|
||||
@@ -145,6 +149,7 @@ findpath()
|
||||
fi
|
||||
|
||||
printf "%s\n" "$found"
|
||||
|
||||
shift 1
|
||||
done
|
||||
}
|
||||
@@ -184,7 +189,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 +204,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 +239,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 +254,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
|
||||
|
||||
@@ -52,10 +52,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 )) \
|
||||
|
||||
+2
-1
@@ -10,7 +10,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
|
||||
|
||||
+9
-7
@@ -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"
|
||||
@@ -106,6 +106,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
|
||||
@@ -341,12 +342,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
|
||||
|
||||
|
||||
+48
-18
@@ -57,6 +57,7 @@ trees()
|
||||
|
||||
if [ -z "${OPTARG+x}" ]; then
|
||||
shift 1
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -70,7 +71,9 @@ trees()
|
||||
err "missing flag ($flags)" "trees" "$@"
|
||||
elif [ -z "$project" ]; then
|
||||
fx_ "x_ ./mk $_f" 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 +97,9 @@ trees()
|
||||
|
||||
targets="$*"
|
||||
cmd="build_targets $targets"
|
||||
singletree "$project" && cmd="build_project"
|
||||
if singletree "$project"; then
|
||||
cmd="build_project"
|
||||
fi
|
||||
|
||||
remkdir "${tmpgit%/*}"
|
||||
}
|
||||
@@ -104,14 +109,18 @@ build_project()
|
||||
if ! configure_project "$configdir"; then
|
||||
return 0
|
||||
elif [ -f "$listfile" ]; then
|
||||
$dry elfcheck || return 0; :
|
||||
if ! $dry 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; :
|
||||
@@ -134,7 +143,9 @@ build_targets()
|
||||
|
||||
if [ "$x" = "list" ]; then
|
||||
x_ ls -1 "config/$project"
|
||||
|
||||
listfile=""
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -182,8 +193,7 @@ handle_defconfig()
|
||||
|
||||
if [ -z "$mode" ]; then
|
||||
for _xarch in $xarch; do
|
||||
if [ -n "$_xarch" ]
|
||||
then
|
||||
if [ -n "$_xarch" ]; then
|
||||
$dry check_cross_compiler "$_xarch"
|
||||
fi
|
||||
done; :
|
||||
@@ -421,14 +431,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 +553,16 @@ gnu_setver()
|
||||
check_defconfig()
|
||||
{
|
||||
if [ ! -f "$defconfig" ]; then
|
||||
$dry err "$project/$target: missing defconfig" \
|
||||
"check_defconfig" "$@"
|
||||
$dry 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 ! $dry elfcheck; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
elfcheck()
|
||||
@@ -556,8 +574,9 @@ elfcheck()
|
||||
|
||||
handle_makefile()
|
||||
{
|
||||
$dry check_makefile "$srcdir" && \
|
||||
$dry x_ make -C "$srcdir" $cleanargs clean
|
||||
if $dry check_makefile "$srcdir"; then
|
||||
$dry x_ make -C "$srcdir" $cleanargs clean
|
||||
fi
|
||||
|
||||
if [ -f "$defconfig" ]; then
|
||||
x_ cp "$defconfig" "$srcdir/.config"
|
||||
@@ -588,9 +607,14 @@ run_make_command()
|
||||
x_ $premake
|
||||
fi
|
||||
|
||||
$dry check_cmake "$srcdir" && [ -z "$mode" ] && \
|
||||
$dry check_autoconf "$srcdir"
|
||||
$dry check_makefile "$srcdir" || return 1
|
||||
if $dry check_cmake "$srcdir"; then
|
||||
if [ -z "$mode" ]; then
|
||||
$dry check_autoconf "$srcdir"
|
||||
fi
|
||||
fi
|
||||
if ! $dry check_makefile "$srcdir"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
$dry x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs
|
||||
|
||||
@@ -598,7 +622,9 @@ run_make_command()
|
||||
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 || \
|
||||
@@ -609,8 +635,11 @@ run_make_command()
|
||||
check_cmake()
|
||||
{
|
||||
if [ -n "$cmakedir" ]; then
|
||||
$dry check_makefile "$1" || cmake -B "$1" \
|
||||
"$1/$cmakedir" || $dry x_ check_makefile "$1"
|
||||
if ! $dry check_makefile "$1"; then
|
||||
if ! cmake -B "$1" "$1/$cmakedir"; then
|
||||
$dry x_ check_makefile "$1"
|
||||
fi
|
||||
fi
|
||||
$dry x_ check_makefile "$1"; :
|
||||
fi
|
||||
}
|
||||
@@ -637,6 +666,7 @@ check_makefile()
|
||||
{
|
||||
if [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \
|
||||
[ ! -f "$1/GNUmakefile" ]; then
|
||||
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
+22
-8
@@ -136,11 +136,13 @@ fetch()
|
||||
[ -f "$_cdp" ] && eval "$_cdl=\"$_cdp\""; :
|
||||
done; :
|
||||
|
||||
# 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
|
||||
@@ -178,8 +180,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()
|
||||
@@ -232,6 +233,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 +276,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,6 +355,7 @@ extract_kbc1126ec_dump()
|
||||
extract_e6400vga()
|
||||
{
|
||||
set +u +e
|
||||
|
||||
chkvars E6400_VGA_offset E6400_VGA_romname
|
||||
|
||||
tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || :
|
||||
@@ -391,6 +396,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
|
||||
}
|
||||
@@ -480,6 +486,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,10 +497,16 @@ 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
|
||||
}
|
||||
|
||||
@@ -513,9 +526,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
|
||||
|
||||
@@ -599,7 +614,6 @@ vfile()
|
||||
fi
|
||||
|
||||
xchanged="y"
|
||||
:
|
||||
}
|
||||
|
||||
# must be called from a subshell
|
||||
|
||||
Reference in New Issue
Block a user