Reader small image

You're reading from  Embedded Linux Projects Using Yocto Project Cookbook

Product typeBook
Published inMar 2015
Publisher
ISBN-139781784395186
Edition1st Edition
Right arrow
Author (1)
Alex Gonzalez
Alex Gonzalez
author image
Alex Gonzalez

Alex González is a software engineering supervisor at Digi International and product owner of the Digi Embedded Yocto distribution. He started working professionally with embedded systems in 1999 and the Linux kernel in 2004, designing products for voice and video over IP networks, and followed his interests into machine-to-machine (M2M) technologies and the Internet of Things. Born and raised in Bilbao, Spain, Alex has an electronic engineering degree from the University of the Basque Country and he received his MSc in communication systems from the University of Portsmouth.
Read more about Alex Gonzalez

Right arrow

Chapter 4. Application Development

In this chapter, we will cover the following recipes:

  • Introducing toolchains

  • Preparing and using an SDK

  • Using the Application Development Toolkit

  • Using the Eclipse IDE

  • Developing GTK+ applications

  • Using the Qt Creator IDE

  • Developing Qt applications

  • Describing workflows for application development

  • Working with GNU make

  • Working with the GNU build system

  • Working with the CMake build system

  • Working with the SCons builder

  • Developing with libraries

  • Working with the Linux framebuffer

  • Using the X Windows system

  • Using Wayland

  • Adding Python applications

  • Integrating the Oracle Java Runtime Environment

  • Integrating the Open Java Development Kit

  • Integrating Java applications

Introduction


Dedicated applications are what define an embedded product, and Yocto offers helpful application development tools as well as the functionality to integrate with popular Integrated Development Environments (IDE) like Eclipse and Qt Creator. It also provides a wide range of utility classes to help in the integration of finished applications into the build system and the target images.

This chapter will introduce the IDEs and show us how they are used to build and debug C and C++ applications on real hardware, and will explore application development, including graphical frameworks and Yocto integration, not only for C and C++ but also Python and Java applications.

Introducing toolchains


A toolchain is a set of tools, binaries, and libraries used to build applications to run on a computer platform. In Yocto, the toolchains are based on GNU components.

Getting ready

A GNU toolchain contains the following components:

  • Assembler (GNU as): This is part of the binutils package

  • Linker (GNU ld): This is also part of the binutils package

  • Compiler (GNU gcc): This has support for C, C++, Java, Ada, Fortran, and Objective C

  • Debugger (GNU gdb): This is the GNU debugger

  • Binary file tools (objdump, nm, objcopy, readelf, strip, and so on): These are part of the binutils package.

These components are enough to build bare metal applications, bootloaders like U-Boot, or operating systems like the Linux kernel, as they don't need a C library and they implement the C library functions they need. However, for Linux user space applications, a POSIX-compliant C library is needed.

The GNU C library, glibc, is the default C library used in the Yocto project. Yocto is introducing support...

Preparing and using an SDK


The Yocto build system can be used to generate a cross-compilation toolchain and matching sysroot for a target system.

Getting ready

We will use the previously used wandboard-quad build directory and source the setup-environment script as follows:

$ cd /opt/yocto/fsl-community-bsp/
$ source setup-environment wandboard-quad

How to do it...

There are several ways to build an SDK with the Yocto build system:

  • The meta-toolchain target.

    This method will build a toolchain that matches your target platform, and a basic sysroot that will not match your target root filesystem. However, this toolchain can be used to build bare metal software like the U-Boot bootloader or the Linux kernel, which do not need a sysroot. The Yocto project offers downloadable sysroot for the supported hardware platforms. You can also build this toolchain yourself with:

    $ bitbake meta-toolchain
    

    Once built, it can be installed with:

    $ cd tmp/deploy/sdk
    $ ./poky-glibc-x86_64-meta-toolchain-cortexa9hf...

Using the Application Development Toolkit


The ADT is an SDK installation script that installs the following for Poky-supported hardware platforms:

  • A prebuilt cross-compilation toolchain, as explained previously

  • A sysroot that matches the core-image-sato target image

  • The QEMU emulator

  • Other development user space tools used for system profiling (these will be discussed in the following chapters)

