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):
|
2024-02-08 17:27:40 +00:00
|
|
|
super().__init__(uhub_location=uhub_location, device_port=device_port)
|
2020-09-03 09:11:21 +00:00
|
|
|
self.serial = serial.Serial(arduino_serial, 9600)
|
|
|
|
|
2019-10-04 13:22:39 +00:00
|
|
|
def touch(self, location, action):
|
|
|
|
self.now()
|
2021-09-27 10:13:51 +00:00
|
|
|
self.log(f"[hardware/trezor] Touching the {location} button by {action}...")
|
|
|
|
self.serial.write(f"{location} {action}\n".encode())
|
2019-10-04 13:22:39 +00:00
|
|
|
|
|
|
|
def update_firmware(self, file=None):
|
|
|
|
if file:
|
|
|
|
unofficial = True
|
2021-09-27 10:13:51 +00:00
|
|
|
trezorctlcmd = f"firmware-update -s -f {file} &"
|
|
|
|
self.log(f"[software] Updating the firmware to {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()
|
|
|
|
|
2020-06-12 06:04:24 +00:00
|
|
|
self.wait(3)
|
2021-02-15 12:23:23 +00:00
|
|
|
self.check_model("Trezor 1 bootloader")
|
|
|
|
|
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")
|
2023-02-28 18:08:55 +00:00
|
|
|
self.wait(30)
|
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")
|
2024-02-08 17:27:40 +00:00
|
|
|
self.wait(15)
|
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")
|