-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
331 lines (280 loc) · 8.99 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
PROJECT_ROOT:=$(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
OVMF=${PROJECT_ROOT}/third_party/ovmf/RELEASEX64_OVMF.fd
QEMU=qemu-system-x86_64
PORT_MONITOR?=2345
PORT_OFFSET_VNC?=5
VNC_PASSWORD?=wasabi
INIT?=hello1
RUNNER_NORMAL=$(shell readlink -f scripts/launch_qemu.sh)
RUNNER_TEST=$(shell readlink -f scripts/test_runner.sh)
NOVNC_VERSION=1.4.0
HOST_TARGET=`rustc -V -v | grep 'host:' | sed 's/host: //'`
CLIPPY_OPTIONS=-D warnings
APPS=$(shell ls $(PROJECT_ROOT)/app)
APP_PACKAGES=$(addprefix -p , $(APPS))
BIN_DIR=$(PROJECT_ROOT)/generated/bin/
TCP_FORWARD_PORT?=18080
HOST_HTTP_SERVER_PORT?=18081
QEMU_ARGS=\
-machine q35 -cpu qemu64 -smp 4 \
-bios $(OVMF) \
-device qemu-xhci \
-device isa-debug-exit,iobase=0xf4,iosize=0x01 \
-netdev user,id=net1,hostfwd=tcp::$(TCP_FORWARD_PORT)-:$(TCP_FORWARD_PORT) \
-device rtl8139,netdev=net1 \
-object filter-dump,id=f2,netdev=net1,file=log/dump_net1.pcap \
-m 1024M \
-drive format=raw,file=fat:rw:mnt \
-chardev file,id=char_com1,mux=on,path=log/com1.txt \
-chardev stdio,id=char_com2,mux=on,logfile=log/com2.txt \
-serial chardev:char_com1 \
-serial chardev:char_com2 \
-rtc base=localtime \
-monitor telnet:0.0.0.0:$(PORT_MONITOR),server,nowait,logfile=log/qemu_monitor.txt \
--no-reboot \
-d int,cpu_reset \
-D log/qemu_debug.txt \
-device usb-kbd \
-device usb-tablet,usb_version=1 \
${MORE_QEMU_FLAGS}
# > -device usb-tablet,usb_version=1
# setting usb_version=1 here to avoid issues.
# c.f. https://bugzilla.redhat.com/show_bug.cgi?id=929068#c2
ifndef DISPLAY
QEMU_ARGS+= -vnc 0.0.0.0:$(PORT_OFFSET_VNC),password=on
endif
ifeq ($(HEADLESS),1)
QEMU_ARGS+= -display none
endif
ifeq ($(GDB),1)
QEMU_ARGS+= -gdb tcp::3333 -S
endif
# QEMU_ARGS+= -device usb-tablet
# -vnc 0.0.0.0:$(PORT_OFFSET_VNC),password=on \
# -gdb tcp::3333 -S \
# -device usb-host,hostbus=1,hostport=1 \
# -device usb-host,hostbus=2,hostport=1.2.1 \
# -device usb-mouse \
# -netdev user,id=net0 -device usb-net,netdev=net0 \
# -object filter-dump,id=f1,netdev=net0,file=log/dump_net0.dat \
APP_RUSTFLAGS=\
-C link-args=-e \
-C link-args=entry \
-C link-args=-z \
-C link-args=execstack
APP_TARGET=x86_64-unknown-none
APP_CARGO=RUSTFLAGS='$(APP_RUSTFLAGS)' cargo
APP_BUILD_ARG=-v --target $(APP_TARGET) --release
.PHONY : default
default: os app
.PHONY : os
os:
rustup component add rust-src --toolchain `rustup show active-toolchain | cut -d ' ' -f 1`
cd os && cargo build --all-targets --all-features
.PHONY : doc
doc:
cargo doc --all
.PHONY : os_doc
os_doc:
cargo doc -p os --open --document-private-items
.PHONY : noli_doc_for_app
noli_doc_for_app:
cargo doc -p noli --open --target $(APP_TARGET) --document-private-items
.PHONY : clippy
clippy:
rustup component add clippy
cd font && cargo clippy -- ${CLIPPY_OPTIONS}
cd os && cargo clippy -- ${CLIPPY_OPTIONS}
cd noli && cargo clippy -- ${CLIPPY_OPTIONS}
cd e2etest && cargo clippy -- ${CLIPPY_OPTIONS}
cd dbgutil && cargo clippy -- ${CLIPPY_OPTIONS}
cd os && cargo clippy --all-features --all-targets -- ${CLIPPY_OPTIONS}
# Run clippy on all apps under app dir
cargo clippy $(APP_PACKAGES) -- ${CLIPPY_OPTIONS}
cargo clippy --target=$(APP_TARGET) $(APP_PACKAGES) -- ${CLIPPY_OPTIONS}
.PHONY : dump_config
dump_config:
@echo "Host target: $(HOST_TARGET)"
.PHONY : test
test :
make pre_upload_test
.PHONY : check
check:
make filecheck
./scripts/ensure_objs_are_not_under_git_control.sh
make rustcheck
make clippy
make spellcheck
make os
.PHONY : run_app_unit_test
run_app_unit_test:
cargo test $(APP_PACKAGES)
.PHONY : pre_upload_test
pre_upload_test:
make doc
cargo test --package noli
make run_os_test
make run_os_lib_test
make run_app_unit_test
.PHONY : post_upload_test
post_upload_test:
make run_e2e_test
.PHONY : fmt
fmt :
rustup component add rustfmt
cargo fmt
.PHONY : commit
commit :
make fmt
git add .
make check
make pre_upload_test
git diff HEAD --color=always | less -R
git commit
.PHONY : filecheck
filecheck:
@! git ls-files | grep -v -E '(\.(rs|md|toml|sh|txt|json|lock|mk|dot|svg)|Makefile|LICENSE|rust-toolchain|Dockerfile|OVMF.fd|\.yml|\.gitignore|\.gitkeep)$$' \
|| ! echo "!!! Unknown file type is being added! Do you really want to commit the file above? (if so, just modify filecheck recipe)"
.PHONY : spellcheck
spellcheck :
@scripts/spellcheck.sh recieve receive
@scripts/spellcheck.sh faild failed
@scripts/spellcheck.sh mappng mapping
@scripts/spellcheck.sh priviledged privileged
@scripts/spellcheck.sh fullfill fulfill
.PHONY : rustcheck
rustcheck :
@scripts/rustcheck.sh
.PHONY : run
run :
export INIT="${INIT}" && \
cd os && cargo \
--config "target.'cfg(target_os = \"uefi\")'.runner = '$(RUNNER_NORMAL)'" \
run --release
.PHONY : run_e2e_test
run_e2e_test :
@echo ">>>>>>>> Running e2etest with FILTER=\"$(FILTER)\""
cd e2etest && cargo test -- --test-threads=1 --nocapture $(FILTER)
.PHONY : run_os_test
run_os_test :
cd os && cargo \
--config "target.'cfg(target_os = \"uefi\")'.runner = '$(RUNNER_TEST)'" \
test --bin os
.PHONY : run_os_lib_test
run_os_lib_test :
cd os && cargo \
--config "target.'cfg(target_os = \"uefi\")'.runner = '$(RUNNER_TEST)'" \
test --lib
.PHONY : app
app :
rustup target add $(APP_TARGET)
[ -d $(BIN_DIR) ] && rm -rf $(BIN_DIR) ; true
$(APP_CARGO) build $(APP_BUILD_ARG) $(APP_PACKAGES)
mkdir -p $(BIN_DIR)
@echo "Installing apps to ${BIN_DIR}"
cd target/$(APP_TARGET)/release && cp $(APPS) $(BIN_DIR)
.PHONY : run_deps
run_deps : app
-rm -rf mnt
mkdir -p mnt/
mkdir -p mnt/EFI/BOOT
cp README.md mnt/
cp generated/bin/* mnt/
cp default/init.txt mnt/
[ -f "${WITH_APP_BIN}" ] && cp ${WITH_APP_BIN} mnt/ || true
.PHONY : watch_serial
watch_serial:
while ! telnet localhost 1235 ; do sleep 1 ; done ;
.PHONY : watch_qemu_monitor
watch_qemu_monitor:
while ! telnet localhost ${PORT_MONITOR} ; do sleep 1 ; done ;
.PHONY : install
install : run_deps generated/bin/os.efi
bash ./scripts/install.sh
.PHONY : internal_launch_qemu
internal_launch_qemu : run_deps
@echo "Using ${PATH_TO_EFI}"
cp ${PATH_TO_EFI} mnt/EFI/BOOT/BOOTX64.EFI
$(QEMU) $(QEMU_ARGS) 2>log/qemu_stderr.txt
.PHONY : internal_run_app_test
internal_run_app_test : run_deps generated/bin/os.efi
cp generated/bin/os.efi mnt/EFI/BOOT/BOOTX64.EFI
@echo Testing app $$INIT...
printf "$$INIT" > mnt/init.txt
$(QEMU) $(QEMU_ARGS) -display none ; \
RETCODE=$$? ; \
if [ $$RETCODE -eq 3 ]; then \
echo "\nPASS" ; \
exit 0 ; \
else \
echo "\nFAIL: QEMU returned $$RETCODE" ; \
exit 1 ; \
fi
.PHONY : internal_run_os_test
internal_run_os_test : run_deps
@echo Using ${LOADER_TEST_EFI} as a os...
cp ${LOADER_TEST_EFI} mnt/EFI/BOOT/BOOTX64.EFI
$(QEMU) $(QEMU_ARGS) -display none ; \
RETCODE=$$? ; \
if [ $$RETCODE -eq 3 ]; then \
echo "\nPASS" ; \
exit 0 ; \
else \
echo "\nFAIL: QEMU returned $$RETCODE" ; \
exit 1 ; \
fi
.PHONY : act
act:
act -P hikalium/wasabi-builder:latest=hikalium/wasabi-builder:latest
.PHONY : symbols
symbols:
cargo run --bin=dbgutil -- symbol | tee symbols.txt
.PHONY : objdump
objdump:
cargo install cargo-binutils
rustup component add llvm-tools-preview
cd os && cargo-objdump -- -d > ../objdump.txt
echo "Saved objdump as objdump.txt"
.PHONY : crash
crash:
cargo run --bin=dbgutil crash \
--qemu-debug-log $$(readlink -f log/qemu_debug.txt) \
--serial-log $$(readlink -f log/com2.txt)
.PHONY : tshark
tshark:
@tshark -V -o ip.check_checksum:TRUE -o tcp.check_checksum:TRUE -r log/dump_net1.pcap
.PHONY : tshark_json
tshark_json:
@tshark -V -o ip.check_checksum:TRUE -x -T json -r log/dump_net1.pcap | jq .
.PHONY : tshark_tcp
tshark_tcp:
@tshark -V -o ip.check_checksum:TRUE -T json -Y tcp -r log/dump_net1.pcap | jq -c '.[]._source.layers | {src_ip: .ip."ip.src", dst_ip: .ip."ip.dst", src: .tcp."tcp.srcport", dst: .tcp."tcp.dstport", flags: .tcp."tcp.flags_tree"."tcp.flags.str", seq: .tcp."tcp.seq_raw", ack_raw: .tcp."tcp.ack_raw"}'
.PHONY : tcp_hello
tcp_hello:
echo "hello" | nc localhost ${TCP_FORWARD_PORT}
.PHONY : tcp_echo_server
tcp_echo_server:
socat -v tcp-l:15000,reuseaddr,fork exec:'/bin/cat'
.PHONY : tcp_http_server
tcp_http_server:
( printf "HTTP/1.1 200 OK\nContent-Length: 14\n\nHello, World!\n" ) | nc -l $(HOST_HTTP_SERVER_PORT)
.PHONY : curl_with_header
curl_with_header:
curl \
-H 'User-Agent:' \
-H 'Host:' \
-H 'Accept:' \
-v localhost:$(HOST_HTTP_SERVER_PORT)
.PHONY : vnc
vnc: generated/noVNC-$(NOVNC_VERSION)
( echo 'change vnc password $(VNC_PASSWORD)' | while ! nc localhost $(PORT_MONITOR) ; do sleep 1 ; done ) &
generated/noVNC-$(NOVNC_VERSION)/utils/novnc_proxy --vnc localhost:$$((5900+${PORT_OFFSET_VNC}))
generated/bin/os.efi:
cd os && cargo install --path . --root ../generated/
generated/noVNC-% :
wget -O generated/novnc.tar.gz https://github.com/novnc/noVNC/archive/refs/tags/v$*.tar.gz
cd generated && tar -xvf novnc.tar.gz
list_structs:
git grep -o 'struct [A-Z][A-Za-z0-9]* ' | sed -e 's#/src/#::#' -e 's#main\.rs:##' -e 's#lib\.rs:##' -e 's#struct ##' -e 's/\.rs:/::/' -e 's#/#::#' | sort -u
list_e2etests:
cargo test -p e2etest -- --list