Getting ready

To install the ADT, you can choose either of the following options:

  • Download a precompiled tarball from the Yocto project downloads site with the following command:

    $ wget http://downloads.yoctoproject.org/releases/yocto/yocto- 1.7.1/adt-installer/adt_installer.tar.bz2
    
  • Build one using your Yocto build directory.

The ADT installer is an automated script to install precompiled Yocto SDK components, so it will be the same whether you download the prebuilt version or you build one yourself.

You can then configure it before running it to customize the installation.

Note that it only makes sense to...

Using the Eclipse IDE


Eclipse is an open source IDE that is written mostly in Java and released under the Eclipse Public License (EPL). It can be extended using plugins, and the Yocto project releases a Yocto plugin that allows us to use Eclipse for application development.

Getting ready

Yocto 1.7 provides Eclipse Yocto plugins for two different Eclipse versions, Juno and Kepler. They can be downloaded at http://downloads.yoctoproject.org/releases/yocto/yocto-1.7.1/eclipse-plugin/. We will use Kepler 4.3, as it is the newest. We will start with the Eclipse Kepler standard edition and install all the required plugins we need.

It is recommended to run Eclipse under Oracle Java 1.7, although other Java providers are supported. You can install Oracle Java 1.7 from Oracle's web site, https://www.java.com/en/, or using a Ubuntu Java Installer PPA, https://launchpad.net/~webupd8team/+archive/ubuntu/java. The latter will integrate Java with your package management system, so it's preferred. To install...

Developing GTK+ applications


This recipe will show how to build, run, and debug a graphical GTK+ application using the Eclipse IDE.

Getting ready

  1. Add the eclipse-debug feature to your project's conf/local.conf file as follows:

    EXTRA_IMAGE_FEATURES += "eclipse-debug"
  2. Build a core-image-sato target image as follows:

    $ cd /opt/yocto/fsl-community-bsp/
    $ source setup-environment wandboard-quad
    $ bitbake core-image-sato
    
  3. Build a core-image-sato toolchain as follows:

    $ bitbake -c populate_sdk core-image-sato
    
  4. Install the toolchain as follows:

    $ cd tmp/deploy/sdk
    $ ./poky-glibc-x86_64-core-image-sato-cortexa9hf-vfp-neon- toolchain-1.7.1.sh
    

Before launching the Eclipse IDE, we can check whether we are able to build and launch a GTK application manually. We will build the following GTK+ hello world application:

The following is a code for gtk_hello_world.c:

#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
  GtkWidget *window;
  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL...

Using the Qt Creator IDE


Qt Creator is a multiplatform IDE part of the Qt Application Development Framework SDK. It is the IDE of choice for Qt application development and is available with multiple licenses, including GPLv3, LGPLv2, and commercial licenses as well.

Getting ready

  1. Download and install the Qt Creator 3.3.0 for your host from the Qt project downloads website. For downloading and installing an x86_64 Linux host, you can use the following commands:

    $ wget http://download.qt.io/official_releases/qtcreator/3.3/3.3.0/qt -creator-opensource-linux-x86_64-3.3.0.run
    $ chmod u+x qt-creator-opensource-linux-x86_64-3.3.0.run
    $ ./qt-creator-opensource-linux-x86_64-3.3.0.run
    
  2. Build a toolchain that is ready to develop Qt applications with the following:

    $ cd /opt/yocto/fsl-community-bsp/
    $ source setup-environment wandboard-quad
    $ bitbake meta-toolchain-qt
    
  3. Install it as follows:

    $ cd tmp/deploy/sdk
    $ ./poky-glibc-x86_64-meta-toolchain-qt-cortexa9hf-vfp-neon- toolchain-qt-1.7.1.sh
    

How to do...

Developing Qt applications


This recipe will show how to build, run, and debug a graphical Qt application using Qt Creator.

Getting ready

