Makefile 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. MAKEFLAGS += -R -r
  2. PROJECT = max80
  3. REVISIONS = v1 v2 bypass
  4. VARIANTS =
  5. QU = quartus
  6. # Common options for all Quartus tools
  7. QPRI = --lower_priority
  8. QCPF = $(QU)_cpf $(QPRI)
  9. QSH = $(QU)_sh $(QPRI)
  10. QSTA = $(QU)_sta $(QPRI)
  11. QPGM = $(QU)_pgm $(QPRI)
  12. # Common options for Quartus in-flow tools
  13. QOPT = --write_settings_files=off $(QPRI)
  14. QMAP = $(QU)_map $(QOPT)
  15. QFIT = $(QU)_fit $(QOPT)
  16. QCDB = $(QU)_cdb $(QOPT)
  17. QASM = $(QU)_asm $(QOPT)
  18. QPOW = $(QU)_pow $(QOPT)
  19. outdir = output
  20. mifdir = mif
  21. PERL = perl
  22. PYTHON = python
  23. SED = sed
  24. GZIP = gzip
  25. BUILDDATE := $(shell LC_ALL=C date)
  26. SUBDIRS = usb
  27. PREREQFILES = $(mifdir)/sram.mif \
  28. $(foreach rev,$(REVISIONS),$(foreach coffmt,jic pof, \
  29. $(outdir)/$(rev).$(coffmt).cof))
  30. alltarg := sof pof jic svf svf.gz xsvf xsvf.gz rbf rbf.gz rpf rpf.gz \
  31. rpd rpd.gz pow.rpt sta.rpt
  32. allout = $(foreach o,$(alltarg),$(outdir)/$(1).$(o))
  33. #vartarg := sof svf svf.gz rbf rbf.gz
  34. #varout = $(foreach o,$(vartarg),$(outdir)/$(1).$(o))
  35. #uptarg := update.svf update.svf.gz update.xsvf update.xsvf.gz
  36. #upout = $(foreach o,$(uptarg),$(outdir)/$(1).$(o))
  37. sram_src = ../rv32/
  38. DRAM_ADDR := 0x100000
  39. DRAM_IMAGE := ../rv32/dram.bin
  40. ESP_IMAGE := ../esp32/output/max80.ino.bin
  41. IDCODE := 0x020f20dd # JTAG IDCODE of FPGA
  42. .SUFFIXES:
  43. .SECONDARY:
  44. .DELETE_ON_ERROR:
  45. all:
  46. $(MAKE) prereq
  47. $(MAKE) $(REVISIONS:=.targets)
  48. $(MAKE) fwimages
  49. # $(MAKE) $(VARIANTS)
  50. # $(MAKE) $(REVISIONS:=.update)
  51. -include $(REVISIONS:=.deps)
  52. .PHONY: fwimages
  53. fwimages: $(patsubst %,$(outdir)/%.fw,$(filter-out bypass,$(REVISIONS)))
  54. .PHONY: $(REVISIONS)
  55. $(REVISIONS):
  56. $(MAKE) prereq
  57. $(MAKE) $@.targets
  58. .PHONY: %.targets
  59. %.targets:
  60. $(MAKE) $(call allout,$*)
  61. .PHONY: %.update
  62. %.update:
  63. $(MAKE) $(call upout,$*)
  64. .PHONY: $(VARIANTS)
  65. $(VARIANTS):
  66. $(MAKE) $(outdir)/$@/variant.stamp
  67. .PHONY: %.vtargets
  68. %.vtargets:
  69. $(MAKE) --old-file=$(outdir)/$*.fit.rpt $(call varout,$*)
  70. $(outdir)/%/variant.stamp: mif/%.mif \
  71. $(foreach rev,$(REVISIONS),$(outdir)/$(rev).fit.rpt)
  72. -rm -rf var/$* $(outdir)/$*
  73. mkdir -p var/$* var/$*/mif $(outdir)/$*
  74. ( cd $(outdir)/$* && ln -sf ../*.asm.rpt ../*.fit.rpt . )
  75. cp -alf Makefile *.deps *.qpf *.qsf *.pins scripts \
  76. db incremental_db var/$*/
  77. ln -f $< var/$*/mif/sram.mif
  78. ( cd var/$* && ln -sf ../../$(outdir)/$* ./output )
  79. $(MAKE) -C var/$* $(REVISIONS:=.vtargets)
  80. echo '$(BUILDDATE)' > $@
  81. $(outdir)/%.map.rpt: %.qsf | $(mifdir)/sram.mif
  82. $(QMAP) $(PROJECT) -c $*
  83. $(outdir)/%.fit.rpt: $(outdir)/%.map.rpt
  84. $(QFIT) $(PROJECT) -c $*
  85. $(mifdir)/%.bin: $(sram_src)/%.bin $(all_map_deps)
  86. cp -f $< $@
  87. printf '%s\0' '$(BUILDDATE)' >> $@
  88. sram_depth := 8192
  89. sram_width := 32
  90. sram_stride := 1
  91. $(mifdir)/%.mif: $(mifdir)/%.bin ../tools/bin2mif.pl
  92. $(PERL) ../tools/bin2mif.pl $< $@ \
  93. $(sram_depth) $(sram_width) $(sram_stride)
  94. $(outdir)/%.mif_update.rpt: $(outdir)/%.fit.rpt
  95. [ -z '$($*_asm_deps)' ] || $(QCDB) --update_mif $(PROJECT) -c $*
  96. $(outdir)/%.sof: $(outdir)/%.mif_update.rpt
  97. $(QASM) $(PROJECT) -c $*
  98. $(outdir)/%.sta.rpt: $(outdir)/%.fit.rpt | $(outdir)/%.sof
  99. $(QSTA) $(PROJECT) -c $*
  100. $(outdir)/%.pow.rpt: $(outdir)/%.sta.rpt
  101. $(QPOW) $(PROJECT) -c $*
  102. $(foreach rev,$(REVISIONS),$(outdir)/$(rev).%.cof): %.cof.xml
  103. $(SED) -e 's/@@PROJECT@@/$(@F:.$*.cof=)/g' $< > $@
  104. $(outdir)/%.jic: $(outdir)/%.jic.cof $(outdir)/%.sof ../rv32/dram.hex
  105. $(QCPF) -o bitstream_compression=on -c $<
  106. $(outdir)/%.pof: $(outdir)/%.pof.cof $(outdir)/%.sof
  107. $(QCPF) -o bitstream_compression=on -c $<
  108. # This produces a transient-load .svf file
  109. # 6 MHz is the speed of USB-Blaster...
  110. $(outdir)/%.svf: $(outdir)/%.sof
  111. $(QCPF) -c -q 6.0MHz -g 3.3 -n p $< $@
  112. # xsvf: compact representation of .svf; more or less a wrapper around
  113. # the raw binary file.
  114. $(outdir)/%.xsvf: $(outdir)/%.svf ../tools/svf2xsvf.py
  115. $(PYTHON) ../tools/svf2xsvf.py $< $@
  116. # Raw Binary File, compact data for transient programming.
  117. $(outdir)/%.rbf: $(outdir)/%.sof
  118. $(QCPF) -c $< $@
  119. # Raw Programmer Data, for loading into flash, includes all contents
  120. # but is rather large if not compressed. Adjust bit ordering to match
  121. # SPI...
  122. $(outdir)/%.rpd: $(outdir)/%.pof
  123. $(QCPF) -c -o bitstream_compression=on -o rpd_little_endian=off $< $@
  124. # RPD file for the FPGA only. The necessary length can be gotten from
  125. # generating a compressed .rbf, but that file is not valid for flashing
  126. # even if bit-reversed due to header(?) differences.
  127. $(outdir)/%.z.rbf: $(outdir)/%.sof
  128. $(QCPF) -c -o bitstream_compression=on $< $@
  129. $(outdir)/%.rpf: $(outdir)/%.rpd $(outdir)/%.z.rbf
  130. dd if=$< of=$@ bs=$$(wc -c < $(@:.rpf=.z.rbf)) count=1
  131. $(outdir)/%.gz: $(outdir)/%
  132. $(GZIP) -9 < $< > $@
  133. $(outdir)/%.fw: $(outdir)/%.rpf $(outdir)/bypass.rbf \
  134. $(DRAM_IMAGE) $(ESP_IMAGE) \
  135. ../tools/mkfwimage.pl
  136. $(PERL) ../tools/mkfwimage.pl -o - \
  137. -type target -str 'MAX80 $*' \
  138. -type fpgainit -addr $(IDCODE) -optional -file $(outdir)/bypass.rbf \
  139. -type data -addr 0 -file $< \
  140. -type data -addr $(DRAM_ADDR) -file $(DRAM_IMAGE) \
  141. -type espota -optional -file $(ESP_IMAGE) \
  142. | $(GZIP) -9 > $@
  143. $(outdir)/%.update.svf: ./scripts/flashsvf.pl \
  144. $(outdir)/jtagupd/%.svf $(outdir)/%.map.rpt $(outdir)/%.fw
  145. $(PERL) $^ $@
  146. # Prerequisite directories and files
  147. .PHONY: prereq
  148. prereq:
  149. mkdir -p $(outdir) $(mifdir)
  150. for d in $(SUBDIRS); do $(MAKE) -C $$d; done
  151. $(MAKE) $(PREREQFILES)
  152. # Clean out SignalTap
  153. signalclean:
  154. for f in *.qsf; do \
  155. $(PERL) -ne 'print unless (/(SIGNALTAP_FILE\b|\bENABLE_SIGNALTAP\b|\bSLD_FILE\b|SLD_NODE_)/);' < $$f > $$f.tmp && \
  156. mv -f $$f.tmp $$f ; \
  157. done
  158. # Programming targets. Environment JTAG_CABLE can override the default,
  159. # which is otherwise the first cable found.
  160. rpar := )
  161. JTAG_CABLE ?= $(shell jtagconfig --enum | sed -ne 's/^1$(rpar) //p')
  162. # Transient programming
  163. program-%: $(outdir)/%.sof
  164. $(QPGM) -c '$(JTAG_CABLE)' -m JTAG -o 'p;$(outdir)/$*.sof'
  165. # Permanent programming in flash
  166. flash-%: $(outdir)/%.jic
  167. $(QPGM) -c '$(JTAG_CABLE)' -m JTAG -i -o 'pvbi;$(outdir)/$*.jic'
  168. %.deps: %.qsf scripts/qsfdeps.pl
  169. $(PERL) scripts/qsfdeps.pl $* $@ $<
  170. clean:
  171. for d in $(SUBDIRS); do $(MAKE) -C $$d clean; done
  172. rm -rf db incremental_db var simulation/modelsim \
  173. greybox_tmp */greybox_tmp iodevs.vh output_files $(mifdir)
  174. for d in $(REVISIONS); do \
  175. rm -f $$d/*.rpt $$d/*.rpt $$d/*.summary $$d/*.smsg \
  176. $$d/*.htm $$d/*.htm_files $$d/*.map $$d/*.eqn $$d/*.sld \
  177. $$d/*.done ; \
  178. done
  179. spotless: clean
  180. for d in $(SUBDIRS); do $(MAKE) -C $$d spotless; done
  181. rm -rf $(outdir) $(mifdir) *.deps *~ \#*~
  182. iodevs.vh: ../iodevs.conf ../tools/iodevs.pl
  183. $(PERL) ../tools/iodevs.pl v $< $@
  184. deps: Makefile
  185. # Verilog header dependencies
  186. max80.sv: iodevs.vh