mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-09-20 05:30:25 +02:00
2fc37b4b47
use of maxdepth 1 does not exclude the main directory, which is undesired in these contexts, though excluded in practise due to how find is actually used. technically, mindepth should be used, just in case, as a defensive measure. the context here is files and directories within a main directory, used as arguments in other commands. Signed-off-by: Leah Rowe <leah@libreboot.org>
207 lines
4.2 KiB
Bash
207 lines
4.2 KiB
Bash
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
|
|
# Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
|
|
# Copyright (c) 2023-2026 Leah Rowe <leah@libreboot.org>
|
|
|
|
cbcfgsdir="config/coreboot"
|
|
tmpromdel="$XBMK_CACHE/DO_NOT_FLASH"
|
|
nvmutil="util/nvmutil/nvmutil"
|
|
ifdtool="elf/coreboot/default/ifdtool"
|
|
|
|
checkvars="CONFIG_GBE_BIN_PATH ${checkvarsxbmk-} ${checkvarschk-}"
|
|
|
|
eval "`newvar archive board boarddir IFD_platform ifdprefix \
|
|
new_mac tmpromdir tree xchanged $checkvars`"
|
|
|
|
inject()
|
|
{
|
|
remkdir "$tmpromdel"
|
|
|
|
[ $# -lt 1 ] && \
|
|
err "No options specified" "inject" "$@"
|
|
|
|
archive="$1";
|
|
new_mac="xx:xx:xx:xx:xx:xx"
|
|
|
|
nuke=""
|
|
xchanged=""
|
|
|
|
[ $# -gt 1 ] && case "$2" in
|
|
nuke)
|
|
new_mac=""
|
|
nuke="nuke"
|
|
;;
|
|
setmac)
|
|
if [ $# -gt 2 ]; then
|
|
new_mac="$3" && \
|
|
[ -z "$new_mac" ] && \
|
|
err "Empty MAC address" "inject" "$@"; :
|
|
fi
|
|
;;
|
|
*)
|
|
err "Unrecognised inject mode: '$2'" "inject" "$@" ;;
|
|
esac
|
|
|
|
[ "$new_mac" = "keep" ] && \
|
|
new_mac=""
|
|
|
|
check_release
|
|
if check_target; then
|
|
patch_release || \
|
|
return 0; :
|
|
fi
|
|
[ "$xchanged" = "y" ] && \
|
|
remktar
|
|
|
|
if [ "$xchanged" = "y" ]; then
|
|
printf "\n'%s' was modified\n" "$archive" 1>&2
|
|
else
|
|
printf "\n'%s' was NOT modified\n" "$archive" 1>&2
|
|
fi
|
|
|
|
x_ rm -Rf "$tmpromdel"
|
|
}
|
|
|
|
check_release()
|
|
{
|
|
[ -L "$archive" ] && \
|
|
err "'$archive' is a symlink" "check_release" "$@"
|
|
if e "$archive" f missing; then
|
|
err "'$archive' missing" "check_release" "$@"
|
|
fi
|
|
|
|
archivename="`basename "$archive" || err "Can't get '$archive' name"`" \
|
|
|| err "can't get '$archive' name" "check_release" "$@"
|
|
|
|
[ -z "$archivename" ] && \
|
|
err "Can't determine archive name" "check_release" "$@"
|
|
|
|
case "$archivename" in
|
|
*_src.tar.xz)
|
|
err "'$archive' is a src archive!" "check_release" "$@"
|
|
;;
|
|
grub_*|seagrub_*|custom_*|seauboot_*|seabios_withgrub_*)
|
|
err "'$archive' is a ROM image" "check_release" "$@"
|
|
;;
|
|
*.tar.xz) _stripped_prefix="${archivename#*_}"
|
|
board="${_stripped_prefix%.tar.xz}"
|
|
;;
|
|
*)
|
|
err "'$archive': cannot detect board" "check_release" "$@"
|
|
;;
|
|
esac; :
|
|
}
|
|
|
|
check_target()
|
|
{
|
|
[ "$board" != "${board#serprog_}" ] && \
|
|
return 1
|
|
|
|
boarddir="$cbcfgsdir/$board"
|
|
|
|
. "$boarddir/target.cfg" || \
|
|
err "Can't read '$boarddir/target.cfg'" "check_target" "$@"
|
|
|
|
[ -z "$tree" ] && \
|
|
err "tree unset in '$boarddir/target.cfg'" "check_target" "$@"
|
|
|
|
x_ ./mk -d coreboot "$tree"
|
|
|
|
ifdtool="elf/coreboot/$tree/ifdtool"
|
|
|
|
[ -n "$IFD_platform" ] && \
|
|
ifdprefix="-p $IFD_platform"; :
|
|
}
|
|
|
|
patch_release()
|
|
{
|
|
[ "$nuke" != "nuke" ] && \
|
|
x_ ./mk download "$board"
|
|
|
|
has_hashes="n"
|
|
tmpromdir="$tmpromdel/bin/$board"
|
|
|
|
remkdir "${tmpromdir%"/bin/$board"}"
|
|
x_ tar -xf "$archive" -C "${tmpromdir%"/bin/$board"}"
|
|
|
|
for _hashes in "vendorhashes" "blobhashes"; do
|
|
if e "$tmpromdir/$_hashes" f; then
|
|
has_hashes="y"
|
|
hashfile="$_hashes"
|
|
|
|
break
|
|
fi
|
|
done
|
|
|
|
readkconfig || \
|
|
return 1
|
|
|
|
[ -n "$new_mac" ] && [ -n "$CONFIG_GBE_BIN_PATH" ] && \
|
|
modify_mac; :
|
|
}
|
|
|
|
readkconfig()
|
|
{
|
|
x_ rm -f "$xbtmp/cbcfg"
|
|
fx_ scankconfig x_ find "$boarddir/config" -type f
|
|
|
|
if e "$xbtmp/cbcfg" f missing; then
|
|
return 1
|
|
fi
|
|
|
|
. "$xbtmp/cbcfg" || \
|
|
err "Can't read '$xbtmp/cbcfg'" "readkconfig" "$@"
|
|
|
|
setvfile "$@" || \
|
|
return 1; :
|
|
}
|
|
|
|
scankconfig()
|
|
{
|
|
for cbc in $checkvars; do
|
|
grep "$cbc" "$1" 2>/dev/null 1>>"$xbtmp/cbcfg" || :
|
|
done
|
|
}
|
|
|
|
modify_mac()
|
|
{
|
|
x_ cp "${CONFIG_GBE_BIN_PATH##*../}" "$xbtmp/gbe"
|
|
|
|
if [ -n "$new_mac" ] && [ "$new_mac" != "restore" ]; then
|
|
x_ make -C util/nvmutil clean
|
|
x_ make -C util/nvmutil
|
|
|
|
x_ "$nvmutil" "$xbtmp/gbe" setmac "$new_mac"
|
|
fi
|
|
|
|
fx_ newmac x_ find "$tmpromdir" -mindepth 1 -maxdepth 1 \
|
|
-type f -name "*.rom"
|
|
|
|
printf "\nThe following GbE NVM data will be written:\n"
|
|
x_ "$nvmutil" "$xbtmp/gbe" dump | grep -v "bytes read from file" || :
|
|
}
|
|
|
|
newmac()
|
|
{
|
|
if e "$1" f; then
|
|
xchanged="y"
|
|
x_ "$ifdtool" $ifdprefix -i GbE:"$xbtmp/gbe" "$1" -O "$1"
|
|
fi
|
|
}
|
|
|
|
remktar()
|
|
{
|
|
(
|
|
x_ cd "${tmpromdir%"/bin/$board"}"
|
|
|
|
printf "Re-building tar archive (please wait)\n"
|
|
mkrom_tarball "bin/$board" 1>/dev/null
|
|
|
|
) || err "Cannot re-generate '$archive'" "remktar" "$@"
|
|
|
|
mv "${tmpromdir%"/bin/$board"}/bin/${relname}_${board}.tar.xz" \
|
|
"$archive" || \
|
|
err "'$archive' -> Can't overwrite" "remktar" "$@"; :
|
|
}
|