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