-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
266 lines (218 loc) · 7.6 KB
/
Copy pathMakefile
File metadata and controls
266 lines (218 loc) · 7.6 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
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
# Project Configuration
PRJ := cl1
PRJ_DIR := $(CURDIR)
BUILD_DIR := ./build/
WAVE_DIR := ./wave
SAIF_DIR := ./saif
VSRC_DIR := ./vsrc
CPUTOP := Cl1Top
DUMP_WAVE :=
PWR_ANALYSIS :=1
CONFIG_DBG = n
CONFIG_NETSIM = n
POSTSIM =1
SDF_ON :=1
#POSTSIM_PATH = /nfs/share/home/wangpian/cl1/backend/Flow_S110/bes_data/sta/sdf/Cl1Top_V3_2026-01-16_20-38_CTS_MAX_CMAX_SDF_Jan_16_20
POSTSIM_PATH = /nfs/share/home/wangpian/cl1/backend/Flow_S110/bes_data/sta/sdf/Cl1Top_Vbase2_2026-02-23_20-37_CTS_MAX_CMAX_SAIF_SDF_Feb_23_20
CPU_DIR := $(if $(POSTSIM), $(POSTSIM_PATH), \
$(if $(filter y, $(CONFIG_NETSIM)), ./soc/core_netlist, $(VSRC_DIR)))
$(info ========================================================)
$(info > POSTSIM Mode: $(if $(POSTSIM), ON, OFF))
$(info > CPU_DIR Path: $(CPU_DIR))
$(info ========================================================)
NETSIM_VZ_FILE := /nfs/share/home/wangpian/cl1/backend/Flow_S110/bes_data/syn/netlist/Cl1Top_FINM100VPOWER20260114_1623.syn.v.gz
ifeq ($(strip $(CONFIG_NETSIM)), y)
_AUTO_UNZIP_VZ := $(shell \
if [ -f $(NETSIM_VZ_FILE) ]; then \
echo "Wait... Decoompressing verilog netlist: $(NETSIM_VZ_FILE)"; \
gzip -cd $(NETSIM_VZ_FILE) > ./soc/core_netlist/Cl1Top_netlist.v; \
else \
echo "Warning: Verilog netlist .gz file not found at $(NETSIM_VZ_FILE)"; \
fi \
)
endif
ifneq ($(strip $(POSTSIM)),)
SDF_GZ_FILE := $(wildcard $(POSTSIM_PATH)/Cl1Top*.sdf.gz)
SDF_OUT_FILE := $(POSTSIM_PATH)/Cl1Top.sdf
_AUTO_UNZIP_SDF := $(shell \
if [ -f $(SDF_GZ_FILE) ]; then \
if [ ! -f $(SDF_OUT_FILE) ] || [ $(SDF_GZ_FILE) -nt $(SDF_OUT_FILE) ]; then \
echo "Wait... Decompressing SDF: $(SDF_GZ_FILE) -> $(SDF_OUT_FILE)"; \
gzip -cd $(SDF_GZ_FILE) > $(SDF_OUT_FILE); \
else \
echo "SDF file is up-to-date: $(SDF_OUT_FILE)"; \
fi; \
else \
echo "Warning: SDF .gz file not found at $(SDF_GZ_FILE)"; \
fi \
)
endif
$(shell mkdir -p $(BUILD_DIR))
$(shell mkdir -p $(WAVE_DIR))
$(shell mkdir -p $(SAIF_DIR))
# Tools
MILL := $(or $(shell which mill), ./mill) # Use global mill if available, otherwise use local ./mill
MKDIR := mkdir -p
RM := rm -rf
MAKE ?= make
VCC ?= vcs
WAVE ?= gtkwave
# Phony Targets
.PHONY: all verilog help reformat checkformat clean run
# Generate Verilog
FIRTOOL_VERSION = 1.105.0
FIRTOOL_PATCH_DIR = $(shell pwd)/patch/firtool
verilog:
@echo "Generating Verilog files..."
$(MKDIR) $(VSRC_DIR)
@./patch/update-firtool.sh $(FIRTOOL_VERSION) $(FIRTOOL_PATCH_DIR)
CHISEL_FIRTOOL_PATH=$(FIRTOOL_PATCH_DIR)/firtool-$(FIRTOOL_VERSION)/bin \
$(MILL) -i $(PRJ).runMain Elaborate --target-dir $(VSRC_DIR) --throw-on-first-error
sed -i '/difftest\.sv/d' $(VSRC_DIR)/$(CPUTOP).sv
sed -i '/Stat\.v/d' $(VSRC_DIR)/$(CPUTOP).sv
# Show Help for Elaborate
help:
@echo "Displaying help for Elaborate..."
$(MILL) -i $(PRJ).runMain Elaborate --help
# Reformat Code
reformat:
@echo "Reformatting code..."
$(MILL) -i __.reformat
# Check Code Format
checkformat:
@echo "Checking code format..."
$(MILL) -i __.checkFormat
# Clean Build Artifacts
clean:
@echo "Cleaning build artifacts..."
$(RM) $(BUILD_DIR)
$(RM) $(wildcard $(VSRC_DIR)/*.sv $(VSRC_DIR)/*.v)
RTLSRC_CPU := $(wildcard $(CPU_DIR)/*.sv) $(wildcard $(CPU_DIR)/*.v)
.PHONY: $(RTLSRC_CPU)
-include ./soc/soc.mk
ifeq ($(CONFIG_DBG), y)
-include ./riscv_dbg/dbg.mk
endif
riscv_dbg/remote_bitbang/librbs_veri.so: INCLUDE_DIRS =./
riscv_dbg/remote_bitbang/librbs_veri.so:
$(MAKE) -C riscv_dbg/remote_bitbang all
mv riscv_dbg/remote_bitbang/librbs.so $@
riscv_dbg/remote_bitbang/librbs_vcs.so:
riscv_dbg/remote_bitbang/librbs_vcs.so:
$(MAKE) -C riscv_dbg/remote_bitbang all INCLUDE_DIRS="./ $(if $(VCS_HOME),$(VCS_HOME)/include,)"
mv riscv_dbg/remote_bitbang/librbs.so $@
ifeq ($(CONFIG_DBG), y)
ifeq ($(VCC), verilator)
BITBANG_SO := $(abspath riscv_dbg/remote_bitbang/librbs_veri.so)
else ifeq ($(VCC), vcs)
BITBANG_SO := $(abspath riscv_dbg/remote_bitbang/librbs_vcs.so)
endif
TEST_CASE = while_loop
TEST_NAME = loop
VF += -DRISCV_DEBUG
VCS_OUT = log/vcs_run.log
OPENOCD_OUT = log/openocd_run.log
OPENOCD_CFG = riscv_dbg/openocd_cfg/dm_compliance_test.cfg
endif
VTOP := top
COMPILE_OUT := $(BUILD_DIR)/compile.log
BIN := $(BUILD_DIR)/$(VTOP)
#./cl1/src/cc/verilator/difftest.cpp
SDF_FLAGS := -sdf Max:top.soc_top_u.Cl1Top_u:$(SDF_OUT_FILE) \
+delay_mode_path \
+sdfverbose \
+neg_tchk \
-negdelay \
-diag=sdf:verbose \
+warn=OPD:10,IWNF:10,SDFCOM_UHICD:10,SDFCOM_ANICD:10,SDFCOM_NICD:10,DRTZ:10,SDFCOM_UHICD:10,SDFCOM_NTCDTL:10
ifeq ($(VCC), verilator)
VF += $(addprefix +incdir+, $(RTLSRC_INCDIR)) \
--Wno-lint --Wno-UNOPTFLAT --Wno-BLKANDNBLK --Wno-COMBDLY --Wno-MODDUP \
-CFLAGS -I$(abspath ./cl1/src/cc/verilator/include) \
--timescale 1ns/1ps \
--autoflush \
--x-assign unique \
--trace --trace-fst \
--build -j 0 --exe --timing --binary\
--Mdir $(BUILD_DIR) \
--top-module $(VTOP) -o $(VTOP)
else ifeq ($(VCC), vcs)
VF += $(addprefix +incdir+, $(RTLSRC_INCDIR)) \
+vc -full64 -sverilog +v2k -timescale=1ns/1ps \
-LDFLAGS -Wl,--no-as-needed \
$(if $(and $(strip $(POSTSIM)), $(strip $(SDF_ON))), $(SDF_FLAGS) , +notimingcheck +nospecify) \
+lint=TFIPC-L \
-lca -kdb \
-CC "$(if $(VCS_HOME), -I$(VCS_HOME)//include,)" \
-debug_access -l $(COMPILE_OUT) \
-Mdir=$(BUILD_DIR) \
-top $(VTOP) -o $(BUILD_DIR)/$(VTOP)
else
$(error unsupport VCC)
endif
# -xprop=xprop.cfg
$(BIN): $(RTLSRC_CPU) $(RTLSRC_DBG) $(RTLSRC_SOC) $(BITBANG_SO)
$(VCC) $(RTLSRC_CPU) $(RTLSRC_DBG) $(BITBANG_SO) $(RTLSRC_SOC) $(VF)
bin: $(BIN)
REF ?= ./utils/riscv32-spike-so
TEST_CASE ?= dummy
TEST_NAME ?= dummy
ifeq ($(VCC), verilator)
WAVE_TYPE = fst
else ifeq ($(VCC), vcs)
WAVE_TYPE = fsdb
endif
#WAVE_TYPE ?= fst
POWER_RTL_F = +rtl_saif +design_name=$(TEST_NAME)
POWER_GATE_F = +gate_saif +design_name=$(TEST_NAME)
POWER_FLAGS = $(if $(PWR_ANALYSIS), \
$(if $(POSTSIM), $(POWER_GATE_F), $(POWER_RTL_F)),)
CURRENT_TIME := $(shell date +%s)
ifneq ($(DUMP_WAVE),)
RUN_ARGS += +$(WAVE_TYPE)
endif
RUN_ARGS += --diff
RUN_ARGS += +firmware=./test/$(TEST_CASE)/build/$(TEST_NAME).hex
RUN_ARGS += --image=./test/$(TEST_CASE)/build/$(TEST_NAME).bin
RUN_ARGS += --ref=$(REF)
# RUN_ARGS += +verilator+rand+reset+2 +verilator+seed+$(CURRENT_TIME)
RUN_ARGS += $(POWER_FLAGS)
# RUN_ARGS += +vcs+initreg+0
# Test Targets (run, gdb, latest)
run: $(BIN)
$(BIN) $(RUN_ARGS)
dbg_test: $(BIN)
@mkdir -p log
@echo "[INFO] Starting dbg_test simulation..."
@( \
echo "[CMD] $(BIN) $(RUN_ARGS) +verbose &> $(VCS_OUT) &"; \
VCS_PID=""; \
cleanup() { \
echo "[INFO] Cleaning up..."; \
[ -n "$$VCS_PID" ] && kill $$VCS_PID 2>/dev/null; \
exit 1; \
}; \
trap 'echo; cleanup' INT TERM; \
./$(BIN) $(RUN_ARGS) +verbose &> $(VCS_OUT) & \
VCS_PID=$$!; \
echo "[INFO] VCS PID: $$VCS_PID"; \
until grep -q "Listening on port" $(VCS_OUT); do sleep 1; done; \
echo "[INFO] Detected 'Listening on port', launching OpenOCD..."; \
./tools/openocd -f $(OPENOCD_CFG) |& tee $(OPENOCD_OUT); \
wait $$VCS_PID; \
)
@echo "[INFO] Simulation completed."
#TODO: add test submodule
test: bin
@for dir in $(CL2_TEST_DIR); do \
$(MAKE) -C $$dir run ARCH=riscv32-cl2 || exit 1; \
done
wave:
$(WAVE) $(WAVE_DIR)/$(VTOP).$(WAVE_TYPE)
verdi:
verdi -ssf $(WAVE_DIR)/$(VTOP).fsdb &
$(WAVE_DIR)/$(VTOP).saif : $(WAVE_DIR)/$(VTOP).fsdb
@echo "Generating SAIF file from FSDB..."
fsdb2saif $^ -s "/top/soc_top_u/Cl1Top_u" -o $@
saif: $(WAVE_DIR)/$(VTOP).saif
.PHONY: $(BIN) wave saif