1# This file is included by the global makefile so that you can add your own 2# architecture-specific flags and dependencies. Remember to do have actions 3# for "archclean" and "archdep" for cleaning up and making dependencies for 4# this architecture 5# 6# This file is subject to the terms and conditions of the GNU General Public 7# License. See the file "COPYING" in the main directory of this archive 8# for more details. 9# 10 11OBJCOPYFLAGS := -O binary 12LDFLAGS_vmlinux := 13ifeq ($(CONFIG_DYNAMIC_FTRACE),y) 14 LDFLAGS_vmlinux := --no-relax 15 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY 16ifeq ($(CONFIG_RISCV_ISA_C),y) 17 CC_FLAGS_FTRACE := -fpatchable-function-entry=4 18else 19 CC_FLAGS_FTRACE := -fpatchable-function-entry=2 20endif 21endif 22 23ifeq ($(CONFIG_CMODEL_MEDLOW),y) 24KBUILD_CFLAGS_MODULE += -mcmodel=medany 25endif 26 27export BITS 28ifeq ($(CONFIG_ARCH_RV64I),y) 29 BITS := 64 30 UTS_MACHINE := riscv64 31 32 KBUILD_CFLAGS += -mabi=lp64 33 KBUILD_AFLAGS += -mabi=lp64 34 35 KBUILD_LDFLAGS += -melf64lriscv 36else 37 BITS := 32 38 UTS_MACHINE := riscv32 39 40 KBUILD_CFLAGS += -mabi=ilp32 41 KBUILD_AFLAGS += -mabi=ilp32 42 KBUILD_LDFLAGS += -melf32lriscv 43endif 44 45ifeq ($(CONFIG_LD_IS_LLD),y) 46ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) 47 KBUILD_CFLAGS += -mno-relax 48 KBUILD_AFLAGS += -mno-relax 49ifndef CONFIG_AS_IS_LLVM 50 KBUILD_CFLAGS += -Wa,-mno-relax 51 KBUILD_AFLAGS += -Wa,-mno-relax 52endif 53endif 54endif 55 56# ISA string setting 57riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima 58riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima 59riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd 60riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c 61 62ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC 63KBUILD_CFLAGS += -Wa,-misa-spec=2.2 64KBUILD_AFLAGS += -Wa,-misa-spec=2.2 65else 66riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei 67endif 68 69KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y)) 70KBUILD_AFLAGS += -march=$(riscv-march-y) 71 72KBUILD_CFLAGS += -mno-save-restore 73KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) 74 75ifeq ($(CONFIG_CMODEL_MEDLOW),y) 76 KBUILD_CFLAGS += -mcmodel=medlow 77endif 78ifeq ($(CONFIG_CMODEL_MEDANY),y) 79 KBUILD_CFLAGS += -mcmodel=medany 80endif 81ifeq ($(CONFIG_PERF_EVENTS),y) 82 KBUILD_CFLAGS += -fno-omit-frame-pointer 83endif 84 85# Avoid generating .eh_frame sections. 86KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables 87 88KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) 89KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax) 90 91# GCC versions that support the "-mstrict-align" option default to allowing 92# unaligned accesses. While unaligned accesses are explicitly allowed in the 93# RISC-V ISA, they're emulated by machine mode traps on all extant 94# architectures. It's faster to have GCC emit only aligned accesses. 95KBUILD_CFLAGS += $(call cc-option,-mstrict-align) 96 97ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) 98prepare: stack_protector_prepare 99stack_protector_prepare: prepare0 100 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \ 101 -mstack-protector-guard-reg=tp \ 102 -mstack-protector-guard-offset=$(shell \ 103 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \ 104 include/generated/asm-offsets.h)) 105endif 106 107# arch specific predefines for sparse 108CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS) 109 110# Default target when executing plain make 111boot := arch/riscv/boot 112ifeq ($(CONFIG_XIP_KERNEL),y) 113KBUILD_IMAGE := $(boot)/xipImage 114else 115KBUILD_IMAGE := $(boot)/Image.gz 116endif 117 118head-y := arch/riscv/kernel/head.o 119 120core-$(CONFIG_RISCV_ERRATA_ALTERNATIVE) += arch/riscv/errata/ 121 122libs-y += arch/riscv/lib/ 123libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a 124 125PHONY += vdso_install 126vdso_install: 127 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ 128 129ifeq ($(KBUILD_EXTMOD),) 130ifeq ($(CONFIG_MMU),y) 131prepare: vdso_prepare 132vdso_prepare: prepare0 133 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h 134endif 135endif 136 137ifneq ($(CONFIG_XIP_KERNEL),y) 138ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_CANAAN),yy) 139KBUILD_IMAGE := $(boot)/loader.bin 140else 141KBUILD_IMAGE := $(boot)/Image.gz 142endif 143endif 144BOOT_TARGETS := Image Image.gz loader loader.bin xipImage 145 146all: $(notdir $(KBUILD_IMAGE)) 147 148$(BOOT_TARGETS): vmlinux 149 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 150 @$(kecho) ' Kernel: $(boot)/$@ is ready' 151 152Image.%: Image 153 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 154 155install: install-image = Image 156zinstall: install-image = Image.gz 157install zinstall: 158 $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 159 $(boot)/$(install-image) System.map "$(INSTALL_PATH)" 160 161archclean: 162 $(Q)$(MAKE) $(clean)=$(boot) 163