Merge tag 'soc-ep93xx-dt-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-block.git] / arch / riscv / Makefile
CommitLineData
fbe934d6 1# This file is included by the global makefile so that you can add your own
8212f898 2# architecture-specific flags and dependencies.
fbe934d6
PD
3#
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
6# for more details.
7#
8
26e7aacb 9LDFLAGS_vmlinux := -z norelro
39b33072 10ifeq ($(CONFIG_RELOCATABLE),y)
26e7aacb 11 LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs
39b33072
AG
12 KBUILD_CFLAGS += -fPIE
13endif
a1d2a6b4 14ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
39b33072 15 LDFLAGS_vmlinux += --no-relax
afc76b8b 16 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
409c8fb2 17ifeq ($(CONFIG_RISCV_ISA_C),y)
409c8fb2 18 CC_FLAGS_FTRACE := -fpatchable-function-entry=4
6724a76c
GR
19else
20 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
409c8fb2 21endif
a1d2a6b4 22endif
aad15bc8 23
5d2388db 24ifeq ($(CONFIG_CMODEL_MEDLOW),y)
aad15bc8
VC
25KBUILD_CFLAGS_MODULE += -mcmodel=medany
26endif
fbe934d6 27
fbe934d6
PD
28export BITS
29ifeq ($(CONFIG_ARCH_RV64I),y)
30 BITS := 64
31 UTS_MACHINE := riscv64
32
33 KBUILD_CFLAGS += -mabi=lp64
34 KBUILD_AFLAGS += -mabi=lp64
a89757da 35
d503ac53 36 KBUILD_LDFLAGS += -melf64lriscv
70a57b24
MO
37
38 KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 --target=riscv64imac-unknown-none-elf \
39 -Cno-redzone
fbe934d6
PD
40else
41 BITS := 32
42 UTS_MACHINE := riscv32
43
44 KBUILD_CFLAGS += -mabi=ilp32
45 KBUILD_AFLAGS += -mabi=ilp32
d503ac53 46 KBUILD_LDFLAGS += -melf32lriscv
fbe934d6
PD
47endif
48
55b71d2c 49ifndef CONFIG_RISCV_USE_LINKER_RELAXATION
ec3a5cb6
KR
50 KBUILD_CFLAGS += -mno-relax
51 KBUILD_AFLAGS += -mno-relax
52cc02b9 52ifndef CONFIG_AS_IS_LLVM
ec3a5cb6
KR
53 KBUILD_CFLAGS += -Wa,-mno-relax
54 KBUILD_AFLAGS += -Wa,-mno-relax
55endif
021d2342
WT
56# LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350
57# Ensure it is aware of linker relaxation with LTO, otherwise relocations may
58# be incorrect: https://github.com/llvm/llvm-project/issues/65090
59else ifeq ($(CONFIG_LTO_CLANG),y)
60 KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax
ec3a5cb6
KR
61endif
62
d1584d79
ST
63ifeq ($(CONFIG_SHADOW_CALL_STACK),y)
64 KBUILD_LDFLAGS += --no-relax-gp
65endif
66
e8be5302 67# ISA string setting
09afac77
CH
68riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
69riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
9671f706 70riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
e8be5302 71riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
fa8e7cce 72riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v
6df2a016 73
70a57b24
MO
74ifneq ($(CONFIG_RISCV_ISA_C),y)
75 KBUILD_RUSTFLAGS += -Ctarget-feature=-c
76endif
77
e89c2e81
NC
78ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
79KBUILD_CFLAGS += -Wa,-misa-spec=2.2
80KBUILD_AFLAGS += -Wa,-misa-spec=2.2
81else
82riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
83endif
6df2a016 84
fa8e7cce
GR
85# Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
86# matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
87KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')
88
e8be5302 89KBUILD_AFLAGS += -march=$(riscv-march-y)
fbe934d6 90
77acc6b5
SH
91# For C code built with floating-point support, exclude V but keep F and D.
92CC_FLAGS_FPU := -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)([^v_]*)v?/\1\2/')
93
fbe934d6
PD
94KBUILD_CFLAGS += -mno-save-restore
95KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
96
97ifeq ($(CONFIG_CMODEL_MEDLOW),y)
98 KBUILD_CFLAGS += -mcmodel=medlow
99endif
100ifeq ($(CONFIG_CMODEL_MEDANY),y)
101 KBUILD_CFLAGS += -mcmodel=medany
102endif
ab1ef68e 103
2f394c0e
AS
104# Avoid generating .eh_frame sections.
105KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
106
e18048da
PD
107# The RISC-V attributes frequently cause compatibility issues and provide no
108# information, so just turn them off.
109KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
110KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
111KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
112KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
113
ab1ef68e 114KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
c1f6eff3 115KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
fbe934d6
PD
116
117# GCC versions that support the "-mstrict-align" option default to allowing
118# unaligned accesses. While unaligned accesses are explicitly allowed in the
119# RISC-V ISA, they're emulated by machine mode traps on all extant
120# architectures. It's faster to have GCC emit only aligned accesses.
b6da6cbe 121ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y)
fbe934d6 122KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
b6da6cbe 123endif
fbe934d6 124
fea2fed2
GR
125ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
126prepare: stack_protector_prepare
127stack_protector_prepare: prepare0
128 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
129 -mstack-protector-guard-reg=tp \
130 -mstack-protector-guard-offset=$(shell \
131 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
132 include/generated/asm-offsets.h))
133endif
134
889d746e
LVO
135# arch specific predefines for sparse
136CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
137
c0fbcd99
AP
138# Default target when executing plain make
139boot := arch/riscv/boot
44c92257
VW
140ifeq ($(CONFIG_XIP_KERNEL),y)
141KBUILD_IMAGE := $(boot)/xipImage
142else
0bfbc914 143ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_CANAAN_K210),yy)
3b938e23
MY
144KBUILD_IMAGE := $(boot)/loader.bin
145else
146ifeq ($(CONFIG_EFI_ZBOOT),)
c0fbcd99 147KBUILD_IMAGE := $(boot)/Image.gz
3b938e23
MY
148else
149KBUILD_IMAGE := $(boot)/vmlinuz.efi
150endif
151endif
44c92257 152endif
c0fbcd99 153
e79dfcbf
ERB
154boot := arch/riscv/boot
155boot-image-y := Image
156boot-image-$(CONFIG_KERNEL_BZIP2) := Image.bz2
157boot-image-$(CONFIG_KERNEL_GZIP) := Image.gz
158boot-image-$(CONFIG_KERNEL_LZ4) := Image.lz4
159boot-image-$(CONFIG_KERNEL_LZMA) := Image.lzma
160boot-image-$(CONFIG_KERNEL_LZO) := Image.lzo
161boot-image-$(CONFIG_KERNEL_ZSTD) := Image.zst
ab4ce983 162boot-image-$(CONFIG_KERNEL_XZ) := Image.xz
e79dfcbf
ERB
163ifdef CONFIG_RISCV_M_MODE
164boot-image-$(CONFIG_ARCH_CANAAN) := loader.bin
165endif
166boot-image-$(CONFIG_EFI_ZBOOT) := vmlinuz.efi
167boot-image-$(CONFIG_XIP_KERNEL) := xipImage
168KBUILD_IMAGE := $(boot)/$(boot-image-y)
169
fbe934d6 170libs-y += arch/riscv/lib/
d7071743 171libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
fbe934d6 172
5a19c7e0 173ifeq ($(KBUILD_EXTMOD),)
a290f510 174ifeq ($(CONFIG_MMU),y)
fde9c59a
SA
175prepare: vdso_prepare
176vdso_prepare: prepare0
177 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
0715372a
GR
178 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
179 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
180
a290f510 181endif
5a19c7e0 182endif
fde9c59a 183
56769ba4 184vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg
4b0bf9a0 185vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
56769ba4 186
ab4ce983 187BOOT_TARGETS := Image Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst Image.xz loader loader.bin xipImage vmlinuz.efi
c0fbcd99 188
405fe7aa 189all: $(notdir $(KBUILD_IMAGE))
c0fbcd99 190
c4db7ff7 191loader.bin: loader
ab4ce983 192Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst Image.xz loader xipImage vmlinuz.efi: Image
e79dfcbf 193
405fe7aa 194$(BOOT_TARGETS): vmlinux
c0fbcd99 195 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
405fe7aa 196 @$(kecho) ' Kernel: $(boot)/$@ is ready'
c0fbcd99 197
e79dfcbf
ERB
198# the install target always installs KBUILD_IMAGE (which may be compressed)
199# but keep the zinstall target for compatibility with older releases
399c1ec8 200install zinstall:
f774f5bb 201 $(call cmd,install)
2c42bcbb 202
5d4595db
RD
203PHONY += rv32_randconfig
204rv32_randconfig:
205 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
206 -f $(srctree)/Makefile randconfig
207
208PHONY += rv64_randconfig
209rv64_randconfig:
210 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
211 -f $(srctree)/Makefile randconfig
72f045d1
GR
212
213PHONY += rv32_defconfig
214rv32_defconfig:
215 $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
77c0c966
JT
216
217PHONY += rv32_nommu_virt_defconfig
218rv32_nommu_virt_defconfig:
219 $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config
07501c49
ERB
220
221define archhelp
222 echo ' Image - Uncompressed kernel image (arch/riscv/boot/Image)'
223 echo ' Image.gz - Compressed kernel image (arch/riscv/boot/Image.gz)'
224 echo ' Image.bz2 - Compressed kernel image (arch/riscv/boot/Image.bz2)'
225 echo ' Image.lz4 - Compressed kernel image (arch/riscv/boot/Image.lz4)'
226 echo ' Image.lzma - Compressed kernel image (arch/riscv/boot/Image.lzma)'
227 echo ' Image.lzo - Compressed kernel image (arch/riscv/boot/Image.lzo)'
228 echo ' Image.zst - Compressed kernel image (arch/riscv/boot/Image.zst)'
ab4ce983 229 echo ' Image.xz - Compressed kernel image (arch/riscv/boot/Image.xz)'
07501c49
ERB
230 echo ' vmlinuz.efi - Compressed EFI kernel image (arch/riscv/boot/vmlinuz.efi)'
231 echo ' Default when CONFIG_EFI_ZBOOT=y'
232 echo ' xipImage - Execute-in-place kernel image (arch/riscv/boot/xipImage)'
233 echo ' Default when CONFIG_XIP_KERNEL=y'
234 echo ' install - Install kernel using (your) ~/bin/$(INSTALLKERNEL) or'
235 echo ' (distribution) /sbin/$(INSTALLKERNEL) or install to '
236 echo ' $$(INSTALL_PATH)'
237endef