How to build a Yocto image for the Raspberry Pi running Azure IoT Edge

Recently, I had a few customers ask about Yocto for Azure IoT Edge.  Yocto, being an embedded Linux, is not as straight forward as Windows, Redhat or Ubuntu.  Currently, Azure IoT Edge supports Yocto, but as a tier 2 OS.

For learning purposes, this blog walks through the process of creating a Yocto image for use on a Raspberry Pi 3.  This information can also be used as a foundation for building production ready Yocto images if needed.

In a later post, I will provide a Dockerfile for automated creation of a Yocto image.

Environment setup:

You will need a Linux OS to build the image.  For this blog, I used Ubuntu 18.04 and you will need ~80 GB of disk space.

Steps to create the Yocto image:

  1. As non-root, setup your environment (will not build as root):
sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
     build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
     xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \
     xterm locales

mkdir -p ~/rpi/sources
cd ~/rpi/sources
locale-gen en_US.UTF-8
  1. get the sources we need (called layers in Yocto terms. For IoT Edge, we can use the sumo or thud build.  Note there is a bug in rust where we have to use the master branch)
git clone https://github.com/Azure/meta-iotedge.git
git clone -b sumo git://git.yoctoproject.org/meta-virtualization
git clone -b master git://github.com/meta-rust/meta-rust.git
git clone -b sumo git://git.yoctoproject.org/poky
git clone -b sumo git://git.openembedded.org/meta-openembedded
git clone -b sumo git://git.yoctoproject.org/meta-intel
git clone -b sumo git://git.yoctoproject.org/meta-raspberrypi
  1. create a basic config file (note, source is a command in the bash shell, if you get a command not found, make sure you are in bash)
