Skip to contentSkip to conversation

First Distro-agnostic series taken from Fedora Rawhide

PATCH Superseded Leo Sandoval 4 participants 33 messages Sep 30, 2024 – Oct 2, 2024 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover First Distro-agnostic series taken from Fedora Rawhide

This is the first patch series taken from Fedora Rawhide spec [1] that are distro-agnostic. The goal is to merge most them so all the community/distros would benefit.

[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 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 (13):
configure.ac: Move bash completion script
normal/menu: Allow "fallback" to include entries by title, not just
number.
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.
blscfg: add blscfg module to parse Boot Loader Specification snippets 10_linux.in: Add devicetree loading
00_header.in: Enable pager by default. (#985860) 10_linux.in 20_linux_xen.in: Don't say "GNU/Linux" in generated menus. 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          |   12 +
 grub-core/commands/blscfg.c          | 1177 ++++++++++++++++++++++++++
 grub-core/commands/legacycfg.c       |    5 +-
 grub-core/commands/loadenv.c         |   77 +-
 grub-core/commands/loadenv.h         |   93 ++
 grub-core/commands/menuentry.c       |   20 +-
 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              |  130 ++-
 grub-core/normal/menu.c              |   85 +-
 grub-core/script/execute.c           |   50 +-
 grub-core/term/terminfo.c            |    2 +-
 grub-core/video/ieee1275.c           |    9 +-
 include/grub/compiler.h              |    2 +
 include/grub/ieee1275/ieee1275.h     |    4 +
 include/grub/menu.h                  |   13 +
 include/grub/misc.h                  |    2 +-
 include/grub/normal.h                |    2 +-
 tests/util/grub-shell-tester.in      |    2 +-
 tests/util/grub-shell.in             |    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              |   22 +-
 util/grub.d/20_linux_xen.in          |    4 +-
 util/grub.d/20_ppc_terminfo.in       |  114 +++
 47 files changed, 1894 insertions(+), 216 deletions(-)
 create mode 100644 grub-core/commands/blscfg.c
 create mode 100644 grub-core/commands/loadenv.h
 create mode 100644 util/grub.d/20_ppc_terminfo.in
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH 1/20 ieee1275/openfw: IBM client architecture (CAS) reboot support

From: Paulo Flabiano Smorigo <[email protected]>

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

---
 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(+)
grub-core/kern/ieee1275/openfw.c +63 -0
index 11b2beb2f..e2ecc65d2 100644
@@ -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;
+}
grub-core/normal/main.c +19 -0
index bd4431000..d3f53d93d 100644
@@ -34,6 +34,9 @@
 #include <grub/charset.h>
 #include <grub/script_sh.h>
 #include <grub/bufio.h>
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/ieee1275.h>
+#endif
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -276,6 +279,22 @@ grub_normal_execute (const char *config, int nested, int batch)
     {
       menu = read_config_file (config);
 
+#ifdef GRUB_MACHINE_IEEE1275
+      int boot;
+      boot = 0;
+      char *script;
+      script = grub_malloc (1024);
+      if (! grub_ieee1275_cas_reboot (script))
+        {
+          char *dummy[1] = { NULL };
+          if (! grub_script_execute_sourcecode (script))
+            boot = 1;
+        }
+      grub_free (script);
+      if (boot)
+        grub_command_execute ("boot", 0, 0);
+#endif
+
       /* Ignore any error.  */
       grub_errno = GRUB_ERR_NONE;
     }
grub-core/script/execute.c +7 -0
index 14ff09094..dab8fd2ae 100644
@@ -28,6 +28,9 @@
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
 #include <grub/verify.h>
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/ieee1275.h>
+#endif
 
 /* Max digits for a char is 3 (0xFF is 255), similarly for an int it
    is sizeof (int) * 3, and one extra for a possible -ve sign.  */
@@ -883,6 +886,10 @@ grub_script_execute_sourcecode (const char *source)
   grub_err_t ret = 0;
   struct grub_script *parsed_script;
 
+#ifdef GRUB_MACHINE_IEEE1275
+  grub_ieee1275_set_boot_last_label (source);
+#endif
+
   while (source)
     {
       char *line;
include/grub/ieee1275/ieee1275.h +2 -0
index dddb38514..4f6e6aaa0 100644
@@ -251,6 +251,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali
 void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
 void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
 						struct grub_ieee1275_devalias *alias);
+int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
+int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
 
 char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);
 
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH 2/20 term/terminfo: for ppc, reset console display attr when clear screen

In reply to Leo Sandoval

From: Paulo Flabiano Smorigo <[email protected]>

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

---
 grub-core/term/terminfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/term/terminfo.c +1 -1
index 4e534c683..3dbe88e89 100644
@@ -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)
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw

PATCH 3/20 ieee1275: Disable GRUB video support for IBM power machines

In reply to Leo Sandoval

From: Paulo Flabiano Smorigo <[email protected]>

Should fix the problem in bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=973205

---
 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(-)
grub-core/kern/ieee1275/cmain.c +4 -1
index e74de3248..810a089a9 100644
@@ -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
grub-core/video/ieee1275.c +6 -3
index ca3d3c3b2..5592e4bb7 100644
@@ -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)
include/grub/ieee1275/ieee1275.h +2 -0
index 4f6e6aaa0..db0ec5f4c 100644
@@ -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);
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw

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

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

Quoted 73 lines · Leo Sandoval

From: Paulo Flabiano Smorigo <[email protected]>

Should fix the problem in bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=973205

---
 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(-)
grub-core/kern/ieee1275/cmain.c +4 -1
index e74de3248..810a089a9 100644
@@ -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

grub-core/video/ieee1275.c +0 -0
index ca3d3c3b2..5592e4bb7 100644
@@ -351,9 +351,12 @@ static struct grub_video_adapter

grub_video_ieee1275_adapter =

GRUB_MOD_INIT(ieee1275_fb)
{

grub-core/video/ieee1275.c +1 -3
-  find_display ();
-  if (display)
-    grub_video_register (&grub_video_ieee1275_adapter);
+  if (! grub_ieee1275_test_flag

(GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT))

grub-core/video/ieee1275.c +5 -0
+    {
+      find_display ();
+      if (display)
+        grub_video_register (&grub_video_ieee1275_adapter);
+    }
 }
 
 GRUB_MOD_FINI(ieee1275_fb)
include/grub/ieee1275/ieee1275.h +2 -0
index 4f6e6aaa0..db0ec5f4c 100644
@@ -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

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

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

Quoted 3 lines · Vladimir 'phcoder' Serbinenko

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

Agree. Let me include it in v2.

Quoted 76 lines · Leo Sandoval
Quoted 74 lines

From: Paulo Flabiano Smorigo <[email protected]>

Should fix the problem in bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=973205

---
 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(-)
grub-core/kern/ieee1275/cmain.c +4 -1
index e74de3248..810a089a9 100644
@@ -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

grub-core/video/ieee1275.c +0 -0
index ca3d3c3b2..5592e4bb7 100644
@@ -351,9 +351,12 @@ static struct grub_video_adapter

grub_video_ieee1275_adapter =

GRUB_MOD_INIT(ieee1275_fb)
{

grub-core/video/ieee1275.c +1 -3
-  find_display ();
-  if (display)
-    grub_video_register (&grub_video_ieee1275_adapter);
+  if (! grub_ieee1275_test_flag

(GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT))

grub-core/video/ieee1275.c +5 -0
+    {
+      find_display ();
+      if (display)
+        grub_video_register (&grub_video_ieee1275_adapter);
+    }
 }
 
 GRUB_MOD_FINI(ieee1275_fb)
include/grub/ieee1275/ieee1275.h +2 -0
index 4f6e6aaa0..db0ec5f4c 100644
@@ -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

Quoted 10 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw

PATCH 4/20 configure.ac: Move bash completion script

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

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(-)
configure.ac +11 -0
index cd667a2eb..ae3a49321 100644
@@ -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"
util/bash-completion.d/Makefile.am +0 -1
index 136287cf1..61108f054 100644
@@ -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
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#7 lore raw

PATCH 5/20 normal/menu: Allow "fallback" to include entries by title, not just number.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1026084

---
 grub-core/normal/menu.c | 85 ++++++++++++++++++++++++++++-------------
 1 file changed, 58 insertions(+), 27 deletions(-)
grub-core/normal/menu.c +58 -27
index 6a90e091f..6444ee6f9 100644
@@ -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)
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#8 lore raw

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

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

Quoted 145 lines · Leo Sandoval

From: Peter Jones <[email protected]>

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1026084

---
 grub-core/normal/menu.c | 85 ++++++++++++++++++++++++++++-------------
 1 file changed, 58 insertions(+), 27 deletions(-)
grub-core/normal/menu.c +24 -0
index 6a90e091f..6444ee6f9 100644
@@ -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

grub-core/normal/menu.c +34 -3
-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 ();
grub-core/normal/menu.c +0 -24
@@ -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

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#9 lore raw

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

Quoted 5 lines · Vladimir 'phcoder' Serbinenko

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?

Quoted 148 lines · Leo Sandoval
Quoted 147 lines

From: Peter Jones <[email protected]>

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1026084

---
 grub-core/normal/menu.c | 85 ++++++++++++++++++++++++++++-------------
 1 file changed, 58 insertions(+), 27 deletions(-)
grub-core/normal/menu.c +24 -0
index 6a90e091f..6444ee6f9 100644
@@ -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

grub-core/normal/menu.c +34 -3
-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 ();
grub-core/normal/menu.c +0 -24
@@ -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

Quoted 10 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw

PATCH 6/20 misc: Make "exit" take a return code.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

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.

---
 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(-)
grub-core/commands/minicmd.c +16 -4
index fa498931e..2bd3ac76f 100644
@@ -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.  */
 }
 
grub-core/kern/efi/efi.c +7 -2
index b93ae3aba..885d7c642 100644
@@ -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 (;;) ;
 }
 
grub-core/kern/emu/main.c +1 -1
index 855b11c3d..38c1576a2 100644
@@ -67,7 +67,7 @@ grub_reboot (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int retval __attribute__((unused)))
 {
   grub_reboot ();
 }
grub-core/kern/emu/misc.c +5 -4
index 521220b49..16c79bc94 100644
@@ -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
 
grub-core/kern/i386/coreboot/init.c +1 -1
index 4fae8b571..feaf9295e 100644
@@ -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().  */
grub-core/kern/i386/qemu/init.c +1 -1
index 08f81d25e..604fc94b5 100644
@@ -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().  */
grub-core/kern/ieee1275/init.c +1 -1
index fb7d1a3ba..50c65b2f6 100644
@@ -114,7 +114,7 @@ grub_addr_t grub_ieee1275_original_stack;
 #define BYTE22              (DY_MEM_V2 | DRC_INFO)
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   grub_ieee1275_exit ();
 }
grub-core/kern/mips/arc/init.c +1 -1
index 2ed3ff319..5c40c3407 100644
@@ -276,7 +276,7 @@ grub_halt (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   GRUB_ARC_FIRMWARE_VECTOR->exit ();
 
grub-core/kern/mips/loongson/init.c +1 -1
index 5bd721260..97b09b0ee 100644
@@ -304,7 +304,7 @@ grub_halt (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   grub_halt ();
 }
grub-core/kern/mips/qemu_mips/init.c +1 -1
index b5477b87f..69488a34e 100644
@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused)))
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   grub_halt ();
 }
grub-core/kern/misc.c +10 -1
index 7cee5d75c..11037dc02 100644
@@ -1311,9 +1311,18 @@ grub_abort (void)
       grub_getkey ();
     }
 
-  grub_exit ();
+  grub_exit (1);
 }
 
+#if defined (__clang__) && !defined (GRUB_UTIL)
+/* clang emits references to abort().  */
+void __attribute__ ((noreturn))
+abort (void)
+{
+  grub_abort ();
+}
+#endif
+
 void
 grub_fatal (const char *fmt, ...)
 {
grub-core/kern/uboot/init.c +3 -3
index 3e338645c..be2a5be1d 100644
@@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size;
 static unsigned long timer_start;
 
 void
-grub_exit (void)
+grub_exit (int rc)
 {
-  grub_uboot_return (0);
+  grub_uboot_return (rc < 0 ? 1 : rc);
 }
 
 static grub_uint64_t
@@ -78,7 +78,7 @@ grub_machine_init (void)
   if (!ver)
     {
       /* Don't even have a console to log errors to... */
-      grub_exit ();
+      grub_exit (-1);
     }
   else if (ver > API_SIG_VERSION)
     {
grub-core/kern/xen/init.c +1 -1
index 782ca7295..708b060f3 100644
@@ -584,7 +584,7 @@ grub_machine_init (void)
 }
 
 void
-grub_exit (void)
+grub_exit (int rc __attribute__((unused)))
 {
   struct sched_shutdown arg;
 
include/grub/misc.h +1 -1
index 1b35a167f..72aff1575 100644
@@ -385,7 +385,7 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
      __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
 char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
 
-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
+void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn));
 void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
 					  grub_uint64_t d,
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#11 lore raw

PATCH 7/20 efi/init: Make efi machines load an env block from a variable

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 grub-core/Makefile.core.def |  1 +
 grub-core/kern/efi/init.c   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
grub-core/Makefile.core.def +1 -0
index 1571421d7..0bffbfea9 100644
@@ -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;
grub-core/kern/efi/init.c +34 -0
index 6c54af6e7..b5201974a 100644
@@ -28,8 +28,11 @@
 #include <grub/env.h>
 #include <grub/mm.h>
 #include <grub/kernel.h>
+
 #include <grub/stack_protector.h>
 
+#include <grub/lib/envblk.h>
+
 #ifdef GRUB_STACK_PROTECTOR
 
 static grub_efi_char16_t stack_chk_fail_msg[] =
@@ -103,6 +106,36 @@ stack_protector_init (void)
 
 grub_addr_t grub_modbase;
 
+#define GRUB_EFI_GRUB_VARIABLE_GUID \
+  { 0x91376aff, 0xcba6, 0x42be, \
+    { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \
+  }
+
+/* Helper for grub_efi_env_init */
+static int
+set_var (const char *name, const char *value,
+	 void *whitelist __attribute__((__unused__)))
+{
+  grub_env_set (name, value);
+  return 0;
+}
+
+static void
+grub_efi_env_init (void)
+{
+  grub_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID;
+  struct grub_envblk envblk_s = { NULL, 0 };
+  grub_envblk_t envblk = &envblk_s;
+
+  grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, &envblk_s.size,
+                         (void **) &envblk_s.buf);
+  if (!envblk_s.buf || envblk_s.size < 1)
+    return;
+
+  grub_envblk_iterate (envblk, NULL, set_var);
+  grub_free (envblk_s.buf);
+}
+
 __attribute__ ((__optimize__ ("-fno-stack-protector"))) void
 grub_efi_init (void)
 {
@@ -128,6 +161,7 @@ grub_efi_init (void)
 
   grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL);
 
+  grub_efi_env_init ();
   grub_efidisk_init ();
 
   grub_efi_register_debug_commands ();
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#12 lore raw

PATCH 8/20 20_ppc_terminfo.in: Migrate PPC from Yaboot to Grub2

In reply to Leo Sandoval

From: Mark Hamzy <[email protected]>

Add configuration support for serial terminal consoles. This will set the maximum screen size so that text is not overwritten.

---
 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
Makefile.util.def +7 -0
index 9432365a9..09bfcadd9 100644
@@ -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;
util/grub.d/20_ppc_terminfo.in new file +114 -0

114 lines not on this page · raw message

Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#13 lore raw

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

Why is it ppc-specific?

Quoted 157 lines · Leo Sandoval

From: Mark Hamzy <[email protected]>

Add configuration support for serial terminal consoles. This will set the maximum screen size so that text is not overwritten.

---
 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
Makefile.util.def +7 -0
index 9432365a9..09bfcadd9 100644
@@ -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;
util/grub.d/ renamed from util/grub.d/20_ppc_terminfo.in +0 -0

20_ppc_terminfo.in
new file mode 100644
index 000000000..10d665868

util/grub.d/20_ppc_terminfo.in new file +105 -0
@@ -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."

util/grub.d/20_ppc_terminfo.in new file +9 -1
+    exit 1
+  fi
+
+  check_terminfo ${GRUB_TERMINFO}
+fi
+
+cat << EOF
+  terminfo -g ${X}x${Y} ${TERMINAL}
+EOF
--

2.46.1

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#14 lore raw

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

Quoted 2 lines · Vladimir 'phcoder' Serbinenko

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.

Quoted 160 lines · Leo Sandoval
Quoted 158 lines

From: Mark Hamzy <[email protected]>

Add configuration support for serial terminal consoles. This will set the maximum screen size so that text is not overwritten.

