Build Embedded Linux System with Yocto Project

1 minute read

Prepare for build yocto project

sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev python3-subunit mesa-common-dev zstd liblz4-tool file locales libacl1 lz4
git clone -b kirkstone git://git.yoctoproject.org/poky.git
git clone -b kirkstone https://github.com/openembedded/meta-openembedded
git clone -b kirkstone https://github.com/agherzan/meta-raspberrypi

Customize configuration

Add required layers:

source poky/oe-init-build-env build-raspberrypi3
bitbake-layers add-layer ../meta-openembedded/meta-oe
bitbake-layers add-layer ../meta-raspberrypi

Then add following to conf/local.conf

DL_DIR ?= "/opt/dl/poky/downloads/"

ENABLE_UART = "1"
RPI_EXTRA_CONFIG = "dtoverlay=disable-bt"

EXTRA_IMAGE_FEATURES += "ssh-server-dropbear"

SDIMG_ROOTFS_TYPE="ext4"
IMAGE_FSTYPES="wic.xz rpi-sdimg"
# Download all the packages first
DISTRO=poky MACHINE=raspberrypi3 bitbake core-image-minimal --runall fetch

# Build minimal image
DISTRO=poky MACHINE=raspberrypi3 bitbake core-image-minimal

# Build for 64-bit currently will fail
DISTRO=poky MACHINE=raspberrypi3-64 bitbake core-image-minimal

From the output we can see there are 3553 tasks for building the final image:

Currently  6 running tasks (3477 of 3553)  97% |############################################################################################   |

As the build process completed, the image can be found here:

65M	tmp/deploy/images/raspberrypi3/core-image-minimal-raspberrypi3-20240126221511.rootfs.rpi-sdimg

Flash with below command or balenaEtcher:

xzcat tmp/deploy/images/raspberrypi3/core-image-minimal-raspberrypi3.wic.xz | sudo dd of=/dev/sdc

The boot log was uploaded to gitlab.

Build SDK

DISTRO=poky MACHINE=raspberrypi3 bitbake core-image-minimal -c populate_sdk

Install yocto sdk without interruption:

./tmp/deploy/sdk/poky-glibc-x86_64-core-image-minimal-cortexa7t2hf-neon-vfpv4-raspberrypi3-toolchain-4.0.15.sh -yd ~/.local/sdk/
Poky (Yocto Project Reference Distro) SDK installer version 4.0.15
==================================================================
You are about to install the SDK to "/home/fdbai/.local/sdk". Proceed [Y/n]? Y
Extracting SDK...............................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /home/fdbai/.local/sdk/environment-setup-cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi
arm-poky-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-poky-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/fdbai/.local/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/11.4.0/lto-wrapper
Target: arm-poky-linux-gnueabi
Configured with: ../../../../../../work-shared/gcc-11.4.0-r0/gcc-11.4.0/configure --build=x86_64-linux --host=x86_64-pokysdk-linux --target=arm-poky-linux-gnueabi --prefix=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr --exec_prefix=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr --bindir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi --sbindir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi --libexecdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi --datadir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share --sysconfdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/etc --sharedstatedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/com --localstatedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/var --libdir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi --includedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/include --oldincludedir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/include --infodir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share/info --mandir=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/x86_64-pokysdk-linux/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/home/fdbai/grecale/projects/raspberrypi3b/build-raspberrypi3/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-arm/11.4.0-r0/recipe-sysroot --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-multilib --enable-default-pie --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=arm-poky-linux-gnueabi- --without-local-prefix --disable-install-libiberty --disable-libssp --enable-libitm --enable-lto --disable-bootstrap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl --with-gxx-include-dir=/not/exist/usr/include/c++/11.4.0 --with-build-time-tools=/home/fdbai/grecale/projects/raspberrypi3b/build-raspberrypi3/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-arm/11.4.0-r0/recipe-sysroot-native/usr/arm-poky-linux-gnueabi/bin --with-sysroot=/not/exist --with-build-sysroot=/home/fdbai/grecale/projects/raspberrypi3b/build-raspberrypi3/tmp/work/x86_64-nativesdk-pokysdk-linux/gcc-cross-canadian-arm/11.4.0-r0/recipe-sysroot --with-plugin-ld=ld --enable-poison-system-directories --disable-static --enable-nls --with-glibc-version=2.28 --enable-initfini-array
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (GCC)