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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.
-
Kubuntu Focus Team Releases New Mini Desktop
The team behind Kubuntu Focus has released a new NX GEN 2 mini desktop PC powered by Linux.