Reader small image

You're reading from  Yocto for Raspberry Pi

Product typeBook
Published inJun 2016
PublisherPackt
ISBN-139781785281952
Edition1st Edition
Concepts
Right arrow
Authors (2):
TEXIER Pierre-Jean
TEXIER Pierre-Jean
author image
TEXIER Pierre-Jean

Pierre-Jean TEXIER has been an embedded Linux engineer at Amplitude Systèmes (Amplitude Systèmes was a pioneer in the marketing of Ytterbium femtosecond lasers) since 2014 where he maintains a custom system on chip i.MX6 with the Yocto project (meta-fsl-arm), which is made by a French company: EUKREA. He is a graduate of ESTEI school at Bordeaux where he spent 3 years as a student in order to become an embedded Linux Engineer. He is a big ardent of the world of free software and the embedded world. His knowledge background includes C/C++, Yocto, Linux, Bash, Kernel development but he is also open to trying new things and testing new technologies. First, I want to thank my patience wife for her during my writing sessions. I also give thanks my parents and my brother, who without them, this book possibly would not have happened. I would also like to thank all of the mentors that I've had over the years. Mentors such as Cyril SAGONERO, Sylvain LE HENAFF, Pierre BORDELAIS, Vincent POULAILLEAU, Fabrice BONNET, Jean-Claude PERESSINOTTO, Pierre AUBRY. Without learning from these teachers, there is not a chance I could be doing what I do today. To finish I would like to thanks Eric MOTTAY the CEO of Amplitude Systèmes, Luca TESTA the head of Electronics team at Amplitude Systèmes for his trust, Hitesham WOODHOO, Alexandre GAMONET, Kevin PINTO and Guillaume MACHINET For the various discussions about the raspberry pi during coffee breaks.
Read more about TEXIER Pierre-Jean

Petter Mabäcker
Petter Mabäcker
author image
Petter Mabäcker

Petter Mabcker is a senior software developer specializing in embedded Linux systems. For the past 8 years, he has been working with embedded Linux professionally. Currently, Petter works as a Scrum Master and senior software developer at Ericsson AB. Additionally, his knowledge includes C/C++, shell scripting, Yocto Project (including BitBake and OpenEmbedded), Scrum, and Git. In 2013, Petter started the small business Technux, which he runs as a side project in parallel with his duties at Ericsson. Some of the focus areas of the business are open source embedded Linux projects, such as the Yocto Project, together with different projects that involve the Raspberry Pi. As part of the work with Technux, Petter works as a contributer to the Yocto Project (including the Raspberry Pi BSP layer, known as meta-raspberrypi).
Read more about Petter Mabäcker

View More author details
Right arrow

Chapter 7. Deploying a Custom Layer on the Raspberry Pi

In this chapter you will learn how to generate a custom layer with the different tools the Yocto Project offers. First of all, you'll discover how to generate a layer; then, you will integrate a recipe to the layer. In addition, to finish this chapter, we will generate a custom image. Reading this chapter will enable you to better organize your source code within the Yocto Project.

Creating the meta-packt_rpi layer with the yocto-layer script


To create our custom layer, we can use two different methods:

  • Manually: create the directory (meta-*) and create the layer configuration file (conf/layer.conf)

  • * Use the yocto-layer script provided by the Poky environment

To gain flexibility and avoid mishandling, we'll use the second option. To use it,  we must initially source all variables to gain access through our shell in the yocto-layer script, as shown in the following command:

$ source oe-init-build-env rpi-build

Now that our environment is set up, we have access  to the yocto-layer  script,  and so,  we can begin the process of creating the layer.

Note that this script (yocto-layer) creates the layer in the current directory by default. That is why we must place it at the root of our environment:

$ cd /where/you/want/to/stored/your/layer

We can now launch the script using the following command:

$ yocto-layer create <layer_name> -o...

Adding gpio-packt to meta-packt_rpi


To test this layer,  we will integrate the application developed in Chapter 5 , Creating, Developing, and Deploying on the Raspberry Pi ( gpio-packt). This will allow us to implement our layer step by step so that it is completely reusable for various projects. The hierarchy of your layer should look like this with the inclusion of this recipe:

$ tree meta-packt_rpi/
meta-packt_rpi/
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
├── recipes-custom
│   └── gpio-packt 
│       ├── gpio-packt
│       │   └── gpio-example.c
│       └── gpio-packt.bb
├── recipes-example
│   └── example
│       ├── example-packt-0.1
│       │   ├── example.patch
│       │   └── helloworld.c
│       └── example-packt_0.1.bb
└── recipes-example-bbappend
    └── example-bbappend
    ├── example-packt-0.1
    │   └── example.patch
    └── example-packt_0.1.bbappend

As with any other extra package for our image, the build system needs to be aware that you want...

Patching gpio-packt


Now that we've seen how to integrate our recipe (gpio-packt) to the previously created layer (meta-packt_rpi), we will see how to create a patch to the gpio-packt recipe.

