diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index cc9e2625cb..0b9e959cfd 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -537,14 +537,20 @@ void fsm_msgGetNextU2FCounter() { layoutHome(); } +static void progress_callback(uint32_t iter, uint32_t total) { + layoutProgress(_("Please wait"), 1000 * iter / total); +} + void fsm_msgGetFirmwareHash(const GetFirmwareHash *msg) { RESP_INIT(FirmwareHash); + layoutProgressSwipe(_("Please wait"), 0); if (memory_firmware_hash(msg->challenge.bytes, msg->challenge.size, - resp->hash.bytes) != 0) { + progress_callback, resp->hash.bytes) != 0) { fsm_sendFailure(FailureType_Failure_FirmwareError, NULL); return; } resp->hash.size = sizeof(resp->hash.bytes); msg_write(MessageType_MessageType_FirmwareHash, resp); + layoutHome(); } diff --git a/legacy/memory.c b/legacy/memory.c index 3f8abbc9c6..39cebb3f9a 100644 --- a/legacy/memory.c +++ b/legacy/memory.c @@ -22,6 +22,7 @@ #include #include "blake2s.h" #include "flash.h" +#include "layout.h" #include "sha2.h" #define FLASH_OPTION_BYTES_1 (*(const uint64_t *)0x1FFFC000) @@ -86,6 +87,7 @@ int memory_bootloader_hash(uint8_t *hash) { } int memory_firmware_hash(const uint8_t *challenge, uint32_t challenge_size, + void (*progress_callback)(uint32_t, uint32_t), uint8_t hash[BLAKE2S_DIGEST_LENGTH]) { BLAKE2S_CTX ctx; if (challenge_size != 0) { @@ -104,6 +106,10 @@ int memory_firmware_hash(const uint8_t *challenge, uint32_t challenge_size, return 1; } blake2s_Update(&ctx, data, size); + if (progress_callback != NULL) { + progress_callback(i - FLASH_CODE_SECTOR_FIRST, + FLASH_CODE_SECTOR_LAST - FLASH_CODE_SECTOR_FIRST); + } } return blake2s_Final(&ctx, hash, BLAKE2S_DIGEST_LENGTH); diff --git a/legacy/memory.h b/legacy/memory.h index 56584a9057..66b4b911c8 100644 --- a/legacy/memory.h +++ b/legacy/memory.h @@ -94,6 +94,7 @@ void memory_protect(void); void memory_write_unlock(void); int memory_bootloader_hash(uint8_t *hash); int memory_firmware_hash(const uint8_t *challenge, uint32_t challenge_size, + void (*progress_callback)(uint32_t, uint32_t), uint8_t hash[32]); static inline void flash_write32(uint32_t addr, uint32_t word) {