public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] dfu, nand: before write a buffer to nand, erase the nand sectors
@ 2013-06-14 10:24 Heiko Schocher
  2013-06-14 22:19 ` Scott Wood
  2013-06-17  5:01 ` [U-Boot] [PATCH v2] " Heiko Schocher
  0 siblings, 2 replies; 12+ messages in thread
From: Heiko Schocher @ 2013-06-14 10:24 UTC (permalink / raw)
  To: u-boot

before writing the received buffer to nand, erase the nand
sectors. If not doing this, nand write fails. See for
more info here:

http://lists.denx.de/pipermail/u-boot/2013-June/156361.html

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Scott Wood <scottwood@freescale.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@ti.com>
---
 common/cmd_nand.c      |  2 +-
 drivers/dfu/dfu_nand.c | 17 +++++++++++++++--
 include/nand.h         |  1 +
 3 Dateien ge?ndert, 17 Zeilen hinzugef?gt(+), 3 Zeilen entfernt(-)

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 8b1e01a..d3fe138 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -428,7 +428,7 @@ static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count,
 /* Adjust a chip/partition size down for bad blocks so we don't
  * read/write/erase past the end of a chip/partition by accident.
  */
-static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
+void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
 {
 	/* We grab the nand info object here fresh because this is usually
 	 * called after arg_off_size() which can change the value of dev.
diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c
index 7dc89b2..6f9a934 100644
--- a/drivers/dfu/dfu_nand.c
+++ b/drivers/dfu/dfu_nand.c
@@ -63,12 +63,25 @@ static int nand_block_op(enum dfu_nand_op op, struct dfu_entity *dfu,
 
 	nand = &nand_info[nand_curr_device];
 
-	if (op == DFU_OP_READ)
+	if (op == DFU_OP_READ) {
 		ret = nand_read_skip_bad(nand, start, &count, &actual,
 				lim, buf);
-	else
+	} else {
+		nand_erase_options_t opts;
+
+		memset(&opts, 0, sizeof(opts));
+		opts.offset = start;
+		opts.length = count;
+		adjust_size_for_badblocks(&opts.length, offset,
+					  nand_curr_device);
+		/* first erase */
+		ret = nand_erase_opts(nand, &opts);
+		if (ret)
+			return ret;
+		/* then write */
 		ret = nand_write_skip_bad(nand, start, &count, &actual,
 				lim, buf, 0);
+	}
 
 	if (ret != 0) {
 		printf("%s: nand_%s_skip_bad call failed at %llx!\n",
diff --git a/include/nand.h b/include/nand.h
index 26190e4..8495b73 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -141,6 +141,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 			size_t *actual, loff_t lim, u_char *buffer, int flags);
 int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts);
 int nand_torture(nand_info_t *nand, loff_t offset);
+void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev);
 
 #define NAND_LOCK_STATUS_TIGHT	0x01
 #define NAND_LOCK_STATUS_UNLOCK 0x04
-- 
1.7.11.7

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

end of thread, other threads:[~2013-07-26 22:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-14 10:24 [U-Boot] [PATCH] dfu, nand: before write a buffer to nand, erase the nand sectors Heiko Schocher
2013-06-14 22:19 ` Scott Wood
2013-06-17  5:01 ` [U-Boot] [PATCH v2] " Heiko Schocher
2013-06-18  0:51   ` Scott Wood
2013-06-20  4:36     ` Heiko Schocher
2013-06-20 17:22       ` Scott Wood
2013-06-21  5:09   ` [U-Boot] [PATCH v3] " Heiko Schocher
2013-06-21 22:50     ` Scott Wood
2013-06-24 16:50     ` [U-Boot] [PATCH v4] " Heiko Schocher
2013-06-24 23:26       ` Scott Wood
2013-07-25  4:43       ` [U-Boot] [PATCH v5] dfu, nand, ubi: add partubi alt settings for updating ubi partition Heiko Schocher
2013-07-26 22:05         ` Scott Wood

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