buildsystem.rst 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. .. _develop_buildsystem:
  2. Build System based on Makefile
  3. ==============================
  4. Nuclei N100 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 N100 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 N100 SDK build system entry file,
  34. application's Makefile need to include this file to use all the features of
  35. Nuclei N100 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, sram, sram ilm)`` will check ``sram`` whether existed in
  84. ``sram ilm``, if existed, return ``sram``, 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. * Linker script used according to the **DOWNLOAD** mode settings
  119. * OpenOCD debug configuration file used for the SoC and Board
  120. * Some extra compiling or debugging options
  121. A valid SoC should be organized like this, take ``evalsoc`` as example:
  122. .. code-block::
  123. SoC/evalsoc
  124. ├── Board
  125. │ └── nuclei_fpga_eval
  126. │ ├── Include
  127. │ │ ├── board_nuclei_fpga_eval.h
  128. │ │ └── nuclei_sdk_hal.h
  129. │ ├── Source
  130. │ │ ├── IAR
  131. │ │ └── GCC
  132. │ └── openocd_evalsoc.cfg
  133. ├── build.mk
  134. └── Common
  135. ├── Include
  136. │ ├── evalsoc.h
  137. │ ├── ... ...
  138. │ ├── evalsoc_uart.h
  139. │ ├── nuclei_sdk_soc.h
  140. │ └── system_evalsoc.h
  141. └── Source
  142. ├── Drivers
  143. │ ├── ... ...
  144. │ └── evalsoc_uart.c
  145. ├── GCC
  146. │ ├── intexc_evalsoc.S
  147. │ ├── intexc_evalsoc_s.S
  148. │ └── startup_evalsoc.S
  149. ├── IAR
  150. │ ├── intexc_evalsoc.S
  151. │ ├── intexc_evalsoc_s.S
  152. │ └── startup_evalsoc.c
  153. ├── Stubs
  154. │ ├── newlib
  155. │ ├── libncrt
  156. │ └── iardlib
  157. ├── evalsoc_common.c
  158. └── system_evalsoc.c
  159. .. _develop_buildsystem_makefile_rtos:
  160. Makefile.rtos
  161. ~~~~~~~~~~~~~
  162. This **Makefile.rtos** will include **<NUCLEI_SDK_ROOT>/OS/<RTOS>/build.mk**
  163. according to our :ref:`develop_buildsystem_var_rtos` variable.
  164. A valid rtos should be organized like this, take ``UCOSII`` as example:
  165. .. code-block::
  166. OS/UCOSII/
  167. ├── arch
  168. ├── build.mk
  169. ├── license.txt
  170. ├── readme.md
  171. └── source
  172. If no :ref:`develop_buildsystem_var_rtos` is chosen, then RTOS
  173. code will not be included during compiling, user will develop
  174. baremetal application.
  175. If **FreeRTOS**, **UCOSII** or **RTThread** RTOS is chosen, then FreeRTOS
  176. UCOSII, or RTThread source code will be included during compiling, and extra
  177. compiler option ``-DRTOS_$(RTOS_UPPER)`` will be passed, then user can develop RTOS application.
  178. For example, if ``FreeRTOS`` is selected, then ``-DRTOS_FREERTOS`` compiler option
  179. will be passed.
  180. .. _develop_buildsystem_makefile_components:
  181. Makefile.components
  182. ~~~~~~~~~~~~~~~~~~~
  183. This **Makefile.components** will include ``build.mk`` Makefiles of selected components defined
  184. via makefile variable :ref:`develop_buildsystem_var_middleware`, the Makefiles are placed in
  185. the sub-folders of **<NUCLEI_SDK_ROOT>/Components/**.
  186. A valid middleware component should be organized like this, take ``fatfs`` as example :
  187. .. code-block::
  188. Components/fatfs/
  189. ├── build.mk
  190. ├── documents
  191. ├── LICENSE.txt
  192. └── source
  193. For example, if there are two valid middleware components in **<NUCLEI_SDK_ROOT>/Components/**, called
  194. ``fatfs`` and ``tjpgd``, and you want to use them in your application, then you can set ``MIDDLEWARE``
  195. like this ``MIDDLEWARE := fatfs tjpgd``, then the application will include these two middlewares into
  196. build process.
  197. .. _develop_buildsystem_makefile_core:
  198. Makefile.core
  199. ~~~~~~~~~~~~~
  200. This **Makefile.core** is used to define the RISC-V ARCH and ABI used during
  201. compiling of the CORE list supported.
  202. If you want to add a new **CORE**, you need to add a new line before **SUPPORTED_CORES**,
  203. and append the new **CORE** to **SUPPORTED_CORES**.
  204. For example, if you want to add a new **CORE** called **n101**, and the **n101**'s
  205. **ARCH** and **ABI** are ``rv32imac`` and ``ilp32``, then you can add a new line
  206. like this ``N101_CORE_ARCH_ABI = rv32imac ilp32``, and append **n101** to **SUPPORTED_CORES**
  207. like this ``SUPPORTED_CORES = n100e n100em n100ezmmul n100 n100m n100zmmul n101``
  208. .. note::
  209. * The appended new **CORE** need to lower-case, e.g. *n101*
  210. * The new defined variable **N101_CORE_ARCH_ABI** need to be all upper-case.
  211. .. _develop_buildsystem_makefile_global:
  212. Makefile.global
  213. ~~~~~~~~~~~~~~~
  214. This **Makefile.global** file is an optional file, and will not be tracked by git,
  215. user can create own **Makefile.global** in **<NUCLEI_SDK_ROOT>/Build** directory.
  216. In this file, user can define custom **SOC**, **BOARD**, **DOWNLOAD** options to
  217. overwrite the default configuration.
  218. For example, if you will use only the :ref:`design_board_nuclei_fpga_eval`, you can
  219. create the **<NUCLEI_SDK_ROOT>/Build/Makefile.global** as below:
  220. .. code-block:: Makefile
  221. SOC ?= evalsoc
  222. BOARD ?= nuclei_fpga_eval
  223. DOWNLOAD ?= sram
  224. .. note::
  225. * If you add above file, then you can build, run, debug application without passing
  226. **SOC**, **BOARD** and **DOWNLOAD** variables using make command for
  227. :ref:`design_board_nuclei_fpga_eval` board, e.g.
  228. - Build and run application for :ref:`design_board_nuclei_fpga_eval`: ``make run``
  229. - Debug application for :ref:`design_board_nuclei_fpga_eval`: ``make debug``
  230. * If you create the **Makefile.global** like above sample code, you will also be able
  231. to use Nuclei N100 SDK build system as usually, it will only change the default **SOC**,
  232. **BOARD** and **DOWNLOAD**, but you can still override the default variable using
  233. make command, such as ``make SOC=evalsoc BOARD=nuclei_fpga_eval DOWNLOAD=sram``
  234. .. _develop_buildsystem_makefile_local:
  235. Makefile.local
  236. ~~~~~~~~~~~~~~
  237. As the :ref:`develop_buildsystem_makefile_global` is used to override the default Makefile
  238. configurations, and the **Makefile.local** is used to override application level Makefile
  239. configurations, and also this file will not be tracked by git.
  240. User can create ``Makefile.local`` file in any of the application folder, placed together with
  241. the application Makefile, for example, you can create ``Makefile.local`` in ``application/baremetal/helloworld``
  242. to override default make configuration for this **helloworld** application.
  243. If you want to change the default board for **helloworld** to use :ref:`design_board_nuclei_fpga_eval`,
  244. you can create ``application/baremetal/helloworld/Makefile.local`` as below:
  245. .. code-block:: Makefile
  246. SOC ?= evalsoc
  247. BOARD ?= nuclei_fpga_eval
  248. DOWNLOAD ?= sram
  249. .. note::
  250. * This local make configuration will override global and default make configuration.
  251. * If you just want to change only some applications' makefile configuration, you can
  252. add and update ``Makefile.local`` for those applications.
  253. .. _develop_buildsystem_make_targets:
  254. Makefile targets of make command
  255. --------------------------------
  256. Here is a list of the :ref:`table_dev_buildsystem_4`.
  257. .. _table_dev_buildsystem_4:
  258. .. list-table:: Make targets supported by Nuclei N100 SDK Build System
  259. :widths: 20 80
  260. :header-rows: 1
  261. :align: center
  262. * - target
  263. - description
  264. * - help
  265. - display help message of Nuclei N100 SDK build system
  266. * - info
  267. - display selected configuration information
  268. * - showflags
  269. - display asm/c/cxx/ld flags and other info
  270. * - showtoolver
  271. - display toolchain/qemu/openocd version
  272. * - all
  273. - build application with selected configuration
  274. * - clean
  275. - clean application with selected configuration
  276. * - dasm
  277. - build and dissemble application with selected configuration
  278. * - bin
  279. - build and generate application binary with selected configuration
  280. * - upload
  281. - build and upload application with selected configuration
  282. * - run_openocd
  283. - run openocd server with selected configuration, and wait for gdb at port specified by $(GDB_PORT)
  284. * - run_gdb
  285. - build and start gdb process with selected configuration, and connect to localhost:$(GDB_PORT)
  286. * - debug
  287. - build and debug application with selected configuration
  288. * - run_qemu
  289. - run application on qemu machine with selected configuration
  290. * - run_xlspike
  291. - run application on xlspike with selected configuration
  292. * - size
  293. - show program size
  294. .. note::
  295. * The selected configuration is controlled by
  296. :ref:`develop_buildsystem_exposed_make_vars`
  297. * For ``run_openocd`` and ``run_gdb`` target, if you want to
  298. change a new gdb port, you can pass the variable
  299. :ref:`develop_buildsystem_var_gdb_port`
  300. * For ``run_qemu``, only ``SOC=evalsoc`` supported,
  301. when do this target, you can pass ``SIMU=qemu`` to support auto-exit,
  302. project recompiling is required.
  303. * For ``run_xlspike``, only ``SOC=evalsoc`` supported,
  304. when do this target, you can pass ``SIMU=xlspike`` to support auto-exit,
  305. project recompiling is required.
  306. .. _develop_buildsystem_exposed_make_vars:
  307. Makefile variables passed by make command
  308. -----------------------------------------
  309. In Nuclei N100 SDK build system, we exposed the following Makefile variables
  310. which can be passed via make command.
  311. * :ref:`develop_buildsystem_var_soc`
  312. * :ref:`develop_buildsystem_var_board`
  313. * :ref:`develop_buildsystem_var_variant`
  314. * :ref:`develop_buildsystem_var_toolchain`
  315. * :ref:`develop_buildsystem_var_download`
  316. * :ref:`develop_buildsystem_var_core`
  317. * :ref:`develop_buildsystem_var_archext`
  318. * :ref:`develop_buildsystem_var_cpu_series`
  319. * :ref:`develop_buildsystem_var_simulation`
  320. * :ref:`develop_buildsystem_var_semihost`
  321. * :ref:`develop_buildsystem_var_gdb_port`
  322. * :ref:`develop_buildsystem_var_v`
  323. * :ref:`develop_buildsystem_var_silent`
  324. .. note::
  325. * These variables can also be used and defined in application Makefile
  326. * If you just want to fix your running board of your application, you can
  327. just define these variables in application Makefile, if defined, then
  328. you can simply use ``make clean``, ``make upload`` or ``make debug``, etc.
  329. .. _develop_buildsystem_var_soc:
  330. SOC
  331. ~~~
  332. **SOC** variable is used to declare which SoC is used in application during compiling.
  333. **evalsoc** is the default SoC, if no **SOC** passed or environment variable set, you can check
  334. default settings by run ``make info``, it will will show default settings without any overriding
  335. make variable.
  336. You can easily find the supported SoCs in the **<NUCLEI_SDK_ROOT>/SoC** directory.
  337. Currently we support the following SoCs, see :ref:`table_dev_buildsystem_1`.
  338. .. _table_dev_buildsystem_1:
  339. .. list-table:: Supported SoCs
  340. :widths: 10, 60
  341. :header-rows: 1
  342. :align: center
  343. * - **SOC**
  344. - Reference
  345. * - evalsoc
  346. - :ref:`design_soc_evalsoc`
  347. .. note::
  348. If you are our SoC subsystem customer, in the SDK delivered to you, you can find your soc name
  349. in this **<NUCLEI_SDK_ROOT>/SoC** directory, take ``ns`` SoC as example, when ``SOC=ns``,
  350. the SoC source code in **<NUCLEI_SDK_ROOT>/SoC/ns/Common** will be used.
  351. This documentation just document the open source version of Nuclei N100 SDK's supported SOC and Board.
  352. .. _develop_buildsystem_var_board:
  353. BOARD
  354. ~~~~~
  355. **BOARD** variable is used to declare which Board is used in application during compiling.
  356. The **BOARD** variable should match the supported boards of chosen **SOC**.
  357. You can easily find the supported Boards in the **<NUCLEI_SDK_ROOT>/<SOC>/Board/** directory.
  358. * :ref:`table_dev_buildsystem_3`
  359. Currently we support the following SoCs.
  360. .. _table_dev_buildsystem_3:
  361. .. list-table:: Supported Boards when SOC=evalsoc
  362. :widths: 10 60
  363. :header-rows: 1
  364. :align: center
  365. * - **BOARD**
  366. - Reference
  367. * - nuclei_fpga_eval
  368. - :ref:`design_board_nuclei_fpga_eval`
  369. .. note::
  370. * If you only specify **SOC** variable in make command, it will use default **BOARD**
  371. and **CORE** option defined in **<NUCLEI_SDK_ROOT>/SoC/<SOC>/build.mk**
  372. * If you are our SoC subsystem customer, in the SDK delivered to you, you can check
  373. the board supported list in **<NUCLEI_SDK_ROOT>/<SOC>/Board/**, take ``SOC=ns BOARD=fpga_eval``
  374. as example, the board source code located **<NUCLEI_SDK_ROOT>/ns/Board/fpga_eval** will be used.
  375. .. _develop_buildsystem_var_variant:
  376. VARIANT
  377. ~~~~~~~
  378. **VARIANT** variable is used to declare which variant of board is used in application during compiling.
  379. It might only affect on only small piece of board, and this is SoC and Board dependent.
  380. This variable only affect the selected board or soc, and it is target dependent.
  381. .. _develop_buildsystem_var_toolchain:
  382. TOOLCHAIN
  383. ~~~~~~~~~
  384. This variable is used to select different toolchain to compile application.
  385. Currently we support 3 toolchain in Nuclei N100 SDK.
  386. * **nuclei_gnu**: default, it will choose nuclei gnu toolchain, distributed with Nuclei Toolchain.
  387. * **nuclei_llvm**: supported for N100, still in experiment, nuclei customized extensions not yet supported, distributed with Nuclei Toolchain.
  388. * **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.
  389. For **nuclei_gnu/nuclei_llvm** toolchain both newlib and libncrt library are supported,
  390. but nuclei_llvm toolchain multilib selection mechanism is not as good as gnu toolchain,
  391. 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.
  392. And IAR compiler support is also done in Nuclei N100 SDK(not yet ready for N100), you can take a try with it
  393. via ``ideprojects/iar`` folder provided prebuilt ide projects.
  394. .. _develop_buildsystem_var_download:
  395. DOWNLOAD
  396. ~~~~~~~~
  397. **DOWNLOAD** variable is used to declare the download mode of the application,
  398. currently it has these modes supported as described in table
  399. :ref:`table_dev_buildsystem_5`
  400. .. _table_dev_buildsystem_5:
  401. .. list-table:: Supported download modes
  402. :widths: 10 70
  403. :header-rows: 1
  404. :align: center
  405. * - **DOWNLOAD**
  406. - Description
  407. * - sram
  408. - | Program will be downloaded into sram and
  409. | run directly in sram, program will lost when poweroff
  410. .. note::
  411. * This variable now target dependent, and its meaning depending on how this
  412. variable is implemented in SoC's build.mk
  413. * macro ``DOWNLOAD_MODE`` and ``DOWNLOAD_MODE_STRING`` will be defined in Makefile,
  414. eg. when ``DOWNLOAD=sram``, macro will be defined as ``-DDOWNLOAD_MODE=DOWNLOAD_MODE_SRAM``,
  415. and ``-DDOWNLOAD_MODE_STRING=\"sram\"``, the ``sram`` will be in upper case,
  416. currently ``DOWNLOAD_MODE_STRING`` macro is used in ``system_<Device>.c`` when
  417. banner is print.
  418. .. _develop_buildsystem_var_core:
  419. CORE
  420. ~~~~
  421. **CORE** variable is used to declare the Nuclei processor core
  422. of the application.
  423. Currently it has these cores supported as described in table
  424. :ref:`table_dev_buildsystem_6`.
  425. .. _table_dev_buildsystem_6:
  426. .. table:: Supported Nuclei Processor cores
  427. :widths: 20 20 20 30
  428. :align: center
  429. ========== ============== ======= =================
  430. **CORE** **ARCH** **ABI** **TUNE**
  431. n100e rv32ec ilp32e nuclei-100-series
  432. n100em rv32emc ilp32e nuclei-100-series
  433. n100ezmmul rv32ec_zmmul ilp32e nuclei-100-series
  434. n100 rv32ic ilp32 nuclei-100-series
  435. n100m rv32imc ilp32 nuclei-100-series
  436. n100zmmul rv32ic_zmmul ilp32 nuclei-100-series
  437. ========== ============== ======= =================
  438. When **CORE** is selected, the **ARCH**, **ABI** and **TUNE** (optional) are set,
  439. and it might affect the compiler options in combination with :ref:`develop_buildsystem_var_archext`
  440. depended on the implementation of SoC build.mk.
  441. Take ``SOC=evalsoc`` as example.
  442. - If **CORE=n100zmmul ARCH_EXT=_zca_zcb_zcmp_zcmt**, then ``ARCH=rv32i_zmmul_zca_zcb_zcmp_zcmt, ABI=ilp32 TUNE=nuclei-100-series``.
  443. riscv arch related compile and link options will be passed, for this case, it will be
  444. ``-march=rv32i_zmmul_zca_zcb_zcmp_zcmt -mabi=ilp32 -mtune=nuclei-100-series``.
  445. - If **CORE=n100e ARCH_EXT=_zicond**, it will be ``-march=rv32ec_zicond -mabi=ilp32e -mtune=nuclei-100-series``.
  446. For riscv code model settings, the ``RISCV_CMODEL`` variable will be set to medlow
  447. for RV32 targets, otherwise it will be medany.
  448. .. _develop_buildsystem_var_archext:
  449. ARCH_EXT
  450. ~~~~~~~~
  451. **ARCH_EXT** variable is used to select extra RISC-V arch extensions supported by Nuclei
  452. RISC-V Processor, except the ``iemafdc``.
  453. .. note::
  454. `Nuclei Toolchain 2023.10`_ now bump gcc version from gcc 10 to gcc 13, which introduced
  455. incompatiable ``-march`` option, so ``ARCH_EXT`` usage is also incompatiable now.
  456. 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.
  457. Here are several examples when using **ARCH_EXT** only for **Nuclei 100 series** RISC-V Processors:
  458. * If you want to use just `Zicond extension`_, you can pass **ARCH_EXT=_zicond**
  459. * If you want to use `Zc 1.0 extension`_
  460. - You can use it together with C extension, which means it should be concat with isa string like ``rv32im_zca_zcb_zcmp_zcmt``
  461. - In Nuclei N100 SDK, the isa string processing is done in build system
  462. - If you want to use with 100 series, you can pass **ARCH_EXT=_zca_zcb_zcmp_zcmt**
  463. * If you want to use both **Zicond** and **Zc** extension, you can pass **ARCH_EXT=_zca_zcb_zcmp_zcmt_zicond**
  464. * 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``
  465. It is suggested to use this **ARCH_EXT** with other arch options like this, can be found in ``SoC/evalsoc/build.mk``:
  466. .. code-block:: makefile
  467. # Set RISCV_ARCH and RISCV_ABI
  468. CORE_UPPER := $(call uc, $(CORE))
  469. CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
  470. RISCV_ARCH ?= $(word 1, $(CORE_ARCH_ABI))$(ARCH_EXT)
  471. RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
  472. .. _develop_buildsystem_var_cpu_series:
  473. CPU_SERIES
  474. ~~~~~~~~~~
  475. This variable will be auto set if your CORE variable match the following rules:
  476. * **100**: CORE start with *10*, the CPU_SERIES will be 100.
  477. It can also be defined in Makefile itself directly or passed via make command.
  478. It will also define an macro called **CPU_SERIES**, eg. for CPU_SERIES=200, it will define macro CPU_SERIES=200.
  479. This variable is currently used in benchmark cases, and require application Makefile changes.
  480. .. _develop_buildsystem_var_semihost:
  481. SEMIHOST
  482. ~~~~~~~~
  483. If **SEMIHOST=1**, it means it will enable semihost support using openocd.
  484. From 0.5.0, both newlib and libncrt support semihosting feature, and when using semihost,
  485. no need to implement the clib stub functions, which is done by newlib or libncrt semihosting
  486. library.
  487. And for Nuclei QEMU >= 2023.10 verison, you can also use semihosting feature, simple usage is like below for qemu:
  488. .. code-block:: shell
  489. cd application/baremetal/helloworld
  490. # clean project first
  491. make SOC=evalsoc SEMIHOST=1 clean
  492. make SOC=evalsoc SEMIHOST=1 all
  493. # run on qemu, SEMIHOST=1 is required to pass when run qemu
  494. make SOC=evalsoc SEMIHOST=1 run_qemu
  495. When using semihosting feature with openocd, debug message will print via openocd console.
  496. You need to use it like this(assume you are run on evalsoc, CORE=n100):
  497. In terminal 1, open openocd and monitor the output:
  498. .. code-block:: shell
  499. cd application/baremetal/helloworld
  500. make SOC=evalsoc CORE=n100 run_openocd
  501. # when terminal 2 has download program and start to run, you will be able to see output here
  502. In terminal 2, gdb connect to the openocd exposed gdb port and load program, and run
  503. .. code-block:: shell
  504. # in normal shell terminal
  505. cd application/baremetal/helloworld
  506. make SOC=evalsoc CORE=n100 SEMIHOST=1 clean
  507. make SOC=evalsoc CORE=n100 SEMIHOST=1 run_gdb
  508. # now in gdb command terminal, run the following command
  509. monitor reset halt
  510. load
  511. ## when run continue, you will be able to see output in previous terminal 1 running openocd
  512. continue
  513. .. _develop_buildsystem_var_simulation:
  514. SIMULATION
  515. ~~~~~~~~~~
  516. If **SIMULATION=1**, it means the program is optimized for hardware simulation environment.
  517. Currently if **SIMULATION=1**, it will pass compile option **-DCFG_SIMULATION**,
  518. application can use this **CFG_SIMULATION** to optimize program for hardware
  519. simulation environment.
  520. .. note::
  521. * Currently the benchmark applications in **application/baremetal/benchmark** used this optimization
  522. .. _develop_buildsystem_var_gdb_port:
  523. GDB_PORT
  524. ~~~~~~~~
  525. This variable is not used usually, by default the **GDB_PORT** variable is ``3333``.
  526. If you want to change a debug gdb port for openocd and gdb when run ``run_openocd`` and
  527. ``run_gdb`` target, you can pass a new port such as ``3344`` to this variable.
  528. For example, if you want to debug application using run_openocd and
  529. run_gdb and specify a different port other than ``3333``.
  530. You can do it like this, take ``nuclei_fpga_eval`` board for example, such as port ``3344``:
  531. * Open openocd server: ``make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=n100 GDB_PORT=3344 run_openocd``
  532. * connect gdb with openocd server: ``make SOC=evalsoc BOARD=nuclei_fpga_eval CORE=n100 GDB_PORT=3344 run_gdb``
  533. .. _develop_buildsystem_var_jtagsn:
  534. JTAGSN
  535. ~~~~~~
  536. This variable is used specify jtag adapter serial number in openocd configuration, need to be supported in
  537. openocd configuration file and makefile, currently **evalsoc** is supported.
  538. It is used by openocd ``adapter serial``.
  539. Assume you have a jtag adapter, serial number is ``FT6S9RD6``, and you want to download program through
  540. this jtag to a fpga with ux900 bitstream on it, you can do it like this.
  541. For windows, you need to pass extra ``A``, eg. ``JTAGSN=FT6S9RD6A``
  542. .. code-block:: shell
  543. # cd to helloworld
  544. cd application/baremetal/helloworld
  545. # clean program
  546. make SOC=evalsoc JTAGSN=FT6S9RD6 clean
  547. # upload program
  548. make SOC=evalsoc JTAGSN=FT6S9RD6 upload
  549. .. _develop_buildsystem_var_banner:
  550. BANNER
  551. ~~~~~~
  552. If **BANNER=0**, when program is rebuilt, then the banner message print in console will not be print,
  553. banner print is default enabled via ``NUCLEI_BANNER=1`` in ``nuclei_sdk_hal.h``.
  554. when ``BANNER=0``, an macro ``-DNUCLEI_BANNER=0`` will be passed in Makefile.
  555. The banner message looks like this:
  556. .. code-block:: c
  557. Nuclei N100 SDK Build Time: Jul 23 2021, 10:22:50
  558. Download Mode: SRAM
  559. CPU Frequency 15999959 Hz
  560. .. _develop_buildsystem_var_v:
  561. V
  562. ~
  563. If **V=1**, it will display compiling message in verbose including compiling options.
  564. By default, no compiling options will be displayed in make console message just to print
  565. less message and make the console message cleaner. If you want to see what compiling option
  566. is used, please pass **V=1** in your make command.
  567. .. _develop_buildsystem_var_silent:
  568. SILENT
  569. ~~~~~~
  570. If **SILENT=1**, it will not display any compiling messsage.
  571. If you don't want to see any compiling message, you can pass **SILENT=1** in your make command.
  572. .. _develop_buildsystem_app_make_vars:
  573. Makefile variables used only in Application Makefile
  574. ----------------------------------------------------
  575. The following variables should be used in application Makefile at your demand,
  576. e.g. ``application/baremetal/demo_timer/Makefile``.
  577. * :ref:`develop_buildsystem_var_target`
  578. * :ref:`develop_buildsystem_var_nuclei_sdk_root`
  579. * :ref:`develop_buildsystem_var_middleware`
  580. * :ref:`develop_buildsystem_var_rtos`
  581. * :ref:`develop_buildsystem_var_stdclib`
  582. * :ref:`develop_buildsystem_var_riscv_arch`
  583. * :ref:`develop_buildsystem_var_riscv_abi`
  584. * :ref:`develop_buildsystem_var_riscv_cmodel`
  585. * :ref:`develop_buildsystem_var_riscv_tune`
  586. * :ref:`develop_buildsystem_var_nogc`
  587. * :ref:`develop_buildsystem_var_rtthread_msh`
  588. .. _develop_buildsystem_var_target:
  589. TARGET
  590. ~~~~~~
  591. This is a necessary variable which must be defined in application Makefile.
  592. It is used to set the name of the application, it will affect the generated
  593. target filenames.
  594. .. warning::
  595. * Please don't put any spaces in TARGET variable
  596. * The variable shouldn't contain any space
  597. .. code-block:: Makefile
  598. # invalid case 1
  599. TARGET ?= hello world
  600. # invalid case 2
  601. TARGET ?= helloworld # before this # there is a extra space
  602. .. _develop_buildsystem_var_nuclei_sdk_root:
  603. NUCLEI_SDK_ROOT
  604. ~~~~~~~~~~~~~~~
  605. This is a necessary variable which must be defined in application Makefile.
  606. It is used to set the path of Nuclei N100 SDK Root, usually it should be set as
  607. relative path, but you can also set absolute path to point to Nuclei N100 SDK.
  608. .. _develop_buildsystem_var_rtos:
  609. RTOS
  610. ~~~~
  611. **RTOS** variable is used to choose which RTOS will be used in this application.
  612. You can easily find the supported RTOSes in the **<NUCLEI_SDK_ROOT>/OS** directory.
  613. * If **RTOS** is not defined, then baremetal service will be enabled with this application.
  614. See examples in ``application/baremetal``.
  615. * If **RTOS** is set the the following values, RTOS service will be enabled with this application.
  616. - ``FreeRTOS``: FreeRTOS service will be enabled, extra macro ``RTOS_FREERTOS`` will be defined,
  617. you can include FreeRTOS header files now, and use FreeRTOS API, for ``FreeRTOS`` application,
  618. you need to have an ``FreeRTOSConfig.h`` header file prepared in you application.
  619. See examples in ``application/freertos``.
  620. - ``UCOSII``: UCOSII service will be enabled, extra macro ``RTOS_UCOSII`` will be defined,
  621. you can include UCOSII header files now, and use UCOSII API, for ``UCOSII`` application,
  622. you need to have ``app_cfg.h``, ``os_cfg.h`` and ``app_hooks.c`` files prepared in you application.
  623. See examples in ``application/ucosii``.
  624. - ``RTThread``: RT-Thread service will be enabled, extra macro ``RTOS_RTTHREAD`` will be defined,
  625. you can include RT-Thread header files now, and use RT-Thread API, for ``UCOSII`` application,
  626. you need to have an ``rtconfig.h`` header file prepared in you application.
  627. See examples in ``application/rtthread``.
  628. .. _develop_buildsystem_var_middleware:
  629. MIDDLEWARE
  630. ~~~~~~~~~~
  631. **MIDDLEWARE** variable is used to select which middlewares should be used in this application.
  632. You can easily find the available middleware components in the **<NUCLEI_SDK_ROOT>/Components** directory.
  633. * If **MIDDLEWARE** is not defined, not leave empty, no middlware package will be selected.
  634. * If **MIDDLEWARE** is defined with more than 1 string, such as ``fatfs tjpgd``, then these two
  635. middlewares will be selected.
  636. .. _develop_buildsystem_var_stdclib:
  637. STDCLIB
  638. ~~~~~~~
  639. **STDCLIB** variable is used to select which standard c runtime library will be used.
  640. If not defined, the default value will be ``newlib_nano``.
  641. In Nuclei GNU Toolchain, we destributed newlib/newlib-nano/Nuclei c runtime library,
  642. so user can select different c runtime library according to their requirement.
  643. Newlib is a simple ANSI C library, math library, available for both RV32 and RV64.
  644. Nuclei C runtime library is a highly optimized c library designed for deeply embedded user cases,
  645. can provided smaller code size and highly optimized floating point support compared to Newlib.
  646. To support both gcc and clang compiler, we decided not to use ``--specs=`` option to
  647. select system library, instead of that, we start to use ``--nodefaultlibs`` options, and link the required
  648. system libraries by the ``STDCLIB`` variable choice, so need to link desired libraries such as:
  649. * ``-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.
  650. * ``-lgcov``: a library used to test coverage program, known as ``gcov/gprof``, see https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
  651. * ``-lc/-lc_nano``: newlib c library or newlib nano c library, see https://sourceware.org/newlib/docs.html
  652. * ``-lm``: newlib math library, see https://sourceware.org/newlib/libm.html
  653. * ``-lstdc++``: gnu standard c++ library, see https://gcc.gnu.org/onlinedocs/libstdc++
  654. * ``-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
  655. * ``-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
  656. * ``-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++``
  657. * Upgrading libncrt from Nuclei GNU Toolchain 2022.12 to Nuclei Toolchain 2023.10, please change it like this, take **libncrt_small** as example:
  658. - **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
  659. - **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
  660. - 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.
  661. .. list-table:: Available STDCLIB choices
  662. :widths: 10 70
  663. :header-rows: 1
  664. :align: center
  665. * - **STDCLIB**
  666. - Description
  667. * - newlib_full
  668. - | Normal version of newlib, optimized for speed at cost of size.
  669. | It provided full feature of newlib, with file io supported.
  670. * - newlib_fast
  671. - Newlib nano version, with printf float and scanf float support.
  672. * - newlib_small
  673. - Newlib nano version, with printf float support.
  674. * - newlib_nano
  675. - Newlib nano version, without printf/scanf float support.
  676. * - libncrt_fast
  677. - Nuclei C runtime library optimized for speed, full feature
  678. * - libncrt_balanced
  679. - Nuclei C runtime library balanced at speed and code size, full feature
  680. * - libncrt_small
  681. - Nuclei C runtime library optimized for code size, full feature
  682. * - libncrt_nano
  683. - Nuclei C runtime library optimized for code size, without float/double support
  684. * - libncrt_pico
  685. - Nuclei C runtime library optimized for code size, without long/long long/float/double support
  686. * - nostd
  687. - no std c library will be used, and don't search the standard system directories for header files
  688. * - nospec
  689. - no std c library will be used, not pass any --specs options
  690. .. note::
  691. * For clang based compiler, if ``-u _print_float`` is not passed in linker options, it may fail
  692. during link process, so here we pass ``-u _print_float`` for newlib_nano, then it means for
  693. nuclei_llvm and terapines toolchain, ``STDCLIB=newlib_nano`` equals to ``STDCLIB=newlib_small``
  694. * Nuclei libncrt library couldn't be used with terapines toolchain, so you can't use any libncrt library
  695. when you are using terapines toolchain.
  696. * About Newlib and Newlib nano difference, please check
  697. https://github.com/riscv-collab/riscv-newlib/blob/riscv-newlib-3.2.0/newlib/README
  698. * About Nuclei C runtime library, it provided basic libgcc, c library and math library feature, but
  699. it didn't provided all the features that newlib can do, it is highly optimized for deeply embedded scenery,
  700. user no need to link with ``-lm`` when using libncrt library when math library is needed.
  701. * Nuclei C runtime library is only available in Nuclei GNU Toolchain released after Nov 2021,
  702. about how to use this library, please follow doc located in ``gcc\share\pdf``, changes need
  703. to be done in startup code, linker script, stub code, and compiler options, you can check commit
  704. history of nuclei sdk for support of libncrt.
  705. * Nuclei C runtime library(libncrt) only support RV32 CPU target, so you cannot use it with RV64 CPU.
  706. * Since there are different c runtime library can be chosen now, so developer
  707. need to provide different stub functions for different library, please check
  708. ``SoC/evalsoc/Common/Source/Stubs/`` and ``SoC/evalsoc/build.mk`` for example.
  709. .. _develop_buildsystem_var_ncrtheap:
  710. NCRTHEAP
  711. ~~~~~~~~
  712. This variable is only valid when using libncrt c library >= v3.0.0, and you can choose different
  713. heapops when using libncrt c library to do heap related operations such as malloc or free.
  714. * **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
  715. * **realtime**: A real-time heap where allocation and deallocation have O(1) performance
  716. * **minimal**: An allocate-only heap where deallocation and reallocation are not implemented
  717. For previous libncrt library, this heapops is default binded with libncrt library, so you can't
  718. choose different heap type, but now you can choose according to your requirements.
  719. .. _develop_buildsystem_var_ncrtio:
  720. NCRTIO
  721. ~~~~~~
  722. This variable is only valid when using libncrt c library >= v3.0.0, and you can choose different
  723. fileops when using libncrt c library to do basic input/output operations.
  724. * **uart**: default, lower level input/output via uart, developer need to implement metal_tty_putc/getc
  725. * **semi**: input/output via semihosting, if you pass **SEMIHOST=1** in make, it will default choose this one when using libncrt library.
  726. * **rtt**: input/output via jlink rtt, require to use JLink tool.
  727. .. _develop_buildsystem_var_smp:
  728. SMP
  729. ~~~
  730. **SMP** variable is used to control smp cpu core count, valid number must > 1.
  731. When **SMP** variable is defined, extra gcc options for ld is passed
  732. ``-Wl,--defsym=__SMP_CPU_CNT=$(SMP)``, and extra c macro ``-DSMP_CPU_CNT=$(SMP)``
  733. is defined this is passed in each SoC's build.mk, such as ``SoC/evalsoc/build.mk``.
  734. When SMP variable is defined, extra openocd command ``set SMP $(SMP)`` will also
  735. be passed when run openocd upload or create a openocd server.
  736. For SMP application, please check ``application/baremetal/smphello``, if you want to implement
  737. a smp application, you need to reimplement ``smp_main``, which all harts will run to this function
  738. instead of ``main``, if you don't implement it, a weak ``smp_main`` in ``startup_<Device>.S`` will
  739. be used, and only boot hartid specified by **BOOT_HARTID** will enter to main, other harts will do wfi.
  740. .. _develop_buildsystem_var_boot_hartid:
  741. BOOT_HARTID
  742. ~~~~~~~~~~~
  743. This variable is used to control the boot hartid in a multiple core system.
  744. If **SMP** variable is specified, it means this application is expected to be a smp application,
  745. otherwise it means this application is expected to be a amp application.
  746. For amp application, only the boot hart specified by **BOOT_HARTID** will run, other harts
  747. will directly do wfi when startup, but for smp application, other hartid will do normal boot
  748. code instead of code/data/bss init, and do sync harts to make sure all harts boots.
  749. For both amp and smp application, the program should execute on a share memory which all
  750. harts can access, not hart private memory such as ilm/dlm.
  751. Currently **SMP** and **BOOT_HARTID** support all require SOC support code to implement it, currently
  752. evalsoc support it, currently qemu simulation didn't work for SMP/AMP use case.
  753. Here is some basic usage for SMP and BOOT_HARTID on UX900 x4, run on external ddr.
  754. .. code-block:: shell
  755. # cd to helloworld
  756. cd <Nuclei N100 SDK>/application/baremetal/helloworld
  757. # clean program
  758. make SOC=evalsoc clean
  759. # AMP: choose hart 1 as boot hartid, other harts spin
  760. make SOC=evalsoc BOOT_HARTID=1 DOWNLOAD=ddr clean upload
  761. cd <Nuclei N100 SDK>/application/baremetal/smphello
  762. # SMP: choose hart 2 as boot hartid
  763. make SOC=evalsoc BOOT_HARTID=2 SMP=4 DOWNLOAD=ddr clean upload
  764. .. _develop_buildsystem_var_hartid_ofs:
  765. HARTID_OFS
  766. ~~~~~~~~~~
  767. This variable is used to set hartid offset relative to real hart index in a complex AMP SoC system.
  768. eg.
  769. 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,
  770. and CPU 1 hartid is 2, so for CPU 0, HARTID_OFS is 0, for CPU 1, HARTID_OFS is 2.
  771. .. _develop_buildsystem_var_stacksz:
  772. STACKSZ
  773. ~~~~~~~
  774. **STACKSZ** variable is used to control the per core stack size reserved in linker script,
  775. this need to cooperate with link script file and linker options.
  776. In link script file, ``__STACK_SIZE`` symbol need to use ``PROVIDE`` feature of ld
  777. to define a weak version, such as ``PROVIDE(__STACK_SIZE = 2K);``, and gcc will pass
  778. ld options ``-Wl,--defsym=__STACK_SIZE=$(STACKSZ)`` to overwrite the default value if
  779. **STACKSZ** is defined.
  780. **STACKSZ** variable must be a valid value accepted by ld, such as 0x2000, 2K, 4K, 8192.
  781. For SMP version, stack size space need to reserve **STACKSZ** x SMP Core Count size.
  782. You can refer to ``SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/gcc_evalsoc_sram.ld`` for smp version.
  783. .. _develop_buildsystem_var_heapsz:
  784. HEAPSZ
  785. ~~~~~~
  786. **HEAPSZ** variable is used to control the heap size reserved in linker script,
  787. this need to cooperate with link script file and linker options.
  788. In link script file, ``__HEAP_SIZE`` symbol need to use ``PROVIDE`` feature of ld
  789. to define a weak version, such as ``PROVIDE(__HEAP_SIZE = 2K);``, and gcc will pass
  790. ld options ``-Wl,--defsym=__HEAP_SIZE=$(HEAPSZ)`` to overwrite the default value if
  791. **HEAPSZ** is defined.
  792. **HEAPSZ** variable must be a valid value accepted by ld, such as 0x2000, 2K, 4K, 8192.
  793. .. _develop_buildsystem_var_riscv_arch:
  794. RISCV_ARCH
  795. ~~~~~~~~~~
  796. **RISCV_ARCH** variable is used to control compiler option ``-mcmodel=$(RISCV_ARCH)``.
  797. It might override RISCV_ARCH defined in SoC build.mk, according to your build.mk implementation.
  798. **RISCV_ARCH** might directly affect the gcc compiler option depended on the implementation of SoC build.mk.
  799. Take ``SOC=evalsoc`` for example.
  800. * **CORE=n100 RISCV_ARCH=rv32imc_zicond RISCV_ABI=ilp32 ARCH_EXT=_zba_zbb_zbc_zbs**, then final compiler options will be
  801. ``-march=rv32imc_zicond -mabi=ilp32 -mtune=nuclei-100-series``. The **ARCH_EXT** is ignored.
  802. .. _develop_buildsystem_var_riscv_abi:
  803. RISCV_ABI
  804. ~~~~~~~~~
  805. **RISCV_ABI** variable is used to control compiler option ``-mcmodel=$(RISCV_ABI)``.
  806. It might override RISCV_ABI defined in SoC build.mk, according to your build.mk implementation.
  807. .. _develop_buildsystem_var_riscv_cmodel:
  808. RISCV_CMODEL
  809. ~~~~~~~~~~~~
  810. **RISCV_CMODEL** is used to control compiler option ``-mcmodel=$(RISCV_CMODEL)``.
  811. For RV32, default value is ``medlow``, otherwise ``medany`` for RV64.
  812. You can set ``RISCV_CMODEL`` to override predefined value.
  813. .. _develop_buildsystem_var_riscv_tune:
  814. RISCV_TUNE
  815. ~~~~~~~~~~
  816. **RISCV_TUNE** is used to control compiler option ``-mtune=$(RISCV_TUNE)``.
  817. It is defined in SoC build.mk, you can override it if your implementation
  818. allow it.
  819. .. _develop_buildsystem_var_app_common_flags:
  820. APP_COMMON_FLAGS
  821. ~~~~~~~~~~~~~~~~
  822. .. note::
  823. * Added in 0.4.0 release.
  824. This variable is used to define app common compiler flags to all c/asm/cpp compiler.
  825. You can pass it via make command to define extra flags to compile application.
  826. .. _develop_buildsystem_var_app_asmflags:
  827. APP_ASMFLAGS
  828. ~~~~~~~~~~~~
  829. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app asm flags.
  830. .. _develop_buildsystem_var_app_cflags:
  831. APP_CFLAGS
  832. ~~~~~~~~~~
  833. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app c flags.
  834. .. _develop_buildsystem_var_app_cxxflags:
  835. APP_CXXFLAGS
  836. ~~~~~~~~~~~~
  837. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app cxx flags.
  838. .. _develop_buildsystem_var_app_ldflags:
  839. APP_LDFLAGS
  840. ~~~~~~~~~~~
  841. This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app linker flags.
  842. .. _develop_buildsystem_var_nogc:
  843. NOGC
  844. ~~~~
  845. **NOGC** variable is used to control whether to enable gc sections to reduce program
  846. code size or not, by default GC is enabled to reduce code size.
  847. When GC is enabled, these options will be added:
  848. * Adding to compiler options: ``-ffunction-sections -fdata-sections``
  849. * Adding to linker options: ``-Wl,--gc-sections -Wl,--check-sections``
  850. If you want to enable this GC feature, you can set **NOGC=0** (default), GC feature will
  851. remove sections for you, but sometimes it might remove sections that are useful,
  852. e.g. For Nuclei N100 SDK test cases, we use ctest framework, and we need to set **NOGC=1**
  853. to disable GC feature.
  854. When ``NOGC=0``(default), extra compile options ``-ffunction-sections -fdata-sections``,
  855. and extra link options ``-Wl,--gc-sections -Wl,--check-sections`` will be passed.
  856. .. _develop_buildsystem_var_rtthread_msh:
  857. RTTHREAD_MSH
  858. ~~~~~~~~~~~~
  859. **RTTHREAD_MSH** variable is valid only when **RTOS** is set to **RTThread**.
  860. When **RTTHREAD_MSH** is set to **1**:
  861. * The RTThread MSH component source code will be included
  862. * The MSH thread will be enabled in the background
  863. * Currently the msh getchar implementation is using a weak function implemented
  864. in ``rt_hw_console_getchar`` in ``OS/RTTThread/libcpu/risc-v/nuclei/cpuport.c``
  865. .. _develop_buildsystem_app_build_vars:
  866. Build Related Makefile variables used only in Application Makefile
  867. ------------------------------------------------------------------
  868. If you want to specify additional compiler flags, please follow this guidance
  869. to modify your application Makefile.
  870. Nuclei N100 SDK build system defined the following variables to control the
  871. build options or flags.
  872. * :ref:`develop_buildsystem_var_incdirs`
  873. * :ref:`develop_buildsystem_var_c_incdirs`
  874. * :ref:`develop_buildsystem_var_cxx_incdirs`
  875. * :ref:`develop_buildsystem_var_asm_incdirs`
  876. * :ref:`develop_buildsystem_var_srcdirs`
  877. * :ref:`develop_buildsystem_var_c_srcdirs`
  878. * :ref:`develop_buildsystem_var_cxx_srcdirs`
  879. * :ref:`develop_buildsystem_var_asm_srcdirs`
  880. * :ref:`develop_buildsystem_var_c_srcs`
  881. * :ref:`develop_buildsystem_var_cxx_srcs`
  882. * :ref:`develop_buildsystem_var_asm_srcs`
  883. * :ref:`develop_buildsystem_var_exclude_srcs`
  884. * :ref:`develop_buildsystem_var_common_flags`
  885. * :ref:`develop_buildsystem_var_cflags`
  886. * :ref:`develop_buildsystem_var_cxxflags`
  887. * :ref:`develop_buildsystem_var_asmflags`
  888. * :ref:`develop_buildsystem_var_ldflags`
  889. * :ref:`develop_buildsystem_var_ldlibs`
  890. * :ref:`develop_buildsystem_var_libdirs`
  891. * :ref:`develop_buildsystem_var_linker_script`
  892. .. _develop_buildsystem_var_incdirs:
  893. INCDIRS
  894. ~~~~~~~
  895. This **INCDIRS** is used to pass C/CPP/ASM include directories.
  896. e.g. To include current directory ``.`` and ``inc`` for C/CPP/ASM
  897. .. code-block:: makefile
  898. INCDIRS = . inc
  899. .. _develop_buildsystem_var_c_incdirs:
  900. C_INCDIRS
  901. ~~~~~~~~~
  902. This **C_INCDIRS** is used to pass C only include directories.
  903. e.g. To include current directory ``.`` and ``cinc`` for C only
  904. .. code-block:: makefile
  905. C_INCDIRS = . cinc
  906. .. _develop_buildsystem_var_cxx_incdirs:
  907. CXX_INCDIRS
  908. ~~~~~~~~~~~
  909. This **CXX_INCDIRS** is used to pass CPP only include directories.
  910. e.g. To include current directory ``.`` and ``cppinc`` for CPP only
  911. .. code-block:: makefile
  912. CXX_INCDIRS = . cppinc
  913. .. _develop_buildsystem_var_asm_incdirs:
  914. ASM_INCDIRS
  915. ~~~~~~~~~~~
  916. This **ASM_INCDIRS** is used to pass ASM only include directories.
  917. e.g. To include current directory ``.`` and ``asminc`` for ASM only
  918. .. code-block:: makefile
  919. ASM_INCDIRS = . asminc
  920. .. _develop_buildsystem_var_srcdirs:
  921. SRCDIRS
  922. ~~~~~~~
  923. This **SRCDIRS** is used to set the source directories used to search
  924. the C/CPP/ASM source code files, it will not do recursively.
  925. e.g. To search C/CPP/ASM source files in directory ``.`` and ``src``
  926. .. code-block:: makefile
  927. SRCDIRS = . src
  928. .. _develop_buildsystem_var_c_srcdirs:
  929. C_SRCDIRS
  930. ~~~~~~~~~
  931. This **C_SRCDIRS** is used to set the source directories used to search
  932. the C only source code files(*.c, *.C), it will not do recursively.
  933. e.g. To search C only source files in directory ``.`` and ``csrc``
  934. .. code-block:: makefile
  935. C_SRCDIRS = . csrc
  936. .. _develop_buildsystem_var_cxx_srcdirs:
  937. CXX_SRCDIRS
  938. ~~~~~~~~~~~
  939. This **CXX_SRCDIRS** is used to set the source directories used to search
  940. the CPP only source code files(*.cpp, *.CPP), it will not do recursively.
  941. e.g. To search CPP only source files in directory ``.`` and ``cppsrc``
  942. .. code-block:: makefile
  943. CXX_SRCDIRS = . cppsrc
  944. .. _develop_buildsystem_var_asm_srcdirs:
  945. ASM_SRCDIRS
  946. ~~~~~~~~~~~
  947. This **ASM_SRCDIRS** is used to set the source directories used to search
  948. the ASM only source code files(*.s, *.S), it will not do recursively.
  949. e.g. To search ASM only source files in directory ``.`` and ``asmsrc``
  950. .. code-block:: makefile
  951. ASM_SRCDIRS = . asmsrc
  952. .. _develop_buildsystem_var_c_srcs:
  953. C_SRCS
  954. ~~~~~~
  955. If you just want to include a few of C source files in directories, you can use this
  956. **C_SRCS** variable, makefile wildcard pattern supported.
  957. e.g. To include ``main.c`` and ``src/hello.c``
  958. .. code-block:: makefile
  959. C_SRCS = main.c src/hello.c
  960. .. _develop_buildsystem_var_cxx_srcs:
  961. CXX_SRCS
  962. ~~~~~~~~
  963. If you just want to include a few of CPP source files in directories, you can use this
  964. **CXX_SRCS** variable, makefile wildcard pattern supported.
  965. e.g. To include ``main.cpp`` and ``src/hello.cpp``
  966. .. code-block:: makefile
  967. CXX_SRCS = main.cpp src/hello.cpp
  968. .. _develop_buildsystem_var_asm_srcs:
  969. ASM_SRCS
  970. ~~~~~~~~
  971. If you just want to include a few of ASM source files in directories, you can use this
  972. **ASM_SRCS** variable, makefile wildcard pattern supported.
  973. e.g. To include ``asm.s`` and ``src/test.s``
  974. .. code-block:: makefile
  975. ASM_SRCS = asm.s src/test.s
  976. .. _develop_buildsystem_var_exclude_srcs:
  977. EXCLUDE_SRCS
  978. ~~~~~~~~~~~~
  979. If you just want to exclude a few of c/asm/cpp source files in directories,
  980. you can use this **EXCLUDE_SRCS** variable, makefile wildcard pattern supported.
  981. e.g. To exclude ``test2.c`` and ``src/test3.c``
  982. .. code-block:: makefile
  983. EXCLUDE_SRCS = test2.c src/test3.c
  984. .. _develop_buildsystem_var_common_flags:
  985. COMMON_FLAGS
  986. ~~~~~~~~~~~~
  987. This **COMMON_FLAGS** variable is used to define common compiler flags to all c/asm/cpp compiler.
  988. For example, you can add a newline ``COMMON_FLAGS += -O3 -funroll-loops -fpeel-loops``
  989. in your application Makefile and these options will be passed to C/ASM/CPP compiler.
  990. This variable should be defined in Makefile.
  991. .. _develop_buildsystem_var_cflags:
  992. CFLAGS
  993. ~~~~~~
  994. Different to **COMMON_FLAGS**, this **CFLAGS** variable is used to define common compiler flags to C compiler only.
  995. For example, you can add a newline ``CFLAGS += -O3 -funroll-loops -fpeel-loops``
  996. in your application Makefile and these options will be passed to C compiler.
  997. .. _develop_buildsystem_var_cxxflags:
  998. CXXFLAGS
  999. ~~~~~~~~
  1000. Different to **COMMON_FLAGS**, this **CXXFLAGS** variable is used to define common compiler flags to cpp compiler only.
  1001. For example, you can add a newline ``CXXFLAGS += -O3 -funroll-loops -fpeel-loops``
  1002. in your application Makefile and these options will be passed to cpp compiler.
  1003. .. _develop_buildsystem_var_asmflags:
  1004. ASMFLAGS
  1005. ~~~~~~~~
  1006. Different to **COMMON_FLAGS**, this **ASMFLAGS** variable is used to define common compiler flags to asm compiler only.
  1007. For example, you can add a newline ``ASMFLAGS += -O3 -funroll-loops -fpeel-loops``
  1008. in your application Makefile and these options will be passed to asm compiler.
  1009. .. _develop_buildsystem_var_ldflags:
  1010. LDFLAGS
  1011. ~~~~~~~
  1012. This **LDFLAGS** is used to pass extra linker flags, for example,
  1013. if you want to use standard system libraries when linking, you can add a newline
  1014. ``LDFLAGS += -nodefaultlibs`` in you application Makefile.
  1015. If you want to link with other libraries, please use ``LDLIBS`` and ``LIBDIRS`` variables.
  1016. .. _develop_buildsystem_var_ldlibs:
  1017. LDLIBS
  1018. ~~~~~~
  1019. This **LDLIBS** variable is library flags or names given to compilers
  1020. when they are supposed to invoke the linker.
  1021. Non-library linker flags, such as -L, should go in the **LIBDIRS** or **LDFLAGS** variable.
  1022. .. _develop_buildsystem_var_libdirs:
  1023. LIBDIRS
  1024. ~~~~~~~
  1025. This **LIBDIRS** variable is used to store the library directories, which could
  1026. be used together with **LDLIBS**.
  1027. For example, if you have a library located in **$(NUCLEI_SDK_ROOT)/Library/DSP/libnmsis_dsp_rv32imac.a**,
  1028. and you want to link it, then you can define these lines:
  1029. .. code-block:: makefile
  1030. LDLIBS = -lnmsis_dsp_rv32imac
  1031. LIBDIRS = $(NUCLEI_SDK_ROOT)/Library/DSP
  1032. .. _develop_buildsystem_var_linker_script:
  1033. LINKER_SCRIPT
  1034. ~~~~~~~~~~~~~
  1035. This **LINKER_SCRIPT** variable could be used to set the link script of the application.
  1036. By default, there is no need to set this variable, since the build system will define
  1037. a default linker script for application according to the build configuration. If you want
  1038. to define your own linker script, you can set this variable.
  1039. For example, ``LINKER_SCRIPT := gcc.ld``.
  1040. .. _GNU Make Standard Library (GMSL): http://sourceforge.net/projects/gmsl/
  1041. .. _Zicond extension: https://github.com/riscvarchive/riscv-zicond
  1042. .. _Zc 1.0 extension: https://github.com/riscv/riscv-code-size-reduction/releases/tag/v1.0.4-3
  1043. .. _Nuclei Toolchain 2023.10: https://github.com/riscv-mcu/riscv-gnu-toolchain/releases/tag/nuclei-2023.10