public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH v2 1/1] efi_loader: expose the device-tree file name
@ 2023-10-17 13:49 Heinrich Schuchardt
  2023-10-17 14:15 ` Ilias Apalodimas
  2023-10-18  3:33 ` Simon Glass
  0 siblings, 2 replies; 26+ messages in thread
From: Heinrich Schuchardt @ 2023-10-17 13:49 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

Forward and backward compatibility of Linux kernel device-trees is
sometimes missing. One solution approach is to load a kernel specific
device-tree. This can either be done via a U-Boot scripts (like the one
generated by Debian package flash-kernel or by a boot loader like GRUB.
The boot loader approach currently requires to know the device-tree name
before first boot which makes it unusable for generic images.

Expose the device-tree file name as EFI variable FdtFile.
This will allow bootloaders to load a kernel specific device-tree.

The variable will not be exposed on ACPI based systems or if the
environment variable fdtfile is not defined.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
v2:
	Use a unique GUID to enable future U-Boot independent
	standardization.
	Do not try to add the variable on ACPI based systems.
---
 include/efi_loader.h       |  5 +++++
 lib/efi_loader/efi_setup.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index e24410505f..2faa1c191c 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -152,6 +152,11 @@ static inline efi_status_t efi_launch_capsules(void)
 	EFI_GUID(0x8108ac4e, 0x9f11, 0x4d59, \
 		 0x85, 0x0e, 0xe2, 0x1a, 0x52, 0x2c, 0x59, 0xb2)
 
+/* Vendor GUID for the FdtFile variable */
+#define VENDOR_FDTFILE_GUID \
+	EFI_GUID(d45dde69, 0x3bd6, 0x40e0, \
+		 0x90, 0xd5, 0x6b, 0x60, 0x6a, 0xa5, 0x77, 0x30)
+
 /* Use internal device tree when starting UEFI application */
 #define EFI_FDT_USE_INTERNAL NULL
 
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index e6de685e87..71bcde645b 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -17,6 +17,8 @@
 
 efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
 
+efi_guid_t vendor_fdtfile_guid = VENDOR_FDTFILE_GUID;
+
 /*
  * Allow unaligned memory access.
  *
@@ -26,6 +28,27 @@ void __weak allow_unaligned(void)
 {
 }
 
+/**
+ * efi_init_fdtfile() - set EFI variable FdtFile
+ *
+ * Return:	status code
+ */
+static efi_status_t efi_init_fdtfile(void)
+{
+	char *val;
+
+	val = env_get("fdtfile");
+	if (!val)
+		return EFI_SUCCESS;
+
+	return efi_set_variable_int(u"FdtFile",
+				    &vendor_fdtfile_guid,
+				    EFI_VARIABLE_BOOTSERVICE_ACCESS |
+				    EFI_VARIABLE_RUNTIME_ACCESS |
+				    EFI_VARIABLE_READ_ONLY,
+				    strlen(val) + 1, val, false);
+}
+
 /**
  * efi_init_platform_lang() - define supported languages
  *
@@ -250,6 +273,13 @@ efi_status_t efi_init_obj_list(void)
 	if (ret != EFI_SUCCESS)
 		goto out;
 
+	/* Define EFI variable FdtFile */
+	if (!CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)) {
+		ret = efi_init_fdtfile();
+		if (ret != EFI_SUCCESS)
+			goto out;
+	}
+
 	/* Indicate supported features */
 	ret = efi_init_os_indications();
 	if (ret != EFI_SUCCESS)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2023-12-31 14:25 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-17 13:49 [PATCH v2 1/1] efi_loader: expose the device-tree file name Heinrich Schuchardt
2023-10-17 14:15 ` Ilias Apalodimas
2023-10-18  3:33 ` Simon Glass
2023-10-18  8:15   ` Heinrich Schuchardt
2023-10-19 13:55     ` Simon Glass
2023-10-19 14:14       ` Mark Kettenis
2023-10-19 16:09       ` Heinrich Schuchardt
2023-10-20 13:21         ` Simon Glass
2023-10-20 13:55           ` Tom Rini
2023-10-20 15:40           ` Heinrich Schuchardt
2023-10-20 16:24             ` Tom Rini
2023-10-21 15:42               ` Simon Glass
2023-10-22  4:53                 ` Heinrich Schuchardt
2023-10-23  7:08                   ` Simon Glass
2023-10-23  8:10                     ` Heinrich Schuchardt
2023-10-23 15:37                     ` Mark Kettenis
2023-10-23 16:34                       ` Tom Rini
2023-10-23 17:05                         ` Mark Kettenis
2023-11-03 19:17                           ` Simon Glass
2023-11-03 19:42                             ` Ilias Apalodimas
2023-11-03 20:00                             ` Ilias Apalodimas
2023-11-03 20:03                             ` Tom Rini
2023-11-14 19:09                             ` Mark Kettenis
2023-11-14 23:20                               ` Tom Rini
2023-12-31 14:25                       ` Peter Robinson
2023-10-20 21:19           ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox