blob: 3ee63c06058840614d3e33a82b6542ae2d5bdfc9 [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"
Sathish Ambley9d69ac32012-03-21 10:28:26 -070018DTS_NAME ?= $(MSM_ARCH)
19DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts)
20DTS_FILE = $(lastword $(subst /, ,$(1)))
21DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1))))
22ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1))))
neetid77a63c52012-01-20 16:39:17 -080023KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
neetid77a63c52012-01-20 16:39:17 -080024DTC = $(KERNEL_OUT)/scripts/dtc/dtc
25
26define append-dtb
Sathish Ambley9d69ac32012-03-21 10:28:26 -070027mkdir -p $(KERNEL_OUT)/arch/arm/boot;\
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
73 $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=arm CROSS_COMPILE=arm-eabi- modules_install
74 $(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