Dick Hollenbeck <dick@softplc.com> SVF to XSVF converter and the XSVF dumper take #2
git-svn-id: svn://svn.berlios.de/openocd/trunk@1304 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
78d990e678
commit
1f9b15867a
File diff suppressed because it is too large
Load Diff
|
@ -1,255 +1,255 @@
|
||||||
#!/usr/bin/python3.0
|
#!/usr/bin/python3.0
|
||||||
|
|
||||||
# Copyright 2008, SoftPLC Corporation http://softplc.com
|
# Copyright 2008, SoftPLC Corporation http://softplc.com
|
||||||
# Dick Hollenbeck dick@softplc.com
|
# Dick Hollenbeck dick@softplc.com
|
||||||
|
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, you may find one here:
|
# along with this program; if not, you may find one here:
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
# or you may search the http://www.gnu.org website for the version 2 license,
|
# or you may search the http://www.gnu.org website for the version 2 license,
|
||||||
# or you may write to the Free Software Foundation, Inc.,
|
# or you may write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
|
||||||
# Dump an Xilinx XSVF file to stdout
|
# Dump an Xilinx XSVF file to stdout
|
||||||
|
|
||||||
# This program is written for python 3.0, and it is not easy to change this
|
# This program is written for python 3.0, and it is not easy to change this
|
||||||
# back to 2.x. You may find it easier to use python 3.x even if that means
|
# back to 2.x. You may find it easier to use python 3.x even if that means
|
||||||
# building it.
|
# building it.
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
|
||||||
LABEL = "A script to dump an XSVF file to stdout"
|
LABEL = "A script to dump an XSVF file to stdout"
|
||||||
|
|
||||||
|
|
||||||
Xsdrsize = 0
|
Xsdrsize = 0
|
||||||
|
|
||||||
|
|
||||||
(XCOMPLETE,XTDOMASK,XSIR,XSDR,XRUNTEST,hole0,hole1,XREPEAT,XSDRSIZE,XSDRTDO,
|
(XCOMPLETE,XTDOMASK,XSIR,XSDR,XRUNTEST,hole0,hole1,XREPEAT,XSDRSIZE,XSDRTDO,
|
||||||
XSETSDRMASKS,XSDRINC,XSDRB,XSDRC,XSDRE,XSDRTDOB,XSDRTDOC,
|
XSETSDRMASKS,XSDRINC,XSDRB,XSDRC,XSDRE,XSDRTDOB,XSDRTDOC,
|
||||||
XSDRTDOE,XSTATE,XENDIR,XENDDR,XSIR2,XCOMMENT,XWAIT,XWAITSTATE,LCOUNT,LDELAY,LSDR) = range(28)
|
XSDRTDOE,XSTATE,XENDIR,XENDDR,XSIR2,XCOMMENT,XWAIT,XWAITSTATE,LCOUNT,LDELAY,LSDR) = range(28)
|
||||||
|
|
||||||
|
|
||||||
(RESET,IDLE,
|
(RESET,IDLE,
|
||||||
DRSELECT,DRCAPTURE,DRSHIFT,DREXIT1,DRPAUSE,DREXIT2,DRUPDATE,
|
DRSELECT,DRCAPTURE,DRSHIFT,DREXIT1,DRPAUSE,DREXIT2,DRUPDATE,
|
||||||
IRSELECT,IRCAPTURE,IRSHIFT,IREXIT1,IRPAUSE,IREXIT2,IRUPDATE) = range(16)
|
IRSELECT,IRCAPTURE,IRSHIFT,IREXIT1,IRPAUSE,IREXIT2,IRUPDATE) = range(16)
|
||||||
|
|
||||||
|
|
||||||
State = ("RESET","IDLE",
|
State = ("RESET","IDLE",
|
||||||
"DRSELECT","DRCAPTURE","DRSHIFT","DREXIT1","DRPAUSE","DREXIT2","DRUPDATE",
|
"DRSELECT","DRCAPTURE","DRSHIFT","DREXIT1","DRPAUSE","DREXIT2","DRUPDATE",
|
||||||
"IRSELECT","IRCAPTURE","IRSHIFT","IREXIT1","IRPAUSE","IREXIT2","IRUPDATE")
|
"IRSELECT","IRCAPTURE","IRSHIFT","IREXIT1","IRPAUSE","IREXIT2","IRUPDATE")
|
||||||
|
|
||||||
Setsdrmasks = 0
|
Setsdrmasks = 0
|
||||||
SetsdrmasksOnesCount = 0
|
SetsdrmasksOnesCount = 0
|
||||||
|
|
||||||
def ReadSDRMASKS( f, len ):
|
def ReadSDRMASKS( f, len ):
|
||||||
global Setsdrmasks, SetsdrmasksOnesCount
|
global Setsdrmasks, SetsdrmasksOnesCount
|
||||||
byteCount = (len+7)//8
|
byteCount = (len+7)//8
|
||||||
Setsdrmasks = f.read( byteCount )
|
Setsdrmasks = f.read( byteCount )
|
||||||
ls = []
|
ls = []
|
||||||
SetsdrmasksOnesCount = 0
|
SetsdrmasksOnesCount = 0
|
||||||
for b in Setsdrmasks:
|
for b in Setsdrmasks:
|
||||||
ls.append( "%x" % ((b & 0xf0) >> 4) )
|
ls.append( "%x" % ((b & 0xf0) >> 4) )
|
||||||
ls.append( "%x" % ( b & 0x0f ) )
|
ls.append( "%x" % ( b & 0x0f ) )
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
if b & (1<<i):
|
if b & (1<<i):
|
||||||
SetsdrmasksOnesCount = SetsdrmasksOnesCount +1
|
SetsdrmasksOnesCount = SetsdrmasksOnesCount +1
|
||||||
return ''.join(ls)
|
return ''.join(ls)
|
||||||
|
|
||||||
|
|
||||||
def bytes2hexString( f, len ):
|
def bytes2hexString( f, len ):
|
||||||
byteCount = (len+7)//8
|
byteCount = (len+7)//8
|
||||||
bytebuf = f.read( byteCount )
|
bytebuf = f.read( byteCount )
|
||||||
ls = []
|
ls = []
|
||||||
for b in bytebuf:
|
for b in bytebuf:
|
||||||
ls.append( "%x" % ((b & 0xf0) >> 4) )
|
ls.append( "%x" % ((b & 0xf0) >> 4) )
|
||||||
ls.append( "%x" % ( b & 0x0f ) )
|
ls.append( "%x" % ( b & 0x0f ) )
|
||||||
return ''.join(ls)
|
return ''.join(ls)
|
||||||
|
|
||||||
|
|
||||||
def ReadByte( f ):
|
def ReadByte( f ):
|
||||||
"""Read a byte from a file and return it as an int in least significant 8 bits"""
|
"""Read a byte from a file and return it as an int in least significant 8 bits"""
|
||||||
b = f.read(1)
|
b = f.read(1)
|
||||||
if b:
|
if b:
|
||||||
return 0xff & b[0];
|
return 0xff & b[0];
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def ShowState( state ):
|
def ShowState( state ):
|
||||||
"""return the given state int as a state string"""
|
"""return the given state int as a state string"""
|
||||||
#return "0x%02x" % state # comment this out to get textual state form
|
#return "0x%02x" % state # comment this out to get textual state form
|
||||||
global State
|
global State
|
||||||
if 0 <= state <= IRUPDATE:
|
if 0 <= state <= IRUPDATE:
|
||||||
return State[state]
|
return State[state]
|
||||||
else:
|
else:
|
||||||
return "Unknown state 0x%02x" % state
|
return "Unknown state 0x%02x" % state
|
||||||
|
|
||||||
|
|
||||||
def ShowOpcode( op, f ):
|
def ShowOpcode( op, f ):
|
||||||
"""return the given byte as an opcode string"""
|
"""return the given byte as an opcode string"""
|
||||||
global Xsdrsize
|
global Xsdrsize
|
||||||
if op == XCOMPLETE:
|
if op == XCOMPLETE:
|
||||||
print("XCOMPLETE")
|
print("XCOMPLETE")
|
||||||
|
|
||||||
elif op == XTDOMASK:
|
elif op == XTDOMASK:
|
||||||
buf = bytes2hexString( f, Xsdrsize )
|
buf = bytes2hexString( f, Xsdrsize )
|
||||||
print("XTDOMASK 0x%s" % buf)
|
print("XTDOMASK 0x%s" % buf)
|
||||||
|
|
||||||
elif op == XSIR:
|
elif op == XSIR:
|
||||||
len = ReadByte( f )
|
len = ReadByte( f )
|
||||||
buf = bytes2hexString( f, len )
|
buf = bytes2hexString( f, len )
|
||||||
print("XSIR 0x%02X 0x%s" % (len, buf))
|
print("XSIR 0x%02X 0x%s" % (len, buf))
|
||||||
|
|
||||||
elif op == XSDR:
|
elif op == XSDR:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDR 0x%s" % tdi)
|
print("XSDR 0x%s" % tdi)
|
||||||
|
|
||||||
elif op == XRUNTEST:
|
elif op == XRUNTEST:
|
||||||
len = struct.unpack( '>i', f.read(4) )[0]
|
len = struct.unpack( '>i', f.read(4) )[0]
|
||||||
print("XRUNTEST 0x%08X" % len)
|
print("XRUNTEST 0x%08X" % len)
|
||||||
|
|
||||||
elif op == XREPEAT:
|
elif op == XREPEAT:
|
||||||
len = ReadByte( f )
|
len = ReadByte( f )
|
||||||
print("XREPEAT 0x%02X" % len)
|
print("XREPEAT 0x%02X" % len)
|
||||||
|
|
||||||
elif op == XSDRSIZE:
|
elif op == XSDRSIZE:
|
||||||
Xsdrsize = struct.unpack( '>i', f.read(4) )[0]
|
Xsdrsize = struct.unpack( '>i', f.read(4) )[0]
|
||||||
#print("XSDRSIZE 0x%08X" % Xsdrsize, file=sys.stderr )
|
#print("XSDRSIZE 0x%08X" % Xsdrsize, file=sys.stderr )
|
||||||
print("XSDRSIZE 0x%08X %d" % (Xsdrsize, Xsdrsize) )
|
print("XSDRSIZE 0x%08X %d" % (Xsdrsize, Xsdrsize) )
|
||||||
|
|
||||||
elif op == XSDRTDO:
|
elif op == XSDRTDO:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
tdo = bytes2hexString( f, Xsdrsize )
|
tdo = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRTDO 0x%s 0x%s" % (tdi, tdo) )
|
print("XSDRTDO 0x%s 0x%s" % (tdi, tdo) )
|
||||||
|
|
||||||
elif op == XSETSDRMASKS:
|
elif op == XSETSDRMASKS:
|
||||||
addrmask = bytes2hexString( f, Xsdrsize )
|
addrmask = bytes2hexString( f, Xsdrsize )
|
||||||
datamask = ReadSDRMASKS( f, Xsdrsize )
|
datamask = ReadSDRMASKS( f, Xsdrsize )
|
||||||
print("XSETSDRMASKS 0x%s 0x%s" % (addrmask, datamask) )
|
print("XSETSDRMASKS 0x%s 0x%s" % (addrmask, datamask) )
|
||||||
|
|
||||||
elif op == XSDRINC:
|
elif op == XSDRINC:
|
||||||
startaddr = bytes2hexString( f, Xsdrsize )
|
startaddr = bytes2hexString( f, Xsdrsize )
|
||||||
len = ReadByte(f)
|
len = ReadByte(f)
|
||||||
print("XSDRINC 0x%s 0x%02X" % (startaddr, len), end='' )
|
print("XSDRINC 0x%s 0x%02X" % (startaddr, len), end='' )
|
||||||
for numTimes in range(len):
|
for numTimes in range(len):
|
||||||
data = bytes2hexString( f, SetsdrmasksOnesCount)
|
data = bytes2hexString( f, SetsdrmasksOnesCount)
|
||||||
print(" 0x%s" % data )
|
print(" 0x%s" % data )
|
||||||
print() # newline
|
print() # newline
|
||||||
|
|
||||||
elif op == XSDRB:
|
elif op == XSDRB:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRB 0x%s" % tdi )
|
print("XSDRB 0x%s" % tdi )
|
||||||
|
|
||||||
elif op == XSDRC:
|
elif op == XSDRC:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRC 0x%s" % tdi )
|
print("XSDRC 0x%s" % tdi )
|
||||||
|
|
||||||
elif op == XSDRE:
|
elif op == XSDRE:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRE 0x%s" % tdi )
|
print("XSDRE 0x%s" % tdi )
|
||||||
|
|
||||||
elif op == XSDRTDOB:
|
elif op == XSDRTDOB:
|
||||||
tdo = bytes2hexString( f, Xsdrsize )
|
tdo = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRTDOB 0x%s" % tdo )
|
print("XSDRTDOB 0x%s" % tdo )
|
||||||
|
|
||||||
elif op == XSDRTDOC:
|
elif op == XSDRTDOC:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
tdo = bytes2hexString( f, Xsdrsize )
|
tdo = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRTDOC 0x%s 0x%s" % (tdi, tdo) )
|
print("XSDRTDOC 0x%s 0x%s" % (tdi, tdo) )
|
||||||
|
|
||||||
elif op == XSDRTDOE:
|
elif op == XSDRTDOE:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
tdo = bytes2hexString( f, Xsdrsize )
|
tdo = bytes2hexString( f, Xsdrsize )
|
||||||
print("XSDRTDOE 0x%s 0x%s" % (tdi, tdo) )
|
print("XSDRTDOE 0x%s 0x%s" % (tdi, tdo) )
|
||||||
|
|
||||||
elif op == XSTATE:
|
elif op == XSTATE:
|
||||||
b = ReadByte(f)
|
b = ReadByte(f)
|
||||||
print("XSTATE %s" % ShowState(b))
|
print("XSTATE %s" % ShowState(b))
|
||||||
|
|
||||||
elif op == XENDIR:
|
elif op == XENDIR:
|
||||||
b = ReadByte( f )
|
b = ReadByte( f )
|
||||||
print("XENDIR %s" % ShowState(b))
|
print("XENDIR %s" % 'IRPAUSE' if b==1 else 'IDLE')
|
||||||
|
|
||||||
elif op == XENDDR:
|
elif op == XENDDR:
|
||||||
b = ReadByte( f )
|
b = ReadByte( f )
|
||||||
print("XENDDR %s" % ShowState(b))
|
print("XENDDR %s" % 'DRPAUSE' if b==1 else 'IDLE')
|
||||||
|
|
||||||
elif op == XSIR2:
|
elif op == XSIR2:
|
||||||
len = struct.unpack( '>H', f.read(2) )[0]
|
len = struct.unpack( '>H', f.read(2) )[0]
|
||||||
buf = bytes2hexString( f, len )
|
buf = bytes2hexString( f, len )
|
||||||
print("XSIR2 0x%04X 0x%s" % (len, buf))
|
print("XSIR2 0x%04X 0x%s" % (len, buf))
|
||||||
|
|
||||||
elif op == XCOMMENT:
|
elif op == XCOMMENT:
|
||||||
cmt = []
|
cmt = []
|
||||||
while 1:
|
while 1:
|
||||||
b = ReadByte(f)
|
b = ReadByte(f)
|
||||||
if b == 0: # terminating nul
|
if b == 0: # terminating nul
|
||||||
break;
|
break;
|
||||||
cmt.append( chr(b) )
|
cmt.append( chr(b) )
|
||||||
print("XCOMMENT \"%s\"" % ''.join(cmt) )
|
print("XCOMMENT \"%s\"" % ''.join(cmt) )
|
||||||
|
|
||||||
elif op == XWAIT:
|
elif op == XWAIT:
|
||||||
run_state = ReadByte(f)
|
run_state = ReadByte(f)
|
||||||
end_state = ReadByte(f)
|
end_state = ReadByte(f)
|
||||||
useconds = struct.unpack( '>i', f.read(4) )[0]
|
useconds = struct.unpack( '>i', f.read(4) )[0]
|
||||||
print("XWAIT %s %s" % (ShowState(run_state), ShowState(end_state)), useconds)
|
print("XWAIT %s %s" % (ShowState(run_state), ShowState(end_state)), useconds)
|
||||||
|
|
||||||
elif op == XWAITSTATE:
|
elif op == XWAITSTATE:
|
||||||
run_state = ReadByte(f)
|
run_state = ReadByte(f)
|
||||||
end_state = ReadByte(f)
|
end_state = ReadByte(f)
|
||||||
clocks = struct.unpack( '>i', f.read(4) )[0]
|
clocks = struct.unpack( '>i', f.read(4) )[0]
|
||||||
useconds = struct.unpack( '>i', f.read(4) )[0]
|
useconds = struct.unpack( '>i', f.read(4) )[0]
|
||||||
print("XWAITSTATE %s %s CLOCKS=%d USECS=%d" % (ShowState(run_state), ShowState(end_state), clocks, useconds) )
|
print("XWAITSTATE %s %s CLOCKS=%d USECS=%d" % (ShowState(run_state), ShowState(end_state), clocks, useconds) )
|
||||||
|
|
||||||
elif op == LCOUNT:
|
elif op == LCOUNT:
|
||||||
loop_count = struct.unpack( '>i', f.read(4) )[0]
|
loop_count = struct.unpack( '>i', f.read(4) )[0]
|
||||||
print("LCOUNT", loop_count )
|
print("LCOUNT", loop_count )
|
||||||
|
|
||||||
elif op == LDELAY:
|
elif op == LDELAY:
|
||||||
run_state = ReadByte(f)
|
run_state = ReadByte(f)
|
||||||
clocks = struct.unpack( '>i', f.read(4) )[0]
|
clocks = struct.unpack( '>i', f.read(4) )[0]
|
||||||
useconds = struct.unpack( '>i', f.read(4) )[0]
|
useconds = struct.unpack( '>i', f.read(4) )[0]
|
||||||
print("LDELAY %s CLOCKS=%d USECS=%d" % (ShowState(run_state), clocks, useconds) )
|
print("LDELAY %s CLOCKS=%d USECS=%d" % (ShowState(run_state), clocks, useconds) )
|
||||||
|
|
||||||
elif op == LSDR:
|
elif op == LSDR:
|
||||||
tdi = bytes2hexString( f, Xsdrsize )
|
tdi = bytes2hexString( f, Xsdrsize )
|
||||||
tdo = bytes2hexString( f, Xsdrsize )
|
tdo = bytes2hexString( f, Xsdrsize )
|
||||||
print("LSDR 0x%s 0x%s" % (tdi, tdo) )
|
print("LSDR 0x%s 0x%s" % (tdi, tdo) )
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("UNKNOWN op 0x%02X %d" % (op, op))
|
print("UNKNOWN op 0x%02X %d" % (op, op))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
if len( sys.argv ) < 2:
|
if len( sys.argv ) < 2:
|
||||||
print("usage %s <xsvf_filename>" % sys.argv[0])
|
print("usage %s <xsvf_filename>" % sys.argv[0])
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
f = open( sys.argv[1], 'rb' )
|
f = open( sys.argv[1], 'rb' )
|
||||||
|
|
||||||
opcode = ReadByte( f )
|
opcode = ReadByte( f )
|
||||||
while opcode != -1:
|
while opcode != -1:
|
||||||
# print the position within the file, then the command
|
# print the position within the file, then the command
|
||||||
print( "%d: " % f.tell(), end='' )
|
print( "%d: " % f.tell(), end='' )
|
||||||
ShowOpcode( opcode, f )
|
ShowOpcode( opcode, f )
|
||||||
opcode = ReadByte(f)
|
opcode = ReadByte(f)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue