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

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