---
 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
Makefile.util.def +7 -0
index 9432365a9..09bfcadd9 100644
@@ -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;
util/grub.d/ renamed from util/grub.d/20_ppc_terminfo.in +0 -0

20_ppc_terminfo.in
new file mode 100644
index 000000000..10d665868

util/grub.d/20_ppc_terminfo.in new file +105 -0
@@ -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."

util/grub.d/20_ppc_terminfo.in new file +9 -1
+    exit 1
+  fi
+
+  check_terminfo ${GRUB_TERMINFO}
+fi
+
+cat << EOF
+  terminfo -g ${X}x${Y} ${TERMINAL}
+EOF
--

2.46.1

Quoted 10 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#15 lore raw

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

Looking at the patch: it's specific to ieee1275 not PPC. The reason is that it operates on ofconsole. But then it means that the patch description doesn't really match the intent. And neither does the name of the variable as it's specific to ofconsole

Quoted 184 lines · Leo Sandoval
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

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.

Quoted 161 lines

Le lun. 30 sept. 2024, 20:49, Leo Sandoval <[email protected]> a écrit :

Quoted 157 lines

From: Mark Hamzy <[email protected]>

Add configuration support for serial terminal consoles. This will set the maximum screen size so that text is not overwritten.

---
 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
Makefile.util.def +7 -0
index 9432365a9..09bfcadd9 100644
@@ -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;
util/grub.d/ renamed from util/grub.d/20_ppc_terminfo.in +0 -0

20_ppc_terminfo.in
new file mode 100644
index 000000000..10d665868

util/grub.d/20_ppc_terminfo.in new file +105 -0
@@ -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."

util/grub.d/20_ppc_terminfo.in new file +9 -1
+    exit 1
+  fi
+
+  check_terminfo ${GRUB_TERMINFO}
+fi
+
+cat << EOF
+  terminfo -g ${X}x${Y} ${TERMINAL}
+EOF
--

2.46.1

Quoted 10 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#16 lore raw

PATCH 9/20 normal: Add fw_path variable (revised)

In reply to Leo Sandoval

From: Paulo Flabiano Smorigo <[email protected]>

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

---
 grub-core/kern/main.c   | 13 ++++++-------
 grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 8 deletions(-)
grub-core/kern/main.c +6 -7
index 731c07c29..463dafdba 100644
@@ -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);
 	}
     }
 
grub-core/normal/main.c +24 -1
index d3f53d93d..08f48c71d 100644
@@ -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)
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#17 lore raw

PATCH 10/20 commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

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

---
 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(-)
grub-core/commands/wildcard.c +15 -1
index ed6586505..5455242c3 100644
@@ -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;
grub-core/lib/cmdline.c +23 -2
index ed0b149dc..8e2294d8f 100644
@@ -20,6 +20,12 @@
 #include <grub/lib/cmdline.h>
 #include <grub/misc.h>
 
+static int
+is_hex(char c)
+{
+  return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
+}
+
 static unsigned int check_arg (char *c, int *has_space)
 {
   int space = 0;
@@ -27,7 +33,13 @@ static unsigned int check_arg (char *c, int *has_space)
 
   while (*c)
     {
-      if (*c == '\\' || *c == '\'' || *c == '"')
+      if (*c == '\\' && *(c+1) == 'x' && is_hex(*(c+2)) && is_hex(*(c+3)))
+	{
+	  size += 4;
+	  c += 4;
+	  continue;
+	}
+      else if (*c == '\\' || *c == '\'' || *c == '"')
 	size++;
       else if (*c == ' ')
 	space = 1;
@@ -86,7 +98,16 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf,
 
       while (*c)
 	{
-	  if (*c == '\\' || *c == '\'' || *c == '"')
+	  if (*c == '\\' && *(c+1) == 'x' &&
+		   is_hex(*(c+2)) && is_hex(*(c+3)))
+	    {
+	      *buf++ = *c++;
+	      *buf++ = *c++;
+	      *buf++ = *c++;
+	      *buf++ = *c++;
+	      continue;
+	    }
+	  else if (*c == '\\' || *c == '\'' || *c == '"')
 	    *buf++ = '\\';
 
 	  *buf++ = *c;
grub-core/script/execute.c +37 -6

67 lines not on this page · raw message

Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#18 lore raw

PATCH 11/20 blscfg: add blscfg module to parse Boot Loader Specification snippets

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

The BootLoaderSpec (BLS) defines a scheme where different bootloaders can share a format for boot items and a configuration directory that accepts these common configurations as drop-in files.

---
 grub-core/Makefile.core.def    |   11 +
 grub-core/commands/blscfg.c    | 1177 ++++++++++++++++++++++++++++++++
 grub-core/commands/legacycfg.c |    5 +-
 grub-core/commands/loadenv.c   |   77 +--
 grub-core/commands/loadenv.h   |   93 +++
 grub-core/commands/menuentry.c |   20 +-
 grub-core/normal/main.c        |    6 +
 include/grub/compiler.h        |    2 +
 include/grub/menu.h            |   13 +
 include/grub/normal.h          |    2 +-
 10 files changed, 1324 insertions(+), 82 deletions(-)
 create mode 100644 grub-core/commands/blscfg.c
 create mode 100644 grub-core/commands/loadenv.h
grub-core/Makefile.core.def +11 -0
index 0bffbfea9..47c0fc755 100644
@@ -842,6 +842,16 @@ module = {
   common = commands/blocklist.c;
 };
 
+module = {
+  name = blscfg;
+  common = commands/blscfg.c;
+  common = commands/loadenv.h;
+  enable = powerpc_ieee1275;
+  enable = efi;
+  enable = i386_pc;
+  enable = emu;
+};
+
 module = {
   name = boot;
   common = commands/boot.c;
@@ -1009,6 +1019,7 @@ module = {
 module = {
   name = loadenv;
   common = commands/loadenv.c;
+  common = commands/loadenv.h;
   common = lib/envblk.c;
 };
 
grub-core/commands/blscfg.c new file +1177 -0

1,177 lines not on this page · raw message

grub-core/commands/legacycfg.c +3 -2
index e9e9d94ef..2c5d1a0ef 100644
@@ -143,7 +143,7 @@ legacy_file (const char *filename)
 	    args[0] = oldname;
 	    grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy",
 					NULL, NULL,
-					entrysrc, 0);
+					entrysrc, 0, NULL, NULL);
 	    grub_free (args);
 	    entrysrc[0] = 0;
 	    grub_free (oldname);
@@ -205,7 +205,8 @@ legacy_file (const char *filename)
 	}
       args[0] = entryname;
       grub_normal_add_menu_entry (1, args, NULL, NULL, NULL,
-				  NULL, NULL, entrysrc, 0);
+				  NULL, NULL, entrysrc, 0, NULL,
+				  NULL);
       grub_free (args);
     }
 
grub-core/commands/loadenv.c +2 -75

89 lines not on this page · raw message

grub-core/commands/loadenv.h new file +93 -0

93 lines not on this page · raw message

grub-core/commands/menuentry.c +16 -4
index 720e6d8ea..b194123eb 100644
@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
 			    char **classes, const char *id,
 			    const char *users, const char *hotkey,
 			    const char *prefix, const char *sourcecode,
-			    int submenu)
+			    int submenu, int *index, struct bls_entry *bls)
 {
   int menu_hotkey = 0;
   char **menu_args = NULL;
@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char **args,
   if (! menu_title)
     goto fail;
 
+  grub_dprintf ("menu", "id:\"%s\"\n", id);
+  grub_dprintf ("menu", "title:\"%s\"\n", menu_title);
   menu_id = grub_strdup (id ? : menu_title);
   if (! menu_id)
     goto fail;
+  grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id);
 
   /* Save argc, args to pass as parameters to block arg later. */
   menu_args = grub_calloc (argc + 1, sizeof (char *));
@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char **args,
   }
 
   /* Add the menu entry at the end of the list.  */
+  int ind=0;
   while (*last)
-    last = &(*last)->next;
+    {
+      ind++;
+      last = &(*last)->next;
+    }
 
   *last = grub_zalloc (sizeof (**last));
   if (! *last)
@@ -188,8 +195,11 @@ grub_normal_add_menu_entry (int argc, const char **args,
   (*last)->args = menu_args;
   (*last)->sourcecode = menu_sourcecode;
   (*last)->submenu = submenu;
+  (*last)->bls = bls;
 
   menu->size++;
+  if (index)
+    *index = ind;
   return GRUB_ERR_NONE;
 
  fail:
@@ -286,7 +296,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
 				       users,
 				       ctxt->state[2].arg, 0,
 				       ctxt->state[3].arg,
-				       ctxt->extcmd->cmd->name[0] == 's');
+				       ctxt->extcmd->cmd->name[0] == 's',
+				       NULL, NULL);
 
   src = args[argc - 1];
   args[argc - 1] = NULL;
@@ -303,7 +314,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
 				  ctxt->state[0].args, ctxt->state[4].arg,
 				  users,
 				  ctxt->state[2].arg, prefix, src + 1,
-				  ctxt->extcmd->cmd->name[0] == 's');
+				  ctxt->extcmd->cmd->name[0] == 's', NULL,
+				  NULL);
 
   src[len - 1] = ch;
   args[argc - 1] = src;
grub-core/normal/main.c +6 -0
index 08f48c71d..1317279c0 100644
@@ -21,6 +21,7 @@
 #include <grub/net.h>
 #include <grub/normal.h>
 #include <grub/dl.h>
+#include <grub/menu.h>
 #include <grub/misc.h>
 #include <grub/file.h>
 #include <grub/mm.h>
@@ -70,6 +71,11 @@ grub_normal_free_menu (grub_menu_t menu)
 	  grub_free (entry->args);
 	}
 
+      if (entry->bls)
+	{
+	  entry->bls->visible = 0;
+	}
+
       grub_free ((void *) entry->id);
       grub_free ((void *) entry->users);
       grub_free ((void *) entry->title);
include/grub/compiler.h +2 -0
index 0c5519387..441a9eca0 100644
@@ -56,4 +56,6 @@
 #  define CLANG_PREREQ(maj,min) 0
 #endif
 
+#define UNUSED __attribute__((__unused__))
+
 #endif /* ! GRUB_COMPILER_HEADER */
include/grub/menu.h +13 -0
index ee2b5e910..0acdc2aa6 100644
@@ -20,6 +20,16 @@
 #ifndef GRUB_MENU_HEADER
 #define GRUB_MENU_HEADER 1
 
+struct bls_entry
+{
+  struct bls_entry *next;
+  struct bls_entry *prev;
+  struct keyval **keyvals;
+  int nkeyvals;
+  char *filename;
+  int visible;
+};
+
 struct grub_menu_entry_class
 {
   char *name;
@@ -60,6 +70,9 @@ struct grub_menu_entry
 
   /* The next element.  */
   struct grub_menu_entry *next;
+
+  /* BLS used to populate the entry */
+  struct bls_entry *bls;
 };
 typedef struct grub_menu_entry *grub_menu_entry_t;
 
include/grub/normal.h +1 -1
index 218cbabcc..8839ad85a 100644
@@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes,
 			    const char *id,
 			    const char *users, const char *hotkey,
 			    const char *prefix, const char *sourcecode,
-			    int submenu);
+			    int submenu, int *index, struct bls_entry *bls);
 
 grub_err_t
 grub_normal_set_password (const char *user, const char *password);
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#19 lore raw

Re: [PATCH 11/20] blscfg: add blscfg module to parse Boot Loader Specification snippets

This is already being reviewed in separate thread

Quoted 1,650 lines · Leo Sandoval

From: Peter Jones <[email protected]>

The BootLoaderSpec (BLS) defines a scheme where different bootloaders can share a format for boot items and a configuration directory that accepts these common configurations as drop-in files.

---
 grub-core/Makefile.core.def    |   11 +
 grub-core/commands/blscfg.c    | 1177 ++++++++++++++++++++++++++++++++
 grub-core/commands/legacycfg.c |    5 +-
 grub-core/commands/loadenv.c   |   77 +--
 grub-core/commands/loadenv.h   |   93 +++
 grub-core/commands/menuentry.c |   20 +-
 grub-core/normal/main.c        |    6 +
 include/grub/compiler.h        |    2 +
 include/grub/menu.h            |   13 +
 include/grub/normal.h          |    2 +-
 10 files changed, 1324 insertions(+), 82 deletions(-)
 create mode 100644 grub-core/commands/blscfg.c
 create mode 100644 grub-core/commands/loadenv.h
grub-core/Makefile.core.def +11 -0
index 0bffbfea9..47c0fc755 100644
@@ -842,6 +842,16 @@ module = {
   common = commands/blocklist.c;
 };
 
+module = {
+  name = blscfg;
+  common = commands/blscfg.c;
+  common = commands/loadenv.h;
+  enable = powerpc_ieee1275;
+  enable = efi;
+  enable = i386_pc;
+  enable = emu;
+};
+
 module = {
   name = boot;
   common = commands/boot.c;
@@ -1009,6 +1019,7 @@ module = {
 module = {
   name = loadenv;
   common = commands/loadenv.c;
+  common = commands/loadenv.h;
   common = lib/envblk.c;
 };
 
grub-core/commands/blscfg.c new file +97 -0
new file mode 100644
index 000000000..e907a6a5d
@@ -0,0 +1,1177 @@
+/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/
+
+/* bls.c - implementation of the boot loader spec */
+
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *
+ *  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/>.
+ */
+
+#include <grub/list.h>
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/dl.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/fs.h>
+#include <grub/env.h>
+#include <grub/file.h>
+#include <grub/normal.h>
+#include <grub/lib/envblk.h>
+
+#include <stdbool.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#include "loadenv.h"
+
+#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
+#ifdef GRUB_MACHINE_EMU
+#define GRUB_BOOT_DEVICE "/boot"
+#else
+#define GRUB_BOOT_DEVICE "($root)"
+#endif
+
+struct keyval
+{
+  const char *key;
+  char *val;
+};
+
+static struct bls_entry *entries = NULL;
+
+#define FOR_BLS_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries)
+
+static int bls_add_keyval(struct bls_entry *entry, char *key, char *val)
+{
+  char *k, *v;
+  struct keyval **kvs, *kv;
+  int new_n = entry->nkeyvals + 1;
+
+  kvs = grub_realloc (entry->keyvals, new_n * sizeof (struct keyval *));
+  if (!kvs)
+    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                      "couldn't find space for BLS entry");
+  entry->keyvals = kvs;
+
+  kv = grub_malloc (sizeof (struct keyval));
+  if (!kv)
+    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                      "couldn't find space for BLS entry");
+
+  k = grub_strdup (key);
+  if (!k)
+    {
+      grub_free (kv);
+      return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                        "couldn't find space for BLS entry");
+    }
+
+  v = grub_strdup (val);
+  if (!v)
+    {
+      grub_free (k);
+      grub_free (kv);
+      return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                        "couldn't find space for BLS entry");
+    }
+
+  kv->key = k;
+  kv->val = v;
+
+  entry->keyvals[entry->nkeyvals] = kv;
+  grub_dprintf("blscfg", "new keyval at %p:%s:%s\n",

entry->keyvals[entry->nkeyvals], k, v);

grub-core/commands/blscfg.c new file +6 -0
+  entry->nkeyvals = new_n;
+
+  return 0;
+}
+
+/* Find they value of the key named by keyname.  If there are allowed to

be
+ * more than one, pass a pointer to an int set to -1 the first time, and pass
+ * the same pointer through each time after, and it'll return them in sorted
+ * order as defined in the BLS fragment file */
+static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last)

