build.mk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 := n205
  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. include $(NUCLEI_SDK_SOC)/cpufeature.mk
  31. JTAGSN ?=
  32. # Please overwrite following variable in Makefile of your application
  33. # System Clock Frequency
  34. # eg. 50MHz in pure int value, 50000000
  35. SYSCLK ?=
  36. NUCLEI_SDK_SOC_BOARD := $(NUCLEI_SDK_SOC)/Board/$(BOARD)
  37. NUCLEI_SDK_SOC_COMMON := $(NUCLEI_SDK_SOC)/Common
  38. OPENOCD_CFG ?= $(NUCLEI_SDK_SOC_BOARD)/openocd_evalsoc.cfg
  39. LDFLAGS += -L $(NUCLEI_SDK_SOC_BOARD)/Source/GCC
  40. LINKER_SCRIPT ?= $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/gcc_evalsoc_$(DOWNLOAD).ld
  41. MAKEFILE_PREREQS += $(NUCLEI_SDK_SOC_BOARD)/Source/GCC/evalsoc.memory
  42. # File existence check for OPENOCD_CFG and LINKER_SCRIPT
  43. ifeq ($(wildcard $(OPENOCD_CFG)),)
  44. $(error The openocd configuration file $(OPENOCD_CFG) for $(SOC) doesn't exist, please check!)
  45. endif
  46. # Allow non-existance of LINKER_SCRIPT, it might be generated
  47. ifeq ($(wildcard $(LINKER_SCRIPT)),)
  48. $(warning The link script file $(LINKER_SCRIPT) for $(SOC) doesn't exist, please check!)
  49. endif
  50. # Add extra cflags for SoC related
  51. ifneq ($(SYSCLK),)
  52. COMMON_FLAGS += -DSYSTEM_CLOCK=$(SYSCLK)
  53. endif
  54. # if JTAGSN is not empty, pass it via openocd command
  55. ifneq ($(JTAGSN),)
  56. OPENOCD_CMD_ARGS += set JTAGSN $(JTAGSN);
  57. endif
  58. # Set RISCV_ARCH and RISCV_ABI
  59. CORE_UPPER := $(call uc, $(CORE))
  60. include $(NUCLEI_SDK_BUILD)/Makefile.core
  61. # you can override SUPPORTED_CORES defined in Makefile.core to limit the COREs used in this SoC
  62. # eg. override SUPPORTED_CORES := n305 n307
  63. CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
  64. # Check whether CORE is in SUPPORTED_CORES
  65. ifeq ($(filter $(CORE), $(SUPPORTED_CORES)),)
  66. $(error Here we only support these cores: $(SUPPORTED_CORES))
  67. endif
  68. # Check whether CORE_ARCH_ABI is presented for CORE
  69. ifneq ($(words $(wordlist 1, 2, $(CORE_ARCH_ABI))), 2)
  70. $(error No correct CORE_ARCH_ABI setting for CORE=$(CORE) found in $(realpath $(NUCLEI_SDK_BUILD)/Makefile.core))
  71. endif
  72. # Handle Nuclei RISC-V ARCH/ABI/CMODEL/TUNE
  73. ## ARCH_EXT could be combination of in order of bkpv, legal combination is list as below:
  74. ## bp: Bitmanip and Packed SIMD Extension present
  75. ## bpv: Bitmanip, Packed SIMD and Vector Extension present
  76. ## bkpv: Bitmanip, Packed SIMD, Scalar Cryptography and Vector Extension present
  77. ### If zc extension passed in ARCH_EXT, remove c in ARCH
  78. TEMP_RISCV_ARCH := $(word 1, $(CORE_ARCH_ABI))
  79. ifneq ($(findstring zc,$(ARCH_EXT)),)
  80. RISCV_ARCH ?= $(TEMP_RISCV_ARCH:c=)$(ARCH_EXT)
  81. else
  82. RISCV_ARCH ?= $(TEMP_RISCV_ARCH)$(ARCH_EXT)
  83. endif
  84. RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
  85. RISCV_TUNE ?= $(word 3, $(CORE_ARCH_ABI))
  86. # Handle QEMU Emulation
  87. QEMU_MACHINE ?= nuclei_evalsoc,download=$(DOWNLOAD)
  88. QEMU_ARCHEXT ?= ${ARCH_EXT}
  89. QEMU_CPU ?= nuclei-$(CORE),ext=$(QEMU_ARCHEXT)
  90. ifneq ($(SEMIHOST),)
  91. QEMU_OPT += -semihosting
  92. endif
  93. ifneq ($(CODESIZE),)
  94. COMMON_FLAGS += -DCODESIZE=$(CODESIZE)
  95. endif
  96. ##### Put your Source code Management configurations below #####
  97. INCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Include
  98. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source $(NUCLEI_SDK_SOC_COMMON)/Source/Drivers
  99. # If semihosting is enabled, no stub function is needed
  100. ifeq ($(SEMIHOST),)
  101. ifneq ($(findstring newlib,$(STDCLIB)),)
  102. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/newlib
  103. else
  104. # no stubs will be used
  105. endif
  106. endif
  107. ifneq ($(findstring libncrt,$(STDCLIB)),)
  108. # semihosting currently not ported to support libncrt
  109. C_SRCDIRS += $(NUCLEI_SDK_SOC_COMMON)/Source/Stubs/libncrt
  110. endif
  111. ASM_SRCS += $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/startup_evalsoc.S \
  112. $(NUCLEI_SDK_SOC_COMMON)/Source/GCC/intexc_evalsoc.S
  113. # Add extra board related source files and header files
  114. VALID_NUCLEI_SDK_SOC_BOARD := $(wildcard $(NUCLEI_SDK_SOC_BOARD))
  115. ifneq ($(VALID_NUCLEI_SDK_SOC_BOARD),)
  116. INCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Include
  117. C_SRCDIRS += $(VALID_NUCLEI_SDK_SOC_BOARD)/Source
  118. endif