6
6
7
7
'''Runner for rfp.'''
8
8
9
+ import os
9
10
import platform
10
11
import re
12
+ from pathlib import Path
11
13
12
14
from runners .core import RunnerCaps , ZephyrBinaryRunner
13
15
14
- if platform .system () == 'Darwin' :
16
+ if platform .system () in ( 'Darwin' , 'Windows' ) :
15
17
DEFAULT_RFP_PORT = None
16
18
else :
17
19
DEFAULT_RFP_PORT = '/dev/ttyACM0'
18
20
21
+ RFP_CLI_EXE = 'rfp-cli'
22
+
19
23
20
24
def to_num (number ):
21
25
dev_match = re .search (r"^\d*\+dev" , number )
@@ -41,15 +45,28 @@ def __init__(
41
45
erase = False ,
42
46
verify = False ,
43
47
port = DEFAULT_RFP_PORT ,
48
+ tool = None ,
49
+ interface = None ,
50
+ rpd_file = None ,
44
51
speed = None ,
52
+ dt_flash = True ,
45
53
):
46
54
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
48
62
self .rfp_cmd = [rfp_cli ]
49
63
self .verify = verify
50
64
self .erase = erase
51
65
self .port = port
66
+ self .tool = tool
67
+ self .interface = interface
52
68
self .device = device
69
+ self .rpd_file = rpd_file
53
70
self .speed = speed
54
71
55
72
@classmethod
@@ -62,14 +79,29 @@ def capabilities(cls):
62
79
63
80
@classmethod
64
81
def do_add_parser (cls , parser ):
82
+ # Find the default efp-cli executable
83
+ cls .default_rfp ()
84
+
65
85
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'
67
87
)
68
88
parser .add_argument (
69
89
'--port' ,
70
90
default = DEFAULT_RFP_PORT ,
71
91
help = 'serial port to use, default is ' + str (DEFAULT_RFP_PORT ),
72
92
)
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
+ )
73
105
parser .add_argument ('--device' , help = 'Specify the device type to pass to rfp-cli' )
74
106
parser .add_argument ('--verify' , action = 'store_true' , help = 'if given, verify after flash' )
75
107
parser .add_argument ('--speed' , help = 'Specify the serial port speed' )
@@ -81,25 +113,47 @@ def do_create(cls, cfg, args):
81
113
rfp_cli = args .rfp_cli ,
82
114
device = args .device ,
83
115
port = args .port ,
116
+ tool = args .tool ,
117
+ interface = args .interface ,
118
+ rpd_file = args .rpd_file ,
84
119
erase = args .erase ,
85
120
speed = args .speed ,
86
121
verify = args .verify ,
87
122
)
88
123
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
+
89
142
def do_run (self , command , ** kwargs ):
90
143
if command == 'flash' :
144
+ if self .rpd_file is not None :
145
+ self .do_partition (** kwargs )
146
+
91
147
self .do_flash (** kwargs )
92
148
else :
93
149
self .logger .error ("Unsuppported command" )
94
150
95
151
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 ])
101
153
154
+ flash_file = None
102
155
load_image = ['-run' ]
156
+
103
157
if self .erase :
104
158
load_image += ['-erase' ]
105
159
else :
@@ -108,13 +162,45 @@ def do_flash(self, **kwargs):
108
162
if self .verify :
109
163
load_image += ['-v' ]
110
164
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 ]
113
199
114
- port = ['-port' , self .port ]
115
200
if self .speed :
116
- port += ['-s' , self .speed ]
201
+ connection += ['-s' , self .speed ]
202
+
117
203
device = ['-device' , self .device ]
118
204
119
- cmd = self .rfp_cmd + port + device + load_image
205
+ cmd = self .rfp_cmd + connection + device + [ '-p' ] + load_image
120
206
self .check_call (cmd )
0 commit comments