blob: 1bb1bf1141cc7fb482afa72bcfc6450c36b9a116 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001# This file is included by the global makefile so that you can add your own
2# architecture-specific flags and dependencies. Remember to do have actions
3# for "archclean" and "archdep" for cleaning up and making dependencies for
4# this architecture
5#
6# This file is subject to the terms and conditions of the GNU General Public
7# License. See the file "COPYING" in the main directory of this archive
8# for more details.
9#
10
11OBJCOPYFLAGS := -O binary
12LDFLAGS_vmlinux :=
13ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
14 LDFLAGS_vmlinux := --no-relax
15endif
Olivier Deprez157378f2022-04-04 15:47:50 +020016
17ifeq ($(CONFIG_CMODEL_MEDLOW),y)
18KBUILD_CFLAGS_MODULE += -mcmodel=medany
19endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000021export BITS
22ifeq ($(CONFIG_ARCH_RV64I),y)
23 BITS := 64
24 UTS_MACHINE := riscv64
25
26 KBUILD_CFLAGS += -mabi=lp64
27 KBUILD_AFLAGS += -mabi=lp64
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000028
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029 KBUILD_LDFLAGS += -melf64lriscv
30else
31 BITS := 32
32 UTS_MACHINE := riscv32
33
34 KBUILD_CFLAGS += -mabi=ilp32
35 KBUILD_AFLAGS += -mabi=ilp32
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000036 KBUILD_LDFLAGS += -melf32lriscv
37endif
38
Olivier Deprez0e641232021-09-23 10:07:05 +020039ifeq ($(CONFIG_LD_IS_LLD),y)
Olivier Deprez92d4c212022-12-06 15:05:30 +010040ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0)
Olivier Deprez0e641232021-09-23 10:07:05 +020041 KBUILD_CFLAGS += -mno-relax
42 KBUILD_AFLAGS += -mno-relax
43ifneq ($(LLVM_IAS),1)
44 KBUILD_CFLAGS += -Wa,-mno-relax
45 KBUILD_AFLAGS += -Wa,-mno-relax
46endif
47endif
Olivier Deprez92d4c212022-12-06 15:05:30 +010048endif
Olivier Deprez0e641232021-09-23 10:07:05 +020049
David Brazdil0f672f62019-12-10 10:32:29 +000050# ISA string setting
51riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
52riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
53riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
54riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
Olivier Deprez157378f2022-04-04 15:47:50 +020055
56# Newer binutils versions default to ISA spec version 20191213 which moves some
57# instructions from the I extension to the Zicsr and Zifencei extensions.
58toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
59riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
60
David Brazdil0f672f62019-12-10 10:32:29 +000061KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
62KBUILD_AFLAGS += -march=$(riscv-march-y)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000063
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064KBUILD_CFLAGS += -mno-save-restore
65KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
66
67ifeq ($(CONFIG_CMODEL_MEDLOW),y)
68 KBUILD_CFLAGS += -mcmodel=medlow
69endif
70ifeq ($(CONFIG_CMODEL_MEDANY),y)
71 KBUILD_CFLAGS += -mcmodel=medany
72endif
David Brazdil0f672f62019-12-10 10:32:29 +000073ifeq ($(CONFIG_PERF_EVENTS),y)
74 KBUILD_CFLAGS += -fno-omit-frame-pointer
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000075endif
76
77KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
Olivier Deprez92d4c212022-12-06 15:05:30 +010078KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000079
80# GCC versions that support the "-mstrict-align" option default to allowing
81# unaligned accesses. While unaligned accesses are explicitly allowed in the
82# RISC-V ISA, they're emulated by machine mode traps on all extant
83# architectures. It's faster to have GCC emit only aligned accesses.
84KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
85
86# arch specific predefines for sparse
87CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
88
David Brazdil0f672f62019-12-10 10:32:29 +000089# Default target when executing plain make
90boot := arch/riscv/boot
91KBUILD_IMAGE := $(boot)/Image.gz
92
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000093head-y := arch/riscv/kernel/head.o
94
David Brazdil0f672f62019-12-10 10:32:29 +000095core-y += arch/riscv/
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000096
97libs-y += arch/riscv/lib/
Olivier Deprez157378f2022-04-04 15:47:50 +020098libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000099
100PHONY += vdso_install
101vdso_install:
102 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
103
Olivier Deprez157378f2022-04-04 15:47:50 +0200104ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_KENDRYTE),yy)
105KBUILD_IMAGE := $(boot)/loader.bin
106else
107KBUILD_IMAGE := $(boot)/Image.gz
108endif
109BOOT_TARGETS := Image Image.gz loader loader.bin
David Brazdil0f672f62019-12-10 10:32:29 +0000110
Olivier Deprez157378f2022-04-04 15:47:50 +0200111all: $(notdir $(KBUILD_IMAGE))
David Brazdil0f672f62019-12-10 10:32:29 +0000112
Olivier Deprez157378f2022-04-04 15:47:50 +0200113$(BOOT_TARGETS): vmlinux
David Brazdil0f672f62019-12-10 10:32:29 +0000114 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
Olivier Deprez157378f2022-04-04 15:47:50 +0200115 @$(kecho) ' Kernel: $(boot)/$@ is ready'
David Brazdil0f672f62019-12-10 10:32:29 +0000116
117zinstall install:
118 $(Q)$(MAKE) $(build)=$(boot) $@