buildsystem.rst 72 KB

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