]> git.sur5r.net Git - u-boot/commitdiff
dfu, nand, ubi: fix erasing after write finish
authorHeiko Schocher <hs@denx.de>
Tue, 7 Jun 2016 06:55:44 +0000 (08:55 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 9 Jun 2016 17:53:13 +0000 (13:53 -0400)
writting to ubi nand partitions need after write ends an erase
of the remaining sectors. This fail, if dfu write size was not
a multiple of erasesize, example log:

Failure erase: -1

Fix this error.

Signed-off-by: Heiko Schocher <hs@denx.de>
drivers/dfu/dfu_nand.c

index ab782bead428f21720bd5a83fa49ea74e9af341b..9fb874c0bcd4f07c9ab1f6732117f4d7ed5a3c46 100644 (file)
@@ -139,6 +139,7 @@ static int dfu_read_medium_nand(struct dfu_entity *dfu, u64 offset, void *buf,
 static int dfu_flush_medium_nand(struct dfu_entity *dfu)
 {
        int ret = 0;
+       u64 off;
 
        /* in case of ubi partition, erase rest of the partition */
        if (dfu->data.nand.ubi) {
@@ -155,7 +156,16 @@ static int dfu_flush_medium_nand(struct dfu_entity *dfu)
                mtd = nand_info[nand_curr_device];
 
                memset(&opts, 0, sizeof(opts));
-               opts.offset = dfu->data.nand.start + dfu->offset +
+               off = dfu->offset;
+               if ((off & (mtd->erasesize - 1)) != 0) {
+                       /*
+                        * last write ended with unaligned length
+                        * sector is erased, jump to next
+                        */
+                       off = off & ~((mtd->erasesize - 1));
+                       off += mtd->erasesize;
+               }
+               opts.offset = dfu->data.nand.start + off +
                                dfu->bad_skip;
                opts.length = dfu->data.nand.start +
                                dfu->data.nand.size - opts.offset;