concepts.rst 93 KB

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