Build OpenThread

View source on GitHub

How to build OpenThread

The steps to build OpenThread vary depending on toolchain, user machine, and target platform.

The most common workflow is:

  1. Set up the build environment and install the desired toolchain:
    1. To build directly on a machine, see the Simulation Codelab for detailed instructions
    2. To use a Docker container with a pre-configured environment, download and run the OpenThread environment image:
      docker pull openthread/environment:latest
      docker run -it --rm openthread/environment bash
      
  2. Within your chosen environment, clone the platform-specific OpenThread Git repository. Taking CC2538 as an example:
    git clone https://github.com/openthread/ot-cc2538.git --recursive
    
  3. From the cloned repository's root directory:
    1. Install the toolchain:
      ./script/bootstrap
      
    2. Build the configuration:
      ./script/build platform-specific-args cmake-options
      
  4. Flash the desired binary to the target platform. All generated binaries are located in ./build/bin.

Configuration

You can configure OpenThread for different functionality and behavior during the build process. Available configuration options are detailed at the following locations:

Type Location
Compile-time constants Listed in all the header files in /src/core/config
cmake build options Listed in openthread/examples/README.md

Build examples

Use cmake build options to enable functionality for the platform. For example, to build the binary for the CC2538 platform with Commissioner and Joiner support enabled:

./script/build -DOT_COMMISSIONER=ON -DOT_JOINER=ON

Or, to build the nRF52840 platform with the Jam Detection feature enabled in its repo:

./script/build nrf52840 UART_trans -DOT_JAM_DETECTION=ON

Binaries

The following binaries are generated in ./build/bin from the build process. To determine which binaries are generated, use flags with the ./script/build command. For example, to build OpenThread and generate only the FTD CLI binary:

./script/build -DOT_APP_CLI=ON -DOT_FTD=ON -DOT_MTD=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF -DOT_RCP=OFF
Binary Description Options
ot-cli-ftd Full Thread device for SoC designs -DOT_APP_CLI=ON
-DOT_FTD=ON
ot-cli-mtd Minimal Thread device for SoC designs -DOT_APP_CLI=ON
-DOT_MTD=ON
ot-ncp-ftd Full Thread device for Network Co-Processor (NCP) designs -DOT_APP_NCP=ON
-DOT_FTD=ON
ot-ncp-mtd Minimal Thread device for NCP designs -DOT_APP_NCP=ON
-DOT_MTD=ON
ot-rcp Radio Co-Processor (RCP) design -DOT_APP_RCP=ON
-DOT_RCP=ON

By default, all above flags are enabled. If you explicitly disable all flags, applications are not built but OpenThread library files are still generated in ./build/lib for use in a project.

Check the examples/platforms directory to see which flags each platform supports. For more information on FTDs and MTDs, see the Thread Primer. For more information on SoC and NCP designs, see Platforms.

The process to flash these binaries varies across example platforms. See the READMEs in each platform's example folder for detailed instructions.

OpenThread Daemon

OpenThread Daemon (OT Daemon) is an OpenThread POSIX build mode that runs OpenThread as a service and is used with the RCP design. For more information on how to build and use it, see OpenThread Daemon.

Build Support Packages

Build Support Packages (BSPs) are found in /third_party. BSPs are additional third-party code used by OpenThread on each respective platform, generally included when porting OpenThread to a new hardware platform.