Skip to contentSkip to conversation

efi/libstub: populate LoaderDevicePartUUID

PATCH Superseded Vincent Mailhol 2 participants 4 messages Sep 3 – Sep 5 EFI

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi/libstub: populate LoaderDevicePartUUID

The Boot Loader Interface [1] defines LoaderDevicePartUUID. That EFI variable records the GPT partition UUID of the partition containing the boot loader.

This is used, for example, by systemd-gpt-auto-generator [2] to identify the disk the boot loader was launched from and automatically detect and mount partitions on it.

GRUB [3] and systemd-boot [4] populate it, but when the kernel is started directly by EFI firmware, there is no conventional external boot loader to provide the variable. In that case, because the EFI stub performs the boot loader role, it should provide the variable itself.

Parse the loaded image device path, extract the GUID signature from its GPT HD() node and publish it under the Linux loader entry vendor GUID as the volatile LoaderDevicePartUUID EFI variable. Do not overwrite an existing variable, so a value supplied by an earlier boot stage keeps precedence.

Install the efi_bli_set_variables() hook in both the generic efi-stub.c path and the x86-specific x86-stub.c path.

Add CONFIG_EFI_STUB_BLI to make this new feature configurable.

For an x86_64 build using gcc 15.3.0, bloat-o-meter reports the following difference between builds without and with CONFIG_EFI_STUB_BLI:

add/remove: 5/0 grow/shrink: 1/0 up/down: 639/0 (639)
Function old new delta

  efi_bli_set_variables                          -     563    +563
  loader_entry_guid                              -      16     +16
  hex                                            -      16     +16
  guid_index                                     -      16     +16
  device_path_guid                               -      16     +16

efi_stub_entry 4180 4192 +12
Total: Before=29223, After=29862, chg +2.19%

[1] The Boot Loader Interface

[2] systemd-gpt-auto-generator

[3] GRUB -- §16.2 bli

[4] systemd -- systemd-boot UEFI Boot Manager

---
Changes in v2:

- Add CONFIG_EFI_STUB_BLI to make the BLI feature optional.

- Use static storage for GUID initializers. This reduces the size by about 10% compared to v1.

- Remove the redundant NULL check on image.

- Move the nibble-to-ASCII-hex conversion out of efi_bli_guid_to_str() into the new efi_bli_nibble_to_hex().

- Rename variables to be closer to the EFI specification.

Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/firmware/efi/Kconfig            |  15 +++++
 drivers/firmware/efi/libstub/Makefile   |   2 +
 drivers/firmware/efi/libstub/bli.c      | 114 ++++++++++++++++++++++++++++++++
 drivers/firmware/efi/libstub/efi-stub.c |   1 +
 drivers/firmware/efi/libstub/efistub.h  |   6 ++
 drivers/firmware/efi/libstub/x86-stub.c |   1 +
 6 files changed, 139 insertions(+)
drivers/firmware/efi/Kconfig +15 -0
index 29e0729299f5..eff7c6164096 100644
@@ -100,6 +100,21 @@ config EFI_ARMSTUB_DTB_LOADER
 	  functionality for bootloaders that do not have such support
 	  this option is necessary.
 
+config EFI_STUB_BLI
+	bool "EFI stub Boot Loader Interface support"
+	depends on EFI_STUB
+	default y
+	help
+	  The Boot Loader Interface defines EFI variables that expose
+	  information about the boot loader to the running OS.
+
+	  Enable this option to let the EFI stub populate the volatile
+	  LoaderDevicePartUUID EFI variable when it is missing. This allows
+	  user space services such as systemd-gpt-auto-generator to discover
+	  partitions on the disk from which the kernel was loaded.
+
+	  If unsure, say Y.
+
 config EFI_BOOTLOADER_CONTROL
 	tristate "EFI Bootloader Control"
 	select UCS2_STRING
drivers/firmware/efi/libstub/Makefile +2 -0
index 77a2b2d74f3f..000a73a4bc52 100644
@@ -75,6 +75,8 @@ libfdt-deps			:= fdt_rw.c fdt_ro.c fdt_wip.c fdt.c \
 lib-$(CONFIG_EFI_PARAMS_FROM_FDT) += fdt.o \
 				     $(patsubst %.c,lib-%.o,$(libfdt-deps))
 
+lib-$(CONFIG_EFI_STUB_BLI)	+= bli.o
+
 $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
 	$(call if_changed_rule,cc_o_c)
 
drivers/firmware/efi/libstub/bli.c new file +114 -0

