nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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