Skip to content
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,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
Expand Down
4 changes: 4 additions & 0 deletions boards/common/blflash.board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

board_set_flasher_ifnset(blflash)
board_finalize_runner_args(blflash)
1 change: 1 addition & 0 deletions scripts/west_commands/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def _import_runner_module(runner_name):

_names = [
'blackmagicprobe',
'blflash',
'bossac',
'canopen_program',
'dediprog',
Expand Down
59 changes: 59 additions & 0 deletions scripts/west_commands/runners/blflash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) 2021 Gerson Fernando Budke <[email protected]>
#
# 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call str. This is already a string.

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',
self.cfg.bin_file,
'-p', self.port,
'-b', self.speed]

self.check_call(cmd_flash)
1 change: 1 addition & 0 deletions scripts/west_commands/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_runner_imports():
# Please keep this sorted alphabetically.
expected = set(('arc-nsim',
'blackmagicprobe',
'blflash',
'bossac',
'canopen',
'dediprog',
Expand Down