Android编译系统参考手册
http://android.cloudchou.com/build/core/tasks/kernel.php
build/core/tasks/kernel.mk
定义生成内核的规则
TARGET_AUTO_KDIR
TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g')
自动设置的内核目录
比如i9100,那么自动设置的内核目录是
kernel/samsung/i9100
TARGET_KERNEL_SOURCE
TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR)
内核源码目录
默认 kernel//
一般在BoardConfig.mk里配置
KERNEL_SRC
KERNEL_SRC := $(TARGET_KERNEL_SOURCE)
内核源码目录
KERNEL_DEFCONFIG
KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG)
编译内核用的配置文件
一般在BoardConfig.mk里配置
VARIANT_DEFCONFIG
VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG)
变量配置
一般在BoardConfig.mk里配置
TARGET_KERNEL_SELINUX_CONFIG
selinux配置
一般在BoardConfig.mk里配置
KERNEL_OUT
KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
示例:
out/target/product/i9100/obj/KERNEL_OBJ
KERNEL_CONFIG
生成的编译内核的配置文件
KERNEL_CONFIG := $(KERNEL_OUT)/.config
示例:
out/target/product/i9100/obj/KERNEL_OBJ/.config
BOARD_USES_UBOOT
是否启用uboot
一般在BoardConfig.mk里配置
BOARD_USES_UNCOMPRESSED_BOOT
是否启用无压缩的boot
一般在BoardConfig.mk里配置
TARGET_PREBUILT_INT_KERNEL
ifeq ($(BOARD_USES_UBOOT),true)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/uImage
TARGET_PREBUILT_INT_KERNEL_TYPE := uImage
else ifeq ($(BOARD_USES_UNCOMPRESSED_BOOT),true)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/Image
TARGET_PREBUILT_INT_KERNEL_TYPE := Image
else
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/zImage
TARGET_PREBUILT_INT_KERNEL_TYPE := zImage
endif
示例:
out/target/product/i9100/obj/KERNEL_OBJ/arch/arm/boot/zImage
TARGET_PREBUILT_INT_KERNEL_TYPE
见TARGET_PREBUILT_INT_KERNEL
TARGET_PREBUILT_KERNEL
预编译的内核
一般在BoardConfig.mk里配置
在Recovery适配时经常需要设置该项
示例:
TARGET_PREBUILT_KERNEL := $(LOCAL_DIR)/kernel
HAS_PREBUILT_KERNEL
是否有预编译的内核
NEEDS_KERNEL_COPY
是否需要拷贝内核
FULL_KERNEL_BUILD
是否需要编译内核源代码
KERNEL_BIN
内核文件
ifeq "$(wildcard $(KERNEL_SRC) )" ""
ifneq ($(HAS_PREBUILT_KERNEL),)
KERNEL_BIN := $(TARGET_PREBUILT_KERNEL)
endif
else
ifeq ($(TARGET_KERNEL_CONFIG),)
....
else
ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
KERNEL_BIN := $(KERNEL_OUT)/piggy
else
KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL)
endif
endif
endif
示例:
out/target/product/i9100/obj/KERNEL_OBJ/arch/arm/boot/zImage
KERNEL_HEADERS_INSTALL
KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
示例:
out/target/product/i9100/obj/KERNEL_OBJ/usr
KERNEL_MODULES_INSTALL
KERNEL_MODULES_INSTALL := system
内核模块的安装目录
KERNEL_MODULES_OUT
KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
内核模块的的实际安装目录
out/target/product/i9100/system/lib/modules
Function: mv-modules
移动模块
在system/lib/modules找到modules.order文件,
然后找到该文件所在目录下的kernel目录的ko模块文件
对这些文件用arm-eabi-strip进行strip处理
然后将其移至system/lib/modules
Function: clean-module-folder
在system/lib/modules找到modules.order文件
然后删除该文件所在的目录
ccache
ccache程序
ifneq ($(USE_CCACHE),)
# search executable
ccache =
ifneq ($(strip $(wildcard $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_EXTRA_TAG)/ccache/ccache)),)
ccache := $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_EXTRA_TAG)/ccache/ccache
else
ifneq ($(strip $(wildcard $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache)),)
ccache := $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
endif
endif
endif
ARM_CROSS_COMPILE
交叉编译工具链所在目录
ifneq ($(TARGET_KERNEL_CUSTOM_TOOLCHAIN),)
ifeq ($(HOST_OS),darwin)
ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ANDROID_BUILD_TOP)/prebuilt/darwin-x86/toolchain/$(TARGET_KERNEL_CUSTOM_TOOLCHAIN)/bin/arm-eabi-"
else
ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ANDROID_BUILD_TOP)/prebuilt/linux-x86/toolchain/$(TARGET_KERNEL_CUSTOM_TOOLCHAIN)/bin/arm-eabi-"
endif
else
ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ARM_EABI_TOOLCHAIN)/arm-eabi-"
endif
MAKE_FLAGS
ifeq ($(HOST_OS),darwin)
MAKE_FLAGS := C_INCLUDE_PATH=$(ANDROID_BUILD_TOP)/external/elfutils/libelf
endif
TARGET_KERNEL_MODULES
ifeq ($(TARGET_KERNEL_MODULES),)
TARGET_KERNEL_MODULES := no-external-modules
endif
Target: $(KERNEL_OUT)
创建$(KERNEL_OUT)目录
即目录out/target/product/i9100/obj/KERNEL_OBJ
Target: $(KERNEL_CONFIG)
生成编译内核源代码用的配置文件
$(KERNEL_CONFIG): $(KERNEL_OUT)
$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(KERNEL_DEFCONFIG)
Target: $(KERNEL_OUT)/piggy
生成piggy内核
$(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
$(hide) gunzip -c $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
TARGET_KERNEL_BINARIES
生成内核,并安装好模块
TARGET_KERNEL_BINARIES: $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
#生成内核
$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) $(TARGET_PREBUILT_INT_KERNEL_TYPE)
#生成模块
-$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) modules
#安装模块至system/lib/modules目录,但是还需strip处理
-$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) modules_install
$(mv-modules)
$(clean-module-folder)
Target: $(TARGET_PREBUILT_INT_KERNEL)
安装模块,并清除先前不用的模块所在目录
ALL_PREBUILT
ALL_PREBUILT += $(file)$(file) : $(KERNEL_BIN) | $(ACP)
$(transform-prebuilt-to-target)
ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET)