Cross Compile Zephyr™ OS

As stated in the documentation, The Zephyr™ Project is a scalable real-time operating system (RTOS) supporting multiple hardware architectures, optimized for resource constrained devices, and built with security in mind.

In this tutorial, we are going show how to cross compile, from our Mac environment, this Zephyr™ Operating System for an ARM target architecture using GNU Arm Embedded Toolchain.

GNU Arm Embedded Toolchain

First of all, download the GNU Arm Embedded Toolchain for Mac OS which is currently the 2017-q4-major release.

Then, install the toolchain in your home /opt directory, as follow :

$ mkdir -p “${HOME}”/opt
$ cd “${HOME}”/opt
$ tar xjf ~/Downloads/gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2
$ chmod -R -w “${HOME}”/opt/gcc-arm-none-eabi-7–2017-q4-major

To check if the toolchain is properly install, simply run gcc with the — version option

$ "${HOME}"/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc --versionarm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7–2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]

Getting and compiling Zephyr™ OS


As explained in the documentation, you will need some dependencies utilities and applications that you need to get :

$ brew install cmake ninja dfu-util doxygen qemu dtc python3 gperf


Now, you need to clone Zephyr™ and install all the requirements requested by Zephyr™ itself (thanks to pip):

$ git clone
$ cd ~/zephyr
$ pip3 install — user -r scripts/requirements.txt
$ source

Configuration toolchain

Now gets the interesting part. We will compile an image of Zephyr™, from our Mac, targeting the Arduino DUE, which is an ARM based board.

The first thing is to set some environment variables that will be used by Ninja and cmake. It is mainly the ARM toolchain path and letting Zephyr™ know about it :

$ export GCCARMEMB_TOOLCHAIN_PATH="~/opt/gcc-arm-none-eabi-7-2017-q4-major/"

Building the hello world sample

Finally, we can build the hello_world sample provided in the repository, targeting our ARM board :

$ cd $ZEPHYR_BASE/samples/hello_world
$ mkdir build && cd build
# compiling for arduino_due using the third part ARM compiler
$ cmake -GNinja -DBOARD=arduino_due ..
# generating the build system with Ninja:
$ ninja

Bonus : run your application in qemu

Arduino DUE is based on a cortex M3 CP UTo run your application in qemu, you need to compile it against qemu. To do so, proceed as follow :

$ cd $ZEPHYR_BASE/samples/hello_world/build# compiling for qemu_cortex_m3 using the third part ARM compiler
$ cmake -GNinja -DBOARD=qemu_cortex_m3 ..
# generating the build system with Ninja:
$ ninja
# running into qemu:
$ ninja run

Going further

What motivates me to share this tutorial is that I couldn’t find easily how to install the third part toolchain and how to configure the environment for cross-compiling.

If you’d like to go further or explore by yourself, here are 2 links :