dm: core: Add a way to convert a devicetree to a dtb

Add a way to flatten a devicetree into binary form. For livetree this
involves generating the devicetree using fdt_property() and other calls.
For flattree it simply involves providing the buffer containing the tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2023-09-26 08:14:43 -06:00
committed by Tom Rini
parent 67fb2159fb
commit 62b1db3377
5 changed files with 187 additions and 0 deletions

View File

@@ -243,6 +243,24 @@ int oftree_new(oftree *treep)
#endif /* OFNODE_MULTI_TREE */
int oftree_to_fdt(oftree tree, struct abuf *buf)
{
int ret;
if (of_live_active()) {
ret = of_live_flatten(ofnode_to_np(oftree_root(tree)), buf);
if (ret)
return log_msg_ret("flt", ret);
} else {
void *fdt = oftree_lookup_fdt(tree);
abuf_init(buf);
abuf_set(buf, fdt, fdt_totalsize(fdt));
}
return 0;
}
/**
* ofnode_from_tree_offset() - get an ofnode from a tree offset (flat tree)
*