blob: f06382ab52db80788357bedb6cdfb21c23672f8c [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!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='technical-details'>
6<title>Technical Details</title>
7
8 <para>
9 This chapter provides technical details for various parts of the
10 Yocto Project.
11 Currently, topics include Yocto Project components,
12 cross-toolchain generation, shared state (sstate) cache,
13 x32, Wayland support, and Licenses.
14 </para>
15
16<section id='usingpoky-components'>
17 <title>Yocto Project Components</title>
18
19 <para>
20 The
21 <ulink url='&YOCTO_DOCS_DEV_URL;#bitbake-term'>BitBake</ulink>
22 task executor together with various types of configuration files form
23 the OpenEmbedded Core.
24 This section overviews these components by describing their use and
25 how they interact.
26 </para>
27
28 <para>
29 BitBake handles the parsing and execution of the data files.
30 The data itself is of various types:
31 <itemizedlist>
32 <listitem><para><emphasis>Recipes:</emphasis> Provides details
33 about particular pieces of software.
34 </para></listitem>
35 <listitem><para><emphasis>Class Data:</emphasis> Abstracts
36 common build information (e.g. how to build a Linux kernel).
37 </para></listitem>
38 <listitem><para><emphasis>Configuration Data:</emphasis> Defines
39 machine-specific settings, policy decisions, and so forth.
40 Configuration data acts as the glue to bind everything
41 together.
42 </para></listitem>
43 </itemizedlist>
44 </para>
45
46 <para>
47 BitBake knows how to combine multiple data sources together and refers
48 to each data source as a layer.
49 For information on layers, see the
50 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and
51 Creating Layers</ulink>" section of the Yocto Project Development Manual.
52 </para>
53
54 <para>
55 Following are some brief details on these core components.
56 For additional information on how these components interact during
57 a build, see the
58 "<link linkend='closer-look'>A Closer Look at the Yocto Project Development Environment</link>"
59 Chapter.
60 </para>
61
62 <section id='usingpoky-components-bitbake'>
63 <title>BitBake</title>
64
65 <para>
66 BitBake is the tool at the heart of the OpenEmbedded build system
67 and is responsible for parsing the
68 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink>,
69 generating a list of tasks from it, and then executing those tasks.
70 </para>
71
72 <para>
73 This section briefly introduces BitBake.
74 If you want more information on BitBake, see the
75 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual'>BitBake User Manual</ulink>.
76 </para>
77
78 <para>
79 To see a list of the options BitBake supports, use either of
80 the following commands:
81 <literallayout class='monospaced'>
82 $ bitbake -h
83 $ bitbake --help
84 </literallayout>
85 </para>
86
87 <para>
88 The most common usage for BitBake is <filename>bitbake <replaceable>packagename</replaceable></filename>, where
89 <filename>packagename</filename> is the name of the package you want to build
90 (referred to as the "target" in this manual).
91 The target often equates to the first part of a recipe's filename
92 (e.g. "foo" for a recipe named
93 <filename>foo_1.3.0-r0.bb</filename>).
94 So, to process the <filename>matchbox-desktop_1.2.3.bb</filename> recipe file, you
95 might type the following:
96 <literallayout class='monospaced'>
97 $ bitbake matchbox-desktop
98 </literallayout>
99 Several different versions of <filename>matchbox-desktop</filename> might exist.
100 BitBake chooses the one selected by the distribution configuration.
101 You can get more details about how BitBake chooses between different
102 target versions and providers in the
103 "<ulink url='&YOCTO_DOCS_BB_URL;#bb-bitbake-preferences'>Preferences</ulink>"
104 section of the BitBake User Manual.
105 </para>
106
107 <para>
108 BitBake also tries to execute any dependent tasks first.
109 So for example, before building <filename>matchbox-desktop</filename>, BitBake
110 would build a cross compiler and <filename>glibc</filename> if they had not already
111 been built.
112 </para>
113
114 <para>
115 A useful BitBake option to consider is the <filename>-k</filename> or
116 <filename>--continue</filename> option.
117 This option instructs BitBake to try and continue processing the job
118 as long as possible even after encountering an error.
119 When an error occurs, the target that
120 failed and those that depend on it cannot be remade.
121 However, when you use this option other dependencies can still be
122 processed.
123 </para>
124 </section>
125
126 <section id='usingpoky-components-metadata'>
127 <title>Metadata (Recipes)</title>
128
129 <para>
130 Files that have the <filename>.bb</filename> suffix are "recipes"
131 files.
132 In general, a recipe contains information about a single piece of
133 software.
134 This information includes the location from which to download the
135 unaltered source, any source patches to be applied to that source
136 (if needed), which special configuration options to apply,
137 how to compile the source files, and how to package the compiled
138 output.
139 </para>
140
141 <para>
142 The term "package" is sometimes used to refer to recipes. However,
143 since the word "package" is used for the packaged output from the OpenEmbedded
144 build system (i.e. <filename>.ipk</filename> or <filename>.deb</filename> files),
145 this document avoids using the term "package" when referring to recipes.
146 </para>
147 </section>
148
149 <section id='usingpoky-components-classes'>
150 <title>Classes</title>
151
152 <para>
153 Class files (<filename>.bbclass</filename>) contain information that
154 is useful to share between
155 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> files.
156 An example is the
157 <link linkend='ref-classes-autotools'><filename>autotools</filename></link>
158 class, which contains common settings for any application that
159 Autotools uses.
160 The "<link linkend='ref-classes'>Classes</link>" chapter provides
161 details about classes and how to use them.
162 </para>
163 </section>
164
165 <section id='usingpoky-components-configuration'>
166 <title>Configuration</title>
167
168 <para>
169 The configuration files (<filename>.conf</filename>) define various configuration variables
170 that govern the OpenEmbedded build process.
171 These files fall into several areas that define machine configuration options,
172 distribution configuration options, compiler tuning options, general common configuration
173 options, and user configuration options in <filename>local.conf</filename>, which is found
174 in the
175 <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>.
176 </para>
177 </section>
178</section>
179
180<section id="cross-development-toolchain-generation">
181 <title>Cross-Development Toolchain Generation</title>
182
183 <para>
184 The Yocto Project does most of the work for you when it comes to
185 creating
186 <ulink url='&YOCTO_DOCS_DEV_URL;#cross-development-toolchain'>cross-development toolchains</ulink>.
187 This section provides some technical background on how
188 cross-development toolchains are created and used.
189 For more information on toolchains, you can also see the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500190 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Software Development Kit (SDK) Developer's Guide</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 </para>
192
193 <para>
194 In the Yocto Project development environment, cross-development
195 toolchains are used to build the image and applications that run on the
196 target hardware.
197 With just a few commands, the OpenEmbedded build system creates
198 these necessary toolchains for you.
199 </para>
200
201 <para>
202 The following figure shows a high-level build environment regarding
203 toolchain construction and use.
204 </para>
205
206 <para>
207 <imagedata fileref="figures/cross-development-toolchains.png" width="8in" depth="6in" align="center" />
208 </para>
209
210 <para>
211 Most of the work occurs on the Build Host.
212 This is the machine used to build images and generally work within the
213 the Yocto Project environment.
214 When you run BitBake to create an image, the OpenEmbedded build system
215 uses the host <filename>gcc</filename> compiler to bootstrap a
216 cross-compiler named <filename>gcc-cross</filename>.
217 The <filename>gcc-cross</filename> compiler is what BitBake uses to
218 compile source files when creating the target image.
219 You can think of <filename>gcc-cross</filename> simply as an
220 automatically generated cross-compiler that is used internally within
221 BitBake only.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222 <note>
223 The extensible SDK does not use
224 <filename>gcc-cross-canadian</filename> since this SDK
225 ships a copy of the OpenEmbedded build system and the sysroot
226 within it contains <filename>gcc-cross</filename>.
227 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 </para>
229
230 <para>
231 The chain of events that occurs when <filename>gcc-cross</filename> is
232 bootstrapped is as follows:
233 <literallayout class='monospaced'>
234 gcc -> binutils-cross -> gcc-cross-initial -> linux-libc-headers -> glibc-initial -> glibc -> gcc-cross -> gcc-runtime
235 </literallayout>
236 <itemizedlist>
237 <listitem><para><filename>gcc</filename>:
238 The build host's GNU Compiler Collection (GCC).
239 </para></listitem>
240 <listitem><para><filename>binutils-cross</filename>:
241 The bare minimum binary utilities needed in order to run
242 the <filename>gcc-cross-initial</filename> phase of the
243 bootstrap operation.
244 </para></listitem>
245 <listitem><para><filename>gcc-cross-initial</filename>:
246 An early stage of the bootstrap process for creating
247 the cross-compiler.
248 This stage builds enough of the <filename>gcc-cross</filename>,
249 the C library, and other pieces needed to finish building the
250 final cross-compiler in later stages.
251 This tool is a "native" package (i.e. it is designed to run on
252 the build host).
253 </para></listitem>
254 <listitem><para><filename>linux-libc-headers</filename>:
255 Headers needed for the cross-compiler.
256 </para></listitem>
257 <listitem><para><filename>glibc-initial</filename>:
258 An initial version of the Embedded GLIBC needed to bootstrap
259 <filename>glibc</filename>.
260 </para></listitem>
261 <listitem><para><filename>gcc-cross</filename>:
262 The final stage of the bootstrap process for the
263 cross-compiler.
264 This stage results in the actual cross-compiler that
265 BitBake uses when it builds an image for a targeted
266 device.
267 <note>
268 If you are replacing this cross compiler toolchain
269 with a custom version, you must replace
270 <filename>gcc-cross</filename>.
271 </note>
272 This tool is also a "native" package (i.e. it is
273 designed to run on the build host).
274 </para></listitem>
275 <listitem><para><filename>gcc-runtime</filename>:
276 Runtime libraries resulting from the toolchain bootstrapping
277 process.
278 This tool produces a binary that consists of the
279 runtime libraries need for the targeted device.
280 </para></listitem>
281 </itemizedlist>
282 </para>
283
284 <para>
285 You can use the OpenEmbedded build system to build an installer for
286 the relocatable SDK used to develop applications.
287 When you run the installer, it installs the toolchain, which contains
288 the development tools (e.g., the
289 <filename>gcc-cross-canadian</filename>),
290 <filename>binutils-cross-canadian</filename>, and other
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500291 <filename>nativesdk-*</filename> tools,
292 which are tools native to the SDK (i.e. native to
293 <link linkend='var-SDK_ARCH'><filename>SDK_ARCH</filename></link>),
294 you need to cross-compile and test your software.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 The figure shows the commands you use to easily build out this
296 toolchain.
297 This cross-development toolchain is built to execute on the
298 <link linkend='var-SDKMACHINE'><filename>SDKMACHINE</filename></link>,
299 which might or might not be the same
300 machine as the Build Host.
301 <note>
302 If your target architecture is supported by the Yocto Project,
303 you can take advantage of pre-built images that ship with the
304 Yocto Project and already contain cross-development toolchain
305 installers.
306 </note>
307 </para>
308
309 <para>
310 Here is the bootstrap process for the relocatable toolchain:
311 <literallayout class='monospaced'>
312 gcc -> binutils-crosssdk -> gcc-crosssdk-initial -> linux-libc-headers ->
313 glibc-initial -> nativesdk-glibc -> gcc-crosssdk -> gcc-cross-canadian
314 </literallayout>
315 <itemizedlist>
316 <listitem><para><filename>gcc</filename>:
317 The build host's GNU Compiler Collection (GCC).
318 </para></listitem>
319 <listitem><para><filename>binutils-crosssdk</filename>:
320 The bare minimum binary utilities needed in order to run
321 the <filename>gcc-crosssdk-initial</filename> phase of the
322 bootstrap operation.
323 </para></listitem>
324 <listitem><para><filename>gcc-crosssdk-initial</filename>:
325 An early stage of the bootstrap process for creating
326 the cross-compiler.
327 This stage builds enough of the
328 <filename>gcc-crosssdk</filename> and supporting pieces so that
329 the final stage of the bootstrap process can produce the
330 finished cross-compiler.
331 This tool is a "native" binary that runs on the build host.
332 </para></listitem>
333 <listitem><para><filename>linux-libc-headers</filename>:
334 Headers needed for the cross-compiler.
335 </para></listitem>
336 <listitem><para><filename>glibc-initial</filename>:
337 An initial version of the Embedded GLIBC needed to bootstrap
338 <filename>nativesdk-glibc</filename>.
339 </para></listitem>
340 <listitem><para><filename>nativesdk-glibc</filename>:
341 The Embedded GLIBC needed to bootstrap the
342 <filename>gcc-crosssdk</filename>.
343 </para></listitem>
344 <listitem><para><filename>gcc-crosssdk</filename>:
345 The final stage of the bootstrap process for the
346 relocatable cross-compiler.
347 The <filename>gcc-crosssdk</filename> is a transitory compiler
348 and never leaves the build host.
349 Its purpose is to help in the bootstrap process to create the
350 eventual relocatable <filename>gcc-cross-canadian</filename>
351 compiler, which is relocatable.
352 This tool is also a "native" package (i.e. it is
353 designed to run on the build host).
354 </para></listitem>
355 <listitem><para><filename>gcc-cross-canadian</filename>:
356 The final relocatable cross-compiler.
357 When run on the
358 <link linkend='var-SDKMACHINE'><filename>SDKMACHINE</filename></link>,
359 this tool
360 produces executable code that runs on the target device.
361 Only one cross-canadian compiler is produced per architecture
362 since they can be targeted at different processor optimizations
363 using configurations passed to the compiler through the
364 compile commands.
365 This circumvents the need for multiple compilers and thus
366 reduces the size of the toolchains.
367 </para></listitem>
368 </itemizedlist>
369 </para>
370
371 <note>
372 For information on advantages gained when building a
373 cross-development toolchain installer, see the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500374 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-building-an-sdk-installer'>Building an SDK Installer</ulink>"
375 section in the Yocto Project Software Development Kit (SDK) Developer's
376 Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377 </note>
378</section>
379
380<section id="shared-state-cache">
381 <title>Shared State Cache</title>
382
383 <para>
384 By design, the OpenEmbedded build system builds everything from scratch unless
385 BitBake can determine that parts do not need to be rebuilt.
386 Fundamentally, building from scratch is attractive as it means all parts are
387 built fresh and there is no possibility of stale data causing problems.
388 When developers hit problems, they typically default back to building from scratch
389 so they know the state of things from the start.
390 </para>
391
392 <para>
393 Building an image from scratch is both an advantage and a disadvantage to the process.
394 As mentioned in the previous paragraph, building from scratch ensures that
395 everything is current and starts from a known state.
396 However, building from scratch also takes much longer as it generally means
397 rebuilding things that do not necessarily need to be rebuilt.
398 </para>
399
400 <para>
401 The Yocto Project implements shared state code that supports incremental builds.
402 The implementation of the shared state code answers the following questions that
403 were fundamental roadblocks within the OpenEmbedded incremental build support system:
404 <itemizedlist>
405 <listitem><para>What pieces of the system have changed and what pieces have
406 not changed?</para></listitem>
407 <listitem><para>How are changed pieces of software removed and replaced?</para></listitem>
408 <listitem><para>How are pre-built components that do not need to be rebuilt from scratch
409 used when they are available?</para></listitem>
410 </itemizedlist>
411 </para>
412
413 <para>
414 For the first question, the build system detects changes in the "inputs" to a given task by
415 creating a checksum (or signature) of the task's inputs.
416 If the checksum changes, the system assumes the inputs have changed and the task needs to be
417 rerun.
418 For the second question, the shared state (sstate) code tracks which tasks add which output
419 to the build process.
420 This means the output from a given task can be removed, upgraded or otherwise manipulated.
421 The third question is partly addressed by the solution for the second question
422 assuming the build system can fetch the sstate objects from remote locations and
423 install them if they are deemed to be valid.
424 </para>
425
426 <note>
427 The OpenEmbedded build system does not maintain
428 <link linkend='var-PR'><filename>PR</filename></link> information
429 as part of the shared state packages.
430 Consequently, considerations exist that affect maintaining shared
431 state feeds.
432 For information on how the OpenEmbedded build system
433 works with packages and can
434 track incrementing <filename>PR</filename> information, see the
435 "<ulink url='&YOCTO_DOCS_DEV_URL;#incrementing-a-package-revision-number'>Incrementing a Package Revision Number</ulink>"
436 section.
437 </note>
438
439 <para>
440 The rest of this section goes into detail about the overall incremental build
441 architecture, the checksums (signatures), shared state, and some tips and tricks.
442 </para>
443
444 <section id='overall-architecture'>
445 <title>Overall Architecture</title>
446
447 <para>
448 When determining what parts of the system need to be built, BitBake
449 works on a per-task basis rather than a per-recipe basis.
450 You might wonder why using a per-task basis is preferred over a per-recipe basis.
451 To help explain, consider having the IPK packaging backend enabled and then switching to DEB.
452 In this case, the
453 <link linkend='ref-tasks-install'><filename>do_install</filename></link>
454 and
455 <link linkend='ref-tasks-package'><filename>do_package</filename></link>
456 task outputs are still valid.
457 However, with a per-recipe approach, the build would not include the
458 <filename>.deb</filename> files.
459 Consequently, you would have to invalidate the whole build and rerun it.
460 Rerunning everything is not the best solution.
461 Also, in this case, the core must be "taught" much about specific tasks.
462 This methodology does not scale well and does not allow users to easily add new tasks
463 in layers or as external recipes without touching the packaged-staging core.
464 </para>
465 </section>
466
467 <section id='checksums'>
468 <title>Checksums (Signatures)</title>
469
470 <para>
471 The shared state code uses a checksum, which is a unique signature of a task's
472 inputs, to determine if a task needs to be run again.
473 Because it is a change in a task's inputs that triggers a rerun, the process
474 needs to detect all the inputs to a given task.
475 For shell tasks, this turns out to be fairly easy because
476 the build process generates a "run" shell script for each task and
477 it is possible to create a checksum that gives you a good idea of when
478 the task's data changes.
479 </para>
480
481 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500482 To complicate the problem, there are things that should not be
483 included in the checksum.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500484 First, there is the actual specific build path of a given task -
485 the <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500486 It does not matter if the work directory changes because it should
487 not affect the output for target packages.
488 Also, the build process has the objective of making native
489 or cross packages relocatable.
490 <note>
491 Both native and cross packages run on the build host.
492 However, cross packages generate output for the target
493 architecture.
494 </note>
495 The checksum therefore needs to exclude
496 <filename>WORKDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500497 The simplistic approach for excluding the work directory is to set
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500498 <filename>WORKDIR</filename> to some fixed value and create the
499 checksum for the "run" script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500500 </para>
501
502 <para>
503 Another problem results from the "run" scripts containing functions that
504 might or might not get called.
505 The incremental build solution contains code that figures out dependencies
506 between shell functions.
507 This code is used to prune the "run" scripts down to the minimum set,
508 thereby alleviating this problem and making the "run" scripts much more
509 readable as a bonus.
510 </para>
511
512 <para>
513 So far we have solutions for shell scripts.
514 What about Python tasks?
515 The same approach applies even though these tasks are more difficult.
516 The process needs to figure out what variables a Python function accesses
517 and what functions it calls.
518 Again, the incremental build solution contains code that first figures out
519 the variable and function dependencies, and then creates a checksum for the data
520 used as the input to the task.
521 </para>
522
523 <para>
524 Like the <filename>WORKDIR</filename> case, situations exist where dependencies
525 should be ignored.
526 For these cases, you can instruct the build process to ignore a dependency
527 by using a line like the following:
528 <literallayout class='monospaced'>
529 PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
530 </literallayout>
531 This example ensures that the
532 <link linkend='var-PACKAGE_ARCHS'><filename>PACKAGE_ARCHS</filename></link>
533 variable does not
534 depend on the value of
535 <link linkend='var-MACHINE'><filename>MACHINE</filename></link>,
536 even if it does reference it.
537 </para>
538
539 <para>
540 Equally, there are cases where we need to add dependencies BitBake is not able to find.
541 You can accomplish this by using a line like the following:
542 <literallayout class='monospaced'>
543 PACKAGE_ARCHS[vardeps] = "MACHINE"
544 </literallayout>
545 This example explicitly adds the <filename>MACHINE</filename> variable as a
546 dependency for <filename>PACKAGE_ARCHS</filename>.
547 </para>
548
549 <para>
550 Consider a case with in-line Python, for example, where BitBake is not
551 able to figure out dependencies.
552 When running in debug mode (i.e. using <filename>-DDD</filename>), BitBake
553 produces output when it discovers something for which it cannot figure out
554 dependencies.
555 The Yocto Project team has currently not managed to cover those dependencies
556 in detail and is aware of the need to fix this situation.
557 </para>
558
559 <para>
560 Thus far, this section has limited discussion to the direct inputs into a task.
561 Information based on direct inputs is referred to as the "basehash" in the
562 code.
563 However, there is still the question of a task's indirect inputs - the
564 things that were already built and present in the
565 <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>.
566 The checksum (or signature) for a particular task needs to add the hashes
567 of all the tasks on which the particular task depends.
568 Choosing which dependencies to add is a policy decision.
569 However, the effect is to generate a master checksum that combines the basehash
570 and the hashes of the task's dependencies.
571 </para>
572
573 <para>
574 At the code level, there are a variety of ways both the basehash and the
575 dependent task hashes can be influenced.
576 Within the BitBake configuration file, we can give BitBake some extra information
577 to help it construct the basehash.
578 The following statement effectively results in a list of global variable
579 dependency excludes - variables never included in any checksum:
580 <literallayout class='monospaced'>
581 BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \
582 SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \
583 USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \
584 PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \
585 CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
586 </literallayout>
587 The previous example excludes
588 <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>
589 since that variable is actually constructed as a path within
590 <link linkend='var-TMPDIR'><filename>TMPDIR</filename></link>, which is on
591 the whitelist.
592 </para>
593
594 <para>
595 The rules for deciding which hashes of dependent tasks to include through
596 dependency chains are more complex and are generally accomplished with a
597 Python function.
598 The code in <filename>meta/lib/oe/sstatesig.py</filename> shows two examples
599 of this and also illustrates how you can insert your own policy into the system
600 if so desired.
601 This file defines the two basic signature generators <filename>OE-Core</filename>
602 uses: "OEBasic" and "OEBasicHash".
603 By default, there is a dummy "noop" signature handler enabled in BitBake.
604 This means that behavior is unchanged from previous versions.
605 <filename>OE-Core</filename> uses the "OEBasicHash" signature handler by default
606 through this setting in the <filename>bitbake.conf</filename> file:
607 <literallayout class='monospaced'>
608 BB_SIGNATURE_HANDLER ?= "OEBasicHash"
609 </literallayout>
610 The "OEBasicHash" <filename>BB_SIGNATURE_HANDLER</filename> is the same as the
611 "OEBasic" version but adds the task hash to the stamp files.
612 This results in any
613 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink>
614 change that changes the task hash, automatically
615 causing the task to be run again.
616 This removes the need to bump <link linkend='var-PR'><filename>PR</filename></link>
617 values, and changes to Metadata automatically ripple across the build.
618 </para>
619
620 <para>
621 It is also worth noting that the end result of these signature generators is to
622 make some dependency and hash information available to the build.
623 This information includes:
624 <itemizedlist>
625 <listitem><para><filename>BB_BASEHASH_task-</filename><replaceable>taskname</replaceable>:
626 The base hashes for each task in the recipe.
627 </para></listitem>
628 <listitem><para><filename>BB_BASEHASH_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
629 The base hashes for each dependent task.
630 </para></listitem>
631 <listitem><para><filename>BBHASHDEPS_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
632 The task dependencies for each task.
633 </para></listitem>
634 <listitem><para><filename>BB_TASKHASH</filename>:
635 The hash of the currently running task.
636 </para></listitem>
637 </itemizedlist>
638 </para>
639 </section>
640
641 <section id='shared-state'>
642 <title>Shared State</title>
643
644 <para>
645 Checksums and dependencies, as discussed in the previous section, solve half the
646 problem of supporting a shared state.
647 The other part of the problem is being able to use checksum information during the build
648 and being able to reuse or rebuild specific components.
649 </para>
650
651 <para>
652 The
653 <link linkend='ref-classes-sstate'><filename>sstate</filename></link>
654 class is a relatively generic implementation of how to "capture"
655 a snapshot of a given task.
656 The idea is that the build process does not care about the source of a task's output.
657 Output could be freshly built or it could be downloaded and unpacked from
658 somewhere - the build process does not need to worry about its origin.
659 </para>
660
661 <para>
662 There are two types of output, one is just about creating a directory
663 in <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>.
664 A good example is the output of either
665 <link linkend='ref-tasks-install'><filename>do_install</filename></link>
666 or
667 <link linkend='ref-tasks-package'><filename>do_package</filename></link>.
668 The other type of output occurs when a set of data is merged into a shared directory
669 tree such as the sysroot.
670 </para>
671
672 <para>
673 The Yocto Project team has tried to keep the details of the
674 implementation hidden in <filename>sstate</filename> class.
675 From a user's perspective, adding shared state wrapping to a task
676 is as simple as this
677 <link linkend='ref-tasks-deploy'><filename>do_deploy</filename></link>
678 example taken from the
679 <link linkend='ref-classes-deploy'><filename>deploy</filename></link>
680 class:
681 <literallayout class='monospaced'>
682 DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
683 SSTATETASKS += "do_deploy"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500684 do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
685 do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
686
687 python do_deploy_setscene () {
688 sstate_setscene(d)
689 }
690 addtask do_deploy_setscene
691 do_deploy[dirs] = "${DEPLOYDIR} ${B}"
692 </literallayout>
693 In this example, we add some extra flags to the task, a name field ("deploy"), an
694 input directory where the task sends data, and the output
695 directory where the data from the task should eventually be copied.
696 We also add a <filename>_setscene</filename> variant of the task and add the task
697 name to the <filename>SSTATETASKS</filename> list.
698 </para>
699
700 <para>
701 If you have a directory whose contents you need to preserve, you can do this with
702 a line like the following:
703 <literallayout class='monospaced'>
704 do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
705 </literallayout>
706 This method, as well as the following example, also works for multiple directories.
707 <literallayout class='monospaced'>
708 do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
709 do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
710 do_package[sstate-lockfile] = "${PACKAGELOCK}"
711 </literallayout>
712 These methods also include the ability to take a lockfile when manipulating
713 shared state directory structures since some cases are sensitive to file
714 additions or removals.
715 </para>
716
717 <para>
718 Behind the scenes, the shared state code works by looking in
719 <link linkend='var-SSTATE_DIR'><filename>SSTATE_DIR</filename></link> and
720 <link linkend='var-SSTATE_MIRRORS'><filename>SSTATE_MIRRORS</filename></link>
721 for shared state files.
722 Here is an example:
723 <literallayout class='monospaced'>
724 SSTATE_MIRRORS ?= "\
725 file://.* http://someserver.tld/share/sstate/PATH \n \
726 file://.* file:///some/local/dir/sstate/PATH"
727 </literallayout>
728 <note>
729 The shared state directory (<filename>SSTATE_DIR</filename>) is
730 organized into two-character subdirectories, where the subdirectory
731 names are based on the first two characters of the hash.
732 If the shared state directory structure for a mirror has the
733 same structure as <filename>SSTATE_DIR</filename>, you must
734 specify "PATH" as part of the URI to enable the build system
735 to map to the appropriate subdirectory.
736 </note>
737 </para>
738
739 <para>
740 The shared state package validity can be detected just by looking at the
741 filename since the filename contains the task checksum (or signature) as
742 described earlier in this section.
743 If a valid shared state package is found, the build process downloads it
744 and uses it to accelerate the task.
745 </para>
746
747 <para>
748 The build processes use the <filename>*_setscene</filename> tasks
749 for the task acceleration phase.
750 BitBake goes through this phase before the main execution code and tries
751 to accelerate any tasks for which it can find shared state packages.
752 If a shared state package for a task is available, the shared state
753 package is used.
754 This means the task and any tasks on which it is dependent are not
755 executed.
756 </para>
757
758 <para>
759 As a real world example, the aim is when building an IPK-based image,
760 only the
761 <link linkend='ref-tasks-package_write_ipk'><filename>do_package_write_ipk</filename></link>
762 tasks would have their
763 shared state packages fetched and extracted.
764 Since the sysroot is not used, it would never get extracted.
765 This is another reason why a task-based approach is preferred over a
766 recipe-based approach, which would have to install the output from every task.
767 </para>
768 </section>
769
770 <section id='tips-and-tricks'>
771 <title>Tips and Tricks</title>
772
773 <para>
774 The code in the build system that supports incremental builds is not
775 simple code.
776 This section presents some tips and tricks that help you work around
777 issues related to shared state code.
778 </para>
779
780 <section id='debugging'>
781 <title>Debugging</title>
782
783 <para>
784 When things go wrong, debugging needs to be straightforward.
785 Because of this, the Yocto Project includes strong debugging
786 tools:
787 <itemizedlist>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500788 <listitem><para>Whenever a shared state package is written
789 out into the
790 <link linkend='var-SSTATE_DIR'><filename>SSTATE_DIR</filename></link>,
791 a corresponding <filename>.siginfo</filename> file is
792 also written.
793 This file contains a pickled Python database of all
794 the Metadata that went into creating the hash for a
795 given shared state package.
796 Whenever a stamp is written into the stamp directory
797 <link linkend='var-STAMP'><filename>STAMP</filename></link>,
798 a corresponding <filename>.sigdata</filename> file
799 is created that contains the same hash data that
800 represented the executed task.
801 </para></listitem>
802 <listitem><para>You can use BitBake to dump out the
803 signature construction information without executing
804 tasks by using either of the following BitBake
805 command-line options:
806 <literallayout class='monospaced'>
807 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
808 -S <replaceable>SIGNATURE_HANDLER</replaceable>
809 </literallayout>
810 <note>
811 Two common values for
812 <replaceable>SIGNATURE_HANDLER</replaceable> are
813 "none" and "printdiff" to only dump the signature
814 or to compare the dumped signature with the
815 cached one, respectively.
816 </note>
817 Using BitBake with either of these options causes
818 BitBake to dump out <filename>.sigdata</filename> files
819 in the stamp directory for every task it would have
820 executed instead of building the specified target
821 package.
822 </para></listitem>
823 <listitem><para>There is a
824 <filename>bitbake-diffsigs</filename> command that
825 can process <filename>.sigdata</filename> and
826 <filename>.siginfo</filename> files.
827 If you specify one of these files, BitBake dumps out
828 the dependency information in the file.
829 If you specify two files, BitBake compares the two
830 files and dumps out the differences between the two.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500831 This more easily helps answer the question of "What
832 changed between X and Y?"</para></listitem>
833 </itemizedlist>
834 </para>
835 </section>
836
837 <section id='invalidating-shared-state'>
838 <title>Invalidating Shared State</title>
839
840 <para>
841 The OpenEmbedded build system uses checksums and shared state
842 cache to avoid unnecessarily rebuilding tasks.
843 Collectively, this scheme is known as "shared state code."
844 </para>
845
846 <para>
847 As with all schemes, this one has some drawbacks.
848 It is possible that you could make implicit changes to your
849 code that the checksum calculations do not take into
850 account.
851 These implicit changes affect a task's output but do not trigger
852 the shared state code into rebuilding a recipe.
853 Consider an example during which a tool changes its output.
854 Assume that the output of <filename>rpmdeps</filename> changes.
855 The result of the change should be that all the
856 <filename>package</filename> and
857 <filename>package_write_rpm</filename> shared state cache
858 items become invalid.
859 However, because the change to the output is
860 external to the code and therefore implicit,
861 the associated shared state cache items do not become
862 invalidated.
863 In this case, the build process uses the cached items rather
864 than running the task again.
865 Obviously, these types of implicit changes can cause problems.
866 </para>
867
868 <para>
869 To avoid these problems during the build, you need to
870 understand the effects of any changes you make.
871 Realize that changes you make directly to a function
872 are automatically factored into the checksum calculation.
873 Thus, these explicit changes invalidate the associated area of
874 shared state cache.
875 However, you need to be aware of any implicit changes that
876 are not obvious changes to the code and could affect the output
877 of a given task.
878 </para>
879
880 <para>
881 When you identify an implicit change, you can easily take steps
882 to invalidate the cache and force the tasks to run.
883 The steps you can take are as simple as changing a function's
884 comments in the source code.
885 For example, to invalidate package shared state files, change
886 the comment statements of
887 <link linkend='ref-tasks-package'><filename>do_package</filename></link>
888 or the comments of one of the functions it calls.
889 Even though the change is purely cosmetic, it causes the
890 checksum to be recalculated and forces the OpenEmbedded build
891 system to run the task again.
892 </para>
893
894 <note>
895 For an example of a commit that makes a cosmetic change to
896 invalidate shared state, see this
897 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
898 </note>
899 </section>
900 </section>
901</section>
902
903<section id='x32'>
904 <title>x32</title>
905
906 <para>
907 x32 is a processor-specific Application Binary Interface (psABI) for x86_64.
908 An ABI defines the calling conventions between functions in a processing environment.
909 The interface determines what registers are used and what the sizes are for various C data types.
910 </para>
911
912 <para>
913 Some processing environments prefer using 32-bit applications even when running
914 on Intel 64-bit platforms.
915 Consider the i386 psABI, which is a very old 32-bit ABI for Intel 64-bit platforms.
916 The i386 psABI does not provide efficient use and access of the Intel 64-bit processor resources,
917 leaving the system underutilized.
918 Now consider the x86_64 psABI.
919 This ABI is newer and uses 64-bits for data sizes and program pointers.
920 The extra bits increase the footprint size of the programs, libraries,
921 and also increases the memory and file system size requirements.
922 Executing under the x32 psABI enables user programs to utilize CPU and system resources
923 more efficiently while keeping the memory footprint of the applications low.
924 Extra bits are used for registers but not for addressing mechanisms.
925 </para>
926
927 <section id='support'>
928 <title>Support</title>
929
930 <para>
931 This Yocto Project release supports the final specifications of x32
932 psABI.
933 Support for x32 psABI exists as follows:
934 <itemizedlist>
935 <listitem><para>You can create packages and images in x32 psABI format on x86_64 architecture targets.
936 </para></listitem>
937 <listitem><para>You can successfully build many recipes with the x32 toolchain.</para></listitem>
938 <listitem><para>You can create and boot <filename>core-image-minimal</filename> and
939 <filename>core-image-sato</filename> images.</para></listitem>
940 </itemizedlist>
941 </para>
942 </section>
943
944 <section id='completing-x32'>
945 <title>Completing x32</title>
946
947 <para>
948 Future Plans for the x32 psABI in the Yocto Project include the following:
949 <itemizedlist>
950 <listitem><para>Enhance and fix the few remaining recipes so they
951 work with and support x32 toolchains.</para></listitem>
952 <listitem><para>Enhance RPM Package Manager (RPM) support for x32 binaries.</para></listitem>
953 <listitem><para>Support larger images.</para></listitem>
954 </itemizedlist>
955 </para>
956 </section>
957
958 <section id='using-x32-right-now'>
959 <title>Using x32 Right Now</title>
960
961 <para>
962 Follow these steps to use the x32 spABI:
963 <itemizedlist>
964 <listitem><para>Enable the x32 psABI tuning file for <filename>x86_64</filename>
965 machines by editing the <filename>conf/local.conf</filename> like this:
966 <literallayout class='monospaced'>
967 MACHINE = "qemux86-64"
968 DEFAULTTUNE = "x86-64-x32"
969 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE', True) \
970 or 'INVALID'), True) or 'lib'}"
971 #MACHINE = "genericx86"
972 #DEFAULTTUNE = "core2-64-x32"
973 </literallayout></para></listitem>
974 <listitem><para>As usual, use BitBake to build an image that supports the x32 psABI.
975 Here is an example:
976 <literallayout class='monospaced'>
977 $ bitbake core-image-sato
978 </literallayout></para></listitem>
979 <listitem><para>As usual, run your image using QEMU:
980 <literallayout class='monospaced'>
981 $ runqemu qemux86-64 core-image-sato
982 </literallayout></para></listitem>
983 </itemizedlist>
984 </para>
985 </section>
986</section>
987
988<section id="wayland">
989 <title>Wayland</title>
990
991 <para>
992 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
993 is a computer display server protocol that
994 provides a method for compositing window managers to communicate
995 directly with applications and video hardware and expects them to
996 communicate with input hardware using other libraries.
997 Using Wayland with supporting targets can result in better control
998 over graphics frame rendering than an application might otherwise
999 achieve.
1000 </para>
1001
1002 <para>
1003 The Yocto Project provides the Wayland protocol libraries and the
1004 reference
1005 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
1006 compositor as part of its release.
1007 This section describes what you need to do to implement Wayland and
1008 use the compositor when building an image for a supporting target.
1009 </para>
1010
1011 <section id="wayland-support">
1012 <title>Support</title>
1013
1014 <para>
1015 The Wayland protocol libraries and the reference Weston compositor
1016 ship as integrated packages in the <filename>meta</filename> layer
1017 of the
1018 <ulink url='&YOCTO_DOCS_DEV_URL;#source-directory'>Source Directory</ulink>.
1019 Specifically, you can find the recipes that build both Wayland
1020 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
1021 </para>
1022
1023 <para>
1024 You can build both the Wayland and Weston packages for use only
1025 with targets that accept the
1026 <ulink url='http://dri.freedesktop.org/wiki/'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
1027 which is also known as Mesa DRI.
1028 This implies that you cannot build and use the packages if your
1029 target uses, for example, the
1030 <trademark class='registered'>Intel</trademark> Embedded Media and
1031 Graphics Driver (<trademark class='registered'>Intel</trademark>
1032 EMGD) that overrides Mesa DRI.
1033 </para>
1034
1035 <note>
1036 Due to lack of EGL support, Weston 1.0.3 will not run directly on
1037 the emulated QEMU hardware.
1038 However, this version of Weston will run under X emulation without
1039 issues.
1040 </note>
1041 </section>
1042
1043 <section id="enabling-wayland-in-an-image">
1044 <title>Enabling Wayland in an Image</title>
1045
1046 <para>
1047 To enable Wayland, you need to enable it to be built and enable
1048 it to be included in the image.
1049 </para>
1050
1051 <section id="enable-building">
1052 <title>Building</title>
1053
1054 <para>
1055 To cause Mesa to build the <filename>wayland-egl</filename>
1056 platform and Weston to build Wayland with Kernel Mode
1057 Setting
1058 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
1059 support, include the "wayland" flag in the
1060 <link linkend="var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></link>
1061 statement in your <filename>local.conf</filename> file:
1062 <literallayout class='monospaced'>
1063 DISTRO_FEATURES_append = " wayland"
1064 </literallayout>
1065 </para>
1066
1067 <note>
1068 If X11 has been enabled elsewhere, Weston will build Wayland
1069 with X11 support
1070 </note>
1071 </section>
1072
1073 <section id="enable-installation-in-an-image">
1074 <title>Installing</title>
1075
1076 <para>
1077 To install the Wayland feature into an image, you must
1078 include the following
1079 <link linkend='var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></link>
1080 statement in your <filename>local.conf</filename> file:
1081 <literallayout class='monospaced'>
1082 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
1083 </literallayout>
1084 </para>
1085 </section>
1086 </section>
1087
1088 <section id="running-weston">
1089 <title>Running Weston</title>
1090
1091 <para>
1092 To run Weston inside X11, enabling it as described earlier and
1093 building a Sato image is sufficient.
1094 If you are running your image under Sato, a Weston Launcher appears
1095 in the "Utility" category.
1096 </para>
1097
1098 <para>
1099 Alternatively, you can run Weston through the command-line
1100 interpretor (CLI), which is better suited for development work.
1101 To run Weston under the CLI, you need to do the following after
1102 your image is built:
1103 <orderedlist>
1104 <listitem><para>Run these commands to export
1105 <filename>XDG_RUNTIME_DIR</filename>:
1106 <literallayout class='monospaced'>
1107 mkdir -p /tmp/$USER-weston
1108 chmod 0700 /tmp/$USER-weston
1109 export XDG_RUNTIME_DIR=/tmp/$USER-weston
1110 </literallayout></para></listitem>
1111 <listitem><para>Launch Weston in the shell:
1112 <literallayout class='monospaced'>
1113 weston
1114 </literallayout></para></listitem>
1115 </orderedlist>
1116 </para>
1117 </section>
1118</section>
1119
1120<section id="licenses">
1121 <title>Licenses</title>
1122
1123 <para>
1124 This section describes the mechanism by which the OpenEmbedded build system
1125 tracks changes to licensing text.
1126 The section also describes how to enable commercially licensed recipes,
1127 which by default are disabled.
1128 </para>
1129
1130 <para>
1131 For information that can help you maintain compliance with various open
1132 source licensing during the lifecycle of the product, see the
1133 "<ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-open-source-license-compliance-during-your-products-lifecycle'>Maintaining Open Source License Compliance During Your Project's Lifecycle</ulink>" section
1134 in the Yocto Project Development Manual.
1135 </para>
1136
1137 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
1138 <title>Tracking License Changes</title>
1139
1140 <para>
1141 The license of an upstream project might change in the future.
1142 In order to prevent these changes going unnoticed, the
1143 <filename><link linkend='var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</link></filename>
1144 variable tracks changes to the license text. The checksums are validated at the end of the
1145 configure step, and if the checksums do not match, the build will fail.
1146 </para>
1147
1148 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
1149 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
1150
1151 <para>
1152 The <filename>LIC_FILES_CHKSUM</filename>
1153 variable contains checksums of the license text in the source code for the recipe.
1154 Following is an example of how to specify <filename>LIC_FILES_CHKSUM</filename>:
1155 <literallayout class='monospaced'>
1156 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
1157 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
1158 file://licfile2.txt;endline=50;md5=zzzz \
1159 ..."
1160 </literallayout>
1161 </para>
1162
1163 <para>
1164 The build system uses the
1165 <filename><link linkend='var-S'>S</link></filename> variable as
1166 the default directory when searching files listed in
1167 <filename>LIC_FILES_CHKSUM</filename>.
1168 The previous example employs the default directory.
1169 </para>
1170
1171 <para>
1172 Consider this next example:
1173 <literallayout class='monospaced'>
1174 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
1175 md5=bb14ed3c4cda583abc85401304b5cd4e"
1176 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
1177 </literallayout>
1178 </para>
1179
1180 <para>
1181 The first line locates a file in
1182 <filename>${S}/src/ls.c</filename>.
1183 The second line refers to a file in
1184 <filename><link linkend='var-WORKDIR'>WORKDIR</link></filename>.
1185 </para>
1186 <para>
1187 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
1188 mandatory for all recipes, unless the
1189 <filename>LICENSE</filename> variable is set to "CLOSED".
1190 </para>
1191 </section>
1192
1193 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
1194 <title>Explanation of Syntax</title>
1195 <para>
1196 As mentioned in the previous section, the
1197 <filename>LIC_FILES_CHKSUM</filename> variable lists all the
1198 important files that contain the license text for the source code.
1199 It is possible to specify a checksum for an entire file, or a specific section of a
1200 file (specified by beginning and ending line numbers with the "beginline" and "endline"
1201 parameters, respectively).
1202 The latter is useful for source files with a license notice header,
1203 README documents, and so forth.
1204 If you do not use the "beginline" parameter, then it is assumed that the text begins on the
1205 first line of the file.
1206 Similarly, if you do not use the "endline" parameter, it is assumed that the license text
1207 ends with the last line of the file.
1208 </para>
1209
1210 <para>
1211 The "md5" parameter stores the md5 checksum of the license text.
1212 If the license text changes in any way as compared to this parameter
1213 then a mismatch occurs.
1214 This mismatch triggers a build failure and notifies the developer.
1215 Notification allows the developer to review and address the license text changes.
1216 Also note that if a mismatch occurs during the build, the correct md5
1217 checksum is placed in the build log and can be easily copied to the recipe.
1218 </para>
1219
1220 <para>
1221 There is no limit to how many files you can specify using the
1222 <filename>LIC_FILES_CHKSUM</filename> variable.
1223 Generally, however, every project requires a few specifications for license tracking.
1224 Many projects have a "COPYING" file that stores the license information for all the source
1225 code files.
1226 This practice allows you to just track the "COPYING" file as long as it is kept up to date.
1227 </para>
1228
1229 <tip>
1230 If you specify an empty or invalid "md5" parameter, BitBake returns an md5 mis-match
1231 error and displays the correct "md5" parameter value during the build.
1232 The correct parameter is also captured in the build log.
1233 </tip>
1234
1235 <tip>
1236 If the whole file contains only license text, you do not need to use the "beginline" and
1237 "endline" parameters.
1238 </tip>
1239 </section>
1240 </section>
1241
1242 <section id="enabling-commercially-licensed-recipes">
1243 <title>Enabling Commercially Licensed Recipes</title>
1244
1245 <para>
1246 By default, the OpenEmbedded build system disables
1247 components that have commercial or other special licensing
1248 requirements.
1249 Such requirements are defined on a
1250 recipe-by-recipe basis through the
1251 <link linkend='var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></link>
1252 variable definition in the affected recipe.
1253 For instance, the
1254 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
1255 recipe contains the following statement:
1256 <literallayout class='monospaced'>
1257 LICENSE_FLAGS = "commercial"
1258 </literallayout>
1259 Here is a slightly more complicated example that contains both an
1260 explicit recipe name and version (after variable expansion):
1261 <literallayout class='monospaced'>
1262 LICENSE_FLAGS = "license_${PN}_${PV}"
1263 </literallayout>
1264 In order for a component restricted by a <filename>LICENSE_FLAGS</filename>
1265 definition to be enabled and included in an image, it
1266 needs to have a matching entry in the global
1267 <link linkend='var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></link>
1268 variable, which is a variable
1269 typically defined in your <filename>local.conf</filename> file.
1270 For example, to enable
1271 the <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
1272 package, you could add either the string
1273 "commercial_gst-plugins-ugly" or the more general string
1274 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
1275 See the
1276 "<link linkend='license-flag-matching'>License Flag Matching</link>" section
1277 for a full explanation of how <filename>LICENSE_FLAGS</filename> matching works.
1278 Here is the example:
1279 <literallayout class='monospaced'>
1280 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
1281 </literallayout>
1282 Likewise, to additionally enable the package built from the recipe containing
1283 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>, and assuming
1284 that the actual recipe name was <filename>emgd_1.10.bb</filename>,
1285 the following string would enable that package as well as
1286 the original <filename>gst-plugins-ugly</filename> package:
1287 <literallayout class='monospaced'>
1288 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
1289 </literallayout>
1290 As a convenience, you do not need to specify the complete license string
1291 in the whitelist for every package.
1292 You can use an abbreviated form, which consists
1293 of just the first portion or portions of the license string before
1294 the initial underscore character or characters.
1295 A partial string will match
1296 any license that contains the given string as the first
1297 portion of its license.
1298 For example, the following
1299 whitelist string will also match both of the packages
1300 previously mentioned as well as any other packages that have
1301 licenses starting with "commercial" or "license".
1302 <literallayout class='monospaced'>
1303 LICENSE_FLAGS_WHITELIST = "commercial license"
1304 </literallayout>
1305 </para>
1306
1307 <section id="license-flag-matching">
1308 <title>License Flag Matching</title>
1309
1310 <para>
1311 License flag matching allows you to control what recipes the
1312 OpenEmbedded build system includes in the build.
1313 Fundamentally, the build system attempts to match
1314 <link linkend='var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></link>
1315 strings found in recipes against
1316 <link linkend='var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></link>
1317 strings found in the whitelist.
1318 A match causes the build system to include a recipe in the
1319 build, while failure to find a match causes the build system to
1320 exclude a recipe.
1321 </para>
1322
1323 <para>
1324 In general, license flag matching is simple.
1325 However, understanding some concepts will help you
1326 correctly and effectively use matching.
1327 </para>
1328
1329 <para>
1330 Before a flag
1331 defined by a particular recipe is tested against the
1332 contents of the whitelist, the expanded string
1333 <filename>_${PN}</filename> is appended to the flag.
1334 This expansion makes each <filename>LICENSE_FLAGS</filename>
1335 value recipe-specific.
1336 After expansion, the string is then matched against the
1337 whitelist.
1338 Thus, specifying
1339 <filename>LICENSE_FLAGS = "commercial"</filename>
1340 in recipe "foo", for example, results in the string
1341 <filename>"commercial_foo"</filename>.
1342 And, to create a match, that string must appear in the
1343 whitelist.
1344 </para>
1345
1346 <para>
1347 Judicious use of the <filename>LICENSE_FLAGS</filename>
1348 strings and the contents of the
1349 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
1350 allows you a lot of flexibility for including or excluding
1351 recipes based on licensing.
1352 For example, you can broaden the matching capabilities by
1353 using license flags string subsets in the whitelist.
1354 <note>When using a string subset, be sure to use the part of
1355 the expanded string that precedes the appended underscore
1356 character (e.g. <filename>usethispart_1.3</filename>,
1357 <filename>usethispart_1.4</filename>, and so forth).
1358 </note>
1359 For example, simply specifying the string "commercial" in
1360 the whitelist matches any expanded
1361 <filename>LICENSE_FLAGS</filename> definition that starts with
1362 the string "commercial" such as "commercial_foo" and
1363 "commercial_bar", which are the strings the build system
1364 automatically generates for hypothetical recipes named
1365 "foo" and "bar" assuming those recipes simply specify the
1366 following:
1367 <literallayout class='monospaced'>
1368 LICENSE_FLAGS = "commercial"
1369 </literallayout>
1370 Thus, you can choose to exhaustively
1371 enumerate each license flag in the whitelist and
1372 allow only specific recipes into the image, or
1373 you can use a string subset that causes a broader range of
1374 matches to allow a range of recipes into the image.
1375 </para>
1376
1377 <para>
1378 This scheme works even if the
1379 <filename>LICENSE_FLAGS</filename> string already
1380 has <filename>_${PN}</filename> appended.
1381 For example, the build system turns the license flag
1382 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would
1383 match both the general "commercial" and the specific
1384 "commercial_1.2_foo" strings found in the whitelist, as
1385 expected.
1386 </para>
1387
1388 <para>
1389 Here are some other scenarios:
1390 <itemizedlist>
1391 <listitem><para>You can specify a versioned string in the
1392 recipe such as "commercial_foo_1.2" in a "foo" recipe.
1393 The build system expands this string to
1394 "commercial_foo_1.2_foo".
1395 Combine this license flag with a whitelist that has
1396 the string "commercial" and you match the flag along
1397 with any other flag that starts with the string
1398 "commercial".</para></listitem>
1399 <listitem><para>Under the same circumstances, you can
1400 use "commercial_foo" in the whitelist and the
1401 build system not only matches "commercial_foo_1.2" but
1402 also matches any license flag with the string
1403 "commercial_foo", regardless of the version.
1404 </para></listitem>
1405 <listitem><para>You can be very specific and use both the
1406 package and version parts in the whitelist (e.g.
1407 "commercial_foo_1.2") to specifically match a
1408 versioned recipe.</para></listitem>
1409 </itemizedlist>
1410 </para>
1411 </section>
1412
1413 <section id="other-variables-related-to-commercial-licenses">
1414 <title>Other Variables Related to Commercial Licenses</title>
1415
1416 <para>
1417 Other helpful variables related to commercial
1418 license handling exist and are defined in the
1419 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
1420 <literallayout class='monospaced'>
1421 COMMERCIAL_AUDIO_PLUGINS ?= ""
1422 COMMERCIAL_VIDEO_PLUGINS ?= ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001423 </literallayout>
1424 If you want to enable these components, you can do so by making sure you have
1425 statements similar to the following
1426 in your <filename>local.conf</filename> configuration file:
1427 <literallayout class='monospaced'>
1428 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
1429 gst-plugins-ugly-mpegaudioparse"
1430 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
1431 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001432 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
1433 </literallayout>
1434 Of course, you could also create a matching whitelist
1435 for those components using the more general "commercial"
1436 in the whitelist, but that would also enable all the
1437 other packages with
1438 <link linkend='var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></link>
1439 containing "commercial", which you may or may not want:
1440 <literallayout class='monospaced'>
1441 LICENSE_FLAGS_WHITELIST = "commercial"
1442 </literallayout>
1443 </para>
1444
1445 <para>
1446 Specifying audio and video plug-ins as part of the
1447 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
1448 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001449 (along with the enabling
1450 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001451 plug-ins or components into built images, thus adding
1452 support for media formats or components.
1453 </para>
1454 </section>
1455 </section>
1456</section>
1457</chapter>
1458<!--
1459vim: expandtab tw=80 ts=4
1460-->