1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

core: port storage to T1

This commit is contained in:
Ondrej Mikle 2020-06-01 15:44:36 +02:00 committed by Pavol Rusnak
parent 2815b62838
commit c877dc8dd6
26 changed files with 102 additions and 6 deletions

View File

@ -28,14 +28,10 @@
#if TREZOR_MODEL == T
#define NORCOW_SECTOR_SIZE (64 * 1024)
#define NORCOW_SECTORS \
{ FLASH_SECTOR_STORAGE_1, FLASH_SECTOR_STORAGE_2 }
#elif TREZOR_MODEL == 1
#define NORCOW_SECTOR_SIZE (16 * 1024)
#define NORCOW_SECTORS \
{ 2, 3 }
#else
@ -43,6 +39,9 @@
#endif
#define NORCOW_SECTORS \
{ FLASH_SECTOR_STORAGE_1, FLASH_SECTOR_STORAGE_2 }
/*
* Current storage version.
*/

View File

@ -39,6 +39,7 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[9] = 0x080A0000, // - 0x080BFFFF | 128 KiB
[10] = 0x080C0000, // - 0x080DFFFF | 128 KiB
[11] = 0x080E0000, // - 0x080FFFFF | 128 KiB
#if TREZOR_MODEL == T
[12] = 0x08100000, // - 0x08103FFF | 16 KiB
[13] = 0x08104000, // - 0x08107FFF | 16 KiB
[14] = 0x08108000, // - 0x0810BFFF | 16 KiB
@ -52,6 +53,9 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[22] = 0x081C0000, // - 0x081DFFFF | 128 KiB
[23] = 0x081E0000, // - 0x081FFFFF | 128 KiB
[24] = 0x08200000, // last element - not a valid sector
#elif TREZOR_MODEL == 1
[12] = 0x08100000, // last element - not a valid sector
#endif
};
const uint8_t FIRMWARE_SECTORS[FIRMWARE_SECTORS_COUNT] = {

View File

@ -26,7 +26,11 @@
// see docs/memory.md for more information
#if TREZOR_MODEL == T
#define FLASH_SECTOR_COUNT 24
#elif TREZOR_MODEL == 1
#define FLASH_SECTOR_COUNT 12
#endif
#define FLASH_SECTOR_BOARDLOADER_START 0
// 1
@ -34,7 +38,13 @@
// 3
#if TREZOR_MODEL == T
#define FLASH_SECTOR_STORAGE_1 4
#define FLASH_SECTOR_STORAGE_2 16
#elif TREZOR_MODEL == 1
#define FLASH_SECTOR_STORAGE_1 2
#define FLASH_SECTOR_STORAGE_2 3
#endif
#define FLASH_SECTOR_BOOTLOADER 5
@ -50,8 +60,6 @@
// 14
#define FLASH_SECTOR_UNUSED_END 15
#define FLASH_SECTOR_STORAGE_2 16
#define FLASH_SECTOR_FIRMWARE_EXTRA_START 17
// 18
// 19

View File

@ -47,6 +47,7 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[9] = 0x080A0000, // - 0x080BFFFF | 128 KiB
[10] = 0x080C0000, // - 0x080DFFFF | 128 KiB
[11] = 0x080E0000, // - 0x080FFFFF | 128 KiB
#if TREZOR_MODEL == T
[12] = 0x08100000, // - 0x08103FFF | 16 KiB
[13] = 0x08104000, // - 0x08107FFF | 16 KiB
[14] = 0x08108000, // - 0x0810BFFF | 16 KiB
@ -60,6 +61,9 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[22] = 0x081C0000, // - 0x081DFFFF | 128 KiB
[23] = 0x081E0000, // - 0x081FFFFF | 128 KiB
[24] = 0x08200000, // last element - not a valid sector
#elif TREZOR_MODEL == 1
[12] = 0x08100000, // last element - not a valid sector
#endif
};
const uint8_t FIRMWARE_SECTORS[FIRMWARE_SECTORS_COUNT] = {

View File

@ -4,11 +4,70 @@ usb.bus.open()
import trezorio as io
from trezorui import Display
import storage
import storage.resident_credentials
from trezor import config
d = Display()
d.clear()
d.backlight(255)
config.init(False)
salt = None
config.unlock(1, salt)
storage.init_unlocked()
storage.cache.start_session()
print("is_initialized: ", storage.is_initialized())
print("version: ", storage.device.is_version_stored())
print("version: ", storage.device.get_version())
print("needs backup: ", storage.device.needs_backup())
storage.device.set_backed_up()
print("needs backup: ", storage.device.needs_backup())
flags = storage.device.get_flags()
print("flags", flags)
storage.device.set_flags(0x200)
print("flags", storage.device.get_flags())
secret = "0"*32
backup_type = 0
storage.device.store_mnemonic_secret(
secret,
backup_type,
needs_backup=True,
no_backup=True,
)
storage.device.set_unfinished_backup(False)
print("unfinished backup: ", storage.device.unfinished_backup())
storage.device.set_unfinished_backup(True)
print("unfinished backup: ", storage.device.unfinished_backup())
key54 = storage.common.get(0x1, 54, public=True)
print("App key 54:", key54)
storage.common.set(0x1, 54, b"asdZ", public=True)
key54 = storage.common.get(0x1, 54, public=True)
print("App key 54 (2):", key54)
key54 = storage.common.delete(0x1, 54, public=True)
key54 = storage.common.get(0x1, 54, public=True)
print("App key 54 (3):", key54)
delay = storage.device.get_autolock_delay_ms()
print("delay", delay)
storage.device.set_autolock_delay_ms(150000)
delay = storage.device.get_autolock_delay_ms()
print("delay", delay)
cache_seed = storage.cache.get(storage.cache.APP_COMMON_SEED)
print("cache seed", cache_seed)
storage.cache.set(storage.cache.APP_COMMON_SEED, 1234)
cache_seed = storage.cache.get(storage.cache.APP_COMMON_SEED)
print("cache seed", cache_seed)
res1 = storage.resident_credentials.get(1)
print("Res credential 1", res1)
res1 = storage.resident_credentials.set(1, b"0"*31 + b"F")
res1 = storage.resident_credentials.get(1)
print("Res credential 1", res1)
i = 0
@ -20,3 +79,4 @@ while True:
print("TOUCH", r)
else:
print("NOTOUCH")
# d.refresh()

View File

@ -0,0 +1 @@
../../src/storage/__init__.py

1
core/src1/storage/cache.py Symbolic link
View File

@ -0,0 +1 @@
../../src/storage/cache.py

1
core/src1/storage/common.py Symbolic link
View File

@ -0,0 +1 @@
../../src/storage/common.py

1
core/src1/storage/device.py Symbolic link
View File

@ -0,0 +1 @@
../../src/storage/device.py

View File

@ -0,0 +1 @@
../../src/storage/resident_credentials.py

View File

@ -0,0 +1 @@
../../src/trezor/__init__.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/__init__.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/base32.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/base58.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/bech32.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/cashaddr.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/curve.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/der.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/hashlib.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/hmac.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/rlp.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/scripts.py

View File

@ -0,0 +1 @@
../../../src/trezor/crypto/slip39.py

1
core/src1/trezor/log.py Symbolic link
View File

@ -0,0 +1 @@
../../src/trezor/log.py

View File

@ -0,0 +1 @@
../../../src/trezor/messages/BackupType.py

1
core/src1/trezor/utils.py Symbolic link
View File

@ -0,0 +1 @@
../../src/trezor/utils.py