From 120a2d9378c4b439917d44246f8df91ac259b39f Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Thu, 5 Oct 2017 22:07:23 +0200 Subject: [PATCH] target: Fix calculation of erase size. --- src/target/target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index a0da26c..e433bdb 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -199,7 +199,8 @@ int target_flash_erase(target *t, target_addr addr, size_t len) int ret = 0; while (len) { struct target_flash *f = flash_for_addr(t, addr); - size_t tmplen = MIN(len, f->length - (addr % f->length)); + size_t tmptarget = MIN(addr + len, f->start + f->length); + size_t tmplen = tmptarget - addr; ret |= f->erase(f, addr, tmplen); addr += tmplen; len -= tmplen;