xref: /OK3568_Linux_fs/kernel/arch/riscv/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# This file is included by the global makefile so that you can add your own
2*4882a593Smuzhiyun# architecture-specific flags and dependencies. Remember to do have actions
3*4882a593Smuzhiyun# for "archclean" and "archdep" for cleaning up and making dependencies for
4*4882a593Smuzhiyun# this architecture
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# This file is subject to the terms and conditions of the GNU General Public
7*4882a593Smuzhiyun# License.  See the file "COPYING" in the main directory of this archive
8*4882a593Smuzhiyun# for more details.
9*4882a593Smuzhiyun#
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunOBJCOPYFLAGS    := -O binary
12*4882a593SmuzhiyunLDFLAGS_vmlinux :=
13*4882a593Smuzhiyunifeq ($(CONFIG_DYNAMIC_FTRACE),y)
14*4882a593Smuzhiyun	LDFLAGS_vmlinux := --no-relax
15*4882a593Smuzhiyunendif
16*4882a593Smuzhiyun
17*4882a593Smuzhiyunifeq ($(CONFIG_CMODEL_MEDLOW),y)
18*4882a593SmuzhiyunKBUILD_CFLAGS_MODULE += -mcmodel=medany
19*4882a593Smuzhiyunendif
20*4882a593Smuzhiyun
21*4882a593Smuzhiyunexport BITS
22*4882a593Smuzhiyunifeq ($(CONFIG_ARCH_RV64I),y)
23*4882a593Smuzhiyun	BITS := 64
24*4882a593Smuzhiyun	UTS_MACHINE := riscv64
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun	KBUILD_CFLAGS += -mabi=lp64
27*4882a593Smuzhiyun	KBUILD_AFLAGS += -mabi=lp64
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun	KBUILD_LDFLAGS += -melf64lriscv
30*4882a593Smuzhiyunelse
31*4882a593Smuzhiyun	BITS := 32
32*4882a593Smuzhiyun	UTS_MACHINE := riscv32
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun	KBUILD_CFLAGS += -mabi=ilp32
35*4882a593Smuzhiyun	KBUILD_AFLAGS += -mabi=ilp32
36*4882a593Smuzhiyun	KBUILD_LDFLAGS += -melf32lriscv
37*4882a593Smuzhiyunendif
38*4882a593Smuzhiyun
39*4882a593Smuzhiyunifeq ($(CONFIG_LD_IS_LLD),y)
40*4882a593Smuzhiyunifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0)
41*4882a593Smuzhiyun	KBUILD_CFLAGS += -mno-relax
42*4882a593Smuzhiyun	KBUILD_AFLAGS += -mno-relax
43*4882a593Smuzhiyunifneq ($(LLVM_IAS),1)
44*4882a593Smuzhiyun	KBUILD_CFLAGS += -Wa,-mno-relax
45*4882a593Smuzhiyun	KBUILD_AFLAGS += -Wa,-mno-relax
46*4882a593Smuzhiyunendif
47*4882a593Smuzhiyunendif
48*4882a593Smuzhiyunendif
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun# ISA string setting
51*4882a593Smuzhiyunriscv-march-$(CONFIG_ARCH_RV32I)	:= rv32ima
52*4882a593Smuzhiyunriscv-march-$(CONFIG_ARCH_RV64I)	:= rv64ima
53*4882a593Smuzhiyunriscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
54*4882a593Smuzhiyunriscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun# Newer binutils versions default to ISA spec version 20191213 which moves some
57*4882a593Smuzhiyun# instructions from the I extension to the Zicsr and Zifencei extensions.
58*4882a593Smuzhiyuntoolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
59*4882a593Smuzhiyunriscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunKBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
62*4882a593SmuzhiyunKBUILD_AFLAGS += -march=$(riscv-march-y)
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunKBUILD_CFLAGS += -mno-save-restore
65*4882a593SmuzhiyunKBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
66*4882a593Smuzhiyun
67*4882a593Smuzhiyunifeq ($(CONFIG_CMODEL_MEDLOW),y)
68*4882a593Smuzhiyun	KBUILD_CFLAGS += -mcmodel=medlow
69*4882a593Smuzhiyunendif
70*4882a593Smuzhiyunifeq ($(CONFIG_CMODEL_MEDANY),y)
71*4882a593Smuzhiyun	KBUILD_CFLAGS += -mcmodel=medany
72*4882a593Smuzhiyunendif
73*4882a593Smuzhiyunifeq ($(CONFIG_PERF_EVENTS),y)
74*4882a593Smuzhiyun        KBUILD_CFLAGS += -fno-omit-frame-pointer
75*4882a593Smuzhiyunendif
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunKBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
78*4882a593SmuzhiyunKBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun# GCC versions that support the "-mstrict-align" option default to allowing
81*4882a593Smuzhiyun# unaligned accesses.  While unaligned accesses are explicitly allowed in the
82*4882a593Smuzhiyun# RISC-V ISA, they're emulated by machine mode traps on all extant
83*4882a593Smuzhiyun# architectures.  It's faster to have GCC emit only aligned accesses.
84*4882a593SmuzhiyunKBUILD_CFLAGS += $(call cc-option,-mstrict-align)
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun# arch specific predefines for sparse
87*4882a593SmuzhiyunCHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun# Default target when executing plain make
90*4882a593Smuzhiyunboot		:= arch/riscv/boot
91*4882a593SmuzhiyunKBUILD_IMAGE	:= $(boot)/Image.gz
92*4882a593Smuzhiyun
93*4882a593Smuzhiyunhead-y := arch/riscv/kernel/head.o
94*4882a593Smuzhiyun
95*4882a593Smuzhiyuncore-y += arch/riscv/
96*4882a593Smuzhiyun
97*4882a593Smuzhiyunlibs-y += arch/riscv/lib/
98*4882a593Smuzhiyunlibs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
99*4882a593Smuzhiyun
100*4882a593SmuzhiyunPHONY += vdso_install
101*4882a593Smuzhiyunvdso_install:
102*4882a593Smuzhiyun	$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
103*4882a593Smuzhiyun
104*4882a593Smuzhiyunifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_KENDRYTE),yy)
105*4882a593SmuzhiyunKBUILD_IMAGE := $(boot)/loader.bin
106*4882a593Smuzhiyunelse
107*4882a593SmuzhiyunKBUILD_IMAGE := $(boot)/Image.gz
108*4882a593Smuzhiyunendif
109*4882a593SmuzhiyunBOOT_TARGETS := Image Image.gz loader loader.bin
110*4882a593Smuzhiyun
111*4882a593Smuzhiyunall:	$(notdir $(KBUILD_IMAGE))
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun$(BOOT_TARGETS): vmlinux
114*4882a593Smuzhiyun	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
115*4882a593Smuzhiyun	@$(kecho) '  Kernel: $(boot)/$@ is ready'
116*4882a593Smuzhiyun
117*4882a593Smuzhiyunzinstall install:
118*4882a593Smuzhiyun	$(Q)$(MAKE) $(build)=$(boot) $@
119