]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: load distro dtb in bootmgr
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 26 Apr 2024 14:13:21 +0000 (16:13 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 10 Jun 2024 09:43:37 +0000 (11:43 +0200)
If no device-tree is specified, try to load a device-tree from the boot
device use the $fdtfile concatenated to either of the paths '/dtb/', '/',
'/dtb/current/'.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
include/efi_loader.h
lib/efi_loader/efi_bootmgr.c
lib/efi_loader/efi_fdt.c

index ab7bed22971bb2bdf70392c5547cc449aa36b128..6c993e1a694084bb31c6cee59533f6bc1c1f62a0 100644 (file)
@@ -1205,4 +1205,6 @@ efi_status_t efi_load_option_dp_join(struct efi_device_path **dp,
 
 int efi_get_distro_fdt_name(char *fname, int size, int seq);
 
+void efi_load_distro_fdt(void **fdt, efi_uintn_t *fdt_size);
+
 #endif /* _EFI_LOADER_H */
index 2c140bb70cd63dd776dc8e4fc1673d20af4e5f96..304ed43595c46788c40f8ee3be93b628a4711143 100644 (file)
@@ -1253,7 +1253,8 @@ efi_status_t efi_bootmgr_run(void *fdt)
        efi_handle_t handle;
        void *load_options;
        efi_status_t ret;
-       void *fdt_lo;
+       void *fdt_lo, *fdt_distro = NULL;
+       efi_uintn_t fdt_size;
 
        /* Initialize EFI drivers */
        ret = efi_init_obj_list();
@@ -1275,6 +1276,10 @@ efi_status_t efi_bootmgr_run(void *fdt)
                        return ret;
                if (fdt_lo)
                        fdt = fdt_lo;
+               if (!fdt) {
+                       efi_load_distro_fdt(&fdt_distro, &fdt_size);
+                       fdt = fdt_distro;
+               }
        }
 
        /*
@@ -1283,8 +1288,12 @@ efi_status_t efi_bootmgr_run(void *fdt)
         */
        ret = efi_install_fdt(fdt);
 
-       if (!IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE))
+       if (!IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
                free(fdt_lo);
+               if (fdt_distro)
+                       efi_free_pages((uintptr_t)fdt_distro,
+                                      efi_size_in_pages(fdt_size));
+       }
 
        if (ret != EFI_SUCCESS) {
                if (EFI_CALL(efi_unload_image(handle)) == EFI_SUCCESS)
index 0edf0c1e2fc5a83f3929298314aa4a231deeed99..86ba00c2bdd96648972a8b077489b0a2c214f39f 100644 (file)
@@ -71,3 +71,47 @@ int efi_get_distro_fdt_name(char *fname, int size, int seq)
 
        return 0;
 }
+
+/**
+ * efi_load_distro_fdt() - load distro device-tree
+ *
+ * @fdt:       on return device-tree, must be freed via efi_free_pages()
+ * @fdt_size:  buffer size
+ */
+void efi_load_distro_fdt(void **fdt, efi_uintn_t *fdt_size)
+{
+       struct efi_device_path *rem, *dp;
+       efi_status_t  ret;
+       efi_handle_t device;
+
+       *fdt = NULL;
+
+       dp = efi_get_dp_from_boot(NULL);
+       if (!dp)
+               return;
+       device = efi_dp_find_obj(dp, NULL, &rem);
+       ret = efi_search_protocol(device, &efi_simple_file_system_protocol_guid,
+                                 NULL);
+       if (ret != EFI_SUCCESS)
+               goto err;
+       memcpy(rem, &END, sizeof(END));
+
+       /* try the various available names */
+       for (int seq = 0; ; ++seq) {
+               struct efi_device_path *file;
+               char buf[255];
+
+               if (efi_get_distro_fdt_name(buf, sizeof(buf), seq))
+                       break;
+               file = efi_dp_from_file(dp, buf);
+               if (!file)
+                       break;
+               ret = efi_load_image_from_path(true, file, fdt, fdt_size);
+               efi_free_pool(file);
+               if (ret == EFI_SUCCESS)
+                       break;
+       }
+
+err:
+       efi_free_pool(dp);
+}