8
8
9
9
import platform
10
10
import re
11
+ from pathlib import Path
11
12
12
13
from runners .core import RunnerCaps , ZephyrBinaryRunner
13
14
14
- if platform .system () == 'Darwin' :
15
+ if platform .system () == 'Darwin' or 'Windows' :
15
16
DEFAULT_RFP_PORT = None
16
17
else :
17
18
DEFAULT_RFP_PORT = '/dev/ttyACM0'
18
19
20
+ RFP_CLI_EXE = 'rfp-cli'
21
+
19
22
20
23
def to_num (number ):
21
24
dev_match = re .search (r"^\d*\+dev" , number )
@@ -41,6 +44,9 @@ def __init__(
41
44
erase = False ,
42
45
verify = False ,
43
46
port = DEFAULT_RFP_PORT ,
47
+ tool = None ,
48
+ interface = None ,
49
+ rpd_file = None ,
44
50
speed = None ,
45
51
):
46
52
super ().__init__ (cfg )
@@ -49,7 +55,10 @@ def __init__(
49
55
self .verify = verify
50
56
self .erase = erase
51
57
self .port = port
58
+ self .tool = tool
59
+ self .interface = interface
52
60
self .device = device
61
+ self .rpd_file = rpd_file
53
62
self .speed = speed
54
63
55
64
@classmethod
@@ -62,14 +71,29 @@ def capabilities(cls):
62
71
63
72
@classmethod
64
73
def do_add_parser (cls , parser ):
74
+ # Find the default efp-cli executable
75
+ cls .default_rfp ()
76
+
65
77
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'
67
79
)
68
80
parser .add_argument (
69
81
'--port' ,
70
82
default = DEFAULT_RFP_PORT ,
71
83
help = 'serial port to use, default is ' + str (DEFAULT_RFP_PORT ),
72
84
)
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
+ )
73
97
parser .add_argument ('--device' , help = 'Specify the device type to pass to rfp-cli' )
74
98
parser .add_argument ('--verify' , action = 'store_true' , help = 'if given, verify after flash' )
75
99
parser .add_argument ('--speed' , help = 'Specify the serial port speed' )
@@ -81,18 +105,43 @@ def do_create(cls, cfg, args):
81
105
rfp_cli = args .rfp_cli ,
82
106
device = args .device ,
83
107
port = args .port ,
108
+ tool = args .tool ,
109
+ interface = args .interface ,
110
+ rpd_file = args .rpd_file ,
84
111
erase = args .erase ,
85
112
speed = args .speed ,
86
113
verify = args .verify ,
87
114
)
88
115
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
+
89
134
def do_run (self , command , ** kwargs ):
90
135
if command == 'flash' :
136
+ if self .rpd_file is not None :
137
+ self .do_partition (** kwargs )
138
+
91
139
self .do_flash (** kwargs )
92
140
else :
93
141
self .logger .error ("Unsuppported command" )
94
142
95
143
def do_flash (self , ** kwargs ):
144
+ self .require (self .rfp_cmd [0 ])
96
145
self .ensure_output ('hex' )
97
146
98
147
hex_name = self .cfg .hex_file
@@ -111,10 +160,36 @@ def do_flash(self, **kwargs):
111
160
# Load image
112
161
load_image += ['-p' , '-file' , hex_name ]
113
162
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
+
115
171
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
+
117
186
device = ['-device' , self .device ]
118
187
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
120
195
self .check_call (cmd )
0 commit comments