Blame SOURCES/0214-templates-Check-for-EFI-at-runtime-instead-of-config.patch

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