[PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide

2024-10-10 Thread Leo Sandoval
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.

Changes since v2:
- modified 0003-Disable-GRUB-video-support-for-IBM-power-machines.patch
  shorter commit description

- deleted 0013-Enable-pager-by-default.-985860.patch
  not accepted: may cause issues on headless devices

Changes since v1:
- deleted 0005-Allow-fallback-to-include-entries-by-title-not-just-.patch
  no longer supported (even if doc indicates the contrary)
  
- deleted 011-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch
  similar patch reviewed in a separate thread
  
- deleted 0014-Don-t-say-GNU-Linux-in-generated-menus.patch
  not accepted

- modified  0003-Disable-GRUB-video-support-for-IBM-power-machines.patch
  included commit description taken from bz

- modified  0008-Migrate-PPC-from-Yaboot-to-Grub2.patch
  included 'ieee1275' on summary and description and improve description

[1] https://src.fedoraproject.org/rpms/grub2

Fedora Ninjas (2):
  Makefile.common: Add .eh_frame to list of relocations stripped
  normal/main: fw_path prefix when fallback searching for grub config

Mark Hamzy (1):
  20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2

Paulo Flabiano Smorigo (4):
  ieee1275/openfw: IBM client architecture (CAS) reboot support
  term/terminfo: for ppc, reset console display attr when clear screen
  ieee1275: Disable GRUB video support for IBM power machines
  normal: Add fw_path variable (revised)

Peter Jones (9):
  configure.ac: Move bash completion script
  misc: Make "exit" take a return code.
  efi/init: Make efi machines load an env block from a variable
  commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.
  10_linux.in: Add devicetree loading
  10_linux.in: Don't require a password to boot entries generated by
grub-mkconfig.
  normal/main: Try mac/guid/etc before grub.cfg on tftp config files.
  10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release
  normal/main: Try $prefix if $fw_path doesn't work.

 Makefile.util.def|   7 ++
 conf/Makefile.common |   2 +-
 configure.ac |  11 +++
 grub-core/Makefile.core.def  |   1 +
 grub-core/commands/minicmd.c |  20 -
 grub-core/commands/wildcard.c|  16 +++-
 grub-core/kern/efi/efi.c |   9 +-
 grub-core/kern/efi/init.c|  34 
 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/cmain.c  |   5 +-
 grub-core/kern/ieee1275/init.c   |  30 ---
 grub-core/kern/ieee1275/openfw.c |  63 ++
 grub-core/kern/main.c|  13 ++-
 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 +-
 grub-core/lib/cmdline.c  |  25 +-
 grub-core/net/net.c  |   2 +-
 grub-core/normal/main.c  | 122 ++-
 grub-core/script/execute.c   |  50 +--
 grub-core/term/terminfo.c|   2 +-
 grub-core/video/ieee1275.c   |   9 +-
 include/grub/ieee1275/ieee1275.h |   4 +
 include/grub/misc.h  |   2 +-
 util/bash-completion.d/Makefile.am   |   1 -
 util/grub-mkconfig.in|   3 +-
 util/grub.d/10_linux.in  |  20 -
 util/grub.d/20_ppc_terminfo.in   | 114 +
 34 files changed, 504 insertions(+), 101 deletions(-)
 create mode 100644 util/grub.d/20_ppc_terminfo.in

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 12/16] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig.

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

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 
---
 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


[PATCH v3 08/16] normal: Add fw_path variable (revised)

2024-10-10 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
Signed-off-by: Robbie Harwood 
---
 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


[PATCH v3 01/16] ieee1275/openfw: IBM client architecture (CAS) reboot support

2024-10-10 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
[rharw...@redhat.com: commit message rewrap]
Signed-off-by: Robbie Harwood 
---
 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 
 #include 
 #include 
+#ifdef GRUB_MACHINE_IEEE1275
+#include 
+#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 
 #include 
 #include 
+#ifdef GRUB_MACHINE_IEEE1275
+#include 
+#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 *so

[PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines

2024-10-10 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
Signed-off-by: Robbie Harwood 
---
 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


[PATCH v3 14/16] normal/main: Try mac/guid/etc before grub.cfg on tftp config files.

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 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-----");
-  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-----");
+  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


[PATCH v3 11/16] Makefile.common: Add .eh_frame to list of relocations stripped

2024-10-10 Thread Leo Sandoval
From: Fedora Ninjas 

Signed-off-by: Peter Jones 
---
 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


[PATCH v3 06/16] efi/init: Make efi machines load an env block from a variable

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 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 
 #include 
 #include 
+
 #include 
 
+#include 
+
 #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


[PATCH v3 10/16] 10_linux.in: Add devicetree loading

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 

Switch to use APM Mustang device tree, for hardware testing.

Signed-off-by: David A. Marlin 

Use the default device tree from the grub default file

instead of hardcoding a value.

Signed-off-by: David A. Marlin 
---
 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


[PATCH v3 05/16] misc: Make "exit" take a return code.

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

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 
---
 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_

[PATCH v3 15/16] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

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 
---
 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


[PATCH v3 09/16] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

Don't munge raw spaces when we're doing our cmdline escaping (#923374)

Signed-off-by: Peter Jones 
---
 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 
 #include 
 
+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


[PATCH v3 04/16] configure.ac: Move bash completion script

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

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


[PATCH v3 16/16] normal/main: Try $prefix if $fw_path doesn't work.

2024-10-10 Thread Leo Sandoval
From: Peter Jones 

Related: rhbz#1148652

Signed-off-by: Peter Jones 
---
 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-----");
+   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-----");
-  config = grub_malloc (config_len);
-
-  if (! config)
-goto quit;
-
-  grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
-
-  grub_net_search_configfile (config);
-
-

[PATCH v3 07/16] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2

2024-10-10 Thread Leo Sandoval
From: Mark Hamzy 

Add configuration support for ieee1275/PPC ofconsole serial terminal.

Signed-off-by: Mark Hamzy 
Signed-off-by: Robbie Harwood 
---
 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 0..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 .
+
+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


[PATCH v3 13/16] normal/main: fw_path prefix when fallback searching for grub config

2024-10-10 Thread Leo Sandoval
From: Fedora Ninjas 

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 
---
 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


[PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen

2024-10-10 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
Signed-off-by: Paulo Flabiano Smorigo 
Signed-off-by: Robbie Harwood 
---
 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 ("\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


[PATCH v2 22/30] btrfs: Add ability to boot from subvolumes

2024-10-11 Thread Leo Sandoval
From: Jeff Mahoney 

This patch adds the ability to specify a different root on a btrfs
filesystem too boot from other than the default one.

btrfs-list-snapshots  will list the subvolumes available on the
filesystem.

set btrfs_subvol= and set btrfs_subvolid= will specify
which subvolume to use and any pathnames provided with either of those
variables set will start using that root. If the subvolume or subvolume id
doesn't exist, then an error case will result.

It is possible to boot into a separate GRUB instance by exporting the
variable and loading the config file from the subvolume.

Signed-off-by: Jeff Mahoney 
---
 grub-core/fs/btrfs.c | 554 +--
 include/grub/btrfs.h |   1 +
 2 files changed, 534 insertions(+), 21 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index ba0c58352..f14fe9c1b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -38,6 +38,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -79,9 +82,11 @@ struct grub_btrfs_superblock
   grub_uint64_t generation;
   grub_uint64_t root_tree;
   grub_uint64_t chunk_tree;
-  grub_uint8_t dummy2[0x20];
+  grub_uint8_t dummy2[0x18];
+  grub_uint64_t bytes_used;
   grub_uint64_t root_dir_objectid;
-  grub_uint8_t dummy3[0x41];
+  grub_uint64_t num_devices;
+  grub_uint8_t dummy3[0x39];
   struct grub_btrfs_device this_device;
   char label[0x100];
   grub_uint8_t dummy4[0x100];
@@ -121,6 +126,7 @@ struct grub_btrfs_data
   grub_uint64_t exttree;
   grub_size_t extsize;
   struct grub_btrfs_extent_data *extent;
+  grub_uint64_t fs_tree;
 };
 
 struct grub_btrfs_chunk_item
@@ -191,6 +197,14 @@ struct grub_btrfs_leaf_descriptor
   } *data;
 };
 
+struct grub_btrfs_root_ref
+{
+  grub_uint64_t dirid;
+  grub_uint64_t sequence;
+  grub_uint16_t name_len;
+  const char name[0];
+} __attribute__ ((packed));
+
 struct grub_btrfs_time
 {
   grub_int64_t sec;
@@ -236,6 +250,14 @@ struct grub_btrfs_extent_data
 
 #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
 
+#define GRUB_BTRFS_ROOT_TREE_OBJECTID 1ULL
+#define GRUB_BTRFS_FS_TREE_OBJECTID 5ULL
+#define GRUB_BTRFS_ROOT_REF_KEY 156
+#define GRUB_BTRFS_ROOT_ITEM_KEY 132
+
+static grub_uint64_t btrfs_default_subvolid = 0;
+static char *btrfs_default_subvol = NULL;
+
 static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
   256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2
 };
@@ -1252,6 +1274,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, 
grub_disk_addr_t addr,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+grub_uint64_t objectid, grub_uint64_t offset,
+grub_uint64_t *fs_root);
+
+static grub_err_t
+lookup_root_by_id(struct grub_btrfs_data *data, grub_uint64_t id)
+{
+  grub_err_t err;
+  grub_uint64_t tree;
+
+  err = get_fs_root(data, data->sblock.root_tree, id, -1, &tree);
+  if (!err)
+data->fs_tree = tree;
+  return err;
+}
+
+static grub_err_t
+find_path (struct grub_btrfs_data *data,
+  const char *path, struct grub_btrfs_key *key,
+  grub_uint64_t *tree, grub_uint8_t *type);
+
+static grub_err_t
+lookup_root_by_name(struct grub_btrfs_data *data, const char *path)
+{
+  grub_err_t err;
+  grub_uint64_t tree = 0;
+  grub_uint8_t type;
+  struct grub_btrfs_key key;
+
+  err = find_path (data, path, &key, &tree, &type);
+  if (err)
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
+
+  if (key.object_id != grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0)
+return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path);
+
+  data->fs_tree = tree;
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused)))
+{
+  if (btrfs_default_subvol)
+return lookup_root_by_name(data, btrfs_default_subvol);
+
+  if (btrfs_default_subvolid)
+return lookup_root_by_id(data, btrfs_default_subvolid);
+
+  data->fs_tree = 0;
+
+  return GRUB_ERR_NONE;
+}
+
+
 static struct grub_btrfs_data *
 grub_btrfs_mount (grub_device_t dev)
 {
@@ -1287,6 +1365,13 @@ grub_btrfs_mount (grub_device_t dev)
   data->devices_attached[0].dev = dev;
   data->devices_attached[0].id = data->sblock.this_device.device_id;
 
+  err = btrfs_handle_subvol (data);
+  if (err)
+{
+  grub_free (data);
+  return NULL;
+}
+
   return data;
 }
 
@@ -1784,6 +1869,91 @@ get_root (struct grub_btrfs_data *data, struct 
grub_btrfs_key *key,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+find_pathname(struct grub_btrfs_data *data, grub_uint64_t objectid,
+  grub_uint64_t fs_root, const char *name, char **pathname)
+{
+  grub_err_t err;
+  struct grub_btrfs_key key = {
+.object_id = objectid,
+.type = GRUB_BTRFS_ITEM_TYPE_INODE_REF,
+.offset = 0,
+  };
+  struct grub_btrfs_key key_out;
+  struct grub_btrfs_leaf_descrip

[PATCH v2 30/30] chainloader: Use grub_efi_...() memory helpers where reasonable.

2024-10-11 Thread Leo Sandoval
From: Peter Jones 

This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and
grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we
get more reasonable type checking.

Signed-off-by: Peter Jones 
---
 grub-core/loader/efi/chainloader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/efi/chainloader.c 
b/grub-core/loader/efi/chainloader.c
index 1de98f783..203692450 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -95,7 +95,7 @@ grub_chainloader_boot (void *context)
 }
 
   if (exit_data)
-b->free_pool (exit_data);
+grub_efi_free_pool (exit_data);
 
   grub_loader_unset ();
 
@@ -419,7 +419,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ 
((unused)),
   grub_free (file_path);
 
   if (address)
-b->free_pages (address, pages);
+grub_efi_free_pages (address, pages);
 
   if (image_handle != NULL)
 b->unload_image (image_handle);
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 24/30] btrfs: export btrfs_subvol and btrfs_subvolid

2024-10-11 Thread Leo Sandoval
From: Michael Chang 

We should export btrfs_subvol and btrfs_subvolid to have both visible
to subsidiary configuration files loaded using configfile.

Signed-off-by: Michael Chang 
---
 grub-core/fs/btrfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 8e2b1e9f7..14e38a4df 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2920,6 +2920,8 @@ GRUB_MOD_INIT (btrfs)
subvol_set_env);
   grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env,
subvolid_set_env);
+  grub_env_export ("btrfs_subvol");
+  grub_env_export ("btrfs_subvolid");
 }
 
 GRUB_MOD_FINI (btrfs)
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 27/30] btrfs: Fallback to old subvol name scheme to support old snapshot config

2024-10-11 Thread Leo Sandoval
From: Andrei Borzenkov 

Ref: bsc#953538
---
 grub-core/fs/btrfs.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index d47f9ab03..c5b3fd116 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -1315,11 +1315,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const 
char *path)
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+lookup_root_by_name_fallback(struct grub_btrfs_data *data, const char *path)
+{
+  grub_err_t err;
+  grub_uint64_t tree = 0;
+  grub_uint8_t type;
+  struct grub_btrfs_key key;
+
+  err = find_path (data, path, &key, &tree, &type);
+  if (err)
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
+
+  if (key.object_id != grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0)
+return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path);
+
+  data->fs_tree = tree;
+  return GRUB_ERR_NONE;
+}
+
 static grub_err_t
 btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused)))
 {
   if (btrfs_default_subvol)
-return lookup_root_by_name(data, btrfs_default_subvol);
+{
+  grub_err_t err;
+  err = lookup_root_by_name(data, btrfs_default_subvol);
+
+  /* Fallback to old schemes */
+  if (err == GRUB_ERR_FILE_NOT_FOUND)
+   {
+ err = GRUB_ERR_NONE;
+ return lookup_root_by_name_fallback(data, btrfs_default_subvol);
+   }
+  return err;
+}
 
   if (btrfs_default_subvolid)
 return lookup_root_by_id(data, btrfs_default_subvolid);
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 28/30] btrfs: Grub not working correctly with btrfs snapshots (bsc#1026511)

2024-10-11 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c | 238 +++
 1 file changed, 238 insertions(+)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index c5b3fd116..1c9e14008 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2906,6 +2906,238 @@ out:
   return 0;
 }
 
+static grub_err_t
+grub_btrfs_get_parent_subvol_path (struct grub_btrfs_data *data,
+   grub_uint64_t child_id,
+   const char *child_path,
+   grub_uint64_t *parent_id,
+   char **path_out)
+{
+  grub_uint64_t fs_root = 0;
+  struct grub_btrfs_key key_in = {
+.object_id = child_id,
+.type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF,
+.offset = 0,
+  }, key_out;
+  struct grub_btrfs_root_ref *ref;
+  char *buf;
+  struct grub_btrfs_leaf_descriptor desc;
+  grub_size_t elemsize;
+  grub_disk_addr_t elemaddr;
+  grub_err_t err;
+  char *parent_path;
+
+  *parent_id = 0;
+  *path_out = 0;
+
+  err = lower_bound(data, &key_in, &key_out, data->sblock.root_tree,
+&elemaddr, &elemsize, &desc, 0);
+  if (err)
+return err;
+
+  if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF || elemaddr == 0)
+next(data, &desc, &elemaddr, &elemsize, &key_out);
+
+  if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF)
+{
+  free_iterator(&desc);
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("can't find root 
backrefs"));
+}
+
+  buf = grub_malloc(elemsize + 1);
+  if (!buf)
+{
+  free_iterator(&desc);
+  return grub_errno;
+}
+
+  err = grub_btrfs_read_logical(data, elemaddr, buf, elemsize, 0);
+  if (err)
+{
+  grub_free(buf);
+  free_iterator(&desc);
+  return err;
+}
+
+  buf[elemsize] = 0;
+  ref = (struct grub_btrfs_root_ref *)buf;
+
+  err = get_fs_root(data, data->sblock.root_tree, grub_le_to_cpu64 
(key_out.offset),
+0, &fs_root);
+  if (err)
+{
+  grub_free(buf);
+  free_iterator(&desc);
+  return err;
+}
+
+  find_pathname(data, grub_le_to_cpu64 (ref->dirid), fs_root, ref->name, 
&parent_path);
+
+  if (child_path)
+{
+  *path_out = grub_xasprintf ("%s/%s", parent_path, child_path);
+  grub_free (parent_path);
+}
+  else
+*path_out = parent_path;
+
+  *parent_id = grub_le_to_cpu64 (key_out.offset);
+
+  grub_free(buf);
+  free_iterator(&desc);
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_btrfs_get_default_subvolume_id (struct grub_btrfs_data *data, 
grub_uint64_t *id)
+{
+  grub_err_t err;
+  grub_disk_addr_t elemaddr;
+  grub_size_t elemsize;
+  struct grub_btrfs_key key, key_out;
+  struct grub_btrfs_dir_item *direl = NULL;
+  const char *ctoken = "default";
+  grub_size_t ctokenlen = sizeof ("default") - 1;
+
+  *id = 0;
+  key.object_id = data->sblock.root_dir_objectid;
+  key.type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key.offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
+  err = lower_bound (data, &key, &key_out, data->sblock.root_tree, &elemaddr, 
&elemsize,
+NULL, 0);
+  if (err)
+return err;
+
+  if (key_cmp (&key, &key_out) != 0)
+return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+
+  struct grub_btrfs_dir_item *cdirel;
+  direl = grub_malloc (elemsize + 1);
+  err = grub_btrfs_read_logical (data, elemaddr, direl, elemsize, 0);
+  if (err)
+{
+  grub_free (direl);
+  return err;
+}
+  for (cdirel = direl;
+   (grub_uint8_t *) cdirel - (grub_uint8_t *) direl
+   < (grub_ssize_t) elemsize;
+   cdirel = (void *) ((grub_uint8_t *) (direl + 1)
+   + grub_le_to_cpu16 (cdirel->n)
+   + grub_le_to_cpu16 (cdirel->m)))
+{
+  if (ctokenlen == grub_le_to_cpu16 (cdirel->n)
+&& grub_memcmp (cdirel->name, ctoken, ctokenlen) == 0)
+  break;
+}
+  if ((grub_uint8_t *) cdirel - (grub_uint8_t *) direl
+  >= (grub_ssize_t) elemsize)
+{
+  grub_free (direl);
+  err = grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+  return err;
+}
+
+  if (cdirel->key.type != GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM)
+{
+  grub_free (direl);
+  err = grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+  return err;
+}
+
+  *id = grub_le_to_cpu64 (cdirel->key.object_id);
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_cmd_btrfs_get_default_subvol (struct grub_extcmd_context *ctxt,
+int argc, char **argv)
+{
+  char *devname;
+  grub_device_t dev;
+  struct grub_btrfs_data *data;
+  grub_err_t err;
+  grub_uint64_t id;
+  char *subvol = NULL;
+  grub_uint64_t subvolid = 0;
+  char *varname = NULL;
+  char *output = NULL;
+  int path_only = ctxt->state[1].set;
+  int num_only = ctxt->state[2].set;
+
+  if (ctxt->state[0].set)
+varname = ctxt->state[0].arg;
+
+  if (argc < 1)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
+

[PATCH v2 18/30] grub-set-password.in: Add friendly grub2 password config tool (#985962)

2024-10-11 Thread Leo Sandoval
From: Robert Marshall 

Provided a tool for users to reset the grub2 root user password
without having to alter the grub.cfg. The hashed password now
lives in a root-only-readable configuration file.

Resolves: rhbz#985962

Signed-off-by: Robert Marshall 
[pjones: fix the efidir in grub-setpassword and rename tool]
Signed-off-by: Peter Jones 
[luto: fix grub-setpassword -o's output path]
Signed-off-by: Andy Lutomirski 
[rharwood: migrate man page to h2m, context]
Signed-off-by: Robbie Harwood 
---
 Makefile.util.def  |  13 
 configure.ac   |   1 +
 docs/man/grub-set-password.h2m |   2 +
 util/grub-mkconfig.in  |   2 +
 util/grub-set-password.in  | 121 +
 util/grub.d/01_users.in|  11 +++
 6 files changed, 150 insertions(+)
 create mode 100644 docs/man/grub-set-password.h2m
 create mode 100644 util/grub-set-password.in
 create mode 100644 util/grub.d/01_users.in

diff --git a/Makefile.util.def b/Makefile.util.def
index 09bfcadd9..95884956a 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -455,6 +455,12 @@ script = {
   installdir = grubconf;
 };
 
+script = {
+  name = '01_users';
+  common = util/grub.d/01_users.in;
+  installdir = grubconf;
+};
+
 script = {
   name = '10_windows';
   common = util/grub.d/10_windows.in;
@@ -733,6 +739,13 @@ script = {
   installdir = sbin;
 };
 
+script = {
+  name = grub-set-password;
+  common = util/grub-set-password.in;
+  mansection = 8;
+  installdir = sbin;
+};
+
 script = {
   name = grub-mkconfig_lib;
   common = util/grub-mkconfig_lib.in;
diff --git a/configure.ac b/configure.ac
index ae3a49321..493e336ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,6 +77,7 @@ grub_TRANSFORM([grub-mkrelpath])
 grub_TRANSFORM([grub-mkrescue])
 grub_TRANSFORM([grub-probe])
 grub_TRANSFORM([grub-reboot])
+grub_TRANSFORM([grub-set-password])
 grub_TRANSFORM([grub-script-check])
 grub_TRANSFORM([grub-set-default])
 grub_TRANSFORM([grub-sparc64-setup])
diff --git a/docs/man/grub-set-password.h2m b/docs/man/grub-set-password.h2m
new file mode 100644
index 0..10ee82f4d
--- /dev/null
+++ b/docs/man/grub-set-password.h2m
@@ -0,0 +1,2 @@
+[NAME]
+grub-set-password \- generate the user.cfg file containing the hashed grub 
bootloader password
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index d1bf4983b..9d5d7964b 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -283,6 +283,8 @@ for i in "${grub_mkconfig_dir}"/* ; do
 *~) ;;
 # emacsen autosave files. FIXME: support other editors
 */\#*\#) ;;
+# rpm config files of yore.
+*.rpmsave|*.rpmnew|*.rpmorig) ;;
 *)
   if grub_file_is_not_garbage "$i" && test -x "$i" ; then
 echo
diff --git a/util/grub-set-password.in b/util/grub-set-password.in
new file mode 100644
index 0..d8005e5a1
--- /dev/null
+++ b/util/grub-set-password.in
@@ -0,0 +1,121 @@
+#!/bin/sh -e
+
+grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
+
+PACKAGE_VERSION="@PACKAGE_VERSION@"
+PACKAGE_NAME="@PACKAGE_NAME@"
+self=`basename $0`
+bindir="@bindir@"
+grub_mkpasswd="${bindir}/@grub_mkpasswd_pbkdf2@"
+
+# Usage: usage
+# Print the usage.
+usage () {
+cat <  put user.cfg in a user-selected directory
+
+Report bugs at https://bugzilla.redhat.com.
+EOF
+}
+
+argument () {
+opt=$1
+shift
+
+if test $# -eq 0; then
+gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" 
"$opt" 1>&2
+exit 1
+fi
+echo $1
+}
+
+# Ensure that it's the root user running this script
+if [ "${EUID}" -ne 0 ]; then
+echo "The grub bootloader password may only be set by root."
+usage
+exit 2
+fi
+
+# Check the arguments.
+while test $# -gt 0
+do
+option=$1
+shift
+
+case "$option" in
+-h | --help)
+   usage
+   exit 0 ;;
+-v | --version)
+   echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
+   exit 0 ;;
+-o | --output)
+OUTPUT_PATH=`argument $option "$@"`; shift ;;
+--output=*)
+OUTPUT_PATH=`echo "$option" | sed 's/--output=//'` ;;
+-o=*)
+OUTPUT_PATH=`echo "$option" | sed 's/-o=//'` ;;
+esac
+done
+
+# set user input or default path for user.cfg file
+if [ -z "${OUTPUT_PATH}" ]; then
+OUTPUT_PATH="${grubdir}"
+fi
+
+if [ ! -d "${OUTPUT_PATH}" ]; then
+echo "${OUTPUT_PATH} does not exist."
+usage
+exit 2;
+fi
+
+ttyopt=$(stty -g)
+fixtty() {
+  stty ${ttyopt}
+}
+
+trap fixtty EXIT
+stty -echo
+
+# prompt & confirm new grub2 root user password
+echo -n "Enter password: "
+read PASSWORD
+echo
+echo -n "Confirm password: "
+read PASSWORD_CONFIRM
+echo
+stty ${ttyopt}
+
+getpass() {
+local P0
+local P1
+P0="$1" && shift
+P1="$1" && shift
+
+( echo ${P0} ; echo ${P1} ) | \
+LC_ALL=C ${grub_mkpasswd} | \
+grep -v '[eE]nter password:' | \
+sed -e "s/PBKDF2 hash of your password is //"
+}
+
+MYPASS="$(getpass "${PASSWORD}" "$

[PATCH v2 25/30] btrfs: grub2-btrfs-03-follow_default

