1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-16 18:30:57 +00:00

storage: Clean up old_storage_size

Note that OLD_STORAGE_SIZE(imported) != 460, because
OLD_STORAGE_SIZE does not include end padding
This commit is contained in:
Saleem Rashid 2017-08-22 17:06:04 +01:00 committed by Pavol Rusnak
parent 5812f9865d
commit a304b76d34

View File

@ -152,27 +152,29 @@ bool storage_from_flash(void)
memcpy(storage_uuid, (void *)(FLASH_STORAGE_START + sizeof(storage_magic)), sizeof(storage_uuid)); memcpy(storage_uuid, (void *)(FLASH_STORAGE_START + sizeof(storage_magic)), sizeof(storage_uuid));
data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str); data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str);
#define OLD_STORAGE_SIZE(last_member) (offsetof(Storage, last_member) + pb_membersize(Storage, last_member))
// copy storage // copy storage
size_t old_storage_size = 0; size_t old_storage_size = 0;
if (version == 1 || version == 2) { if (version == 1 || version == 2) {
old_storage_size = 460; old_storage_size = OLD_STORAGE_SIZE(imported);
} else } else
if (version == 3 || version == 4 || version == 5) { if (version == 3 || version == 4 || version == 5) {
// added homescreen // added homescreen
old_storage_size = 1488; old_storage_size = OLD_STORAGE_SIZE(homescreen);
} else } else
if (version == 6 || version == 7) { if (version == 6 || version == 7) {
// added u2fcounter // added u2fcounter
old_storage_size = 1496; old_storage_size = OLD_STORAGE_SIZE(u2f_counter);
} else } else
if (version == 8) { if (version == 8) {
// added flags and needsBackup // added flags and needsBackup
old_storage_size = 1504; old_storage_size = OLD_STORAGE_SIZE(flags);
} else } else
if (version == 9) { if (version == 9) {
// added u2froot // added u2froot
old_storage_size = 1640; old_storage_size = OLD_STORAGE_SIZE(u2froot);
} }
// erase newly added fields // erase newly added fields