project-rules.mk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # Board config
  39. PIN_DEF ?= $(abspath data/$(PROJ_TOP_MOD)-$(BOARD).pcf)
  40. BOARD_DEFINE=BOARD_$(shell echo $(BOARD) | tr a-z A-Z)
  41. YOSYS_READ_ARGS += -D$(BOARD_DEFINE)=1
  42. # Add those to the list
  43. PROJ_ALL_RTL_SRCS += $(PROJ_RTL_SRCS)
  44. PROJ_ALL_SIM_SRCS += $(PROJ_SIM_SRCS)
  45. PROJ_ALL_PREREQ += $(PROJ_PREREQ)
  46. # Include path
  47. PROJ_SYNTH_INCLUDES := -I$(abspath rtl/) $(addsuffix /rtl/, $(addprefix -I$(ROOT)/cores/, $(PROJ_ALL_DEPS)))
  48. PROJ_SIM_INCLUDES := -I$(abspath sim/) $(addsuffix /sim/, $(addprefix -I$(ROOT)/cores/, $(PROJ_ALL_DEPS)))
  49. # Synthesis & Place-n-route rules
  50. $(BUILD_TMP)/$(PROJ).ys: $(PROJ_TOP_SRC) $(PROJ_ALL_RTL_SRCS)
  51. @echo "read_verilog $(YOSYS_READ_ARGS) $(PROJ_SYNTH_INCLUDES) $(PROJ_TOP_SRC) $(PROJ_ALL_RTL_SRCS)" > $@
  52. @echo "synth_ice40 $(YOSYS_SYNTH_ARGS) -top $(PROJ_TOP_MOD) -json $(PROJ).json" >> $@
  53. $(BUILD_TMP)/$(PROJ).synth.rpt $(BUILD_TMP)/$(PROJ).json: $(PROJ_ALL_PREREQ) $(BUILD_TMP)/$(PROJ).ys $(PROJ_ALL_RTL_SRCS)
  54. cd $(BUILD_TMP) && \
  55. $(YOSYS) -s $(BUILD_TMP)/$(PROJ).ys \
  56. -l $(BUILD_TMP)/$(PROJ).synth.rpt
  57. $(BUILD_TMP)/$(PROJ).pnr.rpt $(BUILD_TMP)/$(PROJ).asc: $(BUILD_TMP)/$(PROJ).json $(PIN_DEF)
  58. $(NEXTPNR) $(NEXTPNR_ARGS) $(NEXTPNR_SYS_ARGS) \
  59. --$(DEVICE) --package $(PACKAGE) \
  60. -l $(BUILD_TMP)/$(PROJ).pnr.rpt \
  61. --json $(BUILD_TMP)/$(PROJ).json \
  62. --pcf $(PIN_DEF) \
  63. --asc $@
  64. %.bin: %.asc
  65. $(ICEPACK) -s $< $@
  66. # Simulation
  67. $(BUILD_TMP)/%_tb: sim/%_tb.v $(ICE40_LIBS) $(PROJ_ALL_PREREQ) $(PROJ_ALL_RTL_SRCS) $(PROJ_ALL_SIM_SRCS)
  68. $(IVERILOG) -Wall -DSIM=1 -D$(BOARD_DEFINE)=1 -o $@ \
  69. $(PROJ_SYNTH_INCLUDES) $(PROJ_SIM_INCLUDES) \
  70. $(addprefix -l, $(ICE40_LIBS) $(PROJ_ALL_RTL_SRCS) $(PROJ_ALL_SIM_SRCS)) \
  71. $<
  72. # Action targets
  73. synth: $(BUILD_TMP)/$(PROJ).bin
  74. sim: $(addprefix $(BUILD_TMP)/, $(PROJ_TESTBENCHES))
  75. prog: $(BUILD_TMP)/$(PROJ).bin
  76. $(ICEPROG) $<
  77. sudo-prog: $(BUILD_TMP)/$(PROJ).bin
  78. @echo 'Executing prog as root!!!'
  79. sudo $(ICEPROG) $<
  80. clean:
  81. @rm -Rf $(BUILD_TMP)
  82. .PHONY: all synth sim prog sudo-prog clean