Skip to content

Commit ec9e40d

Browse files
committed
target_flash: Fix blank_check for pages smaller than writebufsize
1 parent 02c338f commit ec9e40d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/target/target_flash.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,16 @@ static bool flash_blank_check(target_flash_s *flash, target_addr_t src, size_t l
391391
platform_timeout_s timeout;
392392
platform_timeout_set(&timeout, 500);
393393

394-
for (size_t offset = 0U; offset < len; offset += flash->writebufsize) {
394+
/* Pick smaller of: len = option bytes (8), writebufsize (1024), len = flash page (8192) */
395+
const size_t chunksize = flash->writebufsize < len ? flash->writebufsize : len;
396+
397+
for (size_t offset = 0U; offset < len; offset += chunksize) {
395398
/* Fetch chunk into sector buffer */
396-
target_mem32_read(target, flash->buf, src + offset, flash->writebufsize);
399+
target_mem32_read(target, flash->buf, src + offset, chunksize);
397400

398401
/* Compare bytewise with erased value */
399402
const uint8_t erased = flash->erased;
400-
for (size_t i = 0; i < flash->writebufsize; i++) {
403+
for (size_t i = 0; i < chunksize; i++) {
401404
if (flash->buf[i] != erased) {
402405
*mismatch = src + i;
403406
return false;

0 commit comments

Comments
 (0)