2024-10-11 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c | 107 ++-
 1 file changed, 76 insertions(+), 31 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 14e38a4df..d47f9ab03 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -1335,6 +1335,7 @@ grub_btrfs_mount (grub_device_t dev)
 {
   struct grub_btrfs_data *data;
   grub_err_t err;
+  const char *relpath = grub_env_get ("btrfs_relative_path");
 
   if (!dev->disk)
 {
@@ -1365,11 +1366,14 @@ grub_btrfs_mount (grub_device_t dev)
   data->devices_attached[0].dev = dev;
   data->devices_attached[0].id = data->sblock.this_device.device_id;
 
-  err = btrfs_handle_subvol (data);
-  if (err)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
 {
-  grub_free (data);
-  return NULL;
+  err = btrfs_handle_subvol (data);
+  if (err)
+  {
+grub_free (data);
+return NULL;
+  }
 }
 
   return data;
@@ -1966,24 +1970,39 @@ find_path (struct grub_btrfs_data *data,
   grub_size_t allocated = 0;
   struct grub_btrfs_dir_item *direl = NULL;
   struct grub_btrfs_key key_out;
+  int follow_default;
   const char *ctoken;
   grub_size_t ctokenlen;
   char *path_alloc = NULL;
   char *origpath = NULL;
   unsigned symlinks_max = 32;
+  const char *relpath = grub_env_get ("btrfs_relative_path");
 
+  follow_default = 0;
   origpath = grub_strdup (path);
   if (!origpath)
 return grub_errno;
 
-  if (data->fs_tree)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
 {
-  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
-  *tree = data->fs_tree;
-  /* This is a tree root, so everything starts at objectid 256 */
-  key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
-  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
-  key->offset = 0;
+  if (data->fs_tree)
+{
+  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+  *tree = data->fs_tree;
+  /* This is a tree root, so everything starts at objectid 256 */
+  key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
+  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key->offset = 0;
+}
+  else
+{
+  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+  *tree = data->sblock.root_tree;
+  key->object_id = data->sblock.root_dir_objectid;
+  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key->offset = 0;
+  follow_default = 1;
+}
 }
   else
 {
@@ -1994,15 +2013,23 @@ find_path (struct grub_btrfs_data *data,
 
   while (1)
 {
-  while (path[0] == '/')
-   path++;
-  if (!path[0])
-   break;
-  slash = grub_strchr (path, '/');
-  if (!slash)
-   slash = path + grub_strlen (path);
-  ctoken = path;
-  ctokenlen = slash - path;
+  if (!follow_default)
+   {
+ while (path[0] == '/')
+   path++;
+ if (!path[0])
+   break;
+ slash = grub_strchr (path, '/');
+ if (!slash)
+   slash = path + grub_strlen (path);
+ ctoken = path;
+ ctokenlen = slash - path;
+   }
+  else
+   {
+ ctoken = "default";
+ ctokenlen = sizeof ("default") - 1;
+   }
 
   if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
{
@@ -2013,7 +2040,9 @@ find_path (struct grub_btrfs_data *data,
 
   if (ctokenlen == 1 && ctoken[0] == '.')
{
- path = slash;
+ if (!follow_default)
+   path = slash;
+ follow_default = 0;
  continue;
}
   if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.')
@@ -2044,8 +2073,9 @@ find_path (struct grub_btrfs_data *data,
  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
  key->object_id = key_out.offset;
 
- path = slash;
-
+ if (!follow_default)
+   path = slash;
+ follow_default = 0;
  continue;
}
 
@@ -2114,7 +2144,9 @@ find_path (struct grub_btrfs_data *data,
  return err;
}
 
-  path = slash;
+  if (!follow_default)
+   path = slash;
+  follow_default = 0;
   if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK)
{
  struct grub_btrfs_inode inode;
@@ -2164,14 +2196,26 @@ find_path (struct grub_btrfs_data *data,
  path = path_alloc = tmp;
  if (path[0] == '/')
{
- if (data->fs_tree)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
{
- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
- *tree = data->fs_tree;
- /* This is a tree root, so everything starts at objectid 256 
*/
- key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
- key->type = GRUB_B

[PATCH v2 23/30] btrfs: fix a bad null check

2024-10-11 Thread Leo Sandoval
From: Peter Jones 

current gcc complains:

  grub-core/fs/btrfs.c: In function ‘grub_cmd_btrfs_info’:
  grub-core/fs/btrfs.c:2745:7: error: the comparison will always evaluate as 
‘true’ for the address of ‘label’ will never be NULL [-Werror=address]
   2745 |   if (data->sblock.label)
|   ^~~~
  grub-core/fs/btrfs.c:92:8: note: ‘label’ declared here
 92 |   char label[0x100];
|^
  cc1: all warnings being treated as errors

Obviously this check should be on the first data byte instead of the
symbol itself.

Signed-off-by: Peter Jones 
---
 grub-core/fs/btrfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index f14fe9c1b..8e2b1e9f7 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2625,7 +2625,7 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ 
((unused)), int argc,
   return grub_error (GRUB_ERR_BAD_ARGUMENT, "failed to open fs");
 }
 
-  if (data->sblock.label)
+  if (data->sblock.label[0])
 grub_printf("Label: '%s' ", data->sblock.label);
   else
 grub_printf("Label: none ");
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 21/30] 30_os-prober.in: just build chainloader entries, don't try any xnu xnu.

2024-10-11 Thread Leo Sandoval
From: Peter Jones 

Since our bugs tell us that the xnu boot entries really just don't work
most of the time, and they create piles of extra boot entries, because
they can't quite figure out 32-vs-64 and other stuff like that.

It's rediculous, and we should just boot their bootloader through the
chainloader instead.

So this patch does that.

Resolves: rhbz#893179

Signed-off-by: Peter Jones 
---
 util/grub.d/30_os-prober.in | 78 +
 1 file changed, 18 insertions(+), 60 deletions(-)

diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index 656301eaf..1aac097c1 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -45,68 +45,25 @@ if [ -z "${OSPROBED}" ] ; then
 fi
 
 osx_entry() {
-if [ x$2 = x32 ]; then
-# TRANSLATORS: it refers to kernel architecture (32-bit)
-   bitstr="$(gettext "(32-bit)")"
-else
-# TRANSLATORS: it refers to kernel architecture (64-bit)
-   bitstr="$(gettext "(64-bit)")"
-fi
 # TRANSLATORS: it refers on the OS residing on device %s
 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-cat << EOF
-menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx 
--class darwin --class os \$menuentry_id_option 
'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
+hints=""
+for hint in `"${grub_probe}" --device ${device} --target=efi_hints 2> 
/dev/null` ; do
+  hints="${hints} --hint=${hint}"
+done
+cat << EOF
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class osx --class 
darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id 
"${DEVICE}")'  {
 EOF
save_default_entry | grub_add_tab
prepare_grub_to_access_device ${DEVICE} | grub_add_tab
cat << EOF
+   set gfxpayload=keep
 load_video
-set do_resume=0
-if [ /var/vm/sleepimage -nt10 / ]; then
-   if xnu_resume /var/vm/sleepimage; then
- set do_resume=1
-   fi
-fi
-if [ \$do_resume = 0 ]; then
-   xnu_uuid ${OSXUUID} uuid
-   if [ -f /Extra/DSDT.aml ]; then
-  acpi -e /Extra/DSDT.aml
-   fi
-   if [ /kernelcache -nt /System/Library/Extensions ]; then
-  $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
-   elif [ -f /System/Library/Kernels/kernel ]; then
-  $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid
-  xnu_kextdir /System/Library/Extensions
-   else
-  $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
-  if [ /System/Library/Extensions.mkext -nt 
/System/Library/Extensions ]; then
-xnu_mkext /System/Library/Extensions.mkext
-  else
-xnu_kextdir /System/Library/Extensions
-  fi
-   fi
-   if [ -f /Extra/Extensions.mkext ]; then
-  xnu_mkext /Extra/Extensions.mkext
-   fi
-   if [ -d /Extra/Extensions ]; then
-  xnu_kextdir /Extra/Extensions
-   fi
-   if [ -f /Extra/devprop.bin ]; then
-  xnu_devprop_load /Extra/devprop.bin
-   fi
-   if [ -f /Extra/splash.jpg ]; then
-  insmod jpeg
-  xnu_splash /Extra/splash.jpg
-   fi
-   if [ -f /Extra/splash.png ]; then
-  insmod png
-  xnu_splash /Extra/splash.png
-   fi
-   if [ -f /Extra/splash.tga ]; then
-  insmod tga
-  xnu_splash /Extra/splash.tga
-   fi
-fi
+   insmod part_gpt
+   insmod hfsplus
+   search --no-floppy --fs-uuid --set=root ${hints} $(grub_get_device_id 
"${DEVICE}")
+   chainloader (\$root)/System/Library/CoreServices/boot.efi
+   boot
 }
 EOF
 }
@@ -299,11 +256,12 @@ EOF
   echo "$title_correction_code"
 ;;
 macosx)
-  if [ "${UUID}" ]; then
-   OSXUUID="${UUID}"
-   osx_entry xnu_kernel 32
-   osx_entry xnu_kernel64 64
-  fi
+  for subdevice in ${DEVICE%[[:digit:]]*}* ; do
+   parttype="`"${grub_probe}" --device ${device} --target=gpt_parttype 
"${subdevice}" 2> /dev/null`"
+   if [[ "$parttype" = "426f6f74--11aa-aa11-00306543ecac" ]]; then
+ DEVICE="${subdevice}" osx_entry
+   fi
+  done
 ;;
 hurd)
   onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 20/30] grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it in 10_linux

2024-10-11 Thread Leo Sandoval
From: Peter Jones 

This patch adds grub-get-kernel-settings, which reads the system kernel
installation configuration from /etc/sysconfig/kernel, and outputs
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
variables are then used by 10_linux to choose whether or not to create
debug stanzas.

Resolves: rhbz#1226325
[rharwood: migrate man page to h2m]
---
 Makefile.util.def |  7 ++
 configure.ac  |  1 +
 docs/man/grub-get-kernel-settings.h2m |  2 +
 .../bash-completion.d/grub-completion.bash.in | 22 +
 util/grub-get-kernel-settings.in  | 88 +++
 util/grub-mkconfig.in |  3 +
 util/grub.d/10_linux.in   | 23 +++--
 7 files changed, 141 insertions(+), 5 deletions(-)
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
 create mode 100644 util/grub-get-kernel-settings.in

diff --git a/Makefile.util.def b/Makefile.util.def
index 95884956a..84a17ef5c 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -725,6 +725,13 @@ script = {
   installdir = sbin;
 };
 
+script = {
+  name = grub-get-kernel-settings;
+  common = util/grub-get-kernel-settings.in;
+  mansection = 3;
+  installdir = sbin;
+};
+
 script = {
   name = grub-set-default;
   common = util/grub-set-default.in;
diff --git a/configure.ac b/configure.ac
index 493e336ec..3602b4ab6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,7 @@ grub_TRANSFORM([grub-install])
 grub_TRANSFORM([grub-mkconfig])
 grub_TRANSFORM([grub-mkfont])
 grub_TRANSFORM([grub-mkimage])
+grub_TRANSFORM([grub-get-kernel-settings])
 grub_TRANSFORM([grub-glue-efi])
 grub_TRANSFORM([grub-mklayout])
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
diff --git a/docs/man/grub-get-kernel-settings.h2m 
b/docs/man/grub-get-kernel-settings.h2m
new file mode 100644
index 0..b8051f01f
--- /dev/null
+++ b/docs/man/grub-get-kernel-settings.h2m
@@ -0,0 +1,2 @@
+[NAME]
+grub-get-kernel-settings \- Evaluate the system's kernel installation settings 
for use while making a grub configuration file
diff --git a/util/bash-completion.d/grub-completion.bash.in 
b/util/bash-completion.d/grub-completion.bash.in
index 213ce1e57..da7fca5ef 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -275,6 +275,28 @@ have ${__grub_sparc64_setup_program} && \
 unset __grub_sparc64_setup_program
 
 
+#
+# grub-get-kernel-settings
+#
+_grub_get_kernel_settings () {
+local cur
+
+COMPREPLY=()
+cur=`_get_cword`
+
+if [[ "$cur" == -* ]]; then
+__grubcomp "$(__grub_get_options_from_help)"
+else
+# Default complete with a filename
+_filedir
+fi
+}
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
+have ${__grub_get_kernel_settings_program} && \
+ complete -F _grub_get_kernel_settings -o filenames 
${__grub_get_kernel_settings_program}
+unset __grub_get_kernel_settings_program
+
+
 #
 # grub-install
 #
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
new file mode 100644
index 0..7e87dfccc
--- /dev/null
+++ b/util/grub-get-kernel-settings.in
@@ -0,0 +1,88 @@
+#!/bin/sh
+set -e
+
+# Evaluate new-kernel-pkg's configuration file.
+# Copyright (C) 2016 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 .
+
+PACKAGE_NAME=@PACKAGE_NAME@
+PACKAGE_VERSION=@PACKAGE_VERSION@
+datadir="@datadir@"
+if [ "x$pkgdatadir" = x ]; then
+pkgdatadir="${datadir}/@PACKAGE@"
+fi
+
+self=`basename $0`
+
+export TEXTDOMAIN=@PACKAGE@
+export TEXTDOMAINDIR="@localedir@"
+
+. "${pkgdatadir}/grub-mkconfig_lib"
+
+# Usage: usage
+# Print the usage.
+usage () {
+gettext_printf "Usage: %s [OPTION]\n" "$self"
+gettext "Evaluate new-kernel-pkg configuration"; echo
+echo
+print_option_help "-h, --help" "$(gettext "print this message and exit")"
+print_option_help "-v, --version" "$(gettext "print the version 
information and exit")"
+echo
+}
+
+# Check the arguments.
+while test $# -gt 0
+do
+option=$1
+shift
+
+case "$option" in
+-h | --help)
+   usage
+   exit 0 ;;
+-v | --version)
+   echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
+   exit 0 ;;
+-*)
+   gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
+   usage
+   exit 1
+   ;

[PATCH v2 26/30] btdfs: grub2-btrfs-05-grub2-mkconfig

2024-10-11 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
---
 util/grub-mkconfig.in   |  3 ++-
 util/grub-mkconfig_lib.in   |  4 
 util/grub.d/00_header.in| 26 +-
 util/grub.d/10_linux.in |  4 
 util/grub.d/20_linux_xen.in |  4 
 5 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 91f761331..ad5b778e3 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -259,7 +259,8 @@ export GRUB_DEFAULT \
   GRUB_BADRAM \
   GRUB_OS_PROBER_SKIP_LIST \
   GRUB_DISABLE_SUBMENU \
-  GRUB_DEFAULT_DTB
+  GRUB_DEFAULT_DTB \
+  SUSE_BTRFS_SNAPSHOT_BOOTING
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 33e1750ae..0ba0e0e1c 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -49,7 +49,11 @@ grub_warn ()
 
 make_system_path_relative_to_its_root ()
 {
+  if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
+  "${grub_mkrelpath}" -r "$1"
+  else
   "${grub_mkrelpath}" "$1"
+  fi
 }
 
 is_path_readable_by_grub ()
diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
index 6a316a5ba..4ed7975a9 100644
--- a/util/grub.d/00_header.in
+++ b/util/grub.d/00_header.in
@@ -27,6 +27,15 @@ export TEXTDOMAINDIR="@localedir@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+cat /dev/null || true`
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 19/30] net/tcp: add window scaling support

2024-10-11 Thread Leo Sandoval
From: Josef Bacik 

Sometimes we have to provision boxes across regions, such as California to
Sweden.  The http server has a 10 minute timeout, so if we can't get our 250mb
image transferred fast enough our provisioning fails, which is not ideal.  So
add tcp window scaling on open connections and set the window size to 1mb.  With
this change we're able to get higher sustained transfers between regions and can
transfer our image in well below 10 minutes.  Without this patch we'd time out
every time halfway through the transfer.  Thanks,

Signed-off-by: Josef Bacik 
---
 grub-core/net/tcp.c | 42 +-
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c
index 93dee0caa..902ab7e8a 100644
--- a/grub-core/net/tcp.c
+++ b/grub-core/net/tcp.c
@@ -106,6 +106,18 @@ struct tcphdr
   grub_uint16_t urgent;
 } GRUB_PACKED;
 
+struct tcp_scale_opt {
+  grub_uint8_t kind;
+  grub_uint8_t length;
+  grub_uint8_t scale;
+} GRUB_PACKED;
+
+struct tcp_synhdr {
+  struct tcphdr tcphdr;
+  struct tcp_scale_opt scale_opt;
+  grub_uint8_t padding;
+};
+
 struct tcp_pseudohdr
 {
   grub_uint32_t src;
@@ -571,7 +583,7 @@ grub_net_tcp_open (char *server,
   grub_net_tcp_socket_t socket;
   static grub_uint16_t in_port = 21550;
   struct grub_net_buff *nb;
-  struct tcphdr *tcph;
+  struct tcp_synhdr *tcph;
   int i;
   grub_uint8_t *nbd;
   grub_net_link_level_address_t ll_target_addr;
@@ -640,20 +652,24 @@ grub_net_tcp_open (char *server,
 }
 
   tcph = (void *) nb->data;
+  grub_memset(tcph, 0, sizeof (*tcph));
   socket->my_start_seq = grub_get_time_ms ();
   socket->my_cur_seq = socket->my_start_seq + 1;
-  socket->my_window = 8192;
-  tcph->seqnr = grub_cpu_to_be32 (socket->my_start_seq);
-  tcph->ack = grub_cpu_to_be32_compile_time (0);
-  tcph->flags = grub_cpu_to_be16_compile_time ((5 << 12) | TCP_SYN);
-  tcph->window = grub_cpu_to_be16 (socket->my_window);
-  tcph->urgent = 0;
-  tcph->src = grub_cpu_to_be16 (socket->in_port);
-  tcph->dst = grub_cpu_to_be16 (socket->out_port);
-  tcph->checksum = 0;
-  tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
-  &socket->inf->address,
-  &socket->out_nla);
+  socket->my_window = 32768;
+  tcph->tcphdr.seqnr = grub_cpu_to_be32 (socket->my_start_seq);
+  tcph->tcphdr.ack = grub_cpu_to_be32_compile_time (0);
+  tcph->tcphdr.flags = grub_cpu_to_be16_compile_time ((6 << 12) | TCP_SYN);
+  tcph->tcphdr.window = grub_cpu_to_be16 (socket->my_window);
+  tcph->tcphdr.urgent = 0;
+  tcph->tcphdr.src = grub_cpu_to_be16 (socket->in_port);
+  tcph->tcphdr.dst = grub_cpu_to_be16 (socket->out_port);
+  tcph->tcphdr.checksum = 0;
+  tcph->scale_opt.kind = 3;
+  tcph->scale_opt.length = 3;
+  tcph->scale_opt.scale = 5;
+  tcph->tcphdr.checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
+ &socket->inf->address,
+ &socket->out_nla);
 
   tcp_socket_register (socket);
 
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 17/30] 10_linux.in: Make grub2-mkconfig construct titles that look like the ones we want elsewhere.

2024-10-11 Thread Leo Sandoval
From: Peter Jones 

Resolves: rhbz#1215839

Signed-off-by: Peter Jones 
---
 util/grub.d/10_linux.in | 34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 3105c31e4..0115dd0c0 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -80,6 +80,32 @@ case x"$GRUB_FS" in
;;
 esac
 
+mktitle ()
+{
+  local title_type
+  local version
+  local OS_NAME
+  local OS_VERS
+
+  title_type=$1 && shift
+  version=$1 && shift
+
+  OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})"
+  OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
+
+  case $title_type in
+recovery)
+  title=$(printf '%s (%s) %s (recovery mode)' \
+ "${OS_NAME}" "${version}" "${OS_VERS}")
+  ;;
+*)
+  title=$(printf '%s (%s) %s' \
+ "${OS_NAME}" "${version}" "${OS_VERS}")
+  ;;
+  esac
+  echo -n ${title}
+}
+
 title_correction_code=
 
 linux_entry ()
@@ -93,17 +119,11 @@ linux_entry ()
   boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
   fi
   if [ x$type != xsimple ] ; then
-  case $type in
- recovery)
- title="$(gettext_printf "%s, with Linux %s (recovery mode)" 
"${os}" "${version}")" ;;
- *)
- title="$(gettext_printf "%s, with Linux %s" "${os}" 
"${version}")" ;;
-  esac
+  title=$(mktitle "$type" "$version")
   if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux 
versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  replacement_title="$(echo "Advanced options for ${OS}" | sed 
's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  title_correction_code="${title_correction_code}if [ \"x\$default\" = 
'$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
- grub_warn "$(gettext_printf "Please don't use old title \`%s' for 
GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or 
later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" 
"gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
   fi
   echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} 
\$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed 
"s/^/$submenu_indentation/"
   else
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 00/30] Second Distro-agnostic series taken from Fedora Rawhide

2024-10-11 Thread Leo Sandoval
This is the second 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.

Changes since v1:
- delete 0024-efinet-and-bootp-add-support-for-dhcpv6.patch
  build issue, so for the moment discarting it

- delete 0025-bootp-New-net_bootp6-command.patch
  patch will be sent separately by mchang

- delete 0027-Make-grub_fatal-also-backtrace.patch
  not accepted

- delete 0028-Make-our-info-pages-say-grub2-where-appropriate.patch
  non-distro agnostic

- delete 0034-grub2-btrfs-04-grub2-install.patch
  patch will be revisited by author (mchang)

- delete 0036-grub2-btrfs-06-subvol-mount.patch
  not accepted

Andrei Borzenkov (1):
  btrfs: Fallback to old subvol name scheme to support old snapshot
config

Jeff Mahoney (1):
  btrfs: Add ability to boot from subvolumes

Josef Bacik (1):
  net/tcp: add window scaling support

Michael Chang (4):
  btrfs: export btrfs_subvol and btrfs_subvolid
  btrfs: grub2-btrfs-03-follow_default
  btdfs: grub2-btrfs-05-grub2-mkconfig
  btrfs: Grub not working correctly with btrfs snapshots (bsc#1026511)

Peter Jones (6):
  10_linux.in: Make grub2-mkconfig construct titles that look like the
ones we want elsewhere.
  grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it
in 10_linux
  30_os-prober.in: just build chainloader entries, don't try any xnu
xnu.
  btrfs: fix a bad null check
  efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.
  chainloader: Use grub_efi_...() memory helpers where reasonable.

Robert Marshall (1):
  grub-set-password.in: Add friendly grub2 password config tool
(#985962)

 Makefile.util.def |  20 +
 configure.ac  |   2 +
 docs/man/grub-get-kernel-settings.h2m |   2 +
 docs/man/grub-set-password.h2m|   2 +
 grub-core/fs/btrfs.c  | 895 +-
 grub-core/loader/efi/chainloader.c|   4 +-
 grub-core/net/tcp.c   |  42 +-
 include/grub/btrfs.h  |   1 +
 include/grub/efi/efi.h|  36 +-
 .../bash-completion.d/grub-completion.bash.in |  22 +
 util/grub-get-kernel-settings.in  |  88 ++
 util/grub-mkconfig.in |   8 +-
 util/grub-mkconfig_lib.in |   4 +
 util/grub-set-password.in | 121 +++
 util/grub.d/00_header.in  |  26 +-
 util/grub.d/01_users.in   |  11 +
 util/grub.d/10_linux.in   |  61 +-
 util/grub.d/20_linux_xen.in   |   4 +
 util/grub.d/30_os-prober.in   |  78 +-
 19 files changed, 1300 insertions(+), 127 deletions(-)
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
 create mode 100644 docs/man/grub-set-password.h2m
 create mode 100644 util/grub-get-kernel-settings.in
 create mode 100644 util/grub-set-password.in
 create mode 100644 util/grub.d/01_users.in

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 29/30] efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.

2024-10-11 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 include/grub/efi/efi.h | 36 
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index a5cd99e5a..8d98203a7 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -36,6 +36,10 @@ struct linux_arch_kernel_header {
   struct grub_pe_image_header pe_image_header;
 };
 
+/* Variables.  */
+extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
+extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
+
 /* Functions.  */
 void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
 void *registration);
@@ -71,6 +75,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t 
*memory_map_size,
  grub_efi_uintn_t *descriptor_size,
  grub_efi_uint32_t *descriptor_version);
 void grub_efi_memory_fini (void);
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_allocate_pool (grub_efi_memory_type_t pool_type,
+   grub_efi_uintn_t buffer_size,
+   void **buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->allocate_pool(pool_type, buffer_size, buffer);
+  return status;
+}
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_free_pool (void *buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->free_pool(buffer);
+  return status;
+}
+
 grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) 
(grub_efi_handle_t image_handle);
 void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);
 char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
@@ -140,10 +171,7 @@ void grub_efi_init (void);
 void grub_efi_fini (void);
 void grub_efi_set_prefix (void);
 
-/* Variables.  */
-extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
-extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
-
+/* More variables.  */
 extern int EXPORT_VAR(grub_efi_is_finished);
 
 struct grub_net_card;
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 10/17] 10_linux.in: Add devicetree loading

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 

Switch to use APM Mustang device tree, for hardware testing.

Signed-off-by: David A. Marlin 

Use the default device tree from the grub default file

instead of hardcoding a value.

Signed-off-by: David A. Marlin 
---
 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


[PATCH v2 17/17] normal/main: Try $prefix if $fw_path doesn't work.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Related: rhbz#1148652

Signed-off-by: Peter Jones 
---
 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-----");
+   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-----");
-  config = grub_malloc (config_len);
-
-  if (! config)
-goto quit;
-
-  grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
-
-  grub_net_search_configfile (config);
-
-

[PATCH v2 14/17] normal/main: fw_path prefix when fallback searching for grub config

2024-10-07 Thread Leo Sandoval
From: Fedora Ninjas 

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 
---
 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


[PATCH v2 01/17] ieee1275/openfw: IBM client architecture (CAS) reboot support

2024-10-07 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
[rharw...@redhat.com: commit message rewrap]
Signed-off-by: Robbie Harwood 
---
 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 
 #include 
 #include 
+#ifdef GRUB_MACHINE_IEEE1275
+#include 
+#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 
 #include 
 #include 
+#ifdef GRUB_MACHINE_IEEE1275
+#include 
+#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 *so

[PATCH v2 15/17] normal/main: Try mac/guid/etc before grub.cfg on tftp config files.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 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-----");
-  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-----");
+  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


[PATCH v2 16/17] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

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 
---
 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


[PATCH v1 21/37] efinet and bootp: add support for dhcpv6

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 grub-core/net/bootp.c  | 173 +
 grub-core/net/drivers/efi/efinet.c |  86 +-
 grub-core/net/net.c|  72 
 grub-core/net/tftp.c   |   3 +
 include/grub/efi/api.h | 129 -
 include/grub/net.h |  60 ++
 6 files changed, 492 insertions(+), 31 deletions(-)

diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index abe45ef7b..02d2c2614 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -905,6 +905,179 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ 
((unused)),
 
 static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp;
 
