]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: blk: Allow generic read/write operations to work in sandbox
authorTobias Waldekranz <tobias@waldekranz.com>
Thu, 16 Feb 2023 15:33:48 +0000 (16:33 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 5 Apr 2023 14:54:47 +0000 (10:54 -0400)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/blk_common.c

index 75a072caf51a2d4c490bd1421ad8c724427eca61..9f9d4327a99683679deaf5855a41f0c6c880c81f 100644 (file)
@@ -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");