-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
304 lines (273 loc) · 12 KB
/
Makefile
File metadata and controls
304 lines (273 loc) · 12 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
# Copyright (c) 2018-2023 Andre Richter <andre.o.richter@gmail.com>
# Copyright (c) 2023-2024 Lawrence Hunter <lawrence.hunter@outlook.com>
# ---------------------------------------------------------------------------- #
# Optional, user-provided configuration values #
# ---------------------------------------------------------------------------- #
BSP ?= qemu
TOOLCHAIN ?= riscv64-unknown-elf-
DOCKER ?= y
DEBUG ?= n
CLEAR ?= y
# ---------------------------------------------------------------------------- #
# BSP-specific configuration values #
# ---------------------------------------------------------------------------- #
ifeq ($(BSP),qemu_vector)
LOADER_BIN = sentinel_boot
QEMU_BINARY = qemu-system-riscv64
QEMU_MACHINE_TYPE = virt
QEMU_RELEASE_ARGS = -smp 4 -m 256M
OBJDUMP_BINARY = $(TOOLCHAIN)objdump
NM_BINARY = $(TOOLCHAIN)nm
READELF_BINARY = $(TOOLCHAIN)readelf
LD_PATH = riscv64/src/cpu/bootloader-qemu.ld
endif
ifeq ($(BSP),qemu)
LOADER_BIN = sentinel_boot
QEMU_BINARY = qemu-system-riscv64
QEMU_MACHINE_TYPE = virt
QEMU_RELEASE_ARGS = -smp 4 -m 256M
OBJDUMP_BINARY = $(TOOLCHAIN)objdump
NM_BINARY = $(TOOLCHAIN)nm
READELF_BINARY = $(TOOLCHAIN)readelf
LD_PATH = riscv64/src/cpu/bootloader-qemu.ld
endif
ifeq ($(BSP),visionfive)
LOADER_BIN = sentinel_boot
QEMU_BINARY = qemu-system-riscv64
QEMU_MACHINE_TYPE = virt
QEMU_RELEASE_ARGS = -smp 4 -m 128M
OBJDUMP_BINARY = $(TOOLCHAIN)objdump
NM_BINARY = $(TOOLCHAIN)nm
READELF_BINARY = $(TOOLCHAIN)readelf
LD_PATH = riscv64/src/cpu/bootloader-u-boot.ld
endif
ifeq ($(BSP),unmatched)
LOADER_BIN = sentinel_boot
QEMU_BINARY = qemu-system-riscv64
QEMU_MACHINE_TYPE = sifive_u
QEMU_RELEASE_ARGS = -smp 4 -m 128M
OBJDUMP_BINARY = $(TOOLCHAIN)objdump
NM_BINARY = $(TOOLCHAIN)nm
READELF_BINARY = $(TOOLCHAIN)readelf
LD_PATH = riscv64/src/cpu/bootloader-u-boot.ld
endif
# ---------------------------------------------------------------------------- #
# Targets and Prerequisites #
# ---------------------------------------------------------------------------- #
LOADER_MANIFEST = Cargo.toml
LAST_BUILD_CONFIG = target/$(BSP).build_config
LOADER_ELF = target/riscv64gc-unknown-none-elf/release/sentinel_boot
# This parses cargo's dep-info file.
# https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files
LOADER_ELF_DEPS = $(filter-out %: ,$(file < $(LOADER_ELF).d)) \
$(LOADER_MANIFEST) $(LAST_BUILD_CONFIG)
# ---------------------------------------------------------------------------- #
# Command building blocks #
# ---------------------------------------------------------------------------- #
ifeq ($(DEBUG),y)
FEATURES = --features $(BSP),debug
else
FEATURES = --features $(BSP)
endif
COMPILER_ARGS = $(FEATURES) --release
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS) --features $(BSP) \
--document-private-items --workspace
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS) -- -A clippy::modulo_one
OBJCOPY_CMD = rust-objcopy -O binary
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_MINIMAL_CMD = docker build --tag rust-minimal --file Dockerfile \
--target rust-minimal . && \
docker run -v $(shell pwd):$(shell pwd) \
-w $(shell pwd) rust-minimal:latest
DOCKER_FULL_CMD = docker build --tag rust-full --file Dockerfile \
--target rust-full . && \
docker run -v $(shell pwd):$(shell pwd) \
-w $(shell pwd) rust-full:latest
QEMU_CPU_FLAGS = -cpu rv64,v=true,vlen=1024,rvv_ma_all_1s=true,\
rvv_ta_all_1s=true,x-zvbb=true,x-zvbc=true,x-zvknhb=true
QEMU_ARGS = $(QEMU_CPU_FLAGS) $(QEMU_RELEASE_ARGS) -nographic \
-display none -serial mon:stdio \
-bios sentinel_boot -s \
-monitor unix:qemu-monitor-socket,server,nowait
# ---------------------------------------------------------------------------- #
# Targets #
# ---------------------------------------------------------------------------- #
.PHONY: all doc qemu qemu_halted clippy clean readelf objdump nm test \
call_stack geiger hyperfine
all: $(LOADER_BIN)
# ---------------------------------------------------------------------------- #
# Save the configuration as a file, so make understands if it changed #
# ---------------------------------------------------------------------------- #
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
# ---------------------------------------------------------------------------- #
# Compile the SentinelBoot ELF #
# ---------------------------------------------------------------------------- #
$(LOADER_ELF): $(LOADER_ELF_DEPS)
ifeq ($(CLEAR),y)
clear && tmux clear-history || true
endif
cp $(LD_PATH) ./bootloader.ld
ifeq ($(DOCKER),y)
$(call color_header, "Compiling SentinelBoot ELF - $(BSP)")
$(DOCKER_MINIMAL_CMD) cargo vendor
$(DOCKER_MINIMAL_CMD) python3 gen_helper.py
$(DOCKER_MINIMAL_CMD) $(RUSTC_CMD)
else
$(call color_header, "Compiling SentinelBoot ELF - $(BSP)")
cargo vendor
python3 gen_helper.py
$(RUSTC_CMD)
endif
rm ./bootloader.ld
# ---------------------------------------------------------------------------- #
# Generate the stripped SentinelBoot binary #
# ---------------------------------------------------------------------------- #
$(LOADER_BIN): $(LOADER_ELF)
ifeq ($(DOCKER),y)
$(call color_header, "Generating stripped binary")
$(DOCKER_MINIMAL_CMD) $(OBJCOPY_CMD) $(LOADER_ELF) $(LOADER_BIN)
$(call color_progress_prefix, "Name")
$(DOCKER_MINIMAL_CMD) echo $(LOADER_BIN)
$(call color_progress_prefix, "Size")
$(call disk_usage_KiB, $(LOADER_BIN))
else
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(LOADER_ELF) $(LOADER_BIN)
$(call color_progress_prefix, "Name")
@echo $(LOADER_BIN)
$(call color_progress_prefix, "Size")
$(call disk_usage_KiB, $(LOADER_BIN))
endif
# ---------------------------------------------------------------------------- #
# Generate the documentation #
# ---------------------------------------------------------------------------- #
doc:
ifeq ($(DOCKER),y)
$(call color_header, "Generating docs")
$(DOCKER_MINIMAL_CMD) $(DOC_CMD) --open
else
$(call color_header, "Generating docs")
$(DOC_CMD)
endif
# ---------------------------------------------------------------------------- #
# Run SentinelBoot in QEMU #
# ---------------------------------------------------------------------------- #
# -- This is no longer used due to the need for tftp (likely to be removed) -- #
qemu: $(LOADER_BIN)
ifeq ($(DOCKER),y)
$(call color_header, "Launching QEMU")
$(DOCKER_MINIMAL_CMD) $(EXEC_QEMU) $(QEMU_ARGS)
else
$(call color_header, "Launching QEMU")
$(EXEC_QEMU) $(QEMU_ARGS)
endif
qemu_monitor: $(LOADER_BIN)
$(call color_header, "Launching QEMU")
$(EXEC_QEMU) $(QEMU_ARGS)
qemu_halted: $(LOADER_BIN)
$(call color_header, "Launching QEMU")
$(EXEC_QEMU) $(QEMU_ARGS) -S
# ---------------------------------------------------------------------------- #
# Run clippy #
# ---------------------------------------------------------------------------- #
clippy:
ifeq ($(DOCKER),y)
$(DOCKER_MINIMAL_CMD) $(CLIPPY_CMD)
else
$(CLIPPY_CMD)
endif
# ---------------------------------------------------------------------------- #
# Clean #
# ---------------------------------------------------------------------------- #
clean:
ifeq ($(DOCKER),y)
$(DOCKER_MINIMAL_CMD) rm -rf target $(LOADER_BIN) bootloader.ld
else
rm -rf target $(LOADER_BIN) bootloader.ld
endif
# ---------------------------------------------------------------------------- #
# Run readelf #
# ---------------------------------------------------------------------------- #
readelf: $(LOADER_ELF)
$(call color_header, "Launching readelf")
$(READELF_BINARY) --headers $(LOADER_ELF)
# ---------------------------------------------------------------------------- #
# Run objdump #
# ---------------------------------------------------------------------------- #
objdump: $(LOADER_ELF)
$(call color_header, "Launching objdump")
@$(DOCKER_TOOLS) $(OBJDUMP_BINARY) --disassemble --demangle \
--section .text \
--section .rodata \
$(LOADER_ELF) | rustfilt
# ---------------------------------------------------------------------------- #
# Run nm #
# ---------------------------------------------------------------------------- #
nm: $(LOADER_ELF)
$(call color_header, "Launching nm")
$(NM_BINARY) --demangle --print-size $(LOADER_ELF) | sort | rustfilt
# ---------------------------------------------------------------------------- #
# Run tests #
# ---------------------------------------------------------------------------- #
# -- This is no longer used due to the need for tftp (likely to be removed) -- #
test: $(LOADER_BIN)
timeout 5m tftp/qemu_test.sh
# ---------------------------------------------------------------------------- #
# Generate call stack graph #
# ---------------------------------------------------------------------------- #
call_stack:
ifeq ($(DOCKER),y)
$(DOCKER_FULL_CMD) cargo +nightly call-stack --bin sentinel_boot \
--features $(BSP) --target riscv64gc-unknown-none-elf > cg.dot ; \
dot -Tsvg cg.dot > cg.svg && rm cg.dot
else
cargo +nightly call-stack --bin sentinel_boot --features $(BSP) --target \
riscv64gc-unknown-none-elf > cg.dot ; \
dot -Tsvg cg.dot > cg.svg && rm cg.dot
endif
# ---------------------------------------------------------------------------- #
# Execute cargo geiger #
# ---------------------------------------------------------------------------- #
geiger:
echo "# Safety Report" > .github/workflows/geiger.md
ifeq ($(DOCKER),y)
$(DOCKER_FULL_CMD) cargo geiger \
--target riscv64gc-unknown-none-elf \
--features $(BSP) --output-format GitHubMarkdown \
--update-readme --readme-path .github/workflows/geiger.md
else
cargo geiger --target riscv64gc-unknown-none-elf \
--features $(BSP) --output-format GitHubMarkdown --update-readme \
--readme-path .github/workflows/geiger.md
endif
cat .github/workflows/geiger.md
# ---------------------------------------------------------------------------- #
# Execute hyperfine #
# ---------------------------------------------------------------------------- #
# -- This is no longer used due to the need for tftp (likely to be removed) -- #
hyperfine:
ifeq ($(DOCKER),y)
$(DOCKER_FULL_CMD) touch test.md
$(DOCKER_FULL_CMD) hyperfine --warmup 1 --show-output \
--export-markdown test.md ./tftp/qemu_test.sh
$(DOCKER_FULL_CMD) cat test.md
else
touch test.md
hyperfine --warmup 1 --show-output --export-markdown test.md \
./tftp/qemu_test.sh
cat test.md
endif
# ---------------------------------------------------------------------------- #
# Execute cargo expand #
# ---------------------------------------------------------------------------- #
expand:
ifeq ($(DOCKER),y)
$(DOCKER_FULL_CMD) cargo expand \
--target riscv64gc-unknown-none-elf --features $(BSP)
else
cargo expand --target riscv64gc-unknown-none-elf --features $(BSP)
endif