-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJustfile
103 lines (83 loc) · 2.55 KB
/
Justfile
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
# Arch: x86_64, aarch64, riscv64
ARCH := env("ARCH", "x86_64")
RUST_TARGET := env("RUST_TARGET", "x86_64-unknown-none")
IMAGE_NAME := env("IMAGE_NAME", "memsos_" + ARCH)
QEMU_FLAGS := env("QEMU_FLAGS", "")
OVMF_DIR := "ovmf"
LIMINE_DIR := "limine"
# UEFI prefix from ARCH
UEFI_SUFFIX := `\
if [ "{{ARCH}}" = "x86_64" ]; then \
echo "X64"; \
elif [ "{{ARCH}}" = "aarch64" ]; then \
echo "AA64"; \
elif [ "{{ARCH}}" = "riscv64" ]; then \
echo "RISCV64"; \
else \
echo "IA32"; \
fi`
# Run vm
run-uefi: build ovmf
qemu-system-{{ARCH}} \
-M q35 \
-no-reboot \
-no-shutdown \
-d int \
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-{{ARCH}}.fd,readonly=on \
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-{{ARCH}}.fd \
-cdrom {{IMAGE_NAME}}.iso \
{{QEMU_FLAGS}}
run-bios: build
qemu-system-{{ARCH}} \
-M q35 \
-cdrom {{IMAGE_NAME}}.iso \
-d int \
-no-reboot \
-no-shutdown \
-boot d \
{{QEMU_FLAGS}}
# OVMF build
ovmf:
test -d {{OVMF_DIR}} || (mkdir -p {{OVMF_DIR}} && curl -Lo {{OVMF_DIR}}/ovmf-code-{{ARCH}}.fd https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-code-{{ARCH}}.fd && curl -Lo {{OVMF_DIR}}/ovmf-vars-{{ARCH}}.fd https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-vars-{{ARCH}}.fd)
# Limine (bootloader) build
limine:
test -d {{LIMINE_DIR}} || git clone https://github.com/limine-bootloader/limine.git --branch=v8.x-binary --depth=1
make -C {{LIMINE_DIR}}
# Kernel build
kernel:
echo $LANG
just kernel/
# Image build
build: limine kernel
rm -rf iso_root
mkdir -p iso_root/boot
cp -v kernel/kernel iso_root/boot/
mkdir -p iso_root/boot/limine
cp -v limine.conf iso_root/boot/limine/
mkdir -p iso_root/EFI/BOOT
cp -v limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/
cp -v limine/BOOT{{UEFI_SUFFIX}}.EFI iso_root/EFI/BOOT/
xorriso -as mkisofs -b boot/limine/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot boot/limine/limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o {{IMAGE_NAME}}.iso
./limine/limine bios-install {{IMAGE_NAME}}.iso
rm -rf iso_root
clean:
just kernel/ clean
rm -rf iso_root {{IMAGE_NAME}}.iso
rm -rf limine ovmf
format:
cargo fmt --all -p kernel
clippy:
cargo clippy -p kernel
default: run-uefi
lint:
cargo clippy --all-targets --all-features -- -D warnings
fmt:
cargo fmt --all -- --check
fmt-fix:
cargo fmt
test:
cargo test