Skip to contentSkip to conversation

Fedora Rawhide (non-network) EFI patches

PATCH In review Leo Sandoval 4 participants 22 messages Oct 31, 2024 – Nov 8, 2024

lore
Share & tools
lore
#0 lore raw

cover Fedora Rawhide (non-network) EFI patches

This series contains non-network related EFI patches taken from Fedora Rawhide [1]. Some of these patches have already being sent [2][3] however, as suggested by Daniel Kiper, to make the review easier, I took only EFI related patches (ignoring those related to networking) from [1][2][3] and create the series. Network EFI related patches will be sent separately.

[1] https://src.fedoraproject.org/rpms/grub2
[2] https://lists.gnu.org/archive/html/grub-devel/2024-10/msg00145.html
[3] https://lists.gnu.org/archive/html/grub-devel/2024-10/msg00192.html

Jan Hlavac (1):
grub-install: disable support for EFI platforms

Leo Sandoval (1):
25_bli.in 30_uefi_firmware.in: load EFI commands inside test
expressions

Marta Lewandowska (1):
grub-install: install on EFI if forced

Peter Jones (11):
misc: Make "exit" take a return code.
efi/init: Make efi machines load an env block from a variable
efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.
chainloader: Use grub_efi_...() memory helpers where reasonable. efi/api: Add PRIxGRUB_EFI_STATUS and use it.
efi: don't use int for efi status
grub-install: Don't guess /boot/efi/ as HFS+ on ppc machines in
grub-install
misc: align struct efi_variable better...
console: Work around some minor include path weirdnesses
env: Add efi-export-env and efi-load-env commands
nx: set the nx compatible flag in EFI grub images

Renaud Métrich (1):
connectefi: new 'connectefi' command

 NEWS                                 |   2 +-
 docs/grub.texi                       |   7 +
 grub-core/Makefile.core.def          |  13 ++
 grub-core/commands/efi/connectefi.c  | 205 +++++++++++++++++++++++++++
 grub-core/commands/efi/env.c         | 170 ++++++++++++++++++++++
 grub-core/commands/efi/lsefi.c       |   1 +
 grub-core/commands/minicmd.c         |  20 ++-
 grub-core/disk/efi/efidisk.c         |  13 ++
 grub-core/kern/efi/efi.c             |  25 +++-
 grub-core/kern/efi/init.c            |  29 ++++
 grub-core/kern/emu/main.c            |   2 +-
 grub-core/kern/emu/misc.c            |   9 +-
 grub-core/kern/i386/coreboot/init.c  |   2 +-
 grub-core/kern/i386/qemu/init.c      |   2 +-
 grub-core/kern/ieee1275/init.c       |   2 +-
 grub-core/kern/mips/arc/init.c       |   2 +-
 grub-core/kern/mips/loongson/init.c  |   2 +-
 grub-core/kern/mips/qemu_mips/init.c |   2 +-
 grub-core/kern/misc.c                |  11 +-
 grub-core/kern/uboot/init.c          |   6 +-
 grub-core/kern/xen/init.c            |   2 +-
 grub-core/lib/envblk.c               |  43 ++++++
 grub-core/loader/efi/chainloader.c   |   4 +-
 include/grub/arm/efi/console.h       |  24 ++++
 include/grub/arm64/efi/console.h     |  24 ++++
 include/grub/efi/api.h               |   9 ++
 include/grub/efi/disk.h              |   2 +
 include/grub/efi/efi.h               |  46 +++++-
 include/grub/efi/pe32.h              |   2 +
 include/grub/efiemu/runtime.h        |   2 +-
 include/grub/i386/efi/console.h      |  24 ++++
 include/grub/lib/envblk.h            |   3 +
 include/grub/misc.h                  |   2 +-
 include/grub/types.h                 |   1 +
 include/grub/x86_64/efi/console.h    |  24 ++++
 util/grub-install.c                  |  39 ++---
 util/grub.d/25_bli.in                |   4 +-
 util/grub.d/30_uefi-firmware.in      |   3 +-
 util/mkimage.c                       |   1 +
 39 files changed, 724 insertions(+), 60 deletions(-)
 create mode 100644 grub-core/commands/efi/connectefi.c
 create mode 100644 grub-core/commands/efi/env.c
 create mode 100644 include/grub/arm/efi/console.h
 create mode 100644 include/grub/arm64/efi/console.h
 create mode 100644 include/grub/i386/efi/console.h
 create mode 100644 include/grub/x86_64/efi/console.h
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH 1/15 misc: Make "exit" take a return code.

From: Peter Jones <[email protected]>

This adds "exit" with a return code. With this patch, any "exit" command /may/ include a return code, and on platforms that support returning with an exit status, we will do so. By default we return the same exit status we did before this patch.

---
 grub-core/commands/minicmd.c         | 20 ++++++++++++++++----
 grub-core/kern/efi/efi.c             |  9 +++++++--
 grub-core/kern/emu/main.c            |  2 +-
 grub-core/kern/emu/misc.c            |  9 +++++----
 grub-core/kern/i386/coreboot/init.c  |  2 +-
 grub-core/kern/i386/qemu/init.c      |  2 +-
 grub-core/kern/ieee1275/init.c       |  2 +-
 grub-core/kern/mips/arc/init.c       |  2 +-
 grub-core/kern/mips/loongson/init.c  |  2 +-
 grub-core/kern/mips/qemu_mips/init.c |  2 +-
 grub-core/kern/misc.c                | 11 ++++++++++-
 grub-core/kern/uboot/init.c          |  6 +++---
 grub-core/kern/xen/init.c            |  2 +-
 include/grub/misc.h                  |  2 +-
 14 files changed, 50 insertions(+), 23 deletions(-)
grub-core/commands/minicmd.c +16 -4
index fa498931e..2bd3ac76f 100644
@@ -182,12 +182,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
 }
 
 /* exit */
-static grub_err_t __attribute__ ((noreturn))
+static grub_err_t
 grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
-		    int argc __attribute__ ((unused)),
-		    char *argv[] __attribute__ ((unused)))
+		    int argc, char *argv[])
 {
-  grub_exit ();
+  int retval = -1;
+  unsigned long n;
+
+  if (argc < 0 || argc > 1)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+
+  if (argc == 1)
+    {
+      n = grub_strtoul (argv[0], 0, 10);
+      if (n != ~0UL)
+	retval = n;
+    }
+
+  grub_exit (retval);
   /* Not reached.  */
 }
 
grub-core/kern/efi/efi.c +7 -2
index b93ae3aba..885d7c642 100644
@@ -175,11 +175,16 @@ grub_reboot (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int retval)
 {
+  int rc = GRUB_EFI_LOAD_ERROR;
+
+  if (retval == 0)
+    rc = GRUB_EFI_SUCCESS;
+
   grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
   grub_efi_system_table->boot_services->exit (grub_efi_image_handle,
-					      GRUB_EFI_SUCCESS, 0, 0);
+					      rc, 0, 0);
   for (;;) ;
 }
 
grub-core/kern/emu/main.c +1 -1
index 855b11c3d..38c1576a2 100644
@@ -67,7 +67,7 @@ grub_reboot (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int retval __attribute__((unused)))
 {
   grub_reboot ();
 }
grub-core/kern/emu/misc.c +5 -4
index 521220b49..16c79bc94 100644
@@ -83,7 +83,7 @@ grub_util_error (const char *fmt, ...)
   vfprintf (stderr, fmt, ap);
   va_end (ap);
   fprintf (stderr, ".\n");
-  grub_exit ();
+  grub_exit (1);
 }
 
 void *
@@ -152,12 +152,13 @@ xasprintf (const char *fmt, ...)
 
 #if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL)
 void
-grub_exit (void)
+__attribute__ ((noreturn))
+grub_exit (int rc)
 {
-#if defined (GRUB_KERNEL)
+#if defined (GRUB_KERNEL) && !defined (GRUB_MACHINE_EFI)
   grub_reboot ();
 #endif
-  exit (1);
+  exit (rc < 0 ? 1 : rc);
 }
 #endif
 
