blob: ada5143b2a85b014ecfe10de3d3e071cad06c95d [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3**********************
4Yocto Project Concepts
5**********************
6
7This chapter provides explanations for Yocto Project concepts that go
8beyond the surface of "how-to" information and reference (or look-up)
9material. Concepts such as components, the :term:`OpenEmbedded Build System`
10workflow,
11cross-development toolchains, shared state cache, and so forth are
12explained.
13
14Yocto Project Components
15========================
16
17The :term:`BitBake` task executor
18together with various types of configuration files form the
19:term:`OpenEmbedded-Core (OE-Core)`. This section
20overviews these components by describing their use and how they
21interact.
22
23BitBake handles the parsing and execution of the data files. The data
24itself is of various types:
25
26- *Recipes:* Provides details about particular pieces of software.
27
28- *Class Data:* Abstracts common build information (e.g. how to build a
29 Linux kernel).
30
31- *Configuration Data:* Defines machine-specific settings, policy
32 decisions, and so forth. Configuration data acts as the glue to bind
33 everything together.
34
35BitBake knows how to combine multiple data sources together and refers
36to each data source as a layer. For information on layers, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -060037":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050038section of the Yocto Project Development Tasks Manual.
39
40Following are some brief details on these core components. For
41additional information on how these components interact during a build,
42see the
Andrew Geissler09209ee2020-12-13 08:44:15 -060043":ref:`overview-manual/concepts:openembedded build system concepts`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050044section.
45
Andrew Geisslerc9f78652020-09-18 14:11:35 -050046BitBake
47-------
48
49BitBake is the tool at the heart of the :term:`OpenEmbedded Build System`
50and is responsible
51for parsing the :term:`Metadata`, generating
52a list of tasks from it, and then executing those tasks.
53
54This section briefly introduces BitBake. If you want more information on
55BitBake, see the :doc:`BitBake User Manual <bitbake:index>`.
56
57To see a list of the options BitBake supports, use either of the
58following commands:
59::
60
61 $ bitbake -h
62 $ bitbake --help
63
64The most common usage for BitBake is ``bitbake recipename``, where
65``recipename`` is the name of the recipe you want to build (referred
66to as the "target"). The target often equates to the first part of a
67recipe's filename (e.g. "foo" for a recipe named ``foo_1.3.0-r0.bb``).
68So, to process the ``matchbox-desktop_1.2.3.bb`` recipe file, you might
69type the following:
70::
71
72 $ bitbake matchbox-desktop
73
74Several different
75versions of ``matchbox-desktop`` might exist. BitBake chooses the one
76selected by the distribution configuration. You can get more details
77about how BitBake chooses between different target versions and
78providers in the
Andrew Geissler09209ee2020-12-13 08:44:15 -060079":ref:`Preferences <bitbake:bitbake-user-manual/bitbake-user-manual-execution:preferences>`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -050080of the BitBake User Manual.
81
82BitBake also tries to execute any dependent tasks first. So for example,
83before building ``matchbox-desktop``, BitBake would build a cross
84compiler and ``glibc`` if they had not already been built.
85
86A useful BitBake option to consider is the ``-k`` or ``--continue``
87option. This option instructs BitBake to try and continue processing the
88job as long as possible even after encountering an error. When an error
89occurs, the target that failed and those that depend on it cannot be
90remade. However, when you use this option other dependencies can still
91be processed.
92
Andrew Geisslerc9f78652020-09-18 14:11:35 -050093Recipes
94-------
95
96Files that have the ``.bb`` suffix are "recipes" files. In general, a
97recipe contains information about a single piece of software. This
98information includes the location from which to download the unaltered
99source, any source patches to be applied to that source (if needed),
100which special configuration options to apply, how to compile the source
101files, and how to package the compiled output.
102
103The term "package" is sometimes used to refer to recipes. However, since
104the word "package" is used for the packaged output from the OpenEmbedded
105build system (i.e. ``.ipk`` or ``.deb`` files), this document avoids
106using the term "package" when referring to recipes.
107
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500108Classes
109-------
110
111Class files (``.bbclass``) contain information that is useful to share
112between recipes files. An example is the
113:ref:`autotools <ref-classes-autotools>` class,
114which contains common settings for any application that Autotools uses.
Andrew Geissler09209ee2020-12-13 08:44:15 -0600115The ":ref:`ref-manual/classes:Classes`" chapter in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500116Yocto Project Reference Manual provides details about classes and how to
117use them.
118
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500119Configurations
120--------------
121
122The configuration files (``.conf``) define various configuration
123variables that govern the OpenEmbedded build process. These files fall
124into several areas that define machine configuration options,
125distribution configuration options, compiler tuning options, general
126common configuration options, and user configuration options in
127``conf/local.conf``, which is found in the :term:`Build Directory`.
128
129
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500130Layers
131======
132
133Layers are repositories that contain related metadata (i.e. sets of
134instructions) that tell the OpenEmbedded build system how to build a
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500135target. :ref:`overview-manual/yp-intro:the yocto project layer model`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500136facilitates collaboration, sharing, customization, and reuse within the
137Yocto Project development environment. Layers logically separate
138information for your project. For example, you can use a layer to hold
139all the configurations for a particular piece of hardware. Isolating
140hardware-specific configurations allows you to share other metadata by
141using a different layer where that metadata might be common across
142several pieces of hardware.
143
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600144Many layers exist that work in the Yocto Project development environment. The
145:yocto_home:`Yocto Project Curated Layer Index </software-overview/layers/>`
146and :oe_layerindex:`OpenEmbedded Layer Index <>` both contain layers from
147which you can use or leverage.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500148
149By convention, layers in the Yocto Project follow a specific form.
150Conforming to a known structure allows BitBake to make assumptions
151during builds on where to find types of metadata. You can find
152procedures and learn about tools (i.e. ``bitbake-layers``) for creating
153layers suitable for the Yocto Project in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600154":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500155section of the Yocto Project Development Tasks Manual.
156
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500157OpenEmbedded Build System Concepts
158==================================
159
160This section takes a more detailed look inside the build process used by
161the :term:`OpenEmbedded Build System`,
162which is the build
163system specific to the Yocto Project. At the heart of the build system
164is BitBake, the task executor.
165
166The following diagram represents the high-level workflow of a build. The
167remainder of this section expands on the fundamental input, output,
168process, and metadata logical blocks that make up the workflow.
169
170.. image:: figures/YP-flow-diagram.png
171 :align: center
172
173In general, the build's workflow consists of several functional areas:
174
175- *User Configuration:* metadata you can use to control the build
176 process.
177
178- *Metadata Layers:* Various layers that provide software, machine, and
179 distro metadata.
180
181- *Source Files:* Upstream releases, local projects, and SCMs.
182
183- *Build System:* Processes under the control of
184 :term:`BitBake`. This block expands
185 on how BitBake fetches source, applies patches, completes
186 compilation, analyzes output for package generation, creates and
187 tests packages, generates images, and generates cross-development
188 tools.
189
190- *Package Feeds:* Directories containing output packages (RPM, DEB or
191 IPK), which are subsequently used in the construction of an image or
192 Software Development Kit (SDK), produced by the build system. These
193 feeds can also be copied and shared using a web server or other means
194 to facilitate extending or updating existing images on devices at
195 runtime if runtime package management is enabled.
196
197- *Images:* Images produced by the workflow.
198
199- *Application Development SDK:* Cross-development tools that are
200 produced along with an image or separately with BitBake.
201
202User Configuration
203------------------
204
205User configuration helps define the build. Through user configuration,
206you can tell BitBake the target architecture for which you are building
207the image, where to store downloaded source, and other build properties.
208
209The following figure shows an expanded representation of the "User
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500210Configuration" box of the :ref:`general workflow
211figure <overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500212
213.. image:: figures/user-configuration.png
214 :align: center
215
216BitBake needs some basic configuration files in order to complete a
217build. These files are ``*.conf`` files. The minimally necessary ones
218reside as example files in the ``build/conf`` directory of the
219:term:`Source Directory`. For simplicity,
220this section refers to the Source Directory as the "Poky Directory."
221
222When you clone the :term:`Poky` Git repository
223or you download and unpack a Yocto Project release, you can set up the
224Source Directory to be named anything you want. For this discussion, the
225cloned repository uses the default name ``poky``.
226
227.. note::
228
229 The Poky repository is primarily an aggregation of existing
230 repositories. It is not a canonical upstream source.
231
232The ``meta-poky`` layer inside Poky contains a ``conf`` directory that
233has example configuration files. These example files are used as a basis
234for creating actual configuration files when you source
235:ref:`structure-core-script`, which is the
236build environment script.
237
238Sourcing the build environment script creates a
239:term:`Build Directory` if one does not
240already exist. BitBake uses the Build Directory for all its work during
241builds. The Build Directory has a ``conf`` directory that contains
242default versions of your ``local.conf`` and ``bblayers.conf``
243configuration files. These default configuration files are created only
244if versions do not already exist in the Build Directory at the time you
245source the build environment setup script.
246
247Because the Poky repository is fundamentally an aggregation of existing
248repositories, some users might be familiar with running the
249:ref:`structure-core-script` script in the context of separate
250:term:`OpenEmbedded-Core (OE-Core)` and BitBake
251repositories rather than a single Poky repository. This discussion
252assumes the script is executed from within a cloned or unpacked version
253of Poky.
254
255Depending on where the script is sourced, different sub-scripts are
256called to set up the Build Directory (Yocto or OpenEmbedded).
257Specifically, the script ``scripts/oe-setup-builddir`` inside the poky
258directory sets up the Build Directory and seeds the directory (if
259necessary) with configuration files appropriate for the Yocto Project
260development environment.
261
262.. note::
263
264 The
265 scripts/oe-setup-builddir
266 script uses the
267 ``$TEMPLATECONF``
268 variable to determine which sample configuration files to locate.
269
270The ``local.conf`` file provides many basic variables that define a
271build environment. Here is a list of a few. To see the default
272configurations in a ``local.conf`` file created by the build environment
273script, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600274:yocto_git:`local.conf.sample </poky/tree/meta-poky/conf/local.conf.sample>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500275in the ``meta-poky`` layer:
276
277- *Target Machine Selection:* Controlled by the
278 :term:`MACHINE` variable.
279
280- *Download Directory:* Controlled by the
281 :term:`DL_DIR` variable.
282
283- *Shared State Directory:* Controlled by the
284 :term:`SSTATE_DIR` variable.
285
286- *Build Output:* Controlled by the
287 :term:`TMPDIR` variable.
288
289- *Distribution Policy:* Controlled by the
290 :term:`DISTRO` variable.
291
292- *Packaging Format:* Controlled by the
293 :term:`PACKAGE_CLASSES`
294 variable.
295
296- *SDK Target Architecture:* Controlled by the
297 :term:`SDKMACHINE` variable.
298
299- *Extra Image Packages:* Controlled by the
300 :term:`EXTRA_IMAGE_FEATURES`
301 variable.
302
303.. note::
304
305 Configurations set in the
306 conf/local.conf
307 file can also be set in the
308 conf/site.conf
309 and
310 conf/auto.conf
311 configuration files.
312
313The ``bblayers.conf`` file tells BitBake what layers you want considered
314during the build. By default, the layers listed in this file include
315layers minimally needed by the build system. However, you must manually
316add any custom layers you have created. You can find more information on
317working with the ``bblayers.conf`` file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600318":ref:`dev-manual/common-tasks:enabling your layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500319section in the Yocto Project Development Tasks Manual.
320
321The files ``site.conf`` and ``auto.conf`` are not created by the
322environment initialization script. If you want the ``site.conf`` file,
323you need to create that yourself. The ``auto.conf`` file is typically
324created by an autobuilder:
325
326- *site.conf:* You can use the ``conf/site.conf`` configuration
327 file to configure multiple build directories. For example, suppose
328 you had several build environments and they shared some common
329 features. You can set these default build properties here. A good
330 example is perhaps the packaging format to use through the
331 :term:`PACKAGE_CLASSES`
332 variable.
333
334 One useful scenario for using the ``conf/site.conf`` file is to
335 extend your :term:`BBPATH` variable
336 to include the path to a ``conf/site.conf``. Then, when BitBake looks
337 for Metadata using ``BBPATH``, it finds the ``conf/site.conf`` file
338 and applies your common configurations found in the file. To override
339 configurations in a particular build directory, alter the similar
340 configurations within that build directory's ``conf/local.conf``
341 file.
342
343- *auto.conf:* The file is usually created and written to by an
344 autobuilder. The settings put into the file are typically the same as
345 you would find in the ``conf/local.conf`` or the ``conf/site.conf``
346 files.
347
348You can edit all configuration files to further define any particular
349build environment. This process is represented by the "User
350Configuration Edits" box in the figure.
351
352When you launch your build with the ``bitbake target`` command, BitBake
353sorts out the configurations to ultimately define your build
354environment. It is important to understand that the
355:term:`OpenEmbedded Build System` reads the
356configuration files in a specific order: ``site.conf``, ``auto.conf``,
357and ``local.conf``. And, the build system applies the normal assignment
358statement rules as described in the
359":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`" chapter
360of the BitBake User Manual. Because the files are parsed in a specific
361order, variable assignments for the same variable could be affected. For
362example, if the ``auto.conf`` file and the ``local.conf`` set variable1
363to different values, because the build system parses ``local.conf``
364after ``auto.conf``, variable1 is assigned the value from the
365``local.conf`` file.
366
367Metadata, Machine Configuration, and Policy Configuration
368---------------------------------------------------------
369
370The previous section described the user configurations that define
371BitBake's global behavior. This section takes a closer look at the
372layers the build system uses to further control the build. These layers
373provide Metadata for the software, machine, and policies.
374
375In general, three types of layer input exists. You can see them below
376the "User Configuration" box in the `general workflow
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500377figure <overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500378
379- *Metadata (.bb + Patches):* Software layers containing
380 user-supplied recipe files, patches, and append files. A good example
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600381 of a software layer might be the :oe_layer:`meta-qt5 layer </meta-qt5>`
382 from the :oe_layerindex:`OpenEmbedded Layer Index <>`. This layer is for
383 version 5.0 of the popular `Qt <https://wiki.qt.io/About_Qt>`__
384 cross-platform application development framework for desktop, embedded and
385 mobile.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500386
387- *Machine BSP Configuration:* Board Support Package (BSP) layers (i.e.
388 "BSP Layer" in the following figure) providing machine-specific
389 configurations. This type of information is specific to a particular
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500390 target architecture. A good example of a BSP layer from the
391 :ref:`overview-manual/yp-intro:reference distribution (poky)` is the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600392 :yocto_git:`meta-yocto-bsp </poky/tree/meta-yocto-bsp>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500393 layer.
394
395- *Policy Configuration:* Distribution Layers (i.e. "Distro Layer" in
396 the following figure) providing top-level or general policies for the
397 images or SDKs being built for a particular distribution. For
398 example, in the Poky Reference Distribution the distro layer is the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600399 :yocto_git:`meta-poky </poky/tree/meta-poky>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500400 layer. Within the distro layer is a ``conf/distro`` directory that
401 contains distro configuration files (e.g.
Andrew Geissler09209ee2020-12-13 08:44:15 -0600402 :yocto_git:`poky.conf </poky/tree/meta-poky/conf/distro/poky.conf>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500403 that contain many policy configurations for the Poky distribution.
404
405The following figure shows an expanded representation of these three
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500406layers from the :ref:`general workflow figure
407<overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500408
409.. image:: figures/layer-input.png
410 :align: center
411
412In general, all layers have a similar structure. They all contain a
413licensing file (e.g. ``COPYING.MIT``) if the layer is to be distributed,
414a ``README`` file as good practice and especially if the layer is to be
415distributed, a configuration directory, and recipe directories. You can
416learn about the general structure for layers used with the Yocto Project
417in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600418":ref:`dev-manual/common-tasks:creating your own layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500419section in the
420Yocto Project Development Tasks Manual. For a general discussion on
421layers and the many layers from which you can draw, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500422":ref:`overview-manual/concepts:layers`" and
423":ref:`overview-manual/yp-intro:the yocto project layer model`" sections both
424earlier in this manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500425
426If you explored the previous links, you discovered some areas where many
Andrew Geissler09209ee2020-12-13 08:44:15 -0600427layers that work with the Yocto Project exist. The :yocto_git:`Source
428Repositories <>` also shows layers categorized under "Yocto Metadata Layers."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500429
430.. note::
431
432 Layers exist in the Yocto Project Source Repositories that cannot be
433 found in the OpenEmbedded Layer Index. These layers are either
434 deprecated or experimental in nature.
435
436BitBake uses the ``conf/bblayers.conf`` file, which is part of the user
437configuration, to find what layers it should be using as part of the
438build.
439
440Distro Layer
441~~~~~~~~~~~~
442
443The distribution layer provides policy configurations for your
444distribution. Best practices dictate that you isolate these types of
445configurations into their own layer. Settings you provide in
446``conf/distro/distro.conf`` override similar settings that BitBake finds
447in your ``conf/local.conf`` file in the Build Directory.
448
449The following list provides some explanation and references for what you
450typically find in the distribution layer:
451
452- *classes:* Class files (``.bbclass``) hold common functionality that
453 can be shared among recipes in the distribution. When your recipes
454 inherit a class, they take on the settings and functions for that
455 class. You can read more about class files in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600456 ":ref:`ref-manual/classes:Classes`" chapter of the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500457 Reference Manual.
458
459- *conf:* This area holds configuration files for the layer
460 (``conf/layer.conf``), the distribution
461 (``conf/distro/distro.conf``), and any distribution-wide include
462 files.
463
464- *recipes-*:* Recipes and append files that affect common
465 functionality across the distribution. This area could include
466 recipes and append files to add distribution-specific configuration,
467 initialization scripts, custom image recipes, and so forth. Examples
468 of ``recipes-*`` directories are ``recipes-core`` and
469 ``recipes-extra``. Hierarchy and contents within a ``recipes-*``
470 directory can vary. Generally, these directories contain recipe files
471 (``*.bb``), recipe append files (``*.bbappend``), directories that
472 are distro-specific for configuration files, and so forth.
473
474BSP Layer
475~~~~~~~~~
476
477The BSP Layer provides machine configurations that target specific
478hardware. Everything in this layer is specific to the machine for which
479you are building the image or the SDK. A common structure or form is
480defined for BSP layers. You can learn more about this structure in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600481:doc:`/bsp-guide/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500482
483.. note::
484
485 In order for a BSP layer to be considered compliant with the Yocto
486 Project, it must meet some structural requirements.
487
488The BSP Layer's configuration directory contains configuration files for
489the machine (``conf/machine/machine.conf``) and, of course, the layer
490(``conf/layer.conf``).
491
492The remainder of the layer is dedicated to specific recipes by function:
493``recipes-bsp``, ``recipes-core``, ``recipes-graphics``,
494``recipes-kernel``, and so forth. Metadata can exist for multiple
495formfactors, graphics support systems, and so forth.
496
497.. note::
498
499 While the figure shows several
500 recipes-\*
501 directories, not all these directories appear in all BSP layers.
502
503Software Layer
504~~~~~~~~~~~~~~
505
506The software layer provides the Metadata for additional software
507packages used during the build. This layer does not include Metadata
508that is specific to the distribution or the machine, which are found in
509their respective layers.
510
511This layer contains any recipes, append files, and patches, that your
512project needs.
513
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500514Sources
515-------
516
517In order for the OpenEmbedded build system to create an image or any
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500518target, it must be able to access source files. The :ref:`general workflow
519figure <overview-manual/concepts:openembedded build system concepts>`
520represents source files using the "Upstream Project Releases", "Local
521Projects", and "SCMs (optional)" boxes. The figure represents mirrors,
522which also play a role in locating source files, with the "Source
523Materials" box.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500524
525The method by which source files are ultimately organized is a function
526of the project. For example, for released software, projects tend to use
527tarballs or other archived files that can capture the state of a release
528guaranteeing that it is statically represented. On the other hand, for a
529project that is more dynamic or experimental in nature, a project might
530keep source files in a repository controlled by a Source Control Manager
531(SCM) such as Git. Pulling source from a repository allows you to
532control the point in the repository (the revision) from which you want
533to build software. Finally, a combination of the two might exist, which
534would give the consumer a choice when deciding where to get source
535files.
536
537BitBake uses the :term:`SRC_URI`
538variable to point to source files regardless of their location. Each
539recipe must have a ``SRC_URI`` variable that points to the source.
540
541Another area that plays a significant role in where source files come
542from is pointed to by the
543:term:`DL_DIR` variable. This area is
544a cache that can hold previously downloaded source. You can also
545instruct the OpenEmbedded build system to create tarballs from Git
546repositories, which is not the default behavior, and store them in the
547``DL_DIR`` by using the
548:term:`BB_GENERATE_MIRROR_TARBALLS`
549variable.
550
551Judicious use of a ``DL_DIR`` directory can save the build system a trip
552across the Internet when looking for files. A good method for using a
553download directory is to have ``DL_DIR`` point to an area outside of
554your Build Directory. Doing so allows you to safely delete the Build
555Directory if needed without fear of removing any downloaded source file.
556
557The remainder of this section provides a deeper look into the source
558files and the mirrors. Here is a more detailed look at the source file
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500559area of the :ref:`general workflow figure <overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500560
561.. image:: figures/source-input.png
562 :align: center
563
564Upstream Project Releases
565~~~~~~~~~~~~~~~~~~~~~~~~~
566
567Upstream project releases exist anywhere in the form of an archived file
568(e.g. tarball or zip file). These files correspond to individual
569recipes. For example, the figure uses specific releases each for
570BusyBox, Qt, and Dbus. An archive file can be for any released product
571that can be built using a recipe.
572
573Local Projects
574~~~~~~~~~~~~~~
575
576Local projects are custom bits of software the user provides. These bits
577reside somewhere local to a project - perhaps a directory into which the
578user checks in items (e.g. a local directory containing a development
579source tree used by the group).
580
581The canonical method through which to include a local project is to use
582the :ref:`externalsrc <ref-classes-externalsrc>`
583class to include that local project. You use either the ``local.conf``
584or a recipe's append file to override or set the recipe to point to the
585local directory on your disk to pull in the whole source tree.
586
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500587Source Control Managers (Optional)
588~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
589
590Another place from which the build system can get source files is with
Andrew Geissler09209ee2020-12-13 08:44:15 -0600591:ref:`fetchers <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` employing various Source
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500592Control Managers (SCMs) such as Git or Subversion. In such cases, a
593repository is cloned or checked out. The
594:ref:`ref-tasks-fetch` task inside
595BitBake uses the :term:`SRC_URI`
596variable and the argument's prefix to determine the correct fetcher
597module.
598
599.. note::
600
601 For information on how to have the OpenEmbedded build system generate
602 tarballs for Git repositories and place them in the
603 DL_DIR
604 directory, see the :term:`BB_GENERATE_MIRROR_TARBALLS`
605 variable in the Yocto Project Reference Manual.
606
607When fetching a repository, BitBake uses the
608:term:`SRCREV` variable to determine
609the specific revision from which to build.
610
611Source Mirror(s)
612~~~~~~~~~~~~~~~~
613
614Two kinds of mirrors exist: pre-mirrors and regular mirrors. The
615:term:`PREMIRRORS` and
616:term:`MIRRORS` variables point to
617these, respectively. BitBake checks pre-mirrors before looking upstream
618for any source files. Pre-mirrors are appropriate when you have a shared
619directory that is not a directory defined by the
620:term:`DL_DIR` variable. A Pre-mirror
621typically points to a shared directory that is local to your
622organization.
623
624Regular mirrors can be any site across the Internet that is used as an
625alternative location for source code should the primary site not be
626functioning for some reason or another.
627
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500628Package Feeds
629-------------
630
631When the OpenEmbedded build system generates an image or an SDK, it gets
632the packages from a package feed area located in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500633:term:`Build Directory`. The :ref:`general workflow figure
634<overview-manual/concepts:openembedded build system concepts>`
635shows this package feeds area in the upper-right corner.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500636
637This section looks a little closer into the package feeds area used by
638the build system. Here is a more detailed look at the area:
639
640.. image:: figures/package-feeds.png
641 :align: center
642
643Package feeds are an intermediary step in the build process. The
644OpenEmbedded build system provides classes to generate different package
645types, and you specify which classes to enable through the
646:term:`PACKAGE_CLASSES`
647variable. Before placing the packages into package feeds, the build
648process validates them with generated output quality assurance checks
649through the :ref:`insane <ref-classes-insane>`
650class.
651
652The package feed area resides in the Build Directory. The directory the
653build system uses to temporarily store packages is determined by a
654combination of variables and the particular package manager in use. See
655the "Package Feeds" box in the illustration and note the information to
656the right of that area. In particular, the following defines where
657package files are kept:
658
659- :term:`DEPLOY_DIR`: Defined as
660 ``tmp/deploy`` in the Build Directory.
661
662- ``DEPLOY_DIR_*``: Depending on the package manager used, the package
663 type sub-folder. Given RPM, IPK, or DEB packaging and tarball
664 creation, the
665 :term:`DEPLOY_DIR_RPM`,
666 :term:`DEPLOY_DIR_IPK`,
667 :term:`DEPLOY_DIR_DEB`, or
668 :term:`DEPLOY_DIR_TAR`,
669 variables are used, respectively.
670
671- :term:`PACKAGE_ARCH`: Defines
672 architecture-specific sub-folders. For example, packages could exist
673 for the i586 or qemux86 architectures.
674
675BitBake uses the
676:ref:`do_package_write_* <ref-tasks-package_write_deb>`
677tasks to generate packages and place them into the package holding area
678(e.g. ``do_package_write_ipk`` for IPK packages). See the
679":ref:`ref-tasks-package_write_deb`",
680":ref:`ref-tasks-package_write_ipk`",
681":ref:`ref-tasks-package_write_rpm`",
682and
683":ref:`ref-tasks-package_write_tar`"
684sections in the Yocto Project Reference Manual for additional
685information. As an example, consider a scenario where an IPK packaging
686manager is being used and package architecture support for both i586 and
687qemux86 exist. Packages for the i586 architecture are placed in
688``build/tmp/deploy/ipk/i586``, while packages for the qemux86
689architecture are placed in ``build/tmp/deploy/ipk/qemux86``.
690
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500691BitBake Tool
692------------
693
694The OpenEmbedded build system uses
695:term:`BitBake` to produce images and
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500696Software Development Kits (SDKs). You can see from the :ref:`general workflow
697figure <overview-manual/concepts:openembedded build system concepts>`,
698the BitBake area consists of several functional areas. This section takes a
699closer look at each of those areas.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500700
701.. note::
702
703 Separate documentation exists for the BitBake tool. See the
704 BitBake User Manual
705 for reference material on BitBake.
706
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500707Source Fetching
708~~~~~~~~~~~~~~~
709
710The first stages of building a recipe are to fetch and unpack the source
711code:
712
713.. image:: figures/source-fetching.png
714 :align: center
715
716The :ref:`ref-tasks-fetch` and
717:ref:`ref-tasks-unpack` tasks fetch
718the source files and unpack them into the
719:term:`Build Directory`.
720
721.. note::
722
723 For every local file (e.g.
724 file://
725 ) that is part of a recipe's
726 SRC_URI
727 statement, the OpenEmbedded build system takes a checksum of the file
728 for the recipe and inserts the checksum into the signature for the
729 do_fetch
730 task. If any local file has been modified, the
731 do_fetch
732 task and all tasks that depend on it are re-executed.
733
734By default, everything is accomplished in the Build Directory, which has
735a defined structure. For additional general information on the Build
736Directory, see the ":ref:`structure-core-build`" section in
737the Yocto Project Reference Manual.
738
739Each recipe has an area in the Build Directory where the unpacked source
740code resides. The :term:`S` variable points
741to this area for a recipe's unpacked source code. The name of that
742directory for any given recipe is defined from several different
743variables. The preceding figure and the following list describe the
744Build Directory's hierarchy:
745
746- :term:`TMPDIR`: The base directory
747 where the OpenEmbedded build system performs all its work during the
748 build. The default base directory is the ``tmp`` directory.
749
750- :term:`PACKAGE_ARCH`: The
751 architecture of the built package or packages. Depending on the
752 eventual destination of the package or packages (i.e. machine
753 architecture, :term:`Build Host`, SDK, or
754 specific machine), ``PACKAGE_ARCH`` varies. See the variable's
755 description for details.
756
757- :term:`TARGET_OS`: The operating
758 system of the target device. A typical value would be "linux" (e.g.
759 "qemux86-poky-linux").
760
761- :term:`PN`: The name of the recipe used
762 to build the package. This variable can have multiple meanings.
763 However, when used in the context of input files, ``PN`` represents
764 the name of the recipe.
765
766- :term:`WORKDIR`: The location
767 where the OpenEmbedded build system builds a recipe (i.e. does the
768 work to create the package).
769
770 - :term:`PV`: The version of the
771 recipe used to build the package.
772
773 - :term:`PR`: The revision of the
774 recipe used to build the package.
775
776- :term:`S`: Contains the unpacked source
777 files for a given recipe.
778
779 - :term:`BPN`: The name of the recipe
780 used to build the package. The ``BPN`` variable is a version of
781 the ``PN`` variable but with common prefixes and suffixes removed.
782
783 - :term:`PV`: The version of the
784 recipe used to build the package.
785
786.. note::
787
788 In the previous figure, notice that two sample hierarchies exist: one
789 based on package architecture (i.e.
790 PACKAGE_ARCH
791 ) and one based on a machine (i.e.
792 MACHINE
793 ). The underlying structures are identical. The differentiator being
794 what the OpenEmbedded build system is using as a build target (e.g.
795 general architecture, a build host, an SDK, or a specific machine).
796
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500797Patching
798~~~~~~~~
799
800Once source code is fetched and unpacked, BitBake locates patch files
801and applies them to the source files:
802
803.. image:: figures/patching.png
804 :align: center
805
806The :ref:`ref-tasks-patch` task uses a
807recipe's :term:`SRC_URI` statements
808and the :term:`FILESPATH` variable
809to locate applicable patch files.
810
811Default processing for patch files assumes the files have either
812``*.patch`` or ``*.diff`` file types. You can use ``SRC_URI`` parameters
813to change the way the build system recognizes patch files. See the
814:ref:`ref-tasks-patch` task for more
815information.
816
817BitBake finds and applies multiple patches for a single recipe in the
818order in which it locates the patches. The ``FILESPATH`` variable
819defines the default set of directories that the build system uses to
820search for patch files. Once found, patches are applied to the recipe's
821source files, which are located in the
822:term:`S` directory.
823
824For more information on how the source directories are created, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500825":ref:`overview-manual/concepts:source fetching`" section. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500826more information on how to create patches and how the build system
827processes patches, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600828":ref:`dev-manual/common-tasks:patching code`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500829section in the
830Yocto Project Development Tasks Manual. You can also see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600831":ref:`sdk-manual/extensible:use \`\`devtool modify\`\` to modify the source of an existing component`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500832section in the Yocto Project Application Development and the Extensible
833Software Development Kit (SDK) manual and the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600834":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500835section in the Yocto Project Linux Kernel Development Manual.
836
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500837Configuration, Compilation, and Staging
838~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
839
840After source code is patched, BitBake executes tasks that configure and
841compile the source code. Once compilation occurs, the files are copied
842to a holding area (staged) in preparation for packaging:
843
844.. image:: figures/configuration-compile-autoreconf.png
845 :align: center
846
847This step in the build process consists of the following tasks:
848
849- :ref:`ref-tasks-prepare_recipe_sysroot`:
850 This task sets up the two sysroots in
851 ``${``\ :term:`WORKDIR`\ ``}``
852 (i.e. ``recipe-sysroot`` and ``recipe-sysroot-native``) so that
853 during the packaging phase the sysroots can contain the contents of
854 the
855 :ref:`ref-tasks-populate_sysroot`
856 tasks of the recipes on which the recipe containing the tasks
857 depends. A sysroot exists for both the target and for the native
858 binaries, which run on the host system.
859
860- *do_configure*: This task configures the source by enabling and
861 disabling any build-time and configuration options for the software
862 being built. Configurations can come from the recipe itself as well
863 as from an inherited class. Additionally, the software itself might
864 configure itself depending on the target for which it is being built.
865
866 The configurations handled by the
867 :ref:`ref-tasks-configure` task
868 are specific to configurations for the source code being built by the
869 recipe.
870
871 If you are using the
872 :ref:`autotools <ref-classes-autotools>` class,
873 you can add additional configuration options by using the
874 :term:`EXTRA_OECONF` or
875 :term:`PACKAGECONFIG_CONFARGS`
876 variables. For information on how this variable works within that
877 class, see the
878 :ref:`autotools <ref-classes-autotools>` class
Andrew Geissler09209ee2020-12-13 08:44:15 -0600879 :yocto_git:`here </poky/tree/meta/classes/autotools.bbclass>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500880
881- *do_compile*: Once a configuration task has been satisfied,
882 BitBake compiles the source using the
883 :ref:`ref-tasks-compile` task.
884 Compilation occurs in the directory pointed to by the
885 :term:`B` variable. Realize that the
886 ``B`` directory is, by default, the same as the
887 :term:`S` directory.
888
889- *do_install*: After compilation completes, BitBake executes the
890 :ref:`ref-tasks-install` task.
891 This task copies files from the ``B`` directory and places them in a
892 holding area pointed to by the :term:`D`
893 variable. Packaging occurs later using files from this holding
894 directory.
895
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500896Package Splitting
897~~~~~~~~~~~~~~~~~
898
899After source code is configured, compiled, and staged, the build system
900analyzes the results and splits the output into packages:
901
902.. image:: figures/analysis-for-package-splitting.png
903 :align: center
904
905The :ref:`ref-tasks-package` and
906:ref:`ref-tasks-packagedata`
907tasks combine to analyze the files found in the
908:term:`D` directory and split them into
909subsets based on available packages and files. Analysis involves the
910following as well as other items: splitting out debugging symbols,
911looking at shared library dependencies between packages, and looking at
912package relationships.
913
914The ``do_packagedata`` task creates package metadata based on the
915analysis such that the build system can generate the final packages. The
916:ref:`ref-tasks-populate_sysroot`
917task stages (copies) a subset of the files installed by the
918:ref:`ref-tasks-install` task into
919the appropriate sysroot. Working, staged, and intermediate results of
920the analysis and package splitting process use several areas:
921
922- :term:`PKGD`: The destination
923 directory (i.e. ``package``) for packages before they are split into
924 individual packages.
925
926- :term:`PKGDESTWORK`: A
927 temporary work area (i.e. ``pkgdata``) used by the ``do_package``
928 task to save package metadata.
929
930- :term:`PKGDEST`: The parent
931 directory (i.e. ``packages-split``) for packages after they have been
932 split.
933
934- :term:`PKGDATA_DIR`: A shared,
935 global-state directory that holds packaging metadata generated during
936 the packaging process. The packaging process copies metadata from
937 ``PKGDESTWORK`` to the ``PKGDATA_DIR`` area where it becomes globally
938 available.
939
940- :term:`STAGING_DIR_HOST`:
941 The path for the sysroot for the system on which a component is built
942 to run (i.e. ``recipe-sysroot``).
943
944- :term:`STAGING_DIR_NATIVE`:
945 The path for the sysroot used when building components for the build
946 host (i.e. ``recipe-sysroot-native``).
947
948- :term:`STAGING_DIR_TARGET`:
949 The path for the sysroot used when a component that is built to
950 execute on a system and it generates code for yet another machine
951 (e.g. cross-canadian recipes).
952
953The :term:`FILES` variable defines the
954files that go into each package in
955:term:`PACKAGES`. If you want
956details on how this is accomplished, you can look at
Andrew Geissler09209ee2020-12-13 08:44:15 -0600957:yocto_git:`package.bbclass </poky/tree/meta/classes/package.bbclass>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500958
959Depending on the type of packages being created (RPM, DEB, or IPK), the
960:ref:`do_package_write_* <ref-tasks-package_write_deb>`
961task creates the actual packages and places them in the Package Feed
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500962area, which is ``${TMPDIR}/deploy``. You can see the
963":ref:`overview-manual/concepts:package feeds`" section for more detail on
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500964that part of the build process.
965
966.. note::
967
968 Support for creating feeds directly from the
969 deploy/\*
970 directories does not exist. Creating such feeds usually requires some
971 kind of feed maintenance mechanism that would upload the new packages
972 into an official package feed (e.g. the Ångström distribution). This
973 functionality is highly distribution-specific and thus is not
974 provided out of the box.
975
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500976Image Generation
977~~~~~~~~~~~~~~~~
978
979Once packages are split and stored in the Package Feeds area, the build
980system uses BitBake to generate the root filesystem image:
981
982.. image:: figures/image-generation.png
983 :align: center
984
985The image generation process consists of several stages and depends on
986several tasks and variables. The
987:ref:`ref-tasks-rootfs` task creates
988the root filesystem (file and directory structure) for an image. This
989task uses several key variables to help create the list of packages to
990actually install:
991
992- :term:`IMAGE_INSTALL`: Lists
993 out the base set of packages from which to install from the Package
994 Feeds area.
995
996- :term:`PACKAGE_EXCLUDE`:
997 Specifies packages that should not be installed into the image.
998
999- :term:`IMAGE_FEATURES`:
1000 Specifies features to include in the image. Most of these features
1001 map to additional packages for installation.
1002
1003- :term:`PACKAGE_CLASSES`:
1004 Specifies the package backend (e.g. RPM, DEB, or IPK) to use and
1005 consequently helps determine where to locate packages within the
1006 Package Feeds area.
1007
1008- :term:`IMAGE_LINGUAS`:
1009 Determines the language(s) for which additional language support
1010 packages are installed.
1011
1012- :term:`PACKAGE_INSTALL`:
1013 The final list of packages passed to the package manager for
1014 installation into the image.
1015
1016With :term:`IMAGE_ROOTFS`
1017pointing to the location of the filesystem under construction and the
1018``PACKAGE_INSTALL`` variable providing the final list of packages to
1019install, the root file system is created.
1020
1021Package installation is under control of the package manager (e.g.
1022dnf/rpm, opkg, or apt/dpkg) regardless of whether or not package
1023management is enabled for the target. At the end of the process, if
1024package management is not enabled for the target, the package manager's
1025data files are deleted from the root filesystem. As part of the final
1026stage of package installation, post installation scripts that are part
1027of the packages are run. Any scripts that fail to run on the build host
1028are run on the target when the target system is first booted. If you are
1029using a
Andrew Geissler09209ee2020-12-13 08:44:15 -06001030:ref:`read-only root filesystem <dev-manual/common-tasks:creating a read-only root filesystem>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001031all the post installation scripts must succeed on the build host during
1032the package installation phase since the root filesystem on the target
1033is read-only.
1034
1035The final stages of the ``do_rootfs`` task handle post processing. Post
1036processing includes creation of a manifest file and optimizations.
1037
1038The manifest file (``.manifest``) resides in the same directory as the
1039root filesystem image. This file lists out, line-by-line, the installed
1040packages. The manifest file is useful for the
1041:ref:`testimage <ref-classes-testimage*>` class,
1042for example, to determine whether or not to run specific tests. See the
1043:term:`IMAGE_MANIFEST`
1044variable for additional information.
1045
1046Optimizing processes that are run across the image include ``mklibs``,
1047``prelink``, and any other post-processing commands as defined by the
1048:term:`ROOTFS_POSTPROCESS_COMMAND`
1049variable. The ``mklibs`` process optimizes the size of the libraries,
1050while the ``prelink`` process optimizes the dynamic linking of shared
1051libraries to reduce start up time of executables.
1052
1053After the root filesystem is built, processing begins on the image
1054through the :ref:`ref-tasks-image`
1055task. The build system runs any pre-processing commands as defined by
1056the
1057:term:`IMAGE_PREPROCESS_COMMAND`
1058variable. This variable specifies a list of functions to call before the
1059build system creates the final image output files.
1060
1061The build system dynamically creates ``do_image_*`` tasks as needed,
1062based on the image types specified in the
1063:term:`IMAGE_FSTYPES` variable.
1064The process turns everything into an image file or a set of image files
1065and can compress the root filesystem image to reduce the overall size of
1066the image. The formats used for the root filesystem depend on the
1067``IMAGE_FSTYPES`` variable. Compression depends on whether the formats
1068support compression.
1069
1070As an example, a dynamically created task when creating a particular
1071image type would take the following form:
1072::
1073
1074 do_image_type
1075
1076So, if the type
1077as specified by the ``IMAGE_FSTYPES`` were ``ext4``, the dynamically
1078generated task would be as follows:
1079::
1080
1081 do_image_ext4
1082
1083The final task involved in image creation is the
1084:ref:`do_image_complete <ref-tasks-image-complete>`
1085task. This task completes the image by applying any image post
1086processing as defined through the
1087:term:`IMAGE_POSTPROCESS_COMMAND`
1088variable. The variable specifies a list of functions to call once the
1089build system has created the final image output files.
1090
1091.. note::
1092
1093 The entire image generation process is run under
1094 Pseudo. Running under Pseudo ensures that the files in the root filesystem
1095 have correct ownership.
1096
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001097SDK Generation
1098~~~~~~~~~~~~~~
1099
1100The OpenEmbedded build system uses BitBake to generate the Software
1101Development Kit (SDK) installer scripts for both the standard SDK and
1102the extensible SDK (eSDK):
1103
1104.. image:: figures/sdk-generation.png
1105 :align: center
1106
1107.. note::
1108
1109 For more information on the cross-development toolchain generation,
Andrew Geissler09209ee2020-12-13 08:44:15 -06001110 see the ":ref:`overview-manual/concepts:cross-development toolchain generation`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001111 section. For information on advantages gained when building a
1112 cross-development toolchain using the do_populate_sdk task, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001113 ":ref:`sdk-manual/appendix-obtain:building an sdk installer`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001114 the Yocto Project Application Development and the Extensible Software
1115 Development Kit (eSDK) manual.
1116
1117Like image generation, the SDK script process consists of several stages
1118and depends on many variables. The
1119:ref:`ref-tasks-populate_sdk`
1120and
1121:ref:`ref-tasks-populate_sdk_ext`
1122tasks use these key variables to help create the list of packages to
1123actually install. For information on the variables listed in the figure,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001124see the ":ref:`overview-manual/concepts:application development sdk`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001125section.
1126
1127The ``do_populate_sdk`` task helps create the standard SDK and handles
1128two parts: a target part and a host part. The target part is the part
1129built for the target hardware and includes libraries and headers. The
1130host part is the part of the SDK that runs on the
1131:term:`SDKMACHINE`.
1132
1133The ``do_populate_sdk_ext`` task helps create the extensible SDK and
1134handles host and target parts differently than its counter part does for
1135the standard SDK. For the extensible SDK, the task encapsulates the
1136build system, which includes everything needed (host and target) for the
1137SDK.
1138
1139Regardless of the type of SDK being constructed, the tasks perform some
1140cleanup after which a cross-development environment setup script and any
1141needed configuration files are created. The final output is the
1142Cross-development toolchain installation script (``.sh`` file), which
1143includes the environment setup script.
1144
1145Stamp Files and the Rerunning of Tasks
1146~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1147
1148For each task that completes successfully, BitBake writes a stamp file
1149into the :term:`STAMPS_DIR`
1150directory. The beginning of the stamp file's filename is determined by
1151the :term:`STAMP` variable, and the end
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001152of the name consists of the task's name and current :ref:`input
1153checksum <overview-manual/concepts:checksums (signatures)>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001154
1155.. note::
1156
1157 This naming scheme assumes that
1158 BB_SIGNATURE_HANDLER
1159 is "OEBasicHash", which is almost always the case in current
1160 OpenEmbedded.
1161
1162To determine if a task needs to be rerun, BitBake checks if a stamp file
1163with a matching input checksum exists for the task. If such a stamp file
1164exists, the task's output is assumed to exist and still be valid. If the
1165file does not exist, the task is rerun.
1166
1167.. note::
1168
1169 The stamp mechanism is more general than the shared state (sstate)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001170 cache mechanism described in the
1171 ":ref:`overview-manual/concepts:setscene tasks and shared state`" section.
1172 BitBake avoids rerunning any task that has a valid stamp file, not just
1173 tasks that can be accelerated through the sstate cache.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001174
1175 However, you should realize that stamp files only serve as a marker
1176 that some work has been done and that these files do not record task
1177 output. The actual task output would usually be somewhere in
1178 :term:`TMPDIR` (e.g. in some
1179 recipe's :term:`WORKDIR`.) What
1180 the sstate cache mechanism adds is a way to cache task output that
1181 can then be shared between build machines.
1182
1183Since ``STAMPS_DIR`` is usually a subdirectory of ``TMPDIR``, removing
1184``TMPDIR`` will also remove ``STAMPS_DIR``, which means tasks will
1185properly be rerun to repopulate ``TMPDIR``.
1186
1187If you want some task to always be considered "out of date", you can
1188mark it with the :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`
1189varflag. If some other task depends on such a task, then that task will
1190also always be considered out of date, which might not be what you want.
1191
1192For details on how to view information about a task's signature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001193":ref:`dev-manual/common-tasks:viewing task variable dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001194section in the Yocto Project Development Tasks Manual.
1195
1196Setscene Tasks and Shared State
1197~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1198
1199The description of tasks so far assumes that BitBake needs to build
1200everything and no available prebuilt objects exist. BitBake does support
1201skipping tasks if prebuilt objects are available. These objects are
1202usually made available in the form of a shared state (sstate) cache.
1203
1204.. note::
1205
1206 For information on variables affecting sstate, see the
1207 :term:`SSTATE_DIR`
1208 and
1209 :term:`SSTATE_MIRRORS`
1210 variables.
1211
1212The idea of a setscene task (i.e ``do_``\ taskname\ ``_setscene``) is a
1213version of the task where instead of building something, BitBake can
1214skip to the end result and simply place a set of files into specific
1215locations as needed. In some cases, it makes sense to have a setscene
1216task variant (e.g. generating package files in the
1217:ref:`do_package_write_* <ref-tasks-package_write_deb>`
1218task). In other cases, it does not make sense (e.g. a
1219:ref:`ref-tasks-patch` task or a
1220:ref:`ref-tasks-unpack` task) since
1221the work involved would be equal to or greater than the underlying task.
1222
1223In the build system, the common tasks that have setscene variants are
1224:ref:`ref-tasks-package`,
1225``do_package_write_*``,
1226:ref:`ref-tasks-deploy`,
1227:ref:`ref-tasks-packagedata`, and
1228:ref:`ref-tasks-populate_sysroot`.
1229Notice that these tasks represent most of the tasks whose output is an
1230end result.
1231
1232The build system has knowledge of the relationship between these tasks
1233and other preceding tasks. For example, if BitBake runs
1234``do_populate_sysroot_setscene`` for something, it does not make sense
1235to run any of the ``do_fetch``, ``do_unpack``, ``do_patch``,
1236``do_configure``, ``do_compile``, and ``do_install`` tasks. However, if
1237``do_package`` needs to be run, BitBake needs to run those other tasks.
1238
1239It becomes more complicated if everything can come from an sstate cache
1240because some objects are simply not required at all. For example, you do
1241not need a compiler or native tools, such as quilt, if nothing exists to
1242compile or patch. If the ``do_package_write_*`` packages are available
1243from sstate, BitBake does not need the ``do_package`` task data.
1244
1245To handle all these complexities, BitBake runs in two phases. The first
1246is the "setscene" stage. During this stage, BitBake first checks the
1247sstate cache for any targets it is planning to build. BitBake does a
1248fast check to see if the object exists rather than a complete download.
1249If nothing exists, the second phase, which is the setscene stage,
1250completes and the main build proceeds.
1251
1252If objects are found in the sstate cache, the build system works
1253backwards from the end targets specified by the user. For example, if an
1254image is being built, the build system first looks for the packages
1255needed for that image and the tools needed to construct an image. If
1256those are available, the compiler is not needed. Thus, the compiler is
1257not even downloaded. If something was found to be unavailable, or the
1258download or setscene task fails, the build system then tries to install
1259dependencies, such as the compiler, from the cache.
1260
1261The availability of objects in the sstate cache is handled by the
1262function specified by the
1263:term:`bitbake:BB_HASHCHECK_FUNCTION`
1264variable and returns a list of available objects. The function specified
1265by the
1266:term:`bitbake:BB_SETSCENE_DEPVALID`
1267variable is the function that determines whether a given dependency
1268needs to be followed, and whether for any given relationship the
1269function needs to be passed. The function returns a True or False value.
1270
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001271Images
1272------
1273
1274The images produced by the build system are compressed forms of the root
1275filesystem and are ready to boot on a target device. You can see from
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001276the :ref:`general workflow figure
1277<overview-manual/concepts:openembedded build system concepts>` that BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001278output, in part, consists of images. This section takes a closer look at
1279this output:
1280
1281.. image:: figures/images.png
1282 :align: center
1283
1284.. note::
1285
1286 For a list of example images that the Yocto Project provides, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001287 ":doc:`/ref-manual/images`" chapter in the Yocto Project Reference
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001288 Manual.
1289
1290The build process writes images out to the :term:`Build Directory`
1291inside the
1292``tmp/deploy/images/machine/`` folder as shown in the figure. This
1293folder contains any files expected to be loaded on the target device.
1294The :term:`DEPLOY_DIR` variable
1295points to the ``deploy`` directory, while the
1296:term:`DEPLOY_DIR_IMAGE`
1297variable points to the appropriate directory containing images for the
1298current configuration.
1299
1300- kernel-image: A kernel binary file. The
1301 :term:`KERNEL_IMAGETYPE`
1302 variable determines the naming scheme for the kernel image file.
1303 Depending on this variable, the file could begin with a variety of
1304 naming strings. The ``deploy/images/``\ machine directory can contain
1305 multiple image files for the machine.
1306
1307- root-filesystem-image: Root filesystems for the target device (e.g.
1308 ``*.ext3`` or ``*.bz2`` files). The
1309 :term:`IMAGE_FSTYPES`
1310 variable determines the root filesystem image type. The
1311 ``deploy/images/``\ machine directory can contain multiple root
1312 filesystems for the machine.
1313
1314- kernel-modules: Tarballs that contain all the modules built for the
1315 kernel. Kernel module tarballs exist for legacy purposes and can be
1316 suppressed by setting the
1317 :term:`MODULE_TARBALL_DEPLOY`
1318 variable to "0". The ``deploy/images/``\ machine directory can
1319 contain multiple kernel module tarballs for the machine.
1320
1321- bootloaders: If applicable to the target machine, bootloaders
1322 supporting the image. The ``deploy/images/``\ machine directory can
1323 contain multiple bootloaders for the machine.
1324
1325- symlinks: The ``deploy/images/``\ machine folder contains a symbolic
1326 link that points to the most recently built file for each machine.
1327 These links might be useful for external scripts that need to obtain
1328 the latest version of each file.
1329
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001330Application Development SDK
1331---------------------------
1332
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001333In the :ref:`general workflow figure
1334<overview-manual/concepts:openembedded build system concepts>`, the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001335output labeled "Application Development SDK" represents an SDK. The SDK
1336generation process differs depending on whether you build an extensible
1337SDK (e.g. ``bitbake -c populate_sdk_ext`` imagename) or a standard SDK
1338(e.g. ``bitbake -c populate_sdk`` imagename). This section takes a
1339closer look at this output:
1340
1341.. image:: figures/sdk.png
1342 :align: center
1343
1344The specific form of this output is a set of files that includes a
1345self-extracting SDK installer (``*.sh``), host and target manifest
1346files, and files used for SDK testing. When the SDK installer file is
1347run, it installs the SDK. The SDK consists of a cross-development
1348toolchain, a set of libraries and headers, and an SDK environment setup
1349script. Running this installer essentially sets up your
1350cross-development environment. You can think of the cross-toolchain as
1351the "host" part because it runs on the SDK machine. You can think of the
1352libraries and headers as the "target" part because they are built for
1353the target hardware. The environment setup script is added so that you
1354can initialize the environment before using the tools.
1355
1356.. note::
1357
1358 - The Yocto Project supports several methods by which you can set up
1359 this cross-development environment. These methods include
1360 downloading pre-built SDK installers or building and installing
1361 your own SDK installer.
1362
1363 - For background information on cross-development toolchains in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001364 Yocto Project development environment, see the
1365 ":ref:`overview-manual/concepts:cross-development toolchain generation`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001366 section.
1367
1368 - For information on setting up a cross-development environment, see
Andrew Geissler09209ee2020-12-13 08:44:15 -06001369 the :doc:`/sdk-manual/index` manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001370
1371All the output files for an SDK are written to the ``deploy/sdk`` folder
1372inside the :term:`Build Directory` as
1373shown in the previous figure. Depending on the type of SDK, several
1374variables exist that help configure these files. The following list
1375shows the variables associated with an extensible SDK:
1376
1377- :term:`DEPLOY_DIR`: Points to
1378 the ``deploy`` directory.
1379
1380- :term:`SDK_EXT_TYPE`:
1381 Controls whether or not shared state artifacts are copied into the
1382 extensible SDK. By default, all required shared state artifacts are
1383 copied into the SDK.
1384
1385- :term:`SDK_INCLUDE_PKGDATA`:
1386 Specifies whether or not packagedata is included in the extensible
1387 SDK for all recipes in the "world" target.
1388
1389- :term:`SDK_INCLUDE_TOOLCHAIN`:
1390 Specifies whether or not the toolchain is included when building the
1391 extensible SDK.
1392
1393- :term:`SDK_LOCAL_CONF_WHITELIST`:
1394 A list of variables allowed through from the build system
1395 configuration into the extensible SDK configuration.
1396
1397- :term:`SDK_LOCAL_CONF_BLACKLIST`:
1398 A list of variables not allowed through from the build system
1399 configuration into the extensible SDK configuration.
1400
1401- :term:`SDK_INHERIT_BLACKLIST`:
1402 A list of classes to remove from the
1403 :term:`INHERIT` value globally
1404 within the extensible SDK configuration.
1405
1406This next list, shows the variables associated with a standard SDK:
1407
1408- :term:`DEPLOY_DIR`: Points to
1409 the ``deploy`` directory.
1410
1411- :term:`SDKMACHINE`: Specifies
1412 the architecture of the machine on which the cross-development tools
1413 are run to create packages for the target hardware.
1414
1415- :term:`SDKIMAGE_FEATURES`:
1416 Lists the features to include in the "target" part of the SDK.
1417
1418- :term:`TOOLCHAIN_HOST_TASK`:
1419 Lists packages that make up the host part of the SDK (i.e. the part
1420 that runs on the ``SDKMACHINE``). When you use
1421 ``bitbake -c populate_sdk imagename`` to create the SDK, a set of
1422 default packages apply. This variable allows you to add more
1423 packages.
1424
1425- :term:`TOOLCHAIN_TARGET_TASK`:
1426 Lists packages that make up the target part of the SDK (i.e. the part
1427 built for the target hardware).
1428
1429- :term:`SDKPATH`: Defines the
1430 default SDK installation path offered by the installation script.
1431
1432- :term:`SDK_HOST_MANIFEST`:
1433 Lists all the installed packages that make up the host part of the
1434 SDK. This variable also plays a minor role for extensible SDK
1435 development as well. However, it is mainly used for the standard SDK.
1436
1437- :term:`SDK_TARGET_MANIFEST`:
1438 Lists all the installed packages that make up the target part of the
1439 SDK. This variable also plays a minor role for extensible SDK
1440 development as well. However, it is mainly used for the standard SDK.
1441
1442Cross-Development Toolchain Generation
1443======================================
1444
1445The Yocto Project does most of the work for you when it comes to
Andrew Geissler09209ee2020-12-13 08:44:15 -06001446creating :ref:`sdk-manual/intro:the cross-development toolchain`. This
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001447section provides some technical background on how cross-development
1448toolchains are created and used. For more information on toolchains, you
Andrew Geissler09209ee2020-12-13 08:44:15 -06001449can also see the :doc:`/sdk-manual/index` manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001450
1451In the Yocto Project development environment, cross-development
1452toolchains are used to build images and applications that run on the
1453target hardware. With just a few commands, the OpenEmbedded build system
1454creates these necessary toolchains for you.
1455
1456The following figure shows a high-level build environment regarding
1457toolchain construction and use.
1458
1459.. image:: figures/cross-development-toolchains.png
1460 :align: center
1461
1462Most of the work occurs on the Build Host. This is the machine used to
1463build images and generally work within the the Yocto Project
1464environment. When you run
1465:term:`BitBake` to create an image, the
1466OpenEmbedded build system uses the host ``gcc`` compiler to bootstrap a
1467cross-compiler named ``gcc-cross``. The ``gcc-cross`` compiler is what
1468BitBake uses to compile source files when creating the target image. You
1469can think of ``gcc-cross`` simply as an automatically generated
1470cross-compiler that is used internally within BitBake only.
1471
1472.. note::
1473
1474 The extensible SDK does not use
1475 gcc-cross-canadian
1476 since this SDK ships a copy of the OpenEmbedded build system and the
1477 sysroot within it contains
1478 gcc-cross
1479 .
1480
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001481The chain of events that occurs when the standard toolchain is bootstrapped:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001482::
1483
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001484 binutils-cross -> linux-libc-headers -> gcc-cross -> libgcc-initial -> glibc -> libgcc -> gcc-runtime
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001485
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001486- ``gcc``: The compiler, GNU Compiler Collection (GCC).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001487
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001488- ``binutils-cross``: The binary utilities needed in order
1489 to run the ``gcc-cross`` phase of the bootstrap operation and build the
1490 headers for the C library.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001491
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001492- ``linux-libc-headers``: Headers needed for the cross-compiler and C library build.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001493
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001494- ``libgcc-initial``: An initial version of the gcc support library needed
1495 to bootstrap ``glibc``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001496
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001497- ``libgcc``: The final version of the gcc support library which
1498 can only be built once there is a C library to link against.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001499
1500- ``glibc``: The GNU C Library.
1501
1502- ``gcc-cross``: The final stage of the bootstrap process for the
1503 cross-compiler. This stage results in the actual cross-compiler that
1504 BitBake uses when it builds an image for a targeted device.
1505
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001506 This tool is a "native" tool (i.e. it is designed to run on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001507 the build host).
1508
1509- ``gcc-runtime``: Runtime libraries resulting from the toolchain
1510 bootstrapping process. This tool produces a binary that consists of
1511 the runtime libraries need for the targeted device.
1512
1513You can use the OpenEmbedded build system to build an installer for the
1514relocatable SDK used to develop applications. When you run the
1515installer, it installs the toolchain, which contains the development
1516tools (e.g., ``gcc-cross-canadian``, ``binutils-cross-canadian``, and
1517other ``nativesdk-*`` tools), which are tools native to the SDK (i.e.
1518native to :term:`SDK_ARCH`), you
1519need to cross-compile and test your software. The figure shows the
1520commands you use to easily build out this toolchain. This
1521cross-development toolchain is built to execute on the
1522:term:`SDKMACHINE`, which might or
1523might not be the same machine as the Build Host.
1524
1525.. note::
1526
1527 If your target architecture is supported by the Yocto Project, you
1528 can take advantage of pre-built images that ship with the Yocto
1529 Project and already contain cross-development toolchain installers.
1530
1531Here is the bootstrap process for the relocatable toolchain:
1532::
1533
1534 gcc -> binutils-crosssdk -> gcc-crosssdk-initial -> linux-libc-headers -> glibc-initial -> nativesdk-glibc -> gcc-crosssdk -> gcc-cross-canadian
1535
1536- ``gcc``: The build host's GNU Compiler Collection (GCC).
1537
1538- ``binutils-crosssdk``: The bare minimum binary utilities needed in
1539 order to run the ``gcc-crosssdk-initial`` phase of the bootstrap
1540 operation.
1541
1542- ``gcc-crosssdk-initial``: An early stage of the bootstrap process for
1543 creating the cross-compiler. This stage builds enough of the
1544 ``gcc-crosssdk`` and supporting pieces so that the final stage of the
1545 bootstrap process can produce the finished cross-compiler. This tool
1546 is a "native" binary that runs on the build host.
1547
1548- ``linux-libc-headers``: Headers needed for the cross-compiler.
1549
1550- ``glibc-initial``: An initial version of the Embedded GLIBC needed to
1551 bootstrap ``nativesdk-glibc``.
1552
1553- ``nativesdk-glibc``: The Embedded GLIBC needed to bootstrap the
1554 ``gcc-crosssdk``.
1555
1556- ``gcc-crosssdk``: The final stage of the bootstrap process for the
1557 relocatable cross-compiler. The ``gcc-crosssdk`` is a transitory
1558 compiler and never leaves the build host. Its purpose is to help in
1559 the bootstrap process to create the eventual ``gcc-cross-canadian``
1560 compiler, which is relocatable. This tool is also a "native" package
1561 (i.e. it is designed to run on the build host).
1562
1563- ``gcc-cross-canadian``: The final relocatable cross-compiler. When
1564 run on the :term:`SDKMACHINE`,
1565 this tool produces executable code that runs on the target device.
1566 Only one cross-canadian compiler is produced per architecture since
1567 they can be targeted at different processor optimizations using
1568 configurations passed to the compiler through the compile commands.
1569 This circumvents the need for multiple compilers and thus reduces the
1570 size of the toolchains.
1571
1572.. note::
1573
1574 For information on advantages gained when building a
1575 cross-development toolchain installer, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001576 ":ref:`sdk-manual/appendix-obtain:building an sdk installer`" appendix
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001577 in the Yocto Project Application Development and the
1578 Extensible Software Development Kit (eSDK) manual.
1579
1580Shared State Cache
1581==================
1582
1583By design, the OpenEmbedded build system builds everything from scratch
1584unless :term:`BitBake` can determine
1585that parts do not need to be rebuilt. Fundamentally, building from
1586scratch is attractive as it means all parts are built fresh and no
1587possibility of stale data exists that can cause problems. When
1588developers hit problems, they typically default back to building from
1589scratch so they have a know state from the start.
1590
1591Building an image from scratch is both an advantage and a disadvantage
1592to the process. As mentioned in the previous paragraph, building from
1593scratch ensures that everything is current and starts from a known
1594state. However, building from scratch also takes much longer as it
1595generally means rebuilding things that do not necessarily need to be
1596rebuilt.
1597
1598The Yocto Project implements shared state code that supports incremental
1599builds. The implementation of the shared state code answers the
1600following questions that were fundamental roadblocks within the
1601OpenEmbedded incremental build support system:
1602
1603- What pieces of the system have changed and what pieces have not
1604 changed?
1605
1606- How are changed pieces of software removed and replaced?
1607
1608- How are pre-built components that do not need to be rebuilt from
1609 scratch used when they are available?
1610
1611For the first question, the build system detects changes in the "inputs"
1612to a given task by creating a checksum (or signature) of the task's
1613inputs. If the checksum changes, the system assumes the inputs have
1614changed and the task needs to be rerun. For the second question, the
1615shared state (sstate) code tracks which tasks add which output to the
1616build process. This means the output from a given task can be removed,
1617upgraded or otherwise manipulated. The third question is partly
1618addressed by the solution for the second question assuming the build
1619system can fetch the sstate objects from remote locations and install
1620them if they are deemed to be valid.
1621
1622.. note::
1623
1624 - The build system does not maintain
1625 :term:`PR` information as part of
1626 the shared state packages. Consequently, considerations exist that
1627 affect maintaining shared state feeds. For information on how the
1628 build system works with packages and can track incrementing ``PR``
Andrew Geissler09209ee2020-12-13 08:44:15 -06001629 information, see the ":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001630 section in the Yocto Project Development Tasks Manual.
1631
1632 - The code in the build system that supports incremental builds is
1633 not simple code. For techniques that help you work around issues
1634 related to shared state code, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001635 ":ref:`dev-manual/common-tasks:viewing metadata used to create the input signature of a shared state task`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001636 and
Andrew Geissler09209ee2020-12-13 08:44:15 -06001637 ":ref:`dev-manual/common-tasks:invalidating shared state to force a task to run`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001638 sections both in the Yocto Project Development Tasks Manual.
1639
1640The rest of this section goes into detail about the overall incremental
1641build architecture, the checksums (signatures), and shared state.
1642
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001643Overall Architecture
1644--------------------
1645
1646When determining what parts of the system need to be built, BitBake
1647works on a per-task basis rather than a per-recipe basis. You might
1648wonder why using a per-task basis is preferred over a per-recipe basis.
1649To help explain, consider having the IPK packaging backend enabled and
1650then switching to DEB. In this case, the
1651:ref:`ref-tasks-install` and
1652:ref:`ref-tasks-package` task outputs
1653are still valid. However, with a per-recipe approach, the build would
1654not include the ``.deb`` files. Consequently, you would have to
1655invalidate the whole build and rerun it. Rerunning everything is not the
1656best solution. Also, in this case, the core must be "taught" much about
1657specific tasks. This methodology does not scale well and does not allow
1658users to easily add new tasks in layers or as external recipes without
1659touching the packaged-staging core.
1660
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001661Checksums (Signatures)
1662----------------------
1663
1664The shared state code uses a checksum, which is a unique signature of a
1665task's inputs, to determine if a task needs to be run again. Because it
1666is a change in a task's inputs that triggers a rerun, the process needs
1667to detect all the inputs to a given task. For shell tasks, this turns
1668out to be fairly easy because the build process generates a "run" shell
1669script for each task and it is possible to create a checksum that gives
1670you a good idea of when the task's data changes.
1671
1672To complicate the problem, there are things that should not be included
1673in the checksum. First, there is the actual specific build path of a
1674given task - the :term:`WORKDIR`. It
1675does not matter if the work directory changes because it should not
1676affect the output for target packages. Also, the build process has the
1677objective of making native or cross packages relocatable.
1678
1679.. note::
1680
1681 Both native and cross packages run on the
1682 build host. However, cross packages generate output for the target
1683 architecture.
1684
1685The checksum therefore needs to exclude ``WORKDIR``. The simplistic
1686approach for excluding the work directory is to set ``WORKDIR`` to some
1687fixed value and create the checksum for the "run" script.
1688
1689Another problem results from the "run" scripts containing functions that
1690might or might not get called. The incremental build solution contains
1691code that figures out dependencies between shell functions. This code is
1692used to prune the "run" scripts down to the minimum set, thereby
1693alleviating this problem and making the "run" scripts much more readable
1694as a bonus.
1695
1696So far, solutions for shell scripts exist. What about Python tasks? The
1697same approach applies even though these tasks are more difficult. The
1698process needs to figure out what variables a Python function accesses
1699and what functions it calls. Again, the incremental build solution
1700contains code that first figures out the variable and function
1701dependencies, and then creates a checksum for the data used as the input
1702to the task.
1703
1704Like the ``WORKDIR`` case, situations exist where dependencies should be
1705ignored. For these situations, you can instruct the build process to
1706ignore a dependency by using a line like the following:
1707::
1708
1709 PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
1710
1711This example ensures that the :term:`PACKAGE_ARCHS` variable
1712does not depend on the value of :term:`MACHINE`, even if it does
1713reference it.
1714
1715Equally, there are cases where you need to add dependencies BitBake is
1716not able to find. You can accomplish this by using a line like the
1717following:
1718::
1719
1720 PACKAGE_ARCHS[vardeps] = "MACHINE"
1721
1722This example explicitly
1723adds the ``MACHINE`` variable as a dependency for ``PACKAGE_ARCHS``.
1724
1725As an example, consider a case with in-line Python where BitBake is not
1726able to figure out dependencies. When running in debug mode (i.e. using
1727``-DDD``), BitBake produces output when it discovers something for which
1728it cannot figure out dependencies. The Yocto Project team has currently
1729not managed to cover those dependencies in detail and is aware of the
1730need to fix this situation.
1731
1732Thus far, this section has limited discussion to the direct inputs into
1733a task. Information based on direct inputs is referred to as the
1734"basehash" in the code. However, the question of a task's indirect
1735inputs still exits - items already built and present in the
1736:term:`Build Directory`. The checksum (or
1737signature) for a particular task needs to add the hashes of all the
1738tasks on which the particular task depends. Choosing which dependencies
1739to add is a policy decision. However, the effect is to generate a master
1740checksum that combines the basehash and the hashes of the task's
1741dependencies.
1742
1743At the code level, a variety of ways exist by which both the basehash
1744and the dependent task hashes can be influenced. Within the BitBake
1745configuration file, you can give BitBake some extra information to help
1746it construct the basehash. The following statement effectively results
1747in a list of global variable dependency excludes (i.e. variables never
1748included in any checksum):
1749::
1750
1751 BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \\
1752 SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \\
1753 USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \\
1754 PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \\
1755 CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
1756
1757The
1758previous example excludes
1759:term:`WORKDIR` since that variable
1760is actually constructed as a path within
1761:term:`TMPDIR`, which is on the
1762whitelist.
1763
1764The rules for deciding which hashes of dependent tasks to include
1765through dependency chains are more complex and are generally
1766accomplished with a Python function. The code in
1767``meta/lib/oe/sstatesig.py`` shows two examples of this and also
1768illustrates how you can insert your own policy into the system if so
1769desired. This file defines the two basic signature generators
1770:term:`OpenEmbedded-Core (OE-Core)` uses: "OEBasic" and
1771"OEBasicHash". By default, a dummy "noop" signature handler is enabled
1772in BitBake. This means that behavior is unchanged from previous
1773versions. OE-Core uses the "OEBasicHash" signature handler by default
1774through this setting in the ``bitbake.conf`` file:
1775::
1776
1777 BB_SIGNATURE_HANDLER ?= "OEBasicHash"
1778
1779The "OEBasicHash" ``BB_SIGNATURE_HANDLER`` is the same
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001780as the "OEBasic" version but adds the task hash to the :ref:`stamp
1781files <overview-manual/concepts:stamp files and the rerunning of tasks>`. This
1782results in any metadata change that changes the task hash, automatically causing
1783the task to be run again. This removes the need to bump
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001784:term:`PR` values, and changes to metadata
1785automatically ripple across the build.
1786
1787It is also worth noting that the end result of these signature
1788generators is to make some dependency and hash information available to
1789the build. This information includes:
1790
1791- ``BB_BASEHASH_task-``\ taskname: The base hashes for each task in the
1792 recipe.
1793
1794- ``BB_BASEHASH_``\ filename\ ``:``\ taskname: The base hashes for each
1795 dependent task.
1796
1797- ``BBHASHDEPS_``\ filename\ ``:``\ taskname: The task dependencies for
1798 each task.
1799
1800- ``BB_TASKHASH``: The hash of the currently running task.
1801
1802Shared State
1803------------
1804
1805Checksums and dependencies, as discussed in the previous section, solve
1806half the problem of supporting a shared state. The other half of the
1807problem is being able to use checksum information during the build and
1808being able to reuse or rebuild specific components.
1809
1810The :ref:`sstate <ref-classes-sstate>` class is a
1811relatively generic implementation of how to "capture" a snapshot of a
1812given task. The idea is that the build process does not care about the
1813source of a task's output. Output could be freshly built or it could be
1814downloaded and unpacked from somewhere. In other words, the build
1815process does not need to worry about its origin.
1816
1817Two types of output exist. One type is just about creating a directory
1818in :term:`WORKDIR`. A good example is
1819the output of either
1820:ref:`ref-tasks-install` or
1821:ref:`ref-tasks-package`. The other
1822type of output occurs when a set of data is merged into a shared
1823directory tree such as the sysroot.
1824
1825The Yocto Project team has tried to keep the details of the
1826implementation hidden in ``sstate`` class. From a user's perspective,
1827adding shared state wrapping to a task is as simple as this
1828:ref:`ref-tasks-deploy` example taken
1829from the :ref:`deploy <ref-classes-deploy>` class:
1830::
1831
1832 DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
1833 SSTATETASKS += "do_deploy"
1834 do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
1835 do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
1836
1837 python do_deploy_setscene () {
1838 sstate_setscene(d)
1839 }
1840 addtask do_deploy_setscene
1841 do_deploy[dirs] = "${DEPLOYDIR} ${B}"
1842 do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"
1843
1844The following list explains the previous example:
1845
1846- Adding "do_deploy" to ``SSTATETASKS`` adds some required
1847 sstate-related processing, which is implemented in the
1848 :ref:`sstate <ref-classes-sstate>` class, to
1849 before and after the
1850 :ref:`ref-tasks-deploy` task.
1851
1852- The ``do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"`` declares that
1853 ``do_deploy`` places its output in ``${DEPLOYDIR}`` when run normally
1854 (i.e. when not using the sstate cache). This output becomes the input
1855 to the shared state cache.
1856
1857- The ``do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"`` line
1858 causes the contents of the shared state cache to be copied to
1859 ``${DEPLOY_DIR_IMAGE}``.
1860
1861 .. note::
1862
1863 If ``do_deploy`` is not already in the shared state cache or if its input
1864 checksum (signature) has changed from when the output was cached, the task
1865 runs to populate the shared state cache, after which the contents of the
1866 shared state cache is copied to ${:term:`DEPLOY_DIR_IMAGE`}. If
1867 ``do_deploy`` is in the shared state cache and its signature indicates
1868 that the cached output is still valid (i.e. if no relevant task inputs
1869 have changed), then the contents of the shared state cache copies
1870 directly to ${``DEPLOY_DIR_IMAGE``} by the ``do_deploy_setscene`` task
1871 instead, skipping the ``do_deploy`` task.
1872
1873- The following task definition is glue logic needed to make the
1874 previous settings effective:
1875 ::
1876
1877 python do_deploy_setscene () {
1878 sstate_setscene(d)
1879 }
1880 addtask do_deploy_setscene
1881
1882 ``sstate_setscene()`` takes the flags above as input and accelerates the ``do_deploy`` task
1883 through the shared state cache if possible. If the task was
1884 accelerated, ``sstate_setscene()`` returns True. Otherwise, it
1885 returns False, and the normal ``do_deploy`` task runs. For more
1886 information, see the ":ref:`setscene <bitbake:bitbake-user-manual/bitbake-user-manual-execution:setscene>`"
1887 section in the BitBake User Manual.
1888
1889- The ``do_deploy[dirs] = "${DEPLOYDIR} ${B}"`` line creates
1890 ``${DEPLOYDIR}`` and ``${B}`` before the ``do_deploy`` task runs, and
1891 also sets the current working directory of ``do_deploy`` to ``${B}``.
1892 For more information, see the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`"
1893 section in the BitBake
1894 User Manual.
1895
1896 .. note::
1897
1898 In cases where ``sstate-inputdirs`` and ``sstate-outputdirs`` would be
1899 the same, you can use ``sstate-plaindirs``. For example, to preserve the
1900 ${:term:`PKGD`} and ${:term:`PKGDEST`} output from the ``do_package``
1901 task, use the following:
1902 ::
1903
1904 do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
1905
1906
1907- The ``do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"`` line appends
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001908 extra metadata to the :ref:`stamp
1909 file <overview-manual/concepts:stamp files and the rerunning of tasks>`. In
1910 this case, the metadata makes the task specific to a machine's architecture.
1911 See
Andrew Geissler09209ee2020-12-13 08:44:15 -06001912 ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:the task list`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001913 section in the BitBake User Manual for more information on the
1914 ``stamp-extra-info`` flag.
1915
1916- ``sstate-inputdirs`` and ``sstate-outputdirs`` can also be used with
1917 multiple directories. For example, the following declares
1918 ``PKGDESTWORK`` and ``SHLIBWORK`` as shared state input directories,
1919 which populates the shared state cache, and ``PKGDATA_DIR`` and
1920 ``SHLIBSDIR`` as the corresponding shared state output directories:
1921 ::
1922
1923 do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
1924 do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
1925
1926- These methods also include the ability to take a lockfile when
1927 manipulating shared state directory structures, for cases where file
1928 additions or removals are sensitive:
1929 ::
1930
1931 do_package[sstate-lockfile] = "${PACKAGELOCK}"
1932
1933Behind the scenes, the shared state code works by looking in
1934:term:`SSTATE_DIR` and
1935:term:`SSTATE_MIRRORS` for
1936shared state files. Here is an example:
1937::
1938
1939 SSTATE_MIRRORS ?= "\
1940 file://.\* http://someserver.tld/share/sstate/PATH;downloadfilename=PATH \n \
1941 file://.\* file:///some/local/dir/sstate/PATH"
1942
1943.. note::
1944
1945 The shared state directory (``SSTATE_DIR``) is organized into two-character
1946 subdirectories, where the subdirectory names are based on the first two
1947 characters of the hash.
1948 If the shared state directory structure for a mirror has the same structure
1949 as ``SSTATE_DIR``, you must specify "PATH" as part of the URI to enable the build
1950 system to map to the appropriate subdirectory.
1951
1952The shared state package validity can be detected just by looking at the
1953filename since the filename contains the task checksum (or signature) as
1954described earlier in this section. If a valid shared state package is
1955found, the build process downloads it and uses it to accelerate the
1956task.
1957
1958The build processes use the ``*_setscene`` tasks for the task
1959acceleration phase. BitBake goes through this phase before the main
1960execution code and tries to accelerate any tasks for which it can find
1961shared state packages. If a shared state package for a task is
1962available, the shared state package is used. This means the task and any
1963tasks on which it is dependent are not executed.
1964
1965As a real world example, the aim is when building an IPK-based image,
1966only the
1967:ref:`ref-tasks-package_write_ipk`
1968tasks would have their shared state packages fetched and extracted.
1969Since the sysroot is not used, it would never get extracted. This is
1970another reason why a task-based approach is preferred over a
1971recipe-based approach, which would have to install the output from every
1972task.
1973
1974Automatically Added Runtime Dependencies
1975========================================
1976
1977The OpenEmbedded build system automatically adds common types of runtime
1978dependencies between packages, which means that you do not need to
1979explicitly declare the packages using
1980:term:`RDEPENDS`. Three automatic
1981mechanisms exist (``shlibdeps``, ``pcdeps``, and ``depchains``) that
1982handle shared libraries, package configuration (pkg-config) modules, and
1983``-dev`` and ``-dbg`` packages, respectively. For other types of runtime
1984dependencies, you must manually declare the dependencies.
1985
1986- ``shlibdeps``: During the
1987 :ref:`ref-tasks-package` task of
1988 each recipe, all shared libraries installed by the recipe are
1989 located. For each shared library, the package that contains the
1990 shared library is registered as providing the shared library. More
1991 specifically, the package is registered as providing the
1992 `soname <https://en.wikipedia.org/wiki/Soname>`__ of the library. The
1993 resulting shared-library-to-package mapping is saved globally in
1994 :term:`PKGDATA_DIR` by the
1995 :ref:`ref-tasks-packagedata`
1996 task.
1997
1998 Simultaneously, all executables and shared libraries installed by the
1999 recipe are inspected to see what shared libraries they link against.
2000 For each shared library dependency that is found, ``PKGDATA_DIR`` is
2001 queried to see if some package (likely from a different recipe)
2002 contains the shared library. If such a package is found, a runtime
2003 dependency is added from the package that depends on the shared
2004 library to the package that contains the library.
2005
2006 The automatically added runtime dependency also includes a version
2007 restriction. This version restriction specifies that at least the
2008 current version of the package that provides the shared library must
2009 be used, as if "package (>= version)" had been added to ``RDEPENDS``.
2010 This forces an upgrade of the package containing the shared library
2011 when installing the package that depends on the library, if needed.
2012
2013 If you want to avoid a package being registered as providing a
2014 particular shared library (e.g. because the library is for internal
2015 use only), then add the library to
2016 :term:`PRIVATE_LIBS` inside
2017 the package's recipe.
2018
2019- ``pcdeps``: During the ``do_package`` task of each recipe, all
2020 pkg-config modules (``*.pc`` files) installed by the recipe are
2021 located. For each module, the package that contains the module is
2022 registered as providing the module. The resulting module-to-package
2023 mapping is saved globally in ``PKGDATA_DIR`` by the
2024 ``do_packagedata`` task.
2025
2026 Simultaneously, all pkg-config modules installed by the recipe are
2027 inspected to see what other pkg-config modules they depend on. A
2028 module is seen as depending on another module if it contains a
2029 "Requires:" line that specifies the other module. For each module
2030 dependency, ``PKGDATA_DIR`` is queried to see if some package
2031 contains the module. If such a package is found, a runtime dependency
2032 is added from the package that depends on the module to the package
2033 that contains the module.
2034
2035 .. note::
2036
2037 The
2038 pcdeps
2039 mechanism most often infers dependencies between
2040 -dev
2041 packages.
2042
2043- ``depchains``: If a package ``foo`` depends on a package ``bar``,
2044 then ``foo-dev`` and ``foo-dbg`` are also made to depend on
2045 ``bar-dev`` and ``bar-dbg``, respectively. Taking the ``-dev``
2046 packages as an example, the ``bar-dev`` package might provide headers
2047 and shared library symlinks needed by ``foo-dev``, which shows the
2048 need for a dependency between the packages.
2049
2050 The dependencies added by ``depchains`` are in the form of
2051 :term:`RRECOMMENDS`.
2052
2053 .. note::
2054
2055 By default, ``foo-dev`` also has an ``RDEPENDS``-style dependency on
2056 ``foo``, because the default value of ``RDEPENDS_${PN}-dev`` (set in
2057 bitbake.conf) includes "${PN}".
2058
2059 To ensure that the dependency chain is never broken, ``-dev`` and
2060 ``-dbg`` packages are always generated by default, even if the
2061 packages turn out to be empty. See the
2062 :term:`ALLOW_EMPTY` variable
2063 for more information.
2064
2065The ``do_package`` task depends on the ``do_packagedata`` task of each
2066recipe in :term:`DEPENDS` through use
2067of a ``[``\ :ref:`deptask <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
2068declaration, which guarantees that the required
2069shared-library/module-to-package mapping information will be available
2070when needed as long as ``DEPENDS`` has been correctly set.
2071
2072Fakeroot and Pseudo
2073===================
2074
2075Some tasks are easier to implement when allowed to perform certain
2076operations that are normally reserved for the root user (e.g.
2077:ref:`ref-tasks-install`,
2078:ref:`do_package_write* <ref-tasks-package_write_deb>`,
2079:ref:`ref-tasks-rootfs`, and
2080:ref:`do_image* <ref-tasks-image>`). For example,
2081the ``do_install`` task benefits from being able to set the UID and GID
2082of installed files to arbitrary values.
2083
2084One approach to allowing tasks to perform root-only operations would be
2085to require :term:`BitBake` to run as
2086root. However, this method is cumbersome and has security issues. The
2087approach that is actually used is to run tasks that benefit from root
2088privileges in a "fake" root environment. Within this environment, the
2089task and its child processes believe that they are running as the root
2090user, and see an internally consistent view of the filesystem. As long
2091as generating the final output (e.g. a package or an image) does not
2092require root privileges, the fact that some earlier steps ran in a fake
2093root environment does not cause problems.
2094
2095The capability to run tasks in a fake root environment is known as
2096"`fakeroot <http://man.he.net/man1/fakeroot>`__", which is derived from
2097the BitBake keyword/variable flag that requests a fake root environment
2098for a task.
2099
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002100In the :term:`OpenEmbedded Build System`, the program that implements
2101fakeroot is known as :yocto_home:`Pseudo </software-item/pseudo/>`. Pseudo
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002102overrides system calls by using the environment variable ``LD_PRELOAD``,
2103which results in the illusion of running as root. To keep track of
2104"fake" file ownership and permissions resulting from operations that
2105require root permissions, Pseudo uses an SQLite 3 database. This
2106database is stored in
2107``${``\ :term:`WORKDIR`\ ``}/pseudo/files.db``
2108for individual recipes. Storing the database in a file as opposed to in
2109memory gives persistence between tasks and builds, which is not
2110accomplished using fakeroot.
2111
2112.. note::
2113
2114 If you add your own task that manipulates the same files or
2115 directories as a fakeroot task, then that task also needs to run
2116 under fakeroot. Otherwise, the task cannot run root-only operations,
2117 and cannot see the fake file ownership and permissions set by the
2118 other task. You need to also add a dependency on
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002119 ``virtual/fakeroot-native:do_populate_sysroot``, giving the following:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002120 ::
2121
2122 fakeroot do_mytask () {
2123 ...
2124 }
2125 do_mytask[depends] += "virtual/fakeroot-native:do_populate_sysroot"
2126
2127
2128For more information, see the
2129:term:`FAKEROOT* <bitbake:FAKEROOT>` variables in the
2130BitBake User Manual. You can also reference the "`Why Not
2131Fakeroot? <https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot>`__"
2132article for background information on Fakeroot and Pseudo.