Makefile 14 KB

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