Skip to content

Commit

Permalink
feat(python/trezorctl): trezorctl device reboot-to-bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
matejcik committed Jul 28, 2021
1 parent 0e14291 commit 3ba87cb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/.changelog.d/1738.added
@@ -0,0 +1 @@
trezorctl: new command `device reboot-to-bootloader` reboots T1 to bootloader
14 changes: 14 additions & 0 deletions python/src/trezorlib/cli/device.py
Expand Up @@ -258,3 +258,17 @@ def sd_protect(client, operation):
if client.features.model == "1":
raise click.BadUsage("Trezor One does not support SD card protection.")
return device.sd_protect(client, operation)


@cli.command()
@click.pass_obj
def reboot_to_bootloader(obj):
"""Reboot device into bootloader mode."""
# avoid using @with_client because it closes the session afterwards,
# which triggers double prompt on device
with obj.client_context() as client:
if client.features.model != "1":
click.echo(
f"Warning: Rebooting into bootloader not supported on Trezor {client.features.model}"
)
return device.reboot_to_bootloader(client)
2 changes: 2 additions & 0 deletions python/src/trezorlib/cli/trezorctl.py
Expand Up @@ -190,6 +190,8 @@ def print_result(res, is_json, **kwargs):
click.echo("%s.%s: %s" % (k, kk, vv))
else:
click.echo("%s: %s" % (k, v))
elif isinstance(res, messages.Success):
click.echo(res.message)
elif isinstance(res, protobuf.MessageType):
click.echo(protobuf.format_message(res))
elif res is not None:
Expand Down
6 changes: 6 additions & 0 deletions python/src/trezorlib/device.py
Expand Up @@ -209,3 +209,9 @@ def backup(client):
@expect(messages.Success, field="message")
def cancel_authorization(client):
return client.call(messages.CancelAuthorization())


@session
@expect(messages.Success)
def reboot_to_bootloader(client):
return client.call(messages.RebootToBootloader())

0 comments on commit 3ba87cb

Please sign in to comment.