blob: 5a2e30d08b22cef362fc661abfd3f6cf3b376df4 [file] [log] [blame]
agorararmard3f797352020-12-10 18:24:42 +02001# SPDX-FileCopyrightText: 2020 Efabless Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# SPDX-License-Identifier: Apache-2.0
16
agorararmard7eebfe42020-12-07 22:08:29 +020017# cannot commit files larger than 100 MB to GitHub
Ahmed Ghazy31c34652020-12-01 19:59:44 +020018FILE_SIZE_LIMIT_MB = 100
Ahmed Ghazyb1e51702020-12-31 22:43:41 +020019
20# Commands to be used to compress/uncompress files
21# they must operate **in place** (otherwise, modify the target to delete the
22# intermediate file/archive)
23COMPRESS ?= gzip -n --best
24UNCOMPRESS ?= gzip -d
25ARCHIVE_EXT ?= gz
26
27# The following variables are to build static pattern rules
28
29# Needed to rebuild archives that were previously split
30SPLIT_FILES := $(shell find . -type f -name "*.$(ARCHIVE_EXT).00.split")
31SPLIT_FILES_SOURCES := $(basename $(basename $(basename $(SPLIT_FILES))))
32
33# Needed to uncompress the existing archives
34ARCHIVES := $(shell find . -type f -name "*.$(ARCHIVE_EXT)")
35ARCHIVE_SOURCES := $(basename $(ARCHIVES))
36
37# Needed to compress and split files/archives that are too large
Ahmed Ghazy31c34652020-12-01 19:59:44 +020038LARGE_FILES := $(shell find ./gds -type f -name "*.gds")
Ahmed Ghazy0011f612020-12-02 22:53:33 +020039LARGE_FILES += $(shell find . -type f -size +$(FILE_SIZE_LIMIT_MB)M -not -path "./.git/*" -not -path "./gds/*" -not -path "./openlane/*")
Ahmed Ghazyb1e51702020-12-31 22:43:41 +020040LARGE_FILES_GZ := $(addsuffix .$(ARCHIVE_EXT), $(LARGE_FILES))
41LARGE_FILES_GZ_SPLIT := $(addsuffix .$(ARCHIVE_EXT).00.split, $(LARGE_FILES))
42# consider splitting existing archives
43LARGE_FILES_GZ_SPLIT += $(addsuffix .00.split, $(ARCHIVES))
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020044
agorararmard212cd822020-11-26 22:40:17 +020045# PDK setup configs
46THREADS ?= $(shell nproc)
47STD_CELL_LIBRARY ?= sky130_fd_sc_hd
48SPECIAL_VOLTAGE_LIBRARY ?= sky130_fd_sc_hvl
49IO_LIBRARY ?= sky130_fd_io
agorararmardfed74ec2020-12-01 18:03:46 +020050SKYWATER_COMMIT ?= 3d7617a1acb92ea883539bcf22a632d6361a5de4
agorararmarde1ad4aa2021-01-05 20:28:45 +020051OPEN_PDKS_COMMIT ?= 49fc7125db927de199d1f69e002beadc0a29881b
Ahmed Ghazyefdc5292020-11-19 16:05:48 +020052
53.DEFAULT_GOAL := ship
Ahmed Ghazyefdc5292020-11-19 16:05:48 +020054# We need portable GDS_FILE pointers...
55.PHONY: ship
agorararmard212cd822020-11-26 22:40:17 +020056ship: check-env uncompress
Ahmed Ghazyefdc5292020-11-19 16:05:48 +020057 @echo "###############################################"
58 @echo "Generating Caravel GDS (sources are in the 'gds' directory)"
59 @sleep 1
agorararmardf8e91c32020-11-30 23:59:58 +020060 @cp gds/caravel.gds gds/caravel.old.gds && echo "Copying old Caravel to gds/caravel.old.gds" || true
Ahmed Ghazy0252f542020-11-25 14:45:38 +020061 @cd gds && MAGTYPE=mag magic -rcfile ${PDK_ROOT}/sky130A/libs.tech/magic/current/sky130A.magicrc -noc -dnull gen_caravel.tcl < /dev/null
Ahmed Ghazyefdc5292020-11-19 16:05:48 +020062
63
Ahmed Ghazye4c7ec52020-11-20 13:10:15 +020064
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020065.PHONY: clean
66clean:
agorararmard331d2592020-12-31 17:56:06 +020067 cd ./verilog/dv/caravel/mgmt_soc/ && \
68 $(MAKE) -j$(THREADS) clean
69 cd ./verilog/dv/caravel/user_proj_example/ && \
70 $(MAKE) -j$(THREADS) clean
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020071
72
73.PHONY: verify
74verify:
agorararmard331d2592020-12-31 17:56:06 +020075 cd ./verilog/dv/caravel/mgmt_soc/ && \
76 $(MAKE) -j$(THREADS) all
77 cd ./verilog/dv/caravel/user_proj_example/ && \
78 $(MAKE) -j$(THREADS) all
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020079
80
81
Ahmed Ghazyb1e51702020-12-31 22:43:41 +020082#####
83$(LARGE_FILES_GZ): %.$(ARCHIVE_EXT): %
84 @if ! [ $(suffix $<) == ".$(ARCHIVE_EXT)" ]; then\
85 $(COMPRESS) $< > /dev/null &&\
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020086 echo "$< -> $@";\
87 fi
88
Ahmed Ghazyb1e51702020-12-31 22:43:41 +020089$(LARGE_FILES_GZ_SPLIT): %.$(ARCHIVE_EXT).00.split: %.$(ARCHIVE_EXT)
90 @if [ -n "$$(find "$<" -prune -size +$(FILE_SIZE_LIMIT_MB)M)" ]; then\
91 split $< -b $(FILE_SIZE_LIMIT_MB)M $<. -d --additional-suffix=.split &&\
92 rm $< &&\
93 echo -n "$< -> $$(ls $<.*.split)" | tr '\n' ' ' && echo "";\
94 fi
95
Ahmed Ghazye4c7ec52020-11-20 13:10:15 +020096# This target compresses all files larger than $(FILE_SIZE_LIMIT_MB) MB
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020097.PHONY: compress
Ahmed Ghazyb1e51702020-12-31 22:43:41 +020098compress: $(LARGE_FILES_GZ) $(LARGE_FILES_GZ_SPLIT)
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +020099 @echo "Files larger than $(FILE_SIZE_LIMIT_MB) MBytes are compressed!"
100
101
102
Ahmed Ghazyb1e51702020-12-31 22:43:41 +0200103#####
104$(ARCHIVE_SOURCES): %: %.$(ARCHIVE_EXT)
105 @$(UNCOMPRESS) $<
106 @echo "$< -> $@"
107
108.SECONDEXPANSION:
109$(SPLIT_FILES_SOURCES): %: $$(sort $$(wildcard %.$(ARCHIVE_EXT).*.split))
110 @cat $? > $@.$(ARCHIVE_EXT)
111 @rm $?
112 @echo "$? -> $@.$(ARCHIVE_EXT)"
113 @$(UNCOMPRESS) $@.$(ARCHIVE_EXT)
114 @echo "$@.$(ARCHIVE_EXT) -> $@"
115
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +0200116
117.PHONY: uncompress
Ahmed Ghazyb1e51702020-12-31 22:43:41 +0200118uncompress: $(SPLIT_FILES_SOURCES) $(ARCHIVE_SOURCES)
Ahmed Ghazy5898e4a2020-11-13 22:28:55 +0200119 @echo "All files are uncompressed!"
agorararmard212cd822020-11-26 22:40:17 +0200120
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200121
122# LVS
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200123BLOCKS = $(shell cd openlane && find * -maxdepth 0 -type d)
124LVS_BLOCKS = $(foreach block, $(BLOCKS), lvs-$(block))
Ahmed Ghazy7f70d6f2020-12-05 23:05:31 +0200125$(LVS_BLOCKS): lvs-% : ./mag/%.mag ./verilog/gl/%.v
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200126 echo "Extracting $*"
127 mkdir -p ./mag/tmp
128 echo "load $* -dereference;\
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200129 select top cell;\
130 foreach cell [cellname list children] {\
131 load \$$cell -dereference;\
132 property LEFview TRUE;\
133 };\
134 load $* -dereference;\
135 select top cell;\
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200136 extract no all;\
137 extract do local;\
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200138 extract unique;\
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200139 extract;\
140 ext2spice lvs;\
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200141 ext2spice $*.ext;\
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200142 feedback save extract_$*.log;\
143 exit;" > ./mag/extract_$*.tcl
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200144 cd mag && export MAGTYPE=maglef; magic -rcfile ${PDK_ROOT}/sky130A/libs.tech/magic/current/sky130A.magicrc -noc -dnull extract_$*.tcl < /dev/null
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200145 mv ./mag/$*.spice ./spi/lvs
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200146 rm ./mag/*.ext
147 mv -f ./mag/extract_$*.{tcl,log} ./mag/tmp
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200148 ####
149 mkdir -p ./spi/lvs/tmp
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200150 sh ./spi/lvs/run_lvs.sh ./spi/lvs/$*.spice ./verilog/gl/$*.v $*
151 @echo ""
agorararmard308c7e02020-12-30 17:12:48 +0200152 python3 ./scripts/count_lvs.py -f ./verilog/gl/$*.v_comp.json | tee ./spi/lvs/tmp/$*.lvs.summary.log
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200153 mv -f ./verilog/gl/*{.out,.json,.log} ./spi/lvs/tmp 2> /dev/null || true
Ahmed Ghazy66091cc2020-12-17 22:13:06 +0200154 @echo ""
155 @echo "LVS: ./spi/lvs/$*.spice vs. ./verilog/gl/$*.v"
Ahmed Ghazyd3ca6fe2020-12-16 20:48:17 +0200156 @echo "Comparison result: ./spi/lvs/tmp/$*.v_comp.out"
agorararmardc520b2d2020-12-16 23:49:37 +0200157
Ahmed Ghazy96d0fed2020-12-24 21:50:21 +0200158# connect-by-label is enabled here!
159LVS_MAGLEF_BLOCKS = $(foreach block, $(BLOCKS), lvs-maglef-$(block))
160$(LVS_MAGLEF_BLOCKS): lvs-maglef-% : ./mag/%.mag ./verilog/gl/%.v
161 echo "Extracting $*"
162 mkdir -p ./maglef/tmp
163 echo "load $* -dereference;\
164 select top cell;\
165 foreach cell [cellname list children] {\
166 load \$$cell -dereference;\
167 property LEFview TRUE;\
168 };\
169 load $* -dereference;\
170 select top cell;\
171 extract no all;\
172 extract do local;\
173 extract;\
174 ext2spice lvs;\
175 ext2spice $*.ext;\
176 feedback save extract_$*.log;\
177 exit;" > ./mag/extract_$*.tcl
178 cd mag && export MAGTYPE=maglef; magic -noc -dnull extract_$*.tcl < /dev/null
179 mv ./mag/$*.spice ./spi/lvs
180 rm ./maglef/*.ext
181 mv -f ./mag/extract_$*.{tcl,log} ./maglef/tmp
182 ####
183 mkdir -p ./spi/lvs/tmp
184 sh ./spi/lvs/run_lvs.sh ./spi/lvs/$*.spice ./verilog/gl/$*.v $*
185 @echo ""
agorararmard308c7e02020-12-30 17:12:48 +0200186 python3 ./scripts/count_lvs.py -f ./verilog/gl/$*.v_comp.json | tee ./spi/lvs/tmp/$*.maglef.lvs.summary.log
Ahmed Ghazy96d0fed2020-12-24 21:50:21 +0200187 mv -f ./verilog/gl/*{.out,.json,.log} ./spi/lvs/tmp 2> /dev/null || true
188 @echo ""
189 @echo "LVS: ./spi/lvs/$*.spice vs. ./verilog/gl/$*.v"
190 @echo "Comparison result: ./spi/lvs/tmp/$*.v_comp.out"
191
agorararmardc520b2d2020-12-16 23:49:37 +0200192# DRC
193BLOCKS = $(shell cd openlane && find * -maxdepth 0 -type d)
194DRC_BLOCKS = $(foreach block, $(BLOCKS), drc-$(block))
195$(DRC_BLOCKS): drc-% : ./gds/%.gds
196 echo "Running DRC on $*"
197 mkdir -p ./gds/tmp
198 cd gds && export DESIGN_IN_DRC=$* && export MAGTYPE=mag; magic -rcfile ${PDK_ROOT}/sky130A/libs.tech/magic/current/sky130A.magicrc -noc -dnull drc_on_gds.tcl < /dev/null
199 @echo "DRC result: ./gds/tmp/$*.drc"
200
agorararmarde67e1c82020-12-28 18:31:48 +0200201# Antenna
202BLOCKS = $(shell cd openlane && find * -maxdepth 0 -type d)
203ANTENNA_BLOCKS = $(foreach block, $(BLOCKS), antenna-$(block))
204$(ANTENNA_BLOCKS): antenna-% : ./gds/%.gds
205 echo "Running Antenna Checks on $*"
206 mkdir -p ./gds/tmp
207 cd gds && export DESIGN_IN_ANTENNA=$* && export MAGTYPE=mag; magic -rcfile ${PDK_ROOT}/sky130A/libs.tech/magic/current/sky130A.magicrc -noc -dnull antenna_on_gds.tcl < /dev/null 2>&1 | tee ./tmp/$*.antenna
agorararmard5deb5ed2020-12-29 18:00:17 +0200208 mv -f ./gds/*.ext ./gds/tmp/
agorararmarde67e1c82020-12-28 18:31:48 +0200209 @echo "Antenna result: ./gds/tmp/$*.antenna"
210
Ahmed Ghazy876d6072020-12-28 15:55:31 +0200211mag2gds: check-env
212 echo "\
213 gds readonly true; \
214 gds rescale false; \
215 load caravel -dereference;\
216 select top cell;\
217 gds write caravel.gds; \
218 exit;" > ./mag/mag2gds_caravel.tcl
219 @cd mag && PDKPATH=${PDK_ROOT}/sky130A magic -noc -dnull mag2gds_caravel.tcl < /dev/null
220 @rm ./mag/mag2gds_caravel.tcl
221 mv -f ./gds/caravel.gds ./gds/caravel.old.gds
222 mv ./mag/caravel.gds ./gds
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200223
224.PHONY: help
225help:
226 @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
227
Ahmed Ghazyb1e51702020-12-31 22:43:41 +0200228
Ahmed Ghazyfdda2cb2020-12-04 02:00:38 +0200229###########################################################################
agorararmard212cd822020-11-26 22:40:17 +0200230.PHONY: pdk
agorararmarda32bd952020-12-31 21:38:43 +0200231pdk: skywater-pdk skywater-library skywater-timing open_pdks build-pdk
agorararmard212cd822020-11-26 22:40:17 +0200232
233$(PDK_ROOT)/skywater-pdk:
234 git clone https://github.com/google/skywater-pdk.git $(PDK_ROOT)/skywater-pdk
235
236.PHONY: skywater-pdk
237skywater-pdk: check-env $(PDK_ROOT)/skywater-pdk
238 cd $(PDK_ROOT)/skywater-pdk && \
agorararmard63e56722020-12-09 19:57:30 +0200239 git checkout master && git pull && \
agorararmard212cd822020-11-26 22:40:17 +0200240 git checkout -qf $(SKYWATER_COMMIT)
241
242.PHONY: skywater-library
243skywater-library: check-env $(PDK_ROOT)/skywater-pdk
244 cd $(PDK_ROOT)/skywater-pdk && \
245 git submodule update --init libraries/$(STD_CELL_LIBRARY)/latest && \
246 git submodule update --init libraries/$(IO_LIBRARY)/latest && \
agorararmarda32bd952020-12-31 21:38:43 +0200247 git submodule update --init libraries/$(SPECIAL_VOLTAGE_LIBRARY)/latest
agorararmard212cd822020-11-26 22:40:17 +0200248
agorararmarda32bd952020-12-31 21:38:43 +0200249skywater-timing: check-env $(PDK_ROOT)/skywater-pdk
250 cd $(PDK_ROOT)/skywater-pdk && \
251 $(MAKE) -j$(THREADS) timing
agorararmard212cd822020-11-26 22:40:17 +0200252### OPEN_PDKS
253$(PDK_ROOT)/open_pdks:
agorararmarde1ad4aa2021-01-05 20:28:45 +0200254 git clone git://opencircuitdesign.com/open_pdks $(PDK_ROOT)/open_pdks
agorararmard212cd822020-11-26 22:40:17 +0200255
256.PHONY: open_pdks
257open_pdks: check-env $(PDK_ROOT)/open_pdks
258 cd $(PDK_ROOT)/open_pdks && \
agorararmard63e56722020-12-09 19:57:30 +0200259 git checkout master && git pull && \
agorararmard212cd822020-11-26 22:40:17 +0200260 git checkout -qf $(OPEN_PDKS_COMMIT)
261
262.PHONY: build-pdk
263build-pdk: check-env $(PDK_ROOT)/open_pdks $(PDK_ROOT)/skywater-pdk
264 [ -d $(PDK_ROOT)/sky130A ] && \
265 (echo "Warning: A sky130A build already exists under $(PDK_ROOT). It will be deleted first!" && \
266 sleep 5 && \
267 rm -rf $(PDK_ROOT)/sky130A) || \
268 true
269 cd $(PDK_ROOT)/open_pdks && \
agorararmard8ced9ad2020-12-30 18:53:21 +0200270 ./configure --enable-sky130-pdk=$(PDK_ROOT)/skywater-pdk/libraries --with-sky130-local-path=$(PDK_ROOT) && \
agorararmard212cd822020-11-26 22:40:17 +0200271 cd sky130 && \
272 $(MAKE) veryclean && \
273 $(MAKE) && \
274 $(MAKE) install-local
275
agorararmard7eebfe42020-12-07 22:08:29 +0200276.RECIPE: manifest
277manifest:
278 cd verilog/rtl/ && \
agorararmardbd781832020-12-08 21:09:44 +0200279 find * -type f ! -name "user_*.v" ! -name "manifest" ! -name "README" ! -name "defines.v" -exec shasum {} \; > manifest && \
280 cd ../../maglef/ && \
281 shasum *.mag > manifest && \
282 cd ../mag/ && \
283 shasum caravel.mag .magicrc > manifest
284
agorararmard7eebfe42020-12-07 22:08:29 +0200285
agorararmard212cd822020-11-26 22:40:17 +0200286check-env:
287ifndef PDK_ROOT
288 $(error PDK_ROOT is undefined, please export it before running make)
Ahmed Ghazy31c34652020-12-01 19:59:44 +0200289endif
agorararmardcd6f0af2020-12-28 22:32:43 +0200290
291# Make README.rst
agorararmard97fe84f2020-12-28 23:32:41 +0200292README.rst: README.src.rst docs/source/getting-started.rst docs/source/tool-versioning.rst openlane/README.src.rst docs/source/caravel-with-openlane.rst Makefile
agorararmardcd6f0af2020-12-28 22:32:43 +0200293 pip -q install rst_include && \
294 rm -f README.rst && \
agorararmard2dfdac72020-12-29 16:19:56 +0200295 rst_include include README.src.rst - | \
296 sed \
297 -e's@\.\/\_static@\/docs\/source\/\_static@g' \
agorararmard6c935cb2020-12-30 16:32:04 +0200298 -e's@:doc:`tool-versioning`@`tool-versioning.rst <./docs/source/tool-versioning.rst>`__@g' \
agorararmard2dfdac72020-12-29 16:19:56 +0200299 -e's@.. note::@**NOTE:**@g' \
300 -e's@.. warning::@**WARNING:**@g' \
301 > README.rst && \
agorararmard6f660e02020-12-28 23:07:36 +0200302 rst_include include openlane/README.src.rst - | \
303 sed \
304 -e's@https://github.com/efabless/caravel/blob/master/verilog@../verilog@g' \
305 -e's@:ref:`getting-started`@`README.rst <../README.rst>`__@g' \
306 -e's@https://github.com/efabless/caravel/blob/master/openlane/@./@g' \
agorararmard2dfdac72020-12-29 16:19:56 +0200307 -e's@.. note::@**NOTE:**@g' \
308 -e's@.. warning::@**WARNING:**@g' \
agorararmard5deb5ed2020-12-29 18:00:17 +0200309 > openlane/README.rst