|
|
d41074 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
a85e8e |
From: Peter Jones <pjones@redhat.com>
|
|
|
a85e8e |
Date: Fri, 3 Oct 2014 11:08:03 -0400
|
|
|
d41074 |
Subject: [PATCH] Try $prefix if $fw_path doesn't work.
|
|
|
a85e8e |
|
|
|
a85e8e |
Related: rhbz#1148652
|
|
|
a85e8e |
|
|
|
a85e8e |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
a85e8e |
---
|
|
|
d41074 |
grub-core/kern/ieee1275/init.c | 28 +++++-----
|
|
|
a85e8e |
grub-core/net/net.c | 2 +-
|
|
|
d41074 |
grub-core/normal/main.c | 120 ++++++++++++++++++++---------------------
|
|
|
a85e8e |
3 files changed, 75 insertions(+), 75 deletions(-)
|
|
|
a85e8e |
|
|
|
a85e8e |
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
|
|
|
d41074 |
index 8191f8cd658..8ca4bf79f09 100644
|
|
|
a85e8e |
--- a/grub-core/kern/ieee1275/init.c
|
|
|
a85e8e |
+++ b/grub-core/kern/ieee1275/init.c
|
|
|
a85e8e |
@@ -131,23 +131,25 @@ grub_machine_get_bootlocation (char **device, char **path)
|
|
|
a85e8e |
grub_free (canon);
|
|
|
a85e8e |
}
|
|
|
a85e8e |
else
|
|
|
a85e8e |
- *device = grub_ieee1275_encode_devname (bootpath);
|
|
|
a85e8e |
- grub_free (type);
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- filename = grub_ieee1275_get_filename (bootpath);
|
|
|
a85e8e |
- if (filename)
|
|
|
a85e8e |
{
|
|
|
a85e8e |
- char *lastslash = grub_strrchr (filename, '\\');
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- /* Truncate at last directory. */
|
|
|
a85e8e |
- if (lastslash)
|
|
|
a85e8e |
+ filename = grub_ieee1275_get_filename (bootpath);
|
|
|
a85e8e |
+ if (filename)
|
|
|
a85e8e |
{
|
|
|
a85e8e |
- *lastslash = '\0';
|
|
|
a85e8e |
- grub_translate_ieee1275_path (filename);
|
|
|
d41074 |
+ char *lastslash = grub_strrchr (filename, '\\');
|
|
|
d41074 |
|
|
|
a85e8e |
- *path = filename;
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
+ /* Truncate at last directory. */
|
|
|
a85e8e |
+ if (lastslash)
|
|
|
a85e8e |
+ {
|
|
|
a85e8e |
+ *lastslash = '\0';
|
|
|
a85e8e |
+ grub_translate_ieee1275_path (filename);
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ *path = filename;
|
|
|
a85e8e |
+ }
|
|
|
a85e8e |
+ }
|
|
|
a85e8e |
+ *device = grub_ieee1275_encode_devname (bootpath);
|
|
|
a85e8e |
}
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ grub_free (type);
|
|
|
a85e8e |
grub_free (bootpath);
|
|
|
a85e8e |
}
|
|
|
a85e8e |
|
|
|
a85e8e |
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
|
|
d41074 |
index 578e057e18f..10bfed31b2b 100644
|
|
|
a85e8e |
--- a/grub-core/net/net.c
|
|
|
a85e8e |
+++ b/grub-core/net/net.c
|
|
|
a85e8e |
@@ -1817,7 +1817,7 @@ grub_net_search_configfile (char *config)
|
|
|
a85e8e |
/* Remove the remaining minus sign at the end. */
|
|
|
a85e8e |
config[config_len] = '\0';
|
|
|
a85e8e |
|
|
|
a85e8e |
- return GRUB_ERR_NONE;
|
|
|
a85e8e |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
a85e8e |
}
|
|
|
a85e8e |
|
|
|
a85e8e |
static struct grub_preboot *fini_hnd;
|
|
|
a85e8e |
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
|
|
d41074 |
index 4190985ad37..aa14499996b 100644
|
|
|
a85e8e |
--- a/grub-core/normal/main.c
|
|
|
a85e8e |
+++ b/grub-core/normal/main.c
|
|
|
a85e8e |
@@ -331,74 +331,72 @@ grub_enter_normal_mode (const char *config)
|
|
|
a85e8e |
grub_boot_time ("Exiting normal mode");
|
|
|
a85e8e |
}
|
|
|
a85e8e |
|
|
|
a85e8e |
+static grub_err_t
|
|
|
a85e8e |
+grub_try_normal (const char *variable)
|
|
|
a85e8e |
+{
|
|
|
a85e8e |
+ char *config;
|
|
|
a85e8e |
+ const char *prefix;
|
|
|
a85e8e |
+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ prefix = grub_env_get (variable);
|
|
|
a85e8e |
+ if (!prefix)
|
|
|
a85e8e |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
|
|
|
a85e8e |
+ {
|
|
|
a85e8e |
+ grub_size_t config_len;
|
|
|
a85e8e |
+ config_len = grub_strlen (prefix) +
|
|
|
a85e8e |
+ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
a85e8e |
+ config = grub_malloc (config_len);
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ if (! config)
|
|
|
a85e8e |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
|
|
a85e8e |
+ err = grub_net_search_configfile (config);
|
|
|
a85e8e |
+ }
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ if (err != GRUB_ERR_NONE)
|
|
|
a85e8e |
+ {
|
|
|
a85e8e |
+ config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
a85e8e |
+ if (config)
|
|
|
a85e8e |
+ {
|
|
|
a85e8e |
+ grub_file_t file;
|
|
|
a85e8e |
+ file = grub_file_open (config);
|
|
|
a85e8e |
+ if (file)
|
|
|
a85e8e |
+ {
|
|
|
a85e8e |
+ grub_file_close (file);
|
|
|
a85e8e |
+ err = GRUB_ERR_NONE;
|
|
|
a85e8e |
+ }
|
|
|
a85e8e |
+ }
|
|
|
a85e8e |
+ }
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ if (err == GRUB_ERR_NONE)
|
|
|
a85e8e |
+ grub_enter_normal_mode (config);
|
|
|
a85e8e |
+
|
|
|
a85e8e |
+ grub_errno = 0;
|
|
|
a85e8e |
+ grub_free (config);
|
|
|
a85e8e |
+ return err;
|
|
|
a85e8e |
+}
|
|
|
a85e8e |
+
|
|
|
a85e8e |
/* Enter normal mode from rescue mode. */
|
|
|
a85e8e |
static grub_err_t
|
|
|
a85e8e |
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
a85e8e |
int argc, char *argv[])
|
|
|
a85e8e |
{
|
|
|
a85e8e |
- if (argc == 0)
|
|
|
d41074 |
- {
|
|
|
a85e8e |
- /* Guess the config filename. It is necessary to make CONFIG static,
|
|
|
a85e8e |
- so that it won't get broken by longjmp. */
|
|
|
a85e8e |
- char *config;
|
|
|
a85e8e |
- const char *prefix;
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- prefix = grub_env_get ("fw_path");
|
|
|
a85e8e |
- if (! prefix)
|
|
|
a85e8e |
- prefix = grub_env_get ("prefix");
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- if (prefix)
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- grub_size_t config_len;
|
|
|
a85e8e |
- config_len = grub_strlen (prefix) +
|
|
|
a85e8e |
- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
a85e8e |
- config = grub_malloc (config_len);
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- if (! config)
|
|
|
a85e8e |
- goto quit;
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- grub_net_search_configfile (config);
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- grub_enter_normal_mode (config);
|
|
|
a85e8e |
- grub_free (config);
|
|
|
a85e8e |
- config = NULL;
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- if (!config)
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
a85e8e |
- if (config)
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- grub_file_t file;
|
|
|
a85e8e |
-
|
|
|
a85e8e |
- file = grub_file_open (config);
|
|
|
a85e8e |
- if (file)
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- grub_file_close (file);
|
|
|
a85e8e |
- grub_enter_normal_mode (config);
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
- else
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- /* Ignore all errors. */
|
|
|
a85e8e |
- grub_errno = 0;
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
- grub_free (config);
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
- }
|
|
|
a85e8e |
- else
|
|
|
a85e8e |
- {
|
|
|
a85e8e |
- grub_enter_normal_mode (0);
|
|
|
a85e8e |
- }
|
|
|
d41074 |
- }
|
|
|
d41074 |
- else
|
|
|
d41074 |
+ if (argc)
|
|
|
d41074 |
grub_enter_normal_mode (argv[0]);
|
|
|
d41074 |
+ else
|
|
|
d41074 |
+ {
|
|
|
a85e8e |
+ /* Guess the config filename. */
|
|
|
a85e8e |
+ grub_err_t err;
|
|
|
a85e8e |
+ err = grub_try_normal ("fw_path");
|
|
|
a85e8e |
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
a85e8e |
+ err = grub_try_normal ("prefix");
|
|
|
a85e8e |
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
a85e8e |
+ grub_enter_normal_mode (0);
|
|
|
d41074 |
+ }
|
|
|
a85e8e |
|
|
|
a85e8e |
-quit:
|
|
|
a85e8e |
return 0;
|
|
|
a85e8e |
}
|
|
|
a85e8e |
|