+struct grub_net_network_level_interface *
+grub_net_configure_by_dhcpv6_ack (const char *name,
+ struct grub_net_card *card,
+ grub_net_interface_flags_t flags
+   __attribute__((__unused__)),
+ const grub_net_link_level_address_t *hwaddr,
+ const struct grub_net_dhcpv6_packet *packet,
+ int is_def, char **device, char **path)
+{
+  struct grub_net_network_level_interface *inter = NULL;
+  struct grub_net_network_level_address addr;
+  int mask = -1;
+
+  if (!device || !path)
+return NULL;
+
+  *device = 0;
+  *path = 0;
+
+  grub_dprintf ("net", "mac address is %02x:%02x:%02x:%02x:%02x:%02x\n",
+   hwaddr->mac[0], hwaddr->mac[1], hwaddr->mac[2],
+   hwaddr->mac[3], hwaddr->mac[4], hwaddr->mac[5]);
+
+  if (is_def)
+grub_net_default_server = 0;
+
+  if (is_def && !grub_net_default_server && packet)
+{
+  const grub_uint8_t *options = packet->dhcp_options;
+  unsigned int option_max = 1024 - OFFSET_OF (dhcp_options, packet);
+  unsigned int i;
+
+  for (i = 0; i < option_max - sizeof (grub_net_dhcpv6_option_t); )
+   {
+ grub_uint16_t num, len;
+ grub_net_dhcpv6_option_t *opt =
+   (grub_net_dhcpv6_option_t *)(options + i);
+
+ num = grub_be_to_cpu16(opt->option_num);
+ len = grub_be_to_cpu16(opt->option_len);
+
+ grub_dprintf ("net", "got dhcpv6 option %d len %d\n", num, len);
+
+ if (len == 0)
+   break;
+
+ if (len + i > 1024)
+   break;
+
+ if (num == GRUB_NET_DHCP6_BOOTFILE_URL)
+   {
+ char *scheme, *userinfo, *host, *file;
+ char *tmp;
+ int hostlen;
+ int port;
+ int rc = extract_url_info ((const char *)opt->option_data,
+(grub_size_t)len,
+&scheme, &userinfo, &host, &port,
+&file);
+ if (rc < 0)
+   continue;
+
+ /* right now this only handles tftp. */
+ if (grub_strcmp("tftp", scheme))
+   {
+ grub_free (scheme);
+ grub_free (userinfo);
+ grub_free (host);
+ grub_free (file);
+ continue;
+   }
+ grub_free (userinfo);
+
+ hostlen = grub_strlen (host);
+ if (hostlen > 2 && host[0] == '[' && host[hostlen-1] == ']')
+   {
+ tmp = host+1;
+ host[hostlen-1] = '\0';
+   }
+ else
+   tmp = host;
+
+ *device = grub_xasprintf ("%s,%s", scheme, tmp);
+ grub_free (scheme);
+ grub_free (host);
+
+ if (file && *file)
+   {
+ tmp = grub_strrchr (file, '/');
+ if (tmp)
+   *(tmp+1) = '\0';
+ else
+   file[0] = '\0';
+   }
+ else if (!file)
+   file = grub_strdup ("");
+
+ if (file[0] == '/')
+   {
+ *path = grub_strdup (file+1);
+ grub_free (file);
+   }
+ else
+   *path = file;
+   }
+ else if (num == GRUB_NET_DHCP6_IA_NA)
+   {
+ const grub_net_dhcpv6_option_t *ia_na_opt;
+ const grub_net_dhcpv6_opt_ia_na_t *ia_na =
+   (const grub_net_dhcpv6_opt_ia_na_t *)opt;
+ unsigned int left = len - OFFSET_OF (options, ia_na);
+ unsigned int j;
+
+ if ((grub_uint8_t *)ia_na + left >
+ (grub_uint8_t *)options + option_max)
+   left -= ((grub_uint8_t *)ia_na + left)
+   - ((grub_uint8_t *)options + option_max);
+
+ if (len < OFFSET_OF (option_data, opt)
+   + sizeof (grub_net_dhcpv6_option_t))
+   {
+ grub_dprintf ("net",
+   

[PATCH v1 33/37] btrfs: grub2-btrfs-06-subvol-mount

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c| 195 +++-
 grub-core/osdep/linux/getroot.c | 148 +++-
 include/grub/emu/getroot.h  |   5 +
 util/grub-install.c |  49 
 4 files changed, 392 insertions(+), 5 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index d47f9ab03..d44a1c73b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -266,6 +267,12 @@ static grub_err_t
 grub_btrfs_read_logical (struct grub_btrfs_data *data,
 grub_disk_addr_t addr, void *buf, grub_size_t size,
 int recursion_depth);
+static grub_err_t
+get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key,
+ grub_uint64_t *tree, grub_uint8_t *type);
+
+grub_uint64_t
+find_mtab_subvol_tree (const char *path, char **path_in_subvol);
 
 static grub_err_t
 read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
@@ -1302,9 +1309,26 @@ lookup_root_by_name(struct grub_btrfs_data *data, const 
char *path)
   grub_err_t err;
   grub_uint64_t tree = 0;
   grub_uint8_t type;
+  grub_uint64_t saved_tree;
   struct grub_btrfs_key key;
 
+  if (path[0] == '\0')
+{
+  data->fs_tree = 0;
+  return GRUB_ERR_NONE;
+}
+
+  err = get_root (data, &key, &tree, &type);
+  if (err)
+return err;
+
+  saved_tree = data->fs_tree;
+  data->fs_tree = tree;
+
   err = find_path (data, path, &key, &tree, &type);
+
+  data->fs_tree = saved_tree;
+
   if (err)
   return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
 
@@ -2316,11 +2340,20 @@ grub_btrfs_dir (grub_device_t device, const char *path,
   grub_uint64_t tree;
   grub_uint8_t type;
   grub_size_t est_size = 0;
+  char *new_path = NULL;
 
   if (!data)
 return grub_errno;
 
-  err = find_path (data, path, &key_in, &tree, &type);
+  tree = find_mtab_subvol_tree (path, &new_path);
+
+  if (tree)
+data->fs_tree = tree;
+
+  err = find_path (data, new_path ? new_path : path, &key_in, &tree, &type);
+  if (new_path)
+grub_free (new_path);
+
   if (err)
 {
   grub_btrfs_unmount (data);
@@ -2447,11 +2480,21 @@ grub_btrfs_open (struct grub_file *file, const char 
*name)
   struct grub_btrfs_inode inode;
   grub_uint8_t type;
   struct grub_btrfs_key key_in;
+  grub_uint64_t tree;
+  char *new_path = NULL;
 
   if (!data)
 return grub_errno;
 
-  err = find_path (data, name, &key_in, &data->tree, &type);
+  tree = find_mtab_subvol_tree (name, &new_path);
+
+  if (tree)
+data->fs_tree = tree;
+
+  err = find_path (data, new_path ? new_path : name, &key_in, &data->tree, 
&type);
+  if (new_path)
+grub_free (new_path);
+
   if (err)
 {
   grub_btrfs_unmount (data);
@@ -2686,6 +2729,150 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ 
((unused)), int argc,
   return 0;
 }
 
+struct grub_btrfs_mtab
+{
+  struct grub_btrfs_mtab *next;
+  struct grub_btrfs_mtab **prev;
+  char *path;
+  char *subvol;
+  grub_uint64_t tree;
+};
+
+typedef struct grub_btrfs_mtab* grub_btrfs_mtab_t;
+
+static struct grub_btrfs_mtab *btrfs_mtab;
+
+#define FOR_GRUB_MTAB(var) FOR_LIST_ELEMENTS (var, btrfs_mtab)
+#define FOR_GRUB_MTAB_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE((var), (next), 
btrfs_mtab)
+
+static void
+add_mountpoint (const char *path, const char *subvol, grub_uint64_t tree)
+{
+  grub_btrfs_mtab_t m = grub_malloc (sizeof (*m));
+
+  m->path = grub_strdup (path);
+  m->subvol = grub_strdup (subvol);
+  m->tree = tree;
+  grub_list_push (GRUB_AS_LIST_P (&btrfs_mtab), GRUB_AS_LIST (m));
+}
+
+static grub_err_t
+grub_cmd_btrfs_mount_subvol (grub_command_t cmd __attribute__ ((unused)), int 
argc,
+char **argv)
+{
+  char *devname, *dirname, *subvol;
+  struct grub_btrfs_key key_in;
+  grub_uint8_t type;
+  grub_uint64_t tree;
+  grub_uint64_t saved_tree;
+  grub_err_t err;
+  struct grub_btrfs_data *data = NULL;
+  grub_device_t dev = NULL;
+
+  if (argc < 3)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, "required   and 
");
+
+  devname = grub_file_get_device_name(argv[0]);
+  dev = grub_device_open (devname);
+  grub_free (devname);
+
+  if (!dev)
+{
+  err = grub_errno;
+  goto err_out;
+}
+
+  dirname = argv[1];
+  subvol = argv[2];
+
+  data = grub_btrfs_mount (dev);
+  if (!data)
+{
+  err = grub_errno;
+  goto err_out;
+}
+
+  err = find_path (data, dirname, &key_in, &tree, &type);
+  if (err)
+goto err_out;
+
+  if (type !=  GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
+{
+  err = grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory"));
+  goto err_out;
+}
+
+  err = get_root (data, &key_in, &tree, &type);
+
+  if (err)
+goto err_out;
+
+  saved_tree = data->fs_tree;
+  data->fs_tree = tree;
+  err = find_path (data, subvol, &key_i

[PATCH v1 00/37] Second Distro-agnostic series taken from Fedora Rawhide

2024-10-07 Thread Leo Sandoval
This is the second patch series, first version, taken from Fedora Rawhide spec 
[1] that
are distro-agnostic. The goal is to merge most of them so all the 
community/distros
would benefit.

Andrei Borzenkov (1):
  btrfs: Fallback to old subvol name scheme to support old snapshot
config

Jeff Mahoney (1):
  btrfs: Add ability to boot from subvolumes

Josef Bacik (1):
  net/tcp: add window scaling support

Michael Chang (7):
  bootp: New net_bootp6 command
  btrfs: export btrfs_subvol and btrfs_subvolid
  btrfs: grub2-btrfs-03-follow_default
  btrfs: grub2-btrfs-04-grub2-install
  btdfs: grub2-btrfs-05-grub2-mkconfig
  btrfs: grub2-btrfs-06-subvol-mount
  btrfs: Grub not working correctly with btrfs snapshots (bsc#1026511)

Peter Jones (9):
  10_linux.in: Make grub2-mkconfig construct titles that look like the
ones we want elsewhere.
  efinet and bootp: add support for dhcpv6
  grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it
in 10_linux
  backtrace: Make grub_fatal() also backtrace
  grub.texi: Make our info pages say "grub2" where appropriate.
  30_os-prober.in: just build chainloader entries, don't try any xnu
xnu.
  btrfs: fix a bad null check
  efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.
  chainloader: Use grub_efi_...() memory helpers where reasonable.

Robert Marshall (1):
  grub-set-password.in: Add friendly grub2 password config tool
(#985962)

 Makefile.util.def |   20 +
 configure.ac  |2 +
 docs/grub-dev.texi|4 +-
 docs/grub.texi|  359 +++---
 docs/man/grub-get-kernel-settings.h2m |2 +
 docs/man/grub-set-password.h2m|2 +
 grub-core/Makefile.core.def   |3 +
 grub-core/fs/btrfs.c  | 1090 -
 grub-core/kern/misc.c |6 +
 grub-core/lib/arm64/backtrace.c   |   62 +
 grub-core/lib/backtrace.c |2 +
 grub-core/lib/i386/backtrace.c|   14 +-
 grub-core/loader/efi/chainloader.c|4 +-
 grub-core/net/bootp.c |  914 +-
 grub-core/net/drivers/efi/efinet.c|   84 +-
 grub-core/net/ip.c|   39 +
 grub-core/net/net.c   |   72 ++
 grub-core/net/tcp.c   |   42 +-
 grub-core/net/tftp.c  |3 +
 grub-core/osdep/linux/getroot.c   |  151 ++-
 grub-core/osdep/unix/config.c |   17 +-
 include/grub/btrfs.h  |1 +
 include/grub/efi/api.h|  129 +-
 include/grub/efi/efi.h|   36 +-
 include/grub/emu/config.h |1 +
 include/grub/emu/getroot.h|5 +
 include/grub/net.h|   79 ++
 .../bash-completion.d/grub-completion.bash.in |   22 +
 util/config.c |   10 +
 util/grub-get-kernel-settings.in  |   88 ++
 util/grub-install.c   |   63 +
 util/grub-mkconfig.in |8 +-
 util/grub-mkconfig_lib.in |4 +
 util/grub-mkrelpath.c |6 +
 util/grub-set-password.in |  121 ++
 util/grub.d/00_header.in  |   25 +-
 util/grub.d/01_users.in   |   11 +
 util/grub.d/10_linux.in   |   61 +-
 util/grub.d/20_linux_xen.in   |4 +
 util/grub.d/30_os-prober.in   |   78 +-
 40 files changed, 3305 insertions(+), 339 deletions(-)
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
 create mode 100644 docs/man/grub-set-password.h2m
 create mode 100644 grub-core/lib/arm64/backtrace.c
 create mode 100644 util/grub-get-kernel-settings.in
 create mode 100644 util/grub-set-password.in
 create mode 100644 util/grub.d/01_users.in

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 18/37] 10_linux.in: Make grub2-mkconfig construct titles that look like the ones we want elsewhere.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Resolves: rhbz#1215839

Signed-off-by: Peter Jones 
---
 util/grub.d/10_linux.in | 34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 3105c31e4..0115dd0c0 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -80,6 +80,32 @@ case x"$GRUB_FS" in
;;
 esac
 
+mktitle ()
+{
+  local title_type
+  local version
+  local OS_NAME
+  local OS_VERS
+
+  title_type=$1 && shift
+  version=$1 && shift
+
+  OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})"
+  OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
+
+  case $title_type in
+recovery)
+  title=$(printf '%s (%s) %s (recovery mode)' \
+ "${OS_NAME}" "${version}" "${OS_VERS}")
+  ;;
+*)
+  title=$(printf '%s (%s) %s' \
+ "${OS_NAME}" "${version}" "${OS_VERS}")
+  ;;
+  esac
+  echo -n ${title}
+}
+
 title_correction_code=
 
 linux_entry ()
@@ -93,17 +119,11 @@ linux_entry ()
   boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
   fi
   if [ x$type != xsimple ] ; then
-  case $type in
- recovery)
- title="$(gettext_printf "%s, with Linux %s (recovery mode)" 
"${os}" "${version}")" ;;
- *)
- title="$(gettext_printf "%s, with Linux %s" "${os}" 
"${version}")" ;;
-  esac
+  title=$(mktitle "$type" "$version")
   if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux 
versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  replacement_title="$(echo "Advanced options for ${OS}" | sed 
's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  title_correction_code="${title_correction_code}if [ \"x\$default\" = 
'$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
- grub_warn "$(gettext_printf "Please don't use old title \`%s' for 
GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or 
later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" 
"gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
   fi
   echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} 
\$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed 
"s/^/$submenu_indentation/"
   else
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 20/37] net/tcp: add window scaling support

2024-10-07 Thread Leo Sandoval
From: Josef Bacik 

Sometimes we have to provision boxes across regions, such as California to
Sweden.  The http server has a 10 minute timeout, so if we can't get our 250mb
image transferred fast enough our provisioning fails, which is not ideal.  So
add tcp window scaling on open connections and set the window size to 1mb.  With
this change we're able to get higher sustained transfers between regions and can
transfer our image in well below 10 minutes.  Without this patch we'd time out
every time halfway through the transfer.  Thanks,

Signed-off-by: Josef Bacik 
---
 grub-core/net/tcp.c | 42 +-
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c
index 93dee0caa..902ab7e8a 100644
--- a/grub-core/net/tcp.c
+++ b/grub-core/net/tcp.c
@@ -106,6 +106,18 @@ struct tcphdr
   grub_uint16_t urgent;
 } GRUB_PACKED;
 
+struct tcp_scale_opt {
+  grub_uint8_t kind;
+  grub_uint8_t length;
+  grub_uint8_t scale;
+} GRUB_PACKED;
+
+struct tcp_synhdr {
+  struct tcphdr tcphdr;
+  struct tcp_scale_opt scale_opt;
+  grub_uint8_t padding;
+};
+
 struct tcp_pseudohdr
 {
   grub_uint32_t src;
@@ -571,7 +583,7 @@ grub_net_tcp_open (char *server,
   grub_net_tcp_socket_t socket;
   static grub_uint16_t in_port = 21550;
   struct grub_net_buff *nb;
-  struct tcphdr *tcph;
+  struct tcp_synhdr *tcph;
   int i;
   grub_uint8_t *nbd;
   grub_net_link_level_address_t ll_target_addr;
@@ -640,20 +652,24 @@ grub_net_tcp_open (char *server,
 }
 
   tcph = (void *) nb->data;
+  grub_memset(tcph, 0, sizeof (*tcph));
   socket->my_start_seq = grub_get_time_ms ();
   socket->my_cur_seq = socket->my_start_seq + 1;
-  socket->my_window = 8192;
-  tcph->seqnr = grub_cpu_to_be32 (socket->my_start_seq);
-  tcph->ack = grub_cpu_to_be32_compile_time (0);
-  tcph->flags = grub_cpu_to_be16_compile_time ((5 << 12) | TCP_SYN);
-  tcph->window = grub_cpu_to_be16 (socket->my_window);
-  tcph->urgent = 0;
-  tcph->src = grub_cpu_to_be16 (socket->in_port);
-  tcph->dst = grub_cpu_to_be16 (socket->out_port);
-  tcph->checksum = 0;
-  tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
-  &socket->inf->address,
-  &socket->out_nla);
+  socket->my_window = 32768;
+  tcph->tcphdr.seqnr = grub_cpu_to_be32 (socket->my_start_seq);
+  tcph->tcphdr.ack = grub_cpu_to_be32_compile_time (0);
+  tcph->tcphdr.flags = grub_cpu_to_be16_compile_time ((6 << 12) | TCP_SYN);
+  tcph->tcphdr.window = grub_cpu_to_be16 (socket->my_window);
+  tcph->tcphdr.urgent = 0;
+  tcph->tcphdr.src = grub_cpu_to_be16 (socket->in_port);
+  tcph->tcphdr.dst = grub_cpu_to_be16 (socket->out_port);
+  tcph->tcphdr.checksum = 0;
+  tcph->scale_opt.kind = 3;
+  tcph->scale_opt.length = 3;
+  tcph->scale_opt.scale = 5;
+  tcph->tcphdr.checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
+ &socket->inf->address,
+ &socket->out_nla);
 
   tcp_socket_register (socket);
 
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 25/37] grub.texi: Make our info pages say "grub2" where appropriate.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

This needs to be hooked up to --program-transform=, but I haven't had
time.

Signed-off-by: Peter Jones 
---
 docs/grub-dev.texi|   4 +-
 docs/grub.texi| 359 ++
 grub-core/kern/misc.c |   2 +-
 3 files changed, 191 insertions(+), 174 deletions(-)

diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi
index 1276c5930..04c6678cb 100644
--- a/docs/grub-dev.texi
+++ b/docs/grub-dev.texi
@@ -1,7 +1,7 @@
 \input texinfo
 @c -*-texinfo-*-
 @c %**start of header
-@setfilename grub-dev.info
+@setfilename grub2-dev.info
 @include version-dev.texi
 @settitle GNU GRUB Developers Manual @value{VERSION}
 @c Unify all our little indices for now.
@@ -32,7 +32,7 @@ Invariant Sections.
 
 @dircategory Kernel
 @direntry
-* grub-dev: (grub-dev). The GRand Unified Bootloader Dev
+* grub2-dev: (grub2-dev). The GRand Unified Bootloader Dev
 @end direntry
 
 @setchapternewpage odd
diff --git a/docs/grub.texi b/docs/grub.texi
index a225f9a88..cecf14d55 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1,7 +1,7 @@
 \input texinfo
 @c -*-texinfo-*-
 @c %**start of header
-@setfilename grub.info
+@setfilename grub2.info
 @include version.texi
 @settitle GNU GRUB Manual @value{VERSION}
 @c Unify all our little indices for now.
@@ -32,15 +32,15 @@ Invariant Sections.
 
 @dircategory Kernel
 @direntry
-* GRUB: (grub). The GRand Unified Bootloader
-* grub-install: (grub)Invoking grub-install.Install GRUB on your drive
-* grub-mkconfig: (grub)Invoking grub-mkconfig.  Generate GRUB configuration
-* grub-mkpasswd-pbkdf2: (grub)Invoking grub-mkpasswd-pbkdf2.
-* grub-mkrelpath: (grub)Invoking grub-mkrelpath.
-* grub-mkrescue: (grub)Invoking grub-mkrescue.  Make a GRUB rescue image
-* grub-mount: (grub)Invoking grub-mount.Mount a file system using GRUB
-* grub-probe: (grub)Invoking grub-probe.Probe device information
-* grub-script-check: (grub)Invoking grub-script-check.
+* GRUB2: (grub2). The GRand Unified Bootloader
+* grub2-install: (grub2)Invoking grub2-install.Install GRUB on your drive
+* grub2-mkconfig: (grub2)Invoking grub2-mkconfig.  Generate GRUB configuration
+* grub2-mkpasswd-pbkdf2: (grub2)Invoking grub2-mkpasswd-pbkdf2.
+* grub2-mkrelpath: (grub2)Invoking grub2-mkrelpath.
+* grub2-mkrescue: (grub2)Invoking grub2-mkrescue.  Make a GRUB rescue image
+* grub2-mount: (grub2)Invoking grub2-mount.Mount a file system using 
GRUB
+* grub2-probe: (grub2)Invoking grub2-probe.Probe device information
+* grub2-script-check: (grub2)Invoking grub2-script-check.
 @end direntry
 
 @setchapternewpage odd
@@ -223,7 +223,7 @@ surprising.
 
 @item
 @file{grub.cfg} is typically automatically generated by
-@command{grub-mkconfig} (@pxref{Simple configuration}).  This makes it
+@command{grub2-mkconfig} (@pxref{Simple configuration}).  This makes it
 easier to handle versioned kernel upgrades.
 
 @item
@@ -237,7 +237,7 @@ scripting language: variables, conditionals, and loops are 
available.
 @item
 A small amount of persistent storage is available across reboots, using the
 @command{save_env} and @command{load_env} commands in GRUB and the
-@command{grub-editenv} utility.  This is not available in all configurations
+@command{grub2-editenv} utility.  This is not available in all configurations
 (@pxref{Environment block}).
 
 @item
@@ -542,7 +542,7 @@ On OS which have device nodes similar to Unix-like OS GRUB 
tools use the
 OS name. E.g. for GNU/Linux:
 
 @example
-# @kbd{grub-install /dev/sda}
+# @kbd{grub2-install /dev/sda}
 @end example
 
 On AROS we use another syntax. For volumes:
@@ -565,7 +565,7 @@ For disks we use syntax:
 E.g.
 
 @example
-# @kbd{grub-install //:ata.device/0/0}
+# @kbd{grub2-install //:ata.device/0/0}
 @end example
 
 On Windows we use UNC path. For volumes it's typically
@@ -592,7 +592,7 @@ For disks it's
 E.g.
 
 @example
-# @kbd{grub-install \\?\PhysicalDrive0}
+# @kbd{grub2-install \\?\PhysicalDrive0}
 @end example
 
 Beware that you may need to further escape the backslashes depending on your
@@ -602,7 +602,7 @@ When compiled with cygwin support then cygwin drive names 
are automatically
 when needed. E.g.
 
 @example
-# @kbd{grub-install /dev/sda}
+# @kbd{grub2-install /dev/sda}
 @end example
 
 @node Installation
@@ -615,7 +615,7 @@ from the source tarball, or as a package for your OS.
 
 After you have done that, you need to install the boot loader on a
 drive (floppy or hard disk) by using the utility
-@command{grub-install} (@pxref{Invoking grub-install}) on a UNIX-like OS.
+@command{grub2-install} (@pxref{Invoking grub2-install}) on a UNIX-like OS.
 
 GRUB comes with boot images, which are normally put in the directory
 @file{/usr/lib/grub/-} (for BIOS-based machines
@@ -626,22 +626,22 @@ loader needs to find them (usually @file{/boot}) will be 
called
 the @dfn{boot directory}.
 
 @menu
-* Installing GRUB using grub-install::
+* Installin

[PATCH v1 37/37] chainloader: Use grub_efi_...() memory helpers where reasonable.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and
grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we
get more reasonable type checking.

Signed-off-by: Peter Jones 
---
 grub-core/loader/efi/chainloader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/efi/chainloader.c 
b/grub-core/loader/efi/chainloader.c
index 1de98f783..203692450 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -95,7 +95,7 @@ grub_chainloader_boot (void *context)
 }
 
   if (exit_data)
-b->free_pool (exit_data);
+grub_efi_free_pool (exit_data);
 
   grub_loader_unset ();
 
@@ -419,7 +419,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ 
((unused)),
   grub_free (file_path);
 
   if (address)
-b->free_pages (address, pages);
+grub_efi_free_pages (address, pages);
 
   if (image_handle != NULL)
 b->unload_image (image_handle);
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 36/37] efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 include/grub/efi/efi.h | 36 
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index a5cd99e5a..8d98203a7 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -36,6 +36,10 @@ struct linux_arch_kernel_header {
   struct grub_pe_image_header pe_image_header;
 };
 
+/* Variables.  */
+extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
+extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
+
 /* Functions.  */
 void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
 void *registration);
@@ -71,6 +75,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t 
*memory_map_size,
  grub_efi_uintn_t *descriptor_size,
  grub_efi_uint32_t *descriptor_version);
 void grub_efi_memory_fini (void);
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_allocate_pool (grub_efi_memory_type_t pool_type,
+   grub_efi_uintn_t buffer_size,
+   void **buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->allocate_pool(pool_type, buffer_size, buffer);
+  return status;
+}
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_free_pool (void *buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->free_pool(buffer);
+  return status;
+}
+
 grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) 
(grub_efi_handle_t image_handle);
 void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);
 char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
@@ -140,10 +171,7 @@ void grub_efi_init (void);
 void grub_efi_fini (void);
 void grub_efi_set_prefix (void);
 
-/* Variables.  */
-extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
-extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
-
+/* More variables.  */
 extern int EXPORT_VAR(grub_efi_is_finished);
 
 struct grub_net_card;
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 35/37] btrfs: Grub not working correctly with btrfs snapshots (bsc#1026511)

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c | 238 +++
 1 file changed, 238 insertions(+)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index dba86d19b..87e4dd1a0 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -3093,6 +3093,238 @@ out:
   return 0;
 }
 
