nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0018-Make-efi-machines-load-an-env-block-from-a-variable.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Mon, 7 Dec 2015 14:20:49 -0500
8631a2
Subject: [PATCH] Make efi machines load an env block from a variable
8631a2
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
---
8631a2
 grub-core/Makefile.core.def |  1 +
8631a2
 grub-core/kern/efi/init.c   | 34 +++++++++++++++++++++++++++++++++-
8631a2
 2 files changed, 34 insertions(+), 1 deletion(-)
8631a2
8631a2
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
b32e65
index e92a7ef32..f80653882 100644
8631a2
--- a/grub-core/Makefile.core.def
8631a2
+++ b/grub-core/Makefile.core.def
8631a2
@@ -191,6 +191,7 @@ kernel = {
8631a2
   efi = term/efi/console.c;
8631a2
   efi = kern/acpi.c;
8631a2
   efi = kern/efi/acpi.c;
8631a2
+  efi = lib/envblk.c;
8631a2
   i386_coreboot = kern/i386/pc/acpi.c;
8631a2
   i386_multiboot = kern/i386/pc/acpi.c;
8631a2
   i386_coreboot = kern/acpi.c;
8631a2
diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c
b32e65
index 3dfdf2d22..71d2279a0 100644
8631a2
--- a/grub-core/kern/efi/init.c
8631a2
+++ b/grub-core/kern/efi/init.c
8631a2
@@ -25,9 +25,40 @@
8631a2
 #include <grub/env.h>
8631a2
 #include <grub/mm.h>
8631a2
 #include <grub/kernel.h>
8631a2
+#include <grub/lib/envblk.h>
8631a2
 
8631a2
 grub_addr_t grub_modbase;
8631a2
 
8631a2
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
8631a2
+  { 0x91376aff, 0xcba6, 0x42be, \
8631a2
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
8631a2
+  }
8631a2
+
8631a2
+/* Helper for grub_efi_env_init */
8631a2
+static int
8631a2
+set_var (const char *name, const char *value,
8631a2
+	 void *whitelist __attribute__((__unused__)))
8631a2
+{
8631a2
+  grub_env_set (name, value);
8631a2
+  return 0;
8631a2
+}
8631a2
+
8631a2
+static void
8631a2
+grub_efi_env_init (void)
8631a2
+{
8631a2
+  grub_efi_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
8631a2
+  struct grub_envblk envblk_s = { NULL, 0 };
8631a2
+  grub_envblk_t envblk = &envblk_s;
8631a2
+
8631a2
+  envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid,
8631a2
+					&envblk_s.size);
8631a2
+  if (!envblk_s.buf || envblk_s.size < 1)
8631a2
+    return;
8631a2
+
8631a2
+  grub_envblk_iterate (envblk, NULL, set_var);
8631a2
+  grub_free (envblk_s.buf);
8631a2
+}
8631a2
+
8631a2
 void
8631a2
 grub_efi_init (void)
8631a2
 {
8631a2
@@ -42,10 +73,11 @@ grub_efi_init (void)
8631a2
   efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
8631a2
 	      0, 0, 0, NULL);
8631a2
 
8631a2
+  grub_efi_env_init ();
8631a2
   grub_efidisk_init ();
8631a2
 }
8631a2
 
8631a2
-void (*grub_efi_net_config) (grub_efi_handle_t hnd, 
8631a2
+void (*grub_efi_net_config) (grub_efi_handle_t hnd,
8631a2
 			     char **device,
8631a2
 			     char **path);
8631a2