-
Notifications
You must be signed in to change notification settings - Fork 14
/
iic-pex.sh
executable file
·301 lines (267 loc) · 7.5 KB
/
iic-pex.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/bash
# ========================================================================
# PEX (Parasitic Extraction) using Magic VLSI
#
# SPDX-FileCopyrightText: 2021-2024 Harald Pretl
# Johannes Kepler University, Institute for Integrated Circuits
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier: Apache-2.0
#
# Usage: iic-pex.sh [-d] [-m mode] [-s mode] [-n <subcktname>] [-w <workdir>] <cellname>
#
# Supported PEX modes:
# 1 = C-decoupled
# 2 = C-coupled (default)
# 3 = full-RC
# ========================================================================
ERR_GENERAL=1
ERR_FILE_NOT_FOUND=2
ERR_NO_PARAM=3
ERR_WRONG_MODE=4
ERR_CMD_NOT_FOUND=5
ERR_PDK_NOT_SUPPORTED=6
if [ $# -eq 0 ]; then
echo
echo "PEX script using Magic-VLSI (IIC@JKU)"
echo
echo "Usage: $0 [-d] [-m mode] [-s mode] [-n <subcktname>] [-w <workdir>] <cellname>"
echo
echo " -m Select PEX mode (1 = C-decoupled, 2 = C-coupled [default], 3 = full-RC)"
echo " -s Subcircuit definition in PEX netlist (1 = include subcircuit definition [default], 0 = no subcircuit)"
echo " -n name of PEX subcircuit (default is <cellname>)"
echo " -w Set <workdir> working directory"
echo " -d Enable debug information"
echo
exit $ERR_NO_PARAM
fi
# Set the default behavior
# ------------------------
DEBUG=0
GDS_MODE=0
EXT_MODE=2
SUBCIRCUIT=1
RESDIR=$PWD
CELL_NAME_SET=0
# Check flags
# -----------
while getopts "m:s:w:n:d" flag; do
case $flag in
m)
[ $DEBUG -eq 1 ] && echo "[INFO] Flag -m is set to <$OPTARG>."
EXT_MODE=${OPTARG}
;;
s)
[ $DEBUG -eq 1 ] && echo "[INFO] Flag -s is set to <$OPTARG>."
SUBCIRCUIT=${OPTARG}
;;
w)
[ $DEBUG -eq 1 ] && echo "[INFO] Flag -w is set to <$OPTARG>."
RESDIR=$(realpath "$OPTARG")
;;
n)
[ $DEBUG -eq 1 ] && echo "[INFO] Flag -n is set to <$OPTARG>."
CELL_NAME_SET=1
CELL_NAME_PEX=${OPTARG}
;;
d)
echo "[INFO] DEBUG is enabled."
DEBUG=1
;;
*)
;;
esac
done
shift $((OPTIND-1))
# Check that the mode is an integer and in a valid range
# ------------------------------------------------------
if [ -n "$EXT_MODE" ] && [ "$EXT_MODE" -eq "$EXT_MODE" ] 2>/dev/null; then
if [ "$EXT_MODE" -lt 1 ] || [ "$EXT_MODE" -gt 3 ]; then
echo "[ERROR] Unknown extraction mode!"
exit $ERR_WRONG_MODE
fi
else
echo "[ERROR] Extraction mode must be an integer!"
exit $ERR_WRONG_MODE
fi
if [ -n "$SUBCIRCUIT" ] && [ "$SUBCIRCUIT" -eq "$SUBCIRCUIT" ] 2>/dev/null; then
if [ "$SUBCIRCUIT" -lt 0 ] || [ "$SUBCIRCUIT" -gt 1 ]; then
echo "[ERROR] Illegal subcircuit mode!"
exit $ERR_WRONG_MODE
fi
else
echo "[ERROR] Subcircuit mode must be an integer!"
exit $ERR_WRONG_MODE
fi
# Check if the PDK is already supported by this script
# ----------------------------------------------------
if echo "$PDK" | grep -q -i "sky130"; then
[ $DEBUG -eq 1 ] && echo "[INFO] sky130 PDK selected"
elif echo "$PDK" | grep -q -i "gf180mcuC"; then
[ $DEBUG -eq 1 ] && echo "[INFO] gf180mcuC PDK selected"
else
echo "[ERROR] The PDK $PDK is not yet supported!"
exit $ERR_PDK_NOT_SUPPORTED
fi
# check if the input file exists
# ------------------------------
if [ -z "$1" ]; then
echo "[ERROR] No cellname provided!"
exit $ERR_FILE_NOT_FOUND
elif [ -f "$1" ]; then
CELL_LAY="$1"
elif [ -f "$1.mag" ]; then
CELL_LAY="$1.mag"
elif [ -f "$1.mag.gz" ]; then
CELL_LAY="$1.mag.gz"
elif [ -f "$1.gds" ]; then
CELL_LAY="$1.gds"
GDS_MODE=1
elif [ -f "$1.gds.gz" ]; then
CELL_LAY="$1.gds.gz"
GDS_MODE=1
else
echo "[ERROR] Layout $CELL_LAY not found!"
exit $ERR_FILE_NOT_FOUND
fi
[ $DEBUG -eq 1 ] && echo "[INFO] CELL_LAY=$CELL_LAY"
# Define useful variables
# -----------------------
CELL_NAME=$(basename "$CELL_LAY" | cut -f 1 -d '.')
EXT_SCRIPT="$RESDIR/pex_$CELL_NAME.tcl"
NETLIST_PEX="$RESDIR/$CELL_NAME.pex.spice"
if [ $CELL_NAME_SET -eq 0 ]; then
CELL_NAME_PEX=${CELL_NAME}
fi
# check if GDS file
# -----------------
if [[ "$CELL_LAY" == *"gds.gz" ]]; then
cp "$CELL_LAY" tmp.gds.gz
[ -f tmp.gds ] && rm -f tmp.gds
gunzip tmp.gds.gz > /dev/null
CELL_LAY="tmp.gds"
fi
if [[ "$CELL_LAY" == *"gds" ]]; then
GDS_MODE=1
[ $DEBUG = 1 ] && echo "[INFO] GDS mode is selected."
fi
# Generate extract script for magic
# ---------------------------------
{
echo "crashbackups stop"
echo "drc off"
} > "$EXT_SCRIPT"
if [ "$GDS_MODE" -eq 0 ]; then
# we read a .mag/.mag.gz view
{
echo "load ${CELL_LAY}"
} >> "$EXT_SCRIPT"
else
# we read a .gds/.gds.gz view
{
echo "gds read ${CELL_LAY}"
echo "load ${CELL_NAME}"
} >> "$EXT_SCRIPT"
fi
{
echo "select top cell"
echo "flatten ${CELL_NAME}_flat"
echo "load ${CELL_NAME}_flat"
echo "cellname delete ${CELL_NAME}"
echo "cellname rename ${CELL_NAME}_flat ${CELL_NAME_PEX}"
echo "select top cell"
echo "extract path $RESDIR"
echo "ext2spice lvs"
} >> "$EXT_SCRIPT"
if [ "$EXT_MODE" -eq 1 ] || [ "$EXT_MODE" -eq 2 ]; then
if [ "$EXT_MODE" -eq 1 ]; then
EXT_MODE_TEXT="C-decoupled"
elif [ "$EXT_MODE" -eq 2 ]; then
EXT_MODE_TEXT="C-coupled"
else
echo "[ERROR] Illegal branch!"
exit $ERR_GENERAL
fi
{
[ "$EXT_MODE" -eq 1 ] && echo "extract no coupling"
echo "extract all"
} >> "$EXT_SCRIPT"
fi
if [ "$EXT_MODE" -eq 3 ]; then
# Extraction mode RC
EXT_MODE_TEXT="full-RC"
{
echo "extract do resistance"
echo "extract all"
echo "ext2sim labels on"
echo "ext2sim"
echo "extresist tolerance 10"
echo "extresist all"
echo "ext2spice extresist on"
# FIXME acc. Tim Edwards the "tee on" option might produce wrong netlists by placing resistors twice.
# Need to experiment with it!
# echo "ext2spice resistor tee on"
} >> "$EXT_SCRIPT"
fi
{
echo "ext2spice cthresh 0.01"
[ "$SUBCIRCUIT" -eq 0 ] && echo "ext2spice subcircuit top off"
echo "ext2spice -p $RESDIR -o $NETLIST_PEX.tmp"
echo "quit -noprompt"
} >> "$EXT_SCRIPT"
# check if commands exist in the path
# -----------------------------------
if [ ! -x "$(command -v magic)" ]; then
echo "[ERROR] magic could not be found!"
exit $ERR_CMD_NOT_FOUND
fi
# Extract SPICE netlist from layout with magic
# --------------------------------------------
echo "[INFO] Running PEX using magic..."
if [ $DEBUG -eq 0 ]; then
magic -dnull -noconsole \
-rcfile "$PDKPATH/libs.tech/magic/$PDK.magicrc" \
"$EXT_SCRIPT" "$NO_MESSAGE" \
> /dev/null 2> /dev/null
else
magic -dnull -noconsole \
-rcfile "$PDKPATH/libs.tech/magic/$PDK.magicrc" \
"$EXT_SCRIPT" "$NO_MESSAGE"
fi
if [ ! -f "$NETLIST_PEX.tmp" ]; then
echo "[ERROR] No PEX file produced, something went wrong!"
exit $ERR_GENERAL
else
DATE=$(date)
HEADER="* PEX produced on $DATE using $0 with m=$EXT_MODE and s=$SUBCIRCUIT"
{
echo "$HEADER"
cat "$NETLIST_PEX.tmp"
} > "$NETLIST_PEX"
rm -f "$NETLIST_PEX.tmp"
sed -i 's/_flat//g' "$NETLIST_PEX"
fi
# Cleanup
# -------
rm -f ./*.ext
[ -f tmp.gds ] && rm -f tmp.gds
if [ "$EXT_MODE" -eq 3 ]; then
rm -f ./*.nodes
rm -f ./*.ext
rm -f ./*.sim
rm -f ./*.res.ext
fi
[ $DEBUG -eq 0 ] && rm -f "$EXT_SCRIPT"
# Finished
# --------
echo "[DONE] PEX ($EXT_MODE_TEXT) done, extracted SPICE netlist is <$NETLIST_PEX>."