grub-core/commands/blscfg.c new file +57 -0
+{
+  int idx, start = 0;
+  struct keyval *kv = NULL;
+
+  if (last)
+    start = *last + 1;
+
+  for (idx = start; idx < entry->nkeyvals; idx++) {
+    kv = entry->keyvals[idx];
+
+    if (!grub_strcmp (keyname, kv->key))
+      break;
+  }
+
+  if (idx == entry->nkeyvals) {
+    if (last)
+      *last = -1;
+    return NULL;
+  }
+
+  if (last)
+    *last = idx;
+
+  return kv->val;
+}
+
+#define goto_return(x) ({ ret = (x); goto finish; })
+
+/* compare alpha and numeric segments of two versions */
+/* return 1: a is newer than b */
+/*        0: a and b are the same version */
+/*       -1: b is newer than a */
+static int vercmp(const char * a, const char * b)
+{
+    char oldch1, oldch2;
+    char *abuf, *bbuf;
+    char *str1, *str2;
+    char * one, * two;
+    int rc;
+    int isnum;
+    int ret = 0;
+
+    grub_dprintf("blscfg", "%s comparing %s and %s\n", __func__, a, b);
+    if (!grub_strcmp(a, b))
+           return 0;
+
+    abuf = grub_malloc(grub_strlen(a) + 1);
+    bbuf = grub_malloc(grub_strlen(b) + 1);
+    str1 = abuf;
+    str2 = bbuf;
+    grub_strcpy(str1, a);
+    grub_strcpy(str2, b);
+
+    one = str1;
+    two = str2;
+
+    /* loop through each version segment of str1 and str2 and compare

them */

grub-core/commands/blscfg.c new file +2 -0
+    while (*one || *two) {
+       while (*one && !grub_isalnum(*one) && *one != '~' && *one != '+')

one++;
+ while (*two && !grub_isalnum(*two) && *two != '~' && *two != '+')
two++;

grub-core/commands/blscfg.c new file +33 -0
+
+       /* handle the tilde separator, it sorts before everything else */
+       if (*one == '~' || *two == '~') {
+           if (*one != '~') goto_return (1);
+           if (*two != '~') goto_return (-1);
+           one++;
+           two++;
+           continue;
+       }
+
+       /*
+        * Handle plus separator. Concept is the same as tilde,
+        * except that if one of the strings ends (base version),
+        * the other is considered as higher version.
+        */
+       if (*one == '+' || *two == '+') {
+           if (!*one) return -1;
+           if (!*two) return 1;
+           if (*one != '+') goto_return (1);
+           if (*two != '+') goto_return (-1);
+           one++;
+           two++;
+           continue;
+       }
+
+       /* If we ran to the end of either, we are finished with the loop */
+       if (!(*one && *two)) break;
+
+       str1 = one;
+       str2 = two;
+
+       /* grab first completely alpha or completely numeric segment */
+       /* leave one and two pointing to the start of the alpha or numeric

*/

grub-core/commands/blscfg.c new file +33 -0
+       /* segment and walk str1 and str2 to end of segment */
+       if (grub_isdigit(*str1)) {
+           while (*str1 && grub_isdigit(*str1)) str1++;
+           while (*str2 && grub_isdigit(*str2)) str2++;
+           isnum = 1;
+       } else {
+           while (*str1 && grub_isalpha(*str1)) str1++;
+           while (*str2 && grub_isalpha(*str2)) str2++;
+           isnum = 0;
+       }
+
+       /* save character at the end of the alpha or numeric segment */
+       /* so that they can be restored after the comparison */
+       oldch1 = *str1;
+       *str1 = '\0';
+       oldch2 = *str2;
+       *str2 = '\0';
+
+       /* this cannot happen, as we previously tested to make sure that */
+       /* the first string has a non-null segment */
+       if (one == str1) goto_return(-1);       /* arbitrary */
+
+       /* take care of the case where the two version segments are */
+       /* different types: one numeric, the other alpha (i.e. empty) */
+       /* numeric segments are always newer than alpha segments */
+       /* XXX See patch #60884 (and details) from bugzilla #50977. */
+       if (two == str2) goto_return (isnum ? 1 : -1);
+
+       if (isnum) {
+           grub_size_t onelen, twolen;
+           /* this used to be done by converting the digit segments */
+           /* to ints using atoi() - it's changed because long  */
+           /* digit segments can overflow an int - this should fix that.

*/

grub-core/commands/blscfg.c new file +13 -0
+
+           /* throw away any leading zeros - it's a number, right? */
+           while (*one == '0') one++;
+           while (*two == '0') two++;
+
+           /* whichever number has more digits wins */
+           onelen = grub_strlen(one);
+           twolen = grub_strlen(two);
+           if (onelen > twolen) goto_return (1);
+           if (twolen > onelen) goto_return (-1);
+       }
+
+       /* grub_strcmp will return which one is greater - even if the two

*/

grub-core/commands/blscfg.c new file +82 -0
+       /* segments are alpha or if they are numeric.  don't return  */
+       /* if they are equal because there might be more segments to */
+       /* compare */
+       rc = grub_strcmp(one, two);
+       if (rc) goto_return (rc < 1 ? -1 : 1);
+
+       /* restore character that was replaced by null above */
+       *str1 = oldch1;
+       one = str1;
+       *str2 = oldch2;
+       two = str2;
+    }
+
+    /* this catches the case where all numeric and alpha segments have */
+    /* compared identically but the segment sepparating characters were */
+    /* different */
+    if ((!*one) && (!*two)) goto_return (0);
+
+    /* whichever version still has characters left over wins */
+    if (!*one) goto_return (-1); else goto_return (1);
+
+finish:
+    grub_free (abuf);
+    grub_free (bbuf);
+    return ret;
+}
+
+/* returns name/version/release */
+/* NULL string pointer returned if nothing found */
+static void
+split_package_string (char *package_string, char **name,
+                     char **version, char **release)
+{
+  char *package_version, *package_release;
+
+  /* Release */
+  package_release = grub_strrchr (package_string, '-');
+
+  if (package_release != NULL)
+      *package_release++ = '\0';
+
+  *release = package_release;
+
+  if (name == NULL)
+    {
+      *version = package_string;
+    }
+  else
+    {
+      /* Version */
+      package_version = grub_strrchr(package_string, '-');
+
+      if (package_version != NULL)
+       *package_version++ = '\0';
+
+      *version = package_version;
+      /* Name */
+      *name = package_string;
+    }
+
+  /* Bubble up non-null values from release to name */
+  if (name != NULL && *name == NULL)
+    {
+      *name = (*version == NULL ? *release : *version);
+      *version = *release;
+      *release = NULL;
+    }
+  if (*version == NULL)
+    {
+      *version = *release;
+      *release = NULL;
+    }
+}
+
+static int
+split_cmp(char *nvr0, char *nvr1, int has_name)
+{
+  int ret = 0;
+  char *name0, *version0, *release0;
+  char *name1, *version1, *release1;
+
+  split_package_string(nvr0, has_name ? &name0 : NULL, &version0,

&release0);
+ split_package_string(nvr1, has_name ? &name1 : NULL, &version1, &release1);

grub-core/commands/blscfg.c new file +54 -0
+
+  if (has_name)
+    {
+      ret = vercmp(name0 == NULL ? "" : name0,
+                  name1 == NULL ? "" : name1);
+      if (ret != 0)
+       return ret;
+    }
+
+  ret = vercmp(version0 == NULL ? "" : version0,
+              version1 == NULL ? "" : version1);
+  if (ret != 0)
+    return ret;
+
+  ret = vercmp(release0 == NULL ? "" : release0,
+              release1 == NULL ? "" : release1);
+  return ret;
+}
+
+/* return 1: e0 is newer than e1 */
+/*        0: e0 and e1 are the same version */
+/*       -1: e1 is newer than e0 */
+static int bls_cmp(const struct bls_entry *e0, const struct bls_entry *e1)
+{
+  char *id0, *id1;
+  int r;
+
+  id0 = grub_strdup(e0->filename);
+  id1 = grub_strdup(e1->filename);
+
+  r = split_cmp(id0, id1, 1);
+
+  grub_free(id0);
+  grub_free(id1);
+
+  return r;
+}
+
+static void list_add_tail(struct bls_entry *head, struct bls_entry *item)
+{
+  item->next = head;
+  if (head->prev)
+    head->prev->next = item;
+  item->prev = head->prev;
+  head->prev = item;
+}
+
+static int bls_add_entry(struct bls_entry *entry)
+{
+  struct bls_entry *e, *last = NULL;
+  int rc;
+
+  if (!entries) {
+    grub_dprintf ("blscfg", "Add entry with id \"%s\"\n",

entry->filename);

grub-core/commands/blscfg.c new file +12 -0
+    entries = entry;
+    return 0;
+  }
+
+  FOR_BLS_ENTRIES(e) {
+    rc = bls_cmp(entry, e);
+
+    if (!rc)
+      return GRUB_ERR_BAD_ARGUMENT;
+
+    if (rc == 1) {
+      grub_dprintf ("blscfg", "Add entry with id \"%s\"\n",

entry->filename);

grub-core/commands/blscfg.c new file +12 -0
+      list_add_tail (e, entry);
+      if (e == entries) {
+       entries = entry;
+       entry->prev = NULL;
+      }
+      return 0;
+    }
+    last = e;
+  }
+
+  if (last) {
+    grub_dprintf ("blscfg", "Add entry with id \"%s\"\n",

entry->filename);

grub-core/commands/blscfg.c new file +45 -0
+    last->next = entry;
+    entry->prev = last;
+  }
+
+  return 0;
+}
+
+struct read_entry_info {
+  const char *devid;
+  const char *dirname;
+  grub_file_t file;
+};
+
+static int read_entry (
+    const char *filename,
+    const struct grub_dirhook_info *dirhook_info UNUSED,
+    void *data)
+{
+  grub_size_t m = 0, n, clip = 0;
+  int rc = 0;
+  char *p = NULL;
+  grub_file_t f = NULL;
+  struct bls_entry *entry;
+  struct read_entry_info *info = (struct read_entry_info *)data;
+
+  grub_dprintf ("blscfg", "filename: \"%s\"\n", filename);
+
+  n = grub_strlen (filename);
+
+  if (info->file)
+    {
+      f = info->file;
+    }
+  else
+    {
+      if (filename[0] == '.')
+       return 0;
+
+      if (n <= 5)
+       return 0;
+
+      if (grub_strcmp (filename + n - 5, ".conf") != 0)
+       return 0;
+
+      p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname,

filename);

grub-core/commands/blscfg.c new file +121 -0
+
+      f = grub_file_open (p, GRUB_FILE_TYPE_CONFIG);
+      if (!f)
+       goto finish;
+    }
+
+  entry = grub_zalloc (sizeof (*entry));
+  if (!entry)
+    goto finish;
+
+  if (info->file)
+    {
+      char *slash;
+
+      if (n > 5 && !grub_strcmp (filename + n - 5, ".conf") == 0)
+       clip = 5;
+
+      slash = grub_strrchr (filename, '/');
+      if (!slash)
+       slash = grub_strrchr (filename, '\\');
+
+      while (*slash == '/' || *slash == '\\')
+       slash++;
+
+      m = slash ? slash - filename : 0;
+    }
+  else
+    {
+      m = 0;
+      clip = 5;
+    }
+  n -= m;
+
+  entry->filename = grub_strndup(filename + m, n - clip);
+  if (!entry->filename)
+    goto finish;
+
+  entry->filename[n - 5] = '\0';
+
+  for (;;)
+    {
+      char *buf;
+      char *separator;
+
+      buf = grub_file_getline (f);
+      if (!buf)
+       break;
+
+      while (buf && buf[0] && (buf[0] == ' ' || buf[0] == '\t'))
+       buf++;
+      if (buf[0] == '#')
+       continue;
+
+      separator = grub_strchr (buf, ' ');
+
+      if (!separator)
+       separator = grub_strchr (buf, '\t');
+
+      if (!separator || separator[1] == '\0')
+       {
+         grub_free (buf);
+         break;
+       }
+
+      separator[0] = '\0';
+
+      do {
+       separator++;
+      } while (*separator == ' ' || *separator == '\t');
+
+      rc = bls_add_keyval (entry, buf, separator);
+      grub_free (buf);
+      if (rc < 0)
+       break;
+    }
+
+    if (!rc)
+      bls_add_entry(entry);
+
+finish:
+  if (p)
+    grub_free (p);
+
+  if (f)
+    grub_file_close (f);
+
+  return 0;
+}
+
+static grub_envblk_t saved_env = NULL;
+
+static int UNUSED
+save_var (const char *name, const char *value, void *whitelist UNUSED)
+{
+  const char *val = grub_env_get (name);
+  grub_dprintf("blscfg", "saving \"%s\"\n", name);
+
+  if (val)
+    grub_envblk_set (saved_env, name, value);
+
+  return 0;
+}
+
+static int UNUSED
+unset_var (const char *name, const char *value UNUSED, void *whitelist)
+{
+  grub_dprintf("blscfg", "restoring \"%s\"\n", name);
+  if (! whitelist)
+    {
+      grub_env_unset (name);
+      return 0;
+    }
+
+  if (test_whitelist_membership (name,
+                                (const grub_env_whitelist_t *) whitelist))
+    grub_env_unset (name);
+
+  return 0;
+}
+
+static char **bls_make_list (struct bls_entry *entry, const char *key,

int *num)

grub-core/commands/blscfg.c new file +42 -0
+{
+  int last = -1;
+  char *val;
+
+  int nlist = 0;
+  char **list = NULL;
+
+  list = grub_malloc (sizeof (char *));
+  if (!list)
+    return NULL;
+  list[0] = NULL;
+
+  while (1)
+    {
+      char **new;
+
+      val = bls_get_val (entry, key, &last);
+      if (!val)
+       break;
+
+      new = grub_realloc (list, (nlist + 2) * sizeof (char *));
+      if (!new)
+       break;
+
+      list = new;
+      list[nlist++] = val;
+      list[nlist] = NULL;
+  }
+
+  if (!nlist)
+    {
+      grub_free (list);
+      return NULL;
+    }
+
+  if (num)
+    *num = nlist;
+
+  return list;
+}
+
+static char *field_append(bool is_var, char *buffer, const char *start,

const char *end)

