blob: 516898f5f36bd48a802d38deb12f5556d6b3f0d0 (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
.SUFFIXES:
## Variables
PROGRAM ?= led
CST ?= tangnano9k.cst
FLASH_OPTS ?=
# https://github.com/YosysHQ/apicula/wiki/Nextpnr%E2%80%90Himbaechel-Gowin
# but
# https://github.com/YosysHQ/apicula/wiki/gowin_pack says something different. huh?
DEVICE_NAME ?= GW1NR-LV9QN88PC6/I5
DEVICE_FAMILY ?= GW1N-9C
# Can't use this for deps:
# -E $(PROGRAM).deps
# as yosys needs to have -o specified for this to work
# but I specify the command manually
# also, yosys inserts /tmp/ files which makes this useless.
YOSYS_OPTS ?= -Q -q -l $(PROGRAM).yosys.log -e "conflict|is used but has no driver"
DEPS := $(wildcard *.dep)
# this is "bad", as it runs the deps target every time
# probably because of the include below
# SOURCES := $(wildcard *.v)
# DEPS := $(SOURCES:.v=.dep)
## default target
all: $(PROGRAM).fs
## dependencies
tangnano9k.cst:
wget https://github.com/YosysHQ/apicula/raw/refs/heads/master/examples/tangnano9k.cst || \
curl -LO https://github.com/YosysHQ/apicula/raw/refs/heads/master/examples/tangnano9k.cst
## helper targets
.PHONY: clean flash show
show: $(PROGRAM).v
yosys -p "read_verilog $<; show $(PROGRAM)"
flash: $(PROGRAM).fs
openFPGALoader -b tangnano9k $(FLASH_OPTS) $(PROGRAM).fs
clean:
rm -rf *.json *.fs *.svg *.log *.dep
## Patterns
# synthesize
%.json: %.v
# sh resolvedeps.sh $<
# only used for dep-generation, output file is needed for dep file, but otherwise useless
# this must happen *without* synth_gowin, as this includes additional files, which ruin the depfile.
yosys $< -E $*.dep -o $@ && rm -f $@
yosys -p "read_verilog $<; synth_gowin -top $* -json $@" $(YOSYS_OPTS)
# because yosys -E is buggy, or behaves differently than expected,
# use gawk to force-create deps.
%.dep: %.v
# sh resolvedeps.sh $<
yosys $< -E $*.dep -o $*.json && rm -f $*.json
# place and route?
%.pnr.json: %.json $(CST)
nextpnr-himbaechel --json $< --write $@ \
--device $(DEVICE_NAME) --vopt family=$(DEVICE_FAMILY) \
--vopt cst=$(CST) \
--placed-svg $*.plc.svg \
--routed-svg $*.rt.svg \
-q -l $(PROGRAM).pnr.log \
--sdc clock.sdc \
|| \
nextpnr-gowin --json $< --write $@ \
--device $(DEVICE_NAME) --family $(DEVICE_FAMILY) \
--cst $(CST) \
--placed-svg $*.plc.svg \
--routed-svg $*.rt.svg \
-q -l $(PROGRAM).pnr.log \
--sdc clock.sdc
# pack bitstream
%.fs: %.pnr.json
gowin_pack -d $(DEVICE_FAMILY) -o $@ $<
## inter-file dependencies
-include $(DEPS)
-include $($(wildcard *.fs:.fs=.dep)
|