From 0b54b50ba254e12f5c1b3a85ecad33cfec04c6cf Mon Sep 17 00:00:00 2001 From: slush0 Date: Sat, 12 Oct 2013 17:41:55 +0200 Subject: [PATCH] firmware_update command --- trezorlib/client.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/trezorlib/client.py b/trezorlib/client.py index 0d28cf1a6..097e8a466 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -127,10 +127,10 @@ class TrezorClient(object): if isinstance(resp, proto.Failure): self.message_func(resp.message) - if resp.code == 4: + if resp.code == proto.Failure_ActionCancelled: raise CallException("Action cancelled by user") - elif resp.code == 6: + elif resp.code == proto.Failure_PinInvalid: raise PinException("PIN is invalid") raise CallException(resp.code, resp.message) @@ -259,3 +259,16 @@ class TrezorClient(object): resp = self.call(proto.LoadDevice(seed=seed, pin=pin)) self.init_device() return isinstance(resp, proto.Success) + + def firmware_update(self, fp, force=False): + if self.features.bootloader_mode == False: + raise Exception("Device must be in bootloader mode") + + resp = self.call(proto.FirmwareUpdate(force=force, payload=fp.read())) + if isinstance(resp, proto.Success): + return True + + elif isinstance(resp, proto.Failure) and resp.code == proto.Failure_FirmwareDataIncompatibility: + return False + + raise Exception("Unexpected result " % resp)