All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tobias Waldekranz <tobias@waldekranz.com>
To: sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org
Cc: u-boot@lists.denx.de
Subject: [PATCH 2/8] cmd: blk: Allow generic read/write operations to work in sandbox
Date: Wed,  1 Feb 2023 19:10:10 +0100	[thread overview]
Message-ID: <20230201181016.4145834-3-tobias@waldekranz.com> (raw)
In-Reply-To: <20230201181016.4145834-1-tobias@waldekranz.com>

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(-)

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");
-- 
2.34.1


  parent reply	other threads:[~2023-02-01 18:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01 18:10 [PATCH 0/8] blk: blkmap: Composable virtual block devices Tobias Waldekranz
2023-02-01 18:10 ` [PATCH 1/8] image: Fix script execution from FIT images with external data Tobias Waldekranz
2023-02-01 20:20   ` Simon Glass
2023-02-01 18:10 ` Tobias Waldekranz [this message]
2023-02-01 20:20   ` [PATCH 2/8] cmd: blk: Allow generic read/write operations to work in sandbox Simon Glass
2023-02-01 18:10 ` [PATCH 3/8] blk: blkmap: Add basic infrastructure Tobias Waldekranz
2023-02-01 20:20   ` Simon Glass
2023-02-03  9:38     ` Tobias Waldekranz
2023-02-04  0:20       ` Simon Glass
2023-02-06  8:30         ` Tobias Waldekranz
2023-02-07  4:02           ` Simon Glass
2023-02-07  8:31             ` Tobias Waldekranz
2023-02-07 13:38               ` Simon Glass
2023-02-01 18:10 ` [PATCH 4/8] blk: blkmap: Add memory mapping support Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 5/8] blk: blkmap: Add linear device " Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 6/8] cmd: blkmap: Add blkmap command Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 7/8] test: blkmap: Add test suite Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 8/8] doc: blkmap: Add introduction and examples Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 21:14   ` Heinrich Schuchardt
2023-02-01 20:21 ` [PATCH 0/8] blk: blkmap: Composable virtual block devices Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230201181016.4145834-3-tobias@waldekranz.com \
    --to=tobias@waldekranz.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.