A Mutable Log

Embedded Linux system for Raspberry Pi with Yocto Project

Yocto Project, and OpenEmbedded, have been making news lately as the toolchain to build custom embedded Linux systems. I decided to try and get a working Linux system up and running on a Raspberry Pi 1 Model B+.

The procedure that follows uses the meta-raspberrypi BSP in tandem with Yocto Project poky, on a Ubuntu 20.04 host.

Create a Docker container for the build

If you want to use Docker, here’s how you can bring up a minimal container

# Create a new Docker container
docker run --name yoctopi -it -v ${PWD}:/workdir ubuntu:20.04 /bin/bash
# WE'RE INSIDE THE CONTAINER NOW
# Setup host packages
apt update
apt install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint3 xterm python3-subunit mesa-common-dev libpseudo locales vim
# Add locale en_US.UTF-8
dpkg-reconfigure locales
# Add a new user because bitbake doesn't like to run as root
adduser yoctopi
# Switch to new user
su yoctopi
cd /home/yoctopi

We’ve mapped /workdir in the container to the current directory, in case you want to copy files in or out of the container.

To return to the container in the future

docker start -ai yoctopi
su yoctopi
cd /home/yoctopi

Build

Download the required layers using git

git clone http://git.yoctoproject.org/git/poky
git clone http://git.yoctoproject.org/git/meta-raspberrypi
git clone https://github.com/dv1/meta-gstreamer1.0.git

Initialize the build environment by executing

source poky/oe-init-build-env rpi-build

You can run the same command again if you ever need to setup the environment again in the future.

Append meta-raspberrypi and any other layers to BBLAYERS in conf/bblayers.conf

vi conf/bblayers.conf

After you’re done, conf/bblayers.conf should look like

BBLAYERS ?= " \
  /home/yoctopi/poky/meta \
  /home/yoctopi/poky/meta-poky \
  /home/yoctopi/poky/meta-yocto-bsp \
  /home/yoctopi/meta-gstreamer1.0 \
  /home/yoctopi/meta-raspberrypi \
  "

Set MACHINE to raspberrypi in conf/local.conf

vi conf/local.conf

After you’re done, the relevant portion of conf/local.conf should look like

#MACHINE ?= "genericx86-64"
#MACHINE ?= "edgerouter"
#
# This sets the default machine to be qemux86-64 if no other machine is selected:
MACHINE ??= "raspberrypi"

#
# Where to place downloads

This will build an image suitable to be installed on a Raspberry 1 Model B+. Other available alternatives can be seen under /workdir/meta-raspberrypi/conf/machine/

raspberrypi-cm.conf
raspberrypi-cm3.conf
raspberrypi.conf
raspberrypi0-wifi.conf
raspberrypi0.conf
raspberrypi2.conf
raspberrypi3-64.conf
raspberrypi3.conf
raspberrypi4-64.conf
raspberrypi4.conf

Complete the build by executing

bitbake core-image-base

That should take a while.

Deploy image

After the build is complete, create an SD card using the following commands. If you’ve performed the build in a Docker container, you’ll need to copy the files over to a Linux machine.

sudo apt install bmap-tools
sudo bmaptool copy --bmap tmp/deploy/images/raspberrypi/core-image-base-raspberrypi-20210115193541.rootfs.wic.bmap tmp/deploy/images/raspberrypi/core-image-base-raspberrypi-20210115193541.rootfs.wic.bz2 /dev/sda

Change /dev/sda to the appropriate device on your system.

Boot your Raspberry Pi using the SD card. Command line appears on the HDMI display, or, if configured, over the serial port on the expansion header. You can login as root with an empty password.