1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-21 15:39:01 +00:00

feat(python/trezorctl): respect current firmware bitcoinness when updating

This commit is contained in:
matejcik 2023-10-17 10:57:56 +02:00
parent c9be90788f
commit 3ee051bf69

View File

@ -32,7 +32,7 @@ from urllib.parse import urlparse
import click import click
import requests import requests
from .. import exceptions, firmware from .. import exceptions, firmware, messages
from ..firmware import models as fw_models from ..firmware import models as fw_models
from . import with_client from . import with_client
@ -259,11 +259,25 @@ def find_specified_firmware_version(
sys.exit(1) sys.exit(1)
def _should_use_bitcoin_only(features: messages.Features) -> bool:
# in bootloader, decide by unit indicator
# TODO determine by fw vendor if installed?
if features.bootloader_mode:
return bool(features.unit_btconly)
# in firmware, check whether current firmware is bitcoin-only
if messages.Capability.Bitcoin_like not in features.capabilities:
return True
# universal firmware by default
return False
def find_best_firmware_version( def find_best_firmware_version(
client: "TrezorClient", client: "TrezorClient",
version: Optional[str], version: Optional[str],
beta: bool, beta: bool,
bitcoin_only: bool, bitcoin_only: Optional[bool],
) -> Tuple[str, str]: ) -> Tuple[str, str]:
"""Get the url from which to download the firmware and its expected fingerprint. """Get the url from which to download the firmware and its expected fingerprint.
@ -273,6 +287,8 @@ def find_best_firmware_version(
If the specified version is not found, prints the closest available version If the specified version is not found, prints the closest available version
(higher than the specified one, if existing). (higher than the specified one, if existing).
""" """
if bitcoin_only is None:
bitcoin_only = _should_use_bitcoin_only(client.features)
def version_str(version: Iterable[int]) -> str: def version_str(version: Iterable[int]) -> str:
return ".".join(map(str, version)) return ".".join(map(str, version))
@ -491,7 +507,7 @@ def verify(
@click.option("-v", "--version", help="Which version to download") @click.option("-v", "--version", help="Which version to download")
@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("--beta", is_flag=True, help="Use firmware from BETA channel") @click.option("--beta", is_flag=True, help="Use firmware from BETA channel")
@click.option("--bitcoin-only", is_flag=True, help="Use bitcoin-only firmware (if possible)") @click.option("--bitcoin-only/--universal", is_flag=True, default=None, help="Download bitcoin-only or universal firmware (defaults to universal)")
@click.option("--fingerprint", help="Expected firmware fingerprint in hex") @click.option("--fingerprint", help="Expected firmware fingerprint in hex")
@click.pass_obj @click.pass_obj
# fmt: on # fmt: on
@ -502,7 +518,7 @@ def download(
skip_check: bool, skip_check: bool,
fingerprint: Optional[str], fingerprint: Optional[str],
beta: bool, beta: bool,
bitcoin_only: bool, bitcoin_only: Optional[bool],
) -> None: ) -> None:
"""Download and save the firmware image. """Download and save the firmware image.
@ -513,7 +529,7 @@ def download(
# (and we will not be checking device when validating) # (and we will not be checking device when validating)
if version: if version:
url, fp = find_specified_firmware_version( url, fp = find_specified_firmware_version(
version=version, beta=beta, bitcoin_only=bitcoin_only version=version, beta=beta, bitcoin_only=bool(bitcoin_only)
) )
bootloader_onev2 = None bootloader_onev2 = None
trezor_major_version = None trezor_major_version = None
@ -553,7 +569,7 @@ def download(
@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 channel") @click.option("--beta", is_flag=True, help="Use firmware from BETA channel")
@click.option("--bitcoin-only", is_flag=True, help="Use bitcoin-only firmware (if possible)") @click.option("--bitcoin-only/--universal", is_flag=True, default=None, help="Download bitcoin-only or universal firmware (defaults to universal)")
@click.option("--raw", is_flag=True, help="Push raw firmware data to Trezor") @click.option("--raw", is_flag=True, help="Push raw firmware data to Trezor")
@click.option("--fingerprint", help="Expected firmware fingerprint in hex") @click.option("--fingerprint", help="Expected firmware fingerprint in hex")
# fmt: on # fmt: on
@ -568,7 +584,7 @@ def update(
raw: bool, raw: bool,
dry_run: bool, dry_run: bool,
beta: bool, beta: bool,
bitcoin_only: bool, bitcoin_only: Optional[bool],
) -> None: ) -> None:
"""Upload new firmware to device. """Upload new firmware to device.