cd ~/rpi
source sources/poky/oe-init-build-env rpi-build
  1. modify ~/rpi/rpi-build/conf/local.config by running the following commands (on a different hardware version of RP, review: https://meta-raspberrypi.readthedocs.io/en/latest/layer-contents.html#supported-machines optionally you can add either the intel-core2-32 or intel-corei7-64: http://git.yoctoproject.org/cgit/cgit.cgi/meta-intel/about/)
cd ~/rpi/rpi-build/
echo '# Machine Selection' > conf/local.conf
echo 'MACHINE ?= "raspberrypi3"' >> conf/local.conf
echo 'DISTRO ?= "poky"' >> conf/local.conf
echo 'PACKAGE_CLASSES ?= "package_rpm"' >> conf/local.conf
echo 'EXTRA_IMAGE_FEATURES ?= "debug-tweaks ssh-server-dropbear tools-debug tools-sdk"' >> conf/local.conf
echo 'USER_CLASSES ?= "buildstats image-mklibs"' >> conf/local.conf
echo 'PATCHRESOLVE = "noop"' >> conf/local.conf
echo 'BB_DISKMON_DIRS = "\' >> conf/local.conf
echo '    STOPTASKS,${TMPDIR},1G,100K \' >> conf/local.conf
echo '    STOPTASKS,${DL_DIR},1G,100K \' >> conf/local.conf
echo '    STOPTASKS,${SSTATE_DIR},1G,100K \' >> conf/local.conf
echo '    STOPTASKS,/tmp,100M,100K \' >> conf/local.conf
echo '    ABORT,${TMPDIR},100M,1K \' >> conf/local.conf
echo '    ABORT,${DL_DIR},100M,1K \' >> conf/local.conf
echo '    ABORT,${SSTATE_DIR},100M,1K \' >> conf/local.conf
echo '    ABORT,/tmp,10M,1K"' >> conf/local.conf
echo 'SSTATE_MIRRORS = "\' >> conf/local.conf
echo '     file://.* http://sstate.yoctoproject.org/dev/PATH;downloadfilename=PATH \n \' >> conf/local.conf
echo '     file://.* http://sstate.yoctoproject.org/2.4.4/PATH;downloadfilename=PATH \n \' >> conf/local.conf
echo '     file://.* http://sstate.yoctoproject.org/2.5.2/PATH;downloadfilename=PATH \n \' >> conf/local.conf
echo '     file://.* http://sstate.yoctoproject.org/2.5.3/PATH;downloadfilename=PATH \n \' >> conf/local.conf
echo '     file://.* http://sstate.yoctoproject.org/2.6.2/PATH;downloadfilename=PATH \n \' >> conf/local.conf
echo '     file://.* http://sstate.yoctoproject.org/2.7/PATH;downloadfilename=PATH \n \' >> conf/local.conf
echo '     "' >> conf/local.conf
echo 'PACKAGECONFIG_append_pn-qemu-native = " sdl"' >> conf/local.conf
echo 'PACKAGECONFIG_append_pn-nativesdk-qemu = " sdl"' >> conf/local.conf
echo 'CONF_VERSION = "1"' >> conf/local.conf
echo 'IMAGE_INSTALL_append += "\' >> conf/local.conf
echo '                         iotedge-daemon \' >> conf/local.conf
echo '                         iotedge-cli \' >> conf/local.conf
echo '                         docker \' >> conf/local.conf
echo '                         docker-contrib \' >> conf/local.conf
echo '                         ca-certificates \' >> conf/local.conf
echo '                         connman \' >> conf/local.conf
echo '                         connman-client \' >> conf/local.conf
echo '                         "' >> conf/local.conf
echo 'DISTRO_FEATURES_append += " systemd wifi virtualization"' >> conf/local.conf
echo 'VIRTUAL-RUNTIME_init_manager = "systemd"' >> conf/local.conf
echo 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"' >> conf/local.conf
echo 'VIRTUAL-RUNTIME_initscripts = ""' >> conf/local.conf
echo '# we need space for images' >> conf/local.conf
echo 'IMAGE_ROOTFS_EXTRA_SPACE = "10485760"' >> conf/local.conf
echo '# The extra space takes us above 4gb, so' >> conf/local.conf
echo '# turn off hdd and iso images so they do' >> conf/local.conf
echo '# not break' >> conf/local.conf
echo 'NOHDD="1"' >> conf/local.conf
echo 'NOISO="1"' >> conf/local.conf
echo 'RPI_USE_U_BOOT = "1"' >> conf/local.conf
  1. modify ~/rpi/rpi-build/conf/bblayers.conf by running the following commands. Make changes to the BSPDIR line
echo '# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf' > conf/bblayers.conf
echo '# changes incompatibly' >> conf/bblayers.conf
echo 'POKY_BBLAYERS_CONF_VERSION = "2"' >> conf/bblayers.conf
echo '                    ' >> conf/bblayers.conf
echo 'BBPATH = "${TOPDIR}"' >> conf/bblayers.conf
echo 'BBFILES ?= ""' >> conf/bblayers.conf
echo '                    ' >> conf/bblayers.conf
echo 'BSPDIR := "/home/ksaye/rpi/"' >> conf/bblayers.conf
echo '                    ' >> conf/bblayers.conf
echo 'BBLAYERS ?= " \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/poky/meta \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/poky/meta-poky \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/poky/meta-yocto-bsp \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-openembedded/meta-oe \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-openembedded/meta-networking \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-openembedded/meta-python \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-openembedded/meta-filesystems \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-raspberrypi \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-iotedge \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-rust \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-virtualization \' >> conf/bblayers.conf
echo '  "                                      ' >> conf/bblayers.conf
echo 'BBLAYERS_NON_REMOVABLE ?= " \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/poky/meta \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/poky/meta-poky \' >> conf/bblayers.conf
echo '  ${BSPDIR}/sources/meta-iotedge \' >> conf/bblayers.conf
echo '  "' >> conf/bblayers.conf
  1. build the image (this can take over an hour or so depending on your host hardware and bandwidth. Once you have parsed the recipes successfully it should just take time. Consider running nohup bitbake core-image-base & if you feel you will have to disconnect and come back later.)
cd ~/rpi
bitbake core-image-base

The build process consuming all the CPU on the build host.

On a 32 way, 64 GB, machine in Azure with adequate bandwidth and SSD disk: Standard F32s_v2 (32 vcpus, 64 GiB memory)

  1. copy the images to your SD Card (make sure you know which device the card is, example below is /dev/sdX). Need to copy the image to the SD Card on Windows?  You can use: https://rufus.akeo.ie.
sudo dd if=~/rpi/rpi-build/tmp/deploy/images/raspberrypi3/rpi-basic-image-raspberrypi3-64.rpi-sdimg of=/dev/sde bs=4M
  1. boot the Pi, log in as root with no password and change the password

References:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s