Re: Running bootstrap script fails on Debian unstable

2023-02-20 Thread Glenn Washburn
On Mon, 20 Feb 2023 18:50:05 +0100
John Paul Adrian Glaubitz  wrote:

> Hi Glenn!
> 
> On Mon, 2023-02-20 at 11:34 -0600, Glenn Washburn wrote:
> > Does the 2.06 release build with the new autoconf? It looks like
> > sid is using 2.06, I don't see any special patches for
> > configure.ac, and I presume that the sid grub binary is built with
> > the new autoconf. If this all is true, then I'd guess some of the
> > recent configure.ac changes may have something to do with it.
> 
> Very good point. I checked out grub-2.06 to verify that theory, but
> it actually shows the same problem:
> 
> autoreconf: export WARNINGS=
> autoreconf: Entering directory '.'
> autoreconf: running: true --force
> autoreconf: running: aclocal -I m4 --force -I m4
> autoreconf: configure.ac: tracing
> autoreconf: configure.ac: not using Libtool
> autoreconf: configure.ac: not using Intltool
> autoreconf: configure.ac: not using Gtkdoc
> autoreconf: running: /usr/bin/autoconf --include=m4 --force
> configure.ac:54: warning: The macro `AC_CONFIG_HEADER' is obsolete.
> configure.ac:54: You should run autoupdate.
> ./lib/autoconf/status.m4:719: AC_CONFIG_HEADER is expanded from...
> configure.ac:54: the top level
> configure.ac:336: warning: AC_PROG_LEX without either yywrap or
> noyywrap is obsolete ./lib/autoconf/programs.m4:716: _AC_PROG_LEX is
> expanded from... ./lib/autoconf/programs.m4:709: AC_PROG_LEX is
> expanded from... configure.ac:336: the top level
> configure.ac:361: warning: The macro `AC_GNU_SOURCE' is obsolete.
> configure.ac:361: You should run autoupdate.
> ./lib/autoconf/specific.m4:312: AC_GNU_SOURCE is expanded from...
> m4/gnulib-comp.m4:34: gl_EARLY is expanded from...
> configure.ac:361: the top level
> configure.ac:361: warning: AC_COMPILE_IFELSE was called before
> AC_USE_SYSTEM_EXTENSIONS ./lib/autoconf/specific.m4:312:
> AC_GNU_SOURCE is expanded from... m4/gnulib-comp.m4:34: gl_EARLY is
> expanded from... configure.ac:361: the top level
> configure.ac:361: warning: The macro `AC_HELP_STRING' is obsolete.
> configure.ac:361: You should run autoupdate.
> ./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
> m4/threadlib.m4:38: gl_THREADLIB_EARLY_BODY is expanded from...
> m4/threadlib.m4:31: gl_THREADLIB_EARLY is expanded from...
> m4/gnulib-comp.m4:34: gl_EARLY is expanded from...
> configure.ac:361: the top level
> configure.ac:372: warning: The macro `AC_GNU_SOURCE' is obsolete.
> configure.ac:372: You should run autoupdate.
> ./lib/autoconf/specific.m4:312: AC_GNU_SOURCE is expanded from...
> configure.ac:372: the top level

It looks like the debian build log[1] for sid has the same messages, up
to here. The package goes on to build successfully.

> configure.ac:423: error: possibly undefined macro: AC_CHECK_HEADERS
>   If this token and others are legitimate, please use
> m4_pattern_allow. See the Autoconf documentation.
> configure.ac:514: error: possibly undefined macro: AC_LINK_IFELSE
> configure.ac:1608: error: possibly undefined macro: AC_LANG_CALL
> autoreconf: error: /usr/bin/autoconf failed with exit status: 1
> ./bootstrap: autoreconf failed

Do you have installed all the packages that are installed in that build
log? Are you applying all the patches or just building from 2.06 git?

Glenn

[1]
https://buildd.debian.org/status/fetch.php?pkg=grub2=amd64=2.06-8=1675915603=0

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


Re: [PATCH v6 09/14] gdb: Add more support for debugging on EFI platforms

2023-02-20 Thread Glenn Washburn
On Mon, 20 Feb 2023 15:06:46 -0500
Robbie Harwood  wrote:

> Glenn Washburn  writes:
> 
> > If the configure option --enable-efi-debug is given, then enable the
> > printing early in EFI startup of the command needed to load symbols
> > for the GRUB EFI kernel. This is needed because EFI firmware
> > determines where to load the GRUB EFI at runtime, and so the
> > relevant addresses are not known ahead of time.
> 
> Does this actually need to be configurable as opposed to always
> enabled where applicable?  I would want to turn it on in distro
> builds, much like the similar patch we carry is.

