rom.sh: new file, to replace script/roms

stub it from the trees script. the way it works now,
there is less code in the build system.

./build roms

this is no longer a thing

./build roms serprog

this is also no longer a thing. instead, do:

./update trees -b coreboot targetnamehere

./update trees -b pico-serprog

./update trees -b stm32-vserprog

the old commands still works, which causes the new
commands to run

coreboot roms now appear in elf/, not bin/, as before,
but those images now contain payloads.

NOTE: to contradict the above: ./build roms is no
longer a thing, in that it's now deprecated, but
backward compatibility is present for now. it will
be removed in a future release.

./build roms list also still works! it will do:
./update trees -b coreboot list

also:
./update trees -b grub list
this is now possible too

if a target "list" is provided, for multi-tree sources,
the targets are shown.

there is another difference: seagrub roms are now seagrub_,
instead of seabios_withgrub.

seabios-only roms are no longer provided, where grub is also
enabled; only seagrub is used. the user can easily remove
the bootorder file, if they want seabios to not try grub first.

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2
Leah Rowe 2024-07-06 23:36:13 +01:00 committed by Leah Rowe
parent a50c789b1d
commit e01995d491
9 changed files with 165 additions and 219 deletions

14
build
View File

@ -14,7 +14,7 @@ fi
. "include/lib.sh"
eval `setvars "" vdir src_dirname srcdir mode xp`
eval `setvars "" vdir src_dirname srcdir mode xp ser`
err="fail"
main()
@ -30,6 +30,12 @@ main()
case "${1}" in
version) printf "%s\nWebsite: %s\n" "$relname" "$projectsite" ;;
release) shift 1; mkrelease $@ ;;
roms)
if [ $# -gt 1 ] && [ "$2" = "serprog" ]; then
x_ ./update trees -b stm32-vserprog
x_ ./update trees -b pico-serprog; return 0
fi; shift 1
x_ ./update trees -b coreboot $@ ;;
*)
[ -f "$spath" ] || $err "bad command"
shift 1; "$spath" $@ || $err "excmd: $spath $@" ;;
@ -106,9 +112,9 @@ build_release()
(
cd "$srcdir" || $err "$vdir: 2 !cd \"$srcdir\""
./build roms all || $err "$vdir: roms-all"
./build roms serprog rp2040 || $err "$vdir: rp2040"
./build roms serprog stm32 || $err "$vdir: stm32"
./update trees -b coreboot || $err "$vdir: roms-all"
./update trees -b pico-serprog || $err "$vdir: rp2040"
./update trees -b stm32-vserprog || $err "$vdir: stm32"
x_ mv bin ../roms
) || $err "can't build rom images"

View File

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

View File

@ -1,2 +1,13 @@
makeargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
build_depend="seabios/default grub/default memtest86plus"
seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
pv="payload_uboot payload_seabios payload_memtest payload_grub"
v="initmode ubootelf grub_scan_disk uboot_config grubtree grubelf pname"
v="$v displaymode tmprom"
eval `setvars "n" $pv`
eval `setvars "" $v`
mkhelper="mkcorebootbin"
postmake="mkcoreboottar"

View File

@ -0,0 +1,5 @@
sersrc="src/pico-serprog"
serx="$sersrc/build/pico_serprog.uf2"
picosdk="src/pico-sdk"
serdir="$picosdk/src/boards/include/boards"
premake="mkserprog rp2040"

View File

@ -0,0 +1,4 @@
sersrc="src/stm32-vserprog"
serx="$sersrc/stm32-vserprog.hex"
serdir="$sersrc/boards"
mkhelper="mkserprog stm32"

View File

@ -10,7 +10,6 @@ _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
kbnotice="Insert a .gkb file from config/data/grub/keymap/ as keymap.gkb \
if you want a custom keymap in GRUB; use cbfstool from elf/cbfstool."
cbelfdir="elf/.coreboot_nopayload_DO_NOT_FLASH"
ifdtool="elf/ifdtool/default/ifdtool"
cbfstool="elf/cbfstool/default/cbfstool"
tmpgit="$PWD/tmp/gitclone"

