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 |
| 8 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage |
| 9 | KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 10 | KERNEL_MODULES_INSTALL := system |
| 11 | KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 12 | KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image |
| 13 | |
| 14 | MSM_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)) |
| 15 | 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)) |
| 16 | |
| 17 | ifeq "$(KERNEL_USE_OF)" "y" |
| 18 | KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage |
| 19 | DTB_FILE = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH).dtb |
Satya Durga Srinivasu Prabhala | b3ed5d5 | 2012-02-22 20:33:30 +0530 | [diff] [blame] | 20 | DTS_FILE = $(TOP)/kernel/arch/arm/boot/dts/$(MSM_ARCH).dts |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 21 | FULL_KERNEL = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH)-zImage |
| 22 | DTC = $(KERNEL_OUT)/scripts/dtc/dtc |
| 23 | |
| 24 | define append-dtb |
| 25 | md $(KERNEL_OUT)/arch/arm/boot;\ |
| 26 | $(DTC) -p 1024 -O dtb -o $(DTB_FILE) $(DTS_FILE);\ |
| 27 | cat $(KERNEL_ZIMG) $(DTB_FILE) > $(FULL_KERNEL) |
| 28 | endef |
| 29 | else |
| 30 | FULL_KERNEL = $(KERNEL_IMG) |
| 31 | |
| 32 | define append-dtb |
| 33 | endef |
| 34 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | |
| 36 | ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 37 | $(info Using uncompressed kernel) |
| 38 | TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy |
| 39 | else |
| 40 | TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL) |
| 41 | endif |
| 42 | |
| 43 | define mv-modules |
| 44 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 45 | if [ "$$mdpath" != "" ];then\ |
| 46 | mpath=`dirname $$mdpath`;\ |
| 47 | ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 48 | for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 49 | fi |
| 50 | endef |
| 51 | |
| 52 | define clean-module-folder |
| 53 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 54 | if [ "$$mdpath" != "" ];then\ |
| 55 | mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 56 | fi |
| 57 | endef |
| 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) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 74 | $(append-dtb) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | |
| 76 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 77 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install |
| 78 | |
| 79 | kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 80 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags |
| 81 | |
| 82 | kernelconfig: $(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 | |
| 89 | endif |