mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-29 04:08:46 +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 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()
|
if sys.platform in ['trezor', 'pyboard']: # stmhal
|
||||||
|
_file = '/flash/trezor.config'
|
||||||
def get(app, key, default=None):
|
else:
|
||||||
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 = {}
|
|
||||||
_file = '/var/tmp/trezor.config'
|
_file = '/var/tmp/trezor.config'
|
||||||
|
|
||||||
def _load():
|
def _load():
|
||||||
try:
|
try:
|
||||||
with open(_file, 'rb') as f:
|
with open(_file, 'rb') as f:
|
||||||
while True:
|
while True:
|
||||||
d = f.read(4)
|
d = f.read(4)
|
||||||
if len(d) != 4:
|
if len(d) != 4:
|
||||||
break
|
break
|
||||||
k, l = ustruct.unpack('<HH', d)
|
k, l = ustruct.unpack('<HH', d)
|
||||||
v = f.read(l)
|
v = f.read(l)
|
||||||
_mock[k] = v
|
_mock[k] = v
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _save():
|
def _save():
|
||||||
with open(_file, 'wb') as f:
|
with open(_file, 'wb') as f:
|
||||||
for k, v in _mock.items():
|
for k, v in _mock.items():
|
||||||
f.write(ustruct.pack('<HH', k, len(v)))
|
f.write(ustruct.pack('<HH', k, len(v)))
|
||||||
f.write(v)
|
f.write(v)
|
||||||
|
|
||||||
_load()
|
_load()
|
||||||
|
|
||||||
def get(app, key, default=None):
|
def get(app, key, default=None):
|
||||||
return _mock.get((app << 8) | key, default)
|
return _mock.get((app << 8) | key, default)
|
||||||
|
|
||||||
def set(app, key, value):
|
def set(app, key, value):
|
||||||
_mock[(app << 8) | key] = value
|
_mock[(app << 8) | key] = value
|
||||||
_save()
|
_save()
|
||||||
return True
|
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