diff mbox

[U-Boot,4/5] cmd_nand: add nand write.ubi command

Message ID 37c0540a80871c9cc9faa9bc8c2d142f104d1ac7.1304026883.git.bengardiner@nanometrics.ca
State Superseded
Headers show

Commit Message

Ben Gardiner April 28, 2011, 9:47 p.m. UTC
Add another nand write. variant, ubi. This command will request of
nand_write_skip_bad() that all trailing all-0xff pages will be
dropped from eraseblocks as they are written as-per the
reccommended behaviour of the UBI FAQ.

Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
---
 common/cmd_nand.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Comments

Detlev Zundel April 29, 2011, 11:52 a.m. UTC | #1
Hi Ben,

> Add another nand write. variant, ubi. This command will request of
> nand_write_skip_bad() that all trailing all-0xff pages will be
> dropped from eraseblocks as they are written as-per the
> reccommended behaviour of the UBI FAQ.

If I understand the code correctly, then the assumption is that writing
FFs to an erased flash is essentially a no-op, right?  This is not
really UBI specific, so why don't we use a name like e.g. "trimffs" for
the new functionality?

Moreover now that I think about it, I can imagine a corner case where
the flash is not erased at positions where the image contains ffs.  As I
read your code, the ffs will silently be dropped and no error will be
generated, although the contents of the image will _not_ correpsond to
the contents in flash.

If this is right, then this has potential for great confusion.  Maybe we
should check that the flash is really erased at the positions
corresponding to ffs?

Cheers
  Detlev
diff mbox

Patch

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 69b2acc..faece07 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -567,7 +567,11 @@  int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 		rwsize = size;
 
 		s = strchr(cmd, '.');
-		if (!s || !strcmp(s, ".jffs2") ||
+		if (!strcmp(s, ".ubi")) {
+			ret = nand_write_skip_bad(nand, off, &rwsize,
+						  (u_char *)addr,
+						  WITH_DROP_FFS);
+		} else if (!s || !strcmp(s, ".jffs2") ||
 		    !strcmp(s, ".e") || !strcmp(s, ".i")) {
 			if (read)
 				ret = nand_read_skip_bad(nand, off, &rwsize,
@@ -694,6 +698,11 @@  U_BOOT_CMD(
 	"    write 'size' bytes starting at offset 'off' with yaffs format\n"
 	"    from memory address 'addr', skipping bad blocks.\n"
 #endif
+	"nand write.ubi - addr off|partition size\n"
+	"    write 'size' bytes starting at offset 'off'\n"
+	"    from memory address 'addr', skipping bad blocks and "
+	"dropping any pages at the\n"
+	"    end of eraseblocks that contain only 0xFF\n"
 	"nand erase[.spread] [clean] [off [size]] - erase 'size' bytes "
 	"from offset 'off'\n"
 	"    With '.spread', erase enough for given file size, otherwise,\n"