-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
394 lines (320 loc) · 13.2 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# Starship Project
# Copyright (C) 2020-2023 by phantom
# Email: [email protected]
# This file is under MIT License, see https://www.phvntom.tech/LICENSE.txt
TOP := $(CURDIR)
SRC := $(TOP)/repo
BUILD := $(TOP)/build
CONFIG := $(TOP)/conf
SBT_BUILD := $(TOP)/target $(TOP)/project/target $(TOP)/project/project
ASIC := $(TOP)/asic
ifndef RISCV
$(error $$RISCV is undefined, please set $$RISCV to your riscv-toolchain)
endif
GCC_VERSION := $(word 1,$(subst ., ,$(shell gcc -dumpversion)))
ifeq ($(shell echo $(GCC_VERSION)\>=9 | bc ),0)
SCL_PREFIX := source scl_source enable devtoolset-10 &&
endif
all: bitstream
#######################################
#
# Starship Configuration
#
#######################################
include conf/build.mk
ifeq ($(STARSHIP_CORE),CVA6)
ifndef CVA6_REPO_DIR
$(error $$CVA6_REPO_DIR is undefined, please add $$CVA6_REPO_DIR in your configuration)
else
export CVA6_REPO_DIR
endif
endif
#######################################
#
# Verilog Generator
#
#######################################
ROCKET_TOP := $(STARSHIP_TH)
ROCKET_CONF := starship.With$(STARSHIP_CORE)Core,$(STARSHIP_CONFIG),starship.With$(STARSHIP_FREQ)MHz
ROCKET_SRC := $(SRC)/rocket-chip
ROCKET_BUILD := $(BUILD)/rocket-chip
ROCKET_SRCS := $(shell find $(TOP) -name "*.scala")
ROCKET_OUTPUT := $(STARSHIP_CORE).$(lastword $(subst ., ,$(STARSHIP_TOP))).$(lastword $(subst ., ,$(STARSHIP_CONFIG)))
ROCKET_FIRRTL := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).fir
ROCKET_ANNO := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).anno.json
ROCKET_DTS := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).dts
ROCKET_ROMCONF := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).rom.conf
ROCKET_TOP_VERILOG := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).top.v
ROCKET_TH_VERILOG := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).testharness.v
ROCKET_TOP_INCLUDE := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).top.f
ROCKET_TH_INCLUDE := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).testharness.f
ROCKET_TOP_MEMCONF := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).sram.top.conf
ROCKET_TH_MEMCONF := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).sram.testharness.conf
verilog-debug: FIRRTL_DEBUG_OPTION ?= -ll info
$(ROCKET_FIRRTL) $(ROCKET_DTS) $(ROCKET_ROMCONF) $(ROCKET_ANNO)&: $(ROCKET_SRCS)
mkdir -p $(ROCKET_BUILD)
sbt "runMain starship.utils.stage.FIRRTLGenerator \
--dir $(ROCKET_BUILD) \
--top $(ROCKET_TOP) \
--config $(ROCKET_CONF) \
--name $(ROCKET_OUTPUT)"
$(ROCKET_TOP_VERILOG) $(ROCKET_TOP_INCLUDE) $(ROCKET_TOP_MEMCONF) $(ROCKET_TH_VERILOG) $(ROCKET_TH_INCLUDE) $(ROCKET_TH_MEMCONF)&: $(ROCKET_FIRRTL)
mkdir -p $(ROCKET_BUILD)
sbt "runMain starship.utils.stage.RTLGenerator \
--infer-rw $(STARSHIP_TOP) \
-T $(STARSHIP_TOP) -oinc $(ROCKET_TOP_INCLUDE) \
--repl-seq-mem -c:$(STARSHIP_TOP):-o:$(ROCKET_TOP_MEMCONF) \
-faf $(ROCKET_ANNO) -fct firrtl.passes.InlineInstances \
-X verilog $(FIRRTL_DEBUG_OPTION) \
-i $< -o $(ROCKET_TOP_VERILOG)"
sbt "runMain starship.utils.stage.RTLGenerator \
--infer-rw $(STARSHIP_TH) \
-T $(STARSHIP_TOP) -TH $(STARSHIP_TH) -oinc $(ROCKET_TH_INCLUDE) \
--repl-seq-mem -c:$(STARSHIP_TH):-o:$(ROCKET_TH_MEMCONF) \
-faf $(ROCKET_ANNO) -fct firrtl.passes.InlineInstances \
-X verilog $(FIRRTL_DEBUG_OPTION) \
-i $< -o $(ROCKET_TH_VERILOG)"
touch $(ROCKET_TOP_INCLUDE) $(ROCKET_TH_INCLUDE)
#######################################
#
# SRAM Generator
#
#######################################
FIRMWARE_SRC := $(TOP)/firmware
FIRMWARE_BUILD := $(BUILD)/firmware
FSBL_SRC := $(FIRMWARE_SRC)/fsbl
FSBL_BUILD := $(FIRMWARE_BUILD)/fsbl
ROCKET_INCLUDE := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).f
ROCKET_ROM_HEX := $(FSBL_BUILD)/sdboot.hex
ROCKET_ROM := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).rom.v
ROCKET_TOP_SRAM := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).behav_srams.top.v
ROCKET_TH_SRAM := $(ROCKET_BUILD)/$(ROCKET_OUTPUT).behav_srams.testharness.v
VERILOG_SRC := $(ROCKET_TOP_SRAM) $(ROCKET_TH_SRAM) \
$(ROCKET_ROM) \
$(ROCKET_TH_VERILOG) $(ROCKET_TOP_VERILOG)
$(ROCKET_INCLUDE): | $(ROCKET_TH_INCLUDE) $(ROCKET_TOP_INCLUDE)
mkdir -p $(ROCKET_BUILD)
cat $(ROCKET_TH_INCLUDE) $(ROCKET_TOP_INCLUDE) 2> /dev/null | sort -u > $@
echo $(VERILOG_SRC) >> $@
sed -i "s/.*\.f$$/-f &/g" $@
$(ROCKET_TOP_SRAM): $(ROCKET_TOP_MEMCONF)
mkdir -p $(ROCKET_BUILD)
$(ROCKET_SRC)/scripts/vlsi_mem_gen $(ROCKET_TOP_MEMCONF) > $(ROCKET_TOP_SRAM)
$(ROCKET_TH_SRAM): $(ROCKET_TH_MEMCONF)
mkdir -p $(ROCKET_BUILD)
$(ROCKET_SRC)/scripts/vlsi_mem_gen $(ROCKET_TH_MEMCONF) > $(ROCKET_TH_SRAM)
$(ROCKET_ROM_HEX): $(ROCKET_DTS)
mkdir -p $(FSBL_BUILD)
$(MAKE) -C $(FSBL_SRC) PBUS_CLK=$(STARSHIP_FREQ)000000 ROOT_DIR=$(TOP) DTS=$(ROCKET_DTS) hex
$(ROCKET_ROM): $(ROCKET_ROM_HEX) $(ROCKET_ROMCONF)
mkdir -p $(ROCKET_BUILD)
$(ROCKET_SRC)/scripts/vlsi_rom_gen $(ROCKET_ROMCONF) $< > $@
verilog: $(VERILOG_SRC)
verilog-debug: verilog
verilog-patch: verilog
# sed -i "s/s2_pc <= 42'h10000/s2_pc <= 42'h80000000/g" $(ROCKET_TOP_VERILOG)
sed -i "s/s2_pc <= 40'h10000/s2_pc <= 40'h80000000/g" $(ROCKET_TOP_VERILOG)
sed -i "s/core_boot_addr_i = 64'h10000/core_boot_addr_i = 64'h80000000/g" $(ROCKET_TOP_VERILOG)
sed -i "s/40'h10000 : 40'h0/40'h80000000 : 40'h0/g" $(ROCKET_TOP_VERILOG)
sed -i "s/ram\[initvar\] = {2 {\$$random}}/ram\[initvar\] = 0/g" $(ROCKET_TH_SRAM)
sed -i "s/_covMap\[initvar\] = _RAND/_covMap\[initvar\] = 0; \/\//g" $(ROCKET_TOP_VERILOG)
sed -i "s/_covState = _RAND/_covState = 0; \/\//g" $(ROCKET_TOP_VERILOG)
sed -i "s/_covSum = _RAND/_covSum = 0; \/\//g" $(ROCKET_TOP_VERILOG)
#######################################
#
# Bitstream Generator
#
#######################################
VIVADO_TOP := $(lastword $(subst ., ,$(STARSHIP_TH)))
VIVADO_SRC := $(SRC)/rocket-chip-fpga-shells
VIVADO_SCRIPT := $(VIVADO_SRC)/xilinx
VIVADO_BUILD := $(BUILD)/vivado
VIVADO_BITSTREAM := $(VIVADO_BUILD)/$(ROCKET_OUTPUT).bit
$(VIVADO_BITSTREAM): $(ROCKET_INCLUDE) $(VERILOG_SRC)
mkdir -p $(VIVADO_BUILD)
cd $(VIVADO_BUILD); vivado -mode batch -nojournal \
-source $(VIVADO_SCRIPT)/common/tcl/vivado.tcl \
-tclargs -F "$(ROCKET_INCLUDE)" \
-top-module "$(VIVADO_TOP)" \
-ip-vivado-tcls "$(shell find '$(ROCKET_BUILD)' -name '*.vivado.tcl')" \
-board "$(STARSHIP_BOARD)"
bitstream: $(VIVADO_BITSTREAM)
#######################################
#
# RTL Simulation
#
#######################################
SIM_DIR := $(ASIC)/sim
TB_TOP ?= Testbench
TESTCASE_ELF := $(STARSHIP_TESTCASE)
TESTCASE_BIN := $(shell mktemp)
TESTCASE_HEX := $(STARSHIP_TESTCASE).hex
CHISEL_DEFINE := +define+PRINTF_COND=$(TB_TOP).printf_cond \
+define+STOP_COND=!$(TB_TOP).reset \
+define+RANDOMIZE \
+define+RANDOMIZE_MEM_INIT \
+define+RANDOMIZE_REG_INIT \
+define+RANDOMIZE_GARBAGE_ASSIGN \
+define+RANDOMIZE_INVALID_ASSIGN \
+define+RANDOMIZE_DELAY=0.1
SPIKE_DIR := $(SRC)/riscv-isa-sim
SPIKE_SRC := $(shell find $(SPIKE_DIR) -name "*.cc" -o -name "*.h" -o -name "*.c")
SPIKE_BUILD := $(BUILD)/spike
SPIKE_LIB := $(addprefix $(SPIKE_BUILD)/,libcosim.a libriscv.a libdisasm.a libsoftfloat.a libfesvr.a libfdt.a)
SPIKE_INCLUDE := $(SPIKE_DIR) $(SPIKE_DIR)/cosim $(SPIKE_DIR)/fdt $(SPIKE_DIR)/fesvr \
$(SPIKE_DIR)/riscv $(SPIKE_DIR)/softfloat $(SPIKE_BUILD)
export LD_LIBRARY_PATH=$(SPIKE_BUILD)
$(SPIKE_BUILD)/Makefile:
mkdir -p $(SPIKE_BUILD)
cd $(SPIKE_BUILD); $(SCL_PREFIX) $(SPIKE_DIR)/configure
$(SPIKE_LIB)&: $(SPIKE_SRC) $(SPIKE_BUILD)/Makefile
cd $(SPIKE_BUILD); $(SCL_PREFIX) make -j$(shell nproc) $(notdir $(SPIKE_LIB))
#######################################
#
# Synopsys VCS
#
#######################################
VCS_OUTPUT := $(BUILD)/vcs
VERDI_OUTPUT:= $(BUILD)/verdi
VCS_BUILD := $(VCS_OUTPUT)/build
VCS_LOG := $(VCS_OUTPUT)/log
VCS_WAVE := $(VCS_OUTPUT)/wave
VCS_TARGET := $(VCS_BUILD)/$(TB_TOP)
VCS_INCLUDE := $(ROCKET_BUILD)+$(SIM_DIR)
VCS_CFLAGS := -std=c++17 $(addprefix -I,$(SPIKE_INCLUDE)) -I$(ROCKET_BUILD)
VCS_SRC_C := $(SIM_DIR)/spike_difftest.cc \
$(SPIKE_LIB) \
$(SIM_DIR)/timer.cc
VCS_SRC_V := $(SIM_DIR)/$(TB_TOP).v \
$(SIM_DIR)/spike_difftest.v \
$(SIM_DIR)/tty.v
VCS_DEFINE := +define+MODEL=$(STARSHIP_TH) \
+define+TOP_DIR=\"$(VCS_OUTPUT)\" \
+define+INITIALIZE_MEMORY \
+define+CLOCK_PERIOD=1.0 \
+define+DEBUG_FSDB \
+define+TARGET_$(STARSHIP_CORE)
VCS_PARAL_COM := -j$(shell nproc) # -fgp
VCS_PARAL_RUN := # -fgp=num_threads:1,num_fsdb_threads:1 # -fgp=num_cores:$(shell nproc),percent_fsdb_cores:30
VCS_OPTION := -quiet -notice -line +rad -full64 +nospecify +notimingcheck -deraceclockdata \
-sverilog +systemverilogext+.sva+.pkg+.sv+.SV+.vh+.svh+.svi+ -assert svaext \
+vcs+initreg+random +v2k -debug_acc+all -timescale=1ns/10ps +incdir+$(VCS_INCLUDE) \
$(VCS_PARAL_COM) -CFLAGS "$(VCS_CFLAGS)" \
$(CHISEL_DEFINE) $(VCS_DEFINE)
VCS_SIM_OPTION := +vcs+initreg+random $(VCS_PARAL_RUN) +testcase=$(TESTCASE_ELF)
vcs-wave: VCS_SIM_OPTION += +dump +uart_tx=0
vcs-debug: VCS_SIM_OPTION += +verbose +dump +uart_tx=0
vcs-fuzz: VCS_SIM_OPTION += +fuzzing +uart_tx=0
vcs-fuzz-debug: VCS_SIM_OPTION += +fuzzing +verbose +dump +uart_tx=0
vcs-jtag: VCS_SIM_OPTION += +jtag_rbb_enable=1 +verbose +uart_tx=0
vcs-jtag-debug: VCS_SIM_OPTION += +jtag_rbb_enable=1 +verbose +dump +uart_tx=0
$(VCS_TARGET): $(VERILOG_SRC) $(ROCKET_ROM_HEX) $(ROCKET_INCLUDE) $(VCS_SRC_V) $(VCS_SRC_C) $(SPIKE_LIB)
$(MAKE) verilog-patch
mkdir -p $(VCS_BUILD) $(VCS_LOG) $(VCS_WAVE)
cd $(VCS_BUILD); $(SCL_PREFIX) vcs $(VCS_OPTION) -l $(VCS_LOG)/vcs.log -top $(TB_TOP) \
-f $(ROCKET_INCLUDE) $(VCS_SRC_V) $(VCS_SRC_C) -o $@
$(TESTCASE_HEX): $(TESTCASE_ELF)
riscv64-unknown-elf-objcopy --gap-fill 0 \
--set-section-flags .bss=alloc,load,contents \
--set-section-flags .sbss=alloc,load,contents \
--set-section-flags .tbss=alloc,load,contents \
-O binary $< $(TESTCASE_BIN)
od -v -An -tx8 $(TESTCASE_BIN) > $@
rm $(TESTCASE_BIN)
vcs: $(VCS_TARGET) $(TESTCASE_HEX)
mkdir -p $(VCS_BUILD) $(VCS_LOG) $(VCS_WAVE)
cd $(VCS_BUILD); \
$(VCS_TARGET) -quiet +ntb_random_seed_automatic -l $(VCS_LOG)/sim.log \
$(VCS_SIM_OPTION) 2>&1 | tee /tmp/rocket.log; exit "$${PIPESTATUS[0]}";
vcs-wave vcs-debug: vcs
vcs-fuzz vcs-fuzz-debug: vcs
vcs-jtag vcs-jtag-debug: vcs
verdi:
mkdir -p $(VERDI_OUTPUT)
touch $(VERDI_OUTPUT)/signal.rc
cd $(VERDI_OUTPUT); \
verdi -$(VCS_OPTION) -q -ssy -ssv -ssz -autoalias \
-ssf $(VCS_WAVE)/starship.fsdb -sswr $(VERDI_OUTPUT)/signal.rc \
-logfile $(VCS_LOG)/verdi.log -top $(TB_TOP) -f $(ROCKET_INCLUDE) $(VCS_SRC_V) &
#######################################
#
# Verilator
#
#######################################
VLT_BUILD := $(BUILD)/verilator
VLT_WAVE := $(VLT_BUILD)/wave
VLT_TARGET := $(VLT_BUILD)/$(TB_TOP)
VLT_CFLAGS := -std=c++17 $(addprefix -I,$(SPIKE_INCLUDE)) -I$(ROCKET_BUILD)
VLT_SRC_C := $(SIM_DIR)/spike_difftest.cc \
$(SPIKE_LIB) \
$(SIM_DIR)/timer.cc
VLT_SRC_V := $(SIM_DIR)/$(TB_TOP).v \
$(SIM_DIR)/spike_difftest.v \
$(SIM_DIR)/tty.v
VLT_DEFINE := +define+MODEL=$(STARSHIP_TH) \
+define+TOP_DIR=\"$(VLT_BUILD)\" \
+define+INITIALIZE_MEMORY \
+define+CLOCK_PERIOD=1.0 \
+define+DEBUG_VCD \
+define+TARGET_$(STARSHIP_CORE)
VLT_OPTION := -Wno-WIDTH -Wno-STMTDLY -Wno-fatal --timescale 1ns/10ps --trace --timing \
+systemverilogext+.sva+.pkg+.sv+.SV+.vh+.svh+.svi+ \
+incdir+$(ROCKET_BUILD) +incdir+$(SIM_DIR) $(CHISEL_DEFINE) $(VLT_DEFINE) \
--cc --exe --Mdir $(VLT_BUILD) --top-module $(TB_TOP) --main -o $(TB_TOP) \
-CFLAGS "-DVL_DEBUG -DTOP=${TB_TOP} ${VLT_CFLAGS}"
VLT_SIM_OPTION := +testcase=$(TESTCASE_ELF)
vlt-wave: VLT_SIM_OPTION += +dump
vlt-jtag: VLT_SIM_OPTION += +jtag_rbb_enable=1
vlt-jtag-debug: VLT_SIM_OPTION += +dump +jtag_rbb_enable=1
$(VLT_TARGET): $(VERILOG_SRC) $(ROCKET_ROM_HEX) $(ROCKET_INCLUDE) $(VLT_SRC_V) $(VLT_SRC_C) $(SPIKE_LIB)
$(MAKE) verilog-patch
mkdir -p $(VLT_BUILD) $(VLT_WAVE)
cd $(VLT_BUILD); verilator $(VLT_OPTION) -f $(ROCKET_INCLUDE) $(VLT_SRC_V) $(VLT_SRC_C)
make -C $(VLT_BUILD) -f V$(TB_TOP).mk $(TB_TOP)
vlt: $(VLT_TARGET) $(TESTCASE_HEX)
cd $(VLT_BUILD); ./$(TB_TOP) $(VLT_SIM_OPTION)
vlt-wave: vlt
vlt-jtag: vlt
vlt-jtag-debug: vlt
gtkwave:
gtkwave $(VLT_WAVE)/starship.vcd
#######################################
#
# Sythesis
#
#######################################
#######################################
#
# Synopsys DC
#
#######################################
DC_TOP := $(lastword $(subst ., ,$(STARSHIP_TH)))
DC_SRC := $(ASIC)/scripts/syn
DC_OUTPUT := $(BUILD)/syn
DC_BUILD := $(DC_OUTPUT)/build
DC_LOG := $(DC_OUTPUT)/log
DC_NETLIST := $(DC_OUTPUT)/netlist
#######################################
#
# Yosys
#
#######################################
#######################################
#
# Utils
#
#######################################
.PHONY: clean clean-all patch
patch:
find patch -name "*.patch" | \
awk -F/ '{print \
"(" \
"echo \"Apply " $$0 "\" && " \
"cd repo/" $$2 " && " \
"git apply --ignore-space-change --ignore-whitespace ../../" $$0 \
")" \
}' | sh
clean:
rm -rf $(BUILD)
clean-all:
rm -rf $(BUILD) $(SBT_BUILD)