mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-17 19:00:58 +00:00
feat(python): show progress bar for firmware upload
This commit is contained in:
parent
a2a8cc88d9
commit
83bb3a0932
1
python/.changelog.d/noissue.added
Normal file
1
python/.changelog.d/noissue.added
Normal file
@ -0,0 +1 @@
|
|||||||
|
`trezorctl firmware update` shows progress bar (Model T only)
|
@ -394,7 +394,12 @@ def upload_firmware_into_device(
|
|||||||
if f.major_version == 1 and f.firmware_present is not False:
|
if f.major_version == 1 and f.firmware_present is not False:
|
||||||
# Trezor One does not send ButtonRequest
|
# Trezor One does not send ButtonRequest
|
||||||
click.echo("Please confirm the action on your Trezor device")
|
click.echo("Please confirm the action on your Trezor device")
|
||||||
firmware.update(client, firmware_data)
|
|
||||||
|
click.echo("Uploading...\r", nl=False)
|
||||||
|
with click.progressbar(
|
||||||
|
label="Uploading", length=len(firmware_data), show_eta=False
|
||||||
|
) as bar:
|
||||||
|
firmware.update(client, firmware_data, bar.update)
|
||||||
except exceptions.Cancelled:
|
except exceptions.Cancelled:
|
||||||
click.echo("Update aborted on device.")
|
click.echo("Update aborted on device.")
|
||||||
except exceptions.TrezorException as e:
|
except exceptions.TrezorException as e:
|
||||||
@ -582,7 +587,4 @@ def update(
|
|||||||
if dry_run:
|
if dry_run:
|
||||||
click.echo("Dry run. Not uploading firmware to device.")
|
click.echo("Dry run. Not uploading firmware to device.")
|
||||||
else:
|
else:
|
||||||
upload_firmware_into_device(
|
upload_firmware_into_device(client=client, firmware_data=firmware_data)
|
||||||
client=client,
|
|
||||||
firmware_data=firmware_data,
|
|
||||||
)
|
|
||||||
|
@ -485,7 +485,11 @@ def validate(
|
|||||||
|
|
||||||
|
|
||||||
@session
|
@session
|
||||||
def update(client: "TrezorClient", data: bytes) -> None:
|
def update(
|
||||||
|
client: "TrezorClient",
|
||||||
|
data: bytes,
|
||||||
|
progress_update: Callable[[int], Any] = lambda _: None,
|
||||||
|
):
|
||||||
if client.features.bootloader_mode is False:
|
if client.features.bootloader_mode is False:
|
||||||
raise RuntimeError("Device must be in bootloader mode")
|
raise RuntimeError("Device must be in bootloader mode")
|
||||||
|
|
||||||
@ -494,6 +498,7 @@ def update(client: "TrezorClient", data: bytes) -> None:
|
|||||||
# TREZORv1 method
|
# TREZORv1 method
|
||||||
if isinstance(resp, messages.Success):
|
if isinstance(resp, messages.Success):
|
||||||
resp = client.call(messages.FirmwareUpload(payload=data))
|
resp = client.call(messages.FirmwareUpload(payload=data))
|
||||||
|
progress_update(len(data))
|
||||||
if isinstance(resp, messages.Success):
|
if isinstance(resp, messages.Success):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -503,9 +508,11 @@ def update(client: "TrezorClient", data: bytes) -> None:
|
|||||||
while isinstance(resp, messages.FirmwareRequest):
|
while isinstance(resp, messages.FirmwareRequest):
|
||||||
assert resp.offset is not None
|
assert resp.offset is not None
|
||||||
assert resp.length is not None
|
assert resp.length is not None
|
||||||
payload = data[resp.offset : resp.offset + resp.length]
|
length = resp.length
|
||||||
|
payload = data[resp.offset : resp.offset + length]
|
||||||
digest = blake2s(payload).digest()
|
digest = blake2s(payload).digest()
|
||||||
resp = client.call(messages.FirmwareUpload(payload=payload, hash=digest))
|
resp = client.call(messages.FirmwareUpload(payload=payload, hash=digest))
|
||||||
|
progress_update(length)
|
||||||
|
|
||||||
if isinstance(resp, messages.Success):
|
if isinstance(resp, messages.Success):
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user