|
|
5593c8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5593c8 |
From: Peter Jones <pjones@redhat.com>
|
|
|
5593c8 |
Date: Tue, 9 Jul 2019 10:35:16 +0200
|
|
|
5593c8 |
Subject: [PATCH] Try $prefix if $fw_path doesn't work.
|
|
|
5593c8 |
|
|
|
5593c8 |
Related: rhbz#1148652
|
|
|
5593c8 |
|
|
|
5593c8 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
5593c8 |
---
|
|
|
5593c8 |
grub-core/kern/ieee1275/init.c | 28 +++++----
|
|
|
5593c8 |
grub-core/net/net.c | 2 +-
|
|
|
5593c8 |
grub-core/normal/main.c | 134 ++++++++++++++++++++---------------------
|
|
|
5593c8 |
3 files changed, 82 insertions(+), 82 deletions(-)
|
|
|
5593c8 |
|
|
|
5593c8 |
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
|
|
|
1c6ba0 |
index e71d158416..0cd2a62723 100644
|
|
|
5593c8 |
--- a/grub-core/kern/ieee1275/init.c
|
|
|
5593c8 |
+++ b/grub-core/kern/ieee1275/init.c
|
|
|
5593c8 |
@@ -127,23 +127,25 @@ grub_machine_get_bootlocation (char **device, char **path)
|
|
|
5593c8 |
grub_free (canon);
|
|
|
5593c8 |
}
|
|
|
5593c8 |
else
|
|
|
5593c8 |
- *device = grub_ieee1275_encode_devname (bootpath);
|
|
|
5593c8 |
- grub_free (type);
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- filename = grub_ieee1275_get_filename (bootpath);
|
|
|
5593c8 |
- if (filename)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- char *lastslash = grub_strrchr (filename, '\\');
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- /* Truncate at last directory. */
|
|
|
5593c8 |
- if (lastslash)
|
|
|
5593c8 |
+ filename = grub_ieee1275_get_filename (bootpath);
|
|
|
5593c8 |
+ if (filename)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- *lastslash = '\0';
|
|
|
5593c8 |
- grub_translate_ieee1275_path (filename);
|
|
|
5593c8 |
+ char *lastslash = grub_strrchr (filename, '\\');
|
|
|
5593c8 |
|
|
|
5593c8 |
- *path = filename;
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
+ /* Truncate at last directory. */
|
|
|
5593c8 |
+ if (lastslash)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ *lastslash = '\0';
|
|
|
5593c8 |
+ grub_translate_ieee1275_path (filename);
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ *path = filename;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ *device = grub_ieee1275_encode_devname (bootpath);
|
|
|
5593c8 |
}
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ grub_free (type);
|
|
|
5593c8 |
grub_free (bootpath);
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
|
|
1c6ba0 |
index 4d3eb5c1a5..0ef148f4ad 100644
|
|
|
5593c8 |
--- a/grub-core/net/net.c
|
|
|
5593c8 |
+++ b/grub-core/net/net.c
|
|
|
5593c8 |
@@ -1869,7 +1869,7 @@ grub_net_search_config_file (char *config)
|
|
|
5593c8 |
/* Remove the remaining minus sign at the end. */
|
|
|
5593c8 |
config[config_len] = '\0';
|
|
|
5593c8 |
|
|
|
5593c8 |
- return GRUB_ERR_NONE;
|
|
|
5593c8 |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
static struct grub_preboot *fini_hnd;
|
|
|
5593c8 |
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
|
|
1c6ba0 |
index 1e509fceb9..d5968797f4 100644
|
|
|
5593c8 |
--- a/grub-core/normal/main.c
|
|
|
5593c8 |
+++ b/grub-core/normal/main.c
|
|
|
5593c8 |
@@ -337,81 +337,79 @@ grub_enter_normal_mode (const char *config)
|
|
|
5593c8 |
grub_boot_time ("Exiting normal mode");
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
+static grub_err_t
|
|
|
5593c8 |
+grub_try_normal (const char *variable)
|
|
|
5593c8 |
+{
|
|
|
5593c8 |
+ char *config;
|
|
|
5593c8 |
+ const char *prefix;
|
|
|
5593c8 |
+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
|
|
|
5593c8 |
+ const char *net_search_cfg;
|
|
|
5593c8 |
+ int disable_net_search = 0;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ prefix = grub_env_get (variable);
|
|
|
5593c8 |
+ if (!prefix)
|
|
|
5593c8 |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ net_search_cfg = grub_env_get ("feature_net_search_cfg");
|
|
|
5593c8 |
+ if (net_search_cfg && net_search_cfg[0] == 'n')
|
|
|
5593c8 |
+ disable_net_search = 1;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
|
|
|
5593c8 |
+ !disable_net_search)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ grub_size_t config_len;
|
|
|
5593c8 |
+ config_len = grub_strlen (prefix) +
|
|
|
5593c8 |
+ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
5593c8 |
+ config = grub_malloc (config_len);
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (! config)
|
|
|
5593c8 |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
|
|
5593c8 |
+ err = grub_net_search_config_file (config);
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (err != GRUB_ERR_NONE)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
5593c8 |
+ if (config)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ grub_file_t file;
|
|
|
5593c8 |
+ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
|
|
|
5593c8 |
+ if (file)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ grub_file_close (file);
|
|
|
5593c8 |
+ err = GRUB_ERR_NONE;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (err == GRUB_ERR_NONE)
|
|
|
5593c8 |
+ grub_enter_normal_mode (config);
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ grub_errno = 0;
|
|
|
5593c8 |
+ grub_free (config);
|
|
|
5593c8 |
+ return err;
|
|
|
5593c8 |
+}
|
|
|
5593c8 |
+
|
|
|
5593c8 |
/* Enter normal mode from rescue mode. */
|
|
|
5593c8 |
static grub_err_t
|
|
|
5593c8 |
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
5593c8 |
int argc, char *argv[])
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- if (argc == 0)
|
|
|
5593c8 |
- {
|
|
|
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 *net_search_cfg;
|
|
|
5593c8 |
- int disable_net_search = 0;
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- prefix = grub_env_get ("fw_path");
|
|
|
5593c8 |
- if (! prefix)
|
|
|
5593c8 |
- prefix = grub_env_get ("prefix");
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- net_search_cfg = grub_env_get ("feature_net_search_cfg");
|
|
|
5593c8 |
- if (net_search_cfg && net_search_cfg[0] == 'n')
|
|
|
5593c8 |
- disable_net_search = 1;
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- if (prefix)
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
|
|
|
5593c8 |
- !disable_net_search)
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- grub_size_t config_len;
|
|
|
5593c8 |
- config_len = grub_strlen (prefix) +
|
|
|
5593c8 |
- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
5593c8 |
- config = grub_malloc (config_len);
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- if (! config)
|
|
|
5593c8 |
- goto quit;
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- grub_net_search_configfile (config);
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- grub_enter_normal_mode (config);
|
|
|
5593c8 |
- grub_free (config);
|
|
|
5593c8 |
- config = NULL;
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- if (!config)
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
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 |
- else
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- grub_enter_normal_mode (0);
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
- else
|
|
|
5593c8 |
+ if (argc)
|
|
|
5593c8 |
grub_enter_normal_mode (argv[0]);
|
|
|
5593c8 |
+ else
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ /* Guess the config filename. */
|
|
|
5593c8 |
+ grub_err_t err;
|
|
|
5593c8 |
+ err = grub_try_normal ("fw_path");
|
|
|
5593c8 |
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
5593c8 |
+ err = grub_try_normal ("prefix");
|
|
|
5593c8 |
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
5593c8 |
+ grub_enter_normal_mode (0);
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
|
|
|
5593c8 |
-quit:
|
|
|
5593c8 |
return 0;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|