2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2014-10-27 13:30:50 +00:00
|
|
|
From: Peter Jones <pjones@redhat.com>
|
2019-08-15 06:01:31 +00:00
|
|
|
Date: Tue, 9 Jul 2019 10:35:16 +0200
|
2018-07-10 18:39:10 +00:00
|
|
|
Subject: [PATCH] Try $prefix if $fw_path doesn't work.
|
2014-10-27 13:30:50 +00:00
|
|
|
|
|
|
|
Related: rhbz#1148652
|
|
|
|
|
|
|
|
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
|
---
|
2024-08-01 23:56:47 +00:00
|
|
|
grub-core/kern/ieee1275/init.c | 34 ++++++-----
|
2014-10-27 13:30:50 +00:00
|
|
|
grub-core/net/net.c | 2 +-
|
2021-03-12 21:54:28 +00:00
|
|
|
grub-core/normal/main.c | 134 ++++++++++++++++++++---------------------
|
2024-08-01 23:56:47 +00:00
|
|
|
3 files changed, 85 insertions(+), 85 deletions(-)
|
2014-10-27 13:30:50 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 50c65b2f6e5..51c1e1c9d9f 100644
|
2014-10-27 13:30:50 +00:00
|
|
|
--- a/grub-core/kern/ieee1275/init.c
|
|
|
|
+++ b/grub-core/kern/ieee1275/init.c
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -170,23 +170,25 @@ grub_machine_get_bootlocation (char **device, char **path)
|
2014-10-27 13:30:50 +00:00
|
|
|
grub_free (canon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
- *device = grub_ieee1275_encode_devname (bootpath);
|
2024-08-01 23:56:47 +00:00
|
|
|
+ {
|
2014-10-27 13:30:50 +00:00
|
|
|
+ filename = grub_ieee1275_get_filename (bootpath);
|
|
|
|
+ if (filename)
|
2024-08-01 23:56:47 +00:00
|
|
|
+ {
|
2018-02-27 18:56:41 +00:00
|
|
|
+ char *lastslash = grub_strrchr (filename, '\\');
|
2024-08-01 23:56:47 +00:00
|
|
|
+
|
2014-10-27 13:30:50 +00:00
|
|
|
+ /* Truncate at last directory. */
|
|
|
|
+ if (lastslash)
|
|
|
|
+ {
|
|
|
|
+ *lastslash = '\0';
|
|
|
|
+ grub_translate_ieee1275_path (filename);
|
|
|
|
+
|
|
|
|
+ *path = filename;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ *device = grub_ieee1275_encode_devname (bootpath);
|
2024-08-01 23:56:47 +00:00
|
|
|
+ }
|
2014-10-27 13:30:50 +00:00
|
|
|
+
|
2024-08-01 23:56:47 +00:00
|
|
|
grub_free (type);
|
|
|
|
-
|
|
|
|
- filename = grub_ieee1275_get_filename (bootpath);
|
|
|
|
- if (filename)
|
|
|
|
- {
|
|
|
|
- char *lastslash = grub_strrchr (filename, '\\');
|
|
|
|
-
|
|
|
|
- /* Truncate at last directory. */
|
|
|
|
- if (lastslash)
|
|
|
|
- {
|
|
|
|
- *lastslash = '\0';
|
|
|
|
- grub_translate_ieee1275_path (filename);
|
|
|
|
-
|
|
|
|
- *path = filename;
|
|
|
|
- }
|
|
|
|
- }
|
2014-10-27 13:30:50 +00:00
|
|
|
grub_free (bootpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 8cad4fb6d4d..54451cea2a7 100644
|
2014-10-27 13:30:50 +00:00
|
|
|
--- a/grub-core/net/net.c
|
|
|
|
+++ b/grub-core/net/net.c
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -2005,7 +2005,7 @@ grub_net_search_config_file (char *config)
|
2014-10-27 13:30:50 +00:00
|
|
|
/* Remove the remaining minus sign at the end. */
|
|
|
|
config[config_len] = '\0';
|
|
|
|
|
|
|
|
- return GRUB_ERR_NONE;
|
|
|
|
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct grub_preboot *fini_hnd;
|
|
|
|
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
2024-08-01 23:56:47 +00:00
|
|
|
index 4c89892fa70..3463f444f74 100644
|
2014-10-27 13:30:50 +00:00
|
|
|
--- a/grub-core/normal/main.c
|
|
|
|
+++ b/grub-core/normal/main.c
|
2021-11-04 16:29:49 +00:00
|
|
|
@@ -335,81 +335,79 @@ grub_enter_normal_mode (const char *config)
|
2014-10-27 13:30:50 +00:00
|
|
|
grub_boot_time ("Exiting normal mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
+static grub_err_t
|
|
|
|
+grub_try_normal (const char *variable)
|
|
|
|
+{
|
|
|
|
+ char *config;
|
|
|
|
+ const char *prefix;
|
|
|
|
+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
|
2021-03-12 21:54:28 +00:00
|
|
|
+ const char *net_search_cfg;
|
|
|
|
+ int disable_net_search = 0;
|
2014-10-27 13:30:50 +00:00
|
|
|
+
|
|
|
|
+ prefix = grub_env_get (variable);
|
|
|
|
+ if (!prefix)
|
|
|
|
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
|
+
|
2021-03-12 21:54:28 +00:00
|
|
|
+ net_search_cfg = grub_env_get ("feature_net_search_cfg");
|
|
|
|
+ if (net_search_cfg && net_search_cfg[0] == 'n')
|
|
|
|
+ disable_net_search = 1;
|
|
|
|
+
|
|
|
|
+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
|
|
|
|
+ !disable_net_search)
|
2014-10-27 13:30:50 +00:00
|
|
|
+ {
|
2019-08-15 06:01:31 +00:00
|
|
|
+ grub_size_t config_len;
|
|
|
|
+ config_len = grub_strlen (prefix) +
|
|
|
|
+ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
|
+ config = grub_malloc (config_len);
|
2014-10-27 13:30:50 +00:00
|
|
|
+
|
2019-08-15 06:01:31 +00:00
|
|
|
+ if (! config)
|
|
|
|
+ return GRUB_ERR_FILE_NOT_FOUND;
|
2014-10-27 13:30:50 +00:00
|
|
|
+
|
2019-08-15 06:01:31 +00:00
|
|
|
+ grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
2021-03-12 21:54:28 +00:00
|
|
|
+ err = grub_net_search_config_file (config);
|
2014-10-27 13:30:50 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (err != GRUB_ERR_NONE)
|
|
|
|
+ {
|
2019-08-15 06:01:31 +00:00
|
|
|
+ config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
|
+ if (config)
|
|
|
|
+ {
|
|
|
|
+ grub_file_t file;
|
|
|
|
+ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
|
|
|
|
+ if (file)
|
|
|
|
+ {
|
|
|
|
+ grub_file_close (file);
|
|
|
|
+ err = GRUB_ERR_NONE;
|
|
|
|
+ }
|
|
|
|
+ }
|
2014-10-27 13:30:50 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (err == GRUB_ERR_NONE)
|
|
|
|
+ grub_enter_normal_mode (config);
|
|
|
|
+
|
|
|
|
+ grub_errno = 0;
|
|
|
|
+ grub_free (config);
|
|
|
|
+ return err;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
/* Enter normal mode from rescue mode. */
|
|
|
|
static grub_err_t
|
|
|
|
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
|
int argc, char *argv[])
|
|
|
|
{
|
|
|
|
- if (argc == 0)
|
2018-02-27 18:56:41 +00:00
|
|
|
- {
|
2014-10-27 13:30:50 +00:00
|
|
|
- /* Guess the config filename. It is necessary to make CONFIG static,
|
|
|
|
- so that it won't get broken by longjmp. */
|
|
|
|
- char *config;
|
|
|
|
- const char *prefix;
|
2021-03-12 21:54:28 +00:00
|
|
|
- const char *net_search_cfg;
|
|
|
|
- int disable_net_search = 0;
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
|
|
|
- prefix = grub_env_get ("fw_path");
|
|
|
|
- if (! prefix)
|
|
|
|
- prefix = grub_env_get ("prefix");
|
|
|
|
-
|
2021-03-12 21:54:28 +00:00
|
|
|
- net_search_cfg = grub_env_get ("feature_net_search_cfg");
|
|
|
|
- if (net_search_cfg && net_search_cfg[0] == 'n')
|
|
|
|
- disable_net_search = 1;
|
|
|
|
-
|
2014-10-27 13:30:50 +00:00
|
|
|
- if (prefix)
|
2019-08-15 06:01:31 +00:00
|
|
|
- {
|
2021-03-12 21:54:28 +00:00
|
|
|
- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
|
|
|
|
- !disable_net_search)
|
2019-08-15 06:01:31 +00:00
|
|
|
- {
|
|
|
|
- grub_size_t config_len;
|
|
|
|
- config_len = grub_strlen (prefix) +
|
|
|
|
- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
|
- config = grub_malloc (config_len);
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
2019-08-15 06:01:31 +00:00
|
|
|
- if (! config)
|
|
|
|
- goto quit;
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
2019-08-15 06:01:31 +00:00
|
|
|
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
2019-08-15 06:01:31 +00:00
|
|
|
- grub_net_search_configfile (config);
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
2019-08-15 06:01:31 +00:00
|
|
|
- grub_enter_normal_mode (config);
|
|
|
|
- grub_free (config);
|
|
|
|
- config = NULL;
|
|
|
|
- }
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
2019-08-15 06:01:31 +00:00
|
|
|
- if (!config)
|
|
|
|
- {
|
|
|
|
- config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
|
- if (config)
|
|
|
|
- {
|
|
|
|
- grub_file_t file;
|
2014-10-27 13:30:50 +00:00
|
|
|
-
|
2019-08-15 06:01:31 +00:00
|
|
|
- file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
|
|
|
|
- if (file)
|
|
|
|
- {
|
|
|
|
- grub_file_close (file);
|
|
|
|
- grub_enter_normal_mode (config);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- /* Ignore all errors. */
|
|
|
|
- grub_errno = 0;
|
|
|
|
- }
|
|
|
|
- grub_free (config);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
2014-10-27 13:30:50 +00:00
|
|
|
- else
|
2019-08-15 06:01:31 +00:00
|
|
|
- {
|
|
|
|
- grub_enter_normal_mode (0);
|
|
|
|
- }
|
2018-02-27 18:56:41 +00:00
|
|
|
- }
|
|
|
|
- else
|
|
|
|
+ if (argc)
|
|
|
|
grub_enter_normal_mode (argv[0]);
|
|
|
|
+ else
|
|
|
|
+ {
|
2014-10-27 13:30:50 +00:00
|
|
|
+ /* Guess the config filename. */
|
|
|
|
+ grub_err_t err;
|
|
|
|
+ err = grub_try_normal ("fw_path");
|
|
|
|
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
|
+ err = grub_try_normal ("prefix");
|
|
|
|
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
|
+ grub_enter_normal_mode (0);
|
2018-02-27 18:56:41 +00:00
|
|
|
+ }
|
2014-10-27 13:30:50 +00:00
|
|
|
|
|
|
|
-quit:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|