Makefile 8.3 KB

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