]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dfu, nand: before write a buffer to nand, erase the nand sectors
authorHeiko Schocher <hs@denx.de>
Mon, 24 Jun 2013 16:50:40 +0000 (18:50 +0200)
committerScott Wood <scottwood@freescale.com>
Mon, 24 Jun 2013 23:17:23 +0000 (18:17 -0500)
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

Using the nand erase option "spread", maybe overwrite
blocks on, for example another mtd partition, if the
erasing range contains bad blocks.
So a limit option is added to nand_erase_opts()

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>
Signed-off-by: Scott Wood <scottwood@freescale.com>
drivers/dfu/dfu_nand.c
drivers/mtd/nand/nand_util.c
include/nand.h

index 7dc89b2f2b483a9a96eae3606928a4b30591bb37..07dee89815c8cd7dc2033f9190ec29d5878d7623 100644 (file)
@@ -63,12 +63,26 @@ 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;
+               opts.spread = 1;
+               opts.quiet = 1;
+               opts.lim = lim;
+               /* 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",
index d81972ca27baa9f851af9aa872da262386f31d2c..1d22b5240d46701468ce911046dede4bf125ad43 100644 (file)
@@ -120,6 +120,10 @@ int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts)
 
                WATCHDOG_RESET();
 
+               if (opts->lim && (erase.addr >= (opts->offset + opts->lim))) {
+                       puts("Size of erase exceeds limit\n");
+                       return -EFBIG;
+               }
                if (!opts->scrub && bbtest) {
                        int ret = mtd_block_isbad(meminfo, erase.addr);
                        if (ret > 0) {
index 26190e4137da9ac05c896506f909d230f5f4537d..228d87127cae0a42e87230c8c55935148b3799e4 100644 (file)
@@ -125,6 +125,8 @@ struct nand_erase_options {
 
        /* Don't include skipped bad blocks in size to be erased */
        int spread;
+       /* maximum size that actual may be in order to not exceed the buf */
+       loff_t lim;
 };
 
 typedef struct nand_erase_options nand_erase_options_t;