118
include/rom.sh Normal file
View File

@ -0,0 +1,118 @@
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2014-2016,2020-2021,2023-2024 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2021-2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# Copyright (c) 2022-2023 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com>
mkserprog()
{
basename -as .h "$serdir/"*.h > "$TMPDIR/ser" || $err "!mk $1 $TMPDIR"
while read -r sertarget; do
[ "$1" = "rp2040" ] && x_ cmake -DPICO_BOARD="$sertarget" \
-DPICO_SDK_PATH="$picosdk" -B "$sersrc/build" "$sersrc" \
&& x_ cmake --build "$sersrc/build"
[ "$1" = "stm32" ] && x_ make -C "$sersrc" \
libopencm3-just-make BOARD=$sertarget && x_ make -C \
"$sersrc" BOARD=$sertarget; x_ mkdir -p "bin/serprog_$1"
x_ mv "$serx" "bin/serprog_$1/serprog_$sertarget.${serx##*.}"
done < "$TMPDIR/ser"
[ "$XBMK_RELEASE" = "y" ] && mkrom_tarball "bin/serprog_$1"; return 0
}
mkpayload_grub()
{
eval `setvars "" grub_modules grub_install_modules`
eval `setcfg "$grubdata/module/$tree"`
x_ rm -f "$cdir/grub.elf"
"${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \
--fonts= --themes= --locales= --modules="$grub_modules" \
--install-modules="$grub_install_modules" \
"/boot/grub/grub_default.cfg=${cdir}/.config" \
"/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
"/background.png=$grubdata/background/background1280x800.png" || \
$err "$tree: cannot build grub.elf"; return 0
}
mkcorebootbin()
{
[ "$target" = "$tree" ] && return 0
tmprom="$cdir/build/coreboot.rom"
initmode="${defconfig##*/}"; displaymode="${initmode##*_}"
initmode="${initmode%%_*}"
[ -n "$displaymode" ] && displaymode="_$displaymode"
cbfstool="elf/cbfstool/$tree/cbfstool"
[ -n "$uboot_config" ] || uboot_config="default"
[ "$payload_uboot" = "y" ] || payload_seabios="y"
[ "$payload_grub" = "y" ] && payload_seabios="y"
[ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
$err "$target: U-Boot and SeaBIOS/GRUB are both enabled."
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
[ -n "$grubtree" ] || grubtree="default"
grubelf="elf/grub/$grubtree/payload/grub.elf"
[ "$payload_memtest" = "y" ] || payload_memtest="n"
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
x_ ./update trees -b coreboot utils $tree
[ "$payload_seabios" = "y" ] && pname="seabios" && add_seabios
[ "$payload_uboot" = "y" ] && pname="uboot" && add_uboot
newrom="bin/$target/${pname}_${target}_$initmode$displaymode.rom"
x_ mkdir -p "${newrom%/*}"; x_ mv "$tmprom" "$newrom"
}
add_seabios()
{
_seabioself="elf/seabios/default/$initmode/bios.bin.elf"
cbfs "$tmprom" "$_seabioself" "fallback/payload"
x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
_z="2"; [ "$initmode" = "vgarom" ] && _z="0"
x_ "$cbfstool" "$tmprom" add-int -i $_z -n etc/pci-optionrom-exec
x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
[ "$initmode" = "libgfxinit" ] && \
cbfs "$tmprom" "$seavgabiosrom" vgaroms/seavgabios.bin raw
[ "$payload_memtest" = "y" ] && cbfs "$tmprom" \
"elf/memtest86plus/memtest.bin" img/memtest
[ "$payload_grub" = "y" ] && pname="seagrub" && add_grub; return 0
}
add_grub()
{
cbfs "$tmprom" "$grubelf" "img/grub2"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$TMPDIR/tmpcfg" || $err "$target: !insert scandisk"
cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
}
add_uboot()
{
ubdir="elf/u-boot/$target/$uboot_config"
ubootelf="$ubdir/u-boot.elf" && [ ! -f "$ubootelf" ] && \
ubootelf="$ubdir/u-boot"
[ -f "$ubootelf" ] || $err "cb/$target: Can't find u-boot"
cbfs "$tmprom" "$ubootelf" "fallback/payload"
}
mkcoreboottar()
{
[ "$target" = "$tree" ] && return 0
[ "$XBMK_RELEASE" = "y" ] && mkrom_tarball "bin/$target"; return 0
}

View File

@ -1,188 +0,0 @@
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2014-2016,2020-2021,2023-2024 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2021-2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# Copyright (c) 2022-2023 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com>
set -u -e
. "include/lib.sh"
tmprom="$TMPDIR/rom"
seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
cfgsdir="config/coreboot"
rp2040src="src/pico-serprog"
rp2040x="$rp2040src/build/pico_serprog.uf2"
picosdk="src/pico-sdk"
rp2040dir="$picosdk/src/boards/include/boards"
stm32src="src/stm32-vserprog"
stm32x="$stm32src/stm32-vserprog.hex"
stm32dir="$stm32src/boards"
# Disable all payloads by default.
# target.cfg files have to specifically enable [a] payload(s)
pv="payload_uboot payload_seabios payload_memtest payload_grub"
v="romdir initmode displaymode targetdir tree release ubootelf"
v="$v board grub_scan_disk uboot_config grubtree grubelf tmpmv"
eval `setvars "n" $pv`
eval `setvars "" $v boards targets serdir ser`
main()
{
while [ $# -gt 0 ]; do
if [ "$1" = "serprog" ]; then
[ $# -lt 2 ] && $err "serprog type not set"
[ "$2" != "rp2040" ] && [ "$2" != "stm32" ] && \
$err "invalid serprog type"
eval "x_ ./update trees -f \"\${${2}src##*/}\""
ser="$2" && shift 2 && continue
fi
[ "$1$ser" = "list" ] && x_ ls -1 config/coreboot && return 0
[ "$1" = "all" ] && shift 1 && continue
boards="$1 $boards"; shift 1
done
[ -n "$boards" ] || [ -n "$ser" ] || boards="$(ls -1 \
config/coreboot)" || $err "can't list coreboot boards"
[ -n "$ser" ] && \
eval "serlist \"\$${ser}dir\" > \"\$TMPDIR/ser\" || $err \"!ser\""
[ -n "$ser" ] && [ -z "$boards" ] && boards="$(cat "$TMPDIR/ser")"
for x in $boards; do
[ -n "$ser" ] && mkserprogfw "$ser" "$x"
[ -z "$ser" ] && [ -d "config/coreboot/$x/config" ] && \
configure_target "$x" && build_roms && \
[ -d "bin/$board" ] && targets="$targets, $x" && \
[ "$XBMK_RELEASE" = "y" ] && mkrom_tarball "bin/$x"
done
[ -n "$ser" ] && [ "$XBMK_RELEASE" = "y" ] && \
mkrom_tarball "bin/serprog_$ser" && return 0
[ -z "$ser" ] && [ -z "$targets" ] && $err "No images were compiled"
[ -z "$ser" ] && printf "ROMs built in bin/ for: %s\n" "${targets#, }"
[ -n "$ser" ] && printf "ROMs (serprog) built in bin/%s/\n" "$ser"
printf "Please flash from bin/, NOT elf/ - ALSO:\n%s\n" "$kbnotice"
}
mkserprogfw()
{
x_ mkdir -p "bin/serprog_$1"
[ "$1" = "rp2040" ] && x_ cmake -DPICO_BOARD="$2" \
-DPICO_SDK_PATH="$picosdk" -B "$rp2040src/build" "$rp2040src" && \
x_ cmake --build "$rp2040src/build"
[ "$1" = "stm32" ] && x_ make -C "$stm32src" libopencm3-just-make \
BOARD=$2 && x_ make -C "$stm32src" BOARD=$2
eval "x_ mv \"\$${1}x\" \"bin/serprog_$1/serprog_$2.\${${1}x##*.}\""
}
serlist()
{
basename -a -s .h "$1/"*.h || $err "$1: can't list boards"
}
configure_target()
{
eval `setvars "n" $pv`
eval `setvars "" $v`
board="$1"; targetdir="$cfgsdir/$board"; romdir="bin/$board"
# Override the above defaults using target.cfg
eval `setcfg "$targetdir/target.cfg"`
[ -z "$tree" ] && $err "$board: tree not defined"
[ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && return 1
[ "$board" = "$tree" ] && return 1
x_ ./update trees -b coreboot $board
cbfstool="elf/cbfstool/$tree/cbfstool"
x_ ./update trees -b coreboot utils $tree
[ -n "$uboot_config" ] || uboot_config="default"
[ "$payload_uboot" = "y" ] || payload_seabios="y"
[ "$payload_grub" = "y" ] && payload_seabios="y"
[ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
$err "$board: U-Boot and SeaBIOS/GRUB are both enabled."
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
[ -n "$grubtree" ] || grubtree="default"
grubelf="elf/grub/$grubtree/payload/grub.elf"
[ "$payload_memtest" = "y" ] || payload_memtest="n"
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n"; return 0
}
build_roms()
{
x_ rm -Rf "$romdir"
for cbcfg in "$targetdir/config/"*; do
[ -f "$cbcfg" ] || continue; cn="${cbcfg##*/}"; dt="${cn#*_}" \
&& [ "$dt" = "$cn" ] && dt="txtmode"; displaymode="$dt"
initmode="${cn%%_*}"; chkvars initmode displaymode
e "$cbcfg" f not || add_payloads
done; x_ rm -f "$tmprom"
}
add_payloads()
{
cbuild="$cbelfdir/$board/${initmode}_$displaymode"
[ "$initmode" = "normal" ] && cbuild="${cbuild%"_$displaymode"}"
x_ cp "$cbuild/coreboot.rom" "$tmprom"
[ "$payload_seabios" = "y" ] && add_seabios_payload
[ "$payload_uboot" = "y" ] || return 0
ubdir="elf/u-boot/$board/$uboot_config"; ubootelf="$ubdir/u-boot.elf" \
&& [ ! -f "$ubootelf" ] && ubootelf="$ubdir/u-boot"
[ -f "$ubootelf" ] || $err "$board: Can't find u-boot"
cbfs "$tmprom" "$ubootelf" "fallback/payload"
cprom "$romdir/uboot_payload_${board}_${initmode}_$displaymode.rom"
}
add_seabios_payload()
{
_seabioself="elf/seabios/default/$initmode/bios.bin.elf"
pstr="seabios" && [ "$payload_grub" = "y" ] && pstr="seabios_withgrub"
newrom="$romdir/${pstr}_${board}_$initmode.rom"
[ "$initmode" = "normal" ] || newrom="${newrom%.rom}_$displaymode.rom"
cbfs "$tmprom" "$_seabioself" "fallback/payload"
x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
z="2"; [ "$initmode" = "vgarom" ] && z="0"
x_ "$cbfstool" "$tmprom" add-int -i $z -n etc/pci-optionrom-exec
x_ "$cbfstool" "$tmprom" add-int -i 0 -n etc/optionroms-checksum
[ "$initmode" = "libgfxinit" ] && cbfs "$tmprom" "$seavgabiosrom" \
vgaroms/seavgabios.bin raw
if [ "$payload_grub" = "y" ]; then
cbfs "$tmprom" "$grubelf" "img/grub2"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" \
> "$TMPDIR/tmpcfg" || $err "$board: !insert scandisk"
cbfs "$tmprom" "$TMPDIR/tmpcfg" scan.cfg raw
fi
[ "$payload_memtest" = "y" ] && \
cbfs "$tmprom" "elf/memtest86plus/memtest.bin" img/memtest
cprom "$newrom" && [ "$payload_grub" = "y" ] && \
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw && \
cprom "${newrom%.rom}_grubfirst.rom"; return 0
}
cprom()
{
x_ mkdir -p "${1%/*}"; x_ cp "$tmprom" "$1"
}
main $@

View File

@ -8,10 +8,15 @@ set -u -e
. "include/lib.sh"
. "include/git.sh"
. "include/rom.sh"
. "config/data/pico-serprog/mkhelper.cfg"
. "config/data/coreboot/mkhelper.cfg"
eval `setvars "" xarch cdir defconfig cmakedir xlang mode makeargs elfdir cmd \
project target target_dir targets xtree _f target1 bootstrapargs mkhelper \
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend`
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \
premake release postmake`
main()
{
@ -46,6 +51,7 @@ main()
datadir="config/data/$project"
cfgsdir="config/$project"
listfile="$datadir/build.list" # needed on multi, optional on single
[ -f "$listfile" ] || listfile="" # optional on all projects
remkdir "${tmpgit%/*}"
@ -61,7 +67,6 @@ main()
build_project()
{
configure_project "$cfgsdir" || return 0
[ -f "$listfile" ] || listfile="" # optional on single-tree
dest_dir="$elfdir"
[ ! -f "$listfile" ] || elfcheck || return 0
@ -77,10 +82,7 @@ build_project()
build_targets()
{
[ "$elfdir" = "elf/coreboot" ] && elfdir="$cbelfdir"
[ -d "$cfgsdir" ] || $err "directory, $cfgsdir, does not exist"
[ -f "$listfile" ] || $err "list file, $listfile, does not exist"
# Build for all targets if no argument is given
[ $# -gt 0 ] && target1="$1"
@ -94,10 +96,14 @@ build_targets()
handle_targets()
{
for x in $targets; do
[ "$x" = "list" ] && x_ ls -1 "config/$project" && \
listfile="" && break
target="$x"
printf "'make %s', '%s', '%s'\n" "$mode" "$project" "$target"
x_ handle_defconfig
done
[ -n "$mode" ] || [ -z "$postmake" ] || $postmake || \
$err "$project/$target: !postmake: $postmake"; continue
done; return 0
}
handle_defconfig()
@ -139,8 +145,8 @@ handle_src_tree()
configure_project()
{
eval `setvars "" xarch xlang bootstrapargs autoconfargs xtree \
tree_depend makeargs btype mkhelper build_depend`
eval `setvars "" xarch xlang build_depend autoconfargs xtree postmake \
tree_depend makeargs btype mkhelper bootstrapargs premake release`
[ -f "$1/target.cfg" ] || btype="auto"
[ -f "$datadir/mkhelper.cfg" ] && eval `setcfg "$datadir/mkhelper.cfg"`
@ -157,6 +163,7 @@ configure_project()
&& break; _tcfg="${_tcfg%/*/target.cfg}/$tree/target.cfg"
done
[ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && return 1
[ -z "$btype" ] || [ "${mode%config}" = "$mode" ] || return 1
[ -z "$mode" ] && for bd in $build_depend; do
@ -242,6 +249,8 @@ handle_makefile()
run_make_command()
{
[ -z "$premake" ] || [ -n "$mode" ] || $premake || $err "!$premake"
check_cmake "$cdir" && [ -z "$mode" ] && check_autoconf "$cdir"
check_makefile "$cdir" || return 1
@ -278,23 +287,6 @@ check_makefile()
[ -f "$1/GNUmakefile" ] || return 1; return 0
}
mkpayload_grub()
{
eval `setvars "" grub_modules grub_install_modules`
eval `setcfg "$grubdata/module/$tree"`
x_ rm -f "$cdir/grub.elf"
"${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \
--fonts= --themes= --locales= --modules="$grub_modules" \
--install-modules="$grub_install_modules" \
"/boot/grub/grub_default.cfg=${cdir}/.config" \
"/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \
"/background.png=$grubdata/background/background1280x800.png" || \
$err "$tree: cannot build grub.elf"; return 0
}
copy_elf()
{
[ -f "$listfile" ] && x_ mkdir -p "$dest_dir" && while read -r f; do