west: runners: Add support for a common --reset argument

Some of the runners in the tree have been adding their own,
class-specific versions of a switch to instruct the runner to reset or
not the device after flashing.

In order to better support multi-image builds that require more than one
flash operation, introduce a new --reset,--no-reset command-line
parameter that is part of the RunnerCaps so taht this functionality can
be accessed in a standardized manner.

Implementations for the new parameter are provided for the runner
classes that were already configurable in this regard.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Carles Cufi 2023-09-26 13:09:06 +02:00 committed by Martí Bolívar
commit 2d38c095a6
8 changed files with 60 additions and 29 deletions

View file

@ -16,13 +16,15 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for espidf.'''
def __init__(self, cfg, device, boot_address, part_table_address,
app_address, erase=False, baud=921600, flash_size='detect',
flash_freq='40m', flash_mode='dio', espidf='espidf',
bootloader_bin=None, partition_table_bin=None, no_stub=False):
app_address, erase=False, reset=False, baud=921600,
flash_size='detect', flash_freq='40m', flash_mode='dio',
espidf='espidf', bootloader_bin=None, partition_table_bin=None,
no_stub=False):
super().__init__(cfg)
self.elf = cfg.elf_file
self.app_bin = cfg.bin_file
self.erase = bool(erase)
self.reset = bool(reset)
self.device = device
self.boot_address = boot_address
self.part_table_address = part_table_address
@ -42,7 +44,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
@classmethod
def capabilities(cls):
return RunnerCaps(commands={'flash'}, erase=True)
return RunnerCaps(commands={'flash'}, erase=True, reset=True)
@classmethod
def do_add_parser(cls, parser):
@ -77,6 +79,8 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
parser.add_argument('--esp-no-stub', default=False, action='store_true',
help='Disable launching the flasher stub, only talk to ROM bootloader')
parser.set_defaults(reset=True)
@classmethod
def do_create(cls, cfg, args):
if args.esp_tool:
@ -88,7 +92,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
return Esp32BinaryRunner(
cfg, args.esp_device, boot_address=args.esp_boot_address,
part_table_address=args.esp_partition_table_address,
app_address=args.esp_app_address, erase=args.erase,
app_address=args.esp_app_address, erase=args.erase, reset=args.reset,
baud=args.esp_baud_rate, flash_size=args.esp_flash_size,
flash_freq=args.esp_flash_freq, flash_mode=args.esp_flash_mode,
espidf=espidf, bootloader_bin=args.esp_flash_bootloader,
@ -111,7 +115,8 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
cmd_flash.extend(['--port', self.device])
cmd_flash.extend(['--baud', self.baud])
cmd_flash.extend(['--before', 'default_reset'])
cmd_flash.extend(['--after', 'hard_reset', 'write_flash', '-u'])
if self.reset:
cmd_flash.extend(['--after', 'hard_reset', 'write_flash', '-u'])
cmd_flash.extend(['--flash_mode', self.flash_mode])
cmd_flash.extend(['--flash_freq', self.flash_freq])
cmd_flash.extend(['--flash_size', self.flash_size])