Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Author: Huacai Chen <[email protected]>
  4. # Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  5. boot := arch/loongarch/boot
  6. KBUILD_DEFCONFIG := loongson3_defconfig
  7. image-name-y := vmlinux
  8. image-name-$(CONFIG_EFI_ZBOOT) := vmlinuz
  9. ifndef CONFIG_EFI_STUB
  10. KBUILD_IMAGE := $(boot)/vmlinux.elf
  11. else
  12. KBUILD_IMAGE := $(boot)/$(image-name-y).efi
  13. endif
  14. #
  15. # Select the object file format to substitute into the linker script.
  16. #
  17. 64bit-tool-archpref = loongarch64
  18. 32bit-bfd = elf32-loongarch
  19. 64bit-bfd = elf64-loongarch
  20. 32bit-emul = elf32loongarch
  21. 64bit-emul = elf64loongarch
  22. ifdef CONFIG_64BIT
  23. tool-archpref = $(64bit-tool-archpref)
  24. UTS_MACHINE := loongarch64
  25. endif
  26. ifneq ($(SUBARCH),$(ARCH))
  27. ifeq ($(CROSS_COMPILE),)
  28. CROSS_COMPILE := $(call cc-cross-prefix, $(tool-archpref)-linux- $(tool-archpref)-linux-gnu- $(tool-archpref)-unknown-linux-gnu-)
  29. endif
  30. endif
  31. ifdef CONFIG_64BIT
  32. ld-emul = $(64bit-emul)
  33. cflags-y += -mabi=lp64s
  34. endif
  35. cflags-y += -G0 -pipe -msoft-float
  36. LDFLAGS_vmlinux += -G0 -static -n -nostdlib
  37. # When the assembler supports explicit relocation hint, we must use it.
  38. # GCC may have -mexplicit-relocs off by default if it was built with an old
  39. # assembler, so we force it via an option.
  40. #
  41. # When the assembler does not supports explicit relocation hint, we can't use
  42. # it. Disable it if the compiler supports it.
  43. #
  44. # If you've seen "unknown reloc hint" message building the kernel and you are
  45. # now wondering why "-mexplicit-relocs" is not wrapped with cc-option: the
  46. # combination of a "new" assembler and "old" compiler is not supported. Either
  47. # upgrade the compiler or downgrade the assembler.
  48. ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
  49. cflags-y += -mexplicit-relocs
  50. KBUILD_CFLAGS_KERNEL += -mdirect-extern-access
  51. else
  52. cflags-y += $(call cc-option,-mno-explicit-relocs)
  53. KBUILD_AFLAGS_KERNEL += -Wa,-mla-global-with-pcrel
  54. KBUILD_CFLAGS_KERNEL += -Wa,-mla-global-with-pcrel
  55. KBUILD_AFLAGS_MODULE += -Wa,-mla-global-with-abs
  56. KBUILD_CFLAGS_MODULE += -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
  57. endif
  58. cflags-y += -ffreestanding
  59. cflags-y += $(call cc-option, -mno-check-zero-division)
  60. ifndef CONFIG_PHYSICAL_START
  61. load-y = 0x9000000000200000
  62. else
  63. load-y = $(CONFIG_PHYSICAL_START)
  64. endif
  65. bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y)
  66. drivers-$(CONFIG_PCI) += arch/loongarch/pci/
  67. KBUILD_AFLAGS += $(cflags-y)
  68. KBUILD_CFLAGS += $(cflags-y)
  69. KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y)
  70. # This is required to get dwarf unwinding tables into .debug_frame
  71. # instead of .eh_frame so we don't discard them.
  72. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  73. # Don't emit unaligned accesses.
  74. # Not all LoongArch cores support unaligned access, and as kernel we can't
  75. # rely on others to provide emulation for these accesses.
  76. KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
  77. KBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)
  78. KBUILD_LDFLAGS += -m $(ld-emul)
  79. ifdef CONFIG_LOONGARCH
  80. CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
  81. grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
  82. sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
  83. endif
  84. libs-y += arch/loongarch/lib/
  85. libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  86. ifeq ($(KBUILD_EXTMOD),)
  87. prepare: vdso_prepare
  88. vdso_prepare: prepare0
  89. $(Q)$(MAKE) $(build)=arch/loongarch/vdso include/generated/vdso-offsets.h
  90. endif
  91. PHONY += vdso_install
  92. vdso_install:
  93. $(Q)$(MAKE) $(build)=arch/loongarch/vdso $@
  94. all: $(notdir $(KBUILD_IMAGE))
  95. vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux
  96. $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@
  97. install:
  98. $(Q)install -D -m 755 $(KBUILD_IMAGE) $(INSTALL_PATH)/$(image-name-y)-$(KERNELRELEASE)
  99. $(Q)install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE)
  100. $(Q)install -D -m 644 System.map $(INSTALL_PATH)/System.map-$(KERNELRELEASE)
  101. define archhelp
  102. echo ' install - install kernel into $(INSTALL_PATH)'
  103. echo
  104. endef