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