forked from moroso/cpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
226 lines (178 loc) · 7.34 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
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
RUNTIME := $(shell date +R%Y%m%d-%H%M%S)
RUN ?= $(RUNTIME)
RUNDIR ?= runs/$(RUN)
TESTPLANS ?= L0 L1
VER_CFLAGS=-g
include config.mk
-include $(HOME)/.quartus_config.mk
Q ?= quartus_
default:
@echo "targets:"
# @echo " sw builds software (must be run before fpga to build boot0)"
@echo " fpga runs a complete pass through the tool flow"
@echo " sim produces a Verilator binary"
@echo " tests runs tests"
@echo " sanity runs sanity-only tests"
@echo " auto re-autoizes all RTL"
@echo ""
@echo "expert targets:"
@echo " tb_... builds one testbench"
@echo " test_... runs one test"
@echo ""
@echo "variables:"
@echo " RUN=[...] name of run (for runs/ directory; defaults to date+time)"
@echo " STA=1 run static timing analysis"
@echo " PROG=1 download FPGA bitfile to board after compilation"
@echo " SVF=1 build SVF for distribution"
@echo " TESTPLANS=... testplans to run (for tests) (default: L0)"
@echo " TESTS=... tests tor run (for tests)"
@echo " TRACE=1 dump vcd file from test"
@echo ""
@echo "testplans available:"
@$(foreach testplan,$(ALL_TESTPLANS),echo " $(testplan): $(TESTPLAN_$(testplan)_name) (tests:$(TESTPLAN_$(testplan)_tests)) ";)
@echo ""
@echo "error: you must specify a valid target"
@exit 1
.PHONY: default
#sw: .DUMMY
# @make -C sw
###############################################################################
GREEN=\033[32;01m
RED=\033[31;01m
STOP=\033[0m
say = @echo -e "${GREEN}"$(1)"${STOP}"
err = @echo -e "${RED}"$(1)"${STOP}"
###############################################################################
.PHONY: symlinks
symlinks: $(RUNDIR)/stamps/symlinks
$(RUNDIR)/stamps/symlinks:
$(call say,Creating run symlinks)
@mkdir -p runs
if [ -h runs/run_0a ] ; then rm runs/run_1a; mv runs/run_0a runs/run_1a ; fi
ln -s $(RUN) runs/run_0a
@mkdir -p $(RUNDIR)/stamps
@touch $(RUNDIR)/stamps/symlinks
.PHONY: sim-symlinks
sim-symlinks: $(RUNDIR)/stamps/sim-symlinks
$(RUNDIR)/stamps/sim-symlinks: $(RUNDIR)/stamps/symlinks
if [ -h runs/sim_0a ] ; then rm runs/sim_1a; mv runs/sim_0a runs/sim_1a ; fi
ln -s $(RUN) runs/sim_0a
@touch $(RUNDIR)/stamps/sim-symlinks
.PHONY: sim-genrtl
sim-genrtl: $(RUNDIR)/stamps/sim-genrtl
$(RUNDIR)/stamps/sim-genrtl: sim-symlinks
$(call say,Copying RTL for simulation to $(RUNDIR)/sim/rtl...)
@mkdir -p $(RUNDIR)/stamps
@mkdir -p $(RUNDIR)/sim/rtl
@cp $(RTL_COMMON) $(RTL_SIM) $(RTL_INC) $(RUNDIR)/sim/rtl
$(call say,Copying testbench for simulation to $(RUNDIR)/sim...)
@cp -R sim/* $(RUNDIR)/sim
@touch $(RUNDIR)/stamps/sim-genrtl
# Here comes all the testplan mess.
# First, define the rules to build the testbenches.
define TB_template
$(RUNDIR)/sim/$(1)/V$$($(1)_top): $(RUNDIR)/stamps/sim-genrtl
$(call say,"Verilating testbench: $(1)")
cd $(RUNDIR)/sim; verilator -CFLAGS $(VER_CFLAGS) -Irtl --Mdir $(1) --cc $$(TB_$(1)_top) $$(TB_$(1)_cpps) --exe --assert $(if $(TRACE),--trace)
$(call say,"Compiling testbench: $(1)")
make -C $(RUNDIR)/sim/$(1) -f V$$(TB_$(1)_top).mk
.PHONY: tb_$(1)
tb_$(1): $(RUNDIR)/sim/$(1)/V$$($(1)_top)
endef
$(foreach tb,$(ALL_TBS),$(eval $(call TB_template,$(tb))))
TB_binary = ../../sim/$(1)/V$(TB_$(1)_top)
# Then, the rules to run tests.
define TEST_template
$(RUNDIR)/test/$(1)/log: tb_$$(TEST_$(1)_tb)
$(call say,"Running test: $(1)")
@mkdir -p $(RUNDIR)/test/$(1)
$$(if $$(TEST_$(1)_rom),cp $$(TEST_$(1)_rom) $(RUNDIR)/test/$(1)/bootrom.hex)
(cd $(RUNDIR)/test/$(1); $$(TEST_$(1)_env) $$(call TB_binary,$$(TEST_$(1)_tb)) > log)
.PHONY: test_$(1)
test_$(1): $(RUNDIR)/test/$(1)/log
endef
$(foreach test,$(ALL_TESTS),$(eval $(call TEST_template,$(test))))
# Finally, run the tests as requested.
TESTS += $(foreach testplan,$(TESTPLANS),$(TESTPLAN_$(testplan)_tests))
tests: $(foreach test,$(TESTS),$(RUNDIR)/test/$(test)/log)
sanity:
make tests TESTPLANS=L0
.PHONY: sim
sim:
$(call err,"There is no simulator right now: maybe you want to 'make tests'?")
###############################################################################
QPARAMS = $(FPGA_TOOL_BITS) --read_settings_files=off --write_settings_files=off $(FPGA_PROJ)
.PHONY: fpga-symlinks
fpga-symlinks: $(RUNDIR)/stamps/fpga-symlinks
$(RUNDIR)/stamps/fpga-symlinks: $(RUNDIR)/stamps/symlinks
if [ -h runs/fpga_0a ] ; then rm runs/fpga_1a; mv runs/fpga_0a runs/fpga_1a ; fi
ln -s $(RUN) runs/fpga_0a
@touch $(RUNDIR)/stamps/fpga-symlinks
# XXX: should we generate the .xst file?
.PHONY: fpga-genrtl
fpga-genrtl: $(RUNDIR)/stamps/fpga-genrtl
$(RUNDIR)/stamps/fpga-genrtl: $(RUNDIR)/stamps/fpga-symlinks
$(call say,"Copying RTL for synthesis to $(RUNDIR)/fpga/rtl...")
@mkdir -p $(RUNDIR)/stamps
@mkdir -p $(RUNDIR)/fpga/rtl
@cp $(RTL_COMMON) $(RTL_FPGA) $(RTL_INC) $(RUNDIR)/fpga/rtl
$(call say,"Copying FPGA configuration to $(RUNDIR)/fpga...")
@cp fpga/* $(RUNDIR)/fpga
@touch $(RUNDIR)/stamps/fpga-genrtl
.PHONY: fpga-map
fpga-map: $(RUNDIR)/stamps/fpga-map
$(RUNDIR)/stamps/fpga-map: $(RUNDIR)/stamps/fpga-genrtl
$(call say,"Running mapper in $(RUNDIR)/fpga...")
@touch $(RUNDIR)/stamps/fpga-map-start
cd $(RUNDIR)/fpga; $(Q)map $(FPGA_TOOL_BITS) --read_settings_files=on --write_settings_files=on $(FPGA_PROJ) $(addprefix --source=rtl/,$(notdir $(RTL_COMMON) $(RTL_FPGA)))
@touch $(RUNDIR)/stamps/fpga-map
.PHONY: fpga-fit
fpga-fit: $(RUNDIR)/stamps/fpga-fit
$(RUNDIR)/stamps/fpga-fit: $(RUNDIR)/stamps/fpga-map
$(call say,"Running fitter in $(RUNDIR)/fpga...")
@touch $(RUNDIR)/stamps/fpga-fit-start
cd $(RUNDIR)/fpga; $(Q)fit $(QPARAMS)
@touch $(RUNDIR)/stamps/fpga-fit
.PHONY: fpga-asm
fpga-asm: $(RUNDIR)/stamps/fpga-asm
$(RUNDIR)/stamps/fpga-asm: $(RUNDIR)/stamps/fpga-fit
$(call say,"Running assembler in $(RUNDIR)/fpga...")
@touch $(RUNDIR)/stamps/fpga-asm-start
cd $(RUNDIR)/fpga; $(Q)asm $(QPARAMS)
@touch $(RUNDIR)/stamps/fpga-asm
@echo -en "\n\n\n"
$(call say,"Bit file generated: $(RUNDIR)/fpga/output_files/$(FPGA_PROJ).sof")
@echo -en "\n\n\n"
.PHONY: fpga-sta
fpga-sta: $(RUNDIR)/stamps/fpga-sta
$(RUNDIR)/stamps/fpga-sta: $(RUNDIR)/stamps/fpga-fit
$(call say,"Running STA in $(RUNDIR)/fpga...")
@touch $(RUNDIR)/stamps/fpga-sta-start
cd $(RUNDIR)/fpga; $(Q)sta $(FPGA_PROJ)
@touch $(RUNDIR)/stamps/fpga-sta
$(RUNDIR)/fpga/output_files/$(FPGA_PROJ).sof: $(RUNDIR)/stamps/fpga-asm
.PHONY: fpga-svf
fpga-svf: $(RUNDIR)/fpga/output_files/$(FPGA_PROJ).svf
$(RUNDIR)/fpga/output_files/$(FPGA_PROJ).svf: $(RUNDIR)/fpga/output_files/$(FPGA_PROJ).sof
$(Q)cpf -c -q 33MHz -g 3.3 -n p $< $@
.PHONY: fpga-prog
fpga-prog: $(RUNDIR)/fpga/output_files/$(FPGA_PROJ).sof
$(Q)pgm -m JTAG -o p\;$<
.PHONY: fpga
fpga: $(RUNDIR)/stamps/fpga
$(RUNDIR)/stamps/fpga: fpga-asm $(if $(STA),fpga-sta) $(if $(SVF),fpga-svf) $(if $(PROG),fpga-prog)
@echo -en '\n\n\n'
$(call say,"Build complete!")
$(call say," Bit file location: $(RUNDIR)/fpga/output_files/$(FPGA_PROJ).sof")
@$(if $(SVF),$(call say," SVF file location: $(RUNDIR)/fpga/output_files/$(FPGA_PROJ).svf"))
@echo -en '\n\n\n'
@touch $(RUNDIR)/stamps/fpga
###############################################################################
.PHONY: auto
auto:
emacs -l utils/nogit.el -l utils/verilog-mode.el --batch $(RTL_COMMON) $(RTL_FPGA) $(RTL_SIM) -f verilog-batch-auto
.PHONY: unauto
unauto:
emacs -l utils/nogit.el -l utils/verilog-mode.el --batch $(RTL_COMMON) $(RTL_FPGA) $(RTL_SIM) -f verilog-batch-delete-auto
#tests:
# make -C tests