-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path!make_programFlash.vbs
307 lines (284 loc) · 10.6 KB
/
!make_programFlash.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
'-----------------------------------------------------
' Constants:
'-----------------------------------------------------
Const formatIntelHex = 0
Const formatBinary = 1
Const formatASCII = 2
Const eraseAffected = 0
Const eraseAll = 1
Const eraseNone = 2
'-----------------------------------------------------
' Text format variables:
'-----------------------------------------------------
Dim NL
Dim TB
Dim TB2
Dim TB3
NL = vbNewLine
TB = vbTab
TB2 = TB+TB
TB3 = TB+TB+TB
usage = "cscript.exe --driver <driver file> [OPTIONS]"+NL+_
"REQUIRED:"+NL+_
NL+_
"--driver <driver file>"+TB+_
": specifies <driver file> for communication with the flash device"+NL+_
NL+_
"OPTIONS: "+NL+_
"--image <image file>"+TB+_
": specifies <image file> for loading into flash"+NL+_
"--offsetL [addr]"+TB+_
": address offset to use when executing image file load (default is 0x0)"+NL+_
"--format"+TB2+_
": format of the image file; 0 - Intel Hex (default), 1 - binary, 2 - ASCII"+NL+_
"--verifyWrites"+TB2+_
": verify write operations during the image file load (default is false)"+NL+_
"--eraseOption"+TB2+_
": option to clear the flash area where the image load is occurring;"+NL+_
TB3+_
" 0 - erase affected (default), 1 - erase all, 2 - erase none"+NL+_
"--fill"+TB3+_
": fill flash with values"+NL+_
"--boot"+TB3+_
": boot up the hardware board with the image in flash"+NL+_
"--offsetF [addr]"+TB+_
": address offset to use when executing fill (default is 0x0)"+NL+_
"--count [n]"+TB2+_
": number of values to write during fill operation (default is 16)"+NL+_
"--stride [s]"+TB2+_
": offset of the next write during fill operation (default is 1)"+NL+_
"--value [val]"+TB2+_
": value to be written into flash during fill (default is 0x0)"+NL+_
"--eraseAll"+TB2+_
": erase entire flash"+NL+_
"--eraseBlocks [0,1,..]"+TB+_
": erase specified sectors of flash (comma-separated list with no spaces);"+NL+_
TB3+_
" if sector list is ommitted, the default is 0,1,2,3"+NL
'-----------------------------------------------------
' Helper variables:
'-----------------------------------------------------
Dim index
'-----------------------------------------------------
' Options:
'-----------------------------------------------------
Dim doLoadImage
Dim doVerifyWrites
Dim doEraseAll
Dim doEraseBlocks
Dim doLoadDriver
Dim doFill
Dim doBoot
'-----------------------------------------------------
' Values:
'-----------------------------------------------------
Dim fpDriver
Dim LdrImage
Dim LdrImage2
Dim blocks
Dim eraseOption
Dim imageFormat
Dim imageOffset
Dim fillOffset
Dim fillCount
Dim fillStride
Dim fillValue
'-----------------------------------------------------
' Initial values for script variables and options:
'-----------------------------------------------------
doLoadImage = False
doVerifyWrites = False
doEraseAll = False
doEraseBlocks = False
doLoadDriver = False
doVerifyWrites = False
doBoot = False
blocks = Array ( 0, 1, 2, 3 )
eraseOption = eraseAffected
imageFormat = formatIntelHex
imageOffset = 0
fillOffset = 0
fillCount = 16
fillStride = 1
fillValue = 0
index = 0
'-----------------------------------------------------
' Check script usage:
'-----------------------------------------------------
If ( WScript.arguments.Count = 0 ) Then
displayUsage
WScript.Quit ( 0 )
End If
'-----------------------------------------------------
' Process user selected command line options:
'-----------------------------------------------------
For Each arg in WScript.arguments
If ( StrComp ( arg, "--driver" ) = 0 ) Then
doLoadDriver = True
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
fpDriver = WScript.arguments ( index + 1 )
End If
ElseIf ( StrComp ( arg, "--image" ) = 0 ) Then
doLoadImage = True
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
LdrImage = WScript.arguments ( index + 1 )
End If
ElseIf ( StrComp ( arg, "--fill" ) = 0 ) Then
doFill = True
ElseIf ( StrComp ( arg, "--boot" ) = 0 ) Then
doBoot = True
ElseIf ( StrComp ( arg, "--verifyWrites" ) = 0 ) Then
doVerifyWrites = True
ElseIf ( StrComp ( arg, "--eraseAll" ) = 0 ) Then
doEraseAll = True
ElseIf ( StrComp ( arg, "--eraseBlocks" ) = 0 ) Then
doEraseBlocks = True
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
blocks = Split ( WScript.arguments ( index + 1 ), "," )
End If
ElseIf ( StrComp ( arg, "--eraseOption" ) = 0 ) Then
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
eraseOption = Eval ( temp )
End If
ElseIf ( StrComp ( arg, "--format" ) = 0 ) Then
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
imageFormat = Eval ( temp )
End If
ElseIf ( StrComp ( arg, "--offsetL" ) = 0 ) Then
doImageOffset = True
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
imageOffset = Eval ( temp )
End If
ElseIf ( StrComp ( arg, "--offsetF" ) = 0 ) Then
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
fillOffset = Eval ( temp )
End If
ElseIf ( StrComp ( arg, "--count" ) = 0 ) Then
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
fillCount = Eval ( temp )
End If
ElseIf ( StrComp ( arg, "--stride" ) = 0 ) Then
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
fillStride = Eval ( temp )
End If
ElseIf ( StrComp ( arg, "--value" ) = 0 ) Then
If ( ( index + 1 ) <= WScript.arguments.Count ) Then
temp = WScript.arguments ( index + 1 )
temp = Replace ( temp, "0x", "&h" )
fillValue = Eval ( temp )
End If
End If
index = index + 1
Next
'-----------------------------------------------------
' Print user selected options (for debugging the
' script itself):
'-----------------------------------------------------
Sub checkArgs ( )
WScript.StdOut.WriteLine "FPDriver: " + FPDriver
WScript.StdOut.WriteLine "LdrImage: " + LdrImage
WScript.StdOut.WriteLine "doEraseBlocks: " + CStr ( doEraseBlocks )
WScript.StdOut.WriteLine "doEraseAll: " + CStr ( doEraseAll )
WScript.StdOut.WriteLine "doLoadImage: " + CStr ( doLoadImage )
WScript.StdOut.WriteLine "doVerifyWrites: " + CStr ( doVerifyWrites )
WScript.StdOut.WriteLine "doBoot: " + CStr ( doBoot )
WScript.StdOut.WriteLine "eraseOption: " + CStr ( eraseOption )
WScript.StdOut.WriteLine "imageFormat: " + CStr ( imageFormat )
WScript.StdOut.WriteLine "imageOffset: " + CStr ( imageOffset )
WScript.StdOut.WriteLine "fillOffset: " + CStr ( fillOffset )
WScript.StdOut.WriteLine "fillCount: " + CStr ( fillCount )
WScript.StdOut.WriteLine "fillStride: " + CStr ( fillStride )
WScript.StdOut.WriteLine "fillValue: " + "0x" + Hex ( fillValue )
WScript.StdOut.Write "eraseBlocks: "
For i = 0 to UBound ( blocks )
WScript.StdOut.Write CStr ( blocks(i) ) + " "
Next
WScript.StdOut.WriteLine ""
End Sub
'-----------------------------------------------------
' Print out script usage:
'-----------------------------------------------------
Sub displayUsage ( )
WScript.StdOut.Write usage
End Sub
'-----------------------------------------------------
' Connect to the Idde object via COM and initialize
' some settings:
'-----------------------------------------------------
Set app = CreateObject( "VisualDSP.ADspApplication" )
app.Interactive = True
app.Visible = True
Set session = app.CreateSession( "flashingsession", "Blackfin Emulators/EZ-KIT Lites", "ADSP-BF504F via ICE-100B", "ADSP-BF504F" )
If (session Is Nothing) Then
app.PrintText tabConsole, "CreateSession failed"
WScript.Quit ( 0 )
End If
'-----------------------------------------------------
' Retrieve a reference to the Flash Programmer plug-in
' object:
'-----------------------------------------------------
WScript.StdOut.WriteLine "Starting the FlashProgrammer plugin..."
Set FPPlugin = app.PluginList.Item("Flash Programmer")
Set FlashProgrammer = FPPlugin.Open()
'-----------------------------------------------------
' Load the flash driver:
'-----------------------------------------------------
WScript.StdOut.WriteLine "Loading the FP driver..."
FlashProgrammer.LoadDriver FPDriver
'-----------------------------------------------------
' First, perform all user selected erase options:
'-----------------------------------------------------
If ( doEraseAll = True ) Then
WScript.StdOut.WriteLine "Erasing all flash..."
FlashProgrammer.EraseAll()
ElseIf ( doEraseBlocks = True ) Then
WScript.StdOut.WriteLine "Erasing Flash blocks..."
For i = 0 To UBound ( blocks )
strBlock = blocks(i)
WScript.StdOut.WriteLine "Erasing block " + strBlock + "..."
FlashProgrammer.EraseBlock CInt ( strBlock )
Next
End If
'-----------------------------------------------------
' Do any user chosen flash fills:
'-----------------------------------------------------
If ( doFill = True ) Then
If ( fillCount < 0 ) Then
fillCount = 16
End If
WScript.StdOut.WriteLine "Filling flash: count " + CStr ( fillCount ) + "..."
FlashProgrammer.FillFlash fillOffset, fillCount, fillStride, fillValue
End If
'-----------------------------------------------------
' Load the user specified image file:
'-----------------------------------------------------
If ( doLoadImage = True ) Then
WScript.StdOut.WriteLine "Programming Flash with the image File..."
FlashProgrammer.LoadFile LdrImage, imageFormat, doVerify, eraseOption, imageOffset
End If
'-----------------------------------------------------
' Boot up the target board if user has selected this
' option:
'-----------------------------------------------------
If ( doBoot = True ) Then
WScript.StdOut.WriteLine "Booting up the board from flash..."
While ( app.ActiveSession.ActiveProcessor.BreakpointList.Count > 0 ):
app.ActiveSession.ActiveProcessor.BreakpointList.RemoveBreakpointByIndex( 0 )
WEnd
session.ProcessorList(0).Reset(True)
session.ProcessorList(0).Run(False)
End If
WScript.StdOut.WriteLine "All done!"
app.DisconnectSession