build.mk 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. ##
  2. #### SoC Build Settings Notice
  3. # The following variables need be defined according to your SoC and Board
  4. # BOARD: MUST, set this variable to one of the valid folder basename under $(NUCLEI_SDK_SOC)/Board/
  5. # CORE: MUST, set this variable to one of SUPPORTED_CORES defined in $(NUCLEI_SDK_BUILD)/Makefile.core
  6. # VARIANT: OPTIONAL, set this variable to consecutive characters better less than 8 chars, such as lite, v1, v2.
  7. # It can be used to define different variant of similar board
  8. # NUCLEI_SDK_SOC_BOARD: MUST, set this variable to $(NUCLEI_SDK_SOC)/Board/$(BOARD), this means the
  9. # base folder for selected BOARD
  10. # NUCLEI_SDK_SOC_COMMON: MUST, set this variable to $(NUCLEI_SDK_SOC)/Common, this means the base
  11. # folder for selected SOC
  12. # OPENOCD_CFG: MUST, set this variable to openocd configuration file used for the Board or SoC
  13. # LINKER_SCRIPT: MUST, set this variable to linker script file for selected board and download mode
  14. # RISCV_ARCH: MUST, set this variable to the riscv arch you are using, see $(NUCLEI_SDK_BUILD)/Makefile.core
  15. # RISCV_ABI: MUST, set this variable to the riscv abi you are using, see $(NUCLEI_SDK_BUILD)/Makefile.core
  16. # RISCV_TUNE: Optional, set this variable to the mtune you are using, see $(NUCLEI_SDK_BUILD)/Makefile.core
  17. # If your SoC used a fixed BOARD, CORE or DOWNLOAD mode, please use override to define a fixed variable value, eg.
  18. # override CORE := n203
  19. # override DOWNLOAD := flashxip
  20. # override BOARD := nuclei_fpga_eval
  21. #### Source Code Management Notice
  22. # you need to declare the following items:
  23. # 1. C/ASM/CPP source code folders which need to be compiled
  24. # 2. Some C/ASM/CPP source code files whihc need to be compiled
  25. # You can use these makefile variables defined in $(NUCLEI_SDK_BUILD)/Makefile.files to achieve this, for details,
  26. # please check https://doc.nucleisys.com/nuclei_sdk/develop/buildsystem.html#build-related-makefile-variables-used-only-in-application-makefile
  27. ##
  28. ##### Put your SoC build configurations below #####
  29. override BOARD := nuclei_fpga_eval
  30. # If using generated cpu configs done by nuclei_gen
  31. # NOTE: cpu nuclei_gen tool will do the following things:
  32. # 1. generate cpufeature.h in where evalsoc.h located
  33. # 2. generate cpufeature.mk where this build.mk located
  34. # 3. sed and replace flash/ilm/dlm/sram/ddr base and size in evalsoc.memory
  35. # 4. sed and replace openocd_evalsoc.cfg to provide correct workmem_base/workmem_size/flashxip_base/xipnuspi_base
  36. # 5. If you want to use prebuilt IAR projects, you need to modify IAR linker script *.icf by yourself, not yet tested(FIXME)
  37. include $(NUCLEI_SDK_SOC)/cpufeature.mk
  38. # SMP must be a number, and above 1, means smp cpu count in a cluster
  39. # it will define c macro SMP_CPU_CNT to be SMP value
  40. # and define a ld symbol __SMP_CPU_CNT to be used by linker script
  41. SMP ?=
  42. # BOOT_HARTID must be a number, and above 0, the hartid is taken the mhartid bit 0-7
  43. # it will define a c macro BOOT_HARTID to be boot hart id,
  44. # other harts other than boot hartid will do wfi when in AMP mode,
  45. # or run application in smp mode
  46. BOOT_HARTID ?= 0
  47. # HARTID_OFS is used to set hartid offset to the cpu hartid to get current hart index
  48. # for example, cpu hartid maybe 1, but hart index is 0, so the offset is 1
  49. # This is not neccessary for most cases, only useful in cases such as a multiple cpu
  50. # system, cpu0 has 1 hart, hartid is 0, cpu1 has 1 hart, hartid is 1, but cpu1
  51. # hart index is 0, so in this case set this value to 1
  52. HARTID_OFS ?=
  53. # JTAGSN must be a jtag serial number
  54. # If not specified, it will not bind serial number
  55. JTAGSN ?=
  56. # SPLITMODE is used to create correct jtag chain
  57. # for NA300/NA900 with split mode enabled
  58. # 1: means enable 1 hart gdb connection, hartid is controlled by BOOT_HARTID
  59. # 2: means enable 2 hart gdb connection, will open two gdb ports
  60. SPLITMODE ?=
  61. # Please overwrite following variable in Makefile of your application
  62. # System Clock Frequency
  63. # eg. 50MHz in pure int value, 50000000
  64. SYSCLK ?=
  65. NUCLEI_SDK_SOC_BOARD := $(NUCLEI_SDK_SOC)/Board/$(BOARD)
  66. NUCLEI_SDK_SOC_COMMON := $(NUCLEI_SDK_SOC)/Common
  67. OPENOCD_XLSPIKE_CFG ?= $(NUCLEI_SDK_SOC_BOARD)/openocd_xlspike.cfg
  68. OPENOCD_CFG ?= $(NUCLEI_SDK_SOC_BOARD)/openocd_evalsoc.cfg
  69. # smp use a different openocd configuration file
  70. # and will set SMP value in the openocd configuration file
  71. ifneq ($(SMP),)
  72. OPENOCD_CMD_ARGS += set SMP $(SMP);
  73. endif
  74. # Search linker script include directory
  75. LDFLAGS += -L $(NUCLEI_SDK_SOC_BOARD)/Source/GCC
  76. LINKER_SCRIPT ?= $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/gcc_evalsoc_$(DOWNLOAD).ld
  77. MAKEFILE_PREREQS += $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/evalsoc.memory
  78. # File existence check for OPENOCD_CFG and LINKER_SCRIPT
  79. ifeq ($(wildcard $(OPENOCD_CFG)),)
  80. $(error The openocd configuration file $(OPENOCD_CFG) for $(SOC) doesn't exist, please check!)
  81. endif
  82. # Allow non-existance of LINKER_SCRIPT, it might be generated
  83. ifeq ($(wildcard $(LINKER_SCRIPT)),)
  84. $(warning The link script file $(LINKER_SCRIPT) for $(SOC) doesn't exist, please check!)
  85. endif
  86. # Add extra cflags for SoC related
  87. ifeq ($(DOWNLOAD), flash)
  88. COMMON_FLAGS += -DVECTOR_TABLE_REMAPPED
  89. endif
  90. ifneq ($(SYSCLK),)
  91. COMMON_FLAGS += -DSYSTEM_CLOCK=$(SYSCLK)
  92. endif
  93. ifneq ($(SMP),)
  94. $(call assert,$(call gt,$(SMP),1),SMP must be a integer number >= 2)
  95. ifneq ($(BOOT_HARTID),)
  96. $(call assert,$(call gt,$(SMP),$(BOOT_HARTID)),BOOT_HARTID must be small than SMP)
  97. endif
  98. CPU_CNT := $(SMP)
  99. COMMON_FLAGS += -DSMP_CPU_CNT=$(CPU_CNT)
  100. LDFLAGS += -Wl,--defsym=__SMP_CPU_CNT=$(CPU_CNT)
  101. endif
  102. ifneq ($(BOOT_HARTID),)
  103. $(call assert,$(call gte,$(BOOT_HARTID),0),BOOT_HARTID must be a integer number >= 0)
  104. ifeq ($(CPU_CNT),)
  105. CPU_CNT := $(call inc,$(BOOT_HARTID))
  106. endif
  107. # if BOOT_HARTID is set, will set the BOOT_HARTID in openocd configuration file
  108. OPENOCD_CMD_ARGS += set BOOT_HARTID $(BOOT_HARTID);
  109. COMMON_FLAGS += -DBOOT_HARTID=$(BOOT_HARTID)
  110. endif
  111. # if JTAGSN is not empty, pass it via openocd command
  112. ifneq ($(JTAGSN),)
  113. OPENOCD_CMD_ARGS += set JTAGSN $(JTAGSN);
  114. endif
  115. # if SPLITMODE is not empty, pass it via openocd command
  116. ifneq ($(SPLITMODE),)
  117. OPENOCD_CMD_ARGS += set SPLITMODE $(SPLITMODE);
  118. endif
  119. # If HARTID_OFS is not empty
  120. ifneq ($(HARTID_OFS),)
  121. COMMON_FLAGS += -D__HARTID_OFFSET=$(HARTID_OFS)
  122. endif
  123. # Set RISCV_ARCH and RISCV_ABI
  124. CORE_UPPER := $(call uc, $(CORE))
  125. include $(NUCLEI_SDK_BUILD)/Makefile.core
  126. # you can override SUPPORTED_CORES defined in Makefile.core to limit the COREs used in this SoC
  127. # eg. override SUPPORTED_CORES := n300 n300f
  128. CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
  129. # Check whether CORE is in SUPPORTED_CORES
  130. ifeq ($(filter $(CORE), $(SUPPORTED_CORES)),)
  131. $(error Here we only support these cores: $(SUPPORTED_CORES))
  132. endif
  133. # Check whether CORE_ARCH_ABI is presented for CORE
  134. ifneq ($(words $(wordlist 1, 2, $(CORE_ARCH_ABI))), 2)
  135. $(error No correct CORE_ARCH_ABI setting for CORE=$(CORE) found in $(realpath $(NUCLEI_SDK_BUILD)/Makefile.core))
  136. endif
  137. # Handle Nuclei RISC-V ARCH/ABI/CMODEL/TUNE
  138. ## ARCH_EXT could be combination of in order of bkpv, legal combination is list as below:
  139. ## bp: Bitmanip and Packed SIMD Extension present
  140. ## bpv: Bitmanip, Packed SIMD and Vector Extension present
  141. ## bkpv: Bitmanip, Packed SIMD, Scalar Cryptography and Vector Extension present
  142. ### If zc extension passed in ARCH_EXT, remove c in ARCH
  143. TEMP_RISCV_ARCH := $(word 1, $(CORE_ARCH_ABI))
  144. ifneq ($(findstring zc,$(ARCH_EXT)),)
  145. RISCV_ARCH ?= $(TEMP_RISCV_ARCH:c=)$(ARCH_EXT)
  146. else
  147. RISCV_ARCH ?= $(TEMP_RISCV_ARCH)$(ARCH_EXT)
  148. endif
  149. RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
  150. RISCV_TUNE ?= $(word 3, $(CORE_ARCH_ABI))
  151. ifneq ($(CODESIZE),)
  152. COMMON_FLAGS += -DCODESIZE=$(CODESIZE)
  153. endif
  154. # If ECLIC_HWCTX is 1, define ECLIC_HW_CTX_AUTO
  155. ifeq ($(ECLIC_HWCTX),1)
  156. COMMON_FLAGS += -DECLIC_HW_CTX_AUTO
  157. endif
  158. ##### Put your Source code Management configurations below #####
  159. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include
  160. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source $(NUCLEI_SDK_SOC_COMMON)/Source/Drivers
  161. # If semihosting is enabled, no stub function is needed
  162. ifeq ($(SEMIHOST),)
  163. ifneq ($(findstring newlib,$(STDCLIB)),)
  164. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/newlib
  165. else
  166. # no stubs will be used
  167. endif
  168. endif
  169. ifneq ($(findstring libncrt,$(STDCLIB)),)
  170. # semihosting currently not ported to support libncrt
  171. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/libncrt
  172. endif
  173. ASM_SRCS += $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/startup_evalsoc.S \
  174. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_evalsoc.S \
  175. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_evalsoc_s.S
  176. # Add extra board related source files and header files
  177. VALID_NUCLEI_SDK_SOC_BOARD := $(wildcard $(NUCLEI_SDK_SOC_BOARD))
  178. ifneq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
  179. INCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Include
  180. C_SRCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Source
  181. endif
  182. # NOTE: runmode.mk is mainly used by nuclei sdk for evalsoc to control ILM/DLM/ICACHE/DCACHE enable or disable
  183. # during `_premain_init`, which is only useful for internal usage
  184. -include $(NUCLEI_SDK_SOC)/runmode.mk
  185. # NOTE: When cpufeature.mk and cpufeature.h are generated by nuclei_gen
  186. # then CPU_CONFIG_MK will be defined as 1 in cpufeature.mk
  187. # And then cpuconfig.mk will not be included
  188. ifneq ($(CPU_CONFIG_MK),1)
  189. # NOTE: this is useful for nuclei sdk for evalsoc to dynamic control which cpu config to be enabled
  190. # eg. XLCFG_PLIC=1 will enable plic and will define CFG_HAS_PLIC
  191. -include $(NUCLEI_SDK_SOC)/cpuconfig.mk
  192. endif
  193. # NOTE: include nuclei qemu run options
  194. -include $(NUCLEI_SDK_SOC)/qemu.mk
  195. # NOTE: include nuclei near cycle model run options
  196. -include $(NUCLEI_SDK_SOC)/xlmodel.mk
  197. # NOTE: include rtl simulation related options
  198. -include $(NUCLEI_SDK_SOC)/simulation.mk