0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 HAS_BIARCH := $(call cc-option-yn, -m32)
0014
0015
0016 CROSS32_COMPILE ?=
0017
0018
0019
0020 uname := $(shell uname -m)
0021 KBUILD_DEFCONFIG := $(if $(filter ppc%,$(uname)),$(uname),ppc64)_defconfig
0022
0023 new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi)
0024
0025 ifeq ($(new_nm),y)
0026 NM := $(NM) --synthetic
0027 endif
0028
0029
0030
0031
0032 export BITS
0033
0034 ifdef CONFIG_PPC64
0035 BITS := 64
0036 else
0037 BITS := 32
0038 endif
0039
0040 machine-y = ppc
0041 machine-$(CONFIG_PPC64) += 64
0042 machine-$(CONFIG_CPU_LITTLE_ENDIAN) += le
0043 UTS_MACHINE := $(subst $(space),,$(machine-y))
0044
0045
0046 ifdef CONFIG_PPC32
0047 KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
0048 else
0049 ifeq ($(call ld-ifversion, -ge, 22500, y),y)
0050
0051
0052 KBUILD_LDFLAGS_MODULE += --save-restore-funcs
0053 else
0054 KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
0055 endif
0056 endif
0057
0058 ifdef CONFIG_CPU_LITTLE_ENDIAN
0059 KBUILD_CFLAGS += -mlittle-endian
0060 KBUILD_LDFLAGS += -EL
0061 LDEMULATION := lppc
0062 GNUTARGET := powerpcle
0063 MULTIPLEWORD := -mno-multiple
0064 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
0065 else
0066 KBUILD_CFLAGS += $(call cc-option,-mbig-endian)
0067 KBUILD_LDFLAGS += -EB
0068 LDEMULATION := ppc
0069 GNUTARGET := powerpc
0070 MULTIPLEWORD := -mmultiple
0071 endif
0072
0073 ifdef CONFIG_PPC64
0074 ifndef CONFIG_CC_IS_CLANG
0075 cflags-$(CONFIG_PPC64_ELF_ABI_V1) += $(call cc-option,-mabi=elfv1)
0076 cflags-$(CONFIG_PPC64_ELF_ABI_V1) += $(call cc-option,-mcall-aixdesc)
0077 aflags-$(CONFIG_PPC64_ELF_ABI_V1) += $(call cc-option,-mabi=elfv1)
0078 aflags-$(CONFIG_PPC64_ELF_ABI_V2) += -mabi=elfv2
0079 endif
0080 endif
0081
0082 ifndef CONFIG_CC_IS_CLANG
0083 cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align
0084 endif
0085
0086 cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
0087 cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
0088 aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
0089 aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
0090
0091 ifeq ($(HAS_BIARCH),y)
0092 KBUILD_CFLAGS += -m$(BITS)
0093 KBUILD_AFLAGS += -m$(BITS) -Wl,-a$(BITS)
0094 KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION)
0095 endif
0096
0097 cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls
0098 ifdef CONFIG_PPC64
0099 cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r13
0100 else
0101 cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2
0102 endif
0103
0104 LDFLAGS_vmlinux-y := -Bstatic
0105 LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
0106 LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) += -z notext
0107 LDFLAGS_vmlinux := $(LDFLAGS_vmlinux-y)
0108
0109 ifdef CONFIG_PPC64
0110 ifeq ($(call cc-option-yn,-mcmodel=medium),y)
0111
0112
0113
0114
0115
0116
0117
0118
0119 KBUILD_CFLAGS_MODULE += -mcmodel=large
0120 else
0121 export NO_MINIMAL_TOC := -mno-minimal-toc
0122 endif
0123 endif
0124
0125 CFLAGS-$(CONFIG_PPC64) := $(call cc-option,-mtraceback=no)
0126 ifndef CONFIG_CC_IS_CLANG
0127 ifdef CONFIG_PPC64_ELF_ABI_V2
0128 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2,$(call cc-option,-mcall-aixdesc))
0129 AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2)
0130 else
0131 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
0132 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcall-aixdesc)
0133 AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
0134 endif
0135 endif
0136 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcmodel=medium,$(call cc-option,-mminimal-toc))
0137 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mno-pointers-to-nested-functions)
0138
0139
0140
0141 CFLAGS-$(CONFIG_PPC32) := $(call cc-option, -ffixed-r2)
0142
0143
0144
0145 CFLAGS-$(CONFIG_PPC32) += $(call cc-option, $(MULTIPLEWORD))
0146
0147 CFLAGS-$(CONFIG_PPC32) += $(call cc-option,-mno-readonly-in-sdata)
0148
0149 ifdef CONFIG_PPC_BOOK3S_64
0150 ifdef CONFIG_CPU_LITTLE_ENDIAN
0151 CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=power8
0152 CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=power9,-mtune=power8)
0153 else
0154 CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=power7,$(call cc-option,-mtune=power5))
0155 CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mcpu=power5,-mcpu=power4)
0156 endif
0157 else ifdef CONFIG_PPC_BOOK3E_64
0158 CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64
0159 endif
0160
0161 ifdef CONFIG_FUNCTION_TRACER
0162 CC_FLAGS_FTRACE := -pg
0163 ifdef CONFIG_MPROFILE_KERNEL
0164 CC_FLAGS_FTRACE += -mprofile-kernel
0165 endif
0166 endif
0167
0168 CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call cc-option,-mcpu=$(CONFIG_TARGET_CPU))
0169 AFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call cc-option,-mcpu=$(CONFIG_TARGET_CPU))
0170
0171 CFLAGS-$(CONFIG_E5500_CPU) += $(call cc-option,-mcpu=e500mc64,-mcpu=powerpc64)
0172 CFLAGS-$(CONFIG_E6500_CPU) += $(call cc-option,-mcpu=e6500,$(E5500_CPU))
0173
0174 asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
0175
0176 KBUILD_CPPFLAGS += -I $(srctree)/arch/$(ARCH) $(asinstr)
0177 KBUILD_AFLAGS += $(AFLAGS-y)
0178 KBUILD_CFLAGS += $(call cc-option,-msoft-float)
0179 KBUILD_CFLAGS += -pipe $(CFLAGS-y)
0180 CPP = $(CC) -E $(KBUILD_CFLAGS)
0181
0182 CHECKFLAGS += -m$(BITS) -D__powerpc__ -D__powerpc$(BITS)__
0183 ifdef CONFIG_CPU_BIG_ENDIAN
0184 CHECKFLAGS += -D__BIG_ENDIAN__
0185 else
0186 CHECKFLAGS += -D__LITTLE_ENDIAN__
0187 endif
0188
0189 ifdef CONFIG_476FPE_ERR46
0190 KBUILD_LDFLAGS_MODULE += --ppc476-workaround \
0191 -T $(srctree)/arch/powerpc/platforms/44x/ppc476_modules.lds
0192 endif
0193
0194
0195 KBUILD_CFLAGS += $(call cc-option,-mno-altivec)
0196 KBUILD_CFLAGS += $(call cc-option,-mno-vsx)
0197
0198
0199
0200 KBUILD_CFLAGS += $(call cc-option,-mno-spe)
0201 KBUILD_CFLAGS += $(call cc-option,-mspe=no)
0202
0203
0204 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
0205
0206
0207
0208 KBUILD_CFLAGS += $(call cc-option,-mno-string)
0209
0210 cpu-as-$(CONFIG_40x) += -Wa,-m405
0211 cpu-as-$(CONFIG_44x) += -Wa,-m440
0212 cpu-as-$(CONFIG_ALTIVEC) += $(call as-option,-Wa$(comma)-maltivec)
0213 cpu-as-$(CONFIG_E500) += -Wa,-me500
0214
0215
0216
0217
0218
0219
0220 cpu-as-$(CONFIG_PPC_BOOK3S_64) += $(call as-option,-Wa$(comma)-mpower4) $(call as-option,-Wa$(comma)-many)
0221 cpu-as-$(CONFIG_PPC_E500MC) += $(call as-option,-Wa$(comma)-me500mc)
0222
0223 KBUILD_AFLAGS += $(cpu-as-y)
0224 KBUILD_CFLAGS += $(cpu-as-y)
0225
0226 KBUILD_AFLAGS += $(aflags-y)
0227 KBUILD_CFLAGS += $(cflags-y)
0228
0229 head-$(CONFIG_PPC64) := arch/powerpc/kernel/head_64.o
0230 head-$(CONFIG_PPC_BOOK3S_32) := arch/powerpc/kernel/head_book3s_32.o
0231 head-$(CONFIG_PPC_8xx) := arch/powerpc/kernel/head_8xx.o
0232 head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o
0233 head-$(CONFIG_44x) := arch/powerpc/kernel/head_44x.o
0234 head-$(CONFIG_FSL_BOOKE) := arch/powerpc/kernel/head_fsl_booke.o
0235
0236 head-$(CONFIG_PPC64) += arch/powerpc/kernel/entry_64.o
0237 head-$(CONFIG_PPC_FPU) += arch/powerpc/kernel/fpu.o
0238 head-$(CONFIG_ALTIVEC) += arch/powerpc/kernel/vector.o
0239 head-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += arch/powerpc/kernel/prom_init.o
0240
0241
0242 all: zImage
0243
0244
0245 BOOT_TARGETS1 := zImage zImage.initrd uImage
0246 BOOT_TARGETS2 := zImage% dtbImage% treeImage.% cuImage.% simpleImage.% uImage.%
0247
0248 PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2)
0249
0250 boot := arch/$(ARCH)/boot
0251
0252 $(BOOT_TARGETS1): vmlinux
0253 $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
0254 $(BOOT_TARGETS2): vmlinux
0255 $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
0256
0257
0258 PHONY += bootwrapper_install
0259 bootwrapper_install:
0260 $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
0261
0262
0263
0264
0265
0266 define merge_into_defconfig
0267 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
0268 -m -O $(objtree) $(srctree)/arch/$(ARCH)/configs/$(1) \
0269 $(foreach config,$(2),$(srctree)/arch/$(ARCH)/configs/$(config).config)
0270 +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
0271 endef
0272
0273 PHONY += pseries_le_defconfig
0274 pseries_le_defconfig:
0275 $(call merge_into_defconfig,pseries_defconfig,le)
0276
0277 PHONY += ppc64le_defconfig
0278 ppc64le_defconfig:
0279 $(call merge_into_defconfig,ppc64_defconfig,le)
0280
0281 PHONY += ppc64le_guest_defconfig
0282 ppc64le_guest_defconfig:
0283 $(call merge_into_defconfig,ppc64_defconfig,le guest)
0284
0285 PHONY += ppc64_guest_defconfig
0286 ppc64_guest_defconfig:
0287 $(call merge_into_defconfig,ppc64_defconfig,be guest)
0288
0289 PHONY += powernv_be_defconfig
0290 powernv_be_defconfig:
0291 $(call merge_into_defconfig,powernv_defconfig,be)
0292
0293 PHONY += mpc85xx_defconfig
0294 mpc85xx_defconfig:
0295 $(call merge_into_defconfig,mpc85xx_base.config,\
0296 85xx-32bit 85xx-hw fsl-emb-nonhw)
0297
0298 PHONY += mpc85xx_smp_defconfig
0299 mpc85xx_smp_defconfig:
0300 $(call merge_into_defconfig,mpc85xx_base.config,\
0301 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw)
0302
0303 PHONY += corenet32_smp_defconfig
0304 corenet32_smp_defconfig:
0305 $(call merge_into_defconfig,corenet_base.config,\
0306 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw dpaa)
0307
0308 PHONY += corenet64_smp_defconfig
0309 corenet64_smp_defconfig:
0310 $(call merge_into_defconfig,corenet_base.config,\
0311 85xx-64bit 85xx-smp altivec 85xx-hw fsl-emb-nonhw dpaa)
0312
0313 PHONY += mpc86xx_defconfig
0314 mpc86xx_defconfig:
0315 $(call merge_into_defconfig,mpc86xx_base.config,\
0316 86xx-hw fsl-emb-nonhw)
0317
0318 PHONY += mpc86xx_smp_defconfig
0319 mpc86xx_smp_defconfig:
0320 $(call merge_into_defconfig,mpc86xx_base.config,\
0321 86xx-smp 86xx-hw fsl-emb-nonhw)
0322
0323 PHONY += ppc32_allmodconfig
0324 ppc32_allmodconfig:
0325 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/book3s_32.config \
0326 -f $(srctree)/Makefile allmodconfig
0327
0328 PHONY += ppc_defconfig
0329 ppc_defconfig:
0330 $(call merge_into_defconfig,book3s_32.config,)
0331
0332 PHONY += ppc64le_allmodconfig
0333 ppc64le_allmodconfig:
0334 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/le.config \
0335 -f $(srctree)/Makefile allmodconfig
0336
0337 PHONY += ppc64le_allnoconfig
0338 ppc64le_allnoconfig:
0339 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/ppc64le.config \
0340 -f $(srctree)/Makefile allnoconfig
0341
0342 PHONY += ppc64_book3e_allmodconfig
0343 ppc64_book3e_allmodconfig:
0344 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-64bit.config \
0345 -f $(srctree)/Makefile allmodconfig
0346
0347 PHONY += ppc32_randconfig
0348 ppc32_randconfig:
0349 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/32-bit.config \
0350 -f $(srctree)/Makefile randconfig
0351
0352 PHONY += ppc64_randconfig
0353 ppc64_randconfig:
0354 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/64-bit.config \
0355 -f $(srctree)/Makefile randconfig
0356
0357 define archhelp
0358 @echo '* zImage - Build default images selected by kernel config'
0359 @echo ' zImage.* - Compressed kernel image (arch/$(ARCH)/boot/zImage.*)'
0360 @echo ' uImage - U-Boot native image format'
0361 @echo ' cuImage.<dt> - Backwards compatible U-Boot image for older'
0362 @echo ' versions which do not support device trees'
0363 @echo ' dtbImage.<dt> - zImage with an embedded device tree blob'
0364 @echo ' simpleImage.<dt> - Firmware independent image.'
0365 @echo ' treeImage.<dt> - Support for older IBM 4xx firmware (not U-Boot)'
0366 @echo ' install - Install kernel using'
0367 @echo ' (your) ~/bin/$(INSTALLKERNEL) or'
0368 @echo ' (distribution) /sbin/$(INSTALLKERNEL) or'
0369 @echo ' install to $$(INSTALL_PATH) and run lilo'
0370 @echo ' *_defconfig - Select default config from arch/$(ARCH)/configs'
0371 @echo ''
0372 @echo ' Targets with <dt> embed a device tree blob inside the image'
0373 @echo ' These targets support board with firmware that does not'
0374 @echo ' support passing a device tree directly. Replace <dt> with the'
0375 @echo ' name of a dts file from the arch/$(ARCH)/boot/dts/ directory'
0376 @echo ' (minus the .dts extension).'
0377 endef
0378
0379 PHONY += install
0380 install:
0381 $(call cmd,install)
0382
0383 ifeq ($(KBUILD_EXTMOD),)
0384
0385
0386
0387
0388
0389
0390 prepare: vdso_prepare
0391 vdso_prepare: prepare0
0392 $(if $(CONFIG_VDSO32),$(Q)$(MAKE) \
0393 $(build)=arch/powerpc/kernel/vdso include/generated/vdso32-offsets.h)
0394 $(if $(CONFIG_PPC64),$(Q)$(MAKE) \
0395 $(build)=arch/powerpc/kernel/vdso include/generated/vdso64-offsets.h)
0396 endif
0397
0398 archprepare: checkbin
0399
0400 archheaders:
0401 $(Q)$(MAKE) $(build)=arch/powerpc/kernel/syscalls all
0402
0403 ifdef CONFIG_STACKPROTECTOR
0404 prepare: stack_protector_prepare
0405
0406 PHONY += stack_protector_prepare
0407 stack_protector_prepare: prepare0
0408 ifdef CONFIG_PPC64
0409 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
0410 else
0411 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
0412 endif
0413 endif
0414
0415 PHONY += checkbin
0416
0417
0418 checkbin:
0419 @if test "x${CONFIG_LD_IS_LLD}" != "xy" -a \
0420 "x$(call ld-ifversion, -le, 22400, y)" = "xy" ; then \
0421 echo -n '*** binutils 2.24 miscompiles weak symbols ' ; \
0422 echo 'in some circumstances.' ; \
0423 echo '*** binutils 2.23 do not define the TOC symbol ' ; \
0424 echo -n '*** Please use a different binutils version.' ; \
0425 false ; \
0426 fi