+static grub_err_t
+grub_btrfs_get_parent_subvol_path (struct grub_btrfs_data *data,
+   grub_uint64_t child_id,
+   const char *child_path,
+   grub_uint64_t *parent_id,
+   char **path_out)
+{
+  grub_uint64_t fs_root = 0;
+  struct grub_btrfs_key key_in = {
+.object_id = child_id,
+.type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF,
+.offset = 0,
+  }, key_out;
+  struct grub_btrfs_root_ref *ref;
+  char *buf;
+  struct grub_btrfs_leaf_descriptor desc;
+  grub_size_t elemsize;
+  grub_disk_addr_t elemaddr;
+  grub_err_t err;
+  char *parent_path;
+
+  *parent_id = 0;
+  *path_out = 0;
+
+  err = lower_bound(data, &key_in, &key_out, data->sblock.root_tree,
+&elemaddr, &elemsize, &desc, 0);
+  if (err)
+return err;
+
+  if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF || elemaddr == 0)
+next(data, &desc, &elemaddr, &elemsize, &key_out);
+
+  if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF)
+{
+  free_iterator(&desc);
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("can't find root 
backrefs"));
+}
+
+  buf = grub_malloc(elemsize + 1);
+  if (!buf)
+{
+  free_iterator(&desc);
+  return grub_errno;
+}
+
+  err = grub_btrfs_read_logical(data, elemaddr, buf, elemsize, 0);
+  if (err)
+{
+  grub_free(buf);
+  free_iterator(&desc);
+  return err;
+}
+
+  buf[elemsize] = 0;
+  ref = (struct grub_btrfs_root_ref *)buf;
+
+  err = get_fs_root(data, data->sblock.root_tree, grub_le_to_cpu64 
(key_out.offset),
+0, &fs_root);
+  if (err)
+{
+  grub_free(buf);
+  free_iterator(&desc);
+  return err;
+}
+
+  find_pathname(data, grub_le_to_cpu64 (ref->dirid), fs_root, ref->name, 
&parent_path);
+
+  if (child_path)
+{
+  *path_out = grub_xasprintf ("%s/%s", parent_path, child_path);
+  grub_free (parent_path);
+}
+  else
+*path_out = parent_path;
+
+  *parent_id = grub_le_to_cpu64 (key_out.offset);
+
+  grub_free(buf);
+  free_iterator(&desc);
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_btrfs_get_default_subvolume_id (struct grub_btrfs_data *data, 
grub_uint64_t *id)
+{
+  grub_err_t err;
+  grub_disk_addr_t elemaddr;
+  grub_size_t elemsize;
+  struct grub_btrfs_key key, key_out;
+  struct grub_btrfs_dir_item *direl = NULL;
+  const char *ctoken = "default";
+  grub_size_t ctokenlen = sizeof ("default") - 1;
+
+  *id = 0;
+  key.object_id = data->sblock.root_dir_objectid;
+  key.type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key.offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
+  err = lower_bound (data, &key, &key_out, data->sblock.root_tree, &elemaddr, 
&elemsize,
+NULL, 0);
+  if (err)
+return err;
+
+  if (key_cmp (&key, &key_out) != 0)
+return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+
+  struct grub_btrfs_dir_item *cdirel;
+  direl = grub_malloc (elemsize + 1);
+  err = grub_btrfs_read_logical (data, elemaddr, direl, elemsize, 0);
+  if (err)
+{
+  grub_free (direl);
+  return err;
+}
+  for (cdirel = direl;
+   (grub_uint8_t *) cdirel - (grub_uint8_t *) direl
+   < (grub_ssize_t) elemsize;
+   cdirel = (void *) ((grub_uint8_t *) (direl + 1)
+   + grub_le_to_cpu16 (cdirel->n)
+   + grub_le_to_cpu16 (cdirel->m)))
+{
+  if (ctokenlen == grub_le_to_cpu16 (cdirel->n)
+&& grub_memcmp (cdirel->name, ctoken, ctokenlen) == 0)
+  break;
+}
+  if ((grub_uint8_t *) cdirel - (grub_uint8_t *) direl
+  >= (grub_ssize_t) elemsize)
+{
+  grub_free (direl);
+  err = grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+  return err;
+}
+
+  if (cdirel->key.type != GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM)
+{
+  grub_free (direl);
+  err = grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+  return err;
+}
+
+  *id = grub_le_to_cpu64 (cdirel->key.object_id);
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_cmd_btrfs_get_default_subvol (struct grub_extcmd_context *ctxt,
+int argc, char **argv)
+{
+  char *devname;
+  grub_device_t dev;
+  struct grub_btrfs_data *data;
+  grub_err_t err;
+  grub_uint64_t id;
+  char *subvol = NULL;
+  grub_uint64_t subvolid = 0;
+  char *varname = NULL;
+  char *output = NULL;
+  int path_only = ctxt->state[1].set;
+  int num_only = ctxt->state[2].set;
+
+  if (ctxt->state[0].set)
+varname = ctxt->state[0].arg;
+
+  if (argc < 1)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
+

[PATCH v1 31/37] btrfs: grub2-btrfs-04-grub2-install

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/osdep/linux/getroot.c |  7 +++
 grub-core/osdep/unix/config.c   | 17 +++--
 include/grub/emu/config.h   |  1 +
 util/config.c   | 10 ++
 util/grub-install.c | 14 ++
 util/grub-mkrelpath.c   |  6 ++
 6 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
index 7dd775d2a..7c29b3523 100644
--- a/grub-core/osdep/linux/getroot.c
+++ b/grub-core/osdep/linux/getroot.c
@@ -373,6 +373,7 @@ get_btrfs_fs_prefix (const char *mount_path)
   return NULL;
 }
 
+int use_relative_path_on_btrfs = 0;
 
 char **
 grub_find_root_devices_from_mountinfo (const char *dir, char **relroot)
@@ -516,6 +517,12 @@ again:
{
  ret = grub_find_root_devices_from_btrfs (dir);
  fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path);
+ if (use_relative_path_on_btrfs)
+   {
+ if (fs_prefix)
+   free (fs_prefix);
+ fs_prefix = xstrdup ("/");
+   }
}
   else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0)
{
diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c
index 0b1f7618d..0ce0e309a 100644
--- a/grub-core/osdep/unix/config.c
+++ b/grub-core/osdep/unix/config.c
@@ -82,6 +82,19 @@ grub_util_load_config (struct grub_util_config *cfg)
   if (v)
 cfg->grub_distributor = xstrdup (v);
 
+  v = getenv ("SUSE_BTRFS_SNAPSHOT_BOOTING");
+  if (v)
+{
+  if (grub_strncmp(v, "true", sizeof ("true") - 1) == 0)
+{
+  cfg->is_suse_btrfs_snapshot_enabled = 1;
+}
+  else
+{
+  cfg->is_suse_btrfs_snapshot_enabled = 0;
+}
+}
+
   cfgfile = grub_util_get_config_filename ();
   if (!grub_util_is_regular (cfgfile))
 return;
@@ -105,8 +118,8 @@ grub_util_load_config (struct grub_util_config *cfg)
   *ptr++ = *iptr;
 }
 
-  strcpy (ptr, "'; printf 
\"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\n\" "
- "\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\"");
+  strcpy (ptr, "'; printf 
\"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\nSUSE_BTRFS_SNAPSHOT_BOOTING=%s\\n\"
 "
+ "\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\" 
\"$SUSE_BTRFS_SNAPSHOT_BOOTING\"");
 
   argv[2] = script;
   argv[3] = '\0';
diff --git a/include/grub/emu/config.h b/include/grub/emu/config.h
index 875d5896c..c9a7e5f4a 100644
--- a/include/grub/emu/config.h
+++ b/include/grub/emu/config.h
@@ -37,6 +37,7 @@ struct grub_util_config
 {
   int is_cryptodisk_enabled;
   char *grub_distributor;
+  int is_suse_btrfs_snapshot_enabled;
 };
 
 void
diff --git a/util/config.c b/util/config.c
index ebcdd8f5e..f044a880a 100644
--- a/util/config.c
+++ b/util/config.c
@@ -42,6 +42,16 @@ grub_util_parse_config (FILE *f, struct grub_util_config 
*cfg, int simple)
cfg->is_cryptodisk_enabled = 1;
  continue;
}
+  if (grub_strncmp (ptr, "SUSE_BTRFS_SNAPSHOT_BOOTING=",
+   sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1) == 0)
+   {
+ ptr += sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1;
+ if (*ptr == '"' || *ptr == '\'')
+   ptr++;
+ if (grub_strncmp(ptr, "true", sizeof ("true") - 1) == 0)
+   cfg->is_suse_btrfs_snapshot_enabled = 1;
+ continue;
+   }
   if (grub_strncmp (ptr, "GRUB_DISTRIBUTOR=",
sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0)
{
diff --git a/util/grub-install.c b/util/grub-install.c
index 7dc5657bb..ec3ed4967 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -843,6 +843,8 @@ try_open (const char *path)
 }
 #endif
 
+extern int use_relative_path_on_btrfs;
+
 int
 main (int argc, char *argv[])
 {
@@ -876,6 +878,9 @@ main (int argc, char *argv[])
 
   grub_util_load_config (&config);
 
+  if (config.is_suse_btrfs_snapshot_enabled)
+use_relative_path_on_btrfs = 1;
+
   if (!bootloader_id && config.grub_distributor)
 {
   char *ptr;
@@ -1366,6 +1371,15 @@ main (int argc, char *argv[])
   relative_grubdir = xstrdup ("/");
 }
 
+  if (config.is_suse_btrfs_snapshot_enabled
+  && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
+{
+  if (!load_cfg_f)
+load_cfg_f = grub_util_fopen (load_cfg, "wb");
+  have_load_cfg = 1;
+  fprintf (load_cfg_f, "set btrfs_relative_path='y'\n");
+}
+
   char *prefix_drive = NULL;
   char *install_drive = NULL;
 
diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c
index 47a241a39..5db7a9a7d 100644
--- a/util/grub-mkrelpath.c
+++ b/util/grub-mkrelpath.c
@@ -40,9 +40,12 @@ struct arguments
 };
 
 static struct argp_option options[] = {
+  {"relative",  'r', 0, 0, "use relative path on btrfs", 0},
   { 0, 0, 0, 0, 0, 0 }
 };
 
+extern int use_relative_path_on_btrfs;
+
 static error

[PATCH v1 29/37] btrfs: export btrfs_subvol and btrfs_subvolid

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

We should export btrfs_subvol and btrfs_subvolid to have both visible
to subsidiary configuration files loaded using configfile.

Signed-off-by: Michael Chang 
---
 grub-core/fs/btrfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 8e2b1e9f7..14e38a4df 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2920,6 +2920,8 @@ GRUB_MOD_INIT (btrfs)
subvol_set_env);
   grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env,
subvolid_set_env);
+  grub_env_export ("btrfs_subvol");
+  grub_env_export ("btrfs_subvolid");
 }
 
 GRUB_MOD_FINI (btrfs)
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 28/37] btrfs: fix a bad null check

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

current gcc complains:

  grub-core/fs/btrfs.c: In function ‘grub_cmd_btrfs_info’:
  grub-core/fs/btrfs.c:2745:7: error: the comparison will always evaluate as 
‘true’ for the address of ‘label’ will never be NULL [-Werror=address]
   2745 |   if (data->sblock.label)
|   ^~~~
  grub-core/fs/btrfs.c:92:8: note: ‘label’ declared here
 92 |   char label[0x100];
|^
  cc1: all warnings being treated as errors

Obviously this check should be on the first data byte instead of the
symbol itself.

Signed-off-by: Peter Jones 
---
 grub-core/fs/btrfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index f14fe9c1b..8e2b1e9f7 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2625,7 +2625,7 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ 
((unused)), int argc,
   return grub_error (GRUB_ERR_BAD_ARGUMENT, "failed to open fs");
 }
 
-  if (data->sblock.label)
+  if (data->sblock.label[0])
 grub_printf("Label: '%s' ", data->sblock.label);
   else
 grub_printf("Label: none ");
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 26/37] 30_os-prober.in: just build chainloader entries, don't try any xnu xnu.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Since our bugs tell us that the xnu boot entries really just don't work
most of the time, and they create piles of extra boot entries, because
they can't quite figure out 32-vs-64 and other stuff like that.

It's rediculous, and we should just boot their bootloader through the
chainloader instead.

So this patch does that.

Resolves: rhbz#893179

Signed-off-by: Peter Jones 
---
 util/grub.d/30_os-prober.in | 78 +
 1 file changed, 18 insertions(+), 60 deletions(-)

diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index 656301eaf..1aac097c1 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -45,68 +45,25 @@ if [ -z "${OSPROBED}" ] ; then
 fi
 
 osx_entry() {
-if [ x$2 = x32 ]; then
-# TRANSLATORS: it refers to kernel architecture (32-bit)
-   bitstr="$(gettext "(32-bit)")"
-else
-# TRANSLATORS: it refers to kernel architecture (64-bit)
-   bitstr="$(gettext "(64-bit)")"
-fi
 # TRANSLATORS: it refers on the OS residing on device %s
 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-cat << EOF
-menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx 
--class darwin --class os \$menuentry_id_option 
'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
+hints=""
+for hint in `"${grub_probe}" --device ${device} --target=efi_hints 2> 
/dev/null` ; do
+  hints="${hints} --hint=${hint}"
+done
+cat << EOF
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class osx --class 
darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id 
"${DEVICE}")'  {
 EOF
save_default_entry | grub_add_tab
prepare_grub_to_access_device ${DEVICE} | grub_add_tab
cat << EOF
+   set gfxpayload=keep
 load_video
-set do_resume=0
-if [ /var/vm/sleepimage -nt10 / ]; then
-   if xnu_resume /var/vm/sleepimage; then
- set do_resume=1
-   fi
-fi
-if [ \$do_resume = 0 ]; then
-   xnu_uuid ${OSXUUID} uuid
-   if [ -f /Extra/DSDT.aml ]; then
-  acpi -e /Extra/DSDT.aml
-   fi
-   if [ /kernelcache -nt /System/Library/Extensions ]; then
-  $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
-   elif [ -f /System/Library/Kernels/kernel ]; then
-  $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid
-  xnu_kextdir /System/Library/Extensions
-   else
-  $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
-  if [ /System/Library/Extensions.mkext -nt 
/System/Library/Extensions ]; then
-xnu_mkext /System/Library/Extensions.mkext
-  else
-xnu_kextdir /System/Library/Extensions
-  fi
-   fi
-   if [ -f /Extra/Extensions.mkext ]; then
-  xnu_mkext /Extra/Extensions.mkext
-   fi
-   if [ -d /Extra/Extensions ]; then
-  xnu_kextdir /Extra/Extensions
-   fi
-   if [ -f /Extra/devprop.bin ]; then
-  xnu_devprop_load /Extra/devprop.bin
-   fi
-   if [ -f /Extra/splash.jpg ]; then
-  insmod jpeg
-  xnu_splash /Extra/splash.jpg
-   fi
-   if [ -f /Extra/splash.png ]; then
-  insmod png
-  xnu_splash /Extra/splash.png
-   fi
-   if [ -f /Extra/splash.tga ]; then
-  insmod tga
-  xnu_splash /Extra/splash.tga
-   fi
-fi
+   insmod part_gpt
+   insmod hfsplus
+   search --no-floppy --fs-uuid --set=root ${hints} $(grub_get_device_id 
"${DEVICE}")
+   chainloader (\$root)/System/Library/CoreServices/boot.efi
+   boot
 }
 EOF
 }
@@ -299,11 +256,12 @@ EOF
   echo "$title_correction_code"
 ;;
 macosx)
-  if [ "${UUID}" ]; then
-   OSXUUID="${UUID}"
-   osx_entry xnu_kernel 32
-   osx_entry xnu_kernel64 64
-  fi
+  for subdevice in ${DEVICE%[[:digit:]]*}* ; do
+   parttype="`"${grub_probe}" --device ${device} --target=gpt_parttype 
"${subdevice}" 2> /dev/null`"
+   if [[ "$parttype" = "426f6f74--11aa-aa11-00306543ecac" ]]; then
+ DEVICE="${subdevice}" osx_entry
+   fi
+  done
 ;;
 hurd)
   onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 02/17] term/terminfo: for ppc, reset console display attr when clear screen

2024-10-07 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
Signed-off-by: Paulo Flabiano Smorigo 
Signed-off-by: Robbie Harwood 
---
 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 ("\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


[PATCH v2 03/17] ieee1275: Disable GRUB video support for IBM power machines

2024-10-07 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

Disable GRUB Video Support from IBM Power Machines. This patch fixes what
is describe above and should fix 
https://bugzilla.redhat.com/show_bug.cgi?id=973205.
C&P the bz problem's description:

Grub crashes if it tries to run in video mode.

I'm currently testing with grub rpm from f18 in a lpar inside a Power 7R2 
machine using a matrox video card attached.

To reproduce you need to redirect the console to the video output.

This will happens:

IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM STARTING SOFTWARE   IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBMPLEASE WAIT...   IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM
IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM IBM

Welcome to GRUB

DEFAULT CATCH!, exception-handler=fff00300
at   %SRR0: 0020ac80   %SRR1: 3002
Open Firmware exception handler entered from non-OF code

Client's Fix Pt Regs:
 00 00780c38 01adfc40  1800
 04 00780850 0004afff 001d2bb0 
 08 1800 fffb5000 1804b000 01adfc50
 0c 0008  00800050 0266
 10 0265 0270 026e 0267
 14 0263 0001 001a 0002
 18 0002  00780dce 8080
 1c 0067 001d3de0 001d2b30 0002
Special Regs:
%IV: 0300 %CR: 22002084%XER: 2000  %DSISR: 4200
  %SRR0: 0020ac80   %SRR1: 3002
%LR: 6584%CTR: 0004b000
   %DAR: 1804afff
Virtual PID = 0
 ok
0 >

In Power, GRUB has video support and works fine with PowerMAC.

Theorically it should works with IBM machines as well but, using a Matrox 
videocard and grub.cfg with the video option enabled, GRUB crashes as we saw 
above.

Using GRUB debug we saw that the crash happens because GRUB tries to access the 
video card address:

video/ieee1275.c:236: IEEE1275: keeping current mode 640x480
video/ieee1275.c:266: IEEE1275: initialising FB @ 0x1800 640x480x8

GRUB gets the address from the display card node from openfirmware. The 
property is called "address":

0 > dev /pci@800200d/pci@0/display@0  ok
0 > .properties
ibm,loc-codeU78AB.001.WZSHS9P-P1-C7-T1
vendor-id   102b
device-id   2527
revision-id 0001
class-code  0003
interrupts  0001
min-grant   0010
max-latency 0020
subsystem-vendor-id 102b
subsystem-id2300
devsel-speed0001
fast-back-to-back
built-in
namedisplay
compatible  MTRX,G550
pci102b,2527
pciclass,03
display
reg 0099     
02990030     0001
02990010     0400
02990014     0080
02990018     0080
fcode-rom-offset9000
device_type display
character-set   ISO8859-1
iso6429-1983-colors
power-consumption     007270e0 007270e0   
007b98a0 007b98a0
ibm,fw-revision-level   0100
assigned-addresses  82990010  f800   0400
82990014  f700   0080
82990018  f780   0080
82990030  f6fe   0002
address 1800 1700
width   0280
height  01e0
depth   0008
linebytes   0280
bios release   

[PATCH v2 09/17] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Don't munge raw spaces when we're doing our cmdline escaping (#923374)

Signed-off-by: Peter Jones 
---
 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 
 #include 
 
+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


[PATCH v2 08/17] normal: Add fw_path variable (revised)

2024-10-07 Thread Leo Sandoval
From: Paulo Flabiano Smorigo 

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 
Signed-off-by: Robbie Harwood 
---
 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


[PATCH v2 12/17] Makefile.common: Add .eh_frame to list of relocations stripped

2024-10-07 Thread Leo Sandoval
From: Fedora Ninjas 

Signed-off-by: Peter Jones 
---
 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


[PATCH v2 11/17] 00_header.in: Enable pager by default. (#985860)

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 util/grub.d/00_header.in | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
index 6a316a5ba..c2d8b0937 100644
--- a/util/grub.d/00_header.in
+++ b/util/grub.d/00_header.in
@@ -43,6 +43,8 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then 
GRUB_DEFAULT_BUTTON='${saved_
 if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then 
GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
 
 cat << EOF
+set pager=1
+
 if [ -s \$prefix/grubenv ]; then
   load_env
 fi
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 05/17] misc: Make "exit" take a return code.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

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 
---
 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_

[PATCH v2 07/17] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2

2024-10-07 Thread Leo Sandoval
From: Mark Hamzy 

Add configuration support for ieee1275/PPC ofconsole serial terminal.

Signed-off-by: Mark Hamzy 
Signed-off-by: Robbie Harwood 
---
 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 0..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 .
+
+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


[PATCH v2 04/17] configure.ac: Move bash completion script

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

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


[PATCH v2 00/17] First Distro-agnostic series taken from Fedora Rawhide

2024-10-07 Thread Leo Sandoval
This is the first patch series, second version, taken from Fedora Rawhide spec 
[1] that
are distro-agnostic. The goal is to merge most of them so all the 
community/distros
would benefit.

Changes since v1:
- deleted0005-Allow-fallback-to-include-entries-by-title-not-just-.patch
  no longer supported (even if doc indicates the contrary)
  
- deleted011-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch
  similar patch reviewed in a separate thread
  
- deleted0014-Don-t-say-GNU-Linux-in-generated-menus.patch
  not accepted

- modified   
patches/0003-Disable-GRUB-video-support-for-IBM-power-machines.patch
  included commit description taken from bz

- modified   patches/0008-Migrate-PPC-from-Yaboot-to-Grub2.patch
  included 'ieee1275' on summary and description and improve description

[1] https://src.fedoraproject.org/rpms/grub2

Fedora Ninjas (2):
  Makefile.common: Add .eh_frame to list of relocations stripped
  normal/main: fw_path prefix when fallback searching for grub config

Mark Hamzy (1):
  20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2

Paulo Flabiano Smorigo (4):
  ieee1275/openfw: IBM client architecture (CAS) reboot support
  term/terminfo: for ppc, reset console display attr when clear screen
  ieee1275: Disable GRUB video support for IBM power machines
  normal: Add fw_path variable (revised)

Peter Jones (10):
  configure.ac: Move bash completion script
  misc: Make "exit" take a return code.
  efi/init: Make efi machines load an env block from a variable
  commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.
  10_linux.in: Add devicetree loading
  00_header.in: Enable pager by default. (#985860)
  10_linux.in: Don't require a password to boot entries generated by
grub-mkconfig.
  normal/main: Try mac/guid/etc before grub.cfg on tftp config files.
  10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release
  normal/main: Try $prefix if $fw_path doesn't work.

 Makefile.util.def|   7 ++
 conf/Makefile.common |   2 +-
 configure.ac |  11 +++
 grub-core/Makefile.core.def  |   1 +
 grub-core/commands/minicmd.c |  20 -
 grub-core/commands/wildcard.c|  16 +++-
 grub-core/kern/efi/efi.c |   9 +-
 grub-core/kern/efi/init.c|  34 
 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/cmain.c  |   5 +-
 grub-core/kern/ieee1275/init.c   |  30 ---
 grub-core/kern/ieee1275/openfw.c |  63 ++
 grub-core/kern/main.c|  13 ++-
 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 +-
 grub-core/lib/cmdline.c  |  25 +-
 grub-core/net/net.c  |   2 +-
 grub-core/normal/main.c  | 122 ++-
 grub-core/script/execute.c   |  50 +--
 grub-core/term/terminfo.c|   2 +-
 grub-core/video/ieee1275.c   |   9 +-
 include/grub/ieee1275/ieee1275.h |   4 +
 include/grub/misc.h  |   2 +-
 util/bash-completion.d/Makefile.am   |   1 -
 util/grub-mkconfig.in|   3 +-
 util/grub.d/00_header.in |   2 +
 util/grub.d/10_linux.in  |  20 -
 util/grub.d/20_ppc_terminfo.in   | 114 +
 35 files changed, 506 insertions(+), 101 deletions(-)
 create mode 100644 util/grub.d/20_ppc_terminfo.in

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2 13/17] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig.

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

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 
---
 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


[PATCH v2 06/17] efi/init: Make efi machines load an env block from a variable

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 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 
 #include 
 #include 
+
 #include 
 
+#include 
+
 #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


[PATCH v1 22/37] bootp: New net_bootp6 command

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

Implement new net_bootp6 command for IPv6 network auto configuration via the
DHCPv6 protocol (RFC3315).

Signed-off-by: Michael Chang 
Signed-off-by: Ken Lin 
[pjones: Put back our code to add a local route]
Signed-off-by: Peter Jones 
---
 grub-core/net/bootp.c  | 1059 +++-
 grub-core/net/drivers/efi/efinet.c |   18 +-
 grub-core/net/ip.c |   39 +
 include/grub/efi/api.h |2 +-
 include/grub/net.h |   91 ++-
 5 files changed, 1001 insertions(+), 208 deletions(-)

diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index 02d2c2614..e0aec2523 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -24,6 +24,98 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+
+static int
+dissect_url (const char *url, char **proto, char **host, char **path)
+{
+  const char *p, *ps;
+  grub_size_t l;
+
+  *proto = *host = *path = NULL;
+  ps = p = url;
+
+  while ((p = grub_strchr (p, ':')))
+{
+  if (grub_strlen (p) < sizeof ("://") - 1)
+   break;
+  if (grub_memcmp (p, "://", sizeof ("://") - 1) == 0)
+   {
+ l = p - ps;
+ *proto = grub_malloc (l + 1);
+ if (!*proto)
+   {
+ grub_print_error ();
+ return 0;
+   }
+
+ grub_memcpy (*proto, ps, l);
+ (*proto)[l] = '\0';
+ p +=  sizeof ("://") - 1;
+ break;
+   }
+  ++p;
+}
+
+  if (!*proto)
+{
+  grub_dprintf ("bootp", "url: %s is not valid, protocol not found\n", 
url);
+  return 0;
+}
+
+  ps = p;
+  p = grub_strchr (p, '/');
+
+  if (!p)
+{
+  grub_dprintf ("bootp", "url: %s is not valid, host/path not found\n", 
url);
+  grub_free (*proto);
+  *proto = NULL;
+  return 0;
+}
+
+  l = p - ps;
+
+  if (l > 2 && ps[0] == '[' && ps[l - 1] == ']')
+{
+  *host = grub_malloc (l - 1);
+  if (!*host)
+   {
+ grub_print_error ();
+ grub_free (*proto);
+ *proto = NULL;
+ return 0;
+   }
+  grub_memcpy (*host, ps + 1, l - 2);
+  (*host)[l - 2] = 0;
+}
+  else
+{
+  *host = grub_malloc (l + 1);
+  if (!*host)
+   {
+ grub_print_error ();
+ grub_free (*proto);
+ *proto = NULL;
+ return 0;
+   }
+  grub_memcpy (*host, ps, l);
+  (*host)[l] = 0;
+}
+
+  *path = grub_strdup (p);
+  if (!*path)
+{
+  grub_print_error ();
+  grub_free (*host);
+  grub_free (*proto);
+  *host = NULL;
+  *proto = NULL;
+  return 0;
+}
+  return 1;
+}
 
 struct grub_dhcp_discover_options
 {
@@ -610,6 +702,584 @@ out:
   return err;
 }
 
+/* The default netbuff size for sending DHCPv6 packets which should be
+   large enough to hold the information */
+#define GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE 512
+
+struct grub_dhcp6_options
+{
+  grub_uint8_t *client_duid;
+  grub_uint16_t client_duid_len;
+  grub_uint8_t *server_duid;
+  grub_uint16_t server_duid_len;
+  grub_uint32_t iaid;
+  grub_uint32_t t1;
+  grub_uint32_t t2;
+  grub_net_network_level_address_t *ia_addr;
+  grub_uint32_t preferred_lifetime;
+  grub_uint32_t valid_lifetime;
+  grub_net_network_level_address_t *dns_server_addrs;
+  grub_uint16_t num_dns_server;
+  char *boot_file_proto;
+  char *boot_file_server_ip;
+  char *boot_file_path;
+};
+
+typedef struct grub_dhcp6_options *grub_dhcp6_options_t;
+
+struct grub_dhcp6_session
+{
+  struct grub_dhcp6_session *next;
+  struct grub_dhcp6_session **prev;
+  grub_uint32_t iaid;
+  grub_uint32_t transaction_id:24;
+  grub_uint64_t start_time;
+  struct grub_net_dhcp6_option_duid_ll duid;
+  struct grub_net_network_level_interface *iface;
+
+  /* The associated dhcpv6 options */
+  grub_dhcp6_options_t adv;
+  grub_dhcp6_options_t reply;
+};
+
+typedef struct grub_dhcp6_session *grub_dhcp6_session_t;
+
+typedef void (*dhcp6_option_hook_fn) (const struct grub_net_dhcp6_option *opt, 
void *data);
+
+static void
+foreach_dhcp6_option (const struct grub_net_dhcp6_option *opt, grub_size_t 
size,
+ dhcp6_option_hook_fn hook, void *hook_data);
+
+static void
+parse_dhcp6_iaaddr (const struct grub_net_dhcp6_option *opt, void *data)
+{
+  grub_dhcp6_options_t dhcp6 = (grub_dhcp6_options_t )data;
+
+  grub_uint16_t code = grub_be_to_cpu16 (opt->code);
+  grub_uint16_t len = grub_be_to_cpu16 (opt->len);
+
+  if (code == GRUB_NET_DHCP6_OPTION_IAADDR)
+{
+  const struct grub_net_dhcp6_option_iaaddr *iaaddr;
+  iaaddr = (const struct grub_net_dhcp6_option_iaaddr *)opt->data;
+
+  if (len < sizeof (*iaaddr))
+   {
+ grub_dprintf ("bootp", "DHCPv6: code %u with insufficient length 
%u\n", code, len);
+ return;
+   }
+  if (!dhcp6->ia_addr)
+   {
+ dhcp6->ia_addr = grub_malloc (sizeof(*dhcp6->ia_addr));
+ dhcp6->ia_addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
+ dhcp6->i

[PATCH v1 30/37] btrfs: grub2-btrfs-03-follow_default

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c | 107 ++-
 1 file changed, 76 insertions(+), 31 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 14e38a4df..d47f9ab03 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -1335,6 +1335,7 @@ grub_btrfs_mount (grub_device_t dev)
 {
   struct grub_btrfs_data *data;
   grub_err_t err;
+  const char *relpath = grub_env_get ("btrfs_relative_path");
 
   if (!dev->disk)
 {
@@ -1365,11 +1366,14 @@ grub_btrfs_mount (grub_device_t dev)
   data->devices_attached[0].dev = dev;
   data->devices_attached[0].id = data->sblock.this_device.device_id;
 
-  err = btrfs_handle_subvol (data);
-  if (err)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
 {
-  grub_free (data);
-  return NULL;
+  err = btrfs_handle_subvol (data);
+  if (err)
+  {
+grub_free (data);
+return NULL;
+  }
 }
 
   return data;
@@ -1966,24 +1970,39 @@ find_path (struct grub_btrfs_data *data,
   grub_size_t allocated = 0;
   struct grub_btrfs_dir_item *direl = NULL;
   struct grub_btrfs_key key_out;
+  int follow_default;
   const char *ctoken;
   grub_size_t ctokenlen;
   char *path_alloc = NULL;
   char *origpath = NULL;
   unsigned symlinks_max = 32;
+  const char *relpath = grub_env_get ("btrfs_relative_path");
 
+  follow_default = 0;
   origpath = grub_strdup (path);
   if (!origpath)
 return grub_errno;
 
-  if (data->fs_tree)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
 {
-  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
-  *tree = data->fs_tree;
-  /* This is a tree root, so everything starts at objectid 256 */
-  key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
-  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
-  key->offset = 0;
+  if (data->fs_tree)
+{
+  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+  *tree = data->fs_tree;
+  /* This is a tree root, so everything starts at objectid 256 */
+  key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
+  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key->offset = 0;
+}
+  else
+{
+  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+  *tree = data->sblock.root_tree;
+  key->object_id = data->sblock.root_dir_objectid;
+  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key->offset = 0;
+  follow_default = 1;
+}
 }
   else
 {
@@ -1994,15 +2013,23 @@ find_path (struct grub_btrfs_data *data,
 
   while (1)
 {
-  while (path[0] == '/')
-   path++;
-  if (!path[0])
-   break;
-  slash = grub_strchr (path, '/');
-  if (!slash)
-   slash = path + grub_strlen (path);
-  ctoken = path;
-  ctokenlen = slash - path;
+  if (!follow_default)
+   {
+ while (path[0] == '/')
+   path++;
+ if (!path[0])
+   break;
+ slash = grub_strchr (path, '/');
+ if (!slash)
+   slash = path + grub_strlen (path);
+ ctoken = path;
+ ctokenlen = slash - path;
+   }
+  else
+   {
+ ctoken = "default";
+ ctokenlen = sizeof ("default") - 1;
+   }
 
   if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
{
@@ -2013,7 +2040,9 @@ find_path (struct grub_btrfs_data *data,
 
   if (ctokenlen == 1 && ctoken[0] == '.')
{
- path = slash;
+ if (!follow_default)
+   path = slash;
+ follow_default = 0;
  continue;
}
   if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.')
@@ -2044,8 +2073,9 @@ find_path (struct grub_btrfs_data *data,
  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
  key->object_id = key_out.offset;
 
- path = slash;
-
+ if (!follow_default)
+   path = slash;
+ follow_default = 0;
  continue;
}
 
@@ -2114,7 +2144,9 @@ find_path (struct grub_btrfs_data *data,
  return err;
}
 
-  path = slash;
+  if (!follow_default)
+   path = slash;
+  follow_default = 0;
   if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK)
{
  struct grub_btrfs_inode inode;
@@ -2164,14 +2196,26 @@ find_path (struct grub_btrfs_data *data,
  path = path_alloc = tmp;
  if (path[0] == '/')
{
- if (data->fs_tree)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
{
- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
- *tree = data->fs_tree;
- /* This is a tree root, so everything starts at objectid 256 
*/
- key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
- key->type = GRUB_B

[PATCH v1 32/37] btdfs: grub2-btrfs-05-grub2-mkconfig

2024-10-07 Thread Leo Sandoval
From: Michael Chang 

Signed-off-by: Michael Chang 
---
 util/grub-mkconfig.in   |  3 ++-
 util/grub-mkconfig_lib.in   |  4 
 util/grub.d/00_header.in| 25 -
 util/grub.d/10_linux.in |  4 
 util/grub.d/20_linux_xen.in |  4 
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 91f761331..ad5b778e3 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -259,7 +259,8 @@ export GRUB_DEFAULT \
   GRUB_BADRAM \
   GRUB_OS_PROBER_SKIP_LIST \
   GRUB_DISABLE_SUBMENU \
-  GRUB_DEFAULT_DTB
+  GRUB_DEFAULT_DTB \
+  SUSE_BTRFS_SNAPSHOT_BOOTING
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 33e1750ae..0ba0e0e1c 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -49,7 +49,11 @@ grub_warn ()
 
 make_system_path_relative_to_its_root ()
 {
+  if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
+  "${grub_mkrelpath}" -r "$1"
+  else
   "${grub_mkrelpath}" "$1"
+  fi
 }
 
 is_path_readable_by_grub ()
diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
index c2d8b0937..3e1b77265 100644
--- a/util/grub.d/00_header.in
+++ b/util/grub.d/00_header.in
@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+cat /dev/null || true`
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 23/37] grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it in 10_linux

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

