nalika / rpms / grub2

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