aboutsummaryrefslogtreecommitdiff
path: root/src/lpc11xx.c
diff options
context:
space:
mode:
authorGareth McMullin2014-07-30 16:45:55 +1200
committerGareth McMullin2014-07-30 16:45:55 +1200
commit3daf5d7e11d5788987dd96b6491ceacdd6444f22 (patch)
tree70178f1b083e8ce5f603ca0a2e4bb64db6a3a205 /src/lpc11xx.c
parent5d61575ce6508c76ed1800f46be47583b76408df (diff)
parent3543e560afdbd795683e7781c6d6dc5ff7567951 (diff)
Merge branch 'lpc11xx-flash' of https://github.com/John-Titor/blackmagic into John-Titor-lpc11xx-flash
Conflicts: src/lpc11xx.c
Diffstat (limited to 'src/lpc11xx.c')
-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 */