Generating the patch

The first step is to create the .patch file. Use the following commands to create a backup of the original file:

$ cd meta-pack_rpi/recipe-custom/gpio_packt
$ cp gpio-packt/gpio-example.c gpio-packt/gpio-example.orig

Now, we can modify our main source code (gpio-example.c):

$ sed -i 's/Button Mode/Button Mode!/' gpio-packt/gpio-example.c

We have now changed our source file like we wanted to; the next step is to create our patch file with the diff command:

$ diff -u gpio-packt/gpio-example.orig gpio-packt/gpio-example.c >  gpio-packt/fix.patch

Now that we have our .patch file, we need to update our principal source file:

$ mv gpio-packt/gpio-example.orig gpio-packt/gpio-example.c

Adding the patch to the recipe file

Be careful, because even if we have generated our .patch...

Creating the raspberry-packt-image.bb image


Through out this chapter, our aim was to create a layer that can be reused in any environment. We'll see how to create our own image to be more dependent on images provided by the meta-raspberrypi BSP layer. There's no need to worry, because to create an image, we just need to make a recipe file.

Creating the environment

To separate the recipes of our layer, we will position our image recipe in a layer called recipe-core, where we will create our raspberry-packt-image.bb recipe file.  Here are the results of our layer after creating it:

$ tree meta-packt_rpi/
meta-packt_rpi/
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
├── recipes-core
│   └── images
│       ├── raspberry-packt-image.bb
├── recipes-custom
   └── gpio-packt
│       ├── gpio-packt
│       │   ├── fix.patch
│       │   └── gpio-example.c
│       └── gpio-packt.bb
├── recipes-example
│   └── example
│       ├── example-packt-0.1
│       │ ...

Deploying the raspberry-packt-image.bb image


Now comes the time when we can test our image and check its operation. To do this, we have to launch usual bitbake command, but this time with an argument-the name of our image, raspberry-packt-image:

$ bitbake raspberry-packt-image
Loading cache: 100% |########################################################################################################################################################################| ETA:  00:00:00

Now, we have a 100% custom environment ( layer , recipe , and image ).

Note

Remember, to learn how to best handle the meta-packt_rpi layer directory, you can visit http://www.yoctoproject.org/docs/1.4.2/dev-manual/dev-manual.html#managing-layers .

Summary


In this chapter, we learned how to generate a custom layer using the yocto-layer script. We also learned how to integrate a recipe into this, and finally, we created a custom image and it on our Raspberry Pi.

In the next chapter, we will explore all of the Raspberry Pi's peripherals.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Yocto for Raspberry Pi
Published in: Jun 2016Publisher: PacktISBN-13: 9781785281952
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
TEXIER Pierre-Jean

Pierre-Jean TEXIER has been an embedded Linux engineer at Amplitude Systèmes (Amplitude Systèmes was a pioneer in the marketing of Ytterbium femtosecond lasers) since 2014 where he maintains a custom system on chip i.MX6 with the Yocto project (meta-fsl-arm), which is made by a French company: EUKREA. He is a graduate of ESTEI school at Bordeaux where he spent 3 years as a student in order to become an embedded Linux Engineer. He is a big ardent of the world of free software and the embedded world. His knowledge background includes C/C++, Yocto, Linux, Bash, Kernel development but he is also open to trying new things and testing new technologies. First, I want to thank my patience wife for her during my writing sessions. I also give thanks my parents and my brother, who without them, this book possibly would not have happened. I would also like to thank all of the mentors that I've had over the years. Mentors such as Cyril SAGONERO, Sylvain LE HENAFF, Pierre BORDELAIS, Vincent POULAILLEAU, Fabrice BONNET, Jean-Claude PERESSINOTTO, Pierre AUBRY. Without learning from these teachers, there is not a chance I could be doing what I do today. To finish I would like to thanks Eric MOTTAY the CEO of Amplitude Systèmes, Luca TESTA the head of Electronics team at Amplitude Systèmes for his trust, Hitesham WOODHOO, Alexandre GAMONET, Kevin PINTO and Guillaume MACHINET For the various discussions about the raspberry pi during coffee breaks.
Read more about TEXIER Pierre-Jean

author image
Petter Mabäcker

Petter Mabcker is a senior software developer specializing in embedded Linux systems. For the past 8 years, he has been working with embedded Linux professionally. Currently, Petter works as a Scrum Master and senior software developer at Ericsson AB. Additionally, his knowledge includes C/C++, shell scripting, Yocto Project (including BitBake and OpenEmbedded), Scrum, and Git. In 2013, Petter started the small business Technux, which he runs as a side project in parallel with his duties at Ericsson. Some of the focus areas of the business are open source embedded Linux projects, such as the Yocto Project, together with different projects that involve the Raspberry Pi. As part of the work with Technux, Petter works as a contributer to the Yocto Project (including the Raspberry Pi BSP layer, known as meta-raspberrypi).
Read more about Petter Mabäcker