Yocto – build system
The Yocto Project is a set of templates, tools and methods that allow to build custom embedded Linux-based systems.
Build System
Build system purposes,
- Compiling or cross-compiling applications
- Packaging applications
- Testing output binaries and ecosystem compatibility
- Deploying generated images
Without build system,
- Each application has to be built manually, or using custom and non stable scripts
- The root file system has to be created from scratch
- The applications configurations have to be done by hand
- Each dependency has to be matched manually
- Integrating software programs from different teams is painful
Build system benefits,
- Build systems automate the process of building a target system, including the kernel, and sometimes the toolchain
- It is possible to generate the same root file system for different hardware targets or to have a debug image based on the production one, with some more flags or debugging applications
- They automatically download, configure, compile and install all the components in the right order, sometimes after applying patches to fix cross-compiling issues.
- They make sure all the application dependencies are matched.
- They already contain a large number of packages, that should fit your main requirements, and are easily extensible.
- The build becomes reproducible, which allows to easily change the configuration of some components, upgrade them, fix bugs, etc.
- Several configurations can be handled in the same project.
Workflow,
- Development of each application is done out of the build system, on an external repository.
- The build system downloads sources from this repository and starts the build following the instructions.
- The build system is used to build the full system and to provide a working image to the customer
Yocto
Core components
- Bitbake build engine
- task scheduler like make
- interprets configuration files and recipes/metadata to perform a set of tasks, to download, configure and build specified packages and filesystem images
- OpenEmbedded Core set of base layers
- set of recipes, layers and classes which are shared between all OpenEmbedded based systems.
- Recipes
- describe how to fetch, configure, compile and package applications and images
- Layers
- are sets of recipes, matching a common purpose. eg meta-ti layer for Texas Instruments board support
- Multiple layers are used within a same distribution, depending on the requirements
- Poky reference system
- collection of projects and tools, used to bootstrap a new distribution based on the Yocto Project.
- oe-init-build-env script provided to set up the build directory and the environment variables (eve to run bitbake command)
Yocto Layers
Layers in Yocto allow to organize the long list of providers and to easily customize for target hardware while reusing a lot of tools already available. It also makes it easy to distribute customizable source code trough a unique layer.
Layers are basically a group of directories and meta-data in configuration and recipe files (which contains metadata as text). This creation of directories and meta-data files can be done by hand. However, it is always easier to use the new-layer script in order to create the required structure and then fill in with customized configuration.
$ cd /sources
$ ./poky/scripts/yocto-layer create
e.g. $ yocto-layer create new-layer
It creates directory ‘./meta-new-layer’
It is not a must but it’s strongly recommended to have the name of the layer start with “meta-“, the Poky new layer script uses this naming convention.
Layer Priority
Each layer has a priority, which is used by bitbake to decide which layer takes precedence if there are recipe files with the same name in multiple layers. A higher numeric value represents a higher priority.
Layer basic requirements
- README with information regarding what’s contained in the layer and any dependencies
- COPYING file with the copyright and use notice for the hardware in the new layer.
- conf folder which contains the layer’s configuration (.conf) files.
Adding Layer
Once the layer has been created it’s necessary to add it to the list of Layers that make up the BSP (Board Support Package) so Bitbake can locate it and parse the metadata contained within it, in other words, you must make the build system aware of your new layer.
In order to enable a layer, need to add the layer’s path to the BBLAYERS variable in the ‘conf/bblayers.conf’ file which is found on the build directory.
Need to add layer to each build directory in which it need to be used.
e.g. BBLAYERS += ” ${BSPDIR}/sources/meta-new-layer ”
Then added layer will be listed in result of “bitbake-layers show-layers”
Adding Recipe
New layer script also creates a basic recipe, which can be used as template or starting point.
If there are many versions of the same recipe the default behavior is to use the recipe contained in the highest priority layer even if it’s not the higher version of the recipe.
To force bitbake to use a certain version, following variable need to use on the local.conf file.
PREFERRED_VERSION_recipename
Recipe main requirements
- SRC_URI which points to the location of the source code
- SRC_REV if applicable it would correspond to a particular commit or branch from the source code repository
- LICENSE a variable that defines the type of license to bitbake
- LIC_FILES_CHKSUM should point to a file within the source tree that corresponds to the md5 check-sum of the license file so it can be verified.
Append Recipe
The append files allow to change an existing recipe.
The name of the file must be the same as the original recipe plus the append suffix (.bbappend) and should be located on the same path as the original recipe but in new-layer (created one).
The append file can be described as a piece of code or metadata that is added to the end of the original recipe. If there are more than one append files for a particular recipe all of them will be joined in reverse priority, that is, the highest priority layer’s bbappend will be added last.
Further to Read
- http://free-electrons.com/doc/training/yocto/yocto-slides.pdf “Advanced Configuration” of overriding or modifying variables of build/conf/local.cong Slides 62 to 69
- http://free-electrons.com/training/yocto/
- http://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manual.html
- https://www.yoctoproject.org/docs/1.6/yocto-project-qs/yocto-project-qs.html
- https://vimeo.com/36450321
References