blob: d97d3c3c9cb498946bd87ac181e0bb4cc19da209 [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
4ifeq ($(TARGET_PREBUILT_KERNEL),)
5
6KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
7KERNEL_CONFIG := $(KERNEL_OUT)/.config
Shashank Mittal9ee375e2013-07-15 17:46:32 -07008ifeq ($(TARGET_KERNEL_APPEND_DTB), true)
9TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb
10else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070011TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
Shashank Mittal9ee375e2013-07-15 17:46:32 -070012endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070013KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
14KERNEL_MODULES_INSTALL := system
15KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
neetid77a63c52012-01-20 16:39:17 -080016KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image
17
Ravi Kumar Va8d66cc2012-09-21 15:55:27 +053018DTS_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 -080019KERNEL_USE_OF ?= $(shell $(PERL) -e '$$of = "n"; while (<>) { if (/CONFIG_USE_OF=y/) { $$of = "y"; break; } } print $$of;' kernel/arch/arm/configs/$(KERNEL_DEFCONFIG))
20
21ifeq "$(KERNEL_USE_OF)" "y"
Sathish Ambley9d69ac32012-03-21 10:28:26 -070022DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts)
23DTS_FILE = $(lastword $(subst /, ,$(1)))
24DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1))))
25ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1))))
neetid77a63c52012-01-20 16:39:17 -080026KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
neetid77a63c52012-01-20 16:39:17 -080027DTC = $(KERNEL_OUT)/scripts/dtc/dtc
28
29define append-dtb
Sathish Ambley9d69ac32012-03-21 10:28:26 -070030mkdir -p $(KERNEL_OUT)/arch/arm/boot;\
David Ng6d8fe652012-09-17 16:35:24 -070031$(foreach DTS_NAME, $(DTS_NAMES), \
32 $(foreach d, $(DTS_FILES), \
33 $(DTC) -p 1024 -O dtb -o $(call DTB_FILE,$(d)) $(d); \
34 cat $(KERNEL_ZIMG) $(call DTB_FILE,$(d)) > $(call ZIMG_FILE,$(d));))
neetid77a63c52012-01-20 16:39:17 -080035endef
36else
neetid77a63c52012-01-20 16:39:17 -080037
38define append-dtb
39endef
40endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041
42ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
43$(info Using uncompressed kernel)
44TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy
45else
46TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
47endif
48
49define mv-modules
50mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
51if [ "$$mdpath" != "" ];then\
52mpath=`dirname $$mdpath`;\
53ko=`find $$mpath/kernel -type f -name *.ko`;\
54for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
55fi
56endef
57
58define clean-module-folder
59mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
60if [ "$$mdpath" != "" ];then\
61mpath=`dirname $$mdpath`; rm -rf $$mpath;\
62fi
63endef
64
65$(KERNEL_OUT):
66 mkdir -p $(KERNEL_OUT)
67
68$(KERNEL_CONFIG): $(KERNEL_OUT)
69 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- $(KERNEL_DEFCONFIG)
70
71$(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
72 $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
73
74$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
75 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi-
76 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- modules
Nagender Telkarbb77a752012-09-14 19:16:18 -070077 $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) INSTALL_MOD_STRIP=1 ARCH=arm CROSS_COMPILE=arm-eabi- modules_install
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078 $(mv-modules)
79 $(clean-module-folder)
neetid77a63c52012-01-20 16:39:17 -080080 $(append-dtb)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081
82$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
83 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install
84
85kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
86 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags
87
88kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
89 env KCONFIG_NOTIMESTAMP=true \
90 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
91 env KCONFIG_NOTIMESTAMP=true \
92 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- savedefconfig
93 cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)
94
95endif