introduce nand write.trimffs
Subsystems (2)
v2 cover introduce nand write.trimffs
This series adds a nand write variant which implements the procedure reccomended in the UBI FAQ [1] of dropping trailing pages of eraseblocks containing entirely 0xff's.
[1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo
Changes since v1:
* renamed to 'trimffs' from 'ubi'
* wrapped the new feature in #ifdefs
* don't make it default for jffs -- patch dropped
* attribution of the drop_ffs() function from mtd-utils to Artem
Ben Gardiner (4):
[v2] nand_base: trivial: fix comment read/write comment [v2] nand_util: convert nand_write_skip_bad() to flags [v2] nand_util: drop trailing all-0xff pages if requested [v2] cmd_nand: add nand write.trimffs command
common/cmd_nand.c | 22 +++++++++++++++++++- drivers/mtd/nand/nand_base.c | 2 +- drivers/mtd/nand/nand_util.c | 43 +++++++++++++++++++++++++++++++++++------ include/nand.h | 7 +++++- 4 files changed, 63 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.4.1
PATCH v2 1/4 nand_base: trivial: fix comment read/write comment
Replace an incorrect 'read' with 'write' in a comment.
---
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")
--- drivers/mtd/nand/nand_base.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/nand/nand_base.c +1 -1
@@ -1950,7 +1950,7 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,struct nand_chip *chip = mtd->priv;int ret; -/* Do not allow reads past end of device */ +/* Do not allow writes past end of device */ if ((to + len) > mtd->size)return -EINVAL ;if (!len)
Signature · 1 line
1.7.4.1
PATCH v2 2/4 nand_util: convert nand_write_skip_bad() to flags
In reply to Ben GardinerIn a future commit the behaviour of nand_write_skip_bad() will be further extended.
Convert the only flag currently passed to the nand_write_ skip_bad() function to a bitfield of only one allocated member. This should avoid an explosion of int's at the end of the parameter list or the ambiguous calls like
nand_write_skip_bad(info, offset, len, buf, 0, 1, 1); nand_write_skip_bad(info, offset, len, buf, 0, 1, 0);
Instead there will be:
nand_write_skip_bad(info, offset, len, buf, WITH_YAFFS_OOB |
WITH_OTHER);
---
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 flag from WITH_OOB to WITH_YAFFS_OOB (Detlev Zundel)
* introduce 'WITH_DEFAULTS' flag defined as 0 so as to convert also the remaining nand_write_skip_bad() call (Detlev Zundel)
--- common/cmd_nand.c | 6 ++++-- drivers/mtd/nand/nand_util.c | 8 ++++---- include/nand.h | 6 +++++- 3 files changed, 13 insertions(+), 7 deletions(-)
common/cmd_nand.c +4 -2
@@ -574,14 +574,16 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) (u_char *)addr); else ret =nand_write_skip_bad (nand, off, &rwsize, - (u_char *)addr,0 ); + (u_char *)addr, +WITH_DEFAULTS ); #ifdef CONFIG_CMD_NAND_YAFFS }else if (!strcmp (s,".yaffs" )) {if (read) {printf ("Unknown nand command suffix '%s'.\n" , s);return 1 ; } - ret =nand_write_skip_bad (nand, off, &rwsize, (u_char *)addr,1 ); + ret =nand_write_skip_bad (nand, off, &rwsize, + (u_char *)addr,WITH_YAFFS_OOB );#endif }else if (!strcmp (s,".oob" )) {/* out-of-band data */
drivers/mtd/nand/nand_util.c +4 -4
@@ -448,11 +448,11 @@ static int check_skip_len(nand_info_t *nand, loff_t offset, size_t length)* @param offset offset in flash * @param length buffer length * @param buffer buffer to read from -* @param withoob whether write with yaffs format +* @param flags flags mmofying the behaviour of the write to NAND * @return 0 in case of success */ int nand_write_skip_bad (nand_info_t *nand,loff_t offset,size_t *length, -u_char *buffer,int withoob) +u_char *buffer,int flags) {int rval =0 , blocksize;size_t left_to_write = *length;
@@ -460,7 +460,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,int need_skip;#ifdef CONFIG_CMD_NAND_YAFFS -if (withoob) { +if (flags &WITH_YAFFS_OOB ) {int pages; pages = nand->erasesize / nand->writesize; blocksize = (pages * nand->oobsize) + nand->erasesize;
@@ -529,7 +529,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, write_size = blocksize - block_offset;#ifdef CONFIG_CMD_NAND_YAFFS -if (withoob) { +if (flags &WITH_YAFFS_OOB ) {int page, pages;size_t pagesize = nand->writesize;size_t pagesize_oob = pagesize + nand->oobsize;
include/nand.h +5 -1
@@ -114,8 +114,12 @@ typedef struct nand_erase_options nand_erase_options_t;int nand_read_skip_bad (nand_info_t *nand,loff_t offset,size_t *length,u_char *buffer); + +#define WITH_YAFFS_OOB (1 << 0)/* whether write with yaffs format */ +#define WITH_DEFAULTS 0 +int nand_write_skip_bad (nand_info_t *nand,loff_t offset,size_t *length, -u_char *buffer,int withoob); +u_char *buffer,int flags);int nand_erase_opts (nand_info_t *meminfo,const nand_erase_options_t *opts);#define NAND_LOCK_STATUS_TIGHT 0x01
Signature · 1 line
1.7.4.1
PATCH v2 3/4 nand_util: drop trailing all-0xff pages if requested
In reply to Ben GardinerAdd a flag to nand_read_skip_bad() such that if true, any trailing pages in an eraseblock whose contents are entirely 0xff will be dropped.
The implementation is via a new drop_ffs() function which is based on the function of the same name from the ubiformat utility by Artem Bityutskiy.
This is as-per the reccomendations of the UBI FAQ [1]
[1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo
---
This behaviour was found to fix both UBI and JFFS2 images written to cleanly erased NAND partitions on da850evm.
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")
* wrap the new functionality in a CONFIG_CMD_NAND_TRIMFFS ifdef to reduce size impact of new feature
--- drivers/mtd/nand/nand_util.c | 32 +++++++++++++++++++++++++++++--- include/nand.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-)
drivers/mtd/nand/nand_util.c +29 -3
@@ -436,6 +436,24 @@ static int check_skip_len(nand_info_t *nand, loff_t offset, size_t length)return ret; } +#ifdef CONFIG_CMD_NAND_TRIMFFS +static size_t drop_ffs (const nand_info_t *nand,const u_char *buf, +const size_t *len) +{ +size_t i, l = *len; + +for (i = l -1 ; i >=0 ; i--) +if (((const uint8_t *)buf)[i] !=0xFF ) +break ; + +/* The resulting length must be aligned to the minimum flash I/O size */ + l = i +1 ; + l = (l + nand->writesize -1 ) / nand->writesize; + l *= nand->writesize; +return l; +} +#endif +/** * nand_write_skip_bad: *
@@ -499,7 +517,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,return -EINVAL ; } -if (!need_skip) { +if (!need_skip && !(flags &WITH_DROP_FFS )) { rval =nand_write (nand, offset, length, buffer);if (rval ==0 )return 0 ;
@@ -512,7 +530,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,while (left_to_write >0 ) {size_t block_offset = offset & (nand->erasesize -1 ); -size_t write_size; +size_t write_size, truncated_write_size;WATCHDOG_RESET ();
@@ -558,7 +576,15 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, else#endif { - rval =nand_write (nand, offset, &write_size, p_buffer); + truncated_write_size = write_size; +#ifdef CONFIG_CMD_NAND_TRIMFFS +if (flags &WITH_DROP_FFS ) + truncated_write_size =drop_ffs (nand, p_buffer, + &write_size); +#endif + + rval =nand_write (nand, offset, &truncated_write_size, + p_buffer); offset += write_size; p_buffer += write_size; }
include/nand.h +1 -0
@@ -116,6 +116,7 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, u_char *buffer);#define WITH_YAFFS_OOB (1 << 0)/* whether write with yaffs format */ +#define WITH_DROP_FFS (1 << 1)/* drop trailing all-0xff pages */ #define WITH_DEFAULTS 0 int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
Signature · 1 line
1.7.4.1
PATCH v2 4/4 cmd_nand: add nand write.trimffs command
In reply to Ben GardinerAdd 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
---
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(-)
common/cmd_nand.c +16 -0
@@ -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"
drivers/mtd/nand/nand_util.c +3 -0
@@ -11,6 +11,9 @@* nandwrite.c by Steven J. Hill (sjhill at realitydiluted.com) * and Thomas Gleixner (tglx at linutronix.de) * +* Copyright (C) 2008 Nokia Corporation: drop_ffs() function by +* Artem Bityutskiy <[email protected]> from mtd-utils +* * See file CREDITS for list of people who contributed to this * project. *
Signature · 1 line
1.7.4.1
PATCH v2 1/4 nand_base: trivial: fix comment read/write comment
In reply to Ben GardinerHi Ben,
Quoted 3 lines
Replace an incorrect 'read' with 'write' in a comment.
Signed-off-by Ben Gardiner <[email protected]>
Signature · 7 lines
Whenever you find yourself on the side of the majority it is
time to pause and reflect.
-- Mark Twain
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.dePATCH v2 2/4 nand_util: convert nand_write_skip_bad() to flags
In reply to Ben GardinerHi Ben,
Quoted 19 lines
In a future commit the behaviour of
nand_write_skip_bad()will be further extended.Convert the only flag currently passed to the
nand_write_skip_bad()function to a bitfield of only one allocated member. This should avoid an explosion of int's at the end of the parameter list or the ambiguous calls like
nand_write_skip_bad(info, offset, len, buf, 0, 1, 1);nand_write_skip_bad(info, offset, len, buf, 0, 1, 0);Instead there will be:
nand_write_skip_bad(info, offset, len, buf,
WITH_YAFFS_OOB|WITH_OTHER);Signed-off-by Ben Gardiner <[email protected]>CC Detlev Zundel <[email protected]>
Quoted 7 lines
---
Changes since v1:
* rebased to HEAD ofgit://git.denx.de/u-boot-nand-flash.git: ff7b4a0 ("env_nand: zero-initialize variablenand_erase_options")
* renamed the flag fromWITH_OOBtoWITH_YAFFS_OOB(Detlev Zundel)
* introduce 'WITH_DEFAULTS' flag defined as 0 so as to convert also the remainingnand_write_skip_bad()call (Detlev Zundel)
I don't remember requesting this change - and rereading my mails I cannot find anything either. Actually I consider this define to be overkill. What I was asking for was to change all occurrences of the function call - a 0 for flags is ok with me.
If you remove that again, you can add my
Cheers
Detlev
Signature · 8 lines
I've been examining the existing [linux] kernel configuration system, and I
have about concluded that the best favor we could do everybody involved with
it is to take it out behind the barn and shoot it through the head.
-- Eric S. Raymond on linux-kbuild Mar 2000
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.dePATCH v2 4/4 cmd_nand: add nand write.trimffs command
In reply to Ben GardinerHi Ben,
Quoted 14 lines
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 <[email protected]>CC Artem Bityutskiy <[email protected]>CC Detlev Zundel <[email protected]>
Quoted 6 lines
---
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
Signature · 8 lines
Modern technique has made it possible for leisure, within limits, to be not the prerogative of small privileged classes, but a right evenly distributed throughout the community. The morality of work is the morality of slaves, and the modern world has no need of slavery. -- Bertrand Russell -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
PATCH v2 3/4 nand_util: drop trailing all-0xff pages if requested
In reply to Ben GardinerHi Ben,
Quoted 4 lines
Add a flag to
nand_read_skip_bad()such that if true, any trailing pages in an eraseblock whose contents are entirely0xffwill be dropped.
Quoted 8 lines
The implementation is via a new
drop_ffs()function which is based on the function of the same name from the ubiformat utility by Artem Bityutskiy.This is as-per the reccomendations of the UBI FAQ [1]
Signed-off-by Ben Gardiner <[email protected]>CC Artem Bityutskiy <[email protected]>
Cheers
Detlev
Signature · 8 lines
"Oh, didn't you know, the Lord did the original programming of the universe in COBOL." - "That's why the world is the evil work of Satan. A true divine being would have used Scheme." - "And, if so, Jesus would have been crucified on a big lambda symbol." -- K. Chafin, K. Schilling & D. Hanley, on comp.lang.lisp -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
PATCH v2 2/4 nand_util: convert nand_write_skip_bad() to flags
In reply to Detlev ZundelHi Detlev,
Quoted 8 lines · Detlev Zundel
Quoted 7 lines
---
Changes since v1:
?* rebased to HEAD ofgit://git.denx.de/u-boot-nand-flash.git: ff7b4a0 ? ?("env_nand: zero-initialize variablenand_erase_options") ?* renamed the flag fromWITH_OOBtoWITH_YAFFS_OOB(Detlev Zundel) ?* introduce 'WITH_DEFAULTS' flag defined as 0 so as to convert also ? ?the remainingnand_write_skip_bad()call (Detlev Zundel)
Quoted 4 lines
I don't remember requesting this change - and rereading my mails I cannot find anything either. ?Actually I consider this define to be overkill. ?What I was asking for was to change all occurrences of the function call - a 0 for flags is ok with me.
Sorry. That was how I interpreted the following. My mistake.
Quoted 18 lines · Detlev Zundel
Quoted 11 lines
common/cmd_nand.c +2
-1@@ -581,7 +581,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("Unknown nand command suffix '%s'.\n", s); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return 1; ? ? ? ? ? ? ? ? ? ? ? } - ? ? ? ? ? ? ? ? ? ? ret = nand_write_skip_bad(nand, off, &rwsize, (u_char *)addr, 1); + ? ? ? ? ? ? ? ? ? ? ret = nand_write_skip_bad(nand, off, &rwsize, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (u_char *)addr, WITH_OOB);Quoted 3 lines
?#endif
? ? ? ? ? ? ? } else if (!strcmp(s, ".oob")) {
? ? ? ? ? ? ? ? ? ? ? /* out-of-band data */I see an occurrence of
nand_write_skip_badjust above this if block. Please replace this also.
Quoted 3 lines
If you remove that again, you can add my
Acked-by Detlev Zundel <[email protected]>
Will do.
Thank you, Detlev.
,Ben Gardiner
---
Nanometrics Inc.
http://www.nanometrics.ca
PATCH v2 4/4 cmd_nand: add nand write.trimffs command
In reply to Detlev ZundelHi Detlev,
Quoted 2 lines · Detlev Zundel
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