-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaddebugbitstream.py
284 lines (252 loc) · 10.1 KB
/
readdebugbitstream.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
#!/usr/bin/env python3
import sys
import csv
from binascii import hexlify
#def getDevice(DeviceID):
# Devices = {
# 0x03722093: "XC7Z010",
# 0x03727093: "XC7Z020",
# 0x0484A093: "XCZU9EG",
# }
# return Devices.get(DeviceID, "")
def main(argv):
filename = argv[0]
fileCSV = ('devices.csv')
print filename
f = open(filename, 'r+')
f_csv = open(fileCSV, 'r+')
reader = csv.reader(f_csv)
Sync = 0
B1 = 0
B2 = 0
B3 = 0
B4 = 0
addr = 0
pre_addr = 0
row_addr = 0
pre_row_addr = 0
BA = 0 # Block type [25:23]
TB = 0 # Top/bottom bit [22]
RA = 0 # Row address [21:17]
MJA= 0 # Column address [16:7]
MNA= 0 # Minor address [6:0]
row_BA = 0 # Block type [25:23]
row_TB = 0 # Top/bottom bit [22]
row_RA = 0 # Row address [21:17]
NoOfFr = 0
NoOfFrPerRow = 0
pre_BA = BA
pre_TB = TB
pre_RA = RA
pre_MJA= MJA
pre_row_BA = row_BA
pre_row_TB = row_TB
pre_row_RA = row_RA
Device= ""
DevFa = ""
while True:
# for i in range(200):
B4 = B3
B3 = B2
B2 = B1
byte = f.read(1)
if byte == '':
break
byte = hexlify(byte)
B1 = int(byte, 16)
# print B4,B3,B2,B1
# print hex(B4),hex(B3),hex(B2),hex(B1)
if B4 == 0xaa and B3 == 0x99 and B2 == 0x55 and B1 == 0x66:
print "Sync Word!"
Sync = 1
break
if Sync == 1:
while True:
word = f.read(4)
if word == '':
break
word = int(hexlify(word), 16)
if word == 0x30018001:
word1 = f.read(4)
word1 = hexlify(word1)
# print word1
for row in reader:
if int(word1, 16) == int(row[0], 16):
Device = row[1]
# word1 = int(hexlify(word1), 16)
# Device= getDevice(word1)
if Device == "":
print "Device is not supported!"
break
else:
print "Found a device:",Device
DevFa = Device[2:4]
print "Device family:",DevFa
if word == 0x30002001:
# print "FAR register commands"
word = f.read(4)
word1 = f.read(4)
word2 = f.read(4)
word3 = f.read(4)
word = int(hexlify(word), 16)
word3 = int(hexlify(word3), 16)
if DevFa == "7Z":
BA = (word & 0x03800000) >> 23
TB = (word & 0x00400000) >> 22
RA = (word & 0x003E0000) >> 17
row_BA = (word & 0x03800000) >> 23
row_TB = (word & 0x00400000) >> 22
row_RA = (word & 0x003E0000) >> 17
MJA= (word & 0x0001FF80) >> 7
MNA= (word & 0x0000007F)
addr = (word & ~(0x0000007F))
row_addr = (word & ~(0x0001FFFF))
elif DevFa == "ZU" or DevFa == "VU":
BA = (word & 0x07000000) >> 24
RA = (word & 0x00FC0000) >> 18
row_BA = (word & 0x07000000) >> 24
row_RA = (word & 0x00FC0000) >> 18
MJA= (word & 0x0003FF00) >> 8
MNA= (word & 0x000000FF)
addr = (word & ~(0x000000FF))
row_addr = (word & ~(0x0003FFFF))
else:
BA = (word & 0x03800000) >> 23
TB = (word & 0x00400000) >> 22
RA = (word & 0x003E0000) >> 17
row_BA = (word & 0x03800000) >> 23
row_TB = (word & 0x00400000) >> 22
row_RA = (word & 0x003E0000) >> 17
MJA= (word & 0x0001FF80) >> 7
MNA= (word & 0x0000007F)
addr = (word & ~(0x0000007F))
row_addr = (word & ~(0x0001FFFF))
# check if that frame contains no configuration data
if pre_addr == addr:
NoOfFr = NoOfFr + 1
else:
if DevFa == "7Z":
print "address:",hex(pre_addr),"column BA:",pre_BA,"TB:",pre_TB,"RA:",pre_RA,"MJA:",pre_MJA,"has no. of frames:",NoOfFr
NoOfFr = 1
pre_BA = BA
pre_TB = TB
pre_RA = RA
pre_MJA= MJA
pre_addr = addr
elif DevFa == "ZU":
print "address:",hex(pre_addr),"column BA:",pre_BA,"RA:",pre_RA,"MJA:",pre_MJA,"has no. of frames:",NoOfFr
NoOfFr = 1
pre_BA = BA
pre_RA = RA
pre_MJA= MJA
pre_addr = addr
else:
print "address:",hex(pre_addr),"column BA:",pre_BA,"TB:",pre_TB,"RA:",pre_RA,"MJA:",pre_MJA,"has no. of frames:",NoOfFr
NoOfFr = 1
pre_BA = BA
pre_TB = TB
pre_RA = RA
pre_MJA= MJA
pre_addr = addr
# check if that frame contains no configuration data
if pre_row_addr == row_addr:
NoOfFrPerRow = NoOfFrPerRow + 1
else:
if DevFa == "7Z":
print "Row BA:",pre_row_BA,"TB:",pre_row_TB,"RA:",pre_row_RA,"has no. of frames:",NoOfFrPerRow
NoOfFrPerRow = 1
pre_row_BA = row_BA
pre_row_TB = row_TB
pre_row_RA = row_RA
pre_row_addr = row_addr
elif DevFa == "ZU":
print "Row BA:",pre_row_BA,"RA:",pre_row_RA,"has no. of frames:",NoOfFrPerRow
NoOfFrPerRow = 1
pre_row_BA = row_BA
pre_row_RA = row_RA
pre_row_addr = row_addr
else:
print "Row BA:",pre_row_BA,"TB:",pre_row_TB,"RA:",pre_row_RA,"has no. of frames:",NoOfFrPerRow
NoOfFrPerRow = 1
pre_row_BA = row_BA
pre_row_TB = row_TB
pre_row_RA = row_RA
pre_row_addr = row_addr
if word == 0x30010001 and DevFa == "6V":
word = f.read(4)
word1 = f.read(4)
word = int(hexlify(word), 16)
word1 = int(hexlify(word1), 16)
BA = (word & 0x00E00000) >> 21
TB = (word & 0x00100000) >> 20
RA = (word & 0x000F8000) >> 15
row_BA = (word & 0x00E00000) >> 21
row_TB = (word & 0x00100000) >> 20
row_RA = (word & 0x000F8000) >> 15
MJA= (word & 0x00007F80) >> 7
MNA= (word & 0x0000007F)
addr = (word & ~(0x0000007F))
row_addr = (word & ~(0x00007FFF))
# check if that frame contains no configuration data
if pre_addr == addr:
NoOfFr = NoOfFr + 1
else:
print "address:",hex(pre_addr),"column BA:",pre_BA,"TB:",pre_TB,"RA:",pre_RA,"MJA:",pre_MJA,"has no. of frames:",NoOfFr
NoOfFr = 1
pre_BA = BA
pre_TB = TB
pre_RA = RA
pre_MJA= MJA
pre_addr = addr
# check if that frame contains no configuration data
if pre_row_addr == row_addr:
NoOfFrPerRow = NoOfFrPerRow + 1
else:
print "Row BA:",pre_row_BA,"TB:",pre_row_TB,"RA:",pre_row_RA,"has no. of frames:",NoOfFrPerRow
NoOfFrPerRow = 1
pre_row_BA = row_BA
pre_row_TB = row_TB
pre_row_RA = row_RA
pre_row_addr = row_addr
if word == 0x30010001 and DevFa == "7V":
word = f.read(4)
word1 = f.read(4)
word = int(hexlify(word), 16)
word1 = int(hexlify(word1), 16)
BA = (word & 0x03800000) >> 23
TB = (word & 0x00400000) >> 22
RA = (word & 0x003E0000) >> 17
row_BA = (word & 0x03800000) >> 23
row_TB = (word & 0x00400000) >> 22
row_RA = (word & 0x003E0000) >> 17
MJA= (word & 0x0001FF80) >> 7
MNA= (word & 0x0000007F)
addr = (word & ~(0x0000007F))
row_addr = (word & ~(0x0001FFFF))
# check if that frame contains no configuration data
if pre_addr == addr:
NoOfFr = NoOfFr + 1
else:
print "address:",hex(pre_addr),"column BA:",pre_BA,"TB:",pre_TB,"RA:",pre_RA,"MJA:",pre_MJA,"has no. of frames:",NoOfFr
NoOfFr = 1
pre_BA = BA
pre_TB = TB
pre_RA = RA
pre_MJA= MJA
pre_addr = addr
# check if that frame contains no configuration data
if pre_row_addr == row_addr:
NoOfFrPerRow = NoOfFrPerRow + 1
else:
print "Row BA:",pre_row_BA,"TB:",pre_row_TB,"RA:",pre_row_RA,"has no. of frames:",NoOfFrPerRow
NoOfFrPerRow = 1
pre_row_BA = row_BA
pre_row_TB = row_TB
pre_row_RA = row_RA
pre_row_addr = row_addr
else:
print "Couldn't find the SYNC word - Invalid bitfile"
print "end of file!"
f.close()
if __name__ == "__main__":
main(sys.argv[1:])