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