mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-21 22:08:08 +00:00
perf(core): optimize boot speed by checking empty image area by words
[no changelog]
This commit is contained in:
parent
c3f84e2949
commit
b3d1ba25d9
@ -280,23 +280,42 @@ secbool check_image_contents(const image_header *const hdr, uint32_t firstskip,
|
||||
return secfalse;
|
||||
}
|
||||
|
||||
uint32_t expected_word = expected_byte << 24 | expected_byte << 16 |
|
||||
expected_byte << 8 | expected_byte;
|
||||
|
||||
while (offset < end_offset) {
|
||||
size_t bytes_to_check = MIN(
|
||||
IMAGE_CHUNK_SIZE - (offset % IMAGE_CHUNK_SIZE), end_offset - offset);
|
||||
size_t words_to_check = bytes_to_check / sizeof(uint32_t);
|
||||
size_t single_bytes_to_check = bytes_to_check % sizeof(uint32_t);
|
||||
|
||||
const uint8_t *data =
|
||||
(const uint8_t *)flash_area_get_address(area, offset, bytes_to_check);
|
||||
if (!data) {
|
||||
const uint8_t *bytes = (const uint8_t *)flash_area_get_address(
|
||||
area, offset, single_bytes_to_check);
|
||||
if (!bytes) {
|
||||
return secfalse;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bytes_to_check; i++) {
|
||||
if (data[i] != expected_byte) {
|
||||
for (size_t i = 0; i < single_bytes_to_check; i++) {
|
||||
if (bytes[i] != expected_byte) {
|
||||
return secfalse;
|
||||
}
|
||||
}
|
||||
|
||||
offset += bytes_to_check;
|
||||
offset += single_bytes_to_check;
|
||||
|
||||
const uint32_t *data = (const uint32_t *)flash_area_get_address(
|
||||
area, offset, bytes_to_check - single_bytes_to_check);
|
||||
if (!data) {
|
||||
return secfalse;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < words_to_check; i++) {
|
||||
if (data[i] != expected_word) {
|
||||
return secfalse;
|
||||
}
|
||||
}
|
||||
|
||||
offset += words_to_check * sizeof(uint32_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user