project-rules.mk 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #
  2. # project-rules.mk
  3. #
  4. # Default tools
  5. YOSYS ?= yosys
  6. YOSYS_READ_ARGS ?=
  7. YOSYS_SYNTH_ARGS ?= -dffe_min_ce_use 4 -relut
  8. NEXTPNR ?= nextpnr-ice40
  9. NEXTPNR_ARGS ?= --freq 50
  10. ICEPACK ?= icepack
  11. ICEPROG ?= iceprog
  12. IVERILOG ?= iverilog
  13. ifeq ($(PLACER),heap)
  14. NEXTPNR_SYS_ARGS += --placer heap
  15. endif
  16. ICE40_LIBS ?= $(shell yosys-config --datdir/ice40/cells_sim.v)
  17. # Must be first rule and call it 'all' by convention
  18. all: synth
  19. # Root directory
  20. ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..)
  21. # Temporary build-directory
  22. BUILD_TMP := $(abspath build-tmp)
  23. $(BUILD_TMP):
  24. mkdir -p $(BUILD_TMP)
  25. # Discover all cores
  26. $(foreach core_dir, $(wildcard $(ROOT)/cores/*), $(eval include $(core_dir)/core.mk))
  27. # Resolve dependency tree for project and collect sources
  28. $(BUILD_TMP)/proj-deps.mk: Makefile $(BUILD_TMP) $(addprefix $(BUILD_TMP)/deps-core-,$(PROJ_DEPS))
  29. @echo "include $(BUILD_TMP)/deps-core-*" > $@
  30. @echo "PROJ_ALL_DEPS := \$$(DEPS_SOLVE_TMP)" >> $@
  31. @echo "PROJ_ALL_RTL_SRCS := \$$(RTL_SRCS_SOLVE_TMP)" >> $@
  32. @echo "PROJ_ALL_SIM_SRCS := \$$(SIM_SRCS_SOLVE_TMP)" >> $@
  33. @echo "PROJ_ALL_PREREQ := \$$(PREREQ_SOLVE_TMP)" >> $@
  34. include $(BUILD_TMP)/proj-deps.mk
  35. # Make all sources absolute
  36. PROJ_RTL_SRCS := $(abspath $(PROJ_RTL_SRCS))
  37. PROJ_TOP_SRC := $(abspath $(PROJ_TOP_SRC))
  38. PIN_DEF ?= $(abspath data/$(PROJ_TOP_MOD)-$(BOARD).pcf)
  39. # Add those to the list
  40. PROJ_ALL_RTL_SRCS += $(PROJ_RTL_SRCS)
  41. PROJ_ALL_SIM_SRCS += $(PROJ_SIM_SRCS)
  42. PROJ_ALL_PREREQ += $(PROJ_PREREQ)
  43. # Include path
  44. PROJ_SYNTH_INCLUDES := -I$(abspath rtl/) $(addsuffix /rtl/, $(addprefix -I$(ROOT)/cores/, $(PROJ_ALL_DEPS)))
  45. PROJ_SIM_INCLUDES := -I$(abspath sim/) $(addsuffix /sim/, $(addprefix -I$(ROOT)/cores/, $(PROJ_ALL_DEPS)))
  46. # Synthesis & Place-n-route rules
  47. $(BUILD_TMP)/$(PROJ).ys: $(PROJ_TOP_SRC) $(PROJ_ALL_RTL_SRCS)
  48. @echo "read_verilog $(YOSYS_READ_ARGS) $(PROJ_SYNTH_INCLUDES) $(PROJ_TOP_SRC) $(PROJ_ALL_RTL_SRCS)" > $@
  49. @echo "synth_ice40 $(YOSYS_SYNTH_ARGS) -top $(PROJ_TOP_MOD) -json $(PROJ).json" >> $@
  50. $(BUILD_TMP)/$(PROJ).synth.rpt $(BUILD_TMP)/$(PROJ).json: $(PROJ_ALL_PREREQ) $(BUILD_TMP)/$(PROJ).ys $(PROJ_ALL_RTL_SRCS)
  51. cd $(BUILD_TMP) && \
  52. $(YOSYS) -s $(BUILD_TMP)/$(PROJ).ys \
  53. -l $(BUILD_TMP)/$(PROJ).synth.rpt
  54. $(BUILD_TMP)/$(PROJ).pnr.rpt $(BUILD_TMP)/$(PROJ).asc: $(BUILD_TMP)/$(PROJ).json $(PIN_DEF)
  55. $(NEXTPNR) $(NEXTPNR_ARGS) $(NEXTPNR_SYS_ARGS) \
  56. --$(DEVICE) --package $(PACKAGE) \
  57. -l $(BUILD_TMP)/$(PROJ).pnr.rpt \
  58. --json $(BUILD_TMP)/$(PROJ).json \
  59. --pcf $(PIN_DEF) \
  60. --asc $@
  61. %.bin: %.asc
  62. $(ICEPACK) -s $< $@
  63. # Simulation
  64. $(BUILD_TMP)/%_tb: sim/%_tb.v $(ICE40_LIBS) $(PROJ_ALL_PREREQ) $(PROJ_ALL_RTL_SRCS) $(PROJ_ALL_SIM_SRCS)
  65. iverilog -Wall -DSIM=1 -o $@ \
  66. $(PROJ_SYNTH_INCLUDES) $(PROJ_SIM_INCLUDES) \
  67. $(addprefix -l, $(ICE40_LIBS) $(PROJ_ALL_RTL_SRCS) $(PROJ_ALL_SIM_SRCS)) \
  68. $<
  69. # Action targets
  70. synth: $(BUILD_TMP)/$(PROJ).bin
  71. sim: $(addprefix $(BUILD_TMP)/, $(PROJ_TESTBENCHES))
  72. prog: $(BUILD_TMP)/$(PROJ).bin
  73. $(ICEPROG) $<
  74. sudo-prog: $(BUILD_TMP)/$(PROJ).bin
  75. @echo 'Executing prog as root!!!'
  76. sudo $(ICEPROG) $<
  77. clean:
  78. @rm -Rf $(BUILD_TMP)
  79. .PHONY: all synth sim prog sudo-prog clean