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