If you are looking to boot your custom-made embedded Linux, this article is crafted to provide guidance to those looking to familiarize themselves with the Yocto Project, with a simple exercise using Raspberry Pi 4
What are Yocto and Buildroot?
Yocto and Buildroot are embedded system build frameworks that enable the creation of customized Linux systems for embedded devices. They offer flexibility and automation in image setup and construction. Yocto tends to be more robust and intricate, while Buildroot is simpler and quicker to use.
Why are Recipes key in Yocto
The secret sauce in a standout Yocto image? Recipes. Think of recipes as the blueprints, detailing how each software ingredient should be mixed, baked, and served (built and configure). They offer a phenomenal level of control, ensuring your final dish (or in this case, image) is tailored for your project.
Yocto Alternatives: Buildroot a simple approach
For those looking for a more straightforward solution, there’s Buildroot. Buildroot focuses on creating embedded systems and is renowned for its simplicity and user-friendliness. If you’re new to building embedded systems, it can be a great starting point. However, it’s worth pointing out that Buildroot may have certain limitations when it comes to advanced customization and automation.
The Yocto Challenge: Sweat, Savor, and Success
While the Yocto Project might present a steeper learning curve compared to Buildroot, it boasts a series of notable advantages. With Yocto, you can leverage tools such as U-Boot, the Linux kernel, and more to have even finer control over your embedded system. Automation is among Yocto’s primary strengths, granting you comprehensive control over your images and recipes. This means you’re always in control, masterfully shaping your images and recipes.
Get Your Hands Dirty: Building Yocto Kirkstone for Raspberry Pi 4
Ready to roll up your sleeves? Let’s bake a custom image for your Raspberry Pi 4.
Package Preparation and Installation
Before commencing the custom image creation for the Raspberry Pi 4 using Yocto, ensure your main directory isn’t encrypted with eCryptFS. OpenEmbedded doesn’t support eCryptFS file systems due to filename length constraints.
Next, install the necessary dependencies, including the lz4
package, by executing the command:
sudo apt-get install lz4 bc build-essential chrpath cpio diffstat gawk git python3 texinfo wget gdisk libssl-dev
Preparation for Raspberry Pi 4
To add support for Raspberry Pi 4 to our project, we need to include the meta-raspberrypi
To ensure our Pi 4 gets the love it deserves, we’ll fold in the layer meta-raspberrypi
. It’s the special touch that offers support for all Raspberry Pi boards, and yes, that includes the Raspberry Pi 4. Grab the layer right here
Next, let’s prep our base by downloading Poky:
git clone git://git.yoctoproject.org/poky -b kirkstone
With that done, let’s set up our build directory and
To add support for Raspberry Pi 4 to our project, we need to include the meta-raspberrypi
To ensure our Pi 4 gets the love it deserves, we’ll fold in the layer meta-raspberrypi
. It’s the special touch that offers support for all Raspberry Pi boards, and yes, that includes the Raspberry Pi 4. Grab the layer right here
Next, let’s prep our base by downloading Poky:
git clone git://git.yoctoproject.org/poky -b kirkstone
With that done, let’s set up our build directory and sprinkle in the BSP layer with:
source poky/oe-init-build-env build bitbake-layers layerindex-fetch meta-raspberrypi
- Shell Environment Setup for Compilations
Now, you’re set to run the ‘bitbake <target>’ command for compiling. Common targets include:
core-image-minimal
core-image-full-cmdline
core-image-sato
core-image-weston
meta-toolchain
meta-ide-support
You can also run qemu images with commands like ‘runqemu qemux86’. Some other handy commands include:
- ‘devtool’ and ‘recipetool’ for common recipe tasks.
- ‘bitbake-layers’ for common layer tasks.
- ‘oe-pkgdata-util’ for standard target package tasks.
Lastly, after setting up the build directory and BSP layers, initiate the specific build for your Raspberry Pi 4 with:
MACHINE=raspberrypi4 bitbake core-image-full-cmdline
The MACHINE variable can be adjusted based on your desired board or set in build/conf/local.conf
.
This command will construct the custom image for your Raspberry Pi 4.
The Grand Reveal: Booting Raspberry Pi 4
Voila! Once your baking session concludes, you’ll find your fresh image nestled in the directory build/tmp/deploy/images/raspberrypi4/. Look for the file core-image-full-cmdline-raspberrypi4.wic.bz2.
Before you transfer this masterpiece to an SD card, ensure you’re writing to the right device. Double-check, and maybe even triple-check. We wouldn’t want any burnt pies, would we?
You can use the “dd” utility to transfer:
bashCopy code
bzcat core-image-full-cmdline-raspberrypi4.wic.bz2 | sudo dd of=/dev/<media>
After copying the content to the SD card, slot it into the SD card slot, connect the HDMI cable, and power up the machine. It should boot up seamlessly.
Alternatively, without using a command, flash this image onto a microSD card using Etcher and boot it on your Raspberry Pi 4:
- Insert a microSD card into your host machine.
- Launch Etcher.
- Click on “Flash from file” in Etcher.
- Locate and open the “wic.bz2” image you built for Raspberry Pi 4.
- Select the destination in Etcher.
- Pick the microSD card inserted in Step 1.
- Click “Flash from Etcher” to write the image.
- Eject the microSD card post-writing by Etcher.
- Insert the microSD card into your Raspberry Pi 4.
- Power up the Raspberry Pi 4 using its USB-C port.
Confirm your Pi 4 has booted successfully by connecting it to Ethernet and watching the network activity lights flicker.