Yocto: Part 3 – Build & run your first ever image!

In the previous posts, we introduced you to Yocto and also showed how to set up your Ubuntu PC for doing Yocto builds. In case you missed them, here they are!

Yocto: Part 1 – A Definitive Introduction

Yocto: Part 2 – Setting up Ubuntu host

In this post, we get right into the action and build our first ever Yocto image. We highly recommend doing this build to everyone – irrespective of the actual machine you want to build for as the resulting image is pretty handy to quickly check for features that you originally want in the image!

Create a working directory

The very first step is to create a working directory for yocto. It is not mandatory but considered a good practice to have a dedicated working directory rather than do everything in a random place on your PC.

Let us assume you are in your home directory. Execute the below commands to create a working directory.

$ mkdir yocto
$ cd yocto

Download Poky and select the desired release

We are almost there! The next step is to download the Poky source code and then checkout the desired release that you need. We will use the dunfell release in this example.

$ git clone git://git.yoctoproject.org/poky
$ cd poky
$ git checkout -b dunfell origin/dunfell

Create your active build directory

A build directory is where all your Yocto builds reside. What this allows you to do is to compartmentalise the builds cleanly but at the same time re-use as many resource as possible. In the build directory resides the machine configuration, specific variables that your image/machine needs, additional recipes you need added to your image, etc.

At the same time, the reusable components like common recipes, source code, tarballs, build state cache, etc. all reside in the poky folder. This allows you to simply create a new build directory for your other machines or projects but still reuse existing components already downloaded, created and/or built.

To create a build directory, you simply need to source a script called oe-init-build-env that will create the build environment (paths, shortcuts, variables, etc.).

$ source oe-init-build-env <name of your build directory>

If you don’t specify a name, a build directory named build is automatically created. The next time you want to use the same directory, simply call the same command again. Also, once this command has executed, you will already be inside the newly created build directory.

Start your first build

The very first build is generally the longest as it downloads hundreds of tarballs from various upstream sources mentioned in the recipes. So, it is a good idea to break it down into two parts. First step is to just fetch all the source code, tarballs, etc. Second step is to do the actual build using the downloaded resources along with the configuration metadata and recipes.

Speaking of recipes, there are a number of core- image recipes already available for you to use. These core recipes enable you to create a working linux image without doing absolutely any customisation for your platform. A successful creation of such an image is proof that your build setup works and you can then move on to doing more sophisticated builds for your own machines.

A small subset of these core images would already be on your screen if your last command executed correctly i.e. you are already inside your build directory. Some popular core images are:

  • core-image-base – A console-only image that fully supports the target hardware.
  • core-image-minimal – A small image allowing the device to just boot.
  • core-image-sato – An image with Sato support, a mobile environment and visual style that works with mobile devices.
  • core-image-clutter – An image with support for the OpenGL-based toolkit Clutter
  • core-image-full-cmdline – A console-only image with more full-featured Linux system functionality installed.
  • ….

The default machine selected for Yocto build is named qemux86-64. This selection can be viewed in the file conf/local.conf. Qemu is a very handy tool to test your Yocto images as it allows you to see if all the feature that you needed in the image are there without really downloading the image to your target machine. As a bonus, it is also a pretty cool linux learning tool as the qemu runs the image using virtualisation and has access to the same resources as your host machine (say Ubuntu).

In this post, we use core-image-sato and keep qemux86-64 as the machine.

To fetch the resources needed for this build, execute the below command.

$ bitbake core-image-sato --runall=fetch

Depending on your internet connection speed and the CPU capability itself, it may take anywhere from few tens of minutes to an hour or more.

Once the resources have been fetched, it is time to start your build. To do so, execute the below command.

$ bitbake core-image-sato

Depending on your CPU capability, it may take anywhere from few tens of minutes to maybe even a few hours (took 2.5 hours for us!).

Running the image

Once the build is complete, the output image can be found in tmp/deploy/images/qemux86-64 folder. Poky provides a handy tool called runqemu that abstracts out a lot of gory steps needed to run the image. It all comes down to executing a simple command to boot your very first Yocto image for the very first time!

To do so, execute the below command:

$ runqemu qemux86-64 nographic

The nographic argument tells runqemu that we are not interested in launching a GUI. This is handy as sometimes, the graphics card access is finicky which can lead to crashes.

That’s it – you should now see your qemux86-64 image boot up. The first boot may take a long time…maybe up to a minute or slightly more. Patience is the key!

We have captured all the steps mentioned above and more in this video.. do check it out and share with others if you find it useful!

If you like our work, do consider subscribing to the channel!

Woohoo! You built your first ever Yocto image..do you feel like a super-hero, yet? Wait till we build our first image for the raspberrypi4 in the next post. See you!

4 thoughts on “Yocto: Part 3 – Build & run your first ever image!

Leave a Reply