mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
use mock config for stmhal, setup hid in boot
This commit is contained in:
parent
7aa8593941
commit
f42b62fa40
@ -0,0 +1,6 @@
|
||||
import sys
|
||||
|
||||
if sys.platform in ['trezor', 'pyboard']: # stmhal
|
||||
import pyb
|
||||
# hid=(subclass, protocol, max_packet_len, polling_interval, report_desc)
|
||||
pyb.usb_mode('CDC+HID', vid=0x1209, pid=0x53C1, hid=(0, 0, 64, 1, b'\x06\x00\xff\x09\x01\xa1\x01\x09\x20\x15\x00\x26\xff\x00\x75\x08\x95\x40\x81\x02\x09\x21\x15\x00\x26\xff\x00\x75\x08\x95\x40\x91\x02\xc0'))
|
@ -1,50 +1,40 @@
|
||||
import sys
|
||||
import ustruct
|
||||
|
||||
if sys.platform == 'trezor': # stmhal - use binary module (not working atm)
|
||||
# mock implementation using binary file
|
||||
|
||||
from TrezorConfig import Config
|
||||
_mock = {}
|
||||
|
||||
_config = Config()
|
||||
|
||||
def get(app, key, default=None):
|
||||
v = _config.get(app, key)
|
||||
return v if v else default
|
||||
|
||||
def set(app, key, value):
|
||||
return _config.set(app, key, value)
|
||||
|
||||
else: # emulator (mock implementation using binary file)
|
||||
|
||||
import ustruct
|
||||
|
||||
_mock = {}
|
||||
if sys.platform in ['trezor', 'pyboard']: # stmhal
|
||||
_file = '/flash/trezor.config'
|
||||
else:
|
||||
_file = '/var/tmp/trezor.config'
|
||||
|
||||
def _load():
|
||||
try:
|
||||
with open(_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)
|
||||
_mock[k] = v
|
||||
except OSError:
|
||||
pass
|
||||
def _load():
|
||||
try:
|
||||
with open(_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)
|
||||
_mock[k] = v
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def _save():
|
||||
with open(_file, 'wb') as f:
|
||||
for k, v in _mock.items():
|
||||
f.write(ustruct.pack('<HH', k, len(v)))
|
||||
f.write(v)
|
||||
def _save():
|
||||
with open(_file, 'wb') as f:
|
||||
for k, v in _mock.items():
|
||||
f.write(ustruct.pack('<HH', k, len(v)))
|
||||
f.write(v)
|
||||
|
||||
_load()
|
||||
_load()
|
||||
|
||||
def get(app, key, default=None):
|
||||
return _mock.get((app << 8) | key, default)
|
||||
def get(app, key, default=None):
|
||||
return _mock.get((app << 8) | key, default)
|
||||
|
||||
def set(app, key, value):
|
||||
_mock[(app << 8) | key] = value
|
||||
_save()
|
||||
return True
|
||||
def set(app, key, value):
|
||||
_mock[(app << 8) | key] = value
|
||||
_save()
|
||||
return True
|
||||
|
10
src/trezor/config.py.real
Normal file
10
src/trezor/config.py.real
Normal file
@ -0,0 +1,10 @@
|
||||
from TrezorConfig import Config
|
||||
|
||||
_config = Config()
|
||||
|
||||
def get(app, key, default=None):
|
||||
v = _config.get(app, key)
|
||||
return v if v else default
|
||||
|
||||
def set(app, key, value):
|
||||
return _config.set(app, key, value)
|
Loading…
Reference in New Issue
Block a user