blob: 3684a3f400680d10b1514876b924cc8a0cc7159c [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
8TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
9KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
10KERNEL_MODULES_INSTALL := system
11KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
neetid77a63c52012-01-20 16:39:17 -080012KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image
13
Ravi Kumar Va8d66cc2012-09-21 15:55:27 +053014DTS_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 -080015KERNEL_USE_OF ?= $(shell $(PERL) -e '$$of = "n"; while (<>) { if (/CONFIG_USE_OF=y/) { $$of = "y"; break; } } print $$of;' kernel/arch/arm/configs/$(KERNEL_DEFCONFIG))
16
17ifeq "$(KERNEL_USE_OF)" "y"
Sathish Ambley9d69ac32012-03-21 10:28:26 -070018DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts)
19DTS_FILE = $(lastword $(subst /, ,$(1)))
20DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1))))
21ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1))))
neetid77a63c52012-01-20 16:39:17 -080022KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
neetid77a63c52012-01-20 16:39:17 -080023DTC = $(KERNEL_OUT)/scripts/dtc/dtc
24
25define append-dtb
Sathish Ambley9d69ac32012-03-21 10:28:26 -070026mkdir -p $(KERNEL_OUT)/arch/arm/boot;\
David Ng6d8fe652012-09-17 16:35:24 -070027$(foreach DTS_NAME, $(DTS_NAMES), \
28 $(foreach d, $(DTS_FILES), \
29 $(DTC) -p 1024 -O dtb -o $(call DTB_FILE,$(d)) $(d); \
30 cat $(KERNEL_ZIMG) $(call DTB_FILE,$(d)) > $(call ZIMG_FILE,$(d));))
neetid77a63c52012-01-20 16:39:17 -080031endef
32else
neetid77a63c52012-01-20 16:39:17 -080033
34define append-dtb
35endef
36endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
39$(info Using uncompressed kernel)
40TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy
41else
42TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
43endif
44
45define mv-modules
46mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
47if [ "$$mdpath" != "" ];then\
48mpath=`dirname $$mdpath`;\
49ko=`find $$mpath/kernel -type f -name *.ko`;\
50for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
51fi
52endef
53
54define clean-module-folder
55mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
56if [ "$$mdpath" != "" ];then\
57mpath=`dirname $$mdpath`; rm -rf $$mpath;\
58fi
59endef
60
61$(KERNEL_OUT):
62 mkdir -p $(KERNEL_OUT)
63
64$(KERNEL_CONFIG): $(KERNEL_OUT)
65 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- $(KERNEL_DEFCONFIG)
66
67$(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
68 $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
69
70$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
71 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi-
72 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- modules
Nagender Telkarbb77a752012-09-14 19:16:18 -070073 $(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 -070074 $(mv-modules)
75 $(clean-module-folder)
neetid77a63c52012-01-20 16:39:17 -080076 $(append-dtb)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077
78$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
79 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install
80
81kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
82 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags
83
84kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
85 env KCONFIG_NOTIMESTAMP=true \
86 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
87 env KCONFIG_NOTIMESTAMP=true \
88 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- savedefconfig
89 cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)
90
91endif