Saturday, February 06, 2016

Creating a New Yocto Recipe

What is Yocto ?

The Yocto Project is an open source collaboration project that provides templates, tools and methods to help you create custom Linux-based systems for embedded products regardless of the hardware architecture.

What is a recipe ?

The thing that comes to our mind when we hear the word recipe is a set of instructions for preparing a particular dish, including a list of the ingredients required. Similarly a recipe file in yocto is a set of instructions for building packages. A recipe describes where you get source code, which patches to apply, how to configure the source, how to compile it and so on. Recipes also describe dependencies for libraries or for other recipes. Recipes represent the logical unit of execution, the software to build, the images to build, and use the .bb file extension. The recipes are present in layers ( A collection of recipes representing the core, a BSP, or an application stack)

Creating a Recipe:

There are a number of meta-layers which provides recipes for a numerous packages but there may come a time where we have to get down and write a recipe for ourselves.
If you open a recipe you will see a number of entries, the entries you will encounter often are given below
Whenever it comes to creating a recipe most people tend to copy an existing recipe and alter the contents manually. There are tools provided by yocto to aid us in creating recipes. The following tools helps us in creating a recipe
  • create-recipe
  • recipetool
In my little experiments with these tools, I learnt that recipetool produces a buildable recipe. Below are the sample recipes of zlib-1.2.8 created using recipetool and create-recipe you can see the difference here

Sample recipe by recipetool:

recipetool create -o
The usage of recipetool can be understood from the help message shown below:
usage: recipetool create [-h] -o OUTFILE [-m] [-x EXTRACTPATH] source
Creates a new recipe from a source tree
positional arguments:
source Path or URL to source
optional arguments:
-h, --help show this help message and exit
-o OUTFILE, --outfile OUTFILE
Specify filename for recipe to create
-m, --machine Make recipe machine-specific as opposed to
Assuming source is a URL, fetch it and extract it to
the directory specified as EXTRACTPATH
The contents of the recipe created as a result of the recipetool command is given below
 # Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "Unknown"
LIC_FILES_CHKSUM = "file://contrib/dotzlib/LICENSE_1_0.txt;md5=81543b22c36f10d20ac9712f8d80ef8d"
SRC_URI = " "
SRC_URI[md5sum] = "44d667c142d7cda120332623eab69f40"
SRC_URI[sha256sum] = "36658cb768a54c1d4dec43c3116c27ed893e88b02ecfcb44f2166f9c0b7f2a0d"
S = "${WORKDIR}/zlib-1.2.8"
inherit cmake
# Specify any options you want to pass to cmake using EXTRA_OECMAKE:

Sample recipe by create-recipe:

The create-recipe command doesn't require the output file. By default it creates the recipe with the source link  provided.
The contents of the recipe created as a result of the create-recipe command is given below.
SUMMARY = "zlib compression library"
zlib 1.2.8 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files (zlib format), rfc1951 (deflate format) and
rfc1952 (gzip format).
SRC_URI = " \
SRC_URI[md5sum] = "44d667c142d7cda120332623eab69f40"
SRC_URI[sha256sum] = "36658cb768a54c1d4dec43c3116c27ed893e88b02ecfcb44f2166f9c0b7f2a0d"

Differences between recipetool & create-recipe

Both recipe creation tools provides the SRC_URI and its checksums. The create-recipe tool provides us with SUMMARY & DESCRIPTION which should be mentioned in a recipe but it doesn't carry weight when compared to the mention of source directory ( S )  and the class required to build the package ( inherit cmake).
Also create-recipe fails if the source doesn't provide a tarball. But recipetool can be used for git source too.
I use both the tools so the recipe would be similar to the standard yocto recipes. So use whichever tool suits you and enjoy creating recipes.  An another post will follow in creating-recipes which will explain creating recipes that require further customization.

No comments:

Post a Comment