[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 15/20] Try mac/guid/etc before grub.cfg on tftp config files
From: |
Robbie Harwood |
Subject: |
[PATCH v5 15/20] Try mac/guid/etc before grub.cfg on tftp config files |
Date: |
Tue, 25 Apr 2023 11:05:26 -0400 |
From: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
grub-core/kern/ieee1275/init.c | 28 +++----
grub-core/net/net.c | 2 +-
grub-core/normal/main.c | 129 +++++++++++++++++----------------
3 files changed, 82 insertions(+), 77 deletions(-)
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
index bd9a4804bc..2e8b695e56 100644
--- a/grub-core/kern/ieee1275/init.c
+++ b/grub-core/kern/ieee1275/init.c
@@ -165,23 +165,25 @@ grub_machine_get_bootlocation (char **device, char **path)
grub_free (canon);
}
else
- *device = grub_ieee1275_encode_devname (bootpath);
- grub_free (type);
-
- filename = grub_ieee1275_get_filename (bootpath);
- if (filename)
{
- char *lastslash = grub_strrchr (filename, '\\');
-
- /* Truncate at last directory. */
- if (lastslash)
+ filename = grub_ieee1275_get_filename (bootpath);
+ if (filename)
{
- *lastslash = '\0';
- grub_translate_ieee1275_path (filename);
+ char *lastslash = grub_strrchr (filename, '\\');
- *path = filename;
- }
+ /* Truncate at last directory. */
+ if (lastslash)
+ {
+ *lastslash = '\0';
+ grub_translate_ieee1275_path (filename);
+
+ *path = filename;
+ }
+ }
+ *device = grub_ieee1275_encode_devname (bootpath);
}
+
+ grub_free (type);
grub_free (bootpath);
}
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 38754a94f6..83e9f92573 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -2073,7 +2073,7 @@ grub_net_search_config_file (char *config)
/* 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
index dfdfd56e06..58d3dcee8d 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -310,76 +310,79 @@ grub_enter_normal_mode (const char *config)
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;
+ const char *net_search_cfg;
+ int disable_net_search = 0;
+
+ prefix = grub_env_get (variable);
+ if (!prefix)
+ return GRUB_ERR_FILE_NOT_FOUND;
+
+ 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)
+ {
+ grub_size_t config_len;
+ config_len = grub_strlen (prefix) +
+ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
+ config = grub_malloc (config_len);
+
+ if (! config)
+ return GRUB_ERR_FILE_NOT_FOUND;
+
+ grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
+ err = grub_net_search_config_file (config);
+ }
+
+ if (err != GRUB_ERR_NONE)
+ {
+ 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;
+ }
+ }
+ }
+
+ 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)
- {
- /* 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, *fw_path;
-
- prefix = fw_path = grub_env_get ("fw_path");
- if (fw_path)
- {
- config = grub_xasprintf ("%s/grub.cfg", fw_path);
- if (config)
- {
- grub_file_t file;
-
- 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);
- }
- }
-
- if (!prefix)
- prefix = grub_env_get ("prefix");
- if (prefix)
- {
- grub_size_t config_len;
- int disable_net_search = 0;
- const char *net_search_cfg;
-
- config_len = grub_strlen (prefix) +
- sizeof
("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
- config = grub_malloc (config_len);
-
- if (!config)
- goto quit;
-
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
-
- 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)
- grub_net_search_config_file (config);
-
- grub_enter_normal_mode (config);
- grub_free (config);
- }
- else
- grub_enter_normal_mode (0);
- }
- else
+ if (argc)
grub_enter_normal_mode (argv[0]);
+ else
+ {
+ /* 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);
+ }
-quit:
return 0;
}
--
2.40.0
- [PATCH v5 04/20] efinet + bootp: add net_bootp6 command supporting dhcpv6, (continued)
- [PATCH v5 04/20] efinet + bootp: add net_bootp6 command supporting dhcpv6, Robbie Harwood, 2023/04/25
- [PATCH v5 01/20] Revert "net/http: Allow use of non-standard TCP/IP ports", Robbie Harwood, 2023/04/25
- [PATCH v5 13/20] Add fw_path variable to detect config file on efi, Robbie Harwood, 2023/04/25
- [PATCH v5 19/20] normal/main: Discover the device to read the config from as a fallback, Robbie Harwood, 2023/04/25
- [PATCH v5 10/20] Support UEFI networking protocols, Robbie Harwood, 2023/04/25
- [PATCH v5 03/20] net/http: check result of grub_netbuff_put() in http_receive(), Robbie Harwood, 2023/04/25
- [PATCH v5 16/20] Prepend prefix when HTTP path is relative, Robbie Harwood, 2023/04/25
- [PATCH v5 11/20] efinet: also use the firmware acceleration for http, Robbie Harwood, 2023/04/25
- [PATCH v5 08/20] efinet Configure network from UEFI device path, Robbie Harwood, 2023/04/25
- [PATCH v5 06/20] grub.texi: Add net_bootp6 doumentation, Robbie Harwood, 2023/04/25
- [PATCH v5 15/20] Try mac/guid/etc before grub.cfg on tftp config files,
Robbie Harwood <=
- [PATCH v5 20/20] efinet: Add DHCP proxy support, Robbie Harwood, 2023/04/25
- [PATCH v5 05/20] efinet: add structures for PXE messages, Robbie Harwood, 2023/04/25
- [PATCH v5 18/20] http: Prepend prefix when the HTTP path is relative, Robbie Harwood, 2023/04/25
- [PATCH v5 07/20] bootp: Process DHCPACK packet during HTTP Boot, Robbie Harwood, 2023/04/25
- [PATCH v5 09/20] efinet: set DNS server from UEFI protocol, Robbie Harwood, 2023/04/25
- [PATCH v5 02/20] net: read bracketed ipv6 addrs and port numbers, Robbie Harwood, 2023/04/25
- [PATCH v5 17/20] efi/http: Enclose literal IPv6 addresses in square brackets, Robbie Harwood, 2023/04/25
- [PATCH v5 12/20] efi/http: match protocol+hostname of boot url in root_url, Robbie Harwood, 2023/04/25
- [PATCH v5 14/20] use fw_path prefix when fallback searching for grub config, Robbie Harwood, 2023/04/25