Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

west: runners: bossac: Honor --erase flag #81894

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading