forked from Hongqin-Li/rpi-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (69 loc) · 2.2 KB
/
Makefile
File metadata and controls
88 lines (69 loc) · 2.2 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
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
-include config.mk
CFLAGS := -Wall -g -O2 \
-fno-pie -fno-pic -fno-stack-protector \
-fno-zero-initialized-in-bss \
-static -fno-builtin -nostdlib -nostdinc -ffreestanding -nostartfiles \
-mgeneral-regs-only \
-MMD -MP \
-Iinc -Ilibc/obj/include -Ilibc/arch/aarch64 -Ilibc/include -Ilibc/arch/generic
CFLAGS += -DNOT_DEBUG -DLOG_DEBUG -DRASPI=$(RASPI)
CFLAGS += -mlittle-endian -mcmodel=small -mno-outline-atomics
ifeq ($(strip $(RASPI)), 3)
CFLAGS += -mcpu=cortex-a53 -mtune=cortex-a53
else ifeq ($(strip $(RASPI)), 4)
CFLAGS += -mcpu=cortex-a72 -mtune=cortex-a72
else
$(error RASPI must be set to 3 or 4)
endif
SRC_DIRS := kern
BUILD_DIR = obj
KERN_ELF := $(BUILD_DIR)/kernel8.elf
KERN_IMG := $(BUILD_DIR)/kernel8.img
SD_IMG := $(BUILD_DIR)/sd.img
all:
$(MAKE) -C boot
$(MAKE) -C usr
$(MAKE) $(SD_IMG)
# Automatically find sources and headers
SRCS := $(shell find $(SRC_DIRS) -name *.c -or -name *.S)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
-include $(DEPS)
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.S.o: %.S
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(KERN_ELF): kern/linker.ld $(OBJS)
$(LD) -o $@ -T $< $(OBJS)
$(OBJDUMP) -S -d $@ > $(basename $@).asm
$(OBJDUMP) -x $@ > $(basename $@).hdr
$(KERN_IMG): $(KERN_ELF)
$(OBJCOPY) -O binary $< $@
-include mksd.mk
QEMU_CMD ?= $(QEMU) -M raspi3 -nographic -serial null -serial mon:stdio -drive file=$(SD_IMG),if=sd,format=raw
qemu: all
$(QEMU_CMD) -kernel $(KERN_IMG)
qemu-gdb: all
$(QEMU_CMD) -kernel $(KERN_IMG) -S -gdb tcp::1234
gdb:
gdb-multiarch -n -x .gdbinit
init:
sudo apt install -y gcc-aarch64-linux-gnu gdb-multiarch
sudo apt install -y qemu-system-arm qemu-efi-aarch64 qemu-utils
sudo apt install -y mtools
sudo apt install -y indent
git submodule update --init --recursive
(cd libc && export CROSS_COMPILE=$(CROSS) && ./configure --target=$(ARCH))
LINT_SRC := $(shell find $(SRC_DIRS) usr -name *.c)
LINT_TMP := $(LINT_SRC:%=%~)
lint:
indent -kr -psl -ss -nut -ncs $(LINT_SRC)
rm $(LINT_TMP)
clean:
$(MAKE) -C usr clean
$(MAKE) -C libc clean
$(MAKE) -C boot clean
rm -rf $(BUILD_DIR)
.PHONY: init all lint clean qemu qemu-gdb gdb