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

embed: make model and emulator orthogonal, update macros to match this logic

This commit is contained in:
Pavol Rusnak 2018-08-31 15:52:26 +02:00
parent 5b5b593eb3
commit e3607156d8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
12 changed files with 28 additions and 39 deletions

View File

@ -109,7 +109,7 @@ env.Replace(
'vendor/micropython/lib/cmsis/inc',
] + CPPPATH_MOD,
CPPDEFINES=[
'TREZOR_MODEL_T',
('TREZOR_MODEL', 'T'),
'STM32F427xx',
'USE_HAL_DRIVER',
('STM32_HAL_H', '"<stm32f4xx.h>"'),

View File

@ -131,7 +131,7 @@ env.Replace(
'vendor/micropython/lib/cmsis/inc',
] + CPPPATH_MOD,
CPPDEFINES=[
'TREZOR_MODEL_T',
('TREZOR_MODEL', 'T'),
'STM32F427xx',
'USE_HAL_DRIVER',
('STM32_HAL_H', '"<stm32f4xx.h>"'),

View File

@ -324,7 +324,7 @@ env.Replace(
'vendor/micropython/ports/stm32',
] + CPPPATH_MOD,
CPPDEFINES=[
'TREZOR_MODEL_T',
('TREZOR_MODEL', 'T'),
'STM32F427xx',
'USE_HAL_DRIVER',
('STM32_HAL_H', '"<stm32f4xx.h>"'),

View File

@ -98,7 +98,7 @@ env.Replace(
'vendor/micropython/ports/stm32',
] + CPPPATH_MOD,
CPPDEFINES=[
'TREZOR_MODEL_T',
('TREZOR_MODEL', 'T'),
'STM32F427xx',
('STM32_HAL_H', '"<stm32f4xx_hal.h>"'),
] + CPPDEFINES_MOD,

View File

@ -98,7 +98,7 @@ env.Replace(
'vendor/micropython/ports/stm32',
] + CPPPATH_MOD,
CPPDEFINES=[
'TREZOR_MODEL_T',
('TREZOR_MODEL', 'T'),
'STM32F427xx',
('STM32_HAL_H', '"<stm32f4xx_hal.h>"'),
] + CPPDEFINES_MOD,

View File

@ -265,8 +265,8 @@ env.Replace(
'vendor/micropython/lib/mp-readline',
] + CPPPATH_MOD,
CPPDEFINES=[
'UNIX',
'TREZOR_MODEL_EMU',
'TREZOR_EMULATOR',
('TREZOR_MODEL', 'T'),
'MICROPY_USE_READLINE',
('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'),
] + CPPDEFINES_MOD,

View File

@ -35,7 +35,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_MODEL_EMU
#ifdef TREZOR_EMULATOR
sdcard_init();
#endif
return MP_OBJ_FROM_PTR(o);

View File

@ -47,12 +47,10 @@ static struct {
int x, y;
} DISPLAY_OFFSET;
#if defined TREZOR_MODEL_T
#include "display-stm32.h"
#elif defined TREZOR_MODEL_EMU
#ifdef TREZOR_EMULATOR
#include "display-unix.h"
#else
#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported.
#include "display-stm32.h"
#endif
// common display functions
@ -392,7 +390,7 @@ void display_print(const char *text, int textlen)
display_refresh();
}
#ifdef TREZOR_MODEL_EMU
#ifdef TREZOR_EMULATOR
#define mini_vsnprintf vsnprintf
#include <stdio.h>
#else

View File

@ -107,7 +107,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_MODEL_T
#ifndef TREZOR_EMULATOR
__asm__ volatile("msr control, %0" :: "r" (0x1));
__asm__ volatile("isb");
#endif
@ -120,11 +120,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_set_mode_unprivileged_obj, mod_
/// Retrieve internal symbol.
/// '''
STATIC mp_obj_t mod_trezorutils_symbol(mp_obj_t name) {
#define XSTR(s) STR(s)
#define STR(s) #s
mp_buffer_info_t str;
mp_get_buffer_raise(name, &str, MP_BUFFER_READ);
if (0 == strncmp(str.buf, "GITREV", str.len)) {
#define XSTR(s) STR(s)
#define STR(s) #s
return mp_obj_new_str(XSTR(GITREV), strlen(XSTR(GITREV)));
}
if (0 == strncmp(str.buf, "VERSION_MAJOR", str.len)) {
@ -136,25 +136,20 @@ STATIC mp_obj_t mod_trezorutils_symbol(mp_obj_t name) {
if (0 == strncmp(str.buf, "VERSION_PATCH", str.len)) {
return mp_obj_new_int(VERSION_PATCH);
}
if (0 == strncmp(str.buf, "MODEL", str.len)) {
return mp_obj_new_str(XSTR(TREZOR_MODEL), strlen(XSTR(TREZOR_MODEL)));
}
if (0 == strncmp(str.buf, "EMULATOR", str.len)) {
#ifdef TREZOR_EMULATOR
return mp_const_true;
#else
return mp_const_false;
#endif
}
return mp_const_none;
}
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)) : 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) },
@ -162,7 +157,6 @@ 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);

View File

@ -15,9 +15,7 @@ def get_features():
f.minor_version = utils.symbol("VERSION_MINOR")
f.patch_version = utils.symbol("VERSION_PATCH")
f.revision = utils.symbol("GITREV")
f.model = utils.model()
if f.model == "EMU":
f.model = "T" # emulator currently emulates model T
f.model = utils.symbol("MODEL")
f.device_id = storage.get_device_id()
f.label = storage.get_label()
f.initialized = storage.is_initialized()

View File

@ -3,8 +3,7 @@ import utime
from micropython import const
from trezorui import Display
from trezor import io, loop, res, workflow
from trezor.utils import model
from trezor import io, loop, res, workflow, utils
display = Display()
@ -18,7 +17,7 @@ if __debug__:
loop.after_step_hook = debug_display_refresh
# in both debug and production, emulator needs to draw the screen explicitly
elif model() == "EMU":
elif utils.symbol("EMULATOR"):
loop.after_step_hook = display.refresh
# re-export constants from modtrezorui

View File

@ -1,6 +1,6 @@
import gc
import sys
from trezorutils import halt, memcpy, model, set_mode_unprivileged, symbol # noqa: F401
from trezorutils import halt, memcpy, set_mode_unprivileged, symbol # noqa: F401
def unimport_begin():