2023-02-21 11:30:24 +00:00
|
|
|
# isort:skip_file
|
|
|
|
|
|
|
|
import trezorui2
|
|
|
|
import utime
|
|
|
|
|
|
|
|
# Showing welcome screen as soon as possible
|
|
|
|
# (display is also prepared on that occasion).
|
|
|
|
# Remembering time to control how long we show it.
|
|
|
|
trezorui2.draw_welcome_screen()
|
|
|
|
welcome_screen_start_ms = utime.ticks_ms()
|
|
|
|
|
2019-10-25 15:43:55 +00:00
|
|
|
import storage
|
|
|
|
import storage.device
|
2020-04-14 10:21:32 +00:00
|
|
|
from trezor import config, log, loop, ui, utils, wire
|
2023-02-21 11:30:24 +00:00
|
|
|
from trezor.pin import (
|
|
|
|
allow_all_loader_messages,
|
|
|
|
ignore_nonpin_loader_messages,
|
|
|
|
show_pin_timeout,
|
|
|
|
)
|
2022-09-26 21:07:29 +00:00
|
|
|
from trezor.ui.layouts.homescreen import Lockscreen
|
2018-07-03 14:20:26 +00:00
|
|
|
|
2020-04-22 08:54:09 +00:00
|
|
|
from apps.common.request_pin import can_lock_device, verify_user_pin
|
2017-12-14 16:14:15 +00:00
|
|
|
|
2023-02-21 11:30:24 +00:00
|
|
|
_WELCOME_SCREEN_MS = 1500 # how long do we want to show welcome screen (minimum)
|
|
|
|
|
|
|
|
|
|
|
|
def enforce_welcome_screen_duration() -> None:
|
|
|
|
"""Make sure we will show the welcome screen for appropriate amount of time."""
|
|
|
|
# Not wasting the time in debug builds (saves time during emulator debugging)
|
|
|
|
if __debug__:
|
|
|
|
return
|
|
|
|
while utime.ticks_ms() - welcome_screen_start_ms < _WELCOME_SCREEN_MS:
|
|
|
|
utime.sleep_ms(100)
|
|
|
|
|
2017-12-14 16:14:15 +00:00
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def bootscreen() -> None:
|
2023-02-21 11:30:24 +00:00
|
|
|
"""Sequence of actions to be done on boot (after device is connected).
|
|
|
|
|
|
|
|
We are starting with welcome_screen on the screen and want to show it
|
|
|
|
for at least _WELCOME_SCREEN_MS before any other screen.
|
|
|
|
|
|
|
|
Any non-PIN loaders are ignored during this function.
|
|
|
|
Allowing all of them before returning.
|
|
|
|
"""
|
2022-09-26 21:07:29 +00:00
|
|
|
lockscreen = Lockscreen(label=storage.device.get_label(), bootscreen=True)
|
2019-10-25 15:43:55 +00:00
|
|
|
ui.display.orientation(storage.device.get_rotation())
|
2017-10-24 11:59:09 +00:00
|
|
|
while True:
|
2018-02-19 19:36:12 +00:00
|
|
|
try:
|
2020-04-22 08:54:09 +00:00
|
|
|
if can_lock_device():
|
2023-02-21 11:30:24 +00:00
|
|
|
enforce_welcome_screen_duration()
|
2020-04-14 10:21:32 +00:00
|
|
|
await lockscreen
|
2020-03-16 22:40:39 +00:00
|
|
|
await verify_user_pin()
|
|
|
|
storage.init_unlocked()
|
2023-02-21 11:30:24 +00:00
|
|
|
enforce_welcome_screen_duration()
|
|
|
|
allow_all_loader_messages()
|
2020-03-16 22:40:39 +00:00
|
|
|
return
|
2020-04-21 12:31:24 +00:00
|
|
|
except wire.PinCancelled:
|
2020-03-20 10:18:18 +00:00
|
|
|
# verify_user_pin will convert a SdCardUnavailable (in case of sd salt)
|
|
|
|
# to PinCancelled exception.
|
2020-04-21 12:31:24 +00:00
|
|
|
# Ignore exception, retry loop.
|
|
|
|
pass
|
2019-11-04 14:34:00 +00:00
|
|
|
except BaseException as e:
|
2020-03-20 10:18:18 +00:00
|
|
|
# other exceptions here are unexpected and should halt the device
|
2019-11-06 12:57:00 +00:00
|
|
|
if __debug__:
|
|
|
|
log.exception(__name__, e)
|
2019-10-17 15:56:09 +00:00
|
|
|
utils.halt(e.__class__.__name__)
|
2018-02-19 19:36:12 +00:00
|
|
|
|
|
|
|
|
2023-02-21 11:30:24 +00:00
|
|
|
# Ignoring all non-PIN messages in the boot-phase (turned off in `bootscreen()`).
|
|
|
|
ignore_nonpin_loader_messages()
|
|
|
|
|
2019-02-21 13:06:20 +00:00
|
|
|
config.init(show_pin_timeout)
|
2021-03-22 14:30:36 +00:00
|
|
|
|
|
|
|
if __debug__ and not utils.EMULATOR:
|
|
|
|
config.wipe()
|
|
|
|
|
2018-02-19 19:36:12 +00:00
|
|
|
loop.schedule(bootscreen())
|
2017-10-24 11:59:09 +00:00
|
|
|
loop.run()
|