xilinx.mk 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # The top level module should define the variables below then include
  2. # this file. The files listed should be in the same directory as the
  3. # Makefile.
  4. #
  5. # variable description
  6. # ---------- -------------
  7. # project project name (top level module should match this name)
  8. # top_module top level module of the project
  9. # libdir path to library directory
  10. # libs library modules used
  11. # vfiles all local .v files
  12. # xilinx_cores all local .xco files
  13. # vendor vendor of FPGA (xilinx, altera, etc.)
  14. # family FPGA device family (spartan3e)
  15. # part FPGA part name (xc4vfx12-10-sf363)
  16. # flashsize size of flash for mcs file (16384)
  17. # optfile (optional) xst extra opttions file to put in .scr
  18. # map_opts (optional) options to give to map
  19. # par_opts (optional) options to give to par
  20. # intstyle (optional) intstyle option to all tools
  21. #
  22. # files description
  23. # ---------- ------------
  24. # $(project).ucf ucf file
  25. #
  26. # Library modules should have a modules.mk in their root directory,
  27. # namely $(libdir)/<libname>/module.mk, that simply adds to the vfiles
  28. # and xilinx_cores variable.
  29. #
  30. # all the .xco files listed in xilinx_cores will be generated with core, with
  31. # the resulting .v and .ngc files placed back in the same directory as
  32. # the .xco file.
  33. #
  34. # TODO: .xco files are device dependant, should use a template based system
  35. coregen_work_dir ?= ./coregen-tmp
  36. map_opts ?= -timing -ol high -detail -pr b -register_duplication -w
  37. par_opts ?= -ol high
  38. isedir ?= /data/Xilinx/14.7/ISE_DS
  39. xil_env ?= . $(isedir)/settings64.sh
  40. flashsize ?= 8192
  41. libmks = $(patsubst %,$(libdir)/%/module.mk,$(libs))
  42. mkfiles = Makefile $(libmks) xilinx.mk
  43. include $(libmks)
  44. corengcs = $(foreach core,$(xilinx_cores),$(core:.xco=.ngc))
  45. local_corengcs = $(foreach ngc,$(corengcs),$(notdir $(ngc)))
  46. vfiles += $(foreach core,$(xilinx_cores),$(core:.xco=.v))
  47. junk += $(local_corengcs)
  48. .PHONY: default xilinx_cores clean twr etwr
  49. default: $(project).bit $(project).mcs
  50. xilinx_cores: $(corengcs)
  51. twr: $(project).twr
  52. etwr: $(project)_err.twr
  53. define cp_template
  54. $(2): $(1)
  55. cp $(1) $(2)
  56. endef
  57. $(foreach ngc,$(corengcs),$(eval $(call cp_template,$(ngc),$(notdir $(ngc)))))
  58. %.ngc %.v: %.xco
  59. @echo "=== rebuilding $@"
  60. if [ -d $(coregen_work_dir) ]; then \
  61. rm -rf $(coregen_work_dir)/*; \
  62. else \
  63. mkdir -p $(coregen_work_dir); \
  64. fi
  65. cd $(coregen_work_dir); \
  66. $(xil_env); \
  67. coregen -b $$OLDPWD/$<; \
  68. cd -
  69. xcodir=`dirname $<`; \
  70. basename=`basename $< .xco`; \
  71. if [ ! -r $(coregen_work_dir/$$basename.ngc) ]; then \
  72. echo "'$@' wasn't created."; \
  73. exit 1; \
  74. else \
  75. cp $(coregen_work_dir)/$$basename.v $(coregen_work_dir)/$$basename.ngc $$xcodir; \
  76. fi
  77. junk += $(coregen_work_dir)
  78. date = $(shell date +%F-%H-%M)
  79. # some common junk
  80. junk += *.xrpt
  81. programming_files: $(project).bit $(project).mcs
  82. mkdir -p $@/$(date)
  83. mkdir -p $@/latest
  84. for x in .bit .mcs .cfi _bd.bmm; do cp $(project)$$x $@/$(date)/$(project)$$x; cp $(project)$$x $@/latest/$(project)$$x; done
  85. $(xil_env); xst -help | head -1 | sed 's/^/#/' | cat - $(project).scr > $@/$(date)/$(project).scr
  86. $(project).mcs: $(project).bit
  87. $(xil_env); \
  88. promgen -w -s $(flashsize) -p mcs -o $@ -u 0 $^
  89. junk += $(project).mcs $(project).cfi $(project).prm
  90. $(project).bit: $(project)_par.ncd
  91. $(xil_env); \
  92. # bitgen $(intstyle) -g UserID:0x09470947 -g DriveDone:yes -g StartupClk:Cclk -w $(project)_par.ncd $(project).bit
  93. bitgen $(intstyle) -g compress -g UserID:0x09470947 -g DriveDone:yes -g StartupClk:Cclk -w $(project)_par.ncd $(project).bit
  94. junk += $(project).bgn $(project).bit $(project).drc $(project)_bd.bmm
  95. $(project)_par.ncd: $(project).ncd
  96. $(xil_env); \
  97. if par $(intstyle) $(par_opts) -w $(project).ncd $(project)_par.ncd; then \
  98. :; \
  99. else \
  100. $(MAKE) etwr; \
  101. fi
  102. junk += $(project)_par.ncd $(project)_par.par $(project)_par.pad
  103. junk += $(project)_par_pad.csv $(project)_par_pad.txt
  104. junk += $(project)_par.grf $(project)_par.ptwx
  105. junk += $(project)_par.unroutes $(project)_par.xpi
  106. $(project).ncd: $(project).ngd
  107. if [ -r $(project)_par.ncd ]; then \
  108. cp $(project)_par.ncd smartguide.ncd; \
  109. smartguide="-smartguide smartguide.ncd"; \
  110. else \
  111. smartguide=""; \
  112. fi; \
  113. $(xil_env); \
  114. map $(intstyle) $(map_opts) $$smartguide $<
  115. junk += $(project).ncd $(project).pcf $(project).ngm $(project).mrp $(project).map
  116. junk += smartguide.ncd $(project).psr
  117. junk += $(project)_summary.xml $(project)_usage.xml
  118. $(project).ngd: $(project).ngc $(project).ucf $(project).bmm
  119. $(xil_env); ngdbuild $(intstyle) $(project).ngc -bm $(project).bmm
  120. junk += $(project).ngd $(project).bld
  121. $(project).ngc: $(vfiles) $(local_corengcs) $(project).scr $(project).prj
  122. $(xil_env); xst $(intstyle) -ifn $(project).scr
  123. junk += xlnx_auto* $(top_module).lso $(project).srp
  124. junk += netlist.lst xst $(project).ngc
  125. $(project).prj: $(vfiles) $(mkfiles)
  126. for src in $(vfiles); do echo "verilog work $$src" >> $(project).tmpprj; done
  127. sort -u $(project).tmpprj > $(project).prj
  128. rm -f $(project).tmpprj
  129. junk += $(project).prj
  130. optfile += $(wildcard $(project).opt)
  131. top_module ?= $(project)
  132. $(project).scr: $(optfile) $(mkfiles) ./xilinx.opt
  133. echo "run" > $@
  134. echo "-p $(part)" >> $@
  135. echo "-top $(top_module)" >> $@
  136. echo "-ifn $(project).prj" >> $@
  137. echo "-ofn $(project).ngc" >> $@
  138. cat ./xilinx.opt $(optfile) >> $@
  139. junk += $(project).scr
  140. $(project).post_map.twr: $(project).ncd
  141. $(xil_env); trce -e 10 $< $(project).pcf -o $@
  142. junk += $(project).post_map.twr $(project).post_map.twx smartpreview.twr
  143. $(project).twr: $(project)_par.ncd
  144. $(xil_env); trce $< $(project).pcf -o $(project).twr
  145. junk += $(project).twr $(project).twx smartpreview.twr
  146. $(project)_err.twr: $(project)_par.ncd
  147. $(xil_env); trce -e 10 $< $(project).pcf -o $(project)_err.twr
  148. junk += $(project)_err.twr $(project)_err.twx
  149. .gitignore: $(mkfiles)
  150. echo programming_files $(junk) | sed 's, ,\n,g' > .gitignore
  151. clean::
  152. rm -rf $(junk)