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
BBLAYERS ?= " \
/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 \
"
BBLAYERS ?= " \
/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:
https://github.com/mytechpg/helloworld.git
you can build hello world program for your Linux system with
make
or
CC=gcc make
In the second case, you will use gcc as compiler.
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:
meta-mytechpg-test/
recipes-helloworld/
helloworld/
helloworld_1.0.bb
helloworld/
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:
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:
https://github.com/mytechpg/helloworld.git
you can build hello world program for your Linux system with
make
or
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:
meta-mytechpg-test/
recipes-helloworld/
helloworld/
helloworld_1.0.bb
helloworld/
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
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:
BASE_WORKDIR ?= "${TMPDIR}/work"
WORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}"
For example, for our QEMU environment:
/area/devel/yocto/poky/qemu/tmp/work/i586-poky-linux/helloworld/1.0-
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-recipeWORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}"
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
/area/devel/yocto/poky/qemu/tmp/work/i586-poky-linux/helloworld/1.0-
You can find your package in ${TMPDIR}/deploy/ipk/i586