minor code cleanup in shell scripts

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-10-19 23:36:56 +01:00
parent 8b6e44a104
commit 0b98c9b00c
8 changed files with 39 additions and 59 deletions

13
build
View File

@ -59,7 +59,7 @@ initialise_command()
[ "${mode}" = "help" ] && usage ${0} && lbmk_exit 0 [ "${mode}" = "help" ] && usage ${0} && lbmk_exit 0
if [ "${mode}" = "list" ]; then if [ "${mode}" = "list" ]; then
listitems "${buildpath}" items "${buildpath}"
lbmk_exit 0 lbmk_exit 0
elif [ $# -lt 2 ]; then elif [ $# -lt 2 ]; then
usage ${0} usage ${0}
@ -91,15 +91,8 @@ install_packages()
execute_command() execute_command()
{ {
if [ "${option}" = "list" ]; then [ "$option" = "list" ] && xx_ items "$buildpath/$mode" && lbmk_exit 0
xx_ listitems "${buildpath}/${mode}"
lbmk_exit 0
fi
lbmkcmd="${buildpath}/${mode}/${option}" lbmkcmd="${buildpath}/${mode}/${option}"
[ "${lbmkcmd}" = "./script/build/boot/roms" ] && \
printf "NOTE: ./build boot roms now: ./build fw coreboot\n" 1>&2
[ "${lbmkcmd%/*}" = "./script/update/blobs" ] && \
printf "NOTE: ./update blobs is now: ./update vendor\n" 1>&2
[ -f "${lbmkcmd}" ] || fail "Invalid command. Run: ${linkpath} help" [ -f "${lbmkcmd}" ] || fail "Invalid command. Run: ${linkpath} help"
"${lbmkcmd}" $@ || fail "execute_command: ${lbmkcmd} ${@}" "${lbmkcmd}" $@ || fail "execute_command: ${lbmkcmd} ${@}"
} }
@ -111,7 +104,7 @@ usage()
USAGE: ${progname} <MODE> <OPTION> USAGE: ${progname} <MODE> <OPTION>
possible values for 'mode': possible values for 'mode':
$(listitems "${buildpath}") $(items "${buildpath}")
For each of the above modes, you may also do: For each of the above modes, you may also do:
${progname} <MODE> list ${progname} <MODE> list

View File

@ -4,8 +4,7 @@
# This file is only used by update/project/trees # This file is only used by update/project/trees
eval "$(setvars "" _target rev _xm)" eval "$(setvars "" _target rev _xm loc url bkup_url depend)"
eval "$(setvars "" loc url bkup_url depend)"
tmp_git_dir="${PWD}/tmp/gitclone" tmp_git_dir="${PWD}/tmp/gitclone"
fetch_project_trees() fetch_project_trees()

View File

@ -4,7 +4,7 @@
# Modifications in this version are Copyright 2021 and 2023 Leah Rowe. # Modifications in this version are Copyright 2021 and 2023 Leah Rowe.
# Original copyright detailed in repo: https://review.coreboot.org/coreboot/ # Original copyright detailed in repo: https://review.coreboot.org/coreboot/
eval "$(setvars "" MRC_url MRC_url_bkup MRC_hash MRC_board)" eval "$(setvars "" MRC_url MRC_url_bkup MRC_hash MRC_board ROOTFS SHELLBALL)"
extract_mrc() extract_mrc()
{ {
@ -12,14 +12,14 @@ extract_mrc()
[ -z "${CONFIG_MRC_FILE}" ] && \ [ -z "${CONFIG_MRC_FILE}" ] && \
err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set" err "extract_mrc $MRC_hash: CONFIG_MRC_FILE not set"
_file="${MRC_url##*/}" ROOTFS="root-a.ext2"
_file="${_file%.zip}" SHELLBALL="chromeos-firmwareupdate-${MRC_board}"
( (
x_ cd "${appdir}" x_ cd "${appdir}"
extract_partition ROOT-A "${_file}" root-a.ext2 extract_partition
extract_shellball root-a.ext2 chromeos-firmwareupdate-${MRC_board} extract_shellball
extract_coreboot chromeos-firmwareupdate-${MRC_board} extract_coreboot
) )
x_ "${cbfstool}" "${appdir}/"coreboot-*.bin extract -n mrc.bin \ x_ "${cbfstool}" "${appdir}/"coreboot-*.bin extract -n mrc.bin \
@ -28,9 +28,9 @@ extract_mrc()
extract_partition() extract_partition()
{ {
NAME=${1} NAME="ROOT-A"
FILE=${2} FILE="${MRC_url##*/}"
ROOTFS=${3} FILE="${FILE%.zip}"
_bs=1024 _bs=1024
printf "Extracting ROOT-A partition\n" printf "Extracting ROOT-A partition\n"
@ -46,9 +46,6 @@ extract_partition()
extract_shellball() extract_shellball()
{ {
ROOTFS=${1}
SHELLBALL=${2}
printf "Extracting chromeos-firmwareupdate\n" printf "Extracting chromeos-firmwareupdate\n"
printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \ printf "cd /usr/sbin\ndump chromeos-firmwareupdate ${SHELLBALL}\nquit" \
| debugfs "${ROOTFS}" || err "extract_shellball: debugfs" | debugfs "${ROOTFS}" || err "extract_shellball: debugfs"
@ -56,13 +53,12 @@ extract_shellball()
extract_coreboot() extract_coreboot()
{ {
_shellball=${1}
_unpacked=$( mktemp -d ) _unpacked=$( mktemp -d )
printf "Extracting coreboot image\n" printf "Extracting coreboot image\n"
[ -f "${_shellball}" ] || \ [ -f "${SHELLBALL}" ] || \
err "extract_coreboot: shellball missing in google cros image" err "extract_coreboot: shellball missing in google cros image"
x_ sh "${_shellball}" --unpack "${_unpacked}" x_ sh "${SHELLBALL}" --unpack "${_unpacked}"
# TODO: audit the f* out of that shellball, for each mrc version. # TODO: audit the f* out of that shellball, for each mrc version.
# it has to be updated for each mrc update. we should ideally # it has to be updated for each mrc update. we should ideally

View File

@ -17,11 +17,11 @@ eval "$(setvars "" CONFIG_BOARD_DELL_E6400 CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN \
CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_SMSC_SCH5545_EC_FW_FILE \ CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_SMSC_SCH5545_EC_FW_FILE \
CONFIG_IFD_BIN_PATH CONFIG_MRC_FILE _dest board boarddir)" CONFIG_IFD_BIN_PATH CONFIG_MRC_FILE _dest board boarddir)"
listitems() items()
{ {
rval=1 rval=1
[ ! -d "${1}" ] && \ [ ! -d "${1}" ] && \
printf "listitems: directory '%s' doesn't exist" "${1}" && \ printf "items: directory '%s' doesn't exist" "${1}" && \
return 1 return 1
for x in "${1}/"*; do for x in "${1}/"*; do
# -e used because this is for files *or* directories # -e used because this is for files *or* directories

View File

@ -25,15 +25,14 @@ pv="${pv} payload_seabios_withgrub payload_uboot memtest_bin"
v="romdir cbrom initmode displaymode cbcfg targetdir tree arch" v="romdir cbrom initmode displaymode cbcfg targetdir tree arch"
v="${v} grub_timeout ubdir vendorfiles board grub_scan_disk uboot_config" v="${v} grub_timeout ubdir vendorfiles board grub_scan_disk uboot_config"
eval "$(setvars "n" ${pv})" eval "$(setvars "n" ${pv})"
eval "$(setvars "" ${v})" eval "$(setvars "" ${v} boards _displaymode _payload _keyboard all targets)"
eval "$(setvars "" boards _displaymode _payload _keyboard all targets)"
main() main()
{ {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case ${1} in case ${1} in
help) usage && exit 0 ;; help) usage && exit 0 ;;
list) listitems config/coreboot && exit 0 ;; list) items config/coreboot && exit 0 ;;
-d) _displaymode="${2}" ;; -d) _displaymode="${2}" ;;
-p) _payload="${2}" ;; -p) _payload="${2}" ;;
-k) _keyboard="${2}" ;; -k) _keyboard="${2}" ;;
@ -45,7 +44,7 @@ main()
shift 2 shift 2
done done
[ "${all}" != "y" ] || boards=$(listitems config/coreboot) || \ [ "${all}" != "y" ] || boards=$(items config/coreboot) || \
err "Cannot generate list of boards for building" err "Cannot generate list of boards for building"
for x in ${boards}; do for x in ${boards}; do
@ -63,11 +62,7 @@ main()
printf "\nROM images available in these directories:\n" printf "\nROM images available in these directories:\n"
printf "${targets}^^ ROM images available in these directories.\n\n" printf "${targets}^^ ROM images available in these directories.\n\n"
printf "WARNING!!!!!!! PLEASE READ:\n\n" printf "DO NOT flash ROM images from elf/ - please use bin/ instead.\n"
printf "DO NOT flash ROM images contained under elf/, because they lack"
printf " payloads and will BRICK your machine. Please flash ROM images"
printf " contained under bin/ instead. YOU HAVE BEEN WARNED.\n\n"
} }
check_target() check_target()
@ -151,13 +146,12 @@ prepare_target()
build_dependency_seabios() build_dependency_seabios()
{ {
[ "${payload_seabios}" = "y" ] || return 0 [ "${payload_seabios}" = "y" ] || return 0
[ -f "${seavgabiosrom}" ] && \
[ -f elf/seabios/default/libgfxinit/bios.bin.elf ] && \
[ -f elf/seabios/default/vgarom/bios.bin.elf ] && \
[ -f elf/seabios/default/normal/bios.bin.elf ] && return 0
if [ ! -f "${seavgabiosrom}" ] \
|| [ ! -f elf/seabios/default/libgfxinit/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/vgarom/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/normal/bios.bin.elf ]; then
x_ ./update project trees -b seabios x_ ./update project trees -b seabios
fi
} }
build_dependency_grub() build_dependency_grub()
@ -413,7 +407,7 @@ usage()
./build fw coreboot x60 -p grub -d corebootfb -k usqwerty ./build fw coreboot x60 -p grub -d corebootfb -k usqwerty
possible values for 'target': possible values for 'target':
$(listitems "config/coreboot") $(items "config/coreboot")
Refer to the ${projectname} documentation for more information. Refer to the ${projectname} documentation for more information.
EOF EOF

