buildsystem.rst 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  1. .. _develop_buildsystem:
  2. Build System based on Makefile
  3. ==============================
  4. Nuclei SDK's build system is based on Makefile, user can build,
  5. run ordebug application in Windows and Linux.
  6. .. _develop_buildsystem_structure:
  7. Makefile Structure
  8. ------------------
  9. Nuclei SDK's Makefiles mainly placed in **<NUCLEI_SDK_ROOT>/Build** directory and
  10. an extra *Makefile* located in **<NUCLEI_SDK_ROOT>/Makefile**.
  11. This extra **<NUCLEI_SDK_ROOT>/Makefile** introduce a new Make variable called
  12. **PROGRAM** to provide the ability to build or run application in **<NUCLEI_SDK_ROOT>**.
  13. For example, if you want to *rebuild and upload* application **application/baremetal/timer_test**,
  14. you can run ``make PROGRAM=application/baremetal/timer_test clean upload`` to achieve it.
  15. The **<NUCLEI_SDK_ROOT>/Build** directory content list as below:
  16. .. code-block:: text
  17. gmsl/
  18. toolchain/
  19. Makefile.base
  20. Makefile.conf
  21. Makefile.core
  22. Makefile.components
  23. Makefile.files
  24. Makefile.global -> Created by user
  25. Makefile.misc
  26. Makefile.rtos
  27. Makefile.rules
  28. Makefile.soc
  29. The file or directory is used explained as below:
  30. .. _develop_buildsystem_makefile_base:
  31. Makefile.base
  32. ~~~~~~~~~~~~~
  33. This **Makefile.base** file is used as Nuclei SDK build system entry file,
  34. application's Makefile need to include this file to use all the features of
  35. Nuclei SDK build system.
  36. It will expose Make variables or options such as **BOARD** or **SOC** passed
  37. by ``make`` command, click :ref:`develop_buildsystem_exposed_make_vars`
  38. to learn more.
  39. This file will include optional :ref:`develop_buildsystem_makefile_global`
  40. and :ref:`develop_buildsystem_makefile_local` which allow user to set custom
  41. global Makefile configurations and local application Makefile configurations.
  42. This file will include the following makefiles:
  43. * :ref:`develop_buildsystem_gmsl`: additional library functions provided via gmsl
  44. * :ref:`develop_buildsystem_toolchain`: additional library functions provided via gmsl
  45. * :ref:`develop_buildsystem_makefile_misc`: misc functions and OS check helpers
  46. * :ref:`develop_buildsystem_makefile_conf`: main Makefile configuration entry
  47. * :ref:`develop_buildsystem_makefile_rules`: make rules of this build system
  48. .. _develop_buildsystem_gmsl:
  49. gmsl
  50. ~~~~
  51. The **gmsl** directory consist of the `GNU Make Standard Library (GMSL)`_,
  52. which is an a library of functions to be used with GNU Make's $(call) that
  53. provides functionality not available in standard GNU Make.
  54. We use this **gmsl** tool to make sure we help us achieve some linux command
  55. which is only supported in Linux.
  56. .. _develop_buildsystem_toolchain:
  57. toolchain
  58. ~~~~~~~~~
  59. The **toolchain** directory contains different toolchain support makefiles,
  60. such as Nuclei GNU toolchain, Nuclei LLVM toolchain and Terapines toolchain,
  61. if you want to add a different toolchain support, you also need to add a new
  62. toolchain makefile in it, you can refer to existing ones.
  63. Since different toolchain support is added, in application Makefile, if your
  64. toolchain options are not compatiable with others, to provide a compatiable
  65. application for different toolchain, we recommend you to add ``toolchain_$(TOOLCHAIN).mk``
  66. file in your application folder, and in application Makefile include this file,
  67. you can refer to ``application/baremetal/benchmark/coremark`` to see example usage.
  68. .. _develop_buildsystem_makefile_misc:
  69. Makefile.misc
  70. ~~~~~~~~~~~~~
  71. This **Makefile.misc** file mainly provide these functions:
  72. * Define **get_csrcs**, **get_asmsrcs**, **get_cxxsrcs** and **check_item_exist** make functions
  73. - **get_csrcs**: Function to get ``*.c or *.C`` source files from a list of directories, no ability to
  74. do recursive match. e.g. ``$(call get_csrcs, csrc csrc/abc)`` will return c source files in
  75. ``csrc`` and ``csrc/abc`` directories.
  76. - **get_asmsrcs**: Function to get ``*.s or *.S`` source files from a list of directories, no ability to
  77. do recursive match. e.g. ``$(call get_asmsrcs, asmsrc asmsrc/abc)`` will return asm source files in
  78. ``asmsrc`` and ``asmsrc/abc`` directories.
  79. - **get_cxxsrcs**: Function to get ``*.cpp or *.CPP`` source files from a list of directories, no ability
  80. to do recursive match. e.g. ``$(call get_cxxsrcs, cppsrc cppsrc/abc)`` will return cpp source files in
  81. ``cppsrc`` and ``cppsrc/abc`` directories.
  82. - **check_item_exist**: Function to check if item existed in a set of items. e.g.
  83. ``$(call check_item_exist, flash, flash ilm flashxip)`` will check ``flash`` whether existed in
  84. ``flash ilm flashxip``, if existed, return ``flash``, otherwise return empty.
  85. * Check and define OS related functions, and also a set of trace print functions.
  86. .. _develop_buildsystem_makefile_conf:
  87. Makefile.conf
  88. ~~~~~~~~~~~~~
  89. This **Makefile.conf** file will define the following items:
  90. * Toolchain related variables used during compiling
  91. * Debug related variables
  92. * Include :ref:`develop_buildsystem_makefile_files` and :ref:`develop_buildsystem_makefile_rtos`
  93. * Collect all the C/C++/ASM compiling and link options
  94. .. _develop_buildsystem_makefile_rules:
  95. Makefile.rules
  96. ~~~~~~~~~~~~~~
  97. This **Makefile.rules** file will do the following things:
  98. * Collect all the sources during compiling
  99. * Define all the rules used for building, uploading and debugging
  100. * Print help message for build system
  101. .. _develop_buildsystem_makefile_files:
  102. Makefile.files
  103. ~~~~~~~~~~~~~~
  104. This **Makefile.files** file will do the following things:
  105. * Define common C/C++/ASM source and include directories
  106. * Define common C/C++/ASM macros
  107. .. _develop_buildsystem_makefile_soc:
  108. Makefile.soc
  109. ~~~~~~~~~~~~
  110. This **Makefile.soc** will include valid makefiles located in
  111. **<NUCLEI_SDK_ROOT>/SoC/<SOC>/build.mk** according to
  112. the :ref:`develop_buildsystem_var_soc` makefile variable setting.
  113. It will define the following items:
  114. * **DOWNLOAD** and **CORE** variables
  115. - For :ref:`design_soc_evalsoc`, we can support all the modes defined in
  116. :ref:`develop_buildsystem_var_download`, and **CORE** list defined in
  117. :ref:`develop_buildsystem_makefile_core`
  118. - For :ref:`design_soc_gd32vf103`, The **CORE** is fixed to N205, since
  119. it is a real SoC chip, and only **FlashXIP** download mode is supported
  120. * Linker script used according to the **DOWNLOAD** mode settings
  121. * OpenOCD debug configuration file used for the SoC and Board
  122. * Some extra compiling or debugging options
  123. A valid SoC should be organized like this, take ``evalsoc`` as example:
  124. .. code-block::
  125. SoC/evalsoc
  126. ├── Board
  127. │ └── nuclei_fpga_eval
  128. │ ├── Include
  129. │ │ ├── board_nuclei_fpga_eval.h
  130. │ │ └── nuclei_sdk_hal.h
  131. │ ├── Source
  132. │ │ ├── IAR
  133. │ │ └── GCC
  134. │ └── openocd_evalsoc.cfg
  135. ├── build.mk
  136. └── Common
  137. ├── Include
  138. │ ├── evalsoc.h
  139. │ ├── ... ...
  140. │ ├── evalsoc_uart.h
  141. │ ├── nuclei_sdk_soc.h
  142. │ └── system_evalsoc.h
  143. └── Source
  144. ├── Drivers
  145. │ ├── ... ...
  146. │ └── evalsoc_uart.c
  147. ├── GCC
  148. │ ├── intexc_evalsoc.S
  149. │ ├── intexc_evalsoc_s.S
  150. │ └── startup_evalsoc.S
  151. ├── IAR
  152. │ ├── intexc_evalsoc.S
  153. │ ├── intexc_evalsoc_s.S
  154. │ └── startup_evalsoc.c
  155. ├── Stubs
  156. │ ├── newlib
  157. │ ├── libncrt
  158. │ └── iardlib
  159. ├── evalsoc_common.c
  160. └── system_evalsoc.c
  161. .. _develop_buildsystem_makefile_rtos:
  162. Makefile.rtos
  163. ~~~~~~~~~~~~~
  164. This **Makefile.rtos** will include **<NUCLEI_SDK_ROOT>/OS/<RTOS>/build.mk**
  165. according to our :ref:`develop_buildsystem_var_rtos` variable.
  166. A valid rtos should be organized like this, take ``UCOSII`` as example:
  167. .. code-block::
  168. OS/UCOSII/
  169. ├── arch
  170. ├── build.mk
  171. ├── license.txt
  172. ├── readme.md
  173. └── source
  174. If no :ref:`develop_buildsystem_var_rtos` is chosen, then RTOS
  175. code will not be included during compiling, user will develop
  176. baremetal application.
  177. If **FreeRTOS**, **UCOSII** or **RTThread** RTOS is chosen, then FreeRTOS
  178. UCOSII, or RTThread source code will be included during compiling, and extra
  179. compiler option ``-DRTOS_$(RTOS_UPPER)`` will be passed, then user can develop RTOS application.
  180. For example, if ``FreeRTOS`` is selected, then ``-DRTOS_FREERTOS`` compiler option
  181. will be passed.
  182. .. _develop_buildsystem_makefile_components:
  183. Makefile.components
  184. ~~~~~~~~~~~~~~~~~~~
  185. This **Makefile.components** will include ``build.mk`` Makefiles of selected components defined
  186. via makefile variable :ref:`develop_buildsystem_var_middleware`, the Makefiles are placed in
  187. the sub-folders of **<NUCLEI_SDK_ROOT>/Components/**.
  188. A valid middleware component should be organized like this, take ``fatfs`` as example :
  189. .. code-block::
  190. Components/fatfs/
  191. ├── build.mk
  192. ├── documents
  193. ├── LICENSE.txt
  194. └── source
  195. For example, if there are two valid middleware components in **<NUCLEI_SDK_ROOT>/Components/**, called
  196. ``fatfs`` and ``tjpgd``, and you want to use them in your application, then you can set ``MIDDLEWARE``
  197. like this ``MIDDLEWARE := fatfs tjpgd``, then the application will include these two middlewares into
  198. build process.
  199. .. _develop_buildsystem_makefile_core:
  200. Makefile.core
  201. ~~~~~~~~~~~~~
  202. This **Makefile.core** is used to define the RISC-V ARCH and ABI used during
  203. compiling of the CORE list supported.
  204. If you want to add a new **CORE**, you need to add a new line before **SUPPORTED_CORES**,
  205. and append the new **CORE** to **SUPPORTED_CORES**.
  206. For example, if you want to add a new **CORE** called **n308**, and the **n308**'s
  207. **ARCH** and **ABI** are ``rv32imafdc`` and ``ilp32d``, then you can add a new line
  208. like this ``N308_CORE_ARCH_ABI = rv32imafdc ilp32d``, and append **n308** to **SUPPORTED_CORES**
  209. like this ``SUPPORTED_CORES = n201 n201e n203 n203e n308 nx600``
  210. .. note::
  211. * The appended new **CORE** need to lower-case, e.g. *n308*
  212. * The new defined variable **N308_CORE_ARCH_ABI** need to be all upper-case.
  213. .. _develop_buildsystem_makefile_global:
  214. Makefile.global
  215. ~~~~~~~~~~~~~~~
  216. This **Makefile.global** file is an optional file, and will not be tracked by git,
  217. user can create own **Makefile.global** in **<NUCLEI_SDK_ROOT>/Build** directory.
  218. In this file, user can define custom **SOC**, **BOARD**, **DOWNLOAD** options to
  219. overwrite the default configuration.
  220. For example, if you will use only the :ref:`design_board_gd32vf103v_rvstar`, you can
  221. create the **<NUCLEI_SDK_ROOT>/Build/Makefile.global** as below:
  222. .. code-block:: Makefile
  223. SOC ?= gd32vf103
  224. BOARD ?= gd32vf103v_rvstar
  225. DOWNLOAD ?= flashxip
  226. .. note::
  227. * If you add above file, then you can build, run, debug application without passing
  228. **SOC**, **BOARD** and **DOWNLOAD** variables using make command for
  229. :ref:`design_board_gd32vf103v_rvstar` board, e.g.
  230. - Build and run application for :ref:`design_board_gd32vf103v_rvstar`: ``make run``
  231. - Debug application for :ref:`design_board_gd32vf103v_rvstar`: ``make debug``
  232. * The :ref:`design_board_gd32vf103v_rvstar` only support ``FlashXIP`` download mode.
  233. * If you create the **Makefile.global** like above sample code, you will also be able
  234. to use Nuclei SDK build system as usually, it will only change the default **SOC**,
  235. **BOARD** and **DOWNLOAD**, but you can still override the default variable using
  236. make command, such as ``make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm``
  237. .. _develop_buildsystem_makefile_local:
  238. Makefile.local
  239. ~~~~~~~~~~~~~~
  240. As the :ref:`develop_buildsystem_makefile_global` is used to override the default Makefile
  241. configurations, and the **Makefile.local** is used to override application level Makefile
  242. configurations, and also this file will not be tracked by git.
  243. User can create ``Makefile.local`` file in any of the application folder, placed together with
  244. the application Makefile, for example, you can create ``Makefile.local`` in ``application/baremetal/helloworld``
  245. to override default make configuration for this **helloworld** application.
  246. If you want to change the default board for **helloworld** to use :ref:`design_board_gd32vf103v_rvstar`,
  247. you can create ``application/baremetal/helloworld/Makefile.local`` as below:
  248. .. code-block:: Makefile
  249. SOC ?= gd32vf103
  250. BOARD ?= gd32vf103v_rvstar
  251. DOWNLOAD ?= flashxip
  252. .. note::
  253. * This local make configuration will override global and default make configuration.
  254. * If you just want to change only some applications' makefile configuration, you can
  255. add and update ``Makefile.local`` for those applications.
  256. .. _develop_buildsystem_make_targets:
  257. Makefile targets of make command
  258. --------------------------------
  259. Here is a list of the :ref:`table_dev_buildsystem_4`.
  260. .. _table_dev_buildsystem_4:
  261. .. list-table:: Make targets supported by Nuclei SDK Build System
  262. :widths: 20 80
  263. :header-rows: 1
  264. :align: center
  265. * - target
  266. - description
  267. * - help
  268. - display help message of Nuclei SDK build system
  269. * - info
  270. - display selected configuration information
  271. * - showflags
  272. - display asm/c/cxx/ld flags and other info
  273. * - showtoolver
  274. - display toolchain/qemu/openocd version
  275. * - all
  276. - build application with selected configuration
  277. * - clean
  278. - clean application with selected configuration
  279. * - dasm
  280. - build and dissemble application with selected configuration
  281. * - bin
  282. - build and generate application binary with selected configuration
  283. * - upload
  284. - build and upload application with selected configuration
  285. * - run_openocd
  286. - run openocd server with selected configuration, and wait for gdb at port specified by $(GDB_PORT)
  287. * - run_gdb
  288. - build and start gdb process with selected configuration, and connect to localhost:$(GDB_PORT)
  289. * - debug
  290. - build and debug application with selected configuration
  291. * - run_qemu
  292. - run application on qemu machine with selected configuration
  293. * - run_xlspike
  294. - run application on xlspike with selected configuration
  295. * - size
  296. - show program size
  297. .. note::
  298. * The selected configuration is controlled by
  299. :ref:`develop_buildsystem_exposed_make_vars`
  300. * For ``run_openocd`` and ``run_gdb`` target, if you want to
  301. change a new gdb port, you can pass the variable
  302. :ref:`develop_buildsystem_var_gdb_port`
  303. * For ``run_qemu``, only ``SOC=evalsoc`` supported,
  304. when do this target, you can pass ``SIMU=qemu`` to support auto-exit,
  305. project recompiling is required.
  306. * For ``run_xlspike``, only ``SOC=evalsoc`` supported,
  307. when do this target, you can pass ``SIMU=xlspike`` to support auto-exit,
  308. project recompiling is required.
  309. .. _develop_buildsystem_exposed_make_vars:
  310. Makefile variables passed by make command
  311. -----------------------------------------
  312. In Nuclei SDK build system, we exposed the following Makefile variables
  313. which can be passed via make command.
  314. * :ref:`develop_buildsystem_var_soc`
  315. * :ref:`develop_buildsystem_var_board`
  316. * :ref:`develop_buildsystem_var_variant`
  317. * :ref:`develop_buildsystem_var_toolchain`
  318. * :ref:`develop_buildsystem_var_download`
  319. * :ref:`develop_buildsystem_var_core`
  320. * :ref:`develop_buildsystem_var_archext`
  321. * :ref:`develop_buildsystem_var_cpu_series`
  322. * :ref:`develop_buildsystem_var_simulation`
  323. * :ref:`develop_buildsystem_var_semihost`
  324. * :ref:`develop_buildsystem_var_gdb_port`
  325. * :ref:`develop_buildsystem_var_v`
  326. * :ref:`develop_buildsystem_var_silent`
  327. .. note::
  328. * These variables can also be used and defined in application Makefile
  329. * If you just want to fix your running board of your application, you can
  330. just define these variables in application Makefile, if defined, then
  331. you can simply use ``make clean``, ``make upload`` or ``make debug``, etc.
  332. .. _develop_buildsystem_var_soc:
  333. SOC
  334. ~~~
  335. **SOC** variable is used to declare which SoC is used in application during compiling.
  336. **evalsoc** is the default SoC, if no **SOC** passed or environment variable set, you can check
  337. default settings by run ``make info``, it will will show default settings without any overriding
  338. make variable.
  339. You can easily find the supported SoCs in the **<NUCLEI_SDK_ROOT>/SoC** directory.
  340. Currently we support the following SoCs, see :ref:`table_dev_buildsystem_1`.
  341. .. _table_dev_buildsystem_1:
  342. .. list-table:: Supported SoCs
  343. :widths: 10, 60
  344. :header-rows: 1
  345. :align: center
  346. * - **SOC**
  347. - Reference
  348. * - gd32vf103
  349. - :ref:`design_soc_gd32vf103`
  350. * - gd32vw55x
  351. - :ref:`design_soc_gd32vw55x`
  352. * - evalsoc
  353. - :ref:`design_soc_evalsoc`
  354. .. note::
  355. If you are our SoC subsystem customer, in the SDK delivered to you, you can find your soc name
  356. in this **<NUCLEI_SDK_ROOT>/SoC** directory, take ``gd32vf103`` SoC as example, when ``SOC=gd32vf103``,
  357. the SoC source code in **<NUCLEI_SDK_ROOT>/SoC/gd32vf103/Common** will be used.
  358. This documentation just document the open source version of Nuclei SDK's supported SOC and Board.
  359. .. _develop_buildsystem_var_board:
  360. BOARD
  361. ~~~~~
  362. **BOARD** variable is used to declare which Board is used in application during compiling.
  363. The **BOARD** variable should match the supported boards of chosen **SOC**.
  364. You can easily find the supported Boards in the **<NUCLEI_SDK_ROOT>/<SOC>/Board/** directory.
  365. * :ref:`table_dev_buildsystem_2`
  366. * :ref:`table_dev_buildsystem_3`
  367. * :ref:`table_dev_buildsystem_3_1`
  368. Currently we support the following SoCs.
  369. .. _table_dev_buildsystem_2:
  370. .. list-table:: Supported Boards when SOC=gd32vf103
  371. :widths: 20, 60
  372. :header-rows: 1
  373. :align: center
  374. * - **BOARD**
  375. - Reference
  376. * - gd32vf103v_rvstar
  377. - :ref:`design_board_gd32vf103v_rvstar`
  378. * - gd32vf103c_dlink
  379. - :ref:`design_board_gd32vf103c_dlink`
  380. * - gd32vf103v_eval
  381. - :ref:`design_board_gd32vf103v_eval`
  382. * - gd32vf103c_longan_nano
  383. - :ref:`design_board_sipeed_longan_nano`
  384. * - gd32vf103c_t_display
  385. - :ref:`design_board_sipeed_longan_nano`
  386. * - gd32vw553h_eval
  387. - :ref:`design_board_gd32vw553h_eval`
  388. .. _table_dev_buildsystem_3:
  389. .. list-table:: Supported Boards when SOC=evalsoc
  390. :widths: 10 60
  391. :header-rows: 1
  392. :align: center
  393. * - **BOARD**
  394. - Reference
  395. * - nuclei_fpga_eval
  396. - :ref:`design_board_nuclei_fpga_eval`
  397. .. _table_dev_buildsystem_3_1:
  398. .. list-table:: Supported Boards when SOC=g32vw55x
  399. :widths: 20, 60
  400. :header-rows: 1
  401. :align: center
  402. * - **BOARD**
  403. - Reference
  404. * - gd32vw553h_eval
  405. - :ref:`design_board_gd32vw553h_eval`
  406. .. note::
  407. * If you only specify **SOC** variable in make command, it will use default **BOARD**
  408. and **CORE** option defined in **<NUCLEI_SDK_ROOT>/SoC/<SOC>/build.mk**
  409. * If you are our SoC subsystem customer, in the SDK delivered to you, you can check
  410. the board supported list in **<NUCLEI_SDK_ROOT>/<SOC>/Board/**, take ``SOC=gd32vf103 BOARD=gd32vf103v_rvstar``
  411. as example, the board source code located **<NUCLEI_SDK_ROOT>/gd32vf103/Board/gd32vf103v_rvstar** will be used.
  412. .. _develop_buildsystem_var_variant:
  413. VARIANT
  414. ~~~~~~~
  415. **VARIANT** variable is used to declare which variant of board is used in application during compiling.
  416. It might only affect on only small piece of board, and this is SoC and Board dependent.
  417. This variable only affect the selected board or soc, and it is target dependent.
  418. .. _develop_buildsystem_var_toolchain:
  419. TOOLCHAIN
  420. ~~~~~~~~~
  421. .. note::
  422. This variable is added in 0.5.0 release.
  423. This variable is used to select different toolchain to compile application.
  424. Currently we support 3 toolchain in Nuclei SDK.
  425. * **nuclei_gnu**: default, it will choose nuclei gnu toolchain, distributed with Nuclei Toolchain.
  426. * **nuclei_llvm**: still in experiment, nuclei customized extensions not yet supported, distributed with Nuclei Toolchain.
  427. * **terapines**: still in experiment, it depends on the toolchain vendor about the supported extensions, if you want to take a try with it, just visit https://www.terapines.com/ and request an terapines toolchain evaluation.
  428. For **nuclei_gnu/nuclei_llvm** toolchain both newlib and libncrt library are supported,
  429. but nuclei_llvm toolchain multilib selection mechanism is not as good as gnu toolchain,
  430. you need to take care of the arch isa string order, please see ``riscv64-unknown-unknown-elf-clang -v`` output for supported multilib and its isa string order.
  431. And IAR compiler support is also done in Nuclei SDK, you can take a try with it
  432. via ``ideprojects/iar`` folder provided prebuilt ide projects.
  433. If you want to use old Nuclei GNU Toolchain <= 2022.12 in Nuclei SDK 0.5.0, you need to pass extra ``COMPILE_PREFIX=riscv-nuclei-elf-`` when build any application, such as ``make CORE=n300fd COMPILE_PREFIX=riscv-nuclei-elf- STDCLIB=libncrt_small clean all``, but this is not recommended, and will be deprecated in future any time.
  434. .. _develop_buildsystem_var_download:
  435. DOWNLOAD
  436. ~~~~~~~~
  437. **DOWNLOAD** variable is used to declare the download mode of the application,
  438. currently it has these modes supported as described in table
  439. :ref:`table_dev_buildsystem_5`
  440. .. _table_dev_buildsystem_5:
  441. .. list-table:: Supported download modes
  442. :widths: 10 70
  443. :header-rows: 1
  444. :align: center
  445. * - **DOWNLOAD**
  446. - Description
  447. * - ilm
  448. - | Program will be downloaded into ilm/ram and
  449. | run directly in ilm/ram, program will lost when poweroff
  450. * - flash
  451. - | Program will be downloaded into flash, when running,
  452. | program will be copied to ilm/ram and run in ilm/ram
  453. * - flashxip
  454. - Program will be downloaded into flash and run directly in flash
  455. * - ddr
  456. - | Program will be downloaded into ddr and
  457. | run directly in ddr, program will lost when poweroff
  458. * - sram
  459. - | Program will be downloaded into sram and
  460. | run directly in sram, program will lost when poweroff
  461. .. note::
  462. * This variable now target dependent, and its meaning depending on how this
  463. variable is implemented in SoC's build.mk
  464. * :ref:`design_soc_gd32vf103` only support **DOWNLOAD=flashxip**
  465. * **flashxip** mode in :ref:`design_soc_evalsoc` is very slow due to
  466. the CORE frequency is very slow, and flash execution speed is slow
  467. * **ddr** mode is introduced in release ``0.2.5`` of Nuclei SDK
  468. * macro ``DOWNLOAD_MODE`` and ``DOWNLOAD_MODE_STRING`` will be defined in Makefile,
  469. eg. when ``DOWNLOAD=flash``, macro will be defined as ``-DDOWNLOAD_MODE=DOWNLOAD_MODE_FLASH``,
  470. and ``-DDOWNLOAD_MODE_STRING=\"flash\"``, the ``flash`` will be in upper case,
  471. currently ``DOWNLOAD_MODE_STRING`` macro is used in ``system_<Device>.c`` when
  472. banner is print.
  473. * This download mode is also used to clarify whether in the link script,
  474. your eclic vector table is placed in ``.vtable_ilm`` or ``.vtable`` section, eg.
  475. for evalsoc, when ``DOWNLOAD=flash``, vector table is placed in ``.vtable_ilm`` section,
  476. and an extra macro called ``VECTOR_TABLE_REMAPPED`` will be passed in Makefile.
  477. When ``VECTOR_TABLE_REMAPPED`` is defined, it means vector table's LMA and VMA are
  478. different, it is remapped.
  479. * From release ``0.3.2``, this ``DOWNLOAD_MODE`` should not be used, and macros
  480. ``DOWNLOAD_MODE_ILM``, ``DOWNLOAD_MODE_FLASH``, ``DOWNLOAD_MODE_FLASHXIP`` and
  481. ``DOWNLOAD_MODE_DDR`` previously defined in ``riscv_encoding.h`` now are moved to
  482. ``<Device.h>`` such as ``evalsoc.h``, and should be deprecated in future.
  483. Now we are directly using ``DOWNLOAD_MODE_STRING`` to pass the download mode string,
  484. no longer need to define it in source code as before.
  485. * From release ``0.3.2``, you can define **DOWNLOAD** not just the download mode list above,
  486. you can use other download mode names specified by your customized SoC.
  487. * For SRAM download mode, for 200/300, it don't has DDR, so sram is a external ram outside of cpu,
  488. for 600/900, it has DDR, so sram is the ddr ram
  489. .. _develop_buildsystem_var_core:
  490. CORE
  491. ~~~~
  492. **CORE** variable is used to declare the Nuclei processor core
  493. of the application.
  494. **NOTICE**: Nuclei 100 series such as N100 is not supported by normal Nuclei SDK, you need
  495. to switch to ``develop_n100`` branch to try it out.
  496. Currently it has these cores supported as described in table
  497. :ref:`table_dev_buildsystem_6`.
  498. .. _table_dev_buildsystem_6:
  499. .. table:: Supported Nuclei Processor cores
  500. :widths: 20 20 20
  501. :align: center
  502. ======== ========== ======= =================
  503. **CORE** **ARCH** **ABI** **TUNE**
  504. n200 rv32imc ilp32 nuclei-200-series
  505. n200e rv32emc ilp32e nuclei-200-series
  506. n201 rv32iac ilp32 nuclei-200-series
  507. n201e rv32eac ilp32e nuclei-200-series
  508. n202 rv32ic ilp32 nuclei-200-series
  509. n202e rv32ec ilp32e nuclei-200-series
  510. n203 rv32imac ilp32 nuclei-200-series
  511. n203e rv32emac ilp32e nuclei-200-series
  512. n300 rv32imac ilp32 nuclei-300-series
  513. n300f rv32imafc ilp32f nuclei-300-series
  514. n300fd rv32imafdc ilp32d nuclei-300-series
  515. n600 rv32imac ilp32 nuclei-600-series
  516. n600f rv32imafc ilp32f nuclei-600-series
  517. n600fd rv32imafdc ilp32d nuclei-600-series
  518. u600 rv32imac ilp32 nuclei-600-series
  519. u600f rv32imafc ilp32f nuclei-600-series
  520. u600fd rv32imafdc ilp32d nuclei-600-series
  521. nx600 rv64imac lp64 nuclei-600-series
  522. nx600f rv64imafc lp64f nuclei-600-series
  523. nx600fd rv64imafdc lp64d nuclei-600-series
  524. ux600 rv64imac lp64 nuclei-600-series
  525. ux600f rv64imafc lp64f nuclei-600-series
  526. ux600fd rv64imafdc lp64d nuclei-600-series
  527. n900 rv32imac ilp32 nuclei-900-series
  528. n900f rv32imafc ilp32f nuclei-900-series
  529. n900fd rv32imafdc ilp32d nuclei-900-series
  530. u900 rv32imac ilp32 nuclei-900-series
  531. u900f rv32imafc ilp32f nuclei-900-series
  532. u900fd rv32imafdc ilp32d nuclei-900-series
  533. nx900 rv64imac lp64 nuclei-900-series
  534. nx900f rv64imafc lp64f nuclei-900-series
  535. nx900fd rv64imafdc lp64d nuclei-900-series
  536. ux900 rv64imac lp64 nuclei-900-series
  537. ux900f rv64imafc lp64f nuclei-900-series
  538. ux900fd rv64imafdc lp64d nuclei-900-series
  539. ux1000fd rv64imafdc lp64d nuclei-1000-series
  540. ======== ========== ======= =================
  541. When **CORE** is selected, the **ARCH**, **ABI** and **TUNE** (optional) are set,
  542. and it might affect the compiler options in combination with :ref:`develop_buildsystem_var_archext`
  543. depended on the implementation of SoC build.mk.
  544. If you are not sure about which ARCH and extension and cpu feature your Nuclei CPU has,
  545. you can run :ref:`design_app_cpuinfo` example to confirm it.
  546. .. note::
  547. * ``n205/n205e/n305/n307/n307fd`` CORE are removed in Nuclei SDK 0.7.0
  548. * ``n200e/n202/n202e`` CORE are added in Nuclei SDK 0.7.0
  549. * In Nuclei SDK, this **CORE** variable is just a **shorthand** to find a suitable **ARCH**,
  550. **ABI** and **TUNE** for target SoC to pass to the compiler as described in above table.
  551. So for example, **CORE=n600fd** equals **CORE=u600fd**, **CORE=n900fd** equals **CORE=u900fd**
  552. * Nuclei CPU product name such as N310, NA300, NA900, NI900, N308 is just a name, since
  553. the CPU itself is configurable, so the final **ARCH** and **ABI** is different according
  554. to your configuration, you should find a proper base **CORE** name according to your CPU RTL
  555. configuration, and if you have extra ISA not fit in this **CORE** name, you can pass it via
  556. :ref:`develop_buildsystem_var_archext`, for example, if your CPU product is NA300, and **CPU_ISA**
  557. after RTL configuration is ``rv32imafd_zca_zcb_zcf_zcmp_zcmt_zba_zbb_zbc_zbs_zfhmin_zicond_xxldspn3x``,
  558. then you can set **CORE=n300fd**, **ARCH_EXT** can be set to empty **ARCH_EXT=**, or **ARCH_EXT=_zca_zcb_zcf_zcmp_zcmt_zba_zbb_zbc_zbs_zfhmin_zicond_xxldspn3x**, or
  559. shorter **ARCH_EXT=_zca_zcb_zcf_zcmp_zcmt_zicond_xxldsp**, but a invalid **ARCH_EXT** could cause
  560. a library not match issue due to toolchain can only distributed with limited multilib which can be checked
  561. via ``riscv64-unknown-elf-gcc -print-multi-lib``, so please take care.
  562. * For other CPU features such as TEE, ECLIC, TIMER, CACHE, CCM, SMP and etc, you should modify the
  563. section **Processor and Core Peripheral Section** in your ``<Device.h>``, such as ``SoC/evalsoc/Common/Include/evalsoc.h``.
  564. Take ``SOC=evalsoc`` as example.
  565. - If **CORE=n205 ARCH_EXT=**, then ``ARCH=rv32imac, ABI=ilp32 TUNE=nuclei-200-series``.
  566. riscv arch related compile and link options will be passed, for this case, it will be
  567. ``-march=rv32imac -mabi=ilp32 -mtune=nuclei-200-series``.
  568. - If **CORE=n205 ARCH_EXT=_zba_zbb_zbc_zbs**, it will be ``-march=rv32imac_zba_zbb_zbc_zbs -mabi=ilp32 -mtune=nuclei-200-series``.
  569. For riscv code model settings, the ``RISCV_CMODEL`` variable will be set to medlow
  570. for RV32 targets, otherwise it will be medany.
  571. The some SoCs, the CORE is fixed, so the ARCH and ABI will be fixed, such as
  572. ``gd32vf103`` SoC, in build system, the CORE is fixed to n205, and ARCH=rv32imac, ABI=ilp32.
  573. .. _develop_buildsystem_var_archext:
  574. ARCH_EXT
  575. ~~~~~~~~
  576. **ARCH_EXT** variable is used to select extra RISC-V arch extensions supported by Nuclei
  577. RISC-V Processor, except the ``iemafdc``.
  578. .. note::
  579. `Nuclei Toolchain 2023.10`_ now bump gcc version from gcc 10 to gcc 13, which introduced
  580. incompatiable ``-march`` option, so ``ARCH_EXT`` usage is also incompatiable now.
  581. About the incompatiable march option change, please see https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/26, which is already present in latest gcc and clang release.
  582. About latest and full version of RISC-V Ratified ISA Spec, please click latest released spec here https://github.com/riscv/riscv-isa-manual/releases/,
  583. check the ``unpriv-isa-asciidoc.pdf`` and ``priv-isa-asciidoc.pdf``.
  584. About Nuclei RISC-V toolchain user guide, please check https://doc.nucleisys.com/nuclei_tools/toolchain/index.html
  585. When using gcc 13 or clang 17 toolchain in 2023.10 or later toolchain release, you need to use it like this in 0.5.0 sdk release or later version.
  586. Here are several examples when using **ARCH_EXT** for Nuclei RISC-V Processors:
  587. .. note::
  588. This **ARCH_EXT=** is only used in Nuclei SDK makefile based build system, not used in Nuclei Studio IDE,
  589. in Nuclei Studio IDE, you need to set the **Other extensions** in ``Nuclei Settings`` or
  590. ``Project Properities -> Settings -> C/C++ Build -> Tool Settings -> Target Processor -> Other Extensions``,
  591. eg. If you pass **ARCH_EXT=_zba_zbb_zbc_zbs** using make, then you should set ``_zba_zbb_zbc_zbs`` in **Other extensions**.
  592. * If you want to use just `B 1.0 extension`_, you can pass **ARCH_EXT=_zba_zbb_zbc_zbs**
  593. * If you want to use just Nuclei implemented `P 0.5.4 extension`_ and N1/N2/N3 customized extension
  594. - Xxldsp: means P 0.5.4 + Nuclei default enabled additional 8 expd instructions for both RV32 and RV64, you can pass **ARCH_EXT=_xxldsp**
  595. - Xxldspn1x: means Xxldsp + Nuclei N1 additional instructions for RV32 only, you can pass **ARCH_EXT=_xxldspn1x**
  596. - Xxldspn2x: means Xxldspn1x + Nuclei N2 additional instructions for RV32 only, you can pass **ARCH_EXT=_xxldspn2x**
  597. - Xxldspn3x: means Xxldspn1x + Nuclei N3 additional instructions for RV32 only, you can pass **ARCH_EXT=_xxldspn3x**
  598. * If you want to use `K 1.0 extension`_, you can pass **ARCH_EXT=_zk_zks**
  599. * If you want to use `V 1.0 extension`_
  600. - For rv32 without f/d extension, you can pass **ARCH_EXT=_zve32x**
  601. - For rv32 with f/d extension, you can pass **ARCH_EXT=_zve32f**
  602. - For rv64 without f/d extension, you can pass **ARCH_EXT=_zve64x**
  603. - For rv64 with f extension, you can pass **ARCH_EXT=_zve64f**
  604. - For rv64 with fd extension, you can pass **ARCH_EXT=v**
  605. * If you want to use F16(zfh/zvfh) extension, you can follow below steps
  606. - For case without vector extension, you can add extra ``_zfh`` to **ARCH_EXT**, eg, **ARCH_EXT=_zfh**
  607. - For case with vector extension, you can add extra ``_zfh_zvfh`` to **ARCH_EXT**, eg, **ARCH_EXT=_zfh_zvfh**
  608. - And the prebuilt NMSIS DSP library also provide F16 support with prebuilt F16 library, you can check library name with ``zfh``, such as ``NMSIS/Library/DSP/GCC/libnmsis_dsp_rv32imafc_zfh_zvfh_zve32f.a``
  609. - Spec about `zfh extension`_ and `zvfh extension`_
  610. * If you want to use `Zc 1.0 extension`_
  611. - You can use it together with C extension, which means it should be concat with isa string like ``rv32imafd_zca_zcb_zcf_zcmp_zcmt``
  612. - In Nuclei SDK, the isa string processing is done in build system
  613. - If you want to use with n300/n900, you can pass **ARCH_EXT=_zca_zcb_zcmp_zcmt**
  614. - If you want to use with n300f/n900f, you can pass **ARCH_EXT=_zca_zcb_zcf_zcmp_zcmt**
  615. - If you want to use with n300fd/n900fd, you can pass **ARCH_EXT=_zca_zcb_zcf_zcmp_zcmt**
  616. - If you want to use with n300fd/n900fd without zcmp/zcmt, you can pass **ARCH_EXT=_zca_zcb_zcf_zcd**
  617. - If you want to use with extra Nuclei Code Size Reduction extension called Xxlcz, you can add extra ``_xxlcz`` in **ARCH_EXT**, eg. for n300, you can pass **ARCH_EXT=_zca_zcb_zcmp_zcmt_xxlcz**
  618. * When using customized extensions such as Xxldsp/Xxldspn1x/Xxldspn2x/Xxldspn3x/Xxlcz, the isa string must be placed after all ``_z`` started isa strings, here is an legal string such as ``rv32imafd_zca_zcb_zcf_zcmp_zcmt_zba_zbb_zbc_zbs_zk_zks_xxlcz_xxldspn3x`` for rv32 with imafd + Zc + B + K + Xxldspn3x + Xxlcz
  619. * You need to handle this **ARCH_EXT** carefully, expecially using with demo_dsp demo since it will default search library match the whole arch name but you can pass :ref:`develop_buildsystem_var_nmsis_lib_arch` variable in Makefile to choose your desired library arch.
  620. * LLVM Clang in Nuclei RISC-V Toolchain 2023.10 don't support ``Xxldsp`` and ``Xxlcz`` extension now, please take care.
  621. * When using llvm clang compiler, the isa string order must be treat carefully, it is not handled very good when searching different multilib.
  622. * You can check prebuilt multilib for gcc and clang using ``riscv64-unknown-elf-gcc --print-multi-lib`` and ``riscv64-unknown-elf-clang --print-multi-lib``
  623. Here below are for using gcc 10 toolchain, you can use it like this below in old nuclei sdk release before 0.5.0.
  624. Currently, valid arch extension combination should match the order of ``bpv``.
  625. Here is a list of valid arch extensions:
  626. * **ARCH_EXT=b**: RISC-V bitmanipulation extension.
  627. * **ARCH_EXT=p**: RISC-V packed simd extension.
  628. * **ARCH_EXT=v**: RISC-V vector extension.
  629. * **ARCH_EXT=bp**: RISC-V bitmanipulation and packed simd extension.
  630. * **ARCH_EXT=pv**: RISC-V packed simd and vector extension.
  631. * **ARCH_EXT=bpv**: RISC-V bitmanipulation, packed simd and vector extension.
  632. It is suggested to use this **ARCH_EXT** with other arch options like this, can be found in
  633. ``SoC/evalsoc/build.mk``:
  634. .. code-block:: makefile
  635. # Set RISCV_ARCH and RISCV_ABI
  636. CORE_UPPER := $(call uc, $(CORE))
  637. CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
  638. RISCV_ARCH ?= $(word 1, $(CORE_ARCH_ABI))$(ARCH_EXT)
  639. RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
  640. .. _develop_buildsystem_var_cpu_series:
  641. CPU_SERIES
  642. ~~~~~~~~~~
  643. .. note::
  644. * This variable is used to control different compiler options for different Nuclei CPU series such
  645. as 200/300/600/900/1000.
  646. * If you are looking for Nuclei 100 series support, please refer to ``develop_n100`` branch of Nuclei SDK repository.
  647. This variable will be auto set if your CORE variable match the following rules:
  648. * **200**: CORE start with *20*, the CPU_SERIES will be 200.
  649. * **300**: CORE start with *30*, the CPU_SERIES will be 300.
  650. * **600**: CORE start with *60*, the CPU_SERIES will be 600.
  651. * **900**: CORE start with *90*, the CPU_SERIES will be 900.
  652. * **1000**: CORE start with *100*, the CPU_SERIES will be 1000.
  653. * **0**: CORE start with others, the CPU_SERIES will be 0.
  654. It can also be defined in Makefile itself directly or passed via make command.
  655. It will also define an macro called **CPU_SERIES**, eg. for CPU_SERIES=200, it will define macro CPU_SERIES=200.
  656. This variable is currently used in benchmark cases, and require application Makefile changes.
  657. .. _develop_buildsystem_var_semihost:
  658. SEMIHOST
  659. ~~~~~~~~
  660. If **SEMIHOST=1**, it means it will enable semihost support using openocd.
  661. From 0.5.0, both newlib and libncrt support semihosting feature, and when using semihost,
  662. no need to implement the clib stub functions, which is done by newlib or libncrt semihosting
  663. library.
  664. And for qemu 2023.10 verison, you can also use semihosting feature, simple usage is like below for qemu:
  665. .. code-block:: shell
  666. cd application/baremetal/helloworld
  667. # clean project first
  668. make SOC=evalsoc SEMIHOST=1 clean
  669. make SOC=evalsoc SEMIHOST=1 all
  670. # run on qemu, SEMIHOST=1 is required to pass when run qemu
  671. make SOC=evalsoc SEMIHOST=1 run_qemu
  672. When using semihosting feature with openocd, debug message will print via openocd console.
  673. You need to use it like this(assume you are run on evalsoc, CORE=n300):
  674. In terminal 1, open openocd and monitor the output:
  675. .. code-block:: shell
  676. cd application/baremetal/helloworld
  677. make SOC=evalsoc CORE=n300 run_openocd
  678. # when terminal 2 has download program and start to run, you will be able to see output here
  679. In terminal 2, gdb connect to the openocd exposed gdb port and load program, and run
  680. .. code-block:: shell
  681. # in normal shell terminal
  682. cd application/baremetal/helloworld
  683. make SOC=evalsoc CORE=n300 SEMIHOST=1 clean
  684. make SOC=evalsoc CORE=n300 SEMIHOST=1 run_gdb
  685. # now in gdb command terminal, run the following command
  686. monitor reset halt
  687. load
  688. ## when run continue, you will be able to see output in previous terminal 1 running openocd
  689. continue
  690. .. _develop_buildsystem_var_simulation:
  691. SIMULATION
  692. ~~~~~~~~~~
  693. If **SIMULATION=1**, it means the program is optimized for hardware simulation environment.
  694. Currently if **SIMULATION=1**, it will pass compile option **-DCFG_SIMULATION**,
  695. application can use this **CFG_SIMULATION** to optimize program for hardware
  696. simulation environment.
  697. .. note::
  698. * Currently the benchmark applications in **application/baremetal/benchmark** used this optimization
  699. .. _develop_buildsystem_var_gdb_port:
  700. GDB_PORT
  701. ~~~~~~~~
  702. .. note::
  703. * This new variable **GDB_PORT** is added in Nuclei SDK since version ``0.2.4``
  704. This variable is not used usually, by default the **GDB_PORT** variable is ``3333``.
  705. If you want to change a debug gdb port for openocd and gdb when run ``run_openocd`` and
  706. ``run_gdb`` target, you can pass a new port such as ``3344`` to this variable.
  707. For example, if you want to debug application using run_openocd and
  708. run_gdb and specify a different port other than ``3333``.
  709. You can do it like this, take ``nuclei_fpga_eval`` board for example, such as port ``3344``:
  710. * Open openocd server: ``make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=n300f GDB_PORT=3344 run_openocd``
  711. * connect gdb with openocd server: ``make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=n300f GDB_PORT=3344 run_gdb``
  712. .. _develop_buildsystem_var_jtagsn:
  713. JTAGSN
  714. ~~~~~~
  715. .. note::
  716. * This new variable **JTAGSN** is added in ``0.4.0`` release
  717. This variable is used specify jtag adapter serial number in openocd configuration, need to be supported in
  718. openocd configuration file and makefile, currently **evalsoc** is supported.
  719. It is used by openocd ``adapter serial``.
  720. Assume you have a jtag adapter, serial number is ``FT6S9RD6``, and you want to download program through
  721. this jtag to a fpga with ux900 bitstream on it, you can do it like this.
  722. For windows, you need to pass extra ``A``, eg. ``JTAGSN=FT6S9RD6A``
  723. .. code-block:: shell
  724. # cd to helloworld
  725. cd application/baremetal/helloworld
  726. # clean program
  727. make SOC=evalsoc CORE=ux900 JTAGSN=FT6S9RD6 clean
  728. # upload program
  729. make SOC=evalsoc CORE=ux900 JTAGSN=FT6S9RD6 upload
  730. .. _develop_buildsystem_var_banner:
  731. BANNER
  732. ~~~~~~
  733. If **BANNER=0**, when program is rebuilt, then the banner message print in console will not be print,
  734. banner print is default enabled via ``NUCLEI_BANNER=1`` in ``nuclei_sdk_hal.h``.
  735. when ``BANNER=0``, an macro ``-DNUCLEI_BANNER=0`` will be passed in Makefile.
  736. The banner message looks like this:
  737. .. code-block:: c
  738. Nuclei SDK Build Time: Jul 23 2021, 10:22:50
  739. Download Mode: ILM
  740. CPU Frequency 15999959 Hz
  741. .. _develop_buildsystem_var_v:
  742. V
  743. ~
  744. If **V=1**, it will display compiling message in verbose including compiling options.
  745. By default, no compiling options will be displayed in make console message just to print
  746. less message and make the console message cleaner. If you want to see what compiling option
  747. is used, please pass **V=1** in your make command.
  748. .. _develop_buildsystem_var_silent:
  749. SILENT
  750. ~~~~~~
  751. If **SILENT=1**, it will not display any compiling messsage.
  752. If you don't want to see any compiling message, you can pass **SILENT=1** in your make command.
  753. .. _develop_buildsystem_app_make_vars:
  754. Makefile variables used only in Application Makefile
  755. ----------------------------------------------------
  756. The following variables should be used in application Makefile at your demand,
  757. e.g. ``application/baremetal/demo_timer/Makefile``.
  758. * :ref:`develop_buildsystem_var_target`
  759. * :ref:`develop_buildsystem_var_nuclei_sdk_root`
  760. * :ref:`develop_buildsystem_var_middleware`
  761. * :ref:`develop_buildsystem_var_rtos`
  762. * :ref:`develop_buildsystem_var_stdclib`
  763. * :ref:`develop_buildsystem_var_nmsis_lib`
  764. * :ref:`develop_buildsystem_var_nmsis_lib_arch`
  765. * :ref:`develop_buildsystem_var_riscv_arch`
  766. * :ref:`develop_buildsystem_var_riscv_abi`
  767. * :ref:`develop_buildsystem_var_riscv_cmodel`
  768. * :ref:`develop_buildsystem_var_riscv_tune`
  769. * :ref:`develop_buildsystem_var_nogc`
  770. * :ref:`develop_buildsystem_var_rtthread_msh`
  771. .. _develop_buildsystem_var_target:
  772. TARGET
  773. ~~~~~~
  774. This is a necessary variable which must be defined in application Makefile.
  775. It is used to set the name of the application, it will affect the generated
  776. target filenames.
  777. .. warning::
  778. * Please don't put any spaces in TARGET variable
  779. * The variable shouldn't contain any space
  780. .. code-block:: Makefile
  781. # invalid case 1
  782. TARGET ?= hello world
  783. # invalid case 2
  784. TARGET ?= helloworld # before this # there is a extra space
  785. .. _develop_buildsystem_var_nuclei_sdk_root:
  786. NUCLEI_SDK_ROOT
  787. ~~~~~~~~~~~~~~~
  788. This is a necessary variable which must be defined in application Makefile.
  789. It is used to set the path of Nuclei SDK Root, usually it should be set as
  790. relative path, but you can also set absolute path to point to Nuclei SDK.
  791. .. _develop_buildsystem_var_rtos:
  792. RTOS
  793. ~~~~
  794. **RTOS** variable is used to choose which RTOS will be used in this application.
  795. You can easily find the supported RTOSes in the **<NUCLEI_SDK_ROOT>/OS** directory.
  796. * If **RTOS** is not defined, then baremetal service will be enabled with this application.
  797. See examples in ``application/baremetal``.
  798. * If **RTOS** is set the the following values, RTOS service will be enabled with this application.
  799. - ``FreeRTOS``: :ref:`design_rtos_freertos` service will be enabled, extra macro ``RTOS_FREERTOS`` will be defined,
  800. you can include FreeRTOS header files now, and use FreeRTOS API, for ``FreeRTOS`` application,
  801. you need to have an ``FreeRTOSConfig.h`` header file prepared in you application.
  802. See examples in ``application/freertos``.
  803. - ``UCOSII``: :ref:`design_rtos_ucosii` service will be enabled, extra macro ``RTOS_UCOSII`` will be defined,
  804. you can include UCOSII header files now, and use UCOSII API, for ``UCOSII`` application,
  805. you need to have ``app_cfg.h``, ``os_cfg.h`` and ``app_hooks.c`` files prepared in you application.
  806. See examples in ``application/ucosii``.
  807. - ``RTThread``: :ref:`design_rtos_rtthread` service will be enabled, extra macro ``RTOS_RTTHREAD`` will be defined,
  808. you can include RT-Thread header files now, and use RT-Thread API, for ``RTThread`` application,
  809. you need to have an ``rtconfig.h`` header file prepared in you application.
  810. See examples in ``application/rtthread``.
  811. - ``ThreadX``: :ref:`design_rtos_threadx` service will be enabled, extra macro ``RTOS_THREADX`` will be defined,
  812. you can include ThreadX header files now, and use ThreadX API, for ``ThreadX`` application,
  813. you need to have an ``tx_user.h`` header file prepared in you application.
  814. See examples in ``application/threadx``.
  815. .. _develop_buildsystem_var_middleware:
  816. MIDDLEWARE
  817. ~~~~~~~~~~
  818. **MIDDLEWARE** variable is used to select which middlewares should be used in this application.
  819. You can easily find the available middleware components in the **<NUCLEI_SDK_ROOT>/Components** directory.
  820. * If **MIDDLEWARE** is not defined, not leave empty, no middlware package will be selected.
  821. * If **MIDDLEWARE** is defined with more than 1 string, such as ``fatfs tjpgd``, then these two
  822. middlewares will be selected.
  823. Currently we provide the following middlewares:
  824. * **profiling**: This middleware is not expected to use in Makefile based build system, you need to use it in
  825. Nuclei Studio, it is used to provide code coverage via gcov and profiling via gprof, for details, please refer
  826. to the ``README.md`` in this folder.
  827. .. _develop_buildsystem_var_nmsis_lib:
  828. NMSIS_LIB
  829. ~~~~~~~~~
  830. **NMSIS_LIB** variable is used to select which NMSIS libraries should be used in this application.
  831. Currently you can select the following libraries:
  832. * **nmsis_dsp**: NMSIS DSP prebuilt library.
  833. * **nmsis_nn**: NMSIS NN prebuilt library.
  834. You can select more than libraries of NMSIS. For example, if you want to use NMSIS NN library,
  835. NMSIS DSP library is also required. so you need to set **NMSIS_LIB** like this ``NMSIS_LIB := nmsis_nn nmsis_dsp``
  836. .. _develop_buildsystem_var_nmsis_lib_arch:
  837. NMSIS_LIB_ARCH
  838. ~~~~~~~~~~~~~~
  839. This variable is used to select real nmsis dsp/nn library arch used, if not set, it will use **RISCV_ARCH** passed.
  840. The **NMSIS_LIB_ARCH** need to match the prebuilt libraries located in **NMSIS/Library/DSP/GCC** and **NMSIS/Library/NN/GCC**, eg. ``NMSIS_LIB_ARCH := rv32imafc_zfh_zvfh_zve32f_zba_zbb_zbc_zbs_xxldspn1x`` will select ``libnmsis_dsp_rv32imafc_zfh_zvfh_zve32f_zba_zbb_zbc_zbs_xxldspn1x.a`` if ``NMSIS_LIB := nmsis_dsp``
  841. This is useful when you want to specify a different arch for library.
  842. eg. When your cpu arch is ``rv32imafdc_zba_zbb_zbc_zbs_zk_zks_xxldspn3x``, and you want to use ``rv32imafdc_zba_zbb_zbc_zbs_xxldspn1x``, then you can set **NMSIS_LIB_ARCH=rv32imafdc_zba_zbb_zbc_zbs_xxldspn1x** in Makefile, otherwise it will use the real cpu arch passed by **CORE** and **ARCH_EXT** or directly via **RISCV_ARCH**.
  843. .. _develop_buildsystem_var_stdclib:
  844. STDCLIB
  845. ~~~~~~~
  846. **STDCLIB** variable is used to select which standard c runtime library will be used.
  847. If not defined, the default value will be ``newlib_nano``.
  848. In Nuclei GNU Toolchain, we destributed newlib/newlib-nano/Nuclei c runtime library,
  849. so user can select different c runtime library according to their requirement.
  850. Newlib is a simple ANSI C library, math library, available for both RV32 and RV64.
  851. Nuclei C runtime library is a highly optimized c library designed for deeply embedded user cases,
  852. can provided smaller code size and highly optimized floating point support compared to Newlib.
  853. From 0.5.0 release, to support both gcc and clang compiler, we decided not to use ``--specs=`` option to
  854. select system library, instead of that, we start to use ``--nodefaultlibs`` options, and link the required
  855. system libraries by the ``STDCLIB`` variable choice, so need to link desired libraries such as:
  856. * ``-lgcc``: a standard library (linked by default, excluded by -nodefaultlibs) that provides internal subroutines to overcome shortcomings of particular machines, see https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html.
  857. * ``-lgcov``: a library used to test coverage program, known as ``gcov/gprof``, see https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
  858. * ``-lc/-lc_nano``: newlib c library or newlib nano c library, see https://sourceware.org/newlib/docs.html
  859. * ``-lm``: newlib math library, see https://sourceware.org/newlib/libm.html
  860. * ``-lstdc++``: gnu standard c++ library, see https://gcc.gnu.org/onlinedocs/libstdc++
  861. * ``-lsemihost``: riscv semihosting library which implement a set of standard I/O and file I/O operations, see https://github.com/riscv-mcu/riscv-newlib/tree/nuclei/newlib-4.3.0/libgloss/riscv
  862. * ``-lnosys``: a set of stub functions which implement a set of standard I/O operations but does nothing, and when link with it, it will throw link warning, see https://github.com/riscv-mcu/riscv-newlib/blob/nuclei/newlib-4.3.0/libgloss/libnosys
  863. * ``-lncrt_pico/-lncrt_nano/-lncrt_small/-lncrt_balanced/-lncrt_fast``: Nuclei libncrt library, it provides pico/nano/small/balanced/fast variant to provide standard c library, math library, and libgcc library features, and need to use together with ``-lheapops_minimal/-lheapops_basic/-lheapops_realtime`` heap operation API, and ``-lfileops_uart/-lfileops_semi/-lfileops_rtt`` file io operation API, when using this libncrt library, please don't link ``-lgcc -lc_nano/-lc -lm -lsemihost -lnosys``, and it also can't link with ``-lstdc++``
  864. * Upgrading libncrt from Nuclei GNU Toolchain 2022.12 to Nuclei Toolchain 2023.10, please change it like this, take **libncrt_small** as example:
  865. - **asm/c/c++ options**: ``--specs=libncrt_small.specs`` -> ``--specs=libncrt_small.specs`` works for gcc, or ``-isystem=/include/libncrt`` works for both gcc and clang
  866. - **ld options**: ``--specs=libncrt_small.specs`` -> ``--specs=libncrt_small.specs -lheapops_basic -lfileops_uart`` works for gcc, ``-nodefaultlibs -lncrt_small -lheapops_basic -lfileops_uart`` works for both gcc and clang
  867. - We recommend you to use later version works for both gcc and clang, ``-nodefaultlibs`` is used to exclude startup crt, libgcc and c library in default gcc or clang, use the version specified by us to use libncrt.
  868. .. list-table:: Available STDCLIB choices
  869. :widths: 10 70
  870. :header-rows: 1
  871. :align: center
  872. * - **STDCLIB**
  873. - Description
  874. * - newlib_full
  875. - | Normal version of newlib, optimized for speed at cost of size.
  876. | It provided full feature of newlib, with file io supported.
  877. * - newlib_fast
  878. - Newlib nano version, with printf float and scanf float support.
  879. * - newlib_small
  880. - Newlib nano version, with printf float support.
  881. * - newlib_nano
  882. - Newlib nano version, without printf/scanf float support.
  883. * - libncrt_fast
  884. - Nuclei C runtime library optimized for speed, full feature
  885. * - libncrt_balanced
  886. - Nuclei C runtime library balanced at speed and code size, full feature
  887. * - libncrt_small
  888. - Nuclei C runtime library optimized for code size, full feature
  889. * - libncrt_nano
  890. - Nuclei C runtime library optimized for code size, without float/double support
  891. * - libncrt_pico
  892. - Nuclei C runtime library optimized for code size, without long/long long/float/double support
  893. * - nostd
  894. - no std c library will be used, and don't search the standard system directories for header files
  895. * - nospec
  896. - no std c library will be used, not pass any --specs options
  897. .. note::
  898. * For clang based compiler, if ``-u _print_float`` is not passed in linker options, it may fail
  899. during link process, so here we pass ``-u _print_float`` for newlib_nano, then it means for
  900. nuclei_llvm and terapines toolchain, ``STDCLIB=newlib_nano`` equals to ``STDCLIB=newlib_small``
  901. * Nuclei libncrt library couldn't be used with terapines toolchain, so you can't use any libncrt library
  902. when you are using terapines toolchain.
  903. * About Newlib and Newlib nano difference, please check
  904. https://github.com/riscv-collab/riscv-newlib/blob/riscv-newlib-3.2.0/newlib/README
  905. * About Nuclei C runtime library, it provided basic libgcc, c library and math library feature, but
  906. it didn't provided all the features that newlib can do, it is highly optimized for deeply embedded scenery,
  907. user no need to link with ``-lm`` when using libncrt library when math library is needed.
  908. * Nuclei C runtime library is only available in Nuclei GNU Toolchain released after Nov 2021,
  909. about how to use this library, please follow doc located in ``gcc\share\pdf``, changes need
  910. to be done in startup code, linker script, stub code, and compiler options, you can check commit
  911. history of nuclei sdk for support of libncrt.
  912. * Nuclei C runtime library(libncrt) only support RV32 CPU target, so you cannot use it with RV64 CPU.
  913. * Since there are different c runtime library can be chosen now, so developer
  914. need to provide different stub functions for different library, please check
  915. ``SoC/evalsoc/Common/Source/Stubs/`` and ``SoC/evalsoc/build.mk`` for example.
  916. .. _develop_buildsystem_var_ncrtheap:
  917. NCRTHEAP
  918. ~~~~~~~~
  919. .. note::
  920. * This variable is added in 0.5.0 release to support libncrt v3.0.0.
  921. This variable is only valid when using libncrt c library >= v3.0.0, and you can choose different
  922. heapops when using libncrt c library to do heap related operations such as malloc or free.
  923. * **basic**: default, this is previous release of libncrt c library used one. A low-overhead best-fit heap where allocation and deallocation have very little internal fragmentation
  924. * **realtime**: A real-time heap where allocation and deallocation have O(1) performance
  925. * **minimal**: An allocate-only heap where deallocation and reallocation are not implemented
  926. For previous libncrt library, this heapops is default binded with libncrt library, so you can't
  927. choose different heap type, but now you can choose according to your requirements.
  928. .. _develop_buildsystem_var_ncrtio:
  929. NCRTIO
  930. ~~~~~~
  931. .. note::
  932. * This variable is added in 0.5.0 release to support libncrt v3.0.0.
  933. This variable is only valid when using libncrt c library >= v3.0.0, and you can choose different
  934. fileops when using libncrt c library to do basic input/output operations.
  935. * **uart**: default, lower level input/output via uart, developer need to implement metal_tty_putc/getc
  936. * **semi**: input/output via semihosting, if you pass **SEMIHOST=1** in make, it will default choose this one when using libncrt library.
  937. * **rtt**: input/output via jlink rtt, require to use JLink tool.
  938. .. _develop_buildsystem_var_smp:
  939. SMP
  940. ~~~
  941. **SMP** variable is used to control smp cpu core count, valid number must > 1.
  942. When **SMP** variable is defined, extra gcc options for ld is passed
  943. ``-Wl,--defsym=__SMP_CPU_CNT=$(SMP)``, and extra c macro ``-DSMP_CPU_CNT=$(SMP)``
  944. is defined this is passed in each SoC's build.mk, such as ``SoC/evalsoc/build.mk``.
  945. When SMP variable is defined, extra openocd command ``set SMP $(SMP)`` will also
  946. be passed when run openocd upload or create a openocd server.
  947. For SMP application, please check ``application/baremetal/smphello``, if you want to implement
  948. a smp application, you need to reimplement ``smp_main``, which all harts will run to this function
  949. instead of ``main``, if you don't implement it, a weak ``smp_main`` in ``startup_<Device>.S`` will
  950. be used, and only boot hartid specified by **BOOT_HARTID** will enter to main, other harts will do wfi.
  951. .. _develop_buildsystem_var_boot_hartid:
  952. BOOT_HARTID
  953. ~~~~~~~~~~~
  954. .. note::
  955. * This new variable **BOOT_HARTID** is added in ``0.4.0`` release
  956. This variable is used to control the boot hartid in a multiple core system.
  957. If **SMP** variable is specified, it means this application is expected to be a smp application,
  958. otherwise it means this application is expected to be a amp application.
  959. For amp application, only the boot hart specified by **BOOT_HARTID** will run, other harts
  960. will directly do wfi when startup, but for smp application, other hartid will do normal boot
  961. code instead of code/data/bss init, and do sync harts to make sure all harts boots.
  962. For both amp and smp application, the program should execute on a share memory which all
  963. harts can access, not hart private memory such as ilm/dlm.
  964. Currently **SMP** and **BOOT_HARTID** support all require SOC support code to implement it, currently
  965. evalsoc support it, currently qemu simulation didn't work for SMP/AMP use case.
  966. Here is some basic usage for SMP and BOOT_HARTID on UX900 x4, run on external ddr.
  967. .. code-block:: shell
  968. # cd to helloworld
  969. cd <Nuclei SDK>/application/baremetal/helloworld
  970. # clean program
  971. make SOC=evalsoc CORE=ux900 clean
  972. # AMP: choose hart 1 as boot hartid, other harts spin
  973. make SOC=evalsoc CORE=ux900 BOOT_HARTID=1 DOWNLOAD=ddr clean upload
  974. cd <Nuclei SDK>/application/baremetal/smphello
  975. # SMP: choose hart 2 as boot hartid
  976. make SOC=evalsoc CORE=ux900 BOOT_HARTID=2 SMP=4 DOWNLOAD=ddr clean upload
  977. .. _develop_buildsystem_var_hartid_ofs:
  978. HARTID_OFS
  979. ~~~~~~~~~~
  980. .. note::
  981. * This new variable is added in ``0.5.0`` release
  982. This variable is used to set hartid offset relative to real hart index in a complex AMP SoC system.
  983. eg.
  984. In a SoC system, it has 2 CPU, CPU 0 has 2 smp core, CPU 1 has 1 core, and CPU 0 hartid is 0, 1,
  985. and CPU 1 hartid is 2, so for CPU 0, HARTID_OFS is 0, for CPU 1, HARTID_OFS is 2.
  986. .. _develop_buildsystem_var_stacksz:
  987. STACKSZ
  988. ~~~~~~~
  989. **STACKSZ** variable is used to control the per core stack size reserved in linker script,
  990. this need to cooperate with link script file and linker options.
  991. In link script file, ``__STACK_SIZE`` symbol need to use ``PROVIDE`` feature of ld
  992. to define a weak version, such as ``PROVIDE(__STACK_SIZE = 2K);``, and gcc will pass
  993. ld options ``-Wl,--defsym=__STACK_SIZE=$(STACKSZ)`` to overwrite the default value if
  994. **STACKSZ** is defined.
  995. **STACKSZ** variable must be a valid value accepted by ld, such as 0x2000, 2K, 4K, 8192.
  996. For SMP version, stack size space need to reserve **STACKSZ** x SMP Core Count size.
  997. You can refer to ``SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/gcc_evalsoc_ilm.ld`` for smp version.
  998. .. _develop_buildsystem_var_heapsz:
  999. HEAPSZ
  1000. ~~~~~~
  1001. **HEAPSZ** variable is used to control the heap size reserved in linker script,
  1002. this need to cooperate with link script file and linker options.
  1003. In link script file, ``__HEAP_SIZE`` symbol need to use ``PROVIDE`` feature of ld
  1004. to define a weak version, such as ``PROVIDE(__HEAP_SIZE = 2K);``, and gcc will pass
  1005. ld options ``-Wl,--defsym=__HEAP_SIZE=$(HEAPSZ)`` to overwrite the default value if
  1006. **HEAPSZ** is defined.
  1007. **HEAPSZ** variable must be a valid value accepted by ld, such as 0x2000, 2K, 4K, 8192.
  1008. .. _develop_buildsystem_var_riscv_arch:
  1009. RISCV_ARCH
  1010. ~~~~~~~~~~
  1011. **RISCV_ARCH** variable is used to control compiler option ``-mcmodel=$(RISCV_ARCH)``.
  1012. It might override RISCV_ARCH defined in SoC build.mk, according to your build.mk implementation.
  1013. **RISCV_ARCH** might directly affect the gcc compiler option depended on the implementation of SoC build.mk.
  1014. Take ``SOC=evalsoc`` for example.
  1015. * **CORE=n300 RISCV_ARCH=rv32imafdc_zk_zks RISCV_ABI=ilp32d ARCH_EXT=_zba_zbb_zbc_zbs**, then final compiler options will be
  1016. ``-march=rv32imafdc_zk_zks -mabi=ilp32d -mtune=nuclei-300-series``. The **ARCH_EXT** is ignored.
  1017. .. _develop_buildsystem_var_riscv_abi:
  1018. RISCV_ABI
  1019. ~~~~~~~~~
  1020. **RISCV_ABI** variable is used to control compiler option ``-mcmodel=$(RISCV_ABI)``.
  1021. It might override RISCV_ABI defined in SoC build.mk, according to your build.mk implementation.
  1022. .. _develop_buildsystem_var_riscv_cmodel:
  1023. RISCV_CMODEL
  1024. ~~~~~~~~~~~~
  1025. **RISCV_CMODEL** is used to control compiler option ``-mcmodel=$(RISCV_CMODEL)``.
  1026. For RV32, default value is ``medlow``, otherwise ``medany`` for RV64.
  1027. You can set ``RISCV_CMODEL`` to override predefined value.
  1028. .. _develop_buildsystem_var_riscv_tune:
  1029. RISCV_TUNE
  1030. ~~~~~~~~~~
  1031. **RISCV_TUNE** is used to control compiler option ``-mtune=$(RISCV_TUNE)``.
  1032. It is defined in SoC build.mk, you can override it if your implementation
  1033. allow it.
  1034. .. _develop_buildsystem_var_app_common_flags:
  1035. APP_COMMON_FLAGS
  1036. ~~~~~~~~~~~~~~~~
  1037. .. note::
  1038. * Added in 0.4.0 release.
  1039. This variable is used to define app common compiler flags to all c/asm/cpp compiler.
  1040. You can pass it via make command to define extra flags to compile application.
  1041. .. _develop_buildsystem_var_app_asmflags:
  1042. APP_ASMFLAGS
  1043. ~~~~~~~~~~~~
  1044. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app asm flags.
  1045. .. _develop_buildsystem_var_app_cflags:
  1046. APP_CFLAGS
  1047. ~~~~~~~~~~
  1048. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app c flags.
  1049. .. _develop_buildsystem_var_app_cxxflags:
  1050. APP_CXXFLAGS
  1051. ~~~~~~~~~~~~
  1052. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app cxx flags.
  1053. .. _develop_buildsystem_var_app_ldflags:
  1054. APP_LDFLAGS
  1055. ~~~~~~~~~~~
  1056. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app linker flags.
  1057. .. _develop_buildsystem_var_nogc:
  1058. NOGC
  1059. ~~~~
  1060. **NOGC** variable is used to control whether to enable gc sections to reduce program
  1061. code size or not, by default GC is enabled to reduce code size.
  1062. When GC is enabled, these options will be added:
  1063. * Adding to compiler options: ``-ffunction-sections -fdata-sections``
  1064. * Adding to linker options: ``-Wl,--gc-sections -Wl,--check-sections``
  1065. If you want to enable this GC feature, you can set **NOGC=0** (default), GC feature will
  1066. remove sections for you, but sometimes it might remove sections that are useful,
  1067. e.g. For Nuclei SDK test cases, we use ctest framework, and we need to set **NOGC=1**
  1068. to disable GC feature.
  1069. When ``NOGC=0``(default), extra compile options ``-ffunction-sections -fdata-sections``,
  1070. and extra link options ``-Wl,--gc-sections -Wl,--check-sections`` will be passed.
  1071. .. _develop_buildsystem_var_rtthread_msh:
  1072. RTTHREAD_MSH
  1073. ~~~~~~~~~~~~
  1074. **RTTHREAD_MSH** variable is valid only when **RTOS** is set to **RTThread**.
  1075. When **RTTHREAD_MSH** is set to **1**:
  1076. * The RTThread MSH component source code will be included
  1077. * The MSH thread will be enabled in the background
  1078. * Currently the msh getchar implementation is using a weak function implemented
  1079. in ``rt_hw_console_getchar`` in ``OS/RTTThread/libcpu/risc-v/nuclei/cpuport.c``
  1080. .. _develop_buildsystem_app_build_vars:
  1081. Build Related Makefile variables used only in Application Makefile
  1082. ------------------------------------------------------------------
  1083. If you want to specify additional compiler flags, please follow this guidance
  1084. to modify your application Makefile.
  1085. Nuclei SDK build system defined the following variables to control the
  1086. build options or flags.
  1087. * :ref:`develop_buildsystem_var_incdirs`
  1088. * :ref:`develop_buildsystem_var_c_incdirs`
  1089. * :ref:`develop_buildsystem_var_cxx_incdirs`
  1090. * :ref:`develop_buildsystem_var_asm_incdirs`
  1091. * :ref:`develop_buildsystem_var_srcdirs`
  1092. * :ref:`develop_buildsystem_var_c_srcdirs`
  1093. * :ref:`develop_buildsystem_var_cxx_srcdirs`
  1094. * :ref:`develop_buildsystem_var_asm_srcdirs`
  1095. * :ref:`develop_buildsystem_var_c_srcs`
  1096. * :ref:`develop_buildsystem_var_cxx_srcs`
  1097. * :ref:`develop_buildsystem_var_asm_srcs`
  1098. * :ref:`develop_buildsystem_var_exclude_srcs`
  1099. * :ref:`develop_buildsystem_var_common_flags`
  1100. * :ref:`develop_buildsystem_var_cflags`
  1101. * :ref:`develop_buildsystem_var_cxxflags`
  1102. * :ref:`develop_buildsystem_var_asmflags`
  1103. * :ref:`develop_buildsystem_var_ldflags`
  1104. * :ref:`develop_buildsystem_var_ldlibs`
  1105. * :ref:`develop_buildsystem_var_libdirs`
  1106. * :ref:`develop_buildsystem_var_linker_script`
  1107. .. _develop_buildsystem_var_incdirs:
  1108. INCDIRS
  1109. ~~~~~~~
  1110. This **INCDIRS** is used to pass C/CPP/ASM include directories.
  1111. e.g. To include current directory ``.`` and ``inc`` for C/CPP/ASM
  1112. .. code-block:: makefile
  1113. INCDIRS = . inc
  1114. .. _develop_buildsystem_var_c_incdirs:
  1115. C_INCDIRS
  1116. ~~~~~~~~~
  1117. This **C_INCDIRS** is used to pass C only include directories.
  1118. e.g. To include current directory ``.`` and ``cinc`` for C only
  1119. .. code-block:: makefile
  1120. C_INCDIRS = . cinc
  1121. .. _develop_buildsystem_var_cxx_incdirs:
  1122. CXX_INCDIRS
  1123. ~~~~~~~~~~~
  1124. This **CXX_INCDIRS** is used to pass CPP only include directories.
  1125. e.g. To include current directory ``.`` and ``cppinc`` for CPP only
  1126. .. code-block:: makefile
  1127. CXX_INCDIRS = . cppinc
  1128. .. _develop_buildsystem_var_asm_incdirs:
  1129. ASM_INCDIRS
  1130. ~~~~~~~~~~~
  1131. This **ASM_INCDIRS** is used to pass ASM only include directories.
  1132. e.g. To include current directory ``.`` and ``asminc`` for ASM only
  1133. .. code-block:: makefile
  1134. ASM_INCDIRS = . asminc
  1135. .. _develop_buildsystem_var_srcdirs:
  1136. SRCDIRS
  1137. ~~~~~~~
  1138. This **SRCDIRS** is used to set the source directories used to search
  1139. the C/CPP/ASM source code files, it will not do recursively.
  1140. e.g. To search C/CPP/ASM source files in directory ``.`` and ``src``
  1141. .. code-block:: makefile
  1142. SRCDIRS = . src
  1143. .. _develop_buildsystem_var_c_srcdirs:
  1144. C_SRCDIRS
  1145. ~~~~~~~~~
  1146. This **C_SRCDIRS** is used to set the source directories used to search
  1147. the C only source code files(*.c, *.C), it will not do recursively.
  1148. e.g. To search C only source files in directory ``.`` and ``csrc``
  1149. .. code-block:: makefile
  1150. C_SRCDIRS = . csrc
  1151. .. _develop_buildsystem_var_cxx_srcdirs:
  1152. CXX_SRCDIRS
  1153. ~~~~~~~~~~~
  1154. This **CXX_SRCDIRS** is used to set the source directories used to search
  1155. the CPP only source code files(*.cpp, *.CPP), it will not do recursively.
  1156. e.g. To search CPP only source files in directory ``.`` and ``cppsrc``
  1157. .. code-block:: makefile
  1158. CXX_SRCDIRS = . cppsrc
  1159. .. _develop_buildsystem_var_asm_srcdirs:
  1160. ASM_SRCDIRS
  1161. ~~~~~~~~~~~
  1162. This **ASM_SRCDIRS** is used to set the source directories used to search
  1163. the ASM only source code files(*.s, *.S), it will not do recursively.
  1164. e.g. To search ASM only source files in directory ``.`` and ``asmsrc``
  1165. .. code-block:: makefile
  1166. ASM_SRCDIRS = . asmsrc
  1167. .. _develop_buildsystem_var_c_srcs:
  1168. C_SRCS
  1169. ~~~~~~
  1170. If you just want to include a few of C source files in directories, you can use this
  1171. **C_SRCS** variable, makefile wildcard pattern supported.
  1172. e.g. To include ``main.c`` and ``src/hello.c``
  1173. .. code-block:: makefile
  1174. C_SRCS = main.c src/hello.c
  1175. .. _develop_buildsystem_var_cxx_srcs:
  1176. CXX_SRCS
  1177. ~~~~~~~~
  1178. If you just want to include a few of CPP source files in directories, you can use this
  1179. **CXX_SRCS** variable, makefile wildcard pattern supported.
  1180. e.g. To include ``main.cpp`` and ``src/hello.cpp``
  1181. .. code-block:: makefile
  1182. CXX_SRCS = main.cpp src/hello.cpp
  1183. .. _develop_buildsystem_var_asm_srcs:
  1184. ASM_SRCS
  1185. ~~~~~~~~
  1186. If you just want to include a few of ASM source files in directories, you can use this
  1187. **ASM_SRCS** variable, makefile wildcard pattern supported.
  1188. e.g. To include ``asm.s`` and ``src/test.s``
  1189. .. code-block:: makefile
  1190. ASM_SRCS = asm.s src/test.s
  1191. .. _develop_buildsystem_var_exclude_srcs:
  1192. EXCLUDE_SRCS
  1193. ~~~~~~~~~~~~
  1194. If you just want to exclude a few of c/asm/cpp source files in directories,
  1195. you can use this **EXCLUDE_SRCS** variable, makefile wildcard pattern supported.
  1196. e.g. To exclude ``test2.c`` and ``src/test3.c``
  1197. .. code-block:: makefile
  1198. EXCLUDE_SRCS = test2.c src/test3.c
  1199. .. _develop_buildsystem_var_common_flags:
  1200. COMMON_FLAGS
  1201. ~~~~~~~~~~~~
  1202. This **COMMON_FLAGS** variable is used to define common compiler flags to all c/asm/cpp compiler.
  1203. For example, you can add a newline ``COMMON_FLAGS += -O3 -funroll-loops -fpeel-loops``
  1204. in your application Makefile and these options will be passed to C/ASM/CPP compiler.
  1205. This variable should be defined in Makefile.
  1206. .. _develop_buildsystem_var_cflags:
  1207. CFLAGS
  1208. ~~~~~~
  1209. Different to **COMMON_FLAGS**, this **CFLAGS** variable is used to define common compiler flags to C compiler only.
  1210. For example, you can add a newline ``CFLAGS += -O3 -funroll-loops -fpeel-loops``
  1211. in your application Makefile and these options will be passed to C compiler.
  1212. .. _develop_buildsystem_var_cxxflags:
  1213. CXXFLAGS
  1214. ~~~~~~~~
  1215. Different to **COMMON_FLAGS**, this **CXXFLAGS** variable is used to define common compiler flags to cpp compiler only.
  1216. For example, you can add a newline ``CXXFLAGS += -O3 -funroll-loops -fpeel-loops``
  1217. in your application Makefile and these options will be passed to cpp compiler.
  1218. .. _develop_buildsystem_var_asmflags:
  1219. ASMFLAGS
  1220. ~~~~~~~~
  1221. Different to **COMMON_FLAGS**, this **ASMFLAGS** variable is used to define common compiler flags to asm compiler only.
  1222. For example, you can add a newline ``ASMFLAGS += -O3 -funroll-loops -fpeel-loops``
  1223. in your application Makefile and these options will be passed to asm compiler.
  1224. .. _develop_buildsystem_var_ldflags:
  1225. LDFLAGS
  1226. ~~~~~~~
  1227. This **LDFLAGS** is used to pass extra linker flags, for example,
  1228. if you want to use standard system libraries when linking, you can add a newline
  1229. ``LDFLAGS += -nodefaultlibs`` in you application Makefile.
  1230. If you want to link with other libraries, please use ``LDLIBS`` and ``LIBDIRS`` variables.
  1231. .. _develop_buildsystem_var_ldlibs:
  1232. LDLIBS
  1233. ~~~~~~
  1234. This **LDLIBS** variable is library flags or names given to compilers
  1235. when they are supposed to invoke the linker.
  1236. Non-library linker flags, such as -L, should go in the **LIBDIRS** or **LDFLAGS** variable.
  1237. .. _develop_buildsystem_var_libdirs:
  1238. LIBDIRS
  1239. ~~~~~~~
  1240. This **LIBDIRS** variable is used to store the library directories, which could
  1241. be used together with **LDLIBS**.
  1242. For example, if you have a library located in **$(NUCLEI_SDK_ROOT)/Library/DSP/libnmsis_dsp_rv32imac.a**,
  1243. and you want to link it, then you can define these lines:
  1244. .. code-block:: makefile
  1245. LDLIBS = -lnmsis_dsp_rv32imac
  1246. LIBDIRS = $(NUCLEI_SDK_ROOT)/Library/DSP
  1247. .. _develop_buildsystem_var_linker_script:
  1248. LINKER_SCRIPT
  1249. ~~~~~~~~~~~~~
  1250. This **LINKER_SCRIPT** variable could be used to set the link script of the application.
  1251. By default, there is no need to set this variable, since the build system will define
  1252. a default linker script for application according to the build configuration. If you want
  1253. to define your own linker script, you can set this variable.
  1254. For example, ``LINKER_SCRIPT := gcc.ld``.
  1255. .. _GNU Make Standard Library (GMSL): http://sourceforge.net/projects/gmsl/
  1256. .. _B 1.0 extension: https://github.com/riscv/riscv-bitmanip/releases/tag/1.0.0
  1257. .. _P 0.5.4 extension: https://github.com/riscv/riscv-p-spec/blob/33be869910077afd52653031f18a235b1f9d4442/P-ext-proposal.adoc
  1258. .. _K 1.0 extension: https://github.com/riscv/riscv-crypto/releases/tag/v1.0.0
  1259. .. _V 1.0 extension: https://github.com/riscv/riscv-v-spec/releases/tag/v1.0
  1260. .. _Zc 1.0 extension: https://github.com/riscv/riscv-code-size-reduction/releases/tag/v1.0.4-3
  1261. .. _zfh extension: https://wiki.riscv.org/display/HOME/Recently+Ratified+Extensions
  1262. .. _zvfh extension: https://github.com/riscv/riscv-v-spec/releases/tag/zvfh
  1263. .. _Nuclei Toolchain 2023.10: https://github.com/riscv-mcu/riscv-gnu-toolchain/releases/tag/nuclei-2023.10