1#!/bin/tcsh -f 2#---------------------------------------------------------- 3# DRC error checking script using magic 4#---------------------------------------------------------- 5# Tim Edwards, 8/20/18, for Open Circuit Design 6#---------------------------------------------------------- 7 8# Split out options from the main arguments 9set argline=(`getopt "" $argv[1-]`) 10 11set options=`echo "$argline" | awk 'BEGIN {FS = "-- "} END {print $1}'` 12set cmdargs=`echo "$argline" | awk 'BEGIN {FS = "-- "} END {print $2}'` 13set argc=`echo $cmdargs | wc -w` 14 15if ($argc >= 2) then 16 set argv1=`echo $cmdargs | cut -d' ' -f1` 17 set argv2=`echo $cmdargs | cut -d' ' -f2` 18else 19 echo "Usage: magic_drc.sh [options] <project_path> <source_name>" 20 echo " where" 21 echo " <project_path> is the name of the project directory containing" 22 echo " a file called qflow_vars.sh." 23 echo " <source_name> is the root name of the verilog file" 24 exit 1 25endif 26 27set projectpath=$argv1 28set sourcename=$argv2 29set rootname=${sourcename:h} 30 31# This script is called with the first argument <project_path>, which should 32# have file "qflow_vars.sh". Get all of our standard variable definitions 33# from the qflow_vars.sh file. 34 35if (! -f ${projectpath}/qflow_vars.sh ) then 36 echo "Error: Cannot find file qflow_vars.sh in path ${projectpath}" 37 exit 1 38endif 39 40source ${projectpath}/qflow_vars.sh 41source ${techdir}/${techname}.sh 42cd ${projectpath} 43if (-f project_vars.sh) then 44 source project_vars.sh 45endif 46 47if (! ${?drc_options} ) then 48 set drc_options = ${options} 49endif 50 51if (! ${?drc_gdsview} ) then 52 set drc_gdsview = "" 53endif 54 55set rundrcfile="${layoutdir}/run_drc_${rootname}.tcl" 56 57if (!($?logdir)) then 58 set logdir=${projectpath}/log 59endif 60mkdir -p ${logdir} 61set lastlog=${logdir}/lvs.log 62set synthlog=${logdir}/drc.log 63rm -f ${synthlog} >& /dev/null 64rm -f ${logdir}/lvs.log >& /dev/null 65rm -f ${logdir}/gdsii.log >& /dev/null 66touch ${synthlog} 67set date=`date` 68echo "Qflow DRC logfile created on $date" > ${synthlog} 69 70# Check if last line of drc log file says "error condition" 71if ( ! -f ${lastlog} ) then 72 set lastlog=${logdir}/post_sta.log 73endif 74if ( ! -f ${lastlog} ) then 75 echo "Warning: No LVS or post-route STA logfiles found." 76else 77 set errcond = `tail -1 ${lastlog} | grep "error condition" | wc -l` 78 if ( ${errcond} == 1 ) then 79 echo "Synthesis flow stopped on error condition. DRC check " 80 echo "will not proceed until error condition is cleared." 81 exit 1 82 endif 83endif 84 85# Does variable "gdsfile" exist? If not, then use the LEF views for 86# DRC checks. 87 88set use_gds=1 89if (! ${?gdsfile} || ( ${?gdsfile} && ( ${gdsfile} == "" ) ) ) then 90 set use_gds=0 91endif 92 93# Prepend techdir to each leffile unless leffile begins with "/" 94set lefpath="" 95foreach f (${leffile}) 96 set abspath=`echo ${f} | cut -c1` 97 if ( "${abspath}" == "/" ) then 98 set p=${leffile} 99 else 100 set p=${techdir}/${leffile} 101 endif 102 set lefpath="${lefpath} $p" 103end 104 105# Ditto for gdsfile 106set gdspath="" 107foreach f (${gdsfile}) 108 set abspath=`echo ${f} | cut -c1` 109 if ( "${abspath}" == "/" ) then 110 set p=${gdsfile} 111 else 112 set p=${techdir}/${gdsfile} 113 endif 114 set gdspath="${gdspath} $p" 115end 116 117#---------------------------------------------------------- 118# Done with initialization 119#---------------------------------------------------------- 120 121cd ${layoutdir} 122 123#------------------------------------------------------------------ 124# Determine the version number and availability of scripting 125#------------------------------------------------------------------ 126 127set version=`${bindir}/magic --version` 128set major=`echo $version | cut -d. -f1` 129set minor=`echo $version | cut -d. -f2` 130set subv=`echo $version | cut -d. -f3` 131 132#------------------------------------------------------------------ 133# Generate script for input to magic. 134#------------------------------------------------------------------ 135 136# Usually "gdsfile" is set to one GDS file for the standard cell set 137# but it can be a space-separated list of GDS files to read. This 138# is set by reading the .sh file. If no gdsfile variable exists, or 139# is blank, then GDS generation cannot proceed. 140 141rm -f ${rundrcfile} 142touch ${rundrcfile} 143 144if (! ($?drc_gdsview)) then 145 set drc_gdsview=0 146endif 147 148if ( !(-r $techfile)) then 149 if (`echo $techfile | cut -c1` != "/") then 150 set techfile=${techdir}/${techfile} 151 endif 152endif 153if (-r $techfile) then 154 cat >> ${rundrcfile} << EOF 155tech load $techfile -noprompt 156EOF 157endif 158 159if ( $drc_gdsview == 1 ) then 160cat >> ${rundrcfile} << EOF 161gds readonly true 162gds rescale false 163EOF 164foreach gfile ( ${gdspath} ) 165cat >> ${rundrcfile} << EOF 166gds read $gfile 167EOF 168end 169else 170foreach lfile ( ${lefpath} ) 171cat >> ${rundrcfile} << EOF 172lef read $lfile 173EOF 174end 175endif 176 177cat >> ${rundrcfile} << EOF 178load $rootname 179drc on 180select top cell 181expand 182drc check 183drc catchup 184set dcount [drc list count total] 185puts stdout "drc = \$dcount" 186quit 187EOF 188 189#------------------------------------------------------------------ 190# Run magic in batch mode. 191#------------------------------------------------------------------ 192 193echo "Running magic $version" 194echo "magic -dnull -noconsole ${drc_options} ${rundrcfile}" |& tee -a ${synthlog} 195${bindir}/magic -dnull -noconsole ${drc_options} ${rundrcfile} |& tee -a ${synthlog} 196 197set errcond = $status 198if ( ${errcond} != 0 ) then 199 echo "magic failed with exit status ${errcond}" |& tee -a ${synthlog} 200 echo "Premature exit." |& tee -a ${synthlog} 201 echo "Synthesis flow stopped on error condition." >>& ${synthlog} 202 exit 1 203endif 204 205#--------------------------------------------------------------------- 206# Spot check: Does the last line of the synthlog have "drc = 0"? 207#--------------------------------------------------------------------- 208 209set errors=`tail -10 ${synthlog} | grep "drc =" | cut -d' ' -f3` 210if ( $errors > 0 ) then 211 echo "DRC failure: There are ${errors} DRC errors in the layout." \ 212 |& tee -a ${synthlog} 213 echo "Premature exit." |& tee -a ${synthlog} 214 echo "Synthesis flow stopped due to error condition." >> ${synthlog} 215 exit 1 216endif 217 218#------------------------------------------------------------ 219# Done! 220#------------------------------------------------------------ 221 222set endtime = `date` 223echo "DRC checking script ended on $endtime" >> $synthlog 224 225exit 0 226