From e7c40c956069b99a03c07150dbfd120c075aee89 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 28 Jul 2021 16:01:02 +0200 Subject: [PATCH] feat(python/trezorctl): trezorctl device reboot-to-bootloader --- python/.changelog.d/1738.added | 1 + python/docs/OPTIONS.rst | 15 ++++++++------- python/src/trezorlib/cli/device.py | 17 +++++++++++++++++ python/src/trezorlib/device.py | 6 ++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 python/.changelog.d/1738.added diff --git a/python/.changelog.d/1738.added b/python/.changelog.d/1738.added new file mode 100644 index 0000000000..2e40897a98 --- /dev/null +++ b/python/.changelog.d/1738.added @@ -0,0 +1 @@ +trezorctl: new command `device reboot-to-bootloader` reboots T1 to bootloader diff --git a/python/docs/OPTIONS.rst b/python/docs/OPTIONS.rst index 58b877fb64..7781d83153 100644 --- a/python/docs/OPTIONS.rst +++ b/python/docs/OPTIONS.rst @@ -205,13 +205,14 @@ Device management commands - setup, recover seed, wipe, etc. --help Show this message and exit. Commands: - backup Perform device seed backup. - load Upload seed and custom configuration to the device. - recover Start safe recovery workflow. - sd-protect Secure the device with SD card protection. - self-test Perform a self-test. - setup Perform device setup and generate new seed. - wipe Reset device to factory defaults and remove all private data. + backup Perform device seed backup. + load Upload seed and custom configuration to the device. + reboot-to-bootloader Reboot device into bootloader mode. + recover Start safe recovery workflow. + sd-protect Secure the device with SD card protection. + self-test Perform a self-test. + setup Perform device setup and generate new seed. + wipe Reset device to factory defaults and remove all private data. EOS commands. ~~~~~~~~~~~~~ diff --git a/python/src/trezorlib/cli/device.py b/python/src/trezorlib/cli/device.py index 39bd18e1ef..587cdad9d2 100644 --- a/python/src/trezorlib/cli/device.py +++ b/python/src/trezorlib/cli/device.py @@ -258,3 +258,20 @@ 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. + + Currently only supported on Trezor Model One. + """ + # 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) diff --git a/python/src/trezorlib/device.py b/python/src/trezorlib/device.py index 2179cd19be..56b3b0728c 100644 --- a/python/src/trezorlib/device.py +++ b/python/src/trezorlib/device.py @@ -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, field="message") +def reboot_to_bootloader(client): + return client.call(messages.RebootToBootloader())