Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | #Android makefile to build kernel as a part of Android Build |
Neeti Desai | 334bbc6 | 2012-01-26 16:29:13 -0800 | [diff] [blame] | 2 | PERL = perl |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | |
Sridhar Gujje | f2bed4e | 2014-07-07 14:25:22 +0530 | [diff] [blame] | 4 | KERNEL_TARGET := $(strip $(INSTALLED_KERNEL_TARGET)) |
| 5 | ifeq ($(KERNEL_TARGET),) |
| 6 | INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel |
| 7 | endif |
| 8 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9 | ifeq ($(TARGET_PREBUILT_KERNEL),) |
| 10 | |
| 11 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 12 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
Shashank Mittal | 9ee375e | 2013-07-15 17:46:32 -0700 | [diff] [blame] | 13 | ifeq ($(TARGET_KERNEL_APPEND_DTB), true) |
| 14 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb |
| 15 | else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 16 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage |
Shashank Mittal | 9ee375e | 2013-07-15 17:46:32 -0700 | [diff] [blame] | 17 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 19 | KERNEL_MODULES_INSTALL := system |
| 20 | KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 21 | KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image |
| 22 | |
Ravi Kumar V | a8d66cc | 2012-09-21 15:55:27 +0530 | [diff] [blame] | 23 | DTS_NAMES ?= $(shell $(PERL) -e 'while (<>) {$$a = $$1 if /CONFIG_ARCH_((?:MSM|QSD|MPQ)[a-zA-Z0-9]+)=y/; $$r = $$1 if /CONFIG_MSM_SOC_REV_(?!NONE)(\w+)=y/; $$arch = $$arch.lc("$$a$$r ") if /CONFIG_ARCH_((?:MSM|QSD|MPQ)[a-zA-Z0-9]+)=y/} print $$arch;' $(KERNEL_CONFIG)) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 24 | KERNEL_USE_OF ?= $(shell $(PERL) -e '$$of = "n"; while (<>) { if (/CONFIG_USE_OF=y/) { $$of = "y"; break; } } print $$of;' kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)) |
| 25 | |
| 26 | ifeq "$(KERNEL_USE_OF)" "y" |
Sathish Ambley | 9d69ac3 | 2012-03-21 10:28:26 -0700 | [diff] [blame] | 27 | DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts) |
| 28 | DTS_FILE = $(lastword $(subst /, ,$(1))) |
| 29 | DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1)))) |
| 30 | ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1)))) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 31 | KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 32 | DTC = $(KERNEL_OUT)/scripts/dtc/dtc |
| 33 | |
| 34 | define append-dtb |
Sathish Ambley | 9d69ac3 | 2012-03-21 10:28:26 -0700 | [diff] [blame] | 35 | mkdir -p $(KERNEL_OUT)/arch/arm/boot;\ |
David Ng | 6d8fe65 | 2012-09-17 16:35:24 -0700 | [diff] [blame] | 36 | $(foreach DTS_NAME, $(DTS_NAMES), \ |
| 37 | $(foreach d, $(DTS_FILES), \ |
| 38 | $(DTC) -p 1024 -O dtb -o $(call DTB_FILE,$(d)) $(d); \ |
| 39 | cat $(KERNEL_ZIMG) $(call DTB_FILE,$(d)) > $(call ZIMG_FILE,$(d));)) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 40 | endef |
| 41 | else |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 42 | |
| 43 | define append-dtb |
| 44 | endef |
| 45 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | |
| 47 | ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 48 | $(info Using uncompressed kernel) |
| 49 | TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy |
| 50 | else |
| 51 | TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL) |
| 52 | endif |
| 53 | |
| 54 | define mv-modules |
| 55 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 56 | if [ "$$mdpath" != "" ];then\ |
| 57 | mpath=`dirname $$mdpath`;\ |
| 58 | ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 59 | for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 60 | fi |
| 61 | endef |
| 62 | |
| 63 | define clean-module-folder |
| 64 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 65 | if [ "$$mdpath" != "" ];then\ |
| 66 | mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 67 | fi |
| 68 | endef |
| 69 | |
| 70 | $(KERNEL_OUT): |
| 71 | mkdir -p $(KERNEL_OUT) |
| 72 | |
| 73 | $(KERNEL_CONFIG): $(KERNEL_OUT) |
Samir Mehta | 1ec0b65 | 2015-09-15 17:09:55 +0530 | [diff] [blame] | 74 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- $(KERNEL_DEFCONFIG) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | |
| 76 | $(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL) |
| 77 | $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy |
| 78 | |
| 79 | $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL) |
Samir Mehta | 1ec0b65 | 2015-09-15 17:09:55 +0530 | [diff] [blame] | 80 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- |
| 81 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- modules |
| 82 | $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) INSTALL_MOD_STRIP=1 ARCH=arm CROSS_COMPILE=arm-linux-androideabi- modules_install |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 83 | $(mv-modules) |
| 84 | $(clean-module-folder) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 85 | $(append-dtb) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 86 | |
| 87 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
Samir Mehta | 1ec0b65 | 2015-09-15 17:09:55 +0530 | [diff] [blame] | 88 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- headers_install |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 89 | |
| 90 | kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG) |
Samir Mehta | 1ec0b65 | 2015-09-15 17:09:55 +0530 | [diff] [blame] | 91 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- tags |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 92 | |
| 93 | kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 94 | env KCONFIG_NOTIMESTAMP=true \ |
Samir Mehta | 1ec0b65 | 2015-09-15 17:09:55 +0530 | [diff] [blame] | 95 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- menuconfig |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 96 | env KCONFIG_NOTIMESTAMP=true \ |
Samir Mehta | 1ec0b65 | 2015-09-15 17:09:55 +0530 | [diff] [blame] | 97 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- savedefconfig |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG) |
| 99 | |
| 100 | endif |