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>
audit2-merge1
Leah Rowe 2024-05-27 20:16:49 +01:00 committed by Leah Rowe
parent 75b6fbf302
commit 935447b035
2 changed files with 31 additions and 26 deletions

View File

@ -50,7 +50,7 @@ if [ -f (cbfsdisk)/timeout.cfg ]; then
else else
set timeout=5 set timeout=5
fi fi
set grub_scan_disk="both" set grub_scan_disk="nvme ahci ata"
if [ -f (cbfsdisk)/scan.cfg ]; then if [ -f (cbfsdisk)/scan.cfg ]; then
source (cbfsdisk)/scan.cfg source (cbfsdisk)/scan.cfg
fi fi
@ -139,15 +139,9 @@ function search_bootcfg {
} }
menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' { menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o' {
if [ "${grub_scan_disk}" != "ata" ]; then for grub_disk in ${grub_scan_disk}; do
search_bootcfg ahci search_bootcfg ${grub_disk}
fi done
if [ "${grub_scan_disk}" != "ahci" ]; then
search_bootcfg ata
fi
if [ "${grub_scan_disk}" != "nvme" ]; then
search_bootcfg nvme
fi
# grub device enumeration is very slow, so checks are hardcoded # grub device enumeration is very slow, so checks are hardcoded
@ -169,22 +163,22 @@ menuentry 'Load Operating System (incl. fully encrypted disks) [o]' --hotkey='o
unset nvmedev unset nvmedev
for i in 11 10 9 8 7 6 5 4 3 2 1 0; do for i in 11 10 9 8 7 6 5 4 3 2 1 0; do
for part in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do for part in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do
if [ "${grub_scan_disk}" != "ata" ]; then for grub_disk in ${grub_scan_disk}; do
ahcidev="(ahci${i},${part}) ${ahcidev}" if [ "${grub_disk}" = "ahci" ]; then
fi ahcidev="(ahci${i},${part}) ${ahcidev}"
if [ "${grub_scan_disk}" != "ahci" ]; then elif [ "${grub_disk}" = "ata" ]; then
atadev="(ata${i},${part}) ${atadev}" atadev="(ata${i},${part}) ${atadev}"
fi elif [ "${grub_disk}" = "nvme" ]; then
if [ "${grub_scan_disk}" != "nvme" ]; then # TODO: do we care about other namesapces
# TODO: do we care about other namesapces nvmedev="(nvme${i}n1,${part}) ${nvmedev}"
nvmedev="(nvme${i}n1,${part}) ${nvmedev}" fi
fi done
done done
done done
set pager=0 set pager=0
echo -n "Attempting to unlock encrypted volumes" echo -n "Attempting to unlock encrypted volumes"
for dev in ${ahcidev} ${atadev} ${nvmedev} ${lvmvol} ${raidvol}; do for dev in ${nvmedev} ${ahcidev} ${atadev} ${lvmvol} ${raidvol}; do
if cryptomount "${dev}" ; then break ; fi if cryptomount "${dev}" ; then break ; fi
done done
set pager=1 set pager=1

View File

@ -150,9 +150,21 @@ configure_target()
# Override the above defaults using target.cfg # Override the above defaults using target.cfg
. "$targetdir/target.cfg" . "$targetdir/target.cfg"
[ -z "$grub_scan_disk" ] && grub_scan_disk="both" [ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
[ "$grub_scan_disk" != "both" ] && [ "$grub_scan_disk" != "ata" ] && \ _ata=""
[ "$grub_scan_disk" != "ahci" ] && grub_scan_disk="both" _ahci=""
_nvme=""
_grub_scan_disk=""
for _disk in $grub_scan_disk; do
[ "$_disk" != "nvme" ] && [ "$_disk" != "ahci" ] && \
[ "$_disk" != "ata" ] && _grub_scan_disk="nvme ahci ata" \
&& break
eval "[ -n \"\$_$_disk\" ] && continue"
eval "_$_disk=\"$_disk\""
_grub_scan_disk="$_grub_scan_disk $_disk"
done
[ -z "$_grub_scan_disk" ] && _grub_scan_disk="nvme ahci ata"
grub_scan_disk="${_grub_scan_disk# }"
[ -z "$tree" ] && $err "$board: tree not defined" [ -z "$tree" ] && $err "$board: tree not defined"
@ -333,8 +345,7 @@ build_grub_roms()
tmpcfg="$(mktemp -t coreboot_rom.XXXXXXXXXX)" tmpcfg="$(mktemp -t coreboot_rom.XXXXXXXXXX)"
printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" > "$tmpcfg" || \ printf "set grub_scan_disk=\"%s\"\n" "$grub_scan_disk" > "$tmpcfg" || \
$err "set grub_scandisk, $grub_scan_disk, $tmpcfg" $err "set grub_scandisk, $grub_scan_disk, $tmpcfg"
[ "$grub_scan_disk" = "both" ] || \ x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
x_ "$cbfstool" "$tmprom" add -f "$tmpcfg" -n scan.cfg -t raw
printf "set timeout=%s\n" "$grub_timeout" > "$tmpcfg" || \ printf "set timeout=%s\n" "$grub_timeout" > "$tmpcfg" || \
$err "set timeout, $grub_timeout, $tmpcfg" $err "set timeout, $grub_timeout, $tmpcfg"
[ -z "$grub_timeout" ] || x_ "$cbfstool" "$tmprom" add \ [ -z "$grub_timeout" ] || x_ "$cbfstool" "$tmprom" add \