concepts.rst 93 KB

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