grub-core/commands/blscfg.c new file +15 -0
+{
+  char *tmp = grub_strndup(start, end - start + 1);
+  const char *field = tmp;
+  int term = is_var ? 2 : 1;
+
+  if (is_var) {
+    field = grub_env_get (tmp);
+    if (!field)
+      return buffer;
+  }
+
+  if (!buffer)
+    buffer = grub_zalloc (grub_strlen(field) + term);
+  else
+    buffer = grub_realloc (buffer, grub_strlen(buffer) +

grub_strlen(field) + term);

grub-core/commands/blscfg.c new file +116 -0
+
+  if (!buffer)
+    return NULL;
+
+  tmp = buffer + grub_strlen(buffer);
+  tmp = grub_stpcpy (tmp, field);
+
+  if (is_var)
+      tmp = grub_stpcpy (tmp, " ");
+
+  return buffer;
+}
+
+static char *expand_val(const char *value)
+{
+  char *buffer = NULL;
+  const char *start = value;
+  const char *end = value;
+  bool is_var = false;
+
+  if (!value)
+    return NULL;
+
+  while (*value) {
+    if (*value == '$') {
+      if (start != end) {
+       buffer = field_append(is_var, buffer, start, end);
+       if (!buffer)
+         return NULL;
+      }
+
+      is_var = true;
+      start = value + 1;
+    } else if (is_var) {
+      if (!grub_isalnum(*value) && *value != '_') {
+       buffer = field_append(is_var, buffer, start, end);
+       is_var = false;
+       start = value;
+       if (*start == ' ')
+         start++;
+      }
+    }
+
+    end = value;
+    value++;
+  }
+
+  if (start != end) {
+    buffer = field_append(is_var, buffer, start, end);
+    if (!buffer)
+      return NULL;
+  }
+
+  return buffer;
+}
+
+static char **early_initrd_list (const char *initrd)
+{
+  int nlist = 0;
+  char **list = NULL;
+  char *separator;
+
+  while ((separator = grub_strchr (initrd, ' ')))
+    {
+      list = grub_realloc (list, (nlist + 2) * sizeof (char *));
+      if (!list)
+        return NULL;
+
+      list[nlist++] = grub_strndup(initrd, separator - initrd);
+      list[nlist] = NULL;
+      initrd = separator + 1;
+  }
+
+  list = grub_realloc (list, (nlist + 2) * sizeof (char *));
+  if (!list)
+    return NULL;
+
+  list[nlist++] = grub_strndup(initrd, grub_strlen(initrd));
+  list[nlist] = NULL;
+
+  return list;
+}
+
+static void create_entry (struct bls_entry *entry)
+{
+  int argc = 0;
+  const char **argv = NULL;
+
+  char *title = NULL;
+  char *clinux = NULL;
+  char *options = NULL;
+  char **initrds = NULL;
+  char *initrd = NULL;
+  const char *early_initrd = NULL;
+  char **early_initrds = NULL;
+  char *initrd_prefix = NULL;
+  char *devicetree = NULL;
+  char *dt = NULL;
+  char *id = entry->filename;
+  char *dotconf = id;
+  char *hotkey = NULL;
+
+  char *users = NULL;
+  char **classes = NULL;
+
+  char **args = NULL;
+
+  char *src = NULL;
+  int i, index;
+  bool add_dt_prefix = false;
+
+  grub_dprintf("blscfg", "%s got here\n", __func__);
+  clinux = bls_get_val (entry, "linux", NULL);
+  if (!clinux)
+    {
+      grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n",

entry->filename);

grub-core/commands/blscfg.c new file +58 -0
+      goto finish;
+    }
+
+  /*
+   * strip the ".conf" off the end before we make it our "id" field.
+   */
+  do
+    {
+      dotconf = grub_strstr(dotconf, ".conf");
+    } while (dotconf != NULL && dotconf[5] != '\0');
+  if (dotconf)
+    dotconf[0] = '\0';
+
+  title = bls_get_val (entry, "title", NULL);
+  options = expand_val (bls_get_val (entry, "options", NULL));
+
+  if (!options)
+    options = expand_val (grub_env_get("default_kernelopts"));
+
+  initrds = bls_make_list (entry, "initrd", NULL);
+
+  devicetree = expand_val (bls_get_val (entry, "devicetree", NULL));
+
+  if (!devicetree)
+    {
+      devicetree = expand_val (grub_env_get("devicetree"));
+      add_dt_prefix = true;
+    }
+
+  hotkey = bls_get_val (entry, "grub_hotkey", NULL);
+  users = expand_val (bls_get_val (entry, "grub_users", NULL));
+  classes = bls_make_list (entry, "grub_class", NULL);
+  args = bls_make_list (entry, "grub_arg", &argc);
+
+  argc += 1;
+  argv = grub_malloc ((argc + 1) * sizeof (char *));
+  argv[0] = title ? title : clinux;
+  for (i = 1; i < argc; i++)
+    argv[i] = args[i-1];
+  argv[argc] = NULL;
+
+  early_initrd = grub_env_get("early_initrd");
+
+  grub_dprintf ("blscfg", "adding menu entry for \"%s\" with id \"%s\"\n",
+               title, id);
+  if (early_initrd)
+    {
+      early_initrds = early_initrd_list(early_initrd);
+      if (!early_initrds)
+      {
+       grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+       goto finish;
+      }
+
+      if (initrds != NULL && initrds[0] != NULL)
+       {
+         initrd_prefix = grub_strrchr (initrds[0], '/');
+         initrd_prefix = grub_strndup(initrds[0], initrd_prefix -

initrds[0] + 1);

grub-core/commands/blscfg.c new file +40 -0
+       }
+      else
+       {
+         initrd_prefix = grub_strrchr (clinux, '/');
+         initrd_prefix = grub_strndup(clinux, initrd_prefix - clinux + 1);
+       }
+
+      if (!initrd_prefix)
+       {
+         grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+         goto finish;
+       }
+    }
+
+  if (early_initrds || initrds)
+    {
+      int initrd_size = sizeof ("initrd");
+      char *tmp;
+
+      for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++)
+       initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \
+                      + grub_strlen(initrd_prefix)  \
+                      + grub_strlen (early_initrds[i]) + 1;
+
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
+       initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \
+                      + grub_strlen (initrds[i]) + 1;
+      initrd_size += 1;
+
+      initrd = grub_malloc (initrd_size);
+      if (!initrd)
+       {
+         grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+         goto finish;
+       }
+
+      tmp = grub_stpcpy(initrd, "initrd");
+      for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++)
+       {
+         grub_dprintf ("blscfg", "adding early initrd %s\n",

early_initrds[i]);

grub-core/commands/blscfg.c new file +32 -0
+         tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+         tmp = grub_stpcpy (tmp, initrd_prefix);
+         tmp = grub_stpcpy (tmp, early_initrds[i]);
+         grub_free(early_initrds[i]);
+       }
+
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
+       {
+         grub_dprintf ("blscfg", "adding initrd %s\n", initrds[i]);
+         tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+         tmp = grub_stpcpy (tmp, initrds[i]);
+       }
+      tmp = grub_stpcpy (tmp, "\n");
+    }
+
+  if (devicetree)
+    {
+      char *prefix = NULL;
+      int dt_size;
+
+      if (add_dt_prefix)
+       {
+         prefix = grub_strrchr (clinux, '/');
+         prefix = grub_strndup(clinux, prefix - clinux + 1);
+         if (!prefix)
+           {
+             grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+             goto finish;
+           }
+       }
+
+      dt_size = sizeof("devicetree " GRUB_BOOT_DEVICE) +

grub_strlen(devicetree) + 1;

grub-core/commands/blscfg.c new file +27 -0
+
+      if (add_dt_prefix)
+       {
+         dt_size += grub_strlen(prefix);
+       }
+
+      dt = grub_malloc (dt_size);
+      if (!dt)
+        {
+          grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+        goto finish;
+        }
+      char *tmp = dt;
+      tmp = grub_stpcpy (dt, "devicetree");
+      tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+      if (add_dt_prefix)
+        tmp = grub_stpcpy (tmp, prefix);
+      tmp = grub_stpcpy (tmp, devicetree);
+      tmp = grub_stpcpy (tmp, "\n");
+
+      grub_free(prefix);
+    }
+
+  grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id);
+
+  const char *sdval = grub_env_get("save_default");
+  bool savedefault = ((NULL != sdval) && (grub_strcmp(sdval, "true") ==

0));

grub-core/commands/blscfg.c new file +7 -0
+  src = grub_xasprintf ("%sload_video\n"
+                       "set gfxpayload=keep\n"
+                       "insmod gzio\n"
+                       "linux %s%s%s%s\n"
+                       "%s%s",
+                       savedefault ? "savedefault\n" : "",
+                       GRUB_BOOT_DEVICE, clinux, options ? " " : "",

options ? options : "",

grub-core/commands/blscfg.c new file +3 -0
+                       initrd ? initrd : "", dt ? dt : "");
+
+  grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey,

NULL, src, 0, &index, entry);

grub-core/commands/blscfg.c new file +65 -0
+  grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id);
+
+finish:
+  grub_free (dt);
+  grub_free (initrd);
+  grub_free (initrd_prefix);
+  grub_free (early_initrds);
+  grub_free (devicetree);
+  grub_free (initrds);
+  grub_free (options);
+  grub_free (classes);
+  grub_free (args);
+  grub_free (argv);
+  grub_free (src);
+}
+
+struct find_entry_info {
+       const char *dirname;
+       const char *devid;
+       grub_device_t dev;
+       grub_fs_t fs;
+};
+
+/*
+ * info: the filesystem object the file is on.
+ */
+static int find_entry (struct find_entry_info *info)
+{
+  struct read_entry_info read_entry_info;
+  grub_fs_t blsdir_fs = NULL;
+  grub_device_t blsdir_dev = NULL;
+  const char *blsdir = info->dirname;
+  int fallback = 0;
+  int r = 0;
+
+  if (!blsdir) {
+    blsdir = grub_env_get ("blsdir");
+    if (!blsdir)
+      blsdir = GRUB_BLS_CONFIG_PATH;
+  }
+
+  read_entry_info.file = NULL;
+  read_entry_info.dirname = blsdir;
+
+  grub_dprintf ("blscfg", "scanning blsdir: %s\n", blsdir);
+
+  blsdir_dev = info->dev;
+  blsdir_fs = info->fs;
+  read_entry_info.devid = info->devid;
+
+read_fallback:
+  r = blsdir_fs->fs_dir (blsdir_dev, read_entry_info.dirname, read_entry,
+                        &read_entry_info);
+  if (r != 0) {
+      grub_dprintf ("blscfg", "read_entry returned error\n");
+      grub_err_t e;
+      do
+       {
+         e = grub_error_pop();
+       } while (e);
+  }
+
+  if (r && !info->dirname && !fallback) {
+    read_entry_info.dirname = "/boot" GRUB_BLS_CONFIG_PATH;
+    grub_dprintf ("blscfg", "Entries weren't found in %s, fallback to

%s\n",

grub-core/commands/blscfg.c new file +43 -0
+                 blsdir, read_entry_info.dirname);
+    fallback = 1;
+    goto read_fallback;
+  }
+
+  return 0;
+}
+
+static grub_err_t
+bls_load_entries (const char *path)
+{
+  grub_size_t len;
+  grub_fs_t fs;
+  grub_device_t dev;
+  static grub_err_t r;
+  const char *devid = NULL;
+  char *blsdir = NULL;
+  struct find_entry_info info = {
+      .dev = NULL,
+      .fs = NULL,
+      .dirname = NULL,
+  };
+  struct read_entry_info rei = {
+      .devid = NULL,
+      .dirname = NULL,
+  };
+
+  if (path) {
+    len = grub_strlen (path);
+    if (grub_strcmp (path + len - 5, ".conf") == 0) {
+      rei.file = grub_file_open (path, GRUB_FILE_TYPE_CONFIG);
+      if (!rei.file)
+       return grub_errno;
+      /*
+       * read_entry() closes the file
+       */
+      return read_entry(path, NULL, &rei);
+    } else if (path[0] == '(') {
+      devid = path + 1;
+
+      blsdir = grub_strchr (path, ')');
+      if (!blsdir)
+       return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Filepath isn't

correct"));

grub-core/commands/blscfg.c new file +74 -0
+
+      *blsdir = '\0';
+      blsdir = blsdir + 1;
+    }
+  }
+
+  if (!devid) {
+#ifdef GRUB_MACHINE_EMU
+    devid = "host";
+#else
+    devid = grub_env_get ("root");
+#endif
+    if (!devid)
+      return grub_error (GRUB_ERR_FILE_NOT_FOUND,
+                        N_("variable `%s' isn't set"), "root");
+  }
+
+  grub_dprintf ("blscfg", "opening %s\n", devid);
+  dev = grub_device_open (devid);
+  if (!dev)
+    return grub_errno;
+
+  grub_dprintf ("blscfg", "probing fs\n");
+  fs = grub_fs_probe (dev);
+  if (!fs)
+    {
+      r = grub_errno;
+      goto finish;
+    }
+
+  info.dirname = blsdir;
+  info.devid = devid;
+  info.dev = dev;
+  info.fs = fs;
+  find_entry(&info);
+
+finish:
+  if (dev)
+    grub_device_close (dev);
+
+  return r;
+}
+
+static bool
+is_default_entry(const char *def_entry, struct bls_entry *entry, int idx)
+{
+  const char *title;
+  int def_idx;
+
+  if (!def_entry)
+    return false;
+
+  if (grub_strcmp(def_entry, entry->filename) == 0)
+    return true;
+
+  title = bls_get_val(entry, "title", NULL);
+
+  if (title && grub_strcmp(def_entry, title) == 0)
+    return true;
+
+  def_idx = (int)grub_strtol(def_entry, NULL, 0);
+  if (grub_errno == GRUB_ERR_BAD_NUMBER) {
+    grub_errno = GRUB_ERR_NONE;
+    return false;
+  }
+
+  if (def_idx == idx)
+    return true;
+
+  return false;
+}
+
+static grub_err_t
+bls_create_entries (bool show_default, bool show_non_default, char

*entry_id)

grub-core/commands/blscfg.c new file +68 -0
+{
+  const char *def_entry = NULL;
+  struct bls_entry *entry = NULL;
+  int idx = 0;
+
+  def_entry = grub_env_get("default");
+
+  grub_dprintf ("blscfg", "%s Creating entries from bls\n", __func__);
+  FOR_BLS_ENTRIES(entry) {
+    if (entry->visible) {
+      idx++;
+      continue;
+    }
+
+    if ((show_default && is_default_entry(def_entry, entry, idx)) ||
+       (show_non_default && !is_default_entry(def_entry, entry, idx)) ||
+       (entry_id && grub_strcmp(entry_id, entry->filename) == 0)) {
+      create_entry(entry);
+      entry->visible = 1;
+    }
+    idx++;
+  }
+
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED,
+                int argc, char **args)
+{
+  grub_err_t r;
+  char *path = NULL;
+  char *entry_id = NULL;
+  bool show_default = true;
+  bool show_non_default = true;
+
+  if (argc == 1) {
+    if (grub_strcmp (args[0], "default") == 0) {
+      show_non_default = false;
+    } else if (grub_strcmp (args[0], "non-default") == 0) {
+      show_default = false;
+    } else if (args[0][0] == '(') {
+      path = args[0];
+    } else {
+      entry_id = args[0];
+      show_default = false;
+      show_non_default = false;
+    }
+  }
+
+  r = bls_load_entries(path);
+  if (r)
+    return r;
+
+  return bls_create_entries(show_default, show_non_default, entry_id);
+}
+
+static grub_extcmd_t cmd;
+static grub_extcmd_t oldcmd;
+
+GRUB_MOD_INIT(blscfg)
+{
+  grub_dprintf("blscfg", "%s got here\n", __func__);
+  cmd = grub_register_extcmd ("blscfg",
+                             grub_cmd_blscfg,
+                             0,
+                             NULL,
+                             N_("Import Boot Loader Specification

snippets."),

grub-core/commands/blscfg.c new file +6 -0
+                             NULL);
+  oldcmd = grub_register_extcmd ("bls_import",
+                                grub_cmd_blscfg,
+                                0,
+                                NULL,
+                                N_("Import Boot Loader Specification

snippets."),

grub-core/commands/blscfg.c new file +8 -0
+                                NULL);
+}
+
+GRUB_MOD_FINI(blscfg)
+{
+  grub_unregister_extcmd (cmd);
+  grub_unregister_extcmd (oldcmd);
+}
grub-core/commands/legacycfg.c +3 -2
index e9e9d94ef..2c5d1a0ef 100644
@@ -143,7 +143,7 @@ legacy_file (const char *filename)
            args[0] = oldname;
            grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy",
                                        NULL, NULL,
-                                       entrysrc, 0);
+                                       entrysrc, 0, NULL, NULL);
            grub_free (args);
            entrysrc[0] = 0;
            grub_free (oldname);
@@ -205,7 +205,8 @@ legacy_file (const char *filename)
        }
       args[0] = entryname;
       grub_normal_add_menu_entry (1, args, NULL, NULL, NULL,
-                                 NULL, NULL, entrysrc, 0);
+                                 NULL, NULL, entrysrc, 0, NULL,
+                                 NULL);
       grub_free (args);
     }
 
grub-core/commands/loadenv.c +2 -75
index 166445849..dfcb19e0f 100644
@@ -28,6 +28,8 @@
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
 
+#include "loadenv.h"
+
 GRUB_MOD_LICENSE ("GPLv3+");
 
 static const struct grub_arg_option options[] =
@@ -79,81 +81,6 @@ open_envblk_file (char *filename,
   return file;
 }
 
-static grub_envblk_t
-read_envblk_file (grub_file_t file)
-{
-  grub_off_t offset = 0;
-  char *buf;
-  grub_size_t size = grub_file_size (file);
-  grub_envblk_t envblk;
-
-  buf = grub_malloc (size);
-  if (! buf)
-    return 0;
-
-  while (size > 0)
-    {
-      grub_ssize_t ret;
-
-      ret = grub_file_read (file, buf + offset, size);
-      if (ret <= 0)
-        {
-          grub_free (buf);
-          return 0;
-        }
-
-      size -= ret;
-      offset += ret;
-    }
-
-  envblk = grub_envblk_open (buf, offset);
-  if (! envblk)
-    {
-      grub_free (buf);
-      grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
-      return 0;
-    }
-
-  return envblk;
-}
-
-struct grub_env_whitelist
-{
-  grub_size_t len;
-  char **list;
-};
-typedef struct grub_env_whitelist grub_env_whitelist_t;
-
-static int
-test_whitelist_membership (const char* name,
-                           const grub_env_whitelist_t* whitelist)
-{
-  grub_size_t i;
-
-  for (i = 0; i < whitelist->len; i++)
-    if (grub_strcmp (name, whitelist->list[i]) == 0)
-      return 1;  /* found it */
-
-  return 0;  /* not found */
-}
-
-/* Helper for grub_cmd_load_env.  */
-static int
-set_var (const char *name, const char *value, void *whitelist)
-{
-  if (! whitelist)
-    {
-      grub_env_set (name, value);
-      return 0;
-    }
-
-  if (test_whitelist_membership (name,
-                                (const grub_env_whitelist_t *) whitelist))
-    grub_env_set (name, value);
-
-  return 0;
-}
-
 static grub_err_t
 grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)
 {
grub-core/commands/loadenv.h new file +93 -0
new file mode 100644
index 000000000..952f46121
@@ -0,0 +1,93 @@
+/* loadenv.c - command to load/save environment variable.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 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/>.
+ */
+
+static grub_envblk_t UNUSED
+read_envblk_file (grub_file_t file)
+{
+  grub_off_t offset = 0;
+  char *buf;
+  grub_size_t size = grub_file_size (file);
+  grub_envblk_t envblk;
+
+  buf = grub_malloc (size);
+  if (! buf)
+    return 0;
+
+  while (size > 0)
+    {
+      grub_ssize_t ret;
+
+      ret = grub_file_read (file, buf + offset, size);
+      if (ret <= 0)
+        {
+          grub_free (buf);
+          return 0;
+        }
+
+      size -= ret;
+      offset += ret;
+    }
+
+  envblk = grub_envblk_open (buf, offset);
+  if (! envblk)
+    {
+      grub_free (buf);
+      grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
+      return 0;
+    }
+
+  return envblk;
+}
+
+struct grub_env_whitelist
+{
+  grub_size_t len;
+  char **list;
+};
+typedef struct grub_env_whitelist grub_env_whitelist_t;
+
+static int UNUSED
+test_whitelist_membership (const char* name,
+                           const grub_env_whitelist_t* whitelist)
+{
+  grub_size_t i;
+
+  for (i = 0; i < whitelist->len; i++)
+    if (grub_strcmp (name, whitelist->list[i]) == 0)
+      return 1;  /* found it */
+
+  return 0;  /* not found */
+}
+
+/* Helper for grub_cmd_load_env.  */
+static int UNUSED
+set_var (const char *name, const char *value, void *whitelist)
+{
+  if (! whitelist)
+    {
+      grub_env_set (name, value);
+      return 0;
+    }
+
+  if (test_whitelist_membership (name,
+                                (const grub_env_whitelist_t *) whitelist))
+    grub_env_set (name, value);
+
+  return 0;
+}
grub-core/commands/menuentry.c +4 -1
index 720e6d8ea..b194123eb 100644
@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
                            char **classes, const char *id,
                            const char *users, const char *hotkey,
                            const char *prefix, const char *sourcecode,
-                           int submenu)
+                           int submenu, int *index, struct bls_entry *bls)
 {
   int menu_hotkey = 0;
   char **menu_args = NULL;
@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char
 **args,
   if (! menu_title)
     goto fail;
 
+  grub_dprintf ("menu", "id:\"%s\"\n", id);
+  grub_dprintf ("menu", "title:\"%s\"\n", menu_title);
   menu_id = grub_strdup (id ? : menu_title);
   if (! menu_id)
     goto fail;
+  grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id);
 
   /* Save argc, args to pass as parameters to block arg later. */
   menu_args = grub_calloc (argc + 1, sizeof (char *));
