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
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.