[U-Boot] [PATCH v2 07/40] fdt: Add a subnodes iterator macro

Thierry Reding thierry.reding at gmail.com
Tue Aug 26 17:33:55 CEST 2014


From: Thierry Reding <treding at nvidia.com>

The fdt_for_each_subnode() iterator macro provided by this patch can be
used to iterate over a device tree node's subnodes. At each iteration a
loop variable will be set to the next subnode.

Acked-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Thierry Reding <treding at nvidia.com>
---
Changes in v2:
- specify the data types in the comment because the macro doesn't have them

 include/libfdt.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/include/libfdt.h b/include/libfdt.h
index 2dfc6d9e5ce7..f3cbb637be41 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -163,6 +163,31 @@ int fdt_first_subnode(const void *fdt, int offset);
  */
 int fdt_next_subnode(const void *fdt, int offset);
 
+/**
+ * fdt_for_each_subnode - iterate over all subnodes of a parent
+ *
+ * This is actually a wrapper around a for loop and would be used like so:
+ *
+ *	fdt_for_each_subnode(fdt, node, parent) {
+ *		...
+ *		use node
+ *		...
+ *	}
+ *
+ * Note that this is implemented as a macro and node is used as iterator in
+ * the loop. It should therefore be a locally allocated variable. The parent
+ * variable on the other hand is never modified, so it can be constant or
+ * even a literal.
+ *
+ * @fdt:	FDT blob (const void *)
+ * @node:	child node (int)
+ * @parent:	parent node (int)
+ */
+#define fdt_for_each_subnode(fdt, node, parent)		\
+	for (node = fdt_first_subnode(fdt, parent);	\
+	     node >= 0;					\
+	     node = fdt_next_subnode(fdt, node))
+
 /**********************************************************************/
 /* General functions                                                  */
 /**********************************************************************/
-- 
2.0.4



More information about the U-Boot mailing list