
From: Simon Glass <sjg@chromium.org> Add a new 'fdt reserved' subcommand that displays all reserved memory regions defined in the device tree's /reserved-memory node. This command provides a formatted table showing the ID, name, start address, and size of each reserved memory region. Avoid a conflict with the existing 'fdt resize' command. Update the docs and add a test. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org> --- cmd/fdt.c | 7 ++++++- doc/usage/cmd/fdt.rst | 26 ++++++++++++++++++++++++++ test/cmd/fdt.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 4aedac6116e..7fe0d9dc22c 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -768,8 +768,12 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_FAILURE; } #endif + /* print reserved memory regions */ + else if (strncmp(argv[1], "rese", 4) == 0) { + fdt_print_reserved(working_fdt); + /* resize the fdt */ - else if (strncmp(argv[1], "re", 2) == 0) { + } else if (strncmp(argv[1], "re", 2) == 0) { uint extrasize; if (argc > 2) extrasize = hextoul(argv[2], NULL); @@ -902,6 +906,7 @@ U_BOOT_LONGHELP(fdt, #endif "fdt move <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n" "fdt resize [<extrasize>] - Resize fdt to size + padding to 4k addr + some optional <extrasize> if needed\n" + "fdt reserved - Print reserved-memory regions\n" "fdt print <path> [<prop>] - Recursive print starting at <path>\n" "fdt list <path> [<prop>] - Print one level starting at <path>\n" "fdt get value <var> <path> <prop> [<index>] - Get <property> and store in <var>\n" diff --git a/doc/usage/cmd/fdt.rst b/doc/usage/cmd/fdt.rst index 71a9fc627e5..2fbb50e5013 100644 --- a/doc/usage/cmd/fdt.rst +++ b/doc/usage/cmd/fdt.rst @@ -12,6 +12,7 @@ Synopsis :: fdt addr [-cq] [addr [len]] + fdt reserved Description ----------- @@ -48,6 +49,22 @@ If the `len` argument is provided, then the device tree is expanded to that size. This can be used to make space for more nodes and properties. It is assumed that there is enough space in memory for this expansion. +fdt reserved +~~~~~~~~~~~~ + +This command prints all reserved memory regions defined in the device tree's +`/reserved-memory` node. The output shows a formatted table with the following +columns: + +- **ID**: Sequential number for each region +- **Name**: Node name of the reserved memory region +- **Start**: Start address of the reserved memory region in hexadecimal +- **Size**: Size of the reserved memory region in hexadecimal + +If no `/reserved-memory` node exists in the device tree, the command will +display an appropriate message. This command is useful for debugging memory +layout issues and verifying that reserved memory regions are properly defined. + Example ------- @@ -67,6 +84,15 @@ address and expand it to 0xf000 in size:: => md 10000 4 00010000: edfe0dd0 00f00000 78000000 7c270000 ...........x..'| +Print all reserved memory regions:: + + => fdt reserved + ID Name Start Size + ---------------------------------------------------------------- + 0 secmon@1f000000 0x000000001f000000 0x0000000001000000 + 1 atf@40000000 0x0000000040000000 0x0000000000200000 + 2 linux,cma 0x0000000050000000 0x0000000008000000 + Return value ------------ diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 9de79870c40..10a2f309a45 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1464,3 +1464,43 @@ static int fdt_test_apply(struct unit_test_state *uts) return 0; } FDT_TEST(fdt_test_apply, UTF_CONSOLE); + +/* Test 'fdt reserved' reading reserved-memory nodes */ +static int fdt_test_reserved(struct unit_test_state *uts) +{ + struct fdt_header *old_working_fdt; + char fdt[8192]; + ulong addr; + + if (!IS_ENABLED(CONFIG_SANDBOX)) + return -EAGAIN; + + /* Save the original working_fdt */ + old_working_fdt = working_fdt; + + /* Set working_fdt to control FDT (sandbox has reserved memory) */ + working_fdt = (struct fdt_header *)gd->fdt_blob; + + ut_assertok(run_command("fdt reserved", 0)); + + /* Just verify we get the header */ + ut_assert_nextlinen("ID"); + ut_assert_nextlinen("------"); + + /* Verify we get a tcg_event_log entry with correct address/size */ + ut_assert_nextline("0 tcg_event_log 0x100000 0x2000 "); + + /* Test with FDT that has no reserved-memory node */ + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr)); + ut_assertok(run_command("fdt reserved", 0)); + ut_assert_nextlinen("ID Name Start Size"); + ut_assert_nextline("----------------------------------------------------------------"); + ut_assert_nextline("No /reserved-memory node found in device tree"); + ut_assert_console_end(); + + /* Restore the original working_fdt */ + working_fdt = old_working_fdt; + + return 0; +} +FDT_TEST(fdt_test_reserved, UTF_CONSOLE); -- 2.43.0