mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-04 21:05:29 +00:00
refactor(core): improve conditional compilations based on model
[no changelog]
This commit is contained in:
parent
112c67cb30
commit
102b31ddea
@ -264,6 +264,7 @@ def cargo_build():
|
|||||||
features.append("bitcoin_only")
|
features.append("bitcoin_only")
|
||||||
features.append("ui")
|
features.append("ui")
|
||||||
features.append("bootloader")
|
features.append("bootloader")
|
||||||
|
features.extend(FEATURES_AVAILABLE)
|
||||||
|
|
||||||
cargo_opts = [
|
cargo_opts = [
|
||||||
f'--target={RUST_TARGET}',
|
f'--target={RUST_TARGET}',
|
||||||
|
@ -166,11 +166,6 @@ if FEATURE_FLAGS["SECP256K1_ZKP"]:
|
|||||||
SOURCE_MOD += [
|
SOURCE_MOD += [
|
||||||
'embed/extmod/modtrezorio/modtrezorio.c',
|
'embed/extmod/modtrezorio/modtrezorio.c',
|
||||||
]
|
]
|
||||||
if TREZOR_MODEL in ('T',):
|
|
||||||
SOURCE_MOD += [
|
|
||||||
'embed/extmod/modtrezorio/ff.c',
|
|
||||||
'embed/extmod/modtrezorio/ffunicode.c',
|
|
||||||
]
|
|
||||||
|
|
||||||
# modtrezorui
|
# modtrezorui
|
||||||
CPPPATH_MOD += [
|
CPPPATH_MOD += [
|
||||||
@ -722,6 +717,8 @@ def cargo_build():
|
|||||||
if DMA2D:
|
if DMA2D:
|
||||||
features.append('dma2d')
|
features.append('dma2d')
|
||||||
|
|
||||||
|
features.extend(FEATURES_AVAILABLE)
|
||||||
|
|
||||||
cargo_opts = [
|
cargo_opts = [
|
||||||
f'--target={RUST_TARGET}',
|
f'--target={RUST_TARGET}',
|
||||||
f'--target-dir=../../build/firmware/rust',
|
f'--target-dir=../../build/firmware/rust',
|
||||||
|
@ -686,6 +686,14 @@ def cargo_build():
|
|||||||
if DMA2D:
|
if DMA2D:
|
||||||
features.append('dma2d')
|
features.append('dma2d')
|
||||||
|
|
||||||
|
if TREZOR_MODEL in ('T',) :
|
||||||
|
features.append('touch')
|
||||||
|
if TREZOR_MODEL in ('R') :
|
||||||
|
features.append('buttons')
|
||||||
|
if TREZOR_MODEL in ('1') :
|
||||||
|
features.append('buttons')
|
||||||
|
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
|
||||||
|
|
||||||
return f'cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}'
|
return f'cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}'
|
||||||
|
@ -82,7 +82,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
}
|
}
|
||||||
#if defined TREZOR_MODEL_T
|
#if defined USE_TOUCH
|
||||||
else if (iface == TOUCH_IFACE) {
|
else if (iface == TOUCH_IFACE) {
|
||||||
const uint32_t evt = touch_read();
|
const uint32_t evt = touch_read();
|
||||||
if (evt) {
|
if (evt) {
|
||||||
@ -126,7 +126,8 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
|
#endif
|
||||||
|
#if USE_BUTTON
|
||||||
else if (iface == BUTTON_IFACE) {
|
else if (iface == BUTTON_IFACE) {
|
||||||
const uint32_t evt = button_read();
|
const uint32_t evt = button_read();
|
||||||
if (evt & (BTN_EVT_DOWN | BTN_EVT_UP)) {
|
if (evt & (BTN_EVT_DOWN | BTN_EVT_UP)) {
|
||||||
@ -143,8 +144,6 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#error Unknown Trezor model
|
|
||||||
#endif
|
#endif
|
||||||
else if (mode == POLL_READ) {
|
else if (mode == POLL_READ) {
|
||||||
if (sectrue == usb_hid_can_read(iface)) {
|
if (sectrue == usb_hid_can_read(iface)) {
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include TREZOR_BOARD
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "touch/touch.h"
|
#include "touch/touch.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
@ -47,9 +48,11 @@ bool usb_connected_previously = true;
|
|||||||
#include "modtrezorio-webusb.h"
|
#include "modtrezorio-webusb.h"
|
||||||
#include "modtrezorio-usb.h"
|
#include "modtrezorio-usb.h"
|
||||||
// clang-format on
|
// clang-format on
|
||||||
#if defined TREZOR_MODEL_T
|
#ifdef USE_SBU
|
||||||
#include "modtrezorio-fatfs.h"
|
|
||||||
#include "modtrezorio-sbu.h"
|
#include "modtrezorio-sbu.h"
|
||||||
|
#endif
|
||||||
|
#ifdef USE_SD_CARD
|
||||||
|
#include "modtrezorio-fatfs.h"
|
||||||
#include "modtrezorio-sdcard.h"
|
#include "modtrezorio-sdcard.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -77,16 +80,22 @@ bool usb_connected_previously = true;
|
|||||||
STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
|
STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
|
||||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio)},
|
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio)},
|
||||||
|
|
||||||
#if defined TREZOR_MODEL_T
|
#ifdef USE_SBU
|
||||||
{MP_ROM_QSTR(MP_QSTR_fatfs), MP_ROM_PTR(&mod_trezorio_fatfs_module)},
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_SBU), MP_ROM_PTR(&mod_trezorio_SBU_type)},
|
{MP_ROM_QSTR(MP_QSTR_SBU), MP_ROM_PTR(&mod_trezorio_SBU_type)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_sdcard), MP_ROM_PTR(&mod_trezorio_sdcard_module)},
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_SD_CARD
|
||||||
|
{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)},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_TOUCH
|
||||||
{MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_INT(TOUCH_IFACE)},
|
{MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_INT(TOUCH_IFACE)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_ROM_INT((TOUCH_START >> 24) & 0xFFU)},
|
{MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_ROM_INT((TOUCH_START >> 24) & 0xFFU)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_TOUCH_MOVE), MP_ROM_INT((TOUCH_MOVE >> 24) & 0xFFU)},
|
{MP_ROM_QSTR(MP_QSTR_TOUCH_MOVE), MP_ROM_INT((TOUCH_MOVE >> 24) & 0xFFU)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_TOUCH_END), MP_ROM_INT((TOUCH_END >> 24) & 0xFFU)},
|
{MP_ROM_QSTR(MP_QSTR_TOUCH_END), MP_ROM_INT((TOUCH_END >> 24) & 0xFFU)},
|
||||||
#elif defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
|
#endif
|
||||||
|
#ifdef USE_BUTTON
|
||||||
{MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_INT(BUTTON_IFACE)},
|
{MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_INT(BUTTON_IFACE)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_BUTTON_PRESSED),
|
{MP_ROM_QSTR(MP_QSTR_BUTTON_PRESSED),
|
||||||
MP_ROM_INT((BTN_EVT_DOWN >> 24) & 0x3U)},
|
MP_ROM_INT((BTN_EVT_DOWN >> 24) & 0x3U)},
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
#include TREZOR_BOARD
|
||||||
|
|
||||||
#ifndef TREZOR_EMULATOR
|
#ifndef TREZOR_EMULATOR
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
@ -222,17 +223,6 @@ STATIC mp_obj_t mod_trezorutils_reboot_to_bootloader() {
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_to_bootloader_obj,
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_reboot_to_bootloader_obj,
|
||||||
mod_trezorutils_reboot_to_bootloader);
|
mod_trezorutils_reboot_to_bootloader);
|
||||||
|
|
||||||
/// def usb_data_connected() -> bool:
|
|
||||||
/// """
|
|
||||||
/// Returns whether USB has been enumerated/configured
|
|
||||||
/// (and is not just connected by cable without data pins)
|
|
||||||
/// """
|
|
||||||
STATIC mp_obj_t mod_trezorutils_usb_data_connected() {
|
|
||||||
return usb_configured() == sectrue ? mp_const_true : mp_const_false;
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_usb_data_connected_obj,
|
|
||||||
mod_trezorutils_usb_data_connected);
|
|
||||||
|
|
||||||
STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
|
STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
|
||||||
{&mp_type_bytes}, 0, sizeof(SCM_REVISION) - 1, (const byte *)SCM_REVISION};
|
{&mp_type_bytes}, 0, sizeof(SCM_REVISION) - 1, (const byte *)SCM_REVISION};
|
||||||
|
|
||||||
@ -240,6 +230,7 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
|
|||||||
/// VERSION_MAJOR: int
|
/// VERSION_MAJOR: int
|
||||||
/// VERSION_MINOR: int
|
/// VERSION_MINOR: int
|
||||||
/// VERSION_PATCH: int
|
/// VERSION_PATCH: int
|
||||||
|
/// USE_SD_CARD: bool
|
||||||
/// MODEL: str
|
/// MODEL: str
|
||||||
/// EMULATOR: bool
|
/// EMULATOR: bool
|
||||||
/// BITCOIN_ONLY: bool
|
/// BITCOIN_ONLY: bool
|
||||||
@ -255,14 +246,17 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
|
|||||||
MP_ROM_PTR(&mod_trezorutils_firmware_vendor_obj)},
|
MP_ROM_PTR(&mod_trezorutils_firmware_vendor_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_reboot_to_bootloader),
|
{MP_ROM_QSTR(MP_QSTR_reboot_to_bootloader),
|
||||||
MP_ROM_PTR(&mod_trezorutils_reboot_to_bootloader_obj)},
|
MP_ROM_PTR(&mod_trezorutils_reboot_to_bootloader_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_usb_data_connected),
|
|
||||||
MP_ROM_PTR(&mod_trezorutils_usb_data_connected_obj)},
|
|
||||||
// various built-in constants
|
// various built-in constants
|
||||||
{MP_ROM_QSTR(MP_QSTR_SCM_REVISION),
|
{MP_ROM_QSTR(MP_QSTR_SCM_REVISION),
|
||||||
MP_ROM_PTR(&mod_trezorutils_revision_obj)},
|
MP_ROM_PTR(&mod_trezorutils_revision_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_VERSION_MAJOR), MP_ROM_INT(VERSION_MAJOR)},
|
{MP_ROM_QSTR(MP_QSTR_VERSION_MAJOR), MP_ROM_INT(VERSION_MAJOR)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_VERSION_MINOR), MP_ROM_INT(VERSION_MINOR)},
|
{MP_ROM_QSTR(MP_QSTR_VERSION_MINOR), MP_ROM_INT(VERSION_MINOR)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_VERSION_PATCH), MP_ROM_INT(VERSION_PATCH)},
|
{MP_ROM_QSTR(MP_QSTR_VERSION_PATCH), MP_ROM_INT(VERSION_PATCH)},
|
||||||
|
#ifdef USE_SD_CARD
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_true},
|
||||||
|
#else
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_false},
|
||||||
|
#endif
|
||||||
#if defined TREZOR_MODEL_1
|
#if defined TREZOR_MODEL_1
|
||||||
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MP_QSTR_1)},
|
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MP_QSTR_1)},
|
||||||
#elif defined TREZOR_MODEL_T
|
#elif defined TREZOR_MODEL_T
|
||||||
|
@ -8,8 +8,8 @@ build = "build.rs"
|
|||||||
[features]
|
[features]
|
||||||
default = ["model_tt"]
|
default = ["model_tt"]
|
||||||
bitcoin_only = []
|
bitcoin_only = []
|
||||||
model_tt = ["touch", "jpeg"]
|
model_tt = ["jpeg"]
|
||||||
model_tr = ["buttons"]
|
model_tr = []
|
||||||
micropython = []
|
micropython = []
|
||||||
protobuf = ["micropython"]
|
protobuf = ["micropython"]
|
||||||
ui = []
|
ui = []
|
||||||
@ -22,7 +22,10 @@ touch = []
|
|||||||
clippy = []
|
clippy = []
|
||||||
jpeg = []
|
jpeg = []
|
||||||
debug = ["ui_debug"]
|
debug = ["ui_debug"]
|
||||||
test = ["cc", "glob", "micropython", "protobuf", "ui", "ui_debug", "dma2d"]
|
sbu = []
|
||||||
|
sdcard = []
|
||||||
|
rgb_led = []
|
||||||
|
test = ["cc", "glob", "micropython", "protobuf", "ui", "ui_debug", "dma2d", "touch"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
#ifndef _BOARD_UNIX_H
|
#ifndef _BOARD_UNIX_H
|
||||||
#define _BOARD_UNIX_H
|
#define _BOARD_UNIX_H
|
||||||
|
|
||||||
|
#ifdef TREZOR_MODEL_T
|
||||||
|
#define USE_TOUCH 1
|
||||||
|
#define USE_SD_CARD 1
|
||||||
|
#define USE_SBU 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TREZOR_MODEL_1
|
||||||
|
#define USE_BUTTON 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TREZOR_MODEL_R
|
||||||
|
#define USE_BUTTON 1
|
||||||
|
#define USE_SBU 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "display-unix.h"
|
#include "display-unix.h"
|
||||||
|
|
||||||
#define USE_TOUCH 1
|
#define USE_TOUCH 1
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#if defined TREZOR_MODEL_T
|
#include TREZOR_BOARD
|
||||||
|
#ifdef USE_TOUCH
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
@ -85,7 +86,9 @@ void touch_power_on(void) {}
|
|||||||
|
|
||||||
uint32_t touch_is_detected(void) { return _touch_detected; }
|
uint32_t touch_is_detected(void) { return _touch_detected; }
|
||||||
|
|
||||||
#elif defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_BUTTON
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
|
||||||
@ -121,6 +124,4 @@ uint32_t button_read(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown Trezor model
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -65,18 +65,11 @@ def reboot_to_bootloader() -> None:
|
|||||||
"""
|
"""
|
||||||
Reboots to bootloader.
|
Reboots to bootloader.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# extmod/modtrezorutils/modtrezorutils.c
|
|
||||||
def usb_data_connected() -> bool:
|
|
||||||
"""
|
|
||||||
Returns whether USB has been enumerated/configured
|
|
||||||
(and is not just connected by cable without data pins)
|
|
||||||
"""
|
|
||||||
SCM_REVISION: bytes
|
SCM_REVISION: bytes
|
||||||
VERSION_MAJOR: int
|
VERSION_MAJOR: int
|
||||||
VERSION_MINOR: int
|
VERSION_MINOR: int
|
||||||
VERSION_PATCH: int
|
VERSION_PATCH: int
|
||||||
|
USE_SD_CARD: bool
|
||||||
MODEL: str
|
MODEL: str
|
||||||
EMULATOR: bool
|
EMULATOR: bool
|
||||||
BITCOIN_ONLY: bool
|
BITCOIN_ONLY: bool
|
||||||
|
@ -15,7 +15,7 @@ def configure(env, features_wanted, defines, sources):
|
|||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ['embed/trezorhal/button.c']
|
||||||
features_available.append("button")
|
features_available.append("buttons")
|
||||||
|
|
||||||
env.get('ENV')['TREZOR_BOARD'] = board
|
env.get('ENV')['TREZOR_BOARD'] = board
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ def configure(env, features_wanted, defines, sources):
|
|||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ['embed/trezorhal/button.c']
|
||||||
features_available.append("button")
|
features_available.append("buttons")
|
||||||
|
|
||||||
if "rgb_led" in features_wanted:
|
if "rgb_led" in features_wanted:
|
||||||
sources += ['embed/trezorhal/rgb_led.c']
|
sources += ['embed/trezorhal/rgb_led.c']
|
||||||
|
@ -15,7 +15,7 @@ def configure(env, features_wanted, defines, sources):
|
|||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ['embed/trezorhal/button.c']
|
sources += ['embed/trezorhal/button.c']
|
||||||
features_available.append("button")
|
features_available.append("buttons")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sbu.c', ]
|
sources += ['embed/trezorhal/sbu.c', ]
|
||||||
|
@ -20,6 +20,8 @@ def configure(env, features_wanted, defines, sources):
|
|||||||
|
|
||||||
if "sdcard" in features_wanted:
|
if "sdcard" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sdcard.c', ]
|
sources += ['embed/trezorhal/sdcard.c', ]
|
||||||
|
sources += ['embed/extmod/modtrezorio/ff.c', ]
|
||||||
|
sources += ['embed/extmod/modtrezorio/ffunicode.c', ]
|
||||||
features_available.append("sdcard")
|
features_available.append("sdcard")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
|
@ -2,20 +2,46 @@ import utime
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import storage.cache as storage_cache
|
import storage.cache as storage_cache
|
||||||
from trezor import config, wire
|
from trezor import config, utils, wire
|
||||||
|
|
||||||
from .sdcard import request_sd_salt
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any, NoReturn
|
from typing import Any, NoReturn
|
||||||
from trezor.wire import Context, GenericContext
|
from trezor.wire import Context, GenericContext
|
||||||
|
|
||||||
|
|
||||||
def can_lock_device() -> bool:
|
async def _request_sd_salt(
|
||||||
"""Return True if the device has a PIN set or SD-protect enabled."""
|
ctx: wire.GenericContext, raise_cancelled_on_unavailable: bool = False
|
||||||
import storage.sd_salt
|
) -> bytearray | None:
|
||||||
|
"""Helper to get SD salt in a general manner, working for all models.
|
||||||
|
|
||||||
return config.has_pin() or storage.sd_salt.is_enabled()
|
Is model-specific, because some models (like TR/T2B1) do not even
|
||||||
|
have SD card support (and we do not want to include SD-card connected code).
|
||||||
|
"""
|
||||||
|
from trezor import utils
|
||||||
|
|
||||||
|
if not utils.USE_SD_CARD:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
from .sdcard import request_sd_salt, SdCardUnavailable
|
||||||
|
|
||||||
|
try:
|
||||||
|
return await request_sd_salt(ctx)
|
||||||
|
except SdCardUnavailable:
|
||||||
|
if raise_cancelled_on_unavailable:
|
||||||
|
raise wire.PinCancelled("SD salt is unavailable")
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def can_lock_device() -> bool:
|
||||||
|
"""Return True if the device has a PIN set or SD-protect enabled (when supported)."""
|
||||||
|
# TR/T2B1 does not support SD card
|
||||||
|
if not utils.USE_SD_CARD:
|
||||||
|
return config.has_pin()
|
||||||
|
else:
|
||||||
|
import storage.sd_salt
|
||||||
|
|
||||||
|
return config.has_pin() or storage.sd_salt.is_enabled()
|
||||||
|
|
||||||
|
|
||||||
async def request_pin(
|
async def request_pin(
|
||||||
@ -56,7 +82,7 @@ async def request_pin_and_sd_salt(
|
|||||||
else:
|
else:
|
||||||
pin = ""
|
pin = ""
|
||||||
|
|
||||||
salt = await request_sd_salt(ctx)
|
salt = await _request_sd_salt(ctx)
|
||||||
|
|
||||||
return pin, salt
|
return pin, salt
|
||||||
|
|
||||||
@ -73,8 +99,6 @@ async def verify_user_pin(
|
|||||||
retry: bool = True,
|
retry: bool = True,
|
||||||
cache_time_ms: int = 0,
|
cache_time_ms: int = 0,
|
||||||
) -> None:
|
) -> None:
|
||||||
from .sdcard import SdCardUnavailable
|
|
||||||
|
|
||||||
# _get_last_unlock_time
|
# _get_last_unlock_time
|
||||||
last_unlock = int.from_bytes(
|
last_unlock = int.from_bytes(
|
||||||
storage_cache.get(storage_cache.APP_COMMON_REQUEST_PIN_LAST_UNLOCK, b""), "big"
|
storage_cache.get(storage_cache.APP_COMMON_REQUEST_PIN_LAST_UNLOCK, b""), "big"
|
||||||
@ -98,10 +122,7 @@ async def verify_user_pin(
|
|||||||
else:
|
else:
|
||||||
pin = ""
|
pin = ""
|
||||||
|
|
||||||
try:
|
salt = await _request_sd_salt(ctx, raise_cancelled_on_unavailable=True)
|
||||||
salt = await request_sd_salt(ctx)
|
|
||||||
except SdCardUnavailable:
|
|
||||||
raise wire.PinCancelled("SD salt is unavailable")
|
|
||||||
if config.unlock(pin, salt):
|
if config.unlock(pin, salt):
|
||||||
_set_last_unlock_time()
|
_set_last_unlock_time()
|
||||||
return
|
return
|
||||||
|
@ -2,7 +2,7 @@ from micropython import const
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import storage.device
|
import storage.device
|
||||||
from trezor import io
|
from trezor import io, utils
|
||||||
from trezor.sdcard import with_filesystem
|
from trezor.sdcard import with_filesystem
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -10,8 +10,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
T = TypeVar("T", bound=Callable)
|
T = TypeVar("T", bound=Callable)
|
||||||
|
|
||||||
|
if utils.USE_SD_CARD:
|
||||||
fatfs = io.fatfs # global_import_cache
|
fatfs = io.fatfs # global_import_cache
|
||||||
|
|
||||||
SD_CARD_HOT_SWAPPABLE = False
|
SD_CARD_HOT_SWAPPABLE = False
|
||||||
SD_SALT_LEN_BYTES = const(32)
|
SD_SALT_LEN_BYTES = const(32)
|
||||||
|
@ -5,6 +5,7 @@ from trezorutils import ( # noqa: F401
|
|||||||
EMULATOR,
|
EMULATOR,
|
||||||
MODEL,
|
MODEL,
|
||||||
SCM_REVISION,
|
SCM_REVISION,
|
||||||
|
USE_SD_CARD,
|
||||||
VERSION_MAJOR,
|
VERSION_MAJOR,
|
||||||
VERSION_MINOR,
|
VERSION_MINOR,
|
||||||
VERSION_PATCH,
|
VERSION_PATCH,
|
||||||
@ -14,7 +15,6 @@ from trezorutils import ( # noqa: F401
|
|||||||
halt,
|
halt,
|
||||||
memcpy,
|
memcpy,
|
||||||
reboot_to_bootloader,
|
reboot_to_bootloader,
|
||||||
usb_data_connected,
|
|
||||||
)
|
)
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user