2020-09-03 09:11:21 +00:00
|
|
|
import serial
|
2019-10-04 13:22:39 +00:00
|
|
|
|
|
|
|
from .device import Device
|
|
|
|
|
|
|
|
|
|
|
|
class TrezorOne(Device):
|
2020-09-03 09:11:21 +00:00
|
|
|
def __init__(self, uhub_location, arduino_serial, device_port):
|
|
|
|
super().__init__(uhub_location, device_port)
|
|
|
|
self.serial = serial.Serial(arduino_serial, 9600)
|
|
|
|
|
2019-10-04 13:22:39 +00:00
|
|
|
def touch(self, location, action):
|
|
|
|
self.now()
|
2021-01-21 23:18:34 +00:00
|
|
|
self.log(
|
2019-10-04 13:22:39 +00:00
|
|
|
"[hardware/trezor] Touching the {} button by {}...".format(location, action)
|
|
|
|
)
|
|
|
|
self.serial.write(("{} {}\n".format(location, action)).encode())
|
|
|
|
|
|
|
|
def update_firmware(self, file=None):
|
|
|
|
if file:
|
|
|
|
unofficial = True
|
2020-09-03 09:11:21 +00:00
|
|
|
trezorctlcmd = "firmware-update -s -f {} &".format(file)
|
2021-01-21 23:18:34 +00:00
|
|
|
self.log("[software] Updating the firmware to {}".format(file))
|
2019-10-04 13:22:39 +00:00
|
|
|
else:
|
|
|
|
unofficial = False
|
2020-09-03 09:11:21 +00:00
|
|
|
trezorctlcmd = "firmware-update &"
|
2021-01-21 23:18:34 +00:00
|
|
|
self.log("[software] Updating the firmware to latest")
|
2020-06-12 06:04:24 +00:00
|
|
|
self.wait(3)
|
2019-10-04 13:22:39 +00:00
|
|
|
self._enter_bootloader()
|
|
|
|
|
2021-01-21 23:18:34 +00:00
|
|
|
self.run_trezorctl("list")
|
|
|
|
|
2020-06-12 06:04:24 +00:00
|
|
|
self.wait(3)
|
2020-09-03 09:11:21 +00:00
|
|
|
self.run_trezorctl(trezorctlcmd)
|
2019-10-04 13:22:39 +00:00
|
|
|
self.wait(3)
|
|
|
|
self.touch("right", "click")
|
2020-12-04 16:16:57 +00:00
|
|
|
self.wait(25)
|
2019-10-04 13:22:39 +00:00
|
|
|
if unofficial:
|
|
|
|
self.touch("right", "click")
|
|
|
|
self.wait(10)
|
|
|
|
self.power_off()
|
|
|
|
self.power_on()
|
|
|
|
if unofficial:
|
|
|
|
self.touch("right", "click")
|
|
|
|
self.wait(5)
|
|
|
|
self.touch("right", "click")
|
|
|
|
self.wait(5)
|
2021-01-21 23:18:34 +00:00
|
|
|
return self.check_model("Trezor 1")
|
2019-10-04 13:22:39 +00:00
|
|
|
|
|
|
|
def _enter_bootloader(self):
|
|
|
|
self.power_off()
|
|
|
|
self.touch("all", "press")
|
|
|
|
self.wait(2)
|
|
|
|
self.power_on()
|
|
|
|
self.wait(2)
|
|
|
|
self.touch("all", "unpress")
|