From cbd0fdcd5d72e99ec578c593dfe252caed04cddd Mon Sep 17 00:00:00 2001 From: obrusvit Date: Tue, 23 Jan 2024 17:03:03 +0100 Subject: [PATCH] feat(core/sdbackup): fix build and minor changes --- common/protob/messages-debug.proto | 5 +- .../extmod/modtrezorio/modtrezorio-fatfs.h | 25 ++++----- ...itcher.h => modtrezorio-sdcard_inserter.h} | 52 ++++++++--------- core/embed/extmod/modtrezorio/modtrezorio.c | 8 +-- core/embed/trezorhal/sdcard.h | 2 +- core/embed/trezorhal/unix/sdcard.c | 56 +++++++++---------- core/embed/unix/sdcard_emu_mock.c | 14 ++--- core/embed/unix/sdcard_emu_mock.h | 4 +- core/mocks/generated/trezorio/__init__.pyi | 2 +- ...dcard_switcher.pyi => sdcard_inserter.pyi} | 4 +- core/src/all_modules.py | 8 +-- core/src/apps/debug/__init__.py | 6 +- .../apps/management/reset_device/__init__.py | 2 +- .../layouts/{ejectcard.py => sdcard_eject.py} | 2 +- .../tt/{ejectcard.py => sdcard_eject.py} | 11 ++-- core/tests/test_storage.sd_seed_backup.py | 4 +- core/tests/test_trezor.io.fatfs.py | 8 ++- core/tests/test_trezor.io.sdcard.py | 4 +- core/tests/test_trezor.sdcard.py | 4 +- tests/input_flows.py | 4 -- 20 files changed, 110 insertions(+), 115 deletions(-) rename core/embed/extmod/modtrezorio/{modtrezorio-sdcard_switcher.h => modtrezorio-sdcard_inserter.h} (67%) rename core/mocks/generated/trezorio/{sdcard_switcher.pyi => sdcard_inserter.pyi} (72%) rename core/src/trezor/ui/layouts/{ejectcard.py => sdcard_eject.py} (70%) rename core/src/trezor/ui/layouts/tt/{ejectcard.py => sdcard_eject.py} (84%) diff --git a/common/protob/messages-debug.proto b/common/protob/messages-debug.proto index b9fe2488f..3ad26b404 100644 --- a/common/protob/messages-debug.proto +++ b/common/protob/messages-debug.proto @@ -185,8 +185,9 @@ message DebugLinkEraseSdCard { } /** - * Request: Insert SD card into device (emulator). - * If serial_number is not supplied, the message is interpreted as a request for ejecting a card. + * Request: Insert SD card into device (emulator only) + * If serial_number is not supplied, the message is interpreted as a request for ejecting the card. + * @start * @next Success */ message DebugLinkInsertSdCard { diff --git a/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h b/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h index 9a87fb9b3..d9aab9890 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-fatfs.h @@ -21,7 +21,6 @@ #include "py/mperrno.h" #include "py/obj.h" #include "py/objstr.h" -/* #include "stdio.h" */ // clang-format off #include "ff.h" @@ -96,7 +95,11 @@ const PARTITION VolToPart[] = { {0, 1} // Logical Volume 0 => Physical Disk 0, Partition 1 }; -// Helper function to create a partition on a SD card. +// Helper function to create exactly one partition on a SD card. +// param `pt_size` uses the same convention as `f_fdisk`, i.e. when the value is +// * <= 100, it specifies the partition size in percentage of the entire drive. +// * >100, it specifies the number of sectors. +// More info here: http://elm-chan.org/fsw/ff/doc/fdisk.html void make_partition(int pt_size) { uint8_t working_buf[FF_MAX_SS] = {0}; LBA_t plist[] = {pt_size, 0}; @@ -560,13 +563,15 @@ STATIC mp_obj_t mod_trezorio_fatfs_mkfs(size_t n_args, const mp_obj_t *args) { // create partition if (n_args > 0 && args[0] == mp_const_true) { - // for SD card backup: we make a small FAT32 partition and keep the rest - // unallocated, FatFS allows smallest size as 0xFFF5 + 550. Windows needs - // two more clusters not to complain. MAX_FAT16 + 1 + 551 + // for SD card backup: make the smallest FAT32 partition and keep the rest + // unallocated. The size of the partition is set to MAX_FAT16 + overhead, + // i.e. 0xFFF5 + 552. FatFS library can create FAT32 as small as MAX_FAT16 + + // 550. However, in order to make Windows happy with the partition, we need + // to put two more clusters, otherwise Windows offer formatting. const int n_clusters = 0xFFF5 + 552; make_partition(n_clusters); } else { - // for other use (SD salt): make the partition over the whole space. + // for other use (SD salt): make the partition over the whole drive space. make_partition(100); } @@ -590,14 +595,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorio_fatfs_mkfs_obj, 0, 1, /// """ STATIC mp_obj_t mod_trezorio_fatfs_get_capacity() { FATFS_ONLY_MOUNTED; - /* printf("csize: %d\n", fs_instance.csize); */ - /* printf("fatent: %d\n", fs_instance.n_fatent); */ - /* printf("free clusters: %d\n", fs_instance.free_clst); */ - /* printf("volbase: %d\n", fs_instance.volbase); */ - /* printf("fatbase: %d\n", fs_instance.fatbase); */ - /* printf("dirbase: %d\n", fs_instance.dirbase); */ - /* printf("database: %d\n", fs_instance.database); */ - /* printf("winsect: %d\n", fs_instance.winsect); */ // total number of clusters in the filesystem DWORD total_clusters = fs_instance.n_fatent - 2; // size of each cluster in bytes diff --git a/core/embed/extmod/modtrezorio/modtrezorio-sdcard_switcher.h b/core/embed/extmod/modtrezorio/modtrezorio-sdcard_inserter.h similarity index 67% rename from core/embed/extmod/modtrezorio/modtrezorio-sdcard_switcher.h rename to core/embed/extmod/modtrezorio/modtrezorio-sdcard_inserter.h index d4cf005fd..13e1f5918 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-sdcard_switcher.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-sdcard_inserter.h @@ -25,7 +25,7 @@ #include "sdcard.h" #include "sdcard_emu_mock.h" -/// package: trezorio.sdcard_switcher +/// package: trezorio.sdcard_inserter /// def insert( /// card_sn: int, @@ -35,7 +35,7 @@ /// """ /// Inserts SD card to the emulator. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_switcher_insert(size_t n_args, +STATIC mp_obj_t mod_trezorio_sdcard_inserter_insert(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { STATIC const mp_arg_t allowed_args[] = { @@ -72,47 +72,47 @@ STATIC mp_obj_t mod_trezorio_sdcard_switcher_insert(size_t n_args, CHECK_PARAM_RANGE(capacity_bytes, ONE_MEBIBYTE, 1024 * ONE_MEBIBYTE) // capacity between 1 MiB and 1 GiB - sdcard_mock.inserted = sectrue; - set_sdcard_mock_filename((int)card_sn); - sdcard_mock.buffer = NULL; - sdcard_mock.serial_number = card_sn; - sdcard_mock.capacity_bytes = capacity_bytes; - sdcard_mock.blocks = capacity_bytes / SDCARD_BLOCK_SIZE; - sdcard_mock.manuf_ID = manuf_id; + sd_mock.inserted = sectrue; + set_sd_mock_filename((int)card_sn); + sd_mock.buffer = NULL; + sd_mock.serial_number = card_sn; + sd_mock.capacity_bytes = capacity_bytes; + sd_mock.blocks = capacity_bytes / SDCARD_BLOCK_SIZE; + sd_mock.manuf_ID = manuf_id; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_trezorio_sdcard_switcher_insert_obj, 1, - mod_trezorio_sdcard_switcher_insert); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_trezorio_sdcard_inserter_insert_obj, 1, + mod_trezorio_sdcard_inserter_insert); /// def eject() -> None: /// """ /// Ejects SD card from the emulator. /// """ -STATIC mp_obj_t mod_trezorio_sdcard_switcher_eject() { - sdcard_mock.inserted = secfalse; +STATIC mp_obj_t mod_trezorio_sdcard_inserter_eject() { + sd_mock.inserted = secfalse; - if (sdcard_mock.buffer != NULL) { + if (sd_mock.buffer != NULL) { // TODO repetion with unix/sdcard.c code - int r = munmap(sdcard_mock.buffer, sdcard_mock.capacity_bytes); + int r = munmap(sd_mock.buffer, sd_mock.capacity_bytes); ensure(sectrue * (r == 0), "munmap failed"); - sdcard_mock.buffer = NULL; + sd_mock.buffer = NULL; } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_switcher_eject_obj, - mod_trezorio_sdcard_switcher_eject); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_sdcard_inserter_eject_obj, + mod_trezorio_sdcard_inserter_eject); -STATIC const mp_rom_map_elem_t mod_trezorio_sdcard_switcher_globals_table[] = { - {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdcard_switcher)}, +STATIC const mp_rom_map_elem_t mod_trezorio_sdcard_inserter_globals_table[] = { + {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdcard_inserter)}, {MP_ROM_QSTR(MP_QSTR_insert), - MP_ROM_PTR(&mod_trezorio_sdcard_switcher_insert_obj)}, + MP_ROM_PTR(&mod_trezorio_sdcard_inserter_insert_obj)}, {MP_ROM_QSTR(MP_QSTR_eject), - MP_ROM_PTR(&mod_trezorio_sdcard_switcher_eject_obj)}, + MP_ROM_PTR(&mod_trezorio_sdcard_inserter_eject_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(mod_trezorio_sdcard_switcher_globals, - mod_trezorio_sdcard_switcher_globals_table); +STATIC MP_DEFINE_CONST_DICT(mod_trezorio_sdcard_inserter_globals, + mod_trezorio_sdcard_inserter_globals_table); -STATIC const mp_obj_module_t mod_trezorio_sdcard_switcher_module = { +STATIC const mp_obj_module_t mod_trezorio_sdcard_inserter_module = { .base = {&mp_type_module}, - .globals = (mp_obj_dict_t *)&mod_trezorio_sdcard_switcher_globals, + .globals = (mp_obj_dict_t *)&mod_trezorio_sdcard_inserter_globals, }; diff --git a/core/embed/extmod/modtrezorio/modtrezorio.c b/core/embed/extmod/modtrezorio/modtrezorio.c index a0e5c14a9..370ef4f7c 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio.c +++ b/core/embed/extmod/modtrezorio/modtrezorio.c @@ -55,12 +55,12 @@ bool usb_connected_previously = true; #include "modtrezorio-fatfs.h" #include "modtrezorio-sdcard.h" #ifdef TREZOR_EMULATOR -#include "modtrezorio-sdcard_switcher.h" +#include "modtrezorio-sdcard_inserter.h" #endif #endif /// package: trezorio.__init__ -/// from . import fatfs, sdcard, sdcard_switcher +/// from . import fatfs, sdcard, sdcard_inserter /// POLL_READ: int # wait until interface is readable and return read data /// POLL_WRITE: int # wait until interface is writable @@ -91,8 +91,8 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_fatfs), MP_ROM_PTR(&mod_trezorio_fatfs_module)}, {MP_ROM_QSTR(MP_QSTR_sdcard), MP_ROM_PTR(&mod_trezorio_sdcard_module)}, #ifdef TREZOR_EMULATOR - {MP_ROM_QSTR(MP_QSTR_sdcard_switcher), - MP_ROM_PTR(&mod_trezorio_sdcard_switcher_module)}, + {MP_ROM_QSTR(MP_QSTR_sdcard_inserter), + MP_ROM_PTR(&mod_trezorio_sdcard_inserter_module)}, #endif #endif diff --git a/core/embed/trezorhal/sdcard.h b/core/embed/trezorhal/sdcard.h index f64e65430..93129fe1e 100644 --- a/core/embed/trezorhal/sdcard.h +++ b/core/embed/trezorhal/sdcard.h @@ -51,7 +51,7 @@ // this is a fixed size and should not be changed #define SDCARD_BLOCK_SIZE (512) // fixed offset for SD seed backup: -// Maximal size for FAT16 + overhead + start offset +// MAX_FAT16 + overhead + start offset #define SDCARD_BACKUP_BLOCK_START (65525 + 552 + 63) void sdcard_init(void); diff --git a/core/embed/trezorhal/unix/sdcard.c b/core/embed/trezorhal/unix/sdcard.c index 4a3ad0834..841ac96f5 100644 --- a/core/embed/trezorhal/unix/sdcard.c +++ b/core/embed/trezorhal/unix/sdcard.c @@ -30,35 +30,32 @@ #include "sdcard.h" #include "sdcard_emu_mock.h" -#define SDCARD_FILE sdcard_mock.filename -#define SDCARD_BUFFER sdcard_mock.buffer -#define SDCARD_SIZE sdcard_mock.capacity_bytes -#define SDCARD_BLOCKS (SDCARD_SIZE / SDCARD_BLOCK_SIZE) +#define SDCARD_BLOCKS (sd_mock.capacity_bytes / SDCARD_BLOCK_SIZE) static void sdcard_exit(void) { - if (SDCARD_BUFFER == NULL) { + if (sd_mock.buffer == NULL) { return; } - int r = munmap(SDCARD_BUFFER, SDCARD_SIZE); + int r = munmap(sd_mock.buffer, sd_mock.capacity_bytes); ensure(sectrue * (r == 0), "munmap failed"); - SDCARD_BUFFER = NULL; + sd_mock.buffer = NULL; } void sdcard_init(void) { - if (SDCARD_BUFFER != NULL) { + if (sd_mock.buffer != NULL) { return; } // check whether the file exists and it has the correct size struct stat sb; - int r = stat(SDCARD_FILE, &sb); + int r = stat(sd_mock.filename, &sb); int should_clear = 0; // (re)create if non existent or wrong size - if (r != 0 || sb.st_size != SDCARD_SIZE) { - int fd = open(SDCARD_FILE, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); + if (r != 0 || sb.st_size != sd_mock.capacity_bytes) { + int fd = open(sd_mock.filename, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); ensure(sectrue * (fd >= 0), "open failed"); - r = ftruncate(fd, SDCARD_SIZE); + r = ftruncate(fd, sd_mock.capacity_bytes); ensure(sectrue * (r == 0), "truncate failed"); r = close(fd); ensure(sectrue * (r == 0), "close failed"); @@ -67,43 +64,44 @@ void sdcard_init(void) { } // mmap file - int fd = open(SDCARD_FILE, O_RDWR); + int fd = open(sd_mock.filename, O_RDWR); ensure(sectrue * (fd >= 0), "open failed"); - void *map = mmap(0, SDCARD_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + void *map = mmap(0, sd_mock.capacity_bytes, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); ensure(sectrue * (map != MAP_FAILED), "mmap failed"); - SDCARD_BUFFER = (uint8_t *)map; + sd_mock.buffer = (uint8_t *)map; if (should_clear) { - for (int i = 0; i < SDCARD_SIZE; ++i) SDCARD_BUFFER[i] = 0xFF; + for (int i = 0; i < sd_mock.capacity_bytes; ++i) sd_mock.buffer[i] = 0xFF; } - sdcard_mock.powered = secfalse; + sd_mock.powered = secfalse; atexit(sdcard_exit); } -secbool sdcard_is_present(void) { return sdcard_mock.inserted; } +secbool sdcard_is_present(void) { return sd_mock.inserted; } secbool sdcard_power_on(void) { - if (sdcard_mock.inserted == secfalse) { + if (sd_mock.inserted == secfalse) { return secfalse; } sdcard_init(); - sdcard_mock.powered = sectrue; + sd_mock.powered = sectrue; return sectrue; } -void sdcard_power_off(void) { sdcard_mock.powered = secfalse; } +void sdcard_power_off(void) { sd_mock.powered = secfalse; } uint64_t sdcard_get_capacity_in_bytes(void) { - return sdcard_mock.powered == sectrue ? SDCARD_SIZE : 0; + return sd_mock.powered == sectrue ? sd_mock.capacity_bytes : 0; } secbool sdcard_read_blocks(uint32_t *dest, uint32_t block_num, uint32_t num_blocks) { - if (sectrue != sdcard_mock.powered) { + if (sectrue != sd_mock.powered) { return secfalse; } if (block_num >= SDCARD_BLOCKS) { @@ -112,14 +110,14 @@ secbool sdcard_read_blocks(uint32_t *dest, uint32_t block_num, if (num_blocks > SDCARD_BLOCKS - block_num) { return secfalse; } - memcpy(dest, SDCARD_BUFFER + block_num * SDCARD_BLOCK_SIZE, + memcpy(dest, sd_mock.buffer + block_num * SDCARD_BLOCK_SIZE, num_blocks * SDCARD_BLOCK_SIZE); return sectrue; } secbool sdcard_write_blocks(const uint32_t *src, uint32_t block_num, uint32_t num_blocks) { - if (sectrue != sdcard_mock.powered) { + if (sectrue != sd_mock.powered) { return secfalse; } if (block_num >= SDCARD_BLOCKS) { @@ -128,14 +126,12 @@ secbool sdcard_write_blocks(const uint32_t *src, uint32_t block_num, if (num_blocks > SDCARD_BLOCKS - block_num) { return secfalse; } - memcpy(SDCARD_BUFFER + block_num * SDCARD_BLOCK_SIZE, src, + memcpy(sd_mock.buffer + block_num * SDCARD_BLOCK_SIZE, src, num_blocks * SDCARD_BLOCK_SIZE); return sectrue; } -uint64_t __wur sdcard_get_manuf_id(void) { - return (uint64_t)sdcard_mock.manuf_ID; -} +uint64_t __wur sdcard_get_manuf_id(void) { return (uint64_t)sd_mock.manuf_ID; } uint64_t __wur sdcard_get_serial_num(void) { - return (uint64_t)sdcard_mock.serial_number; + return (uint64_t)sd_mock.serial_number; } diff --git a/core/embed/unix/sdcard_emu_mock.c b/core/embed/unix/sdcard_emu_mock.c index 36d982aac..60ae1de33 100644 --- a/core/embed/unix/sdcard_emu_mock.c +++ b/core/embed/unix/sdcard_emu_mock.c @@ -6,7 +6,7 @@ // By default, Emulator starts without mocked SD card, i.e. initially // sdcard.is_present() == False -SDCardMock sdcard_mock = { +SDCardMock sd_mock = { .inserted = secfalse, .powered = secfalse, .filename = NULL, @@ -17,8 +17,8 @@ SDCardMock sdcard_mock = { .manuf_ID = 0, }; -void set_sdcard_mock_filename(int serial_number) { - if (sdcard_mock.serial_number == serial_number) { +void set_sd_mock_filename(int serial_number) { + if (sd_mock.serial_number == serial_number) { // serial_number determines the filename, so assuming the PROFILE_DIR // doesn't change during a lifetime of the emulator, we can skip the rename return; @@ -46,10 +46,10 @@ void set_sdcard_mock_filename(int serial_number) { serial_number); // free the old filename - if (sdcard_mock.filename != NULL) { - free(sdcard_mock.filename); - sdcard_mock.filename = NULL; + if (sd_mock.filename != NULL) { + free(sd_mock.filename); + sd_mock.filename = NULL; } - sdcard_mock.filename = new_filename; + sd_mock.filename = new_filename; } diff --git a/core/embed/unix/sdcard_emu_mock.h b/core/embed/unix/sdcard_emu_mock.h index a003ec162..75243b23c 100644 --- a/core/embed/unix/sdcard_emu_mock.h +++ b/core/embed/unix/sdcard_emu_mock.h @@ -19,8 +19,8 @@ typedef struct { uint8_t manuf_ID; } SDCardMock; -extern SDCardMock sdcard_mock; +extern SDCardMock sd_mock; -void set_sdcard_mock_filename(int serial_number); +void set_sd_mock_filename(int serial_number); #endif // __TREZOR_SDCARD_EMULATOR_MOCK_H__ diff --git a/core/mocks/generated/trezorio/__init__.pyi b/core/mocks/generated/trezorio/__init__.pyi index d5e6a8882..98fad0ef6 100644 --- a/core/mocks/generated/trezorio/__init__.pyi +++ b/core/mocks/generated/trezorio/__init__.pyi @@ -190,7 +190,7 @@ class WebUSB: """ Sends message using USB WebUSB (device) or UDP (emulator). """ -from . import fatfs, sdcard, sdcard_switcher +from . import fatfs, sdcard, sdcard_inserter POLL_READ: int # wait until interface is readable and return read data POLL_WRITE: int # wait until interface is writable TOUCH: int # interface id of the touch events diff --git a/core/mocks/generated/trezorio/sdcard_switcher.pyi b/core/mocks/generated/trezorio/sdcard_inserter.pyi similarity index 72% rename from core/mocks/generated/trezorio/sdcard_switcher.pyi rename to core/mocks/generated/trezorio/sdcard_inserter.pyi index b4256892e..d171d8c06 100644 --- a/core/mocks/generated/trezorio/sdcard_switcher.pyi +++ b/core/mocks/generated/trezorio/sdcard_inserter.pyi @@ -1,7 +1,7 @@ from typing import * -# extmod/modtrezorio/modtrezorio-sdcard_switcher.h +# extmod/modtrezorio/modtrezorio-sdcard_inserter.h def insert( card_sn: int, capacity_bytes: int | None = 122_945_536, @@ -12,7 +12,7 @@ def insert( """ -# extmod/modtrezorio/modtrezorio-sdcard_switcher.h +# extmod/modtrezorio/modtrezorio-sdcard_inserter.h def eject() -> None: """ Ejects SD card from the emulator. diff --git a/core/src/all_modules.py b/core/src/all_modules.py index 3ee662e45..8dfeb9688 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -155,8 +155,6 @@ trezor.ui.layouts import trezor.ui.layouts trezor.ui.layouts.common import trezor.ui.layouts.common -trezor.ui.layouts.ejectcard -import trezor.ui.layouts.ejectcard trezor.ui.layouts.fido import trezor.ui.layouts.fido trezor.ui.layouts.homescreen @@ -167,6 +165,8 @@ trezor.ui.layouts.recovery import trezor.ui.layouts.recovery trezor.ui.layouts.reset import trezor.ui.layouts.reset +trezor.ui.layouts.sdcard_eject +import trezor.ui.layouts.sdcard_eject trezor.ui.layouts.tr import trezor.ui.layouts.tr trezor.ui.layouts.tr.fido @@ -181,8 +181,6 @@ trezor.ui.layouts.tr.reset import trezor.ui.layouts.tr.reset trezor.ui.layouts.tt import trezor.ui.layouts.tt -trezor.ui.layouts.tt.ejectcard -import trezor.ui.layouts.tt.ejectcard trezor.ui.layouts.tt.fido import trezor.ui.layouts.tt.fido trezor.ui.layouts.tt.homescreen @@ -193,6 +191,8 @@ trezor.ui.layouts.tt.recovery import trezor.ui.layouts.tt.recovery trezor.ui.layouts.tt.reset import trezor.ui.layouts.tt.reset +trezor.ui.layouts.tt.sdcard_eject +import trezor.ui.layouts.tt.sdcard_eject trezor.ui.style import trezor.ui.style trezor.utils diff --git a/core/src/apps/debug/__init__.py b/core/src/apps/debug/__init__.py index 5da8058db..da79c13b2 100644 --- a/core/src/apps/debug/__init__.py +++ b/core/src/apps/debug/__init__.py @@ -258,12 +258,12 @@ if __debug__: async def dispatch_DebugLinkInsertSdCard(msg: DebugLinkInsertSdCard) -> Success: from trezor import io - sdcard_switcher = io.sdcard_switcher # local_cache_attribute + sdcard_inserter = io.sdcard_inserter # local_cache_attribute sdcard = io.sdcard # local_cache_attribute if msg.serial_number is None: - sdcard_switcher.eject() + sdcard_inserter.eject() else: - sdcard_switcher.insert( + sdcard_inserter.insert( msg.serial_number, capacity_bytes=msg.capacity_bytes, manuf_id=msg.manuf_ID, diff --git a/core/src/apps/management/reset_device/__init__.py b/core/src/apps/management/reset_device/__init__.py index 626ba79cc..1a24f91f7 100644 --- a/core/src/apps/management/reset_device/__init__.py +++ b/core/src/apps/management/reset_device/__init__.py @@ -156,7 +156,7 @@ async def _backup_mnemonic_or_share( async def sdcard_backup_seed(mnemonic_secret: bytes, backup_type: BackupType) -> None: from storage.sd_seed_backup import is_backup_present, store_seed_on_sdcard from trezor.ui.layouts import confirm_action, show_success - from trezor.ui.layouts.ejectcard import make_user_eject_sdcard + from trezor.ui.layouts.sdcard_eject import make_user_eject_sdcard from apps.common.sdcard import ensure_sdcard, is_trz_card diff --git a/core/src/trezor/ui/layouts/ejectcard.py b/core/src/trezor/ui/layouts/sdcard_eject.py similarity index 70% rename from core/src/trezor/ui/layouts/ejectcard.py rename to core/src/trezor/ui/layouts/sdcard_eject.py index 193a3550c..fb97c1460 100644 --- a/core/src/trezor/ui/layouts/ejectcard.py +++ b/core/src/trezor/ui/layouts/sdcard_eject.py @@ -1,6 +1,6 @@ from trezor import utils if utils.UI_LAYOUT == "TT": - from .tt.ejectcard import * # noqa: F401,F403 + from .tt.sdcard_eject import * # noqa: F401,F403 elif utils.UI_LAYOUT == "TR": raise ValueError("Unsupported layout") diff --git a/core/src/trezor/ui/layouts/tt/ejectcard.py b/core/src/trezor/ui/layouts/tt/sdcard_eject.py similarity index 84% rename from core/src/trezor/ui/layouts/tt/ejectcard.py rename to core/src/trezor/ui/layouts/tt/sdcard_eject.py index e79978e54..7ace0aa7b 100644 --- a/core/src/trezor/ui/layouts/tt/ejectcard.py +++ b/core/src/trezor/ui/layouts/tt/sdcard_eject.py @@ -1,11 +1,10 @@ -from typing import TYPE_CHECKING -from trezor import loop, ui -from trezor.ui.layouts import interact +from typing import Any + import trezorui2 -from . import RustLayout +from trezor import loop, ui -if TYPE_CHECKING: - from typing import Any, Tuple +from ..common import interact +from . import RustLayout class EjectSDCardScreen(RustLayout): diff --git a/core/tests/test_storage.sd_seed_backup.py b/core/tests/test_storage.sd_seed_backup.py index 54b64067f..e1ec3b69a 100644 --- a/core/tests/test_storage.sd_seed_backup.py +++ b/core/tests/test_storage.sd_seed_backup.py @@ -9,13 +9,13 @@ class TestStorageSdSeedBackup(unittest.TestCase): # TODO add more tests, also for repairing the backup card def setUp(self): - io.sdcard_switcher.insert(1) + io.sdcard_inserter.insert(1) self.mnemonic = ( b"crane mesh that gain predict open dice defy lottery toddler coin upgrade" ) def tearDown(self): - io.sdcard_switcher.eject() + io.sdcard_inserter.eject() def test_backup_and_restore(self): io.sdcard.power_on() diff --git a/core/tests/test_trezor.io.fatfs.py b/core/tests/test_trezor.io.fatfs.py index 63b82db96..d8ae9b2fc 100644 --- a/core/tests/test_trezor.io.fatfs.py +++ b/core/tests/test_trezor.io.fatfs.py @@ -1,10 +1,11 @@ from common import * -from trezorio import sdcard, fatfs +from trezorio import sdcard, fatfs, sdcard_inserter class TestTrezorIoFatfs(unittest.TestCase): def setUp(self): + sdcard_inserter.insert(1) sdcard.power_on() fatfs.mkfs() fatfs.mount() @@ -12,6 +13,7 @@ class TestTrezorIoFatfs(unittest.TestCase): def tearDown(self): fatfs.unmount() sdcard.power_off() + sdcard_inserter.eject() def _filename(self, suffix=""): return f"FILE{suffix}.TXT" @@ -140,10 +142,12 @@ class TestTrezorIoFatfsMounting(unittest.TestCase): ] def setUp(self): + sdcard_inserter.insert(1) sdcard.power_on() def tearDown(self): sdcard.power_off() + sdcard_inserter.eject() def test_mount_unmount(self): fatfs.mkfs() @@ -210,6 +214,7 @@ class TestTrezorIoFatfsMounting(unittest.TestCase): class TestTrezorIoFatfsAndSdcard(unittest.TestCase): def test_sd_power(self): + sdcard_inserter.insert(1) sdcard.power_off() self.assertFalse(fatfs.is_mounted()) self.assertRaises(fatfs.FatFSError, fatfs.mount) @@ -222,6 +227,7 @@ class TestTrezorIoFatfsAndSdcard(unittest.TestCase): sdcard.power_off() self.assertFalse(fatfs.is_mounted()) + sdcard_inserter.eject() if __name__ == "__main__": diff --git a/core/tests/test_trezor.io.sdcard.py b/core/tests/test_trezor.io.sdcard.py index 0cfd106e3..8726040ac 100644 --- a/core/tests/test_trezor.io.sdcard.py +++ b/core/tests/test_trezor.io.sdcard.py @@ -5,10 +5,10 @@ from trezor import io class TestTrezorIoSdcard(unittest.TestCase): def setUp(self): - io.sdcard_switcher.insert(1) + io.sdcard_inserter.insert(1) def tearDown(self): - io.sdcard_switcher.eject() + io.sdcard_inserter.eject() def test_start(self): self.assertTrue(io.sdcard.is_present()) diff --git a/core/tests/test_trezor.sdcard.py b/core/tests/test_trezor.sdcard.py index b115d9c9b..88d34bac5 100644 --- a/core/tests/test_trezor.sdcard.py +++ b/core/tests/test_trezor.sdcard.py @@ -7,10 +7,10 @@ fatfs = io.fatfs class TestTrezorSdcard(unittest.TestCase): def setUp(self): - io.sdcard_switcher.insert(1) + io.sdcard_inserter.insert(1) def tearDown(self): - io.sdcard_switcher.eject() + io.sdcard_inserter.eject() def test_power(self): # sdcard.capacity() will return 0 if the card is not powered, diff --git a/tests/input_flows.py b/tests/input_flows.py index 9170307f3..b21cf875f 100644 --- a/tests/input_flows.py +++ b/tests/input_flows.py @@ -1600,10 +1600,6 @@ class InputFlowSlip39BasicRecoverySdCard(InputFlowBase): if self.pin is not None: yield from self.PIN.setup_new_pin(self.pin) - # "Words" counterpart: - # yield from self.REC.setup_slip39_recovery(self.word_count) - # yield from self.REC.input_all_slip39_shares(self.shares) - # choose SD card for n in self.sdcard_numbers: self.debug.eject_sd_card()