Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # This file is included by the global makefile so that you can add your own
  2. # architecture-specific flags and dependencies. Remember to do have actions
  3. # for "archclean" and "archdep" for cleaning up and making dependencies for
  4. # this architecture
  5. #
  6. # This file is subject to the terms and conditions of the GNU General Public
  7. # License. See the file "COPYING" in the main directory of this archive
  8. # for more details.
  9. #
  10. OBJCOPYFLAGS := -O binary
  11. LDFLAGS_vmlinux :=
  12. ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
  13. LDFLAGS_vmlinux := --no-relax
  14. KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  15. CC_FLAGS_FTRACE := -fpatchable-function-entry=8
  16. endif
  17. ifeq ($(CONFIG_CMODEL_MEDLOW),y)
  18. KBUILD_CFLAGS_MODULE += -mcmodel=medany
  19. endif
  20. export BITS
  21. ifeq ($(CONFIG_ARCH_RV64I),y)
  22. BITS := 64
  23. UTS_MACHINE := riscv64
  24. KBUILD_CFLAGS += -mabi=lp64
  25. KBUILD_AFLAGS += -mabi=lp64
  26. KBUILD_LDFLAGS += -melf64lriscv
  27. else
  28. BITS := 32
  29. UTS_MACHINE := riscv32
  30. KBUILD_CFLAGS += -mabi=ilp32
  31. KBUILD_AFLAGS += -mabi=ilp32
  32. KBUILD_LDFLAGS += -melf32lriscv
  33. endif
  34. ifeq ($(CONFIG_LD_IS_LLD),y)
  35. KBUILD_CFLAGS += -mno-relax
  36. KBUILD_AFLAGS += -mno-relax
  37. ifneq ($(LLVM_IAS),1)
  38. KBUILD_CFLAGS += -Wa,-mno-relax
  39. KBUILD_AFLAGS += -Wa,-mno-relax
  40. endif
  41. endif
  42. # ISA string setting
  43. # Newer binutils versions default to ISA spec version 20191213 which moves some
  44. # instructions from the I extension to the Zicsr and Zifencei extensions.
  45. toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
  46. riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
  47. riscv-march-cflags-$(CONFIG_ARCH_RV32I) := rv32ima
  48. riscv-march-cflags-$(CONFIG_ARCH_RV64I) := rv64ima
  49. riscv-march-cflags-$(CONFIG_RISCV_ISA_C) := $(riscv-march-cflags-y)c
  50. riscv-march-aflags-$(CONFIG_ARCH_RV32I) := rv32ima
  51. riscv-march-aflags-$(CONFIG_ARCH_RV64I) := rv64ima
  52. riscv-march-aflags-$(CONFIG_FPU) := $(riscv-march-aflags-y)fd
  53. riscv-march-aflags-$(CONFIG_RISCV_ISA_C) := $(riscv-march-aflags-y)c
  54. riscv-march-aflags-$(CONFIG_VECTOR_1_0) := $(riscv-march-aflags-y)v
  55. riscv-march-aflags-$(CONFIG_VECTOR_0_7) := $(riscv-march-aflags-y)v0p7
  56. riscv-march-aflags-$(CONFIG_THEAD_ISA) := $(riscv-march-aflags-y)_xtheadc
  57. KBUILD_CFLAGS += -march=$(riscv-march-cflags-y) -Wa,-march=$(riscv-march-aflags-y)
  58. KBUILD_AFLAGS += -march=$(riscv-march-aflags-y)
  59. KBUILD_CFLAGS += -mno-save-restore
  60. KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
  61. ifeq ($(CONFIG_CMODEL_MEDLOW),y)
  62. KBUILD_CFLAGS += -mcmodel=medlow
  63. endif
  64. ifeq ($(CONFIG_CMODEL_MEDANY),y)
  65. KBUILD_CFLAGS += -mcmodel=medany
  66. endif
  67. ifeq ($(CONFIG_PERF_EVENTS),y)
  68. KBUILD_CFLAGS += -fno-omit-frame-pointer
  69. endif
  70. KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
  71. # GCC versions that support the "-mstrict-align" option default to allowing
  72. # unaligned accesses. While unaligned accesses are explicitly allowed in the
  73. # RISC-V ISA, they're emulated by machine mode traps on all extant
  74. # architectures. It's faster to have GCC emit only aligned accesses.
  75. KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
  76. # arch specific predefines for sparse
  77. CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
  78. # Default target when executing plain make
  79. boot := arch/riscv/boot
  80. KBUILD_IMAGE := $(boot)/Image.gz
  81. head-y := arch/riscv/kernel/head.o
  82. core-y += arch/riscv/
  83. core-$(CONFIG_KVM) += arch/riscv/kvm/
  84. libs-y += arch/riscv/lib/
  85. libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  86. PHONY += vdso_install
  87. vdso_install:
  88. $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
  89. $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
  90. $(build)=arch/riscv/kernel/compat_vdso $@)
  91. ifeq ($(KBUILD_EXTMOD),)
  92. ifeq ($(CONFIG_MMU),y)
  93. prepare: vdso_prepare
  94. vdso_prepare: prepare0
  95. $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
  96. $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
  97. $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
  98. endif
  99. endif
  100. ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_KENDRYTE),yy)
  101. KBUILD_IMAGE := $(boot)/loader.bin
  102. else
  103. KBUILD_IMAGE := $(boot)/Image.gz
  104. endif
  105. BOOT_TARGETS := Image Image.gz loader loader.bin
  106. all: $(notdir $(KBUILD_IMAGE))
  107. $(BOOT_TARGETS): vmlinux
  108. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  109. @$(kecho) ' Kernel: $(boot)/$@ is ready'
  110. zinstall install:
  111. $(Q)$(MAKE) $(build)=$(boot) $@