-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathMakefile
More file actions
311 lines (265 loc) · 11.4 KB
/
Copy pathMakefile
File metadata and controls
311 lines (265 loc) · 11.4 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
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
ARCH ?= aarch64
LOG ?= info
STATS ?= off
PORT ?= 2333
MODE ?= release
BOARD ?= qemu-gicv3
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
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
# 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 += --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)
# Defconfig / menuconfig: see tools/kconfig/kconfig_cli.py
kconfig_python := tools/kconfig/.venv/bin/python
# Targets
.PHONY: all elf disa run gdb monitor clean tools rootfs vscode ci-run defconfig menuconfig savedefconfig ensure_config clean_check kconfig_venv link_board check-hv-mem-overlap
kconfig_venv:
@if [ ! -x $(kconfig_python) ]; then \
echo "$(COLOR_YELLOW)Creating tools/kconfig/.venv (kconfiglib)...$(COLOR_RESET)"; \
./tools/kconfig/bootstrap_venv.sh; \
fi
ensure_config:
@CONFIG_ARCH=; CONFIG_BOARD=; \
if [ -f .config ]; then \
CONFIG_ARCH=$$(grep '^# ARCH=' .config 2>/dev/null | head -1 | sed 's/^# ARCH=//'); \
[ -n "$$CONFIG_ARCH" ] || CONFIG_ARCH=$$(grep '^ARCH=' .config | head -1 | cut -d'=' -f2); \
CONFIG_BOARD=$$(grep '^# BOARD=' .config 2>/dev/null | head -1 | sed 's/^# BOARD=//'); \
[ -n "$$CONFIG_BOARD" ] || CONFIG_BOARD=$$(grep '^BOARD=' .config | head -1 | cut -d'=' -f2); \
fi; \
if [ ! -f .config ]; then \
echo "$(COLOR_YELLOW)No .config; running defconfig for $(ARCH)/$(BOARD)$(COLOR_RESET)"; \
$(MAKE) --no-print-directory defconfig; \
elif [ "$$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 and reloading defconfig...$(COLOR_RESET)"; \
./tools/clean.sh; \
$(MAKE) --no-print-directory defconfig; \
fi
clean_check: ensure_config
link_board:
@mkdir -p src/platform
@ln -sfn ../../platform/$(ARCH)/$(BOARD)/board.rs src/platform/__board.rs
defconfig: kconfig_venv
@$(kconfig_python) tools/kconfig/kconfig_cli.py defconfig
@$(MAKE) --no-print-directory link_board
menuconfig: kconfig_venv
@$(kconfig_python) tools/kconfig/kconfig_cli.py menuconfig
savedefconfig:
@./tools/kconfig/save_defconfig.sh "$(ARCH)" "$(BOARD)"
all: ensure_config gen_cargo_config vscode $(hvisor_bin) check-hv-mem-overlap
@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" "DEFCONFIG =" "$(COLOR_BOLD)platform/$(ARCH)/$(BOARD)/kconfig/defconfig$(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"
gen_cargo_config:
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .cargo/config.toml...$(COLOR_RESET)\n"
@chmod +x tools/kconfig/host_config.sh 2>/dev/null || true
./tools/kconfig/host_config.sh cargo
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .cargo/config.toml success!$(COLOR_RESET)\n"
check-hv-mem-overlap: $(hvisor_bin) platform/$(ARCH)/$(BOARD)/board.rs
@printf "$(COLOR_GREEN)$(COLOR_BOLD)checking hvisor memory vs root zone regions...$(COLOR_RESET)\n"
@python3 tools/check_hv_mem_overlap.py $(hvisor_elf) platform/$(ARCH)/$(BOARD)/board.rs && \
printf "$(COLOR_GREEN)$(COLOR_BOLD)check passed!$(COLOR_RESET)\n" || \
(printf "$(COLOR_RED)$(COLOR_BOLD)OVERLAP DETECTED! See details above.$(COLOR_RESET)\n" && \
false)
vscode:
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .vscode/settings.json...$(COLOR_RESET)\n"
@chmod +x tools/kconfig/host_config.sh 2>/dev/null || true
./tools/kconfig/host_config.sh vscode
@printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .vscode/settings.json success!$(COLOR_RESET)\n"
elf: ensure_config gen_cargo_config
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)
ci-run: all
@mkdir -p "$(CURDIR)/.qemu"
$(MAKE) run QEMU_ARGS+='$(subst -nographic,-display none,$(filter-out -s -S -serial mon:stdio,$(QEMU_ARGS))) -monitor none -chardev socket,id=char0,path=$(CURDIR)/.qemu/qemu.sock,server=on,wait=off -serial chardev:char0'
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
TFTP_DIR ?= ~/tftp
cp: $(hvisor_bin)
mkdir -p $(TFTP_DIR)
cp $(hvisor_bin) $(TFTP_DIR)/
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: all
cargo fmt --all
@echo "your code has been formatted"
clippy: ensure_config gen_cargo_config
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 ensure_config gen_cargo_config
cargo test $(build_args) -vv
stest: clean test-pre ensure_config 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 ensure_config 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 ensure_config 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