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.

Signed-off-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com>
---
 lib/efi_loader/efi_setup.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index e6de685e87..b24feb94dc 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -26,6 +26,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",
+                                   &efi_u_boot_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 +271,11 @@ efi_status_t efi_init_obj_list(void)
        if (ret != EFI_SUCCESS)
                goto out;
 
+       /* Define EFI variable FdtFile */
+       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

Reply via email to