consolidate u-boot/seabios/coreboot build scripts

See file:
resources/scripts/build/defconfig/for
It is based on:
resources/scripts/build/payload/u-boot

The u-boot payload script has been deleted, as has the
seabios payload script; the build/boot/roms logic has
been heavily simplified too, by removing the logic for
building of elf files based on defconfig.

SeaBIOS, U-Boot and coreboot all use defconfig-type
infrastructure for their build systems, and they are
fundamentally the *same* in how to compile each codebase,
at least in an lbmk context, regardless of actual (and
very huge) differences in these codebases.

Several hundred sources-lines of code have been eliminated
by this change, drastically simplifying everything; U-Boot
payload compiling also now errors out when a single build
fails, instead of continuing. Also: build/boot/roms no longer
re-compiles a coreboot target that was already compiled,
which is the same behaviour observed for payloads.

(this means you must now manually delete a target, when you
wish to re-build it; the build/boot/roms logic now more or
less just runs cbfstool; blobutil is handled from
build/defconfig/for)

ALSO: Since crossgcc is now handled by build/defconfig/for, not
build/boot/roms, standalone compiling of u-boot is now possible.
This has been tested. You compile it like so:
./build defconfig for u-boot
or specific trees, e.g.
./build defconfig for u-boot default

One other consequence of this patch is that re-building the same
ROM image is now much faster, because the same builds are re-used
unless deleted. This could be useful when testing grub.cfg changes,
for example, if that's all you change. With things like ccache used
(not yet used robustly in lbmk), this could speed things up more,
depending on the codebase.

This patch demonstrates the raw power of lbmk; it is a very
simple and highly efficient build system, and now much more so!

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-08-17 23:27:30 +01:00
parent 673b144a4c
commit e5b898f6cb
20 changed files with 355 additions and 550 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@
/bios_extract/
/ec/
/tmp/
/elf/
/payload/
/me_cleaner/
*.s[a-w]?

View File

@ -25,7 +25,7 @@
.POSIX:
#.PHONY: all check modules ich9m-descriptors payloads roms release \
#.PHONY: all check modules ich9m-descriptors roms release \
# clean crossgcc-clean install-dependencies-ubuntu \
# install-dependencies-debian install-dependencies-arch \
# install-dependencies-void install-dependencies-fedora38 \
@ -39,9 +39,6 @@ modules:
ich9m-descriptors:
./build descriptors ich9m
payloads:
./build payload all
roms:
./build boot roms all
@ -53,13 +50,13 @@ clean:
./build clean cbutils
./build clean flashrom
./build clean ich9utils
./build clean payloads
./build clean seabios
./build clean grub
./build clean memtest86plus
./build clean rom_images
./build clean u-boot
./build clean bios_extract
rm -Rf elf/ bin/
crossgcc-clean:
./build clean crossgcc

View File

@ -0,0 +1 @@
build/coreboot.rom

View File

@ -47,8 +47,8 @@
}
{seabios}{
rev: 1281e340ad1d90c0cc8e8d902bb34f1871eb48cf
loc: seabios
rev: HEAD
loc: seabios/seabios
url: https://review.coreboot.org/seabios
bkup_url: https://github.com/coreboot/seabios
}

View File

