-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (165 loc) · 6.47 KB
/
Makefile
File metadata and controls
197 lines (165 loc) · 6.47 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
ARCH ?= aarch64
LOG ?= info
STATS ?= off
PORT ?= 2333
MODE ?= debug
BOARD ?= qemu-gicv3
FEATURES=
BID ?=
# 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
# 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
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