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