Skip to content

Commit 3947525

Browse files
committed
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>
1 parent 42262e8 commit 3947525

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

doc/develop/flash_debug/host-tools.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ The typical command to flash the board is:
2828

2929
.. code-block:: console
3030
31-
west flash [ -r bossac ] [ -p /dev/ttyX ]
31+
west flash [ -r bossac ] [ -p /dev/ttyX ] [ --erase ]
32+
33+
.. note::
34+
35+
By default, flashing with bossac will only erase the flash pages containing
36+
the flashed application, leaving other pages untouched. Should you wish to
37+
erase the entire flash of the target when flashing, pass the ``--erase``
38+
parameter when flashing.
3239

3340
Flash configuration for devices:
3441

doc/releases/migration-guide-4.1.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ the :ref:`release notes<zephyr_4.1>`.
1818
Build System
1919
************
2020

21+
BOSSA Runner
22+
============
23+
24+
The ``bossac`` runner has been changed to no longer do a full erase by default when flashing. To
25+
perform a full erase, pass the ``--erase`` option when executing ``west flash``.
26+
2127
Kernel
2228
******
2329

scripts/west_commands/runners/bossac.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
2525
'''Runner front-end for bossac.'''
2626

2727
def __init__(self, cfg, bossac='bossac', port=DEFAULT_BOSSAC_PORT,
28-
speed=DEFAULT_BOSSAC_SPEED, boot_delay=0):
28+
speed=DEFAULT_BOSSAC_SPEED, boot_delay=0, erase=False):
2929
super().__init__(cfg)
3030
self.bossac = bossac
3131
self.port = port
3232
self.speed = speed
3333
self.boot_delay = boot_delay
34+
self.erase = erase
3435

3536
@classmethod
3637
def name(cls):
3738
return 'bossac'
3839

3940
@classmethod
4041
def capabilities(cls):
41-
return RunnerCaps(commands={'flash'})
42+
return RunnerCaps(commands={'flash'}, erase=True)
4243

4344
@classmethod
4445
def do_add_parser(cls, parser):
@@ -60,7 +61,7 @@ def do_add_parser(cls, parser):
6061
def do_create(cls, cfg, args):
6162
return BossacBinaryRunner(cfg, bossac=args.bossac,
6263
port=args.bossac_port, speed=args.speed,
63-
boot_delay=args.delay)
64+
boot_delay=args.delay, erase=args.erase)
6465

6566
def read_help(self):
6667
"""Run bossac --help and return the output as a list of lines"""
@@ -180,9 +181,12 @@ def magic_delay(self):
180181

181182
def make_bossac_cmd(self):
182183
self.ensure_output('bin')
183-
cmd_flash = [self.bossac, '-p', self.port, '-R', '-e', '-w', '-v',
184+
cmd_flash = [self.bossac, '-p', self.port, '-R', '-w', '-v',
184185
'-b', self.cfg.bin_file]
185186

187+
if self.erase:
188+
cmd_flash += ['-e']
189+
186190
dt_chosen_code_partition_nd = self.get_chosen_code_partition_node()
187191

188192
if self.is_partition_enabled():

scripts/west_commands/tests/test_bossac.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,30 @@
2727
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
2828
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
2929
'eof', '255'],
30-
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
30+
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
3131
'-b', RC_KERNEL_BIN],
3232
]
3333

3434
EXPECTED_COMMANDS_WITH_SPEED = [
3535
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', TEST_BOSSAC_SPEED,
3636
'ospeed', TEST_BOSSAC_SPEED, 'cs8', '-cstopb', 'ignpar', 'eol', '255',
3737
'eof', '255'],
38-
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
38+
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
3939
'-b', RC_KERNEL_BIN],
4040
]
4141

42+
EXPECTED_COMMANDS_WITH_ERASE = [
43+
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
44+
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
45+
'eof', '255'],
46+
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
47+
'-b', RC_KERNEL_BIN, '-e'],
48+
]
4249
EXPECTED_COMMANDS_WITH_OFFSET = [
4350
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
4451
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
4552
'eof', '255'],
46-
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
53+
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
4754
'-b', RC_KERNEL_BIN, '-o', str(TEST_OFFSET)],
4855
]
4956

@@ -54,7 +61,7 @@
5461
'eof', '255'
5562
],
5663
[
57-
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
64+
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
5865
'-b', RC_KERNEL_BIN, '-o', str(TEST_FLASH_ADDRESS),
5966
],
6067
]
@@ -66,7 +73,7 @@
6673
'eof', '255'
6774
],
6875
[
69-
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
76+
'bossac', '-p', TEST_BOSSAC_PORT, '-R', '-w', '-v',
7077
'-b', RC_KERNEL_BIN, '-o', str(TEST_FLASH_ADDRESS),
7178
],
7279
]
@@ -175,6 +182,7 @@ def test_bossac_init(cc, req, get_cod_par, sup, runner_config, tmpdir):
175182
176183
Output:
177184
no --offset
185+
no -e
178186
"""
179187
runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_STD)
180188
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):
207215
208216
Output:
209217
no --offset
218+
no -e
210219
"""
211220
args = ['--bossac-port', str(TEST_BOSSAC_PORT)]
212221
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
257266
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_SPEED]
258267

259268

269+
@patch('runners.bossac.BossacBinaryRunner.supports',
270+
return_value=False)
271+
@patch('runners.bossac.BossacBinaryRunner.get_chosen_code_partition_node',
272+
return_value=None)
273+
@patch('runners.core.ZephyrBinaryRunner.require',
274+
side_effect=require_patch)
275+
@patch('runners.core.ZephyrBinaryRunner.check_call')
276+
def test_bossac_create_with_erase(cc, req, get_cod_par, sup, runner_config, tmpdir):
277+
"""
278+
Test commands using a runner created from command line parameters.
279+
280+
Requirements:
281+
Any SDK
282+
283+
Configuration:
284+
ROM bootloader
285+
CONFIG_USE_DT_CODE_PARTITION=n
286+
without zephyr,code-partition
287+
288+
Input:
289+
--erase
290+
291+
Output:
292+
no --offset
293+
"""
294+
args = ['--bossac-port', str(TEST_BOSSAC_PORT),
295+
'--erase']
296+
parser = argparse.ArgumentParser(allow_abbrev=False)
297+
BossacBinaryRunner.add_parser(parser)
298+
arg_namespace = parser.parse_args(args)
299+
runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_STD)
300+
runner = BossacBinaryRunner.create(runner_config, arg_namespace)
301+
with patch('os.path.isfile', side_effect=os_path_isfile_patch):
302+
runner.run('flash')
303+
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_ERASE]
304+
260305
@patch('runners.bossac.BossacBinaryRunner.supports',
261306
return_value=True)
262307
@patch('runners.bossac.BossacBinaryRunner.get_chosen_code_partition_node',

0 commit comments

Comments
 (0)