concepts.rst 100 KB

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