diff mbox series

[2/8] cmd: blk: Allow generic read/write operations to work in sandbox

Message ID 20230201181016.4145834-3-tobias@waldekranz.com
State Superseded
Delegated to: Tom Rini
Headers show
Series blk: blkmap: Composable virtual block devices | expand

Commit Message

Tobias Waldekranz Feb. 1, 2023, 6:10 p.m. UTC
Ensure that the memory destination/source addresses of block
read/write operations are mapped in before access. Currently, this is
only needed on sandbox builds.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
 cmd/blk_common.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Simon Glass Feb. 1, 2023, 8:20 p.m. UTC | #1
On Wed, 1 Feb 2023 at 11:10, Tobias Waldekranz <tobias@waldekranz.com> wrote:
>
> Ensure that the memory destination/source addresses of block
> read/write operations are mapped in before access. Currently, this is
> only needed on sandbox builds.
>
> Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
> ---
>  cmd/blk_common.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)

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

Patch

diff --git a/cmd/blk_common.c b/cmd/blk_common.c
index 75a072caf5..9f9d4327a9 100644
--- a/cmd/blk_common.c
+++ b/cmd/blk_common.c
@@ -11,6 +11,7 @@ 
 #include <common.h>
 #include <blk.h>
 #include <command.h>
+#include <mapmem.h>
 
 int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
 		   int *cur_devnump)
@@ -63,31 +64,37 @@  int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
 
 	default: /* at least 4 args */
 		if (strcmp(argv[1], "read") == 0) {
-			ulong addr = hextoul(argv[2], NULL);
+			phys_addr_t paddr = hextoul(argv[2], NULL);
 			lbaint_t blk = hextoul(argv[3], NULL);
 			ulong cnt = hextoul(argv[4], NULL);
+			void *vaddr;
 			ulong n;
 
 			printf("\n%s read: device %d block # "LBAFU", count %lu ... ",
 			       if_name, *cur_devnump, blk, cnt);
 
+			vaddr = map_sysmem(paddr, 512 * cnt);
 			n = blk_read_devnum(uclass_id, *cur_devnump, blk, cnt,
-					    (ulong *)addr);
+					    vaddr);
+			unmap_sysmem(vaddr);
 
 			printf("%ld blocks read: %s\n", n,
 			       n == cnt ? "OK" : "ERROR");
 			return n == cnt ? 0 : 1;
 		} else if (strcmp(argv[1], "write") == 0) {
-			ulong addr = hextoul(argv[2], NULL);
+			phys_addr_t paddr = hextoul(argv[2], NULL);
 			lbaint_t blk = hextoul(argv[3], NULL);
 			ulong cnt = hextoul(argv[4], NULL);
+			void *vaddr;
 			ulong n;
 
 			printf("\n%s write: device %d block # "LBAFU", count %lu ... ",
 			       if_name, *cur_devnump, blk, cnt);
 
+			vaddr = map_sysmem(paddr, 512 * cnt);
 			n = blk_write_devnum(uclass_id, *cur_devnump, blk, cnt,
-					     (ulong *)addr);
+					     vaddr);
+			unmap_sysmem(vaddr);
 
 			printf("%ld blocks written: %s\n", n,
 			       n == cnt ? "OK" : "ERROR");