grub-core/commands/menuentry.c +5 -1
@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char
 **args,
   }
 
   /* Add the menu entry at the end of the list.  */
+  int ind=0;
   while (*last)
-    last = &(*last)->next;
+    {
+      ind++;
+      last = &(*last)->next;
+    }
 
   *last = grub_zalloc (sizeof (**last));
   if (! *last)
grub-core/commands/menuentry.c +3 -0
@@ -188,8 +195,11 @@ grub_normal_add_menu_entry (int argc, const char
 **args,
   (*last)->args = menu_args;
   (*last)->sourcecode = menu_sourcecode;
   (*last)->submenu = submenu;
+  (*last)->bls = bls;
 
   menu->size++;
+  if (index)
+    *index = ind;
   return GRUB_ERR_NONE;
 

fail:

grub-core/commands/menuentry.c +2 -1
@@ -286,7 +296,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int
 argc, char **args)
                                       users,
                                       ctxt->state[2].arg, 0,
                                       ctxt->state[3].arg,
-                                      ctxt->extcmd->cmd->name[0] == 's');
+                                      ctxt->extcmd->cmd->name[0] == 's',
+                                      NULL, NULL);
 
   src = args[argc - 1];
   args[argc - 1] = NULL;
grub-core/commands/menuentry.c +2 -1
@@ -303,7 +314,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int
 argc, char **args)
                                  ctxt->state[0].args, ctxt->state[4].arg,
                                  users,
                                  ctxt->state[2].arg, prefix, src + 1,
-                                 ctxt->extcmd->cmd->name[0] == 's');
+                                 ctxt->extcmd->cmd->name[0] == 's', NULL,
+                                 NULL);
 
   src[len - 1] = ch;
   args[argc - 1] = src;
grub-core/normal/main.c +6 -0
index 08f48c71d..1317279c0 100644
@@ -21,6 +21,7 @@
 #include <grub/net.h>
 #include <grub/normal.h>
 #include <grub/dl.h>
+#include <grub/menu.h>
 #include <grub/misc.h>
 #include <grub/file.h>
 #include <grub/mm.h>
@@ -70,6 +71,11 @@ grub_normal_free_menu (grub_menu_t menu)
          grub_free (entry->args);
        }
 
+      if (entry->bls)
+       {
+         entry->bls->visible = 0;
+       }
+
       grub_free ((void *) entry->id);
       grub_free ((void *) entry->users);
       grub_free ((void *) entry->title);
include/grub/compiler.h +2 -0
index 0c5519387..441a9eca0 100644
@@ -56,4 +56,6 @@
 #  define CLANG_PREREQ(maj,min) 0
 #endif
 
+#define UNUSED __attribute__((__unused__))
+
 #endif /* ! GRUB_COMPILER_HEADER */
include/grub/menu.h +13 -0
index ee2b5e910..0acdc2aa6 100644
@@ -20,6 +20,16 @@
 #ifndef GRUB_MENU_HEADER
 #define GRUB_MENU_HEADER 1
 
+struct bls_entry
+{
+  struct bls_entry *next;
+  struct bls_entry *prev;
+  struct keyval **keyvals;
+  int nkeyvals;
+  char *filename;
+  int visible;
+};
+
 struct grub_menu_entry_class
 {
   char *name;
@@ -60,6 +70,9 @@ struct grub_menu_entry
 
   /* The next element.  */
   struct grub_menu_entry *next;
+
+  /* BLS used to populate the entry */
+  struct bls_entry *bls;
 };
 typedef struct grub_menu_entry *grub_menu_entry_t;
 
include/grub/normal.h +1 -1
index 218cbabcc..8839ad85a 100644
@@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char
 **args, char **classes,
                            const char *id,
                            const char *users, const char *hotkey,
                            const char *prefix, const char *sourcecode,
-                           int submenu);
+                           int submenu, int *index, struct bls_entry
 *bls);
 

grub_err_t
grub_normal_set_password (const char *user, const char *password);
--
2.46.1

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#20 lore raw

Re: [PATCH 11/20] blscfg: add blscfg module to parse Boot Loader Specification snippets

Quoted 2 lines · Vladimir 'phcoder' Serbinenko

This is already being reviewed in separate thread

I did not see a similar patch being reviewed before sending the series, so I will drop it. if possible, can you send the grub-devel archive link? I could not find it through google nor search string field at
https://lists.gnu.org/archive/html/grub-devel/

Quoted 1,663 lines · Leo Sandoval
Quoted 1,661 lines

From: Peter Jones <[email protected]>

The BootLoaderSpec (BLS) defines a scheme where different bootloaders can share a format for boot items and a configuration directory that accepts these common configurations as drop-in files.

---
 grub-core/Makefile.core.def    |   11 +
 grub-core/commands/blscfg.c    | 1177 ++++++++++++++++++++++++++++++++
 grub-core/commands/legacycfg.c |    5 +-
 grub-core/commands/loadenv.c   |   77 +--
 grub-core/commands/loadenv.h   |   93 +++
 grub-core/commands/menuentry.c |   20 +-
 grub-core/normal/main.c        |    6 +
 include/grub/compiler.h        |    2 +
 include/grub/menu.h            |   13 +
 include/grub/normal.h          |    2 +-
 10 files changed, 1324 insertions(+), 82 deletions(-)
 create mode 100644 grub-core/commands/blscfg.c
 create mode 100644 grub-core/commands/loadenv.h
grub-core/Makefile.core.def +11 -0
index 0bffbfea9..47c0fc755 100644
@@ -842,6 +842,16 @@ module = {
   common = commands/blocklist.c;
 };
 
+module = {
+  name = blscfg;
+  common = commands/blscfg.c;
+  common = commands/loadenv.h;
+  enable = powerpc_ieee1275;
+  enable = efi;
+  enable = i386_pc;
+  enable = emu;
+};
+
 module = {
   name = boot;
   common = commands/boot.c;
@@ -1009,6 +1019,7 @@ module = {
 module = {
   name = loadenv;
   common = commands/loadenv.c;
+  common = commands/loadenv.h;
   common = lib/envblk.c;
 };
 
grub-core/commands/blscfg.c new file +97 -0
new file mode 100644
index 000000000..e907a6a5d
@@ -0,0 +1,1177 @@
+/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/
+
+/* bls.c - implementation of the boot loader spec */
+
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *
+ *  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/>.
+ */
+
+#include <grub/list.h>
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/dl.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/fs.h>
+#include <grub/env.h>
+#include <grub/file.h>
+#include <grub/normal.h>
+#include <grub/lib/envblk.h>
+
+#include <stdbool.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#include "loadenv.h"
+
+#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
+#ifdef GRUB_MACHINE_EMU
+#define GRUB_BOOT_DEVICE "/boot"
+#else
+#define GRUB_BOOT_DEVICE "($root)"
+#endif
+
+struct keyval
+{
+  const char *key;
+  char *val;
+};
+
+static struct bls_entry *entries = NULL;
+
+#define FOR_BLS_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries)
+
+static int bls_add_keyval(struct bls_entry *entry, char *key, char *val)
+{
+  char *k, *v;
+  struct keyval **kvs, *kv;
+  int new_n = entry->nkeyvals + 1;
+
+  kvs = grub_realloc (entry->keyvals, new_n * sizeof (struct keyval *));
+  if (!kvs)
+    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                      "couldn't find space for BLS entry");
+  entry->keyvals = kvs;
+
+  kv = grub_malloc (sizeof (struct keyval));
+  if (!kv)
+    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                      "couldn't find space for BLS entry");
+
+  k = grub_strdup (key);
+  if (!k)
+    {
+      grub_free (kv);
+      return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                        "couldn't find space for BLS entry");
+    }
+
+  v = grub_strdup (val);
+  if (!v)
+    {
+      grub_free (k);
+      grub_free (kv);
+      return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                        "couldn't find space for BLS entry");
+    }
+
+  kv->key = k;
+  kv->val = v;
+
+  entry->keyvals[entry->nkeyvals] = kv;
+  grub_dprintf("blscfg", "new keyval at %p:%s:%s\n",

entry->keyvals[entry->nkeyvals], k, v);

grub-core/commands/blscfg.c new file +6 -0
+  entry->nkeyvals = new_n;
+
+  return 0;
+}
+
+/* Find they value of the key named by keyname.  If there are allowed to

be
+ * more than one, pass a pointer to an int set to -1 the first time, and pass
+ * the same pointer through each time after, and it'll return them in sorted
+ * order as defined in the BLS fragment file */
+static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last)

grub-core/commands/blscfg.c new file +57 -0
+{
+  int idx, start = 0;
+  struct keyval *kv = NULL;
+
+  if (last)
+    start = *last + 1;
+
+  for (idx = start; idx < entry->nkeyvals; idx++) {
+    kv = entry->keyvals[idx];
+
+    if (!grub_strcmp (keyname, kv->key))
+      break;
+  }
+
+  if (idx == entry->nkeyvals) {
+    if (last)
+      *last = -1;
+    return NULL;
+  }
+
+  if (last)
+    *last = idx;
+
+  return kv->val;
+}
+
+#define goto_return(x) ({ ret = (x); goto finish; })
+
+/* compare alpha and numeric segments of two versions */
+/* return 1: a is newer than b */
+/*        0: a and b are the same version */
+/*       -1: b is newer than a */
+static int vercmp(const char * a, const char * b)
+{
+    char oldch1, oldch2;
+    char *abuf, *bbuf;
+    char *str1, *str2;
+    char * one, * two;
+    int rc;
+    int isnum;
+    int ret = 0;
+
+    grub_dprintf("blscfg", "%s comparing %s and %s\n", __func__, a, b);
+    if (!grub_strcmp(a, b))
+           return 0;
+
+    abuf = grub_malloc(grub_strlen(a) + 1);
+    bbuf = grub_malloc(grub_strlen(b) + 1);
+    str1 = abuf;
+    str2 = bbuf;
+    grub_strcpy(str1, a);
+    grub_strcpy(str2, b);
+
+    one = str1;
+    two = str2;
+
+    /* loop through each version segment of str1 and str2 and compare

them */

grub-core/commands/blscfg.c new file +2 -0
+    while (*one || *two) {
+       while (*one && !grub_isalnum(*one) && *one != '~' && *one != '+')

one++;
+ while (*two && !grub_isalnum(*two) && *two != '~' && *two != '+')
two++;

grub-core/commands/blscfg.c new file +26 -0
+
+       /* handle the tilde separator, it sorts before everything else */
+       if (*one == '~' || *two == '~') {
+           if (*one != '~') goto_return (1);
+           if (*two != '~') goto_return (-1);
+           one++;
+           two++;
+           continue;
+       }
+
+       /*
+        * Handle plus separator. Concept is the same as tilde,
+        * except that if one of the strings ends (base version),
+        * the other is considered as higher version.
+        */
+       if (*one == '+' || *two == '+') {
+           if (!*one) return -1;
+           if (!*two) return 1;
+           if (*one != '+') goto_return (1);
+           if (*two != '+') goto_return (-1);
+           one++;
+           two++;
+           continue;
+       }
+
+       /* If we ran to the end of either, we are finished with the loop

*/

grub-core/commands/blscfg.c new file +7 -0
+       if (!(*one && *two)) break;
+
+       str1 = one;
+       str2 = two;
+
+       /* grab first completely alpha or completely numeric segment */
+       /* leave one and two pointing to the start of the alpha or

numeric */

grub-core/commands/blscfg.c new file +19 -0
+       /* segment and walk str1 and str2 to end of segment */
+       if (grub_isdigit(*str1)) {
+           while (*str1 && grub_isdigit(*str1)) str1++;
+           while (*str2 && grub_isdigit(*str2)) str2++;
+           isnum = 1;
+       } else {
+           while (*str1 && grub_isalpha(*str1)) str1++;
+           while (*str2 && grub_isalpha(*str2)) str2++;
+           isnum = 0;
+       }
+
+       /* save character at the end of the alpha or numeric segment */
+       /* so that they can be restored after the comparison */
+       oldch1 = *str1;
+       *str1 = '\0';
+       oldch2 = *str2;
+       *str2 = '\0';
+
+       /* this cannot happen, as we previously tested to make sure that

*/

grub-core/commands/blscfg.c new file +14 -0
+       /* the first string has a non-null segment */
+       if (one == str1) goto_return(-1);       /* arbitrary */
+
+       /* take care of the case where the two version segments are */
+       /* different types: one numeric, the other alpha (i.e. empty) */
+       /* numeric segments are always newer than alpha segments */
+       /* XXX See patch #60884 (and details) from bugzilla #50977. */
+       if (two == str2) goto_return (isnum ? 1 : -1);
+
+       if (isnum) {
+           grub_size_t onelen, twolen;
+           /* this used to be done by converting the digit segments */
+           /* to ints using atoi() - it's changed because long  */
+           /* digit segments can overflow an int - this should fix that.

*/

grub-core/commands/blscfg.c new file +13 -0
+
+           /* throw away any leading zeros - it's a number, right? */
+           while (*one == '0') one++;
+           while (*two == '0') two++;
+
+           /* whichever number has more digits wins */
+           onelen = grub_strlen(one);
+           twolen = grub_strlen(two);
+           if (onelen > twolen) goto_return (1);
+           if (twolen > onelen) goto_return (-1);
+       }
+
+       /* grub_strcmp will return which one is greater - even if the two

*/

grub-core/commands/blscfg.c new file +15 -0
+       /* segments are alpha or if they are numeric.  don't return  */
+       /* if they are equal because there might be more segments to */
+       /* compare */
+       rc = grub_strcmp(one, two);
+       if (rc) goto_return (rc < 1 ? -1 : 1);
+
+       /* restore character that was replaced by null above */
+       *str1 = oldch1;
+       one = str1;
+       *str2 = oldch2;
+       two = str2;
+    }
+
+    /* this catches the case where all numeric and alpha segments have */
+    /* compared identically but the segment sepparating characters were

*/

grub-core/commands/blscfg.c new file +67 -0
+    /* different */
+    if ((!*one) && (!*two)) goto_return (0);
+
+    /* whichever version still has characters left over wins */
+    if (!*one) goto_return (-1); else goto_return (1);
+
+finish:
+    grub_free (abuf);
+    grub_free (bbuf);
+    return ret;
+}
+
+/* returns name/version/release */
+/* NULL string pointer returned if nothing found */
+static void
+split_package_string (char *package_string, char **name,
+                     char **version, char **release)
+{
+  char *package_version, *package_release;
+
+  /* Release */
+  package_release = grub_strrchr (package_string, '-');
+
+  if (package_release != NULL)
+      *package_release++ = '\0';
+
+  *release = package_release;
+
+  if (name == NULL)
+    {
+      *version = package_string;
+    }
+  else
+    {
+      /* Version */
+      package_version = grub_strrchr(package_string, '-');
+
+      if (package_version != NULL)
+       *package_version++ = '\0';
+
+      *version = package_version;
+      /* Name */
+      *name = package_string;
+    }
+
+  /* Bubble up non-null values from release to name */
+  if (name != NULL && *name == NULL)
+    {
+      *name = (*version == NULL ? *release : *version);
+      *version = *release;
+      *release = NULL;
+    }
+  if (*version == NULL)
+    {
+      *version = *release;
+      *release = NULL;
+    }
+}
+
+static int
+split_cmp(char *nvr0, char *nvr1, int has_name)
+{
+  int ret = 0;
+  char *name0, *version0, *release0;
+  char *name1, *version1, *release1;
+
+  split_package_string(nvr0, has_name ? &name0 : NULL, &version0,

&release0);
+ split_package_string(nvr1, has_name ? &name1 : NULL, &version1, &release1);

grub-core/commands/blscfg.c new file +23 -0
+
+  if (has_name)
+    {
+      ret = vercmp(name0 == NULL ? "" : name0,
+                  name1 == NULL ? "" : name1);
+      if (ret != 0)
+       return ret;
+    }
+
+  ret = vercmp(version0 == NULL ? "" : version0,
+              version1 == NULL ? "" : version1);
+  if (ret != 0)
+    return ret;
+
+  ret = vercmp(release0 == NULL ? "" : release0,
+              release1 == NULL ? "" : release1);
+  return ret;
+}
+
+/* return 1: e0 is newer than e1 */
+/*        0: e0 and e1 are the same version */
+/*       -1: e1 is newer than e0 */
+static int bls_cmp(const struct bls_entry *e0, const struct bls_entry

*e1)

