x86_64: Harmonize GRUB's behavior with that of U-Boot

This means that:

- The full boot order is now respected, using the magic "fallback"
  varible in GRUB. This means that if an entry fails to load, we move
  on to the next one in the defined order.

- Netbooting is supported. In this mode, GRUB will acquire an IP
  address using DHCP, after which it downloads an image using TFTP.

- If we run out of valid entries, we always make sure to reboot. This
  ensures that, e.g., a temporary TFTP server outage does not cause an
  Infix device to get stuck in GRUB.

At the moment, the image handling is excruciatingly inefficient when
netbooting, as the image is downloaded multiple times behind the
scenes. Ideally, downloads would be cached, but a quick investigation
indicates that an implementation of this would take more time than we
can spare at the moment. Therefore, we settle for the working, though
wasteful, implementation.
This commit is contained in:
Tobias Waldekranz
2023-04-19 10:47:54 +02:00
committed by Joachim Wiberg
parent b7058b2d6c
commit 09751fdd96
5 changed files with 68 additions and 15 deletions
+55 -11
View File
@@ -1,29 +1,73 @@
set timeout="1"
set default="primary"
set log="loglevel=4"
load_env ORDER DEBUG
if [ -z "$ORDER" ]; then
set ORDER="primary secondary"
fi
set ORDER="$ORDER reboot"
for slot in $ORDER; do
set default="$slot"
break
if [ -z "$default" ]; then
set default="$slot"
else
# Contrary to what the documentation says, GRUB (2.06) does
# not support using titles or IDs in the fallback variable, so
# we translate to indices.
if [ "$slot" = "primary" ]; then
set fallback="$fallback 0"
elif [ "$slot" = "secondary" ]; then
set fallback="$fallback 1"
elif [ "$slot" = "net" ]; then
set fallback="$fallback 2"
elif [ "$slot" = "reboot" ]; then
set fallback="$fallback 3"
fi
fi
done
if [ "$DEBUG" ]; then
set log="debug"
else
set log="loglevel=4"
fi
submenu "primary" "$log" {
set slot="$1"
set append="$2"
set root=(hd0,gpt3)
source /boot/grub/grub.cfg
set slot="$1"
set append="console=ttyS0 root=PARTLABEL=$slot $2"
set root=(hd0,gpt3)
source /boot/grub/grub.cfg
}
submenu "secondary" "$log" {
set slot="$1"
set append="console=ttyS0 root=PARTLABEL=$slot $2"
set root=(hd0,gpt4)
source /boot/grub/grub.cfg
}
submenu "net" "$log" {
net_dhcp
if [ "$net_efinet0_dhcp_next_server" -a "$net_efinet0_dhcp_boot_file" ]; then
set initrd=(tftp,$net_efinet0_dhcp_next_server)/$net_efinet0_dhcp_boot_file
loopback initrd $initrd
set root=(initrd)
set slot="$1"
set append="$2"
set root=(hd0,gpt4)
set append="console=ttyS0 root=/dev/ram ramdisk_size=65536 $2"
source /boot/grub/grub.cfg
else
if [ -z "$net_efinet0_dhcp_next_server" ]; then
echo "No TFTP server supplied in DHCP response"
fi
if [ -z "$net_efinet0_dhcp_boot_file" ]; then
echo "No bootfile supplied in DHCP response"
fi
fi
}
submenu "reboot" {
reboot
}
+4 -2
View File
@@ -1,8 +1,10 @@
# GRUB Environment Block
# WARNING: Do not edit this file by tools other than grub-editenv!!!
ORDER=primary secondary
ORDER=primary secondary net
primary_OK=1
secondary_OK=1
net_OK=1
primary_TRY=0
secondary_TRY=0
################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
net_TRY=0
#########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
+4 -1
View File
@@ -1,3 +1,6 @@
menuentry "Infix" --id infix {
linux /boot/bzImage root=PARTLABEL=$slot rauc.slot=$slot console=ttyS0 $append nokaslr
linux /boot/bzImage rauc.slot=$slot nokaslr $append
if [ "$initrd" ]; then
initrd $initrd
fi
}
+4
View File
@@ -16,3 +16,7 @@ bootname=primary
[slot.rootfs.1]
device=/dev/disk/by-partlabel/secondary
bootname=secondary
[slot.net.0]
device=/dev/ram
bootname=net
+1 -1
View File
@@ -103,7 +103,7 @@ BR2_TARGET_ROOTFS_SQUASHFS=y
BR2_TARGET_EDK2=y
BR2_TARGET_GRUB2=y
BR2_TARGET_GRUB2_X86_64_EFI=y
BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 fat squash4 part_gpt normal efi_gop configfile loadenv test terminfo terminal echo"
BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 squash4 part_gpt normal efi_gop configfile loadenv test echo reboot net efinet tftp loopback"
BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI="${BR2_EXTERNAL_INFIX_PATH}/board/amd64/grub-embed.cfg"
BR2_TARGET_GRUB2_INSTALL_TOOLS=y
BR2_PACKAGE_HOST_DOSFSTOOLS=y