AndroidKernel.mk 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #Android makefile to build kernel as a part of Android Build
  2. KERNEL_TARGET := $(strip $(INSTALLED_KERNEL_TARGET))
  3. ifeq ($(KERNEL_TARGET),)
  4. INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
  5. endif
  6. ifeq ($(TARGET_PREBUILT_KERNEL),)
  7. KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
  8. KERNEL_CONFIG := $(KERNEL_OUT)/.config
  9. ifeq ($(TARGET_KERNEL_APPEND_DTB), true)
  10. TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb
  11. else
  12. TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
  13. endif
  14. KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
  15. KERNEL_MODULES_INSTALL := system
  16. KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules
  17. KERNEL_IMG=$(KERNEL_OUT)/arch/arm/boot/Image
  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))
  19. #KERNEL_USE_OF ?= $(shell $(PERL) -e '$$of = "n"; while (<>) { if (/CONFIG_USE_OF=y/) { $$of = "y"; break; } } print $$of;' $(TARGET_KERNEL_SOURCE)/arch/arm/configs/$(KERNEL_DEFCONFIG))
  20. #ifeq "$(KERNEL_USE_OF)" "y"
  21. DTS_FILES = $(wildcard $(TOP)/$(TARGET_KERNEL_SOURCE)/arch/arm/boot/dts/$(DTS_NAME)*.dts)
  22. DTS_FILE = $(lastword $(subst /, ,$(1)))
  23. DTB_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%.dtb,$(call DTS_FILE,$(1))))
  24. ZIMG_FILE = $(addprefix $(KERNEL_OUT)/arch/arm/boot/,$(patsubst %.dts,%-zImage,$(call DTS_FILE,$(1))))
  25. KERNEL_ZIMG = $(KERNEL_OUT)/arch/arm/boot/zImage
  26. DTC = $(KERNEL_OUT)/scripts/dtc/dtc
  27. define append-dtb
  28. mkdir -p $(KERNEL_OUT)/arch/arm/boot;\
  29. $(foreach DTS_NAME, $(DTS_NAMES), \
  30. $(foreach d, $(DTS_FILES), \
  31. $(DTC) -p 1024 -O dtb -o $(call DTB_FILE,$(d)) $(d); \
  32. cat $(KERNEL_ZIMG) $(call DTB_FILE,$(d)) > $(call ZIMG_FILE,$(d));))
  33. endef
  34. else
  35. define append-dtb
  36. endef
  37. endif
  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. define mv-modules
  45. mdpath=`find $(KERNEL_MODULES_OUT) -type f -name modules.dep`;\
  46. if [ "$$mdpath" != "" ];then\
  47. mpath=`dirname $$mdpath`;\
  48. ko=`find $$mpath/kernel -type f -name *.ko`;\
  49. for i in $$ko; do mv $$i $(KERNEL_MODULES_OUT)/; done;\
  50. fi
  51. endef
  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. TARGET_KERNEL_CLANG_PATH ?= $(BUILD_TOP)/prebuilts/clang/host/$(HOST_OS)-x86/$(KERNEL_CLANG_VERSION)
  59. PATH_OVERRIDE := PATH=$(TARGET_KERNEL_CLANG_PATH)/bin:$$PATH LD_LIBRARY_PATH=$(TARGET_KERNEL_CLANG_PATH)/lib64:$$LD_LIBRARY_PATH
  60. PATH_OVERRIDE += PATH=$(KERNEL_TOOLCHAIN_PATH_gcc)/bin:$$PATH
  61. # System tools are no longer allowed on 10+
  62. PATH_OVERRIDE += $(TOOLS_PATH_OVERRIDE)
  63. $(KERNEL_OUT):
  64. mkdir -p $(KERNEL_OUT)
  65. $(KERNEL_CONFIG): $(KERNEL_OUT)
  66. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) $(KERNEL_DEFCONFIG)
  67. $(KERNEL_OUT)/piggy : $(TARGET_PREBUILT_INT_KERNEL)
  68. $(hide) gunzip -c $(KERNEL_OUT)/arch/arm/boot/compressed/piggy.gzip > $(KERNEL_OUT)/piggy
  69. $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_OUT) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL)
  70. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD)
  71. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) modules
  72. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) INSTALL_MOD_STRIP=1 ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) modules_install
  73. $(mv-modules)
  74. $(clean-module-folder)
  75. $(append-dtb)
  76. $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT) $(KERNEL_CONFIG)
  77. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) headers_install
  78. .PHONY: kerneltags
  79. kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
  80. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) tags
  81. .PHONY: kernelconfig
  82. kernelconfig: $(KERNEL_OUT) $(KERNEL_CONFIG)
  83. env KCONFIG_NOTIMESTAMP=true \
  84. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) menuconfig
  85. env KCONFIG_NOTIMESTAMP=true \
  86. $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=../../$(KERNEL_OUT) ARCH=arm $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_LD) savedefconfig
  87. cp $(KERNEL_OUT)/defconfig $(TARGET_KERNEL_SOURCE)/arch/arm/configs/$(KERNEL_DEFCONFIG)
  88. #endif