project-rules.mk 2.7 KB

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