Makefile 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #
  2. # arch/arm64/Makefile
  3. #
  4. # This file is included by the global makefile so that you can add your own
  5. # architecture-specific flags and dependencies.
  6. #
  7. # This file is subject to the terms and conditions of the GNU General Public
  8. # License. See the file "COPYING" in the main directory of this archive
  9. # for more details.
  10. #
  11. # Copyright (C) 1995-2001 by Russell King
  12. LDFLAGS_vmlinux :=--no-undefined -X
  13. CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
  14. GZFLAGS :=-9
  15. ifeq ($(CONFIG_RELOCATABLE), y)
  16. # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
  17. # for relative relocs, since this leads to better Image compression
  18. # with the relocation offsets always being zero.
  19. LDFLAGS_vmlinux += -pie -shared -Bsymbolic \
  20. $(call ld-option, --no-apply-dynamic-relocs)
  21. endif
  22. ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
  23. ifeq ($(call ld-option, --fix-cortex-a53-843419),)
  24. $(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
  25. else
  26. ifeq ($(call gold-ifversion, -lt, 114000000, y), y)
  27. $(warning This version of GNU gold may generate incorrect code with --fix-cortex-a53-843419;\
  28. see https://sourceware.org/bugzilla/show_bug.cgi?id=21491)
  29. endif
  30. LDFLAGS_vmlinux += --fix-cortex-a53-843419
  31. endif
  32. else
  33. ifeq ($(ld-name),gold)
  34. # Pass --no-fix-cortex-a53-843419 to ensure the erratum fix is disabled
  35. LDFLAGS += --no-fix-cortex-a53-843419
  36. endif
  37. endif
  38. KBUILD_DEFCONFIG := defconfig
  39. # Check for binutils support for specific extensions
  40. lseinstr := $(call as-instr,.arch_extension lse,-DCONFIG_AS_LSE=1)
  41. ifeq ($(CONFIG_ARM64_LSE_ATOMICS), y)
  42. ifeq ($(lseinstr),)
  43. $(warning LSE atomics not supported by binutils)
  44. endif
  45. endif
  46. ifeq ($(CONFIG_COMPAT_VDSO), y)
  47. CROSS_COMPILE_ARM32 ?= $(CONFIG_CROSS_COMPILE_ARM32:"%"=%)
  48. # Check that the user has provided a valid prefix for the 32-bit toolchain.
  49. # To prevent selecting the system $(cc-name) by default, the prefix is not
  50. # allowed to be empty, unlike CROSS_COMPILE. In the unlikely event that the
  51. # system $(cc-name) is actually the 32-bit ARM compiler to be used, the
  52. # variable can be set to the dirname (e.g. CROSS_COMPILE_ARM32=/usr/bin/).
  53. # Note: this Makefile is read both before and after regenerating the config
  54. # (if needed). Any warning appearing before the config has been regenerated
  55. # should be ignored. If the error is triggered and you set
  56. # CONFIG_CROSS_COMPILE_ARM32, set CROSS_COMPILE_ARM32 to an appropriate value
  57. # when invoking make and fix CONFIG_CROSS_COMPILE_ARM32.
  58. ifeq ($(CROSS_COMPILE_ARM32),)
  59. $(error CROSS_COMPILE_ARM32 not defined or empty, the compat vDSO will not be built)
  60. else ifeq ($(cc-name),clang)
  61. export CLANG_TRIPLE_ARM32 ?= $(CROSS_COMPILE_ARM32)
  62. export CLANG_TARGET_ARM32 := --target=$(notdir $(CLANG_TRIPLE_ARM32:%-=%))
  63. export GCC_TOOLCHAIN32_DIR := $(dir $(shell which $(CROSS_COMPILE_ARM32)ld))
  64. export GCC_TOOLCHAIN32 := $(realpath $(GCC_TOOLCHAIN32_DIR)/..)
  65. export CLANG_PREFIX32 := --prefix=$(GCC_TOOLCHAIN32_DIR)
  66. export CLANG_GCC32_TC := --gcc-toolchain=$(GCC_TOOLCHAIN32)
  67. export CONFIG_VDSO32 := y
  68. vdso32 := -DCONFIG_VDSO32=1
  69. else ifeq ($(shell which $(CROSS_COMPILE_ARM32)$(cc-name) 2> /dev/null),)
  70. $(error $(CROSS_COMPILE_ARM32)$(cc-name) not found, check CROSS_COMPILE_ARM32)
  71. else
  72. export CROSS_COMPILE_ARM32
  73. export CONFIG_VDSO32 := y
  74. vdso32 := -DCONFIG_VDSO32=1
  75. endif
  76. endif
  77. ifeq ($(cc-name),clang)
  78. # This is a workaround for https://bugs.llvm.org/show_bug.cgi?id=30792.
  79. # TODO: revert when this is fixed in LLVM.
  80. KBUILD_CFLAGS += -mno-implicit-float
  81. else
  82. KBUILD_CFLAGS += -mgeneral-regs-only
  83. endif
  84. KBUILD_CFLAGS += $(lseinstr) $(vdso32)
  85. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  86. KBUILD_CFLAGS += $(call cc-option, -mpc-relative-literal-loads)
  87. KBUILD_CFLAGS += -fno-pic
  88. KBUILD_AFLAGS += $(lseinstr) $(vdso32)
  89. ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
  90. KBUILD_CFLAGS += -ffixed-x18
  91. endif
  92. ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
  93. KBUILD_CPPFLAGS += -mbig-endian
  94. AS += -EB
  95. LD += -EB
  96. UTS_MACHINE := aarch64_be
  97. else
  98. KBUILD_CPPFLAGS += -mlittle-endian
  99. AS += -EL
  100. LD += -EL
  101. UTS_MACHINE := aarch64
  102. endif
  103. CHECKFLAGS += -D__aarch64__
  104. ifeq ($(CONFIG_ARM64_MODULE_CMODEL_LARGE), y)
  105. KBUILD_CFLAGS_MODULE += -mcmodel=large
  106. ifeq ($(CONFIG_LTO_CLANG), y)
  107. # Code model is not stored in LLVM IR, so we need to pass it also to LLVMgold
  108. KBUILD_LDFLAGS_MODULE += -plugin-opt=-code-model=large
  109. endif
  110. endif
  111. ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
  112. KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm64/kernel/module.lds
  113. endif
  114. # Default value
  115. head-y := arch/arm64/kernel/head.o
  116. # The byte offset of the kernel image in RAM from the start of RAM.
  117. ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
  118. TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
  119. int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
  120. rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
  121. else
  122. TEXT_OFFSET := 0x00080000
  123. endif
  124. ifeq ($(cc-name),clang)
  125. KBUILD_CFLAGS += $(call cc-disable-warning, asm-operand-widths)
  126. endif
  127. # KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - 3)) - (1 << 61)
  128. # in 32-bit arithmetic
  129. KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \
  130. (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \
  131. + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - 3)) \
  132. - (1 << (64 - 32 - 3)) )) )
  133. export TEXT_OFFSET GZFLAGS
  134. core-y += arch/arm64/kernel/ arch/arm64/mm/
  135. core-$(CONFIG_NET) += arch/arm64/net/
  136. core-$(CONFIG_KVM) += arch/arm64/kvm/
  137. core-$(CONFIG_XEN) += arch/arm64/xen/
  138. core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
  139. libs-y := arch/arm64/lib/ $(libs-y)
  140. core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  141. suffix_$(CONFIG_KERNEL_GZIP) = gz
  142. suffix_$(CONFIG_KERNEL_LZ4) = lz4
  143. # Default target when executing plain make
  144. ifeq ($(CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE),y)
  145. KBUILD_IMAGE := Image.$(suffix_y)-dtb
  146. else
  147. KBUILD_IMAGE := Image.$(suffix_y)
  148. endif
  149. KBUILD_DTBS := dtbs
  150. KBUILD_DTBO_IMG := dtbo.img
  151. ifeq ($(CONFIG_BUILD_ARM64_DT_OVERLAY),y)
  152. export DTC_FLAGS := -@
  153. endif
  154. ifeq ($(CONFIG_BUILD_ARM64_APPLY_DTBO),y)
  155. KBUILD_APPLY_DTBO := apply_dtbo
  156. endif
  157. BUILD_DTC_PATH = $(subst $\",,$(CONFIG_BUILD_ARM64_DTC))
  158. ifneq ($(BUILD_DTC_PATH),)
  159. DTC = $(BUILD_DTC_PATH)
  160. endif
  161. BUILD_DTC_FLAGS = $(subst $\",,$(CONFIG_BUILD_ARM64_DTC_FLAGS))
  162. ifneq ($(BUILD_DTC_FLAGS),)
  163. DTC_FLAGS += $(BUILD_DTC_FLAGS)
  164. endif
  165. ifeq ($(CONFIG_BUILD_ARM64_DT_OVERLAY),y)
  166. all: $(KBUILD_IMAGE) $(KBUILD_DTBS) $(KBUILD_DTBO_IMG) $(KBUILD_APPLY_DTBO)
  167. else
  168. all: $(KBUILD_IMAGE) $(KBUILD_DTBS)
  169. endif
  170. boot := arch/arm64/boot
  171. Image: vmlinux
  172. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  173. Image.%: Image
  174. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  175. zinstall install:
  176. $(Q)$(MAKE) $(build)=$(boot) $@
  177. %.dtb: scripts
  178. $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
  179. PHONY += dtbs dtbs_install
  180. dtbs: prepare scripts
  181. $(Q)$(MAKE) $(build)=$(boot)/dts
  182. dtbs_install:
  183. $(Q)$(MAKE) $(dtbinst)=$(boot)/dts
  184. Image-dtb Image.gz-dtb Image.lz4-dtb: vmlinux scripts dtbs
  185. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  186. ifeq ($(CONFIG_BUILD_ARM64_DT_OVERLAY),y)
  187. ifeq ($(CONFIG_BOARD_B1C1),y)
  188. dtbo.img: $(boot)/dts/dtboimg.cfg dtbs
  189. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  190. else
  191. dtbo.img: $(boot)/dts/dtboimg-sdm670.cfg dtbs
  192. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  193. endif
  194. endif
  195. ifeq ($(CONFIG_BUILD_ARM64_DT_OVERLAY),y)
  196. PHONY += apply_dtbo
  197. dtboapply := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.dtboapply obj
  198. apply_dtbo: Image.lz4-dtb dtbo.img
  199. $(Q)$(MAKE) $(dtboapply)=$(boot) KERNEL_DTB=Image.lz4-dtb DTBO=dtbo.img
  200. endif
  201. PHONY += vdso_install
  202. vdso_install:
  203. $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
  204. # We use MRPROPER_FILES and CLEAN_FILES now
  205. archclean:
  206. $(Q)$(MAKE) $(clean)=$(boot)
  207. $(Q)$(MAKE) $(clean)=$(boot)/dts
  208. CLEAN_FILES += $(boot)/Image $(boot)/Image-dtb $(boot)/Image.* $(boot)/dtbo.img
  209. MRPROPER_FILES += $(boot)/Image $(boot)/Image-dtb $(boot)/Image.* $(boot)/dtbo.img
  210. # We need to generate vdso-offsets.h before compiling certain files in kernel/.
  211. # In order to do that, we should use the archprepare target, but we can't since
  212. # asm-offsets.h is included in some files used to generate vdso-offsets.h, and
  213. # asm-offsets.h is built in prepare0, for which archprepare is a dependency.
  214. # Therefore we need to generate the header after prepare0 has been made, hence
  215. # this hack.
  216. prepare: vdso_prepare
  217. vdso_prepare: prepare0
  218. $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
  219. $(if $(CONFIG_VDSO32),$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
  220. include/generated/vdso32-offsets.h)
  221. define archhelp
  222. echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
  223. echo '* Image.lz4 - Compressed kernel image (arch/$(ARCH)/boot/Image.lz4)'
  224. echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
  225. echo '* dtbs - Build device tree blobs for enabled boards'
  226. echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
  227. echo ' install - Install uncompressed kernel'
  228. echo ' zinstall - Install compressed kernel'
  229. echo ' Install using (your) ~/bin/installkernel or'
  230. echo ' (distribution) /sbin/installkernel or'
  231. echo ' install to $$(INSTALL_PATH) and run lilo'
  232. endef