efi_loader: bootbin: do not load an initrd if none is provided

Do not try to create an initrd device path nor try to register
an initrd with the EFI_LOAD_FILE2_PROTOCOL if none is provided.

Handle initrd installation in efi_binary_run_dp with
efi_install_initrd, imitating what is done for the fdt.

Fixes: 36835a9105 ("efi_loader: binary_run: register an initrd")
Reported-by: Weizhao Ouyang <o451686892@gmail.com>
Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
Tested-by: Weizhao Ouyang <o451686892@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Adriano Cordova
2025-05-01 09:19:24 +02:00
committed by Heinrich Schuchardt
parent a4af308e4a
commit 24600fd068
3 changed files with 32 additions and 6 deletions
+2
View File
@@ -597,6 +597,8 @@ efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
void *efi_get_configuration_table(const efi_guid_t *guid);
/* Install device tree */
efi_status_t efi_install_fdt(void *fdt);
/* Install initrd */
efi_status_t efi_install_initrd(void *initrd, size_t initd_sz);
/* Execute loaded UEFI image */
efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options);
/* Run loaded UEFI image with given fdt */
+1 -6
View File
@@ -220,7 +220,6 @@ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt,
struct efi_device_path *dp_img)
{
efi_status_t ret;
struct efi_device_path *dp_initrd;
/* Initialize EFI drivers */
ret = efi_init_obj_list();
@@ -234,11 +233,7 @@ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt,
if (ret != EFI_SUCCESS)
return ret;
dp_initrd = efi_dp_from_mem(EFI_LOADER_DATA, (uintptr_t)initrd, initd_sz);
if (!dp_initrd)
return EFI_OUT_OF_RESOURCES;
ret = efi_initrd_register(dp_initrd);
ret = efi_install_initrd(initrd, initd_sz);
if (ret != EFI_SUCCESS)
return ret;
+29
View File
@@ -622,6 +622,35 @@ efi_status_t efi_install_fdt(void *fdt)
return EFI_SUCCESS;
}
/**
* efi_install_initrd() - install initrd
*
* Install the initrd located at @initrd using the EFI_LOAD_FILE2
* protocol.
*
* @initrd: address of initrd or NULL if none is provided
* @initrd_sz: size of initrd
* Return: status code
*/
efi_status_t efi_install_initrd(void *initrd, size_t initd_sz)
{
efi_status_t ret;
struct efi_device_path *dp_initrd;
if (!initrd)
return EFI_SUCCESS;
dp_initrd = efi_dp_from_mem(EFI_LOADER_DATA, (uintptr_t)initrd, initd_sz);
if (!dp_initrd)
return EFI_OUT_OF_RESOURCES;
ret = efi_initrd_register(dp_initrd);
if (ret != EFI_SUCCESS)
efi_free_pool(dp_initrd);
return ret;
}
/**
* do_bootefi_exec() - execute EFI binary
*