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
10 LDFLAGS_vmlinux := -z norelro
11 ifeq ($(CONFIG_RELOCATABLE),y)
12 LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs
13 KBUILD_CFLAGS += -fPIE
15 ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
16 LDFLAGS_vmlinux += --no-relax
17 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
18 ifeq ($(CONFIG_RISCV_ISA_C),y)
19 CC_FLAGS_FTRACE := -fpatchable-function-entry=4
21 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
25 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
26 KBUILD_CFLAGS_MODULE += -mcmodel=medany
30 ifeq ($(CONFIG_ARCH_RV64I),y)
32 UTS_MACHINE := riscv64
34 KBUILD_CFLAGS += -mabi=lp64
35 KBUILD_AFLAGS += -mabi=lp64
37 KBUILD_LDFLAGS += -melf64lriscv
40 UTS_MACHINE := riscv32
42 KBUILD_CFLAGS += -mabi=ilp32
43 KBUILD_AFLAGS += -mabi=ilp32
44 KBUILD_LDFLAGS += -melf32lriscv
47 ifeq ($(CONFIG_LD_IS_LLD),y)
48 ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y)
49 KBUILD_CFLAGS += -mno-relax
50 KBUILD_AFLAGS += -mno-relax
51 ifndef CONFIG_AS_IS_LLVM
52 KBUILD_CFLAGS += -Wa,-mno-relax
53 KBUILD_AFLAGS += -Wa,-mno-relax
59 riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
60 riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
61 riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
62 riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
63 riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v
65 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
66 KBUILD_CFLAGS += -Wa,-misa-spec=2.2
67 KBUILD_AFLAGS += -Wa,-misa-spec=2.2
69 riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
72 # Check if the toolchain supports Zihintpause extension
73 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause
75 # Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
76 # matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
77 KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')
79 KBUILD_AFLAGS += -march=$(riscv-march-y)
81 KBUILD_CFLAGS += -mno-save-restore
82 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
84 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
85 KBUILD_CFLAGS += -mcmodel=medlow
87 ifeq ($(CONFIG_CMODEL_MEDANY),y)
88 KBUILD_CFLAGS += -mcmodel=medany
91 # Avoid generating .eh_frame sections.
92 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
94 # The RISC-V attributes frequently cause compatibility issues and provide no
95 # information, so just turn them off.
96 KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
97 KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
98 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
99 KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
101 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
102 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
104 # GCC versions that support the "-mstrict-align" option default to allowing
105 # unaligned accesses. While unaligned accesses are explicitly allowed in the
106 # RISC-V ISA, they're emulated by machine mode traps on all extant
107 # architectures. It's faster to have GCC emit only aligned accesses.
108 KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
110 ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
111 prepare: stack_protector_prepare
112 stack_protector_prepare: prepare0
113 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
114 -mstack-protector-guard-reg=tp \
115 -mstack-protector-guard-offset=$(shell \
116 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
117 include/generated/asm-offsets.h))
120 # arch specific predefines for sparse
121 CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
123 # Default target when executing plain make
124 boot := arch/riscv/boot
125 ifeq ($(CONFIG_XIP_KERNEL),y)
126 KBUILD_IMAGE := $(boot)/xipImage
128 KBUILD_IMAGE := $(boot)/Image.gz
131 libs-y += arch/riscv/lib/
132 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
134 PHONY += vdso_install
136 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
137 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
138 $(build)=arch/riscv/kernel/compat_vdso compat_$@)
140 ifeq ($(KBUILD_EXTMOD),)
141 ifeq ($(CONFIG_MMU),y)
142 prepare: vdso_prepare
143 vdso_prepare: prepare0
144 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
145 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
146 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
151 ifneq ($(CONFIG_XIP_KERNEL),y)
152 ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy)
153 KBUILD_IMAGE := $(boot)/loader.bin
155 ifeq ($(CONFIG_EFI_ZBOOT),)
156 KBUILD_IMAGE := $(boot)/Image.gz
158 KBUILD_IMAGE := $(boot)/vmlinuz.efi
162 BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
164 all: $(notdir $(KBUILD_IMAGE))
166 $(BOOT_TARGETS): vmlinux
167 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
168 @$(kecho) ' Kernel: $(boot)/$@ is ready'
171 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
173 install: KBUILD_IMAGE := $(boot)/Image
174 zinstall: KBUILD_IMAGE := $(boot)/Image.gz
178 PHONY += rv32_randconfig
180 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
181 -f $(srctree)/Makefile randconfig
183 PHONY += rv64_randconfig
185 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
186 -f $(srctree)/Makefile randconfig
188 PHONY += rv32_defconfig
190 $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
192 PHONY += rv32_nommu_virt_defconfig
193 rv32_nommu_virt_defconfig:
194 $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config