concepts.rst 93 KB

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