|
| 1 | +#Android makefile to build kernel as a part of Android Build |
| 2 | + |
| 3 | +TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g') |
| 4 | + |
| 5 | +## Externally influenced variables |
| 6 | +# kernel location - optional, defaults to kernel/<vendor>/<device> |
| 7 | +TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR) |
| 8 | +KERNEL_SRC := $(TARGET_KERNEL_SOURCE) |
| 9 | +# kernel configuration - mandatory |
| 10 | +KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG) |
| 11 | + |
| 12 | +## Internal variables |
| 13 | +KERNEL_OUT := $(ANDROID_BUILD_TOP)/$(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 14 | +KERNEL_CONFIG := $(KERNEL_OUT)/.config |
| 15 | + |
| 16 | +ifeq ($(BOARD_USES_UBOOT),true) |
| 17 | + TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/uImage |
| 18 | + TARGET_PREBUILT_INT_KERNEL_TYPE := uImage |
| 19 | +else ifeq ($(BOARD_USES_UNCOMPRESSED_BOOT),true) |
| 20 | + TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/Image |
| 21 | + TARGET_PREBUILT_INT_KERNEL_TYPE := Image |
| 22 | +else |
| 23 | + TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/zImage |
| 24 | + TARGET_PREBUILT_INT_KERNEL_TYPE := zImage |
| 25 | +endif |
| 26 | + |
| 27 | +ifeq "$(wildcard $(KERNEL_SRC) )" "" |
| 28 | + ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 29 | + HAS_PREBUILT_KERNEL := true |
| 30 | + NEEDS_KERNEL_COPY := true |
| 31 | + else |
| 32 | + $(foreach cf,$(PRODUCT_COPY_FILES), \ |
| 33 | + $(eval _src := $(call word-colon,1,$(cf))) \ |
| 34 | + $(eval _dest := $(call word-colon,2,$(cf))) \ |
| 35 | + $(ifeq kernel,$(_dest), \ |
| 36 | + $(eval HAS_PREBUILT_KERNEL := true))) |
| 37 | + endif |
| 38 | + |
| 39 | + ifneq ($(HAS_PREBUILT_KERNEL),) |
| 40 | + $(warning ***************************************************************) |
| 41 | + $(warning * Using prebuilt kernel binary instead of source *) |
| 42 | + $(warning * THIS IS DEPRECATED, AND WILL BE DISCONTINUED *) |
| 43 | + $(warning * Please configure your device to download the kernel *) |
| 44 | + $(warning * source repository to $(KERNEL_SRC)) |
| 45 | + $(warning * See http://wiki.cyanogenmod.com/wiki/Integrated_kernel_building) |
| 46 | + $(warning * for more information *) |
| 47 | + $(warning ***************************************************************) |
| 48 | + FULL_KERNEL_BUILD := false |
| 49 | + KERNEL_BIN := $(TARGET_PREBUILT_KERNEL) |
| 50 | + else |
| 51 | + $(warning ***************************************************************) |
| 52 | + $(warning * *) |
| 53 | + $(warning * No kernel source found, and no fallback prebuilt defined. *) |
| 54 | + $(warning * Please make sure your device is properly configured to *) |
| 55 | + $(warning * download the kernel repository to $(KERNEL_SRC)) |
| 56 | + $(warning * and add the TARGET_KERNEL_CONFIG variable to BoardConfig.mk *) |
| 57 | + $(warning * *) |
| 58 | + $(warning * As an alternative, define the TARGET_PREBUILT_KERNEL *) |
| 59 | + $(warning * variable with the path to the prebuilt binary kernel image *) |
| 60 | + $(warning * in your BoardConfig.mk file *) |
| 61 | + $(warning * *) |
| 62 | + $(warning ***************************************************************) |
| 63 | + $(error "NO KERNEL") |
| 64 | + endif |
| 65 | +else |
| 66 | + NEEDS_KERNEL_COPY := true |
| 67 | + ifeq ($(TARGET_KERNEL_CONFIG),) |
| 68 | + $(warning **********************************************************) |
| 69 | + $(warning * Kernel source found, but no configuration was defined *) |
| 70 | + $(warning * Please add the TARGET_KERNEL_CONFIG variable to your *) |
| 71 | + $(warning * BoardConfig.mk file *) |
| 72 | + $(warning **********************************************************) |
| 73 | + # $(error "NO KERNEL CONFIG") |
| 74 | + else |
| 75 | + #$(info Kernel source found, building it) |
| 76 | + FULL_KERNEL_BUILD := true |
| 77 | + ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 78 | + $(info Using uncompressed kernel) |
| 79 | + KERNEL_BIN := $(KERNEL_OUT)/piggy |
| 80 | + else |
| 81 | + KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL) |
| 82 | + endif |
| 83 | + endif |
| 84 | +endif |
| 85 | + |
| 86 | +ifeq ($(FULL_KERNEL_BUILD),true) |
| 87 | + |
| 88 | +KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 89 | +KERNEL_MODULES_INSTALL := system |
| 90 | +KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
| 91 | + |
| 92 | +define mv-modules |
| 93 | + mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.order`;\ |
| 94 | + if [ "$$mdpath" != "" ];then\ |
| 95 | + mpath=`dirname $$mdpath`;\ |
| 96 | + ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 97 | + for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 98 | + fi |
| 99 | +endef |
| 100 | + |
| 101 | +define clean-module-folder |
| 102 | + mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.order`;\ |
| 103 | + if [ "$$mdpath" != "" ];then\ |
| 104 | + mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 105 | + fi |
| 106 | +endef |
| 107 | + |
| 108 | +ifeq ($(TARGET_ARCH),arm) |
| 109 | + ifneq ($(USE_CCACHE),) |
| 110 | + ccache := $(ANDROID_BUILD_TOP)/prebuilt/$(HOST_PREBUILT_TAG)/ccache/ccache |
| 111 | + # Check that the executable is here. |
| 112 | + ccache := $(strip $(wildcard $(ccache))) |
| 113 | + endif |
| 114 | + ifeq ($(HOST_OS),darwin) |
| 115 | + ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ANDROID_BUILD_TOP)/prebuilt/darwin-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-" |
| 116 | + else |
| 117 | + ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ARM_EABI_TOOLCHAIN)/arm-eabi-" |
| 118 | + endif |
| 119 | + ccache = |
| 120 | +endif |
| 121 | + |
| 122 | +ifeq ($(TARGET_KERNEL_MODULES),) |
| 123 | + TARGET_KERNEL_MODULES := no-external-modules |
| 124 | +endif |
| 125 | + |
| 126 | +$(KERNEL_OUT): |
| 127 | + mkdir -p $(KERNEL_OUT) |
| 128 | + mkdir -p $(KERNEL_MODULES_OUT) |
| 129 | + |
| 130 | +$(KERNEL_CONFIG): $(KERNEL_OUT) |
| 131 | + $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) $(KERNEL_DEFCONFIG) |
| 132 | + |
| 133 | +$(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL) |
| 134 | + $(hide) gunzip -c $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy |
| 135 | + |
| 136 | +TARGET_KERNEL_BINARIES: $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL) |
| 137 | + $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) $(TARGET_PREBUILT_INT_KERNEL_TYPE) |
| 138 | + $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) modules |
| 139 | + $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) modules_install |
| 140 | + $(mv-modules) |
| 141 | + $(clean-module-folder) |
| 142 | + |
| 143 | +$(TARGET_KERNEL_MODULES): TARGET_KERNEL_BINARIES |
| 144 | + |
| 145 | +$(TARGET_PREBUILT_INT_KERNEL): $(TARGET_KERNEL_MODULES) |
| 146 | + $(mv-modules) |
| 147 | + $(clean-module-folder) |
| 148 | + |
| 149 | +$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 150 | + $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) headers_install |
| 151 | + |
| 152 | +endif # FULL_KERNEL_BUILD |
| 153 | + |
| 154 | +## Install it |
| 155 | + |
| 156 | +ifeq ($(NEEDS_KERNEL_COPY),true) |
| 157 | +file := $(INSTALLED_KERNEL_TARGET) |
| 158 | +ALL_PREBUILT += $(file) |
| 159 | +$(file) : $(KERNEL_BIN) | $(ACP) |
| 160 | + $(transform-prebuilt-to-target) |
| 161 | + |
| 162 | +ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET) |
| 163 | +endif |
0 commit comments