blob: 83339da98fa5d3eb1c4e64f56696ce82533c1a13 [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
Andrew Geisslerc926e172021-05-07 16:11:35 -050058following commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050059
60 $ bitbake -h
61 $ bitbake --help
62
63The most common usage for BitBake is ``bitbake recipename``, where
64``recipename`` is the name of the recipe you want to build (referred
65to as the "target"). The target often equates to the first part of a
66recipe's filename (e.g. "foo" for a recipe named ``foo_1.3.0-r0.bb``).
67So, to process the ``matchbox-desktop_1.2.3.bb`` recipe file, you might
Andrew Geisslerc926e172021-05-07 16:11:35 -050068type the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050069
70 $ bitbake matchbox-desktop
71
72Several different
73versions of ``matchbox-desktop`` might exist. BitBake chooses the one
74selected by the distribution configuration. You can get more details
75about how BitBake chooses between different target versions and
76providers in the
Patrick Williams213cb262021-08-07 19:21:33 -050077":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:preferences`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -050078of the BitBake User Manual.
79
80BitBake also tries to execute any dependent tasks first. So for example,
81before building ``matchbox-desktop``, BitBake would build a cross
82compiler and ``glibc`` if they had not already been built.
83
84A useful BitBake option to consider is the ``-k`` or ``--continue``
85option. This option instructs BitBake to try and continue processing the
86job as long as possible even after encountering an error. When an error
87occurs, the target that failed and those that depend on it cannot be
88remade. However, when you use this option other dependencies can still
89be processed.
90
Andrew Geisslerc9f78652020-09-18 14:11:35 -050091Recipes
92-------
93
94Files that have the ``.bb`` suffix are "recipes" files. In general, a
95recipe contains information about a single piece of software. This
96information includes the location from which to download the unaltered
97source, any source patches to be applied to that source (if needed),
98which special configuration options to apply, how to compile the source
99files, and how to package the compiled output.
100
101The term "package" is sometimes used to refer to recipes. However, since
102the word "package" is used for the packaged output from the OpenEmbedded
103build system (i.e. ``.ipk`` or ``.deb`` files), this document avoids
104using the term "package" when referring to recipes.
105
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500106Classes
107-------
108
109Class files (``.bbclass``) contain information that is useful to share
110between recipes files. An example is the
111:ref:`autotools <ref-classes-autotools>` class,
Patrick Williams03907ee2022-05-01 06:28:52 -0500112which contains common settings for any application that is built with
113the `GNU Autotools <https://en.wikipedia.org/wiki/GNU_Autotools>`__.
114The ":ref:`ref-manual/classes:Classes`" chapter in the Yocto Project
115Reference Manual provides details about classes and how to use them.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500116
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500117Configurations
118--------------
119
120The configuration files (``.conf``) define various configuration
121variables that govern the OpenEmbedded build process. These files fall
122into several areas that define machine configuration options,
123distribution configuration options, compiler tuning options, general
124common configuration options, and user configuration options in
125``conf/local.conf``, which is found in the :term:`Build Directory`.
126
127
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500128Layers
129======
130
131Layers are repositories that contain related metadata (i.e. sets of
132instructions) that tell the OpenEmbedded build system how to build a
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500133target. :ref:`overview-manual/yp-intro:the yocto project layer model`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500134facilitates collaboration, sharing, customization, and reuse within the
135Yocto Project development environment. Layers logically separate
136information for your project. For example, you can use a layer to hold
137all the configurations for a particular piece of hardware. Isolating
138hardware-specific configurations allows you to share other metadata by
139using a different layer where that metadata might be common across
140several pieces of hardware.
141
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700142There are many layers working in the Yocto Project development environment. The
Patrick Williams03907ee2022-05-01 06:28:52 -0500143:yocto_home:`Yocto Project Compatible Layer Index </software-overview/layers/>`
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600144and :oe_layerindex:`OpenEmbedded Layer Index <>` both contain layers from
145which you can use or leverage.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500146
147By convention, layers in the Yocto Project follow a specific form.
148Conforming to a known structure allows BitBake to make assumptions
149during builds on where to find types of metadata. You can find
150procedures and learn about tools (i.e. ``bitbake-layers``) for creating
151layers suitable for the Yocto Project in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600152":ref:`dev-manual/common-tasks:understanding and creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500153section of the Yocto Project Development Tasks Manual.
154
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500155OpenEmbedded Build System Concepts
156==================================
157
158This section takes a more detailed look inside the build process used by
159the :term:`OpenEmbedded Build System`,
160which is the build
161system specific to the Yocto Project. At the heart of the build system
162is BitBake, the task executor.
163
164The following diagram represents the high-level workflow of a build. The
165remainder of this section expands on the fundamental input, output,
166process, and metadata logical blocks that make up the workflow.
167
168.. image:: figures/YP-flow-diagram.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500169 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500170
171In general, the build's workflow consists of several functional areas:
172
173- *User Configuration:* metadata you can use to control the build
174 process.
175
176- *Metadata Layers:* Various layers that provide software, machine, and
177 distro metadata.
178
179- *Source Files:* Upstream releases, local projects, and SCMs.
180
181- *Build System:* Processes under the control of
182 :term:`BitBake`. This block expands
183 on how BitBake fetches source, applies patches, completes
184 compilation, analyzes output for package generation, creates and
185 tests packages, generates images, and generates cross-development
186 tools.
187
188- *Package Feeds:* Directories containing output packages (RPM, DEB or
189 IPK), which are subsequently used in the construction of an image or
190 Software Development Kit (SDK), produced by the build system. These
191 feeds can also be copied and shared using a web server or other means
192 to facilitate extending or updating existing images on devices at
193 runtime if runtime package management is enabled.
194
195- *Images:* Images produced by the workflow.
196
197- *Application Development SDK:* Cross-development tools that are
198 produced along with an image or separately with BitBake.
199
200User Configuration
201------------------
202
203User configuration helps define the build. Through user configuration,
204you can tell BitBake the target architecture for which you are building
205the image, where to store downloaded source, and other build properties.
206
207The following figure shows an expanded representation of the "User
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500208Configuration" box of the :ref:`general workflow
209figure <overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500210
211.. image:: figures/user-configuration.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500212 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500213
214BitBake needs some basic configuration files in order to complete a
215build. These files are ``*.conf`` files. The minimally necessary ones
216reside as example files in the ``build/conf`` directory of the
217:term:`Source Directory`. For simplicity,
218this section refers to the Source Directory as the "Poky Directory."
219
220When you clone the :term:`Poky` Git repository
221or you download and unpack a Yocto Project release, you can set up the
222Source Directory to be named anything you want. For this discussion, the
223cloned repository uses the default name ``poky``.
224
225.. note::
226
227 The Poky repository is primarily an aggregation of existing
228 repositories. It is not a canonical upstream source.
229
230The ``meta-poky`` layer inside Poky contains a ``conf`` directory that
231has example configuration files. These example files are used as a basis
232for creating actual configuration files when you source
233:ref:`structure-core-script`, which is the
234build environment script.
235
236Sourcing the build environment script creates a
237:term:`Build Directory` if one does not
238already exist. BitBake uses the Build Directory for all its work during
239builds. The Build Directory has a ``conf`` directory that contains
240default versions of your ``local.conf`` and ``bblayers.conf``
241configuration files. These default configuration files are created only
242if versions do not already exist in the Build Directory at the time you
243source the build environment setup script.
244
245Because the Poky repository is fundamentally an aggregation of existing
246repositories, some users might be familiar with running the
247:ref:`structure-core-script` script in the context of separate
248:term:`OpenEmbedded-Core (OE-Core)` and BitBake
249repositories rather than a single Poky repository. This discussion
250assumes the script is executed from within a cloned or unpacked version
251of Poky.
252
253Depending on where the script is sourced, different sub-scripts are
254called to set up the Build Directory (Yocto or OpenEmbedded).
255Specifically, the script ``scripts/oe-setup-builddir`` inside the poky
256directory sets up the Build Directory and seeds the directory (if
257necessary) with configuration files appropriate for the Yocto Project
258development environment.
259
260.. note::
261
262 The
263 scripts/oe-setup-builddir
264 script uses the
265 ``$TEMPLATECONF``
266 variable to determine which sample configuration files to locate.
267
268The ``local.conf`` file provides many basic variables that define a
269build environment. Here is a list of a few. To see the default
270configurations in a ``local.conf`` file created by the build environment
271script, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600272:yocto_git:`local.conf.sample </poky/tree/meta-poky/conf/local.conf.sample>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500273in the ``meta-poky`` layer:
274
275- *Target Machine Selection:* Controlled by the
276 :term:`MACHINE` variable.
277
278- *Download Directory:* Controlled by the
279 :term:`DL_DIR` variable.
280
281- *Shared State Directory:* Controlled by the
282 :term:`SSTATE_DIR` variable.
283
284- *Build Output:* Controlled by the
285 :term:`TMPDIR` variable.
286
287- *Distribution Policy:* Controlled by the
288 :term:`DISTRO` variable.
289
290- *Packaging Format:* Controlled by the
291 :term:`PACKAGE_CLASSES`
292 variable.
293
294- *SDK Target Architecture:* Controlled by the
295 :term:`SDKMACHINE` variable.
296
297- *Extra Image Packages:* Controlled by the
298 :term:`EXTRA_IMAGE_FEATURES`
299 variable.
300
301.. note::
302
Andrew Geissler9aee5002022-03-30 16:27:02 +0000303 Configurations set in the ``conf/local.conf`` file can also be set
304 in the ``conf/site.conf`` and ``conf/auto.conf`` configuration files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500305
306The ``bblayers.conf`` file tells BitBake what layers you want considered
307during the build. By default, the layers listed in this file include
308layers minimally needed by the build system. However, you must manually
309add any custom layers you have created. You can find more information on
310working with the ``bblayers.conf`` file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600311":ref:`dev-manual/common-tasks:enabling your layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500312section in the Yocto Project Development Tasks Manual.
313
314The files ``site.conf`` and ``auto.conf`` are not created by the
315environment initialization script. If you want the ``site.conf`` file,
Andrew Geisslerd5838332022-05-27 11:33:10 -0500316you need to create it yourself. The ``auto.conf`` file is typically
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500317created by an autobuilder:
318
319- *site.conf:* You can use the ``conf/site.conf`` configuration
320 file to configure multiple build directories. For example, suppose
321 you had several build environments and they shared some common
322 features. You can set these default build properties here. A good
323 example is perhaps the packaging format to use through the
Andrew Geisslerd5838332022-05-27 11:33:10 -0500324 :term:`PACKAGE_CLASSES` variable.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500325
326- *auto.conf:* The file is usually created and written to by an
327 autobuilder. The settings put into the file are typically the same as
328 you would find in the ``conf/local.conf`` or the ``conf/site.conf``
329 files.
330
331You can edit all configuration files to further define any particular
332build environment. This process is represented by the "User
333Configuration Edits" box in the figure.
334
335When you launch your build with the ``bitbake target`` command, BitBake
336sorts out the configurations to ultimately define your build
337environment. It is important to understand that the
338:term:`OpenEmbedded Build System` reads the
339configuration files in a specific order: ``site.conf``, ``auto.conf``,
340and ``local.conf``. And, the build system applies the normal assignment
341statement rules as described in the
342":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`" chapter
343of the BitBake User Manual. Because the files are parsed in a specific
344order, variable assignments for the same variable could be affected. For
345example, if the ``auto.conf`` file and the ``local.conf`` set variable1
346to different values, because the build system parses ``local.conf``
347after ``auto.conf``, variable1 is assigned the value from the
348``local.conf`` file.
349
350Metadata, Machine Configuration, and Policy Configuration
351---------------------------------------------------------
352
353The previous section described the user configurations that define
354BitBake's global behavior. This section takes a closer look at the
355layers the build system uses to further control the build. These layers
356provide Metadata for the software, machine, and policies.
357
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700358In general, there are three types of layer input. You can see them below
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500359the "User Configuration" box in the `general workflow
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500360figure <overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500361
362- *Metadata (.bb + Patches):* Software layers containing
363 user-supplied recipe files, patches, and append files. A good example
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600364 of a software layer might be the :oe_layer:`meta-qt5 layer </meta-qt5>`
365 from the :oe_layerindex:`OpenEmbedded Layer Index <>`. This layer is for
366 version 5.0 of the popular `Qt <https://wiki.qt.io/About_Qt>`__
367 cross-platform application development framework for desktop, embedded and
368 mobile.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500369
370- *Machine BSP Configuration:* Board Support Package (BSP) layers (i.e.
371 "BSP Layer" in the following figure) providing machine-specific
372 configurations. This type of information is specific to a particular
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500373 target architecture. A good example of a BSP layer from the
374 :ref:`overview-manual/yp-intro:reference distribution (poky)` is the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600375 :yocto_git:`meta-yocto-bsp </poky/tree/meta-yocto-bsp>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500376 layer.
377
378- *Policy Configuration:* Distribution Layers (i.e. "Distro Layer" in
379 the following figure) providing top-level or general policies for the
380 images or SDKs being built for a particular distribution. For
381 example, in the Poky Reference Distribution the distro layer is the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600382 :yocto_git:`meta-poky </poky/tree/meta-poky>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500383 layer. Within the distro layer is a ``conf/distro`` directory that
384 contains distro configuration files (e.g.
Andrew Geissler09209ee2020-12-13 08:44:15 -0600385 :yocto_git:`poky.conf </poky/tree/meta-poky/conf/distro/poky.conf>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500386 that contain many policy configurations for the Poky distribution.
387
388The following figure shows an expanded representation of these three
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500389layers from the :ref:`general workflow figure
390<overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500391
392.. image:: figures/layer-input.png
393 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -0500394 :width: 70%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500395
396In general, all layers have a similar structure. They all contain a
397licensing file (e.g. ``COPYING.MIT``) if the layer is to be distributed,
398a ``README`` file as good practice and especially if the layer is to be
399distributed, a configuration directory, and recipe directories. You can
400learn about the general structure for layers used with the Yocto Project
401in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600402":ref:`dev-manual/common-tasks:creating your own layer`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500403section in the
404Yocto Project Development Tasks Manual. For a general discussion on
405layers and the many layers from which you can draw, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500406":ref:`overview-manual/concepts:layers`" and
407":ref:`overview-manual/yp-intro:the yocto project layer model`" sections both
408earlier in this manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500409
410If you explored the previous links, you discovered some areas where many
Andrew Geissler09209ee2020-12-13 08:44:15 -0600411layers that work with the Yocto Project exist. The :yocto_git:`Source
412Repositories <>` also shows layers categorized under "Yocto Metadata Layers."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500413
414.. note::
415
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700416 There are layers in the Yocto Project Source Repositories that cannot be
417 found in the OpenEmbedded Layer Index. Such layers are either
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500418 deprecated or experimental in nature.
419
420BitBake uses the ``conf/bblayers.conf`` file, which is part of the user
421configuration, to find what layers it should be using as part of the
422build.
423
424Distro Layer
425~~~~~~~~~~~~
426
427The distribution layer provides policy configurations for your
428distribution. Best practices dictate that you isolate these types of
429configurations into their own layer. Settings you provide in
430``conf/distro/distro.conf`` override similar settings that BitBake finds
431in your ``conf/local.conf`` file in the Build Directory.
432
433The following list provides some explanation and references for what you
434typically find in the distribution layer:
435
436- *classes:* Class files (``.bbclass``) hold common functionality that
437 can be shared among recipes in the distribution. When your recipes
438 inherit a class, they take on the settings and functions for that
439 class. You can read more about class files in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600440 ":ref:`ref-manual/classes:Classes`" chapter of the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500441 Reference Manual.
442
443- *conf:* This area holds configuration files for the layer
444 (``conf/layer.conf``), the distribution
445 (``conf/distro/distro.conf``), and any distribution-wide include
446 files.
447
448- *recipes-*:* Recipes and append files that affect common
449 functionality across the distribution. This area could include
450 recipes and append files to add distribution-specific configuration,
451 initialization scripts, custom image recipes, and so forth. Examples
452 of ``recipes-*`` directories are ``recipes-core`` and
453 ``recipes-extra``. Hierarchy and contents within a ``recipes-*``
454 directory can vary. Generally, these directories contain recipe files
455 (``*.bb``), recipe append files (``*.bbappend``), directories that
456 are distro-specific for configuration files, and so forth.
457
458BSP Layer
459~~~~~~~~~
460
461The BSP Layer provides machine configurations that target specific
462hardware. Everything in this layer is specific to the machine for which
463you are building the image or the SDK. A common structure or form is
464defined for BSP layers. You can learn more about this structure in the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600465:doc:`/bsp-guide/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500466
467.. note::
468
469 In order for a BSP layer to be considered compliant with the Yocto
470 Project, it must meet some structural requirements.
471
472The BSP Layer's configuration directory contains configuration files for
473the machine (``conf/machine/machine.conf``) and, of course, the layer
474(``conf/layer.conf``).
475
476The remainder of the layer is dedicated to specific recipes by function:
477``recipes-bsp``, ``recipes-core``, ``recipes-graphics``,
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700478``recipes-kernel``, and so forth. There can be metadata for multiple
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500479formfactors, graphics support systems, and so forth.
480
481.. note::
482
483 While the figure shows several
484 recipes-\*
485 directories, not all these directories appear in all BSP layers.
486
487Software Layer
488~~~~~~~~~~~~~~
489
490The software layer provides the Metadata for additional software
491packages used during the build. This layer does not include Metadata
492that is specific to the distribution or the machine, which are found in
493their respective layers.
494
495This layer contains any recipes, append files, and patches, that your
496project needs.
497
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500498Sources
499-------
500
501In order for the OpenEmbedded build system to create an image or any
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500502target, it must be able to access source files. The :ref:`general workflow
503figure <overview-manual/concepts:openembedded build system concepts>`
504represents source files using the "Upstream Project Releases", "Local
505Projects", and "SCMs (optional)" boxes. The figure represents mirrors,
506which also play a role in locating source files, with the "Source
507Materials" box.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500508
509The method by which source files are ultimately organized is a function
510of the project. For example, for released software, projects tend to use
511tarballs or other archived files that can capture the state of a release
512guaranteeing that it is statically represented. On the other hand, for a
513project that is more dynamic or experimental in nature, a project might
514keep source files in a repository controlled by a Source Control Manager
515(SCM) such as Git. Pulling source from a repository allows you to
516control the point in the repository (the revision) from which you want
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700517to build software. A combination of the two is also possible.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500518
519BitBake uses the :term:`SRC_URI`
520variable to point to source files regardless of their location. Each
Andrew Geissler09036742021-06-25 14:25:14 -0500521recipe must have a :term:`SRC_URI` variable that points to the source.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500522
523Another area that plays a significant role in where source files come
524from is pointed to by the
525:term:`DL_DIR` variable. This area is
526a cache that can hold previously downloaded source. You can also
527instruct the OpenEmbedded build system to create tarballs from Git
528repositories, which is not the default behavior, and store them in the
Andrew Geissler09036742021-06-25 14:25:14 -0500529:term:`DL_DIR` by using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500530:term:`BB_GENERATE_MIRROR_TARBALLS`
531variable.
532
Andrew Geissler09036742021-06-25 14:25:14 -0500533Judicious use of a :term:`DL_DIR` directory can save the build system a trip
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500534across the Internet when looking for files. A good method for using a
Andrew Geissler09036742021-06-25 14:25:14 -0500535download directory is to have :term:`DL_DIR` point to an area outside of
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500536your Build Directory. Doing so allows you to safely delete the Build
537Directory if needed without fear of removing any downloaded source file.
538
539The remainder of this section provides a deeper look into the source
540files and the mirrors. Here is a more detailed look at the source file
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500541area of the :ref:`general workflow figure <overview-manual/concepts:openembedded build system concepts>`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500542
543.. image:: figures/source-input.png
544 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -0500545 :width: 70%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500546
547Upstream Project Releases
548~~~~~~~~~~~~~~~~~~~~~~~~~
549
550Upstream project releases exist anywhere in the form of an archived file
551(e.g. tarball or zip file). These files correspond to individual
552recipes. For example, the figure uses specific releases each for
553BusyBox, Qt, and Dbus. An archive file can be for any released product
554that can be built using a recipe.
555
556Local Projects
557~~~~~~~~~~~~~~
558
559Local projects are custom bits of software the user provides. These bits
Andrew Geissler615f2f12022-07-15 14:00:58 -0500560reside somewhere local to a project --- perhaps a directory into which the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500561user checks in items (e.g. a local directory containing a development
562source tree used by the group).
563
564The canonical method through which to include a local project is to use
565the :ref:`externalsrc <ref-classes-externalsrc>`
566class to include that local project. You use either the ``local.conf``
567or a recipe's append file to override or set the recipe to point to the
568local directory on your disk to pull in the whole source tree.
569
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500570Source Control Managers (Optional)
571~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
572
573Another place from which the build system can get source files is with
Patrick Williams213cb262021-08-07 19:21:33 -0500574:ref:`bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers` employing various Source
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500575Control Managers (SCMs) such as Git or Subversion. In such cases, a
576repository is cloned or checked out. The
577:ref:`ref-tasks-fetch` task inside
578BitBake uses the :term:`SRC_URI`
579variable and the argument's prefix to determine the correct fetcher
580module.
581
582.. note::
583
584 For information on how to have the OpenEmbedded build system generate
585 tarballs for Git repositories and place them in the
586 DL_DIR
587 directory, see the :term:`BB_GENERATE_MIRROR_TARBALLS`
588 variable in the Yocto Project Reference Manual.
589
590When fetching a repository, BitBake uses the
591:term:`SRCREV` variable to determine
592the specific revision from which to build.
593
594Source Mirror(s)
595~~~~~~~~~~~~~~~~
596
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700597There are two kinds of mirrors: pre-mirrors and regular mirrors. The
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500598:term:`PREMIRRORS` and
599:term:`MIRRORS` variables point to
600these, respectively. BitBake checks pre-mirrors before looking upstream
601for any source files. Pre-mirrors are appropriate when you have a shared
602directory that is not a directory defined by the
603:term:`DL_DIR` variable. A Pre-mirror
604typically points to a shared directory that is local to your
605organization.
606
607Regular mirrors can be any site across the Internet that is used as an
608alternative location for source code should the primary site not be
609functioning for some reason or another.
610
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500611Package Feeds
612-------------
613
614When the OpenEmbedded build system generates an image or an SDK, it gets
615the packages from a package feed area located in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500616:term:`Build Directory`. The :ref:`general workflow figure
617<overview-manual/concepts:openembedded build system concepts>`
618shows this package feeds area in the upper-right corner.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500619
620This section looks a little closer into the package feeds area used by
621the build system. Here is a more detailed look at the area:
622
623.. image:: figures/package-feeds.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500624 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500625
626Package feeds are an intermediary step in the build process. The
627OpenEmbedded build system provides classes to generate different package
628types, and you specify which classes to enable through the
629:term:`PACKAGE_CLASSES`
630variable. Before placing the packages into package feeds, the build
631process validates them with generated output quality assurance checks
632through the :ref:`insane <ref-classes-insane>`
633class.
634
635The package feed area resides in the Build Directory. The directory the
636build system uses to temporarily store packages is determined by a
637combination of variables and the particular package manager in use. See
638the "Package Feeds" box in the illustration and note the information to
639the right of that area. In particular, the following defines where
640package files are kept:
641
642- :term:`DEPLOY_DIR`: Defined as
643 ``tmp/deploy`` in the Build Directory.
644
645- ``DEPLOY_DIR_*``: Depending on the package manager used, the package
646 type sub-folder. Given RPM, IPK, or DEB packaging and tarball
647 creation, the
648 :term:`DEPLOY_DIR_RPM`,
649 :term:`DEPLOY_DIR_IPK`,
650 :term:`DEPLOY_DIR_DEB`, or
651 :term:`DEPLOY_DIR_TAR`,
652 variables are used, respectively.
653
654- :term:`PACKAGE_ARCH`: Defines
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700655 architecture-specific sub-folders. For example, packages could be
656 available for the i586 or qemux86 architectures.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500657
658BitBake uses the
659:ref:`do_package_write_* <ref-tasks-package_write_deb>`
660tasks to generate packages and place them into the package holding area
661(e.g. ``do_package_write_ipk`` for IPK packages). See the
662":ref:`ref-tasks-package_write_deb`",
663":ref:`ref-tasks-package_write_ipk`",
664":ref:`ref-tasks-package_write_rpm`",
665and
666":ref:`ref-tasks-package_write_tar`"
667sections in the Yocto Project Reference Manual for additional
668information. As an example, consider a scenario where an IPK packaging
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700669manager is being used and there is package architecture support for both
670i586 and qemux86. Packages for the i586 architecture are placed in
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500671``build/tmp/deploy/ipk/i586``, while packages for the qemux86
672architecture are placed in ``build/tmp/deploy/ipk/qemux86``.
673
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500674BitBake Tool
675------------
676
677The OpenEmbedded build system uses
678:term:`BitBake` to produce images and
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500679Software Development Kits (SDKs). You can see from the :ref:`general workflow
680figure <overview-manual/concepts:openembedded build system concepts>`,
681the BitBake area consists of several functional areas. This section takes a
682closer look at each of those areas.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500683
684.. note::
685
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700686 Documentation for the BitBake tool is available separately. See the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500687 BitBake User Manual
688 for reference material on BitBake.
689
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500690Source Fetching
691~~~~~~~~~~~~~~~
692
693The first stages of building a recipe are to fetch and unpack the source
694code:
695
696.. image:: figures/source-fetching.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500697 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500698
699The :ref:`ref-tasks-fetch` and
700:ref:`ref-tasks-unpack` tasks fetch
701the source files and unpack them into the
702:term:`Build Directory`.
703
704.. note::
705
706 For every local file (e.g.
707 file://
708 ) that is part of a recipe's
709 SRC_URI
710 statement, the OpenEmbedded build system takes a checksum of the file
711 for the recipe and inserts the checksum into the signature for the
712 do_fetch
713 task. If any local file has been modified, the
714 do_fetch
715 task and all tasks that depend on it are re-executed.
716
717By default, everything is accomplished in the Build Directory, which has
718a defined structure. For additional general information on the Build
719Directory, see the ":ref:`structure-core-build`" section in
720the Yocto Project Reference Manual.
721
722Each recipe has an area in the Build Directory where the unpacked source
723code resides. The :term:`S` variable points
724to this area for a recipe's unpacked source code. The name of that
725directory for any given recipe is defined from several different
726variables. The preceding figure and the following list describe the
727Build Directory's hierarchy:
728
729- :term:`TMPDIR`: The base directory
730 where the OpenEmbedded build system performs all its work during the
731 build. The default base directory is the ``tmp`` directory.
732
733- :term:`PACKAGE_ARCH`: The
734 architecture of the built package or packages. Depending on the
735 eventual destination of the package or packages (i.e. machine
736 architecture, :term:`Build Host`, SDK, or
Andrew Geissler09036742021-06-25 14:25:14 -0500737 specific machine), :term:`PACKAGE_ARCH` varies. See the variable's
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500738 description for details.
739
740- :term:`TARGET_OS`: The operating
741 system of the target device. A typical value would be "linux" (e.g.
742 "qemux86-poky-linux").
743
744- :term:`PN`: The name of the recipe used
745 to build the package. This variable can have multiple meanings.
Andrew Geissler09036742021-06-25 14:25:14 -0500746 However, when used in the context of input files, :term:`PN` represents
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500747 the name of the recipe.
748
749- :term:`WORKDIR`: The location
750 where the OpenEmbedded build system builds a recipe (i.e. does the
751 work to create the package).
752
753 - :term:`PV`: The version of the
754 recipe used to build the package.
755
756 - :term:`PR`: The revision of the
757 recipe used to build the package.
758
759- :term:`S`: Contains the unpacked source
760 files for a given recipe.
761
762 - :term:`BPN`: The name of the recipe
Andrew Geissler09036742021-06-25 14:25:14 -0500763 used to build the package. The :term:`BPN` variable is a version of
Andrew Geissler5f350902021-07-23 13:09:54 -0400764 the :term:`PN` variable but with common prefixes and suffixes removed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500765
766 - :term:`PV`: The version of the
767 recipe used to build the package.
768
769.. note::
770
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700771 In the previous figure, notice that there are two sample hierarchies:
772 one based on package architecture (i.e. :term:`PACKAGE_ARCH`)
773 and one based on a machine (i.e. :term:`MACHINE`).
774 The underlying structures are identical. The differentiator being
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500775 what the OpenEmbedded build system is using as a build target (e.g.
776 general architecture, a build host, an SDK, or a specific machine).
777
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500778Patching
779~~~~~~~~
780
781Once source code is fetched and unpacked, BitBake locates patch files
782and applies them to the source files:
783
784.. image:: figures/patching.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500785 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500786
787The :ref:`ref-tasks-patch` task uses a
788recipe's :term:`SRC_URI` statements
789and the :term:`FILESPATH` variable
790to locate applicable patch files.
791
792Default processing for patch files assumes the files have either
Andrew Geissler09036742021-06-25 14:25:14 -0500793``*.patch`` or ``*.diff`` file types. You can use :term:`SRC_URI` parameters
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500794to change the way the build system recognizes patch files. See the
795:ref:`ref-tasks-patch` task for more
796information.
797
798BitBake finds and applies multiple patches for a single recipe in the
Andrew Geissler09036742021-06-25 14:25:14 -0500799order in which it locates the patches. The :term:`FILESPATH` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500800defines the default set of directories that the build system uses to
801search for patch files. Once found, patches are applied to the recipe's
802source files, which are located in the
803:term:`S` directory.
804
805For more information on how the source directories are created, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500806":ref:`overview-manual/concepts:source fetching`" section. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500807more information on how to create patches and how the build system
808processes patches, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600809":ref:`dev-manual/common-tasks:patching code`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500810section in the
811Yocto Project Development Tasks Manual. You can also see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600812":ref:`sdk-manual/extensible:use \`\`devtool modify\`\` to modify the source of an existing component`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500813section in the Yocto Project Application Development and the Extensible
814Software Development Kit (SDK) manual and the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600815":ref:`kernel-dev/common:using traditional kernel development to patch the kernel`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500816section in the Yocto Project Linux Kernel Development Manual.
817
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500818Configuration, Compilation, and Staging
819~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
820
821After source code is patched, BitBake executes tasks that configure and
822compile the source code. Once compilation occurs, the files are copied
823to a holding area (staged) in preparation for packaging:
824
825.. image:: figures/configuration-compile-autoreconf.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500826 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500827
828This step in the build process consists of the following tasks:
829
830- :ref:`ref-tasks-prepare_recipe_sysroot`:
831 This task sets up the two sysroots in
832 ``${``\ :term:`WORKDIR`\ ``}``
833 (i.e. ``recipe-sysroot`` and ``recipe-sysroot-native``) so that
834 during the packaging phase the sysroots can contain the contents of
835 the
836 :ref:`ref-tasks-populate_sysroot`
837 tasks of the recipes on which the recipe containing the tasks
838 depends. A sysroot exists for both the target and for the native
839 binaries, which run on the host system.
840
841- *do_configure*: This task configures the source by enabling and
842 disabling any build-time and configuration options for the software
843 being built. Configurations can come from the recipe itself as well
844 as from an inherited class. Additionally, the software itself might
845 configure itself depending on the target for which it is being built.
846
847 The configurations handled by the
848 :ref:`ref-tasks-configure` task
849 are specific to configurations for the source code being built by the
850 recipe.
851
852 If you are using the
853 :ref:`autotools <ref-classes-autotools>` class,
854 you can add additional configuration options by using the
855 :term:`EXTRA_OECONF` or
856 :term:`PACKAGECONFIG_CONFARGS`
857 variables. For information on how this variable works within that
858 class, see the
859 :ref:`autotools <ref-classes-autotools>` class
Andrew Geissler09209ee2020-12-13 08:44:15 -0600860 :yocto_git:`here </poky/tree/meta/classes/autotools.bbclass>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500861
862- *do_compile*: Once a configuration task has been satisfied,
863 BitBake compiles the source using the
864 :ref:`ref-tasks-compile` task.
865 Compilation occurs in the directory pointed to by the
866 :term:`B` variable. Realize that the
Andrew Geissler09036742021-06-25 14:25:14 -0500867 :term:`B` directory is, by default, the same as the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500868 :term:`S` directory.
869
870- *do_install*: After compilation completes, BitBake executes the
871 :ref:`ref-tasks-install` task.
Andrew Geissler09036742021-06-25 14:25:14 -0500872 This task copies files from the :term:`B` directory and places them in a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500873 holding area pointed to by the :term:`D`
874 variable. Packaging occurs later using files from this holding
875 directory.
876
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500877Package Splitting
878~~~~~~~~~~~~~~~~~
879
880After source code is configured, compiled, and staged, the build system
881analyzes the results and splits the output into packages:
882
883.. image:: figures/analysis-for-package-splitting.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500884 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500885
886The :ref:`ref-tasks-package` and
887:ref:`ref-tasks-packagedata`
888tasks combine to analyze the files found in the
889:term:`D` directory and split them into
890subsets based on available packages and files. Analysis involves the
891following as well as other items: splitting out debugging symbols,
892looking at shared library dependencies between packages, and looking at
893package relationships.
894
895The ``do_packagedata`` task creates package metadata based on the
896analysis such that the build system can generate the final packages. The
897:ref:`ref-tasks-populate_sysroot`
898task stages (copies) a subset of the files installed by the
899:ref:`ref-tasks-install` task into
900the appropriate sysroot. Working, staged, and intermediate results of
901the analysis and package splitting process use several areas:
902
903- :term:`PKGD`: The destination
904 directory (i.e. ``package``) for packages before they are split into
905 individual packages.
906
907- :term:`PKGDESTWORK`: A
908 temporary work area (i.e. ``pkgdata``) used by the ``do_package``
909 task to save package metadata.
910
911- :term:`PKGDEST`: The parent
912 directory (i.e. ``packages-split``) for packages after they have been
913 split.
914
915- :term:`PKGDATA_DIR`: A shared,
916 global-state directory that holds packaging metadata generated during
917 the packaging process. The packaging process copies metadata from
Andrew Geissler09036742021-06-25 14:25:14 -0500918 :term:`PKGDESTWORK` to the :term:`PKGDATA_DIR` area where it becomes globally
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500919 available.
920
921- :term:`STAGING_DIR_HOST`:
922 The path for the sysroot for the system on which a component is built
923 to run (i.e. ``recipe-sysroot``).
924
925- :term:`STAGING_DIR_NATIVE`:
926 The path for the sysroot used when building components for the build
927 host (i.e. ``recipe-sysroot-native``).
928
929- :term:`STAGING_DIR_TARGET`:
930 The path for the sysroot used when a component that is built to
931 execute on a system and it generates code for yet another machine
932 (e.g. cross-canadian recipes).
933
934The :term:`FILES` variable defines the
935files that go into each package in
936:term:`PACKAGES`. If you want
937details on how this is accomplished, you can look at
Andrew Geissler09209ee2020-12-13 08:44:15 -0600938:yocto_git:`package.bbclass </poky/tree/meta/classes/package.bbclass>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500939
940Depending on the type of packages being created (RPM, DEB, or IPK), the
941:ref:`do_package_write_* <ref-tasks-package_write_deb>`
942task creates the actual packages and places them in the Package Feed
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500943area, which is ``${TMPDIR}/deploy``. You can see the
944":ref:`overview-manual/concepts:package feeds`" section for more detail on
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500945that part of the build process.
946
947.. note::
948
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700949 Support for creating feeds directly from the ``deploy/*``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500950 directories does not exist. Creating such feeds usually requires some
951 kind of feed maintenance mechanism that would upload the new packages
952 into an official package feed (e.g. the Ångström distribution). This
953 functionality is highly distribution-specific and thus is not
954 provided out of the box.
955
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500956Image Generation
957~~~~~~~~~~~~~~~~
958
959Once packages are split and stored in the Package Feeds area, the build
960system uses BitBake to generate the root filesystem image:
961
962.. image:: figures/image-generation.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500963 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500964
965The image generation process consists of several stages and depends on
966several tasks and variables. The
967:ref:`ref-tasks-rootfs` task creates
968the root filesystem (file and directory structure) for an image. This
969task uses several key variables to help create the list of packages to
970actually install:
971
972- :term:`IMAGE_INSTALL`: Lists
973 out the base set of packages from which to install from the Package
974 Feeds area.
975
976- :term:`PACKAGE_EXCLUDE`:
977 Specifies packages that should not be installed into the image.
978
979- :term:`IMAGE_FEATURES`:
980 Specifies features to include in the image. Most of these features
981 map to additional packages for installation.
982
983- :term:`PACKAGE_CLASSES`:
984 Specifies the package backend (e.g. RPM, DEB, or IPK) to use and
985 consequently helps determine where to locate packages within the
986 Package Feeds area.
987
988- :term:`IMAGE_LINGUAS`:
989 Determines the language(s) for which additional language support
990 packages are installed.
991
992- :term:`PACKAGE_INSTALL`:
993 The final list of packages passed to the package manager for
994 installation into the image.
995
996With :term:`IMAGE_ROOTFS`
997pointing to the location of the filesystem under construction and the
Andrew Geissler09036742021-06-25 14:25:14 -0500998:term:`PACKAGE_INSTALL` variable providing the final list of packages to
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500999install, the root file system is created.
1000
1001Package installation is under control of the package manager (e.g.
1002dnf/rpm, opkg, or apt/dpkg) regardless of whether or not package
1003management is enabled for the target. At the end of the process, if
1004package management is not enabled for the target, the package manager's
1005data files are deleted from the root filesystem. As part of the final
1006stage of package installation, post installation scripts that are part
1007of the packages are run. Any scripts that fail to run on the build host
1008are run on the target when the target system is first booted. If you are
1009using a
Andrew Geissler09209ee2020-12-13 08:44:15 -06001010:ref:`read-only root filesystem <dev-manual/common-tasks:creating a read-only root filesystem>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001011all the post installation scripts must succeed on the build host during
1012the package installation phase since the root filesystem on the target
1013is read-only.
1014
1015The final stages of the ``do_rootfs`` task handle post processing. Post
1016processing includes creation of a manifest file and optimizations.
1017
1018The manifest file (``.manifest``) resides in the same directory as the
1019root filesystem image. This file lists out, line-by-line, the installed
1020packages. The manifest file is useful for the
1021:ref:`testimage <ref-classes-testimage*>` class,
1022for example, to determine whether or not to run specific tests. See the
1023:term:`IMAGE_MANIFEST`
1024variable for additional information.
1025
Andrew Geissler9aee5002022-03-30 16:27:02 +00001026Optimizing processes that are run across the image include ``mklibs``
1027and any other post-processing commands as defined by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001028:term:`ROOTFS_POSTPROCESS_COMMAND`
Andrew Geissler9aee5002022-03-30 16:27:02 +00001029variable. The ``mklibs`` process optimizes the size of the libraries.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001030
1031After the root filesystem is built, processing begins on the image
1032through the :ref:`ref-tasks-image`
1033task. The build system runs any pre-processing commands as defined by
1034the
1035:term:`IMAGE_PREPROCESS_COMMAND`
1036variable. This variable specifies a list of functions to call before the
1037build system creates the final image output files.
1038
1039The build system dynamically creates ``do_image_*`` tasks as needed,
1040based on the image types specified in the
1041:term:`IMAGE_FSTYPES` variable.
1042The process turns everything into an image file or a set of image files
1043and can compress the root filesystem image to reduce the overall size of
1044the image. The formats used for the root filesystem depend on the
Andrew Geissler09036742021-06-25 14:25:14 -05001045:term:`IMAGE_FSTYPES` variable. Compression depends on whether the formats
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001046support compression.
1047
1048As an example, a dynamically created task when creating a particular
Andrew Geisslerc926e172021-05-07 16:11:35 -05001049image type would take the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001050
1051 do_image_type
1052
1053So, if the type
Andrew Geissler09036742021-06-25 14:25:14 -05001054as specified by the :term:`IMAGE_FSTYPES` were ``ext4``, the dynamically
Andrew Geisslerc926e172021-05-07 16:11:35 -05001055generated task would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001056
1057 do_image_ext4
1058
1059The final task involved in image creation is the
1060:ref:`do_image_complete <ref-tasks-image-complete>`
1061task. This task completes the image by applying any image post
1062processing as defined through the
1063:term:`IMAGE_POSTPROCESS_COMMAND`
1064variable. The variable specifies a list of functions to call once the
1065build system has created the final image output files.
1066
1067.. note::
1068
1069 The entire image generation process is run under
1070 Pseudo. Running under Pseudo ensures that the files in the root filesystem
1071 have correct ownership.
1072
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001073SDK Generation
1074~~~~~~~~~~~~~~
1075
1076The OpenEmbedded build system uses BitBake to generate the Software
1077Development Kit (SDK) installer scripts for both the standard SDK and
1078the extensible SDK (eSDK):
1079
1080.. image:: figures/sdk-generation.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05001081 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001082
1083.. note::
1084
1085 For more information on the cross-development toolchain generation,
Andrew Geissler09209ee2020-12-13 08:44:15 -06001086 see the ":ref:`overview-manual/concepts:cross-development toolchain generation`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001087 section. For information on advantages gained when building a
1088 cross-development toolchain using the do_populate_sdk task, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001089 ":ref:`sdk-manual/appendix-obtain:building an sdk installer`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001090 the Yocto Project Application Development and the Extensible Software
1091 Development Kit (eSDK) manual.
1092
1093Like image generation, the SDK script process consists of several stages
1094and depends on many variables. The
1095:ref:`ref-tasks-populate_sdk`
1096and
1097:ref:`ref-tasks-populate_sdk_ext`
1098tasks use these key variables to help create the list of packages to
1099actually install. For information on the variables listed in the figure,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001100see the ":ref:`overview-manual/concepts:application development sdk`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001101section.
1102
1103The ``do_populate_sdk`` task helps create the standard SDK and handles
1104two parts: a target part and a host part. The target part is the part
1105built for the target hardware and includes libraries and headers. The
1106host part is the part of the SDK that runs on the
1107:term:`SDKMACHINE`.
1108
1109The ``do_populate_sdk_ext`` task helps create the extensible SDK and
1110handles host and target parts differently than its counter part does for
1111the standard SDK. For the extensible SDK, the task encapsulates the
1112build system, which includes everything needed (host and target) for the
1113SDK.
1114
1115Regardless of the type of SDK being constructed, the tasks perform some
1116cleanup after which a cross-development environment setup script and any
1117needed configuration files are created. The final output is the
1118Cross-development toolchain installation script (``.sh`` file), which
1119includes the environment setup script.
1120
1121Stamp Files and the Rerunning of Tasks
1122~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1123
1124For each task that completes successfully, BitBake writes a stamp file
1125into the :term:`STAMPS_DIR`
1126directory. The beginning of the stamp file's filename is determined by
1127the :term:`STAMP` variable, and the end
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001128of the name consists of the task's name and current :ref:`input
1129checksum <overview-manual/concepts:checksums (signatures)>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001130
1131.. note::
1132
1133 This naming scheme assumes that
1134 BB_SIGNATURE_HANDLER
1135 is "OEBasicHash", which is almost always the case in current
1136 OpenEmbedded.
1137
1138To determine if a task needs to be rerun, BitBake checks if a stamp file
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001139with a matching input checksum exists for the task. In this case,
1140the task's output is assumed to exist and still be valid. Otherwise,
1141the task is rerun.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001142
1143.. note::
1144
1145 The stamp mechanism is more general than the shared state (sstate)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001146 cache mechanism described in the
1147 ":ref:`overview-manual/concepts:setscene tasks and shared state`" section.
1148 BitBake avoids rerunning any task that has a valid stamp file, not just
1149 tasks that can be accelerated through the sstate cache.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001150
1151 However, you should realize that stamp files only serve as a marker
1152 that some work has been done and that these files do not record task
1153 output. The actual task output would usually be somewhere in
1154 :term:`TMPDIR` (e.g. in some
1155 recipe's :term:`WORKDIR`.) What
1156 the sstate cache mechanism adds is a way to cache task output that
1157 can then be shared between build machines.
1158
Andrew Geissler09036742021-06-25 14:25:14 -05001159Since :term:`STAMPS_DIR` is usually a subdirectory of :term:`TMPDIR`, removing
1160:term:`TMPDIR` will also remove :term:`STAMPS_DIR`, which means tasks will
1161properly be rerun to repopulate :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001162
1163If you want some task to always be considered "out of date", you can
1164mark it with the :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`
1165varflag. If some other task depends on such a task, then that task will
1166also always be considered out of date, which might not be what you want.
1167
1168For details on how to view information about a task's signature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001169":ref:`dev-manual/common-tasks:viewing task variable dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001170section in the Yocto Project Development Tasks Manual.
1171
1172Setscene Tasks and Shared State
1173~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1174
1175The description of tasks so far assumes that BitBake needs to build
1176everything and no available prebuilt objects exist. BitBake does support
1177skipping tasks if prebuilt objects are available. These objects are
1178usually made available in the form of a shared state (sstate) cache.
1179
1180.. note::
1181
1182 For information on variables affecting sstate, see the
1183 :term:`SSTATE_DIR`
1184 and
1185 :term:`SSTATE_MIRRORS`
1186 variables.
1187
Andrew Geisslereff27472021-10-29 15:35:00 -05001188The idea of a setscene task (i.e ``do_taskname_setscene``) is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001189version of the task where instead of building something, BitBake can
1190skip to the end result and simply place a set of files into specific
1191locations as needed. In some cases, it makes sense to have a setscene
1192task variant (e.g. generating package files in the
1193:ref:`do_package_write_* <ref-tasks-package_write_deb>`
1194task). In other cases, it does not make sense (e.g. a
1195:ref:`ref-tasks-patch` task or a
1196:ref:`ref-tasks-unpack` task) since
1197the work involved would be equal to or greater than the underlying task.
1198
1199In the build system, the common tasks that have setscene variants are
1200:ref:`ref-tasks-package`,
1201``do_package_write_*``,
1202:ref:`ref-tasks-deploy`,
1203:ref:`ref-tasks-packagedata`, and
1204:ref:`ref-tasks-populate_sysroot`.
1205Notice that these tasks represent most of the tasks whose output is an
1206end result.
1207
1208The build system has knowledge of the relationship between these tasks
1209and other preceding tasks. For example, if BitBake runs
1210``do_populate_sysroot_setscene`` for something, it does not make sense
1211to run any of the ``do_fetch``, ``do_unpack``, ``do_patch``,
1212``do_configure``, ``do_compile``, and ``do_install`` tasks. However, if
1213``do_package`` needs to be run, BitBake needs to run those other tasks.
1214
1215It becomes more complicated if everything can come from an sstate cache
1216because some objects are simply not required at all. For example, you do
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001217not need a compiler or native tools, such as quilt, if there isn't anything
1218to compile or patch. If the ``do_package_write_*`` packages are available
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001219from sstate, BitBake does not need the ``do_package`` task data.
1220
1221To handle all these complexities, BitBake runs in two phases. The first
1222is the "setscene" stage. During this stage, BitBake first checks the
1223sstate cache for any targets it is planning to build. BitBake does a
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001224fast check to see if the object exists rather than doing a complete download.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001225If nothing exists, the second phase, which is the setscene stage,
1226completes and the main build proceeds.
1227
1228If objects are found in the sstate cache, the build system works
1229backwards from the end targets specified by the user. For example, if an
1230image is being built, the build system first looks for the packages
1231needed for that image and the tools needed to construct an image. If
1232those are available, the compiler is not needed. Thus, the compiler is
1233not even downloaded. If something was found to be unavailable, or the
1234download or setscene task fails, the build system then tries to install
1235dependencies, such as the compiler, from the cache.
1236
1237The availability of objects in the sstate cache is handled by the
Patrick Williams213cb262021-08-07 19:21:33 -05001238function specified by the :term:`BB_HASHCHECK_FUNCTION`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001239variable and returns a list of available objects. The function specified
Patrick Williams213cb262021-08-07 19:21:33 -05001240by the :term:`BB_SETSCENE_DEPVALID`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001241variable is the function that determines whether a given dependency
1242needs to be followed, and whether for any given relationship the
1243function needs to be passed. The function returns a True or False value.
1244
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001245Images
1246------
1247
1248The images produced by the build system are compressed forms of the root
1249filesystem and are ready to boot on a target device. You can see from
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001250the :ref:`general workflow figure
1251<overview-manual/concepts:openembedded build system concepts>` that BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001252output, in part, consists of images. This section takes a closer look at
1253this output:
1254
1255.. image:: figures/images.png
1256 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05001257 :width: 75%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001258
1259.. note::
1260
1261 For a list of example images that the Yocto Project provides, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001262 ":doc:`/ref-manual/images`" chapter in the Yocto Project Reference
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001263 Manual.
1264
1265The build process writes images out to the :term:`Build Directory`
1266inside the
1267``tmp/deploy/images/machine/`` folder as shown in the figure. This
1268folder contains any files expected to be loaded on the target device.
1269The :term:`DEPLOY_DIR` variable
1270points to the ``deploy`` directory, while the
1271:term:`DEPLOY_DIR_IMAGE`
1272variable points to the appropriate directory containing images for the
1273current configuration.
1274
1275- kernel-image: A kernel binary file. The
1276 :term:`KERNEL_IMAGETYPE`
1277 variable determines the naming scheme for the kernel image file.
1278 Depending on this variable, the file could begin with a variety of
1279 naming strings. The ``deploy/images/``\ machine directory can contain
1280 multiple image files for the machine.
1281
1282- root-filesystem-image: Root filesystems for the target device (e.g.
1283 ``*.ext3`` or ``*.bz2`` files). The
1284 :term:`IMAGE_FSTYPES`
1285 variable determines the root filesystem image type. The
1286 ``deploy/images/``\ machine directory can contain multiple root
1287 filesystems for the machine.
1288
1289- kernel-modules: Tarballs that contain all the modules built for the
1290 kernel. Kernel module tarballs exist for legacy purposes and can be
1291 suppressed by setting the
1292 :term:`MODULE_TARBALL_DEPLOY`
1293 variable to "0". The ``deploy/images/``\ machine directory can
1294 contain multiple kernel module tarballs for the machine.
1295
1296- bootloaders: If applicable to the target machine, bootloaders
1297 supporting the image. The ``deploy/images/``\ machine directory can
1298 contain multiple bootloaders for the machine.
1299
1300- symlinks: The ``deploy/images/``\ machine folder contains a symbolic
1301 link that points to the most recently built file for each machine.
1302 These links might be useful for external scripts that need to obtain
1303 the latest version of each file.
1304
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001305Application Development SDK
1306---------------------------
1307
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001308In the :ref:`general workflow figure
1309<overview-manual/concepts:openembedded build system concepts>`, the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001310output labeled "Application Development SDK" represents an SDK. The SDK
1311generation process differs depending on whether you build an extensible
1312SDK (e.g. ``bitbake -c populate_sdk_ext`` imagename) or a standard SDK
1313(e.g. ``bitbake -c populate_sdk`` imagename). This section takes a
1314closer look at this output:
1315
1316.. image:: figures/sdk.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05001317 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001318
1319The specific form of this output is a set of files that includes a
1320self-extracting SDK installer (``*.sh``), host and target manifest
1321files, and files used for SDK testing. When the SDK installer file is
1322run, it installs the SDK. The SDK consists of a cross-development
1323toolchain, a set of libraries and headers, and an SDK environment setup
1324script. Running this installer essentially sets up your
1325cross-development environment. You can think of the cross-toolchain as
1326the "host" part because it runs on the SDK machine. You can think of the
1327libraries and headers as the "target" part because they are built for
1328the target hardware. The environment setup script is added so that you
1329can initialize the environment before using the tools.
1330
1331.. note::
1332
1333 - The Yocto Project supports several methods by which you can set up
1334 this cross-development environment. These methods include
1335 downloading pre-built SDK installers or building and installing
1336 your own SDK installer.
1337
1338 - For background information on cross-development toolchains in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001339 Yocto Project development environment, see the
1340 ":ref:`overview-manual/concepts:cross-development toolchain generation`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001341 section.
1342
1343 - For information on setting up a cross-development environment, see
Andrew Geissler09209ee2020-12-13 08:44:15 -06001344 the :doc:`/sdk-manual/index` manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001345
1346All the output files for an SDK are written to the ``deploy/sdk`` folder
1347inside the :term:`Build Directory` as
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001348shown in the previous figure. Depending on the type of SDK, there are
1349several variables to configure these files. Here are the variables
1350associated with an extensible SDK:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001351
1352- :term:`DEPLOY_DIR`: Points to
1353 the ``deploy`` directory.
1354
1355- :term:`SDK_EXT_TYPE`:
1356 Controls whether or not shared state artifacts are copied into the
1357 extensible SDK. By default, all required shared state artifacts are
1358 copied into the SDK.
1359
1360- :term:`SDK_INCLUDE_PKGDATA`:
1361 Specifies whether or not packagedata is included in the extensible
1362 SDK for all recipes in the "world" target.
1363
1364- :term:`SDK_INCLUDE_TOOLCHAIN`:
1365 Specifies whether or not the toolchain is included when building the
1366 extensible SDK.
1367
Andrew Geissler9aee5002022-03-30 16:27:02 +00001368- :term:`ESDK_LOCALCONF_ALLOW`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001369 A list of variables allowed through from the build system
1370 configuration into the extensible SDK configuration.
1371
Andrew Geissler9aee5002022-03-30 16:27:02 +00001372- :term:`ESDK_LOCALCONF_REMOVE`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001373 A list of variables not allowed through from the build system
1374 configuration into the extensible SDK configuration.
1375
Andrew Geissler9aee5002022-03-30 16:27:02 +00001376- :term:`ESDK_CLASS_INHERIT_DISABLE`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001377 A list of classes to remove from the
1378 :term:`INHERIT` value globally
1379 within the extensible SDK configuration.
1380
1381This next list, shows the variables associated with a standard SDK:
1382
1383- :term:`DEPLOY_DIR`: Points to
1384 the ``deploy`` directory.
1385
1386- :term:`SDKMACHINE`: Specifies
1387 the architecture of the machine on which the cross-development tools
1388 are run to create packages for the target hardware.
1389
1390- :term:`SDKIMAGE_FEATURES`:
1391 Lists the features to include in the "target" part of the SDK.
1392
1393- :term:`TOOLCHAIN_HOST_TASK`:
1394 Lists packages that make up the host part of the SDK (i.e. the part
Andrew Geissler09036742021-06-25 14:25:14 -05001395 that runs on the :term:`SDKMACHINE`). When you use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001396 ``bitbake -c populate_sdk imagename`` to create the SDK, a set of
1397 default packages apply. This variable allows you to add more
1398 packages.
1399
1400- :term:`TOOLCHAIN_TARGET_TASK`:
1401 Lists packages that make up the target part of the SDK (i.e. the part
1402 built for the target hardware).
1403
1404- :term:`SDKPATH`: Defines the
1405 default SDK installation path offered by the installation script.
1406
1407- :term:`SDK_HOST_MANIFEST`:
1408 Lists all the installed packages that make up the host part of the
1409 SDK. This variable also plays a minor role for extensible SDK
1410 development as well. However, it is mainly used for the standard SDK.
1411
1412- :term:`SDK_TARGET_MANIFEST`:
1413 Lists all the installed packages that make up the target part of the
1414 SDK. This variable also plays a minor role for extensible SDK
1415 development as well. However, it is mainly used for the standard SDK.
1416
1417Cross-Development Toolchain Generation
1418======================================
1419
1420The Yocto Project does most of the work for you when it comes to
Andrew Geissler09209ee2020-12-13 08:44:15 -06001421creating :ref:`sdk-manual/intro:the cross-development toolchain`. This
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001422section provides some technical background on how cross-development
1423toolchains are created and used. For more information on toolchains, you
Andrew Geissler09209ee2020-12-13 08:44:15 -06001424can also see the :doc:`/sdk-manual/index` manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001425
1426In the Yocto Project development environment, cross-development
1427toolchains are used to build images and applications that run on the
1428target hardware. With just a few commands, the OpenEmbedded build system
1429creates these necessary toolchains for you.
1430
1431The following figure shows a high-level build environment regarding
1432toolchain construction and use.
1433
1434.. image:: figures/cross-development-toolchains.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05001435 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001436
1437Most of the work occurs on the Build Host. This is the machine used to
1438build images and generally work within the the Yocto Project
1439environment. When you run
1440:term:`BitBake` to create an image, the
1441OpenEmbedded build system uses the host ``gcc`` compiler to bootstrap a
1442cross-compiler named ``gcc-cross``. The ``gcc-cross`` compiler is what
1443BitBake uses to compile source files when creating the target image. You
1444can think of ``gcc-cross`` simply as an automatically generated
1445cross-compiler that is used internally within BitBake only.
1446
1447.. note::
1448
Andrew Geissler09036742021-06-25 14:25:14 -05001449 The extensible SDK does not use ``gcc-cross-canadian``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001450 since this SDK ships a copy of the OpenEmbedded build system and the
Andrew Geissler09036742021-06-25 14:25:14 -05001451 sysroot within it contains ``gcc-cross``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001452
Andrew Geisslerc926e172021-05-07 16:11:35 -05001453The chain of events that occurs when the standard toolchain is bootstrapped::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001454
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001455 binutils-cross -> linux-libc-headers -> gcc-cross -> libgcc-initial -> glibc -> libgcc -> gcc-runtime
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001456
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001457- ``gcc``: The compiler, GNU Compiler Collection (GCC).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001458
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001459- ``binutils-cross``: The binary utilities needed in order
1460 to run the ``gcc-cross`` phase of the bootstrap operation and build the
1461 headers for the C library.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001462
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001463- ``linux-libc-headers``: Headers needed for the cross-compiler and C library build.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001464
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001465- ``libgcc-initial``: An initial version of the gcc support library needed
1466 to bootstrap ``glibc``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001467
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001468- ``libgcc``: The final version of the gcc support library which
1469 can only be built once there is a C library to link against.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001470
1471- ``glibc``: The GNU C Library.
1472
1473- ``gcc-cross``: The final stage of the bootstrap process for the
1474 cross-compiler. This stage results in the actual cross-compiler that
1475 BitBake uses when it builds an image for a targeted device.
1476
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001477 This tool is a "native" tool (i.e. it is designed to run on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001478 the build host).
1479
1480- ``gcc-runtime``: Runtime libraries resulting from the toolchain
1481 bootstrapping process. This tool produces a binary that consists of
1482 the runtime libraries need for the targeted device.
1483
1484You can use the OpenEmbedded build system to build an installer for the
1485relocatable SDK used to develop applications. When you run the
1486installer, it installs the toolchain, which contains the development
1487tools (e.g., ``gcc-cross-canadian``, ``binutils-cross-canadian``, and
1488other ``nativesdk-*`` tools), which are tools native to the SDK (i.e.
1489native to :term:`SDK_ARCH`), you
1490need to cross-compile and test your software. The figure shows the
1491commands you use to easily build out this toolchain. This
1492cross-development toolchain is built to execute on the
1493:term:`SDKMACHINE`, which might or
1494might not be the same machine as the Build Host.
1495
1496.. note::
1497
1498 If your target architecture is supported by the Yocto Project, you
1499 can take advantage of pre-built images that ship with the Yocto
1500 Project and already contain cross-development toolchain installers.
1501
Andrew Geisslerc926e172021-05-07 16:11:35 -05001502Here is the bootstrap process for the relocatable toolchain::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001503
1504 gcc -> binutils-crosssdk -> gcc-crosssdk-initial -> linux-libc-headers -> glibc-initial -> nativesdk-glibc -> gcc-crosssdk -> gcc-cross-canadian
1505
1506- ``gcc``: The build host's GNU Compiler Collection (GCC).
1507
1508- ``binutils-crosssdk``: The bare minimum binary utilities needed in
1509 order to run the ``gcc-crosssdk-initial`` phase of the bootstrap
1510 operation.
1511
1512- ``gcc-crosssdk-initial``: An early stage of the bootstrap process for
1513 creating the cross-compiler. This stage builds enough of the
1514 ``gcc-crosssdk`` and supporting pieces so that the final stage of the
1515 bootstrap process can produce the finished cross-compiler. This tool
1516 is a "native" binary that runs on the build host.
1517
1518- ``linux-libc-headers``: Headers needed for the cross-compiler.
1519
1520- ``glibc-initial``: An initial version of the Embedded GLIBC needed to
1521 bootstrap ``nativesdk-glibc``.
1522
1523- ``nativesdk-glibc``: The Embedded GLIBC needed to bootstrap the
1524 ``gcc-crosssdk``.
1525
1526- ``gcc-crosssdk``: The final stage of the bootstrap process for the
1527 relocatable cross-compiler. The ``gcc-crosssdk`` is a transitory
1528 compiler and never leaves the build host. Its purpose is to help in
1529 the bootstrap process to create the eventual ``gcc-cross-canadian``
1530 compiler, which is relocatable. This tool is also a "native" package
1531 (i.e. it is designed to run on the build host).
1532
1533- ``gcc-cross-canadian``: The final relocatable cross-compiler. When
1534 run on the :term:`SDKMACHINE`,
1535 this tool produces executable code that runs on the target device.
1536 Only one cross-canadian compiler is produced per architecture since
1537 they can be targeted at different processor optimizations using
1538 configurations passed to the compiler through the compile commands.
1539 This circumvents the need for multiple compilers and thus reduces the
1540 size of the toolchains.
1541
1542.. note::
1543
1544 For information on advantages gained when building a
1545 cross-development toolchain installer, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001546 ":ref:`sdk-manual/appendix-obtain:building an sdk installer`" appendix
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001547 in the Yocto Project Application Development and the
1548 Extensible Software Development Kit (eSDK) manual.
1549
1550Shared State Cache
1551==================
1552
1553By design, the OpenEmbedded build system builds everything from scratch
1554unless :term:`BitBake` can determine
1555that parts do not need to be rebuilt. Fundamentally, building from
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001556scratch is attractive as it means all parts are built fresh and there is
1557no possibility of stale data that can cause problems. When
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001558developers hit problems, they typically default back to building from
Andrew Geissler595f6302022-01-24 19:11:47 +00001559scratch so they have a known state from the start.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001560
1561Building an image from scratch is both an advantage and a disadvantage
1562to the process. As mentioned in the previous paragraph, building from
1563scratch ensures that everything is current and starts from a known
1564state. However, building from scratch also takes much longer as it
1565generally means rebuilding things that do not necessarily need to be
1566rebuilt.
1567
1568The Yocto Project implements shared state code that supports incremental
1569builds. The implementation of the shared state code answers the
1570following questions that were fundamental roadblocks within the
1571OpenEmbedded incremental build support system:
1572
1573- What pieces of the system have changed and what pieces have not
1574 changed?
1575
1576- How are changed pieces of software removed and replaced?
1577
1578- How are pre-built components that do not need to be rebuilt from
1579 scratch used when they are available?
1580
1581For the first question, the build system detects changes in the "inputs"
1582to a given task by creating a checksum (or signature) of the task's
1583inputs. If the checksum changes, the system assumes the inputs have
1584changed and the task needs to be rerun. For the second question, the
1585shared state (sstate) code tracks which tasks add which output to the
1586build process. This means the output from a given task can be removed,
1587upgraded or otherwise manipulated. The third question is partly
1588addressed by the solution for the second question assuming the build
1589system can fetch the sstate objects from remote locations and install
1590them if they are deemed to be valid.
1591
1592.. note::
1593
1594 - The build system does not maintain
1595 :term:`PR` information as part of
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001596 the shared state packages. Consequently, there are considerations that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001597 affect maintaining shared state feeds. For information on how the
Andrew Geissler09036742021-06-25 14:25:14 -05001598 build system works with packages and can track incrementing :term:`PR`
Andrew Geissler09209ee2020-12-13 08:44:15 -06001599 information, see the ":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001600 section in the Yocto Project Development Tasks Manual.
1601
1602 - The code in the build system that supports incremental builds is
Andrew Geisslereff27472021-10-29 15:35:00 -05001603 complex. For techniques that help you work around issues
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001604 related to shared state code, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001605 ":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 -05001606 and
Andrew Geissler09209ee2020-12-13 08:44:15 -06001607 ":ref:`dev-manual/common-tasks:invalidating shared state to force a task to run`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001608 sections both in the Yocto Project Development Tasks Manual.
1609
1610The rest of this section goes into detail about the overall incremental
1611build architecture, the checksums (signatures), and shared state.
1612
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001613Overall Architecture
1614--------------------
1615
1616When determining what parts of the system need to be built, BitBake
1617works on a per-task basis rather than a per-recipe basis. You might
1618wonder why using a per-task basis is preferred over a per-recipe basis.
1619To help explain, consider having the IPK packaging backend enabled and
1620then switching to DEB. In this case, the
1621:ref:`ref-tasks-install` and
1622:ref:`ref-tasks-package` task outputs
1623are still valid. However, with a per-recipe approach, the build would
1624not include the ``.deb`` files. Consequently, you would have to
1625invalidate the whole build and rerun it. Rerunning everything is not the
1626best solution. Also, in this case, the core must be "taught" much about
1627specific tasks. This methodology does not scale well and does not allow
1628users to easily add new tasks in layers or as external recipes without
1629touching the packaged-staging core.
1630
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001631Checksums (Signatures)
1632----------------------
1633
1634The shared state code uses a checksum, which is a unique signature of a
1635task's inputs, to determine if a task needs to be run again. Because it
1636is a change in a task's inputs that triggers a rerun, the process needs
1637to detect all the inputs to a given task. For shell tasks, this turns
1638out to be fairly easy because the build process generates a "run" shell
1639script for each task and it is possible to create a checksum that gives
1640you a good idea of when the task's data changes.
1641
1642To complicate the problem, there are things that should not be included
1643in the checksum. First, there is the actual specific build path of a
Andrew Geissler615f2f12022-07-15 14:00:58 -05001644given task --- the :term:`WORKDIR`. It
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001645does not matter if the work directory changes because it should not
1646affect the output for target packages. Also, the build process has the
1647objective of making native or cross packages relocatable.
1648
1649.. note::
1650
1651 Both native and cross packages run on the
1652 build host. However, cross packages generate output for the target
1653 architecture.
1654
Andrew Geissler09036742021-06-25 14:25:14 -05001655The checksum therefore needs to exclude :term:`WORKDIR`. The simplistic
1656approach for excluding the work directory is to set :term:`WORKDIR` to some
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001657fixed value and create the checksum for the "run" script.
1658
1659Another problem results from the "run" scripts containing functions that
1660might or might not get called. The incremental build solution contains
1661code that figures out dependencies between shell functions. This code is
1662used to prune the "run" scripts down to the minimum set, thereby
1663alleviating this problem and making the "run" scripts much more readable
1664as a bonus.
1665
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001666So far, there are solutions for shell scripts. What about Python tasks? The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001667same approach applies even though these tasks are more difficult. The
1668process needs to figure out what variables a Python function accesses
1669and what functions it calls. Again, the incremental build solution
1670contains code that first figures out the variable and function
1671dependencies, and then creates a checksum for the data used as the input
1672to the task.
1673
Andrew Geissler09036742021-06-25 14:25:14 -05001674Like the :term:`WORKDIR` case, there can be situations where dependencies should be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001675ignored. For these situations, you can instruct the build process to
Andrew Geisslerc926e172021-05-07 16:11:35 -05001676ignore a dependency by using a line like the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001677
1678 PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
1679
1680This example ensures that the :term:`PACKAGE_ARCHS` variable
1681does not depend on the value of :term:`MACHINE`, even if it does
1682reference it.
1683
1684Equally, there are cases where you need to add dependencies BitBake is
1685not able to find. You can accomplish this by using a line like the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001686following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001687
1688 PACKAGE_ARCHS[vardeps] = "MACHINE"
1689
1690This example explicitly
Andrew Geissler09036742021-06-25 14:25:14 -05001691adds the :term:`MACHINE` variable as a dependency for :term:`PACKAGE_ARCHS`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001692
1693As an example, consider a case with in-line Python where BitBake is not
1694able to figure out dependencies. When running in debug mode (i.e. using
1695``-DDD``), BitBake produces output when it discovers something for which
1696it cannot figure out dependencies. The Yocto Project team has currently
1697not managed to cover those dependencies in detail and is aware of the
1698need to fix this situation.
1699
1700Thus far, this section has limited discussion to the direct inputs into
1701a task. Information based on direct inputs is referred to as the
1702"basehash" in the code. However, the question of a task's indirect
Andrew Geissler615f2f12022-07-15 14:00:58 -05001703inputs still exits --- items already built and present in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001704:term:`Build Directory`. The checksum (or
1705signature) for a particular task needs to add the hashes of all the
1706tasks on which the particular task depends. Choosing which dependencies
Andrew Geissler595f6302022-01-24 19:11:47 +00001707to add is a policy decision. However, the effect is to generate a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001708checksum that combines the basehash and the hashes of the task's
1709dependencies.
1710
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001711At the code level, there are multiple ways by which both the basehash
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001712and the dependent task hashes can be influenced. Within the BitBake
1713configuration file, you can give BitBake some extra information to help
1714it construct the basehash. The following statement effectively results
1715in a list of global variable dependency excludes (i.e. variables never
Andrew Geisslerc926e172021-05-07 16:11:35 -05001716included in any checksum)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001717
Andrew Geissler9aee5002022-03-30 16:27:02 +00001718 BB_BASEHASH_IGNORE_VARS ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001719 SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \\
1720 USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \\
1721 PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \\
1722 CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
1723
Andrew Geissler595f6302022-01-24 19:11:47 +00001724The previous example does not include :term:`WORKDIR` since that variable is
1725actually constructed as a path within :term:`TMPDIR`, which is included above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001726
1727The rules for deciding which hashes of dependent tasks to include
1728through dependency chains are more complex and are generally
1729accomplished with a Python function. The code in
1730``meta/lib/oe/sstatesig.py`` shows two examples of this and also
1731illustrates how you can insert your own policy into the system if so
1732desired. This file defines the two basic signature generators
1733:term:`OpenEmbedded-Core (OE-Core)` uses: "OEBasic" and
1734"OEBasicHash". By default, a dummy "noop" signature handler is enabled
1735in BitBake. This means that behavior is unchanged from previous
1736versions. OE-Core uses the "OEBasicHash" signature handler by default
Andrew Geisslerc926e172021-05-07 16:11:35 -05001737through this setting in the ``bitbake.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001738
1739 BB_SIGNATURE_HANDLER ?= "OEBasicHash"
1740
Andrew Geissler09036742021-06-25 14:25:14 -05001741The "OEBasicHash" :term:`BB_SIGNATURE_HANDLER` is the same
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001742as the "OEBasic" version but adds the task hash to the :ref:`stamp
1743files <overview-manual/concepts:stamp files and the rerunning of tasks>`. This
1744results in any metadata change that changes the task hash, automatically causing
1745the task to be run again. This removes the need to bump
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001746:term:`PR` values, and changes to metadata
1747automatically ripple across the build.
1748
1749It is also worth noting that the end result of these signature
1750generators is to make some dependency and hash information available to
1751the build. This information includes:
1752
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001753- ``BB_BASEHASH:task-``\ taskname: The base hashes for each task in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001754 recipe.
1755
1756- ``BB_BASEHASH_``\ filename\ ``:``\ taskname: The base hashes for each
1757 dependent task.
1758
Andrew Geissler09036742021-06-25 14:25:14 -05001759- :term:`BB_TASKHASH`: The hash of the currently running task.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001760
1761Shared State
1762------------
1763
1764Checksums and dependencies, as discussed in the previous section, solve
1765half the problem of supporting a shared state. The other half of the
1766problem is being able to use checksum information during the build and
1767being able to reuse or rebuild specific components.
1768
1769The :ref:`sstate <ref-classes-sstate>` class is a
1770relatively generic implementation of how to "capture" a snapshot of a
1771given task. The idea is that the build process does not care about the
1772source of a task's output. Output could be freshly built or it could be
1773downloaded and unpacked from somewhere. In other words, the build
1774process does not need to worry about its origin.
1775
1776Two types of output exist. One type is just about creating a directory
1777in :term:`WORKDIR`. A good example is
1778the output of either
1779:ref:`ref-tasks-install` or
1780:ref:`ref-tasks-package`. The other
1781type of output occurs when a set of data is merged into a shared
1782directory tree such as the sysroot.
1783
1784The Yocto Project team has tried to keep the details of the
Andrew Geissler595f6302022-01-24 19:11:47 +00001785implementation hidden in the :ref:`sstate <ref-classes-sstate>` class. From a user's perspective,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001786adding shared state wrapping to a task is as simple as this
1787:ref:`ref-tasks-deploy` example taken
Andrew Geisslerc926e172021-05-07 16:11:35 -05001788from the :ref:`deploy <ref-classes-deploy>` class::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001789
1790 DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
1791 SSTATETASKS += "do_deploy"
1792 do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
1793 do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
1794
1795 python do_deploy_setscene () {
1796 sstate_setscene(d)
1797 }
1798 addtask do_deploy_setscene
1799 do_deploy[dirs] = "${DEPLOYDIR} ${B}"
1800 do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"
1801
1802The following list explains the previous example:
1803
1804- Adding "do_deploy" to ``SSTATETASKS`` adds some required
1805 sstate-related processing, which is implemented in the
1806 :ref:`sstate <ref-classes-sstate>` class, to
1807 before and after the
1808 :ref:`ref-tasks-deploy` task.
1809
1810- The ``do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"`` declares that
1811 ``do_deploy`` places its output in ``${DEPLOYDIR}`` when run normally
1812 (i.e. when not using the sstate cache). This output becomes the input
1813 to the shared state cache.
1814
1815- The ``do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"`` line
1816 causes the contents of the shared state cache to be copied to
1817 ``${DEPLOY_DIR_IMAGE}``.
1818
1819 .. note::
1820
1821 If ``do_deploy`` is not already in the shared state cache or if its input
1822 checksum (signature) has changed from when the output was cached, the task
1823 runs to populate the shared state cache, after which the contents of the
1824 shared state cache is copied to ${:term:`DEPLOY_DIR_IMAGE`}. If
1825 ``do_deploy`` is in the shared state cache and its signature indicates
1826 that the cached output is still valid (i.e. if no relevant task inputs
1827 have changed), then the contents of the shared state cache copies
Andrew Geissler09036742021-06-25 14:25:14 -05001828 directly to ${:term:`DEPLOY_DIR_IMAGE`} by the ``do_deploy_setscene`` task
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001829 instead, skipping the ``do_deploy`` task.
1830
1831- The following task definition is glue logic needed to make the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001832 previous settings effective::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001833
1834 python do_deploy_setscene () {
1835 sstate_setscene(d)
1836 }
1837 addtask do_deploy_setscene
1838
1839 ``sstate_setscene()`` takes the flags above as input and accelerates the ``do_deploy`` task
1840 through the shared state cache if possible. If the task was
1841 accelerated, ``sstate_setscene()`` returns True. Otherwise, it
1842 returns False, and the normal ``do_deploy`` task runs. For more
Patrick Williams213cb262021-08-07 19:21:33 -05001843 information, see the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:setscene`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001844 section in the BitBake User Manual.
1845
1846- The ``do_deploy[dirs] = "${DEPLOYDIR} ${B}"`` line creates
1847 ``${DEPLOYDIR}`` and ``${B}`` before the ``do_deploy`` task runs, and
1848 also sets the current working directory of ``do_deploy`` to ``${B}``.
1849 For more information, see the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`"
1850 section in the BitBake
1851 User Manual.
1852
1853 .. note::
1854
1855 In cases where ``sstate-inputdirs`` and ``sstate-outputdirs`` would be
1856 the same, you can use ``sstate-plaindirs``. For example, to preserve the
1857 ${:term:`PKGD`} and ${:term:`PKGDEST`} output from the ``do_package``
Andrew Geisslerc926e172021-05-07 16:11:35 -05001858 task, use the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001859
1860 do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
1861
1862
1863- The ``do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"`` line appends
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001864 extra metadata to the :ref:`stamp
1865 file <overview-manual/concepts:stamp files and the rerunning of tasks>`. In
1866 this case, the metadata makes the task specific to a machine's architecture.
1867 See
Andrew Geissler09209ee2020-12-13 08:44:15 -06001868 ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:the task list`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001869 section in the BitBake User Manual for more information on the
1870 ``stamp-extra-info`` flag.
1871
1872- ``sstate-inputdirs`` and ``sstate-outputdirs`` can also be used with
1873 multiple directories. For example, the following declares
Andrew Geissler09036742021-06-25 14:25:14 -05001874 :term:`PKGDESTWORK` and ``SHLIBWORK`` as shared state input directories,
1875 which populates the shared state cache, and :term:`PKGDATA_DIR` and
Andrew Geisslerc926e172021-05-07 16:11:35 -05001876 ``SHLIBSDIR`` as the corresponding shared state output directories::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001877
1878 do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
1879 do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
1880
1881- These methods also include the ability to take a lockfile when
1882 manipulating shared state directory structures, for cases where file
Andrew Geisslerc926e172021-05-07 16:11:35 -05001883 additions or removals are sensitive::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001884
1885 do_package[sstate-lockfile] = "${PACKAGELOCK}"
1886
1887Behind the scenes, the shared state code works by looking in
1888:term:`SSTATE_DIR` and
1889:term:`SSTATE_MIRRORS` for
Andrew Geisslerc926e172021-05-07 16:11:35 -05001890shared state files. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001891
1892 SSTATE_MIRRORS ?= "\
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001893 file://.* https://someserver.tld/share/sstate/PATH;downloadfilename=PATH \
Patrick Williams93c203f2021-10-06 16:15:23 -05001894 file://.* file:///some/local/dir/sstate/PATH"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001895
1896.. note::
1897
Andrew Geissler5f350902021-07-23 13:09:54 -04001898 The shared state directory (:term:`SSTATE_DIR`) is organized into two-character
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001899 subdirectories, where the subdirectory names are based on the first two
1900 characters of the hash.
1901 If the shared state directory structure for a mirror has the same structure
Andrew Geissler09036742021-06-25 14:25:14 -05001902 as :term:`SSTATE_DIR`, you must specify "PATH" as part of the URI to enable the build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001903 system to map to the appropriate subdirectory.
1904
1905The shared state package validity can be detected just by looking at the
1906filename since the filename contains the task checksum (or signature) as
1907described earlier in this section. If a valid shared state package is
1908found, the build process downloads it and uses it to accelerate the
1909task.
1910
1911The build processes use the ``*_setscene`` tasks for the task
1912acceleration phase. BitBake goes through this phase before the main
1913execution code and tries to accelerate any tasks for which it can find
1914shared state packages. If a shared state package for a task is
1915available, the shared state package is used. This means the task and any
1916tasks on which it is dependent are not executed.
1917
1918As a real world example, the aim is when building an IPK-based image,
1919only the
1920:ref:`ref-tasks-package_write_ipk`
1921tasks would have their shared state packages fetched and extracted.
1922Since the sysroot is not used, it would never get extracted. This is
1923another reason why a task-based approach is preferred over a
1924recipe-based approach, which would have to install the output from every
1925task.
1926
Andrew Geissler595f6302022-01-24 19:11:47 +00001927Hash Equivalence
1928----------------
1929
1930The above section explained how BitBake skips the execution of tasks
1931whose output can already be found in the Shared State cache.
1932
1933During a build, it may often be the case that the output / result of a task might
1934be unchanged despite changes in the task's input values. An example might be
1935whitespace changes in some input C code. In project terms, this is what we define
1936as "equivalence".
1937
1938To keep track of such equivalence, BitBake has to manage three hashes
1939for each task:
1940
1941- The *task hash* explained earlier: computed from the recipe metadata,
1942 the task code and the task hash values from its dependencies.
1943 When changes are made, these task hashes are therefore modified,
1944 causing the task to re-execute. The task hashes of tasks depending on this
1945 task are therefore modified too, causing the whole dependency
1946 chain to re-execute.
1947
1948- The *output hash*, a new hash computed from the output of Shared State tasks,
1949 tasks that save their resulting output to a Shared State tarball.
1950 The mapping between the task hash and its output hash is reported
1951 to a new *Hash Equivalence* server. This mapping is stored in a database
1952 by the server for future reference.
1953
1954- The *unihash*, a new hash, initially set to the task hash for the task.
1955 This is used to track the *unicity* of task output, and we will explain
1956 how its value is maintained.
1957
1958When Hash Equivalence is enabled, BitBake computes the task hash
1959for each task by using the unihash of its dependencies, instead
1960of their task hash.
1961
1962Now, imagine that a Shared State task is modified because of a change in
1963its code or metadata, or because of a change in its dependencies.
1964Since this modifies its task hash, this task will need re-executing.
1965Its output hash will therefore be computed again.
1966
1967Then, the new mapping between the new task hash and its output hash
1968will be reported to the Hash Equivalence server. The server will
1969let BitBake know whether this output hash is the same as a previously
1970reported output hash, for a different task hash.
1971
1972If the output hash is already known, BitBake will update the task's
1973unihash to match the original task hash that generated that output.
1974Thanks to this, the depending tasks will keep a previously recorded
1975task hash, and BitBake will be able to retrieve their output from
1976the Shared State cache, instead of re-executing them. Similarly, the
1977output of further downstream tasks can also be retrieved from Shared
1978Shate.
1979
1980If the output hash is unknown, a new entry will be created on the Hash
1981Equivalence server, matching the task hash to that output.
1982The depending tasks, still having a new task hash because of the
1983change, will need to re-execute as expected. The change propagates
1984to the depending tasks.
1985
1986To summarize, when Hash Equivalence is enabled, a change in one of the
1987tasks in BitBake's run queue doesn't have to propagate to all the
1988downstream tasks that depend on the output of this task, causing a
1989full rebuild of such tasks, and so on with the next depending tasks.
1990Instead, when the output of this task remains identical to previously
1991recorded output, BitBake can safely retrieve all the downstream
1992task output from the Shared State cache.
1993
1994.. note::
1995
1996 Having :doc:`/test-manual/reproducible-builds` is a key ingredient for
1997 the stability of the task's output hash. Therefore, the effectiveness
1998 of Hash Equivalence strongly depends on it.
1999
2000This applies to multiple scenarios:
2001
2002- A "trivial" change to a recipe that doesn't impact its generated output,
2003 such as whitespace changes, modifications to unused code paths or
2004 in the ordering of variables.
2005
2006- Shared library updates, for example to fix a security vulnerability.
2007 For sure, the programs using such a library should be rebuilt, but
2008 their new binaries should remain identical. The corresponding tasks should
2009 have a different output hash because of the change in the hash of their
2010 library dependency, but thanks to their output being identical, Hash
2011 Equivalence will stop the propagation down the dependency chain.
2012
2013- Native tool updates. Though the depending tasks should be rebuilt,
2014 it's likely that they will generate the same output and be marked
2015 as equivalent.
2016
2017This mechanism is enabled by default in Poky, and is controlled by three
2018variables:
2019
2020- :term:`bitbake:BB_HASHSERVE`, specifying a local or remote Hash
2021 Equivalence server to use.
2022
2023- :term:`BB_HASHSERVE_UPSTREAM`, when ``BB_HASHSERVE = "auto"``,
2024 allowing to connect the local server to an upstream one.
2025
2026- :term:`bitbake:BB_SIGNATURE_HANDLER`, which must be set to ``OEEquivHash``.
2027
2028Therefore, the default configuration in Poky corresponds to the
2029below settings::
2030
2031 BB_HASHSERVE = "auto"
2032 BB_SIGNATURE_HANDLER = "OEEquivHash"
2033
2034Rather than starting a local server, another possibility is to rely
2035on a Hash Equivalence server on a network, by setting::
2036
2037 BB_HASHSERVE = "<HOSTNAME>:<PORT>"
2038
2039.. note::
2040
2041 The shared Hash Equivalence server needs to be maintained together with the
2042 Shared State cache. Otherwise, the server could report Shared State hashes
2043 that only exist on specific clients.
2044
2045 We therefore recommend that one Hash Equivalence server be set up to
2046 correspond with a given Shared State cache, and to start this server
2047 in *read-only mode*, so that it doesn't store equivalences for
2048 Shared State caches that are local to clients.
2049
2050 See the :term:`BB_HASHSERVE` reference for details about starting
2051 a Hash Equivalence server.
2052
2053See the `video <https://www.youtube.com/watch?v=zXEdqGS62Wc>`__
2054of Joshua Watt's `Hash Equivalence and Reproducible Builds
2055<https://elinux.org/images/3/37/Hash_Equivalence_and_Reproducible_Builds.pdf>`__
2056presentation at ELC 2020 for a very synthetic introduction to the
2057Hash Equivalence implementation in the Yocto Project.
2058
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002059Automatically Added Runtime Dependencies
2060========================================
2061
2062The OpenEmbedded build system automatically adds common types of runtime
2063dependencies between packages, which means that you do not need to
2064explicitly declare the packages using
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002065:term:`RDEPENDS`. There are three automatic
2066mechanisms (``shlibdeps``, ``pcdeps``, and ``depchains``) that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002067handle shared libraries, package configuration (pkg-config) modules, and
2068``-dev`` and ``-dbg`` packages, respectively. For other types of runtime
2069dependencies, you must manually declare the dependencies.
2070
2071- ``shlibdeps``: During the
2072 :ref:`ref-tasks-package` task of
2073 each recipe, all shared libraries installed by the recipe are
2074 located. For each shared library, the package that contains the
2075 shared library is registered as providing the shared library. More
2076 specifically, the package is registered as providing the
2077 `soname <https://en.wikipedia.org/wiki/Soname>`__ of the library. The
2078 resulting shared-library-to-package mapping is saved globally in
2079 :term:`PKGDATA_DIR` by the
2080 :ref:`ref-tasks-packagedata`
2081 task.
2082
2083 Simultaneously, all executables and shared libraries installed by the
2084 recipe are inspected to see what shared libraries they link against.
Andrew Geissler09036742021-06-25 14:25:14 -05002085 For each shared library dependency that is found, :term:`PKGDATA_DIR` is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002086 queried to see if some package (likely from a different recipe)
2087 contains the shared library. If such a package is found, a runtime
2088 dependency is added from the package that depends on the shared
2089 library to the package that contains the library.
2090
2091 The automatically added runtime dependency also includes a version
2092 restriction. This version restriction specifies that at least the
2093 current version of the package that provides the shared library must
Andrew Geissler09036742021-06-25 14:25:14 -05002094 be used, as if "package (>= version)" had been added to :term:`RDEPENDS`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002095 This forces an upgrade of the package containing the shared library
2096 when installing the package that depends on the library, if needed.
2097
2098 If you want to avoid a package being registered as providing a
2099 particular shared library (e.g. because the library is for internal
2100 use only), then add the library to
2101 :term:`PRIVATE_LIBS` inside
2102 the package's recipe.
2103
2104- ``pcdeps``: During the ``do_package`` task of each recipe, all
2105 pkg-config modules (``*.pc`` files) installed by the recipe are
2106 located. For each module, the package that contains the module is
2107 registered as providing the module. The resulting module-to-package
Andrew Geissler09036742021-06-25 14:25:14 -05002108 mapping is saved globally in :term:`PKGDATA_DIR` by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002109 ``do_packagedata`` task.
2110
2111 Simultaneously, all pkg-config modules installed by the recipe are
2112 inspected to see what other pkg-config modules they depend on. A
2113 module is seen as depending on another module if it contains a
2114 "Requires:" line that specifies the other module. For each module
Andrew Geissler09036742021-06-25 14:25:14 -05002115 dependency, :term:`PKGDATA_DIR` is queried to see if some package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002116 contains the module. If such a package is found, a runtime dependency
2117 is added from the package that depends on the module to the package
2118 that contains the module.
2119
2120 .. note::
2121
2122 The
2123 pcdeps
2124 mechanism most often infers dependencies between
2125 -dev
2126 packages.
2127
2128- ``depchains``: If a package ``foo`` depends on a package ``bar``,
2129 then ``foo-dev`` and ``foo-dbg`` are also made to depend on
2130 ``bar-dev`` and ``bar-dbg``, respectively. Taking the ``-dev``
2131 packages as an example, the ``bar-dev`` package might provide headers
2132 and shared library symlinks needed by ``foo-dev``, which shows the
2133 need for a dependency between the packages.
2134
2135 The dependencies added by ``depchains`` are in the form of
2136 :term:`RRECOMMENDS`.
2137
2138 .. note::
2139
Andrew Geissler5f350902021-07-23 13:09:54 -04002140 By default, ``foo-dev`` also has an :term:`RDEPENDS`-style dependency on
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002141 ``foo``, because the default value of ``RDEPENDS:${PN}-dev`` (set in
Andrew Geisslerd5838332022-05-27 11:33:10 -05002142 ``bitbake.conf``) includes "${PN}".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002143
2144 To ensure that the dependency chain is never broken, ``-dev`` and
2145 ``-dbg`` packages are always generated by default, even if the
2146 packages turn out to be empty. See the
2147 :term:`ALLOW_EMPTY` variable
2148 for more information.
2149
2150The ``do_package`` task depends on the ``do_packagedata`` task of each
2151recipe in :term:`DEPENDS` through use
2152of a ``[``\ :ref:`deptask <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
2153declaration, which guarantees that the required
2154shared-library/module-to-package mapping information will be available
Andrew Geissler09036742021-06-25 14:25:14 -05002155when needed as long as :term:`DEPENDS` has been correctly set.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002156
2157Fakeroot and Pseudo
2158===================
2159
2160Some tasks are easier to implement when allowed to perform certain
2161operations that are normally reserved for the root user (e.g.
2162:ref:`ref-tasks-install`,
2163:ref:`do_package_write* <ref-tasks-package_write_deb>`,
2164:ref:`ref-tasks-rootfs`, and
2165:ref:`do_image* <ref-tasks-image>`). For example,
2166the ``do_install`` task benefits from being able to set the UID and GID
2167of installed files to arbitrary values.
2168
2169One approach to allowing tasks to perform root-only operations would be
2170to require :term:`BitBake` to run as
2171root. However, this method is cumbersome and has security issues. The
2172approach that is actually used is to run tasks that benefit from root
2173privileges in a "fake" root environment. Within this environment, the
2174task and its child processes believe that they are running as the root
2175user, and see an internally consistent view of the filesystem. As long
2176as generating the final output (e.g. a package or an image) does not
2177require root privileges, the fact that some earlier steps ran in a fake
2178root environment does not cause problems.
2179
2180The capability to run tasks in a fake root environment is known as
2181"`fakeroot <http://man.he.net/man1/fakeroot>`__", which is derived from
2182the BitBake keyword/variable flag that requests a fake root environment
2183for a task.
2184
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002185In the :term:`OpenEmbedded Build System`, the program that implements
2186fakeroot is known as :yocto_home:`Pseudo </software-item/pseudo/>`. Pseudo
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002187overrides system calls by using the environment variable ``LD_PRELOAD``,
2188which results in the illusion of running as root. To keep track of
2189"fake" file ownership and permissions resulting from operations that
2190require root permissions, Pseudo uses an SQLite 3 database. This
2191database is stored in
2192``${``\ :term:`WORKDIR`\ ``}/pseudo/files.db``
2193for individual recipes. Storing the database in a file as opposed to in
2194memory gives persistence between tasks and builds, which is not
2195accomplished using fakeroot.
2196
2197.. note::
2198
2199 If you add your own task that manipulates the same files or
2200 directories as a fakeroot task, then that task also needs to run
2201 under fakeroot. Otherwise, the task cannot run root-only operations,
2202 and cannot see the fake file ownership and permissions set by the
2203 other task. You need to also add a dependency on
Andrew Geisslerc926e172021-05-07 16:11:35 -05002204 ``virtual/fakeroot-native:do_populate_sysroot``, giving the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002205
2206 fakeroot do_mytask () {
2207 ...
2208 }
2209 do_mytask[depends] += "virtual/fakeroot-native:do_populate_sysroot"
2210
2211
2212For more information, see the
2213:term:`FAKEROOT* <bitbake:FAKEROOT>` variables in the
2214BitBake User Manual. You can also reference the "`Why Not
2215Fakeroot? <https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot>`__"
2216article for background information on Fakeroot and Pseudo.