Skip to content

Commit cf40e54

Browse files
Hau Hoquytranpzz
authored andcommitted
scripts: west: flash: Add support for scripts to flash using the RFP tool.
Add support for scripts to flash using the RFP tool. Signed-off-by: Hau Ho <hau.ho.xc@bp.renesas.com>
1 parent d54010a commit cf40e54

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

scripts/west_commands/runners/rfp.py

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88

99
import platform
1010
import re
11+
from pathlib import Path
1112

1213
from runners.core import RunnerCaps, ZephyrBinaryRunner
1314

14-
if platform.system() == 'Darwin':
15+
if platform.system() == 'Darwin' or 'Windows':
1516
DEFAULT_RFP_PORT = None
1617
else:
1718
DEFAULT_RFP_PORT = '/dev/ttyACM0'
1819

20+
RFP_CLI_EXE = 'rfp-cli'
21+
1922

2023
def to_num(number):
2124
dev_match = re.search(r"^\d*\+dev", number)
@@ -41,6 +44,8 @@ def __init__(
4144
erase=False,
4245
verify=False,
4346
port=DEFAULT_RFP_PORT,
47+
tool=None,
48+
interface=None,
4449
speed=None,
4550
):
4651
super().__init__(cfg)
@@ -49,6 +54,8 @@ def __init__(
4954
self.verify = verify
5055
self.erase = erase
5156
self.port = port
57+
self.tool = tool
58+
self.interface = interface
5259
self.device = device
5360
self.speed = speed
5461

@@ -62,14 +69,25 @@ def capabilities(cls):
6269

6370
@classmethod
6471
def do_add_parser(cls, parser):
72+
# Find the default efp-cli executable
73+
cls.default_rfp()
74+
6575
parser.add_argument(
66-
'--rfp-cli', default='rfp-cli', help='path to rfp-cli, default is rfp-cli'
76+
'--rfp-cli', default=RFP_CLI_EXE, help='path to rfp-cli, default is rfp-cli'
6777
)
6878
parser.add_argument(
6979
'--port',
7080
default=DEFAULT_RFP_PORT,
7181
help='serial port to use, default is ' + str(DEFAULT_RFP_PORT),
7282
)
83+
parser.add_argument(
84+
'--tool',
85+
help='emulator hardware to use (e2, e2l, jlink) when port is not set',
86+
)
87+
parser.add_argument(
88+
'--interface',
89+
help='selects the communications interface (uart, swd)',
90+
)
7391
parser.add_argument('--device', help='Specify the device type to pass to rfp-cli')
7492
parser.add_argument('--verify', action='store_true', help='if given, verify after flash')
7593
parser.add_argument('--speed', help='Specify the serial port speed')
@@ -81,18 +99,39 @@ def do_create(cls, cfg, args):
8199
rfp_cli=args.rfp_cli,
82100
device=args.device,
83101
port=args.port,
102+
tool=args.tool,
103+
interface=args.interface,
84104
erase=args.erase,
85105
speed=args.speed,
86106
verify=args.verify,
87107
)
88108

109+
@staticmethod
110+
def default_rfp():
111+
global RFP_CLI_EXE
112+
113+
if platform.system() == 'Windows':
114+
try:
115+
import winreg
116+
117+
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
118+
key = winreg.OpenKey(registry, r"SOFTWARE\Classes\rpjfile\shell\Open\command")
119+
val = winreg.QueryValue(key, None)
120+
match = re.match(r'"(.*?)".*', val)[1]
121+
RFP_CLI_EXE = str(Path(match).parent / 'rfp-cli.exe')
122+
except Exception:
123+
RFP_CLI_EXE = 'rfp-cli.exe'
124+
else:
125+
RFP_CLI_EXE = 'rfp-cli'
126+
89127
def do_run(self, command, **kwargs):
90128
if command == 'flash':
91129
self.do_flash(**kwargs)
92130
else:
93131
self.logger.error("Unsuppported command")
94132