grub-core/commands/blscfg.c new file +31 -0
+{
+  char *id0, *id1;
+  int r;
+
+  id0 = grub_strdup(e0->filename);
+  id1 = grub_strdup(e1->filename);
+
+  r = split_cmp(id0, id1, 1);
+
+  grub_free(id0);
+  grub_free(id1);
+
+  return r;
+}
+
+static void list_add_tail(struct bls_entry *head, struct bls_entry *item)
+{
+  item->next = head;
+  if (head->prev)
+    head->prev->next = item;
+  item->prev = head->prev;
+  head->prev = item;
+}
+
+static int bls_add_entry(struct bls_entry *entry)
+{
+  struct bls_entry *e, *last = NULL;
+  int rc;
+
+  if (!entries) {
+    grub_dprintf ("blscfg", "Add entry with id \"%s\"\n",

entry->filename);

grub-core/commands/blscfg.c new file +12 -0
+    entries = entry;
+    return 0;
+  }
+
+  FOR_BLS_ENTRIES(e) {
+    rc = bls_cmp(entry, e);
+
+    if (!rc)
+      return GRUB_ERR_BAD_ARGUMENT;
+
+    if (rc == 1) {
+      grub_dprintf ("blscfg", "Add entry with id \"%s\"\n",

entry->filename);

grub-core/commands/blscfg.c new file +12 -0
+      list_add_tail (e, entry);
+      if (e == entries) {
+       entries = entry;
+       entry->prev = NULL;
+      }
+      return 0;
+    }
+    last = e;
+  }
+
+  if (last) {
+    grub_dprintf ("blscfg", "Add entry with id \"%s\"\n",

entry->filename);

grub-core/commands/blscfg.c new file +45 -0
+    last->next = entry;
+    entry->prev = last;
+  }
+
+  return 0;
+}
+
+struct read_entry_info {
+  const char *devid;
+  const char *dirname;
+  grub_file_t file;
+};
+
+static int read_entry (
+    const char *filename,
+    const struct grub_dirhook_info *dirhook_info UNUSED,
+    void *data)
+{
+  grub_size_t m = 0, n, clip = 0;
+  int rc = 0;
+  char *p = NULL;
+  grub_file_t f = NULL;
+  struct bls_entry *entry;
+  struct read_entry_info *info = (struct read_entry_info *)data;
+
+  grub_dprintf ("blscfg", "filename: \"%s\"\n", filename);
+
+  n = grub_strlen (filename);
+
+  if (info->file)
+    {
+      f = info->file;
+    }
+  else
+    {
+      if (filename[0] == '.')
+       return 0;
+
+      if (n <= 5)
+       return 0;
+
+      if (grub_strcmp (filename + n - 5, ".conf") != 0)
+       return 0;
+
+      p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname,

filename);

grub-core/commands/blscfg.c new file +115 -0
+
+      f = grub_file_open (p, GRUB_FILE_TYPE_CONFIG);
+      if (!f)
+       goto finish;
+    }
+
+  entry = grub_zalloc (sizeof (*entry));
+  if (!entry)
+    goto finish;
+
+  if (info->file)
+    {
+      char *slash;
+
+      if (n > 5 && !grub_strcmp (filename + n - 5, ".conf") == 0)
+       clip = 5;
+
+      slash = grub_strrchr (filename, '/');
+      if (!slash)
+       slash = grub_strrchr (filename, '\\');
+
+      while (*slash == '/' || *slash == '\\')
+       slash++;
+
+      m = slash ? slash - filename : 0;
+    }
+  else
+    {
+      m = 0;
+      clip = 5;
+    }
+  n -= m;
+
+  entry->filename = grub_strndup(filename + m, n - clip);
+  if (!entry->filename)
+    goto finish;
+
+  entry->filename[n - 5] = '\0';
+
+  for (;;)
+    {
+      char *buf;
+      char *separator;
+
+      buf = grub_file_getline (f);
+      if (!buf)
+       break;
+
+      while (buf && buf[0] && (buf[0] == ' ' || buf[0] == '\t'))
+       buf++;
+      if (buf[0] == '#')
+       continue;
+
+      separator = grub_strchr (buf, ' ');
+
+      if (!separator)
+       separator = grub_strchr (buf, '\t');
+
+      if (!separator || separator[1] == '\0')
+       {
+         grub_free (buf);
+         break;
+       }
+
+      separator[0] = '\0';
+
+      do {
+       separator++;
+      } while (*separator == ' ' || *separator == '\t');
+
+      rc = bls_add_keyval (entry, buf, separator);
+      grub_free (buf);
+      if (rc < 0)
+       break;
+    }
+
+    if (!rc)
+      bls_add_entry(entry);
+
+finish:
+  if (p)
+    grub_free (p);
+
+  if (f)
+    grub_file_close (f);
+
+  return 0;
+}
+
+static grub_envblk_t saved_env = NULL;
+
+static int UNUSED
+save_var (const char *name, const char *value, void *whitelist UNUSED)
+{
+  const char *val = grub_env_get (name);
+  grub_dprintf("blscfg", "saving \"%s\"\n", name);
+
+  if (val)
+    grub_envblk_set (saved_env, name, value);
+
+  return 0;
+}
+
+static int UNUSED
+unset_var (const char *name, const char *value UNUSED, void *whitelist)
+{
+  grub_dprintf("blscfg", "restoring \"%s\"\n", name);
+  if (! whitelist)
+    {
+      grub_env_unset (name);
+      return 0;
+    }
+
+  if (test_whitelist_membership (name,
+                                (const grub_env_whitelist_t *)

whitelist))

grub-core/commands/blscfg.c new file +6 -0
+    grub_env_unset (name);
+
+  return 0;
+}
+
+static char **bls_make_list (struct bls_entry *entry, const char *key,

int *num)

grub-core/commands/blscfg.c new file +42 -0
+{
+  int last = -1;
+  char *val;
+
+  int nlist = 0;
+  char **list = NULL;
+
+  list = grub_malloc (sizeof (char *));
+  if (!list)
+    return NULL;
+  list[0] = NULL;
+
+  while (1)
+    {
+      char **new;
+
+      val = bls_get_val (entry, key, &last);
+      if (!val)
+       break;
+
+      new = grub_realloc (list, (nlist + 2) * sizeof (char *));
+      if (!new)
+       break;
+
+      list = new;
+      list[nlist++] = val;
+      list[nlist] = NULL;
+  }
+
+  if (!nlist)
+    {
+      grub_free (list);
+      return NULL;
+    }
+
+  if (num)
+    *num = nlist;
+
+  return list;
+}
+
+static char *field_append(bool is_var, char *buffer, const char *start,

const char *end)

grub-core/commands/blscfg.c new file +15 -0
+{
+  char *tmp = grub_strndup(start, end - start + 1);
+  const char *field = tmp;
+  int term = is_var ? 2 : 1;
+
+  if (is_var) {
+    field = grub_env_get (tmp);
+    if (!field)
+      return buffer;
+  }
+
+  if (!buffer)
+    buffer = grub_zalloc (grub_strlen(field) + term);
+  else
+    buffer = grub_realloc (buffer, grub_strlen(buffer) +

grub_strlen(field) + term);

grub-core/commands/blscfg.c new file +116 -0
+
+  if (!buffer)
+    return NULL;
+
+  tmp = buffer + grub_strlen(buffer);
+  tmp = grub_stpcpy (tmp, field);
+
+  if (is_var)
+      tmp = grub_stpcpy (tmp, " ");
+
+  return buffer;
+}
+
+static char *expand_val(const char *value)
+{
+  char *buffer = NULL;
+  const char *start = value;
+  const char *end = value;
+  bool is_var = false;
+
+  if (!value)
+    return NULL;
+
+  while (*value) {
+    if (*value == '$') {
+      if (start != end) {
+       buffer = field_append(is_var, buffer, start, end);
+       if (!buffer)
+         return NULL;
+      }
+
+      is_var = true;
+      start = value + 1;
+    } else if (is_var) {
+      if (!grub_isalnum(*value) && *value != '_') {
+       buffer = field_append(is_var, buffer, start, end);
+       is_var = false;
+       start = value;
+       if (*start == ' ')
+         start++;
+      }
+    }
+
+    end = value;
+    value++;
+  }
+
+  if (start != end) {
+    buffer = field_append(is_var, buffer, start, end);
+    if (!buffer)
+      return NULL;
+  }
+
+  return buffer;
+}
+
+static char **early_initrd_list (const char *initrd)
+{
+  int nlist = 0;
+  char **list = NULL;
+  char *separator;
+
+  while ((separator = grub_strchr (initrd, ' ')))
+    {
+      list = grub_realloc (list, (nlist + 2) * sizeof (char *));
+      if (!list)
+        return NULL;
+
+      list[nlist++] = grub_strndup(initrd, separator - initrd);
+      list[nlist] = NULL;
+      initrd = separator + 1;
+  }
+
+  list = grub_realloc (list, (nlist + 2) * sizeof (char *));
+  if (!list)
+    return NULL;
+
+  list[nlist++] = grub_strndup(initrd, grub_strlen(initrd));
+  list[nlist] = NULL;
+
+  return list;
+}
+
+static void create_entry (struct bls_entry *entry)
+{
+  int argc = 0;
+  const char **argv = NULL;
+
+  char *title = NULL;
+  char *clinux = NULL;
+  char *options = NULL;
+  char **initrds = NULL;
+  char *initrd = NULL;
+  const char *early_initrd = NULL;
+  char **early_initrds = NULL;
+  char *initrd_prefix = NULL;
+  char *devicetree = NULL;
+  char *dt = NULL;
+  char *id = entry->filename;
+  char *dotconf = id;
+  char *hotkey = NULL;
+
+  char *users = NULL;
+  char **classes = NULL;
+
+  char **args = NULL;
+
+  char *src = NULL;
+  int i, index;
+  bool add_dt_prefix = false;
+
+  grub_dprintf("blscfg", "%s got here\n", __func__);
+  clinux = bls_get_val (entry, "linux", NULL);
+  if (!clinux)
+    {
+      grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n",

entry->filename);

grub-core/commands/blscfg.c new file +44 -0
+      goto finish;
+    }
+
+  /*
+   * strip the ".conf" off the end before we make it our "id" field.
+   */
+  do
+    {
+      dotconf = grub_strstr(dotconf, ".conf");
+    } while (dotconf != NULL && dotconf[5] != '\0');
+  if (dotconf)
+    dotconf[0] = '\0';
+
+  title = bls_get_val (entry, "title", NULL);
+  options = expand_val (bls_get_val (entry, "options", NULL));
+
+  if (!options)
+    options = expand_val (grub_env_get("default_kernelopts"));
+
+  initrds = bls_make_list (entry, "initrd", NULL);
+
+  devicetree = expand_val (bls_get_val (entry, "devicetree", NULL));
+
+  if (!devicetree)
+    {
+      devicetree = expand_val (grub_env_get("devicetree"));
+      add_dt_prefix = true;
+    }
+
+  hotkey = bls_get_val (entry, "grub_hotkey", NULL);
+  users = expand_val (bls_get_val (entry, "grub_users", NULL));
+  classes = bls_make_list (entry, "grub_class", NULL);
+  args = bls_make_list (entry, "grub_arg", &argc);
+
+  argc += 1;
+  argv = grub_malloc ((argc + 1) * sizeof (char *));
+  argv[0] = title ? title : clinux;
+  for (i = 1; i < argc; i++)
+    argv[i] = args[i-1];
+  argv[argc] = NULL;
+
+  early_initrd = grub_env_get("early_initrd");
+
+  grub_dprintf ("blscfg", "adding menu entry for \"%s\" with id

\"%s\"\n",

grub-core/commands/blscfg.c new file +14 -0
+               title, id);
+  if (early_initrd)
+    {
+      early_initrds = early_initrd_list(early_initrd);
+      if (!early_initrds)
+      {
+       grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+       goto finish;
+      }
+
+      if (initrds != NULL && initrds[0] != NULL)
+       {
+         initrd_prefix = grub_strrchr (initrds[0], '/');
+         initrd_prefix = grub_strndup(initrds[0], initrd_prefix -

initrds[0] + 1);

grub-core/commands/blscfg.c new file +5 -0
+       }
+      else
+       {
+         initrd_prefix = grub_strrchr (clinux, '/');
+         initrd_prefix = grub_strndup(clinux, initrd_prefix - clinux +

1);

grub-core/commands/blscfg.c new file +35 -0
+       }
+
+      if (!initrd_prefix)
+       {
+         grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+         goto finish;
+       }
+    }
+
+  if (early_initrds || initrds)
+    {
+      int initrd_size = sizeof ("initrd");
+      char *tmp;
+
+      for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++)
+       initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \
+                      + grub_strlen(initrd_prefix)  \
+                      + grub_strlen (early_initrds[i]) + 1;
+
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
+       initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \
+                      + grub_strlen (initrds[i]) + 1;
+      initrd_size += 1;
+
+      initrd = grub_malloc (initrd_size);
+      if (!initrd)
+       {
+         grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+         goto finish;
+       }
+
+      tmp = grub_stpcpy(initrd, "initrd");
+      for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++)
+       {
+         grub_dprintf ("blscfg", "adding early initrd %s\n",

early_initrds[i]);

grub-core/commands/blscfg.c new file +32 -0
+         tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+         tmp = grub_stpcpy (tmp, initrd_prefix);
+         tmp = grub_stpcpy (tmp, early_initrds[i]);
+         grub_free(early_initrds[i]);
+       }
+
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
+       {
+         grub_dprintf ("blscfg", "adding initrd %s\n", initrds[i]);
+         tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+         tmp = grub_stpcpy (tmp, initrds[i]);
+       }
+      tmp = grub_stpcpy (tmp, "\n");
+    }
+
+  if (devicetree)
+    {
+      char *prefix = NULL;
+      int dt_size;
+
+      if (add_dt_prefix)
+       {
+         prefix = grub_strrchr (clinux, '/');
+         prefix = grub_strndup(clinux, prefix - clinux + 1);
+         if (!prefix)
+           {
+             grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+             goto finish;
+           }
+       }
+
+      dt_size = sizeof("devicetree " GRUB_BOOT_DEVICE) +

grub_strlen(devicetree) + 1;

grub-core/commands/blscfg.c new file +27 -0
+
+      if (add_dt_prefix)
+       {
+         dt_size += grub_strlen(prefix);
+       }
+
+      dt = grub_malloc (dt_size);
+      if (!dt)
+        {
+          grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+        goto finish;
+        }
+      char *tmp = dt;
+      tmp = grub_stpcpy (dt, "devicetree");
+      tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+      if (add_dt_prefix)
+        tmp = grub_stpcpy (tmp, prefix);
+      tmp = grub_stpcpy (tmp, devicetree);
+      tmp = grub_stpcpy (tmp, "\n");
+
+      grub_free(prefix);
+    }
+
+  grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id);
+
+  const char *sdval = grub_env_get("save_default");
+  bool savedefault = ((NULL != sdval) && (grub_strcmp(sdval, "true") ==

0));