114 lines not on this page · raw message

drivers/firmware/efi/libstub/efi-stub.c +1 -0
index 42d6073bcd06..2a95f4ea104a 100644
@@ -165,6 +165,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
 	dpy = setup_primary_display();
 
 	efi_retrieve_eventlog();
+	efi_bli_set_variables(image);
 
 	/* Ask the firmware to clear memory on unclean shutdown */
 	efi_enable_reset_attack_mitigation();
drivers/firmware/efi/libstub/efistub.h +6 -0
index fd91fc15ec81..a4f961ea43a8 100644
@@ -1072,6 +1072,12 @@ efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
 			      int memory_type, unsigned long alloc_min,
 			      unsigned long alloc_max);
 
+#ifdef CONFIG_EFI_STUB_BLI
+void efi_bli_set_variables(efi_loaded_image_t *image);
+#else
+static inline void efi_bli_set_variables(efi_loaded_image_t *image) { }
+#endif
+
 efi_status_t efi_random_get_seed(void);
 
 efi_status_t check_platform_features(void);
drivers/firmware/efi/libstub/x86-stub.c +1 -0
index cef32e2c82d8..b762f7f37f28 100644
@@ -1014,6 +1014,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
 	efi_random_get_seed();
 
 	efi_retrieve_eventlog();
+	efi_bli_set_variables(image);
 
 	setup_graphics(boot_params);
 

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260724-efi_stub_bli-477289050225

Best regards,

Signature · 1 line
Vincent Mailhol <[email protected]>
maintainer
#1 lore raw

Hello Vincent,

Quoted 4 lines · Vincent Mailhol

The Boot Loader Interface [1] defines LoaderDevicePartUUID. That EFI variable records the GPT partition UUID of the partition containing the boot loader.

Quoted 9 lines

This is used, for example, by systemd-gpt-auto-generator [2] to identify the disk the boot loader was launched from and automatically detect and mount partitions on it.

GRUB [3] and systemd-boot [4] populate it, but when the kernel is started directly by EFI firmware, there is no conventional external boot loader to provide the variable. In that case, because the EFI stub performs the boot loader role, it should provide the variable itself.

Fair enough.

But shouldn't it set LoaderInfo as well then?

Quoted 11 lines

Parse the loaded image device path, extract the GUID signature from its GPT HD() node and publish it under the Linux loader entry vendor GUID as the volatile LoaderDevicePartUUID EFI variable. Do not overwrite an existing variable, so a value supplied by an earlier boot stage keeps precedence.

Install the efi_bli_set_variables() hook in both the generic efi-stub.c path and the x86-specific x86-stub.c path.

Add CONFIG_EFI_STUB_BLI to make this new feature configurable.

I don't think this is needed tbh. Better to enable this unconditionally so we can rely on this being present in the longer term.

Quoted 110 lines

For an x86_64 build using gcc 15.3.0, bloat-o-meter reports the following difference between builds without and with CONFIG_EFI_STUB_BLI:

add/remove: 5/0 grow/shrink: 1/0 up/down: 639/0 (639)
Function old new delta

  efi_bli_set_variables                          -     563    +563
  loader_entry_guid                              -      16     +16
  hex                                            -      16     +16
  guid_index                                     -      16     +16
  device_path_guid                               -      16     +16

efi_stub_entry 4180 4192 +12
Total: Before=29223, After=29862, chg +2.19%

[1] The Boot Loader Interface

[2] systemd-gpt-auto-generator
Link:
https://www.freedesktop.org/software/systemd/man/latest/systemd-gpt-auto-generator.html

[3] GRUB -- §16.2 bli
Link:
https://www.gnu.org/software/grub/manual/grub/html_node/bli_005fmodule.html

[4] systemd -- systemd-boot UEFI Boot Manager

---
Changes in v2:

- Add CONFIG_EFI_STUB_BLI to make the BLI feature optional.

- Use static storage for GUID initializers. This reduces the size by about 10% compared to v1.

- Remove the redundant NULL check on image.

- Move the nibble-to-ASCII-hex conversion out of efi_bli_guid_to_str() into the new efi_bli_nibble_to_hex().

- Rename variables to be closer to the EFI specification.

Link to v1:
https://lore.kernel.org/r/[email protected]

---
 drivers/firmware/efi/Kconfig            |  15 +++++
 drivers/firmware/efi/libstub/Makefile   |   2 +
 drivers/firmware/efi/libstub/bli.c      | 114 
