-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
147 lines (113 loc) · 3.19 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Supported architectures:
# - riscv64
# - riscv32 (no SMP)
ARCH ?= riscv64
#DEBUG_OUTPUT=1
#INITCONST_STR=1
#GCOV=1
VERSION=3
PATCHLEVEL=15
EXTRAVERSION=
QEMU_CPUS ?= 2
QEMU_CMDLINE ?= ""
all: grinch.bin user/initrd.cpio tools
HOSTCC=gcc
DTC=dtc
GDB=$(CROSS_COMPILE)gdb
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
AR=$(CROSS_COMPILE)ar
AS=$(CROSS_COMPILE)as
OBJDUMP=$(CROSS_COMPILE)objdump
OBJCOPY=$(CROSS_COMPILE)objcopy
SZ=$(CROSS_COMPILE)size
RMRF=rm -rf
D_UBOOT=$(realpath res/u-boot)
UBOOT_PFX=$(D_UBOOT)/u-boot-$(ARCH)-$(PLATFORM)
UBOOT_BIN=$(UBOOT_PFX)/u-boot-nodtb.bin
MAKEARGS_UBOOT=-j 8 CROSS_COMPILE=$(CROSS_COMPILE) ARCH=$(ARCH_SUPER)
ifdef V
QUIET := @true
VERBOSE :=
else
QUIET := @echo
VERBOSE := @
endif
OPT?=-O0
AFLAGS_COMMON=-D__ASSEMBLY__
CFLAGS_STANDALONE=-nostdinc -ffreestanding -g -ggdb
ifeq ($(INITCONST_STR), 1)
CFLAGS_STANDALONE += -Wno-format-security -DINITCONST_STR
else
CFLAGS_STANDALONE += -Wformat-security
endif
CFLAGS_COMMON=$(OPT) \
-fno-strict-aliasing \
-fno-omit-frame-pointer -fno-stack-protector \
-ffunction-sections -fdata-sections \
-Wall -Wextra -Wno-unused-parameter \
-Wstrict-prototypes -Wtype-limits \
-Wmissing-declarations -Wmissing-prototypes \
-Wnested-externs -Wshadow -Wredundant-decls \
-Wundef -Wdeprecated -Werror
LDFLAGS_COMMON=
ifeq ($(DEBUG_OUTPUT), 1)
CFLAGS_COMMON += -DDEBUG
endif
define clean_objects
$(QUIET) "[CLEAN]" $1
$(VERBOSE) $(RMRF) $(1)/built-in.a $(2) $(2:.o=.gcno) $(2:.o=.gcda)
endef
define clean_file
$(QUIET) "[CLEAN]" $1
$(VERBOSE) $(RMRF) $(1)
endef
define clean_files
$(QUIET) "[CLEAN]" $1
$(VERBOSE) $(RMRF) $(2)
endef
include scripts/kernel.mk
include user/inc.mk
include tools/inc.mk
%.bin: %.elf
$(QUIET) "[OBJC] $@"
$(VERBOSE) $(OBJCOPY) -O binary $^ $@
%/built-in.a:
$(QUIET) "[AR] $@"
$(VERBOSE) rm -f $@
$(VERBOSE) $(AR) cDPrST $@ $^
QEMU_CMD=$(QEMU) $(QEMU_ARGS_COMMON) $(QEMU_ARGS) -append $(QEMU_CMDLINE)
QEMU_CMD_DIRECT=$(QEMU_CMD) -kernel grinch.bin -initrd user/initrd.cpio
QEMU_CMD_UBOOT=$(QEMU_CMD) -kernel $(UBOOT_BIN) $(QEMU_UBOOT_ARGS)
qemu: all
$(QEMU_CMD_DIRECT)
qemuu: all $(UBOOT_BIN)
$(QEMU_CMD_UBOOT)
qemudb: all
$(QEMU_CMD_DIRECT) -S
qemuudb: all $(UBOOT_BIN)
$(QEMU_CMD_UBOOT) -S
qemu.dts: grinch.bin user/initrd.cpio
$(QEMU_CMD_DIRECT) $(QEMU_MACHINE),dumpdtb=/tmp/qemu_tmp.dtb
dtc -I dtb -O dts /tmp/qemu_tmp.dtb -o $@
rm -f /tmp/qemu_tmp.dtb
.PHONY: grinch.dump
grinch.dump: scripts/grinch_dump.gdb grinch.elf
$(GDB) -x $<
grinch.info: grinch.dump tools/gcov_extract
./tools/gcov_extract $<
lcov -c -d . -o $@
gcov: grinch.info
mkdir -p gcov
genhtml $< -o gcov/
$(UBOOT_BIN):
mkdir -p $(UBOOT_PFX)
cp -av res/u-boot/$(UBOOT_CFG) $(UBOOT_PFX)/.config
$(MAKE) -C $(D_UBOOT)/u-boot $(MAKEARGS_UBOOT) O=$(UBOOT_PFX) oldconfig
$(MAKE) -C $(UBOOT_PFX) $(MAKEARGS_UBOOT) u-boot-nodtb.bin
debug: grinch.bin
$(GDB) -x scripts/debug.gdb $^
clean: clean_core clean_lib clean_mm clean_fs clean_user clean_arch clean_drivers clean_kernel clean_tools
$(call clean_files,all,kernel.bin grinch.bin grinch.elf grinch.dump grinch.info gcov)
mrproper: clean
$(MAKE) -C $(D_UBOOT) mrproper