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