[PATCH v6 3/6] misc: fw_loader: implement generic get_fw_loader_from_node()
Christian Marangi
ansuelsmth at gmail.com
Thu Apr 9 15:32:59 CEST 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 search and probe a
matching FW loader device, if found.
Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
---
drivers/misc/fw_loader/fw_loader-uclass.c | 23 +++++++++++++++++++++++
include/fw_loader.h | 14 ++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/drivers/misc/fw_loader/fw_loader-uclass.c b/drivers/misc/fw_loader/fw_loader-uclass.c
index 16a1fe2d4a65..c32c213b5b38 100644
--- a/drivers/misc/fw_loader/fw_loader-uclass.c
+++ b/drivers/misc/fw_loader/fw_loader-uclass.c
@@ -9,6 +9,8 @@
#include <linux/types.h>
#include <dm.h>
#include <dm/device.h>
+#include <dm/device-internal.h>
+#include <dm/uclass.h>
#include <fw_loader.h>
#ifdef CONFIG_CMD_UBIFS
@@ -96,6 +98,27 @@ UCLASS_DRIVER(fw_loader) = {
.per_device_auto = sizeof(struct firmware),
};
+int get_fw_loader_from_node(ofnode node, struct udevice **dev)
+{
+ struct udevice *fw_dev;
+ int ret;
+
+ node = ofnode_parse_phandle(node, "firmware-loader", 0);
+ if (!ofnode_valid(node))
+ return -ENODEV;
+
+ ret = device_find_global_by_ofnode(node, &fw_dev);
+ if (ret)
+ return ret;
+
+ ret = device_probe(fw_dev);
+ if (ret)
+ return ret;
+
+ *dev = fw_dev;
+ return 0;
+}
+
/**
* _request_firmware_prepare - Prepare firmware struct.
*
diff --git a/include/fw_loader.h b/include/fw_loader.h
index 56f5e3be6195..99c47380a172 100644
--- a/include/fw_loader.h
+++ b/include/fw_loader.h
@@ -6,8 +6,22 @@
#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.
+ *
+ * Search and probe a matching FW loader device, if found.
+ *
+ * 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.53.0
More information about the U-Boot
mailing list