fdt: Add a command to show reserved-memory regions
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>
This commit is contained in:
@@ -2265,7 +2265,7 @@ void fdt_print_reserved(void *fdt)
|
||||
int node, reserved, id;
|
||||
int addr_cells, size_cells;
|
||||
|
||||
printf("%-4s %-20s %-18s %-18s\n", "ID", "Name", "Start", "Size");
|
||||
printf("%-4s %-20s %-16s %-16s\n", "ID", "Name", "Start", "Size");
|
||||
printf("--------------------------------------------------------"
|
||||
"--------\n");
|
||||
|
||||
@@ -2300,7 +2300,7 @@ void fdt_print_reserved(void *fdt)
|
||||
rsv_size = (rsv_size << 32) |
|
||||
fdt32_to_cpu(reg[cells++]);
|
||||
|
||||
printf("%-4d %-20s 0x%-16llx 0x%-16llx\n",
|
||||
printf("%-4d %-20s %-16llx %-16llx\n",
|
||||
id++, name ? name : "(unnamed)", rsv_start,
|
||||
rsv_size);
|
||||
} else {
|
||||
|
||||
10
cmd/Kconfig
10
cmd/Kconfig
@@ -495,6 +495,16 @@ config CMD_FDT
|
||||
help
|
||||
Do FDT related setup before booting into the Operating System.
|
||||
|
||||
config CMD_FDT_RESERVED
|
||||
bool "fdt subcommand to show reserved memory"
|
||||
depends on CMD_FDT
|
||||
default y if SANDBOX || EFI_APP
|
||||
help
|
||||
Provides an 'fdt reserved' command which shows a list of the
|
||||
reserved-memory regions in the devicetree, before booting into the
|
||||
Operating System. Note that this is differen from 'fdt rsvmem'
|
||||
which shows the reserve entries after the FDT header.
|
||||
|
||||
config SUPPORT_EXTENSION_SCAN
|
||||
bool
|
||||
|
||||
|
||||
10
cmd/fdt.c
10
cmd/fdt.c
@@ -768,8 +768,13 @@ 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 (IS_ENABLED(CONFIG_CMD_FDT_RESERVED) &&
|
||||
!strncmp(argv[1], "rese", 4)) {
|
||||
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 +907,9 @@ 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"
|
||||
#ifdef CONFIG_CMD_FDT_RESERVED
|
||||
"fdt reserved - Print reserved-memory regions\n"
|
||||
#endif
|
||||
"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"
|
||||
|
||||
@@ -12,6 +12,7 @@ Synopsis
|
||||
::
|
||||
|
||||
fdt addr [-cq] [addr [len]]
|
||||
fdt reserved
|
||||
|
||||
Description
|
||||
-----------
|
||||
@@ -48,6 +49,24 @@ 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.
|
||||
|
||||
This subcommand is only present is `CONFIG_CMD_FDT_RESERVED` is enabled.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
@@ -67,6 +86,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
|
||||
------------
|
||||
|
||||
|
||||
@@ -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 100000 2000 ");
|
||||
|
||||
/* 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);
|
||||
|
||||
Reference in New Issue
Block a user