grub-core/kern/i386/coreboot/init.c +1 -1
index 4fae8b571..feaf9295e 100644
@@ -41,7 +41,7 @@ extern grub_uint8_t _end[];
 extern grub_uint8_t _edata[];
 
 void  __attribute__ ((noreturn))
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   /* We can't use grub_fatal() in this function.  This would create an infinite
      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
grub-core/kern/i386/qemu/init.c +1 -1
index 08f81d25e..604fc94b5 100644
@@ -42,7 +42,7 @@ extern grub_uint8_t _end[];
 extern grub_uint8_t _edata[];
 
 void  __attribute__ ((noreturn))
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   /* We can't use grub_fatal() in this function.  This would create an infinite
      loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
grub-core/kern/ieee1275/init.c +1 -1
index fb7d1a3ba..50c65b2f6 100644
@@ -114,7 +114,7 @@ grub_addr_t grub_ieee1275_original_stack;
 #define BYTE22              (DY_MEM_V2 | DRC_INFO)
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   grub_ieee1275_exit ();
 }
grub-core/kern/mips/arc/init.c +1 -1
index 2ed3ff319..5c40c3407 100644
@@ -276,7 +276,7 @@ grub_halt (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   GRUB_ARC_FIRMWARE_VECTOR->exit ();
 
grub-core/kern/mips/loongson/init.c +1 -1
index 5bd721260..97b09b0ee 100644
@@ -304,7 +304,7 @@ grub_halt (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   grub_halt ();
 }
grub-core/kern/mips/qemu_mips/init.c +1 -1
index b5477b87f..69488a34e 100644
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   grub_halt ();
 }
grub-core/kern/misc.c +10 -1
index 7cee5d75c..11037dc02 100644
@@ -1311,9 +1311,18 @@ grub_abort (void)
       grub_getkey ();
     }
 
-  grub_exit ();
+  grub_exit (1);
 }
 
+#if defined (__clang__) && !defined (GRUB_UTIL)
+/* clang emits references to abort().  */
+void __attribute__ ((noreturn))
+abort (void)
+{
+  grub_abort ();
+}
+#endif
+
 void
 grub_fatal (const char *fmt, ...)
 {
grub-core/kern/uboot/init.c +3 -3
index 3e338645c..be2a5be1d 100644
@@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size;
 static unsigned long timer_start;
 
 void
-grub_exit (void)
+grub_exit (int rc)
 {
-  grub_uboot_return (0);
+  grub_uboot_return (rc < 0 ? 1 : rc);
 }
 
 static grub_uint64_t
@@ -78,7 +78,7 @@ grub_machine_init (void)
   if (!ver)
     {
       /* Don't even have a console to log errors to... */
-      grub_exit ();
+      grub_exit (-1);
     }
   else if (ver > API_SIG_VERSION)
     {
grub-core/kern/xen/init.c +1 -1
index 782ca7295..708b060f3 100644
@@ -584,7 +584,7 @@ grub_machine_init (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   struct sched_shutdown arg;
 
include/grub/misc.h +1 -1
index 1b35a167f..72aff1575 100644
@@ -385,7 +385,7 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
      __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
 char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
 
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
 void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
 					  grub_uint64_t d,
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH 2/15 efi/init: Make efi machines load an env block from a variable

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 grub-core/Makefile.core.def |  1 +
 grub-core/kern/efi/init.c   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
grub-core/Makefile.core.def +1 -0
index 1571421d7..0bffbfea9 100644
@@ -219,6 +219,7 @@ kernel = {
   efi = kern/efi/acpi.c;
   efi = kern/efi/sb.c;
   efi = kern/lockdown.c;
+  efi = lib/envblk.c;
   i386_coreboot = kern/i386/pc/acpi.c;
   i386_multiboot = kern/i386/pc/acpi.c;
   i386_coreboot = kern/acpi.c;
grub-core/kern/efi/init.c +34 -0
index 6c54af6e7..b5201974a 100644
@@ -28,8 +28,11 @@
 #include <grub/env.h>
 #include <grub/mm.h>
 #include <grub/kernel.h>
+
 #include <grub/stack_protector.h>
 
+#include <grub/lib/envblk.h>
+
 #ifdef GRUB_STACK_PROTECTOR
 
 static grub_efi_char16_t stack_chk_fail_msg[] =
@@ -103,6 +106,36 @@ stack_protector_init (void)
 
 grub_addr_t grub_modbase;
 
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
+  { 0x91376aff, 0xcba6, 0x42be, \
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
+  }
+
+/* Helper for grub_efi_env_init */
+static int
+set_var (const char *name, const char *value,
+	 void *whitelist __attribute__((__unused__)))
+{
+  grub_env_set (name, value);
+  return 0;
+}
+
+static void
+grub_efi_env_init (void)
+{
+  grub_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
+  struct grub_envblk envblk_s = { NULL, 0 };
+  grub_envblk_t envblk = &envblk_s;
+
+  grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size,
+                         (void **) &envblk_s.buf);
+  if (!envblk_s.buf || envblk_s.size < 1)
+    return;
+
+  grub_envblk_iterate (envblk, NULL, set_var);
+  grub_free (envblk_s.buf);
+}
+
 __attribute__ ((__optimize__ ("-fno-stack-protector"))) void
 grub_efi_init (void)
 {
@@ -128,6 +161,7 @@ grub_efi_init (void)
 
   grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL);
 
+  grub_efi_env_init ();
   grub_efidisk_init ();
 
   grub_efi_register_debug_commands ();
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw

PATCH 3/15 efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 include/grub/efi/efi.h | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
include/grub/efi/efi.h +32 -4
index a5cd99e5a..8d98203a7 100644
@@ -36,6 +36,10 @@ struct linux_arch_kernel_header {
   struct grub_pe_image_header pe_image_header;
 };
 
+/* Variables.  */
+extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
+extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
+
 /* Functions.  */
 void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
 					     void *registration);
@@ -71,6 +75,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size,
 				      grub_efi_uintn_t *descriptor_size,
 				      grub_efi_uint32_t *descriptor_version);
 void grub_efi_memory_fini (void);
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_allocate_pool (grub_efi_memory_type_t pool_type,
+			grub_efi_uintn_t buffer_size,
+			void **buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->allocate_pool(pool_type, buffer_size, buffer);
+  return status;
+}
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_free_pool (void *buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->free_pool(buffer);
+  return status;
+}
+
 grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle);
 void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);
 char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
@@ -140,10 +171,7 @@ void grub_efi_init (void);
 void grub_efi_fini (void);
 void grub_efi_set_prefix (void);
 
-/* Variables.  */
-extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
-extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
-
+/* More variables.  */
 extern int EXPORT_VAR(grub_efi_is_finished);
 
 struct grub_net_card;
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw

PATCH 4/15 chainloader: Use grub_efi_...() memory helpers where reasonable.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we get more reasonable type checking.

---
 grub-core/loader/efi/chainloader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/loader/efi/chainloader.c +2 -2
index 1de98f783..203692450 100644
@@ -95,7 +95,7 @@ grub_chainloader_boot (void *context)
     }
 
   if (exit_data)
-    b->free_pool (exit_data);
+    grub_efi_free_pool (exit_data);
 
   grub_loader_unset ();
 
@@ -419,7 +419,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
   grub_free (file_path);
 
   if (address)
-    b->free_pages (address, pages);
+    grub_efi_free_pages (address, pages);
 
   if (image_handle != NULL)
     b->unload_image (image_handle);
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#5 lore raw

PATCH 5/15 efi/api: Add PRIxGRUB_EFI_STATUS and use it.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

This avoids syntax checkers getting confused about if it's llx or lx.

---
 include/grub/efi/api.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/grub/efi/api.h +9 -0
index d44d00ad7..5f3cd4cc0 100644
@@ -577,7 +577,16 @@ typedef grub_uint64_t grub_efi_uint64_t;
 typedef grub_uint8_t grub_efi_char8_t;
 typedef grub_uint16_t grub_efi_char16_t;
 
