2017-11-14 23:59:14 +01:00
|
|
|
"""
|
|
|
|
|
This is a DRC/LVS/PEX interface file for magic + netgen.
|
|
|
|
|
|
2018-08-28 20:48:23 +02:00
|
|
|
We include the tech file for SCN3ME_SUBM in the tech directory,
|
|
|
|
|
that is included in OpenRAM during DRC.
|
|
|
|
|
You can use this interactively by appending the magic system path in
|
|
|
|
|
your .magicrc file
|
|
|
|
|
path sys /Users/mrg/openram/technology/scn3me_subm/tech
|
|
|
|
|
|
|
|
|
|
We require the version 30 Magic rules which allow via stacking.
|
|
|
|
|
We obtained this file from Qflow ( http://opencircuitdesign.com/qflow/index.html )
|
|
|
|
|
and include its appropriate license.
|
2017-11-14 23:59:14 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import time
|
2018-08-30 23:20:41 +02:00
|
|
|
import shutil
|
2017-11-14 23:59:14 +01:00
|
|
|
import debug
|
2017-11-16 22:52:58 +01:00
|
|
|
from globals import OPTS
|
2017-11-14 23:59:14 +01:00
|
|
|
import subprocess
|
|
|
|
|
|
2018-07-11 20:59:24 +02:00
|
|
|
# Keep track of statistics
|
|
|
|
|
num_drc_runs = 0
|
|
|
|
|
num_lvs_runs = 0
|
|
|
|
|
num_pex_runs = 0
|
|
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
def write_magic_script(cell_name, gds_name, extract=False):
|
|
|
|
|
""" Write a magic script to perform DRC and optionally extraction. """
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-01-12 23:39:42 +01:00
|
|
|
global OPTS
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-01-12 19:24:49 +01:00
|
|
|
run_file = OPTS.openram_temp + "run_drc.sh"
|
|
|
|
|
f = open(run_file, "w")
|
|
|
|
|
f.write("#!/bin/sh\n")
|
2018-01-12 23:39:42 +01:00
|
|
|
f.write("{} -dnull -noconsole << EOF\n".format(OPTS.drc_exe[1]))
|
2018-01-12 19:24:49 +01:00
|
|
|
f.write("gds polygon subcell true\n")
|
|
|
|
|
f.write("gds warning default\n")
|
|
|
|
|
f.write("gds read {}\n".format(gds_name))
|
2018-01-12 23:39:42 +01:00
|
|
|
f.write("load {}\n".format(cell_name))
|
2018-08-22 20:37:24 +02:00
|
|
|
# Flatten the cell to get rid of DRCs spanning multiple layers
|
|
|
|
|
# (e.g. with routes)
|
|
|
|
|
f.write("flatten {}_new\n".format(cell_name))
|
|
|
|
|
f.write("load {}_new\n".format(cell_name))
|
2018-09-18 21:57:39 +02:00
|
|
|
f.write("cellname rename {0}_new {0}\n".format(cell_name))
|
|
|
|
|
f.write("load {}\n".format(cell_name))
|
|
|
|
|
f.write("writeall force\n")
|
2018-01-12 23:39:42 +01:00
|
|
|
f.write("drc check\n")
|
|
|
|
|
f.write("drc catchup\n")
|
|
|
|
|
f.write("drc count total\n")
|
2018-01-12 19:24:49 +01:00
|
|
|
f.write("drc count\n")
|
2018-10-05 17:18:53 +02:00
|
|
|
if not extract:
|
|
|
|
|
pre = "#"
|
|
|
|
|
else:
|
|
|
|
|
pre = ""
|
|
|
|
|
f.write(pre+"extract all\n")
|
|
|
|
|
f.write(pre+"ext2spice hierarchy on\n")
|
|
|
|
|
f.write(pre+"ext2spice scale off\n")
|
|
|
|
|
# Can choose hspice, ngspice, or spice3,
|
|
|
|
|
# but they all seem compatible enough.
|
|
|
|
|
#f.write(pre+"ext2spice format ngspice\n")
|
|
|
|
|
f.write(pre+"ext2spice\n")
|
2018-01-12 19:24:49 +01:00
|
|
|
f.write("quit -noprompt\n")
|
|
|
|
|
f.write("EOF\n")
|
|
|
|
|
|
2017-11-14 23:59:14 +01:00
|
|
|
f.close()
|
2018-01-12 19:24:49 +01:00
|
|
|
os.system("chmod u+x {}".format(run_file))
|
2018-01-18 01:48:35 +01:00
|
|
|
|
|
|
|
|
def write_netgen_script(cell_name, sp_name):
|
|
|
|
|
""" Write a netgen script to perform LVS. """
|
|
|
|
|
|
|
|
|
|
global OPTS
|
2018-10-05 17:30:25 +02:00
|
|
|
|
|
|
|
|
if os.path.exists(OPTS.openram_tech + "/mag_lib/setup.tcl"):
|
|
|
|
|
setup_file = OPTS.openram_tech + "/mag_lib/setup.tcl"
|
|
|
|
|
# Copy setup.tcl file into temp dir
|
|
|
|
|
shutil.copy(OPTS.openram_tech + "/mag_lib/setup.tcl",
|
|
|
|
|
OPTS.openram_temp)
|
|
|
|
|
else:
|
|
|
|
|
setup_file = 'nosetup'
|
2018-01-18 01:48:35 +01:00
|
|
|
|
|
|
|
|
run_file = OPTS.openram_temp + "run_lvs.sh"
|
|
|
|
|
f = open(run_file, "w")
|
|
|
|
|
f.write("#!/bin/sh\n")
|
|
|
|
|
f.write("{} -noconsole << EOF\n".format(OPTS.lvs_exe[1]))
|
2018-03-03 03:03:55 +01:00
|
|
|
f.write("readnet spice {0}.spice\n".format(cell_name))
|
|
|
|
|
f.write("readnet spice {0}\n".format(sp_name))
|
2018-01-26 21:39:00 +01:00
|
|
|
# Allow some flexibility in W size because magic will snap to a lambda grid
|
|
|
|
|
# This can also cause disconnects unfortunately!
|
|
|
|
|
# f.write("property {{{0}{1}.spice nfet}} tolerance {{w 0.1}}\n".format(OPTS.openram_temp,
|
|
|
|
|
# cell_name))
|
|
|
|
|
# f.write("property {{{0}{1}.spice pfet}} tolerance {{w 0.1}}\n".format(OPTS.openram_temp,
|
|
|
|
|
# cell_name))
|
2018-10-05 17:30:25 +02:00
|
|
|
f.write("lvs {0}.spice {{{1} {0}}} {2} {0}.lvs.report\n".format(cell_name, sp_name, setup_file))
|
2018-01-18 01:48:35 +01:00
|
|
|
f.write("quit\n")
|
|
|
|
|
f.write("EOF\n")
|
|
|
|
|
f.close()
|
|
|
|
|
os.system("chmod u+x {}".format(run_file))
|
2018-03-03 03:03:55 +01:00
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
|
|
|
|
|
def run_drc(cell_name, gds_name, extract=False):
|
|
|
|
|
"""Run DRC check on a cell which is implemented in gds_name."""
|
|
|
|
|
|
2018-07-11 20:59:24 +02:00
|
|
|
global num_drc_runs
|
|
|
|
|
num_drc_runs += 1
|
|
|
|
|
|
2018-08-30 23:20:41 +02:00
|
|
|
# Copy .magicrc file into temp dir
|
|
|
|
|
shutil.copy(OPTS.openram_tech + "/mag_lib/.magicrc",
|
|
|
|
|
OPTS.openram_temp)
|
|
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
write_magic_script(cell_name, gds_name, extract)
|
2018-01-12 19:24:49 +01:00
|
|
|
|
2017-11-14 23:59:14 +01:00
|
|
|
# run drc
|
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
os.chdir(OPTS.openram_temp)
|
2018-01-12 23:39:42 +01:00
|
|
|
errfile = "{0}{1}.drc.err".format(OPTS.openram_temp, cell_name)
|
2018-02-02 23:07:15 +01:00
|
|
|
outfile = "{0}{1}.drc.summary".format(OPTS.openram_temp, cell_name)
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-01-12 19:24:49 +01:00
|
|
|
cmd = "{0}run_drc.sh 2> {1} 1> {2}".format(OPTS.openram_temp,
|
|
|
|
|
errfile,
|
|
|
|
|
outfile)
|
2018-02-25 20:14:31 +01:00
|
|
|
debug.info(2, cmd)
|
2017-11-14 23:59:14 +01:00
|
|
|
os.system(cmd)
|
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
2018-01-12 23:39:42 +01:00
|
|
|
# Check the result for these lines in the summary:
|
|
|
|
|
# Total DRC errors found: 0
|
|
|
|
|
# The count is shown in this format:
|
|
|
|
|
# Cell replica_cell_6t has 3 error tiles.
|
|
|
|
|
# Cell tri_gate_array has 8 error tiles.
|
|
|
|
|
# etc.
|
2017-11-14 23:59:14 +01:00
|
|
|
try:
|
2018-01-12 23:39:42 +01:00
|
|
|
f = open(outfile, "r")
|
2017-11-14 23:59:14 +01:00
|
|
|
except:
|
|
|
|
|
debug.error("Unable to retrieve DRC results file. Is magic set up?",1)
|
|
|
|
|
results = f.readlines()
|
|
|
|
|
f.close()
|
|
|
|
|
# those lines should be the last 3
|
2018-01-12 23:39:42 +01:00
|
|
|
for line in results:
|
|
|
|
|
if "Total DRC errors found:" in line:
|
2018-05-12 01:32:00 +02:00
|
|
|
errors = int(re.split(": ", line)[1])
|
2018-01-12 23:39:42 +01:00
|
|
|
break
|
2017-11-14 23:59:14 +01:00
|
|
|
|
|
|
|
|
# always display this summary
|
|
|
|
|
if errors > 0:
|
2018-01-12 23:39:42 +01:00
|
|
|
for line in results:
|
|
|
|
|
if "error tiles" in line:
|
2018-01-30 00:31:14 +01:00
|
|
|
debug.info(1,line.rstrip("\n"))
|
2018-01-20 01:38:19 +01:00
|
|
|
debug.error("DRC Errors {0}\t{1}".format(cell_name, errors))
|
2017-11-14 23:59:14 +01:00
|
|
|
else:
|
2018-01-20 01:38:19 +01:00
|
|
|
debug.info(1, "DRC Errors {0}\t{1}".format(cell_name, errors))
|
2017-11-14 23:59:14 +01:00
|
|
|
|
|
|
|
|
return errors
|
|
|
|
|
|
|
|
|
|
|
2018-02-05 23:52:51 +01:00
|
|
|
def run_lvs(cell_name, gds_name, sp_name, final_verification=False):
|
2017-11-14 23:59:14 +01:00
|
|
|
"""Run LVS check on a given top-level name which is
|
2018-02-05 23:52:51 +01:00
|
|
|
implemented in gds_name and sp_name. Final verification will
|
|
|
|
|
ensure that there are no remaining virtual conections. """
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-07-11 20:59:24 +02:00
|
|
|
global num_lvs_runs
|
|
|
|
|
num_lvs_runs += 1
|
|
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
run_drc(cell_name, gds_name, extract=True)
|
|
|
|
|
write_netgen_script(cell_name, sp_name)
|
2017-11-14 23:59:14 +01:00
|
|
|
|
|
|
|
|
# run LVS
|
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
os.chdir(OPTS.openram_temp)
|
2018-01-18 01:48:35 +01:00
|
|
|
errfile = "{0}{1}.lvs.err".format(OPTS.openram_temp, cell_name)
|
|
|
|
|
outfile = "{0}{1}.lvs.out".format(OPTS.openram_temp, cell_name)
|
2018-02-02 21:47:42 +01:00
|
|
|
resultsfile = "{0}{1}.lvs.report".format(OPTS.openram_temp, cell_name)
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
cmd = "{0}run_lvs.sh lvs 2> {1} 1> {2}".format(OPTS.openram_temp,
|
|
|
|
|
errfile,
|
|
|
|
|
outfile)
|
2018-02-25 20:14:31 +01:00
|
|
|
debug.info(2, cmd)
|
2017-11-14 23:59:14 +01:00
|
|
|
os.system(cmd)
|
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
2018-04-21 00:46:12 +02:00
|
|
|
total_errors = 0
|
|
|
|
|
|
2017-11-14 23:59:14 +01:00
|
|
|
# check the result for these lines in the summary:
|
2018-02-01 14:38:48 +01:00
|
|
|
f = open(resultsfile, "r")
|
2017-11-14 23:59:14 +01:00
|
|
|
results = f.readlines()
|
|
|
|
|
f.close()
|
2018-04-21 00:46:12 +02:00
|
|
|
# Look for the results after the final "Subcircuit summary:"
|
|
|
|
|
# which will be the top-level netlist.
|
|
|
|
|
final_results = []
|
|
|
|
|
for line in reversed(results):
|
|
|
|
|
if "Subcircuit summary:" in line:
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
final_results.insert(0,line)
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-04-21 00:46:12 +02:00
|
|
|
# There were property errors in any module.
|
2018-01-18 01:48:35 +01:00
|
|
|
test = re.compile("Property errors were found.")
|
2018-05-12 01:32:00 +02:00
|
|
|
propertyerrors = list(filter(test.search, results))
|
2018-04-21 00:46:12 +02:00
|
|
|
total_errors += len(propertyerrors)
|
|
|
|
|
|
2018-02-01 14:38:48 +01:00
|
|
|
# Require pins to match?
|
|
|
|
|
# Cell pin lists for pnand2_1.spice and pnand2_1 altered to match.
|
2018-02-02 21:47:42 +01:00
|
|
|
# test = re.compile(".*altered to match.")
|
2018-05-12 01:32:00 +02:00
|
|
|
# pinerrors = list(filter(test.search, results))
|
2018-02-02 21:47:42 +01:00
|
|
|
# if len(pinerrors)>0:
|
|
|
|
|
# debug.warning("Pins altered to match in {}.".format(cell_name))
|
|
|
|
|
|
2018-01-23 02:50:53 +01:00
|
|
|
#if len(propertyerrors)>0:
|
|
|
|
|
# debug.warning("Property errors found, but not checking them.")
|
2017-11-14 23:59:14 +01:00
|
|
|
|
2018-04-21 00:46:12 +02:00
|
|
|
# Netlists do not match.
|
|
|
|
|
test = re.compile("Netlists do not match.")
|
2018-05-12 01:32:00 +02:00
|
|
|
incorrect = list(filter(test.search, final_results))
|
2018-04-21 00:46:12 +02:00
|
|
|
total_errors += len(incorrect)
|
|
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
# Netlists match uniquely.
|
2018-05-12 01:32:00 +02:00
|
|
|
test = re.compile("match uniquely.")
|
|
|
|
|
correct = list(filter(test.search, final_results))
|
2018-01-18 01:48:35 +01:00
|
|
|
# Fail if they don't match. Something went wrong!
|
2018-04-21 00:46:12 +02:00
|
|
|
if len(correct) == 0:
|
2018-01-18 01:48:35 +01:00
|
|
|
total_errors += 1
|
2018-01-30 00:31:14 +01:00
|
|
|
|
2018-01-18 01:48:35 +01:00
|
|
|
if total_errors>0:
|
|
|
|
|
# Just print out the whole file, it is short.
|
|
|
|
|
for e in results:
|
2018-01-30 00:31:14 +01:00
|
|
|
debug.info(1,e.strip("\n"))
|
2018-07-18 23:28:43 +02:00
|
|
|
debug.error("{0}\tLVS mismatch (results in {1})".format(cell_name,resultsfile))
|
|
|
|
|
else:
|
|
|
|
|
debug.info(1, "{0}\tLVS matches".format(cell_name))
|
2017-11-14 23:59:14 +01:00
|
|
|
|
|
|
|
|
return total_errors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_pex(name, gds_name, sp_name, output=None):
|
|
|
|
|
"""Run pex on a given top-level name which is
|
|
|
|
|
implemented in gds_name and sp_name. """
|
|
|
|
|
|
2018-07-11 20:59:24 +02:00
|
|
|
global num_pex_runs
|
|
|
|
|
num_pex_runs += 1
|
|
|
|
|
|
2017-11-15 00:49:47 +01:00
|
|
|
debug.warning("PEX using magic not implemented.")
|
2017-12-12 23:53:19 +01:00
|
|
|
return 1
|
2017-11-14 23:59:14 +01:00
|
|
|
|
|
|
|
|
from tech import drc
|
|
|
|
|
if output == None:
|
|
|
|
|
output = name + ".pex.netlist"
|
|
|
|
|
|
|
|
|
|
# check if lvs report has been done
|
|
|
|
|
# if not run drc and lvs
|
|
|
|
|
if not os.path.isfile(name + ".lvs.report"):
|
|
|
|
|
run_drc(name, gds_name)
|
|
|
|
|
run_lvs(name, gds_name, sp_name)
|
|
|
|
|
|
2018-08-28 20:48:23 +02:00
|
|
|
"""
|
|
|
|
|
2. magic can perform extraction with the following:
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
rm -f $1.ext
|
|
|
|
|
rm -f $1.spice
|
|
|
|
|
magic -dnull -noconsole << EOF
|
|
|
|
|
tech load SCN3ME_SUBM.30
|
|
|
|
|
#scalegrid 1 2
|
|
|
|
|
gds rescale no
|
|
|
|
|
gds polygon subcell true
|
|
|
|
|
gds warning default
|
|
|
|
|
gds read $1
|
|
|
|
|
extract
|
|
|
|
|
ext2spice scale off
|
|
|
|
|
ext2spice
|
|
|
|
|
quit -noprompt
|
|
|
|
|
EOF
|
|
|
|
|
"""
|
|
|
|
|
|
2017-11-14 23:59:14 +01:00
|
|
|
pex_rules = drc["xrc_rules"]
|
|
|
|
|
pex_runset = {
|
|
|
|
|
'pexRulesFile': pex_rules,
|
|
|
|
|
'pexRunDir': OPTS.openram_temp,
|
|
|
|
|
'pexLayoutPaths': gds_name,
|
|
|
|
|
'pexLayoutPrimary': name,
|
|
|
|
|
#'pexSourcePath' : OPTS.openram_temp+"extracted.sp",
|
|
|
|
|
'pexSourcePath': sp_name,
|
|
|
|
|
'pexSourcePrimary': name,
|
|
|
|
|
'pexReportFile': name + ".lvs.report",
|
|
|
|
|
'pexPexNetlistFile': output,
|
|
|
|
|
'pexPexReportFile': name + ".pex.report",
|
|
|
|
|
'pexMaskDBFile': name + ".maskdb",
|
|
|
|
|
'cmnFDIDEFLayoutPath': name + ".def",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# write the runset file
|
|
|
|
|
f = open(OPTS.openram_temp + "pex_runset", "w")
|
|
|
|
|
for k in sorted(pex_runset.iterkeys()):
|
|
|
|
|
f.write("*{0}: {1}\n".format(k, pex_runset[k]))
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
# run pex
|
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
os.chdir(OPTS.openram_temp)
|
|
|
|
|
errfile = "{0}{1}.pex.err".format(OPTS.openram_temp, name)
|
|
|
|
|
outfile = "{0}{1}.pex.out".format(OPTS.openram_temp, name)
|
|
|
|
|
|
|
|
|
|
cmd = "{0} -gui -pex {1}pex_runset -batch 2> {2} 1> {3}".format(OPTS.pex_exe,
|
|
|
|
|
OPTS.openram_temp,
|
|
|
|
|
errfile,
|
|
|
|
|
outfile)
|
|
|
|
|
debug.info(2, cmd)
|
|
|
|
|
os.system(cmd)
|
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
|
|
# also check the output file
|
|
|
|
|
f = open(outfile, "r")
|
|
|
|
|
results = f.readlines()
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
# Errors begin with "ERROR:"
|
|
|
|
|
test = re.compile("ERROR:")
|
2018-05-12 01:32:00 +02:00
|
|
|
stdouterrors = list(filter(test.search, results))
|
2017-11-14 23:59:14 +01:00
|
|
|
for e in stdouterrors:
|
|
|
|
|
debug.error(e.strip("\n"))
|
|
|
|
|
|
|
|
|
|
out_errors = len(stdouterrors)
|
|
|
|
|
|
|
|
|
|
assert(os.path.isfile(output))
|
|
|
|
|
#correct_port(name, output, sp_name)
|
|
|
|
|
|
|
|
|
|
return out_errors
|
|
|
|
|
|
2018-07-11 20:59:24 +02:00
|
|
|
def print_drc_stats():
|
|
|
|
|
debug.info(1,"DRC runs: {0}".format(num_drc_runs))
|
|
|
|
|
def print_lvs_stats():
|
|
|
|
|
debug.info(1,"LVS runs: {0}".format(num_lvs_runs))
|
|
|
|
|
def print_pex_stats():
|
|
|
|
|
debug.info(1,"PEX runs: {0}".format(num_pex_runs))
|