1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00

core: support rebooting into default mode

This commit is contained in:
Jan Pochyla 2019-07-24 14:39:14 +02:00 committed by Tomas Susanka
parent d2597d54c1
commit ebe883e4a9
4 changed files with 33 additions and 25 deletions

View File

@ -73,9 +73,10 @@ async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
return Success(message=msg.message)
def boot() -> None:
def boot(features_only: bool = False) -> None:
register(MessageType.Initialize, protobuf_workflow, handle_Initialize)
register(MessageType.GetFeatures, protobuf_workflow, handle_GetFeatures)
register(MessageType.Cancel, protobuf_workflow, handle_Cancel)
register(MessageType.ClearSession, protobuf_workflow, handle_ClearSession)
register(MessageType.Ping, protobuf_workflow, handle_Ping)
if not features_only:
register(MessageType.Cancel, protobuf_workflow, handle_Cancel)
register(MessageType.ClearSession, protobuf_workflow, handle_ClearSession)
register(MessageType.Ping, protobuf_workflow, handle_Ping)

View File

@ -15,10 +15,11 @@ async def recovery_homescreen() -> None:
ctx = wire.DummyContext()
try:
await recovery_process(ctx)
except Exception:
# clear the loop state, so loop.run will exit and the device is soft-rebooted
finally:
# clear the loop state, so loop.run will exit
loop.clear()
raise
# clear the registered wire handlers to avoid conflicts
wire.clear()
async def recovery_process(ctx: wire.Context) -> Success:

View File

@ -6,12 +6,9 @@ import boot # noqa: F401
# prepare the USB interfaces, but do not connect to the host yet
import usb
from trezor import wire, utils
from trezor import utils
# initialize the wire codec and start the USB
wire.setup(usb.iface_wire)
if __debug__:
wire.setup(usb.iface_debug)
# start the USB
usb.bus.open()
# switch into unprivileged mode, as we don't need the extra permissions anymore
@ -20,15 +17,10 @@ utils.set_mode_unprivileged()
def _boot_recovery():
# load applications
import apps.management
import apps.homescreen
# boot applications
apps.management.boot()
if __debug__:
import apps.debug
apps.debug.boot()
apps.homescreen.boot(features_only=True)
from apps.management.recovery_device.homescreen import recovery_homescreen
@ -79,11 +71,20 @@ def _boot_default():
workflow.startdefault(homescreen)
from trezor import loop, workflow
from trezor import loop, wire, workflow
from apps.common.storage import recovery
if recovery.is_in_progress():
_boot_recovery()
else:
_boot_default()
loop.run()
while True:
# initialize the wire codec
wire.setup(usb.iface_wire)
if __debug__:
wire.setup(usb.iface_debug)
# boot either in recovery or default mode
if recovery.is_in_progress():
_boot_recovery()
else:
_boot_default()
loop.run()
# loop is empty, reboot

View File

@ -58,6 +58,11 @@ def setup(iface: WireInterface) -> None:
loop.schedule(session_handler(iface, codec_v1.SESSION_ID))
def clear() -> None:
"""Remove all registered handlers."""
workflow_handlers.clear()
class DummyContext:
async def call(*argv):
pass