-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
61 lines (47 loc) · 1.54 KB
/
Makefile
File metadata and controls
61 lines (47 loc) · 1.54 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
include common.mk
KERN = kernel
USER = user
MKFS = mkfs
KERNEL_ELF = kernel-qemu
FS_IMG = fs.img
CPUNUM = 2
.PHONY: clean $(KERN) $(USER) $(MKFS) all
# 比赛评测用的all目标 - 只需编译kernel生成kernel-qemu
all: $(KERN)
$(KERN):
$(MAKE) build --directory=$@
$(USER):
$(MAKE) init --directory=$@
$(MKFS):
$(MAKE) build --directory=$@
$(MKFS)/mkfs $(FS_IMG)
# QEMU相关配置
QEMU = qemu-system-riscv64
# 使用default bios(比赛评测环境)
QEMUOPTS = -machine virt -bios default -kernel $(KERNEL_ELF)
QEMUOPTS += -m 128M -smp $(CPUNUM) -nographic
QEMUOPTS += -drive file=$(FS_IMG),if=none,format=raw,id=x0
QEMUOPTS += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
# 比赛评测用的SD卡运行模式
SDCARD_IMG = sdcard.img
QEMUOPTS_SD = -machine virt -bios default -kernel $(KERNEL_ELF)
QEMUOPTS_SD += -m 128M -smp $(CPUNUM) -nographic
QEMUOPTS_SD += -drive file=$(SDCARD_IMG),if=none,format=raw,id=x0
QEMUOPTS_SD += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
# 调试
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
build: $(USER) $(KERN) $(MKFS)
# qemu运行
qemu: $(USER) $(KERN) $(MKFS)
$(QEMU) $(QEMUOPTS)
.gdbinit: .gdbinit.tmpl-riscv
sed "s/:1234/:$(GDBPORT)/" < $^ > $@
qemu-gdb: $(USER) $(KERN) $(MKFS) .gdbinit
$(QEMU) $(QEMUOPTS) -S $(QEMUGDB)
clean:
$(MAKE) --directory=$(KERN) clean
$(MAKE) --directory=$(MKFS) clean
rm -f $(KERNEL_ELF) $(FS_IMG) .gdbinit