-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
322 lines (298 loc) · 9.19 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
################################################################################
##
## Filename: Makefile
## {{{
## Project: KIMOS, a Mercury KX2 demonstration project
##
## Purpose: A master project makefile. It tries to build all targets
## within the project, mostly by directing subdirectory makes.
##
## Creator: Dan Gisselquist, Ph.D.
## Gisselquist Technology, LLC
##
################################################################################
## }}}
## Copyright (C) 2024, Gisselquist Technology, LLC
## {{{
## This file is part of the KIMOS project.
##
## The KIMOS project is free software and gateware: you can redistribute it
## and/or modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation, either version 3 of the License,
## or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program. (It's in the $(ROOT)/doc directory. Run make with no
## target there if the PDF file isn't present.) If not, see
## <http://www.gnu.org/licenses/> for a copy.
## }}}
## License: GPL, v3, as defined and found on www.gnu.org,
## {{{
## http://www.gnu.org/licenses/gpl.html
##
################################################################################
##
## }}}
.PHONY: all
all: check-install datestamp autodata sim sw
#
# Defines and directories
## {{{
AUTOD := autodata
SIMD := sim
#
# Could also depend upon load, if desired, but not necessary
BENCH := # `find bench -name Makefile` `find bench -name "*.cpp"` `find bench -name "*.h"`
SIM := `find sim -name Makefile` `find sim -name "*.cpp"` `find sim -name "*.h"` `find sim -name "*.c"`
RTL := `find rtl -name "*.v"` `find rtl -name Makefile`
NOTES := `find . -name "*.txt"` `find . -name "*.html"`
SW := `find sw -name "*.cpp"` `find sw -name "*.c"` \
`find sw -name "*.h"` `find sw -name "*.sh"` \
`find sw -name "*.py"` `find sw -name "*.pl"` \
`find sw -name "*.png"` `find sw -name Makefile`
DEVSW := `find sw/board -name "*.cpp"` `find sw/board -name "*.h"` \
`find sw/board -name Makefile`
PROJ :=
BIN := # `find xilinx -name "*.bit"`
AUTODATA := `find $(AUTOD) -name "*.txt"` `find $(AUTOD) -name Makefile`
CONSTRAINTS := `find . -name "*.xdc"`
YYMMDD:=`date +%Y%m%d`
SUBMAKE:= $(MAKE) --no-print-directory -C
LOADER:= openFPGALoader
## }}}
##
## Check that we have all the programs available to us that we need
## {{{
#
.PHONY: check-install
check-install: check-perl check-autofpga check-verilator check-zip-gcc check-gpp check-loader
.PHONY: check-perl
$(call checkif-installed,perl,)
.PHONY: check-autofpga
check-autofpga:
$(call checkif-installed,autofpga,-V)
.PHONY: check-verilator
check-verilator:
$(call checkif-installed,verilator,-V)
.PHONY: check-zip-gcc
check-zip-gcc:
$(call checkif-installed,zip-gcc,-v)
.PHONY: check-gpp
check-gpp:
$(call checkif-installed,g++,-v)
.PHONY: check-loader
check-loader:
$(call checkif-installed,openFPGALoader,-V)
## }}}
#
#
# Now that we know that all of our required components exist, we can build
# things
#
#
.PHONY: datestamp
## {{{
# Create a datestamp file, so that we can check for the build-date when the
# project was put together.
#
datestamp: check-perl
@bash -c 'if [ ! -e $(YYMMDD)-build.v ]; then rm -f 20??????-build.v; perl mkdatev.pl > $(YYMMDD)-build.v; rm -f rtl/builddate.v; fi'
@bash -c 'if [ ! -e rtl/builddate.v ]; then cd rtl; cp ../$(YYMMDD)-build.v builddate.v; fi'
## }}}
.PHONY: archive
## {{{
#
## Make a tar archive of this file, as a poor mans version of source code
## control. (Sorry ... I've been burned too many times by files I've wiped
## away ...)
#
ARCHIVEFILES := $(BENCH) $(SW) $(RTL) $(SIM) $(NOTES) $(PROJ) $(BIN) $(CONSTRAINTS) $(AUTODATA) README.md
archive:
tar --transform s,^,$(YYMMDD)-tii/, --exclude=dump.txt --exclude=trace.vcd -chjf $(YYMMDD)-tii.tjz $(ARCHIVEFILES)
## }}}
################################################################################
##
## Auto-FPGA
## {{{
.PHONY: autodata
## Build our main (and toplevel) Verilog files via autofpga
##
autodata: check-autofpga
$(SUBMAKE) $(AUTOD)
$(call copyif-changed,$(AUTOD)/toplevel.v,rtl/toplevel.v)
$(call copyif-changed,$(AUTOD)/main.v,rtl/main.v)
$(call copyif-changed,$(AUTOD)/iscachable.v,rtl/iscachable.v)
$(call copyif-changed,$(AUTOD)/build.xdc,rtl/board.xdc)
$(call copyif-changed,$(AUTOD)/regdefs.h,sw/host/regdefs.h)
$(call copyif-changed,$(AUTOD)/regdefs.cpp,sw/host/regdefs.cpp)
$(call copyif-changed,$(AUTOD)/board.h,sw/zlib/board.h)
$(call copyif-changed,$(AUTOD)/board.h,sw/board/board.h)
$(call copyif-changed,$(AUTOD)/bkram.ld,sw/board/bkram.ld)
$(call copyif-changed,$(AUTOD)/board.ld,sw/board/board.ld)
$(call copyif-changed,$(AUTOD)/sdram.ld,sw/board/sdram.ld)
$(call copyif-changed,$(AUTOD)/rtl.make.inc,rtl/make.inc)
$(call copyif-changed,$(AUTOD)/testb.h,$(SIMD)/testb.h)
$(call copyif-changed,$(AUTOD)/main_tb.cpp,$(SIMD)/main_tb.cpp)
.PHONY: altauto
## Build our main (and toplevel) Verilog files via autofpga
##
altauto: check-autofpga
$(SUBMAKE) $(AUTOD) lddata
$(call copyif-changed,$(AUTOD)/toplevel.v,rtl/toplevel.v)
$(call copyif-changed,$(AUTOD)/main.v,rtl/main.v)
$(call copyif-changed,$(AUTOD)/iscachable.v,rtl/iscachable.v)
$(call copyif-changed,$(AUTOD)/build.xdc,rtl/board.xdc)
$(call copyif-changed,$(AUTOD)/regdefs.h,sw/host/regdefs.h)
$(call copyif-changed,$(AUTOD)/regdefs.cpp,sw/host/regdefs.cpp)
$(call copyif-changed,$(AUTOD)/board.h,sw/zlib/board.h)
$(call copyif-changed,$(AUTOD)/board.h,sw/board/board.h)
$(call copyif-changed,$(AUTOD)/bkram.ld,sw/board/bkram.ld)
$(call copyif-changed,$(AUTOD)/board.ld,sw/board/board.ld)
$(call copyif-changed,$(AUTOD)/rtl.make.inc,rtl/make.inc)
$(call copyif-changed,$(AUTOD)/testb.h,$(SIMD)/testb.h)
$(call copyif-changed,$(AUTOD)/main_tb.cpp,$(SIMD)/main_tb.cpp)
## }}}
################################################################################
##
## RTL: Lint RTL, Verilate, build bit file, etc.
## {{{
.PHONY: verilated rtl
#
# Verify that the rtl has no bugs in it, while also creating a Verilator
# simulation class library that we can then use for simulation
#
verilated: datestamp check-verilator
+@$(SUBMAKE) rtl
.PHONY: rtl
rtl: verilated
.PHONY: bit
bit:
cd xilinx ; $(MAKE) --no-print-directory xula.bit
## }}}
################################################################################
##
## Simulation target
## {{{
## Build a simulation of this entire design
## (Running it will be part of the test target below)
##
.PHONY: sim
sim: rtl check-gpp
+@$(SUBMAKE) $(SIMD)
## }}}
################################################################################
##
## Software targets
## {{{
##
## A master target to build all of the support software
##
.PHONY: sw
sw: sw-host sw-zlib sw-board # sw-boot
.PHONY: sw-host
## {{{
##
## Build the host support software
##
sw-host: check-gpp rtl
+@$(SUBMAKE) sw/host
## }}}
.PHONY: sw-zlib
## {{{
##
## Build the hardware specific newlib library
##
sw-zlib: check-zip-gcc rtl
+@$(SUBMAKE) sw/zlib
## }}}
.PHONY: sw-fatfs
## {{{
sw-fatfs: check-zip-gcc rtl
+@$(SUBMAKE) sw/fatfs
## }}}
.PHONY: sw-board
## {{{
## Build the board software. This may (or may not) use the software library
##
sw-board: sw-zlib sw-fatfs check-zip-gcc rtl
+@$(SUBMAKE) sw/board
## }}}
.PHONY: sw-boot
## {{{
##
## Build the boot software. This would allow us to boot from an SD card,
## however ... this project doesn't currently use it.
##
## sw-boot: check-zip-gcc sw-zlib
## +@$(SUBMAKE) sw/boot
## }}}
## }}}
################################################################################
##
## Test targets
## {{{
.PHONY: test
#
# Run "Hello World", and ... see if this all works
#
#.PHONY: hello
#hello: sim sw
# $(SIMD)/main_tb sw/board/hello
# .PHONY: sdtest
# sdtest: sim sw
# $(SIMD)/main_tb sw/board/sdtest
#test: hello
## }}}
################################################################################
##
## Load the device
## {{{
## BITFILE := blinky.bit
BITFILE := kimos.bit
$(BITFILE): ../xilinx/kimos.runs/impl_1/toplevel.bit
@cp $< $@
.PHONY: load
load: $(BITFILE)
$(LOADER) --freq 3750000 --ftdi-serial FTENC $(BITFILE)
## }}}
################################################################################
##
## Macro definitions
## {{{
# copyif-changed
## {{{
##
## Copy a file from the auto-data directory that had been created by
## autofpga, into the directory structure where it might be used.
##
define copyif-changed
@bash -c 'cmp $(1) $(2); if [[ $$? != 0 ]]; then echo "Copying $(1) to $(2)"; cp $(1) $(2); fi'
endef
## }}}
# checkif-installed
## {{{
##
## Check if the given program is installed
##
define checkif-installed
@bash -c '$(1) $(2) < /dev/null >& /dev/null; if [[ $$? != 0 ]]; then echo "Program not found: $(1)"; exit -1; fi'
endef
## }}}
## }}}
################################################################################
##
.PHONY: clean
## {{{
clean:
+$(SUBMAKE) $(AUTOD) clean
+$(SUBMAKE) $(SIMD) clean
+$(SUBMAKE) rtl clean
+$(SUBMAKE) sw/zlib clean
+$(SUBMAKE) sw/board clean
+$(SUBMAKE) sw/host clean
## }}}