Zephyr RTOS setup raspberry pi - joectchan/blog GitHub Wiki

Zephyr RTOS setup on Raspberry Pi

  • This does NOT work at this moment. The installation procedure installs toolchain for Ubuntu on x86. Raspberry Pi is ARM. I need to learn how to configure west to use a different toolchain.

Following the steps on the official page

Step 1

Update my Ubuntu on raspberry pi. Straight forward.

Step 2

I run into these errors when I try to install the standard set of packages.

E: Package 'gcc-multilib' has no installation candidate
E: Unable to locate package g++-multilib
E: Couldn't find any package by regex 'g++-multilib'

apt-cache search gcc-multilib shows that it provides cross-compilers. I circumvent the erros by skipping these two packages.

This is screenshot of what I typed and my result

ubuntu@ubuntu:~$ sudo apt install --no-install-recommends git cmake ninja-build gperf   ccache dfu-util device-tree-compiler wget   python3-pip python3-setuptools python3-tk python3-wheel xz-utils file   make gcc  libsdl2-dev

Reading package lists... Done
Building dependency tree       
Reading state information... Done
cmake is already the newest version (3.13.4-1build1).

... Omitted many pages of output ...

Setting up libglu1-mesa-dev:arm64 (9.0.1-0ubuntu1) ...
Setting up libsdl2-dev (2.0.10+dfsg1-1ubuntu1) ...
ubuntu@ubuntu:~$ 

The version of cmake is recent enough. No further installation needed.

Install west is smooth.

Step 3

I changed a little because I want my programming projects under ~/workspace/

cd ~/workspace/
west init zephyrproject
cd zephyrproject
west update

Step 4

Export Zephyr CMake package is straight forward.

Step 5

pip3 isntall. First, I change the location the requirement file because mine is installed under ~/workspace/

pip3 install --user -r zephyr/scripts/requirements.txt 

However, I run into errors

    In file included from src/lxml/etree.c:692:
    src/lxml/includes/etree_defs.h:14:10: fatal error: libxml/xmlversion.h: No such file or directory
       14 | #include "libxml/xmlversion.h"
          |          ^~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    Compile failed: command 'aarch64-linux-gnu-gcc' failed with exit status 1
    cc -I/usr/include/libxml2 -c /tmp/xmlXPathInitj7amqm0l.c -o tmp/xmlXPathInitj7amqm0l.o
    /tmp/xmlXPathInitj7amqm0l.c:1:10: fatal error: libxml/xpath.h: No such file or directory
        1 | #include "libxml/xpath.h"
          |          ^~~~~~~~~~~~~~~~
    compilation terminated.
    *********************************************************************************
    Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
    *********************************************************************************
    error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-dgluy_te/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-5c7z_uy8/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-dgluy_te/lxml/

Scroll up a few screens of log. Find out the compiliation is meant to get these packages.

Building wheels for collected packages: coverage, sphinx-tabs, cbor, junit2html, lxml

Since compilation breaks down around code related to libxml2 installation, I start from searching for lxml.

ubuntu@ubuntu:~/workspace/zephyrproject$ apt-cache search lxml
python3-lxml - pythonic binding for the libxml2 and libxslt libraries

I install a pre-built package for Ubuntu (for raspberry pi)

ubuntu@ubuntu:~/workspace/zephyrproject$ sudo apt-get install python3-lxml
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  python3-bs4 python3-html5lib python3-soupsieve python3-webencodings
Suggested packages:
  python3-genshi python3-lxml-dbg python-lxml-doc
The following NEW packages will be installed:
  python3-bs4 python3-html5lib python3-lxml python3-soupsieve python3-webencodings
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 1315 kB of archives.
After this operation, 6020 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y

I run my original pip3 install after installing python3-lxml

ubuntu@ubuntu:~/workspace/zephyrproject$ pip3 install --user -r zephyr/scripts/requirements.txt

... Omitted many pages of output ...

