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"
|
|
|
|
grub_background="background1280x800.png"
|
|
|
|
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"
|
haswell: only provide NRI-based ROMs in releases
release="n" is set in target.cfg on haswell build targets
that use mrc.bin
script/update/release exports LBMK_RELEASE="y"
script/build/roms skips building a given target if release="n"
in target.cfg *and* LBMK_RELEASE="y"
you could also do the export yourself before running ./build roms,
for example:
export LBMK_RELEASE="y"
./build roms all
This would skip these ROM images. The native haswell raminit is
now stable enough in my testing, that I wish to delete the MRC-based
targets. This is in line with Libreboot's Binary Blob Reduction Policy,
which states: if a blob can be avoided, it should be avoided.
The problem is that users often run the inject script in *lbmk* from
Git, instead of from the src release archive. I forsee some users
running this on modern lbmk with older release images. If the mrc-based
target isn't there, the user may use an NRI-based target name, and
think it works; they will insert without MRC. I foresaw this ages
ago, which is why Caleb and I ensured that the script checks hashes,
and hashes are included in releases.
Therefore: for the time being, keep the MRC-based configs in lbmk
but do not include images for them in releases. This can be done
indefinitely, but I'll probably remove those configs entirely at
some point.
On the following boards, Libreboot now will *only* provide NRI-based
ROM images for the following machines:
* Dell OptiPlex 9020 SFF
* Dell OptiPlex 9020 MT
* Lenovo ThinkPad T440p
* Lenovo ThinkPad W541/W540
I now recommend exclusive use of NRI-based images, on Haswell
hardware. It's stable enough in my testing, and now supports S3.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-04-24 04:27:27 +00:00
|
|
|
v="romdir cbrom initmode displaymode cbcfg targetdir tree keymaps 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 13:01:42 +00:00
|
|
|
eval "$(setvars "" $v boards opt_k 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:01:42 +00:00
|
|
|
if [ "$1" = "-k" ]; then
|
2024-06-14 08:11:07 +00:00
|
|
|
[ $# -lt 2 ] && $err "$1: option not specified"
|
2024-06-14 13:01:42 +00:00
|
|
|
opt_k="$2"
|
2024-06-14 08:11:07 +00:00
|
|
|
elif [ "$1" = "serprog" ]; then
|
|
|
|
shift 1; handle_serprog $@; return 0
|
|
|
|
elif [ "$1" = "list" ]; then
|
2024-06-14 12:19:25 +00:00
|
|
|
x_ ls -1 config/coreboot; return 0
|
2024-06-14 08:11:07 +00:00
|
|
|
else
|
|
|
|
[ "$1" = "all" ] && shift && continue
|
2024-05-26 00:54:36 +00:00
|
|
|
boards="$1 $boards"
|
2024-06-14 08:11:07 +00:00
|
|
|
shift && continue
|
|
|
|
fi
|
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
|
|
|
|
[ -d "config/coreboot/$x/config" ] && \
|
|
|
|
handle_coreboot_target "$x"; continue
|
|
|
|
done
|
2023-10-06 02:03:31 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
x="directories"
|
|
|
|
[ "$xbmk_release" = "y" ] && x="archives (remember the inject command)"
|
2024-05-14 22:17:22 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
[ -z "$targets" ] && $err "No ROM images were compiled"
|
2024-05-26 08:22:39 +00:00
|
|
|
printf "\nROM images available in these %s:\n" "$x"
|
2024-05-26 00:54:36 +00:00
|
|
|
eval "printf \"$targets\""
|
2024-05-26 08:22:39 +00:00
|
|
|
printf "^^ ROM images available in these %s.\n\n" "$x"
|
2023-10-10 05:04:47 +00:00
|
|
|
|
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-05-09 12:52:49 +00:00
|
|
|
handle_serprog()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
handle_coreboot_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:09:23 +00:00
|
|
|
grub_background="background1280x800.png"
|
2024-05-05 04:28:06 +00:00
|
|
|
board="$1"
|
2024-05-05 04:09:23 +00:00
|
|
|
|
|
|
|
configure_target
|
2024-05-11 17:53:12 +00:00
|
|
|
[ "$board" = "$tree" ] && return 0
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$xbmk_release" = "y" ] && [ "$release" = "n" ] && return 0
|
2024-05-05 04:09:23 +00:00
|
|
|
|
|
|
|
build_payloads
|
|
|
|
build_target_mainboard
|
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
[ -d "bin/$board" ] || return 0
|
|
|
|
[ "$xbmk_release" = "y" ] || targets="* bin/$board\n$targets"
|
2024-05-19 05:45:38 +00:00
|
|
|
[ "$xbmk_release" = "y" ] && mkrom_tarball "bin/$board" && \
|
2024-05-26 00:54:36 +00:00
|
|
|
targets="* bin/${relname}_$board.tar.xz\n$targets"; return 0
|
2024-05-05 04:09:23 +00:00
|
|
|
}
|
|
|
|
|
2023-12-24 06:02:12 +00:00
|
|
|
configure_target()
|
2023-10-05 02:23:07 +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 13:01:42 +00:00
|
|
|
uboot_config="default"; 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" ] \
|
|
|
|
|| [ "$payload_seabios_grubonly" = "y" ]; then build_grub_payload
|
|
|
|
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:47:43 +00:00
|
|
|
build_grub_payload()
|
2023-10-05 02:23:07 +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
|
|
|
for keymapfile in "$grubdata/keymap/"*.gkb; do
|
2024-05-26 00:54:36 +00:00
|
|
|
[ -f "$keymapfile" ] && keymaps="$keymaps $keymapfile"
|
2023-09-30 13:13:11 +00:00
|
|
|
done
|
2024-06-14 08:11:07 +00:00
|
|
|
[ -z "$opt_k" ] || [ -f "$grubdata/keymap/${opt_k}.gkb" ] || \
|
|
|
|
$err "build_grub_payload: ${opt_k} layout not defined"
|
|
|
|
[ -n "$opt_k" ] && keymaps="$grubdata/keymap/$opt_k.gkb"
|
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
|
|
|
|
|
|
|
[ -f "$grubelf" ] || x_ ./update trees -b grub $grubtree; 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-01-01 18:00:53 +00:00
|
|
|
build_target_mainboard()
|
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-05-26 00:54:36 +00:00
|
|
|
[ "$payload_memtest" != "y" ] || x_ "$cbfstool" "$cbrom" add-payload \
|
2024-06-06 08:11:39 +00:00
|
|
|
-f "$mt86bin" -n img/memtest -c lzma
|
2024-05-26 00:54:36 +00:00
|
|
|
[ "$payload_seabios" = "y" ] && build_seabios_roms
|
2023-12-24 09:04:36 +00:00
|
|
|
[ "$payload_grub" != "y" ] || x_ 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"
|
|
|
|
x_ 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
|
|
|
}
|
|
|
|
|
2023-10-05 02:23:07 +00:00
|
|
|
# Make separate ROM images with GRUB payload, for each supported keymap
|
|
|
|
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-05-26 00:54:36 +00:00
|
|
|
x_ "$cbfstool" "$tmprom" add-payload -f "$grubelf" \
|
|
|
|
-n "$grub_cbfs" -c lzma
|
2023-10-05 02:23:07 +00:00
|
|
|
|
|
|
|
# we only need insert background.png once, for each coreboot config:
|
2024-05-26 00:54:36 +00:00
|
|
|
if [ "$displaymode" = "vesafb" ] || \
|
|
|
|
[ "$displaymode" = "corebootfb" ]; then
|
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
|
|
|
backgroundfile="$grubdata/background/$grub_background"
|
2024-05-26 00:54:36 +00:00
|
|
|
"$cbfstool" "$tmprom" add -f "$backgroundfile" -n \
|
|
|
|
background.png -t raw || $err "!bg, $backgroundfile"
|
2023-10-05 02:23:07 +00:00
|
|
|
fi
|
|
|
|
|
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"
|
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
|
|
|
x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
|
2024-05-26 00:54:36 +00:00
|
|
|
printf "set timeout=%s\n" "$grub_timeout" > "$tmpcfg" || \
|
|
|
|
$err "set timeout, $grub_timeout, $tmpcfg"
|
|
|
|
[ -z "$grub_timeout" ] || x_ "$cbfstool" "$tmprom" add \
|
|
|
|
-f "$tmpcfg" -n timeout.cfg -t raw
|
|
|
|
x_ rm -f "$tmpcfg"
|
|
|
|
|
|
|
|
for keymapfile in $keymaps; do
|
|
|
|
[ -f "$keymapfile" ] || continue
|
2023-10-05 02:23:07 +00:00
|
|
|
keymap="${keymapfile##*/}"
|
|
|
|
keymap="${keymap%.gkb}"
|
GRUB: insert only 1 keymap per board, in cbfs
There is no need to add multiple keymap files, because
GRUB can load keymaps from CBFS. The current build logic
is designed to avoid building multiple GRUB binaries,
which are expensive computationally because each one
would then have to be compressed for each board.
This patch provides the best of both worlds: less space
used in flash like in the old lbmk design (1 keymap per
board), but retaining the current build speeds and therefore
not re-introducing the slowness of lbmk's previous GRUB
build logic.
The grub.cfg file has been modified, accordingly. It now
only loads a keymap.gkb file from CBFS, by default. It does
this, only if that file exists; if not, GRUB already defaults
to US Qwerty layout anyway.
ALSO: compress all keymap gkb files with xz -6
GRUB automatically decompresses files when accessed.
This results in about 2KB of flash space saved in CBFS.
Here is real-world data, showing the increased flash space:
< fallback/payload 0x3eb80 simple elf 548821 none
< keymap.cfg 0xc4bc0 raw 16 none
< (empty) 0xc4c00 null 11633316 none
---
> fallback/payload 0x3eb80 simple elf 546787 none
> keymap.gkb 0xc43c0 raw 344 none
> (empty) 0xc4540 null 11635044 none
This was taken by diffing the cbfstool "print" output,
both before and after. The *after* result is with this change.
11633316. In this example, 1728 bytes have been saved. Therefore,
with compression taken into account, this patch saves about 1.7KB
of space in CBFS.
This change means that lbmk can now scale to support hundreds
of keymaps, without increasing the amount of flash space used,
in each given image. Since the keymap files are compressed in
lbmk.git, in advance, we spend no additional time on compression
at build time. The resulting change in build speed in negligible.
Adding your own keymap.gkb file was already possible, for changing
the keymap in libreboot images, if you didn't want to change the
memdisk (and thus re-compile grub.elf). Now, this is the default
behaviour, and the only way to do it. It's much more efficient.
The original keymap files can be restored, by running unxz.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-01-17 23:54:53 +00:00
|
|
|
|
|
|
|
tmpgrubrom="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ cp "$tmprom" "$tmpgrubrom"
|
GRUB: insert only 1 keymap per board, in cbfs
There is no need to add multiple keymap files, because
GRUB can load keymaps from CBFS. The current build logic
is designed to avoid building multiple GRUB binaries,
which are expensive computationally because each one
would then have to be compressed for each board.
This patch provides the best of both worlds: less space
used in flash like in the old lbmk design (1 keymap per
board), but retaining the current build speeds and therefore
not re-introducing the slowness of lbmk's previous GRUB
build logic.
The grub.cfg file has been modified, accordingly. It now
only loads a keymap.gkb file from CBFS, by default. It does
this, only if that file exists; if not, GRUB already defaults
to US Qwerty layout anyway.
ALSO: compress all keymap gkb files with xz -6
GRUB automatically decompresses files when accessed.
This results in about 2KB of flash space saved in CBFS.
Here is real-world data, showing the increased flash space:
< fallback/payload 0x3eb80 simple elf 548821 none
< keymap.cfg 0xc4bc0 raw 16 none
< (empty) 0xc4c00 null 11633316 none
---
> fallback/payload 0x3eb80 simple elf 546787 none
> keymap.gkb 0xc43c0 raw 344 none
> (empty) 0xc4540 null 11635044 none
This was taken by diffing the cbfstool "print" output,
both before and after. The *after* result is with this change.
11633316. In this example, 1728 bytes have been saved. Therefore,
with compression taken into account, this patch saves about 1.7KB
of space in CBFS.
This change means that lbmk can now scale to support hundreds
of keymaps, without increasing the amount of flash space used,
in each given image. Since the keymap files are compressed in
lbmk.git, in advance, we spend no additional time on compression
at build time. The resulting change in build speed in negligible.
Adding your own keymap.gkb file was already possible, for changing
the keymap in libreboot images, if you didn't want to change the
memdisk (and thus re-compile grub.elf). Now, this is the default
behaviour, and the only way to do it. It's much more efficient.
The original keymap files can be restored, by running unxz.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-01-17 23:54:53 +00:00
|
|
|
x_ "$cbfstool" "$tmpgrubrom" add -f "$keymapfile" \
|
|
|
|
-n keymap.gkb -t raw
|
2023-10-05 02:23:07 +00:00
|
|
|
|
2024-05-26 00:54:36 +00:00
|
|
|
newrom="$romdir/${payload1}_${board}_${initmode}_"
|
|
|
|
newrom="$newrom${displaymode}_$keymap.rom"
|
|
|
|
[ "$initmode" = "normal" ] && newrom="$romdir/${payload1}_" \
|
|
|
|
&& newrom="$newrom${board}_${initmode}_$keymap.rom"
|
|
|
|
x_ cprom "$tmpgrubrom" "$newrom"
|
2024-05-27 14:05:33 +00:00
|
|
|
if [ "$payload_seabios_withgrub" = "y" ] && \
|
|
|
|
[ "$payload1" != "grub" ]; then
|
2024-04-28 19:21:35 +00:00
|
|
|
x_ "$cbfstool" "$tmpgrubrom" add \
|
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
|
|
|
-f "$grubdata/bootorder" -n bootorder -t raw
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ cprom "$tmpgrubrom" "${newrom%.rom}_grubfirst.rom"
|
2024-05-27 13:42:16 +00:00
|
|
|
if [ "$payload_seabios_grubonly" = "y" ]; then
|
|
|
|
x_ "$cbfstool" "$tmpgrubrom" add-int -i 0 \
|
|
|
|
-n etc/show-boot-menu
|
|
|
|
x_ cprom "$tmpgrubrom" \
|
|
|
|
"${newrom%.rom}_grubonly.rom"
|
|
|
|
fi
|
2024-04-28 18:56:25 +00:00
|
|
|
fi
|
2024-05-26 00:54:36 +00:00
|
|
|
x_ rm -f "$tmpgrubrom"
|
2023-10-05 02:23:07 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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"
|
2023-12-24 09:04:36 +00:00
|
|
|
x_ "$cbfstool" "$tmprom" add-payload -f "$_seabioself" \
|
2024-05-26 00:54:36 +00:00
|
|
|
-n "$_seabios_cbfs_path" -c lzma
|
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-05-26 00:54:36 +00:00
|
|
|
[ "$initmode" != "libgfxinit" ] || x_ "$cbfstool" "$tmprom" add -f \
|
|
|
|
"$seavgabiosrom" -n vgaroms/seavgabios.bin -t 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"
|
2023-12-24 09:04:36 +00:00
|
|
|
x_ "$cbfstool" "$tmprom" add-payload -f "$_ubootelf" \
|
2024-05-26 00:54:36 +00:00
|
|
|
-n "$_uboot_cbfs_path" -c lzma
|
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 $@
|