[U-Boot] [PATCH V2] fdt: introduce fdtdec_get_child_count

Peng Fan van.freenix at gmail.com
Mon Feb 1 06:31:15 CET 2016


Introduce fdtdec_get_child_count for get the number of subnodes
of one parent node.

Signed-off-by: Peng Fan <van.freenix at gmail.com>
Cc: Simon Glass <sjg at chromium.org>
---

V2:
 correct spell error.
 renamed to fdtdec_get_child_count, move code to lib/fdtdec.c and add
 prototype in include/fdtdec.h

 include/fdtdec.h |  9 +++++++++
 lib/fdtdec.c     | 11 +++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index dd82916..d1c29a8 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -722,6 +722,15 @@ const u32 *fdtdec_locate_array(const void *blob, int node,
  */
 int fdtdec_get_bool(const void *blob, int node, const char *prop_name);
 
+/*
+ * Count child nodes of one parent node.
+ *
+ * @param blob	FDT blob
+ * @param node	parent node
+ * @return number of child node; 0 if there is not child node
+ */
+int fdtdec_get_child_count(const void *blob, int node);
+
 /**
  * Look in the FDT for a config item with the given name and return its value
  * as a 32-bit integer. The property must have at least 4 bytes of data. The
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 0eb56af..1b1ca02 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -831,6 +831,17 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
 	return rc;
 }
 
+int fdtdec_get_child_count(const void *blob, int node)
+{
+	int subnode;
+	int num = 0;
+
+	fdt_for_each_subnode(blob, subnode, node)
+		num++;
+
+	return num;
+}
+
 int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
 		u8 *array, int count)
 {
-- 
2.6.2



More information about the U-Boot mailing list