nalika / rpms / grub2

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