++++++++++++++++++++++++++++++++
 drivers/firmware/efi/libstub/efi-stub.c |   1 +
 drivers/firmware/efi/libstub/efistub.h  |   6 ++
 drivers/firmware/efi/libstub/x86-stub.c |   1 +
 6 files changed, 139 insertions(+)
drivers/firmware/efi/Kconfig +15 -0
index 29e0729299f5..eff7c6164096 100644
@@ -100,6 +100,21 @@ config EFI_ARMSTUB_DTB_LOADER
 	  functionality for bootloaders that do not have such support
 	  this option is necessary.
 
+config EFI_STUB_BLI
+	bool "EFI stub Boot Loader Interface support"
+	depends on EFI_STUB
+	default y
+	help
+	  The Boot Loader Interface defines EFI variables that expose
+	  information about the boot loader to the running OS.
+
+	  Enable this option to let the EFI stub populate the volatile
+	  LoaderDevicePartUUID EFI variable when it is missing. This allows
+	  user space services such as systemd-gpt-auto-generator to discover
+	  partitions on the disk from which the kernel was loaded.
+
+	  If unsure, say Y.
+
 config EFI_BOOTLOADER_CONTROL
 	tristate "EFI Bootloader Control"
 	select UCS2_STRING
drivers/firmware/efi/libstub/Makefile +2 -0
index 77a2b2d74f3f..000a73a4bc52 100644
@@ -75,6 +75,8 @@ libfdt-deps			:= fdt_rw.c fdt_ro.c fdt_wip.c fdt.c \
 lib-$(CONFIG_EFI_PARAMS_FROM_FDT) += fdt.o \
 				     $(patsubst %.c,lib-%.o,$(libfdt-deps))
 
+lib-$(CONFIG_EFI_STUB_BLI)	+= bli.o
+
 $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
 	$(call if_changed_rule,cc_o_c)
 
drivers/firmware/efi/libstub/bli.c new file +8 -0
new file mode 100644
index 000000000000..d54eb42729a7
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/efi.h>
+#include <linux/errno.h>
+#include <linux/unaligned.h>
+
+#include "efistub.h"
+

drivers/firmware/efi/libstub/bli.c line 18

Quoted 10 lines
drivers/firmware/efi/libstub/bli.c new file +10 -0
+struct efi_hd_dev_path {
+	struct efi_generic_dev_path header;
+	u32 partition_number;
+	u64 partition_start;
+	u64 partition_size;
+	efi_guid_t signature;
+	u8 partition_format;
+	u8 signature_type;
+} __packed;
+

Please add this to linux/efi.h and add it to the union in struct efi_dev_path as well.

drivers/firmware/efi/libstub/bli.c line 21

Quoted 3 lines
drivers/firmware/efi/libstub/bli.c new file +3 -0
+#define EFI_HD_PARTITION_FORMAT_GPT	2
+#define EFI_HD_SIGNATURE_TYPE_GUID	2
+

These too

Quoted 22 lines
drivers/firmware/efi/libstub/bli.c new file +8 -0
+static efi_char16_t efi_bli_nibble_to_hex(u8 nibble)
+{
+	static const char hex[16] __nonstring = "0123456789abcdef";
+
+	return hex[nibble];
+}
+
+static void efi_bli_guid_to_str(const efi_guid_t *guid, efi_char16_t 

*out)

drivers/firmware/efi/libstub/bli.c new file +13 -0
+{
+	static const u8 guid_index[UUID_SIZE] = {
+		3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15,
+	};
+
+	for (int i = 0; i < ARRAY_SIZE(guid_index); i++) {
+		u8 byte = guid->b[guid_index[i]];
+
+		*out++ = efi_bli_nibble_to_hex(byte >> 4);
+		*out++ = efi_bli_nibble_to_hex(byte & 0xf);
+
+		switch (i) {
+		case 3:

drivers/firmware/efi/libstub/bli.c line 52

Quoted 10 lines
drivers/firmware/efi/libstub/bli.c new file +10 -0
+		case 5:
+		case 7:
+		case 9:
+			*out++ = L'-';
+		}
+	}
+
+	*out = L'\0';
+}
+

I'm reluctant to add this kind of code as a special one-off, so I got a bit carried away and took this code and put it in the stub's printf layer.

Could you please check whether the first two patches at [0] are sufficient for efi_bli_guid_to_str() to be replaced by a simple efi_snprintf("%pUl", ...) call here?

Signature · 4 lines
Ard.


[0] https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=efi-libstub-native-utf16
#2 lore raw
Quoted 17 lines · Ard Biesheuvel

