Patchwork [U-Boot,2/5,V3] NAND: Add nand read.raw and write.raw commands

login
register
mail settings
Submitter Marek Vasut
Date Sept. 22, 2011, 6:36 p.m.
Message ID <1316716571-2876-1-git-send-email-marek.vasut@gmail.com>
Download mbox | patch
Permalink /patch/115997/
State Superseded
Headers show

Comments

Marek Vasut - Sept. 22, 2011, 6:36 p.m.
These commands should work around various "hardware" ECC and BCH methods.

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Cc: Scott Wood <scottwood@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Detlev Zundel <dzu@denx.de>
---
 common/cmd_nand.c |   21 +++++++++++++++++++--
 doc/README.nand   |    9 +++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

V2: Add documentation.
V3: Drop size param.
Scott Wood - Sept. 22, 2011, 6:40 p.m.
On 09/22/2011 01:36 PM, Marek Vasut wrote:
> @@ -695,10 +711,11 @@ U_BOOT_CMD(
>  	"NAND sub-system",
>  	"info - show available NAND devices\n"
>  	"nand device [dev] - show or set current device\n"
> -	"nand read - addr off|partition size\n"
> -	"nand write - addr off|partition size\n"
> +	"nand read[.raw] - addr off|partition\n"
> +	"nand write[.raw] - addr off|partition\n"
>  	"    read/write 'size' bytes starting at offset 'off'\n"
>  	"    to/from memory address 'addr', skipping bad blocks.\n"
> +	"    Use read.raw/write.raw to avoid ECC and write the block as-is.\n"

Only the .raw version lacks size -- please do not remove it from the
help text for the normal read/write.

> diff --git a/doc/README.nand b/doc/README.nand
> index 751b693..62c077e 100644
> --- a/doc/README.nand
> +++ b/doc/README.nand
> @@ -94,6 +94,15 @@ Commands:
>        of data for one 512-byte page or 2 256-byte pages. There is no check
>        for bad blocks.
>  
> +   nand read.raw addr ofs|partition
> +      Read block from `ofs' in NAND flash to `addr'. This reads the raw block,
> +      so ECC is avoided and the OOB area is read as well.
> +
> +   nand write.raw addr ofs|partition
> +      Write block from `addr' to `ofs' in NAND flash. This writes the raw block,
> +      so ECC is avoided and the OOB area is written as well, making the whole
> +      block written as-is.

Again, it's operating on a page, not a block.

-Scott

Patch

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 66e06a5..92b6280 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -606,6 +606,22 @@  int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 				ret = nand->read_oob(nand, off, &ops);
 			else
 				ret = nand->write_oob(nand, off, &ops);
+		} else if (!strcmp(s, ".raw")) {
+			/* Raw access */
+			mtd_oob_ops_t ops = {
+				.datbuf = (u8 *)addr,
+				.oobbuf = ((u8 *)addr) + nand->writesize,
+				.len = nand->writesize,
+				.ooblen = nand->oobsize,
+				.mode = MTD_OOB_RAW
+			};
+
+			rwsize = nand->writesize + nand->oobsize;
+
+			if (read)
+				ret = nand->read_oob(nand, off, &ops);
+			else
+				ret = nand->write_oob(nand, off, &ops);
 		} else {
 			printf("Unknown nand command suffix '%s'.\n", s);
 			return 1;
@@ -695,10 +711,11 @@  U_BOOT_CMD(
 	"NAND sub-system",
 	"info - show available NAND devices\n"
 	"nand device [dev] - show or set current device\n"
-	"nand read - addr off|partition size\n"
-	"nand write - addr off|partition size\n"
+	"nand read[.raw] - addr off|partition\n"
+	"nand write[.raw] - addr off|partition\n"
 	"    read/write 'size' bytes starting at offset 'off'\n"
 	"    to/from memory address 'addr', skipping bad blocks.\n"
+	"    Use read.raw/write.raw to avoid ECC and write the block as-is.\n"
 #ifdef CONFIG_CMD_NAND_TRIMFFS
 	"nand write.trimffs - addr off|partition size\n"
 	"    write 'size' bytes starting at offset 'off' from memory address\n"
diff --git a/doc/README.nand b/doc/README.nand
index 751b693..62c077e 100644
--- a/doc/README.nand
+++ b/doc/README.nand
@@ -94,6 +94,15 @@  Commands:
       of data for one 512-byte page or 2 256-byte pages. There is no check
       for bad blocks.
 
+   nand read.raw addr ofs|partition
+      Read block from `ofs' in NAND flash to `addr'. This reads the raw block,
+      so ECC is avoided and the OOB area is read as well.
+
+   nand write.raw addr ofs|partition
+      Write block from `addr' to `ofs' in NAND flash. This writes the raw block,
+      so ECC is avoided and the OOB area is written as well, making the whole
+      block written as-is.
+
 Configuration Options:
 
    CONFIG_CMD_NAND