jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / contrib / xsvf_tools / xsvfdump.py
1 #!/usr/bin/python3.0
2 # SPDX-License-Identifier: GPL-2.0-or-later
3
4 # Copyright 2008, SoftPLC Corporation http://softplc.com
5 # Dick Hollenbeck dick@softplc.com
6
7 # Dump an Xilinx XSVF file to stdout
8
9 # This program is written for python 3.0, and it is not easy to change this
10 # back to 2.x. You may find it easier to use python 3.x even if that means
11 # building it.
12
13
14 import sys
15 import struct
16
17
18 LABEL = "A script to dump an XSVF file to stdout"
19
20
21 Xsdrsize = 0
22
23
24 (XCOMPLETE,XTDOMASK,XSIR,XSDR,XRUNTEST,hole0,hole1,XREPEAT,XSDRSIZE,XSDRTDO,
25 XSETSDRMASKS,XSDRINC,XSDRB,XSDRC,XSDRE,XSDRTDOB,XSDRTDOC,
26 XSDRTDOE,XSTATE,XENDIR,XENDDR,XSIR2,XCOMMENT,XWAIT,XWAITSTATE,
27 LCOUNT,LDELAY,LSDR,XTRST) = range(29)
28
29
30 (RESET,IDLE,
31 DRSELECT,DRCAPTURE,DRSHIFT,DREXIT1,DRPAUSE,DREXIT2,DRUPDATE,
32 IRSELECT,IRCAPTURE,IRSHIFT,IREXIT1,IRPAUSE,IREXIT2,IRUPDATE) = range(16)
33
34
35 State = ("RESET","IDLE",
36 "DRSELECT","DRCAPTURE","DRSHIFT","DREXIT1","DRPAUSE","DREXIT2","DRUPDATE",
37 "IRSELECT","IRCAPTURE","IRSHIFT","IREXIT1","IRPAUSE","IREXIT2","IRUPDATE")
38
39
40 trst_mode_allowed = ('ON', 'OFF', 'Z', 'ABSENT')
41
42
43 Setsdrmasks = 0
44 SetsdrmasksOnesCount = 0
45
46 def ReadSDRMASKS( f, len ):
47 global Setsdrmasks, SetsdrmasksOnesCount
48 byteCount = (len+7)//8
49 Setsdrmasks = f.read( byteCount )
50 ls = []
51 SetsdrmasksOnesCount = 0
52 for b in Setsdrmasks:
53 ls.append( "%x" % ((b & 0xf0) >> 4) )
54 ls.append( "%x" % ( b & 0x0f ) )
55 for i in range(8):
56 if b & (1<<i):
57 SetsdrmasksOnesCount = SetsdrmasksOnesCount +1
58 return ''.join(ls)
59
60
61 def bytes2hexString( f, len ):
62 byteCount = (len+7)//8
63 bytebuf = f.read( byteCount )
64 ls = []
65 for b in bytebuf:
66 ls.append( "%x" % ((b & 0xf0) >> 4) )
67 ls.append( "%x" % ( b & 0x0f ) )
68 return ''.join(ls)
69
70
71 def ReadByte( f ):
72 """Read a byte from a file and return it as an int in least significant 8 bits"""
73 b = f.read(1)
74 if b:
75 return 0xff & b[0];
76 else:
77 return -1
78
79
80 def ShowState( state ):
81 """return the given state int as a state string"""
82 #return "0x%02x" % state # comment this out to get textual state form
83 global State
84 if 0 <= state <= IRUPDATE:
85 return State[state]
86 else:
87 return "Unknown state 0x%02x" % state
88
89
90 def ShowOpcode( op, f ):
91 """return the given byte as an opcode string"""
92 global Xsdrsize
93 if op == XCOMPLETE:
94 print("XCOMPLETE")
95
96 elif op == XTDOMASK:
97 buf = bytes2hexString( f, Xsdrsize )
98 print("XTDOMASK 0x%s" % buf)
99
100 elif op == XSIR:
101 len = ReadByte( f )
102 buf = bytes2hexString( f, len )
103 print("XSIR 0x%02X 0x%s" % (len, buf))
104
105 elif op == XSDR:
106 tdi = bytes2hexString( f, Xsdrsize )
107 print("XSDR 0x%s" % tdi)
108
109 elif op == XRUNTEST:
110 len = struct.unpack( '>i', f.read(4) )[0]
111 print("XRUNTEST 0x%08X" % len)
112
113 elif op == XREPEAT:
114 len = ReadByte( f )
115 print("XREPEAT 0x%02X" % len)
116
117 elif op == XSDRSIZE:
118 Xsdrsize = struct.unpack( '>i', f.read(4) )[0]
119 #print("XSDRSIZE 0x%08X" % Xsdrsize, file=sys.stderr )
120 print("XSDRSIZE 0x%08X %d" % (Xsdrsize, Xsdrsize) )
121
122 elif op == XSDRTDO:
123 tdi = bytes2hexString( f, Xsdrsize )
124 tdo = bytes2hexString( f, Xsdrsize )
125 print("XSDRTDO 0x%s 0x%s" % (tdi, tdo) )
126
127 elif op == XSETSDRMASKS:
128 addrmask = bytes2hexString( f, Xsdrsize )
129 datamask = ReadSDRMASKS( f, Xsdrsize )
130 print("XSETSDRMASKS 0x%s 0x%s" % (addrmask, datamask) )
131
132 elif op == XSDRINC:
133 startaddr = bytes2hexString( f, Xsdrsize )
134 len = ReadByte(f)
135 print("XSDRINC 0x%s 0x%02X" % (startaddr, len), end='' )
136 for numTimes in range(len):
137 data = bytes2hexString( f, SetsdrmasksOnesCount)
138 print(" 0x%s" % data )
139 print() # newline
140
141 elif op == XSDRB:
142 tdi = bytes2hexString( f, Xsdrsize )
143 print("XSDRB 0x%s" % tdi )
144
145 elif op == XSDRC:
146 tdi = bytes2hexString( f, Xsdrsize )
147 print("XSDRC 0x%s" % tdi )
148
149 elif op == XSDRE:
150 tdi = bytes2hexString( f, Xsdrsize )
151 print("XSDRE 0x%s" % tdi )
152
153 elif op == XSDRTDOB:
154 tdo = bytes2hexString( f, Xsdrsize )
155 print("XSDRTDOB 0x%s" % tdo )
156
157 elif op == XSDRTDOC:
158 tdi = bytes2hexString( f, Xsdrsize )
159 tdo = bytes2hexString( f, Xsdrsize )
160 print("XSDRTDOC 0x%s 0x%s" % (tdi, tdo) )
161
162 elif op == XSDRTDOE:
163 tdi = bytes2hexString( f, Xsdrsize )
164 tdo = bytes2hexString( f, Xsdrsize )
165 print("XSDRTDOE 0x%s 0x%s" % (tdi, tdo) )
166
167 elif op == XSTATE:
168 b = ReadByte(f)
169 print("XSTATE %s" % ShowState(b))
170
171 elif op == XENDIR:
172 b = ReadByte( f )
173 print("XENDIR %s" % 'IRPAUSE' if b==1 else 'IDLE')
174
175 elif op == XENDDR:
176 b = ReadByte( f )
177 print("XENDDR %s" % 'DRPAUSE' if b==1 else 'IDLE')
178
179 elif op == XSIR2:
180 len = struct.unpack( '>H', f.read(2) )[0]
181 buf = bytes2hexString( f, len )
182 print("XSIR2 0x%04X 0x%s" % (len, buf))
183
184 elif op == XCOMMENT:
185 cmt = []
186 while 1:
187 b = ReadByte(f)
188 if b == 0: # terminating nul
189 break;
190 cmt.append( chr(b) )
191 print("XCOMMENT \"%s\"" % ''.join(cmt) )
192
193 elif op == XWAIT:
194 run_state = ReadByte(f)
195 end_state = ReadByte(f)
196 useconds = struct.unpack( '>i', f.read(4) )[0]
197 print("XWAIT %s %s" % (ShowState(run_state), ShowState(end_state)), useconds)
198
199 elif op == XWAITSTATE:
200 run_state = ReadByte(f)
201 end_state = ReadByte(f)
202 clocks = struct.unpack( '>i', f.read(4) )[0]
203 useconds = struct.unpack( '>i', f.read(4) )[0]
204 print("XWAITSTATE %s %s CLOCKS=%d USECS=%d" % (ShowState(run_state), ShowState(end_state), clocks, useconds) )
205
206 elif op == LCOUNT:
207 loop_count = struct.unpack( '>i', f.read(4) )[0]
208 print("LCOUNT", loop_count )
209
210 elif op == LDELAY:
211 run_state = ReadByte(f)
212 clocks = struct.unpack( '>i', f.read(4) )[0]
213 useconds = struct.unpack( '>i', f.read(4) )[0]
214 print("LDELAY %s CLOCKS=%d USECS=%d" % (ShowState(run_state), clocks, useconds) )
215
216 elif op == LSDR:
217 tdi = bytes2hexString( f, Xsdrsize )
218 tdo = bytes2hexString( f, Xsdrsize )
219 print("LSDR 0x%s 0x%s" % (tdi, tdo) )
220
221 elif op == XTRST:
222 # the argument is a single byte and it is the index into "trst_mode_allowed"
223 trst_mode = ReadByte(f)
224 if trst_mode <= 3:
225 print("TRST %s" % trst_mode_allowed[trst_mode] )
226 else:
227 print("TRST 0x%02X" % trst_mode );
228
229 else:
230 print("UNKNOWN op 0x%02X %d" % (op, op))
231 exit(1)
232
233
234 def main():
235
236 if len( sys.argv ) < 2:
237 print("usage %s <xsvf_filename>" % sys.argv[0])
238 exit(1)
239
240 f = open( sys.argv[1], 'rb' )
241
242 opcode = ReadByte( f )
243 while opcode != -1:
244 # print the position within the file, then the command
245 print( "%d: " % f.tell(), end='' )
246 ShowOpcode( opcode, f )
247 opcode = ReadByte(f)
248
249
250 if __name__ == "__main__":
251 main()

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)