Hello Vincent,

Quoted 4 lines · Vincent Mailhol

The Boot Loader Interface [1] defines LoaderDevicePartUUID. That EFI variable records the GPT partition UUID of the partition containing the boot loader.

Quoted 9 lines

This is used, for example, by systemd-gpt-auto-generator [2] to identify the disk the boot loader was launched from and automatically detect and mount partitions on it.

GRUB [3] and systemd-boot [4] populate it, but when the kernel is started directly by EFI firmware, there is no conventional external boot loader to provide the variable. In that case, because the EFI stub performs the boot loader role, it should provide the variable itself.

Quoted 3 lines

Fair enough.

But shouldn't it set LoaderInfo as well then?

Sure. This is quite easy to do.

Any preference of what to put in that variable? I am thinking of adding the release number like this:

	#define EFI_BLI_LOADER_INFO L"Linux EFI stub " UTS_RELEASE

This looks consistent with what the other boot loaders are doing:

	$ cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cfb6c7-440b29bb8c4f 
	GRUB 2.12

Also, this gave me an idea. Maybe we can use the LoaderInfo variable as a sentinel for all other variables:

	void efi_bli_set_variables(efi_loaded_image_t *image)
	{
		unsigned long size = 0;

		if (get_efi_var(L"LoaderInfo", &loader_entry_guid,
				NULL, &size, NULL) != EFI_NOT_FOUND)
			return;

		efi_bli_populate_loader_info();
		efi_bli_populate_loader_part_uuid(image);
	}

If it is set, we bail out, otherwise, we assume that the earlier boot stage did not implement BLI and we blindly populate everything. No more additional check on whether LoaderDevicePartUUID or other variables are set!

Does this approach make sense?

Quoted 6 lines
Quoted 6 lines

Parse the loaded image device path, extract the GUID signature from its GPT HD() node and publish it under the Linux loader entry vendor GUID as the volatile LoaderDevicePartUUID EFI variable. Do not overwrite an existing variable, so a value supplied by an earlier boot stage keeps precedence.

Quoted 8 lines
Quoted 5 lines

Install the efi_bli_set_variables() hook in both the generic efi-stub.c path and the x86-specific x86-stub.c path.

Add CONFIG_EFI_STUB_BLI to make this new feature configurable.

I don't think this is needed tbh. Better to enable this unconditionally so we can rely on this being present in the longer term.

Agreed. To be honest, I did not put that in v1. I was just worried that people might complain of the size increase for a feature some might no want to use. But maybe my other cleanup series on the GUID made a more convincing argument on the size!

I will happily remove this in v3.

Quoted 124 lines
Quoted 110 lines

For an x86_64 build using gcc 15.3.0, bloat-o-meter reports the following difference between builds without and with CONFIG_EFI_STUB_BLI:

add/remove: 5/0 grow/shrink: 1/0 up/down: 639/0 (639)
Function old new delta

  efi_bli_set_variables                          -     563    +563
  loader_entry_guid                              -      16     +16
  hex                                            -      16     +16
  guid_index                                     -      16     +16
  device_path_guid                               -      16     +16

efi_stub_entry 4180 4192 +12
Total: Before=29223, After=29862, chg +2.19%

[1] The Boot Loader Interface

[2] systemd-gpt-auto-generator
Link:
https://www.freedesktop.org/software/systemd/man/latest/systemd-gpt-auto-generator.html

[3] GRUB -- §16.2 bli
Link:
https://www.gnu.org/software/grub/manual/grub/html_node/bli_005fmodule.html

[4] systemd -- systemd-boot UEFI Boot Manager

---
Changes in v2:

- Add CONFIG_EFI_STUB_BLI to make the BLI feature optional.

- Use static storage for GUID initializers. This reduces the size by about 10% compared to v1.

- Remove the redundant NULL check on image.

- Move the nibble-to-ASCII-hex conversion out of efi_bli_guid_to_str() into the new efi_bli_nibble_to_hex().

- Rename variables to be closer to the EFI specification.

Link to v1:
https://lore.kernel.org/r/[email protected]

---
 drivers/firmware/efi/Kconfig            |  15 +++++
 drivers/firmware/efi/libstub/Makefile   |   2 +
 drivers/firmware/efi/libstub/bli.c      | 114 
++++++++++++++++++++++++++++++++
 drivers/firmware/efi/libstub/efi-stub.c |   1 +
 drivers/firmware/efi/libstub/efistub.h  |   6 ++
 drivers/firmware/efi/libstub/x86-stub.c |   1 +
 6 files changed, 139 insertions(+)
