summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorwangqinglin <[email protected]>2023-06-27 22:09:51 +0800
committerGitHub <[email protected]>2023-06-27 10:09:51 -0400
commitcb03b8c83422372e1392e729d0989fd15fb902ae (patch)
tree57f50af3d1a1186f8eb20bbdaa5ffcab004e1cc7 /components/drivers
parentc2c83533c938cfa92a444f3ec015f3d61ef5a326 (diff)
[component][fdt]添加设备树子节点寻找宏 (#7377)
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/fdt/inc/dtb_node.h4
-rw-r--r--components/drivers/fdt/src/dtb_get.c3
2 files changed, 7 insertions, 0 deletions
diff --git a/components/drivers/fdt/inc/dtb_node.h b/components/drivers/fdt/inc/dtb_node.h
index b783dfdf8c..7d780e9948 100644
--- a/components/drivers/fdt/inc/dtb_node.h
+++ b/components/drivers/fdt/inc/dtb_node.h
@@ -70,6 +70,7 @@ struct dtb_node
};
const char *path;
phandle handle;
+ int level;
struct dtb_property *properties;
struct dtb_node *parent;
@@ -288,6 +289,9 @@ const uint32_t *dtb_node_get_address(const struct dtb_node *dev, int index,
#define for_each_of_allnodes_from(from, dn) \
for (dn = dtb_node_find_all_nodes(from); dn; dn = dtb_node_find_all_nodes(dn))
+#define for_each_of_all_child_nodes_from(from, dn) \
+ for (dn = dtb_node_find_all_nodes(from); dn && (dn->level > from->level); dn = dtb_node_find_all_nodes(dn))
+
#define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
#define dtb_node_get(x) (x)
diff --git a/components/drivers/fdt/src/dtb_get.c b/components/drivers/fdt/src/dtb_get.c
index a8f32fe850..51c3f5ee1d 100644
--- a/components/drivers/fdt/src/dtb_get.c
+++ b/components/drivers/fdt/src/dtb_get.c
@@ -96,6 +96,7 @@ static int _dtb_node_get_dtb_nodes_list(struct dtb_node *dtb_node_head, struct d
paths_buf.cur += node_name_sz;
*paths_buf.cur++ = '/';
*paths_buf.cur++ = '\0';
+ dtb_node->level = dtb_node_head->level + 1;
}
else
{
@@ -144,6 +145,7 @@ static int _dtb_node_get_dtb_nodes_list(struct dtb_node *dtb_node_head, struct d
return FDT_RET_NO_MEMORY;
}
dtb_node = dtb_node->sibling;
+ dtb_node->level--;
}
else
{
@@ -235,6 +237,7 @@ struct dtb_node *dtb_node_get_dtb_list(void *fdt)
dtb_node_head->handle = fdt_get_phandle(fdt, root_off);
dtb_node_head->properties = (struct dtb_property *)malloc(sizeof(struct dtb_property));
dtb_node_head->child = (struct dtb_node *)malloc(sizeof(struct dtb_node));
+ dtb_node_head->level = 0;
if (dtb_node_head->properties == NULL || dtb_node_head->child == NULL)
{