How To Add A Custom App To A Yocto Build
This page is a walk-through to show you how to add your own code/app to a custom Linux build that uses Yocto.
Making A Basic Hello, World App (Binary)
Firstly, we need a basic application that we can then add to a Yocto build. Letβs create a simple application that prints Hello, World
to stdout
and then exits.
We need to create the following files:
HelloWorld.c
HelloWorld.h
LICENSE
configure.ac
Makefile.am
These will be added to a git repository and pushed to GitHub (no folder structure, all these files will be added to the root repository directory).
Letβs create a HelloWorld.c
:
And a matching HelloWorld.h
:
We also need a LICENSE
file. Yocto is quite particular about licenses, to ensure that users can specify exactly what licensing restrictions are present in a particular build (e.g. make sure this build ONLY contains open-source code). Create a LICENSE
file, we will use the MIT license for this one:
We need a configure.ac
file:
Finally, make a Makefile.am
:
Notice in the Makefile.am
file that we add helloworld
to the bin_PROGRAMS
variable. This makes Yocto create a binary executable of your example βHello, Worldβ application and places it in /usr/bin
, making it executable from the command-line. We will use this feature to test it in QEMU once we have built the image below.
Commit all these files into a git repository. If you want the Yocto layer to download the files automatically, this repository needs to be placed on a server, so I used GitHub.
The code for this example app is located at https://github.com/gbmhunter/YoctoHelloWorldApp.
Make A Layer To Hold The App
The application needs to be added to a Yocto layer before it can be included in a build. It can either be added to an existing layer, or added to a new one. We will create a new layer to keep the development environment βcleanβ. All layers are contained with a meta-<layer name>
folder.
We will create a layer called meta-example
. Create a new directory called meta-example in the main Yocto directory (called poky
in our case).
Now cd
into this new directory and create a new folder called conf
.
The config folder holds configuration data about the layer. cd
into this directory and create a new file called layer.conf
:
Add the standard config code to layer.conf
as shown below. This layer.conf
file tells Yocto where the BitBake files are located in this package. We wonβt go into any more detail about this file, as this is beyond the scope of this tutorial.
We have finished with the conf
folder. We now need to create a recipe for this layer of ours. cd
into the parent directory, and create a new directory called recipes-example
.
Last updated