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