a5bd9f6
From 3198c6026265f42d043e61587579ea590fcd2ad4 Mon Sep 17 00:00:00 2001
176f649
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
176f649
Date: Wed, 19 Sep 2012 21:22:55 -0300
a5bd9f6
Subject: [PATCH 344/364] Add fw_path variable (revised)
Matthew Garrett 939f590
176f649
This patch makes grub look for its config file on efi where the app was
176f649
found. It was originally written by Matthew Garrett, and adapted to fix the
176f649
"No modules are loaded on grub2 network boot" issue:
176f649
176f649
https://bugzilla.redhat.com/show_bug.cgi?id=857936
Matthew Garrett 939f590
---
a5bd9f6
 grub-core/kern/main.c   | 16 ++++++++++++++--
a5bd9f6
 grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
176f649
 2 files changed, 38 insertions(+), 3 deletions(-)
Matthew Garrett 939f590
Matthew Garrett 939f590
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
a5bd9f6
index 19dc988..8ab7794 100644
Matthew Garrett 939f590
--- a/grub-core/kern/main.c
Matthew Garrett 939f590
+++ b/grub-core/kern/main.c
a5bd9f6
@@ -125,6 +125,20 @@ grub_set_prefix_and_root (void)
Matthew Garrett 939f590
 
Matthew Garrett 939f590
   grub_register_variable_hook ("root", 0, grub_env_write_root);
Matthew Garrett 939f590
 
Matthew Garrett 939f590
+  grub_machine_get_bootlocation (&fwdevice, &fwpath);
Matthew Garrett 939f590
+
Matthew Garrett 939f590
+  if (fwdevice && fwpath)
Matthew Garrett 939f590
+    {
Matthew Garrett 939f590
+      char *fw_path;
Matthew Garrett 939f590
+
bc70a66
+      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
Matthew Garrett 939f590
+      if (fw_path)
Matthew Garrett 939f590
+	{
Matthew Garrett 939f590
+	  grub_env_set ("fw_path", fw_path);
Matthew Garrett 939f590
+	  grub_free (fw_path);
Matthew Garrett 939f590
+	}
Matthew Garrett 939f590
+    }
Matthew Garrett 939f590
+
Matthew Garrett 939f590
   if (prefix)
Matthew Garrett 939f590
     {
Matthew Garrett 939f590
       char *pptr = NULL;
a5bd9f6
@@ -142,8 +156,6 @@ grub_set_prefix_and_root (void)
Matthew Garrett 939f590
       if (pptr[0])
Matthew Garrett 939f590
 	path = grub_strdup (pptr);
Matthew Garrett 939f590
     }
Matthew Garrett 939f590
-  if ((!device || device[0] == ',' || !device[0]) || !path)
Matthew Garrett 939f590
-    grub_machine_get_bootlocation (&fwdevice, &fwpath);
Matthew Garrett 939f590
 
Matthew Garrett 939f590
   if (!device && fwdevice)
Matthew Garrett 939f590
     device = fwdevice;
Matthew Garrett 939f590
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
a5bd9f6
index 9aaa3b2..ea8cd53 100644
Matthew Garrett 939f590
--- a/grub-core/normal/main.c
Matthew Garrett 939f590
+++ b/grub-core/normal/main.c
a5bd9f6
@@ -346,7 +346,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
Matthew Garrett 939f590
       /* Guess the config filename. It is necessary to make CONFIG static,
Matthew Garrett 939f590
 	 so that it won't get broken by longjmp.  */
Matthew Garrett 939f590
       char *config;
Matthew Garrett 939f590
-      const char *prefix;
Matthew Garrett 939f590
+      const char *prefix, *fw_path;
Matthew Garrett 939f590
+
Matthew Garrett 939f590
+      fw_path = grub_env_get ("fw_path");
Matthew Garrett 939f590
+      if (fw_path)
Matthew Garrett 939f590
+	{
Matthew Garrett 939f590
+	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
Matthew Garrett 939f590
+	  if (config)
Matthew Garrett 939f590
+	    {
Matthew Garrett 939f590
+	      grub_file_t file;
Matthew Garrett 939f590
+
Matthew Garrett 939f590
+	      file = grub_file_open (config);
Matthew Garrett 939f590
+	      if (file)
Matthew Garrett 939f590
+		{
Matthew Garrett 939f590
+		  grub_file_close (file);
Matthew Garrett 939f590
+		  grub_enter_normal_mode (config);
Matthew Garrett 939f590
+		}
176f649
+              else
176f649
+                {
176f649
+                  /*  Ignore all errors.  */
176f649
+                  grub_errno = 0;
176f649
+                }
Matthew Garrett 939f590
+	      grub_free (config);
Matthew Garrett 939f590
+	    }
Matthew Garrett 939f590
+	}
Matthew Garrett 939f590
 
Matthew Garrett 939f590
       prefix = grub_env_get ("prefix");
Matthew Garrett 939f590
       if (prefix)
Matthew Garrett 939f590
-- 
a5bd9f6
1.8.1.4
Matthew Garrett 939f590