+
 typedef grub_efi_uintn_t grub_efi_status_t;
+/* Make grub_efi_status_t reasonably printable. */
+#if GRUB_CPU_SIZEOF_VOID_P == 8
+#define PRIxGRUB_EFI_STATUS "lx"
+#define PRIdGRUB_EFI_STATUS "ld"
+#else
+#define PRIxGRUB_EFI_STATUS "llx"
+#define PRIdGRUB_EFI_STATUS "lld"
+#endif
 
 /*
  * On x86, the EFI calling convention may deviate from the local one, so
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#6 lore raw

PATCH 6/15 efi: don't use int for efi status

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 grub-core/kern/efi/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/efi/efi.c +1 -1
index 885d7c642..2bb8a0e7a 100644
@@ -177,7 +177,7 @@ grub_reboot (void)
 void
 grub_exit (int retval)
 {
-  int rc = GRUB_EFI_LOAD_ERROR;
+  grub_efi_status_t rc = GRUB_EFI_LOAD_ERROR;
 
   if (retval == 0)
     rc = GRUB_EFI_SUCCESS;
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#7 lore raw

PATCH 7/15 grub-install: Don't guess /boot/efi/ as HFS+ on ppc machines in grub-install

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

This should never be trying this, and since we've consolidated the grubenv to always be on /boot/efi/EFI/fedora/, this code causes it to always make the wrong decision.

Resolves: rhbz#1484474

---
 util/grub-install.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
util/grub-install.c +1 -11
index 7dc5657bb..c245d9359 100644
@@ -1229,18 +1229,8 @@ main (int argc, char *argv[])
 	  char *d;
 
 	  is_guess = 1;
-	  d = grub_util_path_concat (2, bootdir, "macppc");
-	  if (!grub_util_is_directory (d))
-	    {
-	      free (d);
-	      d = grub_util_path_concat (2, bootdir, "efi");
-	    }
 	  /* Find the Mac HFS(+) System Partition.  */
-	  if (!grub_util_is_directory (d))
-	    {
-	      free (d);
-	      d = grub_util_path_concat (2, bootdir, "EFI");
-	    }
+	  d = grub_util_path_concat (2, bootdir, "macppc");
 	  if (!grub_util_is_directory (d))
 	    {
 	      free (d);
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#8 lore raw

PATCH 8/15 misc: align struct efi_variable better...

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 include/grub/efiemu/runtime.h | 2 +-
 include/grub/types.h          | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/grub/efiemu/runtime.h +1 -1
index 2ff429845..6363fd522 100644
@@ -33,5 +33,5 @@ struct efi_variable
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
-} GRUB_PACKED;
+} GRUB_PACKED GRUB_ALIGNED(8);
 #endif /* ! GRUB_EFI_EMU_RUNTIME_HEADER */
include/grub/types.h +1 -0
index 064066e2e..59e030268 100644
@@ -30,6 +30,7 @@
 #else
 #define GRUB_PACKED __attribute__ ((packed))
 #endif
+#define GRUB_ALIGNED(x) __attribute__((aligned (x)))
 
 #ifdef GRUB_BUILD
 # define GRUB_CPU_SIZEOF_VOID_P	BUILD_SIZEOF_VOID_P
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#9 lore raw

PATCH 9/15 console: Work around some minor include path weirdnesses

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 include/grub/arm/efi/console.h    | 24 ++++++++++++++++++++++++
 include/grub/arm64/efi/console.h  | 24 ++++++++++++++++++++++++
 include/grub/i386/efi/console.h   | 24 ++++++++++++++++++++++++
 include/grub/x86_64/efi/console.h | 24 ++++++++++++++++++++++++
 4 files changed, 96 insertions(+)
 create mode 100644 include/grub/arm/efi/console.h
 create mode 100644 include/grub/arm64/efi/console.h
 create mode 100644 include/grub/i386/efi/console.h
 create mode 100644 include/grub/x86_64/efi/console.h
include/grub/arm/efi/console.h new file +24 -0
new file mode 100644
index 000000000..1592f6f76
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARM_EFI_CONSOLE_H
+#define GRUB_ARM_EFI_CONSOLE_H
+
+#include <efi/console.h>
+
+#endif /* ! GRUB_ARM_EFI_CONSOLE_H */
include/grub/arm64/efi/console.h new file +24 -0
new file mode 100644
index 000000000..956893393
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARM64_EFI_CONSOLE_H
+#define GRUB_ARM64_EFI_CONSOLE_H
+
+#include <efi/console.h>
+
+#endif /* ! GRUB_ARM64_EFI_CONSOLE_H */
include/grub/i386/efi/console.h new file +24 -0
new file mode 100644
index 000000000..9231375cb
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_I386_EFI_CONSOLE_H
+#define GRUB_I386_EFI_CONSOLE_H
+
+#include <efi/console.h>
+
+#endif /* ! GRUB_I386_EFI_CONSOLE_H */
include/grub/x86_64/efi/console.h new file +24 -0
new file mode 100644
index 000000000..dba9d8678
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_X86_64_EFI_CONSOLE_H
+#define GRUB_X86_64_EFI_CONSOLE_H
+
+#include <efi/console.h>
+
+#endif /* ! GRUB_X86_64_EFI_CONSOLE_H */
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#10 lore raw

PATCH 10/15 env: Add efi-export-env and efi-load-env commands

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

This adds "efi-export-env VARIABLE" and "efi-load-env", which manipulate the environment block stored in the EFI variable GRUB_ENV-91376aff-cba6-42be-949d-06fde81128e8.

---
 grub-core/Makefile.core.def  |   6 ++
 grub-core/commands/efi/env.c | 170 +++++++++++++++++++++++++++++++++++
 grub-core/kern/efi/efi.c     |   3 +
 grub-core/kern/efi/init.c    |   5 --
 grub-core/lib/envblk.c       |  43 +++++++++
 include/grub/efi/efi.h       |   5 ++
 include/grub/lib/envblk.h    |   3 +
 7 files changed, 230 insertions(+), 5 deletions(-)
 create mode 100644 grub-core/commands/efi/env.c
grub-core/Makefile.core.def +6 -0
index 0bffbfea9..f23fd60d2 100644
@@ -825,6 +825,12 @@ module = {
   enable = efi;
 };
 
+module = {
+  name = efienv;
+  common = commands/efi/env.c;
+  enable = efi;
+};
+
 module = {
   name = efifwsetup;
   efi = commands/efi/efifwsetup.c;
grub-core/commands/efi/env.c new file +170 -0

170 lines not on this page · raw message

grub-core/kern/efi/efi.c +3 -0
index 2bb8a0e7a..02a3afcc0 100644
@@ -227,6 +227,9 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,
   if (status == GRUB_EFI_SUCCESS)
     return GRUB_ERR_NONE;
 
+  if (status == GRUB_EFI_NOT_FOUND && datasize == 0)
+    return GRUB_ERR_NONE;
+
   return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
 }
 
grub-core/kern/efi/init.c +0 -5
index b5201974a..dee3918fd 100644
@@ -106,11 +106,6 @@ stack_protector_init (void)
 
 grub_addr_t grub_modbase;
 
-#define GRUB_EFI_GRUB_VARIABLE_GUID \
-  { 0x91376aff, 0xcba6, 0x42be, \
-    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
-  }
-
 /* Helper for grub_efi_env_init */
 static int
 set_var (const char *name, const char *value,
grub-core/lib/envblk.c +43 -0

49 lines not on this page · raw message

include/grub/efi/efi.h +5 -0
index 8d98203a7..6c2c1f36e 100644
@@ -36,6 +36,11 @@ struct linux_arch_kernel_header {
   struct grub_pe_image_header pe_image_header;
 };
 
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
+  { 0x91376aff, 0xcba6, 0x42be, \
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
+  }
+
 /* Variables.  */
 extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
 extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
include/grub/lib/envblk.h +3 -0
index c3e655921..ab969af24 100644
@@ -22,6 +22,8 @@
 #define GRUB_ENVBLK_SIGNATURE	"# GRUB Environment Block\n"
 #define GRUB_ENVBLK_DEFCFG	"grubenv"
 
+#define DEFAULT_ENVBLK_SIZE	1024
+
 #ifndef ASM_FILE
 
 struct grub_envblk
@@ -33,6 +35,7 @@ typedef struct grub_envblk *grub_envblk_t;
 
 grub_envblk_t grub_envblk_open (char *buf, grub_size_t size);
 int grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value);
