general code cleanup on lbmk shell scripts

in update/blobs/download, i saw instances where
appdir was being deleted with rm -r, but the more
appropriate command would rm -Rf. this is now fixed.

other than that, i've mostly just simplified a bunch
of if statements and consolidated some duplicated
logic (e.g. if/else block for dependencies in
build_dependencies() of update/blobs/download

one or two functions and/or variables have been
renamed, for greater clarity in the code, also
removed a few messages that were redundant

used printf instead of echo, in a few places, also
fixed up the indentation in a few places

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2023-08-21 19:41:49 +01:00
parent 7be4706552
commit 62f23123cb
17 changed files with 307 additions and 581 deletions
+20 -48
View File
@@ -29,13 +29,10 @@ _ifd_destination=""
main()
{
sname=${0}
if [ $# -lt 2 ]; then
fail "Missing arguments (less than two)."
fi
[ $# -lt 2 ] && fail "Missing arguments (fewer than two)."
board="${1}"
vendor_rom="${2}"
boarddir="${cbcfgsdir}/${board}"
check_board
@@ -45,39 +42,22 @@ main()
check_board()
{
if [ ! -f "${vendor_rom}" ] ; then
[ -f "${vendor_rom}" ] || \
fail "file does not exist: ${vendor_rom}"
elif [ ! -d "${boarddir}" ]; then
[ -d "${boarddir}" ] || \
fail "build/roms ${board}: target not defined"
elif [ ! -f "${boarddir}/target.cfg" ]; then
[ -f "${boarddir}/target.cfg" ] || \
fail "build/roms ${board}: missing target.cfg"
fi
}
build_dependencies()
{
if [ ! -d me_cleaner ]; then
printf "downloading me_cleaner\n"
./fetch me_cleaner || fail 'could not download me_cleaner'
else
printf "me_cleaner already downloaded. Skipping.\n"
printf "run ./fetch me_cleaner to manually overwrite\n"
fi
if [ ! -d ${cbdir} ]; then
printf "downloading coreboot\n"
./fetch_trees coreboot default \
|| fail "could not download coreboot"
else
printf "coreboot already downloaded. Skipping.\n"
printf "run ./fetch_trees coreboot to manually overwrite\n"
fi
if ! [ -f ${ifdtool} ]; then
printf "building ifdtool from coreboot\n"
make -C "${ifdtool%/ifdtool}" \
|| fail "could not build ifdtool"
fi
[ -d me_cleaner ] || \
./fetch me_cleaner || fail "can't fetch me_cleaner"
[ -d ${cbdir} ] || \
./fetch_trees coreboot default || fail "can't fetch coreboot"
[ -f ${ifdtool} ] || \
make -C "${ifdtool%/ifdtool}" || fail "can't build ifdtool"
}
extract_blobs()
@@ -88,10 +68,8 @@ extract_blobs()
. ${1} 2>/dev/null
. "${boarddir}/target.cfg"
if [ "$CONFIG_HAVE_MRC" = "y" ]; then
printf 'haswell board detected, downloading mrc\n'
[ "$CONFIG_HAVE_MRC" != "y" ] || \
./update blobs mrc || fail "could not download mrc"
fi
_me_destination=${CONFIG_ME_BIN_PATH#../../}
_gbe_destination=${CONFIG_GBE_BIN_PATH#../../}
@@ -103,13 +81,9 @@ extract_blobs()
# Cleans up other files extracted with ifdtool
rm -f flashregion*.bin 2> /dev/null
if [ -f ${_ifd_destination} ]; then
printf "gbe, ifd, and me extracted to %s\n" \
${_me_destination%/*}
else
printf "WARNING: Intel firmware descriptor could not "
printf "be extracted with modified me\n"
fi
[ -f ${_ifd_destination} ] || fail "Could not extract IFD"
printf "gbe, ifd, and me extracted to %s\n" \
${_me_destination%/*}
}
extract_blob_intel_me()
@@ -117,25 +91,23 @@ extract_blob_intel_me()
printf "extracting clean ime and modified ifd\n"
${mecleaner} -D ${_ifd_destination} \
-M ${_me_destination} ${vendor_rom} -t -r -S \
|| ${me7updateparser} \
-O ${_me_destination} ${vendor_rom} \
|| fail \
"me_cleaner failed to extract blobs from rom"
-M ${_me_destination} ${vendor_rom} -t -r -S || \
${me7updateparser} \
-O ${_me_destination} ${vendor_rom} || \
fail "me_cleaner failed to extract blobs from rom"
}
extract_blob_intel_gbe_nvm()
{
printf "extracting gigabit ethernet firmware"
./${ifdtool} -x ${vendor_rom}
mv flashregion*gbe.bin ${_gbe_destination} \
|| fail 'could not extract gbe'
mv flashregion*gbe.bin ${_gbe_destination} || \
fail 'could not extract gbe'
}
fail()
{
print_help
printf "\n%s: ERROR: %s\n" ${sname} $@
exit 1
}