-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
142 lines (105 loc) · 3.42 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
TARGET ?= upduino
PACKAGE=sg48
DEVICE=5k
SPEED=up
BUILDDIR=build
# Sources:
TESTS=\
uart \
timer \
system \
upduino_post \
RTL=\
rtl/ALU.v\
rtl/cpu.v\
rtl/minirom.v\
rtl/pll.v\
rtl/ps2.v\
rtl/ram.v\
rtl/rgbled.v\
rtl/spi.v\
rtl/system.v\
rtl/timer.v\
rtl/uart.v\
rtl/vga.v\
# Firmware to save into flash at address 0x20000.
FIRMWARE=$(BUILDDIR)/firmware.bin
# Clock constrains for packer:
SDC_FILE=clk-pre.sdc
HEXFILE=$(BUILDDIR)/minirom.hex
all: $(TARGET) $(FIRMWARE)
.PHONY: prog
prog: prog-fpga prog-fw
.PHONY: prog-fpga
prog-fpga: $(BUILDDIR)/$(TARGET).bin
# Only program if not already ok
iceprog -c "$<" || iceprog "$<"
.PHONY: prog-fw
prog-fw: $(FIRMWARE)
iceprog -o 128k -c "$<" || iceprog -o 128k "$<"
.PHONY: test
test: $(TESTS:%=$(BUILDDIR)/%.vcd)
.PHONY: $(TARGET)
$(TARGET): %: $(BUILDDIR)/%.bin $(BUILDDIR)/%.time
$(BUILDDIR)/%.blif: rtl/%.v | $(BUILDDIR)
yosys -q -p 'synth_ice40 -top $* -blif $@' -l $(@:.blif=-yosys.log) $(filter %.v, $^) \
&& sed -n -e '/^[1-9].*statistics/,/^[1-9]/p' $(@:.blif=-yosys.log)
$(BUILDDIR)/%.json: rtl/%.v | $(BUILDDIR)
yosys -q -p 'synth_ice40 -top $* -json $@' -l $(@:.json=-yosys.log) $(filter %.v, $^) \
&& sed -n -e '/^[1-9].*statistics/,/^[1-9]/p' $(@:.json=-yosys.log)
# Place using ARACHNE-PNR
#$(BUILDDIR)/%.asc: $(BUILDDIR)/%.blif rtl/%.pcf
# arachne-pnr -d $(DEVICE) -P $(PACKAGE) -p rtl/$*.pcf -o $@ $<
# Place using NEXTPNR
$(BUILDDIR)/%.asc: $(BUILDDIR)/%.json rtl/%.pcf
nextpnr-ice40 --pre-pack $(SDC_FILE) \
--$(SPEED)$(DEVICE) --json $< --pcf rtl/$*.pcf --asc $@
$(BUILDDIR)/%.bin: $(BUILDDIR)/%.asc
icepack $< $@
# Timing report
$(BUILDDIR)/%.time: $(BUILDDIR)/%.asc rtl/%.pcf
icetime -m -t -P $(PACKAGE) -p rtl/$*.pcf -d $(SPEED)$(DEVICE) -r $@ $<
# Post-synthesis verilog - from BLIF
#$(BUILDDIR)/%_syn.v: $(BUILDDIR)/%.blif
# yosys -o $@ -p 'read_blif -wideports $<'
# Post-synthesis verilog - from JSON
$(BUILDDIR)/%_syn.v: $(BUILDDIR)/%.json
yosys -o $@ -p 'read_json $<'
# Post synthesis simulator
$(BUILDDIR)/%_post_test: tests/%_post_tb.v $(BUILDDIR)/%_syn.v
# Filter out PLL cell to allow simulation
sed -i 's/ SB_PLL40_CORE/ TB_SB_PLL40_CORE/' $(BUILDDIR)/$*_syn.v
iverilog -g2012 -o $@ -D POST_SYNTHESIS $< $(BUILDDIR)/$*_syn.v \
`yosys-config --datdir/ice40/cells_sim.v`
# Module simulator
$(BUILDDIR)/%_test: tests/%_tb.v rtl/%.v | $(BUILDDIR)
iverilog -g2012 -o $@ $(filter %.v , $^) `yosys-config --datdir/ice40/cells_sim.v`
# Run simulation
$(BUILDDIR)/%.vcd: $(BUILDDIR)/%_test
vvp $< +vcd=$@
# Assemble sources
$(BUILDDIR)/%.bin: asm/%.asm | $(BUILDDIR)
mads $< -l:$(@:.bin=.lst) -t:$(@:.bin=.lbl) -o:$@
$(BUILDDIR)/%.hex: $(BUILDDIR)/%.bin | $(BUILDDIR)
od -An -tx1 -w1 -v $< > $@
# Make folders
$(BUILDDIR):
mkdir -p $(BUILDDIR)
clean:
rm -rf $(BUILDDIR)
.PRECIOUS: $(BUILDDIR)/%.blif $(BUILDDIR)/%.json $(BUILDDIR)/%.asc $(BUILDDIR)/%_syn.v
# Dependencies
$(BUILDDIR)/system.json: $(RTL)
$(BUILDDIR)/system.blif: $(RTL)
$(BUILDDIR)/system_test: $(RTL)
$(BUILDDIR)/upduino.json: $(RTL)
$(BUILDDIR)/upduino.blif: $(RTL)
$(BUILDDIR)/upduino_test: $(RTL)
$(BUILDDIR)/system_test: $(HEXFILE)
$(BUILDDIR)/system.blif: $(HEXFILE)
$(BUILDDIR)/system.json: $(HEXFILE)
$(BUILDDIR)/upduino_test: $(HEXFILE)
$(BUILDDIR)/upduino.blif: $(HEXFILE)
$(BUILDDIR)/upduino.json: $(HEXFILE)
$(BUILDDIR)/minirom.bin: asm/defines.inc
$(BUILDDIR)/firmware.bin: asm/defines.inc