diff --git a/.gitmodules b/.gitmodules index 07beebb91..075894e4e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/micropython"] path = vendor/micropython url = https://github.com/trezor/micropython.git +[submodule "vendor/norcow"] + path = vendor/norcow + url = https://github.com/trezor/norcow.git diff --git a/extmod/modtrezorconfig/modtrezorconfig.c b/extmod/modtrezorconfig/modtrezorconfig.c index 17fb0b5df..454a35f33 100644 --- a/extmod/modtrezorconfig/modtrezorconfig.c +++ b/extmod/modtrezorconfig/modtrezorconfig.c @@ -14,15 +14,9 @@ #include "py/binary.h" #include "py/objstr.h" -#if MICROPY_PY_TREZORCONFIG - - -// temporary function stubs from norcow -void norcow_init(void) { } -bool norcow_get(uint16_t key, const void **val, uint32_t *len) { *val = "Works!"; *len = 6; return true; } -bool norcow_set(uint16_t key, const void *val, uint32_t len) { return true; } -// end +#include "norcow.h" +#if MICROPY_PY_TREZORCONFIG typedef struct _mp_obj_Config_t { mp_obj_base_t base; @@ -79,7 +73,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorConfig_Config_set_obj, 4, 4 /// Erases the whole config (use with caution!) /// ''' STATIC mp_obj_t mod_TrezorConfig_Config_wipe(mp_obj_t self) { - // TODO + norcow_wipe(); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorConfig_Config_wipe_obj, mod_TrezorConfig_Config_wipe); diff --git a/extmod/modtrezorconfig/norcow.c b/extmod/modtrezorconfig/norcow.c new file mode 120000 index 000000000..8222de0a6 --- /dev/null +++ b/extmod/modtrezorconfig/norcow.c @@ -0,0 +1 @@ +../../vendor/norcow/norcow.c \ No newline at end of file diff --git a/extmod/modtrezorconfig/norcow.h b/extmod/modtrezorconfig/norcow.h new file mode 120000 index 000000000..a4a69374e --- /dev/null +++ b/extmod/modtrezorconfig/norcow.h @@ -0,0 +1 @@ +../../vendor/norcow/norcow.h \ No newline at end of file diff --git a/extmod/modtrezorconfig/norcow_config.h b/extmod/modtrezorconfig/norcow_config.h new file mode 100644 index 000000000..dd0807680 --- /dev/null +++ b/extmod/modtrezorconfig/norcow_config.h @@ -0,0 +1,10 @@ +#ifdef UNIX +#define NORCOW_UNIX 1 +#define NORCOW_FILE "/var/tmp/trezor.config" +#endif + +#ifdef STM32_HAL_H +// TODO: switch to native implementation when finished +#define NORCOW_UNIX 1 +#define NORCOW_FILE "/sd/trezor.config" +#endif diff --git a/src/trezor/config.py b/src/trezor/config.py index e7babd2ff..471f64435 100644 --- a/src/trezor/config.py +++ b/src/trezor/config.py @@ -1,52 +1,13 @@ -import sys -import ustruct +from TrezorConfig import Config -# mock implementation using binary file +_config = Config() -_mock = {} +def get(app, key, default=None): + v = _config.get(app, key) + return v if v else default -if sys.platform in ['trezor', 'pyboard']: # stmhal - _file = '/flash/trezor.config' -else: - _file = '/var/tmp/trezor.config' - - -def _load(): - global _mock - try: - with open(_file, 'rb') as f: - while True: - d = f.read(4) - if len(d) != 4: - break - k, l = ustruct.unpack('