Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | #Android makefile to build kernel as a part of Android Build |
Neeti Desai | 334bbc6 | 2012-01-26 16:29:13 -0800 | [diff] [blame] | 2 | PERL = perl |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | |
| 4 | ifeq ($(TARGET_PREBUILT_KERNEL),) |
| 5 | |
| 6 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 7 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
Shashank Mittal | 9ee375e | 2013-07-15 17:46:32 -0700 | [diff] [blame] | 8 | ifeq ($(TARGET_KERNEL_APPEND_DTB), true) |
| 9 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb |
| 10 | else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 11 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage |
Shashank Mittal | 9ee375e | 2013-07-15 17:46:32 -0700 | [diff] [blame] | 12 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 13 | KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 14 | KERNEL_MODULES_INSTALL := system |
| 15 | KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 16 | KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image |
| 17 | |
Ravi Kumar V | a8d66cc | 2012-09-21 15:55:27 +0530 | [diff] [blame] | 18 | DTS_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)) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 19 | KERNEL_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 | |
| 21 | ifeq "$(KERNEL_USE_OF)" "y" |
Sathish Ambley | 9d69ac3 | 2012-03-21 10:28:26 -0700 | [diff] [blame] | 22 | DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts) |
| 23 | DTS_FILE = $(lastword $(subst /, ,$(1))) |
| 24 | DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1)))) |
| 25 | ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1)))) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 26 | KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 27 | DTC = $(KERNEL_OUT)/scripts/dtc/dtc |
| 28 | |
| 29 | define append-dtb |
Sathish Ambley | 9d69ac3 | 2012-03-21 10:28:26 -0700 | [diff] [blame] | 30 | mkdir -p $(KERNEL_OUT)/arch/arm/boot;\ |
David Ng | 6d8fe65 | 2012-09-17 16:35:24 -0700 | [diff] [blame] | 31 | $(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));)) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 35 | endef |
| 36 | else |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 37 | |
| 38 | define append-dtb |
| 39 | endef |
| 40 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | |
| 42 | ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 43 | $(info Using uncompressed kernel) |
| 44 | TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy |
| 45 | else |
| 46 | TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL) |
| 47 | endif |
| 48 | |
| 49 | define mv-modules |
| 50 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 51 | if [ "$$mdpath" != "" ];then\ |
| 52 | mpath=`dirname $$mdpath`;\ |
| 53 | ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 54 | for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 55 | fi |
| 56 | endef |
| 57 | |
| 58 | define clean-module-folder |
| 59 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 60 | if [ "$$mdpath" != "" ];then\ |
| 61 | mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 62 | fi |
| 63 | endef |
| 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 Telkar | bb77a75 | 2012-09-14 19:16:18 -0700 | [diff] [blame] | 77 | $(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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | $(mv-modules) |
| 79 | $(clean-module-folder) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 80 | $(append-dtb) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 81 | |
| 82 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 83 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install |
| 84 | |
| 85 | kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 86 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags |
| 87 | |
| 88 | kernelconfig: $(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 | |
| 95 | endif |