1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

embed/extmod/modtrezorutils: add symbol() func

to expose internal C symbols, usually defined as macros
This commit is contained in:
Pavol Rusnak 2018-02-23 21:27:26 +01:00
parent adaa53174b
commit 35e1135c95
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 35 additions and 7 deletions

View File

@ -7,6 +7,8 @@
#include "py/runtime.h"
#include "version.h"
#if MICROPY_PY_TREZORUTILS
#include <string.h>
@ -107,12 +109,38 @@ STATIC mp_obj_t mod_trezorutils_set_mode_unprivileged(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_set_mode_unprivileged_obj, mod_trezorutils_set_mode_unprivileged);
/// def symbol(name: str) -> str/int/None:
/// '''
/// Retrieve internal symbol.
/// '''
STATIC mp_obj_t mod_trezorutils_symbol(mp_obj_t name) {
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)), false);
}
if (0 == strncmp(str.buf, "VERSION_MAJOR", str.len)) {
return mp_obj_new_int(VERSION_MAJOR);
}
if (0 == strncmp(str.buf, "VERSION_MINOR", str.len)) {
return mp_obj_new_int(VERSION_MINOR);
}
if (0 == strncmp(str.buf, "VERSION_PATCH", str.len)) {
return mp_obj_new_int(VERSION_PATCH);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorutils_symbol_obj, mod_trezorutils_symbol);
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) },
{ MP_ROM_QSTR(MP_QSTR_memcpy), MP_ROM_PTR(&mod_trezorutils_memcpy_obj) },
{ 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) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals, mp_module_trezorutils_globals_table);

1
embed/unix/version.h Symbolic link
View File

@ -0,0 +1 @@
../firmware/version.h

View File

@ -1,6 +1,6 @@
from trezor import config
from trezor.wire import register, protobuf_workflow
from trezor.utils import unimport
from trezor.utils import unimport, symbol
from trezor.messages.wire_types import Initialize, GetFeatures, Ping, ClearSession
@ -15,11 +15,10 @@ async def respond_Features(ctx, msg):
f = Features()
f.vendor = 'trezor.io'
# TODO: f.revision = '0123456789'
# TODO: f.bootloader_hash = '0123456789'
f.major_version = 2
f.minor_version = 0
f.patch_version = 1
f.revision = symbol('GITREV')
f.major_version = symbol('VERSION_MAJOR')
f.minor_version = symbol('VERSION_MINOR')
f.patch_version = symbol('VERSION_PATCH')
f.model = 'T'
f.coins = coins.COINS

View File

@ -1,7 +1,7 @@
import sys
import gc
from trezorutils import halt, memcpy, set_mode_unprivileged
from trezorutils import halt, memcpy, set_mode_unprivileged, symbol
def unimport(genfunc):