From 62b1db33778611a3023d1e3a98e869b495edc9ca Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:43 -0600 Subject: 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 --- test/dm/ofnode.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/dm/ofnode.c') diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 845cded449a..ceeb8e57791 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include @@ -1456,3 +1458,25 @@ static int dm_test_ofnode_delete(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_delete, UT_TESTF_SCAN_FDT); + +static int dm_test_oftree_to_fdt(struct unit_test_state *uts) +{ + oftree tree, check; + struct abuf buf, buf2; + + tree = oftree_default(); + ut_assertok(oftree_to_fdt(tree, &buf)); + ut_assert(abuf_size(&buf) > SZ_16K); + + /* convert it back to a tree and see if it looks OK */ + check = oftree_from_fdt(abuf_data(&buf)); + ut_assert(oftree_valid(check)); + + ut_assertok(oftree_to_fdt(check, &buf2)); + ut_assert(abuf_size(&buf2) > SZ_16K); + ut_asserteq(abuf_size(&buf), abuf_size(&buf2)); + ut_asserteq_mem(abuf_data(&buf), abuf_data(&buf2), abuf_size(&buf)); + + return 0; +} +DM_TEST(dm_test_oftree_to_fdt, UT_TESTF_SCAN_FDT); -- cgit v1.2.3