xref: /openbmc/linux/arch/riscv/Makefile (revision 559d1e45)
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
10ifeq ($(CONFIG_RELOCATABLE),y)
11	LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro --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
62
63# Newer binutils versions default to ISA spec version 20191213 which moves some
64# instructions from the I extension to the Zicsr and Zifencei extensions.
65toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
66riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
67
68# Check if the toolchain supports Zihintpause extension
69riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause
70
71KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
72KBUILD_AFLAGS += -march=$(riscv-march-y)
73
74KBUILD_CFLAGS += -mno-save-restore
75KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
76
77ifeq ($(CONFIG_CMODEL_MEDLOW),y)
78	KBUILD_CFLAGS += -mcmodel=medlow
79endif
80ifeq ($(CONFIG_CMODEL_MEDANY),y)
81	KBUILD_CFLAGS += -mcmodel=medany
82endif
83ifeq ($(CONFIG_PERF_EVENTS),y)
84        KBUILD_CFLAGS += -fno-omit-frame-pointer
85endif
86
87# Avoid generating .eh_frame sections.
88KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
89
90KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
91KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
92
93# GCC versions that support the "-mstrict-align" option default to allowing
94# unaligned accesses.  While unaligned accesses are explicitly allowed in the
95# RISC-V ISA, they're emulated by machine mode traps on all extant
96# architectures.  It's faster to have GCC emit only aligned accesses.
97KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
98
99ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
100prepare: stack_protector_prepare
101stack_protector_prepare: prepare0
102	$(eval KBUILD_CFLAGS += -mstack-protector-guard=tls		  \
103				-mstack-protector-guard-reg=tp		  \
104				-mstack-protector-guard-offset=$(shell	  \
105			awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
106					include/generated/asm-offsets.h))
107endif
108
109# arch specific predefines for sparse
110CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
111
112# Default target when executing plain make
113boot		:= arch/riscv/boot
114ifeq ($(CONFIG_XIP_KERNEL),y)
115KBUILD_IMAGE := $(boot)/xipImage
116else
117KBUILD_IMAGE	:= $(boot)/Image.gz
118endif
119
120libs-y += arch/riscv/lib/
121libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
122
123PHONY += vdso_install
124vdso_install:
125	$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
126	$(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
127		$(build)=arch/riscv/kernel/compat_vdso compat_$@)
128
129ifeq ($(KBUILD_EXTMOD),)
130ifeq ($(CONFIG_MMU),y)
131prepare: vdso_prepare
132vdso_prepare: prepare0
133	$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
134	$(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
135		$(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
136
137endif
138endif
139
140ifneq ($(CONFIG_XIP_KERNEL),y)
141ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy)
142KBUILD_IMAGE := $(boot)/loader.bin
143else
144ifeq ($(CONFIG_EFI_ZBOOT),)
145KBUILD_IMAGE := $(boot)/Image.gz
146else
147KBUILD_IMAGE := $(boot)/vmlinuz.efi
148endif
149endif
150endif
151BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
152
153all:	$(notdir $(KBUILD_IMAGE))
154
155$(BOOT_TARGETS): vmlinux
156	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
157	@$(kecho) '  Kernel: $(boot)/$@ is ready'
158
159Image.%: Image
160	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
161
162install: KBUILD_IMAGE := $(boot)/Image
163zinstall: KBUILD_IMAGE := $(boot)/Image.gz
164install zinstall:
165	$(call cmd,install)
166
167PHONY += rv32_randconfig
168rv32_randconfig:
169	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
170		-f $(srctree)/Makefile randconfig
171
172PHONY += rv64_randconfig
173rv64_randconfig:
174	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
175		-f $(srctree)/Makefile randconfig
176
177PHONY += rv32_defconfig
178rv32_defconfig:
179	$(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
180