mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-20 21:38:26 +00:00
add new firmware update method, update protobuf
This commit is contained in:
parent
dccc1b08ed
commit
29348f4098
@ -956,18 +956,35 @@ class ProtocolMixin(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
|
|
||||||
|
# TREZORv1 method
|
||||||
|
if isinstance(resp, proto.Success):
|
||||||
fingerprint = hashlib.sha256(data[256:]).hexdigest()
|
fingerprint = hashlib.sha256(data[256:]).hexdigest()
|
||||||
log("Firmware fingerprint: " + fingerprint)
|
log("Firmware fingerprint: " + fingerprint)
|
||||||
resp = self.call(proto.FirmwareUpload(payload=data))
|
resp = self.call(proto.FirmwareUpload(payload=data))
|
||||||
|
|
||||||
if isinstance(resp, proto.Success):
|
if isinstance(resp, proto.Success):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
elif isinstance(resp, proto.Failure) and resp.code == types.Failure_FirmwareError:
|
elif isinstance(resp, proto.Failure) and resp.code == types.Failure_FirmwareError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
raise Exception("Unexpected result %s" % resp)
|
raise Exception("Unexpected result %s" % resp)
|
||||||
|
|
||||||
|
# TREZORv2 method
|
||||||
|
if isinstance(resp, proto.FirmwareRequest):
|
||||||
|
import pyblake2
|
||||||
|
while True:
|
||||||
|
payload = data[resp.offset:resp.offset + resp.length]
|
||||||
|
digest = pyblake2.blake2s(payload).digest()
|
||||||
|
resp = self.call(proto.FirmwareUpload(payload=payload, hash=digest))
|
||||||
|
if isinstance(resp, proto.FirmwareRequest):
|
||||||
|
continue
|
||||||
|
elif isinstance(resp, proto.Success):
|
||||||
|
return True
|
||||||
|
elif isinstance(resp, proto.Failure) and resp.code == types.Failure_FirmwareError:
|
||||||
|
return False
|
||||||
|
raise Exception("Unexpected result %s" % resp)
|
||||||
|
|
||||||
|
raise Exception("Unexpected message %s" % resp)
|
||||||
|
|
||||||
class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient):
|
class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user