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