]> git.gag.com Git - fw/stlink/commitdiff
When ignoring the end of a file, make sure we don't ignore partial words.
authorJim Paris <jim@jtan.com>
Fri, 31 Jan 2014 21:26:35 +0000 (16:26 -0500)
committerJim Paris <jim@jtan.com>
Fri, 31 Jan 2014 21:26:35 +0000 (16:26 -0500)
Consider a 128-byte write to the chip.  If the last 2 bytes are
considered "empty", then len is adjusted to 126, and run_flash_loader
will only copy 126 bytes to RAM.  However, run_flash_loader then
proceeds to round up to 32 words (128 bytes) when flashing, which has
the effect of clobbering those last two "empty" bytes with junk data.

src/stlink-common.c

index b7645fe880f3dfc49a40fbaceb7d883505c58cc0..b942dea065e1428b6457676697bb0536fc273af2 100644 (file)
@@ -1752,8 +1752,10 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
        else
            num_empty = 0;
     }
+    /* Round down to words */
+    num_empty -= (num_empty & 3);
     if(num_empty != 0) {
-       ILOG("Ignoring %d bytes of Zeros at end of file\n",num_empty);
+       ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
        mf.len -= num_empty;
     }
     err = stlink_write_flash(sl, addr, mf.base, mf.len);