From 92c6da7b210d760693d2f36c457ea96eeaf8d7a2 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 1 Oct 2023 02:12:42 +0100 Subject: build/boot/roms_helper: shorten variable names also: further reduce the number of arguments passed, to certain functions as and when feasible, in cases where those are global variables that never change. the cbfstool argument in mkUbootRom wasn't even used. that function was only using the global variable, which again is only set once. i also shortened a few messages, removed a few errant line breaks and reduced sloccount by exactly 1 in main() by re-arranging how the shift command is used. it's mainly about shortening variable names, to then reduce the number of line breaks, but it's a surgical code size reduction in build/boot/roms. Signed-off-by: Leah Rowe --- include/boot.sh | 22 +++---- script/build/boot/roms | 8 +-- script/build/boot/roms_helper | 132 ++++++++++++++++++------------------------ 3 files changed, 69 insertions(+), 93 deletions(-) diff --git a/include/boot.sh b/include/boot.sh index 06648cb6..6685652d 100755 --- a/include/boot.sh +++ b/include/boot.sh @@ -3,7 +3,7 @@ # SPDX-FileCopyrightText: 2022 Ferass El Hafidi # SPDX-FileCopyrightText: 2023 Leah Rowe -eval "$(setvars "" first board boards _displaymode _payload _keyboard_layout)" +eval "$(setvars "" first board boards _displaymode _payload _keyboard)" main() { @@ -16,21 +16,17 @@ main() while [ $# -gt 0 ]; do case ${1} in - -d) - _displaymode="${2}" - shift ;; - -p) - _payload="${2}" - shift ;; - -k) - _keyboard_layout="${2}" - shift ;; + -d) _displaymode="${2}" ;; + -p) _payload="${2}" ;; + -k) _keyboard="${2}" ;; all) - first="all" ;; + first="all" + continue ;; *) - boards="${1} ${boards}" ;; + boards="${1} ${boards}" + continue ;; esac - shift + shift 2 done handle_targets diff --git a/script/build/boot/roms b/script/build/boot/roms index 39c0eed6..29f53dda 100755 --- a/script/build/boot/roms +++ b/script/build/boot/roms @@ -21,8 +21,7 @@ handle_targets() { [ -z "${_displaymode}" ] || _displaymode="-d ${_displaymode}" [ -z "${_payload}" ] || _payload="-p ${_payload}" - [ -z "${_keyboard_layout}" ] || \ - _keyboard_layout="-k ${_keyboard_layout}" + [ -z "${_keyboard}" ] || _keyboard="-k ${_keyboard}" printf "Building %s ROM images\n" "${projectname}" @@ -44,10 +43,9 @@ check_targets() build_bootroms() { - opts="${_displaymode} ${_payload} ${_keyboard_layout}" + opts="${_displaymode} ${_payload} ${_keyboard}" for x in ${boards}; do - ./build boot roms_helper ${_displaymode} ${_payload} \ - ${_keyboard_layout} ${x} || \ + ./build boot roms_helper ${opts} ${x} || \ err "handle_targets ${opts} ${x}: build error" [ -d "bin/${x}" ] && targets="${x} ${targets}" done diff --git a/script/build/boot/roms_helper b/script/build/boot/roms_helper index 927c1401..09b08125 100755 --- a/script/build/boot/roms_helper +++ b/script/build/boot/roms_helper @@ -25,7 +25,7 @@ kmapdir="config/grub/keymap" eval "$(setvars "n" payload_grub payload_grub_withseabios payload_seabios \ payload_seabios_withgrub payload_memtest payload_uboot)" -eval "$(setvars "" romdir cbdir cbfstool corebootrom initmode displaymode \ +eval "$(setvars "" romdir cbdir cbfstool cbrom initmode displaymode \ cbcfg targetdir grub_timeout ubdir blobs_required)" eval "$(setvars "undefined" grub_scan_disk tree arch uboot_config)" @@ -108,7 +108,7 @@ build_dependencies() cbdir="coreboot/${board}" [ "${board}" = "${tree}" ] || cbdir="coreboot/${tree}" cbfstool="cbutils/${tree}/cbfstool" - corebootrom="${cbdir}/build/coreboot.rom" + cbrom="${cbdir}/build/coreboot.rom" ./build coreboot utils ${tree} || err "cannot build cbutils/${tree}" @@ -144,7 +144,7 @@ build_dependency_grub() [ "${payload_seabios_withgrub}" != "y" ] && return 0 rebuild_grub="n" - [ ! -f "${grubelf}" ] && rebuild_grub="y" + [ -f "${grubelf}" ] || rebuild_grub="y" for keymapfile in "${kmapdir}"/*.gkb; do [ "${rebuild_grub}" = "y" ] || break [ -f "${keymapfile}" ] || continue @@ -196,7 +196,6 @@ build_target() build_roms() { cbcfg="${1}" - [ ! -f "${cbcfg}" ] && \ printf "'%s' does not exist. Skipping build for %s %s %s\n" \ "${cbcfg}" "${board}" "${displaymode}" "${initmode}" \ @@ -205,22 +204,22 @@ build_roms() ./handle make config -b coreboot ${board} || \ err "build_roms: cannot build coreboot for target: ${board}" - _corebootrom="elf/coreboot/${board}/${initmode}_${displaymode}" + _cbrom="elf/coreboot/${board}/${initmode}_${displaymode}" [ "${initmode}" = "normal" ] && \ - _corebootrom="${_corebootrom%_${displaymode}}" - _corebootrom="${_corebootrom}/coreboot.rom" - corebootrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)" - cp "${_corebootrom}" "${corebootrom}" || \ + _cbrom="${_cbrom%_${displaymode}}" + _cbrom="${_cbrom}/coreboot.rom" + cbrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)" + cp "${_cbrom}" "${cbrom}" || \ err "build_roms: cannot copy rom" [ "${payload_memtest}" != "y" ] || \ - "${cbfstool}" "${corebootrom}" add-payload \ + "${cbfstool}" "${cbrom}" add-payload \ -f "${memtest_bin}" -n img/memtest -c lzma || \ err "build_roms: cannot add img/memtest to coreboot rom" [ "${payload_seabios}" = "y" ] && \ build_seabios_roms [ "${payload_grub}" != "y" ] || \ - build_grub_roms "${corebootrom}" "grub" || \ + build_grub_roms "${cbrom}" "grub" || \ err "build_roms: build_grub_roms failed" [ "${payload_uboot}" = "y" ] || return 0 build_uboot_roms @@ -230,13 +229,13 @@ build_seabios_roms() { if [ "${payload_seabios_withgrub}" = "y" ]; then tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) - cp "${corebootrom}" "${tmprom}" || \ + cp "${cbrom}" "${tmprom}" || \ err "build_seabios_roms: cannot copy to tmprom" build_grub_roms "${tmprom}" "seabios_withgrub" || \ err "build_roms: cannot build grub roms, seabios w/grub" rm -f "${tmprom}" || err "build_roms: can't remove tmprom" else - t=$(mkSeabiosRom "${corebootrom}" "fallback/payload") || \ + t=$(mkSeabiosRom "${cbrom}" "fallback/payload") || \ err "build_seabios_roms: cannot build tmprom" newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}" [ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \ @@ -250,33 +249,30 @@ build_seabios_roms() # Make separate ROM images with GRUB payload, for each supported keymap build_grub_roms() { - tmprompath="${1}" - firstpayloadname="${2}" # allow values: grub, seabios, seabios_withgrub - grubelf_cbfs="fallback/payload" + tmprom="${1}" + payload1="${2}" # allow values: grub, seabios, seabios_withgrub + grub_cbfs="fallback/payload" if [ "${payload_grub_withseabios}" = "y" ] && \ - [ "${firstpayloadname}" = "grub" ]; then - mv "$(mkSeabiosRom "${tmprompath}" "seabios.elf")" \ - "${tmprompath}" || \ + [ "${payload1}" = "grub" ]; then + mv "$(mkSeabiosRom "${tmprom}" "seabios.elf")" "${tmprom}" || \ err "build_grub_roms: cannot move tmp rom (seabios.elf)" elif [ "${payload_seabios_withgrub}" = "y" ] && \ - [ "${firstpayloadname}" != "grub" ]; then - mv "$(mkSeabiosRom "${tmprompath}" "fallback/payload")" \ - "${tmprompath}" || \ - err "build_grub_roms: cannot move SeaBIOS ROM to tmprom" - grubelf_cbfs="img/grub2" + [ "${payload1}" != "grub" ]; then + mv "$(mkSeabiosRom "${tmprom}" fallback/payload)" "${tmprom}" \ + || err "build_grub_roms: cannot move SeaBIOS ROM to tmprom" + grub_cbfs="img/grub2" fi # we only need insert grub.elf once, for each coreboot config: - "${cbfstool}" "${tmprompath}" add-payload -f "${grubelf}" \ - -n ${grubelf_cbfs} -c lzma || \ - err "build_grub_roms: cannot add grub payload to tmprom" + "${cbfstool}" "${tmprom}" add-payload -f "${grubelf}" -n ${grub_cbfs} \ + -c lzma || err "build_grub_roms: cannot add grub payload to tmprom" # we only need insert background.png once, for each coreboot config: if [ "${displaymode}" = "vesafb" ] || \ [ "${displaymode}" = "corebootfb" ]; then backgroundfile="config/grub/background/${grub_background}" - "${cbfstool}" "${tmprompath}" add -f ${backgroundfile} \ + "${cbfstool}" "${tmprom}" add -f ${backgroundfile} \ -n background.png -t raw || \ err "build_grub_roms: cannot add background.png to tmprom" @@ -287,38 +283,31 @@ build_grub_roms() { printf "set grub_scan_disk=\"%s\"\n" "${grub_scan_disk}" > \ "${tmpcfg}" || err "build_grub_roms: cannot create scan.cfg" [ "${grub_scan_disk}" = "both" ] || \ - "${cbfstool}" "${tmprompath}" add -f "${tmpcfg}" -n scan.cfg \ - -t raw || err "build_grub_roms: cannot insert scan.cfg into CBFS" - + "${cbfstool}" "${tmprom}" add -f "${tmpcfg}" -n scan.cfg -t \ + raw || err "build_grub_roms: can't insert scan.cfg" printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \ - err "build_grub_roms: cannot insert into temporary timeout.cfg" + err "build_grub_roms: can't create timeout.cfg" [ -z "${grub_timeout}" ] || \ - "${cbfstool}" "${tmprompath}" add -f "${tmpcfg}" -n timeout.cfg \ - -t raw || err "build_grub_roms: cannot create timeout.cfg" - rm -f "${tmpcfg}" || err "cannot delete tmpcfg" + "${cbfstool}" "${tmprom}" add -f "${tmpcfg}" -n timeout.cfg \ + -t raw || err "build_grub_roms: can't insert timeout.cfg" + rm -f "${tmpcfg}" || err "build_grub_roms: can't delete tmpcfg" keymaps="" for kmapfile in "${kmapdir}"/*; do keymaps="${keymaps} ${kmapfile}" done - [ -z ${_keyboard_layout} ] || \ - keymaps="${kmapdir}/${_keyboard_layout}.gkb" + [ -z ${_keyboard} ] || keymaps="${kmapdir}/${_keyboard}.gkb" for keymapfile in ${keymaps}; do - printf "keymaps is %s, keymapfile is %s\n" \ - "${keymaps}" "${keymapfile}" - [ -f "${keymapfile}" ] || continue - keymap="${keymapfile##*/}" keymap="${keymap%.gkb}" + tmpgrubrom="$(mkGrubRom "${keymap}" "${tmprom}")" - tmpgrubrom="$(mkGrubRom "${keymap}" "${tmprompath}")" - - newrom="${romdir}/${firstpayloadname}_${board}_${initmode}_" + newrom="${romdir}/${payload1}_${board}_${initmode}_" newrom="${newrom}${displaymode}_${keymap}.rom" [ "${initmode}" = "normal" ] && \ - newrom="${romdir}/${firstpayloadname}_${board}_" && \ + newrom="${romdir}/${payload1}_${board}_" && \ newrom="${newrom}${initmode}_${keymap}.rom" moverom "${tmpgrubrom}" "${newrom}" || \ err "build_grub_roms, moverom" @@ -328,15 +317,14 @@ build_grub_roms() { # make a rom in /tmp/ and then print the path of that ROM mkGrubRom() { - target_keymap="${1}" - target_cbrom="${2}" + _keymap="${1}" + _cbrom="${2}" - keymapcfg="elf/grub/keymap_${target_keymap}.cfg" + keymapcfg="elf/grub/keymap_${_keymap}.cfg" tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || \ err "mkGrubRom: cannot create tmprom" - cp "${target_cbrom}" "${tmprom}" || \ - err "mkGrubRom: cannot copy to tmprom" + cp "${_cbrom}" "${tmprom}" || err "mkGrubRom: cannot copy to tmprom" "${cbfstool}" "${tmprom}" add -f "${keymapcfg}" -n keymap.cfg -t raw \ || err "mkGrubRom: cannot add keymap.cfg to tmprom" @@ -345,17 +333,17 @@ mkGrubRom() { # make a rom in /tmp/ and then print the path of that ROM mkSeabiosRom() { - target_cbrom="${1}" # rom to insert seabios in. will not be touched + _cbrom="${1}" # rom to insert seabios in. will not be touched # (a tmpfile will be made instead) - target_seabios_cbfs_path="${2}" # e.g. fallback/payload - target_seabioself="elf/seabios/default/${initmode}/bios.bin.elf" + _seabios_cbfs_path="${2}" # e.g. fallback/payload + _seabioself="elf/seabios/default/${initmode}/bios.bin.elf" tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) - cp "${target_cbrom}" "${tmprom}" || \ + cp "${_cbrom}" "${tmprom}" || \ err "mkSeabiosRom: cannot copy to tmprom" - "${cbfstool}" "${tmprom}" add-payload -f "${target_seabioself}" \ - -n ${target_seabios_cbfs_path} -c lzma || \ - err "mkSeabiosRom: can't add payload, ${target_seabioself}, to rom" + "${cbfstool}" "${tmprom}" add-payload -f "${_seabioself}" \ + -n ${_seabios_cbfs_path} -c lzma || \ + err "mkSeabiosRom: can't add payload, ${_seabioself}, to rom" "${cbfstool}" "${tmprom}" add-int -i 3000 -n etc/ps2-keyboard-spinup \ || err "mkSeabiosRom: cbfs add-int etc/ps2-keyboard-spinup 3000" @@ -374,8 +362,7 @@ mkSeabiosRom() { build_uboot_roms() { - tmprom="$(mkUbootRom "${corebootrom}" "fallback/payload" \ - "${uboot_config}" "${cbfstool}")" + tmprom="$(mkUbootRom "${cbrom}" "fallback/payload")" newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom" [ "${initmode}" = "normal" ] && \ newrom="${romdir}/uboot_payload_${board}_${initmode}.rom" @@ -386,25 +373,21 @@ build_uboot_roms() # make a rom in /tmp/ and then print the path of that ROM mkUbootRom() { - target_cbrom="${1}" # rom to insert u-boot in. it won't be touched + _cbrom="${1}" # rom to insert u-boot in. it won't be touched # (a tmpfile will be made instead) - target_uboot_cbfs_path="${2}" # e.g. fallback/payload - target_uboot_config="${3}" - cbfstool_path="${4}" + _uboot_cbfs_path="${2}" # e.g. fallback/payload - target_ubdir="elf/u-boot/${board}/${target_uboot_config}" - target_ubootelf="${target_ubdir}/u-boot.elf" - [ -f "${target_ubootelf}" ] || \ - target_ubootelf="${target_ubdir}/u-boot.bin" - [ -f "${target_ubootelf}" ] || \ - err "mkUbootRom: ${board}: cant find u-boot build" + _ubdir="elf/u-boot/${board}/${uboot_config}" + _ubootelf="${_ubdir}/u-boot.elf" + [ -f "${_ubootelf}" ] || _ubootelf="${_ubdir}/u-boot.bin" + [ -f "${_ubootelf}" ] || err "mkUbootRom: ${board}: cant find u-boot" tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) - cp "${target_cbrom}" "${tmprom}" || \ + cp "${_cbrom}" "${tmprom}" || \ err "mkUbootRom: cannot copy to tmprom" - "${cbfstool}" "${tmprom}" add-payload -f "${target_ubootelf}" \ - -n ${target_uboot_cbfs_path} -c lzma || \ + "${cbfstool}" "${tmprom}" add-payload -f "${_ubootelf}" \ + -n ${_uboot_cbfs_path} -c lzma || \ err "mkUbootRom: cannot add u-boot to tmprom" printf "%s\n" "${tmprom}" @@ -416,12 +399,11 @@ moverom() { rompath="${1}" newrom="${2}" - printf "\nCreating new ROM image: %s\n" "${newrom}" + printf "Creating target image: %s\n" "${newrom}" [ -d "${newrom%/*}" ] || mkdir -p "${newrom%/*}/" || \ err "moverom: cannot create rom directory: \"${newrom%/*}\"" - [ "${blobs_required}" = "n" ] && \ - newrom="${newrom%.rom}_noblobs.rom" + [ "${blobs_required}" = "n" ] && newrom="${newrom%.rom}_noblobs.rom" cp "${rompath}" "${newrom}" || err "moverom: can't copy rom" } -- cgit v1.2.1