Before launching Qt Creator, we check whether we are able to build and launch a Qt application manually. We will build a Qt hello world application.

Here is the code for qt_hello_world.cpp:

#include <QApplication>
#include <QPushButton>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QPushButton hello("Hello world!");

     hello.show();
     return app.exec();
 }

To build it, we use the meta-toolchain-qt installed as described previously:

$ source /opt/poky/1.7.1/environment-setup-cortexa9hf-vfp-neon-poky- linux-gnueabi
$ qmake -project
$ qmake
$ make

This uses qmake to create a project file and a Makefile file with all the relevant code files in the folder.

To run it, we first need to build a filesystem with Qt support. We first prepare the environment as follows:

$ cd /opt/yocto/fsl-community-bsp/
$ source setup-environment...

Describing workflows for application development


The workflows for application development are similar to the ones we already saw for U-Boot and the Linux kernel back in Chapter 2, The BSP Layer.

How to do it...

We will see how the following development workflows are applied to application development:

  • External development

  • Working directory development

  • External source development

How it works...

External development

This is what we have been using on the recipes we saw before when building from the command line using a standalone toolchain, and also when using both the Eclipse and Qt Creator IDEs. This workflow produces binaries that have to be individually copied to the hardware to run and debug. It can be used in conjunction with the other workflows.

Working directory development

When the application is being built by the Yocto build system, we use this workflow to debug sporadic problems. However, it is not the recommended workflow for long developments. Note, though, that it is usually the first...

Working with GNU make


GNU make is a make implementation for Linux systems. It is used by a wide variety of open source projects, including the Linux kernel. The build is managed by a Makefile, which tells make how to build the source code.

How to do it...

Yocto recipes inherit base.bbclass and hence their default behavior is to look for a Makefile, makefile, or GNU Makefile and use GNU make to build the package.

If your package already contains a Makefile, then all you need to worry about are the arguments that need to be passed to make. Make arguments can be passed using the EXTRA_OEMAKE variable, and a do_install override that calls the oe_runmake install needs to be provided, otherwise an empty install is run.

For example, the logrotate recipe is based on a Makefile and looks as follows:

SUMMARY = "Rotates, compresses, removes and mails system log files"
SECTION = "console/utils"
HOMEPAGE = "https://fedorahosted.org/logrotate/"
LICENSE = "GPLv2"

DEPENDS="coreutils popt"

LIC_FILES_CHKSUM...

Working with the GNU build system


A Makefile is a good solution when you are always going to build and run your software on the same system, and things like glibc and gcc versions and the available library versions are known. However, most software need to be built and run in a variety of systems.

Getting ready

The GNU build system, or autotools, is a set of tools whose aim is to create a Makefile for your software in a variety of systems. It's made up of three main tools:

  • autoconf: This parses the contents of a configure.ac file that describes the source code to be built and creates a configure script. This script will then be used to generate the final Makefile.

  • automake: This parses the contents of a Makefile.am file and converts it into a Makefile.in file. This is then used by the configure script generated earlier to obtain a config.status script that gets automatically executed to obtain the final Makefile.

  • libtools: This manages the creation of both static and dynamic libraries.

How to...

Working with the CMake build system


The GNU make system is a great tool when you build exclusively for Linux systems. However, some packages are multiplatform and need a way to manage Makefile files on different operating systems. CMake is a cross-platform build system that can work not only with GNU make, but also Microsoft Visual Studio and Apple's Xcode.

Getting ready

The CMake tool parses the CMakeLists.txt files in every directory to control the build process. An example CMakeLists.txt file to compile the hello world example follows:

cmake_minimum_required(VERSION 2.8.10)
project(helloworld)
add_executable(helloworld helloworld.c)
install(TARGETS helloworld RUNTIME DESTINATION bin)

How to do it...

The Yocto build system also contains classes with the required knowledge to build CMake packages. All your recipe needs to do is to inherit the cmake class and configure the arguments to be passed to the configure script in the EXTRA_OECMAKE variable. Usually, the CMake system understands how to...

Working with the SCons builder