95133
def do_flash(self, **kwargs):
134+
self.require(self.rfp_cmd[0])
96135
self.ensure_output('hex')
97136

98137
hex_name = self.cfg.hex_file
@@ -111,10 +150,18 @@ def do_flash(self, **kwargs):
111150
# Load image
112151
load_image += ['-p', '-file', hex_name]
113152

114-
port = ['-port', self.port]
153+
if self.tool is None:
154+
connection = ['-port', self.port]
155+
else:
156+
connection = ['-tool', self.tool]
157+
158+
if self.interface:
159+
connection += ['-interface', self.interface]
160+
115161
if self.speed:
116-
port += ['-s', self.speed]
162+
connection += ['-s', self.speed]
163+
117164
device = ['-device', self.device]
118165

119-
cmd = self.rfp_cmd + port + device + load_image
166+
cmd = self.rfp_cmd + connection + device + load_image
120167
self.check_call(cmd)

scripts/west_commands/tests/test_rfp.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696

9797
def require_patch(program):
98-
assert program in ['rfp']
98+
assert program in ['rfp', 'rfp-cli', TEST_RFP_USR_LOCAL_RFP_CLI]
9999

100100

101101
os_path_isfile = os.path.isfile
@@ -109,7 +109,8 @@ def os_path_isfile_patch(filename):
109109

110110
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
111111
@patch('runners.core.ZephyrBinaryRunner.check_call')
112-
def test_rfp_init(cc, req, runner_config, tmpdir):
112+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
113+
def test_rfp_init(dr, cc, req, runner_config, tmpdir):
113114
"""
114115
Test commands using a runner created by constructor.
115116
@@ -129,7 +130,8 @@ def test_rfp_init(cc, req, runner_config, tmpdir):
129130

130131
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
131132
@patch('runners.core.ZephyrBinaryRunner.check_call')
132-
def test_rfp_create(cc, req, runner_config, tmpdir):
133+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
134+
def test_rfp_create(dr, cc, req, runner_config, tmpdir):
133135
"""
134136
Test commands using a runner created from command line parameters.
135137
@@ -154,7 +156,8 @@ def test_rfp_create(cc, req, runner_config, tmpdir):
154156

155157
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
156158
@patch('runners.core.ZephyrBinaryRunner.check_call')
157-
def test_rfp_create_with_speed(cc, req, runner_config, tmpdir):
159+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
160+
def test_rfp_create_with_speed(dr, cc, req, runner_config, tmpdir):
158161
"""
159162
Test commands using a runner created from command line parameters.
160163
@@ -185,7 +188,8 @@ def test_rfp_create_with_speed(cc, req, runner_config, tmpdir):
185188

186189
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
187190
@patch('runners.core.ZephyrBinaryRunner.check_call')
188-
def test_rfp_create_with_erase(cc, req, runner_config, tmpdir):
191+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
192+
def test_rfp_create_with_erase(dr, cc, req, runner_config, tmpdir):
189193
"""
190194
Test commands using a runner created from command line parameters.
191195
@@ -207,7 +211,8 @@ def test_rfp_create_with_erase(cc, req, runner_config, tmpdir):
207211

208212
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
209213
@patch('runners.core.ZephyrBinaryRunner.check_call')
210-
def test_rfp_create_with_verify(cc, req, runner_config, tmpdir):
214+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
215+
def test_rfp_create_with_verify(dr, cc, req, runner_config, tmpdir):
211216
"""
212217
Test commands using a runner created from command line parameters.
213218
@@ -229,7 +234,8 @@ def test_rfp_create_with_verify(cc, req, runner_config, tmpdir):
229234

230235
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
231236
@patch('runners.core.ZephyrBinaryRunner.check_call')
232-
def test_rfp_create_with_rfp_cli(cc, req, runner_config, tmpdir):
237+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
238+
def test_rfp_create_with_rfp_cli(dr, cc, req, runner_config, tmpdir):
233239
"""
234240
Test commands using a runner created from command line parameters.
235241

0 commit comments

Comments
 (0)