concepts.rst 100 KB

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