kenv.mk 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Copyright (C) 2017 MediaTek Inc.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License version 2 as
  5. # published by the Free Software Foundation.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. # See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  11. KERNEL_ENV_PATH := $(call my-dir)
  12. KERNEL_ROOT_DIR := $(PWD)
  13. define touch-kernel-image-timestamp
  14. if [ -e $(1) ] && [ -e $(2) ] && cmp -s $(1) $(2); then \
  15. echo $(2) has no change;\
  16. mv -f $(1) $(2);\
  17. else \
  18. rm -f $(1);\
  19. fi
  20. endef
  21. define move-kernel-module-files
  22. v=`cat $(2)/include/config/kernel.release`;\
  23. for i in `grep -h '\.ko' /dev/null $(2)/.tmp_versions/*.mod`; do \
  24. o=`basename $$i`;\
  25. if [ -e $(1)/lib/modules/$$o ] && cmp -s $(1)/lib/modules/$$v/kernel/$$i $(1)/lib/modules/$$o; then \
  26. echo $(1)/lib/modules/$$o has no change;\
  27. else \
  28. echo Update $(1)/lib/modules/$$o;\
  29. mv -f $(1)/lib/modules/$$v/kernel/$$i $(1)/lib/modules/$$o;\
  30. fi;\
  31. done
  32. endef
  33. define clean-kernel-module-dirs
  34. rm -rf $(1)/lib/modules/$(if $(2),`cat $(2)/include/config/kernel.release`,*/)
  35. endef
  36. # '\\' in command is wrongly replaced to '\\\\' in kernel/out/arch/arm/boot/compressed/.piggy.xzkern.cmd
  37. define fixup-kernel-cmd-file
  38. if [ -e $(1) ]; then cp $(1) $(1).bak; sed -e 's/\\\\\\\\/\\\\/g' < $(1).bak > $(1); rm -f $(1).bak; fi
  39. endef
  40. ifneq ($(strip $(TARGET_NO_KERNEL)),true)
  41. KERNEL_DIR := $(KERNEL_ENV_PATH)
  42. mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
  43. current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
  44. ifeq ($(KERNEL_TARGET_ARCH),arm64)
  45. ifeq ($(strip $(TARGET_KERNEL_USE_CLANG)),true)
  46. include $(current_dir)/build.config.mtk.aarch64
  47. else
  48. include $(current_dir)/build.config.mtk.aarch64.gcc
  49. endif
  50. else
  51. ifeq ($(strip $(TARGET_KERNEL_USE_CLANG)),true)
  52. include $(current_dir)/build.config.mtk.arm
  53. else
  54. $(error TARGET_KERNEL_USE_CLANG is not set)
  55. endif
  56. endif
  57. ARGS := CROSS_COMPILE=$(CROSS_COMPILE)
  58. ifneq ($(CLANG_TRIPLE),)
  59. ARGS += CLANG_TRIPLE=$(CLANG_TRIPLE)
  60. endif
  61. ifneq ($(LD),)
  62. ARGS += LD=$(LD)
  63. endif
  64. ifneq ($(LD_LIBRARY_PATH),)
  65. ARGS += LD_LIBRARY_PATH=$(KERNEL_ROOT_DIR)/$(LD_LIBRARY_PATH)
  66. endif
  67. ifneq ($(NM),)
  68. ARGS += NM=$(NM)
  69. endif
  70. ifneq ($(OBJCOPY),)
  71. ARGS += OBJCOPY=$(OBJCOPY)
  72. endif
  73. ifeq ("$(CC)", "gcc")
  74. CC :=
  75. endif
  76. ifneq ($(filter-out false,$(USE_CCACHE)),)
  77. CCACHE_EXEC ?= /usr/bin/ccache
  78. CCACHE_EXEC := $(abspath $(wildcard $(CCACHE_EXEC)))
  79. else
  80. CCACHE_EXEC :=
  81. endif
  82. ifneq ($(CCACHE_EXEC),)
  83. ifneq ($(CC),)
  84. ARGS += CCACHE_CPP2=yes CC='$(CCACHE_EXEC) $(CC)'
  85. endif
  86. else
  87. ifneq ($(CC),)
  88. ARGS += CC=$(CC)
  89. endif
  90. endif
  91. TARGET_KERNEL_CROSS_COMPILE := $(KERNEL_ROOT_DIR)/$(LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN)/$(CROSS_COMPILE)
  92. ifeq ($(wildcard $(TARGET_PREBUILT_KERNEL)),)
  93. KERNEL_OUT ?= $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
  94. KERNEL_ROOT_OUT := $(if $(filter /% ~%,$(KERNEL_OUT)),,$(KERNEL_ROOT_DIR)/)$(KERNEL_OUT)
  95. ifeq ($(KERNEL_TARGET_ARCH), arm64)
  96. ifeq ($(MTK_APPENDED_DTB_SUPPORT), yes)
  97. KERNEL_ZIMAGE_OUT := $(KERNEL_OUT)/arch/$(KERNEL_TARGET_ARCH)/boot/Image.gz-dtb
  98. else
  99. KERNEL_ZIMAGE_OUT := $(KERNEL_OUT)/arch/$(KERNEL_TARGET_ARCH)/boot/Image.gz
  100. endif
  101. else
  102. ifeq ($(MTK_APPENDED_DTB_SUPPORT), yes)
  103. KERNEL_ZIMAGE_OUT := $(KERNEL_OUT)/arch/$(KERNEL_TARGET_ARCH)/boot/zImage-dtb
  104. else
  105. KERNEL_ZIMAGE_OUT := $(KERNEL_OUT)/arch/$(KERNEL_TARGET_ARCH)/boot/zImage
  106. endif
  107. endif
  108. BUILT_KERNEL_TARGET := $(KERNEL_ZIMAGE_OUT).bin
  109. INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
  110. INSTALLED_DTB_OVERLAY_TARGET := $(PRODUCT_OUT)/odmdtbo.img
  111. BUILT_DTB_OVERLAY_TARGET := $(KERNEL_OUT)/arch/$(KERNEL_TARGET_ARCH)/boot/dts/odmdtbo.img
  112. TARGET_KERNEL_CONFIG := $(KERNEL_OUT)/.config
  113. KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
  114. KERNEL_CONFIG_FILE := $(KERNEL_DIR)/arch/$(KERNEL_TARGET_ARCH)/configs/$(word 1,$(KERNEL_DEFCONFIG))
  115. #KERNEL_CONFIG_MODULES := $(shell grep ^CONFIG_MODULES=y $(KERNEL_CONFIG_FILE))
  116. #KERNEL_MODULES_OUT := $(if $(filter /% ~%,$(TARGET_OUT)),,$(KERNEL_ROOT_DIR)/)$(TARGET_OUT)
  117. #KERNEL_MODULES_DEPS := $(if $(wildcard $(KERNEL_MODULES_OUT)/lib/modules/*.ko),$(wildcard $(KERNEL_MODULES_OUT)/lib/modules/*.ko),$(KERNEL_MODULES_OUT)/lib/modules)
  118. #KERNEL_MODULES_SYMBOLS_OUT := $(if $(filter /% ~%,$(TARGET_OUT_UNSTRIPPED)),,$(KERNEL_ROOT_DIR)/)$(TARGET_OUT_UNSTRIPPED)/system
  119. KERNEL_MAKE_OPTION := O=$(KERNEL_ROOT_OUT) ARCH=$(KERNEL_TARGET_ARCH) $(ARGS) ROOTDIR=$(KERNEL_ROOT_DIR)
  120. KERNEL_MAKE_PATH_OPTION := /usr/bin:/bin
  121. KERNEL_MAKE_OPTION += PATH=$(KERNEL_ROOT_DIR)/$(CLANG_PREBUILT_BIN):$(KERNEL_ROOT_DIR)/$(LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN):$(KERNEL_MAKE_PATH_OPTION):$$PATH
  122. ifdef MTK_DTBO_FEATURE
  123. KERNEL_MAKE_OPTION += MTK_DTBO_FEATURE=$(MTK_DTBO_FEATURE)
  124. endif
  125. else
  126. BUILT_KERNEL_TARGET := $(TARGET_PREBUILT_KERNEL)
  127. endif#TARGET_PREBUILT_KERNEL is empty
  128. KERNEL_MAKE_OPTION += PROJECT_DTB_NAMES='$(PROJECT_DTB_NAMES)'
  129. endif#TARGET_NO_KERNEL