[v4, 3/5] misc: fw_loader: implement generic get_fw_loader_from_node()

Simon Glass sjg at chromium.org
Thu Apr 2 01:25:05 CEST 2026


Hi Christian,

On 2026-03-31T07:53:19, Christian Marangi <ansuelsmth at gmail.com> wrote:
> misc: fw_loader: implement generic get_fw_loader_from_node()
> misc: fw_loader: implement generic get_fw_loader_from_node()
>
> 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>
> Reviewed-by: Neha Malcom Francis <n-francis at ti.com>

> diff --git a/drivers/misc/fw_loader/fw_loader.c b/drivers/misc/fw_loader/fw_loader.c
> @@ -90,6 +91,45 @@ int generic_fw_loader_probe(struct udevice *dev)
> +static int fw_loaders[] = {

This should be const.

> diff --git a/drivers/misc/fw_loader/fw_loader.c b/drivers/misc/fw_loader/fw_loader.c
> @@ -90,6 +91,45 @@ int generic_fw_loader_probe(struct udevice *dev)
> +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;
> +}

Hmm, looping over uclasses is not the right approach here.
uclass_get_device_by_ofnode() will find the device if it exists in the
specified uclass, so if a device with the given ofnode exists, it can
only be in one uclass. Looping seem unnecessary and a bit odd...

How about using device_find_global_by_ofnode() to find the device
regardless of uclass, then probe it with device_probe() if found?

Regards,
Simon


More information about the U-Boot mailing list