[RFC 10/14] efi_loader: load device-tree specified in boot option

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed May 22 08:28:57 CEST 2024


On Fri, Apr 26, 2024 at 04:13:17PM +0200, Heinrich Schuchardt wrote:
> We allow to specify the triple of binary, initrd, and device-tree in boot
> options.
>
> Add the code to actually load the specified device-tree.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
>  lib/efi_loader/efi_bootmgr.c | 57 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 56 insertions(+), 1 deletion(-)
>
> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> index d924810a94b..3d58a928b10 100644
> --- a/lib/efi_loader/efi_bootmgr.c
> +++ b/lib/efi_loader/efi_bootmgr.c
> @@ -1185,6 +1185,55 @@ out:
>  	return ret;
>  }
>
> +/**
> + * load_fdt_from_load_option - load device-tree from load option
> + *
> + * Return:	pointer to loaded device-tree or NULL
> + */
> +static void *load_fdt_from_load_option(void)
> +{
> +	struct efi_device_path *dp = NULL;
> +	struct efi_file_handle *f = NULL;
> +	efi_uintn_t filesize;
> +	void *buffer;
> +	efi_status_t ret;
> +
> +	dp = efi_get_dp_from_boot(&efi_guid_fdt);
> +	if (!dp)
> +		return NULL;
> +
> +	/* Open file */
> +	f = efi_file_from_path(dp);
> +	if (!f) {
> +		log_err("Can't find fdt specified in Boot####\n");
> +		goto out;
> +	}
> +
> +	/* Get file size */
> +	ret = efi_file_size(f, &filesize);
> +	if (ret != EFI_SUCCESS)
> +		goto out;
> +
> +	buffer = malloc(filesize);
> +	if (!buffer) {
> +		log_err("Out of memory\n");
> +		goto out;
> +	}
> +	ret = EFI_CALL(f->read(f, &filesize, (void *)buffer));
> +	if (ret != EFI_SUCCESS) {
> +		log_err("Can't read fdt\n");
> +		free(buffer);
> +		buffer = NULL;
> +	}
> +
> +out:
> +	efi_free_pool(dp);
> +	if (f)
> +		EFI_CALL(f->close(f));
> +
> +	return buffer;
> +}
> +
>  /**
>   * efi_bootmgr_run() - execute EFI boot manager
>   * @fdt:	Flat device tree
> @@ -1200,6 +1249,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
>  	efi_handle_t handle;
>  	void *load_options;
>  	efi_status_t ret;
> +	void *fdt_lo;
>
>  	/* Initialize EFI drivers */
>  	ret = efi_init_obj_list();
> @@ -1215,9 +1265,14 @@ efi_status_t efi_bootmgr_run(void *fdt)
>  		return ret;
>  	}
>
> +	fdt_lo = load_fdt_from_load_option();
> +	if (fdt_lo)
> +		fdt = fdt_lo;
> +
>  	ret = efi_install_fdt(fdt);
> +	free(fdt_lo);
>  	if (ret != EFI_SUCCESS) {
> -		if (EFI_CALL(efi_unload_image(*handle)) == EFI_SUCCESS)
> +		if (EFI_CALL(efi_unload_image(handle)) == EFI_SUCCESS)

You don't need this change. The *handle was a typo in patch #9

Thanks
/Ilias
>  			free(load_options);
>  		else
>  			log_err("Unloading image failed\n");
> --
> 2.43.0
>


More information about the U-Boot mailing list