grub-core/commands/blscfg.c new file +7 -0
+  src = grub_xasprintf ("%sload_video\n"
+                       "set gfxpayload=keep\n"
+                       "insmod gzio\n"
+                       "linux %s%s%s%s\n"
+                       "%s%s",
+                       savedefault ? "savedefault\n" : "",
+                       GRUB_BOOT_DEVICE, clinux, options ? " " : "",

options ? options : "",

grub-core/commands/blscfg.c new file +3 -0
+                       initrd ? initrd : "", dt ? dt : "");
+
+  grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey,

NULL, src, 0, &index, entry);

grub-core/commands/blscfg.c new file +65 -0
+  grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id);
+
+finish:
+  grub_free (dt);
+  grub_free (initrd);
+  grub_free (initrd_prefix);
+  grub_free (early_initrds);
+  grub_free (devicetree);
+  grub_free (initrds);
+  grub_free (options);
+  grub_free (classes);
+  grub_free (args);
+  grub_free (argv);
+  grub_free (src);
+}
+
+struct find_entry_info {
+       const char *dirname;
+       const char *devid;
+       grub_device_t dev;
+       grub_fs_t fs;
+};
+
+/*
+ * info: the filesystem object the file is on.
+ */
+static int find_entry (struct find_entry_info *info)
+{
+  struct read_entry_info read_entry_info;
+  grub_fs_t blsdir_fs = NULL;
+  grub_device_t blsdir_dev = NULL;
+  const char *blsdir = info->dirname;
+  int fallback = 0;
+  int r = 0;
+
+  if (!blsdir) {
+    blsdir = grub_env_get ("blsdir");
+    if (!blsdir)
+      blsdir = GRUB_BLS_CONFIG_PATH;
+  }
+
+  read_entry_info.file = NULL;
+  read_entry_info.dirname = blsdir;
+
+  grub_dprintf ("blscfg", "scanning blsdir: %s\n", blsdir);
+
+  blsdir_dev = info->dev;
+  blsdir_fs = info->fs;
+  read_entry_info.devid = info->devid;
+
+read_fallback:
+  r = blsdir_fs->fs_dir (blsdir_dev, read_entry_info.dirname, read_entry,
+                        &read_entry_info);
+  if (r != 0) {
+      grub_dprintf ("blscfg", "read_entry returned error\n");
+      grub_err_t e;
+      do
+       {
+         e = grub_error_pop();
+       } while (e);
+  }
+
+  if (r && !info->dirname && !fallback) {
+    read_entry_info.dirname = "/boot" GRUB_BLS_CONFIG_PATH;
+    grub_dprintf ("blscfg", "Entries weren't found in %s, fallback to

%s\n",

grub-core/commands/blscfg.c new file +43 -0
+                 blsdir, read_entry_info.dirname);
+    fallback = 1;
+    goto read_fallback;
+  }
+
+  return 0;
+}
+
+static grub_err_t
+bls_load_entries (const char *path)
+{
+  grub_size_t len;
+  grub_fs_t fs;
+  grub_device_t dev;
+  static grub_err_t r;
+  const char *devid = NULL;
+  char *blsdir = NULL;
+  struct find_entry_info info = {
+      .dev = NULL,
+      .fs = NULL,
+      .dirname = NULL,
+  };
+  struct read_entry_info rei = {
+      .devid = NULL,
+      .dirname = NULL,
+  };
+
+  if (path) {
+    len = grub_strlen (path);
+    if (grub_strcmp (path + len - 5, ".conf") == 0) {
+      rei.file = grub_file_open (path, GRUB_FILE_TYPE_CONFIG);
+      if (!rei.file)
+       return grub_errno;
+      /*
+       * read_entry() closes the file
+       */
+      return read_entry(path, NULL, &rei);
+    } else if (path[0] == '(') {
+      devid = path + 1;
+
+      blsdir = grub_strchr (path, ')');
+      if (!blsdir)
+       return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Filepath isn't

correct"));

grub-core/commands/blscfg.c new file +74 -0
+
+      *blsdir = '\0';
+      blsdir = blsdir + 1;
+    }
+  }
+
+  if (!devid) {
+#ifdef GRUB_MACHINE_EMU
+    devid = "host";
+#else
+    devid = grub_env_get ("root");
+#endif
+    if (!devid)
+      return grub_error (GRUB_ERR_FILE_NOT_FOUND,
+                        N_("variable `%s' isn't set"), "root");
+  }
+
+  grub_dprintf ("blscfg", "opening %s\n", devid);
+  dev = grub_device_open (devid);
+  if (!dev)
+    return grub_errno;
+
+  grub_dprintf ("blscfg", "probing fs\n");
+  fs = grub_fs_probe (dev);
+  if (!fs)
+    {
+      r = grub_errno;
+      goto finish;
+    }
+
+  info.dirname = blsdir;
+  info.devid = devid;
+  info.dev = dev;
+  info.fs = fs;
+  find_entry(&info);
+
+finish:
+  if (dev)
+    grub_device_close (dev);
+
+  return r;
+}
+
+static bool
+is_default_entry(const char *def_entry, struct bls_entry *entry, int idx)
+{
+  const char *title;
+  int def_idx;
+
+  if (!def_entry)
+    return false;
+
+  if (grub_strcmp(def_entry, entry->filename) == 0)
+    return true;
+
+  title = bls_get_val(entry, "title", NULL);
+
+  if (title && grub_strcmp(def_entry, title) == 0)
+    return true;
+
+  def_idx = (int)grub_strtol(def_entry, NULL, 0);
+  if (grub_errno == GRUB_ERR_BAD_NUMBER) {
+    grub_errno = GRUB_ERR_NONE;
+    return false;
+  }
+
+  if (def_idx == idx)
+    return true;
+
+  return false;
+}
+
+static grub_err_t
+bls_create_entries (bool show_default, bool show_non_default, char

*entry_id)

grub-core/commands/blscfg.c new file +68 -0
+{
+  const char *def_entry = NULL;
+  struct bls_entry *entry = NULL;
+  int idx = 0;
+
+  def_entry = grub_env_get("default");
+
+  grub_dprintf ("blscfg", "%s Creating entries from bls\n", __func__);
+  FOR_BLS_ENTRIES(entry) {
+    if (entry->visible) {
+      idx++;
+      continue;
+    }
+
+    if ((show_default && is_default_entry(def_entry, entry, idx)) ||
+       (show_non_default && !is_default_entry(def_entry, entry, idx)) ||
+       (entry_id && grub_strcmp(entry_id, entry->filename) == 0)) {
+      create_entry(entry);
+      entry->visible = 1;
+    }
+    idx++;
+  }
+
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED,
+                int argc, char **args)
+{
+  grub_err_t r;
+  char *path = NULL;
+  char *entry_id = NULL;
+  bool show_default = true;
+  bool show_non_default = true;
+
+  if (argc == 1) {
+    if (grub_strcmp (args[0], "default") == 0) {
+      show_non_default = false;
+    } else if (grub_strcmp (args[0], "non-default") == 0) {
+      show_default = false;
+    } else if (args[0][0] == '(') {
+      path = args[0];
+    } else {
+      entry_id = args[0];
+      show_default = false;
+      show_non_default = false;
+    }
+  }
+
+  r = bls_load_entries(path);
+  if (r)
+    return r;
+
+  return bls_create_entries(show_default, show_non_default, entry_id);
+}
+
+static grub_extcmd_t cmd;
+static grub_extcmd_t oldcmd;
+
+GRUB_MOD_INIT(blscfg)
+{
+  grub_dprintf("blscfg", "%s got here\n", __func__);
+  cmd = grub_register_extcmd ("blscfg",
+                             grub_cmd_blscfg,
+                             0,
+                             NULL,
+                             N_("Import Boot Loader Specification

snippets."),

grub-core/commands/blscfg.c new file +6 -0
+                             NULL);
+  oldcmd = grub_register_extcmd ("bls_import",
+                                grub_cmd_blscfg,
+                                0,
+                                NULL,
+                                N_("Import Boot Loader Specification

snippets."),

grub-core/commands/blscfg.c new file +8 -0
+                                NULL);
+}
+
+GRUB_MOD_FINI(blscfg)
+{
+  grub_unregister_extcmd (cmd);
+  grub_unregister_extcmd (oldcmd);
+}
grub-core/commands/legacycfg.c +3 -2
index e9e9d94ef..2c5d1a0ef 100644
@@ -143,7 +143,7 @@ legacy_file (const char *filename)
            args[0] = oldname;
            grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy",
                                        NULL, NULL,
-                                       entrysrc, 0);
+                                       entrysrc, 0, NULL, NULL);
            grub_free (args);
            entrysrc[0] = 0;
            grub_free (oldname);
@@ -205,7 +205,8 @@ legacy_file (const char *filename)
        }
       args[0] = entryname;
       grub_normal_add_menu_entry (1, args, NULL, NULL, NULL,
-                                 NULL, NULL, entrysrc, 0);
+                                 NULL, NULL, entrysrc, 0, NULL,
+                                 NULL);
       grub_free (args);
     }
 
grub-core/commands/loadenv.c +2 -75
index 166445849..dfcb19e0f 100644
@@ -28,6 +28,8 @@
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
 
+#include "loadenv.h"
+
 GRUB_MOD_LICENSE ("GPLv3+");
 
 static const struct grub_arg_option options[] =
@@ -79,81 +81,6 @@ open_envblk_file (char *filename,
   return file;
 }
 
-static grub_envblk_t
-read_envblk_file (grub_file_t file)
-{
-  grub_off_t offset = 0;
-  char *buf;
-  grub_size_t size = grub_file_size (file);
-  grub_envblk_t envblk;
-
-  buf = grub_malloc (size);
-  if (! buf)
-    return 0;
-
-  while (size > 0)
-    {
-      grub_ssize_t ret;
-
-      ret = grub_file_read (file, buf + offset, size);
-      if (ret <= 0)
-        {
-          grub_free (buf);
-          return 0;
-        }
-
-      size -= ret;
-      offset += ret;
-    }
-
-  envblk = grub_envblk_open (buf, offset);
-  if (! envblk)
-    {
-      grub_free (buf);
-      grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
-      return 0;
-    }
-
-  return envblk;
-}
-
-struct grub_env_whitelist
-{
-  grub_size_t len;
-  char **list;
-};
-typedef struct grub_env_whitelist grub_env_whitelist_t;
-
-static int
-test_whitelist_membership (const char* name,
-                           const grub_env_whitelist_t* whitelist)
-{
-  grub_size_t i;
-
-  for (i = 0; i < whitelist->len; i++)
-    if (grub_strcmp (name, whitelist->list[i]) == 0)
-      return 1;  /* found it */
-
-  return 0;  /* not found */
-}
-
-/* Helper for grub_cmd_load_env.  */
-static int
-set_var (const char *name, const char *value, void *whitelist)
-{
-  if (! whitelist)
-    {
-      grub_env_set (name, value);
-      return 0;
-    }
-
-  if (test_whitelist_membership (name,
-                                (const grub_env_whitelist_t *)
 whitelist))
-    grub_env_set (name, value);
-
-  return 0;
-}
-
 static grub_err_t
 grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)

{

grub-core/commands/loadenv.h new file +89 -0
new file mode 100644
index 000000000..952f46121
@@ -0,0 +1,93 @@
+/* loadenv.c - command to load/save environment variable.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 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/>.
+ */
+
+static grub_envblk_t UNUSED
+read_envblk_file (grub_file_t file)
+{
+  grub_off_t offset = 0;
+  char *buf;
+  grub_size_t size = grub_file_size (file);
+  grub_envblk_t envblk;
+
+  buf = grub_malloc (size);
+  if (! buf)
+    return 0;
+
+  while (size > 0)
+    {
+      grub_ssize_t ret;
+
+      ret = grub_file_read (file, buf + offset, size);
+      if (ret <= 0)
+        {
+          grub_free (buf);
+          return 0;
+        }
+
+      size -= ret;
+      offset += ret;
+    }
+
+  envblk = grub_envblk_open (buf, offset);
+  if (! envblk)
+    {
+      grub_free (buf);
+      grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
+      return 0;
+    }
+
+  return envblk;
+}
+
+struct grub_env_whitelist
+{
+  grub_size_t len;
+  char **list;
+};
+typedef struct grub_env_whitelist grub_env_whitelist_t;
+
+static int UNUSED
+test_whitelist_membership (const char* name,
+                           const grub_env_whitelist_t* whitelist)
+{
+  grub_size_t i;
+
+  for (i = 0; i < whitelist->len; i++)
+    if (grub_strcmp (name, whitelist->list[i]) == 0)
+      return 1;  /* found it */
+
+  return 0;  /* not found */
+}
+
+/* Helper for grub_cmd_load_env.  */
+static int UNUSED
+set_var (const char *name, const char *value, void *whitelist)
+{
+  if (! whitelist)
+    {
+      grub_env_set (name, value);
+      return 0;
+    }
+
+  if (test_whitelist_membership (name,
+                                (const grub_env_whitelist_t *)

whitelist))

grub-core/commands/loadenv.h new file +4 -0
+    grub_env_set (name, value);
+
+  return 0;
+}
grub-core/commands/menuentry.c +1 -1
index 720e6d8ea..b194123eb 100644
@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
                            char **classes, const char *id,
                            const char *users, const char *hotkey,
                            const char *prefix, const char *sourcecode,
-                           int submenu)
+                           int submenu, int *index, struct bls_entry
 *bls)
 {
   int menu_hotkey = 0;
   char **menu_args = NULL;
grub-core/commands/menuentry.c +3 -0
@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char
 **args,
   if (! menu_title)
     goto fail;
 
+  grub_dprintf ("menu", "id:\"%s\"\n", id);
+  grub_dprintf ("menu", "title:\"%s\"\n", menu_title);
   menu_id = grub_strdup (id ? : menu_title);
   if (! menu_id)
     goto fail;
+  grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id);
 
   /* Save argc, args to pass as parameters to block arg later. */
   menu_args = grub_calloc (argc + 1, sizeof (char *));
grub-core/commands/menuentry.c +5 -1
@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char
 **args,
   }
 
   /* Add the menu entry at the end of the list.  */
+  int ind=0;
   while (*last)
-    last = &(*last)->next;
+    {
+      ind++;
+      last = &(*last)->next;
+    }
 
   *last = grub_zalloc (sizeof (**last));
   if (! *last)
grub-core/commands/menuentry.c +3 -0
@@ -188,8 +195,11 @@ grub_normal_add_menu_entry (int argc, const char
 **args,
   (*last)->args = menu_args;
   (*last)->sourcecode = menu_sourcecode;
   (*last)->submenu = submenu;
+  (*last)->bls = bls;
 
   menu->size++;
+  if (index)
+    *index = ind;
   return GRUB_ERR_NONE;
 

fail:

grub-core/commands/menuentry.c +2 -1
@@ -286,7 +296,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int
 argc, char **args)
                                       users,
                                       ctxt->state[2].arg, 0,
                                       ctxt->state[3].arg,
-                                      ctxt->extcmd->cmd->name[0] == 's');
+                                      ctxt->extcmd->cmd->name[0] == 's',
+                                      NULL, NULL);
 
   src = args[argc - 1];
   args[argc - 1] = NULL;
grub-core/commands/menuentry.c +2 -1
@@ -303,7 +314,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int
 argc, char **args)
                                  ctxt->state[0].args, ctxt->state[4].arg,
                                  users,
                                  ctxt->state[2].arg, prefix, src + 1,
-                                 ctxt->extcmd->cmd->name[0] == 's');
+                                 ctxt->extcmd->cmd->name[0] == 's', NULL,
+                                 NULL);
 
   src[len - 1] = ch;
   args[argc - 1] = src;
grub-core/normal/main.c +6 -0
index 08f48c71d..1317279c0 100644
@@ -21,6 +21,7 @@
 #include <grub/net.h>
 #include <grub/normal.h>
 #include <grub/dl.h>
+#include <grub/menu.h>
 #include <grub/misc.h>
 #include <grub/file.h>
 #include <grub/mm.h>
@@ -70,6 +71,11 @@ grub_normal_free_menu (grub_menu_t menu)
          grub_free (entry->args);
        }
 
+      if (entry->bls)
+       {
+         entry->bls->visible = 0;
+       }
+
       grub_free ((void *) entry->id);
       grub_free ((void *) entry->users);
       grub_free ((void *) entry->title);
include/grub/compiler.h +2 -0
index 0c5519387..441a9eca0 100644
@@ -56,4 +56,6 @@
 #  define CLANG_PREREQ(maj,min) 0
 #endif
 
+#define UNUSED __attribute__((__unused__))
+
 #endif /* ! GRUB_COMPILER_HEADER */
