Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 += arch/powerpc/lib/crtsavres.o
  52. endif
  53. ifdef CONFIG_CPU_LITTLE_ENDIAN
  54. KBUILD_CFLAGS += -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_CFLAGS += $(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_CFLAGS += -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
  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. CC_FLAGS_FTRACE := -fpatchable-function-entry=2
  129. else
  130. CC_FLAGS_FTRACE := -pg
  131. ifdef CONFIG_MPROFILE_KERNEL
  132. CC_FLAGS_FTRACE += -mprofile-kernel
  133. endif
  134. endif
  135. endif
  136. CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += -mcpu=$(CONFIG_TARGET_CPU)
  137. AFLAGS-$(CONFIG_TARGET_CPU_BOOL) += -mcpu=$(CONFIG_TARGET_CPU)
  138. CFLAGS-y += $(CONFIG_TUNE_CPU)
  139. asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
  140. KBUILD_CPPFLAGS += -I $(srctree)/arch/powerpc $(asinstr)
  141. KBUILD_AFLAGS += $(AFLAGS-y)
  142. KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU)
  143. KBUILD_CFLAGS += $(CFLAGS-y)
  144. CPP = $(CC) -E $(KBUILD_CFLAGS)
  145. CHECKFLAGS += -m$(BITS) -D__powerpc__ -D__powerpc$(BITS)__
  146. ifdef CONFIG_CPU_BIG_ENDIAN
  147. CHECKFLAGS += -D__BIG_ENDIAN__
  148. else
  149. CHECKFLAGS += -D__LITTLE_ENDIAN__
  150. endif
  151. ifdef CONFIG_476FPE_ERR46
  152. KBUILD_LDFLAGS_MODULE += --ppc476-workaround \
  153. -T $(srctree)/arch/powerpc/platforms/44x/ppc476_modules.lds
  154. endif
  155. # No prefix or pcrel
  156. ifdef CONFIG_PPC_KERNEL_PREFIXED
  157. KBUILD_CFLAGS += $(call cc-option,-mprefixed)
  158. else
  159. KBUILD_CFLAGS += $(call cc-option,-mno-prefixed)
  160. endif
  161. ifdef CONFIG_PPC_KERNEL_PCREL
  162. KBUILD_CFLAGS += $(call cc-option,-mpcrel)
  163. else
  164. KBUILD_CFLAGS += $(call cc-option,-mno-pcrel)
  165. endif
  166. # No AltiVec or VSX or MMA instructions when building kernel
  167. KBUILD_CFLAGS += $(call cc-option,-mno-altivec)
  168. KBUILD_CFLAGS += $(call cc-option,-mno-vsx)
  169. KBUILD_CFLAGS += $(call cc-option,-mno-mma)
  170. # No SPE instruction when building kernel
  171. # (We use all available options to help semi-broken compilers)
  172. KBUILD_CFLAGS += $(call cc-option,-mno-spe)
  173. KBUILD_CFLAGS += $(call cc-option,-mspe=no)
  174. # Don't emit .eh_frame since we have no use for it
  175. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  176. # Never use string load/store instructions as they are
  177. # often slow when they are implemented at all
  178. KBUILD_CFLAGS += $(call cc-option,-mno-string)
  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/powerpc/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. include $(srctree)/scripts/Makefile.defconf
  196. generated_configs += ppc64le_defconfig
  197. ppc64le_defconfig:
  198. $(call merge_into_defconfig,ppc64_defconfig,le)
  199. generated_configs += ppc64le_guest_defconfig
  200. ppc64le_guest_defconfig:
  201. $(call merge_into_defconfig,ppc64_defconfig,le guest kvm_guest)
  202. generated_configs += ppc64_guest_defconfig
  203. ppc64_guest_defconfig:
  204. $(call merge_into_defconfig,ppc64_defconfig,be guest kvm_guest)
  205. generated_configs += pseries_le_defconfig
  206. pseries_le_defconfig: ppc64le_guest_defconfig
  207. generated_configs += pseries_defconfig
  208. pseries_defconfig: ppc64le_guest_defconfig
  209. generated_configs += powernv_be_defconfig
  210. powernv_be_defconfig:
  211. $(call merge_into_defconfig,powernv_defconfig,be)
  212. generated_configs += mpc85xx_defconfig
  213. mpc85xx_defconfig:
  214. $(call merge_into_defconfig,mpc85xx_base.config,\
  215. 85xx-32bit 85xx-hw fsl-emb-nonhw)
  216. generated_configs += mpc85xx_smp_defconfig
  217. mpc85xx_smp_defconfig:
  218. $(call merge_into_defconfig,mpc85xx_base.config,\
  219. 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw)
  220. generated_configs += corenet32_smp_defconfig
  221. corenet32_smp_defconfig:
  222. $(call merge_into_defconfig,corenet_base.config,\
  223. 85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw dpaa)
  224. generated_configs += corenet64_smp_defconfig
  225. corenet64_smp_defconfig:
  226. $(call merge_into_defconfig,corenet_base.config,\
  227. 85xx-64bit 85xx-smp altivec 85xx-hw fsl-emb-nonhw dpaa)
  228. generated_configs += mpc86xx_defconfig
  229. mpc86xx_defconfig:
  230. $(call merge_into_defconfig,mpc86xx_base.config,\
  231. 86xx-hw fsl-emb-nonhw)
  232. generated_configs += mpc86xx_smp_defconfig
  233. mpc86xx_smp_defconfig:
  234. $(call merge_into_defconfig,mpc86xx_base.config,\
  235. 86xx-smp 86xx-hw fsl-emb-nonhw)
  236. generated_configs += ppc32_allmodconfig
  237. ppc32_allmodconfig:
  238. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/book3s_32.config \
  239. -f $(srctree)/Makefile allmodconfig
  240. generated_configs += ppc44x_allmodconfig
  241. ppc44x_allmodconfig:
  242. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/44x.config \
  243. -f $(srctree)/Makefile allmodconfig
  244. generated_configs += ppc8xx_allmodconfig
  245. ppc8xx_allmodconfig:
  246. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/8xx.config \
  247. -f $(srctree)/Makefile allmodconfig
  248. generated_configs += ppc85xx_allmodconfig
  249. ppc85xx_allmodconfig:
  250. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-32bit.config \
  251. -f $(srctree)/Makefile allmodconfig
  252. generated_configs += ppc_defconfig
  253. ppc_defconfig:
  254. $(call merge_into_defconfig,book3s_32.config,)
  255. generated_configs += ppc64le_allmodconfig
  256. ppc64le_allmodconfig:
  257. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/le.config \
  258. -f $(srctree)/Makefile allmodconfig
  259. generated_configs += ppc64le_allnoconfig
  260. ppc64le_allnoconfig:
  261. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/ppc64le.config \
  262. -f $(srctree)/Makefile allnoconfig
  263. generated_configs += ppc64_book3e_allmodconfig
  264. ppc64_book3e_allmodconfig:
  265. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-64bit.config \
  266. -f $(srctree)/Makefile allmodconfig
  267. generated_configs += ppc32_randconfig
  268. ppc32_randconfig:
  269. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/32-bit.config \
  270. -f $(srctree)/Makefile randconfig
  271. generated_configs += ppc64_randconfig
  272. ppc64_randconfig:
  273. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/64-bit.config \
  274. -f $(srctree)/Makefile randconfig
  275. PHONY += $(generated_configs)
  276. define archhelp
  277. echo '* zImage - Build default images selected by kernel config'
  278. echo ' zImage.* - Compressed kernel image (arch/powerpc/boot/zImage.*)'
  279. echo ' uImage - U-Boot native image format'
  280. echo ' cuImage.<dt> - Backwards compatible U-Boot image for older'
  281. echo ' versions which do not support device trees'
  282. echo ' dtbImage.<dt> - zImage with an embedded device tree blob'
  283. echo ' simpleImage.<dt> - Firmware independent image.'
  284. echo ' treeImage.<dt> - Support for older IBM 4xx firmware (not U-Boot)'
  285. echo ' install - Install kernel using'
  286. echo ' (your) ~/bin/$(INSTALLKERNEL) or'
  287. echo ' (distribution) /sbin/$(INSTALLKERNEL) or'
  288. echo ' install to $$(INSTALL_PATH) and run lilo'
  289. echo ' *_defconfig - Select default config from arch/powerpc/configs'
  290. echo ''
  291. echo ' Targets with <dt> embed a device tree blob inside the image'
  292. echo ' These targets support board with firmware that does not'
  293. echo ' support passing a device tree directly. Replace <dt> with the'
  294. echo ' name of a dts file from the arch/powerpc/boot/dts/ directory'
  295. echo ' (minus the .dts extension).'
  296. echo
  297. $(foreach cfg,$(generated_configs),
  298. printf " %-27s - Build for %s\\n" $(cfg) $(subst _defconfig,,$(cfg));)
  299. endef
  300. PHONY += install
  301. install:
  302. $(call cmd,install)
  303. ifeq ($(KBUILD_EXTMOD),)
  304. # We need to generate vdso-offsets.h before compiling certain files in kernel/.
  305. # In order to do that, we should use the archprepare target, but we can't since
  306. # asm-offsets.h is included in some files used to generate vdso-offsets.h, and
  307. # asm-offsets.h is built in prepare0, for which archprepare is a dependency.
  308. # Therefore we need to generate the header after prepare0 has been made, hence
  309. # this hack.
  310. prepare: vdso_prepare
  311. vdso_prepare: prepare0
  312. $(if $(CONFIG_VDSO32),$(Q)$(MAKE) \
  313. $(build)=arch/powerpc/kernel/vdso include/generated/vdso32-offsets.h)
  314. $(if $(CONFIG_PPC64),$(Q)$(MAKE) \
  315. $(build)=arch/powerpc/kernel/vdso include/generated/vdso64-offsets.h)
  316. endif
  317. archprepare: checkbin
  318. archheaders:
  319. $(Q)$(MAKE) $(build)=arch/powerpc/kernel/syscalls all
  320. ifdef CONFIG_STACKPROTECTOR
  321. prepare: stack_protector_prepare
  322. PHONY += stack_protector_prepare
  323. stack_protector_prepare: prepare0
  324. ifdef CONFIG_PPC64
  325. $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls -mstack-protector-guard-reg=r13 \
  326. -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
  327. else
  328. $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls -mstack-protector-guard-reg=r2 \
  329. -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
  330. endif
  331. endif
  332. PHONY += checkbin
  333. checkbin:
  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