Ricardo Cerqueira | dfd3ca4 | 2012-04-11 11:21:23 +0100 | [diff] [blame] | 1 | # Copyright (C) 2012 The CyanogenMod Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # Android makefile to build kernel as a part of Android Build |
| 16 | |
| 17 | TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g') |
| 18 | |
| 19 | ## Externally influenced variables |
| 20 | # kernel location - optional, defaults to kernel/<vendor>/<device> |
| 21 | TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR) |
| 22 | KERNEL_SRC := $(TARGET_KERNEL_SOURCE) |
| 23 | # kernel configuration - mandatory |
| 24 | KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG) |
| 25 | VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG) |
| 26 | SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG) |
| 27 | |
| 28 | ## Internal variables |
| 29 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 30 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
| 31 | |
| 32 | ifneq ($(BOARD_KERNEL_IMAGE_NAME),) |
| 33 | TARGET_PREBUILT_INT_KERNEL_TYPE := $(BOARD_KERNEL_IMAGE_NAME) |
| 34 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/$(TARGET_PREBUILT_INT_KERNEL_TYPE) |
| 35 | else |
| 36 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/zImage |
| 37 | TARGET_PREBUILT_INT_KERNEL_TYPE := zImage |
| 38 | endif |
| 39 | |
| 40 | ## Do be discontinued in a future version. Notify builder about target |
| 41 | ## kernel format requirement |
| 42 | ifeq ($(BOARD_KERNEL_IMAGE_NAME),) |
| 43 | ifeq ($(BOARD_USES_UBOOT),true) |
| 44 | $(error "Please set BOARD_KERNEL_IMAGE_NAME to uImage") |
| 45 | else ifeq ($(BOARD_USES_UNCOMPRESSED_BOOT),true) |
| 46 | $(error "Please set BOARD_KERNEL_IMAGE_NAME to Image") |
| 47 | endif |
| 48 | endif |
| 49 | |
| 50 | ifeq "$(wildcard $(KERNEL_SRC) )" "" |
| 51 | ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 52 | HAS_PREBUILT_KERNEL := true |
| 53 | NEEDS_KERNEL_COPY := true |
| 54 | else |
| 55 | $(foreach cf,$(PRODUCT_COPY_FILES), \ |
| 56 | $(eval _src := $(call word-colon,1,$(cf))) \ |
| 57 | $(eval _dest := $(call word-colon,2,$(cf))) \ |
| 58 | $(ifeq kernel,$(_dest), \ |
| 59 | $(eval HAS_PREBUILT_KERNEL := true))) |
| 60 | endif |
| 61 | |
| 62 | ifneq ($(HAS_PREBUILT_KERNEL),) |
| 63 | $(warning ***************************************************************) |
| 64 | $(warning * Using prebuilt kernel binary instead of source *) |
| 65 | $(warning * THIS IS DEPRECATED, AND WILL BE DISCONTINUED *) |
| 66 | $(warning * Please configure your device to download the kernel *) |
| 67 | $(warning * source repository to $(KERNEL_SRC)) |
| 68 | $(warning * See http://wiki.cyanogenmod.org/w/Doc:_integrated_kernel_building) |
| 69 | $(warning * for more information *) |
| 70 | $(warning ***************************************************************) |
| 71 | FULL_KERNEL_BUILD := false |
| 72 | KERNEL_BIN := $(TARGET_PREBUILT_KERNEL) |
| 73 | else |
| 74 | $(warning ***************************************************************) |
| 75 | $(warning * *) |
| 76 | $(warning * No kernel source found, and no fallback prebuilt defined. *) |
| 77 | $(warning * Please make sure your device is properly configured to *) |
| 78 | $(warning * download the kernel repository to $(KERNEL_SRC)) |
| 79 | $(warning * and add the TARGET_KERNEL_CONFIG variable to BoardConfig.mk *) |
| 80 | $(warning * *) |
| 81 | $(warning * As an alternative, define the TARGET_PREBUILT_KERNEL *) |
| 82 | $(warning * variable with the path to the prebuilt binary kernel image *) |
| 83 | $(warning * in your BoardConfig.mk file *) |
| 84 | $(warning * *) |
| 85 | $(warning ***************************************************************) |
| 86 | $(error "NO KERNEL") |
| 87 | endif |
| 88 | else |
| 89 | NEEDS_KERNEL_COPY := true |
| 90 | ifeq ($(TARGET_KERNEL_CONFIG),) |
| 91 | $(warning **********************************************************) |
| 92 | $(warning * Kernel source found, but no configuration was defined *) |
| 93 | $(warning * Please add the TARGET_KERNEL_CONFIG variable to your *) |
| 94 | $(warning * BoardConfig.mk file *) |
| 95 | $(warning **********************************************************) |
| 96 | # $(error "NO KERNEL CONFIG") |
| 97 | else |
| 98 | #$(info Kernel source found, building it) |
| 99 | FULL_KERNEL_BUILD := true |
| 100 | ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 101 | $(info Using uncompressed kernel) |
| 102 | KERNEL_BIN := $(KERNEL_OUT)/piggy |
| 103 | else |
| 104 | KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL) |
| 105 | endif |
| 106 | endif |
| 107 | endif |
| 108 | |
Josue Rivera | f07e0a7 | 2014-11-12 01:05:39 +0100 | [diff] [blame] | 109 | ifeq ($(TARGET_KERNEL_CUSTOM_RAMDISK),true) |
| 110 | $(shell sed -i "s;CONFIG_INITRAMFS_SOURCE=\"\.\.;CONFIG_INITRAMFS_SOURCE=\"source/\.\.;" $(KERNEL_PATH)) |
| 111 | endif |
| 112 | |
Ricardo Cerqueira | dfd3ca4 | 2012-04-11 11:21:23 +0100 | [diff] [blame] | 113 | ifeq ($(FULL_KERNEL_BUILD),true) |
| 114 | |
| 115 | KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 116 | KERNEL_MODULES_INSTALL := system |
| 117 | KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
| 118 | |
| 119 | define mv-modules |
| 120 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.order`;\ |
| 121 | if [ "$$mdpath" != "" ];then\ |
| 122 | mpath=`dirname $$mdpath`;\ |
| 123 | ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 124 | for i in $$ko; do $(ARM_EABI_TOOLCHAIN)/arm-eabi-strip --strip-unneeded $$i;\ |
| 125 | mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 126 | fi |
| 127 | endef |
| 128 | |
| 129 | define clean-module-folder |
| 130 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.order`;\ |
| 131 | if [ "$$mdpath" != "" ];then\ |
| 132 | mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 133 | fi |
| 134 | endef |
| 135 | |
| 136 | ifeq ($(TARGET_ARCH),arm) |
| 137 | ifneq ($(USE_CCACHE),) |
Chet Kener | fb9a9aa | 2014-12-03 19:58:15 -0500 | [diff] [blame^] | 138 | ccache := $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache |
| 139 | # Check that the executable is here. |
| 140 | ccache := $(strip $(wildcard $(ccache))) |
Ricardo Cerqueira | dfd3ca4 | 2012-04-11 11:21:23 +0100 | [diff] [blame] | 141 | endif |
Chet Kener | ae47c45 | 2014-12-03 19:58:15 -0500 | [diff] [blame] | 142 | ifneq ($(TARGET_GCC_VERSION_ARM),) |
| 143 | ifeq ($(HOST_OS),darwin) |
| 144 | ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ANDROID_BUILD_TOP)/prebuilts/gcc/darwin-x86/arm/arm-eabi-$(TARGET_GCC_VERSION_ARM)/bin/arm-eabi-" |
| 145 | else |
| 146 | ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ANDROID_BUILD_TOP)/prebuilts/gcc/linux-x86/arm/arm-eabi-$(TARGET_GCC_VERSION_ARM)/bin/arm-eabi-" |
| 147 | endif |
| 148 | else |
| 149 | ARM_CROSS_COMPILE:=CROSS_COMPILE="$(ccache) $(ARM_EABI_TOOLCHAIN)/arm-eabi-" |
| 150 | endif |
Ricardo Cerqueira | dfd3ca4 | 2012-04-11 11:21:23 +0100 | [diff] [blame] | 151 | ccache = |
| 152 | endif |
| 153 | |
| 154 | ifeq ($(HOST_OS),darwin) |
| 155 | MAKE_FLAGS := C_INCLUDE_PATH=$(ANDROID_BUILD_TOP)/external/elfutils/libelf |
| 156 | endif |
| 157 | |
| 158 | ifeq ($(TARGET_KERNEL_MODULES),) |
| 159 | TARGET_KERNEL_MODULES := no-external-modules |
| 160 | endif |
| 161 | |
| 162 | $(KERNEL_OUT): |
| 163 | mkdir -p $(KERNEL_OUT) |
| 164 | mkdir -p $(KERNEL_MODULES_OUT) |
| 165 | |
| 166 | $(KERNEL_CONFIG): $(KERNEL_OUT) |
| 167 | $(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) |
| 168 | |
| 169 | $(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL) |
| 170 | $(hide) gunzip -c $(KERNEL_OUT)/arch/$(TARGET_ARCH)/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy |
| 171 | |
| 172 | TARGET_KERNEL_BINARIES: $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL) |
| 173 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) $(TARGET_PREBUILT_INT_KERNEL_TYPE) |
| 174 | -$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) dtbs |
| 175 | -$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) modules |
| 176 | -$(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) modules_install |
| 177 | $(mv-modules) |
| 178 | $(clean-module-folder) |
| 179 | |
| 180 | $(TARGET_KERNEL_MODULES): TARGET_KERNEL_BINARIES |
| 181 | |
| 182 | $(TARGET_PREBUILT_INT_KERNEL): $(TARGET_KERNEL_MODULES) |
| 183 | $(mv-modules) |
| 184 | $(clean-module-folder) |
| 185 | |
| 186 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 187 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE) headers_install |
| 188 | |
| 189 | endif # FULL_KERNEL_BUILD |
| 190 | |
| 191 | ## Install it |
| 192 | |
| 193 | ifeq ($(NEEDS_KERNEL_COPY),true) |
| 194 | file := $(INSTALLED_KERNEL_TARGET) |
| 195 | ALL_PREBUILT += $(file) |
| 196 | $(file) : $(KERNEL_BIN) | $(ACP) |
| 197 | $(transform-prebuilt-to-target) |
| 198 | |
| 199 | ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET) |
| 200 | endif |