nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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