build/boot/roms_helper: simplify rom file handling

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2023-09-30 23:23:09 +01:00
parent c477599c78
commit 9bc9dddf64
+27 -35
View File
@@ -240,19 +240,13 @@ build_seabios_roms()
err "build_roms: cannot build grub roms, seabios w/grub" err "build_roms: cannot build grub roms, seabios w/grub"
rm -f "${tmprom}" || err "build_roms: can't remove tmprom" rm -f "${tmprom}" || err "build_roms: can't remove tmprom"
else else
x=${corebootrom} t=$(mkSeabiosRom "${corebootrom}" "fallback/payload" \
y=${initmode} "${initmode}") || \
t=$(mkSeabiosRom "$x" "fallback/payload" "$y") || \
err "build_seabios_roms: cannot build tmprom" err "build_seabios_roms: cannot build tmprom"
if [ "${initmode}" = "normal" ]; then newrom="${romdir}/seabios_${board}_${initmode}_${displaymode}"
newrompath="${romdir}/seabios_${board}_" [ "${initmode}" = "normal" ] && newrom="${romdir}/seabios" \
newrompath="${newrompath}${initmode}.rom" && newrom="${newrom}_${board}_${initmode}"
else moverom "${t}" "${newrom}.rom" || \
newrompath="${romdir}/seabios_${board}_"
newrompath="${newrompath}${initmode}_"
newrompath="${newrompath}${displaymode}.rom"
fi
moverom "${t}" "${newrompath}" || \
err "build_roms: cannot copy rom" err "build_roms: cannot copy rom"
rm -f "${t}" || err "cannot rm ${t}" rm -f "${t}" || err "cannot rm ${t}"
fi fi
@@ -296,17 +290,18 @@ build_grub_roms() {
fi fi
tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX) || tmpcfg=$(mktemp -t coreboot_rom.XXXXXXXXXX) ||
err "mkGrubRom: cannot create temporary scan.cfg" err "build_grub_roms: cannot create temporary scan.cfg"
printf "set grub_scan_disk=\"%s\"\n" "${grub_scan_disk}" > \ printf "set grub_scan_disk=\"%s\"\n" "${grub_scan_disk}" > \
"${tmpcfg}" || err "mkGrubRom: cannot insert to temporary scan.cfg" "${tmpcfg}" || err "build_grub_roms: cannot create scan.cfg"
[ "${grub_scan_disk}" = "both" ] || \ [ "${grub_scan_disk}" = "both" ] || \
"${cbfstool}" "${tmprompath}" add -f "${tmpcfg}" -n scan.cfg \ "${cbfstool}" "${tmprompath}" add -f "${tmpcfg}" -n scan.cfg \
-t raw || err "mkGrubROM: cannot insert scan.cfg into CBFS" -t raw || err "build_grub_roms: cannot insert scan.cfg into CBFS"
printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \ printf "set timeout=%s\n" "${grub_timeout}" > "${tmpcfg}" || \
err "mkGrubRom: cannot insert into temporary timeout.cfg" err "build_grub_roms: cannot insert into temporary timeout.cfg"
[ -z "${grub_timeout}" ] || \ [ -z "${grub_timeout}" ] || \
"${cbfstool}" "${tmprompath}" add -f "${tmpcfg}" -n timeout.cfg \ "${cbfstool}" "${tmprompath}" add -f "${tmpcfg}" -n timeout.cfg \
-t raw || err "mkGrubROM: cannot insert timeout.cfg into CBFS" -t raw || err "build_grub_roms: cannot create timeout.cfg"
rm -f "${tmpcfg}" || err "cannot delete tmpcfg" rm -f "${tmpcfg}" || err "cannot delete tmpcfg"
keymaps="" keymaps=""
@@ -327,15 +322,12 @@ build_grub_roms() {
tmpgrubrom="$(mkGrubRom "${keymap}" "${tmprompath}")" tmpgrubrom="$(mkGrubRom "${keymap}" "${tmprompath}")"
if [ "${initmode}" = "normal" ]; then newrom="${romdir}/${firstpayloadname}_${board}_${initmode}_"
newrompath="${romdir}/${firstpayloadname}_${board}_" newrom="${newrom}${displaymode}_${keymap}.rom"
newrompath="${newrompath}${initmode}_${keymap}.rom" [ "${initmode}" = "normal" ] && \
else newrom="${romdir}/${firstpayloadname}_${board}_" && \
newrompath="${romdir}/${firstpayloadname}_${board}_" newrom="${newrom}${initmode}_${keymap}.rom"
newrompath="${newrompath}${initmode}_${displaymode}_" moverom "${tmpgrubrom}" "${newrom}" || \
newrompath="${newrompath}${keymap}.rom"
fi
moverom "${tmpgrubrom}" "${newrompath}" || \
err "build_grub_roms, moverom" err "build_grub_roms, moverom"
rm -f "${tmpgrubrom}" || err "rm tmpgrubrom, build_grub_roms" rm -f "${tmpgrubrom}" || err "rm tmpgrubrom, build_grub_roms"
done done
@@ -392,10 +384,10 @@ build_uboot_roms()
{ {
tmprom="$(mkUbootRom "${corebootrom}" "fallback/payload" \ tmprom="$(mkUbootRom "${corebootrom}" "fallback/payload" \
"${uboot_config}" "${cbfstool}")" "${uboot_config}" "${cbfstool}")"
newrompath="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom" newrom="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
[ "${initmode}" = "normal" ] && \ [ "${initmode}" = "normal" ] && \
newrompath="${romdir}/uboot_payload_${board}_${initmode}.rom" newrom="${romdir}/uboot_payload_${board}_${initmode}.rom"
moverom "${tmprom}" "${newrompath}" || \ moverom "${tmprom}" "${newrom}" || \
err "build_roms: moverom fail (u-boot)" err "build_roms: moverom fail (u-boot)"
rm -f "${tmprom}" || err "build_roms: cannot rm u-boot rom" rm -f "${tmprom}" || err "build_roms: cannot rm u-boot rom"
} }
@@ -430,15 +422,15 @@ mkUbootRom() {
# after calling this function. therefore this function is "final" # after calling this function. therefore this function is "final"
moverom() { moverom() {
rompath="${1}" rompath="${1}"
newrompath="${2}" newrom="${2}"
printf "\nCreating new ROM image: %s\n" "${newrompath}" printf "\nCreating new ROM image: %s\n" "${newrom}"
[ -d "${newrompath%/*}" ] || mkdir -p "${newrompath%/*}/" || \ [ -d "${newrom%/*}" ] || mkdir -p "${newrom%/*}/" || \
err "moverom: cannot create rom directory: \"${newrompath%/*}\"" err "moverom: cannot create rom directory: \"${newrom%/*}\""
[ "${blobs_required}" = "n" ] && \ [ "${blobs_required}" = "n" ] && \
newrompath="${newrompath%.rom}_noblobs.rom" newrom="${newrom%.rom}_noblobs.rom"
cp "${rompath}" "${newrompath}" || err "moverom: can't copy rom" cp "${rompath}" "${newrom}" || err "moverom: can't copy rom"
} }
main $@ main $@