overview-manual-concepts.rst 89 KB

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