Skip to content

Commit 48afe74

Browse files
committed
Bugfix: Function was not working correctly when start of flash was != 0.
1 parent 364319d commit 48afe74

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utility/ota/FlashSHA256.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ String FlashSHA256::calc(uint32_t const start_addr, uint32_t const max_flash_siz
4545
sha256.begin();
4646

4747
/* Read the first two chunks of flash. */
48-
uint32_t flash_addr = start_addr;
48+
uint32_t flash_addr = start_addr;
49+
uint32_t bytes_read = 0;
4950
memcpy(chunk, reinterpret_cast<const void *>(flash_addr), FLASH_READ_CHUNK_SIZE);
5051
flash_addr += FLASH_READ_CHUNK_SIZE;
5152

52-
for(; flash_addr < max_flash_size; flash_addr += FLASH_READ_CHUNK_SIZE)
53+
for(; bytes_read < max_flash_size; flash_addr += FLASH_READ_CHUNK_SIZE)
5354
{
5455
/* Read the next chunk of memory. */
5556
memcpy(next_chunk, reinterpret_cast<const void *>(flash_addr), FLASH_READ_CHUNK_SIZE);
@@ -75,13 +76,15 @@ String FlashSHA256::calc(uint32_t const start_addr, uint32_t const max_flash_siz
7576
}
7677
/* Update with the remaining bytes. */
7778
sha256.update(chunk, valid_bytes_in_chunk);
79+
bytes_read += valid_bytes_in_chunk;
7880
break;
7981
}
8082

8183
/* We've read a normal segment with the next segment not containing
8284
* any erased elements, just update the SHA256 hash calcultion.
8385
*/
8486
sha256.update(chunk, FLASH_READ_CHUNK_SIZE);
87+
bytes_read += FLASH_READ_CHUNK_SIZE;
8588

8689
/* Copy next_chunk to chunk. */
8790
memcpy(chunk, next_chunk, FLASH_READ_CHUNK_SIZE);
@@ -100,7 +103,7 @@ String FlashSHA256::calc(uint32_t const start_addr, uint32_t const max_flash_siz
100103
sha256_str += buf;
101104
});
102105
/* Do some debug printout. */
103-
DEBUG_VERBOSE("SHA256: %d bytes read", flash_addr);
106+
DEBUG_VERBOSE("SHA256: %d bytes read", bytes_read);
104107
return sha256_str;
105108
}
106109

0 commit comments

Comments
 (0)