diff --git a/CODEOWNERS b/CODEOWNERS index b441aa4e6ef96..fc034daa01da4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -619,6 +619,7 @@ /scripts/twister @nashif /scripts/series-push-hook.sh @erwango /scripts/west_commands/ @mbolivar-nordic +/scripts/west_commands/runners/blflash.py @mbolivar-nordic @nandojve /scripts/west-commands.yml @mbolivar-nordic /scripts/zephyr_module.py @tejlmand /scripts/uf2conv.py @petejohanson diff --git a/boards/common/blflash.board.cmake b/boards/common/blflash.board.cmake new file mode 100644 index 0000000000000..5c99a2b913bf1 --- /dev/null +++ b/boards/common/blflash.board.cmake @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_set_flasher_ifnset(blflash) +board_finalize_runner_args(blflash) diff --git a/scripts/west_commands/runners/__init__.py b/scripts/west_commands/runners/__init__.py index eb4816a9e1d12..167b59fd8f248 100644 --- a/scripts/west_commands/runners/__init__.py +++ b/scripts/west_commands/runners/__init__.py @@ -26,6 +26,7 @@ def _import_runner_module(runner_name): _names = [ 'blackmagicprobe', + 'blflash', 'bossac', 'canopen_program', 'dediprog', diff --git a/scripts/west_commands/runners/blflash.py b/scripts/west_commands/runners/blflash.py new file mode 100644 index 0000000000000..786094ce379e9 --- /dev/null +++ b/scripts/west_commands/runners/blflash.py @@ -0,0 +1,59 @@ +# Copyright (c) 2021 Gerson Fernando Budke +# +# SPDX-License-Identifier: Apache-2.0 + +'''Bouffalo Lab flash tool (blflash) runner for serial boot ROM''' + +from runners.core import ZephyrBinaryRunner, RunnerCaps + +DEFAULT_BLFLASH_PORT = '/dev/ttyUSB0' +DEFAULT_BLFLASH_SPEED = '2000000' + +class BlFlashBinaryRunner(ZephyrBinaryRunner): + '''Runner front-end for blflash.''' + + def __init__(self, cfg, blflash='blflash', + port=DEFAULT_BLFLASH_PORT, + speed=DEFAULT_BLFLASH_SPEED): + super().__init__(cfg) + self.blflash = blflash + self.port = port + self.speed = speed + + @classmethod + def name(cls): + return 'blflash' + + @classmethod + def capabilities(cls): + return RunnerCaps(commands={'flash'}) + + @classmethod + def do_add_parser(cls, parser): + parser.add_argument('--blflash', default='blflash', + help='path to blflash, default is blflash') + parser.add_argument('--port', default=DEFAULT_BLFLASH_PORT, + help='serial port to use, default is ' + + str(DEFAULT_BLFLASH_PORT)) + parser.add_argument('--speed', default=DEFAULT_BLFLASH_SPEED, + help='serial port speed to use, default is ' + + DEFAULT_BLFLASH_SPEED) + + @classmethod + def do_create(cls, cfg, args): + return BlFlashBinaryRunner(cfg, + blflash=args.blflash, + port=args.port, + speed=args.speed) + + def do_run(self, command, **kwargs): + self.require(self.blflash) + self.ensure_output('bin') + + cmd_flash = [self.blflash, + 'flash', + '-s', self.speed, + self.cfg.bin_file, + '-p', self.port] + + self.check_call(cmd_flash) diff --git a/scripts/west_commands/tests/test_imports.py b/scripts/west_commands/tests/test_imports.py index 079f6b7607ae6..8aeba86eb85ac 100644 --- a/scripts/west_commands/tests/test_imports.py +++ b/scripts/west_commands/tests/test_imports.py @@ -16,6 +16,7 @@ def test_runner_imports(): # Please keep this sorted alphabetically. expected = set(('arc-nsim', 'blackmagicprobe', + 'blflash', 'bossac', 'canopen', 'dediprog',