View File

@ -87,7 +87,7 @@ build_targets()
[ $# -gt 0 ] && target1="${1}" [ $# -gt 0 ] && target1="${1}"
[ "${target1}" = "utils" ] && [ "${project}" = "coreboot" ] && \ [ "${target1}" = "utils" ] && [ "${project}" = "coreboot" ] && \
shift 1 shift 1
targets=$(listitems "${cfgsdir}") || \ targets=$(items "${cfgsdir}") || \
err "Cannot get options for ${cfgsdir}" err "Cannot get options for ${cfgsdir}"
[ $# -gt 0 ] && targets=$@ [ $# -gt 0 ] && targets=$@
@ -173,15 +173,14 @@ handle_src_tree()
fi fi
[ "${target1}" = "utils" ] && [ "${project}" = "coreboot" ] && return 0 [ "${target1}" = "utils" ] && [ "${project}" = "coreboot" ] && return 0
[ "$project" != "coreboot" ] && [ "$project" != "u-boot" ] && return 0
# u-boot and coreboot are both compiled with coreboot's crossgcc # u-boot and coreboot are both compiled with coreboot's crossgcc
if [ "${project}" = "coreboot" ] || [ "${project}" = "u-boot" ]; then
[ ! -z ${mode} ] || check_cross_compiler || \ [ ! -z ${mode} ] || check_cross_compiler || \
err "handle_src_tree ${project}/${target}: crossgcc" err "handle_src_tree ${project}/${target}: crossgcc"
cbfstool="cbutils/${tree}/cbfstool" cbfstool="cbutils/${tree}/cbfstool"
[ -f "${cbfstool}" ] || \ [ -f "${cbfstool}" ] && return 0
x_ ./update project trees -b coreboot utils "${tree}" x_ ./update project trees -b coreboot utils "${tree}"
fi
} }
# set up cross-compiler (coreboot crossgcc) for u-boot and coreboot # set up cross-compiler (coreboot crossgcc) for u-boot and coreboot
@ -279,6 +278,7 @@ run_make_command()
x_ printf "%s\n" "${version%%-*}" >"${codedir}/.coreboot-version" x_ printf "%s\n" "${version%%-*}" >"${codedir}/.coreboot-version"
x_ make ${mode} -j$(nproc) -C "${codedir}" x_ make ${mode} -j$(nproc) -C "${codedir}"
[ "${mode}" != "clean" ] && return 0 [ "${mode}" != "clean" ] && return 0
make -C "${codedir}" distclean 2>/dev/null || : make -C "${codedir}" distclean 2>/dev/null || :
} }

