concepts.rst 100 KB

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