Yocto Project
Yocto Project
1. Fetch
2. Extract
3. Patch
4. Configure
5. Build
6. Install
7. Package
Building Open Embedded S/W packages
1)Fetch
➔Downloading the s/w packages from the ➔Some projects provides access to
download area Released versions
➔Usually it will be tar files in compressed Development branches through, git, SVN
form. etc
➔Downloads are accessible through ➔Download packages contains,
protocols,
Source code
• HTTP
Patch files
• HTTPS
Auxiliary files
• FTP
• SFTP etc
OE Build System should automatically select the right tool to extract the SOURCES
Building Open Embedded S/W packages
3) Patch
➔Process of incrementally modifying the How Does the Build System Handle
source code by adding, deleting or changing Patches?
the source files. ➔Build System needs to know where to
➔Why? copy the patch
To fix the bugs. files.
To address the security issues. ➔Order in which patches are applied is
To add the extra features. important.
BUILDDIR is Environment Variable which is used to define Absolute path of the build directory.
Environmental Setup
Common Targets
●Core-image-minimal
– A small image to boot a device and have access to core command line commands
and services.
●Core-image-sato
–Image with Sato support. Sato is a GNOME mobile-based user interface.
●Meta-toolchain
–Includes development headers and libraries to develop directly on the target.
●Meta-ide-support
–Generates the cross-toolchain. Useful when working with the SDK.
Environmental Setup
Commands
●bitbake
–The main build engine command.
–Used to perform tasks on available packages (download, configure, compile...).
●bitbake-*
–Various specific commands related to the BitBake build engine.(Eg. bitbake-layers)
●yocto-layer
–Command to create a new generic layer.
●yocto-bsp
–Command to create a new generic BSP.
Build Directory
/build
conf/
Configuration files. Image specific and layer configuration.
downloads/
Downloaded upstream tarballs of the packages used in the builds.
sstate-cache/
Shared state cache. Used by all builds.
tmp/
Holds all the build system outputs.
tmp/buildstats/
Stores performance and timing info for each package built.(e.g., CPU usage, elapsed time, host info).
Build Directory
/build
tmp/deploy/images/
Contains the complete images built by the OpenEmbedded build system.
These images are used to flash the target.
tmp/work/
Set of specific work directories, split by architecture.
They are used to unpack, configure and build the packages.
Contains the patched sources, generated objects and logs.
tmp/sysroots/
Shared libraries and headers used to compile packages for the target but also for the host.
Configuring: Build System
/build/conf/
The conf/ directory in the build one holds build specific configuration.
bblayers.conf
● Explicitly list the available layers.
local.conf
●Set up the configuration variables relative to the current user for the
build.
●Configuration variables can be overridden there.
Configuring: Build System
/build/conf/local.conf
●The conf/local.conf configuration file holds local user configuration variables:
–BB_NUMBER_THREADS
●How many tasks BitBake should perform in parallel.
●Defaults to the number of CPUs on the system.
–PARALLEL_MAKE
●How many processes should be used when compiling.
●Defaults to the number of CPUs on the system.
–MACHINE
●The machine the target is built for, e.g. RaspberryPi.
–PACKAGE_CLASSES
●Packages format (deb, ipk or rpm).
Building an Image
Compilation
●The compilation is handled by the BitBake build engine.
●Usage: bitbake [options] [recipename/target …]
●To build a target: bitbake [target]
●Building a minimal image: bitbake core-image-minimal
–This will run a full build for the selected target.
Building an Image –Lab
●Download the sources
●Set up the environment
●Configure the build
●Build an image
BitBake
How it is different from others
●Its metadata syntax not only enables
–Variables
–But also integrates
●Shell scripts
●Python functions.
BitBake
Running the BitBake
●BitBake always must be called with basename of the recipe or target
as the parameter.
●Example: bitbake core-image-minimal
●Core-image-minimal corresponds to the file core-image-minimal.bb
●BitBake will not automatically looks for the recipe in the current
working directory.
●Bitbake requires to set-up an execution environment before hand.
BitBake
BitBake Execution Environment
●BitBake first searches for the conf/bblayers.conf file.
●Bitbake expects this file to contain the variable, BBLAYERS
●Layers contained in this path is expected to contain conf/layer.conf file
●The purpose of the layer.conf file is to set-up, BBPATH and BBFILES
variables, so that bitbake can find recipes, classes, config files.
●BBPATH : Contains path to classes(.bbclass files) and conf files(.conf
files) in the sub-directories classes and the configuration DIR conf.
●BBFILES : Contains path to recipes files
BitBake
The Flow
●After parsing conf/bblayers.conf, bitbake looks for conf/bitbake.conf
which provides build system set-up.
●After parsing conf/bitbake.conf and other .conf files, it locates and
parses all classes.
Note: Atleast base.bbclass must be present for the bitbake to operate correctly, which provides
Basic functions like build task
BitBake
Common Bitbake Options
●BitBake can be used to run a full build for a given target with bitbake [target].
●But it can be more precise, with optional options:
-c <task> execute the given task
-s list all locally available packages and their versions
-f force the given task to be run by removing its stamp file
world keyword for all packages
-b <recipe> execute tasks from the given recipe (without resolving
dependencies).
BitBake
Bitbake: Examples
●bitbake -c listtasks virtual/kernel
–Gives a list of the available tasks for the package virtual/kernel. Tasks are prefixed with do_.
●bitbake -c menuconfig virtual/kernel
– Execute the task menuconfig on the kernel package.
● bitbake -f dropbear
– Force the dropbear package to be rebuilt from scratch.
● bitbake -c fetchall world
–Download all package sources and their dependencies.
● For a full description: bitbake --help
BitBake
Bitbake: Metadata
● Metadata: It describes how the software packages are built, their relations and dependencies.
● Metadata are classified into
–Variables (SRC_URI, DEPENDS, LICENSE, FILESEXTRAPATHS)
–Executable Metadata (Eg. Tasks: do_fetch, do_compile, do_install, do_package)
●Functions and tasks embedded inside the recipes and classes.
●Categories
.conf
.bb
.bbclass
.bbappend
.inc
BitBake
Bitbake Metadata : It's Catagories
● .conf files
–Metadata in this files is global and affects all recipes referencingthem.
–It contains only variables, no executables metadata.
–If same variable is assigned in multiple conf files, then order established by the
layer priority determines which variable to be evaluated.
– bitbake.conf has lowest priority, local.conf has the highest.
BitBake
Bitbake Metadata : It's Catagories
● .bb files
–Describes a particular s/w packages and how it is built.
–It provides executable metadata in the form of tasks with instructions for
●Downloading
●Unpacking
●Patching
●Compiling
●Packaging
●Installing...
BitBake
Bitbake Metadata : It's Catagories
● .bbclass files
–Provides inheritance mechanism for the recipes to share same build instructions.
– Bitbake searches for class files inside the classes directory of the layer.
–Recipes includes classes by directive inherit
–Classes are global.
–FILES
Example: FILES_${PN} = "/usr/bin/mypackage"
FILES_${PN}-dev = "/usr/include/mypackage"
–PACKAGE_BEFORE_PN
Example: PACKAGE_BEFORE_PN = "${PN}-dev ${PN}-dbg"
Recipes
Basics: Recipe Layout
● Task Overrides, Prepends and Appends
–This section contains override, prepend or append to the tasks to redefine, change or extend the default
behavior.
Overrides do_install:raspberrypi() {
echo "Installing for
Raspberry Pi" }
Prepend (_prepend)
do_install_prepend() {
echo "Pre-compilation
steps"
}
Recipes
Basics: Recipe Layout
●Run-time Metadata
–RDEPENDS
●List of packages that this package depends at the run-time
–RRECOMMENDS
●Similar to the RDEPENDS but have weak dependencies, failure to install will not fail to build, but to extend the functionalit y.
–RSUGGESTS
●Similar to RRECOMMENDS but even weaker in the sense that package managers will not install these packages even if they are
available.
●Only provides the info that installing these will be beneficial.
–RPROVIDES
●The recipe name and version usually match the upstream package ones.
●When using the recipe bash_4.2.bb:
${PN} = "bash"
${PV} = "4.2"
Recipes
Organization
poky
meta-custom
meta/recipes-core/init-ifupdown/ recipes-core/init-ifupdown/
init-ifupdown_1.0.bb init-ifupdown_1.0.bbappend
meta-ti
recipes-bsp/u-boot recipes-bsp/u-boot
u-boot-ti.inc u-boot-ti.inc
u-boot_2025.07.bb u-boot_2025.07.bbappend
Recipes
Organization
●Many packages have more than one recipe, to support different versions.
●In that case the common metadata is included in each version specific recipe and is in a .inc file:
<package>.inc: version agnostic metadata.
<package>_<version>.bb: require <package>.inc and version specific metadata.
● We can divide a recipe into three main parts:
–The header: what/who
–The sources: where
–The tasks: how
Recipes
The source locations: overview
●We need to retrieve both the raw sources from an official location and the resources
needed to configure, patch or install the package.
●SRC_URI defines where and how to retrieve the needed elements. It is a set of URI
schemes pointing to the resource locations (local or remote).
●URI scheme syntax: scheme://url;param1;param2
●scheme can describe a local file using file:// or remote locations with https://, git://,
svn://, hg://, ftp://...
●By default, sources are fetched in $BUILDDIR/downloads.
Change it with the DL_DIR variable in conf/local.conf
Recipes
The source locations: remote files
●The git scheme:
–git://<url>;protocol=<protocol>;branch=<branch>
–When using git, it is necessary to also define SRCREV.
●If SRCREV is a hash or a tag not present in master, the branch parameter is mandatory.
●When the tag is not in any branch, it is possible to use nobranch=1
●The http, https and ftp schemes:
–https://example.com/package-1.0.tar.bz2
–A few variables are available to help pointing to remote locations:
●${SOURCEFORGE_MIRROR}, ${GNU_MIRROR}, $KERNELORG_MIRROR}...
–Example: ${SOURCEFORGE_MIRROR}/<project-name>/${PN}- ${PV}.tar.gz
–See meta/conf/bitbake.conf
Recipes
The source locations: remote files
● An md5 or an sha256 sum must be provided when the protocol used to retrieve the file(s) does not guarantee their
integrity. This is the case for https,http or ftp.
–SRC_URI[md5sum] = "97b2c3fb082241ab5c56ab728522622b"
–SRC_URI[sha256sum] = "..."
●It's possible to use checksums for more than one file, using the name parameter:
–SRC_URI = "http://example.com/src.tar.bz2;name=tarball \
http://example.com/fixes.patch;name=patch"
–SRC_URI[tarball.md5sum] = "97b2c3fb082241ab5c56..."
–SRC_URI[patch.md5sum] = "b184acf9eb39df794ffd..."
Recipes
The source locations: local files
●All local files found in SRC_URI are copied into the package's working directory, in build/tmp/work/.
●The searched paths are defined in the FILESPATH variable.
FILESPATH = "${@base_set_filespath([
"${FILE_DIRNAME}/${PN}",
"${FILE_DIRNAME}/${PN}-${PV}",
"${FILE_DIRNAME}/files"], d)}"
FILESOVERRIDES="$MACHINEOVERRIDES}:DISTROOVERRIDES}"
● The base_set_filespath(path) function uses its path parameter, FILESEXTRAPATHS and FILESOVERRIDES to fill the
FILESPATH variable.
●Custom paths and files can be added using FILESEXTRAPATHS and FILESOVERRIDES.
●Prepend the paths, as the order matters, prepend with :=
Recipes
The source locations: tar balls
● When extracting a tar ball, BitBake expects to find the extracted files in a directory
named <package-name>-<version>.
● This is controlled by the S variable. If the directory has another name, you must
explicitly define S.
S = "${WORKDIR}/${PN}-${PV}"
● If the scheme is git, S must be set to ${WORKDIR}/git
Recipes
The source locations: license files
●License files must have their own checksum.
●LIC_FILES_CHKSUM defines the URI pointing to the license file in the source code as well as its
checksum.
–LIC_FILES_CHKSUM = "file://gpl.txt;md5=393a5ca..."
–LIC_FILES_CHKSUM = \
"file://main.c;beginline=3;endline=21;md5=58e..."
– LIC_FILES_CHKSUM = \
"file://${COMMON_LICENSE_DIR}/MIT;md5=083..."
●This allows to track any license update: if the license changes, the build will trigger a failure as the
checksum won't be valid anymore.
Recipes
Dependencies
● Sometimes a package have dependencies on specific versions of another
package.
●BitBake allows to reflect this by using:
–DEPENDS = "package-b (>= 1.2)" (Build Time)
–RDEPENDS_${PN} = "package-b (>= 1.2)" (Run time)
● The following operators are supported: =, >, <, >= and <=.
Recipes
Tasks
● Default tasks already exists, they are defined in classes:
–do_fetch
–do_unpack
–do_patch
–do_configure
–do_compile
–do_install
–do_package
–do_rootfs
●You can get a list of existing tasks for a recipe with:
bitbake <recipe> -c listtasks
Recipes
Writing Tasks
● Functions use the sh shell syntax, with available OpenEmbedded variables and internal functions
available.
D The destination directory (root directory of where the files are installed, before creating the
image).
WORKDIR The package's working directory
● Syntax of a task:
do_task() {
action0
action1
...
}
Recipes
Writing Tasks
●Example
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} -o hello ${WORKDIR}/hello.c
}
do_install() {
install -d ${D}${bindir}
install -m 0755 hello ${D}${bindir}
}
Recipes
Writing Tasks
●Example: Using Makefile
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}${bindir}
install -m 0755 hello ${D}${bindir}
}
Recipes
Modifying Existing Tasks
●Tasks can be extended with _prepend or _append
do_install_append() {
install -d ${D}${sysconfdir}
install -m 0755 hello.conf ${D}${sysconfdir}
}
Recipes
Adding New Tasks
● Tasks can be added with addtask
do_mkimage () {
uboot-mkimage ...
}
SRC_URI = "file://hello.c"
LIC_FILES_CHKSUM = \
"file://hello.c;beginline=3;endline=21;md5=58e..."
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} -o hello ${WORKDIR}/hello.c
}
do_install() {
install -d ${D}${bindir}
install -m 0755 hello ${D}${bindir}
Recipes:
Example:with a version agnostic part
tar.inc
SUMMARY = "GNU file archiving program"
HOMEPAGE = "http://www.gnu.org/software/tar/"
SECTION = "base"
SRC_URI = "${GNU_MIRROR}/tar/tar-${PV}.tar.bz2"
do_configure() { ... }
do_compile() { ... }
do_install() { ... }
Recipes:
Example:with a version agnostic part
tar_1.17.bb
require tar.inc
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = \
"file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552"
SRC_URI += "file://avoid_heap_overflow.patch"
SRC_URI[md5sum] = "c6c4f1c075dbf0f75c29737faa58f290"
Recipes:
Example:with a version agnostic part
tar_1.27.bb
require tar.inc
LICENSE = "GPLv3"
LIC_FILES_CHKSUM = \
"file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
SRC_URI[md5sum] = "2cee42a2ff4f1cd4f9298eeeb2264519"
Classes
Introduction
● Classes provide an abstraction to common code, which can bere-used in
multiple packages.
●Common tasks do not have to be re-developed!
●Any metadata and task which can be put in a recipe can be used in a class.
●Classes extension is .bbclass
●Classes are located in the classes folder of a layer.
●Packages can use this common code by inheriting a class: inherit
inherit <class>
Classes
Common Classes
● Common classes can be found in meta/classes/
–base.bbclass
–kernel.bbclass
–autotools.bbclass
–update-alternatives.bbclass
–useradd.bbclass
...
Classes
Base Class
●Every recipe inherits the base class automatically.
●Contains a set of basic common tasks to fetch, unpack or compile
packages.
● Inherits other common classes, providing:
–Mirrors definitions: DEBIAN_MIRROR, GNU_MIRROR,
KERNELORG_MIRROR...
–The ability to filter patches by SRC_URI
–Some tasks: clean, listtasks or fetchall.
●Defines oe_runmake, using EXTRA_OEMAKE to use custom
arguments.
Classes
Kernel Class
●Used to build Linux kernels.
●Defines tasks to configure, compile and install a kernel and its
modules.
●The kernel is divided into several packages:
–kernel, kernel-base, kernel-dev, kernel-modules...
●Automatically provides the virtual package virtual/kernel.
●Configuration variables are available:
–KERNEL_IMAGETYPE, defaults to zImage
–KERNEL_EXTRA_ARGS
–INITRAMFS_IMAGE
Classes
The autotools Class
●Defines tasks and metadata to handle packages using the autotools
buildsystem (autoconf, automake and libtool):
–do_configure: generates the configure script using autoreconf
and loads it with standard arguments or cross-compilation.
–do_compile: runs make
–do_install: runs make install
●Extra configuration parameters can be passed with EXTRA_OECONF.
●Compilation flags can be added thanks to the EXTRA_OEMAKE
variable.
Classes
The update-alternative class
●Allows to install multiple binaries having the same functionality,
avoiding conflicts by renaming the binaries.
●Four variables are used to configure the class:
–ALTERNATIVE The name of the binary.
–ALTERNATIVE_LINK_NAME The path of the resulting binary.
–ALTERNATIVE_PRIORITY The alternative priority.
●The command with the highest priority will be used
Classes
The useradd class
●This class helps to add users to the resulting image.
●Adding custom users is required by many services to avoid running them as root.
●USERADD_PACKAGES must be defined when the useradd class is
inherited. Defines the list of packages which needs the user.
●Users and groups will be created before the packages using it perform
their do_install.
●At least one of the two following variables must be set:
–USERADD_PARAM: parameters to pass to useradd.
–GROUPADD_PARAM: parameters to pass to groupadd.
Classes
The useradd class : Example
DESCRIPTION = "useradd class usage example"
PRIORITY = "optional"
SECTION = "examples"
LICENSE = "MIT"
SRC_URI = "file://file0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bc..."
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM = "-u 1000 -d /home/user0 -s /bin/bash user0"
do_install() {
install -m 644 file0 ${D}/home/user0/
chown user0:user0 ${D}/home/user0/file0
}
Binary Packages
●It is possible to install binaries into the generated root filesystem.
●Use the do_install task to copy the binaries into the root file system.
Bitbake File Inclusion
Locate files in the build system
●Metadata can be shared using included files.
●BitBake uses the BBPATH to find the files to be included. It also looks into the current directory.
●Three keywords can be used to include files from recipes, classes or other
configuration files:
–inherit
–include
–require
Bitbake File Inclusion
The inherit keyword
● inherit can be used in recipes or classes, to inherit the functionalities of a class.
●To inherit the functionalities of the kernel class, use: inherit kernel
BBPATH.
inherit ${FOO}
Bitbake File Inclusion
The include & require keyword
● include and require can be used in all files, to insert the content of another file at
that location.
● If the path specified on the include (or require) path is relative, BitBake will insert
the first file found in BBPATH.
● include does not produce an error when a file cannot be found, whereas require
raises a parsing error.
●To include a local file: include example.inc
●To include a file from another location (which could be in another layer):
include path/to/file.inc
Layers