blog


Project maintained by abiaog Hosted on GitHub Pages — Theme by mattgraham

bitbake

Obtaining BitBake

git clone git://git.openembedded.org/bitbake

version

peter@peter-ThinkPad-T430:~/work/src/bitbake$ ./bin/bitbake --version
BitBake Build Tool Core version 1.31.1

The Hello World Example

Create a Project Directory

Run Bitbake

peter@peter-ThinkPad-T430:~/work/examples/hello$ bitbake
The BBPATH variable is not set and bitbake did not find a conf/bblayers.conf file in the expected location.
Maybe you accidentally invoked bitbake from the wrong directory?

When you run BitBake, it begins looking for metadata files. The BBPATH variable is what tells BitBake where to look for those files. BBPATH is not set and you need to set it. Without BBPATH, Bitbake cannot find any configuration files (.conf) or recipe files (.bb) at all. BitBake also cannot find the bitbake.conf file.

Setting BBPATH

peter@peter-ThinkPad-T430:~/work/examples/hello$ BBPATH="/home/peter/work/examples/hello"
peter@peter-ThinkPad-T430:~/work/examples/hello$ export BBPATH
peter@peter-ThinkPad-T430:~/work/examples/hello$ bitbake
ERROR: Traceback (most recent call last):
  File "/home/peter/work/src/bitbake/lib/bb/cookerdata.py", line 181, in wrapped
    return func(fn, *args)
  File "/home/peter/work/src/bitbake/lib/bb/cookerdata.py", line 206, in parse_config_file
    return bb.parse.handle(fn, data, include)
  File "/home/peter/work/src/bitbake/lib/bb/parse/__init__.py", line 113, in handle
    return h['handle'](fn, data, include)
  File "/home/peter/work/src/bitbake/lib/bb/parse/parse_py/ConfHandler.py", line 126, in handle
    abs_fn = resolve_file(fn, data)
  File "/home/peter/work/src/bitbake/lib/bb/parse/__init__.py", line 131, in resolve_file
    raise IOError(errno.ENOENT, "file %s not found in %s" % (fn, bbpath))
FileNotFoundError: [Errno 2] file conf/bitbake.conf not found in /home/peter/work/examples/hello

This sample output shows that BitBake could not find the conf/bitbake.conf file in the project directory. This file is the first thing BitBake must find in order to build a target. And, since the project directory for this example is empty, you need to provide a conf/bitbake.conf file. ERROR: Unable to parse conf/bitbake.conf: [Errno 2] file conf/bitbake.conf not found in /home/peter/work/examples/hello

Creating conf/bitbake.conf

hello/conf/bitbake.conf

For more information on the bitbake.conf, see http://hambedded.org/blog/2012/11/24/from-bitbake-hello-world-to-an-image/#an-overview-of-bitbakeconf

peter@peter-ThinkPad-T430:~/work/examples/hello$ mkdir conf
peter@peter-ThinkPad-T430:~/work/examples/hello$ vim conf/bitbake.conf
peter@peter-ThinkPad-T430:~/work/examples/hello$ 

From within the conf directory, use some editor to create the bitbake.conf so that it contains the following:

 TMPDIR  = "${TOPDIR}/tmp"
 CACHE   = "${TMPDIR}/cache"
 STAMP   = "${TMPDIR}/stamps"
 T       = "${TMPDIR}/work"
 B       = "${TMPDIR}"

The TMPDIR variable establishes a directory that BitBake uses for build output and intermediate files (other than the cached information used by the Setscene process. Here, the TMPDIR directory is set to hello/tmp.

Run Bitbake

peter@peter-ThinkPad-T430:~/work/examples/hello$ bitbake
ERROR: ParseError in configuration INHERITs: Could not inherit file classes/base.bbclass
peter@peter-ThinkPad-T430:~/work/examples/hello$ 

In the sample output, BitBake could not find the classes/base.bbclass file. You need to create that file next.

Creating classes/base.bbclass

BitBake uses class files to provide common code and functionality. The minimally required class for BitBake is the classes/base.bbclass file. The base class is implicitly inherited by every recipe. BitBake looks for the class in the classes directory of the project (i.e hello/classes in this example).

Move to the classes directory and then create the base.bbclass file by inserting this single line:

 addtask build

The minimal task that BitBake runs is the do_build task. This is all the example needs in order to build the project. Of course, the base.bbclass can have much more depending on which build environments BitBake is supporting. For more information on the base.bbclass file, you can look at http://hambedded.org/blog/2012/11/24/from-bitbake-hello-world-to-an-image/#tasks.

peter@peter-ThinkPad-T430:~/work/examples/hello$ mkdir classes
peter@peter-ThinkPad-T430:~/work/examples/hello$ vim classes/base.bbclass

hello/conf/bitbake.conf

Run Bitbake

peter@peter-ThinkPad-T430:~/work/examples/hello$ bitbake
Nothing to do.  Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.

BitBake is finally reporting no errors. However, you can see that it really does not have anything to do. You need to create a recipe that gives BitBake something to do.

Creating a Layer

While it is not really necessary for such a small example, it is good practice to create a layer in which to keep your code separate from the general metadata used by BitBake. Thus, this example creates and uses a layer called “mylayer”. Note You can find additional information on adding a layer at http://hambedded.org/blog/2012/11/24/from-bitbake-hello-world-to-an-image/#adding-an-example-layer.

Minimally, you need a recipe file and a layer configuration file in your layer. The configuration file needs to be in the conf directory inside the layer.

mylayer/conf/layer.conf

You need to create the recipe file next. Inside your layer at the top-level, use an editor and create a recipe file named printhello.bb that has the following:

mylayer/printhello.bb

Run Bitbake With a Target

peter@peter-ThinkPad-T430:~/work/examples/hello$ bitbake printhello
ERROR: no recipe files to build, check your BBPATH and BBFILES?

Summary: There was 1 ERROR message shown, returning a non-zero exit code.

We have created the layer with the recipe and the layer configuration file but it still seems that BitBake cannot find the recipe. BitBake needs a conf/bblayers.conf that lists the layers for the project. Without this file, BitBake cannot find the recipe.

Creating conf/bblayers.conf

BitBake uses the conf/bblayers.conf file to locate layers needed for the project. This file must reside in the conf directory of the project (i.e. hello/conf for this example).

Set your working directory to the hello/conf directory and then create the bblayers.conf file so that it contains the following:

hello/conf/bblayers.conf

peter@peter-ThinkPad-T430:~/work/examples/hello$ vim conf/bblayers.conf
peter@peter-ThinkPad-T430:~/work/examples/hello$ 
peter@peter-ThinkPad-T430:~/work/examples/hello$ bitbake printhello
Parsing recipes: 100% |#########################################################################################################| Time: 0:00:00
Parsing of 1 .bb files complete (0 cached, 1 parsed). 1 targets, 0 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Initialising tasks: 100% |######################################################################################################| Time: 0:00:00
NOTE: Executing RunQueue Tasks
None do_build: ********************
None do_build: *                  *
None do_build: *  Hello, World!   *
None do_build: *                  *
None do_build: ********************
NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be rerun and all succeeded.

Note

After the first execution, re-running bitbake printhello again will not result in a BitBake run that prints the same console output. The reason for this is that the first time the printhello.bb recipe's do_build task executes successfully, BitBake writes a stamp file for the task. Thus, the next time you attempt to run the task using that same bitbake command, BitBake notices the stamp and therefore determines that the task does not need to be re-run. If you delete the tmp directory or run bitbake -c clean printhello and then re-run the build, the "Hello, World!" message will be printed again.

Reference

Manual