Blob Blame History Raw
From 3198c6026265f42d043e61587579ea590fcd2ad4 Mon Sep 17 00:00:00 2001
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Date: Wed, 19 Sep 2012 21:22:55 -0300
Subject: [PATCH 344/364] Add fw_path variable (revised)

This patch makes grub look for its config file on efi where the app was
found. It was originally written by Matthew Garrett, and adapted to fix the
"No modules are loaded on grub2 network boot" issue:

https://bugzilla.redhat.com/show_bug.cgi?id=857936
---
 grub-core/kern/main.c   | 16 ++++++++++++++--
 grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 19dc988..8ab7794 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -125,6 +125,20 @@ grub_set_prefix_and_root (void)
 
   grub_register_variable_hook ("root", 0, grub_env_write_root);
 
+  grub_machine_get_bootlocation (&fwdevice, &fwpath);
+
+  if (fwdevice && fwpath)
+    {
+      char *fw_path;
+
+      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
+      if (fw_path)
+	{
+	  grub_env_set ("fw_path", fw_path);
+	  grub_free (fw_path);
+	}
+    }
+
   if (prefix)
     {
       char *pptr = NULL;
@@ -142,8 +156,6 @@ grub_set_prefix_and_root (void)
       if (pptr[0])
 	path = grub_strdup (pptr);
     }
-  if ((!device || device[0] == ',' || !device[0]) || !path)
-    grub_machine_get_bootlocation (&fwdevice, &fwpath);
 
   if (!device && fwdevice)
     device = fwdevice;
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 9aaa3b2..ea8cd53 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -346,7 +346,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
       /* Guess the config filename. It is necessary to make CONFIG static,
 	 so that it won't get broken by longjmp.  */
       char *config;
-      const char *prefix;
+      const char *prefix, *fw_path;
+
+      fw_path = grub_env_get ("fw_path");
+      if (fw_path)
+	{
+	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
+	  if (config)
+	    {
+	      grub_file_t file;
+
+	      file = grub_file_open (config);
+	      if (file)
+		{
+		  grub_file_close (file);
+		  grub_enter_normal_mode (config);
+		}
+              else
+                {
+                  /*  Ignore all errors.  */
+                  grub_errno = 0;
+                }
+	      grub_free (config);
+	    }
+	}
 
       prefix = grub_env_get ("prefix");
       if (prefix)
-- 
1.8.1.4