diff mbox series

[1/3] cmd: fdt: move: Use map_sysmem to convert pointers

Message ID 20220705171350.1765454-2-andre.przywara@arm.com
State Accepted
Delegated to: Simon Glass
Headers show
Series fdt: introduce "apply-all" command | expand

Commit Message

Andre Przywara July 5, 2022, 5:13 p.m. UTC
The "fdt move" subcommand was using the provided DTB addresses directly,
without trying to "map" them into U-Boot's address space. This happened
to work since on the vast majority of "real" platforms there is a simple
1:1 mapping of VA to PAs, so either value works fine.

However this is not true on the sandbox, so the "fdt move" command fails
there miserably:
=> fdt addr $fdtcontroladdr
=> cp.l $fdtcontroladdr $fdt_addr_r 40  # simple memcpy works
=> fdt move $fdtcontroladdr $fdt_addr_r
Segmentation fault

Use the proper "map_sysmem" call to convert PAs to VAs, to make this
more robust in general and to enable operation in the sandbox.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 cmd/fdt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Simon Glass July 12, 2022, 10:58 a.m. UTC | #1
On Tue, 5 Jul 2022 at 11:14, Andre Przywara <andre.przywara@arm.com> wrote:
>
> The "fdt move" subcommand was using the provided DTB addresses directly,
> without trying to "map" them into U-Boot's address space. This happened
> to work since on the vast majority of "real" platforms there is a simple
> 1:1 mapping of VA to PAs, so either value works fine.
>
> However this is not true on the sandbox, so the "fdt move" command fails
> there miserably:
> => fdt addr $fdtcontroladdr
> => cp.l $fdtcontroladdr $fdt_addr_r 40  # simple memcpy works
> => fdt move $fdtcontroladdr $fdt_addr_r
> Segmentation fault
>
> Use the proper "map_sysmem" call to convert PAs to VAs, to make this
> more robust in general and to enable operation in the sandbox.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  cmd/fdt.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass July 17, 2022, 8:12 a.m. UTC | #2
On Tue, 5 Jul 2022 at 11:14, Andre Przywara <andre.przywara@arm.com> wrote:
>
> The "fdt move" subcommand was using the provided DTB addresses directly,
> without trying to "map" them into U-Boot's address space. This happened
> to work since on the vast majority of "real" platforms there is a simple
> 1:1 mapping of VA to PAs, so either value works fine.
>
> However this is not true on the sandbox, so the "fdt move" command fails
> there miserably:
> => fdt addr $fdtcontroladdr
> => cp.l $fdtcontroladdr $fdt_addr_r 40  # simple memcpy works
> => fdt move $fdtcontroladdr $fdt_addr_r
> Segmentation fault
>
> Use the proper "map_sysmem" call to convert PAs to VAs, to make this
> more robust in general and to enable operation in the sandbox.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  cmd/fdt.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

Patch

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 842e6cb634..abdc553b2b 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -211,11 +211,11 @@  static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		/*
 		 * Set the address and length of the fdt.
 		 */
-		working_fdt = (struct fdt_header *)hextoul(argv[2], NULL);
+		working_fdt = map_sysmem(hextoul(argv[2], NULL), 0);
 		if (!fdt_valid(&working_fdt))
 			return 1;
 
-		newaddr = (struct fdt_header *)hextoul(argv[3], NULL);
+		newaddr = map_sysmem(hextoul(argv[3], NULL), 0);
 
 		/*
 		 * If the user specifies a length, use that.  Otherwise use the
@@ -242,7 +242,7 @@  static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 				fdt_strerror(err));
 			return 1;
 		}
-		set_working_fdt_addr((ulong)newaddr);
+		set_working_fdt_addr(map_to_sysmem(newaddr));
 #ifdef CONFIG_OF_SYSTEM_SETUP
 	/* Call the board-specific fixup routine */
 	} else if (strncmp(argv[1], "sys", 3) == 0) {