Reader small image

You're reading from  Using Yocto Project with BeagleBone Black

Product typeBook
Published inJun 2015
Reading LevelIntermediate
Publisher
ISBN-139781785289736
Edition1st Edition
Languages
Right arrow
Authors (2):
Irfan Sadiq
Irfan Sadiq
author image
Irfan Sadiq

H M Irfan Sadiq was a Linux enthusiast as a graduate student. He started his career as an embedded system development engineer and has been working as an H.264 Decoder developer and optimizer for the VLIW architecture. He got an opportunity to work on multiple multimedia frameworks that are open source as well as proprietary. He tried to work in a start-up in the entirely different domain of web development. He has been working on OpenEmbedded and Yocto Project technologies since he joined Mentor Graphics as the technical lead back in 2010. He has been working on derivative technologies of Yocto Project and OpenEmbedded for quite some time now, spanning more than 4 years. He has also been working on various hardware platforms based on the ARM, PPC, and x86 architecture. The diverse nature of subsequent BSPs has challenges in the context of QA. One of the challenges was to keep the QA packages in one place in such a way that they could be applied to all different product/platform combinations. He addressed this by creating a Yocto Project-based layer for which he is a maintainer as well as a gatekeeper.
Read more about Irfan Sadiq

View More author details
Right arrow

Chapter 3. Creating the helloworld Recipe

In the previous chapter, you learned the history of BitBake, its options, and how it works. In this chapter, we will create our first demo application, a very basic one, helloworld demo. Creating and running such an application does not require much effort. In this chapter, we will:

  • Learn the basic elements of a recipe

  • Learn the contents of work and build directory

  • Have an overview of tasks

  • Learn how to deploy packages

Creating helloworld


Yocto Project provides us with helping scripts to ease our tasks. You will learn some of these scripts during the course of this book. To create our helloworld recipe, we will use one such script, called yocto-layer. This script can be found under the scripts directory in poky. Primarily, this script is meant to create a layer that is used to arrange various sets of recipes. Currently, if we have a look at the contents of our poky directory, which we created in first chapter for creation of images, we have the following directories. These directories are layers, as can be found using the find command:

 $ find . -name layer.conf 
./meta/conf/layer.conf
./meta-skeleton/conf/layer.conf
./meta-yocto-bsp/conf/layer.conf
./meta-yocto/conf/layer.conf
./meta-selftest/conf/layer.conf

All of these are Poky layers, and we cannot use any of these to keep our metadata. Technically, this is not impossible, but it is not a recommended way of development. So, we will create our own layer...

Contents of the helloworld recipe


A recipe file is actually a set of instructions/actions that BitBake will perform, for our package to be created. This name is inspired by a cooking recipe, as BitBake itself is inspired from the cooking terminology, baking. In our case, it is helloworld_0.1.bb. Let's walk through the contents of the helloworld_0.1.bb recipe:

  • The top of this file contains comments about its derivation, since it is derived from the Yocto Project documentation.

  • DESCRIPTION: This variable contains a string value. For any recipe we can and should provide a description to let the users know what this recipe is about.

  • SECTION: In this variable, we define what type of recipe it is. In our case, it is an example. In other cases, it can be utilities, graphics, kernel, and so on.

  • LICENSE: Here, we specify the type of license we want to use for our recipe. In our case, it is MIT. Other values can be BSD, GPL, or your custom license. However, you need to provide a license file for your...

Building a recipe


Now that we have created a recipe, we are ready to build it. We already know how to build a recipe by invoking the simple BitBake <recipename> command as follows in our specific case:

$ bitbake helloworld

Tip

Do not forget to set an environment before running BitBake commands. You can set the environment by running the following command:

$ source oe-init-build-env build_bbb

We are omitting the output of this command for brevity. This will build our helloworld application/package/recipe. Thus, the binary helloworld that is created can be found at tmp/work/cortexa8hf-vfp-neon-poky-linux-gnueabi/helloworld/0.1-r0/helloworld. How can we know where some specific package will be found? Do we need to run a find command for this, or is there some criterion followed? Yes, we have a certain criteria followed here. For this, we need to look into how the WORKDIR variable is constructed. If we grep this variable from bitbake.conf, which can be found under poky/meta/conf/ directory...