Daniel suggested to make it configurable, originally it wasn't. I could
see someone annoyed with the flash of text and rather have it disabled.
Personally, I don't care much. I don't think it makes sense to have the
gdbinfo module configurable, it should always be enabled (which it
isn't currently).

Also, Daniel was concerned about this breaking silent boot. How does this 
affect things for you?

> > This is not printed when secure boot is enabled.
> 
> This will mean that any debugging first requires disabling secureboot.
> That's potentially annoying and I'm not sure I see a security benefit
> to doing so.

This was also requested by Daniel, and I have no preference. I confess
to not seeing a security benefit also. It also seems reasonable to
think that it might. Perhaps Daniel has something specific in mind.

Glenn

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


[PATCH v3] loader/i386/linux.c Correct wrong initrd address for debug

2023-02-20 Thread Jeremy Szu
The 'addr' is used to request the memory with specific ranges but the
real loadable address come from the relocator.
Thus, print the final retrieved addresses (virtual and physical) for
initrd.

v2: append SOB

v3: fix wrong code base

Signed-off-by: Jeremy Szu 
---
 grub-core/loader/i386/linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 10a367629..cbe975318 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -1123,8 +1123,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ 
((unused)),
   if (grub_initrd_load (_ctx, initrd_mem))
 goto fail;
 
-  grub_dprintf ("linux", "Initrd, addr=0x%x, size=0x%x\n",
-   (unsigned) addr, (unsigned) size);
+  grub_dprintf ("linux", "Initrd (%p) at 0x%" PRIxGRUB_ADDR ", size=0x%x\n",
+   initrd_mem, initrd_mem_target, (unsigned) size);
 
   linux_params.ramdisk_image = initrd_mem_target;
   linux_params.ramdisk_size = size;
-- 
2.38.1


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


Re: [PATCH v6 09/14] gdb: Add more support for debugging on EFI platforms

2023-02-20 Thread Robbie Harwood
Glenn Washburn  writes:

> If the configure option --enable-efi-debug is given, then enable the
> printing early in EFI startup of the command needed to load symbols for
> the GRUB EFI kernel. This is needed because EFI firmware determines where
> to load the GRUB EFI at runtime, and so the relevant addresses are not
> known ahead of time.

Does this actually need to be configurable as opposed to always enabled
where applicable?  I would want to turn it on in distro builds, much
like the similar patch we carry is.

> This is not printed when secure boot is enabled.

This will mean that any debugging first requires disabling secureboot.
That's potentially annoying and I'm not sure I see a security benefit to
doing so.

Be well,
--Robbie


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


[PATCH v2 4/7] util/grub.d: activate bli module on EFI

2023-02-20 Thread Oliver Steffen
Add a new configuration drop-in file that loads the
boot-loader-interface (bli) module and runs the command in case we are
booting on  the EFI platform.

Signed-off-by: Oliver Steffen 
---
 util/grub.d/25_boot_loader_interface.in | 34 +
 1 file changed, 34 insertions(+)
 create mode 100644 util/grub.d/25_boot_loader_interface.in

diff --git a/util/grub.d/25_boot_loader_interface.in 
b/util/grub.d/25_boot_loader_interface.in
new file mode 100644
index 0..8285d7627
--- /dev/null
+++ b/util/grub.d/25_boot_loader_interface.in
@@ -0,0 +1,34 @@
+#!/usr/bin/sh
+set -e
+
+# grub-mkconfig helper script.
+# Copyright (C) 2020  Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB.  If not, see .
+
+prefix="/usr"
+exec_prefix="/usr"
+datarootdir="/usr/share"
+
+export TEXTDOMAIN=grub
+export TEXTDOMAINDIR="${datarootdir}/locale"
+
+. "$pkgdatadir/grub-mkconfig_lib"
+
+cat << EOF
+if [ "\$grub_platform" = "efi" ]; then
+  insmod boot-loader-interface
+  boot-loader-interface
+fi
+EOF
-- 
2.39.2


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


[PATCH v2 1/7] efi: add grub_efi_set_variable_with_attributes

2023-02-20 Thread Oliver Steffen
Add a function to the EFI module that allows setting EFI variables
with specific attributes.

This is useful for marking variables as volatile, for example.

Signed-off-by: Oliver Steffen 
---
 grub-core/kern/efi/efi.c | 19 +--
 include/grub/efi/efi.h   |  6 ++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index cf49d6357..03abf5531 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -201,8 +201,8 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t 
memory_map_size,
 }
 
 grub_err_t
-grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
- void *data, grub_size_t datasize)
+grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t 
*guid,
+ void *data, grub_size_t datasize, grub_efi_uint32_t 
attributes)
 {
   grub_efi_status_t status;
   grub_efi_runtime_services_t *r;
@@ -219,10 +219,7 @@ grub_efi_set_variable(const char *var, const 
grub_efi_guid_t *guid,
 
   r = grub_efi_system_table->runtime_services;
 
-  status = efi_call_5 (r->set_variable, var16, guid,
-  (GRUB_EFI_VARIABLE_NON_VOLATILE
-   | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
-   | GRUB_EFI_VARIABLE_RUNTIME_ACCESS),
+  status = efi_call_5 (r->set_variable, var16, guid, attributes,
   datasize, data);
   grub_free (var16);
   if (status == GRUB_EFI_SUCCESS)
@@ -231,6 +228,16 @@ grub_efi_set_variable(const char *var, const 
grub_efi_guid_t *guid,
   return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
 }
 
+grub_err_t
+grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
+ void *data, grub_size_t datasize)
+{
+  return grub_efi_set_variable_with_attributes (var, guid, data, datasize, 
+   GRUB_EFI_VARIABLE_NON_VOLATILE
+   | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
+   | GRUB_EFI_VARIABLE_RUNTIME_ACCESS);
+}
+
 grub_efi_status_t
 grub_efi_get_variable_with_attributes (const char *var,
   const grub_efi_guid_t *guid,
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index e61272de5..8e9a905a4 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -86,6 +86,12 @@ grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const 
char *variable,
   grub_size_t 
*datasize_out,
   void **data_out);
 grub_err_t
+EXPORT_FUNC (grub_efi_set_variable_with_attributes) (const char *var,
+const grub_efi_guid_t *guid,
+void *data,
+grub_size_t datasize,
+grub_efi_uint32_t attributes);
+grub_err_t
 EXPORT_FUNC (grub_efi_set_variable) (const char *var,
 const grub_efi_guid_t *guid,
 void *data,
-- 
2.39.2


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


[PATCH v2 2/7] efi: check for integer overflow in string conversion

2023-02-20 Thread Oliver Steffen
Check for integer overflow when converting the name of the
EFI variable to UTF16 in grub_efi_set_variable_with_attributes().

Signed-off-by: Oliver Steffen 
---
 grub-core/kern/efi/efi.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index 03abf5531..a23c80a21 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -210,6 +211,11 @@ grub_efi_set_variable_with_attributes (const char *var, 
const grub_efi_guid_t *g
   grub_size_t len, len16;
 
   len = grub_strlen (var);
+
+  /* Check for integer overflow */
+  if (len > GRUB_SIZE_MAX / GRUB_MAX_UTF16_PER_UTF8 - 1)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable name too long"));
+
   len16 = len * GRUB_MAX_UTF16_PER_UTF8;
   var16 = grub_calloc (len16 + 1, sizeof (var16[0]));
   if (!var16)
-- 
2.39.2


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


[PATCH v2 6/7] commands/probe: use grub_gpt_part_guid_snprint

2023-02-20 Thread Oliver Steffen
Use the new function for printing the partition guid.

Signed-off-by: Oliver Steffen 
---
 grub-core/commands/probe.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c
index 9a80ea54f..3fe50d11e 100644
--- a/grub-core/commands/probe.c
+++ b/grub-core/commands/probe.c
@@ -104,7 +104,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char 
**args)
   if (state[6].set)
 {
   /* ---- + null terminator */
-  char val[37] = "none";
+  char val[GRUB_GPT_GUID_STR_LEN + 1] = "none";
   if (dev->disk && dev->disk->partition)
{
  struct grub_partition *p = dev->disk->partition;
@@ -130,14 +130,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char 
**args)
  return grub_errno;
}
  guid = 
- grub_snprintf (val, sizeof(val),
-"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-grub_le_to_cpu32 (guid->data1),
-grub_le_to_cpu16 (guid->data2),
-grub_le_to_cpu16 (guid->data3),
-guid->data4[0], guid->data4[1], guid->data4[2],
-guid->data4[3], guid->data4[4], guid->data4[5],
-guid->data4[6], guid->data4[7]);
+grub_gpt_part_guid_snprint (val, sizeof(val), guid);
}
  else if (grub_strcmp(dev->disk->partition->partmap->name, "msdos") == 
0)
{
-- 
2.39.2


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


[PATCH v2 5/7] partmap/gpt: add print function for guids

2023-02-20 Thread Oliver Steffen
Code to print gpt patition guids has been duplicated in multiple places.
Add a common function for that.

Signed-off-by: Oliver Steffen 
---
 grub-core/partmap/gpt.c  | 13 +
 include/grub/gpt_partition.h |  6 ++
 2 files changed, 19 insertions(+)

diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
index 075cc96f1..e0da7e885 100644
--- a/grub-core/partmap/gpt.c
+++ b/grub-core/partmap/gpt.c
@@ -227,6 +227,19 @@ static struct grub_partition_map grub_gpt_partition_map =
 #endif
   };
 
+int
+grub_gpt_part_guid_snprint (char *str, grub_size_t n, const 
grub_gpt_part_guid_t *guid)
+{
+  return grub_snprintf (str, n,
+GRUB_PRIxGPT_GUID,
+grub_le_to_cpu32 (guid->data1),
+grub_le_to_cpu16 (guid->data2),
+grub_le_to_cpu16 (guid->data3),
+guid->data4[0], guid->data4[1], guid->data4[2],
+guid->data4[3], guid->data4[4], guid->data4[5],
+guid->data4[6], guid->data4[7]);
+}
+
 GRUB_MOD_INIT(part_gpt)
 {
   grub_partition_map_register (_gpt_partition_map);
diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
index 7a93f4329..9b1660322 100644
--- a/include/grub/gpt_partition.h
+++ b/include/grub/gpt_partition.h
@@ -50,6 +50,9 @@ typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
{ 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3 }  \
   }
 
+#define GRUB_PRIxGPT_GUID "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"
+#define GRUB_GPT_GUID_STR_LEN 36
+
 struct grub_gpt_header
 {
   grub_uint8_t magic[8];
@@ -83,5 +86,8 @@ grub_gpt_partition_map_iterate (grub_disk_t disk,
grub_partition_iterate_hook_t hook,
void *hook_data);
 
+int
+grub_gpt_part_guid_snprint (char *str, grub_size_t n,
+   const grub_gpt_part_guid_t *guid);
 
 #endif /* ! GRUB_GPT_PARTITION_HEADER */
-- 
2.39.2


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


[PATCH v2 0/7] Add basic Boot Loader Interface support

2023-02-20 Thread Oliver Steffen

This is a step towards supporting unified kernel images (UKI) in Grub.

Add a new module named bli, which provides a command with the same name.
It implements a small but quite useful part of the Boot Loader Interface
[0].  This interface uses EFI variables for communication between the
boot loader and the operating system.

This module sets two EFI variables under the vendor GUID
4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:

- LoaderInfo: contains GRUB + .
  This allows the running operating system to identify the boot loader
  used during boot.

- LoaderDevicePartUUID: contains the partition UUID of the
  EFI System Partition (ESP). This is used by
  systemd-gpt-auto-generator [1] to find the root partitions (and
  others too), via partition type IDs [2]. This is especially useful for
  UKIs, where the kernel command line is fixed and usually does not
  contain any information about the root partition.

This module is only available on EFI platforms.

[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] 
https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] 
https://uapi-group.org/specifications/specs/discoverable_partitions_specification/

v2:
- Addressed comments from Daniel
- Added a print function for gpt guids
- Added integer overflow check in UTF16 conversion
- Added config drop-in file that loads the module on EFI

v1:
https://mail.gnu.org/archive/html/grub-devel/2023-01/msg00104.html

Oliver Steffen (7):
  efi: add grub_efi_set_variable_with_attributes
  efi: check for integer overflow in string conversion
  Add a module for the Boot Loader Interface
  util/grub.d: activate bli module on EFI
  partmap/gpt: add print function for guids
  commands/probe: use grub_gpt_part_guid_snprint
  commands/bli: use grub_gpt_part_guid_snprint

 grub-core/Makefile.core.def |   6 +
 grub-core/commands/bli.c| 209 
 grub-core/commands/probe.c  |  11 +-
 grub-core/kern/efi/efi.c|  25 ++-
 grub-core/partmap/gpt.c |  13 ++
 include/grub/efi/api.h  |   5 +
 include/grub/efi/efi.h  |   6 +
 include/grub/gpt_partition.h|   6 +
 util/grub.d/25_boot_loader_interface.in |  34 
 9 files changed, 300 insertions(+), 15 deletions(-)
 create mode 100644 grub-core/commands/bli.c
 create mode 100644 util/grub.d/25_boot_loader_interface.in

-- 
2.39.2


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


[PATCH v2 3/7] Add a module for the Boot Loader Interface

2023-02-20 Thread Oliver Steffen
Add a new module named boot_loader_interface, which provides a command
with the same name. It implements a small but quite useful part of the
Boot Loader Interface [0].  This interface uses EFI variables for
communication between the boot loader and the operating system.

This module sets two EFI variables under the vendor GUID
4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:

- LoaderInfo: contains GRUB + .
  This allows the running operating system to identify the boot loader
  used during boot.

- LoaderDevicePartUUID: contains the partition UUID of the
  EFI System Partition (ESP).  This is used by
  systemd-gpt-auto-generator [1] to find the root partitions (and others
  too), via partition type IDs [2].

This module is only available on EFI platforms.

[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] 
https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] 
https://uapi-group.org/specifications/specs/discoverable_partitions_specification/

Signed-off-by: Oliver Steffen 
---
 grub-core/Makefile.core.def |   6 +
 grub-core/commands/bli.c| 213 
 include/grub/efi/api.h  |   5 +
 3 files changed, 224 insertions(+)
 create mode 100644 grub-core/commands/bli.c

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 71093a100..cdfa2d101 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -2548,3 +2548,9 @@ module = {
   common = commands/i386/wrmsr.c;
   enable = x86;
 };
+
+module = {
+  name = bli;
+  efi = commands/bli.c;
+  enable = efi;
+};
diff --git a/grub-core/commands/bli.c b/grub-core/commands/bli.c
new file mode 100644
index 0..10993222d
--- /dev/null
+++ b/grub-core/commands/bli.c
@@ -0,0 +1,213 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2023  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 .
+ *
+ *  Implementation of the Boot Loader Interface.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define MODNAME "bli"
+
+static const grub_efi_guid_t bli_vendor_guid = 
GRUB_EFI_VENDOR_BOOT_LOADER_INTERFACE_GUID;
+
+static char *
+machine_get_bootdevice (void)
+{
+  grub_efi_loaded_image_t *image;
+
+  image = grub_efi_get_loaded_image (grub_efi_image_handle);
+  if (image == NULL)
+return NULL;
+
+  return grub_efidisk_get_device_name (image->device_handle);
+}
+
+static grub_err_t
+get_part_uuid (grub_device_t dev, char **part_uuid)
+{
+  grub_err_t status = GRUB_ERR_NONE;
+  grub_disk_t disk;
+  struct grub_gpt_partentry entry;
+  grub_gpt_part_guid_t *guid;
+
+  if (dev == NULL || dev->disk == NULL || dev->disk->partition == NULL)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid device"));
+
+  disk = grub_disk_open (dev->disk->name);
+  if (disk == NULL)
+{
+  status = grub_errno;
+  grub_dprintf (MODNAME, "Error opening disk\n");
+  return status;
+}
+
+  if (grub_strcmp (dev->disk->partition->partmap->name, "gpt") != 0)
+{
+  status = grub_error (GRUB_ERR_BAD_PART_TABLE,
+  N_("this is not a GPT partition table"));
+  goto fail;
+}
+
+  if (grub_disk_read (disk, dev->disk->partition->offset,
+ dev->disk->partition->index, sizeof (entry), ) != 
GRUB_ERR_NONE)
+{
+  status = grub_errno;
+  grub_dprintf (MODNAME, "%s: Read error\n", dev->disk->name);
+  goto fail;
+}
+
+  guid = 
+  *part_uuid = grub_xasprintf (
+  "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+  grub_le_to_cpu32 (guid->data1), grub_le_to_cpu16 (guid->data2),
+  grub_le_to_cpu16 (guid->data3), guid->data4[0], guid->data4[1],
+  guid->data4[2], guid->data4[3], guid->data4[4], guid->data4[5],
+  guid->data4[6], guid->data4[7]);
+  if (*part_uuid == NULL)
+status = grub_errno;
+
+ fail:
+  grub_disk_close (disk);
+
+  return status;
+}
+
+static grub_err_t
+set_efi_str_variable (const char *name, const grub_efi_guid_t *guid,
+  const char *value)
+{
+  grub_size_t len, len16;
+  grub_efi_char16_t *value_16;
+  grub_err_t status;
+
+  len = grub_strlen (value);
+
+  /* Check for integer overflow */
+  if (len > GRUB_SIZE_MAX / GRUB_MAX_UTF16_PER_UTF8 - 1)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, 

[PATCH v2 7/7] commands/bli: use grub_gpt_part_guid_snprint

2023-02-20 Thread Oliver Steffen
Use the new function for printing the partition guid.

Signed-off-by: Oliver Steffen 
---
 grub-core/commands/bli.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/grub-core/commands/bli.c b/grub-core/commands/bli.c
index 10993222d..160cbdb34 100644
--- a/grub-core/commands/bli.c
+++ b/grub-core/commands/bli.c
@@ -83,14 +83,10 @@ get_part_uuid (grub_device_t dev, char **part_uuid)
 }
 
   guid = 
-  *part_uuid = grub_xasprintf (
-  "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-  grub_le_to_cpu32 (guid->data1), grub_le_to_cpu16 (guid->data2),
-  grub_le_to_cpu16 (guid->data3), guid->data4[0], guid->data4[1],
-  guid->data4[2], guid->data4[3], guid->data4[4], guid->data4[5],
-  guid->data4[6], guid->data4[7]);
+  *part_uuid = grub_calloc (GRUB_GPT_GUID_STR_LEN + 1, sizeof (char));
   if (*part_uuid == NULL)
 status = grub_errno;
+  grub_gpt_part_guid_snprint (*part_uuid, GRUB_GPT_GUID_STR_LEN + 1, guid);
 
  fail:
   grub_disk_close (disk);
-- 
2.39.2


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


Re: Running bootstrap script fails on Debian unstable

2023-02-20 Thread John Paul Adrian Glaubitz
Hi Glenn!

On Mon, 2023-02-20 at 11:34 -0600, Glenn Washburn wrote:
> Does the 2.06 release build with the new autoconf? It looks like sid is
> using 2.06, I don't see any special patches for configure.ac, and I
> presume that the sid grub binary is built with the new autoconf. If
> this all is true, then I'd guess some of the recent configure.ac
> changes may have something to do with it.

Very good point. I checked out grub-2.06 to verify that theory, but it actually
shows the same problem:

autoreconf: export WARNINGS=
autoreconf: Entering directory '.'
autoreconf: running: true --force
autoreconf: running: aclocal -I m4 --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: /usr/bin/autoconf --include=m4 --force
configure.ac:54: warning: The macro `AC_CONFIG_HEADER' is obsolete.
configure.ac:54: You should run autoupdate.
./lib/autoconf/status.m4:719: AC_CONFIG_HEADER is expanded from...
configure.ac:54: the top level
configure.ac:336: warning: AC_PROG_LEX without either yywrap or noyywrap is 
obsolete
./lib/autoconf/programs.m4:716: _AC_PROG_LEX is expanded from...
./lib/autoconf/programs.m4:709: AC_PROG_LEX is expanded from...
configure.ac:336: the top level
configure.ac:361: warning: The macro `AC_GNU_SOURCE' is obsolete.
configure.ac:361: You should run autoupdate.
./lib/autoconf/specific.m4:312: AC_GNU_SOURCE is expanded from...
m4/gnulib-comp.m4:34: gl_EARLY is expanded from...
configure.ac:361: the top level
configure.ac:361: warning: AC_COMPILE_IFELSE was called before 
AC_USE_SYSTEM_EXTENSIONS
./lib/autoconf/specific.m4:312: AC_GNU_SOURCE is expanded from...
m4/gnulib-comp.m4:34: gl_EARLY is expanded from...
configure.ac:361: the top level
configure.ac:361: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:361: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
m4/threadlib.m4:38: gl_THREADLIB_EARLY_BODY is expanded from...
m4/threadlib.m4:31: gl_THREADLIB_EARLY is expanded from...
m4/gnulib-comp.m4:34: gl_EARLY is expanded from...
configure.ac:361: the top level
configure.ac:372: warning: The macro `AC_GNU_SOURCE' is obsolete.
configure.ac:372: You should run autoupdate.
./lib/autoconf/specific.m4:312: AC_GNU_SOURCE is expanded from...
configure.ac:372: the top level
configure.ac:423: error: possibly undefined macro: AC_CHECK_HEADERS
  If this token and others are legitimate, please use m4_pattern_allow.
  See the Autoconf documentation.
configure.ac:514: error: possibly undefined macro: AC_LINK_IFELSE
configure.ac:1608: error: possibly undefined macro: AC_LANG_CALL
autoreconf: error: /usr/bin/autoconf failed with exit status: 1
./bootstrap: autoreconf failed

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

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


Re: Running bootstrap script fails on Debian unstable

2023-02-20 Thread Glenn Washburn
Hi Adrian,

On Mon, 20 Feb 2023 15:26:35 +0100
John Paul Adrian Glaubitz  wrote:

> Hi Mihai!
> 
> On Mon, 2023-02-20 at 15:01 +0100, Mihai Moldovan wrote:
> > * On 2/20/23 10:28, John Paul Adrian Glaubitz wrote:
> > > I wanted to start the current GRUB master branch on various
> > > architectures and it turns out that the bootstrap script
> > > currently fails on Debian unstable due to the autoconf syntax
> > > changes:
> > > 
> > > running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose
> > > --install --force -I m4  --no-recursive [...]
> > > autoreconf: running: /usr/bin/autoconf --include=m4 --force
> > > configure.ac:429: error: possibly undefined macro:
> > > AC_CHECK_HEADERS If this token and others are legitimate, please
> > > use m4_pattern_allow. See the Autoconf documentation.
> > > configure.ac:520: error: possibly undefined macro: AC_LINK_IFELSE
> > > configure.ac:1631: error: possibly undefined macro: AC_LANG_CALL
> > > autoreconf: error: /usr/bin/autoconf failed with exit status: 1
> > > ./bootstrap: autoreconf failed
> > > 
> > > Does anyone know how to address this issue?
> > 
> > Nothing that would immediately stick out. How is this invoked? Are
> > you using sbuild to build the package in an automatic fashion,
> > maybe even via buildd?
> 
> No. I am using a clean Debian unstable environment created with
> schroot with the necessary build dependencies installed to perform a
> manual build.
> 
> > Can you reproduce it locally (but still in a clean chroot, like via
> > passing --anything-failed-commands='%SBUILD_SHELL' to the sbuild
> > call and having an interactive shell) to easily debug this?
> 
> I'm performing a manual, local build.
> 
> > AC_CHECK_HEADERS should be defined in
> > /usr/share/autoconf/autoconf/headers.m4 (and additionally in the
> > frozen m4 file at /usr/share/autoconf/autoconf/autoconf.m4f , but
> > I've never really grasped the concept of frozen m4 files) and
> > AC_LINK_IFELSE in /usr/share/autoconf/autoconf/lang.m4 .
> > 
> > These are standard macros, so if autoconf cannot find them,
> > something really weird must be going on. You'll probably have to
> > strace autoreconf to figure out what it's reading. Unfortunately,
> > debugging autotools is a nightmare.
> 
> Well, autoconf was changed in incompatible ways with version 2.70 and
> I assume that this is the problem. See for example [1].

Does the 2.06 release build with the new autoconf? It looks like sid is
using 2.06, I don't see any special patches for configure.ac, and I
presume that the sid grub binary is built with the new autoconf. If
this all is true, then I'd guess some of the recent configure.ac
changes may have something to do with it.

Glenn

> 
> Adrian
> 
> > [1] https://lwn.net/Articles/839395/
> 

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


Re: [PATCH v1 2/2] Add a module for the Boot Loader Interface

2023-02-20 Thread Oliver Steffen
Thank you for the comments, Daniel.

Quoting Daniel Kiper (2023-02-15 19:27:03)
> On Mon, Jan 16, 2023 at 12:40:53PM +0100, Oliver Steffen wrote:
> > Add a new module named boot_loader_interface, which provides a command
>
> I would prefer something shorter than boot_loader_interface. bli?

Then bli it is.

>
> > with the same name. It implements a small but quite useful part of the
> > Boot Loader Interface [0].  This interface uses EFI variables for
> > communication between the boot loader and the operating system.
> >
> > This module sets two EFI variables under the vendor GUID
> > 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:
> >
> > - LoaderInfo: contains GRUB + .
> >   This allows the running operating system to identify the boot loader
> >   used during boot.
> >
> > - LoaderDevicePartUUID: contains the partition UUID of the
> >   EFI System Partition (ESP).  This is used by
> >   systemd-gpt-auto-generator [1] to find the root partitions (and others
> >   too), via partition type IDs [2].
> >
> > This module is only available on EFI platforms.
> >
> > [0] https://systemd.io/BOOT_LOADER_INTERFACE/
> > [1] 
> > https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
> > [2] 
> > https://uapi-group.org/specifications/specs/discoverable_partitions_specification/
> >
> > Signed-off-by: Oliver Steffen 
> > ---
> >  grub-core/Makefile.core.def|   6 +
> >  grub-core/commands/boot_loader_interface.c | 217 +
> >  2 files changed, 223 insertions(+)
> >  create mode 100644 grub-core/commands/boot_loader_interface.c
> >
> > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> > index ba967aac8..23455fb71 100644
> > --- a/grub-core/Makefile.core.def
> > +++ b/grub-core/Makefile.core.def
> > @@ -2547,3 +2547,9 @@ module = {
> >common = commands/i386/wrmsr.c;
> >enable = x86;
> >  };
> > +
> > +module = {
> > +  name = boot_loader_interface;
>
> s/boot_loader_interface/bli/?
>
> > +  efi = commands/boot_loader_interface.c;
>
> Ditto and below if needed...
>
> > +  enable = efi;
> > +};
> > diff --git a/grub-core/commands/boot_loader_interface.c 
> > b/grub-core/commands/boot_loader_interface.c
> > new file mode 100644
> > index 0..ccd7fa3d9
> > --- /dev/null
> > +++ b/grub-core/commands/boot_loader_interface.c
> > @@ -0,0 +1,217 @@
> > +/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/
>
> Could you move this to the end of the file? Good example you can find in
> the Xen project [1].

I personally do not care about this, it was just part of the file I used
as a template. Is this wanted, or can we just drop it?

>
> > +/* boot_loader_interface.c - implementation of the boot loader interface
> > + */
>
> Please use correct formatting for comments [2] and move this one behind
> the license below.
>
> > +/*
> > + *  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 .
> > + */
>
> Please take license from the grub-core/kern/efi/sb.c file and update
> year in it. You can also merge module description with the license like
> it is done in the grub-core/kern/efi/sb.c.
>
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +GRUB_MOD_LICENSE ("GPLv3+");
> > +
> > +#define MODNAME "boot_loader_interface"
> > +
> > +static const grub_efi_guid_t boot_loader_interface_vendor_guid =
> > +  { 0x4a67b082, 0x0a4c, 0x41cf,
> > +{0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f} };
>
> Please define this GUID as constant in the include/grub/efi/api.h (you
> will find good examples how it should be done there). I expect it can
> be useful for others too.
>
> > +static char *
> > +machine_get_bootdevice (void)
> > +{
> > +  grub_efi_loaded_image_t *image;
> > +
> > +  image = grub_efi_get_loaded_image (grub_efi_image_handle);
> > +  if (!image)
>
> Please compare pointers explicitly with NULL, e.g. "if (image == NULL)",
> here and below...
>
> > +return NULL;
> > +
> > +  return grub_efidisk_get_device_name (image->device_handle);
> > +}
> > +
> > +static grub_err_t
> > +get_part_uuid (grub_device_t dev, char **part_uuid)
> > +{
> > +  grub_err_t status = GRUB_ERR_NONE;
> > +  grub_disk_t disk;
> > +  struct grub_gpt_partentry entry;
> > +  

Re: Running bootstrap script fails on Debian unstable

2023-02-20 Thread Mihai Moldovan
* On 2/20/23 15:26, John Paul Adrian Glaubitz wrote:
> [...]
>>
>> These are standard macros, so if autoconf cannot find them, something really
>> weird must be going on. You'll probably have to strace autoreconf to figure 
>> out
>> what it's reading. Unfortunately, debugging autotools is a nightmare.
> 
> Well, autoconf was changed in incompatible ways with version 2.70 and I 
> assume that
> this is the problem. See for example [1].

True, but I briefly looked up what changed and none of these core macros have
been removed or deprecated and the new, stricter quoting rules have also worked
before and grub has either been updated accordingly or almost almost used
correct quoting from the beginning.

Given that those core macros are "possibly undefined", something else must be
going on. I'd check what autoreconf/autoconf reads.



Mihai


OpenPGP_signature
Description: OpenPGP digital signature
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Running bootstrap script fails on Debian unstable

2023-02-20 Thread John Paul Adrian Glaubitz
Hi Mihai!

On Mon, 2023-02-20 at 15:01 +0100, Mihai Moldovan wrote:
> * On 2/20/23 10:28, John Paul Adrian Glaubitz wrote:
> > I wanted to start the current GRUB master branch on various architectures 
> > and it
> > turns out that the bootstrap script currently fails on Debian unstable due 
> > to
> > the autoconf syntax changes:
> > 
> > running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install 
> > --force -I m4  --no-recursive
> > [...]
> > autoreconf: running: /usr/bin/autoconf --include=m4 --force
> > configure.ac:429: error: possibly undefined macro: AC_CHECK_HEADERS
> >   If this token and others are legitimate, please use m4_pattern_allow.
> >   See the Autoconf documentation.
> > configure.ac:520: error: possibly undefined macro: AC_LINK_IFELSE
> > configure.ac:1631: error: possibly undefined macro: AC_LANG_CALL
> > autoreconf: error: /usr/bin/autoconf failed with exit status: 1
> > ./bootstrap: autoreconf failed
> > 
> > Does anyone know how to address this issue?
> 
> Nothing that would immediately stick out. How is this invoked? Are you using
> sbuild to build the package in an automatic fashion, maybe even via buildd?

No. I am using a clean Debian unstable environment created with schroot with the
necessary build dependencies installed to perform a manual build.

> Can you reproduce it locally (but still in a clean chroot, like via passing
> --anything-failed-commands='%SBUILD_SHELL' to the sbuild call and having an
> interactive shell) to easily debug this?

I'm performing a manual, local build.

> AC_CHECK_HEADERS should be defined in /usr/share/autoconf/autoconf/headers.m4
> (and additionally in the frozen m4 file at
> /usr/share/autoconf/autoconf/autoconf.m4f , but I've never really grasped the
> concept of frozen m4 files) and AC_LINK_IFELSE in
> /usr/share/autoconf/autoconf/lang.m4 .
> 
> These are standard macros, so if autoconf cannot find them, something really
> weird must be going on. You'll probably have to strace autoreconf to figure 
> out
> what it's reading. Unfortunately, debugging autotools is a nightmare.

Well, autoconf was changed in incompatible ways with version 2.70 and I assume 
that
this is the problem. See for example [1].

Adrian

> [1] https://lwn.net/Articles/839395/

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

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


Re: Running bootstrap script fails on Debian unstable

2023-02-20 Thread Mihai Moldovan
* On 2/20/23 10:28, John Paul Adrian Glaubitz wrote:
> I wanted to start the current GRUB master branch on various architectures and 
> it
> turns out that the bootstrap script currently fails on Debian unstable due to
> the autoconf syntax changes:
> 
> running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install 
> --force -I m4  --no-recursive
> [...]
> autoreconf: running: /usr/bin/autoconf --include=m4 --force
> configure.ac:429: error: possibly undefined macro: AC_CHECK_HEADERS
>   If this token and others are legitimate, please use m4_pattern_allow.
>   See the Autoconf documentation.
> configure.ac:520: error: possibly undefined macro: AC_LINK_IFELSE
> configure.ac:1631: error: possibly undefined macro: AC_LANG_CALL
> autoreconf: error: /usr/bin/autoconf failed with exit status: 1
> ./bootstrap: autoreconf failed
> 
> Does anyone know how to address this issue?

Nothing that would immediately stick out. How is this invoked? Are you using
sbuild to build the package in an automatic fashion, maybe even via buildd? Can
you reproduce it locally (but still in a clean chroot, like via passing
--anything-failed-commands='%SBUILD_SHELL' to the sbuild call and having an
interactive shell) to easily debug this?

AC_CHECK_HEADERS should be defined in /usr/share/autoconf/autoconf/headers.m4
(and additionally in the frozen m4 file at
/usr/share/autoconf/autoconf/autoconf.m4f , but I've never really grasped the
concept of frozen m4 files) and AC_LINK_IFELSE in
/usr/share/autoconf/autoconf/lang.m4 .

These are standard macros, so if autoconf cannot find them, something really
weird must be going on. You'll probably have to strace autoreconf to figure out
what it's reading. Unfortunately, debugging autotools is a nightmare.



Mihai


OpenPGP_signature
Description: OpenPGP digital signature
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Running bootstrap script fails on Debian unstable

2023-02-20 Thread John Paul Adrian Glaubitz
Hello!

I wanted to start the current GRUB master branch on various architectures and it
turns out that the bootstrap script currently fails on Debian unstable due to
the autoconf syntax changes:

running: AUTOPOINT=true LIBTOOLIZE=true autoreconf --verbose --install --force 
-I m4  --no-recursive
autoreconf: export WARNINGS=
autoreconf: Entering directory '.'
autoreconf: running: true --force
autoreconf: running: aclocal -I m4 --force -I m4  
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: /usr/bin/autoconf --include=m4 --force
configure.ac:429: error: possibly undefined macro: AC_CHECK_HEADERS
  If this token and others are legitimate, please use m4_pattern_allow.
  See the Autoconf documentation.
configure.ac:520: error: possibly undefined macro: AC_LINK_IFELSE
configure.ac:1631: error: possibly undefined macro: AC_LANG_CALL
autoreconf: error: /usr/bin/autoconf failed with exit status: 1
./bootstrap: autoreconf failed

Does anyone know how to address this issue?

Thanks,
Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

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