Makefile 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Author: Huacai Chen <chenhuacai@loongson.cn>
  4. # Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  5. boot := arch/loongarch/boot
  6. KBUILD_DEFCONFIG := loongson3_defconfig
  7. KBUILD_DTBS := dtbs
  8. image-name-y := vmlinux
  9. image-name-$(CONFIG_EFI_ZBOOT) := vmlinuz
  10. ifndef CONFIG_EFI_STUB
  11. KBUILD_IMAGE := $(boot)/vmlinux.elf
  12. else
  13. KBUILD_IMAGE := $(boot)/$(image-name-y).efi
  14. endif
  15. #
  16. # Select the object file format to substitute into the linker script.
  17. #
  18. 64bit-tool-archpref = loongarch64
  19. 32bit-bfd = elf32-loongarch
  20. 64bit-bfd = elf64-loongarch
  21. 32bit-emul = elf32loongarch
  22. 64bit-emul = elf64loongarch
  23. CC_FLAGS_FPU := -mfpu=64
  24. CC_FLAGS_NO_FPU := -msoft-float
  25. ifdef CONFIG_UNWINDER_ORC
  26. orc_hash_h := arch/$(SRCARCH)/include/generated/asm/orc_hash.h
  27. orc_hash_sh := $(srctree)/scripts/orc_hash.sh
  28. targets += $(orc_hash_h)
  29. quiet_cmd_orc_hash = GEN $@
  30. cmd_orc_hash = mkdir -p $(dir $@); \
  31. $(CONFIG_SHELL) $(orc_hash_sh) < $< > $@
  32. $(orc_hash_h): $(srctree)/arch/loongarch/include/asm/orc_types.h $(orc_hash_sh) FORCE
  33. $(call if_changed,orc_hash)
  34. archprepare: $(orc_hash_h)
  35. endif
  36. ifdef CONFIG_DYNAMIC_FTRACE
  37. KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  38. CC_FLAGS_FTRACE := -fpatchable-function-entry=2
  39. endif
  40. ifdef CONFIG_64BIT
  41. tool-archpref = $(64bit-tool-archpref)
  42. UTS_MACHINE := loongarch64
  43. endif
  44. ifneq ($(SUBARCH),$(ARCH))
  45. ifeq ($(CROSS_COMPILE),)
  46. CROSS_COMPILE := $(call cc-cross-prefix, $(tool-archpref)-linux- $(tool-archpref)-linux-gnu- $(tool-archpref)-unknown-linux-gnu-)
  47. endif
  48. endif
  49. ifdef CONFIG_64BIT
  50. ld-emul = $(64bit-emul)
  51. cflags-y += -mabi=lp64s -mcmodel=normal
  52. endif
  53. cflags-y += -pipe $(CC_FLAGS_NO_FPU)
  54. LDFLAGS_vmlinux += -static -n -nostdlib
  55. # When the assembler supports explicit relocation hint, we must use it.
  56. # GCC may have -mexplicit-relocs off by default if it was built with an old
  57. # assembler, so we force it via an option.
  58. #
  59. # When the assembler does not supports explicit relocation hint, we can't use
  60. # it. Disable it if the compiler supports it.
  61. #
  62. # The combination of a "new" assembler and "old" GCC is not supported, given
  63. # the rarity of this combo and the extra complexity needed to make it work.
  64. # Either upgrade the compiler or downgrade the assembler; the build will error
  65. # out if it is the case (by probing for the model attribute; all supported
  66. # compilers in this case would have support).
  67. #
  68. # Also, -mdirect-extern-access is useful in case of building with explicit
  69. # relocs, for avoiding unnecessary GOT accesses. It is harmless to not have
  70. # support though.
  71. ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
  72. cflags-y += $(call cc-option,-mexplicit-relocs)
  73. KBUILD_CFLAGS_KERNEL += $(call cc-option,-mdirect-extern-access)
  74. KBUILD_CFLAGS_KERNEL += $(call cc-option,-fdirect-access-external-data)
  75. KBUILD_AFLAGS_MODULE += $(call cc-option,-fno-direct-access-external-data)
  76. KBUILD_CFLAGS_MODULE += $(call cc-option,-fno-direct-access-external-data)
  77. else
  78. cflags-y += $(call cc-option,-mno-explicit-relocs)
  79. KBUILD_AFLAGS_KERNEL += -Wa,-mla-global-with-pcrel
  80. KBUILD_CFLAGS_KERNEL += -Wa,-mla-global-with-pcrel
  81. KBUILD_AFLAGS_MODULE += -Wa,-mla-global-with-abs
  82. KBUILD_CFLAGS_MODULE += -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
  83. endif
  84. KBUILD_AFLAGS += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
  85. KBUILD_CFLAGS += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
  86. KBUILD_AFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
  87. KBUILD_CFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
  88. ifdef CONFIG_OBJTOOL
  89. KBUILD_CFLAGS += -fno-jump-tables
  90. endif
  91. KBUILD_RUSTFLAGS += --target=loongarch64-unknown-none-softfloat -Ccode-model=small
  92. KBUILD_RUSTFLAGS_KERNEL += -Zdirect-access-external-data=yes
  93. KBUILD_RUSTFLAGS_MODULE += -Zdirect-access-external-data=no
  94. ifeq ($(CONFIG_RELOCATABLE),y)
  95. KBUILD_CFLAGS_KERNEL += -fPIE
  96. KBUILD_RUSTFLAGS_KERNEL += -Crelocation-model=pie
  97. LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
  98. endif
  99. cflags-y += $(call cc-option, -mno-check-zero-division)
  100. ifndef CONFIG_KASAN
  101. cflags-y += -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset
  102. endif
  103. load-y = 0x9000000000200000
  104. bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y)
  105. drivers-$(CONFIG_PCI) += arch/loongarch/pci/
  106. KBUILD_AFLAGS += $(cflags-y)
  107. KBUILD_CFLAGS += $(cflags-y)
  108. KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y)
  109. # This is required to get dwarf unwinding tables into .debug_frame
  110. # instead of .eh_frame so we don't discard them.
  111. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  112. ifdef CONFIG_ARCH_STRICT_ALIGN
  113. # Don't emit unaligned accesses.
  114. # Not all LoongArch cores support unaligned access, and as kernel we can't
  115. # rely on others to provide emulation for these accesses.
  116. KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
  117. else
  118. # Optimise for performance on hardware supports unaligned access.
  119. KBUILD_CFLAGS += $(call cc-option,-mno-strict-align)
  120. endif
  121. KBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)
  122. KBUILD_LDFLAGS += -m $(ld-emul)
  123. ifdef need-compiler
  124. CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
  125. grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
  126. sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
  127. endif
  128. libs-y += arch/loongarch/lib/
  129. libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  130. drivers-y += arch/loongarch/crypto/
  131. # suspend and hibernation support
  132. drivers-$(CONFIG_PM) += arch/loongarch/power/
  133. ifeq ($(KBUILD_EXTMOD),)
  134. prepare: vdso_prepare
  135. vdso_prepare: prepare0
  136. $(Q)$(MAKE) $(build)=arch/loongarch/vdso include/generated/vdso-offsets.h
  137. endif
  138. vdso-install-y += arch/loongarch/vdso/vdso.so.dbg
  139. all: $(notdir $(KBUILD_IMAGE)) $(KBUILD_DTBS)
  140. vmlinuz.efi: vmlinux.efi
  141. vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux
  142. $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@
  143. install:
  144. $(Q)install -D -m 755 $(KBUILD_IMAGE) $(INSTALL_PATH)/$(image-name-y)-$(KERNELRELEASE)
  145. $(Q)install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE)
  146. $(Q)install -D -m 644 System.map $(INSTALL_PATH)/System.map-$(KERNELRELEASE)
  147. define archhelp
  148. echo ' install - install kernel into $(INSTALL_PATH)'
  149. echo
  150. endef