dcavalca / rpms / grub2

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