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

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