diff mbox

[U-Boot,2/4,v2] nand_util: convert nand_write_skip_bad() to flags

Message ID 3ea2081d8694778a35ca03a7940242dae8e88c75.1305823168.git.bengardiner@nanometrics.ca
State Superseded
Headers show

Commit Message

Ben Gardiner May 19, 2011, 4:49 p.m. UTC
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 <bengardiner@nanometrics.ca>
CC: Detlev Zundel <dzu@denx.de>

---
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(-)

Comments

Detlev Zundel May 24, 2011, 1:17 p.m. UTC | #1
Hi Ben,

> 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 <bengardiner@nanometrics.ca>
> CC: Detlev Zundel <dzu@denx.de>
>
> ---
> 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)

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

Acked-by: Detlev Zundel <dzu@denx.de>

Cheers
  Detlev
Ben Gardiner May 24, 2011, 1:27 p.m. UTC | #2
Hi Detlev,

On Tue, May 24, 2011 at 9:17 AM, Detlev Zundel <dzu@denx.de> wrote:
>> ---
>> 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)
>
> 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.

On Fri, Apr 29, 2011 at 7:44 AM, Detlev Zundel <dzu@denx.de> wrote:
>> diff --git a/common/cmd_nand.c b/common/cmd_nand.c
>> index 7bd37de..69b2acc 100644
>> --- a/common/cmd_nand.c
>> +++ b/common/cmd_nand.c
>> @@ -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);
>>  #endif
>>               } else if (!strcmp(s, ".oob")) {
>>                       /* out-of-band data */
>
> I see an occurrence of nand_write_skip_bad just above this if block.
> Please replace this also.

> If you remove that again, you can add my
>
> Acked-by: Detlev Zundel <dzu@denx.de>

Will do.

Thank you, Detlev.

,Ben Gardiner

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

Patch

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 7bd37de..cb752c1 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -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 */
diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 5a6f7ae..03ccd02 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -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;
diff --git a/include/nand.h b/include/nand.h
index 7459bd0..95b83a0 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -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