mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 11:28:14 +00:00
python: introduce --bitcoin-only option to trezorctl firmware-update
This commit is contained in:
parent
e3df251f84
commit
8cd9ea49de
@ -621,7 +621,9 @@ def validate_firmware(version, fw, expected_fingerprint=None):
|
|||||||
sys.exit(5)
|
sys.exit(5)
|
||||||
|
|
||||||
|
|
||||||
def find_best_firmware_version(bootloader_version, requested_version=None, beta=False):
|
def find_best_firmware_version(
|
||||||
|
bootloader_version, requested_version=None, beta=False, bitcoin_only=False
|
||||||
|
):
|
||||||
if beta:
|
if beta:
|
||||||
url = "https://beta-wallet.trezor.io/data/firmware/{}/releases.json"
|
url = "https://beta-wallet.trezor.io/data/firmware/{}/releases.json"
|
||||||
else:
|
else:
|
||||||
@ -630,6 +632,8 @@ def find_best_firmware_version(bootloader_version, requested_version=None, beta=
|
|||||||
if not releases:
|
if not releases:
|
||||||
raise click.ClickException("Failed to get list of releases")
|
raise click.ClickException("Failed to get list of releases")
|
||||||
|
|
||||||
|
if bitcoin_only:
|
||||||
|
releases = [r for r in releases if "url_bitcoinonly" in r]
|
||||||
releases.sort(key=lambda r: r["version"], reverse=True)
|
releases.sort(key=lambda r: r["version"], reverse=True)
|
||||||
|
|
||||||
def version_str(version):
|
def version_str(version):
|
||||||
@ -674,14 +678,18 @@ def find_best_firmware_version(bootloader_version, requested_version=None, beta=
|
|||||||
if not ok:
|
if not ok:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if beta:
|
if bitcoin_only:
|
||||||
url = "https://beta-wallet.trezor.io/" + release["url"]
|
url = release["url_bitcoinonly"]
|
||||||
|
fingerprint = release["fingerprint_bitcoinonly"]
|
||||||
else:
|
else:
|
||||||
url = "https://wallet.trezor.io/" + release["url"]
|
url = release["url"]
|
||||||
if url.endswith(".hex"):
|
fingerprint = release["fingerprint"]
|
||||||
url = url[:-4]
|
if beta:
|
||||||
|
url = "https://beta-wallet.trezor.io/" + url
|
||||||
|
else:
|
||||||
|
url = "https://wallet.trezor.io/" + url
|
||||||
|
|
||||||
return url, release["fingerprint"]
|
return url, fingerprint
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@ -692,6 +700,7 @@ def find_best_firmware_version(bootloader_version, requested_version=None, beta=
|
|||||||
@click.option("-s", "--skip-check", is_flag=True, help="Do not validate firmware integrity")
|
@click.option("-s", "--skip-check", is_flag=True, help="Do not validate firmware integrity")
|
||||||
@click.option("-n", "--dry-run", is_flag=True, help="Perform all steps but do not actually upload the firmware")
|
@click.option("-n", "--dry-run", is_flag=True, help="Perform all steps but do not actually upload the firmware")
|
||||||
@click.option("--beta", is_flag=True, help="Use firmware from BETA wallet")
|
@click.option("--beta", is_flag=True, help="Use firmware from BETA wallet")
|
||||||
|
@click.option("--bitcoin-only", is_flag=True, help="Use bitcoin-only firmware (if possible)")
|
||||||
@click.option("--raw", is_flag=True, help="Push raw data to Trezor")
|
@click.option("--raw", is_flag=True, help="Push raw data to Trezor")
|
||||||
@click.option("--fingerprint", help="Expected firmware fingerprint in hex")
|
@click.option("--fingerprint", help="Expected firmware fingerprint in hex")
|
||||||
@click.option("--skip-vendor-header", help="Skip vendor header validation on Trezor T")
|
@click.option("--skip-vendor-header", help="Skip vendor header validation on Trezor T")
|
||||||
@ -708,6 +717,7 @@ def firmware_update(
|
|||||||
raw,
|
raw,
|
||||||
dry_run,
|
dry_run,
|
||||||
beta,
|
beta,
|
||||||
|
bitcoin_only,
|
||||||
):
|
):
|
||||||
"""Upload new firmware to device.
|
"""Upload new firmware to device.
|
||||||
|
|
||||||
@ -743,12 +753,20 @@ def firmware_update(
|
|||||||
if not url:
|
if not url:
|
||||||
bootloader_version = [f.major_version, f.minor_version, f.patch_version]
|
bootloader_version = [f.major_version, f.minor_version, f.patch_version]
|
||||||
version_list = [int(x) for x in version.split(".")] if version else None
|
version_list = [int(x) for x in version.split(".")] if version else None
|
||||||
url, fp = find_best_firmware_version(bootloader_version, version_list, beta)
|
url, fp = find_best_firmware_version(
|
||||||
|
bootloader_version, version_list, beta, bitcoin_only
|
||||||
|
)
|
||||||
if not fingerprint:
|
if not fingerprint:
|
||||||
fingerprint = fp
|
fingerprint = fp
|
||||||
|
|
||||||
|
try:
|
||||||
click.echo("Downloading from {}".format(url))
|
click.echo("Downloading from {}".format(url))
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
|
r.raise_for_status()
|
||||||
|
except requests.exceptions.HTTPError as err:
|
||||||
|
click.echo("Error downloading file: {}".format(err))
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
data = r.content
|
data = r.content
|
||||||
|
|
||||||
if not raw and not skip_check:
|
if not raw and not skip_check:
|
||||||
|
Loading…
Reference in New Issue
Block a user