-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify.py
executable file
·381 lines (295 loc) · 10.4 KB
/
verify.py
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#! /usr/bin/python3.5
################################################################################
# @Author: Corteggiani Nassim <Corteggiani> #
# @Email: [email protected] #
# @Filename: verify.py #
# @Last modified by: Corteggiani #
# @Last modified time: 21-Mar-2017 #
# @License: GPLv3 #
# #
# Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. #
# Copyright (C) 2017 Corteggiani Nassim <Corteggiani> #
# #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# #
################################################################################
import random
from itertools import combinations
import itertools
import subprocess
import os
import time
import binascii
import sys
import argparse
#TODO : the path should be passed as command-line argument !
# PATH = "/home/enoname/Tools/altera/13.1/modelsim_ase/linux"
PATH = ""
VERBOSE = 0
def LOG(lvl, category ,message):
if VERBOSE >= lvl :
if category != "":
print("["+category+"]\n\t"+message)
else:
print("\t"+message)
def set_inputs(input):
f = open(PATH+"/../bin/jtag_open_cores_test/input.txt", "w")
input = format(intput, 'x')
f.write(input+'\n')
f.close()
def read_outputs():
# f = open(PATH+"/../bin/jtag_open_cores_test/output.txt", "r")
f = open(PATH+"io/output.txt", "r")
lines = f.readlines()
f.close()
return lines
def verify(State_start, outputs):
fsm = jtag_fsm(State_start)
tms = -1;
tdi = -1;
i = 0;
for line in outputs:
for c in line:
if c == '0':
if i==0 or i%3==0 :
tms = 0
else:
tdi = 0
if c == '1':
if i==0 or i%3==0 :
tms = 1
else:
tdi = 1
if c == 'U':
if i==0 or i%3==0 :
tms = -1
else:
tdi = -1
i = i + 1
LOG(1,"JTAG_FSM", "TMS :"+str(tms)+" TDI :"+str(tdi))
fsm.run(tms, tdi)
LOG(0, "JTAG_FSM", "SHIFT DATA REGISTER : "+"{0:b}".format(fsm.shift_ir))
LOG(0, "JTAG_FSM", "SHIFT INTRUCTION REGISTER : "+"{0:b}".format(fsm.shift_dr))
return fsm
def start_simu():
err = None
out = None
pid = -1
LOG(0, "", "[Simulator]")
LOG(0, "", " starting...")
with open(os.devnull, "w") as fnull:
pipe = subprocess.Popen([PATH+"/vsim", "-c", "-do", "cd "+PATH+"/../bin/jtag_open_cores_test ; do sim.do; quit"], stdout=out, stderr=err)
LOG(0, "", " simulation in progress...")
time.sleep(1)
if err != None :
LOG(0, "ERROR", "Unable to run ModelSim : \n\n"+err)
exit(-1)
LOG(0, "", " simulation successfully done...")
LOG(0, "", " closing simulator...")
class jtag_fsm:
def __init__(self, checkpoint) :
self.TEST_LOGIC_RESET = 0
self.RUN_TEST_IDLE = 1
self.SELECT_DR_SCAN = 2
self.CAPTURE_DR = 3
self.SHIFT_DR = 4
self.EXIT1_DR = 5
self.PAUSE_DR = 6
self.EXIT2_DR = 7
self.UPDATE_DR = 8
self.SELECT_IR_SCAN = 9
self.CAPTURE_IR = 10
self.SHIFT_IR = 11
self.EXIT1_IR = 12
self.PAUSE_IR = 13
self.EXIT2_IR = 14
self.UPDATE_IR = 15
self.shift_dr = 0
self.shift_ir = 0
self.shift_dr_counter = 0
self.shift_ir_counter = 0
self.checkpoint = checkpoint
self.checkpoint_done = False
#JTAG Transitions Table
self.fsm = [
{'TEST_LOGIC_RESET': {'0': self.RUN_TEST_IDLE, '1': self.TEST_LOGIC_RESET}},
{'RUN_TEST_IDLE' : {'0': self.RUN_TEST_IDLE, '1': self.SELECT_DR_SCAN}},
{'SELECT_DR_SCAN' : {'0': self.CAPTURE_DR, '1': self.SELECT_IR_SCAN}},
{'CAPTURE_DR' : {'0': self.SHIFT_DR, '1': self.EXIT1_DR}},
{'SHIFT_DR' : {'0': self.SHIFT_DR, '1': self.EXIT1_DR}},
{'EXIT1_DR' : {'0': self.PAUSE_DR, '1': self.UPDATE_DR}},
{'PAUSE_DR' : {'0': self.PAUSE_DR, '1': self.EXIT2_DR}},
{'EXIT2_DR' : {'0': self.SHIFT_DR, '1': self.UPDATE_DR}},
{'UPDATE_DR' : {'0': self.RUN_TEST_IDLE, '1': self.SELECT_DR_SCAN}},
{'SELECT_IR_SCAN' : {'0': self.CAPTURE_IR, '1': self.TEST_LOGIC_RESET}},
{'CAPTURE_IR' : {'0': self.SHIFT_IR, '1': self.EXIT1_IR}},
{'SHIFT_IR' : {'0': self.SHIFT_IR, '1': self.EXIT1_IR}},
{'EXIT1_IR' : {'0': self.PAUSE_IR, '1': self.UPDATE_IR}},
{'PAUSE_IR' : {'0': self.PAUSE_IR, '1': self.EXIT2_IR}},
{'EXIT2_IR' : {'0': self.SHIFT_IR, '1': self.UPDATE_IR}},
{'UPDATE_IR' : {'0': self.RUN_TEST_IDLE, '1': self.SELECT_DR_SCAN}}
]
self.initial_state = self.TEST_LOGIC_RESET
self.current_state = -1
def run(self, tms, tdi):
if( self.current_state == -1 ):
self.current_state = self.initial_state
if self.checkpoint == self.current_state:
self.checkpoint_done = True
if self.current_state == self.SHIFT_IR:
self.shift_ir |= (tdi << self.shift_ir_counter)
self.shift_ir_counter += 1
if self.current_state == self.SHIFT_DR:
self.shift_dr += (tdi << self.shift_dr_counter)
self.shift_dr_counter += 1
# LOG(self.fsm[self.current_state])
key, value = next(iter(self.fsm[self.current_state].items()))
LOG(1, "JTAG_FSM", "Current state : "+key)
if tms == 0:
self.current_state = value['0']
elif tms == 1:
self.current_state = value['1']
else:
LOG(0, "JTAG_FSM", "unknown transition ...")
if self.current_state == self.UPDATE_DR:
LOG(0, "JTAG_FSM", "SHIFT DATA REGISTER : "+"{0:b}".format(self.shift_dr))
self.shift_dr_counter = 0
#self.shift_dr = 0
self.decode_shift()
if self.current_state == self.UPDATE_IR:
LOG(0, "JTAG_FSM", "SHIFT INTRUCTION REGISTER : "+"{0:b}".format(self.shift_ir))
self.shift_ir_counter = 0
#self.shift_ir = 0
def decode_shift(self):
RW = "Unknown"
OPCODE = "Unknown"
ADDR = "Unknown"
addr = (self.shift_dr >> 1) & 0x3
if self.shift_ir == 0xA:
OPCODE = "DPACC"
if addr == 1:
ADDR = "CSW_JTAG"
elif addr == 2:
ADDR = "SELECT_JTAG"
elif self.shift_ir == 0xB:
OPCODE = "APACC"
if addr == 3:
ADDR = "DRW_AHB_AP"
elif addr == 1:
ADDR = "TAR_AHB_AP"
elif addr == 0:
ADDR = "CSW_AHB_AP"
if (self.shift_dr & 1) == 1 :
RW = "READ"
else :
RW = "WRITE"
LOG(0, "", "RW : "+RW)
LOG(0, "", "ADDR : "+ADDR)
LOG(0, "", "DATA : "+hex(self.shift_dr >> 3))
LOG(0, "", "OPCODE : "+OPCODE)
LOG(0, "", "\n\n")
#self.shift_ir = 0
self.shift_dr = 0
def parse_args():
parser = argparse.ArgumentParser(description='Verify JTAG simulation outputs')
parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity (specify several times for more)")
parser.add_argument("--path", dest = "path", default = "", type = str, help = "Path to simmulation io directory")
#os.path.expanduser("")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse_args()
PATH = args.path
VERBOSE = args.verbose
LOG(0, "", "\************************************")
LOG(0, "", "* Internal Jtag Command Generator *")
LOG(0, "", "\************************************/")
start_states_dict = {
'SHIFT_DR': 4,
'SHIFT_IR': 0xB,
}
end_states_dict = {
'TEST_LOGIC_RESET': 0,
'RUN_TEST_IDLE': 1,
'SELECT_DR': 2,
'CAPTURE_DR': 3,
# 'SHIFT_DR': 4,
'EXIT1_DR': 5,
'PAUSE_DR': 6,
'EXIT2_DR': 7,
'UPDATE_DR': 8,
'SELECT_IR': 9,
'CAPTURE_IR': 0xA,
# 'SHIFT_IR': 0xB,
'EXIT1_IR': 0xC,
'PAUSE_IR': 0xD,
'EXIT2_IR': 0xE,
'UPDATE_IR': 0xF,
}
line = -1
# combi=[]
# for x in combinations(items,2):
# dic={z:items[z] for z in x}
# combi.append(dic)
# LOG(combi)
# for item in combi:
combi = itertools.product(start_states_dict, end_states_dict)
for item in combi:
State_start_name = item[0]
State_start = start_states_dict[State_start_name]
State_end_name = item[1]
State_end = end_states_dict[State_end_name]
Shift_register = 0
if(State_end==4 or State_end == 0xB):
Shift_count = random.randint(1, 35)
else:
Shift_count = 0
line = line + 1
intput = 0
intput = ((State_start & 0xF) << 44)
intput = intput | ((State_end & 0xF) << 40)
intput = intput | ((Shift_count & 0xFF) << 32)
if(State_end==4 or State_end == 0xB):
intput = intput | (0xABABABAB >> (32-Shift_count) )
Shift_register = (0xABABABAB >> (32-Shift_count) )
LOG(0, "", "-------------------")
LOG(0, "", "Start State : "+State_start_name)
LOG(0, "", "End State : "+State_end_name)
LOG(0, "", "Shift Count : "+str(Shift_count))
LOG(0, "", "Line : "+str(line))
LOG(0, "", "Output : "+hex(intput))
LOG(0, "", "-------------------")
# set_inputs(intput)
# start_simu()
outputs = read_outputs()
fsm = verify(State_start, outputs)
error = False
# if fsm.current_state != State_end:
# LOG("[ERROR]\n\tFinal state differs from Oracle")
# LOG("\n\tExpected : "+str(State_end_name))
# key, value = fsm.fsm[fsm.current_state].popitem()
# LOG("\n\tResult : "+key)
# error = True
#
# if Shift_count > 0 :
# if fsm.shift_ir != Shift_register:
# if fsm.shift_dr != Shift_register:
# LOG("[ERROR]\n\tShift register value differs from Oracle")
# error = True
#
# if error == True:
# exit(0)
key, value = fsm.fsm[fsm.current_state].popitem()
LOG(0, "Test Done", "Expected "+key+" got "+State_end_name)
exit(0)