[PATCH 3/5] misc: fw_loader: implement generic get_fw_loader_from_node()
Christian Marangi
ansuelsmth at gmail.com
Tue Mar 3 14:29:10 CET 2026
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 | 13 ++++++++++
2 files changed, 53 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..d07306c0674f 100644
--- a/include/fw_loader.h
+++ b/include/fw_loader.h
@@ -8,6 +8,19 @@
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.
--
2.51.0
More information about the U-Boot
mailing list