* [PATCH v3 01/16] ieee1275/openfw: IBM client architecture (CAS) reboot support
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen Leo Sandoval
` (15 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
This is an implementation of IBM client architecture (CAS) reboot for GRUB.
There are cases where the POWER firmware must reboot in order to support
specific features requested by a kernel. The kernel calls
ibm,client-architecture-support and it may either return or reboot with
the new feature set. eg:
Calling ibm,client-architecture-support.../
Elapsed time since release of system processors: 70959 mins 50 secs
Welcome to GRUB!
Instead of return to the GRUB menu, it will check if the flag for CAS
reboot is set. If so, grub will automatically boot the last booted
kernel using the same parameters
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
[rharwood@redhat.com: commit message rewrap]
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++
grub-core/normal/main.c | 19 ++++++++++
grub-core/script/execute.c | 7 ++++
include/grub/ieee1275/ieee1275.h | 2 +
4 files changed, 91 insertions(+)
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
index 11b2beb2f..e2ecc65d2 100644
--- a/grub-core/kern/ieee1275/openfw.c
+++ b/grub-core/kern/ieee1275/openfw.c
@@ -591,3 +591,66 @@ grub_ieee1275_get_boot_dev (void)
return bootpath;
}
+
+/* Check if it's a CAS reboot. If so, set the script to be executed. */
+int
+grub_ieee1275_cas_reboot (char *script)
+{
+ grub_uint32_t ibm_ca_support_reboot;
+ grub_uint32_t ibm_fw_nbr_reboots;
+ char property_value[10];
+ grub_ssize_t actual;
+ grub_ieee1275_ihandle_t options;
+
+ if (grub_ieee1275_finddevice ("/options", &options) < 0)
+ return -1;
+
+ /* Check two properties, one is enough to get cas reboot value */
+ ibm_ca_support_reboot = 0;
+ if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen,
+ "ibm,client-architecture-support-reboot",
+ &ibm_ca_support_reboot,
+ sizeof (ibm_ca_support_reboot),
+ &actual) >= 0)
+ grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: %u\n",
+ ibm_ca_support_reboot);
+
+ ibm_fw_nbr_reboots = 0;
+ if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots",
+ property_value, sizeof (property_value),
+ &actual) >= 0)
+ {
+ property_value[sizeof (property_value) - 1] = 0;
+ ibm_fw_nbr_reboots = (grub_uint8_t) grub_strtoul (property_value, 0, 10);
+ grub_dprintf("ieee1275", "ibm,fw-nbr-reboots: %u\n", ibm_fw_nbr_reboots);
+ }
+
+ if (ibm_ca_support_reboot || ibm_fw_nbr_reboots)
+ {
+ if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual))
+ {
+ if (actual > 1024)
+ script = grub_realloc (script, actual + 1);
+ grub_ieee1275_get_property (options, "boot-last-label", script, actual,
+ &actual);
+ return 0;
+ }
+ }
+
+ grub_ieee1275_set_boot_last_label ("");
+
+ return -1;
+}
+
+int grub_ieee1275_set_boot_last_label (const char *text)
+{
+ grub_ieee1275_ihandle_t options;
+ grub_ssize_t actual;
+
+ grub_dprintf("ieee1275", "set boot_last_label (size: %u)\n", grub_strlen(text));
+ if (! grub_ieee1275_finddevice ("/options", &options) &&
+ options != (grub_ieee1275_ihandle_t) -1)
+ grub_ieee1275_set_property (options, "boot-last-label", text,
+ grub_strlen (text), &actual);
+ return 0;
+}
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index bd4431000..d3f53d93d 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -34,6 +34,9 @@
#include <grub/charset.h>
#include <grub/script_sh.h>
#include <grub/bufio.h>
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/ieee1275.h>
+#endif
GRUB_MOD_LICENSE ("GPLv3+");
@@ -276,6 +279,22 @@ grub_normal_execute (const char *config, int nested, int batch)
{
menu = read_config_file (config);
+#ifdef GRUB_MACHINE_IEEE1275
+ int boot;
+ boot = 0;
+ char *script;
+ script = grub_malloc (1024);
+ if (! grub_ieee1275_cas_reboot (script))
+ {
+ char *dummy[1] = { NULL };
+ if (! grub_script_execute_sourcecode (script))
+ boot = 1;
+ }
+ grub_free (script);
+ if (boot)
+ grub_command_execute ("boot", 0, 0);
+#endif
+
/* Ignore any error. */
grub_errno = GRUB_ERR_NONE;
}
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
index 14ff09094..dab8fd2ae 100644
--- a/grub-core/script/execute.c
+++ b/grub-core/script/execute.c
@@ -28,6 +28,9 @@
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/verify.h>
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/ieee1275.h>
+#endif
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
is sizeof (int) * 3, and one extra for a possible -ve sign. */
@@ -883,6 +886,10 @@ grub_script_execute_sourcecode (const char *source)
grub_err_t ret = 0;
struct grub_script *parsed_script;
+#ifdef GRUB_MACHINE_IEEE1275
+ grub_ieee1275_set_boot_last_label (source);
+#endif
+
while (source)
{
char *line;
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index dddb38514..4f6e6aaa0 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -251,6 +251,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali
void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
struct grub_ieee1275_devalias *alias);
+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
+int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 01/16] ieee1275/openfw: IBM client architecture (CAS) reboot support Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines Leo Sandoval
` (14 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
v2: Also use \x0c instead of a literal ^L to make future patches less
awkward.
This should fix this bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=908519
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
grub-core/term/terminfo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c
index 4e534c683..3dbe88e89 100644
--- a/grub-core/term/terminfo.c
+++ b/grub-core/term/terminfo.c
@@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output *term,
/* Clear the screen. Using serial console, screen(1) only recognizes the
* ANSI escape sequence. Using video console, Apple Open Firmware
* (version 3.1.1) only recognizes the literal ^L. So use both. */
- data->cls = grub_strdup ("\f\e[2J");
+ data->cls = grub_strdup ("\x0c\e[2J\e[m");
data->reverse_video_on = grub_strdup ("\e[7m");
data->reverse_video_off = grub_strdup ("\e[m");
if (grub_strcmp ("ieee1275", str) == 0)
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 01/16] ieee1275/openfw: IBM client architecture (CAS) reboot support Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 04/16] configure.ac: Move bash completion script Leo Sandoval
` (13 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
GRUB gets the display card node address from OpenFirmware, however this address
is truncated to 32-bits (OpenFirmware works on 32-bits, so GRUB) effectively
getting an invalid address. This change disables the video support on IBM power
machines. More details can be found at [1].
[1] https://bugzilla.redhat.com/show_bug.cgi?id=973205
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
grub-core/kern/ieee1275/cmain.c | 5 ++++-
grub-core/video/ieee1275.c | 9 ++++++---
include/grub/ieee1275/ieee1275.h | 2 ++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c
index e74de3248..810a089a9 100644
--- a/grub-core/kern/ieee1275/cmain.c
+++ b/grub-core/kern/ieee1275/cmain.c
@@ -89,7 +89,10 @@ grub_ieee1275_find_options (void)
}
if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0)
- grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);
+ {
+ grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);
+ grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT);
+ }
/* Old Macs have no key repeat, newer ones have fully working one.
The ones inbetween when repeated key generates an escaoe sequence
diff --git a/grub-core/video/ieee1275.c b/grub-core/video/ieee1275.c
index ca3d3c3b2..5592e4bb7 100644
--- a/grub-core/video/ieee1275.c
+++ b/grub-core/video/ieee1275.c
@@ -351,9 +351,12 @@ static struct grub_video_adapter grub_video_ieee1275_adapter =
GRUB_MOD_INIT(ieee1275_fb)
{
- find_display ();
- if (display)
- grub_video_register (&grub_video_ieee1275_adapter);
+ if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT))
+ {
+ find_display ();
+ if (display)
+ grub_video_register (&grub_video_ieee1275_adapter);
+ }
}
GRUB_MOD_FINI(ieee1275_fb)
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index 4f6e6aaa0..db0ec5f4c 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -145,6 +145,8 @@ enum grub_ieee1275_flag
GRUB_IEEE1275_FLAG_POWER_VM,
GRUB_IEEE1275_FLAG_POWER_KVM,
+
+ GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT
};
extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 04/16] configure.ac: Move bash completion script
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (2 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 05/16] misc: Make "exit" take a return code Leo Sandoval
` (12 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=922997
Apparently these go in a new place now.
---
configure.ac | 11 +++++++++++
util/bash-completion.d/Makefile.am | 1 -
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index cd667a2eb..ae3a49321 100644
--- a/configure.ac
+++ b/configure.ac
@@ -319,6 +319,14 @@ AC_SUBST(grubdirname)
AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
[Default grub directory name])
+PKG_PROG_PKG_CONFIG
+AS_IF([$($PKG_CONFIG --exists bash-completion)], [
+ bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion)
+] , [
+ bashcompletiondir=${datadir}/bash-completion/completions
+])
+AC_SUBST(bashcompletiondir)
+
#
# Checks for build programs.
#
@@ -534,6 +542,9 @@ HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags"
# Check for target programs.
#
+# This makes sure pkg.m4 is available.
+m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
+
# Find tools for the target.
if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
tmp_ac_tool_prefix="$ac_tool_prefix"
diff --git a/util/bash-completion.d/Makefile.am b/util/bash-completion.d/Makefile.am
index 136287cf1..61108f054 100644
--- a/util/bash-completion.d/Makefile.am
+++ b/util/bash-completion.d/Makefile.am
@@ -6,7 +6,6 @@ EXTRA_DIST = $(bash_completion_source)
CLEANFILES = $(bash_completion_script) config.log
-bashcompletiondir = $(sysconfdir)/bash_completion.d
bashcompletion_DATA = $(bash_completion_script)
$(bash_completion_script): $(bash_completion_source) $(top_builddir)/config.status
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 05/16] misc: Make "exit" take a return code.
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (3 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 04/16] configure.ac: Move bash completion script Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 06/16] efi/init: Make efi machines load an env block from a variable Leo Sandoval
` (11 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
This adds "exit" with a return code. With this patch, any "exit"
command /may/ include a return code, and on platforms that support
returning with an exit status, we will do so. By default we return the
same exit status we did before this patch.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/commands/minicmd.c | 20 ++++++++++++++++----
grub-core/kern/efi/efi.c | 9 +++++++--
grub-core/kern/emu/main.c | 2 +-
grub-core/kern/emu/misc.c | 9 +++++----
grub-core/kern/i386/coreboot/init.c | 2 +-
grub-core/kern/i386/qemu/init.c | 2 +-
grub-core/kern/ieee1275/init.c | 2 +-
grub-core/kern/mips/arc/init.c | 2 +-
grub-core/kern/mips/loongson/init.c | 2 +-
grub-core/kern/mips/qemu_mips/init.c | 2 +-
grub-core/kern/misc.c | 11 ++++++++++-
grub-core/kern/uboot/init.c | 6 +++---
grub-core/kern/xen/init.c | 2 +-
include/grub/misc.h | 2 +-
14 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
index fa498931e..2bd3ac76f 100644
--- a/grub-core/commands/minicmd.c
+++ b/grub-core/commands/minicmd.c
@@ -182,12 +182,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
}
/* exit */
-static grub_err_t __attribute__ ((noreturn))
+static grub_err_t
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
- int argc __attribute__ ((unused)),
- char *argv[] __attribute__ ((unused)))
+ int argc, char *argv[])
{
- grub_exit ();
+ int retval = -1;
+ unsigned long n;
+
+ if (argc < 0 || argc > 1)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+
+ if (argc == 1)
+ {
+ n = grub_strtoul (argv[0], 0, 10);
+ if (n != ~0UL)
+ retval = n;
+ }
+
+ grub_exit (retval);
/* Not reached. */
}
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index b93ae3aba..885d7c642 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -175,11 +175,16 @@ grub_reboot (void)
}
void
-grub_exit (void)
+grub_exit (int retval)
{
+ int rc = GRUB_EFI_LOAD_ERROR;
+
+ if (retval == 0)
+ rc = GRUB_EFI_SUCCESS;
+
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
grub_efi_system_table->boot_services->exit (grub_efi_image_handle,
- GRUB_EFI_SUCCESS, 0, 0);
+ rc, 0, 0);
for (;;) ;
}
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
index 855b11c3d..38c1576a2 100644
--- a/grub-core/kern/emu/main.c
+++ b/grub-core/kern/emu/main.c
@@ -67,7 +67,7 @@ grub_reboot (void)
}
void
-grub_exit (void)
+grub_exit (int retval __attribute__((unused)))
{
grub_reboot ();
}
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
index 521220b49..16c79bc94 100644
--- a/grub-core/kern/emu/misc.c
+++ b/grub-core/kern/emu/misc.c
@@ -83,7 +83,7 @@ grub_util_error (const char *fmt, ...)
vfprintf (stderr, fmt, ap);
va_end (ap);
fprintf (stderr, ".\n");
- grub_exit ();
+ grub_exit (1);
}
void *
@@ -152,12 +152,13 @@ xasprintf (const char *fmt, ...)
#if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL)
void
-grub_exit (void)
+__attribute__ ((noreturn))
+grub_exit (int rc)
{
-#if defined (GRUB_KERNEL)
+#if defined (GRUB_KERNEL) && !defined (GRUB_MACHINE_EFI)
grub_reboot ();
#endif
- exit (1);
+ exit (rc < 0 ? 1 : rc);
}
#endif
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
index 4fae8b571..feaf9295e 100644
--- a/grub-core/kern/i386/coreboot/init.c
+++ b/grub-core/kern/i386/coreboot/init.c
@@ -41,7 +41,7 @@ extern grub_uint8_t _end[];
extern grub_uint8_t _edata[];
void __attribute__ ((noreturn))
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
/* We can't use grub_fatal() in this function. This would create an infinite
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c
index 08f81d25e..604fc94b5 100644
--- a/grub-core/kern/i386/qemu/init.c
+++ b/grub-core/kern/i386/qemu/init.c
@@ -42,7 +42,7 @@ extern grub_uint8_t _end[];
extern grub_uint8_t _edata[];
void __attribute__ ((noreturn))
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
/* We can't use grub_fatal() in this function. This would create an infinite
loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
index fb7d1a3ba..50c65b2f6 100644
--- a/grub-core/kern/ieee1275/init.c
+++ b/grub-core/kern/ieee1275/init.c
@@ -114,7 +114,7 @@ grub_addr_t grub_ieee1275_original_stack;
#define BYTE22 (DY_MEM_V2 | DRC_INFO)
void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
grub_ieee1275_exit ();
}
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
index 2ed3ff319..5c40c3407 100644
--- a/grub-core/kern/mips/arc/init.c
+++ b/grub-core/kern/mips/arc/init.c
@@ -276,7 +276,7 @@ grub_halt (void)
}
void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
GRUB_ARC_FIRMWARE_VECTOR->exit ();
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
index 5bd721260..97b09b0ee 100644
--- a/grub-core/kern/mips/loongson/init.c
+++ b/grub-core/kern/mips/loongson/init.c
@@ -304,7 +304,7 @@ grub_halt (void)
}
void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
grub_halt ();
}
diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c
index b5477b87f..69488a34e 100644
--- a/grub-core/kern/mips/qemu_mips/init.c
+++ b/grub-core/kern/mips/qemu_mips/init.c
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
}
void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
grub_halt ();
}
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 7cee5d75c..11037dc02 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -1311,9 +1311,18 @@ grub_abort (void)
grub_getkey ();
}
- grub_exit ();
+ grub_exit (1);
}
+#if defined (__clang__) && !defined (GRUB_UTIL)
+/* clang emits references to abort(). */
+void __attribute__ ((noreturn))
+abort (void)
+{
+ grub_abort ();
+}
+#endif
+
void
grub_fatal (const char *fmt, ...)
{
diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c
index 3e338645c..be2a5be1d 100644
--- a/grub-core/kern/uboot/init.c
+++ b/grub-core/kern/uboot/init.c
@@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size;
static unsigned long timer_start;
void
-grub_exit (void)
+grub_exit (int rc)
{
- grub_uboot_return (0);
+ grub_uboot_return (rc < 0 ? 1 : rc);
}
static grub_uint64_t
@@ -78,7 +78,7 @@ grub_machine_init (void)
if (!ver)
{
/* Don't even have a console to log errors to... */
- grub_exit ();
+ grub_exit (-1);
}
else if (ver > API_SIG_VERSION)
{
diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
index 782ca7295..708b060f3 100644
--- a/grub-core/kern/xen/init.c
+++ b/grub-core/kern/xen/init.c
@@ -584,7 +584,7 @@ grub_machine_init (void)
}
void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
{
struct sched_shutdown arg;
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 1b35a167f..72aff1575 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -385,7 +385,7 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
__attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
grub_uint64_t d,
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 06/16] efi/init: Make efi machines load an env block from a variable
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (4 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 05/16] misc: Make "exit" take a return code Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 07/16] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2 Leo Sandoval
` (10 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/Makefile.core.def | 1 +
grub-core/kern/efi/init.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 1571421d7..0bffbfea9 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -219,6 +219,7 @@ kernel = {
efi = kern/efi/acpi.c;
efi = kern/efi/sb.c;
efi = kern/lockdown.c;
+ efi = lib/envblk.c;
i386_coreboot = kern/i386/pc/acpi.c;
i386_multiboot = kern/i386/pc/acpi.c;
i386_coreboot = kern/acpi.c;
diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c
index 6c54af6e7..b5201974a 100644
--- a/grub-core/kern/efi/init.c
+++ b/grub-core/kern/efi/init.c
@@ -28,8 +28,11 @@
#include <grub/env.h>
#include <grub/mm.h>
#include <grub/kernel.h>
+
#include <grub/stack_protector.h>
+#include <grub/lib/envblk.h>
+
#ifdef GRUB_STACK_PROTECTOR
static grub_efi_char16_t stack_chk_fail_msg[] =
@@ -103,6 +106,36 @@ stack_protector_init (void)
grub_addr_t grub_modbase;
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
+ { 0x91376aff, 0xcba6, 0x42be, \
+ { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
+ }
+
+/* Helper for grub_efi_env_init */
+static int
+set_var (const char *name, const char *value,
+ void *whitelist __attribute__((__unused__)))
+{
+ grub_env_set (name, value);
+ return 0;
+}
+
+static void
+grub_efi_env_init (void)
+{
+ grub_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
+ struct grub_envblk envblk_s = { NULL, 0 };
+ grub_envblk_t envblk = &envblk_s;
+
+ grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size,
+ (void **) &envblk_s.buf);
+ if (!envblk_s.buf || envblk_s.size < 1)
+ return;
+
+ grub_envblk_iterate (envblk, NULL, set_var);
+ grub_free (envblk_s.buf);
+}
+
__attribute__ ((__optimize__ ("-fno-stack-protector"))) void
grub_efi_init (void)
{
@@ -128,6 +161,7 @@ grub_efi_init (void)
grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL);
+ grub_efi_env_init ();
grub_efidisk_init ();
grub_efi_register_debug_commands ();
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 07/16] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (5 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 06/16] efi/init: Make efi machines load an env block from a variable Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 08/16] normal: Add fw_path variable (revised) Leo Sandoval
` (9 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Mark Hamzy <hamzy@us.ibm.com>
Add configuration support for ieee1275/PPC ofconsole serial terminal.
Signed-off-by: Mark Hamzy <hamzy@us.ibm.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
Makefile.util.def | 7 ++
util/grub.d/20_ppc_terminfo.in | 114 +++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+)
create mode 100644 util/grub.d/20_ppc_terminfo.in
diff --git a/Makefile.util.def b/Makefile.util.def
index 9432365a9..09bfcadd9 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -517,6 +517,13 @@ script = {
installdir = grubconf;
};
+script = {
+ name = '20_ppc_terminfo';
+ common = util/grub.d/20_ppc_terminfo.in;
+ installdir = grubconf;
+ condition = COND_HOST_LINUX;
+};
+
script = {
name = '30_os-prober';
common = util/grub.d/30_os-prober.in;
diff --git a/util/grub.d/20_ppc_terminfo.in b/util/grub.d/20_ppc_terminfo.in
new file mode 100644
index 000000000..10d665868
--- /dev/null
+++ b/util/grub.d/20_ppc_terminfo.in
@@ -0,0 +1,114 @@
+#! /bin/sh
+set -e
+
+# grub-mkconfig helper script.
+# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+libdir=@libdir@
+. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
+
+export TEXTDOMAIN=@PACKAGE@
+export TEXTDOMAINDIR=@localedir@
+
+X=80
+Y=24
+TERMINAL=ofconsole
+
+argument () {
+ opt=$1
+ shift
+
+ if test $# -eq 0; then
+ echo "$0: option requires an argument -- '$opt'" 1>&2
+ exit 1
+ fi
+ echo $1
+}
+
+check_terminfo () {
+
+ while test $# -gt 0
+ do
+ option=$1
+ shift
+
+ case "$option" in
+ terminfo | TERMINFO)
+ ;;
+
+ -g)
+ NEWXY=`argument $option "$@"`
+ NEWX=`echo $NEWXY | cut -d x -f 1`
+ NEWY=`echo $NEWXY | cut -d x -f 2`
+
+ if [ ${NEWX} -ge 80 ] ; then
+ X=${NEWX}
+ else
+ echo "Warning: ${NEWX} is less than the minimum size of 80"
+ fi
+
+ if [ ${NEWY} -ge 24 ] ; then
+ Y=${NEWY}
+ else
+ echo "Warning: ${NEWY} is less than the minimum size of 24"
+ fi
+
+ shift
+ ;;
+
+ *)
+# # accept console or ofconsole
+# if [ "$option" != "console" -a "$option" != "ofconsole" ] ; then
+# echo "Error: GRUB_TERMINFO unknown console: $option"
+# exit 1
+# fi
+# # perfer console
+# TERMINAL=console
+ # accept ofconsole
+ if [ "$option" != "ofconsole" ] ; then
+ echo "Error: GRUB_TERMINFO unknown console: $option"
+ exit 1
+ fi
+ # perfer console
+ TERMINAL=ofconsole
+ ;;
+ esac
+
+ done
+
+}
+
+if ! uname -m | grep -q ppc ; then
+ exit 0
+fi
+
+if [ "x${GRUB_TERMINFO}" != "x" ] ; then
+ F1=`echo ${GRUB_TERMINFO} | cut -d " " -f 1`
+
+ if [ "${F1}" != "terminfo" ] ; then
+ echo "Error: GRUB_TERMINFO is set to \"${GRUB_TERMINFO}\" The first word should be terminfo."
+ exit 1
+ fi
+
+ check_terminfo ${GRUB_TERMINFO}
+fi
+
+cat << EOF
+ terminfo -g ${X}x${Y} ${TERMINAL}
+EOF
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 08/16] normal: Add fw_path variable (revised)
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (6 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 07/16] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2 Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-15 5:23 ` Michael Chang via Grub-devel
2024-10-10 21:43 ` [PATCH v3 09/16] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested Leo Sandoval
` (8 subsequent siblings)
16 siblings, 1 reply; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
This patch makes grub look for its config file on efi where the app was
found. It was originally written by Matthew Garrett, and adapted to fix the
"No modules are loaded on grub2 network boot" issue:
https://bugzilla.redhat.com/show_bug.cgi?id=857936
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
grub-core/kern/main.c | 13 ++++++-------
grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 731c07c29..463dafdba 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -128,16 +128,15 @@ grub_set_prefix_and_root (void)
grub_machine_get_bootlocation (&fwdevice, &fwpath);
- if (fwdevice)
+ if (fwdevice && fwpath)
{
- char *cmdpath;
+ char *fw_path;
- cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
- if (cmdpath)
+ fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
+ if (fw_path)
{
- grub_env_set ("cmdpath", cmdpath);
- grub_env_export ("cmdpath");
- grub_free (cmdpath);
+ grub_env_set ("fw_path", fw_path);
+ grub_free (fw_path);
}
}
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index d3f53d93d..08f48c71d 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
/* 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;
+ const char *prefix, *fw_path;
+
+ 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);
+ }
+ }
prefix = grub_env_get ("prefix");
if (prefix)
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH v3 08/16] normal: Add fw_path variable (revised)
2024-10-10 21:43 ` [PATCH v3 08/16] normal: Add fw_path variable (revised) Leo Sandoval
@ 2024-10-15 5:23 ` Michael Chang via Grub-devel
2024-10-15 9:01 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 21+ messages in thread
From: Michael Chang via Grub-devel @ 2024-10-15 5:23 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: Michael Chang
On Thu, Oct 10, 2024 at 03:43:26PM GMT, Leo Sandoval wrote:
> From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
>
> This patch makes grub look for its config file on efi where the app was
> found. It was originally written by Matthew Garrett, and adapted to fix the
> "No modules are loaded on grub2 network boot" issue:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=857936
>
> Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> Signed-off-by: Robbie Harwood <rharwood@redhat.com>
> ---
> grub-core/kern/main.c | 13 ++++++-------
> grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
> 2 files changed, 30 insertions(+), 8 deletions(-)
>
> diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
> index 731c07c29..463dafdba 100644
> --- a/grub-core/kern/main.c
> +++ b/grub-core/kern/main.c
> @@ -128,16 +128,15 @@ grub_set_prefix_and_root (void)
>
> grub_machine_get_bootlocation (&fwdevice, &fwpath);
>
> - if (fwdevice)
> + if (fwdevice && fwpath)
> {
> - char *cmdpath;
> + char *fw_path;
>
> - cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
> - if (cmdpath)
> + fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
> + if (fw_path)
> {
> - grub_env_set ("cmdpath", cmdpath);
> - grub_env_export ("cmdpath");
> - grub_free (cmdpath);
> + grub_env_set ("fw_path", fw_path);
> + grub_free (fw_path);
I believe $cmdpath is an important and well-known public variable. It is
officially documented [1], and therefore, it shouldn't be removed or
renamed without formal notice.
A quick google search [2] shows many references to $cmdpath, and many
custom grub scripts would rely on it to function properly.
IMHO removing or renaming it would introduce a breaking change. Adding
$fw_path would be fine, but it's unclear to me why that would be
necessary either.
[1]
https://www.gnu.org/software/grub/manual/grub/html_node/cmdpath.html
[2]
https://wiki.archlinux.org/title/GRUB/Tips_and_tricks
https://superuser.com/questions/1757526/get-device-part-of-a-file-path-within-grub-cfg
https://github.com/opencomputeproject/onie/blob/master/build-config/scripts/mk-grub-efi-image
https://stackoverflow.com/questions/35269943/how-does-the-grub-2-uefi-loader-know-where-to-look-for-the-configuration-file-o
Thanks,
Michael
> }
> }
>
> diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
> index d3f53d93d..08f48c71d 100644
> --- a/grub-core/normal/main.c
> +++ b/grub-core/normal/main.c
> @@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
> /* 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;
> + const char *prefix, *fw_path;
> +
> + 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);
> + }
> + }
>
> prefix = grub_env_get ("prefix");
> if (prefix)
> --
> 2.46.2
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH v3 08/16] normal: Add fw_path variable (revised)
2024-10-15 5:23 ` Michael Chang via Grub-devel
@ 2024-10-15 9:01 ` Vladimir 'phcoder' Serbinenko
0 siblings, 0 replies; 21+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2024-10-15 9:01 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1.1: Type: text/plain, Size: 4359 bytes --]
Le mar. 15 oct. 2024, 08:24, Michael Chang via Grub-devel <
grub-devel@gnu.org> a écrit :
> On Thu, Oct 10, 2024 at 03:43:26PM GMT, Leo Sandoval wrote:
> > From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> >
> > This patch makes grub look for its config file on efi where the app was
> > found. It was originally written by Matthew Garrett, and adapted to fix
> the
> > "No modules are loaded on grub2 network boot" issue:
> >
> > https://bugzilla.redhat.com/show_bug.cgi?id=857936
> >
> > Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> > Signed-off-by: Robbie Harwood <rharwood@redhat.com>
> > ---
> > grub-core/kern/main.c | 13 ++++++-------
> > grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
> > 2 files changed, 30 insertions(+), 8 deletions(-)
> >
> > diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
> > index 731c07c29..463dafdba 100644
> > --- a/grub-core/kern/main.c
> > +++ b/grub-core/kern/main.c
> > @@ -128,16 +128,15 @@ grub_set_prefix_and_root (void)
> >
> > grub_machine_get_bootlocation (&fwdevice, &fwpath);
> >
> > - if (fwdevice)
> > + if (fwdevice && fwpath)
> > {
> > - char *cmdpath;
> > + char *fw_path;
> >
> > - cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
> > - if (cmdpath)
> > + fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
> > + if (fw_path)
> > {
> > - grub_env_set ("cmdpath", cmdpath);
> > - grub_env_export ("cmdpath");
> > - grub_free (cmdpath);
> > + grub_env_set ("fw_path", fw_path);
> > + grub_free (fw_path);
>
>
> I believe $cmdpath is an important and well-known public variable. It is
> officially documented [1], and therefore, it shouldn't be removed or
> renamed without formal notice.
>
> A quick google search [2] shows many references to $cmdpath, and many
> custom grub scripts would rely on it to function properly.
>
My thoughts exactly. I totally agree.
>
> IMHO removing or renaming it would introduce a breaking change. Adding
> $fw_path would be fine, but it's unclear to me why that would be
> necessary either.
>
> [1]
> https://www.gnu.org/software/grub/manual/grub/html_node/cmdpath.html
>
> [2]
> https://wiki.archlinux.org/title/GRUB/Tips_and_tricks
>
> https://superuser.com/questions/1757526/get-device-part-of-a-file-path-within-grub-cfg
>
> https://github.com/opencomputeproject/onie/blob/master/build-config/scripts/mk-grub-efi-image
>
> https://stackoverflow.com/questions/35269943/how-does-the-grub-2-uefi-loader-know-where-to-look-for-the-configuration-file-o
>
> Thanks,
> Michael
>
> > }
> > }
> >
> > diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
> > index d3f53d93d..08f48c71d 100644
> > --- a/grub-core/normal/main.c
> > +++ b/grub-core/normal/main.c
> > @@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd
> __attribute__ ((unused)),
> > /* 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;
> > + const char *prefix, *fw_path;
> > +
> > + 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);
> > + }
> > + }
> >
> > prefix = grub_env_get ("prefix");
> > if (prefix)
> > --
> > 2.46.2
> >
> >
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
[-- Attachment #1.2: Type: text/html, Size: 7095 bytes --]
[-- Attachment #2: Type: text/plain, Size: 141 bytes --]
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v3 09/16] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (7 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 08/16] normal: Add fw_path variable (revised) Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 10/16] 10_linux.in: Add devicetree loading Leo Sandoval
` (7 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
Don't munge raw spaces when we're doing our cmdline escaping (#923374)
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/commands/wildcard.c | 16 ++++++++++++-
grub-core/lib/cmdline.c | 25 ++++++++++++++++++--
grub-core/script/execute.c | 43 ++++++++++++++++++++++++++++++-----
3 files changed, 75 insertions(+), 9 deletions(-)
diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c
index ed6586505..5455242c3 100644
--- a/grub-core/commands/wildcard.c
+++ b/grub-core/commands/wildcard.c
@@ -488,6 +488,12 @@ check_file (const char *dir, const char *basename)
return ctx.found;
}
+static int
+is_hex(char c)
+{
+ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
+}
+
static void
unescape (char *out, const char *in, const char *end)
{
@@ -496,7 +502,15 @@ unescape (char *out, const char *in, const char *end)
for (optr = out, iptr = in; iptr < end;)
{
- if (*iptr == '\\' && iptr + 1 < end)
+ if (*iptr == '\\' && iptr + 3 < end && iptr[1] == 'x' && is_hex(iptr[2]) && is_hex(iptr[3]))
+ {
+ *optr++ = *iptr++;
+ *optr++ = *iptr++;
+ *optr++ = *iptr++;
+ *optr++ = *iptr++;
+ continue;
+ }
+ else if (*iptr == '\\' && iptr + 1 < end)
{
*optr++ = iptr[1];
iptr += 2;
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
index ed0b149dc..8e2294d8f 100644
--- a/grub-core/lib/cmdline.c
+++ b/grub-core/lib/cmdline.c
@@ -20,6 +20,12 @@
#include <grub/lib/cmdline.h>
#include <grub/misc.h>
+static int
+is_hex(char c)
+{
+ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
+}
+
static unsigned int check_arg (char *c, int *has_space)
{
int space = 0;
@@ -27,7 +33,13 @@ static unsigned int check_arg (char *c, int *has_space)
while (*c)
{
- if (*c == '\\' || *c == '\'' || *c == '"')
+ if (*c == '\\' && *(c+1) == 'x' && is_hex(*(c+2)) && is_hex(*(c+3)))
+ {
+ size += 4;
+ c += 4;
+ continue;
+ }
+ else if (*c == '\\' || *c == '\'' || *c == '"')
size++;
else if (*c == ' ')
space = 1;
@@ -86,7 +98,16 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf,
while (*c)
{
- if (*c == '\\' || *c == '\'' || *c == '"')
+ if (*c == '\\' && *(c+1) == 'x' &&
+ is_hex(*(c+2)) && is_hex(*(c+3)))
+ {
+ *buf++ = *c++;
+ *buf++ = *c++;
+ *buf++ = *c++;
+ *buf++ = *c++;
+ continue;
+ }
+ else if (*c == '\\' || *c == '\'' || *c == '"')
*buf++ = '\\';
*buf++ = *c;
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
index dab8fd2ae..c19b4bf70 100644
--- a/grub-core/script/execute.c
+++ b/grub-core/script/execute.c
@@ -56,6 +56,12 @@ static struct grub_script_scope *scope = 0;
/* Wildcard translator for GRUB script. */
struct grub_script_wildcard_translator *grub_wildcard_translator;
+static int
+is_hex(char c)
+{
+ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
+}
+
static char*
wildcard_escape (const char *s)
{
@@ -72,7 +78,15 @@ wildcard_escape (const char *s)
i = 0;
while ((ch = *s++))
{
- if (ch == '*' || ch == '\\' || ch == '?')
+ if (ch == '\\' && s[0] == 'x' && is_hex(s[1]) && is_hex(s[2]))
+ {
+ p[i++] = ch;
+ p[i++] = *s++;
+ p[i++] = *s++;
+ p[i++] = *s++;
+ continue;
+ }
+ else if (ch == '*' || ch == '\\' || ch == '?')
p[i++] = '\\';
p[i++] = ch;
}
@@ -96,7 +110,14 @@ wildcard_unescape (const char *s)
i = 0;
while ((ch = *s++))
{
- if (ch == '\\')
+ if (ch == '\\' && s[0] == 'x' && is_hex(s[1]) && is_hex(s[2]))
+ {
+ p[i++] = '\\';
+ p[i++] = *s++;
+ p[i++] = *s++;
+ p[i++] = *s++;
+ }
+ else if (ch == '\\')
p[i++] = *s++;
else
p[i++] = ch;
@@ -398,10 +419,20 @@ parse_string (const char *str,
switch (*ptr)
{
case '\\':
- escaped = !escaped;
- if (!escaped && put)
- *(put++) = '\\';
- ptr++;
+ if (!escaped && put && *(ptr+1) == 'x' && is_hex(*(ptr+2)) && is_hex(*(ptr+3)))
+ {
+ *(put++) = *ptr++;
+ *(put++) = *ptr++;
+ *(put++) = *ptr++;
+ *(put++) = *ptr++;
+ }
+ else
+ {
+ escaped = !escaped;
+ if (!escaped && put)
+ *(put++) = '\\';
+ ptr++;
+ }
break;
case '$':
if (escaped)
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 10/16] 10_linux.in: Add devicetree loading
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (8 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 09/16] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 11/16] Makefile.common: Add .eh_frame to list of relocations stripped Leo Sandoval
` (6 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
Switch to use APM Mustang device tree, for hardware testing.
Signed-off-by: David A. Marlin <d.marlin@redhat.com>
Use the default device tree from the grub default file
instead of hardcoding a value.
Signed-off-by: David A. Marlin <dmarlin@redhat.com>
---
util/grub-mkconfig.in | 3 ++-
util/grub.d/10_linux.in | 15 +++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 32c480dae..d1bf4983b 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -255,7 +255,8 @@ export GRUB_DEFAULT \
GRUB_ENABLE_CRYPTODISK \
GRUB_BADRAM \
GRUB_OS_PROBER_SKIP_LIST \
- GRUB_DISABLE_SUBMENU
+ GRUB_DISABLE_SUBMENU \
+ GRUB_DEFAULT_DTB
if test "x${grub_cfg}" != "x"; then
rm -f "${grub_cfg}.new"
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index cc393be7e..00d4b220c 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -155,6 +155,13 @@ EOF
sed "s/^/$submenu_indentation/" << EOF
echo '$(echo "$message" | grub_quote)'
initrd $(echo $initrd_path)
+EOF
+ fi
+ if test -n "${fdt}" ; then
+ message="$(gettext_printf "Loading fdt ...")"
+ sed "s/^/$submenu_indentation/" << EOF
+ echo '$(echo "$message" | grub_quote)'
+ devicetree ${rel_dirname}/${fdt}
EOF
fi
sed "s/^/$submenu_indentation/" << EOF
@@ -250,6 +257,14 @@ for linux in ${reverse_sorted_list}; do
gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
fi
+ fdt=
+ for i in "dtb-${version}" "dtb-${alt_version}"; do
+ if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then
+ fdt="${i}/${GRUB_DEFAULT_DTB}"
+ break
+ fi
+ done
+
config=
for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
if test -e "${i}" ; then
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 11/16] Makefile.common: Add .eh_frame to list of relocations stripped
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (9 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 10/16] 10_linux.in: Add devicetree loading Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 12/16] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig Leo Sandoval
` (5 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Fedora Ninjas <grub2-owner@fedoraproject.org>
Signed-off-by: Peter Jones <pjones@redhat.com>
---
conf/Makefile.common | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/conf/Makefile.common b/conf/Makefile.common
index b8f216f6c..ece9ed8a1 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -41,7 +41,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding
LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1
CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
-STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx
+STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx
if !COND_emu
if COND_HAVE_ASM_USCORE
LDFLAGS_KERNEL += -Wl,--defsym=_malloc=_grub_malloc -Wl,--defsym=_free=_grub_free
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 12/16] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig.
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (10 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 11/16] Makefile.common: Add .eh_frame to list of relocations stripped Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 13/16] normal/main: fw_path prefix when fallback searching for grub config Leo Sandoval
` (4 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
When we set a password, we just want that to mean you can't /edit/ an entry.
Resolves: rhbz#1030176
Signed-off-by: Peter Jones <pjones@redhat.com>
---
util/grub.d/10_linux.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 00d4b220c..66418f65d 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -26,7 +26,7 @@ datarootdir="@datarootdir@"
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@"
-CLASS="--class gnu-linux --class gnu --class os"
+CLASS="--class gnu-linux --class gnu --class os --unrestricted"
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU/Linux
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 13/16] normal/main: fw_path prefix when fallback searching for grub config
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (11 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 12/16] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 14/16] normal/main: Try mac/guid/etc before grub.cfg on tftp config files Leo Sandoval
` (3 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Fedora Ninjas <grub2-owner@fedoraproject.org>
When PXE booting via UEFI firmware, grub was searching for grub.cfg
in the fw_path directory where the grub application was found. If
that didn't exist, a fallback search would look for config file names
based on MAC and IP address. However, the search would look in the
prefix directory which may not be the same fw_path. This patch
changes that behavior to use the fw_path directory for the fallback
search. Only if fw_path is NULL will the prefix directory be searched.
Signed-off-by: Mark Salter <msalter@redhat.com>
---
grub-core/normal/main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 08f48c71d..fd8be685a 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -341,7 +341,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
char *config;
const char *prefix, *fw_path;
- fw_path = grub_env_get ("fw_path");
+ prefix = fw_path = grub_env_get ("fw_path");
if (fw_path)
{
config = grub_xasprintf ("%s/grub.cfg", fw_path);
@@ -364,7 +364,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
}
}
- prefix = grub_env_get ("prefix");
+ if (! prefix)
+ prefix = grub_env_get ("prefix");
if (prefix)
{
grub_size_t config_len;
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 14/16] normal/main: Try mac/guid/etc before grub.cfg on tftp config files.
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (12 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 13/16] normal/main: fw_path prefix when fallback searching for grub config Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 15/16] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release Leo Sandoval
` (2 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/normal/main.c | 93 ++++++++++++++++++++++-------------------
1 file changed, 49 insertions(+), 44 deletions(-)
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index fd8be685a..973e7d733 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -339,61 +339,66 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
/* 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);
- }
- }
+ const char *prefix;
+ const char *net_search_cfg;
+ int disable_net_search = 0;
+ prefix = grub_env_get ("fw_path");
if (! prefix)
prefix = grub_env_get ("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 (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 (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)
- goto quit;
+ if (! config)
+ goto quit;
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
+ 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;
+ grub_net_search_configfile (config);
- 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);
+ config = NULL;
+ }
- grub_enter_normal_mode (config);
- grub_free (config);
- }
+ if (!config)
+ {
+ 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);
+ grub_enter_normal_mode (config);
+ }
+ else
+ {
+ /* Ignore all errors. */
+ grub_errno = 0;
+ }
+ grub_free (config);
+ }
+ }
+ }
else
- grub_enter_normal_mode (0);
+ {
+ grub_enter_normal_mode (0);
+ }
}
else
grub_enter_normal_mode (argv[0]);
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 15/16] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (13 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 14/16] normal/main: Try mac/guid/etc before grub.cfg on tftp config files Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 16/16] normal/main: Try $prefix if $fw_path doesn't work Leo Sandoval
2024-10-30 16:39 ` [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Daniel Kiper
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
This makes us use pretty names in the titles we generate in
grub2-mkconfig when GRUB_DISTRIBUTOR isn't set.
Resolves: rhbz#996794
Signed-off-by: Peter Jones <pjones@redhat.com>
---
util/grub.d/10_linux.in | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 66418f65d..3105c31e4 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -29,7 +29,8 @@ export TEXTDOMAINDIR="@localedir@"
CLASS="--class gnu-linux --class gnu --class os --unrestricted"
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
- OS=GNU/Linux
+ OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})"
+ CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}"
else
OS="${GRUB_DISTRIBUTOR} GNU/Linux"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v3 16/16] normal/main: Try $prefix if $fw_path doesn't work.
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (14 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 15/16] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release Leo Sandoval
@ 2024-10-10 21:43 ` Leo Sandoval
2024-10-30 16:39 ` [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Daniel Kiper
16 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-10 21:43 UTC (permalink / raw)
To: grub-devel
From: Peter Jones <pjones@redhat.com>
Related: rhbz#1148652
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/kern/ieee1275/init.c | 28 +++----
grub-core/net/net.c | 2 +-
grub-core/normal/main.c | 132 ++++++++++++++++-----------------
3 files changed, 81 insertions(+), 81 deletions(-)
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
index 50c65b2f6..51c1e1c9d 100644
--- a/grub-core/kern/ieee1275/init.c
+++ b/grub-core/kern/ieee1275/init.c
@@ -170,23 +170,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 8cad4fb6d..54451cea2 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -2005,7 +2005,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 973e7d733..750c6c20c 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -329,81 +329,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)
+ if (argc)
+ grub_enter_normal_mode (argv[0]);
+ else
{
- /* 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;
- const char *net_search_cfg;
- int disable_net_search = 0;
-
- prefix = grub_env_get ("fw_path");
- if (! prefix)
- prefix = grub_env_get ("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 (prefix)
- {
- 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)
- goto quit;
-
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
-
- grub_net_search_configfile (config);
-
- grub_enter_normal_mode (config);
- grub_free (config);
- config = NULL;
- }
-
- if (!config)
- {
- 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);
- grub_enter_normal_mode (config);
- }
- else
- {
- /* Ignore all errors. */
- grub_errno = 0;
- }
- grub_free (config);
- }
- }
- }
- else
- {
- grub_enter_normal_mode (0);
- }
+ /* 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);
}
- else
- grub_enter_normal_mode (argv[0]);
-quit:
return 0;
}
--
2.46.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
` (15 preceding siblings ...)
2024-10-10 21:43 ` [PATCH v3 16/16] normal/main: Try $prefix if $fw_path doesn't work Leo Sandoval
@ 2024-10-30 16:39 ` Daniel Kiper
2024-10-30 17:03 ` Leo Sandoval
16 siblings, 1 reply; 21+ messages in thread
From: Daniel Kiper @ 2024-10-30 16:39 UTC (permalink / raw)
To: Leo Sandoval; +Cc: grub-devel
Leo,
On Thu, Oct 10, 2024 at 03:43:18PM -0600, Leo Sandoval wrote:
> This is the first patch series, taken from Fedora Rawhide spec [1] that
> is distro-agnostic. The goal is to merge most of them so all the community/distros
> would benefit.
I think it will be much easier to deal with patches if series contain
just somehow related ones. So, I think we should focus on EFI and Btrfs
changes first. Just post two series containing these two things only. We
can get back to other patches from series you sent when we merge the EFI
and Btrfs stuff.
Anyway, thank you for taking a stab at this.
Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide
2024-10-30 16:39 ` [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Daniel Kiper
@ 2024-10-30 17:03 ` Leo Sandoval
0 siblings, 0 replies; 21+ messages in thread
From: Leo Sandoval @ 2024-10-30 17:03 UTC (permalink / raw)
To: Daniel Kiper; +Cc: grub-devel
[-- Attachment #1.1: Type: text/plain, Size: 1097 bytes --]
Hi Daniel,
Thanks for your feedback, comment inline.
On Wed, Oct 30, 2024 at 10:40 AM Daniel Kiper <dkiper@net-space.pl> wrote:
> Leo,
>
> On Thu, Oct 10, 2024 at 03:43:18PM -0600, Leo Sandoval wrote:
> > This is the first patch series, taken from Fedora Rawhide spec [1] that
> > is distro-agnostic. The goal is to merge most of them so all the
> community/distros
> > would benefit.
>
> I think it will be much easier to deal with patches if series contain
> just somehow related ones. So, I think we should focus on EFI and Btrfs
> changes first. Just post two series containing these two things only. We
> can get back to other patches from series you sent when we merge the EFI
> and Btrfs stuff.
>
sounds like a better approach. Once I started this work last month, I tried
creating series per area for all Fedora patches but patch dependencies
between areas created merge issues so I abandoned this idea.
Let me try it again with these two sets, EFI and BTRFS and see how it goes.
>
> Anyway, thank you for taking a stab at this.
>
> Daniel
>
>
[-- Attachment #1.2: Type: text/html, Size: 1762 bytes --]
[-- Attachment #2: Type: text/plain, Size: 141 bytes --]
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 21+ messages in thread