build/roms: Support using U-Boot as a coreboot payload

This enables embedding U-Boot into the coreboot roms as the payload. For
now, the ELF file generated by enabling CONFIG_REMAKE_ELF is used, which
includes the U-Boot binary and the board-specific device-tree file. It
might be better to use the FIT payload support for U-Boot, but that was
reportedly broken and is not tested yet.

Coreboot boards can specify payload_uboot="y" in their board.cfg to
enable building a rom with U-Boot as the payload, which is built from
the U-Boot board with the same name. Boards can further specify a
uboot_config option, to choose which board-specific config file U-Boot
should be built with.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
Alper Nebi Yasak 2022-08-26 17:14:57 +03:00 committed by Denis 'GNUtoo' Carikli
parent 4883b39e39
commit bdd6485dfc
Signed by: GNUtoo
GPG Key ID: 5F5DFCC14177E263
1 changed files with 61 additions and 1 deletions

View File

@ -64,6 +64,8 @@ payload_seabios="n"
payload_seabios_withgrub="n" # i386-coreboot grub accessible from SeaBIOS boot menu
seabios_opromloadonly="0"
payload_memtest="n"
payload_uboot="n"
uboot_config="undefined"
# Override the above defaults using board.cfg
source "resources/coreboot/${board}/board.cfg"
@ -110,7 +112,7 @@ fi
# NOTE: reverse logic must not be applied. If SeaBIOS-with-GRUB works, that doesn't
# necessarily mean GRUB-with-SeaBIOS will work nicely. for example, the board might
# only have an add-on GPU available, where it's recommended to boot SeaBIOS first
if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ]; then
if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] && [ "${payload_uboot}" != "y" ]; then
while true; do
for configfile in "resources/coreboot/${board}/config/"*; do
if [ -f "${configfile}" ]; then
@ -122,6 +124,16 @@ if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ]; then
done
fi
if [ "${payload_uboot}" != "n" ] && \
[ "${payload_uboot}" != "y" ]; then
payload_uboot="n"
fi
if [ "${payload_uboot}" = "y" ] && \
[ "${uboot_config}" = "undefined" ]; then
uboot_config="default"
fi
if [ "${payload_memtest}" = "y" ]; then
if [ ! -f "memtest86plus/memtest" ]; then
./build module memtest86plus
@ -216,6 +228,21 @@ if [ "${payload_grub}" = "y" ] || [ "${payload_seabios_withgrub}" = "y" ]; then
done
fi
if [ "${payload_uboot}" = "y" ]; then
if [ "${uboot_config}" = "default" ] && \
[ -f "payload/u-boot/${board}/u-boot.elf" ]; then
ubootelf="payload/u-boot/${board}/u-boot.elf"
else
ubootelf="payload/u-boot/${board}/${uboot_config}/u-boot.elf"
fi
if [ ! -f "${ubootelf}" ]; then
printf "Required U-Boot payloads not yet built. Building now:\n"
rm -Rf "payload/u-boot/${board}" # just in case
./build payload u-boot "${board}"
fi
fi
# it is assumed that no other work will be done on the ROM
# after calling this function. therefore this function is "final"
moverom() {
@ -325,6 +352,28 @@ make_seabios_rom() {
printf "%s\n" "${tmprom}"
}
# make a rom in /tmp/ and then print the path of that ROM
make_uboot_payload_rom() {
target_cbrom="${1}" # rom to insert u-boot in. this rom 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}"
if [ "${target_uboot_config}" = "default" ]; then
target_ubootelf="payload/u-boot/${board}/u-boot.elf"
else
target_ubootelf="payload/u-boot/${board}/${target_uboot_config}/u-boot.elf"
fi
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
cp "${target_cbrom}" "${tmprom}"
"${cbfstool}" "${tmprom}" add-payload -f "${target_ubootelf}" -n ${target_uboot_cbfs_path} -c lzma
printf "%s\n" "${tmprom}"
}
# make a rom in /tmp/ and then print the path of that ROM
make_grubrom_from_keymap() {
target_keymap="${1}"
@ -455,6 +504,17 @@ mkRoms() {
if [ "${payload_grub}" = "y" ]; then
mkRomsWithGrub "${corebootrom}" "${initmode}" "${displaymode}" "grub"
fi
if [ "${payload_uboot}" = "y" ]; then
tmpubootrom="$(make_uboot_payload_rom "${corebootrom}" "fallback/payload" "${uboot_config}" "${cbfstool}")"
if [ "${initmode}" = "normal" ]; then
newrompath="${romdir}/uboot_payload_${board}_${initmode}.rom"
else
newrompath="${romdir}/uboot_payload_${board}_${initmode}_${displaymode}.rom"
fi
moverom "${tmpubootrom}" "${newrompath}" "${romtype}"
rm -f "${tmpubootrom}"
fi
}
initmode="libgfxinit"