Skip to content

Commit

Permalink
flashing: don't give bossac offset parameter unless explicitly provided
Browse files Browse the repository at this point in the history
This fixes a problem which appeared after bossac version was downgraded
to 1.7 which no longer accepts the -o/--offset parameter. Now the offset
is fed to bossac executable only if it's explicitly provided and not by
default.

Signed-off-by: Kuba Sanak <[email protected]>
  • Loading branch information
KubaFYI committed Jan 27, 2020
1 parent d6d0b64 commit 570540e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 4 additions & 3 deletions scripts/west_commands/runners/bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for bossac.'''

def __init__(self, cfg, bossac='bossac', port=DEFAULT_BOSSAC_PORT,
offset=0):
offset=None):
super(BossacBinaryRunner, self).__init__(cfg)
self.bossac = bossac
self.port = port
Expand All @@ -33,7 +33,7 @@ def capabilities(cls):
def do_add_parser(cls, parser):
parser.add_argument('--bossac', default='bossac',
help='path to bossac, default is bossac')
parser.add_argument('--offset', default=0,
parser.add_argument('--offset', default=None,
help='start erase/write/read/verify operation '
'at flash OFFSET; OFFSET must be aligned '
' to a flash page boundary')
Expand All @@ -56,8 +56,9 @@ def do_run(self, command, **kwargs):
'ospeed', '1200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
'eof', '255']
cmd_flash = [self.bossac, '-p', self.port, '-R', '-e', '-w', '-v',
'-o', '%s' % self.offset,
'-b', self.cfg.bin_file]
if self.offset is not None:
cmd_flash += ['-o', '%s' % self.offset]

self.check_call(cmd_stty)
self.check_call(cmd_flash)
24 changes: 21 additions & 3 deletions scripts/west_commands/tests/test_bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '1200', 'ospeed', '1200',
'cs8', '-cstopb', 'ignpar', 'eol', '255', 'eof', '255'],
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
'-o', str(TEST_OFFSET), '-b', RC_KERNEL_BIN],
'-b', RC_KERNEL_BIN],
]
EXPECTED_COMMANDS_WITH_OFFSET = [
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '1200', 'ospeed', '1200',
'cs8', '-cstopb', 'ignpar', 'eol', '255', 'eof', '255'],
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
'-b', RC_KERNEL_BIN, '-o', str(TEST_OFFSET)],
]

def require_patch(program):
Expand All @@ -28,11 +34,23 @@ def test_bossac_init(cc, req, runner_config):
runner = BossacBinaryRunner(runner_config, port=TEST_BOSSAC_PORT,
offset=TEST_OFFSET)
runner.run('flash')
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS]
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_OFFSET]

@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
@patch('runners.core.ZephyrBinaryRunner.check_call')
def test_bossac_create(cc, req, runner_config):
'''Test commands using a runner created from command line parameters.'''
args = ['--bossac-port', str(TEST_BOSSAC_PORT)]
parser = argparse.ArgumentParser()
BossacBinaryRunner.add_parser(parser)
arg_namespace = parser.parse_args(args)
runner = BossacBinaryRunner.create(runner_config, arg_namespace)
runner.run('flash')
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS]

@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
@patch('runners.core.ZephyrBinaryRunner.check_call')
def test_bossac_create_with_offset(cc, req, runner_config):
'''Test commands using a runner created from command line parameters.'''
args = ['--bossac-port', str(TEST_BOSSAC_PORT),
'--offset', str(TEST_OFFSET)]
Expand All @@ -41,4 +59,4 @@ def test_bossac_create(cc, req, runner_config):
arg_namespace = parser.parse_args(args)
runner = BossacBinaryRunner.create(runner_config, arg_namespace)
runner.run('flash')
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS]
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_OFFSET]

0 comments on commit 570540e

Please sign in to comment.