blob: 893ef7ba0774a5e804be18bd8aa2a93222f59756 [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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> into
22 multiple layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 Layers allow you to isolate different types of customizations from
24 each other.
Brad Bishop316dfdd2018-06-25 12:45:53 -040025 For introductory information on the Yocto Project Layer Model,
26 see the
27 "<ulink url='&YOCTO_DOCS_OM_URL;#the-yocto-project-layer-model'>The Yocto Project Layer Model</ulink>"
28 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 </para>
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 <section id='creating-your-own-layer'>
32 <title>Creating Your Own Layer</title>
33
34 <para>
35 It is very easy to create your own layers to use with the
36 OpenEmbedded build system.
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 The Yocto Project ships with tools that speed up creating
38 layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 This section describes the steps you perform by hand to create
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 layers so that you can better understand them.
41 For information about the layer-creation tools, see the
42 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 section in the Yocto Project Board Support Package (BSP)
44 Developer's Guide and the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 section further down in this manual.
47 </para>
48
49 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040050 Follow these general steps to create your layer without using
51 tools:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 <orderedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -040053 <listitem><para>
54 <emphasis>Check Existing Layers:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 Before creating a new layer, you should be sure someone
56 has not already created a layer containing the Metadata
57 you need.
58 You can see the
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 <ulink url='http://layers.openembedded.org/layerindex/layers/'>OpenEmbedded Metadata Index</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 for a list of layers from the OpenEmbedded community
61 that can be used in the Yocto Project.
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 You could find a layer that is identical or close to
63 what you need.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 <listitem><para>
66 <emphasis>Create a Directory:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 Create the directory for your layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -040068 When you create the layer, be sure to create the
69 directory in an area not associated with the
70 Yocto Project
71 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
72 (e.g. the cloned <filename>poky</filename> repository).
73 </para>
74
75 <para>While not strictly required, prepend the name of
76 the directory with the string "meta-".
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 For example:
78 <literallayout class='monospaced'>
79 meta-mylayer
80 meta-GUI_xyz
81 meta-mymachine
82 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040083 With rare exceptions, a layer's name follows this
84 form:
85 <literallayout class='monospaced'>
86 meta-<replaceable>root_name</replaceable>
87 </literallayout>
88 Following this layer naming convention can
89 save you trouble later when tools, components, or
90 variables "assume" your layer name begins with "meta-".
91 A notable example is in configuration files as
92 shown in the following step where layer names without
93 the "meta-" string are appended
94 to several variables used in the configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 <listitem><para id='dev-layer-config-file-description'>
97 <emphasis>Create a Layer Configuration File:</emphasis>
98 Inside your new layer folder, you need to create a
99 <filename>conf/layer.conf</filename> file.
100 It is easiest to take an existing layer configuration
101 file and copy that to your layer's
102 <filename>conf</filename> directory and then modify the
103 file as needed.</para>
104
105 <para>The
106 <filename>meta-yocto-bsp/conf/layer.conf</filename> file
107 in the Yocto Project
108 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf'>Source Repositories</ulink>
109 demonstrates the required syntax.
110 For your layer, you need to replace "yoctobsp" with
111 a unique identifier for your layer (e.g. "machinexyz"
112 for a layer named "meta-machinexyz"):
113 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 # We have a conf and classes directory, add to BBPATH
115 BBPATH .= ":${LAYERDIR}"
116
117 # We have recipes-* directories, add to BBFILES
118 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
119 ${LAYERDIR}/recipes-*/*/*.bbappend"
120
121 BBFILE_COLLECTIONS += "yoctobsp"
122 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
123 BBFILE_PRIORITY_yoctobsp = "5"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 LAYERVERSION_yoctobsp = "4"
125 LAYERSERIES_COMPAT_yoctobsp = "&DISTRO_NAME_NO_CAP;"
126 </literallayout>
127 Following is an explanation of the layer configuration
128 file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130 <listitem><para>
131 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>:
132 Adds the layer's root directory to BitBake's
133 search path.
134 Through the use of the
135 <filename>BBPATH</filename> variable, BitBake
136 locates class files
137 (<filename>.bbclass</filename>),
138 configuration files, and files that are
139 included with <filename>include</filename> and
140 <filename>require</filename> statements.
141 For these cases, BitBake uses the first file
142 that matches the name found in
143 <filename>BBPATH</filename>.
144 This is similar to the way the
145 <filename>PATH</filename> variable is used for
146 binaries.
147 It is recommended, therefore, that you use
148 unique class and configuration filenames in
149 your custom layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400151 <listitem><para>
152 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>:
153 Defines the location for all recipes in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155 </para></listitem>
156 <listitem><para>
157 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'><filename>BBFILE_COLLECTIONS</filename></ulink>:
158 Establishes the current layer through a
159 unique identifier that is used throughout the
160 OpenEmbedded build system to refer to the layer.
161 In this example, the identifier "yoctobsp" is
162 the representation for the container layer
163 named "meta-yocto-bsp".
164 </para></listitem>
165 <listitem><para>
166 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'><filename>BBFILE_PATTERN</filename></ulink>:
167 Expands immediately during parsing to
168 provide the directory of the layer.
169 </para></listitem>
170 <listitem><para>
171 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>:
172 Establishes a priority to use for
173 recipes in the layer when the OpenEmbedded build
174 finds recipes of the same name in different
175 layers.
176 </para></listitem>
177 <listitem><para>
178 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'><filename>LAYERVERSION</filename></ulink>:
179 Establishes a version number for the layer.
180 You can use this version number to specify this
181 exact version of the layer as a dependency when
182 using the
183 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDEPENDS'><filename>LAYERDEPENDS</filename></ulink>
184 variable.
185 </para></listitem>
186 <listitem><para>
187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERSERIES_COMPAT'><filename>LAYERSERIES_COMPAT</filename></ulink>:
188 Lists the
189 <ulink url='&YOCTO_WIKI_URL;/wiki/Releases'>Yocto Project</ulink>
190 releases for which the current version is
191 compatible.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800192 This variable is a good way to indicate if
193 your particular layer is current.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194 </para></listitem>
195 </itemizedlist>
196 </para></listitem>
197 <listitem><para>
198 <emphasis>Add Content:</emphasis>
199 Depending on the type of layer, add the content.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 If the layer adds support for a machine, add the machine
201 configuration in a <filename>conf/machine/</filename>
202 file within the layer.
203 If the layer adds distro policy, add the distro
204 configuration in a <filename>conf/distro/</filename>
205 file within the layer.
206 If the layer introduces new recipes, put the recipes
207 you need in <filename>recipes-*</filename>
208 subdirectories within the layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400209 <note>
210 For an explanation of layer hierarchy that
211 is compliant with the Yocto Project, see
212 the
213 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout'>Example Filesystem Layout</ulink>"
214 section in the Yocto Project Board
215 Support Package (BSP) Developer's Guide.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 </note>
217 </para></listitem>
218 <listitem><para>
219 <emphasis>Optionally Test for Compatibility:</emphasis>
220 If you want permission to use the Yocto Project
221 Compatibility logo with your layer or application that
222 uses your layer, perform the steps to apply for
223 compatibility.
224 See the
225 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
226 section for more information.
227 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 </orderedlist>
229 </para>
230 </section>
231
232 <section id='best-practices-to-follow-when-creating-layers'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500233 <title>Following Best Practices When Creating Layers</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234
235 <para>
236 To create layers that are easier to maintain and that will
237 not impact builds for other machines, you should consider the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 information in the following list:
239 <itemizedlist>
240 <listitem><para>
241 <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis>
242 In other words, do not copy an entire recipe into your
243 layer and then modify it.
244 Rather, use an append file
245 (<filename>.bbappend</filename>) to override only those
246 parts of the original recipe you need to modify.
247 </para></listitem>
248 <listitem><para>
249 <emphasis>Avoid Duplicating Include Files:</emphasis>
250 Use append files (<filename>.bbappend</filename>)
251 for each recipe that uses an include file.
252 Or, if you are introducing a new recipe that requires
253 the included file, use the path relative to the
254 original layer directory to refer to the file.
255 For example, use
256 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
257 instead of
258 <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
259 If you're finding you have to overlay the include file,
260 it could indicate a deficiency in the include file in
261 the layer to which it originally belongs.
262 If this is the case, you should try to address that
263 deficiency instead of overlaying the include file.
264 For example, you could address this by getting the
265 maintainer of the include file to add a variable or
266 variables to make it easy to override the parts needing
267 to be overridden.
268 </para></listitem>
269 <listitem><para>
270 <emphasis>Structure Your Layers:</emphasis>
271 Proper use of overrides within append files and
272 placement of machine-specific files within your layer
273 can ensure that a build is not using the wrong Metadata
274 and negatively impacting a build for a different
275 machine.
276 Following are some examples:
277 <itemizedlist>
278 <listitem><para>
279 <emphasis>Modify Variables to Support a
280 Different Machine:</emphasis>
281 Suppose you have a layer named
282 <filename>meta-one</filename> that adds support
283 for building machine "one".
284 To do so, you use an append file named
285 <filename>base-files.bbappend</filename> and
286 create a dependency on "foo" by altering the
287 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
288 variable:
289 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 DEPENDS = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 </literallayout>
292 The dependency is created during any build that
293 includes the layer
294 <filename>meta-one</filename>.
295 However, you might not want this dependency
296 for all machines.
297 For example, suppose you are building for
298 machine "two" but your
299 <filename>bblayers.conf</filename> file has the
300 <filename>meta-one</filename> layer included.
301 During the build, the
302 <filename>base-files</filename> for machine
303 "two" will also have the dependency on
304 <filename>foo</filename>.</para>
305 <para>To make sure your changes apply only when
306 building machine "one", use a machine override
307 with the <filename>DEPENDS</filename> statement:
308 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 DEPENDS_one = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500310 </literallayout>
311 You should follow the same strategy when using
312 <filename>_append</filename> and
313 <filename>_prepend</filename> operations:
314 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 DEPENDS_append_one = " foo"
316 DEPENDS_prepend_one = "foo "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 </literallayout>
318 As an actual example, here's a line from the recipe
319 for gnutls, which adds dependencies on
320 "argp-standalone" when building with the musl C
321 library:
322 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323 DEPENDS_append_libc-musl = " argp-standalone"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500324 </literallayout>
325 <note>
326 Avoiding "+=" and "=+" and using
327 machine-specific
328 <filename>_append</filename>
329 and <filename>_prepend</filename> operations
330 is recommended as well.
331 </note>
332 </para></listitem>
333 <listitem><para>
334 <emphasis>Place Machine-Specific Files in
335 Machine-Specific Locations:</emphasis>
336 When you have a base recipe, such as
337 <filename>base-files.bb</filename>, that
338 contains a
339 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
340 statement to a file, you can use an append file
341 to cause the build to use your own version of
342 the file.
343 For example, an append file in your layer at
344 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
345 could extend
346 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
347 using
348 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
349 as follows:
350 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352 </literallayout>
353 The build for machine "one" will pick up your
354 machine-specific file as long as you have the
355 file in
356 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
357 However, if you are building for a different
358 machine and the
359 <filename>bblayers.conf</filename> file includes
360 the <filename>meta-one</filename> layer and
361 the location of your machine-specific file is
362 the first location where that file is found
363 according to <filename>FILESPATH</filename>,
364 builds for all machines will also use that
365 machine-specific file.</para>
366 <para>You can make sure that a machine-specific
367 file is used for a particular machine by putting
368 the file in a subdirectory specific to the
369 machine.
370 For example, rather than placing the file in
371 <filename>meta-one/recipes-core/base-files/base-files/</filename>
372 as shown above, put it in
373 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
374 Not only does this make sure the file is used
375 only when building for machine "one", but the
376 build process locates the file more quickly.</para>
377 <para>In summary, you need to place all files
378 referenced from <filename>SRC_URI</filename>
379 in a machine-specific subdirectory within the
380 layer in order to restrict those files to
381 machine-specific builds.
382 </para></listitem>
383 </itemizedlist>
384 </para></listitem>
385 <listitem><para>
386 <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis>
387 If you want permission to use the
388 Yocto Project Compatibility logo with your layer
389 or application that uses your layer, perform the
390 steps to apply for compatibility.
391 See the
392 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
393 section for more information.
394 </para></listitem>
395 <listitem><para>
396 <emphasis>Follow the Layer Naming Convention:</emphasis>
397 Store custom layers in a Git repository that use the
398 <filename>meta-<replaceable>layer_name</replaceable></filename>
399 format.
400 </para></listitem>
401 <listitem><para>
402 <emphasis>Group Your Layers Locally:</emphasis>
403 Clone your repository alongside other cloned
404 <filename>meta</filename> directories from the
405 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
406 </para></listitem>
407 </itemizedlist>
408 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 </section>
410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 <section id='making-sure-your-layer-is-compatible-with-yocto-project'>
412 <title>Making Sure Your Layer is Compatible With Yocto Project</title>
413
414 <para>
415 When you create a layer used with the Yocto Project, it is
416 advantageous to make sure that the layer interacts well with
417 existing Yocto Project layers (i.e. the layer is compatible
418 with the Yocto Project).
419 Ensuring compatibility makes the layer easy to be consumed
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500420 by others in the Yocto Project community and could allow you
421 permission to use the Yocto Project Compatible Logo.
422 <note>
423 Only Yocto Project member organizations are permitted to
424 use the Yocto Project Compatible Logo.
425 The logo is not available for general use.
426 For information on how to become a Yocto Project member
427 organization, see the
428 <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500429 </note>
430 </para>
431
432 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500433 The Yocto Project Compatibility Program consists of a layer
434 application process that requests permission to use the Yocto
435 Project Compatibility Logo for your layer and application.
436 The process consists of two parts:
437 <orderedlist>
438 <listitem><para>
439 Successfully passing a script
440 (<filename>yocto-check-layer</filename>) that
441 when run against your layer, tests it against
442 constraints based on experiences of how layers have
443 worked in the real world and where pitfalls have been
444 found.
445 Getting a "PASS" result from the script is required for
446 successful compatibility registration.
447 </para></listitem>
448 <listitem><para>
449 Completion of an application acceptance form, which
450 you can find at
451 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
452 </para></listitem>
453 </orderedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 </para>
455
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 <para>
457 To be granted permission to use the logo, you need to satisfy
458 the following:
459 <itemizedlist>
460 <listitem><para>
461 Be able to check the box indicating that you
462 got a "PASS" when running the script against your
463 layer.
464 </para></listitem>
465 <listitem><para>
466 Answer "Yes" to the questions on the form or have an
467 acceptable explanation for any questions answered "No".
468 </para></listitem>
469 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400470 Be a Yocto Project Member Organization.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500471 </para></listitem>
472 </itemizedlist>
473 </para>
474
475 <para>
476 The remainder of this section presents information on the
477 registration form and on the
478 <filename>yocto-check-layer</filename> script.
479 </para>
480
481 <section id='yocto-project-compatible-program-application'>
482 <title>Yocto Project Compatible Program Application</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483
484 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500485 Use the form to apply for your layer's approval.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486 Upon successful application, you can use the Yocto
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500487 Project Compatibility Logo with your layer and the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 application that uses your layer.
489 </para>
490
491 <para>
492 To access the form, use this link:
493 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
494 Follow the instructions on the form to complete your
495 application.
496 </para>
497
498 <para>
499 The application consists of the following sections:
500 <itemizedlist>
501 <listitem><para>
502 <emphasis>Contact Information:</emphasis>
503 Provide your contact information as the fields
504 require.
505 Along with your information, provide the
506 released versions of the Yocto Project for which
507 your layer is compatible.
508 </para></listitem>
509 <listitem><para>
510 <emphasis>Acceptance Criteria:</emphasis>
511 Provide "Yes" or "No" answers for each of the
512 items in the checklist.
513 Space exists at the bottom of the form for any
514 explanations for items for which you answered "No".
515 </para></listitem>
516 <listitem><para>
517 <emphasis>Recommendations:</emphasis>
518 Provide answers for the questions regarding Linux
519 kernel use and build success.
520 </para></listitem>
521 </itemizedlist>
522 </para>
523 </section>
524
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500525 <section id='yocto-check-layer-script'>
526 <title><filename>yocto-check-layer</filename> Script</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527
528 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500529 The <filename>yocto-check-layer</filename> script
530 provides you a way to assess how compatible your layer is
531 with the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500532 You should run this script prior to using the form to
533 apply for compatibility as described in the previous
534 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500535 You need to achieve a "PASS" result in order to have
536 your application form successfully processed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 </para>
538
539 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400540 The script divides tests into three areas: COMMON, BSP,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500541 and DISTRO.
542 For example, given a distribution layer (DISTRO), the
543 layer must pass both the COMMON and DISTRO related tests.
544 Furthermore, if your layer is a BSP layer, the layer must
545 pass the COMMON and BSP set of tests.
546 </para>
547
548 <para>
549 To execute the script, enter the following commands from
550 your build directory:
551 <literallayout class='monospaced'>
552 $ source oe-init-build-env
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 $ yocto-check-layer <replaceable>your_layer_directory</replaceable>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500554 </literallayout>
555 Be sure to provide the actual directory for your layer
556 as part of the command.
557 </para>
558
559 <para>
560 Entering the command causes the script to determine the
561 type of layer and then to execute a set of specific
562 tests against the layer.
563 The following list overviews the test:
564 <itemizedlist>
565 <listitem><para>
566 <filename>common.test_readme</filename>:
567 Tests if a <filename>README</filename> file
568 exists in the layer and the file is not empty.
569 </para></listitem>
570 <listitem><para>
571 <filename>common.test_parse</filename>:
572 Tests to make sure that BitBake can parse the
573 files without error (i.e.
574 <filename>bitbake -p</filename>).
575 </para></listitem>
576 <listitem><para>
577 <filename>common.test_show_environment</filename>:
578 Tests that the global or per-recipe environment
579 is in order without errors (i.e.
580 <filename>bitbake -e</filename>).
581 </para></listitem>
582 <listitem><para>
583 <filename>common.test_signatures</filename>:
584 Tests to be sure that BSP and DISTRO layers do not
585 come with recipes that change signatures.
586 </para></listitem>
587 <listitem><para>
588 <filename>bsp.test_bsp_defines_machines</filename>:
589 Tests if a BSP layer has machine configurations.
590 </para></listitem>
591 <listitem><para>
592 <filename>bsp.test_bsp_no_set_machine</filename>:
593 Tests to ensure a BSP layer does not set the
594 machine when the layer is added.
595 </para></listitem>
596 <listitem><para>
597 <filename>distro.test_distro_defines_distros</filename>:
598 Tests if a DISTRO layer has distro configurations.
599 </para></listitem>
600 <listitem><para>
601 <filename>distro.test_distro_no_set_distro</filename>:
602 Tests to ensure a DISTRO layer does not set the
603 distribution when the layer is added.
604 </para></listitem>
605 </itemizedlist>
606 </para>
607 </section>
608 </section>
609
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610 <section id='enabling-your-layer'>
611 <title>Enabling Your Layer</title>
612
613 <para>
614 Before the OpenEmbedded build system can use your new layer,
615 you need to enable it.
616 To enable your layer, simply add your layer's path to the
617 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
618 variable in your <filename>conf/bblayers.conf</filename> file,
619 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 The following example shows how to enable a layer named
622 <filename>meta-mylayer</filename>:
623 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400624 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
625 # changes incompatibly
626 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627
628 BBPATH = "${TOPDIR}"
629 BBFILES ?= ""
630
631 BBLAYERS ?= " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400632 /home/<replaceable>user</replaceable>/poky/meta \
633 /home/<replaceable>user</replaceable>/poky/meta-poky \
634 /home/<replaceable>user</replaceable>/poky/meta-yocto-bsp \
635 /home/<replaceable>user</replaceable>/poky/meta-mylayer \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500636 "
637 </literallayout>
638 </para>
639
640 <para>
641 BitBake parses each <filename>conf/layer.conf</filename> file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400642 from the top down as specified in the
643 <filename>BBLAYERS</filename> variable
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500644 within the <filename>conf/bblayers.conf</filename> file.
645 During the processing of each
646 <filename>conf/layer.conf</filename> file, BitBake adds the
647 recipes, classes and configurations contained within the
648 particular layer to the source directory.
649 </para>
650 </section>
651
652 <section id='using-bbappend-files'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500653 <title>Using .bbappend Files in Your Layer</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500654
655 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500656 A recipe that appends Metadata to another recipe is called a
657 BitBake append file.
658 A BitBake append file uses the <filename>.bbappend</filename>
659 file type suffix, while the corresponding recipe to which
660 Metadata is being appended uses the <filename>.bb</filename>
661 file type suffix.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500662 </para>
663
664 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500665 You can use a <filename>.bbappend</filename> file in your
666 layer to make additions or changes to the content of another
667 layer's recipe without having to copy the other layer's
668 recipe into your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669 Your <filename>.bbappend</filename> file resides in your layer,
670 while the main <filename>.bb</filename> recipe file to
671 which you are appending Metadata resides in a different layer.
672 </para>
673
674 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 Being able to append information to an existing recipe not only
676 avoids duplication, but also automatically applies recipe
677 changes from a different layer into your layer.
678 If you were copying recipes, you would have to manually merge
679 changes as they occur.
680 </para>
681
682 <para>
683 When you create an append file, you must use the same root
684 name as the corresponding recipe file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685 For example, the append file
686 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
687 <filename>someapp_&DISTRO;.bb</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500688 This means the original recipe and append file names are
689 version number-specific.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500690 If the corresponding recipe is renamed to update to a newer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500691 version, you must also rename and possibly update
692 the corresponding <filename>.bbappend</filename> as well.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 During the build process, BitBake displays an error on starting
694 if it detects a <filename>.bbappend</filename> file that does
695 not have a corresponding recipe with a matching name.
696 See the
697 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
698 variable for information on how to handle this error.
699 </para>
700
701 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702 As an example, consider the main formfactor recipe and a
703 corresponding formfactor append file both from the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500704 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500705 Here is the main formfactor recipe, which is named
706 <filename>formfactor_0.0.bb</filename> and located in the
707 "meta" layer at
708 <filename>meta/recipes-bsp/formfactor</filename>:
709 <literallayout class='monospaced'>
710 SUMMARY = "Device formfactor information"
711 SECTION = "base"
712 LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500713 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714 PR = "r45"
715
716 SRC_URI = "file://config file://machconfig"
717 S = "${WORKDIR}"
718
719 PACKAGE_ARCH = "${MACHINE_ARCH}"
720 INHIBIT_DEFAULT_DEPS = "1"
721
722 do_install() {
723 # Install file only if it has contents
724 install -d ${D}${sysconfdir}/formfactor/
725 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
726 if [ -s "${S}/machconfig" ]; then
727 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
728 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 } </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 In the main recipe, note the
731 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
732 variable, which tells the OpenEmbedded build system where to
733 find files during the build.
734 </para>
735
736 <para>
737 Following is the append file, which is named
738 <filename>formfactor_0.0.bbappend</filename> and is from the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500739 Raspberry Pi BSP Layer named
740 <filename>meta-raspberrypi</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500741 The file is in the layer at
742 <filename>recipes-bsp/formfactor</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 <literallayout class='monospaced'>
744 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
745 </literallayout>
746 </para>
747
748 <para>
749 By default, the build system uses the
750 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
751 variable to locate files.
752 This append file extends the locations by setting the
753 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
754 variable.
755 Setting this variable in the <filename>.bbappend</filename>
756 file is the most reliable and recommended method for adding
757 directories to the search path used by the build system
758 to find files.
759 </para>
760
761 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500762 The statement in this example extends the directories to
763 include
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500764 <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>,
765 which resolves to a directory named
766 <filename>formfactor</filename> in the same directory
767 in which the append file resides (i.e.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500768 <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500769 This implies that you must have the supporting directory
770 structure set up that will contain any files or patches you
771 will be including from the layer.
772 </para>
773
774 <para>
775 Using the immediate expansion assignment operator
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500776 <filename>:=</filename> is important because of the reference
777 to <filename>THISDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500778 The trailing colon character is important as it ensures that
779 items in the list remain colon-separated.
780 <note>
781 <para>
782 BitBake automatically defines the
783 <filename>THISDIR</filename> variable.
784 You should never set this variable yourself.
785 Using "_prepend" as part of the
786 <filename>FILESEXTRAPATHS</filename> ensures your path
787 will be searched prior to other paths in the final
788 list.
789 </para>
790
791 <para>
792 Also, not all append files add extra files.
793 Many append files simply exist to add build options
794 (e.g. <filename>systemd</filename>).
795 For these cases, your append file would not even
796 use the <filename>FILESEXTRAPATHS</filename> statement.
797 </para>
798 </note>
799 </para>
800 </section>
801
802 <section id='prioritizing-your-layer'>
803 <title>Prioritizing Your Layer</title>
804
805 <para>
806 Each layer is assigned a priority value.
807 Priority values control which layer takes precedence if there
808 are recipe files with the same name in multiple layers.
809 For these cases, the recipe file from the layer with a higher
810 priority number takes precedence.
811 Priority values also affect the order in which multiple
812 <filename>.bbappend</filename> files for the same recipe are
813 applied.
814 You can either specify the priority manually, or allow the
815 build system to calculate it based on the layer's dependencies.
816 </para>
817
818 <para>
819 To specify the layer's priority manually, use the
820 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400821 variable and append the layer's root name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500822 <literallayout class='monospaced'>
823 BBFILE_PRIORITY_mylayer = "1"
824 </literallayout>
825 </para>
826
827 <note>
828 <para>It is possible for a recipe with a lower version number
829 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
830 in a layer that has a higher priority to take precedence.</para>
831 <para>Also, the layer priority does not currently affect the
832 precedence order of <filename>.conf</filename>
833 or <filename>.bbclass</filename> files.
834 Future versions of BitBake might address this.</para>
835 </note>
836 </section>
837
838 <section id='managing-layers'>
839 <title>Managing Layers</title>
840
841 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400842 You can use the BitBake layer management tool
843 <filename>bitbake-layers</filename> to provide a view
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844 into the structure of recipes across a multi-layer project.
845 Being able to generate output that reports on configured layers
846 with their paths and priorities and on
847 <filename>.bbappend</filename> files and their applicable
848 recipes can help to reveal potential problems.
849 </para>
850
851 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400852 For help on the BitBake layer management tool, use the
853 following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500854 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400855 $ bitbake-layers --help
856 NOTE: Starting bitbake server...
857 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] &lt;subcommand&gt; ...
858
859 BitBake layers utility
860
861 optional arguments:
862 -d, --debug Enable debug output
863 -q, --quiet Print only errors
864 -F, --force Force add without recipe parse verification
865 --color COLOR Colorize output (where COLOR is auto, always, never)
866 -h, --help show this help message and exit
867
868 subcommands:
869 &lt;subcommand&gt;
870 show-layers show current configured layers.
871 show-overlayed list overlayed recipes (where the same recipe exists
872 in another layer)
873 show-recipes list available recipes, showing the layer they are
874 provided by
875 show-appends list bbappend files and recipe files they apply to
876 show-cross-depends Show dependencies between recipes that cross layer
877 boundaries.
878 add-layer Add one or more layers to bblayers.conf.
879 remove-layer Remove one or more layers from bblayers.conf.
880 flatten flatten layer configuration into a separate output
881 directory.
882 layerindex-fetch Fetches a layer from a layer index along with its
883 dependent layers, and adds them to conf/bblayers.conf.
884 layerindex-show-depends
885 Find layer dependencies from layer index.
886 create-layer Create a basic layer
887
888 Use bitbake-layers &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500889 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400890 </para>
891
892 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500893 The following list describes the available commands:
894 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400895 <listitem><para>
896 <emphasis><filename>help:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500897 Displays general help or help on a specified command.
898 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400899 <listitem><para>
900 <emphasis><filename>show-layers:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500901 Shows the current configured layers.
902 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400903 <listitem><para>
904 <emphasis><filename>show-overlayed:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 Lists overlayed recipes.
906 A recipe is overlayed when a recipe with the same name
907 exists in another layer that has a higher layer
908 priority.
909 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400910 <listitem><para>
911 <emphasis><filename>show-recipes:</filename></emphasis>
912 Lists available recipes and the layers that provide them.
913 </para></listitem>
914 <listitem><para>
915 <emphasis><filename>show-appends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916 Lists <filename>.bbappend</filename> files and the
917 recipe files to which they apply.
918 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400919 <listitem><para>
920 <emphasis><filename>show-cross-depends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500921 Lists dependency relationships between recipes that
922 cross layer boundaries.
923 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400924 <listitem><para>
925 <emphasis><filename>add-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500926 Adds a layer to <filename>bblayers.conf</filename>.
927 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400928 <listitem><para>
929 <emphasis><filename>remove-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500930 Removes a layer from <filename>bblayers.conf</filename>
931 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400932 <listitem><para>
933 <emphasis><filename>flatten:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500934 Flattens the layer configuration into a separate output
935 directory.
936 Flattening your layer configuration builds a "flattened"
937 directory that contains the contents of all layers,
938 with any overlayed recipes removed and any
939 <filename>.bbappend</filename> files appended to the
940 corresponding recipes.
941 You might have to perform some manual cleanup of the
942 flattened layer as follows:
943 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400944 <listitem><para>
945 Non-recipe files (such as patches)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500946 are overwritten.
947 The flatten command shows a warning for these
948 files.
949 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400950 <listitem><para>
951 Anything beyond the normal layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952 setup has been added to the
953 <filename>layer.conf</filename> file.
954 Only the lowest priority layer's
955 <filename>layer.conf</filename> is used.
956 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400957 <listitem><para>
958 Overridden and appended items from
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500959 <filename>.bbappend</filename> files need to be
960 cleaned up.
961 The contents of each
962 <filename>.bbappend</filename> end up in the
963 flattened recipe.
964 However, if there are appended or changed
965 variable values, you need to tidy these up
966 yourself.
967 Consider the following example.
968 Here, the <filename>bitbake-layers</filename>
969 command adds the line
970 <filename>#### bbappended ...</filename> so that
971 you know where the following lines originate:
972 <literallayout class='monospaced'>
973 ...
974 DESCRIPTION = "A useful utility"
975 ...
976 EXTRA_OECONF = "--enable-something"
977 ...
978
979 #### bbappended from meta-anotherlayer ####
980
981 DESCRIPTION = "Customized utility"
982 EXTRA_OECONF += "--enable-somethingelse"
983 </literallayout>
984 Ideally, you would tidy up these utilities as
985 follows:
986 <literallayout class='monospaced'>
987 ...
988 DESCRIPTION = "Customized utility"
989 ...
990 EXTRA_OECONF = "--enable-something --enable-somethingelse"
991 ...
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500992 </literallayout>
993 </para></listitem>
994 </itemizedlist>
995 </para></listitem>
996 <listitem><para>
997 <emphasis><filename>layerindex-fetch</filename>:</emphasis>
998 Fetches a layer from a layer index, along with its
999 dependent layers, and adds the layers to the
1000 <filename>conf/bblayers.conf</filename> file.
1001 </para></listitem>
1002 <listitem><para>
1003 <emphasis><filename>layerindex-show-depends</filename>:</emphasis>
1004 Finds layer dependencies from the layer index.
1005 </para></listitem>
1006 <listitem><para>
1007 <emphasis><filename>create-layer</filename>:</emphasis>
1008 Creates a basic layer.
1009 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001010 </itemizedlist>
1011 </para>
1012 </section>
1013
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001014 <section id='creating-a-general-layer-using-the-bitbake-layers-script'>
1015 <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
1017 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001018 The <filename>bitbake-layers</filename> script with the
1019 <filename>create-layer</filename> subcommand simplifies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001020 creating a new general layer.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 <note><title>Notes</title>
1022 <itemizedlist>
1023 <listitem><para>
1024 For information on BSP layers, see the
1025 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
1026 section in the Yocto Project Board Specific (BSP)
1027 Developer's Guide.
1028 </para></listitem>
1029 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001030 In order to use a layer with the OpenEmbedded
1031 build system, you need to add the layer to your
1032 <filename>bblayers.conf</filename> configuration
1033 file.
1034 See the
1035 "<link linkend='adding-a-layer-using-the-bitbake-layers-script'>Adding a Layer Using the <filename>bitbake-layers</filename> Script</link>"
1036 section for more information.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001037 </para></listitem>
1038 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001039 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 The default mode of the script's operation with this
1041 subcommand is to create a layer with the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001042 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001043 <listitem><para>A layer priority of 6.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001044 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001045 <listitem><para>A <filename>conf</filename>
1046 subdirectory that contains a
1047 <filename>layer.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001048 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001049 <listitem><para>
1050 A <filename>recipes-example</filename> subdirectory
1051 that contains a further subdirectory named
1052 <filename>example</filename>, which contains
1053 an <filename>example.bb</filename> recipe file.
1054 </para></listitem>
1055 <listitem><para>A <filename >COPYING.MIT</filename>,
1056 which is the license statement for the layer.
1057 The script assumes you want to use the MIT license,
1058 which is typical for most layers, for the contents of
1059 the layer itself.
1060 </para></listitem>
1061 <listitem><para>
1062 A <filename>README</filename> file, which is a file
1063 describing the contents of your new layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001064 </para></listitem>
1065 </itemizedlist>
1066 </para>
1067
1068 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001069 In its simplest form, you can use the following command form
1070 to create a layer.
1071 The command creates a layer whose name corresponds to
1072 <replaceable>your_layer_name</replaceable> in the current
1073 directory:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001074 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001075 $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001076 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001077 As an example, the following command creates a layer named
1078 <filename>meta-scottrif</filename> in your home directory:
1079 <literallayout class='monospaced'>
1080 $ cd /usr/home
1081 $ bitbake-layers create-layer meta-scottrif
1082 NOTE: Starting bitbake server...
1083 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
1084 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 </para>
1086
1087 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001088 If you want to set the priority of the layer to other than the
1089 default value of "6", you can either use the
1090 <filename>&dash;&dash;priority</filename> option or you can
1091 edit the
1092 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
1093 value in the <filename>conf/layer.conf</filename> after the
1094 script creates it.
1095 Furthermore, if you want to give the example recipe file
1096 some name other than the default, you can
1097 use the
1098 <filename>&dash;&dash;example-recipe-name</filename> option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001099 </para>
1100
1101 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001102 The easiest way to see how the
1103 <filename>bitbake-layers create-layer</filename> command
1104 works is to experiment with the script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001105 You can also read the usage information by entering the
1106 following:
1107 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001108 $ bitbake-layers create-layer --help
1109 NOTE: Starting bitbake server...
1110 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
1111 [--example-recipe-name EXAMPLERECIPE]
1112 layerdir
1113
1114 Create a basic layer
1115
1116 positional arguments:
1117 layerdir Layer directory to create
1118
1119 optional arguments:
1120 -h, --help show this help message and exit
1121 --priority PRIORITY, -p PRIORITY
1122 Layer directory to create
1123 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
1124 Filename of the example recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001125 </literallayout>
1126 </para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001127 </section>
1128
1129 <section id='adding-a-layer-using-the-bitbake-layers-script'>
1130 <title>Adding a Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001131
1132 <para>
1133 Once you create your general layer, you must add it to your
1134 <filename>bblayers.conf</filename> file.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001135 Adding the layer to this configuration file makes the
1136 OpenEmbedded build system aware of your layer so that it can
1137 search it for metadata.
1138 </para>
1139
1140 <para>
1141 Add your layer by using the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001142 <filename>bitbake-layers add-layer</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001143 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001144 $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable>
1145 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001146 Here is an example that adds a layer named
1147 <filename>meta-scottrif</filename> to the configuration file.
1148 Following the command that adds the layer is another
1149 <filename>bitbake-layers</filename> command that shows the
1150 layers that are in your <filename>bblayers.conf</filename>
1151 file:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001152 <literallayout class='monospaced'>
1153 $ bitbake-layers add-layer meta-scottrif
1154 NOTE: Starting bitbake server...
Brad Bishop316dfdd2018-06-25 12:45:53 -04001155 Parsing recipes: 100% |##########################################################| Time: 0:00:49
1156 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001157 $ bitbake-layers show-layers
1158 NOTE: Starting bitbake server...
1159 layer path priority
1160 ==========================================================================
1161 meta /home/scottrif/poky/meta 5
1162 meta-poky /home/scottrif/poky/meta-poky 5
1163 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001164 workspace /home/scottrif/poky/build/workspace 99
1165 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001166 </literallayout>
1167 Adding the layer to this file enables the build system to
1168 locate the layer during the build.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001169 <note>
1170 During a build, the OpenEmbedded build system looks in
1171 the layers from the top of the list down to the bottom
1172 in that order.
1173 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001174 </para>
1175 </section>
1176 </section>
1177
1178 <section id='usingpoky-extend-customimage'>
1179 <title>Customizing Images</title>
1180
1181 <para>
1182 You can customize images to satisfy particular requirements.
1183 This section describes several methods and provides guidelines for each.
1184 </para>
1185
1186 <section id='usingpoky-extend-customimage-localconf'>
1187 <title>Customizing Images Using <filename>local.conf</filename></title>
1188
1189 <para>
1190 Probably the easiest way to customize an image is to add a
1191 package by way of the <filename>local.conf</filename>
1192 configuration file.
1193 Because it is limited to local use, this method generally only
1194 allows you to add packages and is not as flexible as creating
1195 your own customized image.
1196 When you add packages using local variables this way, you need
1197 to realize that these variable changes are in effect for every
1198 build and consequently affect all images, which might not
1199 be what you require.
1200 </para>
1201
1202 <para>
1203 To add a package to your image using the local configuration
1204 file, use the
1205 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1206 variable with the <filename>_append</filename> operator:
1207 <literallayout class='monospaced'>
1208 IMAGE_INSTALL_append = " strace"
1209 </literallayout>
1210 Use of the syntax is important - specifically, the space between
1211 the quote and the package name, which is
1212 <filename>strace</filename> in this example.
1213 This space is required since the <filename>_append</filename>
1214 operator does not add the space.
1215 </para>
1216
1217 <para>
1218 Furthermore, you must use <filename>_append</filename> instead
1219 of the <filename>+=</filename> operator if you want to avoid
1220 ordering issues.
1221 The reason for this is because doing so unconditionally appends
1222 to the variable and avoids ordering problems due to the
1223 variable being set in image recipes and
1224 <filename>.bbclass</filename> files with operators like
1225 <filename>?=</filename>.
1226 Using <filename>_append</filename> ensures the operation takes
1227 affect.
1228 </para>
1229
1230 <para>
1231 As shown in its simplest use,
1232 <filename>IMAGE_INSTALL_append</filename> affects all images.
1233 It is possible to extend the syntax so that the variable
1234 applies to a specific image only.
1235 Here is an example:
1236 <literallayout class='monospaced'>
1237 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
1238 </literallayout>
1239 This example adds <filename>strace</filename> to the
1240 <filename>core-image-minimal</filename> image only.
1241 </para>
1242
1243 <para>
1244 You can add packages using a similar approach through the
1245 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
1246 variable.
1247 If you use this variable, only
1248 <filename>core-image-*</filename> images are affected.
1249 </para>
1250 </section>
1251
1252 <section id='usingpoky-extend-customimage-imagefeatures'>
1253 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
1254 <filename>EXTRA_IMAGE_FEATURES</filename></title>
1255
1256 <para>
1257 Another method for customizing your image is to enable or
1258 disable high-level image features by using the
1259 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
1260 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
1261 variables.
1262 Although the functions for both variables are nearly equivalent,
1263 best practices dictate using <filename>IMAGE_FEATURES</filename>
1264 from within a recipe and using
1265 <filename>EXTRA_IMAGE_FEATURES</filename> from within
1266 your <filename>local.conf</filename> file, which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001267 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001268 </para>
1269
1270 <para>
1271 To understand how these features work, the best reference is
1272 <filename>meta/classes/core-image.bbclass</filename>.
1273 This class lists out the available
Brad Bishop316dfdd2018-06-25 12:45:53 -04001274 <filename>IMAGE_FEATURES</filename> of which most map to
1275 package groups while some, such as
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001276 <filename>debug-tweaks</filename> and
1277 <filename>read-only-rootfs</filename>, resolve as general
1278 configuration settings.
1279 </para>
1280
1281 <para>
1282 In summary, the file looks at the contents of the
1283 <filename>IMAGE_FEATURES</filename> variable and then maps
1284 or configures the feature accordingly.
1285 Based on this information, the build system automatically
1286 adds the appropriate packages or configurations to the
1287 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
1288 variable.
1289 Effectively, you are enabling extra features by extending the
1290 class or creating a custom class for use with specialized image
1291 <filename>.bb</filename> files.
1292 </para>
1293
1294 <para>
1295 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1296 from within your local configuration file.
1297 Using a separate area from which to enable features with
1298 this variable helps you avoid overwriting the features in the
1299 image recipe that are enabled with
1300 <filename>IMAGE_FEATURES</filename>.
1301 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1302 to <filename>IMAGE_FEATURES</filename> within
1303 <filename>meta/conf/bitbake.conf</filename>.
1304 </para>
1305
1306 <para>
1307 To illustrate how you can use these variables to modify your
1308 image, consider an example that selects the SSH server.
1309 The Yocto Project ships with two SSH servers you can use
1310 with your images: Dropbear and OpenSSH.
1311 Dropbear is a minimal SSH server appropriate for
1312 resource-constrained environments, while OpenSSH is a
1313 well-known standard SSH server implementation.
1314 By default, the <filename>core-image-sato</filename> image
1315 is configured to use Dropbear.
1316 The <filename>core-image-full-cmdline</filename> and
1317 <filename>core-image-lsb</filename> images both
1318 include OpenSSH.
1319 The <filename>core-image-minimal</filename> image does not
1320 contain an SSH server.
1321 </para>
1322
1323 <para>
1324 You can customize your image and change these defaults.
1325 Edit the <filename>IMAGE_FEATURES</filename> variable
1326 in your recipe or use the
1327 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1328 <filename>local.conf</filename> file so that it configures the
1329 image you are working with to include
1330 <filename>ssh-server-dropbear</filename> or
1331 <filename>ssh-server-openssh</filename>.
1332 </para>
1333
1334 <note>
1335 See the
1336 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1337 section in the Yocto Project Reference Manual for a complete
1338 list of image features that ship with the Yocto Project.
1339 </note>
1340 </section>
1341
1342 <section id='usingpoky-extend-customimage-custombb'>
1343 <title>Customizing Images Using Custom .bb Files</title>
1344
1345 <para>
1346 You can also customize an image by creating a custom recipe
1347 that defines additional software as part of the image.
1348 The following example shows the form for the two lines you need:
1349 <literallayout class='monospaced'>
1350 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1351
1352 inherit core-image
1353 </literallayout>
1354 </para>
1355
1356 <para>
1357 Defining the software using a custom recipe gives you total
1358 control over the contents of the image.
1359 It is important to use the correct names of packages in the
1360 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1361 variable.
1362 You must use the OpenEmbedded notation and not the Debian notation for the names
1363 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1364 </para>
1365
1366 <para>
1367 The other method for creating a custom image is to base it on an existing image.
1368 For example, if you want to create an image based on <filename>core-image-sato</filename>
1369 but add the additional package <filename>strace</filename> to the image,
1370 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1371 new <filename>.bb</filename> and add the following line to the end of the copy:
1372 <literallayout class='monospaced'>
1373 IMAGE_INSTALL += "strace"
1374 </literallayout>
1375 </para>
1376 </section>
1377
1378 <section id='usingpoky-extend-customimage-customtasks'>
1379 <title>Customizing Images Using Custom Package Groups</title>
1380
1381 <para>
1382 For complex custom images, the best approach for customizing
1383 an image is to create a custom package group recipe that is
1384 used to build the image or images.
1385 A good example of a package group recipe is
1386 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1387 </para>
1388
1389 <para>
1390 If you examine that recipe, you see that the
1391 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1392 variable lists the package group packages to produce.
1393 The <filename>inherit packagegroup</filename> statement
1394 sets appropriate default values and automatically adds
1395 <filename>-dev</filename>, <filename>-dbg</filename>, and
1396 <filename>-ptest</filename> complementary packages for each
1397 package specified in the <filename>PACKAGES</filename>
1398 statement.
1399 <note>
1400 The <filename>inherit packages</filename> should be
1401 located near the top of the recipe, certainly before
1402 the <filename>PACKAGES</filename> statement.
1403 </note>
1404 </para>
1405
1406 <para>
1407 For each package you specify in <filename>PACKAGES</filename>,
1408 you can use
1409 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1410 and
1411 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1412 entries to provide a list of packages the parent task package
1413 should contain.
1414 You can see examples of these further down in the
1415 <filename>packagegroup-base.bb</filename> recipe.
1416 </para>
1417
1418 <para>
1419 Here is a short, fabricated example showing the same basic
1420 pieces:
1421 <literallayout class='monospaced'>
1422 DESCRIPTION = "My Custom Package Groups"
1423
1424 inherit packagegroup
1425
1426 PACKAGES = "\
1427 packagegroup-custom-apps \
1428 packagegroup-custom-tools \
1429 "
1430
1431 RDEPENDS_packagegroup-custom-apps = "\
1432 dropbear \
1433 portmap \
1434 psplash"
1435
1436 RDEPENDS_packagegroup-custom-tools = "\
1437 oprofile \
1438 oprofileui-server \
1439 lttng-tools"
1440
1441 RRECOMMENDS_packagegroup-custom-tools = "\
1442 kernel-module-oprofile"
1443 </literallayout>
1444 </para>
1445
1446 <para>
1447 In the previous example, two package group packages are created with their dependencies and their
1448 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1449 <filename>packagegroup-custom-tools</filename>.
1450 To build an image using these package group packages, you need to add
1451 <filename>packagegroup-custom-apps</filename> and/or
1452 <filename>packagegroup-custom-tools</filename> to
1453 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1454 For other forms of image dependencies see the other areas of this section.
1455 </para>
1456 </section>
1457
1458 <section id='usingpoky-extend-customimage-image-name'>
1459 <title>Customizing an Image Hostname</title>
1460
1461 <para>
1462 By default, the configured hostname (i.e.
1463 <filename>/etc/hostname</filename>) in an image is the
1464 same as the machine name.
1465 For example, if
1466 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1467 equals "qemux86", the configured hostname written to
1468 <filename>/etc/hostname</filename> is "qemux86".
1469 </para>
1470
1471 <para>
1472 You can customize this name by altering the value of the
1473 "hostname" variable in the
1474 <filename>base-files</filename> recipe using either
1475 an append file or a configuration file.
1476 Use the following in an append file:
1477 <literallayout class='monospaced'>
1478 hostname="myhostname"
1479 </literallayout>
1480 Use the following in a configuration file:
1481 <literallayout class='monospaced'>
1482 hostname_pn-base-files = "myhostname"
1483 </literallayout>
1484 </para>
1485
1486 <para>
1487 Changing the default value of the variable "hostname" can be
1488 useful in certain situations.
1489 For example, suppose you need to do extensive testing on an
1490 image and you would like to easily identify the image
1491 under test from existing images with typical default
1492 hostnames.
1493 In this situation, you could change the default hostname to
1494 "testme", which results in all the images using the name
1495 "testme".
1496 Once testing is complete and you do not need to rebuild the
1497 image for test any longer, you can easily reset the default
1498 hostname.
1499 </para>
1500
1501 <para>
1502 Another point of interest is that if you unset the variable,
1503 the image will have no default hostname in the filesystem.
1504 Here is an example that unsets the variable in a
1505 configuration file:
1506 <literallayout class='monospaced'>
1507 hostname_pn-base-files = ""
1508 </literallayout>
1509 Having no default hostname in the filesystem is suitable for
1510 environments that use dynamic hostnames such as virtual
1511 machines.
1512 </para>
1513 </section>
1514 </section>
1515
1516 <section id='new-recipe-writing-a-new-recipe'>
1517 <title>Writing a New Recipe</title>
1518
1519 <para>
1520 Recipes (<filename>.bb</filename> files) are fundamental components
1521 in the Yocto Project environment.
1522 Each software component built by the OpenEmbedded build system
1523 requires a recipe to define the component.
1524 This section describes how to create, write, and test a new
1525 recipe.
1526 <note>
1527 For information on variables that are useful for recipes and
1528 for information about recipe naming issues, see the
1529 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1530 section of the Yocto Project Reference Manual.
1531 </note>
1532 </para>
1533
1534 <section id='new-recipe-overview'>
1535 <title>Overview</title>
1536
1537 <para>
1538 The following figure shows the basic process for creating a
1539 new recipe.
1540 The remainder of the section provides details for the steps.
1541 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1542 </para>
1543 </section>
1544
1545 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1546 <title>Locate or Automatically Create a Base Recipe</title>
1547
1548 <para>
1549 You can always write a recipe from scratch.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001550 However, three choices exist that can help you quickly get a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001551 start on a new recipe:
1552 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001553 <listitem><para>
1554 <emphasis><filename>devtool add</filename>:</emphasis>
1555 A command that assists in creating a recipe and
1556 an environment conducive to development.
1557 </para></listitem>
1558 <listitem><para>
1559 <emphasis><filename>recipetool create</filename>:</emphasis>
1560 A command provided by the Yocto Project that automates
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001561 creation of a base recipe based on the source
1562 files.
1563 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001564 <listitem><para>
1565 <emphasis>Existing Recipes:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001566 Location and modification of an existing recipe that is
1567 similar in function to the recipe you need.
1568 </para></listitem>
1569 </itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001570 <note>
1571 For information on recipe syntax, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001572 "<link linkend='recipe-syntax'>Recipe Syntax</link>"
1573 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001574 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001575 </para>
1576
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001577 <section id='new-recipe-creating-the-base-recipe-using-devtool'>
1578 <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001579
1580 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001581 The <filename>devtool add</filename> command uses the same
1582 logic for auto-creating the recipe as
1583 <filename>recipetool create</filename>, which is listed
1584 below.
1585 Additionally, however, <filename>devtool add</filename>
1586 sets up an environment that makes it easy for you to
1587 patch the source and to make changes to the recipe as
1588 is often necessary when adding a recipe to build a new
1589 piece of software to be included in a build.
1590 </para>
1591
1592 <para>
1593 You can find a complete description of the
1594 <filename>devtool add</filename> command in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001595 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>"
1596 section in the Yocto Project Application Development
1597 and the Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001598 </para>
1599 </section>
1600
1601 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1602 <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
1603
1604 <para>
1605 <filename>recipetool create</filename> automates creation
1606 of a base recipe given a set of source code files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001607 As long as you can extract or point to the source files,
1608 the tool will construct a recipe and automatically
1609 configure all pre-build information into the recipe.
1610 For example, suppose you have an application that builds
1611 using Autotools.
1612 Creating the base recipe using
1613 <filename>recipetool</filename> results in a recipe
1614 that has the pre-build dependencies, license requirements,
1615 and checksums configured.
1616 </para>
1617
1618 <para>
1619 To run the tool, you just need to be in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001621 and have sourced the build environment setup script
1622 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001623 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
Brad Bishop316dfdd2018-06-25 12:45:53 -04001624 To get help on the tool, use the following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001625 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001626 $ recipetool -h
1627 NOTE: Starting bitbake server...
1628 usage: recipetool [-d] [-q] [--color COLOR] [-h] &lt;subcommand&gt; ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001629
Brad Bishop316dfdd2018-06-25 12:45:53 -04001630 OpenEmbedded recipe tool
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001631
Brad Bishop316dfdd2018-06-25 12:45:53 -04001632 options:
1633 -d, --debug Enable debug output
1634 -q, --quiet Print only errors
1635 --color COLOR Colorize output (where COLOR is auto, always, never)
1636 -h, --help show this help message and exit
1637
1638 subcommands:
1639 create Create a new recipe
1640 newappend Create a bbappend for the specified target in the specified
1641 layer
1642 setvar Set a variable within a recipe
1643 appendfile Create/update a bbappend to replace a target file
1644 appendsrcfiles Create/update a bbappend to add or replace source files
1645 appendsrcfile Create/update a bbappend to add or replace a source file
1646 Use recipetool &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001647 </literallayout>
1648 </para>
1649
1650 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001651 Running
1652 <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001653 creates the base recipe and locates it properly in the
1654 layer that contains your source files.
1655 Following are some syntax examples:
1656 </para>
1657
1658 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001659 Use this syntax to generate a recipe based on
1660 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001661 Once generated, the recipe resides in the existing source
1662 code layer:
1663 <literallayout class='monospaced'>
1664 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1665 </literallayout>
1666 Use this syntax to generate a recipe using code that you
1667 extract from <replaceable>source</replaceable>.
1668 The extracted code is placed in its own layer defined
1669 by <replaceable>EXTERNALSRC</replaceable>.
1670 <literallayout class='monospaced'>
1671 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1672 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001673 Use this syntax to generate a recipe based on
1674 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001675 The options direct <filename>recipetool</filename> to
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001676 generate debugging information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001677 Once generated, the recipe resides in the existing source
1678 code layer:
1679 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001680 recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001681 </literallayout>
1682 </para>
1683 </section>
1684
1685 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1686 <title>Locating and Using a Similar Recipe</title>
1687
1688 <para>
1689 Before writing a recipe from scratch, it is often useful to
1690 discover whether someone else has already written one that
1691 meets (or comes close to meeting) your needs.
1692 The Yocto Project and OpenEmbedded communities maintain many
1693 recipes that might be candidates for what you are doing.
1694 You can find a good central index of these recipes in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001695 <ulink url='http://layers.openembedded.org'>OpenEmbedded Layer Index</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001696 </para>
1697
1698 <para>
1699 Working from an existing recipe or a skeleton recipe is the
1700 best way to get started.
1701 Here are some points on both methods:
1702 <itemizedlist>
1703 <listitem><para><emphasis>Locate and modify a recipe that
1704 is close to what you want to do:</emphasis>
1705 This method works when you are familiar with the
1706 current recipe space.
1707 The method does not work so well for those new to
1708 the Yocto Project or writing recipes.</para>
1709 <para>Some risks associated with this method are
1710 using a recipe that has areas totally unrelated to
1711 what you are trying to accomplish with your recipe,
1712 not recognizing areas of the recipe that you might
1713 have to add from scratch, and so forth.
1714 All these risks stem from unfamiliarity with the
1715 existing recipe space.</para></listitem>
1716 <listitem><para><emphasis>Use and modify the following
1717 skeleton recipe:</emphasis>
1718 If for some reason you do not want to use
1719 <filename>recipetool</filename> and you cannot
1720 find an existing recipe that is close to meeting
1721 your needs, you can use the following structure to
1722 provide the fundamental areas of a new recipe.
1723 <literallayout class='monospaced'>
1724 DESCRIPTION = ""
1725 HOMEPAGE = ""
1726 LICENSE = ""
1727 SECTION = ""
1728 DEPENDS = ""
1729 LIC_FILES_CHKSUM = ""
1730
1731 SRC_URI = ""
1732 </literallayout>
1733 </para></listitem>
1734 </itemizedlist>
1735 </para>
1736 </section>
1737 </section>
1738
1739 <section id='new-recipe-storing-and-naming-the-recipe'>
1740 <title>Storing and Naming the Recipe</title>
1741
1742 <para>
1743 Once you have your base recipe, you should put it in your
1744 own layer and name it appropriately.
1745 Locating it correctly ensures that the OpenEmbedded build
1746 system can find it when you use BitBake to process the
1747 recipe.
1748 </para>
1749
1750 <itemizedlist>
1751 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1752 The OpenEmbedded build system locates your recipe
1753 through the layer's <filename>conf/layer.conf</filename>
1754 file and the
1755 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1756 variable.
1757 This variable sets up a path from which the build system can
1758 locate recipes.
1759 Here is the typical use:
1760 <literallayout class='monospaced'>
1761 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1762 ${LAYERDIR}/recipes-*/*/*.bbappend"
1763 </literallayout>
1764 Consequently, you need to be sure you locate your new recipe
1765 inside your layer such that it can be found.</para>
1766 <para>You can find more information on how layers are
1767 structured in the
1768 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1769 section.</para></listitem>
1770 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1771 When you name your recipe, you need to follow this naming
1772 convention:
1773 <literallayout class='monospaced'>
1774 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1775 </literallayout>
1776 Use lower-cased characters and do not include the reserved
1777 suffixes <filename>-native</filename>,
1778 <filename>-cross</filename>, <filename>-initial</filename>,
1779 or <filename>-dev</filename> casually (i.e. do not use them
1780 as part of your recipe name unless the string applies).
1781 Here are some examples:
1782 <literallayout class='monospaced'>
1783 cups_1.7.0.bb
1784 gawk_4.0.2.bb
1785 irssi_0.8.16-rc1.bb
1786 </literallayout></para></listitem>
1787 </itemizedlist>
1788 </section>
1789
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001790 <section id='new-recipe-running-a-build-on-the-recipe'>
1791 <title>Running a Build on the Recipe</title>
1792
1793 <para>
1794 Creating a new recipe is usually an iterative process that
1795 requires using BitBake to process the recipe multiple times in
1796 order to progressively discover and add information to the
1797 recipe file.
1798 </para>
1799
1800 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001801 Assuming you have sourced the build environment setup script (i.e.
1802 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001803 and you are in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001804 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001805 use BitBake to process your recipe.
1806 All you need to provide is the
1807 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1808 in the previous section:
1809 <literallayout class='monospaced'>
1810 $ bitbake <replaceable>basename</replaceable>
1811 </literallayout>
1812
1813 </para>
1814
1815 <para>
1816 During the build, the OpenEmbedded build system creates a
1817 temporary work directory for each recipe
1818 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1819 where it keeps extracted source files, log files, intermediate
1820 compilation and packaging files, and so forth.
1821 </para>
1822
1823 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001824 The path to the per-recipe temporary work directory depends
1825 on the context in which it is being built.
1826 The quickest way to find this path is to have BitBake return it
1827 by running the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001828 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001829 $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001830 </literallayout>
1831 As an example, assume a Source Directory top-level folder named
1832 <filename>poky</filename>, a default Build Directory at
1833 <filename>poky/build</filename>, and a
1834 <filename>qemux86-poky-linux</filename> machine target system.
1835 Furthermore, suppose your recipe is named
1836 <filename>foo_1.3.0.bb</filename>.
1837 In this case, the work directory the build system uses to
1838 build the package would be as follows:
1839 <literallayout class='monospaced'>
1840 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1841 </literallayout>
1842 Inside this directory you can find sub-directories such as
1843 <filename>image</filename>, <filename>packages-split</filename>,
1844 and <filename>temp</filename>.
1845 After the build, you can examine these to determine how well
1846 the build went.
1847 <note>
1848 You can find log files for each task in the recipe's
1849 <filename>temp</filename> directory (e.g.
1850 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1851 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1852 (e.g. <filename>log.do_configure</filename>,
1853 <filename>log.do_fetch</filename>, and
1854 <filename>log.do_compile</filename>).
1855 </note>
1856 </para>
1857
1858 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001859 You can find more information about the build process in
Brad Bishop316dfdd2018-06-25 12:45:53 -04001860 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-development-environment'>The Yocto Project Development Environment</ulink>"
1861 chapter of the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001862 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863 </section>
1864
1865 <section id='new-recipe-fetching-code'>
1866 <title>Fetching Code</title>
1867
1868 <para>
1869 The first thing your recipe must do is specify how to fetch
1870 the source files.
1871 Fetching is controlled mainly through the
1872 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1873 variable.
1874 Your recipe must have a <filename>SRC_URI</filename> variable
1875 that points to where the source is located.
1876 For a graphical representation of source locations, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001877 "<ulink url='&YOCTO_DOCS_OM_URL;#sources-dev-environment'>Sources</ulink>"
1878 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001879 </para>
1880
1881 <para>
1882 The
1883 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1884 task uses the prefix of each entry in the
1885 <filename>SRC_URI</filename> variable value to determine which
1886 fetcher to use to get your source files.
1887 It is the <filename>SRC_URI</filename> variable that triggers
1888 the fetcher.
1889 The
1890 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1891 task uses the variable after source is fetched to apply
1892 patches.
1893 The OpenEmbedded build system uses
1894 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1895 for scanning directory locations for local files in
1896 <filename>SRC_URI</filename>.
1897 </para>
1898
1899 <para>
1900 The <filename>SRC_URI</filename> variable in your recipe must
1901 define each unique location for your source files.
1902 It is good practice to not hard-code pathnames in an URL used
1903 in <filename>SRC_URI</filename>.
1904 Rather than hard-code these paths, use
1905 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1906 which causes the fetch process to use the version specified in
1907 the recipe filename.
1908 Specifying the version in this manner means that upgrading the
1909 recipe to a future version is as simple as renaming the recipe
1910 to match the new version.
1911 </para>
1912
1913 <para>
1914 Here is a simple example from the
1915 <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
1916 recipe where the source comes from a single tarball.
1917 Notice the use of the
1918 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1919 variable:
1920 <literallayout class='monospaced'>
1921 SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
1922 </literallayout>
1923 </para>
1924
1925 <para>
1926 Files mentioned in <filename>SRC_URI</filename> whose names end
1927 in a typical archive extension (e.g. <filename>.tar</filename>,
1928 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1929 <filename>.zip</filename>, and so forth), are automatically
1930 extracted during the
1931 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1932 task.
1933 For another example that specifies these types of files, see
1934 the
1935 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1936 section.
1937 </para>
1938
1939 <para>
1940 Another way of specifying source is from an SCM.
1941 For Git repositories, you must specify
1942 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1943 and you should specify
1944 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1945 to include the revision with
1946 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1947 Here is an example from the recipe
1948 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1949 <literallayout class='monospaced'>
1950 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1951
1952 PR = "r6"
1953 PV = "1.0.5+git${SRCPV}"
1954
1955 SRC_URI = "git://git.kernel.dk/blktrace.git \
1956 file://ldflags.patch"
1957 </literallayout>
1958 </para>
1959
1960 <para>
1961 If your <filename>SRC_URI</filename> statement includes
1962 URLs pointing to individual files fetched from a remote server
1963 other than a version control system, BitBake attempts to
1964 verify the files against checksums defined in your recipe to
1965 ensure they have not been tampered with or otherwise modified
1966 since the recipe was written.
1967 Two checksums are used:
1968 <filename>SRC_URI[md5sum]</filename> and
1969 <filename>SRC_URI[sha256sum]</filename>.
1970 </para>
1971
1972 <para>
1973 If your <filename>SRC_URI</filename> variable points to
1974 more than a single URL (excluding SCM URLs), you need to
1975 provide the <filename>md5</filename> and
1976 <filename>sha256</filename> checksums for each URL.
1977 For these cases, you provide a name for each URL as part of
1978 the <filename>SRC_URI</filename> and then reference that name
1979 in the subsequent checksum statements.
1980 Here is an example:
1981 <literallayout class='monospaced'>
1982 SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001983 ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001984
1985 SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
1986 SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
1987
1988 SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
1989 SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
1990 </literallayout>
1991 </para>
1992
1993 <para>
1994 Proper values for <filename>md5</filename> and
1995 <filename>sha256</filename> checksums might be available
1996 with other signatures on the download page for the upstream
1997 source (e.g. <filename>md5</filename>,
1998 <filename>sha1</filename>, <filename>sha256</filename>,
1999 <filename>GPG</filename>, and so forth).
2000 Because the OpenEmbedded build system only deals with
2001 <filename>sha256sum</filename> and <filename>md5sum</filename>,
2002 you should verify all the signatures you find by hand.
2003 </para>
2004
2005 <para>
2006 If no <filename>SRC_URI</filename> checksums are specified
2007 when you attempt to build the recipe, or you provide an
2008 incorrect checksum, the build will produce an error for each
2009 missing or incorrect checksum.
2010 As part of the error message, the build system provides
2011 the checksum string corresponding to the fetched file.
2012 Once you have the correct checksums, you can copy and paste
2013 them into your recipe and then run the build again to continue.
2014 <note>
2015 As mentioned, if the upstream source provides signatures
2016 for verifying the downloaded source code, you should
2017 verify those manually before setting the checksum values
2018 in the recipe and continuing with the build.
2019 </note>
2020 </para>
2021
2022 <para>
2023 This final example is a bit more complicated and is from the
2024 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2025 recipe.
2026 The example's <filename>SRC_URI</filename> statement identifies
2027 multiple files as the source files for the recipe: a tarball, a
2028 patch file, a desktop file, and an icon.
2029 <literallayout class='monospaced'>
2030 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2031 file://xwc.patch \
2032 file://rxvt.desktop \
2033 file://rxvt.png"
2034 </literallayout>
2035 </para>
2036
2037 <para>
2038 When you specify local files using the
2039 <filename>file://</filename> URI protocol, the build system
2040 fetches files from the local machine.
2041 The path is relative to the
2042 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2043 variable and searches specific directories in a certain order:
2044 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2045 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2046 and <filename>files</filename>.
2047 The directories are assumed to be subdirectories of the
2048 directory in which the recipe or append file resides.
2049 For another example that specifies these types of files, see the
2050 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2051 section.
2052 </para>
2053
2054 <para>
2055 The previous example also specifies a patch file.
2056 Patch files are files whose names usually end in
2057 <filename>.patch</filename> or <filename>.diff</filename> but
2058 can end with compressed suffixes such as
2059 <filename>diff.gz</filename> and
2060 <filename>patch.bz2</filename>, for example.
2061 The build system automatically applies patches as described
2062 in the
2063 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2064 </para>
2065 </section>
2066
2067 <section id='new-recipe-unpacking-code'>
2068 <title>Unpacking Code</title>
2069
2070 <para>
2071 During the build, the
2072 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2073 task unpacks the source with
2074 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2075 pointing to where it is unpacked.
2076 </para>
2077
2078 <para>
2079 If you are fetching your source files from an upstream source
2080 archived tarball and the tarball's internal structure matches
2081 the common convention of a top-level subdirectory named
2082 <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>,
2083 then you do not need to set <filename>S</filename>.
2084 However, if <filename>SRC_URI</filename> specifies to fetch
2085 source from an archive that does not use this convention,
2086 or from an SCM like Git or Subversion, your recipe needs to
2087 define <filename>S</filename>.
2088 </para>
2089
2090 <para>
2091 If processing your recipe using BitBake successfully unpacks
2092 the source files, you need to be sure that the directory
2093 pointed to by <filename>${S}</filename> matches the structure
2094 of the source.
2095 </para>
2096 </section>
2097
2098 <section id='new-recipe-patching-code'>
2099 <title>Patching Code</title>
2100
2101 <para>
2102 Sometimes it is necessary to patch code after it has been
2103 fetched.
2104 Any files mentioned in <filename>SRC_URI</filename> whose
2105 names end in <filename>.patch</filename> or
2106 <filename>.diff</filename> or compressed versions of these
2107 suffixes (e.g. <filename>diff.gz</filename> are treated as
2108 patches.
2109 The
2110 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2111 task automatically applies these patches.
2112 </para>
2113
2114 <para>
2115 The build system should be able to apply patches with the "-p1"
2116 option (i.e. one directory level in the path will be stripped
2117 off).
2118 If your patch needs to have more directory levels stripped off,
2119 specify the number of levels using the "striplevel" option in
2120 the <filename>SRC_URI</filename> entry for the patch.
2121 Alternatively, if your patch needs to be applied in a specific
2122 subdirectory that is not specified in the patch file, use the
2123 "patchdir" option in the entry.
2124 </para>
2125
2126 <para>
2127 As with all local files referenced in
2128 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2129 using <filename>file://</filename>, you should place
2130 patch files in a directory next to the recipe either
2131 named the same as the base name of the recipe
2132 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2133 and
2134 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2135 or "files".
2136 </para>
2137 </section>
2138
2139 <section id='new-recipe-licensing'>
2140 <title>Licensing</title>
2141
2142 <para>
2143 Your recipe needs to have both the
2144 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2145 and
2146 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2147 variables:
2148 <itemizedlist>
2149 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2150 This variable specifies the license for the software.
2151 If you do not know the license under which the software
2152 you are building is distributed, you should go to the
2153 source code and look for that information.
2154 Typical files containing this information include
2155 <filename>COPYING</filename>,
2156 <filename>LICENSE</filename>, and
2157 <filename>README</filename> files.
2158 You could also find the information near the top of
2159 a source file.
2160 For example, given a piece of software licensed under
2161 the GNU General Public License version 2, you would
2162 set <filename>LICENSE</filename> as follows:
2163 <literallayout class='monospaced'>
2164 LICENSE = "GPLv2"
2165 </literallayout></para>
2166 <para>The licenses you specify within
2167 <filename>LICENSE</filename> can have any name as long
2168 as you do not use spaces, since spaces are used as
2169 separators between license names.
2170 For standard licenses, use the names of the files in
2171 <filename>meta/files/common-licenses/</filename>
2172 or the <filename>SPDXLICENSEMAP</filename> flag names
2173 defined in <filename>meta/conf/licenses.conf</filename>.
2174 </para></listitem>
2175 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2176 The OpenEmbedded build system uses this variable to
2177 make sure the license text has not changed.
2178 If it has, the build produces an error and it affords
2179 you the chance to figure it out and correct the problem.
2180 </para>
2181 <para>You need to specify all applicable licensing
2182 files for the software.
2183 At the end of the configuration step, the build process
2184 will compare the checksums of the files to be sure
2185 the text has not changed.
2186 Any differences result in an error with the message
2187 containing the current checksum.
2188 For more explanation and examples of how to set the
2189 <filename>LIC_FILES_CHKSUM</filename> variable, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002190 "<link link='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
2191 section.</para>
2192
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002193 <para>To determine the correct checksum string, you
2194 can list the appropriate files in the
2195 <filename>LIC_FILES_CHKSUM</filename> variable with
2196 incorrect md5 strings, attempt to build the software,
2197 and then note the resulting error messages that will
2198 report the correct md5 strings.
2199 See the
2200 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2201 section for additional information.
2202 </para>
2203
2204 <para>
2205 Here is an example that assumes the software has a
2206 <filename>COPYING</filename> file:
2207 <literallayout class='monospaced'>
2208 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2209 </literallayout>
2210 When you try to build the software, the build system
2211 will produce an error and give you the correct string
2212 that you can substitute into the recipe file for a
2213 subsequent build.
2214 </para></listitem>
2215 </itemizedlist>
2216 </para>
2217
2218<!--
2219
2220 <para>
2221 For trying this out I created a new recipe named
2222 <filename>htop_1.0.2.bb</filename> and put it in
2223 <filename>poky/meta/recipes-extended/htop</filename>.
2224 There are two license type statements in my very simple
2225 recipe:
2226 <literallayout class='monospaced'>
2227 LICENSE = ""
2228
2229 LIC_FILES_CHKSUM = ""
2230
2231 SRC_URI[md5sum] = ""
2232 SRC_URI[sha256sum] = ""
2233 </literallayout>
2234 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2235 Next, you delete or comment out the two <filename>SRC_URI</filename>
2236 lines at the end and then attempt to build the software with
2237 <filename>bitbake htop</filename>.
2238 Doing so causes BitBake to report some errors and and give
2239 you the actual strings you need for the last two
2240 <filename>SRC_URI</filename> lines.
2241 Prior to this, you have to dig around in the home page of the
2242 source for <filename>htop</filename> and determine that the
2243 software is released under GPLv2.
2244 You can provide that in the <filename>LICENSE</filename>
2245 statement.
2246 Now you edit your recipe to have those two strings for
2247 the <filename>SRC_URI</filename> statements:
2248 <literallayout class='monospaced'>
2249 LICENSE = "GPLv2"
2250
2251 LIC_FILES_CHKSUM = ""
2252
2253 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2254 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2255 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2256 </literallayout>
2257 At this point, you can build the software again using the
2258 <filename>bitbake htop</filename> command.
2259 There is just a set of errors now associated with the
2260 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2261 </para>
2262-->
2263
2264 </section>
2265
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002266 <section id='new-dependencies'>
2267 <title>Dependencies</title>
2268
2269 <para>
2270 Most software packages have a short list of other packages
2271 that they require, which are called dependencies.
2272 These dependencies fall into two main categories: build-time
2273 dependencies, which are required when the software is built;
2274 and runtime dependencies, which are required to be installed
2275 on the target in order for the software to run.
2276 </para>
2277
2278 <para>
2279 Within a recipe, you specify build-time dependencies using the
2280 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2281 variable.
2282 Although nuances exist, items specified in
2283 <filename>DEPENDS</filename> should be names of other recipes.
2284 It is important that you specify all build-time dependencies
2285 explicitly.
2286 If you do not, due to the parallel nature of BitBake's
2287 execution, you can end up with a race condition where the
2288 dependency is present for one task of a recipe (e.g.
2289 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
2290 and then gone when the next task runs (e.g.
2291 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
2292 </para>
2293
2294 <para>
2295 Another consideration is that configure scripts might
2296 automatically check for optional dependencies and enable
2297 corresponding functionality if those dependencies are found.
2298 This behavior means that to ensure deterministic results and
2299 thus avoid more race conditions, you need to either explicitly
2300 specify these dependencies as well, or tell the configure
2301 script explicitly to disable the functionality.
2302 If you wish to make a recipe that is more generally useful
2303 (e.g. publish the recipe in a layer for others to use),
2304 instead of hard-disabling the functionality, you can use the
2305 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
2306 variable to allow functionality and the corresponding
2307 dependencies to be enabled and disabled easily by other
2308 users of the recipe.
2309 </para>
2310
2311 <para>
2312 Similar to build-time dependencies, you specify runtime
2313 dependencies through a variable -
2314 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
2315 which is package-specific.
2316 All variables that are package-specific need to have the name
2317 of the package added to the end as an override.
2318 Since the main package for a recipe has the same name as the
2319 recipe, and the recipe's name can be found through the
2320 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2321 variable, then you specify the dependencies for the main
2322 package by setting <filename>RDEPENDS_${PN}</filename>.
2323 If the package were named <filename>${PN}-tools</filename>,
2324 then you would set <filename>RDEPENDS_${PN}-tools</filename>,
2325 and so forth.
2326 </para>
2327
2328 <para>
2329 Some runtime dependencies will be set automatically at
2330 packaging time.
2331 These dependencies include any shared library dependencies
2332 (i.e. if a package "example" contains "libexample" and
2333 another package "mypackage" contains a binary that links to
2334 "libexample" then the OpenEmbedded build system will
2335 automatically add a runtime dependency to "mypackage" on
2336 "example").
2337 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002338 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
2339 section in the Yocto Project Overview and Concepts Manual for
2340 further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002341 </para>
2342 </section>
2343
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002344 <section id='new-recipe-configuring-the-recipe'>
2345 <title>Configuring the Recipe</title>
2346
2347 <para>
2348 Most software provides some means of setting build-time
2349 configuration options before compilation.
2350 Typically, setting these options is accomplished by running a
2351 configure script with some options, or by modifying a build
2352 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002353 <note>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002354 As of Yocto Project Release 1.7, some of the core recipes
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002355 that package binary configuration scripts now disable the
2356 scripts due to the scripts previously requiring error-prone
2357 path substitution.
2358 The OpenEmbedded build system uses
2359 <filename>pkg-config</filename> now, which is much more
2360 robust.
2361 You can find a list of the <filename>*-config</filename>
2362 scripts that are disabled list in the
2363 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2364 section in the Yocto Project Reference Manual.
2365 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002366 </para>
2367
2368 <para>
2369 A major part of build-time configuration is about checking for
2370 build-time dependencies and possibly enabling optional
2371 functionality as a result.
2372 You need to specify any build-time dependencies for the
2373 software you are building in your recipe's
2374 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2375 value, in terms of other recipes that satisfy those
2376 dependencies.
2377 You can often find build-time or runtime
2378 dependencies described in the software's documentation.
2379 </para>
2380
2381 <para>
2382 The following list provides configuration items of note based
2383 on how your software is built:
2384 <itemizedlist>
2385 <listitem><para><emphasis>Autotools:</emphasis>
2386 If your source files have a
2387 <filename>configure.ac</filename> file, then your
2388 software is built using Autotools.
2389 If this is the case, you just need to worry about
2390 modifying the configuration.</para>
2391 <para>When using Autotools, your recipe needs to inherit
2392 the
2393 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2394 class and your recipe does not have to contain a
2395 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2396 task.
2397 However, you might still want to make some adjustments.
2398 For example, you can set
2399 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002400 or
2401 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002402 to pass any needed configure options that are specific
2403 to the recipe.</para></listitem>
2404 <listitem><para><emphasis>CMake:</emphasis>
2405 If your source files have a
2406 <filename>CMakeLists.txt</filename> file, then your
2407 software is built using CMake.
2408 If this is the case, you just need to worry about
2409 modifying the configuration.</para>
2410 <para>When you use CMake, your recipe needs to inherit
2411 the
2412 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2413 class and your recipe does not have to contain a
2414 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2415 task.
2416 You can make some adjustments by setting
2417 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2418 to pass any needed configure options that are specific
2419 to the recipe.</para></listitem>
2420 <listitem><para><emphasis>Other:</emphasis>
2421 If your source files do not have a
2422 <filename>configure.ac</filename> or
2423 <filename>CMakeLists.txt</filename> file, then your
2424 software is built using some method other than Autotools
2425 or CMake.
2426 If this is the case, you normally need to provide a
2427 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2428 task in your recipe
2429 unless, of course, there is nothing to configure.
2430 </para>
2431 <para>Even if your software is not being built by
2432 Autotools or CMake, you still might not need to deal
2433 with any configuration issues.
2434 You need to determine if configuration is even a required step.
2435 You might need to modify a Makefile or some configuration file
2436 used for the build to specify necessary build options.
2437 Or, perhaps you might need to run a provided, custom
2438 configure script with the appropriate options.</para>
2439 <para>For the case involving a custom configure
2440 script, you would run
2441 <filename>./configure --help</filename> and look for
2442 the options you need to set.</para></listitem>
2443 </itemizedlist>
2444 </para>
2445
2446 <para>
2447 Once configuration succeeds, it is always good practice to
2448 look at the <filename>log.do_configure</filename> file to
2449 ensure that the appropriate options have been enabled and no
2450 additional build-time dependencies need to be added to
2451 <filename>DEPENDS</filename>.
2452 For example, if the configure script reports that it found
2453 something not mentioned in <filename>DEPENDS</filename>, or
2454 that it did not find something that it needed for some
2455 desired optional functionality, then you would need to add
2456 those to <filename>DEPENDS</filename>.
2457 Looking at the log might also reveal items being checked for,
2458 enabled, or both that you do not want, or items not being found
2459 that are in <filename>DEPENDS</filename>, in which case
2460 you would need to look at passing extra options to the
2461 configure script as needed.
2462 For reference information on configure options specific to the
2463 software you are building, you can consult the output of the
2464 <filename>./configure --help</filename> command within
2465 <filename>${S}</filename> or consult the software's upstream
2466 documentation.
2467 </para>
2468 </section>
2469
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002470 <section id='new-recipe-using-headers-to-interface-with-devices'>
2471 <title>Using Headers to Interface with Devices</title>
2472
2473 <para>
2474 If your recipe builds an application that needs to
2475 communicate with some device or needs an API into a custom
2476 kernel, you will need to provide appropriate header files.
2477 Under no circumstances should you ever modify the existing
2478 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>
2479 file.
2480 These headers are used to build <filename>libc</filename> and
2481 must not be compromised with custom or machine-specific
2482 header information.
2483 If you customize <filename>libc</filename> through modified
2484 headers all other applications that use
2485 <filename>libc</filename> thus become affected.
2486 <note><title>Warning</title>
2487 Never copy and customize the <filename>libc</filename>
2488 header file (i.e.
2489 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>).
2490 </note>
2491 The correct way to interface to a device or custom kernel is
2492 to use a separate package that provides the additional headers
2493 for the driver or other unique interfaces.
2494 When doing so, your application also becomes responsible for
2495 creating a dependency on that specific provider.
2496 </para>
2497
2498 <para>
2499 Consider the following:
2500 <itemizedlist>
2501 <listitem><para>
2502 Never modify
2503 <filename>linux-libc-headers.inc</filename>.
2504 Consider that file to be part of the
2505 <filename>libc</filename> system, and not something
2506 you use to access the kernel directly.
2507 You should access <filename>libc</filename> through
2508 specific <filename>libc</filename> calls.
2509 </para></listitem>
2510 <listitem><para>
2511 Applications that must talk directly to devices
2512 should either provide necessary headers themselves,
2513 or establish a dependency on a special headers package
2514 that is specific to that driver.
2515 </para></listitem>
2516 </itemizedlist>
2517 </para>
2518
2519 <para>
2520 For example, suppose you want to modify an existing header
2521 that adds I/O control or network support.
2522 If the modifications are used by a small number programs,
2523 providing a unique version of a header is easy and has little
2524 impact.
2525 When doing so, bear in mind the guidelines in the previous
2526 list.
2527 <note>
2528 If for some reason your changes need to modify the behavior
2529 of the <filename>libc</filename>, and subsequently all
2530 other applications on the system, use a
2531 <filename>.bbappend</filename> to modify the
2532 <filename>linux-kernel-headers.inc</filename> file.
2533 However, take care to not make the changes
2534 machine specific.
2535 </note>
2536 </para>
2537
2538 <para>
2539 Consider a case where your kernel is older and you need
2540 an older <filename>libc</filename> ABI.
2541 The headers installed by your recipe should still be a
2542 standard mainline kernel, not your own custom one.
2543 </para>
2544
2545 <para>
2546 When you use custom kernel headers you need to get them from
2547 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>,
2548 which is the directory with kernel headers that are
2549 required to build out-of-tree modules.
2550 Your recipe will also need the following:
2551 <literallayout class='monospaced'>
2552 do_configure[depends] += "virtual/kernel:do_shared_workdir"
2553 </literallayout>
2554 </para>
2555 </section>
2556
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002557 <section id='new-recipe-compilation'>
2558 <title>Compilation</title>
2559
2560 <para>
2561 During a build, the <filename>do_compile</filename> task
2562 happens after source is fetched, unpacked, and configured.
2563 If the recipe passes through <filename>do_compile</filename>
2564 successfully, nothing needs to be done.
2565 </para>
2566
2567 <para>
2568 However, if the compile step fails, you need to diagnose the
2569 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002570 Here are some common issues that cause failures.
2571 <note>
2572 For cases where improper paths are detected for
2573 configuration files or for when libraries/headers cannot
2574 be found, be sure you are using the more robust
2575 <filename>pkg-config</filename>.
2576 See the note in section
2577 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2578 for additional information.
2579 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002580 <itemizedlist>
2581 <listitem><para><emphasis>Parallel build failures:</emphasis>
2582 These failures manifest themselves as intermittent
2583 errors, or errors reporting that a file or directory
2584 that should be created by some other part of the build
2585 process could not be found.
2586 This type of failure can occur even if, upon inspection,
2587 the file or directory does exist after the build has
2588 failed, because that part of the build process happened
2589 in the wrong order.</para>
2590 <para>To fix the problem, you need to either satisfy
2591 the missing dependency in the Makefile or whatever
2592 script produced the Makefile, or (as a workaround)
2593 set
2594 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2595 to an empty string:
2596 <literallayout class='monospaced'>
2597 PARALLEL_MAKE = ""
2598 </literallayout></para>
2599 <para>
2600 For information on parallel Makefile issues, see the
2601 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2602 section.
2603 </para></listitem>
2604 <listitem><para><emphasis>Improper host path usage:</emphasis>
2605 This failure applies to recipes building for the target
2606 or <filename>nativesdk</filename> only.
2607 The failure occurs when the compilation process uses
2608 improper headers, libraries, or other files from the
2609 host system when cross-compiling for the target.
2610 </para>
2611 <para>To fix the problem, examine the
2612 <filename>log.do_compile</filename> file to identify
2613 the host paths being used (e.g.
2614 <filename>/usr/include</filename>,
2615 <filename>/usr/lib</filename>, and so forth) and then
2616 either add configure options, apply a patch, or do both.
2617 </para></listitem>
2618 <listitem><para><emphasis>Failure to find required
2619 libraries/headers:</emphasis>
2620 If a build-time dependency is missing because it has
2621 not been declared in
2622 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2623 or because the dependency exists but the path used by
2624 the build process to find the file is incorrect and the
2625 configure step did not detect it, the compilation
2626 process could fail.
2627 For either of these failures, the compilation process
2628 notes that files could not be found.
2629 In these cases, you need to go back and add additional
2630 options to the configure script as well as possibly
2631 add additional build-time dependencies to
2632 <filename>DEPENDS</filename>.</para>
2633 <para>Occasionally, it is necessary to apply a patch
2634 to the source to ensure the correct paths are used.
2635 If you need to specify paths to find files staged
2636 into the sysroot from other recipes, use the variables
2637 that the OpenEmbedded build system provides
2638 (e.g.
2639 <filename>STAGING_BINDIR</filename>,
2640 <filename>STAGING_INCDIR</filename>,
2641 <filename>STAGING_DATADIR</filename>, and so forth).
2642<!--
2643 (e.g.
2644 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2645 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2646 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2647 and so forth).
2648-->
2649 </para></listitem>
2650 </itemizedlist>
2651 </para>
2652 </section>
2653
2654 <section id='new-recipe-installing'>
2655 <title>Installing</title>
2656
2657 <para>
2658 During <filename>do_install</filename>, the task copies the
2659 built files along with their hierarchy to locations that
2660 would mirror their locations on the target device.
2661 The installation process copies files from the
2662 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2663 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2664 and
2665 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2666 directories to the
2667 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2668 directory to create the structure as it should appear on the
2669 target system.
2670 </para>
2671
2672 <para>
2673 How your software is built affects what you must do to be
2674 sure your software is installed correctly.
2675 The following list describes what you must do for installation
2676 depending on the type of build system used by the software
2677 being built:
2678 <itemizedlist>
2679 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2680 If the software your recipe is building uses Autotools
2681 or CMake, the OpenEmbedded build
2682 system understands how to install the software.
2683 Consequently, you do not have to have a
2684 <filename>do_install</filename> task as part of your
2685 recipe.
2686 You just need to make sure the install portion of the
2687 build completes with no issues.
2688 However, if you wish to install additional files not
2689 already being installed by
2690 <filename>make install</filename>, you should do this
2691 using a <filename>do_install_append</filename> function
2692 using the install command as described in
2693 the "Manual" bulleted item later in this list.
2694 </para></listitem>
2695 <listitem><para><emphasis>Other (using
2696 <filename>make install</filename>):</emphasis>
2697 You need to define a
2698 <filename>do_install</filename> function in your
2699 recipe.
2700 The function should call
2701 <filename>oe_runmake install</filename> and will likely
2702 need to pass in the destination directory as well.
2703 How you pass that path is dependent on how the
2704 <filename>Makefile</filename> being run is written
2705 (e.g. <filename>DESTDIR=${D}</filename>,
2706 <filename>PREFIX=${D}</filename>,
2707 <filename>INSTALLROOT=${D}</filename>, and so forth).
2708 </para>
2709 <para>For an example recipe using
2710 <filename>make install</filename>, see the
2711 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2712 section.</para></listitem>
2713 <listitem><para><emphasis>Manual:</emphasis>
2714 You need to define a
2715 <filename>do_install</filename> function in your
2716 recipe.
2717 The function must first use
2718 <filename>install -d</filename> to create the
2719 directories under
2720 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2721 Once the directories exist, your function can use
2722 <filename>install</filename> to manually install the
2723 built software into the directories.</para>
2724 <para>You can find more information on
2725 <filename>install</filename> at
2726 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2727 </para></listitem>
2728 </itemizedlist>
2729 </para>
2730
2731 <para>
2732 For the scenarios that do not use Autotools or
2733 CMake, you need to track the installation
2734 and diagnose and fix any issues until everything installs
2735 correctly.
2736 You need to look in the default location of
2737 <filename>${D}</filename>, which is
2738 <filename>${WORKDIR}/image</filename>, to be sure your
2739 files have been installed correctly.
2740 </para>
2741
2742 <note><title>Notes</title>
2743 <itemizedlist>
2744 <listitem><para>
2745 During the installation process, you might need to
2746 modify some of the installed files to suit the target
2747 layout.
2748 For example, you might need to replace hard-coded paths
2749 in an initscript with values of variables provided by
2750 the build system, such as replacing
2751 <filename>/usr/bin/</filename> with
2752 <filename>${bindir}</filename>.
2753 If you do perform such modifications during
2754 <filename>do_install</filename>, be sure to modify the
2755 destination file after copying rather than before
2756 copying.
2757 Modifying after copying ensures that the build system
2758 can re-execute <filename>do_install</filename> if
2759 needed.
2760 </para></listitem>
2761 <listitem><para>
2762 <filename>oe_runmake install</filename>, which can be
2763 run directly or can be run indirectly by the
2764 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2765 and
2766 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2767 classes, runs <filename>make install</filename> in
2768 parallel.
2769 Sometimes, a Makefile can have missing dependencies
2770 between targets that can result in race conditions.
2771 If you experience intermittent failures during
2772 <filename>do_install</filename>, you might be able to
2773 work around them by disabling parallel Makefile
2774 installs by adding the following to the recipe:
2775 <literallayout class='monospaced'>
2776 PARALLEL_MAKEINST = ""
2777 </literallayout>
2778 See
2779 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2780 for additional information.
2781 </para></listitem>
2782 </itemizedlist>
2783 </note>
2784 </section>
2785
2786 <section id='new-recipe-enabling-system-services'>
2787 <title>Enabling System Services</title>
2788
2789 <para>
2790 If you want to install a service, which is a process that
2791 usually starts on boot and runs in the background, then
2792 you must include some additional definitions in your recipe.
2793 </para>
2794
2795 <para>
2796 If you are adding services and the service initialization
2797 script or the service file itself is not installed, you must
2798 provide for that installation in your recipe using a
2799 <filename>do_install_append</filename> function.
2800 If your recipe already has a <filename>do_install</filename>
2801 function, update the function near its end rather than
2802 adding an additional <filename>do_install_append</filename>
2803 function.
2804 </para>
2805
2806 <para>
2807 When you create the installation for your services, you need
2808 to accomplish what is normally done by
2809 <filename>make install</filename>.
2810 In other words, make sure your installation arranges the output
2811 similar to how it is arranged on the target system.
2812 </para>
2813
2814 <para>
2815 The OpenEmbedded build system provides support for starting
2816 services two different ways:
2817 <itemizedlist>
2818 <listitem><para><emphasis>SysVinit:</emphasis>
2819 SysVinit is a system and service manager that
2820 manages the init system used to control the very basic
2821 functions of your system.
2822 The init program is the first program
2823 started by the Linux kernel when the system boots.
2824 Init then controls the startup, running and shutdown
2825 of all other programs.</para>
2826 <para>To enable a service using SysVinit, your recipe
2827 needs to inherit the
2828 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2829 class.
2830 The class helps facilitate safely installing the
2831 package on the target.</para>
2832 <para>You will need to set the
2833 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2834 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2835 and
2836 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2837 variables within your recipe.</para></listitem>
2838 <listitem><para><emphasis>systemd:</emphasis>
2839 System Management Daemon (systemd) was designed to
2840 replace SysVinit and to provide
2841 enhanced management of services.
2842 For more information on systemd, see the systemd
2843 homepage at
2844 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2845 </para>
2846 <para>To enable a service using systemd, your recipe
2847 needs to inherit the
2848 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2849 class.
2850 See the <filename>systemd.bbclass</filename> file
2851 located in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002852 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002853 section for more information.
2854 </para></listitem>
2855 </itemizedlist>
2856 </para>
2857 </section>
2858
2859 <section id='new-recipe-packaging'>
2860 <title>Packaging</title>
2861
2862 <para>
2863 Successful packaging is a combination of automated processes
2864 performed by the OpenEmbedded build system and some
2865 specific steps you need to take.
2866 The following list describes the process:
2867 <itemizedlist>
2868 <listitem><para><emphasis>Splitting Files</emphasis>:
2869 The <filename>do_package</filename> task splits the
2870 files produced by the recipe into logical components.
2871 Even software that produces a single binary might
2872 still have debug symbols, documentation, and other
2873 logical components that should be split out.
2874 The <filename>do_package</filename> task ensures
2875 that files are split up and packaged correctly.
2876 </para></listitem>
2877 <listitem><para><emphasis>Running QA Checks</emphasis>:
2878 The
2879 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2880 class adds a step to
2881 the package generation process so that output quality
2882 assurance checks are generated by the OpenEmbedded
2883 build system.
2884 This step performs a range of checks to be sure the
2885 build's output is free of common problems that show
2886 up during runtime.
2887 For information on these checks, see the
2888 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2889 class and the
2890 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2891 chapter in the Yocto Project Reference Manual.
2892 </para></listitem>
2893 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2894 After you build your software, you need to be sure
2895 your packages are correct.
2896 Examine the
2897 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2898 directory and make sure files are where you expect
2899 them to be.
2900 If you discover problems, you can set
2901 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2902 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2903 <filename>do_install(_append)</filename>, and so forth as
2904 needed.
2905 </para></listitem>
2906 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2907 If you need to split an application into several
2908 packages, see the
2909 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2910 section for an example.
2911 </para></listitem>
2912 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2913 For an example showing how to install a
2914 post-installation script, see the
2915 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2916 section.
2917 </para></listitem>
2918 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2919 Depending on what your recipe is building and how it
2920 is configured, it might be important to mark the
2921 packages produced as being specific to a particular
2922 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002923 a particular machine or architecture at all.</para>
2924 <para>By default, packages apply to any machine with the
2925 same architecture as the target machine.
2926 When a recipe produces packages that are
2927 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002928 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2929 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002930 is applied only for a particular machine), you should
2931 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002932 recipe:
2933 <literallayout class='monospaced'>
2934 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002935 </literallayout></para>
2936 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002937 that do not contain anything specific to the target
2938 machine or architecture at all (e.g. recipes
2939 that simply package script files or configuration
2940 files), you should use the
2941 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
2942 class to do this for you by adding this to your
2943 recipe:
2944 <literallayout class='monospaced'>
2945 inherit allarch
2946 </literallayout>
2947 Ensuring that the package architecture is correct is
2948 not critical while you are doing the first few builds
2949 of your recipe.
2950 However, it is important in order
2951 to ensure that your recipe rebuilds (or does not
2952 rebuild) appropriately in response to changes in
2953 configuration, and to ensure that you get the
2954 appropriate packages installed on the target machine,
2955 particularly if you run separate builds for more
2956 than one target machine.
2957 </para></listitem>
2958 </itemizedlist>
2959 </para>
2960 </section>
2961
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002962 <section id='new-sharing-files-between-recipes'>
2963 <title>Sharing Files Between Recipes</title>
2964
2965 <para>
2966 Recipes often need to use files provided by other recipes on
2967 the build host.
2968 For example, an application linking to a common library needs
2969 access to the library itself and its associated headers.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002970 The way this access is accomplished is by populating a sysroot
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002971 with files.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002972 Each recipe has two sysroots in its work directory, one for
2973 target files
2974 (<filename>recipe-sysroot</filename>) and one for files that
2975 are native to the build host
2976 (<filename>recipe-sysroot-native</filename>).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002977 <note>
2978 You could find the term "staging" used within the Yocto
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002979 project regarding files populating sysroots (e.g. the
Brad Bishop37a0e4d2017-12-04 01:01:44 -05002980 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink>
2981 variable).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002982 </note>
2983 </para>
2984
2985 <para>
2986 Recipes should never populate the sysroot directly (i.e. write
2987 files into sysroot).
2988 Instead, files should be installed into standard locations
2989 during the
2990 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2991 task within the
2992 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2993 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002994 The reason for this limitation is that almost all files that
2995 populate the sysroot are cataloged in manifests in order to
2996 ensure the files can be removed later when a recipe is either
2997 modified or removed.
2998 Thus, the sysroot is able to remain free from stale files.
2999 </para>
3000
3001 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003002 A subset of the files installed by the
3003 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3004 task are used by the
3005 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3006 task as defined by the the
3007 <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>
3008 variable to automatically populate the sysroot.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003009 It is possible to modify the list of directories that populate
3010 the sysroot.
3011 The following example shows how you could add the
3012 <filename>/opt</filename> directory to the list of
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003013 directories within a recipe:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003014 <literallayout class='monospaced'>
3015 SYSROOT_DIRS += "/opt"
3016 </literallayout>
3017 </para>
3018
3019 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003020 For a more complete description of the
3021 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3022 task and its associated functions, see the
3023 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink>
3024 class.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003025 </para>
3026 </section>
3027
Brad Bishop316dfdd2018-06-25 12:45:53 -04003028 <section id='metadata-virtual-providers'>
3029 <title>Using Virtual Providers</title>
3030
3031 <para>
3032 Prior to a build, if you know that several different recipes
3033 provide the same functionality, you can use a virtual provider
3034 (i.e. <filename>virtual/*</filename>) as a placeholder for the
3035 actual provider.
3036 The actual provider is determined at build-time.
3037 </para>
3038
3039 <para>
3040 A common scenario where a virtual provider is used would be
3041 for the kernel recipe.
3042 Suppose you have three kernel recipes whose
3043 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
3044 values map to <filename>kernel-big</filename>,
3045 <filename>kernel-mid</filename>, and
3046 <filename>kernel-small</filename>.
3047 Furthermore, each of these recipes in some way uses a
3048 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3049 statement that essentially identifies itself as being able
3050 to provide <filename>virtual/kernel</filename>.
3051 Here is one way through the
3052 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-kernel'><filename>kernel</filename></ulink>
3053 class:
3054 <literallayout class='monospaced'>
3055 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
3056 </literallayout>
3057 Any recipe that inherits the <filename>kernel</filename> class
3058 is going to utilize a <filename>PROVIDES</filename> statement
3059 that identifies that recipe as being able to provide the
3060 <filename>virtual/kernel</filename> item.
3061 </para>
3062
3063 <para>
3064 Now comes the time to actually build an image and you need a
3065 kernel recipe, but which one?
3066 You can configure your build to call out the kernel recipe
3067 you want by using the
3068 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></ulink>
3069 variable.
3070 As an example, consider the
3071 <ulink url='https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc'><filename>x86-base.inc</filename></ulink>
3072 include file, which is a machine
3073 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>)
3074 configuration file.
3075 This include file is the reason all x86-based machines use the
3076 <filename>linux-yocto</filename> kernel.
3077 Here are the relevant lines from the include file:
3078 <literallayout class='monospaced'>
3079 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
3080 PREFERRED_VERSION_linux-yocto ??= "4.15%"
3081 </literallayout>
3082 </para>
3083
3084 <para>
3085 When you use a virtual provider, you do not have to
3086 "hard code" a recipe name as a build dependency.
3087 You can use the
3088 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3089 variable to state the build is dependent on
3090 <filename>virtual/kernel</filename> for example:
3091 <literallayout class='monospaced'>
3092 DEPENDS = "virtual/kernel"
3093 </literallayout>
3094 During the build, the OpenEmbedded build system picks
3095 the correct recipe needed for the
3096 <filename>virtual/kernel</filename> dependency based on the
3097 <filename>PREFERRED_PROVIDER</filename> variable.
3098 If you want to use the small kernel mentioned at the beginning
3099 of this section, configure your build as follows:
3100 <literallayout class='monospaced'>
3101 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
3102 </literallayout>
3103 <note>
3104 Any recipe that
3105 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3106 a <filename>virtual/*</filename> item that is ultimately
3107 not selected through
3108 <filename>PREFERRED_PROVIDER</filename> does not get built.
3109 Preventing these recipes from building is usually the
3110 desired behavior since this mechanism's purpose is to
3111 select between mutually exclusive alternative providers.
3112 </note>
3113 </para>
3114
3115 <para>
3116 The following lists specific examples of virtual providers:
3117 <itemizedlist>
3118 <listitem><para>
3119 <filename>virtual/kernel</filename>:
3120 Provides the name of the kernel recipe to use when
3121 building a kernel image.
3122 </para></listitem>
3123 <listitem><para>
3124 <filename>virtual/bootloader</filename>:
3125 Provides the name of the bootloader to use when
3126 building an image.
3127 </para></listitem>
3128 <listitem><para>
3129 <filename>virtual/mesa</filename>:
3130 Provides <filename>gbm.pc</filename>.
3131 </para></listitem>
3132 <listitem><para>
3133 <filename>virtual/egl</filename>:
3134 Provides <filename>egl.pc</filename> and possibly
3135 <filename>wayland-egl.pc</filename>.
3136 </para></listitem>
3137 <listitem><para>
3138 <filename>virtual/libgl</filename>:
3139 Provides <filename>gl.pc</filename> (i.e. libGL).
3140 </para></listitem>
3141 <listitem><para>
3142 <filename>virtual/libgles1</filename>:
3143 Provides <filename>glesv1_cm.pc</filename>
3144 (i.e. libGLESv1_CM).
3145 </para></listitem>
3146 <listitem><para>
3147 <filename>virtual/libgles2</filename>:
3148 Provides <filename>glesv2.pc</filename>
3149 (i.e. libGLESv2).
3150 </para></listitem>
3151 </itemizedlist>
3152 </para>
3153 </section>
3154
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003155 <section id='properly-versioning-pre-release-recipes'>
3156 <title>Properly Versioning Pre-Release Recipes</title>
3157
3158 <para>
3159 Sometimes the name of a recipe can lead to versioning
3160 problems when the recipe is upgraded to a final release.
3161 For example, consider the
3162 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
3163 the list of example recipes in the
3164 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
3165 section.
3166 This recipe is at a release candidate stage (i.e.
3167 "rc1").
3168 When the recipe is released, the recipe filename becomes
3169 <filename>irssi_0.8.16.bb</filename>.
3170 The version change from <filename>0.8.16-rc1</filename>
3171 to <filename>0.8.16</filename> is seen as a decrease by the
3172 build system and package managers, so the resulting packages
3173 will not correctly trigger an upgrade.
3174 </para>
3175
3176 <para>
3177 In order to ensure the versions compare properly, the
3178 recommended convention is to set
3179 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
3180 within the recipe to
3181 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
3182 You can use an additional variable so that you can use the
3183 current version elsewhere.
3184 Here is an example:
3185 <literallayout class='monospaced'>
3186 REALPV = "0.8.16-rc1"
3187 PV = "0.8.15+${REALPV}"
3188 </literallayout>
3189 </para>
3190 </section>
3191
3192 <section id='new-recipe-post-installation-scripts'>
3193 <title>Post-Installation Scripts</title>
3194
3195 <para>
3196 Post-installation scripts run immediately after installing
3197 a package on the target or during image creation when a
3198 package is included in an image.
3199 To add a post-installation script to a package, add a
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003200 <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003201 the recipe file (<filename>.bb</filename>) and replace
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003202 <replaceable>PACKAGENAME</replaceable> with the name of the package
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003203 you want to attach to the <filename>postinst</filename>
3204 script.
3205 To apply the post-installation script to the main package
3206 for the recipe, which is usually what is required, specify
3207 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003208 in place of <replaceable>PACKAGENAME</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003209 </para>
3210
3211 <para>
3212 A post-installation function has the following structure:
3213 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003214 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003215 # Commands to carry out
3216 }
3217 </literallayout>
3218 </para>
3219
3220 <para>
3221 The script defined in the post-installation function is
3222 called when the root filesystem is created.
3223 If the script succeeds, the package is marked as installed.
3224 If the script fails, the package is marked as unpacked and
3225 the script is executed when the image boots again.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003226 <note>
3227 Any RPM post-installation script that runs on the target
3228 should return a 0 exit code.
3229 RPM does not allow non-zero exit codes for these scripts,
3230 and the RPM package manager will cause the package to fail
3231 installation on the target.
3232 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003233 </para>
3234
3235 <para>
3236 Sometimes it is necessary for the execution of a
3237 post-installation script to be delayed until the first boot.
3238 For example, the script might need to be executed on the
3239 device itself.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003240 To delay script execution until boot time, you must explicitly
3241 mark post installs to defer to the target.
3242 You can use <filename>pkg_postinst_ontarget()</filename> or
3243 call
3244 <filename>postinst-intercepts defer_to_first_boot</filename>
3245 from <filename>pkg_postinst()</filename>.
3246 Any failure of a <filename>pkg_postinst()</filename> script
3247 (including exit 1) triggers an error during the
3248 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
3249 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003250 </para>
3251
3252 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003253 If you have recipes that use
3254 <filename>pkg_postinst</filename> function
3255 and they require the use of non-standard native
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003256 tools that have dependencies during rootfs construction, you
3257 need to use the
3258 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3259 variable in your recipe to list these tools.
3260 If you do not use this variable, the tools might be missing and
3261 execution of the post-installation script is deferred until
3262 first boot.
3263 Deferring the script to first boot is undesirable and for
3264 read-only rootfs impossible.
3265 </para>
3266
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003267 <note>
3268 Equivalent support for pre-install, pre-uninstall, and
3269 post-uninstall scripts exist by way of
3270 <filename>pkg_preinst</filename>,
3271 <filename>pkg_prerm</filename>, and
3272 <filename>pkg_postrm</filename>, respectively.
3273 These scrips work in exactly the same way as does
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003274 <filename>pkg_postinst</filename> with the exception
3275 that they run at different times.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003276 Also, because of when they run, they are not applicable to
3277 being run at image creation time like
3278 <filename>pkg_postinst</filename>.
3279 </note>
3280 </section>
3281
3282 <section id='new-recipe-testing'>
3283 <title>Testing</title>
3284
3285 <para>
3286 The final step for completing your recipe is to be sure that
3287 the software you built runs correctly.
3288 To accomplish runtime testing, add the build's output
3289 packages to your image and test them on the target.
3290 </para>
3291
3292 <para>
3293 For information on how to customize your image by adding
3294 specific packages, see the
3295 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3296 section.
3297 </para>
3298 </section>
3299
3300 <section id='new-recipe-testing-examples'>
3301 <title>Examples</title>
3302
3303 <para>
3304 To help summarize how to write a recipe, this section provides
3305 some examples given various scenarios:
3306 <itemizedlist>
3307 <listitem><para>Recipes that use local files</para></listitem>
3308 <listitem><para>Using an Autotooled package</para></listitem>
3309 <listitem><para>Using a Makefile-based package</para></listitem>
3310 <listitem><para>Splitting an application into multiple packages</para></listitem>
3311 <listitem><para>Adding binaries to an image</para></listitem>
3312 </itemizedlist>
3313 </para>
3314
3315 <section id='new-recipe-single-c-file-package-hello-world'>
3316 <title>Single .c File Package (Hello World!)</title>
3317
3318 <para>
3319 Building an application from a single file that is stored
3320 locally (e.g. under <filename>files</filename>) requires
3321 a recipe that has the file listed in the
3322 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3323 variable.
3324 Additionally, you need to manually write the
3325 <filename>do_compile</filename> and
3326 <filename>do_install</filename> tasks.
3327 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3328 variable defines the directory containing the source code,
3329 which is set to
3330 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3331 in this case - the directory BitBake uses for the build.
3332 <literallayout class='monospaced'>
3333 SUMMARY = "Simple helloworld application"
3334 SECTION = "examples"
3335 LICENSE = "MIT"
3336 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3337
3338 SRC_URI = "file://helloworld.c"
3339
3340 S = "${WORKDIR}"
3341
3342 do_compile() {
3343 ${CC} helloworld.c -o helloworld
3344 }
3345
3346 do_install() {
3347 install -d ${D}${bindir}
3348 install -m 0755 helloworld ${D}${bindir}
3349 }
3350 </literallayout>
3351 </para>
3352
3353 <para>
3354 By default, the <filename>helloworld</filename>,
3355 <filename>helloworld-dbg</filename>, and
3356 <filename>helloworld-dev</filename> packages are built.
3357 For information on how to customize the packaging process,
3358 see the
3359 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3360 section.
3361 </para>
3362 </section>
3363
3364 <section id='new-recipe-autotooled-package'>
3365 <title>Autotooled Package</title>
3366 <para>
3367 Applications that use Autotools such as <filename>autoconf</filename> and
3368 <filename>automake</filename> require a recipe that has a source archive listed in
3369 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3370 also inherit the
3371 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3372 class, which contains the definitions of all the steps
3373 needed to build an Autotool-based application.
3374 The result of the build is automatically packaged.
3375 And, if the application uses NLS for localization, packages with local information are
3376 generated (one package per language).
3377 Following is one example: (<filename>hello_2.3.bb</filename>)
3378 <literallayout class='monospaced'>
3379 SUMMARY = "GNU Helloworld application"
3380 SECTION = "examples"
3381 LICENSE = "GPLv2+"
3382 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3383
3384 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3385
3386 inherit autotools gettext
3387 </literallayout>
3388 </para>
3389
3390 <para>
3391 The variable
3392 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3393 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003394 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3395 section in the Yocto Project Overview and Concepts Manual.
3396 You can quickly create Autotool-based recipes in a manner
3397 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003398 </para>
3399 </section>
3400
3401 <section id='new-recipe-makefile-based-package'>
3402 <title>Makefile-Based Package</title>
3403
3404 <para>
3405 Applications that use GNU <filename>make</filename> also require a recipe that has
3406 the source archive listed in
3407 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3408 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3409 starts the <filename>make</filename> command to compile the application.
3410 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003411 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3412 or
3413 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3414 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003415 BitBake passes these options into the GNU <filename>make</filename> invocation.
3416 Note that a <filename>do_install</filename> task is still required.
3417 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3418 </para>
3419
3420 <para>
3421 Some applications might require extra parameters to be passed to the compiler.
3422 For example, the application might need an additional header path.
3423 You can accomplish this by adding to the
3424 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3425 The following example shows this:
3426 <literallayout class='monospaced'>
3427 CFLAGS_prepend = "-I ${S}/include "
3428 </literallayout>
3429 </para>
3430
3431 <para>
3432 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3433 <literallayout class='monospaced'>
3434 SUMMARY = "Tools for managing memory technology devices"
3435 SECTION = "base"
3436 DEPENDS = "zlib lzo e2fsprogs util-linux"
3437 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3438 LICENSE = "GPLv2+"
3439 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3440 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3441
3442 # Use the latest version at 26 Oct, 2013
3443 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3444 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3445 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3446 "
3447
3448 PV = "1.5.1+git${SRCPV}"
3449
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003450 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003451
3452 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3453
3454 do_install () {
3455 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3456 }
3457
3458 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3459
3460 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3461 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3462 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3463
3464 PARALLEL_MAKE = ""
3465
3466 BBCLASSEXTEND = "native"
3467 </literallayout>
3468 </para>
3469 </section>
3470
3471 <section id='splitting-an-application-into-multiple-packages'>
3472 <title>Splitting an Application into Multiple Packages</title>
3473
3474 <para>
3475 You can use the variables
3476 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3477 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3478 to split an application into multiple packages.
3479 </para>
3480
3481 <para>
3482 Following is an example that uses the <filename>libxpm</filename> recipe.
3483 By default, this recipe generates a single package that contains the library along
3484 with a few binaries.
3485 You can modify the recipe to split the binaries into separate packages:
3486 <literallayout class='monospaced'>
3487 require xorg-lib-common.inc
3488
3489 SUMMARY = "Xpm: X Pixmap extension library"
3490 LICENSE = "BSD"
3491 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3492 DEPENDS += "libxext libsm libxt"
3493 PE = "1"
3494
3495 XORG_PN = "libXpm"
3496
3497 PACKAGES =+ "sxpm cxpm"
3498 FILES_cxpm = "${bindir}/cxpm"
3499 FILES_sxpm = "${bindir}/sxpm"
3500 </literallayout>
3501 </para>
3502
3503 <para>
3504 In the previous example, we want to ship the <filename>sxpm</filename>
3505 and <filename>cxpm</filename> binaries in separate packages.
3506 Since <filename>bindir</filename> would be packaged into the main
3507 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3508 package by default, we prepend the <filename>PACKAGES</filename>
3509 variable so additional package names are added to the start of list.
3510 This results in the extra <filename>FILES_*</filename>
3511 variables then containing information that define which files and
3512 directories go into which packages.
3513 Files included by earlier packages are skipped by latter packages.
3514 Thus, the main <filename>PN</filename> package
3515 does not include the above listed files.
3516 </para>
3517 </section>
3518
3519 <section id='packaging-externally-produced-binaries'>
3520 <title>Packaging Externally Produced Binaries</title>
3521
3522 <para>
3523 Sometimes, you need to add pre-compiled binaries to an
3524 image.
3525 For example, suppose that binaries for proprietary code
3526 exist, which are created by a particular division of a
3527 company.
3528 Your part of the company needs to use those binaries as
3529 part of an image that you are building using the
3530 OpenEmbedded build system.
3531 Since you only have the binaries and not the source code,
3532 you cannot use a typical recipe that expects to fetch the
3533 source specified in
3534 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3535 and then compile it.
3536 </para>
3537
3538 <para>
3539 One method is to package the binaries and then install them
3540 as part of the image.
3541 Generally, it is not a good idea to package binaries
3542 since, among other things, it can hinder the ability to
3543 reproduce builds and could lead to compatibility problems
3544 with ABI in the future.
3545 However, sometimes you have no choice.
3546 </para>
3547
3548 <para>
3549 The easiest solution is to create a recipe that uses
3550 the
3551 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3552 class and to be sure that you are using default locations
3553 for build artifacts.
3554 In most cases, the <filename>bin_package</filename> class
3555 handles "skipping" the configure and compile steps as well
3556 as sets things up to grab packages from the appropriate
3557 area.
3558 In particular, this class sets <filename>noexec</filename>
3559 on both the
3560 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3561 and
3562 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3563 tasks, sets
3564 <filename>FILES_${PN}</filename> to "/" so that it picks
3565 up all files, and sets up a
3566 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3567 task, which effectively copies all files from
3568 <filename>${S}</filename> to <filename>${D}</filename>.
3569 The <filename>bin_package</filename> class works well when
3570 the files extracted into <filename>${S}</filename> are
3571 already laid out in the way they should be laid out
3572 on the target.
3573 For more information on these variables, see the
3574 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3575 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3576 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3577 and
3578 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3579 variables in the Yocto Project Reference Manual's variable
3580 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003581 <note><title>Notes</title>
3582 <itemizedlist>
3583 <listitem><para>
3584 Using
3585 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3586 is a good idea even for components distributed
3587 in binary form, and is often necessary for
3588 shared libraries.
3589 For a shared library, listing the library
3590 dependencies in
3591 <filename>DEPENDS</filename> makes sure that
3592 the libraries are available in the staging
3593 sysroot when other recipes link against the
3594 library, which might be necessary for
3595 successful linking.
3596 </para></listitem>
3597 <listitem><para>
3598 Using <filename>DEPENDS</filename> also
3599 allows runtime dependencies between packages
3600 to be added automatically.
3601 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003602 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3603 section in the Yocto Project Overview and
3604 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003605 </para></listitem>
3606 </itemizedlist>
3607 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003608 </para>
3609
3610 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003611 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003612 class, you need to be sure you are doing the following:
3613 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003614 <listitem><para>
3615 Create a recipe where the
3616 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3617 and
3618 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3619 tasks do nothing:
3620 It is usually sufficient to just not define these
3621 tasks in the recipe, because the default
3622 implementations do nothing unless a Makefile is
3623 found in
3624 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3625 </para>
3626
3627 <para>If
3628 <filename>${S}</filename> might contain a Makefile,
3629 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003630 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003631 <filename>do_compile</filename> with custom
3632 versions, then you can use the
3633 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3634 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003635 <literallayout class='monospaced'>
3636 do_configure[noexec] = "1"
3637 do_compile[noexec] = "1"
3638 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003639 Unlike
3640 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3641 using the flag preserves the dependency chain from
3642 the
3643 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>, <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>,
3644 and
3645 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3646 tasks to the
3647 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3648 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003649 </para></listitem>
3650 <listitem><para>Make sure your
3651 <filename>do_install</filename> task installs the
3652 binaries appropriately.
3653 </para></listitem>
3654 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003655 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3656 (usually
3657 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3658 to point to the files you have installed, which of
3659 course depends on where you have installed them
3660 and whether those files are in different locations
3661 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003662 </para></listitem>
3663 </itemizedlist>
3664 </para>
3665 </section>
3666 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003667
3668 <section id="following-recipe-style-guidelines">
3669 <title>Following Recipe Style Guidelines</title>
3670
3671 <para>
3672 When writing recipes, it is good to conform to existing
3673 style guidelines.
3674 The
3675 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3676 wiki page provides rough guidelines for preferred recipe style.
3677 </para>
3678
3679 <para>
3680 It is common for existing recipes to deviate a bit from this
3681 style.
3682 However, aiming for at least a consistent style is a good idea.
3683 Some practices, such as omitting spaces around
3684 <filename>=</filename> operators in assignments or ordering
3685 recipe components in an erratic way, are widely seen as poor
3686 style.
3687 </para>
3688 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003689
3690 <section id='recipe-syntax'>
3691 <title>Recipe Syntax</title>
3692
3693 <para>
3694 Understanding recipe file syntax is important for writing
3695 recipes.
3696 The following list overviews the basic items that make up a
3697 BitBake recipe file.
3698 For more complete BitBake syntax descriptions, see the
3699 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3700 chapter of the BitBake User Manual.
3701 <itemizedlist>
3702 <listitem><para>
3703 <emphasis>Variable Assignments and Manipulations:</emphasis>
3704 Variable assignments allow a value to be assigned to a
3705 variable.
3706 The assignment can be static text or might include
3707 the contents of other variables.
3708 In addition to the assignment, appending and prepending
3709 operations are also supported.</para>
3710
3711 <para>The following example shows some of the ways
3712 you can use variables in recipes:
3713 <literallayout class='monospaced'>
3714 S = "${WORKDIR}/postfix-${PV}"
3715 CFLAGS += "-DNO_ASM"
3716 SRC_URI_append = " file://fixup.patch"
3717 </literallayout>
3718 </para></listitem>
3719 <listitem><para>
3720 <emphasis>Functions:</emphasis>
3721 Functions provide a series of actions to be performed.
3722 You usually use functions to override the default
3723 implementation of a task function or to complement
3724 a default function (i.e. append or prepend to an
3725 existing function).
3726 Standard functions use <filename>sh</filename> shell
3727 syntax, although access to OpenEmbedded variables and
3728 internal methods are also available.</para>
3729
3730 <para>The following is an example function from the
3731 <filename>sed</filename> recipe:
3732 <literallayout class='monospaced'>
3733 do_install () {
3734 autotools_do_install
3735 install -d ${D}${base_bindir}
3736 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3737 rmdir ${D}${bindir}/
3738 }
3739 </literallayout>
3740 It is also possible to implement new functions that
3741 are called between existing tasks as long as the
3742 new functions are not replacing or complementing the
3743 default functions.
3744 You can implement functions in Python
3745 instead of shell.
3746 Both of these options are not seen in the majority of
3747 recipes.
3748 </para></listitem>
3749 <listitem><para><emphasis>Keywords:</emphasis>
3750 BitBake recipes use only a few keywords.
3751 You use keywords to include common
3752 functions (<filename>inherit</filename>), load parts
3753 of a recipe from other files
3754 (<filename>include</filename> and
3755 <filename>require</filename>) and export variables
3756 to the environment (<filename>export</filename>).
3757 </para>
3758
3759 <para>The following example shows the use of some of
3760 these keywords:
3761 <literallayout class='monospaced'>
3762 export POSTCONF = "${STAGING_BINDIR}/postconf"
3763 inherit autoconf
3764 require otherfile.inc
3765 </literallayout>
3766 </para></listitem>
3767 <listitem><para>
3768 <emphasis>Comments (#):</emphasis>
3769 Any lines that begin with the hash character
3770 (<filename>#</filename>) are treated as comment lines
3771 and are ignored:
3772 <literallayout class='monospaced'>
3773 # This is a comment
3774 </literallayout>
3775 </para></listitem>
3776 </itemizedlist>
3777 </para>
3778
3779 <para>
3780 This next list summarizes the most important and most commonly
3781 used parts of the recipe syntax.
3782 For more information on these parts of the syntax, you can
3783 reference the
3784 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3785 chapter in the BitBake User Manual.
3786 <itemizedlist>
3787 <listitem><para>
3788 <emphasis>Line Continuation (\):</emphasis>
3789 Use the backward slash (<filename>\</filename>)
3790 character to split a statement over multiple lines.
3791 Place the slash character at the end of the line that
3792 is to be continued on the next line:
3793 <literallayout class='monospaced'>
3794 VAR = "A really long \
3795 line"
3796 </literallayout>
3797 <note>
3798 You cannot have any characters including spaces
3799 or tabs after the slash character.
3800 </note>
3801 </para></listitem>
3802 <listitem><para>
3803 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3804 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3805 syntax to access the contents of a variable:
3806 <literallayout class='monospaced'>
3807 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3808 </literallayout>
3809 <note>
3810 It is important to understand that the value of a
3811 variable expressed in this form does not get
3812 substituted automatically.
3813 The expansion of these expressions happens
3814 on-demand later (e.g. usually when a function that
3815 makes reference to the variable executes).
3816 This behavior ensures that the values are most
3817 appropriate for the context in which they are
3818 finally used.
3819 On the rare occasion that you do need the variable
3820 expression to be expanded immediately, you can use
3821 the <filename>:=</filename> operator instead of
3822 <filename>=</filename> when you make the
3823 assignment, but this is not generally needed.
3824 </note>
3825 </para></listitem>
3826 <listitem><para>
3827 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3828 Use double quotes around values in all variable
3829 assignments (e.g.
3830 <filename>"<replaceable>value</replaceable>"</filename>).
3831 Following is an example:
3832 <literallayout class='monospaced'>
3833 VAR1 = "${OTHERVAR}"
3834 VAR2 = "The version is ${PV}"
3835 </literallayout>
3836 </para></listitem>
3837 <listitem><para>
3838 <emphasis>Conditional Assignment (?=):</emphasis>
3839 Conditional assignment is used to assign a
3840 value to a variable, but only when the variable is
3841 currently unset.
3842 Use the question mark followed by the equal sign
3843 (<filename>?=</filename>) to make a "soft" assignment
3844 used for conditional assignment.
3845 Typically, "soft" assignments are used in the
3846 <filename>local.conf</filename> file for variables
3847 that are allowed to come through from the external
3848 environment.
3849 </para>
3850
3851 <para>Here is an example where
3852 <filename>VAR1</filename> is set to "New value" if
3853 it is currently empty.
3854 However, if <filename>VAR1</filename> has already been
3855 set, it remains unchanged:
3856 <literallayout class='monospaced'>
3857 VAR1 ?= "New value"
3858 </literallayout>
3859 In this next example, <filename>VAR1</filename>
3860 is left with the value "Original value":
3861 <literallayout class='monospaced'>
3862 VAR1 = "Original value"
3863 VAR1 ?= "New value"
3864 </literallayout>
3865 </para></listitem>
3866 <listitem><para>
3867 <emphasis>Appending (+=):</emphasis>
3868 Use the plus character followed by the equals sign
3869 (<filename>+=</filename>) to append values to existing
3870 variables.
3871 <note>
3872 This operator adds a space between the existing
3873 content of the variable and the new content.
3874 </note></para>
3875
3876 <para>Here is an example:
3877 <literallayout class='monospaced'>
3878 SRC_URI += "file://fix-makefile.patch"
3879 </literallayout>
3880 </para></listitem>
3881 <listitem><para>
3882 <emphasis>Prepending (=+):</emphasis>
3883 Use the equals sign followed by the plus character
3884 (<filename>=+</filename>) to prepend values to existing
3885 variables.
3886 <note>
3887 This operator adds a space between the new content
3888 and the existing content of the variable.
3889 </note></para>
3890
3891 <para>Here is an example:
3892 <literallayout class='monospaced'>
3893 VAR =+ "Starts"
3894 </literallayout>
3895 </para></listitem>
3896 <listitem><para>
3897 <emphasis>Appending (_append):</emphasis>
3898 Use the <filename>_append</filename> operator to
3899 append values to existing variables.
3900 This operator does not add any additional space.
3901 Also, the operator is applied after all the
3902 <filename>+=</filename>, and
3903 <filename>=+</filename> operators have been applied and
3904 after all <filename>=</filename> assignments have
3905 occurred.
3906 </para>
3907
3908 <para>The following example shows the space being
3909 explicitly added to the start to ensure the appended
3910 value is not merged with the existing value:
3911 <literallayout class='monospaced'>
3912 SRC_URI_append = " file://fix-makefile.patch"
3913 </literallayout>
3914 You can also use the <filename>_append</filename>
3915 operator with overrides, which results in the actions
3916 only being performed for the specified target or
3917 machine:
3918 <literallayout class='monospaced'>
3919 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3920 </literallayout>
3921 </para></listitem>
3922 <listitem><para>
3923 <emphasis>Prepending (_prepend):</emphasis>
3924 Use the <filename>_prepend</filename> operator to
3925 prepend values to existing variables.
3926 This operator does not add any additional space.
3927 Also, the operator is applied after all the
3928 <filename>+=</filename>, and
3929 <filename>=+</filename> operators have been applied and
3930 after all <filename>=</filename> assignments have
3931 occurred.
3932 </para>
3933
3934 <para>The following example shows the space being
3935 explicitly added to the end to ensure the prepended
3936 value is not merged with the existing value:
3937 <literallayout class='monospaced'>
3938 CFLAGS_prepend = "-I${S}/myincludes "
3939 </literallayout>
3940 You can also use the <filename>_prepend</filename>
3941 operator with overrides, which results in the actions
3942 only being performed for the specified target or
3943 machine:
3944 <literallayout class='monospaced'>
3945 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
3946 </literallayout>
3947 </para></listitem>
3948 <listitem><para>
3949 <emphasis>Overrides:</emphasis>
3950 You can use overrides to set a value conditionally,
3951 typically based on how the recipe is being built.
3952 For example, to set the
3953 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
3954 variable's value to "standard/base" for any target
3955 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
3956 except for qemuarm where it should be set to
3957 "standard/arm-versatile-926ejs", you would do the
3958 following:
3959 <literallayout class='monospaced'>
3960 KBRANCH = "standard/base"
3961 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
3962 </literallayout>
3963 Overrides are also used to separate alternate values
3964 of a variable in other situations.
3965 For example, when setting variables such as
3966 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3967 and
3968 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
3969 that are specific to individual packages produced by
3970 a recipe, you should always use an override that
3971 specifies the name of the package.
3972 </para></listitem>
3973 <listitem><para>
3974 <emphasis>Indentation:</emphasis>
3975 Use spaces for indentation rather than than tabs.
3976 For shell functions, both currently work.
3977 However, it is a policy decision of the Yocto Project
3978 to use tabs in shell functions.
3979 Realize that some layers have a policy to use spaces
3980 for all indentation.
3981 </para></listitem>
3982 <listitem><para>
3983 <emphasis>Using Python for Complex Operations:</emphasis>
3984 For more advanced processing, it is possible to use
3985 Python code during variable assignments (e.g.
3986 search and replacement on a variable).</para>
3987
3988 <para>You indicate Python code using the
3989 <filename>${@<replaceable>python_code</replaceable>}</filename>
3990 syntax for the variable assignment:
3991 <literallayout class='monospaced'>
3992 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
3993 </literallayout>
3994 </para></listitem>
3995 <listitem><para>
3996 <emphasis>Shell Function Syntax:</emphasis>
3997 Write shell functions as if you were writing a shell
3998 script when you describe a list of actions to take.
3999 You should ensure that your script works with a generic
4000 <filename>sh</filename> and that it does not require
4001 any <filename>bash</filename> or other shell-specific
4002 functionality.
4003 The same considerations apply to various system
4004 utilities (e.g. <filename>sed</filename>,
4005 <filename>grep</filename>, <filename>awk</filename>,
4006 and so forth) that you might wish to use.
4007 If in doubt, you should check with multiple
4008 implementations - including those from BusyBox.
4009 </para></listitem>
4010 </itemizedlist>
4011 </para>
4012 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004013 </section>
4014
4015 <section id="platdev-newmachine">
4016 <title>Adding a New Machine</title>
4017
4018 <para>
4019 Adding a new machine to the Yocto Project is a straightforward
4020 process.
4021 This section describes how to add machines that are similar
4022 to those that the Yocto Project already supports.
4023 <note>
4024 Although well within the capabilities of the Yocto Project,
4025 adding a totally new architecture might require
4026 changes to <filename>gcc/glibc</filename> and to the site
4027 information, which is beyond the scope of this manual.
4028 </note>
4029 </para>
4030
4031 <para>
4032 For a complete example that shows how to add a new machine,
4033 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004034 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
4035 section in the Yocto Project Board Support Package (BSP)
4036 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004037 </para>
4038
4039 <section id="platdev-newmachine-conffile">
4040 <title>Adding the Machine Configuration File</title>
4041
4042 <para>
4043 To add a new machine, you need to add a new machine
4044 configuration file to the layer's
4045 <filename>conf/machine</filename> directory.
4046 This configuration file provides details about the device
4047 you are adding.
4048 </para>
4049
4050 <para>
4051 The OpenEmbedded build system uses the root name of the
4052 machine configuration file to reference the new machine.
4053 For example, given a machine configuration file named
4054 <filename>crownbay.conf</filename>, the build system
4055 recognizes the machine as "crownbay".
4056 </para>
4057
4058 <para>
4059 The most important variables you must set in your machine
4060 configuration file or include from a lower-level configuration
4061 file are as follows:
4062 <itemizedlist>
4063 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4064 (e.g. "arm")</para></listitem>
4065 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4066 </para></listitem>
4067 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4068 (e.g. "apm screen wifi")</para></listitem>
4069 </itemizedlist>
4070 </para>
4071
4072 <para>
4073 You might also need these variables:
4074 <itemizedlist>
4075 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4076 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4077 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4078 (e.g. "zImage")</para></listitem>
4079 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4080 (e.g. "tar.gz jffs2")</para></listitem>
4081 </itemizedlist>
4082 </para>
4083
4084 <para>
4085 You can find full details on these variables in the reference
4086 section.
4087 You can leverage existing machine <filename>.conf</filename>
4088 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4089 </para>
4090 </section>
4091
4092 <section id="platdev-newmachine-kernel">
4093 <title>Adding a Kernel for the Machine</title>
4094
4095 <para>
4096 The OpenEmbedded build system needs to be able to build a kernel
4097 for the machine.
4098 You need to either create a new kernel recipe for this machine,
4099 or extend an existing kernel recipe.
4100 You can find several kernel recipe examples in the
4101 Source Directory at
4102 <filename>meta/recipes-kernel/linux</filename>
4103 that you can use as references.
4104 </para>
4105
4106 <para>
4107 If you are creating a new kernel recipe, normal recipe-writing
4108 rules apply for setting up a
4109 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4110 Thus, you need to specify any necessary patches and set
4111 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4112 to point at the source code.
4113 You need to create a <filename>do_configure</filename> task that
4114 configures the unpacked kernel with a
4115 <filename>defconfig</filename> file.
4116 You can do this by using a <filename>make defconfig</filename>
4117 command or, more commonly, by copying in a suitable
4118 <filename>defconfig</filename> file and then running
4119 <filename>make oldconfig</filename>.
4120 By making use of <filename>inherit kernel</filename> and
4121 potentially some of the <filename>linux-*.inc</filename> files,
4122 most other functionality is centralized and the defaults of the
4123 class normally work well.
4124 </para>
4125
4126 <para>
4127 If you are extending an existing kernel recipe, it is usually
4128 a matter of adding a suitable <filename>defconfig</filename>
4129 file.
4130 The file needs to be added into a location similar to
4131 <filename>defconfig</filename> files used for other machines
4132 in a given kernel recipe.
4133 A possible way to do this is by listing the file in the
4134 <filename>SRC_URI</filename> and adding the machine to the
4135 expression in
4136 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4137 <literallayout class='monospaced'>
4138 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4139 </literallayout>
4140 For more information on <filename>defconfig</filename> files,
4141 see the
4142 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4143 section in the Yocto Project Linux Kernel Development Manual.
4144 </para>
4145 </section>
4146
4147 <section id="platdev-newmachine-formfactor">
4148 <title>Adding a Formfactor Configuration File</title>
4149
4150 <para>
4151 A formfactor configuration file provides information about the
4152 target hardware for which the image is being built and information that
4153 the build system cannot obtain from other sources such as the kernel.
4154 Some examples of information contained in a formfactor configuration file include
4155 framebuffer orientation, whether or not the system has a keyboard,
4156 the positioning of the keyboard in relation to the screen, and
4157 the screen resolution.
4158 </para>
4159
4160 <para>
4161 The build system uses reasonable defaults in most cases.
4162 However, if customization is
4163 necessary, you need to create a <filename>machconfig</filename> file
4164 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4165 directory.
4166 This directory contains directories for specific machines such as
4167 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4168 For information about the settings available and the defaults, see the
4169 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4170 same area.
4171 </para>
4172
4173 <para>
4174 Following is an example for "qemuarm" machine:
4175 <literallayout class='monospaced'>
4176 HAVE_TOUCHSCREEN=1
4177 HAVE_KEYBOARD=1
4178
4179 DISPLAY_CAN_ROTATE=0
4180 DISPLAY_ORIENTATION=0
4181 #DISPLAY_WIDTH_PIXELS=640
4182 #DISPLAY_HEIGHT_PIXELS=480
4183 #DISPLAY_BPP=16
4184 DISPLAY_DPI=150
4185 DISPLAY_SUBPIXEL_ORDER=vrgb
4186 </literallayout>
4187 </para>
4188 </section>
4189 </section>
4190
Brad Bishop316dfdd2018-06-25 12:45:53 -04004191 <section id='gs-upgrading-recipes'>
4192 <title>Upgrading Recipes</title>
4193
4194 <para>
4195 Over time, upstream developers publish new versions for software
4196 built by layer recipes.
4197 It is recommended to keep recipes up-to-date with upstream
4198 version releases.
4199 You can use the Automated Upgrade Helper (AUH) to set up
4200 automatic version upgrades.
4201 Alternatively, you can use <filename>devtool upgrade</filename>
4202 to set up semi-automatic version upgrades.
4203 Finally, you can even manually upgrade a recipe by editing the
4204 recipe itself.
4205 </para>
4206
4207 <section id='gs-using-the-auto-upgrade-helper'>
4208 <title>Using the Auto Upgrade Helper (AUH)</title>
4209
4210 <para>
4211 The AUH utility works in conjunction with the
4212 OpenEmbedded build system in order to automatically generate
4213 upgrades for recipes based on new versions being
4214 published upstream.
4215 Use AUH when you want to create a service that performs the
4216 upgrades automatically and optionally sends you an email with
4217 the results.
4218 </para>
4219
4220 <para>
4221 AUH allows you to update several recipes with a single use.
4222 You can also optionally perform build and integration tests
4223 using images with the results saved to your hard drive and
4224 emails of results optionally sent to recipe maintainers.
4225 Finally, AUH creates Git commits with appropriate commit
4226 messages in the layer's tree for the changes made to recipes.
4227 <note>
4228 Conditions do exist when you should not use AUH to upgrade
4229 recipes and you should instead use either
4230 <filename>devtool upgrade</filename> or upgrade your
4231 recipes manually:
4232 <itemizedlist>
4233 <listitem><para>
4234 When AUH cannot complete the upgrade sequence.
4235 This situation usually results because custom
4236 patches carried by the recipe cannot be
4237 automatically rebased to the new version.
4238 In this case, <filename>devtool upgrade</filename>
4239 allows you to manually resolve conflicts.
4240 </para></listitem>
4241 <listitem><para>
4242 When for any reason you want fuller control over
4243 the upgrade process.
4244 For example, when you want special arrangements
4245 for testing.
4246 </para></listitem>
4247 </itemizedlist>
4248 </note>
4249 </para>
4250
4251 <para>
4252 The following steps describe how to set up the AUH utility:
4253 <orderedlist>
4254 <listitem><para>
4255 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4256 You need to be sure that your development host is
4257 set up to use the Yocto Project.
4258 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004259 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004260 section.
4261 </para></listitem>
4262 <listitem><para>
4263 <emphasis>Make Sure Git is Configured:</emphasis>
4264 The AUH utility requires Git to be configured because
4265 AUH uses Git to save upgrades.
4266 Thus, you must have Git user and email configured.
4267 The following command shows your configurations:
4268 <literallayout class='monospaced'>
4269 $ git config --list
4270 </literallayout>
4271 If you do not have the user and email configured, you
4272 can use the following commands to do so:
4273 <literallayout class='monospaced'>
4274 $ git config --global user.name <replaceable>some_name</replaceable>
4275 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4276 </literallayout>
4277 </para></listitem>
4278 <listitem><para>
4279 <emphasis>Clone the AUH Repository:</emphasis>
4280 To use AUH, you must clone the repository onto your
4281 development host.
4282 The following command uses Git to create a local
4283 copy of the repository on your system:
4284 <literallayout class='monospaced'>
4285 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4286 Cloning into 'auto-upgrade-helper'...
4287 remote: Counting objects: 768, done.
4288 remote: Compressing objects: 100% (300/300), done.
4289 remote: Total 768 (delta 499), reused 703 (delta 434)
4290 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4291 Resolving deltas: 100% (499/499), done.
4292 Checking connectivity... done.
4293 </literallayout>
4294 AUH is not part of the
4295 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4296 or
4297 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4298 repositories.
4299 </para></listitem>
4300 <listitem><para>
4301 <emphasis>Create a Dedicated Build Directory:</emphasis>
4302 Run the
4303 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4304 script to create a fresh build directory that you
4305 use exclusively for running the AUH utility:
4306 <literallayout class='monospaced'>
4307 $ cd ~/poky
4308 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4309 </literallayout>
4310 Re-using an existing build directory and its
4311 configurations is not recommended as existing settings
4312 could cause AUH to fail or behave undesirably.
4313 </para></listitem>
4314 <listitem><para>
4315 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4316 Several settings need to exist in the
4317 <filename>local.conf</filename> file in the build
4318 directory you just created for AUH.
4319 Make these following configurations:
4320 <itemizedlist>
4321 <listitem><para>
4322 Enable "distrodata" as follows:
4323 <literallayout class='monospaced'>
4324 INHERIT =+ "distrodata"
4325 </literallayout>
4326 </para></listitem>
4327 <listitem><para>
4328 If you want to enable
4329 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4330 which is optional, you need the following
4331 lines in the
4332 <filename>conf/local.conf</filename> file:
4333 <literallayout class='monospaced'>
4334 INHERIT =+ "buildhistory"
4335 BUILDHISTORY_COMMIT = "1"
4336 </literallayout>
4337 With this configuration and a successful
4338 upgrade, a build history "diff" file appears in
4339 the
4340 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4341 file found in your build directory.
4342 </para></listitem>
4343 <listitem><para>
4344 If you want to enable testing through the
4345 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4346 class, which is optional, you need to have the
4347 following set in your
4348 <filename>conf/local.conf</filename> file:
4349 <literallayout class='monospaced'>
4350 INHERIT += "testimage"
4351 </literallayout>
4352 <note>
4353 If your distro does not enable by default
4354 ptest, which Poky does, you need the
4355 following in your
4356 <filename>local.conf</filename> file:
4357 <literallayout class='monospaced'>
4358 DISTRO_FEATURES_append = " ptest"
4359 </literallayout>
4360 </note>
4361 </para></listitem>
4362 </itemizedlist>
4363 </para></listitem>
4364 <listitem><para>
4365 <emphasis>Optionally Start a vncserver:</emphasis>
4366 If you are running in a server without an X11 session,
4367 you need to start a vncserver:
4368 <literallayout class='monospaced'>
4369 $ vncserver :1
4370 $ export DISPLAY=:1
4371 </literallayout>
4372 </para></listitem>
4373 <listitem><para>
4374 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4375 You need to have the
4376 <filename>upgrade-helper/upgrade-helper.conf</filename>
4377 configuration file in your build directory.
4378 You can find a sample configuration file in the
4379 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4380 </para>
4381
4382 <para>Read through the sample file and make
4383 configurations as needed.
4384 For example, if you enabled build history in your
4385 <filename>local.conf</filename> as described earlier,
4386 you must enable it in
4387 <filename>upgrade-helper.conf</filename>.</para>
4388
4389 <para>Also, if you are using the default
4390 <filename>maintainers.inc</filename> file supplied
4391 with Poky and located in
4392 <filename>meta-yocto</filename> and you do not set a
4393 "maintainers_whitelist" or "global_maintainer_override"
4394 in the <filename>upgrade-helper.conf</filename>
4395 configuration, and you specify "-e all" on the
4396 AUH command-line, the utility automatically sends out
4397 emails to all the default maintainers.
4398 Please avoid this.
4399 </para></listitem>
4400 </orderedlist>
4401 </para>
4402
4403 <para>
4404 This next set of examples describes how to use the AUH:
4405 <itemizedlist>
4406 <listitem><para>
4407 <emphasis>Upgrading a Specific Recipe:</emphasis>
4408 To upgrade a specific recipe, use the following
4409 form:
4410 <literallayout class='monospaced'>
4411 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4412 </literallayout>
4413 For example, this command upgrades the
4414 <filename>xmodmap</filename> recipe:
4415 <literallayout class='monospaced'>
4416 $ upgrade-helper.py xmodmap
4417 </literallayout>
4418 </para></listitem>
4419 <listitem><para>
4420 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4421 To upgrade a specific recipe to a particular version,
4422 use the following form:
4423 <literallayout class='monospaced'>
4424 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4425 </literallayout>
4426 For example, this command upgrades the
4427 <filename>xmodmap</filename> recipe to version
4428 1.2.3:
4429 <literallayout class='monospaced'>
4430 $ upgrade-helper.py xmodmap -t 1.2.3
4431 </literallayout>
4432 </para></listitem>
4433 <listitem><para>
4434 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4435 To upgrade all recipes to their most recent versions
4436 and suppress the email notifications, use the following
4437 command:
4438 <literallayout class='monospaced'>
4439 $ upgrade-helper.py all
4440 </literallayout>
4441 </para></listitem>
4442 <listitem><para>
4443 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4444 To upgrade all recipes to their most recent versions
4445 and send email messages to maintainers for each
4446 attempted recipe as well as a status email, use the
4447 following command:
4448 <literallayout class='monospaced'>
4449 $ upgrade-helper.py -e all
4450 </literallayout>
4451 </para></listitem>
4452 </itemizedlist>
4453 </para>
4454
4455 <para>
4456 Once you have run the AUH utility, you can find the results
4457 in the AUH build directory:
4458 <literallayout class='monospaced'>
4459 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4460 </literallayout>
4461 The AUH utility also creates recipe update commits from
4462 successful upgrade attempts in the layer tree.
4463 </para>
4464
4465 <para>
4466 You can easily set up to run the AUH utility on a regular
4467 basis by using a cron job.
4468 See the
4469 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4470 file distributed with the utility for an example.
4471 </para>
4472 </section>
4473
4474 <section id='gs-using-devtool-upgrade'>
4475 <title>Using <filename>devtool upgrade</filename></title>
4476
4477 <para>
4478 As mentioned earlier, an alternative method for upgrading
4479 recipes to newer versions is to use
4480 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4481 You can read about <filename>devtool upgrade</filename> in
4482 general in the
4483 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software'>Use <filename>devtool upgrade</filename> to Create a Version of the Recipe that Supports a Newer Version of the Software</ulink>"
4484 section in the Yocto Project Application Development and the
4485 Extensible Software Development Kit (eSDK) Manual.
4486 </para>
4487
4488 <para>
4489 To see all the command-line options available with
4490 <filename>devtool upgrade</filename>, use the following help
4491 command:
4492 <literallayout class='monospaced'>
4493 $ devtool upgrade -h
4494 </literallayout>
4495 </para>
4496
4497 <para>
4498 If you want to find out what version a recipe is currently at
4499 upstream without any attempt to upgrade your local version of
4500 the recipe, you can use the following command:
4501 <literallayout class='monospaced'>
4502 $ devtool latest-version <replaceable>recipe_name</replaceable>
4503 </literallayout>
4504 </para>
4505
4506 <para>
4507 As mentioned in the previous section describing AUH,
4508 <filename>devtool upgrade</filename> works in a
4509 less-automated manner than AUH.
4510 Specifically, <filename>devtool upgrade</filename> only
4511 works on a single recipe that you name on the command line,
4512 cannot perform build and integration testing using images,
4513 and does not automatically generate commits for changes in
4514 the source tree.
4515 Despite all these "limitations",
4516 <filename>devtool upgrade</filename> updates the recipe file
4517 to the new upstream version and attempts to rebase custom
4518 patches contained by the recipe as needed.
4519 <note>
4520 AUH uses much of <filename>devtool upgrade</filename>
4521 behind the scenes making AUH somewhat of a "wrapper"
4522 application for <filename>devtool upgrade</filename>.
4523 </note>
4524 </para>
4525
4526 <para>
4527 A typical scenario involves having used Git to clone an
4528 upstream repository that you use during build operations.
4529 Because you are (or have) built the recipe in the past, the
4530 layer is likely added to your configuration already.
4531 If for some reason, the layer is not added, you could add
4532 it easily using the
4533 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4534 script.
4535 For example, suppose you use the <filename>nano.bb</filename>
4536 recipe from the <filename>meta-oe</filename> layer in the
4537 <filename>meta-openembedded</filename> repository.
4538 For this example, assume that the layer has been cloned into
4539 following area:
4540 <literallayout class='monospaced'>
4541 /home/scottrif/meta-openembedded
4542 </literallayout>
4543 The following command from your
4544 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4545 adds the layer to your build configuration (i.e.
4546 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4547 <literallayout class='monospaced'>
4548 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4549 NOTE: Starting bitbake server...
4550 Parsing recipes: 100% |##########################################| Time: 0:00:55
4551 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4552 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4553 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4554 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4555 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4556 </literallayout>
4557 For this example, assume that the <filename>nano.bb</filename>
4558 recipe that is upstream has a 2.9.3 version number.
4559 However, the version in the local repository is 2.7.4.
4560 The following command from your build directory automatically
4561 upgrades the recipe for you:
4562 <note>
4563 Using the <filename>-V</filename> option is not necessary.
4564 Omitting the version number causes
4565 <filename>devtool upgrade</filename> to upgrade the recipe
4566 to the most recent version.
4567 </note>
4568 <literallayout class='monospaced'>
4569 $ devtool upgrade nano -V 2.9.3
4570 NOTE: Starting bitbake server...
4571 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4572 Parsing recipes: 100% |##########################################| Time: 0:00:46
4573 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4574 NOTE: Extracting current version source...
4575 NOTE: Resolving any missing task queue dependencies
4576 .
4577 .
4578 .
4579 NOTE: Executing SetScene Tasks
4580 NOTE: Executing RunQueue Tasks
4581 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4582 Adding changed files: 100% |#####################################| Time: 0:00:00
4583 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4584 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4585 </literallayout>
4586 Continuing with this example, you can use
4587 <filename>devtool build</filename> to build the newly upgraded
4588 recipe:
4589 <literallayout class='monospaced'>
4590 $ devtool build nano
4591 NOTE: Starting bitbake server...
4592 Loading cache: 100% |################################################################################################| Time: 0:00:01
4593 Loaded 2040 entries from dependency cache.
4594 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4595 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4596 NOTE: Resolving any missing task queue dependencies
4597 .
4598 .
4599 .
4600 NOTE: Executing SetScene Tasks
4601 NOTE: Executing RunQueue Tasks
4602 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4603 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4604 </literallayout>
4605 Within the <filename>devtool upgrade</filename> workflow,
4606 opportunity exists to deploy and test your rebuilt software.
4607 For this example, however, running
4608 <filename>devtool finish</filename> cleans up the workspace
4609 once the source in your workspace is clean.
4610 This usually means using Git to stage and submit commits
4611 for the changes generated by the upgrade process.
4612 </para>
4613
4614 <para>
4615 Once the tree is clean, you can clean things up in this
4616 example with the following command from the
4617 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4618 directory:
4619 <literallayout class='monospaced'>
4620 $ devtool finish nano meta-oe
4621 NOTE: Starting bitbake server...
4622 Loading cache: 100% |################################################################################################| Time: 0:00:00
4623 Loaded 2040 entries from dependency cache.
4624 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4625 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4626 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4627 NOTE: Updating recipe nano_2.9.3.bb
4628 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4629 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4630 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4631 </literallayout>
4632 Using the <filename>devtool finish</filename> command cleans
4633 up the workspace and creates a patch file based on your
4634 commits.
4635 The tool puts all patch files back into the source directory
4636 in a sub-directory named <filename>nano</filename> in this
4637 case.
4638 </para>
4639 </section>
4640
4641 <section id='dev-manually-upgrading-a-recipe'>
4642 <title>Manually Upgrading a Recipe</title>
4643
4644 <para>
4645 If for some reason you choose not to upgrade recipes using the
4646 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4647 or by using
4648 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4649 you can manually edit the recipe files to upgrade the versions.
4650 <note><title>Caution</title>
4651 Manually updating multiple recipes scales poorly and
4652 involves many steps.
4653 The recommendation to upgrade recipe versions is through
4654 AUH or <filename>devtool upgrade</filename>, both of which
4655 automate some steps and provide guidance for others needed
4656 for the manual process.
4657 </note>
4658 </para>
4659
4660 <para>
4661 To manually upgrade recipe versions, follow these general steps:
4662 <orderedlist>
4663 <listitem><para>
4664 <emphasis>Change the Version:</emphasis>
4665 Rename the recipe such that the version (i.e. the
4666 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4667 part of the recipe name) changes appropriately.
4668 If the version is not part of the recipe name, change
4669 the value as it is set for <filename>PV</filename>
4670 within the recipe itself.
4671 </para></listitem>
4672 <listitem><para>
4673 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4674 If the source code your recipe builds is fetched from
4675 Git or some other version control system, update
4676 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4677 to point to the commit hash that matches the new
4678 version.
4679 </para></listitem>
4680 <listitem><para>
4681 <emphasis>Build the Software:</emphasis>
4682 Try to build the recipe using BitBake.
4683 Typical build failures include the following:
4684 <itemizedlist>
4685 <listitem><para>
4686 License statements were updated for the new
4687 version.
4688 For this case, you need to review any changes
4689 to the license and update the values of
4690 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4691 and
4692 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4693 as needed.
4694 <note>
4695 License changes are often inconsequential.
4696 For example, the license text's copyright
4697 year might have changed.
4698 </note>
4699 </para></listitem>
4700 <listitem><para>
4701 Custom patches carried by the older version of
4702 the recipe might fail to apply to the new
4703 version.
4704 For these cases, you need to review the
4705 failures.
4706 Patches might not be necessary for the new
4707 version of the software if the upgraded version
4708 has fixed those issues.
4709 If a patch is necessary and failing, you need
4710 to rebase it into the new version.
4711 </para></listitem>
4712 </itemizedlist>
4713 </para></listitem>
4714 <listitem><para>
4715 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4716 Once you successfully build the new software for a
4717 given architecture, you could test the build for
4718 other architectures by changing the
4719 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4720 variable and rebuilding the software.
4721 This optional step is especially important if the
4722 recipe is to be released publicly.
4723 </para></listitem>
4724 <listitem><para>
4725 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4726 Checking both these reveals if new features exist that
4727 could break backwards-compatibility.
4728 If so, you need to take steps to mitigate or eliminate
4729 that situation.
4730 </para></listitem>
4731 <listitem><para>
4732 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4733 If you want, you can test the new software by booting
4734 it onto actual hardware.
4735 </para></listitem>
4736 <listitem><para>
4737 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4738 After all builds work and any testing is successful,
4739 you can create commits for any changes in the layer
4740 holding your upgraded recipe.
4741 </para></listitem>
4742 </orderedlist>
4743 </para>
4744 </section>
4745 </section>
4746
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004747 <section id='finding-the-temporary-source-code'>
4748 <title>Finding Temporary Source Code</title>
4749
4750 <para>
4751 You might find it helpful during development to modify the
4752 temporary source code used by recipes to build packages.
4753 For example, suppose you are developing a patch and you need to
4754 experiment a bit to figure out your solution.
4755 After you have initially built the package, you can iteratively
4756 tweak the source code, which is located in the
4757 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4758 and then you can force a re-compile and quickly test your altered
4759 code.
4760 Once you settle on a solution, you can then preserve your changes
4761 in the form of patches.
4762 </para>
4763
4764 <para>
4765 During a build, the unpacked temporary source code used by recipes
4766 to build packages is available in the Build Directory as
4767 defined by the
4768 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4769 variable.
4770 Below is the default value for the <filename>S</filename> variable
4771 as defined in the
4772 <filename>meta/conf/bitbake.conf</filename> configuration file
4773 in the
4774 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4775 <literallayout class='monospaced'>
4776 S = "${WORKDIR}/${BP}"
4777 </literallayout>
4778 You should be aware that many recipes override the
4779 <filename>S</filename> variable.
4780 For example, recipes that fetch their source from Git usually set
4781 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4782 <note>
4783 The
4784 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4785 represents the base recipe name, which consists of the name
4786 and version:
4787 <literallayout class='monospaced'>
4788 BP = "${BPN}-${PV}"
4789 </literallayout>
4790 </note>
4791 </para>
4792
4793 <para>
4794 The path to the work directory for the recipe
4795 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4796 is defined as follows:
4797 <literallayout class='monospaced'>
4798 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4799 </literallayout>
4800 The actual directory depends on several things:
4801 <itemizedlist>
4802 <listitem><para>
4803 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4804 The top-level build output directory.
4805 </para></listitem>
4806 <listitem><para>
4807 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4808 The target system identifier.
4809 </para></listitem>
4810 <listitem><para>
4811 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4812 The recipe name.
4813 </para></listitem>
4814 <listitem><para>
4815 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4816 The epoch - (if
4817 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4818 is not specified, which is usually the case for most
4819 recipes, then <filename>EXTENDPE</filename> is blank).
4820 </para></listitem>
4821 <listitem><para>
4822 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4823 The recipe version.
4824 </para></listitem>
4825 <listitem><para>
4826 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4827 The recipe revision.
4828 </para></listitem>
4829 </itemizedlist>
4830 </para>
4831
4832 <para>
4833 As an example, assume a Source Directory top-level folder
4834 named <filename>poky</filename>, a default Build Directory at
4835 <filename>poky/build</filename>, and a
4836 <filename>qemux86-poky-linux</filename> machine target
4837 system.
4838 Furthermore, suppose your recipe is named
4839 <filename>foo_1.3.0.bb</filename>.
4840 In this case, the work directory the build system uses to
4841 build the package would be as follows:
4842 <literallayout class='monospaced'>
4843 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4844 </literallayout>
4845 </para>
4846 </section>
4847
4848 <section id="using-a-quilt-workflow">
4849 <title>Using Quilt in Your Workflow</title>
4850
4851 <para>
4852 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4853 is a powerful tool that allows you to capture source code changes
4854 without having a clean source tree.
4855 This section outlines the typical workflow you can use to modify
4856 source code, test changes, and then preserve the changes in the
4857 form of a patch all using Quilt.
4858 <note><title>Tip</title>
4859 With regard to preserving changes to source files, if you
4860 clean a recipe or have <filename>rm_work</filename> enabled,
4861 the
4862 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4863 as described in the Yocto Project Application Development
4864 and the Extensible Software Development Kit (eSDK) manual
4865 is a safer development flow than the flow that uses Quilt.
4866 </note>
4867 </para>
4868
4869 <para>
4870 Follow these general steps:
4871 <orderedlist>
4872 <listitem><para>
4873 <emphasis>Find the Source Code:</emphasis>
4874 Temporary source code used by the OpenEmbedded build system
4875 is kept in the
4876 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4877 See the
4878 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4879 section to learn how to locate the directory that has the
4880 temporary source code for a particular package.
4881 </para></listitem>
4882 <listitem><para>
4883 <emphasis>Change Your Working Directory:</emphasis>
4884 You need to be in the directory that has the temporary
4885 source code.
4886 That directory is defined by the
4887 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4888 variable.</para></listitem>
4889 <listitem><para>
4890 <emphasis>Create a New Patch:</emphasis>
4891 Before modifying source code, you need to create a new
4892 patch.
4893 To create a new patch file, use
4894 <filename>quilt new</filename> as below:
4895 <literallayout class='monospaced'>
4896 $ quilt new my_changes.patch
4897 </literallayout>
4898 </para></listitem>
4899 <listitem><para>
4900 <emphasis>Notify Quilt and Add Files:</emphasis>
4901 After creating the patch, you need to notify Quilt about
4902 the files you plan to edit.
4903 You notify Quilt by adding the files to the patch you
4904 just created:
4905 <literallayout class='monospaced'>
4906 $ quilt add file1.c file2.c file3.c
4907 </literallayout>
4908 </para></listitem>
4909 <listitem><para>
4910 <emphasis>Edit the Files:</emphasis>
4911 Make your changes in the source code to the files you added
4912 to the patch.
4913 </para></listitem>
4914 <listitem><para>
4915 <emphasis>Test Your Changes:</emphasis>
4916 Once you have modified the source code, the easiest way to
4917 test your changes is by calling the
4918 <filename>do_compile</filename> task as shown in the
4919 following example:
4920 <literallayout class='monospaced'>
4921 $ bitbake -c compile -f <replaceable>package</replaceable>
4922 </literallayout>
4923 The <filename>-f</filename> or <filename>--force</filename>
4924 option forces the specified task to execute.
4925 If you find problems with your code, you can just keep
4926 editing and re-testing iteratively until things work
4927 as expected.
4928 <note>
4929 All the modifications you make to the temporary
4930 source code disappear once you run the
4931 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4932 or
4933 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4934 tasks using BitBake (i.e.
4935 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4936 and
4937 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4938 Modifications will also disappear if you use the
4939 <filename>rm_work</filename> feature as described
4940 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004941 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4942 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004943 </note>
4944 </para></listitem>
4945 <listitem><para>
4946 <emphasis>Generate the Patch:</emphasis>
4947 Once your changes work as expected, you need to use Quilt
4948 to generate the final patch that contains all your
4949 modifications.
4950 <literallayout class='monospaced'>
4951 $ quilt refresh
4952 </literallayout>
4953 At this point, the <filename>my_changes.patch</filename>
4954 file has all your edits made to the
4955 <filename>file1.c</filename>, <filename>file2.c</filename>,
4956 and <filename>file3.c</filename> files.</para>
4957
4958 <para>You can find the resulting patch file in the
4959 <filename>patches/</filename> subdirectory of the source
4960 (<filename>S</filename>) directory.
4961 </para></listitem>
4962 <listitem><para>
4963 <emphasis>Copy the Patch File:</emphasis>
4964 For simplicity, copy the patch file into a directory
4965 named <filename>files</filename>, which you can create
4966 in the same directory that holds the recipe
4967 (<filename>.bb</filename>) file or the append
4968 (<filename>.bbappend</filename>) file.
4969 Placing the patch here guarantees that the OpenEmbedded
4970 build system will find the patch.
4971 Next, add the patch into the
4972 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4973 of the recipe.
4974 Here is an example:
4975 <literallayout class='monospaced'>
4976 SRC_URI += "file://my_changes.patch"
4977 </literallayout>
4978 </para></listitem>
4979 </orderedlist>
4980 </para>
4981 </section>
4982
4983 <section id="platdev-appdev-devshell">
4984 <title>Using a Development Shell</title>
4985
4986 <para>
4987 When debugging certain commands or even when just editing packages,
4988 <filename>devshell</filename> can be a useful tool.
4989 When you invoke <filename>devshell</filename>, all tasks up to and
4990 including
4991 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
4992 are run for the specified target.
4993 Then, a new terminal is opened and you are placed in
4994 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
4995 the source directory.
4996 In the new terminal, all the OpenEmbedded build-related environment variables are
4997 still defined so you can use commands such as <filename>configure</filename> and
4998 <filename>make</filename>.
4999 The commands execute just as if the OpenEmbedded build system were executing them.
5000 Consequently, working this way can be helpful when debugging a build or preparing
5001 software to be used with the OpenEmbedded build system.
5002 </para>
5003
5004 <para>
5005 Following is an example that uses <filename>devshell</filename> on a target named
5006 <filename>matchbox-desktop</filename>:
5007 <literallayout class='monospaced'>
5008 $ bitbake matchbox-desktop -c devshell
5009 </literallayout>
5010 </para>
5011
5012 <para>
5013 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5014 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5015 variable controls what type of shell is opened.
5016 </para>
5017
5018 <para>
5019 For spawned terminals, the following occurs:
5020 <itemizedlist>
5021 <listitem><para>The <filename>PATH</filename> variable includes the
5022 cross-toolchain.</para></listitem>
5023 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5024 <filename>.pc</filename> files.</para></listitem>
5025 <listitem><para>The <filename>configure</filename> command finds the
5026 Yocto Project site files as well as any other necessary files.</para></listitem>
5027 </itemizedlist>
5028 </para>
5029
5030 <para>
5031 Within this environment, you can run configure or compile
5032 commands as if they were being run by
5033 the OpenEmbedded build system itself.
5034 As noted earlier, the working directory also automatically changes to the
5035 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5036 </para>
5037
5038 <para>
5039 To manually run a specific task using <filename>devshell</filename>,
5040 run the corresponding <filename>run.*</filename> script in
5041 the
5042 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5043 directory (e.g.,
5044 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5045 If a task's script does not exist, which would be the case if the task was
5046 skipped by way of the sstate cache, you can create the task by first running
5047 it outside of the <filename>devshell</filename>:
5048 <literallayout class='monospaced'>
5049 $ bitbake -c <replaceable>task</replaceable>
5050 </literallayout>
5051 <note><title>Notes</title>
5052 <itemizedlist>
5053 <listitem><para>Execution of a task's <filename>run.*</filename>
5054 script and BitBake's execution of a task are identical.
5055 In other words, running the script re-runs the task
5056 just as it would be run using the
5057 <filename>bitbake -c</filename> command.
5058 </para></listitem>
5059 <listitem><para>Any <filename>run.*</filename> file that does not
5060 have a <filename>.pid</filename> extension is a
5061 symbolic link (symlink) to the most recent version of that
5062 file.
5063 </para></listitem>
5064 </itemizedlist>
5065 </note>
5066 </para>
5067
5068 <para>
5069 Remember, that the <filename>devshell</filename> is a mechanism that allows
5070 you to get into the BitBake task execution environment.
5071 And as such, all commands must be called just as BitBake would call them.
5072 That means you need to provide the appropriate options for
5073 cross-compilation and so forth as applicable.
5074 </para>
5075
5076 <para>
5077 When you are finished using <filename>devshell</filename>, exit the shell
5078 or close the terminal window.
5079 </para>
5080
5081 <note><title>Notes</title>
5082 <itemizedlist>
5083 <listitem><para>
5084 It is worth remembering that when using <filename>devshell</filename>
5085 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5086 instead of just using <filename>gcc</filename>.
5087 The same applies to other applications such as <filename>binutils</filename>,
5088 <filename>libtool</filename> and so forth.
5089 BitBake sets up environment variables such as <filename>CC</filename>
5090 to assist applications, such as <filename>make</filename> to find the correct tools.
5091 </para></listitem>
5092 <listitem><para>
5093 It is also worth noting that <filename>devshell</filename> still works over
5094 X11 forwarding and similar situations.
5095 </para></listitem>
5096 </itemizedlist>
5097 </note>
5098 </section>
5099
5100 <section id="platdev-appdev-devpyshell">
5101 <title>Using a Development Python Shell</title>
5102
5103 <para>
5104 Similar to working within a development shell as described in
5105 the previous section, you can also spawn and work within an
5106 interactive Python development shell.
5107 When debugging certain commands or even when just editing packages,
5108 <filename>devpyshell</filename> can be a useful tool.
5109 When you invoke <filename>devpyshell</filename>, all tasks up to and
5110 including
5111 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5112 are run for the specified target.
5113 Then a new terminal is opened.
5114 Additionally, key Python objects and code are available in the same
5115 way they are to BitBake tasks, in particular, the data store 'd'.
5116 So, commands such as the following are useful when exploring the data
5117 store and running functions:
5118 <literallayout class='monospaced'>
Brad Bishop19323692019-04-05 15:28:33 -04005119 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005120 '/media/build1/poky/build/tmp/sysroots'
Brad Bishop19323692019-04-05 15:28:33 -04005121 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005122 '${TMPDIR}/sysroots'
5123 pydevshell> d.setVar("FOO", "bar")
Brad Bishop19323692019-04-05 15:28:33 -04005124 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005125 'bar'
5126 pydevshell> d.delVar("FOO")
Brad Bishop19323692019-04-05 15:28:33 -04005127 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005128 pydevshell> bb.build.exec_func("do_unpack", d)
5129 pydevshell>
5130 </literallayout>
5131 The commands execute just as if the OpenEmbedded build system were executing them.
5132 Consequently, working this way can be helpful when debugging a build or preparing
5133 software to be used with the OpenEmbedded build system.
5134 </para>
5135
5136 <para>
5137 Following is an example that uses <filename>devpyshell</filename> on a target named
5138 <filename>matchbox-desktop</filename>:
5139 <literallayout class='monospaced'>
5140 $ bitbake matchbox-desktop -c devpyshell
5141 </literallayout>
5142 </para>
5143
5144 <para>
5145 This command spawns a terminal and places you in an interactive
5146 Python interpreter within the OpenEmbedded build environment.
5147 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5148 variable controls what type of shell is opened.
5149 </para>
5150
5151 <para>
5152 When you are finished using <filename>devpyshell</filename>, you
5153 can exit the shell either by using Ctrl+d or closing the terminal
5154 window.
5155 </para>
5156 </section>
5157
Brad Bishop316dfdd2018-06-25 12:45:53 -04005158 <section id='dev-building'>
5159 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005160
5161 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005162 This section describes various build procedures.
5163 For example, the steps needed for a simple build, a target that
5164 uses multiple configurations, building an image for more than
5165 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005166 </para>
5167
Brad Bishop316dfdd2018-06-25 12:45:53 -04005168 <section id='dev-building-a-simple-image'>
5169 <title>Building a Simple Image</title>
5170
5171 <para>
5172 In the development environment, you need to build an image
5173 whenever you change hardware support, add or change system
5174 libraries, or add or change services that have dependencies.
5175 Several methods exist that allow you to build an image within
5176 the Yocto Project.
5177 This section presents the basic steps you need to build a
5178 simple image using BitBake from a build host running Linux.
5179 <note><title>Notes</title>
5180 <itemizedlist>
5181 <listitem><para>
5182 For information on how to build an image using
5183 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5184 see the
5185 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5186 </para></listitem>
5187 <listitem><para>
5188 For information on how to use
5189 <filename>devtool</filename> to build images, see
5190 the
5191 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5192 section in the Yocto Project Application
5193 Development and the Extensible Software Development
5194 Kit (eSDK) manual.
5195 </para></listitem>
5196 <listitem><para>
5197 For a quick example on how to build an image using
5198 the OpenEmbedded build system, see the
5199 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5200 document.
5201 </para></listitem>
5202 </itemizedlist>
5203 </note>
5204 </para>
5205
5206 <para>
5207 The build process creates an entire Linux distribution from
5208 source and places it in your
5209 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5210 under <filename>tmp/deploy/images</filename>.
5211 For detailed information on the build process using BitBake,
5212 see the
5213 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5214 section in the Yocto Project Overview and Concepts Manual.
5215 </para>
5216
5217 <para>
5218 The following figure and list overviews the build process:
5219 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5220 <orderedlist>
5221 <listitem><para>
5222 <emphasis>Set up Your Host Development System to Support
5223 Development Using the Yocto Project</emphasis>:
5224 See the
5225 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5226 section for options on how to get a build host ready to
5227 use the Yocto Project.
5228 </para></listitem>
5229 <listitem><para>
5230 <emphasis>Initialize the Build Environment:</emphasis>
5231 Initialize the build environment by sourcing the build
5232 environment script (i.e.
5233 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5234 <literallayout class='monospaced'>
5235 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5236 </literallayout></para>
5237
5238 <para>When you use the initialization script, the
5239 OpenEmbedded build system uses
5240 <filename>build</filename> as the default Build
5241 Directory in your current work directory.
5242 You can use a <replaceable>build_dir</replaceable>
5243 argument with the script to specify a different build
5244 directory.
5245 <note><title>Tip</title>
5246 A common practice is to use a different Build
5247 Directory for different targets.
5248 For example, <filename>~/build/x86</filename> for a
5249 <filename>qemux86</filename> target, and
5250 <filename>~/build/arm</filename> for a
5251 <filename>qemuarm</filename> target.
5252 </note>
5253 </para></listitem>
5254 <listitem><para>
5255 <emphasis>Make Sure Your <filename>local.conf</filename>
5256 File is Correct:</emphasis>
5257 Ensure the <filename>conf/local.conf</filename>
5258 configuration file, which is found in the Build
5259 Directory, is set up how you want it.
5260 This file defines many aspects of the build environment
5261 including the target machine architecture through the
5262 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5263 the packaging format used during the build
5264 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5265 and a centralized tarball download directory through the
5266 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5267 </para></listitem>
5268 <listitem><para>
5269 <emphasis>Build the Image:</emphasis>
5270 Build the image using the <filename>bitbake</filename>
5271 command:
5272 <literallayout class='monospaced'>
5273 $ bitbake <replaceable>target</replaceable>
5274 </literallayout>
5275 <note>
5276 For information on BitBake, see the
5277 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5278 </note>
5279 The <replaceable>target</replaceable> is the name of the
5280 recipe you want to build.
5281 Common targets are the images in
5282 <filename>meta/recipes-core/images</filename>,
5283 <filename>meta/recipes-sato/images</filename>, and so
5284 forth all found in the
5285 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5286 Or, the target can be the name of a recipe for a
5287 specific piece of software such as BusyBox.
5288 For more details about the images the OpenEmbedded build
5289 system supports, see the
5290 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5291 chapter in the Yocto Project Reference Manual.</para>
5292
5293 <para>As an example, the following command builds the
5294 <filename>core-image-minimal</filename> image:
5295 <literallayout class='monospaced'>
5296 $ bitbake core-image-minimal
5297 </literallayout>
5298 Once an image has been built, it often needs to be
5299 installed.
5300 The images and kernels built by the OpenEmbedded
5301 build system are placed in the Build Directory in
5302 <filename class="directory">tmp/deploy/images</filename>.
5303 For information on how to run pre-built images such as
5304 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5305 see the
5306 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5307 manual.
5308 For information about how to install these images,
5309 see the documentation for your particular board or
5310 machine.
5311 </para></listitem>
5312 </orderedlist>
5313 </para>
5314 </section>
5315
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005316 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5317 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005318
5319 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005320 You can use a single <filename>bitbake</filename> command
5321 to build multiple images or packages for different targets
5322 where each image or package requires a different configuration
5323 (multiple configuration builds).
5324 The builds, in this scenario, are sometimes referred to as
5325 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005326 </para>
5327
5328 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005329 This section describes how to set up for multiple
5330 configuration builds and how to account for cross-build
5331 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005332 </para>
5333
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005334 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5335 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005336
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005337 <para>
5338 To accomplish a multiple configuration build, you must
5339 define each target's configuration separately using
5340 a parallel configuration file in the
5341 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5342 and you must follow a required file hierarchy.
5343 Additionally, you must enable the multiple configuration
5344 builds in your <filename>local.conf</filename> file.
5345 </para>
5346
5347 <para>
5348 Follow these steps to set up and execute multiple
5349 configuration builds:
5350 <itemizedlist>
5351 <listitem><para>
5352 <emphasis>Create Separate Configuration Files</emphasis>:
5353 You need to create a single configuration file for
5354 each build target (each multiconfig).
5355 Minimally, each configuration file must define the
5356 machine and the temporary directory BitBake uses
5357 for the build.
5358 Suggested practice dictates that you do not
5359 overlap the temporary directories
5360 used during the builds.
5361 However, it is possible that you can share the
5362 temporary directory
5363 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5364 For example, consider a scenario with two
5365 different multiconfigs for the same
5366 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5367 two distributions such as "poky" and "poky-lsb".
5368 In this case, you might want to use the same
5369 <filename>TMPDIR</filename>.</para>
5370
5371 <para>Here is an example showing the minimal
5372 statements needed in a configuration file for
5373 a "qemux86" target whose temporary build directory
5374 is <filename>tmpmultix86</filename>:
5375 <literallayout class='monospaced'>
5376 MACHINE="qemux86"
5377 TMPDIR="${TOPDIR}/tmpmultix86"
5378 </literallayout></para>
5379
5380 <para>The location for these multiconfig
5381 configuration files is specific.
5382 They must reside in the current build directory in
5383 a sub-directory of <filename>conf</filename> named
5384 <filename>multiconfig</filename>.
5385 Following is an example that defines two
5386 configuration files for the "x86" and "arm"
5387 multiconfigs:
5388 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5389 </para>
5390
5391 <para>The reason for this required file hierarchy
5392 is because the <filename>BBPATH</filename> variable
5393 is not constructed until the layers are parsed.
5394 Consequently, using the configuration file as a
5395 pre-configuration file is not possible unless it is
5396 located in the current working directory.
5397 </para></listitem>
5398 <listitem><para>
5399 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5400 Use the
5401 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5402 variable in your
5403 <filename>conf/local.conf</filename> configuration
5404 file to specify each multiconfig.
5405 Continuing with the example from the previous
5406 figure, the <filename>BBMULTICONFIG</filename>
5407 variable needs to enable two multiconfigs: "x86"
5408 and "arm" by specifying each configuration file:
5409 <literallayout class='monospaced'>
5410 BBMULTICONFIG = "x86 arm"
5411 </literallayout>
5412 </para></listitem>
5413 <listitem><para>
5414 <emphasis>Launch BitBake</emphasis>:
5415 Use the following BitBake command form to launch the
5416 multiple configuration build:
5417 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005418 $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005419 </literallayout>
5420 For the example in this section, the following
5421 command applies:
5422 <literallayout class='monospaced'>
5423 $ bitbake multiconfig:x86:core-image-minimal multiconfig:arm:core-image-sato
5424 </literallayout>
5425 The previous BitBake command builds a
5426 <filename>core-image-minimal</filename> image that
5427 is configured through the
5428 <filename>x86.conf</filename> configuration file
5429 and builds a <filename>core-image-sato</filename>
5430 image that is configured through the
5431 <filename>arm.conf</filename> configuration file.
5432 </para></listitem>
5433 </itemizedlist>
5434 <note>
5435 Support for multiple configuration builds in the
5436 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5437 not include Shared State (sstate) optimizations.
5438 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005439 in, for example, two different
5440 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005441 either loads from an existing sstate cache for that
5442 build at the start or builds the object fresh.
5443 </note>
5444 </para>
5445 </section>
5446
5447 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5448 <title>Enabling Multiple Configuration Build Dependencies</title>
5449
5450 <para>
5451 Sometimes dependencies can exist between targets
5452 (multiconfigs) in a multiple configuration build.
5453 For example, suppose that in order to build a
5454 <filename>core-image-sato</filename> image for an "x86"
5455 multiconfig, the root filesystem of an "arm"
5456 multiconfig must exist.
5457 This dependency is essentially that the
5458 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5459 task in the <filename>core-image-sato</filename> recipe
5460 depends on the completion of the
5461 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5462 task of the <filename>core-image-minimal</filename>
5463 recipe.
5464 </para>
5465
5466 <para>
5467 To enable dependencies in a multiple configuration
5468 build, you must declare the dependencies in the recipe
5469 using the following statement form:
5470 <literallayout class='monospaced'>
5471 <replaceable>task_or_package</replaceable>[mcdepends] = "multiconfig:<replaceable>from_multiconfig</replaceable>:<replaceable>to_multiconfig</replaceable>:<replaceable>recipe_name</replaceable>:<replaceable>task_on_which_to_depend</replaceable>"
5472 </literallayout>
5473 To better show how to use this statement, consider the
5474 example scenario from the first paragraph of this section.
5475 The following statement needs to be added to the recipe
5476 that builds the <filename>core-image-sato</filename>
5477 image:
5478 <literallayout class='monospaced'>
5479 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_rootfs"
5480 </literallayout>
5481 In this example, the
5482 <replaceable>from_multiconfig</replaceable> is "x86".
5483 The <replaceable>to_multiconfig</replaceable> is "arm".
5484 The task on which the <filename>do_image</filename> task
5485 in the recipe depends is the <filename>do_rootfs</filename>
5486 task from the <filename>core-image-minimal</filename>
5487 recipe associated with the "arm" multiconfig.
5488 </para>
5489
5490 <para>
5491 Once you set up this dependency, you can build the
5492 "x86" multiconfig using a BitBake command as follows:
5493 <literallayout class='monospaced'>
5494 $ bitbake multiconfig:x86:core-image-sato
5495 </literallayout>
5496 This command executes all the tasks needed to create
5497 the <filename>core-image-sato</filename> image for the
5498 "x86" multiconfig.
5499 Because of the dependency, BitBake also executes through
5500 the <filename>do_rootfs</filename> task for the "arm"
5501 multiconfig build.
5502 </para>
5503
5504 <para>
5505 Having a recipe depend on the root filesystem of another
5506 build might not seem that useful.
5507 Consider this change to the statement in the
5508 <filename>core-image-sato</filename> recipe:
5509 <literallayout class='monospaced'>
5510 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_image"
5511 </literallayout>
5512 In this case, BitBake must create the
5513 <filename>core-image-minimal</filename> image for the
5514 "arm" build since the "x86" build depends on it.
5515 </para>
5516
5517 <para>
5518 Because "x86" and "arm" are enabled for multiple
5519 configuration builds and have separate configuration
5520 files, BitBake places the artifacts for each build in the
5521 respective temporary build directories (i.e.
5522 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5523 </para>
5524 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005525 </section>
5526
5527 <section id='building-an-initramfs-image'>
5528 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5529
5530 <para>
5531 An initial RAM filesystem (initramfs) image provides a temporary
5532 root filesystem used for early system initialization (e.g.
5533 loading of modules needed to locate and mount the "real" root
5534 filesystem).
5535 <note>
5536 The initramfs image is the successor of initial RAM disk
5537 (initrd).
5538 It is a "copy in and out" (cpio) archive of the initial
5539 filesystem that gets loaded into memory during the Linux
5540 startup process.
5541 Because Linux uses the contents of the archive during
5542 initialization, the initramfs image needs to contain all of the
5543 device drivers and tools needed to mount the final root
5544 filesystem.
5545 </note>
5546 </para>
5547
5548 <para>
5549 Follow these steps to create an initramfs image:
5550 <orderedlist>
5551 <listitem><para>
5552 <emphasis>Create the initramfs Image Recipe:</emphasis>
5553 You can reference the
5554 <filename>core-image-minimal-initramfs.bb</filename>
5555 recipe found in the <filename>meta/recipes-core</filename>
5556 directory of the
5557 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5558 as an example from which to work.
5559 </para></listitem>
5560 <listitem><para>
5561 <emphasis>Decide if You Need to Bundle the initramfs Image
5562 Into the Kernel Image:</emphasis>
5563 If you want the initramfs image that is built to be
5564 bundled in with the kernel image, set the
5565 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5566 variable to "1" in your <filename>local.conf</filename>
5567 configuration file and set the
5568 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5569 variable in the recipe that builds the kernel image.
5570 <note><title>Tip</title>
5571 It is recommended that you do bundle the initramfs
5572 image with the kernel image to avoid circular
5573 dependencies between the kernel recipe and the
5574 initramfs recipe should the initramfs image
5575 include kernel modules.
5576 </note>
5577 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5578 flag causes the initramfs image to be unpacked
5579 into the <filename>${B}/usr/</filename> directory.
5580 The unpacked initramfs image is then passed to the kernel's
5581 <filename>Makefile</filename> using the
5582 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5583 variable, allowing the initramfs image to be built into
5584 the kernel normally.
5585 <note>
5586 If you choose to not bundle the initramfs image with
5587 the kernel image, you are essentially using an
5588 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5589 Creating an initrd is handled primarily through the
5590 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5591 <filename>INITRD_LIVE</filename>, and
5592 <filename>INITRD_IMAGE_LIVE</filename> variables.
5593 For more information, see the
5594 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5595 file.
5596 </note>
5597 </para></listitem>
5598 <listitem><para>
5599 <emphasis>Optionally Add Items to the initramfs Image
5600 Through the initramfs Image Recipe:</emphasis>
5601 If you add items to the initramfs image by way of its
5602 recipe, you should use
5603 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5604 rather than
5605 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5606 <filename>PACKAGE_INSTALL</filename> gives more direct
5607 control of what is added to the image as compared to
5608 the defaults you might not necessarily want that are
5609 set by the
5610 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5611 or
5612 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5613 classes.
5614 </para></listitem>
5615 <listitem><para>
5616 <emphasis>Build the Kernel Image and the initramfs
5617 Image:</emphasis>
5618 Build your kernel image using BitBake.
5619 Because the initramfs image recipe is a dependency of the
5620 kernel image, the initramfs image is built as well and
5621 bundled with the kernel image if you used the
5622 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5623 variable described earlier.
5624 </para></listitem>
5625 </orderedlist>
5626 </para>
5627 </section>
5628
5629 <section id='building-a-tiny-system'>
5630 <title>Building a Tiny System</title>
5631
5632 <para>
5633 Very small distributions have some significant advantages such
5634 as requiring less on-die or in-package memory (cheaper), better
5635 performance through efficient cache usage, lower power requirements
5636 due to less memory, faster boot times, and reduced development
5637 overhead.
5638 Some real-world examples where a very small distribution gives
5639 you distinct advantages are digital cameras, medical devices,
5640 and small headless systems.
5641 </para>
5642
5643 <para>
5644 This section presents information that shows you how you can
5645 trim your distribution to even smaller sizes than the
5646 <filename>poky-tiny</filename> distribution, which is around
5647 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5648 </para>
5649
5650 <section id='tiny-system-overview'>
5651 <title>Overview</title>
5652
5653 <para>
5654 The following list presents the overall steps you need to
5655 consider and perform to create distributions with smaller
5656 root filesystems, achieve faster boot times, maintain your critical
5657 functionality, and avoid initial RAM disks:
5658 <itemizedlist>
5659 <listitem><para>
5660 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5661 </para></listitem>
5662 <listitem><para>
5663 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5664 </para></listitem>
5665 <listitem><para>
5666 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5667 </para></listitem>
5668 <listitem><para>
5669 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5670 </para></listitem>
5671 <listitem><para>
5672 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5673 </para></listitem>
5674 <listitem><para>
5675 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5676 </para></listitem>
5677 <listitem><para>
5678 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5679 </para></listitem>
5680 </itemizedlist>
5681 </para>
5682 </section>
5683
5684 <section id='goals-and-guiding-principles'>
5685 <title>Goals and Guiding Principles</title>
5686
5687 <para>
5688 Before you can reach your destination, you need to know
5689 where you are going.
5690 Here is an example list that you can use as a guide when
5691 creating very small distributions:
5692 <itemizedlist>
5693 <listitem><para>Determine how much space you need
5694 (e.g. a kernel that is 1 Mbyte or less and
5695 a root filesystem that is 3 Mbytes or less).
5696 </para></listitem>
5697 <listitem><para>Find the areas that are currently
5698 taking 90% of the space and concentrate on reducing
5699 those areas.
5700 </para></listitem>
5701 <listitem><para>Do not create any difficult "hacks"
5702 to achieve your goals.</para></listitem>
5703 <listitem><para>Leverage the device-specific
5704 options.</para></listitem>
5705 <listitem><para>Work in a separate layer so that you
5706 keep changes isolated.
5707 For information on how to create layers, see
5708 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5709 </para></listitem>
5710 </itemizedlist>
5711 </para>
5712 </section>
5713
5714 <section id='understand-what-gives-your-image-size'>
5715 <title>Understand What Contributes to Your Image Size</title>
5716
5717 <para>
5718 It is easiest to have something to start with when creating
5719 your own distribution.
5720 You can use the Yocto Project out-of-the-box to create the
5721 <filename>poky-tiny</filename> distribution.
5722 Ultimately, you will want to make changes in your own
5723 distribution that are likely modeled after
5724 <filename>poky-tiny</filename>.
5725 <note>
5726 To use <filename>poky-tiny</filename> in your build,
5727 set the
5728 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5729 variable in your
5730 <filename>local.conf</filename> file to "poky-tiny"
5731 as described in the
5732 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5733 section.
5734 </note>
5735 </para>
5736
5737 <para>
5738 Understanding some memory concepts will help you reduce the
5739 system size.
5740 Memory consists of static, dynamic, and temporary memory.
5741 Static memory is the TEXT (code), DATA (initialized data
5742 in the code), and BSS (uninitialized data) sections.
5743 Dynamic memory represents memory that is allocated at runtime:
5744 stacks, hash tables, and so forth.
5745 Temporary memory is recovered after the boot process.
5746 This memory consists of memory used for decompressing
5747 the kernel and for the <filename>__init__</filename>
5748 functions.
5749 </para>
5750
5751 <para>
5752 To help you see where you currently are with kernel and root
5753 filesystem sizes, you can use two tools found in the
5754 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5755 the <filename>scripts/tiny/</filename> directory:
5756 <itemizedlist>
5757 <listitem><para><filename>ksize.py</filename>: Reports
5758 component sizes for the kernel build objects.
5759 </para></listitem>
5760 <listitem><para><filename>dirsize.py</filename>: Reports
5761 component sizes for the root filesystem.</para></listitem>
5762 </itemizedlist>
5763 This next tool and command help you organize configuration
5764 fragments and view file dependencies in a human-readable form:
5765 <itemizedlist>
5766 <listitem><para><filename>merge_config.sh</filename>:
5767 Helps you manage configuration files and fragments
5768 within the kernel.
5769 With this tool, you can merge individual configuration
5770 fragments together.
5771 The tool allows you to make overrides and warns you
5772 of any missing configuration options.
5773 The tool is ideal for allowing you to iterate on
5774 configurations, create minimal configurations, and
5775 create configuration files for different machines
5776 without having to duplicate your process.</para>
5777 <para>The <filename>merge_config.sh</filename> script is
5778 part of the Linux Yocto kernel Git repositories
5779 (i.e. <filename>linux-yocto-3.14</filename>,
5780 <filename>linux-yocto-3.10</filename>,
5781 <filename>linux-yocto-3.8</filename>, and so forth)
5782 in the
5783 <filename>scripts/kconfig</filename> directory.</para>
5784 <para>For more information on configuration fragments,
5785 see the
5786 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5787 section in the Yocto Project Linux Kernel Development
5788 Manual.
5789 </para></listitem>
5790 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5791 Using the BitBake command with these options brings up
5792 a Dependency Explorer from which you can view file
5793 dependencies.
5794 Understanding these dependencies allows you to make
5795 informed decisions when cutting out various pieces of the
5796 kernel and root filesystem.</para></listitem>
5797 </itemizedlist>
5798 </para>
5799 </section>
5800
5801 <section id='trim-the-root-filesystem'>
5802 <title>Trim the Root Filesystem</title>
5803
5804 <para>
5805 The root filesystem is made up of packages for booting,
5806 libraries, and applications.
5807 To change things, you can configure how the packaging happens,
5808 which changes the way you build them.
5809 You can also modify the filesystem itself or select a different
5810 filesystem.
5811 </para>
5812
5813 <para>
5814 First, find out what is hogging your root filesystem by running the
5815 <filename>dirsize.py</filename> script from your root directory:
5816 <literallayout class='monospaced'>
5817 $ cd <replaceable>root-directory-of-image</replaceable>
5818 $ dirsize.py 100000 > dirsize-100k.log
5819 $ cat dirsize-100k.log
5820 </literallayout>
5821 You can apply a filter to the script to ignore files under
5822 a certain size.
5823 The previous example filters out any files below 100 Kbytes.
5824 The sizes reported by the tool are uncompressed, and thus
5825 will be smaller by a relatively constant factor in a
5826 compressed root filesystem.
5827 When you examine your log file, you can focus on areas of the
5828 root filesystem that take up large amounts of memory.
5829 </para>
5830
5831 <para>
5832 You need to be sure that what you eliminate does not cripple
5833 the functionality you need.
5834 One way to see how packages relate to each other is by using
5835 the Dependency Explorer UI with the BitBake command:
5836 <literallayout class='monospaced'>
5837 $ cd <replaceable>image-directory</replaceable>
5838 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5839 </literallayout>
5840 Use the interface to select potential packages you wish to
5841 eliminate and see their dependency relationships.
5842 </para>
5843
5844 <para>
5845 When deciding how to reduce the size, get rid of packages that
5846 result in minimal impact on the feature set.
5847 For example, you might not need a VGA display.
5848 Or, you might be able to get by with <filename>devtmpfs</filename>
5849 and <filename>mdev</filename> instead of
5850 <filename>udev</filename>.
5851 </para>
5852
5853 <para>
5854 Use your <filename>local.conf</filename> file to make changes.
5855 For example, to eliminate <filename>udev</filename> and
5856 <filename>glib</filename>, set the following in the
5857 local configuration file:
5858 <literallayout class='monospaced'>
5859 VIRTUAL-RUNTIME_dev_manager = ""
5860 </literallayout>
5861 </para>
5862
5863 <para>
5864 Finally, you should consider exactly the type of root
5865 filesystem you need to meet your needs while also reducing
5866 its size.
5867 For example, consider <filename>cramfs</filename>,
5868 <filename>squashfs</filename>, <filename>ubifs</filename>,
5869 <filename>ext2</filename>, or an <filename>initramfs</filename>
5870 using <filename>initramfs</filename>.
5871 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5872 journal.
5873 If you are okay with running read-only, you do not need this
5874 journal.
5875 </para>
5876
5877 <note>
5878 After each round of elimination, you need to rebuild your
5879 system and then use the tools to see the effects of your
5880 reductions.
5881 </note>
5882 </section>
5883
5884 <section id='trim-the-kernel'>
5885 <title>Trim the Kernel</title>
5886
5887 <para>
5888 The kernel is built by including policies for hardware-independent
5889 aspects.
5890 What subsystems do you enable?
5891 For what architecture are you building?
5892 Which drivers do you build by default?
5893 <note>You can modify the kernel source if you want to help
5894 with boot time.
5895 </note>
5896 </para>
5897
5898 <para>
5899 Run the <filename>ksize.py</filename> script from the top-level
5900 Linux build directory to get an idea of what is making up
5901 the kernel:
5902 <literallayout class='monospaced'>
5903 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5904 $ ksize.py > ksize.log
5905 $ cat ksize.log
5906 </literallayout>
5907 When you examine the log, you will see how much space is
5908 taken up with the built-in <filename>.o</filename> files for
5909 drivers, networking, core kernel files, filesystem, sound,
5910 and so forth.
5911 The sizes reported by the tool are uncompressed, and thus
5912 will be smaller by a relatively constant factor in a compressed
5913 kernel image.
5914 Look to reduce the areas that are large and taking up around
5915 the "90% rule."
5916 </para>
5917
5918 <para>
5919 To examine, or drill down, into any particular area, use the
5920 <filename>-d</filename> option with the script:
5921 <literallayout class='monospaced'>
5922 $ ksize.py -d > ksize.log
5923 </literallayout>
5924 Using this option breaks out the individual file information
5925 for each area of the kernel (e.g. drivers, networking, and
5926 so forth).
5927 </para>
5928
5929 <para>
5930 Use your log file to see what you can eliminate from the kernel
5931 based on features you can let go.
5932 For example, if you are not going to need sound, you do not
5933 need any drivers that support sound.
5934 </para>
5935
5936 <para>
5937 After figuring out what to eliminate, you need to reconfigure
5938 the kernel to reflect those changes during the next build.
5939 You could run <filename>menuconfig</filename> and make all your
5940 changes at once.
5941 However, that makes it difficult to see the effects of your
5942 individual eliminations and also makes it difficult to replicate
5943 the changes for perhaps another target device.
5944 A better method is to start with no configurations using
5945 <filename>allnoconfig</filename>, create configuration
5946 fragments for individual changes, and then manage the
5947 fragments into a single configuration file using
5948 <filename>merge_config.sh</filename>.
5949 The tool makes it easy for you to iterate using the
5950 configuration change and build cycle.
5951 </para>
5952
5953 <para>
5954 Each time you make configuration changes, you need to rebuild
5955 the kernel and check to see what impact your changes had on
5956 the overall size.
5957 </para>
5958 </section>
5959
5960 <section id='remove-package-management-requirements'>
5961 <title>Remove Package Management Requirements</title>
5962
5963 <para>
5964 Packaging requirements add size to the image.
5965 One way to reduce the size of the image is to remove all the
5966 packaging requirements from the image.
5967 This reduction includes both removing the package manager
5968 and its unique dependencies as well as removing the package
5969 management data itself.
5970 </para>
5971
5972 <para>
5973 To eliminate all the packaging requirements for an image,
5974 be sure that "package-management" is not part of your
5975 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5976 statement for the image.
5977 When you remove this feature, you are removing the package
5978 manager as well as its dependencies from the root filesystem.
5979 </para>
5980 </section>
5981
5982 <section id='look-for-other-ways-to-minimize-size'>
5983 <title>Look for Other Ways to Minimize Size</title>
5984
5985 <para>
5986 Depending on your particular circumstances, other areas that you
5987 can trim likely exist.
5988 The key to finding these areas is through tools and methods
5989 described here combined with experimentation and iteration.
5990 Here are a couple of areas to experiment with:
5991 <itemizedlist>
5992 <listitem><para><filename>glibc</filename>:
5993 In general, follow this process:
5994 <orderedlist>
5995 <listitem><para>Remove <filename>glibc</filename>
5996 features from
5997 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
5998 that you think you do not need.</para></listitem>
5999 <listitem><para>Build your distribution.
6000 </para></listitem>
6001 <listitem><para>If the build fails due to missing
6002 symbols in a package, determine if you can
6003 reconfigure the package to not need those
6004 features.
6005 For example, change the configuration to not
6006 support wide character support as is done for
6007 <filename>ncurses</filename>.
6008 Or, if support for those characters is needed,
6009 determine what <filename>glibc</filename>
6010 features provide the support and restore the
6011 configuration.
6012 </para></listitem>
6013 <listitem><para>Rebuild and repeat the process.
6014 </para></listitem>
6015 </orderedlist></para></listitem>
6016 <listitem><para><filename>busybox</filename>:
6017 For BusyBox, use a process similar as described for
6018 <filename>glibc</filename>.
6019 A difference is you will need to boot the resulting
6020 system to see if you are able to do everything you
6021 expect from the running system.
6022 You need to be sure to integrate configuration fragments
6023 into Busybox because BusyBox handles its own core
6024 features and then allows you to add configuration
6025 fragments on top.
6026 </para></listitem>
6027 </itemizedlist>
6028 </para>
6029 </section>
6030
6031 <section id='iterate-on-the-process'>
6032 <title>Iterate on the Process</title>
6033
6034 <para>
6035 If you have not reached your goals on system size, you need
6036 to iterate on the process.
6037 The process is the same.
6038 Use the tools and see just what is taking up 90% of the root
6039 filesystem and the kernel.
6040 Decide what you can eliminate without limiting your device
6041 beyond what you need.
6042 </para>
6043
6044 <para>
6045 Depending on your system, a good place to look might be
6046 Busybox, which provides a stripped down
6047 version of Unix tools in a single, executable file.
6048 You might be able to drop virtual terminal services or perhaps
6049 ipv6.
6050 </para>
6051 </section>
6052 </section>
6053
6054 <section id='building-images-for-more-than-one-machine'>
6055 <title>Building Images for More than One Machine</title>
6056
6057 <para>
6058 A common scenario developers face is creating images for several
6059 different machines that use the same software environment.
6060 In this situation, it is tempting to set the
6061 tunings and optimization flags for each build specifically for
6062 the targeted hardware (i.e. "maxing out" the tunings).
6063 Doing so can considerably add to build times and package feed
6064 maintenance collectively for the machines.
6065 For example, selecting tunes that are extremely specific to a
6066 CPU core used in a system might enable some micro optimizations
6067 in GCC for that particular system but would otherwise not gain
6068 you much of a performance difference across the other systems
6069 as compared to using a more general tuning across all the builds
6070 (e.g. setting
6071 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6072 specifically for each machine's build).
6073 Rather than "max out" each build's tunings, you can take steps that
6074 cause the OpenEmbedded build system to reuse software across the
6075 various machines where it makes sense.
6076 </para>
6077
6078 <para>
6079 If build speed and package feed maintenance are considerations,
6080 you should consider the points in this section that can help you
6081 optimize your tunings to best consider build times and package
6082 feed maintenance.
6083 <itemizedlist>
6084 <listitem><para>
6085 <emphasis>Share the Build Directory:</emphasis>
6086 If at all possible, share the
6087 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6088 across builds.
6089 The Yocto Project supports switching between different
6090 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6091 values in the same <filename>TMPDIR</filename>.
6092 This practice is well supported and regularly used by
6093 developers when building for multiple machines.
6094 When you use the same <filename>TMPDIR</filename> for
6095 multiple machine builds, the OpenEmbedded build system can
6096 reuse the existing native and often cross-recipes for
6097 multiple machines.
6098 Thus, build time decreases.
6099 <note>
6100 If
6101 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6102 settings change or fundamental configuration settings
6103 such as the filesystem layout, you need to work with
6104 a clean <filename>TMPDIR</filename>.
6105 Sharing <filename>TMPDIR</filename> under these
6106 circumstances might work but since it is not
6107 guaranteed, you should use a clean
6108 <filename>TMPDIR</filename>.
6109 </note>
6110 </para></listitem>
6111 <listitem><para>
6112 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6113 By default, the OpenEmbedded build system enables three
6114 levels of package architectures: "all", "tune" or "package",
6115 and "machine".
6116 Any given recipe usually selects one of these package
6117 architectures (types) for its output.
6118 Depending for what a given recipe creates packages, making
6119 sure you enable the appropriate package architecture can
6120 directly impact the build time.</para>
6121
6122 <para>A recipe that just generates scripts can enable
6123 "all" architecture because there are no binaries to build.
6124 To specifically enable "all" architecture, be sure your
6125 recipe inherits the
6126 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6127 class.
6128 This class is useful for "all" architectures because it
6129 configures many variables so packages can be used across
6130 multiple architectures.</para>
6131
6132 <para>If your recipe needs to generate packages that are
6133 machine-specific or when one of the build or runtime
6134 dependencies is already machine-architecture dependent,
6135 which makes your recipe also machine-architecture dependent,
6136 make sure your recipe enables the "machine" package
6137 architecture through the
6138 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6139 variable:
6140 <literallayout class='monospaced'>
6141 PACKAGE_ARCH = "${MACHINE_ARCH}"
6142 </literallayout>
6143 When you do not specifically enable a package
6144 architecture through the
6145 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6146 The OpenEmbedded build system defaults to the
6147 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6148 setting:
6149 <literallayout class='monospaced'>
6150 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6151 </literallayout>
6152 </para></listitem>
6153 <listitem><para>
6154 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6155 Some tunes are more generic and can run on multiple targets
6156 (e.g. an <filename>armv5</filename> set of packages could
6157 run on <filename>armv6</filename> and
6158 <filename>armv7</filename> processors in most cases).
6159 Similarly, <filename>i486</filename> binaries could work
6160 on <filename>i586</filename> and higher processors.
6161 You should realize, however, that advances on newer
6162 processor versions would not be used.</para>
6163
6164 <para>If you select the same tune for several different
6165 machines, the OpenEmbedded build system reuses software
6166 previously built, thus speeding up the overall build time.
6167 Realize that even though a new sysroot for each machine is
6168 generated, the software is not recompiled and only one
6169 package feed exists.
6170 </para></listitem>
6171 <listitem><para>
6172 <emphasis>Manage Granular Level Packaging:</emphasis>
6173 Sometimes cases exist where injecting another level of
6174 package architecture beyond the three higher levels noted
6175 earlier can be useful.
6176 For example, consider how NXP (formerly Freescale) allows
6177 for the easy reuse of binary packages in their layer
6178 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6179 In this example, the
6180 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6181 class shares GPU packages for i.MX53 boards because
6182 all boards share the AMD GPU.
6183 The i.MX6-based boards can do the same because all boards
6184 share the Vivante GPU.
6185 This class inspects the BitBake datastore to identify if
6186 the package provides or depends on one of the
6187 sub-architecture values.
6188 If so, the class sets the
6189 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6190 value based on the <filename>MACHINE_SUBARCH</filename>
6191 value.
6192 If the package does not provide or depend on one of the
6193 sub-architecture values but it matches a value in the
6194 machine-specific filter, it sets
6195 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6196 This behavior reduces the number of packages built and
6197 saves build time by reusing binaries.
6198 </para></listitem>
6199 <listitem><para>
6200 <emphasis>Use Tools to Debug Issues:</emphasis>
6201 Sometimes you can run into situations where software is
6202 being rebuilt when you think it should not be.
6203 For example, the OpenEmbedded build system might not be
6204 using shared state between machines when you think it
6205 should be.
6206 These types of situations are usually due to references
6207 to machine-specific variables such as
6208 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6209 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6210 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6211 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6212 and so forth in code that is supposed to only be
6213 tune-specific or when the recipe depends
6214 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6215 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6216 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6217 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6218 and so forth) on some other recipe that already has
6219 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6220 defined as "${MACHINE_ARCH}".
6221 <note>
6222 Patches to fix any issues identified are most welcome
6223 as these issues occasionally do occur.
6224 </note></para>
6225
6226 <para>For such cases, you can use some tools to help you
6227 sort out the situation:
6228 <itemizedlist>
6229 <listitem><para>
6230 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6231 You can find this tool in the
6232 <filename>scripts</filename> directory of the
6233 Source Repositories.
6234 See the comments in the script for information on
6235 how to use the tool.
6236 </para></listitem>
6237 <listitem><para>
6238 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6239 Using this option causes BitBake to try to
6240 establish the closest signature match it can
6241 (e.g. in the shared state cache) and then run
6242 <filename>bitbake-diffsigs</filename> over the
6243 matches to determine the stamps and delta where
6244 these two stamp trees diverge.
6245 </para></listitem>
6246 </itemizedlist>
6247 </para></listitem>
6248 </itemizedlist>
6249 </para>
6250 </section>
6251
6252 <section id="building-software-from-an-external-source">
6253 <title>Building Software from an External Source</title>
6254
6255 <para>
6256 By default, the OpenEmbedded build system uses the
6257 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6258 when building source code.
6259 The build process involves fetching the source files, unpacking
6260 them, and then patching them if necessary before the build takes
6261 place.
6262 </para>
6263
6264 <para>
6265 Situations exist where you might want to build software from source
6266 files that are external to and thus outside of the
6267 OpenEmbedded build system.
6268 For example, suppose you have a project that includes a new BSP with
6269 a heavily customized kernel.
6270 And, you want to minimize exposing the build system to the
6271 development team so that they can focus on their project and
6272 maintain everyone's workflow as much as possible.
6273 In this case, you want a kernel source directory on the development
6274 machine where the development occurs.
6275 You want the recipe's
6276 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6277 variable to point to the external directory and use it as is, not
6278 copy it.
6279 </para>
6280
6281 <para>
6282 To build from software that comes from an external source, all you
6283 need to do is inherit the
6284 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6285 class and then set the
6286 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6287 variable to point to your external source code.
6288 Here are the statements to put in your
6289 <filename>local.conf</filename> file:
6290 <literallayout class='monospaced'>
6291 INHERIT += "externalsrc"
6292 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6293 </literallayout>
6294 </para>
6295
6296 <para>
6297 This next example shows how to accomplish the same thing by setting
6298 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6299 recipe's append file:
6300 <literallayout class='monospaced'>
6301 EXTERNALSRC = "<replaceable>path</replaceable>"
6302 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6303 </literallayout>
6304 <note>
6305 In order for these settings to take effect, you must globally
6306 or locally inherit the
6307 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6308 class.
6309 </note>
6310 </para>
6311
6312 <para>
6313 By default, <filename>externalsrc.bbclass</filename> builds
6314 the source code in a directory separate from the external source
6315 directory as specified by
6316 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6317 If you need to have the source built in the same directory in
6318 which it resides, or some other nominated directory, you can set
6319 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6320 to point to that directory:
6321 <literallayout class='monospaced'>
6322 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6323 </literallayout>
6324 </para>
6325 </section>
Brad Bishop19323692019-04-05 15:28:33 -04006326
6327 <section id="replicating-a-build-offline">
6328 <title>Replicating a Build Offline</title>
6329
6330 <para>
6331 It can be useful to take a "snapshot" of upstream sources
6332 used in a build and then use that "snapshot" later to
6333 replicate the build offline.
6334 To do so, you need to first prepare and populate your downloads
6335 directory your "snapshot" of files.
6336 Once your downloads directory is ready, you can use it at
6337 any time and from any machine to replicate your build.
6338 </para>
6339
6340 <para>
6341 Follow these steps to populate your Downloads directory:
6342 <orderedlist>
6343 <listitem><para>
6344 <emphasis>Create a Clean Downloads Directory:</emphasis>
6345 Start with an empty downloads directory
6346 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>).
6347 You start with an empty downloads directory by either
6348 removing the files in the existing directory or by
6349 setting
6350 <filename>DL_DIR</filename> to point to either an
6351 empty location or one that does not yet exist.
6352 </para></listitem>
6353 <listitem><para>
6354 <emphasis>Generate Tarballs of the Source Git Repositories:</emphasis>
6355 Edit your <filename>local.conf</filename> configuration
6356 file as follows:
6357 <literallayout class='monospaced'>
6358 DL_DIR = "/home/<replaceable>your-download-dir</replaceable>/"
6359 BB_GENERATE_MIRROR_TARBALLS = "1"
6360 </literallayout>
6361 During the fetch process in the next step, BitBake
6362 gathers the source files and creates tarballs in
6363 the directory pointed to by <filename>DL_DIR</filename>.
6364 See the
6365 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
6366 variable for more information.
6367 </para></listitem>
6368 <listitem><para>
6369 <emphasis>Populate Your Downloads Directory Without Building:</emphasis>
6370 Use BitBake to fetch your sources but inhibit the
6371 build:
6372 <literallayout class='monospaced'>
6373 $ bitbake <replaceable>target</replaceable> --runonly=fetch
6374 </literallayout>
6375 The downloads directory (i.e.
6376 <filename>${DL_DIR}</filename>) now has a "snapshot" of
6377 the source files in the form of tarballs, which can
6378 be used for the build.
6379 </para></listitem>
6380 <listitem><para>
6381 <emphasis>Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory:</emphasis>
6382 If you want, you can clean up your downloads directory
6383 by removing any Git or other Source Control Management
6384 (SCM) subdirectories such as
6385 <filename>${DL_DIR}/git2/*</filename>.
6386 The tarballs already contain these subdirectories.
6387 </para></listitem>
6388 </orderedlist>
6389 </para>
6390
6391 <para>
6392 Once your downloads directory has everything it needs regarding
6393 source files, you can create your "own-mirror" and build
6394 your target.
6395 Understand that you can use the files to build the target
6396 offline from any machine and at any time.
6397 </para>
6398
6399 <para>
6400 Follow these steps to build your target using the files in the
6401 downloads directory:
6402 <orderedlist>
6403 <listitem><para>
6404 <emphasis>Using Local Files Only:</emphasis>
6405 Inside your <filename>local.conf</filename> file, add
6406 the
6407 <ulink url='&YOCTO_DOCS_REF_URL;#var-SOURCE_MIRROR_URL'><filename>SOURCE_MIRROR_URL</filename></ulink>
6408 variable,
6409 inherit the <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-own-mirrors'><filename>own-mirrors</filename></ulink>
6410 class, and use the
6411 <ulink url='&YOCTO_DOCS_BB_URL;#var-bb-BB_NO_NETWORK'><filename>BB_NO_NETWORK</filename></ulink>
6412 variable to your <filename>local.conf</filename>.
6413 <literallayout class='monospaced'>
6414 SOURCE_MIRROR_URL ?= "file:///home/<replaceable>your-download-dir</replaceable>/"
6415 INHERIT += "own-mirrors"
6416 BB_NO_NETWORK = "1"
6417 </literallayout>
6418 The <filename>SOURCE_MIRROR_URL</filename> and
6419 <filename>own-mirror</filename> class set up the system
6420 to use the downloads directory as your "own mirror".
6421 Using the <filename>BB_NO_NETWORK</filename>
6422 variable makes sure that BitBake's fetching process
6423 in step 3 stays local, which means files from
6424 your "own-mirror" are used.
6425 </para></listitem>
6426 <listitem><para>
6427 <emphasis>Start With a Clean Build:</emphasis>
6428 You can start with a clean build by removing the
6429 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
6430 directory or using a new
6431 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
6432 </para></listitem>
6433 <listitem><para>
6434 <emphasis>Build Your Target:</emphasis>
6435 Use BitBake to build your target:
6436 <literallayout class='monospaced'>
6437 $ bitbake <replaceable>target</replaceable>
6438 </literallayout>
6439 The build completes using the known local "snapshot" of
6440 source files from your mirror.
6441 The resulting tarballs for your "snapshot" of source
6442 files are in the downloads directory.
6443 <note>
6444 <para>The offline build does not work if recipes
6445 attempt to find the latest version of software
6446 by setting
6447 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
6448 to
6449 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink><filename>}</filename>:
6450 <literallayout class='monospaced'>
6451 SRCREV = "${AUTOREV}"
6452 </literallayout>
6453 When a recipe sets
6454 <filename>SRCREV</filename> to
6455 <filename>${AUTOREV}</filename>, the build system
6456 accesses the network in an attempt to determine the
6457 latest version of software from the SCM.
6458 Typically, recipes that use
6459 <filename>AUTOREV</filename> are custom or
6460 modified recipes.
6461 Recipes that reside in public repositories
6462 usually do not use <filename>AUTOREV</filename>.
6463 </para>
6464
6465 <para>If you do have recipes that use
6466 <filename>AUTOREV</filename>, you can take steps to
6467 still use the recipes in an offline build.
6468 Do the following:
6469 <orderedlist>
6470 <listitem><para>
6471 Use a configuration generated by
6472 enabling
6473 <link linkend='maintaining-build-output-quality'>build history</link>.
6474 </para></listitem>
6475 <listitem><para>
6476 Use the
6477 <filename>buildhistory-collect-srcrevs</filename>
6478 command to collect the stored
6479 <filename>SRCREV</filename> values from
6480 the build's history.
6481 For more information on collecting these
6482 values, see the
6483 "<link linkend='build-history-package-information'>Build History Package Information</link>"
6484 section.
6485 </para></listitem>
6486 <listitem><para>
6487 Once you have the correct source
6488 revisions, you can modify those recipes
6489 to to set <filename>SRCREV</filename>
6490 to specific versions of the software.
6491 </para></listitem>
6492 </orderedlist>
6493 </para>
6494 </note>
6495 </para></listitem>
6496 </orderedlist>
6497 </para>
6498 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006499 </section>
6500
Brad Bishop316dfdd2018-06-25 12:45:53 -04006501 <section id='speeding-up-a-build'>
6502 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006503
6504 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006505 Build time can be an issue.
6506 By default, the build system uses simple controls to try and maximize
6507 build efficiency.
6508 In general, the default settings for all the following variables
6509 result in the most efficient build times when dealing with single
6510 socket systems (i.e. a single CPU).
6511 If you have multiple CPUs, you might try increasing the default
6512 values to gain more speed.
6513 See the descriptions in the glossary for each variable for more
6514 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006515 <itemizedlist>
6516 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006517 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6518 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006519 </para></listitem>
6520 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006521 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6522 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006523 </para></listitem>
6524 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006525 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6526 Extra options passed to the <filename>make</filename> command
6527 during the
6528 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6529 task in order to specify parallel compilation on the
6530 local build host.
6531 </para></listitem>
6532 <listitem><para>
6533 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6534 Extra options passed to the <filename>make</filename> command
6535 during the
6536 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6537 task in order to specify parallel installation on the
6538 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006539 </para></listitem>
6540 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006541 As mentioned, these variables all scale to the number of processor
6542 cores available on the build system.
6543 For single socket systems, this auto-scaling ensures that the build
6544 system fundamentally takes advantage of potential parallel operations
6545 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006546 </para>
6547
6548 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006549 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006550 <itemizedlist>
6551 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006552 File system type:
6553 The file system type that the build is being performed on can
6554 also influence performance.
6555 Using <filename>ext4</filename> is recommended as compared
6556 to <filename>ext2</filename> and <filename>ext3</filename>
6557 due to <filename>ext4</filename> improved features
6558 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006559 </para></listitem>
6560 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006561 Disabling the updating of access time using
6562 <filename>noatime</filename>:
6563 The <filename>noatime</filename> mount option prevents the
6564 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006565 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006566 <listitem><para>
6567 Setting a longer commit:
6568 Using the "commit=" mount option increases the interval
6569 in seconds between disk cache writes.
6570 Changing this interval from the five second default to
6571 something longer increases the risk of data loss but decreases
6572 the need to write to the disk, thus increasing the build
6573 performance.
6574 </para></listitem>
6575 <listitem><para>
6576 Choosing the packaging backend:
6577 Of the available packaging backends, IPK is the fastest.
6578 Additionally, selecting a singular packaging backend also
6579 helps.
6580 </para></listitem>
6581 <listitem><para>
6582 Using <filename>tmpfs</filename> for
6583 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6584 as a temporary file system:
6585 While this can help speed up the build, the benefits are
6586 limited due to the compiler using
6587 <filename>-pipe</filename>.
6588 The build system goes to some lengths to avoid
6589 <filename>sync()</filename> calls into the
6590 file system on the principle that if there was a significant
6591 failure, the
6592 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6593 contents could easily be rebuilt.
6594 </para></listitem>
6595 <listitem><para>
6596 Inheriting the
6597 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6598 class:
6599 Inheriting this class has shown to speed up builds due to
6600 significantly lower amounts of data stored in the data
6601 cache as well as on disk.
6602 Inheriting this class also makes cleanup of
6603 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6604 faster, at the expense of being easily able to dive into the
6605 source code.
6606 File system maintainers have recommended that the fastest way
6607 to clean up large numbers of files is to reformat partitions
6608 rather than delete files due to the linear nature of
6609 partitions.
6610 This, of course, assumes you structure the disk partitions and
6611 file systems in a way that this is practical.
6612 </para></listitem>
6613 </itemizedlist>
6614 Aside from the previous list, you should keep some trade offs in
6615 mind that can help you speed up the build:
6616 <itemizedlist>
6617 <listitem><para>
6618 Remove items from
6619 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6620 that you might not need.
6621 </para></listitem>
6622 <listitem><para>
6623 Exclude debug symbols and other debug information:
6624 If you do not need these symbols and other debug information,
6625 disabling the <filename>*-dbg</filename> package generation
6626 can speed up the build.
6627 You can disable this generation by setting the
6628 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6629 variable to "1".
6630 </para></listitem>
6631 <listitem><para>
6632 Disable static library generation for recipes derived from
6633 <filename>autoconf</filename> or <filename>libtool</filename>:
6634 Following is an example showing how to disable static
6635 libraries and still provide an override to handle exceptions:
6636 <literallayout class='monospaced'>
6637 STATICLIBCONF = "--disable-static"
6638 STATICLIBCONF_sqlite3-native = ""
6639 EXTRA_OECONF += "${STATICLIBCONF}"
6640 </literallayout>
6641 <note><title>Notes</title>
6642 <itemizedlist>
6643 <listitem><para>
6644 Some recipes need static libraries in order to work
6645 correctly (e.g. <filename>pseudo-native</filename>
6646 needs <filename>sqlite3-native</filename>).
6647 Overrides, as in the previous example, account for
6648 these kinds of exceptions.
6649 </para></listitem>
6650 <listitem><para>
6651 Some packages have packaging code that assumes the
6652 presence of the static libraries.
6653 If so, you might need to exclude them as well.
6654 </para></listitem>
6655 </itemizedlist>
6656 </note>
6657 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006658 </itemizedlist>
6659 </para>
6660 </section>
6661
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006662 <section id="platdev-working-with-libraries">
6663 <title>Working With Libraries</title>
6664
6665 <para>
6666 Libraries are an integral part of your system.
6667 This section describes some common practices you might find
6668 helpful when working with libraries to build your system:
6669 <itemizedlist>
6670 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6671 </para></listitem>
6672 <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>
6673 </para></listitem>
6674 <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>
6675 </para></listitem>
6676 </itemizedlist>
6677 </para>
6678
6679 <section id='including-static-library-files'>
6680 <title>Including Static Library Files</title>
6681
6682 <para>
6683 If you are building a library and the library offers static linking, you can control
6684 which static library files (<filename>*.a</filename> files) get included in the
6685 built library.
6686 </para>
6687
6688 <para>
6689 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6690 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6691 variables in the
6692 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6693 by the <filename>do_install</filename> task are packaged.
6694 By default, the <filename>PACKAGES</filename> variable includes
6695 <filename>${PN}-staticdev</filename>, which represents all static library files.
6696 <note>
6697 Some previously released versions of the Yocto Project
6698 defined the static library files through
6699 <filename>${PN}-dev</filename>.
6700 </note>
6701 Following is part of the BitBake configuration file, where
6702 you can see how the static library files are defined:
6703 <literallayout class='monospaced'>
6704 PACKAGE_BEFORE_PN ?= ""
6705 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6706 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6707 FILES = ""
6708
6709 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6710 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6711 ${base_bindir}/* ${base_sbindir}/* \
6712 ${base_libdir}/*${SOLIBS} \
6713 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6714 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6715 ${datadir}/pixmaps ${datadir}/applications \
6716 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6717 ${libdir}/bonobo/servers"
6718
6719 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6720
6721 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6722 ${datadir}/gnome/help"
6723 SECTION_${PN}-doc = "doc"
6724
6725 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6726 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6727 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6728 ${datadir}/aclocal ${base_libdir}/*.o \
6729 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6730 SECTION_${PN}-dev = "devel"
6731 ALLOW_EMPTY_${PN}-dev = "1"
6732 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6733
6734 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6735 SECTION_${PN}-staticdev = "devel"
6736 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6737 </literallayout>
6738 </para>
6739 </section>
6740
6741 <section id="combining-multiple-versions-library-files-into-one-image">
6742 <title>Combining Multiple Versions of Library Files into One Image</title>
6743
6744 <para>
6745 The build system offers the ability to build libraries with different
6746 target optimizations or architecture formats and combine these together
6747 into one system image.
6748 You can link different binaries in the image
6749 against the different libraries as needed for specific use cases.
6750 This feature is called "Multilib."
6751 </para>
6752
6753 <para>
6754 An example would be where you have most of a system compiled in 32-bit
6755 mode using 32-bit libraries, but you have something large, like a database
6756 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6757 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6758 </para>
6759
6760 <para>
6761 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6762 the approach the build system uses facilitates different target optimizations.
6763 You could compile some binaries to use one set of libraries and other binaries
6764 to use a different set of libraries.
6765 The libraries could differ in architecture, compiler options, or other
6766 optimizations.
6767 </para>
6768
6769 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006770 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006771 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006772 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006773 <itemizedlist>
6774 <listitem><para><filename>conf/multilib-example.conf</filename>
6775 configuration file</para></listitem>
6776 <listitem><para><filename>conf/multilib-example2.conf</filename>
6777 configuration file</para></listitem>
6778 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6779 recipe</para></listitem>
6780 </itemizedlist>
6781 </para>
6782
6783 <section id='preparing-to-use-multilib'>
6784 <title>Preparing to Use Multilib</title>
6785
6786 <para>
6787 User-specific requirements drive the Multilib feature.
6788 Consequently, there is no one "out-of-the-box" configuration that likely
6789 exists to meet your needs.
6790 </para>
6791
6792 <para>
6793 In order to enable Multilib, you first need to ensure your recipe is
6794 extended to support multiple libraries.
6795 Many standard recipes are already extended and support multiple libraries.
6796 You can check in the <filename>meta/conf/multilib.conf</filename>
6797 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006798 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006799 done using the
6800 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6801 variable.
6802 Eventually, all recipes will be covered and this list will
6803 not be needed.
6804 </para>
6805
6806 <para>
6807 For the most part, the Multilib class extension works automatically to
6808 extend the package name from <filename>${PN}</filename> to
6809 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6810 is the particular multilib (e.g. "lib32-" or "lib64-").
6811 Standard variables such as
6812 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6813 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6814 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6815 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6816 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6817 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6818 are automatically extended by the system.
6819 If you are extending any manual code in the recipe, you can use the
6820 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6821 correctly.
6822 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6823 </para>
6824 </section>
6825
6826 <section id='using-multilib'>
6827 <title>Using Multilib</title>
6828
6829 <para>
6830 After you have set up the recipes, you need to define the actual
6831 combination of multiple libraries you want to build.
6832 You accomplish this through your <filename>local.conf</filename>
6833 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006834 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006835 An example configuration would be as follows:
6836 <literallayout class='monospaced'>
6837 MACHINE = "qemux86-64"
6838 require conf/multilib.conf
6839 MULTILIBS = "multilib:lib32"
6840 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006841 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006842 </literallayout>
6843 This example enables an
6844 additional library named <filename>lib32</filename> alongside the
6845 normal target packages.
6846 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6847 For information on this particular tuning, see
6848 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6849 </para>
6850
6851 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006852 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006853 in all the images, which illustrates one method of including a
6854 multiple library dependency.
6855 You can use a normal image build to include this dependency,
6856 for example:
6857 <literallayout class='monospaced'>
6858 $ bitbake core-image-sato
6859 </literallayout>
6860 You can also build Multilib packages specifically with a command like this:
6861 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006862 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006863 </literallayout>
6864 </para>
6865 </section>
6866
6867 <section id='additional-implementation-details'>
6868 <title>Additional Implementation Details</title>
6869
6870 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006871 Generic implementation details as well as details that are
6872 specific to package management systems exist.
6873 Following are implementation details that exist regardless
6874 of the package management system:
6875 <itemizedlist>
6876 <listitem><para>The typical convention used for the
6877 class extension code as used by
6878 Multilib assumes that all package names specified
6879 in
6880 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6881 that contain <filename>${PN}</filename> have
6882 <filename>${PN}</filename> at the start of the name.
6883 When that convention is not followed and
6884 <filename>${PN}</filename> appears at
6885 the middle or the end of a name, problems occur.
6886 </para></listitem>
6887 <listitem><para>The
6888 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6889 value under Multilib will be extended to
6890 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6891 (e.g. "-pokymllib32" for a "lib32" Multilib with
6892 Poky).
6893 The reason for this slightly unwieldy contraction
6894 is that any "-" characters in the vendor
6895 string presently break Autoconf's
6896 <filename>config.sub</filename>, and
6897 other separators are problematic for different
6898 reasons.
6899 </para></listitem>
6900 </itemizedlist>
6901 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006902
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006903 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006904 For the RPM Package Management System, the following implementation details
6905 exist:
6906 <itemizedlist>
6907 <listitem><para>A unique architecture is defined for the Multilib packages,
6908 along with creating a unique deploy folder under
6909 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006910 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006911 For example, consider <filename>lib32</filename> in a
6912 <filename>qemux86-64</filename> image.
6913 The possible architectures in the system are "all", "qemux86_64",
6914 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6915 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6916 <filename>${PN}</filename> during RPM packaging.
6917 The naming for a normal RPM package and a Multilib RPM package in a
6918 <filename>qemux86-64</filename> system resolves to something similar to
6919 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6920 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6921 </para></listitem>
6922 <listitem><para>When installing a Multilib image, the RPM backend first
6923 installs the base image and then installs the Multilib libraries.
6924 </para></listitem>
6925 <listitem><para>The build system relies on RPM to resolve the identical files in the
6926 two (or more) Multilib packages.</para></listitem>
6927 </itemizedlist>
6928 </para>
6929
6930 <para>
6931 For the IPK Package Management System, the following implementation details exist:
6932 <itemizedlist>
6933 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6934 <filename>${PN}</filename> during IPK packaging.
6935 The naming for a normal RPM package and a Multilib IPK package in a
6936 <filename>qemux86-64</filename> system resolves to something like
6937 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6938 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6939 </para></listitem>
6940 <listitem><para>The IPK deploy folder is not modified with
6941 <filename>${MLPREFIX}</filename> because packages with and without
6942 the Multilib feature can exist in the same folder due to the
6943 <filename>${PN}</filename> differences.</para></listitem>
6944 <listitem><para>IPK defines a sanity check for Multilib installation
6945 using certain rules for file comparison, overridden, etc.
6946 </para></listitem>
6947 </itemizedlist>
6948 </para>
6949 </section>
6950 </section>
6951
6952 <section id='installing-multiple-versions-of-the-same-library'>
6953 <title>Installing Multiple Versions of the Same Library</title>
6954
6955 <para>
6956 Situations can exist where you need to install and use
6957 multiple versions of the same library on the same system
6958 at the same time.
6959 These situations almost always exist when a library API
6960 changes and you have multiple pieces of software that
6961 depend on the separate versions of the library.
6962 To accommodate these situations, you can install multiple
6963 versions of the same library in parallel on the same system.
6964 </para>
6965
6966 <para>
6967 The process is straightforward as long as the libraries use
6968 proper versioning.
6969 With properly versioned libraries, all you need to do to
6970 individually specify the libraries is create separate,
6971 appropriately named recipes where the
6972 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6973 name includes a portion that differentiates each library version
6974 (e.g.the major part of the version number).
6975 Thus, instead of having a single recipe that loads one version
6976 of a library (e.g. <filename>clutter</filename>), you provide
6977 multiple recipes that result in different versions
6978 of the libraries you want.
6979 As an example, the following two recipes would allow the
6980 two separate versions of the <filename>clutter</filename>
6981 library to co-exist on the same system:
6982 <literallayout class='monospaced'>
6983 clutter-1.6_1.6.20.bb
6984 clutter-1.8_1.8.4.bb
6985 </literallayout>
6986 Additionally, if you have other recipes that depend on a given
6987 library, you need to use the
6988 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
6989 variable to create the dependency.
6990 Continuing with the same example, if you want to have a recipe
6991 depend on the 1.8 version of the <filename>clutter</filename>
6992 library, use the following in your recipe:
6993 <literallayout class='monospaced'>
6994 DEPENDS = "clutter-1.8"
6995 </literallayout>
6996 </para>
6997 </section>
6998 </section>
6999
Brad Bishop316dfdd2018-06-25 12:45:53 -04007000 <section id='using-x32-psabi'>
7001 <title>Using x32 psABI</title>
7002
7003 <para>
7004 x32 processor-specific Application Binary Interface
7005 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
7006 is a native 32-bit processor-specific ABI for
7007 <trademark class='registered'>Intel</trademark> 64 (x86-64)
7008 architectures.
7009 An ABI defines the calling conventions between functions in a
7010 processing environment.
7011 The interface determines what registers are used and what the
7012 sizes are for various C data types.
7013 </para>
7014
7015 <para>
7016 Some processing environments prefer using 32-bit applications even
7017 when running on Intel 64-bit platforms.
7018 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
7019 64-bit platforms.
7020 The i386 psABI does not provide efficient use and access of the
7021 Intel 64-bit processor resources, leaving the system underutilized.
7022 Now consider the x86_64 psABI.
7023 This ABI is newer and uses 64-bits for data sizes and program
7024 pointers.
7025 The extra bits increase the footprint size of the programs,
7026 libraries, and also increases the memory and file system size
7027 requirements.
7028 Executing under the x32 psABI enables user programs to utilize CPU
7029 and system resources more efficiently while keeping the memory
7030 footprint of the applications low.
7031 Extra bits are used for registers but not for addressing mechanisms.
7032 </para>
7033
7034 <para>
7035 The Yocto Project supports the final specifications of x32 psABI
7036 as follows:
7037 <itemizedlist>
7038 <listitem><para>
7039 You can create packages and images in x32 psABI format on
7040 x86_64 architecture targets.
7041 </para></listitem>
7042 <listitem><para>
7043 You can successfully build recipes with the x32 toolchain.
7044 </para></listitem>
7045 <listitem><para>
7046 You can create and boot
7047 <filename>core-image-minimal</filename> and
7048 <filename>core-image-sato</filename> images.
7049 </para></listitem>
7050 <listitem><para>
7051 RPM Package Manager (RPM) support exists for x32 binaries.
7052 </para></listitem>
7053 <listitem><para>
7054 Support for large images exists.
7055 </para></listitem>
7056 </itemizedlist>
7057 </para>
7058
7059 <para>
7060 To use the x32 psABI, you need to edit your
7061 <filename>conf/local.conf</filename> configuration file as
7062 follows:
7063 <literallayout class='monospaced'>
7064 MACHINE = "qemux86-64"
7065 DEFAULTTUNE = "x86-64-x32"
Brad Bishop19323692019-04-05 15:28:33 -04007066 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
7067 or 'INVALID')) or 'lib'}"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007068 </literallayout>
7069 Once you have set up your configuration file, use BitBake to
7070 build an image that supports the x32 psABI.
7071 Here is an example:
7072 <literallayout class='monospaced'>
7073 $ bitbake core-image-sato
7074 </literallayout>
7075 </para>
7076 </section>
7077
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007078 <section id='enabling-gobject-introspection-support'>
7079 <title>Enabling GObject Introspection Support</title>
7080
7081 <para>
7082 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
7083 is the standard mechanism for accessing GObject-based software
7084 from runtime environments.
7085 GObject is a feature of the GLib library that provides an object
7086 framework for the GNOME desktop and related software.
7087 GObject Introspection adds information to GObject that allows
7088 objects created within it to be represented across different
7089 programming languages.
7090 If you want to construct GStreamer pipelines using Python, or
7091 control UPnP infrastructure using Javascript and GUPnP,
7092 GObject introspection is the only way to do it.
7093 </para>
7094
7095 <para>
7096 This section describes the Yocto Project support for generating
7097 and packaging GObject introspection data.
7098 GObject introspection data is a description of the
7099 API provided by libraries built on top of GLib framework,
7100 and, in particular, that framework's GObject mechanism.
7101 GObject Introspection Repository (GIR) files go to
7102 <filename>-dev</filename> packages,
7103 <filename>typelib</filename> files go to main packages as they
7104 are packaged together with libraries that are introspected.
7105 </para>
7106
7107 <para>
7108 The data is generated when building such a library, by linking
7109 the library with a small executable binary that asks the library
7110 to describe itself, and then executing the binary and
7111 processing its output.
7112 </para>
7113
7114 <para>
7115 Generating this data in a cross-compilation environment
7116 is difficult because the library is produced for the target
7117 architecture, but its code needs to be executed on the build host.
7118 This problem is solved with the OpenEmbedded build system by
7119 running the code through QEMU, which allows precisely that.
7120 Unfortunately, QEMU does not always work perfectly as mentioned
7121 in the xxx section.
7122 </para>
7123
7124 <section id='enabling-the-generation-of-introspection-data'>
7125 <title>Enabling the Generation of Introspection Data</title>
7126
7127 <para>
7128 Enabling the generation of introspection data (GIR files)
7129 in your library package involves the following:
7130 <orderedlist>
7131 <listitem><para>
7132 Inherit the
7133 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
7134 class.
7135 </para></listitem>
7136 <listitem><para>
7137 Make sure introspection is not disabled anywhere in
7138 the recipe or from anything the recipe includes.
7139 Also, make sure that "gobject-introspection-data" is
7140 not in
7141 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7142 and that "qemu-usermode" is not in
7143 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7144 If either of these conditions exist, nothing will
7145 happen.
7146 </para></listitem>
7147 <listitem><para>
7148 Try to build the recipe.
7149 If you encounter build errors that look like
7150 something is unable to find
7151 <filename>.so</filename> libraries, check where these
7152 libraries are located in the source tree and add
7153 the following to the recipe:
7154 <literallayout class='monospaced'>
7155 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
7156 </literallayout>
7157 <note>
7158 See recipes in the <filename>oe-core</filename>
7159 repository that use that
7160 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
7161 as an example.
7162 </note>
7163 </para></listitem>
7164 <listitem><para>
7165 Look for any other errors, which probably mean that
7166 introspection support in a package is not entirely
7167 standard, and thus breaks down in a cross-compilation
7168 environment.
7169 For such cases, custom-made fixes are needed.
7170 A good place to ask and receive help in these cases
7171 is the
7172 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7173 </para></listitem>
7174 </orderedlist>
7175 <note>
7176 Using a library that no longer builds against the latest
7177 Yocto Project release and prints introspection related
7178 errors is a good candidate for the previous procedure.
7179 </note>
7180 </para>
7181 </section>
7182
7183 <section id='disabling-the-generation-of-introspection-data'>
7184 <title>Disabling the Generation of Introspection Data</title>
7185
7186 <para>
7187 You might find that you do not want to generate
7188 introspection data.
7189 Or, perhaps QEMU does not work on your build host and
7190 target architecture combination.
7191 If so, you can use either of the following methods to
7192 disable GIR file generations:
7193 <itemizedlist>
7194 <listitem><para>
7195 Add the following to your distro configuration:
7196 <literallayout class='monospaced'>
7197 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7198 </literallayout>
7199 Adding this statement disables generating
7200 introspection data using QEMU but will still enable
7201 building introspection tools and libraries
7202 (i.e. building them does not require the use of QEMU).
7203 </para></listitem>
7204 <listitem><para>
7205 Add the following to your machine configuration:
7206 <literallayout class='monospaced'>
7207 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7208 </literallayout>
7209 Adding this statement disables the use of QEMU
7210 when building packages for your machine.
7211 Currently, this feature is used only by introspection
7212 recipes and has the same effect as the previously
7213 described option.
7214 <note>
7215 Future releases of the Yocto Project might have
7216 other features affected by this option.
7217 </note>
7218 </para></listitem>
7219 </itemizedlist>
7220 If you disable introspection data, you can still
7221 obtain it through other means such as copying the data
7222 from a suitable sysroot, or by generating it on the
7223 target hardware.
7224 The OpenEmbedded build system does not currently
7225 provide specific support for these techniques.
7226 </para>
7227 </section>
7228
7229 <section id='testing-that-introspection-works-in-an-image'>
7230 <title>Testing that Introspection Works in an Image</title>
7231
7232 <para>
7233 Use the following procedure to test if generating
7234 introspection data is working in an image:
7235 <orderedlist>
7236 <listitem><para>
7237 Make sure that "gobject-introspection-data" is not in
7238 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7239 and that "qemu-usermode" is not in
7240 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7241 </para></listitem>
7242 <listitem><para>
7243 Build <filename>core-image-sato</filename>.
7244 </para></listitem>
7245 <listitem><para>
7246 Launch a Terminal and then start Python in the
7247 terminal.
7248 </para></listitem>
7249 <listitem><para>
7250 Enter the following in the terminal:
7251 <literallayout class='monospaced'>
7252 >>> from gi.repository import GLib
7253 >>> GLib.get_host_name()
7254 </literallayout>
7255 </para></listitem>
7256 <listitem><para>
7257 For something a little more advanced, enter the
7258 following:
7259 <literallayout class='monospaced'>
7260 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7261 </literallayout>
7262 </para></listitem>
7263 </orderedlist>
7264 </para>
7265 </section>
7266
7267 <section id='known-issues'>
7268 <title>Known Issues</title>
7269
7270 <para>
7271 The following know issues exist for
7272 GObject Introspection Support:
7273 <itemizedlist>
7274 <listitem><para>
7275 <filename>qemu-ppc64</filename> immediately crashes.
7276 Consequently, you cannot build introspection data on
7277 that architecture.
7278 </para></listitem>
7279 <listitem><para>
7280 x32 is not supported by QEMU.
7281 Consequently, introspection data is disabled.
7282 </para></listitem>
7283 <listitem><para>
7284 musl causes transient GLib binaries to crash on
7285 assertion failures.
7286 Consequently, generating introspection data is
7287 disabled.
7288 </para></listitem>
7289 <listitem><para>
7290 Because QEMU is not able to run the binaries correctly,
7291 introspection is disabled for some specific packages
7292 under specific architectures (e.g.
7293 <filename>gcr</filename>,
7294 <filename>libsecret</filename>, and
7295 <filename>webkit</filename>).
7296 </para></listitem>
7297 <listitem><para>
7298 QEMU usermode might not work properly when running
7299 64-bit binaries under 32-bit host machines.
7300 In particular, "qemumips64" is known to not work under
7301 i686.
7302 </para></listitem>
7303 </itemizedlist>
7304 </para>
7305 </section>
7306 </section>
7307
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007308 <section id='dev-optionally-using-an-external-toolchain'>
7309 <title>Optionally Using an External Toolchain</title>
7310
7311 <para>
7312 You might want to use an external toolchain as part of your
7313 development.
7314 If this is the case, the fundamental steps you need to accomplish
7315 are as follows:
7316 <itemizedlist>
7317 <listitem><para>
7318 Understand where the installed toolchain resides.
7319 For cases where you need to build the external toolchain,
7320 you would need to take separate steps to build and install
7321 the toolchain.
7322 </para></listitem>
7323 <listitem><para>
7324 Make sure you add the layer that contains the toolchain to
7325 your <filename>bblayers.conf</filename> file through the
7326 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7327 variable.
7328 </para></listitem>
7329 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007330 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007331 variable in your <filename>local.conf</filename> file
7332 to the location in which you installed the toolchain.
7333 </para></listitem>
7334 </itemizedlist>
7335 A good example of an external toolchain used with the Yocto Project
7336 is <trademark class='registered'>Mentor Graphics</trademark>
7337 Sourcery G++ Toolchain.
7338 You can see information on how to use that particular layer in the
7339 <filename>README</filename> file at
7340 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7341 You can find further information by reading about the
7342 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7343 variable in the Yocto Project Reference Manual's variable glossary.
7344 </para>
7345 </section>
7346
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007347 <section id='creating-partitioned-images-using-wic'>
7348 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007349
7350 <para>
7351 Creating an image for a particular hardware target using the
7352 OpenEmbedded build system does not necessarily mean you can boot
7353 that image as is on your device.
7354 Physical devices accept and boot images in various ways depending
7355 on the specifics of the device.
7356 Usually, information about the hardware can tell you what image
7357 format the device requires.
7358 Should your device require multiple partitions on an SD card, flash,
7359 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007360 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007361 </para>
7362
7363 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007364 The <filename>wic</filename> command generates partitioned
7365 images from existing OpenEmbedded build artifacts.
7366 Image generation is driven by partitioning commands
7367 contained in an Openembedded kickstart file
7368 (<filename>.wks</filename>) specified either directly on
7369 the command line or as one of a selection of canned
7370 kickstart files as shown with the
7371 <filename>wic list images</filename> command in the
7372 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7373 section.
7374 When you apply the command to a given set of build
7375 artifacts, the result is an image or set of images that
7376 can be directly written onto media and used on a particular
7377 system.
7378 <note>
7379 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007380 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007381 Chapter in the Yocto Project Reference Manual.
7382 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007383 </para>
7384
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007385 <para>
7386 The <filename>wic</filename> command and the infrastructure
7387 it is based on is by definition incomplete.
7388 The purpose of the command is to allow the generation of
7389 customized images, and as such, was designed to be
7390 completely extensible through a plug-in interface.
7391 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007392 "<link linkend='wic-using-the-wic-plug-ins-interface'>Using the Wic Plug-Ins Interface</link>"
7393 section for information on these plug-ins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007394 </para>
7395
7396 <para>
7397 This section provides some background information on Wic,
7398 describes what you need to have in
7399 place to run the tool, provides instruction on how to use
Brad Bishop316dfdd2018-06-25 12:45:53 -04007400 the Wic utility, provides information on using the Wic plug-ins
7401 interface, and provides several examples that show how to use
7402 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007403 </para>
7404
7405 <section id='wic-background'>
7406 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007407
7408 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007409 This section provides some background on the Wic utility.
7410 While none of this information is required to use
7411 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007412 <itemizedlist>
7413 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007414 The name "Wic" is derived from OpenEmbedded
7415 Image Creator (oeic).
7416 The "oe" diphthong in "oeic" was promoted to the
7417 letter "w", because "oeic" is both difficult to
7418 remember and to pronounce.
7419 </para></listitem>
7420 <listitem><para>
7421 Wic is loosely based on the
7422 Meego Image Creator (<filename>mic</filename>)
7423 framework.
7424 The Wic implementation has been
7425 heavily modified to make direct use of OpenEmbedded
7426 build artifacts instead of package installation and
7427 configuration, which are already incorporated within
7428 the OpenEmbedded artifacts.
7429 </para></listitem>
7430 <listitem><para>
7431 Wic is a completely independent
7432 standalone utility that initially provides
7433 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007434 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007435 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007436 class.
7437 The difference between Wic and those examples is
7438 that with Wic the functionality of those scripts is
7439 implemented by a general-purpose partitioning language,
7440 which is based on Redhat kickstart syntax.
7441 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007442 </itemizedlist>
7443 </para>
7444 </section>
7445
7446 <section id='wic-requirements'>
7447 <title>Requirements</title>
7448
7449 <para>
7450 In order to use the Wic utility with the OpenEmbedded Build
7451 system, your system needs to meet the following
7452 requirements:
7453 <itemizedlist>
7454 <listitem><para>
7455 The Linux distribution on your development host must
7456 support the Yocto Project.
7457 See the
7458 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7459 section in the Yocto Project Reference Manual for
7460 the list of distributions that support the
7461 Yocto Project.
7462 </para></listitem>
7463 <listitem><para>
7464 The standard system utilities, such as
7465 <filename>cp</filename>, must be installed on your
7466 development host system.
7467 </para></listitem>
7468 <listitem><para>
7469 You must have sourced the build environment
7470 setup script (i.e.
7471 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7472 found in the
7473 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7474 </para></listitem>
7475 <listitem><para>
7476 You need to have the build artifacts already
7477 available, which typically means that you must
7478 have already created an image using the
7479 Openembedded build system (e.g.
7480 <filename>core-image-minimal</filename>).
7481 While it might seem redundant to generate an image
7482 in order to create an image using
7483 Wic, the current version of
7484 Wic requires the artifacts
7485 in the form generated by the OpenEmbedded build
7486 system.
7487 </para></listitem>
7488 <listitem><para>
7489 You must build several native tools, which are
7490 built to run on the build system:
7491 <literallayout class='monospaced'>
7492 $ bitbake parted-native dosfstools-native mtools-native
7493 </literallayout>
7494 </para></listitem>
7495 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007496 Include "wic" as part of the
7497 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7498 variable.
7499 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007500 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007501 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007502 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007503 as part of the
7504 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7505 variable
7506 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007507 </itemizedlist>
7508 </para>
7509 </section>
7510
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007511 <section id='wic-getting-help'>
7512 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007513
7514 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007515 You can get general help for the <filename>wic</filename>
7516 command by entering the <filename>wic</filename> command
7517 by itself or by entering the command with a help argument
7518 as follows:
7519 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007520 $ wic -h
7521 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007522 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007523 </literallayout>
7524 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007525
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007526 <para>
7527 Currently, Wic supports seven commands:
7528 <filename>cp</filename>, <filename>create</filename>,
7529 <filename>help</filename>, <filename>list</filename>,
7530 <filename>ls</filename>, <filename>rm</filename>, and
7531 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007532 You can get help for all these commands except "help" by
7533 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007534 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007535 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007536 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007537 For example, the following command returns help for the
7538 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007539 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007540 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007541 </literallayout>
7542 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007543
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007544 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007545 Wic supports help for three topics:
7546 <filename>overview</filename>,
7547 <filename>plugins</filename>, and
7548 <filename>kickstart</filename>.
7549 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007550 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007551 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007552 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007553 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007554 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007555 $ wic help overview
7556 </literallayout>
7557 </para>
7558
7559 <para>
7560 One additional level of help exists for Wic.
7561 You can get help on individual images through the
7562 <filename>list</filename> command.
7563 You can use the <filename>list</filename> command to return the
7564 available Wic images as follows:
7565 <literallayout class='monospaced'>
7566 $ wic list images
7567 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7568 genericx86 Create an EFI disk image for genericx86*
7569 beaglebone-yocto Create SD card image for Beaglebone
7570 edgerouter Create SD card image for Edgerouter
7571 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7572 directdisk-gpt Create a 'pcbios' direct disk image
7573 mkefidisk Create an EFI disk image
7574 directdisk Create a 'pcbios' direct disk image
7575 systemd-bootdisk Create an EFI disk image with systemd-boot
7576 mkhybridiso Create a hybrid ISO image
7577 sdimage-bootpart Create SD card image with a boot partition
7578 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7579 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7580 </literallayout>
7581 Once you know the list of available Wic images, you can use
7582 <filename>help</filename> with the command to get help on a
7583 particular image.
7584 For example, the following command returns help on the
7585 "beaglebone-yocto" image:
7586 <literallayout class='monospaced'>
7587 $ wic list beaglebone-yocto help
7588
7589
7590 Creates a partitioned SD card image for Beaglebone.
7591 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007592 </literallayout>
7593 </para>
7594 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007595
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007596 <section id='operational-modes'>
7597 <title>Operational Modes</title>
7598
7599 <para>
7600 You can use Wic in two different
7601 modes, depending on how much control you need for
7602 specifying the Openembedded build artifacts that are
7603 used for creating the image: Raw and Cooked:
7604 <itemizedlist>
7605 <listitem><para>
7606 <emphasis>Raw Mode:</emphasis>
7607 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007608 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007609 </para></listitem>
7610 <listitem><para>
7611 <emphasis>Cooked Mode:</emphasis>
7612 The current
7613 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7614 setting and image name are used to automatically
7615 locate and provide the build artifacts.
7616 You just supply a kickstart file and the name
7617 of the image from which to use artifacts.
7618 </para></listitem>
7619 </itemizedlist>
7620 </para>
7621
7622 <para>
7623 Regardless of the mode you use, you need to have the build
7624 artifacts ready and available.
7625 </para>
7626
7627 <section id='raw-mode'>
7628 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007629
7630 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007631 Running Wic in raw mode allows you to specify all the
7632 partitions through the <filename>wic</filename>
7633 command line.
7634 The primary use for raw mode is if you have built
7635 your kernel outside of the Yocto Project
7636 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7637 In other words, you can point to arbitrary kernel,
7638 root filesystem locations, and so forth.
7639 Contrast this behavior with cooked mode where Wic
7640 looks in the Build Directory (e.g.
7641 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007642 </para>
7643
7644 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007645 The general form of the
7646 <filename>wic</filename> command in raw mode is:
7647 <literallayout class='monospaced'>
7648 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007649
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007650 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007651
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007652 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007653 An OpenEmbedded kickstart file. You can provide
7654 your own custom file or use a file from a set of
7655 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007656
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007657 optional arguments:
7658 -h, --help show this help message and exit
7659 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7660 name of directory to create image in
7661 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7662 name of the image to use the artifacts from e.g. core-
7663 image-sato
7664 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7665 path to the /rootfs dir to use as the .wks rootfs
7666 source
7667 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7668 path to the dir containing the boot artifacts (e.g.
7669 /EFI or /syslinux dirs) to use as the .wks bootimg
7670 source
7671 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7672 path to the dir containing the kernel to use in the
7673 .wks bootimg
7674 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7675 path to the native sysroot containing the tools to use
7676 to build the image
7677 -s, --skip-build-check
7678 skip the build check
7679 -f, --build-rootfs build rootfs
7680 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7681 compress image with specified compressor
7682 -m, --bmap generate .bmap
7683 --no-fstab-update Do not change fstab file.
7684 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7685 directory with &lt;image&gt;.env files that store bitbake
7686 variables
7687 -D, --debug output debug information
7688 </literallayout>
7689 <note>
7690 You do not need root privileges to run
7691 Wic.
7692 In fact, you should not run as root when using the
7693 utility.
7694 </note>
7695 </para>
7696 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007697
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007698 <section id='cooked-mode'>
7699 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007700
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007701 <para>
7702 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007703 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007704 In other words, you do not have to specify kernel or
7705 root filesystem locations as part of the command.
7706 All you need to provide is a kickstart file and the
7707 name of the image from which to use artifacts by using
7708 the "-e" option.
7709 Wic looks in the Build Directory (e.g.
7710 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7711 for artifacts.
7712 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007713
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007714 <para>
7715 The general form of the <filename>wic</filename>
7716 command using Cooked Mode is as follows:
7717 <literallayout class='monospaced'>
7718 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007719
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007720 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007721
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007722 <replaceable>wks_file</replaceable>:
7723 An OpenEmbedded kickstart file. You can provide
7724 your own custom file or use a file from a set of
7725 existing files provided with the Yocto Project
7726 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007727
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007728 required argument:
7729 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7730 name of the image to use the artifacts from e.g. core-
7731 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007732 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007733 </para>
7734 </section>
7735 </section>
7736
7737 <section id='using-a-provided-kickstart-file'>
7738 <title>Using an Existing Kickstart File</title>
7739
7740 <para>
7741 If you do not want to create your own kickstart file, you
7742 can use an existing file provided by the Wic installation.
7743 As shipped, kickstart files can be found in the
7744 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007745 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007746 in the following two locations:
7747 <literallayout class='monospaced'>
7748 poky/meta-yocto-bsp/wic
7749 poky/scripts/lib/wic/canned-wks
7750 </literallayout>
7751 Use the following command to list the available kickstart
7752 files:
7753 <literallayout class='monospaced'>
7754 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007755 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7756 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007757 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007758 edgerouter Create SD card image for Edgerouter
7759 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7760 directdisk-gpt Create a 'pcbios' direct disk image
7761 mkefidisk Create an EFI disk image
7762 directdisk Create a 'pcbios' direct disk image
7763 systemd-bootdisk Create an EFI disk image with systemd-boot
7764 mkhybridiso Create a hybrid ISO image
7765 sdimage-bootpart Create SD card image with a boot partition
7766 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7767 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7768 </literallayout>
7769 When you use an existing file, you do not have to use the
7770 <filename>.wks</filename> extension.
7771 Here is an example in Raw Mode that uses the
7772 <filename>directdisk</filename> file:
7773 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007774 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7775 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007776 </literallayout>
7777 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007778
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007779 <para>
7780 Here are the actual partition language commands
7781 used in the <filename>genericx86.wks</filename> file to
7782 generate an image:
7783 <literallayout class='monospaced'>
7784 # short-description: Create an EFI disk image for genericx86*
7785 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7786 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7787 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007788 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7789
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007790 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7791 </literallayout>
7792 </para>
7793 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007794
Brad Bishop316dfdd2018-06-25 12:45:53 -04007795 <section id='wic-using-the-wic-plug-ins-interface'>
7796 <title>Using the Wic Plug-Ins Interface</title>
7797
7798 <para>
7799 You can extend and specialize Wic functionality by using
7800 Wic plug-ins.
7801 This section explains the Wic plug-in interface.
7802 <note>
7803 Wic plug-ins consist of "source" and "imager" plug-ins.
7804 Imager plug-ins are beyond the scope of this section.
7805 </note>
7806 </para>
7807
7808 <para>
7809 Source plug-ins provide a mechanism to customize partition
7810 content during the Wic image generation process.
7811 You can use source plug-ins to map values that you specify
7812 using <filename>--source</filename> commands in kickstart
7813 files (i.e. <filename>*.wks</filename>) to a plug-in
7814 implementation used to populate a given partition.
7815 <note>
7816 If you use plug-ins that have build-time dependencies
7817 (e.g. native tools, bootloaders, and so forth)
7818 when building a Wic image, you need to specify those
7819 dependencies using the
7820 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7821 variable.
7822 </note>
7823 </para>
7824
7825 <para>
7826 Source plug-ins are subclasses defined in plug-in files.
7827 As shipped, the Yocto Project provides several plug-in
7828 files.
7829 You can see the source plug-in files that ship with the
7830 Yocto Project
7831 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
7832 Each of these plug-in files contains source plug-ins that
7833 are designed to populate a specific Wic image partition.
7834 </para>
7835
7836 <para>
7837 Source plug-ins are subclasses of the
7838 <filename>SourcePlugin</filename> class, which is
7839 defined in the
7840 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7841 file.
7842 For example, the <filename>BootimgEFIPlugin</filename>
7843 source plug-in found in the
7844 <filename>bootimg-efi.py</filename> file is a subclass of
7845 the <filename>SourcePlugin</filename> class, which is found
7846 in the <filename>pluginbase.py</filename> file.
7847 </para>
7848
7849 <para>
7850 You can also implement source plug-ins in a layer outside
7851 of the Source Repositories (external layer).
7852 To do so, be sure that your plug-in files are located in
7853 a directory whose path is
7854 <filename>scripts/lib/wic/plugins/source/</filename>
7855 within your external layer.
7856 When the plug-in files are located there, the source
7857 plug-ins they contain are made available to Wic.
7858 </para>
7859
7860 <para>
7861 When the Wic implementation needs to invoke a
7862 partition-specific implementation, it looks for the plug-in
7863 with the same name as the <filename>--source</filename>
7864 parameter used in the kickstart file given to that
7865 partition.
7866 For example, if the partition is set up using the following
7867 command in a kickstart file:
7868 <literallayout class='monospaced'>
7869 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7870 </literallayout>
7871 The methods defined as class members of the matching
7872 source plug-in (i.e. <filename>bootimg-pcbios</filename>)
7873 in the <filename>bootimg-pcbios.py</filename> plug-in file
7874 are used.
7875 </para>
7876
7877 <para>
7878 To be more concrete, here is the corresponding plug-in
7879 definition from the <filename>bootimg-pcbios.py</filename>
7880 file for the previous command along with an example
7881 method called by the Wic implementation when it needs to
7882 prepare a partition using an implementation-specific
7883 function:
7884 <literallayout class='monospaced'>
7885 .
7886 .
7887 .
7888 class BootimgPcbiosPlugin(SourcePlugin):
7889 """
7890 Create MBR boot partition and install syslinux on it.
7891 """
7892
7893 name = 'bootimg-pcbios'
7894 .
7895 .
7896 .
7897 @classmethod
7898 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7899 oe_builddir, bootimg_dir, kernel_dir,
7900 rootfs_dir, native_sysroot):
7901 """
7902 Called to do the actual content population for a partition i.e. it
7903 'prepares' the partition to be incorporated into the image.
7904 In this case, prepare content for legacy bios boot partition.
7905 """
7906 .
7907 .
7908 .
7909 </literallayout>
7910 If a subclass (plug-in) itself does not implement a
7911 particular function, Wic locates and uses the default
7912 version in the superclass.
7913 It is for this reason that all source plug-ins are derived
7914 from the <filename>SourcePlugin</filename> class.
7915 </para>
7916
7917 <para>
7918 The <filename>SourcePlugin</filename> class defined in
7919 the <filename>pluginbase.py</filename> file defines
7920 a set of methods that source plug-ins can implement or
7921 override.
7922 Any plug-ins (subclass of
7923 <filename>SourcePlugin</filename>) that do not implement
7924 a particular method inherit the implementation of the
7925 method from the <filename>SourcePlugin</filename> class.
7926 For more information, see the
7927 <filename>SourcePlugin</filename> class in the
7928 <filename>pluginbase.py</filename> file for details:
7929 </para>
7930
7931 <para>
7932 The following list describes the methods implemented in the
7933 <filename>SourcePlugin</filename> class:
7934 <itemizedlist>
7935 <listitem><para>
7936 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7937 Called to populate a partition with actual content.
7938 In other words, the method prepares the final
7939 partition image that is incorporated into the
7940 disk image.
7941 </para></listitem>
7942 <listitem><para>
7943 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7944 Called before
7945 <filename>do_prepare_partition()</filename> to
7946 create custom configuration files for a partition
7947 (e.g. syslinux or grub configuration files).
7948 </para></listitem>
7949 <listitem><para>
7950 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7951 Called after all partitions have been prepared and
7952 assembled into a disk image.
7953 This method provides a hook to allow finalization
7954 of a disk image (e.g. writing an MBR).
7955 </para></listitem>
7956 <listitem><para>
7957 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7958 Special content-staging hook called before
7959 <filename>do_prepare_partition()</filename>.
7960 This method is normally empty.</para>
7961
7962 <para>Typically, a partition just uses the passed-in
7963 parameters (e.g. the unmodified value of
7964 <filename>bootimg_dir</filename>).
7965 However, in some cases, things might need to be
7966 more tailored.
7967 As an example, certain files might additionally
7968 need to be taken from
7969 <filename>bootimg_dir + /boot</filename>.
7970 This hook allows those files to be staged in a
7971 customized fashion.
7972 <note>
7973 <filename>get_bitbake_var()</filename>
7974 allows you to access non-standard variables
7975 that you might want to use for this
7976 behavior.
7977 </note>
7978 </para></listitem>
7979 </itemizedlist>
7980 </para>
7981
7982 <para>
7983 You can extend the source plug-in mechanism.
7984 To add more hooks, create more source plug-in methods
7985 within <filename>SourcePlugin</filename> and the
7986 corresponding derived subclasses.
7987 The code that calls the plug-in methods uses the
7988 <filename>plugin.get_source_plugin_methods()</filename>
7989 function to find the method or methods needed by the call.
7990 Retrieval of those methods is accomplished by filling up
7991 a dict with keys that contain the method names of interest.
7992 On success, these will be filled in with the actual
7993 methods.
7994 See the Wic implementation for examples and details.
7995 </para>
7996 </section>
7997
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007998 <section id='wic-usage-examples'>
7999 <title>Examples</title>
8000
8001 <para>
8002 This section provides several examples that show how to use
8003 the Wic utility.
8004 All the examples assume the list of requirements in the
8005 "<link linkend='wic-requirements'>Requirements</link>"
8006 section have been met.
8007 The examples assume the previously generated image is
8008 <filename>core-image-minimal</filename>.
8009 </para>
8010
8011 <section id='generate-an-image-using-a-provided-kickstart-file'>
8012 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008013
8014 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008015 This example runs in Cooked Mode and uses the
8016 <filename>mkefidisk</filename> kickstart file:
8017 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008018 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008019 INFO: Building wic-tools...
8020 .
8021 .
8022 .
8023 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008024 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008025
8026 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008027 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8028 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8029 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8030 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008031
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008032 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008033 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008034 </literallayout>
8035 The previous example shows the easiest way to create
8036 an image by running in cooked mode and supplying
8037 a kickstart file and the "-e" option to point to the
8038 existing build artifacts.
8039 Your <filename>local.conf</filename> file needs to have
8040 the
8041 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8042 variable set to the machine you are using, which is
8043 "qemux86" in this example.
8044 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008045
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008046 <para>
8047 Once the image builds, the output provides image
8048 location, artifact use, and kickstart file information.
8049 <note>
8050 You should always verify the details provided in the
8051 output to make sure that the image was indeed
8052 created exactly as expected.
8053 </note>
8054 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008055
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008056 <para>
8057 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008058 image from the Build Directory onto a USB stick, or
8059 whatever media for which you built your image, and boot
8060 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008061 You can write the image by using
8062 <filename>bmaptool</filename> or
8063 <filename>dd</filename>:
8064 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008065 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008066 </literallayout>
8067 or
8068 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008069 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008070 </literallayout>
8071 <note>
8072 For more information on how to use the
8073 <filename>bmaptool</filename> to flash a device
8074 with an image, see the
8075 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
8076 section.
8077 </note>
8078 </para>
8079 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008080
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008081 <section id='using-a-modified-kickstart-file'>
8082 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008083
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008084 <para>
8085 Because partitioned image creation is driven by the
8086 kickstart file, it is easy to affect image creation by
8087 changing the parameters in the file.
8088 This next example demonstrates that through modification
8089 of the <filename>directdisk-gpt</filename> kickstart
8090 file.
8091 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008092
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008093 <para>
8094 As mentioned earlier, you can use the command
8095 <filename>wic list images</filename> to show the list
8096 of existing kickstart files.
8097 The directory in which the
8098 <filename>directdisk-gpt.wks</filename> file resides is
8099 <filename>scripts/lib/image/canned-wks/</filename>,
8100 which is located in the
8101 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
8102 (e.g. <filename>poky</filename>).
8103 Because available files reside in this directory,
8104 you can create and add your own custom files to the
8105 directory.
8106 Subsequent use of the
8107 <filename>wic list images</filename> command would then
8108 include your kickstart files.
8109 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008110
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008111 <para>
8112 In this example, the existing
8113 <filename>directdisk-gpt</filename> file already does
8114 most of what is needed.
8115 However, for the hardware in this example, the image
8116 will need to boot from <filename>sdb</filename> instead
8117 of <filename>sda</filename>, which is what the
8118 <filename>directdisk-gpt</filename> kickstart file
8119 uses.
8120 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008121
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008122 <para>
8123 The example begins by making a copy of the
8124 <filename>directdisk-gpt.wks</filename> file in the
8125 <filename>scripts/lib/image/canned-wks</filename>
8126 directory and then by changing the lines that specify
8127 the target disk from which to boot.
8128 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008129 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
8130 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008131 </literallayout>
8132 Next, the example modifies the
8133 <filename>directdisksdb-gpt.wks</filename> file and
8134 changes all instances of
8135 "<filename>--ondisk sda</filename>" to
8136 "<filename>--ondisk sdb</filename>".
8137 The example changes the following two lines and leaves
8138 the remaining lines untouched:
8139 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008140 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008141 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
8142 </literallayout>
8143 Once the lines are changed, the example generates the
8144 <filename>directdisksdb-gpt</filename> image.
8145 The command points the process at the
8146 <filename>core-image-minimal</filename> artifacts for
8147 the Next Unit of Computing (nuc)
8148 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8149 the <filename>local.conf</filename>.
8150 <literallayout class='monospaced'>
8151 $ wic create directdisksdb-gpt -e core-image-minimal
8152 INFO: Building wic-tools...
8153 .
8154 .
8155 .
8156 Initialising tasks: 100% |#######################################| Time: 0:00:01
8157 NOTE: Executing SetScene Tasks
8158 NOTE: Executing RunQueue Tasks
8159 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
8160 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008161
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008162 INFO: The new image(s) can be found here:
8163 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008164
8165 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008166 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8167 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8168 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8169 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008170
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008171 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008172 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008173 </literallayout>
8174 Continuing with the example, you can now directly
8175 <filename>dd</filename> the image to a USB stick, or
8176 whatever media for which you built your image,
8177 and boot the resulting media:
8178 <literallayout class='monospaced'>
8179 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8180 140966+0 records in
8181 140966+0 records out
8182 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8183 $ sudo eject /dev/sdb
8184 </literallayout>
8185 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008186 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008187
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008188 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8189 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008190
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008191 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008192 This next example manually specifies each build artifact
8193 (runs in Raw Mode) and uses a modified kickstart file.
8194 The example also uses the <filename>-o</filename> option
8195 to cause Wic to create the output
8196 somewhere other than the default output directory,
8197 which is the current directory:
8198 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008199 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8200 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8201 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8202 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8203 --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008204
8205 INFO: Creating image(s)...
8206
8207 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008208 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008209
8210 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008211 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8212 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8213 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8214 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008215
8216 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008217 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008218 </literallayout>
8219 For this example,
8220 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8221 did not have to be specified in the
8222 <filename>local.conf</filename> file since the
8223 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008224 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008225 </section>
8226
8227 <section id='using-wic-to-manipulate-an-image'>
8228 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008229
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008230 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008231 Wic image manipulation allows you to shorten turnaround
8232 time during image development.
8233 For example, you can use Wic to delete the kernel partition
8234 of a Wic image and then insert a newly built kernel.
8235 This saves you time from having to rebuild the entire image
8236 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008237 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008238 In order to use Wic to manipulate a Wic image as in
8239 this example, your development machine must have the
8240 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008241 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008242 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008243
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008244 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008245 The following example examines the contents of the Wic
8246 image, deletes the existing kernel, and then inserts a
8247 new kernel:
8248 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008249 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008250 <emphasis>List the Partitions:</emphasis>
8251 Use the <filename>wic ls</filename> command to list
8252 all the partitions in the Wic image:
8253 <literallayout class='monospaced'>
8254 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8255 Num Start End Size Fstype
8256 1 1048576 25041919 23993344 fat16
8257 2 25165824 72157183 46991360 ext4
8258 </literallayout>
8259 The previous output shows two partitions in the
8260 <filename>core-image-minimal-qemux86.wic</filename>
8261 image.
8262 </para></listitem>
8263 <listitem><para>
8264 <emphasis>Examine a Particular Partition:</emphasis>
8265 Use the <filename>wic ls</filename> command again
8266 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008267 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008268 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008269 You can get command usage on any Wic command
8270 using the following form:
8271 <literallayout class='monospaced'>
8272 $ wic help <replaceable>command</replaceable>
8273 </literallayout>
8274 For example, the following command shows you
8275 the various ways to use the
8276 <filename>wic ls</filename> command:
8277 <literallayout class='monospaced'>
8278 $ wic help ls
8279 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008280 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008281 The following command shows what is in Partition
8282 one:
8283 <literallayout class='monospaced'>
8284 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8285 Volume in drive : is boot
8286 Volume Serial Number is E894-1809
8287 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008288
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008289 libcom32 c32 186500 2017-10-09 16:06
8290 libutil c32 24148 2017-10-09 16:06
8291 syslinux cfg 220 2017-10-09 16:06
8292 vesamenu c32 27104 2017-10-09 16:06
8293 vmlinuz 6904608 2017-10-09 16:06
8294 5 files 7 142 580 bytes
8295 16 582 656 bytes free
8296 </literallayout>
8297 The previous output shows five files, with the
8298 <filename>vmlinuz</filename> being the kernel.
8299 <note>
8300 If you see the following error, you need to
8301 update or create a
8302 <filename>~/.mtoolsrc</filename> file and
8303 be sure to have the line “mtools_skip_check=1“
8304 in the file.
8305 Then, run the Wic command again:
8306 <literallayout class='monospaced'>
8307 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8308 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8309 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8310 </literallayout>
8311 </note>
8312 </para></listitem>
8313 <listitem><para>
8314 <emphasis>Remove the Old Kernel:</emphasis>
8315 Use the <filename>wic rm</filename> command to
8316 remove the <filename>vmlinuz</filename> file
8317 (kernel):
8318 <literallayout class='monospaced'>
8319 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8320 </literallayout>
8321 </para></listitem>
8322 <listitem><para>
8323 <emphasis>Add In the New Kernel:</emphasis>
8324 Use the <filename>wic cp</filename> command to
8325 add the updated kernel to the Wic image.
8326 Depending on how you built your kernel, it could
8327 be in different places.
8328 If you used <filename>devtool</filename> and
8329 an SDK to build your kernel, it resides in the
8330 <filename>tmp/work</filename> directory of the
8331 extensible SDK.
8332 If you used <filename>make</filename> to build the
8333 kernel, the kernel will be in the
8334 <filename>workspace/sources</filename> area.
8335 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008336
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008337 <para>The following example assumes
8338 <filename>devtool</filename> was used to build
8339 the kernel:
8340 <literallayout class='monospaced'>
8341 cp ~/poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \
8342 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8343 </literallayout>
8344 Once the new kernel is added back into the image,
8345 you can use the <filename>dd</filename>
8346 command or
8347 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8348 to flash your wic image onto an SD card
8349 or USB stick and test your target.
8350 <note>
8351 Using <filename>bmaptool</filename> is
8352 generally 10 to 20 times faster than using
8353 <filename>dd</filename>.
8354 </note>
8355 </para></listitem>
8356 </orderedlist>
8357 </para>
8358 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008359 </section>
8360 </section>
8361
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008362 <section id='flashing-images-using-bmaptool'>
8363 <title>Flashing Images Using <filename>bmaptool</filename></title>
8364
8365 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008366 A fast and easy way to flash an image to a bootable device
8367 is to use Bmaptool, which is integrated into the OpenEmbedded
8368 build system.
8369 Bmaptool is a generic tool that creates a file's block map (bmap)
8370 and then uses that map to copy the file.
8371 As compared to traditional tools such as dd or cp, Bmaptool
8372 can copy (or flash) large files like raw system image files
8373 much faster.
8374 <note><title>Notes</title>
8375 <itemizedlist>
8376 <listitem><para>
8377 If you are using Ubuntu or Debian distributions, you
8378 can install the <filename>bmap-tools</filename> package
8379 using the following command and then use the tool
8380 without specifying <filename>PATH</filename> even from
8381 the root account:
8382 <literallayout class='monospaced'>
8383 $ sudo apt-get install bmap-tools
8384 </literallayout>
8385 </para></listitem>
8386 <listitem><para>
8387 If you are unable to install the
8388 <filename>bmap-tools</filename> package, you will
8389 need to build Bmaptool before using it.
8390 Use the following command:
8391 <literallayout class='monospaced'>
8392 $ bitbake bmap-tools-native
8393 </literallayout>
8394 </para></listitem>
8395 </itemizedlist>
8396 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008397 </para>
8398
8399 <para>
8400 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008401 Realize that while this example uses a Wic image, you can use
8402 Bmaptool to flash any type of image.
8403 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008404 <orderedlist>
8405 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008406 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8407 You need to have the following set in your
8408 <filename>local.conf</filename> file before building
8409 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008410 <literallayout class='monospaced'>
8411 IMAGE_FSTYPES += "wic wic.bmap"
8412 </literallayout>
8413 </para></listitem>
8414 <listitem><para>
8415 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008416 Either have your image ready (pre-built with the
8417 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8418 setting previously mentioned) or take the step to build
8419 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008420 <literallayout class='monospaced'>
8421 $ bitbake <replaceable>image</replaceable>
8422 </literallayout>
8423 </para></listitem>
8424 <listitem><para>
8425 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008426 Flash the device with the image by using Bmaptool
8427 depending on your particular setup.
8428 The following commands assume the image resides in the
8429 Build Directory's <filename>deploy/images/</filename>
8430 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008431 <itemizedlist>
8432 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008433 If you have write access to the media, use this
8434 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008435 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008436 $ oe-run-native bmap-tools-native bmaptool copy <replaceable>build-directory</replaceable>/tmp/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.wic /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008437 </literallayout>
8438 </para></listitem>
8439 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008440 If you do not have write access to the media, set
8441 your permissions first and then use the same
8442 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008443 <literallayout class='monospaced'>
8444 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008445 $ oe-run-native bmap-tools-native bmaptool copy <replaceable>build-directory</replaceable>/tmp/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.wic /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008446 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008447 </para></listitem>
8448 </itemizedlist>
8449 </para></listitem>
8450 </orderedlist>
8451 </para>
8452
8453 <para>
8454 For help on the <filename>bmaptool</filename> command, use the
8455 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008456 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008457 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008458 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008459 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008460 </section>
8461
8462 <section id='making-images-more-secure'>
8463 <title>Making Images More Secure</title>
8464
8465 <para>
8466 Security is of increasing concern for embedded devices.
8467 Consider the issues and problems discussed in just this
8468 sampling of work found across the Internet:
8469 <itemizedlist>
8470 <listitem><para><emphasis>
8471 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8472 by Bruce Schneier
8473 </para></listitem>
8474 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008475 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008476 by Carna Botnet</para></listitem>
8477 <listitem><para><emphasis>
8478 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8479 by Jake Edge
8480 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008481 </itemizedlist>
8482 </para>
8483
8484 <para>
8485 When securing your image is of concern, there are steps, tools,
8486 and variables that you can consider to help you reach the
8487 security goals you need for your particular device.
8488 Not all situations are identical when it comes to making an
8489 image secure.
8490 Consequently, this section provides some guidance and suggestions
8491 for consideration when you want to make your image more secure.
8492 <note>
8493 Because the security requirements and risks are
8494 different for every type of device, this section cannot
8495 provide a complete reference on securing your custom OS.
8496 It is strongly recommended that you also consult other sources
8497 of information on embedded Linux system hardening and on
8498 security.
8499 </note>
8500 </para>
8501
8502 <section id='general-considerations'>
8503 <title>General Considerations</title>
8504
8505 <para>
8506 General considerations exist that help you create more
8507 secure images.
8508 You should consider the following suggestions to help
8509 make your device more secure:
8510 <itemizedlist>
8511 <listitem><para>
8512 Scan additional code you are adding to the system
8513 (e.g. application code) by using static analysis
8514 tools.
8515 Look for buffer overflows and other potential
8516 security problems.
8517 </para></listitem>
8518 <listitem><para>
8519 Pay particular attention to the security for
8520 any web-based administration interface.
8521 </para>
8522 <para>Web interfaces typically need to perform
8523 administrative functions and tend to need to run with
8524 elevated privileges.
8525 Thus, the consequences resulting from the interface's
8526 security becoming compromised can be serious.
8527 Look for common web vulnerabilities such as
8528 cross-site-scripting (XSS), unvalidated inputs,
8529 and so forth.</para>
8530 <para>As with system passwords, the default credentials
8531 for accessing a web-based interface should not be the
8532 same across all devices.
8533 This is particularly true if the interface is enabled
8534 by default as it can be assumed that many end-users
8535 will not change the credentials.
8536 </para></listitem>
8537 <listitem><para>
8538 Ensure you can update the software on the device to
8539 mitigate vulnerabilities discovered in the future.
8540 This consideration especially applies when your
8541 device is network-enabled.
8542 </para></listitem>
8543 <listitem><para>
8544 Ensure you remove or disable debugging functionality
8545 before producing the final image.
8546 For information on how to do this, see the
8547 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8548 section.
8549 </para></listitem>
8550 <listitem><para>
8551 Ensure you have no network services listening that
8552 are not needed.
8553 </para></listitem>
8554 <listitem><para>
8555 Remove any software from the image that is not needed.
8556 </para></listitem>
8557 <listitem><para>
8558 Enable hardware support for secure boot functionality
8559 when your device supports this functionality.
8560 </para></listitem>
8561 </itemizedlist>
8562 </para>
8563 </section>
8564
8565 <section id='security-flags'>
8566 <title>Security Flags</title>
8567
8568 <para>
8569 The Yocto Project has security flags that you can enable that
8570 help make your build output more secure.
8571 The security flags are in the
8572 <filename>meta/conf/distro/include/security_flags.inc</filename>
8573 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008574 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008575 (e.g. <filename>poky</filename>).
8576 <note>
8577 Depending on the recipe, certain security flags are enabled
8578 and disabled by default.
8579 </note>
8580 </para>
8581
8582 <para>
8583<!--
8584 The GCC/LD flags in <filename>security_flags.inc</filename>
8585 enable more secure code generation.
8586 By including the <filename>security_flags.inc</filename>
8587 file, you enable flags to the compiler and linker that cause
8588 them to generate more secure code.
8589 <note>
8590 The GCC/LD flags are enabled by default in the
8591 <filename>poky-lsb</filename> distribution.
8592 </note>
8593-->
8594 Use the following line in your
8595 <filename>local.conf</filename> file or in your custom
8596 distribution configuration file to enable the security
8597 compiler and linker flags for your build:
8598 <literallayout class='monospaced'>
8599 require conf/distro/include/security_flags.inc
8600 </literallayout>
8601 </para>
8602 </section>
8603
8604 <section id='considerations-specific-to-the-openembedded-build-system'>
8605 <title>Considerations Specific to the OpenEmbedded Build System</title>
8606
8607 <para>
8608 You can take some steps that are specific to the
8609 OpenEmbedded build system to make your images more secure:
8610 <itemizedlist>
8611 <listitem><para>
8612 Ensure "debug-tweaks" is not one of your selected
8613 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8614 When creating a new project, the default is to provide you
8615 with an initial <filename>local.conf</filename> file that
8616 enables this feature using the
8617 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8618 <literallayout class='monospaced'>
8619 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8620 </literallayout>
8621 To disable that feature, simply comment out that line in your
8622 <filename>local.conf</filename> file, or
8623 make sure <filename>IMAGE_FEATURES</filename> does not contain
8624 "debug-tweaks" before producing your final image.
8625 Among other things, leaving this in place sets the
8626 root password as blank, which makes logging in for
8627 debugging or inspection easy during
8628 development but also means anyone can easily log in
8629 during production.
8630 </para></listitem>
8631 <listitem><para>
8632 It is possible to set a root password for the image
8633 and also to set passwords for any extra users you might
8634 add (e.g. administrative or service type users).
8635 When you set up passwords for multiple images or
8636 users, you should not duplicate passwords.
8637 </para>
8638 <para>
8639 To set up passwords, use the
8640 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8641 class, which is the preferred method.
8642 For an example on how to set up both root and user
8643 passwords, see the
8644 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8645 section.
8646 <note>
8647 When adding extra user accounts or setting a
8648 root password, be cautious about setting the
8649 same password on every device.
8650 If you do this, and the password you have set
8651 is exposed, then every device is now potentially
8652 compromised.
8653 If you need this access but want to ensure
8654 security, consider setting a different,
8655 random password for each device.
8656 Typically, you do this as a separate step after
8657 you deploy the image onto the device.
8658 </note>
8659 </para></listitem>
8660 <listitem><para>
8661 Consider enabling a Mandatory Access Control (MAC)
8662 framework such as SMACK or SELinux and tuning it
8663 appropriately for your device's usage.
8664 You can find more information in the
8665 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8666 layer.
8667 </para></listitem>
8668 </itemizedlist>
8669 </para>
8670
8671 <para>
8672 </para>
8673 </section>
8674
8675 <section id='tools-for-hardening-your-image'>
8676 <title>Tools for Hardening Your Image</title>
8677
8678 <para>
8679 The Yocto Project provides tools for making your image
8680 more secure.
8681 You can find these tools in the
8682 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008683 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008684 </para>
8685 </section>
8686 </section>
8687
8688 <section id='creating-your-own-distribution'>
8689 <title>Creating Your Own Distribution</title>
8690
8691 <para>
8692 When you build an image using the Yocto Project and
8693 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008694 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8695 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008696 If you wish to gain more control over package alternative
8697 selections, compile-time options, and other low-level
8698 configurations, you can create your own distribution.
8699 </para>
8700
8701 <para>
8702 To create your own distribution, the basic steps consist of
8703 creating your own distribution layer, creating your own
8704 distribution configuration file, and then adding any needed
8705 code and Metadata to the layer.
8706 The following steps provide some more detail:
8707 <itemizedlist>
8708 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8709 Create your distribution layer so that you can keep your
8710 Metadata and code for the distribution separate.
8711 It is strongly recommended that you create and use your own
8712 layer for configuration and code.
8713 Using your own layer as compared to just placing
8714 configurations in a <filename>local.conf</filename>
8715 configuration file makes it easier to reproduce the same
8716 build configuration when using multiple build machines.
8717 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008718 "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008719 section for information on how to quickly set up a layer.
8720 </para></listitem>
8721 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8722 The distribution configuration file needs to be created in
8723 the <filename>conf/distro</filename> directory of your
8724 layer.
8725 You need to name it using your distribution name
8726 (e.g. <filename>mydistro.conf</filename>).
8727 <note>
8728 The
8729 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8730 variable in your
8731 <filename>local.conf</filename> file determines the
8732 name of your distribution.
8733 </note></para>
8734 <para>You can split out parts of your configuration file
8735 into include files and then "require" them from within
8736 your distribution configuration file.
8737 Be sure to place the include files in the
8738 <filename>conf/distro/include</filename> directory of
8739 your layer.
8740 A common example usage of include files would be to
8741 separate out the selection of desired version and revisions
8742 for individual recipes.
8743</para>
8744 <para>Your configuration file needs to set the following
8745 required variables:
8746 <literallayout class='monospaced'>
8747 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8748 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8749 </literallayout>
8750 These following variables are optional and you typically
8751 set them from the distribution configuration file:
8752 <literallayout class='monospaced'>
8753 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8754 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8755 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8756 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8757 </literallayout>
8758 <tip>
8759 If you want to base your distribution configuration file
8760 on the very basic configuration from OE-Core, you
8761 can use
8762 <filename>conf/distro/defaultsetup.conf</filename> as
8763 a reference and just include variables that differ
8764 as compared to <filename>defaultsetup.conf</filename>.
8765 Alternatively, you can create a distribution
8766 configuration file from scratch using the
8767 <filename>defaultsetup.conf</filename> file
8768 or configuration files from other distributions
8769 such as Poky or Angstrom as references.
8770 </tip></para></listitem>
8771 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8772 Be sure to define any other variables for which you want to
8773 create a default or enforce as part of the distribution
8774 configuration.
8775 You can include nearly any variable from the
8776 <filename>local.conf</filename> file.
8777 The variables you use are not limited to the list in the
8778 previous bulleted item.</para></listitem>
8779 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8780 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008781 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008782 set your
8783 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8784 variable to point to your distribution's configuration file.
8785 For example, if your distribution's configuration file is
8786 named <filename>mydistro.conf</filename>, then you point
8787 to it as follows:
8788 <literallayout class='monospaced'>
8789 DISTRO = "mydistro"
8790 </literallayout></para></listitem>
8791 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8792 Use your layer to hold other information needed for the
8793 distribution:
8794 <itemizedlist>
8795 <listitem><para>Add recipes for installing
8796 distro-specific configuration files that are not
8797 already installed by another recipe.
8798 If you have distro-specific configuration files
8799 that are included by an existing recipe, you should
8800 add an append file (<filename>.bbappend</filename>)
8801 for those.
8802 For general information and recommendations
8803 on how to add recipes to your layer, see the
8804 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8805 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008806 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008807 sections.</para></listitem>
8808 <listitem><para>Add any image recipes that are specific
8809 to your distribution.</para></listitem>
8810 <listitem><para>Add a <filename>psplash</filename>
8811 append file for a branded splash screen.
8812 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008813 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008814 section.</para></listitem>
8815 <listitem><para>Add any other append files to make
8816 custom changes that are specific to individual
8817 recipes.</para></listitem>
8818 </itemizedlist></para></listitem>
8819 </itemizedlist>
8820 </para>
8821 </section>
8822
8823 <section id='creating-a-custom-template-configuration-directory'>
8824 <title>Creating a Custom Template Configuration Directory</title>
8825
8826 <para>
8827 If you are producing your own customized version
8828 of the build system for use by other users, you might
8829 want to customize the message shown by the setup script or
8830 you might want to change the template configuration files (i.e.
8831 <filename>local.conf</filename> and
8832 <filename>bblayers.conf</filename>) that are created in
8833 a new build directory.
8834 </para>
8835
8836 <para>
8837 The OpenEmbedded build system uses the environment variable
8838 <filename>TEMPLATECONF</filename> to locate the directory
8839 from which it gathers configuration information that ultimately
8840 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008841 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008842 <filename>conf</filename> directory.
8843 By default, <filename>TEMPLATECONF</filename> is set as
8844 follows in the <filename>poky</filename> repository:
8845 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008846 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008847 </literallayout>
8848 This is the directory used by the build system to find templates
8849 from which to build some key configuration files.
8850 If you look at this directory, you will see the
8851 <filename>bblayers.conf.sample</filename>,
8852 <filename>local.conf.sample</filename>, and
8853 <filename>conf-notes.txt</filename> files.
8854 The build system uses these files to form the respective
8855 <filename>bblayers.conf</filename> file,
8856 <filename>local.conf</filename> file, and display the list of
8857 BitBake targets when running the setup script.
8858 </para>
8859
8860 <para>
8861 To override these default configuration files with
8862 configurations you want used within every new
8863 Build Directory, simply set the
8864 <filename>TEMPLATECONF</filename> variable to your directory.
8865 The <filename>TEMPLATECONF</filename> variable is set in the
8866 <filename>.templateconf</filename> file, which is in the
8867 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008868 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008869 folder (e.g. <filename>poky</filename>).
8870 Edit the <filename>.templateconf</filename> so that it can locate
8871 your directory.
8872 </para>
8873
8874 <para>
8875 Best practices dictate that you should keep your
8876 template configuration directory in your custom distribution layer.
8877 For example, suppose you have a layer named
8878 <filename>meta-mylayer</filename> located in your home directory
8879 and you want your template configuration directory named
8880 <filename>myconf</filename>.
8881 Changing the <filename>.templateconf</filename> as follows
8882 causes the OpenEmbedded build system to look in your directory
8883 and base its configuration files on the
8884 <filename>*.sample</filename> configuration files it finds.
8885 The final configuration files (i.e.
8886 <filename>local.conf</filename> and
8887 <filename>bblayers.conf</filename> ultimately still end up in
8888 your Build Directory, but they are based on your
8889 <filename>*.sample</filename> files.
8890 <literallayout class='monospaced'>
8891 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8892 </literallayout>
8893 </para>
8894
8895 <para>
8896 Aside from the <filename>*.sample</filename> configuration files,
8897 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008898 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008899 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008900 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008901 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8902 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008903 output.
8904 Customizing this <filename>conf-notes.txt</filename> file is a
8905 good way to make sure your list of custom targets appears
8906 as part of the script's output.
8907 </para>
8908
8909 <para>
8910 Here is the default list of targets displayed as a result of
8911 running either of the setup scripts:
8912 <literallayout class='monospaced'>
8913 You can now run 'bitbake &lt;target&gt;'
8914
8915 Common targets are:
8916 core-image-minimal
8917 core-image-sato
8918 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008919 meta-ide-support
8920 </literallayout>
8921 </para>
8922
8923 <para>
8924 Changing the listed common targets is as easy as editing your
8925 version of <filename>conf-notes.txt</filename> in your
8926 custom template configuration directory and making sure you
8927 have <filename>TEMPLATECONF</filename> set to your directory.
8928 </para>
8929 </section>
8930
Brad Bishop316dfdd2018-06-25 12:45:53 -04008931 <section id='dev-saving-memory-during-a-build'>
8932 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008933
8934 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008935 To help conserve disk space during builds, you can add the
8936 following statement to your project's
8937 <filename>local.conf</filename> configuration file found in the
8938 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8939 <literallayout class='monospaced'>
8940 INHERIT += "rm_work"
8941 </literallayout>
8942 Adding this statement deletes the work directory used for building
8943 a recipe once the recipe is built.
8944 For more information on "rm_work", see the
8945 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8946 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008947 </para>
8948 </section>
8949
8950 <section id='working-with-packages'>
8951 <title>Working with Packages</title>
8952
8953 <para>
8954 This section describes a few tasks that involve packages:
8955 <itemizedlist>
8956 <listitem><para>
8957 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8958 </para></listitem>
8959 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008960 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008961 </para></listitem>
8962 <listitem><para>
8963 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8964 </para></listitem>
8965 <listitem><para>
8966 <link linkend='using-runtime-package-management'>Using Runtime Package Management</link>
8967 </para></listitem>
8968 <listitem><para>
8969 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8970 </para></listitem>
8971 </itemizedlist>
8972 </para>
8973
8974 <section id='excluding-packages-from-an-image'>
8975 <title>Excluding Packages from an Image</title>
8976
8977 <para>
8978 You might find it necessary to prevent specific packages
8979 from being installed into an image.
8980 If so, you can use several variables to direct the build
8981 system to essentially ignore installing recommended packages
8982 or to not install a package at all.
8983 </para>
8984
8985 <para>
8986 The following list introduces variables you can use to
8987 prevent packages from being installed into your image.
8988 Each of these variables only works with IPK and RPM
8989 package types.
8990 Support for Debian packages does not exist.
8991 Also, you can use these variables from your
8992 <filename>local.conf</filename> file or attach them to a
8993 specific image recipe by using a recipe name override.
8994 For more detail on the variables, see the descriptions in the
8995 Yocto Project Reference Manual's glossary chapter.
8996 <itemizedlist>
8997 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
8998 Use this variable to specify "recommended-only"
8999 packages that you do not want installed.
9000 </para></listitem>
9001 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
9002 Use this variable to prevent all "recommended-only"
9003 packages from being installed.
9004 </para></listitem>
9005 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
9006 Use this variable to prevent specific packages from
9007 being installed regardless of whether they are
9008 "recommended-only" or not.
9009 You need to realize that the build process could
9010 fail with an error when you
9011 prevent the installation of a package whose presence
9012 is required by an installed package.
9013 </para></listitem>
9014 </itemizedlist>
9015 </para>
9016 </section>
9017
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009018 <section id='incrementing-a-binary-package-version'>
9019 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009020
9021 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009022 This section provides some background on how binary package
9023 versioning is accomplished and presents some of the services,
9024 variables, and terminology involved.
9025 </para>
9026
9027 <para>
9028 In order to understand binary package versioning, you need
9029 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009030 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009031 <listitem><para>
9032 Binary Package: The binary package that is eventually
9033 built and installed into an image.
9034 </para></listitem>
9035 <listitem><para>
9036 Binary Package Version: The binary package version
9037 is composed of two components - a version and a
9038 revision.
9039 <note>
9040 Technically, a third component, the "epoch" (i.e.
9041 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
9042 is involved but this discussion for the most part
9043 ignores <filename>PE</filename>.
9044 </note>
9045 The version and revision are taken from the
9046 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
9047 and
9048 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9049 variables, respectively.
9050 </para></listitem>
9051 <listitem><para>
9052 <filename>PV</filename>: The recipe version.
9053 <filename>PV</filename> represents the version of the
9054 software being packaged.
9055 Do not confuse <filename>PV</filename> with the
9056 binary package version.
9057 </para></listitem>
9058 <listitem><para>
9059 <filename>PR</filename>: The recipe revision.
9060 </para></listitem>
9061 <listitem><para>
9062 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
9063 The OpenEmbedded build system uses this string
9064 to help define the value of <filename>PV</filename>
9065 when the source code revision needs to be included
9066 in it.
9067 </para></listitem>
9068 <listitem><para>
9069 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
9070 A network-based service that helps automate keeping
9071 package feeds compatible with existing package
9072 manager applications such as RPM, APT, and OPKG.
9073 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009074 </itemizedlist>
9075 </para>
9076
9077 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009078 Whenever the binary package content changes, the binary package
9079 version must change.
9080 Changing the binary package version is accomplished by changing
9081 or "bumping" the <filename>PR</filename> and/or
9082 <filename>PV</filename> values.
9083 Increasing these values occurs one of two ways:
9084 <itemizedlist>
9085 <listitem><para>Automatically using a Package Revision
9086 Service (PR Service).
9087 </para></listitem>
9088 <listitem><para>Manually incrementing the
9089 <filename>PR</filename> and/or
9090 <filename>PV</filename> variables.
9091 </para></listitem>
9092 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009093 </para>
9094
9095 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009096 Given a primary challenge of any build system and its users
9097 is how to maintain a package feed that is compatible with
9098 existing package manager applications such as RPM, APT, and
9099 OPKG, using an automated system is much preferred over a
9100 manual system.
9101 In either system, the main requirement is that binary package
9102 version numbering increases in a linear fashion and that a
9103 number of version components exist that support that linear
9104 progression.
9105 For information on how to ensure package revisioning remains
9106 linear, see the
9107 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
9108 section.
9109 </para>
9110
9111 <para>
9112 The following three sections provide related information on the
9113 PR Service, the manual method for "bumping"
9114 <filename>PR</filename> and/or <filename>PV</filename>, and
9115 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009116 </para>
9117
9118 <section id='working-with-a-pr-service'>
9119 <title>Working With a PR Service</title>
9120
9121 <para>
9122 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009123 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009124 is error prone, inaccurate, and causes problems for people
9125 submitting recipes.
9126 Conversely, the PR Service automatically generates
9127 increasing numbers, particularly the revision field,
9128 which removes the human element.
9129 <note>
9130 For additional information on using a PR Service, you
9131 can see the
9132 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
9133 wiki page.
9134 </note>
9135 </para>
9136
9137 <para>
9138 The Yocto Project uses variables in order of
9139 decreasing priority to facilitate revision numbering (i.e.
9140 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
9141 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
9142 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9143 for epoch, version, and revision, respectively).
9144 The values are highly dependent on the policies and
9145 procedures of a given distribution and package feed.
9146 </para>
9147
9148 <para>
9149 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04009150 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009151 which are unique to a given build, the build system
9152 knows when to rebuild packages.
9153 All the inputs into a given task are represented by a
9154 signature, which can trigger a rebuild when different.
9155 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009156 <filename>PR</filename>, <filename>PV</filename>, and
9157 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009158 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009159 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009160 </para>
9161
9162 <para>
9163 The PR Service works with both
9164 <filename>OEBasic</filename> and
9165 <filename>OEBasicHash</filename> generators.
9166 The value of <filename>PR</filename> bumps when the
9167 checksum changes and the different generator mechanisms
9168 change signatures under different circumstances.
9169 </para>
9170
9171 <para>
9172 As implemented, the build system includes values from
9173 the PR Service into the <filename>PR</filename> field as
9174 an addition using the form "<filename>.x</filename>" so
9175 <filename>r0</filename> becomes <filename>r0.1</filename>,
9176 <filename>r0.2</filename> and so forth.
9177 This scheme allows existing <filename>PR</filename> values
9178 to be used for whatever reasons, which include manual
9179 <filename>PR</filename> bumps, should it be necessary.
9180 </para>
9181
9182 <para>
9183 By default, the PR Service is not enabled or running.
9184 Thus, the packages generated are just "self consistent".
9185 The build system adds and removes packages and
9186 there are no guarantees about upgrade paths but images
9187 will be consistent and correct with the latest changes.
9188 </para>
9189
9190 <para>
9191 The simplest form for a PR Service is for it to exist
9192 for a single host development system that builds the
9193 package feed (building system).
9194 For this scenario, you can enable a local PR Service by
9195 setting
9196 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9197 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009198 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009199 <literallayout class='monospaced'>
9200 PRSERV_HOST = "localhost:0"
9201 </literallayout>
9202 Once the service is started, packages will automatically
9203 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009204 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009205 </para>
9206
9207 <para>
9208 If you have a more complex setup where multiple host
9209 development systems work against a common, shared package
9210 feed, you have a single PR Service running and it is
9211 connected to each building system.
9212 For this scenario, you need to start the PR Service using
9213 the <filename>bitbake-prserv</filename> command:
9214 <literallayout class='monospaced'>
9215 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9216 </literallayout>
9217 In addition to hand-starting the service, you need to
9218 update the <filename>local.conf</filename> file of each
9219 building system as described earlier so each system
9220 points to the server and port.
9221 </para>
9222
9223 <para>
9224 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009225 some sanity checks to binary package versions, in
9226 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009227 To enable build history, add the following to each building
9228 system's <filename>local.conf</filename> file:
9229 <literallayout class='monospaced'>
9230 # It is recommended to activate "buildhistory" for testing the PR service
9231 INHERIT += "buildhistory"
9232 BUILDHISTORY_COMMIT = "1"
9233 </literallayout>
9234 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009235 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9236 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009237 </para>
9238
9239 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009240 <para>
9241 The OpenEmbedded build system does not maintain
9242 <filename>PR</filename> information as part of the
9243 shared state (sstate) packages.
9244 If you maintain an sstate feed, its expected that either
9245 all your building systems that contribute to the sstate
9246 feed use a shared PR Service, or you do not run a PR
9247 Service on any of your building systems.
9248 Having some systems use a PR Service while others do
9249 not leads to obvious problems.
9250 </para>
9251
9252 <para>
9253 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009254 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9255 section in the Yocto Project Overview and Concepts
9256 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009257 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009258 </note>
9259 </section>
9260
9261 <section id='manually-bumping-pr'>
9262 <title>Manually Bumping PR</title>
9263
9264 <para>
9265 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009266 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009267 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9268 variable.
9269 </para>
9270
9271 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009272 If a committed change results in changing the package
9273 output, then the value of the PR variable needs to be
9274 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009275 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009276 variable and set its initial value equal to "r0", which is
9277 the default.
9278 Even though the default value is "r0", the practice of
9279 adding it to a new recipe makes it harder to forget to bump
9280 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009281 </para>
9282
9283 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009284 If you are sharing a common <filename>.inc</filename> file
9285 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009286 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009287 variable to ensure that the recipes sharing the
9288 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009289 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009290 The <filename>.inc</filename> file must set
9291 <filename>INC_PR</filename> (initially to "r0"), and all
9292 recipes referring to it should set <filename>PR</filename>
9293 to "${INC_PR}.0" initially, incrementing the last number
9294 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009295 If the <filename>.inc</filename> file is changed then its
9296 <filename>INC_PR</filename> should be incremented.
9297 </para>
9298
9299 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009300 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009301 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9302 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009303 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009304 <filename>INC_PR</filename>).
9305 </para>
9306
9307 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009308 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009309 However, if for some reason <filename>PV</filename> changes
9310 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009311 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9312 variable (Package Epoch).
9313 The <filename>PE</filename> variable defaults to "0".
9314 </para>
9315
9316 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009317 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009318 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9319 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009320 These guidelines define how versions are compared and what
9321 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009322 </para>
9323 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009324
9325 <section id='automatically-incrementing-a-binary-package-revision-number'>
9326 <title>Automatically Incrementing a Package Version Number</title>
9327
9328 <para>
9329 When fetching a repository, BitBake uses the
9330 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9331 variable to determine the specific source code revision
9332 from which to build.
9333 You set the <filename>SRCREV</filename> variable to
9334 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9335 to cause the OpenEmbedded build system to automatically use the
9336 latest revision of the software:
9337 <literallayout class='monospaced'>
9338 SRCREV = "${AUTOREV}"
9339 </literallayout>
9340 </para>
9341
9342 <para>
9343 Furthermore, you need to reference <filename>SRCPV</filename>
9344 in <filename>PV</filename> in order to automatically update
9345 the version whenever the revision of the source code
9346 changes.
9347 Here is an example:
9348 <literallayout class='monospaced'>
9349 PV = "1.0+git${SRCPV}"
9350 </literallayout>
9351 The OpenEmbedded build system substitutes
9352 <filename>SRCPV</filename> with the following:
9353 <literallayout class='monospaced'>
9354 AUTOINC+<replaceable>source_code_revision</replaceable>
9355 </literallayout>
9356 The build system replaces the <filename>AUTOINC</filename> with
9357 a number.
9358 The number used depends on the state of the PR Service:
9359 <itemizedlist>
9360 <listitem><para>
9361 If PR Service is enabled, the build system increments
9362 the number, which is similar to the behavior of
9363 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9364 This behavior results in linearly increasing package
9365 versions, which is desirable.
9366 Here is an example:
9367 <literallayout class='monospaced'>
9368 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9369 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9370 </literallayout>
9371 </para></listitem>
9372 <listitem><para>
9373 If PR Service is not enabled, the build system
9374 replaces the <filename>AUTOINC</filename>
9375 placeholder with zero (i.e. "0").
9376 This results in changing the package version since
9377 the source revision is included.
9378 However, package versions are not increased linearly.
9379 Here is an example:
9380 <literallayout class='monospaced'>
9381 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9382 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9383 </literallayout>
9384 </para></listitem>
9385 </itemizedlist>
9386 </para>
9387
9388 <para>
9389 In summary, the OpenEmbedded build system does not track the
9390 history of binary package versions for this purpose.
9391 <filename>AUTOINC</filename>, in this case, is comparable to
9392 <filename>PR</filename>.
9393 If PR server is not enabled, <filename>AUTOINC</filename>
9394 in the package version is simply replaced by "0".
9395 If PR server is enabled, the build system keeps track of the
9396 package versions and bumps the number when the package
9397 revision changes.
9398 </para>
9399 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009400 </section>
9401
9402 <section id='handling-optional-module-packaging'>
9403 <title>Handling Optional Module Packaging</title>
9404
9405 <para>
9406 Many pieces of software split functionality into optional
9407 modules (or plug-ins) and the plug-ins that are built
9408 might depend on configuration options.
9409 To avoid having to duplicate the logic that determines what
9410 modules are available in your recipe or to avoid having
9411 to package each module by hand, the OpenEmbedded build system
9412 provides functionality to handle module packaging dynamically.
9413 </para>
9414
9415 <para>
9416 To handle optional module packaging, you need to do two things:
9417 <itemizedlist>
9418 <listitem><para>Ensure the module packaging is actually
9419 done.</para></listitem>
9420 <listitem><para>Ensure that any dependencies on optional
9421 modules from other recipes are satisfied by your recipe.
9422 </para></listitem>
9423 </itemizedlist>
9424 </para>
9425
9426 <section id='making-sure-the-packaging-is-done'>
9427 <title>Making Sure the Packaging is Done</title>
9428
9429 <para>
9430 To ensure the module packaging actually gets done, you use
9431 the <filename>do_split_packages</filename> function within
9432 the <filename>populate_packages</filename> Python function
9433 in your recipe.
9434 The <filename>do_split_packages</filename> function
9435 searches for a pattern of files or directories under a
9436 specified path and creates a package for each one it finds
9437 by appending to the
9438 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9439 variable and setting the appropriate values for
9440 <filename>FILES_packagename</filename>,
9441 <filename>RDEPENDS_packagename</filename>,
9442 <filename>DESCRIPTION_packagename</filename>, and so forth.
9443 Here is an example from the <filename>lighttpd</filename>
9444 recipe:
9445 <literallayout class='monospaced'>
9446 python populate_packages_prepend () {
9447 lighttpd_libdir = d.expand('${libdir}')
9448 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9449 'lighttpd-module-%s', 'Lighttpd module for %s',
9450 extra_depends='')
9451 }
9452 </literallayout>
9453 The previous example specifies a number of things in the
9454 call to <filename>do_split_packages</filename>.
9455 <itemizedlist>
9456 <listitem><para>A directory within the files installed
9457 by your recipe through <filename>do_install</filename>
9458 in which to search.</para></listitem>
9459 <listitem><para>A regular expression used to match module
9460 files in that directory.
9461 In the example, note the parentheses () that mark
9462 the part of the expression from which the module
9463 name should be derived.</para></listitem>
9464 <listitem><para>A pattern to use for the package names.
9465 </para></listitem>
9466 <listitem><para>A description for each package.
9467 </para></listitem>
9468 <listitem><para>An empty string for
9469 <filename>extra_depends</filename>, which disables
9470 the default dependency on the main
9471 <filename>lighttpd</filename> package.
9472 Thus, if a file in <filename>${libdir}</filename>
9473 called <filename>mod_alias.so</filename> is found,
9474 a package called <filename>lighttpd-module-alias</filename>
9475 is created for it and the
9476 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9477 is set to "Lighttpd module for alias".</para></listitem>
9478 </itemizedlist>
9479 </para>
9480
9481 <para>
9482 Often, packaging modules is as simple as the previous
9483 example.
9484 However, more advanced options exist that you can use
9485 within <filename>do_split_packages</filename> to modify its
9486 behavior.
9487 And, if you need to, you can add more logic by specifying
9488 a hook function that is called for each package.
9489 It is also perfectly acceptable to call
9490 <filename>do_split_packages</filename> multiple times if
9491 you have more than one set of modules to package.
9492 </para>
9493
9494 <para>
9495 For more examples that show how to use
9496 <filename>do_split_packages</filename>, see the
9497 <filename>connman.inc</filename> file in the
9498 <filename>meta/recipes-connectivity/connman/</filename>
9499 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009500 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009501 You can also find examples in
9502 <filename>meta/classes/kernel.bbclass</filename>.
9503 </para>
9504
9505 <para>
9506 Following is a reference that shows
9507 <filename>do_split_packages</filename> mandatory and
9508 optional arguments:
9509 <literallayout class='monospaced'>
9510 Mandatory arguments
9511
9512 root
9513 The path in which to search
9514 file_regex
9515 Regular expression to match searched files.
9516 Use parentheses () to mark the part of this
9517 expression that should be used to derive the
9518 module name (to be substituted where %s is
9519 used in other function arguments as noted below)
9520 output_pattern
9521 Pattern to use for the package names. Must
9522 include %s.
9523 description
9524 Description to set for each package. Must
9525 include %s.
9526
9527 Optional arguments
9528
9529 postinst
9530 Postinstall script to use for all packages
9531 (as a string)
9532 recursive
9533 True to perform a recursive search - default
9534 False
9535 hook
9536 A hook function to be called for every match.
9537 The function will be called with the following
9538 arguments (in the order listed):
9539
9540 f
9541 Full path to the file/directory match
9542 pkg
9543 The package name
9544 file_regex
9545 As above
9546 output_pattern
9547 As above
9548 modulename
9549 The module name derived using file_regex
9550
9551 extra_depends
9552 Extra runtime dependencies (RDEPENDS) to be
9553 set for all packages. The default value of None
9554 causes a dependency on the main package
9555 (${PN}) - if you do not want this, pass empty
9556 string '' for this parameter.
9557 aux_files_pattern
9558 Extra item(s) to be added to FILES for each
9559 package. Can be a single string item or a list
9560 of strings for multiple items. Must include %s.
9561 postrm
9562 postrm script to use for all packages (as a
9563 string)
9564 allow_dirs
9565 True to allow directories to be matched -
9566 default False
9567 prepend
9568 If True, prepend created packages to PACKAGES
9569 instead of the default False which appends them
9570 match_path
9571 match file_regex on the whole relative path to
9572 the root rather than just the file name
9573 aux_files_pattern_verbatim
9574 Extra item(s) to be added to FILES for each
9575 package, using the actual derived module name
9576 rather than converting it to something legal
9577 for a package name. Can be a single string item
9578 or a list of strings for multiple items. Must
9579 include %s.
9580 allow_links
9581 True to allow symlinks to be matched - default
9582 False
9583 summary
9584 Summary to set for each package. Must include %s;
9585 defaults to description if not set.
9586 </literallayout>
9587 </para>
9588 </section>
9589
9590 <section id='satisfying-dependencies'>
9591 <title>Satisfying Dependencies</title>
9592
9593 <para>
9594 The second part for handling optional module packaging
9595 is to ensure that any dependencies on optional modules
9596 from other recipes are satisfied by your recipe.
9597 You can be sure these dependencies are satisfied by
9598 using the
9599 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9600 Here is an example that continues with the
9601 <filename>lighttpd</filename> recipe shown earlier:
9602 <literallayout class='monospaced'>
9603 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9604 </literallayout>
9605 The name specified in the regular expression can of
9606 course be anything.
9607 In this example, it is <filename>lighttpd-module-</filename>
9608 and is specified as the prefix to ensure that any
9609 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9610 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9611 on a package name starting with the prefix are satisfied
9612 during build time.
9613 If you are using <filename>do_split_packages</filename>
9614 as described in the previous section, the value you put in
9615 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9616 the name pattern specified in the call to
9617 <filename>do_split_packages</filename>.
9618 </para>
9619 </section>
9620 </section>
9621
9622 <section id='using-runtime-package-management'>
9623 <title>Using Runtime Package Management</title>
9624
9625 <para>
9626 During a build, BitBake always transforms a recipe into one or
9627 more packages.
9628 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009629 and produces a number of packages (e.g.
9630 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9631 <filename>bash-completion</filename>,
9632 <filename>bash-completion-dbg</filename>,
9633 <filename>bash-completion-dev</filename>,
9634 <filename>bash-completion-extra</filename>,
9635 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009636 Not all generated packages are included in an image.
9637 </para>
9638
9639 <para>
9640 In several situations, you might need to update, add, remove,
9641 or query the packages on a target device at runtime
9642 (i.e. without having to generate a new image).
9643 Examples of such situations include:
9644 <itemizedlist>
9645 <listitem><para>
9646 You want to provide in-the-field updates to deployed
9647 devices (e.g. security updates).
9648 </para></listitem>
9649 <listitem><para>
9650 You want to have a fast turn-around development cycle
9651 for one or more applications that run on your device.
9652 </para></listitem>
9653 <listitem><para>
9654 You want to temporarily install the "debug" packages
9655 of various applications on your device so that
9656 debugging can be greatly improved by allowing
9657 access to symbols and source debugging.
9658 </para></listitem>
9659 <listitem><para>
9660 You want to deploy a more minimal package selection of
9661 your device but allow in-the-field updates to add a
9662 larger selection for customization.
9663 </para></listitem>
9664 </itemizedlist>
9665 </para>
9666
9667 <para>
9668 In all these situations, you have something similar to a more
9669 traditional Linux distribution in that in-field devices
9670 are able to receive pre-compiled packages from a server for
9671 installation or update.
9672 Being able to install these packages on a running,
9673 in-field device is what is termed "runtime package
9674 management".
9675 </para>
9676
9677 <para>
9678 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009679 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009680 packages plus the required metadata.
9681 You also need package manipulation tools on the target.
9682 The build machine is a likely candidate to act as the server.
9683 However, that machine does not necessarily have to be the
9684 package server.
9685 The build machine could push its artifacts to another machine
9686 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009687 In fact, doing so is advantageous for a production
9688 environment as getting the packages away from the
9689 development system's build directory prevents accidental
9690 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009691 </para>
9692
9693 <para>
9694 A simple build that targets just one device produces
9695 more than one package database.
9696 In other words, the packages produced by a build are separated
9697 out into a couple of different package groupings based on
9698 criteria such as the target's CPU architecture, the target
9699 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009700 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009701 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009702 <filename>noarch</filename>, <filename>i586</filename>, and
9703 <filename>qemux86</filename>.
9704 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009705 aware of all the packages that were available to it,
9706 you would need to point it to each of these databases
9707 individually.
9708 In a similar way, a traditional Linux distribution usually is
9709 configured to be aware of a number of software repositories
9710 from which it retrieves packages.
9711 </para>
9712
9713 <para>
9714 Using runtime package management is completely optional and
9715 not required for a successful build or deployment in any
9716 way.
9717 But if you want to make use of runtime package management,
9718 you need to do a couple things above and beyond the basics.
9719 The remainder of this section describes what you need to do.
9720 </para>
9721
9722 <section id='runtime-package-management-build'>
9723 <title>Build Considerations</title>
9724
9725 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009726 This section describes build considerations of which you
9727 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009728 package management.
9729 </para>
9730
9731 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009732 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009733 what format or formats to use.
9734 In your configuration, you use the
9735 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009736 variable to specify the format:
9737 <orderedlist>
9738 <listitem><para>
9739 Open the <filename>local.conf</filename> file
9740 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009741 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009742 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9743 </para></listitem>
9744 <listitem><para>
9745 Select the desired package format as follows:
9746 <literallayout class='monospaced'>
9747 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9748 </literallayout>
9749 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009750 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009751 supported package formats.
9752 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009753 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009754 different package formats, you can set the
9755 variable with more than one argument.
9756 However, the OpenEmbedded build system only
9757 uses the first argument when creating an image
9758 or Software Development Kit (SDK).
9759 </note>
9760 </para></listitem>
9761 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009762 </para>
9763
9764 <para>
9765 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009766 package database containing the packages in your current
9767 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009768 target for runtime package management, you can include
9769 "package-management" in the
9770 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9771 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009772 Including "package-management" in this configuration
9773 variable ensures that when the image is assembled for your
9774 target, the image includes the currently-known package
9775 databases as well as the target-specific tools required
9776 for runtime package management to be performed on the
9777 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009778 However, this is not strictly necessary.
9779 You could start your image off without any databases
9780 but only include the required on-target package
9781 tool(s).
9782 As an example, you could include "opkg" in your
9783 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9784 variable if you are using the IPK package format.
9785 You can then initialize your target's package database(s)
9786 later once your image is up and running.
9787 </para>
9788
9789 <para>
9790 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009791 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009792 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009793 package index after the build by using the following
9794 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009795 <literallayout class='monospaced'>
9796 $ bitbake package-index
9797 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009798 It might be tempting to build the package and the
9799 package index at the same time with a command such as
9800 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009801 <literallayout class='monospaced'>
9802 $ bitbake <replaceable>some-package</replaceable> package-index
9803 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009804 Do not do this as BitBake does not schedule the package
9805 index for after the completion of the package you are
9806 building.
9807 Consequently, you cannot be sure of the package index
9808 including information for the package you just built.
9809 Thus, be sure to run the package update step separately
9810 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009811 </para>
9812
9813 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009814 You can use the
9815 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9816 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9817 and
9818 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9819 variables to pre-configure target images to use a package
9820 feed.
9821 If you do not define these variables, then manual steps
9822 as described in the subsequent sections are necessary to
9823 configure the target.
9824 You should set these variables before building the image
9825 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009826 </para>
9827
9828 <para>
9829 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009830 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009831 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009832 For example, if
9833 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009834 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009835 is RPM, then your RPM packages are available in
9836 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009837 </para>
9838 </section>
9839
9840 <section id='runtime-package-management-server'>
9841 <title>Host or Server Machine Setup</title>
9842
9843 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009844 Although other protocols are possible, a server using HTTP
9845 typically serves packages.
9846 If you want to use HTTP, then set up and configure a
9847 web server such as Apache 2, lighttpd, or
9848 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009849 </para>
9850
9851 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009852 To keep things simple, this section describes how to set
9853 up a SimpleHTTPServer web server to share package feeds
9854 from the developer's machine.
9855 Although this server might not be the best for a production
9856 environment, the setup is simple and straight forward.
9857 Should you want to use a different server more suited for
9858 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9859 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009860 </para>
9861
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009862 <para>
9863 From within the build directory where you have built an
9864 image based on your packaging choice (i.e. the
9865 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9866 setting), simply start the server.
9867 The following example assumes a build directory of
9868 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9869 <filename>PACKAGE_CLASSES</filename> setting of
9870 "package_rpm":
9871 <literallayout class='monospaced'>
9872 $ cd ~/poky/build/tmp/deploy/rpm
9873 $ python -m SimpleHTTPServer
9874 </literallayout>
9875 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009876 </section>
9877
9878 <section id='runtime-package-management-target'>
9879 <title>Target Setup</title>
9880
9881 <para>
9882 Setting up the target differs depending on the
9883 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009884 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009885 </para>
9886
9887 <section id='runtime-package-management-target-rpm'>
9888 <title>Using RPM</title>
9889
9890 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009891 The
9892 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9893 (DNF) performs runtime package management of RPM
9894 packages.
9895 In order to use DNF for runtime package management,
9896 you must perform an initial setup on the target
9897 machine for cases where the
9898 <filename>PACKAGE_FEED_*</filename> variables were not
9899 set as part of the image that is running on the
9900 target.
9901 This means if you built your image and did not not use
9902 these variables as part of the build and your image is
9903 now running on the target, you need to perform the
9904 steps in this section if you want to use runtime
9905 package management.
9906 <note>
9907 For information on the
9908 <filename>PACKAGE_FEED_*</filename> variables, see
9909 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9910 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9911 and
9912 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9913 in the Yocto Project Reference Manual variables
9914 glossary.
9915 </note>
9916 </para>
9917
9918 <para>
9919 On the target, you must inform DNF that package
9920 databases are available.
9921 You do this by creating a file named
9922 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9923 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009924 </para>
9925
9926 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009927 As an example, assume the target is able to use the
9928 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009929 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009930 and <filename>qemux86</filename> from a server named
9931 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009932 The specifics for setting up the web server are up to
9933 you.
9934 The critical requirement is that the URIs in the
9935 target repository configuration point to the
9936 correct remote location for the feeds.
9937 <note><title>Tip</title>
9938 For development purposes, you can point the web
9939 server to the build system's
9940 <filename>deploy</filename> directory.
9941 However, for production use, it is better to copy
9942 the package directories to a location outside of
9943 the build area and use that location.
9944 Doing so avoids situations where the build system
9945 overwrites or changes the
9946 <filename>deploy</filename> directory.
9947 </note>
9948 </para>
9949
9950 <para>
9951 When telling DNF where to look for the package
9952 databases, you must declare individual locations
9953 per architecture or a single location used for all
9954 architectures.
9955 You cannot do both:
9956 <itemizedlist>
9957 <listitem><para>
9958 <emphasis>Create an Explicit List of Architectures:</emphasis>
9959 Define individual base URLs to identify where
9960 each package database is located:
9961 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009962 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009963 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009964 </literallayout>
9965 This example informs DNF about individual
9966 package databases for all three architectures.
9967 </para></listitem>
9968 <listitem><para>
9969 <emphasis>Create a Single (Full) Package Index:</emphasis>
9970 Define a single base URL that identifies where
9971 a full package database is located:
9972 <literallayout class='monospaced'>
9973 [oe-packages]
9974 baseurl=http://my.server/rpm
9975 </literallayout>
9976 This example informs DNF about a single package
9977 database that contains all the package index
9978 information for all supported architectures.
9979 </para></listitem>
9980 </itemizedlist>
9981 </para>
9982
9983 <para>
9984 Once you have informed DNF where to find the package
9985 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009986 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009987 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009988 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009989 DNF is now able to find, install, and upgrade packages
9990 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009991 <note>
9992 See the
9993 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
9994 for additional information.
9995 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009996 </para>
9997 </section>
9998
9999 <section id='runtime-package-management-target-ipk'>
10000 <title>Using IPK</title>
10001
10002 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010003 The <filename>opkg</filename> application performs
10004 runtime package management of IPK packages.
10005 You must perform an initial setup for
10006 <filename>opkg</filename> on the target machine
10007 if the
10008 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10009 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10010 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10011 variables have not been set or the target image was
10012 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010013 </para>
10014
10015 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010016 The <filename>opkg</filename> application uses
10017 configuration files to find available package
10018 databases.
10019 Thus, you need to create a configuration file inside
10020 the <filename>/etc/opkg/</filename> direction, which
10021 informs <filename>opkg</filename> of any repository
10022 you want to use.
10023 </para>
10024
10025 <para>
10026 As an example, suppose you are serving packages from a
10027 <filename>ipk/</filename> directory containing the
10028 <filename>i586</filename>,
10029 <filename>all</filename>, and
10030 <filename>qemux86</filename> databases through an
10031 HTTP server named <filename>my.server</filename>.
10032 On the target, create a configuration file
10033 (e.g. <filename>my_repo.conf</filename>) inside the
10034 <filename>/etc/opkg/</filename> directory containing
10035 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010036 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010037 src/gz all http://my.server/ipk/all
10038 src/gz i586 http://my.server/ipk/i586
10039 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010040 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010041 Next, instruct <filename>opkg</filename> to fetch
10042 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010043 <literallayout class='monospaced'>
10044 # opkg update
10045 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010046 The <filename>opkg</filename> application is now able
10047 to find, install, and upgrade packages from the
10048 specified repository.
10049 </para>
10050 </section>
10051
10052 <section id='runtime-package-management-target-deb'>
10053 <title>Using DEB</title>
10054
10055 <para>
10056 The <filename>apt</filename> application performs
10057 runtime package management of DEB packages.
10058 This application uses a source list file to find
10059 available package databases.
10060 You must perform an initial setup for
10061 <filename>apt</filename> on the target machine
10062 if the
10063 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10064 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10065 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10066 variables have not been set or the target image was
10067 built before the variables were set.
10068 </para>
10069
10070 <para>
10071 To inform <filename>apt</filename> of the repository
10072 you want to use, you might create a list file (e.g.
10073 <filename>my_repo.list</filename>) inside the
10074 <filename>/etc/apt/sources.list.d/</filename>
10075 directory.
10076 As an example, suppose you are serving packages from a
10077 <filename>deb/</filename> directory containing the
10078 <filename>i586</filename>,
10079 <filename>all</filename>, and
10080 <filename>qemux86</filename> databases through an
10081 HTTP server named <filename>my.server</filename>.
10082 The list file should contain:
10083 <literallayout class='monospaced'>
10084 deb http://my.server/deb/all ./
10085 deb http://my.server/deb/i586 ./
10086 deb http://my.server/deb/qemux86 ./
10087 </literallayout>
10088 Next, instruct the <filename>apt</filename>
10089 application to fetch the repository information:
10090 <literallayout class='monospaced'>
10091 # apt-get update
10092 </literallayout>
10093 After this step, <filename>apt</filename> is able
10094 to find, install, and upgrade packages from the
10095 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010096 </para>
10097 </section>
10098 </section>
10099 </section>
10100
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010101 <section id='generating-and-using-signed-packages'>
10102 <title>Generating and Using Signed Packages</title>
10103 <para>
10104 In order to add security to RPM packages used during a build,
10105 you can take steps to securely sign them.
10106 Once a signature is verified, the OpenEmbedded build system
10107 can use the package in the build.
10108 If security fails for a signed package, the build system
10109 aborts the build.
10110 </para>
10111
10112 <para>
10113 This section describes how to sign RPM packages during a build
10114 and how to use signed package feeds (repositories) when
10115 doing a build.
10116 </para>
10117
10118 <section id='signing-rpm-packages'>
10119 <title>Signing RPM Packages</title>
10120
10121 <para>
10122 To enable signing RPM packages, you must set up the
10123 following configurations in either your
10124 <filename>local.config</filename> or
10125 <filename>distro.config</filename> file:
10126 <literallayout class='monospaced'>
10127 # Inherit sign_rpm.bbclass to enable signing functionality
10128 INHERIT += " sign_rpm"
10129 # Define the GPG key that will be used for signing.
10130 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
10131 # Provide passphrase for the key
10132 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
10133 </literallayout>
10134 <note>
10135 Be sure to supply appropriate values for both
10136 <replaceable>key_name</replaceable> and
10137 <replaceable>passphrase</replaceable>
10138 </note>
10139 Aside from the
10140 <filename>RPM_GPG_NAME</filename> and
10141 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
10142 previous example, two optional variables related to signing
10143 exist:
10144 <itemizedlist>
10145 <listitem><para>
10146 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10147 Specifies a <filename>gpg</filename> binary/wrapper
10148 that is executed when the package is signed.
10149 </para></listitem>
10150 <listitem><para>
10151 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10152 Specifies the <filename>gpg</filename> home
10153 directory used when the package is signed.
10154 </para></listitem>
10155 </itemizedlist>
10156 </para>
10157 </section>
10158
10159 <section id='processing-package-feeds'>
10160 <title>Processing Package Feeds</title>
10161
10162 <para>
10163 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010164 also enable signed package feeds for IPK and RPM packages.
10165 </para>
10166
10167 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010168 The steps you need to take to enable signed package feed
10169 use are similar to the steps used to sign RPM packages.
10170 You must define the following in your
10171 <filename>local.config</filename> or
10172 <filename>distro.config</filename> file:
10173 <literallayout class='monospaced'>
10174 INHERIT += "sign_package_feed"
10175 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10176 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10177 </literallayout>
10178 For signed package feeds, the passphrase must exist in a
10179 separate file, which is pointed to by the
10180 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10181 variable.
10182 Regarding security, keeping a plain text passphrase out of
10183 the configuration is more secure.
10184 </para>
10185
10186 <para>
10187 Aside from the
10188 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10189 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10190 variables, three optional variables related to signed
10191 package feeds exist:
10192 <itemizedlist>
10193 <listitem><para>
10194 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10195 Specifies a <filename>gpg</filename> binary/wrapper
10196 that is executed when the package is signed.
10197 </para></listitem>
10198 <listitem><para>
10199 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10200 Specifies the <filename>gpg</filename> home
10201 directory used when the package is signed.
10202 </para></listitem>
10203 <listitem><para>
10204 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10205 Specifies the type of <filename>gpg</filename>
10206 signature.
10207 This variable applies only to RPM and IPK package
10208 feeds.
10209 Allowable values for the
10210 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10211 are "ASC", which is the default and specifies ascii
10212 armored, and "BIN", which specifies binary.
10213 </para></listitem>
10214 </itemizedlist>
10215 </para>
10216 </section>
10217 </section>
10218
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010219 <section id='testing-packages-with-ptest'>
10220 <title>Testing Packages With ptest</title>
10221
10222 <para>
10223 A Package Test (ptest) runs tests against packages built
10224 by the OpenEmbedded build system on the target machine.
10225 A ptest contains at least two items: the actual test, and
10226 a shell script (<filename>run-ptest</filename>) that starts
10227 the test.
10228 The shell script that starts the test must not contain
10229 the actual test - the script only starts the test.
10230 On the other hand, the test can be anything from a simple
10231 shell script that runs a binary and checks the output to
10232 an elaborate system of test binaries and data files.
10233 </para>
10234
10235 <para>
10236 The test generates output in the format used by
10237 Automake:
10238 <literallayout class='monospaced'>
10239 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10240 </literallayout>
10241 where the result can be <filename>PASS</filename>,
10242 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10243 and the testname can be any identifying string.
10244 </para>
10245
10246 <para>
10247 For a list of Yocto Project recipes that are already
10248 enabled with ptest, see the
10249 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10250 wiki page.
10251 <note>
10252 A recipe is "ptest-enabled" if it inherits the
10253 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10254 class.
10255 </note>
10256 </para>
10257
10258 <section id='adding-ptest-to-your-build'>
10259 <title>Adding ptest to Your Build</title>
10260
10261 <para>
10262 To add package testing to your build, add the
10263 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10264 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10265 variables to your <filename>local.conf</filename> file,
10266 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010267 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010268 <literallayout class='monospaced'>
10269 DISTRO_FEATURES_append = " ptest"
10270 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10271 </literallayout>
10272 Once your build is complete, the ptest files are installed
10273 into the
10274 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10275 directory within the image, where
10276 <filename><replaceable>package</replaceable></filename>
10277 is the name of the package.
10278 </para>
10279 </section>
10280
10281 <section id='running-ptest'>
10282 <title>Running ptest</title>
10283
10284 <para>
10285 The <filename>ptest-runner</filename> package installs a
10286 shell script that loops through all installed ptest test
10287 suites and runs them in sequence.
10288 Consequently, you might want to add this package to
10289 your image.
10290 </para>
10291 </section>
10292
10293 <section id='getting-your-package-ready'>
10294 <title>Getting Your Package Ready</title>
10295
10296 <para>
10297 In order to enable a recipe to run installed ptests
10298 on target hardware,
10299 you need to prepare the recipes that build the packages
10300 you want to test.
10301 Here is what you have to do for each recipe:
10302 <itemizedlist>
10303 <listitem><para><emphasis>Be sure the recipe
10304 inherits the
10305 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10306 class:</emphasis>
10307 Include the following line in each recipe:
10308 <literallayout class='monospaced'>
10309 inherit ptest
10310 </literallayout>
10311 </para></listitem>
10312 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10313 This script starts your test.
10314 Locate the script where you will refer to it
10315 using
10316 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10317 Here is an example that starts a test for
10318 <filename>dbus</filename>:
10319 <literallayout class='monospaced'>
10320 #!/bin/sh
10321 cd test
10322 make -k runtest-TESTS
10323 </literallayout>
10324 </para></listitem>
10325 <listitem><para><emphasis>Ensure dependencies are
10326 met:</emphasis>
10327 If the test adds build or runtime dependencies
10328 that normally do not exist for the package
10329 (such as requiring "make" to run the test suite),
10330 use the
10331 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10332 and
10333 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10334 variables in your recipe in order for the package
10335 to meet the dependencies.
10336 Here is an example where the package has a runtime
10337 dependency on "make":
10338 <literallayout class='monospaced'>
10339 RDEPENDS_${PN}-ptest += "make"
10340 </literallayout>
10341 </para></listitem>
10342 <listitem><para><emphasis>Add a function to build the
10343 test suite:</emphasis>
10344 Not many packages support cross-compilation of
10345 their test suites.
10346 Consequently, you usually need to add a
10347 cross-compilation function to the package.
10348 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010349
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010350 <para>Many packages based on Automake compile and
10351 run the test suite by using a single command
10352 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010353 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010354 builds and runs on the same computer, while
10355 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010356 on the host but executed for the target
10357 architecture (though often, as in the case for
10358 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010359 The built version of Automake that ships with the
10360 Yocto Project includes a patch that separates
10361 building and execution.
10362 Consequently, packages that use the unaltered,
10363 patched version of <filename>make check</filename>
10364 automatically cross-compiles.</para>
10365 <para>Regardless, you still must add a
10366 <filename>do_compile_ptest</filename> function to
10367 build the test suite.
10368 Add a function similar to the following to your
10369 recipe:
10370 <literallayout class='monospaced'>
10371 do_compile_ptest() {
10372 oe_runmake buildtest-TESTS
10373 }
10374 </literallayout>
10375 </para></listitem>
10376 <listitem><para><emphasis>Ensure special configurations
10377 are set:</emphasis>
10378 If the package requires special configurations
10379 prior to compiling the test code, you must
10380 insert a <filename>do_configure_ptest</filename>
10381 function into the recipe.
10382 </para></listitem>
10383 <listitem><para><emphasis>Install the test
10384 suite:</emphasis>
10385 The <filename>ptest</filename> class
10386 automatically copies the file
10387 <filename>run-ptest</filename> to the target and
10388 then runs make <filename>install-ptest</filename>
10389 to run the tests.
10390 If this is not enough, you need to create a
10391 <filename>do_install_ptest</filename> function and
10392 make sure it gets called after the
10393 "make install-ptest" completes.
10394 </para></listitem>
10395 </itemizedlist>
10396 </para>
10397 </section>
10398 </section>
10399 </section>
10400
Brad Bishop316dfdd2018-06-25 12:45:53 -040010401 <section id='efficiently-fetching-source-files-during-a-build'>
10402 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010403
10404 <para>
10405 The OpenEmbedded build system works with source files located
10406 through the
10407 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10408 variable.
10409 When you build something using BitBake, a big part of the operation
10410 is locating and downloading all the source tarballs.
10411 For images, downloading all the source for various packages can
10412 take a significant amount of time.
10413 </para>
10414
10415 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010416 This section shows you how you can use mirrors to speed up
10417 fetching source files and how you can pre-fetch files all of which
10418 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010419 </para>
10420
10421 <section id='setting-up-effective-mirrors'>
10422 <title>Setting up Effective Mirrors</title>
10423
10424 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010425 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010426 build is simply downloading all of the source tarballs.
10427 Maybe you have been working with another build system
10428 (OpenEmbedded or Angstrom) for which you have built up a
10429 sizable directory of source tarballs.
10430 Or, perhaps someone else has such a directory for which you
10431 have read access.
10432 If so, you can save time by adding statements to your
10433 configuration file so that the build process checks local
10434 directories first for existing tarballs before checking the
10435 Internet.
10436 </para>
10437
10438 <para>
10439 Here is an efficient way to set it up in your
10440 <filename>local.conf</filename> file:
10441 <literallayout class='monospaced'>
10442 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10443 INHERIT += "own-mirrors"
10444 BB_GENERATE_MIRROR_TARBALLS = "1"
10445 # BB_NO_NETWORK = "1"
10446 </literallayout>
10447 </para>
10448
10449 <para>
10450 In the previous example, the
10451 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10452 variable causes the OpenEmbedded build system to generate
10453 tarballs of the Git repositories and store them in the
10454 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10455 directory.
10456 Due to performance reasons, generating and storing these
10457 tarballs is not the build system's default behavior.
10458 </para>
10459
10460 <para>
10461 You can also use the
10462 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10463 variable.
10464 For an example, see the variable's glossary entry in the
10465 Yocto Project Reference Manual.
10466 </para>
10467 </section>
10468
10469 <section id='getting-source-files-and-suppressing-the-build'>
10470 <title>Getting Source Files and Suppressing the Build</title>
10471
10472 <para>
10473 Another technique you can use to ready yourself for a
10474 successive string of build operations, is to pre-fetch
10475 all the source files without actually starting a build.
10476 This technique lets you work through any download issues
10477 and ultimately gathers all the source files into your
10478 download directory
10479 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10480 which is located with
10481 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10482 </para>
10483
10484 <para>
10485 Use the following BitBake command form to fetch all the
10486 necessary sources without starting the build:
10487 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010488 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010489 </literallayout>
10490 This variation of the BitBake command guarantees that you
10491 have all the sources for that BitBake target should you
10492 disconnect from the Internet and want to do the build
10493 later offline.
10494 </para>
10495 </section>
10496 </section>
10497
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010498 <section id="selecting-an-initialization-manager">
10499 <title>Selecting an Initialization Manager</title>
10500
10501 <para>
10502 By default, the Yocto Project uses SysVinit as the initialization
10503 manager.
10504 However, support also exists for systemd,
10505 which is a full replacement for init with
10506 parallel starting of services, reduced shell overhead and other
10507 features that are used by many distributions.
10508 </para>
10509
10510 <para>
10511 If you want to use SysVinit, you do
10512 not have to do anything.
10513 But, if you want to use systemd, you must
10514 take some steps as described in the following sections.
10515 </para>
10516
10517 <section id='using-systemd-exclusively'>
10518 <title>Using systemd Exclusively</title>
10519
10520 <para>
10521 Set the these variables in your distribution configuration
10522 file as follows:
10523 <literallayout class='monospaced'>
10524 DISTRO_FEATURES_append = " systemd"
10525 VIRTUAL-RUNTIME_init_manager = "systemd"
10526 </literallayout>
10527 You can also prevent the SysVinit
10528 distribution feature from
10529 being automatically enabled as follows:
10530 <literallayout class='monospaced'>
10531 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10532 </literallayout>
10533 Doing so removes any redundant SysVinit scripts.
10534 </para>
10535
10536 <para>
10537 To remove initscripts from your image altogether,
10538 set this variable also:
10539 <literallayout class='monospaced'>
10540 VIRTUAL-RUNTIME_initscripts = ""
10541 </literallayout>
10542 </para>
10543
10544 <para>
10545 For information on the backfill variable, see
10546 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10547 </para>
10548 </section>
10549
10550 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10551 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10552
10553 <para>
10554 Set these variables in your distribution configuration
10555 file as follows:
10556 <literallayout class='monospaced'>
10557 DISTRO_FEATURES_append = " systemd"
10558 VIRTUAL-RUNTIME_init_manager = "systemd"
10559 </literallayout>
10560 Doing so causes your main image to use the
10561 <filename>packagegroup-core-boot.bb</filename> recipe and
10562 systemd.
10563 The rescue/minimal image cannot use this package group.
10564 However, it can install SysVinit
10565 and the appropriate packages will have support for both
10566 systemd and SysVinit.
10567 </para>
10568 </section>
10569 </section>
10570
10571 <section id="selecting-dev-manager">
10572 <title>Selecting a Device Manager</title>
10573
10574 <para>
10575 The Yocto Project provides multiple ways to manage the device
10576 manager (<filename>/dev</filename>):
10577 <itemizedlist>
10578 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10579 For this case, the <filename>/dev</filename> directory
10580 is persistent and the required device nodes are created
10581 during the build.
10582 </para></listitem>
10583 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10584 For this case, the <filename>/dev</filename> directory
10585 is provided by the kernel as an in-memory file system and
10586 is automatically populated by the kernel at runtime.
10587 Additional configuration of device nodes is done in user
10588 space by a device manager like
10589 <filename>udev</filename> or
10590 <filename>busybox-mdev</filename>.
10591 </para></listitem>
10592 </itemizedlist>
10593 </para>
10594
10595 <section id="static-dev-management">
10596 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10597
10598 <para>
10599 To use the static method for device population, you need to
10600 set the
10601 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10602 variable to "0" as follows:
10603 <literallayout class='monospaced'>
10604 USE_DEVFS = "0"
10605 </literallayout>
10606 </para>
10607
10608 <para>
10609 The content of the resulting <filename>/dev</filename>
10610 directory is defined in a Device Table file.
10611 The
10612 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10613 variable defines the Device Table to use and should be set
10614 in the machine or distro configuration file.
10615 Alternatively, you can set this variable in your
10616 <filename>local.conf</filename> configuration file.
10617 </para>
10618
10619 <para>
10620 If you do not define the
10621 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10622 <filename>device_table-minimal.txt</filename> is used:
10623 <literallayout class='monospaced'>
10624 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10625 </literallayout>
10626 </para>
10627
10628 <para>
10629 The population is handled by the <filename>makedevs</filename>
10630 utility during image creation:
10631 </para>
10632 </section>
10633
10634 <section id="devtmpfs-dev-management">
10635 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10636
10637 <para>
10638 To use the dynamic method for device population, you need to
10639 use (or be sure to set) the
10640 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10641 variable to "1", which is the default:
10642 <literallayout class='monospaced'>
10643 USE_DEVFS = "1"
10644 </literallayout>
10645 With this setting, the resulting <filename>/dev</filename>
10646 directory is populated by the kernel using
10647 <filename>devtmpfs</filename>.
10648 Make sure the corresponding kernel configuration variable
10649 <filename>CONFIG_DEVTMPFS</filename> is set when building
10650 you build a Linux kernel.
10651 </para>
10652
10653 <para>
10654 All devices created by <filename>devtmpfs</filename> will be
10655 owned by <filename>root</filename> and have permissions
10656 <filename>0600</filename>.
10657 </para>
10658
10659 <para>
10660 To have more control over the device nodes, you can use a
10661 device manager like <filename>udev</filename> or
10662 <filename>busybox-mdev</filename>.
10663 You choose the device manager by defining the
10664 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10665 in your machine or distro configuration file.
10666 Alternatively, you can set this variable in your
10667 <filename>local.conf</filename> configuration file:
10668 <literallayout class='monospaced'>
10669 VIRTUAL-RUNTIME_dev_manager = "udev"
10670
10671 # Some alternative values
10672 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10673 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10674 </literallayout>
10675 </para>
10676 </section>
10677 </section>
10678
10679 <section id="platdev-appdev-srcrev">
10680 <title>Using an External SCM</title>
10681
10682 <para>
10683 If you're working on a recipe that pulls from an external Source
10684 Code Manager (SCM), it is possible to have the OpenEmbedded build
10685 system notice new recipe changes added to the SCM and then build
10686 the resulting packages that depend on the new recipes by using
10687 the latest versions.
10688 This only works for SCMs from which it is possible to get a
10689 sensible revision number for changes.
10690 Currently, you can do this with Apache Subversion (SVN), Git, and
10691 Bazaar (BZR) repositories.
10692 </para>
10693
10694 <para>
10695 To enable this behavior, the
10696 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
10697 of the recipe needs to reference
10698 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
10699 Here is an example:
10700 <literallayout class='monospaced'>
10701 PV = "1.2.3+git${SRCPV}"
10702 </literallayout>
10703 Then, you can add the following to your
10704 <filename>local.conf</filename>:
10705 <literallayout class='monospaced'>
10706 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
10707 </literallayout>
10708 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
10709 is the name of the recipe for which you want to enable automatic source
10710 revision updating.
10711 </para>
10712
10713 <para>
10714 If you do not want to update your local configuration file, you can
10715 add the following directly to the recipe to finish enabling
10716 the feature:
10717 <literallayout class='monospaced'>
10718 SRCREV = "${AUTOREV}"
10719 </literallayout>
10720 </para>
10721
10722 <para>
10723 The Yocto Project provides a distribution named
10724 <filename>poky-bleeding</filename>, whose configuration
10725 file contains the line:
10726 <literallayout class='monospaced'>
10727 require conf/distro/include/poky-floating-revisions.inc
10728 </literallayout>
10729 This line pulls in the listed include file that contains
10730 numerous lines of exactly that form:
10731 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010732 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
10733 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
10734 #SRCREV_pn-opkg ?= "${AUTOREV}"
10735 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
10736 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010737 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
10738 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
10739 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
10740 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
10741 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010742 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
10743 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
10744 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
10745 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010746 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
10747 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010748 .
10749 .
10750 .
10751 </literallayout>
10752 These lines allow you to experiment with building a
10753 distribution that tracks the latest development source
10754 for numerous packages.
10755 <note><title>Caution</title>
10756 The <filename>poky-bleeding</filename> distribution
10757 is not tested on a regular basis.
10758 Keep this in mind if you use it.
10759 </note>
10760 </para>
10761 </section>
10762
10763 <section id='creating-a-read-only-root-filesystem'>
10764 <title>Creating a Read-Only Root Filesystem</title>
10765
10766 <para>
10767 Suppose, for security reasons, you need to disable
10768 your target device's root filesystem's write permissions
10769 (i.e. you need a read-only root filesystem).
10770 Or, perhaps you are running the device's operating system
10771 from a read-only storage device.
10772 For either case, you can customize your image for
10773 that behavior.
10774 </para>
10775
10776 <note>
10777 Supporting a read-only root filesystem requires that the system and
10778 applications do not try to write to the root filesystem.
10779 You must configure all parts of the target system to write
10780 elsewhere, or to gracefully fail in the event of attempting to
10781 write to the root filesystem.
10782 </note>
10783
10784 <section id='creating-the-root-filesystem'>
10785 <title>Creating the Root Filesystem</title>
10786
10787 <para>
10788 To create the read-only root filesystem, simply add the
10789 "read-only-rootfs" feature to your image.
10790 Using either of the following statements in your
10791 image recipe or from within the
10792 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010793 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010794 causes the build system to create a read-only root filesystem:
10795 <literallayout class='monospaced'>
10796 IMAGE_FEATURES = "read-only-rootfs"
10797 </literallayout>
10798 or
10799 <literallayout class='monospaced'>
10800 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
10801 </literallayout>
10802 </para>
10803
10804 <para>
10805 For more information on how to use these variables, see the
10806 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
10807 section.
10808 For information on the variables, see
10809 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
10810 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
10811 </para>
10812 </section>
10813
10814 <section id='post-installation-scripts'>
10815 <title>Post-Installation Scripts</title>
10816
10817 <para>
10818 It is very important that you make sure all
10819 post-Installation (<filename>pkg_postinst</filename>) scripts
10820 for packages that are installed into the image can be run
10821 at the time when the root filesystem is created during the
10822 build on the host system.
10823 These scripts cannot attempt to run during first-boot on the
10824 target device.
10825 With the "read-only-rootfs" feature enabled,
10826 the build system checks during root filesystem creation to make
10827 sure all post-installation scripts succeed.
10828 If any of these scripts still need to be run after the root
10829 filesystem is created, the build immediately fails.
10830 These build-time checks ensure that the build fails
10831 rather than the target device fails later during its
10832 initial boot operation.
10833 </para>
10834
10835 <para>
10836 Most of the common post-installation scripts generated by the
10837 build system for the out-of-the-box Yocto Project are engineered
10838 so that they can run during root filesystem creation
10839 (e.g. post-installation scripts for caching fonts).
10840 However, if you create and add custom scripts, you need
10841 to be sure they can be run during this file system creation.
10842 </para>
10843
10844 <para>
10845 Here are some common problems that prevent
10846 post-installation scripts from running during root filesystem
10847 creation:
10848 <itemizedlist>
10849 <listitem><para>
10850 <emphasis>Not using $D in front of absolute
10851 paths:</emphasis>
10852 The build system defines
10853 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
10854 when the root filesystem is created.
10855 Furthermore, <filename>$D</filename> is blank when the
10856 script is run on the target device.
10857 This implies two purposes for <filename>$D</filename>:
10858 ensuring paths are valid in both the host and target
10859 environments, and checking to determine which
10860 environment is being used as a method for taking
10861 appropriate actions.
10862 </para></listitem>
10863 <listitem><para>
10864 <emphasis>Attempting to run processes that are
10865 specific to or dependent on the target
10866 architecture:</emphasis>
10867 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010868 tools, which run on the host system,
10869 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010870 by alternatively running the processes under QEMU,
10871 which has the <filename>qemu_run_binary</filename>
10872 function.
10873 For more information, see the
10874 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
10875 class.</para></listitem>
10876 </itemizedlist>
10877 </para>
10878 </section>
10879
10880 <section id='areas-with-write-access'>
10881 <title>Areas With Write Access</title>
10882
10883 <para>
10884 With the "read-only-rootfs" feature enabled,
10885 any attempt by the target to write to the root filesystem at
10886 runtime fails.
10887 Consequently, you must make sure that you configure processes
10888 and applications that attempt these types of writes do so
10889 to directories with write access (e.g.
10890 <filename>/tmp</filename> or <filename>/var/run</filename>).
10891 </para>
10892 </section>
10893 </section>
10894
Brad Bishop316dfdd2018-06-25 12:45:53 -040010895
10896
10897
10898 <section id='maintaining-build-output-quality'>
10899 <title>Maintaining Build Output Quality</title>
10900
10901 <para>
10902 Many factors can influence the quality of a build.
10903 For example, if you upgrade a recipe to use a new version of an
10904 upstream software package or you experiment with some new
10905 configuration options, subtle changes can occur that you might
10906 not detect until later.
10907 Consider the case where your recipe is using a newer version of
10908 an upstream package.
10909 In this case, a new version of a piece of software might
10910 introduce an optional dependency on another library, which is
10911 auto-detected.
10912 If that library has already been built when the software is
10913 building, the software will link to the built library and that
10914 library will be pulled into your image along with the new
10915 software even if you did not want the library.
10916 </para>
10917
10918 <para>
10919 The
10920 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
10921 class exists to help you maintain the quality of your build
10922 output.
10923 You can use the class to highlight unexpected and possibly
10924 unwanted changes in the build output.
10925 When you enable build history, it records information about the
10926 contents of each package and image and then commits that
10927 information to a local Git repository where you can examine
10928 the information.
10929 </para>
10930
10931 <para>
10932 The remainder of this section describes the following:
10933 <itemizedlist>
10934 <listitem><para>
10935 How you can enable and disable build history
10936 </para></listitem>
10937 <listitem><para>
10938 How to understand what the build history contains
10939 </para></listitem>
10940 <listitem><para>
10941 How to limit the information used for build history
10942 </para></listitem>
10943 <listitem><para>
10944 How to examine the build history from both a
10945 command-line and web interface
10946 </para></listitem>
10947 </itemizedlist>
10948 </para>
10949
10950 <section id='enabling-and-disabling-build-history'>
10951 <title>Enabling and Disabling Build History</title>
10952
10953 <para>
10954 Build history is disabled by default.
10955 To enable it, add the following <filename>INHERIT</filename>
10956 statement and set the
10957 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
10958 variable to "1" at the end of your
10959 <filename>conf/local.conf</filename> file found in the
10960 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
10961 <literallayout class='monospaced'>
10962 INHERIT += "buildhistory"
10963 BUILDHISTORY_COMMIT = "1"
10964 </literallayout>
10965 Enabling build history as previously described causes the
10966 OpenEmbedded build system to collect build output information
10967 and commit it as a single commit to a local
10968 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
10969 repository.
10970 <note>
10971 Enabling build history increases your build times slightly,
10972 particularly for images, and increases the amount of disk
10973 space used during the build.
10974 </note>
10975 </para>
10976
10977 <para>
10978 You can disable build history by removing the previous
10979 statements from your <filename>conf/local.conf</filename>
10980 file.
10981 </para>
10982 </section>
10983
10984 <section id='understanding-what-the-build-history-contains'>
10985 <title>Understanding What the Build History Contains</title>
10986
10987 <para>
10988 Build history information is kept in
10989 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
10990 in the Build Directory as defined by the
10991 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
10992 variable.
10993 The following is an example abbreviated listing:
10994 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
10995 </para>
10996
10997 <para>
10998 At the top level, a <filename>metadata-revs</filename>
10999 file exists that lists the revisions of the repositories for
11000 the enabled layers when the build was produced.
11001 The rest of the data splits into separate
11002 <filename>packages</filename>, <filename>images</filename>
11003 and <filename>sdk</filename> directories, the contents of
11004 which are described as follows.
11005 </para>
11006
11007 <section id='build-history-package-information'>
11008 <title>Build History Package Information</title>
11009
11010 <para>
11011 The history for each package contains a text file that has
11012 name-value pairs with information about the package.
11013 For example,
11014 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
11015 contains the following:
11016 <literallayout class='monospaced'>
11017 PV = 1.22.1
11018 PR = r32
11019 RPROVIDES =
11020 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
11021 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
11022 PKGSIZE = 540168
11023 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
11024 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
11025 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
11026 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
11027 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
11028 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
11029 /etc/busybox.links.nosuid /etc/busybox.links.suid
11030 </literallayout>
11031 Most of these name-value pairs correspond to variables
11032 used to produce the package.
11033 The exceptions are <filename>FILELIST</filename>, which
11034 is the actual list of files in the package, and
11035 <filename>PKGSIZE</filename>, which is the total size of
11036 files in the package in bytes.
11037 </para>
11038
11039 <para>
11040 A file also exists that corresponds to the recipe from
11041 which the package came (e.g.
11042 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
11043 <literallayout class='monospaced'>
11044 PV = 1.22.1
11045 PR = r32
11046 DEPENDS = initscripts kern-tools-native update-rc.d-native \
11047 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
11048 virtual/libc virtual/update-alternatives
11049 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
11050 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
11051 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
11052 </literallayout>
11053 </para>
11054
11055 <para>
11056 Finally, for those recipes fetched from a version control
11057 system (e.g., Git), a file exists that lists source
11058 revisions that are specified in the recipe and lists
11059 the actual revisions used during the build.
11060 Listed and actual revisions might differ when
11061 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
11062 is set to
11063 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
11064 Here is an example assuming
11065 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
11066 <literallayout class='monospaced'>
11067 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11068 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11069 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11070 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11071 </literallayout>
11072 You can use the
11073 <filename>buildhistory-collect-srcrevs</filename>
11074 command with the <filename>-a</filename> option to
11075 collect the stored <filename>SRCREV</filename> values
11076 from build history and report them in a format suitable for
11077 use in global configuration (e.g.,
11078 <filename>local.conf</filename> or a distro include file)
11079 to override floating <filename>AUTOREV</filename> values
11080 to a fixed set of revisions.
11081 Here is some example output from this command:
11082 <literallayout class='monospaced'>
11083 $ buildhistory-collect-srcrevs -a
11084 # i586-poky-linux
11085 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
11086 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
11087 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
11088 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11089 # x86_64-linux
11090 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
11091 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
11092 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
11093 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
11094 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
11095 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
11096 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
11097 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
11098 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11099 # qemux86-poky-linux
11100 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11101 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
11102 # all-poky-linux
11103 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
11104 </literallayout>
11105 <note>
11106 Here are some notes on using the
11107 <filename>buildhistory-collect-srcrevs</filename>
11108 command:
11109 <itemizedlist>
11110 <listitem><para>
11111 By default, only values where the
11112 <filename>SRCREV</filename> was not hardcoded
11113 (usually when <filename>AUTOREV</filename>
11114 is used) are reported.
11115 Use the <filename>-a</filename> option to
11116 see all <filename>SRCREV</filename> values.
11117 </para></listitem>
11118 <listitem><para>
11119 The output statements might not have any effect
11120 if overrides are applied elsewhere in the
11121 build system configuration.
11122 Use the <filename>-f</filename> option to add
11123 the <filename>forcevariable</filename> override
11124 to each output line if you need to work around
11125 this restriction.
11126 </para></listitem>
11127 <listitem><para>
11128 The script does apply special handling when
11129 building for multiple machines.
11130 However, the script does place a comment before
11131 each set of values that specifies which
11132 triplet to which they belong as previously
11133 shown (e.g.,
11134 <filename>i586-poky-linux</filename>).
11135 </para></listitem>
11136 </itemizedlist>
11137 </note>
11138 </para>
11139 </section>
11140
11141 <section id='build-history-image-information'>
11142 <title>Build History Image Information</title>
11143
11144 <para>
11145 The files produced for each image are as follows:
11146 <itemizedlist>
11147 <listitem><para>
11148 <filename>image-files:</filename>
11149 A directory containing selected files from the root
11150 filesystem.
11151 The files are defined by
11152 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
11153 </para></listitem>
11154 <listitem><para>
11155 <filename>build-id.txt:</filename>
11156 Human-readable information about the build
11157 configuration and metadata source revisions.
11158 This file contains the full build header as printed
11159 by BitBake.
11160 </para></listitem>
11161 <listitem><para>
11162 <filename>*.dot:</filename>
11163 Dependency graphs for the image that are
11164 compatible with <filename>graphviz</filename>.
11165 </para></listitem>
11166 <listitem><para>
11167 <filename>files-in-image.txt:</filename>
11168 A list of files in the image with permissions,
11169 owner, group, size, and symlink information.
11170 </para></listitem>
11171 <listitem><para>
11172 <filename>image-info.txt:</filename>
11173 A text file containing name-value pairs with
11174 information about the image.
11175 See the following listing example for more
11176 information.
11177 </para></listitem>
11178 <listitem><para>
11179 <filename>installed-package-names.txt:</filename>
11180 A list of installed packages by name only.
11181 </para></listitem>
11182 <listitem><para>
11183 <filename>installed-package-sizes.txt:</filename>
11184 A list of installed packages ordered by size.
11185 </para></listitem>
11186 <listitem><para>
11187 <filename>installed-packages.txt:</filename>
11188 A list of installed packages with full package
11189 filenames.
11190 </para></listitem>
11191 </itemizedlist>
11192 <note>
11193 Installed package information is able to be gathered
11194 and produced even if package management is disabled
11195 for the final image.
11196 </note>
11197 </para>
11198
11199 <para>
11200 Here is an example of <filename>image-info.txt</filename>:
11201 <literallayout class='monospaced'>
11202 DISTRO = poky
11203 DISTRO_VERSION = 1.7
11204 USER_CLASSES = buildstats image-mklibs image-prelink
11205 IMAGE_CLASSES = image_types
11206 IMAGE_FEATURES = debug-tweaks
11207 IMAGE_LINGUAS =
11208 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11209 BAD_RECOMMENDATIONS =
11210 NO_RECOMMENDATIONS =
11211 PACKAGE_EXCLUDE =
11212 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11213 write_image_manifest ; buildhistory_list_installed_image ; \
11214 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11215 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11216 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11217 IMAGESIZE = 6900
11218 </literallayout>
11219 Other than <filename>IMAGESIZE</filename>, which is the
11220 total size of the files in the image in Kbytes, the
11221 name-value pairs are variables that may have influenced the
11222 content of the image.
11223 This information is often useful when you are trying to
11224 determine why a change in the package or file
11225 listings has occurred.
11226 </para>
11227 </section>
11228
11229 <section id='using-build-history-to-gather-image-information-only'>
11230 <title>Using Build History to Gather Image Information Only</title>
11231
11232 <para>
11233 As you can see, build history produces image information,
11234 including dependency graphs, so you can see why something
11235 was pulled into the image.
11236 If you are just interested in this information and not
11237 interested in collecting specific package or SDK
11238 information, you can enable writing only image information
11239 without any history by adding the following to your
11240 <filename>conf/local.conf</filename> file found in the
11241 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11242 <literallayout class='monospaced'>
11243 INHERIT += "buildhistory"
11244 BUILDHISTORY_COMMIT = "0"
11245 BUILDHISTORY_FEATURES = "image"
11246 </literallayout>
11247 Here, you set the
11248 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11249 variable to use the image feature only.
11250 </para>
11251 </section>
11252
11253 <section id='build-history-sdk-information'>
11254 <title>Build History SDK Information</title>
11255
11256 <para>
11257 Build history collects similar information on the contents
11258 of SDKs
11259 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11260 as compared to information it collects for images.
11261 Furthermore, this information differs depending on whether
11262 an extensible or standard SDK is being produced.
11263 </para>
11264
11265 <para>
11266 The following list shows the files produced for SDKs:
11267 <itemizedlist>
11268 <listitem><para>
11269 <filename>files-in-sdk.txt:</filename>
11270 A list of files in the SDK with permissions,
11271 owner, group, size, and symlink information.
11272 This list includes both the host and target parts
11273 of the SDK.
11274 </para></listitem>
11275 <listitem><para>
11276 <filename>sdk-info.txt:</filename>
11277 A text file containing name-value pairs with
11278 information about the SDK.
11279 See the following listing example for more
11280 information.
11281 </para></listitem>
11282 <listitem><para>
11283 <filename>sstate-task-sizes.txt:</filename>
11284 A text file containing name-value pairs with
11285 information about task group sizes
11286 (e.g. <filename>do_populate_sysroot</filename>
11287 tasks have a total size).
11288 The <filename>sstate-task-sizes.txt</filename> file
11289 exists only when an extensible SDK is created.
11290 </para></listitem>
11291 <listitem><para>
11292 <filename>sstate-package-sizes.txt:</filename>
11293 A text file containing name-value pairs with
11294 information for the shared-state packages and
11295 sizes in the SDK.
11296 The <filename>sstate-package-sizes.txt</filename>
11297 file exists only when an extensible SDK is created.
11298 </para></listitem>
11299 <listitem><para>
11300 <filename>sdk-files:</filename>
11301 A folder that contains copies of the files
11302 mentioned in
11303 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11304 files are present in the output.
11305 Additionally, the default value of
11306 <filename>BUILDHISTORY_SDK_FILES</filename> is
11307 specific to the extensible SDK although you can
11308 set it differently if you would like to pull in
11309 specific files from the standard SDK.</para>
11310
11311 <para>The default files are
11312 <filename>conf/local.conf</filename>,
11313 <filename>conf/bblayers.conf</filename>,
11314 <filename>conf/auto.conf</filename>,
11315 <filename>conf/locked-sigs.inc</filename>, and
11316 <filename>conf/devtool.conf</filename>.
11317 Thus, for an extensible SDK, these files get
11318 copied into the <filename>sdk-files</filename>
11319 directory.
11320 </para></listitem>
11321 <listitem><para>
11322 The following information appears under
11323 each of the <filename>host</filename>
11324 and <filename>target</filename> directories
11325 for the portions of the SDK that run on the host
11326 and on the target, respectively:
11327 <note>
11328 The following files for the most part are empty
11329 when producing an extensible SDK because this
11330 type of SDK is not constructed from packages
11331 as is the standard SDK.
11332 </note>
11333 <itemizedlist>
11334 <listitem><para>
11335 <filename>depends.dot:</filename>
11336 Dependency graph for the SDK that is
11337 compatible with
11338 <filename>graphviz</filename>.
11339 </para></listitem>
11340 <listitem><para>
11341 <filename>installed-package-names.txt:</filename>
11342 A list of installed packages by name only.
11343 </para></listitem>
11344 <listitem><para>
11345 <filename>installed-package-sizes.txt:</filename>
11346 A list of installed packages ordered by size.
11347 </para></listitem>
11348 <listitem><para>
11349 <filename>installed-packages.txt:</filename>
11350 A list of installed packages with full
11351 package filenames.
11352 </para></listitem>
11353 </itemizedlist>
11354 </para></listitem>
11355 </itemizedlist>
11356 </para>
11357
11358 <para>
11359 Here is an example of <filename>sdk-info.txt</filename>:
11360 <literallayout class='monospaced'>
11361 DISTRO = poky
11362 DISTRO_VERSION = 1.3+snapshot-20130327
11363 SDK_NAME = poky-glibc-i686-arm
11364 SDK_VERSION = 1.3+snapshot
11365 SDKMACHINE =
11366 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11367 BAD_RECOMMENDATIONS =
11368 SDKSIZE = 352712
11369 </literallayout>
11370 Other than <filename>SDKSIZE</filename>, which is the
11371 total size of the files in the SDK in Kbytes, the
11372 name-value pairs are variables that might have influenced
11373 the content of the SDK.
11374 This information is often useful when you are trying to
11375 determine why a change in the package or file listings
11376 has occurred.
11377 </para>
11378 </section>
11379
11380 <section id='examining-build-history-information'>
11381 <title>Examining Build History Information</title>
11382
11383 <para>
11384 You can examine build history output from the command
11385 line or from a web interface.
11386 </para>
11387
11388 <para>
11389 To see any changes that have occurred (assuming you have
11390 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11391 you can simply use any Git command that allows you to
11392 view the history of a repository.
11393 Here is one method:
11394 <literallayout class='monospaced'>
11395 $ git log -p
11396 </literallayout>
11397 You need to realize, however, that this method does show
11398 changes that are not significant (e.g. a package's size
11399 changing by a few bytes).
11400 </para>
11401
11402 <para>
11403 A command-line tool called
11404 <filename>buildhistory-diff</filename> does exist, though,
11405 that queries the Git repository and prints just the
11406 differences that might be significant in human-readable
11407 form.
11408 Here is an example:
11409 <literallayout class='monospaced'>
11410 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11411 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11412 /etc/anotherpkg.conf was added
11413 /sbin/anotherpkg was added
11414 * (installed-package-names.txt):
11415 * anotherpkg was added
11416 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11417 anotherpkg was added
11418 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11419 * PR changed from "r0" to "r1"
11420 * PV changed from "0.1.10" to "0.1.12"
11421 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11422 * PR changed from "r0" to "r1"
11423 * PV changed from "0.1.10" to "0.1.12"
11424 </literallayout>
11425 <note>
11426 The <filename>buildhistory-diff</filename> tool
11427 requires the <filename>GitPython</filename> package.
11428 Be sure to install it using Pip3 as follows:
11429 <literallayout class='monospaced'>
11430 $ pip3 install GitPython --user
11431 </literallayout>
11432 Alternatively, you can install
11433 <filename>python3-git</filename> using the appropriate
11434 distribution package manager (e.g.
11435 <filename>apt-get</filename>, <filename>dnf</filename>,
11436 or <filename>zipper</filename>).
11437 </note>
11438 </para>
11439
11440 <para>
11441 To see changes to the build history using a web interface,
11442 follow the instruction in the <filename>README</filename>
11443 file here.
11444 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11445 </para>
11446
11447 <para>
11448 Here is a sample screenshot of the interface:
11449 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11450 </para>
11451 </section>
11452 </section>
11453 </section>
11454
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011455 <section id="performing-automated-runtime-testing">
11456 <title>Performing Automated Runtime Testing</title>
11457
11458 <para>
11459 The OpenEmbedded build system makes available a series of automated
11460 tests for images to verify runtime functionality.
11461 You can run these tests on either QEMU or actual target hardware.
11462 Tests are written in Python making use of the
11463 <filename>unittest</filename> module, and the majority of them
11464 run commands on the target system over SSH.
11465 This section describes how you set up the environment to use these
11466 tests, run available tests, and write and add your own tests.
11467 </para>
11468
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011469 <para>
11470 For information on the test and QA infrastructure available
11471 within the Yocto Project, see the
11472 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11473 section in the Yocto Project Reference Manual.
11474 </para>
11475
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011476 <section id='enabling-tests'>
11477 <title>Enabling Tests</title>
11478
11479 <para>
11480 Depending on whether you are planning to run tests using
11481 QEMU or on the hardware, you have to take
11482 different steps to enable the tests.
11483 See the following subsections for information on how to
11484 enable both types of tests.
11485 </para>
11486
11487 <section id='qemu-image-enabling-tests'>
11488 <title>Enabling Runtime Tests on QEMU</title>
11489
11490 <para>
11491 In order to run tests, you need to do the following:
11492 <itemizedlist>
11493 <listitem><para><emphasis>Set up to avoid interaction
11494 with <filename>sudo</filename> for networking:</emphasis>
11495 To accomplish this, you must do one of the
11496 following:
11497 <itemizedlist>
11498 <listitem><para>Add
11499 <filename>NOPASSWD</filename> for your user
11500 in <filename>/etc/sudoers</filename> either for
11501 all commands or just for
11502 <filename>runqemu-ifup</filename>.
11503 You must provide the full path as that can
11504 change if you are using multiple clones of the
11505 source repository.
11506 <note>
11507 On some distributions, you also need to
11508 comment out "Defaults requiretty" in
11509 <filename>/etc/sudoers</filename>.
11510 </note></para></listitem>
11511 <listitem><para>Manually configure a tap interface
11512 for your system.</para></listitem>
11513 <listitem><para>Run as root the script in
11514 <filename>scripts/runqemu-gen-tapdevs</filename>,
11515 which should generate a list of tap devices.
11516 This is the option typically chosen for
11517 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011518 <note><title>Notes</title>
11519 <itemizedlist>
11520 <listitem><para>
11521 Be sure to use an absolute path
11522 when calling this script
11523 with sudo.
11524 </para></listitem>
11525 <listitem><para>
11526 The package recipe
11527 <filename>qemu-helper-native</filename>
11528 is required to run this script.
11529 Build the package using the
11530 following command:
11531 <literallayout class='monospaced'>
11532 $ bitbake qemu-helper-native
11533 </literallayout>
11534 </para></listitem>
11535 </itemizedlist>
11536 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011537 </para></listitem>
11538 </itemizedlist></para></listitem>
11539 <listitem><para><emphasis>Set the
11540 <filename>DISPLAY</filename> variable:</emphasis>
11541 You need to set this variable so that you have an X
11542 server available (e.g. start
11543 <filename>vncserver</filename> for a headless machine).
11544 </para></listitem>
11545 <listitem><para><emphasis>Be sure your host's firewall
11546 accepts incoming connections from
11547 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011548 Some of the tests (in particular DNF tests) start
11549 an HTTP server on a random high number port,
11550 which is used to serve files to the target.
11551 The DNF module serves
11552 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11553 so it can run DNF channel commands.
11554 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011555 must accept incoming connections from 192.168.7.0/24,
11556 which is the default IP range used for tap devices
11557 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011558 <listitem><para><emphasis>Be sure your host has the
11559 correct packages installed:</emphasis>
11560 Depending your host's distribution, you need
11561 to have the following packages installed:
11562 <itemizedlist>
11563 <listitem><para>Ubuntu and Debian:
11564 <filename>sysstat</filename> and
11565 <filename>iproute2</filename>
11566 </para></listitem>
11567 <listitem><para>OpenSUSE:
11568 <filename>sysstat</filename> and
11569 <filename>iproute2</filename>
11570 </para></listitem>
11571 <listitem><para>Fedora:
11572 <filename>sysstat</filename> and
11573 <filename>iproute</filename>
11574 </para></listitem>
11575 <listitem><para>CentOS:
11576 <filename>sysstat</filename> and
11577 <filename>iproute</filename>
11578 </para></listitem>
11579 </itemizedlist>
11580 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011581 </itemizedlist>
11582 </para>
11583
11584 <para>
11585 Once you start running the tests, the following happens:
11586 <orderedlist>
11587 <listitem><para>A copy of the root filesystem is written
11588 to <filename>${WORKDIR}/testimage</filename>.
11589 </para></listitem>
11590 <listitem><para>The image is booted under QEMU using the
11591 standard <filename>runqemu</filename> script.
11592 </para></listitem>
11593 <listitem><para>A default timeout of 500 seconds occurs
11594 to allow for the boot process to reach the login prompt.
11595 You can change the timeout period by setting
11596 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11597 in the <filename>local.conf</filename> file.
11598 </para></listitem>
11599 <listitem><para>Once the boot process is reached and the
11600 login prompt appears, the tests run.
11601 The full boot log is written to
11602 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11603 </para></listitem>
11604 <listitem><para>Each test module loads in the order found
11605 in <filename>TEST_SUITES</filename>.
11606 You can find the full output of the commands run over
11607 SSH in
11608 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11609 </para></listitem>
11610 <listitem><para>If no failures occur, the task running the
11611 tests ends successfully.
11612 You can find the output from the
11613 <filename>unittest</filename> in the task log at
11614 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11615 </para></listitem>
11616 </orderedlist>
11617 </para>
11618 </section>
11619
11620 <section id='hardware-image-enabling-tests'>
11621 <title>Enabling Runtime Tests on Hardware</title>
11622
11623 <para>
11624 The OpenEmbedded build system can run tests on real
11625 hardware, and for certain devices it can also deploy
11626 the image to be tested onto the device beforehand.
11627 </para>
11628
11629 <para>
11630 For automated deployment, a "master image" is installed
11631 onto the hardware once as part of setup.
11632 Then, each time tests are to be run, the following
11633 occurs:
11634 <orderedlist>
11635 <listitem><para>The master image is booted into and
11636 used to write the image to be tested to
11637 a second partition.
11638 </para></listitem>
11639 <listitem><para>The device is then rebooted using an
11640 external script that you need to provide.
11641 </para></listitem>
11642 <listitem><para>The device boots into the image to be
11643 tested.
11644 </para></listitem>
11645 </orderedlist>
11646 </para>
11647
11648 <para>
11649 When running tests (independent of whether the image
11650 has been deployed automatically or not), the device is
11651 expected to be connected to a network on a
11652 pre-determined IP address.
11653 You can either use static IP addresses written into
11654 the image, or set the image to use DHCP and have your
11655 DHCP server on the test network assign a known IP address
11656 based on the MAC address of the device.
11657 </para>
11658
11659 <para>
11660 In order to run tests on hardware, you need to set
11661 <filename>TEST_TARGET</filename> to an appropriate value.
11662 For QEMU, you do not have to change anything, the default
11663 value is "QemuTarget".
11664 For running tests on hardware, the following options exist:
11665 <itemizedlist>
11666 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11667 Choose "SimpleRemoteTarget" if you are going to
11668 run tests on a target system that is already
11669 running the image to be tested and is available
11670 on the network.
11671 You can use "SimpleRemoteTarget" in conjunction
11672 with either real hardware or an image running
11673 within a separately started QEMU or any
11674 other virtual machine manager.
11675 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011676 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
11677 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011678 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011679 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011680 <filename>core-image-testmaster</filename>
11681 (or something similar) is installed.
11682 Also, your hardware under test must be in a
11683 DHCP-enabled network that gives it the same IP
11684 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011685 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011686 additional requirements and considerations.
11687 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011688 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011689 section, which follows, for more information.
11690 </para></listitem>
11691 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
11692 Choose "BeagleBoneTarget" if you are deploying
11693 images and running tests on the BeagleBone
11694 "Black" or original "White" hardware.
11695 For information on how to use these tests, see the
11696 comments at the top of the BeagleBoneTarget
11697 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
11698 file.
11699 </para></listitem>
11700 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
11701 Choose "EdgeRouterTarget" is you are deploying
11702 images and running tests on the Ubiquiti Networks
11703 EdgeRouter Lite.
11704 For information on how to use these tests, see the
11705 comments at the top of the EdgeRouterTarget
11706 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
11707 file.
11708 </para></listitem>
11709 <listitem><para><emphasis>"GrubTarget":</emphasis>
11710 Choose the "supports deploying images and running
11711 tests on any generic PC that boots using GRUB.
11712 For information on how to use these tests, see the
11713 comments at the top of the GrubTarget
11714 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
11715 file.
11716 </para></listitem>
11717 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
11718 Create your own custom target if you want to run
11719 tests when you are deploying images and running
11720 tests on a custom machine within your BSP layer.
11721 To do this, you need to add a Python unit that
11722 defines the target class under
11723 <filename>lib/oeqa/controllers/</filename> within
11724 your layer.
11725 You must also provide an empty
11726 <filename>__init__.py</filename>.
11727 For examples, see files in
11728 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
11729 </para></listitem>
11730 </itemizedlist>
11731 </para>
11732 </section>
11733
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011734 <section id='selecting-systemdboottarget'>
11735 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011736
11737 <para>
11738 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011739 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011740 in this section.
11741 You can skip down to the
11742 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
11743 section.
11744 </para>
11745
11746 <para>
11747 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011748 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011749 setup of your master image by doing the following:
11750 <orderedlist>
11751 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
11752 Be sure that <filename>EFI_PROVIDER</filename>
11753 is as follows:
11754 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011755 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011756 </literallayout>
11757 </para></listitem>
11758 <listitem><para><emphasis>Build the master image:</emphasis>
11759 Build the <filename>core-image-testmaster</filename>
11760 image.
11761 The <filename>core-image-testmaster</filename>
11762 recipe is provided as an example for a
11763 "master" image and you can customize the image
11764 recipe as you would any other recipe.
11765 </para>
11766 <para>Here are the image recipe requirements:
11767 <itemizedlist>
11768 <listitem><para>Inherits
11769 <filename>core-image</filename>
11770 so that kernel modules are installed.
11771 </para></listitem>
11772 <listitem><para>Installs normal linux utilities
11773 not busybox ones (e.g.
11774 <filename>bash</filename>,
11775 <filename>coreutils</filename>,
11776 <filename>tar</filename>,
11777 <filename>gzip</filename>, and
11778 <filename>kmod</filename>).
11779 </para></listitem>
11780 <listitem><para>Uses a custom
11781 Initial RAM Disk (initramfs) image with a
11782 custom installer.
11783 A normal image that you can install usually
11784 creates a single rootfs partition.
11785 This image uses another installer that
11786 creates a specific partition layout.
11787 Not all Board Support Packages (BSPs)
11788 can use an installer.
11789 For such cases, you need to manually create
11790 the following partition layout on the
11791 target:
11792 <itemizedlist>
11793 <listitem><para>First partition mounted
11794 under <filename>/boot</filename>,
11795 labeled "boot".
11796 </para></listitem>
11797 <listitem><para>The main rootfs
11798 partition where this image gets
11799 installed, which is mounted under
11800 <filename>/</filename>.
11801 </para></listitem>
11802 <listitem><para>Another partition
11803 labeled "testrootfs" where test
11804 images get deployed.
11805 </para></listitem>
11806 </itemizedlist>
11807 </para></listitem>
11808 </itemizedlist>
11809 </para></listitem>
11810 <listitem><para><emphasis>Install image:</emphasis>
11811 Install the image that you just built on the target
11812 system.
11813 </para></listitem>
11814 </orderedlist>
11815 </para>
11816
11817 <para>
11818 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011819 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011820 to set up the test image:
11821 <orderedlist>
11822 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
11823 Make sure you have the following statements in
11824 your <filename>local.conf</filename> file:
11825 <literallayout class='monospaced'>
11826 IMAGE_FSTYPES += "tar.gz"
11827 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011828 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011829 TEST_TARGET_IP = "192.168.2.3"
11830 </literallayout>
11831 </para></listitem>
11832 <listitem><para><emphasis>Build your test image:</emphasis>
11833 Use BitBake to build the image:
11834 <literallayout class='monospaced'>
11835 $ bitbake core-image-sato
11836 </literallayout>
11837 </para></listitem>
11838 </orderedlist>
11839 </para>
11840 </section>
11841
11842 <section id='power-control'>
11843 <title>Power Control</title>
11844
11845 <para>
11846 For most hardware targets other than SimpleRemoteTarget,
11847 you can control power:
11848 <itemizedlist>
11849 <listitem><para>
11850 You can use
11851 <filename>TEST_POWERCONTROL_CMD</filename>
11852 together with
11853 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11854 as a command that runs on the host and does power
11855 cycling.
11856 The test code passes one argument to that command:
11857 off, on or cycle (off then on).
11858 Here is an example that could appear in your
11859 <filename>local.conf</filename> file:
11860 <literallayout class='monospaced'>
11861 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
11862 </literallayout>
11863 In this example, the expect script does the
11864 following:
11865 <literallayout class='monospaced'>
11866 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
11867 </literallayout>
11868 It then runs a Python script that controls power
11869 for a label called <filename>nuc1</filename>.
11870 <note>
11871 You need to customize
11872 <filename>TEST_POWERCONTROL_CMD</filename>
11873 and
11874 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11875 for your own setup.
11876 The one requirement is that it accepts
11877 "on", "off", and "cycle" as the last argument.
11878 </note>
11879 </para></listitem>
11880 <listitem><para>
11881 When no command is defined, it connects to the
11882 device over SSH and uses the classic reboot command
11883 to reboot the device.
11884 Classic reboot is fine as long as the machine
11885 actually reboots (i.e. the SSH test has not
11886 failed).
11887 It is useful for scenarios where you have a simple
11888 setup, typically with a single board, and where
11889 some manual interaction is okay from time to time.
11890 </para></listitem>
11891 </itemizedlist>
11892 If you have no hardware to automatically perform power
11893 control but still wish to experiment with automated
11894 hardware testing, you can use the dialog-power-control
11895 script that shows a dialog prompting you to perform the
11896 required power action.
11897 This script requires either KDialog or Zenity to be
11898 installed.
11899 To use this script, set the
11900 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
11901 variable as follows:
11902 <literallayout class='monospaced'>
11903 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
11904 </literallayout>
11905 </para>
11906 </section>
11907
11908 <section id='serial-console-connection'>
11909 <title>Serial Console Connection</title>
11910
11911 <para>
11912 For test target classes requiring a serial console
11913 to interact with the bootloader (e.g. BeagleBoneTarget,
11914 EdgeRouterTarget, and GrubTarget), you need to
11915 specify a command to use to connect to the serial console
11916 of the target machine by using the
11917 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
11918 variable and optionally the
11919 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
11920 variable.
11921 </para>
11922
11923 <para>
11924 These cases could be a serial terminal program if the
11925 machine is connected to a local serial port, or a
11926 <filename>telnet</filename> or
11927 <filename>ssh</filename> command connecting to a remote
11928 console server.
11929 Regardless of the case, the command simply needs to
11930 connect to the serial console and forward that connection
11931 to standard input and output as any normal terminal
11932 program does.
11933 For example, to use the picocom terminal program on
11934 serial device <filename>/dev/ttyUSB0</filename>
11935 at 115200bps, you would set the variable as follows:
11936 <literallayout class='monospaced'>
11937 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
11938 </literallayout>
11939 For local devices where the serial port device disappears
11940 when the device reboots, an additional "serdevtry" wrapper
11941 script is provided.
11942 To use this wrapper, simply prefix the terminal command
11943 with
11944 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
11945 <literallayout class='monospaced'>
11946 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
11947115200 /dev/ttyUSB0"
11948 </literallayout>
11949 </para>
11950 </section>
11951 </section>
11952
11953 <section id="qemu-image-running-tests">
11954 <title>Running Tests</title>
11955
11956 <para>
11957 You can start the tests automatically or manually:
11958 <itemizedlist>
11959 <listitem><para><emphasis>Automatically running tests:</emphasis>
11960 To run the tests automatically after the
11961 OpenEmbedded build system successfully creates an image,
11962 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011963 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011964 variable to "1" in your <filename>local.conf</filename>
11965 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011966 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011967 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011968 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011969 </literallayout>
11970 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011971 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011972 <literallayout class='monospaced'>
11973 bitbake core-image-sato
11974 </literallayout></para></listitem>
11975 <listitem><para><emphasis>Manually running tests:</emphasis>
11976 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011977 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011978 class by editing your <filename>local.conf</filename>
11979 file:
11980 <literallayout class='monospaced'>
11981 INHERIT += "testimage"
11982 </literallayout>
11983 Next, use BitBake to run the tests:
11984 <literallayout class='monospaced'>
11985 bitbake -c testimage <replaceable>image</replaceable>
11986 </literallayout></para></listitem>
11987 </itemizedlist>
11988 </para>
11989
11990 <para>
11991 All test files reside in
11992 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011993 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011994 A test name maps directly to a Python module.
11995 Each test module may contain a number of individual tests.
11996 Tests are usually grouped together by the area
11997 tested (e.g tests for systemd reside in
11998 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
11999 </para>
12000
12001 <para>
12002 You can add tests to any layer provided you place them in the
12003 proper area and you extend
12004 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12005 in the <filename>local.conf</filename> file as normal.
12006 Be sure that tests reside in
12007 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
12008 <note>
12009 Be sure that module names do not collide with module names
12010 used in the default set of test modules in
12011 <filename>meta/lib/oeqa/runtime</filename>.
12012 </note>
12013 </para>
12014
12015 <para>
12016 You can change the set of tests run by appending or overriding
12017 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
12018 variable in <filename>local.conf</filename>.
12019 Each name in <filename>TEST_SUITES</filename> represents a
12020 required test for the image.
12021 Test modules named within <filename>TEST_SUITES</filename>
12022 cannot be skipped even if a test is not suitable for an image
12023 (e.g. running the RPM tests on an image without
12024 <filename>rpm</filename>).
12025 Appending "auto" to <filename>TEST_SUITES</filename> causes the
12026 build system to try to run all tests that are suitable for the
12027 image (i.e. each test module may elect to skip itself).
12028 </para>
12029
12030 <para>
12031 The order you list tests in <filename>TEST_SUITES</filename>
12032 is important and influences test dependencies.
12033 Consequently, tests that depend on other tests should be added
12034 after the test on which they depend.
12035 For example, since the <filename>ssh</filename> test
12036 depends on the
12037 <filename>ping</filename> test, "ssh" needs to come after
12038 "ping" in the list.
12039 The test class provides no re-ordering or dependency handling.
12040 <note>
12041 Each module can have multiple classes with multiple test
12042 methods.
12043 And, Python <filename>unittest</filename> rules apply.
12044 </note>
12045 </para>
12046
12047 <para>
12048 Here are some things to keep in mind when running tests:
12049 <itemizedlist>
12050 <listitem><para>The default tests for the image are defined
12051 as:
12052 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012053 DEFAULT_TEST_SUITES_pn-<replaceable>image</replaceable> = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012054 </literallayout></para></listitem>
12055 <listitem><para>Add your own test to the list of the
12056 by using the following:
12057 <literallayout class='monospaced'>
12058 TEST_SUITES_append = " mytest"
12059 </literallayout></para></listitem>
12060 <listitem><para>Run a specific list of tests as follows:
12061 <literallayout class='monospaced'>
12062 TEST_SUITES = "test1 test2 test3"
12063 </literallayout>
12064 Remember, order is important.
12065 Be sure to place a test that is dependent on another test
12066 later in the order.</para></listitem>
12067 </itemizedlist>
12068 </para>
12069 </section>
12070
12071 <section id="exporting-tests">
12072 <title>Exporting Tests</title>
12073
12074 <para>
12075 You can export tests so that they can run independently of
12076 the build system.
12077 Exporting tests is required if you want to be able to hand
12078 the test execution off to a scheduler.
12079 You can only export tests that are defined in
12080 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
12081 </para>
12082
12083 <para>
12084 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012085 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012086 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012087 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012088 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
12089 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012090 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012091 You can then export the tests with the following BitBake
12092 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012093 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012094 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012095 </literallayout>
12096 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012097 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12098 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012099 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
12100 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012101 <filename>TEST_EXPORT_DIR</filename> variable.
12102 </para>
12103
12104 <para>
12105 You can now run the tests outside of the build environment:
12106 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012107 $ cd tmp/testexport/<replaceable>image</replaceable>
12108 $ ./runexported.py testdata.json
12109 </literallayout>
12110 </para>
12111
12112 <para>
12113 Here is a complete example that shows IP addresses and uses
12114 the <filename>core-image-sato</filename> image:
12115 <literallayout class='monospaced'>
12116 INHERIT +="testexport"
12117 TEST_TARGET_IP = "192.168.7.2"
12118 TEST_SERVER_IP = "192.168.7.1"
12119 </literallayout>
12120 Use BitBake to export the tests:
12121 <literallayout class='monospaced'>
12122 $ bitbake core-image-sato -c testexport
12123 </literallayout>
12124 Run the tests outside of the build environment using the
12125 following:
12126 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012127 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012128 $ ./runexported.py testdata.json
12129 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012130 </para>
12131 </section>
12132
12133 <section id="qemu-image-writing-new-tests">
12134 <title>Writing New Tests</title>
12135
12136 <para>
12137 As mentioned previously, all new test files need to be in the
12138 proper place for the build system to find them.
12139 New tests for additional functionality outside of the core
12140 should be added to the layer that adds the functionality, in
12141 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
12142 (as long as
12143 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12144 is extended in the layer's
12145 <filename>layer.conf</filename> file as normal).
12146 Just remember the following:
12147 <itemizedlist>
12148 <listitem><para>Filenames need to map directly to test
12149 (module) names.
12150 </para></listitem>
12151 <listitem><para>Do not use module names that
12152 collide with existing core tests.
12153 </para></listitem>
12154 <listitem><para>Minimally, an empty
12155 <filename>__init__.py</filename> file must exist
12156 in the runtime directory.
12157 </para></listitem>
12158 </itemizedlist>
12159 </para>
12160
12161 <para>
12162 To create a new test, start by copying an existing module
12163 (e.g. <filename>syslog.py</filename> or
12164 <filename>gcc.py</filename> are good ones to use).
12165 Test modules can use code from
12166 <filename>meta/lib/oeqa/utils</filename>, which are helper
12167 classes.
12168 </para>
12169
12170 <note>
12171 Structure shell commands such that you rely on them and they
12172 return a single code for success.
12173 Be aware that sometimes you will need to parse the output.
12174 See the <filename>df.py</filename> and
12175 <filename>date.py</filename> modules for examples.
12176 </note>
12177
12178 <para>
12179 You will notice that all test classes inherit
12180 <filename>oeRuntimeTest</filename>, which is found in
12181 <filename>meta/lib/oetest.py</filename>.
12182 This base class offers some helper attributes, which are
12183 described in the following sections:
12184 </para>
12185
12186 <section id='qemu-image-writing-tests-class-methods'>
12187 <title>Class Methods</title>
12188
12189 <para>
12190 Class methods are as follows:
12191 <itemizedlist>
12192 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12193 Returns "True" if <filename>pkg</filename> is in the
12194 installed package list of the image, which is based
12195 on the manifest file that is generated during the
12196 <filename>do_rootfs</filename> task.
12197 </para></listitem>
12198 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12199 Returns "True" if the feature is in
12200 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12201 or
12202 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12203 </para></listitem>
12204 </itemizedlist>
12205 </para>
12206 </section>
12207
12208 <section id='qemu-image-writing-tests-class-attributes'>
12209 <title>Class Attributes</title>
12210
12211 <para>
12212 Class attributes are as follows:
12213 <itemizedlist>
12214 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12215 Equals "ps -ef" if <filename>procps</filename> is
12216 installed in the image.
12217 Otherwise, <filename>pscmd</filename> equals
12218 "ps" (busybox).
12219 </para></listitem>
12220 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12221 The called test context, which gives access to the
12222 following attributes:
12223 <itemizedlist>
12224 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12225 The BitBake datastore, which allows you to
12226 use stuff such as
12227 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12228 </para></listitem>
12229 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12230 Used internally.
12231 The tests do not need these.
12232 </para></listitem>
12233 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12234 The absolute path to
12235 <filename>meta/lib/oeqa/runtime/files</filename>,
12236 which contains helper files for tests meant
12237 for copying on the target such as small
12238 files written in C for compilation.
12239 </para></listitem>
12240 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12241 The target controller object used to deploy
12242 and start an image on a particular target
12243 (e.g. QemuTarget, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012244 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012245 Tests usually use the following:
12246 <itemizedlist>
12247 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12248 The target's IP address.
12249 </para></listitem>
12250 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12251 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012252 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012253 suite.
12254 </para></listitem>
12255 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12256 The single, most used method.
12257 This command is a wrapper for:
12258 <filename>ssh root@host "cmd"</filename>.
12259 The command returns a tuple:
12260 (status, output), which are what
12261 their names imply - the return code
12262 of "cmd" and whatever output
12263 it produces.
12264 The optional timeout argument
12265 represents the number of seconds the
12266 test should wait for "cmd" to
12267 return.
12268 If the argument is "None", the
12269 test uses the default instance's
12270 timeout period, which is 300
12271 seconds.
12272 If the argument is "0", the test
12273 runs until the command returns.
12274 </para></listitem>
12275 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12276 <filename>scp localpath root@ip:remotepath</filename>.
12277 </para></listitem>
12278 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12279 <filename>scp root@host:remotepath localpath</filename>.
12280 </para></listitem>
12281 </itemizedlist></para></listitem>
12282 </itemizedlist></para></listitem>
12283 </itemizedlist>
12284 </para>
12285 </section>
12286
12287 <section id='qemu-image-writing-tests-instance-attributes'>
12288 <title>Instance Attributes</title>
12289
12290 <para>
12291 A single instance attribute exists, which is
12292 <filename>target</filename>.
12293 The <filename>target</filename> instance attribute is
12294 identical to the class attribute of the same name, which
12295 is described in the previous section.
12296 This attribute exists as both an instance and class
12297 attribute so tests can use
12298 <filename>self.target.run(cmd)</filename> in instance
12299 methods instead of
12300 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12301 </para>
12302 </section>
12303 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012304
12305 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12306 <title>Installing Packages in the DUT Without the Package Manager</title>
12307
12308 <para>
12309 When a test requires a package built by BitBake, it is possible
12310 to install that package.
12311 Installing the package does not require a package manager be
12312 installed in the device under test (DUT).
12313 It does, however, require an SSH connection and the target must
12314 be using the <filename>sshcontrol</filename> class.
12315 <note>
12316 This method uses <filename>scp</filename> to copy files
12317 from the host to the target, which causes permissions and
12318 special attributes to be lost.
12319 </note>
12320 </para>
12321
12322 <para>
12323 A JSON file is used to define the packages needed by a test.
12324 This file must be in the same path as the file used to define
12325 the tests.
12326 Furthermore, the filename must map directly to the test
12327 module name with a <filename>.json</filename> extension.
12328 </para>
12329
12330 <para>
12331 The JSON file must include an object with the test name as
12332 keys of an object or an array.
12333 This object (or array of objects) uses the following data:
12334 <itemizedlist>
12335 <listitem><para>"pkg" - A mandatory string that is the
12336 name of the package to be installed.
12337 </para></listitem>
12338 <listitem><para>"rm" - An optional boolean, which defaults
12339 to "false", that specifies to remove the package after
12340 the test.
12341 </para></listitem>
12342 <listitem><para>"extract" - An optional boolean, which
12343 defaults to "false", that specifies if the package must
12344 be extracted from the package format.
12345 When set to "true", the package is not automatically
12346 installed into the DUT.
12347 </para></listitem>
12348 </itemizedlist>
12349 </para>
12350
12351 <para>
12352 Following is an example JSON file that handles test "foo"
12353 installing package "bar" and test "foobar" installing
12354 packages "foo" and "bar".
12355 Once the test is complete, the packages are removed from the
12356 DUT.
12357 <literallayout class='monospaced'>
12358 {
12359 "foo": {
12360 "pkg": "bar"
12361 },
12362 "foobar": [
12363 {
12364 "pkg": "foo",
12365 "rm": true
12366 },
12367 {
12368 "pkg": "bar",
12369 "rm": true
12370 }
12371 ]
12372 }
12373 </literallayout>
12374 </para>
12375 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012376 </section>
12377
Brad Bishop316dfdd2018-06-25 12:45:53 -040012378 <section id='usingpoky-debugging-tools-and-techniques'>
12379 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012380
12381 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012382 The exact method for debugging build failures depends on the nature
12383 of the problem and on the system's area from which the bug
12384 originates.
12385 Standard debugging practices such as comparison against the last
12386 known working version with examination of the changes and the
12387 re-application of steps to identify the one causing the problem are
12388 valid for the Yocto Project just as they are for any other system.
12389 Even though it is impossible to detail every possible potential
12390 failure, this section provides some general tips to aid in
12391 debugging given a variety of situations.
12392 <note><title>Tip</title>
12393 A useful feature for debugging is the error reporting tool.
12394 Configuring the Yocto Project to use this tool causes the
12395 OpenEmbedded build system to produce error reporting commands as
12396 part of the console output.
12397 You can enter the commands after the build completes to log
12398 error information into a common database, that can help you
12399 figure out what might be going wrong.
12400 For information on how to enable and use this feature, see the
12401 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12402 section.
12403 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012404 </para>
12405
12406 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012407 The following list shows the debugging topics in the remainder of
12408 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012409 <itemizedlist>
12410 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012411 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12412 describes how to find and view logs from tasks that
12413 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012414 </para></listitem>
12415 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012416 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12417 describes how to use the BitBake <filename>-e</filename>
12418 option to examine variable values after a recipe has been
12419 parsed.
12420 </para></listitem>
12421 <listitem><para>
12422 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12423 describes how to use the
12424 <filename>oe-pkgdata-util</filename> utility to query
12425 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12426 and display package-related information for built
12427 packages.
12428 </para></listitem>
12429 <listitem><para>
12430 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12431 describes how to use the BitBake <filename>-g</filename>
12432 option to display recipe dependency information used
12433 during the build.
12434 </para></listitem>
12435 <listitem><para>
12436 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12437 describes how to use the
12438 <filename>bitbake-dumpsig</filename> command in
12439 conjunction with key subdirectories in the
12440 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12441 to determine variable dependencies.
12442 </para></listitem>
12443 <listitem><para>
12444 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12445 describes how to use several BitBake options (e.g.
12446 <filename>-c</filename>, <filename>-C</filename>, and
12447 <filename>-f</filename>) to run specific tasks in the
12448 build chain.
12449 It can be useful to run tasks "out-of-order" when trying
12450 isolate build issues.
12451 </para></listitem>
12452 <listitem><para>
12453 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12454 describes how to use BitBake's <filename>-D</filename>
12455 debug output option to reveal more about what BitBake is
12456 doing during the build.
12457 </para></listitem>
12458 <listitem><para>
12459 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12460 describes how to use the BitBake <filename>-b</filename>
12461 option to build a recipe while ignoring dependencies.
12462 </para></listitem>
12463 <listitem><para>
12464 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12465 describes how to use the many recipe logging functions
12466 to produce debugging output and report errors and warnings.
12467 </para></listitem>
12468 <listitem><para>
12469 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12470 describes how to debug situations where the build consists
12471 of several parts that are run simultaneously and when the
12472 output or result of one part is not ready for use with a
12473 different part of the build that depends on that output.
12474 </para></listitem>
12475 <listitem><para>
12476 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12477 describes how to use GDB to allow you to examine running
12478 programs, which can help you fix problems.
12479 </para></listitem>
12480 <listitem><para>
12481 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12482 describes how to use GDB directly on target hardware for
12483 debugging.
12484 </para></listitem>
12485 <listitem><para>
12486 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12487 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012488 </para></listitem>
12489 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012490 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012491
12492 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012493 For debugging information within the popular
12494 <trademark class='trade'>Eclipse</trademark> IDE, see the
12495 "<ulink url='&YOCTO_DOCS_SDK_URL;#adt-eclipse'>Working within Eclipse</ulink>"
12496 section in the Yocto Project Application Development and the
12497 Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012498 </para>
12499
Brad Bishop316dfdd2018-06-25 12:45:53 -040012500 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12501 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012502
12503 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012504 You can find the log for a task in the file
12505 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12506 For example, the log for the
12507 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12508 task of the QEMU minimal image for the x86 machine
12509 (<filename>qemux86</filename>) might be in
12510 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12511 To see the commands
12512 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12513 ran to generate a log, look at the corresponding
12514 <filename>run.do_</filename><replaceable>taskname</replaceable>
12515 file in the same directory.
12516 </para>
12517
12518 <para>
12519 <filename>log.do_</filename><replaceable>taskname</replaceable>
12520 and
12521 <filename>run.do_</filename><replaceable>taskname</replaceable>
12522 are actually symbolic links to
12523 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12524 and
12525 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12526 where <replaceable>pid</replaceable> is the PID the task had
12527 when it ran.
12528 The symlinks always point to the files corresponding to the most
12529 recent run.
12530 </para>
12531 </section>
12532
12533 <section id='dev-debugging-viewing-variable-values'>
12534 <title>Viewing Variable Values</title>
12535
12536 <para>
12537 BitBake's <filename>-e</filename> option is used to display
12538 variable values after parsing.
12539 The following command displays the variable values after the
12540 configuration files (i.e. <filename>local.conf</filename>,
12541 <filename>bblayers.conf</filename>,
12542 <filename>bitbake.conf</filename> and so forth) have been
12543 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012544 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012545 $ bitbake -e
12546 </literallayout>
12547 The following command displays variable values after a specific
12548 recipe has been parsed.
12549 The variables include those from the configuration as well:
12550 <literallayout class='monospaced'>
12551 $ bitbake -e recipename
12552 </literallayout>
12553 <note><para>
12554 Each recipe has its own private set of variables
12555 (datastore).
12556 Internally, after parsing the configuration, a copy of the
12557 resulting datastore is made prior to parsing each recipe.
12558 This copying implies that variables set in one recipe will
12559 not be visible to other recipes.</para>
12560
12561 <para>Likewise, each task within a recipe gets a private
12562 datastore based on the recipe datastore, which means that
12563 variables set within one task will not be visible to
12564 other tasks.</para>
12565 </note>
12566 </para>
12567
12568 <para>
12569 In the output of <filename>bitbake -e</filename>, each
12570 variable is preceded by a description of how the variable
12571 got its value, including temporary values that were later
12572 overriden.
12573 This description also includes variable flags (varflags) set on
12574 the variable.
12575 The output can be very helpful during debugging.
12576 </para>
12577
12578 <para>
12579 Variables that are exported to the environment are preceded by
12580 <filename>export</filename> in the output of
12581 <filename>bitbake -e</filename>.
12582 See the following example:
12583 <literallayout class='monospaced'>
12584 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12585 </literallayout>
12586 </para>
12587
12588 <para>
12589 In addition to variable values, the output of the
12590 <filename>bitbake -e</filename> and
12591 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12592 commands includes the following information:
12593 <itemizedlist>
12594 <listitem><para>
12595 The output starts with a tree listing all configuration
12596 files and classes included globally, recursively listing
12597 the files they include or inherit in turn.
12598 Much of the behavior of the OpenEmbedded build system
12599 (including the behavior of the
12600 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12601 is implemented in the
12602 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12603 class and the classes it inherits, rather than being
12604 built into BitBake itself.
12605 </para></listitem>
12606 <listitem><para>
12607 After the variable values, all functions appear in the
12608 output.
12609 For shell functions, variables referenced within the
12610 function body are expanded.
12611 If a function has been modified using overrides or
12612 using override-style operators like
12613 <filename>_append</filename> and
12614 <filename>_prepend</filename>, then the final assembled
12615 function body appears in the output.
12616 </para></listitem>
12617 </itemizedlist>
12618 </para>
12619 </section>
12620
12621 <section id='viewing-package-information-with-oe-pkgdata-util'>
12622 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12623
12624 <para>
12625 You can use the <filename>oe-pkgdata-util</filename>
12626 command-line utility to query
12627 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12628 and display various package-related information.
12629 When you use the utility, you must use it to view information
12630 on packages that have already been built.
12631 </para>
12632
12633 <para>
12634 Following are a few of the available
12635 <filename>oe-pkgdata-util</filename> subcommands.
12636 <note>
12637 You can use the standard * and ? globbing wildcards as part
12638 of package names and paths.
12639 </note>
12640 <itemizedlist>
12641 <listitem><para>
12642 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12643 Lists all packages that have been built, optionally
12644 limiting the match to packages that match
12645 <replaceable>pattern</replaceable>.
12646 </para></listitem>
12647 <listitem><para>
12648 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12649 Lists the files and directories contained in the given
12650 packages.
12651 <note>
12652 <para>
12653 A different way to view the contents of a package is
12654 to look at the
12655 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12656 directory of the recipe that generates the
12657 package.
12658 This directory is created by the
12659 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12660 task and has one subdirectory for each package the
12661 recipe generates, which contains the files stored in
12662 that package.</para>
12663 <para>
12664 If you want to inspect the
12665 <filename>${WORKDIR}/packages-split</filename>
12666 directory, make sure that
12667 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12668 is not enabled when you build the recipe.
12669 </para>
12670 </note>
12671 </para></listitem>
12672 <listitem><para>
12673 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12674 Lists the names of the packages that contain the given
12675 paths.
12676 For example, the following tells us that
12677 <filename>/usr/share/man/man1/make.1</filename>
12678 is contained in the <filename>make-doc</filename>
12679 package:
12680 <literallayout class='monospaced'>
12681 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12682 make-doc: /usr/share/man/man1/make.1
12683 </literallayout>
12684 </para></listitem>
12685 <listitem><para>
12686 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12687 Lists the name of the recipes that
12688 produce the given packages.
12689 </para></listitem>
12690 </itemizedlist>
12691 </para>
12692
12693 <para>
12694 For more information on the <filename>oe-pkgdata-util</filename>
12695 command, use the help facility:
12696 <literallayout class='monospaced'>
12697 $ oe-pkgdata-util &dash;&dash;help
12698 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
12699 </literallayout>
12700 </para>
12701 </section>
12702
12703 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
12704 <title>Viewing Dependencies Between Recipes and Tasks</title>
12705
12706 <para>
12707 Sometimes it can be hard to see why BitBake wants to build other
12708 recipes before the one you have specified.
12709 Dependency information can help you understand why a recipe is
12710 built.
12711 </para>
12712
12713 <para>
12714 To generate dependency information for a recipe, run the
12715 following command:
12716 <literallayout class='monospaced'>
12717 $ bitbake -g <replaceable>recipename</replaceable>
12718 </literallayout>
12719 This command writes the following files in the current
12720 directory:
12721 <itemizedlist>
12722 <listitem><para>
12723 <filename>pn-buildlist</filename>: A list of
12724 recipes/targets involved in building
12725 <replaceable>recipename</replaceable>.
12726 "Involved" here means that at least one task from the
12727 recipe needs to run when building
12728 <replaceable>recipename</replaceable> from scratch.
12729 Targets that are in
12730 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
12731 are not listed.
12732 </para></listitem>
12733 <listitem><para>
12734 <filename>task-depends.dot</filename>: A graph showing
12735 dependencies between tasks.
12736 </para></listitem>
12737 </itemizedlist>
12738 </para>
12739
12740 <para>
12741 The graphs are in
12742 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
12743 format and can be converted to images (e.g. using the
12744 <filename>dot</filename> tool from
12745 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
12746 <note><title>Notes</title>
12747 <itemizedlist>
12748 <listitem><para>
12749 DOT files use a plain text format.
12750 The graphs generated using the
12751 <filename>bitbake -g</filename> command are often so
12752 large as to be difficult to read without special
12753 pruning (e.g. with Bitbake's
12754 <filename>-I</filename> option) and processing.
12755 Despite the form and size of the graphs, the
12756 corresponding <filename>.dot</filename> files can
12757 still be possible to read and provide useful
12758 information.
12759 </para>
12760
12761 <para>As an example, the
12762 <filename>task-depends.dot</filename> file contains
12763 lines such as the following:
12764 <literallayout class='monospaced'>
12765 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
12766 </literallayout>
12767 The above example line reveals that the
12768 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
12769 task in <filename>libxslt</filename> depends on the
12770 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
12771 task in <filename>libxml2</filename>, which is a
12772 normal
12773 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
12774 dependency between the two recipes.
12775 </para></listitem>
12776 <listitem><para>
12777 For an example of how <filename>.dot</filename>
12778 files can be processed, see the
12779 <filename>scripts/contrib/graph-tool</filename>
12780 Python script, which finds and displays paths
12781 between graph nodes.
12782 </para></listitem>
12783 </itemizedlist>
12784 </note>
12785 </para>
12786
12787 <para>
12788 You can use a different method to view dependency information
12789 by using the following command:
12790 <literallayout class='monospaced'>
12791 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
12792 </literallayout>
12793 This command displays a GUI window from which you can view
12794 build-time and runtime dependencies for the recipes involved in
12795 building <replaceable>recipename</replaceable>.
12796 </para>
12797 </section>
12798
12799 <section id='dev-viewing-task-variable-dependencies'>
12800 <title>Viewing Task Variable Dependencies</title>
12801
12802 <para>
12803 As mentioned in the
12804 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
12805 section of the BitBake User Manual, BitBake tries to
12806 automatically determine what variables a task depends on so
12807 that it can rerun the task if any values of the variables
12808 change.
12809 This determination is usually reliable.
12810 However, if you do things like construct variable names at
12811 runtime, then you might have to manually declare dependencies
12812 on those variables using <filename>vardeps</filename> as
12813 described in the
12814 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
12815 section of the BitBake User Manual.
12816 </para>
12817
12818 <para>
12819 If you are unsure whether a variable dependency is being
12820 picked up automatically for a given task, you can list the
12821 variable dependencies BitBake has determined by doing the
12822 following:
12823 <orderedlist>
12824 <listitem><para>
12825 Build the recipe containing the task:
12826 <literallayout class='monospaced'>
12827 $ bitbake <replaceable>recipename</replaceable>
12828 </literallayout>
12829 </para></listitem>
12830 <listitem><para>
12831 Inside the
12832 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
12833 directory, find the signature data
12834 (<filename>sigdata</filename>) file that corresponds
12835 to the task.
12836 The <filename>sigdata</filename> files contain a pickled
12837 Python database of all the metadata that went into
12838 creating the input checksum for the task.
12839 As an example, for the
12840 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
12841 task of the <filename>db</filename> recipe, the
12842 <filename>sigdata</filename> file might be found in the
12843 following location:
12844 <literallayout class='monospaced'>
12845 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12846 </literallayout>
12847 For tasks that are accelerated through the shared state
12848 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
12849 cache, an additional <filename>siginfo</filename> file
12850 is written into
12851 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
12852 along with the cached task output.
12853 The <filename>siginfo</filename> files contain exactly
12854 the same information as <filename>sigdata</filename>
12855 files.
12856 </para></listitem>
12857 <listitem><para>
12858 Run <filename>bitbake-dumpsig</filename> on the
12859 <filename>sigdata</filename> or
12860 <filename>siginfo</filename> file.
12861 Here is an example:
12862 <literallayout class='monospaced'>
12863 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12864 </literallayout>
12865 In the output of the above command, you will find a
12866 line like the following, which lists all the (inferred)
12867 variable dependencies for the task.
12868 This list also includes indirect dependencies from
12869 variables depending on other variables, recursively.
12870 <literallayout class='monospaced'>
12871 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
12872 </literallayout>
12873 <note>
12874 Functions (e.g. <filename>base_do_fetch</filename>)
12875 also count as variable dependencies.
12876 These functions in turn depend on the variables they
12877 reference.
12878 </note>
12879 The output of <filename>bitbake-dumpsig</filename> also
12880 includes the value each variable had, a list of
12881 dependencies for each variable, and
12882 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
12883 information.
12884 </para></listitem>
12885 </orderedlist>
12886 </para>
12887
12888 <para>
12889 There is also a <filename>bitbake-diffsigs</filename> command
12890 for comparing two <filename>siginfo</filename> or
12891 <filename>sigdata</filename> files.
12892 This command can be helpful when trying to figure out what
12893 changed between two versions of a task.
12894 If you call <filename>bitbake-diffsigs</filename> with just one
12895 file, the command behaves like
12896 <filename>bitbake-dumpsig</filename>.
12897 </para>
12898
12899 <para>
12900 You can also use BitBake to dump out the signature construction
12901 information without executing tasks by using either of the
12902 following BitBake command-line options:
12903 <literallayout class='monospaced'>
12904 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
12905 -S <replaceable>SIGNATURE_HANDLER</replaceable>
12906 </literallayout>
12907 <note>
12908 Two common values for
12909 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
12910 "printdiff", which dump only the signature or compare the
12911 dumped signature with the cached one, respectively.
12912 </note>
12913 Using BitBake with either of these options causes BitBake to
12914 dump out <filename>sigdata</filename> files in the
12915 <filename>stamps</filename> directory for every task it would
12916 have executed instead of building the specified target package.
12917 </para>
12918 </section>
12919
12920 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
12921 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
12922
12923 <para>
12924 Seeing what metadata went into creating the input signature
12925 of a shared state (sstate) task can be a useful debugging
12926 aid.
12927 This information is available in signature information
12928 (<filename>siginfo</filename>) files in
12929 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
12930 For information on how to view and interpret information in
12931 <filename>siginfo</filename> files, see the
12932 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12933 section.
12934 </para>
12935
12936 <para>
12937 For conceptual information on shared state, see the
12938 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
12939 section in the Yocto Project Overview and Concepts Manual.
12940 </para>
12941 </section>
12942
12943 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
12944 <title>Invalidating Shared State to Force a Task to Run</title>
12945
12946 <para>
12947 The OpenEmbedded build system uses
12948 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
12949 and
12950 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
12951 cache to avoid unnecessarily rebuilding tasks.
12952 Collectively, this scheme is known as "shared state code."
12953 </para>
12954
12955 <para>
12956 As with all schemes, this one has some drawbacks.
12957 It is possible that you could make implicit changes to your
12958 code that the checksum calculations do not take into
12959 account.
12960 These implicit changes affect a task's output but do not
12961 trigger the shared state code into rebuilding a recipe.
12962 Consider an example during which a tool changes its output.
12963 Assume that the output of <filename>rpmdeps</filename>
12964 changes.
12965 The result of the change should be that all the
12966 <filename>package</filename> and
12967 <filename>package_write_rpm</filename> shared state cache
12968 items become invalid.
12969 However, because the change to the output is
12970 external to the code and therefore implicit,
12971 the associated shared state cache items do not become
12972 invalidated.
12973 In this case, the build process uses the cached items
12974 rather than running the task again.
12975 Obviously, these types of implicit changes can cause
12976 problems.
12977 </para>
12978
12979 <para>
12980 To avoid these problems during the build, you need to
12981 understand the effects of any changes you make.
12982 Realize that changes you make directly to a function
12983 are automatically factored into the checksum calculation.
12984 Thus, these explicit changes invalidate the associated
12985 area of shared state cache.
12986 However, you need to be aware of any implicit changes that
12987 are not obvious changes to the code and could affect
12988 the output of a given task.
12989 </para>
12990
12991 <para>
12992 When you identify an implicit change, you can easily
12993 take steps to invalidate the cache and force the tasks
12994 to run.
12995 The steps you can take are as simple as changing a
12996 function's comments in the source code.
12997 For example, to invalidate package shared state files,
12998 change the comment statements of
12999 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13000 or the comments of one of the functions it calls.
13001 Even though the change is purely cosmetic, it causes the
13002 checksum to be recalculated and forces the build system to
13003 run the task again.
13004 <note>
13005 For an example of a commit that makes a cosmetic
13006 change to invalidate shared state, see this
13007 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
13008 </note>
13009 </para>
13010 </section>
13011
13012 <section id='dev-debugging-taskrunning'>
13013 <title>Running Specific Tasks</title>
13014
13015 <para>
13016 Any given recipe consists of a set of tasks.
13017 The standard BitBake behavior in most cases is:
13018 <filename>do_fetch</filename>,
13019 <filename>do_unpack</filename>,
13020 <filename>do_patch</filename>,
13021 <filename>do_configure</filename>,
13022 <filename>do_compile</filename>,
13023 <filename>do_install</filename>,
13024 <filename>do_package</filename>,
13025 <filename>do_package_write_*</filename>, and
13026 <filename>do_build</filename>.
13027 The default task is <filename>do_build</filename> and any tasks
13028 on which it depends build first.
13029 Some tasks, such as <filename>do_devshell</filename>, are not
13030 part of the default build chain.
13031 If you wish to run a task that is not part of the default build
13032 chain, you can use the <filename>-c</filename> option in
13033 BitBake.
13034 Here is an example:
13035 <literallayout class='monospaced'>
13036 $ bitbake matchbox-desktop -c devshell
13037 </literallayout>
13038 </para>
13039
13040 <para>
13041 The <filename>-c</filename> option respects task dependencies,
13042 which means that all other tasks (including tasks from other
13043 recipes) that the specified task depends on will be run before
13044 the task.
13045 Even when you manually specify a task to run with
13046 <filename>-c</filename>, BitBake will only run the task if it
13047 considers it "out of date".
13048 See the
13049 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
13050 section in the Yocto Project Overview and Concepts Manual for
13051 how BitBake determines whether a task is "out of date".
13052 </para>
13053
13054 <para>
13055 If you want to force an up-to-date task to be rerun (e.g.
13056 because you made manual modifications to the recipe's
13057 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
13058 that you want to try out), then you can use the
13059 <filename>-f</filename> option.
13060 <note>
13061 The reason <filename>-f</filename> is never required when
13062 running the
13063 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
13064 task is because the
13065 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
13066 variable flag is already set for the task.
13067 </note>
13068 The following example shows one way you can use the
13069 <filename>-f</filename> option:
13070 <literallayout class='monospaced'>
13071 $ bitbake matchbox-desktop
13072 .
13073 .
13074 make some changes to the source code in the work directory
13075 .
13076 .
13077 $ bitbake matchbox-desktop -c compile -f
13078 $ bitbake matchbox-desktop
13079 </literallayout>
13080 </para>
13081
13082 <para>
13083 This sequence first builds and then recompiles
13084 <filename>matchbox-desktop</filename>.
13085 The last command reruns all tasks (basically the packaging
13086 tasks) after the compile.
13087 BitBake recognizes that the <filename>do_compile</filename>
13088 task was rerun and therefore understands that the other tasks
13089 also need to be run again.
13090 </para>
13091
13092 <para>
13093 Another, shorter way to rerun a task and all
13094 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
13095 that depend on it is to use the <filename>-C</filename>
13096 option.
13097 <note>
13098 This option is upper-cased and is separate from the
13099 <filename>-c</filename> option, which is lower-cased.
13100 </note>
13101 Using this option invalidates the given task and then runs the
13102 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
13103 task, which is the default task if no task is given, and the
13104 tasks on which it depends.
13105 You could replace the final two commands in the previous example
13106 with the following single command:
13107 <literallayout class='monospaced'>
13108 $ bitbake matchbox-desktop -C compile
13109 </literallayout>
13110 Internally, the <filename>-f</filename> and
13111 <filename>-C</filename> options work by tainting (modifying) the
13112 input checksum of the specified task.
13113 This tainting indirectly causes the task and its
13114 dependent tasks to be rerun through the normal task dependency
13115 mechanisms.
13116 <note>
13117 BitBake explicitly keeps track of which tasks have been
13118 tainted in this fashion, and will print warnings such as the
13119 following for builds involving such tasks:
13120 <literallayout class='monospaced'>
13121 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
13122 </literallayout>
13123 The purpose of the warning is to let you know that the work
13124 directory and build output might not be in the clean state
13125 they would be in for a "normal" build, depending on what
13126 actions you took.
13127 To get rid of such warnings, you can remove the work
13128 directory and rebuild the recipe, as follows:
13129 <literallayout class='monospaced'>
13130 $ bitbake matchbox-desktop -c clean
13131 $ bitbake matchbox-desktop
13132 </literallayout>
13133 </note>
13134 </para>
13135
13136 <para>
13137 You can view a list of tasks in a given package by running the
13138 <filename>do_listtasks</filename> task as follows:
13139 <literallayout class='monospaced'>
13140 $ bitbake matchbox-desktop -c listtasks
13141 </literallayout>
13142 The results appear as output to the console and are also in the
13143 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
13144 </para>
13145 </section>
13146
13147 <section id='dev-debugging-bitbake'>
13148 <title>General BitBake Problems</title>
13149
13150 <para>
13151 You can see debug output from BitBake by using the
13152 <filename>-D</filename> option.
13153 The debug output gives more information about what BitBake
13154 is doing and the reason behind it.
13155 Each <filename>-D</filename> option you use increases the
13156 logging level.
13157 The most common usage is <filename>-DDD</filename>.
13158 </para>
13159
13160 <para>
13161 The output from
13162 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
13163 can reveal why BitBake chose a certain version of a package or
13164 why BitBake picked a certain provider.
13165 This command could also help you in a situation where you think
13166 BitBake did something unexpected.
13167 </para>
13168 </section>
13169
13170 <section id='dev-debugging-buildfile'>
13171 <title>Building with No Dependencies</title>
13172
13173 <para>
13174 To build a specific recipe (<filename>.bb</filename> file),
13175 you can use the following command form:
13176 <literallayout class='monospaced'>
13177 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13178 </literallayout>
13179 This command form does not check for dependencies.
13180 Consequently, you should use it only when you know existing
13181 dependencies have been met.
13182 <note>
13183 You can also specify fragments of the filename.
13184 In this case, BitBake checks for a unique match.
13185 </note>
13186 </para>
13187 </section>
13188
13189 <section id='recipe-logging-mechanisms'>
13190 <title>Recipe Logging Mechanisms</title>
13191
13192 <para>
13193 The Yocto Project provides several logging functions for
13194 producing debugging output and reporting errors and warnings.
13195 For Python functions, the following logging functions exist.
13196 All of these functions log to
13197 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13198 and can also log to standard output (stdout) with the right
13199 settings:
13200 <itemizedlist>
13201 <listitem><para>
13202 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13203 Writes <replaceable>msg</replaceable> as is to the
13204 log while also logging to stdout.
13205 </para></listitem>
13206 <listitem><para>
13207 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13208 Writes "NOTE: <replaceable>msg</replaceable>" to the
13209 log.
13210 Also logs to stdout if BitBake is called with "-v".
13211 </para></listitem>
13212 <listitem><para>
13213 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13214 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13215 log.
13216 Also logs to stdout if the log level is greater than or
13217 equal to <replaceable>level</replaceable>.
13218 See the
13219 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13220 option in the BitBake User Manual for more information.
13221 </para></listitem>
13222 <listitem><para>
13223 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13224 Writes "WARNING: <replaceable>msg</replaceable>" to the
13225 log while also logging to stdout.
13226 </para></listitem>
13227 <listitem><para>
13228 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13229 Writes "ERROR: <replaceable>msg</replaceable>" to the
13230 log while also logging to standard out (stdout).
13231 <note>
13232 Calling this function does not cause the task to fail.
13233 </note>
13234 </para></listitem>
13235 <listitem><para>
13236 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13237 This logging function is similar to
13238 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13239 but also causes the calling task to fail.
13240 <note>
13241 <filename>bb.fatal()</filename> raises an exception,
13242 which means you do not need to put a "return"
13243 statement after the function.
13244 </note>
13245 </para></listitem>
13246 </itemizedlist>
13247 </para>
13248
13249 <para>
13250 The same logging functions are also available in shell
13251 functions, under the names
13252 <filename>bbplain</filename>, <filename>bbnote</filename>,
13253 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13254 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13255 The
13256 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13257 class implements these functions.
13258 See that class in the
13259 <filename>meta/classes</filename> folder of the
13260 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13261 for information.
13262 </para>
13263
13264 <section id='logging-with-python'>
13265 <title>Logging With Python</title>
13266
13267 <para>
13268 When creating recipes using Python and inserting code that
13269 handles build logs, keep in mind the goal is to have
13270 informative logs while keeping the console as "silent" as
13271 possible.
13272 Also, if you want status messages in the log, use the
13273 "debug" loglevel.
13274 </para>
13275
13276 <para>
13277 Following is an example written in Python.
13278 The code handles logging for a function that determines the
13279 number of tasks needed to be run.
13280 See the
13281 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13282 section for additional information:
13283 <literallayout class='monospaced'>
13284 python do_listtasks() {
13285 bb.debug(2, "Starting to figure out the task list")
13286 if noteworthy_condition:
13287 bb.note("There are 47 tasks to run")
13288 bb.debug(2, "Got to point xyz")
13289 if warning_trigger:
13290 bb.warn("Detected warning_trigger, this might be a problem later.")
13291 if recoverable_error:
13292 bb.error("Hit recoverable_error, you really need to fix this!")
13293 if fatal_error:
13294 bb.fatal("fatal_error detected, unable to print the task list")
13295 bb.plain("The tasks present are abc")
13296 bb.debug(2, "Finished figuring out the tasklist")
13297 }
13298 </literallayout>
13299 </para>
13300 </section>
13301
13302 <section id='logging-with-bash'>
13303 <title>Logging With Bash</title>
13304
13305 <para>
13306 When creating recipes using Bash and inserting code that
13307 handles build logs, you have the same goals - informative
13308 with minimal console output.
13309 The syntax you use for recipes written in Bash is similar
13310 to that of recipes written in Python described in the
13311 previous section.
13312 </para>
13313
13314 <para>
13315 Following is an example written in Bash.
13316 The code logs the progress of the <filename>do_my_function</filename> function.
13317 <literallayout class='monospaced'>
13318 do_my_function() {
13319 bbdebug 2 "Running do_my_function"
13320 if [ exceptional_condition ]; then
13321 bbnote "Hit exceptional_condition"
13322 fi
13323 bbdebug 2 "Got to point xyz"
13324 if [ warning_trigger ]; then
13325 bbwarn "Detected warning_trigger, this might cause a problem later."
13326 fi
13327 if [ recoverable_error ]; then
13328 bberror "Hit recoverable_error, correcting"
13329 fi
13330 if [ fatal_error ]; then
13331 bbfatal "fatal_error detected"
13332 fi
13333 bbdebug 2 "Completed do_my_function"
13334 }
13335 </literallayout>
13336 </para>
13337 </section>
13338 </section>
13339
13340 <section id='debugging-parallel-make-races'>
13341 <title>Debugging Parallel Make Races</title>
13342
13343 <para>
13344 A parallel <filename>make</filename> race occurs when the build
13345 consists of several parts that are run simultaneously and
13346 a situation occurs when the output or result of one
13347 part is not ready for use with a different part of the build
13348 that depends on that output.
13349 Parallel make races are annoying and can sometimes be difficult
13350 to reproduce and fix.
13351 However, some simple tips and tricks exist that can help
13352 you debug and fix them.
13353 This section presents a real-world example of an error
13354 encountered on the Yocto Project autobuilder and the process
13355 used to fix it.
13356 <note>
13357 If you cannot properly fix a <filename>make</filename> race
13358 condition, you can work around it by clearing either the
13359 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13360 or
13361 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13362 variables.
13363 </note>
13364 </para>
13365
13366 <section id='the-failure'>
13367 <title>The Failure</title>
13368
13369 <para>
13370 For this example, assume that you are building an image that
13371 depends on the "neard" package.
13372 And, during the build, BitBake runs into problems and
13373 creates the following output.
13374 <note>
13375 This example log file has longer lines artificially
13376 broken to make the listing easier to read.
13377 </note>
13378 If you examine the output or the log file, you see the
13379 failure during <filename>make</filename>:
13380 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013381 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13382 | DEBUG: Executing shell function do_compile
13383 | NOTE: make -j 16
13384 | make --no-print-directory all-am
13385 | /bin/mkdir -p include/near
13386 | /bin/mkdir -p include/near
13387 | /bin/mkdir -p include/near
13388 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13389 0.14-r0/neard-0.14/include/types.h include/near/types.h
13390 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13391 0.14-r0/neard-0.14/include/log.h include/near/log.h
13392 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13393 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13394 | /bin/mkdir -p include/near
13395 | /bin/mkdir -p include/near
13396 | /bin/mkdir -p include/near
13397 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13398 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13399 | /bin/mkdir -p include/near
13400 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13401 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13402 | /bin/mkdir -p include/near
13403 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13404 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13405 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13406 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13407 | /bin/mkdir -p include/near
13408 | /bin/mkdir -p include/near
13409 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13410 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13411 | /bin/mkdir -p include/near
13412 | /bin/mkdir -p include/near
13413 | /bin/mkdir -p include/near
13414 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13415 0.14-r0/neard-0.14/include/device.h include/near/device.h
13416 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13417 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13418 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13419 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13420 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13421 0.14-r0/neard-0.14/include/version.h include/near/version.h
13422 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13423 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13424 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13425 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13426 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13427 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13428 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13429 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13430 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13431 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13432 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13433 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13434 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13435 -o tools/snep-send.o tools/snep-send.c
13436 | In file included from tools/snep-send.c:16:0:
13437 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13438 | #include &lt;near/dbus.h&gt;
13439 | ^
13440 | compilation terminated.
13441 | make[1]: *** [tools/snep-send.o] Error 1
13442 | make[1]: *** Waiting for unfinished jobs....
13443 | make: *** [all] Error 2
13444 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013445 </literallayout>
13446 </para>
13447 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013448
Brad Bishop316dfdd2018-06-25 12:45:53 -040013449 <section id='reproducing-the-error'>
13450 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013451
Brad Bishop316dfdd2018-06-25 12:45:53 -040013452 <para>
13453 Because race conditions are intermittent, they do not
13454 manifest themselves every time you do the build.
13455 In fact, most times the build will complete without problems
13456 even though the potential race condition exists.
13457 Thus, once the error surfaces, you need a way to reproduce
13458 it.
13459 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013460
Brad Bishop316dfdd2018-06-25 12:45:53 -040013461 <para>
13462 In this example, compiling the "neard" package is causing
13463 the problem.
13464 So the first thing to do is build "neard" locally.
13465 Before you start the build, set the
13466 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13467 variable in your <filename>local.conf</filename> file to
13468 a high number (e.g. "-j 20").
13469 Using a high value for <filename>PARALLEL_MAKE</filename>
13470 increases the chances of the race condition showing up:
13471 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013472 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013473 </literallayout>
13474 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013475
Brad Bishop316dfdd2018-06-25 12:45:53 -040013476 <para>
13477 Once the local build for "neard" completes, start a
13478 <filename>devshell</filename> build:
13479 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013480 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013481 </literallayout>
13482 For information on how to use a
13483 <filename>devshell</filename>, see the
13484 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13485 section.
13486 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013487
Brad Bishop316dfdd2018-06-25 12:45:53 -040013488 <para>
13489 In the <filename>devshell</filename>, do the following:
13490 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013491 $ make clean
13492 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013493 </literallayout>
13494 The <filename>devshell</filename> commands cause the failure
13495 to clearly be visible.
13496 In this case, a missing dependency exists for the "neard"
13497 Makefile target.
13498 Here is some abbreviated, sample output with the
13499 missing dependency clearly visible at the end:
13500 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013501 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13502 .
13503 .
13504 .
13505 tools/snep-send.c
13506 In file included from tools/snep-send.c:16:0:
13507 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13508 #include &lt;near/dbus.h&gt;
13509 ^
13510 compilation terminated.
13511 make: *** [tools/snep-send.o] Error 1
13512 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013513 </literallayout>
13514 </para>
13515 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013516
Brad Bishop316dfdd2018-06-25 12:45:53 -040013517 <section id='creating-a-patch-for-the-fix'>
13518 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013519
Brad Bishop316dfdd2018-06-25 12:45:53 -040013520 <para>
13521 Because there is a missing dependency for the Makefile
13522 target, you need to patch the
13523 <filename>Makefile.am</filename> file, which is generated
13524 from <filename>Makefile.in</filename>.
13525 You can use Quilt to create the patch:
13526 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013527 $ quilt new parallelmake.patch
13528 Patch patches/parallelmake.patch is now on top
13529 $ quilt add Makefile.am
13530 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013531 </literallayout>
13532 For more information on using Quilt, see the
13533 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13534 section.
13535 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013536
Brad Bishop316dfdd2018-06-25 12:45:53 -040013537 <para>
13538 At this point you need to make the edits to
13539 <filename>Makefile.am</filename> to add the missing
13540 dependency.
13541 For our example, you have to add the following line
13542 to the file:
13543 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013544 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013545 </literallayout>
13546 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013547
Brad Bishop316dfdd2018-06-25 12:45:53 -040013548 <para>
13549 Once you have edited the file, use the
13550 <filename>refresh</filename> command to create the patch:
13551 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013552 $ quilt refresh
13553 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013554 </literallayout>
13555 Once the patch file exists, you need to add it back to the
13556 originating recipe folder.
13557 Here is an example assuming a top-level
13558 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13559 named <filename>poky</filename>:
13560 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013561 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013562 </literallayout>
13563 The final thing you need to do to implement the fix in the
13564 build is to update the "neard" recipe (i.e.
13565 <filename>neard-0.14.bb</filename>) so that the
13566 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13567 statement includes the patch file.
13568 The recipe file is in the folder above the patch.
13569 Here is what the edited <filename>SRC_URI</filename>
13570 statement would look like:
13571 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013572 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13573 file://neard.in \
13574 file://neard.service.in \
13575 file://parallelmake.patch \
13576 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013577 </literallayout>
13578 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013579
Brad Bishop316dfdd2018-06-25 12:45:53 -040013580 <para>
13581 With the patch complete and moved to the correct folder and
13582 the <filename>SRC_URI</filename> statement updated, you can
13583 exit the <filename>devshell</filename>:
13584 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013585 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013586 </literallayout>
13587 </para>
13588 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013589
Brad Bishop316dfdd2018-06-25 12:45:53 -040013590 <section id='testing-the-build'>
13591 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013592
Brad Bishop316dfdd2018-06-25 12:45:53 -040013593 <para>
13594 With everything in place, you can get back to trying the
13595 build again locally:
13596 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013597 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013598 </literallayout>
13599 This build should succeed.
13600 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013601
Brad Bishop316dfdd2018-06-25 12:45:53 -040013602 <para>
13603 Now you can open up a <filename>devshell</filename> again
13604 and repeat the clean and make operations as follows:
13605 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013606 $ bitbake neard -c devshell
13607 $ make clean
13608 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013609 </literallayout>
13610 The build should work without issue.
13611 </para>
13612
13613 <para>
13614 As with all solved problems, if they originated upstream,
13615 you need to submit the fix for the recipe in OE-Core and
13616 upstream so that the problem is taken care of at its
13617 source.
13618 See the
13619 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13620 section for more information.
13621 </para>
13622 </section>
13623 </section>
13624
13625 <section id="platdev-gdb-remotedebug">
13626 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13627
13628 <para>
13629 GDB allows you to examine running programs, which in turn helps
13630 you to understand and fix problems.
13631 It also allows you to perform post-mortem style analysis of
13632 program crashes.
13633 GDB is available as a package within the Yocto Project and is
13634 installed in SDK images by default.
13635 See the
13636 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13637 chapter in the Yocto Project Reference Manual for a description of
13638 these images.
13639 You can find information on GDB at
13640 <ulink url="http://sourceware.org/gdb/"/>.
13641 <note><title>Tip</title>
13642 For best results, install debug (<filename>-dbg</filename>)
13643 packages for the applications you are going to debug.
13644 Doing so makes extra debug symbols available that give you
13645 more meaningful output.
13646 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013647 </para>
13648
13649 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013650 Sometimes, due to memory or disk space constraints, it is not
13651 possible to use GDB directly on the remote target to debug
13652 applications.
13653 These constraints arise because GDB needs to load the debugging
13654 information and the binaries of the process being debugged.
13655 Additionally, GDB needs to perform many computations to locate
13656 information such as function names, variable names and values,
13657 stack traces and so forth - even before starting the debugging
13658 process.
13659 These extra computations place more load on the target system
13660 and can alter the characteristics of the program being debugged.
13661 </para>
13662
13663 <para>
13664 To help get past the previously mentioned constraints, you can
13665 use gdbserver, which runs on the remote target and does not
13666 load any debugging information from the debugged process.
13667 Instead, a GDB instance processes the debugging information that
13668 is run on a remote computer - the host GDB.
13669 The host GDB then sends control commands to gdbserver to make
13670 it stop or start the debugged program, as well as read or write
13671 memory regions of that debugged program.
13672 All the debugging information loaded and processed as well
13673 as all the heavy debugging is done by the host GDB.
13674 Offloading these processes gives the gdbserver running on the
13675 target a chance to remain small and fast.
13676 </para>
13677
13678 <para>
13679 Because the host GDB is responsible for loading the debugging
13680 information and for doing the necessary processing to make
13681 actual debugging happen, you have to make sure the host can
13682 access the unstripped binaries complete with their debugging
13683 information and also be sure the target is compiled with no
13684 optimizations.
13685 The host GDB must also have local access to all the libraries
13686 used by the debugged program.
13687 Because gdbserver does not need any local debugging information,
13688 the binaries on the remote target can remain stripped.
13689 However, the binaries must also be compiled without optimization
13690 so they match the host's binaries.
13691 </para>
13692
13693 <para>
13694 To remain consistent with GDB documentation and terminology,
13695 the binary being debugged on the remote target machine is
13696 referred to as the "inferior" binary.
13697 For documentation on GDB see the
13698 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
13699 </para>
13700
13701 <para>
13702 The following steps show you how to debug using the GNU project
13703 debugger.
13704 <orderedlist>
13705 <listitem><para>
13706 <emphasis>Configure your build system to construct the
13707 companion debug filesystem:</emphasis></para>
13708
13709 <para>In your <filename>local.conf</filename> file, set
13710 the following:
13711 <literallayout class='monospaced'>
13712 IMAGE_GEN_DEBUGFS = "1"
13713 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
13714 </literallayout>
13715 These options cause the OpenEmbedded build system
13716 to generate a special companion filesystem fragment,
13717 which contains the matching source and debug symbols to
13718 your deployable filesystem.
13719 The build system does this by looking at what is in the
13720 deployed filesystem, and pulling the corresponding
13721 <filename>-dbg</filename> packages.</para>
13722
13723 <para>The companion debug filesystem is not a complete
13724 filesystem, but only contains the debug fragments.
13725 This filesystem must be combined with the full filesystem
13726 for debugging.
13727 Subsequent steps in this procedure show how to combine
13728 the partial filesystem with the full filesystem.
13729 </para></listitem>
13730 <listitem><para>
13731 <emphasis>Configure the system to include gdbserver in
13732 the target filesystem:</emphasis></para>
13733
13734 <para>Make the following addition in either your
13735 <filename>local.conf</filename> file or in an image
13736 recipe:
13737 <literallayout class='monospaced'>
13738 IMAGE_INSTALL_append = “ gdbserver"
13739 </literallayout>
13740 The change makes sure the <filename>gdbserver</filename>
13741 package is included.
13742 </para></listitem>
13743 <listitem><para>
13744 <emphasis>Build the environment:</emphasis></para>
13745
13746 <para>Use the following command to construct the image
13747 and the companion Debug Filesystem:
13748 <literallayout class='monospaced'>
13749 $ bitbake <replaceable>image</replaceable>
13750 </literallayout>
13751 Build the cross GDB component and make it available
13752 for debugging.
13753 Build the SDK that matches the image.
13754 Building the SDK is best for a production build
13755 that can be used later for debugging, especially
13756 during long term maintenance:
13757 <literallayout class='monospaced'>
13758 $ bitbake -c populate_sdk <replaceable>image</replaceable>
13759 </literallayout></para>
13760
13761 <para>Alternatively, you can build the minimal
13762 toolchain components that match the target.
13763 Doing so creates a smaller than typical SDK and only
13764 contains a minimal set of components with which to
13765 build simple test applications, as well as run the
13766 debugger:
13767 <literallayout class='monospaced'>
13768 $ bitbake meta-toolchain
13769 </literallayout></para>
13770
13771 <para>A final method is to build Gdb itself within
13772 the build system:
13773 <literallayout class='monospaced'>
13774 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
13775 </literallayout>
13776 Doing so produces a temporary copy of
13777 <filename>cross-gdb</filename> you can use for
13778 debugging during development.
13779 While this is the quickest approach, the two previous
13780 methods in this step are better when considering
13781 long-term maintenance strategies.
13782 <note>
13783 If you run
13784 <filename>bitbake gdb-cross</filename>, the
13785 OpenEmbedded build system suggests the actual
13786 image (e.g. <filename>gdb-cross-i586</filename>).
13787 The suggestion is usually the actual name you want
13788 to use.
13789 </note>
13790 </para></listitem>
13791 <listitem><para>
13792 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
13793
13794 <para>Run the following commands to set up the
13795 <filename>debugfs</filename>:
13796 <literallayout class='monospaced'>
13797 $ mkdir debugfs
13798 $ cd debugfs
13799 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
13800 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
13801 </literallayout>
13802 </para></listitem>
13803 <listitem><para>
13804 <emphasis>Set up GDB</emphasis></para>
13805
13806 <para>Install the SDK (if you built one) and then
13807 source the correct environment file.
13808 Sourcing the environment file puts the SDK in your
13809 <filename>PATH</filename> environment variable.</para>
13810
13811 <para>If you are using the build system, Gdb is
13812 located in
13813 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
13814 </para></listitem>
13815 <listitem><para>
13816 <emphasis>Boot the target:</emphasis></para>
13817
13818 <para>For information on how to run QEMU, see the
13819 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
13820 <note>
13821 Be sure to verify that your host can access the
13822 target via TCP.
13823 </note>
13824 </para></listitem>
13825 <listitem><para>
13826 <emphasis>Debug a program:</emphasis></para>
13827
13828 <para>Debugging a program involves running gdbserver
13829 on the target and then running Gdb on the host.
13830 The example in this step debugs
13831 <filename>gzip</filename>:
13832 <literallayout class='monospaced'>
13833 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
13834 </literallayout>
13835 For additional gdbserver options, see the
13836 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
13837 </para>
13838
13839 <para>After running gdbserver on the target, you need
13840 to run Gdb on the host and configure it and connect to
13841 the target.
13842 Use these commands:
13843 <literallayout class='monospaced'>
13844 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
13845 $ <replaceable>arch</replaceable>-gdb
13846
13847 (gdb) set sysroot debugfs
13848 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
13849 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
13850 </literallayout>
13851 At this point, everything should automatically load
13852 (i.e. matching binaries, symbols and headers).
13853 <note>
13854 The Gdb <filename>set</filename> commands in the
13855 previous example can be placed into the users
13856 <filename>~/.gdbinit</filename> file.
13857 Upon starting, Gdb automatically runs whatever
13858 commands are in that file.
13859 </note>
13860 </para></listitem>
13861 <listitem><para>
13862 <emphasis>Deploying without a full image
13863 rebuild:</emphasis></para>
13864
13865 <para>In many cases, during development you want a
13866 quick method to deploy a new binary to the target and
13867 debug it, without waiting for a full image build.
13868 </para>
13869
13870 <para>One approach to solving this situation is to
13871 just build the component you want to debug.
13872 Once you have built the component, copy the
13873 executable directly to both the target and the
13874 host <filename>debugfs</filename>.</para>
13875
13876 <para>If the binary is processed through the debug
13877 splitting in OpenEmbedded, you should also
13878 copy the debug items (i.e. <filename>.debug</filename>
13879 contents and corresponding
13880 <filename>/usr/src/debug</filename> files)
13881 from the work directory.
13882 Here is an example:
13883 <literallayout class='monospaced'>
13884 $ bitbake bash
13885 $ bitbake -c devshell bash
13886 $ cd ..
13887 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
13888 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
13889 </literallayout>
13890 </para></listitem>
13891 </orderedlist>
13892 </para>
13893 </section>
13894
13895 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
13896 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
13897
13898 <para>
13899 The previous section addressed using GDB remotely for debugging
13900 purposes, which is the most usual case due to the inherent
13901 hardware limitations on many embedded devices.
13902 However, debugging in the target hardware itself is also
13903 possible with more powerful devices.
13904 This section describes what you need to do in order to support
13905 using GDB to debug on the target hardware.
13906 </para>
13907
13908 <para>
13909 To support this kind of debugging, you need do the following:
13910 <itemizedlist>
13911 <listitem><para>
13912 Ensure that GDB is on the target.
13913 You can do this by adding "gdb" to
13914 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
13915 <literallayout class='monospaced'>
13916 IMAGE_INSTALL_append = " gdb"
13917 </literallayout>
13918 Alternatively, you can add "tools-debug" to
13919 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
13920 <literallayout class='monospaced'>
13921 IMAGE_FEATURES_append = " tools-debug"
13922 </literallayout>
13923 </para></listitem>
13924 <listitem><para>
13925 Ensure that debug symbols are present.
13926 You can make sure these symbols are present by
13927 installing <filename>-dbg</filename>:
13928 <literallayout class='monospaced'>
13929 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
13930 </literallayout>
13931 Alternatively, you can do the following to include all
13932 the debug symbols:
13933 <literallayout class='monospaced'>
13934 IMAGE_FEATURES_append = " dbg-pkgs"
13935 </literallayout>
13936 </para></listitem>
13937 </itemizedlist>
13938 <note>
13939 To improve the debug information accuracy, you can reduce
13940 the level of optimization used by the compiler.
13941 For example, when adding the following line to your
13942 <filename>local.conf</filename> file, you will reduce
13943 optimization from
13944 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
13945 of "-O2" to
13946 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
13947 of "-O -fno-omit-frame-pointer":
13948 <literallayout class='monospaced'>
13949 DEBUG_BUILD = "1"
13950 </literallayout>
13951 Consider that this will reduce the application's performance
13952 and is recommended only for debugging purposes.
13953 </note>
13954 </para>
13955 </section>
13956
13957 <section id='dev-other-debugging-others'>
13958 <title>Other Debugging Tips</title>
13959
13960 <para>
13961 Here are some other tips that you might find useful:
13962 <itemizedlist>
13963 <listitem><para>
13964 When adding new packages, it is worth watching for
13965 undesirable items making their way into compiler command
13966 lines.
13967 For example, you do not want references to local system
13968 files like
13969 <filename>/usr/lib/</filename> or
13970 <filename>/usr/include/</filename>.
13971 </para></listitem>
13972 <listitem><para>
13973 If you want to remove the <filename>psplash</filename>
13974 boot splashscreen,
13975 add <filename>psplash=false</filename> to the kernel
13976 command line.
13977 Doing so prevents <filename>psplash</filename> from
13978 loading and thus allows you to see the console.
13979 It is also possible to switch out of the splashscreen by
13980 switching the virtual console (e.g. Fn+Left or Fn+Right
13981 on a Zaurus).
13982 </para></listitem>
13983 <listitem><para>
13984 Removing
13985 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
13986 (usually <filename>tmp/</filename>, within the
13987 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
13988 can often fix temporary build issues.
13989 Removing <filename>TMPDIR</filename> is usually a
13990 relatively cheap operation, because task output will be
13991 cached in
13992 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13993 (usually <filename>sstate-cache/</filename>, which is
13994 also in the Build Directory).
13995 <note>
13996 Removing <filename>TMPDIR</filename> might be a
13997 workaround rather than a fix.
13998 Consequently, trying to determine the underlying
13999 cause of an issue before removing the directory is
14000 a good idea.
14001 </note>
14002 </para></listitem>
14003 <listitem><para>
14004 Understanding how a feature is used in practice within
14005 existing recipes can be very helpful.
14006 It is recommended that you configure some method that
14007 allows you to quickly search through files.</para>
14008
14009 <para>Using GNU Grep, you can use the following shell
14010 function to recursively search through common
14011 recipe-related files, skipping binary files,
14012 <filename>.git</filename> directories, and the
14013 Build Directory (assuming its name starts with
14014 "build"):
14015 <literallayout class='monospaced'>
14016 g() {
14017 grep -Ir \
14018 --exclude-dir=.git \
14019 --exclude-dir='build*' \
14020 --include='*.bb*' \
14021 --include='*.inc*' \
14022 --include='*.conf*' \
14023 --include='*.py*' \
14024 "$@"
14025 }
14026 </literallayout>
14027 Following are some usage examples:
14028 <literallayout class='monospaced'>
14029 $ g FOO # Search recursively for "FOO"
14030 $ g -i foo # Search recursively for "foo", ignoring case
14031 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
14032 </literallayout>
14033 If figuring out how some feature works requires a lot of
14034 searching, it might indicate that the documentation
14035 should be extended or improved.
14036 In such cases, consider filing a documentation bug using
14037 the Yocto Project implementation of
14038 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
14039 For information on how to submit a bug against
14040 the Yocto Project, see the Yocto Project Bugzilla
14041 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
14042 and the
14043 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
14044 section.
14045 <note>
14046 The manuals might not be the right place to document
14047 variables that are purely internal and have a
14048 limited scope (e.g. internal variables used to
14049 implement a single <filename>.bbclass</filename>
14050 file).
14051 </note>
14052 </para></listitem>
14053 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014054 </para>
14055 </section>
14056 </section>
14057
Brad Bishop316dfdd2018-06-25 12:45:53 -040014058 <section id='making-changes-to-the-yocto-project'>
14059 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014060
14061 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014062 Because the Yocto Project is an open-source, community-based
14063 project, you can effect changes to the project.
14064 This section presents procedures that show you how to submit
14065 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014066 </para>
14067
Brad Bishop316dfdd2018-06-25 12:45:53 -040014068 <section id='submitting-a-defect-against-the-yocto-project'>
14069 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014070
14071 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014072 Use the Yocto Project implementation of
14073 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
14074 to submit a defect (bug) against the Yocto Project.
14075 For additional information on this implementation of Bugzilla see the
14076 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
14077 section in the Yocto Project Reference Manual.
14078 For more detail on any of the following steps, see the Yocto Project
14079 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014080 </para>
14081
14082 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014083 Use the following general steps to submit a bug"
14084
14085 <orderedlist>
14086 <listitem><para>
14087 Open the Yocto Project implementation of
14088 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
14089 </para></listitem>
14090 <listitem><para>
14091 Click "File a Bug" to enter a new bug.
14092 </para></listitem>
14093 <listitem><para>
14094 Choose the appropriate "Classification", "Product", and
14095 "Component" for which the bug was found.
14096 Bugs for the Yocto Project fall into one of several
14097 classifications, which in turn break down into several
14098 products and components.
14099 For example, for a bug against the
14100 <filename>meta-intel</filename> layer, you would choose
14101 "Build System, Metadata &amp; Runtime", "BSPs", and
14102 "bsps-meta-intel", respectively.
14103 </para></listitem>
14104 <listitem><para>
14105 Choose the "Version" of the Yocto Project for which you found
14106 the bug (e.g. &DISTRO;).
14107 </para></listitem>
14108 <listitem><para>
14109 Determine and select the "Severity" of the bug.
14110 The severity indicates how the bug impacted your work.
14111 </para></listitem>
14112 <listitem><para>
14113 Choose the "Hardware" that the bug impacts.
14114 </para></listitem>
14115 <listitem><para>
14116 Choose the "Architecture" that the bug impacts.
14117 </para></listitem>
14118 <listitem><para>
14119 Choose a "Documentation change" item for the bug.
14120 Fixing a bug might or might not affect the Yocto Project
14121 documentation.
14122 If you are unsure of the impact to the documentation, select
14123 "Don't Know".
14124 </para></listitem>
14125 <listitem><para>
14126 Provide a brief "Summary" of the bug.
14127 Try to limit your summary to just a line or two and be sure
14128 to capture the essence of the bug.
14129 </para></listitem>
14130 <listitem><para>
14131 Provide a detailed "Description" of the bug.
14132 You should provide as much detail as you can about the context,
14133 behavior, output, and so forth that surrounds the bug.
14134 You can even attach supporting files for output from logs by
14135 using the "Add an attachment" button.
14136 </para></listitem>
14137 <listitem><para>
14138 Click the "Submit Bug" button submit the bug.
14139 A new Bugzilla number is assigned to the bug and the defect
14140 is logged in the bug tracking system.
14141 </para></listitem>
14142 </orderedlist>
14143 Once you file a bug, the bug is processed by the Yocto Project Bug
14144 Triage Team and further details concerning the bug are assigned
14145 (e.g. priority and owner).
14146 You are the "Submitter" of the bug and any further categorization,
14147 progress, or comments on the bug result in Bugzilla sending you an
14148 automated email concerning the particular change or progress to the
14149 bug.
14150 </para>
14151 </section>
14152
14153 <section id='how-to-submit-a-change'>
14154 <title>Submitting a Change to the Yocto Project</title>
14155
14156 <para>
14157 Contributions to the Yocto Project and OpenEmbedded are very welcome.
14158 Because the system is extremely configurable and flexible, we recognize
14159 that developers will want to extend, configure or optimize it for
14160 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014161 </para>
14162
14163 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014164 The Yocto Project uses a mailing list and a patch-based workflow
14165 that is similar to the Linux kernel but contains important
14166 differences.
14167 In general, a mailing list exists through which you can submit
14168 patches.
14169 You should send patches to the appropriate mailing list so that they
14170 can be reviewed and merged by the appropriate maintainer.
14171 The specific mailing list you need to use depends on the
14172 location of the code you are changing.
14173 Each component (e.g. layer) should have a
14174 <filename>README</filename> file that indicates where to send
14175 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014176 </para>
14177
14178 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014179 You can send the patch to the mailing list using whichever approach
14180 you feel comfortable with to generate the patch.
14181 Once sent, the patch is usually reviewed by the community at large.
14182 If somebody has concerns with the patch, they will usually voice
14183 their concern over the mailing list.
14184 If a patch does not receive any negative reviews, the maintainer of
14185 the affected layer typically takes the patch, tests it, and then
14186 based on successful testing, merges the patch.
14187 </para>
14188
14189 <para id='figuring-out-the-mailing-list-to-use'>
14190 The "poky" repository, which is the Yocto Project's reference build
14191 environment, is a hybrid repository that contains several
14192 individual pieces (e.g. BitBake, Metadata, documentation,
14193 and so forth) built using the combo-layer tool.
14194 The upstream location used for submitting changes varies by
14195 component:
14196 <itemizedlist>
14197 <listitem><para>
14198 <emphasis>Core Metadata:</emphasis>
14199 Send your patch to the
14200 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14201 mailing list. For example, a change to anything under
14202 the <filename>meta</filename> or
14203 <filename>scripts</filename> directories should be sent
14204 to this mailing list.
14205 </para></listitem>
14206 <listitem><para>
14207 <emphasis>BitBake:</emphasis>
14208 For changes to BitBake (i.e. anything under the
14209 <filename>bitbake</filename> directory), send your patch
14210 to the
14211 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14212 mailing list.
14213 </para></listitem>
14214 <listitem><para>
14215 <emphasis>"meta-*" trees:</emphasis>
14216 These trees contain Metadata.
14217 Use the
14218 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14219 mailing list.
14220 </para></listitem>
14221 </itemizedlist>
14222 </para>
14223
14224 <para>
14225 For changes to other layers hosted in the Yocto Project source
14226 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14227 and the Yocto Project documentation, use the
14228 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14229 general mailing list.
14230 <note>
14231 Sometimes a layer's documentation specifies to use a
14232 particular mailing list.
14233 If so, use that list.
14234 </note>
14235 For additional recipes that do not fit into the core Metadata, you
14236 should determine which layer the recipe should go into and submit
14237 the change in the manner recommended by the documentation (e.g.
14238 the <filename>README</filename> file) supplied with the layer.
14239 If in doubt, please ask on the Yocto general mailing list or on
14240 the openembedded-devel mailing list.
14241 </para>
14242
14243 <para>
14244 You can also push a change upstream and request a maintainer to
14245 pull the change into the component's upstream repository.
14246 You do this by pushing to a contribution repository that is upstream.
14247 See the
14248 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14249 section in the Yocto Project Overview and Concepts Manual for additional
14250 concepts on working in the Yocto Project development environment.
14251 </para>
14252
14253 <para>
14254 Two commonly used testing repositories exist for
14255 OpenEmbedded-Core:
14256 <itemizedlist>
14257 <listitem><para>
14258 <emphasis>"ross/mut" branch:</emphasis>
14259 The "mut" (master-under-test) tree
14260 exists in the <filename>poky-contrib</filename> repository
14261 in the
14262 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14263 </para></listitem>
14264 <listitem><para>
14265 <emphasis>"master-next" branch:</emphasis>
14266 This branch is part of the main
14267 "poky" repository in the Yocto Project source repositories.
14268 </para></listitem>
14269 </itemizedlist>
14270 Maintainers use these branches to test submissions prior to merging
14271 patches.
14272 Thus, you can get an idea of the status of a patch based on
14273 whether the patch has been merged into one of these branches.
14274 <note>
14275 This system is imperfect and changes can sometimes get lost in the
14276 flow.
14277 Asking about the status of a patch or change is reasonable if the
14278 change has been idle for a while with no feedback.
14279 The Yocto Project does have plans to use
14280 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14281 to track the status of patches and also to automatically preview
14282 patches.
14283 </note>
14284 </para>
14285
14286 <para>
14287 The following sections provide procedures for submitting a change.
14288 </para>
14289
14290 <section id='pushing-a-change-upstream'>
14291 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14292
14293 <para>
14294 Follow this procedure to push a change to an upstream "contrib"
14295 Git repository:
14296 <note>
14297 You can find general Git information on how to push a change
14298 upstream in the
14299 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14300 </note>
14301 <orderedlist>
14302 <listitem><para>
14303 <emphasis>Make Your Changes Locally:</emphasis>
14304 Make your changes in your local Git repository.
14305 You should make small, controlled, isolated changes.
14306 Keeping changes small and isolated aids review,
14307 makes merging/rebasing easier and keeps the change
14308 history clean should anyone need to refer to it in
14309 future.
14310 </para></listitem>
14311 <listitem><para>
14312 <emphasis>Stage Your Changes:</emphasis>
14313 Stage your changes by using the <filename>git add</filename>
14314 command on each file you changed.
14315 </para></listitem>
14316 <listitem><para id='making-sure-you-have-correct-commit-information'>
14317 <emphasis>Commit Your Changes:</emphasis>
14318 Commit the change by using the
14319 <filename>git commit</filename> command.
14320 Make sure your commit information follows standards by
14321 following these accepted conventions:
14322 <itemizedlist>
14323 <listitem><para>
14324 Be sure to include a "Signed-off-by:" line in the
14325 same style as required by the Linux kernel.
14326 Adding this line signifies that you, the submitter,
14327 have agreed to the Developer's Certificate of
14328 Origin 1.1 as follows:
14329 <literallayout class='monospaced'>
14330 Developer's Certificate of Origin 1.1
14331
14332 By making a contribution to this project, I certify that:
14333
14334 (a) The contribution was created in whole or in part by me and I
14335 have the right to submit it under the open source license
14336 indicated in the file; or
14337
14338 (b) The contribution is based upon previous work that, to the best
14339 of my knowledge, is covered under an appropriate open source
14340 license and I have the right under that license to submit that
14341 work with modifications, whether created in whole or in part
14342 by me, under the same open source license (unless I am
14343 permitted to submit under a different license), as indicated
14344 in the file; or
14345
14346 (c) The contribution was provided directly to me by some other
14347 person who certified (a), (b) or (c) and I have not modified
14348 it.
14349
14350 (d) I understand and agree that this project and the contribution
14351 are public and that a record of the contribution (including all
14352 personal information I submit with it, including my sign-off) is
14353 maintained indefinitely and may be redistributed consistent with
14354 this project or the open source license(s) involved.
14355 </literallayout>
14356 </para></listitem>
14357 <listitem><para>
14358 Provide a single-line summary of the change.
14359 and,
14360 if more explanation is needed, provide more
14361 detail in the body of the commit.
14362 This summary is typically viewable in the
14363 "shortlist" of changes.
14364 Thus, providing something short and descriptive
14365 that gives the reader a summary of the change is
14366 useful when viewing a list of many commits.
14367 You should prefix this short description with the
14368 recipe name (if changing a recipe), or else with
14369 the short form path to the file being changed.
14370 </para></listitem>
14371 <listitem><para>
14372 For the body of the commit message, provide
14373 detailed information that describes what you
14374 changed, why you made the change, and the approach
14375 you used.
14376 It might also be helpful if you mention how you
14377 tested the change.
14378 Provide as much detail as you can in the body of
14379 the commit message.
14380 <note>
14381 You do not need to provide a more detailed
14382 explanation of a change if the change is
14383 minor to the point of the single line
14384 summary providing all the information.
14385 </note>
14386 </para></listitem>
14387 <listitem><para>
14388 If the change addresses a specific bug or issue
14389 that is associated with a bug-tracking ID,
14390 include a reference to that ID in your detailed
14391 description.
14392 For example, the Yocto Project uses a specific
14393 convention for bug references - any commit that
14394 addresses a specific bug should use the following
14395 form for the detailed description.
14396 Be sure to use the actual bug-tracking ID from
14397 Bugzilla for
14398 <replaceable>bug-id</replaceable>:
14399 <literallayout class='monospaced'>
14400 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14401
14402 <replaceable>detailed description of change</replaceable>
14403 </literallayout>
14404 </para></listitem>
14405 </itemizedlist>
14406 </para></listitem>
14407 <listitem><para>
14408 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14409 If you have arranged for permissions to push to an
14410 upstream contrib repository, push the change to that
14411 repository:
14412 <literallayout class='monospaced'>
14413 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14414 </literallayout>
14415 For example, suppose you have permissions to push into the
14416 upstream <filename>meta-intel-contrib</filename>
14417 repository and you are working in a local branch named
14418 <replaceable>your_name</replaceable><filename>/README</filename>.
14419 The following command pushes your local commits to the
14420 <filename>meta-intel-contrib</filename> upstream
14421 repository and puts the commit in a branch named
14422 <replaceable>your_name</replaceable><filename>/README</filename>:
14423 <literallayout class='monospaced'>
14424 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14425 </literallayout>
14426 </para></listitem>
14427 <listitem><para id='push-determine-who-to-notify'>
14428 <emphasis>Determine Who to Notify:</emphasis>
14429 Determine the maintainer or the mailing list
14430 that you need to notify for the change.</para>
14431
14432 <para>Before submitting any change, you need to be sure
14433 who the maintainer is or what mailing list that you need
14434 to notify.
14435 Use either these methods to find out:
14436 <itemizedlist>
14437 <listitem><para>
14438 <emphasis>Maintenance File:</emphasis>
14439 Examine the <filename>maintainers.inc</filename>
14440 file, which is located in the
14441 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14442 at
14443 <filename>meta/conf/distro/include</filename>,
14444 to see who is responsible for code.
14445 </para></listitem>
14446 <listitem><para>
14447 <emphasis>Search by File:</emphasis>
14448 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14449 you can enter the following command to bring up a
14450 short list of all commits against a specific file:
14451 <literallayout class='monospaced'>
14452 git shortlog -- <replaceable>filename</replaceable>
14453 </literallayout>
14454 Just provide the name of the file for which you
14455 are interested.
14456 The information returned is not ordered by history
14457 but does include a list of everyone who has
14458 committed grouped by name.
14459 From the list, you can see who is responsible for
14460 the bulk of the changes against the file.
14461 </para></listitem>
14462 <listitem><para>
14463 <emphasis>Examine the List of Mailing Lists:</emphasis>
14464 For a list of the Yocto Project and related mailing
14465 lists, see the
14466 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14467 section in the Yocto Project Reference Manual.
14468 </para></listitem>
14469 </itemizedlist>
14470 </para></listitem>
14471 <listitem><para>
14472 <emphasis>Make a Pull Request:</emphasis>
14473 Notify the maintainer or the mailing list that you have
14474 pushed a change by making a pull request.</para>
14475
14476 <para>The Yocto Project provides two scripts that
14477 conveniently let you generate and send pull requests to the
14478 Yocto Project.
14479 These scripts are <filename>create-pull-request</filename>
14480 and <filename>send-pull-request</filename>.
14481 You can find these scripts in the
14482 <filename>scripts</filename> directory within the
14483 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14484 (e.g. <filename>~/poky/scripts</filename>).
14485 </para>
14486
14487 <para>Using these scripts correctly formats the requests
14488 without introducing any whitespace or HTML formatting.
14489 The maintainer that receives your patches either directly
14490 or through the mailing list needs to be able to save and
14491 apply them directly from your emails.
14492 Using these scripts is the preferred method for sending
14493 patches.</para>
14494
14495 <para>First, create the pull request.
14496 For example, the following command runs the script,
14497 specifies the upstream repository in the contrib directory
14498 into which you pushed the change, and provides a subject
14499 line in the created patch files:
14500 <literallayout class='monospaced'>
14501 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14502 </literallayout>
14503 Running this script forms
14504 <filename>*.patch</filename> files in a folder named
14505 <filename>pull-</filename><replaceable>PID</replaceable>
14506 in the current directory.
14507 One of the patch files is a cover letter.</para>
14508
14509 <para>Before running the
14510 <filename>send-pull-request</filename> script, you must
14511 edit the cover letter patch to insert information about
14512 your change.
14513 After editing the cover letter, send the pull request.
14514 For example, the following command runs the script and
14515 specifies the patch directory and email address.
14516 In this example, the email address is a mailing list:
14517 <literallayout class='monospaced'>
14518 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14519 </literallayout>
14520 You need to follow the prompts as the script is
14521 interactive.
14522 <note>
14523 For help on using these scripts, simply provide the
14524 <filename>-h</filename> argument as follows:
14525 <literallayout class='monospaced'>
14526 $ poky/scripts/create-pull-request -h
14527 $ poky/scripts/send-pull-request -h
14528 </literallayout>
14529 </note>
14530 </para></listitem>
14531 </orderedlist>
14532 </para>
14533 </section>
14534
14535 <section id='submitting-a-patch'>
14536 <title>Using Email to Submit a Patch</title>
14537
14538 <para>
14539 You can submit patches without using the
14540 <filename>create-pull-request</filename> and
14541 <filename>send-pull-request</filename> scripts described in the
14542 previous section.
14543 However, keep in mind, the preferred method is to use the scripts.
14544 </para>
14545
14546 <para>
14547 Depending on the components changed, you need to submit the email
14548 to a specific mailing list.
14549 For some guidance on which mailing list to use, see the
14550 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14551 at the beginning of this section.
14552 For a description of all the available mailing lists, see the
14553 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14554 section in the Yocto Project Reference Manual.
14555 </para>
14556
14557 <para>
14558 Here is the general procedure on how to submit a patch through
14559 email without using the scripts:
14560 <orderedlist>
14561 <listitem><para>
14562 <emphasis>Make Your Changes Locally:</emphasis>
14563 Make your changes in your local Git repository.
14564 You should make small, controlled, isolated changes.
14565 Keeping changes small and isolated aids review,
14566 makes merging/rebasing easier and keeps the change
14567 history clean should anyone need to refer to it in
14568 future.
14569 </para></listitem>
14570 <listitem><para>
14571 <emphasis>Stage Your Changes:</emphasis>
14572 Stage your changes by using the <filename>git add</filename>
14573 command on each file you changed.
14574 </para></listitem>
14575 <listitem><para>
14576 <emphasis>Commit Your Changes:</emphasis>
14577 Commit the change by using the
14578 <filename>git commit --signoff</filename> command.
14579 Using the <filename>--signoff</filename> option identifies
14580 you as the person making the change and also satisfies
14581 the Developer's Certificate of Origin (DCO) shown earlier.
14582 </para>
14583
14584 <para>When you form a commit, you must follow certain
14585 standards established by the Yocto Project development
14586 team.
14587 See
14588 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14589 in the previous section for information on how to
14590 provide commit information that meets Yocto Project
14591 commit message standards.
14592 </para></listitem>
14593 <listitem><para>
14594 <emphasis>Format the Commit:</emphasis>
14595 Format the commit into an email message.
14596 To format commits, use the
14597 <filename>git format-patch</filename> command.
14598 When you provide the command, you must include a revision
14599 list or a number of patches as part of the command.
14600 For example, either of these two commands takes your most
14601 recent single commit and formats it as an email message in
14602 the current directory:
14603 <literallayout class='monospaced'>
14604 $ git format-patch -1
14605 </literallayout>
14606 or
14607 <literallayout class='monospaced'>
14608 $ git format-patch HEAD~
14609 </literallayout></para>
14610
14611 <para>After the command is run, the current directory
14612 contains a numbered <filename>.patch</filename> file for
14613 the commit.</para>
14614
14615 <para>If you provide several commits as part of the
14616 command, the <filename>git format-patch</filename> command
14617 produces a series of numbered files in the current
14618 directory – one for each commit.
14619 If you have more than one patch, you should also use the
14620 <filename>--cover</filename> option with the command,
14621 which generates a cover letter as the first "patch" in
14622 the series.
14623 You can then edit the cover letter to provide a
14624 description for the series of patches.
14625 For information on the
14626 <filename>git format-patch</filename> command,
14627 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14628 using the <filename>man git-format-patch</filename>
14629 command.
14630 <note>
14631 If you are or will be a frequent contributor to the
14632 Yocto Project or to OpenEmbedded, you might consider
14633 requesting a contrib area and the necessary associated
14634 rights.
14635 </note>
14636 </para></listitem>
14637 <listitem><para>
14638 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14639 Import the files into your mail client by using the
14640 <filename>git send-email</filename> command.
14641 <note>
14642 In order to use <filename>git send-email</filename>,
14643 you must have the proper Git packages installed on
14644 your host.
14645 For Ubuntu, Debian, and Fedora the package is
14646 <filename>git-email</filename>.
14647 </note></para>
14648
14649 <para>The <filename>git send-email</filename> command
14650 sends email by using a local or remote Mail Transport Agent
14651 (MTA) such as <filename>msmtp</filename>,
14652 <filename>sendmail</filename>, or through a direct
14653 <filename>smtp</filename> configuration in your Git
14654 <filename>~/.gitconfig</filename> file.
14655 If you are submitting patches through email only, it is
14656 very important that you submit them without any whitespace
14657 or HTML formatting that either you or your mailer
14658 introduces.
14659 The maintainer that receives your patches needs to be able
14660 to save and apply them directly from your emails.
14661 A good way to verify that what you are sending will be
14662 applicable by the maintainer is to do a dry run and send
14663 them to yourself and then save and apply them as the
14664 maintainer would.</para>
14665
14666 <para>The <filename>git send-email</filename> command is
14667 the preferred method for sending your patches using
14668 email since there is no risk of compromising whitespace
14669 in the body of the message, which can occur when you use
14670 your own mail client.
14671 The command also has several options that let you
14672 specify recipients and perform further editing of the
14673 email message.
14674 For information on how to use the
14675 <filename>git send-email</filename> command,
14676 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14677 the <filename>man git-send-email</filename> command.
14678 </para></listitem>
14679 </orderedlist>
14680 </para>
14681 </section>
14682 </section>
14683 </section>
14684
14685 <section id='working-with-licenses'>
14686 <title>Working With Licenses</title>
14687
14688 <para>
14689 As mentioned in the
14690 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
14691 section in the Yocto Project Overview and Concepts Manual,
14692 open source projects are open to the public and they
14693 consequently have different licensing structures in place.
14694 This section describes the mechanism by which the
14695 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
14696 tracks changes to licensing text and covers how to maintain open
14697 source license compliance during your project's lifecycle.
14698 The section also describes how to enable commercially licensed
14699 recipes, which by default are disabled.
14700 </para>
14701
14702 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
14703 <title>Tracking License Changes</title>
14704
14705 <para>
14706 The license of an upstream project might change in the future.
14707 In order to prevent these changes going unnoticed, the
14708 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
14709 variable tracks changes to the license text. The checksums are
14710 validated at the end of the configure step, and if the
14711 checksums do not match, the build will fail.
14712 </para>
14713
14714 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
14715 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
14716
14717 <para>
14718 The <filename>LIC_FILES_CHKSUM</filename>
14719 variable contains checksums of the license text in the
14720 source code for the recipe.
14721 Following is an example of how to specify
14722 <filename>LIC_FILES_CHKSUM</filename>:
14723 <literallayout class='monospaced'>
14724 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
14725 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
14726 file://licfile2.txt;endline=50;md5=zzzz \
14727 ..."
14728 </literallayout>
14729 <note><title>Notes</title>
14730 <itemizedlist>
14731 <listitem><para>
14732 When using "beginline" and "endline", realize
14733 that line numbering begins with one and not
14734 zero.
14735 Also, the included lines are inclusive (i.e.
14736 lines five through and including 29 in the
14737 previous example for
14738 <filename>licfile1.txt</filename>).
14739 </para></listitem>
14740 <listitem><para>
14741 When a license check fails, the selected license
14742 text is included as part of the QA message.
14743 Using this output, you can determine the exact
14744 start and finish for the needed license text.
14745 </para></listitem>
14746 </itemizedlist>
14747 </note>
14748 </para>
14749
14750 <para>
14751 The build system uses the
14752 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
14753 variable as the default directory when searching files
14754 listed in <filename>LIC_FILES_CHKSUM</filename>.
14755 The previous example employs the default directory.
14756 </para>
14757
14758 <para>
14759 Consider this next example:
14760 <literallayout class='monospaced'>
14761 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
14762 md5=bb14ed3c4cda583abc85401304b5cd4e"
14763 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
14764 </literallayout>
14765 </para>
14766
14767 <para>
14768 The first line locates a file in
14769 <filename>${S}/src/ls.c</filename> and isolates lines five
14770 through 16 as license text.
14771 The second line refers to a file in
14772 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
14773 </para>
14774
14775 <para>
14776 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
14777 mandatory for all recipes, unless the
14778 <filename>LICENSE</filename> variable is set to "CLOSED".
14779 </para>
14780 </section>
14781
14782 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
14783 <title>Explanation of Syntax</title>
14784
14785 <para>
14786 As mentioned in the previous section, the
14787 <filename>LIC_FILES_CHKSUM</filename> variable lists all
14788 the important files that contain the license text for the
14789 source code.
14790 It is possible to specify a checksum for an entire file,
14791 or a specific section of a file (specified by beginning and
14792 ending line numbers with the "beginline" and "endline"
14793 parameters, respectively).
14794 The latter is useful for source files with a license
14795 notice header, README documents, and so forth.
14796 If you do not use the "beginline" parameter, then it is
14797 assumed that the text begins on the first line of the file.
14798 Similarly, if you do not use the "endline" parameter,
14799 it is assumed that the license text ends with the last
14800 line of the file.
14801 </para>
14802
14803 <para>
14804 The "md5" parameter stores the md5 checksum of the license
14805 text.
14806 If the license text changes in any way as compared to
14807 this parameter then a mismatch occurs.
14808 This mismatch triggers a build failure and notifies
14809 the developer.
14810 Notification allows the developer to review and address
14811 the license text changes.
14812 Also note that if a mismatch occurs during the build,
14813 the correct md5 checksum is placed in the build log and
14814 can be easily copied to the recipe.
14815 </para>
14816
14817 <para>
14818 There is no limit to how many files you can specify using
14819 the <filename>LIC_FILES_CHKSUM</filename> variable.
14820 Generally, however, every project requires a few
14821 specifications for license tracking.
14822 Many projects have a "COPYING" file that stores the
14823 license information for all the source code files.
14824 This practice allows you to just track the "COPYING"
14825 file as long as it is kept up to date.
14826 <note><title>Tips</title>
14827 <itemizedlist>
14828 <listitem><para>
14829 If you specify an empty or invalid "md5"
14830 parameter,
14831 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
14832 returns an md5 mis-match
14833 error and displays the correct "md5" parameter
14834 value during the build.
14835 The correct parameter is also captured in
14836 the build log.
14837 </para></listitem>
14838 <listitem><para>
14839 If the whole file contains only license text,
14840 you do not need to use the "beginline" and
14841 "endline" parameters.
14842 </para></listitem>
14843 </itemizedlist>
14844 </note>
14845 </para>
14846 </section>
14847 </section>
14848
14849 <section id="enabling-commercially-licensed-recipes">
14850 <title>Enabling Commercially Licensed Recipes</title>
14851
14852 <para>
14853 By default, the OpenEmbedded build system disables
14854 components that have commercial or other special licensing
14855 requirements.
14856 Such requirements are defined on a
14857 recipe-by-recipe basis through the
14858 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
14859 variable definition in the affected recipe.
14860 For instance, the
14861 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14862 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014863 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014864 LICENSE_FLAGS = "commercial"
14865 </literallayout>
14866 Here is a slightly more complicated example that contains both
14867 an explicit recipe name and version (after variable expansion):
14868 <literallayout class='monospaced'>
14869 LICENSE_FLAGS = "license_${PN}_${PV}"
14870 </literallayout>
14871 In order for a component restricted by a
14872 <filename>LICENSE_FLAGS</filename> definition to be enabled and
14873 included in an image, it needs to have a matching entry in the
14874 global
14875 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
14876 variable, which is a variable typically defined in your
14877 <filename>local.conf</filename> file.
14878 For example, to enable the
14879 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14880 package, you could add either the string
14881 "commercial_gst-plugins-ugly" or the more general string
14882 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
14883 See the
14884 "<link linkend='license-flag-matching'>License Flag Matching</link>"
14885 section for a full
14886 explanation of how <filename>LICENSE_FLAGS</filename> matching
14887 works.
14888 Here is the example:
14889 <literallayout class='monospaced'>
14890 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
14891 </literallayout>
14892 Likewise, to additionally enable the package built from the
14893 recipe containing
14894 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
14895 and assuming that the actual recipe name was
14896 <filename>emgd_1.10.bb</filename>, the following string would
14897 enable that package as well as the original
14898 <filename>gst-plugins-ugly</filename> package:
14899 <literallayout class='monospaced'>
14900 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
14901 </literallayout>
14902 As a convenience, you do not need to specify the complete
14903 license string in the whitelist for every package.
14904 You can use an abbreviated form, which consists
14905 of just the first portion or portions of the license
14906 string before the initial underscore character or characters.
14907 A partial string will match any license that contains the
14908 given string as the first portion of its license.
14909 For example, the following whitelist string will also match
14910 both of the packages previously mentioned as well as any other
14911 packages that have licenses starting with "commercial" or
14912 "license".
14913 <literallayout class='monospaced'>
14914 LICENSE_FLAGS_WHITELIST = "commercial license"
14915 </literallayout>
14916 </para>
14917
14918 <section id="license-flag-matching">
14919 <title>License Flag Matching</title>
14920
14921 <para>
14922 License flag matching allows you to control what recipes
14923 the OpenEmbedded build system includes in the build.
14924 Fundamentally, the build system attempts to match
14925 <filename>LICENSE_FLAGS</filename> strings found in recipes
14926 against <filename>LICENSE_FLAGS_WHITELIST</filename>
14927 strings found in the whitelist.
14928 A match causes the build system to include a recipe in the
14929 build, while failure to find a match causes the build
14930 system to exclude a recipe.
14931 </para>
14932
14933 <para>
14934 In general, license flag matching is simple.
14935 However, understanding some concepts will help you
14936 correctly and effectively use matching.
14937 </para>
14938
14939 <para>
14940 Before a flag
14941 defined by a particular recipe is tested against the
14942 contents of the whitelist, the expanded string
14943 <filename>_${PN}</filename> is appended to the flag.
14944 This expansion makes each
14945 <filename>LICENSE_FLAGS</filename> value recipe-specific.
14946 After expansion, the string is then matched against the
14947 whitelist.
14948 Thus, specifying
14949 <filename>LICENSE_FLAGS = "commercial"</filename>
14950 in recipe "foo", for example, results in the string
14951 <filename>"commercial_foo"</filename>.
14952 And, to create a match, that string must appear in the
14953 whitelist.
14954 </para>
14955
14956 <para>
14957 Judicious use of the <filename>LICENSE_FLAGS</filename>
14958 strings and the contents of the
14959 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
14960 allows you a lot of flexibility for including or excluding
14961 recipes based on licensing.
14962 For example, you can broaden the matching capabilities by
14963 using license flags string subsets in the whitelist.
14964 <note>
14965 When using a string subset, be sure to use the part of
14966 the expanded string that precedes the appended
14967 underscore character (e.g.
14968 <filename>usethispart_1.3</filename>,
14969 <filename>usethispart_1.4</filename>, and so forth).
14970 </note>
14971 For example, simply specifying the string "commercial" in
14972 the whitelist matches any expanded
14973 <filename>LICENSE_FLAGS</filename> definition that starts
14974 with the string "commercial" such as "commercial_foo" and
14975 "commercial_bar", which are the strings the build system
14976 automatically generates for hypothetical recipes named
14977 "foo" and "bar" assuming those recipes simply specify the
14978 following:
14979 <literallayout class='monospaced'>
14980 LICENSE_FLAGS = "commercial"
14981 </literallayout>
14982 Thus, you can choose to exhaustively
14983 enumerate each license flag in the whitelist and
14984 allow only specific recipes into the image, or
14985 you can use a string subset that causes a broader range of
14986 matches to allow a range of recipes into the image.
14987 </para>
14988
14989 <para>
14990 This scheme works even if the
14991 <filename>LICENSE_FLAGS</filename> string already
14992 has <filename>_${PN}</filename> appended.
14993 For example, the build system turns the license flag
14994 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
14995 would match both the general "commercial" and the specific
14996 "commercial_1.2_foo" strings found in the whitelist, as
14997 expected.
14998 </para>
14999
15000 <para>
15001 Here are some other scenarios:
15002 <itemizedlist>
15003 <listitem><para>
15004 You can specify a versioned string in the recipe
15005 such as "commercial_foo_1.2" in a "foo" recipe.
15006 The build system expands this string to
15007 "commercial_foo_1.2_foo".
15008 Combine this license flag with a whitelist that has
15009 the string "commercial" and you match the flag
15010 along with any other flag that starts with the
15011 string "commercial".
15012 </para></listitem>
15013 <listitem><para>
15014 Under the same circumstances, you can use
15015 "commercial_foo" in the whitelist and the build
15016 system not only matches "commercial_foo_1.2" but
15017 also matches any license flag with the string
15018 "commercial_foo", regardless of the version.
15019 </para></listitem>
15020 <listitem><para>
15021 You can be very specific and use both the
15022 package and version parts in the whitelist (e.g.
15023 "commercial_foo_1.2") to specifically match a
15024 versioned recipe.
15025 </para></listitem>
15026 </itemizedlist>
15027 </para>
15028 </section>
15029
15030 <section id="other-variables-related-to-commercial-licenses">
15031 <title>Other Variables Related to Commercial Licenses</title>
15032
15033 <para>
15034 Other helpful variables related to commercial
15035 license handling exist and are defined in the
15036 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
15037 <literallayout class='monospaced'>
15038 COMMERCIAL_AUDIO_PLUGINS ?= ""
15039 COMMERCIAL_VIDEO_PLUGINS ?= ""
15040 </literallayout>
15041 If you want to enable these components, you can do so by
15042 making sure you have statements similar to the following
15043 in your <filename>local.conf</filename> configuration file:
15044 <literallayout class='monospaced'>
15045 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
15046 gst-plugins-ugly-mpegaudioparse"
15047 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
15048 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
15049 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
15050 </literallayout>
15051 Of course, you could also create a matching whitelist
15052 for those components using the more general "commercial"
15053 in the whitelist, but that would also enable all the
15054 other packages with <filename>LICENSE_FLAGS</filename>
15055 containing "commercial", which you may or may not want:
15056 <literallayout class='monospaced'>
15057 LICENSE_FLAGS_WHITELIST = "commercial"
15058 </literallayout>
15059 </para>
15060
15061 <para>
15062 Specifying audio and video plug-ins as part of the
15063 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
15064 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
15065 (along with the enabling
15066 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
15067 plug-ins or components into built images, thus adding
15068 support for media formats or components.
15069 </para>
15070 </section>
15071 </section>
15072
15073 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
15074 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
15075
15076 <para>
15077 One of the concerns for a development organization using open source
15078 software is how to maintain compliance with various open source
15079 licensing during the lifecycle of the product.
15080 While this section does not provide legal advice or
15081 comprehensively cover all scenarios, it does
15082 present methods that you can use to
15083 assist you in meeting the compliance requirements during a software
15084 release.
15085 </para>
15086
15087 <para>
15088 With hundreds of different open source licenses that the Yocto
15089 Project tracks, it is difficult to know the requirements of each
15090 and every license.
15091 However, the requirements of the major FLOSS licenses can begin
15092 to be covered by
15093 assuming that three main areas of concern exist:
15094 <itemizedlist>
15095 <listitem><para>Source code must be provided.</para></listitem>
15096 <listitem><para>License text for the software must be
15097 provided.</para></listitem>
15098 <listitem><para>Compilation scripts and modifications to the
15099 source code must be provided.
15100 </para></listitem>
15101 </itemizedlist>
15102 There are other requirements beyond the scope of these
15103 three and the methods described in this section
15104 (e.g. the mechanism through which source code is distributed).
15105 </para>
15106
15107 <para>
15108 As different organizations have different methods of complying with
15109 open source licensing, this section is not meant to imply that
15110 there is only one single way to meet your compliance obligations,
15111 but rather to describe one method of achieving compliance.
15112 The remainder of this section describes methods supported to meet the
15113 previously mentioned three requirements.
15114 Once you take steps to meet these requirements,
15115 and prior to releasing images, sources, and the build system,
15116 you should audit all artifacts to ensure completeness.
15117 <note>
15118 The Yocto Project generates a license manifest during
15119 image creation that is located
15120 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
15121 to assist with any audits.
15122 </note>
15123 </para>
15124
15125 <section id='providing-the-source-code'>
15126 <title>Providing the Source Code</title>
15127
15128 <para>
15129 Compliance activities should begin before you generate the
15130 final image.
15131 The first thing you should look at is the requirement that
15132 tops the list for most compliance groups - providing
15133 the source.
15134 The Yocto Project has a few ways of meeting this
15135 requirement.
15136 </para>
15137
15138 <para>
15139 One of the easiest ways to meet this requirement is
15140 to provide the entire
15141 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
15142 used by the build.
15143 This method, however, has a few issues.
15144 The most obvious is the size of the directory since it includes
15145 all sources used in the build and not just the source used in
15146 the released image.
15147 It will include toolchain source, and other artifacts, which
15148 you would not generally release.
15149 However, the more serious issue for most companies is accidental
15150 release of proprietary software.
15151 The Yocto Project provides an
15152 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
15153 class to help avoid some of these concerns.
15154 </para>
15155
15156 <para>
15157 Before you employ <filename>DL_DIR</filename> or the
15158 <filename>archiver</filename> class, you need to decide how
15159 you choose to provide source.
15160 The source <filename>archiver</filename> class can generate
15161 tarballs and SRPMs and can create them with various levels of
15162 compliance in mind.
15163 </para>
15164
15165 <para>
15166 One way of doing this (but certainly not the only way) is to
15167 release just the source as a tarball.
15168 You can do this by adding the following to the
15169 <filename>local.conf</filename> file found in the
15170 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15171 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015172 INHERIT += "archiver"
15173 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015174 </literallayout>
15175 During the creation of your image, the source from all
15176 recipes that deploy packages to the image is placed within
15177 subdirectories of
15178 <filename>DEPLOY_DIR/sources</filename> based on the
15179 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15180 for each recipe.
15181 Releasing the entire directory enables you to comply with
15182 requirements concerning providing the unmodified source.
15183 It is important to note that the size of the directory can
15184 get large.
15185 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015186
Brad Bishop316dfdd2018-06-25 12:45:53 -040015187 <para>
15188 A way to help mitigate the size issue is to only release
15189 tarballs for licenses that require the release of
15190 source.
15191 Let us assume you are only concerned with GPL code as
15192 identified by running the following script:
15193 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015194 # Script to archive a subset of packages matching specific license(s)
15195 # Source and license files are copied into sub folders of package folder
15196 # Must be run from build folder
15197 #!/bin/bash
15198 src_release_dir="source-release"
15199 mkdir -p $src_release_dir
15200 for a in tmp/deploy/sources/*; do
15201 for d in $a/*; do
15202 # Get package name from path
15203 p=`basename $d`
15204 p=${p%-*}
15205 p=${p%-*}
15206 # Only archive GPL packages (update *GPL* regex for your license check)
15207 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15208 if [ $numfiles -gt 1 ]; then
15209 echo Archiving $p
15210 mkdir -p $src_release_dir/$p/source
15211 cp $d/* $src_release_dir/$p/source 2> /dev/null
15212 mkdir -p $src_release_dir/$p/license
15213 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15214 fi
15215 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015216 done
15217 </literallayout>
15218 At this point, you could create a tarball from the
15219 <filename>gpl_source_release</filename> directory and
15220 provide that to the end user.
15221 This method would be a step toward achieving compliance
15222 with section 3a of GPLv2 and with section 6 of GPLv3.
15223 </para>
15224 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015225
Brad Bishop316dfdd2018-06-25 12:45:53 -040015226 <section id='providing-license-text'>
15227 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015228
Brad Bishop316dfdd2018-06-25 12:45:53 -040015229 <para>
15230 One requirement that is often overlooked is inclusion
15231 of license text.
15232 This requirement also needs to be dealt with prior to
15233 generating the final image.
15234 Some licenses require the license text to accompany
15235 the binary.
15236 You can achieve this by adding the following to your
15237 <filename>local.conf</filename> file:
15238 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015239 COPY_LIC_MANIFEST = "1"
15240 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015241 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015242 </literallayout>
15243 Adding these statements to the configuration file ensures
15244 that the licenses collected during package generation
15245 are included on your image.
15246 <note>
15247 <para>Setting all three variables to "1" results in the
15248 image having two copies of the same license file.
15249 One copy resides in
15250 <filename>/usr/share/common-licenses</filename> and
15251 the other resides in
15252 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015253
Brad Bishop316dfdd2018-06-25 12:45:53 -040015254 <para>The reason for this behavior is because
15255 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15256 and
15257 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15258 add a copy of the license when the image is built but do
15259 not offer a path for adding licenses for newly installed
15260 packages to an image.
15261 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15262 adds a separate package and an upgrade path for adding
15263 licenses to an image.</para>
15264 </note>
15265 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015266
Brad Bishop316dfdd2018-06-25 12:45:53 -040015267 <para>
15268 As the source <filename>archiver</filename> class has already
15269 archived the original
15270 unmodified source that contains the license files,
15271 you would have already met the requirements for inclusion
15272 of the license information with source as defined by the GPL
15273 and other open source licenses.
15274 </para>
15275 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015276
Brad Bishop316dfdd2018-06-25 12:45:53 -040015277 <section id='providing-compilation-scripts-and-source-code-modifications'>
15278 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015279
Brad Bishop316dfdd2018-06-25 12:45:53 -040015280 <para>
15281 At this point, we have addressed all we need to
15282 prior to generating the image.
15283 The next two requirements are addressed during the final
15284 packaging of the release.
15285 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015286
Brad Bishop316dfdd2018-06-25 12:45:53 -040015287 <para>
15288 By releasing the version of the OpenEmbedded build system
15289 and the layers used during the build, you will be providing both
15290 compilation scripts and the source code modifications in one
15291 step.
15292 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015293
Brad Bishop316dfdd2018-06-25 12:45:53 -040015294 <para>
15295 If the deployment team has a
15296 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15297 and a distro layer, and those those layers are used to patch,
15298 compile, package, or modify (in any way) any open source
15299 software included in your released images, you
15300 might be required to release those layers under section 3 of
15301 GPLv2 or section 1 of GPLv3.
15302 One way of doing that is with a clean
15303 checkout of the version of the Yocto Project and layers used
15304 during your build.
15305 Here is an example:
15306 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015307 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15308 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015309 $ cd poky
15310 # We built using the release_branch for our layers
15311 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15312 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15313 # clean up the .git repos
15314 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015315 </literallayout>
15316 One thing a development organization might want to consider
15317 for end-user convenience is to modify
15318 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15319 ensure that when the end user utilizes the released build
15320 system to build an image, the development organization's
15321 layers are included in the <filename>bblayers.conf</filename>
15322 file automatically:
15323 <literallayout class='monospaced'>
15324 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015325 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015326 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015327
15328 BBPATH = "${TOPDIR}"
15329 BBFILES ?= ""
15330
15331 BBLAYERS ?= " \
15332 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015333 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015334 ##OEROOT##/meta-yocto-bsp \
15335 ##OEROOT##/meta-mylayer \
15336 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015337 </literallayout>
15338 Creating and providing an archive of the
15339 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15340 layers (recipes, configuration files, and so forth)
15341 enables you to meet your
15342 requirements to include the scripts to control compilation
15343 as well as any modifications to the original source.
15344 </para>
15345 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015346 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015347
15348 <section id='copying-licenses-that-do-not-exist'>
15349 <title>Copying Licenses that Do Not Exist</title>
15350
15351 <para>
15352 Some packages, such as the linux-firmware package, have many
15353 licenses that are not in any way common.
15354 You can avoid adding a lot of these types of common license
15355 files, which are only applicable to a specific package, by using
15356 the
15357 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15358 variable.
15359 Using this variable also avoids QA errors when you use a
15360 non-common, non-CLOSED license in a recipe.
15361 </para>
15362
15363 <para>
15364 The following is an example that uses the
15365 <filename>LICENSE.Abilis.txt</filename>
15366 file as the license from the fetched source:
15367 <literallayout class='monospaced'>
15368 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15369 </literallayout>
15370 </para>
15371 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015372 </section>
15373
15374 <section id='using-the-error-reporting-tool'>
15375 <title>Using the Error Reporting Tool</title>
15376
15377 <para>
15378 The error reporting tool allows you to
15379 submit errors encountered during builds to a central database.
15380 Outside of the build environment, you can use a web interface to
15381 browse errors, view statistics, and query for errors.
15382 The tool works using a client-server system where the client
15383 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015384 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015385 (e.g. <filename>poky</filename>).
15386 The server receives the information collected and saves it in a
15387 database.
15388 </para>
15389
15390 <para>
15391 A live instance of the error reporting server exists at
15392 <ulink url='http://errors.yoctoproject.org'></ulink>.
15393 This server exists so that when you want to get help with
15394 build failures, you can submit all of the information on the
15395 failure easily and then point to the URL in your bug report
15396 or send an email to the mailing list.
15397 <note>
15398 If you send error reports to this server, the reports become
15399 publicly visible.
15400 </note>
15401 </para>
15402
15403 <section id='enabling-and-using-the-tool'>
15404 <title>Enabling and Using the Tool</title>
15405
15406 <para>
15407 By default, the error reporting tool is disabled.
15408 You can enable it by inheriting the
15409 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15410 class by adding the following statement to the end of
15411 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015412 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015413 <literallayout class='monospaced'>
15414 INHERIT += "report-error"
15415 </literallayout>
15416 </para>
15417
15418 <para>
15419 By default, the error reporting feature stores information in
15420 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15421 However, you can specify a directory to use by adding the following
15422 to your <filename>local.conf</filename> file:
15423 <literallayout class='monospaced'>
15424 ERR_REPORT_DIR = "path"
15425 </literallayout>
15426 Enabling error reporting causes the build process to collect
15427 the errors and store them in a file as previously described.
15428 When the build system encounters an error, it includes a
15429 command as part of the console output.
15430 You can run the command to send the error file to the server.
15431 For example, the following command sends the errors to an
15432 upstream server:
15433 <literallayout class='monospaced'>
15434 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15435 </literallayout>
15436 In the previous example, the errors are sent to a public
15437 database available at
15438 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15439 used by the entire community.
15440 If you specify a particular server, you can send the errors
15441 to a different database.
15442 Use the following command for more information on available
15443 options:
15444 <literallayout class='monospaced'>
15445 $ send-error-report --help
15446 </literallayout>
15447 </para>
15448
15449 <para>
15450 When sending the error file, you are prompted to review the
15451 data being sent as well as to provide a name and optional
15452 email address.
15453 Once you satisfy these prompts, the command returns a link
15454 from the server that corresponds to your entry in the database.
15455 For example, here is a typical link:
15456 <literallayout class='monospaced'>
15457 http://errors.yoctoproject.org/Errors/Details/9522/
15458 </literallayout>
15459 Following the link takes you to a web interface where you can
15460 browse, query the errors, and view statistics.
15461 </para>
15462 </section>
15463
15464 <section id='disabling-the-tool'>
15465 <title>Disabling the Tool</title>
15466
15467 <para>
15468 To disable the error reporting feature, simply remove or comment
15469 out the following statement from the end of your
15470 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015471 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015472 <literallayout class='monospaced'>
15473 INHERIT += "report-error"
15474 </literallayout>
15475 </para>
15476 </section>
15477
15478 <section id='setting-up-your-own-error-reporting-server'>
15479 <title>Setting Up Your Own Error Reporting Server</title>
15480
15481 <para>
15482 If you want to set up your own error reporting server, you
15483 can obtain the code from the Git repository at
15484 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15485 Instructions on how to set it up are in the README document.
15486 </para>
15487 </section>
15488 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015489
15490 <section id="dev-using-wayland-and-weston">
15491 <title>Using Wayland and Weston</title>
15492
15493 <para>
15494 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15495 is a computer display server protocol that
15496 provides a method for compositing window managers to communicate
15497 directly with applications and video hardware and expects them to
15498 communicate with input hardware using other libraries.
15499 Using Wayland with supporting targets can result in better control
15500 over graphics frame rendering than an application might otherwise
15501 achieve.
15502 </para>
15503
15504 <para>
15505 The Yocto Project provides the Wayland protocol libraries and the
15506 reference
15507 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15508 compositor as part of its release.
15509 You can find the integrated packages in the
15510 <filename>meta</filename> layer of the
15511 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15512 Specifically, you can find the recipes that build both Wayland
15513 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15514 </para>
15515
15516 <para>
15517 You can build both the Wayland and Weston packages for use only
15518 with targets that accept the
15519 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15520 which is also known as Mesa DRI.
15521 This implies that you cannot build and use the packages if your
15522 target uses, for example, the
15523 <trademark class='registered'>Intel</trademark> Embedded Media
15524 and Graphics Driver
15525 (<trademark class='registered'>Intel</trademark> EMGD) that
15526 overrides Mesa DRI.
15527 <note>
15528 Due to lack of EGL support, Weston 1.0.3 will not run
15529 directly on the emulated QEMU hardware.
15530 However, this version of Weston will run under X emulation
15531 without issues.
15532 </note>
15533 </para>
15534
15535 <para>
15536 This section describes what you need to do to implement Wayland and
15537 use the Weston compositor when building an image for a supporting
15538 target.
15539 </para>
15540
15541 <section id="enabling-wayland-in-an-image">
15542 <title>Enabling Wayland in an Image</title>
15543
15544 <para>
15545 To enable Wayland, you need to enable it to be built and enable
15546 it to be included (installed) in the image.
15547 </para>
15548
15549 <section id="enable-building">
15550 <title>Building</title>
15551
15552 <para>
15553 To cause Mesa to build the <filename>wayland-egl</filename>
15554 platform and Weston to build Wayland with Kernel Mode
15555 Setting
15556 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15557 support, include the "wayland" flag in the
15558 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15559 statement in your <filename>local.conf</filename> file:
15560 <literallayout class='monospaced'>
15561 DISTRO_FEATURES_append = " wayland"
15562 </literallayout>
15563 <note>
15564 If X11 has been enabled elsewhere, Weston will build
15565 Wayland with X11 support
15566 </note>
15567 </para>
15568 </section>
15569
15570 <section id="enable-installation-in-an-image">
15571 <title>Installing</title>
15572
15573 <para>
15574 To install the Wayland feature into an image, you must
15575 include the following
15576 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15577 statement in your <filename>local.conf</filename> file:
15578 <literallayout class='monospaced'>
15579 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15580 </literallayout>
15581 </para>
15582 </section>
15583 </section>
15584
15585 <section id="running-weston">
15586 <title>Running Weston</title>
15587
15588 <para>
15589 To run Weston inside X11, enabling it as described earlier and
15590 building a Sato image is sufficient.
15591 If you are running your image under Sato, a Weston Launcher
15592 appears in the "Utility" category.
15593 </para>
15594
15595 <para>
15596 Alternatively, you can run Weston through the command-line
15597 interpretor (CLI), which is better suited for development work.
15598 To run Weston under the CLI, you need to do the following after
15599 your image is built:
15600 <orderedlist>
15601 <listitem><para>
15602 Run these commands to export
15603 <filename>XDG_RUNTIME_DIR</filename>:
15604 <literallayout class='monospaced'>
15605 mkdir -p /tmp/$USER-weston
15606 chmod 0700 /tmp/$USER-weston
15607 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15608 </literallayout>
15609 </para></listitem>
15610 <listitem><para>
15611 Launch Weston in the shell:
15612 <literallayout class='monospaced'>
15613 weston
15614 </literallayout></para></listitem>
15615 </orderedlist>
15616 </para>
15617 </section>
15618 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015619</chapter>
15620
15621<!--
15622vim: expandtab tw=80 ts=4
15623-->