18c2ecf20Sopenharmony_ci#
28c2ecf20Sopenharmony_ci# arch/arm64/Makefile
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# This file is included by the global makefile so that you can add your own
58c2ecf20Sopenharmony_ci# architecture-specific flags and dependencies.
68c2ecf20Sopenharmony_ci#
78c2ecf20Sopenharmony_ci# This file is subject to the terms and conditions of the GNU General Public
88c2ecf20Sopenharmony_ci# License.  See the file "COPYING" in the main directory of this archive
98c2ecf20Sopenharmony_ci# for more details.
108c2ecf20Sopenharmony_ci#
118c2ecf20Sopenharmony_ci# Copyright (C) 1995-2001 by Russell King
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciLDFLAGS_vmlinux	:=--no-undefined -X
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciifeq ($(CONFIG_RELOCATABLE), y)
168c2ecf20Sopenharmony_ci# Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
178c2ecf20Sopenharmony_ci# for relative relocs, since this leads to better Image compression
188c2ecf20Sopenharmony_ci# with the relocation offsets always being zero.
198c2ecf20Sopenharmony_ciLDFLAGS_vmlinux		+= -shared -Bsymbolic -z notext \
208c2ecf20Sopenharmony_ci			$(call ld-option, --no-apply-dynamic-relocs)
218c2ecf20Sopenharmony_ciendif
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
248c2ecf20Sopenharmony_ci  ifeq ($(call ld-option, --fix-cortex-a53-843419),)
258c2ecf20Sopenharmony_ci$(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
268c2ecf20Sopenharmony_ci  else
278c2ecf20Sopenharmony_ciLDFLAGS_vmlinux	+= --fix-cortex-a53-843419
288c2ecf20Sopenharmony_ci  endif
298c2ecf20Sopenharmony_ciendif
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y)
328c2ecf20Sopenharmony_ci  ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y)
338c2ecf20Sopenharmony_ci$(warning LSE atomics not supported by binutils)
348c2ecf20Sopenharmony_ci  endif
358c2ecf20Sopenharmony_ciendif
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cicc_has_k_constraint := $(call try-run,echo				\
388c2ecf20Sopenharmony_ci	'int main(void) {						\
398c2ecf20Sopenharmony_ci		asm volatile("and w0, w0, %w0" :: "K" (4294967295));	\
408c2ecf20Sopenharmony_ci		return 0;						\
418c2ecf20Sopenharmony_ci	}' | $(CC) -S -x c -o "$$TMP" -,,-DCONFIG_CC_HAS_K_CONSTRAINT=1)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciifeq ($(CONFIG_BROKEN_GAS_INST),y)
448c2ecf20Sopenharmony_ci$(warning Detected assembler with broken .inst; disassembly will be unreliable)
458c2ecf20Sopenharmony_ciendif
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciKBUILD_CFLAGS	+= -mgeneral-regs-only	\
488c2ecf20Sopenharmony_ci		   $(compat_vdso) $(cc_has_k_constraint)
498c2ecf20Sopenharmony_ciKBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
508c2ecf20Sopenharmony_ciKBUILD_AFLAGS	+= $(compat_vdso)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciKBUILD_CFLAGS	+= $(call cc-option,-mabi=lp64)
538c2ecf20Sopenharmony_ciKBUILD_AFLAGS	+= $(call cc-option,-mabi=lp64)
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci# Avoid generating .eh_frame* sections.
568c2ecf20Sopenharmony_ciKBUILD_CFLAGS	+= -fno-asynchronous-unwind-tables -fno-unwind-tables
578c2ecf20Sopenharmony_ciKBUILD_AFLAGS	+= -fno-asynchronous-unwind-tables -fno-unwind-tables
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
608c2ecf20Sopenharmony_ciprepare: stack_protector_prepare
618c2ecf20Sopenharmony_cistack_protector_prepare: prepare0
628c2ecf20Sopenharmony_ci	$(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg		  \
638c2ecf20Sopenharmony_ci				-mstack-protector-guard-reg=sp_el0	  \
648c2ecf20Sopenharmony_ci				-mstack-protector-guard-offset=$(shell	  \
658c2ecf20Sopenharmony_ci			awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
668c2ecf20Sopenharmony_ci					include/generated/asm-offsets.h))
678c2ecf20Sopenharmony_ciendif
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci# Ensure that if the compiler supports branch protection we default it
708c2ecf20Sopenharmony_ci# off, this will be overridden if we are using branch protection.
718c2ecf20Sopenharmony_cibranch-prot-flags-y += $(call cc-option,-mbranch-protection=none)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciifeq ($(CONFIG_ARM64_PTR_AUTH),y)
748c2ecf20Sopenharmony_cibranch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all
758c2ecf20Sopenharmony_ci# We enable additional protection for leaf functions as there is some
768c2ecf20Sopenharmony_ci# narrow potential for ROP protection benefits and no substantial
778c2ecf20Sopenharmony_ci# performance impact has been observed.
788c2ecf20Sopenharmony_ciifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
798c2ecf20Sopenharmony_cibranch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET_BTI) := -mbranch-protection=pac-ret+leaf+bti
808c2ecf20Sopenharmony_cielse
818c2ecf20Sopenharmony_cibranch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pac-ret+leaf
828c2ecf20Sopenharmony_ciendif
838c2ecf20Sopenharmony_ci# -march=armv8.3-a enables the non-nops instructions for PAC, to avoid the
848c2ecf20Sopenharmony_ci# compiler to generate them and consequently to break the single image contract
858c2ecf20Sopenharmony_ci# we pass it only to the assembler. This option is utilized only in case of non
868c2ecf20Sopenharmony_ci# integrated assemblers.
878c2ecf20Sopenharmony_ciifeq ($(CONFIG_AS_HAS_PAC), y)
888c2ecf20Sopenharmony_ciasm-arch := armv8.3-a
898c2ecf20Sopenharmony_ciendif
908c2ecf20Sopenharmony_ciendif
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciKBUILD_CFLAGS += $(branch-prot-flags-y)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
958c2ecf20Sopenharmony_ci# make sure to pass the newest target architecture to -march.
968c2ecf20Sopenharmony_ciasm-arch := armv8.4-a
978c2ecf20Sopenharmony_ciendif
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciifdef asm-arch
1008c2ecf20Sopenharmony_ciKBUILD_CFLAGS	+= -Wa,-march=$(asm-arch) \
1018c2ecf20Sopenharmony_ci		   -DARM64_ASM_ARCH='"$(asm-arch)"'
1028c2ecf20Sopenharmony_ciendif
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciifeq ($(CONFIG_SHADOW_CALL_STACK), y)
1058c2ecf20Sopenharmony_ciKBUILD_CFLAGS	+= -ffixed-x18
1068c2ecf20Sopenharmony_ciendif
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
1098c2ecf20Sopenharmony_ciKBUILD_CPPFLAGS	+= -mbig-endian
1108c2ecf20Sopenharmony_ciCHECKFLAGS	+= -D__AARCH64EB__
1118c2ecf20Sopenharmony_ci# Prefer the baremetal ELF build target, but not all toolchains include
1128c2ecf20Sopenharmony_ci# it so fall back to the standard linux version if needed.
1138c2ecf20Sopenharmony_ciKBUILD_LDFLAGS	+= -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
1148c2ecf20Sopenharmony_ciUTS_MACHINE	:= aarch64_be
1158c2ecf20Sopenharmony_cielse
1168c2ecf20Sopenharmony_ciKBUILD_CPPFLAGS	+= -mlittle-endian
1178c2ecf20Sopenharmony_ciCHECKFLAGS	+= -D__AARCH64EL__
1188c2ecf20Sopenharmony_ci# Same as above, prefer ELF but fall back to linux target if needed.
1198c2ecf20Sopenharmony_ciKBUILD_LDFLAGS	+= -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
1208c2ecf20Sopenharmony_ciUTS_MACHINE	:= aarch64
1218c2ecf20Sopenharmony_ciendif
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciifeq ($(CONFIG_LD_IS_LLD), y)
1248c2ecf20Sopenharmony_ciKBUILD_LDFLAGS	+= -z norelro
1258c2ecf20Sopenharmony_ciendif
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciCHECKFLAGS	+= -D__aarch64__
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
1308c2ecf20Sopenharmony_ci  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
1318c2ecf20Sopenharmony_ci  CC_FLAGS_FTRACE := -fpatchable-function-entry=2
1328c2ecf20Sopenharmony_ciendif
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci# Default value
1358c2ecf20Sopenharmony_cihead-y		:= arch/arm64/kernel/head.o
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciifeq ($(CONFIG_KASAN_SW_TAGS), y)
1388c2ecf20Sopenharmony_ciKASAN_SHADOW_SCALE_SHIFT := 4
1398c2ecf20Sopenharmony_cielse
1408c2ecf20Sopenharmony_ciKASAN_SHADOW_SCALE_SHIFT := 3
1418c2ecf20Sopenharmony_ciendif
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciKBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
1448c2ecf20Sopenharmony_ciKBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
1458c2ecf20Sopenharmony_ciKBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cicore-y		+= arch/arm64/
1488c2ecf20Sopenharmony_cilibs-y		:= arch/arm64/lib/ $(libs-y)
1498c2ecf20Sopenharmony_cilibs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci# Default target when executing plain make
1528c2ecf20Sopenharmony_ciboot		:= arch/arm64/boot
1538c2ecf20Sopenharmony_ciKBUILD_IMAGE	:= $(boot)/Image.gz
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ciall:	Image.gz
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciImage: vmlinux
1598c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ciImage.%: Image
1628c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cizinstall install:
1658c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $@
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ciPHONY += vdso_install
1688c2ecf20Sopenharmony_civdso_install:
1698c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
1708c2ecf20Sopenharmony_ci	$(if $(CONFIG_COMPAT_VDSO), \
1718c2ecf20Sopenharmony_ci		$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 $@)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci# We use MRPROPER_FILES and CLEAN_FILES now
1748c2ecf20Sopenharmony_ciarchclean:
1758c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(clean)=$(boot)
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ciifeq ($(KBUILD_EXTMOD),)
1788c2ecf20Sopenharmony_ci# We need to generate vdso-offsets.h before compiling certain files in kernel/.
1798c2ecf20Sopenharmony_ci# In order to do that, we should use the archprepare target, but we can't since
1808c2ecf20Sopenharmony_ci# asm-offsets.h is included in some files used to generate vdso-offsets.h, and
1818c2ecf20Sopenharmony_ci# asm-offsets.h is built in prepare0, for which archprepare is a dependency.
1828c2ecf20Sopenharmony_ci# Therefore we need to generate the header after prepare0 has been made, hence
1838c2ecf20Sopenharmony_ci# this hack.
1848c2ecf20Sopenharmony_ciprepare: vdso_prepare
1858c2ecf20Sopenharmony_civdso_prepare: prepare0
1868c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
1878c2ecf20Sopenharmony_ci	$(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \
1888c2ecf20Sopenharmony_ci		$(build)=arch/arm64/kernel/vdso32  \
1898c2ecf20Sopenharmony_ci		include/generated/vdso32-offsets.h)
1908c2ecf20Sopenharmony_ciendif
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cidefine archhelp
1938c2ecf20Sopenharmony_ci  echo  '* Image.gz      - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
1948c2ecf20Sopenharmony_ci  echo  '  Image         - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
1958c2ecf20Sopenharmony_ci  echo  '  install       - Install uncompressed kernel'
1968c2ecf20Sopenharmony_ci  echo  '  zinstall      - Install compressed kernel'
1978c2ecf20Sopenharmony_ci  echo  '                  Install using (your) ~/bin/installkernel or'
1988c2ecf20Sopenharmony_ci  echo  '                  (distribution) /sbin/installkernel or'
1998c2ecf20Sopenharmony_ci  echo  '                  install to $$(INSTALL_PATH) and run lilo'
2008c2ecf20Sopenharmony_ciendef
201