-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
465 lines (343 loc) · 12.4 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
################################################
#
# Makefile to Manage QuartusII/QSys Design
#
# Copyright Altera (c) 2013
# All Rights Reserved
#
################################################
SHELL := /bin/bash
################################################
# Tools
CAT := cat
CD := cd
CHMOD := chmod
CP := cp -rf
ECHO := echo
DATE := date
HEAD := head
MKDIR := mkdir -p
MV := mv
RM := rm -rf
SED := sed
TAR := tar
TOUCH := touch
# Helpful Macros
SPACE := $(empty) $(empty)
################################################
################################################
.PHONY: default
default: help
################################################
################################################
.PHONY: all
all: sof rbf preloader uboot dtb
################################################
################################################
# Target Stamping
ACDS_VERSION := $(shell quartus_cmd -version 2>/dev/null | grep Version | $(HEAD) -n1 | $(SED) -e 's,^Version[ \t]*\([0-9.]*\).*,\1,g' 2>/dev/null)
define get_stamp_dir
stamp$(if $(ACDS_VERSION),/$(ACDS_VERSION))
endef
define get_stamp_target
$(get_stamp_dir)$(if $1,/$1.stamp,$(error ERROR: Arg 1 missing to $0 function))
endef
define stamp_target
@$(MKDIR) $(@D)
@$(TOUCH) $@
endef
.PHONY: clean
clean:
@$(ECHO) "Cleaning stamp files (which will trigger rebuild)"
@$(RM) $(get_stamp_dir)
@$(ECHO) " TIP: Use 'make scrub_clean' to get a deeper clean"
################################################
################################################
# Archiving & Cleaning your QuartusII/QSys Project
AR_TIMESTAMP := $(if $(ACDS_VERSION),$(subst .,_,$(ACDS_VERSION))_)$(subst $(SPACE),,$(shell $(DATE) +%m%d%Y_%k%M%S))
AR_DIR := tgz
AR_FILE := $(AR_DIR)/$(basename $(firstword $(wildcard *.qpf)))_$(AR_TIMESTAMP).tar.gz
PRELOADER_DIR := software/preloader
AR_REGEX := \
Makefile ip readme.txt ds5 \
altera_avalon* *.qpf *.qsf *.sdc *.v *.sv *.vhd *.qsys *.tcl *.stp *.sed quartus.ini \
*.sof *.rbf *.sopcinfo *.jdi output_files \
hps_isw_handoff */*.svd */synthesis/*.svd *.dts *.dtb *.xml \
$(PRELOADER_DIR)/preloader-mkpimage.bin \
$(PRELOADER_DIR)/uboot-socfpga/u-boot.img \
$(PRELOADER_DIR)/uboot-socfpga/spl/u-boot-spl \
$(PRELOADER_DIR)/uboot-socfpga/u-boot \
$(PRELOADER_DIR)/preloader.ds \
$(PRELOADER_DIR)/uboot.ds
AR_FILTER_OUT = %_tb.qsys
AR_FILES = $(filter-out $(AR_FILTER_OUT),$(wildcard $(AR_REGEX)))
CLEAN_FILES += $(filter-out $(AR_DIR) $(AR_FILES),$(wildcard *))
CLEAN_FILES += $(wildcard .qsys_edit)
HELP_TARGETS += tgz
tgz.HELP := Create a tarball with the barebones source files that comprise this design
.PHONY: tarball tgz
tarball tgz: $(AR_FILE)
$(AR_FILE):
@$(MKDIR) $(@D)
@$(if $(wildcard $(@D)/*.tar.gz),$(MKDIR) $(@D)/.archive;$(MV) $(@D)/*.tar.gz $(@D)/.archive)
@$(ECHO) "Generating $@..."
@$(TAR) -czf $@ $(AR_FILES)
HELP_TARGETS += scrub_clean
scrub_clean.HELP := Restore design to its barebones state
.PHONY: scrub scrub_clean
scrub scrub_clean:
$(if $(strip $(CLEAN_FILES)),$(RM) $(CLEAN_FILES),@$(ECHO) "You're already as clean as it gets!")
.PHONY: tgz_scrub_clean
tgz_scrub_clean:
$(MAKE) tgz AR_FILE=$(AR_FILE)
$(MAKE) -s scrub_clean
$(TAR) -xzf $(AR_FILE)
################################################
################################################
# Build QuartusII/QSys Project
#
#############
# QSys
QSYS_FILE := $(firstword $(wildcard *top*.qsys) $(wildcard *main*.qsys) $(wildcard *.qsys))
QSYS_DEPS := $(wildcard *.qsys)
QSYS_BASE := $(basename $(QSYS_FILE))
QSYS_QIP := $(QSYS_BASE)/synthesis/$(QSYS_BASE).qip
QSYS_SOPCINFO := $(QSYS_BASE).sopcinfo
QSYS_STAMP := $(call get_stamp_target,qsys)
# Under cygwin, ensure TMP env variable is not a cygwin style path
# before calling ip-generate
ifneq ($(shell which cygwin1.dll 2>/dev/null),)
ifneq ($(shell which cygpath 2>/dev/null),)
SET_QSYS_GENERATE_ENV = TMP="$(shell cygpath -m "$(TMP)")"
endif
endif
.PHONY: qsys_compile
qsys_compile: $(QSYS_STAMP)
$(QSYS_QIP) : $(QSYS_STAMP)
$(QSYS_STAMP): $(QSYS_DEPS)
@$(RM) $(QSYS_QIP) $(QSYS_SOPCINFO) $(QSYS_BASE)
$(SET_QSYS_GENERATE_ENV) qsys-generate $(QSYS_FILE) --synthesis=VERILOG $(QSYS_GENERATE_ARGS)
$(stamp_target)
HELP_TARGETS += qsys_edit
qsys_edit.HELP := Launch QSys GUI
.PHONY: qsys_edit
qsys_edit:
qsys-edit $(QSYS_FILE) &
#############
# Quartus II
QUARTUS_QPF := $(firstword $(wildcard *.qpf))
QUARTUS_QSF := $(patsubst %.qpf,%.qsf,$(QUARTUS_QPF))
QUARTUS_BASE := $(basename $(QUARTUS_QPF))
QUARTUS_HDL_SOURCE := $(wildcard *.v *.sv *.vhd)
QUARTUS_MISC_SOURCE := $(wildcard *.stp *.sdc)
QUARTUS_PIN_ASSIGNMENTS_STAMP := $(call get_stamp_target,quartus_pin_assignments)
QUARTUS_DEPS = $(QUARTUS_QPF) $(QUARTUS_QSF) $(QUARTUS_HDL_SOURCE) $(QUARTUS_MISC_SOURCE) $(QSYS_STAMP) $(QSYS_QIP) $(QUARTUS_PIN_ASSIGNMENTS_STAMP)
QUARTUS_SOF := output_files/$(patsubst %.qpf,%.sof,$(QUARTUS_QPF))
QUARTUS_STAMP := $(call get_stamp_target,quartus)
.PHONY: quartus_compile
quartus_compile: $(QUARTUS_STAMP)
$(QUARTUS_SOF): $(QUARTUS_STAMP)
$(QUARTUS_PIN_ASSIGNMENTS_STAMP): $(QSYS_STAMP)
@for pin_assign_tcl_file in $$(find $(QSYS_BASE) -name '*_pin_assignments.tcl'); do \
quartus_map $(QUARTUS_QPF); \
echo "Applying $${pin_assign_tcl_file} to $(QUARTUS_QPF)..."; \
quartus_sta -t $${pin_assign_tcl_file} $(QUARTUS_QPF); \
done
$(stamp_target)
$(QUARTUS_STAMP): $(QUARTUS_DEPS)
$(RM) $(QUARTUS_SOF) *.sof output_files
quartus_stp $(QUARTUS_BASE)
quartus_sh --flow compile $(QUARTUS_QPF)
$(stamp_target)
HELP_TARGETS += quartus_edit
quartus_edit.HELP := Launch Quartus II GUI
.PHONY: quartus_edit
quartus_edit:
quartus $(QUARTUS_QPF) &
HELP_TARGETS += sof
sof.HELP := QSys generate & Quartus compile this design
BATCH_TARGETS += sof
.PHONY: sof
sof: $(QUARTUS_SOF)
QUARTUS_RBF := $(patsubst %.sof,%.rbf,$(QUARTUS_SOF))
#
# This converts the sof into compressed, unencrypted
# raw binary format corresponding to MSEL value of 8
# in the FPGAMGRREGS_STAT register. If you read the
# the whole register, it should be 0x50.
#
# CVSoC DevBoard SW1 MSEL should be set to up,down,up,down,up,up
#
$(QUARTUS_RBF): %.rbf: %.sof
quartus_cpf -c -o bitstream_compression=on $< $@
.PHONY: rbf
rbf: $(QUARTUS_RBF)
.PHONY: create_rbf
create_rbf:
quartus_cpf -c -o bitstream_compression=on $(QUARTUS_SOF) $(QUARTUS_RBF)
################################################
################################################
# QSYS/Quartus Project Generation
# - we don't run this generation step automatically on purpose because they
# it will destroy any changes/customizations that you've made to your qsys
# or your quartus project
#
QSYS_QSYS_GEN := $(firstword $(wildcard create_*_qsys.tcl))
QUARTUS_QSF_QPF_GEN := $(firstword $(wildcard create_*_quartus.tcl))
.PHONY: quartus_generate_qsf_qpf
ifneq ($(QUARTUS_QSF_QPF_GEN),)
quartus_generate_qsf_qpf: $(QUARTUS_QSF_QPF_GEN)
$(RM) $(QUARTUS_QSF) $(QUARTUS_QPF)
quartus_sh --script=$<
else
quartus_generate_qsf_qpf:
@$(ECHO) "Make target '$@' is not supported for this design"
endif
.PHONY: qsys_generate_qsys
ifneq ($(QSYS_QSYS_GEN),)
qsys_generate_qsys: $(QSYS_QSYS_GEN)
$(RM) $(QSYS_FILE)
qsys-script --script=$<
else
qsys_generate_qsys:
@$(ECHO) "Make target '$@' is not supported for this design"
endif
################################################
################################################
# Quartus Programming
QUARTUS_PGM_STAMP := $(call get_stamp_target,quartus_pgm)
# set these for your board
# BOARD_CABLE =
# FPGA Board Device Index. Default to 2 since this is the most
# common setting for dev board
# For SoCKIT board, this should be set to 1
BOARD_DEVICE_INDEX ?= 2
define quartus_pgm_sof
jtagconfig
quartus_pgm --mode=jtag $(if $(BOARD_CABLE),--cable="$(BOARD_CABLE)") --operation=p\;$1$(if $(BOARD_DEVICE_INDEX),"@$(BOARD_DEVICE_INDEX)")
jtagconfig $(if $(BOARD_CABLE),-c "$(BOARD_CABLE)") -n
endef
.PHONY: pgm
pgm: $(QUARTUS_PGM_STAMP)
$(QUARTUS_PGM_STAMP): $(QUARTUS_SOF)
$(call quartus_pgm_sof,$<)
$(stamp_target)
HELP_TARGETS += program_fpga
program_fpga.HELP := Quartus program sof to your attached dev board
.PHONY: program_fpga
program_fpga:
$(call quartus_pgm_sof,$(QUARTUS_SOF))
# HPS Device Index. Default to 1 since this is the most
# common setting for dev board
BOARD_HPS_DEVICE_INDEX ?= 1
define quartus_hps_pgm_qspi
jtagconfig
quartus_hps $(if $(BOARD_CABLE),--cable="$(BOARD_CABLE)") $(if $(BOARD_HPS_DEVICE_INDEX),--device=$(BOARD_HPS_DEVICE_INDEX)) --operation=PV $1
endef
HELP_TARGETS += program_qspi
program_qspi.HELP := Flash program preloader into QSPI Flash
.PHONY: program_qspi
program_qspi: $(PRELOADER_DIR)/preloader-mkpimage.bin
$(call quartus_hps_pgm_qspi,$<)
################################################
################################################
# Preloader
QSYS_HPS_INST_NAME := hps_0
SBT.CREATE_SETTINGS := bsp-create-settings
SBT.GENERATE := bsp-generate-files
HELP_TARGETS += preloader
preloader.HELP := Build Preloader BSP for this design into $(PRELOADER_DIR) directory
PRELOADER_ID := hps_isw_handoff/$(QSYS_BASE)_$(QSYS_HPS_INST_NAME)/id
PRELOADER_DEPS := $(PRELOADER_ID)
PRELOADER_STAMP := $(call get_stamp_target,preloader)
$(PRELOADER_ID): $(QUARTUS_STAMP)
.PHONY: preloader
preloader: $(PRELOADER_STAMP)
# Create and build preloader with watchdog disabled.
# This is useful for board bring up and troubleshooting.
$(PRELOADER_STAMP): $(PRELOADER_DEPS)
$(RM) $(PRELOADER_DIR)
$(MKDIR) $(PRELOADER_DIR)
$(SBT.CREATE_SETTINGS) \
--type spl \
--bsp-dir $(PRELOADER_DIR) \
--preloader-settings-dir "../../hps_isw_handoff/$(QSYS_BASE)_$(QSYS_HPS_INST_NAME)" \
--settings $(PRELOADER_DIR)/settings.bsp \
--set spl.boot.WATCHDOG_ENABLE false
$(MAKE) -C $(PRELOADER_DIR)
$(stamp_target)
UBOOT_STAMP := $(call get_stamp_target,uboot)
$(UBOOT_STAMP): $(PRELOADER_STAMP)
$(MAKE) -C $(PRELOADER_DIR) uboot
$(stamp_target)
HELP_TARGETS += uboot
uboot.HELP := Build U-Boot into $(PRELOADER_DIR) directory
.PHONY: uboot
uboot: $(UBOOT_STAMP)
################################################
################################################
# Device Tree Source (dts)
DEVICE_TREE_SOURCE := $(patsubst %.sopcinfo,%.dts,$(QSYS_SOPCINFO))
DTS.SOPC2DTS := sopc2dts
DTS.BOARDINFO := $(wildcard $(QSYS_BASE)_board_info.xml)
DTS.CLOCKINFO := hps_clock_info.xml
$(DEVICE_TREE_SOURCE): %.dts: %.sopcinfo $(DTS.BOARDINFO) $(DTS.CLOCKINFO)
ifeq ($(DTS.BOARDINFO),)
$(warning WARNING: DTS BoardInfo file was not specified or found)
endif
$(DTS.SOPC2DTS) --input $< --output $@ $(if $(DTS.BOARDINFO),--board $(DTS.BOARDINFO)) $(if $(DTS.CLOCKINFO),--board $(DTS.CLOCKINFO)) --bridge-removal all
HELP_TARGETS += dts
dts.HELP := Generate a device tree for this qsys design
.PHONY: dts
dts: $(DEVICE_TREE_SOURCE)
# Device Tree Blob (dtb)
DEVICE_TREE_BLOB := $(patsubst %.dts,%.dtb,$(DEVICE_TREE_SOURCE))
# device tree compiler
DTS.DTC := dtc
$(DEVICE_TREE_BLOB): %.dtb: %.dts
$(DTS.DTC) -I dts -O dtb -o $@ $<
HELP_TARGETS += dtb
dtb.HELP := Generate a device tree blob for this qsys design
.PHONY: dtb
dtb: $(DEVICE_TREE_BLOB)
################################################
# Running Batch Jobs
ifneq ($(BATCH_TARGETS),)
BATCH_DIR := $(if $(TMP),$(TMP)/)batch/$(AR_TIMESTAMP)
.PHONY: $(patsubst %,batch-%,$(BATCH_TARGETS))
$(patsubst %,batch-%,$(BATCH_TARGETS)): batch-%: $(AR_FILE)
@$(RM) $(BATCH_DIR)
@$(MKDIR) $(BATCH_DIR)
$(CP) $< $(BATCH_DIR)
$(CD) $(BATCH_DIR) && $(TAR) -xzf $(notdir $<) && $(CHMOD) -R 755 *
$(MAKE) -C $(BATCH_DIR) $*
endif # BATCH_TARGETS != <empty>
################################################
################################################
# Help system
HELP_TARGETS += help
help.HELP := Displays this info (i.e. the available targets)
.PHONY: help
help: help-init help-targets help-fini
HELP_TARGETS_X := $(patsubst %,help-%,$(sort $(HELP_TARGETS)))
.PHONY: $(HELP_TARGETS_X)
help-targets: $(HELP_TARGETS_X)
$(HELP_TARGETS_X): help-%:
@$(ECHO) "*********************"
@$(ECHO) "* Target: $*"
@$(ECHO) "* $($*.HELP)"
.PHONY: help-init
help-init:
@$(ECHO) "*****************************************"
@$(ECHO) "* *"
@$(ECHO) "* Manage QuartusII/QSys design *"
@$(ECHO) "* *"
@$(ECHO) "* Copyright (c) 2013 *"
@$(ECHO) "* All Rights Reserved *"
@$(ECHO) "* *"
@$(ECHO) "*****************************************"
@$(ECHO) ""
.PHONY: help-fini
help-fini:
@$(ECHO) "*********************"
################################################