This patch adds grub-get-kernel-settings, which reads the system kernel
installation configuration from /etc/sysconfig/kernel, and outputs
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
variables are then used by 10_linux to choose whether or not to create
debug stanzas.

Resolves: rhbz#1226325
[rharwood: migrate man page to h2m]
---
 Makefile.util.def |  7 ++
 configure.ac  |  1 +
 docs/man/grub-get-kernel-settings.h2m |  2 +
 .../bash-completion.d/grub-completion.bash.in | 22 +
 util/grub-get-kernel-settings.in  | 88 +++
 util/grub-mkconfig.in |  3 +
 util/grub.d/10_linux.in   | 23 +++--
 7 files changed, 141 insertions(+), 5 deletions(-)
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
 create mode 100644 util/grub-get-kernel-settings.in

diff --git a/Makefile.util.def b/Makefile.util.def
index 95884956a..84a17ef5c 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -725,6 +725,13 @@ script = {
   installdir = sbin;
 };
 
+script = {
+  name = grub-get-kernel-settings;
+  common = util/grub-get-kernel-settings.in;
+  mansection = 3;
+  installdir = sbin;
+};
+
 script = {
   name = grub-set-default;
   common = util/grub-set-default.in;
diff --git a/configure.ac b/configure.ac
index 493e336ec..3602b4ab6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,7 @@ grub_TRANSFORM([grub-install])
 grub_TRANSFORM([grub-mkconfig])
 grub_TRANSFORM([grub-mkfont])
 grub_TRANSFORM([grub-mkimage])
+grub_TRANSFORM([grub-get-kernel-settings])
 grub_TRANSFORM([grub-glue-efi])
 grub_TRANSFORM([grub-mklayout])
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
diff --git a/docs/man/grub-get-kernel-settings.h2m 
b/docs/man/grub-get-kernel-settings.h2m
new file mode 100644
index 0..b8051f01f
--- /dev/null
+++ b/docs/man/grub-get-kernel-settings.h2m
@@ -0,0 +1,2 @@
+[NAME]
+grub-get-kernel-settings \- Evaluate the system's kernel installation settings 
for use while making a grub configuration file
diff --git a/util/bash-completion.d/grub-completion.bash.in 
b/util/bash-completion.d/grub-completion.bash.in
index 213ce1e57..da7fca5ef 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -275,6 +275,28 @@ have ${__grub_sparc64_setup_program} && \
 unset __grub_sparc64_setup_program
 
 
+#
+# grub-get-kernel-settings
+#
+_grub_get_kernel_settings () {
+local cur
+
+COMPREPLY=()
+cur=`_get_cword`
+
+if [[ "$cur" == -* ]]; then
+__grubcomp "$(__grub_get_options_from_help)"
+else
+# Default complete with a filename
+_filedir
+fi
+}
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
+have ${__grub_get_kernel_settings_program} && \
+ complete -F _grub_get_kernel_settings -o filenames 
${__grub_get_kernel_settings_program}
+unset __grub_get_kernel_settings_program
+
+
 #
 # grub-install
 #
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
new file mode 100644
index 0..7e87dfccc
--- /dev/null
+++ b/util/grub-get-kernel-settings.in
@@ -0,0 +1,88 @@
+#!/bin/sh
+set -e
+
+# Evaluate new-kernel-pkg's configuration file.
+# Copyright (C) 2016 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 .
+
+PACKAGE_NAME=@PACKAGE_NAME@
+PACKAGE_VERSION=@PACKAGE_VERSION@
+datadir="@datadir@"
+if [ "x$pkgdatadir" = x ]; then
+pkgdatadir="${datadir}/@PACKAGE@"
+fi
+
+self=`basename $0`
+
+export TEXTDOMAIN=@PACKAGE@
+export TEXTDOMAINDIR="@localedir@"
+
+. "${pkgdatadir}/grub-mkconfig_lib"
+
+# Usage: usage
+# Print the usage.
+usage () {
+gettext_printf "Usage: %s [OPTION]\n" "$self"
+gettext "Evaluate new-kernel-pkg configuration"; echo
+echo
+print_option_help "-h, --help" "$(gettext "print this message and exit")"
+print_option_help "-v, --version" "$(gettext "print the version 
information and exit")"
+echo
+}
+
+# Check the arguments.
+while test $# -gt 0
+do
+option=$1
+shift
+
+case "$option" in
+-h | --help)
+   usage
+   exit 0 ;;
+-v | --version)
+   echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
+   exit 0 ;;
+-*)
+   gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
+   usage
+   exit 1
+   ;

[PATCH v1 19/37] grub-set-password.in: Add friendly grub2 password config tool (#985962)

2024-10-07 Thread Leo Sandoval
From: Robert Marshall 

Provided a tool for users to reset the grub2 root user password
without having to alter the grub.cfg. The hashed password now
lives in a root-only-readable configuration file.

Resolves: rhbz#985962

Signed-off-by: Robert Marshall 
[pjones: fix the efidir in grub-setpassword and rename tool]
Signed-off-by: Peter Jones 
[luto: fix grub-setpassword -o's output path]
Signed-off-by: Andy Lutomirski 
[rharwood: migrate man page to h2m, context]
Signed-off-by: Robbie Harwood 
---
 Makefile.util.def  |  13 
 configure.ac   |   1 +
 docs/man/grub-set-password.h2m |   2 +
 util/grub-mkconfig.in  |   2 +
 util/grub-set-password.in  | 121 +
 util/grub.d/01_users.in|  11 +++
 6 files changed, 150 insertions(+)
 create mode 100644 docs/man/grub-set-password.h2m
 create mode 100644 util/grub-set-password.in
 create mode 100644 util/grub.d/01_users.in

diff --git a/Makefile.util.def b/Makefile.util.def
index 09bfcadd9..95884956a 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -455,6 +455,12 @@ script = {
   installdir = grubconf;
 };
 
+script = {
+  name = '01_users';
+  common = util/grub.d/01_users.in;
+  installdir = grubconf;
+};
+
 script = {
   name = '10_windows';
   common = util/grub.d/10_windows.in;
@@ -733,6 +739,13 @@ script = {
   installdir = sbin;
 };
 
+script = {
+  name = grub-set-password;
+  common = util/grub-set-password.in;
+  mansection = 8;
+  installdir = sbin;
+};
+
 script = {
   name = grub-mkconfig_lib;
   common = util/grub-mkconfig_lib.in;
diff --git a/configure.ac b/configure.ac
index ae3a49321..493e336ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,6 +77,7 @@ grub_TRANSFORM([grub-mkrelpath])
 grub_TRANSFORM([grub-mkrescue])
 grub_TRANSFORM([grub-probe])
 grub_TRANSFORM([grub-reboot])
+grub_TRANSFORM([grub-set-password])
 grub_TRANSFORM([grub-script-check])
 grub_TRANSFORM([grub-set-default])
 grub_TRANSFORM([grub-sparc64-setup])
diff --git a/docs/man/grub-set-password.h2m b/docs/man/grub-set-password.h2m
new file mode 100644
index 0..10ee82f4d
--- /dev/null
+++ b/docs/man/grub-set-password.h2m
@@ -0,0 +1,2 @@
+[NAME]
+grub-set-password \- generate the user.cfg file containing the hashed grub 
bootloader password
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index d1bf4983b..9d5d7964b 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -283,6 +283,8 @@ for i in "${grub_mkconfig_dir}"/* ; do
 *~) ;;
 # emacsen autosave files. FIXME: support other editors
 */\#*\#) ;;
+# rpm config files of yore.
+*.rpmsave|*.rpmnew|*.rpmorig) ;;
 *)
   if grub_file_is_not_garbage "$i" && test -x "$i" ; then
 echo
diff --git a/util/grub-set-password.in b/util/grub-set-password.in
new file mode 100644
index 0..d8005e5a1
--- /dev/null
+++ b/util/grub-set-password.in
@@ -0,0 +1,121 @@
+#!/bin/sh -e
+
+grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
+
+PACKAGE_VERSION="@PACKAGE_VERSION@"
+PACKAGE_NAME="@PACKAGE_NAME@"
+self=`basename $0`
+bindir="@bindir@"
+grub_mkpasswd="${bindir}/@grub_mkpasswd_pbkdf2@"
+
+# Usage: usage
+# Print the usage.
+usage () {
+cat <  put user.cfg in a user-selected directory
+
+Report bugs at https://bugzilla.redhat.com.
+EOF
+}
+
+argument () {
+opt=$1
+shift
+
+if test $# -eq 0; then
+gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" 
"$opt" 1>&2
+exit 1
+fi
+echo $1
+}
+
+# Ensure that it's the root user running this script
+if [ "${EUID}" -ne 0 ]; then
+echo "The grub bootloader password may only be set by root."
+usage
+exit 2
+fi
+
+# Check the arguments.
+while test $# -gt 0
+do
+option=$1
+shift
+
+case "$option" in
+-h | --help)
+   usage
+   exit 0 ;;
+-v | --version)
+   echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
+   exit 0 ;;
+-o | --output)
+OUTPUT_PATH=`argument $option "$@"`; shift ;;
+--output=*)
+OUTPUT_PATH=`echo "$option" | sed 's/--output=//'` ;;
+-o=*)
+OUTPUT_PATH=`echo "$option" | sed 's/-o=//'` ;;
+esac
+done
+
+# set user input or default path for user.cfg file
+if [ -z "${OUTPUT_PATH}" ]; then
+OUTPUT_PATH="${grubdir}"
+fi
+
+if [ ! -d "${OUTPUT_PATH}" ]; then
+echo "${OUTPUT_PATH} does not exist."
+usage
+exit 2;
+fi
+
+ttyopt=$(stty -g)
+fixtty() {
+  stty ${ttyopt}
+}
+
+trap fixtty EXIT
+stty -echo
+
+# prompt & confirm new grub2 root user password
+echo -n "Enter password: "
+read PASSWORD
+echo
+echo -n "Confirm password: "
+read PASSWORD_CONFIRM
+echo
+stty ${ttyopt}
+
+getpass() {
+local P0
+local P1
+P0="$1" && shift
+P1="$1" && shift
+
+( echo ${P0} ; echo ${P1} ) | \
+LC_ALL=C ${grub_mkpasswd} | \
+grep -v '[eE]nter password:' | \
+sed -e "s/PBKDF2 hash of your password is //"
+}
+
+MYPASS="$(getpass "${PASSWORD}" "$

[PATCH v1 27/37] btrfs: Add ability to boot from subvolumes

2024-10-07 Thread Leo Sandoval
From: Jeff Mahoney 

This patch adds the ability to specify a different root on a btrfs
filesystem too boot from other than the default one.

btrfs-list-snapshots  will list the subvolumes available on the
filesystem.

set btrfs_subvol= and set btrfs_subvolid= will specify
which subvolume to use and any pathnames provided with either of those
variables set will start using that root. If the subvolume or subvolume id
doesn't exist, then an error case will result.

It is possible to boot into a separate GRUB instance by exporting the
variable and loading the config file from the subvolume.

Signed-off-by: Jeff Mahoney 
---
 grub-core/fs/btrfs.c | 554 +--
 include/grub/btrfs.h |   1 +
 2 files changed, 534 insertions(+), 21 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index ba0c58352..f14fe9c1b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -38,6 +38,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -79,9 +82,11 @@ struct grub_btrfs_superblock
   grub_uint64_t generation;
   grub_uint64_t root_tree;
   grub_uint64_t chunk_tree;
-  grub_uint8_t dummy2[0x20];
+  grub_uint8_t dummy2[0x18];
+  grub_uint64_t bytes_used;
   grub_uint64_t root_dir_objectid;
-  grub_uint8_t dummy3[0x41];
+  grub_uint64_t num_devices;
+  grub_uint8_t dummy3[0x39];
   struct grub_btrfs_device this_device;
   char label[0x100];
   grub_uint8_t dummy4[0x100];
@@ -121,6 +126,7 @@ struct grub_btrfs_data
   grub_uint64_t exttree;
   grub_size_t extsize;
   struct grub_btrfs_extent_data *extent;
+  grub_uint64_t fs_tree;
 };
 
 struct grub_btrfs_chunk_item
@@ -191,6 +197,14 @@ struct grub_btrfs_leaf_descriptor
   } *data;
 };
 
+struct grub_btrfs_root_ref
+{
+  grub_uint64_t dirid;
+  grub_uint64_t sequence;
+  grub_uint16_t name_len;
+  const char name[0];
+} __attribute__ ((packed));
+
 struct grub_btrfs_time
 {
   grub_int64_t sec;
@@ -236,6 +250,14 @@ struct grub_btrfs_extent_data
 
 #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
 
+#define GRUB_BTRFS_ROOT_TREE_OBJECTID 1ULL
+#define GRUB_BTRFS_FS_TREE_OBJECTID 5ULL
+#define GRUB_BTRFS_ROOT_REF_KEY 156
+#define GRUB_BTRFS_ROOT_ITEM_KEY 132
+
+static grub_uint64_t btrfs_default_subvolid = 0;
+static char *btrfs_default_subvol = NULL;
+
 static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
   256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2
 };
@@ -1252,6 +1274,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, 
grub_disk_addr_t addr,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+grub_uint64_t objectid, grub_uint64_t offset,
+grub_uint64_t *fs_root);
+
+static grub_err_t
+lookup_root_by_id(struct grub_btrfs_data *data, grub_uint64_t id)
+{
+  grub_err_t err;
+  grub_uint64_t tree;
+
+  err = get_fs_root(data, data->sblock.root_tree, id, -1, &tree);
+  if (!err)
+data->fs_tree = tree;
+  return err;
+}
+
+static grub_err_t
+find_path (struct grub_btrfs_data *data,
+  const char *path, struct grub_btrfs_key *key,
+  grub_uint64_t *tree, grub_uint8_t *type);
+
+static grub_err_t
+lookup_root_by_name(struct grub_btrfs_data *data, const char *path)
+{
+  grub_err_t err;
+  grub_uint64_t tree = 0;
+  grub_uint8_t type;
+  struct grub_btrfs_key key;
+
+  err = find_path (data, path, &key, &tree, &type);
+  if (err)
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
+
+  if (key.object_id != grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0)
+return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path);
+
+  data->fs_tree = tree;
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused)))
+{
+  if (btrfs_default_subvol)
+return lookup_root_by_name(data, btrfs_default_subvol);
+
+  if (btrfs_default_subvolid)
+return lookup_root_by_id(data, btrfs_default_subvolid);
+
+  data->fs_tree = 0;
+
+  return GRUB_ERR_NONE;
+}
+
+
 static struct grub_btrfs_data *
 grub_btrfs_mount (grub_device_t dev)
 {
@@ -1287,6 +1365,13 @@ grub_btrfs_mount (grub_device_t dev)
   data->devices_attached[0].dev = dev;
   data->devices_attached[0].id = data->sblock.this_device.device_id;
 
+  err = btrfs_handle_subvol (data);
+  if (err)
+{
+  grub_free (data);
+  return NULL;
+}
+
   return data;
 }
 
@@ -1784,6 +1869,91 @@ get_root (struct grub_btrfs_data *data, struct 
grub_btrfs_key *key,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+find_pathname(struct grub_btrfs_data *data, grub_uint64_t objectid,
+  grub_uint64_t fs_root, const char *name, char **pathname)
+{
+  grub_err_t err;
+  struct grub_btrfs_key key = {
+.object_id = objectid,
+.type = GRUB_BTRFS_ITEM_TYPE_INODE_REF,
+.offset = 0,
+  };
+  struct grub_btrfs_key key_out;
+  struct grub_btrfs_leaf_descrip

[PATCH v1 24/37] backtrace: Make grub_fatal() also backtrace

2024-10-07 Thread Leo Sandoval
From: Peter Jones 

---
 grub-core/Makefile.core.def |  3 ++
 grub-core/kern/misc.c   |  6 
 grub-core/lib/arm64/backtrace.c | 62 +
 grub-core/lib/backtrace.c   |  2 ++
 grub-core/lib/i386/backtrace.c  | 14 +++-
 5 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 grub-core/lib/arm64/backtrace.c

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 0bffbfea9..17b581220 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -199,6 +199,9 @@ kernel = {
 
   softdiv = lib/division.c;
 
+  x86 = lib/i386/backtrace.c;
+  x86 = lib/backtrace.c;
+
   i386 = kern/i386/dl.c;
   i386_xen = kern/i386/dl.c;
   i386_xen_pvh = kern/i386/dl.c;
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 11037dc02..465a8e74e 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 union printf_arg
 {
@@ -1301,6 +1302,11 @@ grub_printf_fmt_check (const char *fmt, const char 
*fmt_expected)
 void __attribute__ ((noreturn))
 grub_abort (void)
 {
+#ifndef GRUB_UTIL
+#if defined(__i386__) || defined(__x86_64__)
+  grub_backtrace();
+#endif
+#endif
   grub_printf ("\nAborted.");
 
 #ifndef GRUB_UTIL
diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c
new file mode 100644
index 0..1079b5380
--- /dev/null
+++ b/grub-core/lib/arm64/backtrace.c
@@ -0,0 +1,62 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  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 .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MAX_STACK_FRAME 102400
+
+void
+grub_backtrace_pointer (int frame)
+{
+  while (1)
+{
+  void *lp = __builtin_return_address (frame);
+  if (!lp)
+   break;
+
+  lp = __builtin_extract_return_addr (lp);
+
+  grub_printf ("%p: ", lp);
+  grub_backtrace_print_address (lp);
+  grub_printf (" (");
+  for (i = 0; i < 2; i++)
+   grub_printf ("%p,", ((void **)ptr) [i + 2]);
+  grub_printf ("%p)\n", ((void **)ptr) [i + 2]);
+  nptr = *(void **)ptr;
+  if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME
+ || nptr == ptr)
+   {
+ grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr);
+ break;
+   }
+  ptr = nptr;
+}
+}
+
+void
+grub_backtrace (void)
+{
+  grub_backtrace_pointer (1);
+}
+
diff --git a/grub-core/lib/backtrace.c b/grub-core/lib/backtrace.c
index 825a8800e..c0ad6ab8b 100644
--- a/grub-core/lib/backtrace.c
+++ b/grub-core/lib/backtrace.c
@@ -29,6 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 void
 grub_backtrace_print_address (void *addr)
 {
+#ifndef GRUB_UTIL
   grub_dl_t mod;
 
   FOR_DL_MODULES (mod)
@@ -44,6 +45,7 @@ grub_backtrace_print_address (void *addr)
}
   }
 
+#endif
   grub_printf ("%p", addr);
 }
 
diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c
index c3e03c727..c67273db3 100644
--- a/grub-core/lib/i386/backtrace.c
+++ b/grub-core/lib/i386/backtrace.c
@@ -15,11 +15,23 @@
  *  You should have received a copy of the GNU General Public License
  *  along with GRUB.  If not, see .
  */
+#include 
+#ifdef GRUB_UTIL
+#define REALLY_GRUB_UTIL GRUB_UTIL
+#undef GRUB_UTIL
+#endif
+
+#include 
+#include 
+
+#ifdef REALLY_GRUB_UTIL
+#define GRUB_UTIL REALLY_GRUB_UTIL
+#undef REALLY_GRUB_UTIL
+#endif
 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 34/37] btrfs: Fallback to old subvol name scheme to support old snapshot config

