How the Yocto framework brings Linux to IoT devices

An Application

The last step is to run a custom application or modify the kernel to support your custom hardware. The first thing you need to do is create two new repositories. One repository houses your own layer, and the other is for the manifest used to download all layers, including yours, via the Repo tool. Because the vendor (Digi in this example) controls the manifest, you need to copy it, add your layer to the repository, and finally upload the modified manifest to your own repo.

The second thing you need is the files for your layer. You can simply copy the configuration file from another layer and create your own recipes using the structure shown previously. For a "Hello, World" application in C, the resulting directory structure would be like the one in Listing 4.

Listing 4

Directory Structure

meta-custom
|-- apps
|      |-- files
|      |      |-- hello-world.c
|      |-- hello-world.bb

The hello-world.bb file must be specially formatted; Listing 5 shows the contents. The first four lines describe the recipe and its license. If this is derived from the GPL, the checksum must be specified. If you do not want to publish the recipe under a free license, you can enter the value CLOSED in the License field.

Listing 5

hello-world.bb

01 DESCRIPTION = "Simple Hello World Application"
02 SECTION = "examples"
03 LICENSE = "WITH
04 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
05 SRC_URI = "file://helloworld.c"
06 S = "${WORKDIR}"
07 do_compile() {
08   ${CC} hello-world.c -o hello-world
09 }
10 do_install() {
11   install -d ${D}${bindir}
12   install -m 0755 hello-world ${D}${bindir}
13 }

The SRC_URI in Line 5 tells BitBake where to find the files associated with the recipe. In this example, the only file is a single C file. However, you can also specify complete repositories that are managed by Git or Subversion.

The end of the recipe contains two more functions (from Lines 7 and 10) that compile the source file of the applications and install the results. The Yocto framework comes with basic versions of these functions, which the user can then overwrite. The framework also already contains templates for other frequently used functions, such as for downloading sources.

The actual application is a very simple C file (Listing 6). To create the recipe, just use the short bitbake hello-world command.

Listing 6

hello-world.c

#include <stdio.h>
{
  printf("Hello, world!\n");
}

For the IoT device to run the "Hello, World" application, you need to add it to the final image. So far, the bitbake dey-image-qt command has told BitBake to build the image from the dey-image-qt recipe. All you need to append the package that creates the hello-world.bb recipe is an append file named dey-image-qt.bbappend with the contents in Listing 7.

Listing 7

Append file

IMAGE_INSTALL_append = " hello-world"

If you now call bitbake dey-image-qt, the "Hello, World" binary will also be created and placed in the final image, which you can now load onto the IoT device.

Conclusions

If you need to adapt an operating system to run on an embedded device, and you want to use Linux, the Yocto project will give you a head start with sorting through the details. The tools, layers, and recipes of the Yocto project will save you time and simplify the task of adapting Linux to the hardware. Alternative frameworks also exist, for example, Buildroot [3], which you will read about elsewhere in this issue. The advantage of Yocto is that it is very popular among SoM vendors and has become the predominant framework for Linux builds. The disadvantage: It requires significantly more resources than Buildroot.

Figure 1: Bare metal, RTOS, and Linux embedded systems differ in their demand for system resources.

Infos

  1. Yocto Project/OpenEmbedded Framework: https://www.yoctoproject.org
  2. Getting Started: The Yocto Project Overview: https://www.yoctoproject.org/software-overview/
  3. Buildroot: https://buildroot.org

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News