SCons is also a multiplatform build system written in Python, with its configuration files also written in the same language. It also includes support for Microsoft Visual Studio among other features.

Getting ready

SCons parses the SConstruct files, and by default it does not propagate the environment into the build system. This is to avoid build issues caused by environment differences. This is a complication for Yocto, as it configures the environment with the cross-compilation toolchain settings.

SCons does not define a standard way to support cross-compilation, so every project will implement it differently. For a simple example as the hello world program, we can just initialize the CC and PATH variables from the external environment as follows:

import os
env = Environment(CC = os.environ['CC'],
                  ENV = {'PATH': os.environ['PATH']})
env.Program("helloworld", "helloworld.c")

How to do it...

The Yocto build system also contains classes with the...

Developing with libraries


Most applications make use of shared libraries, which saves system memory and disk space, as they are shared between different applications. Modularizing code into libraries also allows for easier versioning and code management.

This recipe will explain how to work with both static and shared libraries in Linux and Yocto.

Getting ready

By convention, library files start with the lib prefix.

There are basically two library types:

  • Static libraries (.a): When the object code is linked and becomes part of the application

  • Dynamic libraries (.so): Linked at compile time but not included in the application, so they need to be available at runtime. Multiple applications can share a dynamic library so they need less disk space.

Libraries are placed in the following standard root filesystem locations:

  • /lib: Libraries required for startup

  • /usr/lib: Most system libraries

  • /usr/local/lib: Non-system libraries

Dynamic libraries follow certain naming conventions on running systems so that...

Working with the Linux framebuffer


The Linux kernel provides an abstraction for the graphical hardware in the form of framebuffer devices. These allow applications to access the graphics hardware through a well-defined API. The framebuffer is also used to provide a graphical console to the Linux kernel, so that it can, for example, display colors and a logo.

In this recipe, we will explore how applications can use the Linux framebuffer to display graphics and video.

Getting ready

Some applications, especially in embedded devices, are able to access the framebuffer by mapping the memory and accessing it directly. For example, the gstreamer framework is able to work directly over the framebuffer, as is the Qt graphical framework.

Qt is a cross-platform application framework written in C++ and developed both by Digia, under the Qt company name, and the open source Qt project community.

For Qt applications, Poky provides a qt4e-demo-image and the FSL community BSP provides a qte-in-use-image, both...

Using the X Windows system


The X Windows system provides the framework for a GUI environment – things like drawing and moving windows on the display and interacting with input devices like the mouse, the keyboard, and touchscreens. The protocol version has been X11 for over two decades, so it also known as X11.

Getting ready

The reference implementation for the X Windows system is the X.Org server, which is released under permissive licenses such as MIT. It uses a client/server model, with the server communicating with several client programs, serving user input, and accepting graphical output. The X11 protocol is network transparent so that the clients and the server may run on different machines, with different architectures and operating systems. However, mostly, they both run on the same machine and communicate using local sockets.

User interface specifications, such as buttons or menu styles, are not defined in X11, which leaves it to other window manager applications that are usually...

Using Wayland


Wayland is a display server protocol that is intended to replace the X Window system, and it is licensed under the MIT license.

This recipe will provide an overview of Wayland, including some key differences with the X Window system, and will show how to make use of it in Yocto.

Getting ready

The Wayland protocol follows a client/server model in which clients are the graphical applications requesting the display of pixel buffers on the screen, and the server, or compositor, is the service provider that controls the display of these buffers.

The Wayland compositor can be a Linux display server, an X application, or a special Wayland client. Weston is the reference Wayland compositor in the Wayland project. It is written in C and works with the Linux kernel APIs. It relies on evdev for the handling of input events.

Wayland uses Direct Rendering Manager (DRM) in the Linux kernel and does not need something like an X server. The client renders the window contents to a buffer shared...

Adding Python applications


In Yocto 1.7, Poky has support for building both Python 2 and Python 3 applications, and includes a small set of Python development tools in the meta/recipes-devtools/python directory.

A wider variety of Python applications are available in the meta-python layer included as part of meta-openembedded, which you can add to your conf/bblayers.conf file if you want to.

