[PATCH v2 3/5] misc: fw_loader: implement generic get_fw_loader_from_node()
Francis, Neha
n-francis at ti.com
Tue Mar 17 07:18:36 CET 2026
On 3/7/2026 12:35 AM, Christian Marangi wrote:
> Implement a generic function to get a FW loader dev from a node.
>
> There is currently only get_fs_loader() but that is limited to chosen
> node and is limited only to FS loader.
>
> Introduce get_fw_loader_from_node() that will parse the
> "firmware-loader" from a specified node and will loop over all the
> available FW loader until one is found (as it will be probed by the
> dedicated compatible)
>
> Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
> ---
> drivers/misc/fw_loader/fw_loader.c | 40 ++++++++++++++++++++++++++++++
> include/fw_loader.h | 15 +++++++++++
> 2 files changed, 55 insertions(+)
>
> diff --git a/drivers/misc/fw_loader/fw_loader.c b/drivers/misc/fw_loader/fw_loader.c
> index 6459ba23a15b..e477a631fae3 100644
> --- a/drivers/misc/fw_loader/fw_loader.c
> +++ b/drivers/misc/fw_loader/fw_loader.c
> @@ -8,6 +8,7 @@
> #include <blk.h>
> #include <linux/types.h>
> #include <dm/device.h>
> +#include <dm/uclass.h>
> #include <fw_loader.h>
>
> #include "internal.h"
> @@ -67,6 +68,45 @@ int generic_fw_loader_probe(struct udevice *dev)
> return 0;
> }
>
> +static int fw_loaders[] = {
> +#if CONFIG_IS_ENABLED(FS_LOADER)
> + UCLASS_FS_FIRMWARE_LOADER,
> +#endif
> +};
> +
> +/**
> + * get_fw_loader_from_node - Get FW loader dev from @node.
> + *
> + * @node: ofnode where "firmware-loader" phandle is stored.
> + * @dev: pointer where to store the FW loader dev.
> + *
> + * Loop over all the supported FW loader and find a matching
> + * one.
> + *
> + * Return: Negative value if fail, 0 for successful.
> + */
> +int get_fw_loader_from_node(ofnode node, struct udevice **dev)
> +{
> + int i, ret;
> +
> + node = ofnode_parse_phandle(node, "firmware-loader", 0);
> + if (!ofnode_valid(node))
> + return -ENODEV;
> +
> + /*
> + * Loop over all the available FW loaders and stop when
> + * found one.
> + */
> + for (i = 0; i < ARRAY_SIZE(fw_loaders); i++) {
> + ret = uclass_get_device_by_ofnode(fw_loaders[i],
> + node, dev);
> + if (!ret)
> + return 0;
> + }
> +
> + return -ENODEV;
> +}
> +
> /**
> * _request_firmware_prepare - Prepare firmware struct.
> *
> diff --git a/include/fw_loader.h b/include/fw_loader.h
> index 56f5e3be6195..7053c7bc6f05 100644
> --- a/include/fw_loader.h
> +++ b/include/fw_loader.h
> @@ -6,8 +6,23 @@
> #ifndef _FW_LOADER_H_
> #define _FW_LOADER_H_
>
> +#include <dm/ofnode_decl.h>
> +
> struct udevice;
>
> +/**
> + * get_fw_loader_from_node - Get FW loader dev from @node.
> + *
> + * @node: ofnode where "firmware-loader" phandle is stored.
> + * @dev: pointer where to store the FW loader dev.
> + *
> + * Loop over all the supported FW loader and find a matching
> + * one.
> + *
> + * Return: Negative value if fail, 0 for successful.
> + */
> +int get_fw_loader_from_node(ofnode node, struct udevice **dev);
> +
> /**
> * request_firmware_into_buf - Load firmware into a previously allocated buffer.
> * @dev: An instance of a driver.
Reviewed-by: Neha Malcom Francis <n-francis at ti.com>
--
Thanking You
Neha Malcom Francis
More information about the U-Boot
mailing list