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