blob: cc94b6935730e88737146e0dcb2518aacc1382fc [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
14MSM_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))
15KERNEL_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"
18KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
19DTB_FILE = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH).dtb
Satya Durga Srinivasu Prabhalab3ed5d52012-02-22 20:33:30 +053020DTS_FILE = $(TOP)/kernel/arch/arm/boot/dts/$(MSM_ARCH).dts
neetid77a63c52012-01-20 16:39:17 -080021FULL_KERNEL = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH)-zImage
22DTC = $(KERNEL_OUT)/scripts/dtc/dtc
23
24define append-dtb
25md $(KERNEL_OUT)/arch/arm/boot;\
26$(DTC) -p 1024 -O dtb -o $(DTB_FILE) $(DTS_FILE);\
27cat $(KERNEL_ZIMG) $(DTB_FILE) > $(FULL_KERNEL)
28endef
29else
30FULL_KERNEL = $(KERNEL_IMG)
31
32define append-dtb
33endef
34endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035
36ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
37$(info Using uncompressed kernel)
38TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy
39else
40TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
41endif
42
43define mv-modules
44mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
45if [ "$$mdpath" != "" ];then\
46mpath=`dirname $$mdpath`;\
47ko=`find $$mpath/kernel -type f -name *.ko`;\
48for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
49fi
50endef
51
52define clean-module-folder
53mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
54if [ "$$mdpath" != "" ];then\
55mpath=`dirname $$mdpath`; rm -rf $$mpath;\
56fi
57endef
58
59$(KERNEL_OUT):
60 mkdir -p $(KERNEL_OUT)
61
62$(KERNEL_CONFIG): $(KERNEL_OUT)
63 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- $(KERNEL_DEFCONFIG)
64
65$(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
66 $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
67
68$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
69 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi-
70 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- modules
71 $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=arm CROSS_COMPILE=arm-eabi- modules_install
72 $(mv-modules)
73 $(clean-module-folder)
neetid77a63c52012-01-20 16:39:17 -080074 $(append-dtb)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075
76$(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
77 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install
78
79kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
80 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags
81
82kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
83 env KCONFIG_NOTIMESTAMP=true \
84 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
85 env KCONFIG_NOTIMESTAMP=true \
86 $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- savedefconfig
87 cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)
88
89endif