Yocto is an ecosystem for building custom Linux distributions that handles everything from pulling source code to producing flashable images. Yocto is used everywhere from small embedded devices to self-driving cars.
Why Use Yocto
Here are the main reasons to use Yocto:
- You need a custom Linux distribution
- You want a cross-compilation toolchain and SDK
For example, you might want to build an OS image for AArch64 that you can deploy to your robot, and also generate a cross-compilation toolchain so you can build software for that robot on your x86_64 workstation.
Parts of Yocto
- Yocto: The overall project
- Bitbake: The build tool used by Yocto
- OpenEmbedded: Provides core recipes and classes
- Poky: A reference distribution built with Yocto
Basic Terminology
- Package: A software package, think a
.deb
or.rpm
file - Recipe: Produces one or more packages
- Layer: A container for one or more recipes
- Class: A composable unit of build logic
Getting Started
First, install kas, which massively simplifies using Yocto. I recommend using kas-container
specifically to avoid messing with your host environment.
Here is an example template to get you started: https://github.com/Slowki/yocto-example
Using the template
git clone https://github.com/Slowki/yocto-example.git
cd yocto-example
# Create a virtual environment for kas (or alternatively use `uv` to manage it)
python3 -m venv .venv
source .venv/bin/activate
pip install kas
Building the image
kas-container build kas.yaml
Building the SDK
kas-container build -c populate_sdk kas.yaml
Extending the Example
To find new layers and recipes, check out https://layers.openembedded.org/.
Add new layers to kas.yaml
and any exciting packages to the IMAGE_INSTALL:append
expression in meta-my-layer/recipes-image/image/my-image.bb
.
Patching a Recipe
One of the cool parts of Yocto is how easy it is to patch existing recipes. There’s an example in the tempalte at meta-my-layer/recipes-support/vim/vim_%.bbappend