Skip to content

Commit 889d27d

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 889d27d

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
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: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)