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