Skip to main content

Simulating devices with QEMU

Install West

Install Dependencies

  1. Install dependencies with apt:

    sudo apt update
    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-venv python3-wheel xz-utils file \
    make gcc gcc-multilib g++-multilib libsdl2-dev
  2. West requires CMake version 3.20.0 or higher. Check the version that your package manager installed:

    $ cmake --version
    cmake version 3.16.3

    If you have an older version, Ubuntu 20.04 systems can add the Kitware repository which maintains the newest release:

    wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
    sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
    sudo apt update
    sudo apt install cmake
    cmake --version

    If the Kitware repository doesn't work for you (ie: your system is not running Ubuntu 20.04), you can build the stable version of CMake from source.

Install West

We recommend creating a python3 virtual environment to avoid running into tooling incompatibilities.

  1. Create your workspace directory:

    mkdir ~/undefined
  2. Use pip3 to install west (beginning with the wheel dependency):

    pip3 install wheel
    pip3 install west

Install Golioth Firmware SDK

  1. With west installed, grab the Zephyr SDK:

    cd ~
    west init -m https://github.com/golioth/golioth-firmware-sdk.git --mr v0.12.1 --mf west-zephyr.yml ~/golioth-zephyr-workspace
    cd golioth-zephyr-workspace/modules/lib/golioth-firmware-sdk
    git submodule update --init --recursive
    west update
    info

    Depending on your internet and I/O speed, west update can take upwards of 5 or 10 minutes.

  2. Tell west to automatically configure CMake:

    west zephyr-export
  3. Install the remaining dependencies:

    pip install -r ~/golioth-zephyr-workspace/zephyr/scripts/requirements.txt

Toolchain check

If you've been using some of the other tutorials on this site, you may have been changing the toolchain, specifically if you used the ESP32. Type the following:

export -p | grep "ZEPHYR"

This should list the following variable

  • ZEPHYR_TOOLCHAIN_VARIANT

If these are set to Espressif, change them to use the default zephyr toolchain (part of the SDK you installed above)

On Linux we compile (non-Espressif) Zephyr using the Zephyr SDK. Do you have that installed? If not, go check out this page on the Zephyr getting started docs.

export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk-x.y.z
caution

Be sure to fill in the sdk name that matches your Zephyr SDK install!

Add credentials to sample

Navigate to the Golioth directory within Zephyr

cd ~/golioth-zephyr-workspace/modules/lib/golioth

This is also the place we will build Zephyr from.

Modify the sample you'd like to build (ie. the hello sample)

nano samples/hello/prj.conf

At the bottom of the page, add your credentials for your device:

CONFIG_GOLIOTH_SAMPLE_HARDCODED_PSK_ID="DEVICE_CRED_ID"
CONFIG_GOLIOTH_SAMPLE_HARDCODED_PSK="DEVICE_PSK"

Save and exit (ctrl+x in nano)

Build for a QEMU Device

At this point, you can build a Golioth Zephyr project:

west build -b qemu_x86 samples/hello -p

and run it:

west build -t run

This should have the same effect as running on a piece of hardware, as in the Golioth NCS Build Environment or Golioth Zephyr Build Environment quickstart guides

For more on networking, see the QEMU page on the Zephyr Docs