Creating Custom Distributions with Yocto for Embedded Linux Systems
The Yocto Project is not a ready-made Linux distribution; it is a build framework that produces your own embedded Linux distribution from source. Its task engine, BitBake, reads recipes organised in layers and builds the kernel, bootloader, libraries and your applications into an image tailored to your target board. The result is a reproducible, versionable operating system that contains only the packages you actually need.
What is the Yocto Project and why use it?
The Yocto Project is an open-source collaboration project hosted by the Linux Foundation. It is built on the OpenEmbedded build system and BitBake, and its reference distribution is called Poky. The main reasons it is chosen for industrial devices:
- Customisation: Everything from a minimal image of a few megabytes to a full graphical system is produced with the same tooling.
- Reproducibility: The same layer revisions and configuration produce the same image, which matters when you maintain a fleet of devices in the field.
- Broad hardware support: Silicon vendors (NXP, TI, Raspberry Pi and others) publish BSP layers for their boards.
- License tracking: The license of every package is recorded during the build, which simplifies product compliance reviews.
- Long-term support: Selected releases are designated LTS and receive updates for four years: Scarthgap 5.0 is supported until April 2028 and Wrynose 6.0 until April 2030. Support for the previous LTS, Kirkstone 4.0, has ended.
What are Yocto's core concepts?
Yocto looks complex at first; once the concepts click, the structure is quite logical.
| Concept | File / Example | Purpose |
|---|---|---|
| Layer | meta-mycompany/ | A directory grouping related recipes, classes and configuration |
| Recipe | myapp_1.0.bb | Defines a package's source, build and install steps |
| Append | myapp_%.bbappend | Modifies a recipe from another layer without touching its file |
| Class | cmake.bbclass | Shared build logic, used via inherit |
| Machine configuration | conf/machine/*.conf | Target hardware: CPU architecture, kernel, bootloader, device tree |
| Distro configuration | conf/distro/*.conf | System policy: init system, DISTRO_FEATURES, libc |
| Image recipe | core-image-minimal.bb | The list of packages that go into the root filesystem |
| BitBake | bitbake <target> | The engine that parses recipes and runs tasks in dependency order |
How does BitBake process a recipe?
For each recipe BitBake runs a chain of tasks: do_fetch (download the source) → do_unpack → do_patch → do_configure → do_compile → do_install → do_package, and finally do_rootfs for the image. Each task's output is stored in the sstate-cache (shared state). A task whose inputs have not changed is not rerun on the next build; its result is restored from the cache. This is the mechanism that actually governs build times in Yocto.
How do you get started with Yocto?
On an Ubuntu/Debian build host, install the required packages (for the Scarthgap release):
sudo apt install build-essential chrpath cpio debianutils diffstat file gawk gcc git \
iputils-ping libacl1 liblz4-tool locales python3 python3-git python3-jinja2 \
python3-pexpect python3-pip python3-subunit socat texinfo unzip wget xz-utils zstd
Then check out Poky from an LTS branch and build your first image. The commands in this article are for Scarthgap; setup steps may differ in newer releases such as Wrynose, so check that release's documentation:
git clone -b scarthgap https://git.yoctoproject.org/poky
cd poky
source oe-init-build-env build # creates build/ and changes into it
bitbake core-image-minimal # minimal image for the QEMU target
The MACHINE variable in build/conf/local.conf selects the target board. For a Raspberry Pi 4, for example, you add the meta-raspberrypi layer and set MACHINE = "raspberrypi4-64".
How should you structure your own layer?
Keeping company-specific changes in a separate layer, rather than editing Poky or BSP layers, makes release upgrades far easier:
bitbake-layers create-layer ../meta-mycompany
bitbake-layers add-layer ../meta-mycompany
A mature product layer typically looks like this:
meta-mycompany/
├── conf/
│ ├── layer.conf # layer priority, compatible releases
│ ├── distro/mycompany.conf # distribution policy
│ └── machine/mydevice.conf # custom board definition (if needed)
├── recipes-apps/
│ └── myapp/myapp_1.0.bb # application recipe
├── recipes-core/
│ └── images/mycompany-image.bb # product image
└── recipes-kernel/
└── linux/linux-yocto_%.bbappend # kernel patch / config fragment
Example application recipe
SUMMARY = "My Custom Application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=..."
SRC_URI = "git://github.com/mycompany/myapp.git;protocol=https;branch=main"
SRCREV = "<fixed-commit-hash>" # pin a commit for production instead of AUTOREV
inherit cmake
do_install() {
install -d ${D}${bindir}
install -m 0755 ${B}/myapp ${D}${bindir}
}
SRCREV = "${AUTOREV}" is convenient during development, but because it pulls the latest commit on every build it breaks reproducibility; use a fixed commit in product images.
Distro and image definition
# conf/distro/mycompany.conf
require conf/distro/poky.conf
DISTRO = "mycompany"
DISTRO_FEATURES:append = " systemd"
INIT_MANAGER = "systemd"
# recipes-core/images/mycompany-image.bb
require recipes-core/images/core-image-minimal.bb
IMAGE_INSTALL:append = " myapp openssh"
With DISTRO = "mycompany" set in local.conf, the whole image is built with that policy. Hardware (machine), policy (distro) and content (image) stay separate, so moving the same software to a different board only requires changing MACHINE.
How do Yocto, Buildroot and a stock distribution compare?
| Criterion | Yocto | Buildroot | Debian/Ubuntu-based |
|---|---|---|---|
| Learning curve | Steep | Moderate | Low |
| First build time | Long (hours) | Shorter | No build, prebuilt packages |
| Incremental builds | Fast with sstate | Config changes usually need a full rebuild | — |
| Package management | Yes (rpm/ipk/deb) | No | apt |
| Image size control | Very fine-grained | Fine-grained | Limited |
| Long-lived product maintenance | Strong (LTS, layers) | Good | Tied to the distro's lifecycle |
What should you expect in build time and resources?
Yocto's biggest cost is the first build. Because the cross-toolchain, the kernel and hundreds of packages are compiled from source, the first bitbake run can take hours even on a powerful machine and consume tens of gigabytes of disk. Practical tips:
- Share
DL_DIRandSSTATE_DIR: When downloaded sources and the sstate cache are shared across build directories or CI machines, subsequent builds drop to minutes. BB_NUMBER_THREADSandPARALLEL_MAKE: These default to the CPU count; lowering them on machines with limited RAM avoids out-of-memory failures.rm_work:INHERIT += "rm_work"deletes the work directories of finished recipes and noticeably reduces disk usage.- Use an SSD: BitBake handles a very large number of small files, so disk speed directly affects build time.
This upfront cost pays back over the product's life as controlled, reproducible updates.
Summary: checklist for starting a Yocto project
- Pick an LTS branch and pin every layer to the same branch.
- Identify your board's BSP layer and confirm the
MACHINEvalue. - Keep company changes in your own layer, using
.bbappendfiles. - Define a separate distro and image recipe; keep
local.confminimal. - Use a fixed
SRCREVin production recipes and share the sstate cache.
To build a Qt user interface on top of a Yocto-based system, see our article on Embedded Linux HMI development with Yocto and Qt; the panels we build on this foundation are on the HMI Industrial Display Solutions page. For the microcontroller side, where Linux is not needed, we explain why we use Zephyr RTOS; for the basics, see the embedded systems glossary entry.
At Amazeng, we provide consulting and development services for embedded Linux systems. Contact us for your needs.