+grub_err_t grub_envblk_get (grub_envblk_t envblk, const char * const name, char ** const value);
 void grub_envblk_delete (grub_envblk_t envblk, const char *name);
 void grub_envblk_iterate (grub_envblk_t envblk,
                           void *hook_data,
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#11 lore raw

Re: [PATCH v1 10/15] env: Add efi-export-env and efi-load-env commands

Quoted 5 lines · On Thu, 31 Oct 2024 13:42:53 -0600 Leo Sandoval <[email protected]> wrote:

From: Peter Jones <[email protected]>

This adds "efi-export-env VARIABLE" and "efi-load-env", which manipulate the environment block stored in the EFI variable GRUB_ENV-91376aff-cba6-42be-949d-06fde81128e8.

I would prefer that this patch and patch #2 be either dropped or pulled from my patch series "[PATCH v2 0/4] EFI envblk"[1] (the original from over a year ago). I fixed several bugs in the original patches, which I have not checked to see if still exist in these patches. Another reason my series is an improvement is that it adds a patch that adds testing of this feature via QEMU. Please review my series instead of including these patches, so we can get this functionality merged.

The one contention may be the last patch in my series that allow debugging to be enabled as soon as possible (eg. before and config files are read). If that is the case, I can split that patch off from the series in order to get it merged more quickly.

Glenn

[1]
https://lore.kernel.org/grub-devel/[email protected]/

Quoted 320 lines
---
 grub-core/Makefile.core.def  |   6 ++
 grub-core/commands/efi/env.c | 170 +++++++++++++++++++++++++++++++++++
 grub-core/kern/efi/efi.c     |   3 +
 grub-core/kern/efi/init.c    |   5 --
 grub-core/lib/envblk.c       |  43 +++++++++
 include/grub/efi/efi.h       |   5 ++
 include/grub/lib/envblk.h    |   3 +
 7 files changed, 230 insertions(+), 5 deletions(-)
 create mode 100644 grub-core/commands/efi/env.c
grub-core/Makefile.core.def +6 -0
index 0bffbfea9..f23fd60d2 100644
@@ -825,6 +825,12 @@ module = {
   enable = efi;
 };
 
+module = {
+  name = efienv;
+  common = commands/efi/env.c;
+  enable = efi;
+};
+
 module = {
   name = efifwsetup;
   efi = commands/efi/efifwsetup.c;
grub-core/commands/efi/env.c new file +170 -0
new file mode 100644
index 000000000..4080f24fd
@@ -0,0 +1,170 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2012  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <grub/dl.h>
+#include <grub/mm.h>
+#include <grub/misc.h>
+#include <grub/types.h>
+#include <grub/mm.h>
+#include <grub/misc.h>
+#include <grub/efi/api.h>
+#include <grub/efi/efi.h>
+#include <grub/env.h>
+#include <grub/lib/envblk.h>
+#include <grub/command.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static const grub_guid_t grub_env_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
+
+static grub_err_t
+grub_efi_export_env(grub_command_t cmd __attribute__ ((unused)),
+                    int argc, char *argv[])
+{
+  const char *value;
+  char *old_value;
+  struct grub_envblk envblk_s = { NULL, 0 };
+  grub_envblk_t envblk = &envblk_s;
+  grub_err_t err;
+  int changed = 1;
+  grub_efi_status_t status;
+
+  grub_dprintf ("efienv", "argc:%d\n", argc);
+  for (int i = 0; i < argc; i++)
+    grub_dprintf ("efienv", "argv[%d]: %s\n", i, argv[i]);
+
+  if (argc != 1)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable name expected"));
+
+  grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, &envblk_s.size,
+                         (void **) &envblk_s.buf);
+  if (!envblk_s.buf || envblk_s.size < 1)
+    {
+      char *buf = grub_malloc (1025);
+      if (!buf)
+        return grub_errno;
+
+      grub_memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
+      grub_memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
+	      DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
+      buf[1024] = '\0';
+
+      envblk_s.buf = buf;
+      envblk_s.size = 1024;
+    }
+  else
+    {
+      char *buf = grub_realloc (envblk_s.buf, envblk_s.size + 1);
+      if (!buf)
+	return grub_errno;
+
+      envblk_s.buf = buf;
+      envblk_s.buf[envblk_s.size] = '\0';
+    }
+
+  err = grub_envblk_get(envblk, argv[0], &old_value);
+  if (err != GRUB_ERR_NONE)
+    {
+      grub_dprintf ("efienv", "grub_envblk_get returned %d\n", err);
+      return err;
+    }
+
+  value = grub_env_get(argv[0]);
+  if ((!value && !old_value) ||
+      (value && old_value && !grub_strcmp(old_value, value)))
+    changed = 0;
+
+  if (old_value)
+    grub_free(old_value);
+
+  if (changed == 0)
+    {
+      grub_dprintf ("efienv", "No changes necessary\n");
+      return 0;
+    }
+
+  if (value)
+    {
+      grub_dprintf ("efienv", "setting \"%s\" to \"%s\"\n", argv[0], value);
+      grub_envblk_set(envblk, argv[0], value);
+    }
+  else
+    {
+      grub_dprintf ("efienv", "deleting \"%s\" from envblk\n", argv[0]);
+      grub_envblk_delete(envblk, argv[0]);
+    }
+
+  grub_dprintf ("efienv", "envblk is %lu bytes:\n\"%s\"\n", envblk_s.size, envblk_s.buf);
+
+  grub_dprintf ("efienv", "removing GRUB_ENV\n");
+  status = grub_efi_set_variable ("GRUB_ENV", &grub_env_guid, NULL, 0);
+  if (status != GRUB_EFI_SUCCESS)
+    grub_dprintf ("efienv", "removal returned %ld\n", status);
+
+  grub_dprintf ("efienv", "setting GRUB_ENV\n");
+  status = grub_efi_set_variable ("GRUB_ENV", &grub_env_guid,
+				  envblk_s.buf, envblk_s.size);
+  if (status != GRUB_EFI_SUCCESS)
+    grub_dprintf ("efienv", "setting GRUB_ENV returned %ld\n", status);
+
+  return 0;
+}
+
+static int
+set_var (const char *name, const char *value,
+	 void *whitelist __attribute__((__unused__)))
+{
+  grub_env_set (name, value);
+  return 0;
+}
+
+static grub_err_t
+grub_efi_load_env(grub_command_t cmd __attribute__ ((unused)),
+                    int argc, char *argv[] __attribute__((__unused__)))
+{
+  struct grub_envblk envblk_s = { NULL, 0 };
+  grub_envblk_t envblk = &envblk_s;
+
+  grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, &envblk_s.size,
+                         (void **) &envblk_s.buf);
+  if (!envblk_s.buf || envblk_s.size < 1)
+    return 0;
+
+  if (argc > 0)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unexpected argument"));
+
+  grub_envblk_iterate (envblk, NULL, set_var);
+  grub_free (envblk_s.buf);
+
+  return GRUB_ERR_NONE;
+}
+
+static grub_command_t export_cmd, loadenv_cmd;
+
+GRUB_MOD_INIT(lsefi)
+{
+  export_cmd = grub_register_command ("efi-export-env", grub_efi_export_env,
+	    N_("VARIABLE_NAME"), N_("Export environment variable to UEFI."));
+  loadenv_cmd = grub_register_command ("efi-load-env", grub_efi_load_env,
+	    NULL, N_("Load the grub environment from UEFI."));
+}
+
+GRUB_MOD_FINI(lsefi)
+{
+  grub_unregister_command (export_cmd);
+  grub_unregister_command (loadenv_cmd);
+}
grub-core/kern/efi/efi.c +3 -0
index 2bb8a0e7a..02a3afcc0 100644
@@ -227,6 +227,9 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,
   if (status == GRUB_EFI_SUCCESS)
     return GRUB_ERR_NONE;
 
