mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-25 09:22:33 +00:00
core: support rebooting into default mode
This commit is contained in:
parent
d2597d54c1
commit
ebe883e4a9
@ -73,9 +73,10 @@ async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
|
|||||||
return Success(message=msg.message)
|
return Success(message=msg.message)
|
||||||
|
|
||||||
|
|
||||||
def boot() -> None:
|
def boot(features_only: bool = False) -> None:
|
||||||
register(MessageType.Initialize, protobuf_workflow, handle_Initialize)
|
register(MessageType.Initialize, protobuf_workflow, handle_Initialize)
|
||||||
register(MessageType.GetFeatures, protobuf_workflow, handle_GetFeatures)
|
register(MessageType.GetFeatures, protobuf_workflow, handle_GetFeatures)
|
||||||
|
if not features_only:
|
||||||
register(MessageType.Cancel, protobuf_workflow, handle_Cancel)
|
register(MessageType.Cancel, protobuf_workflow, handle_Cancel)
|
||||||
register(MessageType.ClearSession, protobuf_workflow, handle_ClearSession)
|
register(MessageType.ClearSession, protobuf_workflow, handle_ClearSession)
|
||||||
register(MessageType.Ping, protobuf_workflow, handle_Ping)
|
register(MessageType.Ping, protobuf_workflow, handle_Ping)
|
||||||
|
@ -15,10 +15,11 @@ async def recovery_homescreen() -> None:
|
|||||||
ctx = wire.DummyContext()
|
ctx = wire.DummyContext()
|
||||||
try:
|
try:
|
||||||
await recovery_process(ctx)
|
await recovery_process(ctx)
|
||||||
except Exception:
|
finally:
|
||||||
# clear the loop state, so loop.run will exit and the device is soft-rebooted
|
# clear the loop state, so loop.run will exit
|
||||||
loop.clear()
|
loop.clear()
|
||||||
raise
|
# clear the registered wire handlers to avoid conflicts
|
||||||
|
wire.clear()
|
||||||
|
|
||||||
|
|
||||||
async def recovery_process(ctx: wire.Context) -> Success:
|
async def recovery_process(ctx: wire.Context) -> Success:
|
||||||
|
@ -6,12 +6,9 @@ import boot # noqa: F401
|
|||||||
# prepare the USB interfaces, but do not connect to the host yet
|
# prepare the USB interfaces, but do not connect to the host yet
|
||||||
import usb
|
import usb
|
||||||
|
|
||||||
from trezor import wire, utils
|
from trezor import utils
|
||||||
|
|
||||||
# initialize the wire codec and start the USB
|
# start the USB
|
||||||
wire.setup(usb.iface_wire)
|
|
||||||
if __debug__:
|
|
||||||
wire.setup(usb.iface_debug)
|
|
||||||
usb.bus.open()
|
usb.bus.open()
|
||||||
|
|
||||||
# switch into unprivileged mode, as we don't need the extra permissions anymore
|
# switch into unprivileged mode, as we don't need the extra permissions anymore
|
||||||
@ -20,15 +17,10 @@ utils.set_mode_unprivileged()
|
|||||||
|
|
||||||
def _boot_recovery():
|
def _boot_recovery():
|
||||||
# load applications
|
# load applications
|
||||||
import apps.management
|
import apps.homescreen
|
||||||
|
|
||||||
# boot applications
|
# boot applications
|
||||||
apps.management.boot()
|
apps.homescreen.boot(features_only=True)
|
||||||
|
|
||||||
if __debug__:
|
|
||||||
import apps.debug
|
|
||||||
|
|
||||||
apps.debug.boot()
|
|
||||||
|
|
||||||
from apps.management.recovery_device.homescreen import recovery_homescreen
|
from apps.management.recovery_device.homescreen import recovery_homescreen
|
||||||
|
|
||||||
@ -79,11 +71,20 @@ def _boot_default():
|
|||||||
workflow.startdefault(homescreen)
|
workflow.startdefault(homescreen)
|
||||||
|
|
||||||
|
|
||||||
from trezor import loop, workflow
|
from trezor import loop, wire, workflow
|
||||||
from apps.common.storage import recovery
|
from apps.common.storage import recovery
|
||||||
|
|
||||||
|
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():
|
if recovery.is_in_progress():
|
||||||
_boot_recovery()
|
_boot_recovery()
|
||||||
else:
|
else:
|
||||||
_boot_default()
|
_boot_default()
|
||||||
loop.run()
|
loop.run()
|
||||||
|
|
||||||
|
# loop is empty, reboot
|
||||||
|
@ -58,6 +58,11 @@ def setup(iface: WireInterface) -> None:
|
|||||||
loop.schedule(session_handler(iface, codec_v1.SESSION_ID))
|
loop.schedule(session_handler(iface, codec_v1.SESSION_ID))
|
||||||
|
|
||||||
|
|
||||||
|
def clear() -> None:
|
||||||
|
"""Remove all registered handlers."""
|
||||||
|
workflow_handlers.clear()
|
||||||
|
|
||||||
|
|
||||||
class DummyContext:
|
class DummyContext:
|
||||||
async def call(*argv):
|
async def call(*argv):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user