From 393d98a739f823609e2958909f5520164e972c14 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Nov 2024 12:05:48 -0700 Subject: [PATCH] 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 --- doc/releases/migration-guide-4.1.rst | 6 +++ scripts/west_commands/runners/bossac.py | 12 +++-- scripts/west_commands/tests/test_bossac.py | 55 ++++++++++++++++++++-- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/doc/releases/migration-guide-4.1.rst b/doc/releases/migration-guide-4.1.rst index e7420af494173d..24a10a7ee581d6 100644 --- a/doc/releases/migration-guide-4.1.rst +++ b/doc/releases/migration-guide-4.1.rst @@ -18,6 +18,12 @@ the :ref:`release notes`. 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 ****** diff --git a/scripts/west_commands/runners/bossac.py b/scripts/west_commands/runners/bossac.py index 227d6b5c82e7a6..0cfbcc1adfe990 100644 --- a/scripts/west_commands/runners/bossac.py +++ b/scripts/west_commands/runners/bossac.py @@ -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 @@ def name(cls): @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 @@ 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""" @@ -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(): diff --git a/scripts/west_commands/tests/test_bossac.py b/scripts/west_commands/tests/test_bossac.py index 58cc8b01b5d708..2e1b7b2c223fba 100644 --- a/scripts/west_commands/tests/test_bossac.py +++ b/scripts/west_commands/tests/test_bossac.py @@ -27,7 +27,7 @@ ['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 @@ ['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 @@ '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 @@ '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',