Makefile 6.0 KB

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