1#!/bin/tcsh -f 2#---------------------------------------------------------- 3# GDSII output generating script using magic 4#---------------------------------------------------------- 5# Tim Edwards, 4/23/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_gds.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 (! ${?gdsii_options} ) then 48 set gdsii_options = ${options} 49endif 50 51set gengdsfile="${layoutdir}/generate_gds_${rootname}.tcl" 52 53if (!($?logdir)) then 54 set logdir=${projectpath}/log 55endif 56mkdir -p ${logdir} 57set lastlog=${logdir}/drc.log 58set synthlog=${logdir}/gdsii.log 59rm -f ${synthlog} >& /dev/null 60touch ${synthlog} 61set date=`date` 62echo "Qflow gdsii logfile created on $date" > ${synthlog} 63 64# Check if last line of drc log file says "error condition" 65if ( ! -f ${lastlog} ) then 66 set lastlog=${logdir}/lvs.log 67endif 68if ( ! -f ${lastlog} ) then 69 echo "Warning: No DRC or LVS logfiles found." 70else 71 set errcond = `tail -1 ${lastlog} | grep "error condition" | wc -l` 72 if ( ${errcond} == 1 ) then 73 echo "Synthesis flow stopped on error condition. GDSII generation" 74 echo "will not proceed until error condition is cleared." 75 exit 1 76 endif 77endif 78 79# Does variable "gdsfile" exist? 80 81if (! ${?gdsfile} || ( ${?gdsfile} && ( ${gdsfile} == "" ) ) ) then 82 echo "GDS generation failure: No gdsfile variable set in technology setup script." \ 83 |& tee -a ${synthlog} 84 echo "Premature exit." |& tee -a ${synthlog} 85 echo "Synthesis flow stopped due to error condition." >> ${synthlog} 86 exit 1 87endif 88 89# Prepend techdir to each gdsfile unless gdsfile begins with "/" 90set gdspath="" 91foreach f (${gdsfile}) 92 set abspath=`echo ${f} | cut -c1` 93 if ( "${abspath}" == "/" ) then 94 set p=${gdsfile} 95 else 96 set p=${techdir}/${gdsfile} 97 endif 98 set gdspath="${gdspath} $p" 99end 100 101#---------------------------------------------------------- 102# Done with initialization 103#---------------------------------------------------------- 104 105cd ${layoutdir} 106 107#------------------------------------------------------------------ 108# Determine the version number and availability of scripting 109#------------------------------------------------------------------ 110 111set version=`${bindir}/magic --version` 112set major=`echo $version | cut -d. -f1` 113set minor=`echo $version | cut -d. -f2` 114set subv=`echo $version | cut -d. -f3` 115 116#------------------------------------------------------------------ 117# Generate script for input to magic. 118#------------------------------------------------------------------ 119 120if ( !(-r $techfile)) then 121 if (`echo $techfile | cut -c1` != "/") then 122 set techfile=${techdir}/${techfile} 123 endif 124endif 125if (-r $techfile) then 126 cat >> ${gengdsfile} << EOF 127tech load $techfile -noprompt 128EOF 129else 130 touch ${gengdsfile} 131endif 132 133 134cat >> ${gengdsfile} << EOF 135drc off 136box 0 0 0 0 137gds readonly true 138gds rescale false 139EOF 140 141# Usually "gdsfile" is set to one GDS file for the standard cell set 142# but it can be a space-separated list of GDS files to read. This 143# is set by reading the .sh file. 144 145foreach gfile ( ${gdspath} ) 146cat >> ${gengdsfile} << EOF 147gds read $gfile 148EOF 149end 150 151# NOTE: "*hier write disable" and "*array write disable" prevent 152# magic from doing an exhaustive search on GDS layer interactions 153# between standard cells. This is disabled on the assumption that 154# the standard cells are properly designed and do not generate DRC 155# spacing errors when abutted. The standard cells will be abstract 156# views, anyway, so only a few layers like metal1 are represented. 157 158cat >> ${gengdsfile} << EOF 159load $rootname 160select top cell 161expand 162cif *hier write disable 163cif *array write disable 164gds write $rootname 165quit 166EOF 167 168#------------------------------------------------------------------ 169# Run magic in batch mode. 170#------------------------------------------------------------------ 171 172echo "Running magic $version" 173echo "magic -dnull -noconsole ${gdsii_options} ${gengdsfile}" |& tee -a ${synthlog} 174${bindir}/magic -dnull -noconsole ${gdsii_options} ${gengdsfile} |& tee -a ${synthlog} 175 176set errcond = $status 177if ( ${errcond} != 0 ) then 178 echo "magic failed with exit status ${errcond}" |& tee -a ${synthlog} 179 echo "Premature exit." |& tee -a ${synthlog} 180 echo "Synthesis flow stopped on error condition." >>& ${synthlog} 181 exit 1 182endif 183 184#--------------------------------------------------------------------- 185# Spot check: Did magic produce file ${rootname}.gds? 186#--------------------------------------------------------------------- 187 188if ( ! -f ${rootname}.gds || ( -M ${rootname}.gds < -M ${rootname}.def )) then 189 echo "magic failure: No file ${rootname}.gds." |& tee -a ${synthlog} 190 echo "Premature exit." |& tee -a ${synthlog} 191 echo "Synthesis flow stopped due to error condition." >> ${synthlog} 192 exit 1 193endif 194 195#------------------------------------------------------------ 196# Done! 197#------------------------------------------------------------ 198 199set endtime = `date` 200echo "GDS generating script ended on $endtime" >> $synthlog 201 202exit 0 203