Federico Fuga

Engineering, Tech, Informatics & science

A quick recap on installing a Zephyr Development Environment on Linux

08 Mar 2023 12:49 CET

This guide is a very concise recap based on the great “Getting Started Guide” on the Zephyr Documentation website.

Installing is not difficult and it just take some time and bandwidth.

First I reccommend to install the python tool west on a virtual environment. If you, like me, intend to develop application mostly outside the zephyr project subdirectory as freestanding apps, you’ll use a small env script to setup the ZEPHYR_BASE Environment variable. So adding a line to activate the venv will not be a problem.

First step, check the prerequisites:

  • have the system updated
  • have all the dependencies installed
  • have python3-venv installed
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install --no-install-recommends git cmake ninja-build gperf \
  ccache dfu-util device-tree-compiler wget \
  python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
  make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
$ sudo apt install python3-venv

We assume you install the environment in a proper directory. The guide suggest ~/zephyrproject but I hate to have many subdirectories in my home, so my choice was for ~/Documents/devel/Zephyr/zephyrproject and my apps will go in ~/Documents/devel/Zephyr/. Fix the commands following your choice though.

Create the venv, install west, update the project:

happycactus@iMint:~/Documents/devel/Zephyr$ python3 -m venv ./zephyrproject/.venv
happycactus@iMint:~/Documents/devel/Zephyr$ . ./zephyrproject/.venv/bin/activate
(.venv) happycactus@iMint:~/Documents/devel/Zephyr$ pip install west
Collecting west
  Using cached west-1.0.0-py3-none-any.whl (87 kB)
Collecting PyYAML>=5.1
...
(.venv) happycactus@iMint:~/Documents/devel/Zephyr$ cd zephyrproject/
(.venv) happycactus@iMint:~/Documents/devel/Zephyr/zephyrproject$ west update
=== updating canopennode (modules/lib/canopennode):
--- canopennode: initializing
Initialized empty Git repository in /home/happycactus/Documents/devel/Zephyr/zephyrproject/modules/lib/canopennode/.git/
--- canopennode: fetching, need revision dec12fa3f0d790cafa8414a4c2930ea71ab72ffd
remote: Enumerating objects: 1902, done.

This will take some more time.

Then Download the Zephyr SDK, containing the toolchain and other useful stuff. Install it in /opt or wherever you think it will be suitable. Then fixup everything by running ./setup.sh

(.venv) happycactus@iMint:~$ cd Downloads/
(.venv) happycactus@iMint:~/Downloads$ wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz
--2023-03-08 12:51:29--  https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz
Resolving github.com (github.com)... 140.82.121.3
...
(.venv) happycactus@iMint:~/Downloads$ cd /opt/
(.venv) happycactus@iMint:/opt$ tar xvf ~/Downloads/zephyr-sdk-0.15.2_linux-x86_64.tar.gz
zephyr-sdk-0.15.2/
zephyr-sdk-0.15.2/xtensa-espressif_esp32s2_zephyr-elf/
...
(.venv) happycactus@iMint:/opt$ cd zephyr-sdk-0.15.2/
(.venv) happycactus@iMint:/opt/zephyr-sdk-0.15.2$ ./setup.sh 
Zephyr SDK 0.15.2 Setup
...
All done.
Press any key to exit ...
(.venv) happycactus@iMint:/opt/zephyr-sdk-0.15.2$ sudo cp sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
(.venv) happycactus@iMint:/opt/zephyr-sdk-0.15.2$ sudo udevadm control --reload

The last line install an udev rule for openocd debugger.

You may need additional tools, like programmers or libraries and tool for your board, like with SEGGER, Nordic and Adafruit.