-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
164 lines (124 loc) · 4.53 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
161
162
163
164
# 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
MORTY ?= morty
SVASE ?= svase
SV2V ?= sv2v
PYTHON3 ?= python3
VERILATOR ?= /foss/tools/bin/verilator
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 := /sw/bin/helloworld.hex
$(SW):
$(MAKE) -C sw/ compile
## Build the helloworld software
software: $(SW)
sw: $(SW)
.PHONY: software
##################
# 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 > $@
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)
rm -rf vsim/work
cd vsim; $(VSIM) -c -do "source compile_rtl.tcl; exit"
cd vsim; $(VSIM) -gui tb_croc_soc $(VSIM_ARGS)
## Simulate netlist using Questasim/Modelsim/vsim
vsim-yosys: vsim/compile_netlist.tcl $(SW) 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)
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
.PHONY: verilator vsim vsim-yosys verilator-yosys
####################
# Open Source Flow #
####################
TOP_DESIGN ?= croc_chip
DUT_DESIGN ?= croc_soc
BENDER_TARGETS ?= asic ihp13 rtl synthesis verilator
MORTY_DEFINES ?= VERILATOR SYNTHESIS MORTY TARGET_ASIC TARGET_SYNTHESIS
PICKLE_OUT ?= $(PROJ_DIR)/pickle
# list of source files
$(PICKLE_OUT)/croc_sources.json: Bender.lock Bender.yml rtl/*/Bender.yml
mkdir -p pickle
$(BENDER) sources -f $(foreach t,$(BENDER_TARGETS),-t $(t)) > $@
# pickle source files into one file/context
$(PICKLE_OUT)/croc_morty.sv: $(PICKLE_OUT)/croc_sources.json rtl/* ihp13/*.sv
$(MORTY) -q -f $< -o $@ $(foreach d,$(MORTY_DEFINES),-D $(d)=1)
# simplify SystemVerilog by propagating parameters and unfolding generate statements
$(PICKLE_OUT)/croc_svase.sv: $(PICKLE_OUT)/croc_morty.sv
$(SVASE) $(TOP_DESIGN) $@ $<
sed -i 's/module $(TOP_DESIGN)__[[:digit:]]\+/module $(TOP_DESIGN)/' $@
sed -i 's/ $(DUT_DESIGN)__[[:digit:]]\+ / $(DUT_DESIGN) /' $@
# convert SystemVerilog to Verilog
$(PICKLE_OUT)/croc_sv2v.v: $(PICKLE_OUT)/croc_svase.sv
$(SV2V) --oversized-numbers --write $@ $<
.PHONY: pickle
## Generate verilog file for synthesis
pickle: $(PICKLE_OUT)/croc_sv2v.v
include ihp13/technology.mk
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