This guide walks through the complete process of building an embedded Linux image for a Raspberry Pi 3 using the Yocto Project. Starting from a fresh Ubuntu environment, you will install prerequisites, configure the build system, and produce a flashable image.
Embedded Linux System Components
Before starting, it is worth reviewing what you are building. A Linux-based embedded system has six main components:
+------------------------------------------+
| Application |
+------------------------------------------+
| System Programs (BusyBox, daemons) |
+------------------------------------------+
| Root Filesystem |
+------------------------------------------+
| Linux Kernel |
+------------------------------------------+
| Device Tree |
+------------------------------------------+
| Bootloader |
+------------------------------------------+
| Hardware (Raspberry Pi 3) |
+------------------------------------------+
| Component | Role |
|---|---|
| Bootloader | Stored in SoC ROM, controls system power-on |
| Device Tree | Describes the physical hardware to the kernel |
| Linux Kernel | Manages hardware resources and services |
| System Programs | Utilities for accessing OS resources |
| Application | Software implementing the device's user function |
| Root Filesystem | Storage for all programs, apps, and configs |
The Yocto Project
The Yocto Project is a completely free, open-source framework for creating custom Linux-based systems for any embedded hardware.
It is not an embedded Linux distribution — it creates a custom one for you.
Yocto builds are composed of several entities:
- Poky — the reference distribution containing the OpenEmbedded build system
- BitBake — the generic task execution engine
- OpenEmbedded Core — shared metadata
- Yocto Metadata — Yocto-specific recipes and configurations
- BSP (Board Support Package) — hardware-specific support (e.g.
meta-raspberrypi)
Step 1: Prepare the Host Environment
Using Docker (Optional but Recommended)
If you do not have a supported Linux distribution installed natively, use Docker:
docker run -dit --name ubuntu_18 \
-v /Users/amr/myworkspace:/home/myworkspace \
ubuntu:18.04
docker attach ubuntu_18
apt update && apt upgrade -y
apt install sudo git nano vim -y
Create a build user:
useradd amr
passwd amr
usermod -aG sudo amr
usermod -s /bin/bash amr
su - amr
Install Host Prerequisites
Install the packages required by Yocto on Ubuntu:
sudo apt install gawk wget git diffstat unzip texinfo \
gcc-multilib build-essential chrpath socat \
libsdl1.2-dev xterm ncurses-dev lzop \
minicom u-boot-tools curl
Install the repo tool (used by some Yocto distributions to manage multiple repositories):
mkdir ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo \
> ~/bin/repo
chmod a+x ~/bin/repo
export PATH=$PATH:~/bin
Configure Git
git config --global user.name "username"
git config --global user.email "email@example.com"
Step 2: Download Yocto
This example uses Yocto 3.4 (Honister) to build for Raspberry Pi 3.
mkdir -p ~/yocto/sources
cd ~/yocto/sources
# Clone Poky
git clone -b honister git://git.yoctoproject.org/poky.git
# Clone the Raspberry Pi BSP layer
git clone -b honister git://git.yoctoproject.org/meta-raspberrypi
Step 3: Configure the Build Environment
Initialise the Yocto build environment and create a build directory named rpi-build:
cd ~/yocto
source sources/poky/oe-init-build-env rpi-build
This script creates the rpi-build directory and changes into it. You will find a conf/ directory containing the configuration files.
Step 4: Configure the Build
Edit local.conf
Configure the target machine and build settings. Open rpi-build/conf/local.conf and replace the default content or append:
For Yocto version 3 and below:
MACHINE ?= "raspberrypi3"
PREFERRED_VERSION_linux-raspberrypi = "4.%"
DISTRO_FEATURES_remove = "x11 wayland"
DISTRO_FEATURES_append = " systemd"
VIRTUAL-RUNTIME_init_manager = "systemd"
ENABLE_UART = "1"
For Yocto version 3 and above (new syntax):
MACHINE ?= "raspberrypi3"
PREFERRED_VERSION:linux-raspberrypi = "4.%"
DISTRO_FEATURES:remove = "x11 wayland"
DISTRO_FEATURES:append = " systemd"
VIRTUAL-RUNTIME:init_manager = "systemd"
ENABLE_UART = "1"
Edit bblayers.conf
Add the Raspberry Pi BSP layer to the build. Replace the content of rpi-build/conf/bblayers.conf:
LCONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BSPDIR := "${@os.path.abspath(os.path.dirname(d.getVar('FILE', True)) + '/../..')}"
BBFILES ?= ""
BBLAYERS ?= " \
${BSPDIR}/sources/poky/meta \
${BSPDIR}/sources/poky/meta-yocto \
${BSPDIR}/sources/poky/meta-yocto-bsp \
${BSPDIR}/sources/meta-raspberrypi \
"
Step 5: Optional Network Configuration
To enable Ethernet connectivity on the Raspberry Pi from within Yocto, configure the network interface file. This step is optional and primarily useful for testing connectivity.
cd ~/yocto/sources/poky/meta/recipes-core/init-ifupdown/init-ifupdown-1.0
mkdir raspberrypi3
touch interfaces
Add the network configuration to the interfaces file:
# The loopback interface
auto lo
iface lo inet loopback
# Wired interface with static IP
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
Step 6: Build the Image
With the build environment sourced and the configuration complete, trigger the build:
cd ~/yocto
source sources/poky/oe-init-build-env rpi-build
bitbake rpi-basic-image
BitBake will:
- Parse all recipe metadata
- Resolve build dependencies
- Download required source archives
- Cross-compile all packages
- Assemble the root filesystem
- Create the final image
Build time varies depending on host speed — expect 1–4 hours on the first run. Subsequent builds are much faster due to caching.
Step 7: Locate and Deploy the Image
When the build completes, locate the output images:
ls ~/yocto/rpi-build/tmp-glibc/deploy/images/raspberrypi3/
Image files have a .wic or .sdimg extension. Flash the image to an SD card:
sudo dd if=rpi-basic-image-raspberrypi3.wic \
of=/dev/mmcblk0 \
bs=1M \
status=progress
sync
Alternatively, use Balena Etcher — a graphical tool for writing disk images to SD cards.
Step 8: Boot the Raspberry Pi
- Insert the SD card into the Raspberry Pi 3
- Connect a serial console (UART) or HDMI display
- Power on the board
- The bootloader (U-Boot) loads and passes control to the Linux kernel
- The system boots to a login prompt
Default credentials for Yocto images are typically:
- Username:
root - Password: (none — press Enter)
Build Summary
Yocto Raspberry Pi 3 Build Flow:
Prepare host (install packages, Git)
|
v
Clone poky + meta-raspberrypi
|
v
source oe-init-build-env rpi-build
|
v
Configure local.conf (MACHINE = raspberrypi3)
Configure bblayers.conf (add meta-raspberrypi)
|
v
bitbake rpi-basic-image
|
v
Flash .wic image to SD card
|
v
Boot on Raspberry Pi 3
Final Thoughts
This practical guide demonstrates the complete workflow for building an embedded Linux image with Yocto. Once you have successfully built and booted the base image, you can:
- Add custom recipes and layers for your application
- Customise the kernel configuration with
bitbake -c menuconfig linux-yocto - Add packages to the image via
IMAGE_INSTALL:append - Create your own
meta-layer for product-specific customisation
The skills learned here form the foundation for building production-quality embedded Linux systems.