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