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