GNU Linux-libre 5.4.274-gnu1
[releases.git] / arch / powerpc / Makefile
1 # 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 # Copyright (C) 1994 by Linus Torvalds
11 # Changes for PPC by Gary Thomas
12 # Rewritten by Cort Dougan and Paul Mackerras
13 #
14
15 HAS_BIARCH      := $(call cc-option-yn, -m32)
16
17 # Set default 32 bits cross compilers for vdso and boot wrapper
18 CROSS32_COMPILE ?=
19
20 # If we're on a ppc/ppc64/ppc64le machine use that defconfig, otherwise just use
21 # ppc64_defconfig because we have nothing better to go on.
22 uname := $(shell uname -m)
23 KBUILD_DEFCONFIG := $(if $(filter ppc%,$(uname)),$(uname),ppc64)_defconfig
24
25 new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi)
26
27 ifeq ($(new_nm),y)
28 NM              := $(NM) --synthetic
29 endif
30
31 # BITS is used as extension for files which are available in a 32 bit
32 # and a 64 bit version to simplify shared Makefiles.
33 # e.g.: obj-y += foo_$(BITS).o
34 export BITS
35
36 ifdef CONFIG_PPC64
37         BITS := 64
38 else
39         BITS := 32
40 endif
41
42 machine-y = ppc
43 machine-$(CONFIG_PPC64) += 64
44 machine-$(CONFIG_CPU_LITTLE_ENDIAN) += le
45 UTS_MACHINE := $(subst $(space),,$(machine-y))
46
47 # XXX This needs to be before we override LD below
48 ifdef CONFIG_PPC32
49 KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
50 else
51 KBUILD_LDS_MODULE += $(srctree)/arch/powerpc/kernel/module.lds
52 ifeq ($(call ld-ifversion, -ge, 225000000, y),y)
53 # Have the linker provide sfpr if possible.
54 # There is a corresponding test in arch/powerpc/lib/Makefile
55 KBUILD_LDFLAGS_MODULE += --save-restore-funcs
56 else
57 KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
58 endif
59 endif
60
61 ifdef CONFIG_CPU_LITTLE_ENDIAN
62 KBUILD_CFLAGS   += -mlittle-endian
63 KBUILD_LDFLAGS  += -EL
64 LDEMULATION     := lppc
65 GNUTARGET       := powerpcle
66 MULTIPLEWORD    := -mno-multiple
67 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
68 else
69 KBUILD_CFLAGS += $(call cc-option,-mbig-endian)
70 KBUILD_LDFLAGS  += -EB
71 LDEMULATION     := ppc
72 GNUTARGET       := powerpc
73 MULTIPLEWORD    := -mmultiple
74 endif
75
76 ifdef CONFIG_PPC64
77 ifndef CONFIG_CC_IS_CLANG
78 cflags-$(CONFIG_CPU_BIG_ENDIAN)         += $(call cc-option,-mabi=elfv1)
79 cflags-$(CONFIG_CPU_BIG_ENDIAN)         += $(call cc-option,-mcall-aixdesc)
80 aflags-$(CONFIG_CPU_BIG_ENDIAN)         += $(call cc-option,-mabi=elfv1)
81 aflags-$(CONFIG_CPU_LITTLE_ENDIAN)      += -mabi=elfv2
82 endif
83 endif
84
85 ifndef CONFIG_CC_IS_CLANG
86   cflags-$(CONFIG_CPU_LITTLE_ENDIAN)    += -mno-strict-align
87 endif
88
89 cflags-$(CONFIG_CPU_BIG_ENDIAN)         += $(call cc-option,-mbig-endian)
90 cflags-$(CONFIG_CPU_LITTLE_ENDIAN)      += -mlittle-endian
91 aflags-$(CONFIG_CPU_BIG_ENDIAN)         += $(call cc-option,-mbig-endian)
92 aflags-$(CONFIG_CPU_LITTLE_ENDIAN)      += -mlittle-endian
93
94 ifeq ($(HAS_BIARCH),y)
95 KBUILD_CFLAGS   += -m$(BITS)
96 KBUILD_AFLAGS   += -m$(BITS)
97 KBUILD_LDFLAGS  += -m elf$(BITS)$(LDEMULATION)
98 endif
99
100 cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls
101 ifdef CONFIG_PPC64
102 cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r13
103 else
104 cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2
105 endif
106
107 LDFLAGS_vmlinux-y := -Bstatic
108 LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
109 LDFLAGS_vmlinux := $(LDFLAGS_vmlinux-y)
110 LDFLAGS_vmlinux += $(call ld-option,--orphan-handling=warn)
111
112 ifdef CONFIG_PPC64
113 ifeq ($(call cc-option-yn,-mcmodel=medium),y)
114         # -mcmodel=medium breaks modules because it uses 32bit offsets from
115         # the TOC pointer to create pointers where possible. Pointers into the
116         # percpu data area are created by this method.
117         #
118         # The kernel module loader relocates the percpu data section from the
119         # original location (starting with 0xd...) to somewhere in the base
120         # kernel percpu data space (starting with 0xc...). We need a full
121         # 64bit relocation for this to work, hence -mcmodel=large.
122         KBUILD_CFLAGS_MODULE += -mcmodel=large
123 else
124         export NO_MINIMAL_TOC := -mno-minimal-toc
125 endif
126 endif
127
128 CFLAGS-$(CONFIG_PPC64)  := $(call cc-option,-mtraceback=no)
129 ifndef CONFIG_CC_IS_CLANG
130 ifdef CONFIG_CPU_LITTLE_ENDIAN
131 CFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mabi=elfv2,$(call cc-option,-mcall-aixdesc))
132 AFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mabi=elfv2)
133 else
134 CFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mabi=elfv1)
135 CFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mcall-aixdesc)
136 AFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mabi=elfv1)
137 endif
138 endif
139 CFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mcmodel=medium,$(call cc-option,-mminimal-toc))
140 CFLAGS-$(CONFIG_PPC64)  += $(call cc-option,-mno-pointers-to-nested-functions)
141
142 # Clang unconditionally reserves r2 on ppc32 and does not support the flag
143 # https://bugs.llvm.org/show_bug.cgi?id=39555
144 CFLAGS-$(CONFIG_PPC32)  := $(call cc-option, -ffixed-r2)
145
146 # Clang doesn't support -mmultiple / -mno-multiple
147 # https://bugs.llvm.org/show_bug.cgi?id=39556
148 CFLAGS-$(CONFIG_PPC32)  += $(call cc-option, $(MULTIPLEWORD))
149
150 CFLAGS-$(CONFIG_PPC32)  += $(call cc-option,-mno-readonly-in-sdata)
151
152 ifdef CONFIG_PPC_BOOK3S_64
153 ifdef CONFIG_CPU_LITTLE_ENDIAN
154 CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=power8
155 CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=power9,-mtune=power8)
156 else
157 CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=power7,$(call cc-option,-mtune=power5))
158 CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=power4
159 endif
160 else ifdef CONFIG_PPC_BOOK3E_64
161 CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64
162 endif
163
164 ifdef CONFIG_FUNCTION_TRACER
165 CC_FLAGS_FTRACE := -pg
166 ifdef CONFIG_MPROFILE_KERNEL
167 CC_FLAGS_FTRACE += -mprofile-kernel
168 endif
169 # Work around gcc code-gen bugs with -pg / -fno-omit-frame-pointer in gcc <= 4.8
170 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44199
171 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52828
172 ifndef CONFIG_CC_IS_CLANG
173 CC_FLAGS_FTRACE += $(call cc-ifversion, -lt, 0409, -mno-sched-epilog)
174 endif
175 endif
176
177 CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call cc-option,-mcpu=$(CONFIG_TARGET_CPU))
178 AFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call cc-option,-mcpu=$(CONFIG_TARGET_CPU))
179
180 # Altivec option not allowed with e500mc64 in GCC.
181 ifdef CONFIG_ALTIVEC
182 E5500_CPU := -mcpu=powerpc64
183 else
184 E5500_CPU := $(call cc-option,-mcpu=e500mc64,-mcpu=powerpc64)
185 endif
186 CFLAGS-$(CONFIG_E5500_CPU) += $(E5500_CPU)
187 CFLAGS-$(CONFIG_E6500_CPU) += $(call cc-option,-mcpu=e6500,$(E5500_CPU))
188
189 asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
190
191 KBUILD_CPPFLAGS += -I $(srctree)/arch/$(ARCH) $(asinstr)
192 KBUILD_AFLAGS   += $(AFLAGS-y)
193 KBUILD_CFLAGS   += $(call cc-option,-msoft-float)
194 KBUILD_CFLAGS   += -pipe $(CFLAGS-y)
195 CPP             = $(CC) -E $(KBUILD_CFLAGS)
196
197 CHECKFLAGS      += -m$(BITS) -D__powerpc__ -D__powerpc$(BITS)__
198 ifdef CONFIG_CPU_BIG_ENDIAN
199 CHECKFLAGS      += -D__BIG_ENDIAN__
200 else
201 CHECKFLAGS      += -D__LITTLE_ENDIAN__
202 endif
203
204 ifdef CONFIG_476FPE_ERR46
205         KBUILD_LDFLAGS_MODULE += --ppc476-workaround \
206                 -T $(srctree)/arch/powerpc/platforms/44x/ppc476_modules.lds
207 endif
208
209 # No AltiVec or VSX instructions when building kernel
210 KBUILD_CFLAGS += $(call cc-option,-mno-altivec)
211 KBUILD_CFLAGS += $(call cc-option,-mno-vsx)
212
213 # No SPE instruction when building kernel
214 # (We use all available options to help semi-broken compilers)
215 KBUILD_CFLAGS += $(call cc-option,-mno-spe)
216 KBUILD_CFLAGS += $(call cc-option,-mspe=no)
217
218 # FIXME: the module load should be taught about the additional relocs
219 # generated by this.
220 # revert to pre-gcc-4.4 behaviour of .eh_frame
221 KBUILD_CFLAGS   += $(call cc-option,-fno-dwarf2-cfi-asm)
222
223 # Never use string load/store instructions as they are
224 # often slow when they are implemented at all
225 KBUILD_CFLAGS           += $(call cc-option,-mno-string)
226
227 cpu-as-$(CONFIG_4xx)            += -Wa,-m405
228 cpu-as-$(CONFIG_ALTIVEC)        += $(call as-option,-Wa$(comma)-maltivec)
229 cpu-as-$(CONFIG_E500)           += -Wa,-me500
230
231 # When using '-many -mpower4' gas will first try and find a matching power4
232 # mnemonic and failing that it will allow any valid mnemonic that GAS knows
233 # about. GCC will pass -many to GAS when assembling, clang does not.
234 cpu-as-$(CONFIG_PPC_BOOK3S_64)  += -Wa,-mpower4 -Wa,-many
235 cpu-as-$(CONFIG_PPC_E500MC)     += $(call as-option,-Wa$(comma)-me500mc)
236
237 KBUILD_AFLAGS += $(cpu-as-y)
238 KBUILD_CFLAGS += $(cpu-as-y)
239
240 KBUILD_AFLAGS += $(aflags-y)
241 KBUILD_CFLAGS += $(cflags-y)
242
243 head-y                          := arch/powerpc/kernel/head_$(BITS).o
244 head-$(CONFIG_PPC_8xx)          := arch/powerpc/kernel/head_8xx.o
245 head-$(CONFIG_40x)              := arch/powerpc/kernel/head_40x.o
246 head-$(CONFIG_44x)              := arch/powerpc/kernel/head_44x.o
247 head-$(CONFIG_FSL_BOOKE)        := arch/powerpc/kernel/head_fsl_booke.o
248
249 head-$(CONFIG_PPC64)            += arch/powerpc/kernel/entry_64.o
250 head-$(CONFIG_PPC_FPU)          += arch/powerpc/kernel/fpu.o
251 head-$(CONFIG_ALTIVEC)          += arch/powerpc/kernel/vector.o
252 head-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE)  += arch/powerpc/kernel/prom_init.o
253
254 # See arch/powerpc/Kbuild for content of core part of the kernel
255 core-y += arch/powerpc/
256
257 drivers-$(CONFIG_OPROFILE)      += arch/powerpc/oprofile/
258
259 # Default to zImage, override when needed
260 all: zImage
261
262 # With make 3.82 we cannot mix normal and wildcard targets
263 BOOT_TARGETS1 := zImage zImage.initrd uImage
264 BOOT_TARGETS2 := zImage% dtbImage% treeImage.% cuImage.% simpleImage.% uImage.%
265
266 PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2)
267
268 boot := arch/$(ARCH)/boot
269
270 $(BOOT_TARGETS1): vmlinux
271         $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
272 $(BOOT_TARGETS2): vmlinux
273         $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
274
275
276 bootwrapper_install:
277         $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
278
279 # Used to create 'merged defconfigs'
280 # To use it $(call) it with the first argument as the base defconfig
281 # and the second argument as a space separated list of .config files to merge,
282 # without the .config suffix.
283 define merge_into_defconfig
284         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
285                 -m -O $(objtree) $(srctree)/arch/$(ARCH)/configs/$(1) \
286                 $(foreach config,$(2),$(srctree)/arch/$(ARCH)/configs/$(config).config)
287         +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
288 endef
289
290 PHONY += pseries_le_defconfig
291 pseries_le_defconfig:
292         $(call merge_into_defconfig,pseries_defconfig,le)
293
294 PHONY += ppc64le_defconfig
295 ppc64le_defconfig:
296         $(call merge_into_defconfig,ppc64_defconfig,le)
297
298 PHONY += ppc64le_guest_defconfig
299 ppc64le_guest_defconfig:
300         $(call merge_into_defconfig,ppc64_defconfig,le guest)
301
302 PHONY += ppc64_guest_defconfig
303 ppc64_guest_defconfig:
304         $(call merge_into_defconfig,ppc64_defconfig,be guest)
305
306 PHONY += powernv_be_defconfig
307 powernv_be_defconfig:
308         $(call merge_into_defconfig,powernv_defconfig,be)
309
310 PHONY += mpc85xx_defconfig
311 mpc85xx_defconfig:
312         $(call merge_into_defconfig,mpc85xx_basic_defconfig,\
313                 85xx-32bit 85xx-hw fsl-emb-nonhw)
314
315 PHONY += mpc85xx_smp_defconfig
316 mpc85xx_smp_defconfig:
317         $(call merge_into_defconfig,mpc85xx_basic_defconfig,\
318                 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw)
319
320 PHONY += corenet32_smp_defconfig
321 corenet32_smp_defconfig:
322         $(call merge_into_defconfig,corenet_basic_defconfig,\
323                 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw dpaa)
324
325 PHONY += corenet64_smp_defconfig
326 corenet64_smp_defconfig:
327         $(call merge_into_defconfig,corenet_basic_defconfig,\
328                 85xx-64bit 85xx-smp altivec 85xx-hw fsl-emb-nonhw dpaa)
329
330 PHONY += mpc86xx_defconfig
331 mpc86xx_defconfig:
332         $(call merge_into_defconfig,mpc86xx_basic_defconfig,\
333                 86xx-hw fsl-emb-nonhw)
334
335 PHONY += mpc86xx_smp_defconfig
336 mpc86xx_smp_defconfig:
337         $(call merge_into_defconfig,mpc86xx_basic_defconfig,\
338                 86xx-smp 86xx-hw fsl-emb-nonhw)
339
340 PHONY += ppc32_allmodconfig
341 ppc32_allmodconfig:
342         $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/book3s_32.config \
343                 -f $(srctree)/Makefile allmodconfig
344
345 PHONY += ppc_defconfig
346 ppc_defconfig:
347         $(call merge_into_defconfig,book3s_32.config,)
348
349 PHONY += ppc64le_allmodconfig
350 ppc64le_allmodconfig:
351         $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/le.config \
352                 -f $(srctree)/Makefile allmodconfig
353
354 PHONY += ppc64_book3e_allmodconfig
355 ppc64_book3e_allmodconfig:
356         $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-64bit.config \
357                 -f $(srctree)/Makefile allmodconfig
358
359 define archhelp
360   @echo '* zImage          - Build default images selected by kernel config'
361   @echo '  zImage.*        - Compressed kernel image (arch/$(ARCH)/boot/zImage.*)'
362   @echo '  uImage          - U-Boot native image format'
363   @echo '  cuImage.<dt>    - Backwards compatible U-Boot image for older'
364   @echo '                    versions which do not support device trees'
365   @echo '  dtbImage.<dt>   - zImage with an embedded device tree blob'
366   @echo '  simpleImage.<dt> - Firmware independent image.'
367   @echo '  treeImage.<dt>  - Support for older IBM 4xx firmware (not U-Boot)'
368   @echo '  install         - Install kernel using'
369   @echo '                    (your) ~/bin/$(INSTALLKERNEL) or'
370   @echo '                    (distribution) /sbin/$(INSTALLKERNEL) or'
371   @echo '                    install to $$(INSTALL_PATH) and run lilo'
372   @echo '  *_defconfig     - Select default config from arch/$(ARCH)/configs'
373   @echo ''
374   @echo '  Targets with <dt> embed a device tree blob inside the image'
375   @echo '  These targets support board with firmware that does not'
376   @echo '  support passing a device tree directly.  Replace <dt> with the'
377   @echo '  name of a dts file from the arch/$(ARCH)/boot/dts/ directory'
378   @echo '  (minus the .dts extension).'
379 endef
380
381 install:
382         $(Q)$(MAKE) $(build)=$(boot) install
383
384 vdso_install:
385 ifdef CONFIG_PPC64
386         $(Q)$(MAKE) $(build)=arch/$(ARCH)/kernel/vdso64 $@
387 endif
388 ifdef CONFIG_VDSO32
389         $(Q)$(MAKE) $(build)=arch/$(ARCH)/kernel/vdso32 $@
390 endif
391
392 archclean:
393         $(Q)$(MAKE) $(clean)=$(boot)
394
395 archprepare: checkbin
396
397 archheaders:
398         $(Q)$(MAKE) $(build)=arch/powerpc/kernel/syscalls all
399
400 ifdef CONFIG_STACKPROTECTOR
401 prepare: stack_protector_prepare
402
403 stack_protector_prepare: prepare0
404 ifdef CONFIG_PPC64
405         $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
406 else
407         $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
408 endif
409 endif
410
411 ifdef CONFIG_SMP
412 prepare: task_cpu_prepare
413
414 task_cpu_prepare: prepare0
415         $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TASK_CPU") print $$3;}' include/generated/asm-offsets.h))
416 endif
417
418 # Check toolchain versions:
419 # - gcc-4.6 is the minimum kernel-wide version so nothing required.
420 checkbin:
421         @if test "x${CONFIG_CPU_LITTLE_ENDIAN}" = "xy" \
422             && $(LD) --version | head -1 | grep ' 2\.24$$' >/dev/null ; then \
423                 echo -n '*** binutils 2.24 miscompiles weak symbols ' ; \
424                 echo 'in some circumstances.' ; \
425                 echo -n '*** Please use a different binutils version.' ; \
426                 false ; \
427         fi
428         @if test "x${CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT}" = "xy" -a \
429                 "x${CONFIG_LD_IS_BFD}" = "xy" -a \
430                 "${CONFIG_LD_VERSION}" = "23700" ; then \
431                 echo -n '*** binutils 2.37 drops unused section symbols, which recordmcount ' ; \
432                 echo 'is unable to handle.' ; \
433                 echo '*** Please use a different binutils version.' ; \
434                 false ; \
435         fi