Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. LDFLAGS_vmlinux := -z norelro
  9. ifeq ($(CONFIG_RELOCATABLE),y)
  10. LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs
  11. KBUILD_CFLAGS += -fPIE
  12. endif
  13. ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
  14. LDFLAGS_vmlinux += --no-relax
  15. KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  16. ifeq ($(CONFIG_RISCV_ISA_C),y)
  17. CC_FLAGS_FTRACE := -fpatchable-function-entry=4
  18. else
  19. CC_FLAGS_FTRACE := -fpatchable-function-entry=2
  20. endif
  21. endif
  22. ifeq ($(CONFIG_CMODEL_MEDLOW),y)
  23. KBUILD_CFLAGS_MODULE += -mcmodel=medany
  24. endif
  25. export BITS
  26. ifeq ($(CONFIG_ARCH_RV64I),y)
  27. BITS := 64
  28. UTS_MACHINE := riscv64
  29. KBUILD_CFLAGS += -mabi=lp64
  30. KBUILD_AFLAGS += -mabi=lp64
  31. KBUILD_LDFLAGS += -melf64lriscv
  32. KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 --target=riscv64imac-unknown-none-elf \
  33. -Cno-redzone
  34. else
  35. BITS := 32
  36. UTS_MACHINE := riscv32
  37. KBUILD_CFLAGS += -mabi=ilp32
  38. KBUILD_AFLAGS += -mabi=ilp32
  39. KBUILD_LDFLAGS += -melf32lriscv
  40. endif
  41. ifndef CONFIG_RISCV_USE_LINKER_RELAXATION
  42. KBUILD_CFLAGS += -mno-relax
  43. KBUILD_AFLAGS += -mno-relax
  44. ifndef CONFIG_AS_IS_LLVM
  45. KBUILD_CFLAGS += -Wa,-mno-relax
  46. KBUILD_AFLAGS += -Wa,-mno-relax
  47. endif
  48. # LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350
  49. # Ensure it is aware of linker relaxation with LTO, otherwise relocations may
  50. # be incorrect: https://github.com/llvm/llvm-project/issues/65090
  51. else ifeq ($(CONFIG_LTO_CLANG),y)
  52. KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax
  53. endif
  54. ifeq ($(CONFIG_SHADOW_CALL_STACK),y)
  55. KBUILD_LDFLAGS += --no-relax-gp
  56. endif
  57. # ISA string setting
  58. riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
  59. riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
  60. riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
  61. riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
  62. riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v
  63. ifneq ($(CONFIG_RISCV_ISA_C),y)
  64. KBUILD_RUSTFLAGS += -Ctarget-feature=-c
  65. endif
  66. ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
  67. KBUILD_CFLAGS += -Wa,-misa-spec=2.2
  68. KBUILD_AFLAGS += -Wa,-misa-spec=2.2
  69. else
  70. riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
  71. endif
  72. # Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
  73. # matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
  74. KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')
  75. KBUILD_AFLAGS += -march=$(riscv-march-y)
  76. # For C code built with floating-point support, exclude V but keep F and D.
  77. CC_FLAGS_FPU := -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)([^v_]*)v?/\1\2/')
  78. KBUILD_CFLAGS += -mno-save-restore
  79. KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
  80. ifeq ($(CONFIG_CMODEL_MEDLOW),y)
  81. KBUILD_CFLAGS += -mcmodel=medlow
  82. endif
  83. ifeq ($(CONFIG_CMODEL_MEDANY),y)
  84. KBUILD_CFLAGS += -mcmodel=medany
  85. endif
  86. # Avoid generating .eh_frame sections.
  87. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
  88. # The RISC-V attributes frequently cause compatibility issues and provide no
  89. # information, so just turn them off.
  90. KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
  91. KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
  92. KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
  93. KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
  94. KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
  95. KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
  96. # GCC versions that support the "-mstrict-align" option default to allowing
  97. # unaligned accesses. While unaligned accesses are explicitly allowed in the
  98. # RISC-V ISA, they're emulated by machine mode traps on all extant
  99. # architectures. It's faster to have GCC emit only aligned accesses.
  100. ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y)
  101. KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
  102. endif
  103. ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
  104. prepare: stack_protector_prepare
  105. stack_protector_prepare: prepare0
  106. $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
  107. -mstack-protector-guard-reg=tp \
  108. -mstack-protector-guard-offset=$(shell \
  109. awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
  110. include/generated/asm-offsets.h))
  111. endif
  112. # arch specific predefines for sparse
  113. CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
  114. # Default target when executing plain make
  115. boot := arch/riscv/boot
  116. ifeq ($(CONFIG_XIP_KERNEL),y)
  117. KBUILD_IMAGE := $(boot)/xipImage
  118. else
  119. ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_SOC_CANAAN_K210),yy)
  120. KBUILD_IMAGE := $(boot)/loader.bin
  121. else
  122. ifeq ($(CONFIG_EFI_ZBOOT),)
  123. KBUILD_IMAGE := $(boot)/Image.gz
  124. else
  125. KBUILD_IMAGE := $(boot)/vmlinuz.efi
  126. endif
  127. endif
  128. endif
  129. boot := arch/riscv/boot
  130. boot-image-y := Image
  131. boot-image-$(CONFIG_KERNEL_BZIP2) := Image.bz2
  132. boot-image-$(CONFIG_KERNEL_GZIP) := Image.gz
  133. boot-image-$(CONFIG_KERNEL_LZ4) := Image.lz4
  134. boot-image-$(CONFIG_KERNEL_LZMA) := Image.lzma
  135. boot-image-$(CONFIG_KERNEL_LZO) := Image.lzo
  136. boot-image-$(CONFIG_KERNEL_ZSTD) := Image.zst
  137. boot-image-$(CONFIG_KERNEL_XZ) := Image.xz
  138. ifdef CONFIG_RISCV_M_MODE
  139. boot-image-$(CONFIG_ARCH_CANAAN) := loader.bin
  140. endif
  141. boot-image-$(CONFIG_EFI_ZBOOT) := vmlinuz.efi
  142. boot-image-$(CONFIG_XIP_KERNEL) := xipImage
  143. KBUILD_IMAGE := $(boot)/$(boot-image-y)
  144. libs-y += arch/riscv/lib/
  145. libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  146. ifeq ($(KBUILD_EXTMOD),)
  147. ifeq ($(CONFIG_MMU),y)
  148. prepare: vdso_prepare
  149. vdso_prepare: prepare0
  150. $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
  151. $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
  152. $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
  153. endif
  154. endif
  155. vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg
  156. vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
  157. BOOT_TARGETS := Image Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst Image.xz loader loader.bin xipImage vmlinuz.efi
  158. all: $(notdir $(KBUILD_IMAGE))
  159. loader.bin: loader
  160. Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst Image.xz loader xipImage vmlinuz.efi: Image
  161. $(BOOT_TARGETS): vmlinux
  162. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  163. @$(kecho) ' Kernel: $(boot)/$@ is ready'
  164. # the install target always installs KBUILD_IMAGE (which may be compressed)
  165. # but keep the zinstall target for compatibility with older releases
  166. install zinstall:
  167. $(call cmd,install)
  168. PHONY += rv32_randconfig
  169. rv32_randconfig:
  170. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
  171. -f $(srctree)/Makefile randconfig
  172. PHONY += rv64_randconfig
  173. rv64_randconfig:
  174. $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
  175. -f $(srctree)/Makefile randconfig
  176. PHONY += rv32_defconfig
  177. rv32_defconfig:
  178. $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
  179. PHONY += rv32_nommu_virt_defconfig
  180. rv32_nommu_virt_defconfig:
  181. $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config
  182. define archhelp
  183. echo ' Image - Uncompressed kernel image (arch/riscv/boot/Image)'
  184. echo ' Image.gz - Compressed kernel image (arch/riscv/boot/Image.gz)'
  185. echo ' Image.bz2 - Compressed kernel image (arch/riscv/boot/Image.bz2)'
  186. echo ' Image.lz4 - Compressed kernel image (arch/riscv/boot/Image.lz4)'
  187. echo ' Image.lzma - Compressed kernel image (arch/riscv/boot/Image.lzma)'
  188. echo ' Image.lzo - Compressed kernel image (arch/riscv/boot/Image.lzo)'
  189. echo ' Image.zst - Compressed kernel image (arch/riscv/boot/Image.zst)'
  190. echo ' Image.xz - Compressed kernel image (arch/riscv/boot/Image.xz)'
  191. echo ' vmlinuz.efi - Compressed EFI kernel image (arch/riscv/boot/vmlinuz.efi)'
  192. echo ' Default when CONFIG_EFI_ZBOOT=y'
  193. echo ' xipImage - Execute-in-place kernel image (arch/riscv/boot/xipImage)'
  194. echo ' Default when CONFIG_XIP_KERNEL=y'
  195. echo ' install - Install kernel using (your) ~/bin/$(INSTALLKERNEL) or'
  196. echo ' (distribution) /sbin/$(INSTALLKERNEL) or install to '
  197. echo ' $$(INSTALL_PATH)'
  198. endef