+  if (status == GRUB_EFI_NOT_FOUND && datasize == 0)
+    return GRUB_ERR_NONE;
+
   return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
 }
 
grub-core/kern/efi/init.c +0 -5
index b5201974a..dee3918fd 100644
@@ -106,11 +106,6 @@ stack_protector_init (void)
 
 grub_addr_t grub_modbase;
 
-#define GRUB_EFI_GRUB_VARIABLE_GUID \
-  { 0x91376aff, 0xcba6, 0x42be, \
-    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
-  }
-
 /* Helper for grub_efi_env_init */
 static int
 set_var (const char *name, const char *value,
grub-core/lib/envblk.c +43 -0
index 2e4e78b13..874506da1 100644
@@ -223,6 +223,49 @@ grub_envblk_delete (grub_envblk_t envblk, const char *name)
     }
 }
 
+struct get_var_state {
+  const char * const name;
+  char * value;
+  int found;
+};
+
+static int
+get_var (const char * const name, const char * const value, void *statep)
+{
+  struct get_var_state *state = (struct get_var_state *)statep;
+
+  if (!grub_strcmp(state->name, name))
+    {
+      state->found = 1;
+      state->value = grub_strdup(value);
+      if (!state->value)
+	grub_errno = grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+
+      return 1;
+    }
+
+  return 0;
+}
+
+grub_err_t
+grub_envblk_get (grub_envblk_t envblk, const char * const name, char ** const value)
+{
+  struct get_var_state state = {
+      .name = name,
+      .value = NULL,
+      .found = 0,
+  };
+
+  grub_envblk_iterate(envblk, (void *)&state, get_var);
+
+  *value = state.value;
+
+  if (state.found && !state.value)
+    return grub_errno;
+
+  return GRUB_ERR_NONE;
+}
+
 void
 grub_envblk_iterate (grub_envblk_t envblk,
                      void *hook_data,
include/grub/efi/efi.h +5 -0
index 8d98203a7..6c2c1f36e 100644
@@ -36,6 +36,11 @@ struct linux_arch_kernel_header {
   struct grub_pe_image_header pe_image_header;
 };
 
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
+  { 0x91376aff, 0xcba6, 0x42be, \
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
+  }
+
 /* Variables.  */
 extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
 extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
include/grub/lib/envblk.h +2 -0
index c3e655921..ab969af24 100644
@@ -22,6 +22,8 @@
 #define GRUB_ENVBLK_SIGNATURE	"# GRUB Environment Block\n"
 #define GRUB_ENVBLK_DEFCFG	"grubenv"
 
+#define DEFAULT_ENVBLK_SIZE	1024
+
 #ifndef ASM_FILE
 
 struct grub_envblk

include/grub/lib/envblk.h typedef struct grub_envblk *grub_envblk_t; · line 41

Quoted 7 lines
include/grub/lib/envblk.h +1 -0
@@ -33,6 +35,7 @@ typedef struct grub_envblk *grub_envblk_t;
 
 grub_envblk_t grub_envblk_open (char *buf, grub_size_t size);
 int grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value);
