mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-25 17:09:44 +00:00
embed: rename TREZOR_STM32/UNIX to TREZOR_MODEL_T/EMU, introduce trezor.utils.model()
This commit is contained in:
parent
c7c5f55508
commit
611d374bbd
@ -121,7 +121,7 @@ env.Replace(
|
||||
'vendor/micropython/lib/cmsis/inc',
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
'TREZOR_STM32',
|
||||
'TREZOR_MODEL_T',
|
||||
'MCU_SERIES_F4',
|
||||
'STM32F427xx',
|
||||
'USE_HAL_DRIVER',
|
||||
|
@ -143,7 +143,7 @@ env.Replace(
|
||||
'vendor/micropython/lib/cmsis/inc',
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
'TREZOR_STM32',
|
||||
'TREZOR_MODEL_T',
|
||||
'MCU_SERIES_F4',
|
||||
'STM32F427xx',
|
||||
'USE_HAL_DRIVER',
|
||||
|
@ -328,7 +328,7 @@ env.Replace(
|
||||
'vendor/micropython/ports/stm32',
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
'TREZOR_STM32',
|
||||
'TREZOR_MODEL_T',
|
||||
'MCU_SERIES_F4',
|
||||
'STM32F427xx',
|
||||
'USE_HAL_DRIVER',
|
||||
|
@ -110,7 +110,7 @@ env.Replace(
|
||||
'vendor/micropython/ports/stm32',
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
'TREZOR_STM32',
|
||||
'TREZOR_MODEL_T',
|
||||
'MCU_SERIES_F4',
|
||||
'STM32F427xx',
|
||||
('STM32_HAL_H', '"<stm32f4xx_hal.h>"'),
|
||||
|
@ -110,7 +110,7 @@ env.Replace(
|
||||
'vendor/micropython/ports/stm32',
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
'TREZOR_STM32',
|
||||
'TREZOR_MODEL_T',
|
||||
'MCU_SERIES_F4',
|
||||
'STM32F427xx',
|
||||
('STM32_HAL_H', '"<stm32f4xx_hal.h>"'),
|
||||
|
@ -261,7 +261,7 @@ env.Replace(
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
'UNIX',
|
||||
'TREZOR_UNIX',
|
||||
'TREZOR_MODEL_EMU',
|
||||
'MICROPY_USE_READLINE',
|
||||
('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'),
|
||||
] + CPPDEFINES_MOD,
|
||||
|
@ -33,7 +33,7 @@ STATIC mp_obj_t mod_trezorio_SDCard_make_new(const mp_obj_type_t *type, size_t n
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
mp_obj_SDCard_t *o = m_new_obj(mp_obj_SDCard_t);
|
||||
o->base.type = type;
|
||||
#if defined TREZOR_UNIX
|
||||
#if defined TREZOR_MODEL_EMU
|
||||
sdcard_init();
|
||||
#endif
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
|
@ -44,9 +44,9 @@ static struct {
|
||||
int x, y;
|
||||
} DISPLAY_OFFSET;
|
||||
|
||||
#if defined TREZOR_STM32
|
||||
#if defined TREZOR_MODEL_T
|
||||
#include "display-stm32.h"
|
||||
#elif defined TREZOR_UNIX
|
||||
#elif defined TREZOR_MODEL_EMU
|
||||
#include "display-unix.h"
|
||||
#else
|
||||
#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported.
|
||||
@ -385,7 +385,7 @@ void display_print(const char *text, int textlen)
|
||||
display_refresh();
|
||||
}
|
||||
|
||||
#ifdef TREZOR_UNIX
|
||||
#ifdef TREZOR_MODEL_EMU
|
||||
#define mini_vsnprintf vsnprintf
|
||||
#include <stdio.h>
|
||||
#else
|
||||
|
@ -113,7 +113,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1, mod_t
|
||||
/// Set unprivileged mode.
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_trezorutils_set_mode_unprivileged(void) {
|
||||
#if defined TREZOR_STM32
|
||||
#if defined TREZOR_MODEL_T
|
||||
__asm__ volatile("msr control, %0" :: "r" (0x1));
|
||||
__asm__ volatile("isb");
|
||||
#endif
|
||||
@ -146,6 +146,21 @@ STATIC mp_obj_t mod_trezorutils_symbol(mp_obj_t name) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_symbol_obj, mod_trezorutils_symbol);
|
||||
|
||||
/// def model() -> str:
|
||||
/// '''
|
||||
/// Return which hardware model we are running on.
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_trezorutils_model(void) {
|
||||
const char *model = NULL;
|
||||
#if defined TREZOR_MODEL_T
|
||||
model = "T";
|
||||
#elif defined TREZOR_MODEL_EMU
|
||||
model = "EMU";
|
||||
#endif
|
||||
return model ? mp_obj_new_str(model, strlen(model), false) : mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_model_obj, mod_trezorutils_model);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorutils) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_consteq), MP_ROM_PTR(&mod_trezorutils_consteq_obj) },
|
||||
@ -153,6 +168,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&mod_trezorutils_halt_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_mode_unprivileged), MP_ROM_PTR(&mod_trezorutils_set_mode_unprivileged_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_symbol), MP_ROM_PTR(&mod_trezorutils_symbol_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_model), MP_ROM_PTR(&mod_trezorutils_model_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals, mp_module_trezorutils_globals_table);
|
||||
|
@ -1,5 +1,5 @@
|
||||
from trezor import config
|
||||
from trezor.utils import unimport, symbol
|
||||
from trezor.utils import unimport, symbol, model
|
||||
from trezor.wire import register, protobuf_workflow
|
||||
from trezor.messages import wire_types
|
||||
from trezor.messages.Features import Features
|
||||
@ -31,7 +31,8 @@ async def respond_Features(ctx, msg):
|
||||
f.passphrase_cached = cache.has_passphrase()
|
||||
f.needs_backup = storage.needs_backup()
|
||||
f.flags = storage.get_flags()
|
||||
f.model = 'T'
|
||||
if model() in ['T', 'EMU']: # emulator currently emulates model T
|
||||
f.model = 'T'
|
||||
|
||||
return f
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
from micropython import const
|
||||
|
||||
import sys
|
||||
import math
|
||||
import utime
|
||||
|
||||
@ -10,11 +9,12 @@ from trezor import io
|
||||
from trezor import loop
|
||||
from trezor import res
|
||||
from trezor import workflow
|
||||
from trezor.utils import model
|
||||
|
||||
display = Display()
|
||||
|
||||
# for desktop platforms, we need to refresh the display after each frame
|
||||
if sys.platform != 'trezor':
|
||||
if model() == 'EMU':
|
||||
loop.after_step_hook = display.refresh
|
||||
|
||||
# import constants from modtrezorui
|
||||
|
@ -1,7 +1,7 @@
|
||||
import sys
|
||||
import gc
|
||||
|
||||
from trezorutils import halt, memcpy, set_mode_unprivileged, symbol # noqa: F401
|
||||
from trezorutils import halt, memcpy, set_mode_unprivileged, symbol, model # noqa: F401
|
||||
|
||||
|
||||
def unimport(genfunc):
|
||||
|
@ -1,5 +1,6 @@
|
||||
from trezor.utils import ensure
|
||||
|
||||
|
||||
class SkipTest(Exception):
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user