diff mbox series

[v2,09/32] cmd: fdt: Map address returned from fdt get addr to sysmem

Message ID 20230302030845.322552-9-marek.vasut+renesas@mailbox.org
State Accepted
Commit c2a5d1078027b6c0480eda45bd4d2eae80ceb67e
Delegated to: Simon Glass
Headers show
Series [v2,01/32] cmd: fdt: Import is_printable_string() from DTC to fix u32 misprint | expand

Commit Message

Marek Vasut March 2, 2023, 3:08 a.m. UTC
The address returned from 'fdt get addr' command must be mapped
into sysmem, as this is a working FDT. Access to this address
without mapping it would lead to crash e.g. in sandbox.

The following command triggers the crash:
"
./u-boot -Dc 'fdt addr $fdtcontroladdr ; fdt get addr var / compatible ; md $var'
"

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
V2: Add RB from Simon
---
 cmd/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Simon Glass March 8, 2023, 10:16 p.m. UTC | #1
The address returned from 'fdt get addr' command must be mapped
into sysmem, as this is a working FDT. Access to this address
without mapping it would lead to crash e.g. in sandbox.

The following command triggers the crash:
"
./u-boot -Dc 'fdt addr $fdtcontroladdr ; fdt get addr var / compatible
; md $var'
"

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
V2: Add RB from Simon
---
 cmd/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!
diff mbox series

Patch

diff --git a/cmd/fdt.c b/cmd/fdt.c
index bc19303159d..f2576ab4b38 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -468,7 +468,8 @@  static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 					/* Get address */
 					char buf[19];
 
-					snprintf(buf, sizeof(buf), "0x%p", nodep);
+					snprintf(buf, sizeof(buf), "0x%lx",
+						 (ulong)map_to_sysmem(nodep));
 					env_set(var, buf);
 				} else if (subcmd[0] == 's') {
 					/* Get size */