Makefile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. OBJCOPYFLAGS := -O binary
  9. LDFLAGS_vmlinux :=
  10. ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
  11. LDFLAGS_vmlinux := --no-relax
  12. KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  13. ifeq ($(CONFIG_RISCV_ISA_C),y)
  14. CC_FLAGS_FTRACE := -fpatchable-function-entry=4
  15. else
  16. CC_FLAGS_FTRACE := -fpatchable-function-entry=2
  17. endif
  18. endif
  19. ifeq ($(CONFIG_CMODEL_MEDLOW),y)
  20. KBUILD_CFLAGS_MODULE += -mcmodel=medany
  21. endif
  22. export BITS
  23. ifeq ($(CONFIG_ARCH_RV64I),y)
  24. BITS := 64
  25. UTS_MACHINE := riscv64
  26. KBUILD_CFLAGS += -mabi=lp64
  27. KBUILD_AFLAGS += -mabi=lp64
  28. KBUILD_LDFLAGS += -melf64lriscv
  29. else
  30. BITS := 32
  31. UTS_MACHINE := riscv32
  32. KBUILD_CFLAGS += -mabi=ilp32
  33. KBUILD_AFLAGS += -mabi=ilp32
  34. KBUILD_LDFLAGS += -melf32lriscv
  35. endif
  36. ifeq ($(CONFIG_LD_IS_LLD),y)
  37. ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0)
  38. KBUILD_CFLAGS += -mno-relax
  39. KBUILD_AFLAGS += -mno-relax
  40. ifndef CONFIG_AS_IS_LLVM
  41. KBUILD_CFLAGS += -Wa,-mno-relax
  42. KBUILD_AFLAGS += -Wa,-mno-relax
  43. endif
  44. endif
  45. endif
  46. # ISA string setting
  47. riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
  48. riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
  49. riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
  50. riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
  51. ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
  52. KBUILD_CFLAGS += -Wa,-misa-spec=2.2
  53. KBUILD_AFLAGS += -Wa,-misa-spec=2.2
  54. else
  55. riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
  56. endif
  57. # Check if the toolchain supports Zicbom extension
  58. riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZICBOM) := $(riscv-march-y)_zicbom
  59. # Check if the toolchain supports Zihintpause extension
  60. riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause
  61. KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
  62. KBUILD_AFLAGS += -march=$(riscv-march-y)
  63. KBUILD_CFLAGS += -mno-save-restore
  64. KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
  65. ifeq ($(CONFIG_CMODEL_MEDLOW),y)
  66. KBUILD_CFLAGS += -mcmodel=medlow
  67. endif
  68. ifeq ($(CONFIG_CMODEL_MEDANY),y)
  69. KBUILD_CFLAGS += -mcmodel=medany
  70. endif
  71. ifeq ($(CONFIG_PERF_EVENTS),y)
  72. KBUILD_CFLAGS += -fno-omit-frame-pointer
  73. endif
  74. # Avoid generating .eh_frame sections.
  75. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
  76. # The RISC-V attributes frequently cause compatibility issues and provide no
  77. # information, so just turn them off.
  78. KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
  79. KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
  80. KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
  81. KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
  82. KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
  83. KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
  84. # GCC versions that support the "-mstrict-align" option default to allowing
  85. # unaligned accesses. While unaligned accesses are explicitly allowed in the
  86. # RISC-V ISA, they're emulated by machine mode traps on all extant
  87. # architectures. It's faster to have GCC emit only aligned accesses.
  88. KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
  89. ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
  90. prepare: stack_protector_prepare
  91. stack_protector_prepare: prepare0
  92. $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
  93. -mstack-protector-guard-reg=tp \
  94. -mstack-protector-guard-offset=$(shell \
  95. awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
  96. include/generated/asm-offsets.h))
  97. endif
  98. # arch specific predefines for sparse
  99. CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
  100. # Default target when executing plain make
  101. boot := arch/riscv/boot
  102. ifeq ($(CONFIG_XIP_KERNEL),y)
  103. KBUILD_IMAGE := $(boot)/xipImage
  104. else
  105. KBUILD_IMAGE := $(boot)/Image.gz
  106. endif
  107. libs-y += arch/riscv/lib/
  108. libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  109. PHONY += vdso_install
  110. vdso_install:
  111. $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
  112. $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
  113. $(build)=arch/riscv/kernel/compat_vdso compat_$@)
  114. ifeq ($(KBUILD_EXTMOD),)
  115. ifeq ($(CONFIG_MMU),y)
  116. prepare: vdso_prepare
  117. vdso_prepare: prepare0
  118. $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
  119. $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
  120. $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
  121. endif
  122. endif
  123. ifneq ($(CONFIG_XIP_KERNEL),y)
  124. ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_CANAAN),yy)
  125. KBUILD_IMAGE := $(boot)/loader.bin
  126. else
  127. ifeq ($(CONFIG_EFI_ZBOOT),)
  128. KBUILD_IMAGE := $(boot)/Image.gz
  129. else
  130. KBUILD_IMAGE := $(boot)/vmlinuz.efi
  131. endif
  132. endif
  133. endif
  134. BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
  135. all: $(notdir $(KBUILD_IMAGE))
  136. $(BOOT_TARGETS): vmlinux
  137. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  138. @$(kecho) ' Kernel: $(boot)/$@ is ready'
  139. Image.%: Image
  140. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  141. install: KBUILD_IMAGE := $(boot)/Image
  142. zinstall: KBUILD_IMAGE := $(boot)/Image.gz
  143. install zinstall:
  144. $(call cmd,install)
  145. PHONY += rv32_randconfig
  146. rv32_randconfig:
  147. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
  148. -f $(srctree)/Makefile randconfig
  149. PHONY += rv64_randconfig
  150. rv64_randconfig:
  151. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
  152. -f $(srctree)/Makefile randconfig
  153. PHONY += rv32_defconfig
  154. rv32_defconfig:
  155. $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config