blob: 7d4e1c1518d676c59c1e3ababfa0f29f3cd6f491 [file] [log] [blame]
Yifei Zhuc7654b72022-11-24 01:02:46 +08001# 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
16MAKEFLAGS+=--warn-undefined-variables
17
18export CARAVEL_ROOT?=$(PWD)/caravel
19PRECHECK_ROOT?=${HOME}/mpw_precheck
20export MCW_ROOT?=$(PWD)/mgmt_core_wrapper
21SIM?=RTL
22
23# Install lite version of caravel, (1): caravel-lite, (0): caravel
24CARAVEL_LITE?=1
25
26# PDK switch varient
27export PDK?=sky130A
28#export PDK?=gf180mcuC
29export PDKPATH?=$(PDK_ROOT)/$(PDK)
30
31
32
33ifeq ($(PDK),sky130A)
34 SKYWATER_COMMIT=f70d8ca46961ff92719d8870a18a076370b85f6c
35 export OPEN_PDKS_COMMIT?=0059588eebfc704681dc2368bd1d33d96281d10f
36 export OPENLANE_TAG?=2022.11.19
37 MPW_TAG ?= mpw-8b
38
39ifeq ($(CARAVEL_LITE),1)
40 CARAVEL_NAME := caravel-lite
41 CARAVEL_REPO := https://github.com/efabless/caravel-lite
42 CARAVEL_TAG := $(MPW_TAG)
43else
44 CARAVEL_NAME := caravel
45 CARAVEL_REPO := https://github.com/efabless/caravel
46 CARAVEL_TAG := $(MPW_TAG)
47endif
48
49endif
50
51ifeq ($(PDK),sky130B)
52 SKYWATER_COMMIT=f70d8ca46961ff92719d8870a18a076370b85f6c
53 export OPEN_PDKS_COMMIT?=0059588eebfc704681dc2368bd1d33d96281d10f
54 export OPENLANE_TAG?=2022.11.19
55 MPW_TAG ?= mpw-8b
56
57ifeq ($(CARAVEL_LITE),1)
58 CARAVEL_NAME := caravel-lite
59 CARAVEL_REPO := https://github.com/efabless/caravel-lite
60 CARAVEL_TAG := $(MPW_TAG)
61else
62 CARAVEL_NAME := caravel
63 CARAVEL_REPO := https://github.com/efabless/caravel
64 CARAVEL_TAG := $(MPW_TAG)
65endif
66
67endif
68
69ifeq ($(PDK),gf180mcuC)
70
71 MPW_TAG ?= gfmpw-0b
72 CARAVEL_NAME := caravel
73 CARAVEL_REPO := https://github.com/efabless/caravel-gf180mcu
74 CARAVEL_TAG := $(MPW_TAG)
75 #OPENLANE_TAG=ddfeab57e3e8769ea3d40dda12be0460e09bb6d9
76 export OPEN_PDKS_COMMIT?=0059588eebfc704681dc2368bd1d33d96281d10f
77 export OPENLANE_TAG?=2022.11.19
78
79endif
80
81# Include Caravel Makefile Targets
82.PHONY: % : check-caravel
83%:
84 export CARAVEL_ROOT=$(CARAVEL_ROOT) && $(MAKE) -f $(CARAVEL_ROOT)/Makefile $@
85
86.PHONY: install
87install:
88 if [ -d "$(CARAVEL_ROOT)" ]; then\
89 echo "Deleting exisiting $(CARAVEL_ROOT)" && \
90 rm -rf $(CARAVEL_ROOT) && sleep 2;\
91 fi
92 echo "Installing $(CARAVEL_NAME).."
93 git clone -b $(CARAVEL_TAG) $(CARAVEL_REPO) $(CARAVEL_ROOT) --depth=1
94
95# Install DV setup
96.PHONY: simenv
97simenv:
98 docker pull efabless/dv:latest
99
100.PHONY: setup
101setup: install check-env install_mcw openlane pdk-with-volare setup-timing-scripts
102
103# Openlane
104blocks=$(shell cd openlane && find * -maxdepth 0 -type d)
105.PHONY: $(blocks)
106$(blocks): % :
107 $(MAKE) -C openlane $*
108
109dv_patterns=$(shell cd verilog/dv && find * -maxdepth 0 -type d)
110dv-targets-rtl=$(dv_patterns:%=verify-%-rtl)
111dv-targets-gl=$(dv_patterns:%=verify-%-gl)
112dv-targets-gl-sdf=$(dv_patterns:%=verify-%-gl-sdf)
113
114TARGET_PATH=$(shell pwd)
115verify_command="source ~/.bashrc && cd ${TARGET_PATH}/verilog/dv/$* && export SIM=${SIM} && make"
116dv_base_dependencies=simenv
117docker_run_verify=\
118 docker run -v ${TARGET_PATH}:${TARGET_PATH} -v ${PDK_ROOT}:${PDK_ROOT} \
119 -v ${CARAVEL_ROOT}:${CARAVEL_ROOT} \
120 -e TARGET_PATH=${TARGET_PATH} -e PDK_ROOT=${PDK_ROOT} \
121 -e CARAVEL_ROOT=${CARAVEL_ROOT} \
122 -e TOOLS=/foss/tools/riscv-gnu-toolchain-rv32i/217e7f3debe424d61374d31e33a091a630535937 \
123 -e DESIGNS=$(TARGET_PATH) \
124 -e USER_PROJECT_VERILOG=$(TARGET_PATH)/verilog \
125 -e PDK=$(PDK) \
126 -e CORE_VERILOG_PATH=$(TARGET_PATH)/mgmt_core_wrapper/verilog \
127 -e CARAVEL_VERILOG_PATH=$(TARGET_PATH)/caravel/verilog \
128 -e MCW_ROOT=$(MCW_ROOT) \
129 -u $$(id -u $$USER):$$(id -g $$USER) efabless/dv:latest \
130 sh -c $(verify_command)
131
132.PHONY: harden
133harden: $(blocks)
134
135.PHONY: verify
136verify: $(dv-targets-rtl)
137
138.PHONY: verify-all-rtl
139verify-all-rtl: $(dv-targets-rtl)
140
141.PHONY: verify-all-gl
142verify-all-gl: $(dv-targets-gl)
143
144.PHONY: verify-all-gl-sdf
145verify-all-gl-sdf: $(dv-targets-gl-sdf)
146
147$(dv-targets-rtl): SIM=RTL
148$(dv-targets-rtl): verify-%-rtl: $(dv_base_dependencies)
149 $(docker_run_verify)
150
151$(dv-targets-gl): SIM=GL
152$(dv-targets-gl): verify-%-gl: $(dv_base_dependencies)
153 $(docker_run_verify)
154
155$(dv-targets-gl-sdf): SIM=GL_SDF
156$(dv-targets-gl-sdf): verify-%-gl-sdf: $(dv_base_dependencies)
157 $(docker_run_verify)
158
159clean-targets=$(blocks:%=clean-%)
160.PHONY: $(clean-targets)
161$(clean-targets): clean-% :
162 rm -f ./verilog/gl/$*.v
163 rm -f ./spef/$*.spef
164 rm -f ./sdc/$*.sdc
165 rm -f ./sdf/$*.sdf
166 rm -f ./gds/$*.gds
167 rm -f ./mag/$*.mag
168 rm -f ./lef/$*.lef
169 rm -f ./maglef/*.maglef
170
171make_what=setup $(blocks) $(dv-targets-rtl) $(dv-targets-gl) $(dv-targets-gl-sdf) $(clean-targets)
172.PHONY: what
173what:
174 # $(make_what)
175
176# Install Openlane
177.PHONY: openlane
178openlane:
179 @if [ "$$(realpath $${OPENLANE_ROOT})" = "$$(realpath $$(pwd)/openlane)" ]; then\
180 echo "OPENLANE_ROOT is set to '$$(pwd)/openlane' which contains openlane config files"; \
181 echo "Please set it to a different directory"; \
182 exit 1; \
183 fi
184 cd openlane && $(MAKE) openlane
185
186#### Not sure if the targets following are of any use
187
188# Create symbolic links to caravel's main files
189.PHONY: simlink
190simlink: check-caravel
191### Symbolic links relative path to $CARAVEL_ROOT
192 $(eval MAKEFILE_PATH := $(shell realpath --relative-to=openlane $(CARAVEL_ROOT)/openlane/Makefile))
193 $(eval PIN_CFG_PATH := $(shell realpath --relative-to=openlane/user_project_wrapper $(CARAVEL_ROOT)/openlane/user_project_wrapper_empty/pin_order.cfg))
194 mkdir -p openlane
195 mkdir -p openlane/user_project_wrapper
196 cd openlane &&\
197 ln -sf $(MAKEFILE_PATH) Makefile
198 cd openlane/user_project_wrapper &&\
199 ln -sf $(PIN_CFG_PATH) pin_order.cfg
200
201# Update Caravel
202.PHONY: update_caravel
203update_caravel: check-caravel
204 cd $(CARAVEL_ROOT)/ && git checkout $(CARAVEL_TAG) && git pull
205
206# Uninstall Caravel
207.PHONY: uninstall
208uninstall:
209 rm -rf $(CARAVEL_ROOT)
210
211
212# Install Pre-check
213# Default installs to the user home directory, override by "export PRECHECK_ROOT=<precheck-installation-path>"
214.PHONY: precheck
215precheck:
216 @git clone --depth=1 --branch $(MPW_TAG) https://github.com/efabless/mpw_precheck.git $(PRECHECK_ROOT)
217 @docker pull efabless/mpw_precheck:latest
218
219.PHONY: run-precheck
220run-precheck: check-pdk check-precheck
221 $(eval INPUT_DIRECTORY := $(shell pwd))
222 cd $(PRECHECK_ROOT) && \
223 docker run -v $(PRECHECK_ROOT):$(PRECHECK_ROOT) \
224 -v $(INPUT_DIRECTORY):$(INPUT_DIRECTORY) \
225 -v $(PDK_ROOT):$(PDK_ROOT) \
226 -e INPUT_DIRECTORY=$(INPUT_DIRECTORY) \
227 -e PDK_PATH=$(PDK_ROOT)/$(PDK) \
228 -e PDK_ROOT=$(PDK_ROOT) \
229 -e PDKPATH=$(PDKPATH) \
230 -u $(shell id -u $(USER)):$(shell id -g $(USER)) \
231 efabless/mpw_precheck:latest bash -c "cd $(PRECHECK_ROOT) ; python3 mpw_precheck.py --input_directory $(INPUT_DIRECTORY) --pdk_path $(PDK_ROOT)/$(PDK)"
232
233
234
235.PHONY: clean
236clean:
237 cd ./verilog/dv/ && \
238 $(MAKE) -j$(THREADS) clean
239
240check-caravel:
241 @if [ ! -d "$(CARAVEL_ROOT)" ]; then \
242 echo "Caravel Root: "$(CARAVEL_ROOT)" doesn't exists, please export the correct path before running make. "; \
243 exit 1; \
244 fi
245
246check-precheck:
247 @if [ ! -d "$(PRECHECK_ROOT)" ]; then \
248 echo "Pre-check Root: "$(PRECHECK_ROOT)" doesn't exists, please export the correct path before running make. "; \
249 exit 1; \
250 fi
251
252check-pdk:
253 @if [ ! -d "$(PDK_ROOT)" ]; then \
254 echo "PDK Root: "$(PDK_ROOT)" doesn't exists, please export the correct path before running make. "; \
255 exit 1; \
256 fi
257
258.PHONY: help
259help:
260 cd $(CARAVEL_ROOT) && $(MAKE) help
261 @$(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 '^$@$$'
262
263
264export CUP_ROOT=$(shell pwd)
265export TIMING_ROOT?=$(shell pwd)/deps/timing-scripts
266export PROJECT_ROOT=$(CUP_ROOT)
267timing-scripts-repo=https://github.com/efabless/timing-scripts.git
268
269$(TIMING_ROOT):
270 @mkdir -p $(CUP_ROOT)/deps
271 @git clone $(timing-scripts-repo) $(TIMING_ROOT)
272
273.PHONY: setup-timing-scripts
274setup-timing-scripts: $(TIMING_ROOT)
275 @( cd $(TIMING_ROOT) && git pull )
276 @#( cd $(TIMING_ROOT) && git fetch && git checkout $(MPW_TAG); )
277 @python3 -m venv ./venv
278 . ./venv/bin/activate && \
279 python3 -m pip install --upgrade pip && \
280 python3 -m pip install -r $(TIMING_ROOT)/requirements.txt && \
281 deactivate
282
283./verilog/gl/user_project_wrapper.v:
284 $(error you don't have $@)
285
286./env/spef-mapping.tcl:
287 @echo "run the following:"
288 @echo "make extract-parasitics"
289 @echo "make create-spef-mapping"
290 exit 1
291
292.PHONY: create-spef-mapping
293create-spef-mapping: ./verilog/gl/user_project_wrapper.v
294 @. ./venv/bin/activate && \
295 python3 $(TIMING_ROOT)/scripts/generate_spef_mapping.py \
296 -i ./verilog/gl/user_project_wrapper.v \
297 -o ./env/spef-mapping.tcl \
298 --pdk-path $(PDK_ROOT)/$(PDK) \
299 --macro-parent mprj \
300 --project-root "$(CUP_ROOT)" && \
301 deactivate
302
303.PHONY: extract-parasitics
304extract-parasitics: ./verilog/gl/user_project_wrapper.v
305 @. ./venv/bin/activate && \
306 python3 $(TIMING_ROOT)/scripts/get_macros.py \
307 -i ./verilog/gl/user_project_wrapper.v \
308 -o ./tmp-macros-list \
309 --project-root "$(CUP_ROOT)" \
310 --pdk-path $(PDK_ROOT)/$(PDK) && \
311 deactivate
312 @cat ./tmp-macros-list | cut -d " " -f2 \
313 | xargs -I % bash -c "$(MAKE) -C $(TIMING_ROOT) \
314 -f $(TIMING_ROOT)/timing.mk rcx-% || echo 'Cannot extract %. Probably no def for this macro'"
315 @$(MAKE) -C $(TIMING_ROOT) -f $(TIMING_ROOT)/timing.mk rcx-user_project_wrapper
316 @cat ./tmp-macros-list
317 @rm ./tmp-macros-list
318
319.PHONY: caravel-sta
320caravel-sta: ./env/spef-mapping.tcl
321 @$(MAKE) -C $(TIMING_ROOT) -f $(TIMING_ROOT)/timing.mk caravel-timing-typ
322 @$(MAKE) -C $(TIMING_ROOT) -f $(TIMING_ROOT)/timing.mk caravel-timing-fast
323 @$(MAKE) -C $(TIMING_ROOT) -f $(TIMING_ROOT)/timing.mk caravel-timing-slow
324 @echo "You can find results for all corners in $(CUP_ROOT)/signoff/caravel/openlane-signoff/timing/"