nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0444-Add-fw_path-variable-revised.patch

f96e0b
From dfb57206eb4beaa16b99e3dc69221d351b29c7c3 Mon Sep 17 00:00:00 2001
f96e0b
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f96e0b
Date: Wed, 19 Sep 2012 21:22:55 -0300
f96e0b
Subject: [PATCH 444/482] Add fw_path variable (revised)
f96e0b
f96e0b
This patch makes grub look for its config file on efi where the app was
f96e0b
found. It was originally written by Matthew Garrett, and adapted to fix the
f96e0b
"No modules are loaded on grub2 network boot" issue:
f96e0b
f96e0b
https://bugzilla.redhat.com/show_bug.cgi?id=857936
f96e0b
---
f96e0b
 grub-core/kern/main.c   | 16 ++++++++++++++--
f96e0b
 grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
f96e0b
 2 files changed, 38 insertions(+), 3 deletions(-)
f96e0b
f96e0b
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
f96e0b
index 19dc988..8ab7794 100644
f96e0b
--- a/grub-core/kern/main.c
f96e0b
+++ b/grub-core/kern/main.c
f96e0b
@@ -125,6 +125,20 @@ grub_set_prefix_and_root (void)
f96e0b
 
f96e0b
   grub_register_variable_hook ("root", 0, grub_env_write_root);
f96e0b
 
f96e0b
+  grub_machine_get_bootlocation (&fwdevice, &fwpath);
f96e0b
+
f96e0b
+  if (fwdevice && fwpath)
f96e0b
+    {
f96e0b
+      char *fw_path;
f96e0b
+
f96e0b
+      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
f96e0b
+      if (fw_path)
f96e0b
+	{
f96e0b
+	  grub_env_set ("fw_path", fw_path);
f96e0b
+	  grub_free (fw_path);
f96e0b
+	}
f96e0b
+    }
f96e0b
+
f96e0b
   if (prefix)
f96e0b
     {
f96e0b
       char *pptr = NULL;
f96e0b
@@ -142,8 +156,6 @@ grub_set_prefix_and_root (void)
f96e0b
       if (pptr[0])
f96e0b
 	path = grub_strdup (pptr);
f96e0b
     }
f96e0b
-  if ((!device || device[0] == ',' || !device[0]) || !path)
f96e0b
-    grub_machine_get_bootlocation (&fwdevice, &fwpath);
f96e0b
 
f96e0b
   if (!device && fwdevice)
f96e0b
     device = fwdevice;
f96e0b
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
f96e0b
index ffc2cd2..a1d5589 100644
f96e0b
--- a/grub-core/normal/main.c
f96e0b
+++ b/grub-core/normal/main.c
f96e0b
@@ -355,7 +355,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
f96e0b
       /* Guess the config filename. It is necessary to make CONFIG static,
f96e0b
 	 so that it won't get broken by longjmp.  */
f96e0b
       char *config;
f96e0b
-      const char *prefix;
f96e0b
+      const char *prefix, *fw_path;
f96e0b
+
f96e0b
+      fw_path = grub_env_get ("fw_path");
f96e0b
+      if (fw_path)
f96e0b
+	{
f96e0b
+	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
f96e0b
+	  if (config)
f96e0b
+	    {
f96e0b
+	      grub_file_t file;
f96e0b
+
f96e0b
+	      file = grub_file_open (config);
f96e0b
+	      if (file)
f96e0b
+		{
f96e0b
+		  grub_file_close (file);
f96e0b
+		  grub_enter_normal_mode (config);
f96e0b
+		}
f96e0b
+              else
f96e0b
+                {
f96e0b
+                  /*  Ignore all errors.  */
f96e0b
+                  grub_errno = 0;
f96e0b
+                }
f96e0b
+	      grub_free (config);
f96e0b
+	    }
f96e0b
+	}
f96e0b
 
f96e0b
       prefix = grub_env_get ("prefix");
f96e0b
       if (prefix)
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b