android androidkernel.mk,高通kernel顶层目录下的AndroidKernel.mk文件
高通kernel顶层目录下的AndroidKernel.mk文件高通kernel顶层目录下的AndroidKernel.mk文件是Android的编译系统的一部分,用来编译kernel。它的位置是在aosp/kernel目录下。文件层级结构12345678910111213141516定义变量【第一处】ifeq ($(TARGET_PREBUILT_KERNEL),)定义变量【第二处】ifeq (
高通kernel顶层目录下的AndroidKernel.mk文件
高通kernel顶层目录下的AndroidKernel.mk文件是Android的编译系统的一部分,用来编译kernel。
它的位置是在aosp/kernel目录下。
文件层级结构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16定义变量【第一处】
ifeq ($(TARGET_PREBUILT_KERNEL),)
定义变量【第二处】
ifeq ($(KERNEL_DEFCONFIG)$(wildcard $(KERNEL_CONFIG)),)
$(error Kernel configuration not defined, cannot build kernel)
else
定义变量【第三处】
定义一些目标和依赖
endif
endif
文件具体内容(带注释)
定义变量【第一处】
PERL变量
1
2#Android makefile to build kernel as a part of Android Build
PERL = perl
KERNEL_TARGET 和 INSTALLED_KERNEL_TARGET 变量
1
2
3
4KERNEL_TARGET := $(strip $(INSTALLED_KERNEL_TARGET))
ifeq ($(KERNEL_TARGET),)
INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
endif
在build/core/Makefile文件中,定义了INSTALLED_KERNEL_TARGET变量
1
2
3
4
5ifneq ($(strip $(TARGET_NO_KERNEL)),true)
INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
else
INSTALLED_KERNEL_TARGET :=
endif
TARGET_NO_KERNEL是在device/厂商/产品名/BoardConfig.mk中定义的
1TARGET_NO_KERNEL := false
Makefile中, ifeq关键字用来判断参数是否相等, ifneq的关键字是用来判断参数是否不相等, 格式为:
1
2
3
4
5ifneq (ARG1, ARG2) / ifneq (ARG1, ARG2)
ifneq 'ARG1' 'ARG2' / ifneq 'ARG1' 'ARG2'
ifneq "ARG1" "ARG2" / ifneq "ARG1" "ARG2"
ifneq "ARG1" 'ARG2' / ifneq "ARG1" 'ARG2'
ifneq 'ARG1' "ARG2" / ifneq 'ARG1' "ARG2"
综上所述可知,不论TARGET_NO_KERNEL为false还是true,则KERNEL_TARGET和INSTALLED_KERNEL_TARGET的值都为$(PRODUCT_OUT)/kernel。
TARGET_KERNEL_ARCH 和 KERNEL_ARCH 变量
1
2
3
4
5
6TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
ifeq ($(TARGET_KERNEL_ARCH),)
KERNEL_ARCH := arm
else
KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
endif
TARGET_KERNEL_ARCH是在device/厂商/产品名/BoardConfig.mk中定义的。 如果已经定义为某值(如arm64),KERNEL_ARCH就设定为该值(如arm64)。 反之,则设定为默认值arm
TARGET_KERNEL_HEADER_ARCH 和 KERNEL_HEADER_ARCH 变量
1
2
3
4
5
6
7TARGET_KERNEL_HEADER_ARCH := $(strip $(TARGET_KERNEL_HEADER_ARCH))
ifeq ($(TARGET_KERNEL_HEADER_ARCH),)
KERNEL_HEADER_ARCH := $(KERNEL_ARCH)
else
$(warning Forcing kernel header generation only for '$(TARGET_KERNEL_HEADER_ARCH)')
KERNEL_HEADER_ARCH := $(TARGET_KERNEL_HEADER_ARCH)
endif
TARGET_KERNEL_ARCH是在device/厂商/产品名/BoardConfig.mk中定义的。 如果TARGET_KERNEL_HEADER_ARCH为空,KERNEL_HEADER_ARCH就设定为KERNEL_ARCH的值。 反之,则警告并将KERNEL_HEADER_ARCH设定为TARGET_KERNEL_HEADER_ARCH
KERNEL_HEADER_DEFCONFIG 变量
1
2
3
4KERNEL_HEADER_DEFCONFIG := $(strip $(KERNEL_HEADER_DEFCONFIG))
ifeq ($(KERNEL_HEADER_DEFCONFIG),)
KERNEL_HEADER_DEFCONFIG := $(KERNEL_DEFCONFIG)
endif
KERNEL_DEFCONFIG是在device/厂商/产品名/AndroidBoard.mk中定义的。 KERNEL_HEADER_DEFCONFIG未找到定义的地方。 当KERNEL_HEADER_DEFCONFIG为空,则被赋值为KERNEL_DEFCONFIG。
binder
1
2
3
4
5
6# Force 32-bit binder IPC for 64bit kernel with 32bit userspace
ifeq ($(KERNEL_ARCH),arm64)
ifeq ($(TARGET_ARCH),arm)
KERNEL_CONFIG_OVERRIDE := CONFIG_ANDROID_BINDER_IPC_32BIT=y
endif
endif
通过条件判断,是否让32-bit的binder IPC(进程间通信机制) 强制运行于64bit的kernel的32bit用户空间。
TARGET_KERNEL_CROSS_COMPILE_PREFIX 和 KERNEL_CROSS_COMPILE 变量
1
2
3
4
5
6TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX))
ifeq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),)
KERNEL_CROSS_COMPILE := arm-eabi-
else
KERNEL_CROSS_COMPILE := $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)
endif
TARGET_KERNEL_CROSS_COMPILE_PREFIX是在device/厂商/产品名/AndroidBoard.mk中定义的。 例:TARGET_KERNEL_CROSS_COMPILE_PREFIX := aarch64-linux-android-
定义变量【第二处】
KERNEL_CFLAGS变量
1
2
3
4KERNEL_GCC_NOANDROID_CHK := $(shell (echo "int main() {return 0;}" | $(KERNEL_CROSS_COMPILE)gcc -E -mno-android - > /dev/null 2>&1 ; echo $$?))
ifeq ($(strip $(KERNEL_GCC_NOANDROID_CHK)),0)
KERNEL_CFLAGS := KCFLAGS=-mno-android
endif
KERNEL_GCC_NOANDROID_CHK 变量如果为0,则定义KERNEL_CFLAGS为KCFLAGS=-mno-android
mkfile_path变量
1mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
获得mk文件路径
current_dir变量
1current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
TARGET_KERNEL_VERSION变量
1
2
3ifeq ($(TARGET_KERNEL_VERSION),)
TARGET_KERNEL_VERSION := 3.18
endif
TARGET_KERNEL变量
1TARGET_KERNEL := msm-$(TARGET_KERNEL_VERSION)
通过TARGET_KERNEL变量,定义KERNEL_OUT等变量
1
2
3
4
5
6
7
8
9
10
11
12
13
14ifeq ($(TARGET_KERNEL),$(current_dir))
# New style, kernel/msm-version
BUILD_ROOT_LOC := ../../
TARGET_KERNEL_SOURCE := kernel/$(TARGET_KERNEL)
KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/kernel/$(TARGET_KERNEL)
KERNEL_SYMLINK := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
KERNEL_USR := $(KERNEL_SYMLINK)/usr
else
# Legacy style, kernel source directly under kernel
KERNEL_LEGACY_DIR := true
BUILD_ROOT_LOC := ../
TARGET_KERNEL_SOURCE := kernel
KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
endif
KERNEL_CONFIG变量
1KERNEL_CONFIG := $(KERNEL_OUT)/.config
定义变量【第三处】
TARGET_PREBUILT_INT_KERNEL变量
1
2
3
4
5
6
7
8
9
10ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
$(info Using uncompressed kernel)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image
else
ifeq ($(KERNEL_ARCH),arm64)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image.gz
else
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/zImage
endif
endif
依据TARGET_KERNEL_APPEND_DTB变量,定义TARGET_PREBUILT_INT_KERNEL变量
1
2
3
4ifeq ($(TARGET_KERNEL_APPEND_DTB), true)
$(info Using appended DTB)
TARGET_PREBUILT_INT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)-dtb
endif
KERNEL_HEADERS_INSTALL变量
1KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
KERNEL_MODULES_INSTALL变量
1KERNEL_MODULES_INSTALL :=system
KERNEL_MODULES_OUT变量
1KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
TARGET_PREBUILT_KERNEL变量
1TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
宏mv-modules
1
2
3
4
5
6
7
8define mv-modules
mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
if [ "$$mdpath" != "" ];then\
mpath=`dirname $$mdpath`;\
ko=`find $$mpath/kernel -type f -name *.ko`;\
for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
fi
endef
宏clean-module-folder
1
2
3
4
5
6define clean-module-folder
mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
if [ "$$mdpath" != "" ];then\
mpath=`dirname $$mdpath`; rm -rf $$mpath;\
fi
endef
目标和依赖
ifneq ($(KERNEL_LEGACY_DIR),true)
$(KERNEL_USR): $(KERNEL_HEADERS_INSTALL)
rm -rf $(KERNEL_SYMLINK)
ln -s kernel/$(TARGET_KERNEL) $(KERNEL_SYMLINK)
$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_USR)
endif
$(KERNEL_OUT):
mkdir -p $(KERNEL_OUT)
$(KERNEL_CONFIG): $(KERNEL_OUT)
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG)
$(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \
echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \
echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) oldconfig; fi
$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_HEADERS_INSTALL)
$(hide) echo "Building kernel..."
$(hide) rm -rf $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/dts
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_CFLAGS)
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_CFLAGS) modules
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) INSTALL_MOD_PATH=$(BUILD_ROOT_LOC)../$(KERNEL_MODULES_INSTALL) INSTALL_MOD_STRIP=1 ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) modules_install
$(mv-modules)
$(clean-module-folder)
$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT)
$(hide) if [ ! -z "$(KERNEL_HEADER_DEFCONFIG)" ]; then \
rm -f $(BUILD_ROOT_LOC)$(KERNEL_CONFIG); \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_HEADER_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_HEADER_DEFCONFIG); \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_HEADER_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) headers_install; fi
$(hide) if [ "$(KERNEL_HEADER_DEFCONFIG)" != "$(KERNEL_DEFCONFIG)" ]; then \
echo "Used a different defconfig for header generation"; \
rm -f $(BUILD_ROOT_LOC)$(KERNEL_CONFIG); \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG); fi
$(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \
echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \
echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) oldconfig; fi
kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) tags
kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
env KCONFIG_NOTIMESTAMP=true \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) menuconfig
env KCONFIG_NOTIMESTAMP=true \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) savedefconfig
cp $(KERNEL_OUT)/defconfig $(TARGET_KERNEL_SOURCE)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_DEFCONFIG)
更多推荐
所有评论(0)