Yocto Slides
Yocto Slides
Yocto Slides
Corrections, suggestions, contributions and translations are welcome! embedded Linux and kernel engineering
Send them to feedback@bootlin.com
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/301
Yocto Project and OpenEmbedded system development training
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/301
About Bootlin
About Bootlin
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/301
Bootlin introduction
▶ Engineering company
• In business since 2004
• Before 2018: Free Electrons
▶ Team based in France and Italy
▶ Serving customers worldwide
▶ Highly focused and recognized expertise
• Embedded Linux
• Linux kernel
• Embedded Linux build systems
▶ Strong open-source contributor
▶ Activities
• Engineering services
• Training courses
▶ https://bootlin.com
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/301
Bootlin engineering services
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/301
Bootlin training courses
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/301
Bootlin, an open-source contributor
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/301
Bootlin on-line resources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/301
Generic course information
Generic course
information
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/301
Two supported hardware platforms
Two variants for this course, each using a different hardware platform.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/301
Shopping list: BeagleBone Black Wireless variant
562?qs=k%2Fsw%252B3Yi%2FUbELBjXQpiBUQ%3D%3D
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/301
Shopping list: STM32MP1 Discovery Kit variant
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/301
Supported hardware
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 13/301
Supported hardware
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/301
Training quiz and certificate
▶ You have been given a quiz to test your knowledge on the topics covered by the
course. That’s not too late to take it if you haven’t done it yet!
▶ At the end of the course, we will submit this quiz to you again. That time, you
will see the correct answers.
▶ It allows Bootlin to assess your progress thanks to the course. That’s also a kind
of challenge, to look for clues throughout the lectures and labs / demos, as all the
answers are in the course!
▶ Another reason is that we only give training certificates to people who achieve at
least a 50% score in the final quiz and who attended all the sessions.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/301
Participate!
During the lectures...
▶ Don’t hesitate to ask questions. Other people in the audience may have similar
questions too.
▶ Don’t hesitate to share your experience too, for example to compare Linux with
other operating systems you know.
▶ Your point of view is most valuable, because it can be similar to your colleagues’
and different from the trainer’s.
▶ In on-line sessions
• Please keep your camera on too if you have one.
• Also make sure your name is properly filled.
• If Jitsi Meet is used, you can also use the ”Raise your hand” button when you wish
to ask a question but don’t want to interrupt.
▶ All this helps the trainer to engage with participants, see when something needs
clarifying and make the session more interactive, enjoyable and useful for everyone.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/301
Collaborate!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/301
Practical lab - Training Setup
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/301
Introduction to Embedded Linux
Introduction to
Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/301
Simplified Linux system architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/301
Overall Linux boot sequence
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/301
Embedded Linux work
▶ BSP work: porting the bootloader and Linux kernel, developing Linux device
drivers.
▶ system integration work: assembling all the user space components needed for
the system, configure them, develop the upgrade and recovery mechanisms, etc.
▶ application development: write the company-specific applications and libraries.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/301
Complexity of user space integration
ALL
xlib_libXrandr harfbuzz xlib_libXcursor xlib_libXdamage xlib_libXi xlib_libXinerama xproto_xcmiscproto xlib_libXres xlib_libXxf86vm xproto_xf86dgaproto mcookie xdata_xbitmaps xproto_bigreqsproto xproto_compositeproto xproto_glproto xkeyboard-config xproto_videoproto xlib_libxkbfile
xproto_randrproto cairo xproto_damageproto xlib_libXfixes xlib_libXft xproto_xineramaproto xproto_resourceproto xproto_xf86vidmodeproto host-xapp_xkbcomp xfont_font-cursor-misc xfont_font-misc-misc xfont_font-alias
xlib_libXrender xproto_fixesproto gdk-pixbuf fontconfig xlib_libXext host-xlib_libxkbfile host-xapp_mkfontdir host-xapp_bdftopcf host-xfont_font-util xfont_font-util
glibc host-gdk-pixbuf xproto_xf86bigfontproto xproto_xextproto xproto_inputproto xproto_kbproto freetype libxcb xlib_xtrans host-libxcb xfont_encodings xproto_fontsproto host-xproto_xf86bigfontproto host-xproto_inputproto host-xproto_kbproto host-xproto_xextproto host-xlib_xtrans host-xfont_encodings host-xproto_fontsproto
linux-headers host-gcc-initial host-gawk host-libglib2 libpng libpthread-stubs xcb-proto host-xcb-proto host-intltool xlib_libfontenc xlib_libXdmcp xlib_libXau host-libxslt host-libpthread-stubs host-xapp_mkfontscale xproto_presentproto
host-binutils libffi host-libffi host-gettext host-libpng zlib host-python host-libxml-parser-perl xproto_xproto xutil_util-macros host-libxml2 host-freetype host-xlib_libfontenc host-xlib_libXau host-xlib_libXdmcp
host-gmp host-libtool
host-m4
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/301
System integration: several possibilities
Pros Cons
Building everything manually Full flexibility Dependency hell
Learning experience Need to understand a lot of details
Version compatibility
Lack of reproducibility
Binary distribution Easy to create and extend Hard to customize
Debian, Ubuntu, Fedora, etc. Hard to optimize (boot time, size)
Hard to rebuild the full system from source
Large system
Uses native compilation (slow)
No well-defined mechanism to generate an
image
Lots of mandatory dependencies
Not available for all architectures
Build systems Nearly full flexibility Not as easy as a binary distribution
Buildroot, Yocto, PTXdist, etc. Built from source: customization and op- Build time
timization are easy
Fully reproducible
Uses cross-compilation
Have embedded specific packages not nec-
essarily in desktop distros
Make more features optional
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/301
Embedded Linux build system: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/301
Embedded Linux build system: tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/301
Yocto Project and Poky reference system overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 27/301
Yocto Project and Poky reference system overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/301
About
▶ The Yocto Project is a set of templates, tools and methods that allow to build
custom embedded Linux-based systems.
▶ It is an open source project initiated by the Linux Foundation in 2010 and is still
managed by one of its fellows: Richard Purdie.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 29/301
Yocto: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 30/301
The Yocto Project lexicon
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 31/301
The Yocto Project lexicon
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 32/301
The Yocto Project lexicon
▶ Organization of OpenEmbedded-Core:
• Recipes describe how to fetch, configure, compile and package applications and
images. They have a specific syntax.
• Layers are sets of recipes, matching a common purpose. For Texas Instruments
board support, the meta-ti-bsp layer is used.
• Multiple layers are used within a same distribution, depending on the requirements.
• It supports the ARM, MIPS (32 and 64 bits), PowerPC, RISC-V and x86 (32 and 64
bits) architectures.
• It supports QEMU emulated machines for these architectures.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 33/301
The Yocto Project lexicon
▶ The Yocto Project is not used as a finite set of layers and tools.
▶ Instead, it provides a common base of tools and layers on top of which custom
and specific layers are added, depending on your target.
▶ The main required element is Poky, the reference system which includes
OpenEmbedded-Core. Other available tools are optional, but may be useful in
some cases.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 34/301
Example of a Yocto Project based BSP
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 35/301
Yocto Project and Poky reference system overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 36/301
Getting the Poky reference system
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 37/301
Poky
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 38/301
Poky source tree 1/2
bitbake/ Holds all scripts used by the BitBake command. Usually matches the
stable release of the BitBake project.
documentation/ All documentation sources for the Yocto Project documentation. Can
be used to generate nice PDFs.
meta/ Contains the OpenEmbedded-Core metadata.
meta-skeleton/ Contains template recipes for BSP and kernel development.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 39/301
Poky source tree 2/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 40/301
Documentation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 41/301
Using Yocto Project - basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 42/301
Using Yocto Project - basics
Environment setup
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 43/301
Environment setup
▶ All Poky files are left unchanged when building a custom image.
▶ Specific configuration files and build repositories are stored in a separate build
directory.
▶ A script, oe-init-build-env, is provided to set up the build directory and the
environment variables (needed to be able to use the bitbake command for
example).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 44/301
oe-init-build-env
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 45/301
Common targets
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 46/301
Exported environment variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 47/301
Available commands
bitbake The main build engine command. Used to perform tasks on available
recipes (download, configure, compile…).
bitbake-* Various specific commands related to the BitBake build engine.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 48/301
The build/ directory 1/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 49/301
The build/ directory 2/2
tmp/buildstats/ Build statistics for all packages built (CPU usage, elapsed time, host,
timestamps…).
tmp/deploy/ Final output of the 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 applications for the target
but also for the host.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 50/301
Using Yocto Project - basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 51/301
The build/conf/ directory
▶ 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.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 52/301
Configuring the build
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 53/301
Using Yocto Project - basics
Building an image
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 54/301
Compilation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 55/301
Practical lab - First Yocto build
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 56/301
Using Yocto Project - advanced usage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 57/301
Advanced build usage and configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 58/301
A little reminder
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 59/301
Using Yocto Project - advanced usage
Variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 60/301
Overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 61/301
Operators
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 62/301
Operators caveats
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 63/301
Overrides
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 64/301
Overrides to modify variable values
▶ The append override adds at the end of the variable (without space).
• IMAGE_INSTALL:append = " dropbear" adds dropbear to the packages installed
on the image.
▶ The prepend override adds at the beginning of the variable (without space).
• FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" adds the folder to the set of
paths where files are located (in a recipe).
▶ The remove override removes all occurrences of a value within a variable.
• IMAGE_INSTALL:remove = "i2c-tools"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 65/301
Overrides for conditional assignment
▶ Append the machine name to only define a configuration variable for a given
machine. It tries to match with values from OVERRIDES which includes MACHINE,
SOC_FAMILY.
OVERRIDES="arm:armv7a:ti-soc:ti33x:beaglebone:poky"
KERNEL_DEVICETREE:beaglebone = "am335x-bone.dtb" # This is applied
KERNEL_DEVICETREE:dra7xx-evm = "dra7-evm.dtb" # This is ignored
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 66/301
Combining overrides 1/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 67/301
Combining overrides 2/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 68/301
Order of variable assignment
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 69/301
Using Yocto Project - advanced usage
Packages variants
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 70/301
Introduction to package variants
▶ Some packages have the same purpose, and only one can be used at a time.
▶ The build system uses virtual packages to reflect this. A virtual package
describes functionalities and several packages may provide it.
▶ Only one of the packages that provide the functionality will be compiled and
integrated into the resulting image.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 71/301
Variant examples
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 72/301
Package selection
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 73/301
Version selection
▶ By default, Bitbake will try to build the provider with the highest version number,
from the highest priority layer, unless the recipe defines
DEFAULT_PREFERENCE = "-1"
▶ When multiple package versions are available, it is also possible to explicitly pick a
given version with PREFERRED_VERSION.
▶ The package names have to suffix this variable.
▶ % can be used as a wildcard.
▶ Example:
• PREFERRED_VERSION_nginx = "1.20.1"
• PREFERRED_VERSION_linux-yocto = "5.14%"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 74/301
Using Yocto Project - advanced usage
Packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 75/301
Selection
▶ The set of packages installed into the image is defined by the target you choose
(e.g. core-image-minimal).
▶ It is possible to have a custom set by defining our own target, and we will see this
later.
▶ When developing or debugging, adding packages can be useful, without modifying
the recipes.
▶ Packages are controlled by the IMAGE_INSTALL configuration variable.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 76/301
Exclusion
▶ The list of packages to install is also filtered using the PACKAGE_EXCLUDE variable.
▶ If you choose to not install a package using this variable and some other package
is dependent on it (i.e. listed in a recipe’s RDEPENDS variable), the
OpenEmbedded build system generates a fatal installation error.
▶ This only works with RPM and IPK packages.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 77/301
Using Yocto Project - advanced usage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 78/301
Common BitBake options
▶ BitBake can be used to run a full build for a given target with bitbake [target]
• target is a recipe name, possibly with modifiers, e.g. -native
• bitbake ncurses
• bitbake ncurses-native
▶ But it can be more precise, with optional options:
-c <task> execute the given task
-s list all locally available recipes and their versions
-f force the given task to be run by removing its stamp file
world keyword for all recipes
-b <recipe> execute tasks from the given recipe (without resolving
dependencies).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 79/301
BitBake examples
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 80/301
shared state cache
▶ BitBake stores the output of each task in a directory, the shared state cache. Its
location is controlled by the SSTATE_DIR variable.
▶ This cache is use to speed up compilation.
▶ Over time, as you compile more recipes, it can grow quite big. It is possible to
clean old data with:
$ ./scripts/sstate-cache-management.sh -y -d \
--cache-dir=$SSTATE_DIR
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 81/301
Practical lab - Advanced Yocto configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 82/301
Writing recipes - basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 83/301
Writing recipes - basics
Recipes: overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 84/301
Recipes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 85/301
Basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 86/301
Content of a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 87/301
Common variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 88/301
Writing recipes - basics
Organization of a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 89/301
Organization of a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 90/301
Organization of a recipe
▶ Many applications 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:
• <application>.inc: version agnostic metadata.
• <application>_<version>.bb: require <application>.inc and version specific
metadata.
▶ We can divide a recipe into three main parts:
• The header: what/who
• The sources: where
• The tasks: how
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 91/301
The header
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 92/301
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 application.
▶ 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
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 93/301
The source locations: remote files 1/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 94/301
The source locations: remote files 2/2
▶ 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..."
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 95/301
The source locations: local files
▶ All local files found in SRC_URI are copied into the recipe’s working directory, in
$BUILDDIR/tmp/work/.
▶ The searched paths are defined in the FILESPATH variable.
FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}",
"${FILE_DIRNAME}/${BPN}","${FILE_DIRNAME}/files"], d)}
FILESOVERRIDES = "${TRANSLATED_TARGET_ARCH}:
${MACHINEOVERRIDES}:${DISTROOVERRIDES}"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 97/301
The source locations: license files
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.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 98/301
Dependencies 1/2
▶ A recipe can have dependencies during the build or at runtime. To reflect these
requirements in the recipe, two variables are used:
DEPENDS List of the recipe build-time dependencies.
RDEPENDS List of the package runtime dependencies. Must be package specific
(e.g. with :${PN}).
▶ DEPENDS = "recipe-b": the local do_prepare_recipe_sysroot task depends on
the do_populate_sysroot task of recipe-b.
▶ RDEPENDS:${PN} = "recipe-b": the local do_build task depends on the
do_package_write_<archive-format> task of recipe b.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 99/301
Dependencies 2/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 100/301
Tasks
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 101/301
Writing tasks 1/2
▶ Functions use the sh shell syntax, with available OpenEmbedded variables and
internal functions available.
WORKDIR the recipe’s working directory
S The directory where the source code is extracted
B The directory where bitbake places the objects generated during the
build
D The destination directory (root directory of where the files are
installed, before creating the image).
▶ Syntax of a task:
do_task() {
action0
action1
...
}
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 102/301
Writing tasks 2/2
▶ Example:
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}${bindir}
install -m 0755 hello ${D}${bindir}
}
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 103/301
Modifying existing tasks
do_install:append() {
install -d ${D}${sysconfdir}
install -m 0644 hello.conf ${D}${sysconfdir}
}
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 104/301
Adding new tasks
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 105/301
Writing recipes - basics
Applying patches
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 106/301
Patches use cases
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 107/301
The source locations: patches
▶ Files ending in .patch, .diff or having the apply=yes parameter will be applied
after the sources are retrieved and extracted, during the do_patch task.
SRC_URI += "file://joystick-support.patch \
file://smp-fixes.diff \
"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 108/301
Resolving conflicts
▶ The PATCHRESOLVE variable defines how to handle conflicts when applying patches.
▶ It has two valid values:
• noop: the build fails if a patch cannot be successfully applied.
• user: a shell is launched to resolve manually the conflicts.
▶ By default, PATCHRESOLVE = "noop" in meta-poky.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 109/301
Writing recipes - basics
Example of a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 110/301
Hello world recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 111/301
Writing recipes - basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 112/301
tar.inc
SRC_URI = "${GNU_MIRROR}/tar/tar-${PV}.tar.bz2"
do_configure() { ... }
do_compile() { ... }
do_install() { ... }
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 113/301
tar_1.17.bb
require tar.inc
LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = \
"file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552"
SRC_URI += "file://avoid_heap_overflow.patch"
SRC_URI[md5sum] = "c6c4f1c075dbf0f75c29737faa58f290"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 114/301
tar_1.26.bb
require tar.inc
LICENSE = "GPL-3.0-only"
LIC_FILES_CHKSUM = \
"file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
SRC_URI[md5sum] = "2cee42a2ff4f1cd4f9298eeeb2264519"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 115/301
Practical lab - Add a custom application
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 116/301
Writing recipes - advanced
Writing recipes -
advanced
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 117/301
Writing recipes - advanced
Extending a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 118/301
Introduction to recipe extensions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 119/301
Introduction to recipe extensions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 120/301
Extend a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 121/301
Extend a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 122/301
Writing recipes - advanced
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 123/301
Hello world append file
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://custom-modification-0.patch \
file://custom-modification-1.patch \
"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 124/301
Writing recipes - advanced
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 125/301
Advanced configuration
▶ In the real word, more complex configurations are often needed because recipes
may:
• Provide virtual packages
• Inherit generic functions from classes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 126/301
Providing virtual packages
▶ BitBake allows to use virtual names instead of the actual package name. We saw
a use case with package variants.
▶ The virtual name is specified through the PROVIDES variable.
▶ Several recipes can provide the same virtual name. Only one will be built and
installed into the generated image.
▶ PROVIDES = "virtual/kernel"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 127/301
Writing recipes - advanced
Classes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 128/301
Introduction to classes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 129/301
Common classes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 130/301
The base class
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 131/301
The kernel class
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 132/301
The autotools class
▶ Defines tasks and metadata to handle applications using the autotools build
system (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.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 133/301
Example: use the autotools class
SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
SRC_URI[md5sum] = "67607d2616a0faaf5bc94c59dca7c3cb"
SRC_URI[sha256sum] = "ecbb7a2214196c57ff9340aa71458e1559abd38f6d8d169666846935df191ea7"
LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
inherit autotools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 134/301
The useradd class
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 135/301
Example: use the useradd class
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
}
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 136/301
Writing recipes - advanced
Binary packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 137/301
Specifics for binary packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 138/301
Writing recipes - advanced
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 139/301
Locate files in the build system
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 140/301
The inherit keyword
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 141/301
The include and require keywords
▶ 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 ninvaders.inc
▶ To include a file from another location (which could be in another layer):
require path/to/file.inc
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 142/301
Writing recipes - advanced
Debugging recipes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 143/301
Debugging recipes
▶ For each task, logs are available in the temp directory in the work folder of a
recipe. This includes both the actual tasks code that ran and the output of the
task.
▶ bitbake can dump the whole environment, including the variable values and how
they were set:
$ bitbake -e ninvaders
# $DEPENDS [4 operations]
# set /yocto-labs/poky/meta/conf/bitbake.conf:268
# ""
# set /yocto-labs/poky/meta/conf/documentation.conf:130
# [doc] "Lists a recipe's build-time dependencies (i.e. other recipe files)."
# :prepend /yocto-training/yocto-labs/poky/meta/classes/base.bbclass:74
# "${BASEDEPENDS} "
# set /yocto-labs/meta-bootlinlabs/recipes-games/ninvaders/ninvaders.inc:11
# "ncurses"
# pre-expansion value:
# "${BASEDEPENDS} ncurses"
DEPENDS="virtual/arm-poky-linux-gnueabi-gcc virtual/arm-poky-linux-gnueabi-compilerlibs virtual/libc ncurses"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 144/301
Debugging recipes
▶ A development shell, exporting the full environment can be used to debug build
failures:
$ bitbake -c devshell <recipe>
▶ To understand what a change in a recipe implies, you can activate build history in
local.conf:
INHERIT += "buildhistory"
BUILDHISTORY_COMMIT = "1"
Then use the buildhistory-diff tool to examine differences between two builds.
• buildhistory-diff
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 145/301
Writing recipes - advanced
Network usage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 146/301
Source fetching
▶ BitBake will look for files to retrieve at the following locations, in order:
1. DL_DIR (the local download directory).
2. The PREMIRRORS locations.
3. The upstream source, as defined in SRC_URI.
4. The MIRRORS locations.
▶ If all the mirrors fail, the build will fail.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 147/301
Mirror configuration in OpenEmbedded-Core
meta/classes/mirrors.bbclass
PREMIRRORS += "git://sourceware.org/git/glibc.git https://downloads.yoctoproject.org/mirror/sources/ \
git://sourceware.org/git/binutils-gdb.git https://downloads.yoctoproject.org/mirror/sources/"
MIRRORS += "\
svn://.*/.* http://sources.openembedded.org/ \
git://.*/.* http://sources.openembedded.org/ \
https?://.*/.* http://sources.openembedded.org/ \
ftp://.*/.* http://sources.openembedded.org/ \
...
"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 148/301
Configuring the premirrors
INHERIT += "own-mirrors"
SOURCE_MIRROR_URL = "http://example.com/my-mirror"
▶ For a more complex setup, prepend custom mirrors to the PREMIRRORS variable:
PREMIRRORS:prepend = "\
git://.*/.* http://example.com/my-mirror-for-git/ \
svn://.*/.* http://example.com/my-mirror-for-svn/ \
http://.*/.* http://www.yoctoproject.org/sources/ \
https://.*/.* http://www.yoctoproject.org/sources/ "
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 149/301
Forbidding network access
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 150/301
Layers
Layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 151/301
Layers
Introduction to layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 152/301
Layers’ principles
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 153/301
Layers in Poky
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 154/301
Layers in Poky
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 155/301
Third party layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 156/301
Integrate and use a layer 1/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 157/301
Integrate and use a layer 2/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 158/301
Integrate and use a layer 3/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 159/301
Some useful layers
▶ Many SoC specific layers are available, providing support for the boards using
these SoCs. Some examples: meta-ti, meta-freescale and meta-raspberrypi.
▶ Other layers offer to support applications not available in the Poky reference
system:
• meta-browser: web browsers (Chromium, Firefox).
• meta-filesystems: support for additional filesystems.
• meta-gstreamer10: support for GStreamer 1.0.
• meta-java and meta-oracle-java: Java support.
• meta-linaro-toolchain: Linaro toolchain recipes.
• meta-qt5: QT5 modules.
• meta-realtime: real time tools and test programs.
• meta-telephony and many more…
Notice that some of these layers do not come with all the Yocto branches. The
meta-browser did not have a krogoth branch, for example.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 160/301
Layers
Creating a layer
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 161/301
Custom layer
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 162/301
Create a custom layer 1/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 163/301
Create a custom layer 2/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 164/301
Use a layer: best practices
▶ Do not copy and modify existing recipes from other layers. Instead use append
files.
▶ Avoid duplicating files. Use append files or explicitly use a path relative to other
layers.
▶ Save the layer alongside other layers, in OEROOT.
▶ Use LAYERDEPENDS to explicitly define layer dependencies.
▶ Use LAYERSERIES_COMPAT to define the Yocto version(s) with which the layer is
compatible.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 165/301
Practical lab - Create a custom layer
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 166/301
Practical lab - Extend a recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 167/301
BSP Layers
BSP Layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 168/301
BSP Layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 169/301
BSP layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 170/301
Overview
▶ BSP layers are device specific layers. They hold metadata with the purpose of
supporting specific hardware devices.
▶ BSP layers describe the hardware features and often provide a custom kernel and
bootloader with the required modules and drivers.
▶ BSP layers can also provide additional software, designed to take advantage of the
hardware features.
▶ As a layer, it is integrated into the build system as we previously saw.
▶ A good practice is to name it meta-<bsp_name>.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 171/301
BSP layers Specifics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 172/301
BSP Layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 173/301
Overview 1/2
▶ A layer provides one machine file (hardware configuration file) per machine it
supports.
▶ These configuration files are stored under
meta-<bsp_name>/conf/machine/*.conf
▶ The file names correspond to the values set in the MACHINE configuration variable.
• meta-ti/meta-ti-bsp/conf/machine/beaglebone.conf
• MACHINE = "beaglebone"
▶ Each machine should be described in the README file of the BSP.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 174/301
Overview 2/2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 175/301
Machine configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 176/301
MACHINE_FEATURES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 177/301
conf/machine/include/cfa10036.inc
SOC_FAMILY = "mxs:mx28:cfa10036"
PREFERRED_PROVIDER_virtual/kernel ?= "linux-cfa"
PREFERRED_PROVIDER_virtual/bootloader ?= "barebox"
IMAGE_BOOTLOADER = "barebox"
BAREBOX_BINARY = "barebox"
IMAGE_FSTYPES:mxs = "tar.bz2 barebox.mxsboot-sdcard sdcard.gz"
IMXBOOTLETS_MACHINE = "cfa10036"
KERNEL_IMAGETYPE = "zImage"
KERNEL_DEVICETREE = "imx28-cfa10036.dtb"
# we need the kernel to be installed in the final image
IMAGE_INSTALL:append = " kernel-image kernel-devicetree"
SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3"
SERIAL_CONSOLE = "115200 ttyAMA0"
MACHINE_FEATURES = "usbgadget usbhost vfat"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 178/301
conf/machine/cfa10057.conf
#@TYPE: Machine
#@NAME: Crystalfontz CFA-10057
#@SOC: i.MX28
#@DESCRIPTION: Machine configuration for CFA-10057, also called CFA-920
#@MAINTAINER: Alexandre Belloni <alexandre.belloni@bootlin.com>
include conf/machine/include/cfa10036.inc
KERNEL_DEVICETREE += "imx28-cfa10057.dtb"
MACHINE_FEATURES += "touchscreen"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 179/301
BSP Layers
Bootloader
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 180/301
Default bootloader 1/2
▶ By default the bootloader used is the mainline version of U-Boot, with a fixed
version (per Poky release).
▶ All the magic is done in meta/recipes-bsp/u-boot/u-boot.inc
▶ Some configuration variables used by the U-Boot recipe can be customized, in the
machine file.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 181/301
Default bootloader 2/2
SPL_BINARY If an SPL is built, describes the name of the output binary. Defaults to
an empty string.
UBOOT_SUFFIX bin (default) or img.
UBOOT_MACHINE The target used to build the configuration.
UBOOT_ENTRYPOINT The bootloader entry point.
UBOOT_LOADADDRESS The bootloader load address.
UBOOT_MAKE_TARGET Make target when building the bootloader. Defaults to
all.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 182/301
Customize the bootloader
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 183/301
BSP Layers
Kernel
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 184/301
Linux kernel recipes in Yocto
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 185/301
Linux Yocto 1/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 186/301
Linux Yocto 2/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 187/301
Linux Yocto 3/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 188/301
Linux Yocto: Kernel Metadata 1/2
▶ Kernel Metadata is a way to organize and to split the kernel configuration and
patches in little pieces each providing support for one feature.
▶ Two main configuration variables help taking advantage of this:
LINUX_KERNEL_TYPE standard (default), tiny or preempt-rt
• standard: generic Linux kernel policy.
• tiny: bare minimum configuration, for small kernels.
• preempt-rt: applies the PREEMPT_RT patch.
KERNEL_FEATURES List of features to enable. Features are sets of patches and
configuration fragments.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 189/301
Linux Yocto: Kernel Metadata 2/2
▶ Kernel Metadata description files have their own syntax to describe an optional
kernel feature
▶ A basic feature is defined as a patch to apply and a configuration fragment to add
▶ Simple example, features/nunchuk.scc
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 190/301
Practical lab - Create a custom machine configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 191/301
Distro Layers
Distro Layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 192/301
Distro Layers
Distro Layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 193/301
Distro layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 194/301
Distro layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 195/301
Best practice
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 196/301
Creating a Distro layer
require conf/distro/poky.conf
DISTRO = "distro"
DISTRO_NAME = "distro description"
DISTRO_VERSION = "1.0"
MAINTAINER = "..."
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 197/301
DISTRO_FEATURES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 198/301
Toolchain selection
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 199/301
Sample files
▶ A distro layer often contains sample files, used as templates to build key
configurations files.
▶ Example of sample files:
• bblayers.conf.sample
• local.conf.sample
▶ In Poky, they are in meta-poky/conf/.
▶ The TEMPLATECONF variable controls where to find the samples.
▶ It is set in ${OEROOT}/.templateconf.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 200/301
Distro Layers
Release management
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 201/301
Release management
There are multiple tasks that OE/bitbake based projects let you do on your own to
ensure build reproducibility:
▶ Code distribution and project setup.
▶ Release tagging
A separate tool is needed for that, usual solutions are:
▶ combo-layer, as done by Poky:
https://wiki.yoctoproject.org/wiki/Combo-layer
▶ git submodules + setup script. Great example in YOE:
https://github.com/YoeDistro/yoe-distro
▶ repo and templateconf or setup script
▶ kas
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 202/301
Distribute the distribution
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 203/301
Manifest example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 204/301
Retrieve the project using repo
▶ repo init uses the default.xml manifest in the repository, unless specified
otherwise.
▶ You can see the full repo documentation at
https://source.android.com/source/using-repo.html.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 205/301
repo: release
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 206/301
kas
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 207/301
kas configuration
header:
version: 8
machine: mymachine
distro: mydistro
target:
- myimage
repos:
meta-custom:
bitbake:
url: "https://git.openembedded.org/bitbake"
refspec: "2.0"
layers:
.: excluded
openembedded-core:
url: "https://git.openembedded.org/openembedded-core"
refspec: kirkstone
layers:
meta:
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 208/301
kas configuration
meta-freescale:
url: "https://github.com/Freescale/meta-freescale"
refspec: kirkstone
meta-openembedded:
url: https://git.openembedded.org/meta-openembedded
refspec: kirkstone
layers:
meta-oe:
meta-python:
meta-networking:
▶ Then a single command will build all the listed target for the machine:
$ kas build meta-custom/mymachine.yaml
▶ Or, alternatively, invoke bitbake commands:
$ kas shell /path/to/kas-project.yml -c 'bitbake dosfsutils-native'
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 209/301
Images
Images
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 210/301
Images
Introduction to images
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 211/301
Overview 1/3
▶ An image is the top level recipe and is used alongside the machine definition.
▶ Whereas the machine describes the hardware used and its capabilities, the image
is architecture agnostic and defines how the root filesystem is built, with what
packages.
▶ By default, several images are provided in Poky:
• meta*/recipes*/images/*.bb
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 212/301
Overview 2/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 213/301
Overview 3/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 214/301
Organization of an image recipe
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 215/301
Example of an image
require recipes-core/images/core-image-minimal.bb
IMAGE_INSTALL += "ninvaders"
LICENSE = "MIT"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 216/301
Images
Image types
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 217/301
IMAGE_FSTYPES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 218/301
Creating an image type
▶ If you have a particular layout on your storage (for example bootloader location on
an SD card), you may want to create your own image type.
▶ This is done through a class that inherits from image_types.
▶ It has to define a function named IMAGE_CMD_<type>.
▶ Append it to IMAGE_TYPES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 219/301
Creating an image conversion type
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 220/301
wic
▶ wic is a tool that can create a flashable image from the compiled packages and
artifacts.
▶ It can create partitions.
▶ It can select which files are located in which partition through the use of plugins.
▶ The final image layout is described in a .wks or .wks.in file.
▶ It can be extended in any layer.
▶ Usage example:
WKS_FILE = "imx-uboot-custom.wks.in"
IMAGE_FSTYPES = "wic.bmap wic"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 221/301
imx-uboot-custom.wks.in
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 222/301
Images
Package groups
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 223/301
Overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 224/301
Common package groups
▶ packagegroup-core-boot
▶ packagegroup-core-buildessential
▶ packagegroup-core-nfs-client
▶ packagegroup-core-nfs-server
▶ packagegroup-core-tools-debug
▶ packagegroup-core-tools-profile
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 225/301
Example
./meta/recipes-core/packagegroups/packagegroup-core-tools-debug.bb:
inherit packagegroup
RDEPENDS:${PN} = "\
gdb \
gdbserver \
strace"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 226/301
Practical lab - Create a custom image
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 227/301
Writing recipes - going further
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 228/301
Writing recipes - going further
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 229/301
Tasks in Python
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 230/301
Accessing the datastore with Python
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 231/301
Python code examples
# Anonymous function
python __anonymous() {
if d.getVar("FOO", True) == "example":
d.setVar("BAR", "Hello, World.")
}
# Task
python do_settime() {
import time
d.setVar("TIME", time.strftime('%Y%m%d', time.gmtime()))
}
# Inline
do_install() {
echo "Build OS: ${@os.uname()[0].lower()}"
}
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 232/301
Writing recipes - going further
Variable flags
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 233/301
Variable flags
▶ Variable flags are used to store extra information on tasks and variables.
SRC_URI[md5sum] = "97b2c3fb082241ab5c56ab728522622b"
▶ They are used to control task functionalities.
▶ A number of these flags are already used by BitBake:
• dirs: directories that should be created before the task runs. The last one becomes
the work directory for the task.
• noexec: disable the execution of the task.
• nostamp: do not create a stamp file when running the task. The task will always be
executed.
• doc: task documentation displayed by listtasks.
do_menuconfig[nostamp] = "1"
do_settime[noexec] = "1"
do_settime[doc] = "Set the current time in ${TIME}"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 234/301
Writing recipes - going further
Packages features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 235/301
Benefits
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 236/301
PACKAGECONFIG
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 237/301
Example: from ConnMan
PACKAGECONFIG[wifi] = "--enable-wifi, \
--disable-wifi, \
wpa-supplicant, \
wpa-supplicant"
PACKAGECONFIG[bluez] = "--enable-bluetooth, \
--disable-bluetooth, \
bluez5, \
bluez5"
PACKAGECONFIG[openvpn] = "--enable-openvpn, \
--disable-openvpn, \
, \
openvpn"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 238/301
Writing recipes - going further
Conditional features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 239/301
Conditional features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 240/301
Writing recipes - going further
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 241/301
Root filesystem generation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 242/301
Writing recipes - going further
Package splitting
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 243/301
Package splitting
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 244/301
Package splitting
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 245/301
PACKAGES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 246/301
FILES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 247/301
FILES: the main package
▶ The package named just ${PN} is the one that gets installed in the root filesystem.
▶ In Poky, defaults to:
FILES:${PN} = \
"${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
${sysconfdir} ${sharedstatedir} ${localstatedir} \
${base_bindir}/* ${base_sbindir}/* \
${base_libdir}/*${SOLIBS} \
${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
${datadir}/${BPN} ${libdir}/${BPN}/* \
${datadir}/pixmaps ${datadir}/applications \
${datadir}/idl ${datadir}/omf ${datadir}/sounds \
${libdir}/bonobo/servers"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 248/301
Example
require kexec-tools.inc
export LDFLAGS = "-L${STAGING_LIBDIR}"
EXTRA_OECONF = " --with-zlib=yes"
SRC_URI[md5sum] = \
"b9f2a3ba0ba9c78625ee7a50532500d8"
SRC_URI[sha256sum] = "..."
FILES:kexec = "${sbindir}/kexec"
FILES:kdump = "${sbindir}/kdump"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 249/301
Inspecting packages
oe-pkgdata-util is a tool that can help inspecting packages:
▶ Which package is shipping a file:
$ oe-pkgdata-util find-path /bin/busybox
busybox: /bin/busybox
Licensing
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 251/301
Licensing
Managing licenses
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 252/301
Tracking license changes
LIC_FILES_CHKSUM = " \
file://COPYING;md5=... \
file://src/file.c;beginline=3;endline=21;md5=..."
▶ LIC_FILES_CHKSUM is mandatory in every recipe, unless LICENSE is set to CLOSED.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 253/301
Package exclusion
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 254/301
Commercial licenses
LICENSE_FLAGS = "commercial"
▶ To build a package with a commercial component, the package must be in the
LICENSE_FLAGS_ACCEPTED variable.
▶ Example, gst-plugins-ugly:
LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 255/301
Listing licenses
OpenEmbbedded will generate a manifest of all the licenses of the software present on
the target image in $BUILDDIR/tmp/deploy/licenses/<image>/license.manifest
PACKAGE NAME: busybox
PACKAGE VERSION: 1.31.1
RECIPE NAME: busybox
LICENSE: GPL-2.0-only & bzip2-1.0.4
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 256/301
Providing license text
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 257/301
Providing sources
OpenEmbbedded provides the archiver class to generate tarballs of the source code:
▶ Use INHERIT += "archiver"
▶ Set the ARCHIVER_MODE variable, the default is to provide patched sources. To
provide configured sources:
ARCHIVER_MODE[src] = "configured"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 258/301
Application development workflow
Application
development workflow
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 259/301
Recommended workflows
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 260/301
Application development workflow
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 261/301
Overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 262/301
The Yocto Project SDK
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 263/301
Available SDKs
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 264/301
The generic SDK
▶ Mainly used for low-level development, where only the toolchain is needed:
• Bootloader development.
• Kernel development.
▶ The recipe meta-toolchain generates this SDK:
• bitbake meta-toolchain
▶ The generated script, containing all the tools for this SDK, is in:
• $BUILDDIR/tmp/deploy/sdk
• Example:
poky-glibc-x86_64-meta-toolchain-cortexa8hf-neon-toolchain-2.5.sh
▶ The SDK will be configured to be compatible with the specified MACHINE.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 265/301
The image-based SDK
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 266/301
Adding packages to the SDK
▶ Both can be appended to install more tools or libraries useful for development.
▶ Example: to have native curl on the SDK:
TOOLCHAIN_HOST_TASK:append = "nativesdk-curl"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 267/301
SDK format
▶ Both SDKs are distributed as bash scripts.
▶ These scripts self extract themselves to install the toolchains and the files they
provide.
▶ To install an SDK, retrieve the generated script and execute it.
• The script asks where to install the SDK. Defaults to /opt/poky/<version>
• Example: /opt/poky/2.5
$ ./poky-glibc-x86_64-meta-toolchain-cortexa8hf-neon-toolchain-2.5.sh
Poky (Yocto Project Reference Distro) SDK installer version 2.5
===============================================================
Enter target directory for SDK (default: /opt/poky/2.5):
You are about to install the SDK to "/opt/poky/2.5". Proceed[Y/n]?
Extracting SDK.................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source
the environment setup script e.g.
$ . /opt/poky/2.5/environment-setup-cortexa8hf-neon-poky-linux-gnueabi
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 268/301
Use the SDK
$ cd /opt/poky/2.5
$ source ./environment-setup-cortexa8hf-neon-poky-linux-gnueabi
▶ The PATH is updated to take into account the binaries installed alongside the SDK.
▶ Environment variables are exported to help using the tools.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 269/301
SDK installation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 270/301
SDK environment variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 271/301
Examples
$ unset LDFLAGS
$ make menuconfig
$ make
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 272/301
Application development workflow
Devtool
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 273/301
Overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 274/301
devtool usage 1/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 275/301
devtool usage 2/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 276/301
devtool usage 3/3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 277/301
Application development workflow
Quilt
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 278/301
Overview
▶ Quilt is a utility to manage patches which can be used without having a clean
source tree.
▶ It can be used to create patches for recipes already available in the build system.
▶ Be careful when using this workflow: the modifications won’t persist across builds!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 279/301
Using Quilt
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 280/301
Practical lab - Create and use a Poky SDK
▶ Generate an SDK
▶ Compile an application for the target in the
SDK
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 281/301
Runtime Package Management
Runtime Package
Management
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 282/301
Introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 283/301
Requirements
▶ First of all, you need a server to serve the packages to a private subnet or over the
Internet. Packages are typically served over https or http.
▶ Specific tools are also required on the target, and must be shipped on the
product. They should be included into the images generated by the build system.
▶ These tools will be specific to the package type used.
• This is similar to Linux distributions: Debian is using .deb related tools (dpkg,
apt…) while Fedora uses .rpm related ones (rpm, dnf).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 284/301
Runtime Package Management
Build configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 285/301
Build configuration 1/2
▶ The PACKAGE_CLASSES variable controls which package format to use. More than
one can be used.
▶ Valid values are package_rpm, package_deb, package_ipk.
▶ By default Poky uses the RPM format, while OpenEmbedded-Core uses the IPK
one.
▶ Example:
• PACKAGE_CLASSES = "package_ipk"
• PACKAGE_CLASSES = "package_rpm package_deb"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 286/301
Build configuration 2/2
To install the required tools on the target, there are two possible solutions:
▶ By adding package-management to the images features.
• The required tool will be installed on the target.
• The package database corresponding to the build will be installed as well.
▶ Or by manually adding the required tools in IMAGE_INSTALL. For example, to use
the IPK format we need opkg.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 287/301
Build considerations
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 288/301
Runtime Package Management
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 289/301
Apache2 example setup
<VirtualHost *:80>
ServerName packages.example.net
DocumentRoot /path/to/build/tmp/deploy/ipk
<Directory /path/to/build/tmp/deploy/ipk>
Options +Indexes
Options Indexes FollowSymLinks
Order allow,deny
allow from all
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 290/301
Runtime Package Management
Target configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 291/301
The IPK runtime management software
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 292/301
opkg usage
▶ opkg update: fetch and update the package databases, from the remote package
servers.
▶ opkg list: list available packages.
▶ opkg upgrade: upgrade all installed packages.
▶ opkg upgrade <package>: upgrade one package explicitly.
▶ opkg install <package>: install a specific package.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 293/301
opkg upgrade over an unstable network
# opkg update
# opkg --download-only upgrade
# opkg upgrade
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 294/301
Yocto Project Resources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 295/301
Yocto Project documentation
▶ https://docs.yoctoproject.org/
▶ Wiki: https://wiki.yoctoproject.org/wiki/Main_Page
▶ https://layers.openembedded.org/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 296/301
Useful Reading (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 297/301
Useful Reading (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 298/301
Last slides
Last slides
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 299/301
Last slide
Thank you!
And may the Source be with you
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 300/301
Rights to copy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 301/301