In this chapter, we will cover the basic concept of Yocto/OE in order to integrate a custom application with the Raspberry Pi. We will learn how to generate an SDK for a cross-compiling application. We'll also discuss package management.
After that, we will create our own application and recipe in order to deploy it on the Raspberry Pi through the Yocto Project.
An SDK is a set of tools we can use outside Yocto/OE. These tools generally include a compiler, linker, debugger, libraries, and external headers. This set of compilation tools is called a toolchain. With the Raspberry Pi (or other embedded platforms), the toolchain is often composed of crosstools, which are tools executed on one architecture that produce a binary for use in another architecture.
The following figure depicts the process of cross-compilation:
The Yocto/OE build system can be used to generate a cross-compilation toolchain and matching sysroot
folder for a target system.
With this build system, there are several ways of generating an SDK that conforms to our Raspberry Pi platform.
The meta-toolchain recipe will build a toolchain that matches the Raspberry Pi platform and a basic sysroot (generic SDK) that does not match our target root filesystem. However, this toolchain can be used to build software such as the U-Boot bootloader, the Linux kernel, or simple applications that do not need a sysroot
folder. We can generate this toolchain with the following command:
$ source oe-init-build-env rpi-build $ bitbake meta-toolchain
Once it has been built, we can install it like this:
$ cd poky/rpi-build/tmp/deploy/sdk $ ./poky-eglibc-x86_64-meta-toolchain-qt5-armv6-vfp-toolchain- 1.7.1.sh
The populate task is the best and recommended way of building a toolchain matching the Raspberry Pi platform with a sysroot
folder matching our target root filesystem. We can generate this toolchain with the following command:
$ bitbake rpi-basic-image.bb -c populate_sdk
We can install it with these commands:
$ cd tmp/deploy/sdk $ ./poky-eglibc-x86_64-meta-toolchain-qt-armv6-vfp-toolchain-1.7.1.sh
The following figure is a summary of the populate task, taken directly from the Yocto Project Manual ( http://www.yoctoproject.org/docs/current/ref-manual/ref-manual.html#sdk-dev-environment ):
The meta-toolchain-qt
toolchain is just an extension of meta-toolchain
and includes support for compiling Qt applications (graphical or non-graphical). We can generate this toolchain with the following command:
$ bitbake meta-toolchain-qt
Once it has been built, we can install it with these commands:
$ cd tmp/deploy/sdk $ ./poky-eglibc-x86_64-meta-toolchain-qt-armv6-vfp-toolchain-1.7.1.sh
This toolchain is just an extension of meta-toolchain-qt
, including support for compiling Qt5 applications. We can generate it with the following command:
$ bitbake meta-toolchain-qt5
Once it has been built, we can install it with these commands:
$ cd tmp/deploy/sdk $ ./poky-eglibc-x86_64-meta-toolchain-qt5-armv6-vfp-toolchain- 1.7.1.sh
The SDK can be designed for use on a 32-bit or 64-bit Linux distribution, and that depends on the host architecture in which the SDK is generated. The selection is made by setting the SDKMACHINE
variable (in conf/local.conf
), which can take i686
or x86_64
as values, like this, for example:
SDKMACHINE? = "X86_64"
In order to validate the proper functioning of our toolchain, we can try to compile an application.
The first thing to do is source the environment variable for our toolchain. Use either of these commands:
$ source /opt/poky/1.7.1/environment-setup-armv6-vfp poky-linux- gnueabi $ . ./opt/poky/1.7.1/environment-setup-armv6-vfp poky-linux-gnueabi
After this, our toolchain is in our system PATH
variable, and we can take a look at all of the tools in the toolchain:
$ arm-poky-linux-gnueabi-arm-poky-linux-gnueabi-addr2line arm-poky-linux-gnueabi-elfedit arm-poky-linux-gnueabi-gcc-ranlib arm-poky-linux-gnueabi-ld.bfd arm-poky-linux-gnueabi-readelf arm-poky-linux-gnueabi-ar arm-poky-linux-gnueabi-g++ arm-poky-linux-gnueabi-gcov arm-poky-linux-gnueabi-nm arm-poky-linux-gnueabi-size arm-poky-linux-gnueabi-as arm-poky-linux-gnueabi-gcc arm-poky-linux-gnueabi-gdb arm-poky-linux-gnueabi-objcopy arm-poky-linux-gnueabi-strings arm-poky-linux-gnueabi-c++filt arm-poky-linux-gnueabi-gcc-ar arm-poky-linux-gnueabi-gprof arm-poky-linux-gnueabi-objdump arm-poky-linux-gnueabi-strip arm-poky-linux-gnueabi-cpp arm-poky-linux-gnueabi-gcc-nm arm-poky-linux-gnueabi-ld arm-poky-linux-gnueabi-ranlib
We can find our compiler (arm-poky-linux-gnueabi-gcc
or arm-poky-linux-gnueabi-g++
for C++ applications), our debugger (arm-poky-linux-gnueabi-gdb
), some binary tools (GNU Binary Utilities), and so on.
Now, we can compile our first application with the external toolchain:
$ ${CC} -o hello_world_packt hello_world_packt.c $ file hello_world_packthello_world_packt: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=1c2b89895d89b1868884295756214d609748f2c2, not stripped
18.222.35.77