9d78483
From 40d6b00fa48ae9c1cecf143da5c6061f6ffcb719 Mon Sep 17 00:00:00 2001
9d78483
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
9d78483
Date: Wed, 19 Sep 2012 21:22:55 -0300
9d78483
Subject: [PATCH] Add fw_path variable (revised)
Matthew Garrett 939f590
9d78483
This patch makes grub look for its config file on efi where the app was
9d78483
found. It was originally written by Matthew Garrett, and adapted to fix the
9d78483
"No modules are loaded on grub2 network boot" issue:
9d78483
9d78483
https://bugzilla.redhat.com/show_bug.cgi?id=857936
Matthew Garrett 939f590
---
Matthew Garrett 939f590
 grub-core/kern/main.c   |   16 ++++++++++++++--
9d78483
 grub-core/normal/main.c |   25 ++++++++++++++++++++++++-
9d78483
 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
9d78483
index 3262444..820fd66 100644
Matthew Garrett 939f590
--- a/grub-core/kern/main.c
Matthew Garrett 939f590
+++ b/grub-core/kern/main.c
Matthew Garrett 939f590
@@ -114,6 +114,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;
Matthew Garrett 939f590
@@ -131,8 +145,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
9d78483
index 13473ec..39bb734 100644
Matthew Garrett 939f590
--- a/grub-core/normal/main.c
Matthew Garrett 939f590
+++ b/grub-core/normal/main.c
9d78483
@@ -333,7 +333,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
+		}
9d78483
+              else
9d78483
+                {
9d78483
+                  /*  Ignore all errors.  */
9d78483
+                  grub_errno = 0;
9d78483
+                }
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
-- 
9d78483
1.7.10.4
Matthew Garrett 939f590