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

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Peter Jones <pjones@redhat.com>
8e15ce
Date: Mon, 7 Dec 2015 14:20:49 -0500
8e15ce
Subject: [PATCH] Make efi machines load an env block from a variable
8e15ce
8e15ce
Signed-off-by: Peter Jones <pjones@redhat.com>
8e15ce
---
8e15ce
 grub-core/Makefile.core.def |  1 +
8e15ce
 grub-core/kern/efi/init.c   | 36 +++++++++++++++++++++++++++++++++++-
8e15ce
 2 files changed, 36 insertions(+), 1 deletion(-)
8e15ce
8e15ce
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
8e15ce
index 45d3edaa4dc..c865a08b027 100644
8e15ce
--- a/grub-core/Makefile.core.def
8e15ce
+++ b/grub-core/Makefile.core.def
8e15ce
@@ -207,6 +207,7 @@ kernel = {
8e15ce
   efi = kern/efi/acpi.c;
8e15ce
   efi = kern/efi/sb.c;
8e15ce
   efi = kern/lockdown.c;
8e15ce
+  efi = lib/envblk.c;
8e15ce
   i386_coreboot = kern/i386/pc/acpi.c;
8e15ce
   i386_multiboot = kern/i386/pc/acpi.c;
8e15ce
   i386_coreboot = kern/acpi.c;
8e15ce
diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c
8e15ce
index 7facacf09c7..6d39bd3ad29 100644
8e15ce
--- a/grub-core/kern/efi/init.c
8e15ce
+++ b/grub-core/kern/efi/init.c
8e15ce
@@ -27,8 +27,11 @@
8e15ce
 #include <grub/env.h>
8e15ce
 #include <grub/mm.h>
8e15ce
 #include <grub/kernel.h>
8e15ce
+
8e15ce
 #include <grub/stack_protector.h>
8e15ce
 
8e15ce
+#include <grub/lib/envblk.h>
8e15ce
+
8e15ce
 #ifdef GRUB_STACK_PROTECTOR
8e15ce
 
8e15ce
 static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
8e15ce
@@ -82,6 +85,36 @@ stack_protector_init (void)
8e15ce
 
8e15ce
 grub_addr_t grub_modbase;
8e15ce
 
8e15ce
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
8e15ce
+  { 0x91376aff, 0xcba6, 0x42be, \
8e15ce
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
8e15ce
+  }
8e15ce
+
8e15ce
+/* Helper for grub_efi_env_init */
8e15ce
+static int
8e15ce
+set_var (const char *name, const char *value,
8e15ce
+	 void *whitelist __attribute__((__unused__)))
8e15ce
+{
8e15ce
+  grub_env_set (name, value);
8e15ce
+  return 0;
8e15ce
+}
8e15ce
+
8e15ce
+static void
8e15ce
+grub_efi_env_init (void)
8e15ce
+{
8e15ce
+  grub_efi_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
8e15ce
+  struct grub_envblk envblk_s = { NULL, 0 };
8e15ce
+  grub_envblk_t envblk = &envblk_s;
8e15ce
+
8e15ce
+  grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size,
8e15ce
+                         (void **) &envblk_s.buf);
8e15ce
+  if (!envblk_s.buf || envblk_s.size < 1)
8e15ce
+    return;
8e15ce
+
8e15ce
+  grub_envblk_iterate (envblk, NULL, set_var);
8e15ce
+  grub_free (envblk_s.buf);
8e15ce
+}
8e15ce
+
8e15ce
 void
8e15ce
 grub_efi_init (void)
8e15ce
 {
8e15ce
@@ -108,10 +141,11 @@ grub_efi_init (void)
8e15ce
   efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
8e15ce
 	      0, 0, 0, NULL);
8e15ce
 
8e15ce
+  grub_efi_env_init ();
8e15ce
   grub_efidisk_init ();
8e15ce
 }
8e15ce
 
8e15ce
-void (*grub_efi_net_config) (grub_efi_handle_t hnd, 
8e15ce
+void (*grub_efi_net_config) (grub_efi_handle_t hnd,
8e15ce
 			     char **device,
8e15ce
 			     char **path);
8e15ce