@ -129,10 +129,6 @@ listboards()
buildrom() {
board="$1"
# Start by building blobs and placing them in the
# coreboot tree only for boards that need them
./update blobs download ${board} || exit 1
if [ -d "resources/coreboot/${board}/" ]; then
./build boot roms_helper ${board}${opts}
else

View File

@ -29,11 +29,19 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
err()
{
printf "ERROR: build/boot/roms: %s\n" "${1}" 1>&2
exit 1
}
projectname="$(cat projectname)"
blobs_required=""
microcode_required=""
board=""
ubdir=""
kmapdir="resources/grub/keymap"
displaymodes=""
payloads=""
@ -58,16 +66,11 @@ done
printf "\n\nboard is %s , kb is %s , displaymode is %s , payloads is %s\n" \
${board} ${keyboard_layouts} ${displaymodes} ${payloads} 1>&2
if [ ! -d "resources/coreboot/${board}" ]; then
printf "build/roms: Target not defined: %s\n" ${board}
exit 1
fi
if [ ! -f "resources/coreboot/${board}/target.cfg" ]; then
printf "build/roms: Missing target.cfg for target: %s\n" ${board}
exit 1
fi
[ ! -d "resources/coreboot/${board}" ] && \
err "Target not defined: ${board}"
[ ! -f "resources/coreboot/${board}/target.cfg" ] && \
err "Missing target.cfg for target: ${board}"
grub_scan_disk="undefined"
tree="undefined"
@ -80,72 +83,42 @@ 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
seabios_opromloadonly="0"
payload_memtest="n"
payload_uboot="n"
uboot_config="undefined"
# ditto option whether to compile ada in crossgcc:
crossgcc_ada="y" # yes by default
# Override the above defaults using target.cfg
. "resources/coreboot/${board}/target.cfg"
if [ "${grub_scan_disk}" = "undefined" ]; then
printf "build/roms: Target '%s' does not define grub_scan_disk. " \
${board}
printf "Defaulting to 'both'.\n"
[ "${grub_scan_disk}" = "undefined" ] && \
grub_scan_disk="both"
fi
if [ "${grub_scan_disk}" != "both" ] && \
[ "${grub_scan_disk}" != "ata" ] && \
[ "${grub_scan_disk}" != "ahci" ]; then
printf "build/roms: Target '%s' defines bad grub_scan_disk option. " \
${board}
printf "Defaulting to 'both'.\n"
[ "${grub_scan_disk}" != "both" ] && [ "${grub_scan_disk}" != "ata" ] && \
[ "${grub_scan_disk}" != "ahci" ] && \
grub_scan_disk="both"
# erroring out would be silly. just use the default
fi
if [ "${tree}" = "undefined" ]; then
printf "build/roms: Target '%s' does not define a coreboot tree. " \
${board}
printf "Skipping build.\n"
exit 1
fi
if [ "${arch}" = "undefined" ]; then
printf "build/roms: Target '%s' does not define a CPU type. " \
${board}
printf "Skipping build.\n"
exit 1
fi
[ "${tree}" = "undefined" ] && \
err "Target '${board}' does not define a coreboot tree. Skipping build."
[ "${arch}" = "undefined" ] && \
err "Target '${board}' does not define a CPU type. Skipping build."
if [ "${seabios_opromloadonly}" != "0" ] && \
[ "${seabios_opromloadonly}" != "1" ]; then
seabios_opromloadonly="0"
fi
if [ "${payload_memtest}" != "n" ] && \
[ "${payload_memtest}" != "y" ]; then
[ "${payload_memtest}" != "n" ] && \
[ "${payload_memtest}" != "y" ] && \
payload_memtest="n"
fi
if [ "${payload_grub_withseabios}" = "y" ]; then
[ "${payload_grub_withseabios}" = "y" ] && \
payload_grub="y"
fi
if [ "${payload_grub_withseabios}" = "y" ]; then
payload_seabios="y"
payload_seabios_withgrub="y"
fi
if [ "${payload_seabios_withgrub}" = "y" ]; then
[ "${payload_seabios_withgrub}" = "y" ] && \
payload_seabios="y"
fi
# NOTE: reverse logic must NOT be applied. If SeaBIOS-with-GRUB works, that
# doesn't necessarily mean GRUb-with-SeaBIOS will. For example, the board
# might have an external GPU, where it's recommended to boot SeaBIOS first
if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] \
&& [ "${payload_uboot}" != "y" ]; then
for configfile in "resources/coreboot/${board}/config/"*; do
if [ ! -e "${configfile}" ]; then
continue
fi
[ ! -e "${configfile}" ] && continue
printf "ERROR build/roms: Target '%s' defines no payload. " \
${board}
printf "Exiting.\n"
@ -153,32 +126,17 @@ if [ "${payload_grub}" != "y" ] && [ "${payload_seabios}" != "y" ] \
done
fi
if [ "${payload_uboot}" != "n" ] && \
[ "${payload_uboot}" != "y" ]; then
[ "${payload_uboot}" != "n" ] && [ "${payload_uboot}" != "y" ] && \
payload_uboot="n"
fi
if [ "${payload_uboot}" = "y" ] && \
[ "${uboot_config}" = "undefined" ]; then
[ "${payload_uboot}" = "y" ] && [ "${uboot_config}" = "undefined" ] && \
uboot_config="default"
fi
if [ "${microcode_required}" != "n" ] \
&& [ "${microcode_required}" != "y" ]; then
[ "${microcode_required}" != "n" ] && [ "${microcode_required}" != "y" ] && \
microcode_required="y"
fi
if [ "${blobs_required}" != "n" ] \
&& [ "${blobs_required}" != "y" ]; then
[ "${blobs_required}" != "n" ] && [ "${blobs_required}" != "y" ] && \
blobs_required="y"
fi
# ada support needed for libgfxinit submodule
if [ "${crossgcc_ada}" != "y" ] && [ "${crossgcc_ada}" != "n" ]; then
crossgcc_ada="y"
fi
# Override all payload directives with cmdline args
# (do not override crossgcc_ada)
if [ ! -z ${payloads} ]; then
echo "setting payloads $payloads"
payload_grub="n"
@ -186,7 +144,6 @@ if [ ! -z ${payloads} ]; then
payload_seabios="n"
payload_seabios_withgrub="n" # i386-coreboot grub from SeaBIOS menu
payload_uboot="n"
seabios_opromloadonly="0"
payload_memtest="n"
for payload in ${payloads} ; do
@ -196,95 +153,42 @@ fi
romdir="bin/${board}"
cbdir="coreboot/${board}"
if [ "${board}" != "${tree}" ]; then
[ "${board}" != "${tree}" ] && \
cbdir="coreboot/${tree}"
fi
cbfstool="cbutils/${tree}/cbfstool"
corebootrom="${cbdir}/build/coreboot.rom"
seavgabiosrom="payload/seabios/seavgabios.bin"
seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
./build module cbutils ${tree} || exit 1
if [ ! -d "${cbdir}" ]; then
./fetch_trees coreboot ${tree}
fi
cat version > "${cbdir}/.coreboot-version"
if [ "${crossgcc_ada}" = "n" ]; then
export BUILD_LANGUAGES=c
fi
if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then
if [ ! -d "${cbdir}/util/crossgcc/xgcc/i386-elf/" ]; then
# Even for 64-bit machines, coreboot builds 32-bit ROM
# images, so we only need to worry about i386-elf
make -C "${cbdir}" crossgcc-i386 CPUS=$(nproc)
fi
case "$(uname -m)" in
x86*|i*86|amd64) : ;;
*) export CROSS_COMPILE=i386-elf- ;;
esac
elif [ "${arch}" = "ARMv7" ]; then
if [ ! -d "${cbdir}/util/crossgcc/xgcc/arm-eabi/" ]; then
make -C "${cbdir}" crossgcc-arm CPUS=$(nproc)
fi
case "$(uname -m)" in
arm|arm32|armv6*|armv7*) : ;;
*) export CROSS_COMPILE=arm-eabi- ;;
esac
elif [ "${arch}" = "AArch64" ]; then
if [ ! -d "${cbdir}/util/crossgcc/xgcc/aarch64-elf/" ]; then
make -C "${cbdir}" crossgcc-aarch64 CPUS=$(nproc)
fi
# aarch64 also needs armv7 toolchain for arm-trusted-firmware
if [ ! -d "${cbdir}/util/crossgcc/xgcc/arm-eabi/" ]; then
make -C "${cbdir}" crossgcc-arm CPUS=$(nproc)
fi
case "$(uname -m)" in
arm64|aarch64) : ;;
*) export CROSS_COMPILE=aarch64-elf- ;;
esac
fi
export PATH="$(pwd)/${cbdir}/util/crossgcc/xgcc/bin:$PATH"
if [ ! -f "${seavgabiosrom}" ] \
|| [ ! -f payload/seabios/seabios_libgfxinit.elf ] \
|| [ ! -f payload/seabios/seabios_vgarom.elf ] \
|| [ ! -f payload/seabios/seabios_normal.elf ]; then
if [ "${payload_seabios}" = "y" ]; then
./build payload seabios
elif [ "${payload_grub}" = "y" ] \
&& [ "${payload_grub_withseabios}" = "y" ]; then
./build payload seabios
fi
|| [ ! -f elf/seabios/default/libgfxinit/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/vgarom/bios.bin.elf ] \
|| [ ! -f elf/seabios/default/normal/bios.bin.elf ]; then
[ "${payload_seabios}" = "y" ] && \
./build defconfig for seabios
fi
if [ "${payload_memtest}" = "y" ]; then
if [ ! -f "memtest86plus/memtest" ]; then
./build module memtest86plus
fi
fi
[ "${payload_memtest}" = "y" ] && [ ! -f "memtest86plus/memtest" ] && \
./build module memtest86plus
[ -d "${romdir}/" ] || mkdir -p "${romdir}/"
rm -f "${romdir}"/*
if [ "${payload_grub}" = "y" ] \
|| [ "${payload_seabios_withgrub}" = "y" ]; then
if [ -f "payload/grub/grub_usqwerty.cfg" ]; then
if [ -f "elf/grub/grub_usqwerty.cfg" ]; then
sha1sumcmd="sha1sum resources/grub/config/grub.cfg"
grubrefchecksum="$(${sha1sumcmd} | awk '{print $1}')"
sha1sumcmd="sha1sum payload/grub/grub_usqwerty.cfg"
sha1sumcmd="sha1sum elf/grub/grub_usqwerty.cfg"
grubbuildchecksum="$(${sha1sumcmd} | awk '{print $1}')"
if [ "${grubrefchecksum}" != "${grubbuildchecksum}" ]; then
rm -Rf payload/grub/
printf "Changes detected to GRUB. Re-building now:\n"
fi
else
printf "Required GRUB payloads not yet built. Building now:\n"
rm -Rf payload/grub/ # just in case
fi
for keymapfile in ${kmapdir}/*; do
@ -295,33 +199,25 @@ if [ "${payload_grub}" = "y" ] \
keymap="${keymapfile##*/}"
keymap="${keymap%.gkb}"
grubelf="payload/grub/grub_${keymap}.elf"
grubcfg="payload/grub/grub_${keymap}.cfg"
grubtestcfg="payload/grub/grub_${keymap}_test.cfg"
grubelf="elf/grub/grub_${keymap}.elf"
grubcfg="elf/grub/grub_${keymap}.cfg"
grubtestcfg="elf/grub/grub_${keymap}_test.cfg"
if [ ! -f "${grubelf}" ] || [ ! -f "${grubcfg}" ] || \
[ ! -f "${grubtestcfg}" ]; then
./build payload grub
[ ! -f "${grubtestcfg}" ]; then
./build payload grub
fi
done
fi
if [ "${payload_uboot}" = "y" ]; then
if [ "${uboot_config}" = "default" ]; then
ubdir="payload/u-boot/${board}"
else
ubdir="payload/u-boot/${board}/${uboot_config}"
fi
if [ -f "${ubdir}/u-boot.elf" ]; then
ubootelf="${ubdir}/u-boot.elf"
elif [ -f "${ubdir}/u-boot" ]; then
ubootelf="${ubdir}/u-boot"
else
printf "Required U-Boot payload not yet built. Building now\n"
rm -Rf "payload/u-boot/${board}" # just in case
./build payload u-boot "${board}"
fi
./build defconfig for u-boot ${board}
ubdir="elf/u-boot/${board}/${uboot_config}"
ubootelf="${ubdir}/u-boot.elf"
[ ! -f "${ubootelf}" ] && [ -f "${ubdir}/u-boot.bin" ] && \
ubootelf="${ubdir}/u-boot.bin"
[ ! -f "${ubootelf}" ] && \
err "Could not find u-boot build for board, ${board}"
fi
# it is assumed that no other work will be done on the ROM
@ -331,9 +227,8 @@ moverom() {
newrompath="$2"
cuttype="$3"
if [ "${blobs_required}" = "n" ]; then
[ "${blobs_required}" = "n" ] && \
newrompath="${newrompath%.rom}_noblobs.rom"
fi
printf "\nCreating new ROM image: %s\n" "${newrompath}"
@ -404,47 +299,14 @@ moverom() {
fi
}
# expected: configs must not specify a payload
mkCoreboot() {
cbdir="${1}" # eg. coreboot/default
cbcfgpath="${2}" # eg. resources/coreboot/e6400nvidia_4mb/config/normal
if [ ! -f "${cbcfgpath}" ]; then
printf "\nmkCoreboot: coreboot config '%s' does not exist. " \
${cbcfgpath}
printf "Skipping build.\n"
return 0
fi
cat version > "${cbdir}/.coreboot-version"
(
if [ -f "${cbfstool}" ]; then
mv "${cbfstool}" "${cbdir}/cbfstool"
fi
cd "${cbdir}"
make distclean
cd -
if [ -f "${cbdir}/cbfstool" ]; then
mv "${cbdir}/cbfstool" "${cbfstool}"
fi
)
cp "${cbcfgpath}" "${cbdir}"/.config
(
cd "${cbdir}"
make -j$(nproc)
)
}
# 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
# (a tmpfile will be made instead)
target_seabios_cbfs_path="${2}" # e.g. fallback/payload
target_opromloadonly="${3}" # TODO: purge (useless setting)
target_initmode="${4}" # e.g. libgfxinit
target_initmode="${3}" # e.g. libgfxinit
target_seabioself="payload/seabios/seabios_${target_initmode}.elf"
target_seavgabios_rom="payload/seabios/seavgabios.bin"
target_seabioself="elf/seabios/default/${target_initmode}/bios.bin.elf"
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
@ -468,11 +330,8 @@ mkSeabiosRom() {
"${cbfstool}" "${tmprom}" add-int -i 0 -n etc/optionroms-checksum \
|| exit 1
"${cbfstool}" "${tmprom}" add-int -i ${target_opromloadonly} \
-n etc/only-load-option-roms || exit 1
if [ "${target_initmode}" = "libgfxinit" ]; then
"${cbfstool}" "${tmprom}" add -f "${target_seavgabios_rom}" \
"${cbfstool}" "${tmprom}" add -f "${seavgabiosrom}" \
-n vgaroms/seavgabios.bin -t raw || exit 1
fi
@ -487,17 +346,12 @@ mkUbootRom() {
target_uboot_config="${3}"
cbfstool_path="${4}"
if [ "${target_uboot_config}" = "default" ]; then
target_ubdir="payload/u-boot/${board}"
else
target_ubdir="payload/u-boot/${board}/${target_uboot_config}"
fi
if [ -f "${target_ubdir}/u-boot.elf" ]; then
target_ubootelf="${target_ubdir}/u-boot.elf"
elif [ -f "${target_ubdir}/u-boot" ]; then
target_ubootelf="${target_ubdir}/u-boot"
fi
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 "Could not find u-boot build for board, ${board}"
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX)
@ -514,9 +368,9 @@ mkGrubRom() {
target_cbrom="${2}"
target_grubelf_cbfs_path="${3}" # e.g. fallback/payload
grubelf="payload/grub/grub_${target_keymap}.elf"
grubcfg="payload/grub/grub_${target_keymap}.cfg"
grubtestcfg="payload/grub/grub_${target_keymap}_test.cfg"
grubelf="elf/grub/grub_${target_keymap}.elf"
grubcfg="elf/grub/grub_${target_keymap}.cfg"
grubtestcfg="elf/grub/grub_${target_keymap}_test.cfg"
tmprom=$(mktemp -t coreboot_rom.XXXXXXXXXX) || exit 1
cp "${target_cbrom}" "${tmprom}" || exit 1
@ -572,15 +426,14 @@ mkRomsWithGrub() {
firstpayloadname="${4}" # allow values: grub, seabios, seabios_withgrub
x=${tmprompath}
y=${seabios_opromloadonly}
z=${initmode}
y=${initmode}
if [ "${payload_grub_withseabios}" = "y" ] \
&& [ "${firstpayloadname}" = "grub" ]; then
mv "$(mkSeabiosRom "${x}" "seabios.elf" "${y}" "${z}")" \
mv "$(mkSeabiosRom "${x}" "seabios.elf" "${y}")" \
"${tmprompath}"
elif [ "${payload_seabios_withgrub}" ] \
&& [ "${firstpayloadname}" != "grub" ]; then
mv "$(mkSeabiosRom "${x}" "fallback/payload" "$y" "$z")" \
mv "$(mkSeabiosRom "${x}" "fallback/payload" "$y")" \
"${tmprompath}"
fi
@ -631,7 +484,8 @@ mkRomsWithGrub() {
}
# Main ROM building function. This calls all other functions
mkRoms() {
mkRoms()
{
cbcfgpath="${1}"
displaymode="${2}"
initmode="${3}"
@ -643,7 +497,13 @@ mkRoms() {
return 0
fi
mkCoreboot "${cbdir}" "${cbcfgpath}"
./build defconfig for coreboot ${board}
_corebootrom="elf/coreboot/${board}/${initmode}_${displaymode}"
[ "${initmode}" = "normal" ] && \
_corebootrom="${_corebootrom%_${displaymode}}"
_corebootrom="${_corebootrom}/coreboot.rom"
corebootrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
cp "${_corebootrom}" "${corebootrom}"
if [ "${displaymode}" = "txtmode" ] \
&& [ "${payload_memtest}" = "y" ]; then
@ -655,9 +515,8 @@ mkRoms() {
if [ "${payload_seabios}" = "y" ]; then
if [ "${payload_seabios_withgrub}" = "n" ]; then
x=${corebootrom}
y=${seabios_opromloadonly}
z=${initmode}
t=$(mkSeabiosRom "$x" "fallback/payload" "$y" "$z")
y=${initmode}
t=$(mkSeabiosRom "$x" "fallback/payload" "$y")
if [ "${initmode}" = "normal" ]; then
newrompath="${romdir}/seabios_${board}_"
newrompath="${newrompath}${initmode}.rom"
@ -736,8 +595,3 @@ else
mkRoms "${cbcfgpath}" "${displaymode}" "${initmode}"
done
fi
(
cd "${cbdir}"
make distclean
)

View File

@ -1,30 +0,0 @@
#!/usr/bin/env sh
# helper script: nothing to see here, forks!
#
# Copyright (C) 2020, 2021 Leah Rowe <info@minifree.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
# clean bucts
# --------------------------------------------------------
printf "Cleaning up payloads\n"
rm -Rf payload/

View File

@ -24,14 +24,13 @@ set -u -e
# clean bucts
# --------------------------------------------------------
printf "Cleaning the previous build of seabios\n"
rm -f seabios_libgfxinit.elf seavgabios.bin seabios_vgarom.elf
printf "Cleaning the previous builds of seabios\n"
rm -Rf elf/seabios || exit 1
[ ! -d "seabios/" ] && exit 0
(
cd "seabios/"
make distclean
)
for x in seabios/*; do
[ "${x}" = "seabios/seabios" ] && continue
[ ! -d "${x}" ] && continue
make -C "${x}" distclean || exit 1
done

View File

@ -0,0 +1,240 @@
#!/usr/bin/env sh
# helper script: build elf files on build systems that use defconfig/kconfig
#
# Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# Copyright (C) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (C) 2023 Leah Rowe <leah@libreboot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# you could probably build *linux* with this script!
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
projectname="$(cat projectname)"
our_version="$(cat version)"
export LOCALVERSION="-${projectname}-${our_version}"
arch=""
cfgsdir=""
codedir=""
config=""
config_name=""
crossgcc_ada=""
elfdir=""
listfile=""
project=""
target=""
target_dir=""
tree=""
main()
{
[ $# -lt 1 ] && err "Project name not specified"
project="${1}"
elfdir="elf/${project}"
shift 1
cfgsdir="resources/${project}"
[ -d "${cfgsdir}" ] || err "directory, ${cfgsdir}, does not exist"
listfile="${cfgsdir}/build.list"
[ -f "${listfile}" ] || err "list file, ${listfile}, does not exist"
printf "Building %s binaries (elf files)\n" ${project}
# Build for all targets if no argument is given
if [ "$#" -eq 0 ]; then
for target_dir in "${cfgsdir}"/*; do
[ ! -d "${target_dir}/config/" ] && \
continue
set -- "$@" "${target_dir#${cfgsdir}/}"
done
fi
[ ! -d "${elfdir}" ] && \
mkdir -p ${elfdir}/
for x in "$@"; do
target="${x}"
if [ "${project}" = "coreboot" ]; then
./update blobs download ${target} || err "blobutil"
fi
build_defconfig || exit 1
done
printf "Done! The files are stored under %s/\n\n" ${elfdir}
}
build_defconfig()
{
handle_dependencies "${target}" || return 1
for y in "${target_dir}/config"/*; do
[ ! -f "${y}" ] && continue
config="${y}"
config_name="${config#$target_dir/config/}"
printf "build/defconfig/%s %s: build config %s\n" \
${project} ${target} ${config_name}
check_config || continue
build_elf
copy_elf
done
}
handle_dependencies()
{
target_dir="${cfgsdir}/${target}"
mkdir -p "${elfdir}/${target}"
tree="undefined"
arch="undefined"
[ ! -f "${target_dir}/target.cfg" ] && \
err "build/${project} ${target}: Missing target.cfg"
# Override the above defaults using target.cfg
. "${target_dir}/target.cfg" # source
[ "${tree}" = "undefined" ] && \
err "build/${project} %{target}: tree undefined"
[ "${arch}" = "undefined" ] && \
err "build/${project} ${target}: undefined cpu type"
codedir="${project}/${tree}"
[ -d "${codedir}" ] || \
./fetch_trees "${project}" "$target" || exit 1
# u-boot and coreboot are both compiled with coreboot's crossgcc
if [ "${project}" = "coreboot" ] || [ "${project}" = "u-boot" ]; then
check_cross_compiler || err "crossgcc fail"
fi
}
# set up cross-compiler (coreboot crossgcc) for u-boot and coreboot
# (seabios and grub currently use hostcc, not crossgcc)
check_cross_compiler()
{
[ "${crossgcc_ada}" = "y" ] || [ "${crossgcc_ada}" = "n" ] || \
crossgcc_ada="y"
[ "${crossgcc_ada}" != "y" ] && \
export BUILD_LANGUAGES=c
cbdir="coreboot/${tree}"
[ "${project}" != "coreboot" ] && \
cbdir="coreboot/default" # not u-boot (e.g. linux will use it)
[ "${project}" = "u-boot" ] && \
cbdir="coreboot/cros" # u-boot only used on coreboot/cros
# only true if not building coreboot:
[ -d "${cbdir}" ] || \
./fetch_trees coreboot ${cbdir#coreboot/} || \
err "check_cross_compiler"
if [ "${arch}" = "x86_32" ] || [ "${arch}" = "x86_64" ]; then
if [ ! -d "${cbdir}/util/crossgcc/xgcc/i386-elf/" ]; then
# Even for 64-bit machines, coreboot builds 32-bit ROM
# images, so we only need to worry about i386-elf
make -C "${cbdir}" crossgcc-i386 CPUS=$(nproc) || \
return 1
fi
case "$(uname -m)" in
x86*|i*86|amd64) : ;;
*) export CROSS_COMPILE=i386-elf- ;;
esac
elif [ "${arch}" = "ARMv7" ]; then
if [ ! -d "${cbdir}/util/crossgcc/xgcc/arm-eabi/" ]; then
make -C "${cbdir}" crossgcc-arm CPUS=$(nproc) || \
return 1
fi
case "$(uname -m)" in
arm|arm32|armv6*|armv7*) : ;;
*) export CROSS_COMPILE=arm-eabi- ;;
esac
elif [ "${arch}" = "AArch64" ]; then
if [ ! -d "${cbdir}/util/crossgcc/xgcc/aarch64-elf/" ]; then
make -C "${cbdir}" crossgcc-aarch64 CPUS=$(nproc) || \
return 1
fi
# aarch64 also needs armv7 toolchain for arm-trusted-firmware
if [ ! -d "${cbdir}/util/crossgcc/xgcc/arm-eabi/" ]; then
make -C "${cbdir}" crossgcc-arm CPUS=$(nproc) || \
return 1
fi
case "$(uname -m)" in
arm64|aarch64) : ;;
*) export CROSS_COMPILE=aarch64-elf- ;;
esac
fi
# we *must* ensure that u-boot's build system uses crossgcc first
export PATH="$(pwd)/${cbdir}/util/crossgcc/xgcc/bin:$PATH"
}
check_config()
{
[ ! -f "${config}" ] && \
err "build/${project} ${target}: configs missing"
dest_dir="${elfdir}/${target}/${config_name}"
for elftest in "${dest_dir}"/*; do
if [ -f "${elftest}" ]; then
printf "Build already exists, so skipping build\n" 1>&2
return 1
fi
done
mkdir -p "${dest_dir}"
printf "build/%s %s: building config %s).\n" \
${project} ${target} ${config_name}
}
build_elf()
{
make -C "${codedir}" distclean || err "build_elf"
cp "${config}" "${codedir}/.config" || err "build_elf"
make -C "${codedir}" silentoldconfig || \
make -C "${codedir}" oldconfig || : # don't error on oldconfig
[ "${project}" = "coreboot" ] && \
printf "%s\n" "${our_version}" > "${codedir}/.coreboot-version"
make -C "${codedir}" -j"$(nproc)" all || err "build_elf"
}
copy_elf()
{
for f in $(cat "${listfile}"); do
[ -f "${codedir}/$f" ] && cp "${codedir}/${f}" "${dest_dir}/"
done
make -C "${codedir}" distclean || \
make -C "${codedir}" clean || err "copy_elf"
}
err()
{
[ -z "${codedir}" ] || \
make -C "${codedir}" distclean \
|| make -C "${codedir}" clean || :
printf "build/defconfig error %s\n" "${1}" 1>&2
exit 1
}
main $@

View File

@ -34,12 +34,12 @@ main()
./fetch grub
[ ! -f "grub/grub-mkstandalone" ] && \
./build module grub
[ ! -d "payload/" ] && \
mkdir -p payload/
[ ! -d "payload/grub" ] && \
mkdir -p payload/grub/
[ ! -d "elf/" ] && \
mkdir -p elf/
[ ! -d "elf/grub" ] && \
mkdir -p elf/grub/
rm -f payload/grub/*
rm -f elf/grub/*
# Separate GRUB payload per keymap to save space in ROM.
@ -47,7 +47,7 @@ main()
build_grub_payloads "${keylayoutfile}"
done
printf "Done! Check payload/grub/ to see the files.\n\n"
printf "Done! Check elf/grub/ to see the files.\n\n"
}
build_grub_payloads()
@ -63,7 +63,7 @@ build_grub_payloads()
build_grub_elf "${keylayoutfile}"
create_grub_config
printf "Created 'payload/grub/grub_%s.elf' and configs.'\n" \
printf "Created 'elf/grub/grub_%s.elf' and configs.'\n" \
"${keymap}"
}
@ -77,7 +77,7 @@ build_grub_elf()
grub/grub-mkstandalone \
--grub-mkimage="grub/grub-mkimage" \
-O i386-coreboot \
-o payload/grub/grub_${keymap}.elf \
-o elf/grub/grub_${keymap}.elf \
-d grub/grub-core/ \
--fonts= --themes= --locales= \
--modules="${grub_modules}" \
@ -89,10 +89,10 @@ create_grub_config()
{
sed "s/usqwerty/${keymap}/" \
< ${grubcfgsdir}/config/grub.cfg \
> payload/grub/grub_${keymap}.cfg
> elf/grub/grub_${keymap}.cfg
sed "s/grubtest.cfg/grub.cfg/" \
< payload/grub/grub_${keymap}.cfg \
> payload/grub/grub_${keymap}_test.cfg
< elf/grub/grub_${keymap}.cfg \
> elf/grub/grub_${keymap}_test.cfg
}
main $@

View File

@ -1,84 +0,0 @@
#!/usr/bin/env sh
# helper script: builds SeaBIOS source code
#
# Copyright (C) 2020, 2021, 2023 Leah Rowe <info@minifree.org>
# Copyright (C) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
payloaddir="payload/seabios"
seabios_elf="seabios/out/bios.bin.elf"
seavgabios="seabios/out/vgabios.bin"
main()
{
printf "Building SeaBIOS payloads and SeaVGABIOS\n"
check_dependencies
for x in normal vgarom libgfxinit; do
build_seabios_elf "${x}"
done
# clean it again. gotta keep it clean!
if [ -f seabios/Makefile ]; then
make distclean -BC seabios || exit 1
fi
printf "Done! SeaBIOS files are in %s/\n\n" ${payloaddir}
}
check_dependencies()
{
if [ ! -d "${payloaddir}" ]; then
mkdir -p ${payloaddir}/ || exit 1
fi
rm -f ${payloaddir}/* || exit 1
if [ ! -d "seabios/" ]; then
./fetch seabios || exit 1
fi
}
build_seabios_elf()
{
inittype=${1}
if [ ! -f seabios/Makefile ]; then
printf "SeaBIOS not properly downloaded.\n"
exit 1
fi
make distclean -BC seabios || exit 1
cp "resources/seabios/config/${inittype}" seabios/.config
make silentoldconfig -j$(nproc) -BC seabios || exit 1
make -j$(nproc) -BC seabios || exit 1
seabios_elf_dst="${payloaddir}/seabios_${inittype}.elf"
cp ${seabios_elf} "${seabios_elf_dst}" || exit 1
if [ "${inittype}" = "libgfxinit" ]; then
cp ${seavgabios} ${payloaddir}/seavgabios.bin || exit 1
fi
rm -f seabios/.config || exit 1
}
main $@

View File

@ -1,179 +0,0 @@
#!/usr/bin/env sh
# helper script: builds U-Boot source code
#
# Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# Copyright (C) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (C) 2023 Leah Rowe <leah@libreboot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
RET=0
pdir="payload/u-boot"
ubdir=""
arch=""
tree=""
config_name=""
board_dir=""
our_version="$(cat version)"
projectname="$(cat projectname)"
export LOCALVERSION="-${projectname}-${our_version}"
main()
{
printf "Building U-Boot payloads\n"
# Build for all boards if no argument is given
if [ "$#" -eq 0 ]; then
for board_dir in resources/u-boot/*; do
[ ! -d "${board_dir}/config/" ] && \
continue
set -- "$@" "${board_dir#resources/u-boot/}"
done
fi
[ ! -d "payload/" ] && \
mkdir -p payload/
[ ! -d "${pdir}" ] && \
mkdir -p ${pdir}/
for board in "$@"; do
build_uboot_payloads "${board}" || continue
done
printf "Done! U-Boot files are in %s/\n\n" ${pdir}
exit $RET
}
build_uboot_payloads()
{
board=${1}
handle_dependencies "${board}" || return 1
for config in "${board_dir}/config"/*; do
config_name="${config#$board_dir/config/}"
check_config "${board}" "${config}" || continue
build_uboot_elf "${config}"
printf "build/u-boot %s: build config %s\n" \
"${board}" "${config_name}"
done
}
handle_dependencies()
{
board=${1}
board_dir="resources/u-boot/${board}"
rm -rf "${pdir}/${board}"
mkdir -p "${pdir}/${board}"
tree="undefined"
arch="undefined"
if [ ! -f "${board_dir}/target.cfg" ]; then
printf "build/u-boot %s: Missing target.cfg.\n" \
"${board}"
RET=1
return 1
fi
# Override the above defaults using target.cfg
. "${board_dir}/target.cfg" # source
if [ "${tree}" = "undefined" ]; then
printf "build/u-boot %s: tree undefined\n" \
"${board}"
RET=1
return 1
fi
if [ "${arch}" = "undefined" ]; then
printf "build/u-boot %s: undefined cpu type\n" \
"${board}"
RET=1
return 1
fi
ubdir="u-boot/${board}"
if [ "${board}" != "${tree}" ]; then
ubdir="u-boot/${tree}"
fi
if [ ! -d "${ubdir}" ]; then
./fetch_trees u-boot "$board"
fi
if [ ! -d "${ubdir}" ]; then
printf "build/u-boot %s: uboot download failed\n" \
"${board}"
RET=1
return 1
fi
}
check_config()
{
board=${1}
config=${2}
if [ ! -f "${config}" ]; then
printf "build/u-boot %s: configs missing\n" \
${board}
RET=1
return 1
fi
if [ "$config_name" = "default" ]; then
dest_dir="${pdir}/${board}"
else
dest_dir="${pdir}/${board}/${config_name}"
fi
mkdir -p "${dest_dir}"
printf "build/u-boot %s: building config %s).\n" \
${board} ${config_name}
}
build_uboot_elf()
{
config=${1}
make -C "${ubdir}" distclean
cp "${config}" "${ubdir}/.config"
make -C "${ubdir}" olddefconfig
make -C "${ubdir}" -j"$(nproc)" all
for f in "${ubdir}"/u-boot "${ubdir}"/u-boot.bin \
"${ubdir}"/u-boot.dtb \
"${ubdir}"/u-boot.img \
"${ubdir}"/u-boot.itb \
"${ubdir}"/u-boot.elf
do
if [ -f "$f" ]; then
mv "$f" "${dest_dir}/"
fi
done
make -C "${ubdir}" distclean
}
main $@

View File

@ -30,7 +30,7 @@ main()
download_seabios()
{
if [ ! -d "seabios" ]; then
./fetch seabios
./fetch_trees seabios
fi
if [ ! -d "seabios" ]; then
printf "error: Failed to download SeaBIOS. "

View File

@ -28,7 +28,7 @@ set -u -e
printf "Updating seabios configs\n"
if [ ! -d "seabios" ]; then
./fetch seabios
./fetch_trees seabios
fi
if [ ! -d "seabios" ]; then

View File

@ -0,0 +1,2 @@
out/bios.bin.elf
out/vgabios.bin

View File

@ -0,0 +1,3 @@
arch="x86_32"
tree="default"
rev="1281e340ad1d90c0cc8e8d902bb34f1871eb48cf"

View File

@ -0,0 +1,5 @@
u-boot.bin
u-boot.dtb
u-boot.img
u-boot.itb
u-boot.elf