aboutsummaryrefslogtreecommitdiff
path: root/src/lpc11xx.c
diff options
context:
space:
mode:
authorRichard Eoin Meadows2013-09-08 13:13:16 +0100
committerGareth McMullin2013-10-05 13:14:03 +0800
commitb8f9a2ed4b607e5152eb007a100373b3253e32a0 (patch)
treea1d08afeb6047cb046009e8cf1b860ca383ae9e4 /src/lpc11xx.c
parent40820a2354bd76b86e429dbd9f213375dfe05af4 (diff)
Bugfix: Always apply the vector table magic number correctly.
Previously when the flash write length was less than the Chunk size the 2nd chunk write would re-calculate and apply an incorrect magic number
Diffstat (limited to 'src/lpc11xx.c')
-rw-r--r--src/lpc11xx.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lpc11xx.c b/src/lpc11xx.c
index 83f37ba..9adbe2b 100644
--- a/src/lpc11xx.c
+++ b/src/lpc11xx.c
@@ -216,13 +216,18 @@ lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src,
chunk_offset = 0;
/* if we are programming the vectors, calculate the magic number */
- if (chunk == 0) {
+ if (dest == 0) {
uint32_t *w = (uint32_t *)(&flash_pgm.data[0]);
uint32_t sum = 0;
- for (unsigned i = 0; i < 7; i++)
- sum += w[i];
- w[7] = 0 - sum;
+ if (copylen >= 7) {
+ for (unsigned i = 0; i < 7; i++)
+ sum += w[i];
+ w[7] = 0 - sum;
+ } else {
+ /* We can't possibly calculate the magic number */
+ return -1;
+ }
}
} else {