2023-06-13 11:09:01 +00:00
|
|
|
#!/usr/bin/env sh
|
2023-09-25 01:19:30 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2024-05-26 00:54:36 +00:00
|
|
|
# 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>
|
2021-05-18 12:56:12 +00:00
|
|
|
|
|
|
|
set -u -e
|
|
|
|
|
2024-05-26 11:10:27 +00:00
|
|
|
. "include/lib.sh"
|
2023-08-23 17:56:31 +00:00
|
|
|
|
2023-10-05 02:23:07 +00:00
|
|
|
seavgabiosrom="elf/seabios/default/libgfxinit/vgabios.bin"
|
|
|
|
cfgsdir="config/coreboot"
|
2024-05-26 00:54:36 +00:00
|
|
|
picosrc="src/pico-serprog"
|
|
|
|
picosdk="src/pico-sdk"
|
|
|
|
stm32src="src/stm32-vserprog"
|
2023-09-30 12:05:57 +00:00
|
|
|
|
2023-10-05 02:23:07 +00:00
|
|
|
# Disable all payloads by default.
|
|
|
|
# target.cfg files have to specifically enable [a] payload(s)
|
2024-05-26 00:54:36 +00:00
|
|
|
pv="payload_uboot payload_grub_withseabios payload_seabios payload_memtest t"
|
|
|
|
pv="$pv payload_seabios_withgrub payload_seabios_grubonly payload_grub mt86bin"
|
2024-06-14 16:34:30 +00:00
|
|
|
v="romdir cbrom initmode displaymode cbcfg targetdir tree release"
|
make GRUB multi-tree and re-add xhci patches
Re-add xHCI only on haswell and broadwell machines, where
they are needed. Otherwise, keep the same GRUB code.
The xHCI patches were removed because they caused issues
on Sandybridge-based Dell Latitude laptops. See:
https://codeberg.org/libreboot/lbmk/issues/216
The issue was not reported elsewhere, including on the
Haswell/Broadwell hardware where they are needed, but the
build system could only build one version of GRUB.
The older machines do not need xHCI patches, because they
either do not have xHCI patches, or work (in GRUB) because
they're in EHCI mode when running the payload.
So, the problem is that we need the xHCI patches for GRUB
on Haswell/Broadwell hardware, but the patches break
Sandybridge hardware, and we only had the one build of GRUB.
To mitigate this problem, the build system now supports
building multiple revisions of GRUB, with different patches,
and each given coreboot target can say which GRUB tree to use
by setting this in target.cfg:
grubtree="xhci"
In the above example, the "xhci" tree would be used. Some
generic GRUB config has been moved to config/data/grub/
and config/grub/ now looks like config/coreboot/ - also,
the grub.cfg file (named "payload" in each tree) is copied
to the GRUB source tree as ".config", then added to GRUB's
memdisk in the same way, as grub.cfg.
Several other design changes had to be made because of this:
* grub.cfg in memdisk no longer automatically jumps to one
in CBFS, but now shows a menuentry for it if available
* Certain commands in script/trees are disabled for GRUB,
such as *config make commands.
* gnulib is now defined in config/submodule/grub/, instead
of config/git/grub - and this mitigates an existing bug
where downloading gnulib first would make grub no longer
possible to download in lbmk.
The coreboot option CONFIG_FINALIZE_USB_ROUTE_XHCI has been
re-enabled on: Dell OptiPlex 9020 MT, Dell OptiPlex 9020 SFF,
Lenovo ThinkPad T440p and Lenovo ThinkPad W541 - now USB should
work again in GRUB.
The GRUB payload has been re-enabled on HP EliteBook 820 G2.
This change will enable per-board GRUB optimisation in the
future. For example, we hardcode what partitions and LVMs
GRUB scans because * is slow on ICH7-based machines, due
to GRUB's design. On other machines, * is reasonably fast,
for automatically enumerating the list of devices for boot.
Use of * (and other wildcards) could enable our GRUB payload
to automatically boot more distros, with minimal fuss. This
can be done at a later date, in subsequent revisions.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-06-01 22:01:30 +00:00
|
|
|
v="$v grub_timeout ubdir board grub_scan_disk uboot_config grubtree grubelf"
|
2024-06-14 08:11:07 +00:00
|
|
|
eval "$(setvars "n" $pv)"
|
2024-06-14 16:34:30 +00:00
|
|
|
eval "$(setvars "" $v boards targets serprog_boards_dir)"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
|
|
|
main()
|
2023-09-30 12:21:15 +00:00
|
|
|
{
|
2023-10-05 02:23:07 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2024-06-14 13:19:44 +00:00
|
|
|
[ "$1" = "list" ] && eval "x_ ls -1 config/coreboot; return 0"
|
|
|
|
[ "$1" = "serprog" ] && eval "shift 1; mkserprog $@; return 0"
|
|
|
|
[ "$1" = "all" ] && shift && continue
|
|
|
|
boards="$1 $boards"; shift 1
|
2023-10-05 02:23:07 +00:00
|
|
|
done
|
|
|
|
|
2024-06-14 12:19:25 +00:00
|
|
|
[ -n "$boards" ] || boards="$(ls -1 config/coreboot)" || \
|
2024-06-14 08:11:07 +00:00
|
|
|
$err "Cannot generate list of boards for building"
|
|
|
|
for x in $boards; do
|
2024-06-14 15:34:05 +00:00
|
|
|
[ -d "config/coreboot/$x/config" ] && configure_target "$x" \
|
|
|
|
&& build_payloads && build_board && [ -d "bin/$board" ] \
|
|
|
|
&& targets="$targets, $x"; continue
|
2024-06-14 08:11:07 +00:00
|
|
|
done
|
2023-10-06 02:03:31 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
[ -z "$targets" ] && $err "No ROM images were compiled"
|
2024-06-14 15:34:05 +00:00
|
|
|
printf "Check these ROM directories in bin/: %s\n" "${targets#, }"
|
2023-12-24 09:04:36 +00:00
|
|
|
printf "DO NOT flash images from elf/ - please use bin/ instead.\n"
|
2023-09-30 12:21:15 +00:00
|
|
|
}
|
|
|
|
|
2024-06-14 13:19:44 +00:00
|
|
|
mkserprog()
|
2024-05-09 12:52:49 +00:00
|
|
|
{
|
2024-06-02 23:17:36 +00:00
|
|
|
[ -z "${1+x}" ] && badcmd
|
2024-05-15 03:30:42 +00:00
|
|
|
[ "$1" != "rp2040" ] && [ "$1" != "stm32" ] && $err "bad command"
|
2024-05-26 00:54:36 +00:00
|
|
|
if [ "$1" = "rp2040" ]; then
|
|
|
|
serprog_boards_dir="$picosdk/src/boards/include/boards"
|
|
|
|
[ -d "$picosrc" ] || x_ ./update trees -f "pico-serprog"
|
|
|
|
elif [ "$1" = "stm32" ]; then
|
|
|
|
serprog_boards_dir="$stm32src/boards"
|
|
|
|
[ -d "$stm32src" ] || x_ ./update trees -f "stm32-vserprog"
|
2024-05-09 12:52:49 +00:00
|
|
|
fi
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ mkdir -p "bin/serprog_$1"
|
2024-05-09 12:52:49 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
if [ $# -gt 1 ] && [ "$2" = "list" ]; then
|
|
|
|
list_serprog_boards "$serprog_boards_dir"
|
2024-05-14 22:17:22 +00:00
|
|
|
return 0
|
2024-05-09 12:52:49 +00:00
|
|
|
elif [ $# -gt 1 ]; then
|
2024-05-26 00:54:36 +00:00
|
|
|
build_${1}_rom "$2"
|
2024-05-09 12:52:49 +00:00
|
|
|
else
|
2024-05-26 00:54:36 +00:00
|
|
|
list_serprog_boards "$serprog_boards_dir" | \
|
2024-05-09 12:52:49 +00:00
|
|
|
while read -r board; do
|
2024-05-26 00:54:36 +00:00
|
|
|
build_${1}_rom "$board"
|
2024-05-09 12:52:49 +00:00
|
|
|
done
|
|
|
|
fi
|
2024-05-14 22:17:22 +00:00
|
|
|
|
2024-05-19 05:45:38 +00:00
|
|
|
[ "$xbmk_release" = "y" ] && mkrom_tarball "bin/serprog_$1"; return 0
|
2024-05-09 12:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_rp2040_rom()
|
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
board="$1"
|
|
|
|
printf "Building pico-serprog for %s\n" "$board"
|
|
|
|
x_ cmake -DPICO_BOARD="$board" -DPICO_SDK_PATH="$picosdk" \
|
|
|
|
-B "$picosrc/build" "$picosrc"
|
|
|
|
x_ cmake --build "$picosrc/build"
|
|
|
|
x_ mv "$picosrc/build/pico_serprog.uf2" \
|
|
|
|
"bin/serprog_rp2040/serprog_$board.uf2"
|
2024-05-09 12:52:49 +00:00
|
|
|
printf "output to bin/serprog_rp2040/serprog_%s.uf2\n" "$board"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_stm32_rom()
|
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
board="$1"
|
|
|
|
printf "Building stm32-vserprog for %s\n" "$board"
|
|
|
|
x_ make -C "$stm32src" libopencm3-just-make BOARD=$board
|
|
|
|
x_ make -C "$stm32src" BOARD=$board
|
|
|
|
x_ mv "$stm32src/stm32-vserprog.hex" \
|
|
|
|
"bin/serprog_stm32/serprog_$board.hex"
|
2024-05-09 12:52:49 +00:00
|
|
|
printf "output to bin/serprog_stm32/serprog_%s.hex\n" "$board"
|
|
|
|
}
|
|
|
|
|
|
|
|
list_serprog_boards()
|
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
basename -a -s .h "$1/"*.h || $err "$1: can't list boards"
|
2024-05-09 12:52:49 +00:00
|
|
|
}
|
|
|
|
|
2024-06-14 15:34:05 +00:00
|
|
|
configure_target()
|
2024-05-05 04:09:23 +00:00
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
eval "$(setvars "n" $pv) $(setvars "" $v)"
|
2024-05-05 04:28:06 +00:00
|
|
|
board="$1"
|
2024-05-05 04:09:23 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
targetdir="$cfgsdir/$board"
|
|
|
|
[ -f "$targetdir/target.cfg" ] || $err "$board: target.cfg missing"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
|
|
|
# Override the above defaults using target.cfg
|
2024-05-26 00:54:36 +00:00
|
|
|
. "$targetdir/target.cfg"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
grub.cfg: use grub_scan_disk to set boot order
Previously, grub_scan_disk could set ata, ahci or "both",
which would make both be tried (ahci first). This worked
when we only dealt with ata and ahci devices, but now we
support nvme devices so the logic is inherently flawed.
Instead, use grub_scan_disk to store the boot order, e.g.:
grub_scan_disk="ahci nvme ata"
grub_scan_disk="nvme ata"
In the first example, it would make GRUB scan ahci first,
then nvme and then ata.
In the secontd example, it would make GRUB scan nvme first,
and then ata.
If "both" is set, or anything other than ahci/ata/nvme,
grub_scan_disk is now changed to "nvme ahci ata".
Actual grub_scan_disk entries in target.cfg files will now
be modified, to match each machine.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-05-27 19:16:49 +00:00
|
|
|
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
|
2024-06-09 17:48:58 +00:00
|
|
|
|
make GRUB multi-tree and re-add xhci patches
Re-add xHCI only on haswell and broadwell machines, where
they are needed. Otherwise, keep the same GRUB code.
The xHCI patches were removed because they caused issues
on Sandybridge-based Dell Latitude laptops. See:
https://codeberg.org/libreboot/lbmk/issues/216
The issue was not reported elsewhere, including on the
Haswell/Broadwell hardware where they are needed, but the
build system could only build one version of GRUB.
The older machines do not need xHCI patches, because they
either do not have xHCI patches, or work (in GRUB) because
they're in EHCI mode when running the payload.
So, the problem is that we need the xHCI patches for GRUB
on Haswell/Broadwell hardware, but the patches break
Sandybridge hardware, and we only had the one build of GRUB.
To mitigate this problem, the build system now supports
building multiple revisions of GRUB, with different patches,
and each given coreboot target can say which GRUB tree to use
by setting this in target.cfg:
grubtree="xhci"
In the above example, the "xhci" tree would be used. Some
generic GRUB config has been moved to config/data/grub/
and config/grub/ now looks like config/coreboot/ - also,
the grub.cfg file (named "payload" in each tree) is copied
to the GRUB source tree as ".config", then added to GRUB's
memdisk in the same way, as grub.cfg.
Several other design changes had to be made because of this:
* grub.cfg in memdisk no longer automatically jumps to one
in CBFS, but now shows a menuentry for it if available
* Certain commands in script/trees are disabled for GRUB,
such as *config make commands.
* gnulib is now defined in config/submodule/grub/, instead
of config/git/grub - and this mitigates an existing bug
where downloading gnulib first would make grub no longer
possible to download in lbmk.
The coreboot option CONFIG_FINALIZE_USB_ROUTE_XHCI has been
re-enabled on: Dell OptiPlex 9020 MT, Dell OptiPlex 9020 SFF,
Lenovo ThinkPad T440p and Lenovo ThinkPad W541 - now USB should
work again in GRUB.
The GRUB payload has been re-enabled on HP EliteBook 820 G2.
This change will enable per-board GRUB optimisation in the
future. For example, we hardcode what partitions and LVMs
GRUB scans because * is slow on ICH7-based machines, due
to GRUB's design. On other machines, * is reasonably fast,
for automatically enumerating the list of devices for boot.
Use of * (and other wildcards) could enable our GRUB payload
to automatically boot more distros, with minimal fuss. This
can be done at a later date, in subsequent revisions.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-06-01 22:01:30 +00:00
|
|
|
[ -n "$grubtree" ] || grubtree="default"
|
|
|
|
grubelf="elf/grub/$grubtree/payload/grub.elf"
|
|
|
|
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
[ -z "$tree" ] && $err "$board: tree not defined"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_memtest" != "y" ] && payload_memtest="n"
|
2024-05-21 22:32:18 +00:00
|
|
|
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
|
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_grub_withseabios" = "y" ] && payload_grub="y"
|
|
|
|
[ "$payload_grub_withseabios" = "y" ] && \
|
2023-10-05 21:16:07 +00:00
|
|
|
eval "$(setvars "y" payload_seabios payload_seabios_withgrub)"
|
2023-12-22 13:05:32 +00:00
|
|
|
[ "$payload_seabios_withgrub" = "y" ] && payload_seabios="y"
|
|
|
|
[ "$payload_seabios_grubonly" = "y" ] && payload_seabios="y"
|
|
|
|
[ "$payload_seabios_grubonly" = "y" ] && payload_seabios_withgrub="y"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
|
|
|
# The reverse logic must not be applied. If SeaBIOS-with-GRUB works,
|
2024-05-19 05:30:32 +00:00
|
|
|
# that doesn't mean GRUB-with-SeaBIOS will, e.g. VGA ROM execution
|
2023-12-24 09:04:36 +00:00
|
|
|
[ "$payload_grub" != "y" ] && [ "$payload_seabios" != "y" ] && \
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_uboot" != "y" ] && $err "'$board' defines no payload"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2023-12-24 09:04:36 +00:00
|
|
|
[ "$payload_uboot" != "n" ] && [ "$payload_uboot" != "y" ] && \
|
2023-10-05 02:23:07 +00:00
|
|
|
payload_uboot="n"
|
2023-12-24 09:04:36 +00:00
|
|
|
[ "$payload_uboot" = "y" ] && [ -z "$uboot_config" ] && \
|
2024-06-14 15:26:49 +00:00
|
|
|
uboot_config="default"
|
|
|
|
|
|
|
|
[ "$xbmk_release" = "y" ] && [ "$release" = "n" ] && return 1
|
|
|
|
[ "$board" = "$tree" ] && return 1; return 0
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
2024-01-01 17:57:35 +00:00
|
|
|
build_payloads()
|
2023-09-30 13:13:11 +00:00
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
romdir="bin/$board"
|
|
|
|
cbdir="src/coreboot/$board"
|
|
|
|
[ "$board" = "$tree" ] || cbdir="src/coreboot/$tree"
|
2024-06-06 20:45:53 +00:00
|
|
|
cbfstool="elf/cbfstool/$tree/cbfstool"
|
2024-05-26 00:54:36 +00:00
|
|
|
cbrom="$cbdir/build/coreboot.rom"
|
2023-10-02 02:54:39 +00:00
|
|
|
|
2023-12-24 09:04:36 +00:00
|
|
|
[ -f "$cbfstool" ] || x_ ./update trees -b coreboot utils $tree
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-06-06 08:05:16 +00:00
|
|
|
mt86bin="elf/memtest86plus/memtest.bin"
|
2024-06-06 08:11:39 +00:00
|
|
|
[ "$payload_memtest" != "y" ] || [ -f "$mt86bin" ] || \
|
2023-10-19 23:17:30 +00:00
|
|
|
x_ ./update trees -b memtest86plus
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-01-01 17:52:23 +00:00
|
|
|
[ "$payload_seabios" = "y" ] && x_ ./update trees -b seabios
|
2024-01-01 22:11:29 +00:00
|
|
|
if [ "$payload_grub" = "y" ] || [ "$payload_seabios_withgrub" = "y" ] \
|
2024-06-14 16:34:30 +00:00
|
|
|
|| [ "$payload_seabios_grubonly" = "y" ]; then
|
|
|
|
[ -f "$grubelf" ] || x_ ./update trees -b grub $grubtree
|
2024-01-01 22:11:29 +00:00
|
|
|
fi
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_uboot" = "y" ] && build_uboot_payload; return 0
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
2024-01-01 17:57:35 +00:00
|
|
|
build_uboot_payload()
|
2023-10-05 02:23:07 +00:00
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ ./update trees -b u-boot $board
|
|
|
|
ubdir="elf/u-boot/$board/$uboot_config"
|
|
|
|
ubootelf="$ubdir/u-boot.elf"
|
|
|
|
[ ! -f "$ubootelf" ] && [ -f "$ubdir/u-boot" ] && \
|
|
|
|
ubootelf="$ubdir/u-boot"
|
|
|
|
[ -f "$ubootelf" ] || $err "$board: Can't find u-boot"; return 0
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
2024-06-14 15:34:05 +00:00
|
|
|
build_board()
|
2023-10-05 02:23:07 +00:00
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ rm -Rf "$romdir"
|
2023-12-23 16:16:26 +00:00
|
|
|
|
2023-10-05 02:23:07 +00:00
|
|
|
for x in "normal" "vgarom" "libgfxinit"; do
|
2024-05-26 00:54:36 +00:00
|
|
|
initmode="$x"
|
2023-10-05 02:23:07 +00:00
|
|
|
hmode="vesafb"
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$initmode" = "vgarom" ] || hmode="corebootfb"
|
|
|
|
modes="$hmode txtmode"
|
|
|
|
for y in $modes; do
|
|
|
|
displaymode="$y"
|
|
|
|
[ "$initmode" = "normal" ] && \
|
2023-10-05 02:23:07 +00:00
|
|
|
[ "$displaymode" != "txtmode" ] && continue
|
2024-05-26 00:54:36 +00:00
|
|
|
cbcfg="$targetdir/config/${initmode}_$displaymode"
|
|
|
|
[ "$initmode" = "normal" ] && cbcfg="${cbcfg%_*}"
|
|
|
|
build_roms "$cbcfg"; x_ rm -f "$cbrom"
|
2023-10-05 02:23:07 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
build_roms()
|
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
cbcfg="$1"
|
|
|
|
e "$cbcfg" f not && return 0
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ ./update trees -b coreboot $board
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2023-12-22 13:05:32 +00:00
|
|
|
_cbrom="elf/coreboot_nopayload_DO_NOT_FLASH"
|
2024-05-26 00:54:36 +00:00
|
|
|
_cbrom="$_cbrom/$board/${initmode}_$displaymode"
|
|
|
|
[ "$initmode" = "normal" ] && _cbrom="${_cbrom%"_$displaymode"}"
|
|
|
|
_cbrom="$_cbrom/coreboot.rom"
|
2023-10-05 02:23:07 +00:00
|
|
|
cbrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ cp "$_cbrom" "$cbrom"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-06-15 19:22:19 +00:00
|
|
|
[ "$payload_memtest" != "y" ] || cbfs "$cbrom" "$mt86bin" img/memtest
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_seabios" = "y" ] && build_seabios_roms
|
2024-06-15 22:31:26 +00:00
|
|
|
[ "$payload_grub" != "y" ] || build_grub_roms "$cbrom" "grub"
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_uboot" = "y" ] || return 0
|
|
|
|
x_ cp "$_cbrom" "$cbrom"
|
2023-10-05 02:23:07 +00:00
|
|
|
build_uboot_roms
|
|
|
|
}
|
|
|
|
|
|
|
|
build_seabios_roms()
|
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
if [ "$payload_seabios_withgrub" = "y" ]; then
|
|
|
|
t="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
|
|
|
|
x_ cp "$cbrom" "$t"
|
2024-06-15 22:31:26 +00:00
|
|
|
build_grub_roms "$t" "seabios_withgrub"
|
2023-10-05 02:23:07 +00:00
|
|
|
else
|
2024-05-26 00:54:36 +00:00
|
|
|
t="$(mkSeabiosRom "$cbrom" "fallback/payload")" || \
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "build_seabios_roms: cannot build tmprom"
|
2024-05-26 00:54:36 +00:00
|
|
|
newrom="$romdir/seabios_${board}_${initmode}_$displaymode"
|
|
|
|
[ "$initmode" = "normal" ] && newrom="$romdir/seabios" \
|
|
|
|
&& newrom="${newrom}_${board}_$initmode"
|
|
|
|
x_ cprom "$t" "$newrom.rom"
|
2023-10-05 02:23:07 +00:00
|
|
|
fi
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ rm -f "$t"
|
2023-09-30 13:13:11 +00:00
|
|
|
}
|
|
|
|
|
2024-06-14 16:34:30 +00:00
|
|
|
# Make separate ROM images with GRUB payload
|
2023-10-05 02:23:07 +00:00
|
|
|
build_grub_roms()
|
2023-09-30 12:05:57 +00:00
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
tmprom="$1"
|
|
|
|
payload1="$2" # allow values: grub, seabios, seabios_withgrub
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2023-10-05 21:16:07 +00:00
|
|
|
grub_cbfs="fallback/payload"
|
2023-12-23 12:16:14 +00:00
|
|
|
if [ "$payload1" = "grub" ] && [ "$payload_grub_withseabios" = "y" ]
|
|
|
|
then
|
2024-05-26 00:54:36 +00:00
|
|
|
_tmpmvrom="$(mkSeabiosRom "$tmprom" "seabios.elf")" || \
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "build_grub_roms 1 $board: can't build tmprom"
|
2023-12-23 12:16:14 +00:00
|
|
|
x_ mv "$_tmpmvrom" "$tmprom"
|
|
|
|
elif [ "$payload1" != "grub" ] && [ "$payload_seabios_withgrub" = "y" ]
|
|
|
|
then
|
|
|
|
grub_cbfs="img/grub2"
|
2024-05-26 00:54:36 +00:00
|
|
|
_tmpmvrom="$(mkSeabiosRom "$tmprom" fallback/payload)" || \
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "build_grub_roms 2 $board: can't build tmprom"
|
2023-12-23 12:16:14 +00:00
|
|
|
x_ mv "$_tmpmvrom" "$tmprom"
|
|
|
|
fi
|
2023-10-05 02:23:07 +00:00
|
|
|
|
|
|
|
# we only need insert grub.elf once, for each coreboot config:
|
2024-06-15 19:22:19 +00:00
|
|
|
cbfs "$tmprom" "$grubelf" "$grub_cbfs"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
tmpcfg="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
|
|
|
|
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" > "$tmpcfg" || \
|
2024-06-14 13:01:42 +00:00
|
|
|
$err "set grub_scan_disk, $grub_scan_disk, $tmpcfg"
|
2024-06-15 19:22:19 +00:00
|
|
|
cbfs "$tmprom" "$tmpcfg" scan.cfg raw
|
2024-05-26 00:54:36 +00:00
|
|
|
printf "set timeout=%s\n" "$grub_timeout" > "$tmpcfg" || \
|
|
|
|
$err "set timeout, $grub_timeout, $tmpcfg"
|
2024-06-15 19:22:19 +00:00
|
|
|
[ -z "$grub_timeout" ] || cbfs "$tmprom" "$tmpcfg" timeout.cfg raw
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ rm -f "$tmpcfg"
|
|
|
|
|
2024-06-14 16:34:30 +00:00
|
|
|
newrom="$romdir/${payload1}_${board}_${initmode}_$displaymode.rom"
|
|
|
|
[ "$initmode" = "normal" ] && newrom="$romdir/${payload1}_" \
|
|
|
|
&& newrom="$newrom${board}_$initmode.rom"
|
|
|
|
x_ cprom "$tmprom" "$newrom"
|
|
|
|
if [ "$payload_seabios_withgrub" = "y" ] && \
|
|
|
|
[ "$payload1" != "grub" ]; then
|
2024-06-15 19:22:19 +00:00
|
|
|
cbfs "$tmprom" "$grubdata/bootorder" bootorder raw
|
2024-06-14 16:34:30 +00:00
|
|
|
x_ cprom "$tmprom" "${newrom%.rom}_grubfirst.rom"
|
|
|
|
if [ "$payload_seabios_grubonly" = "y" ]; then
|
|
|
|
x_ "$cbfstool" "$tmprom" add-int -i 0 \
|
|
|
|
-n etc/show-boot-menu
|
|
|
|
x_ cprom "$tmprom" "${newrom%.rom}_grubonly.rom"
|
2024-04-28 18:56:25 +00:00
|
|
|
fi
|
2024-06-14 16:34:30 +00:00
|
|
|
fi
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# make a rom in /tmp/ and then print the path of that ROM
|
|
|
|
mkSeabiosRom() {
|
2024-05-26 00:54:36 +00:00
|
|
|
_cbrom="$1" # rom to insert seabios in. will not be touched
|
2023-10-05 02:23:07 +00:00
|
|
|
# (a tmpfile will be made instead)
|
2024-05-26 00:54:36 +00:00
|
|
|
_seabios_cbfs_path="$2" # e.g. fallback/payload
|
|
|
|
_seabioself="elf/seabios/default/$initmode/bios.bin.elf"
|
|
|
|
tmprom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ cp "$_cbrom" "$tmprom"
|
2024-06-15 19:22:19 +00:00
|
|
|
cbfs "$tmprom" "$_seabioself" "$_seabios_cbfs_path"
|
2023-12-22 13:05:32 +00:00
|
|
|
x_ "$cbfstool" "$tmprom" add-int -i 3000 -n etc/ps2-keyboard-spinup
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2023-12-24 09:04:36 +00:00
|
|
|
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
|
2024-06-15 19:22:19 +00:00
|
|
|
[ "$initmode" != "libgfxinit" ] || cbfs "$tmprom" "$seavgabiosrom" \
|
|
|
|
vgaroms/seavgabios.bin raw
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
printf "%s\n" "$tmprom"
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_uboot_roms()
|
|
|
|
{
|
2024-05-26 00:54:36 +00:00
|
|
|
tmprom="$(mkUbootRom "$cbrom" "fallback/payload")" || \
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
$err "build_uboot_roms $board: could not create tmprom"
|
2024-05-26 00:54:36 +00:00
|
|
|
newrom="$romdir/uboot_payload_${board}_${initmode}_$displaymode.rom"
|
|
|
|
x_ cprom "$tmprom" "$newrom"
|
|
|
|
x_ rm -f "$tmprom"
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# make a rom in /tmp/ and then print the path of that ROM
|
|
|
|
mkUbootRom() {
|
2024-05-26 00:54:36 +00:00
|
|
|
_cbrom="$1"
|
|
|
|
_uboot_cbfs_path="$2"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
_ubdir="elf/u-boot/$board/$uboot_config"
|
|
|
|
_ubootelf="$_ubdir/u-boot.elf"
|
|
|
|
[ -f "$_ubootelf" ] || _ubootelf="$_ubdir/u-boot"
|
safer, simpler error handling in lbmk
in shell scripts, a function named the same as a program included in
the $PATH will override that program. for example, you could make a
function called ls() and this would override the standand "ls".
in lbmk, a part of it was first trying to run the "fail" command,
deferring to "err", because some scripts call fail() which does
some minor cleanup before calling err.
in most cases, fail() is not defined, and it's possible that the user
could have a program called "fail" in their $PATH, the behaviour of
which we could not determine, and it could have disastrous effects.
lbmk error handling has been re-engineered in such a way that the
err function is defined in a variable, which defaults to err_ which
calls err_, so defined under include/err.sh.
in functions that require cleanup prior to error handling, a fail()
function is still defined, and err is overridden, thus:
err="fail"
this change has made xx_() obsolete, so now only x_ is used. the x_
function is a wrapper that can be used to run a command and exit with
non-zero status (from lbmk) if the command fails. the xx_ command
did the same thing, but called fail() which would have called err();
now everything is $err
example:
rm -f "$filename" || err "could not delete file"
this would now be:
rm -f "$filename" || $err "could not delete file"
overriding of err= must be done *after* including err.sh. for
example:
err="fail"
. "include/err.sh"
^ this is wrong. instead, one must do:
. "include/err.sh"
err="fail"
this is because err is set as a global variable under err.sh
the new error handling is much cleaner, and safer. it also reduces
the chance of mistakes such as: calling err when you meant to
call fail. this is because the standard way is now to call $err,
so you set err="fail" at the top of the script and all is well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-03-27 01:19:39 +00:00
|
|
|
[ -f "$_ubootelf" ] || $err "mkUbootRom: $board: cant find u-boot"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
tmprom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ cp "$_cbrom" "$tmprom"
|
2024-06-15 19:22:19 +00:00
|
|
|
cbfs "$tmprom" "$_ubootelf" "$_uboot_cbfs_path"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
printf "%s\n" "$tmprom"
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
cprom()
|
don't delete microcode updates in rom images
at present, lbmk can remove microcode updates on images for
a given target, if the target specifies
microcode_required="n" in target.cfg
lbmk then provides images with microcode, and images without,
in a given release. although the user can also remove them
manually, this just makes it a bit more convenient, for those
users who do wish to run without the updates. this functionality
is provided only on those platforms where no-microcode is tested.
well, this behaviour implements a compromise on libreboot policy,
which is to always include microcode updates by default. see:
Binary Blob Reduction Policy
the *canoeboot* project now exists, developed in parallel with
libreboot, and it ships without microcode updates, on the same
targets where lbmk also handled this.
running without microcode updates is foolish, and should not
be encouraged. clean up lbmk by not providing this kludge.
the libreboot documentation will be updated, telling such users
to try canoeboot instead, or to remove the update from a given
libreboot rom - this is still possible, and mitigations such as
PECI disablement on GM45 are still in place (and will be kept),
so that this continues to work well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-12-23 06:54:56 +00:00
|
|
|
{
|
|
|
|
printf "Creating target image: %s\n" "$2"
|
2023-10-05 02:23:07 +00:00
|
|
|
|
don't delete microcode updates in rom images
at present, lbmk can remove microcode updates on images for
a given target, if the target specifies
microcode_required="n" in target.cfg
lbmk then provides images with microcode, and images without,
in a given release. although the user can also remove them
manually, this just makes it a bit more convenient, for those
users who do wish to run without the updates. this functionality
is provided only on those platforms where no-microcode is tested.
well, this behaviour implements a compromise on libreboot policy,
which is to always include microcode updates by default. see:
Binary Blob Reduction Policy
the *canoeboot* project now exists, developed in parallel with
libreboot, and it ships without microcode updates, on the same
targets where lbmk also handled this.
running without microcode updates is foolish, and should not
be encouraged. clean up lbmk by not providing this kludge.
the libreboot documentation will be updated, telling such users
to try canoeboot instead, or to remove the update from a given
libreboot rom - this is still possible, and mitigations such as
PECI disablement on GM45 are still in place (and will be kept),
so that this continues to work well.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-12-23 06:54:56 +00:00
|
|
|
x_ mkdir -p "${2%/*}"
|
|
|
|
x_ cp "$1" "$2"
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$xbmk_release" = "y" ] && mksha512sum "$2" "vendorhashes" && \
|
|
|
|
x_ ./vendor inject -r "$2" -b "$board" -n nuke; return 0
|
2023-10-05 02:23:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 04:39:11 +00:00
|
|
|
main $@
|