include/grub/menu.h +13 -0
index ee2b5e910..0acdc2aa6 100644
@@ -20,6 +20,16 @@
 #ifndef GRUB_MENU_HEADER
 #define GRUB_MENU_HEADER 1
 
+struct bls_entry
+{
+  struct bls_entry *next;
+  struct bls_entry *prev;
+  struct keyval **keyvals;
+  int nkeyvals;
+  char *filename;
+  int visible;
+};
+
 struct grub_menu_entry_class
 {
   char *name;
@@ -60,6 +70,9 @@ struct grub_menu_entry
 
   /* The next element.  */
   struct grub_menu_entry *next;
+
+  /* BLS used to populate the entry */
+  struct bls_entry *bls;
 };
 typedef struct grub_menu_entry *grub_menu_entry_t;
 
include/grub/normal.h +1 -1
index 218cbabcc..8839ad85a 100644
@@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char
 **args, char **classes,
                            const char *id,
                            const char *users, const char *hotkey,
                            const char *prefix, const char *sourcecode,
-                           int submenu);
+                           int submenu, int *index, struct bls_entry
 *bls);
 

grub_err_t
grub_normal_set_password (const char *user, const char *password);
--
2.46.1

Quoted 10 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#21 lore raw

PATCH 12/20 10_linux.in: Add devicetree loading

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

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

Use the default device tree from the grub default file

instead of hardcoding a value.

---
 util/grub-mkconfig.in   |  3 ++-
 util/grub.d/10_linux.in | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
util/grub-mkconfig.in +2 -1
index 32c480dae..d1bf4983b 100644
@@ -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"
util/grub.d/10_linux.in +15 -0
index cc393be7e..00d4b220c 100644
@@ -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
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#22 lore raw

PATCH 13/20 00_header.in: Enable pager by default. (#985860)

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 util/grub.d/00_header.in | 2 ++
 1 file changed, 2 insertions(+)
util/grub.d/00_header.in +2 -0
index 6a316a5ba..c2d8b0937 100644
@@ -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
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#23 lore raw

PATCH 14/20 10_linux.in 20_linux_xen.in: Don't say "GNU/Linux" in generated menus.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

[rharwood: say it even less]

---
 grub-core/normal/main.c         | 2 +-
 tests/util/grub-shell-tester.in | 2 +-
 tests/util/grub-shell.in        | 2 +-
 util/grub.d/10_linux.in         | 4 ++--
 util/grub.d/20_linux_xen.in     | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)
grub-core/normal/main.c +1 -1
index 1317279c0..568c2adfa 100644
@@ -218,7 +218,7 @@ grub_normal_init_page (struct grub_term_output *term,
 
   grub_term_cls (term);
 
-  msg_formatted = grub_xasprintf (_("GNU GRUB  version %s"), PACKAGE_VERSION);
+  msg_formatted = grub_xasprintf (_("GRUB version %s"), PACKAGE_VERSION);
   if (!msg_formatted)
     return;
 
tests/util/grub-shell-tester.in +1 -1
index 8a87109b1..9a4319d4f 100644
@@ -56,7 +56,7 @@ for option in "$@"; do
 	usage
 	exit 0 ;;
     -v | --version)
-	echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+	echo "$0 (GRUB ${PACKAGE_VERSION})"
 	exit 0 ;;
     --modules=*)
 	ms=`echo "$option" | sed -e 's/--modules=//'`
tests/util/grub-shell.in +1 -1
index 496e1bab3..e0570c88e 100644
@@ -243,7 +243,7 @@ for option in "$@"; do
 	usage
 	exit 0 ;;
     -v | --version)
-	echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+	echo "$0 (GRUB ${PACKAGE_VERSION})"
 	exit 0 ;;
     --trim)
 	trim=1 ;;
util/grub.d/10_linux.in +2 -2
index 00d4b220c..901745707 100644
@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
+  OS="$(sed 's, release .*$,,g' /etc/system-release)"
 else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
+  OS="${GRUB_DISTRIBUTOR}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
 fi
 
util/grub.d/20_linux_xen.in +2 -2
index 94dd8be13..98ee5bc58 100644
@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os --class xen"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
+  OS="$(sed 's, release .*$,,g' /etc/system-release)"
 else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
+  OS="${GRUB_DISTRIBUTOR}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
 fi
 
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#24 lore raw

Re: [PATCH 14/20] 10_linux.in 20_linux_xen.in: Don't say "GNU/Linux" in generated menus.

Quoted 29 lines · Leo Sandoval

From: Peter Jones <[email protected]>

[rharwood: say it even less]

---
 grub-core/normal/main.c         | 2 +-
 tests/util/grub-shell-tester.in | 2 +-
 tests/util/grub-shell.in        | 2 +-
 util/grub.d/10_linux.in         | 4 ++--
 util/grub.d/20_linux_xen.in     | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)
grub-core/normal/main.c +1 -1
index 1317279c0..568c2adfa 100644
@@ -218,7 +218,7 @@ grub_normal_init_page (struct grub_term_output *term,
 
   grub_term_cls (term);
 
-  msg_formatted = grub_xasprintf (_("GNU GRUB  version %s"), PACKAGE_VERSION);
+  msg_formatted = grub_xasprintf (_("GRUB version %s"), PACKAGE_VERSION);
   if (!msg_formatted)
     return;
 
tests/util/grub-shell-tester.in +0 -0
index 8a87109b1..9a4319d4f 100644

tests/util/grub-shell-tester.in for option in "$@"; do · line 59

Quoted 5 lines
tests/util/grub-shell-tester.in +1 -1
@@ -56,7 +56,7 @@ for option in "$@"; do
 	usage
 	exit 0 ;;
     -v | --version)
-	echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+	echo "$0 (GRUB ${PACKAGE_VERSION})"

This and related changes seem bizarre? I can understand changing GNU/Linux -> Linux on some systems (based on uname -o for instance, or just by using PRETTY_NAME from /etc/os-release or ...), but not blanket-removing 'GNU' from the sources, even when it pertains to GRUB rather than whatever distribution.

Signature · 1 line
Arsen Arsenović

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#25 lore raw

Re: [PATCH 14/20] 10_linux.in 20_linux_xen.in: Don't say "GNU/Linux" in generated menus.

In reply to Leo Sandoval

Official stand of FSF and GNU project is that the correct name is GNU/Linux. The only case where this could be justified is for non-GNU variants like BusyBox distros or Android

Quoted 90 lines · Leo Sandoval

From: Peter Jones <[email protected]>

[rharwood: say it even less]

---
 grub-core/normal/main.c         | 2 +-
 tests/util/grub-shell-tester.in | 2 +-
 tests/util/grub-shell.in        | 2 +-
 util/grub.d/10_linux.in         | 4 ++--
 util/grub.d/20_linux_xen.in     | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)
grub-core/normal/main.c +1 -1
index 1317279c0..568c2adfa 100644
@@ -218,7 +218,7 @@ grub_normal_init_page (struct grub_term_output *term,
 
   grub_term_cls (term);
 
-  msg_formatted = grub_xasprintf (_("GNU GRUB  version %s"),
 PACKAGE_VERSION);
+  msg_formatted = grub_xasprintf (_("GRUB version %s"), PACKAGE_VERSION);
   if (!msg_formatted)
     return;
tests/util/ renamed from tests/util/grub-shell-tester.in +0 -0

grub-shell-tester.in
index 8a87109b1..9a4319d4f 100644

tests/util/grub-shell-tester.in +1 -1
@@ -56,7 +56,7 @@ for option in "$@"; do
        usage
        exit 0 ;;
     -v | --version)
-       echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+       echo "$0 (GRUB ${PACKAGE_VERSION})"
        exit 0 ;;
     --modules=*)
        ms=`echo "$option" | sed -e 's/--modules=//'`
tests/util/grub-shell.in +1 -1
index 496e1bab3..e0570c88e 100644
@@ -243,7 +243,7 @@ for option in "$@"; do
        usage
        exit 0 ;;
     -v | --version)
-       echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+       echo "$0 (GRUB ${PACKAGE_VERSION})"
        exit 0 ;;
     --trim)
        trim=1 ;;
util/grub.d/10_linux.in +2 -3
index 00d4b220c..901745707 100644
@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
+  OS="$(sed 's, release .*$,,g' /etc/system-release)"
 else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
+  OS="${GRUB_DISTRIBUTOR}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' '
-f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
 fi
util/grub.d/20_linux_xen.in +2 -4
index 94dd8be13..98ee5bc58 100644
@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os --class xen"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
+  OS="$(sed 's, release .*$,,g' /etc/system-release)"
 else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
+  OS="${GRUB_DISTRIBUTOR}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' '
-f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
 fi
 
--

2.46.1

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#26 lore raw

Re: [PATCH 14/20] 10_linux.in 20_linux_xen.in: Don't say "GNU/Linux" in generated menus.

I think we can argue whether 'Linux' or 'GNU/Linux' is the valid name for this category of OSes that contain GNU components in userland, but I don't see why the boot entry cannot be just the "given name" for each OS. For instance ours is called just "Ubuntu", it's neither "Ubuntu Linux" or "Ubuntu GNU/Linux", so we carry a similar patch.

Mate

Quoted 91 lines · Vladimir 'phcoder' Serbinenko

Official stand of FSF and GNU project is that the correct name is GNU/Linux. The only case where this could be justified is for non-GNU variants like BusyBox distros or Android

Quoted 87 lines · Leo Sandoval

From: Peter Jones <[email protected]>

[rharwood: say it even less]

---
 grub-core/normal/main.c         | 2 +-
 tests/util/grub-shell-tester.in | 2 +-
 tests/util/grub-shell.in        | 2 +-
 util/grub.d/10_linux.in         | 4 ++--
 util/grub.d/20_linux_xen.in     | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)
grub-core/normal/main.c +1 -1
index 1317279c0..568c2adfa 100644
@@ -218,7 +218,7 @@ grub_normal_init_page (struct grub_term_output *term,
 
   grub_term_cls (term);
 
-  msg_formatted = grub_xasprintf (_("GNU GRUB  version %s"), PACKAGE_VERSION);
+  msg_formatted = grub_xasprintf (_("GRUB version %s"), PACKAGE_VERSION);
   if (!msg_formatted)
     return;
 
tests/util/grub-shell-tester.in +1 -1
index 8a87109b1..9a4319d4f 100644
@@ -56,7 +56,7 @@ for option in "$@"; do
        usage
        exit 0 ;;
     -v | --version)
-       echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+       echo "$0 (GRUB ${PACKAGE_VERSION})"
        exit 0 ;;
     --modules=*)
        ms=`echo "$option" | sed -e 's/--modules=//'`
tests/util/grub-shell.in +1 -1
index 496e1bab3..e0570c88e 100644
@@ -243,7 +243,7 @@ for option in "$@"; do
        usage
        exit 0 ;;
     -v | --version)
-       echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
+       echo "$0 (GRUB ${PACKAGE_VERSION})"
        exit 0 ;;
     --trim)
        trim=1 ;;
util/grub.d/10_linux.in +2 -2
index 00d4b220c..901745707 100644
@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
+  OS="$(sed 's, release .*$,,g' /etc/system-release)"
 else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
+  OS="${GRUB_DISTRIBUTOR}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
 fi
 
util/grub.d/20_linux_xen.in +2 -3
index 94dd8be13..98ee5bc58 100644
@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os --class xen"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
+  OS="$(sed 's, release .*$,,g' /etc/system-release)"
 else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
+  OS="${GRUB_DISTRIBUTOR}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
 fi
 
--

2.46.1

Quoted 9 lines
Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#27 lore raw

PATCH 15/20 Makefile.common: Add .eh_frame to list of relocations stripped

In reply to Leo Sandoval

From: Fedora Ninjas <[email protected]>

---
 conf/Makefile.common | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
conf/Makefile.common +1 -1
index b8f216f6c..ece9ed8a1 100644
@@ -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
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#28 lore raw

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

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

When we set a password, we just want that to mean you can't /edit/ an entry.

Resolves: rhbz#1030176

---
 util/grub.d/10_linux.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/grub.d/10_linux.in +1 -1
index 901745707..9c31a94de 100644
@@ -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="$(sed 's, release .*$,,g' /etc/system-release)"
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#29 lore raw

PATCH 17/20 normal/main: fw_path prefix when fallback searching for grub config

In reply to Leo Sandoval

From: Fedora Ninjas <[email protected]>

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.

---
 grub-core/normal/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
grub-core/normal/main.c +3 -2
index 568c2adfa..0b2bbee19 100644
@@ -347,7 +347,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);
@@ -370,7 +370,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;
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#30 lore raw

PATCH 18/20 normal/main: Try mac/guid/etc before grub.cfg on tftp config files.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

---
 grub-core/normal/main.c | 93 ++++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 44 deletions(-)
grub-core/normal/main.c +49 -44
index 0b2bbee19..4c89892fa 100644
@@ -345,61 +345,66 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
       /* Guess the config filename. It is necessary to make CONFIG static,
 	 so that it won't get broken by longjmp.  */
       char *config;
-      const char *prefix, *fw_path;
-
-      prefix = fw_path = grub_env_get ("fw_path");
-      if (fw_path)
-	{
-	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
-	  if (config)
-	    {
-	      grub_file_t file;
-
-	      file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
-	      if (file)
-		{
-		  grub_file_close (file);
-		  grub_enter_normal_mode (config);
-		}
-              else
-                {
-                  /*  Ignore all errors.  */
-                  grub_errno = 0;
-                }
-	      grub_free (config);
-	    }
-	}
+      const char *prefix;
+      const char *net_search_cfg;
+      int disable_net_search = 0;
 
+      prefix = grub_env_get ("fw_path");
       if (! prefix)
 	      prefix = grub_env_get ("prefix");
+
+      net_search_cfg = grub_env_get ("feature_net_search_cfg");
+      if (net_search_cfg && net_search_cfg[0] == 'n')
+	      disable_net_search = 1;
+
       if (prefix)
         {
-          grub_size_t config_len;
-          int disable_net_search = 0;
-          const char *net_search_cfg;
-
-          config_len = grub_strlen (prefix) +
-                       sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
-          config = grub_malloc (config_len);
+          if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
+              !disable_net_search)
+            {
+              grub_size_t config_len;
+              config_len = grub_strlen (prefix) +
+                sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
+              config = grub_malloc (config_len);
 
-          if (!config)
-            goto quit;
+              if (! config)
+                goto quit;
 
-          grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
+              grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
 
-          net_search_cfg = grub_env_get ("feature_net_search_cfg");
-          if (net_search_cfg && net_search_cfg[0] == 'n')
-            disable_net_search = 1;
+              grub_net_search_configfile (config);
 
-          if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
-              !disable_net_search)
-            grub_net_search_config_file (config);
+              grub_enter_normal_mode (config);
+              grub_free (config);
+              config = NULL;
+            }
 
-	  grub_enter_normal_mode (config);
-	  grub_free (config);
-	}
+          if (!config)
+            {
+              config = grub_xasprintf ("%s/grub.cfg", prefix);
+              if (config)
+                {
+                  grub_file_t file;
+
+                  file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
+                  if (file)
+                    {
+                      grub_file_close (file);
+                      grub_enter_normal_mode (config);
+                    }
+                  else
+                    {
+                      /*  Ignore all errors.  */
+                      grub_errno = 0;
+                    }
+                  grub_free (config);
+                }
+            }
+        }
       else
-	grub_enter_normal_mode (0);
+        {
+          grub_enter_normal_mode (0);
+        }
     }
   else
     grub_enter_normal_mode (argv[0]);
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#31 lore raw

PATCH 19/20 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

This makes us use pretty names in the titles we generate in grub2-mkconfig when GRUB_DISTRIBUTOR isn't set.

Resolves: rhbz#996794

---
 util/grub.d/10_linux.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
util/grub.d/10_linux.in +2 -1
index 9c31a94de..b7809091b 100644
@@ -29,7 +29,8 @@ export TEXTDOMAINDIR="@localedir@"
 CLASS="--class gnu-linux --class gnu --class os --unrestricted"
 
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS="$(sed 's, release .*$,,g' /etc/system-release)"
+  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}"
   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#32 lore raw

PATCH 20/20 normal/main: Try $prefix if $fw_path doesn't work.

In reply to Leo Sandoval

From: Peter Jones <[email protected]>

Related: rhbz#1148652

---
 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(-)
grub-core/kern/ieee1275/init.c +15 -13
index 50c65b2f6..51c1e1c9d 100644
@@ -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);
 }
 
grub-core/net/net.c +1 -1
index 8cad4fb6d..54451cea2 100644
@@ -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;
grub-core/normal/main.c +65 -67

146 lines not on this page · raw message

Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel