Makefile 6.0 KB

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