-
Notifications
You must be signed in to change notification settings - Fork 1
Tag 6 Bitbake
Bitbake is a build tool, like for example make. It is used in OpenEmbedded, which is used by Yocto.
Yocto -> OpenEmbedded -> BitBake
Bitbake is used in Yocto as a meta toolchain that invokes other toolchains. For example in Yocto Bitbake could call wget, patch, configure, make, make install ...
There's an awesome tutorial on bitbake's homepage (link see at the bottom of this page). This is an excerpt of that training, please execute the commands during the training yourself and please wait at the points marked BISCUIT STOP until the whole training group reached that point. You may want to fetch a biscuit then.
- git clone https://github.com/openembedded/bitbake
- cd bitbake
- export PATH='pwd'/bin:$PATH
- echo $PATH
- export PYTHONPATH='pwd'/lib:$PYTHONPATH
- echo $PYTHONPATH
- bitbake --version
Bitbake projects contain many layers, which can easily be switched on or off for particular builds. The sum of layers might be a toolkit of all company-wide available software (also 3d party like QT). So this is your toolbox, and you'll probably select (only) some of it for your device.
Bitbake -> Layer -> Recipe
A layer folder contains configuration, task and target descriptions for what BitBake does. It is common praxis to name a layer folders meta-'something'. The build folder is the directory from which the bitbake command has to be executed. Here, BitBake expects its initial configuration file and it will place all files it creates in this folder.
bbTutorial/ ├── build │ ├── bitbake.lock │ └── conf │ └── bblayers.conf └── meta-tutorial ├── classes │ └── base.bbclass └── conf ├── bitbake.conf └── layer.conf
Useful commands:
- mkdir creates a directory
- cd changes into a directory
- touch creates an empty file
- pwd shows the current directory's path
- nano edits a file
BISCUIT STOP
- build/conf/bblayers.conf
The first file BitBake expects is conf/bblayers.conf in its working directory, which is our build directory.
BBPATH := "${TOPDIR}" BBFILES ?= "" BBLAYERS = "/path/to/meta-tutorial"
Add the current directory to BBPATH. TOPDIR is internally set by BitBake to the current working directory. Initialize the variable BBFILES as empty. Recipes will be added later. Add the path of our meta-tutorial to the BBLAYERS variable. When executed, BitBake will search all given layer directories for additional configurations.
- meta-tutorial/conf/layer.conf
BBPATH .= ":${LAYERDIR}" BBFILES += ""
LAYERDIR is a variable BitBake passes to the layer it loads. We append this path to the BBPATH variable. BBFILES tells BitBake where recipes are. The ".=" and "+=" append the value without or with space to a variable.
- meta-tutorial/classes/base.bbclass (common functions, like for logging inside bitbake)
- meta-tutorial/conf/bitbake.conf (some variables)
These files can be taken from the BitBake installation directory in the folders bitbake/conf and bitbake/classes.
- cd build
- bitbake
BISCUIT STOP
- bitbake -vDDD
- Shows debug output
- bitbake -s
- Shows list of recipes
A cache speeds up compilation
- nano meta-turorial/conf/bitbake.conf
CACHE = "${TMPDIR}/cache/default"
BISCUIT STOP
One Bitbake setup contains many layers, our's is 'meta-tutorial'. Each Bitbake Layer contains many recipes. Now we can add work to be done in our first 'recipe'.
BitBake needs to know about which recipes a layer provides.
- nano meta-tutorial/conf/layer.conf
BBPATH .= ":${LAYERDIR}" BBFILES += "${LAYERDIR}/recipes-*/*/*.bb"
Naming a recipe "recipe-" is just a common convention like "meta-" is used for layers. It is not a technical requirement to name them that way.
- mkdir meta-tutorial/recipes-tutorial
- mkdir meta-tutorial/recipes-tutorial/first
- nano meta-tutorial/recipes-tutorial/first/first_0.1.bb
DESCRIPTION = "I am the first recipe" PR = "r1" do_build () { touch ~/lunixrocks }
Please note that you could add any shell script instead of the touch shell command. E.g. download a library with "wget" or start a compiler with "cc" or use another build system like "make" or patch something with "patch" ...
cd into the build directory and execute
- bitbake -s
Now you should see your recipe.
- bitbake first
This builds your recipe and you will see file created with touch by:
- ls ~
Advanced: If you like and have time left, you may want to use other shell commands. For example create a folder in your home directory with "mkdir ~/test" and download the latest version of your favorite website with the "wget" command. (Hint: "rm -rf" removes your old attempt's output - but be very careful with that command ;)
BISCUIT STOP
- bitbake first
This is handy if you're working on one recipe, you can compile only that module.
Also interesting:
- cat build/tmp/work/first-0.1-r1/temp/log.do_build
- Look around what other logfiles are available in this place
- bitbake -s
A recipe consists of tasks (layer -> recipe -> task). List all tasks:
- bitbake -c listtasks first
It is easily possible to execute one particular task during development:
- bitbake -c sometask first
Building absolutely everything
- bitbake world
Add a hello world program by following the principles found at: http://www.embeddedlinux.org.cn/OEManual/recipes_examples.html
http://a4z.bitbucket.org/docs/BitBake/guide.html http://www.embeddedlinux.org.cn/OEManual/recipes_examples.html