[component][fdt]添加设备树子节点寻找宏 (#7377)

This commit is contained in:
wangqinglin 2023-06-27 22:09:51 +08:00 committed by GitHub
parent c2c83533c9
commit cb03b8c834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

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

View File

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