build/roms_helper: move logic into main()

logic will be split from main into smaller
functions, in follow-up commits
This commit is contained in:
Leah Rowe
2023-05-12 16:55:45 +01:00
parent df611f9bc1
commit bceb5f2eb4
+112 -96
View File
@@ -36,6 +36,33 @@ kmapdir="resources/grub/keymap"
displaymodes="" displaymodes=""
payloads="" payloads=""
keyboard_layouts="" keyboard_layouts=""
board=""
grub_scan_disk="undefined"
cbtree="undefined"
romtype="normal" # optional parameter in board.cfg. "normal" is default
arch="undefined"
# Disable all payloads by default.
# board.cfg files have to specifically enable [a] payload(s)
payload_grub="n"
payload_grub_wseabios="n" # seabios chainloaded from grub
payload_seabios="n"
payload_seabios_wgrub="n" # i386-coreboot grub from SeaBIOS boot menu
payload_memtest="n"
payload_uboot="n"
uboot_config="undefined"
romdir=""
cbdir=""
cbfstool=""
corebootrom=""
seavgabiosrom=""
CROSS_COMPILE=""
main()
{
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case ${1} in case ${1} in
-d) -d)
@@ -53,48 +80,36 @@ while [ $# -gt 0 ]; do
shift shift
done done
printf "board is %s , kb is %s , displaymode is %s , payloads is %s\n" \ printf "board %s , kb %s , displaymode %s , payloads %s\n" \
${board} ${keyboard_layouts} ${displaymodes} ${payloads} ${board} ${keyboard_layouts} ${displaymodes} \
${payloads}
if [ "${board}" = "" ]; then
printf "build/roms: undefined board. Exiting\n"
exit 1
fi
if [ ! -d "${cbcfgdir}/${board}" ]; then if [ ! -d "${cbcfgdir}/${board}" ]; then
printf "build/roms: Target not defined: %s\n" ${board} printf "build/roms: Target not defined: %s\n" ${board}
exit 1 exit 1
fi fi
if [ ! -f "${cbcfgdir}/${board}/board.cfg" ]; then if [ ! -f "${cbcfgdir}/${board}/board.cfg" ]; then
printf "build/roms: Missing board.cfg for target: %s\n" ${board} printf "build/roms %s: Missing board.cfg\n" ${board}
exit 1 exit 1
fi fi
grub_scan_disk="undefined"
cbtree="undefined"
romtype="normal" # optional parameter in board.cfg. "normal" is default
arch="undefined"
# Disable all payloads by default.
# board.cfg files have to specifically enable [a] payload(s)
payload_grub="n"
payload_grub_withseabios="n" # seabios chainloaded from grub
payload_seabios="n"
payload_seabios_withgrub="n" # i386-coreboot grub from SeaBIOS boot menu
payload_memtest="n"
payload_uboot="n"
uboot_config="undefined"
# Override the above defaults using board.cfg # Override the above defaults using board.cfg
. "${cbcfgdir}/${board}/board.cfg" . "${cbcfgdir}/${board}/board.cfg"
if [ "${grub_scan_disk}" = "undefined" ]; then if [ "${grub_scan_disk}" = "undefined" ]; then
printf "build/roms: Target '%s' does not define grub_scan_disk. " \ printf "build/roms '%s': grub_scan_disk is undefined. " \
${board} ${board}
printf "Defaulting to 'both'.\n" printf "Defaulting to 'both'.\n"
grub_scan_disk="both" grub_scan_disk="both"
fi fi
if [ "${grub_scan_disk}" != "both" ] && \ if [ "${grub_scan_disk}" != "both" ] && \
[ "${grub_scan_disk}" != "ata" ] && \ [ "${grub_scan_disk}" != "ata" ] && \
[ "${grub_scan_disk}" != "ahci" ]; then [ "${grub_scan_disk}" != "ahci" ]; then
printf "build/roms: Target '%s' defines bad grub_scan_disk option. " \ printf "build/roms '%s': invalid grub_scan_disk config. " \
${board} ${board}
printf "Defaulting to 'both'.\n" printf "Defaulting to 'both'.\n"
grub_scan_disk="both" grub_scan_disk="both"
@@ -102,13 +117,13 @@ if [ "${grub_scan_disk}" != "both" ] && \
fi fi
if [ "${cbtree}" = "undefined" ]; then if [ "${cbtree}" = "undefined" ]; then
printf "build/roms: Target '%s' does not define a coreboot tree. " \ printf "build/roms '%s': undefined coreboot tree. " \
${board} ${board}
printf "Skipping build.\n" printf "Skipping build.\n"
exit 1 exit 1
fi fi
if [ "${arch}" = "undefined" ]; then if [ "${arch}" = "undefined" ]; then
printf "build/roms: Target '%s' does not define a CPU type. " \ printf "build/roms '%s': undefined CPU type. " \
${board} ${board}
printf "Skipping build.\n" printf "Skipping build.\n"
exit 1 exit 1
@@ -118,49 +133,45 @@ if [ "${payload_memtest}" != "n" ] && \
[ "${payload_memtest}" != "y" ]; then [ "${payload_memtest}" != "y" ]; then
payload_memtest="n" payload_memtest="n"
fi fi
if [ "${payload_grub_withseabios}" = "y" ]; then if [ "${payload_grub_wseabios}" = "y" ]; then
payload_grub="y" payload_grub="y"
fi fi
if [ "${payload_grub_withseabios}" = "y" ]; then if [ "${payload_grub_wseabios}" = "y" ]; then
payload_seabios="y" payload_seabios="y"
payload_seabios_withgrub="y" payload_seabios_wgrub="y"
fi fi
if [ "${payload_seabios_withgrub}" = "y" ]; then if [ "${payload_seabios_wgrub}" = "y" ]; then
payload_seabios="y" payload_seabios="y"
fi fi
# NOTE: reverse logic must NOT be applied. If SeaBIOS-with-GRUB works, that # NOTE: reverse logic must NOT be applied. If SeaBIOS-with-GRUB works,
# doesn't necessarily mean GRUb-with-SeaBIOS will. For example, the board # that doesn't mean GRUB-with-SeaBIOS will. For example, the board
# might have an external GPU, where it's recommended to boot SeaBIOS first # might have an external GPU, where SeaBIOS should be booted first
if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] \ if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] \
&& [ "${payload_uboot}" != "y" ]; then && [ "${payload_uboot}" != "y" ]; then
for configfile in "${cbcfgdir}/${board}/config/"*; do for configfile in "${cbcfgdir}/${board}/config/"*; do
if [ ! -e "${configfile}" ]; then if [ ! -e "${configfile}" ]; then
continue continue
fi fi
printf "ERROR build/roms: Target '%s' defines no payload. " \ printf "build/roms %s: Payload undefined. Exiting.\n" \
${board} ${board}
printf "Exiting.\n"
exit 1 exit 1
done done
fi fi
if [ "${payload_uboot}" != "n" ] && \ if [ "${payload_uboot}" != "n" ] && \
[ "${payload_uboot}" != "y" ]; then [ "${payload_uboot}" != "y" ]; then
payload_uboot="n" payload_uboot="n"
fi fi
if [ "${payload_uboot}" = "y" ] && \ if [ "${payload_uboot}" = "y" ] && \
[ "${uboot_config}" = "undefined" ]; then [ "${uboot_config}" = "undefined" ]; then
uboot_config="default" uboot_config="default"
fi fi
# Override all payload directives with cmdline args # Override all payload directives with cmdline args
if [ ! -z ${payloads} ]; then if [ ! -z ${payloads} ]; then
echo "setting payloads $payloads" echo "setting payloads $payloads"
payload_grub="n" payload_grub="n"
payload_grub_withseabios="n" # seabios chainloaded from grub payload_grub_wseabios="n" # seabios chainloaded from grub
payload_seabios="n" payload_seabios="n"
payload_seabios_withgrub="n" # i386-coreboot grub from SeaBIOS menu payload_seabios_wgrub="n" # grub from SeaBIOS menu
payload_uboot="n" payload_uboot="n"
payload_memtest="n" payload_memtest="n"
@@ -181,7 +192,6 @@ seavgabiosrom="payload/seabios/seavgabios.bin"
if [ ! -d "${cbdir}" ]; then if [ ! -d "${cbdir}" ]; then
./download coreboot ${cbtree} ./download coreboot ${cbtree}
fi fi
cat version > "${cbdir}/.coreboot-version" cat version > "${cbdir}/.coreboot-version"
if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then
@@ -221,7 +231,6 @@ export PATH="$(pwd)/${cbdir}/util/crossgcc/xgcc/bin:$PATH"
if [ ! -f "${cbfstool}" ]; then if [ ! -f "${cbfstool}" ]; then
./build module cbutils ${cbtree} || exit 1 ./build module cbutils ${cbtree} || exit 1
fi fi
if [ ! -f "${seavgabiosrom}" ] \ if [ ! -f "${seavgabiosrom}" ] \
|| [ ! -f payload/seabios/seabios_libgfxinit.elf ] \ || [ ! -f payload/seabios/seabios_libgfxinit.elf ] \
|| [ ! -f payload/seabios/seabios_vgarom.elf ] \ || [ ! -f payload/seabios/seabios_vgarom.elf ] \
@@ -229,11 +238,11 @@ if [ ! -f "${seavgabiosrom}" ] \
if [ "${payload_seabios}" = "y" ]; then if [ "${payload_seabios}" = "y" ]; then
./build payload seabios ./build payload seabios
elif [ "${payload_grub}" = "y" ] \ elif [ "${payload_grub}" = "y" ] \
&& [ "${payload_grub_withseabios}" = "y" ]; then && [ "${payload_grub_wseabios}" = "y" ]
then
./build payload seabios ./build payload seabios
fi fi
fi fi
if [ "${payload_memtest}" = "y" ]; then if [ "${payload_memtest}" = "y" ]; then
if [ ! -f "memtest86plus/memtest" ]; then if [ ! -f "memtest86plus/memtest" ]; then
./build module memtest86plus ./build module memtest86plus
@@ -244,20 +253,20 @@ fi
rm -f "${romdir}"/* rm -f "${romdir}"/*
if [ "${payload_grub}" = "y" ] \ if [ "${payload_grub}" = "y" ] \
|| [ "${payload_seabios_withgrub}" = "y" ]; then || [ "${payload_seabios_wgrub}" = "y" ]; then
if [ -f "payload/grub/grub_usqwerty.cfg" ]; then if [ -f "payload/grub/grub_usqwerty.cfg" ]; then
sha1sumcmd="sha1sum resources/grub/config/grub.cfg" sha1cmd="sha1sum resources/grub/config/grub.cfg"
grubrefchecksum="$(${sha1sumcmd} | awk '{print $1}')" grubrefchecksum="$(${sha1cmd} | awk '{print $1}')"
sha1sumcmd="sha1sum payload/grub/grub_usqwerty.cfg" sha1cmd="sha1sum payload/grub/grub_usqwerty.cfg"
grubbuildchecksum="$(${sha1sumcmd} | awk '{print $1}')" grubsha1="$(${sha1cmd} | awk '{print $1}')"
if [ "${grubrefchecksum}" != "${grubbuildchecksum}" ]; then if [ "${grubrefchecksum}" != "${grubsha1}" ]; then
rm -Rf payload/grub/ rm -Rf payload/grub/
printf "Changes detected to GRUB. Re-building now:\n" printf "GRUB change detected. Rebuilding:\n"
fi fi
else else
printf "Required GRUB payloads not yet built. Building now:\n" printf "GRUB payloads needed. Building:\n"
rm -Rf payload/grub/ # just in case rm -Rf payload/grub/ # just in case
fi fi
for keymapfile in ${kmapdir}/*; do for keymapfile in ${kmapdir}/*; do
@@ -280,6 +289,7 @@ if [ "${payload_grub}" = "y" ] \
fi fi
if [ "${payload_uboot}" = "y" ]; then if [ "${payload_uboot}" = "y" ]; then
ubdir=""
if [ "${uboot_config}" = "default" ]; then if [ "${uboot_config}" = "default" ]; then
ubdir="payload/u-boot/${board}" ubdir="payload/u-boot/${board}"
else else
@@ -291,12 +301,50 @@ if [ "${payload_uboot}" = "y" ]; then
elif [ -f "${ubdir}/u-boot" ]; then elif [ -f "${ubdir}/u-boot" ]; then
ubootelf="${ubdir}/u-boot" ubootelf="${ubdir}/u-boot"
else else
printf "Required U-Boot payload not yet built. Building now\n" printf "U-Boot needed. Building:\n"
rm -Rf "payload/u-boot/${board}" # just in case rm -Rf "payload/u-boot/${board}" # just in case
./build payload u-boot "${board}" ./build payload u-boot "${board}"
fi fi
fi fi
if [ -z ${displaymodes} ]; then
initmode="libgfxinit"
for displaymode in corebootfb txtmode; do
_cbcfg="${cbcfgdir}/${board}/config/${initmode}"
_cbcfg="${_cbcfg}_${displaymode}"
mkRoms "${_cbcfg}" "${displaymode}" "${initmode}"
done
initmode="vgarom"
for displaymode in vesafb txtmode; do
_cbcfg="${cbcfgdir}/${board}/config/${initmode}"
_cbcfg="${_cbcfg}_${displaymode}"
mkRoms "${_cbcfg}" "${displaymode}" "${initmode}"
done
initmode="normal"
displaymode="txtmode"
_cbcfg="${cbcfgdir}/${board}/config/${initmode}"
mkRoms "${_cbcfg}" "${displaymode}" "${initmode}"
else
echo "special displaymode defined as $displaymodes"
for initmode in vgarom libgfxinit; do
for displaymode in ${displaymodes}; do
_cbcfg="${cbcfgdir}/${board}/config/"
_cbcfg="${_cbcfg}${initmode}_${displaymode}"
mkRoms "${_cbcfg}" "${displaymode}" \
"${initmode}"
done
done
fi
(
cd "${cbdir}"
make distclean # TODO: do make clean instead (avoid re-building utils)
)
}
# it is assumed that no other work will be done on the ROM # it is assumed that no other work will be done on the ROM
# after calling this function. therefore this function is "final" # after calling this function. therefore this function is "final"
moverom() moverom()
@@ -350,10 +398,10 @@ moverom()
mkCoreboot() mkCoreboot()
{ {
cbdir="${1}" # eg. coreboot/default cbdir="${1}" # eg. coreboot/default
cbcfgpath="${2}" # eg. ${cbcfgdir}/e6400nvidia_4mb/config/normal _cbcfg="${2}" # eg. ${cbcfgdir}/e6400nvidia_4mb/config/normal
if [ ! -f "${cbcfgpath}" ]; then if [ ! -f "${_cbcfg}" ]; then
printf "\nmkCoreboot: coreboot config '%s' does not exist. " \ printf "\nmkCoreboot: coreboot config '%s' does not exist. " \
${cbcfgpath} ${_cbcfg}
printf "Skipping build.\n" printf "Skipping build.\n"
return 0 return 0
fi fi
@@ -372,7 +420,7 @@ mkCoreboot()
mv "${cbdir}/cbfstool" "${cbfstool}" mv "${cbdir}/cbfstool" "${cbfstool}"
fi fi
) )
cp "${cbcfgpath}" "${cbdir}"/.config cp "${_cbcfg}" "${cbdir}"/.config
./build module cbutils ${cbdir#coreboot/} || exit 1 ./build module cbutils ${cbdir#coreboot/} || exit 1
( (
cd "${cbdir}" cd "${cbdir}"
@@ -512,15 +560,15 @@ mkRomsWithGrub()
tmprompath="${1}" tmprompath="${1}"
initmode="${2}" initmode="${2}"
displaymode="${3}" displaymode="${3}"
firstpayloadname="${4}" # allow values: grub, seabios, seabios_withgrub firstpayloadname="${4}" # allow values: grub, seabios, seabios_wgrub
x=${tmprompath} x=${tmprompath}
y=${initmode} y=${initmode}
if [ "${payload_grub_withseabios}" = "y" ] \ if [ "${payload_grub_wseabios}" = "y" ] \
&& [ "${firstpayloadname}" = "grub" ]; then && [ "${firstpayloadname}" = "grub" ]; then
mv "$(mkSeabiosRom "${x}" "seabios.elf" "${y}")" \ mv "$(mkSeabiosRom "${x}" "seabios.elf" "${y}")" \
"${tmprompath}" "${tmprompath}"
elif [ "${payload_seabios_withgrub}" ] \ elif [ "${payload_seabios_wgrub}" ] \
&& [ "${firstpayloadname}" != "grub" ]; then && [ "${firstpayloadname}" != "grub" ]; then
mv "$(mkSeabiosRom "${x}" "fallback/payload" "${y}")" \ mv "$(mkSeabiosRom "${x}" "fallback/payload" "${y}")" \
"${tmprompath}" "${tmprompath}"
@@ -569,18 +617,18 @@ mkRomsWithGrub()
# Main ROM building function. This calls all other functions # Main ROM building function. This calls all other functions
mkRoms() mkRoms()
{ {
cbcfgpath="${1}" _cbcfg="${1}"
displaymode="${2}" displaymode="${2}"
initmode="${3}" initmode="${3}"
if [ ! -f "${cbcfgpath}" ]; then if [ ! -f "${_cbcfg}" ]; then
printf "'%s' does not exist. Skipping build for %s %s %s\n" \ printf "'%s' does not exist. Skipping build for %s %s %s\n" \
${cbcfgpath} ${board} \ ${_cbcfg} ${board} \
${displaymode} ${initmode} ${displaymode} ${initmode}
return 0 return 0
fi fi
mkCoreboot "${cbdir}" "${cbcfgpath}" mkCoreboot "${cbdir}" "${_cbcfg}"
if [ "${displaymode}" = "txtmode" ] \ if [ "${displaymode}" = "txtmode" ] \
&& [ "${payload_memtest}" = "y" ]; then && [ "${payload_memtest}" = "y" ]; then
@@ -590,7 +638,7 @@ mkRoms()
fi fi
if [ "${payload_seabios}" = "y" ]; then if [ "${payload_seabios}" = "y" ]; then
if [ "${payload_seabios_withgrub}" = "n" ]; then if [ "${payload_seabios_wgrub}" = "n" ]; then
x=${corebootrom} x=${corebootrom}
y=${initmode} y=${initmode}
t=$(mkSeabiosRom "$x" "fallback/payload" "$y") t=$(mkSeabiosRom "$x" "fallback/payload" "$y")
@@ -633,36 +681,4 @@ mkRoms()
fi fi
} }
if [ -z ${displaymodes} ]; then main $@
initmode="libgfxinit"
for displaymode in corebootfb txtmode; do
cbcfgpath="${cbcfgdir}/${board}/config/${initmode}_$displaymode"
mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
done
initmode="vgarom"
for displaymode in vesafb txtmode; do
cbcfgpath="${cbcfgdir}/${board}/config/${initmode}_$displaymode"
mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
done
initmode="normal"
displaymode="txtmode"
cbcfgpath="${cbcfgdir}/${board}/config/${initmode}"
mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
else
echo "special displaymode defined as $displaymodes"
for initmode in vgarom libgfxinit; do
for displaymode in ${displaymodes}; do
cbcfgpath="${cbcfgdir}/${board}/config/${initmode}_"
cbcfgpath="${cbcfgpath}${displaymode}"
mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
done
done
fi
(
cd "${cbdir}"
make distclean
)