blob: 97aa85ddf1196448d21e938aa14569a1c53cec99 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001#Android makefile to build kernel as a part of Android Build
2
3ifeq ($(TARGET_PREBUILT_KERNEL),)
4
5KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
6KERNEL_CONFIG := $(KERNEL_OUT)/.config
7TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
8KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
9KERNEL_MODULES_INSTALL := system
10KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
neetid77a63c52012-01-20 16:39:17 -080011KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image
12
13MSM_ARCH ?= $(shell $(PERL) -e 'while (<>) {$$a = $$1 if /CONFIG_ARCH_((?:MSM|QSD)[a-zA-Z0-9]+)=y/; $$r = $$1 if /CONFIG_MSM_SOC_REV_(?!NONE)(\w+)=y/;} print lc("$$a$$r\n");' $(KERNEL_CONFIG))
14KERNEL_USE_OF ?= $(shell $(PERL) -e '$$of = "n"; while (<>) { if (/CONFIG_USE_OF=y/) { $$of = "y"; break; } } print $$of;' kernel/arch/arm/configs/$(KERNEL_DEFCONFIG))
15
16ifeq "$(KERNEL_USE_OF)" "y"
17KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
18DTB_FILE = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH).dtb
19DTS_FILE = $(KERNEL_OUT)/../../../../../../kernel/arch/arm/boot/dts/$(MSM_ARCH).dts
20FULL_KERNEL = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH)-zImage
21DTC = $(KERNEL_OUT)/scripts/dtc/dtc
22
23define append-dtb
24md $(KERNEL_OUT)/arch/arm/boot;\
25$(DTC) -p 1024 -O dtb -o $(DTB_FILE) $(DTS_FILE);\
26cat $(KERNEL_ZIMG) $(DTB_FILE) > $(FULL_KERNEL)
27endef
28else
29FULL_KERNEL = $(KERNEL_IMG)
30
31define append-dtb
32endef
33endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034
35ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
36$(info Using uncompressed kernel)
37TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy
38else
39TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
40endif
41
42define mv-modules
43mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
44if [ "$$mdpath" != "" ];then\
45mpath=`dirname $$mdpath`;\
46ko=`find $$mpath/kernel -type f -name *.ko`;\
47for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
48fi
49endef
50
51define clean-module-folder
52mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
53if [ "$$mdpath" != "" ];then\
54mpath=`dirname $$mdpath`; rm -rf $$mpath;\
55fi
56endef
57
58$(KERNEL_OUT):
59 mkdir -p $(KERNEL_OUT)
60
61$(KERNEL_CONFIG): $(KERNEL_OUT)
62 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- $(KERNEL_DEFCONFIG)
63
64$(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
65 $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
66
67$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
68 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi-
69 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- modules
70 $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=arm CROSS_COMPILE=arm-eabi- modules_install
71 $(mv-modules)
72 $(clean-module-folder)
neetid77a63c52012-01-20 16:39:17 -080073 $(append-dtb)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
75$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
76 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install
77
78kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
79 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags
80
81kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
82 env KCONFIG_NOTIMESTAMP=true \
83 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
84 env KCONFIG_NOTIMESTAMP=true \
85 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- savedefconfig
86 cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)
87
88endif