Build System based on Makefile
HummingBird SDK’s build system is based on Makefile, user can build, run ordebug application in Windows and Linux.
Makefile Structure
HummingBird SDK’s Makefiles mainly placed in <HBIRD_SDK_ROOT>/Build directory and an extra Makefile located in <HBIRD_SDK_ROOT>/Makefile.
This extra <HBIRD_SDK_ROOT>/Makefile introduce a new Make variable called PROGRAM to provide the ability to build or run application in <HBIRD_SDK_ROOT>.
For example, if you want to rebuild and upload application application/baremetal/timer_test,
you can run make PROGRAM=application/baremetal/timer_test clean upload
to achieve it.
The <HBIRD_SDK_ROOT>/Build directory content list as below:
gmsl/
Makefile.base
Makefile.conf
Makefile.core
Makefile.components
Makefile.files
Makefile.global -> Created by user
Makefile.misc
Makefile.rtos
Makefile.rules
Makefile.soc
The file or directory is used explained as below:
Makefile.base
This Makefile.base file is used as HummingBird SDK build system entry file, application’s Makefile need to include this file to use all the features of HummingBird SDK build system.
It will expose Make variables or options such as BOARD or SOC passed
by make
command, click Makefile variables passed by make command
to learn more.
This file will include optional Makefile.global and Makefile.local which allow user to set custom global Makefile configurations and local application Makefile configurations.
This file will include the following makefiles:
gmsl: additional library functions provided via gmsl
Makefile.misc: misc functions and OS check helpers
Makefile.conf: main Makefile configuration entry
Makefile.rules: make rules of this build system
gmsl
The gmsl directory consist of the GNU Make Standard Library (GMSL), which is an a library of functions to be used with GNU Make’s $(call) that provides functionality not available in standard GNU Make.
We use this gmsl tool to make sure we help us achieve some linux command which is only supported in Linux.
Makefile.misc
This Makefile.misc file mainly provide these functions:
Define get_csrcs, get_asmsrcs, get_cxxsrcs and check_item_exist make functions
get_csrcs: Function to get
*.c or *.C
source files from a list of directories, no ability to do recursive match. e.g.$(call get_csrcs, csrc csrc/abc)
will return c source files incsrc
andcsrc/abc
directories.get_asmsrcs: Function to get
*.s or *.S
source files from a list of directories, no ability to do recursive match. e.g.$(call get_asmsrcs, asmsrc asmsrc/abc)
will return asm source files inasmsrc
andasmsrc/abc
directories.get_cxxsrcs: Function to get
*.cpp or *.CPP
source files from a list of directories, no ability to do recursive match. e.g.$(call get_cxxsrcs, cppsrc cppsrc/abc)
will return cpp source files incppsrc
andcppsrc/abc
directories.check_item_exist: Function to check if item existed in a set of items. e.g.
$(call check_item_exist, flash, flash ilm flashxip)
will checkflash
whether existed inflash ilm flashxip
, if existed, returnflash
, otherwise return empty.
Check and define OS related functions, and also a set of trace print functions.
Makefile.conf
This Makefile.conf file will define the following items:
Toolchain related variables used during compiling
Debug related variables
Include Makefile.files and Makefile.rtos
Collect all the C/C++/ASM compiling and link options
Makefile.components
This Makefile.components will include build.mk
Makefiles of selected components defined
via makefile variable MIDDLEWARE, the Makefiles are placed in
the sub-folders of <HBIRD_SDK_ROOT>/Components/.
A valid middleware component should be organized like this, take fatfs
as example :
Components/fatfs/
├── build.mk
├── documents
├── LICENSE.txt
└── source
For example, if there are two valid middleware components in <HBIRD_SDK_ROOT>/Components/, called
fatfs
and tjpgd
, and you want to use them in your application, then you can set MIDDLEWARE
like this MIDDLEWARE := fatfs tjpgd
, then the application will include these two middlewares into
build process.
Makefile.rules
This Makefile.rules file will do the following things:
Collect all the sources during compiling
Define all the rules used for building, uploading and debugging
Print help message for build system
Makefile.files
This Makefile.files file will do the following things:
Define common C/C++/ASM source and include directories
Define common C/C++/ASM macros
Include Makefile.files.<SOC> which will include all the source code related to the SOC and BOARD
Makefile.files.hbird: Used to include source code for HummingBird SoC
Makefile.soc
This Makefile.soc will include valid makefiles located in <HBIRD_SDK_ROOT>/SoC/<SOC>/build.mk according to the SOC makefile variable setting.
It will define the following items:
DOWNLOAD and CORE variables
For HummingBird SoC, we can support all the modes defined in DOWNLOAD, and CORE list defined in Makefile.core
For HummingBird SoC V2, we can support all the modes defined in DOWNLOAD, and CORE list defined in Makefile.core
Linker script used according to the DOWNLOAD mode settings
OpenOCD debug configuration file used for the SoC and Board
Some extra compiling or debugging options
A valid SoC should be organized like this, take hbirdv2
as example:
SoC/hbirdv2
├── Board
│ └── hbird_fpga_eval
│ ├── Include
│ │ ├── board_hbird_fpga_eval.h
│ │ └── hbird_sdk_hal.h
│ ├── Source
│ │ └── GCC
│ └── openocd_hbirdv2.cfg
├── build.mk
└── Common
├── Include
│ ├── hbirdv2.h
│ ├── ... ...
│ ├── hbirdv2_uart.h
│ ├── hbird_sdk_soc.h
│ └── system_hbirdv2.h
└── Source
├── Drivers
│ ├── ... ...
│ └── hbirdv2_uart.c
├── GCC
│ ├── intexc_hbirdv2.S
│ └── startup_hbirdv2.S
├── Stubs
│ ├── read.c
│ ├── ... ...
│ └── write.c
├── hbirdv2_common.c
└── system_hbirdv2.c
Makefile.rtos
This Makefile.rtos will include <HBIRD_SDK_ROOT>/OS/<RTOS>/build.mk according to our RTOS variable.
A valid rtos should be organized like this, take UCOSII
as example:
OS/UCOSII/
├── arch
├── build.mk
├── license.txt
├── readme.md
└── source
If no RTOS is chosen, then RTOS code will not be included during compiling, user will develop baremetal application.
If FreeRTOS, UCOSII or RTThread RTOS is chosen, then FreeRTOS
UCOSII, or RTThread source code will be included during compiling, and extra
compiler option -DRTOS_$(RTOS_UPPER)
will be passed, then user can develop RTOS application.
For example, if FreeRTOS
is selected, then -DRTOS_FREERTOS
compiler option
will be passed.
Makefile.core
This Makefile.core is used to define the RISC-V ARCH and ABI used during compiling of the CORE list supported.
If you want to add a new CORE, you need to add a new line before SUPPORTED_CORES, and append the new CORE to SUPPORTED_CORES.
For example, if you want to add a new CORE called e207, and the e207’s
ARCH and ABI are rv32imafdc
and ilp32d
, then you can add a new line
like this E207_CORE_ARCH_ABI = rv32imafdc ilp32d
, and append e207 to SUPPORTED_CORES
like this SUPPORTED_CORES = e201 e201e e203 e205 e205f e205fd e207
Note
The appended new CORE need to lower-case, e.g. e207
The new defined variable E207_CORE_ARCH_ABI need to be all upper-case.
Makefile.global
This Makefile.global file is an optional file, and will not be tracked by git, user can create own Makefile.global in <HBIRD_SDK_ROOT>/Build directory.
In this file, user can define custom SOC, BOARD, DOWNLOAD options to overwrite the default configuration.
For example, if you will use only the HummingBird Evaluation Kit, you can create the <HBIRD_SDK_ROOT>/Build/Makefile.global as below:
SOC ?= hbird
BOARD ?= hbird_eval
DOWNLOAD ?= flashxip
Note
If you add above file, then you can build, run, debug application without passing SOC, BOARD and DOWNLOAD variables using make command for HummingBird Evaluation Kit board, e.g.
Build and run application for HummingBird Evaluation Kit:
make run
Debug application for HummingBird Evaluation Kit:
make debug
If you create the Makefile.global like above sample code, you will also be able to use HummingBird SDK build system as usually, it will only change the default SOC, BOARD and DOWNLOAD, but you can still override the default variable using make command, such as
make SOC=hbird BOARD=hbird_eval DOWNLOAD=ilm
Makefile.local
As the Makefile.global is used to override the default Makefile configurations, and the Makefile.local is used to override application level Makefile configurations, and also this file will not be tracked by git.
User can create Makefile.local
file in any of the application folder, placed together with
the application Makefile, for example, you can create Makefile.local
in application/baremetal/helloworld
to override default make configuration for this helloworld application.
If you want to change the default board for helloworld to use HummingBird Evaluation Kit,
you can create application/baremetal/helloworld/Makefile.local
as below:
SOC ?= hbird
BOARD ?= hbird_eval
DOWNLOAD ?= flashxip
Note
This local make configuration will override global and default make configuration.
If you just want to change only some applications’ makefile configuration, you can add and update
Makefile.local
for those applications.
Makefile targets of make command
Here is a list of the Make targets supported by HummingBird SDK Build System.
target |
description |
---|---|
help |
display help message of HummingBird SDK build system |
info |
display selected configuration information |
all |
build application with selected configuration |
clean |
clean application with selected configuration |
dasm |
build and dissemble application with selected configuration |
bin |
build and generate application binary with selected configuration |
upload |
build and upload application with selected configuration |
run_openocd |
run openocd server with selected configuration |
run_gdb |
build and start gdb process with selected configuration |
debug |
build and debug application with selected configuration |
Note
The selected configuration is controlled by Makefile variables passed by make command
For
run_openocd
andrun_gdb
target, if you want to change a new gdb port, you can pass the variable GDB_PORT
Makefile variables passed by make command
In HummingBird SDK build system, we exposed the following Makefile variables which can be passed via make command.
Note
These variables can also be used and defined in application Makefile
If you just want to fix your running board of your application, you can just define these variables in application Makefile, if defined, then you can simply use
make clean
,make upload
ormake debug
, etc.
SOC
SOC variable is used to declare which SoC is used in application during compiling.
You can easily find the supported SoCs in the <HBIRD_SDK_ROOT>/SoC directory.
Currently we support the following SoCs, see Supported SoCs.
SOC |
Reference |
---|---|
hbird |
|
hbirdv2 |
BOARD
Board variable is used to declare which Board is used in application during compiling.
The BOARD variable should match the supported boards of chosen SOC. You can easily find the supported Boards in the <HBIRD_SDK_ROOT>/<SOC>/Board/ directory.
Currently we support the following Boards.
BOARD |
Reference |
---|---|
hbird_eval |
BOARD |
Reference |
---|---|
hbird_ddr_200t |
|
hbird_mcu_200t |
Note
If you only specify SOC variable in make command, it will use default BOARD and CORE option defined in Makefile.soc.<SOC>
DOWNLOAD
DOWNLOAD variable is used to declare the download mode of the application, currently it has these modes supported as described in table Supported download modes
DOWNLOAD |
Description |
---|---|
ilm |
Program will be download into ilm/ram and
run directly in ilm/ram, program lost when poweroff
|
flash |
Program will be download into flash, when running,
program will be copied to ilm/ram and run in ilm/ram
|
flashxip |
Program will to be download into flash and run directly in Flash |
Note
HummingBird SoC support all the download modes.
flashxip mode in HummingBird SoC is very slow due to the CORE frequency is very slow, and Flash speed is slow
CORE
CORE variable is used to declare the HummingBird RISC-V processor core of the application.
Currently it has these cores supported as described in table Supported HummingBird RISC-V Processor cores.
CORE |
ARCH |
ABI |
e203e |
rv32eac |
ilp32e |
e203 |
rv32imac |
ilp32 |
SIMULATION
If SIMULATION=1, it means the program is optimized for hardware simulation environment.
Currently if SIMULATION=1, it will pass compile option -DCFG_SIMULATION, application can use this CFG_SIMULATION to optimize program for hardware simulation environment.
Note
Currently the benchmark applications in application/baremetal/benchmark used this optimization
GDB_PORT
Note
This new variable GDB_PORT is added in HummingBird SDK since version
0.2.4
This variable is not used usually, by default the GDB_PORT variable is 3333
.
If you want to change a debug gdb port for openocd and gdb when run run_openocd
and
run_gdb
target, you can pass a new port such as 3344
to this variable.
For example, if you want to debug application using run_openocd and
run_gdb and specify a different port other than 3333
.
You can do it like this, take hbird_eval
board for example, such as port 3344
:
Open openocd server:
make SOC=hbird BOARD=hbird_eval CORE=e203 GDB_PORT=3344 run_openocd
connect gdb with openocd server:
make SOC=hbird BOARD=hbird_eval CORE=e203 GDB_PORT=3344 run_gdb
V
If V=1, it will display compiling message in verbose including compiling options.
By default, no compiling options will be displayed in make console message just to print less message and make the console message cleaner. If you want to see what compiling option is used, please pass V=1 in your make command.
SILENT
If SILENT=1, it will not display any compiling messsage.
If you don’t want to see any compiling message, you can pass SILENT=1 in your make command.
Makefile variables used only in Application Makefile
The following variables should be used in application Makefile at your demand,
e.g. application/baremetal/timer_test/Makefile
.
TARGET
This is a necessary variable which must be defined in application Makefile.
It is used to set the name of the application, it will affect the generated target filenames.
HBIRD_SDK_ROOT
This is a necessary variable which must be defined in application Makefile.
It is used to set the path of HummingBird SDK Root, usually it should be set as relative path, but you can also set absolute path to point to HummingBird SDK.
RTOS
RTOS variable is used to choose which RTOS will be used in this application.
You can easily find the supported RTOSes in the <HBIRD_SDK_ROOT>/OS directory.
If RTOS is not defined, then baremetal service will be enabled with this application. See examples in
application/baremetal
.If RTOS is set the the following values, RTOS service will be enabled with this application.
FreeRTOS
: FreeRTOS service will be enabled, you can include FreeRTOS header files now, and use FreeRTOS API, forFreeRTOS
application, you need to have anFreeRTOSConfig.h
header file prepared in you application. See examples inapplication/freertos
.UCOSII
: UCOSII service will be enabled, you can include UCOSII header files now, and use UCOSII API, forUCOSII
application, you need to haveapp_cfg.h
,os_cfg.h
andapp_hooks.c
files prepared in you application. See examples inapplication/ucosii
.RTThread
: RT-Thread service will be enabled, you can include RT-Thread header files now, and use RT-Thread API, forUCOSII
application, you need to have anrtconfig.h
header file prepared in you application. See examples inapplication/rtthread
.
MIDDLEWARE
MIDDLEWARE variable is used to select which middlewares should be used in this application.
You can easily find the available middleware components in the <HBIRD_SDK_ROOT>/Components directory.
If MIDDLEWARE is not defined, not leave empty, no middlware package will be selected.
If MIDDLEWARE is defined with more than 1 string, such as
fatfs tjpgd
, then these two middlewares will be selected.
PFLOAT
PFLOAT variable is used to enable floating point value print when using the newlib nano(NEWLIB=nano).
If you don’t use newlib nano, this variable will have no affect.
NEWLIB
NEWLIB variable is used to select which newlib version will be chosen.
If NEWLIB=nano, then newlib nano will be selected. About newlib, please visit https://sourceware.org/newlib/README.
If NEWLIB=, then normal newlib will be used.
NOGC
NOGC variable is used to control whether to enable gc sections to reduce program code size or not, by default GC is enabled to reduce code size.
When GC is enabled, these options will be added:
Adding to compiler options:
-ffunction-sections -fdata-sections
Adding to linker options:
-Wl,--gc-sections -Wl,--check-sections
If you don’t want disable this GC feature, you can set NOGC=1, GC feature will remove sections for you, but sometimes it might remove sections that are useful, e.g. For HummingBird SDK test cases, we use ctest framework, and we need to set NOGC=1 to disable GC feature.
RTTHREAD_MSH
RTTHREAD_MSH variable is valid only when RTOS is set to RTThread.
When RTTHREAD_MSH is set to 1:
The RTThread MSH component source code will be included
The MSH thread will be enabled in the background
Currently the msh getchar implementation is using a weak function implemented in
rt_hw_console_getchar
inOS/RTTThread/libcpu/risc-v/nuclei/cpuport.c