-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
187 lines (150 loc) · 4.38 KB
/
Makefile
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# SPDX-License-Identifier: AGPL-3.0-Only
# Copyright (C) 2022 Sean Anderson <seanga2@gmail.com>
Q = 1
ADOC = asciidoctor
SYNTH = yosys
PNR = nextpnr-ice40
ICARUS = iverilog
ICEPACK = icepack
VVP = vvp
.DELETE_ON_ERROR:
.PHONY: all
all: examples/breakout_hub/top.bin
.PHONY: FORCE
FORCE:
log:
mkdir $@
INCDIRS := rtl
LIBDIRS := rtl lib/verilog-lfsr/rtl
%.synth.json: %.v | log
$(SYNTH) -q -E $@.d -b json -o $@ -l log/$(*F).synth \
-p "read_verilog $(addprefix -I ,$(INCDIRS)) -sv $<" \
-p "hierarchy $(addprefix -libdir ,$(LIBDIRS) $(<D))" \
-p "synth_ice40 -top $(*F)"
define run-jsontov =
( grep timescale $*.v; $(SYNTH) -q -p "write_verilog -defparam -noattr" -f json $< ) > $@
endef
%.synth.v: %.synth.json %.v
$(run-jsontov)
%.place.v: %.place.json %.v
$(run-jsontov)
IFLAGS := -g2012 -gspecify -Wall
# Don't warn about including the timescale from common.vh
IFLAGS += -Wno-timescale
# Don't warn about mem2reg sensitivity
IFLAGS += -Wno-sensitivity-entire-array
EXTRA_V := rtl/iverilog_dump.v
define run-icarus =
$(ICARUS) $(IFLAGS) -I$(<D) $(addprefix -y,$(LIBDIRS) $(<D)) -M$@.pre -DTOP=$(TOP) \
-s $(TOP) -s iverilog_dump -o $@ $< $(EXTRA_V) && \
( echo -n "$@: " && tr '\n' ' ' ) < $@.pre > $@.d; RET=$$?; rm -f $@.pre; exit $$RET
endef
%.vvp: TOP = $(*F)
%.vvp: %.v rtl/iverilog_dump.v
$(run-icarus)
%.synth.vvp: TOP = $(*F)
%.synth.vvp %.place.vvp: EXTRA_V += $(shell $(SYNTH)-config --datdir)/ice40/cells_sim.v
# Don't warn about unused SB_IO ports
%.synth.vvp: IFLAGS += -Wno-portbind
%.synth.vvp: %.synth.v rtl/iverilog_dump.v
$(run-icarus)
%.place.vvp: TOP = top
# Don't warn about unused SB_IO ports
%.place.vvp: IFLAGS += -Wno-portbind
%.place.vvp: IFLAGS += -DTIMING -Ttyp
%.place.vvp: %.place.v rtl/iverilog_dump.v
$(run-icarus)
PNRARGS := --freq 125 --hx8k --package ct256 --pcf-allow-unconstrained --no-promote-globals
PNRARGS += --no-print-critical-path-source
define run-pnr =
$(PNR) -q $(PNRARGS) --json $< --log log/$(*F).$(LOG_EXT)
endef
%.sdf %.place.json &: PNRARGS += --write $*.place.json --sdf $*.sdf
%.sdf %.place.json &: LOG_EXT := place
%.sdf %.place.json &: %.synth.json | log
$(run-pnr)
PNR_RETRIES := 10
%.asc: PNRARGS += --pcf $*.pcf --asc $@ -r
%.asc: LOG_EXT := asc
%.asc: %.synth.json %.pcf | log
for i in $$(seq $(PNR_RETRIES)); do \
if $(run-pnr); then \
exit 0; \
fi \
done; \
exit 1
%.bin: %.asc
$(ICEPACK) $< $@
-include $(wildcard rtl/*.d)
-include $(wildcard examples/*/*.d)
export LIBPYTHON_LOC := $(shell cocotb-config --libpython)
VVPFLAGS := -M $(shell cocotb-config --lib-dir)
VVPFLAGS += -m $(shell cocotb-config --lib-name vpi icarus)
PLUSARGS = -fst +vcd=$@
# Always use color output if we have a tty. This allows for easy use of -O
ifeq ($(shell test -c /dev/stdin && echo 1),1)
export COCOTB_ANSI_OUTPUT=1
endif
# There are too my columns by default; reduce them
export COCOTB_REDUCED_LOG_FMT=2
define run-vvp =
MODULE=tb.$* $(VVP) $(VVPFLAGS) $< $(PLUSARGS)
endef
%.fst: PLUSARGS += +levels=0
%.fst: rtl/%.vvp tb/%.py FORCE
$(run-vvp)
%.synth.fst: PLUSARGS += +levels=1
%.synth.fst: rtl/%.synth.vvp tb/%.py FORCE
$(run-vvp)
%.place.fst: PLUSARGS += +levels=1 +sdf=rtl/$*.sdf
%.place.fst: rtl/%.place.vvp rtl/%.sdf tb/%.py FORCE
$(run-vvp)
MODULES += axis_replay_buffer
MODULES += axis_mii_tx
MODULES += axis_wb_bridge
MODULES += descramble
MODULES += hub
MODULES += hub_core
MODULES += led_blinker
MODULES += mdio
MODULES += mdio_io
MODULES += mdio_regs
MODULES += mii_elastic_buffer
MODULES += mii_io_rx
MODULES += mii_io_tx
MODULES += nrzi_decode
MODULES += nrzi_encode
MODULES += pcs_rx
MODULES += pcs_tx
MODULES += phy_core
MODULES += pmd_dp83223
MODULES += pmd_dp83223_rx
MODULES += reset_sync
MODULES += scramble
MODULES += uart_tx
MODULES += uart_rx
MODULES += uart_wb_bridge
MODULES += wb_mux
MODULES += wb_reg
.PHONY: test
test: $(addsuffix .fst,$(MODULES)) $(addsuffix .synth.fst,$(MODULES))
#test: $(addsuffix .place.fst,$(MODULES))
.PHONY: asc
asc: $(addprefix rtl/,$(addsuffix .asc,$(MODULES)))
doc/output:
mkdir -p $@
doc/output/%.html: doc/%.adoc doc/docinfo.html | doc/output
$(ADOC) -o $@ $<
DOCS += index
DOCS += interfaces
DOCS += uart_wb_bridge
.PHONY: htmldocs
htmldocs: $(addprefix doc/output/,$(addsuffix .html,$(DOCS)))
CLEAN_EXT := .json .asc .pre .vvp .d .synth.v .place.v .sdf .bin
.PHONY: clean
clean:
rm -f *.fst
rm -rf log
rm -f $(addprefix rtl/*,$(CLEAN_EXT))
rm -f $(addprefix examples/*/*,$(CLEAN_EXT))
rm -rf doc/output