mirror of https://github.com/openXC7/prjxray.git
Add segmaker library, Refactor lutinit and ffconfig generate.py
Signed-off-by: Clifford Wolf <clifford@clifford.at> Signed-off-by: Tim 'mithro' Ansell <mithro@mithis.com>
This commit is contained in:
parent
90c0b570e8
commit
1871aea240
|
|
@ -1,37 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os, sys, json, re
|
import sys, re
|
||||||
|
|
||||||
|
sys.path.append("../../../utils/")
|
||||||
|
from segmaker import segmaker
|
||||||
|
|
||||||
#################################################
|
segmk = segmaker("design_%s.bits" % sys.argv[1])
|
||||||
# Loading Raw Source Data
|
|
||||||
|
|
||||||
grid = None
|
print("Loading tags from design_%s.txt." % sys.argv[1])
|
||||||
bits = dict()
|
|
||||||
data = dict()
|
|
||||||
|
|
||||||
print("Loading grid.")
|
|
||||||
with open("../../../database/%s/tilegrid.json" % os.getenv("XRAY_DATABASE"), "r") as f:
|
|
||||||
grid = json.load(f)
|
|
||||||
|
|
||||||
print("Loading bits.")
|
|
||||||
with open("design_%s.bits" % sys.argv[1], "r") as f:
|
|
||||||
for line in f:
|
|
||||||
line = line.split("_")
|
|
||||||
bit_frame = int(line[1], 16)
|
|
||||||
bit_wordidx = int(line[2], 10)
|
|
||||||
bit_bitidx = int(line[3], 10)
|
|
||||||
base_frame = bit_frame & ~0x7f
|
|
||||||
|
|
||||||
if base_frame not in bits:
|
|
||||||
bits[base_frame] = dict()
|
|
||||||
|
|
||||||
if bit_wordidx not in bits[base_frame]:
|
|
||||||
bits[base_frame][bit_wordidx] = set()
|
|
||||||
|
|
||||||
bits[base_frame][bit_wordidx].add((bit_frame, bit_wordidx, bit_bitidx))
|
|
||||||
|
|
||||||
print("Loading text data.")
|
|
||||||
with open("design_%s.txt" % sys.argv[1], "r") as f:
|
with open("design_%s.txt" % sys.argv[1], "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.split()
|
line = line.split()
|
||||||
|
|
@ -39,80 +15,11 @@ with open("design_%s.txt" % sys.argv[1], "r") as f:
|
||||||
bel = line[1]
|
bel = line[1]
|
||||||
init = int(line[2][4:], 16)
|
init = int(line[2][4:], 16)
|
||||||
|
|
||||||
if site not in data:
|
|
||||||
data[site] = dict()
|
|
||||||
|
|
||||||
for i in range(64):
|
for i in range(64):
|
||||||
bitname = "%s.INIT[%02d]" % (bel, i)
|
bitname = "%s.INIT[%02d]" % (bel, i)
|
||||||
data[site][bitname] = ((init >> i) & 1) != 0
|
bitname = bitname.replace("6LUT", "LUT")
|
||||||
|
segmk.addtag(site, bitname, ((init >> i) & 1) != 0)
|
||||||
|
|
||||||
|
segmk.compile()
|
||||||
#################################################
|
segmk.write(sys.argv[1])
|
||||||
# Group per Segment
|
|
||||||
|
|
||||||
print("Compile segment data.")
|
|
||||||
|
|
||||||
segments_by_type = dict()
|
|
||||||
|
|
||||||
for tilename, tiledata in grid["tiles"].items():
|
|
||||||
if "segment" not in tiledata:
|
|
||||||
continue
|
|
||||||
|
|
||||||
segdata = grid["segments"][tiledata["segment"]]
|
|
||||||
|
|
||||||
if segdata["type"] not in segments_by_type:
|
|
||||||
segments_by_type[segdata["type"]] = dict()
|
|
||||||
segments = segments_by_type[segdata["type"]]
|
|
||||||
|
|
||||||
tile_type = tiledata["type"]
|
|
||||||
segname = "%s_%03d" % (segdata["baseaddr"][0][2:], segdata["baseaddr"][1])
|
|
||||||
|
|
||||||
for site in tiledata["sites"]:
|
|
||||||
if site not in data:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not segname in segments:
|
|
||||||
segments[segname] = { "bits": set(), "tags": dict() }
|
|
||||||
|
|
||||||
base_frame = int(segdata["baseaddr"][0][2:], 16)
|
|
||||||
for wordidx in range(segdata["baseaddr"][1], segdata["baseaddr"][1]+2):
|
|
||||||
if base_frame not in bits:
|
|
||||||
continue
|
|
||||||
if wordidx not in bits[base_frame]:
|
|
||||||
continue
|
|
||||||
for bit_frame, bit_wordidx, bit_bitidx in bits[base_frame][wordidx]:
|
|
||||||
bitname = "%02d_%02d" % (bit_frame - base_frame, 32*(bit_wordidx - segdata["baseaddr"][1]) + bit_bitidx)
|
|
||||||
segments[segname]["bits"].add(bitname)
|
|
||||||
|
|
||||||
if re.match(r"SLICE_X[0-9]*[02468]Y", site):
|
|
||||||
sitekey = "SLICE_X0"
|
|
||||||
elif re.match(r"SLICE_X[0-9]*[13579]Y", site):
|
|
||||||
sitekey = "SLICE_X1"
|
|
||||||
else:
|
|
||||||
assert 0
|
|
||||||
|
|
||||||
for name, value in data[site].items():
|
|
||||||
tag = "%s.%s.%s" % (re.sub("_[LR]$", "", tile_type), sitekey, name)
|
|
||||||
tag = tag.replace("SLICE_X0.SLICEM", "SLICEM_X0")
|
|
||||||
tag = tag.replace("SLICE_X1.SLICEM", "SLICEM_X1")
|
|
||||||
tag = tag.replace("SLICE_X0.SLICEL", "SLICEL_X0")
|
|
||||||
tag = tag.replace("SLICE_X1.SLICEL", "SLICEL_X1")
|
|
||||||
tag = tag.replace("6LUT", "LUT")
|
|
||||||
segments[segname]["tags"][tag] = value
|
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
# Print
|
|
||||||
|
|
||||||
print("Write segment data.")
|
|
||||||
|
|
||||||
for segtype in segments_by_type.keys():
|
|
||||||
with open("segdata_%s_%s.txt" % (segtype, sys.argv[1]), "w") as f:
|
|
||||||
segments = segments_by_type[segtype]
|
|
||||||
for segname, segdata in sorted(segments.items()):
|
|
||||||
print("seg %s" % segname, file=f)
|
|
||||||
for bitname in sorted(segdata["bits"]):
|
|
||||||
print("bit %s" % bitname, file=f)
|
|
||||||
for tagname, tagval in sorted(segdata["tags"].items()):
|
|
||||||
print("tag %s %d" % (tagname, tagval), file=f)
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os, sys, json, re
|
import sys, re
|
||||||
|
|
||||||
|
sys.path.append("../../../utils/")
|
||||||
|
from segmaker import segmaker
|
||||||
|
|
||||||
#################################################
|
segmk = segmaker("design_%s.bits" % sys.argv[1])
|
||||||
# Loading Raw Source Data
|
|
||||||
|
|
||||||
grid = None
|
print("Loading tags from design_%s.txt." % sys.argv[1])
|
||||||
bits = dict()
|
|
||||||
data = dict()
|
|
||||||
|
|
||||||
print("Loading grid.")
|
|
||||||
with open("../../../database/%s/tilegrid.json" % os.getenv("XRAY_DATABASE"), "r") as f:
|
|
||||||
grid = json.load(f)
|
|
||||||
|
|
||||||
print("Loading bits.")
|
|
||||||
with open("design_%s.bits" % sys.argv[1], "r") as f:
|
|
||||||
for line in f:
|
|
||||||
line = line.split("_")
|
|
||||||
bit_frame = int(line[1], 16)
|
|
||||||
bit_wordidx = int(line[2], 10)
|
|
||||||
bit_bitidx = int(line[3], 10)
|
|
||||||
base_frame = bit_frame & ~0x7f
|
|
||||||
|
|
||||||
if base_frame not in bits:
|
|
||||||
bits[base_frame] = dict()
|
|
||||||
|
|
||||||
if bit_wordidx not in bits[base_frame]:
|
|
||||||
bits[base_frame][bit_wordidx] = set()
|
|
||||||
|
|
||||||
bits[base_frame][bit_wordidx].add((bit_frame, bit_wordidx, bit_bitidx))
|
|
||||||
|
|
||||||
print("Loading text data.")
|
|
||||||
with open("design_%s.txt" % sys.argv[1], "r") as f:
|
with open("design_%s.txt" % sys.argv[1], "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.split()
|
line = line.split()
|
||||||
|
|
@ -41,78 +17,9 @@ with open("design_%s.txt" % sys.argv[1], "r") as f:
|
||||||
init = int(line[3][3])
|
init = int(line[3][3])
|
||||||
cinv = int(line[4][3])
|
cinv = int(line[4][3])
|
||||||
|
|
||||||
if site not in data:
|
segmk.addtag(site, "%s.ZINI" % bel, 1-init)
|
||||||
data[site] = dict()
|
# segmk.addtag(site, "%s.CLOCK_INV" % (bel.split(".")[0]), cinv)
|
||||||
|
|
||||||
data[site]["%s.ZINI" % bel] = 1-init
|
segmk.compile()
|
||||||
# data[site]["%s.CLOCK_INV" % (bel.split(".")[0])] = cinv
|
segmk.write(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
# Group per Segment
|
|
||||||
|
|
||||||
print("Compile segment data.")
|
|
||||||
|
|
||||||
segments_by_type = dict()
|
|
||||||
|
|
||||||
for tilename, tiledata in grid["tiles"].items():
|
|
||||||
if "segment" not in tiledata:
|
|
||||||
continue
|
|
||||||
|
|
||||||
segdata = grid["segments"][tiledata["segment"]]
|
|
||||||
|
|
||||||
if segdata["type"] not in segments_by_type:
|
|
||||||
segments_by_type[segdata["type"]] = dict()
|
|
||||||
segments = segments_by_type[segdata["type"]]
|
|
||||||
|
|
||||||
tile_type = tiledata["type"]
|
|
||||||
segname = "%s_%03d" % (segdata["baseaddr"][0][2:], segdata["baseaddr"][1])
|
|
||||||
|
|
||||||
for site in tiledata["sites"]:
|
|
||||||
if site not in data:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not segname in segments:
|
|
||||||
segments[segname] = { "bits": set(), "tags": dict() }
|
|
||||||
|
|
||||||
base_frame = int(segdata["baseaddr"][0][2:], 16)
|
|
||||||
for wordidx in range(segdata["baseaddr"][1], segdata["baseaddr"][1]+2):
|
|
||||||
if base_frame not in bits:
|
|
||||||
continue
|
|
||||||
if wordidx not in bits[base_frame]:
|
|
||||||
continue
|
|
||||||
for bit_frame, bit_wordidx, bit_bitidx in bits[base_frame][wordidx]:
|
|
||||||
bitname = "%02d_%02d" % (bit_frame - base_frame, 32*(bit_wordidx - segdata["baseaddr"][1]) + bit_bitidx)
|
|
||||||
segments[segname]["bits"].add(bitname)
|
|
||||||
|
|
||||||
if re.match(r"SLICE_X[0-9]*[02468]Y", site):
|
|
||||||
sitekey = "SLICE_X0"
|
|
||||||
elif re.match(r"SLICE_X[0-9]*[13579]Y", site):
|
|
||||||
sitekey = "SLICE_X1"
|
|
||||||
else:
|
|
||||||
assert 0
|
|
||||||
|
|
||||||
for name, value in data[site].items():
|
|
||||||
tag = "%s.%s.%s" % (re.sub("_[LR]$", "", tile_type), sitekey, name)
|
|
||||||
tag = tag.replace("SLICE_X0.SLICEM", "SLICEM_X0")
|
|
||||||
tag = tag.replace("SLICE_X1.SLICEM", "SLICEM_X1")
|
|
||||||
tag = tag.replace("SLICE_X0.SLICEL", "SLICEL_X0")
|
|
||||||
tag = tag.replace("SLICE_X1.SLICEL", "SLICEL_X1")
|
|
||||||
segments[segname]["tags"][tag] = value
|
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
# Print
|
|
||||||
|
|
||||||
print("Write segment data.")
|
|
||||||
|
|
||||||
for segtype in segments_by_type.keys():
|
|
||||||
with open("segdata_%s_%s.txt" % (segtype, sys.argv[1]), "w") as f:
|
|
||||||
segments = segments_by_type[segtype]
|
|
||||||
for segname, segdata in sorted(segments.items()):
|
|
||||||
print("seg %s" % segname, file=f)
|
|
||||||
for bitname in sorted(segdata["bits"]):
|
|
||||||
print("bit %s" % bitname, file=f)
|
|
||||||
for tagname, tagval in sorted(segdata["tags"].items()):
|
|
||||||
print("tag %s %d" % (tagname, tagval), file=f)
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
import os, json, re
|
||||||
|
|
||||||
|
class segmaker:
|
||||||
|
def __init__(self, bitsfile):
|
||||||
|
print("Loading %s grid." % os.getenv("XRAY_DATABASE"))
|
||||||
|
with open("../../../database/%s/tilegrid.json" % os.getenv("XRAY_DATABASE"), "r") as f:
|
||||||
|
self.grid = json.load(f)
|
||||||
|
|
||||||
|
self.bits = dict()
|
||||||
|
self.tags = dict()
|
||||||
|
|
||||||
|
print("Loading bits from %s." % bitsfile)
|
||||||
|
with open(bitsfile, "r") as f:
|
||||||
|
for line in f:
|
||||||
|
line = line.split("_")
|
||||||
|
bit_frame = int(line[1], 16)
|
||||||
|
bit_wordidx = int(line[2], 10)
|
||||||
|
bit_bitidx = int(line[3], 10)
|
||||||
|
base_frame = bit_frame & ~0x7f
|
||||||
|
|
||||||
|
if base_frame not in self.bits:
|
||||||
|
self.bits[base_frame] = dict()
|
||||||
|
|
||||||
|
if bit_wordidx not in self.bits[base_frame]:
|
||||||
|
self.bits[base_frame][bit_wordidx] = set()
|
||||||
|
|
||||||
|
self.bits[base_frame][bit_wordidx].add((bit_frame, bit_wordidx, bit_bitidx))
|
||||||
|
|
||||||
|
def addtag(self, site, name, value):
|
||||||
|
if site not in self.tags:
|
||||||
|
self.tags[site] = dict()
|
||||||
|
self.tags[site][name] = value
|
||||||
|
|
||||||
|
def compile(self):
|
||||||
|
print("Compiling segment data.")
|
||||||
|
|
||||||
|
self.segments_by_type = dict()
|
||||||
|
|
||||||
|
for tilename, tiledata in self.grid["tiles"].items():
|
||||||
|
if "segment" not in tiledata:
|
||||||
|
continue
|
||||||
|
|
||||||
|
segdata = self.grid["segments"][tiledata["segment"]]
|
||||||
|
|
||||||
|
if segdata["type"] not in self.segments_by_type:
|
||||||
|
self.segments_by_type[segdata["type"]] = dict()
|
||||||
|
segments = self.segments_by_type[segdata["type"]]
|
||||||
|
|
||||||
|
tile_type = tiledata["type"]
|
||||||
|
segname = "%s_%03d" % (segdata["baseaddr"][0][2:], segdata["baseaddr"][1])
|
||||||
|
|
||||||
|
for site in tiledata["sites"]:
|
||||||
|
if site not in self.tags:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not segname in segments:
|
||||||
|
segments[segname] = { "bits": set(), "tags": dict() }
|
||||||
|
|
||||||
|
base_frame = int(segdata["baseaddr"][0][2:], 16)
|
||||||
|
for wordidx in range(segdata["baseaddr"][1], segdata["baseaddr"][1]+2):
|
||||||
|
if base_frame not in self.bits:
|
||||||
|
continue
|
||||||
|
if wordidx not in self.bits[base_frame]:
|
||||||
|
continue
|
||||||
|
for bit_frame, bit_wordidx, bit_bitidx in self.bits[base_frame][wordidx]:
|
||||||
|
bitname = "%02d_%02d" % (bit_frame - base_frame, 32*(bit_wordidx - segdata["baseaddr"][1]) + bit_bitidx)
|
||||||
|
segments[segname]["bits"].add(bitname)
|
||||||
|
|
||||||
|
if re.match(r"SLICE_X[0-9]*[02468]Y", site):
|
||||||
|
sitekey = "SLICE_X0"
|
||||||
|
elif re.match(r"SLICE_X[0-9]*[13579]Y", site):
|
||||||
|
sitekey = "SLICE_X1"
|
||||||
|
else:
|
||||||
|
assert 0
|
||||||
|
|
||||||
|
for name, value in self.tags[site].items():
|
||||||
|
tag = "%s.%s.%s" % (re.sub("_[LR]$", "", tile_type), sitekey, name)
|
||||||
|
tag = tag.replace("SLICE_X0.SLICEM", "SLICEM_X0")
|
||||||
|
tag = tag.replace("SLICE_X1.SLICEM", "SLICEM_X1")
|
||||||
|
tag = tag.replace("SLICE_X0.SLICEL", "SLICEL_X0")
|
||||||
|
tag = tag.replace("SLICE_X1.SLICEL", "SLICEL_X1")
|
||||||
|
segments[segname]["tags"][tag] = value
|
||||||
|
|
||||||
|
def write(self, suffix=None, roi=False):
|
||||||
|
for segtype in self.segments_by_type.keys():
|
||||||
|
if suffix is not None:
|
||||||
|
filename = "segdata_%s_%s.txt" % (segtype, suffix)
|
||||||
|
else:
|
||||||
|
filename = "segdata_%s.txt" % (segtype)
|
||||||
|
|
||||||
|
print("Writing %s." % filename)
|
||||||
|
|
||||||
|
with open(filename, "w") as f:
|
||||||
|
segments = self.segments_by_type[segtype]
|
||||||
|
if True:
|
||||||
|
for segname, segdata in sorted(segments.items()):
|
||||||
|
print("seg %s" % segname, file=f)
|
||||||
|
for bitname in sorted(segdata["bits"]):
|
||||||
|
print("bit %s" % bitname, file=f)
|
||||||
|
for tagname, tagval in sorted(segdata["tags"].items()):
|
||||||
|
print("tag %s %d" % (tagname, tagval), file=f)
|
||||||
|
else:
|
||||||
|
print("seg roi", file=f)
|
||||||
|
for segname, segdata in sorted(segments.items()):
|
||||||
|
for bitname in sorted(segdata["bits"]):
|
||||||
|
print("bit %s_%s" % (segname, bitname), file=f)
|
||||||
|
for tagname, tagval in sorted(segdata["tags"].items()):
|
||||||
|
print("tag %s_%s %d" % (segname, tagname, tagval), file=f)
|
||||||
|
|
||||||
Loading…
Reference in New Issue