f4c76c
From 5804ce3d46ef5792ea4aa53e1460c341137961e9 Mon Sep 17 00:00:00 2001
f4c76c
From: Peter Jones <pjones@redhat.com>
f4c76c
Date: Thu, 25 Jun 2015 11:59:09 -0400
f4c76c
Subject: [PATCH 2/6] Make efi machines load an env block from a variable
f4c76c
f4c76c
Signed-off-by: Peter Jones <pjones@redhat.com>
f4c76c
---
f4c76c
 grub-core/Makefile.core.def |  1 +
f4c76c
 grub-core/kern/efi/init.c   | 32 ++++++++++++++++++++++++++++++++
f4c76c
 2 files changed, 33 insertions(+)
f4c76c
f4c76c
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f4c76c
index 38291ce..b3ba5ed 100644
f4c76c
--- a/grub-core/Makefile.core.def
f4c76c
+++ b/grub-core/Makefile.core.def
f4c76c
@@ -174,6 +174,7 @@ kernel = {
f4c76c
   efi = kern/efi/init.c;
f4c76c
   efi = kern/efi/mm.c;
f4c76c
   efi = term/efi/console.c;
f4c76c
+  efi = lib/envblk.c;
f4c76c
 
f4c76c
   x86 = kern/i386/tsc.c;
f4c76c
 
f4c76c
diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c
f4c76c
index e9c85de..d17d18e 100644
f4c76c
--- a/grub-core/kern/efi/init.c
f4c76c
+++ b/grub-core/kern/efi/init.c
f4c76c
@@ -25,9 +25,40 @@
f4c76c
 #include <grub env.h="">
f4c76c
 #include <grub mm.h="">
f4c76c
 #include <grub kernel.h="">
f4c76c
+#include <grub lib="" envblk.h="">
f4c76c
 
f4c76c
 grub_addr_t grub_modbase;
f4c76c
 
f4c76c
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
f4c76c
+  { 0x91376aff, 0xcba6, 0x42be, \
f4c76c
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
f4c76c
+  }
f4c76c
+
f4c76c
+/* Helper for grub_efi_env_init */
f4c76c
+static int
f4c76c
+set_var (const char *name, const char *value,
f4c76c
+	 void *whitelist __attribute__((__unused__)))
f4c76c
+{
f4c76c
+  grub_env_set (name, value);
f4c76c
+  return 0;
f4c76c
+}
f4c76c
+
f4c76c
+static void
f4c76c
+grub_efi_env_init (void)
f4c76c
+{
f4c76c
+  grub_efi_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
f4c76c
+  struct grub_envblk envblk_s = { NULL, 0 };
f4c76c
+  grub_envblk_t envblk = &envblk_s;
f4c76c
+
f4c76c
+  envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid,
f4c76c
+					&envblk_s.size);
f4c76c
+  if (!envblk_s.buf || envblk_s.size < 1)
f4c76c
+    return;
f4c76c
+
f4c76c
+  grub_envblk_iterate (envblk, NULL, set_var);
f4c76c
+  grub_free (envblk_s.buf);
f4c76c
+}
f4c76c
+
f4c76c
 void
f4c76c
 grub_efi_init (void)
f4c76c
 {
f4c76c
@@ -42,6 +73,7 @@ grub_efi_init (void)
f4c76c
   efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
f4c76c
 	      0, 0, 0, NULL);
f4c76c
 
f4c76c
+  grub_efi_env_init ();
f4c76c
   grub_efidisk_init ();
f4c76c
 }
f4c76c
 
f4c76c
-- 
f4c76c
2.4.3
f4c76c