[U-Boot] [PATCH] dfu, nand: before write a buffer to nand, erase the nand sectors
Heiko Schocher
hs at denx.de
Fri Jun 14 12:24:03 CEST 2013
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 at denx.de>
Cc: Scott Wood <scottwood at freescale.com>
Cc: Pantelis Antoniou <panto at antoniou-consulting.com>
Cc: Lukasz Majewski <l.majewski at samsung.com>
Cc: Kyungmin Park <kyungmin.park at samsung.com>
Cc: Marek Vasut <marex at denx.de>
Cc: Tom Rini <trini at 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
More information about the U-Boot
mailing list