Skip to content

Instantly share code, notes, and snippets.

@Juvar1
Created August 18, 2018 19:25
Show Gist options
  • Save Juvar1/e65cb55d0483426e3fb8ac83c41fc409 to your computer and use it in GitHub Desktop.
Save Juvar1/e65cb55d0483426e3fb8ac83c41fc409 to your computer and use it in GitHub Desktop.
SVF is an file format that is used to describe JTAG chain operations. This script converts SVF ascii files to XSVF binary file format. No need to install Xilinx iMPACT software.
# converts SVF ascii files to XSVF binary file format
# usage: python svf2xsvf.py source.svf dest.xsvf
import sys
data = ["XCOMPLETE","XTDOMASK","XSIR","XSDR","XRUNTEST","","","XREPEAT",\
"XSDRSIZE","XSDRTDO","XSETSDRMASKS","XSDRINC","XSDRB","XSDRC","XSDRE",\
"XSDRTDOB","XSDRTDOC","XSDRTDOE","XSTATE","XENDIR","XENDDR",\
"XSIR2","XCOMMENT","XWAIT"]
def name2hex(name):
for idx, n in enumerate(data):
if(n == name): return idx
if(len(sys.argv) == 3):
hexdata = bytearray()
with open(sys.argv[1], "r") as f:
for raw in f:
if(";" in raw):
line = raw[:raw.find(";")]
elif("/" in raw):
line = raw[:raw.find("/")]
elif("!" in raw):
line = raw[:raw.find("!")]
else:
line = raw.rstrip("\r\n")
# take first word as a command
if(" " in line):
hexdata.append(name2hex(line[:line.find(" ")]))
else:
hexdata.append(name2hex(line))
if(name2hex(line) == 0x04): #XRUNTEST needs additional parameters
hexdata.append(0)
hexdata.append(0)
hexdata.append(0)
hexdata.append(0)
continue # continue from next iteration
# take next characters as a parameters
params = line.split(" ")
for idx, p in enumerate(params):
if(idx > 0): hexdata.append(int(p,16))
with open(sys.argv[2], "wb") as f:
f.write(hexdata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment