public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de,
	Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	Michael Trimarchi <michael@amarulasolutions.com>
Cc: Tom Rini <trini@konsulko.com>, Sean Anderson <seanga2@gmail.com>
Subject: [PATCH 07/15] cmd: nand: Map memory before accessing it
Date: Sat, 28 Oct 2023 23:48:37 -0400	[thread overview]
Message-ID: <20231029034845.1169614-8-seanga2@gmail.com> (raw)
In-Reply-To: <20231029034845.1169614-1-seanga2@gmail.com>

In sandbox, all memory must be mapped before accessing it. Do so for the
nand command.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

 cmd/nand.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/cmd/nand.c b/cmd/nand.c
index 71b8f964429..fe834c4ac5c 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -34,6 +34,7 @@
 #include <env.h>
 #include <watchdog.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <asm/byteorder.h>
 #include <jffs2/jffs2.h>
 #include <nand.h>
@@ -432,7 +433,7 @@ static void nand_print_and_set_info(int idx)
 	env_set_hex("nand_erasesize", mtd->erasesize);
 }
 
-static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
+static int raw_access(struct mtd_info *mtd, void *buf, loff_t off,
 		      ulong count, int read, int no_verify)
 {
 	int ret = 0;
@@ -440,8 +441,8 @@ static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
 	while (count--) {
 		/* Raw access */
 		mtd_oob_ops_t ops = {
-			.datbuf = (u8 *)addr,
-			.oobbuf = ((u8 *)addr) + mtd->writesize,
+			.datbuf = buf,
+			.oobbuf = buf + mtd->writesize,
 			.len = mtd->writesize,
 			.ooblen = mtd->oobsize,
 			.mode = MTD_OPS_RAW
@@ -461,7 +462,7 @@ static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
 			break;
 		}
 
-		addr += mtd->writesize + mtd->oobsize;
+		buf += mtd->writesize + mtd->oobsize;
 		off += mtd->writesize;
 	}
 
@@ -675,6 +676,7 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
 		int read;
 		int raw = 0;
 		int no_verify = 0;
+		void *buf;
 
 		if (argc < 4)
 			goto usage;
@@ -730,32 +732,32 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 
 		mtd = get_nand_dev_by_index(dev);
+		buf = map_sysmem(addr, maxsize);
 
 		if (!s || !strcmp(s, ".jffs2") ||
 		    !strcmp(s, ".e") || !strcmp(s, ".i")) {
 			if (read)
 				ret = nand_read_skip_bad(mtd, off, &rwsize,
-							 NULL, maxsize,
-							 (u_char *)addr);
+							 NULL, maxsize, buf);
 			else
 				ret = nand_write_skip_bad(mtd, off, &rwsize,
-							  NULL, maxsize,
-							  (u_char *)addr,
+							  NULL, maxsize, buf,
 							  WITH_WR_VERIFY);
 #ifdef CONFIG_CMD_NAND_TRIMFFS
 		} else if (!strcmp(s, ".trimffs")) {
 			if (read) {
 				printf("Unknown nand command suffix '%s'\n", s);
+				unmap_sysmem(buf);
 				return 1;
 			}
 			ret = nand_write_skip_bad(mtd, off, &rwsize, NULL,
-						maxsize, (u_char *)addr,
+						maxsize, buf,
 						WITH_DROP_FFS | WITH_WR_VERIFY);
 #endif
 		} else if (!strcmp(s, ".oob")) {
 			/* out-of-band data */
 			mtd_oob_ops_t ops = {
-				.oobbuf = (u8 *)addr,
+				.oobbuf = buf,
 				.ooblen = rwsize,
 				.mode = MTD_OPS_RAW
 			};
@@ -765,13 +767,15 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
 			else
 				ret = mtd_write_oob(mtd, off, &ops);
 		} else if (raw) {
-			ret = raw_access(mtd, addr, off, pagecount, read,
+			ret = raw_access(mtd, buf, off, pagecount, read,
 					 no_verify);
 		} else {
 			printf("Unknown nand command suffix '%s'.\n", s);
+			unmap_sysmem(buf);
 			return 1;
 		}
 
+		unmap_sysmem(buf);
 		printf(" %zu bytes %s: %s\n", rwsize,
 		       read ? "read" : "written", ret ? "ERROR" : "OK");
 
-- 
2.37.1


  parent reply	other threads:[~2023-10-29  3:50 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-29  3:48 [PATCH 00/15] nand: Add sandbox tests Sean Anderson
2023-10-29  3:48 ` [PATCH 01/15] spl: nand: Fix NULL-pointer dereference Sean Anderson
2023-10-29 14:15   ` Sean Anderson
2023-10-29  3:48 ` [PATCH 02/15] nand: Don't dereference NULL manufacturer_desc Sean Anderson
2023-10-29 13:06   ` Michael Nazzareno Trimarchi
2023-10-29  3:48 ` [PATCH 03/15] nand: Calculate SYS_NAND_PAGE_COUNT automatically Sean Anderson
2023-11-02  9:53   ` Dario Binacchi
2023-11-02 14:17     ` Sean Anderson
2023-11-02 14:19       ` Dario Binacchi
2023-10-29  3:48 ` [PATCH 04/15] nand: spl_loaders: Only read enough pages to load the image Sean Anderson
2023-10-29 13:08   ` Michael Nazzareno Trimarchi
2023-10-29  3:48 ` [PATCH 05/15] spl: legacy: Honor bl_len when decompressing Sean Anderson
2023-10-29  3:48 ` [PATCH 06/15] spl: nand: Set bl_len to page size Sean Anderson
2023-10-29  3:48 ` Sean Anderson [this message]
2023-10-29  3:48 ` [PATCH 08/15] spl: nand: Map memory before accessing it Sean Anderson
2023-10-29  3:48 ` [PATCH 09/15] mtd: Rename SPL_MTD_SUPPORT to SPL_MTD Sean Anderson
2023-10-29  3:48 ` [PATCH 10/15] mtd: Add some fallbacks for add/del_mtd_device Sean Anderson
2023-11-02 10:45   ` Dario Binacchi
2023-10-29  3:48 ` [PATCH 11/15] nand: Add function to unregister NAND devices Sean Anderson
2023-11-02 10:58   ` Dario Binacchi
2023-10-29  3:48 ` [PATCH 12/15] nand: Allow reinitialization Sean Anderson
2023-11-02 11:08   ` Dario Binacchi
2023-10-29  3:48 ` [PATCH 13/15] arch: sandbox: Add function to create temporary files Sean Anderson
2023-10-29  3:48 ` [PATCH 14/15] nand: Add sandbox driver Sean Anderson
2023-11-02 11:15   ` Dario Binacchi
2023-11-02 13:54     ` Sean Anderson
2023-10-29  3:48 ` [PATCH 15/15] test: spl: Add a test for NAND Sean Anderson
2023-11-02 14:01 ` [PATCH 00/15] nand: Add sandbox tests Dario Binacchi
2023-11-02 14:05   ` Sean Anderson
2023-11-02 14:08     ` Dario Binacchi
2023-11-02 14:13       ` Sean Anderson
2023-11-02 14:18         ` Dario Binacchi
2023-11-04 19:46           ` Sean Anderson
2023-11-09  8:23             ` Dario Binacchi

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=20231029034845.1169614-8-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=michael@amarulasolutions.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox