My journey into embedded Linux continues! After solidifying the fundamentals of Linux driver development, I’m now diving into board bring-up—an exciting challenge that involves building custom Linux images and configuring bootloaders. This means getting familiar with tools like Yocto, Buildroot, U-Boot, and even UEFI, each playing a role in initializing hardware, loading the kernel, and managing the root filesystem.
Bootlin’s resources, particularly on device tree overlays and embedded Linux fundamentals, have already given me valuable insights into how these technologies fit together.
Among these tools, Das U-Boot (or simply U-Boot) stands out as a powerful and widely used open-source bootloader. It provides robust features for hardware initialization, OS loading, boot management, CLI tools, device tree support, and scripting. While Raspberry Pi’s default firmware offers simplicity, it lacks the fine-grained control necessary for a deep understanding of the boot process.
While the proprietary Raspberry Pi bootloader is unavoidable and necessary for the build to function, integrating U-Boot into my Yocto setup (local.conf setting) still allows me to experiment with its features—gaining deeper insights into hardware initialization and kernel loading.
This post serves as a checkpoint documenting my first successful Yocto build of core-image-base for the Raspberry Pi 4B, including the flashing process and initial boot results. This first build does not include U-boot but will be used in my upcoming IOT project post.
From Yoctoproject.org - "Get Started Guide":
sudo apt install build-essential chrpath cpio debianutils diffstat file gawk gcc git iputils-ping libacl1 liblz4-tool locales python3 python3-git python3-jinja2 python3-pexpect python3-pip python3-subunit socat texinfo unzip wget xz-utils zstd
From the "Yocto for Raspberry Pi" Article:
sudo apt-get 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
The article has graphics-related packages (libegl1-mesa, libsdl1.2-dev) for compatibility with certain applications.
Create Yocto Directory structure:
mkdir yocto
cd yocto
mkdir sources
cd sources
Clone Required Repositories:
git clone git://git.yoctoproject.org/poky
git clone git://git.yoctoproject.org/meta-raspberrypi
git clone https://git.openembedded.org/meta-openembedded
Initialize Build Environment:
Option A -
cd .. # Go back to the 'yocto' directory
. sources/poky/oe-init-build-env
Option B -
cd .. # Go back to the 'yocto' directory
mkdir my-rpi-project # Replace 'my-rpi-project' with your project name
cd my-rpi-project
. ../sources/poky/oe-init-build-env
Important: The oe-init-build-env script sets up the necessary environment variables for Yocto to function. In Option B, the ../ is crucial to point to the correct poky directory. After running oe-init-build-env, your command prompt will change, typically indicating that you are in the Yocto build environment.
Configure bblayers.conf:
This file tells Yocto which metadata layers to use. Edit the conf/bblayers.conf file within your build directory.
nano conf/bblayers.conf
Replace contents with:
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
${TOPDIR}/../sources/poky/meta \
${TOPDIR}/../sources/poky/meta-poky \
${TOPDIR}/../sources/poky/meta-yocto-bsp \
${TOPDIR}/../sources/meta-raspberrypi \
${TOPDIR}/../sources/meta-openembedded/meta-oe \
${TOPDIR}/../sources/meta-openembedded/meta-multimedia \
${TOPDIR}/../sources/meta-openembedded/meta-networking \
${TOPDIR}/../sources/meta-openembedded/meta-python \
"
Configure local.conf:
This file sets the target machine, accepted licenses, and other local settings. Edit the conf/local.conf file within your build directory.
[...]
MACHINE ?= "raspberrypi4"
LICENSE_FLAGS_ACCEPTED = "synaptics-killswitch"
[...]
LICENSE error I came across
Expect long time (hours):
bitbake core-image-base
The built image files are located in the following directory within your build directory:
cd tmp/deploy/images/raspberrypi4/
The `.wic.bz2` file is what we need (e.g., `core-image-base-raspberrypi4.rootfs.wic.bz2` is a symbolic link for latest `core-image-base-raspberrypi4.rootfs-YYYYMMDDHHMMSS.wic.bz2`).
Decompress Image:
bzip2 -d core-image-base-raspberrypi4.rootfs-YYYYMMDDHHMMSS.wic.bz2
It will output a '.wic' file.
Identify your SD card device: User 'lsblk' before and after inserting your SD card
(Incorrectly identifying the device can lead to data loss on your computer's hard drive. Note the device name (e.g., /dev/sdb, /dev/mmcblk0) )
Unmount any mounted partitions:
sudo umount /dev/sdXX
Flash the '.wic' image using 'bmaptool' (replace '/dev/sdX' with the correct device):
sudo bmaptool copy core-image-base-raspberrypi4.rootfs-YYYYMMDDHHMMSS.wic /dev/sdX
sudo bmaptool copy --nobmap core-image-base-raspberrypi4.rootfs-YYYYMMDDHHMMSS.wic /dev/sdb
Eject SD card:
After flashing is complete, safely eject the SD card from your computer.
Insert the SD card into the Raspberry Pi and power on.
Default login is 'root' username and no password.
This first Yocto build is a key step forward in setting up a professional-grade embedded development toolchain. I now have improved hands-on experience configuring and managing meta-layers, and I'm comfortable navigating the command-line interface (CLI) to locate the built image and flash it to the target device.
Moving forward, I'm eager to explore U-Boot's capabilities in greater detail and leverage this lightweight image as the foundation for my upcoming IoT project – a local MQTT broker with ESP32 client nodes. This experience has solidified my enthusiasm for embedded Linux development and empowered me to tackle more ambitious projects in the future. I know this foundational image will be extremely helpful as my software grows in complexity.
Resources:
Yocto Project Get Started:
https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html
Build your own Linux Image for the Raspberry Pi:
https://medium.com/nerd-for-tech/build-your-own-linux-image-for-the-raspberry-pi-f61adb799652