mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 15:28:10 +00:00
refactor(core): improve conditional compilations based on model
[no changelog]
This commit is contained in:
parent
eb72fb4241
commit
83500487b8
@ -18,7 +18,7 @@ if TREZOR_MODEL in ('1', ):
|
|||||||
)
|
)
|
||||||
Return()
|
Return()
|
||||||
|
|
||||||
FEATURES_WANTED = ["sdcard"]
|
FEATURES_WANTED = ["sd_card"]
|
||||||
|
|
||||||
CCFLAGS_MOD = ''
|
CCFLAGS_MOD = ''
|
||||||
CPPPATH_MOD = []
|
CPPPATH_MOD = []
|
||||||
|
@ -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}',
|
||||||
|
@ -19,7 +19,7 @@ FEATURE_FLAGS = {
|
|||||||
"SYSTEM_VIEW": False,
|
"SYSTEM_VIEW": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
FEATURES_WANTED = ["input", "sbu", "sdcard", "rgb_led"]
|
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led"]
|
||||||
|
|
||||||
CCFLAGS_MOD = ''
|
CCFLAGS_MOD = ''
|
||||||
CPPPATH_MOD = []
|
CPPPATH_MOD = []
|
||||||
@ -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 += [
|
||||||
@ -619,7 +614,7 @@ if FROZEN:
|
|||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py',
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py',
|
||||||
exclude=[
|
exclude=[
|
||||||
SOURCE_PY_DIR + 'apps/management/sd_protect.py',
|
SOURCE_PY_DIR + 'apps/management/sd_protect.py',
|
||||||
] if TREZOR_MODEL not in ('T',) else [])
|
] if 'sd_card' not in FEATURES_AVAILABLE else [])
|
||||||
)
|
)
|
||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py'))
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py'))
|
||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
|
||||||
@ -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',
|
||||||
|
@ -6,7 +6,7 @@ import tools
|
|||||||
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
||||||
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
||||||
|
|
||||||
FEATURES_WANTED = ["input", "sbu", "sdcard", "rdb_led"]
|
FEATURES_WANTED = ["input", "sbu", "sd_card", "rdb_led"]
|
||||||
|
|
||||||
CCFLAGS_MOD = ''
|
CCFLAGS_MOD = ''
|
||||||
CPPPATH_MOD = []
|
CPPPATH_MOD = []
|
||||||
|
@ -6,7 +6,7 @@ import tools
|
|||||||
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
||||||
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
|
||||||
|
|
||||||
FEATURES_WANTED = ["input", "sdcard"]
|
FEATURES_WANTED = ["input", "sd_card"]
|
||||||
|
|
||||||
CCFLAGS_MOD = ''
|
CCFLAGS_MOD = ''
|
||||||
CPPPATH_MOD = []
|
CPPPATH_MOD = []
|
||||||
|
@ -686,6 +686,12 @@ def cargo_build():
|
|||||||
if DMA2D:
|
if DMA2D:
|
||||||
features.append('dma2d')
|
features.append('dma2d')
|
||||||
|
|
||||||
|
if TREZOR_MODEL in ('T',):
|
||||||
|
features.append('touch')
|
||||||
|
features.append('sd_card')
|
||||||
|
if TREZOR_MODEL in ('R', '1'):
|
||||||
|
features.append('button')
|
||||||
|
|
||||||
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 = []
|
||||||
@ -17,12 +17,15 @@ dma2d = []
|
|||||||
ui_debug = []
|
ui_debug = []
|
||||||
ui_bounds = []
|
ui_bounds = []
|
||||||
bootloader = []
|
bootloader = []
|
||||||
buttons = []
|
button = []
|
||||||
touch = []
|
touch = []
|
||||||
clippy = []
|
clippy = []
|
||||||
jpeg = []
|
jpeg = []
|
||||||
debug = ["ui_debug"]
|
debug = ["ui_debug"]
|
||||||
test = ["cc", "glob", "micropython", "protobuf", "ui", "ui_debug", "dma2d"]
|
sbu = []
|
||||||
|
sd_card = []
|
||||||
|
rgb_led = []
|
||||||
|
test = ["cc", "glob", "micropython", "protobuf", "ui", "ui_debug", "dma2d", "touch"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::ffi;
|
use super::ffi;
|
||||||
|
|
||||||
#[cfg(feature = "buttons")]
|
#[cfg(feature = "button")]
|
||||||
pub use super::ffi::{BTN_EVT_DOWN, BTN_EVT_UP, BTN_LEFT, BTN_RIGHT};
|
pub use super::ffi::{BTN_EVT_DOWN, BTN_EVT_UP, BTN_LEFT, BTN_RIGHT};
|
||||||
|
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
@ -8,7 +8,7 @@ pub fn io_touch_read() -> u32 {
|
|||||||
unsafe { ffi::touch_read() }
|
unsafe { ffi::touch_read() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "buttons")]
|
#[cfg(feature = "button")]
|
||||||
pub fn io_button_read() -> u32 {
|
pub fn io_button_read() -> u32 {
|
||||||
unsafe { ffi::button_read() }
|
unsafe { ffi::button_read() }
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "buttons")]
|
#[cfg(feature = "button")]
|
||||||
use crate::ui::event::ButtonEvent;
|
use crate::ui::event::ButtonEvent;
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
use crate::ui::event::TouchEvent;
|
use crate::ui::event::TouchEvent;
|
||||||
@ -347,7 +347,7 @@ where
|
|||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum Event<'a> {
|
pub enum Event<'a> {
|
||||||
#[cfg(feature = "buttons")]
|
#[cfg(feature = "button")]
|
||||||
Button(ButtonEvent),
|
Button(ButtonEvent),
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
Touch(TouchEvent),
|
Touch(TouchEvent),
|
||||||
|
@ -23,7 +23,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "buttons")]
|
#[cfg(feature = "button")]
|
||||||
use crate::ui::event::ButtonEvent;
|
use crate::ui::event::ButtonEvent;
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
use crate::ui::event::TouchEvent;
|
use crate::ui::event::TouchEvent;
|
||||||
@ -400,7 +400,7 @@ extern "C" fn ui_layout_touch_event(_n_args: usize, _args: *const Obj) -> Obj {
|
|||||||
Obj::const_none()
|
Obj::const_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "buttons")]
|
#[cfg(feature = "button")]
|
||||||
extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj {
|
||||||
let block = |args: &[Obj], _kwargs: &Map| {
|
let block = |args: &[Obj], _kwargs: &Map| {
|
||||||
if args.len() != 3 {
|
if args.len() != 3 {
|
||||||
@ -414,7 +414,7 @@ extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj {
|
|||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "buttons"))]
|
#[cfg(not(feature = "button"))]
|
||||||
extern "C" fn ui_layout_button_event(_n_args: usize, _args: *const Obj) -> Obj {
|
extern "C" fn ui_layout_button_event(_n_args: usize, _args: *const Obj) -> Obj {
|
||||||
Obj::const_none()
|
Obj::const_none()
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -18,9 +18,11 @@ def configure(env, features_wanted, defines, sources):
|
|||||||
sources += ['embed/trezorhal/touch/ft6x36.c', ]
|
sources += ['embed/trezorhal/touch/ft6x36.c', ]
|
||||||
features_available.append("touch")
|
features_available.append("touch")
|
||||||
|
|
||||||
if "sdcard" in features_wanted:
|
if "sd_card" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sdcard.c', ]
|
sources += ['embed/trezorhal/sdcard.c', ]
|
||||||
features_available.append("sdcard")
|
sources += ['embed/extmod/modtrezorio/ff.c', ]
|
||||||
|
sources += ['embed/extmod/modtrezorio/ffunicode.c', ]
|
||||||
|
features_available.append("sd_card")
|
||||||
|
|
||||||
if "sbu" in features_wanted:
|
if "sbu" in features_wanted:
|
||||||
sources += ['embed/trezorhal/sbu.c', ]
|
sources += ['embed/trezorhal/sbu.c', ]
|
||||||
|
@ -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
|
||||||
|
@ -52,7 +52,7 @@ def _find_message_handler_module(msg_type: int) -> str:
|
|||||||
elif msg_type == MessageType.RebootToBootloader:
|
elif msg_type == MessageType.RebootToBootloader:
|
||||||
return "apps.management.reboot_to_bootloader"
|
return "apps.management.reboot_to_bootloader"
|
||||||
|
|
||||||
if utils.MODEL in ("T",) and msg_type == MessageType.SdProtect:
|
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:
|
||||||
return "apps.management.sd_protect"
|
return "apps.management.sd_protect"
|
||||||
|
|
||||||
# bitcoin
|
# bitcoin
|
||||||
|
@ -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