blob: 8a1b38c87de682b4c0d0b583b6c6f81d11617c74 [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>
927 Another place the build system can get source files from is
Brad Bishopc342db32019-05-15 21:57:59 -0400928 through a Source Control Manager (SCM) such as Git or
929 Subversion.
930 In such cases, a repository is cloned or checked out.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400931 The
932 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
933 task inside BitBake uses
934 the <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
935 variable and the argument's prefix to determine the correct
Brad Bishopc342db32019-05-15 21:57:59 -0400936 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'><filename>fetcher</filename></ulink>
937 module.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400938 <note>
939 For information on how to have the OpenEmbedded build
940 system generate tarballs for Git repositories and place
941 them in the
942 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
943 directory, see the
944 <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 -0400945 variable in the Yocto Project Reference Manual.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400946 </note>
947 </para>
948
949 <para>
950 When fetching a repository, BitBake uses the
951 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
952 variable to determine the specific revision from which to
953 build.
954 </para>
955 </section>
956
957 <section id='source-mirrors'>
958 <title>Source Mirror(s)</title>
959
960 <para>
961 Two kinds of mirrors exist: pre-mirrors and regular
962 mirrors.
963 The
964 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
965 and
966 <ulink url='&YOCTO_DOCS_REF_URL;#var-MIRRORS'><filename>MIRRORS</filename></ulink>
967 variables point to these, respectively.
968 BitBake checks pre-mirrors before looking upstream for any
969 source files.
970 Pre-mirrors are appropriate when you have a shared
971 directory that is not a directory defined by the
972 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
973 variable.
974 A Pre-mirror typically points to a shared directory that is
975 local to your organization.
976 </para>
977
978 <para>
979 Regular mirrors can be any site across the Internet
980 that is used as an alternative location for source
981 code should the primary site not be functioning for
982 some reason or another.
983 </para>
984 </section>
985 </section>
986
987 <section id="package-feeds-dev-environment">
988 <title>Package Feeds</title>
989
990 <para>
991 When the OpenEmbedded build system generates an image or an
992 SDK, it gets the packages from a package feed area located
993 in the
994 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
995 The
996 <link linkend='general-workflow-figure'>general workflow figure</link>
997 shows this package feeds area in the upper-right corner.
998 </para>
999
1000 <para>
1001 This section looks a little closer into the package feeds
1002 area used by the build system.
1003 Here is a more detailed look at the area:
1004 <imagedata fileref="figures/package-feeds.png" align="center" width="7in" depth="6in" />
1005 </para>
1006
1007 <para>
1008 Package feeds are an intermediary step in the build process.
1009 The OpenEmbedded build system provides classes to generate
1010 different package types, and you specify which classes to
1011 enable through the
1012 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
1013 variable.
1014 Before placing the packages into package feeds,
1015 the build process validates them with generated output quality
1016 assurance checks through the
1017 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
1018 class.
1019 </para>
1020
1021 <para>
1022 The package feed area resides in the Build Directory.
1023 The directory the build system uses to temporarily store
1024 packages is determined by a combination of variables and the
1025 particular package manager in use.
1026 See the "Package Feeds" box in the illustration and note the
1027 information to the right of that area.
1028 In particular, the following defines where package files are
1029 kept:
1030 <itemizedlist>
1031 <listitem><para>
1032 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>:
1033 Defined as <filename>tmp/deploy</filename> in the Build
1034 Directory.
1035 </para></listitem>
1036 <listitem><para>
1037 <filename>DEPLOY_DIR_*</filename>:
1038 Depending on the package manager used, the package type
1039 sub-folder.
1040 Given RPM, IPK, or DEB packaging and tarball creation,
1041 the
1042 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_RPM'><filename>DEPLOY_DIR_RPM</filename></ulink>,
1043 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_IPK'><filename>DEPLOY_DIR_IPK</filename></ulink>,
1044 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_DEB'><filename>DEPLOY_DIR_DEB</filename></ulink>,
1045 or
1046 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_TAR'><filename>DEPLOY_DIR_TAR</filename></ulink>,
1047 variables are used, respectively.
1048 </para></listitem>
1049 <listitem><para>
1050 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>:
1051 Defines architecture-specific sub-folders.
1052 For example, packages could exist for the i586 or
1053 qemux86 architectures.
1054 </para></listitem>
1055 </itemizedlist>
1056 </para>
1057
1058 <para>
1059 BitBake uses the
1060 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_*</filename></ulink>
1061 tasks to generate packages and place them into the package
1062 holding area (e.g. <filename>do_package_write_ipk</filename>
1063 for IPK packages).
1064 See the
1065 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_deb</filename></ulink>",
1066 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_ipk'><filename>do_package_write_ipk</filename></ulink>",
1067 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_rpm'><filename>do_package_write_rpm</filename></ulink>",
1068 and
1069 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_tar'><filename>do_package_write_tar</filename></ulink>"
1070 sections in the Yocto Project Reference Manual
1071 for additional information.
1072 As an example, consider a scenario where an IPK packaging
1073 manager is being used and package architecture support for
1074 both i586 and qemux86 exist.
1075 Packages for the i586 architecture are placed in
1076 <filename>build/tmp/deploy/ipk/i586</filename>, while packages
1077 for the qemux86 architecture are placed in
1078 <filename>build/tmp/deploy/ipk/qemux86</filename>.
1079 </para>
1080 </section>
1081
1082 <section id='bitbake-dev-environment'>
1083 <title>BitBake</title>
1084
1085 <para>
1086 The OpenEmbedded build system uses
1087 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
1088 to produce images and Software Development Kits (SDKs).
1089 You can see from the
1090 <link linkend='general-workflow-figure'>general workflow figure</link>,
1091 the BitBake area consists of several functional areas.
1092 This section takes a closer look at each of those areas.
1093 <note>
1094 Separate documentation exists for the BitBake tool.
1095 See the
Brad Bishop19323692019-04-05 15:28:33 -04001096 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001097 for reference material on BitBake.
1098 </note>
1099 </para>
1100
1101 <section id='source-fetching-dev-environment'>
1102 <title>Source Fetching</title>
1103
1104 <para>
1105 The first stages of building a recipe are to fetch and
1106 unpack the source code:
1107 <imagedata fileref="figures/source-fetching.png" align="center" width="6.5in" depth="5in" />
1108 </para>
1109
1110 <para>
1111 The
1112 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1113 and
1114 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1115 tasks fetch the source files and unpack them into the
1116 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
1117 <note>
1118 For every local file (e.g. <filename>file://</filename>)
1119 that is part of a recipe's
1120 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1121 statement, the OpenEmbedded build system takes a
1122 checksum of the file for the recipe and inserts the
1123 checksum into the signature for the
1124 <filename>do_fetch</filename> task.
1125 If any local file has been modified, the
1126 <filename>do_fetch</filename> task and all tasks that
1127 depend on it are re-executed.
1128 </note>
1129 By default, everything is accomplished in the Build
1130 Directory, which has a defined structure.
1131 For additional general information on the Build Directory,
1132 see the
1133 "<ulink url='&YOCTO_DOCS_REF_URL;#structure-core-build'><filename>build/</filename></ulink>"
1134 section in the Yocto Project Reference Manual.
1135 </para>
1136
1137 <para>
1138 Each recipe has an area in the Build Directory where the
1139 unpacked source code resides.
1140 The
1141 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
1142 variable points to this area for a recipe's unpacked source
1143 code.
1144 The name of that directory for any given recipe is defined
1145 from several different variables.
1146 The preceding figure and the following list describe
1147 the Build Directory's hierarchy:
1148 <itemizedlist>
1149 <listitem><para>
1150 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
1151 The base directory where the OpenEmbedded build
1152 system performs all its work during the build.
1153 The default base directory is the
1154 <filename>tmp</filename> directory.
1155 </para></listitem>
1156 <listitem><para>
1157 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>:
1158 The architecture of the built package or packages.
1159 Depending on the eventual destination of the
1160 package or packages (i.e. machine architecture,
1161 <ulink url='&YOCTO_DOCS_REF_URL;#hardware-build-system-term'>build host</ulink>,
1162 SDK, or specific machine),
1163 <filename>PACKAGE_ARCH</filename> varies.
1164 See the variable's description for details.
1165 </para></listitem>
1166 <listitem><para>
1167 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_OS'><filename>TARGET_OS</filename></ulink>:
1168 The operating system of the target device.
1169 A typical value would be "linux" (e.g.
1170 "qemux86-poky-linux").
1171 </para></listitem>
1172 <listitem><para>
1173 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
1174 The name of the recipe used to build the package.
1175 This variable can have multiple meanings.
1176 However, when used in the context of input files,
1177 <filename>PN</filename> represents the the name
1178 of the recipe.
1179 </para></listitem>
1180 <listitem><para>
1181 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>:
1182 The location where the OpenEmbedded build system
1183 builds a recipe (i.e. does the work to create the
1184 package).
1185 <itemizedlist>
1186 <listitem><para>
1187 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
1188 The version of the recipe used to build the
1189 package.
1190 </para></listitem>
1191 <listitem><para>
1192 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
1193 The revision of the recipe used to build the
1194 package.
1195 </para></listitem>
1196 </itemizedlist>
1197 </para></listitem>
1198 <listitem><para>
1199 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>:
1200 Contains the unpacked source files for a given
1201 recipe.
1202 <itemizedlist>
1203 <listitem><para>
1204 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>:
1205 The name of the recipe used to build the
1206 package.
1207 The <filename>BPN</filename> variable is
1208 a version of the <filename>PN</filename>
1209 variable but with common prefixes and
1210 suffixes removed.
1211 </para></listitem>
1212 <listitem><para>
1213 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
1214 The version of the recipe used to build the
1215 package.
1216 </para></listitem>
1217 </itemizedlist>
1218 </para></listitem>
1219 </itemizedlist>
1220 <note>
1221 In the previous figure, notice that two sample
1222 hierarchies exist: one based on package architecture (i.e.
1223 <filename>PACKAGE_ARCH</filename>) and one based on a
1224 machine (i.e. <filename>MACHINE</filename>).
1225 The underlying structures are identical.
1226 The differentiator being what the OpenEmbedded build
1227 system is using as a build target (e.g. general
1228 architecture, a build host, an SDK, or a specific
1229 machine).
1230 </note>
1231 </para>
1232 </section>
1233
1234 <section id='patching-dev-environment'>
1235 <title>Patching</title>
1236
1237 <para>
1238 Once source code is fetched and unpacked, BitBake locates
1239 patch files and applies them to the source files:
1240 <imagedata fileref="figures/patching.png" align="center" width="7in" depth="6in" />
1241 </para>
1242
1243 <para>
1244 The
1245 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1246 task uses a recipe's
1247 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1248 statements and the
1249 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
1250 variable to locate applicable patch files.
1251 </para>
1252
1253 <para>
1254 Default processing for patch files assumes the files have
1255 either <filename>*.patch</filename> or
1256 <filename>*.diff</filename> file types.
1257 You can use <filename>SRC_URI</filename> parameters to
1258 change the way the build system recognizes patch files.
1259 See the
1260 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1261 task for more information.
1262 </para>
1263
1264 <para>
1265 BitBake finds and applies multiple patches for a single
1266 recipe in the order in which it locates the patches.
1267 The <filename>FILESPATH</filename> variable defines the
1268 default set of directories that the build system uses to
1269 search for patch files.
1270 Once found, patches are applied to the recipe's source
1271 files, which are located in the
1272 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
1273 directory.
1274 </para>
1275
1276 <para>
1277 For more information on how the source directories are
1278 created, see the
1279 "<link linkend='source-fetching-dev-environment'>Source Fetching</link>"
1280 section.
1281 For more information on how to create patches and how the
1282 build system processes patches, see the
1283 "<ulink url='&YOCTO_DOCS_DEV_URL;#new-recipe-patching-code'>Patching Code</ulink>"
1284 section in the Yocto Project Development Tasks Manual.
1285 You can also see the
1286 "<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>"
1287 section in the Yocto Project Application Development and
1288 the Extensible Software Development Kit (SDK) manual and
1289 the
1290 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</ulink>"
1291 section in the Yocto Project Linux Kernel Development
1292 Manual.
1293 </para>
1294 </section>
1295
1296 <section id='configuration-compilation-and-staging-dev-environment'>
1297 <title>Configuration, Compilation, and Staging</title>
1298
1299 <para>
1300 After source code is patched, BitBake executes tasks that
1301 configure and compile the source code.
1302 Once compilation occurs, the files are copied to a holding
1303 area (staged) in preparation for packaging:
1304 <imagedata fileref="figures/configuration-compile-autoreconf.png" align="center" width="7in" depth="5in" />
1305 </para>
1306
1307 <para>
1308 This step in the build process consists of the following
1309 tasks:
1310 <itemizedlist>
1311 <listitem><para>
1312 <emphasis><ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-prepare_recipe_sysroot'><filename>do_prepare_recipe_sysroot</filename></ulink></emphasis>:
1313 This task sets up the two sysroots in
1314 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
1315 (i.e. <filename>recipe-sysroot</filename> and
1316 <filename>recipe-sysroot-native</filename>) so that
1317 during the packaging phase the sysroots can contain
1318 the contents of the
1319 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
1320 tasks of the recipes on which the recipe
1321 containing the tasks depends.
1322 A sysroot exists for both the target and for the
1323 native binaries, which run on the host system.
1324 </para></listitem>
1325 <listitem><para>
1326 <emphasis><filename>do_configure</filename></emphasis>:
1327 This task configures the source by enabling and
1328 disabling any build-time and configuration options
1329 for the software being built.
1330 Configurations can come from the recipe itself as
1331 well as from an inherited class.
1332 Additionally, the software itself might configure
1333 itself depending on the target for which it is
1334 being built.</para>
1335
1336 <para>The configurations handled by the
1337 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
1338 task are specific to configurations for the source
1339 code being built by the recipe.</para>
1340
1341 <para>If you are using the
1342 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
1343 class, you can add additional configuration options
1344 by using the
1345 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
1346 or
1347 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
1348 variables.
1349 For information on how this variable works within
1350 that class, see the
1351 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
1352 class
1353 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/autotools.bbclass'>here</ulink>.
1354 </para></listitem>
1355 <listitem><para>
1356 <emphasis><filename>do_compile</filename></emphasis>:
1357 Once a configuration task has been satisfied,
1358 BitBake compiles the source using the
1359 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
1360 task.
1361 Compilation occurs in the directory pointed to by
1362 the
1363 <ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink>
1364 variable.
1365 Realize that the <filename>B</filename> directory
1366 is, by default, the same as the
1367 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
1368 directory.
1369 </para></listitem>
1370 <listitem><para>
1371 <emphasis><filename>do_install</filename></emphasis>:
1372 After compilation completes, BitBake executes the
1373 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1374 task.
1375 This task copies files from the
1376 <filename>B</filename> directory and places them
1377 in a holding area pointed to by the
1378 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
1379 variable.
1380 Packaging occurs later using files from this
1381 holding directory.
1382 </para></listitem>
1383 </itemizedlist>
1384 </para>
1385 </section>
1386
1387 <section id='package-splitting-dev-environment'>
1388 <title>Package Splitting</title>
1389
1390 <para>
1391 After source code is configured, compiled, and staged, the
1392 build system analyzes the results and splits the output
1393 into packages:
1394 <imagedata fileref="figures/analysis-for-package-splitting.png" align="center" width="7in" depth="7in" />
1395 </para>
1396
1397 <para>
1398 The
1399 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
1400 and
1401 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-packagedata'><filename>do_packagedata</filename></ulink>
1402 tasks combine to analyze the files found in the
1403 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
1404 directory and split them into subsets based on available
1405 packages and files.
1406 Analysis involves the following as well as other items:
1407 splitting out debugging symbols, looking at shared library
1408 dependencies between packages, and looking at package
1409 relationships.
1410 </para>
1411
1412 <para>
1413 The <filename>do_packagedata</filename> task creates
1414 package metadata based on the analysis such that the
1415 build system can generate the final packages.
1416 The
1417 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
1418 task stages (copies) a subset of the files installed by
1419 the
1420 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1421 task into the appropriate sysroot.
1422 Working, staged, and intermediate results of the analysis
1423 and package splitting process use several areas:
1424 <itemizedlist>
1425 <listitem><para>
1426 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGD'><filename>PKGD</filename></ulink>:
1427 The destination directory
1428 (i.e. <filename>package</filename>) for packages
1429 before they are split into individual packages.
1430 </para></listitem>
1431 <listitem><para>
1432 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDESTWORK'><filename>PKGDESTWORK</filename></ulink>:
1433 A temporary work area (i.e.
1434 <filename>pkgdata</filename>) used by the
1435 <filename>do_package</filename> task to save
1436 package metadata.
1437 </para></listitem>
1438 <listitem><para>
1439 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDEST'><filename>PKGDEST</filename></ulink>:
1440 The parent directory (i.e.
1441 <filename>packages-split</filename>) for packages
1442 after they have been split.
1443 </para></listitem>
1444 <listitem><para>
1445 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>:
1446 A shared, global-state directory that holds
1447 packaging metadata generated during the packaging
1448 process.
1449 The packaging process copies metadata from
1450 <filename>PKGDESTWORK</filename> to the
1451 <filename>PKGDATA_DIR</filename> area where it
1452 becomes globally available.
1453 </para></listitem>
1454 <listitem><para>
1455 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR_HOST'><filename>STAGING_DIR_HOST</filename></ulink>:
1456 The path for the sysroot for the system on which
1457 a component is built to run (i.e.
1458 <filename>recipe-sysroot</filename>).
1459 </para></listitem>
1460 <listitem><para>
1461 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR_NATIVE'><filename>STAGING_DIR_NATIVE</filename></ulink>:
1462 The path for the sysroot used when building
1463 components for the build host (i.e.
1464 <filename>recipe-sysroot-native</filename>).
1465 </para></listitem>
1466 <listitem><para>
1467 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR_TARGET'><filename>STAGING_DIR_TARGET</filename></ulink>:
1468 The path for the sysroot used when a component that
1469 is built to execute on a system and it generates
1470 code for yet another machine (e.g. cross-canadian
1471 recipes).
1472 </para></listitem>
1473 </itemizedlist>
1474 The
1475 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
1476 variable defines the files that go into each package in
1477 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>.
1478 If you want details on how this is accomplished, you can
1479 look at
1480 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/package.bbclass'><filename>package.bbclass</filename></ulink>.
1481 </para>
1482
1483 <para>
1484 Depending on the type of packages being created (RPM, DEB,
1485 or IPK), the
1486 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_*</filename></ulink>
1487 task creates the actual packages and places them in the
1488 Package Feed area, which is
1489 <filename>${TMPDIR}/deploy</filename>.
1490 You can see the
1491 "<link linkend='package-feeds-dev-environment'>Package Feeds</link>"
1492 section for more detail on that part of the build process.
1493 <note>
1494 Support for creating feeds directly from the
1495 <filename>deploy/*</filename> directories does not
1496 exist.
1497 Creating such feeds usually requires some kind of feed
1498 maintenance mechanism that would upload the new
1499 packages into an official package feed (e.g. the
1500 Ångström distribution).
1501 This functionality is highly distribution-specific
1502 and thus is not provided out of the box.
1503 </note>
1504 </para>
1505 </section>
1506
1507 <section id='image-generation-dev-environment'>
1508 <title>Image Generation</title>
1509
1510 <para>
1511 Once packages are split and stored in the Package Feeds
1512 area, the build system uses BitBake to generate the root
1513 filesystem image:
1514 <imagedata fileref="figures/image-generation.png" align="center" width="7.5in" depth="7.5in" />
1515 </para>
1516
1517 <para>
1518 The image generation process consists of several stages and
1519 depends on several tasks and variables.
1520 The
1521 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
1522 task creates the root filesystem (file and directory
1523 structure) for an image.
1524 This task uses several key variables to help create the
1525 list of packages to actually install:
1526 <itemizedlist>
1527 <listitem><para>
1528 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
1529 Lists out the base set of packages from which to
1530 install from the Package Feeds area.
1531 </para></listitem>
1532 <listitem><para>
1533 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
1534 Specifies packages that should not be installed
1535 into the image.
1536 </para></listitem>
1537 <listitem><para>
1538 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
1539 Specifies features to include in the image.
1540 Most of these features map to additional packages
1541 for installation.
1542 </para></listitem>
1543 <listitem><para>
1544 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>:
1545 Specifies the package backend (e.g. RPM, DEB, or
1546 IPK) to use and consequently helps determine where
1547 to locate packages within the Package Feeds area.
1548 </para></listitem>
1549 <listitem><para>
1550 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_LINGUAS'><filename>IMAGE_LINGUAS</filename></ulink>:
1551 Determines the language(s) for which additional
1552 language support packages are installed.
1553 </para></listitem>
1554 <listitem><para>
1555 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>:
1556 The final list of packages passed to the package
1557 manager for installation into the image.
1558 </para></listitem>
1559 </itemizedlist>
1560 </para>
1561
1562 <para>
1563 With
1564 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_ROOTFS'><filename>IMAGE_ROOTFS</filename></ulink>
1565 pointing to the location of the filesystem under
1566 construction and the <filename>PACKAGE_INSTALL</filename>
1567 variable providing the final list of packages to install,
1568 the root file system is created.
1569 </para>
1570
1571 <para>
1572 Package installation is under control of the package
1573 manager (e.g. dnf/rpm, opkg, or apt/dpkg) regardless of
1574 whether or not package management is enabled for the
1575 target.
1576 At the end of the process, if package management is not
1577 enabled for the target, the package manager's data files
1578 are deleted from the root filesystem.
1579 As part of the final stage of package installation,
1580 post installation scripts that are part of the packages
1581 are run.
1582 Any scripts that fail to run on the build host are run on
1583 the target when the target system is first booted.
1584 If you are using a
1585 <ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-read-only-root-filesystem'>read-only root filesystem</ulink>,
1586 all the post installation scripts must succeed on the
1587 build host during the package installation phase since the
1588 root filesystem on the target is read-only.
1589 </para>
1590
1591 <para>
1592 The final stages of the <filename>do_rootfs</filename> task
1593 handle post processing.
1594 Post processing includes creation of a manifest file and
1595 optimizations.
1596 </para>
1597
1598 <para>
1599 The manifest file (<filename>.manifest</filename>) resides
1600 in the same directory as the root filesystem image.
1601 This file lists out, line-by-line, the installed packages.
1602 The manifest file is useful for the
1603 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
1604 class, for example, to determine whether or not to run
1605 specific tests.
1606 See the
1607 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_MANIFEST'><filename>IMAGE_MANIFEST</filename></ulink>
1608 variable for additional information.
1609 </para>
1610
1611 <para>
1612 Optimizing processes that are run across the image include
1613 <filename>mklibs</filename>, <filename>prelink</filename>,
1614 and any other post-processing commands as defined by the
1615 <ulink url='&YOCTO_DOCS_REF_URL;#var-ROOTFS_POSTPROCESS_COMMAND'><filename>ROOTFS_POSTPROCESS_COMMAND</filename></ulink>
1616 variable.
1617 The <filename>mklibs</filename> process optimizes the size
1618 of the libraries, while the <filename>prelink</filename>
1619 process optimizes the dynamic linking of shared libraries
1620 to reduce start up time of executables.
1621 </para>
1622
1623 <para>
1624 After the root filesystem is built, processing begins on
1625 the image through the
1626 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
1627 task.
1628 The build system runs any pre-processing commands as
1629 defined by the
1630 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_PREPROCESS_COMMAND'><filename>IMAGE_PREPROCESS_COMMAND</filename></ulink>
1631 variable.
1632 This variable specifies a list of functions to call before
1633 the build system creates the final image output files.
1634 </para>
1635
1636 <para>
1637 The build system dynamically creates
1638 <filename>do_image_*</filename> tasks as needed, based
1639 on the image types specified in the
1640 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
1641 variable.
1642 The process turns everything into an image file or a set of
1643 image files and can compress the root filesystem image to
1644 reduce the overall size of the image.
1645 The formats used for the root filesystem depend on the
1646 <filename>IMAGE_FSTYPES</filename> variable.
1647 Compression depends on whether the formats support
1648 compression.
1649 </para>
1650
1651 <para>
1652 As an example, a dynamically created task when creating a
1653 particular image <replaceable>type</replaceable> would
1654 take the following form:
1655 <literallayout class='monospaced'>
1656 do_image_<replaceable>type</replaceable>
1657 </literallayout>
1658 So, if the <replaceable>type</replaceable> as specified by
1659 the <filename>IMAGE_FSTYPES</filename> were
1660 <filename>ext4</filename>, the dynamically generated task
1661 would be as follows:
1662 <literallayout class='monospaced'>
1663 do_image_ext4
1664 </literallayout>
1665 </para>
1666
1667 <para>
1668 The final task involved in image creation is the
1669 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image-complete'><filename>do_image_complete</filename></ulink>
1670 task.
1671 This task completes the image by applying any image
1672 post processing as defined through the
1673 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_POSTPROCESS_COMMAND'><filename>IMAGE_POSTPROCESS_COMMAND</filename></ulink>
1674 variable.
1675 The variable specifies a list of functions to call once the
1676 build system has created the final image output files.
1677 <note>
1678 The entire image generation process is run under
1679 <link linkend='fakeroot-and-pseudo'>Pseudo</link>.
1680 Running under Pseudo ensures that the files in the
1681 root filesystem have correct ownership.
1682 </note>
1683 </para>
1684 </section>
1685
1686 <section id='sdk-generation-dev-environment'>
1687 <title>SDK Generation</title>
1688
1689 <para>
1690 The OpenEmbedded build system uses BitBake to generate the
1691 Software Development Kit (SDK) installer scripts for both
1692 the standard SDK and the extensible SDK (eSDK):
1693 </para>
1694
1695 <para>
1696 <imagedata fileref="figures/sdk-generation.png" width="9in" align="center" />
1697 <note>
1698 For more information on the cross-development toolchain
1699 generation, see the
1700 "<link linkend='cross-development-toolchain-generation'>Cross-Development Toolchain Generation</link>"
1701 section.
1702 For information on advantages gained when building a
1703 cross-development toolchain using the
1704 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sdk'><filename>do_populate_sdk</filename></ulink>
1705 task, see the
1706 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-building-an-sdk-installer'>Building an SDK Installer</ulink>"
1707 section in the Yocto Project Application Development
1708 and the Extensible Software Development Kit (eSDK)
1709 manual.
1710 </note>
1711 </para>
1712
1713 <para>
1714 Like image generation, the SDK script process consists of
1715 several stages and depends on many variables.
1716 The
1717 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sdk'><filename>do_populate_sdk</filename></ulink>
1718 and
1719 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sdk_ext'><filename>do_populate_sdk_ext</filename></ulink>
1720 tasks use these key variables to help create the list of
1721 packages to actually install.
1722 For information on the variables listed in the figure,
1723 see the
1724 "<link linkend='sdk-dev-environment'>Application Development SDK</link>"
1725 section.
1726 </para>
1727
1728 <para>
1729 The <filename>do_populate_sdk</filename> task helps create
1730 the standard SDK and handles two parts: a target part and a
1731 host part.
1732 The target part is the part built for the target hardware
1733 and includes libraries and headers.
1734 The host part is the part of the SDK that runs on the
1735 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>.
1736 </para>
1737
1738 <para>
1739 The <filename>do_populate_sdk_ext</filename> task helps
1740 create the extensible SDK and handles host and target parts
1741 differently than its counter part does for the standard SDK.
1742 For the extensible SDK, the task encapsulates the build
1743 system, which includes everything needed (host and target)
1744 for the SDK.
1745 </para>
1746
1747 <para>
1748 Regardless of the type of SDK being constructed, the
1749 tasks perform some cleanup after which a cross-development
1750 environment setup script and any needed configuration files
1751 are created.
1752 The final output is the Cross-development
1753 toolchain installation script (<filename>.sh</filename>
1754 file), which includes the environment setup script.
1755 </para>
1756 </section>
1757
1758 <section id='stamp-files-and-the-rerunning-of-tasks'>
1759 <title>Stamp Files and the Rerunning of Tasks</title>
1760
1761 <para>
1762 For each task that completes successfully, BitBake writes a
1763 stamp file into the
1764 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
1765 directory.
1766 The beginning of the stamp file's filename is determined
1767 by the
1768 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMP'><filename>STAMP</filename></ulink>
1769 variable, and the end of the name consists of the task's
1770 name and current
1771 <link linkend='overview-checksums'>input checksum</link>.
1772 <note>
1773 This naming scheme assumes that
1774 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_SIGNATURE_HANDLER'><filename>BB_SIGNATURE_HANDLER</filename></ulink>
1775 is "OEBasicHash", which is almost always the case in
1776 current OpenEmbedded.
1777 </note>
1778 To determine if a task needs to be rerun, BitBake checks
1779 if a stamp file with a matching input checksum exists
1780 for the task.
1781 If such a stamp file exists, the task's output is
1782 assumed to exist and still be valid.
1783 If the file does not exist, the task is rerun.
1784 <note>
1785 <para>The stamp mechanism is more general than the
1786 shared state (sstate) cache mechanism described in the
1787 "<link linkend='setscene-tasks-and-shared-state'>Setscene Tasks and Shared State</link>"
1788 section.
1789 BitBake avoids rerunning any task that has a valid
1790 stamp file, not just tasks that can be accelerated
1791 through the sstate cache.</para>
1792
1793 <para>However, you should realize that stamp files only
1794 serve as a marker that some work has been done and that
1795 these files do not record task output.
1796 The actual task output would usually be somewhere in
1797 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
1798 (e.g. in some recipe's
1799 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.)
1800 What the sstate cache mechanism adds is a way to cache
1801 task output that can then be shared between build
1802 machines.</para>
1803 </note>
1804 Since <filename>STAMPS_DIR</filename> is usually a
1805 subdirectory of <filename>TMPDIR</filename>, removing
1806 <filename>TMPDIR</filename> will also remove
1807 <filename>STAMPS_DIR</filename>, which means tasks will
1808 properly be rerun to repopulate
1809 <filename>TMPDIR</filename>.
1810 </para>
1811
1812 <para>
1813 If you want some task to always be considered "out of
1814 date", you can mark it with the
1815 <ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink>
1816 varflag.
1817 If some other task depends on such a task, then that
1818 task will also always be considered out of date, which
1819 might not be what you want.
1820 </para>
1821
1822 <para>
1823 For details on how to view information about a task's
1824 signature, see the
1825 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</ulink>"
1826 section in the Yocto Project Development Tasks Manual.
1827 </para>
1828 </section>
1829
1830 <section id='setscene-tasks-and-shared-state'>
1831 <title>Setscene Tasks and Shared State</title>
1832
1833 <para>
1834 The description of tasks so far assumes that BitBake needs
1835 to build everything and no available prebuilt objects
1836 exist.
1837 BitBake does support skipping tasks if prebuilt objects are
1838 available.
1839 These objects are usually made available in the form of a
1840 shared state (sstate) cache.
1841 <note>
1842 For information on variables affecting sstate, see the
1843 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
1844 and
1845 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_MIRRORS'><filename>SSTATE_MIRRORS</filename></ulink>
1846 variables.
1847 </note>
1848 </para>
1849
1850 <para>
1851 The idea of a setscene task (i.e
1852 <filename>do_</filename><replaceable>taskname</replaceable><filename>_setscene</filename>)
1853 is a version of the task where
1854 instead of building something, BitBake can skip to the end
1855 result and simply place a set of files into specific
1856 locations as needed.
1857 In some cases, it makes sense to have a setscene task
1858 variant (e.g. generating package files in the
1859 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write_*</filename></ulink>
1860 task).
1861 In other cases, it does not make sense (e.g. a
1862 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1863 task or a
1864 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1865 task) since the work involved would be equal to or greater
1866 than the underlying task.
1867 </para>
1868
1869 <para>
1870 In the build system, the common tasks that have setscene
1871 variants are
1872 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>,
1873 <filename>do_package_write_*</filename>,
1874 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-deploy'><filename>do_deploy</filename></ulink>,
1875 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-packagedata'><filename>do_packagedata</filename></ulink>,
1876 and
1877 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>.
1878 Notice that these tasks represent most of the tasks whose
1879 output is an end result.
1880 </para>
1881
1882 <para>
1883 The build system has knowledge of the relationship between
1884 these tasks and other preceding tasks.
1885 For example, if BitBake runs
1886 <filename>do_populate_sysroot_setscene</filename> for
1887 something, it does not make sense to run any of the
1888 <filename>do_fetch</filename>,
1889 <filename>do_unpack</filename>,
1890 <filename>do_patch</filename>,
1891 <filename>do_configure</filename>,
1892 <filename>do_compile</filename>, and
1893 <filename>do_install</filename> tasks.
1894 However, if <filename>do_package</filename> needs to be
1895 run, BitBake needs to run those other tasks.
1896 </para>
1897
1898 <para>
1899 It becomes more complicated if everything can come
1900 from an sstate cache because some objects are simply
1901 not required at all.
1902 For example, you do not need a compiler or native tools,
1903 such as quilt, if nothing exists to compile or patch.
1904 If the <filename>do_package_write_*</filename> packages
1905 are available from sstate, BitBake does not need the
1906 <filename>do_package</filename> task data.
1907 </para>
1908
1909 <para>
1910 To handle all these complexities, BitBake runs in two
1911 phases.
1912 The first is the "setscene" stage.
1913 During this stage, BitBake first checks the sstate cache
1914 for any targets it is planning to build.
1915 BitBake does a fast check to see if the object exists
1916 rather than a complete download.
1917 If nothing exists, the second phase, which is the setscene
1918 stage, completes and the main build proceeds.
1919 </para>
1920
1921 <para>
1922 If objects are found in the sstate cache, the build system
1923 works backwards from the end targets specified by the user.
1924 For example, if an image is being built, the build system
1925 first looks for the packages needed for that image and the
1926 tools needed to construct an image.
1927 If those are available, the compiler is not needed.
1928 Thus, the compiler is not even downloaded.
1929 If something was found to be unavailable, or the
1930 download or setscene task fails, the build system then
1931 tries to install dependencies, such as the compiler, from
1932 the cache.
1933 </para>
1934
1935 <para>
1936 The availability of objects in the sstate cache is
1937 handled by the function specified by the
1938 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHCHECK_FUNCTION'><filename>BB_HASHCHECK_FUNCTION</filename></ulink>
1939 variable and returns a list of available objects.
1940 The function specified by the
1941 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_SETSCENE_DEPVALID'><filename>BB_SETSCENE_DEPVALID</filename></ulink>
1942 variable is the function that determines whether a given
1943 dependency needs to be followed, and whether for any given
1944 relationship the function needs to be passed.
1945 The function returns a True or False value.
1946 </para>
1947 </section>
1948 </section>
1949
1950 <section id='images-dev-environment'>
1951 <title>Images</title>
1952
1953 <para>
1954 The images produced by the build system are compressed forms
1955 of the root filesystem and are ready to boot on a target
1956 device.
1957 You can see from the
1958 <link linkend='general-workflow-figure'>general workflow figure</link>
1959 that BitBake output, in part, consists of images.
1960 This section takes a closer look at this output:
1961 <imagedata fileref="figures/images.png" align="center" width="5.5in" depth="5.5in" />
1962 </para>
1963
1964 <note>
1965 For a list of example images that the Yocto Project provides,
1966 see the
1967 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1968 chapter in the Yocto Project Reference Manual.
1969 </note>
1970
1971 <para>
1972 The build process writes images out to the
1973 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
1974 inside the
1975 <filename>tmp/deploy/images/<replaceable>machine</replaceable>/</filename>
1976 folder as shown in the figure.
1977 This folder contains any files expected to be loaded on the
1978 target device.
1979 The
1980 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>
1981 variable points to the <filename>deploy</filename> directory,
1982 while the
1983 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR_IMAGE'><filename>DEPLOY_DIR_IMAGE</filename></ulink>
1984 variable points to the appropriate directory containing images
1985 for the current configuration.
1986 <itemizedlist>
1987 <listitem><para>
1988 <replaceable>kernel-image</replaceable>:
1989 A kernel binary file.
1990 The
1991 <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'><filename>KERNEL_IMAGETYPE</filename></ulink>
1992 variable determines the naming scheme for the
1993 kernel image file.
1994 Depending on this variable, the file could begin with
1995 a variety of naming strings.
1996 The
1997 <filename>deploy/images/</filename><replaceable>machine</replaceable>
1998 directory can contain multiple image files for the
1999 machine.
2000 </para></listitem>
2001 <listitem><para>
2002 <replaceable>root-filesystem-image</replaceable>:
2003 Root filesystems for the target device (e.g.
2004 <filename>*.ext3</filename> or
2005 <filename>*.bz2</filename> files).
2006 The
2007 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
2008 variable determines the root filesystem image type.
2009 The
2010 <filename>deploy/images/</filename><replaceable>machine</replaceable>
2011 directory can contain multiple root filesystems for the
2012 machine.
2013 </para></listitem>
2014 <listitem><para>
2015 <replaceable>kernel-modules</replaceable>:
2016 Tarballs that contain all the modules built for the
2017 kernel.
2018 Kernel module tarballs exist for legacy purposes and
2019 can be suppressed by setting the
2020 <ulink url='&YOCTO_DOCS_REF_URL;#var-MODULE_TARBALL_DEPLOY'><filename>MODULE_TARBALL_DEPLOY</filename></ulink>
2021 variable to "0".
2022 The
2023 <filename>deploy/images/</filename><replaceable>machine</replaceable>
2024 directory can contain multiple kernel module tarballs
2025 for the machine.
2026 </para></listitem>
2027 <listitem><para>
2028 <replaceable>bootloaders</replaceable>:
2029 If applicable to the target machine, bootloaders
2030 supporting the image.
2031 The <filename>deploy/images/</filename><replaceable>machine</replaceable>
2032 directory can contain multiple bootloaders for the
2033 machine.
2034 </para></listitem>
2035 <listitem><para>
2036 <replaceable>symlinks</replaceable>:
2037 The
2038 <filename>deploy/images/</filename><replaceable>machine</replaceable>
2039 folder contains a symbolic link that points to the
2040 most recently built file for each machine.
2041 These links might be useful for external scripts that
2042 need to obtain the latest version of each file.
2043 </para></listitem>
2044 </itemizedlist>
2045 </para>
2046 </section>
2047
2048 <section id='sdk-dev-environment'>
2049 <title>Application Development SDK</title>
2050
2051 <para>
2052 In the
2053 <link linkend='general-workflow-figure'>general workflow figure</link>,
2054 the output labeled "Application Development SDK" represents an
2055 SDK.
2056 The SDK generation process differs depending on whether you
2057 build an extensible SDK (e.g.
2058 <filename>bitbake -c populate_sdk_ext</filename> <replaceable>imagename</replaceable>)
2059 or a standard SDK (e.g.
2060 <filename>bitbake -c populate_sdk</filename> <replaceable>imagename</replaceable>).
2061 This section takes a closer look at this output:
2062 <imagedata fileref="figures/sdk.png" align="center" width="9in" depth="7.25in" />
2063 </para>
2064
2065 <para>
2066 The specific form of this output is a set of files that
2067 includes a self-extracting SDK installer
2068 (<filename>*.sh</filename>), host and target manifest files,
2069 and files used for SDK testing.
2070 When the SDK installer file is run, it installs the SDK.
2071 The SDK consists of a cross-development toolchain, a set of
2072 libraries and headers, and an SDK environment setup script.
2073 Running this installer essentially sets up your
2074 cross-development environment.
2075 You can think of the cross-toolchain as the "host"
2076 part because it runs on the SDK machine.
2077 You can think of the libraries and headers as the "target"
2078 part because they are built for the target hardware.
2079 The environment setup script is added so that you can
2080 initialize the environment before using the tools.
2081 </para>
2082
2083 <note><title>Notes</title>
2084 <itemizedlist>
2085 <listitem><para>
2086 The Yocto Project supports several methods by which
2087 you can set up this cross-development environment.
2088 These methods include downloading pre-built SDK
2089 installers or building and installing your own SDK
2090 installer.
2091 </para></listitem>
2092 <listitem><para>
2093 For background information on cross-development
2094 toolchains in the Yocto Project development
2095 environment, see the
2096 "<link linkend='cross-development-toolchain-generation'>Cross-Development Toolchain Generation</link>"
2097 section.
2098 </para></listitem>
2099 <listitem><para>
2100 For information on setting up a cross-development
2101 environment, see the
2102 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
2103 manual.
2104 </para></listitem>
2105 </itemizedlist>
2106 </note>
2107
2108 <para>
2109 All the output files for an SDK are written to the
2110 <filename>deploy/sdk</filename> folder inside the
2111 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
2112 as shown in the previous figure.
2113 Depending on the type of SDK, several variables exist that help
2114 configure these files.
2115 The following list shows the variables associated with an
2116 extensible SDK:
2117 <itemizedlist>
2118 <listitem><para>
2119 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>:
2120 Points to the <filename>deploy</filename> directory.
2121 </para></listitem>
2122 <listitem><para>
2123 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_EXT_TYPE'><filename>SDK_EXT_TYPE</filename></ulink>:
2124 Controls whether or not shared state artifacts are
2125 copied into the extensible SDK.
2126 By default, all required shared state artifacts are
2127 copied into the SDK.
2128 </para></listitem>
2129 <listitem><para>
2130 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_INCLUDE_PKGDATA'><filename>SDK_INCLUDE_PKGDATA</filename></ulink>:
2131 Specifies whether or not packagedata is included in the
2132 extensible SDK for all recipes in the "world" target.
2133 </para></listitem>
2134 <listitem><para>
2135 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_INCLUDE_TOOLCHAIN'><filename>SDK_INCLUDE_TOOLCHAIN</filename></ulink>:
2136 Specifies whether or not the toolchain is included
2137 when building the extensible SDK.
2138 </para></listitem>
2139 <listitem><para>
2140 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_LOCAL_CONF_WHITELIST'><filename>SDK_LOCAL_CONF_WHITELIST</filename></ulink>:
2141 A list of variables allowed through from the build
2142 system configuration into the extensible SDK
2143 configuration.
2144 </para></listitem>
2145 <listitem><para>
2146 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_LOCAL_CONF_BLACKLIST'><filename>SDK_LOCAL_CONF_BLACKLIST</filename></ulink>:
2147 A list of variables not allowed through from the build
2148 system configuration into the extensible SDK
2149 configuration.
2150 </para></listitem>
2151 <listitem><para>
2152 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_INHERIT_BLACKLIST'><filename>SDK_INHERIT_BLACKLIST</filename></ulink>:
2153 A list of classes to remove from the
2154 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHERIT'><filename>INHERIT</filename></ulink>
2155 value globally within the extensible SDK configuration.
2156 </para></listitem>
2157 </itemizedlist>
2158 This next list, shows the variables associated with a standard
2159 SDK:
2160 <itemizedlist>
2161 <listitem><para>
2162 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPLOY_DIR'><filename>DEPLOY_DIR</filename></ulink>:
2163 Points to the <filename>deploy</filename> directory.
2164 </para></listitem>
2165 <listitem><para>
2166 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>:
2167 Specifies the architecture of the machine on which the
2168 cross-development tools are run to create packages for
2169 the target hardware.
2170 </para></listitem>
2171 <listitem><para>
2172 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKIMAGE_FEATURES'><filename>SDKIMAGE_FEATURES</filename></ulink>:
2173 Lists the features to include in the "target" part
2174 of the SDK.
2175 </para></listitem>
2176 <listitem><para>
2177 <ulink url='&YOCTO_DOCS_REF_URL;#var-TOOLCHAIN_HOST_TASK'><filename>TOOLCHAIN_HOST_TASK</filename></ulink>:
2178 Lists packages that make up the host part of the SDK
2179 (i.e. the part that runs on the
2180 <filename>SDKMACHINE</filename>).
2181 When you use
2182 <filename>bitbake -c populate_sdk <replaceable>imagename</replaceable></filename>
2183 to create the SDK, a set of default packages apply.
2184 This variable allows you to add more packages.
2185 </para></listitem>
2186 <listitem><para>
2187 <ulink url='&YOCTO_DOCS_REF_URL;#var-TOOLCHAIN_TARGET_TASK'><filename>TOOLCHAIN_TARGET_TASK</filename></ulink>:
2188 Lists packages that make up the target part of the SDK
2189 (i.e. the part built for the target hardware).
2190 </para></listitem>
2191 <listitem><para>
2192 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKPATH'><filename>SDKPATH</filename></ulink>:
2193 Defines the default SDK installation path offered by
2194 the installation script.
2195 </para></listitem>
2196 <listitem><para>
2197 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_HOST_MANIFEST'><filename>SDK_HOST_MANIFEST</filename></ulink>:
2198 Lists all the installed packages that make up the host
2199 part of the SDK.
2200 This variable also plays a minor role for extensible
2201 SDK development as well.
2202 However, it is mainly used for the standard SDK.
2203 </para></listitem>
2204 <listitem><para>
2205 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_TARGET_MANIFEST'><filename>SDK_TARGET_MANIFEST</filename></ulink>:
2206 Lists all the installed packages that make up the
2207 target part of the SDK.
2208 This variable also plays a minor role for extensible
2209 SDK development as well.
2210 However, it is mainly used for the standard SDK.
2211 </para></listitem>
2212 </itemizedlist>
2213 </para>
2214 </section>
2215 </section>
2216
2217 <section id="cross-development-toolchain-generation">
2218 <title>Cross-Development Toolchain Generation</title>
2219
2220 <para>
2221 The Yocto Project does most of the work for you when it comes to
2222 creating
2223 <ulink url='&YOCTO_DOCS_REF_URL;#cross-development-toolchain'>cross-development toolchains</ulink>.
2224 This section provides some technical background on how
2225 cross-development toolchains are created and used.
2226 For more information on toolchains, you can also see the
2227 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
2228 manual.
2229 </para>
2230
2231 <para>
2232 In the Yocto Project development environment, cross-development
2233 toolchains are used to build images and applications that run
2234 on the target hardware.
2235 With just a few commands, the OpenEmbedded build system creates
2236 these necessary toolchains for you.
2237 </para>
2238
2239 <para>
2240 The following figure shows a high-level build environment regarding
2241 toolchain construction and use.
2242 </para>
2243
2244 <para>
2245 <imagedata fileref="figures/cross-development-toolchains.png" width="8in" depth="6in" align="center" />
2246 </para>
2247
2248 <para>
2249 Most of the work occurs on the Build Host.
2250 This is the machine used to build images and generally work within
2251 the the Yocto Project environment.
2252 When you run
2253 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
2254 to create an image, the OpenEmbedded build system
2255 uses the host <filename>gcc</filename> compiler to bootstrap a
2256 cross-compiler named <filename>gcc-cross</filename>.
2257 The <filename>gcc-cross</filename> compiler is what BitBake uses to
2258 compile source files when creating the target image.
2259 You can think of <filename>gcc-cross</filename> simply as an
2260 automatically generated cross-compiler that is used internally
2261 within BitBake only.
2262 <note>
2263 The extensible SDK does not use
2264 <filename>gcc-cross-canadian</filename> since this SDK
2265 ships a copy of the OpenEmbedded build system and the sysroot
2266 within it contains <filename>gcc-cross</filename>.
2267 </note>
2268 </para>
2269
2270 <para>
2271 The chain of events that occurs when <filename>gcc-cross</filename> is
2272 bootstrapped is as follows:
2273 <literallayout class='monospaced'>
2274 gcc -> binutils-cross -> gcc-cross-initial -> linux-libc-headers -> glibc-initial -> glibc -> gcc-cross -> gcc-runtime
2275 </literallayout>
2276 <itemizedlist>
2277 <listitem><para>
2278 <filename>gcc</filename>:
2279 The build host's GNU Compiler Collection (GCC).
2280 </para></listitem>
2281 <listitem><para>
2282 <filename>binutils-cross</filename>:
2283 The bare minimum binary utilities needed in order to run
2284 the <filename>gcc-cross-initial</filename> phase of the
2285 bootstrap operation.
2286 </para></listitem>
2287 <listitem><para>
2288 <filename>gcc-cross-initial</filename>:
2289 An early stage of the bootstrap process for creating
2290 the cross-compiler.
2291 This stage builds enough of the <filename>gcc-cross</filename>,
2292 the C library, and other pieces needed to finish building the
2293 final cross-compiler in later stages.
2294 This tool is a "native" package (i.e. it is designed to run on
2295 the build host).
2296 </para></listitem>
2297 <listitem><para>
2298 <filename>linux-libc-headers</filename>:
2299 Headers needed for the cross-compiler.
2300 </para></listitem>
2301 <listitem><para>
2302 <filename>glibc-initial</filename>:
2303 An initial version of the Embedded GNU C Library
2304 (GLIBC) needed to bootstrap <filename>glibc</filename>.
2305 </para></listitem>
2306 <listitem><para>
2307 <filename>glibc</filename>:
2308 The GNU C Library.
2309 </para></listitem>
2310 <listitem><para>
2311 <filename>gcc-cross</filename>:
2312 The final stage of the bootstrap process for the
2313 cross-compiler.
2314 This stage results in the actual cross-compiler that
2315 BitBake uses when it builds an image for a targeted
2316 device.
2317 <note>
2318 If you are replacing this cross compiler toolchain
2319 with a custom version, you must replace
2320 <filename>gcc-cross</filename>.
2321 </note>
2322 This tool is also a "native" package (i.e. it is
2323 designed to run on the build host).
2324 </para></listitem>
2325 <listitem><para>
2326 <filename>gcc-runtime</filename>:
2327 Runtime libraries resulting from the toolchain bootstrapping
2328 process.
2329 This tool produces a binary that consists of the
2330 runtime libraries need for the targeted device.
2331 </para></listitem>
2332 </itemizedlist>
2333 </para>
2334
2335 <para>
2336 You can use the OpenEmbedded build system to build an installer for
2337 the relocatable SDK used to develop applications.
2338 When you run the installer, it installs the toolchain, which
2339 contains the development tools (e.g.,
2340 <filename>gcc-cross-canadian</filename>,
2341 <filename>binutils-cross-canadian</filename>, and other
2342 <filename>nativesdk-*</filename> tools),
2343 which are tools native to the SDK (i.e. native to
2344 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDK_ARCH'><filename>SDK_ARCH</filename></ulink>),
2345 you need to cross-compile and test your software.
2346 The figure shows the commands you use to easily build out this
2347 toolchain.
2348 This cross-development toolchain is built to execute on the
2349 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>,
2350 which might or might not be the same
2351 machine as the Build Host.
2352 <note>
2353 If your target architecture is supported by the Yocto Project,
2354 you can take advantage of pre-built images that ship with the
2355 Yocto Project and already contain cross-development toolchain
2356 installers.
2357 </note>
2358 </para>
2359
2360 <para>
2361 Here is the bootstrap process for the relocatable toolchain:
2362 <literallayout class='monospaced'>
2363 gcc -> binutils-crosssdk -> gcc-crosssdk-initial -> linux-libc-headers ->
2364 glibc-initial -> nativesdk-glibc -> gcc-crosssdk -> gcc-cross-canadian
2365 </literallayout>
2366 <itemizedlist>
2367 <listitem><para>
2368 <filename>gcc</filename>:
2369 The build host's GNU Compiler Collection (GCC).
2370 </para></listitem>
2371 <listitem><para>
2372 <filename>binutils-crosssdk</filename>:
2373 The bare minimum binary utilities needed in order to run
2374 the <filename>gcc-crosssdk-initial</filename> phase of the
2375 bootstrap operation.
2376 </para></listitem>
2377 <listitem><para>
2378 <filename>gcc-crosssdk-initial</filename>:
2379 An early stage of the bootstrap process for creating
2380 the cross-compiler.
2381 This stage builds enough of the
2382 <filename>gcc-crosssdk</filename> and supporting pieces so that
2383 the final stage of the bootstrap process can produce the
2384 finished cross-compiler.
2385 This tool is a "native" binary that runs on the build host.
2386 </para></listitem>
2387 <listitem><para>
2388 <filename>linux-libc-headers</filename>:
2389 Headers needed for the cross-compiler.
2390 </para></listitem>
2391 <listitem><para>
2392 <filename>glibc-initial</filename>:
2393 An initial version of the Embedded GLIBC needed to bootstrap
2394 <filename>nativesdk-glibc</filename>.
2395 </para></listitem>
2396 <listitem><para>
2397 <filename>nativesdk-glibc</filename>:
2398 The Embedded GLIBC needed to bootstrap the
2399 <filename>gcc-crosssdk</filename>.
2400 </para></listitem>
2401 <listitem><para>
2402 <filename>gcc-crosssdk</filename>:
2403 The final stage of the bootstrap process for the
2404 relocatable cross-compiler.
2405 The <filename>gcc-crosssdk</filename> is a transitory
2406 compiler and never leaves the build host.
2407 Its purpose is to help in the bootstrap process to create
2408 the eventual <filename>gcc-cross-canadian</filename>
2409 compiler, which is relocatable.
2410 This tool is also a "native" package (i.e. it is
2411 designed to run on the build host).
2412 </para></listitem>
2413 <listitem><para>
2414 <filename>gcc-cross-canadian</filename>:
2415 The final relocatable cross-compiler.
2416 When run on the
2417 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKMACHINE'><filename>SDKMACHINE</filename></ulink>,
2418 this tool
2419 produces executable code that runs on the target device.
2420 Only one cross-canadian compiler is produced per architecture
2421 since they can be targeted at different processor optimizations
2422 using configurations passed to the compiler through the
2423 compile commands.
2424 This circumvents the need for multiple compilers and thus
2425 reduces the size of the toolchains.
2426 </para></listitem>
2427 </itemizedlist>
2428 </para>
2429
2430 <note>
2431 For information on advantages gained when building a
2432 cross-development toolchain installer, see the
2433 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-building-an-sdk-installer'>Building an SDK Installer</ulink>"
2434 appendix in the Yocto Project Application Development and the
2435 Extensible Software Development Kit (eSDK) manual.
2436 </note>
2437 </section>
2438
2439 <section id="shared-state-cache">
2440 <title>Shared State Cache</title>
2441
2442 <para>
2443 By design, the OpenEmbedded build system builds everything from
2444 scratch unless
2445 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
2446 can determine that parts do not need to be rebuilt.
2447 Fundamentally, building from scratch is attractive as it means all
2448 parts are built fresh and no possibility of stale data exists that
2449 can cause problems.
2450 When developers hit problems, they typically default back to
2451 building from scratch so they have a know state from the
2452 start.
2453 </para>
2454
2455 <para>
2456 Building an image from scratch is both an advantage and a
2457 disadvantage to the process.
2458 As mentioned in the previous paragraph, building from scratch
2459 ensures that everything is current and starts from a known state.
2460 However, building from scratch also takes much longer as it
2461 generally means rebuilding things that do not necessarily need
2462 to be rebuilt.
2463 </para>
2464
2465 <para>
2466 The Yocto Project implements shared state code that supports
2467 incremental builds.
2468 The implementation of the shared state code answers the following
2469 questions that were fundamental roadblocks within the OpenEmbedded
2470 incremental build support system:
2471 <itemizedlist>
2472 <listitem><para>
2473 What pieces of the system have changed and what pieces have
2474 not changed?
2475 </para></listitem>
2476 <listitem><para>
2477 How are changed pieces of software removed and replaced?
2478 </para></listitem>
2479 <listitem><para>
2480 How are pre-built components that do not need to be rebuilt
2481 from scratch used when they are available?
2482 </para></listitem>
2483 </itemizedlist>
2484 </para>
2485
2486 <para>
2487 For the first question, the build system detects changes in the
2488 "inputs" to a given task by creating a checksum (or signature) of
2489 the task's inputs.
2490 If the checksum changes, the system assumes the inputs have changed
2491 and the task needs to be rerun.
2492 For the second question, the shared state (sstate) code tracks
2493 which tasks add which output to the build process.
2494 This means the output from a given task can be removed, upgraded
2495 or otherwise manipulated.
2496 The third question is partly addressed by the solution for the
2497 second question assuming the build system can fetch the sstate
2498 objects from remote locations and install them if they are deemed
2499 to be valid.
2500 <note><title>Notes</title>
2501 <itemizedlist>
2502 <listitem><para>
2503 The build system does not maintain
2504 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
2505 information as part of the shared state packages.
2506 Consequently, considerations exist that affect
2507 maintaining shared state feeds.
2508 For information on how the build system works with
2509 packages and can track incrementing
2510 <filename>PR</filename> information, see the
2511 "<ulink url='&YOCTO_DOCS_DEV_URL;#automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</ulink>"
2512 section in the Yocto Project Development Tasks Manual.
2513 </para></listitem>
2514 <listitem><para>
2515 The code in the build system that supports incremental
2516 builds is not simple code.
2517 For techniques that help you work around issues related
2518 to shared state code, see the
2519 "<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>"
2520 and
2521 "<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>"
2522 sections both in the Yocto Project Development Tasks
2523 Manual.
2524 </para></listitem>
2525 </itemizedlist>
2526 </note>
2527 </para>
2528
2529 <para>
2530 The rest of this section goes into detail about the overall
2531 incremental build architecture, the checksums (signatures), and
2532 shared state.
2533 </para>
2534
2535 <section id='concepts-overall-architecture'>
2536 <title>Overall Architecture</title>
2537
2538 <para>
2539 When determining what parts of the system need to be built,
2540 BitBake works on a per-task basis rather than a per-recipe
2541 basis.
2542 You might wonder why using a per-task basis is preferred over
2543 a per-recipe basis.
2544 To help explain, consider having the IPK packaging backend
2545 enabled and then switching to DEB.
2546 In this case, the
2547 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2548 and
2549 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
2550 task outputs are still valid.
2551 However, with a per-recipe approach, the build would not
2552 include the <filename>.deb</filename> files.
2553 Consequently, you would have to invalidate the whole build and
2554 rerun it.
2555 Rerunning everything is not the best solution.
2556 Also, in this case, the core must be "taught" much about
2557 specific tasks.
2558 This methodology does not scale well and does not allow users
2559 to easily add new tasks in layers or as external recipes
2560 without touching the packaged-staging core.
2561 </para>
2562 </section>
2563
2564 <section id='overview-checksums'>
2565 <title>Checksums (Signatures)</title>
2566
2567 <para>
2568 The shared state code uses a checksum, which is a unique
2569 signature of a task's inputs, to determine if a task needs to
2570 be run again.
2571 Because it is a change in a task's inputs that triggers a
2572 rerun, the process needs to detect all the inputs to a given
2573 task.
2574 For shell tasks, this turns out to be fairly easy because
2575 the build process generates a "run" shell script for each task
2576 and it is possible to create a checksum that gives you a good
2577 idea of when the task's data changes.
2578 </para>
2579
2580 <para>
2581 To complicate the problem, there are things that should not be
2582 included in the checksum.
2583 First, there is the actual specific build path of a given
2584 task - the
2585 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
2586 It does not matter if the work directory changes because it
2587 should not affect the output for target packages.
2588 Also, the build process has the objective of making native
2589 or cross packages relocatable.
2590 <note>
2591 Both native and cross packages run on the
2592 <ulink url='&YOCTO_DOCS_REF_URL;#hardware-build-system-term'>build host</ulink>.
2593 However, cross packages generate output for the target
2594 architecture.
2595 </note>
2596 The checksum therefore needs to exclude
2597 <filename>WORKDIR</filename>.
2598 The simplistic approach for excluding the work directory is to
2599 set <filename>WORKDIR</filename> to some fixed value and
2600 create the checksum for the "run" script.
2601 </para>
2602
2603 <para>
2604 Another problem results from the "run" scripts containing
2605 functions that might or might not get called.
2606 The incremental build solution contains code that figures out
2607 dependencies between shell functions.
2608 This code is used to prune the "run" scripts down to the
2609 minimum set, thereby alleviating this problem and making the
2610 "run" scripts much more readable as a bonus.
2611 </para>
2612
2613 <para>
2614 So far, solutions for shell scripts exist.
2615 What about Python tasks?
2616 The same approach applies even though these tasks are more
2617 difficult.
2618 The process needs to figure out what variables a Python
2619 function accesses and what functions it calls.
2620 Again, the incremental build solution contains code that first
2621 figures out the variable and function dependencies, and then
2622 creates a checksum for the data used as the input to the task.
2623 </para>
2624
2625 <para>
2626 Like the <filename>WORKDIR</filename> case, situations exist
2627 where dependencies should be ignored.
2628 For these situations, you can instruct the build process to
2629 ignore a dependency by using a line like the following:
2630 <literallayout class='monospaced'>
2631 PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
2632 </literallayout>
2633 This example ensures that the
2634 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCHS'><filename>PACKAGE_ARCHS</filename></ulink>
2635 variable does not depend on the value of
2636 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
2637 even if it does reference it.
2638 </para>
2639
2640 <para>
2641 Equally, there are cases where you need to add dependencies
2642 BitBake is not able to find.
2643 You can accomplish this by using a line like the following:
2644 <literallayout class='monospaced'>
2645 PACKAGE_ARCHS[vardeps] = "MACHINE"
2646 </literallayout>
2647 This example explicitly adds the <filename>MACHINE</filename>
2648 variable as a dependency for
2649 <filename>PACKAGE_ARCHS</filename>.
2650 </para>
2651
2652 <para>
2653 As an example, consider a case with in-line Python where
2654 BitBake is not able to figure out dependencies.
2655 When running in debug mode (i.e. using
2656 <filename>-DDD</filename>), BitBake produces output when it
2657 discovers something for which it cannot figure out dependencies.
2658 The Yocto Project team has currently not managed to cover
2659 those dependencies in detail and is aware of the need to fix
2660 this situation.
2661 </para>
2662
2663 <para>
2664 Thus far, this section has limited discussion to the direct
2665 inputs into a task.
2666 Information based on direct inputs is referred to as the
2667 "basehash" in the code.
2668 However, the question of a task's indirect inputs still
2669 exits - items already built and present in the
2670 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
2671 The checksum (or signature) for a particular task needs to add
2672 the hashes of all the tasks on which the particular task
2673 depends.
2674 Choosing which dependencies to add is a policy decision.
2675 However, the effect is to generate a master checksum that
2676 combines the basehash and the hashes of the task's
2677 dependencies.
2678 </para>
2679
2680 <para>
2681 At the code level, a variety of ways exist by which both the
2682 basehash and the dependent task hashes can be influenced.
2683 Within the BitBake configuration file, you can give BitBake
2684 some extra information to help it construct the basehash.
2685 The following statement effectively results in a list of
2686 global variable dependency excludes (i.e. variables never
2687 included in any checksum):
2688 <literallayout class='monospaced'>
2689 BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \
2690 SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \
2691 USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \
2692 PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \
2693 CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
2694 </literallayout>
2695 The previous example excludes
2696 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
2697 since that variable is actually constructed as a path within
2698 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>,
2699 which is on the whitelist.
2700 </para>
2701
2702 <para>
2703 The rules for deciding which hashes of dependent tasks to
2704 include through dependency chains are more complex and are
2705 generally accomplished with a Python function.
2706 The code in <filename>meta/lib/oe/sstatesig.py</filename> shows
2707 two examples of this and also illustrates how you can insert
2708 your own policy into the system if so desired.
2709 This file defines the two basic signature generators
2710 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OE-Core</ulink>
2711 uses: "OEBasic" and "OEBasicHash".
2712 By default, a dummy "noop" signature handler is enabled
2713 in BitBake.
2714 This means that behavior is unchanged from previous versions.
2715 OE-Core uses the "OEBasicHash" signature handler by default
2716 through this setting in the <filename>bitbake.conf</filename>
2717 file:
2718 <literallayout class='monospaced'>
2719 BB_SIGNATURE_HANDLER ?= "OEBasicHash"
2720 </literallayout>
2721 The "OEBasicHash" <filename>BB_SIGNATURE_HANDLER</filename>
2722 is the same as the "OEBasic" version but adds the task hash to
2723 the
2724 <link linkend='stamp-files-and-the-rerunning-of-tasks'>stamp files</link>.
2725 This results in any metadata change that changes the task hash,
2726 automatically causing the task to be run again.
2727 This removes the need to bump
2728 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
2729 values, and changes to metadata automatically ripple across
2730 the build.
2731 </para>
2732
2733 <para>
2734 It is also worth noting that the end result of these
2735 signature generators is to make some dependency and hash
2736 information available to the build.
2737 This information includes:
2738 <itemizedlist>
2739 <listitem><para>
2740 <filename>BB_BASEHASH_task-</filename><replaceable>taskname</replaceable>:
2741 The base hashes for each task in the recipe.
2742 </para></listitem>
2743 <listitem><para>
2744 <filename>BB_BASEHASH_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
2745 The base hashes for each dependent task.
2746 </para></listitem>
2747 <listitem><para>
2748 <filename>BBHASHDEPS_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
2749 The task dependencies for each task.
2750 </para></listitem>
2751 <listitem><para>
2752 <filename>BB_TASKHASH</filename>:
2753 The hash of the currently running task.
2754 </para></listitem>
2755 </itemizedlist>
2756 </para>
2757 </section>
2758
2759 <section id='shared-state'>
2760 <title>Shared State</title>
2761
2762 <para>
2763 Checksums and dependencies, as discussed in the previous
2764 section, solve half the problem of supporting a shared state.
2765 The other half of the problem is being able to use checksum
2766 information during the build and being able to reuse or rebuild
2767 specific components.
2768 </para>
2769
2770 <para>
2771 The
2772 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-sstate'><filename>sstate</filename></ulink>
2773 class is a relatively generic implementation of how to
2774 "capture" a snapshot of a given task.
2775 The idea is that the build process does not care about the
2776 source of a task's output.
2777 Output could be freshly built or it could be downloaded and
2778 unpacked from somewhere.
2779 In other words, the build process does not need to worry about
2780 its origin.
2781 </para>
2782
2783 <para>
2784 Two types of output exist.
2785 One type is just about creating a directory in
2786 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
2787 A good example is the output of either
2788 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2789 or
2790 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>.
2791 The other type of output occurs when a set of data is merged
2792 into a shared directory tree such as the sysroot.
2793 </para>
2794
2795 <para>
2796 The Yocto Project team has tried to keep the details of the
2797 implementation hidden in <filename>sstate</filename> class.
2798 From a user's perspective, adding shared state wrapping to a
2799 task is as simple as this
2800 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-deploy'><filename>do_deploy</filename></ulink>
2801 example taken from the
2802 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-deploy'><filename>deploy</filename></ulink>
2803 class:
2804 <literallayout class='monospaced'>
2805 DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
2806 SSTATETASKS += "do_deploy"
2807 do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
2808 do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
2809
2810 python do_deploy_setscene () {
2811 sstate_setscene(d)
2812 }
2813 addtask do_deploy_setscene
2814 do_deploy[dirs] = "${DEPLOYDIR} ${B}"
2815 do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"
2816 </literallayout>
2817 The following list explains the previous example:
2818 <itemizedlist>
2819 <listitem><para>
2820 Adding "do_deploy" to <filename>SSTATETASKS</filename>
2821 adds some required sstate-related processing, which is
2822 implemented in the
2823 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-sstate'><filename>sstate</filename></ulink>
2824 class, to before and after the
2825 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-deploy'><filename>do_deploy</filename></ulink>
2826 task.
2827 </para></listitem>
2828 <listitem><para>
2829 The
2830 <filename>do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"</filename>
2831 declares that <filename>do_deploy</filename> places its
2832 output in <filename>${DEPLOYDIR}</filename> when run
2833 normally (i.e. when not using the sstate cache).
2834 This output becomes the input to the shared state cache.
2835 </para></listitem>
2836 <listitem><para>
2837 The
2838 <filename>do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"</filename>
2839 line causes the contents of the shared state cache to be
2840 copied to <filename>${DEPLOY_DIR_IMAGE}</filename>.
2841 <note>
2842 If <filename>do_deploy</filename> is not already in
2843 the shared state cache or if its input checksum
2844 (signature) has changed from when the output was
2845 cached, the task runs to populate the shared
2846 state cache, after which the contents of the shared
2847 state cache is copied to
2848 <filename>${DEPLOY_DIR_IMAGE}</filename>.
2849 If <filename>do_deploy</filename> is in the shared
2850 state cache and its signature indicates that the
2851 cached output is still valid (i.e. if no
2852 relevant task inputs have changed), then the
2853 contents of the shared state cache copies
2854 directly to
2855 <filename>${DEPLOY_DIR_IMAGE}</filename> by the
2856 <filename>do_deploy_setscene</filename> task
2857 instead, skipping the
2858 <filename>do_deploy</filename> task.
2859 </note>
2860 </para></listitem>
2861 <listitem><para>
2862 The following task definition is glue logic needed to
2863 make the previous settings effective:
2864 <literallayout class='monospaced'>
2865 python do_deploy_setscene () {
2866 sstate_setscene(d)
2867 }
2868 addtask do_deploy_setscene
2869 </literallayout>
2870 <filename>sstate_setscene()</filename> takes the flags
2871 above as input and accelerates the
2872 <filename>do_deploy</filename> task through the
2873 shared state cache if possible.
2874 If the task was accelerated,
2875 <filename>sstate_setscene()</filename> returns True.
2876 Otherwise, it returns False, and the normal
2877 <filename>do_deploy</filename> task runs.
2878 For more information, see the
2879 "<ulink url='&YOCTO_DOCS_BB_URL;#setscene'>setscene</ulink>"
2880 section in the BitBake User Manual.
2881 </para></listitem>
2882 <listitem><para>
2883 The <filename>do_deploy[dirs] = "${DEPLOYDIR} ${B}"</filename>
2884 line creates <filename>${DEPLOYDIR}</filename> and
2885 <filename>${B}</filename> before the
2886 <filename>do_deploy</filename> task runs, and also sets
2887 the current working directory of
2888 <filename>do_deploy</filename> to
2889 <filename>${B}</filename>.
2890 For more information, see the
2891 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
2892 section in the BitBake User Manual.
2893 <note>
2894 In cases where
2895 <filename>sstate-inputdirs</filename> and
2896 <filename>sstate-outputdirs</filename> would be the
2897 same, you can use
2898 <filename>sstate-plaindirs</filename>.
2899 For example, to preserve the
2900 <filename>${PKGD}</filename> and
2901 <filename>${PKGDEST}</filename> output from the
2902 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
2903 task, use the following:
2904 <literallayout class='monospaced'>
2905 do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
2906 </literallayout>
2907 </note>
2908 </para></listitem>
2909 <listitem><para>
2910 The <filename>do_deploy[stamp-extra-info] = "${MACHINE_ARCH}"</filename>
2911 line appends extra metadata to the
2912 <link linkend='stamp-files-and-the-rerunning-of-tasks'>stamp file</link>.
2913 In this case, the metadata makes the task specific
2914 to a machine's architecture.
2915 See
2916 "<ulink url='&YOCTO_DOCS_BB_URL;#ref-bitbake-tasklist'>The Task List</ulink>"
2917 section in the BitBake User Manual for more
2918 information on the <filename>stamp-extra-info</filename>
2919 flag.
2920 </para></listitem>
2921 <listitem><para>
2922 <filename>sstate-inputdirs</filename> and
2923 <filename>sstate-outputdirs</filename> can also be used
2924 with multiple directories.
2925 For example, the following declares
2926 <filename>PKGDESTWORK</filename> and
2927 <filename>SHLIBWORK</filename> as shared state
2928 input directories, which populates the shared state
2929 cache, and <filename>PKGDATA_DIR</filename> and
2930 <filename>SHLIBSDIR</filename> as the corresponding
2931 shared state output directories:
2932 <literallayout class='monospaced'>
2933 do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
2934 do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
2935 </literallayout>
2936 </para></listitem>
2937 <listitem><para>
2938 These methods also include the ability to take a
2939 lockfile when manipulating shared state directory
2940 structures, for cases where file additions or removals
2941 are sensitive:
2942 <literallayout class='monospaced'>
2943 do_package[sstate-lockfile] = "${PACKAGELOCK}"
2944 </literallayout>
2945 </para></listitem>
2946 </itemizedlist>
2947 </para>
2948
2949 <para>
2950 Behind the scenes, the shared state code works by looking in
2951 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
2952 and
2953 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_MIRRORS'><filename>SSTATE_MIRRORS</filename></ulink>
2954 for shared state files.
2955 Here is an example:
2956 <literallayout class='monospaced'>
2957 SSTATE_MIRRORS ?= "\
2958 file://.* http://someserver.tld/share/sstate/PATH;downloadfilename=PATH \n \
2959 file://.* file:///some/local/dir/sstate/PATH"
2960 </literallayout>
2961 <note>
2962 The shared state directory
2963 (<filename>SSTATE_DIR</filename>) is organized into
2964 two-character subdirectories, where the subdirectory
2965 names are based on the first two characters of the hash.
2966 If the shared state directory structure for a mirror has the
2967 same structure as <filename>SSTATE_DIR</filename>, you must
2968 specify "PATH" as part of the URI to enable the build system
2969 to map to the appropriate subdirectory.
2970 </note>
2971 </para>
2972
2973 <para>
2974 The shared state package validity can be detected just by
2975 looking at the filename since the filename contains the task
2976 checksum (or signature) as described earlier in this section.
2977 If a valid shared state package is found, the build process
2978 downloads it and uses it to accelerate the task.
2979 </para>
2980
2981 <para>
2982 The build processes use the <filename>*_setscene</filename>
2983 tasks for the task acceleration phase.
2984 BitBake goes through this phase before the main execution
2985 code and tries to accelerate any tasks for which it can find
2986 shared state packages.
2987 If a shared state package for a task is available, the
2988 shared state package is used.
2989 This means the task and any tasks on which it is dependent
2990 are not executed.
2991 </para>
2992
2993 <para>
2994 As a real world example, the aim is when building an IPK-based
2995 image, only the
2996 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_ipk'><filename>do_package_write_ipk</filename></ulink>
2997 tasks would have their shared state packages fetched and
2998 extracted.
2999 Since the sysroot is not used, it would never get extracted.
3000 This is another reason why a task-based approach is preferred
3001 over a recipe-based approach, which would have to install the
3002 output from every task.
3003 </para>
3004 </section>
3005 </section>
3006
3007 <section id='automatically-added-runtime-dependencies'>
3008 <title>Automatically Added Runtime Dependencies</title>
3009
3010 <para>
3011 The OpenEmbedded build system automatically adds common types of
3012 runtime dependencies between packages, which means that you do not
3013 need to explicitly declare the packages using
3014 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>.
3015 Three automatic mechanisms exist (<filename>shlibdeps</filename>,
3016 <filename>pcdeps</filename>, and <filename>depchains</filename>)
3017 that handle shared libraries, package configuration (pkg-config)
3018 modules, and <filename>-dev</filename> and
3019 <filename>-dbg</filename> packages, respectively.
3020 For other types of runtime dependencies, you must manually declare
3021 the dependencies.
3022 <itemizedlist>
3023 <listitem><para>
3024 <filename>shlibdeps</filename>:
3025 During the
3026 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
3027 task of each recipe, all shared libraries installed by the
3028 recipe are located.
3029 For each shared library, the package that contains the
3030 shared library is registered as providing the shared
3031 library.
3032 More specifically, the package is registered as providing
3033 the
3034 <ulink url='https://en.wikipedia.org/wiki/Soname'>soname</ulink>
3035 of the library.
3036 The resulting shared-library-to-package mapping
3037 is saved globally in
3038 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
3039 by the
3040 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-packagedata'><filename>do_packagedata</filename></ulink>
3041 task.</para>
3042
3043 <para>Simultaneously, all executables and shared libraries
3044 installed by the recipe are inspected to see what shared
3045 libraries they link against.
3046 For each shared library dependency that is found,
3047 <filename>PKGDATA_DIR</filename> is queried to
3048 see if some package (likely from a different recipe)
3049 contains the shared library.
3050 If such a package is found, a runtime dependency is added
3051 from the package that depends on the shared library to the
3052 package that contains the library.</para>
3053
3054 <para>The automatically added runtime dependency also
3055 includes a version restriction.
3056 This version restriction specifies that at least the
3057 current version of the package that provides the shared
3058 library must be used, as if
3059 "<replaceable>package</replaceable> (>= <replaceable>version</replaceable>)"
3060 had been added to <filename>RDEPENDS</filename>.
3061 This forces an upgrade of the package containing the shared
3062 library when installing the package that depends on the
3063 library, if needed.</para>
3064
3065 <para>If you want to avoid a package being registered as
3066 providing a particular shared library (e.g. because the library
3067 is for internal use only), then add the library to
3068 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRIVATE_LIBS'><filename>PRIVATE_LIBS</filename></ulink>
3069 inside the package's recipe.
3070 </para></listitem>
3071 <listitem><para>
3072 <filename>pcdeps</filename>:
3073 During the <filename>do_package</filename> task of each
3074 recipe, all pkg-config modules
3075 (<filename>*.pc</filename> files) installed by the recipe
3076 are located.
3077 For each module, the package that contains the module is
3078 registered as providing the module.
3079 The resulting module-to-package mapping is saved globally in
3080 <filename>PKGDATA_DIR</filename> by the
3081 <filename>do_packagedata</filename> task.</para>
3082
3083 <para>Simultaneously, all pkg-config modules installed by
3084 the recipe are inspected to see what other pkg-config
3085 modules they depend on.
3086 A module is seen as depending on another module if it
3087 contains a "Requires:" line that specifies the other module.
3088 For each module dependency,
3089 <filename>PKGDATA_DIR</filename> is queried to see if some
3090 package contains the module.
3091 If such a package is found, a runtime dependency is added
3092 from the package that depends on the module to the package
3093 that contains the module.
3094 <note>
3095 The <filename>pcdeps</filename> mechanism most often
3096 infers dependencies between <filename>-dev</filename>
3097 packages.
3098 </note>
3099 </para></listitem>
3100 <listitem><para>
3101 <filename>depchains</filename>:
3102 If a package <filename>foo</filename> depends on a package
3103 <filename>bar</filename>, then <filename>foo-dev</filename>
3104 and <filename>foo-dbg</filename> are also made to depend on
3105 <filename>bar-dev</filename> and
3106 <filename>bar-dbg</filename>, respectively.
3107 Taking the <filename>-dev</filename> packages as an
3108 example, the <filename>bar-dev</filename> package might
3109 provide headers and shared library symlinks needed by
3110 <filename>foo-dev</filename>, which shows the need
3111 for a dependency between the packages.</para>
3112
3113 <para>The dependencies added by
3114 <filename>depchains</filename> are in the form of
3115 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>.
3116 <note>
3117 By default, <filename>foo-dev</filename> also has an
3118 <filename>RDEPENDS</filename>-style dependency on
3119 <filename>foo</filename>, because the default value of
3120 <filename>RDEPENDS_${PN}-dev</filename> (set in
3121 <filename>bitbake.conf</filename>) includes
3122 "${PN}".
3123 </note></para>
3124
3125 <para>To ensure that the dependency chain is never broken,
3126 <filename>-dev</filename> and <filename>-dbg</filename>
3127 packages are always generated by default, even if the
3128 packages turn out to be empty.
3129 See the
3130 <ulink url='&YOCTO_DOCS_REF_URL;#var-ALLOW_EMPTY'><filename>ALLOW_EMPTY</filename></ulink>
3131 variable for more information.
3132 </para></listitem>
3133 </itemizedlist>
3134 </para>
3135
3136 <para>
3137 The <filename>do_package</filename> task depends on the
3138 <filename>do_packagedata</filename> task of each recipe in
3139 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3140 through use of a
3141 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>deptask</filename></ulink><filename>]</filename>
3142 declaration, which guarantees that the required
3143 shared-library/module-to-package mapping information will be available
3144 when needed as long as <filename>DEPENDS</filename> has been
3145 correctly set.
3146 </para>
3147 </section>
3148
3149 <section id='fakeroot-and-pseudo'>
3150 <title>Fakeroot and Pseudo</title>
3151
3152 <para>
3153 Some tasks are easier to implement when allowed to perform certain
3154 operations that are normally reserved for the root user (e.g.
3155 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>,
3156 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package_write_deb'><filename>do_package_write*</filename></ulink>,
3157 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>,
3158 and
3159 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image*</filename></ulink>).
3160 For example, the <filename>do_install</filename> task benefits
3161 from being able to set the UID and GID of installed files to
3162 arbitrary values.
3163 </para>
3164
3165 <para>
3166 One approach to allowing tasks to perform root-only operations
3167 would be to require
3168 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
3169 to run as root.
3170 However, this method is cumbersome and has security issues.
3171 The approach that is actually used is to run tasks that benefit
3172 from root privileges in a "fake" root environment.
3173 Within this environment, the task and its child processes believe
3174 that they are running as the root user, and see an internally
3175 consistent view of the filesystem.
3176 As long as generating the final output (e.g. a package or an image)
3177 does not require root privileges, the fact that some earlier
3178 steps ran in a fake root environment does not cause problems.
3179 </para>
3180
3181 <para>
3182 The capability to run tasks in a fake root environment is known as
3183 "<ulink url='http://man.he.net/man1/fakeroot'>fakeroot</ulink>",
3184 which is derived from the BitBake keyword/variable
3185 flag that requests a fake root environment for a task.
3186 </para>
3187
3188 <para>
3189 In the
3190 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>,
Brad Bishopd89cb5f2019-04-10 09:02:41 -04003191 the program that implements fakeroot is known as
3192 <ulink url='https://www.yoctoproject.org/software-item/pseudo/'>Pseudo</ulink>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04003193 Pseudo overrides system calls by using the environment variable
3194 <filename>LD_PRELOAD</filename>, which results in the illusion
3195 of running as root.
3196 To keep track of "fake" file ownership and permissions resulting
3197 from operations that require root permissions, Pseudo uses
3198 an SQLite 3 database.
3199 This database is stored in
3200 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/pseudo/files.db</filename>
3201 for individual recipes.
3202 Storing the database in a file as opposed to in memory
3203 gives persistence between tasks and builds, which is not
3204 accomplished using fakeroot.
3205 <note><title>Caution</title>
3206 If you add your own task that manipulates the same files or
3207 directories as a fakeroot task, then that task also needs to
3208 run under fakeroot.
3209 Otherwise, the task cannot run root-only operations, and
3210 cannot see the fake file ownership and permissions set by the
3211 other task.
3212 You need to also add a dependency on
3213 <filename>virtual/fakeroot-native:do_populate_sysroot</filename>,
3214 giving the following:
3215 <literallayout class='monospaced'>
3216 fakeroot do_mytask () {
3217 ...
3218 }
3219 do_mytask[depends] += "virtual/fakeroot-native:do_populate_sysroot"
3220 </literallayout>
3221 </note>
3222 For more information, see the
3223 <ulink url='&YOCTO_DOCS_BB_URL;#var-FAKEROOT'><filename>FAKEROOT*</filename></ulink>
3224 variables in the BitBake User Manual.
3225 You can also reference the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003226 "<ulink url='https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot'>Why Not Fakeroot?</ulink>"
Brad Bishopd89cb5f2019-04-10 09:02:41 -04003227 article for background information on Fakeroot and Pseudo.
Brad Bishop316dfdd2018-06-25 12:45:53 -04003228 </para>
3229 </section>
3230</chapter>
3231<!--
3232vim: expandtab tw=80 ts=4
3233-->