2018-07-03 12:28:17 +00:00
|
|
|
# isort:skip_file
|
2021-03-22 14:47:43 +00:00
|
|
|
# fmt: off
|
2018-07-03 12:28:17 +00:00
|
|
|
|
2021-04-12 12:35:02 +00:00
|
|
|
# We are tightly controlling the memory layout. Order of imports is important.
|
|
|
|
# Modules imported directly from here also must take care to have as few dependencies
|
|
|
|
# as possible.
|
2021-04-12 11:52:37 +00:00
|
|
|
|
2021-04-12 12:35:02 +00:00
|
|
|
# === Import always-active modules
|
|
|
|
# trezor imports only C modules
|
2021-04-12 11:52:37 +00:00
|
|
|
import trezor
|
2021-04-12 12:35:02 +00:00
|
|
|
# trezor.utils import only C modules
|
2021-04-12 11:52:37 +00:00
|
|
|
from trezor import utils
|
2021-04-12 12:35:02 +00:00
|
|
|
# we need space for 30 items in the trezor module
|
2021-04-12 11:52:37 +00:00
|
|
|
utils.presize_module("trezor", 30)
|
2021-04-12 12:35:02 +00:00
|
|
|
|
|
|
|
# storage imports storage.common, storage.cache and storage.device.
|
|
|
|
# These import trezor, trezor.config (which is a C module), trezor.utils, and each other.
|
|
|
|
import storage
|
|
|
|
# we will need space for 12 items in the storage module
|
2021-04-12 11:52:37 +00:00
|
|
|
utils.presize_module("storage", 12)
|
2017-10-24 11:59:09 +00:00
|
|
|
|
2021-04-08 10:43:28 +00:00
|
|
|
if not utils.BITCOIN_ONLY:
|
2021-04-12 12:35:02 +00:00
|
|
|
# storage.fido2 only imports C modules
|
2021-04-08 10:43:28 +00:00
|
|
|
import storage.fido2 # noqa: F401
|
|
|
|
|
2021-04-12 12:35:02 +00:00
|
|
|
if __debug__:
|
|
|
|
# storage.debug only imports C modules
|
|
|
|
import storage.debug
|
|
|
|
|
|
|
|
# trezor.pin imports trezor.utils
|
|
|
|
# We need it as an always-active module because trezor.pin.show_pin_timeout is used
|
|
|
|
# as a UI callback for storage, which can be invoked at any time
|
|
|
|
import trezor.pin # noqa: F401
|
|
|
|
|
|
|
|
# === Prepare the USB interfaces first. Do not connect to the host yet.
|
|
|
|
# usb imports trezor.utils and trezor.io which is a C module
|
2018-04-16 15:17:45 +00:00
|
|
|
import usb
|
2017-08-16 13:02:03 +00:00
|
|
|
|
2021-04-12 12:35:02 +00:00
|
|
|
# create an unimport manager that will be reused in the main loop
|
2021-03-22 14:47:43 +00:00
|
|
|
unimport_manager = utils.unimport()
|
2017-08-15 13:09:09 +00:00
|
|
|
|
2021-03-22 14:47:43 +00:00
|
|
|
# unlock the device, unload the boot module afterwards
|
|
|
|
with unimport_manager:
|
|
|
|
import boot
|
|
|
|
del boot
|
2019-07-11 14:52:25 +00:00
|
|
|
|
2021-03-22 14:47:43 +00:00
|
|
|
# start the USB
|
2021-04-12 12:35:02 +00:00
|
|
|
import storage.device
|
|
|
|
|
2021-03-22 14:47:43 +00:00
|
|
|
usb.bus.open(storage.device.get_device_id())
|
2019-07-24 12:39:14 +00:00
|
|
|
|
2021-04-12 12:35:02 +00:00
|
|
|
# run the endless loop
|
2021-03-22 14:47:43 +00:00
|
|
|
while True:
|
|
|
|
with unimport_manager:
|
|
|
|
import session # noqa: F401
|
|
|
|
del session
|