summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-12-22 13:05:32 +0000
committerLeah Rowe <leah@libreboot.org>2023-12-23 02:52:30 +0000
commitb0e5fc9d9c8f648b2b98c48d126cf8e6e828ddd4 (patch)
tree4b9de2046d8923e7e38754276bf3911741d9a54b /script
parentb111f4840a043a7337937c001e1f82b7af3302f2 (diff)
lbmk scripts: general code cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'script')
-rwxr-xr-xscript/build/roms65
-rwxr-xr-xscript/update/trees21
-rwxr-xr-xscript/vendor/download72
-rwxr-xr-xscript/vendor/inject17
4 files changed, 73 insertions, 102 deletions
diff --git a/script/build/roms b/script/build/roms
index 03dce95e..2926f297 100755
--- a/script/build/roms
+++ b/script/build/roms
@@ -19,7 +19,7 @@ kmapdir="config/grub/keymap"
# Disable all payloads by default.
# target.cfg files have to specifically enable [a] payload(s)
-pv="payload_grub payload_grub_withseabios payload_seabios payload_memtest"
+pv="payload_grub payload_grub_withseabios payload_seabios payload_memtest t"
pv="${pv} payload_seabios_withgrub payload_seabios_grubonly payload_uboot memtest_bin"
v="romdir cbrom initmode displaymode cbcfg targetdir tree arch"
v="${v} grub_timeout ubdir vendorfiles board grub_scan_disk uboot_config"
@@ -63,7 +63,7 @@ main()
[ -z "${targets}" ] && err "No ROM images were compiled"
printf "\nROM images available in these directories:\n"
- printf "%s^^ ROM images available in these directories.\n\n" "${targets}"
+ printf "%s^^ ROM images available in these directories.\n\n" "$targets"
printf "DO NOT flash ROM images from elf/ - please use bin/ instead.\n"
}
@@ -77,29 +77,21 @@ check_target()
# Override the above defaults using target.cfg
. "${targetdir}/target.cfg"
- [ -z "${grub_scan_disk}" ] && \
- grub_scan_disk="both"
+ [ -z "${grub_scan_disk}" ] && grub_scan_disk="both"
[ "${grub_scan_disk}" != "both" ] && [ "${grub_scan_disk}" != "ata" ] \
&& [ "${grub_scan_disk}" != "ahci" ] && \
grub_scan_disk="both"
- [ -z "${tree}" ] && \
- err "Target '${board}' defines no tree. Skipping build."
- [ -z "${arch}" ] && \
- err "Target '${board}' defines no arch. Skipping build."
+ [ -z "$arch" ] && err "$board: arch not defined"
+ [ -z "$tree" ] && err "$board: tree not defined"
- [ "${payload_memtest}" != "y" ] && \
- payload_memtest="n"
- [ "${payload_grub_withseabios}" = "y" ] && \
- payload_grub="y"
+ [ "${payload_memtest}" != "y" ] && payload_memtest="n"
+ [ "${payload_grub_withseabios}" = "y" ] && payload_grub="y"
[ "${payload_grub_withseabios}" = "y" ] && \
eval "$(setvars "y" payload_seabios payload_seabios_withgrub)"
- [ "${payload_seabios_withgrub}" = "y" ] && \
- payload_seabios="y"
- if [ "${payload_seabios_grubonly}" = "y" ]; then
- payload_seabios="y"
- payload_seabios_withgrub="y"
- fi
+ [ "$payload_seabios_withgrub" = "y" ] && payload_seabios="y"
+ [ "$payload_seabios_grubonly" = "y" ] && payload_seabios="y"
+ [ "$payload_seabios_grubonly" = "y" ] && payload_seabios_withgrub="y"
# The reverse logic must not be applied. If SeaBIOS-with-GRUB works,
# that doesn't mean GRUB-withSeaBIOS will. For example, the board
@@ -220,13 +212,14 @@ build_roms()
cbcfg="${1}"
if [ ! -f "${cbcfg}" ]; then
printf "'%s' does not exist. Skipping build for %s %s %s\n" \
- "${cbcfg}" "${board}" "${displaymode}" "${initmode}" 1>&2
+ "$cbcfg" "$board" "$displaymode" "$initmode" 1>&2
return 0
fi
x_ ./update trees -b coreboot ${board}
- _cbrom="elf/coreboot_nopayload_DO_NOT_FLASH/${board}/${initmode}_${displaymode}"
+ _cbrom="elf/coreboot_nopayload_DO_NOT_FLASH"
+ _cbrom="${_cbrom}/${board}/${initmode}_${displaymode}"
[ "${initmode}" = "normal" ] && \
_cbrom="${_cbrom%"_${displaymode}"}"
_cbrom="${_cbrom}/coreboot.rom"
@@ -248,10 +241,9 @@ build_roms()
build_seabios_roms()
{
if [ "${payload_seabios_withgrub}" = "y" ]; then
- tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
- x_ cp "${cbrom}" "${tmprom}"
- x_ build_grub_roms "${tmprom}" "seabios_withgrub"
- x_ rm -f "${tmprom}"
+ t=$(mktemp -t coreboot_rom.XXXXXXXXXX)
+ x_ cp "${cbrom}" "${t}"
+ x_ build_grub_roms "${t}" "seabios_withgrub"
else
t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \
err "build_seabios_roms: cannot build tmprom"
@@ -259,8 +251,8 @@ build_seabios_roms()
[ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \
&& newrom="${newrom}_${board}_${initmode}"
x_ moverom "${t}" "${newrom}.rom"
- x_ rm -f "${t}"
fi
+ x_ rm -f "${t}"
}
# Make separate ROM images with GRUB payload, for each supported keymap
@@ -270,11 +262,11 @@ build_grub_roms()
payload1="${2}" # allow values: grub, seabios, seabios_withgrub
grub_cbfs="fallback/payload"
- [ "${payload1}" = "grub" ] && [ "${payload_grub_withseabios}" = "y" ] \
- && x_ mv "$(mkSeabiosRom "${tmprom}" "seabios.elf")" "${tmprom}"
- [ "${payload1}" != "grub" ] && [ "${payload_seabios_withgrub}" = "y" ] \
+ [ "$payload1" = "grub" ] && [ "$payload_grub_withseabios" = "y" ] \
+ && x_ mv "$(mkSeabiosRom "$tmprom" "seabios.elf")" "$tmprom"
+ [ "$payload1" != "grub" ] && [ "$payload_seabios_withgrub" = "y" ] \
&& grub_cbfs="img/grub2" && \
- x_ mv "$(mkSeabiosRom "${tmprom}" fallback/payload)" "${tmprom}"
+ x_ mv "$(mkSeabiosRom "$tmprom" fallback/payload)" "$tmprom"
# we only need insert grub.elf once, for each coreboot config:
x_ "${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" \
@@ -285,14 +277,15 @@ build_grub_roms()
[ "${displaymode}" = "corebootfb" ]; then
backgroundfile="config/grub/background/${grub_background}"
"${cbfstool}" "${tmprom}" add -f ${backgroundfile} \
- -n background.png -t raw || err "insert background, ${backgroundfile}"
+ -n background.png -t raw || \
+ err "insert background, ${backgroundfile}"
fi
tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX)
- printf "set grub_scan_disk=\"%s\"\n" "${grub_scan_disk}" >"${tmpcfg}" \
- || err "set grub_scandisk, ${grub_scan_disk}, ${tmpcfg}"
+ printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" >"$tmpcfg" \
+ || err "set grub_scandisk, $grub_scan_disk, $tmpcfg"
[ "${grub_scan_disk}" = "both" ] || \
- x_ "${cbfstool}" "${tmprom}" add -f "${tmpcfg}" -n scan.cfg -t raw
+ x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \
err "set timeout, ${grub_timeout}, ${tmpcfg}"
[ -z "${grub_timeout}" ] || x_ "${cbfstool}" "${tmprom}" add \
@@ -332,7 +325,7 @@ mkGrubRom() {
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
x_ cp "${_cbrom}" "${tmprom}"
- x_ "${cbfstool}" "${tmprom}" add -f "${keymapcfg}" -n keymap.cfg -t raw
+ x_ "$cbfstool" "$tmprom" add -f "$keymapcfg" -n keymap.cfg -t raw
printf "%s\n" "${tmprom}"
}
@@ -348,7 +341,7 @@ mkSeabiosRom() {
x_ cp "${_cbrom}" "${tmprom}"
x_ "${cbfstool}" "${tmprom}" add-payload -f "${_seabioself}" \
-n "${_seabios_cbfs_path}" -c lzma
- x_ "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup
+ x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
z="2"; [ "${initmode}" = "vgarom" ] && z="0"
x_ "${cbfstool}" "${tmprom}" add-int -i $z -n etc/pci-optionrom-exec
@@ -369,7 +362,7 @@ mkSeabiosGrubonlyRom()
tmpbootorder=$(mktemp -t coreboot_rom.XXXXXXXXXX)
# only load grub, by inserting a custom bootorder file
- printf "/rom@img/grub2\n" > "${tmpbootorder}" || err "printf bootorder"
+ printf "/rom@img/grub2\n" > "$tmpbootorder" || err "printf bootorder"
x_ "${cbfstool}" "${_grubrom}" \
add -f "${tmpbootorder}" -n bootorder -t raw
x_ rm -f "${tmpbootorder}"
diff --git a/script/update/trees b/script/update/trees
index 6e98b370..832f27c5 100755
--- a/script/update/trees
+++ b/script/update/trees
@@ -36,11 +36,9 @@ main()
[ -z "${_f}" ] && err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)"
[ -z "${project}" ] && err "project name not specified"
- if [ -f "config/${project}/build.list" ]; then
- build_targets $@
- else
- build_projects $@
- fi
+ _cmd="build_projects"
+ [ -f "config/${project}/build.list" ] && _cmd="build_targets"
+ $_cmd $@
}
build_projects()
@@ -103,7 +101,7 @@ handle_targets()
x_ handle_defconfig
done
- [ "${target1}" = "utils" ] && [ "${project}" = "coreboot" ] && return 0
+ [ "$target1" = "utils" ] && [ "$project" = "coreboot" ] && return 0
[ -z "${mode}" ] || return 0
printf "Done! The files are stored under %s/\n\n" "${elfdir}"
}
@@ -161,10 +159,7 @@ handle_src_tree()
x_ ./update trees -f "${project}" "${target}"
fi
- [ "${target1}" = "utils" ] && [ "${project}" = "coreboot" ] && return 0
- [ "$project" != "coreboot" ] && [ "$project" != "u-boot" ] && return 0
-
- # u-boot and coreboot are both compiled with coreboot's crossgcc
+ [ "$target1" = "utils" ] && [ "$project" = "coreboot" ] && return 0
[ -z "${mode}" ] || return 0
check_cross_compiler
}
@@ -199,7 +194,7 @@ check_cross_compiler()
check_config()
{
- [ ! -f "${config}" ] && \
+ [ -f "${config}" ] || \
err "check_config: ${project}/${target}: configs missing"
dest_dir="${elfdir}/${target}/${config_name}"
@@ -224,8 +219,8 @@ handle_makefile()
if [ -e "${codedir}/.git" ] && [ "${project}" = "u-boot" ] && \
[ "${mode}" = "distclean" ]; then
x_ git -C "${codedir}" clean -fdx
- elif [ "${mode}" = "oldconfig" ] || [ "${mode}" = "olddefconfig" ] || \
- [ "${mode}" = "menuconfig" ] || [ "${mode}" = "nconfig" ]; then
+ elif [ "$mode" = "oldconfig" ] || [ "$mode" = "olddefconfig" ] || \
+ [ "$mode" = "menuconfig" ] || [ "$mode" = "nconfig" ]; then
x_ cp "${codedir}/.config" "${config}"
elif [ "${mode}" = "savedefconfig" ]; then
x_ cp "${codedir}/defconfig" "${config}"
diff --git a/script/vendor/download b/script/vendor/download
index 7913b558..b83ffb48 100755
--- a/script/vendor/download
+++ b/script/vendor/download
@@ -32,7 +32,7 @@ main()
boarddir="${cbcfgsdir}/${board}"
_b="${board%%_*mb}" # shorthand (avoid duplicating config per rom size)
- check_defconfig "${boarddir}" || exit 0
+ check_defconfig "${boarddir}" && exit 0
detect_firmware && exit 0
scan_config "${_b}" "config/vendor" "err"
@@ -54,16 +54,13 @@ detect_firmware()
build_dependencies()
{
- [ -d "${cbdir}" ] || \
- x_ ./update trees -f coreboot ${cbdir##*/}
+ [ -d "${cbdir}" ] || x_ ./update trees -f coreboot ${cbdir##*/}
for d in uefitool biosutilities bios_extract; do
[ -d "src/${d}" ] && continue
x_ ./update trees -f "${d}"
done
- [ -f "${uefiextract}" ] || \
- x_ ./update trees -b uefitool
- [ -f "${kbc1126_ec_dump}" ] || \
- x_ make -C "${cbdir}/util/kbc1126"
+ [ -f "${uefiextract}" ] || x_ ./update trees -b uefitool
+ [ -f "${kbc1126_ec_dump}" ] || x_ make -C "${cbdir}/util/kbc1126"
[ -f "${cbfstool}" ] && [ -f "${ifdtool}" ] && return 0
x_ ./update trees -b coreboot utils default
}
@@ -71,19 +68,17 @@ build_dependencies()
download_vendorfiles()
{
[ -z "${CONFIG_HAVE_ME_BIN}" ] || \
- fetch "intel_me" "${DL_url}" "${DL_url_bkup}" "${DL_hash}" \
+ fetch intel_me "$DL_url" "$DL_url_bkup" "$DL_hash" \
"${CONFIG_ME_BIN_PATH}"
[ -z "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" ] || \
- fetch "sch5545ec" "${SCH5545EC_DL_url}" \
- "${SCH5545EC_DL_url_bkup}" "${SCH5545EC_DL_hash}" \
- "${CONFIG_SMSC_SCH5545_EC_FW_FILE}"
+ fetch sch5545ec "$SCH5545EC_DL_url" "$SCH5545EC_DL_url_bkup" \
+ "$SCH5545EC_DL_hash" "$CONFIG_SMSC_SCH5545_EC_FW_FILE"
[ -z "${CONFIG_KBC1126_FIRMWARE}" ] || \
- fetch "kbc1126ec" "${EC_url}" "${EC_url_bkup}" "${EC_hash}" \
+ fetch kbc1126ec "$EC_url" "$EC_url_bkup" "$EC_hash" \
"${CONFIG_KBC1126_FW1}"
[ -z "${CONFIG_VGA_BIOS_FILE}" ] || \
- fetch "e6400vga" "${E6400_VGA_DL_url}" \
- "${E6400_VGA_DL_url_bkup}" "${E6400_VGA_DL_hash}" \
- "${CONFIG_VGA_BIOS_FILE}"
+ fetch "e6400vga" "$E6400_VGA_DL_url" "$E6400_VGA_DL_url_bkup" \
+ "$E6400_VGA_DL_hash" "$CONFIG_VGA_BIOS_FILE"
[ -z "${CONFIG_HAVE_MRC}" ] && return 0
fetch "mrc" "$MRC_url" "$MRC_url_bkup" "$MRC_hash" "$CONFIG_MRC_FILE"
}
@@ -95,30 +90,27 @@ fetch()
dl_bkup="${3}"
dlsum="${4}"
[ "${5}" = "/dev/null" ] && return 0
- [ "${5# }" = "${5}" ] || err "fetch: space not allowed in _dest: '${5}'"
- [ "${5#/}" = "${5}" ] || err "fetch: absolute path not allowed: '${5}'"
+ [ "${5# }" = "$5" ] || err "fetch: space not allowed in _dest: '$5'"
+ [ "${5#/}" = "$5" ] || err "fetch: absolute path not allowed: '$5'"
_dest="${5##*../}"
_dl="${vendir}/cache/${dlsum}"
- dl_fail=""
+ eval "$(setvars "n" dl_fail is_rom)"
x_ mkdir -p "${_dl%/*}"
- is_rom="n"
if [ "${dl}" = "rom" ] || [ "${dl_bkup}" = "rom" ]; then
- dl_fail="n"
is_rom="y"
else
dl_fail="y"
- vendor_checksum "${dlsum}" "${_dl}" && dl_fail="n"
+ vendor_checksum "${dlsum}" "${_dl}" || dl_fail="n"
fi
for url in "${dl}" "${dl_bkup}"; do
[ "${dl_fail}" = "n" ] && break
[ -z "${url}" ] && continue
x_ rm -f "${_dl}"
- curl --location --retry 3 -A "${_ua}" "${url}" -o "${_dl}" || \
- wget --tries 3 -U "${_ua}" "${url}" -O "${_dl}" || \
- continue
- vendor_checksum "${dlsum}" "${_dl}" && dl_fail="n"
+ curl --location --retry 3 -A "$_ua" "$url" -o "$_dl" || \
+ wget --tries 3 -U "$_ua" "$url" -O "$_dl" || continue
+ vendor_checksum "${dlsum}" "${_dl}" || dl_fail="n"
done
[ "${dl_fail}" = "y" ] && \
err "fetch ${dlsum}: matched file unavailable"
@@ -133,16 +125,15 @@ fetch()
vendor_checksum()
{
- [ "$(sha512sum "${2}" | awk '{print $1}')" != "${1}" ] || return 0
- printf "Bad checksum for file: %s\n" "${2}" 1>&2
- rm -f "${2}" || :
- return 1
+ [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
+ printf "Bad checksum for file: %s\n" "$2" 1>&2
+ rm -f "$2" || :
}
mkdirs()
{
if [ -f "${1}" ]; then
- printf "mkdirs %s %s: already downloaded\n" "${1}" "${2}" 1>&2
+ printf "mkdirs %s %s: already downloaded\n" "$1" "$2" 1>&2
return 1
fi
mkdir -p "${1%/*}" || err "mkdirs: !mkdir -p ${1%/*}"
@@ -161,8 +152,7 @@ extract_intel_me()
{
_me="${PWD}/${_dest}" # must always be an absolute path
cdir="${PWD}/${appdir}" # must always be an absolute path
- [ $# -gt 0 ] && _me="${1}"
- [ $# -gt 0 ] && cdir="${2}"
+ [ $# -gt 0 ] && _me="${1}" && cdir="${2}"
[ -f "${_me}" ] && return 0
sdir="$(mktemp -d)"
@@ -196,9 +186,8 @@ extract_intel_me()
extract_archive()
{
- innoextract "${1}" -d "${2}" || python "${pfs_extract}" "${1}" -e || \
- 7z x "${1}" -o"${2}" || unar "${1}" -o "${2}" || \
- unzip "${1}" -d "${2}" || return 1
+ innoextract "$1" -d "$2" || python "$pfs_extract" "$1" -e || 7z x "$1" \
+ -o"$2" || unar "$1" -o "$2" || unzip "$1" -d "$2" || return 1
}
extract_kbc1126ec()
@@ -227,12 +216,10 @@ extract_kbc1126ec()
extract_e6400vga()
{
- [ -z "${E6400_VGA_offset}" ] && \
- err "extract_e6400vga: E6400 VGA offset not defined"
- [ -z "${E6400_VGA_romname}" ] && \
- err "extract_e6400vga: E6400 VGA ROM name not defined"
- tail -c +${E6400_VGA_offset} "${_dl}" | \
- gunzip >"${appdir}/bios.bin" || :
+ for v in E6400_VGA_offset E6400_VGA_romname; do
+ eval "[ -z \"\$$v\" ] && err \"extract_e6400vga: $v undefined\""
+ done
+ tail -c +$E6400_VGA_offset "$_dl" | gunzip > "$appdir/bios.bin" || :
(
x_ cd "${appdir}"
[ -f "bios.bin" ] || err "extract_e6400vga: can't extract bios.bin"
@@ -247,8 +234,7 @@ extract_e6400vga()
extract_sch5545ec()
{
# full system ROM (UEFI), to extract with UEFIExtract:
- _bios="${_dl}_extracted/Firmware"
- _bios="${_bios}/1 ${dlsum} -- 1 System BIOS vA.28.bin"
+ _bios="${_dl}_extracted/Firmware/1 ${dlsum} -- 1 System BIOS vA.28.bin"
# this is the SCH5545 firmware, inside of the extracted UEFI ROM:
_sch5545ec_fw="${_bios}.dump/4 7A9354D9-0468-444A-81CE-0BF617D890DF"
_sch5545ec_fw="${_sch5545ec_fw}/54 D386BEB8-4B54-4E69-94F5-06091F67E0D3"
diff --git a/script/vendor/inject b/script/vendor/inject
index 7ae4fc02..b4b74bb7 100755
--- a/script/vendor/inject
+++ b/script/vendor/inject
@@ -135,11 +135,9 @@ patch_release_roms()
x_ cd "${_tmpdir}/bin/"* # TODO: very dodgy, re-write accordingly
# NOTE: For compatibility with older rom releases, defer to sha1
- [ "${nukemode}" = "nuke" ] || \
- sha512sum --status -c vendorhashes || \
- sha1sum --status -c vendorhashes || \
- sha512sum --status -c blobhashes || \
- sha1sum --status -c blobhashes || \
+ [ "${nukemode}" = "nuke" ] || sha512sum --status -c vendorhashes || \
+ sha1sum --status -c vendorhashes || sha512sum --status -c \
+ blobhashes || sha1sum --status -c blobhashes || \
err "patch_release_roms: ROMs did not match expected hashes"
) || err "can't verify vendor hashes"
@@ -168,10 +166,10 @@ patch_rom()
# may sometimes insert certain vendor files at the wrong offset)
# (unless nomicrocode is the only config provided)
[ "${rom}" != "${rom%_nomicrocode.rom}.rom" ] && \
- [ -f "${rom%_nomicrocode.rom}.rom" ] && \
- [ "${release}" = "y" ] && return 0
+ [ -f "${rom%_nomicrocode.rom}.rom" ] && \
+ [ "${release}" = "y" ] && return 0
- x_ check_defconfig "${boarddir}"
+ check_defconfig "$boarddir" && err "patch_rom $boarddir: no configs"
set -- "${boarddir}/config/"*
. "${1}" 2>/dev/null
@@ -185,8 +183,7 @@ patch_rom()
"${CONFIG_KBC1126_FW1_OFFSET}" && \
inject "ecfw2.bin" "$CONFIG_KBC1126_FW2" "raw" \
"${CONFIG_KBC1126_FW2_OFFSET}"
- [ -n "${CONFIG_VGA_BIOS_FILE}" ] && \
- [ -n "${CONFIG_VGA_BIOS_ID}" ] && \
+ [ -n "$CONFIG_VGA_BIOS_FILE" ] && [ -n "$CONFIG_VGA_BIOS_ID" ] && \
inject "pci${CONFIG_VGA_BIOS_ID}.rom" \
"${CONFIG_VGA_BIOS_FILE}" "optionrom"
[ "${CONFIG_INCLUDE_SMSC_SCH5545_EC_FW}" = "y" ] && \