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" |
Sathish Ambley | 9d69ac3 | 2012-03-21 10:28:26 -0700 | [diff] [blame] | 18 | DTS_NAME ?= $(MSM_ARCH) |
| 19 | DTS_FILES = $(wildcard $(TOP)/kernel/arch/arm/boot/dts/$(DTS_NAME)*.dts) |
| 20 | DTS_FILE = $(lastword $(subst /, ,$(1))) |
| 21 | DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1)))) |
| 22 | 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] | 23 | KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 24 | DTC = $(KERNEL_OUT)/scripts/dtc/dtc |
| 25 | |
| 26 | define append-dtb |
Sathish Ambley | 9d69ac3 | 2012-03-21 10:28:26 -0700 | [diff] [blame] | 27 | mkdir -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));) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 31 | endef |
| 32 | else |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 33 | |
| 34 | define append-dtb |
| 35 | endef |
| 36 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | |
| 38 | ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 39 | $(info Using uncompressed kernel) |
| 40 | TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy |
| 41 | else |
| 42 | TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL) |
| 43 | endif |
| 44 | |
| 45 | define mv-modules |
| 46 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 47 | if [ "$$mdpath" != "" ];then\ |
| 48 | mpath=`dirname $$mdpath`;\ |
| 49 | ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 50 | for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 51 | fi |
| 52 | endef |
| 53 | |
| 54 | define clean-module-folder |
| 55 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 56 | if [ "$$mdpath" != "" ];then\ |
| 57 | mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 58 | fi |
| 59 | endef |
| 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) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 76 | $(append-dtb) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | |
| 78 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 79 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install |
| 80 | |
| 81 | kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 82 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags |
| 83 | |
| 84 | kernelconfig: $(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 | |
| 91 | endif |