aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Schuchardt2024-07-13 13:30:29 +0200
committerHeinrich Schuchardt2024-07-19 13:43:50 +0200
commit5c1b5e6bc59a047c2ac65b2c22a2b511658b0f15 (patch)
tree3db036f27cb7094c1a34714c3eb684611dcd6aed
parent7aab2b6c1f9cff9d7f1192651ea81b6855b28a33 (diff)
efi_loader: find distro device-path for media devices
The auto-generated load options for media device do not contain a partition node. We cannot expect the simple file protocol here. Get the partition device-path via the loaded image protocol. Fixes: e91b68fd6b83 ("efi_loader: load distro dtb in bootmgr") Reported-by: E Shattow <lucent@gmail.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Tested-by: E Shattow <lucent@gmail.com>
-rw-r--r--include/efi_loader.h2
-rw-r--r--lib/efi_loader/efi_bootmgr.c2
-rw-r--r--lib/efi_loader/efi_fdt.c33
3 files changed, 21 insertions, 16 deletions
diff --git a/include/efi_loader.h b/include/efi_loader.h
index ca8fc0820f6..f2e5063a970 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -1195,6 +1195,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);
+void efi_load_distro_fdt(efi_handle_t handle, void **fdt, efi_uintn_t *fdt_size);
#endif /* _EFI_LOADER_H */
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 304ed43595c..589d3996b68 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -1277,7 +1277,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
if (fdt_lo)
fdt = fdt_lo;
if (!fdt) {
- efi_load_distro_fdt(&fdt_distro, &fdt_size);
+ efi_load_distro_fdt(handle, &fdt_distro, &fdt_size);
fdt = fdt_distro;
}
}
diff --git a/lib/efi_loader/efi_fdt.c b/lib/efi_loader/efi_fdt.c
index 86ba00c2bdd..4ccf2055be3 100644
--- a/lib/efi_loader/efi_fdt.c
+++ b/lib/efi_loader/efi_fdt.c
@@ -75,28 +75,34 @@ int efi_get_distro_fdt_name(char *fname, int size, int seq)
/**
* efi_load_distro_fdt() - load distro device-tree
*
+ * @handle: handle of loaded image
* @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)
+void efi_load_distro_fdt(efi_handle_t handle, void **fdt, efi_uintn_t *fdt_size)
{
- struct efi_device_path *rem, *dp;
+ struct efi_device_path *dp;
efi_status_t ret;
+ struct efi_handler *handler;
+ struct efi_loaded_image *loaded_image;
efi_handle_t device;
*fdt = NULL;
- dp = efi_get_dp_from_boot(NULL);
- if (!dp)
+ /* Get boot device from loaded image protocol */
+ ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler);
+ if (ret != EFI_SUCCESS)
return;
- device = efi_dp_find_obj(dp, NULL, &rem);
- ret = efi_search_protocol(device, &efi_simple_file_system_protocol_guid,
- NULL);
+ loaded_image = handler->protocol_interface;
+ device = loaded_image->device_handle;
+
+ /* Get device path of boot device */
+ ret = efi_search_protocol(device, &efi_guid_device_path, &handler);
if (ret != EFI_SUCCESS)
- goto err;
- memcpy(rem, &END, sizeof(END));
+ return;
+ dp = handler->protocol_interface;
- /* try the various available names */
+ /* Try the various available names */
for (int seq = 0; ; ++seq) {
struct efi_device_path *file;
char buf[255];
@@ -108,10 +114,9 @@ void efi_load_distro_fdt(void **fdt, efi_uintn_t *fdt_size)
break;
ret = efi_load_image_from_path(true, file, fdt, fdt_size);
efi_free_pool(file);
- if (ret == EFI_SUCCESS)
+ if (ret == EFI_SUCCESS) {
+ log_debug("Fdt %pD loaded\n", file);
break;
+ }
}
-
-err:
- efi_free_pool(dp);
}