dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0090-Add-fw_path-variable-revised.patch

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