Skip to content

Commit 3173294

Browse files
VynDragonnandojve
authored andcommitted
scripts: runner: Introduce bflb_mcu_tool runner
Add Bouffalo Lab ISP console flash runner. This tool enable bootloader to flash devices using serial port. The blflash Rust tool can be found at https://pypi.org/project/bflb-mcu-tool Signed-off-by: Camille BAUD <[email protected]> Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent a32c5ce commit 3173294

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-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
'blflash',
3132
'bossac',
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (c) 2024 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+
import shutil
8+
9+
from runners.core import RunnerCaps, ZephyrBinaryRunner
10+
11+
DEFAULT_PORT = '/dev/ttyUSB0'
12+
DEFAULT_SPEED = '115200'
13+
DEFAULT_CHIP = 'bl602'
14+
BFLB_SDK_MODULE_NAME = 'hal_bouffalolab'
15+
DEFAULT_EXECUTABLE = "bflb-mcu-tool"
16+
17+
18+
class BlFlashCommandBinaryRunner(ZephyrBinaryRunner):
19+
'''Runner front-end for bflb-mcu-tool.'''
20+
21+
def __init__(
22+
self, cfg, port=DEFAULT_PORT, baudrate=DEFAULT_SPEED, chipname=DEFAULT_CHIP, erase=False
23+
):
24+
super().__init__(cfg)
25+
self.port = port
26+
self.baudrate = baudrate
27+
self.chipname = chipname
28+
self.erase = bool(erase)
29+
30+
@classmethod
31+
def name(cls):
32+
return 'bflb_mcu_tool'
33+
34+
@classmethod
35+
def capabilities(cls):
36+
return RunnerCaps(commands={'flash'}, erase=True)
37+
38+
@classmethod
39+
def do_add_parser(cls, parser):
40+
parser.add_argument(
41+
'-p',
42+
'--port',
43+
default=DEFAULT_PORT,
44+
help='serial port to use, default is ' + str(DEFAULT_PORT),
45+
)
46+
parser.add_argument(
47+
'-b',
48+
'--baudrate',
49+
default=DEFAULT_SPEED,
50+
help='serial port speed to use, default is ' + DEFAULT_SPEED,
51+
)
52+
parser.add_argument(
53+
'-ch',
54+
'--chipname',
55+
default=DEFAULT_CHIP,
56+
help='chip model, default is ' + DEFAULT_CHIP,
57+
choices=['bl602', 'bl606p', 'bl616', 'bl702', 'bl702l', 'bl808'],
58+
)
59+
60+
@classmethod
61+
def do_create(cls, cfg, args):
62+
print(args)
63+
if shutil.which(DEFAULT_EXECUTABLE) is None:
64+
raise ValueError(
65+
"Couldnt find bflb-mcu-tool in PATH, please install with pip install \
66+
bflb-mcu-tool"
67+
)
68+
return BlFlashCommandBinaryRunner(
69+
cfg, port=args.port, baudrate=args.baudrate, chipname=args.chipname, erase=args.erase
70+
)
71+
72+
def do_run(self, command, **kwargs):
73+
self.ensure_output('bin')
74+
cmd_flash = [
75+
DEFAULT_EXECUTABLE,
76+
'--interface',
77+
'uart',
78+
'--port',
79+
self.port,
80+
'--baudrate',
81+
self.baudrate,
82+
'--chipname',
83+
self.chipname,
84+
'--firmware',
85+
self.cfg.bin_file,
86+
]
87+
if self.erase is True:
88+
cmd_flash.append("--erase")
89+
self.check_call(cmd_flash)

scripts/west_commands/tests/test_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def test_runner_imports():
1717
expected = set((
1818
# zephyr-keep-sorted-start
1919
'arc-nsim',
20+
'bflb_mcu_tool',
2021
'blackmagicprobe',
2122
'blflash',
2223
'bossac',

0 commit comments

Comments
 (0)