Build directories


Let's have a quick look at the WORKDIR directory. Most of these directories are created and populated when the related task is executed. To have a look at it, let's execute the following command:

$ tree tmp/work/cortexa8hf-vfp-neon-poky-linux-gnueabi/helloworld/0.1-r0/ -dL 1

Here is the output of this command:

tmp/work/cortexa8hf-vfp-neon-poky-linux-gnueabi/helloworld/0.1-r0/
├── deploy-ipks
├── image
├── license-destdir
├── package
├── packages-split
├── patches
├── pkgdata
├── pseudo
├── sysroot-destdir
└── temp

Let's go through these by giving a short description of each:

  • deploy-ipks: The final package (ipk in our case) is placed in this directory.

  • image: Image contents go into this directory. The Do_install task installs contents to this directory before they are added to the respective packages.

  • license-destdir: License-related information is contained in this directory.

  • package: This is a shared place that contains package data when it is being generated, during the...

Tasks


This topic is long due. In the previous chapters we discussed tasks, but not in much detail. Tasks can be considered as units of execution to perform a specific function, or a set of related functions that can be combined together. The helloword tasks can be listed using the -c listtasks option of BitBake:

$ bitbake -c listtasks helloworld

Even for this basic recipe list, there are more than 20 tasks. In this output, each task contains a short description of it, which should be consulted first. We are skipping the list for brevity. Most of the tasks are not seen in the recipes. Why? We are content with the default implementations provided to us, which are automatically used if we do not want to override them. All these tasks are prefixed by do_. Here, we will discuss the most common tasks, to develop our understanding of them.

Build

This is like a placeholder task, to tell bitbake when we do not provide a specific task to be run. We don't have to tell bitbake to run this specific task...

Deploying helloworld


We are dealing with embedded systems and creating a package for an embedded board, that is, BeagleBone. Preparing a package alone doesn't make sense. We cannot run it on the host system. So, the next logical step is to actually deploy our package onto an embedded board. For such a simple recipe, we could have used simple compilation steps, copied the binary on our board and ran it. However, such a technique would have become a nightmare in a simple BSP, where we may easily have to do this for more than 1000 packages. Hence, we are using Yocto Project. We have the following two ways to deploy any recipe.

Manually installing a package

We can manually copy our package from tmp/deploy/ipk/cortexa8hf-vfp-neon/helloworld_0.1-r0_cortexa8hf-vfp-neon.ipk to our board using SCP over SSH, or any other technique available. We can copy it to an SD card and install it on the board, using the following command:

# opkg install  helloworld_0.1-r0_cortexa8hf-vfp-neon.ipk

This is not a very...

Summary


In this chapter, we created a helloworld recipe using the Yocto Project script for layer creation. We modified it a little bit to suit our needs and explained various elements contained in the recipe. We built the recipe and viewed the changes made in the directory structure. Finally, you learned how to deploy it to a target.

In the next chapter, you will learn about complex recipes, taking examples from GStreamer to add multimedia to our system.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Using Yocto Project with BeagleBone Black
Published in: Jun 2015Publisher: ISBN-13: 9781785289736
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

Authors (2)

author image
Irfan Sadiq

H M Irfan Sadiq was a Linux enthusiast as a graduate student. He started his career as an embedded system development engineer and has been working as an H.264 Decoder developer and optimizer for the VLIW architecture. He got an opportunity to work on multiple multimedia frameworks that are open source as well as proprietary. He tried to work in a start-up in the entirely different domain of web development. He has been working on OpenEmbedded and Yocto Project technologies since he joined Mentor Graphics as the technical lead back in 2010. He has been working on derivative technologies of Yocto Project and OpenEmbedded for quite some time now, spanning more than 4 years. He has also been working on various hardware platforms based on the ARM, PPC, and x86 architecture. The diverse nature of subsequent BSPs has challenges in the context of QA. One of the challenges was to keep the QA packages in one place in such a way that they could be applied to all different product/platform combinations. He addressed this by creating a Yocto Project-based layer for which he is a maintainer as well as a gatekeeper.
Read more about Irfan Sadiq