blob: f0836e8b1d1d177218da6cf573e7e5d30ba3d6cd [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='extendpoky'>
6
7<title>Common Tasks</title>
8 <para>
9 This chapter describes fundamental procedures such as creating layers,
10 adding new software packages, extending or customizing images,
11 porting work to new hardware (adding a new machine), and so forth.
12 You will find that the procedures documented here occur often in the
13 development cycle using the Yocto Project.
14 </para>
15
16 <section id="understanding-and-creating-layers">
17 <title>Understanding and Creating Layers</title>
18
19 <para>
20 The OpenEmbedded build system supports organizing
21 <link linkend='metadata'>Metadata</link> into multiple layers.
22 Layers allow you to isolate different types of customizations from
23 each other.
24 You might find it tempting to keep everything in one layer when
25 working on a single project.
26 However, the more modular your Metadata, the easier
27 it is to cope with future changes.
28 </para>
29
30 <para>
31 To illustrate how layers are used to keep things modular, consider
32 machine customizations.
33 These types of customizations typically reside in a special layer,
34 rather than a general layer, called a Board Support Package (BSP)
35 Layer.
36 Furthermore, the machine customizations should be isolated from
37 recipes and Metadata that support a new GUI environment,
38 for example.
39 This situation gives you a couple of layers: one for the machine
40 configurations, and one for the GUI environment.
41 It is important to understand, however, that the BSP layer can
42 still make machine-specific additions to recipes within the GUI
43 environment layer without polluting the GUI layer itself
44 with those machine-specific changes.
45 You can accomplish this through a recipe that is a BitBake append
46 (<filename>.bbappend</filename>) file, which is described later
47 in this section.
48 </para>
49
50 <para>
51 </para>
52
53 <section id='yocto-project-layers'>
54 <title>Layers</title>
55
56 <para>
57 The <link linkend='source-directory'>Source Directory</link>
58 contains both general layers and BSP
59 layers right out of the box.
60 You can easily identify layers that ship with a
61 Yocto Project release in the Source Directory by their
62 folder names.
63 Folders that represent layers typically have names that begin with
64 the string <filename>meta-</filename>.
65 <note>
66 It is not a requirement that a layer name begin with the
67 prefix <filename>meta-</filename>, but it is a commonly
68 accepted standard in the Yocto Project community.
69 </note>
70 For example, when you set up the Source Directory structure,
71 you will see several layers:
72 <filename>meta</filename>,
73 <filename>meta-skeleton</filename>,
74 <filename>meta-selftest</filename>,
75 <filename>meta-yocto</filename>, and
76 <filename>meta-yocto-bsp</filename>.
77 Each of these folders represents a distinct layer.
78 </para>
79
80 <para>
81 As another example, if you set up a local copy of the
82 <filename>meta-intel</filename> Git repository
83 and then explore the folder of that general layer,
84 you will discover many Intel-specific BSP layers inside.
85 For more information on BSP layers, see the
86 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
87 section in the Yocto Project Board Support Package (BSP)
88 Developer's Guide.
89 </para>
90 </section>
91
92 <section id='creating-your-own-layer'>
93 <title>Creating Your Own Layer</title>
94
95 <para>
96 It is very easy to create your own layers to use with the
97 OpenEmbedded build system.
98 The Yocto Project ships with scripts that speed up creating
99 general layers and BSP layers.
100 This section describes the steps you perform by hand to create
101 a layer so that you can better understand them.
102 For information about the layer-creation scripts, see the
103 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>"
104 section in the Yocto Project Board Support Package (BSP)
105 Developer's Guide and the
106 "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
107 section further down in this manual.
108 </para>
109
110 <para>
111 Follow these general steps to create your layer:
112 <orderedlist>
113 <listitem><para><emphasis>Check Existing Layers:</emphasis>
114 Before creating a new layer, you should be sure someone
115 has not already created a layer containing the Metadata
116 you need.
117 You can see the
118 <ulink url='http://layers.openembedded.org/layerindex/layers/'><filename>OpenEmbedded Metadata Index</filename></ulink>
119 for a list of layers from the OpenEmbedded community
120 that can be used in the Yocto Project.
121 </para></listitem>
122 <listitem><para><emphasis>Create a Directory:</emphasis>
123 Create the directory for your layer.
124 While not strictly required, prepend the name of the
125 folder with the string <filename>meta-</filename>.
126 For example:
127 <literallayout class='monospaced'>
128 meta-mylayer
129 meta-GUI_xyz
130 meta-mymachine
131 </literallayout>
132 </para></listitem>
133 <listitem><para><emphasis>Create a Layer Configuration
134 File:</emphasis>
135 Inside your new layer folder, you need to create a
136 <filename>conf/layer.conf</filename> file.
137 It is easiest to take an existing layer configuration
138 file and copy that to your layer's
139 <filename>conf</filename> directory and then modify the
140 file as needed.</para>
141 <para>The
142 <filename>meta-yocto-bsp/conf/layer.conf</filename> file
143 demonstrates the required syntax:
144 <literallayout class='monospaced'>
145 # We have a conf and classes directory, add to BBPATH
146 BBPATH .= ":${LAYERDIR}"
147
148 # We have recipes-* directories, add to BBFILES
149 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
150 ${LAYERDIR}/recipes-*/*/*.bbappend"
151
152 BBFILE_COLLECTIONS += "yoctobsp"
153 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
154 BBFILE_PRIORITY_yoctobsp = "5"
155 LAYERVERSION_yoctobsp = "3"
156 </literallayout></para>
157 <para>Here is an explanation of the example:
158 <itemizedlist>
159 <listitem><para>The configuration and
160 classes directory is appended to
161 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>.
162 <note>
163 All non-distro layers, which include all BSP
164 layers, are expected to append the layer
165 directory to the
166 <filename>BBPATH</filename>.
167 On the other hand, distro layers, such as
168 <filename>meta-yocto</filename>, can choose
169 to enforce their own precedence over
170 <filename>BBPATH</filename>.
171 For an example of that syntax, see the
172 <filename>layer.conf</filename> file for
173 the <filename>meta-yocto</filename> layer.
174 </note></para></listitem>
175 <listitem><para>The recipes for the layers are
176 appended to
177 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'>BBFILES</ulink></filename>.
178 </para></listitem>
179 <listitem><para>The
180 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'>BBFILE_COLLECTIONS</ulink></filename>
181 variable is then appended with the layer name.
182 </para></listitem>
183 <listitem><para>The
184 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'>BBFILE_PATTERN</ulink></filename>
185 variable is set to a regular expression and is
186 used to match files from
187 <filename>BBFILES</filename> into a particular
188 layer.
189 In this case,
190 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename>
191 is used to make <filename>BBFILE_PATTERN</filename> match within the
192 layer's path.</para></listitem>
193 <listitem><para>The
194 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'>BBFILE_PRIORITY</ulink></filename>
195 variable then assigns a priority to the layer.
196 Applying priorities is useful in situations
197 where the same recipe might appear in multiple
198 layers and allows you to choose the layer
199 that takes precedence.</para></listitem>
200 <listitem><para>The
201 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'>LAYERVERSION</ulink></filename>
202 variable optionally specifies the version of a
203 layer as a single number.</para></listitem>
204 </itemizedlist></para>
205 <para>Note the use of the
206 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename>
207 variable, which expands to the directory of the current
208 layer.</para>
209 <para>Through the use of the <filename>BBPATH</filename>
210 variable, BitBake locates class files
211 (<filename>.bbclass</filename>),
212 configuration files, and files that are included
213 with <filename>include</filename> and
214 <filename>require</filename> statements.
215 For these cases, BitBake uses the first file that
216 matches the name found in <filename>BBPATH</filename>.
217 This is similar to the way the <filename>PATH</filename>
218 variable is used for binaries.
219 It is recommended, therefore, that you use unique
220 class and configuration
221 filenames in your custom layer.</para></listitem>
222 <listitem><para><emphasis>Add Content:</emphasis> Depending
223 on the type of layer, add the content.
224 If the layer adds support for a machine, add the machine
225 configuration in a <filename>conf/machine/</filename>
226 file within the layer.
227 If the layer adds distro policy, add the distro
228 configuration in a <filename>conf/distro/</filename>
229 file within the layer.
230 If the layer introduces new recipes, put the recipes
231 you need in <filename>recipes-*</filename>
232 subdirectories within the layer.
233 <note>In order to be compliant with the Yocto Project,
234 a layer must contain a
235 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout-readme'>README file.</ulink>
236 </note></para></listitem>
237 </orderedlist>
238 </para>
239 </section>
240
241 <section id='best-practices-to-follow-when-creating-layers'>
242 <title>Best Practices to Follow When Creating Layers</title>
243
244 <para>
245 To create layers that are easier to maintain and that will
246 not impact builds for other machines, you should consider the
247 information in the following sections.
248 </para>
249
250 <section id='avoid-overlaying-entire-recipes'>
251 <title>Avoid "Overlaying" Entire Recipes</title>
252
253 <para>
254 Avoid "overlaying" entire recipes from other layers in your
255 configuration.
256 In other words, do not copy an entire recipe into your
257 layer and then modify it.
258 Rather, use an append file (<filename>.bbappend</filename>)
259 to override
260 only those parts of the original recipe you need to modify.
261 </para>
262 </section>
263
264 <section id='avoid-duplicating-include-files'>
265 <title>Avoid Duplicating Include Files</title>
266
267 <para>
268 Avoid duplicating include files.
269 Use append files (<filename>.bbappend</filename>)
270 for each recipe
271 that uses an include file.
272 Or, if you are introducing a new recipe that requires
273 the included file, use the path relative to the original
274 layer directory to refer to the file.
275 For example, use
276 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
277 instead of <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
278 If you're finding you have to overlay the include file,
279 it could indicate a deficiency in the include file in
280 the layer to which it originally belongs.
281 If this is the case, you should try to address that
282 deficiency instead of overlaying the include file.
283 For example, you could address this by getting the
284 maintainer of the include file to add a variable or
285 variables to make it easy to override the parts needing
286 to be overridden.
287 </para>
288 </section>
289
290 <section id='structure-your-layers'>
291 <title>Structure Your Layers</title>
292
293 <para>
294 Proper use of overrides within append files and placement
295 of machine-specific files within your layer can ensure that
296 a build is not using the wrong Metadata and negatively
297 impacting a build for a different machine.
298 Following are some examples:
299 <itemizedlist>
300 <listitem><para><emphasis>Modifying Variables to Support
301 a Different Machine:</emphasis>
302 Suppose you have a layer named
303 <filename>meta-one</filename> that adds support
304 for building machine "one".
305 To do so, you use an append file named
306 <filename>base-files.bbappend</filename> and
307 create a dependency on "foo" by altering the
308 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
309 variable:
310 <literallayout class='monospaced'>
311 DEPENDS = "foo"
312 </literallayout>
313 The dependency is created during any build that
314 includes the layer
315 <filename>meta-one</filename>.
316 However, you might not want this dependency
317 for all machines.
318 For example, suppose you are building for
319 machine "two" but your
320 <filename>bblayers.conf</filename> file has the
321 <filename>meta-one</filename> layer included.
322 During the build, the
323 <filename>base-files</filename> for machine
324 "two" will also have the dependency on
325 <filename>foo</filename>.</para>
326 <para>To make sure your changes apply only when
327 building machine "one", use a machine override
328 with the <filename>DEPENDS</filename> statement:
329 <literallayout class='monospaced'>
330 DEPENDS_one = "foo"
331 </literallayout>
332 You should follow the same strategy when using
333 <filename>_append</filename> and
334 <filename>_prepend</filename> operations:
335 <literallayout class='monospaced'>
336 DEPENDS_append_one = " foo"
337 DEPENDS_prepend_one = "foo "
338 </literallayout>
339 As an actual example, here's a line from the recipe for
340 the OProfile profiler, which lists an extra build-time
341 dependency when building specifically for 64-bit PowerPC:
342 <literallayout class='monospaced'>
343 DEPENDS_append_powerpc64 = " libpfm4"
344 </literallayout>
345 <note>
346 Avoiding "+=" and "=+" and using
347 machine-specific
348 <filename>_append</filename>
349 and <filename>_prepend</filename> operations
350 is recommended as well.
351 </note></para></listitem>
352 <listitem><para><emphasis>Place Machine-Specific Files
353 in Machine-Specific Locations:</emphasis>
354 When you have a base recipe, such as
355 <filename>base-files.bb</filename>, that
356 contains a
357 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
358 statement to a file, you can use an append file
359 to cause the build to use your own version of
360 the file.
361 For example, an append file in your layer at
362 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
363 could extend
364 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
365 using
366 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
367 as follows:
368 <literallayout class='monospaced'>
369 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
370 </literallayout>
371 The build for machine "one" will pick up your
372 machine-specific file as long as you have the
373 file in
374 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
375 However, if you are building for a different
376 machine and the
377 <filename>bblayers.conf</filename> file includes
378 the <filename>meta-one</filename> layer and
379 the location of your machine-specific file is
380 the first location where that file is found
381 according to <filename>FILESPATH</filename>,
382 builds for all machines will also use that
383 machine-specific file.</para>
384 <para>You can make sure that a machine-specific
385 file is used for a particular machine by putting
386 the file in a subdirectory specific to the
387 machine.
388 For example, rather than placing the file in
389 <filename>meta-one/recipes-core/base-files/base-files/</filename>
390 as shown above, put it in
391 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
392 Not only does this make sure the file is used
393 only when building for machine "one", but the
394 build process locates the file more quickly.</para>
395 <para>In summary, you need to place all files
396 referenced from <filename>SRC_URI</filename>
397 in a machine-specific subdirectory within the
398 layer in order to restrict those files to
399 machine-specific builds.</para></listitem>
400 </itemizedlist>
401 </para>
402 </section>
403
404 <section id='other-recommendations'>
405 <title>Other Recommendations</title>
406
407 <para>
408 We also recommend the following:
409 <itemizedlist>
410 <listitem><para>Store custom layers in a Git repository
411 that uses the
412 <filename>meta-<replaceable>layer_name</replaceable></filename> format.
413 </para></listitem>
414 <listitem><para>Clone the repository alongside other
415 <filename>meta</filename> directories in the
416 <link linkend='source-directory'>Source Directory</link>.
417 </para></listitem>
418 </itemizedlist>
419 Following these recommendations keeps your Source Directory and
420 its configuration entirely inside the Yocto Project's core
421 base.
422 </para>
423 </section>
424 </section>
425
426 <section id='enabling-your-layer'>
427 <title>Enabling Your Layer</title>
428
429 <para>
430 Before the OpenEmbedded build system can use your new layer,
431 you need to enable it.
432 To enable your layer, simply add your layer's path to the
433 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
434 variable in your <filename>conf/bblayers.conf</filename> file,
435 which is found in the
436 <link linkend='build-directory'>Build Directory</link>.
437 The following example shows how to enable a layer named
438 <filename>meta-mylayer</filename>:
439 <literallayout class='monospaced'>
440 LCONF_VERSION = "6"
441
442 BBPATH = "${TOPDIR}"
443 BBFILES ?= ""
444
445 BBLAYERS ?= " \
446 $HOME/poky/meta \
447 $HOME/poky/meta-yocto \
448 $HOME/poky/meta-yocto-bsp \
449 $HOME/poky/meta-mylayer \
450 "
451 </literallayout>
452 </para>
453
454 <para>
455 BitBake parses each <filename>conf/layer.conf</filename> file
456 as specified in the <filename>BBLAYERS</filename> variable
457 within the <filename>conf/bblayers.conf</filename> file.
458 During the processing of each
459 <filename>conf/layer.conf</filename> file, BitBake adds the
460 recipes, classes and configurations contained within the
461 particular layer to the source directory.
462 </para>
463 </section>
464
465 <section id='using-bbappend-files'>
466 <title>Using .bbappend Files</title>
467
468 <para>
469 Recipes used to append Metadata to other recipes are called
470 BitBake append files.
471 BitBake append files use the <filename>.bbappend</filename> file
472 type suffix, while the corresponding recipes to which Metadata
473 is being appended use the <filename>.bb</filename> file type
474 suffix.
475 </para>
476
477 <para>
478 A <filename>.bbappend</filename> file allows your layer to make
479 additions or changes to the content of another layer's recipe
480 without having to copy the other recipe into your layer.
481 Your <filename>.bbappend</filename> file resides in your layer,
482 while the main <filename>.bb</filename> recipe file to
483 which you are appending Metadata resides in a different layer.
484 </para>
485
486 <para>
487 Append files must have the same root names as their corresponding
488 recipes.
489 For example, the append file
490 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
491 <filename>someapp_&DISTRO;.bb</filename>.
492 This means the original recipe and append file names are version
493 number-specific.
494 If the corresponding recipe is renamed to update to a newer
495 version, the corresponding <filename>.bbappend</filename> file must
496 be renamed (and possibly updated) as well.
497 During the build process, BitBake displays an error on starting
498 if it detects a <filename>.bbappend</filename> file that does
499 not have a corresponding recipe with a matching name.
500 See the
501 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
502 variable for information on how to handle this error.
503 </para>
504
505 <para>
506 Being able to append information to an existing recipe not only
507 avoids duplication, but also automatically applies recipe
508 changes in a different layer to your layer.
509 If you were copying recipes, you would have to manually merge
510 changes as they occur.
511 </para>
512
513 <para>
514 As an example, consider the main formfactor recipe and a
515 corresponding formfactor append file both from the
516 <link linkend='source-directory'>Source Directory</link>.
517 Here is the main formfactor recipe, which is named
518 <filename>formfactor_0.0.bb</filename> and located in the
519 "meta" layer at
520 <filename>meta/recipes-bsp/formfactor</filename>:
521 <literallayout class='monospaced'>
522 SUMMARY = "Device formfactor information"
523 SECTION = "base"
524 LICENSE = "MIT"
525 LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
526 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
527 PR = "r45"
528
529 SRC_URI = "file://config file://machconfig"
530 S = "${WORKDIR}"
531
532 PACKAGE_ARCH = "${MACHINE_ARCH}"
533 INHIBIT_DEFAULT_DEPS = "1"
534
535 do_install() {
536 # Install file only if it has contents
537 install -d ${D}${sysconfdir}/formfactor/
538 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
539 if [ -s "${S}/machconfig" ]; then
540 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
541 fi
542 }
543 </literallayout>
544 In the main recipe, note the
545 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
546 variable, which tells the OpenEmbedded build system where to
547 find files during the build.
548 </para>
549
550 <para>
551 Following is the append file, which is named
552 <filename>formfactor_0.0.bbappend</filename> and is from the
553 Emenlow BSP Layer named
554 <filename>meta-intel/meta-emenlow</filename>.
555 The file is in <filename>recipes-bsp/formfactor</filename>:
556 <literallayout class='monospaced'>
557 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
558 </literallayout>
559 </para>
560
561 <para>
562 By default, the build system uses the
563 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
564 variable to locate files.
565 This append file extends the locations by setting the
566 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
567 variable.
568 Setting this variable in the <filename>.bbappend</filename>
569 file is the most reliable and recommended method for adding
570 directories to the search path used by the build system
571 to find files.
572 </para>
573
574 <para>
575 The statement in this example extends the directories to include
576 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>,
577 which resolves to a directory named
578 <filename>formfactor</filename> in the same directory
579 in which the append file resides (i.e.
580 <filename>meta-intel/meta-emenlow/recipes-bsp/formfactor/formfactor</filename>.
581 This implies that you must have the supporting directory
582 structure set up that will contain any files or patches you
583 will be including from the layer.
584 </para>
585
586 <para>
587 Using the immediate expansion assignment operator
588 <filename>:=</filename> is important because of the reference to
589 <filename>THISDIR</filename>.
590 The trailing colon character is important as it ensures that
591 items in the list remain colon-separated.
592 <note>
593 <para>
594 BitBake automatically defines the
595 <filename>THISDIR</filename> variable.
596 You should never set this variable yourself.
597 Using "_prepend" as part of the
598 <filename>FILESEXTRAPATHS</filename> ensures your path
599 will be searched prior to other paths in the final
600 list.
601 </para>
602
603 <para>
604 Also, not all append files add extra files.
605 Many append files simply exist to add build options
606 (e.g. <filename>systemd</filename>).
607 For these cases, your append file would not even
608 use the <filename>FILESEXTRAPATHS</filename> statement.
609 </para>
610 </note>
611 </para>
612 </section>
613
614 <section id='prioritizing-your-layer'>
615 <title>Prioritizing Your Layer</title>
616
617 <para>
618 Each layer is assigned a priority value.
619 Priority values control which layer takes precedence if there
620 are recipe files with the same name in multiple layers.
621 For these cases, the recipe file from the layer with a higher
622 priority number takes precedence.
623 Priority values also affect the order in which multiple
624 <filename>.bbappend</filename> files for the same recipe are
625 applied.
626 You can either specify the priority manually, or allow the
627 build system to calculate it based on the layer's dependencies.
628 </para>
629
630 <para>
631 To specify the layer's priority manually, use the
632 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
633 variable.
634 For example:
635 <literallayout class='monospaced'>
636 BBFILE_PRIORITY_mylayer = "1"
637 </literallayout>
638 </para>
639
640 <note>
641 <para>It is possible for a recipe with a lower version number
642 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
643 in a layer that has a higher priority to take precedence.</para>
644 <para>Also, the layer priority does not currently affect the
645 precedence order of <filename>.conf</filename>
646 or <filename>.bbclass</filename> files.
647 Future versions of BitBake might address this.</para>
648 </note>
649 </section>
650
651 <section id='managing-layers'>
652 <title>Managing Layers</title>
653
654 <para>
655 You can use the BitBake layer management tool to provide a view
656 into the structure of recipes across a multi-layer project.
657 Being able to generate output that reports on configured layers
658 with their paths and priorities and on
659 <filename>.bbappend</filename> files and their applicable
660 recipes can help to reveal potential problems.
661 </para>
662
663 <para>
664 Use the following form when running the layer management tool.
665 <literallayout class='monospaced'>
666 $ bitbake-layers <replaceable>command</replaceable> [<replaceable>arguments</replaceable>]
667 </literallayout>
668 The following list describes the available commands:
669 <itemizedlist>
670 <listitem><para><filename><emphasis>help:</emphasis></filename>
671 Displays general help or help on a specified command.
672 </para></listitem>
673 <listitem><para><filename><emphasis>show-layers:</emphasis></filename>
674 Shows the current configured layers.
675 </para></listitem>
676 <listitem><para><filename><emphasis>show-recipes:</emphasis></filename>
677 Lists available recipes and the layers that provide them.
678 </para></listitem>
679 <listitem><para><filename><emphasis>show-overlayed:</emphasis></filename>
680 Lists overlayed recipes.
681 A recipe is overlayed when a recipe with the same name
682 exists in another layer that has a higher layer
683 priority.
684 </para></listitem>
685 <listitem><para><filename><emphasis>show-appends:</emphasis></filename>
686 Lists <filename>.bbappend</filename> files and the
687 recipe files to which they apply.
688 </para></listitem>
689 <listitem><para><filename><emphasis>show-cross-depends:</emphasis></filename>
690 Lists dependency relationships between recipes that
691 cross layer boundaries.
692 </para></listitem>
693 <listitem><para><filename><emphasis>add-layer:</emphasis></filename>
694 Adds a layer to <filename>bblayers.conf</filename>.
695 </para></listitem>
696 <listitem><para><filename><emphasis>remove-layer:</emphasis></filename>
697 Removes a layer from <filename>bblayers.conf</filename>
698 </para></listitem>
699 <listitem><para><filename><emphasis>flatten:</emphasis></filename>
700 Flattens the layer configuration into a separate output
701 directory.
702 Flattening your layer configuration builds a "flattened"
703 directory that contains the contents of all layers,
704 with any overlayed recipes removed and any
705 <filename>.bbappend</filename> files appended to the
706 corresponding recipes.
707 You might have to perform some manual cleanup of the
708 flattened layer as follows:
709 <itemizedlist>
710 <listitem><para>Non-recipe files (such as patches)
711 are overwritten.
712 The flatten command shows a warning for these
713 files.
714 </para></listitem>
715 <listitem><para>Anything beyond the normal layer
716 setup has been added to the
717 <filename>layer.conf</filename> file.
718 Only the lowest priority layer's
719 <filename>layer.conf</filename> is used.
720 </para></listitem>
721 <listitem><para>Overridden and appended items from
722 <filename>.bbappend</filename> files need to be
723 cleaned up.
724 The contents of each
725 <filename>.bbappend</filename> end up in the
726 flattened recipe.
727 However, if there are appended or changed
728 variable values, you need to tidy these up
729 yourself.
730 Consider the following example.
731 Here, the <filename>bitbake-layers</filename>
732 command adds the line
733 <filename>#### bbappended ...</filename> so that
734 you know where the following lines originate:
735 <literallayout class='monospaced'>
736 ...
737 DESCRIPTION = "A useful utility"
738 ...
739 EXTRA_OECONF = "--enable-something"
740 ...
741
742 #### bbappended from meta-anotherlayer ####
743
744 DESCRIPTION = "Customized utility"
745 EXTRA_OECONF += "--enable-somethingelse"
746 </literallayout>
747 Ideally, you would tidy up these utilities as
748 follows:
749 <literallayout class='monospaced'>
750 ...
751 DESCRIPTION = "Customized utility"
752 ...
753 EXTRA_OECONF = "--enable-something --enable-somethingelse"
754 ...
755 </literallayout></para></listitem>
756 </itemizedlist></para></listitem>
757 </itemizedlist>
758 </para>
759 </section>
760
761 <section id='creating-a-general-layer-using-the-yocto-layer-script'>
762 <title>Creating a General Layer Using the yocto-layer Script</title>
763
764 <para>
765 The <filename>yocto-layer</filename> script simplifies
766 creating a new general layer.
767 <note>
768 For information on BSP layers, see the
769 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
770 section in the Yocto Project Board Specific (BSP)
771 Developer's Guide.
772 </note>
773 The default mode of the script's operation is to prompt you for
774 information needed to generate the layer:
775 <itemizedlist>
776 <listitem><para>The layer priority.
777 </para></listitem>
778 <listitem><para>Whether or not to create a sample recipe.
779 </para></listitem>
780 <listitem><para>Whether or not to create a sample
781 append file.
782 </para></listitem>
783 </itemizedlist>
784 </para>
785
786 <para>
787 Use the <filename>yocto-layer create</filename> sub-command
788 to create a new general layer.
789 In its simplest form, you can create a layer as follows:
790 <literallayout class='monospaced'>
791 $ yocto-layer create mylayer
792 </literallayout>
793 The previous example creates a layer named
794 <filename>meta-mylayer</filename> in the current directory.
795 </para>
796
797 <para>
798 As the <filename>yocto-layer create</filename> command runs,
799 default values for the prompts appear in brackets.
800 Pressing enter without supplying anything for the prompts
801 or pressing enter and providing an invalid response causes the
802 script to accept the default value.
803 Once the script completes, the new layer
804 is created in the current working directory.
805 The script names the layer by prepending
806 <filename>meta-</filename> to the name you provide.
807 </para>
808
809 <para>
810 Minimally, the script creates the following within the layer:
811 <itemizedlist>
812 <listitem><para><emphasis>The <filename>conf</filename>
813 directory:</emphasis>
814 This directory contains the layer's configuration file.
815 The root name for the file is the same as the root name
816 your provided for the layer (e.g.
817 <filename><replaceable>layer</replaceable>.conf</filename>).
818 </para></listitem>
819 <listitem><para><emphasis>The
820 <filename>COPYING.MIT</filename> file:</emphasis>
821 The copyright and use notice for the software.
822 </para></listitem>
823 <listitem><para><emphasis>The <filename>README</filename>
824 file:</emphasis>
825 A file describing the contents of your new layer.
826 </para></listitem>
827 </itemizedlist>
828 </para>
829
830 <para>
831 If you choose to generate a sample recipe file, the script
832 prompts you for the name for the recipe and then creates it
833 in <filename><replaceable>layer</replaceable>/recipes-example/example/</filename>.
834 The script creates a <filename>.bb</filename> file and a
835 directory, which contains a sample
836 <filename>helloworld.c</filename> source file, along with
837 a sample patch file.
838 If you do not provide a recipe name, the script uses
839 "example".
840 </para>
841
842 <para>
843 If you choose to generate a sample append file, the script
844 prompts you for the name for the file and then creates it
845 in <filename><replaceable>layer</replaceable>/recipes-example-bbappend/example-bbappend/</filename>.
846 The script creates a <filename>.bbappend</filename> file and a
847 directory, which contains a sample patch file.
848 If you do not provide a recipe name, the script uses
849 "example".
850 The script also prompts you for the version of the append file.
851 The version should match the recipe to which the append file
852 is associated.
853 </para>
854
855 <para>
856 The easiest way to see how the <filename>yocto-layer</filename>
857 script works is to experiment with the script.
858 You can also read the usage information by entering the
859 following:
860 <literallayout class='monospaced'>
861 $ yocto-layer help
862 </literallayout>
863 </para>
864
865 <para>
866 Once you create your general layer, you must add it to your
867 <filename>bblayers.conf</filename> file.
868 Here is an example where a layer named
869 <filename>meta-mylayer</filename> is added:
870 <literallayout class='monospaced'>
871 BBLAYERS = ?" \
872 /usr/local/src/yocto/meta \
873 /usr/local/src/yocto/meta-yocto \
874 /usr/local/src/yocto/meta-yocto-bsp \
875 /usr/local/src/yocto/meta-mylayer \
876 "
877 </literallayout>
878 Adding the layer to this file enables the build system to
879 locate the layer during the build.
880 </para>
881 </section>
882 </section>
883
884 <section id='usingpoky-extend-customimage'>
885 <title>Customizing Images</title>
886
887 <para>
888 You can customize images to satisfy particular requirements.
889 This section describes several methods and provides guidelines for each.
890 </para>
891
892 <section id='usingpoky-extend-customimage-localconf'>
893 <title>Customizing Images Using <filename>local.conf</filename></title>
894
895 <para>
896 Probably the easiest way to customize an image is to add a
897 package by way of the <filename>local.conf</filename>
898 configuration file.
899 Because it is limited to local use, this method generally only
900 allows you to add packages and is not as flexible as creating
901 your own customized image.
902 When you add packages using local variables this way, you need
903 to realize that these variable changes are in effect for every
904 build and consequently affect all images, which might not
905 be what you require.
906 </para>
907
908 <para>
909 To add a package to your image using the local configuration
910 file, use the
911 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
912 variable with the <filename>_append</filename> operator:
913 <literallayout class='monospaced'>
914 IMAGE_INSTALL_append = " strace"
915 </literallayout>
916 Use of the syntax is important - specifically, the space between
917 the quote and the package name, which is
918 <filename>strace</filename> in this example.
919 This space is required since the <filename>_append</filename>
920 operator does not add the space.
921 </para>
922
923 <para>
924 Furthermore, you must use <filename>_append</filename> instead
925 of the <filename>+=</filename> operator if you want to avoid
926 ordering issues.
927 The reason for this is because doing so unconditionally appends
928 to the variable and avoids ordering problems due to the
929 variable being set in image recipes and
930 <filename>.bbclass</filename> files with operators like
931 <filename>?=</filename>.
932 Using <filename>_append</filename> ensures the operation takes
933 affect.
934 </para>
935
936 <para>
937 As shown in its simplest use,
938 <filename>IMAGE_INSTALL_append</filename> affects all images.
939 It is possible to extend the syntax so that the variable
940 applies to a specific image only.
941 Here is an example:
942 <literallayout class='monospaced'>
943 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
944 </literallayout>
945 This example adds <filename>strace</filename> to the
946 <filename>core-image-minimal</filename> image only.
947 </para>
948
949 <para>
950 You can add packages using a similar approach through the
951 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
952 variable.
953 If you use this variable, only
954 <filename>core-image-*</filename> images are affected.
955 </para>
956 </section>
957
958 <section id='usingpoky-extend-customimage-imagefeatures'>
959 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
960 <filename>EXTRA_IMAGE_FEATURES</filename></title>
961
962 <para>
963 Another method for customizing your image is to enable or
964 disable high-level image features by using the
965 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
966 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
967 variables.
968 Although the functions for both variables are nearly equivalent,
969 best practices dictate using <filename>IMAGE_FEATURES</filename>
970 from within a recipe and using
971 <filename>EXTRA_IMAGE_FEATURES</filename> from within
972 your <filename>local.conf</filename> file, which is found in the
973 <link linkend='build-directory'>Build Directory</link>.
974 </para>
975
976 <para>
977 To understand how these features work, the best reference is
978 <filename>meta/classes/core-image.bbclass</filename>.
979 This class lists out the available
980 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
981 of which most map to package groups while some, such as
982 <filename>debug-tweaks</filename> and
983 <filename>read-only-rootfs</filename>, resolve as general
984 configuration settings.
985 </para>
986
987 <para>
988 In summary, the file looks at the contents of the
989 <filename>IMAGE_FEATURES</filename> variable and then maps
990 or configures the feature accordingly.
991 Based on this information, the build system automatically
992 adds the appropriate packages or configurations to the
993 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
994 variable.
995 Effectively, you are enabling extra features by extending the
996 class or creating a custom class for use with specialized image
997 <filename>.bb</filename> files.
998 </para>
999
1000 <para>
1001 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1002 from within your local configuration file.
1003 Using a separate area from which to enable features with
1004 this variable helps you avoid overwriting the features in the
1005 image recipe that are enabled with
1006 <filename>IMAGE_FEATURES</filename>.
1007 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1008 to <filename>IMAGE_FEATURES</filename> within
1009 <filename>meta/conf/bitbake.conf</filename>.
1010 </para>
1011
1012 <para>
1013 To illustrate how you can use these variables to modify your
1014 image, consider an example that selects the SSH server.
1015 The Yocto Project ships with two SSH servers you can use
1016 with your images: Dropbear and OpenSSH.
1017 Dropbear is a minimal SSH server appropriate for
1018 resource-constrained environments, while OpenSSH is a
1019 well-known standard SSH server implementation.
1020 By default, the <filename>core-image-sato</filename> image
1021 is configured to use Dropbear.
1022 The <filename>core-image-full-cmdline</filename> and
1023 <filename>core-image-lsb</filename> images both
1024 include OpenSSH.
1025 The <filename>core-image-minimal</filename> image does not
1026 contain an SSH server.
1027 </para>
1028
1029 <para>
1030 You can customize your image and change these defaults.
1031 Edit the <filename>IMAGE_FEATURES</filename> variable
1032 in your recipe or use the
1033 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1034 <filename>local.conf</filename> file so that it configures the
1035 image you are working with to include
1036 <filename>ssh-server-dropbear</filename> or
1037 <filename>ssh-server-openssh</filename>.
1038 </para>
1039
1040 <note>
1041 See the
1042 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1043 section in the Yocto Project Reference Manual for a complete
1044 list of image features that ship with the Yocto Project.
1045 </note>
1046 </section>
1047
1048 <section id='usingpoky-extend-customimage-custombb'>
1049 <title>Customizing Images Using Custom .bb Files</title>
1050
1051 <para>
1052 You can also customize an image by creating a custom recipe
1053 that defines additional software as part of the image.
1054 The following example shows the form for the two lines you need:
1055 <literallayout class='monospaced'>
1056 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1057
1058 inherit core-image
1059 </literallayout>
1060 </para>
1061
1062 <para>
1063 Defining the software using a custom recipe gives you total
1064 control over the contents of the image.
1065 It is important to use the correct names of packages in the
1066 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1067 variable.
1068 You must use the OpenEmbedded notation and not the Debian notation for the names
1069 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1070 </para>
1071
1072 <para>
1073 The other method for creating a custom image is to base it on an existing image.
1074 For example, if you want to create an image based on <filename>core-image-sato</filename>
1075 but add the additional package <filename>strace</filename> to the image,
1076 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1077 new <filename>.bb</filename> and add the following line to the end of the copy:
1078 <literallayout class='monospaced'>
1079 IMAGE_INSTALL += "strace"
1080 </literallayout>
1081 </para>
1082 </section>
1083
1084 <section id='usingpoky-extend-customimage-customtasks'>
1085 <title>Customizing Images Using Custom Package Groups</title>
1086
1087 <para>
1088 For complex custom images, the best approach for customizing
1089 an image is to create a custom package group recipe that is
1090 used to build the image or images.
1091 A good example of a package group recipe is
1092 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1093 </para>
1094
1095 <para>
1096 If you examine that recipe, you see that the
1097 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1098 variable lists the package group packages to produce.
1099 The <filename>inherit packagegroup</filename> statement
1100 sets appropriate default values and automatically adds
1101 <filename>-dev</filename>, <filename>-dbg</filename>, and
1102 <filename>-ptest</filename> complementary packages for each
1103 package specified in the <filename>PACKAGES</filename>
1104 statement.
1105 <note>
1106 The <filename>inherit packages</filename> should be
1107 located near the top of the recipe, certainly before
1108 the <filename>PACKAGES</filename> statement.
1109 </note>
1110 </para>
1111
1112 <para>
1113 For each package you specify in <filename>PACKAGES</filename>,
1114 you can use
1115 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1116 and
1117 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1118 entries to provide a list of packages the parent task package
1119 should contain.
1120 You can see examples of these further down in the
1121 <filename>packagegroup-base.bb</filename> recipe.
1122 </para>
1123
1124 <para>
1125 Here is a short, fabricated example showing the same basic
1126 pieces:
1127 <literallayout class='monospaced'>
1128 DESCRIPTION = "My Custom Package Groups"
1129
1130 inherit packagegroup
1131
1132 PACKAGES = "\
1133 packagegroup-custom-apps \
1134 packagegroup-custom-tools \
1135 "
1136
1137 RDEPENDS_packagegroup-custom-apps = "\
1138 dropbear \
1139 portmap \
1140 psplash"
1141
1142 RDEPENDS_packagegroup-custom-tools = "\
1143 oprofile \
1144 oprofileui-server \
1145 lttng-tools"
1146
1147 RRECOMMENDS_packagegroup-custom-tools = "\
1148 kernel-module-oprofile"
1149 </literallayout>
1150 </para>
1151
1152 <para>
1153 In the previous example, two package group packages are created with their dependencies and their
1154 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1155 <filename>packagegroup-custom-tools</filename>.
1156 To build an image using these package group packages, you need to add
1157 <filename>packagegroup-custom-apps</filename> and/or
1158 <filename>packagegroup-custom-tools</filename> to
1159 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1160 For other forms of image dependencies see the other areas of this section.
1161 </para>
1162 </section>
1163
1164 <section id='usingpoky-extend-customimage-image-name'>
1165 <title>Customizing an Image Hostname</title>
1166
1167 <para>
1168 By default, the configured hostname (i.e.
1169 <filename>/etc/hostname</filename>) in an image is the
1170 same as the machine name.
1171 For example, if
1172 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1173 equals "qemux86", the configured hostname written to
1174 <filename>/etc/hostname</filename> is "qemux86".
1175 </para>
1176
1177 <para>
1178 You can customize this name by altering the value of the
1179 "hostname" variable in the
1180 <filename>base-files</filename> recipe using either
1181 an append file or a configuration file.
1182 Use the following in an append file:
1183 <literallayout class='monospaced'>
1184 hostname="myhostname"
1185 </literallayout>
1186 Use the following in a configuration file:
1187 <literallayout class='monospaced'>
1188 hostname_pn-base-files = "myhostname"
1189 </literallayout>
1190 </para>
1191
1192 <para>
1193 Changing the default value of the variable "hostname" can be
1194 useful in certain situations.
1195 For example, suppose you need to do extensive testing on an
1196 image and you would like to easily identify the image
1197 under test from existing images with typical default
1198 hostnames.
1199 In this situation, you could change the default hostname to
1200 "testme", which results in all the images using the name
1201 "testme".
1202 Once testing is complete and you do not need to rebuild the
1203 image for test any longer, you can easily reset the default
1204 hostname.
1205 </para>
1206
1207 <para>
1208 Another point of interest is that if you unset the variable,
1209 the image will have no default hostname in the filesystem.
1210 Here is an example that unsets the variable in a
1211 configuration file:
1212 <literallayout class='monospaced'>
1213 hostname_pn-base-files = ""
1214 </literallayout>
1215 Having no default hostname in the filesystem is suitable for
1216 environments that use dynamic hostnames such as virtual
1217 machines.
1218 </para>
1219 </section>
1220 </section>
1221
1222 <section id='new-recipe-writing-a-new-recipe'>
1223 <title>Writing a New Recipe</title>
1224
1225 <para>
1226 Recipes (<filename>.bb</filename> files) are fundamental components
1227 in the Yocto Project environment.
1228 Each software component built by the OpenEmbedded build system
1229 requires a recipe to define the component.
1230 This section describes how to create, write, and test a new
1231 recipe.
1232 <note>
1233 For information on variables that are useful for recipes and
1234 for information about recipe naming issues, see the
1235 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1236 section of the Yocto Project Reference Manual.
1237 </note>
1238 </para>
1239
1240 <section id='new-recipe-overview'>
1241 <title>Overview</title>
1242
1243 <para>
1244 The following figure shows the basic process for creating a
1245 new recipe.
1246 The remainder of the section provides details for the steps.
1247 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1248 </para>
1249 </section>
1250
1251 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1252 <title>Locate or Automatically Create a Base Recipe</title>
1253
1254 <para>
1255 You can always write a recipe from scratch.
1256 However, two choices exist that can help you quickly get a
1257 start on a new recipe:
1258 <itemizedlist>
1259 <listitem><para><emphasis><filename>recipetool</filename>:</emphasis>
1260 A tool provided by the Yocto Project that automates
1261 creation of a base recipe based on the source
1262 files.
1263 </para></listitem>
1264 <listitem><para><emphasis>Existing Recipes:</emphasis>
1265 Location and modification of an existing recipe that is
1266 similar in function to the recipe you need.
1267 </para></listitem>
1268 </itemizedlist>
1269 </para>
1270
1271 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1272 <title>Creating the Base Recipe Using <filename>recipetool</filename></title>
1273
1274 <para>
1275 <filename>recipetool</filename> automates creation of
1276 a base recipe given a set of source code files.
1277 As long as you can extract or point to the source files,
1278 the tool will construct a recipe and automatically
1279 configure all pre-build information into the recipe.
1280 For example, suppose you have an application that builds
1281 using Autotools.
1282 Creating the base recipe using
1283 <filename>recipetool</filename> results in a recipe
1284 that has the pre-build dependencies, license requirements,
1285 and checksums configured.
1286 </para>
1287
1288 <para>
1289 To run the tool, you just need to be in your
1290 <link linkend='build-directory'>Build Directory</link>
1291 and have sourced the build environment setup script
1292 (i.e.
1293 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
1294 or
1295 <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>).
1296 Here is the basic <filename>recipetool</filename> syntax:
1297 <note>
1298 Running <filename>recipetool -h</filename> or
1299 <filename>recipetool create -h</filename> produces the
1300 Python-generated help, which presented differently
1301 than what follows here.
1302 </note>
1303 <literallayout class='monospaced'>
1304 recipetool -h
1305 recipetool create [-h]
1306 recipetool [-d] [-q] [--color auto | always | never ] create -o <replaceable>OUTFILE</replaceable> [-m] [-x <replaceable>EXTERNALSRC</replaceable>] <replaceable>source</replaceable>
1307
1308 -d Enables debug output.
1309 -q Outputs only errors (quiet mode).
1310 --color Colorizes the output automatically, always, or never.
1311 -h Displays Python generated syntax for recipetool.
1312 create Causes recipetool to create a base recipe. The create
1313 command is further defined with these options:
1314
1315 -o <replaceable>OUTFILE</replaceable> Specifies the full path and filename for the generated
1316 recipe.
1317 -m Causes the recipe to be machine-specific rather than
1318 architecture-specific (default).
1319 -x <replaceable>EXTERNALSRC</replaceable> Fetches and extracts source files from <replaceable>source</replaceable>
1320 and places them in <replaceable>EXTERNALSRC</replaceable>.
1321 <replaceable>source</replaceable> must be a URL.
1322 -h Displays Python-generated syntax for create.
1323 <replaceable>source</replaceable> Specifies the source code on which to base the
1324 recipe.
1325 </literallayout>
1326 </para>
1327
1328 <para>
1329 Running <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
1330 creates the base recipe and locates it properly in the
1331 layer that contains your source files.
1332 Following are some syntax examples:
1333 </para>
1334
1335 <para>
1336 Use this syntax to generate a recipe based on <replaceable>source</replaceable>.
1337 Once generated, the recipe resides in the existing source
1338 code layer:
1339 <literallayout class='monospaced'>
1340 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1341 </literallayout>
1342 Use this syntax to generate a recipe using code that you
1343 extract from <replaceable>source</replaceable>.
1344 The extracted code is placed in its own layer defined
1345 by <replaceable>EXTERNALSRC</replaceable>.
1346 <literallayout class='monospaced'>
1347 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1348 </literallayout>
1349 Use this syntax to generate a recipe based on <replaceable>source</replaceable>.
1350 The options direct <filename>recipetool</filename> to
1351 run in "quiet mode" and to generate debugging information.
1352 Once generated, the recipe resides in the existing source
1353 code layer:
1354 <literallayout class='monospaced'>
1355 recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
1356 </literallayout>
1357 </para>
1358 </section>
1359
1360 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1361 <title>Locating and Using a Similar Recipe</title>
1362
1363 <para>
1364 Before writing a recipe from scratch, it is often useful to
1365 discover whether someone else has already written one that
1366 meets (or comes close to meeting) your needs.
1367 The Yocto Project and OpenEmbedded communities maintain many
1368 recipes that might be candidates for what you are doing.
1369 You can find a good central index of these recipes in the
1370 <ulink url='http://layers.openembedded.org'>OpenEmbedded metadata index</ulink>.
1371 </para>
1372
1373 <para>
1374 Working from an existing recipe or a skeleton recipe is the
1375 best way to get started.
1376 Here are some points on both methods:
1377 <itemizedlist>
1378 <listitem><para><emphasis>Locate and modify a recipe that
1379 is close to what you want to do:</emphasis>
1380 This method works when you are familiar with the
1381 current recipe space.
1382 The method does not work so well for those new to
1383 the Yocto Project or writing recipes.</para>
1384 <para>Some risks associated with this method are
1385 using a recipe that has areas totally unrelated to
1386 what you are trying to accomplish with your recipe,
1387 not recognizing areas of the recipe that you might
1388 have to add from scratch, and so forth.
1389 All these risks stem from unfamiliarity with the
1390 existing recipe space.</para></listitem>
1391 <listitem><para><emphasis>Use and modify the following
1392 skeleton recipe:</emphasis>
1393 If for some reason you do not want to use
1394 <filename>recipetool</filename> and you cannot
1395 find an existing recipe that is close to meeting
1396 your needs, you can use the following structure to
1397 provide the fundamental areas of a new recipe.
1398 <literallayout class='monospaced'>
1399 DESCRIPTION = ""
1400 HOMEPAGE = ""
1401 LICENSE = ""
1402 SECTION = ""
1403 DEPENDS = ""
1404 LIC_FILES_CHKSUM = ""
1405
1406 SRC_URI = ""
1407 </literallayout>
1408 </para></listitem>
1409 </itemizedlist>
1410 </para>
1411 </section>
1412 </section>
1413
1414 <section id='new-recipe-storing-and-naming-the-recipe'>
1415 <title>Storing and Naming the Recipe</title>
1416
1417 <para>
1418 Once you have your base recipe, you should put it in your
1419 own layer and name it appropriately.
1420 Locating it correctly ensures that the OpenEmbedded build
1421 system can find it when you use BitBake to process the
1422 recipe.
1423 </para>
1424
1425 <itemizedlist>
1426 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1427 The OpenEmbedded build system locates your recipe
1428 through the layer's <filename>conf/layer.conf</filename>
1429 file and the
1430 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1431 variable.
1432 This variable sets up a path from which the build system can
1433 locate recipes.
1434 Here is the typical use:
1435 <literallayout class='monospaced'>
1436 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1437 ${LAYERDIR}/recipes-*/*/*.bbappend"
1438 </literallayout>
1439 Consequently, you need to be sure you locate your new recipe
1440 inside your layer such that it can be found.</para>
1441 <para>You can find more information on how layers are
1442 structured in the
1443 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1444 section.</para></listitem>
1445 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1446 When you name your recipe, you need to follow this naming
1447 convention:
1448 <literallayout class='monospaced'>
1449 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1450 </literallayout>
1451 Use lower-cased characters and do not include the reserved
1452 suffixes <filename>-native</filename>,
1453 <filename>-cross</filename>, <filename>-initial</filename>,
1454 or <filename>-dev</filename> casually (i.e. do not use them
1455 as part of your recipe name unless the string applies).
1456 Here are some examples:
1457 <literallayout class='monospaced'>
1458 cups_1.7.0.bb
1459 gawk_4.0.2.bb
1460 irssi_0.8.16-rc1.bb
1461 </literallayout></para></listitem>
1462 </itemizedlist>
1463 </section>
1464
1465 <section id='understanding-recipe-syntax'>
1466 <title>Understanding Recipe Syntax</title>
1467
1468 <para>
1469 Understanding recipe file syntax is important for
1470 writing recipes.
1471 The following list overviews the basic items that make up a
1472 BitBake recipe file.
1473 For more complete BitBake syntax descriptions, see the
1474 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
1475 chapter of the BitBake User Manual.
1476 <itemizedlist>
1477 <listitem><para><emphasis>Variable Assignments and Manipulations:</emphasis>
1478 Variable assignments allow a value to be assigned to a
1479 variable.
1480 The assignment can be static text or might include
1481 the contents of other variables.
1482 In addition to the assignment, appending and prepending
1483 operations are also supported.</para>
1484 <para>The following example shows some of the ways
1485 you can use variables in recipes:
1486 <literallayout class='monospaced'>
1487 S = "${WORKDIR}/postfix-${PV}"
1488 CFLAGS += "-DNO_ASM"
1489 SRC_URI_append = " file://fixup.patch"
1490 </literallayout>
1491 </para></listitem>
1492 <listitem><para><emphasis>Functions:</emphasis>
1493 Functions provide a series of actions to be performed.
1494 You usually use functions to override the default
1495 implementation of a task function or to complement
1496 a default function (i.e. append or prepend to an
1497 existing function).
1498 Standard functions use <filename>sh</filename> shell
1499 syntax, although access to OpenEmbedded variables and
1500 internal methods are also available.</para>
1501 <para>The following is an example function from the
1502 <filename>sed</filename> recipe:
1503 <literallayout class='monospaced'>
1504 do_install () {
1505 autotools_do_install
1506 install -d ${D}${base_bindir}
1507 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
1508 rmdir ${D}${bindir}/
1509 }
1510 </literallayout>
1511 It is also possible to implement new functions that
1512 are called between existing tasks as long as the
1513 new functions are not replacing or complementing the
1514 default functions.
1515 You can implement functions in Python
1516 instead of shell.
1517 Both of these options are not seen in the majority of
1518 recipes.</para></listitem>
1519 <listitem><para><emphasis>Keywords:</emphasis>
1520 BitBake recipes use only a few keywords.
1521 You use keywords to include common
1522 functions (<filename>inherit</filename>), load parts
1523 of a recipe from other files
1524 (<filename>include</filename> and
1525 <filename>require</filename>) and export variables
1526 to the environment (<filename>export</filename>).</para>
1527 <para>The following example shows the use of some of
1528 these keywords:
1529 <literallayout class='monospaced'>
1530 export POSTCONF = "${STAGING_BINDIR}/postconf"
1531 inherit autoconf
1532 require otherfile.inc
1533 </literallayout>
1534 </para></listitem>
1535 <listitem><para><emphasis>Comments:</emphasis>
1536 Any lines that begin with the hash character
1537 (<filename>#</filename>) are treated as comment lines
1538 and are ignored:
1539 <literallayout class='monospaced'>
1540 # This is a comment
1541 </literallayout>
1542 </para></listitem>
1543 </itemizedlist>
1544 </para>
1545
1546 <para>
1547 This next list summarizes the most important and most commonly
1548 used parts of the recipe syntax.
1549 For more information on these parts of the syntax, you can
1550 reference the
1551 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
1552 chapter in the BitBake User Manual.
1553 <itemizedlist>
1554 <listitem><para><emphasis>Line Continuation: <filename>\</filename></emphasis> -
1555 Use the backward slash (<filename>\</filename>)
1556 character to split a statement over multiple lines.
1557 Place the slash character at the end of the line that
1558 is to be continued on the next line:
1559 <literallayout class='monospaced'>
1560 VAR = "A really long \
1561 line"
1562 </literallayout>
1563 <note>
1564 You cannot have any characters including spaces
1565 or tabs after the slash character.
1566 </note>
1567 </para></listitem>
1568 <listitem><para><emphasis>Using Variables: <filename>${...}</filename></emphasis> -
1569 Use the <filename>${<replaceable>varname</replaceable>}</filename> syntax to
1570 access the contents of a variable:
1571 <literallayout class='monospaced'>
1572 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
1573 </literallayout>
1574 </para></listitem>
1575 <listitem><para><emphasis>Quote All Assignments: <filename>"<replaceable>value</replaceable>"</filename></emphasis> -
1576 Use double quotes around the value in all variable
1577 assignments.
1578 <literallayout class='monospaced'>
1579 VAR1 = "${OTHERVAR}"
1580 VAR2 = "The version is ${PV}"
1581 </literallayout>
1582 </para></listitem>
1583 <listitem><para><emphasis>Conditional Assignment: <filename>?=</filename></emphasis> -
1584 Conditional assignment is used to assign a value to
1585 a variable, but only when the variable is currently
1586 unset.
1587 Use the question mark followed by the equal sign
1588 (<filename>?=</filename>) to make a "soft" assignment
1589 used for conditional assignment.
1590 Typically, "soft" assignments are used in the
1591 <filename>local.conf</filename> file for variables
1592 that are allowed to come through from the external
1593 environment.
1594 </para>
1595 <para>Here is an example where
1596 <filename>VAR1</filename> is set to "New value" if
1597 it is currently empty.
1598 However, if <filename>VAR1</filename> has already been
1599 set, it remains unchanged:
1600 <literallayout class='monospaced'>
1601 VAR1 ?= "New value"
1602 </literallayout>
1603 In this next example, <filename>VAR1</filename>
1604 is left with the value "Original value":
1605 <literallayout class='monospaced'>
1606 VAR1 = "Original value"
1607 VAR1 ?= "New value"
1608 </literallayout>
1609 </para></listitem>
1610 <listitem><para><emphasis>Appending: <filename>+=</filename></emphasis> -
1611 Use the plus character followed by the equals sign
1612 (<filename>+=</filename>) to append values to existing
1613 variables.
1614 <note>
1615 This operator adds a space between the existing
1616 content of the variable and the new content.
1617 </note></para>
1618 <para>Here is an example:
1619 <literallayout class='monospaced'>
1620 SRC_URI += "file://fix-makefile.patch"
1621 </literallayout>
1622 </para></listitem>
1623 <listitem><para><emphasis>Prepending: <filename>=+</filename></emphasis> -
1624 Use the equals sign followed by the plus character
1625 (<filename>=+</filename>) to prepend values to existing
1626 variables.
1627 <note>
1628 This operator adds a space between the new content
1629 and the existing content of the variable.
1630 </note></para>
1631 <para>Here is an example:
1632 <literallayout class='monospaced'>
1633 VAR =+ "Starts"
1634 </literallayout>
1635 </para></listitem>
1636 <listitem><para><emphasis>Appending: <filename>_append</filename></emphasis> -
1637 Use the <filename>_append</filename> operator to
1638 append values to existing variables.
1639 This operator does not add any additional space.
1640 Also, the operator is applied after all the
1641 <filename>+=</filename>, and
1642 <filename>=+</filename> operators have been applied and
1643 after all <filename>=</filename> assignments have
1644 occurred.
1645 </para>
1646 <para>The following example shows the space being
1647 explicitly added to the start to ensure the appended
1648 value is not merged with the existing value:
1649 <literallayout class='monospaced'>
1650 SRC_URI_append = " file://fix-makefile.patch"
1651 </literallayout>
1652 You can also use the <filename>_append</filename>
1653 operator with overrides, which results in the actions
1654 only being performed for the specified target or
1655 machine:
1656 <literallayout class='monospaced'>
1657 SRC_URI_append_sh4 = " file://fix-makefile.patch"
1658 </literallayout>
1659 </para></listitem>
1660 <listitem><para><emphasis>Prepending: <filename>_prepend</filename></emphasis> -
1661 Use the <filename>_prepend</filename> operator to
1662 prepend values to existing variables.
1663 This operator does not add any additional space.
1664 Also, the operator is applied after all the
1665 <filename>+=</filename>, and
1666 <filename>=+</filename> operators have been applied and
1667 after all <filename>=</filename> assignments have
1668 occurred.
1669 </para>
1670 <para>The following example shows the space being
1671 explicitly added to the end to ensure the prepended
1672 value is not merged with the existing value:
1673 <literallayout class='monospaced'>
1674 CFLAGS_prepend = "-I${S}/myincludes "
1675 </literallayout>
1676 You can also use the <filename>_prepend</filename>
1677 operator with overrides, which results in the actions
1678 only being performed for the specified target or
1679 machine:
1680 <literallayout class='monospaced'>
1681 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
1682 </literallayout>
1683 </para></listitem>
1684 <listitem><para><emphasis>Overrides:</emphasis> -
1685 You can use overrides to set a value conditionally,
1686 typically based on how the recipe is being built.
1687 For example, to set the
1688 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
1689 variable's value to "standard/base" for any target
1690 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
1691 except for qemuarm where it should be set to
1692 "standard/arm-versatile-926ejs", you would do the
1693 following:
1694 <literallayout class='monospaced'>
1695 KBRANCH = "standard/base"
1696 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
1697 </literallayout>
1698 Overrides are also used to separate alternate values
1699 of a variable in other situations.
1700 For example, when setting variables such as
1701 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
1702 and
1703 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
1704 that are specific to individual packages produced by
1705 a recipe, you should always use an override that
1706 specifies the name of the package.
1707 </para></listitem>
1708 <listitem><para><emphasis>Indentation:</emphasis>
1709 Use spaces for indentation rather than than tabs.
1710 For shell functions, both currently work.
1711 However, it is a policy decision of the Yocto Project
1712 to use tabs in shell functions.
1713 Realize that some layers have a policy to use spaces
1714 for all indentation.
1715 </para></listitem>
1716 <listitem><para><emphasis>Using Python for Complex Operations: <filename>${@<replaceable>python_code</replaceable>}</filename></emphasis> -
1717 For more advanced processing, it is possible to use
1718 Python code during variable assignments (e.g.
1719 search and replacement on a variable).</para>
1720 <para>You indicate Python code using the
1721 <filename>${@<replaceable>python_code</replaceable>}</filename>
1722 syntax for the variable assignment:
1723 <literallayout class='monospaced'>
1724 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
1725 </literallayout>
1726 </para></listitem>
1727 <listitem><para><emphasis>Shell Function Syntax:</emphasis>
1728 Write shell functions as if you were writing a shell
1729 script when you describe a list of actions to take.
1730 You should ensure that your script works with a generic
1731 <filename>sh</filename> and that it does not require
1732 any <filename>bash</filename> or other shell-specific
1733 functionality.
1734 The same considerations apply to various system
1735 utilities (e.g. <filename>sed</filename>,
1736 <filename>grep</filename>, <filename>awk</filename>,
1737 and so forth) that you might wish to use.
1738 If in doubt, you should check with multiple
1739 implementations - including those from BusyBox.
1740 </para></listitem>
1741 </itemizedlist>
1742 </para>
1743 </section>
1744
1745 <section id='new-recipe-running-a-build-on-the-recipe'>
1746 <title>Running a Build on the Recipe</title>
1747
1748 <para>
1749 Creating a new recipe is usually an iterative process that
1750 requires using BitBake to process the recipe multiple times in
1751 order to progressively discover and add information to the
1752 recipe file.
1753 </para>
1754
1755 <para>
1756 Assuming you have sourced a build environment setup script (i.e.
1757 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
1758 or
1759 <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>)
1760 and you are in the
1761 <link linkend='build-directory'>Build Directory</link>,
1762 use BitBake to process your recipe.
1763 All you need to provide is the
1764 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1765 in the previous section:
1766 <literallayout class='monospaced'>
1767 $ bitbake <replaceable>basename</replaceable>
1768 </literallayout>
1769
1770 </para>
1771
1772 <para>
1773 During the build, the OpenEmbedded build system creates a
1774 temporary work directory for each recipe
1775 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1776 where it keeps extracted source files, log files, intermediate
1777 compilation and packaging files, and so forth.
1778 </para>
1779
1780 <para>
1781 The per-recipe temporary work directory is constructed as follows and
1782 depends on several factors:
1783 <literallayout class='monospaced'>
1784 BASE_WORKDIR ?= "${TMPDIR}/work"
1785 WORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}"
1786 </literallayout>
1787 As an example, assume a Source Directory top-level folder named
1788 <filename>poky</filename>, a default Build Directory at
1789 <filename>poky/build</filename>, and a
1790 <filename>qemux86-poky-linux</filename> machine target system.
1791 Furthermore, suppose your recipe is named
1792 <filename>foo_1.3.0.bb</filename>.
1793 In this case, the work directory the build system uses to
1794 build the package would be as follows:
1795 <literallayout class='monospaced'>
1796 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1797 </literallayout>
1798 Inside this directory you can find sub-directories such as
1799 <filename>image</filename>, <filename>packages-split</filename>,
1800 and <filename>temp</filename>.
1801 After the build, you can examine these to determine how well
1802 the build went.
1803 <note>
1804 You can find log files for each task in the recipe's
1805 <filename>temp</filename> directory (e.g.
1806 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1807 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1808 (e.g. <filename>log.do_configure</filename>,
1809 <filename>log.do_fetch</filename>, and
1810 <filename>log.do_compile</filename>).
1811 </note>
1812 </para>
1813
1814 <para>
1815 You can find more information about the build process in the
1816 "<ulink url='&YOCTO_DOCS_REF_URL;#closer-look'>A Closer Look at the Yocto Project Development Environment</ulink>"
1817 chapter of the Yocto Project Reference Manual.
1818 </para>
1819
1820 <para>
1821 You can also reference the following variables in the
1822 Yocto Project Reference Manual's glossary for more information:
1823 <itemizedlist>
1824 <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
1825 The top-level build output directory</listitem>
1826 <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
1827 The target system identifier</listitem>
1828 <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
1829 The recipe name</listitem>
1830 <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
1831 The epoch - (if
1832 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
1833 is not specified, which is usually the case for most
1834 recipes, then <filename>EXTENDPE</filename> is blank)</listitem>
1835 <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
1836 The recipe version</listitem>
1837 <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
1838 The recipe revision</listitem>
1839 </itemizedlist>
1840 </para>
1841 </section>
1842
1843 <section id='new-recipe-fetching-code'>
1844 <title>Fetching Code</title>
1845
1846 <para>
1847 The first thing your recipe must do is specify how to fetch
1848 the source files.
1849 Fetching is controlled mainly through the
1850 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1851 variable.
1852 Your recipe must have a <filename>SRC_URI</filename> variable
1853 that points to where the source is located.
1854 For a graphical representation of source locations, see the
1855 "<ulink url='&YOCTO_DOCS_REF_URL;#sources-dev-environment'>Sources</ulink>"
1856 section in the Yocto Project Reference Manual.
1857 </para>
1858
1859 <para>
1860 The
1861 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1862 task uses the prefix of each entry in the
1863 <filename>SRC_URI</filename> variable value to determine which
1864 fetcher to use to get your source files.
1865 It is the <filename>SRC_URI</filename> variable that triggers
1866 the fetcher.
1867 The
1868 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1869 task uses the variable after source is fetched to apply
1870 patches.
1871 The OpenEmbedded build system uses
1872 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1873 for scanning directory locations for local files in
1874 <filename>SRC_URI</filename>.
1875 </para>
1876
1877 <para>
1878 The <filename>SRC_URI</filename> variable in your recipe must
1879 define each unique location for your source files.
1880 It is good practice to not hard-code pathnames in an URL used
1881 in <filename>SRC_URI</filename>.
1882 Rather than hard-code these paths, use
1883 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1884 which causes the fetch process to use the version specified in
1885 the recipe filename.
1886 Specifying the version in this manner means that upgrading the
1887 recipe to a future version is as simple as renaming the recipe
1888 to match the new version.
1889 </para>
1890
1891 <para>
1892 Here is a simple example from the
1893 <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
1894 recipe where the source comes from a single tarball.
1895 Notice the use of the
1896 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1897 variable:
1898 <literallayout class='monospaced'>
1899 SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
1900 </literallayout>
1901 </para>
1902
1903 <para>
1904 Files mentioned in <filename>SRC_URI</filename> whose names end
1905 in a typical archive extension (e.g. <filename>.tar</filename>,
1906 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1907 <filename>.zip</filename>, and so forth), are automatically
1908 extracted during the
1909 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1910 task.
1911 For another example that specifies these types of files, see
1912 the
1913 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1914 section.
1915 </para>
1916
1917 <para>
1918 Another way of specifying source is from an SCM.
1919 For Git repositories, you must specify
1920 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1921 and you should specify
1922 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1923 to include the revision with
1924 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1925 Here is an example from the recipe
1926 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1927 <literallayout class='monospaced'>
1928 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1929
1930 PR = "r6"
1931 PV = "1.0.5+git${SRCPV}"
1932
1933 SRC_URI = "git://git.kernel.dk/blktrace.git \
1934 file://ldflags.patch"
1935 </literallayout>
1936 </para>
1937
1938 <para>
1939 If your <filename>SRC_URI</filename> statement includes
1940 URLs pointing to individual files fetched from a remote server
1941 other than a version control system, BitBake attempts to
1942 verify the files against checksums defined in your recipe to
1943 ensure they have not been tampered with or otherwise modified
1944 since the recipe was written.
1945 Two checksums are used:
1946 <filename>SRC_URI[md5sum]</filename> and
1947 <filename>SRC_URI[sha256sum]</filename>.
1948 </para>
1949
1950 <para>
1951 If your <filename>SRC_URI</filename> variable points to
1952 more than a single URL (excluding SCM URLs), you need to
1953 provide the <filename>md5</filename> and
1954 <filename>sha256</filename> checksums for each URL.
1955 For these cases, you provide a name for each URL as part of
1956 the <filename>SRC_URI</filename> and then reference that name
1957 in the subsequent checksum statements.
1958 Here is an example:
1959 <literallayout class='monospaced'>
1960 SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
1961 ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch
1962
1963 SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
1964 SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
1965
1966 SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
1967 SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
1968 </literallayout>
1969 </para>
1970
1971 <para>
1972 Proper values for <filename>md5</filename> and
1973 <filename>sha256</filename> checksums might be available
1974 with other signatures on the download page for the upstream
1975 source (e.g. <filename>md5</filename>,
1976 <filename>sha1</filename>, <filename>sha256</filename>,
1977 <filename>GPG</filename>, and so forth).
1978 Because the OpenEmbedded build system only deals with
1979 <filename>sha256sum</filename> and <filename>md5sum</filename>,
1980 you should verify all the signatures you find by hand.
1981 </para>
1982
1983 <para>
1984 If no <filename>SRC_URI</filename> checksums are specified
1985 when you attempt to build the recipe, or you provide an
1986 incorrect checksum, the build will produce an error for each
1987 missing or incorrect checksum.
1988 As part of the error message, the build system provides
1989 the checksum string corresponding to the fetched file.
1990 Once you have the correct checksums, you can copy and paste
1991 them into your recipe and then run the build again to continue.
1992 <note>
1993 As mentioned, if the upstream source provides signatures
1994 for verifying the downloaded source code, you should
1995 verify those manually before setting the checksum values
1996 in the recipe and continuing with the build.
1997 </note>
1998 </para>
1999
2000 <para>
2001 This final example is a bit more complicated and is from the
2002 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2003 recipe.
2004 The example's <filename>SRC_URI</filename> statement identifies
2005 multiple files as the source files for the recipe: a tarball, a
2006 patch file, a desktop file, and an icon.
2007 <literallayout class='monospaced'>
2008 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2009 file://xwc.patch \
2010 file://rxvt.desktop \
2011 file://rxvt.png"
2012 </literallayout>
2013 </para>
2014
2015 <para>
2016 When you specify local files using the
2017 <filename>file://</filename> URI protocol, the build system
2018 fetches files from the local machine.
2019 The path is relative to the
2020 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2021 variable and searches specific directories in a certain order:
2022 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2023 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2024 and <filename>files</filename>.
2025 The directories are assumed to be subdirectories of the
2026 directory in which the recipe or append file resides.
2027 For another example that specifies these types of files, see the
2028 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2029 section.
2030 </para>
2031
2032 <para>
2033 The previous example also specifies a patch file.
2034 Patch files are files whose names usually end in
2035 <filename>.patch</filename> or <filename>.diff</filename> but
2036 can end with compressed suffixes such as
2037 <filename>diff.gz</filename> and
2038 <filename>patch.bz2</filename>, for example.
2039 The build system automatically applies patches as described
2040 in the
2041 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2042 </para>
2043 </section>
2044
2045 <section id='new-recipe-unpacking-code'>
2046 <title>Unpacking Code</title>
2047
2048 <para>
2049 During the build, the
2050 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2051 task unpacks the source with
2052 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2053 pointing to where it is unpacked.
2054 </para>
2055
2056 <para>
2057 If you are fetching your source files from an upstream source
2058 archived tarball and the tarball's internal structure matches
2059 the common convention of a top-level subdirectory named
2060 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
2061 then you do not need to set <filename>S</filename>.
2062 However, if <filename>SRC_URI</filename> specifies to fetch
2063 source from an archive that does not use this convention,
2064 or from an SCM like Git or Subversion, your recipe needs to
2065 define <filename>S</filename>.
2066 </para>
2067
2068 <para>
2069 If processing your recipe using BitBake successfully unpacks
2070 the source files, you need to be sure that the directory
2071 pointed to by <filename>${S}</filename> matches the structure
2072 of the source.
2073 </para>
2074 </section>
2075
2076 <section id='new-recipe-patching-code'>
2077 <title>Patching Code</title>
2078
2079 <para>
2080 Sometimes it is necessary to patch code after it has been
2081 fetched.
2082 Any files mentioned in <filename>SRC_URI</filename> whose
2083 names end in <filename>.patch</filename> or
2084 <filename>.diff</filename> or compressed versions of these
2085 suffixes (e.g. <filename>diff.gz</filename> are treated as
2086 patches.
2087 The
2088 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2089 task automatically applies these patches.
2090 </para>
2091
2092 <para>
2093 The build system should be able to apply patches with the "-p1"
2094 option (i.e. one directory level in the path will be stripped
2095 off).
2096 If your patch needs to have more directory levels stripped off,
2097 specify the number of levels using the "striplevel" option in
2098 the <filename>SRC_URI</filename> entry for the patch.
2099 Alternatively, if your patch needs to be applied in a specific
2100 subdirectory that is not specified in the patch file, use the
2101 "patchdir" option in the entry.
2102 </para>
2103
2104 <para>
2105 As with all local files referenced in
2106 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2107 using <filename>file://</filename>, you should place
2108 patch files in a directory next to the recipe either
2109 named the same as the base name of the recipe
2110 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2111 and
2112 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2113 or "files".
2114 </para>
2115 </section>
2116
2117 <section id='new-recipe-licensing'>
2118 <title>Licensing</title>
2119
2120 <para>
2121 Your recipe needs to have both the
2122 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2123 and
2124 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2125 variables:
2126 <itemizedlist>
2127 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2128 This variable specifies the license for the software.
2129 If you do not know the license under which the software
2130 you are building is distributed, you should go to the
2131 source code and look for that information.
2132 Typical files containing this information include
2133 <filename>COPYING</filename>,
2134 <filename>LICENSE</filename>, and
2135 <filename>README</filename> files.
2136 You could also find the information near the top of
2137 a source file.
2138 For example, given a piece of software licensed under
2139 the GNU General Public License version 2, you would
2140 set <filename>LICENSE</filename> as follows:
2141 <literallayout class='monospaced'>
2142 LICENSE = "GPLv2"
2143 </literallayout></para>
2144 <para>The licenses you specify within
2145 <filename>LICENSE</filename> can have any name as long
2146 as you do not use spaces, since spaces are used as
2147 separators between license names.
2148 For standard licenses, use the names of the files in
2149 <filename>meta/files/common-licenses/</filename>
2150 or the <filename>SPDXLICENSEMAP</filename> flag names
2151 defined in <filename>meta/conf/licenses.conf</filename>.
2152 </para></listitem>
2153 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2154 The OpenEmbedded build system uses this variable to
2155 make sure the license text has not changed.
2156 If it has, the build produces an error and it affords
2157 you the chance to figure it out and correct the problem.
2158 </para>
2159 <para>You need to specify all applicable licensing
2160 files for the software.
2161 At the end of the configuration step, the build process
2162 will compare the checksums of the files to be sure
2163 the text has not changed.
2164 Any differences result in an error with the message
2165 containing the current checksum.
2166 For more explanation and examples of how to set the
2167 <filename>LIC_FILES_CHKSUM</filename> variable, see the
2168 "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>"
2169 section in the Yocto Project Reference Manual.</para>
2170 <para>To determine the correct checksum string, you
2171 can list the appropriate files in the
2172 <filename>LIC_FILES_CHKSUM</filename> variable with
2173 incorrect md5 strings, attempt to build the software,
2174 and then note the resulting error messages that will
2175 report the correct md5 strings.
2176 See the
2177 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2178 section for additional information.
2179 </para>
2180
2181 <para>
2182 Here is an example that assumes the software has a
2183 <filename>COPYING</filename> file:
2184 <literallayout class='monospaced'>
2185 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2186 </literallayout>
2187 When you try to build the software, the build system
2188 will produce an error and give you the correct string
2189 that you can substitute into the recipe file for a
2190 subsequent build.
2191 </para></listitem>
2192 </itemizedlist>
2193 </para>
2194
2195<!--
2196
2197 <para>
2198 For trying this out I created a new recipe named
2199 <filename>htop_1.0.2.bb</filename> and put it in
2200 <filename>poky/meta/recipes-extended/htop</filename>.
2201 There are two license type statements in my very simple
2202 recipe:
2203 <literallayout class='monospaced'>
2204 LICENSE = ""
2205
2206 LIC_FILES_CHKSUM = ""
2207
2208 SRC_URI[md5sum] = ""
2209 SRC_URI[sha256sum] = ""
2210 </literallayout>
2211 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2212 Next, you delete or comment out the two <filename>SRC_URI</filename>
2213 lines at the end and then attempt to build the software with
2214 <filename>bitbake htop</filename>.
2215 Doing so causes BitBake to report some errors and and give
2216 you the actual strings you need for the last two
2217 <filename>SRC_URI</filename> lines.
2218 Prior to this, you have to dig around in the home page of the
2219 source for <filename>htop</filename> and determine that the
2220 software is released under GPLv2.
2221 You can provide that in the <filename>LICENSE</filename>
2222 statement.
2223 Now you edit your recipe to have those two strings for
2224 the <filename>SRC_URI</filename> statements:
2225 <literallayout class='monospaced'>
2226 LICENSE = "GPLv2"
2227
2228 LIC_FILES_CHKSUM = ""
2229
2230 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2231 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2232 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2233 </literallayout>
2234 At this point, you can build the software again using the
2235 <filename>bitbake htop</filename> command.
2236 There is just a set of errors now associated with the
2237 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2238 </para>
2239-->
2240
2241 </section>
2242
2243 <section id='new-recipe-configuring-the-recipe'>
2244 <title>Configuring the Recipe</title>
2245
2246 <para>
2247 Most software provides some means of setting build-time
2248 configuration options before compilation.
2249 Typically, setting these options is accomplished by running a
2250 configure script with some options, or by modifying a build
2251 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002252 <note>
2253 As of Yocto Project Release 7.1, some of the core recipes
2254 that package binary configuration scripts now disable the
2255 scripts due to the scripts previously requiring error-prone
2256 path substitution.
2257 The OpenEmbedded build system uses
2258 <filename>pkg-config</filename> now, which is much more
2259 robust.
2260 You can find a list of the <filename>*-config</filename>
2261 scripts that are disabled list in the
2262 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2263 section in the Yocto Project Reference Manual.
2264 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002265 </para>
2266
2267 <para>
2268 A major part of build-time configuration is about checking for
2269 build-time dependencies and possibly enabling optional
2270 functionality as a result.
2271 You need to specify any build-time dependencies for the
2272 software you are building in your recipe's
2273 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2274 value, in terms of other recipes that satisfy those
2275 dependencies.
2276 You can often find build-time or runtime
2277 dependencies described in the software's documentation.
2278 </para>
2279
2280 <para>
2281 The following list provides configuration items of note based
2282 on how your software is built:
2283 <itemizedlist>
2284 <listitem><para><emphasis>Autotools:</emphasis>
2285 If your source files have a
2286 <filename>configure.ac</filename> file, then your
2287 software is built using Autotools.
2288 If this is the case, you just need to worry about
2289 modifying the configuration.</para>
2290 <para>When using Autotools, your recipe needs to inherit
2291 the
2292 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2293 class and your recipe does not have to contain a
2294 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2295 task.
2296 However, you might still want to make some adjustments.
2297 For example, you can set
2298 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
2299 to pass any needed configure options that are specific
2300 to the recipe.</para></listitem>
2301 <listitem><para><emphasis>CMake:</emphasis>
2302 If your source files have a
2303 <filename>CMakeLists.txt</filename> file, then your
2304 software is built using CMake.
2305 If this is the case, you just need to worry about
2306 modifying the configuration.</para>
2307 <para>When you use CMake, your recipe needs to inherit
2308 the
2309 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2310 class and your recipe does not have to contain a
2311 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2312 task.
2313 You can make some adjustments by setting
2314 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2315 to pass any needed configure options that are specific
2316 to the recipe.</para></listitem>
2317 <listitem><para><emphasis>Other:</emphasis>
2318 If your source files do not have a
2319 <filename>configure.ac</filename> or
2320 <filename>CMakeLists.txt</filename> file, then your
2321 software is built using some method other than Autotools
2322 or CMake.
2323 If this is the case, you normally need to provide a
2324 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2325 task in your recipe
2326 unless, of course, there is nothing to configure.
2327 </para>
2328 <para>Even if your software is not being built by
2329 Autotools or CMake, you still might not need to deal
2330 with any configuration issues.
2331 You need to determine if configuration is even a required step.
2332 You might need to modify a Makefile or some configuration file
2333 used for the build to specify necessary build options.
2334 Or, perhaps you might need to run a provided, custom
2335 configure script with the appropriate options.</para>
2336 <para>For the case involving a custom configure
2337 script, you would run
2338 <filename>./configure --help</filename> and look for
2339 the options you need to set.</para></listitem>
2340 </itemizedlist>
2341 </para>
2342
2343 <para>
2344 Once configuration succeeds, it is always good practice to
2345 look at the <filename>log.do_configure</filename> file to
2346 ensure that the appropriate options have been enabled and no
2347 additional build-time dependencies need to be added to
2348 <filename>DEPENDS</filename>.
2349 For example, if the configure script reports that it found
2350 something not mentioned in <filename>DEPENDS</filename>, or
2351 that it did not find something that it needed for some
2352 desired optional functionality, then you would need to add
2353 those to <filename>DEPENDS</filename>.
2354 Looking at the log might also reveal items being checked for,
2355 enabled, or both that you do not want, or items not being found
2356 that are in <filename>DEPENDS</filename>, in which case
2357 you would need to look at passing extra options to the
2358 configure script as needed.
2359 For reference information on configure options specific to the
2360 software you are building, you can consult the output of the
2361 <filename>./configure --help</filename> command within
2362 <filename>${S}</filename> or consult the software's upstream
2363 documentation.
2364 </para>
2365 </section>
2366
2367 <section id='new-recipe-compilation'>
2368 <title>Compilation</title>
2369
2370 <para>
2371 During a build, the <filename>do_compile</filename> task
2372 happens after source is fetched, unpacked, and configured.
2373 If the recipe passes through <filename>do_compile</filename>
2374 successfully, nothing needs to be done.
2375 </para>
2376
2377 <para>
2378 However, if the compile step fails, you need to diagnose the
2379 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002380 Here are some common issues that cause failures.
2381 <note>
2382 For cases where improper paths are detected for
2383 configuration files or for when libraries/headers cannot
2384 be found, be sure you are using the more robust
2385 <filename>pkg-config</filename>.
2386 See the note in section
2387 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2388 for additional information.
2389 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002390 <itemizedlist>
2391 <listitem><para><emphasis>Parallel build failures:</emphasis>
2392 These failures manifest themselves as intermittent
2393 errors, or errors reporting that a file or directory
2394 that should be created by some other part of the build
2395 process could not be found.
2396 This type of failure can occur even if, upon inspection,
2397 the file or directory does exist after the build has
2398 failed, because that part of the build process happened
2399 in the wrong order.</para>
2400 <para>To fix the problem, you need to either satisfy
2401 the missing dependency in the Makefile or whatever
2402 script produced the Makefile, or (as a workaround)
2403 set
2404 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2405 to an empty string:
2406 <literallayout class='monospaced'>
2407 PARALLEL_MAKE = ""
2408 </literallayout></para>
2409 <para>
2410 For information on parallel Makefile issues, see the
2411 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2412 section.
2413 </para></listitem>
2414 <listitem><para><emphasis>Improper host path usage:</emphasis>
2415 This failure applies to recipes building for the target
2416 or <filename>nativesdk</filename> only.
2417 The failure occurs when the compilation process uses
2418 improper headers, libraries, or other files from the
2419 host system when cross-compiling for the target.
2420 </para>
2421 <para>To fix the problem, examine the
2422 <filename>log.do_compile</filename> file to identify
2423 the host paths being used (e.g.
2424 <filename>/usr/include</filename>,
2425 <filename>/usr/lib</filename>, and so forth) and then
2426 either add configure options, apply a patch, or do both.
2427 </para></listitem>
2428 <listitem><para><emphasis>Failure to find required
2429 libraries/headers:</emphasis>
2430 If a build-time dependency is missing because it has
2431 not been declared in
2432 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2433 or because the dependency exists but the path used by
2434 the build process to find the file is incorrect and the
2435 configure step did not detect it, the compilation
2436 process could fail.
2437 For either of these failures, the compilation process
2438 notes that files could not be found.
2439 In these cases, you need to go back and add additional
2440 options to the configure script as well as possibly
2441 add additional build-time dependencies to
2442 <filename>DEPENDS</filename>.</para>
2443 <para>Occasionally, it is necessary to apply a patch
2444 to the source to ensure the correct paths are used.
2445 If you need to specify paths to find files staged
2446 into the sysroot from other recipes, use the variables
2447 that the OpenEmbedded build system provides
2448 (e.g.
2449 <filename>STAGING_BINDIR</filename>,
2450 <filename>STAGING_INCDIR</filename>,
2451 <filename>STAGING_DATADIR</filename>, and so forth).
2452<!--
2453 (e.g.
2454 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2455 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2456 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2457 and so forth).
2458-->
2459 </para></listitem>
2460 </itemizedlist>
2461 </para>
2462 </section>
2463
2464 <section id='new-recipe-installing'>
2465 <title>Installing</title>
2466
2467 <para>
2468 During <filename>do_install</filename>, the task copies the
2469 built files along with their hierarchy to locations that
2470 would mirror their locations on the target device.
2471 The installation process copies files from the
2472 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2473 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2474 and
2475 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2476 directories to the
2477 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2478 directory to create the structure as it should appear on the
2479 target system.
2480 </para>
2481
2482 <para>
2483 How your software is built affects what you must do to be
2484 sure your software is installed correctly.
2485 The following list describes what you must do for installation
2486 depending on the type of build system used by the software
2487 being built:
2488 <itemizedlist>
2489 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2490 If the software your recipe is building uses Autotools
2491 or CMake, the OpenEmbedded build
2492 system understands how to install the software.
2493 Consequently, you do not have to have a
2494 <filename>do_install</filename> task as part of your
2495 recipe.
2496 You just need to make sure the install portion of the
2497 build completes with no issues.
2498 However, if you wish to install additional files not
2499 already being installed by
2500 <filename>make install</filename>, you should do this
2501 using a <filename>do_install_append</filename> function
2502 using the install command as described in
2503 the "Manual" bulleted item later in this list.
2504 </para></listitem>
2505 <listitem><para><emphasis>Other (using
2506 <filename>make install</filename>):</emphasis>
2507 You need to define a
2508 <filename>do_install</filename> function in your
2509 recipe.
2510 The function should call
2511 <filename>oe_runmake install</filename> and will likely
2512 need to pass in the destination directory as well.
2513 How you pass that path is dependent on how the
2514 <filename>Makefile</filename> being run is written
2515 (e.g. <filename>DESTDIR=${D}</filename>,
2516 <filename>PREFIX=${D}</filename>,
2517 <filename>INSTALLROOT=${D}</filename>, and so forth).
2518 </para>
2519 <para>For an example recipe using
2520 <filename>make install</filename>, see the
2521 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2522 section.</para></listitem>
2523 <listitem><para><emphasis>Manual:</emphasis>
2524 You need to define a
2525 <filename>do_install</filename> function in your
2526 recipe.
2527 The function must first use
2528 <filename>install -d</filename> to create the
2529 directories under
2530 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2531 Once the directories exist, your function can use
2532 <filename>install</filename> to manually install the
2533 built software into the directories.</para>
2534 <para>You can find more information on
2535 <filename>install</filename> at
2536 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2537 </para></listitem>
2538 </itemizedlist>
2539 </para>
2540
2541 <para>
2542 For the scenarios that do not use Autotools or
2543 CMake, you need to track the installation
2544 and diagnose and fix any issues until everything installs
2545 correctly.
2546 You need to look in the default location of
2547 <filename>${D}</filename>, which is
2548 <filename>${WORKDIR}/image</filename>, to be sure your
2549 files have been installed correctly.
2550 </para>
2551
2552 <note><title>Notes</title>
2553 <itemizedlist>
2554 <listitem><para>
2555 During the installation process, you might need to
2556 modify some of the installed files to suit the target
2557 layout.
2558 For example, you might need to replace hard-coded paths
2559 in an initscript with values of variables provided by
2560 the build system, such as replacing
2561 <filename>/usr/bin/</filename> with
2562 <filename>${bindir}</filename>.
2563 If you do perform such modifications during
2564 <filename>do_install</filename>, be sure to modify the
2565 destination file after copying rather than before
2566 copying.
2567 Modifying after copying ensures that the build system
2568 can re-execute <filename>do_install</filename> if
2569 needed.
2570 </para></listitem>
2571 <listitem><para>
2572 <filename>oe_runmake install</filename>, which can be
2573 run directly or can be run indirectly by the
2574 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2575 and
2576 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2577 classes, runs <filename>make install</filename> in
2578 parallel.
2579 Sometimes, a Makefile can have missing dependencies
2580 between targets that can result in race conditions.
2581 If you experience intermittent failures during
2582 <filename>do_install</filename>, you might be able to
2583 work around them by disabling parallel Makefile
2584 installs by adding the following to the recipe:
2585 <literallayout class='monospaced'>
2586 PARALLEL_MAKEINST = ""
2587 </literallayout>
2588 See
2589 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2590 for additional information.
2591 </para></listitem>
2592 </itemizedlist>
2593 </note>
2594 </section>
2595
2596 <section id='new-recipe-enabling-system-services'>
2597 <title>Enabling System Services</title>
2598
2599 <para>
2600 If you want to install a service, which is a process that
2601 usually starts on boot and runs in the background, then
2602 you must include some additional definitions in your recipe.
2603 </para>
2604
2605 <para>
2606 If you are adding services and the service initialization
2607 script or the service file itself is not installed, you must
2608 provide for that installation in your recipe using a
2609 <filename>do_install_append</filename> function.
2610 If your recipe already has a <filename>do_install</filename>
2611 function, update the function near its end rather than
2612 adding an additional <filename>do_install_append</filename>
2613 function.
2614 </para>
2615
2616 <para>
2617 When you create the installation for your services, you need
2618 to accomplish what is normally done by
2619 <filename>make install</filename>.
2620 In other words, make sure your installation arranges the output
2621 similar to how it is arranged on the target system.
2622 </para>
2623
2624 <para>
2625 The OpenEmbedded build system provides support for starting
2626 services two different ways:
2627 <itemizedlist>
2628 <listitem><para><emphasis>SysVinit:</emphasis>
2629 SysVinit is a system and service manager that
2630 manages the init system used to control the very basic
2631 functions of your system.
2632 The init program is the first program
2633 started by the Linux kernel when the system boots.
2634 Init then controls the startup, running and shutdown
2635 of all other programs.</para>
2636 <para>To enable a service using SysVinit, your recipe
2637 needs to inherit the
2638 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2639 class.
2640 The class helps facilitate safely installing the
2641 package on the target.</para>
2642 <para>You will need to set the
2643 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2644 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2645 and
2646 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2647 variables within your recipe.</para></listitem>
2648 <listitem><para><emphasis>systemd:</emphasis>
2649 System Management Daemon (systemd) was designed to
2650 replace SysVinit and to provide
2651 enhanced management of services.
2652 For more information on systemd, see the systemd
2653 homepage at
2654 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2655 </para>
2656 <para>To enable a service using systemd, your recipe
2657 needs to inherit the
2658 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2659 class.
2660 See the <filename>systemd.bbclass</filename> file
2661 located in your
2662 <link linkend='source-directory'>Source Directory</link>.
2663 section for more information.
2664 </para></listitem>
2665 </itemizedlist>
2666 </para>
2667 </section>
2668
2669 <section id='new-recipe-packaging'>
2670 <title>Packaging</title>
2671
2672 <para>
2673 Successful packaging is a combination of automated processes
2674 performed by the OpenEmbedded build system and some
2675 specific steps you need to take.
2676 The following list describes the process:
2677 <itemizedlist>
2678 <listitem><para><emphasis>Splitting Files</emphasis>:
2679 The <filename>do_package</filename> task splits the
2680 files produced by the recipe into logical components.
2681 Even software that produces a single binary might
2682 still have debug symbols, documentation, and other
2683 logical components that should be split out.
2684 The <filename>do_package</filename> task ensures
2685 that files are split up and packaged correctly.
2686 </para></listitem>
2687 <listitem><para><emphasis>Running QA Checks</emphasis>:
2688 The
2689 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2690 class adds a step to
2691 the package generation process so that output quality
2692 assurance checks are generated by the OpenEmbedded
2693 build system.
2694 This step performs a range of checks to be sure the
2695 build's output is free of common problems that show
2696 up during runtime.
2697 For information on these checks, see the
2698 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2699 class and the
2700 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2701 chapter in the Yocto Project Reference Manual.
2702 </para></listitem>
2703 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2704 After you build your software, you need to be sure
2705 your packages are correct.
2706 Examine the
2707 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2708 directory and make sure files are where you expect
2709 them to be.
2710 If you discover problems, you can set
2711 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2712 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2713 <filename>do_install(_append)</filename>, and so forth as
2714 needed.
2715 </para></listitem>
2716 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2717 If you need to split an application into several
2718 packages, see the
2719 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2720 section for an example.
2721 </para></listitem>
2722 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2723 For an example showing how to install a
2724 post-installation script, see the
2725 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2726 section.
2727 </para></listitem>
2728 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2729 Depending on what your recipe is building and how it
2730 is configured, it might be important to mark the
2731 packages produced as being specific to a particular
2732 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002733 a particular machine or architecture at all.</para>
2734 <para>By default, packages apply to any machine with the
2735 same architecture as the target machine.
2736 When a recipe produces packages that are
2737 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002738 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2739 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002740 is applied only for a particular machine), you should
2741 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002742 recipe:
2743 <literallayout class='monospaced'>
2744 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002745 </literallayout></para>
2746 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002747 that do not contain anything specific to the target
2748 machine or architecture at all (e.g. recipes
2749 that simply package script files or configuration
2750 files), you should use the
2751 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
2752 class to do this for you by adding this to your
2753 recipe:
2754 <literallayout class='monospaced'>
2755 inherit allarch
2756 </literallayout>
2757 Ensuring that the package architecture is correct is
2758 not critical while you are doing the first few builds
2759 of your recipe.
2760 However, it is important in order
2761 to ensure that your recipe rebuilds (or does not
2762 rebuild) appropriately in response to changes in
2763 configuration, and to ensure that you get the
2764 appropriate packages installed on the target machine,
2765 particularly if you run separate builds for more
2766 than one target machine.
2767 </para></listitem>
2768 </itemizedlist>
2769 </para>
2770 </section>
2771
2772 <section id='properly-versioning-pre-release-recipes'>
2773 <title>Properly Versioning Pre-Release Recipes</title>
2774
2775 <para>
2776 Sometimes the name of a recipe can lead to versioning
2777 problems when the recipe is upgraded to a final release.
2778 For example, consider the
2779 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
2780 the list of example recipes in the
2781 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
2782 section.
2783 This recipe is at a release candidate stage (i.e.
2784 "rc1").
2785 When the recipe is released, the recipe filename becomes
2786 <filename>irssi_0.8.16.bb</filename>.
2787 The version change from <filename>0.8.16-rc1</filename>
2788 to <filename>0.8.16</filename> is seen as a decrease by the
2789 build system and package managers, so the resulting packages
2790 will not correctly trigger an upgrade.
2791 </para>
2792
2793 <para>
2794 In order to ensure the versions compare properly, the
2795 recommended convention is to set
2796 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
2797 within the recipe to
2798 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
2799 You can use an additional variable so that you can use the
2800 current version elsewhere.
2801 Here is an example:
2802 <literallayout class='monospaced'>
2803 REALPV = "0.8.16-rc1"
2804 PV = "0.8.15+${REALPV}"
2805 </literallayout>
2806 </para>
2807 </section>
2808
2809 <section id='new-recipe-post-installation-scripts'>
2810 <title>Post-Installation Scripts</title>
2811
2812 <para>
2813 Post-installation scripts run immediately after installing
2814 a package on the target or during image creation when a
2815 package is included in an image.
2816 To add a post-installation script to a package, add a
2817 <filename>pkg_postinst_PACKAGENAME()</filename> function to
2818 the recipe file (<filename>.bb</filename>) and replace
2819 <filename>PACKAGENAME</filename> with the name of the package
2820 you want to attach to the <filename>postinst</filename>
2821 script.
2822 To apply the post-installation script to the main package
2823 for the recipe, which is usually what is required, specify
2824 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2825 in place of <filename>PACKAGENAME</filename>.
2826 </para>
2827
2828 <para>
2829 A post-installation function has the following structure:
2830 <literallayout class='monospaced'>
2831 pkg_postinst_PACKAGENAME() {
2832 # Commands to carry out
2833 }
2834 </literallayout>
2835 </para>
2836
2837 <para>
2838 The script defined in the post-installation function is
2839 called when the root filesystem is created.
2840 If the script succeeds, the package is marked as installed.
2841 If the script fails, the package is marked as unpacked and
2842 the script is executed when the image boots again.
2843 </para>
2844
2845 <para>
2846 Sometimes it is necessary for the execution of a
2847 post-installation script to be delayed until the first boot.
2848 For example, the script might need to be executed on the
2849 device itself.
2850 To delay script execution until boot time, use the following
2851 structure in the post-installation script:
2852 <literallayout class='monospaced'>
2853 pkg_postinst_PACKAGENAME() {
2854 if [ x"$D" = "x" ]; then
2855 # Actions to carry out on the device go here
2856 else
2857 exit 1
2858 fi
2859 }
2860 </literallayout>
2861 </para>
2862
2863 <para>
2864 The previous example delays execution until the image boots
2865 again because the environment variable <filename>D</filename>
2866 points to the directory containing the image when
2867 the root filesystem is created at build time but is unset
2868 when executed on the first boot.
2869 </para>
2870
2871 <note>
2872 Equivalent support for pre-install, pre-uninstall, and
2873 post-uninstall scripts exist by way of
2874 <filename>pkg_preinst</filename>,
2875 <filename>pkg_prerm</filename>, and
2876 <filename>pkg_postrm</filename>, respectively.
2877 These scrips work in exactly the same way as does
2878 <filename>pkg_postinst</filename> with the exception that they
2879 run at different times.
2880 Also, because of when they run, they are not applicable to
2881 being run at image creation time like
2882 <filename>pkg_postinst</filename>.
2883 </note>
2884 </section>
2885
2886 <section id='new-recipe-testing'>
2887 <title>Testing</title>
2888
2889 <para>
2890 The final step for completing your recipe is to be sure that
2891 the software you built runs correctly.
2892 To accomplish runtime testing, add the build's output
2893 packages to your image and test them on the target.
2894 </para>
2895
2896 <para>
2897 For information on how to customize your image by adding
2898 specific packages, see the
2899 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
2900 section.
2901 </para>
2902 </section>
2903
2904 <section id='new-recipe-testing-examples'>
2905 <title>Examples</title>
2906
2907 <para>
2908 To help summarize how to write a recipe, this section provides
2909 some examples given various scenarios:
2910 <itemizedlist>
2911 <listitem><para>Recipes that use local files</para></listitem>
2912 <listitem><para>Using an Autotooled package</para></listitem>
2913 <listitem><para>Using a Makefile-based package</para></listitem>
2914 <listitem><para>Splitting an application into multiple packages</para></listitem>
2915 <listitem><para>Adding binaries to an image</para></listitem>
2916 </itemizedlist>
2917 </para>
2918
2919 <section id='new-recipe-single-c-file-package-hello-world'>
2920 <title>Single .c File Package (Hello World!)</title>
2921
2922 <para>
2923 Building an application from a single file that is stored
2924 locally (e.g. under <filename>files</filename>) requires
2925 a recipe that has the file listed in the
2926 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
2927 variable.
2928 Additionally, you need to manually write the
2929 <filename>do_compile</filename> and
2930 <filename>do_install</filename> tasks.
2931 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
2932 variable defines the directory containing the source code,
2933 which is set to
2934 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
2935 in this case - the directory BitBake uses for the build.
2936 <literallayout class='monospaced'>
2937 SUMMARY = "Simple helloworld application"
2938 SECTION = "examples"
2939 LICENSE = "MIT"
2940 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2941
2942 SRC_URI = "file://helloworld.c"
2943
2944 S = "${WORKDIR}"
2945
2946 do_compile() {
2947 ${CC} helloworld.c -o helloworld
2948 }
2949
2950 do_install() {
2951 install -d ${D}${bindir}
2952 install -m 0755 helloworld ${D}${bindir}
2953 }
2954 </literallayout>
2955 </para>
2956
2957 <para>
2958 By default, the <filename>helloworld</filename>,
2959 <filename>helloworld-dbg</filename>, and
2960 <filename>helloworld-dev</filename> packages are built.
2961 For information on how to customize the packaging process,
2962 see the
2963 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2964 section.
2965 </para>
2966 </section>
2967
2968 <section id='new-recipe-autotooled-package'>
2969 <title>Autotooled Package</title>
2970 <para>
2971 Applications that use Autotools such as <filename>autoconf</filename> and
2972 <filename>automake</filename> require a recipe that has a source archive listed in
2973 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
2974 also inherit the
2975 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2976 class, which contains the definitions of all the steps
2977 needed to build an Autotool-based application.
2978 The result of the build is automatically packaged.
2979 And, if the application uses NLS for localization, packages with local information are
2980 generated (one package per language).
2981 Following is one example: (<filename>hello_2.3.bb</filename>)
2982 <literallayout class='monospaced'>
2983 SUMMARY = "GNU Helloworld application"
2984 SECTION = "examples"
2985 LICENSE = "GPLv2+"
2986 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2987
2988 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2989
2990 inherit autotools gettext
2991 </literallayout>
2992 </para>
2993
2994 <para>
2995 The variable
2996 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
2997 is used to track source license changes as described in the
2998 "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" section.
2999 You can quickly create Autotool-based recipes in a manner similar to the previous example.
3000 </para>
3001 </section>
3002
3003 <section id='new-recipe-makefile-based-package'>
3004 <title>Makefile-Based Package</title>
3005
3006 <para>
3007 Applications that use GNU <filename>make</filename> also require a recipe that has
3008 the source archive listed in
3009 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3010 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3011 starts the <filename>make</filename> command to compile the application.
3012 If you need additional <filename>make</filename> options, you should store them in the
3013 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'>EXTRA_OEMAKE</ulink></filename>
3014 variable.
3015 BitBake passes these options into the GNU <filename>make</filename> invocation.
3016 Note that a <filename>do_install</filename> task is still required.
3017 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3018 </para>
3019
3020 <para>
3021 Some applications might require extra parameters to be passed to the compiler.
3022 For example, the application might need an additional header path.
3023 You can accomplish this by adding to the
3024 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3025 The following example shows this:
3026 <literallayout class='monospaced'>
3027 CFLAGS_prepend = "-I ${S}/include "
3028 </literallayout>
3029 </para>
3030
3031 <para>
3032 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3033 <literallayout class='monospaced'>
3034 SUMMARY = "Tools for managing memory technology devices"
3035 SECTION = "base"
3036 DEPENDS = "zlib lzo e2fsprogs util-linux"
3037 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3038 LICENSE = "GPLv2+"
3039 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3040 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3041
3042 # Use the latest version at 26 Oct, 2013
3043 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3044 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3045 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3046 "
3047
3048 PV = "1.5.1+git${SRCPV}"
3049
3050 S = "${WORKDIR}/git/"
3051
3052 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3053
3054 do_install () {
3055 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3056 }
3057
3058 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3059
3060 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3061 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3062 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3063
3064 PARALLEL_MAKE = ""
3065
3066 BBCLASSEXTEND = "native"
3067 </literallayout>
3068 </para>
3069 </section>
3070
3071 <section id='splitting-an-application-into-multiple-packages'>
3072 <title>Splitting an Application into Multiple Packages</title>
3073
3074 <para>
3075 You can use the variables
3076 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3077 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3078 to split an application into multiple packages.
3079 </para>
3080
3081 <para>
3082 Following is an example that uses the <filename>libxpm</filename> recipe.
3083 By default, this recipe generates a single package that contains the library along
3084 with a few binaries.
3085 You can modify the recipe to split the binaries into separate packages:
3086 <literallayout class='monospaced'>
3087 require xorg-lib-common.inc
3088
3089 SUMMARY = "Xpm: X Pixmap extension library"
3090 LICENSE = "BSD"
3091 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3092 DEPENDS += "libxext libsm libxt"
3093 PE = "1"
3094
3095 XORG_PN = "libXpm"
3096
3097 PACKAGES =+ "sxpm cxpm"
3098 FILES_cxpm = "${bindir}/cxpm"
3099 FILES_sxpm = "${bindir}/sxpm"
3100 </literallayout>
3101 </para>
3102
3103 <para>
3104 In the previous example, we want to ship the <filename>sxpm</filename>
3105 and <filename>cxpm</filename> binaries in separate packages.
3106 Since <filename>bindir</filename> would be packaged into the main
3107 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3108 package by default, we prepend the <filename>PACKAGES</filename>
3109 variable so additional package names are added to the start of list.
3110 This results in the extra <filename>FILES_*</filename>
3111 variables then containing information that define which files and
3112 directories go into which packages.
3113 Files included by earlier packages are skipped by latter packages.
3114 Thus, the main <filename>PN</filename> package
3115 does not include the above listed files.
3116 </para>
3117 </section>
3118
3119 <section id='packaging-externally-produced-binaries'>
3120 <title>Packaging Externally Produced Binaries</title>
3121
3122 <para>
3123 Sometimes, you need to add pre-compiled binaries to an
3124 image.
3125 For example, suppose that binaries for proprietary code
3126 exist, which are created by a particular division of a
3127 company.
3128 Your part of the company needs to use those binaries as
3129 part of an image that you are building using the
3130 OpenEmbedded build system.
3131 Since you only have the binaries and not the source code,
3132 you cannot use a typical recipe that expects to fetch the
3133 source specified in
3134 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3135 and then compile it.
3136 </para>
3137
3138 <para>
3139 One method is to package the binaries and then install them
3140 as part of the image.
3141 Generally, it is not a good idea to package binaries
3142 since, among other things, it can hinder the ability to
3143 reproduce builds and could lead to compatibility problems
3144 with ABI in the future.
3145 However, sometimes you have no choice.
3146 </para>
3147
3148 <para>
3149 The easiest solution is to create a recipe that uses
3150 the
3151 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3152 class and to be sure that you are using default locations
3153 for build artifacts.
3154 In most cases, the <filename>bin_package</filename> class
3155 handles "skipping" the configure and compile steps as well
3156 as sets things up to grab packages from the appropriate
3157 area.
3158 In particular, this class sets <filename>noexec</filename>
3159 on both the
3160 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3161 and
3162 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3163 tasks, sets
3164 <filename>FILES_${PN}</filename> to "/" so that it picks
3165 up all files, and sets up a
3166 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3167 task, which effectively copies all files from
3168 <filename>${S}</filename> to <filename>${D}</filename>.
3169 The <filename>bin_package</filename> class works well when
3170 the files extracted into <filename>${S}</filename> are
3171 already laid out in the way they should be laid out
3172 on the target.
3173 For more information on these variables, see the
3174 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3175 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3176 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3177 and
3178 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3179 variables in the Yocto Project Reference Manual's variable
3180 glossary.
3181 </para>
3182
3183 <para>
3184 If you can't use the <filename>bin_package</filename>
3185 class, you need to be sure you are doing the following:
3186 <itemizedlist>
3187 <listitem><para>Create a recipe where the
3188 <filename>do_configure</filename> and
3189 <filename>do_compile</filename> tasks do nothing:
3190 <literallayout class='monospaced'>
3191 do_configure[noexec] = "1"
3192 do_compile[noexec] = "1"
3193 </literallayout>
3194 Alternatively, you can make these tasks an empty
3195 function.
3196 </para></listitem>
3197 <listitem><para>Make sure your
3198 <filename>do_install</filename> task installs the
3199 binaries appropriately.
3200 </para></listitem>
3201 <listitem><para>Ensure that you set up
3202 <filename>FILES</filename> (usually
3203 <filename>FILES_${PN}</filename>) to point to the
3204 files you have installed, which of course depends
3205 on where you have installed them and whether
3206 those files are in different locations than the
3207 defaults.
3208 </para></listitem>
3209 </itemizedlist>
3210 </para>
3211 </section>
3212 </section>
3213 </section>
3214
3215 <section id="platdev-newmachine">
3216 <title>Adding a New Machine</title>
3217
3218 <para>
3219 Adding a new machine to the Yocto Project is a straightforward
3220 process.
3221 This section describes how to add machines that are similar
3222 to those that the Yocto Project already supports.
3223 <note>
3224 Although well within the capabilities of the Yocto Project,
3225 adding a totally new architecture might require
3226 changes to <filename>gcc/glibc</filename> and to the site
3227 information, which is beyond the scope of this manual.
3228 </note>
3229 </para>
3230
3231 <para>
3232 For a complete example that shows how to add a new machine,
3233 see the
3234 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>"
3235 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
3236 </para>
3237
3238 <section id="platdev-newmachine-conffile">
3239 <title>Adding the Machine Configuration File</title>
3240
3241 <para>
3242 To add a new machine, you need to add a new machine
3243 configuration file to the layer's
3244 <filename>conf/machine</filename> directory.
3245 This configuration file provides details about the device
3246 you are adding.
3247 </para>
3248
3249 <para>
3250 The OpenEmbedded build system uses the root name of the
3251 machine configuration file to reference the new machine.
3252 For example, given a machine configuration file named
3253 <filename>crownbay.conf</filename>, the build system
3254 recognizes the machine as "crownbay".
3255 </para>
3256
3257 <para>
3258 The most important variables you must set in your machine
3259 configuration file or include from a lower-level configuration
3260 file are as follows:
3261 <itemizedlist>
3262 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
3263 (e.g. "arm")</para></listitem>
3264 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
3265 </para></listitem>
3266 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
3267 (e.g. "apm screen wifi")</para></listitem>
3268 </itemizedlist>
3269 </para>
3270
3271 <para>
3272 You might also need these variables:
3273 <itemizedlist>
3274 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
3275 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
3276 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
3277 (e.g. "zImage")</para></listitem>
3278 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
3279 (e.g. "tar.gz jffs2")</para></listitem>
3280 </itemizedlist>
3281 </para>
3282
3283 <para>
3284 You can find full details on these variables in the reference
3285 section.
3286 You can leverage existing machine <filename>.conf</filename>
3287 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
3288 </para>
3289 </section>
3290
3291 <section id="platdev-newmachine-kernel">
3292 <title>Adding a Kernel for the Machine</title>
3293
3294 <para>
3295 The OpenEmbedded build system needs to be able to build a kernel
3296 for the machine.
3297 You need to either create a new kernel recipe for this machine,
3298 or extend an existing kernel recipe.
3299 You can find several kernel recipe examples in the
3300 Source Directory at
3301 <filename>meta/recipes-kernel/linux</filename>
3302 that you can use as references.
3303 </para>
3304
3305 <para>
3306 If you are creating a new kernel recipe, normal recipe-writing
3307 rules apply for setting up a
3308 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3309 Thus, you need to specify any necessary patches and set
3310 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3311 to point at the source code.
3312 You need to create a <filename>do_configure</filename> task that
3313 configures the unpacked kernel with a
3314 <filename>defconfig</filename> file.
3315 You can do this by using a <filename>make defconfig</filename>
3316 command or, more commonly, by copying in a suitable
3317 <filename>defconfig</filename> file and then running
3318 <filename>make oldconfig</filename>.
3319 By making use of <filename>inherit kernel</filename> and
3320 potentially some of the <filename>linux-*.inc</filename> files,
3321 most other functionality is centralized and the defaults of the
3322 class normally work well.
3323 </para>
3324
3325 <para>
3326 If you are extending an existing kernel recipe, it is usually
3327 a matter of adding a suitable <filename>defconfig</filename>
3328 file.
3329 The file needs to be added into a location similar to
3330 <filename>defconfig</filename> files used for other machines
3331 in a given kernel recipe.
3332 A possible way to do this is by listing the file in the
3333 <filename>SRC_URI</filename> and adding the machine to the
3334 expression in
3335 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
3336 <literallayout class='monospaced'>
3337 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
3338 </literallayout>
3339 For more information on <filename>defconfig</filename> files,
3340 see the
3341 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
3342 section in the Yocto Project Linux Kernel Development Manual.
3343 </para>
3344 </section>
3345
3346 <section id="platdev-newmachine-formfactor">
3347 <title>Adding a Formfactor Configuration File</title>
3348
3349 <para>
3350 A formfactor configuration file provides information about the
3351 target hardware for which the image is being built and information that
3352 the build system cannot obtain from other sources such as the kernel.
3353 Some examples of information contained in a formfactor configuration file include
3354 framebuffer orientation, whether or not the system has a keyboard,
3355 the positioning of the keyboard in relation to the screen, and
3356 the screen resolution.
3357 </para>
3358
3359 <para>
3360 The build system uses reasonable defaults in most cases.
3361 However, if customization is
3362 necessary, you need to create a <filename>machconfig</filename> file
3363 in the <filename>meta/recipes-bsp/formfactor/files</filename>
3364 directory.
3365 This directory contains directories for specific machines such as
3366 <filename>qemuarm</filename> and <filename>qemux86</filename>.
3367 For information about the settings available and the defaults, see the
3368 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
3369 same area.
3370 </para>
3371
3372 <para>
3373 Following is an example for "qemuarm" machine:
3374 <literallayout class='monospaced'>
3375 HAVE_TOUCHSCREEN=1
3376 HAVE_KEYBOARD=1
3377
3378 DISPLAY_CAN_ROTATE=0
3379 DISPLAY_ORIENTATION=0
3380 #DISPLAY_WIDTH_PIXELS=640
3381 #DISPLAY_HEIGHT_PIXELS=480
3382 #DISPLAY_BPP=16
3383 DISPLAY_DPI=150
3384 DISPLAY_SUBPIXEL_ORDER=vrgb
3385 </literallayout>
3386 </para>
3387 </section>
3388 </section>
3389
3390 <section id="platdev-working-with-libraries">
3391 <title>Working With Libraries</title>
3392
3393 <para>
3394 Libraries are an integral part of your system.
3395 This section describes some common practices you might find
3396 helpful when working with libraries to build your system:
3397 <itemizedlist>
3398 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
3399 </para></listitem>
3400 <listitem><para><link linkend='combining-multiple-versions-library-files-into-one-image'>How to use the Multilib feature to combine multiple versions of library files into a single image</link>
3401 </para></listitem>
3402 <listitem><para><link linkend='installing-multiple-versions-of-the-same-library'>How to install multiple versions of the same library in parallel on the same system</link>
3403 </para></listitem>
3404 </itemizedlist>
3405 </para>
3406
3407 <section id='including-static-library-files'>
3408 <title>Including Static Library Files</title>
3409
3410 <para>
3411 If you are building a library and the library offers static linking, you can control
3412 which static library files (<filename>*.a</filename> files) get included in the
3413 built library.
3414 </para>
3415
3416 <para>
3417 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
3418 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
3419 variables in the
3420 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
3421 by the <filename>do_install</filename> task are packaged.
3422 By default, the <filename>PACKAGES</filename> variable includes
3423 <filename>${PN}-staticdev</filename>, which represents all static library files.
3424 <note>
3425 Some previously released versions of the Yocto Project
3426 defined the static library files through
3427 <filename>${PN}-dev</filename>.
3428 </note>
3429 Following is part of the BitBake configuration file, where
3430 you can see how the static library files are defined:
3431 <literallayout class='monospaced'>
3432 PACKAGE_BEFORE_PN ?= ""
3433 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
3434 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
3435 FILES = ""
3436
3437 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
3438 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
3439 ${base_bindir}/* ${base_sbindir}/* \
3440 ${base_libdir}/*${SOLIBS} \
3441 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
3442 ${datadir}/${BPN} ${libdir}/${BPN}/* \
3443 ${datadir}/pixmaps ${datadir}/applications \
3444 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
3445 ${libdir}/bonobo/servers"
3446
3447 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
3448
3449 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
3450 ${datadir}/gnome/help"
3451 SECTION_${PN}-doc = "doc"
3452
3453 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
3454 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
3455 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
3456 ${datadir}/aclocal ${base_libdir}/*.o \
3457 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
3458 SECTION_${PN}-dev = "devel"
3459 ALLOW_EMPTY_${PN}-dev = "1"
3460 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
3461
3462 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
3463 SECTION_${PN}-staticdev = "devel"
3464 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
3465 </literallayout>
3466 </para>
3467 </section>
3468
3469 <section id="combining-multiple-versions-library-files-into-one-image">
3470 <title>Combining Multiple Versions of Library Files into One Image</title>
3471
3472 <para>
3473 The build system offers the ability to build libraries with different
3474 target optimizations or architecture formats and combine these together
3475 into one system image.
3476 You can link different binaries in the image
3477 against the different libraries as needed for specific use cases.
3478 This feature is called "Multilib."
3479 </para>
3480
3481 <para>
3482 An example would be where you have most of a system compiled in 32-bit
3483 mode using 32-bit libraries, but you have something large, like a database
3484 engine, that needs to be a 64-bit application and uses 64-bit libraries.
3485 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
3486 </para>
3487
3488 <para>
3489 While the Multilib feature is most commonly used for 32 and 64-bit differences,
3490 the approach the build system uses facilitates different target optimizations.
3491 You could compile some binaries to use one set of libraries and other binaries
3492 to use a different set of libraries.
3493 The libraries could differ in architecture, compiler options, or other
3494 optimizations.
3495 </para>
3496
3497 <para>
3498 This section overviews the Multilib process only.
3499 For more details on how to implement Multilib, see the
3500 <ulink url='&YOCTO_WIKI_URL;/wiki/Multilib'>Multilib</ulink> wiki
3501 page.
3502 </para>
3503
3504 <para>
3505 Aside from this wiki page, several examples exist in the
3506 <filename>meta-skeleton</filename> layer found in the
3507 <link linkend='source-directory'>Source Directory</link>:
3508 <itemizedlist>
3509 <listitem><para><filename>conf/multilib-example.conf</filename>
3510 configuration file</para></listitem>
3511 <listitem><para><filename>conf/multilib-example2.conf</filename>
3512 configuration file</para></listitem>
3513 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
3514 recipe</para></listitem>
3515 </itemizedlist>
3516 </para>
3517
3518 <section id='preparing-to-use-multilib'>
3519 <title>Preparing to Use Multilib</title>
3520
3521 <para>
3522 User-specific requirements drive the Multilib feature.
3523 Consequently, there is no one "out-of-the-box" configuration that likely
3524 exists to meet your needs.
3525 </para>
3526
3527 <para>
3528 In order to enable Multilib, you first need to ensure your recipe is
3529 extended to support multiple libraries.
3530 Many standard recipes are already extended and support multiple libraries.
3531 You can check in the <filename>meta/conf/multilib.conf</filename>
3532 configuration file in the
3533 <link linkend='source-directory'>Source Directory</link> to see how this is
3534 done using the
3535 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
3536 variable.
3537 Eventually, all recipes will be covered and this list will
3538 not be needed.
3539 </para>
3540
3541 <para>
3542 For the most part, the Multilib class extension works automatically to
3543 extend the package name from <filename>${PN}</filename> to
3544 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
3545 is the particular multilib (e.g. "lib32-" or "lib64-").
3546 Standard variables such as
3547 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
3548 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
3549 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
3550 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
3551 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
3552 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
3553 are automatically extended by the system.
3554 If you are extending any manual code in the recipe, you can use the
3555 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
3556 correctly.
3557 This automatic extension code resides in <filename>multilib.bbclass</filename>.
3558 </para>
3559 </section>
3560
3561 <section id='using-multilib'>
3562 <title>Using Multilib</title>
3563
3564 <para>
3565 After you have set up the recipes, you need to define the actual
3566 combination of multiple libraries you want to build.
3567 You accomplish this through your <filename>local.conf</filename>
3568 configuration file in the
3569 <link linkend='build-directory'>Build Directory</link>.
3570 An example configuration would be as follows:
3571 <literallayout class='monospaced'>
3572 MACHINE = "qemux86-64"
3573 require conf/multilib.conf
3574 MULTILIBS = "multilib:lib32"
3575 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05003576 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003577 </literallayout>
3578 This example enables an
3579 additional library named <filename>lib32</filename> alongside the
3580 normal target packages.
3581 When combining these "lib32" alternatives, the example uses "x86" for tuning.
3582 For information on this particular tuning, see
3583 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
3584 </para>
3585
3586 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05003587 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003588 in all the images, which illustrates one method of including a
3589 multiple library dependency.
3590 You can use a normal image build to include this dependency,
3591 for example:
3592 <literallayout class='monospaced'>
3593 $ bitbake core-image-sato
3594 </literallayout>
3595 You can also build Multilib packages specifically with a command like this:
3596 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05003597 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003598 </literallayout>
3599 </para>
3600 </section>
3601
3602 <section id='additional-implementation-details'>
3603 <title>Additional Implementation Details</title>
3604
3605 <para>
3606 Different packaging systems have different levels of native Multilib
3607 support.
3608 For the RPM Package Management System, the following implementation details
3609 exist:
3610 <itemizedlist>
3611 <listitem><para>A unique architecture is defined for the Multilib packages,
3612 along with creating a unique deploy folder under
3613 <filename>tmp/deploy/rpm</filename> in the
3614 <link linkend='build-directory'>Build Directory</link>.
3615 For example, consider <filename>lib32</filename> in a
3616 <filename>qemux86-64</filename> image.
3617 The possible architectures in the system are "all", "qemux86_64",
3618 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
3619 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
3620 <filename>${PN}</filename> during RPM packaging.
3621 The naming for a normal RPM package and a Multilib RPM package in a
3622 <filename>qemux86-64</filename> system resolves to something similar to
3623 <filename>bash-4.1-r2.x86_64.rpm</filename> and
3624 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
3625 </para></listitem>
3626 <listitem><para>When installing a Multilib image, the RPM backend first
3627 installs the base image and then installs the Multilib libraries.
3628 </para></listitem>
3629 <listitem><para>The build system relies on RPM to resolve the identical files in the
3630 two (or more) Multilib packages.</para></listitem>
3631 </itemizedlist>
3632 </para>
3633
3634 <para>
3635 For the IPK Package Management System, the following implementation details exist:
3636 <itemizedlist>
3637 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
3638 <filename>${PN}</filename> during IPK packaging.
3639 The naming for a normal RPM package and a Multilib IPK package in a
3640 <filename>qemux86-64</filename> system resolves to something like
3641 <filename>bash_4.1-r2.x86_64.ipk</filename> and
3642 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
3643 </para></listitem>
3644 <listitem><para>The IPK deploy folder is not modified with
3645 <filename>${MLPREFIX}</filename> because packages with and without
3646 the Multilib feature can exist in the same folder due to the
3647 <filename>${PN}</filename> differences.</para></listitem>
3648 <listitem><para>IPK defines a sanity check for Multilib installation
3649 using certain rules for file comparison, overridden, etc.
3650 </para></listitem>
3651 </itemizedlist>
3652 </para>
3653 </section>
3654 </section>
3655
3656 <section id='installing-multiple-versions-of-the-same-library'>
3657 <title>Installing Multiple Versions of the Same Library</title>
3658
3659 <para>
3660 Situations can exist where you need to install and use
3661 multiple versions of the same library on the same system
3662 at the same time.
3663 These situations almost always exist when a library API
3664 changes and you have multiple pieces of software that
3665 depend on the separate versions of the library.
3666 To accommodate these situations, you can install multiple
3667 versions of the same library in parallel on the same system.
3668 </para>
3669
3670 <para>
3671 The process is straightforward as long as the libraries use
3672 proper versioning.
3673 With properly versioned libraries, all you need to do to
3674 individually specify the libraries is create separate,
3675 appropriately named recipes where the
3676 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
3677 name includes a portion that differentiates each library version
3678 (e.g.the major part of the version number).
3679 Thus, instead of having a single recipe that loads one version
3680 of a library (e.g. <filename>clutter</filename>), you provide
3681 multiple recipes that result in different versions
3682 of the libraries you want.
3683 As an example, the following two recipes would allow the
3684 two separate versions of the <filename>clutter</filename>
3685 library to co-exist on the same system:
3686 <literallayout class='monospaced'>
3687 clutter-1.6_1.6.20.bb
3688 clutter-1.8_1.8.4.bb
3689 </literallayout>
3690 Additionally, if you have other recipes that depend on a given
3691 library, you need to use the
3692 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3693 variable to create the dependency.
3694 Continuing with the same example, if you want to have a recipe
3695 depend on the 1.8 version of the <filename>clutter</filename>
3696 library, use the following in your recipe:
3697 <literallayout class='monospaced'>
3698 DEPENDS = "clutter-1.8"
3699 </literallayout>
3700 </para>
3701 </section>
3702 </section>
3703
3704 <section id='creating-partitioned-images'>
3705 <title>Creating Partitioned Images</title>
3706
3707 <para>
3708 Creating an image for a particular hardware target using the
3709 OpenEmbedded build system does not necessarily mean you can boot
3710 that image as is on your device.
3711 Physical devices accept and boot images in various ways depending
3712 on the specifics of the device.
3713 Usually, information about the hardware can tell you what image
3714 format the device requires.
3715 Should your device require multiple partitions on an SD card, flash,
3716 or an HDD, you can use the OpenEmbedded Image Creator,
3717 <filename>wic</filename>, to create the properly partitioned image.
3718 </para>
3719
3720 <para>
3721 The <filename>wic</filename> command generates partitioned images
3722 from existing OpenEmbedded build artifacts.
3723 Image generation is driven by partitioning commands contained
3724 in an Openembedded kickstart file (<filename>.wks</filename>)
3725 specified either directly on the command line or as one of a
3726 selection of canned <filename>.wks</filename> files as shown
3727 with the <filename>wic list images</filename> command in the
3728 "<link linkend='using-a-provided-kickstart_file'>Using an Existing Kickstart File</link>"
3729 section.
3730 When applied to a given set of build artifacts, the result is an
3731 image or set of images that can be directly written onto media and
3732 used on a particular system.
3733 </para>
3734
3735 <para>
3736 The <filename>wic</filename> command and the infrastructure
3737 it is based on is by definition incomplete.
3738 Its purpose is to allow the generation of customized images,
3739 and as such was designed to be completely extensible through a
3740 plugin interface.
3741 See the
3742 "<link linkend='openembedded-kickstart-plugins'>Plugins</link>"
3743 section for information on these plugins.
3744 </para>
3745
3746 <para>
3747 This section provides some background information on
3748 <filename>wic</filename>, describes what you need to have in
3749 place to run the tool, provides instruction on how to use
3750 <filename>wic</filename>, and provides several examples.
3751 </para>
3752
3753 <section id='wic-background'>
3754 <title>Background</title>
3755
3756 <para>
3757 This section provides some background on the
3758 <filename>wic</filename> utility.
3759 While none of this information is required to use
3760 <filename>wic</filename>, you might find it interesting.
3761 <itemizedlist>
3762 <listitem><para>
3763 The name "wic" is derived from OpenEmbedded
3764 Image Creator (oeic).
3765 The "oe" diphthong in "oeic" was promoted to the
3766 letter "w", because "oeic" is both difficult to remember and
3767 pronounce.</para></listitem>
3768 <listitem><para>
3769 <filename>wic</filename> is loosely based on the
3770 Meego Image Creator (<filename>mic</filename>)
3771 framework.
3772 The <filename>wic</filename> implementation has been
3773 heavily modified to make direct use of OpenEmbedded
3774 build artifacts instead of package installation and
3775 configuration, which are already incorporated within
3776 the OpenEmbedded artifacts.</para></listitem>
3777 <listitem><para>
3778 <filename>wic</filename> is a completely independent
3779 standalone utility that initially provides
3780 easier-to-use and more flexible replacements for a
3781 couple bits of existing functionality in OE Core's
3782 <filename>boot-directdisk.bbclass</filename> and
3783 <filename>mkefidisk.sh</filename> scripts.
3784 The difference between
3785 <filename>wic</filename> and those examples is
3786 that with <filename>wic</filename> the
3787 functionality of those scripts is implemented
3788 by a general-purpose partitioning language, which is
3789 based on Redhat kickstart syntax.</para></listitem>
3790 </itemizedlist>
3791 </para>
3792 </section>
3793
3794 <section id='wic-requirements'>
3795 <title>Requirements</title>
3796
3797 <para>
3798 In order to use the <filename>wic</filename> utility
3799 with the OpenEmbedded Build system, your system needs
3800 to meet the following requirements:
3801 <itemizedlist>
3802 <listitem><para>The Linux distribution on your
3803 development host must support the Yocto Project.
3804 See the
3805 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
3806 section in the Yocto Project Reference Manual for this
3807 list of distributions.</para></listitem>
3808 <listitem><para>
3809 The standard system utilities, such as
3810 <filename>cp</filename>, must be installed on your
3811 development host system.
3812 </para></listitem>
3813 <listitem><para>
3814 You need to have the build artifacts already
3815 available, which typically means that you must
3816 have already created an image using the
3817 Openembedded build system (e.g.
3818 <filename>core-image-minimal</filename>).
3819 While it might seem redundant to generate an image in
3820 order to create an image using
3821 <filename>wic</filename>, the current version of
3822 <filename>wic</filename> requires the artifacts
3823 in the form generated by the build system.
3824 </para></listitem>
3825 <listitem><para>
3826 You must build several native tools:
3827 <literallayout class='monospaced'>
3828 $ bitbake parted-native dosfstools-native mtools-native
3829 </literallayout>
3830 </para></listitem>
3831 <listitem><para>
3832 You must have sourced one of the build environment
3833 setup scripts (i.e.
3834 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
3835 or
3836 <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>)
3837 found in the
3838 <link linkend='build-directory'>Build Directory</link>.
3839 </para></listitem>
3840 </itemizedlist>
3841 </para>
3842 </section>
3843
3844 <section id='wic-getting-help'>
3845 <title>Getting Help</title>
3846
3847 <para>
3848 You can get general help for the <filename>wic</filename>
3849 by entering the <filename>wic</filename> command by itself
3850 or by entering the command with a help argument as follows:
3851 <literallayout class='monospaced'>
3852 $ wic -h
3853 $ wic --help
3854 </literallayout>
3855 </para>
3856
3857 <para>
3858 Currently, <filename>wic</filename> supports two commands:
3859 <filename>create</filename> and <filename>list</filename>.
3860 You can get help for these commands as follows:
3861 <literallayout class='monospaced'>
3862 $ wic help <replaceable>command</replaceable>
3863 </literallayout>
3864 </para>
3865
3866 <para>
3867 You can also get detailed help on a number of topics
3868 from the help system.
3869 The output of <filename>wic --help</filename>
3870 displays a list of available help
3871 topics under a "Help topics" heading.
3872 You can have the help system display the help text for
3873 a given topic by prefacing the topic with
3874 <filename>wic help</filename>:
3875 <literallayout class='monospaced'>
3876 $ wic help <replaceable>help_topic</replaceable>
3877 </literallayout>
3878 </para>
3879
3880 <para>
3881 You can find out more about the images
3882 <filename>wic</filename> creates using the existing
3883 kickstart files with the following form of the command:
3884 <literallayout class='monospaced'>
3885 $ wic list <replaceable>image</replaceable> help
3886 </literallayout>
3887 where <filename><replaceable>image</replaceable></filename> is either
3888 <filename>directdisk</filename> or
3889 <filename>mkefidisk</filename>.
3890 </para>
3891 </section>
3892
3893 <section id='operational-modes'>
3894 <title>Operational Modes</title>
3895
3896 <para>
3897 You can use <filename>wic</filename> in two different
3898 modes, depending on how much control you need for
3899 specifying the Openembedded build artifacts that are
3900 used for creating the image: Raw and Cooked:
3901 <itemizedlist>
3902 <listitem><para><emphasis>Raw Mode:</emphasis>
3903 You explicitly specify build artifacts through
3904 command-line arguments.</para></listitem>
3905 <listitem><para><emphasis>Cooked Mode:</emphasis>
3906 The current
3907 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
3908 setting and image name are used to automatically locate
3909 and provide the build artifacts.</para></listitem>
3910 </itemizedlist>
3911 </para>
3912
3913 <para>
3914 Regardless of the mode you use, you need to have the build
3915 artifacts ready and available.
3916 Additionally, the environment must be set up using the
3917 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
3918 or
3919 <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>
3920 script found in the
3921 <link linkend='build-directory'>Build Directory</link>.
3922 </para>
3923
3924 <section id='raw-mode'>
3925 <title>Raw Mode</title>
3926
3927 <para>
3928 The general form of the 'wic' command in raw mode is:
3929 <literallayout class='monospaced'>
3930 $ wic create <replaceable>image_name</replaceable>.wks [<replaceable>options</replaceable>] [...]
3931
3932 Where:
3933
3934 <replaceable>image_name</replaceable>.wks
3935 An OpenEmbedded kickstart file. You can provide
3936 your own custom file or use a file from a set of
3937 existing files as described by further options.
3938
3939 -o <replaceable>OUTDIR</replaceable>, --outdir=<replaceable>OUTDIR</replaceable>
3940 The name of a directory in which to create image.
3941
3942 -i <replaceable>PROPERTIES_FILE</replaceable>, --infile=<replaceable>PROPERTIES_FILE</replaceable>
3943 The name of a file containing the values for image
3944 properties as a JSON file.
3945
3946 -e <replaceable>IMAGE_NAME</replaceable>, --image-name=<replaceable>IMAGE_NAME</replaceable>
3947 The name of the image from which to use the artifacts
3948 (e.g. <filename>core-image-sato</filename>).
3949
3950 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir=<replaceable>ROOTFS_DIR</replaceable>
3951 The path to the <filename>/rootfs</filename> directory to use as the
3952 <filename>.wks</filename> rootfs source.
3953
3954 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir=<replaceable>BOOTIMG_DIR</replaceable>
3955 The path to the directory containing the boot artifacts
3956 (e.g. <filename>/EFI</filename> or <filename>/syslinux</filename>) to use as the <filename>.wks</filename> bootimg
3957 source.
3958
3959 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir=<replaceable>KERNEL_DIR</replaceable>
3960 The path to the directory containing the kernel to use
3961 in the <filename>.wks</filename> boot image.
3962
3963 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot=<replaceable>NATIVE_SYSROOT</replaceable>
3964 The path to the native sysroot containing the tools to use
3965 to build the image.
3966
3967 -s, --skip-build-check
3968 Skips the build check.
3969
3970 -D, --debug
3971 Output debug information.
3972 </literallayout>
3973 <note>
3974 You do not need root privileges to run
3975 <filename>wic</filename>.
3976 In fact, you should not run as root when using the
3977 utility.
3978 </note>
3979 </para>
3980 </section>
3981
3982 <section id='cooked-mode'>
3983 <title>Cooked Mode</title>
3984
3985 <para>
3986 The general form of the <filename>wic</filename> command
3987 using Cooked Mode is:
3988 <literallayout class='monospaced'>
3989 $ wic create <replaceable>kickstart_file</replaceable> -e <replaceable>image_name</replaceable>
3990
3991 Where:
3992
3993 <replaceable>kickstart_file</replaceable>
3994 An OpenEmbedded kickstart file. You can provide your own
3995 custom file or supplied file.
3996
3997 <replaceable>image_name</replaceable>
3998 Specifies the image built using the OpenEmbedded build
3999 system.
4000 </literallayout>
4001 This form is the simplest and most user-friendly, as it
4002 does not require specifying all individual parameters.
4003 All you need to provide is your own
4004 <filename>.wks</filename> file or one provided with the
4005 release.
4006 </para>
4007 </section>
4008 </section>
4009
4010 <section id='using-a-provided-kickstart_file'>
4011 <title>Using an Existing Kickstart File</title>
4012
4013 <para>
4014 If you do not want to create your own
4015 <filename>.wks</filename> file, you can use an existing
4016 file provided by the <filename>wic</filename> installation.
4017 Use the following command to list the available files:
4018 <literallayout class='monospaced'>
4019 $ wic list images
4020 directdisk Create a 'pcbios' direct disk image
4021 mkefidisk Create an EFI disk image
4022 </literallayout>
4023 When you use an existing file, you do not have to use the
4024 <filename>.wks</filename> extension.
4025 Here is an example in Raw Mode that uses the
4026 <filename>directdisk</filename> file:
4027 <literallayout class='monospaced'>
4028 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
4029 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
4030 </literallayout>
4031 </para>
4032
4033 <para>
4034 Here are the actual partition language commands
4035 used in the <filename>mkefidisk.wks</filename> file to generate
4036 an image:
4037 <literallayout class='monospaced'>
4038 # short-description: Create an EFI disk image
4039 # long-description: Creates a partitioned EFI disk image that the user
4040 # can directly dd to boot media.
4041
4042 part /boot --source bootimg-efi --ondisk sda --label msdos --active --align 1024
4043
4044 part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
4045
4046 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
4047
4048 bootloader --timeout=10 --append="rootwait rootfstype=ext3 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0"
4049 </literallayout>
4050 </para>
4051 </section>
4052
4053 <section id='wic-usage-examples'>
4054 <title>Examples</title>
4055
4056 <para>
4057 This section provides several examples that show how to use
4058 the <filename>wic</filename> utility.
4059 All the examples assume the list of requirements in the
4060 "<link linkend='wic-requirements'>Requirements</link>" section
4061 have been met.
4062 The examples assume the previously generated image is
4063 <filename>core-image-minimal</filename>.
4064 </para>
4065
4066 <section id='generate-an-image-using-a-provided-kickstart-file'>
4067 <title>Generate an Image using an Existing Kickstart File</title>
4068
4069 <para>
4070 This example runs in Cooked Mode and uses the
4071 <filename>mkefidisk</filename> kickstart file:
4072 <literallayout class='monospaced'>
4073 $ wic create mkefidisk -e core-image-minimal
4074 Checking basic build environment...
4075 Done.
4076
4077 Creating image(s)...
4078
4079 Info: The new image(s) can be found here:
4080 /var/tmp/wic/build/mkefidisk-201310230946-sda.direct
4081
4082 The following build artifacts were used to create the image(s):
4083 ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/rootfs
4084 BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/core-image-minimal-1.0/hddimg
4085 KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/minnow/usr/src/kernel
4086 NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux
4087
4088
4089 The image(s) were created using OE kickstart file:
4090 /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/mkefidisk.wks
4091 </literallayout>
4092 This example shows the easiest way to create an image
4093 by running in Cooked Mode and using the
4094 <filename>-e</filename> option with an existing kickstart
4095 file.
4096 All that is necessary is to specify the image used to
4097 generate the artifacts.
4098 Your <filename>local.conf</filename> needs to have the
4099 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4100 variable set to the machine you are using, which is
4101 "minnow" in this example.
4102 </para>
4103
4104 <para>
4105 The output specifies the exact created as well as where
4106 it was created.
4107 The output also names the artifacts used and the exact
4108 <filename>.wks</filename> script that was used to generate
4109 the image.
4110 <note>
4111 You should always verify the details provided in the
4112 output to make sure that the image was indeed created
4113 exactly as expected.
4114 </note>
4115 </para>
4116
4117 <para>
4118 Continuing with the example, you can now directly
4119 <filename>dd</filename> the image to a USB stick, or
4120 whatever media for which you built your image,
4121 and boot the resulting media:
4122 <literallayout class='monospaced'>
4123 $ sudo dd if=/var/tmp/wic/build/mkefidisk-201310230946-sda.direct of=/dev/sdb
4124 [sudo] password for trz:
4125 182274+0 records in
4126 182274+0 records out
4127 93324288 bytes (93 MB) copied, 14.4777 s, 6.4 MB/s
4128 [trz@empanada ~]$ sudo eject /dev/sdb
4129 </literallayout>
4130 </para>
4131 </section>
4132
4133 <section id='using-a-modified-kickstart-file'>
4134 <title>Using a Modified Kickstart File</title>
4135
4136 <para>
4137 Because <filename>wic</filename> image creation is driven
4138 by the kickstart file, it is easy to affect image creation
4139 by changing the parameters in the file.
4140 This next example demonstrates that through modification
4141 of the <filename>directdisk</filename> kickstart file.
4142 </para>
4143
4144 <para>
4145 As mentioned earlier, you can use the command
4146 <filename>wic list images</filename> to show the list
4147 of existing kickstart files.
4148 The directory in which these files reside is
4149 <filename>scripts/lib/image/canned-wks/</filename>
4150 located in the
4151 <link linkend='source-directory'>Source Directory</link>.
4152 Because the available files reside in this directory, you
4153 can create and add your own custom files to the directory.
4154 Subsequent use of the <filename>wic list images</filename>
4155 command would then include your kickstart files.
4156 </para>
4157
4158 <para>
4159 In this example, the existing
4160 <filename>directdisk</filename> file already does most
4161 of what is needed.
4162 However, for the hardware in this example, the image will
4163 need to boot from <filename>sdb</filename> instead of
4164 <filename>sda</filename>, which is what the
4165 <filename>directdisk</filename> kickstart file uses.
4166 </para>
4167
4168 <para>
4169 The example begins by making a copy of the
4170 <filename>directdisk.wks</filename> file in the
4171 <filename>scripts/lib/image/canned-wks</filename>
4172 directory and then changing the lines that specify the
4173 target disk from which to boot.
4174 <literallayout class='monospaced'>
4175 $ cp /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks \
4176 /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks
4177 </literallayout>
4178 Next, the example modifies the
4179 <filename>directdisksdb.wks</filename> file and changes all
4180 instances of "<filename>--ondisk sda</filename>"
4181 to "<filename>--ondisk sdb</filename>".
4182 The example changes the following two lines and leaves the
4183 remaining lines untouched:
4184 <literallayout class='monospaced'>
4185 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
4186 part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024
4187 </literallayout>
4188 Once the lines are changed, the example generates the
4189 <filename>directdisksdb</filename> image.
4190 The command points the process at the
4191 <filename>core-image-minimal</filename> artifacts for the
4192 Next Unit of Computing (nuc)
4193 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4194 the <filename>local.conf</filename>.
4195 <literallayout class='monospaced'>
4196 $ wic create directdisksdb -e core-image-minimal
4197 Checking basic build environment...
4198 Done.
4199
4200 Creating image(s)...
4201
4202 Info: The new image(s) can be found here:
4203 /var/tmp/wic/build/directdisksdb-201310231131-sdb.direct
4204
4205 The following build artifacts were used to create the image(s):
4206 ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/nuc-poky-linux/core-image-minimal/1.0-r0/rootfs
4207 BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/share
4208 KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/src/kernel
4209 NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux
4210
4211
4212 The image(s) were created using OE kickstart file:
4213 /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks
4214 </literallayout>
4215 Continuing with the example, you can now directly
4216 <filename>dd</filename> the image to a USB stick, or
4217 whatever media for which you built your image,
4218 and boot the resulting media:
4219 <literallayout class='monospaced'>
4220 $ sudo dd if=/var/tmp/wic/build/directdisksdb-201310231131-sdb.direct of=/dev/sdb
4221 86018+0 records in
4222 86018+0 records out
4223 44041216 bytes (44 MB) copied, 13.0734 s, 3.4 MB/s
4224 [trz@empanada tmp]$ sudo eject /dev/sdb
4225 </literallayout>
4226 </para>
4227 </section>
4228
4229 <section id='creating-an-image-based-on-core-image-minimal-and-crownbay-noemgd'>
4230 <title>Creating an Image Based on <filename>core-image-minimal</filename> and <filename>crownbay-noemgd</filename></title>
4231
4232 <para>
4233 This example creates an image based on
4234 <filename>core-image-minimal</filename> and a
4235 <filename>crownbay-noemgd</filename>
4236 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4237 that works right out of the box.
4238 <literallayout class='monospaced'>
4239 $ wic create directdisk -e core-image-minimal
4240
4241 Checking basic build environment...
4242 Done.
4243
4244 Creating image(s)...
4245
4246 Info: The new image(s) can be found here:
4247 /var/tmp/wic/build/directdisk-201309252350-sda.direct
4248
4249 The following build artifacts were used to create the image(s):
4250
4251 ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs
4252 BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share
4253 KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
4254 NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
4255
4256 The image(s) were created using OE kickstart file:
4257 /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks
4258 </literallayout>
4259 </para>
4260 </section>
4261
4262 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
4263 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
4264
4265 <para>
4266 This next example manually specifies each build artifact
4267 (runs in Raw Mode) and uses a modified kickstart file.
4268 The example also uses the <filename>-o</filename> option
4269 to cause <filename>wic</filename> to create the output
4270 somewhere other than the default
4271 <filename>/var/tmp/wic</filename> directory:
4272 <literallayout class='monospaced'>
4273 $ wic create ~/test.wks -o /home/trz/testwic --rootfs-dir \
4274 /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs \
4275 --bootimg-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share \
4276 --kernel-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel \
4277 --native-sysroot /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux
4278
4279 Creating image(s)...
4280
4281 Info: The new image(s) can be found here:
4282 /home/trz/testwic/build/test-201309260032-sda.direct
4283
4284 The following build artifacts were used to create the image(s):
4285
4286 ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs
4287 BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share
4288 KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
4289 NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel
4290
4291 The image(s) were created using OE kickstart file:
4292 /home/trz/test.wks
4293 </literallayout>
4294 For this example,
4295 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4296 did not have to be specified in the
4297 <filename>local.conf</filename> file since the artifact is
4298 manually specified.
4299 </para>
4300 </section>
4301 </section>
4302
4303 <section id='openembedded-kickstart-plugins'>
4304 <title>Plugins</title>
4305
4306 <para>
4307 Plugins allow <filename>wic</filename> functionality to
4308 be extended and specialized by users.
4309 This section documents the plugin interface, which is
4310 currently restricted to source plugins.
4311 </para>
4312
4313 <para>
4314 Source plugins provide a mechanism to customize
4315 various aspects of the image generation process in
4316 <filename>wic</filename>, mainly the contents of
4317 partitions.
4318 The plugins provide a mechanism for mapping values
4319 specified in <filename>.wks</filename> files using the
4320 <filename>--source</filename> keyword to a
4321 particular plugin implementation that populates a
4322 corresponding partition.
4323 </para>
4324
4325 <para>
4326 A source plugin is created as a subclass of
4327 <filename>SourcePlugin</filename>.
4328 The plugin file containing it is added to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05004329 <filename>scripts/lib/wic/plugins/source/</filename> to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004330 make the plugin implementation available to the
4331 <filename>wic</filename> implementation.
4332 For more information, see
Patrick Williamsf1e5d692016-03-30 15:21:19 -05004333 <filename>scripts/lib/wic/pluginbase.py</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004334 </para>
4335
4336 <para>
4337 Source plugins can also be implemented and added by
4338 external layers.
4339 As such, any plugins found in a
Patrick Williamsf1e5d692016-03-30 15:21:19 -05004340 <filename>scripts/lib/wic/plugins/source/</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004341 directory in an external layer are also made
4342 available.
4343 </para>
4344
4345 <para>
4346 When the <filename>wic</filename> implementation needs
4347 to invoke a partition-specific implementation, it looks
4348 for the plugin that has the same name as the
4349 <filename>--source</filename> parameter given to
4350 that partition.
4351 For example, if the partition is set up as follows:
4352 <literallayout class='monospaced'>
4353 part /boot --source bootimg-pcbios ...
4354 </literallayout>
4355 The methods defined as class members of the plugin
4356 having the matching <filename>bootimg-pcbios.name</filename>
4357 class member are used.
4358 </para>
4359
4360 <para>
4361 To be more concrete, here is the plugin definition that
4362 matches a
4363 <filename>--source bootimg-pcbios</filename> usage,
4364 along with an example
4365 method called by the <filename>wic</filename> implementation
4366 when it needs to invoke an implementation-specific
4367 partition-preparation function:
4368 <literallayout class='monospaced'>
4369 class BootimgPcbiosPlugin(SourcePlugin):
4370 name = 'bootimg-pcbios'
4371
4372 @classmethod
4373 def do_prepare_partition(self, part, ...)
4374 </literallayout>
4375 If the subclass itself does not implement a function, a
4376 default version in a superclass is located and
4377 used, which is why all plugins must be derived from
4378 <filename>SourcePlugin</filename>.
4379 </para>
4380
4381 <para>
4382 The <filename>SourcePlugin</filename> class defines the
4383 following methods, which is the current set of methods
4384 that can be implemented or overridden by
4385 <filename>--source</filename> plugins.
4386 Any methods not implemented by a
4387 <filename>SourcePlugin</filename> subclass inherit the
4388 implementations present in the
4389 <filename>SourcePlugin</filename> class.
4390 For more information, see the
4391 <filename>SourcePlugin</filename> source for details:
4392 </para>
4393
4394 <para>
4395 <itemizedlist>
4396 <listitem><para><emphasis><filename>do_prepare_partition()</filename>:</emphasis>
4397 Called to do the actual content population for a
4398 partition.
4399 In other words, the method prepares the final
4400 partition image that is incorporated into the
4401 disk image.
4402 </para></listitem>
4403 <listitem><para><emphasis><filename>do_configure_partition()</filename>:</emphasis>
4404 Called before
4405 <filename>do_prepare_partition()</filename>.
4406 This method is typically used to create custom
4407 configuration files for a partition (e.g. syslinux or
4408 grub configuration files).
4409 </para></listitem>
4410 <listitem><para><emphasis><filename>do_install_disk()</filename>:</emphasis>
4411 Called after all partitions have been prepared and
4412 assembled into a disk image.
4413 This method provides a hook to allow finalization of a
4414 disk image, (e.g. writing an MBR).
4415 </para></listitem>
4416 <listitem><para><emphasis><filename>do_stage_partition()</filename>:</emphasis>
4417 Special content-staging hook called before
4418 <filename>do_prepare_partition()</filename>.
4419 This method is normally empty.</para>
4420 <para>Typically, a partition just uses the passed-in
4421 parameters (e.g. the unmodified value of
4422 <filename>bootimg_dir</filename>).
4423 However, in some cases things might need to be
4424 more tailored.
4425 As an example, certain files might additionally
4426 need to be taken from
4427 <filename>bootimg_dir + /boot</filename>.
4428 This hook allows those files to be staged in a
4429 customized fashion.
4430 <note>
4431 <filename>get_bitbake_var()</filename>
4432 allows you to access non-standard variables
4433 that you might want to use for this.
4434 </note>
4435 </para></listitem>
4436 </itemizedlist>
4437 </para>
4438
4439 <para>
4440 This scheme is extensible.
4441 Adding more hooks is a simple matter of adding more
4442 plugin methods to <filename>SourcePlugin</filename> and
4443 derived classes.
4444 The code that then needs to call the plugin methods uses
4445 <filename>plugin.get_source_plugin_methods()</filename>
4446 to find the method or methods needed by the call.
4447 Retrieval of those methods is accomplished
4448 by filling up a dict with keys
4449 containing the method names of interest.
4450 On success, these will be filled in with the actual
4451 methods.
4452 Please see the <filename>wic</filename>
4453 implementation for examples and details.
4454 </para>
4455 </section>
4456
4457 <section id='openembedded-kickstart-wks-reference'>
4458 <title>OpenEmbedded Kickstart (.wks) Reference</title>
4459
4460 <para>
4461 The current <filename>wic</filename> implementation supports
4462 only the basic kickstart partitioning commands:
4463 <filename>partition</filename> (or <filename>part</filename>
4464 for short) and <filename>bootloader</filename>.
4465 <note>
4466 Future updates will implement more commands and options.
4467 If you use anything that is not specifically
4468 supported, results can be unpredictable.
4469 </note>
4470 </para>
4471
4472 <para>
4473 The following is a list of the commands, their syntax,
4474 and meanings.
4475 The commands are based on the Fedora
4476 kickstart versions but with modifications to
4477 reflect <filename>wic</filename> capabilities.
4478 You can see the original documentation for those commands
4479 at the following links:
4480 <itemizedlist>
4481 <listitem><para>
4482 <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition'>http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition</ulink>
4483 </para></listitem>
4484 <listitem><para>
4485 <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader'>http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader</ulink>
4486 </para></listitem>
4487 </itemizedlist>
4488 </para>
4489
4490 <section id='command-part-or-partition'>
4491 <title>Command: part or partition</title>
4492
4493 <para>
4494 This command creates a partition on the system and uses the
4495 following syntax:
4496 <literallayout class='monospaced'>
4497 part <replaceable>mntpoint</replaceable>
4498 </literallayout>
4499 The <filename><replaceable>mntpoint</replaceable></filename>
4500 is where the
4501 partition will be mounted and must be of one of the
4502 following forms:
4503 <itemizedlist>
4504 <listitem><para><filename>/<replaceable>path</replaceable></filename>:
4505 For example, <filename>/</filename>,
4506 <filename>/usr</filename>, and
4507 <filename>/home</filename></para></listitem>
4508 <listitem><para><filename>swap</filename>:
4509 The partition will be used as swap space.
4510 </para></listitem>
4511 </itemizedlist>
4512 </para>
4513
4514 <para>
4515 Following are the supported options:
4516 <itemizedlist>
4517 <listitem><para><emphasis><filename>--size</filename>:</emphasis>
4518 The minimum partition size in MBytes.
4519 Specify an integer value such as 500.
4520 Do not append the number with "MB".
4521 You do not need this option if you use
4522 <filename>--source</filename>.</para></listitem>
4523 <listitem><para><emphasis><filename>--source</filename>:</emphasis>
4524 This option is a
4525 <filename>wic</filename>-specific option that
4526 names the source of the data that populates
4527 the partition.
4528 The most common value for this option is
4529 "rootfs", but you can use any value that maps to
4530 a valid source plugin.
4531 For information on the source plugins, see the
4532 "<link linkend='openembedded-kickstart-plugins'>Plugins</link>"
4533 section.</para>
4534 <para>If you use
4535 <filename>--source rootfs</filename>,
4536 <filename>wic</filename> creates a partition as
4537 large as needed and to fill it with the contents of
4538 the root filesystem pointed to by the
4539 <filename>-r</filename> command-line option
4540 or the equivalent rootfs derived from the
4541 <filename>-e</filename> command-line
4542 option.
4543 The filesystem type used to create the
4544 partition is driven by the value of the
4545 <filename>--fstype</filename> option
4546 specified for the partition.
4547 See the entry on
4548 <filename>--fstype</filename> that
4549 follows for more information.
4550 </para>
4551 <para>If you use
4552 <filename>--source <replaceable>plugin-name</replaceable></filename>,
4553 <filename>wic</filename> creates a partition as
4554 large as needed and fills it with the contents of
4555 the partition that is generated by the
4556 specified plugin name using the data pointed
4557 to by the <filename>-r</filename> command-line
4558 option or the equivalent rootfs derived from the
4559 <filename>-e</filename> command-line
4560 option.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05004561 Exactly what those contents and filesystem type end
4562 up being are dependent on the given plugin
4563 implementation.
4564 </para>
4565 <para>If you do not use the
4566 <filename>--source</filename> option, the
4567 <filename>wic</filename> command creates an empty
4568 partition.
4569 Consequently, you must use the
4570 <filename>--size</filename> option to specify the
4571 size of the empty partition.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004572 </para></listitem>
4573 <listitem><para><emphasis><filename>--ondisk</filename> or <filename>--ondrive</filename>:</emphasis>
4574 Forces the partition to be created on a particular
4575 disk.</para></listitem>
4576 <listitem><para><emphasis><filename>--fstype</filename>:</emphasis>
4577 Sets the file system type for the partition.
4578 Valid values are:
4579 <itemizedlist>
4580 <listitem><para><filename>ext4</filename>
4581 </para></listitem>
4582 <listitem><para><filename>ext3</filename>
4583 </para></listitem>
4584 <listitem><para><filename>ext2</filename>
4585 </para></listitem>
4586 <listitem><para><filename>btrfs</filename>
4587 </para></listitem>
4588 <listitem><para><filename>squashfs</filename>
4589 </para></listitem>
4590 <listitem><para><filename>swap</filename>
4591 </para></listitem>
4592 </itemizedlist></para></listitem>
4593 <listitem><para><emphasis><filename>--fsoptions</filename>:</emphasis>
4594 Specifies a free-form string of options to be
4595 used when mounting the filesystem.
4596 This string will be copied into the
4597 <filename>/etc/fstab</filename> file of the
4598 installed system and should be enclosed in
4599 quotes.
4600 If not specified, the default string
4601 is "defaults".
4602 </para></listitem>
4603 <listitem><para><emphasis><filename>--label label</filename>:</emphasis>
4604 Specifies the label to give to the filesystem to
4605 be made on the partition.
4606 If the given label is already in use by another
4607 filesystem, a new label is created for the
4608 partition.</para></listitem>
4609 <listitem><para><emphasis><filename>--active</filename>:</emphasis>
4610 Marks the partition as active.</para></listitem>
4611 <listitem><para><emphasis><filename>--align (in KBytes)</filename>:</emphasis>
4612 This option is a <filename>wic</filename>-specific
4613 option that says to start a partition on an
4614 x KBytes boundary.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05004615 <listitem><para><emphasis><filename>--no-table</filename>:</emphasis>
4616 This option is a <filename>wic</filename>-specific
4617 option.
4618 Using the option reserves space for the partition
4619 and causes it to become populated.
4620 However, the partition is not added to the
4621 partition table.
4622 </para></listitem>
4623 <listitem><para><emphasis><filename>--extra-space</filename>:</emphasis>
4624 This option is a <filename>wic</filename>-specific
4625 option that adds extra space after the space
4626 filled by the content of the partition.
4627 The final size can go beyond the size specified
4628 by the <filename>--size</filename> option.
4629 The default value is 10 Mbytes.
4630 </para></listitem>
4631 <listitem><para><emphasis><filename>--overhead-factor</filename>:</emphasis>
4632 This option is a <filename>wic</filename>-specific
4633 option that multiplies the size of the partition by
4634 the option's value.
4635 You must supply a value greater than or equal to
4636 "1".
4637 The default value is "1.3".
4638 </para></listitem>
4639 <listitem><para><emphasis><filename>--part-type</filename>:</emphasis>
4640 This option is a <filename>wic</filename>-specific
4641 option that specifies the partition type globally
4642 unique identifier (GUID) for GPT partitions.
4643 You can find the list of partition type GUIDs
4644 at
4645 <ulink url='http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs'></ulink>.
4646 </para></listitem>
4647 <listitem><para><emphasis><filename>--use-uuid</filename>:</emphasis>
4648 This option is a <filename>wic</filename>-specific
4649 option that causes <filename>wic</filename> to
4650 generate a random GUID for the partition.
4651 The generated identifier is used in the bootloader
4652 configuration to specify the root partition.
4653 </para></listitem>
4654 <listitem><para><emphasis><filename>--uuid</filename>:</emphasis>
4655 This option is a <filename>wic</filename>-specific
4656 option that specifies the partition UUID.
4657 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004658 </itemizedlist>
4659 </para>
4660 </section>
4661
4662 <section id='command-bootloader'>
4663 <title>Command: bootloader</title>
4664
4665 <para>
4666 This command specifies how the boot loader should be
4667 configured and supports the following options:
4668 <note>
4669 Bootloader functionality and boot partitions are
4670 implemented by the various
4671 <filename>--source</filename>
4672 plugins that implement bootloader functionality.
4673 The bootloader command essentially provides a means of
4674 modifying bootloader configuration.
4675 </note>
4676 <itemizedlist>
4677 <listitem><para><emphasis><filename>--timeout</filename>:</emphasis>
4678 Specifies the number of seconds before the
4679 bootloader times out and boots the default option.
4680 </para></listitem>
4681 <listitem><para><emphasis><filename>--append</filename>:</emphasis>
4682 Specifies kernel parameters.
4683 These parameters will be added to the syslinux
4684 <filename>APPEND</filename> or
4685 <filename>grub</filename> kernel command line.
4686 </para></listitem>
4687 </itemizedlist>
4688 </para>
4689 </section>
4690 </section>
4691 </section>
4692
4693 <section id='configuring-the-kernel'>
4694 <title>Configuring the Kernel</title>
4695
4696 <para>
4697 Configuring the Yocto Project kernel consists of making sure the
4698 <filename>.config</filename> file has all the right information
4699 in it for the image you are building.
4700 You can use the <filename>menuconfig</filename> tool and
4701 configuration fragments to make sure your
4702 <filename>.config</filename> file is just how you need it.
4703 You can also save known configurations in a
4704 <filename>defconfig</filename> file that the build system can use
4705 for kernel configuration.
4706 </para>
4707
4708 <para>
4709 This section describes how to use <filename>menuconfig</filename>,
4710 create and use configuration fragments, and how to interactively
4711 modify your <filename>.config</filename> file to create the
4712 leanest kernel configuration file possible.
4713 </para>
4714
4715 <para>
4716 For more information on kernel configuration, see the
4717 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4718 section in the Yocto Project Linux Kernel Development Manual.
4719 </para>
4720
4721 <section id='using-menuconfig'>
4722 <title>Using&nbsp;&nbsp;<filename>menuconfig</filename></title>
4723
4724 <para>
4725 The easiest way to define kernel configurations is to set them through the
4726 <filename>menuconfig</filename> tool.
4727 This tool provides an interactive method with which
4728 to set kernel configurations.
4729 For general information on <filename>menuconfig</filename>, see
4730 <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>.
4731 </para>
4732
4733 <para>
4734 To use the <filename>menuconfig</filename> tool in the Yocto Project development
4735 environment, you must launch it using BitBake.
4736 Thus, the environment must be set up using the
4737 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
4738 or
4739 <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>
4740 script found in the
4741 <link linkend='build-directory'>Build Directory</link>.
4742 You must also be sure of the state of your build in the
4743 <link linkend='source-directory'>Source Directory</link>.
4744 The following commands run <filename>menuconfig</filename>
4745 assuming the Source Directory's top-level folder is
4746 <filename>~/poky</filename>:
4747 <literallayout class='monospaced'>
4748 $ cd poky
4749 $ source oe-init-build-env
4750 $ bitbake linux-yocto -c kernel_configme -f
4751 $ bitbake linux-yocto -c menuconfig
4752 </literallayout>
4753 Once <filename>menuconfig</filename> comes up, its standard
4754 interface allows you to interactively examine and configure
4755 all the kernel configuration parameters.
4756 After making your changes, simply exit the tool and save your
4757 changes to create an updated version of the
4758 <filename>.config</filename> configuration file.
4759 </para>
4760
4761 <para>
4762 Consider an example that configures the <filename>linux-yocto-3.14</filename>
4763 kernel.
4764 The OpenEmbedded build system recognizes this kernel as
4765 <filename>linux-yocto</filename>.
4766 Thus, the following commands from the shell in which you previously sourced the
4767 environment initialization script cleans the shared state cache and the
4768 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
4769 directory and then runs <filename>menuconfig</filename>:
4770 <literallayout class='monospaced'>
4771 $ bitbake linux-yocto -c menuconfig
4772 </literallayout>
4773 </para>
4774
4775 <para>
4776 Once <filename>menuconfig</filename> launches, use the interface
4777 to navigate through the selections to find the configuration settings in
4778 which you are interested.
4779 For example, consider the <filename>CONFIG_SMP</filename> configuration setting.
4780 You can find it at <filename>Processor Type and Features</filename> under
4781 the configuration selection <filename>Symmetric Multi-processing Support</filename>.
4782 After highlighting the selection, use the arrow keys to select or deselect
4783 the setting.
4784 When you are finished with all your selections, exit out and save them.
4785 </para>
4786
4787 <para>
4788 Saving the selections updates the <filename>.config</filename> configuration file.
4789 This is the file that the OpenEmbedded build system uses to configure the
4790 kernel during the build.
4791 You can find and examine this file in the Build Directory in
4792 <filename>tmp/work/</filename>.
4793 The actual <filename>.config</filename> is located in the area where the
4794 specific kernel is built.
4795 For example, if you were building a Linux Yocto kernel based on the
4796 Linux 3.14 kernel and you were building a QEMU image targeted for
4797 <filename>x86</filename> architecture, the
4798 <filename>.config</filename> file would be located here:
4799 <literallayout class='monospaced'>
4800 poky/build/tmp/work/qemux86-poky-linux/linux-yocto-3.14.11+git1+84f...
4801 ...656ed30-r1/linux-qemux86-standard-build
4802 </literallayout>
4803 <note>
4804 The previous example directory is artificially split and many of the characters
4805 in the actual filename are omitted in order to make it more readable.
4806 Also, depending on the kernel you are using, the exact pathname
4807 for <filename>linux-yocto-3.14...</filename> might differ.
4808 </note>
4809 </para>
4810
4811 <para>
4812 Within the <filename>.config</filename> file, you can see the kernel settings.
4813 For example, the following entry shows that symmetric multi-processor support
4814 is not set:
4815 <literallayout class='monospaced'>
4816 # CONFIG_SMP is not set
4817 </literallayout>
4818 </para>
4819
4820 <para>
4821 A good method to isolate changed configurations is to use a combination of the
4822 <filename>menuconfig</filename> tool and simple shell commands.
4823 Before changing configurations with <filename>menuconfig</filename>, copy the
4824 existing <filename>.config</filename> and rename it to something else,
4825 use <filename>menuconfig</filename> to make
4826 as many changes as you want and save them, then compare the renamed configuration
4827 file against the newly created file.
4828 You can use the resulting differences as your base to create configuration fragments
4829 to permanently save in your kernel layer.
4830 <note>
4831 Be sure to make a copy of the <filename>.config</filename> and don't just
4832 rename it.
4833 The build system needs an existing <filename>.config</filename>
4834 from which to work.
4835 </note>
4836 </para>
4837 </section>
4838
4839 <section id='creating-a-defconfig-file'>
4840 <title>Creating a&nbsp;&nbsp;<filename>defconfig</filename> File</title>
4841
4842 <para>
4843 A <filename>defconfig</filename> file is simply a
4844 <filename>.config</filename> renamed to "defconfig".
4845 You can use a <filename>defconfig</filename> file
4846 to retain a known set of kernel configurations from which the
4847 OpenEmbedded build system can draw to create the final
4848 <filename>.config</filename> file.
4849 <note>
4850 Out-of-the-box, the Yocto Project never ships a
4851 <filename>defconfig</filename> or
4852 <filename>.config</filename> file.
4853 The OpenEmbedded build system creates the final
4854 <filename>.config</filename> file used to configure the
4855 kernel.
4856 </note>
4857 </para>
4858
4859 <para>
4860 To create a <filename>defconfig</filename>, start with a
4861 complete, working Linux kernel <filename>.config</filename>
4862 file.
4863 Copy that file to the appropriate
4864 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
4865 directory in your layer's
4866 <filename>recipes-kernel/linux</filename> directory, and rename
4867 the copied file to "defconfig".
4868 Then, add the following lines to the linux-yocto
4869 <filename>.bbappend</filename> file in your layer:
4870 <literallayout class='monospaced'>
4871 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
4872 SRC_URI += "file://defconfig"
4873 </literallayout>
4874 The
4875 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
4876 tells the build system how to search for the file, while the
4877 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
4878 extends the
4879 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
4880 variable (search directories) to include the
4881 <filename>${PN}</filename> directory you created to hold the
4882 configuration changes.
4883 <note>
4884 The build system applies the configurations from the
4885 <filename>defconfig</filename> file before applying any
4886 subsequent configuration fragments.
4887 The final kernel configuration is a combination of the
4888 configurations in the <filename>defconfig</filename>
4889 file and any configuration fragments you provide.
4890 You need to realize that if you have any configuration
4891 fragments, the build system applies these on top of and
4892 after applying the existing defconfig file configurations.
4893 </note>
4894 For more information on configuring the kernel, see the
4895 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4896 and
4897 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>"
4898 sections, both in the Yocto Project Linux Kernel Development
4899 Manual.
4900 </para>
4901 </section>
4902
4903 <section id='creating-config-fragments'>
4904 <title>Creating Configuration Fragments</title>
4905
4906 <para>
4907 Configuration fragments are simply kernel options that appear in a file
4908 placed where the OpenEmbedded build system can find and apply them.
4909 Syntactically, the configuration statement is identical to what would appear
4910 in the <filename>.config</filename> file, which is in the
4911 <link linkend='build-directory'>Build Directory</link>:
4912 <literallayout class='monospaced'>
4913 tmp/work/<replaceable>arch</replaceable>-poky-linux/linux-yocto-<replaceable>release_specific_string</replaceable>/linux-<replaceable>arch</replaceable>-<replaceable>build_type</replaceable>
4914 </literallayout>
4915 </para>
4916
4917 <para>
4918 It is simple to create a configuration fragment.
4919 For example, issuing the following from the shell creates a configuration fragment
4920 file named <filename>my_smp.cfg</filename> that enables multi-processor support
4921 within the kernel:
4922 <literallayout class='monospaced'>
4923 $ echo "CONFIG_SMP=y" >> my_smp.cfg
4924 </literallayout>
4925 <note>
4926 All configuration fragment files must use the
4927 <filename>.cfg</filename> extension in order for the
4928 OpenEmbedded build system to recognize them as a
4929 configuration fragment.
4930 </note>
4931 </para>
4932
4933 <para>
4934 Where do you put your configuration fragment files?
4935 You can place these files in the same area pointed to by
4936 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
4937 The OpenEmbedded build system picks up the configuration and
4938 adds it to the kernel's configuration.
4939 For example, suppose you had a set of configuration options
4940 in a file called <filename>myconfig.cfg</filename>.
4941 If you put that file inside a directory named
4942 <filename>linux-yocto</filename> that resides in the same
4943 directory as the kernel's append file and then add a
4944 <filename>SRC_URI</filename> statement such as the following
4945 to the kernel's append file, those configuration options
4946 will be picked up and applied when the kernel is built.
4947 <literallayout class='monospaced'>
4948 SRC_URI += "file://myconfig.cfg"
4949 </literallayout>
4950 </para>
4951
4952 <para>
4953 As mentioned earlier, you can group related configurations into multiple files and
4954 name them all in the <filename>SRC_URI</filename> statement as well.
4955 For example, you could group separate configurations specifically for Ethernet and graphics
4956 into their own files and add those by using a <filename>SRC_URI</filename> statement like the
4957 following in your append file:
4958 <literallayout class='monospaced'>
4959 SRC_URI += "file://myconfig.cfg \
4960 file://eth.cfg \
4961 file://gfx.cfg"
4962 </literallayout>
4963 </para>
4964 </section>
4965
4966 <section id='fine-tuning-the-kernel-configuration-file'>
4967 <title>Fine-Tuning the Kernel Configuration File</title>
4968
4969 <para>
4970 You can make sure the <filename>.config</filename> file is as lean or efficient as
4971 possible by reading the output of the kernel configuration fragment audit,
4972 noting any issues, making changes to correct the issues, and then repeating.
4973 </para>
4974
4975 <para>
4976 As part of the kernel build process, the
4977 <filename>do_kernel_configcheck</filename> task runs.
4978 This task validates the kernel configuration by checking the final
4979 <filename>.config</filename> file against the input files.
4980 During the check, the task produces warning messages for the following
4981 issues:
4982 <itemizedlist>
4983 <listitem><para>Requested options that did not make the final
4984 <filename>.config</filename> file.</para></listitem>
4985 <listitem><para>Configuration items that appear twice in the same
4986 configuration fragment.</para></listitem>
4987 <listitem><para>Configuration items tagged as "required" that were overridden.
4988 </para></listitem>
4989 <listitem><para>A board overrides a non-board specific option.</para></listitem>
4990 <listitem><para>Listed options not valid for the kernel being processed.
4991 In other words, the option does not appear anywhere.</para></listitem>
4992 </itemizedlist>
4993 <note>
4994 The <filename>do_kernel_configcheck</filename> task can
4995 also optionally report if an option is overridden during
4996 processing.
4997 </note>
4998 </para>
4999
5000 <para>
5001 For each output warning, a message points to the file
5002 that contains a list of the options and a pointer to the
5003 configuration fragment that defines them.
5004 Collectively, the files are the key to streamlining the
5005 configuration.
5006 </para>
5007
5008 <para>
5009 To streamline the configuration, do the following:
5010 <orderedlist>
5011 <listitem><para>Start with a full configuration that you
5012 know works - it builds and boots successfully.
5013 This configuration file will be your baseline.
5014 </para></listitem>
5015 <listitem><para>Separately run the
5016 <filename>do_configme</filename> and
5017 <filename>do_kernel_configcheck</filename> tasks.
5018 </para></listitem>
5019 <listitem><para>Take the resulting list of files from the
5020 <filename>do_kernel_configcheck</filename> task
5021 warnings and do the following:
5022 <itemizedlist>
5023 <listitem><para>
5024 Drop values that are redefined in the fragment
5025 but do not change the final
5026 <filename>.config</filename> file.
5027 </para></listitem>
5028 <listitem><para>
5029 Analyze and potentially drop values from the
5030 <filename>.config</filename> file that override
5031 required configurations.
5032 </para></listitem>
5033 <listitem><para>
5034 Analyze and potentially remove non-board
5035 specific options.
5036 </para></listitem>
5037 <listitem><para>
5038 Remove repeated and invalid options.
5039 </para></listitem>
5040 </itemizedlist></para></listitem>
5041 <listitem><para>
5042 After you have worked through the output of the kernel
5043 configuration audit, you can re-run the
5044 <filename>do_configme</filename> and
5045 <filename>do_kernel_configcheck</filename> tasks to
5046 see the results of your changes.
5047 If you have more issues, you can deal with them as
5048 described in the previous step.
5049 </para></listitem>
5050 </orderedlist>
5051 </para>
5052
5053 <para>
5054 Iteratively working through steps two through four eventually yields
5055 a minimal, streamlined configuration file.
5056 Once you have the best <filename>.config</filename>, you can build the Linux
5057 Yocto kernel.
5058 </para>
5059 </section>
5060 </section>
5061
5062 <section id="patching-the-kernel">
5063 <title>Patching the Kernel</title>
5064
5065 <para>
5066 Patching the kernel involves changing or adding configurations to an existing kernel,
5067 changing or adding recipes to the kernel that are needed to support specific hardware features,
5068 or even altering the source code itself.
5069 <note>
5070 You can use the <filename>yocto-kernel</filename> script
5071 found in the <link linkend='source-directory'>Source Directory</link>
5072 under <filename>scripts</filename> to manage kernel patches and configuration.
5073 See the "<ulink url='&YOCTO_DOCS_BSP_URL;#managing-kernel-patches-and-config-items-with-yocto-kernel'>Managing kernel Patches and Config Items with yocto-kernel</ulink>"
5074 section in the Yocto Project Board Support Packages (BSP) Developer's Guide for
5075 more information.</note>
5076 </para>
5077
5078 <para>
5079 This example creates a simple patch by adding some QEMU emulator console
5080 output at boot time through <filename>printk</filename> statements in the kernel's
5081 <filename>calibrate.c</filename> source code file.
5082 Applying the patch and booting the modified image causes the added
5083 messages to appear on the emulator's console.
5084 </para>
5085
5086 <para>
5087 The example assumes a clean build exists for the <filename>qemux86</filename>
5088 machine in a
5089 <link linkend='source-directory'>Source Directory</link>
5090 named <filename>poky</filename>.
5091 Furthermore, the <link linkend='build-directory'>Build Directory</link> is
5092 <filename>build</filename> and is located in <filename>poky</filename> and
5093 the kernel is based on the Linux 3.4 kernel.
5094 </para>
5095
5096 <para>
5097 Also, for more information on patching the kernel, see the
5098 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#applying-patches'>Applying Patches</ulink>"
5099 section in the Yocto Project Linux Kernel Development Manual.
5100 </para>
5101
5102 <section id='create-a-layer-for-your-changes'>
5103 <title>Create a Layer for your Changes</title>
5104
5105 <para>
5106 The first step is to create a layer so you can isolate your
5107 changes.
5108 Rather than use the <filename>yocto-layer</filename> script
5109 to create the layer, this example steps through the process
5110 by hand.
5111 If you want information on the script that creates a general
5112 layer, see the
5113 "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
5114 section.
5115 </para>
5116
5117 <para>
5118 These two commands create a directory you can use for your
5119 layer:
5120 <literallayout class='monospaced'>
5121 $ cd ~/poky
5122 $ mkdir meta-mylayer
5123 </literallayout>
5124 Creating a directory that follows the Yocto Project layer naming
5125 conventions sets up the layer for your changes.
5126 The layer is where you place your configuration files, append
5127 files, and patch files.
5128 To learn more about creating a layer and filling it with the
5129 files you need, see the "<link linkend='understanding-and-creating-layers'>Understanding
5130 and Creating Layers</link>" section.
5131 </para>
5132 </section>
5133
5134 <section id='finding-the-kernel-source-code'>
5135 <title>Finding the Kernel Source Code</title>
5136
5137 <para>
5138 Each time you build a kernel image, the kernel source code is fetched
5139 and unpacked into the following directory:
5140 <literallayout class='monospaced'>
5141 ${S}/linux
5142 </literallayout>
5143 See the "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
5144 section and the
5145 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> variable
5146 for more information about where source is kept during a build.
5147 </para>
5148
5149 <para>
5150 For this example, we are going to patch the
5151 <filename>init/calibrate.c</filename> file
5152 by adding some simple console <filename>printk</filename> statements that we can
5153 see when we boot the image using QEMU.
5154 </para>
5155 </section>
5156
5157 <section id='creating-the-patch'>
5158 <title>Creating the Patch</title>
5159
5160 <para>
5161 Two methods exist by which you can create the patch:
5162 <link linkend='using-devtool-in-your-workflow'><filename>devtool</filename></link> and
5163 <link linkend='using-a-quilt-workflow'>Quilt</link>.
5164 For kernel patches, the Git workflow is more appropriate.
5165 This section assumes the Git workflow and shows the steps specific to
5166 this example.
5167 <orderedlist>
5168 <listitem><para><emphasis>Change the working directory</emphasis>:
5169 Change to where the kernel source code is before making
5170 your edits to the <filename>calibrate.c</filename> file:
5171 <literallayout class='monospaced'>
5172 $ cd ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-${PV}-${PR}/linux
5173 </literallayout>
5174 Because you are working in an established Git repository,
5175 you must be in this directory in order to commit your changes
5176 and create the patch file.
5177 <note>The <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> and
5178 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> variables
5179 represent the version and revision for the
5180 <filename>linux-yocto</filename> recipe.
5181 The <filename>PV</filename> variable includes the Git meta and machine
5182 hashes, which make the directory name longer than you might
5183 expect.
5184 </note></para></listitem>
5185 <listitem><para><emphasis>Edit the source file</emphasis>:
5186 Edit the <filename>init/calibrate.c</filename> file to have the
5187 following changes:
5188 <literallayout class='monospaced'>
5189 void calibrate_delay(void)
5190 {
5191 unsigned long lpj;
5192 static bool printed;
5193 int this_cpu = smp_processor_id();
5194
5195 printk("*************************************\n");
5196 printk("* *\n");
5197 printk("* HELLO YOCTO KERNEL *\n");
5198 printk("* *\n");
5199 printk("*************************************\n");
5200
5201 if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
5202 .
5203 .
5204 .
5205 </literallayout></para></listitem>
5206 <listitem><para><emphasis>Stage and commit your changes</emphasis>:
5207 These Git commands display the modified file, stage it, and then
5208 commit the file:
5209 <literallayout class='monospaced'>
5210 $ git status
5211 $ git add init/calibrate.c
5212 $ git commit -m "calibrate: Add printk example"
5213 </literallayout></para></listitem>
5214 <listitem><para><emphasis>Generate the patch file</emphasis>:
5215 This Git command creates the a patch file named
5216 <filename>0001-calibrate-Add-printk-example.patch</filename>
5217 in the current directory.
5218 <literallayout class='monospaced'>
5219 $ git format-patch -1
5220 </literallayout>
5221 </para></listitem>
5222 </orderedlist>
5223 </para>
5224 </section>
5225
5226 <section id='set-up-your-layer-for-the-build'>
5227 <title>Set Up Your Layer for the Build</title>
5228
5229 <para>These steps get your layer set up for the build:
5230 <orderedlist>
5231 <listitem><para><emphasis>Create additional structure</emphasis>:
5232 Create the additional layer structure:
5233 <literallayout class='monospaced'>
5234 $ cd ~/poky/meta-mylayer
5235 $ mkdir conf
5236 $ mkdir recipes-kernel
5237 $ mkdir recipes-kernel/linux
5238 $ mkdir recipes-kernel/linux/linux-yocto
5239 </literallayout>
5240 The <filename>conf</filename> directory holds your configuration files, while the
5241 <filename>recipes-kernel</filename> directory holds your append file and
5242 your patch file.</para></listitem>
5243 <listitem><para><emphasis>Create the layer configuration file</emphasis>:
5244 Move to the <filename>meta-mylayer/conf</filename> directory and create
5245 the <filename>layer.conf</filename> file as follows:
5246 <literallayout class='monospaced'>
5247 # We have a conf and classes directory, add to BBPATH
5248 BBPATH .= ":${LAYERDIR}"
5249
5250 # We have recipes-* directories, add to BBFILES
5251 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
5252 ${LAYERDIR}/recipes-*/*/*.bbappend"
5253
5254 BBFILE_COLLECTIONS += "mylayer"
5255 BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
5256 BBFILE_PRIORITY_mylayer = "5"
5257 </literallayout>
5258 Notice <filename>mylayer</filename> as part of the last three
5259 statements.</para></listitem>
5260 <listitem><para><emphasis>Create the kernel recipe append file</emphasis>:
5261 Move to the <filename>meta-mylayer/recipes-kernel/linux</filename> directory and create
5262 the <filename>linux-yocto_3.4.bbappend</filename> file as follows:
5263 <literallayout class='monospaced'>
5264 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
5265
5266 SRC_URI += "file://0001-calibrate-Add-printk-example.patch"
5267 </literallayout>
5268 The <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
5269 and <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
5270 statements enable the OpenEmbedded build system to find the patch file.
5271 For more information on using append files, see the
5272 "<link linkend='using-bbappend-files'>Using .bbappend Files</link>"
5273 section.
5274 </para></listitem>
5275 <listitem><para><emphasis>Put the patch file in your layer</emphasis>:
5276 Move the <filename>0001-calibrate-Add-printk-example.patch</filename> file to
5277 the <filename>meta-mylayer/recipes-kernel/linux/linux-yocto</filename>
5278 directory.</para></listitem>
5279 </orderedlist>
5280 </para>
5281 </section>
5282
5283 <section id='set-up-for-the-build'>
5284 <title>Set Up for the Build</title>
5285
5286 <para>
5287 Do the following to make sure the build parameters are set up for the example.
5288 Once you set up these build parameters, they do not have to change unless you
5289 change the target architecture of the machine you are building:
5290 <itemizedlist>
5291 <listitem><para><emphasis>Build for the correct target architecture:</emphasis> Your
5292 selected <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
5293 definition within the <filename>local.conf</filename> file in the
5294 <link linkend='build-directory'>Build Directory</link>
5295 specifies the target architecture used when building the Linux kernel.
5296 By default, <filename>MACHINE</filename> is set to
5297 <filename>qemux86</filename>, which specifies a 32-bit
5298 <trademark class='registered'>Intel</trademark> Architecture
5299 target machine suitable for the QEMU emulator.</para></listitem>
5300 <listitem><para><emphasis>Identify your <filename>meta-mylayer</filename>
5301 layer:</emphasis> The
5302 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
5303 variable in the
5304 <filename>bblayers.conf</filename> file found in the
5305 <filename>poky/build/conf</filename> directory needs to have the path to your local
5306 <filename>meta-mylayer</filename> layer.
5307 By default, the <filename>BBLAYERS</filename> variable contains paths to
5308 <filename>meta</filename>, <filename>meta-yocto</filename>, and
5309 <filename>meta-yocto-bsp</filename> in the
5310 <filename>poky</filename> Git repository.
5311 Add the path to your <filename>meta-mylayer</filename> location:
5312 <literallayout class='monospaced'>
5313 BBLAYERS ?= " \
5314 $HOME/poky/meta \
5315 $HOME/poky/meta-yocto \
5316 $HOME/poky/meta-yocto-bsp \
5317 $HOME/poky/meta-mylayer \
5318 "
5319 </literallayout></para></listitem>
5320 </itemizedlist>
5321 </para>
5322 </section>
5323
5324 <section id='build-the-modified-qemu-kernel-image'>
5325 <title>Build the Modified QEMU Kernel Image</title>
5326
5327 <para>
5328 The following steps build your modified kernel image:
5329 <orderedlist>
5330 <listitem><para><emphasis>Be sure your build environment is initialized</emphasis>:
5331 Your environment should be set up since you previously sourced
5332 the
5333 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
5334 script.
5335 If it is not, source the script again from <filename>poky</filename>.
5336 <literallayout class='monospaced'>
5337 $ cd ~/poky
5338 $ source &OE_INIT_FILE;
5339 </literallayout>
5340 </para></listitem>
5341 <listitem><para><emphasis>Clean up</emphasis>:
5342 Be sure to clean the shared state out by using BitBake
5343 to run from within the Build Directory the
5344 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>
5345 task as follows:
5346 <literallayout class='monospaced'>
5347 $ bitbake -c cleansstate linux-yocto
5348 </literallayout></para>
5349 <para>
5350 <note>
5351 Never remove any files by hand from the
5352 <filename>tmp/deploy</filename>
5353 directory inside the
5354 <link linkend='build-directory'>Build Directory</link>.
5355 Always use the various BitBake clean tasks to
5356 clear out previous build artifacts.
5357 For information on the clean tasks, see the
5358 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>",
5359 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>",
5360 and
5361 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>"
5362 sections all in the Yocto Project Reference
5363 Manual.
5364 </note>
5365 </para></listitem>
5366 <listitem><para><emphasis>Build the image</emphasis>:
5367 Next, build the kernel image using this command:
5368 <literallayout class='monospaced'>
5369 $ bitbake -k linux-yocto
5370 </literallayout></para></listitem>
5371 </orderedlist>
5372 </para>
5373 </section>
5374
5375 <section id='boot-the-image-and-verify-your-changes'>
5376 <title>Boot the Image and Verify Your Changes</title>
5377
5378 <para>
5379 These steps boot the image and allow you to see the changes
5380 <orderedlist>
5381 <listitem><para><emphasis>Boot the image</emphasis>:
5382 Boot the modified image in the QEMU emulator
5383 using this command:
5384 <literallayout class='monospaced'>
5385 $ runqemu qemux86
5386 </literallayout></para></listitem>
5387 <listitem><para><emphasis>Verify the changes</emphasis>:
5388 Log into the machine using <filename>root</filename> with no password and then
5389 use the following shell command to scroll through the console's boot output.
5390 <literallayout class='monospaced'>
5391 # dmesg | less
5392 </literallayout>
5393 You should see the results of your <filename>printk</filename> statements
5394 as part of the output.</para></listitem>
5395 </orderedlist>
5396 </para>
5397 </section>
5398 </section>
5399
5400 <section id='making-images-more-secure'>
5401 <title>Making Images More Secure</title>
5402
5403 <para>
5404 Security is of increasing concern for embedded devices.
5405 Consider the issues and problems discussed in just this
5406 sampling of work found across the Internet:
5407 <itemizedlist>
5408 <listitem><para><emphasis>
5409 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
5410 by Bruce Schneier
5411 </para></listitem>
5412 <listitem><para><emphasis>
5413 "<ulink url='http://internetcensus2012.bitbucket.org/paper.html'>Internet Census 2012</ulink>"</emphasis>
5414 by Carna Botnet</para></listitem>
5415 <listitem><para><emphasis>
5416 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
5417 by Jake Edge
5418 </para></listitem>
5419 <listitem><para><emphasis>
5420 "<ulink url='https://www.nccgroup.com/media/18475/exploiting_security_gateways_via_their_web_interfaces.pdf'>They ought to know better: Exploiting Security Gateways via their Web Interfaces</ulink>"</emphasis>
5421 by Ben Williams
5422 </para></listitem>
5423 </itemizedlist>
5424 </para>
5425
5426 <para>
5427 When securing your image is of concern, there are steps, tools,
5428 and variables that you can consider to help you reach the
5429 security goals you need for your particular device.
5430 Not all situations are identical when it comes to making an
5431 image secure.
5432 Consequently, this section provides some guidance and suggestions
5433 for consideration when you want to make your image more secure.
5434 <note>
5435 Because the security requirements and risks are
5436 different for every type of device, this section cannot
5437 provide a complete reference on securing your custom OS.
5438 It is strongly recommended that you also consult other sources
5439 of information on embedded Linux system hardening and on
5440 security.
5441 </note>
5442 </para>
5443
5444 <section id='general-considerations'>
5445 <title>General Considerations</title>
5446
5447 <para>
5448 General considerations exist that help you create more
5449 secure images.
5450 You should consider the following suggestions to help
5451 make your device more secure:
5452 <itemizedlist>
5453 <listitem><para>
5454 Scan additional code you are adding to the system
5455 (e.g. application code) by using static analysis
5456 tools.
5457 Look for buffer overflows and other potential
5458 security problems.
5459 </para></listitem>
5460 <listitem><para>
5461 Pay particular attention to the security for
5462 any web-based administration interface.
5463 </para>
5464 <para>Web interfaces typically need to perform
5465 administrative functions and tend to need to run with
5466 elevated privileges.
5467 Thus, the consequences resulting from the interface's
5468 security becoming compromised can be serious.
5469 Look for common web vulnerabilities such as
5470 cross-site-scripting (XSS), unvalidated inputs,
5471 and so forth.</para>
5472 <para>As with system passwords, the default credentials
5473 for accessing a web-based interface should not be the
5474 same across all devices.
5475 This is particularly true if the interface is enabled
5476 by default as it can be assumed that many end-users
5477 will not change the credentials.
5478 </para></listitem>
5479 <listitem><para>
5480 Ensure you can update the software on the device to
5481 mitigate vulnerabilities discovered in the future.
5482 This consideration especially applies when your
5483 device is network-enabled.
5484 </para></listitem>
5485 <listitem><para>
5486 Ensure you remove or disable debugging functionality
5487 before producing the final image.
5488 For information on how to do this, see the
5489 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
5490 section.
5491 </para></listitem>
5492 <listitem><para>
5493 Ensure you have no network services listening that
5494 are not needed.
5495 </para></listitem>
5496 <listitem><para>
5497 Remove any software from the image that is not needed.
5498 </para></listitem>
5499 <listitem><para>
5500 Enable hardware support for secure boot functionality
5501 when your device supports this functionality.
5502 </para></listitem>
5503 </itemizedlist>
5504 </para>
5505 </section>
5506
5507 <section id='security-flags'>
5508 <title>Security Flags</title>
5509
5510 <para>
5511 The Yocto Project has security flags that you can enable that
5512 help make your build output more secure.
5513 The security flags are in the
5514 <filename>meta/conf/distro/include/security_flags.inc</filename>
5515 file in your
5516 <link linkend='source-directory'>Source Directory</link>
5517 (e.g. <filename>poky</filename>).
5518 <note>
5519 Depending on the recipe, certain security flags are enabled
5520 and disabled by default.
5521 </note>
5522 </para>
5523
5524 <para>
5525<!--
5526 The GCC/LD flags in <filename>security_flags.inc</filename>
5527 enable more secure code generation.
5528 By including the <filename>security_flags.inc</filename>
5529 file, you enable flags to the compiler and linker that cause
5530 them to generate more secure code.
5531 <note>
5532 The GCC/LD flags are enabled by default in the
5533 <filename>poky-lsb</filename> distribution.
5534 </note>
5535-->
5536 Use the following line in your
5537 <filename>local.conf</filename> file or in your custom
5538 distribution configuration file to enable the security
5539 compiler and linker flags for your build:
5540 <literallayout class='monospaced'>
5541 require conf/distro/include/security_flags.inc
5542 </literallayout>
5543 </para>
5544 </section>
5545
5546 <section id='considerations-specific-to-the-openembedded-build-system'>
5547 <title>Considerations Specific to the OpenEmbedded Build System</title>
5548
5549 <para>
5550 You can take some steps that are specific to the
5551 OpenEmbedded build system to make your images more secure:
5552 <itemizedlist>
5553 <listitem><para>
5554 Ensure "debug-tweaks" is not one of your selected
5555 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
5556 When creating a new project, the default is to provide you
5557 with an initial <filename>local.conf</filename> file that
5558 enables this feature using the
5559 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
5560 <literallayout class='monospaced'>
5561 EXTRA_IMAGE_FEATURES = "debug-tweaks"
5562 </literallayout>
5563 To disable that feature, simply comment out that line in your
5564 <filename>local.conf</filename> file, or
5565 make sure <filename>IMAGE_FEATURES</filename> does not contain
5566 "debug-tweaks" before producing your final image.
5567 Among other things, leaving this in place sets the
5568 root password as blank, which makes logging in for
5569 debugging or inspection easy during
5570 development but also means anyone can easily log in
5571 during production.
5572 </para></listitem>
5573 <listitem><para>
5574 It is possible to set a root password for the image
5575 and also to set passwords for any extra users you might
5576 add (e.g. administrative or service type users).
5577 When you set up passwords for multiple images or
5578 users, you should not duplicate passwords.
5579 </para>
5580 <para>
5581 To set up passwords, use the
5582 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
5583 class, which is the preferred method.
5584 For an example on how to set up both root and user
5585 passwords, see the
5586 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
5587 section.
5588 <note>
5589 When adding extra user accounts or setting a
5590 root password, be cautious about setting the
5591 same password on every device.
5592 If you do this, and the password you have set
5593 is exposed, then every device is now potentially
5594 compromised.
5595 If you need this access but want to ensure
5596 security, consider setting a different,
5597 random password for each device.
5598 Typically, you do this as a separate step after
5599 you deploy the image onto the device.
5600 </note>
5601 </para></listitem>
5602 <listitem><para>
5603 Consider enabling a Mandatory Access Control (MAC)
5604 framework such as SMACK or SELinux and tuning it
5605 appropriately for your device's usage.
5606 You can find more information in the
5607 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
5608 layer.
5609 </para></listitem>
5610 </itemizedlist>
5611 </para>
5612
5613 <para>
5614 </para>
5615 </section>
5616
5617 <section id='tools-for-hardening-your-image'>
5618 <title>Tools for Hardening Your Image</title>
5619
5620 <para>
5621 The Yocto Project provides tools for making your image
5622 more secure.
5623 You can find these tools in the
5624 <filename>meta-security</filename> layer of the
5625 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi'>Yocto Project Source Repositories</ulink>.
5626 </para>
5627 </section>
5628 </section>
5629
5630 <section id='creating-your-own-distribution'>
5631 <title>Creating Your Own Distribution</title>
5632
5633 <para>
5634 When you build an image using the Yocto Project and
5635 do not alter any distribution
5636 <link linkend='metadata'>Metadata</link>, you are creating a
5637 Poky distribution.
5638 If you wish to gain more control over package alternative
5639 selections, compile-time options, and other low-level
5640 configurations, you can create your own distribution.
5641 </para>
5642
5643 <para>
5644 To create your own distribution, the basic steps consist of
5645 creating your own distribution layer, creating your own
5646 distribution configuration file, and then adding any needed
5647 code and Metadata to the layer.
5648 The following steps provide some more detail:
5649 <itemizedlist>
5650 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
5651 Create your distribution layer so that you can keep your
5652 Metadata and code for the distribution separate.
5653 It is strongly recommended that you create and use your own
5654 layer for configuration and code.
5655 Using your own layer as compared to just placing
5656 configurations in a <filename>local.conf</filename>
5657 configuration file makes it easier to reproduce the same
5658 build configuration when using multiple build machines.
5659 See the
5660 "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>"
5661 section for information on how to quickly set up a layer.
5662 </para></listitem>
5663 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
5664 The distribution configuration file needs to be created in
5665 the <filename>conf/distro</filename> directory of your
5666 layer.
5667 You need to name it using your distribution name
5668 (e.g. <filename>mydistro.conf</filename>).
5669 <note>
5670 The
5671 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5672 variable in your
5673 <filename>local.conf</filename> file determines the
5674 name of your distribution.
5675 </note></para>
5676 <para>You can split out parts of your configuration file
5677 into include files and then "require" them from within
5678 your distribution configuration file.
5679 Be sure to place the include files in the
5680 <filename>conf/distro/include</filename> directory of
5681 your layer.
5682 A common example usage of include files would be to
5683 separate out the selection of desired version and revisions
5684 for individual recipes.
5685</para>
5686 <para>Your configuration file needs to set the following
5687 required variables:
5688 <literallayout class='monospaced'>
5689 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
5690 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
5691 </literallayout>
5692 These following variables are optional and you typically
5693 set them from the distribution configuration file:
5694 <literallayout class='monospaced'>
5695 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
5696 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
5697 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
5698 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
5699 </literallayout>
5700 <tip>
5701 If you want to base your distribution configuration file
5702 on the very basic configuration from OE-Core, you
5703 can use
5704 <filename>conf/distro/defaultsetup.conf</filename> as
5705 a reference and just include variables that differ
5706 as compared to <filename>defaultsetup.conf</filename>.
5707 Alternatively, you can create a distribution
5708 configuration file from scratch using the
5709 <filename>defaultsetup.conf</filename> file
5710 or configuration files from other distributions
5711 such as Poky or Angstrom as references.
5712 </tip></para></listitem>
5713 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
5714 Be sure to define any other variables for which you want to
5715 create a default or enforce as part of the distribution
5716 configuration.
5717 You can include nearly any variable from the
5718 <filename>local.conf</filename> file.
5719 The variables you use are not limited to the list in the
5720 previous bulleted item.</para></listitem>
5721 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
5722 In your <filename>local.conf</filename> file in the
5723 <link linkend='build-directory'>Build Directory</link>,
5724 set your
5725 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5726 variable to point to your distribution's configuration file.
5727 For example, if your distribution's configuration file is
5728 named <filename>mydistro.conf</filename>, then you point
5729 to it as follows:
5730 <literallayout class='monospaced'>
5731 DISTRO = "mydistro"
5732 </literallayout></para></listitem>
5733 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
5734 Use your layer to hold other information needed for the
5735 distribution:
5736 <itemizedlist>
5737 <listitem><para>Add recipes for installing
5738 distro-specific configuration files that are not
5739 already installed by another recipe.
5740 If you have distro-specific configuration files
5741 that are included by an existing recipe, you should
5742 add an append file (<filename>.bbappend</filename>)
5743 for those.
5744 For general information and recommendations
5745 on how to add recipes to your layer, see the
5746 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
5747 and
5748 "<link linkend='best-practices-to-follow-when-creating-layers'>Best Practices to Follow When Creating Layers</link>"
5749 sections.</para></listitem>
5750 <listitem><para>Add any image recipes that are specific
5751 to your distribution.</para></listitem>
5752 <listitem><para>Add a <filename>psplash</filename>
5753 append file for a branded splash screen.
5754 For information on append files, see the
5755 "<link linkend='using-bbappend-files'>Using .bbappend Files</link>"
5756 section.</para></listitem>
5757 <listitem><para>Add any other append files to make
5758 custom changes that are specific to individual
5759 recipes.</para></listitem>
5760 </itemizedlist></para></listitem>
5761 </itemizedlist>
5762 </para>
5763 </section>
5764
5765 <section id='creating-a-custom-template-configuration-directory'>
5766 <title>Creating a Custom Template Configuration Directory</title>
5767
5768 <para>
5769 If you are producing your own customized version
5770 of the build system for use by other users, you might
5771 want to customize the message shown by the setup script or
5772 you might want to change the template configuration files (i.e.
5773 <filename>local.conf</filename> and
5774 <filename>bblayers.conf</filename>) that are created in
5775 a new build directory.
5776 </para>
5777
5778 <para>
5779 The OpenEmbedded build system uses the environment variable
5780 <filename>TEMPLATECONF</filename> to locate the directory
5781 from which it gathers configuration information that ultimately
5782 ends up in the
5783 <link linkend='build-directory'>Build Directory's</link>
5784 <filename>conf</filename> directory.
5785 By default, <filename>TEMPLATECONF</filename> is set as
5786 follows in the <filename>poky</filename> repository:
5787 <literallayout class='monospaced'>
5788 TEMPLATECONF=${TEMPLATECONF:-meta-yocto/conf}
5789 </literallayout>
5790 This is the directory used by the build system to find templates
5791 from which to build some key configuration files.
5792 If you look at this directory, you will see the
5793 <filename>bblayers.conf.sample</filename>,
5794 <filename>local.conf.sample</filename>, and
5795 <filename>conf-notes.txt</filename> files.
5796 The build system uses these files to form the respective
5797 <filename>bblayers.conf</filename> file,
5798 <filename>local.conf</filename> file, and display the list of
5799 BitBake targets when running the setup script.
5800 </para>
5801
5802 <para>
5803 To override these default configuration files with
5804 configurations you want used within every new
5805 Build Directory, simply set the
5806 <filename>TEMPLATECONF</filename> variable to your directory.
5807 The <filename>TEMPLATECONF</filename> variable is set in the
5808 <filename>.templateconf</filename> file, which is in the
5809 top-level
5810 <link linkend='source-directory'>Source Directory</link>
5811 folder (e.g. <filename>poky</filename>).
5812 Edit the <filename>.templateconf</filename> so that it can locate
5813 your directory.
5814 </para>
5815
5816 <para>
5817 Best practices dictate that you should keep your
5818 template configuration directory in your custom distribution layer.
5819 For example, suppose you have a layer named
5820 <filename>meta-mylayer</filename> located in your home directory
5821 and you want your template configuration directory named
5822 <filename>myconf</filename>.
5823 Changing the <filename>.templateconf</filename> as follows
5824 causes the OpenEmbedded build system to look in your directory
5825 and base its configuration files on the
5826 <filename>*.sample</filename> configuration files it finds.
5827 The final configuration files (i.e.
5828 <filename>local.conf</filename> and
5829 <filename>bblayers.conf</filename> ultimately still end up in
5830 your Build Directory, but they are based on your
5831 <filename>*.sample</filename> files.
5832 <literallayout class='monospaced'>
5833 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
5834 </literallayout>
5835 </para>
5836
5837 <para>
5838 Aside from the <filename>*.sample</filename> configuration files,
5839 the <filename>conf-notes.txt</filename> also resides in the
5840 default <filename>meta-yocto/conf</filename> directory.
5841 The scripts that set up the build environment
5842 (i.e.
5843 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>
5844 and
5845 <ulink url="&YOCTO_DOCS_REF_URL;#structure-memres-core-script"><filename>oe-init-build-env-memres</filename></ulink>)
5846 use this file to display BitBake targets as part of the script
5847 output.
5848 Customizing this <filename>conf-notes.txt</filename> file is a
5849 good way to make sure your list of custom targets appears
5850 as part of the script's output.
5851 </para>
5852
5853 <para>
5854 Here is the default list of targets displayed as a result of
5855 running either of the setup scripts:
5856 <literallayout class='monospaced'>
5857 You can now run 'bitbake &lt;target&gt;'
5858
5859 Common targets are:
5860 core-image-minimal
5861 core-image-sato
5862 meta-toolchain
5863 adt-installer
5864 meta-ide-support
5865 </literallayout>
5866 </para>
5867
5868 <para>
5869 Changing the listed common targets is as easy as editing your
5870 version of <filename>conf-notes.txt</filename> in your
5871 custom template configuration directory and making sure you
5872 have <filename>TEMPLATECONF</filename> set to your directory.
5873 </para>
5874 </section>
5875
5876 <section id='building-a-tiny-system'>
5877 <title>Building a Tiny System</title>
5878
5879 <para>
5880 Very small distributions have some significant advantages such
5881 as requiring less on-die or in-package memory (cheaper), better
5882 performance through efficient cache usage, lower power requirements
5883 due to less memory, faster boot times, and reduced development
5884 overhead.
5885 Some real-world examples where a very small distribution gives
5886 you distinct advantages are digital cameras, medical devices,
5887 and small headless systems.
5888 </para>
5889
5890 <para>
5891 This section presents information that shows you how you can
5892 trim your distribution to even smaller sizes than the
5893 <filename>poky-tiny</filename> distribution, which is around
5894 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5895 </para>
5896
5897 <section id='tiny-system-overview'>
5898 <title>Overview</title>
5899
5900 <para>
5901 The following list presents the overall steps you need to
5902 consider and perform to create distributions with smaller
5903 root filesystems, achieve faster boot times, maintain your critical
5904 functionality, and avoid initial RAM disks:
5905 <itemizedlist>
5906 <listitem><para>
5907 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5908 </para></listitem>
5909 <listitem><para>
5910 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5911 </para></listitem>
5912 <listitem><para>
5913 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5914 </para></listitem>
5915 <listitem><para>
5916 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5917 </para></listitem>
5918 <listitem><para>
5919 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5920 </para></listitem>
5921 <listitem><para>
5922 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5923 </para></listitem>
5924 <listitem><para>
5925 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5926 </para></listitem>
5927 </itemizedlist>
5928 </para>
5929 </section>
5930
5931 <section id='goals-and-guiding-principles'>
5932 <title>Goals and Guiding Principles</title>
5933
5934 <para>
5935 Before you can reach your destination, you need to know
5936 where you are going.
5937 Here is an example list that you can use as a guide when
5938 creating very small distributions:
5939 <itemizedlist>
5940 <listitem><para>Determine how much space you need
5941 (e.g. a kernel that is 1 Mbyte or less and
5942 a root filesystem that is 3 Mbytes or less).
5943 </para></listitem>
5944 <listitem><para>Find the areas that are currently
5945 taking 90% of the space and concentrate on reducing
5946 those areas.
5947 </para></listitem>
5948 <listitem><para>Do not create any difficult "hacks"
5949 to achieve your goals.</para></listitem>
5950 <listitem><para>Leverage the device-specific
5951 options.</para></listitem>
5952 <listitem><para>Work in a separate layer so that you
5953 keep changes isolated.
5954 For information on how to create layers, see
5955 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5956 </para></listitem>
5957 </itemizedlist>
5958 </para>
5959 </section>
5960
5961 <section id='understand-what-gives-your-image-size'>
5962 <title>Understand What Contributes to Your Image Size</title>
5963
5964 <para>
5965 It is easiest to have something to start with when creating
5966 your own distribution.
5967 You can use the Yocto Project out-of-the-box to create the
5968 <filename>poky-tiny</filename> distribution.
5969 Ultimately, you will want to make changes in your own
5970 distribution that are likely modeled after
5971 <filename>poky-tiny</filename>.
5972 <note>
5973 To use <filename>poky-tiny</filename> in your build,
5974 set the
5975 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5976 variable in your
5977 <filename>local.conf</filename> file to "poky-tiny"
5978 as described in the
5979 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5980 section.
5981 </note>
5982 </para>
5983
5984 <para>
5985 Understanding some memory concepts will help you reduce the
5986 system size.
5987 Memory consists of static, dynamic, and temporary memory.
5988 Static memory is the TEXT (code), DATA (initialized data
5989 in the code), and BSS (uninitialized data) sections.
5990 Dynamic memory represents memory that is allocated at runtime:
5991 stacks, hash tables, and so forth.
5992 Temporary memory is recovered after the boot process.
5993 This memory consists of memory used for decompressing
5994 the kernel and for the <filename>__init__</filename>
5995 functions.
5996 </para>
5997
5998 <para>
5999 To help you see where you currently are with kernel and root
6000 filesystem sizes, you can use two tools found in the
6001 <link linkend='source-directory'>Source Directory</link> in
6002 the <filename>scripts/tiny/</filename> directory:
6003 <itemizedlist>
6004 <listitem><para><filename>ksize.py</filename>: Reports
6005 component sizes for the kernel build objects.
6006 </para></listitem>
6007 <listitem><para><filename>dirsize.py</filename>: Reports
6008 component sizes for the root filesystem.</para></listitem>
6009 </itemizedlist>
6010 This next tool and command help you organize configuration
6011 fragments and view file dependencies in a human-readable form:
6012 <itemizedlist>
6013 <listitem><para><filename>merge_config.sh</filename>:
6014 Helps you manage configuration files and fragments
6015 within the kernel.
6016 With this tool, you can merge individual configuration
6017 fragments together.
6018 The tool allows you to make overrides and warns you
6019 of any missing configuration options.
6020 The tool is ideal for allowing you to iterate on
6021 configurations, create minimal configurations, and
6022 create configuration files for different machines
6023 without having to duplicate your process.</para>
6024 <para>The <filename>merge_config.sh</filename> script is
6025 part of the Linux Yocto kernel Git repositories
6026 (i.e. <filename>linux-yocto-3.14</filename>,
6027 <filename>linux-yocto-3.10</filename>,
6028 <filename>linux-yocto-3.8</filename>, and so forth)
6029 in the
6030 <filename>scripts/kconfig</filename> directory.</para>
6031 <para>For more information on configuration fragments,
6032 see the
6033 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>"
6034 section of the Yocto Project Linux Kernel Development
6035 Manual and the "<link linkend='creating-config-fragments'>Creating Configuration Fragments</link>"
6036 section, which is in this manual.</para></listitem>
6037 <listitem><para><filename>bitbake -u depexp -g <replaceable>bitbake_target</replaceable></filename>:
6038 Using the BitBake command with these options brings up
6039 a Dependency Explorer from which you can view file
6040 dependencies.
6041 Understanding these dependencies allows you to make
6042 informed decisions when cutting out various pieces of the
6043 kernel and root filesystem.</para></listitem>
6044 </itemizedlist>
6045 </para>
6046 </section>
6047
6048 <section id='trim-the-root-filesystem'>
6049 <title>Trim the Root Filesystem</title>
6050
6051 <para>
6052 The root filesystem is made up of packages for booting,
6053 libraries, and applications.
6054 To change things, you can configure how the packaging happens,
6055 which changes the way you build them.
6056 You can also modify the filesystem itself or select a different
6057 filesystem.
6058 </para>
6059
6060 <para>
6061 First, find out what is hogging your root filesystem by running the
6062 <filename>dirsize.py</filename> script from your root directory:
6063 <literallayout class='monospaced'>
6064 $ cd <replaceable>root-directory-of-image</replaceable>
6065 $ dirsize.py 100000 > dirsize-100k.log
6066 $ cat dirsize-100k.log
6067 </literallayout>
6068 You can apply a filter to the script to ignore files under
6069 a certain size.
6070 The previous example filters out any files below 100 Kbytes.
6071 The sizes reported by the tool are uncompressed, and thus
6072 will be smaller by a relatively constant factor in a
6073 compressed root filesystem.
6074 When you examine your log file, you can focus on areas of the
6075 root filesystem that take up large amounts of memory.
6076 </para>
6077
6078 <para>
6079 You need to be sure that what you eliminate does not cripple
6080 the functionality you need.
6081 One way to see how packages relate to each other is by using
6082 the Dependency Explorer UI with the BitBake command:
6083 <literallayout class='monospaced'>
6084 $ cd <replaceable>image-directory</replaceable>
6085 $ bitbake -u depexp -g <replaceable>image</replaceable>
6086 </literallayout>
6087 Use the interface to select potential packages you wish to
6088 eliminate and see their dependency relationships.
6089 </para>
6090
6091 <para>
6092 When deciding how to reduce the size, get rid of packages that
6093 result in minimal impact on the feature set.
6094 For example, you might not need a VGA display.
6095 Or, you might be able to get by with <filename>devtmpfs</filename>
6096 and <filename>mdev</filename> instead of
6097 <filename>udev</filename>.
6098 </para>
6099
6100 <para>
6101 Use your <filename>local.conf</filename> file to make changes.
6102 For example, to eliminate <filename>udev</filename> and
6103 <filename>glib</filename>, set the following in the
6104 local configuration file:
6105 <literallayout class='monospaced'>
6106 VIRTUAL-RUNTIME_dev_manager = ""
6107 </literallayout>
6108 </para>
6109
6110 <para>
6111 Finally, you should consider exactly the type of root
6112 filesystem you need to meet your needs while also reducing
6113 its size.
6114 For example, consider <filename>cramfs</filename>,
6115 <filename>squashfs</filename>, <filename>ubifs</filename>,
6116 <filename>ext2</filename>, or an <filename>initramfs</filename>
6117 using <filename>initramfs</filename>.
6118 Be aware that <filename>ext3</filename> requires a 1 Mbyte
6119 journal.
6120 If you are okay with running read-only, you do not need this
6121 journal.
6122 </para>
6123
6124 <note>
6125 After each round of elimination, you need to rebuild your
6126 system and then use the tools to see the effects of your
6127 reductions.
6128 </note>
6129
6130
6131 </section>
6132
6133 <section id='trim-the-kernel'>
6134 <title>Trim the Kernel</title>
6135
6136 <para>
6137 The kernel is built by including policies for hardware-independent
6138 aspects.
6139 What subsystems do you enable?
6140 For what architecture are you building?
6141 Which drivers do you build by default?
6142 <note>You can modify the kernel source if you want to help
6143 with boot time.
6144 </note>
6145 </para>
6146
6147 <para>
6148 Run the <filename>ksize.py</filename> script from the top-level
6149 Linux build directory to get an idea of what is making up
6150 the kernel:
6151 <literallayout class='monospaced'>
6152 $ cd <replaceable>top-level-linux-build-directory</replaceable>
6153 $ ksize.py > ksize.log
6154 $ cat ksize.log
6155 </literallayout>
6156 When you examine the log, you will see how much space is
6157 taken up with the built-in <filename>.o</filename> files for
6158 drivers, networking, core kernel files, filesystem, sound,
6159 and so forth.
6160 The sizes reported by the tool are uncompressed, and thus
6161 will be smaller by a relatively constant factor in a compressed
6162 kernel image.
6163 Look to reduce the areas that are large and taking up around
6164 the "90% rule."
6165 </para>
6166
6167 <para>
6168 To examine, or drill down, into any particular area, use the
6169 <filename>-d</filename> option with the script:
6170 <literallayout class='monospaced'>
6171 $ ksize.py -d > ksize.log
6172 </literallayout>
6173 Using this option breaks out the individual file information
6174 for each area of the kernel (e.g. drivers, networking, and
6175 so forth).
6176 </para>
6177
6178 <para>
6179 Use your log file to see what you can eliminate from the kernel
6180 based on features you can let go.
6181 For example, if you are not going to need sound, you do not
6182 need any drivers that support sound.
6183 </para>
6184
6185 <para>
6186 After figuring out what to eliminate, you need to reconfigure
6187 the kernel to reflect those changes during the next build.
6188 You could run <filename>menuconfig</filename> and make all your
6189 changes at once.
6190 However, that makes it difficult to see the effects of your
6191 individual eliminations and also makes it difficult to replicate
6192 the changes for perhaps another target device.
6193 A better method is to start with no configurations using
6194 <filename>allnoconfig</filename>, create configuration
6195 fragments for individual changes, and then manage the
6196 fragments into a single configuration file using
6197 <filename>merge_config.sh</filename>.
6198 The tool makes it easy for you to iterate using the
6199 configuration change and build cycle.
6200 </para>
6201
6202 <para>
6203 Each time you make configuration changes, you need to rebuild
6204 the kernel and check to see what impact your changes had on
6205 the overall size.
6206 </para>
6207 </section>
6208
6209 <section id='remove-package-management-requirements'>
6210 <title>Remove Package Management Requirements</title>
6211
6212 <para>
6213 Packaging requirements add size to the image.
6214 One way to reduce the size of the image is to remove all the
6215 packaging requirements from the image.
6216 This reduction includes both removing the package manager
6217 and its unique dependencies as well as removing the package
6218 management data itself.
6219 </para>
6220
6221 <para>
6222 To eliminate all the packaging requirements for an image,
6223 be sure that "package-management" is not part of your
6224 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
6225 statement for the image.
6226 When you remove this feature, you are removing the package
6227 manager as well as its dependencies from the root filesystem.
6228 </para>
6229 </section>
6230
6231 <section id='look-for-other-ways-to-minimize-size'>
6232 <title>Look for Other Ways to Minimize Size</title>
6233
6234 <para>
6235 Depending on your particular circumstances, other areas that you
6236 can trim likely exist.
6237 The key to finding these areas is through tools and methods
6238 described here combined with experimentation and iteration.
6239 Here are a couple of areas to experiment with:
6240 <itemizedlist>
6241 <listitem><para><filename>glibc</filename>:
6242 In general, follow this process:
6243 <orderedlist>
6244 <listitem><para>Remove <filename>glibc</filename>
6245 features from
6246 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6247 that you think you do not need.</para></listitem>
6248 <listitem><para>Build your distribution.
6249 </para></listitem>
6250 <listitem><para>If the build fails due to missing
6251 symbols in a package, determine if you can
6252 reconfigure the package to not need those
6253 features.
6254 For example, change the configuration to not
6255 support wide character support as is done for
6256 <filename>ncurses</filename>.
6257 Or, if support for those characters is needed,
6258 determine what <filename>glibc</filename>
6259 features provide the support and restore the
6260 configuration.
6261 </para></listitem>
6262 <listitem><para>Rebuild and repeat the process.
6263 </para></listitem>
6264 </orderedlist></para></listitem>
6265 <listitem><para><filename>busybox</filename>:
6266 For BusyBox, use a process similar as described for
6267 <filename>glibc</filename>.
6268 A difference is you will need to boot the resulting
6269 system to see if you are able to do everything you
6270 expect from the running system.
6271 You need to be sure to integrate configuration fragments
6272 into Busybox because BusyBox handles its own core
6273 features and then allows you to add configuration
6274 fragments on top.
6275 </para></listitem>
6276 </itemizedlist>
6277 </para>
6278 </section>
6279
6280 <section id='iterate-on-the-process'>
6281 <title>Iterate on the Process</title>
6282
6283 <para>
6284 If you have not reached your goals on system size, you need
6285 to iterate on the process.
6286 The process is the same.
6287 Use the tools and see just what is taking up 90% of the root
6288 filesystem and the kernel.
6289 Decide what you can eliminate without limiting your device
6290 beyond what you need.
6291 </para>
6292
6293 <para>
6294 Depending on your system, a good place to look might be
6295 Busybox, which provides a stripped down
6296 version of Unix tools in a single, executable file.
6297 You might be able to drop virtual terminal services or perhaps
6298 ipv6.
6299 </para>
6300 </section>
6301 </section>
6302
6303 <section id='building-images-for-more-than-one-machine'>
6304 <title>Building Images for More than One Machine</title>
6305
6306 <para>
6307 A common scenario developers face is creating images for several
6308 different machines that use the same software environment.
6309 In this situation, it is tempting to set the
6310 tunings and optimization flags for each build specifically for
6311 the targeted hardware (i.e. "maxing out" the tunings).
6312 Doing so can considerably add to build times and package feed
6313 maintenance collectively for the machines.
6314 For example, selecting tunes that are extremely specific to a
6315 CPU core used in a system might enable some micro optimizations
6316 in GCC for that particular system but would otherwise not gain
6317 you much of a performance difference across the other systems
6318 as compared to using a more general tuning across all the builds
6319 (e.g. setting
6320 <ulink url='var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6321 specifically for each machine's build).
6322 Rather than "max out" each build's tunings, you can take steps that
6323 cause the OpenEmbedded build system to reuse software across the
6324 various machines where it makes sense.
6325 </para>
6326 <para>
6327 If build speed and package feed maintenance are considerations,
6328 you should consider the points in this section that can help you
6329 optimize your tunings to best consider build times and package
6330 feed maintenance.
6331 <itemizedlist>
6332 <listitem><para><emphasis>Share the Build Directory:</emphasis>
6333 If at all possible, share the
6334 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6335 across builds.
6336 The Yocto Project supports switching between different
6337 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6338 values in the same <filename>TMPDIR</filename>.
6339 This practice is well supported and regularly used by
6340 developers when building for multiple machines.
6341 When you use the same <filename>TMPDIR</filename> for
6342 multiple machine builds, the OpenEmbedded build system can
6343 reuse the existing native and often cross-recipes for
6344 multiple machines.
6345 Thus, build time decreases.
6346 <note>
6347 If
6348 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6349 settings change or fundamental configuration settings
6350 such as the filesystem layout, you need to work with
6351 a clean <filename>TMPDIR</filename>.
6352 Sharing <filename>TMPDIR</filename> under these
6353 circumstances might work but since it is not
6354 guaranteed, you should use a clean
6355 <filename>TMPDIR</filename>.
6356 </note>
6357 </para></listitem>
6358 <listitem><para><emphasis>Enable the Appropriate Package Architecture:</emphasis>
6359 By default, the OpenEmbedded build system enables three
6360 levels of package architectures: "all", "tune" or "package",
6361 and "machine".
6362 Any given recipe usually selects one of these package
6363 architectures (types) for its output.
6364 Depending for what a given recipe creates packages, making
6365 sure you enable the appropriate package architecture can
6366 directly impact the build time.</para>
6367 <para>A recipe that just generates scripts can enable
6368 "all" architecture because there are no binaries to build.
6369 To specifically enable "all" architecture, be sure your
6370 recipe inherits the
6371 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6372 class.
6373 This class is useful for "all" architectures because it
6374 configures many variables so packages can be used across
6375 multiple architectures.</para>
6376 <para>If your recipe needs to generate packages that are
6377 machine-specific or when one of the build or runtime
6378 dependencies is already machine-architecture dependent,
6379 which makes your recipe also machine-architecture dependent,
6380 make sure your recipe enables the "machine" package
6381 architecture through the
6382 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6383 variable:
6384 <literallayout class='monospaced'>
6385 PACKAGE_ARCH = "${MACHINE_ARCH}"
6386 </literallayout>
6387 When you do not specifically enable a package
6388 architecture through the
6389 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6390 The OpenEmbedded build system defaults to the
6391 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6392 setting:
6393 <literallayout class='monospaced'>
6394 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6395 </literallayout>
6396 </para></listitem>
6397 <listitem><para><emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6398 Some tunes are more generic and can run on multiple targets
6399 (e.g. an <filename>armv5</filename> set of packages could
6400 run on <filename>armv6</filename> and
6401 <filename>armv7</filename> processors in most cases).
6402 Similarly, <filename>i486</filename> binaries could work
6403 on <filename>i586</filename> and higher processors.
6404 You should realize, however, that advances on newer
6405 processor versions would not be used.</para>
6406 <para>If you select the same tune for several different
6407 machines, the OpenEmbedded build system reuses software
6408 previously built, thus speeding up the overall build time.
6409 Realize that even though a new sysroot for each machine is
6410 generated, the software is not recompiled and only one
6411 package feed exists.
6412 </para></listitem>
6413 <listitem><para><emphasis>Manage Granular Level Packaging:</emphasis>
6414 Sometimes cases exist where injecting another level
6415 of package architecture beyond the three higher levels
6416 noted earlier can be useful.
6417 For example, consider the <filename>emgd</filename>
6418 graphics stack in the
6419 <filename>meta-intel</filename> layer.
6420 In this layer, a subset of software exists that is
6421 compiled against something different from the rest of the
6422 generic packages.
6423 You can examine the key code in the
6424 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi'>Source Repositories</ulink>
6425 "daisy" branch in
6426 <filename>classes/emgd-gl.bbclass</filename>.
6427 For a specific set of packages, the code redefines
6428 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>.
6429 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXTRA_ARCHS'><filename>PACKAGE_EXTRA_ARCHS</filename></ulink>
6430 is then appended with this extra tune name in
6431 <filename>meta-intel-emgd.inc</filename>.
6432 The result is that when searching for packages, the
6433 build system uses a four-level search and the packages
6434 in this new level are preferred as compared to the standard
6435 tune.
6436 The overall result is that the build system reuses most
6437 software from the common tune except for specific cases
6438 as needed.
6439 </para></listitem>
6440 <listitem><para><emphasis>Use Tools to Debug Issues:</emphasis>
6441 Sometimes you can run into situations where software is
6442 being rebuilt when you think it should not be.
6443 For example, the OpenEmbedded build system might not be
6444 using shared state between machines when you think it
6445 should be.
6446 These types of situations are usually due to references
6447 to machine-specific variables such as
6448 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6449 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLE'><filename>SERIAL_CONSOLE</filename></ulink>,
6450 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6451 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6452 and so forth in code that is supposed to only be
6453 tune-specific or when the recipe depends
6454 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6455 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6456 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6457 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6458 and so forth) on some other recipe that already has
6459 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6460 defined as "${MACHINE_ARCH}".
6461 <note>
6462 Patches to fix any issues identified are most welcome
6463 as these issues occasionally do occur.
6464 </note></para>
6465 <para>For such cases, you can use some tools to help you
6466 sort out the situation:
6467 <itemizedlist>
6468 <listitem><para><emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6469 You can find this tool in the
6470 <filename>scripts</filename> directory of the
6471 Source Repositories.
6472 See the comments in the script for information on
6473 how to use the tool.
6474 </para></listitem>
6475 <listitem><para><emphasis>BitBake's "-S printdiff" Option:</emphasis>
6476 Using this option causes BitBake to try to
6477 establish the closest signature match it can
6478 (e.g. in the shared state cache) and then run
6479 <filename>bitbake-diffsigs</filename> over the
6480 matches to determine the stamps and delta where
6481 these two stamp trees diverge.
6482 </para></listitem>
6483 </itemizedlist>
6484 </para></listitem>
6485 </itemizedlist>
6486 </para>
6487 </section>
6488
6489 <section id='working-with-packages'>
6490 <title>Working with Packages</title>
6491
6492 <para>
6493 This section describes a few tasks that involve packages:
6494 <itemizedlist>
6495 <listitem><para>
6496 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
6497 </para></listitem>
6498 <listitem><para>
6499 <link linkend='incrementing-a-package-revision-number'>Incrementing a package revision number</link>
6500 </para></listitem>
6501 <listitem><para>
6502 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
6503 </para></listitem>
6504 <listitem><para>
6505 <link linkend='using-runtime-package-management'>Using Runtime Package Management</link>
6506 </para></listitem>
6507 <listitem><para>
6508 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
6509 </para></listitem>
6510 </itemizedlist>
6511 </para>
6512
6513 <section id='excluding-packages-from-an-image'>
6514 <title>Excluding Packages from an Image</title>
6515
6516 <para>
6517 You might find it necessary to prevent specific packages
6518 from being installed into an image.
6519 If so, you can use several variables to direct the build
6520 system to essentially ignore installing recommended packages
6521 or to not install a package at all.
6522 </para>
6523
6524 <para>
6525 The following list introduces variables you can use to
6526 prevent packages from being installed into your image.
6527 Each of these variables only works with IPK and RPM
6528 package types.
6529 Support for Debian packages does not exist.
6530 Also, you can use these variables from your
6531 <filename>local.conf</filename> file or attach them to a
6532 specific image recipe by using a recipe name override.
6533 For more detail on the variables, see the descriptions in the
6534 Yocto Project Reference Manual's glossary chapter.
6535 <itemizedlist>
6536 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
6537 Use this variable to specify "recommended-only"
6538 packages that you do not want installed.
6539 </para></listitem>
6540 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
6541 Use this variable to prevent all "recommended-only"
6542 packages from being installed.
6543 </para></listitem>
6544 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
6545 Use this variable to prevent specific packages from
6546 being installed regardless of whether they are
6547 "recommended-only" or not.
6548 You need to realize that the build process could
6549 fail with an error when you
6550 prevent the installation of a package whose presence
6551 is required by an installed package.
6552 </para></listitem>
6553 </itemizedlist>
6554 </para>
6555 </section>
6556
6557 <section id='incrementing-a-package-revision-number'>
6558 <title>Incrementing a Package Revision Number</title>
6559
6560 <para>
6561 If a committed change results in changing the package output,
6562 then the value of the
6563 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
6564 variable needs to be increased (or "bumped").
6565 Increasing <filename>PR</filename> occurs one of two ways:
6566 <itemizedlist>
6567 <listitem><para>Automatically using a Package Revision
6568 Service (PR Service).</para></listitem>
6569 <listitem><para>Manually incrementing the
6570 <filename>PR</filename> variable.</para></listitem>
6571 </itemizedlist>
6572 </para>
6573
6574 <para>
6575 Given that one of the challenges any build system and its
6576 users face is how to maintain a package feed that is compatible
6577 with existing package manager applications such as
6578 RPM, APT, and OPKG, using an automated system is much
6579 preferred over a manual system.
6580 In either system, the main requirement is that version
6581 numbering increases in a linear fashion and that a number of
6582 version components exist that support that linear progression.
6583 </para>
6584
6585 <para>
6586 The following two sections provide information on the PR Service
6587 and on manual <filename>PR</filename> bumping.
6588 </para>
6589
6590 <section id='working-with-a-pr-service'>
6591 <title>Working With a PR Service</title>
6592
6593 <para>
6594 As mentioned, attempting to maintain revision numbers in the
6595 <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink>
6596 is error prone, inaccurate, and causes problems for people
6597 submitting recipes.
6598 Conversely, the PR Service automatically generates
6599 increasing numbers, particularly the revision field,
6600 which removes the human element.
6601 <note>
6602 For additional information on using a PR Service, you
6603 can see the
6604 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
6605 wiki page.
6606 </note>
6607 </para>
6608
6609 <para>
6610 The Yocto Project uses variables in order of
6611 decreasing priority to facilitate revision numbering (i.e.
6612 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
6613 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
6614 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
6615 for epoch, version, and revision, respectively).
6616 The values are highly dependent on the policies and
6617 procedures of a given distribution and package feed.
6618 </para>
6619
6620 <para>
6621 Because the OpenEmbedded build system uses
6622 "<ulink url='&YOCTO_DOCS_REF_URL;#checksums'>signatures</ulink>",
6623 which are unique to a given build, the build system
6624 knows when to rebuild packages.
6625 All the inputs into a given task are represented by a
6626 signature, which can trigger a rebuild when different.
6627 Thus, the build system itself does not rely on the
6628 <filename>PR</filename> numbers to trigger a rebuild.
6629 The signatures, however, can be used to generate
6630 <filename>PR</filename> values.
6631 </para>
6632
6633 <para>
6634 The PR Service works with both
6635 <filename>OEBasic</filename> and
6636 <filename>OEBasicHash</filename> generators.
6637 The value of <filename>PR</filename> bumps when the
6638 checksum changes and the different generator mechanisms
6639 change signatures under different circumstances.
6640 </para>
6641
6642 <para>
6643 As implemented, the build system includes values from
6644 the PR Service into the <filename>PR</filename> field as
6645 an addition using the form "<filename>.x</filename>" so
6646 <filename>r0</filename> becomes <filename>r0.1</filename>,
6647 <filename>r0.2</filename> and so forth.
6648 This scheme allows existing <filename>PR</filename> values
6649 to be used for whatever reasons, which include manual
6650 <filename>PR</filename> bumps, should it be necessary.
6651 </para>
6652
6653 <para>
6654 By default, the PR Service is not enabled or running.
6655 Thus, the packages generated are just "self consistent".
6656 The build system adds and removes packages and
6657 there are no guarantees about upgrade paths but images
6658 will be consistent and correct with the latest changes.
6659 </para>
6660
6661 <para>
6662 The simplest form for a PR Service is for it to exist
6663 for a single host development system that builds the
6664 package feed (building system).
6665 For this scenario, you can enable a local PR Service by
6666 setting
6667 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
6668 in your <filename>local.conf</filename> file in the
6669 <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
6670 <literallayout class='monospaced'>
6671 PRSERV_HOST = "localhost:0"
6672 </literallayout>
6673 Once the service is started, packages will automatically
6674 get increasing <filename>PR</filename> values and
6675 BitBake will take care of starting and stopping the server.
6676 </para>
6677
6678 <para>
6679 If you have a more complex setup where multiple host
6680 development systems work against a common, shared package
6681 feed, you have a single PR Service running and it is
6682 connected to each building system.
6683 For this scenario, you need to start the PR Service using
6684 the <filename>bitbake-prserv</filename> command:
6685 <literallayout class='monospaced'>
6686 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
6687 </literallayout>
6688 In addition to hand-starting the service, you need to
6689 update the <filename>local.conf</filename> file of each
6690 building system as described earlier so each system
6691 points to the server and port.
6692 </para>
6693
6694 <para>
6695 It is also recommended you use build history, which adds
6696 some sanity checks to package versions, in conjunction with
6697 the server that is running the PR Service.
6698 To enable build history, add the following to each building
6699 system's <filename>local.conf</filename> file:
6700 <literallayout class='monospaced'>
6701 # It is recommended to activate "buildhistory" for testing the PR service
6702 INHERIT += "buildhistory"
6703 BUILDHISTORY_COMMIT = "1"
6704 </literallayout>
6705 For information on build history, see the
6706 "<ulink url='&YOCTO_DOCS_REF_URL;#maintaining-build-output-quality'>Maintaining Build Output Quality</ulink>"
6707 section in the Yocto Project Reference Manual.
6708 </para>
6709
6710 <note>
6711 <para>The OpenEmbedded build system does not maintain
6712 <filename>PR</filename> information as part of the
6713 shared state (sstate) packages.
6714 If you maintain an sstate feed, its expected that either
6715 all your building systems that contribute to the sstate
6716 feed use a shared PR Service, or you do not run a PR
6717 Service on any of your building systems.
6718 Having some systems use a PR Service while others do
6719 not leads to obvious problems.</para>
6720 <para>For more information on shared state, see the
6721 "<ulink url='&YOCTO_DOCS_REF_URL;#shared-state-cache'>Shared State Cache</ulink>"
6722 section in the Yocto Project Reference Manual.</para>
6723 </note>
6724 </section>
6725
6726 <section id='manually-bumping-pr'>
6727 <title>Manually Bumping PR</title>
6728
6729 <para>
6730 The alternative to setting up a PR Service is to manually
6731 bump the
6732 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
6733 variable.
6734 </para>
6735
6736 <para>
6737 If a committed change results in changing the package output,
6738 then the value of the PR variable needs to be increased
6739 (or "bumped") as part of that commit.
6740 For new recipes you should add the <filename>PR</filename>
6741 variable and set its initial value equal to "r0", which is the default.
6742 Even though the default value is "r0", the practice of adding it to a new recipe makes
6743 it harder to forget to bump the variable when you make changes
6744 to the recipe in future.
6745 </para>
6746
6747 <para>
6748 If you are sharing a common <filename>.inc</filename> file with multiple recipes,
6749 you can also use the
6750 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
6751 variable to ensure that
6752 the recipes sharing the <filename>.inc</filename> file are rebuilt when the
6753 <filename>.inc</filename> file itself is changed.
6754 The <filename>.inc</filename> file must set <filename>INC_PR</filename>
6755 (initially to "r0"), and all recipes referring to it should set <filename>PR</filename>
6756 to "$(INC_PR).0" initially, incrementing the last number when the recipe is changed.
6757 If the <filename>.inc</filename> file is changed then its
6758 <filename>INC_PR</filename> should be incremented.
6759 </para>
6760
6761 <para>
6762 When upgrading the version of a package, assuming the
6763 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
6764 changes, the <filename>PR</filename> variable should be
6765 reset to "r0" (or "$(INC_PR).0" if you are using
6766 <filename>INC_PR</filename>).
6767 </para>
6768
6769 <para>
6770 Usually, version increases occur only to packages.
6771 However, if for some reason <filename>PV</filename> changes but does not
6772 increase, you can increase the
6773 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
6774 variable (Package Epoch).
6775 The <filename>PE</filename> variable defaults to "0".
6776 </para>
6777
6778 <para>
6779 Version numbering strives to follow the
6780 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
6781 Debian Version Field Policy Guidelines</ulink>.
6782 These guidelines define how versions are compared and what "increasing" a version means.
6783 </para>
6784 </section>
6785 </section>
6786
6787 <section id='handling-optional-module-packaging'>
6788 <title>Handling Optional Module Packaging</title>
6789
6790 <para>
6791 Many pieces of software split functionality into optional
6792 modules (or plug-ins) and the plug-ins that are built
6793 might depend on configuration options.
6794 To avoid having to duplicate the logic that determines what
6795 modules are available in your recipe or to avoid having
6796 to package each module by hand, the OpenEmbedded build system
6797 provides functionality to handle module packaging dynamically.
6798 </para>
6799
6800 <para>
6801 To handle optional module packaging, you need to do two things:
6802 <itemizedlist>
6803 <listitem><para>Ensure the module packaging is actually
6804 done.</para></listitem>
6805 <listitem><para>Ensure that any dependencies on optional
6806 modules from other recipes are satisfied by your recipe.
6807 </para></listitem>
6808 </itemizedlist>
6809 </para>
6810
6811 <section id='making-sure-the-packaging-is-done'>
6812 <title>Making Sure the Packaging is Done</title>
6813
6814 <para>
6815 To ensure the module packaging actually gets done, you use
6816 the <filename>do_split_packages</filename> function within
6817 the <filename>populate_packages</filename> Python function
6818 in your recipe.
6819 The <filename>do_split_packages</filename> function
6820 searches for a pattern of files or directories under a
6821 specified path and creates a package for each one it finds
6822 by appending to the
6823 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6824 variable and setting the appropriate values for
6825 <filename>FILES_packagename</filename>,
6826 <filename>RDEPENDS_packagename</filename>,
6827 <filename>DESCRIPTION_packagename</filename>, and so forth.
6828 Here is an example from the <filename>lighttpd</filename>
6829 recipe:
6830 <literallayout class='monospaced'>
6831 python populate_packages_prepend () {
6832 lighttpd_libdir = d.expand('${libdir}')
6833 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
6834 'lighttpd-module-%s', 'Lighttpd module for %s',
6835 extra_depends='')
6836 }
6837 </literallayout>
6838 The previous example specifies a number of things in the
6839 call to <filename>do_split_packages</filename>.
6840 <itemizedlist>
6841 <listitem><para>A directory within the files installed
6842 by your recipe through <filename>do_install</filename>
6843 in which to search.</para></listitem>
6844 <listitem><para>A regular expression used to match module
6845 files in that directory.
6846 In the example, note the parentheses () that mark
6847 the part of the expression from which the module
6848 name should be derived.</para></listitem>
6849 <listitem><para>A pattern to use for the package names.
6850 </para></listitem>
6851 <listitem><para>A description for each package.
6852 </para></listitem>
6853 <listitem><para>An empty string for
6854 <filename>extra_depends</filename>, which disables
6855 the default dependency on the main
6856 <filename>lighttpd</filename> package.
6857 Thus, if a file in <filename>${libdir}</filename>
6858 called <filename>mod_alias.so</filename> is found,
6859 a package called <filename>lighttpd-module-alias</filename>
6860 is created for it and the
6861 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
6862 is set to "Lighttpd module for alias".</para></listitem>
6863 </itemizedlist>
6864 </para>
6865
6866 <para>
6867 Often, packaging modules is as simple as the previous
6868 example.
6869 However, more advanced options exist that you can use
6870 within <filename>do_split_packages</filename> to modify its
6871 behavior.
6872 And, if you need to, you can add more logic by specifying
6873 a hook function that is called for each package.
6874 It is also perfectly acceptable to call
6875 <filename>do_split_packages</filename> multiple times if
6876 you have more than one set of modules to package.
6877 </para>
6878
6879 <para>
6880 For more examples that show how to use
6881 <filename>do_split_packages</filename>, see the
6882 <filename>connman.inc</filename> file in the
6883 <filename>meta/recipes-connectivity/connman/</filename>
6884 directory of the <filename>poky</filename>
6885 <link linkend='yocto-project-repositories'>source repository</link>.
6886 You can also find examples in
6887 <filename>meta/classes/kernel.bbclass</filename>.
6888 </para>
6889
6890 <para>
6891 Following is a reference that shows
6892 <filename>do_split_packages</filename> mandatory and
6893 optional arguments:
6894 <literallayout class='monospaced'>
6895 Mandatory arguments
6896
6897 root
6898 The path in which to search
6899 file_regex
6900 Regular expression to match searched files.
6901 Use parentheses () to mark the part of this
6902 expression that should be used to derive the
6903 module name (to be substituted where %s is
6904 used in other function arguments as noted below)
6905 output_pattern
6906 Pattern to use for the package names. Must
6907 include %s.
6908 description
6909 Description to set for each package. Must
6910 include %s.
6911
6912 Optional arguments
6913
6914 postinst
6915 Postinstall script to use for all packages
6916 (as a string)
6917 recursive
6918 True to perform a recursive search - default
6919 False
6920 hook
6921 A hook function to be called for every match.
6922 The function will be called with the following
6923 arguments (in the order listed):
6924
6925 f
6926 Full path to the file/directory match
6927 pkg
6928 The package name
6929 file_regex
6930 As above
6931 output_pattern
6932 As above
6933 modulename
6934 The module name derived using file_regex
6935
6936 extra_depends
6937 Extra runtime dependencies (RDEPENDS) to be
6938 set for all packages. The default value of None
6939 causes a dependency on the main package
6940 (${PN}) - if you do not want this, pass empty
6941 string '' for this parameter.
6942 aux_files_pattern
6943 Extra item(s) to be added to FILES for each
6944 package. Can be a single string item or a list
6945 of strings for multiple items. Must include %s.
6946 postrm
6947 postrm script to use for all packages (as a
6948 string)
6949 allow_dirs
6950 True to allow directories to be matched -
6951 default False
6952 prepend
6953 If True, prepend created packages to PACKAGES
6954 instead of the default False which appends them
6955 match_path
6956 match file_regex on the whole relative path to
6957 the root rather than just the file name
6958 aux_files_pattern_verbatim
6959 Extra item(s) to be added to FILES for each
6960 package, using the actual derived module name
6961 rather than converting it to something legal
6962 for a package name. Can be a single string item
6963 or a list of strings for multiple items. Must
6964 include %s.
6965 allow_links
6966 True to allow symlinks to be matched - default
6967 False
6968 summary
6969 Summary to set for each package. Must include %s;
6970 defaults to description if not set.
6971 </literallayout>
6972 </para>
6973 </section>
6974
6975 <section id='satisfying-dependencies'>
6976 <title>Satisfying Dependencies</title>
6977
6978 <para>
6979 The second part for handling optional module packaging
6980 is to ensure that any dependencies on optional modules
6981 from other recipes are satisfied by your recipe.
6982 You can be sure these dependencies are satisfied by
6983 using the
6984 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
6985 Here is an example that continues with the
6986 <filename>lighttpd</filename> recipe shown earlier:
6987 <literallayout class='monospaced'>
6988 PACKAGES_DYNAMIC = "lighttpd-module-.*"
6989 </literallayout>
6990 The name specified in the regular expression can of
6991 course be anything.
6992 In this example, it is <filename>lighttpd-module-</filename>
6993 and is specified as the prefix to ensure that any
6994 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
6995 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
6996 on a package name starting with the prefix are satisfied
6997 during build time.
6998 If you are using <filename>do_split_packages</filename>
6999 as described in the previous section, the value you put in
7000 <filename>PACKAGES_DYNAMIC</filename> should correspond to
7001 the name pattern specified in the call to
7002 <filename>do_split_packages</filename>.
7003 </para>
7004 </section>
7005 </section>
7006
7007 <section id='using-runtime-package-management'>
7008 <title>Using Runtime Package Management</title>
7009
7010 <para>
7011 During a build, BitBake always transforms a recipe into one or
7012 more packages.
7013 For example, BitBake takes the <filename>bash</filename> recipe
7014 and currently produces the <filename>bash-dbg</filename>,
7015 <filename>bash-staticdev</filename>,
7016 <filename>bash-dev</filename>, <filename>bash-doc</filename>,
7017 <filename>bash-locale</filename>, and
7018 <filename>bash</filename> packages.
7019 Not all generated packages are included in an image.
7020 </para>
7021
7022 <para>
7023 In several situations, you might need to update, add, remove,
7024 or query the packages on a target device at runtime
7025 (i.e. without having to generate a new image).
7026 Examples of such situations include:
7027 <itemizedlist>
7028 <listitem><para>
7029 You want to provide in-the-field updates to deployed
7030 devices (e.g. security updates).
7031 </para></listitem>
7032 <listitem><para>
7033 You want to have a fast turn-around development cycle
7034 for one or more applications that run on your device.
7035 </para></listitem>
7036 <listitem><para>
7037 You want to temporarily install the "debug" packages
7038 of various applications on your device so that
7039 debugging can be greatly improved by allowing
7040 access to symbols and source debugging.
7041 </para></listitem>
7042 <listitem><para>
7043 You want to deploy a more minimal package selection of
7044 your device but allow in-the-field updates to add a
7045 larger selection for customization.
7046 </para></listitem>
7047 </itemizedlist>
7048 </para>
7049
7050 <para>
7051 In all these situations, you have something similar to a more
7052 traditional Linux distribution in that in-field devices
7053 are able to receive pre-compiled packages from a server for
7054 installation or update.
7055 Being able to install these packages on a running,
7056 in-field device is what is termed "runtime package
7057 management".
7058 </para>
7059
7060 <para>
7061 In order to use runtime package management, you
7062 need a host/server machine that serves up the pre-compiled
7063 packages plus the required metadata.
7064 You also need package manipulation tools on the target.
7065 The build machine is a likely candidate to act as the server.
7066 However, that machine does not necessarily have to be the
7067 package server.
7068 The build machine could push its artifacts to another machine
7069 that acts as the server (e.g. Internet-facing).
7070 </para>
7071
7072 <para>
7073 A simple build that targets just one device produces
7074 more than one package database.
7075 In other words, the packages produced by a build are separated
7076 out into a couple of different package groupings based on
7077 criteria such as the target's CPU architecture, the target
7078 board, or the C library used on the target.
7079 For example, a build targeting the <filename>qemuarm</filename>
7080 device produces the following three package databases:
7081 <filename>all</filename>, <filename>armv5te</filename>, and
7082 <filename>qemuarm</filename>.
7083 If you wanted your <filename>qemuarm</filename> device to be
7084 aware of all the packages that were available to it,
7085 you would need to point it to each of these databases
7086 individually.
7087 In a similar way, a traditional Linux distribution usually is
7088 configured to be aware of a number of software repositories
7089 from which it retrieves packages.
7090 </para>
7091
7092 <para>
7093 Using runtime package management is completely optional and
7094 not required for a successful build or deployment in any
7095 way.
7096 But if you want to make use of runtime package management,
7097 you need to do a couple things above and beyond the basics.
7098 The remainder of this section describes what you need to do.
7099 </para>
7100
7101 <section id='runtime-package-management-build'>
7102 <title>Build Considerations</title>
7103
7104 <para>
7105 This section describes build considerations that you need
7106 to be aware of in order to provide support for runtime
7107 package management.
7108 </para>
7109
7110 <para>
7111 When BitBake generates packages it needs to know
7112 what format or formats to use.
7113 In your configuration, you use the
7114 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
7115 variable to specify the format.
7116 <note>
7117 You can choose to have more than one format but you must
7118 provide at least one.
7119 </note>
7120 </para>
7121
7122 <para>
7123 If you would like your image to start off with a basic
7124 package database of the packages in your current build
7125 as well as have the relevant tools available on the
7126 target for runtime package management, you can include
7127 "package-management" in the
7128 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
7129 variable.
7130 Including "package-management" in this
7131 configuration variable ensures that when the image
7132 is assembled for your target, the image includes
7133 the currently-known package databases as well as
7134 the target-specific tools required for runtime
7135 package management to be performed on the target.
7136 However, this is not strictly necessary.
7137 You could start your image off without any databases
7138 but only include the required on-target package
7139 tool(s).
7140 As an example, you could include "opkg" in your
7141 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
7142 variable if you are using the IPK package format.
7143 You can then initialize your target's package database(s)
7144 later once your image is up and running.
7145 </para>
7146
7147 <para>
7148 Whenever you perform any sort of build step that can
7149 potentially generate a package or modify an existing
7150 package, it is always a good idea to re-generate the
7151 package index with:
7152 <literallayout class='monospaced'>
7153 $ bitbake package-index
7154 </literallayout>
7155 Realize that it is not sufficient to simply do the
7156 following:
7157 <literallayout class='monospaced'>
7158 $ bitbake <replaceable>some-package</replaceable> package-index
7159 </literallayout>
7160 This is because BitBake does not properly schedule the
7161 <filename>package-index</filename> target fully after any
7162 other target has completed.
7163 Thus, be sure to run the package update step separately.
7164 </para>
7165
7166 <para>
7167 As described below in the
7168 "<link linkend='runtime-package-management-target-ipk'>Using IPK</link>"
7169 section, if you are using IPK as your package format, you
7170 can make use of the
7171 <filename>distro-feed-configs</filename> recipe provided
7172 by <filename>meta-oe</filename> in order to configure your
7173 target to use your IPK databases.
7174 </para>
7175
7176 <para>
7177 When your build is complete, your packages reside in the
7178 <filename>${TMPDIR}/deploy/<replaceable>package-format</replaceable></filename>
7179 directory.
7180 For example, if <filename>${TMPDIR}</filename>
7181 is <filename>tmp</filename> and your selected package type
7182 is IPK, then your IPK packages are available in
7183 <filename>tmp/deploy/ipk</filename>.
7184 </para>
7185 </section>
7186
7187 <section id='runtime-package-management-server'>
7188 <title>Host or Server Machine Setup</title>
7189
7190 <para>
7191 Typically, packages are served from a server using
7192 HTTP.
7193 However, other protocols are possible.
7194 If you want to use HTTP, then setup and configure a
7195 web server, such as Apache 2 or lighttpd, on the machine
7196 serving the packages.
7197 </para>
7198
7199 <para>
7200 As previously mentioned, the build machine can act as the
7201 package server.
7202 In the following sections that describe server machine
7203 setups, the build machine is assumed to also be the server.
7204 </para>
7205
7206 <section id='package-server-apache'>
7207 <title>Serving Packages via Apache 2</title>
7208
7209 <para>
7210 This example assumes you are using the Apache 2
7211 server:
7212 <orderedlist>
7213 <listitem><para>
7214 Add the directory to your Apache
7215 configuration, which you can find at
7216 <filename>/etc/httpd/conf/httpd.conf</filename>.
7217 Use commands similar to these on the
7218 development system.
7219 These example commands assume a top-level
7220 <link linkend='source-directory'>Source Directory</link>
7221 named <filename>poky</filename> in your home
7222 directory.
7223 The example also assumes an RPM package type.
7224 If you are using a different package type, such
7225 as IPK, use "ipk" in the pathnames:
7226 <literallayout class='monospaced'>
7227 &lt;VirtualHost *:80&gt;
7228 ....
7229 Alias /rpm ~/poky/build/tmp/deploy/rpm
7230 &lt;Directory "~/poky/build/tmp/deploy/rpm"&gt;
7231 Options +Indexes
7232 &lt;/Directory&gt;
7233 &lt;/VirtualHost&gt;
7234 </literallayout></para></listitem>
7235 <listitem><para>
7236 Reload the Apache configuration as described
7237 in this step.
7238 For all commands, be sure you have root
7239 privileges.
7240 </para>
7241
7242 <para>
7243 If your development system is using Fedora or
7244 CentOS, use the following:
7245 <literallayout class='monospaced'>
7246 # service httpd reload
7247 </literallayout>
7248 For Ubuntu and Debian, use the following:
7249 <literallayout class='monospaced'>
7250 # /etc/init.d/apache2 reload
7251 </literallayout>
7252 For OpenSUSE, use the following:
7253 <literallayout class='monospaced'>
7254 # /etc/init.d/apache2 reload
7255 </literallayout></para></listitem>
7256 <listitem><para>
7257 If you are using Security-Enhanced Linux
7258 (SELinux), you need to label the files as
7259 being accessible through Apache.
7260 Use the following command from the development
7261 host.
7262 This example assumes RPM package types:
7263 <literallayout class='monospaced'>
7264 # chcon -R -h -t httpd_sys_content_t tmp/deploy/rpm
7265 </literallayout></para></listitem>
7266 </orderedlist>
7267 </para>
7268 </section>
7269
7270 <section id='package-server-lighttpd'>
7271 <title>Serving Packages via lighttpd</title>
7272
7273 <para>
7274 If you are using lighttpd, all you need
7275 to do is to provide a link from your
7276 <filename>${TMPDIR}/deploy/<replaceable>package-format</replaceable></filename>
7277 directory to lighttpd's document-root.
7278 You can determine the specifics of your lighttpd
7279 installation by looking through its configuration file,
7280 which is usually found at:
7281 <filename>/etc/lighttpd/lighttpd.conf</filename>.
7282 </para>
7283
7284 <para>
7285 For example, if you are using IPK, lighttpd's
7286 document-root is set to
7287 <filename>/var/www/lighttpd</filename>, and you had
7288 packages for a target named "BOARD",
7289 then you might create a link from your build location
7290 to lighttpd's document-root as follows:
7291 <literallayout class='monospaced'>
7292 # ln -s $(PWD)/tmp/deploy/ipk /var/www/lighttpd/BOARD-dir
7293 </literallayout>
7294 </para>
7295
7296 <para>
7297 At this point, you need to start the lighttpd server.
7298 The method used to start the server varies by
7299 distribution.
7300 However, one basic method that starts it by hand is:
7301 <literallayout class='monospaced'>
7302 # lighttpd -f /etc/lighttpd/lighttpd.conf
7303 </literallayout>
7304 </para>
7305 </section>
7306 </section>
7307
7308 <section id='runtime-package-management-target'>
7309 <title>Target Setup</title>
7310
7311 <para>
7312 Setting up the target differs depending on the
7313 package management system.
7314 This section provides information for RPM and IPK.
7315 </para>
7316
7317 <section id='runtime-package-management-target-rpm'>
7318 <title>Using RPM</title>
7319
7320 <para>
7321 The application for performing runtime package
7322 management of RPM packages on the target is called
7323 <filename>smart</filename>.
7324 </para>
7325
7326 <para>
7327 On the target machine, you need to inform
7328 <filename>smart</filename> of every package database
7329 you want to use.
7330 As an example, suppose your target device can use the
7331 following three package databases from a server named
7332 <filename>server.name</filename>:
7333 <filename>all</filename>, <filename>i586</filename>,
7334 and <filename>qemux86</filename>.
7335 Given this example, issue the following commands on the
7336 target:
7337 <literallayout class='monospaced'>
7338 # smart channel --add all type=rpm-md baseurl=http://server.name/rpm/all
7339 # smart channel --add i585 type=rpm-md baseurl=http://server.name/rpm/i586
7340 # smart channel --add qemux86 type=rpm-md baseurl=http://server.name/rpm/qemux86
7341 </literallayout>
7342 Also from the target machine, fetch the repository
7343 information using this command:
7344 <literallayout class='monospaced'>
7345 # smart update
7346 </literallayout>
7347 You can now use the <filename>smart query</filename>
7348 and <filename>smart install</filename> commands to
7349 find and install packages from the repositories.
7350 </para>
7351 </section>
7352
7353 <section id='runtime-package-management-target-ipk'>
7354 <title>Using IPK</title>
7355
7356 <para>
7357 The application for performing runtime package
7358 management of IPK packages on the target is called
7359 <filename>opkg</filename>.
7360 </para>
7361
7362 <para>
7363 In order to inform <filename>opkg</filename> of the
7364 package databases you want to use, simply create one
7365 or more <filename>*.conf</filename> files in the
7366 <filename>/etc/opkg</filename> directory on the target.
7367 The <filename>opkg</filename> application uses them
7368 to find its available package databases.
7369 As an example, suppose you configured your HTTP server
7370 on your machine named
7371 <filename>www.mysite.com</filename> to serve files
7372 from a <filename>BOARD-dir</filename> directory under
7373 its document-root.
7374 In this case, you might create a configuration
7375 file on the target called
7376 <filename>/etc/opkg/base-feeds.conf</filename> that
7377 contains:
7378 <literallayout class='monospaced'>
7379 src/gz all http://www.mysite.com/BOARD-dir/all
7380 src/gz armv7a http://www.mysite.com/BOARD-dir/armv7a
7381 src/gz beaglebone http://www.mysite.com/BOARD-dir/beaglebone
7382 </literallayout>
7383 </para>
7384
7385 <para>
7386 As a way of making it easier to generate and make
7387 these IPK configuration files available on your
7388 target, simply define
7389 <ulink url='&YOCTO_DOCS_REF_URL;#var-FEED_DEPLOYDIR_BASE_URI'><filename>FEED_DEPLOYDIR_BASE_URI</filename></ulink>
7390 to point to your server and the location within the
7391 document-root which contains the databases.
7392 For example: if you are serving your packages over
7393 HTTP, your server's IP address is 192.168.7.1, and
7394 your databases are located in a directory called
7395 <filename>BOARD-dir</filename> underneath your HTTP
7396 server's document-root, you need to set
7397 <filename>FEED_DEPLOYDIR_BASE_URI</filename> to
7398 <filename>http://192.168.7.1/BOARD-dir</filename> and
7399 a set of configuration files will be generated for you
7400 in your target to work with this feed.
7401 </para>
7402
7403 <para>
7404 On the target machine, fetch (or refresh) the
7405 repository information using this command:
7406 <literallayout class='monospaced'>
7407 # opkg update
7408 </literallayout>
7409 You can now use the <filename>opkg list</filename> and
7410 <filename>opkg install</filename> commands to find and
7411 install packages from the repositories.
7412 </para>
7413 </section>
7414 </section>
7415 </section>
7416
7417 <section id='testing-packages-with-ptest'>
7418 <title>Testing Packages With ptest</title>
7419
7420 <para>
7421 A Package Test (ptest) runs tests against packages built
7422 by the OpenEmbedded build system on the target machine.
7423 A ptest contains at least two items: the actual test, and
7424 a shell script (<filename>run-ptest</filename>) that starts
7425 the test.
7426 The shell script that starts the test must not contain
7427 the actual test - the script only starts the test.
7428 On the other hand, the test can be anything from a simple
7429 shell script that runs a binary and checks the output to
7430 an elaborate system of test binaries and data files.
7431 </para>
7432
7433 <para>
7434 The test generates output in the format used by
7435 Automake:
7436 <literallayout class='monospaced'>
7437 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
7438 </literallayout>
7439 where the result can be <filename>PASS</filename>,
7440 <filename>FAIL</filename>, or <filename>SKIP</filename>,
7441 and the testname can be any identifying string.
7442 </para>
7443
7444 <para>
7445 For a list of Yocto Project recipes that are already
7446 enabled with ptest, see the
7447 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
7448 wiki page.
7449 <note>
7450 A recipe is "ptest-enabled" if it inherits the
7451 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
7452 class.
7453 </note>
7454 </para>
7455
7456 <section id='adding-ptest-to-your-build'>
7457 <title>Adding ptest to Your Build</title>
7458
7459 <para>
7460 To add package testing to your build, add the
7461 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
7462 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
7463 variables to your <filename>local.conf</filename> file,
7464 which is found in the
7465 <link linkend='build-directory'>Build Directory</link>:
7466 <literallayout class='monospaced'>
7467 DISTRO_FEATURES_append = " ptest"
7468 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7469 </literallayout>
7470 Once your build is complete, the ptest files are installed
7471 into the
7472 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
7473 directory within the image, where
7474 <filename><replaceable>package</replaceable></filename>
7475 is the name of the package.
7476 </para>
7477 </section>
7478
7479 <section id='running-ptest'>
7480 <title>Running ptest</title>
7481
7482 <para>
7483 The <filename>ptest-runner</filename> package installs a
7484 shell script that loops through all installed ptest test
7485 suites and runs them in sequence.
7486 Consequently, you might want to add this package to
7487 your image.
7488 </para>
7489 </section>
7490
7491 <section id='getting-your-package-ready'>
7492 <title>Getting Your Package Ready</title>
7493
7494 <para>
7495 In order to enable a recipe to run installed ptests
7496 on target hardware,
7497 you need to prepare the recipes that build the packages
7498 you want to test.
7499 Here is what you have to do for each recipe:
7500 <itemizedlist>
7501 <listitem><para><emphasis>Be sure the recipe
7502 inherits the
7503 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
7504 class:</emphasis>
7505 Include the following line in each recipe:
7506 <literallayout class='monospaced'>
7507 inherit ptest
7508 </literallayout>
7509 </para></listitem>
7510 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
7511 This script starts your test.
7512 Locate the script where you will refer to it
7513 using
7514 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
7515 Here is an example that starts a test for
7516 <filename>dbus</filename>:
7517 <literallayout class='monospaced'>
7518 #!/bin/sh
7519 cd test
7520 make -k runtest-TESTS
7521 </literallayout>
7522 </para></listitem>
7523 <listitem><para><emphasis>Ensure dependencies are
7524 met:</emphasis>
7525 If the test adds build or runtime dependencies
7526 that normally do not exist for the package
7527 (such as requiring "make" to run the test suite),
7528 use the
7529 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
7530 and
7531 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
7532 variables in your recipe in order for the package
7533 to meet the dependencies.
7534 Here is an example where the package has a runtime
7535 dependency on "make":
7536 <literallayout class='monospaced'>
7537 RDEPENDS_${PN}-ptest += "make"
7538 </literallayout>
7539 </para></listitem>
7540 <listitem><para><emphasis>Add a function to build the
7541 test suite:</emphasis>
7542 Not many packages support cross-compilation of
7543 their test suites.
7544 Consequently, you usually need to add a
7545 cross-compilation function to the package.
7546 </para>
7547 <para>Many packages based on Automake compile and
7548 run the test suite by using a single command
7549 such as <filename>make check</filename>.
7550 However, the native <filename>make check</filename>
7551 builds and runs on the same computer, while
7552 cross-compiling requires that the package is built
7553 on the host but executed on the target.
7554 The built version of Automake that ships with the
7555 Yocto Project includes a patch that separates
7556 building and execution.
7557 Consequently, packages that use the unaltered,
7558 patched version of <filename>make check</filename>
7559 automatically cross-compiles.</para>
7560 <para>Regardless, you still must add a
7561 <filename>do_compile_ptest</filename> function to
7562 build the test suite.
7563 Add a function similar to the following to your
7564 recipe:
7565 <literallayout class='monospaced'>
7566 do_compile_ptest() {
7567 oe_runmake buildtest-TESTS
7568 }
7569 </literallayout>
7570 </para></listitem>
7571 <listitem><para><emphasis>Ensure special configurations
7572 are set:</emphasis>
7573 If the package requires special configurations
7574 prior to compiling the test code, you must
7575 insert a <filename>do_configure_ptest</filename>
7576 function into the recipe.
7577 </para></listitem>
7578 <listitem><para><emphasis>Install the test
7579 suite:</emphasis>
7580 The <filename>ptest</filename> class
7581 automatically copies the file
7582 <filename>run-ptest</filename> to the target and
7583 then runs make <filename>install-ptest</filename>
7584 to run the tests.
7585 If this is not enough, you need to create a
7586 <filename>do_install_ptest</filename> function and
7587 make sure it gets called after the
7588 "make install-ptest" completes.
7589 </para></listitem>
7590 </itemizedlist>
7591 </para>
7592 </section>
7593 </section>
7594 </section>
7595
7596 <section id='working-with-source-files'>
7597 <title>Working with Source Files</title>
7598
7599 <para>
7600 The OpenEmbedded build system works with source files located
7601 through the
7602 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
7603 variable.
7604 When you build something using BitBake, a big part of the operation
7605 is locating and downloading all the source tarballs.
7606 For images, downloading all the source for various packages can
7607 take a significant amount of time.
7608 </para>
7609
7610 <para>
7611 This section presents information for working with source
7612 files that can lead to more efficient use of resources and
7613 time.
7614 </para>
7615
7616 <section id='setting-up-effective-mirrors'>
7617 <title>Setting up Effective Mirrors</title>
7618
7619 <para>
7620 As mentioned, a good deal that goes into a Yocto Project
7621 build is simply downloading all of the source tarballs.
7622 Maybe you have been working with another build system
7623 (OpenEmbedded or Angstrom) for which you have built up a
7624 sizable directory of source tarballs.
7625 Or, perhaps someone else has such a directory for which you
7626 have read access.
7627 If so, you can save time by adding statements to your
7628 configuration file so that the build process checks local
7629 directories first for existing tarballs before checking the
7630 Internet.
7631 </para>
7632
7633 <para>
7634 Here is an efficient way to set it up in your
7635 <filename>local.conf</filename> file:
7636 <literallayout class='monospaced'>
7637 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7638 INHERIT += "own-mirrors"
7639 BB_GENERATE_MIRROR_TARBALLS = "1"
7640 # BB_NO_NETWORK = "1"
7641 </literallayout>
7642 </para>
7643
7644 <para>
7645 In the previous example, the
7646 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
7647 variable causes the OpenEmbedded build system to generate
7648 tarballs of the Git repositories and store them in the
7649 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
7650 directory.
7651 Due to performance reasons, generating and storing these
7652 tarballs is not the build system's default behavior.
7653 </para>
7654
7655 <para>
7656 You can also use the
7657 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
7658 variable.
7659 For an example, see the variable's glossary entry in the
7660 Yocto Project Reference Manual.
7661 </para>
7662 </section>
7663
7664 <section id='getting-source-files-and-suppressing-the-build'>
7665 <title>Getting Source Files and Suppressing the Build</title>
7666
7667 <para>
7668 Another technique you can use to ready yourself for a
7669 successive string of build operations, is to pre-fetch
7670 all the source files without actually starting a build.
7671 This technique lets you work through any download issues
7672 and ultimately gathers all the source files into your
7673 download directory
7674 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
7675 which is located with
7676 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
7677 </para>
7678
7679 <para>
7680 Use the following BitBake command form to fetch all the
7681 necessary sources without starting the build:
7682 <literallayout class='monospaced'>
7683 $ bitbake -c fetchall <replaceable>target</replaceable>
7684 </literallayout>
7685 This variation of the BitBake command guarantees that you
7686 have all the sources for that BitBake target should you
7687 disconnect from the Internet and want to do the build
7688 later offline.
7689 </para>
7690 </section>
7691 </section>
7692
7693 <section id="building-software-from-an-external-source">
7694 <title>Building Software from an External Source</title>
7695
7696 <para>
7697 By default, the OpenEmbedded build system uses the
7698 <link linkend='build-directory'>Build Directory</link> when
7699 building source code.
7700 The build process involves fetching the source files, unpacking
7701 them, and then patching them if necessary before the build takes
7702 place.
7703 </para>
7704
7705 <para>
7706 Situations exist where you might want to build software from source
7707 files that are external to and thus outside of the
7708 OpenEmbedded build system.
7709 For example, suppose you have a project that includes a new BSP with
7710 a heavily customized kernel.
7711 And, you want to minimize exposing the build system to the
7712 development team so that they can focus on their project and
7713 maintain everyone's workflow as much as possible.
7714 In this case, you want a kernel source directory on the development
7715 machine where the development occurs.
7716 You want the recipe's
7717 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
7718 variable to point to the external directory and use it as is, not
7719 copy it.
7720 </para>
7721
7722 <para>
7723 To build from software that comes from an external source, all you
7724 need to do is inherit the
7725 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
7726 class and then set the
7727 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
7728 variable to point to your external source code.
7729 Here are the statements to put in your
7730 <filename>local.conf</filename> file:
7731 <literallayout class='monospaced'>
7732 INHERIT += "externalsrc"
7733 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
7734 </literallayout>
7735 </para>
7736
7737 <para>
7738 This next example shows how to accomplish the same thing by setting
7739 <filename>EXTERNALSRC</filename> in the recipe itself or in the
7740 recipe's append file:
7741 <literallayout class='monospaced'>
7742 EXTERNALSRC = "<replaceable>path</replaceable>"
7743 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
7744 </literallayout>
7745 <note>
7746 In order for these settings to take effect, you must globally
7747 or locally inherit the
7748 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
7749 class.
7750 </note>
7751 </para>
7752
7753 <para>
7754 By default, <filename>externalsrc.bbclass</filename> builds
7755 the source code in a directory separate from the external source
7756 directory as specified by
7757 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
7758 If you need to have the source built in the same directory in
7759 which it resides, or some other nominated directory, you can set
7760 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
7761 to point to that directory:
7762 <literallayout class='monospaced'>
7763 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
7764 </literallayout>
7765 </para>
7766 </section>
7767
7768 <section id="selecting-an-initialization-manager">
7769 <title>Selecting an Initialization Manager</title>
7770
7771 <para>
7772 By default, the Yocto Project uses SysVinit as the initialization
7773 manager.
7774 However, support also exists for systemd,
7775 which is a full replacement for init with
7776 parallel starting of services, reduced shell overhead and other
7777 features that are used by many distributions.
7778 </para>
7779
7780 <para>
7781 If you want to use SysVinit, you do
7782 not have to do anything.
7783 But, if you want to use systemd, you must
7784 take some steps as described in the following sections.
7785 </para>
7786
7787 <section id='using-systemd-exclusively'>
7788 <title>Using systemd Exclusively</title>
7789
7790 <para>
7791 Set the these variables in your distribution configuration
7792 file as follows:
7793 <literallayout class='monospaced'>
7794 DISTRO_FEATURES_append = " systemd"
7795 VIRTUAL-RUNTIME_init_manager = "systemd"
7796 </literallayout>
7797 You can also prevent the SysVinit
7798 distribution feature from
7799 being automatically enabled as follows:
7800 <literallayout class='monospaced'>
7801 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7802 </literallayout>
7803 Doing so removes any redundant SysVinit scripts.
7804 </para>
7805
7806 <para>
7807 To remove initscripts from your image altogether,
7808 set this variable also:
7809 <literallayout class='monospaced'>
7810 VIRTUAL-RUNTIME_initscripts = ""
7811 </literallayout>
7812 </para>
7813
7814 <para>
7815 For information on the backfill variable, see
7816 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7817 </para>
7818 </section>
7819
7820 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
7821 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
7822
7823 <para>
7824 Set these variables in your distribution configuration
7825 file as follows:
7826 <literallayout class='monospaced'>
7827 DISTRO_FEATURES_append = " systemd"
7828 VIRTUAL-RUNTIME_init_manager = "systemd"
7829 </literallayout>
7830 Doing so causes your main image to use the
7831 <filename>packagegroup-core-boot.bb</filename> recipe and
7832 systemd.
7833 The rescue/minimal image cannot use this package group.
7834 However, it can install SysVinit
7835 and the appropriate packages will have support for both
7836 systemd and SysVinit.
7837 </para>
7838 </section>
7839 </section>
7840
7841 <section id="selecting-dev-manager">
7842 <title>Selecting a Device Manager</title>
7843
7844 <para>
7845 The Yocto Project provides multiple ways to manage the device
7846 manager (<filename>/dev</filename>):
7847 <itemizedlist>
7848 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
7849 For this case, the <filename>/dev</filename> directory
7850 is persistent and the required device nodes are created
7851 during the build.
7852 </para></listitem>
7853 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
7854 For this case, the <filename>/dev</filename> directory
7855 is provided by the kernel as an in-memory file system and
7856 is automatically populated by the kernel at runtime.
7857 Additional configuration of device nodes is done in user
7858 space by a device manager like
7859 <filename>udev</filename> or
7860 <filename>busybox-mdev</filename>.
7861 </para></listitem>
7862 </itemizedlist>
7863 </para>
7864
7865 <section id="static-dev-management">
7866 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
7867
7868 <para>
7869 To use the static method for device population, you need to
7870 set the
7871 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
7872 variable to "0" as follows:
7873 <literallayout class='monospaced'>
7874 USE_DEVFS = "0"
7875 </literallayout>
7876 </para>
7877
7878 <para>
7879 The content of the resulting <filename>/dev</filename>
7880 directory is defined in a Device Table file.
7881 The
7882 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
7883 variable defines the Device Table to use and should be set
7884 in the machine or distro configuration file.
7885 Alternatively, you can set this variable in your
7886 <filename>local.conf</filename> configuration file.
7887 </para>
7888
7889 <para>
7890 If you do not define the
7891 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
7892 <filename>device_table-minimal.txt</filename> is used:
7893 <literallayout class='monospaced'>
7894 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
7895 </literallayout>
7896 </para>
7897
7898 <para>
7899 The population is handled by the <filename>makedevs</filename>
7900 utility during image creation:
7901 </para>
7902 </section>
7903
7904 <section id="devtmpfs-dev-management">
7905 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
7906
7907 <para>
7908 To use the dynamic method for device population, you need to
7909 use (or be sure to set) the
7910 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
7911 variable to "1", which is the default:
7912 <literallayout class='monospaced'>
7913 USE_DEVFS = "1"
7914 </literallayout>
7915 With this setting, the resulting <filename>/dev</filename>
7916 directory is populated by the kernel using
7917 <filename>devtmpfs</filename>.
7918 Make sure the corresponding kernel configuration variable
7919 <filename>CONFIG_DEVTMPFS</filename> is set when building
7920 you build a Linux kernel.
7921 </para>
7922
7923 <para>
7924 All devices created by <filename>devtmpfs</filename> will be
7925 owned by <filename>root</filename> and have permissions
7926 <filename>0600</filename>.
7927 </para>
7928
7929 <para>
7930 To have more control over the device nodes, you can use a
7931 device manager like <filename>udev</filename> or
7932 <filename>busybox-mdev</filename>.
7933 You choose the device manager by defining the
7934 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
7935 in your machine or distro configuration file.
7936 Alternatively, you can set this variable in your
7937 <filename>local.conf</filename> configuration file:
7938 <literallayout class='monospaced'>
7939 VIRTUAL-RUNTIME_dev_manager = "udev"
7940
7941 # Some alternative values
7942 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
7943 # VIRTUAL-RUNTIME_dev_manager = "systemd"
7944 </literallayout>
7945 </para>
7946 </section>
7947 </section>
7948
7949 <section id="platdev-appdev-srcrev">
7950 <title>Using an External SCM</title>
7951
7952 <para>
7953 If you're working on a recipe that pulls from an external Source
7954 Code Manager (SCM), it is possible to have the OpenEmbedded build
7955 system notice new recipe changes added to the SCM and then build
7956 the resulting packages that depend on the new recipes by using
7957 the latest versions.
7958 This only works for SCMs from which it is possible to get a
7959 sensible revision number for changes.
7960 Currently, you can do this with Apache Subversion (SVN), Git, and
7961 Bazaar (BZR) repositories.
7962 </para>
7963
7964 <para>
7965 To enable this behavior, the
7966 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
7967 of the recipe needs to reference
7968 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
7969 Here is an example:
7970 <literallayout class='monospaced'>
7971 PV = "1.2.3+git${SRCPV}"
7972 </literallayout>
7973 Then, you can add the following to your
7974 <filename>local.conf</filename>:
7975 <literallayout class='monospaced'>
7976 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
7977 </literallayout>
7978 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
7979 is the name of the recipe for which you want to enable automatic source
7980 revision updating.
7981 </para>
7982
7983 <para>
7984 If you do not want to update your local configuration file, you can
7985 add the following directly to the recipe to finish enabling
7986 the feature:
7987 <literallayout class='monospaced'>
7988 SRCREV = "${AUTOREV}"
7989 </literallayout>
7990 </para>
7991
7992 <para>
7993 The Yocto Project provides a distribution named
7994 <filename>poky-bleeding</filename>, whose configuration
7995 file contains the line:
7996 <literallayout class='monospaced'>
7997 require conf/distro/include/poky-floating-revisions.inc
7998 </literallayout>
7999 This line pulls in the listed include file that contains
8000 numerous lines of exactly that form:
8001 <literallayout class='monospaced'>
8002 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
8003 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
8004 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
8005 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
8006 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
8007 SRCREV_pn-matchbox-panel ?= "${AUTOREV}"
8008 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
8009 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
8010 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
8011 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
8012 SRCREV_pn-matchbox-wm-2 ?= "${AUTOREV}"
8013 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
8014 SRCREV_pn-screenshot ?= "${AUTOREV}"
8015 SRCREV_pn-libfakekey ?= "${AUTOREV}"
8016 SRCREV_pn-oprofileui ?= "${AUTOREV}"
8017 .
8018 .
8019 .
8020 </literallayout>
8021 These lines allow you to experiment with building a
8022 distribution that tracks the latest development source
8023 for numerous packages.
8024 <note><title>Caution</title>
8025 The <filename>poky-bleeding</filename> distribution
8026 is not tested on a regular basis.
8027 Keep this in mind if you use it.
8028 </note>
8029 </para>
8030 </section>
8031
8032 <section id='creating-a-read-only-root-filesystem'>
8033 <title>Creating a Read-Only Root Filesystem</title>
8034
8035 <para>
8036 Suppose, for security reasons, you need to disable
8037 your target device's root filesystem's write permissions
8038 (i.e. you need a read-only root filesystem).
8039 Or, perhaps you are running the device's operating system
8040 from a read-only storage device.
8041 For either case, you can customize your image for
8042 that behavior.
8043 </para>
8044
8045 <note>
8046 Supporting a read-only root filesystem requires that the system and
8047 applications do not try to write to the root filesystem.
8048 You must configure all parts of the target system to write
8049 elsewhere, or to gracefully fail in the event of attempting to
8050 write to the root filesystem.
8051 </note>
8052
8053 <section id='creating-the-root-filesystem'>
8054 <title>Creating the Root Filesystem</title>
8055
8056 <para>
8057 To create the read-only root filesystem, simply add the
8058 "read-only-rootfs" feature to your image.
8059 Using either of the following statements in your
8060 image recipe or from within the
8061 <filename>local.conf</filename> file found in the
8062 <link linkend='build-directory'>Build Directory</link>
8063 causes the build system to create a read-only root filesystem:
8064 <literallayout class='monospaced'>
8065 IMAGE_FEATURES = "read-only-rootfs"
8066 </literallayout>
8067 or
8068 <literallayout class='monospaced'>
8069 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
8070 </literallayout>
8071 </para>
8072
8073 <para>
8074 For more information on how to use these variables, see the
8075 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
8076 section.
8077 For information on the variables, see
8078 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
8079 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
8080 </para>
8081 </section>
8082
8083 <section id='post-installation-scripts'>
8084 <title>Post-Installation Scripts</title>
8085
8086 <para>
8087 It is very important that you make sure all
8088 post-Installation (<filename>pkg_postinst</filename>) scripts
8089 for packages that are installed into the image can be run
8090 at the time when the root filesystem is created during the
8091 build on the host system.
8092 These scripts cannot attempt to run during first-boot on the
8093 target device.
8094 With the "read-only-rootfs" feature enabled,
8095 the build system checks during root filesystem creation to make
8096 sure all post-installation scripts succeed.
8097 If any of these scripts still need to be run after the root
8098 filesystem is created, the build immediately fails.
8099 These build-time checks ensure that the build fails
8100 rather than the target device fails later during its
8101 initial boot operation.
8102 </para>
8103
8104 <para>
8105 Most of the common post-installation scripts generated by the
8106 build system for the out-of-the-box Yocto Project are engineered
8107 so that they can run during root filesystem creation
8108 (e.g. post-installation scripts for caching fonts).
8109 However, if you create and add custom scripts, you need
8110 to be sure they can be run during this file system creation.
8111 </para>
8112
8113 <para>
8114 Here are some common problems that prevent
8115 post-installation scripts from running during root filesystem
8116 creation:
8117 <itemizedlist>
8118 <listitem><para>
8119 <emphasis>Not using $D in front of absolute
8120 paths:</emphasis>
8121 The build system defines
8122 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
8123 when the root filesystem is created.
8124 Furthermore, <filename>$D</filename> is blank when the
8125 script is run on the target device.
8126 This implies two purposes for <filename>$D</filename>:
8127 ensuring paths are valid in both the host and target
8128 environments, and checking to determine which
8129 environment is being used as a method for taking
8130 appropriate actions.
8131 </para></listitem>
8132 <listitem><para>
8133 <emphasis>Attempting to run processes that are
8134 specific to or dependent on the target
8135 architecture:</emphasis>
8136 You can work around these attempts by using native
8137 tools to accomplish the same tasks, or
8138 by alternatively running the processes under QEMU,
8139 which has the <filename>qemu_run_binary</filename>
8140 function.
8141 For more information, see the
8142 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
8143 class.</para></listitem>
8144 </itemizedlist>
8145 </para>
8146 </section>
8147
8148 <section id='areas-with-write-access'>
8149 <title>Areas With Write Access</title>
8150
8151 <para>
8152 With the "read-only-rootfs" feature enabled,
8153 any attempt by the target to write to the root filesystem at
8154 runtime fails.
8155 Consequently, you must make sure that you configure processes
8156 and applications that attempt these types of writes do so
8157 to directories with write access (e.g.
8158 <filename>/tmp</filename> or <filename>/var/run</filename>).
8159 </para>
8160 </section>
8161 </section>
8162
8163 <section id="performing-automated-runtime-testing">
8164 <title>Performing Automated Runtime Testing</title>
8165
8166 <para>
8167 The OpenEmbedded build system makes available a series of automated
8168 tests for images to verify runtime functionality.
8169 You can run these tests on either QEMU or actual target hardware.
8170 Tests are written in Python making use of the
8171 <filename>unittest</filename> module, and the majority of them
8172 run commands on the target system over SSH.
8173 This section describes how you set up the environment to use these
8174 tests, run available tests, and write and add your own tests.
8175 </para>
8176
8177 <section id='enabling-tests'>
8178 <title>Enabling Tests</title>
8179
8180 <para>
8181 Depending on whether you are planning to run tests using
8182 QEMU or on the hardware, you have to take
8183 different steps to enable the tests.
8184 See the following subsections for information on how to
8185 enable both types of tests.
8186 </para>
8187
8188 <section id='qemu-image-enabling-tests'>
8189 <title>Enabling Runtime Tests on QEMU</title>
8190
8191 <para>
8192 In order to run tests, you need to do the following:
8193 <itemizedlist>
8194 <listitem><para><emphasis>Set up to avoid interaction
8195 with <filename>sudo</filename> for networking:</emphasis>
8196 To accomplish this, you must do one of the
8197 following:
8198 <itemizedlist>
8199 <listitem><para>Add
8200 <filename>NOPASSWD</filename> for your user
8201 in <filename>/etc/sudoers</filename> either for
8202 all commands or just for
8203 <filename>runqemu-ifup</filename>.
8204 You must provide the full path as that can
8205 change if you are using multiple clones of the
8206 source repository.
8207 <note>
8208 On some distributions, you also need to
8209 comment out "Defaults requiretty" in
8210 <filename>/etc/sudoers</filename>.
8211 </note></para></listitem>
8212 <listitem><para>Manually configure a tap interface
8213 for your system.</para></listitem>
8214 <listitem><para>Run as root the script in
8215 <filename>scripts/runqemu-gen-tapdevs</filename>,
8216 which should generate a list of tap devices.
8217 This is the option typically chosen for
8218 Autobuilder-type environments.
8219 </para></listitem>
8220 </itemizedlist></para></listitem>
8221 <listitem><para><emphasis>Set the
8222 <filename>DISPLAY</filename> variable:</emphasis>
8223 You need to set this variable so that you have an X
8224 server available (e.g. start
8225 <filename>vncserver</filename> for a headless machine).
8226 </para></listitem>
8227 <listitem><para><emphasis>Be sure your host's firewall
8228 accepts incoming connections from
8229 192.168.7.0/24:</emphasis>
8230 Some of the tests (in particular smart tests) start an
8231 HTTP server on a random high number port, which is
8232 used to serve files to the target.
8233 The smart module serves
8234 <filename>${DEPLOY_DIR}/rpm</filename> so it can run
8235 smart channel commands. That means your host's firewall
8236 must accept incoming connections from 192.168.7.0/24,
8237 which is the default IP range used for tap devices
8238 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05008239 <listitem><para><emphasis>Be sure your host has the
8240 correct packages installed:</emphasis>
8241 Depending your host's distribution, you need
8242 to have the following packages installed:
8243 <itemizedlist>
8244 <listitem><para>Ubuntu and Debian:
8245 <filename>sysstat</filename> and
8246 <filename>iproute2</filename>
8247 </para></listitem>
8248 <listitem><para>OpenSUSE:
8249 <filename>sysstat</filename> and
8250 <filename>iproute2</filename>
8251 </para></listitem>
8252 <listitem><para>Fedora:
8253 <filename>sysstat</filename> and
8254 <filename>iproute</filename>
8255 </para></listitem>
8256 <listitem><para>CentOS:
8257 <filename>sysstat</filename> and
8258 <filename>iproute</filename>
8259 </para></listitem>
8260 </itemizedlist>
8261 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008262 </itemizedlist>
8263 </para>
8264
8265 <para>
8266 Once you start running the tests, the following happens:
8267 <orderedlist>
8268 <listitem><para>A copy of the root filesystem is written
8269 to <filename>${WORKDIR}/testimage</filename>.
8270 </para></listitem>
8271 <listitem><para>The image is booted under QEMU using the
8272 standard <filename>runqemu</filename> script.
8273 </para></listitem>
8274 <listitem><para>A default timeout of 500 seconds occurs
8275 to allow for the boot process to reach the login prompt.
8276 You can change the timeout period by setting
8277 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
8278 in the <filename>local.conf</filename> file.
8279 </para></listitem>
8280 <listitem><para>Once the boot process is reached and the
8281 login prompt appears, the tests run.
8282 The full boot log is written to
8283 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
8284 </para></listitem>
8285 <listitem><para>Each test module loads in the order found
8286 in <filename>TEST_SUITES</filename>.
8287 You can find the full output of the commands run over
8288 SSH in
8289 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
8290 </para></listitem>
8291 <listitem><para>If no failures occur, the task running the
8292 tests ends successfully.
8293 You can find the output from the
8294 <filename>unittest</filename> in the task log at
8295 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
8296 </para></listitem>
8297 </orderedlist>
8298 </para>
8299 </section>
8300
8301 <section id='hardware-image-enabling-tests'>
8302 <title>Enabling Runtime Tests on Hardware</title>
8303
8304 <para>
8305 The OpenEmbedded build system can run tests on real
8306 hardware, and for certain devices it can also deploy
8307 the image to be tested onto the device beforehand.
8308 </para>
8309
8310 <para>
8311 For automated deployment, a "master image" is installed
8312 onto the hardware once as part of setup.
8313 Then, each time tests are to be run, the following
8314 occurs:
8315 <orderedlist>
8316 <listitem><para>The master image is booted into and
8317 used to write the image to be tested to
8318 a second partition.
8319 </para></listitem>
8320 <listitem><para>The device is then rebooted using an
8321 external script that you need to provide.
8322 </para></listitem>
8323 <listitem><para>The device boots into the image to be
8324 tested.
8325 </para></listitem>
8326 </orderedlist>
8327 </para>
8328
8329 <para>
8330 When running tests (independent of whether the image
8331 has been deployed automatically or not), the device is
8332 expected to be connected to a network on a
8333 pre-determined IP address.
8334 You can either use static IP addresses written into
8335 the image, or set the image to use DHCP and have your
8336 DHCP server on the test network assign a known IP address
8337 based on the MAC address of the device.
8338 </para>
8339
8340 <para>
8341 In order to run tests on hardware, you need to set
8342 <filename>TEST_TARGET</filename> to an appropriate value.
8343 For QEMU, you do not have to change anything, the default
8344 value is "QemuTarget".
8345 For running tests on hardware, the following options exist:
8346 <itemizedlist>
8347 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
8348 Choose "SimpleRemoteTarget" if you are going to
8349 run tests on a target system that is already
8350 running the image to be tested and is available
8351 on the network.
8352 You can use "SimpleRemoteTarget" in conjunction
8353 with either real hardware or an image running
8354 within a separately started QEMU or any
8355 other virtual machine manager.
8356 </para></listitem>
8357 <listitem><para><emphasis>"GummibootTarget":</emphasis>
8358 Choose "GummibootTarget" if your hardware is
8359 an EFI-based machine with
8360 <filename>gummiboot</filename> as bootloader and
8361 <filename>core-image-testmaster</filename>
8362 (or something similar) is installed.
8363 Also, your hardware under test must be in a
8364 DHCP-enabled network that gives it the same IP
8365 address for each reboot.</para>
8366 <para>If you choose "GummibootTarget", there are
8367 additional requirements and considerations.
8368 See the
8369 "<link linkend='selecting-gummiboottarget'>Selecting GummibootTarget</link>"
8370 section, which follows, for more information.
8371 </para></listitem>
8372 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
8373 Choose "BeagleBoneTarget" if you are deploying
8374 images and running tests on the BeagleBone
8375 "Black" or original "White" hardware.
8376 For information on how to use these tests, see the
8377 comments at the top of the BeagleBoneTarget
8378 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
8379 file.
8380 </para></listitem>
8381 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
8382 Choose "EdgeRouterTarget" is you are deploying
8383 images and running tests on the Ubiquiti Networks
8384 EdgeRouter Lite.
8385 For information on how to use these tests, see the
8386 comments at the top of the EdgeRouterTarget
8387 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
8388 file.
8389 </para></listitem>
8390 <listitem><para><emphasis>"GrubTarget":</emphasis>
8391 Choose the "supports deploying images and running
8392 tests on any generic PC that boots using GRUB.
8393 For information on how to use these tests, see the
8394 comments at the top of the GrubTarget
8395 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
8396 file.
8397 </para></listitem>
8398 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
8399 Create your own custom target if you want to run
8400 tests when you are deploying images and running
8401 tests on a custom machine within your BSP layer.
8402 To do this, you need to add a Python unit that
8403 defines the target class under
8404 <filename>lib/oeqa/controllers/</filename> within
8405 your layer.
8406 You must also provide an empty
8407 <filename>__init__.py</filename>.
8408 For examples, see files in
8409 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
8410 </para></listitem>
8411 </itemizedlist>
8412 </para>
8413 </section>
8414
8415 <section id='selecting-gummiboottarget'>
8416 <title>Selecting GummibootTarget</title>
8417
8418 <para>
8419 If you did not set <filename>TEST_TARGET</filename> to
8420 "GummibootTarget", then you do not need any information
8421 in this section.
8422 You can skip down to the
8423 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
8424 section.
8425 </para>
8426
8427 <para>
8428 If you did set <filename>TEST_TARGET</filename> to
8429 "GummibootTarget", you also need to perform a one-time
8430 setup of your master image by doing the following:
8431 <orderedlist>
8432 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
8433 Be sure that <filename>EFI_PROVIDER</filename>
8434 is as follows:
8435 <literallayout class='monospaced'>
8436 EFI_PROVIDER = "gummiboot"
8437 </literallayout>
8438 </para></listitem>
8439 <listitem><para><emphasis>Build the master image:</emphasis>
8440 Build the <filename>core-image-testmaster</filename>
8441 image.
8442 The <filename>core-image-testmaster</filename>
8443 recipe is provided as an example for a
8444 "master" image and you can customize the image
8445 recipe as you would any other recipe.
8446 </para>
8447 <para>Here are the image recipe requirements:
8448 <itemizedlist>
8449 <listitem><para>Inherits
8450 <filename>core-image</filename>
8451 so that kernel modules are installed.
8452 </para></listitem>
8453 <listitem><para>Installs normal linux utilities
8454 not busybox ones (e.g.
8455 <filename>bash</filename>,
8456 <filename>coreutils</filename>,
8457 <filename>tar</filename>,
8458 <filename>gzip</filename>, and
8459 <filename>kmod</filename>).
8460 </para></listitem>
8461 <listitem><para>Uses a custom
8462 Initial RAM Disk (initramfs) image with a
8463 custom installer.
8464 A normal image that you can install usually
8465 creates a single rootfs partition.
8466 This image uses another installer that
8467 creates a specific partition layout.
8468 Not all Board Support Packages (BSPs)
8469 can use an installer.
8470 For such cases, you need to manually create
8471 the following partition layout on the
8472 target:
8473 <itemizedlist>
8474 <listitem><para>First partition mounted
8475 under <filename>/boot</filename>,
8476 labeled "boot".
8477 </para></listitem>
8478 <listitem><para>The main rootfs
8479 partition where this image gets
8480 installed, which is mounted under
8481 <filename>/</filename>.
8482 </para></listitem>
8483 <listitem><para>Another partition
8484 labeled "testrootfs" where test
8485 images get deployed.
8486 </para></listitem>
8487 </itemizedlist>
8488 </para></listitem>
8489 </itemizedlist>
8490 </para></listitem>
8491 <listitem><para><emphasis>Install image:</emphasis>
8492 Install the image that you just built on the target
8493 system.
8494 </para></listitem>
8495 </orderedlist>
8496 </para>
8497
8498 <para>
8499 The final thing you need to do when setting
8500 <filename>TEST_TARGET</filename> to "GummibootTarget" is
8501 to set up the test image:
8502 <orderedlist>
8503 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
8504 Make sure you have the following statements in
8505 your <filename>local.conf</filename> file:
8506 <literallayout class='monospaced'>
8507 IMAGE_FSTYPES += "tar.gz"
8508 INHERIT += "testimage"
8509 TEST_TARGET = "GummibootTarget"
8510 TEST_TARGET_IP = "192.168.2.3"
8511 </literallayout>
8512 </para></listitem>
8513 <listitem><para><emphasis>Build your test image:</emphasis>
8514 Use BitBake to build the image:
8515 <literallayout class='monospaced'>
8516 $ bitbake core-image-sato
8517 </literallayout>
8518 </para></listitem>
8519 </orderedlist>
8520 </para>
8521 </section>
8522
8523 <section id='power-control'>
8524 <title>Power Control</title>
8525
8526 <para>
8527 For most hardware targets other than SimpleRemoteTarget,
8528 you can control power:
8529 <itemizedlist>
8530 <listitem><para>
8531 You can use
8532 <filename>TEST_POWERCONTROL_CMD</filename>
8533 together with
8534 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
8535 as a command that runs on the host and does power
8536 cycling.
8537 The test code passes one argument to that command:
8538 off, on or cycle (off then on).
8539 Here is an example that could appear in your
8540 <filename>local.conf</filename> file:
8541 <literallayout class='monospaced'>
8542 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8543 </literallayout>
8544 In this example, the expect script does the
8545 following:
8546 <literallayout class='monospaced'>
8547 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
8548 </literallayout>
8549 It then runs a Python script that controls power
8550 for a label called <filename>nuc1</filename>.
8551 <note>
8552 You need to customize
8553 <filename>TEST_POWERCONTROL_CMD</filename>
8554 and
8555 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
8556 for your own setup.
8557 The one requirement is that it accepts
8558 "on", "off", and "cycle" as the last argument.
8559 </note>
8560 </para></listitem>
8561 <listitem><para>
8562 When no command is defined, it connects to the
8563 device over SSH and uses the classic reboot command
8564 to reboot the device.
8565 Classic reboot is fine as long as the machine
8566 actually reboots (i.e. the SSH test has not
8567 failed).
8568 It is useful for scenarios where you have a simple
8569 setup, typically with a single board, and where
8570 some manual interaction is okay from time to time.
8571 </para></listitem>
8572 </itemizedlist>
8573 If you have no hardware to automatically perform power
8574 control but still wish to experiment with automated
8575 hardware testing, you can use the dialog-power-control
8576 script that shows a dialog prompting you to perform the
8577 required power action.
8578 This script requires either KDialog or Zenity to be
8579 installed.
8580 To use this script, set the
8581 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
8582 variable as follows:
8583 <literallayout class='monospaced'>
8584 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8585 </literallayout>
8586 </para>
8587 </section>
8588
8589 <section id='serial-console-connection'>
8590 <title>Serial Console Connection</title>
8591
8592 <para>
8593 For test target classes requiring a serial console
8594 to interact with the bootloader (e.g. BeagleBoneTarget,
8595 EdgeRouterTarget, and GrubTarget), you need to
8596 specify a command to use to connect to the serial console
8597 of the target machine by using the
8598 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
8599 variable and optionally the
8600 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
8601 variable.
8602 </para>
8603
8604 <para>
8605 These cases could be a serial terminal program if the
8606 machine is connected to a local serial port, or a
8607 <filename>telnet</filename> or
8608 <filename>ssh</filename> command connecting to a remote
8609 console server.
8610 Regardless of the case, the command simply needs to
8611 connect to the serial console and forward that connection
8612 to standard input and output as any normal terminal
8613 program does.
8614 For example, to use the picocom terminal program on
8615 serial device <filename>/dev/ttyUSB0</filename>
8616 at 115200bps, you would set the variable as follows:
8617 <literallayout class='monospaced'>
8618 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8619 </literallayout>
8620 For local devices where the serial port device disappears
8621 when the device reboots, an additional "serdevtry" wrapper
8622 script is provided.
8623 To use this wrapper, simply prefix the terminal command
8624 with
8625 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
8626 <literallayout class='monospaced'>
8627 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
8628115200 /dev/ttyUSB0"
8629 </literallayout>
8630 </para>
8631 </section>
8632 </section>
8633
8634 <section id="qemu-image-running-tests">
8635 <title>Running Tests</title>
8636
8637 <para>
8638 You can start the tests automatically or manually:
8639 <itemizedlist>
8640 <listitem><para><emphasis>Automatically running tests:</emphasis>
8641 To run the tests automatically after the
8642 OpenEmbedded build system successfully creates an image,
8643 first set the
8644 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_IMAGE'><filename>TEST_IMAGE</filename></ulink>
8645 variable to "1" in your <filename>local.conf</filename>
8646 file in the
8647 <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>:
8648 <literallayout class='monospaced'>
8649 TEST_IMAGE = "1"
8650 </literallayout>
8651 Next, build your image.
8652 If the image successfully builds, the tests will be
8653 run:
8654 <literallayout class='monospaced'>
8655 bitbake core-image-sato
8656 </literallayout></para></listitem>
8657 <listitem><para><emphasis>Manually running tests:</emphasis>
8658 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -05008659 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008660 class by editing your <filename>local.conf</filename>
8661 file:
8662 <literallayout class='monospaced'>
8663 INHERIT += "testimage"
8664 </literallayout>
8665 Next, use BitBake to run the tests:
8666 <literallayout class='monospaced'>
8667 bitbake -c testimage <replaceable>image</replaceable>
8668 </literallayout></para></listitem>
8669 </itemizedlist>
8670 </para>
8671
8672 <para>
8673 All test files reside in
8674 <filename>meta/lib/oeqa/runtime</filename> in the
8675 <link linkend='source-directory'>Source Directory</link>.
8676 A test name maps directly to a Python module.
8677 Each test module may contain a number of individual tests.
8678 Tests are usually grouped together by the area
8679 tested (e.g tests for systemd reside in
8680 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
8681 </para>
8682
8683 <para>
8684 You can add tests to any layer provided you place them in the
8685 proper area and you extend
8686 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
8687 in the <filename>local.conf</filename> file as normal.
8688 Be sure that tests reside in
8689 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
8690 <note>
8691 Be sure that module names do not collide with module names
8692 used in the default set of test modules in
8693 <filename>meta/lib/oeqa/runtime</filename>.
8694 </note>
8695 </para>
8696
8697 <para>
8698 You can change the set of tests run by appending or overriding
8699 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
8700 variable in <filename>local.conf</filename>.
8701 Each name in <filename>TEST_SUITES</filename> represents a
8702 required test for the image.
8703 Test modules named within <filename>TEST_SUITES</filename>
8704 cannot be skipped even if a test is not suitable for an image
8705 (e.g. running the RPM tests on an image without
8706 <filename>rpm</filename>).
8707 Appending "auto" to <filename>TEST_SUITES</filename> causes the
8708 build system to try to run all tests that are suitable for the
8709 image (i.e. each test module may elect to skip itself).
8710 </para>
8711
8712 <para>
8713 The order you list tests in <filename>TEST_SUITES</filename>
8714 is important and influences test dependencies.
8715 Consequently, tests that depend on other tests should be added
8716 after the test on which they depend.
8717 For example, since the <filename>ssh</filename> test
8718 depends on the
8719 <filename>ping</filename> test, "ssh" needs to come after
8720 "ping" in the list.
8721 The test class provides no re-ordering or dependency handling.
8722 <note>
8723 Each module can have multiple classes with multiple test
8724 methods.
8725 And, Python <filename>unittest</filename> rules apply.
8726 </note>
8727 </para>
8728
8729 <para>
8730 Here are some things to keep in mind when running tests:
8731 <itemizedlist>
8732 <listitem><para>The default tests for the image are defined
8733 as:
8734 <literallayout class='monospaced'>
8735 DEFAULT_TEST_SUITES_pn-<replaceable>image</replaceable> = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg"
8736 </literallayout></para></listitem>
8737 <listitem><para>Add your own test to the list of the
8738 by using the following:
8739 <literallayout class='monospaced'>
8740 TEST_SUITES_append = " mytest"
8741 </literallayout></para></listitem>
8742 <listitem><para>Run a specific list of tests as follows:
8743 <literallayout class='monospaced'>
8744 TEST_SUITES = "test1 test2 test3"
8745 </literallayout>
8746 Remember, order is important.
8747 Be sure to place a test that is dependent on another test
8748 later in the order.</para></listitem>
8749 </itemizedlist>
8750 </para>
8751 </section>
8752
8753 <section id="exporting-tests">
8754 <title>Exporting Tests</title>
8755
8756 <para>
8757 You can export tests so that they can run independently of
8758 the build system.
8759 Exporting tests is required if you want to be able to hand
8760 the test execution off to a scheduler.
8761 You can only export tests that are defined in
8762 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
8763 </para>
8764
8765 <para>
8766 If your image is already built, make sure the following are set
8767 in your <filename>local.conf</filename> file.
8768 Be sure to provide the IP address you need:
8769 <literallayout class='monospaced'>
8770 TEST_EXPORT_ONLY = "1"
8771 TEST_TARGET = "simpleremote"
8772 TEST_TARGET_IP = "192.168.7.2"
8773 TEST_SERVER_IP = "192.168.7.1"
8774 </literallayout>
8775 You can then export the tests with the following:
8776 <literallayout class='monospaced'>
8777 $ bitbake core-image-sato -c testimage
8778 </literallayout>
8779 Exporting the tests places them in the
8780 <link linkend='build-directory'>Build Directory</link> in
8781 <filename>tmp/testimage/core-image-sato</filename>, which
8782 is controlled by the
8783 <filename>TEST_EXPORT_DIR</filename> variable.
8784 </para>
8785
8786 <para>
8787 You can now run the tests outside of the build environment:
8788 <literallayout class='monospaced'>
8789 $ cd tmp/testimage/core-image-sato
8790 $ ./runexported.py testdata.json
8791 </literallayout>
8792 <note>
8793 This "export" feature does not deploy or boot the target
8794 image.
8795 Your target (be it a Qemu or hardware one)
8796 has to already be up and running when you call
8797 <filename>runexported.py</filename>
8798 </note>
8799 </para>
8800
8801 <para>
8802 The exported data (i.e. <filename>testdata.json</filename>)
8803 contains paths to the Build Directory.
8804 Thus, the contents of the directory can be moved
8805 to another machine as long as you update some paths in the
8806 JSON.
8807 Usually, you only care about the
8808 <filename>${DEPLOY_DIR}/rpm</filename> directory
8809 (assuming the RPM and Smart tests are enabled).
8810 Consequently, running the tests on other machine
8811 means that you have to move the contents and call
8812 <filename>runexported.py</filename> with
8813 "--deploy-dir <replaceable>path</replaceable>" as
8814 follows:
8815 <literallayout class='monospaced'>
8816 ./runexported.py --deploy-dir /new/path/on/this/machine testdata.json
8817 </literallayout>
8818 <filename>runexported.py</filename> accepts other arguments
8819 as well as described using <filename>--help</filename>.
8820 </para>
8821 </section>
8822
8823 <section id="qemu-image-writing-new-tests">
8824 <title>Writing New Tests</title>
8825
8826 <para>
8827 As mentioned previously, all new test files need to be in the
8828 proper place for the build system to find them.
8829 New tests for additional functionality outside of the core
8830 should be added to the layer that adds the functionality, in
8831 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
8832 (as long as
8833 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
8834 is extended in the layer's
8835 <filename>layer.conf</filename> file as normal).
8836 Just remember the following:
8837 <itemizedlist>
8838 <listitem><para>Filenames need to map directly to test
8839 (module) names.
8840 </para></listitem>
8841 <listitem><para>Do not use module names that
8842 collide with existing core tests.
8843 </para></listitem>
8844 <listitem><para>Minimally, an empty
8845 <filename>__init__.py</filename> file must exist
8846 in the runtime directory.
8847 </para></listitem>
8848 </itemizedlist>
8849 </para>
8850
8851 <para>
8852 To create a new test, start by copying an existing module
8853 (e.g. <filename>syslog.py</filename> or
8854 <filename>gcc.py</filename> are good ones to use).
8855 Test modules can use code from
8856 <filename>meta/lib/oeqa/utils</filename>, which are helper
8857 classes.
8858 </para>
8859
8860 <note>
8861 Structure shell commands such that you rely on them and they
8862 return a single code for success.
8863 Be aware that sometimes you will need to parse the output.
8864 See the <filename>df.py</filename> and
8865 <filename>date.py</filename> modules for examples.
8866 </note>
8867
8868 <para>
8869 You will notice that all test classes inherit
8870 <filename>oeRuntimeTest</filename>, which is found in
8871 <filename>meta/lib/oetest.py</filename>.
8872 This base class offers some helper attributes, which are
8873 described in the following sections:
8874 </para>
8875
8876 <section id='qemu-image-writing-tests-class-methods'>
8877 <title>Class Methods</title>
8878
8879 <para>
8880 Class methods are as follows:
8881 <itemizedlist>
8882 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
8883 Returns "True" if <filename>pkg</filename> is in the
8884 installed package list of the image, which is based
8885 on the manifest file that is generated during the
8886 <filename>do_rootfs</filename> task.
8887 </para></listitem>
8888 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
8889 Returns "True" if the feature is in
8890 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
8891 or
8892 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
8893 </para></listitem>
8894 </itemizedlist>
8895 </para>
8896 </section>
8897
8898 <section id='qemu-image-writing-tests-class-attributes'>
8899 <title>Class Attributes</title>
8900
8901 <para>
8902 Class attributes are as follows:
8903 <itemizedlist>
8904 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
8905 Equals "ps -ef" if <filename>procps</filename> is
8906 installed in the image.
8907 Otherwise, <filename>pscmd</filename> equals
8908 "ps" (busybox).
8909 </para></listitem>
8910 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
8911 The called test context, which gives access to the
8912 following attributes:
8913 <itemizedlist>
8914 <listitem><para><emphasis><filename>d</filename>:</emphasis>
8915 The BitBake datastore, which allows you to
8916 use stuff such as
8917 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
8918 </para></listitem>
8919 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
8920 Used internally.
8921 The tests do not need these.
8922 </para></listitem>
8923 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
8924 The absolute path to
8925 <filename>meta/lib/oeqa/runtime/files</filename>,
8926 which contains helper files for tests meant
8927 for copying on the target such as small
8928 files written in C for compilation.
8929 </para></listitem>
8930 <listitem><para><emphasis><filename>target</filename>:</emphasis>
8931 The target controller object used to deploy
8932 and start an image on a particular target
8933 (e.g. QemuTarget, SimpleRemote, and
8934 GummibootTarget).
8935 Tests usually use the following:
8936 <itemizedlist>
8937 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
8938 The target's IP address.
8939 </para></listitem>
8940 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
8941 The host's IP address, which is
8942 usually used by the "smart" test
8943 suite.
8944 </para></listitem>
8945 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
8946 The single, most used method.
8947 This command is a wrapper for:
8948 <filename>ssh root@host "cmd"</filename>.
8949 The command returns a tuple:
8950 (status, output), which are what
8951 their names imply - the return code
8952 of "cmd" and whatever output
8953 it produces.
8954 The optional timeout argument
8955 represents the number of seconds the
8956 test should wait for "cmd" to
8957 return.
8958 If the argument is "None", the
8959 test uses the default instance's
8960 timeout period, which is 300
8961 seconds.
8962 If the argument is "0", the test
8963 runs until the command returns.
8964 </para></listitem>
8965 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
8966 <filename>scp localpath root@ip:remotepath</filename>.
8967 </para></listitem>
8968 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
8969 <filename>scp root@host:remotepath localpath</filename>.
8970 </para></listitem>
8971 </itemizedlist></para></listitem>
8972 </itemizedlist></para></listitem>
8973 </itemizedlist>
8974 </para>
8975 </section>
8976
8977 <section id='qemu-image-writing-tests-instance-attributes'>
8978 <title>Instance Attributes</title>
8979
8980 <para>
8981 A single instance attribute exists, which is
8982 <filename>target</filename>.
8983 The <filename>target</filename> instance attribute is
8984 identical to the class attribute of the same name, which
8985 is described in the previous section.
8986 This attribute exists as both an instance and class
8987 attribute so tests can use
8988 <filename>self.target.run(cmd)</filename> in instance
8989 methods instead of
8990 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
8991 </para>
8992 </section>
8993 </section>
8994 </section>
8995
8996 <section id="platdev-gdb-remotedebug">
8997 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
8998
8999 <para>
9000 GDB allows you to examine running programs, which in turn helps you to understand and fix problems.
9001 It also allows you to perform post-mortem style analysis of program crashes.
9002 GDB is available as a package within the Yocto Project and is
9003 installed in SDK images by default.
9004 See the "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" chapter
9005 in the Yocto Project Reference Manual for a description of these images.
9006 You can find information on GDB at <ulink url="http://sourceware.org/gdb/"/>.
9007 </para>
9008
9009 <tip>
9010 For best results, install debug (<filename>-dbg</filename>) packages
9011 for the applications you are going to debug.
9012 Doing so makes extra debug symbols available that give you more
9013 meaningful output.
9014 </tip>
9015
9016 <para>
9017 Sometimes, due to memory or disk space constraints, it is not possible
9018 to use GDB directly on the remote target to debug applications.
9019 These constraints arise because GDB needs to load the debugging information and the
9020 binaries of the process being debugged.
9021 Additionally, GDB needs to perform many computations to locate information such as function
9022 names, variable names and values, stack traces and so forth - even before starting the
9023 debugging process.
9024 These extra computations place more load on the target system and can alter the
9025 characteristics of the program being debugged.
9026 </para>
9027
9028 <para>
9029 To help get past the previously mentioned constraints, you can use Gdbserver.
9030 Gdbserver runs on the remote target and does not load any debugging information
9031 from the debugged process.
9032 Instead, a GDB instance processes the debugging information that is run on a
9033 remote computer - the host GDB.
9034 The host GDB then sends control commands to Gdbserver to make it stop or start the debugged
9035 program, as well as read or write memory regions of that debugged program.
9036 All the debugging information loaded and processed as well
9037 as all the heavy debugging is done by the host GDB.
9038 Offloading these processes gives the Gdbserver running on the target a chance to remain
9039 small and fast.
9040 <note>
9041 By default, source files are part of the
9042 <filename>*-dbg</filename> packages in order to enable GDB
9043 to show source lines in its output.
9044 You can save further space on the target by setting the
9045 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_DEBUG_SPLIT_STYLE'><filename>PACKAGE_DEBUG_SPLIT_STYLE</filename></ulink>
9046 variable to "debug-without-src" so that these packages do not
9047 include the source files.
9048 </note>
9049 </para>
9050
9051 <para>
9052 Because the host GDB is responsible for loading the debugging information and
9053 for doing the necessary processing to make actual debugging happen,
9054 you have to make sure the host can access the unstripped binaries complete
9055 with their debugging information and also be sure the target is compiled with no optimizations.
9056 The host GDB must also have local access to all the libraries used by the
9057 debugged program.
9058 Because Gdbserver does not need any local debugging information, the binaries on
9059 the remote target can remain stripped.
9060 However, the binaries must also be compiled without optimization
9061 so they match the host's binaries.
9062 </para>
9063
9064 <para>
9065 To remain consistent with GDB documentation and terminology, the binary being debugged
9066 on the remote target machine is referred to as the "inferior" binary.
9067 For documentation on GDB see the
9068 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
9069 </para>
9070
9071 <para>
9072 The remainder of this section describes the steps you need to take
9073 to debug using the GNU project debugger.
9074 </para>
9075
9076 <section id='platdev-gdb-remotedebug-setup'>
9077 <title>Set Up the Cross-Development Debugging Environment</title>
9078
9079 <para>
9080 Before you can initiate a remote debugging session, you need
9081 to be sure you have set up the cross-development environment,
9082 toolchain, and sysroot.
9083 The "<ulink url='&YOCTO_DOCS_ADT_URL;#adt-prepare'>Preparing for Application Development</ulink>"
9084 chapter of the Yocto Project Application Developer's Guide
9085 describes this process.
9086 Be sure you have read that chapter and have set up
9087 your environment.
9088 </para>
9089 </section>
9090
9091 <section id="platdev-gdb-remotedebug-launch-gdbserver">
9092 <title>Launch Gdbserver on the Target</title>
9093
9094 <para>
9095 Make sure Gdbserver is installed on the target.
9096 If it is not, install the package
9097 <filename>gdbserver</filename>, which needs the
9098 <filename>libthread-db1</filename> package.
9099 </para>
9100
9101 <para>
9102 Here is an example, that when entered from the host,
9103 connects to the target and launches Gdbserver in order to
9104 "debug" a binary named <filename>helloworld</filename>:
9105 <literallayout class='monospaced'>
9106 $ gdbserver localhost:2345 /usr/bin/helloworld
9107 </literallayout>
9108 Gdbserver should now be listening on port 2345 for debugging
9109 commands coming from a remote GDB process that is running on
9110 the host computer.
9111 Communication between Gdbserver and the host GDB are done
9112 using TCP.
9113 To use other communication protocols, please refer to the
9114 <ulink url='http://www.gnu.org/software/gdb/'>Gdbserver documentation</ulink>.
9115 </para>
9116 </section>
9117
9118 <section id="platdev-gdb-remotedebug-launch-gdb">
9119 <title>Launch GDB on the Host Computer</title>
9120
9121 <para>
9122 Running GDB on the host computer takes a number of stages, which
9123 this section describes.
9124 </para>
9125
9126 <section id="platdev-gdb-remotedebug-launch-gdb-buildcross">
9127 <title>Build the Cross-GDB Package</title>
9128 <para>
9129 A suitable GDB cross-binary is required that runs on your
9130 host computer but also knows about the the ABI of the
9131 remote target.
9132 You can get this binary from the
9133 <link linkend='cross-development-toolchain'>Cross-Development Toolchain</link>.
9134 Here is an example where the toolchain has been installed
9135 in the default directory
9136 <filename>/opt/poky/&DISTRO;</filename>:
9137 <literallayout class='monospaced'>
9138 /opt/poky/&DISTRO;/sysroots/i686-pokysdk-linux/usr/bin/armv7a-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb
9139 </literallayout>
9140 where <filename>arm</filename> is the target architecture
9141 and <filename>linux-gnueabi</filename> is the target ABI.
9142 </para>
9143
9144 <para>
9145 Alternatively, you can use BitBake to build the
9146 <filename>gdb-cross</filename> binary.
9147 Here is an example:
9148 <literallayout class='monospaced'>
9149 $ bitbake gdb-cross
9150 </literallayout>
9151 Once the binary is built, you can find it here:
9152 <literallayout class='monospaced'>
9153 tmp/sysroots/<replaceable>host-arch</replaceable>/usr/bin/<replaceable>target-platform</replaceable>/<replaceable>target-abi</replaceable>-gdb
9154 </literallayout>
9155 </para>
9156 </section>
9157
9158 <section id='create-the-gdb-initialization-file'>
9159 <title>Create the GDB Initialization File and Point to Your Root Filesystem</title>
9160
9161 <para>
9162 Aside from the GDB cross-binary, you also need a GDB
9163 initialization file in the same top directory in which
9164 your binary resides.
9165 When you start GDB on your host development system, GDB
9166 finds this initialization file and executes all the
9167 commands within.
9168 For information on the <filename>.gdbinit</filename>, see
9169 "<ulink url='http://sourceware.org/gdb/onlinedocs/gdb/'>Debugging with GDB</ulink>",
9170 which is maintained by
9171 <ulink url='http://www.sourceware.org'>sourceware.org</ulink>.
9172 </para>
9173
9174 <para>
9175 You need to add a statement in the
9176 <filename>~/.gdbinit</filename> file that points to your
9177 root filesystem.
9178 Here is an example that points to the root filesystem for
9179 an ARM-based target device:
9180 <literallayout class='monospaced'>
9181 set sysroot ~/sysroot_arm
9182 </literallayout>
9183 </para>
9184 </section>
9185
9186 <section id="platdev-gdb-remotedebug-launch-gdb-launchhost">
9187 <title>Launch the Host GDB</title>
9188
9189 <para>
9190 Before launching the host GDB, you need to be sure
9191 you have sourced the cross-debugging environment script,
9192 which if you installed the root filesystem in the default
9193 location is at <filename>/opt/poky/&DISTRO;</filename>
9194 and begins with the string "environment-setup".
9195 For more information, see the
9196 "<ulink url='&YOCTO_DOCS_ADT_URL;#setting-up-the-cross-development-environment'>Setting Up the Cross-Development Environment</ulink>"
9197 section in the Yocto Project Application Developer's
9198 Guide.
9199 </para>
9200
9201 <para>
9202 Finally, switch to the directory where the binary resides
9203 and run the <filename>cross-gdb</filename> binary.
9204 Provide the binary file you are going to debug.
9205 For example, the following command continues with the
9206 example used in the previous section by loading
9207 the <filename>helloworld</filename> binary as well as the
9208 debugging information:
9209 <literallayout class='monospaced'>
9210 $ arm-poky-linux-gnuabi-gdb helloworld
9211 </literallayout>
9212 The commands in your <filename>.gdbinit</filename> execute
9213 and the GDB prompt appears.
9214 </para>
9215 </section>
9216 </section>
9217
9218 <section id='platdev-gdb-connect-to-the-remote-gdb-server'>
9219 <title>Connect to the Remote GDB Server</title>
9220
9221 <para>
9222 From the target, you need to connect to the remote GDB
9223 server that is running on the host.
9224 You need to specify the remote host and port.
9225 Here is the command continuing with the example:
9226 <literallayout class='monospaced'>
9227 target remote 192.168.7.2:2345
9228 </literallayout>
9229 </para>
9230 </section>
9231
9232 <section id="platdev-gdb-remotedebug-launch-gdb-using">
9233 <title>Use the Debugger</title>
9234
9235 <para>
9236 You can now proceed with debugging as normal - as if you were debugging
9237 on the local machine.
9238 For example, to instruct GDB to break in the "main" function and then
9239 continue with execution of the inferior binary use the following commands
9240 from within GDB:
9241 <literallayout class='monospaced'>
9242 (gdb) break main
9243 (gdb) continue
9244 </literallayout>
9245 </para>
9246
9247 <para>
9248 For more information about using GDB, see the project's online documentation at
9249 <ulink url="http://sourceware.org/gdb/download/onlinedocs/"/>.
9250 </para>
9251 </section>
9252 </section>
9253
9254 <section id='debugging-parallel-make-races'>
9255 <title>Debugging Parallel Make Races</title>
9256
9257 <para>
9258 A parallel <filename>make</filename> race occurs when the build
9259 consists of several parts that are run simultaneously and
9260 a situation occurs when the output or result of one
9261 part is not ready for use with a different part of the build that
9262 depends on that output.
9263 Parallel make races are annoying and can sometimes be difficult
9264 to reproduce and fix.
9265 However, some simple tips and tricks exist that can help
9266 you debug and fix them.
9267 This section presents a real-world example of an error encountered
9268 on the Yocto Project autobuilder and the process used to fix it.
9269 <note>
9270 If you cannot properly fix a <filename>make</filename> race
9271 condition, you can work around it by clearing either the
9272 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
9273 or
9274 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
9275 variables.
9276 </note>
9277 </para>
9278
9279 <section id='the-failure'>
9280 <title>The Failure</title>
9281
9282 <para>
9283 For this example, assume that you are building an image that
9284 depends on the "neard" package.
9285 And, during the build, BitBake runs into problems and
9286 creates the following output.
9287 <note>
9288 This example log file has longer lines artificially
9289 broken to make the listing easier to read.
9290 </note>
9291 If you examine the output or the log file, you see the
9292 failure during <filename>make</filename>:
9293 <literallayout class='monospaced'>
9294 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9295 | DEBUG: Executing shell function do_compile
9296 | NOTE: make -j 16
9297 | make --no-print-directory all-am
9298 | /bin/mkdir -p include/near
9299 | /bin/mkdir -p include/near
9300 | /bin/mkdir -p include/near
9301 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9302 0.14-r0/neard-0.14/include/types.h include/near/types.h
9303 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9304 0.14-r0/neard-0.14/include/log.h include/near/log.h
9305 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9306 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
9307 | /bin/mkdir -p include/near
9308 | /bin/mkdir -p include/near
9309 | /bin/mkdir -p include/near
9310 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9311 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
9312 | /bin/mkdir -p include/near
9313 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9314 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9315 | /bin/mkdir -p include/near
9316 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9317 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
9318 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9319 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
9320 | /bin/mkdir -p include/near
9321 | /bin/mkdir -p include/near
9322 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9323 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9324 | /bin/mkdir -p include/near
9325 | /bin/mkdir -p include/near
9326 | /bin/mkdir -p include/near
9327 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9328 0.14-r0/neard-0.14/include/device.h include/near/device.h
9329 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9330 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
9331 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9332 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
9333 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9334 0.14-r0/neard-0.14/include/version.h include/near/version.h
9335 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9336 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
9337 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
9338 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
9339 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
9340 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9341 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9342 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
9343 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
9344 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
9345 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
9346 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9347 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9348 -o tools/snep-send.o tools/snep-send.c
9349 | In file included from tools/snep-send.c:16:0:
9350 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9351 | #include &lt;near/dbus.h&gt;
9352 | ^
9353 | compilation terminated.
9354 | make[1]: *** [tools/snep-send.o] Error 1
9355 | make[1]: *** Waiting for unfinished jobs....
9356 | make: *** [all] Error 2
9357 | ERROR: oe_runmake failed
9358 </literallayout>
9359 </para>
9360 </section>
9361
9362 <section id='reproducing-the-error'>
9363 <title>Reproducing the Error</title>
9364
9365 <para>
9366 Because race conditions are intermittent, they do not
9367 manifest themselves every time you do the build.
9368 In fact, most times the build will complete without problems
9369 even though the potential race condition exists.
9370 Thus, once the error surfaces, you need a way to reproduce it.
9371 </para>
9372
9373 <para>
9374 In this example, compiling the "neard" package is causing the
9375 problem.
9376 So the first thing to do is build "neard" locally.
9377 Before you start the build, set the
9378 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
9379 variable in your <filename>local.conf</filename> file to
9380 a high number (e.g. "-j 20").
9381 Using a high value for <filename>PARALLEL_MAKE</filename>
9382 increases the chances of the race condition showing up:
9383 <literallayout class='monospaced'>
9384 $ bitbake neard
9385 </literallayout>
9386 </para>
9387
9388 <para>
9389 Once the local build for "neard" completes, start a
9390 <filename>devshell</filename> build:
9391 <literallayout class='monospaced'>
9392 $ bitbake neard -c devshell
9393 </literallayout>
9394 For information on how to use a
9395 <filename>devshell</filename>, see the
9396 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
9397 section.
9398 </para>
9399
9400 <para>
9401 In the <filename>devshell</filename>, do the following:
9402 <literallayout class='monospaced'>
9403 $ make clean
9404 $ make tools/snep-send.o
9405 </literallayout>
9406 The <filename>devshell</filename> commands cause the failure
9407 to clearly be visible.
9408 In this case, a missing dependency exists for the "neard"
9409 Makefile target.
9410 Here is some abbreviated, sample output with the
9411 missing dependency clearly visible at the end:
9412 <literallayout class='monospaced'>
9413 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
9414 .
9415 .
9416 .
9417 tools/snep-send.c
9418 In file included from tools/snep-send.c:16:0:
9419 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9420 #include &lt;near/dbus.h&gt;
9421 ^
9422 compilation terminated.
9423 make: *** [tools/snep-send.o] Error 1
9424 $
9425 </literallayout>
9426 </para>
9427 </section>
9428
9429 <section id='creating-a-patch-for-the-fix'>
9430 <title>Creating a Patch for the Fix</title>
9431
9432 <para>
9433 Because there is a missing dependency for the Makefile
9434 target, you need to patch the
9435 <filename>Makefile.am</filename> file, which is generated
9436 from <filename>Makefile.in</filename>.
9437 You can use Quilt to create the patch:
9438 <literallayout class='monospaced'>
9439 $ quilt new parallelmake.patch
9440 Patch patches/parallelmake.patch is now on top
9441 $ quilt add Makefile.am
9442 File Makefile.am added to patch patches/parallelmake.patch
9443 </literallayout>
9444 For more information on using Quilt, see the
9445 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
9446 section.
9447 </para>
9448
9449 <para>
9450 At this point you need to make the edits to
9451 <filename>Makefile.am</filename> to add the missing
9452 dependency.
9453 For our example, you have to add the following line
9454 to the file:
9455 <literallayout class='monospaced'>
9456 tools/snep-send.$(OBJEXT): include/near/dbus.h
9457 </literallayout>
9458 </para>
9459
9460 <para>
9461 Once you have edited the file, use the
9462 <filename>refresh</filename> command to create the patch:
9463 <literallayout class='monospaced'>
9464 $ quilt refresh
9465 Refreshed patch patches/parallelmake.patch
9466 </literallayout>
9467 Once the patch file exists, you need to add it back to the
9468 originating recipe folder.
9469 Here is an example assuming a top-level
9470 <link linkend='source-directory'>Source Directory</link>
9471 named <filename>poky</filename>:
9472 <literallayout class='monospaced'>
9473 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
9474 </literallayout>
9475 The final thing you need to do to implement the fix in the
9476 build is to update the "neard" recipe (i.e.
9477 <filename>neard-0.14.bb</filename>) so that the
9478 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
9479 statement includes the patch file.
9480 The recipe file is in the folder above the patch.
9481 Here is what the edited <filename>SRC_URI</filename>
9482 statement would look like:
9483 <literallayout class='monospaced'>
9484 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
9485 file://neard.in \
9486 file://neard.service.in \
9487 file://parallelmake.patch \
9488 "
9489 </literallayout>
9490 </para>
9491
9492 <para>
9493 With the patch complete and moved to the correct folder and
9494 the <filename>SRC_URI</filename> statement updated, you can
9495 exit the <filename>devshell</filename>:
9496 <literallayout class='monospaced'>
9497 $ exit
9498 </literallayout>
9499 </para>
9500 </section>
9501
9502 <section id='testing-the-build'>
9503 <title>Testing the Build</title>
9504
9505 <para>
9506 With everything in place, you can get back to trying the
9507 build again locally:
9508 <literallayout class='monospaced'>
9509 $ bitbake neard
9510 </literallayout>
9511 This build should succeed.
9512 </para>
9513
9514 <para>
9515 Now you can open up a <filename>devshell</filename> again
9516 and repeat the clean and make operations as follows:
9517 <literallayout class='monospaced'>
9518 $ bitbake neard -c devshell
9519 $ make clean
9520 $ make tools/snep-send.o
9521 </literallayout>
9522 The build should work without issue.
9523 </para>
9524
9525 <para>
9526 As with all solved problems, if they originated upstream, you
9527 need to submit the fix for the recipe in OE-Core and upstream
9528 so that the problem is taken care of at its source.
9529 See the
9530 "<link linkend='how-to-submit-a-change'>How to Submit a Change</link>"
9531 section for more information.
9532 </para>
9533 </section>
9534 </section>
9535
9536 <section id="platdev-oprofile">
9537 <title>Profiling with OProfile</title>
9538
9539 <para>
9540 <ulink url="http://oprofile.sourceforge.net/">OProfile</ulink> is a
9541 statistical profiler well suited for finding performance
9542 bottlenecks in both user-space software and in the kernel.
9543 This profiler provides answers to questions like "Which functions does my application spend
9544 the most time in when doing X?"
9545 Because the OpenEmbedded build system is well integrated with OProfile, it makes profiling
9546 applications on target hardware straight forward.
9547 <note>
9548 For more information on how to set up and run OProfile, see the
9549 "<ulink url='&YOCTO_DOCS_PROF_URL;#profile-manual-oprofile'>oprofile</ulink>"
9550 section in the Yocto Project Profiling and Tracing Manual.
9551 </note>
9552 </para>
9553
9554 <para>
9555 To use OProfile, you need an image that has OProfile installed.
9556 The easiest way to do this is with "tools-profile" in the
9557 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'>IMAGE_FEATURES</ulink></filename> variable.
9558 You also need debugging symbols to be available on the system where the analysis
9559 takes place.
9560 You can gain access to the symbols by using "dbg-pkgs" in the
9561 <filename>IMAGE_FEATURES</filename> variable or by
9562 installing the appropriate debug (<filename>-dbg</filename>)
9563 packages.
9564 </para>
9565
9566 <para>
9567 For successful call graph analysis, the binaries must preserve the frame
9568 pointer register and should also be compiled with the
9569 <filename>-fno-omit-framepointer</filename> flag.
9570 You can achieve this by setting the
9571 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SELECTED_OPTIMIZATION'>SELECTED_OPTIMIZATION</ulink></filename>
9572 variable with the following options:
9573 <literallayout class='monospaced'>
9574 -fexpensive-optimizations
9575 -fno-omit-framepointer
9576 -frename-registers
9577 -O2
9578 </literallayout>
9579 You can also achieve it by setting the
9580 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_BUILD'>DEBUG_BUILD</ulink></filename>
9581 variable to "1" in the <filename>local.conf</filename> configuration file.
9582 If you use the <filename>DEBUG_BUILD</filename> variable,
9583 you also add extra debugging information that can make the debug
9584 packages large.
9585 </para>
9586
9587 <section id="platdev-oprofile-target">
9588 <title>Profiling on the Target</title>
9589
9590 <para>
9591 Using OProfile, you can perform all the profiling work on the target device.
9592 A simple OProfile session might look like the following:
9593 </para>
9594
9595 <para>
9596 <literallayout class='monospaced'>
9597 # opcontrol --reset
9598 # opcontrol --start --separate=lib --no-vmlinux -c 5
9599 .
9600 .
9601 [do whatever is being profiled]
9602 .
9603 .
9604 # opcontrol --stop
9605 $ opreport -cl
9606 </literallayout>
9607 </para>
9608
9609 <para>
9610 In this example, the <filename>reset</filename> command clears any previously profiled data.
9611 The next command starts OProfile.
9612 The options used when starting the profiler separate dynamic library data
9613 within applications, disable kernel profiling, and enable callgraphing up to
9614 five levels deep.
9615 <note>
9616 To profile the kernel, you would specify the
9617 <filename>--vmlinux=/path/to/vmlinux</filename> option.
9618 The <filename>vmlinux</filename> file is usually in the source directory in the
9619 <filename>/boot/</filename> directory and must match the running kernel.
9620 </note>
9621 </para>
9622
9623 <para>
9624 After you perform your profiling tasks, the next command stops the profiler.
9625 After that, you can view results with the <filename>opreport</filename> command with options
9626 to see the separate library symbols and callgraph information.
9627 </para>
9628
9629 <para>
9630 Callgraphing logs information about time spent in functions and about a function's
9631 calling function (parent) and called functions (children).
9632 The higher the callgraphing depth, the more accurate the results.
9633 However, higher depths also increase the logging overhead.
9634 Consequently, you should take care when setting the callgraphing depth.
9635 <note>
9636 On ARM, binaries need to have the frame pointer enabled for callgraphing to work.
9637 To accomplish this use the <filename>-fno-omit-framepointer</filename> option
9638 with <filename>gcc</filename>.
9639 </note>
9640 </para>
9641
9642 <para>
9643 For more information on using OProfile, see the OProfile
9644 online documentation at
9645 <ulink url="http://oprofile.sourceforge.net/docs/"/>.
9646 </para>
9647 </section>
9648
9649 <section id="platdev-oprofile-oprofileui">
9650 <title>Using OProfileUI</title>
9651
9652 <para>
9653 A graphical user interface for OProfile is also available.
9654 You can download and build this interface from the Yocto Project at
9655 <ulink url="&YOCTO_GIT_URL;/cgit.cgi/oprofileui/"></ulink>.
9656 If the "tools-profile" image feature is selected, all necessary binaries
9657 are installed onto the target device for OProfileUI interaction.
9658 For a list of image features that ship with the Yocto Project,
9659 see the
9660 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-features-image'>Image Features</ulink>"
9661 section in the Yocto Project Reference Manual.
9662 </para>
9663
9664 <para>
9665 Even though the source directory usually includes all needed patches on the target device, you
9666 might find you need other OProfile patches for recent OProfileUI features.
9667 If so, see the <ulink url='&YOCTO_GIT_URL;/cgit.cgi/oprofileui/tree/README'>
9668 OProfileUI README</ulink> for the most recent information.
9669 </para>
9670
9671 <section id="platdev-oprofile-oprofileui-online">
9672 <title>Online Mode</title>
9673
9674 <para>
9675 Using OProfile in online mode assumes a working network connection with the target
9676 hardware.
9677 With this connection, you just need to run "oprofile-server" on the device.
9678 By default, OProfile listens on port 4224.
9679 <note>
9680 You can change the port using the <filename>--port</filename> command-line
9681 option.
9682 </note>
9683 </para>
9684
9685 <para>
9686 The client program is called <filename>oprofile-viewer</filename> and its UI is relatively
9687 straight forward.
9688 You access key functionality through the buttons on the toolbar, which
9689 are duplicated in the menus.
9690 Here are the buttons:
9691 <itemizedlist>
9692 <listitem><para><emphasis>Connect:</emphasis> Connects to the remote host.
9693 You can also supply the IP address or hostname.</para></listitem>
9694 <listitem><para><emphasis>Disconnect:</emphasis> Disconnects from the target.
9695 </para></listitem>
9696 <listitem><para><emphasis>Start:</emphasis> Starts profiling on the device.
9697 </para></listitem>
9698 <listitem><para><emphasis>Stop:</emphasis> Stops profiling on the device and
9699 downloads the data to the local host.
9700 Stopping the profiler generates the profile and displays it in the viewer.
9701 </para></listitem>
9702 <listitem><para><emphasis>Download:</emphasis> Downloads the data from the
9703 target and generates the profile, which appears in the viewer.</para></listitem>
9704 <listitem><para><emphasis>Reset:</emphasis> Resets the sample data on the device.
9705 Resetting the data removes sample information collected from previous
9706 sampling runs.
9707 Be sure you reset the data if you do not want to include old sample information.
9708 </para></listitem>
9709 <listitem><para><emphasis>Save:</emphasis> Saves the data downloaded from the
9710 target to another directory for later examination.</para></listitem>
9711 <listitem><para><emphasis>Open:</emphasis> Loads previously saved data.
9712 </para></listitem>
9713 </itemizedlist>
9714 </para>
9715
9716 <para>
9717 The client downloads the complete profile archive from
9718 the target to the host for processing.
9719 This archive is a directory that contains the sample data, the object files,
9720 and the debug information for the object files.
9721 The archive is then converted using the <filename>oparchconv</filename> script, which is
9722 included in this distribution.
9723 The script uses <filename>opimport</filename> to convert the archive from
9724 the target to something that can be processed on the host.
9725 </para>
9726
9727 <para>
9728 Downloaded archives reside in the
9729 <link linkend='build-directory'>Build Directory</link> in
9730 <filename>tmp</filename> and are cleared up when they are no longer in use.
9731 </para>
9732
9733 <para>
9734 If you wish to perform kernel profiling, you need to be sure
9735 a <filename>vmlinux</filename> file that matches the running kernel is available.
9736 In the source directory, that file is usually located in
9737 <filename>/boot/vmlinux-<replaceable>kernelversion</replaceable></filename>, where
9738 <filename><replaceable>kernelversion</replaceable></filename> is the version of the kernel.
9739 The OpenEmbedded build system generates separate <filename>vmlinux</filename>
9740 packages for each kernel it builds.
9741 Thus, it should just be a question of making sure a matching package is
9742 installed (e.g. <filename>opkg install kernel-vmlinux</filename>).
9743 The files are automatically installed into development and profiling images
9744 alongside OProfile.
9745 A configuration option exists within the OProfileUI settings page that you can use to
9746 enter the location of the <filename>vmlinux</filename> file.
9747 </para>
9748
9749 <para>
9750 Waiting for debug symbols to transfer from the device can be slow, and it
9751 is not always necessary to actually have them on the device for OProfile use.
9752 All that is needed is a copy of the filesystem with the debug symbols present
9753 on the viewer system.
9754 The "<link linkend='platdev-gdb-remotedebug-launch-gdb'>Launch GDB on the Host Computer</link>"
9755 section covers how to create such a directory within
9756 the source directory and how to use the OProfileUI Settings
9757 Dialog to specify the location.
9758 If you specify the directory, it will be used when the file checksums
9759 match those on the system you are profiling.
9760 </para>
9761 </section>
9762
9763 <section id="platdev-oprofile-oprofileui-offline">
9764 <title>Offline Mode</title>
9765
9766 <para>
9767 If network access to the target is unavailable, you can generate
9768 an archive for processing in <filename>oprofile-viewer</filename> as follows:
9769 <literallayout class='monospaced'>
9770 # opcontrol --reset
9771 # opcontrol --start --separate=lib --no-vmlinux -c 5
9772 .
9773 .
9774 [do whatever is being profiled]
9775 .
9776 .
9777 # opcontrol --stop
9778 # oparchive -o my_archive
9779 </literallayout>
9780 </para>
9781
9782 <para>
9783 In the above example, <filename>my_archive</filename> is the name of the
9784 archive directory where you would like the profile archive to be kept.
9785 After the directory is created, you can copy it to another host and load it
9786 using <filename>oprofile-viewer</filename> open functionality.
9787 If necessary, the archive is converted.
9788 </para>
9789 </section>
9790 </section>
9791 </section>
9792
9793 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
9794 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
9795
9796 <para>
9797 One of the concerns for a development organization using open source
9798 software is how to maintain compliance with various open source
9799 licensing during the lifecycle of the product.
9800 While this section does not provide legal advice or
9801 comprehensively cover all scenarios, it does
9802 present methods that you can use to
9803 assist you in meeting the compliance requirements during a software
9804 release.
9805 </para>
9806
9807 <para>
9808 With hundreds of different open source licenses that the Yocto
9809 Project tracks, it is difficult to know the requirements of each
9810 and every license.
9811 However, the requirements of the major FLOSS licenses can begin
9812 to be covered by
9813 assuming that three main areas of concern exist:
9814 <itemizedlist>
9815 <listitem><para>Source code must be provided.</para></listitem>
9816 <listitem><para>License text for the software must be
9817 provided.</para></listitem>
9818 <listitem><para>Compilation scripts and modifications to the
9819 source code must be provided.
9820 </para></listitem>
9821 </itemizedlist>
9822 There are other requirements beyond the scope of these
9823 three and the methods described in this section
9824 (e.g. the mechanism through which source code is distributed).
9825 </para>
9826
9827 <para>
9828 As different organizations have different methods of complying with
9829 open source licensing, this section is not meant to imply that
9830 there is only one single way to meet your compliance obligations,
9831 but rather to describe one method of achieving compliance.
9832 The remainder of this section describes methods supported to meet the
9833 previously mentioned three requirements.
9834 Once you take steps to meet these requirements,
9835 and prior to releasing images, sources, and the build system,
9836 you should audit all artifacts to ensure completeness.
9837 <note>
9838 The Yocto Project generates a license manifest during
9839 image creation that is located
9840 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
9841 to assist with any audits.
9842 </note>
9843 </para>
9844
9845 <section id='providing-the-source-code'>
9846 <title>Providing the Source Code</title>
9847
9848 <para>
9849 Compliance activities should begin before you generate the
9850 final image.
9851 The first thing you should look at is the requirement that
9852 tops the list for most compliance groups - providing
9853 the source.
9854 The Yocto Project has a few ways of meeting this
9855 requirement.
9856 </para>
9857
9858 <para>
9859 One of the easiest ways to meet this requirement is
9860 to provide the entire
9861 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
9862 used by the build.
9863 This method, however, has a few issues.
9864 The most obvious is the size of the directory since it includes
9865 all sources used in the build and not just the source used in
9866 the released image.
9867 It will include toolchain source, and other artifacts, which
9868 you would not generally release.
9869 However, the more serious issue for most companies is accidental
9870 release of proprietary software.
9871 The Yocto Project provides an
9872 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
9873 class to help avoid some of these concerns.
9874 </para>
9875
9876 <para>
9877 Before you employ <filename>DL_DIR</filename> or the
9878 archiver class, you need to decide how you choose to
9879 provide source.
9880 The source archiver class can generate tarballs and SRPMs
9881 and can create them with various levels of compliance in mind.
9882 </para>
9883
9884 <para>
9885 One way of doing this (but certainly not the only way) is to
9886 release just the source as a tarball.
9887 You can do this by adding the following to the
9888 <filename>local.conf</filename> file found in the
9889 <link linkend='build-directory'>Build Directory</link>:
9890 <literallayout class='monospaced'>
9891 INHERIT += "archiver"
9892 ARCHIVER_MODE[src] = "original"
9893 </literallayout>
9894 During the creation of your image, the source from all
9895 recipes that deploy packages to the image is placed within
9896 subdirectories of
9897 <filename>DEPLOY_DIR/sources</filename> based on the
9898 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
9899 for each recipe.
9900 Releasing the entire directory enables you to comply with
9901 requirements concerning providing the unmodified source.
9902 It is important to note that the size of the directory can
9903 get large.
9904 </para>
9905
9906 <para>
9907 A way to help mitigate the size issue is to only release
9908 tarballs for licenses that require the release of
9909 source.
9910 Let us assume you are only concerned with GPL code as
9911 identified with the following:
9912 <literallayout class='monospaced'>
9913 $ cd poky/build/tmp/deploy/sources
9914 $ mkdir ~/gpl_source_release
9915 $ for dir in */*GPL*; do cp -r $dir ~/gpl_source_release; done
9916 </literallayout>
9917 At this point, you could create a tarball from the
9918 <filename>gpl_source_release</filename> directory and
9919 provide that to the end user.
9920 This method would be a step toward achieving compliance
9921 with section 3a of GPLv2 and with section 6 of GPLv3.
9922 </para>
9923 </section>
9924
9925 <section id='providing-license-text'>
9926 <title>Providing License Text</title>
9927
9928 <para>
9929 One requirement that is often overlooked is inclusion
9930 of license text.
9931 This requirement also needs to be dealt with prior to
9932 generating the final image.
9933 Some licenses require the license text to accompany
9934 the binary.
9935 You can achieve this by adding the following to your
9936 <filename>local.conf</filename> file:
9937 <literallayout class='monospaced'>
9938 COPY_LIC_MANIFEST = "1"
9939 COPY_LIC_DIRS = "1"
9940 </literallayout>
9941 Adding these statements to the configuration file ensures
9942 that the licenses collected during package generation
9943 are included on your image.
9944 As the source archiver has already archived the original
9945 unmodified source that contains the license files,
9946 you would have already met the requirements for inclusion
9947 of the license information with source as defined by the GPL
9948 and other open source licenses.
9949 </para>
9950 </section>
9951
9952 <section id='providing-compilation-scripts-and-source-code-modifications'>
9953 <title>Providing Compilation Scripts and Source Code Modifications</title>
9954
9955 <para>
9956 At this point, we have addressed all we need to address
9957 prior to generating the image.
9958 The next two requirements are addressed during the final
9959 packaging of the release.
9960 </para>
9961
9962 <para>
9963 By releasing the version of the OpenEmbedded build system
9964 and the layers used during the build, you will be providing both
9965 compilation scripts and the source code modifications in one
9966 step.
9967 </para>
9968
9969 <para>
9970 If the deployment team has a
9971 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
9972 and a distro layer, and those those layers are used to patch,
9973 compile, package, or modify (in any way) any open source
9974 software included in your released images, you
9975 might be required to to release those layers under section 3 of
9976 GPLv2 or section 1 of GPLv3.
9977 One way of doing that is with a clean
9978 checkout of the version of the Yocto Project and layers used
9979 during your build.
9980 Here is an example:
9981 <literallayout class='monospaced'>
9982 # We built using the &DISTRO_NAME; branch of the poky repo
9983 $ git clone -b &DISTRO_NAME; git://git.yoctoproject.org/poky
9984 $ cd poky
9985 # We built using the release_branch for our layers
9986 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
9987 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
9988 # clean up the .git repos
9989 $ find . -name ".git" -type d -exec rm -rf {} \;
9990 </literallayout>
9991 One thing a development organization might want to consider
9992 for end-user convenience is to modify
9993 <filename>meta-yocto/conf/bblayers.conf.sample</filename> to
9994 ensure that when the end user utilizes the released build
9995 system to build an image, the development organization's
9996 layers are included in the <filename>bblayers.conf</filename>
9997 file automatically:
9998 <literallayout class='monospaced'>
9999 # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
10000 # changes incompatibly
10001 LCONF_VERSION = "6"
10002
10003 BBPATH = "${TOPDIR}"
10004 BBFILES ?= ""
10005
10006 BBLAYERS ?= " \
10007 ##OEROOT##/meta \
10008 ##OEROOT##/meta-yocto \
10009 ##OEROOT##/meta-yocto-bsp \
10010 ##OEROOT##/meta-mylayer \
10011 "
10012 </literallayout>
10013 Creating and providing an archive of the
10014 <link linkend='metadata'>Metadata</link> layers
10015 (recipes, configuration files, and so forth)
10016 enables you to meet your
10017 requirements to include the scripts to control compilation
10018 as well as any modifications to the original source.
10019 </para>
10020 </section>
10021 </section>
10022
10023 <section id='using-the-error-reporting-tool'>
10024 <title>Using the Error Reporting Tool</title>
10025
10026 <para>
10027 The error reporting tool allows you to
10028 submit errors encountered during builds to a central database.
10029 Outside of the build environment, you can use a web interface to
10030 browse errors, view statistics, and query for errors.
10031 The tool works using a client-server system where the client
10032 portion is integrated with the installed Yocto Project
10033 <link linkend='source-directory'>Source Directory</link>
10034 (e.g. <filename>poky</filename>).
10035 The server receives the information collected and saves it in a
10036 database.
10037 </para>
10038
10039 <para>
10040 A live instance of the error reporting server exists at
10041 <ulink url='http://errors.yoctoproject.org'></ulink>.
10042 This server exists so that when you want to get help with
10043 build failures, you can submit all of the information on the
10044 failure easily and then point to the URL in your bug report
10045 or send an email to the mailing list.
10046 <note>
10047 If you send error reports to this server, the reports become
10048 publicly visible.
10049 </note>
10050 </para>
10051
10052 <section id='enabling-and-using-the-tool'>
10053 <title>Enabling and Using the Tool</title>
10054
10055 <para>
10056 By default, the error reporting tool is disabled.
10057 You can enable it by inheriting the
10058 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
10059 class by adding the following statement to the end of
10060 your <filename>local.conf</filename> file in your
10061 <link linkend='build-directory'>Build Directory</link>.
10062 <literallayout class='monospaced'>
10063 INHERIT += "report-error"
10064 </literallayout>
10065 </para>
10066
10067 <para>
10068 By default, the error reporting feature stores information in
10069 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
10070 However, you can specify a directory to use by adding the following
10071 to your <filename>local.conf</filename> file:
10072 <literallayout class='monospaced'>
10073 ERR_REPORT_DIR = "path"
10074 </literallayout>
10075 Enabling error reporting causes the build process to collect
10076 the errors and store them in a file as previously described.
10077 When the build system encounters an error, it includes a
10078 command as part of the console output.
10079 You can run the command to send the error file to the server.
10080 For example, the following command sends the errors to an
10081 upstream server:
10082 <literallayout class='monospaced'>
10083 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
10084 </literallayout>
10085 In the previous example, the errors are sent to a public
10086 database available at
10087 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
10088 used by the entire community.
10089 If you specify a particular server, you can send the errors
10090 to a different database.
10091 Use the following command for more information on available
10092 options:
10093 <literallayout class='monospaced'>
10094 $ send-error-report --help
10095 </literallayout>
10096 </para>
10097
10098 <para>
10099 When sending the error file, you are prompted to review the
10100 data being sent as well as to provide a name and optional
10101 email address.
10102 Once you satisfy these prompts, the command returns a link
10103 from the server that corresponds to your entry in the database.
10104 For example, here is a typical link:
10105 <literallayout class='monospaced'>
10106 http://errors.yoctoproject.org/Errors/Details/9522/
10107 </literallayout>
10108 Following the link takes you to a web interface where you can
10109 browse, query the errors, and view statistics.
10110 </para>
10111 </section>
10112
10113 <section id='disabling-the-tool'>
10114 <title>Disabling the Tool</title>
10115
10116 <para>
10117 To disable the error reporting feature, simply remove or comment
10118 out the following statement from the end of your
10119 <filename>local.conf</filename> file in your
10120 <link linkend='build-directory'>Build Directory</link>.
10121 <literallayout class='monospaced'>
10122 INHERIT += "report-error"
10123 </literallayout>
10124 </para>
10125 </section>
10126
10127 <section id='setting-up-your-own-error-reporting-server'>
10128 <title>Setting Up Your Own Error Reporting Server</title>
10129
10130 <para>
10131 If you want to set up your own error reporting server, you
10132 can obtain the code from the Git repository at
10133 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
10134 Instructions on how to set it up are in the README document.
10135 </para>
10136 </section>
10137 </section>
10138</chapter>
10139
10140<!--
10141vim: expandtab tw=80 ts=4
10142-->