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) {