west: runners: bossac: Honor --erase flag
Instead of unconditionally erasing the whole target, add support for using the common --erase flag. Signed-off-by: Peter Johanson <peter@peterjohanson.com>
This commit is contained in:
parent
e3b388c17c
commit
27615a7cf1
4 changed files with 72 additions and 10 deletions
|
|
@ -28,7 +28,14 @@ The typical command to flash the board is:
|
|||
|
||||
.. code-block:: console
|
||||
|
||||
west flash [ -r bossac ] [ -p /dev/ttyX ]
|
||||
west flash [ -r bossac ] [ -p /dev/ttyX ] [ --erase ]
|
||||
|
||||
.. note::
|
||||
|
||||
By default, flashing with bossac will only erase the flash pages containing
|
||||
the flashed application, leaving other pages untouched. Should you wish to
|
||||
erase the entire flash of the target when flashing, pass the ``--erase``
|
||||
parameter when flashing.
|
||||
|
||||
Flash configuration for devices:
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ the :ref:`release notes<zephyr_4.1>`.
|
|||
Build System
|
||||
************
|
||||
|
||||
BOSSA Runner
|
||||
============
|
||||
|
||||
The ``bossac`` runner has been changed to no longer do a full erase by default when flashing. To
|
||||
perform a full erase, pass the ``--erase`` option when executing ``west flash``.
|
||||
|
||||
Kernel
|
||||
******
|
||||
|
||||
|
|
|
|||
|
|
@ -25,12 +25,13 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
|
|||
'''Runner front-end for bossac.'''
|
||||
|
||||
def __init__(self, cfg, bossac='bossac', port=DEFAULT_BOSSAC_PORT,
|
||||
speed=DEFAULT_BOSSAC_SPEED, boot_delay=0):
|
||||
speed=DEFAULT_BOSSAC_SPEED, boot_delay=0, erase=False):
|
||||
super().__init__(cfg)
|
||||
self.bossac = bossac
|
||||
self.port = port
|
||||
self.speed = speed
|
||||
self.boot_delay = boot_delay
|
||||
self.erase = erase
|
||||
|
||||
@classmethod
|
||||
def name(cls):
|
||||
|
|
@ -38,7 +39,7 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
|
|||
|
||||
@classmethod
|
||||
def capabilities(cls):
|
||||
return RunnerCaps(commands={'flash'})
|
||||
return RunnerCaps(commands={'flash'}, erase=True)
|
||||
|
||||
@classmethod
|
||||
def do_add_parser(cls, parser):
|
||||
|
|
@ -60,7 +61,7 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
|
|||
def do_create(cls, cfg, args):
|
||||
return BossacBinaryRunner(cfg, bossac=args.bossac,
|
||||
port=args.bossac_port, speed=args.speed,
|
||||
boot_delay=args.delay)
|
||||
boot_delay=args.delay, erase=args.erase)
|
||||
|
||||
def read_help(self):
|
||||
"""Run bossac --help and return the output as a list of lines"""
|
||||
|
|
@ -180,9 +181,12 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
|
|||
|
||||
def make_bossac_cmd(self):
|
||||
self.ensure_output('bin')
|
||||
cmd_flash = [self.bossac, '-p', self.port, '-R', '-e', '-w', '-v',
|
||||
cmd_flash = [self.bossac, '-p', self.port, '-R', '-w', '-v',
|
||||
'-b', self.cfg.bin_file]
|
||||
|
||||
if self.erase:
|
||||
cmd_flash += ['-e']
|
||||
|
||||
dt_chosen_code_partition_nd = self.get_chosen_code_partition_node()
|
||||
|
||||
if self.is_partition_enabled():
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ EXPECTED_COMMANDS = [
|
|||
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
|
||||
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
|
||||
'eof', '255'],
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
|
||||
'-b', RC_KERNEL_BIN],
|
||||
]
|
||||
|
||||
|
|
@ -35,15 +35,22 @@ EXPECTED_COMMANDS_WITH_SPEED = [
|
|||
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', TEST_BOSSAC_SPEED,
|
||||
'ospeed', TEST_BOSSAC_SPEED, 'cs8', '-cstopb', 'ignpar', 'eol', '255',
|
||||
'eof', '255'],
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
|
||||
'-b', RC_KERNEL_BIN],
|
||||
]
|
||||
|
||||
EXPECTED_COMMANDS_WITH_ERASE = [
|
||||
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
|
||||
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
|
||||
'eof', '255'],
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
|
||||
'-b', RC_KERNEL_BIN, '-e'],
|
||||
]
|
||||
EXPECTED_COMMANDS_WITH_OFFSET = [
|
||||
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
|
||||
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
|
||||
'eof', '255'],
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
|
||||
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
|
||||
'-b', RC_KERNEL_BIN, '-o', str(TEST_OFFSET)],
|
||||
]
|
||||
|
||||
|
|
@ -54,7 +61,7 @@ EXPECTED_COMMANDS_WITH_FLASH_ADDRESS = [
|
|||
'eof', '255'
|
||||
],
|
||||
[
|
||||
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
|
||||
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
|
||||
'-b', RC_KERNEL_BIN, '-o', str(TEST_FLASH_ADDRESS),
|
||||
],
|
||||
]
|
||||
|
|
@ -66,7 +73,7 @@ EXPECTED_COMMANDS_WITH_EXTENDED = [
|
|||
'eof', '255'
|
||||
],
|
||||
[
|
||||
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
|
||||
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
|
||||
'-b', RC_KERNEL_BIN, '-o', str(TEST_FLASH_ADDRESS),
|
||||
],
|
||||
]
|
||||
|
|
@ -175,6 +182,7 @@ def test_bossac_init(cc, req, get_cod_par, sup, runner_config, tmpdir):
|
|||
|
||||
Output:
|
||||
no --offset
|
||||
no -e
|
||||
"""
|
||||
runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_STD)
|
||||
runner = BossacBinaryRunner(runner_config, port=TEST_BOSSAC_PORT)
|
||||
|
|
@ -207,6 +215,7 @@ def test_bossac_create(cc, req, get_cod_par, sup, runner_config, tmpdir):
|
|||
|
||||
Output:
|
||||
no --offset
|
||||
no -e
|
||||
"""
|
||||
args = ['--bossac-port', str(TEST_BOSSAC_PORT)]
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False)
|
||||
|
|
@ -257,6 +266,42 @@ def test_bossac_create_with_speed(cc, req, get_cod_par, sup, runner_config, tmpd
|
|||
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_SPEED]
|
||||
|
||||
|
||||
@patch('runners.bossac.BossacBinaryRunner.supports',
|
||||
return_value=False)
|
||||
@patch('runners.bossac.BossacBinaryRunner.get_chosen_code_partition_node',
|
||||
return_value=None)
|
||||
@patch('runners.core.ZephyrBinaryRunner.require',
|
||||
side_effect=require_patch)
|
||||
@patch('runners.core.ZephyrBinaryRunner.check_call')
|
||||
def test_bossac_create_with_erase(cc, req, get_cod_par, sup, runner_config, tmpdir):
|
||||
"""
|
||||
Test commands using a runner created from command line parameters.
|
||||
|
||||
Requirements:
|
||||
Any SDK
|
||||
|
||||
Configuration:
|
||||
ROM bootloader
|
||||
CONFIG_USE_DT_CODE_PARTITION=n
|
||||
without zephyr,code-partition
|
||||
|
||||
Input:
|
||||
--erase
|
||||
|
||||
Output:
|
||||
no --offset
|
||||
"""
|
||||
args = ['--bossac-port', str(TEST_BOSSAC_PORT),
|
||||
'--erase']
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False)
|
||||
BossacBinaryRunner.add_parser(parser)
|
||||
arg_namespace = parser.parse_args(args)
|
||||
runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_STD)
|
||||
runner = BossacBinaryRunner.create(runner_config, arg_namespace)
|
||||
with patch('os.path.isfile', side_effect=os_path_isfile_patch):
|
||||
runner.run('flash')
|
||||
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_ERASE]
|
||||
|
||||
@patch('runners.bossac.BossacBinaryRunner.supports',
|
||||
return_value=True)
|
||||
@patch('runners.bossac.BossacBinaryRunner.get_chosen_code_partition_node',
|
||||
|
|
|
|||
Loading…
Reference in a new issue