Skip to content

Commit 2b40f17

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 e6a3798 commit 2b40f17

File tree

1 file changed

+80
-5
lines changed
  • scripts/west_commands/runners

1 file changed

+80
-5
lines changed

scripts/west_commands/runners/rfp.py

Lines changed: 80 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,9 @@ def __init__(
4144
erase=False,
4245
verify=False,
4346
port=DEFAULT_RFP_PORT,
47+
tool=None,
48+
interface=None,
49+
rpd_file=None,
4450
speed=None,
4551
):
4652
super().__init__(cfg)
@@ -49,7 +55,10 @@ def __init__(
4955
self.verify = verify
5056
self.erase = erase
5157
self.port = port
58+
self.tool = tool
59+
self.interface = interface
5260
self.device = device
61+
self.rpd_file = rpd_file
5362
self.speed = speed
5463

5564
@classmethod
@@ -62,14 +71,29 @@ def capabilities(cls):
6271

6372
@classmethod
6473
def do_add_parser(cls, parser):
74+
# Find the default efp-cli executable
75+
cls.default_rfp()
76+
6577
parser.add_argument(
66-
'--rfp-cli', default='rfp-cli', help='path to rfp-cli, default is rfp-cli'
78+
'--rfp-cli', default=RFP_CLI_EXE, help='path to rfp-cli, default is rfp-cli'
6779
)
6880
parser.add_argument(
6981
'--port',
7082
default=DEFAULT_RFP_PORT,
7183
help='serial port to use, default is ' + str(DEFAULT_RFP_PORT),
7284
)
85+
parser.add_argument(
86+
'--tool',
87+
help='emulator hardware to use (e2, e2l, jlink) when port is not set',
88+
)
89+
parser.add_argument(
90+
'--interface',
91+
help='selects the communications interface (uart, swd)',
92+
)
93+
parser.add_argument(
94+
'--rpd-file',
95+
help='path to renesas partition data zephyr.rpd',
96+
)
7397
parser.add_argument('--device', help='Specify the device type to pass to rfp-cli')
7498
parser.add_argument('--verify', action='store_true', help='if given, verify after flash')
7599
parser.add_argument('--speed', help='Specify the serial port speed')
@@ -81,18 +105,43 @@ def do_create(cls, cfg, args):
81105
rfp_cli=args.rfp_cli,
82106
device=args.device,
83107
port=args.port,
108+
tool=args.tool,
109+
interface=args.interface,
110+
rpd_file=args.rpd_file,
84111
erase=args.erase,
85112
speed=args.speed,
86113
verify=args.verify,
87114
)
88115

116+
@staticmethod
117+
def default_rfp():
118+
global RFP_CLI_EXE
119+
120+
if platform.system() == 'Windows':
121+
try:
122+
import winreg
123+
124+
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
125+
key = winreg.OpenKey(registry, r"SOFTWARE\Classes\rpjfile\shell\Open\command")
126+
val = winreg.QueryValue(key, None)
127+
match = re.match(r'"(.*?)".*', val)[1]
128+
RFP_CLI_EXE = str(Path(match).parent / 'rfp-cli.exe')
129+
except Exception:
130+
RFP_CLI_EXE = 'rfp-cli.exe'
131+
else:
132+
RFP_CLI_EXE = 'rfp-cli'
133+
89134
def do_run(self, command, **kwargs):
90135
if command == 'flash':
136+
if self.rpd_file is not None:
137+
self.do_partition(**kwargs)
138+
91139
self.do_flash(**kwargs)
92140
else:
93141
self.logger.error("Unsuppported command")
94142

95143
def do_flash(self, **kwargs):
144+
self.require(self.rfp_cmd[0])
96145
self.ensure_output('hex')
97146

98147
hex_name = self.cfg.hex_file
@@ -111,10 +160,36 @@ def do_flash(self, **kwargs):
111160
# Load image
112161
load_image += ['-p', '-file', hex_name]
113162

114-
port = ['-port', self.port]
163+
if self.tool is None:
164+
connection = ['-port', self.port]
165+
else:
166+
connection = ['-tool', self.tool]
167+
168+
if self.interface:
169+
connection += ['-interface', self.interface]
170+
115171
if self.speed:
116-
port += ['-s', self.speed]
172+
connection += ['-s', self.speed]
173+
174+
device = ['-device', self.device]
175+
176+
cmd = self.rfp_cmd + connection + device + load_image
177+
self.check_call(cmd)
178+
179+
def do_partition(self):
180+
self.require(self.rfp_cmd[0])
181+
182+
rpd_path = self.rpd_file
183+
184+
self.logger.info(f'Partition file: {rpd_path}')
185+
117186
device = ['-device', self.device]
118187

119-
cmd = self.rfp_cmd + port + device + load_image
188+
connection = ['-tool', self.tool]
189+
190+
flash_option = ['-fo']
191+
flash_option += ['boundary-file', rpd_path]
192+
flash_option += ['-p']
193+
194+
cmd = self.rfp_cmd + device + connection + flash_option
120195
self.check_call(cmd)

0 commit comments

Comments
 (0)