drivers/firmware/efi/Kconfig +15 -0
index 29e0729299f5..eff7c6164096 100644
@@ -100,6 +100,21 @@ config EFI_ARMSTUB_DTB_LOADER
 	  functionality for bootloaders that do not have such support
 	  this option is necessary.
 
+config EFI_STUB_BLI
+	bool "EFI stub Boot Loader Interface support"
+	depends on EFI_STUB
+	default y
+	help
+	  The Boot Loader Interface defines EFI variables that expose
+	  information about the boot loader to the running OS.
+
+	  Enable this option to let the EFI stub populate the volatile
+	  LoaderDevicePartUUID EFI variable when it is missing. This allows
+	  user space services such as systemd-gpt-auto-generator to discover
+	  partitions on the disk from which the kernel was loaded.
+
+	  If unsure, say Y.
+
 config EFI_BOOTLOADER_CONTROL
 	tristate "EFI Bootloader Control"
 	select UCS2_STRING
drivers/firmware/efi/libstub/Makefile +2 -0
index 77a2b2d74f3f..000a73a4bc52 100644
@@ -75,6 +75,8 @@ libfdt-deps			:= fdt_rw.c fdt_ro.c fdt_wip.c fdt.c \
 lib-$(CONFIG_EFI_PARAMS_FROM_FDT) += fdt.o \
 				     $(patsubst %.c,lib-%.o,$(libfdt-deps))
 
+lib-$(CONFIG_EFI_STUB_BLI)	+= bli.o
+
 $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
 	$(call if_changed_rule,cc_o_c)
 
drivers/firmware/efi/libstub/bli.c new file +8 -0
new file mode 100644
index 000000000000..d54eb42729a7
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/efi.h>
+#include <linux/errno.h>
+#include <linux/unaligned.h>
+
+#include "efistub.h"
+

drivers/firmware/efi/libstub/bli.c line 18

Quoted 10 lines
drivers/firmware/efi/libstub/bli.c new file +10 -0
+struct efi_hd_dev_path {
+	struct efi_generic_dev_path header;
+	u32 partition_number;
+	u64 partition_start;
+	u64 partition_size;
+	efi_guid_t signature;
+	u8 partition_format;
+	u8 signature_type;
+} __packed;
+

Please add this to linux/efi.h and add it to the union in struct efi_dev_path as well.

Quoted 5 lines

drivers/firmware/efi/libstub/bli.c line 21

Quoted 3 lines
drivers/firmware/efi/libstub/bli.c new file +3 -0
+#define EFI_HD_PARTITION_FORMAT_GPT	2
+#define EFI_HD_SIGNATURE_TYPE_GUID	2
+

These too

Ack.

Quoted 28 lines
Quoted 28 lines
drivers/firmware/efi/libstub/bli.c new file +8 -0
+static efi_char16_t efi_bli_nibble_to_hex(u8 nibble)
+{
+	static const char hex[16] __nonstring = "0123456789abcdef";
+
+	return hex[nibble];
+}
+
+static void efi_bli_guid_to_str(const efi_guid_t *guid, efi_char16_t 

*out)

drivers/firmware/efi/libstub/bli.c new file +19 -0
+{
+	static const u8 guid_index[UUID_SIZE] = {
+		3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15,
+	};
+
+	for (int i = 0; i < ARRAY_SIZE(guid_index); i++) {
+		u8 byte = guid->b[guid_index[i]];
+
+		*out++ = efi_bli_nibble_to_hex(byte >> 4);
+		*out++ = efi_bli_nibble_to_hex(byte & 0xf);
+
+		switch (i) {
+		case 3:
+		case 5:
+		case 7:
+		case 9:
+			*out++ = L'-';
+		}
+	}
Quoted 8 lines

drivers/firmware/efi/libstub/bli.c line 52

Quoted 4 lines
drivers/firmware/efi/libstub/bli.c new file +4 -0
+
+	*out = L'\0';
+}
+

I'm reluctant to add this kind of code as a special one-off, so I got a bit carried away and took this code and put it in the stub's printf layer.

Thanks for the extra work!

Quoted 3 lines

Could you please check whether the first two patches at [0] are sufficient for efi_bli_guid_to_str() to be replaced by a simple efi_snprintf("%pUl", ...) call here?

Ack. I already rebased and did a compile test, OK so far. The runtime test will come later. If I find an issue, I will send you a fix. If not, I will just send the v3 rebased on top of your efi-libstub-native-utf16 branch.