+grub_err_t grub_envblk_get (grub_envblk_t envblk, const char * const name, char ** const value);
 void grub_envblk_delete (grub_envblk_t envblk, const char *name);
 void grub_envblk_iterate (grub_envblk_t envblk,
                           void *hook_data,

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#12 lore raw

PATCH 11/15 grub-install: disable support for EFI platforms

In reply to Leo Sandoval

From: Jan Hlavac <[email protected]>

For each platform, GRUB is shipped as a kernel image and a set of modules. These files are then used by the grub-install utility to install GRUB on a specific device. However, in order to support UEFI Secure Boot, the resulting EFI binary must be signed by a recognized private key. For this reason, for EFI platforms, most distributions also ship prebuilt EFI binaries signed by a distribution-specific private key. In this case, however, the grub-install utility should not be used because it would overwrite the signed EFI binary.

The current fix is suboptimal because it preserves all EFI-related code. A better solution could be to modularize the code and provide a build-time option.

Resolves: rhbz#1737444

[rharwood: drop man page]
---
 docs/grub.texi      |  7 +++++++
 util/grub-install.c | 41 +++++++++++++++++++----------------------
 2 files changed, 26 insertions(+), 22 deletions(-)
docs/grub.texi +7 -0
index a225f9a88..bc9791794 100644
@@ -7080,6 +7080,13 @@ grub-install @var{install_device}
 The device name @var{install_device} is an OS device name or a GRUB
 device name.
 
+In order to support UEFI Secure Boot, the resulting GRUB EFI binary must
+be signed by a recognized private key. For this reason, for EFI
+platforms, most distributions also ship prebuilt GRUB EFI binaries
+signed by a distribution-specific private key. In this case, however,
+@command{grub2-install} should not be used because it would overwrite
+the signed EFI binary.
+
 @command{grub-install} accepts the following options:
 
 @table @option
util/grub-install.c +19 -22

59 lines not on this page · raw message

Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#13 lore raw

Re: [PATCH v1 11/15] grub-install: disable support for EFI platforms

Quoted 110 lines · Leo Sandoval

From: Jan Hlavac <[email protected]>

For each platform, GRUB is shipped as a kernel image and a set of modules. These files are then used by the grub-install utility to install GRUB on a specific device. However, in order to support UEFI Secure Boot, the resulting EFI binary must be signed by a recognized private key. For this reason, for EFI platforms, most distributions also ship prebuilt EFI binaries signed by a distribution-specific private key. In this case, however, the grub-install utility should not be used because it would overwrite the signed EFI binary.

The current fix is suboptimal because it preserves all EFI-related code. A better solution could be to modularize the code and provide a build-time option.

Resolves: rhbz#1737444

[rharwood: drop man page]
---
 docs/grub.texi      |  7 +++++++
 util/grub-install.c | 41 +++++++++++++++++++----------------------
 2 files changed, 26 insertions(+), 22 deletions(-)
docs/grub.texi +7 -0
index a225f9a88..bc9791794 100644
@@ -7080,6 +7080,13 @@ grub-install @var{install_device}
 The device name @var{install_device} is an OS device name or a GRUB
 device name.
 
+In order to support UEFI Secure Boot, the resulting GRUB EFI binary must
+be signed by a recognized private key. For this reason, for EFI
+platforms, most distributions also ship prebuilt GRUB EFI binaries
+signed by a distribution-specific private key. In this case, however,
+@command{grub2-install} should not be used because it would overwrite
+the signed EFI binary.
+
 @command{grub-install} accepts the following options:
 
 @table @option
util/grub-install.c +19 -23
index c245d9359..ee61b042b 100644
@@ -910,6 +910,25 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_ARM_EFI:
+    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_I386_EFI:
+    case GRUB_INSTALL_PLATFORM_IA64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+      is_efi = 1;
+      grub_util_error (_("this utility cannot be used for EFI platforms"
+                         " because it does not support UEFI Secure Boot"));
+      break;
+    default:
+      is_efi = 0;
+      break;
+    }
+
   {
     char *platname = grub_install_get_platform_name (platform);
     fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1024,27 +1043,6 @@ main (int argc, char *argv[])
   grub_hostfs_init ();
   grub_host_init ();
 
-  switch (platform)
-    {
-    case GRUB_INSTALL_PLATFORM_I386_EFI:
-    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-    case GRUB_INSTALL_PLATFORM_IA64_EFI:
-      is_efi = 1;
-      break;
-    default:
-      is_efi = 0;
-      break;
-
-      /* pacify warning.  */
-    case GRUB_INSTALL_PLATFORM_MAX:
-      break;
-    }
-
   switch (platform)
     {
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
@@ -1060,7 +1058,6 @@ main (int argc, char *argv[])
     }
 
   /* Find the EFI System Partition.  */
-
   if (is_efi)
     {
       grub_fs_t fs;
--
Quoted 1 line

2.46.2

This patch should not be upstreamed as-is, since it completely breaks the ability to generate grub-efi binaries on the system with the assumption that pre-existing ones have been shipped by a distributor.

The rework mentioned in the commit message body needs to happen here, because it's unacceptable to just completely break stuff.

Signature · 6 lines
真実はいつも一つ!/ Always, there's only one truth!

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#14 lore raw

Re: [PATCH v1 11/15] grub-install: disable support for EFI platforms

Quoted 35 lines · Neal Gompa
Quoted 33 lines · Leo Sandoval

From: Jan Hlavac <[email protected]>

For each platform, GRUB is shipped as a kernel image and a set of modules. These files are then used by the grub-install utility to install GRUB on a specific device. However, in order to support UEFI Secure Boot, the resulting EFI binary must be signed by a recognized private key. For this reason, for EFI platforms, most distributions also ship prebuilt EFI binaries signed by a distribution-specific private key. In this case, however, the grub-install utility should not be used because it would overwrite the signed EFI binary.

The current fix is suboptimal because it preserves all EFI-related code. A better solution could be to modularize the code and provide a build-time option.

Resolves: rhbz#1737444

[rharwood: drop man page]
---
 docs/grub.texi      |  7 +++++++
 util/grub-install.c | 41 +++++++++++++++++++----------------------
 2 files changed, 26 insertions(+), 22 deletions(-)
docs/grub.texi +0 -0
index a225f9a88..bc9791794 100644
@@ -7080,6 +7080,13 @@ grub-install @var{install_device}
 The device name @var{install_device} is an OS device name or a GRUB
 device name.
 
Quoted 1 line

docs/grub.texi grub-install @var{install_device} · line 7083

Quoted 1 line
docs/grub.texi +1 -0
+In order to support UEFI Secure Boot, the resulting GRUB EFI binary

must

Quoted 17 lines
Quoted 17 lines
docs/grub.texi +6 -0
+be signed by a recognized private key. For this reason, for EFI
+platforms, most distributions also ship prebuilt GRUB EFI binaries
+signed by a distribution-specific private key. In this case, however,
+@command{grub2-install} should not be used because it would overwrite
+the signed EFI binary.
+
 @command{grub-install} accepts the following options:
 
 @table @option
util/grub-install.c +0 -0
index c245d9359..ee61b042b 100644
@@ -910,6 +910,25 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
Quoted 12 lines

util/grub-install.c main (int argc, char *argv[])

Quoted 12 lines
util/grub-install.c +12 -0
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_ARM_EFI:
+    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_I386_EFI:
+    case GRUB_INSTALL_PLATFORM_IA64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+      is_efi = 1;
+      grub_util_error (_("this utility cannot be used for EFI

platforms"

Quoted 1 line

util/grub-install.c main (int argc, char *argv[]) · line 925

Quoted 1 line
util/grub-install.c +1 -0
+                         " because it does not support UEFI Secure

Boot"));

Quoted 40 lines
Quoted 40 lines
util/grub-install.c +6 -21
+      break;
+    default:
+      is_efi = 0;
+      break;
+    }
+
   {
     char *platname = grub_install_get_platform_name (platform);
     fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1024,27 +1043,6 @@ main (int argc, char *argv[])
   grub_hostfs_init ();
   grub_host_init ();
 
-  switch (platform)
-    {
-    case GRUB_INSTALL_PLATFORM_I386_EFI:
-    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-    case GRUB_INSTALL_PLATFORM_IA64_EFI:
-      is_efi = 1;
-      break;
-    default:
-      is_efi = 0;
-      break;
-
-      /* pacify warning.  */
-    case GRUB_INSTALL_PLATFORM_MAX:
-      break;
-    }
-
   switch (platform)
     {
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
@@ -1060,7 +1058,6 @@ main (int argc, char *argv[])
     }
 
Quoted 11 lines
Quoted 7 lines
util/grub-install.c +0 -2
   /* Find the EFI System Partition.  */
-
   if (is_efi)
     {
       grub_fs_t fs;
--

2.46.2

This patch should not be upstreamed as-is, since it completely breaks the ability to generate grub-efi binaries on the system with the assumption that pre-existing ones have been shipped by a distributor.

Right. This one fits nicely on Fedora (and perhaps others distros) thus making this one non-distro
agnostic patch.

Quoted 4 lines

The rework mentioned in the commit message body needs to happen here, because it's unacceptable to just completely break stuff.

For the moment I will drop this patch, pending a better approach as the author/you mentioned.

Quoted 11 lines

--
真実はいつも一つ!/ Always, there's only one truth!

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#15 lore raw

PATCH 12/15 connectefi: new 'connectefi' command

In reply to Leo Sandoval

From: Renaud Métrich <[email protected]>

When efi.quickboot is enabled on VMWare (which is the default for hardware release 16 and later), it may happen that not all EFI devices are connected. Due to this, browsing the devices in make_devices() just fails to find devices, in particular disks or partitions for a given disk.
This typically happens when network booting, then trying to chainload to local disk (this is used in deployment tools such as Red Hat Satellite), which is done through using the following grub.cfg snippet:
-------- 8< ---------------- 8< ---------------- 8< -------- unset prefix
search --file --set=prefix /EFI/redhat/grubx64.efi
if [ -n "$prefix" ]; then
chainloader ($prefix)/EFI/redhat/grubx64/efi
...
-------- 8< ---------------- 8< ---------------- 8< --------

With efi.quickboot, none of the devices are connected, causing "search" to fail. Sometimes devices are connected but not the partition of the disk matching $prefix, causing partition to not be found by "chainloader".

This patch introduces a new "connectefi pciroot|scsi" command which recursively connects all EFI devices starting from a given controller type:
- if 'pciroot' is specified, recursion is performed for all PCI root handles
- if 'scsi' is specified, recursion is performed for all SCSI I/O handles (recommended usage to avoid connecting unwanted handles which may impact Grub performances)

Typical grub.cfg snippet would then be:
-------- 8< ---------------- 8< ---------------- 8< -------- connectefi scsi
unset prefix
search --file --set=prefix /EFI/redhat/grubx64.efi if [ -n "$prefix" ]; then
chainloader ($prefix)/EFI/redhat/grubx64/efi
...
-------- 8< ---------------- 8< ---------------- 8< --------

The code is easily extensible to handle other arguments in the future if needed.

---
 NEWS                                |   2 +-
 grub-core/Makefile.core.def         |   6 +
 grub-core/commands/efi/connectefi.c | 205 ++++++++++++++++++++++++++++
 grub-core/commands/efi/lsefi.c      |   1 +
 grub-core/disk/efi/efidisk.c        |  13 ++
 grub-core/kern/efi/efi.c            |  13 ++
 include/grub/efi/disk.h             |   2 +
 include/grub/efi/efi.h              |   5 +
 8 files changed, 246 insertions(+), 1 deletion(-)
 create mode 100644 grub-core/commands/efi/connectefi.c
NEWS +1 -1
index 310130962..e3cfcd569 100644
@@ -118,7 +118,7 @@ New in 2.02:
   * Prefer pmtimer for TSC calibration.
 
 * New/improved platform support:
-  * New `efifwsetup' and `lsefi' commands on EFI platforms.
+  * New `efifwsetup', `lsefi' and `connectefi` commands on EFI platforms.
   * New `cmosdump' and `cmosset' commands on platforms with CMOS support.
   * New command `pcidump' for PCI platforms.
   * Improve opcode parsing in ACPI halt implementation.
grub-core/Makefile.core.def +6 -0
index f23fd60d2..e19feca3e 100644
@@ -843,6 +843,12 @@ module = {
   enable = efi;
 };
 
+module = {
+  name = connectefi;
+  common = commands/efi/connectefi.c;
+  enable = efi;
+};
+
 module = {
   name = blocklist;
   common = commands/blocklist.c;
grub-core/commands/efi/connectefi.c new file +205 -0

205 lines not on this page · raw message

grub-core/commands/efi/lsefi.c +1 -0
index 7b8316d41..3635cd99b 100644
@@ -19,6 +19,7 @@
 #include <grub/mm.h>
 #include <grub/misc.h>
 #include <grub/efi/api.h>
+#include <grub/efi/disk.h>
 #include <grub/efi/edid.h>
 #include <grub/efi/pci.h>
 #include <grub/efi/efi.h>
grub-core/disk/efi/efidisk.c +13 -0
index 3b5ed5691..525d59838 100644
@@ -396,6 +396,19 @@ enumerate_disks (void)
   free_devices (devices);
 }
 
+void
+grub_efidisk_reenumerate_disks (void)
+{
+  free_devices (fd_devices);
+  free_devices (hd_devices);
+  free_devices (cd_devices);
+  fd_devices = 0;
+  hd_devices = 0;
+  cd_devices = 0;
+
+  enumerate_disks ();
+}
+
 static int
 grub_efidisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
 		      grub_disk_pull_t pull)
grub-core/kern/efi/efi.c +13 -0
index 02a3afcc0..1c0c3ee5f 100644
@@ -96,6 +96,19 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
   return buffer;
 }
 
+grub_efi_status_t
+grub_efi_connect_controller (grub_efi_handle_t controller_handle,
+			     grub_efi_handle_t *driver_image_handle,
+			     grub_efi_device_path_protocol_t *remaining_device_path,
+			     grub_efi_boolean_t recursive)
+{
+  grub_efi_boot_services_t *b;
+
+  b = grub_efi_system_table->boot_services;
+  return b->connect_controller(controller_handle,
+		     driver_image_handle, remaining_device_path, recursive);
+}
+
 void *
 grub_efi_open_protocol (grub_efi_handle_t handle,
 			grub_guid_t *protocol,
include/grub/efi/disk.h +2 -0
index 254475c84..6845c2f1f 100644
@@ -27,6 +27,8 @@ grub_efi_handle_t
 EXPORT_FUNC(grub_efidisk_get_device_handle) (grub_disk_t disk);
 char *EXPORT_FUNC(grub_efidisk_get_device_name) (grub_efi_handle_t *handle);
 
+void EXPORT_FUNC(grub_efidisk_reenumerate_disks) (void);
+
 void grub_efidisk_init (void);
 void grub_efidisk_fini (void);
 
include/grub/efi/efi.h +5 -0
index 6c2c1f36e..736d6f256 100644
@@ -53,6 +53,11 @@ EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type,
 				     grub_guid_t *protocol,
 				     void *search_key,
 				     grub_efi_uintn_t *num_handles);
+grub_efi_status_t
+EXPORT_FUNC(grub_efi_connect_controller) (grub_efi_handle_t controller_handle,
+					  grub_efi_handle_t *driver_image_handle,
+					  grub_efi_device_path_protocol_t *remaining_device_path,
+					  grub_efi_boolean_t recursive);
 void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
 					   grub_guid_t *protocol,
 					   grub_efi_uint32_t attributes);
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#16 lore raw

PATCH 13/15 nx: set the nx compatible flag in EFI grub images

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

For NX, we need the grub binary to announce that it is compatible with the NX feature. This implies that when loading the executable grub image, several attributes are true:

- the binary doesn't need an executable stack
- the binary doesn't need sections to be both executable and writable
- the binary knows how to use the EFI Memory Attributes protocol on code it is loading.

This patch adds a definition for the PE DLL Characteristics flag GRUB_PE32_NX_COMPAT, and changes grub-mkimage to set that flag.

---
 include/grub/efi/pe32.h | 2 ++
 util/mkimage.c          | 1 +
 2 files changed, 3 insertions(+)
include/grub/efi/pe32.h +2 -0
index 4e6e9d254..9887e14b2 100644
@@ -231,6 +231,8 @@ struct grub_pe64_optional_header
 
 #define GRUB_PE32_SUBSYSTEM_EFI_APPLICATION	10
 
+#define GRUB_PE32_NX_COMPAT	0x0100
+
 #define GRUB_PE32_NUM_DATA_DIRECTORIES	16
 
 struct grub_pe32_section_table
util/mkimage.c +1 -0
index 4237383ac..9b4720e21 100644
@@ -1403,6 +1403,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdangling-pointer"
 #endif
+	PE_OHDR (o32, o64, dll_characteristics) = grub_host_to_target16 (GRUB_PE32_NX_COMPAT);
 	PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
 	PE_OHDR (o32, o64, entry_addr) = grub_host_to_target32 (layout.start_address);
 	PE_OHDR (o32, o64, image_base) = 0;
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#17 lore raw

PATCH 14/15 grub-install: install on EFI if forced

In reply to Leo Sandoval

From: Marta Lewandowska <[email protected]>

UEFI Secure Boot requires signed grub binaries to work, so grub- install should not be used. However, users who have Secure Boot disabled and wish to use the command should not be prevented from doing so if they invoke --force.

fixes bz#1917213 / bz#2240994

---
 util/grub-install.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
util/grub-install.c +19 -19
index ee61b042b..b924c2d34 100644
@@ -910,25 +910,6 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
-  switch (platform)
-    {
-    case GRUB_INSTALL_PLATFORM_ARM_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-    case GRUB_INSTALL_PLATFORM_I386_EFI:
-    case GRUB_INSTALL_PLATFORM_IA64_EFI:
-    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-      is_efi = 1;
-      grub_util_error (_("this utility cannot be used for EFI platforms"
-                         " because it does not support UEFI Secure Boot"));
-      break;
-    default:
-      is_efi = 0;
-      break;
-    }
-
   {
     char *platname = grub_install_get_platform_name (platform);
     fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1045,6 +1026,22 @@ main (int argc, char *argv[])
 
   switch (platform)
     {
+    case GRUB_INSTALL_PLATFORM_ARM_EFI:
+    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_I386_EFI:
+    case GRUB_INSTALL_PLATFORM_IA64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+      is_efi = 1;
+      if (!force)
+        grub_util_error (_("This utility should not be used for EFI platforms"
+                          " because it does not support UEFI Secure Boot."
+                          " If you really wish to proceed, invoke the --force"
+                          " option.\nMake sure Secure Boot is disabled before"
+                          " proceeding"));
+      break;
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
 #ifdef __linux__
@@ -1053,6 +1050,9 @@ main (int argc, char *argv[])
         try_open ("/dev/nvram");
 #endif
       break;
+      /* pacify warning.  */
+    case GRUB_INSTALL_PLATFORM_MAX:
+      break;
     default:
       break;
     }
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#18 lore raw

Re: [PATCH v1 14/15] grub-install: install on EFI if forced

Quoted 79 lines · Leo Sandoval

From: Marta Lewandowska <[email protected]>

UEFI Secure Boot requires signed grub binaries to work, so grub- install should not be used. However, users who have Secure Boot disabled and wish to use the command should not be prevented from doing so if they invoke --force.

fixes bz#1917213 / bz#2240994

---
 util/grub-install.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
util/grub-install.c +19 -20
index ee61b042b..b924c2d34 100644
@@ -910,25 +910,6 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
-  switch (platform)
-    {
-    case GRUB_INSTALL_PLATFORM_ARM_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-    case GRUB_INSTALL_PLATFORM_I386_EFI:
-    case GRUB_INSTALL_PLATFORM_IA64_EFI:
-    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-      is_efi = 1;
-      grub_util_error (_("this utility cannot be used for EFI platforms"
-                         " because it does not support UEFI Secure Boot"));
-      break;
-    default:
-      is_efi = 0;
-      break;
-    }
-
   {
     char *platname = grub_install_get_platform_name (platform);
     fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1045,6 +1026,22 @@ main (int argc, char *argv[])
 
   switch (platform)
     {
+    case GRUB_INSTALL_PLATFORM_ARM_EFI:
+    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_I386_EFI:
+    case GRUB_INSTALL_PLATFORM_IA64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+      is_efi = 1;
+      if (!force)
+        grub_util_error (_("This utility should not be used for EFI platforms"
+                          " because it does not support UEFI Secure Boot."
+                          " If you really wish to proceed, invoke the --force"
+                          " option.\nMake sure Secure Boot is disabled before"
+                          " proceeding"));
+      break;
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
 #ifdef __linux__
@@ -1053,6 +1050,9 @@ main (int argc, char *argv[])
         try_open ("/dev/nvram");
 #endif
       break;
+      /* pacify warning.  */
+    case GRUB_INSTALL_PLATFORM_MAX:
+      break;
     default:
       break;
     }
--
Quoted 2 lines

2.46.2

This should be merged with the patch that breaks grub-install for EFI and re-sent as one *new* patch. It's not okay to break it and then fix it in the same patch series, since we don't want broken functionality in a commit applied to git.

Signature · 6 lines
真実はいつも一つ!/ Always, there's only one truth!

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#19 lore raw

Re: [PATCH v1 14/15] grub-install: install on EFI if forced

Quoted 84 lines · Neal Gompa
Quoted 26 lines · Leo Sandoval

From: Marta Lewandowska <[email protected]>

UEFI Secure Boot requires signed grub binaries to work, so grub- install should not be used. However, users who have Secure Boot disabled and wish to use the command should not be prevented from doing so if they invoke --force.

fixes bz#1917213 / bz#2240994

---
 util/grub-install.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
util/grub-install.c +0 -3
index ee61b042b..b924c2d34 100644
@@ -910,25 +910,6 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
-  switch (platform)
-    {
-    case GRUB_INSTALL_PLATFORM_ARM_EFI:

util/grub-install.c main (int argc, char *argv[]) · line 925

Quoted 10 lines
util/grub-install.c +0 -10
-    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-    case GRUB_INSTALL_PLATFORM_I386_EFI:
-    case GRUB_INSTALL_PLATFORM_IA64_EFI:
-    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-      is_efi = 1;
-      grub_util_error (_("this utility cannot be used for EFI platforms"
-                         " because it does not support UEFI Secure

Boot"));

Quoted 14 lines
util/grub-install.c +1 -6
-      break;
-    default:
-      is_efi = 0;
-      break;
-    }
-
   {
     char *platname = grub_install_get_platform_name (platform);
     fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1045,6 +1026,22 @@ main (int argc, char *argv[])
 
   switch (platform)
     {
+    case GRUB_INSTALL_PLATFORM_ARM_EFI:

util/grub-install.c main (int argc, char *argv[]) · line 1039

Quoted 10 lines
util/grub-install.c +10 -0
+    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_I386_EFI:
+    case GRUB_INSTALL_PLATFORM_IA64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+      is_efi = 1;
+      if (!force)
+        grub_util_error (_("This utility should not be used for EFI

platforms"

util/grub-install.c main (int argc, char *argv[]) · line 1040

Quoted 1 line
util/grub-install.c +1 -0
+                          " because it does not support UEFI Secure

Boot."

util/grub-install.c main (int argc, char *argv[]) · line 1041

Quoted 1 line
util/grub-install.c +1 -0
+                          " If you really wish to proceed, invoke the

--force"

util/grub-install.c main (int argc, char *argv[]) · line 1042

Quoted 1 line
util/grub-install.c +1 -0
+                          " option.\nMake sure Secure Boot is disabled

before"

Quoted 15 lines
util/grub-install.c +5 -0
+                          " proceeding"));
+      break;
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
 #ifdef __linux__
@@ -1053,6 +1050,9 @@ main (int argc, char *argv[])
         try_open ("/dev/nvram");
 #endif
       break;
+      /* pacify warning.  */
+    case GRUB_INSTALL_PLATFORM_MAX:
+      break;
     default:
       break;
     }
Quoted 9 lines
Quoted 3 lines

--
2.46.2

This should be merged with the patch that breaks grub-install for EFI and re-sent as one *new* patch. It's not okay to break it and then fix it in the same patch series, since we don't want broken functionality in a commit applied to git.

Partially agree with you and also thought about it, however this is a new feature where a new parameter is included, so at the end I decided to leave both and keep the authorship. Based on the above, I will also drop this one from the series and the reason is that this patch is based on a previous patch that is broken.

Quoted 11 lines

--
真実はいつも一つ!/ Always, there's only one truth!

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#20 lore raw

Re: [PATCH v1 14/15] grub-install: install on EFI if forced

In reply to Neal Gompa
Quoted 79 lines · Neal Gompa
Quoted 78 lines · Leo Sandoval

From: Marta Lewandowska <[email protected]>

UEFI Secure Boot requires signed grub binaries to work, so grub- install should not be used. However, users who have Secure Boot disabled and wish to use the command should not be prevented from doing so if they invoke --force.

fixes bz#1917213 / bz#2240994

---
 util/grub-install.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
util/grub-install.c +19 -19
index ee61b042b..b924c2d34 100644
@@ -910,25 +910,6 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
-  switch (platform)
-    {
-    case GRUB_INSTALL_PLATFORM_ARM_EFI:
-    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-    case GRUB_INSTALL_PLATFORM_I386_EFI:
-    case GRUB_INSTALL_PLATFORM_IA64_EFI:
-    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-      is_efi = 1;
-      grub_util_error (_("this utility cannot be used for EFI platforms"
-                         " because it does not support UEFI Secure Boot"));
-      break;
-    default:
-      is_efi = 0;
-      break;
-    }
-
   {
     char *platname = grub_install_get_platform_name (platform);
     fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1045,6 +1026,22 @@ main (int argc, char *argv[])
 
   switch (platform)
     {
+    case GRUB_INSTALL_PLATFORM_ARM_EFI:
+    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_I386_EFI:
+    case GRUB_INSTALL_PLATFORM_IA64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+    case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+      is_efi = 1;
+      if (!force)
+        grub_util_error (_("This utility should not be used for EFI platforms"
+                          " because it does not support UEFI Secure Boot."
+                          " If you really wish to proceed, invoke the --force"
+                          " option.\nMake sure Secure Boot is disabled before"
+                          " proceeding"));
+      break;
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
 #ifdef __linux__
@@ -1053,6 +1050,9 @@ main (int argc, char *argv[])
         try_open ("/dev/nvram");
 #endif
       break;
+      /* pacify warning.  */
+    case GRUB_INSTALL_PLATFORM_MAX:
+      break;
     default:
       break;
     }
Quoted 8 lines
Quoted 3 lines

--
2.46.2

This should be merged with the patch that breaks grub-install for EFI and re-sent as one *new* patch. It's not okay to break it and then fix it in the same patch series, since we don't want broken functionality in a commit applied to git.

In addition, making mandatory the option --force when Secure Boot is not enabled will need many changes of grub installation handling by many distributions, admins and end users, and lead to a lot of systems unable to boot until done.

Why not instead, in case of Linux systems, check the Secure Boot status of the firmware, for instance querying the NVRAM variable exposed as:
/sys/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c and only if enabled, when running grub-install, display an error or warning?

Didier

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#21 lore raw

PATCH 15/15 25_bli.in 30_uefi_firmware.in: load EFI commands inside test expressions

In reply to Leo Sandoval

These two commands may fail interrumping the normal boot process, so placing these inside test expressions is a safer approach.

Resolves: #2305291

---
 util/grub.d/25_bli.in           | 4 +++-
 util/grub.d/30_uefi-firmware.in | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)
util/grub.d/25_bli.in +3 -1
index 26e27a019..00a8d7159 100644
@@ -19,6 +19,8 @@ set -e
 
 cat << EOF
 if [ "\$grub_platform" = "efi" ]; then
-  insmod bli
+        if [ ! insmod bli ]; then
+                echo "bli module not available"
+        fi
 fi
 EOF
util/grub.d/30_uefi-firmware.in +1 -2
index 1c2365ddb..1ef31e08f 100644
@@ -32,8 +32,7 @@ gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
 
 cat << EOF
 if [ "\$grub_platform" = "efi" ]; then
-	fwsetup --is-supported
-	if [ "\$?" = 0 ]; then
+	if [ fwsetup --is-supported ]; then
 		menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
 			fwsetup
 		}
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel