dcavalca / rpms / grub2

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