nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0184-efi-Print-an-error-if-boot-to-firmware-setup-is-not-.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 01:10:18 +0200
8e15ce
Subject: [PATCH] efi: Print an error if boot to firmware setup is not
8e15ce
 supported
8e15ce
8e15ce
The "fwsetup" command is only registered if the firmware supports booting
8e15ce
to the firmware setup UI. But it could be possible that the GRUB config
8e15ce
already contains a "fwsetup" entry, because it was generated in a machine
8e15ce
that has support for this feature.
8e15ce
8e15ce
To prevent users getting a "can't find command `fwsetup`" error if it is
8e15ce
not supported by the firmware, let's just always register the command but
8e15ce
print a more accurate message if the firmware doesn't support this option.
8e15ce
8e15ce
Resolves: rhbz#1823864
8e15ce
8e15ce
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
8e15ce
---
8e15ce
 grub-core/commands/efi/efifwsetup.c | 43 ++++++++++++++++++++-----------------
8e15ce
 1 file changed, 23 insertions(+), 20 deletions(-)
8e15ce
8e15ce
diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c
b35c50
index eaca032838..328c45e82e 100644
8e15ce
--- a/grub-core/commands/efi/efifwsetup.c
8e15ce
+++ b/grub-core/commands/efi/efifwsetup.c
8e15ce
@@ -27,6 +27,25 @@
8e15ce
 
8e15ce
 GRUB_MOD_LICENSE ("GPLv3+");
8e15ce
 
8e15ce
+static grub_efi_boolean_t
8e15ce
+efifwsetup_is_supported (void)
8e15ce
+{
8e15ce
+  grub_efi_uint64_t *os_indications_supported = NULL;
8e15ce
+  grub_size_t oi_size = 0;
8e15ce
+  grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
8e15ce
+
8e15ce
+  grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
8e15ce
+			 (void **) &os_indications_supported);
8e15ce
+
8e15ce
+  if (!os_indications_supported)
8e15ce
+    return 0;
8e15ce
+
8e15ce
+  if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI)
8e15ce
+    return 1;
8e15ce
+
8e15ce
+  return 0;
8e15ce
+}
8e15ce
+
8e15ce
 static grub_err_t
8e15ce
 grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
8e15ce
 		  int argc __attribute__ ((unused)),
8e15ce
@@ -38,6 +57,10 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
8e15ce
   grub_size_t oi_size;
8e15ce
   grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
8e15ce
 
8e15ce
+  if (!efifwsetup_is_supported ())
8e15ce
+	  return grub_error (GRUB_ERR_INVALID_COMMAND,
8e15ce
+			     N_("Reboot to firmware setup is not supported"));
8e15ce
+
8e15ce
   grub_efi_get_variable ("OsIndications", &global, &oi_size,
8e15ce
 			 (void **) &old_os_indications);
8e15ce
 
8e15ce
@@ -56,28 +79,8 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
8e15ce
 
8e15ce
 static grub_command_t cmd = NULL;
8e15ce
 
8e15ce
-static grub_efi_boolean_t
8e15ce
-efifwsetup_is_supported (void)
8e15ce
-{
8e15ce
-  grub_efi_uint64_t *os_indications_supported = NULL;
8e15ce
-  grub_size_t oi_size = 0;
8e15ce
-  grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
8e15ce
-
8e15ce
-  grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
8e15ce
-			 (void **) &os_indications_supported);
8e15ce
-
8e15ce
-  if (!os_indications_supported)
8e15ce
-    return 0;
8e15ce
-
8e15ce
-  if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI)
8e15ce
-    return 1;
8e15ce
-
8e15ce
-  return 0;
8e15ce
-}
8e15ce
-
8e15ce
 GRUB_MOD_INIT (efifwsetup)
8e15ce
 {
8e15ce
-  if (efifwsetup_is_supported ())
8e15ce
     cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL,
8e15ce
 				 N_("Reboot into firmware setup menu."));
8e15ce