162306a36Sopenharmony_ci# This file is included by the global makefile so that you can add your own 262306a36Sopenharmony_ci# architecture-specific flags and dependencies. 362306a36Sopenharmony_ci# 462306a36Sopenharmony_ci# This file is subject to the terms and conditions of the GNU General Public 562306a36Sopenharmony_ci# License. See the file "COPYING" in the main directory of this archive 662306a36Sopenharmony_ci# for more details. 762306a36Sopenharmony_ci# 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciLDFLAGS_vmlinux := -z norelro 1062306a36Sopenharmony_ciifeq ($(CONFIG_RELOCATABLE),y) 1162306a36Sopenharmony_ci LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs 1262306a36Sopenharmony_ci KBUILD_CFLAGS += -fPIE 1362306a36Sopenharmony_ciendif 1462306a36Sopenharmony_ciifeq ($(CONFIG_DYNAMIC_FTRACE),y) 1562306a36Sopenharmony_ci LDFLAGS_vmlinux += --no-relax 1662306a36Sopenharmony_ci KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY 1762306a36Sopenharmony_ciifeq ($(CONFIG_RISCV_ISA_C),y) 1862306a36Sopenharmony_ci CC_FLAGS_FTRACE := -fpatchable-function-entry=4 1962306a36Sopenharmony_cielse 2062306a36Sopenharmony_ci CC_FLAGS_FTRACE := -fpatchable-function-entry=2 2162306a36Sopenharmony_ciendif 2262306a36Sopenharmony_ciendif 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciifeq ($(CONFIG_CMODEL_MEDLOW),y) 2562306a36Sopenharmony_ciKBUILD_CFLAGS_MODULE += -mcmodel=medany 2662306a36Sopenharmony_ciendif 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciexport BITS 2962306a36Sopenharmony_ciifeq ($(CONFIG_ARCH_RV64I),y) 3062306a36Sopenharmony_ci BITS := 64 3162306a36Sopenharmony_ci UTS_MACHINE := riscv64 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci KBUILD_CFLAGS += -mabi=lp64 3462306a36Sopenharmony_ci KBUILD_AFLAGS += -mabi=lp64 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci KBUILD_LDFLAGS += -melf64lriscv 3762306a36Sopenharmony_cielse 3862306a36Sopenharmony_ci BITS := 32 3962306a36Sopenharmony_ci UTS_MACHINE := riscv32 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci KBUILD_CFLAGS += -mabi=ilp32 4262306a36Sopenharmony_ci KBUILD_AFLAGS += -mabi=ilp32 4362306a36Sopenharmony_ci KBUILD_LDFLAGS += -melf32lriscv 4462306a36Sopenharmony_ciendif 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciifeq ($(CONFIG_LD_IS_LLD),y) 4762306a36Sopenharmony_ciifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) 4862306a36Sopenharmony_ci KBUILD_CFLAGS += -mno-relax 4962306a36Sopenharmony_ci KBUILD_AFLAGS += -mno-relax 5062306a36Sopenharmony_ciifndef CONFIG_AS_IS_LLVM 5162306a36Sopenharmony_ci KBUILD_CFLAGS += -Wa,-mno-relax 5262306a36Sopenharmony_ci KBUILD_AFLAGS += -Wa,-mno-relax 5362306a36Sopenharmony_ciendif 5462306a36Sopenharmony_ciendif 5562306a36Sopenharmony_ciendif 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci# ISA string setting 5862306a36Sopenharmony_ciriscv-march-$(CONFIG_ARCH_RV32I) := rv32ima 5962306a36Sopenharmony_ciriscv-march-$(CONFIG_ARCH_RV64I) := rv64ima 6062306a36Sopenharmony_ciriscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd 6162306a36Sopenharmony_ciriscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c 6262306a36Sopenharmony_ciriscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC 6562306a36Sopenharmony_ciKBUILD_CFLAGS += -Wa,-misa-spec=2.2 6662306a36Sopenharmony_ciKBUILD_AFLAGS += -Wa,-misa-spec=2.2 6762306a36Sopenharmony_cielse 6862306a36Sopenharmony_ciriscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei 6962306a36Sopenharmony_ciendif 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci# Check if the toolchain supports Zihintpause extension 7262306a36Sopenharmony_ciriscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci# Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by 7562306a36Sopenharmony_ci# matching non-v and non-multi-letter extensions out with the filter ([^v_]*) 7662306a36Sopenharmony_ciKBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/') 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciKBUILD_AFLAGS += -march=$(riscv-march-y) 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ciKBUILD_CFLAGS += -mno-save-restore 8162306a36Sopenharmony_ciKBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciifeq ($(CONFIG_CMODEL_MEDLOW),y) 8462306a36Sopenharmony_ci KBUILD_CFLAGS += -mcmodel=medlow 8562306a36Sopenharmony_ciendif 8662306a36Sopenharmony_ciifeq ($(CONFIG_CMODEL_MEDANY),y) 8762306a36Sopenharmony_ci KBUILD_CFLAGS += -mcmodel=medany 8862306a36Sopenharmony_ciendif 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci# Avoid generating .eh_frame sections. 9162306a36Sopenharmony_ciKBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci# The RISC-V attributes frequently cause compatibility issues and provide no 9462306a36Sopenharmony_ci# information, so just turn them off. 9562306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute) 9662306a36Sopenharmony_ciKBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute) 9762306a36Sopenharmony_ciKBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 9862306a36Sopenharmony_ciKBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciKBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) 10162306a36Sopenharmony_ciKBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci# GCC versions that support the "-mstrict-align" option default to allowing 10462306a36Sopenharmony_ci# unaligned accesses. While unaligned accesses are explicitly allowed in the 10562306a36Sopenharmony_ci# RISC-V ISA, they're emulated by machine mode traps on all extant 10662306a36Sopenharmony_ci# architectures. It's faster to have GCC emit only aligned accesses. 10762306a36Sopenharmony_ciKBUILD_CFLAGS += $(call cc-option,-mstrict-align) 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) 11062306a36Sopenharmony_ciprepare: stack_protector_prepare 11162306a36Sopenharmony_cistack_protector_prepare: prepare0 11262306a36Sopenharmony_ci $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \ 11362306a36Sopenharmony_ci -mstack-protector-guard-reg=tp \ 11462306a36Sopenharmony_ci -mstack-protector-guard-offset=$(shell \ 11562306a36Sopenharmony_ci awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \ 11662306a36Sopenharmony_ci include/generated/asm-offsets.h)) 11762306a36Sopenharmony_ciendif 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci# arch specific predefines for sparse 12062306a36Sopenharmony_ciCHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS) 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci# Default target when executing plain make 12362306a36Sopenharmony_ciboot := arch/riscv/boot 12462306a36Sopenharmony_ciifeq ($(CONFIG_XIP_KERNEL),y) 12562306a36Sopenharmony_ciKBUILD_IMAGE := $(boot)/xipImage 12662306a36Sopenharmony_cielse 12762306a36Sopenharmony_ciKBUILD_IMAGE := $(boot)/Image.gz 12862306a36Sopenharmony_ciendif 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_cilibs-y += arch/riscv/lib/ 13162306a36Sopenharmony_cilibs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ciPHONY += vdso_install 13462306a36Sopenharmony_civdso_install: 13562306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ 13662306a36Sopenharmony_ci $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ 13762306a36Sopenharmony_ci $(build)=arch/riscv/kernel/compat_vdso compat_$@) 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciifeq ($(KBUILD_EXTMOD),) 14062306a36Sopenharmony_ciifeq ($(CONFIG_MMU),y) 14162306a36Sopenharmony_ciprepare: vdso_prepare 14262306a36Sopenharmony_civdso_prepare: prepare0 14362306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h 14462306a36Sopenharmony_ci $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ 14562306a36Sopenharmony_ci $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h) 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ciendif 14862306a36Sopenharmony_ciendif 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ciifneq ($(CONFIG_XIP_KERNEL),y) 15162306a36Sopenharmony_ciifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy) 15262306a36Sopenharmony_ciKBUILD_IMAGE := $(boot)/loader.bin 15362306a36Sopenharmony_cielse 15462306a36Sopenharmony_ciifeq ($(CONFIG_EFI_ZBOOT),) 15562306a36Sopenharmony_ciKBUILD_IMAGE := $(boot)/Image.gz 15662306a36Sopenharmony_cielse 15762306a36Sopenharmony_ciKBUILD_IMAGE := $(boot)/vmlinuz.efi 15862306a36Sopenharmony_ciendif 15962306a36Sopenharmony_ciendif 16062306a36Sopenharmony_ciendif 16162306a36Sopenharmony_ciBOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ciall: $(notdir $(KBUILD_IMAGE)) 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci$(BOOT_TARGETS): vmlinux 16662306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 16762306a36Sopenharmony_ci @$(kecho) ' Kernel: $(boot)/$@ is ready' 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ciImage.%: Image 17062306a36Sopenharmony_ci $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ciinstall: KBUILD_IMAGE := $(boot)/Image 17362306a36Sopenharmony_cizinstall: KBUILD_IMAGE := $(boot)/Image.gz 17462306a36Sopenharmony_ciinstall zinstall: 17562306a36Sopenharmony_ci $(call cmd,install) 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ciPHONY += rv32_randconfig 17862306a36Sopenharmony_cirv32_randconfig: 17962306a36Sopenharmony_ci $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \ 18062306a36Sopenharmony_ci -f $(srctree)/Makefile randconfig 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciPHONY += rv64_randconfig 18362306a36Sopenharmony_cirv64_randconfig: 18462306a36Sopenharmony_ci $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \ 18562306a36Sopenharmony_ci -f $(srctree)/Makefile randconfig 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciPHONY += rv32_defconfig 18862306a36Sopenharmony_cirv32_defconfig: 18962306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ciPHONY += rv32_nommu_virt_defconfig 19262306a36Sopenharmony_cirv32_nommu_virt_defconfig: 19362306a36Sopenharmony_ci $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config 194