blob: 5d45883c642e2de78f0cd17b6b416a9387a29599 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001#Android makefile to build kernel as a part of Android Build
Neeti Desai334bbc62012-01-26 16:29:13 -08002PERL = perl
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003
Sridhar Gujjef2bed4e2014-07-07 14:25:22 +05304KERNEL_TARGET := $(strip $(INSTALLED_KERNEL_TARGET))
5ifeq ($(KERNEL_TARGET),)
6INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
7endif
8
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009ifeq ($(TARGET_PREBUILT_KERNEL),)
10
11KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
12KERNEL_CONFIG := $(KERNEL_OUT)/.config
Shashank Mittal9ee375e2013-07-15 17:46:32 -070013ifeq ($(TARGET_KERNEL_APPEND_DTB), true)
14TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb
15else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070016TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
Shashank Mittal9ee375e2013-07-15 17:46:32 -070017endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
19KERNEL_MODULES_INSTALL := system
20KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
neetid77a63c52012-01-20 16:39:17 -080021KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image
22
Ravi Kumar Va8d66cc2012-09-21 15:55:27 +053023DTS_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))
neetid77a63c52012-01-20 16:39:17 -080024KERNEL_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
26ifeq "$(KERNEL_USE_OF)" "y"
Sathish Ambley9d69ac32012-03-21 10:28:26 -070027DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts)
28DTS_FILE = $(lastword $(subst /, ,$(1)))
29DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1))))
30ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1))))
neetid77a63c52012-01-20 16:39:17 -080031KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
neetid77a63c52012-01-20 16:39:17 -080032DTC = $(KERNEL_OUT)/scripts/dtc/dtc
33
34define append-dtb
Sathish Ambley9d69ac32012-03-21 10:28:26 -070035mkdir -p $(KERNEL_OUT)/arch/arm/boot;\
David Ng6d8fe652012-09-17 16:35:24 -070036$(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));))
neetid77a63c52012-01-20 16:39:17 -080040endef
41else
neetid77a63c52012-01-20 16:39:17 -080042
43define append-dtb
44endef
45endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046
47ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
48$(info Using uncompressed kernel)
49TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy
50else
51TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
52endif
53
54define mv-modules
55mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
56if [ "$$mdpath" != "" ];then\
57mpath=`dirname $$mdpath`;\
58ko=`find $$mpath/kernel -type f -name *.ko`;\
59for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
60fi
61endef
62
63define clean-module-folder
64mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
65if [ "$$mdpath" != "" ];then\
66mpath=`dirname $$mdpath`; rm -rf $$mpath;\
67fi
68endef
69
70$(KERNEL_OUT):
71 mkdir -p $(KERNEL_OUT)
72
73$(KERNEL_CONFIG): $(KERNEL_OUT)
Samir Mehta1ec0b652015-09-15 17:09:55 +053074 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- $(KERNEL_DEFCONFIG)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075
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 Mehta1ec0b652015-09-15 17:09:55 +053080 $(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 Huntsman3f2bc4d2011-08-16 17:27:22 -070083 $(mv-modules)
84 $(clean-module-folder)
neetid77a63c52012-01-20 16:39:17 -080085 $(append-dtb)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086
87$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
Samir Mehta1ec0b652015-09-15 17:09:55 +053088 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- headers_install
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089
90kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
Samir Mehta1ec0b652015-09-15 17:09:55 +053091 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- tags
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092
93kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
94 env KCONFIG_NOTIMESTAMP=true \
Samir Mehta1ec0b652015-09-15 17:09:55 +053095 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- menuconfig
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096 env KCONFIG_NOTIMESTAMP=true \
Samir Mehta1ec0b652015-09-15 17:09:55 +053097 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- savedefconfig
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)
99
100endif