Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | #Android makefile to build kernel as a part of Android Build |
| 2 | |
| 3 | ifeq ($(TARGET_PREBUILT_KERNEL),) |
| 4 | |
| 5 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 6 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
| 7 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage |
| 8 | KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 9 | KERNEL_MODULES_INSTALL := system |
| 10 | KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 11 | KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image |
| 12 | |
| 13 | 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)) |
| 14 | 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)) |
| 15 | |
| 16 | ifeq "$(KERNEL_USE_OF)" "y" |
| 17 | KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage |
| 18 | DTB_FILE = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH).dtb |
| 19 | DTS_FILE = $(KERNEL_OUT)/../../../../../../kernel/arch/arm/boot/dts/$(MSM_ARCH).dts |
| 20 | FULL_KERNEL = $(KERNEL_OUT)/arch/arm/boot/$(MSM_ARCH)-zImage |
| 21 | DTC = $(KERNEL_OUT)/scripts/dtc/dtc |
| 22 | |
| 23 | define append-dtb |
| 24 | md $(KERNEL_OUT)/arch/arm/boot;\ |
| 25 | $(DTC) -p 1024 -O dtb -o $(DTB_FILE) $(DTS_FILE);\ |
| 26 | cat $(KERNEL_ZIMG) $(DTB_FILE) > $(FULL_KERNEL) |
| 27 | endef |
| 28 | else |
| 29 | FULL_KERNEL = $(KERNEL_IMG) |
| 30 | |
| 31 | define append-dtb |
| 32 | endef |
| 33 | endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | |
| 35 | ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true) |
| 36 | $(info Using uncompressed kernel) |
| 37 | TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy |
| 38 | else |
| 39 | TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL) |
| 40 | endif |
| 41 | |
| 42 | define mv-modules |
| 43 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 44 | if [ "$$mdpath" != "" ];then\ |
| 45 | mpath=`dirname $$mdpath`;\ |
| 46 | ko=`find $$mpath/kernel -type f -name *.ko`;\ |
| 47 | for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\ |
| 48 | fi |
| 49 | endef |
| 50 | |
| 51 | define clean-module-folder |
| 52 | mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\ |
| 53 | if [ "$$mdpath" != "" ];then\ |
| 54 | mpath=`dirname $$mdpath`; rm -rf $$mpath;\ |
| 55 | fi |
| 56 | endef |
| 57 | |
| 58 | $(KERNEL_OUT): |
| 59 | mkdir -p $(KERNEL_OUT) |
| 60 | |
| 61 | $(KERNEL_CONFIG): $(KERNEL_OUT) |
| 62 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- $(KERNEL_DEFCONFIG) |
| 63 | |
| 64 | $(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL) |
| 65 | $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy |
| 66 | |
| 67 | $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL) |
| 68 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- |
| 69 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- modules |
| 70 | $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) ARCH=arm CROSS_COMPILE=arm-eabi- modules_install |
| 71 | $(mv-modules) |
| 72 | $(clean-module-folder) |
neetid | 77a63c5 | 2012-01-20 16:39:17 -0800 | [diff] [blame] | 73 | $(append-dtb) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | |
| 75 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 76 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- headers_install |
| 77 | |
| 78 | kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 79 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- tags |
| 80 | |
| 81 | kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG) |
| 82 | env KCONFIG_NOTIMESTAMP=true \ |
| 83 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig |
| 84 | env KCONFIG_NOTIMESTAMP=true \ |
| 85 | $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-eabi- savedefconfig |
| 86 | cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG) |
| 87 | |
| 88 | endif |