Skip to content

Commit

Permalink
target_flash: simplify inner loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Oct 24, 2024
1 parent 5b19498 commit 8c8db53
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/target/target_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,18 @@ static bool flash_blank_check(target_flash_s *flash, target_addr_t src, size_t l
platform_timeout_s timeout;
platform_timeout_set(&timeout, 500);

while (len) {
const size_t offset = src % flash->writebufsize;
const size_t local_len = MIN(flash->writebufsize - offset, len);
for (size_t offset = 0U; offset < len; offset += flash->writebufsize) {
/* Fetch chunk into sector buffer */
target_mem32_read(target, flash->buf, src, local_len);
target_mem32_read(target, flash->buf, src + offset, flash->writebufsize);

/* Compare bytewise with erased value */
const uint8_t erased = flash->erased;
for (size_t i = 0; i < local_len; i++) {
for (size_t i = 0; i < flash->writebufsize; i++) {
if (flash->buf[i] != erased) {
*mismatch = src + i;
return false;
}
}
src += local_len;
len -= local_len;
target_print_progress(&timeout);
}
return result;
Expand Down

0 comments on commit 8c8db53

Please sign in to comment.