Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. MAKEFLAGS += -R -r
  2. PROJECT = max80
  3. REVISIONS = v1 v2 v2boot
  4. QU = quartus
  5. # Common options for all Quartus tools
  6. QPRI = --lower_priority
  7. QCPF = $(QU)_cpf $(QPRI)
  8. QSH = $(QU)_sh $(QPRI)
  9. QSTA = $(QU)_sta $(QPRI)
  10. QPGM = $(QU)_pgm $(QPRI)
  11. # Common options for Quartus in-flow tools
  12. QOPT = --write_settings_files=off $(QPRI)
  13. QMAP = $(QU)_map $(QOPT)
  14. QFIT = $(QU)_fit $(QOPT)
  15. QCDB = $(QU)_cdb $(QOPT)
  16. QASM = $(QU)_asm $(QOPT)
  17. QPOW = $(QU)_pow $(QOPT)
  18. outdir = output
  19. PERL = perl
  20. PYTHON = python
  21. SED = sed
  22. GZIP = gzip
  23. SUBDIRS = usb
  24. PREREQFILES = $(outdir)/sram.mif \
  25. $(foreach rev,$(REVISIONS),$(foreach coffmt,jic pof, \
  26. $(outdir)/$(rev).$(coffmt).cof))
  27. alltarg := sof pof jic svf svf.gz xsvf xsvf.gz rbf rbf.gz \
  28. rpd rpd.gz pow.rpt sta.rpt
  29. allout = $(foreach o,$(alltarg),$(outdir)/$(1).$(o))
  30. sram_src = ../rv32/boot.bin
  31. .SUFFIXES:
  32. .SECONDARY:
  33. .DELETE_ON_ERROR:
  34. all:
  35. $(MAKE) prereq
  36. $(MAKE) $(foreach rev,$(REVISIONS),$(rev).targets)
  37. -include $(foreach rev,$(REVISIONS),$(rev).deps)
  38. .PHONY: $(REVISIONS)
  39. $(REVISIONS):
  40. $(MAKE) prereq
  41. $(MAKE) $@.targets
  42. .PHONY: %.targets
  43. %.targets:
  44. $(MAKE) $(call allout,$*)
  45. $(outdir)/%.map.rpt: %.qsf | $(outdir)/sram.bin
  46. $(QMAP) $(PROJECT) -c $*
  47. $(outdir)/%.fit.rpt: $(outdir)/%.map.rpt
  48. $(QFIT) $(PROJECT) -c $*
  49. $(outdir)/sram.bin: $(sram_src) $(all_map_deps)
  50. LC_ALL=C date | tr '\n' '\0' | cat $< - > $@
  51. sram_depth := 8192
  52. sram_width := 32
  53. sram_stride := 1
  54. $(outdir)/%.mif: $(outdir)/%.bin ../tools/bin2mif.pl
  55. $(PERL) ../tools/bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride)
  56. $(outdir)/%.mif_update.rpt: $(outdir)/%.fit.rpt
  57. [ -z '$($*_asm_deps)' ] || $(QCDB) --update_mif $(PROJECT) -c $*
  58. $(outdir)/%.sof: $(outdir)/%.mif_update.rpt
  59. $(QASM) $(PROJECT) -c $*
  60. $(outdir)/%.sta.rpt: $(outdir)/%.fit.rpt | $(outdir)/%.sof
  61. $(QSTA) $(PROJECT) -c $*
  62. $(outdir)/%.pow.rpt: $(outdir)/%.sta.rpt
  63. $(QPOW) $(PROJECT) -c $*
  64. $(foreach rev,$(REVISIONS),$(outdir)/$(rev).%.cof): %.cof.xml
  65. $(SED) -e 's/@@PROJECT@@/$(@F:.$*.cof=)/g' $< > $@
  66. $(outdir)/%.jic: $(outdir)/%.jic.cof $(outdir)/%.sof ../rv32/dram.hex
  67. $(QCPF) -c $<
  68. $(outdir)/%.pof: $(outdir)/%.pof.cof $(outdir)/%.sof
  69. $(QCPF) -c $<
  70. # This produces a transient-load .svf file
  71. $(outdir)/%.svf: $(outdir)/%.sof
  72. $(QCPF) -c -q 12.0MHz -g 3.3 -n p $< $@
  73. # xsvf: compact representation of .svf; more or less a wrapper around
  74. # the raw binary file.
  75. $(outdir)/%.xsvf: $(outdir)/%.svf ../tools/svf2xsvf.py
  76. $(PYTHON) ../tools/svf2xsvf.py $< $@
  77. # Raw Binary File, compact data for transient programming or for loading
  78. # into flash (address 0); does *not* include the non-FPGA code; load
  79. # ../rv32/dram.{bin,bin.gz,hex} for that.
  80. $(outdir)/%.rbf: $(outdir)/%.sof
  81. $(QCPF) -c $< $@
  82. # Raw Programmer Data, for loading into flash, includes all contents
  83. # but is rather large if not compressed.
  84. $(outdir)/%.rpd: $(outdir)/%.pof
  85. $(QCPF) -c $< $@
  86. $(outdir)/%.gz: $(outdir)/%
  87. $(GZIP) -9 < $< > $@
  88. # Prerequisite directories and files
  89. prereq:
  90. mkdir -p $(outdir)
  91. $(MAKE) $(PREREQFILES)
  92. for d in $(SUBDIRS); do $(MAKE) -C $$d; done
  93. # Clean out SignalTap
  94. signalclean:
  95. for f in *.qsf; do \
  96. $(PERL) -ne 'print unless (/(SIGNALTAP_FILE\b|\bENABLE_SIGNALTAP\b|\bSLD_FILE\b|SLD_NODE_)/);' < $$f > $$f.tmp && \
  97. mv -f $$f.tmp $$f ; \
  98. done
  99. # Programming targets. Environment JTAG_CABLE can override the default,
  100. # which is otherwise the first cable found.
  101. rpar := )
  102. JTAG_CABLE ?= $(shell jtagconfig --enum | sed -ne 's/^1$(rpar) //p')
  103. # Transient programming
  104. program-%: $(outdir)/%.sof
  105. $(QPGM) -c '$(JTAG_CABLE)' -m JTAG -o 'p;$(outdir)/$*.sof'
  106. # Permanent programming in flash
  107. flash-%: $(outdir)/%.jic
  108. $(QPGM) -c '$(JTAG_CABLE)' -m JTAG -i -o 'pvbi;$(outdir)/$*.jic'
  109. %.deps: %.qsf scripts/qsfdeps.pl
  110. $(PERL) scripts/qsfdeps.pl $* $@ $<
  111. clean:
  112. for d in $(SUBDIRS); do $(MAKE) -C $$d clean; done
  113. rm -rf db incremental_db simulation/modelsim \
  114. greybox_tmp */greybox_tmp iodevs.vh output_files
  115. for d in $(REVISIONS); do \
  116. $$d/*.rpt $$d/*.rpt $$d/*.summary $$d/*.smsg \
  117. $$d/*.htm $$d/*.htm_files $$d/*.map $$d/*.eqn $$d/*.sld \
  118. $$d/*.done ; \
  119. done
  120. spotless:
  121. for d in $(SUBDIRS); do $(MAKE) -C $$d spotless; done
  122. rm -rf $(outdir) *.deps *~ \#*~
  123. iodevs.vh: ../iodevs.conf ../tools/iodevs.pl
  124. $(PERL) ../tools/iodevs.pl v $< $@
  125. deps: Makefile
  126. # Verilog header dependencies
  127. max80.sv: iodevs.vh