Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. # This file is included by the global makefile so that you can add your own
  2. # architecture-specific flags and dependencies.
  3. #
  4. # This file is subject to the terms and conditions of the GNU General Public
  5. # License. See the file "COPYING" in the main directory of this archive
  6. # for more details.
  7. #
  8. # Copyright (C) 1994 by Linus Torvalds
  9. # Changes for PPC by Gary Thomas
  10. # Rewritten by Cort Dougan and Paul Mackerras
  11. #
  12. HAS_BIARCH := $(call cc-option-yn, -m32)
  13. # Set default 32 bits cross compilers for vdso and boot wrapper
  14. CROSS32_COMPILE ?=
  15. # If we're on a ppc/ppc64/ppc64le machine use that defconfig, otherwise just use
  16. # ppc64_defconfig because we have nothing better to go on.
  17. uname := $(shell uname -m)
  18. KBUILD_DEFCONFIG := $(if $(filter ppc%,$(uname)),$(uname),ppc64)_defconfig
  19. new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi)
  20. ifeq ($(new_nm),y)
  21. NM := $(NM) --synthetic
  22. endif
  23. # BITS is used as extension for files which are available in a 32 bit
  24. # and a 64 bit version to simplify shared Makefiles.
  25. # e.g.: obj-y += foo_$(BITS).o
  26. export BITS
  27. ifdef CONFIG_PPC64
  28. BITS := 64
  29. else
  30. BITS := 32
  31. endif
  32. machine-y = ppc
  33. machine-$(CONFIG_PPC64) += 64
  34. machine-$(CONFIG_CPU_LITTLE_ENDIAN) += le
  35. UTS_MACHINE := $(subst $(space),,$(machine-y))
  36. # XXX This needs to be before we override LD below
  37. ifdef CONFIG_PPC32
  38. KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
  39. else
  40. ifeq ($(call ld-ifversion, -ge, 22500, y),y)
  41. # Have the linker provide sfpr if possible.
  42. # There is a corresponding test in arch/powerpc/lib/Makefile
  43. KBUILD_LDFLAGS_MODULE += --save-restore-funcs
  44. else
  45. KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
  46. endif
  47. endif
  48. ifdef CONFIG_CPU_LITTLE_ENDIAN
  49. KBUILD_CFLAGS += -mlittle-endian
  50. KBUILD_LDFLAGS += -EL
  51. LDEMULATION := lppc
  52. GNUTARGET := powerpcle
  53. MULTIPLEWORD := -mno-multiple
  54. KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
  55. else
  56. KBUILD_CFLAGS += $(call cc-option,-mbig-endian)
  57. KBUILD_LDFLAGS += -EB
  58. LDEMULATION := ppc
  59. GNUTARGET := powerpc
  60. MULTIPLEWORD := -mmultiple
  61. endif
  62. ifdef CONFIG_PPC64
  63. ifndef CONFIG_CC_IS_CLANG
  64. cflags-$(CONFIG_PPC64_ELF_ABI_V1) += $(call cc-option,-mabi=elfv1)
  65. cflags-$(CONFIG_PPC64_ELF_ABI_V1) += $(call cc-option,-mcall-aixdesc)
  66. aflags-$(CONFIG_PPC64_ELF_ABI_V1) += $(call cc-option,-mabi=elfv1)
  67. aflags-$(CONFIG_PPC64_ELF_ABI_V2) += -mabi=elfv2
  68. endif
  69. endif
  70. ifndef CONFIG_CC_IS_CLANG
  71. cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align
  72. endif
  73. cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
  74. cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
  75. aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
  76. aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
  77. ifeq ($(HAS_BIARCH),y)
  78. KBUILD_CFLAGS += -m$(BITS)
  79. KBUILD_AFLAGS += -m$(BITS)
  80. KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION)
  81. endif
  82. cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls
  83. ifdef CONFIG_PPC64
  84. cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r13
  85. else
  86. cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2
  87. endif
  88. LDFLAGS_vmlinux-y := -Bstatic
  89. LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
  90. LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) += -z notext
  91. LDFLAGS_vmlinux := $(LDFLAGS_vmlinux-y)
  92. ifdef CONFIG_PPC64
  93. ifeq ($(call cc-option-yn,-mcmodel=medium),y)
  94. # -mcmodel=medium breaks modules because it uses 32bit offsets from
  95. # the TOC pointer to create pointers where possible. Pointers into the
  96. # percpu data area are created by this method.
  97. #
  98. # The kernel module loader relocates the percpu data section from the
  99. # original location (starting with 0xd...) to somewhere in the base
  100. # kernel percpu data space (starting with 0xc...). We need a full
  101. # 64bit relocation for this to work, hence -mcmodel=large.
  102. KBUILD_CFLAGS_MODULE += -mcmodel=large
  103. else
  104. export NO_MINIMAL_TOC := -mno-minimal-toc
  105. endif
  106. endif
  107. CFLAGS-$(CONFIG_PPC64) := $(call cc-option,-mtraceback=no)
  108. ifndef CONFIG_CC_IS_CLANG
  109. ifdef CONFIG_PPC64_ELF_ABI_V2
  110. CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2,$(call cc-option,-mcall-aixdesc))
  111. AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2)
  112. else
  113. CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
  114. CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcall-aixdesc)
  115. AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
  116. endif
  117. endif
  118. CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcmodel=medium,$(call cc-option,-mminimal-toc))
  119. CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mno-pointers-to-nested-functions)
  120. # Clang unconditionally reserves r2 on ppc32 and does not support the flag
  121. # https://bugs.llvm.org/show_bug.cgi?id=39555
  122. CFLAGS-$(CONFIG_PPC32) := $(call cc-option, -ffixed-r2)
  123. # Clang doesn't support -mmultiple / -mno-multiple
  124. # https://bugs.llvm.org/show_bug.cgi?id=39556
  125. CFLAGS-$(CONFIG_PPC32) += $(call cc-option, $(MULTIPLEWORD))
  126. CFLAGS-$(CONFIG_PPC32) += $(call cc-option,-mno-readonly-in-sdata)
  127. ifdef CONFIG_FUNCTION_TRACER
  128. CC_FLAGS_FTRACE := -pg
  129. ifdef CONFIG_MPROFILE_KERNEL
  130. CC_FLAGS_FTRACE += -mprofile-kernel
  131. endif
  132. endif
  133. CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += -mcpu=$(CONFIG_TARGET_CPU)
  134. AFLAGS-$(CONFIG_TARGET_CPU_BOOL) += -mcpu=$(CONFIG_TARGET_CPU)
  135. CFLAGS-$(CONFIG_POWERPC64_CPU) += $(call cc-option,-mtune=power10, \
  136. $(call cc-option,-mtune=power9, \
  137. $(call cc-option,-mtune=power8)))
  138. asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
  139. KBUILD_CPPFLAGS += -I $(srctree)/arch/$(ARCH) $(asinstr)
  140. KBUILD_AFLAGS += $(AFLAGS-y)
  141. KBUILD_CFLAGS += $(call cc-option,-msoft-float)
  142. KBUILD_CFLAGS += -pipe $(CFLAGS-y)
  143. CPP = $(CC) -E $(KBUILD_CFLAGS)
  144. CHECKFLAGS += -m$(BITS) -D__powerpc__ -D__powerpc$(BITS)__
  145. ifdef CONFIG_CPU_BIG_ENDIAN
  146. CHECKFLAGS += -D__BIG_ENDIAN__
  147. else
  148. CHECKFLAGS += -D__LITTLE_ENDIAN__
  149. endif
  150. ifdef CONFIG_476FPE_ERR46
  151. KBUILD_LDFLAGS_MODULE += --ppc476-workaround \
  152. -T $(srctree)/arch/powerpc/platforms/44x/ppc476_modules.lds
  153. endif
  154. # No prefix or pcrel
  155. KBUILD_CFLAGS += $(call cc-option,-mno-prefixed)
  156. KBUILD_CFLAGS += $(call cc-option,-mno-pcrel)
  157. # No AltiVec or VSX or MMA instructions when building kernel
  158. KBUILD_CFLAGS += $(call cc-option,-mno-altivec)
  159. KBUILD_CFLAGS += $(call cc-option,-mno-vsx)
  160. KBUILD_CFLAGS += $(call cc-option,-mno-mma)
  161. # No SPE instruction when building kernel
  162. # (We use all available options to help semi-broken compilers)
  163. KBUILD_CFLAGS += $(call cc-option,-mno-spe)
  164. KBUILD_CFLAGS += $(call cc-option,-mspe=no)
  165. # Don't emit .eh_frame since we have no use for it
  166. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  167. # Never use string load/store instructions as they are
  168. # often slow when they are implemented at all
  169. KBUILD_CFLAGS += $(call cc-option,-mno-string)
  170. cpu-as-$(CONFIG_ALTIVEC) += $(call as-option,-Wa$(comma)-maltivec)
  171. # When using '-many -mpower4' gas will first try and find a matching power4
  172. # mnemonic and failing that it will allow any valid mnemonic that GAS knows
  173. # about. GCC will pass -many to GAS when assembling, clang does not.
  174. # LLVM IAS doesn't understand either flag: https://github.com/ClangBuiltLinux/linux/issues/675
  175. # but LLVM IAS only supports ISA >= 2.06 for Book3S 64 anyway...
  176. cpu-as-$(CONFIG_PPC_BOOK3S_64) += $(call as-option,-Wa$(comma)-mpower4) $(call as-option,-Wa$(comma)-many)
  177. KBUILD_AFLAGS += $(cpu-as-y)
  178. KBUILD_CFLAGS += $(cpu-as-y)
  179. KBUILD_AFLAGS += $(aflags-y)
  180. KBUILD_CFLAGS += $(cflags-y)
  181. # Default to zImage, override when needed
  182. all: zImage
  183. # With make 3.82 we cannot mix normal and wildcard targets
  184. BOOT_TARGETS1 := zImage zImage.initrd uImage
  185. BOOT_TARGETS2 := zImage% dtbImage% treeImage.% cuImage.% simpleImage.% uImage.%
  186. PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2)
  187. boot := arch/$(ARCH)/boot
  188. $(BOOT_TARGETS1): vmlinux
  189. $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
  190. $(BOOT_TARGETS2): vmlinux
  191. $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
  192. PHONY += bootwrapper_install
  193. bootwrapper_install:
  194. $(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
  195. # Used to create 'merged defconfigs'
  196. # To use it $(call) it with the first argument as the base defconfig
  197. # and the second argument as a space separated list of .config files to merge,
  198. # without the .config suffix.
  199. define merge_into_defconfig
  200. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
  201. -m -O $(objtree) $(srctree)/arch/$(ARCH)/configs/$(1) \
  202. $(foreach config,$(2),$(srctree)/arch/$(ARCH)/configs/$(config).config)
  203. +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
  204. endef
  205. PHONY += pseries_le_defconfig
  206. pseries_le_defconfig:
  207. $(call merge_into_defconfig,pseries_defconfig,le)
  208. PHONY += ppc64le_defconfig
  209. ppc64le_defconfig:
  210. $(call merge_into_defconfig,ppc64_defconfig,le)
  211. PHONY += ppc64le_guest_defconfig
  212. ppc64le_guest_defconfig:
  213. $(call merge_into_defconfig,ppc64_defconfig,le guest)
  214. PHONY += ppc64_guest_defconfig
  215. ppc64_guest_defconfig:
  216. $(call merge_into_defconfig,ppc64_defconfig,be guest)
  217. PHONY += powernv_be_defconfig
  218. powernv_be_defconfig:
  219. $(call merge_into_defconfig,powernv_defconfig,be)
  220. PHONY += mpc85xx_defconfig
  221. mpc85xx_defconfig:
  222. $(call merge_into_defconfig,mpc85xx_base.config,\
  223. 85xx-32bit 85xx-hw fsl-emb-nonhw)
  224. PHONY += mpc85xx_smp_defconfig
  225. mpc85xx_smp_defconfig:
  226. $(call merge_into_defconfig,mpc85xx_base.config,\
  227. 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw)
  228. PHONY += corenet32_smp_defconfig
  229. corenet32_smp_defconfig:
  230. $(call merge_into_defconfig,corenet_base.config,\
  231. 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw dpaa)
  232. PHONY += corenet64_smp_defconfig
  233. corenet64_smp_defconfig:
  234. $(call merge_into_defconfig,corenet_base.config,\
  235. 85xx-64bit 85xx-smp altivec 85xx-hw fsl-emb-nonhw dpaa)
  236. PHONY += mpc86xx_defconfig
  237. mpc86xx_defconfig:
  238. $(call merge_into_defconfig,mpc86xx_base.config,\
  239. 86xx-hw fsl-emb-nonhw)
  240. PHONY += mpc86xx_smp_defconfig
  241. mpc86xx_smp_defconfig:
  242. $(call merge_into_defconfig,mpc86xx_base.config,\
  243. 86xx-smp 86xx-hw fsl-emb-nonhw)
  244. PHONY += ppc32_allmodconfig
  245. ppc32_allmodconfig:
  246. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/book3s_32.config \
  247. -f $(srctree)/Makefile allmodconfig
  248. PHONY += ppc_defconfig
  249. ppc_defconfig:
  250. $(call merge_into_defconfig,book3s_32.config,)
  251. PHONY += ppc64le_allmodconfig
  252. ppc64le_allmodconfig:
  253. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/le.config \
  254. -f $(srctree)/Makefile allmodconfig
  255. PHONY += ppc64le_allnoconfig
  256. ppc64le_allnoconfig:
  257. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/ppc64le.config \
  258. -f $(srctree)/Makefile allnoconfig
  259. PHONY += ppc64_book3e_allmodconfig
  260. ppc64_book3e_allmodconfig:
  261. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-64bit.config \
  262. -f $(srctree)/Makefile allmodconfig
  263. PHONY += ppc32_randconfig
  264. ppc32_randconfig:
  265. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/32-bit.config \
  266. -f $(srctree)/Makefile randconfig
  267. PHONY += ppc64_randconfig
  268. ppc64_randconfig:
  269. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/64-bit.config \
  270. -f $(srctree)/Makefile randconfig
  271. define archhelp
  272. @echo '* zImage - Build default images selected by kernel config'
  273. @echo ' zImage.* - Compressed kernel image (arch/$(ARCH)/boot/zImage.*)'
  274. @echo ' uImage - U-Boot native image format'
  275. @echo ' cuImage.<dt> - Backwards compatible U-Boot image for older'
  276. @echo ' versions which do not support device trees'
  277. @echo ' dtbImage.<dt> - zImage with an embedded device tree blob'
  278. @echo ' simpleImage.<dt> - Firmware independent image.'
  279. @echo ' treeImage.<dt> - Support for older IBM 4xx firmware (not U-Boot)'
  280. @echo ' install - Install kernel using'
  281. @echo ' (your) ~/bin/$(INSTALLKERNEL) or'
  282. @echo ' (distribution) /sbin/$(INSTALLKERNEL) or'
  283. @echo ' install to $$(INSTALL_PATH) and run lilo'
  284. @echo ' *_defconfig - Select default config from arch/$(ARCH)/configs'
  285. @echo ''
  286. @echo ' Targets with <dt> embed a device tree blob inside the image'
  287. @echo ' These targets support board with firmware that does not'
  288. @echo ' support passing a device tree directly. Replace <dt> with the'
  289. @echo ' name of a dts file from the arch/$(ARCH)/boot/dts/ directory'
  290. @echo ' (minus the .dts extension).'
  291. endef
  292. PHONY += install
  293. install:
  294. $(call cmd,install)
  295. ifeq ($(KBUILD_EXTMOD),)
  296. # We need to generate vdso-offsets.h before compiling certain files in kernel/.
  297. # In order to do that, we should use the archprepare target, but we can't since
  298. # asm-offsets.h is included in some files used to generate vdso-offsets.h, and
  299. # asm-offsets.h is built in prepare0, for which archprepare is a dependency.
  300. # Therefore we need to generate the header after prepare0 has been made, hence
  301. # this hack.
  302. prepare: vdso_prepare
  303. vdso_prepare: prepare0
  304. $(if $(CONFIG_VDSO32),$(Q)$(MAKE) \
  305. $(build)=arch/powerpc/kernel/vdso include/generated/vdso32-offsets.h)
  306. $(if $(CONFIG_PPC64),$(Q)$(MAKE) \
  307. $(build)=arch/powerpc/kernel/vdso include/generated/vdso64-offsets.h)
  308. endif
  309. archprepare: checkbin
  310. archheaders:
  311. $(Q)$(MAKE) $(build)=arch/powerpc/kernel/syscalls all
  312. ifdef CONFIG_STACKPROTECTOR
  313. prepare: stack_protector_prepare
  314. PHONY += stack_protector_prepare
  315. stack_protector_prepare: prepare0
  316. ifdef CONFIG_PPC64
  317. $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
  318. else
  319. $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
  320. endif
  321. endif
  322. PHONY += checkbin
  323. # Check toolchain versions:
  324. # - gcc-4.6 is the minimum kernel-wide version so nothing required.
  325. checkbin:
  326. @if test "x${CONFIG_LD_IS_LLD}" != "xy" -a \
  327. "x$(call ld-ifversion, -le, 22400, y)" = "xy" ; then \
  328. echo -n '*** binutils 2.24 miscompiles weak symbols ' ; \
  329. echo 'in some circumstances.' ; \
  330. echo '*** binutils 2.23 do not define the TOC symbol ' ; \
  331. echo -n '*** Please use a different binutils version.' ; \
  332. false ; \
  333. fi
  334. @if test "x${CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT}" = "xy" -a \
  335. "x${CONFIG_LD_IS_BFD}" = "xy" -a \
  336. "${CONFIG_LD_VERSION}" = "23700" ; then \
  337. echo -n '*** binutils 2.37 drops unused section symbols, which recordmcount ' ; \
  338. echo 'is unable to handle.' ; \
  339. echo '*** Please use a different binutils version.' ; \
  340. false ; \
  341. fi