AndroidKernel.mk 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #Android makefile to build kernel as a part of Android Build
  2. PERL = perl
  3. KERNEL_TARGET := $(strip $(INSTALLED_KERNEL_TARGET))
  4. ifeq ($(KERNEL_TARGET),)
  5. INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
  6. endif
  7. ifeq ($(TARGET_PREBUILT_KERNEL),)
  8. KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
  9. KERNEL_CONFIG := $(KERNEL_OUT)/.config
  10. ifeq ($(TARGET_KERNEL_APPEND_DTB), true)
  11. TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb
  12. else
  13. TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
  14. endif
  15. KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
  16. KERNEL_MODULES_INSTALL := system
  17. KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
  18. KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image
  19. 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))
  20. 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))
  21. ifeq "$(KERNEL_USE_OF)" "y"
  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))))
  26. KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
  27. DTC = $(KERNEL_OUT)/scripts/dtc/dtc
  28. define append-dtb
  29. mkdir -p $(KERNEL_OUT)/arch/arm/boot;\
  30. $(foreach DTS_NAME, $(DTS_NAMES), \
  31. $(foreach d, $(DTS_FILES), \
  32. $(DTC) -p 1024 -O dtb -o $(call DTB_FILE,$(d)) $(d); \
  33. cat $(KERNEL_ZIMG) $(call DTB_FILE,$(d)) > $(call ZIMG_FILE,$(d));))
  34. endef
  35. else
  36. define append-dtb
  37. endef
  38. endif
  39. ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
  40. $(info Using uncompressed kernel)
  41. TARGET_PREBUILT_KERNEL := $(KERNEL_OUT)/piggy
  42. else
  43. TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
  44. endif
  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. define clean-module-folder
  54. mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
  55. if [ "$$mdpath" != "" ];then\
  56. mpath=`dirname $$mdpath`; rm -rf $$mpath;\
  57. fi
  58. endef
  59. $(KERNEL_OUT):
  60. mkdir -p $(KERNEL_OUT)
  61. $(KERNEL_CONFIG): $(KERNEL_OUT)
  62. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- $(KERNEL_DEFCONFIG)
  63. $(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
  64. $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
  65. $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
  66. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi-
  67. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- modules
  68. $(MAKE) -C kernel O=../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) INSTALL_MOD_STRIP=1 ARCH=arm CROSS_COMPILE=arm-linux-androideabi- modules_install
  69. $(mv-modules)
  70. $(clean-module-folder)
  71. $(append-dtb)
  72. $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
  73. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- headers_install
  74. kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
  75. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- tags
  76. kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
  77. env KCONFIG_NOTIMESTAMP=true \
  78. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- menuconfig
  79. env KCONFIG_NOTIMESTAMP=true \
  80. $(MAKE) -C kernel O=../$(KERNEL_OUT) ARCH=arm CROSS_COMPILE=arm-linux-androideabi- savedefconfig
  81. cp $(KERNEL_OUT)/defconfig kernel/arch/arm/configs/$(KERNEL_DEFCONFIG)
  82. endif