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