67f07b7
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
67f07b7
From: Javier Martinez Canillas <javierm@redhat.com>
67f07b7
Date: Tue, 6 Jul 2021 00:38:40 +0200
67f07b7
Subject: [PATCH] templates: Check for EFI at runtime instead of config
67f07b7
 generation time
67f07b7
67f07b7
The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var
67f07b7
exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether
67f07b7
a "fwsetup" menu entry would be added or not to the GRUB menu.
67f07b7
67f07b7
But this has the problem that it will only work if the configuration file
67f07b7
was created on an UEFI machine that supports booting to a firmware UI.
67f07b7
67f07b7
This for example doesn't support creating GRUB config files when executing
67f07b7
on systems that support both UEFI and legacy BIOS booting. Since creating
67f07b7
the config file from legacy BIOS wouldn't allow to access the firmware UI.
67f07b7
67f07b7
To prevent this, make the template to unconditionally create the grub.cfg
67f07b7
snippet but check at runtime if was booted through UEFI to decide if this
67f07b7
entry should be added. That way it won't be added when booting with BIOS.
67f07b7
67f07b7
There's no need to check if EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set,
67f07b7
since that's already done by the "fwsetup" command when is executed.
67f07b7
67f07b7
Resolves: rhbz#1823864
67f07b7
67f07b7
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
67f07b7
---
67f07b7
 util/grub.d/30_uefi-firmware.in | 21 ++++++++-------------
67f07b7
 1 file changed, 8 insertions(+), 13 deletions(-)
67f07b7
67f07b7
diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in
e622855
index d344d3883d..b6041b55e2 100644
67f07b7
--- a/util/grub.d/30_uefi-firmware.in
67f07b7
+++ b/util/grub.d/30_uefi-firmware.in
67f07b7
@@ -26,19 +26,14 @@ export TEXTDOMAINDIR="@localedir@"
67f07b7
 
67f07b7
 . "$pkgdatadir/grub-mkconfig_lib"
67f07b7
 
67f07b7
-EFI_VARS_DIR=/sys/firmware/efi/efivars
67f07b7
-EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c
67f07b7
-OS_INDICATIONS="$EFI_VARS_DIR/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE"
67f07b7
+LABEL="UEFI Firmware Settings"
67f07b7
 
67f07b7
-if [ -e "$OS_INDICATIONS" ] && \
67f07b7
-   [ "$(( $(printf 0x%x \'"$(cat $OS_INDICATIONS | cut -b5)"\') & 1 ))" = 1 ]; then
67f07b7
-  LABEL="UEFI Firmware Settings"
67f07b7
+gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
67f07b7
 
67f07b7
-  gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
67f07b7
-
67f07b7
-  cat << EOF
67f07b7
-menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
67f07b7
-	fwsetup
67f07b7
-}
67f07b7
-EOF
67f07b7
+cat << EOF
67f07b7
+if [ "\$grub_platform" = "efi" ]; then
67f07b7
+	menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
67f07b7
+		fwsetup
67f07b7
+	}
67f07b7
 fi
67f07b7
+EOF