2024-10-07 Thread Leo Sandoval
From: Andrei Borzenkov 

Ref: bsc#953538
---
 grub-core/fs/btrfs.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index d44a1c73b..dba86d19b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -1339,11 +1339,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const 
char *path)
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+lookup_root_by_name_fallback(struct grub_btrfs_data *data, const char *path)
+{
+  grub_err_t err;
+  grub_uint64_t tree = 0;
+  grub_uint8_t type;
+  struct grub_btrfs_key key;
+
+  err = find_path (data, path, &key, &tree, &type);
+  if (err)
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
+
+  if (key.object_id != grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0)
+return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path);
+
+  data->fs_tree = tree;
+  return GRUB_ERR_NONE;
+}
+
 static grub_err_t
 btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused)))
 {
   if (btrfs_default_subvol)
-return lookup_root_by_name(data, btrfs_default_subvol);
+{
+  grub_err_t err;
+  err = lookup_root_by_name(data, btrfs_default_subvol);
+
+  /* Fallback to old schemes */
+  if (err == GRUB_ERR_FILE_NOT_FOUND)
+   {
+ err = GRUB_ERR_NONE;
+ return lookup_root_by_name_fallback(data, btrfs_default_subvol);
+   }
+  return err;
+}
 
   if (btrfs_default_subvolid)
 return lookup_root_by_id(data, btrfs_default_subvolid);
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] legacycfg.c: avoid closing file twice

2024-10-16 Thread Leo Sandoval
An Internal (at Red Hat) static soure code scan detected the issue below,
pointing to an use-after-free scenario so remove the extra file close
call.

Error: USE_AFTER_FREE (CWE-416):
grub-2.06/grub-core/commands/legacycfg.c:194: freed_arg: "grub_file_close" 
frees "file".
grub-2.06/grub-core/commands/legacycfg.c:201: deref_arg: Calling 
"grub_file_close" dereferences freed pointer "file".
#  199| if (!args)
#  200| {
#  201|-> grub_file_close (file);
#  202|   grub_free (suffix);
#  203|       grub_free (entrysrc);

Signed-off-by: Leo Sandoval 
---
 grub-core/commands/legacycfg.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c
index e9e9d94ef..3bf9fe2e4 100644
--- a/grub-core/commands/legacycfg.c
+++ b/grub-core/commands/legacycfg.c
@@ -198,7 +198,6 @@ legacy_file (const char *filename)
   const char **args = grub_malloc (sizeof (args[0]));
   if (!args)
{
- grub_file_close (file);
  grub_free (suffix);
  grub_free (entrysrc);
  return grub_errno;
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2 09/17] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.

2024-10-10 Thread Leo Sandoval
On Mon, Oct 7, 2024 at 1:05 PM  wrote:

> On 10/7/24 11:18 AM, Leo Sandoval wrote:
> > From: Peter Jones 
> >
> > Don't munge raw spaces when we're doing our cmdline escaping (#923374)
> >
> > Signed-off-by: Peter Jones 
> > ---
> >   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'));
> > +}
> > +
>
> Is there a way you can inline a version of this function in some library
> header to avoid duplicating it elsewhere? Also it seems like a generally
> useful function. Just a thought.
>

Good point. I see identical definitions in other files
(grub-core/lib/cmdline.c and grub-core/script/execute.c). I believe this
would required
a separated patch to unify all these definitions into one.


>
> Thanks
> Ross
>
> >   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 
> >   #include 
> >
> > +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,

Re: [PATCH v1 37/37] chainloader: Use grub_efi_...() memory helpers where reasonable.

2024-10-10 Thread Leo Sandoval
On Mon, Oct 7, 2024 at 1:44 PM  wrote:

> On 10/7/24 11:21 AM, Leo Sandoval wrote:
> > From: Peter Jones 
> >
> > This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and
> > grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we
> > get more reasonable type checking.
>
> While the idea of putting wrappers around the EFI pool allocation calls
> seems reasonable (re: previous patch), this patch does not do what the
> comment says. Nothing seems to call grub_efi_allocate_pool(). But since
> something freed a pool in grub_chainloader_boot(), it must have been
> allocated somewhere. Was that part left out?
>

you are right in both points, comment is not precise and there are other
places where grub_efi_allocate_pool()
wrapper can be used but it is left out. Adding the allocate wrapper
deserves a separate patch, For the moment,
I will update the comment and bump the version.


> Thanks
> Ross
>
> >
> > Signed-off-by: Peter Jones 
> > ---
> >   grub-core/loader/efi/chainloader.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/grub-core/loader/efi/chainloader.c
> b/grub-core/loader/efi/chainloader.c
> > index 1de98f783..203692450 100644
> > --- a/grub-core/loader/efi/chainloader.c
> > +++ b/grub-core/loader/efi/chainloader.c
> > @@ -95,7 +95,7 @@ grub_chainloader_boot (void *context)
> >   }
> >
> > if (exit_data)
> > -b->free_pool (exit_data);
> > +grub_efi_free_pool (exit_data);
> >
> > grub_loader_unset ();
> >
> > @@ -419,7 +419,7 @@ grub_cmd_chainloader (grub_command_t cmd
> __attribute__ ((unused)),
> > grub_free (file_path);
> >
> > if (address)
> > -b->free_pages (address, pages);
> > +grub_efi_free_pages (address, pages);
> >
> > if (image_handle != NULL)
> >   b->unload_image (image_handle);
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 08/20] 20_ppc_terminfo.in: Migrate PPC from Yaboot to Grub2

2024-10-02 Thread Leo Sandoval
On Mon, Sep 30, 2024 at 12:57 PM Vladimir 'phcoder' Serbinenko <
phco...@gmail.com> wrote:

> Why is it ppc-specific?
>

IBM wrote this patch so this is why this is ppc specific, but you are
right, it can apply to all archs. I will send a v2.



>
> Le lun. 30 sept. 2024, 20:49, Leo Sandoval  a écrit :
>
>> From: Mark Hamzy 
>>
>> Add configuration support for serial terminal consoles.  This will set
>> the maximum screen size so that text is not overwritten.
>>
>> Signed-off-by: Mark Hamzy 
>> Signed-off-by: Robbie Harwood 
>> ---
>>  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 0..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.1
>>
>>
>> ___
>> 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
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 05/20] normal/menu: Allow "fallback" to include entries by title, not just number.

2024-10-02 Thread Leo Sandoval
On Mon, Sep 30, 2024 at 1:03 PM Vladimir 'phcoder' Serbinenko <
phco...@gmail.com> wrote:

> Using titles is broken concept and the only reason we support it in
> default is backwards compatibility. Maybe it's better to restrict it to
> just IDs
>
>
The word 'title' is still on the doc
https://www.gnu.org/software/grub/manual/grub/html_node/default.html#default
, so we should support it, correct?  or update the doc instead and
completely remove the title option?



> Le lun. 30 sept. 2024, 20:48, Leo Sandoval  a écrit :
>
>> From: Peter Jones 
>>
>> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1026084
>>
>> Signed-off-by: Peter Jones 
>> ---
>>  grub-core/normal/menu.c | 85 -
>>  1 file changed, 58 insertions(+), 27 deletions(-)
>>
>> diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
>> index 6a90e091f..6444ee6f9 100644
>> --- a/grub-core/normal/menu.c
>> +++ b/grub-core/normal/menu.c
>> @@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout)
>>  }
>>  }
>>
>> +static int
>> +menuentry_eq (const char *id, const char *spec)
>> +{
>> +  const char *ptr1, *ptr2;
>> +  ptr1 = id;
>> +  ptr2 = spec;
>> +  while (1)
>> +{
>> +  if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
>> +   return ptr2 - spec;
>> +  if (*ptr2 == '>' && ptr2[1] != '>')
>> +   return 0;
>> +  if (*ptr2 == '>')
>> +   ptr2++;
>> +  if (*ptr1 != *ptr2)
>> +   return 0;
>> +  if (*ptr1 == 0)
>> +   return ptr1 - id;
>> +  ptr1++;
>> +  ptr2++;
>> +}
>> +  return 0;
>> +}
>> +
>>  /* Get the first entry number from the value of the environment variable
>> NAME,
>> which is a space-separated list of non-negative integers.  The entry
>> number
>> which is returned is stripped from the value of NAME.  If no entry
>> number
>> can be found, -1 is returned.  */
>>  static int
>> -get_and_remove_first_entry_number (const char *name)
>> +get_and_remove_first_entry_number (grub_menu_t menu, const char *name)
>>  {
>>const char *val, *tail;
>>int entry;
>> +  int sz = 0;
>>
>>val = grub_env_get (name);
>>if (! val)
>> @@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name)
>>
>>entry = (int) grub_strtoul (val, &tail, 0);
>>
>> +  if (grub_errno == GRUB_ERR_BAD_NUMBER)
>> +{
>> +  /* See if the variable matches the title of a menu entry.  */
>> +  grub_menu_entry_t e = menu->entry_list;
>> +  int i;
>> +
>> +  for (i = 0; e; i++)
>> +   {
>> + sz = menuentry_eq (e->title, val);
>> + if (sz < 1)
>> +   sz = menuentry_eq (e->id, val);
>> +
>> + if (sz >= 1)
>> +   {
>> + entry = i;
>> + break;
>> +   }
>> + e = e->next;
>> +   }
>> +
>> +  if (sz > 0)
>> +   grub_errno = GRUB_ERR_NONE;
>> +
>> +  if (! e)
>> +   entry = -1;
>> +}
>> +
>>if (grub_errno == GRUB_ERR_NONE)
>>  {
>> -  /* Skip whitespace to find the next digit.  */
>> +  if (sz > 0)
>> +   tail += sz;
>> +
>> +  /* Skip whitespace to find the next entry.  */
>>while (*tail && grub_isspace (*tail))
>> tail++;
>>grub_env_set (name, tail);
>> @@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
>>grub_menu_execute_entry (entry, 1);
>>
>>/* Deal with fallback entries.  */
>> -  while ((fallback_entry = get_and_remove_first_entry_number
>> ("fallback"))
>> +  while ((fallback_entry = get_and_remove_first_entry_number (menu,
>> "fallback"))
>>  >= 0)
>>  {
>>grub_print_error ();
>> @@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer
>> *viewer)
>>viewers = viewer;
>>  }
>>
>> -static int
>> -menuentry_eq (const char *id, const char *spec)
>> -{
>> -  const char *ptr1, *ptr2;
>> -  ptr1 = id;
>> -  ptr2 = spec;
>> -  while (1)
>> -{
>> -  if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
>> -   return 1;
>> -  if (*ptr2 == '>' && ptr2[1] != '>')
>> -   return 0;
>> -  if (*ptr2 == '>')
>> -   ptr2++;
>> -  if (*ptr1 != *ptr2)
>> -   return 0;
>> -  if (*ptr1 == 0)
>> -   return 1;
>> -  ptr1++;
>> -  ptr2++;
>> -}
>> -}
>> -
>> -
>>  /* Get the entry number from the variable NAME.  */
>>  static int
>>  get_entry_number (grub_menu_t menu, const char *name)
>> --
>> 2.46.1
>>
>>
>> ___
>> 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
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 03/20] ieee1275: Disable GRUB video support for IBM power machines

2024-10-02 Thread Leo Sandoval
On Mon, Sep 30, 2024 at 1:07 PM Vladimir 'phcoder' Serbinenko <
phco...@gmail.com> wrote:

> This needs a detailed comment in quirks code as to why we disable video
> mode.
>

Agree. Let me include it in v2.


>
> Le lun. 30 sept. 2024, 20:47, Leo Sandoval  a écrit :
>
>> From: Paulo Flabiano Smorigo 
>>
>> Should fix the problem in bugzilla:
>> https://bugzilla.redhat.com/show_bug.cgi?id=973205
>>
>> Signed-off-by: Paulo Flabiano Smorigo 
>> Signed-off-by: Robbie Harwood 
>> ---
>>  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.1
>>
>>
>> ___
>> 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
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2 00/30] Second Distro-agnostic series taken from Fedora Rawhide

2024-10-14 Thread Leo Sandoval
On Sat, Oct 12, 2024 at 8:55 AM Neal Gompa  wrote:

> On Fri, Oct 11, 2024 at 6:39 PM Leo Sandoval  wrote:
> >
> > This is the second 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.
> >
> > Changes since v1:
> > - delete 0024-efinet-and-bootp-add-support-for-dhcpv6.patch
> >   build issue, so for the moment discarting it
> >
> > - delete 0025-bootp-New-net_bootp6-command.patch
> >   patch will be sent separately by mchang
> >
> > - delete 0027-Make-grub_fatal-also-backtrace.patch
> >   not accepted
> >
> > - delete 0028-Make-our-info-pages-say-grub2-where-appropriate.patch
> >   non-distro agnostic
> >
> > - delete 0034-grub2-btrfs-04-grub2-install.patch
> >   patch will be revisited by author (mchang)
> >
> > - delete 0036-grub2-btrfs-06-subvol-mount.patch
> >   not accepted
> >
> > Andrei Borzenkov (1):
> >   btrfs: Fallback to old subvol name scheme to support old snapshot
> > config
> >
> > Jeff Mahoney (1):
> >   btrfs: Add ability to boot from subvolumes
> >
> > Josef Bacik (1):
> >   net/tcp: add window scaling support
> >
> > Michael Chang (4):
> >   btrfs: export btrfs_subvol and btrfs_subvolid
> >   btrfs: grub2-btrfs-03-follow_default
> >   btdfs: grub2-btrfs-05-grub2-mkconfig
> >   btrfs: Grub not working correctly with btrfs snapshots (bsc#1026511)
> >
> > Peter Jones (6):
> >   10_linux.in: Make grub2-mkconfig construct titles that look like the
> > ones we want elsewhere.
> >   grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it
> > in 10_linux
> >   30_os-prober.in: just build chainloader entries, don't try any xnu
> > xnu.
> >   btrfs: fix a bad null check
> >   efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.
> >   chainloader: Use grub_efi_...() memory helpers where reasonable.
> >
> > Robert Marshall (1):
> >   grub-set-password.in: Add friendly grub2 password config tool
> > (#985962)
> >
>
> I appreciate that you're doing this, thank you! I've given some
> feedback on the btrfs patches, though alas I missed the v1 round where
> some of the patches were debated.
>

Thanks for the feedback Neal. I am about to bump the series version with
your comments and some descriptions provided by mchang.


>
>
>
> --
> 真実はいつも一つ!/ Always, there's only one truth!
>
> ___
> 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


[PATCH v3 20/29] grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it in 10_linux

2024-10-14 Thread Leo Sandoval
From: Peter Jones 

This patch adds grub-get-kernel-settings, which reads the system kernel
installation configuration from /etc/sysconfig/kernel, and outputs
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
variables are then used by 10_linux to choose whether or not to create
debug stanzas.

Resolves: rhbz#1226325
[rharwood: migrate man page to h2m]
---
 Makefile.util.def |  7 ++
 configure.ac  |  1 +
 docs/man/grub-get-kernel-settings.h2m |  2 +
 .../bash-completion.d/grub-completion.bash.in | 22 +
 util/grub-get-kernel-settings.in  | 88 +++
 util/grub-mkconfig.in |  3 +
 util/grub.d/10_linux.in   | 23 +++--
 7 files changed, 141 insertions(+), 5 deletions(-)
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
 create mode 100644 util/grub-get-kernel-settings.in

diff --git a/Makefile.util.def b/Makefile.util.def
index 95884956a..84a17ef5c 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -725,6 +725,13 @@ script = {
   installdir = sbin;
 };
 
+script = {
+  name = grub-get-kernel-settings;
+  common = util/grub-get-kernel-settings.in;
+  mansection = 3;
+  installdir = sbin;
+};
+
 script = {
   name = grub-set-default;
   common = util/grub-set-default.in;
diff --git a/configure.ac b/configure.ac
index 493e336ec..3602b4ab6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,7 @@ grub_TRANSFORM([grub-install])
 grub_TRANSFORM([grub-mkconfig])
 grub_TRANSFORM([grub-mkfont])
 grub_TRANSFORM([grub-mkimage])
+grub_TRANSFORM([grub-get-kernel-settings])
 grub_TRANSFORM([grub-glue-efi])
 grub_TRANSFORM([grub-mklayout])
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
diff --git a/docs/man/grub-get-kernel-settings.h2m 
b/docs/man/grub-get-kernel-settings.h2m
new file mode 100644
index 0..b8051f01f
--- /dev/null
+++ b/docs/man/grub-get-kernel-settings.h2m
@@ -0,0 +1,2 @@
+[NAME]
+grub-get-kernel-settings \- Evaluate the system's kernel installation settings 
for use while making a grub configuration file
diff --git a/util/bash-completion.d/grub-completion.bash.in 
b/util/bash-completion.d/grub-completion.bash.in
index 213ce1e57..da7fca5ef 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -275,6 +275,28 @@ have ${__grub_sparc64_setup_program} && \
 unset __grub_sparc64_setup_program
 
 
+#
+# grub-get-kernel-settings
+#
+_grub_get_kernel_settings () {
+local cur
+
+COMPREPLY=()
+cur=`_get_cword`
+
+if [[ "$cur" == -* ]]; then
+__grubcomp "$(__grub_get_options_from_help)"
+else
+# Default complete with a filename
+_filedir
+fi
+}
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
+have ${__grub_get_kernel_settings_program} && \
+ complete -F _grub_get_kernel_settings -o filenames 
${__grub_get_kernel_settings_program}
+unset __grub_get_kernel_settings_program
+
+
 #
 # grub-install
 #
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
new file mode 100644
index 0..7e87dfccc
--- /dev/null
+++ b/util/grub-get-kernel-settings.in
@@ -0,0 +1,88 @@
+#!/bin/sh
+set -e
+
+# Evaluate new-kernel-pkg's configuration file.
+# Copyright (C) 2016 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 .
+
+PACKAGE_NAME=@PACKAGE_NAME@
+PACKAGE_VERSION=@PACKAGE_VERSION@
+datadir="@datadir@"
+if [ "x$pkgdatadir" = x ]; then
+pkgdatadir="${datadir}/@PACKAGE@"
+fi
+
+self=`basename $0`
+
+export TEXTDOMAIN=@PACKAGE@
+export TEXTDOMAINDIR="@localedir@"
+
+. "${pkgdatadir}/grub-mkconfig_lib"
+
+# Usage: usage
+# Print the usage.
+usage () {
+gettext_printf "Usage: %s [OPTION]\n" "$self"
+gettext "Evaluate new-kernel-pkg configuration"; echo
+echo
+print_option_help "-h, --help" "$(gettext "print this message and exit")"
+print_option_help "-v, --version" "$(gettext "print the version 
information and exit")"
+echo
+}
+
+# Check the arguments.
+while test $# -gt 0
+do
+option=$1
+shift
+
+case "$option" in
+-h | --help)
+   usage
+   exit 0 ;;
+-v | --version)
+   echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
+   exit 0 ;;
+-*)
+   gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
+   usage
+   exit 1
+   ;

[PATCH v3 17/29] 10_linux.in: Make grub2-mkconfig construct titles that look like the ones we want elsewhere.

2024-10-14 Thread Leo Sandoval
From: Peter Jones 

Resolves: rhbz#1215839

Signed-off-by: Peter Jones 
---
 util/grub.d/10_linux.in | 34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 3105c31e4..0115dd0c0 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -80,6 +80,32 @@ case x"$GRUB_FS" in
;;
 esac
 
+mktitle ()
+{
+  local title_type
+  local version
+  local OS_NAME
+  local OS_VERS
+
+  title_type=$1 && shift
+  version=$1 && shift
+
+  OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})"
+  OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
+
+  case $title_type in
+recovery)
+  title=$(printf '%s (%s) %s (recovery mode)' \
+ "${OS_NAME}" "${version}" "${OS_VERS}")
+  ;;
+*)
+  title=$(printf '%s (%s) %s' \
+ "${OS_NAME}" "${version}" "${OS_VERS}")
+  ;;
+  esac
+  echo -n ${title}
+}
+
 title_correction_code=
 
 linux_entry ()
@@ -93,17 +119,11 @@ linux_entry ()
   boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
   fi
   if [ x$type != xsimple ] ; then
-  case $type in
- recovery)
- title="$(gettext_printf "%s, with Linux %s (recovery mode)" 
"${os}" "${version}")" ;;
- *)
- title="$(gettext_printf "%s, with Linux %s" "${os}" 
"${version}")" ;;
-  esac
+  title=$(mktitle "$type" "$version")
   if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux 
versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  replacement_title="$(echo "Advanced options for ${OS}" | sed 
's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  title_correction_code="${title_correction_code}if [ \"x\$default\" = 
'$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
- grub_warn "$(gettext_printf "Please don't use old title \`%s' for 
GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or 
later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" 
"gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
   fi
   echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} 
\$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed 
"s/^/$submenu_indentation/"
   else
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 21/29] 30_os-prober.in: just build chainloader entries, don't try any xnu xnu.

2024-10-14 Thread Leo Sandoval
From: Peter Jones 

Since our bugs tell us that the xnu boot entries really just don't work
most of the time, and they create piles of extra boot entries, because
they can't quite figure out 32-vs-64 and other stuff like that.

It's rediculous, and we should just boot their bootloader through the
chainloader instead.

So this patch does that.

Resolves: rhbz#893179

Signed-off-by: Peter Jones 
---
 util/grub.d/30_os-prober.in | 78 +
 1 file changed, 18 insertions(+), 60 deletions(-)

diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index 656301eaf..1aac097c1 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -45,68 +45,25 @@ if [ -z "${OSPROBED}" ] ; then
 fi
 
 osx_entry() {
-if [ x$2 = x32 ]; then
-# TRANSLATORS: it refers to kernel architecture (32-bit)
-   bitstr="$(gettext "(32-bit)")"
-else
-# TRANSLATORS: it refers to kernel architecture (64-bit)
-   bitstr="$(gettext "(64-bit)")"
-fi
 # TRANSLATORS: it refers on the OS residing on device %s
 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-cat << EOF
-menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx 
--class darwin --class os \$menuentry_id_option 
'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
+hints=""
+for hint in `"${grub_probe}" --device ${device} --target=efi_hints 2> 
/dev/null` ; do
+  hints="${hints} --hint=${hint}"
+done
+cat << EOF
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class osx --class 
darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id 
"${DEVICE}")'  {
 EOF
save_default_entry | grub_add_tab
prepare_grub_to_access_device ${DEVICE} | grub_add_tab
cat << EOF
+   set gfxpayload=keep
 load_video
-set do_resume=0
-if [ /var/vm/sleepimage -nt10 / ]; then
-   if xnu_resume /var/vm/sleepimage; then
- set do_resume=1
-   fi
-fi
-if [ \$do_resume = 0 ]; then
-   xnu_uuid ${OSXUUID} uuid
-   if [ -f /Extra/DSDT.aml ]; then
-  acpi -e /Extra/DSDT.aml
-   fi
-   if [ /kernelcache -nt /System/Library/Extensions ]; then
-  $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
-   elif [ -f /System/Library/Kernels/kernel ]; then
-  $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid
-  xnu_kextdir /System/Library/Extensions
-   else
-  $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
-  if [ /System/Library/Extensions.mkext -nt 
/System/Library/Extensions ]; then
-xnu_mkext /System/Library/Extensions.mkext
-  else
-xnu_kextdir /System/Library/Extensions
-  fi
-   fi
-   if [ -f /Extra/Extensions.mkext ]; then
-  xnu_mkext /Extra/Extensions.mkext
-   fi
-   if [ -d /Extra/Extensions ]; then
-  xnu_kextdir /Extra/Extensions
-   fi
-   if [ -f /Extra/devprop.bin ]; then
-  xnu_devprop_load /Extra/devprop.bin
-   fi
-   if [ -f /Extra/splash.jpg ]; then
-  insmod jpeg
-  xnu_splash /Extra/splash.jpg
-   fi
-   if [ -f /Extra/splash.png ]; then
-  insmod png
-  xnu_splash /Extra/splash.png
-   fi
-   if [ -f /Extra/splash.tga ]; then
-  insmod tga
-  xnu_splash /Extra/splash.tga
-   fi
-fi
+   insmod part_gpt
+   insmod hfsplus
+   search --no-floppy --fs-uuid --set=root ${hints} $(grub_get_device_id 
"${DEVICE}")
+   chainloader (\$root)/System/Library/CoreServices/boot.efi
+   boot
 }
 EOF
 }
@@ -299,11 +256,12 @@ EOF
   echo "$title_correction_code"
 ;;
 macosx)
