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;