The Raspberry Pi is low-cost single board computer(SBC) created by the Raspberry Pi Foundation in 2012. This SBC was initialy created for educational purposes and by the end of 2019 over 30M pieces were sold. At this moment 5 different models exits: Raspberry Pi Zero, Raspberry Pi, Raspberry Pi 2, Raspberry Pi 3 and Raspberry Pi 4.

The Yocto Project is a open source project that simplifies the daunting task of creating a custom embedded Linux. The Yocto Project provides tools and a complete set of configuration files for easing this process.

This tutorial will focus on building a linux image for the Raspberry Pi using the Yocto Project

1. Required

2. Dependencies

The Yocto Project requires some dependencies before the build can be started on Ubuntu 20.04

sudo apt-get install git-core build-essential gawk chrpath texinfo diffstat python3 python3-distutils

3. Clone repositories

Let’s start with cloning the poky and meta-raspberrypi repositories. Zeus is the name of the latest version.

mkdir yocto
cd yocto
git clone -b zeus git://git.yoctoproject.org/poky.git
cd poky
git clone -b zeus git://git.yoctoproject.org/meta-raspberrypi

4. Init the build

Create the build directory and initialize the build.

. oe-init-build-env build

5. Change the build configuration

Edit conf/local.conf from the build directory and add the following. Read the following for more information.

BB_NUMBER_THREADS = "4"
PARALLEL_MAKE = "-j 4"
MACHINE ?= "raspberrypi0-wifi" # for Raspberry Pi Zero build
GPU_MEM = "16"

Edit conf/bblayers.conf from the build directory and add the meta-raspberrypi layer.

BBLAYERS ?= " \
  /home/user/yocto/poky/meta \
  /home/user/yocto/poky/meta-yocto \
  /home/user/yocto/poky/meta-yocto-bsp \
  /home/user/yocto/poky/meta-raspberrypi
 "

6. Build

We are now ready to start the build. Without modification the meta-raspberryi layer allows us to build two images: core-image-minimal and and core-image-base. The build time depends on your build machine and internet connection.

bitbake core-image-minimal

7. Flash

The build output can be located at: /home/user/yocto/poky/build/tmp/deploy/images/raspberrypi0-wifi

The image to install on the sdcard: core-image-minimal-raspberrypi0-wifi.rpi-sdimg

Insert sdcard and determine name:

user@ubuntu:~$ dmesg
[ 2724.054584] usb 1-1: new high-speed USB device number 2 using ehci-pci
[ 2724.310705] usb 1-1: New USB device found, idVendor=05e3, idProduct=0716, bcdDevice=97.44
[ 2724.310708] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=2
[ 2724.310716] usb 1-1: Product: USB Storage
[ 2724.310717] usb 1-1: SerialNumber: 000000009744
[ 2724.400226] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 2724.402598] scsi host33: usb-storage 1-1:1.0
[ 2725.598411] sd 33:0:0:2: [sdd] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[ 2725.770045] sd 33:0:0:2: [sdd] Write Protect is off
[ 2725.770050] sd 33:0:0:2: [sdd] Mode Sense: 03 00 00 00
[ 2725.782617] sd 33:0:0:2: [sdd] No Caching mode page found
[ 2725.782622] sd 33:0:0:2: [sdd] Assuming drive cache: write through
[ 2725.914036]  sdd: sdd1

The flash disk name can be seen in the dmesg output: /dev/sdd We are now ready to flash the image.

cd /home/user/yocto/poky/build/tmp/deploy/images/raspberrypi0-wifi/

sudo dd if=/dev/zero of=/dev/sdd bs=512 count=1

sudo dd if=core-image-minimal-raspberrypi0-wifi.rpi-sdimg of=/dev/sdd bs=8192

sudo sync

8. Boot

Insert the flashed sdcard and startup the raspberrypi.