Yours sincerely,
Vincent Mailhol

#3 lore raw
Quoted 49 lines · Vincent Mailhol
Quoted 17 lines · Ard Biesheuvel

Hello Vincent,

Quoted 4 lines · Vincent Mailhol

The Boot Loader Interface [1] defines LoaderDevicePartUUID. That EFI variable records the GPT partition UUID of the partition containing the boot loader.

Quoted 9 lines

This is used, for example, by systemd-gpt-auto-generator [2] to identify the disk the boot loader was launched from and automatically detect and mount partitions on it.

GRUB [3] and systemd-boot [4] populate it, but when the kernel is started directly by EFI firmware, there is no conventional external boot loader to provide the variable. In that case, because the EFI stub performs the boot loader role, it should provide the variable itself.

Quoted 3 lines

Fair enough.

But shouldn't it set LoaderInfo as well then?

Sure. This is quite easy to do.

Any preference of what to put in that variable? I am thinking of adding the release number like this:

	#define EFI_BLI_LOADER_INFO L"Linux EFI stub " UTS_RELEASE

This looks consistent with what the other boot loaders are doing:

	$ cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cfb6c7-440b29bb8c4f 
	GRUB 2.12

Also, this gave me an idea. Maybe we can use the LoaderInfo variable as a sentinel for all other variables:

	void efi_bli_set_variables(efi_loaded_image_t *image)
	{
		unsigned long size = 0;

		if (get_efi_var(L"LoaderInfo", &loader_entry_guid,
				NULL, &size, NULL) != EFI_NOT_FOUND)
			return;

		efi_bli_populate_loader_info();
		efi_bli_populate_loader_part_uuid(image);
	}
Quoted 4 lines

If it is set, we bail out, otherwise, we assume that the earlier boot stage did not implement BLI and we blindly populate everything. No more additional check on whether LoaderDevicePartUUID or other variables are set!

FYI, this is my latest WIP:

	void efi_bli_set_variables(efi_loaded_image_t *image)
	{
		static efi_char16_t loader_info[] = L"Linux EFI stub " UTS_RELEASE;
		unsigned long size = 0;
	
		if (get_efi_var(L"LoaderInfo", &loader_entry_guid,
				NULL, &size, NULL) != EFI_NOT_FOUND)
			return;
	
		if (set_efi_var(L"LoaderInfo", &loader_entry_guid,
				EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
				sizeof(loader_info), loader_info) != EFI_SUCCESS)
			return;
	
		efi_bli_populate_loader_part_uuid(image);
	}

The idea is that the sentinel check will not only be the presence of LoaderInfo but also the fact that we could successfully set it. The other variables (LoaderDevicePartUUID and whatever might comme in the future) are set without further check and failure to set them is silencely ignored.

Quoted 1 line

Does this approach make sense?

(...)

Quoted 6 lines
Quoted 3 lines

I'm reluctant to add this kind of code as a special one-off, so I got a bit carried away and took this code and put it in the stub's printf layer.

Thanks for the extra work!

Quoted 8 lines
Quoted 3 lines

Could you please check whether the first two patches at [0] are sufficient for efi_bli_guid_to_str() to be replaced by a simple efi_snprintf("%pUl", ...) call here?

Ack. I already rebased and did a compile test, OK so far. The runtime test will come later. If I find an issue, I will send you a fix. If not, I will just send the v3 rebased on top of your efi-libstub-native-utf16 branch.

I spoke a bit too quick. Compiling

drivers/firmware/efi/libstub/lib.a

worked well, but in a full build,

arch/x86/boot/compressed/error.c

failed to link because it expects libstub to provide vsnprintf() (c.f. comment above panic()) which you removed in commit edbd49dfea2a ("efi/libstub: Add widestring support to vsnprintf()").

You need to squash this in that commit:

---8<---

drivers/firmware/efi/libstub/vsprintf.c +5 -0
index 521bdace031df..337326ce00488 100644
@@ -663,6 +663,11 @@ int snprintf(char *buf, size_t size, const char *fmt, ...)
 	return i;
 }
 
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
+{
+	return efi_vsnprintf(buf, size, fmt, args, false, false);
+}
+
 int efi_snprintf(efi_char16_t *buf, size_t size, const char *fmt, ...)
 {
 	va_list args;

---8<---

or modify arch/x86/boot/compressed/error.c to take another vsnprintf() variant.

Yours sincerely,
Vincent Mailhol