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