Objective: This writeup will guide you on how to create a custom minimal image for Raspberry Pi 4 board using the Yocto build tool. More capability and flesh will be added to the image in subsequent writeups.
Recommended prerequisite articles to read:
In this writeup, we will explore building a console-only image for Raspberry Pi 4. This image recipe is one of the default Yocto project image recipes, called core-image-base.
If you have reviewed the linked prerequisite article, you will have an appreciation for the need of proper directory structure. I have a directory where all the builds for different boards are executed. In this directory, we will make a new directory to hold the various raspberry pi variants and specifically the pi 4 as shown here:
The first step is to fork the meta raspberrypi repository. This forms the basis on which our image will be built upon. It is best practice to fork meta layers/repositories into the main poky directory as shown here:
At this point, we can explore the contents of the meta-raspberrypi directory as shown next:
We then get to the rpi_4 directory to commence the build process by invoking the source command as shown below:
This creates a build directory and a conf subdirectory. At this stage, we want to go with default settings as much as possible. There are two important things to do at this stage. One is to include the meta-raspberrypi layer into the bblayers_conf file, which was created into the build/conf path.
The other important thing is to specify the machine (board) that we are targeting by editing the local.conf file located in the build/conf path. As a best practice, I store all my builds’ downloads into a single location. Hence, we can edit the local.conf file to point to the shared downloads directory.
We can now issue the bitbake command for building an image. The image we want to build is the core-image-base which is one of the default image recipes that come with the Yocto project.
Depending on your internet speed, computer speed and previous builds, this build stage can take as long as more than 3 hours. You will be able to monitor the progress as shown below:
On successful build, the image created will be located in the build/tmp/deploy/images as shown below:
Since we will be using an SD card as the bootable storage, the image we will burn into the SD card is the .rpi-sdimg. The command below accomplishes this (the SD card in this particular case is recognized as /dev/sdb in my Linux host machine).
On booting the board with this image, a terminal console is available. Since it is a console-only image, we will need to add more image features and packages in subsequent builds to enable graphical user interface.