forked from IObundle/iob-soc-sut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (181 loc) · 10.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
CORE := iob_soc_sut
BOARD ?= AES-KU040-DB-G
# Disable Linter while rules are not finished
DISABLE_LINT:=1
ifeq ($(TESTER),1)
TOP_MODULE_NAME :=iob_soc_tester
endif
LIB_DIR:=submodules/OPENCRYPTOLINUX/submodules/IOBSOC/submodules/LIB
include $(LIB_DIR)/setup.mk
INIT_MEM ?= 1
RUN_LINUX ?= 0
ifeq ($(INIT_MEM),1)
SETUP_ARGS += INIT_MEM
endif
ifeq ($(TESTER_ONLY),1)
SETUP_ARGS += TESTER_ONLY
endif
ifeq ($(RUN_LINUX),1)
SETUP_ARGS += RUN_LINUX
endif
ifeq ($(NO_ILA),1)
SETUP_ARGS += NO_ILA
endif
setup:
make build-setup SETUP_ARGS="$(SETUP_ARGS)"
sim-run: build_dir_name
make clean setup && make -C $(BUILD_DIR)/ sim-run
fpga-run: build_dir_name
nix-shell --run "make clean setup INIT_MEM=0"
make fpga-connect
# allow `test-linux-fpga-connect` and `fpga-connect` to symlink different
# minicom scripts
fpga-connect-internal: build_dir_name
nix-shell --run 'make -C $(BUILD_DIR)/ fpga-fw-build BOARD=$(BOARD) RUN_LINUX=$(RUN_LINUX)'
make -C $(BUILD_DIR)/ fpga-run BOARD=$(BOARD) RUN_LINUX=$(RUN_LINUX)
fpga-connect: build_dir_name
-ln -fs minicom_tester.txt $(BUILD_DIR)/hardware/fpga/minicom_linux_script.txt
make fpga-connect-internal BOARD=$(BOARD) RUN_LINUX=$(RUN_LINUX)
test-linux-fpga-connect: build_dir_name
-rm $(BUILD_DIR)/hardware/fpga/test.log
-ln -fs minicom_tester_test.txt $(BUILD_DIR)/hardware/fpga/minicom_linux_script.txt
make fpga-connect-internal TESTER=1 RUN_LINUX=1
.PHONY: sim-run fpga-run fpga-connect test-linux-fpga-connect
test-all: build_dir_name
#make sim-run SIMULATOR=icarus
make sim-run SIMULATOR=verilator
make fpga-run BOARD=CYCLONEV-GT-DK
make fpga-run BOARD=AES-KU040-DB-G
make clean setup && make -C $(BUILD_DIR)/ doc-test
.PHONY: test-all
build-sut-netlist: build_dir_name
make clean && make setup
# Rename constraint files
#FPGA_DIR=`ls -d $(BUILD_DIR)/hardware/fpga/quartus/CYCLONEV-GT-DK` &&\
#mv $$FPGA_DIR/iob_soc_sut_fpga_wrapper_dev.sdc $$FPGA_DIR/iob_soc_sut_dev.sdc
#FPGA_DIR=`ls -d $(BUILD_DIR)/hardware/fpga/vivado/AES-KU040-DB-G` &&\
#mv $$FPGA_DIR/iob_soc_sut_fpga_wrapper_dev.sdc $$FPGA_DIR/iob_soc_sut_dev.sdc
# Build netlist
make -C $(BUILD_DIR)/ fpga-build BOARD=$(BOARD) IS_FPGA=0
tester-sut-netlist: build-sut-netlist
#Build tester without sut sources, but with netlist instead
TESTER_VER=`cat submodules/TESTER/iob_soc_tester_setup.py | grep version= | cut -d"'" -f2` &&\
rm -fr ../iob_soc_tester_V* && make setup TESTER_ONLY=1 BUILD_DIR="../iob_soc_tester_$$TESTER_VER" &&\
cp ../iob_soc_sut_V*/hardware/fpga/iob_soc_sut_fpga_wrapper_netlist.v ../iob_soc_tester_$$TESTER_VER/hardware/fpga/iob_soc_sut.v &&\
cp ../iob_soc_sut_V*/hardware/fpga/iob_soc_sut_firmware.* ../iob_soc_tester_$$TESTER_VER/hardware/fpga/ &&\
if [ -f ../iob_soc_sut_V*/hardware/fpga/iob_soc_sut_stub.v ]; then cp ../iob_soc_sut_V*/hardware/fpga/iob_soc_sut_stub.v ../iob_soc_tester_$$TESTER_VER/hardware/src/; fi &&\
echo -e "\nIP+=iob_soc_sut.v" >> ../iob_soc_tester_$$TESTER_VER/hardware/fpga/fpga_build.mk &&\
cp software/firmware/iob_soc_tester_firmware.c ../iob_soc_tester_$$TESTER_VER/software/firmware
# Copy and modify iob_soc_sut_params.vh (needed for stub) and modify *_stub.v to insert the SUT parameters
TESTER_VER=`cat submodules/TESTER/iob_soc_tester_setup.py | grep version= | cut -d"'" -f2` &&\
if [ -f ../iob_soc_sut_V*/hardware/fpga/iob_soc_sut_stub.v ]; then\
cp ../iob_soc_sut_V0.70/hardware/src/iob_soc_sut_params.vh ../iob_soc_tester_$$TESTER_VER/hardware/src/;\
sed -i -E 's/=[^,]*(,?)$$/=0\1/g' ../iob_soc_tester_$$TESTER_VER/hardware/src/iob_soc_sut_params.vh;\
sed -i 's/_sut(/_sut#(\n`include "iob_soc_sut_params.vh"\n)(/g' ../iob_soc_tester_$$TESTER_VER/hardware/src/iob_soc_sut_stub.v;\
fi
# Run Tester on fpga
TESTER_VER=`cat submodules/TESTER/iob_soc_tester_setup.py | grep version= | cut -d"'" -f2` &&\
make -C ../iob_soc_tester_V*/ fpga-run BOARD=$(BOARD) | tee ../iob_soc_tester_$$TESTER_VER/test.log && grep "Verification successful!" ../iob_soc_tester_$$TESTER_VER/test.log > /dev/null
.PHONY: build-sut-netlist test-sut-netlist
# Target to create vcd file based on ila_data.bin generated by the ILA Tester peripheral
ila-vcd: build_dir_name
# Copy simulation ila data from remote machine
make -C $(BUILD_DIR)/hardware/simulation copy_remote_simulation_ila_data
# Create VCD file from simulation ila data
if [ -f $(BUILD_DIR)/hardware/simulation/ila_data.bin ]; then \
./$(BUILD_DIR)/./scripts/ilaDataToVCD.py ILA0 $(BUILD_DIR)/hardware/simulation/ila_data.bin ila_sim.vcd; fi
# Copy fpga ila data from remote machine
make -C $(BUILD_DIR)/hardware/fpga copy_remote_fpga_ila_data BOARD=$(BOARD)
# Create VCD file from fpga ila data
if [ -f $(BUILD_DIR)/hardware/fpga/ila_data.bin ]; then \
./$(BUILD_DIR)/./scripts/ilaDataToVCD.py ILA0 $(BUILD_DIR)/hardware/fpga/ila_data.bin ila_fpga.vcd; fi
#gtkwave ./ila_sim.vcd
.PHONY: ila-vcd
### Linux targets
LINUX_OS_DIR ?= submodules/OPENCRYPTOLINUX/submodules/OS
TESTER_DIR ?= submodules/TESTER
REL_OS2TESTER :=`realpath $(TESTER_DIR) --relative-to=$(LINUX_OS_DIR)`
REL_OS2SUT :=`realpath $(CURDIR) --relative-to=$(LINUX_OS_DIR)`
build-linux-dts:
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-dts MACROS_FILE=$(REL_OS2TESTER)/hardware/simulation/linux_build_macros.txt OS_BUILD_DIR=$(REL_OS2TESTER)/hardware/simulation OS_SOFTWARE_DIR=$(REL_OS2TESTER)/software'
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-dts MACROS_FILE=$(REL_OS2TESTER)/hardware/fpga/vivado/AES-KU040-DB-G/linux_build_macros.txt OS_BUILD_DIR=$(REL_OS2TESTER)/hardware/fpga/vivado/AES-KU040-DB-G OS_SOFTWARE_DIR=$(REL_OS2TESTER)/software'
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-dts MACROS_FILE=$(REL_OS2TESTER)/hardware/fpga/quartus/CYCLONEV-GT-DK/linux_build_macros.txt OS_BUILD_DIR=$(REL_OS2TESTER)/hardware/fpga/quartus/CYCLONEV-GT-DK OS_SOFTWARE_DIR=$(REL_OS2TESTER)/software'
build-linux-opensbi:
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-opensbi MACROS_FILE=$(REL_OS2TESTER)/hardware/simulation/linux_build_macros.txt OS_BUILD_DIR=$(REL_OS2TESTER)/hardware/simulation'
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-opensbi MACROS_FILE=$(REL_OS2TESTER)/hardware/fpga/vivado/AES-KU040-DB-G/linux_build_macros.txt OS_BUILD_DIR=$(REL_OS2TESTER)/hardware/fpga/vivado/AES-KU040-DB-G'
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-opensbi MACROS_FILE=$(REL_OS2TESTER)/hardware/fpga/quartus/CYCLONEV-GT-DK/linux_build_macros.txt OS_BUILD_DIR=$(REL_OS2TESTER)/hardware/fpga/quartus/CYCLONEV-GT-DK'
MODULE_NAMES = iob_timer
MODULE_NAMES += iob_soc_sut
MODULE_NAMES += iob_gpio
MODULE_NAMES += iob_pfsm
MODULE_NAMES += iob_ila
MODULE_NAMES += iob_dma
MODULE_NAMES += iob_axistream_in
MODULE_NAMES += iob_axistream_out
MODULE_NAMES += iob_spi_master
build-linux-drivers:
@$(foreach module,$(MODULE_NAMES), \
printf "\n\n\nMaking $(module)\n\n\n"; \
$(eval MODULE_LINUX_DIR=$(shell realpath $(shell find . -type f -name '$(module).py' -printf '%h' -quit))/software/linux) \
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-linux-drivers \
MODULE_DRIVER_DIR=$(MODULE_LINUX_DIR)/drivers \
OS_SUBMODULES_DIR=$(REL_OS2SUT)/.. \
CALLING_DIR=`realpath $(CURDIR)` \
MODULE_NAME=$(module) \
ROOTFS_OVERLAY_DIR=`realpath $(COMBINED_BUILDROOT_DIR)`/buildroot/board/IObundle/iob-soc/rootfs-overlay/ \
PYTHON_DIR=`realpath $(LIB_DIR)`/scripts'; \
)
clean-linux-drivers:
@$(foreach module,$(MODULE_NAMES), \
$(eval MODULE_LINUX_DIR=$(shell realpath $(shell find . -type f -name '$(module).py' -printf '%h' -quit))/software/linux) \
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) clean-linux-drivers \
MODULE_DRIVER_DIR=$(MODULE_LINUX_DIR)/drivers \
OS_SUBMODULES_DIR=$(REL_OS2SUT)/.. \
CALLING_DIR=`realpath $(CURDIR)` \
MODULE_NAME=$(module) \
ROOTFS_OVERLAY_DIR=`realpath $(COMBINED_BUILDROOT_DIR)`/buildroot/board/IObundle/iob-soc/rootfs-overlay/ \
PYTHON_DIR=`realpath $(LIB_DIR)`/scripts'; \
)
COMBINED_BUILDROOT_DIR=..
combine-buildroot:
rm -rf $(COMBINED_BUILDROOT_DIR)/buildroot
cp -r $(LINUX_OS_DIR)/software/buildroot $(COMBINED_BUILDROOT_DIR)/
cp -r $(TESTER_DIR)/software/buildroot $(COMBINED_BUILDROOT_DIR)/
build-linux-buildroot: combine-buildroot build-linux-drivers build-linux-tester-verification
make -C $(LINUX_OS_DIR) build-buildroot OS_SUBMODULES_DIR=$(REL_OS2SUT)/.. OS_SOFTWARE_DIR=../`realpath $(COMBINED_BUILDROOT_DIR) --relative-to=..` OS_BUILD_DIR=$(REL_OS2TESTER)/software/src
build-driver-headers:
@$(foreach module,$(MODULE_NAMES), \
./$(LINUX_OS_DIR)/scripts/drivers.py $(module) -o `realpath $(COMBINED_BUILDROOT_DIR)`/buildroot/board/IObundle/iob-soc/rootfs-overlay/root/tester_verification/; \
)
build-linux-kernel:
-rm ../linux-5.15.98/arch/riscv/boot/Image
nix-shell $(LINUX_OS_DIR)/default.nix --run 'make -C $(LINUX_OS_DIR) build-linux-kernel OS_SUBMODULES_DIR=$(REL_OS2SUT)/.. OS_SOFTWARE_DIR=../`realpath $(TESTER_DIR) --relative-to=..`/software OS_BUILD_DIR=$(REL_OS2TESTER)/software/src'
build-linux-files:
make build-linux-dts
make build-linux-opensbi
make build-linux-kernel
make build-linux-buildroot
.PHONY: build-linux-dts build-linux-opensbi build-linux-buildroot build-linux-kernel build-linux-files
INCLUDE = -I.
SRC = *.c
FLAGS = -Wall -O2
FLAGS += -Werror
#FLAGS += -static
FLAGS += -march=rv32imac
FLAGS += -mabi=ilp32
BIN = run_verification
CC = riscv64-unknown-linux-gnu-gcc
build-linux-tester-verification: build-driver-headers
nix-shell $(LINUX_OS_DIR)/default.nix --run 'cd $(COMBINED_BUILDROOT_DIR)/buildroot/board/IObundle/iob-soc/rootfs-overlay/root/tester_verification/ && \
$(CC) $(FLAGS) $(INCLUDE) -o $(BIN) $(SRC)'
.PHONY: build-linux-tester-verification
#DEBUG
debug-tester-verfication:
-rm ../iob_soc_sut_V0.70/hardware/fpga/test.log
make build-linux-tester-verification
make build-linux-buildroot
cp submodules/TESTER/software/src/rootfs.cpio.gz ../iob_soc_sut_V0.70/software/src/rootfs.cpio.gz
-rm ../iob_soc_sut_V0.70/hardware/fpga/rootfs.cpio.gz
cp submodules/TESTER/hardware/fpga/minicom_tester.txt ../iob_soc_sut_V0.70/hardware/fpga/minicom_tester.txt
nix-shell --run 'source ~/iobundleServerVars.sh; make fpga-connect TESTER=1 RUN_LINUX=1 GRAB_TIMEOUT=200'
.PHONY: debug-tester-verfication