nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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