Yocto for Raspberry Pi 5 Part 1 (Image Creation)
Requirements
- Raspberry Pi 5 (full or compute module)
- Working, updated Linux installation with ~100GiB free space (WSL or Raspberry Pi are fine as well)
- Installed software on Linux: git and python3
Steps
Update the Linux distribution and create a new directory somewhere. I chose yocto-rpi5-01 for the name. Enter the directory and clone two repositories:
git clone https://git.yoctoproject.org/poky -b scarthgap git clone https://git.yoctoproject.org/meta-raspberrypi -b scarthgap
The -b scarthegap parameter selects the scarthegap branch automatically from the repositories. Now, from within the yocto-rpi5-01, set up a build environment using the Python source command. This will create a build directory and set the console’s location inside that directory.
source poky/oe-init-build-env
Note: closing the terminal will invalidate the source command’s settings, so you will have to be run again should you close the terminal, power down, etc. From within the build directory, use bitbake-layers to add the other cloned repo to this project’s configuration.
bitbake-layers add-layer ../meta-raspberrypi
Alternatively, the build/conf/bblayers.conf file can be edited to include the absolute location of the meta-raspberrypi directory. I have not tested this using relative locations yet inside the configuration file yet.
look for BBLAYERS ?= " \ /home/macsimum/yocto-rpi5-01/poky/meta \ /home/macsimum/yocto-rpi5-01/poky/meta-poky \ /home/macsimum/yocto-rpi5-01/poky/meta-yocto-bsp \ /home/macsimum/yocto-rpi5-01/meta-raspberrypi \ "
The command bitbake-layers is useful because it identifies missing packages before the build process starts. I did receive errors on a clean Linux installation:
ERROR: The following required tools (as specified by HOSTTOOLS) appear to be unavailable in PATH, please install them in order to proceed: ar as bunzip2 bzip2 chrpath cpp diffstat file g++ gawk gcc ld lz4c make nm objcopy objdump pzstd ranlib readelf rpcgen strings strip unzstd wget zstd
In my case, build-essential covers a lot of the requirements. Continue installing missing dependencies. Note: lz4c is a special case where the package may be lz4. The package zstd covers pzstd, unzstd, and zstd. Re-run the bitbake-layers command from above after installing any missing dependencies. After this is complete build/conf/bblayers.conf SHOULD look like the example above.
Edit build/conf/local.conf file and add the line:
MACHINE = "raspberrypi5"
Run bitbake core-image-base, and you should receive the following error:
ERROR: Nothing RPROVIDES 'linux-firmware-rpidistro-bcm43455' (but /home/macsimum/yocto-rpi5-01/poky/meta/recipes-core/packagegroups/packagegroup-base.bb RDEPENDS on or otherwise requires it) linux-firmware-rpidistro RPROVIDES linux-firmware-rpidistro-bcm43455 but was skipped: Has a restricted license 'synaptics-killswitch' which is not listed in your LICENSE_FLAGS_ACCEPTED.
You need to agree to a synaptics-killswitch license before you can build the image. Edit build/conf/local.conf and add the line:
# Accept license flags for necessary Broadcom/Raspberry Pi binary blobs (WiFi/Bluetooth drivers) LICENSE_FLAGS_ACCEPTED = "synaptics-killswitch"
Now, run bitbake core-image-base, and it should begin in earnest. The process took almost exactly 3 hours on a moderate pc using four cores. On a Raspberry Pi 5, the process takes closer to six hours and definitely benefits from active cooling. You may see warnings such as:
WARNING: quilt-native-0.67-r0 do_fetch: Failed to fetch URL https://download.savannah.gnu.org/releases/quilt/quilt-0.67.tar.gz, attempting MIRRORS if available
That’s usually not an issue. What you’re looking for is a success message at the end:
NOTE: Tasks Summary: Attempted 5233 tasks of which 0 didn't need to be rerun and all succeeded.
What is Yocto? What is Poky?
Yocto is the set of tools and scripts which build a Linux distro for embedded systems. The Raspberry Pi isn’t really a target platform due to it being closer to a home computer than a System on a Chip deep inside some router, IoT device, or military hardware, but it’s an accessible computer to tinker with. A Raspberry Pi Zero 2 is probably a closer target, but, even so, the default Raspberry Pi Imager and official images are perfectly fine for that platform.
Poky is part hello-world project, part collection of tools from the Yocto project, and part configuration which, by default, builds a minimal Linux operating system we can run using the qemu emulator. For the Raspberry Pi 5, we had to pull the meta-raspberrypi repo which extends Poky’s capabilities to include our target hardware.
What’s next?
In Part 2, I’ll explain where to find the image we built, how to flash it, and how to inspect our distro for configuration and features.