Matthew Garrett 939f590
From d829d54d0f461c7bc6a7d8bd549cfdacfac51082 Mon Sep 17 00:00:00 2001
Matthew Garrett 939f590
From: Matthew Garrett <mjg@redhat.com>
Matthew Garrett 939f590
Date: Mon, 21 May 2012 14:36:39 -0400
Matthew Garrett 939f590
Subject: [PATCH] Add fw_path variable
Matthew Garrett 939f590
Matthew Garrett 939f590
---
Matthew Garrett 939f590
 grub-core/kern/main.c   |   16 ++++++++++++++--
Matthew Garrett 939f590
 grub-core/normal/main.c |   20 +++++++++++++++++++-
Matthew Garrett 939f590
 2 files changed, 33 insertions(+), 3 deletions(-)
Matthew Garrett 939f590
Matthew Garrett 939f590
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
Matthew Garrett 939f590
index 185230c..26481c6 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
Matthew Garrett 939f590
index 1963fe4..64c2a9f 100644
Matthew Garrett 939f590
--- a/grub-core/normal/main.c
Matthew Garrett 939f590
+++ b/grub-core/normal/main.c
Matthew Garrett 939f590
@@ -309,7 +309,25 @@ 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
+		}
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
-- 
Matthew Garrett 939f590
1.7.10.2
Matthew Garrett 939f590