Patchwork [U-Boot,4/4,v2] cmd_nand: add nand write.trimffs command

login
register
mail settings
Submitter Ben Gardiner
Date May 19, 2011, 4:49 p.m.
Message ID <cb0599fadbf1934ae6ba17d9ea5b7afbff83859d.1305823168.git.bengardiner@nanometrics.ca>
Download mbox | patch
Permalink /patch/96429/
State Superseded
Headers show

Comments

Ben Gardiner - May 19, 2011, 4:49 p.m.
Add another nand write. variant, trimffs. This command will request of
nand_write_skip_bad() that all trailing all-0xff pages will be
dropped from eraseblocks when they are written to flash as-per the
reccommended behaviour of the UBI FAQ [1].

The function that implements this timming is the drop_ffs() function
by Artem Bityutskiy, ported from the mtd-utils tree.

[1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo

Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
CC: Artem Bityutskiy <dedekind1@gmail.com>
CC: Detlev Zundel <dzu@denx.de>

---

Detlev,
I did not do any erased-state checks since the implicit assumption
in other nand commands is that the user is required to do their
own erasing beforehand.

Changes since v1:
 * rebased to HEAD of git://git.denx.de/u-boot-nand-flash.git : ff7b4a0
   ("env_nand: zero-initialize variable nand_erase_options")
 * renamed the command variant to '.trimffs' from '.ubi' (Detlev Zundel)
 * added attribution to mtd-utils and Artem Bityutskiy in both the source
   comments and commit message
 * wrapped the new command in a new ifdef, CONFIG_CMD_NAND_TRIMFFS, to
   reduce the size impact of this new feature

---
 common/cmd_nand.c            |   16 ++++++++++++++++
 drivers/mtd/nand/nand_util.c |    3 +++
 2 files changed, 19 insertions(+), 0 deletions(-)
Detlev Zundel - May 24, 2011, 1:22 p.m.
Hi Ben,

> Add another nand write. variant, trimffs. This command will request of
> nand_write_skip_bad() that all trailing all-0xff pages will be
> dropped from eraseblocks when they are written to flash as-per the
> reccommended behaviour of the UBI FAQ [1].
>
> The function that implements this timming is the drop_ffs() function
> by Artem Bityutskiy, ported from the mtd-utils tree.
>
> [1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo
>
> Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
> CC: Artem Bityutskiy <dedekind1@gmail.com>
> CC: Detlev Zundel <dzu@denx.de>
>
> ---
>
> Detlev,
> I did not do any erased-state checks since the implicit assumption
> in other nand commands is that the user is required to do their
> own erasing beforehand.

Yes, I have come to the same conclusion.

I have another request though - please add the new command to
doc/README.nand.  Thanks!

Cheers
  Detlev
Ben Gardiner - May 24, 2011, 1:30 p.m.
Hi Detlev,

On Tue, May 24, 2011 at 9:22 AM, Detlev Zundel <dzu@denx.de> wrote:
> I have another request though - please add the new command to
> doc/README.nand.  Thanks!

Good idea. Will do in v3.

Best Regards,
Ben Gardiner

---
Nanometrics Inc.
http://www.nanometrics.ca

Patch

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index cb752c1..51d726c 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -576,6 +576,16 @@  int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 				ret = nand_write_skip_bad(nand, off, &rwsize,
 							  (u_char *)addr,
 							  WITH_DEFAULTS);
+#ifdef CONFIG_CMD_NAND_TRIMFFS
+		} else if (!strcmp(s, ".trimffs")) {
+			if (read) {
+				printf("Unknown nand command suffix '%s'\n", s);
+				return 1;
+			}
+			ret = nand_write_skip_bad(nand, off, &rwsize,
+						(u_char *)addr,
+						WITH_DROP_FFS);
+#endif
 #ifdef CONFIG_CMD_NAND_YAFFS
 		} else if (!strcmp(s, ".yaffs")) {
 			if (read) {
@@ -690,6 +700,12 @@  U_BOOT_CMD(
 	"nand write - addr off|partition size\n"
 	"    read/write 'size' bytes starting at offset 'off'\n"
 	"    to/from memory address 'addr', skipping bad blocks.\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"
+	"    'addr', skipping bad blocks and dropping any pages at the end\n"
+	"    of eraseblocks that contain only 0xFF\n"
+#endif
 #ifdef CONFIG_CMD_NAND_YAFFS
 	"nand write.yaffs - addr off|partition size\n"
 	"    write 'size' bytes starting at offset 'off' with yaffs format\n"
diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 2bfe743..357f332 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -11,6 +11,9 @@ 
  *		nandwrite.c by Steven J. Hill (sjhill@realitydiluted.com)
  *			       and Thomas Gleixner (tglx@linutronix.de)
  *
+ * Copyright (C) 2008 Nokia Corporation: drop_ffs() function by
+ * Artem Bityutskiy <dedekind1@gmail.com> from mtd-utils
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *