blob: f085dd710dd041a263e7d86c109a9256b09e86e8 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id=' overview-manual-concepts'>
6<title>Yocto Project Concepts</title>
7
8 <para>
9 This chapter provides explanations for Yocto Project concepts that
10 go beyond the surface of "how-to" information and reference (or
11 look-up) material.
12 Concepts such as components, the
13 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
14 workflow, cross-development toolchains, shared state cache, and so
15 forth are explained.
16 </para>
17
18 <section id='yocto-project-components'>
19 <title>Yocto Project Components</title>
20
21 <para>
22 The
23 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
24 task executor together with various types of configuration files
25 form the
26 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core</ulink>.
27 This section overviews these components by describing their use and
28 how they interact.
29 </para>
30
31 <para>
32 BitBake handles the parsing and execution of the data files.
33 The data itself is of various types:
34 <itemizedlist>
35 <listitem><para>
36 <emphasis>Recipes:</emphasis>
37 Provides details about particular pieces of software.
38 </para></listitem>
39 <listitem><para>
40 <emphasis>Class Data:</emphasis>
41 Abstracts common build information (e.g. how to build a
42 Linux kernel).
43 </para></listitem>
44 <listitem><para>
45 <emphasis>Configuration Data:</emphasis>
46 Defines machine-specific settings, policy decisions, and
47 so forth.
48 Configuration data acts as the glue to bind everything
49 together.
50 </para></listitem>
51 </itemizedlist>
52 </para>
53
54 <para>
55 BitBake knows how to combine multiple data sources together and
56 refers to each data source as a layer.
57 For information on layers, see the
58 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
59 section of the Yocto Project Development Tasks Manual.
60 </para>
61
62 <para>
63 Following are some brief details on these core components.
64 For additional information on how these components interact during
65 a build, see the
66 "<link linkend='openembedded-build-system-build-concepts'>OpenEmbedded Build System Concepts</link>"
67 section.
68 </para>
69
70 <section id='usingpoky-components-bitbake'>
71 <title>BitBake</title>
72
73 <para>
74 BitBake is the tool at the heart of the
75 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
76 and is responsible for parsing the
77 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
78 generating a list of tasks from it, and then executing those
79 tasks.
80 </para>
81
82 <para>
83 This section briefly introduces BitBake.
84 If you want more information on BitBake, see the
Brad Bishop19323692019-04-05 15:28:33 -040085 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
Brad Bishop316dfdd2018-06-25 12:45:53 -040086 </para>
87
88 <para>
89 To see a list of the options BitBake supports, use either of
90 the following commands:
91 <literallayout class='monospaced'>
92 $ bitbake -h
93 $ bitbake --help
94 </literallayout>
95 </para>
96
97 <para>
98 The most common usage for BitBake is
99 <filename>bitbake <replaceable>packagename</replaceable></filename>,
100 where <filename>packagename</filename> is the name of the
101 package you want to build (referred to as the "target").
102 The target often equates to the first part of a recipe's
103 filename (e.g. "foo" for a recipe named
104 <filename>foo_1.3.0-r0.bb</filename>).
105 So, to process the
106 <filename>matchbox-desktop_1.2.3.bb</filename> recipe file, you
107 might type the following:
108 <literallayout class='monospaced'>
109 $ bitbake matchbox-desktop
110 </literallayout>
111 Several different versions of
112 <filename>matchbox-desktop</filename> might exist.
113 BitBake chooses the one selected by the distribution
114 configuration.
115 You can get more details about how BitBake chooses between
116 different target versions and providers in the
117 "<ulink url='&YOCTO_DOCS_BB_URL;#bb-bitbake-preferences'>Preferences</ulink>"
118 section of the BitBake User Manual.
119 </para>
120
121 <para>
122 BitBake also tries to execute any dependent tasks first.
123 So for example, before building
124 <filename>matchbox-desktop</filename>, BitBake would build a
125 cross compiler and <filename>glibc</filename> if they had not
126 already been built.
127 </para>
128
129 <para>
130 A useful BitBake option to consider is the
131 <filename>-k</filename> or <filename>--continue</filename>
132 option.
133 This option instructs BitBake to try and continue processing
134 the job as long as possible even after encountering an error.
135 When an error occurs, the target that failed and those that
136 depend on it cannot be remade.
137 However, when you use this option other dependencies can
138 still be processed.
139 </para>
140 </section>
141
142 <section id='overview-components-recipes'>
143 <title>Recipes</title>
144
145 <para>
146 Files that have the <filename>.bb</filename> suffix are
147 "recipes" files.
148 In general, a recipe contains information about a single piece
149 of software.
150 This information includes the location from which to download
151 the unaltered source, any source patches to be applied to that
152 source (if needed), which special configuration options to
153 apply, how to compile the source files, and how to package the
154 compiled output.
155 </para>
156
157 <para>
158 The term "package" is sometimes used to refer to recipes.
159 However, since the word "package" is used for the packaged
160 output from the OpenEmbedded build system (i.e.
161 <filename>.ipk</filename> or <filename>.deb</filename> files),
162 this document avoids using the term "package" when referring
163 to recipes.
164 </para>
165 </section>
166
167 <section id='overview-components-classes'>
168 <title>Classes</title>
169
170 <para>
171 Class files (<filename>.bbclass</filename>) contain information
172 that is useful to share between recipes files.
173 An example is the
174 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
175 class, which contains common settings for any application that
176 Autotools uses.
177 The
178 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes'>Classes</ulink>"
179 chapter in the Yocto Project Reference Manual provides
180 details about classes and how to use them.
181 </para>
182 </section>
183
184 <section id='overview-components-configurations'>
185 <title>Configurations</title>
186
187 <para>
188 The configuration files (<filename>.conf</filename>) define
189 various configuration variables that govern the OpenEmbedded
190 build process.
191 These files fall into several areas that define machine
192 configuration options, distribution configuration options,
193 compiler tuning options, general common configuration options,
194 and user configuration options in
195 <filename>conf/local.conf</filename>, which is found in the
196 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
197 </para>
198 </section>
199 </section>
200
201 <section id='overview-layers'>
202 <title>Layers</title>
203
204 <para>
205 Layers are repositories that contain related metadata (i.e.
206 sets of instructions) that tell the OpenEmbedded build system how
207 to build a target.
208 Yocto Project's
209 <link linkend='the-yocto-project-layer-model'>layer model</link>
210 facilitates collaboration, sharing, customization, and reuse
211 within the Yocto Project development environment.
212 Layers logically separate information for your project.
213 For example, you can use a layer to hold all the configurations
214 for a particular piece of hardware.
215 Isolating hardware-specific configurations allows you to share
216 other metadata by using a different layer where that metadata
217 might be common across several pieces of hardware.
218 </para>
219
220 <para>
221 Many layers exist that work in the Yocto Project development
222 environment.
223 The
224 <ulink url='https://caffelli-staging.yoctoproject.org/software-overview/layers/'>Yocto Project Curated Layer Index</ulink>
225 and
226 <ulink url='http://layers.openembedded.org/layerindex/branch/master/layers/'>OpenEmbedded Layer Index</ulink>
227 both contain layers from which you can use or leverage.
228 </para>
229
230 <para>
231 By convention, layers in the Yocto Project follow a specific form.
232 Conforming to a known structure allows BitBake to make assumptions
233 during builds on where to find types of metadata.
234 You can find procedures and learn about tools (i.e.
235 <filename>bitbake-layers</filename>) for creating layers suitable
236 for the Yocto Project in the
237 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
238 section of the Yocto Project Development Tasks Manual.
239 </para>
240 </section>
241
242 <section id="openembedded-build-system-build-concepts">
243 <title>OpenEmbedded Build System Concepts</title>
244
245 <para>
246 This section takes a more detailed look inside the build
247 process used by the
248 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>,
249 which is the build system specific to the Yocto Project.
250 At the heart of the build system is BitBake, the task executor.
251 </para>
252
253 <para>
254 The following diagram represents the high-level workflow of a
255 build.
256 The remainder of this section expands on the fundamental input,
257 output, process, and metadata logical blocks that make up the
258 workflow.
259 </para>
260
261 <para id='general-workflow-figure'>
262 <imagedata fileref="figures/YP-flow-diagram.png" format="PNG" align='center' width="8in"/>
263 </para>
264
265 <para>
266 In general, the build's workflow consists of several functional
267 areas:
268 <itemizedlist>
269 <listitem><para>
270 <emphasis>User Configuration:</emphasis>
271 metadata you can use to control the build process.
272 </para></listitem>
273 <listitem><para>
274 <emphasis>Metadata Layers:</emphasis>
275 Various layers that provide software, machine, and
276 distro metadata.
277 </para></listitem>
278 <listitem><para>
279 <emphasis>Source Files:</emphasis>
280 Upstream releases, local projects, and SCMs.
281 </para></listitem>
282 <listitem><para>
283 <emphasis>Build System:</emphasis>
284 Processes under the control of
285 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>.
286 This block expands on how BitBake fetches source, applies
287 patches, completes compilation, analyzes output for package
288 generation, creates and tests packages, generates images,
289 and generates cross-development tools.
290 </para></listitem>
291 <listitem><para>
292 <emphasis>Package Feeds:</emphasis>
293 Directories containing output packages (RPM, DEB or IPK),
294 which are subsequently used in the construction of an
295 image or Software Development Kit (SDK), produced by the
296 build system.
297 These feeds can also be copied and shared using a web
298 server or other means to facilitate extending or updating
299 existing images on devices at runtime if runtime package
300 management is enabled.
301 </para></listitem>
302 <listitem><para>
303 <emphasis>Images:</emphasis>
304 Images produced by the workflow.
305 </para></listitem>
306 <listitem><para>
307 <emphasis>Application Development SDK:</emphasis>
308 Cross-development tools that are produced along with
309 an image or separately with BitBake.
310 </para></listitem>
311 </itemizedlist>
312 </para>
313
314 <section id="user-configuration">
315 <title>User Configuration</title>
316
317 <para>
318 User configuration helps define the build.
319 Through user configuration, you can tell BitBake the
320 target architecture for which you are building the image,
321 where to store downloaded source, and other build properties.
322 </para>
323
324 <para>
325 The following figure shows an expanded representation of the
326 "User Configuration" box of the
327 <link linkend='general-workflow-figure'>general workflow figure</link>:
328 </para>
329
330 <para>
331 <imagedata fileref="figures/user-configuration.png" align="center" width="8in" depth="4.5in" />
332 </para>
333
334 <para>
335 BitBake needs some basic configuration files in order to
336 complete a build.
337 These files are <filename>*.conf</filename> files.
338 The minimally necessary ones reside as example files in the
339 <filename>build/conf</filename> directory of the
340 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
341 For simplicity, this section refers to the Source Directory as
342 the "Poky Directory."
343 </para>
344
345 <para>
346 When you clone the
347 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
348 Git repository or you download and unpack a Yocto Project
349 release, you can set up the Source Directory to be named
350 anything you want.
351 For this discussion, the cloned repository uses the default
352 name <filename>poky</filename>.
353 <note>
354 The Poky repository is primarily an aggregation of existing
355 repositories.
356 It is not a canonical upstream source.
357 </note>
358 </para>
359
360 <para>
361 The <filename>meta-poky</filename> layer inside Poky contains
362 a <filename>conf</filename> directory that has example
363 configuration files.
364 These example files are used as a basis for creating actual
365 configuration files when you source
366 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>,
367 which is the build environment script.
368 </para>
369
370 <para>
371 Sourcing the build environment script creates a
372 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
373 if one does not already exist.
374 BitBake uses the Build Directory for all its work during
375 builds.
376 The Build Directory has a <filename>conf</filename> directory
377 that contains default versions of your
378 <filename>local.conf</filename> and
379 <filename>bblayers.conf</filename> configuration files.
380 These default configuration files are created only if versions
381 do not already exist in the Build Directory at the time you
382 source the build environment setup script.
383 </para>
384
385 <para>
386 Because the Poky repository is fundamentally an aggregation of
387 existing repositories, some users might be familiar with
388 running the <filename>&OE_INIT_FILE;</filename> script
389 in the context of separate
390 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core</ulink>
391 and BitBake repositories rather than a single Poky repository.
392 This discussion assumes the script is executed from
393 within a cloned or unpacked version of Poky.
394 </para>
395
396 <para>
397 Depending on where the script is sourced, different
398 sub-scripts are called to set up the Build Directory
399 (Yocto or OpenEmbedded).
400 Specifically, the script
401 <filename>scripts/oe-setup-builddir</filename> inside the
402 poky directory sets up the Build Directory and seeds the
403 directory (if necessary) with configuration files appropriate
404 for the Yocto Project development environment.
405 <note>
406 The <filename>scripts/oe-setup-builddir</filename> script
407 uses the <filename>$TEMPLATECONF</filename> variable to
408 determine which sample configuration files to locate.
409 </note>
410 </para>
411
412 <para>
413 The <filename>local.conf</filename> file provides many
414 basic variables that define a build environment.
415 Here is a list of a few.
416 To see the default configurations in a
417 <filename>local.conf</filename> file created by the build
418 environment script, see the
419 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-poky/conf/local.conf.sample'><filename>local.conf.sample</filename></ulink>
420 in the <filename>meta-poky</filename> layer:
421 <itemizedlist>
422 <listitem><para>
423 <emphasis>Target Machine Selection:</emphasis>
424 Controlled by the
425 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
426 variable.
427 </para></listitem>
428 <listitem><para>
429 <emphasis>Download Directory:</emphasis>
430 Controlled by the
431 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
432 variable.
433 </para></listitem>
434 <listitem><para>
435 <emphasis>Shared State Directory:</emphasis>
436 Controlled by the
437 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
438 variable.
439 </para></listitem>
440 <listitem><para>
441 <emphasis>Build Output:</emphasis>
442 Controlled by the
443 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
444 variable.
445 </para></listitem>
446 <listitem><para>
447 <emphasis>Distribution Policy:</emphasis>
448 Controlled by the
449 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
450 variable.
451 </para></listitem>
452 <listitem><para>
453 <emphasis>Packaging Format:</emphasis>
454 Controlled by the
455 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
456 variable.
457 </para></listitem>
458 <listitem><para>
459 <emphasis>SDK Target Architecture:</emphasis>
460 Controlled by the
461 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>
462 variable.
463 </para></listitem>
464 <listitem><para>
465 <emphasis>Extra Image Packages:</emphasis>
466 Controlled by the
467 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
468 variable.
469 </para></listitem>
470 </itemizedlist>
471 <note>
472 Configurations set in the
473 <filename>conf/local.conf</filename> file can also be set
474 in the <filename>conf/site.conf</filename> and
475 <filename>conf/auto.conf</filename> configuration files.
476 </note>
477 </para>
478
479 <para>
480 The <filename>bblayers.conf</filename> file tells BitBake what
481 layers you want considered during the build.
482 By default, the layers listed in this file include layers
483 minimally needed by the build system.
484 However, you must manually add any custom layers you have
485 created.
486 You can find more information on working with the
487 <filename>bblayers.conf</filename> file in the
488 "<ulink url='&YOCTO_DOCS_DEV_URL;#enabling-your-layer'>Enabling Your Layer</ulink>"
489 section in the Yocto Project Development Tasks Manual.
490 </para>
491
492 <para>
493 The files <filename>site.conf</filename> and
494 <filename>auto.conf</filename> are not created by the
495 environment initialization script.
496 If you want the <filename>site.conf</filename> file, you
497 need to create that yourself.
498 The <filename>auto.conf</filename> file is typically created by
499 an autobuilder:
500 <itemizedlist>
501 <listitem><para>
502 <emphasis><filename>site.conf</filename>:</emphasis>
503 You can use the <filename>conf/site.conf</filename>
504 configuration file to configure multiple
505 build directories.
506 For example, suppose you had several build environments
507 and they shared some common features.
508 You can set these default build properties here.
509 A good example is perhaps the packaging format to use
510 through the
511 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
512 variable.</para>
513
514 <para>One useful scenario for using the
515 <filename>conf/site.conf</filename> file is to extend
516 your
517 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
518 variable to include the path to a
519 <filename>conf/site.conf</filename>.
520 Then, when BitBake looks for Metadata using
521 <filename>BBPATH</filename>, it finds the
522 <filename>conf/site.conf</filename> file and applies
523 your common configurations found in the file.
524 To override configurations in a particular build
525 directory, alter the similar configurations within
526 that build directory's
527 <filename>conf/local.conf</filename> file.
528 </para></listitem>
529 <listitem><para>
530 <emphasis><filename>auto.conf</filename>:</emphasis>
531 The file is usually created and written to by
532 an autobuilder.
533 The settings put into the file are typically the
534 same as you would find in the
535 <filename>conf/local.conf</filename> or the
536 <filename>conf/site.conf</filename> files.
537 </para></listitem>
538 </itemizedlist>
539 </para>
540
541 <para>
542 You can edit all configuration files to further define
543 any particular build environment.
544 This process is represented by the "User Configuration Edits"
545 box in the figure.
546 </para>
547
548 <para>
549 When you launch your build with the
550 <filename>bitbake <replaceable>target</replaceable></filename>
551 command, BitBake sorts out the configurations to ultimately
552 define your build environment.
553 It is important to understand that the
554 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
555 reads the configuration files in a specific order:
556 <filename>site.conf</filename>, <filename>auto.conf</filename>,
557 and <filename>local.conf</filename>.
558 And, the build system applies the normal assignment statement
559 rules as described in the
560 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
561 chapter of the BitBake User Manual.
562 Because the files are parsed in a specific order, variable
563 assignments for the same variable could be affected.
564 For example, if the <filename>auto.conf</filename> file and
565 the <filename>local.conf</filename> set
566 <replaceable>variable1</replaceable> to different values,
567 because the build system parses <filename>local.conf</filename>
568 after <filename>auto.conf</filename>,
569 <replaceable>variable1</replaceable> is assigned the value from
570 the <filename>local.conf</filename> file.
571 </para>
572 </section>
573
574 <section id="metadata-machine-configuration-and-policy-configuration">
575 <title>Metadata, Machine Configuration, and Policy Configuration</title>
576
577 <para>
578 The previous section described the user configurations that
579 define BitBake's global behavior.
580 This section takes a closer look at the layers the build system
581 uses to further control the build.
582 These layers provide Metadata for the software, machine, and
583 policies.
584 </para>
585
586 <para>
587 In general, three types of layer input exists.
588 You can see them below the "User Configuration" box in the
589 <link linkend='general-workflow-figure'>general workflow figure</link>:
590 <itemizedlist>
591 <listitem><para>
592 <emphasis>Metadata (<filename>.bb</filename> + Patches):</emphasis>
593 Software layers containing user-supplied recipe files,
594 patches, and append files.
595 A good example of a software layer might be the
596 <ulink url='https://github.com/meta-qt5/meta-qt5'><filename>meta-qt5</filename></ulink>
597 layer from the
598 <ulink url='http://layers.openembedded.org/layerindex/branch/master/layers/'>OpenEmbedded Layer Index</ulink>.
599 This layer is for version 5.0 of the popular
600 <ulink url='https://wiki.qt.io/About_Qt'>Qt</ulink>
601 cross-platform application development framework for
602 desktop, embedded and mobile.
603 </para></listitem>
604 <listitem><para>
605 <emphasis>Machine BSP Configuration:</emphasis>
606 Board Support Package (BSP) layers (i.e. "BSP Layer"
607 in the following figure) providing machine-specific
608 configurations.
609 This type of information is specific to a particular
610 target architecture.
611 A good example of a BSP layer from the
612 <link linkend='gs-reference-distribution-poky'>Poky Reference Distribution</link>
613 is the
614 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-yocto-bsp'><filename>meta-yocto-bsp</filename></ulink>
615 layer.
616 </para></listitem>
617 <listitem><para>
618 <emphasis>Policy Configuration:</emphasis>
619 Distribution Layers (i.e. "Distro Layer" in the
620 following figure) providing top-level or general
621 policies for the images or SDKs being built for a
622 particular distribution.
623 For example, in the Poky Reference Distribution the
624 distro layer is the
625 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-poky'><filename>meta-poky</filename></ulink>
626 layer.
627 Within the distro layer is a
628 <filename>conf/distro</filename> directory that
629 contains distro configuration files (e.g.
630 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-poky/conf/distro/poky.conf'><filename>poky.conf</filename></ulink>
631 that contain many policy configurations for the
632 Poky distribution.
633 </para></listitem>
634 </itemizedlist>
635 </para>
636
637 <para>
638 The following figure shows an expanded representation of
639 these three layers from the
640 <link linkend='general-workflow-figure'>general workflow figure</link>:
641 </para>
642
643 <para>
644 <imagedata fileref="figures/layer-input.png" align="center" width="8in" depth="8in" />
645 </para>
646
647 <para>
648 In general, all layers have a similar structure.
649 They all contain a licensing file
650 (e.g. <filename>COPYING.MIT</filename>) if the layer is to be
651 distributed, a <filename>README</filename> file as good
652 practice and especially if the layer is to be distributed, a
653 configuration directory, and recipe directories.
654 You can learn about the general structure for layers used with
655 the Yocto Project in the
656 "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-your-own-layer'>Creating Your Own Layer</ulink>"
657 section in the Yocto Project Development Tasks Manual.
658 For a general discussion on layers and the many layers from
659 which you can draw, see the
660 "<link linkend='overview-layers'>Layers</link>" and
661 "<link linkend='the-yocto-project-layer-model'>The Yocto Project Layer Model</link>"
662 sections both earlier in this manual.
663 </para>
664
665 <para>
666 If you explored the previous links, you discovered some
667 areas where many layers that work with the Yocto Project
668 exist.
669 The
670 <ulink url="http://git.yoctoproject.org/">Source Repositories</ulink>
671 also shows layers categorized under "Yocto Metadata Layers."
672 <note>
673 Layers exist in the Yocto Project Source Repositories that
674 cannot be found in the OpenEmbedded Layer Index.
675 These layers are either deprecated or experimental
676 in nature.
677 </note>
678 </para>
679
680 <para>
681 BitBake uses the <filename>conf/bblayers.conf</filename> file,
682 which is part of the user configuration, to find what layers it
683 should be using as part of the build.
684 </para>
685
686 <section id="distro-layer">
687 <title>Distro Layer</title>
688
689 <para>
690 The distribution layer provides policy configurations for
691 your distribution.
692 Best practices dictate that you isolate these types of
693 configurations into their own layer.
694 Settings you provide in
695 <filename>conf/distro/<replaceable>distro</replaceable>.conf</filename> override
696 similar settings that BitBake finds in your
697 <filename>conf/local.conf</filename> file in the Build
698 Directory.
699 </para>
700
701 <para>
702 The following list provides some explanation and references
703 for what you typically find in the distribution layer:
704 <itemizedlist>
705 <listitem><para>
706 <emphasis>classes:</emphasis>
707 Class files (<filename>.bbclass</filename>) hold
708 common functionality that can be shared among
709 recipes in the distribution.
710 When your recipes inherit a class, they take on the
711 settings and functions for that class.
712 You can read more about class files in the
713 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes'>Classes</ulink>"
714 chapter of the Yocto Reference Manual.
715 </para></listitem>
716 <listitem><para>
717 <emphasis>conf:</emphasis>
718 This area holds configuration files for the
719 layer (<filename>conf/layer.conf</filename>),
720 the distribution
721 (<filename>conf/distro/<replaceable>distro</replaceable>.conf</filename>),
722 and any distribution-wide include files.
723 </para></listitem>
724 <listitem><para>
725 <emphasis>recipes-*:</emphasis>
726 Recipes and append files that affect common
727 functionality across the distribution.
728 This area could include recipes and append files
729 to add distribution-specific configuration,
730 initialization scripts, custom image recipes,
731 and so forth.
732 Examples of <filename>recipes-*</filename>
733 directories are <filename>recipes-core</filename>
734 and <filename>recipes-extra</filename>.
735 Hierarchy and contents within a
736 <filename>recipes-*</filename> directory can vary.
737 Generally, these directories contain recipe files
738 (<filename>*.bb</filename>), recipe append files
739 (<filename>*.bbappend</filename>), directories
740 that are distro-specific for configuration files,
741 and so forth.
742 </para></listitem>
743 </itemizedlist>
744 </para>
745 </section>
746
747 <section id="bsp-layer">
748 <title>BSP Layer</title>
749
750 <para>
751 The BSP Layer provides machine configurations that
752 target specific hardware.
753 Everything in this layer is specific to the machine for
754 which you are building the image or the SDK.
755 A common structure or form is defined for BSP layers.
756 You can learn more about this structure in the
757 <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>.
758 <note>
759 In order for a BSP layer to be considered compliant
760 with the Yocto Project, it must meet some structural
761 requirements.
762 </note>
763 </para>
764
765 <para>
766 The BSP Layer's configuration directory contains
767 configuration files for the machine
768 (<filename>conf/machine/<replaceable>machine</replaceable>.conf</filename>)
769 and, of course, the layer
770 (<filename>conf/layer.conf</filename>).
771 </para>
772
773 <para>
774 The remainder of the layer is dedicated to specific recipes
775 by function: <filename>recipes-bsp</filename>,
776 <filename>recipes-core</filename>,
777 <filename>recipes-graphics</filename>,
778 <filename>recipes-kernel</filename>, and so forth.
779 Metadata can exist for multiple formfactors, graphics
780 support systems, and so forth.
781 <note>
782 While the figure shows several
783 <filename>recipes-*</filename> directories, not all
784 these directories appear in all BSP layers.
785 </note>
786 </para>
787 </section>
788
789 <section id="software-layer">
790 <title>Software Layer</title>
791
792 <para>
793 The software layer provides the Metadata for additional
794 software packages used during the build.
795 This layer does not include Metadata that is specific to
796 the distribution or the machine, which are found in their
797 respective layers.
798 </para>
799
800 <para>
801 This layer contains any recipes, append files, and
802 patches, that your project needs.
803 </para>
804 </section>
805 </section>
806
807 <section id="sources-dev-environment">
808 <title>Sources</title>
809
810 <para>
811 In order for the OpenEmbedded build system to create an
812 image or any target, it must be able to access source files.
813 The
814 <link linkend='general-workflow-figure'>general workflow figure</link>
815 represents source files using the "Upstream Project Releases",
816 "Local Projects", and "SCMs (optional)" boxes.
817 The figure represents mirrors, which also play a role in
818 locating source files, with the "Source Materials" box.
819 </para>
820
821 <para>
822 The method by which source files are ultimately organized is
823 a function of the project.
824 For example, for released software, projects tend to use
825 tarballs or other archived files that can capture the
826 state of a release guaranteeing that it is statically
827 represented.
828 On the other hand, for a project that is more dynamic or
829 experimental in nature, a project might keep source files in a
830 repository controlled by a Source Control Manager (SCM) such as
831 Git.
832 Pulling source from a repository allows you to control
833 the point in the repository (the revision) from which you
834 want to build software.
835 Finally, a combination of the two might exist, which would
836 give the consumer a choice when deciding where to get
837 source files.
838 </para>
839
840 <para>
841 BitBake uses the
842 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
843 variable to point to source files regardless of their location.
844 Each recipe must have a <filename>SRC_URI</filename> variable
845 that points to the source.
846 </para>
847
848 <para>
849 Another area that plays a significant role in where source
850 files come from is pointed to by the
851 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
852 variable.
853 This area is a cache that can hold previously downloaded
854 source.
855 You can also instruct the OpenEmbedded build system to create
856 tarballs from Git repositories, which is not the default
857 behavior, and store them in the <filename>DL_DIR</filename>
858 by using the
859 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
860 variable.
861 </para>
862
863 <para>
864 Judicious use of a <filename>DL_DIR</filename> directory can
865 save the build system a trip across the Internet when looking
866 for files.
867 A good method for using a download directory is to have
868 <filename>DL_DIR</filename> point to an area outside of your
869 Build Directory.
870 Doing so allows you to safely delete the Build Directory
871 if needed without fear of removing any downloaded source file.
872 </para>
873
874 <para>
875 The remainder of this section provides a deeper look into the
876 source files and the mirrors.
877 Here is a more detailed look at the source file area of the
878 <link linkend='general-workflow-figure'>general workflow figure</link>:
879 </para>
880
881 <para>
882 <imagedata fileref="figures/source-input.png" width="6in" depth="6in" align="center" />
883 </para>
884
885 <section id='upstream-project-releases'>
886 <title>Upstream Project Releases</title>
887
888 <para>
889 Upstream project releases exist anywhere in the form of an
890 archived file (e.g. tarball or zip file).
891 These files correspond to individual recipes.
892 For example, the figure uses specific releases each for
893 BusyBox, Qt, and Dbus.
894 An archive file can be for any released product that can be
895 built using a recipe.
896 </para>
897 </section>
898
899 <section id='local-projects'>
900 <title>Local Projects</title>
901
902 <para>
903 Local projects are custom bits of software the user
904 provides.
905 These bits reside somewhere local to a project - perhaps
906 a directory into which the user checks in items (e.g.
907 a local directory containing a development source tree
908 used by the group).
909 </para>
910
911 <para>
912 The canonical method through which to include a local
913 project is to use the
914 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
915 class to include that local project.
916 You use either the <filename>local.conf</filename> or a
917 recipe's append file to override or set the
918 recipe to point to the local directory on your disk to pull
919 in the whole source tree.
920 </para>
921 </section>
922
923 <section id='scms'>
924 <title>Source Control Managers (Optional)</title>
925
926 <para>
Brad Bishop15ae2502019-06-18 21:44:24 -0400927 Another place from which the build system can get source
928 files is with
929 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetchers</ulink>
930 employing various Source Control Managers (SCMs) such as
931 Git or Subversion.
Brad Bishopc342db32019-05-15 21:57:59 -0400932 In such cases, a repository is cloned or checked out.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400933 The
934 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
935 task inside BitBake uses
936 the <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
937 variable and the argument's prefix to determine the correct
Brad Bishop15ae2502019-06-18 21:44:24 -0400938 fetcher module.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400939 <note>
940 For information on how to have the OpenEmbedded build
941 system generate tarballs for Git repositories and place
942 them in the
943 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
944 directory, see the
945 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
Brad Bishopc342db32019-05-15 21:57:59 -0400946 variable in the Yocto Project Reference Manual.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400947 </note>
948 </para>
949
950 <para>
951 When fetching a repository, BitBake uses the
952 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
953 variable to determine the specific revision from which to
954 build.
955 </para>
956 </section>
957
958 <section id='source-mirrors'>
959 <title>Source Mirror(s)</title>
960
961 <para>
962 Two kinds of mirrors exist: pre-mirrors and regular
963 mirrors.
964 The
965 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
966 and
967 <ulink url='&YOCTO_DOCS_REF_URL;#var-MIRRORS'><filename>MIRRORS</filename></ulink>
968 variables point to these, respectively.
969 BitBake checks pre-mirrors before looking upstream for any
970 source files.
971 Pre-mirrors are appropriate when you have a shared
972 directory that is not a directory defined by the
973 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
974 variable.
975 A Pre-mirror typically points to a shared directory that is
976 local to your organization.
977 </para>
978
979 <para>
980 Regular mirrors can be any site across the Internet
981 that is used as an alternative location for source
982 code should the primary site not be functioning for
983 some reason or another.
984 </para>
985 </section>
986 </section>
987
988 <section id="package-feeds-dev-environment">
989 <title>Package Feeds</title>
990
991 <para>
992 When the OpenEmbedded build system generates an image or an
993 SDK, it gets the packages from a package feed area located
994 in the
995 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
996 The
997 <link linkend='general-workflow-figure'>general workflow figure</link>
998 shows this package feeds area in the upper-right corner.
999 </para>
1000
1001 <para>
1002 This section looks a little closer into the package feeds
1003 area used by the build system.
1004 Here is a more detailed look at the area:
1005 <imagedata fileref="figures/package-feeds.png" align="center" width="7in" depth="6in" />
1006 </para>
1007
1008 <para>
1009 Package feeds are an intermediary step in the build process.
1010 The OpenEmbedded build system provides classes to generate
1011 different package types, and you specify which classes to
1012 enable through the
1013 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
1014 variable.
1015 Before placing the packages into package feeds,
1016 the build process validates them with generated output quality
1017 assurance checks through the
1018 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
1019 class.
1020 </para>
1021
1022 <para>
1023 The package feed area resides in the Build Directory.
1024 The directory the build system uses to temporarily store
1025 packages is determined by a combination of variables and the
1026 particular package manager in use.
1027 See the "Package Feeds" box in the illustration and note the
1028 information to the right of that area.
1029 In particular, the following defines where package files are
1030 kept:
1031 <itemizedlist>
1032 <listitem><para>
1033 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>:
1034 Defined as <filename>tmp/deploy</filename> in the Build
1035 Directory.
1036 </para></listitem>
1037 <listitem><para>
1038 <filename>DEPLOY_DIR_*</filename>:
1039 Depending on the package manager used, the package type
1040 sub-folder.
1041 Given RPM, IPK, or DEB packaging and tarball creation,
1042 the
1043 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_RPM'><filename>DEPLOY_DIR_RPM</filename></ulink>,
1044 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_IPK'><filename>DEPLOY_DIR_IPK</filename></ulink>,
1045 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_DEB'><filename>DEPLOY_DIR_DEB</filename></ulink>,
1046 or
1047 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_TAR'><filename>DEPLOY_DIR_TAR</filename></ulink>,
1048 variables are used, respectively.
1049 </para></listitem>
1050 <listitem><para>
1051 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>:
1052 Defines architecture-specific sub-folders.
1053 For example, packages could exist for the i586 or
1054 qemux86 architectures.
1055 </para></listitem>
1056 </itemizedlist>
1057 </para>
1058
1059 <para>
1060 BitBake uses the
1061 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_*</filename></ulink>
1062 tasks to generate packages and place them into the package
1063 holding area (e.g. <filename>do_package_write_ipk</filename>
1064 for IPK packages).
1065 See the
1066 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_deb</filename></ulink>",
1067 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_ipk'><filename>do_package_write_ipk</filename></ulink>",
1068 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_rpm'><filename>do_package_write_rpm</filename></ulink>",
1069 and
1070 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_tar'><filename>do_package_write_tar</filename></ulink>"
1071 sections in the Yocto Project Reference Manual
1072 for additional information.
1073 As an example, consider a scenario where an IPK packaging
1074 manager is being used and package architecture support for
1075 both i586 and qemux86 exist.
1076 Packages for the i586 architecture are placed in
1077 <filename>build/tmp/deploy/ipk/i586</filename>, while packages
1078 for the qemux86 architecture are placed in
1079 <filename>build/tmp/deploy/ipk/qemux86</filename>.
1080 </para>
1081 </section>
1082
1083 <section id='bitbake-dev-environment'>
1084 <title>BitBake</title>
1085
1086 <para>
1087 The OpenEmbedded build system uses
1088 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
1089 to produce images and Software Development Kits (SDKs).
1090 You can see from the
1091 <link linkend='general-workflow-figure'>general workflow figure</link>,
1092 the BitBake area consists of several functional areas.
1093 This section takes a closer look at each of those areas.
1094 <note>
1095 Separate documentation exists for the BitBake tool.
1096 See the
Brad Bishop19323692019-04-05 15:28:33 -04001097 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001098 for reference material on BitBake.
1099 </note>
1100 </para>
1101
1102 <section id='source-fetching-dev-environment'>
1103 <title>Source Fetching</title>
1104
1105 <para>
1106 The first stages of building a recipe are to fetch and
1107 unpack the source code:
1108 <imagedata fileref="figures/source-fetching.png" align="center" width="6.5in" depth="5in" />
1109 </para>
1110
1111 <para>
1112 The
1113 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1114 and
1115 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1116 tasks fetch the source files and unpack them into the
1117 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
1118 <note>
1119 For every local file (e.g. <filename>file://</filename>)
1120 that is part of a recipe's
1121 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1122 statement, the OpenEmbedded build system takes a
1123 checksum of the file for the recipe and inserts the
1124 checksum into the signature for the
1125 <filename>do_fetch</filename> task.
1126 If any local file has been modified, the
1127 <filename>do_fetch</filename> task and all tasks that
1128 depend on it are re-executed.
1129 </note>
1130 By default, everything is accomplished in the Build
1131 Directory, which has a defined structure.
1132 For additional general information on the Build Directory,
1133 see the
1134 "<ulink url='&YOCTO_DOCS_REF_URL;#structure-core-build'><filename>build/</filename></ulink>"
1135 section in the Yocto Project Reference Manual.
1136 </para>
1137
1138 <para>
1139 Each recipe has an area in the Build Directory where the
1140 unpacked source code resides.
1141 The
1142 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
1143 variable points to this area for a recipe's unpacked source
1144 code.
1145 The name of that directory for any given recipe is defined
1146 from several different variables.
1147 The preceding figure and the following list describe
1148 the Build Directory's hierarchy:
1149 <itemizedlist>
1150 <listitem><para>
1151 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
1152 The base directory where the OpenEmbedded build
1153 system performs all its work during the build.
1154 The default base directory is the
1155 <filename>tmp</filename> directory.
1156 </para></listitem>
1157 <listitem><para>
1158 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>:
1159 The architecture of the built package or packages.
1160 Depending on the eventual destination of the
1161 package or packages (i.e. machine architecture,
1162 <ulink url='&YOCTO_DOCS_REF_URL;#hardware-build-system-term'>build host</ulink>,
1163 SDK, or specific machine),
1164 <filename>PACKAGE_ARCH</filename> varies.
1165 See the variable's description for details.
1166 </para></listitem>
1167 <listitem><para>
1168 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_OS'><filename>TARGET_OS</filename></ulink>:
1169 The operating system of the target device.
1170 A typical value would be "linux" (e.g.
1171 "qemux86-poky-linux").
1172 </para></listitem>
1173 <listitem><para>
1174 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
1175 The name of the recipe used to build the package.
1176 This variable can have multiple meanings.
1177 However, when used in the context of input files,
1178 <filename>PN</filename> represents the the name
1179 of the recipe.
1180 </para></listitem>
1181 <listitem><para>
1182 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>:
1183 The location where the OpenEmbedded build system
1184 builds a recipe (i.e. does the work to create the
1185 package).
1186 <itemizedlist>
1187 <listitem><para>
1188 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
1189 The version of the recipe used to build the
1190 package.
1191 </para></listitem>
1192 <listitem><para>
1193 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
1194 The revision of the recipe used to build the
1195 package.
1196 </para></listitem>
1197 </itemizedlist>
1198 </para></listitem>
1199 <listitem><para>
1200 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>:
1201 Contains the unpacked source files for a given
1202 recipe.
1203 <itemizedlist>
1204 <listitem><para>
1205 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>:
1206 The name of the recipe used to build the
1207 package.
1208 The <filename>BPN</filename> variable is
1209 a version of the <filename>PN</filename>
1210 variable but with common prefixes and
1211 suffixes removed.
1212 </para></listitem>
1213 <listitem><para>
1214 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
1215 The version of the recipe used to build the
1216 package.
1217 </para></listitem>
1218 </itemizedlist>
1219 </para></listitem>
1220 </itemizedlist>
1221 <note>
1222 In the previous figure, notice that two sample
1223 hierarchies exist: one based on package architecture (i.e.
1224 <filename>PACKAGE_ARCH</filename>) and one based on a
1225 machine (i.e. <filename>MACHINE</filename>).
1226 The underlying structures are identical.
1227 The differentiator being what the OpenEmbedded build
1228 system is using as a build target (e.g. general
1229 architecture, a build host, an SDK, or a specific
1230 machine).
1231 </note>
1232 </para>
1233 </section>
1234
1235 <section id='patching-dev-environment'>
1236 <title>Patching</title>
1237
1238 <para>
1239 Once source code is fetched and unpacked, BitBake locates
1240 patch files and applies them to the source files:
1241 <imagedata fileref="figures/patching.png" align="center" width="7in" depth="6in" />
1242 </para>
1243
1244 <para>
1245 The
1246 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1247 task uses a recipe's
1248 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1249 statements and the
1250 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
1251 variable to locate applicable patch files.
1252 </para>
1253
1254 <para>
1255 Default processing for patch files assumes the files have
1256 either <filename>*.patch</filename> or
1257 <filename>*.diff</filename> file types.
1258 You can use <filename>SRC_URI</filename> parameters to
1259 change the way the build system recognizes patch files.
1260 See the
1261 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1262 task for more information.
1263 </para>
1264
1265 <para>
1266 BitBake finds and applies multiple patches for a single
1267 recipe in the order in which it locates the patches.
1268 The <filename>FILESPATH</filename> variable defines the
1269 default set of directories that the build system uses to
1270 search for patch files.
1271 Once found, patches are applied to the recipe's source
1272 files, which are located in the
1273 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
1274 directory.
1275 </para>
1276
1277 <para>
1278 For more information on how the source directories are
1279 created, see the
1280 "<link linkend='source-fetching-dev-environment'>Source Fetching</link>"
1281 section.
1282 For more information on how to create patches and how the
1283 build system processes patches, see the
1284 "<ulink url='&YOCTO_DOCS_DEV_URL;#new-recipe-patching-code'>Patching Code</ulink>"
1285 section in the Yocto Project Development Tasks Manual.
1286 You can also see the
1287 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-devtool-use-devtool-modify-to-modify-the-source-of-an-existing-component'>Use <filename>devtool modify</filename> to Modify the Source of an Existing Component</ulink>"
1288 section in the Yocto Project Application Development and
1289 the Extensible Software Development Kit (SDK) manual and
1290 the
1291 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</ulink>"
1292 section in the Yocto Project Linux Kernel Development
1293 Manual.
1294 </para>
1295 </section>
1296
1297 <section id='configuration-compilation-and-staging-dev-environment'>
1298 <title>Configuration, Compilation, and Staging</title>
1299
1300 <para>
1301 After source code is patched, BitBake executes tasks that
1302 configure and compile the source code.
1303 Once compilation occurs, the files are copied to a holding
1304 area (staged) in preparation for packaging:
1305 <imagedata fileref="figures/configuration-compile-autoreconf.png" align="center" width="7in" depth="5in" />
1306 </para>
1307
1308 <para>
1309 This step in the build process consists of the following
1310 tasks:
1311 <itemizedlist>
1312 <listitem><para>
1313 <emphasis><ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-prepare_recipe_sysroot'><filename>do_prepare_recipe_sysroot</filename></ulink></emphasis>:
1314 This task sets up the two sysroots in
1315 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
1316 (i.e. <filename>recipe-sysroot</filename> and
1317 <filename>recipe-sysroot-native</filename>) so that
1318 during the packaging phase the sysroots can contain
1319 the contents of the
1320 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
1321 tasks of the recipes on which the recipe
1322 containing the tasks depends.
1323 A sysroot exists for both the target and for the
1324 native binaries, which run on the host system.
1325 </para></listitem>
1326 <listitem><para>
1327 <emphasis><filename>do_configure</filename></emphasis>:
1328 This task configures the source by enabling and
1329 disabling any build-time and configuration options
1330 for the software being built.
1331 Configurations can come from the recipe itself as
1332 well as from an inherited class.
1333 Additionally, the software itself might configure
1334 itself depending on the target for which it is
1335 being built.</para>
1336
1337 <para>The configurations handled by the
1338 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
1339 task are specific to configurations for the source
1340 code being built by the recipe.</para>
1341
1342 <para>If you are using the
1343 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
1344 class, you can add additional configuration options
1345 by using the
1346 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
1347 or
1348 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
1349 variables.
1350 For information on how this variable works within
1351 that class, see the
1352 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
1353 class
1354 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/autotools.bbclass'>here</ulink>.
1355 </para></listitem>
1356 <listitem><para>
1357 <emphasis><filename>do_compile</filename></emphasis>:
1358 Once a configuration task has been satisfied,
1359 BitBake compiles the source using the
1360 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
1361 task.
1362 Compilation occurs in the directory pointed to by
1363 the
1364 <ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink>
1365 variable.
1366 Realize that the <filename>B</filename> directory
1367 is, by default, the same as the
1368 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
1369 directory.
1370 </para></listitem>
1371 <listitem><para>
1372 <emphasis><filename>do_install</filename></emphasis>:
1373 After compilation completes, BitBake executes the
1374 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1375 task.
1376 This task copies files from the
1377 <filename>B</filename> directory and places them
1378 in a holding area pointed to by the
1379 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
1380 variable.
1381 Packaging occurs later using files from this
1382 holding directory.
1383 </para></listitem>
1384 </itemizedlist>
1385 </para>
1386 </section>
1387
1388 <section id='package-splitting-dev-environment'>
1389 <title>Package Splitting</title>
1390
1391 <para>
1392 After source code is configured, compiled, and staged, the
1393 build system analyzes the results and splits the output
1394 into packages:
1395 <imagedata fileref="figures/analysis-for-package-splitting.png" align="center" width="7in" depth="7in" />
1396 </para>
1397
1398 <para>
1399 The
1400 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
1401 and
1402 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-packagedata'><filename>do_packagedata</filename></ulink>
1403 tasks combine to analyze the files found in the
1404 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
1405 directory and split them into subsets based on available
1406 packages and files.
1407 Analysis involves the following as well as other items:
1408 splitting out debugging symbols, looking at shared library
1409 dependencies between packages, and looking at package
1410 relationships.
1411 </para>
1412
1413 <para>
1414 The <filename>do_packagedata</filename> task creates
1415 package metadata based on the analysis such that the
1416 build system can generate the final packages.
1417 The
1418 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
1419 task stages (copies) a subset of the files installed by
1420 the
1421 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1422 task into the appropriate sysroot.
1423 Working, staged, and intermediate results of the analysis
1424 and package splitting process use several areas:
1425 <itemizedlist>
1426 <listitem><para>
1427 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGD'><filename>PKGD</filename></ulink>:
1428 The destination directory
1429 (i.e. <filename>package</filename>) for packages
1430 before they are split into individual packages.
1431 </para></listitem>
1432 <listitem><para>
1433 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDESTWORK'><filename>PKGDESTWORK</filename></ulink>:
1434 A temporary work area (i.e.
1435 <filename>pkgdata</filename>) used by the
1436 <filename>do_package</filename> task to save
1437 package metadata.
1438 </para></listitem>
1439 <listitem><para>
1440 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDEST'><filename>PKGDEST</filename></ulink>:
1441 The parent directory (i.e.
1442 <filename>packages-split</filename>) for packages
1443 after they have been split.
1444 </para></listitem>
1445 <listitem><para>
1446 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>:
1447 A shared, global-state directory that holds
1448 packaging metadata generated during the packaging
1449 process.
1450 The packaging process copies metadata from
1451 <filename>PKGDESTWORK</filename> to the
1452 <filename>PKGDATA_DIR</filename> area where it
1453 becomes globally available.
1454 </para></listitem>
1455 <listitem><para>
1456 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR_HOST'><filename>STAGING_DIR_HOST</filename></ulink>:
1457 The path for the sysroot for the system on which
1458 a component is built to run (i.e.
1459 <filename>recipe-sysroot</filename>).
1460 </para></listitem>
1461 <listitem><para>
1462 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR_NATIVE'><filename>STAGING_DIR_NATIVE</filename></ulink>:
1463 The path for the sysroot used when building
1464 components for the build host (i.e.
1465 <filename>recipe-sysroot-native</filename>).
1466 </para></listitem>
1467 <listitem><para>
1468 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR_TARGET'><filename>STAGING_DIR_TARGET</filename></ulink>:
1469 The path for the sysroot used when a component that
1470 is built to execute on a system and it generates
1471 code for yet another machine (e.g. cross-canadian
1472 recipes).
1473 </para></listitem>
1474 </itemizedlist>
1475 The
1476 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
1477 variable defines the files that go into each package in
1478 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>.
1479 If you want details on how this is accomplished, you can
1480 look at
1481 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/package.bbclass'><filename>package.bbclass</filename></ulink>.
1482 </para>
1483
1484 <para>
1485 Depending on the type of packages being created (RPM, DEB,
1486 or IPK), the
1487 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_*</filename></ulink>
1488 task creates the actual packages and places them in the
1489 Package Feed area, which is
1490 <filename>${TMPDIR}/deploy</filename>.
1491 You can see the
1492 "<link linkend='package-feeds-dev-environment'>Package Feeds</link>"
1493 section for more detail on that part of the build process.
1494 <note>
1495 Support for creating feeds directly from the
1496 <filename>deploy/*</filename> directories does not
1497 exist.
1498 Creating such feeds usually requires some kind of feed
1499 maintenance mechanism that would upload the new
1500 packages into an official package feed (e.g. the
1501 Ångström distribution).
1502 This functionality is highly distribution-specific
1503 and thus is not provided out of the box.
1504 </note>
1505 </para>
1506 </section>
1507
1508 <section id='image-generation-dev-environment'>
1509 <title>Image Generation</title>
1510
1511 <para>
1512 Once packages are split and stored in the Package Feeds
1513 area, the build system uses BitBake to generate the root
1514 filesystem image:
1515 <imagedata fileref="figures/image-generation.png" align="center" width="7.5in" depth="7.5in" />
1516 </para>
1517
1518 <para>
1519 The image generation process consists of several stages and
1520 depends on several tasks and variables.
1521 The
1522 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
1523 task creates the root filesystem (file and directory
1524 structure) for an image.
1525 This task uses several key variables to help create the
1526 list of packages to actually install:
1527 <itemizedlist>
1528 <listitem><para>
1529 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
1530 Lists out the base set of packages from which to
1531 install from the Package Feeds area.
1532 </para></listitem>
1533 <listitem><para>
1534 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
1535 Specifies packages that should not be installed
1536 into the image.
1537 </para></listitem>
1538 <listitem><para>
1539 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
1540 Specifies features to include in the image.
1541 Most of these features map to additional packages
1542 for installation.
1543 </para></listitem>
1544 <listitem><para>
1545 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>:
1546 Specifies the package backend (e.g. RPM, DEB, or
1547 IPK) to use and consequently helps determine where
1548 to locate packages within the Package Feeds area.
1549 </para></listitem>
1550 <listitem><para>
1551 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_LINGUAS'><filename>IMAGE_LINGUAS</filename></ulink>:
1552 Determines the language(s) for which additional
1553 language support packages are installed.
1554 </para></listitem>
1555 <listitem><para>
1556 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>:
1557 The final list of packages passed to the package
1558 manager for installation into the image.
1559 </para></listitem>
1560 </itemizedlist>
1561 </para>
1562
1563 <para>
1564 With
1565 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_ROOTFS'><filename>IMAGE_ROOTFS</filename></ulink>
1566 pointing to the location of the filesystem under
1567 construction and the <filename>PACKAGE_INSTALL</filename>
1568 variable providing the final list of packages to install,
1569 the root file system is created.
1570 </para>
1571
1572 <para>
1573 Package installation is under control of the package
1574 manager (e.g. dnf/rpm, opkg, or apt/dpkg) regardless of
1575 whether or not package management is enabled for the
1576 target.
1577 At the end of the process, if package management is not
1578 enabled for the target, the package manager's data files
1579 are deleted from the root filesystem.
1580 As part of the final stage of package installation,
1581 post installation scripts that are part of the packages
1582 are run.
1583 Any scripts that fail to run on the build host are run on
1584 the target when the target system is first booted.
1585 If you are using a
1586 <ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-read-only-root-filesystem'>read-only root filesystem</ulink>,
1587 all the post installation scripts must succeed on the
1588 build host during the package installation phase since the
1589 root filesystem on the target is read-only.
1590 </para>
1591
1592 <para>
1593 The final stages of the <filename>do_rootfs</filename> task
1594 handle post processing.
1595 Post processing includes creation of a manifest file and
1596 optimizations.
1597 </para>
1598
1599 <para>
1600 The manifest file (<filename>.manifest</filename>) resides
1601 in the same directory as the root filesystem image.
1602 This file lists out, line-by-line, the installed packages.
1603 The manifest file is useful for the
1604 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
1605 class, for example, to determine whether or not to run
1606 specific tests.
1607 See the
1608 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_MANIFEST'><filename>IMAGE_MANIFEST</filename></ulink>
1609 variable for additional information.
1610 </para>
1611
1612 <para>
1613 Optimizing processes that are run across the image include
1614 <filename>mklibs</filename>, <filename>prelink</filename>,
1615 and any other post-processing commands as defined by the
1616 <ulink url='&YOCTO_DOCS_REF_URL;#var-ROOTFS_POSTPROCESS_COMMAND'><filename>ROOTFS_POSTPROCESS_COMMAND</filename></ulink>
1617 variable.
1618 The <filename>mklibs</filename> process optimizes the size
1619 of the libraries, while the <filename>prelink</filename>
1620 process optimizes the dynamic linking of shared libraries
1621 to reduce start up time of executables.
1622 </para>
1623
1624 <para>
1625 After the root filesystem is built, processing begins on
1626 the image through the
1627 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
1628 task.
1629 The build system runs any pre-processing commands as
1630 defined by the
1631 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_PREPROCESS_COMMAND'><filename>IMAGE_PREPROCESS_COMMAND</filename></ulink>
1632 variable.
1633 This variable specifies a list of functions to call before
1634 the build system creates the final image output files.
1635 </para>
1636
1637 <para>
1638 The build system dynamically creates
1639 <filename>do_image_*</filename> tasks as needed, based
1640 on the image types specified in the
1641 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
1642 variable.
1643 The process turns everything into an image file or a set of
1644 image files and can compress the root filesystem image to
1645 reduce the overall size of the image.
1646 The formats used for the root filesystem depend on the
1647 <filename>IMAGE_FSTYPES</filename> variable.
1648 Compression depends on whether the formats support
1649 compression.
1650 </para>
1651
1652 <para>
1653 As an example, a dynamically created task when creating a
1654 particular image <replaceable>type</replaceable> would
1655 take the following form:
1656 <literallayout class='monospaced'>
1657 do_image_<replaceable>type</replaceable>
1658 </literallayout>
1659 So, if the <replaceable>type</replaceable> as specified by
1660 the <filename>IMAGE_FSTYPES</filename> were
1661 <filename>ext4</filename>, the dynamically generated task
1662 would be as follows:
1663 <literallayout class='monospaced'>
1664 do_image_ext4
1665 </literallayout>
1666 </para>
1667
1668 <para>
1669 The final task involved in image creation is the
1670 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image-complete'><filename>do_image_complete</filename></ulink>
1671 task.
1672 This task completes the image by applying any image
1673 post processing as defined through the
1674 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_POSTPROCESS_COMMAND'><filename>IMAGE_POSTPROCESS_COMMAND</filename></ulink>
1675 variable.
1676 The variable specifies a list of functions to call once the
1677 build system has created the final image output files.
1678 <note>
1679 The entire image generation process is run under
1680 <link linkend='fakeroot-and-pseudo'>Pseudo</link>.
1681 Running under Pseudo ensures that the files in the
1682 root filesystem have correct ownership.
1683 </note>
1684 </para>
1685 </section>
1686
1687 <section id='sdk-generation-dev-environment'>
1688 <title>SDK Generation</title>
1689
1690 <para>
1691 The OpenEmbedded build system uses BitBake to generate the
1692 Software Development Kit (SDK) installer scripts for both
1693 the standard SDK and the extensible SDK (eSDK):
1694 </para>
1695
1696 <para>
1697 <imagedata fileref="figures/sdk-generation.png" width="9in" align="center" />
1698 <note>
1699 For more information on the cross-development toolchain
1700 generation, see the
1701 "<link linkend='cross-development-toolchain-generation'>Cross-Development Toolchain Generation</link>"
1702 section.
1703 For information on advantages gained when building a
1704 cross-development toolchain using the
1705 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sdk'><filename>do_populate_sdk</filename></ulink>
1706 task, see the
1707 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-building-an-sdk-installer'>Building an SDK Installer</ulink>"
1708 section in the Yocto Project Application Development
1709 and the Extensible Software Development Kit (eSDK)
1710 manual.
1711 </note>
1712 </para>
1713
1714 <para>
1715 Like image generation, the SDK script process consists of
1716 several stages and depends on many variables.
1717 The
1718 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sdk'><filename>do_populate_sdk</filename></ulink>
1719 and
1720 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sdk_ext'><filename>do_populate_sdk_ext</filename></ulink>
1721 tasks use these key variables to help create the list of
1722 packages to actually install.
1723 For information on the variables listed in the figure,
1724 see the
1725 "<link linkend='sdk-dev-environment'>Application Development SDK</link>"
1726 section.
1727 </para>
1728
1729 <para>
1730 The <filename>do_populate_sdk</filename> task helps create
1731 the standard SDK and handles two parts: a target part and a
1732 host part.
1733 The target part is the part built for the target hardware
1734 and includes libraries and headers.
1735 The host part is the part of the SDK that runs on the
1736 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>.
1737 </para>
1738
1739 <para>
1740 The <filename>do_populate_sdk_ext</filename> task helps
1741 create the extensible SDK and handles host and target parts
1742 differently than its counter part does for the standard SDK.
1743 For the extensible SDK, the task encapsulates the build
1744 system, which includes everything needed (host and target)
1745 for the SDK.
1746 </para>
1747
1748 <para>
1749 Regardless of the type of SDK being constructed, the
1750 tasks perform some cleanup after which a cross-development
1751 environment setup script and any needed configuration files
1752 are created.
1753 The final output is the Cross-development
1754 toolchain installation script (<filename>.sh</filename>
1755 file), which includes the environment setup script.
1756 </para>
1757 </section>
1758
1759 <section id='stamp-files-and-the-rerunning-of-tasks'>
1760 <title>Stamp Files and the Rerunning of Tasks</title>
1761
1762 <para>
1763 For each task that completes successfully, BitBake writes a
1764 stamp file into the
1765 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
1766 directory.
1767 The beginning of the stamp file's filename is determined
1768 by the
1769 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMP'><filename>STAMP</filename></ulink>
1770 variable, and the end of the name consists of the task's
1771 name and current
1772 <link linkend='overview-checksums'>input checksum</link>.
1773 <note>
1774 This naming scheme assumes that
1775 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_SIGNATURE_HANDLER'><filename>BB_SIGNATURE_HANDLER</filename></ulink>
1776 is "OEBasicHash", which is almost always the case in
1777 current OpenEmbedded.
1778 </note>
1779 To determine if a task needs to be rerun, BitBake checks
1780 if a stamp file with a matching input checksum exists
1781 for the task.
1782 If such a stamp file exists, the task's output is
1783 assumed to exist and still be valid.
1784 If the file does not exist, the task is rerun.
1785 <note>
1786 <para>The stamp mechanism is more general than the
1787 shared state (sstate) cache mechanism described in the
1788 "<link linkend='setscene-tasks-and-shared-state'>Setscene Tasks and Shared State</link>"
1789 section.
1790 BitBake avoids rerunning any task that has a valid
1791 stamp file, not just tasks that can be accelerated
1792 through the sstate cache.</para>
1793
1794 <para>However, you should realize that stamp files only
1795 serve as a marker that some work has been done and that
1796 these files do not record task output.
1797 The actual task output would usually be somewhere in
1798 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
1799 (e.g. in some recipe's
1800 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.)
1801 What the sstate cache mechanism adds is a way to cache
1802 task output that can then be shared between build
1803 machines.</para>
1804 </note>
1805 Since <filename>STAMPS_DIR</filename> is usually a
1806 subdirectory of <filename>TMPDIR</filename>, removing
1807 <filename>TMPDIR</filename> will also remove
1808 <filename>STAMPS_DIR</filename>, which means tasks will
1809 properly be rerun to repopulate
1810 <filename>TMPDIR</filename>.
1811 </para>
1812
1813 <para>
1814 If you want some task to always be considered "out of
1815 date", you can mark it with the
1816 <ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink>
1817 varflag.
1818 If some other task depends on such a task, then that
1819 task will also always be considered out of date, which
1820 might not be what you want.
1821 </para>
1822
1823 <para>
1824 For details on how to view information about a task's
1825 signature, see the
1826 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</ulink>"
1827 section in the Yocto Project Development Tasks Manual.
1828 </para>
1829 </section>
1830
1831 <section id='setscene-tasks-and-shared-state'>
1832 <title>Setscene Tasks and Shared State</title>
1833
1834 <para>
1835 The description of tasks so far assumes that BitBake needs
1836 to build everything and no available prebuilt objects
1837 exist.
1838 BitBake does support skipping tasks if prebuilt objects are
1839 available.
1840 These objects are usually made available in the form of a
1841 shared state (sstate) cache.
1842 <note>
1843 For information on variables affecting sstate, see the
1844 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
1845 and
1846 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_MIRRORS'><filename>SSTATE_MIRRORS</filename></ulink>
1847 variables.
1848 </note>
1849 </para>
1850
1851 <para>
1852 The idea of a setscene task (i.e
1853 <filename>do_</filename><replaceable>taskname</replaceable><filename>_setscene</filename>)
1854 is a version of the task where
1855 instead of building something, BitBake can skip to the end
1856 result and simply place a set of files into specific
1857 locations as needed.
1858 In some cases, it makes sense to have a setscene task
1859 variant (e.g. generating package files in the
1860 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_*</filename></ulink>
1861 task).
1862 In other cases, it does not make sense (e.g. a
1863 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1864 task or a
1865 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1866 task) since the work involved would be equal to or greater
1867 than the underlying task.
1868 </para>
1869
1870 <para>
1871 In the build system, the common tasks that have setscene
1872 variants are
1873 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>,
1874 <filename>do_package_write_*</filename>,
1875 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-deploy'><filename>do_deploy</filename></ulink>,
1876 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-packagedata'><filename>do_packagedata</filename></ulink>,
1877 and
1878 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>.
1879 Notice that these tasks represent most of the tasks whose
1880 output is an end result.
1881 </para>
1882
1883 <para>
1884 The build system has knowledge of the relationship between
1885 these tasks and other preceding tasks.
1886 For example, if BitBake runs
1887 <filename>do_populate_sysroot_setscene</filename> for
1888 something, it does not make sense to run any of the
1889 <filename>do_fetch</filename>,
1890 <filename>do_unpack</filename>,
1891 <filename>do_patch</filename>,
1892 <filename>do_configure</filename>,
1893 <filename>do_compile</filename>, and
1894 <filename>do_install</filename> tasks.
1895 However, if <filename>do_package</filename> needs to be
1896 run, BitBake needs to run those other tasks.
1897 </para>
1898
1899 <para>
1900 It becomes more complicated if everything can come
1901 from an sstate cache because some objects are simply
1902 not required at all.
1903 For example, you do not need a compiler or native tools,
1904 such as quilt, if nothing exists to compile or patch.
1905 If the <filename>do_package_write_*</filename> packages
1906 are available from sstate, BitBake does not need the
1907 <filename>do_package</filename> task data.
1908 </para>
1909
1910 <para>
1911 To handle all these complexities, BitBake runs in two
1912 phases.
1913 The first is the "setscene" stage.
1914 During this stage, BitBake first checks the sstate cache
1915 for any targets it is planning to build.
1916 BitBake does a fast check to see if the object exists
1917 rather than a complete download.
1918 If nothing exists, the second phase, which is the setscene
1919 stage, completes and the main build proceeds.
1920 </para>
1921
1922 <para>
1923 If objects are found in the sstate cache, the build system
1924 works backwards from the end targets specified by the user.
1925 For example, if an image is being built, the build system
1926 first looks for the packages needed for that image and the
1927 tools needed to construct an image.
1928 If those are available, the compiler is not needed.
1929 Thus, the compiler is not even downloaded.
1930 If something was found to be unavailable, or the
1931 download or setscene task fails, the build system then
1932 tries to install dependencies, such as the compiler, from
1933 the cache.
1934 </para>
1935
1936 <para>
1937 The availability of objects in the sstate cache is
1938 handled by the function specified by the
1939 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHCHECK_FUNCTION'><filename>BB_HASHCHECK_FUNCTION</filename></ulink>
1940 variable and returns a list of available objects.
1941 The function specified by the
1942 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_SETSCENE_DEPVALID'><filename>BB_SETSCENE_DEPVALID</filename></ulink>
1943 variable is the function that determines whether a given
1944 dependency needs to be followed, and whether for any given
1945 relationship the function needs to be passed.
1946 The function returns a True or False value.
1947 </para>
1948 </section>
1949 </section>
1950
1951 <section id='images-dev-environment'>
1952 <title>Images</title>
1953
1954 <para>
1955 The images produced by the build system are compressed forms
1956 of the root filesystem and are ready to boot on a target
1957 device.
1958 You can see from the
1959 <link linkend='general-workflow-figure'>general workflow figure</link>
1960 that BitBake output, in part, consists of images.
1961 This section takes a closer look at this output:
1962 <imagedata fileref="figures/images.png" align="center" width="5.5in" depth="5.5in" />
1963 </para>
1964
1965 <note>
1966 For a list of example images that the Yocto Project provides,
1967 see the
1968 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1969 chapter in the Yocto Project Reference Manual.
1970 </note>
1971
1972 <para>
1973 The build process writes images out to the
1974 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
1975 inside the
1976 <filename>tmp/deploy/images/<replaceable>machine</replaceable>/</filename>
1977 folder as shown in the figure.
1978 This folder contains any files expected to be loaded on the
1979 target device.
1980 The
1981 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>
1982 variable points to the <filename>deploy</filename> directory,
1983 while the
1984 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_IMAGE'><filename>DEPLOY_DIR_IMAGE</filename></ulink>
1985 variable points to the appropriate directory containing images
1986 for the current configuration.
1987 <itemizedlist>
1988 <listitem><para>
1989 <replaceable>kernel-image</replaceable>:
1990 A kernel binary file.
1991 The
1992 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'><filename>KERNEL_IMAGETYPE</filename></ulink>
1993 variable determines the naming scheme for the
1994 kernel image file.
1995 Depending on this variable, the file could begin with
1996 a variety of naming strings.
1997 The
1998 <filename>deploy/images/</filename><replaceable>machine</replaceable>
1999 directory can contain multiple image files for the
2000 machine.
2001 </para></listitem>
2002 <listitem><para>
2003 <replaceable>root-filesystem-image</replaceable>:
2004 Root filesystems for the target device (e.g.
2005 <filename>*.ext3</filename> or
2006 <filename>*.bz2</filename> files).
2007 The
2008 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
2009 variable determines the root filesystem image type.
2010 The
2011 <filename>deploy/images/</filename><replaceable>machine</replaceable>
2012 directory can contain multiple root filesystems for the
2013 machine.
2014 </para></listitem>
2015 <listitem><para>
2016 <replaceable>kernel-modules</replaceable>:
2017 Tarballs that contain all the modules built for the
2018 kernel.
2019 Kernel module tarballs exist for legacy purposes and
2020 can be suppressed by setting the
2021 <ulink url='&YOCTO_DOCS_REF_URL;#var-MODULE_TARBALL_DEPLOY'><filename>MODULE_TARBALL_DEPLOY</filename></ulink>
2022 variable to "0".
2023 The
2024 <filename>deploy/images/</filename><replaceable>machine</replaceable>
2025 directory can contain multiple kernel module tarballs
2026 for the machine.
2027 </para></listitem>
2028 <listitem><para>
2029 <replaceable>bootloaders</replaceable>:
2030 If applicable to the target machine, bootloaders
2031 supporting the image.
2032 The <filename>deploy/images/</filename><replaceable>machine</replaceable>
2033 directory can contain multiple bootloaders for the
2034 machine.
2035 </para></listitem>
2036 <listitem><para>
2037 <replaceable>symlinks</replaceable>:
2038 The
2039 <filename>deploy/images/</filename><replaceable>machine</replaceable>
2040 folder contains a symbolic link that points to the
2041 most recently built file for each machine.
2042 These links might be useful for external scripts that
2043 need to obtain the latest version of each file.
2044 </para></listitem>
2045 </itemizedlist>
2046 </para>
2047 </section>
2048
2049 <section id='sdk-dev-environment'>
2050 <title>Application Development SDK</title>
2051
2052 <para>
2053 In the
2054 <link linkend='general-workflow-figure'>general workflow figure</link>,
2055 the output labeled "Application Development SDK" represents an
2056 SDK.
2057 The SDK generation process differs depending on whether you
2058 build an extensible SDK (e.g.
2059 <filename>bitbake -c populate_sdk_ext</filename> <replaceable>imagename</replaceable>)
2060 or a standard SDK (e.g.
2061 <filename>bitbake -c populate_sdk</filename> <replaceable>imagename</replaceable>).
2062 This section takes a closer look at this output:
2063 <imagedata fileref="figures/sdk.png" align="center" width="9in" depth="7.25in" />
2064 </para>
2065
2066 <para>
2067 The specific form of this output is a set of files that
2068 includes a self-extracting SDK installer
2069 (<filename>*.sh</filename>), host and target manifest files,
2070 and files used for SDK testing.
2071 When the SDK installer file is run, it installs the SDK.
2072 The SDK consists of a cross-development toolchain, a set of
2073 libraries and headers, and an SDK environment setup script.
2074 Running this installer essentially sets up your
2075 cross-development environment.
2076 You can think of the cross-toolchain as the "host"
2077 part because it runs on the SDK machine.
2078 You can think of the libraries and headers as the "target"
2079 part because they are built for the target hardware.
2080 The environment setup script is added so that you can
2081 initialize the environment before using the tools.
2082 </para>
2083
2084 <note><title>Notes</title>
2085 <itemizedlist>
2086 <listitem><para>
2087 The Yocto Project supports several methods by which
2088 you can set up this cross-development environment.
2089 These methods include downloading pre-built SDK
2090 installers or building and installing your own SDK
2091 installer.
2092 </para></listitem>
2093 <listitem><para>
2094 For background information on cross-development
2095 toolchains in the Yocto Project development
2096 environment, see the
2097 "<link linkend='cross-development-toolchain-generation'>Cross-Development Toolchain Generation</link>"
2098 section.
2099 </para></listitem>
2100 <listitem><para>
2101 For information on setting up a cross-development
2102 environment, see the
2103 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
2104 manual.
2105 </para></listitem>
2106 </itemizedlist>
2107 </note>
2108
2109 <para>
2110 All the output files for an SDK are written to the
2111 <filename>deploy/sdk</filename> folder inside the
2112 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
2113 as shown in the previous figure.
2114 Depending on the type of SDK, several variables exist that help
2115 configure these files.
2116 The following list shows the variables associated with an
2117 extensible SDK:
2118 <itemizedlist>
2119 <listitem><para>
2120 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>:
2121 Points to the <filename>deploy</filename> directory.
2122 </para></listitem>
2123 <listitem><para>
2124 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_EXT_TYPE'><filename>SDK_EXT_TYPE</filename></ulink>:
2125 Controls whether or not shared state artifacts are
2126 copied into the extensible SDK.
2127 By default, all required shared state artifacts are
2128 copied into the SDK.
2129 </para></listitem>
2130 <listitem><para>
2131 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_INCLUDE_PKGDATA'><filename>SDK_INCLUDE_PKGDATA</filename></ulink>:
2132 Specifies whether or not packagedata is included in the
2133 extensible SDK for all recipes in the "world" target.
2134 </para></listitem>
2135 <listitem><para>
2136 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_INCLUDE_TOOLCHAIN'><filename>SDK_INCLUDE_TOOLCHAIN</filename></ulink>:
2137 Specifies whether or not the toolchain is included
2138 when building the extensible SDK.
2139 </para></listitem>
2140 <listitem><para>
2141 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_LOCAL_CONF_WHITELIST'><filename>SDK_LOCAL_CONF_WHITELIST</filename></ulink>:
2142 A list of variables allowed through from the build
2143 system configuration into the extensible SDK
2144 configuration.
2145 </para></listitem>
2146 <listitem><para>
2147 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_LOCAL_CONF_BLACKLIST'><filename>SDK_LOCAL_CONF_BLACKLIST</filename></ulink>:
2148 A list of variables not allowed through from the build
2149 system configuration into the extensible SDK
2150 configuration.
2151 </para></listitem>
2152 <listitem><para>
2153 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_INHERIT_BLACKLIST'><filename>SDK_INHERIT_BLACKLIST</filename></ulink>:
2154 A list of classes to remove from the
2155 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHERIT'><filename>INHERIT</filename></ulink>
2156 value globally within the extensible SDK configuration.
2157 </para></listitem>
2158 </itemizedlist>
2159 This next list, shows the variables associated with a standard
2160 SDK:
2161 <itemizedlist>
2162 <listitem><para>
2163 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>:
2164 Points to the <filename>deploy</filename> directory.
2165 </para></listitem>
2166 <listitem><para>
2167 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>:
2168 Specifies the architecture of the machine on which the
2169 cross-development tools are run to create packages for
2170 the target hardware.
2171 </para></listitem>
2172 <listitem><para>
2173 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKIMAGE_FEATURES'><filename>SDKIMAGE_FEATURES</filename></ulink>:
2174 Lists the features to include in the "target" part
2175 of the SDK.
2176 </para></listitem>
2177 <listitem><para>
2178 <ulink url='&YOCTO_DOCS_REF_URL;#var-TOOLCHAIN_HOST_TASK'><filename>TOOLCHAIN_HOST_TASK</filename></ulink>:
2179 Lists packages that make up the host part of the SDK
2180 (i.e. the part that runs on the
2181 <filename>SDKMACHINE</filename>).
2182 When you use
2183 <filename>bitbake -c populate_sdk <replaceable>imagename</replaceable></filename>
2184 to create the SDK, a set of default packages apply.
2185 This variable allows you to add more packages.
2186 </para></listitem>
2187 <listitem><para>
2188 <ulink url='&YOCTO_DOCS_REF_URL;#var-TOOLCHAIN_TARGET_TASK'><filename>TOOLCHAIN_TARGET_TASK</filename></ulink>:
2189 Lists packages that make up the target part of the SDK
2190 (i.e. the part built for the target hardware).
2191 </para></listitem>
2192 <listitem><para>
2193 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKPATH'><filename>SDKPATH</filename></ulink>:
2194 Defines the default SDK installation path offered by
2195 the installation script.
2196 </para></listitem>
2197 <listitem><para>
2198 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_HOST_MANIFEST'><filename>SDK_HOST_MANIFEST</filename></ulink>:
2199 Lists all the installed packages that make up the host
2200 part of the SDK.
2201 This variable also plays a minor role for extensible
2202 SDK development as well.
2203 However, it is mainly used for the standard SDK.
2204 </para></listitem>
2205 <listitem><para>
2206 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_TARGET_MANIFEST'><filename>SDK_TARGET_MANIFEST</filename></ulink>:
2207 Lists all the installed packages that make up the
2208 target part of the SDK.
2209 This variable also plays a minor role for extensible
2210 SDK development as well.
2211 However, it is mainly used for the standard SDK.
2212 </para></listitem>
2213 </itemizedlist>
2214 </para>
2215 </section>
2216 </section>
2217
2218 <section id="cross-development-toolchain-generation">
2219 <title>Cross-Development Toolchain Generation</title>
2220
2221 <para>
2222 The Yocto Project does most of the work for you when it comes to
2223 creating
2224 <ulink url='&YOCTO_DOCS_REF_URL;#cross-development-toolchain'>cross-development toolchains</ulink>.
2225 This section provides some technical background on how
2226 cross-development toolchains are created and used.
2227 For more information on toolchains, you can also see the
2228 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
2229 manual.
2230 </para>
2231
2232 <para>
2233 In the Yocto Project development environment, cross-development
2234 toolchains are used to build images and applications that run
2235 on the target hardware.
2236 With just a few commands, the OpenEmbedded build system creates
2237 these necessary toolchains for you.
2238 </para>
2239
2240 <para>
2241 The following figure shows a high-level build environment regarding
2242 toolchain construction and use.
2243 </para>
2244
2245 <para>
2246 <imagedata fileref="figures/cross-development-toolchains.png" width="8in" depth="6in" align="center" />
2247 </para>
2248
2249 <para>
2250 Most of the work occurs on the Build Host.
2251 This is the machine used to build images and generally work within
2252 the the Yocto Project environment.
2253 When you run
2254 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
2255 to create an image, the OpenEmbedded build system
2256 uses the host <filename>gcc</filename> compiler to bootstrap a
2257 cross-compiler named <filename>gcc-cross</filename>.
2258 The <filename>gcc-cross</filename> compiler is what BitBake uses to
2259 compile source files when creating the target image.
2260 You can think of <filename>gcc-cross</filename> simply as an
2261 automatically generated cross-compiler that is used internally
2262 within BitBake only.
2263 <note>
2264 The extensible SDK does not use
2265 <filename>gcc-cross-canadian</filename> since this SDK
2266 ships a copy of the OpenEmbedded build system and the sysroot
2267 within it contains <filename>gcc-cross</filename>.
2268 </note>
2269 </para>
2270
2271 <para>
2272 The chain of events that occurs when <filename>gcc-cross</filename> is
2273 bootstrapped is as follows:
2274 <literallayout class='monospaced'>
2275 gcc -> binutils-cross -> gcc-cross-initial -> linux-libc-headers -> glibc-initial -> glibc -> gcc-cross -> gcc-runtime
2276 </literallayout>
2277 <itemizedlist>
2278 <listitem><para>
2279 <filename>gcc</filename>:
2280 The build host's GNU Compiler Collection (GCC).
2281 </para></listitem>
2282 <listitem><para>
2283 <filename>binutils-cross</filename>:
2284 The bare minimum binary utilities needed in order to run
2285 the <filename>gcc-cross-initial</filename> phase of the
2286 bootstrap operation.
2287 </para></listitem>
2288 <listitem><para>
2289 <filename>gcc-cross-initial</filename>:
2290 An early stage of the bootstrap process for creating
2291 the cross-compiler.
2292 This stage builds enough of the <filename>gcc-cross</filename>,
2293 the C library, and other pieces needed to finish building the
2294 final cross-compiler in later stages.
2295 This tool is a "native" package (i.e. it is designed to run on
2296 the build host).
2297 </para></listitem>
2298 <listitem><para>
2299 <filename>linux-libc-headers</filename>:
2300 Headers needed for the cross-compiler.
2301 </para></listitem>
2302 <listitem><para>
2303 <filename>glibc-initial</filename>:
2304 An initial version of the Embedded GNU C Library
2305 (GLIBC) needed to bootstrap <filename>glibc</filename>.
2306 </para></listitem>
2307 <listitem><para>
2308 <filename>glibc</filename>:
2309 The GNU C Library.
2310 </para></listitem>
2311 <listitem><para>
2312 <filename>gcc-cross</filename>:
2313 The final stage of the bootstrap process for the
2314 cross-compiler.
2315 This stage results in the actual cross-compiler that
2316 BitBake uses when it builds an image for a targeted
2317 device.
2318 <note>
2319 If you are replacing this cross compiler toolchain
2320 with a custom version, you must replace
2321 <filename>gcc-cross</filename>.
2322 </note>
2323 This tool is also a "native" package (i.e. it is
2324 designed to run on the build host).
2325 </para></listitem>
2326 <listitem><para>
2327 <filename>gcc-runtime</filename>:
2328 Runtime libraries resulting from the toolchain bootstrapping
2329 process.
2330 This tool produces a binary that consists of the
2331 runtime libraries need for the targeted device.
2332 </para></listitem>
2333 </itemizedlist>
2334 </para>
2335
2336 <para>
2337 You can use the OpenEmbedded build system to build an installer for
2338 the relocatable SDK used to develop applications.
2339 When you run the installer, it installs the toolchain, which
2340 contains the development tools (e.g.,
2341 <filename>gcc-cross-canadian</filename>,
2342 <filename>binutils-cross-canadian</filename>, and other
2343 <filename>nativesdk-*</filename> tools),
2344 which are tools native to the SDK (i.e. native to
2345 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_ARCH'><filename>SDK_ARCH</filename></ulink>),
2346 you need to cross-compile and test your software.
2347 The figure shows the commands you use to easily build out this
2348 toolchain.
2349 This cross-development toolchain is built to execute on the
2350 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>,
2351 which might or might not be the same
2352 machine as the Build Host.
2353 <note>
2354 If your target architecture is supported by the Yocto Project,
2355 you can take advantage of pre-built images that ship with the
2356 Yocto Project and already contain cross-development toolchain
2357 installers.
2358 </note>
2359 </para>
2360
2361 <para>
2362 Here is the bootstrap process for the relocatable toolchain:
2363 <literallayout class='monospaced'>
2364 gcc -> binutils-crosssdk -> gcc-crosssdk-initial -> linux-libc-headers ->
2365 glibc-initial -> nativesdk-glibc -> gcc-crosssdk -> gcc-cross-canadian
2366 </literallayout>
2367 <itemizedlist>
2368 <listitem><para>
2369 <filename>gcc</filename>:
2370 The build host's GNU Compiler Collection (GCC).
2371 </para></listitem>
2372 <listitem><para>
2373 <filename>binutils-crosssdk</filename>:
2374 The bare minimum binary utilities needed in order to run
2375 the <filename>gcc-crosssdk-initial</filename> phase of the
2376 bootstrap operation.
2377 </para></listitem>
2378 <listitem><para>
2379 <filename>gcc-crosssdk-initial</filename>:
2380 An early stage of the bootstrap process for creating
2381 the cross-compiler.
2382 This stage builds enough of the
2383 <filename>gcc-crosssdk</filename> and supporting pieces so that
2384 the final stage of the bootstrap process can produce the
2385 finished cross-compiler.
2386 This tool is a "native" binary that runs on the build host.
2387 </para></listitem>
2388 <listitem><para>
2389 <filename>linux-libc-headers</filename>:
2390 Headers needed for the cross-compiler.
2391 </para></listitem>
2392 <listitem><para>
2393 <filename>glibc-initial</filename>:
2394 An initial version of the Embedded GLIBC needed to bootstrap
2395 <filename>nativesdk-glibc</filename>.
2396 </para></listitem>
2397 <listitem><para>
2398 <filename>nativesdk-glibc</filename>:
2399 The Embedded GLIBC needed to bootstrap the
2400 <filename>gcc-crosssdk</filename>.
2401 </para></listitem>
2402 <listitem><para>
2403 <filename>gcc-crosssdk</filename>:
2404 The final stage of the bootstrap process for the
2405 relocatable cross-compiler.
2406 The <filename>gcc-crosssdk</filename> is a transitory
2407 compiler and never leaves the build host.
2408 Its purpose is to help in the bootstrap process to create
2409 the eventual <filename>gcc-cross-canadian</filename>
2410 compiler, which is relocatable.
2411 This tool is also a "native" package (i.e. it is
2412 designed to run on the build host).
2413 </para></listitem>
2414 <listitem><para>
2415 <filename>gcc-cross-canadian</filename>:
2416 The final relocatable cross-compiler.
2417 When run on the
2418 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>,
2419 this tool
2420 produces executable code that runs on the target device.
2421 Only one cross-canadian compiler is produced per architecture
2422 since they can be targeted at different processor optimizations
2423 using configurations passed to the compiler through the
2424 compile commands.
2425 This circumvents the need for multiple compilers and thus
2426 reduces the size of the toolchains.
2427 </para></listitem>
2428 </itemizedlist>
2429 </para>
2430
2431 <note>
2432 For information on advantages gained when building a
2433 cross-development toolchain installer, see the
2434 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-building-an-sdk-installer'>Building an SDK Installer</ulink>"
2435 appendix in the Yocto Project Application Development and the
2436 Extensible Software Development Kit (eSDK) manual.
2437 </note>
2438 </section>
2439
2440 <section id="shared-state-cache">
2441 <title>Shared State Cache</title>
2442
2443 <para>
2444 By design, the OpenEmbedded build system builds everything from
2445 scratch unless
2446 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
2447 can determine that parts do not need to be rebuilt.
2448 Fundamentally, building from scratch is attractive as it means all
2449 parts are built fresh and no possibility of stale data exists that
2450 can cause problems.
2451 When developers hit problems, they typically default back to
2452 building from scratch so they have a know state from the
2453 start.
2454 </para>
2455
2456 <para>
2457 Building an image from scratch is both an advantage and a
2458 disadvantage to the process.
2459 As mentioned in the previous paragraph, building from scratch
2460 ensures that everything is current and starts from a known state.
2461 However, building from scratch also takes much longer as it
2462 generally means rebuilding things that do not necessarily need
2463 to be rebuilt.
2464 </para>
2465
2466 <para>
2467 The Yocto Project implements shared state code that supports
2468 incremental builds.
2469 The implementation of the shared state code answers the following
2470 questions that were fundamental roadblocks within the OpenEmbedded
2471 incremental build support system:
2472 <itemizedlist>
2473 <listitem><para>
2474 What pieces of the system have changed and what pieces have
2475 not changed?
2476 </para></listitem>
2477 <listitem><para>
2478 How are changed pieces of software removed and replaced?
2479 </para></listitem>
2480 <listitem><para>
2481 How are pre-built components that do not need to be rebuilt
2482 from scratch used when they are available?
2483 </para></listitem>
2484 </itemizedlist>
2485 </para>
2486
2487 <para>
2488 For the first question, the build system detects changes in the
2489 "inputs" to a given task by creating a checksum (or signature) of
2490 the task's inputs.
2491 If the checksum changes, the system assumes the inputs have changed
2492 and the task needs to be rerun.
2493 For the second question, the shared state (sstate) code tracks
2494 which tasks add which output to the build process.
2495 This means the output from a given task can be removed, upgraded
2496 or otherwise manipulated.
2497 The third question is partly addressed by the solution for the
2498 second question assuming the build system can fetch the sstate
2499 objects from remote locations and install them if they are deemed
2500 to be valid.
2501 <note><title>Notes</title>
2502 <itemizedlist>
2503 <listitem><para>
2504 The build system does not maintain
2505 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
2506 information as part of the shared state packages.
2507 Consequently, considerations exist that affect
2508 maintaining shared state feeds.
2509 For information on how the build system works with
2510 packages and can track incrementing
2511 <filename>PR</filename> information, see the
2512 "<ulink url='&YOCTO_DOCS_DEV_URL;#automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</ulink>"
2513 section in the Yocto Project Development Tasks Manual.
2514 </para></listitem>
2515 <listitem><para>
2516 The code in the build system that supports incremental
2517 builds is not simple code.
2518 For techniques that help you work around issues related
2519 to shared state code, see the
2520 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>Viewing Metadata Used to Create the Input Signature of a Shared State Task</ulink>"
2521 and
2522 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-invalidating-shared-state-to-force-a-task-to-run'>Invalidating Shared State to Force a Task to Run</ulink>"
2523 sections both in the Yocto Project Development Tasks
2524 Manual.
2525 </para></listitem>
2526 </itemizedlist>
2527 </note>
2528 </para>
2529
2530 <para>
2531 The rest of this section goes into detail about the overall
2532 incremental build architecture, the checksums (signatures), and
2533 shared state.
2534 </para>
2535
2536 <section id='concepts-overall-architecture'>
2537 <title>Overall Architecture</title>
2538
2539 <para>
2540 When determining what parts of the system need to be built,
2541 BitBake works on a per-task basis rather than a per-recipe
2542 basis.
2543 You might wonder why using a per-task basis is preferred over
2544 a per-recipe basis.
2545 To help explain, consider having the IPK packaging backend
2546 enabled and then switching to DEB.
2547 In this case, the
2548 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2549 and
2550 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
2551 task outputs are still valid.
2552 However, with a per-recipe approach, the build would not
2553 include the <filename>.deb</filename> files.
2554 Consequently, you would have to invalidate the whole build and
2555 rerun it.
2556 Rerunning everything is not the best solution.
2557 Also, in this case, the core must be "taught" much about
2558 specific tasks.
2559 This methodology does not scale well and does not allow users
2560 to easily add new tasks in layers or as external recipes
2561 without touching the packaged-staging core.
2562 </para>
2563 </section>
2564
2565 <section id='overview-checksums'>
2566 <title>Checksums (Signatures)</title>
2567
2568 <para>
2569 The shared state code uses a checksum, which is a unique
2570 signature of a task's inputs, to determine if a task needs to
2571 be run again.
2572 Because it is a change in a task's inputs that triggers a
2573 rerun, the process needs to detect all the inputs to a given
2574 task.
2575 For shell tasks, this turns out to be fairly easy because
2576 the build process generates a "run" shell script for each task
2577 and it is possible to create a checksum that gives you a good
2578 idea of when the task's data changes.
2579 </para>
2580
2581 <para>
2582 To complicate the problem, there are things that should not be
2583 included in the checksum.
2584 First, there is the actual specific build path of a given
2585 task - the
2586 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
2587 It does not matter if the work directory changes because it
2588 should not affect the output for target packages.
2589 Also, the build process has the objective of making native
2590 or cross packages relocatable.
2591 <note>
2592 Both native and cross packages run on the
2593 <ulink url='&YOCTO_DOCS_REF_URL;#hardware-build-system-term'>build host</ulink>.
2594 However, cross packages generate output for the target
2595 architecture.
2596 </note>
2597 The checksum therefore needs to exclude
2598 <filename>WORKDIR</filename>.
2599 The simplistic approach for excluding the work directory is to
2600 set <filename>WORKDIR</filename> to some fixed value and
2601 create the checksum for the "run" script.
2602 </para>
2603
2604 <para>
2605 Another problem results from the "run" scripts containing
2606 functions that might or might not get called.
2607 The incremental build solution contains code that figures out
2608 dependencies between shell functions.
2609 This code is used to prune the "run" scripts down to the
2610 minimum set, thereby alleviating this problem and making the
2611 "run" scripts much more readable as a bonus.
2612 </para>
2613
2614 <para>
2615 So far, solutions for shell scripts exist.
2616 What about Python tasks?
2617 The same approach applies even though these tasks are more
2618 difficult.
2619 The process needs to figure out what variables a Python
2620 function accesses and what functions it calls.
2621 Again, the incremental build solution contains code that first
2622 figures out the variable and function dependencies, and then
2623 creates a checksum for the data used as the input to the task.
2624 </para>
2625
2626 <para>
2627 Like the <filename>WORKDIR</filename> case, situations exist
2628 where dependencies should be ignored.
2629 For these situations, you can instruct the build process to
2630 ignore a dependency by using a line like the following:
2631 <literallayout class='monospaced'>
2632 PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
2633 </literallayout>
2634 This example ensures that the
2635 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCHS'><filename>PACKAGE_ARCHS</filename></ulink>
2636 variable does not depend on the value of
2637 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
2638 even if it does reference it.
2639 </para>
2640
2641 <para>
2642 Equally, there are cases where you need to add dependencies
2643 BitBake is not able to find.
2644 You can accomplish this by using a line like the following:
2645 <literallayout class='monospaced'>
2646 PACKAGE_ARCHS[vardeps] = "MACHINE"
2647 </literallayout>
2648 This example explicitly adds the <filename>MACHINE</filename>
2649 variable as a dependency for
2650 <filename>PACKAGE_ARCHS</filename>.
2651 </para>
2652
2653 <para>
2654 As an example, consider a case with in-line Python where
2655 BitBake is not able to figure out dependencies.
2656 When running in debug mode (i.e. using
2657 <filename>-DDD</filename>), BitBake produces output when it
2658 discovers something for which it cannot figure out dependencies.
2659 The Yocto Project team has currently not managed to cover
2660 those dependencies in detail and is aware of the need to fix
2661 this situation.
2662 </para>
2663
2664 <para>
2665 Thus far, this section has limited discussion to the direct
2666 inputs into a task.
2667 Information based on direct inputs is referred to as the
2668 "basehash" in the code.
2669 However, the question of a task's indirect inputs still
2670 exits - items already built and present in the
2671 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
2672 The checksum (or signature) for a particular task needs to add
2673 the hashes of all the tasks on which the particular task
2674 depends.
2675 Choosing which dependencies to add is a policy decision.
2676 However, the effect is to generate a master checksum that
2677 combines the basehash and the hashes of the task's
2678 dependencies.
2679 </para>
2680
2681 <para>
2682 At the code level, a variety of ways exist by which both the
2683 basehash and the dependent task hashes can be influenced.
2684 Within the BitBake configuration file, you can give BitBake
2685 some extra information to help it construct the basehash.
2686 The following statement effectively results in a list of
2687 global variable dependency excludes (i.e. variables never
2688 included in any checksum):
2689 <literallayout class='monospaced'>
2690 BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \
2691 SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \
2692 USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \
2693 PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \
2694 CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
2695 </literallayout>
2696 The previous example excludes
2697 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
2698 since that variable is actually constructed as a path within
2699 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>,
2700 which is on the whitelist.
2701 </para>
2702
2703 <para>
2704 The rules for deciding which hashes of dependent tasks to
2705 include through dependency chains are more complex and are
2706 generally accomplished with a Python function.
2707 The code in <filename>meta/lib/oe/sstatesig.py</filename> shows
2708 two examples of this and also illustrates how you can insert
2709 your own policy into the system if so desired.
2710 This file defines the two basic signature generators
2711 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OE-Core</ulink>
2712 uses: "OEBasic" and "OEBasicHash".
2713 By default, a dummy "noop" signature handler is enabled
2714 in BitBake.
2715 This means that behavior is unchanged from previous versions.
2716 OE-Core uses the "OEBasicHash" signature handler by default
2717 through this setting in the <filename>bitbake.conf</filename>
2718 file:
2719 <literallayout class='monospaced'>
2720 BB_SIGNATURE_HANDLER ?= "OEBasicHash"
2721 </literallayout>
2722 The "OEBasicHash" <filename>BB_SIGNATURE_HANDLER</filename>
2723 is the same as the "OEBasic" version but adds the task hash to
2724 the
2725 <link linkend='stamp-files-and-the-rerunning-of-tasks'>stamp files</link>.
2726 This results in any metadata change that changes the task hash,
2727 automatically causing the task to be run again.
2728 This removes the need to bump
2729 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
2730 values, and changes to metadata automatically ripple across
2731 the build.
2732 </para>
2733
2734 <para>
2735 It is also worth noting that the end result of these
2736 signature generators is to make some dependency and hash
2737 information available to the build.
2738 This information includes:
2739 <itemizedlist>
2740 <listitem><para>
2741 <filename>BB_BASEHASH_task-</filename><replaceable>taskname</replaceable>:
2742 The base hashes for each task in the recipe.
2743 </para></listitem>
2744 <listitem><para>
2745 <filename>BB_BASEHASH_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
2746 The base hashes for each dependent task.
2747 </para></listitem>
2748 <listitem><para>
2749 <filename>BBHASHDEPS_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
2750 The task dependencies for each task.
2751 </para></listitem>
2752 <listitem><para>
2753 <filename>BB_TASKHASH</filename>:
2754 The hash of the currently running task.
2755 </para></listitem>
2756 </itemizedlist>
2757 </para>
2758 </section>
2759
2760 <section id='shared-state'>
2761 <title>Shared State</title>
2762
2763 <para>
2764 Checksums and dependencies, as discussed in the previous
2765 section, solve half the problem of supporting a shared state.
2766 The other half of the problem is being able to use checksum
2767 information during the build and being able to reuse or rebuild
2768 specific components.
2769 </para>
2770
2771 <para>
2772 The
2773 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-sstate'><filename>sstate</filename></ulink>
2774 class is a relatively generic implementation of how to
2775 "capture" a snapshot of a given task.
2776 The idea is that the build process does not care about the
2777 source of a task's output.
2778 Output could be freshly built or it could be downloaded and
2779 unpacked from somewhere.
2780 In other words, the build process does not need to worry about
2781 its origin.
2782 </para>
2783
2784 <para>
2785 Two types of output exist.
2786 One type is just about creating a directory in
2787 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
2788 A good example is the output of either
2789 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2790 or
2791 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>.
2792 The other type of output occurs when a set of data is merged
2793 into a shared directory tree such as the sysroot.
2794 </para>
2795
2796 <para>
2797 The Yocto Project team has tried to keep the details of the
2798 implementation hidden in <filename>sstate</filename> class.
2799 From a user's perspective, adding shared state wrapping to a
2800 task is as simple as this
2801 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-deploy'><filename>do_deploy</filename></ulink>
2802 example taken from the
2803 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-deploy'><filename>deploy</filename></ulink>
2804 class:
2805 <literallayout class='monospaced'>
2806 DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
2807 SSTATETASKS += "do_deploy"
2808 do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
2809 do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
2810
2811 python do_deploy_setscene () {
2812 sstate_setscene(d)
2813 }
2814 addtask do_deploy_setscene
2815 do_deploy[dirs] = "${DEPLOYDIR} ${B}"
2816 do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"
2817 </literallayout>
2818 The following list explains the previous example:
2819 <itemizedlist>
2820 <listitem><para>
2821 Adding "do_deploy" to <filename>SSTATETASKS</filename>
2822 adds some required sstate-related processing, which is
2823 implemented in the
2824 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-sstate'><filename>sstate</filename></ulink>
2825 class, to before and after the
2826 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-deploy'><filename>do_deploy</filename></ulink>
2827 task.
2828 </para></listitem>
2829 <listitem><para>
2830 The
2831 <filename>do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"</filename>
2832 declares that <filename>do_deploy</filename> places its
2833 output in <filename>${DEPLOYDIR}</filename> when run
2834 normally (i.e. when not using the sstate cache).
2835 This output becomes the input to the shared state cache.
2836 </para></listitem>
2837 <listitem><para>
2838 The
2839 <filename>do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"</filename>
2840 line causes the contents of the shared state cache to be
2841 copied to <filename>${DEPLOY_DIR_IMAGE}</filename>.
2842 <note>
2843 If <filename>do_deploy</filename> is not already in
2844 the shared state cache or if its input checksum
2845 (signature) has changed from when the output was
2846 cached, the task runs to populate the shared
2847 state cache, after which the contents of the shared
2848 state cache is copied to
2849 <filename>${DEPLOY_DIR_IMAGE}</filename>.
2850 If <filename>do_deploy</filename> is in the shared
2851 state cache and its signature indicates that the
2852 cached output is still valid (i.e. if no
2853 relevant task inputs have changed), then the
2854 contents of the shared state cache copies
2855 directly to
2856 <filename>${DEPLOY_DIR_IMAGE}</filename> by the
2857 <filename>do_deploy_setscene</filename> task
2858 instead, skipping the
2859 <filename>do_deploy</filename> task.
2860 </note>
2861 </para></listitem>
2862 <listitem><para>
2863 The following task definition is glue logic needed to
2864 make the previous settings effective:
2865 <literallayout class='monospaced'>
2866 python do_deploy_setscene () {
2867 sstate_setscene(d)
2868 }
2869 addtask do_deploy_setscene
2870 </literallayout>
2871 <filename>sstate_setscene()</filename> takes the flags
2872 above as input and accelerates the
2873 <filename>do_deploy</filename> task through the
2874 shared state cache if possible.
2875 If the task was accelerated,
2876 <filename>sstate_setscene()</filename> returns True.
2877 Otherwise, it returns False, and the normal
2878 <filename>do_deploy</filename> task runs.
2879 For more information, see the
2880 "<ulink url='&YOCTO_DOCS_BB_URL;#setscene'>setscene</ulink>"
2881 section in the BitBake User Manual.
2882 </para></listitem>
2883 <listitem><para>
2884 The <filename>do_deploy[dirs] = "${DEPLOYDIR} ${B}"</filename>
2885 line creates <filename>${DEPLOYDIR}</filename> and
2886 <filename>${B}</filename> before the
2887 <filename>do_deploy</filename> task runs, and also sets
2888 the current working directory of
2889 <filename>do_deploy</filename> to
2890 <filename>${B}</filename>.
2891 For more information, see the
2892 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
2893 section in the BitBake User Manual.
2894 <note>
2895 In cases where
2896 <filename>sstate-inputdirs</filename> and
2897 <filename>sstate-outputdirs</filename> would be the
2898 same, you can use
2899 <filename>sstate-plaindirs</filename>.
2900 For example, to preserve the
2901 <filename>${PKGD}</filename> and
2902 <filename>${PKGDEST}</filename> output from the
2903 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
2904 task, use the following:
2905 <literallayout class='monospaced'>
2906 do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
2907 </literallayout>
2908 </note>
2909 </para></listitem>
2910 <listitem><para>
2911 The <filename>do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"</filename>
2912 line appends extra metadata to the
2913 <link linkend='stamp-files-and-the-rerunning-of-tasks'>stamp file</link>.
2914 In this case, the metadata makes the task specific
2915 to a machine's architecture.
2916 See
2917 "<ulink url='&YOCTO_DOCS_BB_URL;#ref-bitbake-tasklist'>The Task List</ulink>"
2918 section in the BitBake User Manual for more
2919 information on the <filename>stamp-extra-info</filename>
2920 flag.
2921 </para></listitem>
2922 <listitem><para>
2923 <filename>sstate-inputdirs</filename> and
2924 <filename>sstate-outputdirs</filename> can also be used
2925 with multiple directories.
2926 For example, the following declares
2927 <filename>PKGDESTWORK</filename> and
2928 <filename>SHLIBWORK</filename> as shared state
2929 input directories, which populates the shared state
2930 cache, and <filename>PKGDATA_DIR</filename> and
2931 <filename>SHLIBSDIR</filename> as the corresponding
2932 shared state output directories:
2933 <literallayout class='monospaced'>
2934 do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
2935 do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
2936 </literallayout>
2937 </para></listitem>
2938 <listitem><para>
2939 These methods also include the ability to take a
2940 lockfile when manipulating shared state directory
2941 structures, for cases where file additions or removals
2942 are sensitive:
2943 <literallayout class='monospaced'>
2944 do_package[sstate-lockfile] = "${PACKAGELOCK}"
2945 </literallayout>
2946 </para></listitem>
2947 </itemizedlist>
2948 </para>
2949
2950 <para>
2951 Behind the scenes, the shared state code works by looking in
2952 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
2953 and
2954 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_MIRRORS'><filename>SSTATE_MIRRORS</filename></ulink>
2955 for shared state files.
2956 Here is an example:
2957 <literallayout class='monospaced'>
2958 SSTATE_MIRRORS ?= "\
2959 file://.* http://someserver.tld/share/sstate/PATH;downloadfilename=PATH \n \
2960 file://.* file:///some/local/dir/sstate/PATH"
2961 </literallayout>
2962 <note>
2963 The shared state directory
2964 (<filename>SSTATE_DIR</filename>) is organized into
2965 two-character subdirectories, where the subdirectory
2966 names are based on the first two characters of the hash.
2967 If the shared state directory structure for a mirror has the
2968 same structure as <filename>SSTATE_DIR</filename>, you must
2969 specify "PATH" as part of the URI to enable the build system
2970 to map to the appropriate subdirectory.
2971 </note>
2972 </para>
2973
2974 <para>
2975 The shared state package validity can be detected just by
2976 looking at the filename since the filename contains the task
2977 checksum (or signature) as described earlier in this section.
2978 If a valid shared state package is found, the build process
2979 downloads it and uses it to accelerate the task.
2980 </para>
2981
2982 <para>
2983 The build processes use the <filename>*_setscene</filename>
2984 tasks for the task acceleration phase.
2985 BitBake goes through this phase before the main execution
2986 code and tries to accelerate any tasks for which it can find
2987 shared state packages.
2988 If a shared state package for a task is available, the
2989 shared state package is used.
2990 This means the task and any tasks on which it is dependent
2991 are not executed.
2992 </para>
2993
2994 <para>
2995 As a real world example, the aim is when building an IPK-based
2996 image, only the
2997 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_ipk'><filename>do_package_write_ipk</filename></ulink>
2998 tasks would have their shared state packages fetched and
2999 extracted.
3000 Since the sysroot is not used, it would never get extracted.
3001 This is another reason why a task-based approach is preferred
3002 over a recipe-based approach, which would have to install the
3003 output from every task.
3004 </para>
3005 </section>
3006 </section>
3007
3008 <section id='automatically-added-runtime-dependencies'>
3009 <title>Automatically Added Runtime Dependencies</title>
3010
3011 <para>
3012 The OpenEmbedded build system automatically adds common types of
3013 runtime dependencies between packages, which means that you do not
3014 need to explicitly declare the packages using
3015 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>.
3016 Three automatic mechanisms exist (<filename>shlibdeps</filename>,
3017 <filename>pcdeps</filename>, and <filename>depchains</filename>)
3018 that handle shared libraries, package configuration (pkg-config)
3019 modules, and <filename>-dev</filename> and
3020 <filename>-dbg</filename> packages, respectively.
3021 For other types of runtime dependencies, you must manually declare
3022 the dependencies.
3023 <itemizedlist>
3024 <listitem><para>
3025 <filename>shlibdeps</filename>:
3026 During the
3027 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
3028 task of each recipe, all shared libraries installed by the
3029 recipe are located.
3030 For each shared library, the package that contains the
3031 shared library is registered as providing the shared
3032 library.
3033 More specifically, the package is registered as providing
3034 the
3035 <ulink url='https://en.wikipedia.org/wiki/Soname'>soname</ulink>
3036 of the library.
3037 The resulting shared-library-to-package mapping
3038 is saved globally in
3039 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
3040 by the
3041 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-packagedata'><filename>do_packagedata</filename></ulink>
3042 task.</para>
3043
3044 <para>Simultaneously, all executables and shared libraries
3045 installed by the recipe are inspected to see what shared
3046 libraries they link against.
3047 For each shared library dependency that is found,
3048 <filename>PKGDATA_DIR</filename> is queried to
3049 see if some package (likely from a different recipe)
3050 contains the shared library.
3051 If such a package is found, a runtime dependency is added
3052 from the package that depends on the shared library to the
3053 package that contains the library.</para>
3054
3055 <para>The automatically added runtime dependency also
3056 includes a version restriction.
3057 This version restriction specifies that at least the
3058 current version of the package that provides the shared
3059 library must be used, as if
3060 "<replaceable>package</replaceable> (>= <replaceable>version</replaceable>)"
3061 had been added to <filename>RDEPENDS</filename>.
3062 This forces an upgrade of the package containing the shared
3063 library when installing the package that depends on the
3064 library, if needed.</para>
3065
3066 <para>If you want to avoid a package being registered as
3067 providing a particular shared library (e.g. because the library
3068 is for internal use only), then add the library to
3069 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRIVATE_LIBS'><filename>PRIVATE_LIBS</filename></ulink>
3070 inside the package's recipe.
3071 </para></listitem>
3072 <listitem><para>
3073 <filename>pcdeps</filename>:
3074 During the <filename>do_package</filename> task of each
3075 recipe, all pkg-config modules
3076 (<filename>*.pc</filename> files) installed by the recipe
3077 are located.
3078 For each module, the package that contains the module is
3079 registered as providing the module.
3080 The resulting module-to-package mapping is saved globally in
3081 <filename>PKGDATA_DIR</filename> by the
3082 <filename>do_packagedata</filename> task.</para>
3083
3084 <para>Simultaneously, all pkg-config modules installed by
3085 the recipe are inspected to see what other pkg-config
3086 modules they depend on.
3087 A module is seen as depending on another module if it
3088 contains a "Requires:" line that specifies the other module.
3089 For each module dependency,
3090 <filename>PKGDATA_DIR</filename> is queried to see if some
3091 package contains the module.
3092 If such a package is found, a runtime dependency is added
3093 from the package that depends on the module to the package
3094 that contains the module.
3095 <note>
3096 The <filename>pcdeps</filename> mechanism most often
3097 infers dependencies between <filename>-dev</filename>
3098 packages.
3099 </note>
3100 </para></listitem>
3101 <listitem><para>
3102 <filename>depchains</filename>:
3103 If a package <filename>foo</filename> depends on a package
3104 <filename>bar</filename>, then <filename>foo-dev</filename>
3105 and <filename>foo-dbg</filename> are also made to depend on
3106 <filename>bar-dev</filename> and
3107 <filename>bar-dbg</filename>, respectively.
3108 Taking the <filename>-dev</filename> packages as an
3109 example, the <filename>bar-dev</filename> package might
3110 provide headers and shared library symlinks needed by
3111 <filename>foo-dev</filename>, which shows the need
3112 for a dependency between the packages.</para>
3113
3114 <para>The dependencies added by
3115 <filename>depchains</filename> are in the form of
3116 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>.
3117 <note>
3118 By default, <filename>foo-dev</filename> also has an
3119 <filename>RDEPENDS</filename>-style dependency on
3120 <filename>foo</filename>, because the default value of
3121 <filename>RDEPENDS_${PN}-dev</filename> (set in
3122 <filename>bitbake.conf</filename>) includes
3123 "${PN}".
3124 </note></para>
3125
3126 <para>To ensure that the dependency chain is never broken,
3127 <filename>-dev</filename> and <filename>-dbg</filename>
3128 packages are always generated by default, even if the
3129 packages turn out to be empty.
3130 See the
3131 <ulink url='&YOCTO_DOCS_REF_URL;#var-ALLOW_EMPTY'><filename>ALLOW_EMPTY</filename></ulink>
3132 variable for more information.
3133 </para></listitem>
3134 </itemizedlist>
3135 </para>
3136
3137 <para>
3138 The <filename>do_package</filename> task depends on the
3139 <filename>do_packagedata</filename> task of each recipe in
3140 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3141 through use of a
3142 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>deptask</filename></ulink><filename>]</filename>
3143 declaration, which guarantees that the required
3144 shared-library/module-to-package mapping information will be available
3145 when needed as long as <filename>DEPENDS</filename> has been
3146 correctly set.
3147 </para>
3148 </section>
3149
3150 <section id='fakeroot-and-pseudo'>
3151 <title>Fakeroot and Pseudo</title>
3152
3153 <para>
3154 Some tasks are easier to implement when allowed to perform certain
3155 operations that are normally reserved for the root user (e.g.
3156 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>,
3157 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write*</filename></ulink>,
3158 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>,
3159 and
3160 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image*</filename></ulink>).
3161 For example, the <filename>do_install</filename> task benefits
3162 from being able to set the UID and GID of installed files to
3163 arbitrary values.
3164 </para>
3165
3166 <para>
3167 One approach to allowing tasks to perform root-only operations
3168 would be to require
3169 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
3170 to run as root.
3171 However, this method is cumbersome and has security issues.
3172 The approach that is actually used is to run tasks that benefit
3173 from root privileges in a "fake" root environment.
3174 Within this environment, the task and its child processes believe
3175 that they are running as the root user, and see an internally
3176 consistent view of the filesystem.
3177 As long as generating the final output (e.g. a package or an image)
3178 does not require root privileges, the fact that some earlier
3179 steps ran in a fake root environment does not cause problems.
3180 </para>
3181
3182 <para>
3183 The capability to run tasks in a fake root environment is known as
3184 "<ulink url='http://man.he.net/man1/fakeroot'>fakeroot</ulink>",
3185 which is derived from the BitBake keyword/variable
3186 flag that requests a fake root environment for a task.
3187 </para>
3188
3189 <para>
3190 In the
3191 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>,
Brad Bishopd89cb5f2019-04-10 09:02:41 -04003192 the program that implements fakeroot is known as
3193 <ulink url='https://www.yoctoproject.org/software-item/pseudo/'>Pseudo</ulink>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04003194 Pseudo overrides system calls by using the environment variable
3195 <filename>LD_PRELOAD</filename>, which results in the illusion
3196 of running as root.
3197 To keep track of "fake" file ownership and permissions resulting
3198 from operations that require root permissions, Pseudo uses
3199 an SQLite 3 database.
3200 This database is stored in
3201 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/pseudo/files.db</filename>
3202 for individual recipes.
3203 Storing the database in a file as opposed to in memory
3204 gives persistence between tasks and builds, which is not
3205 accomplished using fakeroot.
3206 <note><title>Caution</title>
3207 If you add your own task that manipulates the same files or
3208 directories as a fakeroot task, then that task also needs to
3209 run under fakeroot.
3210 Otherwise, the task cannot run root-only operations, and
3211 cannot see the fake file ownership and permissions set by the
3212 other task.
3213 You need to also add a dependency on
3214 <filename>virtual/fakeroot-native:do_populate_sysroot</filename>,
3215 giving the following:
3216 <literallayout class='monospaced'>
3217 fakeroot do_mytask () {
3218 ...
3219 }
3220 do_mytask[depends] += "virtual/fakeroot-native:do_populate_sysroot"
3221 </literallayout>
3222 </note>
3223 For more information, see the
3224 <ulink url='&YOCTO_DOCS_BB_URL;#var-FAKEROOT'><filename>FAKEROOT*</filename></ulink>
3225 variables in the BitBake User Manual.
3226 You can also reference the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003227 "<ulink url='https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot'>Why Not Fakeroot?</ulink>"
Brad Bishopd89cb5f2019-04-10 09:02:41 -04003228 article for background information on Fakeroot and Pseudo.
Brad Bishop316dfdd2018-06-25 12:45:53 -04003229 </para>
3230 </section>
3231</chapter>
3232<!--
3233vim: expandtab tw=80 ts=4
3234-->