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,8 @@ def __init__(
41
44
erase = False ,
42
45
verify = False ,
43
46
port = DEFAULT_RFP_PORT ,
47
+ tool = None ,
48
+ interface = None ,
44
49
speed = None ,
45
50
):
46
51
super ().__init__ (cfg )
@@ -49,6 +54,8 @@ def __init__(
49
54
self .verify = verify
50
55
self .erase = erase
51
56
self .port = port
57
+ self .tool = tool
58
+ self .interface = interface
52
59
self .device = device
53
60
self .speed = speed
54
61
@@ -62,14 +69,25 @@ def capabilities(cls):
62
69
63
70
@classmethod
64
71
def do_add_parser (cls , parser ):
72
+ # Find the default efp-cli executable
73
+ cls .default_rfp ()
74
+
65
75
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'
67
77
)
68
78
parser .add_argument (
69
79
'--port' ,
70
80
default = DEFAULT_RFP_PORT ,
71
81
help = 'serial port to use, default is ' + str (DEFAULT_RFP_PORT ),
72
82
)
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
+ )
73
91
parser .add_argument ('--device' , help = 'Specify the device type to pass to rfp-cli' )
74
92
parser .add_argument ('--verify' , action = 'store_true' , help = 'if given, verify after flash' )
75
93
parser .add_argument ('--speed' , help = 'Specify the serial port speed' )
@@ -81,18 +99,39 @@ def do_create(cls, cfg, args):
81
99
rfp_cli = args .rfp_cli ,
82
100
device = args .device ,
83
101
port = args .port ,
102
+ tool = args .tool ,
103
+ interface = args .interface ,
84
104
erase = args .erase ,
85
105
speed = args .speed ,
86
106
verify = args .verify ,
87
107
)
88
108
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
+
89
127
def do_run (self , command , ** kwargs ):
90
128
if command == 'flash' :
91
129
self .do_flash (** kwargs )
92
130
else :
93
131
self .logger .error ("Unsuppported command" )
94
132
95
133
def do_flash (self , ** kwargs ):
134
+ self .require (self .rfp_cmd [0 ])
96
135
self .ensure_output ('hex' )
97
136
98
137
hex_name = self .cfg .hex_file
@@ -111,10 +150,18 @@ def do_flash(self, **kwargs):
111
150
# Load image
112
151
load_image += ['-p' , '-file' , hex_name ]
113
152
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
+
115
161
if self .speed :
116
- port += ['-s' , self .speed ]
162
+ connection += ['-s' , self .speed ]
163
+
117
164
device = ['-device' , self .device ]
118
165
119
- cmd = self .rfp_cmd + port + device + load_image
166
+ cmd = self .rfp_cmd + connection + device + load_image
120
167
self .check_call (cmd )
0 commit comments