Getting ready

The standard tool for packaging Python modules is distutils, which is included for both Python 2 and Python 3. Poky includes the distutils class (distutils3 in Python 3), which is used to build Python packages that use distutils. An example recipe in meta-python that uses the distutils class is meta-python/recipes-devtools/python/python-pyusb_1.0.0a2.bb.

SUMMARY = "PyUSB provides USB access on the Python language"
HOMEPAGE = "http://pyusb.sourceforge.net/"
SECTION = "devel/python"
LICENSE = "BSD"
LIC_FILES_CHKSUM = "file://LICENSE;md5=a53a9c39efcfb812e2464af14afab013"
DEPENDS = "libusb1"
PR...

Integrating the Oracle Java Runtime Environment


Oracle provides two specialized Java editions for embedded development:

  • Java SE embedded: This is a large subset of the desktop version of the standard Java SE. It contains optimizations with respect to the standard edition, like size and memory usage, to adapt it to the needs of mid-sized embedded devices.

  • Java Micro Edition (ME): This is targeted at headless low- and mid-range devices, and is a subset of Java SE complying with the Connected Limited Device Configuration (CLDC), and including some extra features and tools for the embedded market. Oracle offers a couple of reference implementations, but Java ME will have to be individually integrated from source into specific platforms.

We will focus on Java SE embedded, which can be downloaded in binary format from the Oracle download site.

Java SE embedded is commercially licensed and requires royalty payments for embedded deployments.

Getting ready

Yocto has a meta-oracle-java layer that is meant...

Integrating the Open Java Development Kit


The open source alternative to the Oracle Java SE embedded is the Open Java Development Kit (OpenJDK), an open source implementation of Java SE licensed under the GPLv2, with the classpath exception, which means that applications are allowed to link without being bound by the GPL license.

This recipe will show how to build OpenJDK with Yocto and integrate the JRE into our target images.

Getting ready

The main components of OpenJDK are:

  • The HotSpot Java Virtual Machine

  • The Java Class Library (JCL)

  • The Java compiler, javac

Initially, OpenJDK needed to be built using a proprietary JDK. However, the IcedTea project allowed us to build OpenJDK using the GNU classpath, the GNU compiler for Java (GCJ), and bootstrap a JDK to build OpenJDK. It also complements OpenJDK with some missing components available on Java SE like a web browser plugin and web start implementations.

Yocto can build meta-java using the meta-java layer, which includes recipes for cross-compiling...

Integrating Java applications


The meta-java layer also offers helper classes to ease the integration of Java libraries and applications into Yocto. In this recipe, we will see an example of building a Java library using the provided classes.

Getting ready

The meta-java layer provides two main classes to help with the integration of Java applications and libraries:

  • The Java bbclass: This provides the default target directories and some auxiliary functions, namely:

    • oe_jarinstall: This installs and symlinks a JAR file

    • oe_makeclasspath: This generates a classpath string from JAR filenames

    • oe_java_simple_wrapper: This wraps your Java application in a shell script

  • The java-library bbclass: This inherits the Java bbclass and extends it to create and install JAR files.

How to do it...

We will use the following meta-custom/recipes-java/java-helloworld/java-helloworld-1.0/HelloWorldSwing.java graphical Swing hello world as an example:

import javax.swing.JFrame;
import javax.swing.JLabel;

public class HelloWorldSwing...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Embedded Linux Projects Using Yocto Project Cookbook
Published in: Mar 2015Publisher: ISBN-13: 9781784395186
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Alex Gonzalez

Alex González is a software engineering supervisor at Digi International and product owner of the Digi Embedded Yocto distribution. He started working professionally with embedded systems in 1999 and the Linux kernel in 2004, designing products for voice and video over IP networks, and followed his interests into machine-to-machine (M2M) technologies and the Internet of Things. Born and raised in Bilbao, Spain, Alex has an electronic engineering degree from the University of the Basque Country and he received his MSc in communication systems from the University of Portsmouth.
Read more about Alex Gonzalez