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.

Image for post
Image for post

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 :

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

Getting and compiling Zephyr™ OS

Dependencies

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

Zephyr™

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

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 :

Building the hello world sample

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

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 :

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 :

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store