blob: 901d81f596e045cabb6852bb3015d2d56bece232 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
|