diff options
| author | Adriano Cordova <[email protected]> | 2025-04-29 09:27:55 -0400 |
|---|---|---|
| committer | Heinrich Schuchardt <[email protected]> | 2025-05-01 09:19:24 +0200 |
| commit | 24600fd06801a23151dfc309867278212e775f65 (patch) | |
| tree | 4d3b1b47ad3d146b07a176250d986c2ce9f5fec3 /lib | |
| parent | a4af308e4acdcf0840226fc4f631e3aa0326699a (diff) | |
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: 36835a9105c ("efi_loader: binary_run: register an initrd")
Reported-by: Weizhao Ouyang <[email protected]>
Signed-off-by: Adriano Cordova <[email protected]>
Tested-by: Weizhao Ouyang <[email protected]>
Reviewed-by: Ilias Apalodimas <[email protected]>
Reviewed-by: Heinrich Schuchardt <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/efi_loader/efi_bootbin.c | 7 | ||||
| -rw-r--r-- | lib/efi_loader/efi_helper.c | 29 |
2 files changed, 30 insertions, 6 deletions
diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index d0f7da309ce..6a189c31ffa 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -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; diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 3936139ca41..19fb5d03fec 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -623,6 +623,35 @@ efi_status_t efi_install_fdt(void *fdt) } /** + * 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 * * The image indicated by @handle is started. When it returns the allocated |
