[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 02/15] efi/init: Make efi machines load an env block from a va
From: |
Leo Sandoval |
Subject: |
[PATCH v1 02/15] efi/init: Make efi machines load an env block from a variable |
Date: |
Thu, 31 Oct 2024 13:42:45 -0600 |
From: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/Makefile.core.def | 1 +
grub-core/kern/efi/init.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 1571421d7..0bffbfea9 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -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;
diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c
index 6c54af6e7..b5201974a 100644
--- a/grub-core/kern/efi/init.c
+++ b/grub-core/kern/efi/init.c
@@ -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 ();
--
2.46.2
- [PATCH v1 00/15] Fedora Rawhide (non-network) EFI patches, Leo Sandoval, 2024/10/31
- [PATCH v1 01/15] misc: Make "exit" take a return code., Leo Sandoval, 2024/10/31
- [PATCH v1 02/15] efi/init: Make efi machines load an env block from a variable,
Leo Sandoval <=
- [PATCH v1 05/15] efi/api: Add PRIxGRUB_EFI_STATUS and use it., Leo Sandoval, 2024/10/31
- [PATCH v1 10/15] env: Add efi-export-env and efi-load-env commands, Leo Sandoval, 2024/10/31
- [PATCH v1 06/15] efi: don't use int for efi status, Leo Sandoval, 2024/10/31
- [PATCH v1 07/15] grub-install: Don't guess /boot/efi/ as HFS+ on ppc machines in grub-install, Leo Sandoval, 2024/10/31
- [PATCH v1 08/15] misc: align struct efi_variable better..., Leo Sandoval, 2024/10/31
- [PATCH v1 13/15] nx: set the nx compatible flag in EFI grub images, Leo Sandoval, 2024/10/31
- [PATCH v1 11/15] grub-install: disable support for EFI platforms, Leo Sandoval, 2024/10/31
- [PATCH v1 04/15] chainloader: Use grub_efi_...() memory helpers where reasonable., Leo Sandoval, 2024/10/31
- [PATCH v1 03/15] efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers., Leo Sandoval, 2024/10/31
- [PATCH v1 09/15] console: Work around some minor include path weirdnesses, Leo Sandoval, 2024/10/31