Skip to content

Commit

Permalink
west: runners: bossac: Honor --erase flag
Browse files Browse the repository at this point in the history
Instead of unconditionally erasing the whole target, add
support for using the common --erase flag.

Signed-off-by: Peter Johanson <peter@peterjohanson.com>
  • Loading branch information
petejohanson authored and fabiobaltieri committed Dec 22, 2024
1 parent e3b388c commit 27615a7
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
9 changes: 8 additions & 1 deletion doc/develop/flash_debug/host-tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 6 additions & 0 deletions doc/releases/migration-guide-4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
******

Expand Down
12 changes: 8 additions & 4 deletions scripts/west_commands/runners/bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ 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):
return 'bossac'

@classmethod
def capabilities(cls):
return RunnerCaps(commands={'flash'})
return RunnerCaps(commands={'flash'}, erase=True)

@classmethod
def do_add_parser(cls, parser):
Expand All @@ -60,7 +61,7 @@ def do_add_parser(cls, parser):
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"""
Expand Down Expand Up @@ -180,9 +181,12 @@ def magic_delay(self):

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():
Expand Down
55 changes: 50 additions & 5 deletions scripts/west_commands/tests/test_bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,30 @@
['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],
]

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)],
]

Expand All @@ -54,7 +61,7 @@
'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),
],
]
Expand All @@ -66,7 +73,7 @@
'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),
],
]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 27615a7

Please sign in to comment.