Exploring yocto with Raspberry Pi [Part 1]
The yocto project has a goal to standardize the way custom Linux distributions are built. I’ve heard rumors it can be used to build both Zephyr and cross compiled Docker images. This tutorial will cover the bare minimum steps for getting a bootable image for the Raspberry pi which can serve for future yocto exploration.
yocto is an umbrella project that unifies all the tooling needed for building a custom Linux distribution. It’s a new brand name for tools that existed before it.
OpenEmbedded is a set of configuration files that define how components of the systems should be treated (downloaded, configured, build, installed… etc).
Bitbake is a python application responsible for executing the actions defined by OpenEmbedded metadata files.
poky consists of generally useful OpenEmbedded defaults packed together with Bitbake. This is our starting point.
You know how to figure out what device represents your sd card (/dev/sdX).
You know how to connect to the serial port of the Raspberry.
Install dependencies and get sources
~$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \ build-essential chrpath socat libsdl1.2-dev xterm ~$ git clone -b morty --single-branch http://git.yoctoproject.org/git/poky ~$ cd poky ~/poky$ git clone -b morty http://git.yoctoproject.org/git/meta-raspberrypi
After installing dependencies we clone poky from its repo. Inside the poky directory we clone
meta-raspberrypi. It contains all the metadata files required by bitbake to create a Raspberyr pi image that can be flashed to the SD card. In terms of yocto terminology,
meta-raspberrypi is a layer.
Notice that both repositories are checked to the same branch
Init the project and set the config files
~/poky$ export POKY_DIR=$PWD ~/poky$ source oe-init-build-env rpi-build ~/poky/rpi-build$ sed -i "11 a\ $POKY_DIR/meta-raspberrypi \\\\" conf/bblayers.conf ~/poky/rpi-build$ sed -i 's/MACHINE ??= "qemux86"/MACHINE ??= "raspberrypi2"/' conf/local.conf
The export of
POKY_DIR enables copy pasting tutorial commands
regardless of how your home directory is named. It isn’t poky related.
source oe-init-build-env rpi-build initialized the project and moves us to the project directory.
sed lines edit the project metadata files
conf/local.conf to specify to bitbake to use
and to build for raspberrypi2. It’s the same as manually changing those files with a text editor.
Build the image, deploy and boot
~/poky/rpi-build$ bitbake rpi-hwup-image ~/poky/rpi-build$ sudo dd if=tmp/deploy/images/raspberrypi2/rpi-hwup-image-raspberrypi2.rpi-sdimg of=/dev/sdX bs=4MB ~/poky/rpi-build$ sudo picocom /dev/ttyUSB0 -b 115200
bitbake rpi-hwup-image will build the Hardware up image as stated in the layer documentation.
All the built images are located under
tmp/depoly/images. We use the image
rpi-hwup-image-raspberrypi2.rpi-sdimg to the sd card, plug the card into the Pi and power it up. Change the
/dev/sdX to whatever represents your SD card.
To see whats going on, we’re connecting to the Pi with a TTL-232R-3V3 cable. It’s detected as
/dev/ttyUSB0 on the my machine.