public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Pad data length for nand write
@ 2009-02-17 17:15 Derek Ou
  2009-02-17 17:15 ` Derek Ou
  2009-02-17 17:55 ` Mike Frysinger
  0 siblings, 2 replies; 10+ messages in thread
From: Derek Ou @ 2009-02-17 17:15 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Derek Ou <dou@siconix.com>
---
 drivers/mtd/nand/nand_util.c |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 6ba52b3..b9d292a 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -475,25 +475,36 @@ int nand_write_skip_bad(nand_info_t *nand, size_t offset, size_t *length,
 {
 	int rval;
 	size_t left_to_write = *length;
+	size_t page_offset, pad_len = 0;
 	size_t len_incl_bad;
 	u_char *p_buffer = buffer;
 
-	/* Reject writes, which are not page aligned */
-	if ((offset & (nand->writesize - 1)) != 0 ||
-	    (*length & (nand->writesize - 1)) != 0) {
-		printf ("Attempt to write non page aligned data\n");
+	/* Reject writes when offset is not page aligned */
+	if ((offset & (nand->writesize - 1)) != 0 ) {
+		printf ("Attempt to write address non page aligned\n");
 		return -EINVAL;
 	}
 
-	len_incl_bad = get_len_incl_bad (nand, offset, *length);
+	/* Pad write length if it's not page aligned */
+	page_offset = left_to_write & (nand->writesize - 1);
+	if (page_offset != 0) {
+		pad_len = nand->writesize - page_offset;
+		left_to_write += pad_len;
+	}
+
+	len_incl_bad = get_len_incl_bad (nand, offset, left_to_write);
 
 	if ((offset + len_incl_bad) >= nand->size) {
 		printf ("Attempt to write outside the flash area\n");
 		return -EINVAL;
 	}
 
-	if (len_incl_bad == *length) {
-		rval = nand_write (nand, offset, length, buffer);
+	/* now, pad data with 0xff */
+	if (page_offset != 0)
+		memset(buffer + *length, 0xff, pad_len);
+
+	if (len_incl_bad == left_to_write) {
+		rval = nand_write (nand, offset, &left_to_write, buffer);
 		if (rval != 0)
 			printf ("NAND write to offset %zx failed %d\n",
 				offset, rval);
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-02-17 21:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-17 17:15 [U-Boot] [PATCH] Pad data length for nand write Derek Ou
2009-02-17 17:15 ` Derek Ou
2009-02-17 18:51   ` Scott Wood
2009-02-17 20:54     ` Derek Ou
2009-02-17 21:16       ` Scott Wood
2009-02-17 21:37         ` Derek Ou
2009-02-17 17:55 ` Mike Frysinger
2009-02-17 18:37   ` Derek Ou
2009-02-17 18:41     ` Scott Wood
2009-02-17 20:22     ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox