-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (60 loc) · 2.09 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
.POSIX:
.PHONY: boot
QEMU_EXTRA_FLAGS=
ARCH=riscv64
RUST_FLAGS=-L. -g -C opt-level=z --edition 2021 --target $(ARCH).json -C relocation-model=static
RUST_SRC=$(RUST_SYSROOT)/lib/rustlib/src/rust/library
OBJCOPY=llvm-objcopy
include cfg.mk
all: cfg.mk krnl.bin
cfg.mk: configure
@printf 'Run ./configure before make\n'
@false
libcore.rlib:
$(RUSTC) $(RUST_FLAGS) --crate-type rlib --crate-name core $(RUST_SRC)/core/src/lib.rs -o $@
libcompiler_builtins.rlib: libcore.rlib compiler_builtins.rs
$(RUSTC) $(RUST_FLAGS) --crate-type rlib --crate-name compiler_builtins compiler_builtins.rs -o $@
liballoc.rlib: libcore.rlib libcompiler_builtins.rlib
$(RUSTC) $(RUST_FLAGS) --crate-type rlib --crate-name alloc $(RUST_SRC)/alloc/src/lib.rs -o $@ --cfg no_global_oom_handling
init: libcore.rlib libcompiler_builtins.rlib liballoc.rlib init.rs abi.rs fdt.rs
$(RUSTC) $(RUST_FLAGS) --crate-type bin --crate-name init init.rs -C link-arg=-Tinit.$(ARCH).lds -o $@
init.bin: init
$(OBJCOPY) -O binary init $@
SRCS=krnl.rs riscv64.rs con.rs rwlock.rs abi.rs
krnl: libcore.rlib libcompiler_builtins.rlib init.bin $(SRCS)
$(RUSTC) $(RUST_FLAGS) --crate-type bin --crate-name krnl krnl.rs -C link-arg=-T$(ARCH).lds -o $@
krnl.bin: krnl
$(OBJCOPY) -O binary krnl $@
qemu: krnl.bin
qemu-system-$(ARCH) -M virt \
-serial mon:stdio -nographic -net none -cpu max \
-kernel krnl.bin $(QEMU_EXTRA_FLAGS) -append "init=/toybox console=ttyS0" \
-smp 2
qemu.efi:
qemu-system-$(ARCH) -M virt \
-drive if=pflash,unit=0,format=raw,file=fw/$(ARCH).fd \
-serial mon:stdio -nographic -net noce -cpu max -s -smp 2
boot: krnl.bin
cp krnl.bin boot
qemu.uboot.s: boot
qemu-system-$(ARCH) -M virt \
-kernel fw/riscv64.u-boot-s.bin \
-serial mon:stdio -nographic -net none -cpu max \
-drive file=fat:rw:boot,if=virtio \
-m 256M -s
qemu.uboot: boot
qemu-system-$(ARCH) -M virt \
-bios fw/riscv64.u-boot.bin \
-serial mon:stdio -nographic -net none -cpu max \
-drive file=fat:rw:boot,if=virtio \
-m 256M -s
fmt:
rustfmt krnl.rs
rustfmt init.rs
clean:
rm -f *.d
rm -f *.rlib
rm -f krnl.bin
rm -f krnl
rm -f init.bin
rm -f init