-
Notifications
You must be signed in to change notification settings - Fork 0
/
AndroidKernel.mk
111 lines (89 loc) · 3.78 KB
/
AndroidKernel.mk
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
#Android makefile to build kernel as a part of Android Build
ifeq ($(KERNEL_DEFCONFIG),)
$(error KERNEL_DEFCONFIG must be set as environment variable)
endif
ifeq ($(INSTALLED_KERNEL_TARGET),)
INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img
BOARD_PREBUILT_DTBOIMAGE := $(PRODUCT_OUT)/prebuilt_dtbo.img
INSTALLED_DTB_TARGET := $(PRODUCT_OUT)/dtb.img
endif
TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
ifeq ($(TARGET_KERNEL_ARCH),)
KERNEL_ARCH := arm64
else
KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
endif
ifeq ($(CROSS_COMPILE),)
KERNEL_CROSS_COMPILE := aarch64-linux-android-
else
KERNEL_CROSS_COMPILE := $(CROSS_COMPILE)
endif
# SOONG_GLOBAL_CONFIG := build/soong/cc/config/global.go
# CLANG_VERSION := $(shell grep "ClangDefaultVersion" $(SOONG_GLOBAL_CONFIG) | grep -o "clang-[0-9][0-9]*")
# CLANG_PATH := prebuilts/clang/host/linux-x86
# CC :=$(PWD)/$(CLANG_PATH)/$(CLANG_VERSION)/bin/clang
# ifeq ($(CLANG_TRIPLE),)
# CLANG_TRIPLE := aarch64-linux-gnu-
# else
# CLANG_TRIPLE := $(CLANG_TRIPLE)
# endif
ifeq ($(TARGET_PREBUILT_KERNEL),)
TARGET_KERNEL_SOURCE := kernel/$(TARGET_KERNEL)
KERNEL_CONFIG := $(TARGET_KERNEL_SOURCE)/.config
KERNEL_BOOT := $(TARGET_KERNEL_SOURCE)/arch/$(KERNEL_ARCH)/boot
KERNEL_BIN := $(KERNEL_BOOT)/Image
KERNEL_DTB_DIR := $(KERNEL_BOOT)/dts/exynos
ifeq ($(TARGET_USE_EVT0),true)
KERNEL_DTB := $(KERNEL_DTB_DIR)/$(TARGET_SOC)_evt0.dtb
KERNEL_DTBO_CFG := $(KERNEL_DTB_DIR)/$(TARGET_SOC)_evt0_dtboimg.cfg
else
KERNEL_DTB := $(KERNEL_DTB_DIR)/$(TARGET_SOC).dtb
KERNEL_DTBO_CFG := $(KERNEL_DTB_DIR)/$(TARGET_SOC)_dtboimg.cfg
endif
MKDTIMG := $(HOST_OUT_EXECUTABLES)/mkdtimg
KERNEL_MERGE_CONFIG := $(TARGET_KERNEL_SOURCE)/scripts/kconfig/merge_config.sh
KERNEL_CONFIG_BASE := $(TARGET_KERNEL_SOURCE)/arch/$(KERNEL_ARCH)/configs
KERNEL_DEFCONFIG_PATH := $(KERNEL_CONFIG_BASE)/$(KERNEL_DEFCONFIG)
KERNEL_USER_CFG := $(KERNEL_CONFIG_BASE)/$(TARGET_SOC)_user.cfg
KERNEL_USERDEBUG_CFG := $(KERNEL_CONFIG_BASE)/$(TARGET_SOC)_userdebug.cfg
ifeq ($(KERNEL_DEFCONFIG),)
$(error Kernel configuration not defined, cannot build kernel)
else
ifeq ($(TARGET_BUILD_VARIANT),eng)
MAKE_CONFIG_CMD := $(MAKE) -C $(TARGET_KERNEL_SOURCE) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG)
else
ifeq ($(TARGET_BUILD_VARIANT),userdebug)
MAKE_CONFIG_CMD := ARCH=$(KERNEL_ARCH) $(KERNEL_MERGE_CONFIG) -m -O $(TARGET_KERNEL_SOURCE) $(KERNEL_DEFCONFIG_PATH) $(KERNEL_USERDEBUG_CFG);
MAKE_CONFIG_CMD += $(MAKE) -C $(TARGET_KERNEL_SOURCE) ARCH=$(KERNEL_ARCH) KCONFIG_ALLCONFIG=.config alldefconfig
else
MAKE_CONFIG_CMD := ARCH=$(KERNEL_ARCH) $(KERNEL_MERGE_CONFIG) -m -O $(TARGET_KERNEL_SOURCE) $(KERNEL_DEFCONFIG_PATH) $(KERNEL_USER_CFG);
MAKE_CONFIG_CMD += $(MAKE) -C $(TARGET_KERNEL_SOURCE) ARCH=$(KERNEL_ARCH) KCONFIG_ALLCONFIG=.config alldefconfig
endif
endif
ifeq ($(N_KERNEL_BUILD_THREAD),)
N_KERNEL_BUILD_THREAD := 1
endif
TARGET_PREBUILT_KERNEL := $(KERNEL_BIN)
.PHONY: phony-rebuild
.PHONY: kernel
kernel: $(KERNEL_BIN)
.PHONY: kernel-distclean
kernel-distclean:
$(MAKE) -C $(TARGET_KERNEL_SOURCE) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) distclean
$(KERNEL_CONFIG): phony-rebuild
$(hide) echo "make $(KERNEL_DEFCONFIG)"
$(MAKE_CONFIG_CMD)
$(KERNEL_BIN): $(KERNEL_CONFIG)
$(hide) echo "Building kernel..."
$(MAKE) -C $(TARGET_KERNEL_SOURCE) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) -j$(N_KERNEL_BUILD_THREAD)
$(INSTALLED_KERNEL_TARGET): $(INSTALLED_DTBOIMAGE_TARGET)
cp $(KERNEL_BIN) $(INSTALLED_KERNEL_TARGET)
cp $(KERNEL_DTB) $(INSTALLED_DTB_TARGET)
$(BOARD_PREBUILT_DTBOIMAGE): $(MKDTIMG) $(KERNEL_DTBO_CFG) $(KERNEL_BIN)
$(hide) echo "Building DTBOIMAGE..."
ln -sf $(TARGET_KERNEL_SOURCE)/arch
$(MKDTIMG) cfg_create $@ $(KERNEL_DTBO_CFG)
rm -f arch
endif #TARGET_PREBUILT_KERNEL
endif #KERNEL_DEFCONFIG