-  if [ "${UUID}" ]; then
-   OSXUUID="${UUID}"
-   osx_entry xnu_kernel 32
-   osx_entry xnu_kernel64 64
-  fi
+  for subdevice in ${DEVICE%[[:digit:]]*}* ; do
+   parttype="`"${grub_probe}" --device ${device} --target=gpt_parttype 
"${subdevice}" 2> /dev/null`"
+   if [[ "$parttype" = "426f6f74--11aa-aa11-00306543ecac" ]]; then
+ DEVICE="${subdevice}" osx_entry
+   fi
+  done
 ;;
 hurd)
   onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 19/29] net/tcp: add window scaling support

2024-10-14 Thread Leo Sandoval
From: Josef Bacik 

Sometimes we have to provision boxes across regions, such as California to
Sweden.  The http server has a 10 minute timeout, so if we can't get our 250mb
image transferred fast enough our provisioning fails, which is not ideal.  So
add tcp window scaling on open connections and set the window size to 1mb.  With
this change we're able to get higher sustained transfers between regions and can
transfer our image in well below 10 minutes.  Without this patch we'd time out
every time halfway through the transfer.  Thanks,

Signed-off-by: Josef Bacik 
---
 grub-core/net/tcp.c | 42 +-
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c
index 93dee0caa..902ab7e8a 100644
--- a/grub-core/net/tcp.c
+++ b/grub-core/net/tcp.c
@@ -106,6 +106,18 @@ struct tcphdr
   grub_uint16_t urgent;
 } GRUB_PACKED;
 
+struct tcp_scale_opt {
+  grub_uint8_t kind;
+  grub_uint8_t length;
+  grub_uint8_t scale;
+} GRUB_PACKED;
+
+struct tcp_synhdr {
+  struct tcphdr tcphdr;
+  struct tcp_scale_opt scale_opt;
+  grub_uint8_t padding;
+};
+
 struct tcp_pseudohdr
 {
   grub_uint32_t src;
@@ -571,7 +583,7 @@ grub_net_tcp_open (char *server,
   grub_net_tcp_socket_t socket;
   static grub_uint16_t in_port = 21550;
   struct grub_net_buff *nb;
-  struct tcphdr *tcph;
+  struct tcp_synhdr *tcph;
   int i;
   grub_uint8_t *nbd;
   grub_net_link_level_address_t ll_target_addr;
@@ -640,20 +652,24 @@ grub_net_tcp_open (char *server,
 }
 
   tcph = (void *) nb->data;
+  grub_memset(tcph, 0, sizeof (*tcph));
   socket->my_start_seq = grub_get_time_ms ();
   socket->my_cur_seq = socket->my_start_seq + 1;
-  socket->my_window = 8192;
-  tcph->seqnr = grub_cpu_to_be32 (socket->my_start_seq);
-  tcph->ack = grub_cpu_to_be32_compile_time (0);
-  tcph->flags = grub_cpu_to_be16_compile_time ((5 << 12) | TCP_SYN);
-  tcph->window = grub_cpu_to_be16 (socket->my_window);
-  tcph->urgent = 0;
-  tcph->src = grub_cpu_to_be16 (socket->in_port);
-  tcph->dst = grub_cpu_to_be16 (socket->out_port);
-  tcph->checksum = 0;
-  tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
-  &socket->inf->address,
-  &socket->out_nla);
+  socket->my_window = 32768;
+  tcph->tcphdr.seqnr = grub_cpu_to_be32 (socket->my_start_seq);
+  tcph->tcphdr.ack = grub_cpu_to_be32_compile_time (0);
+  tcph->tcphdr.flags = grub_cpu_to_be16_compile_time ((6 << 12) | TCP_SYN);
+  tcph->tcphdr.window = grub_cpu_to_be16 (socket->my_window);
+  tcph->tcphdr.urgent = 0;
+  tcph->tcphdr.src = grub_cpu_to_be16 (socket->in_port);
+  tcph->tcphdr.dst = grub_cpu_to_be16 (socket->out_port);
+  tcph->tcphdr.checksum = 0;
+  tcph->scale_opt.kind = 3;
+  tcph->scale_opt.length = 3;
+  tcph->scale_opt.scale = 5;
+  tcph->tcphdr.checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
+ &socket->inf->address,
+ &socket->out_nla);
 
   tcp_socket_register (socket);
 
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 23/29] btrfs: fix a bad null check

2024-10-14 Thread Leo Sandoval
From: Peter Jones 

current gcc complains:

  grub-core/fs/btrfs.c: In function ‘grub_cmd_btrfs_info’:
  grub-core/fs/btrfs.c:2745:7: error: the comparison will always evaluate as 
‘true’ for the address of ‘label’ will never be NULL [-Werror=address]
   2745 |   if (data->sblock.label)
|   ^~~~
  grub-core/fs/btrfs.c:92:8: note: ‘label’ declared here
 92 |   char label[0x100];
|^
  cc1: all warnings being treated as errors

Obviously this check should be on the first data byte instead of the
symbol itself.

Signed-off-by: Peter Jones 
---
 grub-core/fs/btrfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index f14fe9c1b..8e2b1e9f7 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2625,7 +2625,7 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ 
((unused)), int argc,
   return grub_error (GRUB_ERR_BAD_ARGUMENT, "failed to open fs");
 }
 
-  if (data->sblock.label)
+  if (data->sblock.label[0])
 grub_printf("Label: '%s' ", data->sblock.label);
   else
 grub_printf("Label: none ");
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 29/29] chainloader: Use grub_efi_...() memory helpers where reasonable.

2024-10-14 Thread Leo Sandoval
From: Peter Jones 

This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and
grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we
get more reasonable type checking.

Signed-off-by: Peter Jones 
---
 grub-core/loader/efi/chainloader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/efi/chainloader.c 
b/grub-core/loader/efi/chainloader.c
index 1de98f783..203692450 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -95,7 +95,7 @@ grub_chainloader_boot (void *context)
 }
 
   if (exit_data)
-b->free_pool (exit_data);
+grub_efi_free_pool (exit_data);
 
   grub_loader_unset ();
 
@@ -419,7 +419,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ 
((unused)),
   grub_free (file_path);
 
   if (address)
-b->free_pages (address, pages);
+grub_efi_free_pages (address, pages);
 
   if (image_handle != NULL)
 b->unload_image (image_handle);
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 18/29] grub-set-password.in: Add friendly grub2 password config tool (#985962)

2024-10-14 Thread Leo Sandoval
From: Robert Marshall 

Provided a tool for users to reset the grub2 root user password
without having to alter the grub.cfg. The hashed password now
lives in a root-only-readable configuration file.

Resolves: rhbz#985962

Signed-off-by: Robert Marshall 
[pjones: fix the efidir in grub-setpassword and rename tool]
Signed-off-by: Peter Jones 
[luto: fix grub-setpassword -o's output path]
Signed-off-by: Andy Lutomirski 
[rharwood: migrate man page to h2m, context]
Signed-off-by: Robbie Harwood 
---
 Makefile.util.def  |  13 
 configure.ac   |   1 +
 docs/man/grub-set-password.h2m |   2 +
 util/grub-mkconfig.in  |   2 +
 util/grub-set-password.in  | 121 +
 util/grub.d/01_users.in|  11 +++
 6 files changed, 150 insertions(+)
 create mode 100644 docs/man/grub-set-password.h2m
 create mode 100644 util/grub-set-password.in
 create mode 100644 util/grub.d/01_users.in

diff --git a/Makefile.util.def b/Makefile.util.def
index 09bfcadd9..95884956a 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -455,6 +455,12 @@ script = {
   installdir = grubconf;
 };
 
+script = {
+  name = '01_users';
+  common = util/grub.d/01_users.in;
+  installdir = grubconf;
+};
+
 script = {
   name = '10_windows';
   common = util/grub.d/10_windows.in;
@@ -733,6 +739,13 @@ script = {
   installdir = sbin;
 };
 
+script = {
+  name = grub-set-password;
+  common = util/grub-set-password.in;
+  mansection = 8;
+  installdir = sbin;
+};
+
 script = {
   name = grub-mkconfig_lib;
   common = util/grub-mkconfig_lib.in;
diff --git a/configure.ac b/configure.ac
index ae3a49321..493e336ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,6 +77,7 @@ grub_TRANSFORM([grub-mkrelpath])
 grub_TRANSFORM([grub-mkrescue])
 grub_TRANSFORM([grub-probe])
 grub_TRANSFORM([grub-reboot])
+grub_TRANSFORM([grub-set-password])
 grub_TRANSFORM([grub-script-check])
 grub_TRANSFORM([grub-set-default])
 grub_TRANSFORM([grub-sparc64-setup])
diff --git a/docs/man/grub-set-password.h2m b/docs/man/grub-set-password.h2m
new file mode 100644
index 0..10ee82f4d
--- /dev/null
+++ b/docs/man/grub-set-password.h2m
@@ -0,0 +1,2 @@
+[NAME]
+grub-set-password \- generate the user.cfg file containing the hashed grub 
bootloader password
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index d1bf4983b..9d5d7964b 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -283,6 +283,8 @@ for i in "${grub_mkconfig_dir}"/* ; do
 *~) ;;
 # emacsen autosave files. FIXME: support other editors
 */\#*\#) ;;
+# rpm config files of yore.
+*.rpmsave|*.rpmnew|*.rpmorig) ;;
 *)
   if grub_file_is_not_garbage "$i" && test -x "$i" ; then
 echo
diff --git a/util/grub-set-password.in b/util/grub-set-password.in
new file mode 100644
index 0..d8005e5a1
--- /dev/null
+++ b/util/grub-set-password.in
@@ -0,0 +1,121 @@
+#!/bin/sh -e
+
+grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
+
+PACKAGE_VERSION="@PACKAGE_VERSION@"
+PACKAGE_NAME="@PACKAGE_NAME@"
+self=`basename $0`
+bindir="@bindir@"
+grub_mkpasswd="${bindir}/@grub_mkpasswd_pbkdf2@"
+
+# Usage: usage
+# Print the usage.
+usage () {
+cat <  put user.cfg in a user-selected directory
+
+Report bugs at https://bugzilla.redhat.com.
+EOF
+}
+
+argument () {
+opt=$1
+shift
+
+if test $# -eq 0; then
+gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" 
"$opt" 1>&2
+exit 1
+fi
+echo $1
+}
+
+# Ensure that it's the root user running this script
+if [ "${EUID}" -ne 0 ]; then
+echo "The grub bootloader password may only be set by root."
+usage
+exit 2
+fi
+
+# Check the arguments.
+while test $# -gt 0
+do
+option=$1
+shift
+
+case "$option" in
+-h | --help)
+   usage
+   exit 0 ;;
+-v | --version)
+   echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
+   exit 0 ;;
+-o | --output)
+OUTPUT_PATH=`argument $option "$@"`; shift ;;
+--output=*)
+OUTPUT_PATH=`echo "$option" | sed 's/--output=//'` ;;
+-o=*)
+OUTPUT_PATH=`echo "$option" | sed 's/-o=//'` ;;
+esac
+done
+
+# set user input or default path for user.cfg file
+if [ -z "${OUTPUT_PATH}" ]; then
+OUTPUT_PATH="${grubdir}"
+fi
+
+if [ ! -d "${OUTPUT_PATH}" ]; then
+echo "${OUTPUT_PATH} does not exist."
+usage
+exit 2;
+fi
+
+ttyopt=$(stty -g)
+fixtty() {
+  stty ${ttyopt}
+}
+
+trap fixtty EXIT
+stty -echo
+
+# prompt & confirm new grub2 root user password
+echo -n "Enter password: "
+read PASSWORD
+echo
+echo -n "Confirm password: "
+read PASSWORD_CONFIRM
+echo
+stty ${ttyopt}
+
+getpass() {
+local P0
+local P1
+P0="$1" && shift
+P1="$1" && shift
+
+( echo ${P0} ; echo ${P1} ) | \
+LC_ALL=C ${grub_mkpasswd} | \
+grep -v '[eE]nter password:' | \
+sed -e "s/PBKDF2 hash of your password is //"
+}
+
+MYPASS="$(getpass "${PASSWORD}" "$

[PATCH v3 22/29] btrfs: Add ability to boot from subvolumes

2024-10-14 Thread Leo Sandoval
From: Jeff Mahoney 

This patch adds the ability to specify a different root on a btrfs
filesystem too boot from other than the default one.

btrfs-list-snapshots  will list the subvolumes available on the
filesystem.

set btrfs_subvol= and set btrfs_subvolid= will specify
which subvolume to use and any pathnames provided with either of those
variables set will start using that root. If the subvolume or subvolume id
doesn't exist, then an error case will result.

It is possible to boot into a separate GRUB instance by exporting the
variable and loading the config file from the subvolume.

Signed-off-by: Jeff Mahoney 
---
 grub-core/fs/btrfs.c | 554 +--
 include/grub/btrfs.h |   1 +
 2 files changed, 534 insertions(+), 21 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index ba0c58352..f14fe9c1b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -38,6 +38,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -79,9 +82,11 @@ struct grub_btrfs_superblock
   grub_uint64_t generation;
   grub_uint64_t root_tree;
   grub_uint64_t chunk_tree;
-  grub_uint8_t dummy2[0x20];
+  grub_uint8_t dummy2[0x18];
+  grub_uint64_t bytes_used;
   grub_uint64_t root_dir_objectid;
-  grub_uint8_t dummy3[0x41];
+  grub_uint64_t num_devices;
+  grub_uint8_t dummy3[0x39];
   struct grub_btrfs_device this_device;
   char label[0x100];
   grub_uint8_t dummy4[0x100];
@@ -121,6 +126,7 @@ struct grub_btrfs_data
   grub_uint64_t exttree;
   grub_size_t extsize;
   struct grub_btrfs_extent_data *extent;
+  grub_uint64_t fs_tree;
 };
 
 struct grub_btrfs_chunk_item
@@ -191,6 +197,14 @@ struct grub_btrfs_leaf_descriptor
   } *data;
 };
 
+struct grub_btrfs_root_ref
+{
+  grub_uint64_t dirid;
+  grub_uint64_t sequence;
+  grub_uint16_t name_len;
+  const char name[0];
+} __attribute__ ((packed));
+
 struct grub_btrfs_time
 {
   grub_int64_t sec;
@@ -236,6 +250,14 @@ struct grub_btrfs_extent_data
 
 #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
 
+#define GRUB_BTRFS_ROOT_TREE_OBJECTID 1ULL
+#define GRUB_BTRFS_FS_TREE_OBJECTID 5ULL
+#define GRUB_BTRFS_ROOT_REF_KEY 156
+#define GRUB_BTRFS_ROOT_ITEM_KEY 132
+
+static grub_uint64_t btrfs_default_subvolid = 0;
+static char *btrfs_default_subvol = NULL;
+
 static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
   256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2
 };
@@ -1252,6 +1274,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, 
grub_disk_addr_t addr,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree,
+grub_uint64_t objectid, grub_uint64_t offset,
+grub_uint64_t *fs_root);
+
+static grub_err_t
+lookup_root_by_id(struct grub_btrfs_data *data, grub_uint64_t id)
+{
+  grub_err_t err;
+  grub_uint64_t tree;
+
+  err = get_fs_root(data, data->sblock.root_tree, id, -1, &tree);
+  if (!err)
+data->fs_tree = tree;
+  return err;
+}
+
+static grub_err_t
+find_path (struct grub_btrfs_data *data,
+  const char *path, struct grub_btrfs_key *key,
+  grub_uint64_t *tree, grub_uint8_t *type);
+
+static grub_err_t
+lookup_root_by_name(struct grub_btrfs_data *data, const char *path)
+{
+  grub_err_t err;
+  grub_uint64_t tree = 0;
+  grub_uint8_t type;
+  struct grub_btrfs_key key;
+
+  err = find_path (data, path, &key, &tree, &type);
+  if (err)
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
+
+  if (key.object_id != grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0)
+return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path);
+
+  data->fs_tree = tree;
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused)))
+{
+  if (btrfs_default_subvol)
+return lookup_root_by_name(data, btrfs_default_subvol);
+
+  if (btrfs_default_subvolid)
+return lookup_root_by_id(data, btrfs_default_subvolid);
+
+  data->fs_tree = 0;
+
+  return GRUB_ERR_NONE;
+}
+
+
 static struct grub_btrfs_data *
 grub_btrfs_mount (grub_device_t dev)
 {
@@ -1287,6 +1365,13 @@ grub_btrfs_mount (grub_device_t dev)
   data->devices_attached[0].dev = dev;
   data->devices_attached[0].id = data->sblock.this_device.device_id;
 
+  err = btrfs_handle_subvol (data);
+  if (err)
+{
+  grub_free (data);
+  return NULL;
+}
+
   return data;
 }
 
@@ -1784,6 +1869,91 @@ get_root (struct grub_btrfs_data *data, struct 
grub_btrfs_key *key,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+find_pathname(struct grub_btrfs_data *data, grub_uint64_t objectid,
+  grub_uint64_t fs_root, const char *name, char **pathname)
+{
+  grub_err_t err;
+  struct grub_btrfs_key key = {
+.object_id = objectid,
+.type = GRUB_BTRFS_ITEM_TYPE_INODE_REF,
+.offset = 0,
+  };
+  struct grub_btrfs_key key_out;
+  struct grub_btrfs_leaf_descrip

[PATCH v3 24/29] btrfs: export btrfs_subvol and btrfs_subvolid

2024-10-14 Thread Leo Sandoval
From: Michael Chang 

We should export btrfs_subvol and btrfs_subvolid to have both visible
to subsidiary configuration files loaded using configfile.

Signed-off-by: Michael Chang 
---
 grub-core/fs/btrfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 8e2b1e9f7..14e38a4df 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2920,6 +2920,8 @@ GRUB_MOD_INIT (btrfs)
subvol_set_env);
   grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env,
subvolid_set_env);
+  grub_env_export ("btrfs_subvol");
+  grub_env_export ("btrfs_subvolid");
 }
 
 GRUB_MOD_FINI (btrfs)
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 00/29] Second Distro-agnostic series taken from Fedora Rawhide

2024-10-14 Thread Leo Sandoval
This is the second 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.

Thanks to Michael Chang for suggesting and providing updated summaries and 
descriptions.

Changes since v2:
- modified 0033-grub2-btrfs-03-follow_default.patch
  commit summary/description updated/included

- modified 0035-grub2-btrfs-05-grub2-mkconfig.patch
  commit summary/description updated/included

- deleted 0037-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch
  issue should no longer exist & outdated

- modified   
patches/0038-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch
  commit summary/description updated/included

Changes since v1:
- delete 0024-efinet-and-bootp-add-support-for-dhcpv6.patch
  build issue, so for the moment discarting it

- delete 0025-bootp-New-net_bootp6-command.patch
  patch will be sent separately by mchang

- delete 0027-Make-grub_fatal-also-backtrace.patch
  not accepted

- delete 0028-Make-our-info-pages-say-grub2-where-appropriate.patch
  non-distro agnostic

- delete 0034-grub2-btrfs-04-grub2-install.patch
  patch will be revisited by author (mchang)

- delete 0036-grub2-btrfs-06-subvol-mount.patch
  not accepted


Jeff Mahoney (1):
  btrfs: Add ability to boot from subvolumes

Josef Bacik (1):
  net/tcp: add window scaling support

Michael Chang (4):
  btrfs: export btrfs_subvol and btrfs_subvolid
  btrfs: Allow specifying btrfs_relative_path to follow the default
subvolume
  grub-mkconfig: Add GRUB_BTRFS_SNAPSHOT_BOOTING simple configuration
  btrfs: add btrfs-get-default-subvol command

Peter Jones (6):
  10_linux.in: Make grub2-mkconfig construct titles that look like the
ones we want elsewhere.
  grub-get-kernel-settings.in: Add grub-get-kernel-settings and use it
in 10_linux
  30_os-prober.in: just build chainloader entries, don't try any xnu
xnu.
  btrfs: fix a bad null check
  efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.
  chainloader: Use grub_efi_...() memory helpers where reasonable.

Robert Marshall (1):
  grub-set-password.in: Add friendly grub2 password config tool
(#985962)

 Makefile.util.def |  20 +
 configure.ac  |   2 +
 docs/man/grub-get-kernel-settings.h2m |   2 +
 docs/man/grub-set-password.h2m|   2 +
 grub-core/fs/btrfs.c  | 865 +-
 grub-core/loader/efi/chainloader.c|   4 +-
 grub-core/net/tcp.c   |  42 +-
 include/grub/btrfs.h  |   1 +
 include/grub/efi/efi.h|  36 +-
 .../bash-completion.d/grub-completion.bash.in |  22 +
 util/grub-get-kernel-settings.in  |  88 ++
 util/grub-mkconfig.in |   9 +-
 util/grub-mkconfig_lib.in |   4 +
 util/grub-set-password.in | 121 +++
 util/grub.d/00_header.in  |  25 +-
 util/grub.d/01_users.in   |  11 +
 util/grub.d/10_linux.in   |  61 +-
 util/grub.d/20_linux_xen.in   |   4 +
 util/grub.d/30_os-prober.in   |  78 +-
 19 files changed, 1270 insertions(+), 127 deletions(-)
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
 create mode 100644 docs/man/grub-set-password.h2m
 create mode 100644 util/grub-get-kernel-settings.in
 create mode 100644 util/grub-set-password.in
 create mode 100644 util/grub.d/01_users.in

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 26/29] grub-mkconfig: Add GRUB_BTRFS_SNAPSHOT_BOOTING simple configuration

2024-10-14 Thread Leo Sandoval
From: Michael Chang 

To support btrfs rollback and snapshot booting, a simple configuration setting
GRUB_BTRFS_SNAPSHOT_BOOTING is introduced to enable this at the configuration
level. When set to "yes," grub-mkconfig will set btrfs_relative_path=y, and all
paths produced by grub-mkrelpath will be relative to the default subvolume.

Signed-off-by: Michael Chang 
---
 util/grub-mkconfig.in   |  4 +++-
 util/grub-mkconfig_lib.in   |  4 
 util/grub.d/00_header.in| 25 -
 util/grub.d/10_linux.in |  4 
 util/grub.d/20_linux_xen.in |  4 
 5 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 91f761331..b9932147d 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -259,7 +259,9 @@ export GRUB_DEFAULT \
   GRUB_BADRAM \
   GRUB_OS_PROBER_SKIP_LIST \
   GRUB_DISABLE_SUBMENU \
-  GRUB_DEFAULT_DTB
+  GRUB_DEFAULT_DTB \
+  GRUB_BTRFS_SNAPSHOT_BOOTING
+
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 33e1750ae..71e75f0bc 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -49,7 +49,11 @@ grub_warn ()
 
 make_system_path_relative_to_its_root ()
 {
+  if [ "x${GRUB_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
+  "${grub_mkrelpath}" -r "$1"
+  else
   "${grub_mkrelpath}" "$1"
+  fi
 }
 
 is_path_readable_by_grub ()
diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
index 6a316a5ba..2e94a4c95 100644
--- a/util/grub.d/00_header.in
+++ b/util/grub.d/00_header.in
@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
+if [ "x${GRUB_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+cat /dev/null || true`
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v3 27/29] btrfs: add btrfs-get-default-subvol command

2024-10-14 Thread Leo Sandoval
From: Michael Chang 

Introduce the "btrfs-get-default-subvol" command to output the default
subvolume's name or id to the console, or to a variable specified via "-o".

Some example usage:

1. Output the default subvolume's name or path:
   btrfs-get-default-subvol -p ($root)
2. Output the default subvolume's ID or number:
   btrfs-get-default-subvol -n ($root)
3. Output the default subvolume's path to a variable "btrfs_prefix":
   btrfs-get-default-subvol -p -o btrfs_prefix ($root)

This is useful in a prebuilt image like `grub.xen`, which is built at a time
when the guest configuration cannot be determined. In such a setup, trying to
enable "btrfs_relative_path" in the load configuration may lead to problems if
the guest image did not enable btrfs snapshots in its configuration.

As a result, when attempting to locate grub.cfg in a guest, it may be necessary
to specify the default subvolume in advance where the grub.cfg resides. The
script would look like this:

  btrfs-get-default-subvol -p -o btrfs_prefix ($root)
  if [ -n "${btrfs_prefix}" ]; then
configfile "${btrfs_prefix}/boot/grub/grub.cfg"
  else
configfile "/boot/grub/grub.cfg"
  fi

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c | 238 +++
 1 file changed, 238 insertions(+)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index d47f9ab03..d93e9615a 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -2876,6 +2876,238 @@ out:
   return 0;
 }
 
