-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
160 lines (121 loc) · 4.26 KB
/
Makefile
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
# Copyright (c) 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Authors:
# - Philippe Sauter <[email protected]>
# Tools
BENDER ?= bender
PYTHON3 ?= python3
VERILATOR ?= /foss/tools/bin/verilator
YOSYS ?= yosys
OPENROAD ?= openroad
KLAYOUT ?= klayout
VSIM ?= vsim
REGGEN ?= $(PYTHON3) $(shell $(BENDER) path register_interface)/vendor/lowrisc_opentitan/util/regtool.py
# Directories
# directory of the path to the last called Makefile (this one)
PROJ_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
default: help
################
# Dependencies #
################
## Checkout/update dependencies using Bender
checkout:
$(BENDER) checkout
git submodule update --init --recursive
## Reset dependencies (without updating Bender.lock)
clean-deps:
rm -rf .bender
git submodule deinit -f --all
.PHONY: checkout clean-deps
############
# Software #
############
SW_HEX := sw/bin/helloworld.hex
$(SW_HEX): sw/*.c sw/*.h sw/*.S sw/*.ld
$(MAKE) -C sw/ compile
## Build the helloworld software
software: $(SW_HEX)
sw: $(SW_HEX)
.PHONY: software sw
##################
# RTL Simulation #
##################
# Questasim/Modelsim/vsim
VLOG_ARGS = -svinputport=compat
VSIM_ARGS = -t 1ns -voptargs=+acc
VSIM_ARGS += -suppress vsim-3009 -suppress vsim-8683 -suppress vsim-8386
vsim/compile_rtl.tcl: Bender.lock Bender.yml
$(BENDER) script vsim -t rtl -t vsim -t simulation -t verilator -DSYNTHESIS -DSIMULATION --vlog-arg="$(VLOG_ARGS)" > $@
vsim/compile_netlist.tcl: Bender.lock Bender.yml
$(BENDER) script vsim -t ihp13 -t vsim -t simulation -t verilator -t netlist_yosys -DSYNTHESIS -DSIMULATION > $@
## Simulate RTL using Questasim/Modelsim/vsim
vsim: vsim/compile_rtl.tcl $(SW_HEX)
rm -rf vsim/work
cd vsim; $(VSIM) -c -do "source compile_rtl.tcl; exit"
cd vsim; $(VSIM) +binary="$(realpath $(SW_HEX))" -gui tb_croc_soc $(VSIM_ARGS)
## Simulate netlist using Questasim/Modelsim/vsim
vsim-yosys: vsim/compile_netlist.tcl $(SW_HEX) yosys/out/croc_yosys_debug.v
rm -rf vsim/work
cd vsim; $(VSIM) -c -do "source compile_netlist.tcl; source compile_tech.tcl; exit"
cd vsim; $(VSIM) -gui tb_croc_soc $(VSIM_ARGS)
# Verilator
VERILATOR_ARGS = --binary -j 0 -Wno-fatal
VERILATOR_ARGS += -Wno-style
VERILATOR_ARGS += --timing --autoflush --trace --trace-structs
verilator/croc.f: Bender.lock Bender.yml
$(BENDER) script verilator -t rtl -t verilator -DSYNTHESIS -DVERILATOR > $@
## Simulate RTL using Verilator
verilator/obj_dir/Vtb_croc_soc: verilator/croc.f $(SW_HEX)
cd verilator; $(VERILATOR) $(VERILATOR_ARGS) -CFLAGS "-O0" --top tb_croc_soc -f croc.f
verilator: verilator/obj_dir/Vtb_croc_soc
cd verilator; obj_dir/Vtb_croc_soc +binary="$(realpath $(SW_HEX))"
.PHONY: verilator vsim vsim-yosys verilator-yosys
####################
# Open Source Flow #
####################
TOP_DESIGN ?= croc_chip
DUT_DESIGN ?= croc_soc
BENDER_TARGETS ?= asic ihp13 rtl synthesis
SV_DEFINES ?= VERILATOR SYNTHESIS TARGET_ASIC TARGET_SYNTHESIS COMMON_CELLS_ASSERTS_OFF
PICKLE_OUT ?= $(PROJ_DIR)/pickle
SV_FLIST ?= $(PROJ_DIR)/croc.flist
# generate file list given to yosys-slang frontend
$(SV_FLIST): Bender.lock Bender.yml rtl/*/Bender.yml
$(BENDER) script flist-plus $(foreach t,$(BENDER_TARGETS),-t $(t)) $(foreach d,$(SV_DEFINES),-D $(d)=1) > $@
include yosys/yosys.mk
include openroad/openroad.mk
klayout/croc_chip.gds: $(OR_OUT)/croc.def klayout/*.sh klayout/*.py
./klayout/def2gds.sh
klayout: klayout/croc_chip.gds
.PHONY: klayout
#################
# Documentation #
#################
help: Makefile
@printf "Available targets:\n------------------\n"
@for mkfile in $(MAKEFILE_LIST); do \
awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-20s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $$mkfile; \
done
.PHONY: help
###########
# Cleanup #
###########
clean:
rm -f $(SV_FLIST)
rm -f klayout/croc_chip.gds
rm -rf verilator/obj_dir/
rm -f verilator/croc.f
rm -f verilator/croc.vcd
$(MAKE) ys_clean
$(MAKE) or_clean
.PHONY: clean