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

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