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: e91b68fd6b ("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>
This commit is contained in:
Heinrich Schuchardt
2024-07-13 13:30:29 +02:00
parent 7aab2b6c1f
commit 5c1b5e6bc5
3 changed files with 22 additions and 17 deletions

View File

@@ -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); 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 */ #endif /* _EFI_LOADER_H */

View File

@@ -1277,7 +1277,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
if (fdt_lo) if (fdt_lo)
fdt = fdt_lo; fdt = fdt_lo;
if (!fdt) { if (!fdt) {
efi_load_distro_fdt(&fdt_distro, &fdt_size); efi_load_distro_fdt(handle, &fdt_distro, &fdt_size);
fdt = fdt_distro; fdt = fdt_distro;
} }
} }

View File

@@ -75,28 +75,34 @@ int efi_get_distro_fdt_name(char *fname, int size, int seq)
/** /**
* efi_load_distro_fdt() - load distro device-tree * 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: on return device-tree, must be freed via efi_free_pages()
* @fdt_size: buffer size * @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; efi_status_t ret;
struct efi_handler *handler;
struct efi_loaded_image *loaded_image;
efi_handle_t device; efi_handle_t device;
*fdt = NULL; *fdt = NULL;
dp = efi_get_dp_from_boot(NULL); /* Get boot device from loaded image protocol */
if (!dp) ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler);
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) if (ret != EFI_SUCCESS)
goto err; return;
memcpy(rem, &END, sizeof(END)); loaded_image = handler->protocol_interface;
device = loaded_image->device_handle;
/* try the various available names */ /* Get device path of boot device */
ret = efi_search_protocol(device, &efi_guid_device_path, &handler);
if (ret != EFI_SUCCESS)
return;
dp = handler->protocol_interface;
/* Try the various available names */
for (int seq = 0; ; ++seq) { for (int seq = 0; ; ++seq) {
struct efi_device_path *file; struct efi_device_path *file;
char buf[255]; char buf[255];
@@ -108,10 +114,9 @@ void efi_load_distro_fdt(void **fdt, efi_uintn_t *fdt_size)
break; break;
ret = efi_load_image_from_path(true, file, fdt, fdt_size); ret = efi_load_image_from_path(true, file, fdt, fdt_size);
efi_free_pool(file); efi_free_pool(file);
if (ret == EFI_SUCCESS) if (ret == EFI_SUCCESS) {
log_debug("Fdt %pD loaded\n", file);
break; break;
}
} }
err:
efi_free_pool(dp);
} }