Tuesday, August 11, 2015

Howto create a new layer

This post is the first one of a series of tutorials on how to extend a Yocto base image.

In this first tutorial I will to explain how to create a layer, add a first recipe and build a hello world program.

Layer creation

The simplest way to create a new layer is the yocto-layer script, available in the scripts directory.

./scripts/yocto-layer create mytechpg-test

With this command, I created a layer with meta-mytechpg-test name. I added also two samples receipt inside.
You can download my layer with this command:

git clone https://github.com/mytechpg/meta-mytechpg-test.git
SHA: 57d05b703bfb8b415b5cdd1994193eb6c1e82599

The key file is conf/layer.conf that specifies the characteristic of our layer. Typically, you don't need to modify it.
The main entries are:
  • BBPATH specifies the main directory of the layer
  • BBFILES specifies the recipes path. Please note that recipes file have to start with "recipes-"
To add this layer to your Yocto system, you have to modify your conf/bblayers.conf file

  /area/devel/yocto/poky/meta \
  /area/devel/yocto/poky/meta-yocto \
  /area/devel/yocto/poky/meta-yocto-bsp \
  /area/devel/yocto/poky/meta-mytechpg-test \

Hello World simple program

You can download the Hello World program from here:


you can build hello world program for your Linux system with



CC=gcc make

In the second case, you will use gcc as compiler.

Howto create our first recipe

You can download my layer with hello world recipe from github:

git clone https://github.com/mytechpg/meta-mytechpg-test.git
cd meta-mytechpg-test
git checkout a41963c28fe649a9d1f7f5eb5fd103e780481192

First, to create a helloworld recipe you have to create this directory structure:


The inner helloworld directory will be used for patches and at the moment it is empty.
helloworld_1.0.bb contains the instruction to build the helloworld project. "1.0" defines the version and you can refer to it with PV variable.

In this example, you will download the code using a git repository.

The more important entry in the recipe are:
  • LICENSE and LIC_FILES_CHKSUM, that specify the license type, the license file and its checksum
  • SRC_URI, that contains the URI of the git repo
  • SRCREV, with the SHA that we will use
  • S, with the path where Yocto scripts will save our source code. Since we are using a git repository, we added a "git" folder at the end of the path
  • do_compile, that contains the instruction to build our package
  • do_install, that specifies which files has to be installed on the target
Then, to build your recipe, first you have to setup your environment with:
source oe-init-build-env qemu
for qemu, or
source oe-init-build-env raspberrypi
for RaspberryPI

Then, you can execute:

bitbake helloworld

You can find the directory where Yocto builds your project looking these variables:


For example, for our QEMU environment:
  • TMPDIR is /area/devel/yocto/poky/qemu/tmp
  • MULTIMACH_TARGET_SYS is i586-poky-linux/
  • PN is helloworld
  • PV is 1.0
Then, WORKDIR for helloworld 1.0 build for QEMU is

You can find your package in ${TMPDIR}/deploy/ipk/i586

For further information, you can look at http://www.yoctoproject.org/docs/1.8/dev-manual/dev-manual.html#new-recipe-writing-a-new-recipe

No comments:

Post a Comment