-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile.mk
More file actions
190 lines (152 loc) · 6.33 KB
/
Makefile.mk
File metadata and controls
190 lines (152 loc) · 6.33 KB
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
188
189
190
# Default values for architecture and defines
XLEN := 32
ARCH := rv32i
ABI := ilp32
MACHINE := elf32lriscv
RV := rv32
DEFINES :=
# Set things up for a 64bit CPU
ifeq ($(XLEN), 64)
XLEN := 64
ARCH := rv64i
ABI := lp64
RV := rv64
MACHINE := elf64lriscv
DEFINES += -DXLEN=64
endif
# Modify ARCH and DEFINES if SUPPORT_M is set
ifeq ($(SUPPORT_M), 1)
ARCH := $(ARCH)m
DEFINES += -DSUPPORT_M
endif
# Modify ARCH and DEFINES if SUPPORT_M is set
ifeq ($(SUPPORT_B), 1)
ARCH := $(ARCH)_zic64b_zicbom_zicbop
DEFINES += -DSUPPORT_B
endif
# Modify ARCH and DEFINES if SUPPORT_BSUPPORT_ZICSR is set
ifeq ($(SUPPORT_ZICSR), 1)
ARCH := $(ARCH)_zicsr
DEFINES += -DSUPPORT_ZICSR
endif
all:
@echo "################################################################################"
@echo "# #"
@echo "# RISC-V SoC Project #"
@echo "# #"
@echo "################################################################################"
@echo ""
@echo "make p_soc ................. Build a SOC with a paralell bus"
@echo "make tl_soc ................ Build a SOC with a TileLink bus"
@echo "make load .................. Load the built SoC to the FPGA"
@echo ""
@echo "make test .................. Run all testbenches"
@echo "make run_cpu ............... Simulate the cpu in iverilog"
@echo "make run_soc ............... Simulate the soc in iverilog"
##
# SOC Build 1
##
p_soc: bios out
# Compile a C program in riscv asm
bios: etc/main.c
echo $(ARCH)
riscv64-unknown-elf-gcc $(DEFINES) -c -fPIC -march=$(ARCH) -mabi=$(ABI) -nostartfiles -nostdlib -o etc/bios/start.o etc/bios/start.S
riscv64-unknown-elf-gcc $(DEFINES) -c -fPIC -march=$(ARCH) -mabi=$(ABI) -nostartfiles -nostdlib -o etc/bios/bios.o etc/bios/bios.c
riscv64-unknown-elf-ld -m $(MACHINE) -o etc/bios/program.o etc/bios/start.o etc/bios/bios.o
riscv64-unknown-elf-objcopy -O binary etc/bios/program.o etc/bios/bios.bin
riscv64-unknown-elf-objdump -D -b binary -m riscv:$(RV) -M numeric etc/bios/bios.bin > etc/bios/bios.opcodes
hexdump -v -e '1/1 "%02x\n"' etc/bios/bios.bin | \
awk 'BEGIN {desired=256} {print; count++} END {for(i=count+1;i<=desired;i++) print "00"}' > etc/bios/bios.hex
rm etc/bios/*.o
# Synthesis
synthesis: src/p_soc.sv
mkdir -p ./graph
yosys -D SYNTHESIS -q -p "read_verilog -sv -I src/ src/p_soc.sv; hierarchy -check; check; show -colors 1 -width -signed -stretch -prefix graph/soc -format dot; synth_gowin -top top -noabc9 -json synthesis.json"
stat:
yosys -D SYNTHESIS -p "read_verilog -sv src/p_soc.sv; hierarchy -check; check; synth_gowin -top top -noabc9; stat -hier"
# Place and Route
bitstream: synthesis
nextpnr-himbaechel --json synthesis.json --write bitstream.json --device ${DEVICE} --vopt family=${FAMILY} --vopt cst=etc/boards/${BOARD}.cst
# Generate Bitstream
out: bitstream
gowin_pack -d ${FAMILY} -o out.fs bitstream.json
##
# SOC Build 2
##
tl_soc: bios2 out2
# Compile a C program in riscv asm
bios2: etc/main.c
echo $(ARCH)
riscv64-unknown-elf-gcc $(DEFINES) -c -fPIC -march=$(ARCH) -mabi=$(ABI) -nostartfiles -nostdlib -o etc/bios/start.o etc/bios/start.S
riscv64-unknown-elf-gcc $(DEFINES) -c -fPIC -march=$(ARCH) -mabi=$(ABI) -nostartfiles -nostdlib -o etc/bios/bios.o etc/bios/bios.c
riscv64-unknown-elf-ld -m $(MACHINE) -o etc/bios/program.o etc/bios/start.o etc/bios/bios.o
riscv64-unknown-elf-objcopy -O binary etc/bios/program.o etc/bios/bios.bin
riscv64-unknown-elf-objdump -D -b binary -m riscv:$(RV) -M numeric etc/bios/bios.bin > etc/bios/bios.opcodes
hexdump -v -e '1/1 "%02x\n"' etc/bios/bios.bin | \
awk 'BEGIN {desired=256} {print; count++} END {for(i=count+1;i<=desired;i++) print "00"}' > etc/bios/bios.hex
rm etc/bios/*.o
# Synthesis
synthesis2: src/tl_soc.sv
mkdir -p ./graph
yosys -D SYNTHESIS -q -p "read_verilog -sv -I src/ src/tl_soc.sv; hierarchy -check; check; show -colors 1 -width -signed -stretch -prefix graph/soc -format dot; synth_gowin -top top -noabc9 -json synthesis.json"
stat2:
yosys -D SYNTHESIS -p "read_verilog -sv src/tl_soc.sv; hierarchy -check; check; synth_gowin -top top -noabc9; stat -hier"
# Place and Route
bitstream2: synthesis2
nextpnr-himbaechel --json synthesis.json --write bitstream.json --device ${DEVICE} --vopt family=${FAMILY} --vopt cst=etc/boards/${BOARD}.cst --placed-svg graph/soc2_place.svg --routed-svg graph/soc2_routed.svg
# Generate Bitstream
out2: bitstream2
gowin_pack -d ${FAMILY} -o out.fs bitstream.json
##
# Develompent
##
# Create graphs from the dot file
graph:
dot -Tpng ./graph/soc.dot -O
# Program Board
load:
openFPGALoader -b ${BOARD} out.fs -f
# Remove temp files
clean:
rm -f etc/bios/bios.hex
rm -f etc/bios/bios.bin
rm -f etc/bios/bios.opcodes
rm -f out.fs
rm -f bitstream.json
rm -f synthesis.json
rm -rf graph/
##
# Develompent
##
# Compile a C program in riscv asm
asm: etc/main.c
echo $(ARCH)
rm -f etc/program.sv
riscv64-unknown-elf-gcc $(DEFINES) -c -fPIC -march=$(ARCH) -mabi=$(ABI) -nostartfiles -nostdlib -o etc/start.o etc/start.S
riscv64-unknown-elf-gcc $(DEFINES) -c -fPIC -march=$(ARCH) -mabi=$(ABI) -nostartfiles -nostdlib -o etc/main.o etc/main.c
riscv64-unknown-elf-ld -m $(MACHINE) -o etc/program.o etc/start.o etc/main.o
riscv64-unknown-elf-objcopy -O binary etc/program.o etc/program.bin
riscv64-unknown-elf-objdump -D -b binary -m riscv:$(RV) -M numeric etc/program.bin > etc/program.opcodes
run_cpu: asm
mkdir -p ./graph
python etc/scripts/bin_to_sv_mem.py etc/program.bin etc/program.sv etc/program.opcodes -m mock_mem -x 16
rm etc/*.o etc/program.bin etc/program.opcodes
iverilog -g2012 -I src/ $(DEFINES) -o graph/cpu_runner.vvp -s cpu_runner etc/run.sv
vvp -N graph/cpu_runner.vvp
mv ./cpu_runner.vcd ./graph/cpu_runner.vcd
rm -f graph/cpu_runner.vvp
run_soc: bios
mkdir -p ./graph
iverilog -g2012 -I src/ $(DEFINES) -o graph/soc_runner.vvp -s soc_runner etc/runsoc.sv
vvp -N graph/soc_runner.vvp
mv ./soc_runner.vcd ./graph/soc_runner.vcd
rm -f graph/soc_runner.vvp
##
# Tests
##
include MakefileTests.mk
# Automatically find all test_* targets
TESTS := $(shell grep -E '^[[:space:]]*test_[^:]+:$$' MakefileTests.mk | sed -E 's/^[[:space:]]*//' | cut -d':' -f1 )
test: $(TESTS)
.PHONY: load test $(TESTS)
.INTERMEDIATE: synthesis.json bitstream.json