Skip to content

Commit

Permalink
When ignoring the end of a file, make sure we don't ignore partial wo…
Browse files Browse the repository at this point in the history
…rds.

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.
  • Loading branch information
jimparis committed Jan 31, 2014
1 parent bc49ed6 commit 5dcd45d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stlink-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5dcd45d

Please sign in to comment.