-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (43 loc) · 1.59 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
CC = aarch64-none-linux-gnu-gcc
AS = aarch64-none-linux-gnu-as
OBJCOPY = aarch64-none-linux-gnu-objcopy
CFLAGS = -O0 -ffreestanding -nostdlib -nostartfiles -ggdb -mno-outline-atomics
#CFLAGS += -Wall
QEMU = qemu-system-aarch64
KERNELDIR = kernel
BUILDDIR = build
SRCS_C = $(wildcard $(KERNELDIR)/*.c)
SRCS_S = $(wildcard $(KERNELDIR)/*.S)
OBJS = $(patsubst $(KERNELDIR)/*.c, $(BUILDDIR)/*.o, $(SRCS_C))
OBJS += $(patsubst $(KERNELDIR)/*.S, $(BUILDDIR)/*.o, $(SRCS_S))
SRCS_U = user/cat.c user/init.c
OBJS_U = rootfs/cat rootfs/init
ROOTFS := $(wildcard rootfs/*)
all: kernel8.img rootfs.cpio
.PHONY: run clean
$(BUILDDIR)/%.o: $(KERNELDIR)/%.S
@mkdir -p $(BUILDDIR)
$(CC) $(CFLAGS) -c -o $@ $^
$(BUILDDIR)/%.o: $(KERNELDIR)/%.c
@mkdir -p $(BUILDDIR)
$(CC) $(CFLAGS) -c -o $@ $^
$(OBJS_U): $(SRCS_U)
$(CC) $(CFLAGS) -T user/user.ld $< user/libc.c -o $@
kernel8.img: $(OBJS) $(KERNELDIR)/link.ld
$(CC) $(CFLAGS) $(OBJS) -T $(KERNELDIR)/link.ld -o $(BUILDDIR)/kernel8.elf
$(OBJCOPY) $(BUILDDIR)/kernel8.elf -O binary kernel8.img
# QEMU loads the cpio archive file to 0x8000000 by default.
rootfs.cpio: $(ROOTFS)
find ./rootfs | cpio -o -H newc > rootfs.cpio
run: kernel8.img rootfs.cpio
$(QEMU) -M raspi3b -kernel kernel8.img -initrd rootfs.cpio -serial null -serial stdio
run-gdb: kernel8.img rootfs.cpio
$(QEMU) -M raspi3b -kernel kernel8.img -initrd rootfs.cpio -serial null -serial stdio -S -gdb tcp::1234
# then we load :
# aarch64-none-linux-gnu-gdb build/kernel8.elf
# target remote :1234
# and we can start debugging
clean:
rm kernel8.img
rm -r $(BUILDDIR)/*
rm rootfs.cpio