Add 'fdt move' test which works as follows:
- Create simple FDT, map it to sysmem
- 'move' the FDT into new zeroed out sysmem location
- Verify newly active FDT is in the new location
- Compare both locations

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut <marek.vasut+rene...@mailbox.org>
Reviewed-by: Simon Glass <s...@chromium.org>
---
Cc: Heinrich Schuchardt <heinrich.schucha...@canonical.com>
Cc: Simon Glass <s...@chromium.org>
Cc: Tom Rini <tr...@konsulko.com>
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 69a69c5c75c..023b83eb019 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -238,6 +238,40 @@ static int fdt_test_addr_resize(struct unit_test_state 
*uts)
 }
 FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_move(struct unit_test_state *uts)
+{
+       char fdt[256];
+       ulong addr, newaddr = 0x10000;
+       const int size = sizeof(fdt);
+       uint32_t ts;
+       void *buf;
+
+       /* Original source DT */
+       ut_assertok(make_test_fdt(uts, fdt, size));
+       ts = fdt_totalsize(fdt);
+       addr = map_to_sysmem(fdt);
+       set_working_fdt_addr(addr);
+
+       /* Moved target DT location */
+       buf = map_sysmem(newaddr, size);
+       memset(buf, 0, size);
+
+       /* Test moving the working FDT to a new location */
+       ut_assertok(console_record_reset_enable());
+       ut_assertok(run_commandf("fdt move %08x %08x %x", addr, newaddr, ts));
+       ut_assert_nextline("Working FDT set to %lx", newaddr);
+       ut_assertok(ut_check_console_end(uts));
+
+       /* Compare the source and destination DTs */
+       ut_assertok(console_record_reset_enable());
+       ut_assertok(run_commandf("cmp.b %08x %08x %x", addr, newaddr, ts));
+       ut_assert_nextline("Total of %d byte(s) were the same", ts);
+       ut_assertok(ut_check_console_end(uts));
+
+       return 0;
+}
+FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC);
+
 /* Test 'fdt get value' reading an fdt */
 static int fdt_test_get_value_string(struct unit_test_state *uts,
                                     const char *node, const char *prop,
-- 
2.39.2

Reply via email to