Skip to content

Commit 27d43a6

Browse files
committed
Add updatefirmware command
1 parent 92a9a60 commit 27d43a6

File tree

7 files changed

+32
-1
lines changed

7 files changed

+32
-1
lines changed

hwilib/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from .commands import backup_device, displayaddress, enumerate, find_device, \
44
get_client, getmasterxpub, getxpub, getkeypool, getdescriptors, prompt_pin, restore_device, send_pin, setup_device, \
5-
signmessage, signtx, wipe_device, install_udev_rules
5+
signmessage, signtx, wipe_device, install_udev_rules, \
6+
update_firmware
67
from .errors import (
78
handle_errors,
89
DEVICE_CONN_ERROR,
@@ -68,6 +69,9 @@ def send_pin_handler(args, client):
6869
def install_udev_rules_handler(args):
6970
return install_udev_rules('udev', args.location)
7071

72+
def update_firmware_handler(args, client):
73+
return update_firmware(client, args.file)
74+
7175
class HWIHelpFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
7276
pass
7377

@@ -181,6 +185,10 @@ def process_commands(cli_args):
181185
sendpin_parser.add_argument('pin', help='The numeric positions of the PIN')
182186
sendpin_parser.set_defaults(func=send_pin_handler)
183187

188+
update_firmware_parser = subparsers.add_parser('updatefirmware', help='Verify and load firmware from a file onto a device')
189+
update_firmware_parser.add_argument('file', help='The path to the firmware file')
190+
update_firmware_parser.set_defaults(func=update_firmware_handler)
191+
184192
if sys.platform.startswith("linux"):
185193
udevrules_parser = subparsers.add_parser('installudevrules', help='Install and load the udev rule files for the hardware wallet devices')
186194
udevrules_parser.add_argument('--location', help='The path where the udev rules files will be copied', default='/etc/udev/rules.d/')

hwilib/commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,6 @@ def install_udev_rules(source, location):
245245
from .udevinstaller import UDevInstaller
246246
return UDevInstaller.install(source, location)
247247
return {'error': 'udev rules are not needed on your platform', 'code': NOT_IMPLEMENTED}
248+
249+
def update_firmware(client, file):
250+
return client.update_firmware(file)

hwilib/devices/coldcard.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def prompt_pin(self):
242242
def send_pin(self, pin):
243243
raise UnavailableActionError('The Coldcard does not need a PIN sent from the host')
244244

245+
# Verify firmware file then load it onto device
246+
def update_firmware(self, file):
247+
raise NotImplementedError('The Coldcard does not implement this method yet')
248+
245249
def enumerate(password=''):
246250
results = []
247251
devices = hid.enumerate(COINKITE_VID, CKCC_PID)

hwilib/devices/digitalbitbox.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ def prompt_pin(self):
583583
def send_pin(self, pin):
584584
raise UnavailableActionError('The Digital Bitbox does not need a PIN sent from the host')
585585

586+
# Verify firmware file then load it onto device
587+
def update_firmware(self, file):
588+
raise NotImplementedError('The Digital Bitbox does not implement this method yet')
589+
586590
def enumerate(password=''):
587591
results = []
588592
devices = hid.enumerate(DBB_VENDOR_ID, DBB_DEVICE_ID)

hwilib/devices/ledger.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ def prompt_pin(self):
354354
def send_pin(self, pin):
355355
raise UnavailableActionError('The Ledger Nano S and X do not need a PIN sent from the host')
356356

357+
# Verify firmware file then load it onto device
358+
def update_firmware(self, file):
359+
raise UnavailableActionError('The Ledger Nano S and X do not support firmware updates from 3rd party software.')
360+
357361
def enumerate(password=''):
358362
results = []
359363
devices = []

hwilib/devices/trezor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ def send_pin(self, pin):
434434
return {'success': False}
435435
return {'success': True}
436436

437+
# Verify firmware file then load it onto device
438+
def update_firmware(self, file):
439+
raise NotImplementedError('The {} does not implement this method yet'.format(self.type))
440+
437441
def enumerate(password=''):
438442
results = []
439443
for dev in enumerate_devices():

hwilib/hwwclient.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ def prompt_pin(self):
6464
# Send pin
6565
def send_pin(self):
6666
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')
67+
68+
# Verify firmware file then load it onto device
69+
def update_firmware(self, file):
70+
raise NotImplementedError('The HardwareWalletClient base class does not implement this method')

0 commit comments

Comments
 (0)