[U-Boot] [PATCH] Pad data length for nand write

Derek Ou dou at siconix.com
Tue Feb 17 18:15:07 CET 2009


Signed-off-by: Derek Ou <dou at 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



More information about the U-Boot mailing list