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>
static int dfu_flush_medium_nand(struct dfu_entity *dfu)
{
int ret = 0;
static int dfu_flush_medium_nand(struct dfu_entity *dfu)
{
int ret = 0;
/* in case of ubi partition, erase rest of the partition */
if (dfu->data.nand.ubi) {
/* in case of ubi partition, erase rest of the partition */
if (dfu->data.nand.ubi) {
mtd = nand_info[nand_curr_device];
memset(&opts, 0, sizeof(opts));
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;
dfu->bad_skip;
opts.length = dfu->data.nand.start +
dfu->data.nand.size - opts.offset;