mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
trezor.config: use mock implementation on stmhal again
This commit is contained in:
parent
c6ea71901d
commit
6575b8059e
@ -2,9 +2,3 @@
|
||||
#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
|
||||
|
@ -1,6 +1,10 @@
|
||||
from TrezorConfig import Config
|
||||
|
||||
_config = Config()
|
||||
import sys
|
||||
if sys.platform in ['trezor', 'pyboard']: # stmhal
|
||||
from config_mock import Config
|
||||
_config = Config('/sd/trezor.config')
|
||||
else:
|
||||
from TrezorConfig import Config
|
||||
_config = Config()
|
||||
|
||||
def get(app, key, default=None):
|
||||
v = _config.get(app, key)
|
||||
|
37
src/trezor/config_mock.py
Normal file
37
src/trezor/config_mock.py
Normal file
@ -0,0 +1,37 @@
|
||||
# mock implementation using binary file
|
||||
|
||||
import ustruct
|
||||
|
||||
def Config():
|
||||
|
||||
def __init__(self, filename):
|
||||
self._data = {}
|
||||
self._file = filename
|
||||
try:
|
||||
with open(self._file, 'rb') as f:
|
||||
while True:
|
||||
d = f.read(4)
|
||||
if len(d) != 4:
|
||||
break
|
||||
k, l = ustruct.unpack('<HH', d)
|
||||
v = f.read(l)
|
||||
self._data[k] = v
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def _save(self):
|
||||
with open(self._file, 'wb') as f:
|
||||
for k, v in self._data.items():
|
||||
f.write(ustruct.pack('<HH', k, len(v)))
|
||||
f.write(v)
|
||||
|
||||
def get(self, app_id, key, default=None):
|
||||
return self._data.get((app_id << 8) | key, default)
|
||||
|
||||
def set(self, app_id, key, value):
|
||||
self._data[(app_id << 8) | key] = value
|
||||
self._save()
|
||||
|
||||
def wipe(self):
|
||||
self._data = {}
|
||||
self._save()
|
2
vendor/norcow
vendored
2
vendor/norcow
vendored
@ -1 +1 @@
|
||||
Subproject commit 934b3cd1fbef79fd6b079b787e6e3225bbe5684c
|
||||
Subproject commit 5543b20345cfd2f8e4660c04bd8c5e588c9b9dd6
|
Loading…
Reference in New Issue
Block a user