Yocto Linux: Tutorial Basics

The Yocto Project allows users to create custom Linux distributions for emedded and IoT software. It is an open source project, calloborated on by the Linux foundation and other big names in the tech industry. Its big advantage is that it can work on a variety of architectures including some that are not as mainstream or widespread, like ARM, MIPS, PowerPC, x86, and x86-64.

In this tutorial, you will learn the basics of how to use Yocto. We will take you through the step by step instructions to get started with creating your own Linux distribution for an embedded system.

In this tutorial you will learn:

  • What is Yocto used for?
  • How to create a Linux distro with Yocto
Yocto Linux: Tutorial Basics
Yocto Linux: Tutorial Basics
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Yocto, git, various prerequisites
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Yocto Linux: Tutorial Basics

To get started with Yocto, users can download Poky. Poky is a reference Linux distro that Yocto has built as an example. The easiest way to create your own distro is to just edit the files that are used to build Poky.

In addition, developers will supply user configuration, Meta files, Machine BSP configuration, and policy configuration. A custom distribution can then be compiled. The Yocto Project has a great diagram on their website that helps explain the build process:

The Yocto Project workflow
The Yocto Project workflow

Image source: Yocto software overview

Building a Linux distribution with Yocto Project – step by step instructions

  1. The process of using Yocto is very well documented for Ubuntu systems, so it is our recommendation that you use it for your host system. You can still use a lot of other distros, but will need to refer to the system requirements page to learn what prerequisite packages are needed. On Ubuntu or any Debian based system, you can use the following command to install all needed package dependencies:
    $ sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint xterm python3-subunit mesa-common-dev zstd liblz4-tool
  2. Next, we will clone the Yocto git archive which contains all the Poky files. kirkstone is the latest build name at the time of this writing.
    $ git clone -b kirkstone git://git.yoctoproject.org/poky.git
  3. Next, go into the poky directory and initialize the build. This will generate a few configuration files for us, and a new directory.
    $ cd poky
    $ source oe-init-build-env build

    Your terminal will automatically change to the build directory after executing the source command.

    Initialize the build environment for Yocto
    Initialize the build environment for Yocto

  4. Proceed with editing the local.conf file to your liking. This is where you choose your target architecture, what packages your distro will work with (RPM or DEB), and other settings. Anything you choose not to edit will automatically accept the default values. Technically, you do not have to edit anything.
    $ sudo nano conf/local.conf
    Our config is currently set to build for the x86-64 architecture
    Our config is currently set to build for the x86-64 architecture
  5. Next, use the bitbake command to begin compiling.
    $ bitbake core-image-sato
    The build process begins
    The build process begins

    This process may take upwards of a couple hours to complete, depending on the hardware of your computer and connection speed. Many resources will be downloaded and compiled.

The result when the command finishes will be your binary files inside the build directory and poky/build/tmp/deploy/images/qemux86.

Closing Thoughts

In this tutorial, we saw how to use Yocto to build a custom Linux distribution for embedded devices. We have only scraped the surface here, as using Yocto can get extremely complex and the configurations can be done on a very granular scale. Yocto is a godsend to developers that want to use Linux on their embedded devices, and want to customize the software instead of relying on mainstream distros and trying to strip away the unnecessary parts before build time.

Comments and Discussions
Linux Forum