From a7815fff3d292ada671347320dd171f9915993cf Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 4 Oct 2017 14:35:26 +0200 Subject: [PATCH] target.c: No need to split write while still in same flash block. --- 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 c984ffe6..a0da26c6 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -213,7 +213,8 @@ int target_flash_write(target *t, int ret = 0; while (len) { struct target_flash *f = flash_for_addr(t, dest); - size_t tmplen = MIN(len, f->length - (dest % f->length)); + size_t tmptarget = MIN(dest + len, f->start + f->length); + size_t tmplen = tmptarget - dest; if (f->align > 1) { uint32_t offset = dest % f->align; uint8_t data[ALIGN(offset + tmplen, f->align)];