build.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. -include $(NUCLEI_SDK_SOC)/runmode.mk
  87. # Add extra cflags for SoC related
  88. ifeq ($(DOWNLOAD), flash)
  89. COMMON_FLAGS += -DVECTOR_TABLE_REMAPPED
  90. endif
  91. ifneq ($(SYSCLK),)
  92. COMMON_FLAGS += -DSYSTEM_CLOCK=$(SYSCLK)
  93. endif
  94. ## QEMU/XLSPIKE options
  95. ifeq ($(XLCFG_PLIC),1)
  96. QEMU_ELF_OPT := -bios
  97. else
  98. QEMU_ELF_OPT := -kernel
  99. endif
  100. ifneq ($(SMP),)
  101. $(call assert,$(call gt,$(SMP),1),SMP must be a integer number >= 2)
  102. ifneq ($(BOOT_HARTID),)
  103. $(call assert,$(call gt,$(SMP),$(BOOT_HARTID)),BOOT_HARTID must be small than SMP)
  104. endif
  105. CPU_CNT := $(SMP)
  106. COMMON_FLAGS += -DSMP_CPU_CNT=$(CPU_CNT)
  107. LDFLAGS += -Wl,--defsym=__SMP_CPU_CNT=$(CPU_CNT)
  108. endif
  109. ifneq ($(BOOT_HARTID),)
  110. $(call assert,$(call gte,$(BOOT_HARTID),0),BOOT_HARTID must be a integer number >= 0)
  111. ifeq ($(CPU_CNT),)
  112. CPU_CNT := $(call inc,$(BOOT_HARTID))
  113. endif
  114. # if BOOT_HARTID is set, will set the BOOT_HARTID in openocd configuration file
  115. OPENOCD_CMD_ARGS += set BOOT_HARTID $(BOOT_HARTID);
  116. COMMON_FLAGS += -DBOOT_HARTID=$(BOOT_HARTID)
  117. endif
  118. # if JTAGSN is not empty, pass it via openocd command
  119. ifneq ($(JTAGSN),)
  120. OPENOCD_CMD_ARGS += set JTAGSN $(JTAGSN);
  121. endif
  122. # if SPLITMODE is not empty, pass it via openocd command
  123. ifneq ($(SPLITMODE),)
  124. OPENOCD_CMD_ARGS += set SPLITMODE $(SPLITMODE);
  125. endif
  126. # If HARTID_OFS is not empty
  127. ifneq ($(HARTID_OFS),)
  128. COMMON_FLAGS += -D__HARTID_OFFSET=$(HARTID_OFS)
  129. endif
  130. ifneq ($(CPU_CNT),)
  131. QEMU_OPT += -smp $(CPU_CNT)
  132. endif
  133. ## xlspike is only valid for nuclei demosoc/evalsoc
  134. ifneq ($(CPU_CNT),)
  135. XLSPIKE_OPT += -p$(CPU_CNT)
  136. endif
  137. # Set RISCV_ARCH and RISCV_ABI
  138. CORE_UPPER := $(call uc, $(CORE))
  139. include $(NUCLEI_SDK_BUILD)/Makefile.core
  140. # you can override SUPPORTED_CORES defined in Makefile.core to limit the COREs used in this SoC
  141. # eg. override SUPPORTED_CORES := n300 n300f
  142. CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
  143. # Check whether CORE is in SUPPORTED_CORES
  144. ifeq ($(filter $(CORE), $(SUPPORTED_CORES)),)
  145. $(error Here we only support these cores: $(SUPPORTED_CORES))
  146. endif
  147. # Check whether CORE_ARCH_ABI is presented for CORE
  148. ifneq ($(words $(wordlist 1, 2, $(CORE_ARCH_ABI))), 2)
  149. $(error No correct CORE_ARCH_ABI setting for CORE=$(CORE) found in $(realpath $(NUCLEI_SDK_BUILD)/Makefile.core))
  150. endif
  151. # Handle Nuclei RISC-V ARCH/ABI/CMODEL/TUNE
  152. ## ARCH_EXT could be combination of in order of bkpv, legal combination is list as below:
  153. ## bp: Bitmanip and Packed SIMD Extension present
  154. ## bpv: Bitmanip, Packed SIMD and Vector Extension present
  155. ## bkpv: Bitmanip, Packed SIMD, Scalar Cryptography and Vector Extension present
  156. ### If zc extension passed in ARCH_EXT, remove c in ARCH
  157. TEMP_RISCV_ARCH := $(word 1, $(CORE_ARCH_ABI))
  158. ifneq ($(findstring zc,$(ARCH_EXT)),)
  159. RISCV_ARCH ?= $(TEMP_RISCV_ARCH:c=)$(ARCH_EXT)
  160. else
  161. RISCV_ARCH ?= $(TEMP_RISCV_ARCH)$(ARCH_EXT)
  162. endif
  163. RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
  164. RISCV_TUNE ?= $(word 3, $(CORE_ARCH_ABI))
  165. # Handle QEMU Emulation
  166. # - QEMU_MC_EXTOPT is used to pass extra options to qemu -M machine options for evalsoc,
  167. # please dont pass any extra , to this make variable, you can pass such
  168. # as QEMU_MC_EXTOPT=debug=1 but not pass QEMU_MC_EXTOPT=,debug=1
  169. # - QEMU_CPU_EXTOPT is used to pass extra options to qemu -cpu cpu options for evalsoc,
  170. # please dont pass any extra , to this make variable, you can pass such
  171. # as QEMU_CPU_EXTOPT=vlen=512 but not pass QEMU_CPU_EXTOPT=,vlen=512
  172. QEMU_MACHINE ?= nuclei_evalsoc,download=$(DOWNLOAD)
  173. # You can pass customized soc configuration here
  174. ifneq ($(QEMU_SOCCFG),)
  175. QEMU_MACHINE := $(QEMU_MACHINE),soc-cfg=$(NUCLEI_SDK_SOC)/$(QEMU_SOCCFG)
  176. endif
  177. ifneq ($(QEMU_MC_EXTOPT),)
  178. QEMU_MACHINE := $(QEMU_MACHINE),$(QEMU_MC_EXTOPT)
  179. endif
  180. QEMU_ARCHEXT ?= ${ARCH_EXT}
  181. QEMU_CPU ?= nuclei-$(CORE),ext=$(QEMU_ARCHEXT)
  182. ifneq ($(QEMU_CPU_EXTOPT),)
  183. QEMU_CPU := $(QEMU_CPU),$(QEMU_CPU_EXTOPT)
  184. endif
  185. ifneq ($(SEMIHOST),)
  186. QEMU_OPT += -semihosting
  187. endif
  188. # Handle XLModel Emulation
  189. XLMODEL_OPT += -M nuclei_evalsoc
  190. XLMODEL_OPT += --cpu=$(CORE) --download=$(DOWNLOAD)
  191. ifneq ($(ARCH_EXT),)
  192. XLMODEL_OPT += --ext=$(ARCH_EXT)
  193. endif
  194. ifneq ($(CPU_CNT),)
  195. XLMODEL_OPT += --smp=$(CPU_CNT)
  196. endif
  197. ifneq ($(CODESIZE),)
  198. COMMON_FLAGS += -DCODESIZE=$(CODESIZE)
  199. endif
  200. # If ECLIC_HWCTX is 1, define ECLIC_HW_CTX_AUTO
  201. ifeq ($(ECLIC_HWCTX),1)
  202. COMMON_FLAGS += -DECLIC_HW_CTX_AUTO
  203. endif
  204. ##### Put your Source code Management configurations below #####
  205. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include
  206. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source $(NUCLEI_SDK_SOC_COMMON)/Source/Drivers
  207. # If semihosting is enabled, no stub function is needed
  208. ifeq ($(SEMIHOST),)
  209. ifneq ($(findstring newlib,$(STDCLIB)),)
  210. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/newlib
  211. else
  212. # no stubs will be used
  213. endif
  214. endif
  215. ifneq ($(findstring libncrt,$(STDCLIB)),)
  216. # semihosting currently not ported to support libncrt
  217. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/libncrt
  218. endif
  219. ASM_SRCS += $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/startup_evalsoc.S \
  220. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_evalsoc.S \
  221. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_evalsoc_s.S
  222. # Add extra board related source files and header files
  223. VALID_NUCLEI_SDK_SOC_BOARD := $(wildcard $(NUCLEI_SDK_SOC_BOARD))
  224. ifneq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
  225. INCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Include
  226. C_SRCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Source
  227. endif