[U-Boot, v1, 1/1] misc: fs_loader: Add request_firmware_into_buf_via_env API for environment-based firmware loading
Marek Vasut
marek.vasut at mailbox.org
Sun Jul 20 22:47:50 CEST 2025
On 7/20/25 5:04 PM, Lucien.Jheng wrote:
> This commit adds request_firmware_into_buf_via_env() to the fs_loader driver,
> enabling firmware loading into a buffer
> using environment variables for path and size.
> It supports multiple entries via indexed variable names
> (e.g., "fw_dir0", "fw_size0").
> This provides flexible, scriptable firmware loading without hardcoded details.
>
> Signed-off-by: Lucien.Jheng <lucienzx159 at gmail.com>
> ---
> Change log:
> - Re-sending as previous version and add more maintainers to review.
>
> drivers/misc/fs_loader.c | 59 ++++++++++++++++++++++++++++++++++++++++
> include/fs_loader.h | 18 ++++++++++++
> 2 files changed, 77 insertions(+)
>
> diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
> index 66803f4b997..a4f4448f5cc 100644
> --- a/drivers/misc/fs_loader.c
> +++ b/drivers/misc/fs_loader.c
> @@ -228,6 +228,65 @@ int request_firmware_into_buf(struct udevice *dev,
> return ret;
> }
>
> +/**
> + * request_firmware_into_buf_via_env - Load firmware using environment variables.
> + * @dev: An instance of a driver.
> + * @buf: Address of buffer to load firmware into.
> + * @offset: Offset of a file for start reading into buffer.
> + * @fw_index: Index of the firmware entry to load.
> + *
> + * This function loads firmware into the provided buffer using environment
> + * variables to determine the firmware file path, address, and size. It supports
> + * multiple firmware entries by using indexed environment variable names such as
> + * "fw_dir0", "fw_size0", etc.
To make this really scriptable, this code has to run a script which does
the firmware loading and then points the U-Boot code to the buffer with
data in it.
Instead of "fw_index", use "char *script_name" or some such. Then, run
the script. The script should set up two environment variables, call
them e.g. "fw_addr" and "fw_size" or some such . Then, this code should
read the two environment variables, validate them, and possibly copy
their content into $buf . Finally, the code should always unset fw_addr
and fw_size .
Note that request_firmware_into_buf_via_env() should also have 'size'
parameter which describes the maximum size of loaded firmware, so the
code could verify whether the copy of firmware into $buf would write
past the buffer and prevent that.
> + * Return: Size of total read, negative value when error.
> + */
> +int request_firmware_into_buf_via_env(struct udevice *dev,
> + void *buf, u32 offset,
> + unsigned int fw_index)
> +{
I'm sorry for the slow response.
[...]
More information about the U-Boot
mailing list