Skip to content

Commit 292e2d1

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 484851c commit 292e2d1

File tree

1 file changed

+99
-13
lines changed
  • scripts/west_commands/runners

1 file changed

+99
-13
lines changed

scripts/west_commands/runners/rfp.py

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66

77
'''Runner for rfp.'''
88

9+
import os
910
import platform
1011
import re
12+
from pathlib import Path
1113

1214
from runners.core import RunnerCaps, ZephyrBinaryRunner
1315

14-
if platform.system() == 'Darwin':
16+
if platform.system() in ('Darwin', 'Windows'):
1517
DEFAULT_RFP_PORT = None
1618
else:
1719
DEFAULT_RFP_PORT = '/dev/ttyACM0'
1820

21+
RFP_CLI_EXE = 'rfp-cli'
22+
1923

2024
def to_num(number):
2125
dev_match = re.search(r"^\d*\+dev", number)
@@ -41,15 +45,28 @@ def __init__(
4145
erase=False,
4246
verify=False,
4347
port=DEFAULT_RFP_PORT,
48+
tool=None,
49+
interface=None,
50+
rpd_file=None,
4451
speed=None,
52+
dt_flash=True,
4553
):
4654
super().__init__(cfg)
47-
55+
self.file = cfg.file
56+
self.file_type = cfg.file_type
57+
self.hex_name = cfg.hex_file
58+
self.bin_name = cfg.bin_file
59+
self.elf_name = cfg.elf_file
60+
self.mot_name = cfg.mot_file
61+
self.dt_flash = dt_flash
4862
self.rfp_cmd = [rfp_cli]
4963
self.verify = verify
5064
self.erase = erase
5165
self.port = port
66+
self.tool = tool
67+
self.interface = interface
5268
self.device = device
69+
self.rpd_file = rpd_file
5370
self.speed = speed
5471

5572
@classmethod
@@ -62,14 +79,29 @@ def capabilities(cls):
6279

6380
@classmethod
6481
def do_add_parser(cls, parser):
82+
# Find the default efp-cli executable
83+
cls.default_rfp()
84+
6585
parser.add_argument(
66-
'--rfp-cli', default='rfp-cli', help='path to rfp-cli, default is rfp-cli'
86+
'--rfp-cli', default=RFP_CLI_EXE, help='path to rfp-cli, default is rfp-cli'
6787
)
6888
parser.add_argument(
6989
'--port',
7090
default=DEFAULT_RFP_PORT,
7191
help='serial port to use, default is ' + str(DEFAULT_RFP_PORT),
7292
)
93+
parser.add_argument(
94+
'--tool',
95+
help='emulator hardware to use (e2, e2l, jlink) when port is not set',
96+
)
97+
parser.add_argument(
98+
'--interface',
99+
help='selects the communications interface (uart, swd)',
100+
)
101+
parser.add_argument(
102+
'--rpd-file',
103+
help='path to renesas partition data zephyr.rpd',
104+
)
73105
parser.add_argument('--device', help='Specify the device type to pass to rfp-cli')
74106
parser.add_argument('--verify', action='store_true', help='if given, verify after flash')
75107
parser.add_argument('--speed', help='Specify the serial port speed')
@@ -81,25 +113,47 @@ def do_create(cls, cfg, args):
81113
rfp_cli=args.rfp_cli,
82114
device=args.device,
83115
port=args.port,
116+
tool=args.tool,
117+
interface=args.interface,
118+
rpd_file=args.rpd_file,
84119
erase=args.erase,
85120
speed=args.speed,
86121
verify=args.verify,
87122
)
88123

124+
@staticmethod
125+
def default_rfp():
126+
global RFP_CLI_EXE
127+
128+
if platform.system() == 'Windows':
129+
try:
130+
import winreg
131+
132+
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
133+
key = winreg.OpenKey(registry, r"SOFTWARE\Classes\rpjfile\shell\Open\command")
134+
val = winreg.QueryValue(key, None)
135+
match = re.match(r'"(.*?)".*', val)[1]
136+
RFP_CLI_EXE = str(Path(match).parent / 'rfp-cli.exe')
137+
except Exception:
138+
RFP_CLI_EXE = 'rfp-cli.exe'
139+
else:
140+
RFP_CLI_EXE = 'rfp-cli'
141+
89142
def do_run(self, command, **kwargs):
90143
if command == 'flash':
144+
if self.rpd_file is not None:
145+
self.do_partition(**kwargs)
146+
91147
self.do_flash(**kwargs)
92148
else:
93149
self.logger.error("Unsuppported command")
94150

95151
def do_flash(self, **kwargs):
96-
self.ensure_output('hex')
97-
98-
hex_name = self.cfg.hex_file
99-
100-
self.logger.info(f'Flashing file: {hex_name}')
152+
self.require(self.rfp_cmd[0])
101153

154+
flash_file = None
102155
load_image = ['-run']
156+
103157
if self.erase:
104158
load_image += ['-erase']
105159
else:
@@ -108,13 +162,45 @@ def do_flash(self, **kwargs):
108162
if self.verify:
109163
load_image += ['-v']
110164

111-
# Load image
112-
load_image += ['-p', '-file', hex_name]
165+
if self.hex_name is not None and os.path.isfile(self.hex_name):
166+
flash_file = self.hex_name
167+
load_image += ['-file', flash_file]
168+
elif self.mot_name is not None and os.path.isfile(self.mot_name):
169+
flash_file = self.mot_name
170+
load_image += ['-file', flash_file]
171+
172+
elif self.elf_name is not None and os.path.isfile(self.elf_name):
173+
flash_file = self.elf_name
174+
load_image += ['-file', flash_file]
175+
elif self.bin_name is not None and os.path.isfile(self.bin_name):
176+
if self.dt_flash:
177+
flash_addr = self.flash_address_from_build_conf(self.build_conf)
178+
else:
179+
flash_addr = 0
180+
flash_file = self.bin_name
181+
load_image += ['-bin', f'0x{flash_addr:x}', flash_file]
182+
else:
183+
err = (
184+
"Cannot flash; no valid firmware file found.\n"
185+
f"Checked: user file ({self.file}), hex ({self.hex_name}), "
186+
f"mot ({self.mot_name}), bin ({self.bin_name}), elf ({self.elf_name})"
187+
)
188+
raise ValueError(err)
189+
190+
self.logger.info(f'Flashing file: {flash_file}')
191+
192+
if self.tool is None:
193+
connection = ['-port', self.port]
194+
else:
195+
connection = ['-tool', self.tool]
196+
197+
if self.interface:
198+
connection += ['-interface', self.interface]
113199

114-
port = ['-port', self.port]
115200
if self.speed:
116-
port += ['-s', self.speed]
201+
connection += ['-s', self.speed]
202+
117203
device = ['-device', self.device]
118204

119-
cmd = self.rfp_cmd + port + device + load_image
205+
cmd = self.rfp_cmd + connection + device + ['-p'] + load_image
120206
self.check_call(cmd)

0 commit comments

Comments
 (0)