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