Successfully installed Pygments-2.6.1 alabaster-0.7.12 anytree-2.8.0 arrow-0.15.5 babel-2.8.0 breathe-4.14.2 cbor-1.0.0 coverage-5.1 docutils-0.16 gcovr-4.2 gitlint-0.13.1 imagesize-1.2.0 junit2html-22 pytz-2019.3 sh-1.12.14 snowballstemmer-2.0.0 sphinx-2.4.4 sphinx-rtd-theme-0.4.3 sphinx-tabs-1.1.13 sphinxcontrib-applehelp-1.0.2 sphinxcontrib-devhelp-1.0.2 sphinxcontrib-htmlhelp-1.0.3 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-1.0.3 sphinxcontrib-serializinghtml-1.1.4 sphinxcontrib-svg2pdfconverter-1.0.1 tabulate-0.8.7

Step 6

I follow this step with no change. It takes a long time to complete, despite showing error messages.

 [*] Installing additional host tools... 
rm: cannot remove 'environment-setup*': No such file or directory
mv: cannot stat 'version-*': No such file or directory

I allow the installation to create ~/.zephyrrc for me. (I use it very often.)

I find no ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/x86_64-pokysdk-linux directory installed on my Raspberry Pi. The installation on my Ubuntu x86 has that directory.

I am not certain the toolchain installed by this step will work 100% on Raspberry Pi. I will copy the 60-openocd.rules file from my x86 to Raspberry Pi with scp.

Step 7

I run into failure. The toolchain installed is indeed intended for Ubuntu on x86 cross-compiling for ARM. Raspberry Pi is already an ARM system. Need to figure out how to make west run with a different toolchain.

ubuntu@ubuntu:~/workspace/zephyrproject$ west build -p auto -s zephyr/samples/hello_world -d build-hello-world -b disco_l475_iot1 
-- west build: generating a build system
Including boilerplate (Zephyr base): /home/ubuntu/workspace/zephyrproject/zephyr/cmake/app/boilerplate.cmake
-- Application: /home/ubuntu/workspace/zephyrproject/zephyr/samples/hello_world
-- Zephyr version: 2.2.99 (/home/ubuntu/workspace/zephyrproject/zephyr)
-- Found Python3: /usr/bin/python3.7 (found suitable exact version "3.7.5") found components:  Interpreter 
-- Board: disco_l475_iot1
-- Found west: /home/ubuntu/.local/bin/west (found suitable version "0.7.2", minimum required is "0.7.1")
-- Found toolchain: zephyr (/home/ubuntu/zephyr-sdk-0.11.2)
CMake Error at /home/ubuntu/workspace/zephyrproject/zephyr/cmake/compiler/gcc/generic.cmake:24 (message):
  Executing the below command failed.  Are permissions set correctly?

  
  '/home/ubuntu/zephyr-sdk-0.11.2/aarch64-zephyr-elf/bin/aarch64-zephyr-elf-gcc
  --version'

Call Stack (most recent call first):
  /home/ubuntu/workspace/zephyrproject/zephyr/cmake/generic_toolchain.cmake:70 (include)
  /home/ubuntu/workspace/zephyrproject/zephyr/cmake/app/boilerplate.cmake:502 (include)
  /home/ubuntu/workspace/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
  /home/ubuntu/workspace/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
  CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!
FATAL ERROR: command exited with status 1: /usr/bin/cmake -B/home/ubuntu/workspace/zephyrproject/build-hello-world -S/home/ubuntu/workspace/zephyrproject/zephyr/samples/hello_world -GNinja -DBOARD=disco_l475_iot1
ubuntu@ubuntu:~/workspace/zephyrproject$ /home/ubuntu/zephyr-sdk-0.11.2/aarch64-zephyr-elf/bin/aarch64-zephyr-elf-gcc
-bash: /home/ubuntu/zephyr-sdk-0.11.2/aarch64-zephyr-elf/bin/aarch64-zephyr-elf-gcc: cannot execute binary file: Exec format error
ubuntu@ubuntu:~/workspace/zephyrproject$ exit