public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tao Hou <hotforest@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] mtd: nand: fix the written length when nand_write_skip_bad failed
Date: Sat,  2 Mar 2013 17:01:10 +0800	[thread overview]
Message-ID: <1362214870-7464-1-git-send-email-hotforest@gmail.com> (raw)

When the data has been partially written into the NAND Flash,
returning the written length instead of 0. The written length
may be useful when the upper level decides to continue the writing
after skipping the block causing the write failure.

Signed-off-by: Tao Hou <hotforest@gmail.com>
Cc: Scott Wood <scottwood@freescale.com>
Cc: Ben Gardiner <bengardiner@nanometrics.ca>
Cc: Lei Wen <leiwen@marvell.com>
---
 drivers/mtd/nand/nand_util.c |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index de1d13e..f57d723 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -496,8 +496,10 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 
 #ifdef CONFIG_CMD_NAND_YAFFS
 	if (flags & WITH_YAFFS_OOB) {
-		if (flags & ~WITH_YAFFS_OOB)
+		if (flags & ~WITH_YAFFS_OOB) {
+			*length = 0;
 			return -EINVAL;
+		}
 
 		int pages;
 		pages = nand->erasesize / nand->writesize;
@@ -505,6 +507,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 		if (*length % (nand->writesize + nand->oobsize)) {
 			printf("Attempt to write incomplete page"
 				" in yaffs mode\n");
+			*length = 0;
 			return -EINVAL;
 		}
 	} else
@@ -542,7 +545,6 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 		if (rval == 0)
 			return 0;
 
-		*length = 0;
 		printf("NAND write to offset %llx failed %d\n",
 			offset, rval);
 		return rval;
@@ -550,7 +552,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, truncated_write_size;
+		size_t write_size, truncated_write_size, written_size;
 
 		WATCHDOG_RESET();
 
@@ -586,8 +588,10 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 				ops.oobbuf = ops.datbuf + pagesize;
 
 				rval = nand->write_oob(nand, offset, &ops);
-				if (rval != 0)
+				if (rval != 0) {
+					written_size = pagesize_oob * page;
 					break;
+				}
 
 				offset += pagesize;
 				p_buffer += pagesize_oob;
@@ -605,14 +609,18 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 
 			rval = nand_write(nand, offset, &truncated_write_size,
 					p_buffer);
-			offset += write_size;
-			p_buffer += write_size;
+			if (rval == 0) {
+				offset += write_size;
+				p_buffer += write_size;
+			} else {
+				written_size = truncated_write_size;
+			}
 		}
 
 		if (rval != 0) {
 			printf("NAND write to offset %llx failed %d\n",
 				offset, rval);
-			*length -= left_to_write;
+			*length -= left_to_write - written_size;
 			return rval;
 		}
 
-- 
1.7.9.5

             reply	other threads:[~2013-03-02  9:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-02  9:01 Tao Hou [this message]
2013-03-05  1:58 ` [U-Boot] [PATCH] mtd: nand: fix the written length when nand_write_skip_bad failed Scott Wood
2013-03-06 14:56   ` htbegin
2013-03-06 18:22     ` Scott Wood
2013-03-07 15:02       ` htbegin
2013-03-07 22:27         ` Scott Wood
2013-03-10  1:06           ` htbegin
2013-03-11 16:43             ` Scott Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362214870-7464-1-git-send-email-hotforest@gmail.com \
    --to=hotforest@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox