6b2dd0f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b9efc54
From: Peter Jones <pjones@redhat.com>
b9efc54
Date: Mon, 7 Dec 2015 14:20:49 -0500
31cddd6
Subject: [PATCH] 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 +
46968b6
 grub-core/kern/efi/init.c   | 36 +++++++++++++++++++++++++++++++++++-
46968b6
 2 files changed, 36 insertions(+), 1 deletion(-)
b9efc54
b9efc54
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
e622855
index 45d3edaa4d..c865a08b02 100644
b9efc54
--- a/grub-core/Makefile.core.def
b9efc54
+++ b/grub-core/Makefile.core.def
46968b6
@@ -207,6 +207,7 @@ kernel = {
b9efc54
   efi = kern/efi/acpi.c;
46968b6
   efi = kern/efi/sb.c;
46968b6
   efi = kern/lockdown.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
e622855
index 7facacf09c..6d39bd3ad2 100644
b9efc54
--- a/grub-core/kern/efi/init.c
b9efc54
+++ b/grub-core/kern/efi/init.c
46968b6
@@ -27,8 +27,11 @@
b9efc54
 #include <grub/env.h>
b9efc54
 #include <grub/mm.h>
b9efc54
 #include <grub/kernel.h>
46968b6
+
46968b6
 #include <grub/stack_protector.h>
46968b6
 
b9efc54
+#include <grub/lib/envblk.h>
46968b6
+
46968b6
 #ifdef GRUB_STACK_PROTECTOR
46968b6
 
46968b6
 static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
46968b6
@@ -82,6 +85,36 @@ stack_protector_init (void)
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
+
46968b6
+  grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size,
46968b6
+                         (void **) &envblk_s.buf);
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
 {
46968b6
@@ -108,10 +141,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