-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathMakefile
More file actions
281 lines (243 loc) · 9.66 KB
/
Makefile
File metadata and controls
281 lines (243 loc) · 9.66 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
ARCH ?= aarch64
LOG ?= info
STATS ?= off
PORT ?= 2333
MODE ?= release
BOARD ?= qemu-gicv3
FEATURES=
BID ?=
ptest ?=
ifeq ($(origin ptest),command line)
ifneq ($(strip $(ptest)),)
.DEFAULT_GOAL := ptest
endif
endif
# if user uses `make ID=aarch64/qemu-gicv2`, we parse it into ARCH and BOARD
ifeq ($(BID),)
ARCH := $(ARCH)
BOARD := $(BOARD)
else
ARCH := $(shell echo $(BID) | cut -d'/' -f1)
BOARD := $(shell echo $(BID) | cut -d'/' -f2)
endif
# if user add FEATURES in environment, we use it
# else we use the default FEATURES in platform/$(ARCH)/$(BOARD)/cargo/features
ifeq ($(FEATURES),)
FEATURES := $(shell ./tools/read_features.sh $(ARCH) $(BOARD) || echo ERROR)
ifeq ($(FEATURES),ERROR)
$(error ERROR: Read FEATURES failed. Please check if ARCH="$(ARCH)" and BOARD="$(BOARD)" are correct.)
endif
endif
ifeq ($(ARCH),aarch64)
RUSTC_TARGET := aarch64-unknown-none
GDB_ARCH := aarch64
else ifeq ($(ARCH),riscv64)
RUSTC_TARGET := riscv64gc-unknown-none-elf
GDB_ARCH := riscv:rv64
else ifeq ($(ARCH),loongarch64)
RUSTC_TARGET := loongarch64-unknown-none
GDB_ARCH := loongarch64
else ifeq ($(ARCH),x86_64)
RUSTC_TARGET := x86_64-unknown-none
GDB_ARCH := i386:x86-64
else
$(error ERROR: Unsupported ARCH value: $(ARCH))
endif
OBJCOPY ?= rust-objcopy --binary-architecture=$(ARCH)
export MODE
export LOG
export ARCH
export BOARD
export BID
export RUSTC_TARGET
export FEATURES
# Build paths
build_path := target/$(RUSTC_TARGET)/$(MODE)
hvisor_elf := $(build_path)/hvisor
hvisor_bin := $(build_path)/hvisor.bin
image_dir := platform/$(ARCH)/$(BOARD)/image
test_dir := ./platform/$(ARCH)/$(BOARD)/test
perftest_tdownload := $(test_dir)/perftest/tdownload_all.sh
systemtest_tdownload := $(test_dir)/systemtest/tdownload_all.sh
# Build arguments
build_args :=
build_args += --features "$(FEATURES)"
build_args += --target $(RUSTC_TARGET)
build_args += -Z build-std=core,alloc
build_args += -Z build-std-features=compiler-builtins-mem
ifeq ($(MODE), release)
build_args += --release
endif
# color code
COLOR_GREEN := $(shell tput setaf 2)
COLOR_RED := $(shell tput setaf 1)
COLOR_YELLOW := $(shell tput setaf 3)
COLOR_BLUE := $(shell tput setaf 4)
COLOR_BOLD := $(shell tput bold)
COLOR_RESET := $(shell tput sgr0)
# Targets
.PHONY: all elf disa run gdb monitor clean tools rootfs vscode
all: clean_check gen_cargo_config vscode $(hvisor_bin)
@printf "\n"
@printf "$(COLOR_GREEN)$(COLOR_BOLD)hvisor build summary:$(COLOR_RESET)\n"
@printf "%-10s %s\n" "ARCH =" "$(COLOR_BOLD)$(ARCH)$(COLOR_RESET)"
@printf "%-10s %s\n" "BOARD =" "$(COLOR_BOLD)$(BOARD)$(COLOR_RESET)"
@printf "%-10s %s\n" "BID =" "$(COLOR_BOLD)$(BID)$(COLOR_RESET)"
@printf "%-10s %s\n" "LOG =" "$(COLOR_BOLD)$(LOG)$(COLOR_RESET)"
@printf "%-10s %s\n" "FEATURES =" "$(COLOR_BOLD)$(FEATURES)$(COLOR_RESET)"
@printf "%-10s %s\n" "RUSTC_TARGET =" "$(COLOR_BOLD)$(RUSTC_TARGET)$(COLOR_RESET)"
@printf "%-10s %s\n" "BUILD_PATH =" "$(COLOR_BOLD)$(build_path)$(COLOR_RESET)"
@printf "%-10s %s\n" "HVISON_BIN_SIZE =" "$(COLOR_BOLD)$(shell du -h $(hvisor_bin) | cut -f1)$(COLOR_RESET)"
@start_addr=$$(rust-nm $(hvisor_elf) | grep skernel | awk '{print $$1}'); \
end_addr=$$(rust-nm $(hvisor_elf) | grep __hv_end | awk '{print $$1}'); \
size=$$(echo "obase=16; ibase=16; $$(echo $$end_addr | tr 'a-z' 'A-Z') - $$(echo $$start_addr | tr 'a-z' 'A-Z')" | bc | tr 'A-Z' 'a-z'); \
printf "%-10s %s\n" "START_ADDR =" "$(COLOR_BOLD)0x$$start_addr$(COLOR_RESET)"; \
printf "%-10s %s\n" "MEM_SIZE =" "$(COLOR_BOLD)0x$$size$(COLOR_RESET)"; \
printf "%-10s %s\n" "END_ADDR =" "$(COLOR_BOLD)0x$$end_addr$(COLOR_RESET)"
@printf "%-10s %s\n" "BUILD TIME =" "$(COLOR_BOLD)$(shell date)$(COLOR_RESET)"
@printf "\n"
@printf "$(COLOR_GREEN)$(COLOR_BOLD)hvisor build success!$(COLOR_RESET)\n"
clean_check:
# if .config not exist, then everything is fine
# else we read .config and parse ARCH and BOARD, if they are different, we clean the build
@if [ -f ".config" ]; then \
CONFIG_ARCH=$$(cat .config | grep "ARCH" | cut -d'=' -f2); \
CONFIG_BOARD=$$(cat .config | grep "BOARD" | cut -d'=' -f2); \
if [ "$$CONFIG_ARCH" != "$(ARCH)" ] || [ "$$CONFIG_BOARD" != "$(BOARD)" ]; then \
echo "$(COLOR_YELLOW)$(COLOR_BOLD)ARCH or BOARD changed(OLD: $$CONFIG_ARCH/$$CONFIG_BOARD, NEW: $(ARCH)/$(BOARD)), cleaning...$(COLOR_RESET)"; \
./tools/clean.sh; \
fi; \
fi
gen_cargo_config:
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .cargo/config.toml...$(COLOR_RESET)\n"
./tools/gen_cargo_config.sh
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .cargo/config.toml success!$(COLOR_RESET)\n"
vscode:
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .vscode/settings.json...$(COLOR_RESET)\n"
./tools/gen_vscode_settings.sh
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .vscode/settings.json success!$(COLOR_RESET)\n"
elf:
cargo build $(build_args)
disa:
readelf -a $(hvisor_elf) > hvisor-elf.txt
rust-objdump --disassemble --source --line-numbers $(hvisor_elf) > hvisor.asm
run: all
$(QEMU) $(QEMU_ARGS)
gdb: all
$(QEMU) $(QEMU_ARGS) -s -S
show-features:
rustc --print=target-features --target=$(RUSTC_TARGET)
monitor:
gdb-multiarch \
-ex 'file $(hvisor_elf)' \
-ex 'set arch $(GDB_ARCH)' \
-ex 'target remote:1234'
jlink-server:
JLinkGDBServer -select USB -if JTAG -device Cortex-A53 -port 1234
cp:
cp $(hvisor_bin) ~/tftp
test-pre: download-test-img
chmod +x platform/$(ARCH)/$(BOARD)/test/runner.sh
@echo "added execute permission to test runner.sh for board $(BOARD)"
fmt-test: all
cargo fmt --all -- --check
@echo "cargo fmt check passed!"
fmt: all
cargo fmt --all
@echo "your code has been formatted"
clippy:
cargo clippy $(build_args)
flash-img:
# run this will erase all environment for uboot, be careful
# the flash.img in repo will contains the correct bootcmd
qemu-img create -f raw flash.img 64M
download-test-img:
# first check whether the file exists
@if [ ! -f "flash.img" ]; then echo "\nflash.img not found, downloading...\n" && \
wget https://github.com/enkerewpo/hvisor-uboot-env-img/releases/download/v20241227/flash.img.partial && \
./tools/extract.sh ; \
else echo "\nflash.img found\n"; \
fi
test: clean test-pre gen_cargo_config
cargo test $(build_args) -vv
stest: clean test-pre gen_cargo_config
./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh
./platform/$(ARCH)/$(BOARD)/test/systemtest/tdownload_all.sh
./platform/$(ARCH)/$(BOARD)/test/systemtest/trootfs_deploy.sh
./platform/$(ARCH)/$(BOARD)/test/systemtest/tstart.sh
# Performance benchmark: data collection only, does not affect pass/fail.
# Calls systemtest scripts for DTS, then perftest/tdownload_all.sh when present
# (fallback to systemtest/tdownload_all.sh), and perftest/trootfs_deploy.sh.
perf: clean test-pre gen_cargo_config
./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh
@if [ -x "$(perftest_tdownload)" ]; then \
$(perftest_tdownload); \
else \
$(systemtest_tdownload); \
fi
./platform/$(ARCH)/$(BOARD)/test/perftest/trootfs_deploy.sh
./platform/$(ARCH)/$(BOARD)/test/perftest/tstart.sh
# Prepare perf image only: reuse existing rootfs img when present, download
# missing assets, deploy benchmark scripts/tools into image, and print path.
perf-prepare-img: clean test-pre gen_cargo_config
./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh
@if [ -x "$(perftest_tdownload)" ]; then \
$(perftest_tdownload); \
else \
$(systemtest_tdownload); \
fi
@ROOTFS_EXT4="platform/$(ARCH)/$(BOARD)/image/virtdisk/rootfs1.ext4"; \
ROOTFS_ZIP="rootfs1.zip"; \
if [ ! -f "$$ROOTFS_EXT4" ]; then \
echo "WARN: $$ROOTFS_EXT4 not found after download, trying unzip $$ROOTFS_ZIP"; \
if [ -f "$$ROOTFS_ZIP" ]; then \
unzip -qo "$$ROOTFS_ZIP" -d "platform/$(ARCH)/$(BOARD)/image/virtdisk"; \
else \
echo "ERROR: missing $$ROOTFS_EXT4 and $$ROOTFS_ZIP"; \
exit 1; \
fi; \
fi; \
if [ ! -f "$$ROOTFS_EXT4" ]; then \
echo "ERROR: still missing $$ROOTFS_EXT4 after unzip"; \
exit 1; \
fi
./platform/$(ARCH)/$(BOARD)/test/perftest/trootfs_deploy.sh
@echo "READY_IMG=$(PWD)/platform/$(ARCH)/$(BOARD)/image/virtdisk/rootfs1.ext4"
# Run a single perf benchmark (assumes perf image is already prepared).
# Before test start, rebuild hvisor-tool and deploy artifacts into rootfs.
# Usage: make ptest=irq | make ptest=net | make ptest=mem | make ptest=blk
ptest: ptest-check
./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh
./platform/$(ARCH)/$(BOARD)/test/perftest/trootfs_deploy.sh
@if [ "$(ptest)" = "blk" ]; then \
expect -f ./platform/$(ARCH)/$(BOARD)/test/perftest/tstart_blk.sh; \
else \
PTEST=$(ptest) expect -f ./platform/$(ARCH)/$(BOARD)/test/perftest/tstart_one.sh; \
fi
# Run a single perf benchmark without image prepare step.
ptest-only: ptest-check
@if [ "$(ptest)" = "blk" ]; then \
expect -f ./platform/$(ARCH)/$(BOARD)/test/perftest/tstart_blk.sh; \
else \
PTEST=$(ptest) expect -f ./platform/$(ARCH)/$(BOARD)/test/perftest/tstart_one.sh; \
fi
ptest-check:
@if [ -z "$(ptest)" ]; then \
echo "ERROR: ptest is empty. Use: make ptest=irq|net|mem|blk"; \
exit 1; \
fi
@if [ "$(BOARD)" != "qemu-plic" ] && [ "$(BOARD)" != "qemu-gicv3" ]; then \
echo "ERROR: ptest only supports BOARD=qemu-plic|qemu-gicv3 (current: $(BOARD))"; \
exit 1; \
fi
@if [ "$(ptest)" != "irq" ] && [ "$(ptest)" != "net" ] && [ "$(ptest)" != "mem" ] && [ "$(ptest)" != "blk" ]; then \
echo "ERROR: unsupported ptest='$(ptest)'. Use irq|net|mem|blk"; \
exit 1; \
fi
dtb:
@echo "building device tree at platform/$(ARCH)/$(BOARD)/image/dts"
@if [ ! -d "platform/$(ARCH)/$(BOARD)/image/dts" ]; then echo "ERROR: dts directory not found"; exit 1; fi
make -C platform/$(ARCH)/$(BOARD)/image/dts
clean:
./tools/clean.sh
include platform/$(ARCH)/$(BOARD)/platform.mk