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

runners: bossa: fix support for the Arduino Due #26866

Merged
merged 2 commits into from
Oct 9, 2020
Merged
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
35 changes: 21 additions & 14 deletions scripts/west_commands/runners/bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for bossac.'''

def __init__(self, cfg, bossac='bossac', port=DEFAULT_BOSSAC_PORT,
offset=None, flash_address=None):
offset=None):
super().__init__(cfg)
self.bossac = bossac
self.port = port
self.offset = offset
self.flash_address = flash_address

@classmethod
def name(cls):
Expand All @@ -44,24 +43,34 @@ def do_add_parser(cls, parser):
help='serial port to use, default is /dev/ttyACM0')

@classmethod
def do_create(cls, cfg, args):
# BOSSA means there's a bootloader so always fetch the flash address
args.dt_flash = True
def get_flash_offset(cls, cfg):
# Pull the bootloader size from the config
build_conf = BuildConfiguration(cfg.build_dir)
flash_address = cls.get_flash_address(args, build_conf, None)
if build_conf['CONFIG_HAS_FLASH_LOAD_OFFSET']:
return build_conf['CONFIG_FLASH_LOAD_OFFSET']

return None

@classmethod
def do_create(cls, cfg, args):
offset = args.offset

if offset is None:
offset = cls.get_flash_offset(cfg)
return BossacBinaryRunner(cfg, bossac=args.bossac,
port=args.bossac_port, offset=args.offset,
flash_address=flash_address)
port=args.bossac_port, offset=offset)

def read_help(self):
"""Run bossac --help and return the output as a list of lines"""
self.require(self.bossac)
try:
self.check_output([self.bossac, '--help'])
return []
# BOSSA > 1.9.1 returns OK
out = self.check_output([self.bossac, '--help']).decode()
except subprocess.CalledProcessError as ex:
return ex.output.decode().split('\n')
# BOSSA <= 1.9.1 returns an error
out = ex.output.decode()

return out.split('\n')

def supports(self, flag):
"""Check if bossac supports a flag by searching the help"""
Expand All @@ -75,8 +84,6 @@ def get_offset(self, supports_offset):
if supports_offset:
if self.offset is not None:
return self.offset
if self.flash_address is not None:
return self.flash_address

self.logger.warning(
'This version of BOSSA supports the --offset flag but' +
Expand Down Expand Up @@ -113,7 +120,7 @@ def do_run(self, command, **kwargs):

offset = self.get_offset(self.supports('--offset'))

if offset is not None:
if offset:
cmd_flash += ['-o', '%s' % offset]

self.check_call(cmd_flash)
6 changes: 3 additions & 3 deletions scripts/west_commands/tests/test_bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_bossac_init(cc, req, supports, runner_config):

@patch('runners.bossac.BossacBinaryRunner.supports', return_value=True)
@patch('runners.core.BuildConfiguration._init')
@patch('runners.core.ZephyrBinaryRunner.get_flash_address',
@patch('runners.bossac.BossacBinaryRunner.get_flash_offset',
return_value=None)
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
@patch('runners.core.ZephyrBinaryRunner.check_call')
Expand All @@ -86,7 +86,7 @@ def test_bossac_create(cc, req, gfa, bcfg, supports, runner_config):

@patch('runners.bossac.BossacBinaryRunner.supports', return_value=True)
@patch('runners.core.BuildConfiguration._init')
@patch('runners.core.ZephyrBinaryRunner.get_flash_address',
@patch('runners.bossac.BossacBinaryRunner.get_flash_offset',
return_value=TEST_FLASH_ADDRESS)
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
@patch('runners.core.ZephyrBinaryRunner.check_call')
Expand All @@ -105,7 +105,7 @@ def test_bossac_create_with_offset(cc, req, gfa, bcfg, supports,

@patch('runners.bossac.BossacBinaryRunner.supports', return_value=True)
@patch('runners.core.BuildConfiguration._init')
@patch('runners.core.ZephyrBinaryRunner.get_flash_address',
@patch('runners.bossac.BossacBinaryRunner.get_flash_offset',
return_value=TEST_FLASH_ADDRESS)
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
@patch('runners.core.ZephyrBinaryRunner.check_call')
Expand Down