2022-10-09 05:23:01 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# This script runs PrimeTime STA
|
|
|
|
# Rev 1
|
|
|
|
# 6/10/2022
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
def run_sta_all (
|
|
|
|
design: str,
|
2022-10-09 09:40:32 -05:00
|
|
|
output_dir: str,
|
|
|
|
log_dir: str
|
2022-10-09 05:23:01 -05:00
|
|
|
):
|
|
|
|
proc_corners = ["t", "s", "f"]
|
|
|
|
rc_corners = ["nom", "max", "min"]
|
|
|
|
for proc in proc_corners:
|
|
|
|
for rc in rc_corners:
|
2022-10-09 09:40:32 -05:00
|
|
|
run_sta (design, proc, rc, output_dir, log_dir)
|
2022-10-09 05:23:01 -05:00
|
|
|
|
|
|
|
def run_sta (
|
|
|
|
design: str,
|
|
|
|
proc_corner: str,
|
|
|
|
rc_corner: str,
|
2022-10-09 09:40:32 -05:00
|
|
|
output_dir: str,
|
|
|
|
log_dir: str
|
2022-10-09 05:23:01 -05:00
|
|
|
):
|
|
|
|
print (f"PrimeTime STA run for design: {design} at process corner {proc_corner} and RC corner {rc_corner}")
|
|
|
|
|
|
|
|
# Enviornment Variables
|
|
|
|
check_env_vars()
|
2022-10-10 17:46:41 -05:00
|
|
|
os.environ["PDK_ROOT"] = os.getenv('PDK_ROOT')
|
|
|
|
os.environ["PDK"] = os.getenv('PDK')
|
2022-10-09 05:23:01 -05:00
|
|
|
os.environ["PT_LIB_ROOT"] = os.getenv('PT_LIB_ROOT')
|
|
|
|
os.environ["CARAVEL_ROOT"] = os.getenv('CARAVEL_ROOT')
|
|
|
|
os.environ["MCW_ROOT"] = os.getenv('MCW_ROOT')
|
|
|
|
os.environ["OUT_DIR"] = output_dir
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
os.environ["DESIGN"] = design
|
|
|
|
os.environ["PROC_CORNER"] = proc_corner
|
|
|
|
os.environ["RC_CORNER"] = rc_corner
|
|
|
|
|
|
|
|
# PrimeTime command
|
|
|
|
PT_tcl = f"{SCRIPT_DIR}/pt_sta.tcl"
|
2022-10-10 17:46:41 -05:00
|
|
|
pt_command = f"source /tools/bashrc_snps; pt_shell -f {PT_tcl} -output_log_file {log_dir}/{design}/{design}-{rc_corner}-{proc_corner}-sta.log"
|
2022-10-09 05:23:01 -05:00
|
|
|
os.system(pt_command)
|
|
|
|
|
|
|
|
# Check if there exists any violations
|
2022-10-10 17:46:41 -05:00
|
|
|
sta_pass=search_viol(f"{output_dir}/pt_reports/{design}/{design}-{rc_corner}-{proc_corner}-all_viol.rpt")
|
2022-10-09 09:40:32 -05:00
|
|
|
if sta_pass == "pass":
|
|
|
|
print (f"STA run passed!")
|
2022-10-09 05:23:01 -05:00
|
|
|
else:
|
2022-10-09 09:40:32 -05:00
|
|
|
print (f"STA run failed!")
|
|
|
|
if sta_pass == "viol":
|
2022-10-10 17:46:41 -05:00
|
|
|
print(f"There are violations. check report: {output_dir}/pt_reports/{design}/{design}-{rc_corner}-{proc_corner}-all_viol.rpt")
|
2022-10-09 09:40:32 -05:00
|
|
|
else:
|
2022-10-10 17:46:41 -05:00
|
|
|
print(f"Linking failed. check log: {log_dir}/{design}/{design}-{rc_corner}-{proc_corner}-sta.log")
|
2022-10-09 05:23:01 -05:00
|
|
|
|
|
|
|
# Check the required env variables
|
|
|
|
def check_env_vars():
|
2022-10-10 17:46:41 -05:00
|
|
|
pdk_root = os.getenv('PDK_ROOT')
|
|
|
|
pdk = os.getenv('PDK')
|
2022-10-09 05:23:01 -05:00
|
|
|
pt_lib_root = os.getenv('PT_LIB_ROOT')
|
|
|
|
caravel_root = os.getenv('CARAVEL_ROOT')
|
|
|
|
mcw_root = os.getenv('MCW_ROOT')
|
2022-10-10 17:46:41 -05:00
|
|
|
if pdk_root is None:
|
|
|
|
raise FileNotFoundError(
|
|
|
|
"Please export PDK_ROOT to the PDK path"
|
|
|
|
)
|
|
|
|
if pdk is None:
|
|
|
|
raise FileNotFoundError(
|
|
|
|
"Please export PDK to either sky130A or sky130B"
|
|
|
|
)
|
2022-10-09 05:23:01 -05:00
|
|
|
if pt_lib_root is None:
|
|
|
|
raise FileNotFoundError(
|
|
|
|
"Please export PT_LIB_ROOT to the PrimeTime liberties path"
|
|
|
|
)
|
|
|
|
if caravel_root is None:
|
|
|
|
raise FileNotFoundError(
|
|
|
|
"Please export CARAVEL_ROOT to the Caravel repo path"
|
|
|
|
)
|
|
|
|
if mcw_root is None:
|
|
|
|
raise FileNotFoundError(
|
|
|
|
"Please export MCW_ROOT to the Caravel Management SoC Litex repo path"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Analyze the STA all violators output report
|
|
|
|
def search_viol(
|
|
|
|
report_path: str
|
|
|
|
):
|
|
|
|
with open(report_path, 'r') as report:
|
2022-10-09 09:40:32 -05:00
|
|
|
data = report.read()
|
|
|
|
if "(VIOLATED)" in data:
|
|
|
|
return "viol"
|
|
|
|
elif "Could not auto-link design" in data:
|
|
|
|
return "no link"
|
2022-10-09 05:23:01 -05:00
|
|
|
else:
|
2022-10-09 09:40:32 -05:00
|
|
|
return "pass"
|
2022-10-09 05:23:01 -05:00
|
|
|
|
2022-10-09 12:36:50 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Run STA using PrimeTime"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-d",
|
|
|
|
"--design",
|
|
|
|
help="design name",
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-o",
|
|
|
|
"--output_dir",
|
|
|
|
help="output directory",
|
|
|
|
required=True
|
|
|
|
)
|
2022-10-09 13:10:28 -05:00
|
|
|
parser.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--logs_dir",
|
|
|
|
help="output directory",
|
|
|
|
required=True
|
|
|
|
)
|
2022-10-09 12:36:50 -05:00
|
|
|
parser.add_argument(
|
|
|
|
"-rc",
|
|
|
|
"--rc_corner",
|
|
|
|
help="Specify the RC corner for the parasitics (Values are nom, max, or min) <default is nom>",
|
|
|
|
nargs="?",
|
|
|
|
default="nom"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-proc",
|
|
|
|
"--proc_corner",
|
|
|
|
help="Specify the process corner (Values are t, f, or s) <default is t>",
|
|
|
|
nargs="?",
|
|
|
|
default="t"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-a",
|
|
|
|
"--all",
|
|
|
|
help="Specify to run all the process corners and rc corners combinations for the design",
|
|
|
|
action='store_true'
|
|
|
|
)
|
2022-10-09 05:23:01 -05:00
|
|
|
|
2022-10-09 12:36:50 -05:00
|
|
|
args = parser.parse_args()
|
2022-10-09 05:23:01 -05:00
|
|
|
|
2022-10-09 12:36:50 -05:00
|
|
|
output = os.path.abspath(args.output_dir)
|
2022-10-09 13:10:28 -05:00
|
|
|
log = os.path.abspath(args.logs_dir)
|
2022-10-09 05:23:01 -05:00
|
|
|
|
2022-10-09 12:36:50 -05:00
|
|
|
try:
|
|
|
|
os.makedirs(output)
|
|
|
|
except FileExistsError:
|
|
|
|
# directory already exists
|
|
|
|
pass
|
2022-10-09 05:23:01 -05:00
|
|
|
|
2022-10-09 12:36:50 -05:00
|
|
|
try:
|
|
|
|
os.makedirs(log)
|
|
|
|
except FileExistsError:
|
|
|
|
# directory already exists
|
|
|
|
pass
|
|
|
|
try:
|
2022-10-10 17:46:41 -05:00
|
|
|
os.makedirs(log)
|
2022-10-09 12:36:50 -05:00
|
|
|
except FileExistsError:
|
|
|
|
# directory already exists
|
|
|
|
pass
|
|
|
|
try:
|
2022-10-10 17:46:41 -05:00
|
|
|
os.makedirs(os.path.join(log,args.design))
|
2022-10-09 12:36:50 -05:00
|
|
|
except FileExistsError:
|
|
|
|
# directory already exists
|
|
|
|
pass
|
2022-10-09 05:23:01 -05:00
|
|
|
|
2022-10-10 17:46:41 -05:00
|
|
|
sub_dirs = ['pt_reports', 'pt_sdf', 'pt_etm']
|
|
|
|
for item in sub_dirs:
|
|
|
|
path = os.path.join(output,item)
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except FileExistsError:
|
|
|
|
# directory already exists
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
os.makedirs(os.path.join(path,args.design))
|
|
|
|
except FileExistsError:
|
|
|
|
# directory already exists
|
|
|
|
pass
|
|
|
|
|
2022-10-09 12:36:50 -05:00
|
|
|
if args.all:
|
|
|
|
run_sta_all (args.design, output, log)
|
|
|
|
else:
|
|
|
|
run_sta (args.design, args.proc_corner, args.rc_corner, output, log)
|