aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGareth McMullin2014-07-30 16:48:56 +1200
committerGareth McMullin2014-07-30 16:48:56 +1200
commit936b7460e08d9be9e6635ef333f093e903b75274 (patch)
treef1d37969b4fa6b43c07e994ea9f358d9e6af0276
parentbfe5d1168b705623bf5c672c93aac4edb7d17725 (diff)
parent3daf5d7e11d5788987dd96b6491ceacdd6444f22 (diff)
Merge branch 'John-Titor-lpc11xx-flash'
-rw-r--r--src/lpc11xx.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/lpc11xx.c b/src/lpc11xx.c
index 0b422b0..ef26e78 100644
--- a/src/lpc11xx.c
+++ b/src/lpc11xx.c
@@ -260,26 +260,26 @@ lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src,
copylen = len;
memcpy(&flash_pgm.data[chunk_offset], src, copylen);
- /* update to suit */
- len -= copylen;
- src += copylen;
- chunk_offset = 0;
-
/* if we are programming the vectors, calculate the magic number */
- if (chunk == 0) {
+ if ((chunk == 0) && (chunk_offset == 0)) {
+ if (copylen < 32) {
+ /* we have to be programming at least the first 8 vectors... */
+ return -1;
+ }
+
uint32_t *w = (uint32_t *)(&flash_pgm.data[0]);
uint32_t sum = 0;
- 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;
- }
+ for (unsigned i = 0; i < 7; i++)
+ sum += w[i];
+ w[7] = ~sum + 1;
}
+ /* update to suit */
+ len -= copylen;
+ src += copylen;
+ chunk_offset = 0;
+
} else {
/* interior chunk, must be aligned and full-sized */