diff --git a/firmware/fsm.c b/firmware/fsm.c index 532ec14f8d..08bc5bee97 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -452,6 +452,8 @@ void fsm_msgBackupDevice(BackupDevice *msg) { CHECK_INITIALIZED + CHECK_PIN_UNCACHED + (void)msg; reset_backup(true); } diff --git a/firmware/reset.c b/firmware/reset.c index 5efe7be68b..7f8d2c3810 100644 --- a/firmware/reset.c +++ b/firmware/reset.c @@ -121,15 +121,18 @@ void reset_backup(bool separated) storage_commit(); for (int pass = 0; pass < 2; pass++) { - int i = 0; - for (int word_pos = 1; word_pos <= (int)strength/32*3; word_pos++) { + int i = 0, word_pos = 1; + while (storage.mnemonic[i] != 0) { // copy current_word int j = 0; while (storage.mnemonic[i] != ' ' && storage.mnemonic[i] != 0 && j + 1 < (int)sizeof(current_word)) { current_word[j] = storage.mnemonic[i]; i++; j++; } - current_word[j] = 0; if (storage.mnemonic[i] != 0) i++; + current_word[j] = 0; + if (storage.mnemonic[i] != 0) { + i++; + } char desc[] = "##th word is:"; if (word_pos < 10) { desc[0] = ' '; @@ -151,7 +154,7 @@ void reset_backup(bool separated) current_word_display[j + 1] = current_word[j] + 'A' - 'a'; } current_word_display[j + 1] = 0; - if (word_pos == (int)strength/32*3) { // last word + if (storage.mnemonic[i] == 0) { // last word if (pass == 1) { layoutDialogSwipe(&bmp_icon_info, NULL, _("Finish"), NULL, _("Please check the seed"), NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); } else { @@ -172,6 +175,7 @@ void reset_backup(bool separated) fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); return; } + word_pos++; } } diff --git a/firmware/storage.c b/firmware/storage.c index 8bb06b2593..e222928d83 100644 --- a/firmware/storage.c +++ b/firmware/storage.c @@ -102,7 +102,7 @@ static bool sessionPinCached; static bool sessionPassphraseCached; static char sessionPassphrase[51]; -#define STORAGE_VERSION 7 +#define STORAGE_VERSION 8 void storage_show_error(void) { @@ -133,6 +133,7 @@ bool storage_from_flash(void) // version 5: since 1.3.3 // version 6: since 1.3.6 // version 7: since 1.5.1 + // version 8: since 1.5.2 if (version > STORAGE_VERSION) { // downgrade -> clear storage return false; @@ -141,8 +142,26 @@ bool storage_from_flash(void) // load uuid memcpy(storage_uuid, (void *)(FLASH_STORAGE_START + 4), sizeof(storage_uuid)); data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str); + // copy storage - memcpy(&storage, (void *)(FLASH_STORAGE_START + 4 + sizeof(storage_uuid)), sizeof(Storage)); + size_t old_storage_size = 0; + + if (version == 1 || version == 2) { + old_storage_size = 460; + } else + if (version == 3 || version == 4 || version == 5) { + old_storage_size = 1488; + } else + if (version == 6 || version == 7) { + old_storage_size = 1496; + } else + if (version == 8) { + old_storage_size = 1504; + } + + memset(&storage, 0, sizeof(Storage)); + memcpy(&storage, (void *)(FLASH_STORAGE_START + 4 + sizeof(storage_uuid)), old_storage_size); + if (version <= 5) { // convert PIN failure counter from version 5 format uint32_t pinctr = storage.has_pin_failed_attempts diff --git a/firmware/trezor.h b/firmware/trezor.h index df6200b355..7abbe9ce8a 100644 --- a/firmware/trezor.h +++ b/firmware/trezor.h @@ -22,7 +22,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 5 -#define VERSION_PATCH 1 +#define VERSION_PATCH 2 #define STR(X) #X #define VERSTR(X) STR(X)