concepts.rst 100 KB

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