+static grub_err_t
+grub_btrfs_get_parent_subvol_path (struct grub_btrfs_data *data,
+   grub_uint64_t child_id,
+   const char *child_path,
+   grub_uint64_t *parent_id,
+   char **path_out)
+{
+  grub_uint64_t fs_root = 0;
+  struct grub_btrfs_key key_in = {
+.object_id = child_id,
+.type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF,
+.offset = 0,
+  }, key_out;
+  struct grub_btrfs_root_ref *ref;
+  char *buf;
+  struct grub_btrfs_leaf_descriptor desc;
+  grub_size_t elemsize;
+  grub_disk_addr_t elemaddr;
+  grub_err_t err;
+  char *parent_path;
+
+  *parent_id = 0;
+  *path_out = 0;
+
+  err = lower_bound(data, &key_in, &key_out, data->sblock.root_tree,
+&elemaddr, &elemsize, &desc, 0);
+  if (err)
+return err;
+
+  if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF || elemaddr == 0)
+next(data, &desc, &elemaddr, &elemsize, &key_out);
+
+  if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF)
+{
+  free_iterator(&desc);
+  return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("can't find root 
backrefs"));
+}
+
+  buf = grub_malloc(elemsize + 1);
+  if (!buf)
+{
+  free_iterator(&desc);
+  return grub_errno;
+}
+
+  err = grub_btrfs_read_logical(data, elemaddr, buf, elemsize, 0);
+  if (err)
+{
+  grub_free(buf);
+  free_iterator(&desc);
+  return err;
+}
+
+  buf[elemsize] = 0;
+  ref = (struct grub_btrfs_root_ref *)buf;
+
+  err = get_fs_root(data, data->sblock.root_tree, grub_le_to_cpu64 
(key_out.offset),
+0, &fs_root);
+  if (err)
+{
+  grub_free(buf);
+  free_iterator(&desc);
+  return err;
+}
+
+  find_pathname(data, grub_le_to_cpu64 (ref->dirid), fs_root, ref->name, 
&parent_path);
+
+  if (child_path)
+{
+  *path_out = grub_xasprintf ("%s/%s", parent_path, child_path);
+  grub_free (parent_path);
+}
+  else
+*path_out = parent_path;
+
+  *parent_id = grub_le_to_cpu64 (key_out.offset);
+
+  grub_free(buf);
+  free_iterator(&desc);
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_btrfs_get_default_subvolume_id (struct grub_btrfs_data *data, 
grub_uint64_t *id)
+{
+  grub_err_t err;
+  grub_disk_addr_t elemaddr;
+  grub_size_t elemsize;
+  struct grub_btrfs_key key, key_out;
+  struct grub_btrfs_dir_item *direl = NULL;
+  const char *ctoken = "default";
+  grub_size_t ctokenlen = sizeof ("default") - 1;
+
+  *id = 0;
+  key.object_id = data->sblock.root_dir_objectid;
+  key.type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key.offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
+  err = lower_bound (data, &key, &key_out, data->sblock.root_tree, &elemaddr, 
&elemsize,
+NULL, 0);
+  if (err)
+return err;
+
+  if (key_cmp (&key, &key_out) != 0)
+return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found"));
+
+  struct grub_btrfs_dir_item *cdirel;
+  direl = grub_malloc (elemsize + 1);
+  err = grub_btrfs_read_logical (data, elemaddr, direl, elemsize, 0);
+  if (err)
+{
+  grub_free (direl);
+  return err;
+}
+  for (cdirel = direl;
+   (grub_uint8_t *) cdirel - (grub_uint8_t *) direl
+   < (grub_ssize_t) elemsize;
+   cdirel = (void *) ((grub_uint8_t *) (direl + 1)
+   + grub_le_to_cpu16 (cdirel->n)
+   + grub_le_to_cpu16 (cdirel->m)))
+{
+  if (ctokenlen == grub_le_to_cpu16 (cdirel->n)
+&& grub_memcmp (cdir

[PATCH v3 25/29] btrfs: Allow specifying btrfs_relative_path to follow the default subvolume

2024-10-14 Thread Leo Sandoval
From: Michael Chang 

This patch enables the use of a relative path to the btrfs default subvolume by
setting the environment variable btrfs_relative_path=[y1]. In contrast to using
an absolute path from the toplevel root, which always reads files consistently
from a fixed location, the relative path allows grub to follow changes in the
default subvolume, which might occur as a consequence of a rollback operation.

The btrfs_relative_path environment variable is available but not enabled by
default, so the default path remains aligned with the upstream definition. For
systems that do not require btrfs rollback or booting from snapshots, an
absolute path is preferred, as it makes path handling consistent with other
non-btrfs filesystems and allows file access throughout the filesystem
regardless of subvolumes, etc.

Signed-off-by: Michael Chang 
Signed-off-by: Robbie Harwood 
---
 grub-core/fs/btrfs.c | 107 ++-
 1 file changed, 76 insertions(+), 31 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 14e38a4df..d47f9ab03 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -1335,6 +1335,7 @@ grub_btrfs_mount (grub_device_t dev)
 {
   struct grub_btrfs_data *data;
   grub_err_t err;
+  const char *relpath = grub_env_get ("btrfs_relative_path");
 
   if (!dev->disk)
 {
@@ -1365,11 +1366,14 @@ grub_btrfs_mount (grub_device_t dev)
   data->devices_attached[0].dev = dev;
   data->devices_attached[0].id = data->sblock.this_device.device_id;
 
-  err = btrfs_handle_subvol (data);
-  if (err)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
 {
-  grub_free (data);
-  return NULL;
+  err = btrfs_handle_subvol (data);
+  if (err)
+  {
+grub_free (data);
+return NULL;
+  }
 }
 
   return data;
@@ -1966,24 +1970,39 @@ find_path (struct grub_btrfs_data *data,
   grub_size_t allocated = 0;
   struct grub_btrfs_dir_item *direl = NULL;
   struct grub_btrfs_key key_out;
+  int follow_default;
   const char *ctoken;
   grub_size_t ctokenlen;
   char *path_alloc = NULL;
   char *origpath = NULL;
   unsigned symlinks_max = 32;
+  const char *relpath = grub_env_get ("btrfs_relative_path");
 
+  follow_default = 0;
   origpath = grub_strdup (path);
   if (!origpath)
 return grub_errno;
 
-  if (data->fs_tree)
+  if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
 {
-  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
-  *tree = data->fs_tree;
-  /* This is a tree root, so everything starts at objectid 256 */
-  key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
-  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
-  key->offset = 0;
+  if (data->fs_tree)
+{
+  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+  *tree = data->fs_tree;
+  /* This is a tree root, so everything starts at objectid 256 */
+  key->object_id = grub_cpu_to_le64_compile_time 
(GRUB_BTRFS_OBJECT_ID_CHUNK);
+  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key->offset = 0;
+}
+  else
+{
+  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+  *tree = data->sblock.root_tree;
+  key->object_id = data->sblock.root_dir_objectid;
+  key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+  key->offset = 0;
+  follow_default = 1;
+}
 }
   else
 {
@@ -1994,15 +2013,23 @@ find_path (struct grub_btrfs_data *data,
 
   while (1)
 {
-  while (path[0] == '/')
-   path++;
-  if (!path[0])
-   break;
-  slash = grub_strchr (path, '/');
-  if (!slash)
-   slash = path + grub_strlen (path);
-  ctoken = path;
-  ctokenlen = slash - path;
+  if (!follow_default)
+   {
+ while (path[0] == '/')
+   path++;
+ if (!path[0])
+   break;
+ slash = grub_strchr (path, '/');
+ if (!slash)
+   slash = path + grub_strlen (path);
+ ctoken = path;
+ ctokenlen = slash - path;
+   }
+  else
+   {
+ ctoken = "default";
+ ctokenlen = sizeof ("default") - 1;
+   }
 
   if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
{
@@ -2013,7 +2040,9 @@ find_path (struct grub_btrfs_data *data,
 
   if (ctokenlen == 1 && ctoken[0] == '.')
{
- path = slash;
+ if (!follow_default)
+   path = slash;
+ follow_default = 0;
  continue;
}
   if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.')
@@ -2044,8 +2073,9 @@ find_path (struct grub_btrfs_data *data,
  *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
  key->object_id = key_out.offset;
 
- path = slash;
-
+ if (!follow_default)
+   path = slash;
+ follow_default = 0;
  continue;
}
 
@@ -2114,7 +2144,9 @@ find_path (struct grub_btrfs_data *data,
  return err;
  

[PATCH v3 28/29] efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.

2024-10-14 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 include/grub/efi/efi.h | 36 
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index a5cd99e5a..8d98203a7 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -36,6 +36,10 @@ struct linux_arch_kernel_header {
   struct grub_pe_image_header pe_image_header;
 };
 
+/* Variables.  */
+extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
+extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
+
 /* Functions.  */
 void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
 void *registration);
@@ -71,6 +75,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t 
*memory_map_size,
  grub_efi_uintn_t *descriptor_size,
  grub_efi_uint32_t *descriptor_version);
 void grub_efi_memory_fini (void);
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_allocate_pool (grub_efi_memory_type_t pool_type,
+   grub_efi_uintn_t buffer_size,
+   void **buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->allocate_pool(pool_type, buffer_size, buffer);
+  return status;
+}
+
+static inline grub_efi_status_t
+__attribute__((__unused__))
+grub_efi_free_pool (void *buffer)
+{
+  grub_efi_boot_services_t *b;
+  grub_efi_status_t status;
+
+  b = grub_efi_system_table->boot_services;
+  status = b->free_pool(buffer);
+  return status;
+}
+
 grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) 
(grub_efi_handle_t image_handle);
 void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);
 char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
@@ -140,10 +171,7 @@ void grub_efi_init (void);
 void grub_efi_fini (void);
 void grub_efi_set_prefix (void);
 
-/* Variables.  */
-extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
-extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
-
+/* More variables.  */
 extern int EXPORT_VAR(grub_efi_is_finished);
 
 struct grub_net_card;
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v1 11/15] grub-install: disable support for EFI platforms

2024-11-04 Thread Leo Sandoval
On Sun, Nov 3, 2024 at 7:08 PM Neal Gompa  wrote:
>
> On Thu, Oct 31, 2024 at 3:43 PM Leo Sandoval  wrote:
> >
> > From: Jan Hlavac 
> >
> > For each platform, GRUB is shipped as a kernel image and a set of
> > modules. These files are then used by the grub-install utility to
> > install GRUB on a specific device. However, in order to support UEFI
> > Secure Boot, the resulting EFI binary must be signed by a recognized
> > private key. For this reason, for EFI platforms, most distributions also
> > ship prebuilt EFI binaries signed by a distribution-specific private
> > key. In this case, however, the grub-install utility should not be used
> > because it would overwrite the signed EFI binary.
> >
> > The current fix is suboptimal because it preserves all EFI-related code.
> > A better solution could be to modularize the code and provide a
> > build-time option.
> >
> > Resolves: rhbz#1737444
> >
> > Signed-off-by: Jan Hlavac 
> > [rharwood: drop man page]
> > ---
> >  docs/grub.texi  |  7 +++
> >  util/grub-install.c | 41 +++--
> >  2 files changed, 26 insertions(+), 22 deletions(-)
> >
> > diff --git a/docs/grub.texi b/docs/grub.texi
> > index a225f9a88..bc9791794 100644
> > --- a/docs/grub.texi
> > +++ b/docs/grub.texi
> > @@ -7080,6 +7080,13 @@ grub-install @var{install_device}
> >  The device name @var{install_device} is an OS device name or a GRUB
> >  device name.
> >
> > +In order to support UEFI Secure Boot, the resulting GRUB EFI binary
must
> > +be signed by a recognized private key. For this reason, for EFI
> > +platforms, most distributions also ship prebuilt GRUB EFI binaries
> > +signed by a distribution-specific private key. In this case, however,
> > +@command{grub2-install} should not be used because it would overwrite
> > +the signed EFI binary.
> > +
> >  @command{grub-install} accepts the following options:
> >
> >  @table @option
> > diff --git a/util/grub-install.c b/util/grub-install.c
> > index c245d9359..ee61b042b 100644
> > --- a/util/grub-install.c
> > +++ b/util/grub-install.c
> > @@ -910,6 +910,25 @@ main (int argc, char *argv[])
> >
> >platform = grub_install_get_target (grub_install_source_directory);
> >
> > +  switch (platform)
> > +{
> > +case GRUB_INSTALL_PLATFORM_ARM_EFI:
> > +case GRUB_INSTALL_PLATFORM_ARM64_EFI:
> > +case GRUB_INSTALL_PLATFORM_I386_EFI:
> > +case GRUB_INSTALL_PLATFORM_IA64_EFI:
> > +case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
> > +case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
> > +case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
> > +case GRUB_INSTALL_PLATFORM_X86_64_EFI:
> > +  is_efi = 1;
> > +  grub_util_error (_("this utility cannot be used for EFI
platforms"
> > + " because it does not support UEFI Secure
Boot"));
> > +  break;
> > +default:
> > +  is_efi = 0;
> > +  break;
> > +}
> > +
> >{
> >  char *platname = grub_install_get_platform_name (platform);
> >  fprintf (stderr, _("Installing for %s platform.\n"), platname);
> > @@ -1024,27 +1043,6 @@ main (int argc, char *argv[])
> >grub_hostfs_init ();
> >grub_host_init ();
> >
> > -  switch (platform)
> > -{
> > -case GRUB_INSTALL_PLATFORM_I386_EFI:
> > -case GRUB_INSTALL_PLATFORM_X86_64_EFI:
> > -case GRUB_INSTALL_PLATFORM_ARM_EFI:
> > -case GRUB_INSTALL_PLATFORM_ARM64_EFI:
> > -case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
> > -case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
> > -case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
> > -case GRUB_INSTALL_PLATFORM_IA64_EFI:
> > -  is_efi = 1;
> > -  break;
> > -default:
> > -  is_efi = 0;
> > -  break;
> > -
> > -  /* pacify warning.  */
> > -case GRUB_INSTALL_PLATFORM_MAX:
> > -  break;
> > -}
> > -
> >switch (platform)
> >  {
> >  case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
> > @@ -1060,7 +1058,6 @@ main (int argc, char *argv[])
> >  }
> >
> >/* Find the EFI System Partition.  */
> > -
> >if (is_efi)
> >  {
> >grub_fs_t fs;
> > --
> > 2.46.2
>
> This patch should not be upstreamed as-is, since it completely breaks
> the ability to generate grub-efi binaries on the system with the
> assumption that pre-existing ones hav

Re: [PATCH v1 14/15] grub-install: install on EFI if forced

2024-11-04 Thread Leo Sandoval
On Sun, Nov 3, 2024 at 7:09 PM Neal Gompa  wrote:

> On Thu, Oct 31, 2024 at 3:43 PM Leo Sandoval  wrote:
> >
> > From: Marta Lewandowska 
> >
> > UEFI Secure Boot requires signed grub binaries to work, so grub-
> > install should not be used. However, users who have Secure Boot
> > disabled and wish to use the command should not be prevented from
> > doing so if they invoke --force.
> >
> > fixes bz#1917213 / bz#2240994
> >
> > Signed-off-by: Marta Lewandowska 
> > ---
> >  util/grub-install.c | 38 +++---
> >  1 file changed, 19 insertions(+), 19 deletions(-)
> >
> > diff --git a/util/grub-install.c b/util/grub-install.c
> > index ee61b042b..b924c2d34 100644
> > --- a/util/grub-install.c
> > +++ b/util/grub-install.c
> > @@ -910,25 +910,6 @@ main (int argc, char *argv[])
> >
> >platform = grub_install_get_target (grub_install_source_directory);
> >
> > -  switch (platform)
> > -{
> > -case GRUB_INSTALL_PLATFORM_ARM_EFI:
> > -case GRUB_INSTALL_PLATFORM_ARM64_EFI:
> > -case GRUB_INSTALL_PLATFORM_I386_EFI:
> > -case GRUB_INSTALL_PLATFORM_IA64_EFI:
> > -case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
> > -case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
> > -case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
> > -case GRUB_INSTALL_PLATFORM_X86_64_EFI:
> > -  is_efi = 1;
> > -  grub_util_error (_("this utility cannot be used for EFI platforms"
> > - " because it does not support UEFI Secure
> Boot"));
> > -  break;
> > -default:
> > -  is_efi = 0;
> > -  break;
> > -}
> > -
> >{
> >  char *platname = grub_install_get_platform_name (platform);
> >  fprintf (stderr, _("Installing for %s platform.\n"), platname);
> > @@ -1045,6 +1026,22 @@ main (int argc, char *argv[])
> >
> >switch (platform)
> >  {
> > +case GRUB_INSTALL_PLATFORM_ARM_EFI:
> > +case GRUB_INSTALL_PLATFORM_ARM64_EFI:
> > +case GRUB_INSTALL_PLATFORM_I386_EFI:
> > +case GRUB_INSTALL_PLATFORM_IA64_EFI:
> > +case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
> > +case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
> > +case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
> > +case GRUB_INSTALL_PLATFORM_X86_64_EFI:
> > +  is_efi = 1;
> > +  if (!force)
> > +grub_util_error (_("This utility should not be used for EFI
> platforms"
> > +  " because it does not support UEFI Secure
> Boot."
> > +  " If you really wish to proceed, invoke the
> --force"
> > +  " option.\nMake sure Secure Boot is disabled
> before"
> > +  " proceeding"));
> > +  break;
> >  case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
> >  case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
> >  #ifdef __linux__
> > @@ -1053,6 +1050,9 @@ main (int argc, char *argv[])
> >  try_open ("/dev/nvram");
> >  #endif
> >break;
> > +  /* pacify warning.  */
> > +case GRUB_INSTALL_PLATFORM_MAX:
> > +  break;
> >  default:
> >break;
> >  }
> > --
> > 2.46.2
> >
>
> This should be merged with the patch that breaks grub-install for EFI
> and re-sent as one *new* patch. It's not okay to break it and then fix
> it in the same patch series, since we don't want broken functionality
> in a commit applied to git.
>

Partially agree with you and also thought about it, however this is a new
feature  where a new parameter is included, so at the end I decided to
leave both and keep the authorship. Based on the above, I will also drop
this one from the series and the reason is that this patch is based on a
previous patch that is broken.


>
>
>
> --
> 真実はいつも一つ!/ Always, there's only one truth!
>
> ___
> 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


Re: [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide

2024-10-30 Thread Leo Sandoval
Hi Daniel,

Thanks for your feedback, comment inline.

On Wed, Oct 30, 2024 at 10:40 AM Daniel Kiper  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
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 15/15] 25_bli.in 30_uefi_firmware.in: load EFI commands inside test expressions

2024-10-31 Thread Leo Sandoval
These two commands may fail interrumping the normal boot process,
so placing these inside test expressions is a safer approach.

Resolves: #2305291
Suggested-by: Kan-Ru Chen: 
Signed-off-by: Leo Sandoval 
---
 util/grub.d/25_bli.in   | 4 +++-
 util/grub.d/30_uefi-firmware.in | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/util/grub.d/25_bli.in b/util/grub.d/25_bli.in
index 26e27a019..00a8d7159 100644
--- a/util/grub.d/25_bli.in
+++ b/util/grub.d/25_bli.in
@@ -19,6 +19,8 @@ set -e
 
 cat << EOF
 if [ "\$grub_platform" = "efi" ]; then
-  insmod bli
+if [ ! insmod bli ]; then
+echo "bli module not available"
+fi
 fi
 EOF
diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in
index 1c2365ddb..1ef31e08f 100644
--- a/util/grub.d/30_uefi-firmware.in
+++ b/util/grub.d/30_uefi-firmware.in
@@ -32,8 +32,7 @@ gettext_printf "Adding boot menu entry for UEFI Firmware 
Settings ...\n" >&2
 
 cat << EOF
 if [ "\$grub_platform" = "efi" ]; then
-   fwsetup --is-supported
-   if [ "\$?" = 0 ]; then
+   if [ fwsetup --is-supported ]; then
menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
fwsetup
}
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 0/5] Fedora Rawhide BTRFS patches

2024-10-31 Thread Leo Sandoval
This series contains BTRFS patches taken from Fedora Rawhide [1]. Some of
these patches have already being sent [2][3] however, as suggested
by Daniel Kiper, to make the review easier, I took only BTRFS related patches
from [1][2][3] and create the series.

[1] https://src.fedoraproject.org/rpms/grub2
[2] https://lists.gnu.org/archive/html/grub-devel/2024-10/msg00145.html
[3] https://lists.gnu.org/archive/html/grub-devel/2024-10/msg00192.html

Jeff Mahoney (1):
  btrfs: Add ability to boot from subvolumes

Michael Chang (2):
  btrfs: export btrfs_subvol and btrfs_subvolid
  btrfs: Allow specifying btrfs_relative_path to follow the default
subvolume

Peter Jones (2):
  btrfs: fix a bad null check
  btrfs: Fixup for newer compiler

 grub-core/fs/btrfs.c | 629 ---
 include/grub/btrfs.h |   1 +
 2 files changed, 595 insertions(+), 35 deletions(-)

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 14/15] grub-install: install on EFI if forced

2024-10-31 Thread Leo Sandoval
From: Marta Lewandowska 

UEFI Secure Boot requires signed grub binaries to work, so grub-
install should not be used. However, users who have Secure Boot
disabled and wish to use the command should not be prevented from
doing so if they invoke --force.

fixes bz#1917213 / bz#2240994

Signed-off-by: Marta Lewandowska 
---
 util/grub-install.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/util/grub-install.c b/util/grub-install.c
index ee61b042b..b924c2d34 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -910,25 +910,6 @@ main (int argc, char *argv[])
 
   platform = grub_install_get_target (grub_install_source_directory);
 
-  switch (platform)
-{
-case GRUB_INSTALL_PLATFORM_ARM_EFI:
-case GRUB_INSTALL_PLATFORM_ARM64_EFI:
-case GRUB_INSTALL_PLATFORM_I386_EFI:
-case GRUB_INSTALL_PLATFORM_IA64_EFI:
-case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
-case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
-case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
-case GRUB_INSTALL_PLATFORM_X86_64_EFI:
-  is_efi = 1;
-  grub_util_error (_("this utility cannot be used for EFI platforms"
- " because it does not support UEFI Secure Boot"));
-  break;
-default:
-  is_efi = 0;
-  break;
-}
-
   {
 char *platname = grub_install_get_platform_name (platform);
 fprintf (stderr, _("Installing for %s platform.\n"), platname);
@@ -1045,6 +1026,22 @@ main (int argc, char *argv[])
 
   switch (platform)
 {
+case GRUB_INSTALL_PLATFORM_ARM_EFI:
+case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+case GRUB_INSTALL_PLATFORM_I386_EFI:
+case GRUB_INSTALL_PLATFORM_IA64_EFI:
+case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+  is_efi = 1;
+  if (!force)
+grub_util_error (_("This utility should not be used for EFI platforms"
+  " because it does not support UEFI Secure Boot."
+  " If you really wish to proceed, invoke the --force"
+  " option.\nMake sure Secure Boot is disabled before"
+  " proceeding"));
+  break;
 case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
 case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
 #ifdef __linux__
@@ -1053,6 +1050,9 @@ main (int argc, char *argv[])
 try_open ("/dev/nvram");
 #endif
   break;
+  /* pacify warning.  */
+case GRUB_INSTALL_PLATFORM_MAX:
+  break;
 default:
   break;
 }
-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 00/15] Fedora Rawhide (non-network) EFI patches

2024-10-31 Thread Leo Sandoval
This series contains non-network related EFI patches taken from Fedora Rawhide 
[1]. Some
of these patches have already being sent [2][3] however, as suggested by Daniel 
Kiper,
to make the review easier, I took only EFI related patches (ignoring those
related to networking) from [1][2][3] and create the series. Network EFI 
related patches
will be sent separately.

[1] https://src.fedoraproject.org/rpms/grub2
[2] https://lists.gnu.org/archive/html/grub-devel/2024-10/msg00145.html
[3] https://lists.gnu.org/archive/html/grub-devel/2024-10/msg00192.html

Jan Hlavac (1):
  grub-install: disable support for EFI platforms

Leo Sandoval (1):
  25_bli.in 30_uefi_firmware.in: load EFI commands inside test
expressions

Marta Lewandowska (1):
  grub-install: install on EFI if forced

Peter Jones (11):
  misc: Make "exit" take a return code.
  efi/init: Make efi machines load an env block from a variable
  efi: Add grub_efi_allocate_pool() and grub_efi_free_pool() wrappers.
  chainloader: Use grub_efi_...() memory helpers where reasonable.
  efi/api: Add PRIxGRUB_EFI_STATUS and use it.
  efi: don't use int for efi status
  grub-install: Don't guess /boot/efi/ as HFS+ on ppc machines in
grub-install
  misc: align struct efi_variable better...
  console: Work around some minor include path weirdnesses
  env: Add efi-export-env and efi-load-env commands
  nx: set the nx compatible flag in EFI grub images

Renaud Métrich (1):
  connectefi: new 'connectefi' command

 NEWS |   2 +-
 docs/grub.texi   |   7 +
 grub-core/Makefile.core.def  |  13 ++
 grub-core/commands/efi/connectefi.c  | 205 +++
 grub-core/commands/efi/env.c | 170 ++
 grub-core/commands/efi/lsefi.c   |   1 +
 grub-core/commands/minicmd.c |  20 ++-
 grub-core/disk/efi/efidisk.c |  13 ++
 grub-core/kern/efi/efi.c |  25 +++-
 grub-core/kern/efi/init.c|  29 
 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 +-
 grub-core/lib/envblk.c   |  43 ++
 grub-core/loader/efi/chainloader.c   |   4 +-
 include/grub/arm/efi/console.h   |  24 
 include/grub/arm64/efi/console.h |  24 
 include/grub/efi/api.h   |   9 ++
 include/grub/efi/disk.h  |   2 +
 include/grub/efi/efi.h   |  46 +-
 include/grub/efi/pe32.h  |   2 +
 include/grub/efiemu/runtime.h|   2 +-
 include/grub/i386/efi/console.h  |  24 
 include/grub/lib/envblk.h|   3 +
 include/grub/misc.h  |   2 +-
 include/grub/types.h |   1 +
 include/grub/x86_64/efi/console.h|  24 
 util/grub-install.c  |  39 ++---
 util/grub.d/25_bli.in|   4 +-
 util/grub.d/30_uefi-firmware.in  |   3 +-
 util/mkimage.c   |   1 +
 39 files changed, 724 insertions(+), 60 deletions(-)
 create mode 100644 grub-core/commands/efi/connectefi.c
 create mode 100644 grub-core/commands/efi/env.c
 create mode 100644 include/grub/arm/efi/console.h
 create mode 100644 include/grub/arm64/efi/console.h
 create mode 100644 include/grub/i386/efi/console.h
 create mode 100644 include/grub/x86_64/efi/console.h

-- 
2.46.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v1 09/15] console: Work around some minor include path weirdnesses

2024-10-31 Thread Leo Sandoval
From: Peter Jones 

Signed-off-by: Peter Jones 
---
 include/grub/arm/efi/console.h| 24 
 include/grub/arm64/efi/console.h  | 24 
 include/grub/i386/efi/console.h   | 24 
 include/grub/x86_64/efi/console.h | 24 
 4 files changed, 96 insertions(+)
 create mode 100644 include/grub/arm/efi/console.h
 create mode 100644 include/grub/arm64/efi/console.h
 create mode 100644 include/grub/i386/efi/console.h
 create mode 100644 include/grub/x86_64/efi/console.h

diff --git a/include/grub/arm/efi/console.h b/include/grub/arm/efi/console.h
new file mode 100644
index 0..1592f6f76
--- /dev/null
+++ b/include/grub/arm/efi/console.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  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 .
+ */
+
+#ifndef GRUB_ARM_EFI_CONSOLE_H
+#define GRUB_ARM_EFI_CONSOLE_H
+
+#include 
+
+#endif /* ! GRUB_ARM_EFI_CONSOLE_H */
diff --git a/include/grub/arm64/efi/console.h b/include/grub/arm64/efi/console.h
new file mode 100644
index 0..956893393
--- /dev/null
+++ b/include/grub/arm64/efi/console.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  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 .
+ */
+
+#ifndef GRUB_ARM64_EFI_CONSOLE_H
+#define GRUB_ARM64_EFI_CONSOLE_H
+
+#include 
+
+#endif /* ! GRUB_ARM64_EFI_CONSOLE_H */
diff --git a/include/grub/i386/efi/console.h b/include/grub/i386/efi/console.h
new file mode 100644
index 0..9231375cb
--- /dev/null
+++ b/include/grub/i386/efi/console.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  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 .
+ */
+
+#ifndef GRUB_I386_EFI_CONSOLE_H
+#define GRUB_I386_EFI_CONSOLE_H
+
+#include 
+
+#endif /* ! GRUB_I386_EFI_CONSOLE_H */
diff --git a/include/grub/x86_64/efi/console.h 
b/include/grub/x86_64/efi/console.h
new file mode 100644
index 0..dba9d8678
--- /dev/null
+++ b/include/grub/x86_64/efi/console.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2002,2005,2006,2007  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 .
+ */
+
+#ifndef GRUB_X86_64_EFI_CONSOLE_H
+#define GRUB_X86_64_EFI_CONSOLE_H
+
+#include 
+
+#endif /* ! GRUB_X86_64_EFI_CONSOLE_H */
-- 
2.46.2


___
Grub-devel mailing 

  1   2   >