aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lpc43xx.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lpc43xx.c b/src/lpc43xx.c
index fbd3941..6954404 100644
--- a/src/lpc43xx.c
+++ b/src/lpc43xx.c
@@ -431,12 +431,20 @@ static int lpc43xx_flash_write(struct target_s *target, uint32_t dest, const uin
{
unsigned first_chunk = dest / IAP_PGM_CHUNKSIZE;
unsigned last_chunk = (dest + len - 1) / IAP_PGM_CHUNKSIZE;
- unsigned chunk_offset = dest % IAP_PGM_CHUNKSIZE;
+ unsigned chunk_offset;
unsigned chunk;
struct flash_program flash_pgm;
for (chunk = first_chunk; chunk <= last_chunk; chunk++)
{
+ if (chunk == first_chunk)
+ {
+ chunk_offset = dest % IAP_PGM_CHUNKSIZE;
+ }
+ else
+ {
+ chunk_offset = 0;
+ }
/* first and last chunk may require special handling */
if ((chunk == first_chunk) || (chunk == last_chunk)) {
@@ -454,7 +462,6 @@ static int lpc43xx_flash_write(struct target_s *target, uint32_t dest, const uin
/* update to suit */
len -= copylen;
src += copylen;
- chunk_offset = 0;
} else {
/* interior chunk, must be aligned and full-sized */