@@ -45,11 +45,12 @@ String FlashSHA256::calc(uint32_t const start_addr, uint32_t const max_flash_siz
45
45
sha256.begin ();
46
46
47
47
/* 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 ;
49
50
memcpy (chunk, reinterpret_cast <const void *>(flash_addr), FLASH_READ_CHUNK_SIZE);
50
51
flash_addr += FLASH_READ_CHUNK_SIZE;
51
52
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)
53
54
{
54
55
/* Read the next chunk of memory. */
55
56
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
75
76
}
76
77
/* Update with the remaining bytes. */
77
78
sha256.update (chunk, valid_bytes_in_chunk);
79
+ bytes_read += valid_bytes_in_chunk;
78
80
break ;
79
81
}
80
82
81
83
/* We've read a normal segment with the next segment not containing
82
84
* any erased elements, just update the SHA256 hash calcultion.
83
85
*/
84
86
sha256.update (chunk, FLASH_READ_CHUNK_SIZE);
87
+ bytes_read += FLASH_READ_CHUNK_SIZE;
85
88
86
89
/* Copy next_chunk to chunk. */
87
90
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
100
103
sha256_str += buf;
101
104
});
102
105
/* Do some debug printout. */
103
- DEBUG_VERBOSE (" SHA256: %d bytes read" , flash_addr );
106
+ DEBUG_VERBOSE (" SHA256: %d bytes read" , bytes_read );
104
107
return sha256_str;
105
108
}
106
109
0 commit comments