aboutsummaryrefslogtreecommitdiff
path: root/rtl/Makefile
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-21 13:50:28 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-21 13:50:28 +0200
commitcb0be9e2039569ee7d18657e8f675d1f8369b407 (patch)
tree91fa71b3960d1ad5217759371143efbdd833d475 /rtl/Makefile
parent98d0dd96611dc2c0e444eaf9410f8adf2924c6b5 (diff)
downloadriscv_cpu-cb0be9e2039569ee7d18657e8f675d1f8369b407.tar.gz
riscv_cpu-cb0be9e2039569ee7d18657e8f675d1f8369b407.zip
restructured project
Diffstat (limited to 'rtl/Makefile')
-rw-r--r--rtl/Makefile56
1 files changed, 56 insertions, 0 deletions
diff --git a/rtl/Makefile b/rtl/Makefile
new file mode 100644
index 0000000..901d81f
--- /dev/null
+++ b/rtl/Makefile
@@ -0,0 +1,56 @@
+BUILD_DIR ?= build
+
+# defines
+TOP_MODULE = top
+PRJ_NAME = riscv_cpu
+
+# dirs and files
+SRC_DIR = src
+SOURCES = $(wildcard $(SRC_DIR)/*.v)
+CST_DIR = cst
+CST_FILES = $(wildcard $(CST_DIR)/*.cst)
+BITSTREAM = $(BUILD_DIR)/$(PRJ_NAME).fs
+
+# tools
+YOSYS = yosys
+NEXTPNR = nextpnr-himbaechel
+GOWIN_PACK = gowin_pack
+PROGRAMMER = openFPGALoader
+
+# fpga
+FAMILY = GW1N-9C
+DEVICE = GW1NR-LV9QN88PC6/I5
+BOARD = tangnano9k
+
+
+# targets
+all: $(BITSTREAM)
+
+# synthesize
+$(BUILD_DIR)/$(PRJ_NAME).json: $(SOURCES) | $(BUILD_DIR)
+ @echo "read_verilog -Irtl $(SOURCES)" > $(BUILD_DIR)/synth_gowin.ys
+ @echo "chparam -set ROM_FILE \"../build/rom.hex\" rom" >> $(BUILD_DIR)/synth_gowin.ys
+ @echo "synth_gowin -top $(TOP_MODULE)" >> $(BUILD_DIR)/synth_gowin.ys
+ $(YOSYS) $(BUILD_DIR)/synth_gowin.ys -o $(BUILD_DIR)/$(PRJ_NAME).json
+
+# place and route
+$(BUILD_DIR)/$(PRJ_NAME)_pnr.json: $(BUILD_DIR)/$(PRJ_NAME).json $(CST_FILES)
+ $(NEXTPNR) --json $(BUILD_DIR)/$(PRJ_NAME).json --write $(BUILD_DIR)/$(PRJ_NAME)_pnr.json --device $(DEVICE) --vopt family=$(FAMILY) --vopt cst=$(CST_FILES)
+
+# generate bitstream
+$(BITSTREAM): $(BUILD_DIR)/$(PRJ_NAME)_pnr.json
+ $(GOWIN_PACK) -d $(FAMILY) -o $(BITSTREAM) $(BUILD_DIR)/$(PRJ_NAME)_pnr.json
+
+bitstream: $(BITSTREAM)
+
+upload: $(BITSTREAM)
+ $(PROGRAMMER) -b $(BOARD) $(BITSTREAM)
+
+flash: $(BITSTREAM)
+ $(PROGRAMMER) -b $(BOARD) -f $(BITSTREAM)
+
+clean:
+ rm -rf $(BUILD_DIR)
+
+.PHONY: all clean bitsream upload flash
+