View File

@ -63,9 +63,8 @@ build_dependencies()
x_ ./update project trees -b uefitool x_ ./update project trees -b uefitool
[ -f "${kbc1126_ec_dump}" ] || \ [ -f "${kbc1126_ec_dump}" ] || \
x_ make -C "${cbdir}/util/kbc1126" x_ make -C "${cbdir}/util/kbc1126"
if [ ! -f "${cbfstool}" ] || [ ! -f "${ifdtool}" ]; then [ -f "${cbfstool}" ] && [ -f "${ifdtool}" ] && return 0
x_ ./update project trees -b coreboot utils default x_ ./update project trees -b coreboot utils default
fi
} }
download_vendorfiles() download_vendorfiles()
@ -85,8 +84,7 @@ download_vendorfiles()
"${E6400_VGA_DL_url_bkup}" "${E6400_VGA_DL_hash}" \ "${E6400_VGA_DL_url_bkup}" "${E6400_VGA_DL_hash}" \
"${CONFIG_VGA_BIOS_FILE}" "${CONFIG_VGA_BIOS_FILE}"
[ -z "${CONFIG_HAVE_MRC}" ] && return 0 [ -z "${CONFIG_HAVE_MRC}" ] && return 0
fetch "mrc" "${MRC_url}" "${MRC_url_bkup}" "${MRC_hash}" \ fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE"
"${CONFIG_MRC_FILE}"
} }
fetch() fetch()

View File

@ -15,7 +15,7 @@ main()
{ {
[ $# -lt 1 ] && err "No options specified." [ $# -lt 1 ] && err "No options specified."
[ "${1}" = "listboards" ] && \ [ "${1}" = "listboards" ] && \
listitems config/coreboot && exit 0 items config/coreboot && exit 0
archive="${1}" archive="${1}"