1 # This file is included by the global makefile so that you can add your own
2 # architecture-specific flags and dependencies.
4 # This file is subject to the terms and conditions of the GNU General Public
5 # License. See the file "COPYING" in the main directory of this archive
9 OBJCOPYFLAGS := -O binary
11 ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
12 LDFLAGS_vmlinux := --no-relax
13 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
14 ifeq ($(CONFIG_RISCV_ISA_C),y)
15 CC_FLAGS_FTRACE := -fpatchable-function-entry=4
17 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
21 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
22 KBUILD_CFLAGS_MODULE += -mcmodel=medany
26 ifeq ($(CONFIG_ARCH_RV64I),y)
28 UTS_MACHINE := riscv64
30 KBUILD_CFLAGS += -mabi=lp64
31 KBUILD_AFLAGS += -mabi=lp64
33 KBUILD_LDFLAGS += -melf64lriscv
36 UTS_MACHINE := riscv32
38 KBUILD_CFLAGS += -mabi=ilp32
39 KBUILD_AFLAGS += -mabi=ilp32
40 KBUILD_LDFLAGS += -melf32lriscv
43 ifeq ($(CONFIG_LD_IS_LLD),y)
44 ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0)
45 KBUILD_CFLAGS += -mno-relax
46 KBUILD_AFLAGS += -mno-relax
47 ifndef CONFIG_AS_IS_LLVM
48 KBUILD_CFLAGS += -Wa,-mno-relax
49 KBUILD_AFLAGS += -Wa,-mno-relax
55 riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
56 riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
57 riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
58 riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
60 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
61 KBUILD_CFLAGS += -Wa,-misa-spec=2.2
62 KBUILD_AFLAGS += -Wa,-misa-spec=2.2
64 riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
67 # Check if the toolchain supports Zicbom extension
68 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZICBOM) := $(riscv-march-y)_zicbom
70 # Check if the toolchain supports Zihintpause extension
71 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause
73 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
74 KBUILD_AFLAGS += -march=$(riscv-march-y)
76 KBUILD_CFLAGS += -mno-save-restore
77 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
79 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
80 KBUILD_CFLAGS += -mcmodel=medlow
82 ifeq ($(CONFIG_CMODEL_MEDANY),y)
83 KBUILD_CFLAGS += -mcmodel=medany
85 ifeq ($(CONFIG_PERF_EVENTS),y)
86 KBUILD_CFLAGS += -fno-omit-frame-pointer
89 # Avoid generating .eh_frame sections.
90 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
92 # The RISC-V attributes frequently cause compatibility issues and provide no
93 # information, so just turn them off.
94 KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
95 KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
96 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
97 KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
99 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
100 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
102 # GCC versions that support the "-mstrict-align" option default to allowing
103 # unaligned accesses. While unaligned accesses are explicitly allowed in the
104 # RISC-V ISA, they're emulated by machine mode traps on all extant
105 # architectures. It's faster to have GCC emit only aligned accesses.
106 KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
108 ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
109 prepare: stack_protector_prepare
110 stack_protector_prepare: prepare0
111 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
112 -mstack-protector-guard-reg=tp \
113 -mstack-protector-guard-offset=$(shell \
114 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
115 include/generated/asm-offsets.h))
118 # arch specific predefines for sparse
119 CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
121 # Default target when executing plain make
122 boot := arch/riscv/boot
123 ifeq ($(CONFIG_XIP_KERNEL),y)
124 KBUILD_IMAGE := $(boot)/xipImage
126 KBUILD_IMAGE := $(boot)/Image.gz
129 libs-y += arch/riscv/lib/
130 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
132 PHONY += vdso_install
134 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
135 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
136 $(build)=arch/riscv/kernel/compat_vdso compat_$@)
138 ifeq ($(KBUILD_EXTMOD),)
139 ifeq ($(CONFIG_MMU),y)
140 prepare: vdso_prepare
141 vdso_prepare: prepare0
142 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
143 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
144 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
149 ifneq ($(CONFIG_XIP_KERNEL),y)
150 ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_CANAAN),yy)
151 KBUILD_IMAGE := $(boot)/loader.bin
153 ifeq ($(CONFIG_EFI_ZBOOT),)
154 KBUILD_IMAGE := $(boot)/Image.gz
156 KBUILD_IMAGE := $(boot)/vmlinuz.efi
160 BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
162 all: $(notdir $(KBUILD_IMAGE))
164 $(BOOT_TARGETS): vmlinux
165 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
166 @$(kecho) ' Kernel: $(boot)/$@ is ready'
169 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
171 install: KBUILD_IMAGE := $(boot)/Image
172 zinstall: KBUILD_IMAGE := $(boot)/Image.gz
176 PHONY += rv32_randconfig
178 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
179 -f $(srctree)/Makefile randconfig
181 PHONY += rv64_randconfig
183 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
184 -f $(srctree)/Makefile randconfig
186 PHONY += rv32_defconfig
188 $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config