Skip to content

Commit da8f43a

Browse files
VynDragonnandojve
andcommitted
scripts: runners: Introduce bflb_mcu_tool runner
Introduces one of the official flash tools for bouffalolab platforms Co-authored-by: Gerson Fernando Budke <[email protected]> Signed-off-by: Camille BAUD <[email protected]>
1 parent 38ad2a5 commit da8f43a

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
board_set_flasher_ifnset(bflb_mcu_tool)
4+
board_finalize_runner_args(bflb_mcu_tool)

scripts/west_commands/runners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def _import_runner_module(runner_name):
2626

2727
_names = [
2828
# zephyr-keep-sorted-start
29+
'bflb_mcu_tool',
2930
'blackmagicprobe',
3031
'bossac',
3132
'canopen_program',
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (c) 2024-2025 MASSDRIVER EI (massdriver.space)
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
'''Runner for the Official Bouffalo Lab open source command-line flash tool (bflb-mcu-tool)'''
6+
7+
from runners.core import RunnerCaps, ZephyrBinaryRunner
8+
9+
DEFAULT_PORT = '/dev/ttyUSB0'
10+
DEFAULT_SPEED = '115200'
11+
DEFAULT_CHIP = 'bl602'
12+
DEFAULT_EXECUTABLE = "bflb-mcu-tool"
13+
14+
15+
class BlFlashCommandBinaryRunner(ZephyrBinaryRunner):
16+
'''Runner front-end for bflb-mcu-tool.'''
17+
18+
def __init__(
19+
self, cfg, port=DEFAULT_PORT, baudrate=DEFAULT_SPEED, chipname=DEFAULT_CHIP, erase=False
20+
):
21+
super().__init__(cfg)
22+
self.port = port
23+
self.baudrate = baudrate
24+
self.chipname = chipname
25+
self.erase = bool(erase)
26+
27+
@classmethod
28+
def name(cls):
29+
return 'bflb_mcu_tool'
30+
31+
@classmethod
32+
def capabilities(cls):
33+
return RunnerCaps(commands={'flash'}, erase=True, dev_id=True)
34+
35+
@classmethod
36+
def do_add_parser(cls, parser):
37+
parser.set_defaults(dev_id=DEFAULT_PORT)
38+
parser.add_argument(
39+
'-b',
40+
'--baudrate',
41+
default=DEFAULT_SPEED,
42+
help=f"serial port speed to use, default is {str(DEFAULT_SPEED)}",
43+
)
44+
parser.add_argument(
45+
'-ch',
46+
'--chipname',
47+
default=DEFAULT_CHIP,
48+
help=f"chip model, default is {str(DEFAULT_CHIP)}",
49+
choices=['bl602', 'bl606p', 'bl616', 'bl702', 'bl702l', 'bl808'],
50+
)
51+
52+
@classmethod
53+
def do_create(cls, cfg, args):
54+
return BlFlashCommandBinaryRunner(
55+
cfg, port=args.dev_id, baudrate=args.baudrate, chipname=args.chipname, erase=args.erase
56+
)
57+
58+
def do_run(self, command, **kwargs):
59+
self.require(DEFAULT_EXECUTABLE)
60+
self.ensure_output('bin')
61+
cmd_flash = [
62+
DEFAULT_EXECUTABLE,
63+
'--interface',
64+
'uart',
65+
'--port',
66+
self.port,
67+
'--baudrate',
68+
self.baudrate,
69+
'--chipname',
70+
self.chipname,
71+
'--firmware',
72+
self.cfg.bin_file,
73+
]
74+
if self.erase is True:
75+
cmd_flash.append("--erase")
76+
self.check_call(cmd_flash)

0 commit comments

Comments
 (0)