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.
Infos
- Yocto Project/OpenEmbedded Framework: https://www.yoctoproject.org
- Getting Started: The Yocto Project Overview: https://www.yoctoproject.org/software-overview/
- Buildroot: https://buildroot.org
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs