blob: fe1bfba6cfc8fbbf9ae5b17f7d07586a3e7460fd [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.
192 This variable is a good way to indicate how
193 up-to-date your particular layer is.
194 </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.
3240 To delay script execution until boot time, use the following
3241 structure in the post-installation script:
3242 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003243 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003244 if [ x"$D" = "x" ]; then
3245 # Actions to carry out on the device go here
3246 else
3247 exit 1
3248 fi
3249 }
3250 </literallayout>
3251 </para>
3252
3253 <para>
3254 The previous example delays execution until the image boots
3255 again because the environment variable <filename>D</filename>
3256 points to the directory containing the image when
3257 the root filesystem is created at build time but is unset
3258 when executed on the first boot.
3259 </para>
3260
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003261 <para>
3262 If you have recipes that use <filename>pkg_postinst</filename>
3263 scripts and they require the use of non-standard native
3264 tools that have dependencies during rootfs construction, you
3265 need to use the
3266 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3267 variable in your recipe to list these tools.
3268 If you do not use this variable, the tools might be missing and
3269 execution of the post-installation script is deferred until
3270 first boot.
3271 Deferring the script to first boot is undesirable and for
3272 read-only rootfs impossible.
3273 </para>
3274
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003275 <note>
3276 Equivalent support for pre-install, pre-uninstall, and
3277 post-uninstall scripts exist by way of
3278 <filename>pkg_preinst</filename>,
3279 <filename>pkg_prerm</filename>, and
3280 <filename>pkg_postrm</filename>, respectively.
3281 These scrips work in exactly the same way as does
3282 <filename>pkg_postinst</filename> with the exception that they
3283 run at different times.
3284 Also, because of when they run, they are not applicable to
3285 being run at image creation time like
3286 <filename>pkg_postinst</filename>.
3287 </note>
3288 </section>
3289
3290 <section id='new-recipe-testing'>
3291 <title>Testing</title>
3292
3293 <para>
3294 The final step for completing your recipe is to be sure that
3295 the software you built runs correctly.
3296 To accomplish runtime testing, add the build's output
3297 packages to your image and test them on the target.
3298 </para>
3299
3300 <para>
3301 For information on how to customize your image by adding
3302 specific packages, see the
3303 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3304 section.
3305 </para>
3306 </section>
3307
3308 <section id='new-recipe-testing-examples'>
3309 <title>Examples</title>
3310
3311 <para>
3312 To help summarize how to write a recipe, this section provides
3313 some examples given various scenarios:
3314 <itemizedlist>
3315 <listitem><para>Recipes that use local files</para></listitem>
3316 <listitem><para>Using an Autotooled package</para></listitem>
3317 <listitem><para>Using a Makefile-based package</para></listitem>
3318 <listitem><para>Splitting an application into multiple packages</para></listitem>
3319 <listitem><para>Adding binaries to an image</para></listitem>
3320 </itemizedlist>
3321 </para>
3322
3323 <section id='new-recipe-single-c-file-package-hello-world'>
3324 <title>Single .c File Package (Hello World!)</title>
3325
3326 <para>
3327 Building an application from a single file that is stored
3328 locally (e.g. under <filename>files</filename>) requires
3329 a recipe that has the file listed in the
3330 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3331 variable.
3332 Additionally, you need to manually write the
3333 <filename>do_compile</filename> and
3334 <filename>do_install</filename> tasks.
3335 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3336 variable defines the directory containing the source code,
3337 which is set to
3338 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3339 in this case - the directory BitBake uses for the build.
3340 <literallayout class='monospaced'>
3341 SUMMARY = "Simple helloworld application"
3342 SECTION = "examples"
3343 LICENSE = "MIT"
3344 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3345
3346 SRC_URI = "file://helloworld.c"
3347
3348 S = "${WORKDIR}"
3349
3350 do_compile() {
3351 ${CC} helloworld.c -o helloworld
3352 }
3353
3354 do_install() {
3355 install -d ${D}${bindir}
3356 install -m 0755 helloworld ${D}${bindir}
3357 }
3358 </literallayout>
3359 </para>
3360
3361 <para>
3362 By default, the <filename>helloworld</filename>,
3363 <filename>helloworld-dbg</filename>, and
3364 <filename>helloworld-dev</filename> packages are built.
3365 For information on how to customize the packaging process,
3366 see the
3367 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3368 section.
3369 </para>
3370 </section>
3371
3372 <section id='new-recipe-autotooled-package'>
3373 <title>Autotooled Package</title>
3374 <para>
3375 Applications that use Autotools such as <filename>autoconf</filename> and
3376 <filename>automake</filename> require a recipe that has a source archive listed in
3377 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3378 also inherit the
3379 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3380 class, which contains the definitions of all the steps
3381 needed to build an Autotool-based application.
3382 The result of the build is automatically packaged.
3383 And, if the application uses NLS for localization, packages with local information are
3384 generated (one package per language).
3385 Following is one example: (<filename>hello_2.3.bb</filename>)
3386 <literallayout class='monospaced'>
3387 SUMMARY = "GNU Helloworld application"
3388 SECTION = "examples"
3389 LICENSE = "GPLv2+"
3390 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3391
3392 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3393
3394 inherit autotools gettext
3395 </literallayout>
3396 </para>
3397
3398 <para>
3399 The variable
3400 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3401 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003402 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3403 section in the Yocto Project Overview and Concepts Manual.
3404 You can quickly create Autotool-based recipes in a manner
3405 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003406 </para>
3407 </section>
3408
3409 <section id='new-recipe-makefile-based-package'>
3410 <title>Makefile-Based Package</title>
3411
3412 <para>
3413 Applications that use GNU <filename>make</filename> also require a recipe that has
3414 the source archive listed in
3415 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3416 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3417 starts the <filename>make</filename> command to compile the application.
3418 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003419 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3420 or
3421 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3422 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003423 BitBake passes these options into the GNU <filename>make</filename> invocation.
3424 Note that a <filename>do_install</filename> task is still required.
3425 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3426 </para>
3427
3428 <para>
3429 Some applications might require extra parameters to be passed to the compiler.
3430 For example, the application might need an additional header path.
3431 You can accomplish this by adding to the
3432 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3433 The following example shows this:
3434 <literallayout class='monospaced'>
3435 CFLAGS_prepend = "-I ${S}/include "
3436 </literallayout>
3437 </para>
3438
3439 <para>
3440 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3441 <literallayout class='monospaced'>
3442 SUMMARY = "Tools for managing memory technology devices"
3443 SECTION = "base"
3444 DEPENDS = "zlib lzo e2fsprogs util-linux"
3445 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3446 LICENSE = "GPLv2+"
3447 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3448 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3449
3450 # Use the latest version at 26 Oct, 2013
3451 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3452 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3453 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3454 "
3455
3456 PV = "1.5.1+git${SRCPV}"
3457
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003458 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003459
3460 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3461
3462 do_install () {
3463 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3464 }
3465
3466 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3467
3468 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3469 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3470 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3471
3472 PARALLEL_MAKE = ""
3473
3474 BBCLASSEXTEND = "native"
3475 </literallayout>
3476 </para>
3477 </section>
3478
3479 <section id='splitting-an-application-into-multiple-packages'>
3480 <title>Splitting an Application into Multiple Packages</title>
3481
3482 <para>
3483 You can use the variables
3484 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3485 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3486 to split an application into multiple packages.
3487 </para>
3488
3489 <para>
3490 Following is an example that uses the <filename>libxpm</filename> recipe.
3491 By default, this recipe generates a single package that contains the library along
3492 with a few binaries.
3493 You can modify the recipe to split the binaries into separate packages:
3494 <literallayout class='monospaced'>
3495 require xorg-lib-common.inc
3496
3497 SUMMARY = "Xpm: X Pixmap extension library"
3498 LICENSE = "BSD"
3499 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3500 DEPENDS += "libxext libsm libxt"
3501 PE = "1"
3502
3503 XORG_PN = "libXpm"
3504
3505 PACKAGES =+ "sxpm cxpm"
3506 FILES_cxpm = "${bindir}/cxpm"
3507 FILES_sxpm = "${bindir}/sxpm"
3508 </literallayout>
3509 </para>
3510
3511 <para>
3512 In the previous example, we want to ship the <filename>sxpm</filename>
3513 and <filename>cxpm</filename> binaries in separate packages.
3514 Since <filename>bindir</filename> would be packaged into the main
3515 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3516 package by default, we prepend the <filename>PACKAGES</filename>
3517 variable so additional package names are added to the start of list.
3518 This results in the extra <filename>FILES_*</filename>
3519 variables then containing information that define which files and
3520 directories go into which packages.
3521 Files included by earlier packages are skipped by latter packages.
3522 Thus, the main <filename>PN</filename> package
3523 does not include the above listed files.
3524 </para>
3525 </section>
3526
3527 <section id='packaging-externally-produced-binaries'>
3528 <title>Packaging Externally Produced Binaries</title>
3529
3530 <para>
3531 Sometimes, you need to add pre-compiled binaries to an
3532 image.
3533 For example, suppose that binaries for proprietary code
3534 exist, which are created by a particular division of a
3535 company.
3536 Your part of the company needs to use those binaries as
3537 part of an image that you are building using the
3538 OpenEmbedded build system.
3539 Since you only have the binaries and not the source code,
3540 you cannot use a typical recipe that expects to fetch the
3541 source specified in
3542 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3543 and then compile it.
3544 </para>
3545
3546 <para>
3547 One method is to package the binaries and then install them
3548 as part of the image.
3549 Generally, it is not a good idea to package binaries
3550 since, among other things, it can hinder the ability to
3551 reproduce builds and could lead to compatibility problems
3552 with ABI in the future.
3553 However, sometimes you have no choice.
3554 </para>
3555
3556 <para>
3557 The easiest solution is to create a recipe that uses
3558 the
3559 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3560 class and to be sure that you are using default locations
3561 for build artifacts.
3562 In most cases, the <filename>bin_package</filename> class
3563 handles "skipping" the configure and compile steps as well
3564 as sets things up to grab packages from the appropriate
3565 area.
3566 In particular, this class sets <filename>noexec</filename>
3567 on both the
3568 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3569 and
3570 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3571 tasks, sets
3572 <filename>FILES_${PN}</filename> to "/" so that it picks
3573 up all files, and sets up a
3574 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3575 task, which effectively copies all files from
3576 <filename>${S}</filename> to <filename>${D}</filename>.
3577 The <filename>bin_package</filename> class works well when
3578 the files extracted into <filename>${S}</filename> are
3579 already laid out in the way they should be laid out
3580 on the target.
3581 For more information on these variables, see the
3582 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3583 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3584 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3585 and
3586 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3587 variables in the Yocto Project Reference Manual's variable
3588 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003589 <note><title>Notes</title>
3590 <itemizedlist>
3591 <listitem><para>
3592 Using
3593 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3594 is a good idea even for components distributed
3595 in binary form, and is often necessary for
3596 shared libraries.
3597 For a shared library, listing the library
3598 dependencies in
3599 <filename>DEPENDS</filename> makes sure that
3600 the libraries are available in the staging
3601 sysroot when other recipes link against the
3602 library, which might be necessary for
3603 successful linking.
3604 </para></listitem>
3605 <listitem><para>
3606 Using <filename>DEPENDS</filename> also
3607 allows runtime dependencies between packages
3608 to be added automatically.
3609 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003610 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3611 section in the Yocto Project Overview and
3612 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003613 </para></listitem>
3614 </itemizedlist>
3615 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003616 </para>
3617
3618 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003619 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003620 class, you need to be sure you are doing the following:
3621 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003622 <listitem><para>
3623 Create a recipe where the
3624 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3625 and
3626 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3627 tasks do nothing:
3628 It is usually sufficient to just not define these
3629 tasks in the recipe, because the default
3630 implementations do nothing unless a Makefile is
3631 found in
3632 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3633 </para>
3634
3635 <para>If
3636 <filename>${S}</filename> might contain a Makefile,
3637 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003638 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003639 <filename>do_compile</filename> with custom
3640 versions, then you can use the
3641 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3642 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003643 <literallayout class='monospaced'>
3644 do_configure[noexec] = "1"
3645 do_compile[noexec] = "1"
3646 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003647 Unlike
3648 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3649 using the flag preserves the dependency chain from
3650 the
3651 <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>,
3652 and
3653 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3654 tasks to the
3655 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3656 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003657 </para></listitem>
3658 <listitem><para>Make sure your
3659 <filename>do_install</filename> task installs the
3660 binaries appropriately.
3661 </para></listitem>
3662 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003663 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3664 (usually
3665 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3666 to point to the files you have installed, which of
3667 course depends on where you have installed them
3668 and whether those files are in different locations
3669 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003670 </para></listitem>
3671 </itemizedlist>
3672 </para>
3673 </section>
3674 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003675
3676 <section id="following-recipe-style-guidelines">
3677 <title>Following Recipe Style Guidelines</title>
3678
3679 <para>
3680 When writing recipes, it is good to conform to existing
3681 style guidelines.
3682 The
3683 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3684 wiki page provides rough guidelines for preferred recipe style.
3685 </para>
3686
3687 <para>
3688 It is common for existing recipes to deviate a bit from this
3689 style.
3690 However, aiming for at least a consistent style is a good idea.
3691 Some practices, such as omitting spaces around
3692 <filename>=</filename> operators in assignments or ordering
3693 recipe components in an erratic way, are widely seen as poor
3694 style.
3695 </para>
3696 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003697
3698 <section id='recipe-syntax'>
3699 <title>Recipe Syntax</title>
3700
3701 <para>
3702 Understanding recipe file syntax is important for writing
3703 recipes.
3704 The following list overviews the basic items that make up a
3705 BitBake recipe file.
3706 For more complete BitBake syntax descriptions, see the
3707 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3708 chapter of the BitBake User Manual.
3709 <itemizedlist>
3710 <listitem><para>
3711 <emphasis>Variable Assignments and Manipulations:</emphasis>
3712 Variable assignments allow a value to be assigned to a
3713 variable.
3714 The assignment can be static text or might include
3715 the contents of other variables.
3716 In addition to the assignment, appending and prepending
3717 operations are also supported.</para>
3718
3719 <para>The following example shows some of the ways
3720 you can use variables in recipes:
3721 <literallayout class='monospaced'>
3722 S = "${WORKDIR}/postfix-${PV}"
3723 CFLAGS += "-DNO_ASM"
3724 SRC_URI_append = " file://fixup.patch"
3725 </literallayout>
3726 </para></listitem>
3727 <listitem><para>
3728 <emphasis>Functions:</emphasis>
3729 Functions provide a series of actions to be performed.
3730 You usually use functions to override the default
3731 implementation of a task function or to complement
3732 a default function (i.e. append or prepend to an
3733 existing function).
3734 Standard functions use <filename>sh</filename> shell
3735 syntax, although access to OpenEmbedded variables and
3736 internal methods are also available.</para>
3737
3738 <para>The following is an example function from the
3739 <filename>sed</filename> recipe:
3740 <literallayout class='monospaced'>
3741 do_install () {
3742 autotools_do_install
3743 install -d ${D}${base_bindir}
3744 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3745 rmdir ${D}${bindir}/
3746 }
3747 </literallayout>
3748 It is also possible to implement new functions that
3749 are called between existing tasks as long as the
3750 new functions are not replacing or complementing the
3751 default functions.
3752 You can implement functions in Python
3753 instead of shell.
3754 Both of these options are not seen in the majority of
3755 recipes.
3756 </para></listitem>
3757 <listitem><para><emphasis>Keywords:</emphasis>
3758 BitBake recipes use only a few keywords.
3759 You use keywords to include common
3760 functions (<filename>inherit</filename>), load parts
3761 of a recipe from other files
3762 (<filename>include</filename> and
3763 <filename>require</filename>) and export variables
3764 to the environment (<filename>export</filename>).
3765 </para>
3766
3767 <para>The following example shows the use of some of
3768 these keywords:
3769 <literallayout class='monospaced'>
3770 export POSTCONF = "${STAGING_BINDIR}/postconf"
3771 inherit autoconf
3772 require otherfile.inc
3773 </literallayout>
3774 </para></listitem>
3775 <listitem><para>
3776 <emphasis>Comments (#):</emphasis>
3777 Any lines that begin with the hash character
3778 (<filename>#</filename>) are treated as comment lines
3779 and are ignored:
3780 <literallayout class='monospaced'>
3781 # This is a comment
3782 </literallayout>
3783 </para></listitem>
3784 </itemizedlist>
3785 </para>
3786
3787 <para>
3788 This next list summarizes the most important and most commonly
3789 used parts of the recipe syntax.
3790 For more information on these parts of the syntax, you can
3791 reference the
3792 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3793 chapter in the BitBake User Manual.
3794 <itemizedlist>
3795 <listitem><para>
3796 <emphasis>Line Continuation (\):</emphasis>
3797 Use the backward slash (<filename>\</filename>)
3798 character to split a statement over multiple lines.
3799 Place the slash character at the end of the line that
3800 is to be continued on the next line:
3801 <literallayout class='monospaced'>
3802 VAR = "A really long \
3803 line"
3804 </literallayout>
3805 <note>
3806 You cannot have any characters including spaces
3807 or tabs after the slash character.
3808 </note>
3809 </para></listitem>
3810 <listitem><para>
3811 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3812 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3813 syntax to access the contents of a variable:
3814 <literallayout class='monospaced'>
3815 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3816 </literallayout>
3817 <note>
3818 It is important to understand that the value of a
3819 variable expressed in this form does not get
3820 substituted automatically.
3821 The expansion of these expressions happens
3822 on-demand later (e.g. usually when a function that
3823 makes reference to the variable executes).
3824 This behavior ensures that the values are most
3825 appropriate for the context in which they are
3826 finally used.
3827 On the rare occasion that you do need the variable
3828 expression to be expanded immediately, you can use
3829 the <filename>:=</filename> operator instead of
3830 <filename>=</filename> when you make the
3831 assignment, but this is not generally needed.
3832 </note>
3833 </para></listitem>
3834 <listitem><para>
3835 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3836 Use double quotes around values in all variable
3837 assignments (e.g.
3838 <filename>"<replaceable>value</replaceable>"</filename>).
3839 Following is an example:
3840 <literallayout class='monospaced'>
3841 VAR1 = "${OTHERVAR}"
3842 VAR2 = "The version is ${PV}"
3843 </literallayout>
3844 </para></listitem>
3845 <listitem><para>
3846 <emphasis>Conditional Assignment (?=):</emphasis>
3847 Conditional assignment is used to assign a
3848 value to a variable, but only when the variable is
3849 currently unset.
3850 Use the question mark followed by the equal sign
3851 (<filename>?=</filename>) to make a "soft" assignment
3852 used for conditional assignment.
3853 Typically, "soft" assignments are used in the
3854 <filename>local.conf</filename> file for variables
3855 that are allowed to come through from the external
3856 environment.
3857 </para>
3858
3859 <para>Here is an example where
3860 <filename>VAR1</filename> is set to "New value" if
3861 it is currently empty.
3862 However, if <filename>VAR1</filename> has already been
3863 set, it remains unchanged:
3864 <literallayout class='monospaced'>
3865 VAR1 ?= "New value"
3866 </literallayout>
3867 In this next example, <filename>VAR1</filename>
3868 is left with the value "Original value":
3869 <literallayout class='monospaced'>
3870 VAR1 = "Original value"
3871 VAR1 ?= "New value"
3872 </literallayout>
3873 </para></listitem>
3874 <listitem><para>
3875 <emphasis>Appending (+=):</emphasis>
3876 Use the plus character followed by the equals sign
3877 (<filename>+=</filename>) to append values to existing
3878 variables.
3879 <note>
3880 This operator adds a space between the existing
3881 content of the variable and the new content.
3882 </note></para>
3883
3884 <para>Here is an example:
3885 <literallayout class='monospaced'>
3886 SRC_URI += "file://fix-makefile.patch"
3887 </literallayout>
3888 </para></listitem>
3889 <listitem><para>
3890 <emphasis>Prepending (=+):</emphasis>
3891 Use the equals sign followed by the plus character
3892 (<filename>=+</filename>) to prepend values to existing
3893 variables.
3894 <note>
3895 This operator adds a space between the new content
3896 and the existing content of the variable.
3897 </note></para>
3898
3899 <para>Here is an example:
3900 <literallayout class='monospaced'>
3901 VAR =+ "Starts"
3902 </literallayout>
3903 </para></listitem>
3904 <listitem><para>
3905 <emphasis>Appending (_append):</emphasis>
3906 Use the <filename>_append</filename> operator to
3907 append values to existing variables.
3908 This operator does not add any additional space.
3909 Also, the operator is applied after all the
3910 <filename>+=</filename>, and
3911 <filename>=+</filename> operators have been applied and
3912 after all <filename>=</filename> assignments have
3913 occurred.
3914 </para>
3915
3916 <para>The following example shows the space being
3917 explicitly added to the start to ensure the appended
3918 value is not merged with the existing value:
3919 <literallayout class='monospaced'>
3920 SRC_URI_append = " file://fix-makefile.patch"
3921 </literallayout>
3922 You can also use the <filename>_append</filename>
3923 operator with overrides, which results in the actions
3924 only being performed for the specified target or
3925 machine:
3926 <literallayout class='monospaced'>
3927 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3928 </literallayout>
3929 </para></listitem>
3930 <listitem><para>
3931 <emphasis>Prepending (_prepend):</emphasis>
3932 Use the <filename>_prepend</filename> operator to
3933 prepend values to existing variables.
3934 This operator does not add any additional space.
3935 Also, the operator is applied after all the
3936 <filename>+=</filename>, and
3937 <filename>=+</filename> operators have been applied and
3938 after all <filename>=</filename> assignments have
3939 occurred.
3940 </para>
3941
3942 <para>The following example shows the space being
3943 explicitly added to the end to ensure the prepended
3944 value is not merged with the existing value:
3945 <literallayout class='monospaced'>
3946 CFLAGS_prepend = "-I${S}/myincludes "
3947 </literallayout>
3948 You can also use the <filename>_prepend</filename>
3949 operator with overrides, which results in the actions
3950 only being performed for the specified target or
3951 machine:
3952 <literallayout class='monospaced'>
3953 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
3954 </literallayout>
3955 </para></listitem>
3956 <listitem><para>
3957 <emphasis>Overrides:</emphasis>
3958 You can use overrides to set a value conditionally,
3959 typically based on how the recipe is being built.
3960 For example, to set the
3961 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
3962 variable's value to "standard/base" for any target
3963 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
3964 except for qemuarm where it should be set to
3965 "standard/arm-versatile-926ejs", you would do the
3966 following:
3967 <literallayout class='monospaced'>
3968 KBRANCH = "standard/base"
3969 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
3970 </literallayout>
3971 Overrides are also used to separate alternate values
3972 of a variable in other situations.
3973 For example, when setting variables such as
3974 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3975 and
3976 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
3977 that are specific to individual packages produced by
3978 a recipe, you should always use an override that
3979 specifies the name of the package.
3980 </para></listitem>
3981 <listitem><para>
3982 <emphasis>Indentation:</emphasis>
3983 Use spaces for indentation rather than than tabs.
3984 For shell functions, both currently work.
3985 However, it is a policy decision of the Yocto Project
3986 to use tabs in shell functions.
3987 Realize that some layers have a policy to use spaces
3988 for all indentation.
3989 </para></listitem>
3990 <listitem><para>
3991 <emphasis>Using Python for Complex Operations:</emphasis>
3992 For more advanced processing, it is possible to use
3993 Python code during variable assignments (e.g.
3994 search and replacement on a variable).</para>
3995
3996 <para>You indicate Python code using the
3997 <filename>${@<replaceable>python_code</replaceable>}</filename>
3998 syntax for the variable assignment:
3999 <literallayout class='monospaced'>
4000 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
4001 </literallayout>
4002 </para></listitem>
4003 <listitem><para>
4004 <emphasis>Shell Function Syntax:</emphasis>
4005 Write shell functions as if you were writing a shell
4006 script when you describe a list of actions to take.
4007 You should ensure that your script works with a generic
4008 <filename>sh</filename> and that it does not require
4009 any <filename>bash</filename> or other shell-specific
4010 functionality.
4011 The same considerations apply to various system
4012 utilities (e.g. <filename>sed</filename>,
4013 <filename>grep</filename>, <filename>awk</filename>,
4014 and so forth) that you might wish to use.
4015 If in doubt, you should check with multiple
4016 implementations - including those from BusyBox.
4017 </para></listitem>
4018 </itemizedlist>
4019 </para>
4020 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004021 </section>
4022
4023 <section id="platdev-newmachine">
4024 <title>Adding a New Machine</title>
4025
4026 <para>
4027 Adding a new machine to the Yocto Project is a straightforward
4028 process.
4029 This section describes how to add machines that are similar
4030 to those that the Yocto Project already supports.
4031 <note>
4032 Although well within the capabilities of the Yocto Project,
4033 adding a totally new architecture might require
4034 changes to <filename>gcc/glibc</filename> and to the site
4035 information, which is beyond the scope of this manual.
4036 </note>
4037 </para>
4038
4039 <para>
4040 For a complete example that shows how to add a new machine,
4041 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004042 "<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>"
4043 section in the Yocto Project Board Support Package (BSP)
4044 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004045 </para>
4046
4047 <section id="platdev-newmachine-conffile">
4048 <title>Adding the Machine Configuration File</title>
4049
4050 <para>
4051 To add a new machine, you need to add a new machine
4052 configuration file to the layer's
4053 <filename>conf/machine</filename> directory.
4054 This configuration file provides details about the device
4055 you are adding.
4056 </para>
4057
4058 <para>
4059 The OpenEmbedded build system uses the root name of the
4060 machine configuration file to reference the new machine.
4061 For example, given a machine configuration file named
4062 <filename>crownbay.conf</filename>, the build system
4063 recognizes the machine as "crownbay".
4064 </para>
4065
4066 <para>
4067 The most important variables you must set in your machine
4068 configuration file or include from a lower-level configuration
4069 file are as follows:
4070 <itemizedlist>
4071 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4072 (e.g. "arm")</para></listitem>
4073 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4074 </para></listitem>
4075 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4076 (e.g. "apm screen wifi")</para></listitem>
4077 </itemizedlist>
4078 </para>
4079
4080 <para>
4081 You might also need these variables:
4082 <itemizedlist>
4083 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4084 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4085 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4086 (e.g. "zImage")</para></listitem>
4087 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4088 (e.g. "tar.gz jffs2")</para></listitem>
4089 </itemizedlist>
4090 </para>
4091
4092 <para>
4093 You can find full details on these variables in the reference
4094 section.
4095 You can leverage existing machine <filename>.conf</filename>
4096 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4097 </para>
4098 </section>
4099
4100 <section id="platdev-newmachine-kernel">
4101 <title>Adding a Kernel for the Machine</title>
4102
4103 <para>
4104 The OpenEmbedded build system needs to be able to build a kernel
4105 for the machine.
4106 You need to either create a new kernel recipe for this machine,
4107 or extend an existing kernel recipe.
4108 You can find several kernel recipe examples in the
4109 Source Directory at
4110 <filename>meta/recipes-kernel/linux</filename>
4111 that you can use as references.
4112 </para>
4113
4114 <para>
4115 If you are creating a new kernel recipe, normal recipe-writing
4116 rules apply for setting up a
4117 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4118 Thus, you need to specify any necessary patches and set
4119 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4120 to point at the source code.
4121 You need to create a <filename>do_configure</filename> task that
4122 configures the unpacked kernel with a
4123 <filename>defconfig</filename> file.
4124 You can do this by using a <filename>make defconfig</filename>
4125 command or, more commonly, by copying in a suitable
4126 <filename>defconfig</filename> file and then running
4127 <filename>make oldconfig</filename>.
4128 By making use of <filename>inherit kernel</filename> and
4129 potentially some of the <filename>linux-*.inc</filename> files,
4130 most other functionality is centralized and the defaults of the
4131 class normally work well.
4132 </para>
4133
4134 <para>
4135 If you are extending an existing kernel recipe, it is usually
4136 a matter of adding a suitable <filename>defconfig</filename>
4137 file.
4138 The file needs to be added into a location similar to
4139 <filename>defconfig</filename> files used for other machines
4140 in a given kernel recipe.
4141 A possible way to do this is by listing the file in the
4142 <filename>SRC_URI</filename> and adding the machine to the
4143 expression in
4144 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4145 <literallayout class='monospaced'>
4146 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4147 </literallayout>
4148 For more information on <filename>defconfig</filename> files,
4149 see the
4150 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4151 section in the Yocto Project Linux Kernel Development Manual.
4152 </para>
4153 </section>
4154
4155 <section id="platdev-newmachine-formfactor">
4156 <title>Adding a Formfactor Configuration File</title>
4157
4158 <para>
4159 A formfactor configuration file provides information about the
4160 target hardware for which the image is being built and information that
4161 the build system cannot obtain from other sources such as the kernel.
4162 Some examples of information contained in a formfactor configuration file include
4163 framebuffer orientation, whether or not the system has a keyboard,
4164 the positioning of the keyboard in relation to the screen, and
4165 the screen resolution.
4166 </para>
4167
4168 <para>
4169 The build system uses reasonable defaults in most cases.
4170 However, if customization is
4171 necessary, you need to create a <filename>machconfig</filename> file
4172 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4173 directory.
4174 This directory contains directories for specific machines such as
4175 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4176 For information about the settings available and the defaults, see the
4177 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4178 same area.
4179 </para>
4180
4181 <para>
4182 Following is an example for "qemuarm" machine:
4183 <literallayout class='monospaced'>
4184 HAVE_TOUCHSCREEN=1
4185 HAVE_KEYBOARD=1
4186
4187 DISPLAY_CAN_ROTATE=0
4188 DISPLAY_ORIENTATION=0
4189 #DISPLAY_WIDTH_PIXELS=640
4190 #DISPLAY_HEIGHT_PIXELS=480
4191 #DISPLAY_BPP=16
4192 DISPLAY_DPI=150
4193 DISPLAY_SUBPIXEL_ORDER=vrgb
4194 </literallayout>
4195 </para>
4196 </section>
4197 </section>
4198
Brad Bishop316dfdd2018-06-25 12:45:53 -04004199 <section id='gs-upgrading-recipes'>
4200 <title>Upgrading Recipes</title>
4201
4202 <para>
4203 Over time, upstream developers publish new versions for software
4204 built by layer recipes.
4205 It is recommended to keep recipes up-to-date with upstream
4206 version releases.
4207 You can use the Automated Upgrade Helper (AUH) to set up
4208 automatic version upgrades.
4209 Alternatively, you can use <filename>devtool upgrade</filename>
4210 to set up semi-automatic version upgrades.
4211 Finally, you can even manually upgrade a recipe by editing the
4212 recipe itself.
4213 </para>
4214
4215 <section id='gs-using-the-auto-upgrade-helper'>
4216 <title>Using the Auto Upgrade Helper (AUH)</title>
4217
4218 <para>
4219 The AUH utility works in conjunction with the
4220 OpenEmbedded build system in order to automatically generate
4221 upgrades for recipes based on new versions being
4222 published upstream.
4223 Use AUH when you want to create a service that performs the
4224 upgrades automatically and optionally sends you an email with
4225 the results.
4226 </para>
4227
4228 <para>
4229 AUH allows you to update several recipes with a single use.
4230 You can also optionally perform build and integration tests
4231 using images with the results saved to your hard drive and
4232 emails of results optionally sent to recipe maintainers.
4233 Finally, AUH creates Git commits with appropriate commit
4234 messages in the layer's tree for the changes made to recipes.
4235 <note>
4236 Conditions do exist when you should not use AUH to upgrade
4237 recipes and you should instead use either
4238 <filename>devtool upgrade</filename> or upgrade your
4239 recipes manually:
4240 <itemizedlist>
4241 <listitem><para>
4242 When AUH cannot complete the upgrade sequence.
4243 This situation usually results because custom
4244 patches carried by the recipe cannot be
4245 automatically rebased to the new version.
4246 In this case, <filename>devtool upgrade</filename>
4247 allows you to manually resolve conflicts.
4248 </para></listitem>
4249 <listitem><para>
4250 When for any reason you want fuller control over
4251 the upgrade process.
4252 For example, when you want special arrangements
4253 for testing.
4254 </para></listitem>
4255 </itemizedlist>
4256 </note>
4257 </para>
4258
4259 <para>
4260 The following steps describe how to set up the AUH utility:
4261 <orderedlist>
4262 <listitem><para>
4263 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4264 You need to be sure that your development host is
4265 set up to use the Yocto Project.
4266 For information on how to set up your host, see the
4267 "<link linkend='setting-up-the-development-host-to-use-the-yocto-project'>Preparing the Build Host</link>"
4268 section.
4269 </para></listitem>
4270 <listitem><para>
4271 <emphasis>Make Sure Git is Configured:</emphasis>
4272 The AUH utility requires Git to be configured because
4273 AUH uses Git to save upgrades.
4274 Thus, you must have Git user and email configured.
4275 The following command shows your configurations:
4276 <literallayout class='monospaced'>
4277 $ git config --list
4278 </literallayout>
4279 If you do not have the user and email configured, you
4280 can use the following commands to do so:
4281 <literallayout class='monospaced'>
4282 $ git config --global user.name <replaceable>some_name</replaceable>
4283 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4284 </literallayout>
4285 </para></listitem>
4286 <listitem><para>
4287 <emphasis>Clone the AUH Repository:</emphasis>
4288 To use AUH, you must clone the repository onto your
4289 development host.
4290 The following command uses Git to create a local
4291 copy of the repository on your system:
4292 <literallayout class='monospaced'>
4293 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4294 Cloning into 'auto-upgrade-helper'...
4295 remote: Counting objects: 768, done.
4296 remote: Compressing objects: 100% (300/300), done.
4297 remote: Total 768 (delta 499), reused 703 (delta 434)
4298 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4299 Resolving deltas: 100% (499/499), done.
4300 Checking connectivity... done.
4301 </literallayout>
4302 AUH is not part of the
4303 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4304 or
4305 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4306 repositories.
4307 </para></listitem>
4308 <listitem><para>
4309 <emphasis>Create a Dedicated Build Directory:</emphasis>
4310 Run the
4311 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4312 script to create a fresh build directory that you
4313 use exclusively for running the AUH utility:
4314 <literallayout class='monospaced'>
4315 $ cd ~/poky
4316 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4317 </literallayout>
4318 Re-using an existing build directory and its
4319 configurations is not recommended as existing settings
4320 could cause AUH to fail or behave undesirably.
4321 </para></listitem>
4322 <listitem><para>
4323 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4324 Several settings need to exist in the
4325 <filename>local.conf</filename> file in the build
4326 directory you just created for AUH.
4327 Make these following configurations:
4328 <itemizedlist>
4329 <listitem><para>
4330 Enable "distrodata" as follows:
4331 <literallayout class='monospaced'>
4332 INHERIT =+ "distrodata"
4333 </literallayout>
4334 </para></listitem>
4335 <listitem><para>
4336 If you want to enable
4337 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4338 which is optional, you need the following
4339 lines in the
4340 <filename>conf/local.conf</filename> file:
4341 <literallayout class='monospaced'>
4342 INHERIT =+ "buildhistory"
4343 BUILDHISTORY_COMMIT = "1"
4344 </literallayout>
4345 With this configuration and a successful
4346 upgrade, a build history "diff" file appears in
4347 the
4348 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4349 file found in your build directory.
4350 </para></listitem>
4351 <listitem><para>
4352 If you want to enable testing through the
4353 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4354 class, which is optional, you need to have the
4355 following set in your
4356 <filename>conf/local.conf</filename> file:
4357 <literallayout class='monospaced'>
4358 INHERIT += "testimage"
4359 </literallayout>
4360 <note>
4361 If your distro does not enable by default
4362 ptest, which Poky does, you need the
4363 following in your
4364 <filename>local.conf</filename> file:
4365 <literallayout class='monospaced'>
4366 DISTRO_FEATURES_append = " ptest"
4367 </literallayout>
4368 </note>
4369 </para></listitem>
4370 </itemizedlist>
4371 </para></listitem>
4372 <listitem><para>
4373 <emphasis>Optionally Start a vncserver:</emphasis>
4374 If you are running in a server without an X11 session,
4375 you need to start a vncserver:
4376 <literallayout class='monospaced'>
4377 $ vncserver :1
4378 $ export DISPLAY=:1
4379 </literallayout>
4380 </para></listitem>
4381 <listitem><para>
4382 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4383 You need to have the
4384 <filename>upgrade-helper/upgrade-helper.conf</filename>
4385 configuration file in your build directory.
4386 You can find a sample configuration file in the
4387 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4388 </para>
4389
4390 <para>Read through the sample file and make
4391 configurations as needed.
4392 For example, if you enabled build history in your
4393 <filename>local.conf</filename> as described earlier,
4394 you must enable it in
4395 <filename>upgrade-helper.conf</filename>.</para>
4396
4397 <para>Also, if you are using the default
4398 <filename>maintainers.inc</filename> file supplied
4399 with Poky and located in
4400 <filename>meta-yocto</filename> and you do not set a
4401 "maintainers_whitelist" or "global_maintainer_override"
4402 in the <filename>upgrade-helper.conf</filename>
4403 configuration, and you specify "-e all" on the
4404 AUH command-line, the utility automatically sends out
4405 emails to all the default maintainers.
4406 Please avoid this.
4407 </para></listitem>
4408 </orderedlist>
4409 </para>
4410
4411 <para>
4412 This next set of examples describes how to use the AUH:
4413 <itemizedlist>
4414 <listitem><para>
4415 <emphasis>Upgrading a Specific Recipe:</emphasis>
4416 To upgrade a specific recipe, use the following
4417 form:
4418 <literallayout class='monospaced'>
4419 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4420 </literallayout>
4421 For example, this command upgrades the
4422 <filename>xmodmap</filename> recipe:
4423 <literallayout class='monospaced'>
4424 $ upgrade-helper.py xmodmap
4425 </literallayout>
4426 </para></listitem>
4427 <listitem><para>
4428 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4429 To upgrade a specific recipe to a particular version,
4430 use the following form:
4431 <literallayout class='monospaced'>
4432 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4433 </literallayout>
4434 For example, this command upgrades the
4435 <filename>xmodmap</filename> recipe to version
4436 1.2.3:
4437 <literallayout class='monospaced'>
4438 $ upgrade-helper.py xmodmap -t 1.2.3
4439 </literallayout>
4440 </para></listitem>
4441 <listitem><para>
4442 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4443 To upgrade all recipes to their most recent versions
4444 and suppress the email notifications, use the following
4445 command:
4446 <literallayout class='monospaced'>
4447 $ upgrade-helper.py all
4448 </literallayout>
4449 </para></listitem>
4450 <listitem><para>
4451 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4452 To upgrade all recipes to their most recent versions
4453 and send email messages to maintainers for each
4454 attempted recipe as well as a status email, use the
4455 following command:
4456 <literallayout class='monospaced'>
4457 $ upgrade-helper.py -e all
4458 </literallayout>
4459 </para></listitem>
4460 </itemizedlist>
4461 </para>
4462
4463 <para>
4464 Once you have run the AUH utility, you can find the results
4465 in the AUH build directory:
4466 <literallayout class='monospaced'>
4467 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4468 </literallayout>
4469 The AUH utility also creates recipe update commits from
4470 successful upgrade attempts in the layer tree.
4471 </para>
4472
4473 <para>
4474 You can easily set up to run the AUH utility on a regular
4475 basis by using a cron job.
4476 See the
4477 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4478 file distributed with the utility for an example.
4479 </para>
4480 </section>
4481
4482 <section id='gs-using-devtool-upgrade'>
4483 <title>Using <filename>devtool upgrade</filename></title>
4484
4485 <para>
4486 As mentioned earlier, an alternative method for upgrading
4487 recipes to newer versions is to use
4488 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4489 You can read about <filename>devtool upgrade</filename> in
4490 general in the
4491 "<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>"
4492 section in the Yocto Project Application Development and the
4493 Extensible Software Development Kit (eSDK) Manual.
4494 </para>
4495
4496 <para>
4497 To see all the command-line options available with
4498 <filename>devtool upgrade</filename>, use the following help
4499 command:
4500 <literallayout class='monospaced'>
4501 $ devtool upgrade -h
4502 </literallayout>
4503 </para>
4504
4505 <para>
4506 If you want to find out what version a recipe is currently at
4507 upstream without any attempt to upgrade your local version of
4508 the recipe, you can use the following command:
4509 <literallayout class='monospaced'>
4510 $ devtool latest-version <replaceable>recipe_name</replaceable>
4511 </literallayout>
4512 </para>
4513
4514 <para>
4515 As mentioned in the previous section describing AUH,
4516 <filename>devtool upgrade</filename> works in a
4517 less-automated manner than AUH.
4518 Specifically, <filename>devtool upgrade</filename> only
4519 works on a single recipe that you name on the command line,
4520 cannot perform build and integration testing using images,
4521 and does not automatically generate commits for changes in
4522 the source tree.
4523 Despite all these "limitations",
4524 <filename>devtool upgrade</filename> updates the recipe file
4525 to the new upstream version and attempts to rebase custom
4526 patches contained by the recipe as needed.
4527 <note>
4528 AUH uses much of <filename>devtool upgrade</filename>
4529 behind the scenes making AUH somewhat of a "wrapper"
4530 application for <filename>devtool upgrade</filename>.
4531 </note>
4532 </para>
4533
4534 <para>
4535 A typical scenario involves having used Git to clone an
4536 upstream repository that you use during build operations.
4537 Because you are (or have) built the recipe in the past, the
4538 layer is likely added to your configuration already.
4539 If for some reason, the layer is not added, you could add
4540 it easily using the
4541 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4542 script.
4543 For example, suppose you use the <filename>nano.bb</filename>
4544 recipe from the <filename>meta-oe</filename> layer in the
4545 <filename>meta-openembedded</filename> repository.
4546 For this example, assume that the layer has been cloned into
4547 following area:
4548 <literallayout class='monospaced'>
4549 /home/scottrif/meta-openembedded
4550 </literallayout>
4551 The following command from your
4552 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4553 adds the layer to your build configuration (i.e.
4554 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4555 <literallayout class='monospaced'>
4556 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4557 NOTE: Starting bitbake server...
4558 Parsing recipes: 100% |##########################################| Time: 0:00:55
4559 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4560 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4561 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4562 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4563 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4564 </literallayout>
4565 For this example, assume that the <filename>nano.bb</filename>
4566 recipe that is upstream has a 2.9.3 version number.
4567 However, the version in the local repository is 2.7.4.
4568 The following command from your build directory automatically
4569 upgrades the recipe for you:
4570 <note>
4571 Using the <filename>-V</filename> option is not necessary.
4572 Omitting the version number causes
4573 <filename>devtool upgrade</filename> to upgrade the recipe
4574 to the most recent version.
4575 </note>
4576 <literallayout class='monospaced'>
4577 $ devtool upgrade nano -V 2.9.3
4578 NOTE: Starting bitbake server...
4579 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4580 Parsing recipes: 100% |##########################################| Time: 0:00:46
4581 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4582 NOTE: Extracting current version source...
4583 NOTE: Resolving any missing task queue dependencies
4584 .
4585 .
4586 .
4587 NOTE: Executing SetScene Tasks
4588 NOTE: Executing RunQueue Tasks
4589 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4590 Adding changed files: 100% |#####################################| Time: 0:00:00
4591 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4592 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4593 </literallayout>
4594 Continuing with this example, you can use
4595 <filename>devtool build</filename> to build the newly upgraded
4596 recipe:
4597 <literallayout class='monospaced'>
4598 $ devtool build nano
4599 NOTE: Starting bitbake server...
4600 Loading cache: 100% |################################################################################################| Time: 0:00:01
4601 Loaded 2040 entries from dependency cache.
4602 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4603 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4604 NOTE: Resolving any missing task queue dependencies
4605 .
4606 .
4607 .
4608 NOTE: Executing SetScene Tasks
4609 NOTE: Executing RunQueue Tasks
4610 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4611 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4612 </literallayout>
4613 Within the <filename>devtool upgrade</filename> workflow,
4614 opportunity exists to deploy and test your rebuilt software.
4615 For this example, however, running
4616 <filename>devtool finish</filename> cleans up the workspace
4617 once the source in your workspace is clean.
4618 This usually means using Git to stage and submit commits
4619 for the changes generated by the upgrade process.
4620 </para>
4621
4622 <para>
4623 Once the tree is clean, you can clean things up in this
4624 example with the following command from the
4625 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4626 directory:
4627 <literallayout class='monospaced'>
4628 $ devtool finish nano meta-oe
4629 NOTE: Starting bitbake server...
4630 Loading cache: 100% |################################################################################################| Time: 0:00:00
4631 Loaded 2040 entries from dependency cache.
4632 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4633 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4634 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4635 NOTE: Updating recipe nano_2.9.3.bb
4636 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4637 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4638 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4639 </literallayout>
4640 Using the <filename>devtool finish</filename> command cleans
4641 up the workspace and creates a patch file based on your
4642 commits.
4643 The tool puts all patch files back into the source directory
4644 in a sub-directory named <filename>nano</filename> in this
4645 case.
4646 </para>
4647 </section>
4648
4649 <section id='dev-manually-upgrading-a-recipe'>
4650 <title>Manually Upgrading a Recipe</title>
4651
4652 <para>
4653 If for some reason you choose not to upgrade recipes using the
4654 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4655 or by using
4656 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4657 you can manually edit the recipe files to upgrade the versions.
4658 <note><title>Caution</title>
4659 Manually updating multiple recipes scales poorly and
4660 involves many steps.
4661 The recommendation to upgrade recipe versions is through
4662 AUH or <filename>devtool upgrade</filename>, both of which
4663 automate some steps and provide guidance for others needed
4664 for the manual process.
4665 </note>
4666 </para>
4667
4668 <para>
4669 To manually upgrade recipe versions, follow these general steps:
4670 <orderedlist>
4671 <listitem><para>
4672 <emphasis>Change the Version:</emphasis>
4673 Rename the recipe such that the version (i.e. the
4674 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4675 part of the recipe name) changes appropriately.
4676 If the version is not part of the recipe name, change
4677 the value as it is set for <filename>PV</filename>
4678 within the recipe itself.
4679 </para></listitem>
4680 <listitem><para>
4681 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4682 If the source code your recipe builds is fetched from
4683 Git or some other version control system, update
4684 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4685 to point to the commit hash that matches the new
4686 version.
4687 </para></listitem>
4688 <listitem><para>
4689 <emphasis>Build the Software:</emphasis>
4690 Try to build the recipe using BitBake.
4691 Typical build failures include the following:
4692 <itemizedlist>
4693 <listitem><para>
4694 License statements were updated for the new
4695 version.
4696 For this case, you need to review any changes
4697 to the license and update the values of
4698 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4699 and
4700 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4701 as needed.
4702 <note>
4703 License changes are often inconsequential.
4704 For example, the license text's copyright
4705 year might have changed.
4706 </note>
4707 </para></listitem>
4708 <listitem><para>
4709 Custom patches carried by the older version of
4710 the recipe might fail to apply to the new
4711 version.
4712 For these cases, you need to review the
4713 failures.
4714 Patches might not be necessary for the new
4715 version of the software if the upgraded version
4716 has fixed those issues.
4717 If a patch is necessary and failing, you need
4718 to rebase it into the new version.
4719 </para></listitem>
4720 </itemizedlist>
4721 </para></listitem>
4722 <listitem><para>
4723 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4724 Once you successfully build the new software for a
4725 given architecture, you could test the build for
4726 other architectures by changing the
4727 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4728 variable and rebuilding the software.
4729 This optional step is especially important if the
4730 recipe is to be released publicly.
4731 </para></listitem>
4732 <listitem><para>
4733 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4734 Checking both these reveals if new features exist that
4735 could break backwards-compatibility.
4736 If so, you need to take steps to mitigate or eliminate
4737 that situation.
4738 </para></listitem>
4739 <listitem><para>
4740 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4741 If you want, you can test the new software by booting
4742 it onto actual hardware.
4743 </para></listitem>
4744 <listitem><para>
4745 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4746 After all builds work and any testing is successful,
4747 you can create commits for any changes in the layer
4748 holding your upgraded recipe.
4749 </para></listitem>
4750 </orderedlist>
4751 </para>
4752 </section>
4753 </section>
4754
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004755 <section id='finding-the-temporary-source-code'>
4756 <title>Finding Temporary Source Code</title>
4757
4758 <para>
4759 You might find it helpful during development to modify the
4760 temporary source code used by recipes to build packages.
4761 For example, suppose you are developing a patch and you need to
4762 experiment a bit to figure out your solution.
4763 After you have initially built the package, you can iteratively
4764 tweak the source code, which is located in the
4765 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4766 and then you can force a re-compile and quickly test your altered
4767 code.
4768 Once you settle on a solution, you can then preserve your changes
4769 in the form of patches.
4770 </para>
4771
4772 <para>
4773 During a build, the unpacked temporary source code used by recipes
4774 to build packages is available in the Build Directory as
4775 defined by the
4776 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4777 variable.
4778 Below is the default value for the <filename>S</filename> variable
4779 as defined in the
4780 <filename>meta/conf/bitbake.conf</filename> configuration file
4781 in the
4782 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4783 <literallayout class='monospaced'>
4784 S = "${WORKDIR}/${BP}"
4785 </literallayout>
4786 You should be aware that many recipes override the
4787 <filename>S</filename> variable.
4788 For example, recipes that fetch their source from Git usually set
4789 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4790 <note>
4791 The
4792 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4793 represents the base recipe name, which consists of the name
4794 and version:
4795 <literallayout class='monospaced'>
4796 BP = "${BPN}-${PV}"
4797 </literallayout>
4798 </note>
4799 </para>
4800
4801 <para>
4802 The path to the work directory for the recipe
4803 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4804 is defined as follows:
4805 <literallayout class='monospaced'>
4806 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4807 </literallayout>
4808 The actual directory depends on several things:
4809 <itemizedlist>
4810 <listitem><para>
4811 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4812 The top-level build output directory.
4813 </para></listitem>
4814 <listitem><para>
4815 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4816 The target system identifier.
4817 </para></listitem>
4818 <listitem><para>
4819 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4820 The recipe name.
4821 </para></listitem>
4822 <listitem><para>
4823 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4824 The epoch - (if
4825 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4826 is not specified, which is usually the case for most
4827 recipes, then <filename>EXTENDPE</filename> is blank).
4828 </para></listitem>
4829 <listitem><para>
4830 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4831 The recipe version.
4832 </para></listitem>
4833 <listitem><para>
4834 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4835 The recipe revision.
4836 </para></listitem>
4837 </itemizedlist>
4838 </para>
4839
4840 <para>
4841 As an example, assume a Source Directory top-level folder
4842 named <filename>poky</filename>, a default Build Directory at
4843 <filename>poky/build</filename>, and a
4844 <filename>qemux86-poky-linux</filename> machine target
4845 system.
4846 Furthermore, suppose your recipe is named
4847 <filename>foo_1.3.0.bb</filename>.
4848 In this case, the work directory the build system uses to
4849 build the package would be as follows:
4850 <literallayout class='monospaced'>
4851 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4852 </literallayout>
4853 </para>
4854 </section>
4855
4856 <section id="using-a-quilt-workflow">
4857 <title>Using Quilt in Your Workflow</title>
4858
4859 <para>
4860 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4861 is a powerful tool that allows you to capture source code changes
4862 without having a clean source tree.
4863 This section outlines the typical workflow you can use to modify
4864 source code, test changes, and then preserve the changes in the
4865 form of a patch all using Quilt.
4866 <note><title>Tip</title>
4867 With regard to preserving changes to source files, if you
4868 clean a recipe or have <filename>rm_work</filename> enabled,
4869 the
4870 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4871 as described in the Yocto Project Application Development
4872 and the Extensible Software Development Kit (eSDK) manual
4873 is a safer development flow than the flow that uses Quilt.
4874 </note>
4875 </para>
4876
4877 <para>
4878 Follow these general steps:
4879 <orderedlist>
4880 <listitem><para>
4881 <emphasis>Find the Source Code:</emphasis>
4882 Temporary source code used by the OpenEmbedded build system
4883 is kept in the
4884 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4885 See the
4886 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4887 section to learn how to locate the directory that has the
4888 temporary source code for a particular package.
4889 </para></listitem>
4890 <listitem><para>
4891 <emphasis>Change Your Working Directory:</emphasis>
4892 You need to be in the directory that has the temporary
4893 source code.
4894 That directory is defined by the
4895 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4896 variable.</para></listitem>
4897 <listitem><para>
4898 <emphasis>Create a New Patch:</emphasis>
4899 Before modifying source code, you need to create a new
4900 patch.
4901 To create a new patch file, use
4902 <filename>quilt new</filename> as below:
4903 <literallayout class='monospaced'>
4904 $ quilt new my_changes.patch
4905 </literallayout>
4906 </para></listitem>
4907 <listitem><para>
4908 <emphasis>Notify Quilt and Add Files:</emphasis>
4909 After creating the patch, you need to notify Quilt about
4910 the files you plan to edit.
4911 You notify Quilt by adding the files to the patch you
4912 just created:
4913 <literallayout class='monospaced'>
4914 $ quilt add file1.c file2.c file3.c
4915 </literallayout>
4916 </para></listitem>
4917 <listitem><para>
4918 <emphasis>Edit the Files:</emphasis>
4919 Make your changes in the source code to the files you added
4920 to the patch.
4921 </para></listitem>
4922 <listitem><para>
4923 <emphasis>Test Your Changes:</emphasis>
4924 Once you have modified the source code, the easiest way to
4925 test your changes is by calling the
4926 <filename>do_compile</filename> task as shown in the
4927 following example:
4928 <literallayout class='monospaced'>
4929 $ bitbake -c compile -f <replaceable>package</replaceable>
4930 </literallayout>
4931 The <filename>-f</filename> or <filename>--force</filename>
4932 option forces the specified task to execute.
4933 If you find problems with your code, you can just keep
4934 editing and re-testing iteratively until things work
4935 as expected.
4936 <note>
4937 All the modifications you make to the temporary
4938 source code disappear once you run the
4939 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4940 or
4941 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4942 tasks using BitBake (i.e.
4943 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4944 and
4945 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4946 Modifications will also disappear if you use the
4947 <filename>rm_work</filename> feature as described
4948 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004949 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4950 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004951 </note>
4952 </para></listitem>
4953 <listitem><para>
4954 <emphasis>Generate the Patch:</emphasis>
4955 Once your changes work as expected, you need to use Quilt
4956 to generate the final patch that contains all your
4957 modifications.
4958 <literallayout class='monospaced'>
4959 $ quilt refresh
4960 </literallayout>
4961 At this point, the <filename>my_changes.patch</filename>
4962 file has all your edits made to the
4963 <filename>file1.c</filename>, <filename>file2.c</filename>,
4964 and <filename>file3.c</filename> files.</para>
4965
4966 <para>You can find the resulting patch file in the
4967 <filename>patches/</filename> subdirectory of the source
4968 (<filename>S</filename>) directory.
4969 </para></listitem>
4970 <listitem><para>
4971 <emphasis>Copy the Patch File:</emphasis>
4972 For simplicity, copy the patch file into a directory
4973 named <filename>files</filename>, which you can create
4974 in the same directory that holds the recipe
4975 (<filename>.bb</filename>) file or the append
4976 (<filename>.bbappend</filename>) file.
4977 Placing the patch here guarantees that the OpenEmbedded
4978 build system will find the patch.
4979 Next, add the patch into the
4980 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4981 of the recipe.
4982 Here is an example:
4983 <literallayout class='monospaced'>
4984 SRC_URI += "file://my_changes.patch"
4985 </literallayout>
4986 </para></listitem>
4987 </orderedlist>
4988 </para>
4989 </section>
4990
4991 <section id="platdev-appdev-devshell">
4992 <title>Using a Development Shell</title>
4993
4994 <para>
4995 When debugging certain commands or even when just editing packages,
4996 <filename>devshell</filename> can be a useful tool.
4997 When you invoke <filename>devshell</filename>, all tasks up to and
4998 including
4999 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5000 are run for the specified target.
5001 Then, a new terminal is opened and you are placed in
5002 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
5003 the source directory.
5004 In the new terminal, all the OpenEmbedded build-related environment variables are
5005 still defined so you can use commands such as <filename>configure</filename> and
5006 <filename>make</filename>.
5007 The commands execute just as if the OpenEmbedded build system were executing them.
5008 Consequently, working this way can be helpful when debugging a build or preparing
5009 software to be used with the OpenEmbedded build system.
5010 </para>
5011
5012 <para>
5013 Following is an example that uses <filename>devshell</filename> on a target named
5014 <filename>matchbox-desktop</filename>:
5015 <literallayout class='monospaced'>
5016 $ bitbake matchbox-desktop -c devshell
5017 </literallayout>
5018 </para>
5019
5020 <para>
5021 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5022 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5023 variable controls what type of shell is opened.
5024 </para>
5025
5026 <para>
5027 For spawned terminals, the following occurs:
5028 <itemizedlist>
5029 <listitem><para>The <filename>PATH</filename> variable includes the
5030 cross-toolchain.</para></listitem>
5031 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5032 <filename>.pc</filename> files.</para></listitem>
5033 <listitem><para>The <filename>configure</filename> command finds the
5034 Yocto Project site files as well as any other necessary files.</para></listitem>
5035 </itemizedlist>
5036 </para>
5037
5038 <para>
5039 Within this environment, you can run configure or compile
5040 commands as if they were being run by
5041 the OpenEmbedded build system itself.
5042 As noted earlier, the working directory also automatically changes to the
5043 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5044 </para>
5045
5046 <para>
5047 To manually run a specific task using <filename>devshell</filename>,
5048 run the corresponding <filename>run.*</filename> script in
5049 the
5050 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5051 directory (e.g.,
5052 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5053 If a task's script does not exist, which would be the case if the task was
5054 skipped by way of the sstate cache, you can create the task by first running
5055 it outside of the <filename>devshell</filename>:
5056 <literallayout class='monospaced'>
5057 $ bitbake -c <replaceable>task</replaceable>
5058 </literallayout>
5059 <note><title>Notes</title>
5060 <itemizedlist>
5061 <listitem><para>Execution of a task's <filename>run.*</filename>
5062 script and BitBake's execution of a task are identical.
5063 In other words, running the script re-runs the task
5064 just as it would be run using the
5065 <filename>bitbake -c</filename> command.
5066 </para></listitem>
5067 <listitem><para>Any <filename>run.*</filename> file that does not
5068 have a <filename>.pid</filename> extension is a
5069 symbolic link (symlink) to the most recent version of that
5070 file.
5071 </para></listitem>
5072 </itemizedlist>
5073 </note>
5074 </para>
5075
5076 <para>
5077 Remember, that the <filename>devshell</filename> is a mechanism that allows
5078 you to get into the BitBake task execution environment.
5079 And as such, all commands must be called just as BitBake would call them.
5080 That means you need to provide the appropriate options for
5081 cross-compilation and so forth as applicable.
5082 </para>
5083
5084 <para>
5085 When you are finished using <filename>devshell</filename>, exit the shell
5086 or close the terminal window.
5087 </para>
5088
5089 <note><title>Notes</title>
5090 <itemizedlist>
5091 <listitem><para>
5092 It is worth remembering that when using <filename>devshell</filename>
5093 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5094 instead of just using <filename>gcc</filename>.
5095 The same applies to other applications such as <filename>binutils</filename>,
5096 <filename>libtool</filename> and so forth.
5097 BitBake sets up environment variables such as <filename>CC</filename>
5098 to assist applications, such as <filename>make</filename> to find the correct tools.
5099 </para></listitem>
5100 <listitem><para>
5101 It is also worth noting that <filename>devshell</filename> still works over
5102 X11 forwarding and similar situations.
5103 </para></listitem>
5104 </itemizedlist>
5105 </note>
5106 </section>
5107
5108 <section id="platdev-appdev-devpyshell">
5109 <title>Using a Development Python Shell</title>
5110
5111 <para>
5112 Similar to working within a development shell as described in
5113 the previous section, you can also spawn and work within an
5114 interactive Python development shell.
5115 When debugging certain commands or even when just editing packages,
5116 <filename>devpyshell</filename> can be a useful tool.
5117 When you invoke <filename>devpyshell</filename>, all tasks up to and
5118 including
5119 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5120 are run for the specified target.
5121 Then a new terminal is opened.
5122 Additionally, key Python objects and code are available in the same
5123 way they are to BitBake tasks, in particular, the data store 'd'.
5124 So, commands such as the following are useful when exploring the data
5125 store and running functions:
5126 <literallayout class='monospaced'>
5127 pydevshell> d.getVar("STAGING_DIR", True)
5128 '/media/build1/poky/build/tmp/sysroots'
5129 pydevshell> d.getVar("STAGING_DIR", False)
5130 '${TMPDIR}/sysroots'
5131 pydevshell> d.setVar("FOO", "bar")
5132 pydevshell> d.getVar("FOO", True)
5133 'bar'
5134 pydevshell> d.delVar("FOO")
5135 pydevshell> d.getVar("FOO", True)
5136 pydevshell> bb.build.exec_func("do_unpack", d)
5137 pydevshell>
5138 </literallayout>
5139 The commands execute just as if the OpenEmbedded build system were executing them.
5140 Consequently, working this way can be helpful when debugging a build or preparing
5141 software to be used with the OpenEmbedded build system.
5142 </para>
5143
5144 <para>
5145 Following is an example that uses <filename>devpyshell</filename> on a target named
5146 <filename>matchbox-desktop</filename>:
5147 <literallayout class='monospaced'>
5148 $ bitbake matchbox-desktop -c devpyshell
5149 </literallayout>
5150 </para>
5151
5152 <para>
5153 This command spawns a terminal and places you in an interactive
5154 Python interpreter within the OpenEmbedded build environment.
5155 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5156 variable controls what type of shell is opened.
5157 </para>
5158
5159 <para>
5160 When you are finished using <filename>devpyshell</filename>, you
5161 can exit the shell either by using Ctrl+d or closing the terminal
5162 window.
5163 </para>
5164 </section>
5165
Brad Bishop316dfdd2018-06-25 12:45:53 -04005166 <section id='dev-building'>
5167 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005168
5169 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005170 This section describes various build procedures.
5171 For example, the steps needed for a simple build, a target that
5172 uses multiple configurations, building an image for more than
5173 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005174 </para>
5175
Brad Bishop316dfdd2018-06-25 12:45:53 -04005176 <section id='dev-building-a-simple-image'>
5177 <title>Building a Simple Image</title>
5178
5179 <para>
5180 In the development environment, you need to build an image
5181 whenever you change hardware support, add or change system
5182 libraries, or add or change services that have dependencies.
5183 Several methods exist that allow you to build an image within
5184 the Yocto Project.
5185 This section presents the basic steps you need to build a
5186 simple image using BitBake from a build host running Linux.
5187 <note><title>Notes</title>
5188 <itemizedlist>
5189 <listitem><para>
5190 For information on how to build an image using
5191 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5192 see the
5193 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5194 </para></listitem>
5195 <listitem><para>
5196 For information on how to use
5197 <filename>devtool</filename> to build images, see
5198 the
5199 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5200 section in the Yocto Project Application
5201 Development and the Extensible Software Development
5202 Kit (eSDK) manual.
5203 </para></listitem>
5204 <listitem><para>
5205 For a quick example on how to build an image using
5206 the OpenEmbedded build system, see the
5207 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5208 document.
5209 </para></listitem>
5210 </itemizedlist>
5211 </note>
5212 </para>
5213
5214 <para>
5215 The build process creates an entire Linux distribution from
5216 source and places it in your
5217 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5218 under <filename>tmp/deploy/images</filename>.
5219 For detailed information on the build process using BitBake,
5220 see the
5221 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5222 section in the Yocto Project Overview and Concepts Manual.
5223 </para>
5224
5225 <para>
5226 The following figure and list overviews the build process:
5227 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5228 <orderedlist>
5229 <listitem><para>
5230 <emphasis>Set up Your Host Development System to Support
5231 Development Using the Yocto Project</emphasis>:
5232 See the
5233 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5234 section for options on how to get a build host ready to
5235 use the Yocto Project.
5236 </para></listitem>
5237 <listitem><para>
5238 <emphasis>Initialize the Build Environment:</emphasis>
5239 Initialize the build environment by sourcing the build
5240 environment script (i.e.
5241 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5242 <literallayout class='monospaced'>
5243 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5244 </literallayout></para>
5245
5246 <para>When you use the initialization script, the
5247 OpenEmbedded build system uses
5248 <filename>build</filename> as the default Build
5249 Directory in your current work directory.
5250 You can use a <replaceable>build_dir</replaceable>
5251 argument with the script to specify a different build
5252 directory.
5253 <note><title>Tip</title>
5254 A common practice is to use a different Build
5255 Directory for different targets.
5256 For example, <filename>~/build/x86</filename> for a
5257 <filename>qemux86</filename> target, and
5258 <filename>~/build/arm</filename> for a
5259 <filename>qemuarm</filename> target.
5260 </note>
5261 </para></listitem>
5262 <listitem><para>
5263 <emphasis>Make Sure Your <filename>local.conf</filename>
5264 File is Correct:</emphasis>
5265 Ensure the <filename>conf/local.conf</filename>
5266 configuration file, which is found in the Build
5267 Directory, is set up how you want it.
5268 This file defines many aspects of the build environment
5269 including the target machine architecture through the
5270 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5271 the packaging format used during the build
5272 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5273 and a centralized tarball download directory through the
5274 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5275 </para></listitem>
5276 <listitem><para>
5277 <emphasis>Build the Image:</emphasis>
5278 Build the image using the <filename>bitbake</filename>
5279 command:
5280 <literallayout class='monospaced'>
5281 $ bitbake <replaceable>target</replaceable>
5282 </literallayout>
5283 <note>
5284 For information on BitBake, see the
5285 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5286 </note>
5287 The <replaceable>target</replaceable> is the name of the
5288 recipe you want to build.
5289 Common targets are the images in
5290 <filename>meta/recipes-core/images</filename>,
5291 <filename>meta/recipes-sato/images</filename>, and so
5292 forth all found in the
5293 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5294 Or, the target can be the name of a recipe for a
5295 specific piece of software such as BusyBox.
5296 For more details about the images the OpenEmbedded build
5297 system supports, see the
5298 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5299 chapter in the Yocto Project Reference Manual.</para>
5300
5301 <para>As an example, the following command builds the
5302 <filename>core-image-minimal</filename> image:
5303 <literallayout class='monospaced'>
5304 $ bitbake core-image-minimal
5305 </literallayout>
5306 Once an image has been built, it often needs to be
5307 installed.
5308 The images and kernels built by the OpenEmbedded
5309 build system are placed in the Build Directory in
5310 <filename class="directory">tmp/deploy/images</filename>.
5311 For information on how to run pre-built images such as
5312 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5313 see the
5314 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5315 manual.
5316 For information about how to install these images,
5317 see the documentation for your particular board or
5318 machine.
5319 </para></listitem>
5320 </orderedlist>
5321 </para>
5322 </section>
5323
5324 <section id='platdev-building-targets-with-multiple-configurations'>
5325 <title>Building Targets with Multiple Configurations</title>
5326
5327 <para>
5328 Bitbake also has functionality that allows you to build
5329 multiple targets at the same time, where each target uses
5330 a different configuration.
5331 </para>
5332
5333 <para>
5334 In order to accomplish this, you setup each of the configurations
5335 you need to use in parallel by placing the configuration files in
5336 your current build directory alongside the usual
5337 <filename>local.conf</filename> file.
5338 </para>
5339
5340 <para>
5341 Follow these guidelines to create an environment that supports
5342 multiple configurations:
5343 <itemizedlist>
5344 <listitem><para>
5345 <emphasis>Create Configuration Files</emphasis>:
5346 You need to create a single configuration file for each
5347 configuration for which you want to add support.
5348 These files would contain lines such as the following:
5349 <literallayout class='monospaced'>
5350 MACHINE = "A"
5351 </literallayout>
5352 The files would contain any other variables that can
5353 be set and built in the same directory.
5354 <note>
5355 You can change the
5356 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
5357 to not conflict.
5358 </note></para>
5359
5360 <para>
5361 Furthermore, the configuration file must be located in the
5362 current build directory in a directory named
5363 <filename>multiconfig</filename> under the build's
5364 <filename>conf</filename> directory where
5365 <filename>local.conf</filename> resides.
5366 The reason for this restriction is because the
5367 <filename>BBPATH</filename> variable is not constructed
5368 until the layers are parsed.
5369 Consequently, using the configuration file as a
5370 pre-configuration file is not possible unless it is
5371 located in the current working directory.
5372 </para></listitem>
5373 <listitem><para>
5374 <emphasis>Add the BitBake Multi-Config Variable to you Local Configuration File</emphasis>:
5375 Use the
5376 <filename>BBMULTICONFIG</filename>
5377 variable in your <filename>conf/local.conf</filename>
5378 configuration file to specify each separate configuration.
5379 For example, the following line tells BitBake it should load
5380 <filename>conf/multiconfig/configA.conf</filename>,
5381 <filename>conf/multiconfig/configB.conf</filename>, and
5382 <filename>conf/multiconfig/configC.conf</filename>.
5383 <literallayout class='monospaced'>
5384 BBMULTICONFIG = "configA configB configC"
5385 </literallayout>
5386 </para></listitem>
5387 <listitem><para>
5388 <emphasis>Launch BitBake</emphasis>:
5389 Use the following BitBake command form to launch the
5390 build:
5391 <literallayout class='monospaced'>
5392 $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
5393 </literallayout>
5394 Following is an example that supports building a minimal
5395 image for configuration A alongside a standard
5396 <filename>core-image-sato</filename>, which takes its
5397 configuration from <filename>local.conf</filename>:
5398 <literallayout class='monospaced'>
5399 $ bitbake multiconfig:configA:core-image-minimal core-image-sato
5400 </literallayout>
5401 </para></listitem>
5402 </itemizedlist>
5403 </para>
5404
5405 <para>
5406 Support for multiple configurations in this current release of
5407 the Yocto Project (&DISTRO_NAME; &DISTRO;) has some known issues:
5408 <itemizedlist>
5409 <listitem><para>
5410 No inter-multi-configuration dependencies exist.
5411 </para></listitem>
5412 <listitem><para>
5413 Shared State (sstate) optimizations do not exist.
5414 Consequently, if the build uses the same object twice
5415 in, for example, two different
5416 <filename>TMPDIR</filename> directories, the build
5417 will either load from an existing sstate cache at the
5418 start or build the object twice.
5419 </para></listitem>
5420 </itemizedlist>
5421 </para>
5422 </section>
5423
5424 <section id='building-an-initramfs-image'>
5425 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5426
5427 <para>
5428 An initial RAM filesystem (initramfs) image provides a temporary
5429 root filesystem used for early system initialization (e.g.
5430 loading of modules needed to locate and mount the "real" root
5431 filesystem).
5432 <note>
5433 The initramfs image is the successor of initial RAM disk
5434 (initrd).
5435 It is a "copy in and out" (cpio) archive of the initial
5436 filesystem that gets loaded into memory during the Linux
5437 startup process.
5438 Because Linux uses the contents of the archive during
5439 initialization, the initramfs image needs to contain all of the
5440 device drivers and tools needed to mount the final root
5441 filesystem.
5442 </note>
5443 </para>
5444
5445 <para>
5446 Follow these steps to create an initramfs image:
5447 <orderedlist>
5448 <listitem><para>
5449 <emphasis>Create the initramfs Image Recipe:</emphasis>
5450 You can reference the
5451 <filename>core-image-minimal-initramfs.bb</filename>
5452 recipe found in the <filename>meta/recipes-core</filename>
5453 directory of the
5454 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5455 as an example from which to work.
5456 </para></listitem>
5457 <listitem><para>
5458 <emphasis>Decide if You Need to Bundle the initramfs Image
5459 Into the Kernel Image:</emphasis>
5460 If you want the initramfs image that is built to be
5461 bundled in with the kernel image, set the
5462 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5463 variable to "1" in your <filename>local.conf</filename>
5464 configuration file and set the
5465 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5466 variable in the recipe that builds the kernel image.
5467 <note><title>Tip</title>
5468 It is recommended that you do bundle the initramfs
5469 image with the kernel image to avoid circular
5470 dependencies between the kernel recipe and the
5471 initramfs recipe should the initramfs image
5472 include kernel modules.
5473 </note>
5474 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5475 flag causes the initramfs image to be unpacked
5476 into the <filename>${B}/usr/</filename> directory.
5477 The unpacked initramfs image is then passed to the kernel's
5478 <filename>Makefile</filename> using the
5479 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5480 variable, allowing the initramfs image to be built into
5481 the kernel normally.
5482 <note>
5483 If you choose to not bundle the initramfs image with
5484 the kernel image, you are essentially using an
5485 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5486 Creating an initrd is handled primarily through the
5487 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5488 <filename>INITRD_LIVE</filename>, and
5489 <filename>INITRD_IMAGE_LIVE</filename> variables.
5490 For more information, see the
5491 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5492 file.
5493 </note>
5494 </para></listitem>
5495 <listitem><para>
5496 <emphasis>Optionally Add Items to the initramfs Image
5497 Through the initramfs Image Recipe:</emphasis>
5498 If you add items to the initramfs image by way of its
5499 recipe, you should use
5500 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5501 rather than
5502 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5503 <filename>PACKAGE_INSTALL</filename> gives more direct
5504 control of what is added to the image as compared to
5505 the defaults you might not necessarily want that are
5506 set by the
5507 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5508 or
5509 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5510 classes.
5511 </para></listitem>
5512 <listitem><para>
5513 <emphasis>Build the Kernel Image and the initramfs
5514 Image:</emphasis>
5515 Build your kernel image using BitBake.
5516 Because the initramfs image recipe is a dependency of the
5517 kernel image, the initramfs image is built as well and
5518 bundled with the kernel image if you used the
5519 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5520 variable described earlier.
5521 </para></listitem>
5522 </orderedlist>
5523 </para>
5524 </section>
5525
5526 <section id='building-a-tiny-system'>
5527 <title>Building a Tiny System</title>
5528
5529 <para>
5530 Very small distributions have some significant advantages such
5531 as requiring less on-die or in-package memory (cheaper), better
5532 performance through efficient cache usage, lower power requirements
5533 due to less memory, faster boot times, and reduced development
5534 overhead.
5535 Some real-world examples where a very small distribution gives
5536 you distinct advantages are digital cameras, medical devices,
5537 and small headless systems.
5538 </para>
5539
5540 <para>
5541 This section presents information that shows you how you can
5542 trim your distribution to even smaller sizes than the
5543 <filename>poky-tiny</filename> distribution, which is around
5544 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5545 </para>
5546
5547 <section id='tiny-system-overview'>
5548 <title>Overview</title>
5549
5550 <para>
5551 The following list presents the overall steps you need to
5552 consider and perform to create distributions with smaller
5553 root filesystems, achieve faster boot times, maintain your critical
5554 functionality, and avoid initial RAM disks:
5555 <itemizedlist>
5556 <listitem><para>
5557 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5558 </para></listitem>
5559 <listitem><para>
5560 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5561 </para></listitem>
5562 <listitem><para>
5563 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5564 </para></listitem>
5565 <listitem><para>
5566 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5567 </para></listitem>
5568 <listitem><para>
5569 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5570 </para></listitem>
5571 <listitem><para>
5572 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5573 </para></listitem>
5574 <listitem><para>
5575 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5576 </para></listitem>
5577 </itemizedlist>
5578 </para>
5579 </section>
5580
5581 <section id='goals-and-guiding-principles'>
5582 <title>Goals and Guiding Principles</title>
5583
5584 <para>
5585 Before you can reach your destination, you need to know
5586 where you are going.
5587 Here is an example list that you can use as a guide when
5588 creating very small distributions:
5589 <itemizedlist>
5590 <listitem><para>Determine how much space you need
5591 (e.g. a kernel that is 1 Mbyte or less and
5592 a root filesystem that is 3 Mbytes or less).
5593 </para></listitem>
5594 <listitem><para>Find the areas that are currently
5595 taking 90% of the space and concentrate on reducing
5596 those areas.
5597 </para></listitem>
5598 <listitem><para>Do not create any difficult "hacks"
5599 to achieve your goals.</para></listitem>
5600 <listitem><para>Leverage the device-specific
5601 options.</para></listitem>
5602 <listitem><para>Work in a separate layer so that you
5603 keep changes isolated.
5604 For information on how to create layers, see
5605 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5606 </para></listitem>
5607 </itemizedlist>
5608 </para>
5609 </section>
5610
5611 <section id='understand-what-gives-your-image-size'>
5612 <title>Understand What Contributes to Your Image Size</title>
5613
5614 <para>
5615 It is easiest to have something to start with when creating
5616 your own distribution.
5617 You can use the Yocto Project out-of-the-box to create the
5618 <filename>poky-tiny</filename> distribution.
5619 Ultimately, you will want to make changes in your own
5620 distribution that are likely modeled after
5621 <filename>poky-tiny</filename>.
5622 <note>
5623 To use <filename>poky-tiny</filename> in your build,
5624 set the
5625 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5626 variable in your
5627 <filename>local.conf</filename> file to "poky-tiny"
5628 as described in the
5629 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5630 section.
5631 </note>
5632 </para>
5633
5634 <para>
5635 Understanding some memory concepts will help you reduce the
5636 system size.
5637 Memory consists of static, dynamic, and temporary memory.
5638 Static memory is the TEXT (code), DATA (initialized data
5639 in the code), and BSS (uninitialized data) sections.
5640 Dynamic memory represents memory that is allocated at runtime:
5641 stacks, hash tables, and so forth.
5642 Temporary memory is recovered after the boot process.
5643 This memory consists of memory used for decompressing
5644 the kernel and for the <filename>__init__</filename>
5645 functions.
5646 </para>
5647
5648 <para>
5649 To help you see where you currently are with kernel and root
5650 filesystem sizes, you can use two tools found in the
5651 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5652 the <filename>scripts/tiny/</filename> directory:
5653 <itemizedlist>
5654 <listitem><para><filename>ksize.py</filename>: Reports
5655 component sizes for the kernel build objects.
5656 </para></listitem>
5657 <listitem><para><filename>dirsize.py</filename>: Reports
5658 component sizes for the root filesystem.</para></listitem>
5659 </itemizedlist>
5660 This next tool and command help you organize configuration
5661 fragments and view file dependencies in a human-readable form:
5662 <itemizedlist>
5663 <listitem><para><filename>merge_config.sh</filename>:
5664 Helps you manage configuration files and fragments
5665 within the kernel.
5666 With this tool, you can merge individual configuration
5667 fragments together.
5668 The tool allows you to make overrides and warns you
5669 of any missing configuration options.
5670 The tool is ideal for allowing you to iterate on
5671 configurations, create minimal configurations, and
5672 create configuration files for different machines
5673 without having to duplicate your process.</para>
5674 <para>The <filename>merge_config.sh</filename> script is
5675 part of the Linux Yocto kernel Git repositories
5676 (i.e. <filename>linux-yocto-3.14</filename>,
5677 <filename>linux-yocto-3.10</filename>,
5678 <filename>linux-yocto-3.8</filename>, and so forth)
5679 in the
5680 <filename>scripts/kconfig</filename> directory.</para>
5681 <para>For more information on configuration fragments,
5682 see the
5683 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5684 section in the Yocto Project Linux Kernel Development
5685 Manual.
5686 </para></listitem>
5687 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5688 Using the BitBake command with these options brings up
5689 a Dependency Explorer from which you can view file
5690 dependencies.
5691 Understanding these dependencies allows you to make
5692 informed decisions when cutting out various pieces of the
5693 kernel and root filesystem.</para></listitem>
5694 </itemizedlist>
5695 </para>
5696 </section>
5697
5698 <section id='trim-the-root-filesystem'>
5699 <title>Trim the Root Filesystem</title>
5700
5701 <para>
5702 The root filesystem is made up of packages for booting,
5703 libraries, and applications.
5704 To change things, you can configure how the packaging happens,
5705 which changes the way you build them.
5706 You can also modify the filesystem itself or select a different
5707 filesystem.
5708 </para>
5709
5710 <para>
5711 First, find out what is hogging your root filesystem by running the
5712 <filename>dirsize.py</filename> script from your root directory:
5713 <literallayout class='monospaced'>
5714 $ cd <replaceable>root-directory-of-image</replaceable>
5715 $ dirsize.py 100000 > dirsize-100k.log
5716 $ cat dirsize-100k.log
5717 </literallayout>
5718 You can apply a filter to the script to ignore files under
5719 a certain size.
5720 The previous example filters out any files below 100 Kbytes.
5721 The sizes reported by the tool are uncompressed, and thus
5722 will be smaller by a relatively constant factor in a
5723 compressed root filesystem.
5724 When you examine your log file, you can focus on areas of the
5725 root filesystem that take up large amounts of memory.
5726 </para>
5727
5728 <para>
5729 You need to be sure that what you eliminate does not cripple
5730 the functionality you need.
5731 One way to see how packages relate to each other is by using
5732 the Dependency Explorer UI with the BitBake command:
5733 <literallayout class='monospaced'>
5734 $ cd <replaceable>image-directory</replaceable>
5735 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5736 </literallayout>
5737 Use the interface to select potential packages you wish to
5738 eliminate and see their dependency relationships.
5739 </para>
5740
5741 <para>
5742 When deciding how to reduce the size, get rid of packages that
5743 result in minimal impact on the feature set.
5744 For example, you might not need a VGA display.
5745 Or, you might be able to get by with <filename>devtmpfs</filename>
5746 and <filename>mdev</filename> instead of
5747 <filename>udev</filename>.
5748 </para>
5749
5750 <para>
5751 Use your <filename>local.conf</filename> file to make changes.
5752 For example, to eliminate <filename>udev</filename> and
5753 <filename>glib</filename>, set the following in the
5754 local configuration file:
5755 <literallayout class='monospaced'>
5756 VIRTUAL-RUNTIME_dev_manager = ""
5757 </literallayout>
5758 </para>
5759
5760 <para>
5761 Finally, you should consider exactly the type of root
5762 filesystem you need to meet your needs while also reducing
5763 its size.
5764 For example, consider <filename>cramfs</filename>,
5765 <filename>squashfs</filename>, <filename>ubifs</filename>,
5766 <filename>ext2</filename>, or an <filename>initramfs</filename>
5767 using <filename>initramfs</filename>.
5768 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5769 journal.
5770 If you are okay with running read-only, you do not need this
5771 journal.
5772 </para>
5773
5774 <note>
5775 After each round of elimination, you need to rebuild your
5776 system and then use the tools to see the effects of your
5777 reductions.
5778 </note>
5779 </section>
5780
5781 <section id='trim-the-kernel'>
5782 <title>Trim the Kernel</title>
5783
5784 <para>
5785 The kernel is built by including policies for hardware-independent
5786 aspects.
5787 What subsystems do you enable?
5788 For what architecture are you building?
5789 Which drivers do you build by default?
5790 <note>You can modify the kernel source if you want to help
5791 with boot time.
5792 </note>
5793 </para>
5794
5795 <para>
5796 Run the <filename>ksize.py</filename> script from the top-level
5797 Linux build directory to get an idea of what is making up
5798 the kernel:
5799 <literallayout class='monospaced'>
5800 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5801 $ ksize.py > ksize.log
5802 $ cat ksize.log
5803 </literallayout>
5804 When you examine the log, you will see how much space is
5805 taken up with the built-in <filename>.o</filename> files for
5806 drivers, networking, core kernel files, filesystem, sound,
5807 and so forth.
5808 The sizes reported by the tool are uncompressed, and thus
5809 will be smaller by a relatively constant factor in a compressed
5810 kernel image.
5811 Look to reduce the areas that are large and taking up around
5812 the "90% rule."
5813 </para>
5814
5815 <para>
5816 To examine, or drill down, into any particular area, use the
5817 <filename>-d</filename> option with the script:
5818 <literallayout class='monospaced'>
5819 $ ksize.py -d > ksize.log
5820 </literallayout>
5821 Using this option breaks out the individual file information
5822 for each area of the kernel (e.g. drivers, networking, and
5823 so forth).
5824 </para>
5825
5826 <para>
5827 Use your log file to see what you can eliminate from the kernel
5828 based on features you can let go.
5829 For example, if you are not going to need sound, you do not
5830 need any drivers that support sound.
5831 </para>
5832
5833 <para>
5834 After figuring out what to eliminate, you need to reconfigure
5835 the kernel to reflect those changes during the next build.
5836 You could run <filename>menuconfig</filename> and make all your
5837 changes at once.
5838 However, that makes it difficult to see the effects of your
5839 individual eliminations and also makes it difficult to replicate
5840 the changes for perhaps another target device.
5841 A better method is to start with no configurations using
5842 <filename>allnoconfig</filename>, create configuration
5843 fragments for individual changes, and then manage the
5844 fragments into a single configuration file using
5845 <filename>merge_config.sh</filename>.
5846 The tool makes it easy for you to iterate using the
5847 configuration change and build cycle.
5848 </para>
5849
5850 <para>
5851 Each time you make configuration changes, you need to rebuild
5852 the kernel and check to see what impact your changes had on
5853 the overall size.
5854 </para>
5855 </section>
5856
5857 <section id='remove-package-management-requirements'>
5858 <title>Remove Package Management Requirements</title>
5859
5860 <para>
5861 Packaging requirements add size to the image.
5862 One way to reduce the size of the image is to remove all the
5863 packaging requirements from the image.
5864 This reduction includes both removing the package manager
5865 and its unique dependencies as well as removing the package
5866 management data itself.
5867 </para>
5868
5869 <para>
5870 To eliminate all the packaging requirements for an image,
5871 be sure that "package-management" is not part of your
5872 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5873 statement for the image.
5874 When you remove this feature, you are removing the package
5875 manager as well as its dependencies from the root filesystem.
5876 </para>
5877 </section>
5878
5879 <section id='look-for-other-ways-to-minimize-size'>
5880 <title>Look for Other Ways to Minimize Size</title>
5881
5882 <para>
5883 Depending on your particular circumstances, other areas that you
5884 can trim likely exist.
5885 The key to finding these areas is through tools and methods
5886 described here combined with experimentation and iteration.
5887 Here are a couple of areas to experiment with:
5888 <itemizedlist>
5889 <listitem><para><filename>glibc</filename>:
5890 In general, follow this process:
5891 <orderedlist>
5892 <listitem><para>Remove <filename>glibc</filename>
5893 features from
5894 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
5895 that you think you do not need.</para></listitem>
5896 <listitem><para>Build your distribution.
5897 </para></listitem>
5898 <listitem><para>If the build fails due to missing
5899 symbols in a package, determine if you can
5900 reconfigure the package to not need those
5901 features.
5902 For example, change the configuration to not
5903 support wide character support as is done for
5904 <filename>ncurses</filename>.
5905 Or, if support for those characters is needed,
5906 determine what <filename>glibc</filename>
5907 features provide the support and restore the
5908 configuration.
5909 </para></listitem>
5910 <listitem><para>Rebuild and repeat the process.
5911 </para></listitem>
5912 </orderedlist></para></listitem>
5913 <listitem><para><filename>busybox</filename>:
5914 For BusyBox, use a process similar as described for
5915 <filename>glibc</filename>.
5916 A difference is you will need to boot the resulting
5917 system to see if you are able to do everything you
5918 expect from the running system.
5919 You need to be sure to integrate configuration fragments
5920 into Busybox because BusyBox handles its own core
5921 features and then allows you to add configuration
5922 fragments on top.
5923 </para></listitem>
5924 </itemizedlist>
5925 </para>
5926 </section>
5927
5928 <section id='iterate-on-the-process'>
5929 <title>Iterate on the Process</title>
5930
5931 <para>
5932 If you have not reached your goals on system size, you need
5933 to iterate on the process.
5934 The process is the same.
5935 Use the tools and see just what is taking up 90% of the root
5936 filesystem and the kernel.
5937 Decide what you can eliminate without limiting your device
5938 beyond what you need.
5939 </para>
5940
5941 <para>
5942 Depending on your system, a good place to look might be
5943 Busybox, which provides a stripped down
5944 version of Unix tools in a single, executable file.
5945 You might be able to drop virtual terminal services or perhaps
5946 ipv6.
5947 </para>
5948 </section>
5949 </section>
5950
5951 <section id='building-images-for-more-than-one-machine'>
5952 <title>Building Images for More than One Machine</title>
5953
5954 <para>
5955 A common scenario developers face is creating images for several
5956 different machines that use the same software environment.
5957 In this situation, it is tempting to set the
5958 tunings and optimization flags for each build specifically for
5959 the targeted hardware (i.e. "maxing out" the tunings).
5960 Doing so can considerably add to build times and package feed
5961 maintenance collectively for the machines.
5962 For example, selecting tunes that are extremely specific to a
5963 CPU core used in a system might enable some micro optimizations
5964 in GCC for that particular system but would otherwise not gain
5965 you much of a performance difference across the other systems
5966 as compared to using a more general tuning across all the builds
5967 (e.g. setting
5968 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
5969 specifically for each machine's build).
5970 Rather than "max out" each build's tunings, you can take steps that
5971 cause the OpenEmbedded build system to reuse software across the
5972 various machines where it makes sense.
5973 </para>
5974
5975 <para>
5976 If build speed and package feed maintenance are considerations,
5977 you should consider the points in this section that can help you
5978 optimize your tunings to best consider build times and package
5979 feed maintenance.
5980 <itemizedlist>
5981 <listitem><para>
5982 <emphasis>Share the Build Directory:</emphasis>
5983 If at all possible, share the
5984 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
5985 across builds.
5986 The Yocto Project supports switching between different
5987 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
5988 values in the same <filename>TMPDIR</filename>.
5989 This practice is well supported and regularly used by
5990 developers when building for multiple machines.
5991 When you use the same <filename>TMPDIR</filename> for
5992 multiple machine builds, the OpenEmbedded build system can
5993 reuse the existing native and often cross-recipes for
5994 multiple machines.
5995 Thus, build time decreases.
5996 <note>
5997 If
5998 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5999 settings change or fundamental configuration settings
6000 such as the filesystem layout, you need to work with
6001 a clean <filename>TMPDIR</filename>.
6002 Sharing <filename>TMPDIR</filename> under these
6003 circumstances might work but since it is not
6004 guaranteed, you should use a clean
6005 <filename>TMPDIR</filename>.
6006 </note>
6007 </para></listitem>
6008 <listitem><para>
6009 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6010 By default, the OpenEmbedded build system enables three
6011 levels of package architectures: "all", "tune" or "package",
6012 and "machine".
6013 Any given recipe usually selects one of these package
6014 architectures (types) for its output.
6015 Depending for what a given recipe creates packages, making
6016 sure you enable the appropriate package architecture can
6017 directly impact the build time.</para>
6018
6019 <para>A recipe that just generates scripts can enable
6020 "all" architecture because there are no binaries to build.
6021 To specifically enable "all" architecture, be sure your
6022 recipe inherits the
6023 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6024 class.
6025 This class is useful for "all" architectures because it
6026 configures many variables so packages can be used across
6027 multiple architectures.</para>
6028
6029 <para>If your recipe needs to generate packages that are
6030 machine-specific or when one of the build or runtime
6031 dependencies is already machine-architecture dependent,
6032 which makes your recipe also machine-architecture dependent,
6033 make sure your recipe enables the "machine" package
6034 architecture through the
6035 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6036 variable:
6037 <literallayout class='monospaced'>
6038 PACKAGE_ARCH = "${MACHINE_ARCH}"
6039 </literallayout>
6040 When you do not specifically enable a package
6041 architecture through the
6042 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6043 The OpenEmbedded build system defaults to the
6044 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6045 setting:
6046 <literallayout class='monospaced'>
6047 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6048 </literallayout>
6049 </para></listitem>
6050 <listitem><para>
6051 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6052 Some tunes are more generic and can run on multiple targets
6053 (e.g. an <filename>armv5</filename> set of packages could
6054 run on <filename>armv6</filename> and
6055 <filename>armv7</filename> processors in most cases).
6056 Similarly, <filename>i486</filename> binaries could work
6057 on <filename>i586</filename> and higher processors.
6058 You should realize, however, that advances on newer
6059 processor versions would not be used.</para>
6060
6061 <para>If you select the same tune for several different
6062 machines, the OpenEmbedded build system reuses software
6063 previously built, thus speeding up the overall build time.
6064 Realize that even though a new sysroot for each machine is
6065 generated, the software is not recompiled and only one
6066 package feed exists.
6067 </para></listitem>
6068 <listitem><para>
6069 <emphasis>Manage Granular Level Packaging:</emphasis>
6070 Sometimes cases exist where injecting another level of
6071 package architecture beyond the three higher levels noted
6072 earlier can be useful.
6073 For example, consider how NXP (formerly Freescale) allows
6074 for the easy reuse of binary packages in their layer
6075 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6076 In this example, the
6077 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6078 class shares GPU packages for i.MX53 boards because
6079 all boards share the AMD GPU.
6080 The i.MX6-based boards can do the same because all boards
6081 share the Vivante GPU.
6082 This class inspects the BitBake datastore to identify if
6083 the package provides or depends on one of the
6084 sub-architecture values.
6085 If so, the class sets the
6086 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6087 value based on the <filename>MACHINE_SUBARCH</filename>
6088 value.
6089 If the package does not provide or depend on one of the
6090 sub-architecture values but it matches a value in the
6091 machine-specific filter, it sets
6092 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6093 This behavior reduces the number of packages built and
6094 saves build time by reusing binaries.
6095 </para></listitem>
6096 <listitem><para>
6097 <emphasis>Use Tools to Debug Issues:</emphasis>
6098 Sometimes you can run into situations where software is
6099 being rebuilt when you think it should not be.
6100 For example, the OpenEmbedded build system might not be
6101 using shared state between machines when you think it
6102 should be.
6103 These types of situations are usually due to references
6104 to machine-specific variables such as
6105 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6106 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6107 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6108 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6109 and so forth in code that is supposed to only be
6110 tune-specific or when the recipe depends
6111 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6112 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6113 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6114 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6115 and so forth) on some other recipe that already has
6116 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6117 defined as "${MACHINE_ARCH}".
6118 <note>
6119 Patches to fix any issues identified are most welcome
6120 as these issues occasionally do occur.
6121 </note></para>
6122
6123 <para>For such cases, you can use some tools to help you
6124 sort out the situation:
6125 <itemizedlist>
6126 <listitem><para>
6127 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6128 You can find this tool in the
6129 <filename>scripts</filename> directory of the
6130 Source Repositories.
6131 See the comments in the script for information on
6132 how to use the tool.
6133 </para></listitem>
6134 <listitem><para>
6135 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6136 Using this option causes BitBake to try to
6137 establish the closest signature match it can
6138 (e.g. in the shared state cache) and then run
6139 <filename>bitbake-diffsigs</filename> over the
6140 matches to determine the stamps and delta where
6141 these two stamp trees diverge.
6142 </para></listitem>
6143 </itemizedlist>
6144 </para></listitem>
6145 </itemizedlist>
6146 </para>
6147 </section>
6148
6149 <section id="building-software-from-an-external-source">
6150 <title>Building Software from an External Source</title>
6151
6152 <para>
6153 By default, the OpenEmbedded build system uses the
6154 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6155 when building source code.
6156 The build process involves fetching the source files, unpacking
6157 them, and then patching them if necessary before the build takes
6158 place.
6159 </para>
6160
6161 <para>
6162 Situations exist where you might want to build software from source
6163 files that are external to and thus outside of the
6164 OpenEmbedded build system.
6165 For example, suppose you have a project that includes a new BSP with
6166 a heavily customized kernel.
6167 And, you want to minimize exposing the build system to the
6168 development team so that they can focus on their project and
6169 maintain everyone's workflow as much as possible.
6170 In this case, you want a kernel source directory on the development
6171 machine where the development occurs.
6172 You want the recipe's
6173 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6174 variable to point to the external directory and use it as is, not
6175 copy it.
6176 </para>
6177
6178 <para>
6179 To build from software that comes from an external source, all you
6180 need to do is inherit the
6181 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6182 class and then set the
6183 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6184 variable to point to your external source code.
6185 Here are the statements to put in your
6186 <filename>local.conf</filename> file:
6187 <literallayout class='monospaced'>
6188 INHERIT += "externalsrc"
6189 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6190 </literallayout>
6191 </para>
6192
6193 <para>
6194 This next example shows how to accomplish the same thing by setting
6195 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6196 recipe's append file:
6197 <literallayout class='monospaced'>
6198 EXTERNALSRC = "<replaceable>path</replaceable>"
6199 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6200 </literallayout>
6201 <note>
6202 In order for these settings to take effect, you must globally
6203 or locally inherit the
6204 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6205 class.
6206 </note>
6207 </para>
6208
6209 <para>
6210 By default, <filename>externalsrc.bbclass</filename> builds
6211 the source code in a directory separate from the external source
6212 directory as specified by
6213 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6214 If you need to have the source built in the same directory in
6215 which it resides, or some other nominated directory, you can set
6216 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6217 to point to that directory:
6218 <literallayout class='monospaced'>
6219 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6220 </literallayout>
6221 </para>
6222 </section>
6223 </section>
6224
6225
6226
6227 <section id='speeding-up-a-build'>
6228 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006229
6230 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006231 Build time can be an issue.
6232 By default, the build system uses simple controls to try and maximize
6233 build efficiency.
6234 In general, the default settings for all the following variables
6235 result in the most efficient build times when dealing with single
6236 socket systems (i.e. a single CPU).
6237 If you have multiple CPUs, you might try increasing the default
6238 values to gain more speed.
6239 See the descriptions in the glossary for each variable for more
6240 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006241 <itemizedlist>
6242 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006243 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6244 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006245 </para></listitem>
6246 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006247 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6248 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006249 </para></listitem>
6250 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006251 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6252 Extra options passed to the <filename>make</filename> command
6253 during the
6254 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6255 task in order to specify parallel compilation on the
6256 local build host.
6257 </para></listitem>
6258 <listitem><para>
6259 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6260 Extra options passed to the <filename>make</filename> command
6261 during the
6262 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6263 task in order to specify parallel installation on the
6264 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006265 </para></listitem>
6266 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006267 As mentioned, these variables all scale to the number of processor
6268 cores available on the build system.
6269 For single socket systems, this auto-scaling ensures that the build
6270 system fundamentally takes advantage of potential parallel operations
6271 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006272 </para>
6273
6274 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006275 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006276 <itemizedlist>
6277 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006278 File system type:
6279 The file system type that the build is being performed on can
6280 also influence performance.
6281 Using <filename>ext4</filename> is recommended as compared
6282 to <filename>ext2</filename> and <filename>ext3</filename>
6283 due to <filename>ext4</filename> improved features
6284 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006285 </para></listitem>
6286 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006287 Disabling the updating of access time using
6288 <filename>noatime</filename>:
6289 The <filename>noatime</filename> mount option prevents the
6290 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006291 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006292 <listitem><para>
6293 Setting a longer commit:
6294 Using the "commit=" mount option increases the interval
6295 in seconds between disk cache writes.
6296 Changing this interval from the five second default to
6297 something longer increases the risk of data loss but decreases
6298 the need to write to the disk, thus increasing the build
6299 performance.
6300 </para></listitem>
6301 <listitem><para>
6302 Choosing the packaging backend:
6303 Of the available packaging backends, IPK is the fastest.
6304 Additionally, selecting a singular packaging backend also
6305 helps.
6306 </para></listitem>
6307 <listitem><para>
6308 Using <filename>tmpfs</filename> for
6309 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6310 as a temporary file system:
6311 While this can help speed up the build, the benefits are
6312 limited due to the compiler using
6313 <filename>-pipe</filename>.
6314 The build system goes to some lengths to avoid
6315 <filename>sync()</filename> calls into the
6316 file system on the principle that if there was a significant
6317 failure, the
6318 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6319 contents could easily be rebuilt.
6320 </para></listitem>
6321 <listitem><para>
6322 Inheriting the
6323 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6324 class:
6325 Inheriting this class has shown to speed up builds due to
6326 significantly lower amounts of data stored in the data
6327 cache as well as on disk.
6328 Inheriting this class also makes cleanup of
6329 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6330 faster, at the expense of being easily able to dive into the
6331 source code.
6332 File system maintainers have recommended that the fastest way
6333 to clean up large numbers of files is to reformat partitions
6334 rather than delete files due to the linear nature of
6335 partitions.
6336 This, of course, assumes you structure the disk partitions and
6337 file systems in a way that this is practical.
6338 </para></listitem>
6339 </itemizedlist>
6340 Aside from the previous list, you should keep some trade offs in
6341 mind that can help you speed up the build:
6342 <itemizedlist>
6343 <listitem><para>
6344 Remove items from
6345 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6346 that you might not need.
6347 </para></listitem>
6348 <listitem><para>
6349 Exclude debug symbols and other debug information:
6350 If you do not need these symbols and other debug information,
6351 disabling the <filename>*-dbg</filename> package generation
6352 can speed up the build.
6353 You can disable this generation by setting the
6354 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6355 variable to "1".
6356 </para></listitem>
6357 <listitem><para>
6358 Disable static library generation for recipes derived from
6359 <filename>autoconf</filename> or <filename>libtool</filename>:
6360 Following is an example showing how to disable static
6361 libraries and still provide an override to handle exceptions:
6362 <literallayout class='monospaced'>
6363 STATICLIBCONF = "--disable-static"
6364 STATICLIBCONF_sqlite3-native = ""
6365 EXTRA_OECONF += "${STATICLIBCONF}"
6366 </literallayout>
6367 <note><title>Notes</title>
6368 <itemizedlist>
6369 <listitem><para>
6370 Some recipes need static libraries in order to work
6371 correctly (e.g. <filename>pseudo-native</filename>
6372 needs <filename>sqlite3-native</filename>).
6373 Overrides, as in the previous example, account for
6374 these kinds of exceptions.
6375 </para></listitem>
6376 <listitem><para>
6377 Some packages have packaging code that assumes the
6378 presence of the static libraries.
6379 If so, you might need to exclude them as well.
6380 </para></listitem>
6381 </itemizedlist>
6382 </note>
6383 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006384 </itemizedlist>
6385 </para>
6386 </section>
6387
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006388 <section id="platdev-working-with-libraries">
6389 <title>Working With Libraries</title>
6390
6391 <para>
6392 Libraries are an integral part of your system.
6393 This section describes some common practices you might find
6394 helpful when working with libraries to build your system:
6395 <itemizedlist>
6396 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6397 </para></listitem>
6398 <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>
6399 </para></listitem>
6400 <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>
6401 </para></listitem>
6402 </itemizedlist>
6403 </para>
6404
6405 <section id='including-static-library-files'>
6406 <title>Including Static Library Files</title>
6407
6408 <para>
6409 If you are building a library and the library offers static linking, you can control
6410 which static library files (<filename>*.a</filename> files) get included in the
6411 built library.
6412 </para>
6413
6414 <para>
6415 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6416 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6417 variables in the
6418 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6419 by the <filename>do_install</filename> task are packaged.
6420 By default, the <filename>PACKAGES</filename> variable includes
6421 <filename>${PN}-staticdev</filename>, which represents all static library files.
6422 <note>
6423 Some previously released versions of the Yocto Project
6424 defined the static library files through
6425 <filename>${PN}-dev</filename>.
6426 </note>
6427 Following is part of the BitBake configuration file, where
6428 you can see how the static library files are defined:
6429 <literallayout class='monospaced'>
6430 PACKAGE_BEFORE_PN ?= ""
6431 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6432 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6433 FILES = ""
6434
6435 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6436 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6437 ${base_bindir}/* ${base_sbindir}/* \
6438 ${base_libdir}/*${SOLIBS} \
6439 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6440 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6441 ${datadir}/pixmaps ${datadir}/applications \
6442 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6443 ${libdir}/bonobo/servers"
6444
6445 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6446
6447 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6448 ${datadir}/gnome/help"
6449 SECTION_${PN}-doc = "doc"
6450
6451 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6452 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6453 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6454 ${datadir}/aclocal ${base_libdir}/*.o \
6455 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6456 SECTION_${PN}-dev = "devel"
6457 ALLOW_EMPTY_${PN}-dev = "1"
6458 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6459
6460 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6461 SECTION_${PN}-staticdev = "devel"
6462 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6463 </literallayout>
6464 </para>
6465 </section>
6466
6467 <section id="combining-multiple-versions-library-files-into-one-image">
6468 <title>Combining Multiple Versions of Library Files into One Image</title>
6469
6470 <para>
6471 The build system offers the ability to build libraries with different
6472 target optimizations or architecture formats and combine these together
6473 into one system image.
6474 You can link different binaries in the image
6475 against the different libraries as needed for specific use cases.
6476 This feature is called "Multilib."
6477 </para>
6478
6479 <para>
6480 An example would be where you have most of a system compiled in 32-bit
6481 mode using 32-bit libraries, but you have something large, like a database
6482 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6483 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6484 </para>
6485
6486 <para>
6487 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6488 the approach the build system uses facilitates different target optimizations.
6489 You could compile some binaries to use one set of libraries and other binaries
6490 to use a different set of libraries.
6491 The libraries could differ in architecture, compiler options, or other
6492 optimizations.
6493 </para>
6494
6495 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006496 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006497 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006498 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006499 <itemizedlist>
6500 <listitem><para><filename>conf/multilib-example.conf</filename>
6501 configuration file</para></listitem>
6502 <listitem><para><filename>conf/multilib-example2.conf</filename>
6503 configuration file</para></listitem>
6504 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6505 recipe</para></listitem>
6506 </itemizedlist>
6507 </para>
6508
6509 <section id='preparing-to-use-multilib'>
6510 <title>Preparing to Use Multilib</title>
6511
6512 <para>
6513 User-specific requirements drive the Multilib feature.
6514 Consequently, there is no one "out-of-the-box" configuration that likely
6515 exists to meet your needs.
6516 </para>
6517
6518 <para>
6519 In order to enable Multilib, you first need to ensure your recipe is
6520 extended to support multiple libraries.
6521 Many standard recipes are already extended and support multiple libraries.
6522 You can check in the <filename>meta/conf/multilib.conf</filename>
6523 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006524 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006525 done using the
6526 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6527 variable.
6528 Eventually, all recipes will be covered and this list will
6529 not be needed.
6530 </para>
6531
6532 <para>
6533 For the most part, the Multilib class extension works automatically to
6534 extend the package name from <filename>${PN}</filename> to
6535 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6536 is the particular multilib (e.g. "lib32-" or "lib64-").
6537 Standard variables such as
6538 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6539 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6540 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6541 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6542 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6543 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6544 are automatically extended by the system.
6545 If you are extending any manual code in the recipe, you can use the
6546 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6547 correctly.
6548 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6549 </para>
6550 </section>
6551
6552 <section id='using-multilib'>
6553 <title>Using Multilib</title>
6554
6555 <para>
6556 After you have set up the recipes, you need to define the actual
6557 combination of multiple libraries you want to build.
6558 You accomplish this through your <filename>local.conf</filename>
6559 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006560 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006561 An example configuration would be as follows:
6562 <literallayout class='monospaced'>
6563 MACHINE = "qemux86-64"
6564 require conf/multilib.conf
6565 MULTILIBS = "multilib:lib32"
6566 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006567 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006568 </literallayout>
6569 This example enables an
6570 additional library named <filename>lib32</filename> alongside the
6571 normal target packages.
6572 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6573 For information on this particular tuning, see
6574 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6575 </para>
6576
6577 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006578 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006579 in all the images, which illustrates one method of including a
6580 multiple library dependency.
6581 You can use a normal image build to include this dependency,
6582 for example:
6583 <literallayout class='monospaced'>
6584 $ bitbake core-image-sato
6585 </literallayout>
6586 You can also build Multilib packages specifically with a command like this:
6587 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006588 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006589 </literallayout>
6590 </para>
6591 </section>
6592
6593 <section id='additional-implementation-details'>
6594 <title>Additional Implementation Details</title>
6595
6596 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006597 Generic implementation details as well as details that are
6598 specific to package management systems exist.
6599 Following are implementation details that exist regardless
6600 of the package management system:
6601 <itemizedlist>
6602 <listitem><para>The typical convention used for the
6603 class extension code as used by
6604 Multilib assumes that all package names specified
6605 in
6606 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6607 that contain <filename>${PN}</filename> have
6608 <filename>${PN}</filename> at the start of the name.
6609 When that convention is not followed and
6610 <filename>${PN}</filename> appears at
6611 the middle or the end of a name, problems occur.
6612 </para></listitem>
6613 <listitem><para>The
6614 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6615 value under Multilib will be extended to
6616 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6617 (e.g. "-pokymllib32" for a "lib32" Multilib with
6618 Poky).
6619 The reason for this slightly unwieldy contraction
6620 is that any "-" characters in the vendor
6621 string presently break Autoconf's
6622 <filename>config.sub</filename>, and
6623 other separators are problematic for different
6624 reasons.
6625 </para></listitem>
6626 </itemizedlist>
6627 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006628
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006629 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006630 For the RPM Package Management System, the following implementation details
6631 exist:
6632 <itemizedlist>
6633 <listitem><para>A unique architecture is defined for the Multilib packages,
6634 along with creating a unique deploy folder under
6635 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006636 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006637 For example, consider <filename>lib32</filename> in a
6638 <filename>qemux86-64</filename> image.
6639 The possible architectures in the system are "all", "qemux86_64",
6640 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6641 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6642 <filename>${PN}</filename> during RPM packaging.
6643 The naming for a normal RPM package and a Multilib RPM package in a
6644 <filename>qemux86-64</filename> system resolves to something similar to
6645 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6646 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6647 </para></listitem>
6648 <listitem><para>When installing a Multilib image, the RPM backend first
6649 installs the base image and then installs the Multilib libraries.
6650 </para></listitem>
6651 <listitem><para>The build system relies on RPM to resolve the identical files in the
6652 two (or more) Multilib packages.</para></listitem>
6653 </itemizedlist>
6654 </para>
6655
6656 <para>
6657 For the IPK Package Management System, the following implementation details exist:
6658 <itemizedlist>
6659 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6660 <filename>${PN}</filename> during IPK packaging.
6661 The naming for a normal RPM package and a Multilib IPK package in a
6662 <filename>qemux86-64</filename> system resolves to something like
6663 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6664 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6665 </para></listitem>
6666 <listitem><para>The IPK deploy folder is not modified with
6667 <filename>${MLPREFIX}</filename> because packages with and without
6668 the Multilib feature can exist in the same folder due to the
6669 <filename>${PN}</filename> differences.</para></listitem>
6670 <listitem><para>IPK defines a sanity check for Multilib installation
6671 using certain rules for file comparison, overridden, etc.
6672 </para></listitem>
6673 </itemizedlist>
6674 </para>
6675 </section>
6676 </section>
6677
6678 <section id='installing-multiple-versions-of-the-same-library'>
6679 <title>Installing Multiple Versions of the Same Library</title>
6680
6681 <para>
6682 Situations can exist where you need to install and use
6683 multiple versions of the same library on the same system
6684 at the same time.
6685 These situations almost always exist when a library API
6686 changes and you have multiple pieces of software that
6687 depend on the separate versions of the library.
6688 To accommodate these situations, you can install multiple
6689 versions of the same library in parallel on the same system.
6690 </para>
6691
6692 <para>
6693 The process is straightforward as long as the libraries use
6694 proper versioning.
6695 With properly versioned libraries, all you need to do to
6696 individually specify the libraries is create separate,
6697 appropriately named recipes where the
6698 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6699 name includes a portion that differentiates each library version
6700 (e.g.the major part of the version number).
6701 Thus, instead of having a single recipe that loads one version
6702 of a library (e.g. <filename>clutter</filename>), you provide
6703 multiple recipes that result in different versions
6704 of the libraries you want.
6705 As an example, the following two recipes would allow the
6706 two separate versions of the <filename>clutter</filename>
6707 library to co-exist on the same system:
6708 <literallayout class='monospaced'>
6709 clutter-1.6_1.6.20.bb
6710 clutter-1.8_1.8.4.bb
6711 </literallayout>
6712 Additionally, if you have other recipes that depend on a given
6713 library, you need to use the
6714 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
6715 variable to create the dependency.
6716 Continuing with the same example, if you want to have a recipe
6717 depend on the 1.8 version of the <filename>clutter</filename>
6718 library, use the following in your recipe:
6719 <literallayout class='monospaced'>
6720 DEPENDS = "clutter-1.8"
6721 </literallayout>
6722 </para>
6723 </section>
6724 </section>
6725
Brad Bishop316dfdd2018-06-25 12:45:53 -04006726 <section id='using-x32-psabi'>
6727 <title>Using x32 psABI</title>
6728
6729 <para>
6730 x32 processor-specific Application Binary Interface
6731 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
6732 is a native 32-bit processor-specific ABI for
6733 <trademark class='registered'>Intel</trademark> 64 (x86-64)
6734 architectures.
6735 An ABI defines the calling conventions between functions in a
6736 processing environment.
6737 The interface determines what registers are used and what the
6738 sizes are for various C data types.
6739 </para>
6740
6741 <para>
6742 Some processing environments prefer using 32-bit applications even
6743 when running on Intel 64-bit platforms.
6744 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
6745 64-bit platforms.
6746 The i386 psABI does not provide efficient use and access of the
6747 Intel 64-bit processor resources, leaving the system underutilized.
6748 Now consider the x86_64 psABI.
6749 This ABI is newer and uses 64-bits for data sizes and program
6750 pointers.
6751 The extra bits increase the footprint size of the programs,
6752 libraries, and also increases the memory and file system size
6753 requirements.
6754 Executing under the x32 psABI enables user programs to utilize CPU
6755 and system resources more efficiently while keeping the memory
6756 footprint of the applications low.
6757 Extra bits are used for registers but not for addressing mechanisms.
6758 </para>
6759
6760 <para>
6761 The Yocto Project supports the final specifications of x32 psABI
6762 as follows:
6763 <itemizedlist>
6764 <listitem><para>
6765 You can create packages and images in x32 psABI format on
6766 x86_64 architecture targets.
6767 </para></listitem>
6768 <listitem><para>
6769 You can successfully build recipes with the x32 toolchain.
6770 </para></listitem>
6771 <listitem><para>
6772 You can create and boot
6773 <filename>core-image-minimal</filename> and
6774 <filename>core-image-sato</filename> images.
6775 </para></listitem>
6776 <listitem><para>
6777 RPM Package Manager (RPM) support exists for x32 binaries.
6778 </para></listitem>
6779 <listitem><para>
6780 Support for large images exists.
6781 </para></listitem>
6782 </itemizedlist>
6783 </para>
6784
6785 <para>
6786 To use the x32 psABI, you need to edit your
6787 <filename>conf/local.conf</filename> configuration file as
6788 follows:
6789 <literallayout class='monospaced'>
6790 MACHINE = "qemux86-64"
6791 DEFAULTTUNE = "x86-64-x32"
6792 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE', True) \
6793 or 'INVALID'), True) or 'lib'}"
6794 </literallayout>
6795 Once you have set up your configuration file, use BitBake to
6796 build an image that supports the x32 psABI.
6797 Here is an example:
6798 <literallayout class='monospaced'>
6799 $ bitbake core-image-sato
6800 </literallayout>
6801 </para>
6802 </section>
6803
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006804 <section id='enabling-gobject-introspection-support'>
6805 <title>Enabling GObject Introspection Support</title>
6806
6807 <para>
6808 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
6809 is the standard mechanism for accessing GObject-based software
6810 from runtime environments.
6811 GObject is a feature of the GLib library that provides an object
6812 framework for the GNOME desktop and related software.
6813 GObject Introspection adds information to GObject that allows
6814 objects created within it to be represented across different
6815 programming languages.
6816 If you want to construct GStreamer pipelines using Python, or
6817 control UPnP infrastructure using Javascript and GUPnP,
6818 GObject introspection is the only way to do it.
6819 </para>
6820
6821 <para>
6822 This section describes the Yocto Project support for generating
6823 and packaging GObject introspection data.
6824 GObject introspection data is a description of the
6825 API provided by libraries built on top of GLib framework,
6826 and, in particular, that framework's GObject mechanism.
6827 GObject Introspection Repository (GIR) files go to
6828 <filename>-dev</filename> packages,
6829 <filename>typelib</filename> files go to main packages as they
6830 are packaged together with libraries that are introspected.
6831 </para>
6832
6833 <para>
6834 The data is generated when building such a library, by linking
6835 the library with a small executable binary that asks the library
6836 to describe itself, and then executing the binary and
6837 processing its output.
6838 </para>
6839
6840 <para>
6841 Generating this data in a cross-compilation environment
6842 is difficult because the library is produced for the target
6843 architecture, but its code needs to be executed on the build host.
6844 This problem is solved with the OpenEmbedded build system by
6845 running the code through QEMU, which allows precisely that.
6846 Unfortunately, QEMU does not always work perfectly as mentioned
6847 in the xxx section.
6848 </para>
6849
6850 <section id='enabling-the-generation-of-introspection-data'>
6851 <title>Enabling the Generation of Introspection Data</title>
6852
6853 <para>
6854 Enabling the generation of introspection data (GIR files)
6855 in your library package involves the following:
6856 <orderedlist>
6857 <listitem><para>
6858 Inherit the
6859 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
6860 class.
6861 </para></listitem>
6862 <listitem><para>
6863 Make sure introspection is not disabled anywhere in
6864 the recipe or from anything the recipe includes.
6865 Also, make sure that "gobject-introspection-data" is
6866 not in
6867 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
6868 and that "qemu-usermode" is not in
6869 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
6870 If either of these conditions exist, nothing will
6871 happen.
6872 </para></listitem>
6873 <listitem><para>
6874 Try to build the recipe.
6875 If you encounter build errors that look like
6876 something is unable to find
6877 <filename>.so</filename> libraries, check where these
6878 libraries are located in the source tree and add
6879 the following to the recipe:
6880 <literallayout class='monospaced'>
6881 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
6882 </literallayout>
6883 <note>
6884 See recipes in the <filename>oe-core</filename>
6885 repository that use that
6886 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
6887 as an example.
6888 </note>
6889 </para></listitem>
6890 <listitem><para>
6891 Look for any other errors, which probably mean that
6892 introspection support in a package is not entirely
6893 standard, and thus breaks down in a cross-compilation
6894 environment.
6895 For such cases, custom-made fixes are needed.
6896 A good place to ask and receive help in these cases
6897 is the
6898 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
6899 </para></listitem>
6900 </orderedlist>
6901 <note>
6902 Using a library that no longer builds against the latest
6903 Yocto Project release and prints introspection related
6904 errors is a good candidate for the previous procedure.
6905 </note>
6906 </para>
6907 </section>
6908
6909 <section id='disabling-the-generation-of-introspection-data'>
6910 <title>Disabling the Generation of Introspection Data</title>
6911
6912 <para>
6913 You might find that you do not want to generate
6914 introspection data.
6915 Or, perhaps QEMU does not work on your build host and
6916 target architecture combination.
6917 If so, you can use either of the following methods to
6918 disable GIR file generations:
6919 <itemizedlist>
6920 <listitem><para>
6921 Add the following to your distro configuration:
6922 <literallayout class='monospaced'>
6923 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
6924 </literallayout>
6925 Adding this statement disables generating
6926 introspection data using QEMU but will still enable
6927 building introspection tools and libraries
6928 (i.e. building them does not require the use of QEMU).
6929 </para></listitem>
6930 <listitem><para>
6931 Add the following to your machine configuration:
6932 <literallayout class='monospaced'>
6933 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
6934 </literallayout>
6935 Adding this statement disables the use of QEMU
6936 when building packages for your machine.
6937 Currently, this feature is used only by introspection
6938 recipes and has the same effect as the previously
6939 described option.
6940 <note>
6941 Future releases of the Yocto Project might have
6942 other features affected by this option.
6943 </note>
6944 </para></listitem>
6945 </itemizedlist>
6946 If you disable introspection data, you can still
6947 obtain it through other means such as copying the data
6948 from a suitable sysroot, or by generating it on the
6949 target hardware.
6950 The OpenEmbedded build system does not currently
6951 provide specific support for these techniques.
6952 </para>
6953 </section>
6954
6955 <section id='testing-that-introspection-works-in-an-image'>
6956 <title>Testing that Introspection Works in an Image</title>
6957
6958 <para>
6959 Use the following procedure to test if generating
6960 introspection data is working in an image:
6961 <orderedlist>
6962 <listitem><para>
6963 Make sure that "gobject-introspection-data" is not in
6964 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
6965 and that "qemu-usermode" is not in
6966 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
6967 </para></listitem>
6968 <listitem><para>
6969 Build <filename>core-image-sato</filename>.
6970 </para></listitem>
6971 <listitem><para>
6972 Launch a Terminal and then start Python in the
6973 terminal.
6974 </para></listitem>
6975 <listitem><para>
6976 Enter the following in the terminal:
6977 <literallayout class='monospaced'>
6978 >>> from gi.repository import GLib
6979 >>> GLib.get_host_name()
6980 </literallayout>
6981 </para></listitem>
6982 <listitem><para>
6983 For something a little more advanced, enter the
6984 following:
6985 <literallayout class='monospaced'>
6986 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
6987 </literallayout>
6988 </para></listitem>
6989 </orderedlist>
6990 </para>
6991 </section>
6992
6993 <section id='known-issues'>
6994 <title>Known Issues</title>
6995
6996 <para>
6997 The following know issues exist for
6998 GObject Introspection Support:
6999 <itemizedlist>
7000 <listitem><para>
7001 <filename>qemu-ppc64</filename> immediately crashes.
7002 Consequently, you cannot build introspection data on
7003 that architecture.
7004 </para></listitem>
7005 <listitem><para>
7006 x32 is not supported by QEMU.
7007 Consequently, introspection data is disabled.
7008 </para></listitem>
7009 <listitem><para>
7010 musl causes transient GLib binaries to crash on
7011 assertion failures.
7012 Consequently, generating introspection data is
7013 disabled.
7014 </para></listitem>
7015 <listitem><para>
7016 Because QEMU is not able to run the binaries correctly,
7017 introspection is disabled for some specific packages
7018 under specific architectures (e.g.
7019 <filename>gcr</filename>,
7020 <filename>libsecret</filename>, and
7021 <filename>webkit</filename>).
7022 </para></listitem>
7023 <listitem><para>
7024 QEMU usermode might not work properly when running
7025 64-bit binaries under 32-bit host machines.
7026 In particular, "qemumips64" is known to not work under
7027 i686.
7028 </para></listitem>
7029 </itemizedlist>
7030 </para>
7031 </section>
7032 </section>
7033
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007034 <section id='dev-optionally-using-an-external-toolchain'>
7035 <title>Optionally Using an External Toolchain</title>
7036
7037 <para>
7038 You might want to use an external toolchain as part of your
7039 development.
7040 If this is the case, the fundamental steps you need to accomplish
7041 are as follows:
7042 <itemizedlist>
7043 <listitem><para>
7044 Understand where the installed toolchain resides.
7045 For cases where you need to build the external toolchain,
7046 you would need to take separate steps to build and install
7047 the toolchain.
7048 </para></listitem>
7049 <listitem><para>
7050 Make sure you add the layer that contains the toolchain to
7051 your <filename>bblayers.conf</filename> file through the
7052 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7053 variable.
7054 </para></listitem>
7055 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007056 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007057 variable in your <filename>local.conf</filename> file
7058 to the location in which you installed the toolchain.
7059 </para></listitem>
7060 </itemizedlist>
7061 A good example of an external toolchain used with the Yocto Project
7062 is <trademark class='registered'>Mentor Graphics</trademark>
7063 Sourcery G++ Toolchain.
7064 You can see information on how to use that particular layer in the
7065 <filename>README</filename> file at
7066 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7067 You can find further information by reading about the
7068 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7069 variable in the Yocto Project Reference Manual's variable glossary.
7070 </para>
7071 </section>
7072
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007073 <section id='creating-partitioned-images-using-wic'>
7074 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007075
7076 <para>
7077 Creating an image for a particular hardware target using the
7078 OpenEmbedded build system does not necessarily mean you can boot
7079 that image as is on your device.
7080 Physical devices accept and boot images in various ways depending
7081 on the specifics of the device.
7082 Usually, information about the hardware can tell you what image
7083 format the device requires.
7084 Should your device require multiple partitions on an SD card, flash,
7085 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007086 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007087 </para>
7088
7089 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007090 The <filename>wic</filename> command generates partitioned
7091 images from existing OpenEmbedded build artifacts.
7092 Image generation is driven by partitioning commands
7093 contained in an Openembedded kickstart file
7094 (<filename>.wks</filename>) specified either directly on
7095 the command line or as one of a selection of canned
7096 kickstart files as shown with the
7097 <filename>wic list images</filename> command in the
7098 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7099 section.
7100 When you apply the command to a given set of build
7101 artifacts, the result is an image or set of images that
7102 can be directly written onto media and used on a particular
7103 system.
7104 <note>
7105 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007106 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007107 Chapter in the Yocto Project Reference Manual.
7108 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007109 </para>
7110
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007111 <para>
7112 The <filename>wic</filename> command and the infrastructure
7113 it is based on is by definition incomplete.
7114 The purpose of the command is to allow the generation of
7115 customized images, and as such, was designed to be
7116 completely extensible through a plug-in interface.
7117 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007118 "<link linkend='wic-using-the-wic-plug-ins-interface'>Using the Wic Plug-Ins Interface</link>"
7119 section for information on these plug-ins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007120 </para>
7121
7122 <para>
7123 This section provides some background information on Wic,
7124 describes what you need to have in
7125 place to run the tool, provides instruction on how to use
Brad Bishop316dfdd2018-06-25 12:45:53 -04007126 the Wic utility, provides information on using the Wic plug-ins
7127 interface, and provides several examples that show how to use
7128 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007129 </para>
7130
7131 <section id='wic-background'>
7132 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007133
7134 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007135 This section provides some background on the Wic utility.
7136 While none of this information is required to use
7137 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007138 <itemizedlist>
7139 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007140 The name "Wic" is derived from OpenEmbedded
7141 Image Creator (oeic).
7142 The "oe" diphthong in "oeic" was promoted to the
7143 letter "w", because "oeic" is both difficult to
7144 remember and to pronounce.
7145 </para></listitem>
7146 <listitem><para>
7147 Wic is loosely based on the
7148 Meego Image Creator (<filename>mic</filename>)
7149 framework.
7150 The Wic implementation has been
7151 heavily modified to make direct use of OpenEmbedded
7152 build artifacts instead of package installation and
7153 configuration, which are already incorporated within
7154 the OpenEmbedded artifacts.
7155 </para></listitem>
7156 <listitem><para>
7157 Wic is a completely independent
7158 standalone utility that initially provides
7159 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007160 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007161 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
7162 class and <filename>mkefidisk.sh</filename> script.
7163 The difference between
7164 Wic and those examples is
7165 that with Wic the
7166 functionality of those scripts is implemented
7167 by a general-purpose partitioning language, which is
7168 based on Redhat kickstart syntax.</para></listitem>
7169 </itemizedlist>
7170 </para>
7171 </section>
7172
7173 <section id='wic-requirements'>
7174 <title>Requirements</title>
7175
7176 <para>
7177 In order to use the Wic utility with the OpenEmbedded Build
7178 system, your system needs to meet the following
7179 requirements:
7180 <itemizedlist>
7181 <listitem><para>
7182 The Linux distribution on your development host must
7183 support the Yocto Project.
7184 See the
7185 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7186 section in the Yocto Project Reference Manual for
7187 the list of distributions that support the
7188 Yocto Project.
7189 </para></listitem>
7190 <listitem><para>
7191 The standard system utilities, such as
7192 <filename>cp</filename>, must be installed on your
7193 development host system.
7194 </para></listitem>
7195 <listitem><para>
7196 You must have sourced the build environment
7197 setup script (i.e.
7198 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7199 found in the
7200 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7201 </para></listitem>
7202 <listitem><para>
7203 You need to have the build artifacts already
7204 available, which typically means that you must
7205 have already created an image using the
7206 Openembedded build system (e.g.
7207 <filename>core-image-minimal</filename>).
7208 While it might seem redundant to generate an image
7209 in order to create an image using
7210 Wic, the current version of
7211 Wic requires the artifacts
7212 in the form generated by the OpenEmbedded build
7213 system.
7214 </para></listitem>
7215 <listitem><para>
7216 You must build several native tools, which are
7217 built to run on the build system:
7218 <literallayout class='monospaced'>
7219 $ bitbake parted-native dosfstools-native mtools-native
7220 </literallayout>
7221 </para></listitem>
7222 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007223 Include "wic" as part of the
7224 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7225 variable.
7226 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007227 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007228 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007229 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007230 as part of the
7231 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7232 variable
7233 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007234 </itemizedlist>
7235 </para>
7236 </section>
7237
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007238 <section id='wic-getting-help'>
7239 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007240
7241 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007242 You can get general help for the <filename>wic</filename>
7243 command by entering the <filename>wic</filename> command
7244 by itself or by entering the command with a help argument
7245 as follows:
7246 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007247 $ wic -h
7248 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007249 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007250 </literallayout>
7251 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007252
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007253 <para>
7254 Currently, Wic supports seven commands:
7255 <filename>cp</filename>, <filename>create</filename>,
7256 <filename>help</filename>, <filename>list</filename>,
7257 <filename>ls</filename>, <filename>rm</filename>, and
7258 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007259 You can get help for all these commands except "help" by
7260 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007261 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007262 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007263 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007264 For example, the following command returns help for the
7265 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007266 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007267 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007268 </literallayout>
7269 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007270
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007271 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007272 Wic supports help for three topics:
7273 <filename>overview</filename>,
7274 <filename>plugins</filename>, and
7275 <filename>kickstart</filename>.
7276 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007277 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007278 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007279 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007280 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007281 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007282 $ wic help overview
7283 </literallayout>
7284 </para>
7285
7286 <para>
7287 One additional level of help exists for Wic.
7288 You can get help on individual images through the
7289 <filename>list</filename> command.
7290 You can use the <filename>list</filename> command to return the
7291 available Wic images as follows:
7292 <literallayout class='monospaced'>
7293 $ wic list images
7294 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7295 genericx86 Create an EFI disk image for genericx86*
7296 beaglebone-yocto Create SD card image for Beaglebone
7297 edgerouter Create SD card image for Edgerouter
7298 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7299 directdisk-gpt Create a 'pcbios' direct disk image
7300 mkefidisk Create an EFI disk image
7301 directdisk Create a 'pcbios' direct disk image
7302 systemd-bootdisk Create an EFI disk image with systemd-boot
7303 mkhybridiso Create a hybrid ISO image
7304 sdimage-bootpart Create SD card image with a boot partition
7305 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7306 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7307 </literallayout>
7308 Once you know the list of available Wic images, you can use
7309 <filename>help</filename> with the command to get help on a
7310 particular image.
7311 For example, the following command returns help on the
7312 "beaglebone-yocto" image:
7313 <literallayout class='monospaced'>
7314 $ wic list beaglebone-yocto help
7315
7316
7317 Creates a partitioned SD card image for Beaglebone.
7318 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007319 </literallayout>
7320 </para>
7321 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007322
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007323 <section id='operational-modes'>
7324 <title>Operational Modes</title>
7325
7326 <para>
7327 You can use Wic in two different
7328 modes, depending on how much control you need for
7329 specifying the Openembedded build artifacts that are
7330 used for creating the image: Raw and Cooked:
7331 <itemizedlist>
7332 <listitem><para>
7333 <emphasis>Raw Mode:</emphasis>
7334 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007335 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007336 </para></listitem>
7337 <listitem><para>
7338 <emphasis>Cooked Mode:</emphasis>
7339 The current
7340 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7341 setting and image name are used to automatically
7342 locate and provide the build artifacts.
7343 You just supply a kickstart file and the name
7344 of the image from which to use artifacts.
7345 </para></listitem>
7346 </itemizedlist>
7347 </para>
7348
7349 <para>
7350 Regardless of the mode you use, you need to have the build
7351 artifacts ready and available.
7352 </para>
7353
7354 <section id='raw-mode'>
7355 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007356
7357 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007358 Running Wic in raw mode allows you to specify all the
7359 partitions through the <filename>wic</filename>
7360 command line.
7361 The primary use for raw mode is if you have built
7362 your kernel outside of the Yocto Project
7363 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7364 In other words, you can point to arbitrary kernel,
7365 root filesystem locations, and so forth.
7366 Contrast this behavior with cooked mode where Wic
7367 looks in the Build Directory (e.g.
7368 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007369 </para>
7370
7371 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007372 The general form of the
7373 <filename>wic</filename> command in raw mode is:
7374 <literallayout class='monospaced'>
7375 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007376
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007377 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007378
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007379 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007380 An OpenEmbedded kickstart file. You can provide
7381 your own custom file or use a file from a set of
7382 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007383
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007384 optional arguments:
7385 -h, --help show this help message and exit
7386 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7387 name of directory to create image in
7388 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7389 name of the image to use the artifacts from e.g. core-
7390 image-sato
7391 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7392 path to the /rootfs dir to use as the .wks rootfs
7393 source
7394 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7395 path to the dir containing the boot artifacts (e.g.
7396 /EFI or /syslinux dirs) to use as the .wks bootimg
7397 source
7398 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7399 path to the dir containing the kernel to use in the
7400 .wks bootimg
7401 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7402 path to the native sysroot containing the tools to use
7403 to build the image
7404 -s, --skip-build-check
7405 skip the build check
7406 -f, --build-rootfs build rootfs
7407 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7408 compress image with specified compressor
7409 -m, --bmap generate .bmap
7410 --no-fstab-update Do not change fstab file.
7411 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7412 directory with &lt;image&gt;.env files that store bitbake
7413 variables
7414 -D, --debug output debug information
7415 </literallayout>
7416 <note>
7417 You do not need root privileges to run
7418 Wic.
7419 In fact, you should not run as root when using the
7420 utility.
7421 </note>
7422 </para>
7423 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007424
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007425 <section id='cooked-mode'>
7426 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007427
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007428 <para>
7429 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007430 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007431 In other words, you do not have to specify kernel or
7432 root filesystem locations as part of the command.
7433 All you need to provide is a kickstart file and the
7434 name of the image from which to use artifacts by using
7435 the "-e" option.
7436 Wic looks in the Build Directory (e.g.
7437 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7438 for artifacts.
7439 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007440
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007441 <para>
7442 The general form of the <filename>wic</filename>
7443 command using Cooked Mode is as follows:
7444 <literallayout class='monospaced'>
7445 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007446
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007447 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007448
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007449 <replaceable>wks_file</replaceable>:
7450 An OpenEmbedded kickstart file. You can provide
7451 your own custom file or use a file from a set of
7452 existing files provided with the Yocto Project
7453 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007454
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007455 required argument:
7456 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7457 name of the image to use the artifacts from e.g. core-
7458 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007459 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007460 </para>
7461 </section>
7462 </section>
7463
7464 <section id='using-a-provided-kickstart-file'>
7465 <title>Using an Existing Kickstart File</title>
7466
7467 <para>
7468 If you do not want to create your own kickstart file, you
7469 can use an existing file provided by the Wic installation.
7470 As shipped, kickstart files can be found in the
7471 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007472 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007473 in the following two locations:
7474 <literallayout class='monospaced'>
7475 poky/meta-yocto-bsp/wic
7476 poky/scripts/lib/wic/canned-wks
7477 </literallayout>
7478 Use the following command to list the available kickstart
7479 files:
7480 <literallayout class='monospaced'>
7481 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007482 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7483 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007484 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007485 edgerouter Create SD card image for Edgerouter
7486 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7487 directdisk-gpt Create a 'pcbios' direct disk image
7488 mkefidisk Create an EFI disk image
7489 directdisk Create a 'pcbios' direct disk image
7490 systemd-bootdisk Create an EFI disk image with systemd-boot
7491 mkhybridiso Create a hybrid ISO image
7492 sdimage-bootpart Create SD card image with a boot partition
7493 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7494 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7495 </literallayout>
7496 When you use an existing file, you do not have to use the
7497 <filename>.wks</filename> extension.
7498 Here is an example in Raw Mode that uses the
7499 <filename>directdisk</filename> file:
7500 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007501 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7502 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007503 </literallayout>
7504 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007505
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007506 <para>
7507 Here are the actual partition language commands
7508 used in the <filename>genericx86.wks</filename> file to
7509 generate an image:
7510 <literallayout class='monospaced'>
7511 # short-description: Create an EFI disk image for genericx86*
7512 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7513 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7514 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007515 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7516
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007517 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7518 </literallayout>
7519 </para>
7520 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007521
Brad Bishop316dfdd2018-06-25 12:45:53 -04007522 <section id='wic-using-the-wic-plug-ins-interface'>
7523 <title>Using the Wic Plug-Ins Interface</title>
7524
7525 <para>
7526 You can extend and specialize Wic functionality by using
7527 Wic plug-ins.
7528 This section explains the Wic plug-in interface.
7529 <note>
7530 Wic plug-ins consist of "source" and "imager" plug-ins.
7531 Imager plug-ins are beyond the scope of this section.
7532 </note>
7533 </para>
7534
7535 <para>
7536 Source plug-ins provide a mechanism to customize partition
7537 content during the Wic image generation process.
7538 You can use source plug-ins to map values that you specify
7539 using <filename>--source</filename> commands in kickstart
7540 files (i.e. <filename>*.wks</filename>) to a plug-in
7541 implementation used to populate a given partition.
7542 <note>
7543 If you use plug-ins that have build-time dependencies
7544 (e.g. native tools, bootloaders, and so forth)
7545 when building a Wic image, you need to specify those
7546 dependencies using the
7547 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7548 variable.
7549 </note>
7550 </para>
7551
7552 <para>
7553 Source plug-ins are subclasses defined in plug-in files.
7554 As shipped, the Yocto Project provides several plug-in
7555 files.
7556 You can see the source plug-in files that ship with the
7557 Yocto Project
7558 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
7559 Each of these plug-in files contains source plug-ins that
7560 are designed to populate a specific Wic image partition.
7561 </para>
7562
7563 <para>
7564 Source plug-ins are subclasses of the
7565 <filename>SourcePlugin</filename> class, which is
7566 defined in the
7567 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7568 file.
7569 For example, the <filename>BootimgEFIPlugin</filename>
7570 source plug-in found in the
7571 <filename>bootimg-efi.py</filename> file is a subclass of
7572 the <filename>SourcePlugin</filename> class, which is found
7573 in the <filename>pluginbase.py</filename> file.
7574 </para>
7575
7576 <para>
7577 You can also implement source plug-ins in a layer outside
7578 of the Source Repositories (external layer).
7579 To do so, be sure that your plug-in files are located in
7580 a directory whose path is
7581 <filename>scripts/lib/wic/plugins/source/</filename>
7582 within your external layer.
7583 When the plug-in files are located there, the source
7584 plug-ins they contain are made available to Wic.
7585 </para>
7586
7587 <para>
7588 When the Wic implementation needs to invoke a
7589 partition-specific implementation, it looks for the plug-in
7590 with the same name as the <filename>--source</filename>
7591 parameter used in the kickstart file given to that
7592 partition.
7593 For example, if the partition is set up using the following
7594 command in a kickstart file:
7595 <literallayout class='monospaced'>
7596 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7597 </literallayout>
7598 The methods defined as class members of the matching
7599 source plug-in (i.e. <filename>bootimg-pcbios</filename>)
7600 in the <filename>bootimg-pcbios.py</filename> plug-in file
7601 are used.
7602 </para>
7603
7604 <para>
7605 To be more concrete, here is the corresponding plug-in
7606 definition from the <filename>bootimg-pcbios.py</filename>
7607 file for the previous command along with an example
7608 method called by the Wic implementation when it needs to
7609 prepare a partition using an implementation-specific
7610 function:
7611 <literallayout class='monospaced'>
7612 .
7613 .
7614 .
7615 class BootimgPcbiosPlugin(SourcePlugin):
7616 """
7617 Create MBR boot partition and install syslinux on it.
7618 """
7619
7620 name = 'bootimg-pcbios'
7621 .
7622 .
7623 .
7624 @classmethod
7625 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7626 oe_builddir, bootimg_dir, kernel_dir,
7627 rootfs_dir, native_sysroot):
7628 """
7629 Called to do the actual content population for a partition i.e. it
7630 'prepares' the partition to be incorporated into the image.
7631 In this case, prepare content for legacy bios boot partition.
7632 """
7633 .
7634 .
7635 .
7636 </literallayout>
7637 If a subclass (plug-in) itself does not implement a
7638 particular function, Wic locates and uses the default
7639 version in the superclass.
7640 It is for this reason that all source plug-ins are derived
7641 from the <filename>SourcePlugin</filename> class.
7642 </para>
7643
7644 <para>
7645 The <filename>SourcePlugin</filename> class defined in
7646 the <filename>pluginbase.py</filename> file defines
7647 a set of methods that source plug-ins can implement or
7648 override.
7649 Any plug-ins (subclass of
7650 <filename>SourcePlugin</filename>) that do not implement
7651 a particular method inherit the implementation of the
7652 method from the <filename>SourcePlugin</filename> class.
7653 For more information, see the
7654 <filename>SourcePlugin</filename> class in the
7655 <filename>pluginbase.py</filename> file for details:
7656 </para>
7657
7658 <para>
7659 The following list describes the methods implemented in the
7660 <filename>SourcePlugin</filename> class:
7661 <itemizedlist>
7662 <listitem><para>
7663 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7664 Called to populate a partition with actual content.
7665 In other words, the method prepares the final
7666 partition image that is incorporated into the
7667 disk image.
7668 </para></listitem>
7669 <listitem><para>
7670 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7671 Called before
7672 <filename>do_prepare_partition()</filename> to
7673 create custom configuration files for a partition
7674 (e.g. syslinux or grub configuration files).
7675 </para></listitem>
7676 <listitem><para>
7677 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7678 Called after all partitions have been prepared and
7679 assembled into a disk image.
7680 This method provides a hook to allow finalization
7681 of a disk image (e.g. writing an MBR).
7682 </para></listitem>
7683 <listitem><para>
7684 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7685 Special content-staging hook called before
7686 <filename>do_prepare_partition()</filename>.
7687 This method is normally empty.</para>
7688
7689 <para>Typically, a partition just uses the passed-in
7690 parameters (e.g. the unmodified value of
7691 <filename>bootimg_dir</filename>).
7692 However, in some cases, things might need to be
7693 more tailored.
7694 As an example, certain files might additionally
7695 need to be taken from
7696 <filename>bootimg_dir + /boot</filename>.
7697 This hook allows those files to be staged in a
7698 customized fashion.
7699 <note>
7700 <filename>get_bitbake_var()</filename>
7701 allows you to access non-standard variables
7702 that you might want to use for this
7703 behavior.
7704 </note>
7705 </para></listitem>
7706 </itemizedlist>
7707 </para>
7708
7709 <para>
7710 You can extend the source plug-in mechanism.
7711 To add more hooks, create more source plug-in methods
7712 within <filename>SourcePlugin</filename> and the
7713 corresponding derived subclasses.
7714 The code that calls the plug-in methods uses the
7715 <filename>plugin.get_source_plugin_methods()</filename>
7716 function to find the method or methods needed by the call.
7717 Retrieval of those methods is accomplished by filling up
7718 a dict with keys that contain the method names of interest.
7719 On success, these will be filled in with the actual
7720 methods.
7721 See the Wic implementation for examples and details.
7722 </para>
7723 </section>
7724
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007725 <section id='wic-usage-examples'>
7726 <title>Examples</title>
7727
7728 <para>
7729 This section provides several examples that show how to use
7730 the Wic utility.
7731 All the examples assume the list of requirements in the
7732 "<link linkend='wic-requirements'>Requirements</link>"
7733 section have been met.
7734 The examples assume the previously generated image is
7735 <filename>core-image-minimal</filename>.
7736 </para>
7737
7738 <section id='generate-an-image-using-a-provided-kickstart-file'>
7739 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007740
7741 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007742 This example runs in Cooked Mode and uses the
7743 <filename>mkefidisk</filename> kickstart file:
7744 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007745 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007746 INFO: Building wic-tools...
7747 .
7748 .
7749 .
7750 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007751 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007752
7753 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04007754 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
7755 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
7756 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
7757 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 -05007758
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007759 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007760 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007761 </literallayout>
7762 The previous example shows the easiest way to create
7763 an image by running in cooked mode and supplying
7764 a kickstart file and the "-e" option to point to the
7765 existing build artifacts.
7766 Your <filename>local.conf</filename> file needs to have
7767 the
7768 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7769 variable set to the machine you are using, which is
7770 "qemux86" in this example.
7771 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007772
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007773 <para>
7774 Once the image builds, the output provides image
7775 location, artifact use, and kickstart file information.
7776 <note>
7777 You should always verify the details provided in the
7778 output to make sure that the image was indeed
7779 created exactly as expected.
7780 </note>
7781 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007782
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007783 <para>
7784 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007785 image from the Build Directory onto a USB stick, or
7786 whatever media for which you built your image, and boot
7787 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007788 You can write the image by using
7789 <filename>bmaptool</filename> or
7790 <filename>dd</filename>:
7791 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007792 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007793 </literallayout>
7794 or
7795 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007796 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007797 </literallayout>
7798 <note>
7799 For more information on how to use the
7800 <filename>bmaptool</filename> to flash a device
7801 with an image, see the
7802 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
7803 section.
7804 </note>
7805 </para>
7806 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007807
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007808 <section id='using-a-modified-kickstart-file'>
7809 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007810
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007811 <para>
7812 Because partitioned image creation is driven by the
7813 kickstart file, it is easy to affect image creation by
7814 changing the parameters in the file.
7815 This next example demonstrates that through modification
7816 of the <filename>directdisk-gpt</filename> kickstart
7817 file.
7818 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007819
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007820 <para>
7821 As mentioned earlier, you can use the command
7822 <filename>wic list images</filename> to show the list
7823 of existing kickstart files.
7824 The directory in which the
7825 <filename>directdisk-gpt.wks</filename> file resides is
7826 <filename>scripts/lib/image/canned-wks/</filename>,
7827 which is located in the
7828 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
7829 (e.g. <filename>poky</filename>).
7830 Because available files reside in this directory,
7831 you can create and add your own custom files to the
7832 directory.
7833 Subsequent use of the
7834 <filename>wic list images</filename> command would then
7835 include your kickstart files.
7836 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007837
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007838 <para>
7839 In this example, the existing
7840 <filename>directdisk-gpt</filename> file already does
7841 most of what is needed.
7842 However, for the hardware in this example, the image
7843 will need to boot from <filename>sdb</filename> instead
7844 of <filename>sda</filename>, which is what the
7845 <filename>directdisk-gpt</filename> kickstart file
7846 uses.
7847 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007848
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007849 <para>
7850 The example begins by making a copy of the
7851 <filename>directdisk-gpt.wks</filename> file in the
7852 <filename>scripts/lib/image/canned-wks</filename>
7853 directory and then by changing the lines that specify
7854 the target disk from which to boot.
7855 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007856 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
7857 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007858 </literallayout>
7859 Next, the example modifies the
7860 <filename>directdisksdb-gpt.wks</filename> file and
7861 changes all instances of
7862 "<filename>--ondisk sda</filename>" to
7863 "<filename>--ondisk sdb</filename>".
7864 The example changes the following two lines and leaves
7865 the remaining lines untouched:
7866 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007867 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007868 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
7869 </literallayout>
7870 Once the lines are changed, the example generates the
7871 <filename>directdisksdb-gpt</filename> image.
7872 The command points the process at the
7873 <filename>core-image-minimal</filename> artifacts for
7874 the Next Unit of Computing (nuc)
7875 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7876 the <filename>local.conf</filename>.
7877 <literallayout class='monospaced'>
7878 $ wic create directdisksdb-gpt -e core-image-minimal
7879 INFO: Building wic-tools...
7880 .
7881 .
7882 .
7883 Initialising tasks: 100% |#######################################| Time: 0:00:01
7884 NOTE: Executing SetScene Tasks
7885 NOTE: Executing RunQueue Tasks
7886 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
7887 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007888
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007889 INFO: The new image(s) can be found here:
7890 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007891
7892 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04007893 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
7894 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
7895 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
7896 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 -05007897
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007898 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007899 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007900 </literallayout>
7901 Continuing with the example, you can now directly
7902 <filename>dd</filename> the image to a USB stick, or
7903 whatever media for which you built your image,
7904 and boot the resulting media:
7905 <literallayout class='monospaced'>
7906 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
7907 140966+0 records in
7908 140966+0 records out
7909 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
7910 $ sudo eject /dev/sdb
7911 </literallayout>
7912 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007913 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007914
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007915 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
7916 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007917
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007918 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007919 This next example manually specifies each build artifact
7920 (runs in Raw Mode) and uses a modified kickstart file.
7921 The example also uses the <filename>-o</filename> option
7922 to cause Wic to create the output
7923 somewhere other than the default output directory,
7924 which is the current directory:
7925 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007926 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
7927 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
7928 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
7929 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
7930 --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 -05007931
7932 INFO: Creating image(s)...
7933
7934 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007935 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007936
7937 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04007938 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
7939 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
7940 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
7941 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 -05007942
7943 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007944 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007945 </literallayout>
7946 For this example,
7947 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7948 did not have to be specified in the
7949 <filename>local.conf</filename> file since the
7950 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007951 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007952 </section>
7953
7954 <section id='using-wic-to-manipulate-an-image'>
7955 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007956
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007957 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007958 Wic image manipulation allows you to shorten turnaround
7959 time during image development.
7960 For example, you can use Wic to delete the kernel partition
7961 of a Wic image and then insert a newly built kernel.
7962 This saves you time from having to rebuild the entire image
7963 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007964 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007965 In order to use Wic to manipulate a Wic image as in
7966 this example, your development machine must have the
7967 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007968 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007969 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007970
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007971 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007972 The following example examines the contents of the Wic
7973 image, deletes the existing kernel, and then inserts a
7974 new kernel:
7975 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007976 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007977 <emphasis>List the Partitions:</emphasis>
7978 Use the <filename>wic ls</filename> command to list
7979 all the partitions in the Wic image:
7980 <literallayout class='monospaced'>
7981 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
7982 Num Start End Size Fstype
7983 1 1048576 25041919 23993344 fat16
7984 2 25165824 72157183 46991360 ext4
7985 </literallayout>
7986 The previous output shows two partitions in the
7987 <filename>core-image-minimal-qemux86.wic</filename>
7988 image.
7989 </para></listitem>
7990 <listitem><para>
7991 <emphasis>Examine a Particular Partition:</emphasis>
7992 Use the <filename>wic ls</filename> command again
7993 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007994 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007995 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007996 You can get command usage on any Wic command
7997 using the following form:
7998 <literallayout class='monospaced'>
7999 $ wic help <replaceable>command</replaceable>
8000 </literallayout>
8001 For example, the following command shows you
8002 the various ways to use the
8003 <filename>wic ls</filename> command:
8004 <literallayout class='monospaced'>
8005 $ wic help ls
8006 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008007 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008008 The following command shows what is in Partition
8009 one:
8010 <literallayout class='monospaced'>
8011 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8012 Volume in drive : is boot
8013 Volume Serial Number is E894-1809
8014 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008015
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008016 libcom32 c32 186500 2017-10-09 16:06
8017 libutil c32 24148 2017-10-09 16:06
8018 syslinux cfg 220 2017-10-09 16:06
8019 vesamenu c32 27104 2017-10-09 16:06
8020 vmlinuz 6904608 2017-10-09 16:06
8021 5 files 7 142 580 bytes
8022 16 582 656 bytes free
8023 </literallayout>
8024 The previous output shows five files, with the
8025 <filename>vmlinuz</filename> being the kernel.
8026 <note>
8027 If you see the following error, you need to
8028 update or create a
8029 <filename>~/.mtoolsrc</filename> file and
8030 be sure to have the line “mtools_skip_check=1“
8031 in the file.
8032 Then, run the Wic command again:
8033 <literallayout class='monospaced'>
8034 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8035 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8036 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8037 </literallayout>
8038 </note>
8039 </para></listitem>
8040 <listitem><para>
8041 <emphasis>Remove the Old Kernel:</emphasis>
8042 Use the <filename>wic rm</filename> command to
8043 remove the <filename>vmlinuz</filename> file
8044 (kernel):
8045 <literallayout class='monospaced'>
8046 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8047 </literallayout>
8048 </para></listitem>
8049 <listitem><para>
8050 <emphasis>Add In the New Kernel:</emphasis>
8051 Use the <filename>wic cp</filename> command to
8052 add the updated kernel to the Wic image.
8053 Depending on how you built your kernel, it could
8054 be in different places.
8055 If you used <filename>devtool</filename> and
8056 an SDK to build your kernel, it resides in the
8057 <filename>tmp/work</filename> directory of the
8058 extensible SDK.
8059 If you used <filename>make</filename> to build the
8060 kernel, the kernel will be in the
8061 <filename>workspace/sources</filename> area.
8062 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008063
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008064 <para>The following example assumes
8065 <filename>devtool</filename> was used to build
8066 the kernel:
8067 <literallayout class='monospaced'>
8068 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 \
8069 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8070 </literallayout>
8071 Once the new kernel is added back into the image,
8072 you can use the <filename>dd</filename>
8073 command or
8074 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8075 to flash your wic image onto an SD card
8076 or USB stick and test your target.
8077 <note>
8078 Using <filename>bmaptool</filename> is
8079 generally 10 to 20 times faster than using
8080 <filename>dd</filename>.
8081 </note>
8082 </para></listitem>
8083 </orderedlist>
8084 </para>
8085 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008086 </section>
8087 </section>
8088
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008089 <section id='flashing-images-using-bmaptool'>
8090 <title>Flashing Images Using <filename>bmaptool</filename></title>
8091
8092 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008093 A fast and easy way to flash an image to a bootable device
8094 is to use Bmaptool, which is integrated into the OpenEmbedded
8095 build system.
8096 Bmaptool is a generic tool that creates a file's block map (bmap)
8097 and then uses that map to copy the file.
8098 As compared to traditional tools such as dd or cp, Bmaptool
8099 can copy (or flash) large files like raw system image files
8100 much faster.
8101 <note><title>Notes</title>
8102 <itemizedlist>
8103 <listitem><para>
8104 If you are using Ubuntu or Debian distributions, you
8105 can install the <filename>bmap-tools</filename> package
8106 using the following command and then use the tool
8107 without specifying <filename>PATH</filename> even from
8108 the root account:
8109 <literallayout class='monospaced'>
8110 $ sudo apt-get install bmap-tools
8111 </literallayout>
8112 </para></listitem>
8113 <listitem><para>
8114 If you are unable to install the
8115 <filename>bmap-tools</filename> package, you will
8116 need to build Bmaptool before using it.
8117 Use the following command:
8118 <literallayout class='monospaced'>
8119 $ bitbake bmap-tools-native
8120 </literallayout>
8121 </para></listitem>
8122 </itemizedlist>
8123 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008124 </para>
8125
8126 <para>
8127 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008128 Realize that while this example uses a Wic image, you can use
8129 Bmaptool to flash any type of image.
8130 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008131 <orderedlist>
8132 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008133 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8134 You need to have the following set in your
8135 <filename>local.conf</filename> file before building
8136 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008137 <literallayout class='monospaced'>
8138 IMAGE_FSTYPES += "wic wic.bmap"
8139 </literallayout>
8140 </para></listitem>
8141 <listitem><para>
8142 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008143 Either have your image ready (pre-built with the
8144 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8145 setting previously mentioned) or take the step to build
8146 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008147 <literallayout class='monospaced'>
8148 $ bitbake <replaceable>image</replaceable>
8149 </literallayout>
8150 </para></listitem>
8151 <listitem><para>
8152 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008153 Flash the device with the image by using Bmaptool
8154 depending on your particular setup.
8155 The following commands assume the image resides in the
8156 Build Directory's <filename>deploy/images/</filename>
8157 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008158 <itemizedlist>
8159 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008160 If you have write access to the media, use this
8161 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008162 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008163 $ 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 -05008164 </literallayout>
8165 </para></listitem>
8166 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008167 If you do not have write access to the media, set
8168 your permissions first and then use the same
8169 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008170 <literallayout class='monospaced'>
8171 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008172 $ 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 -05008173 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008174 </para></listitem>
8175 </itemizedlist>
8176 </para></listitem>
8177 </orderedlist>
8178 </para>
8179
8180 <para>
8181 For help on the <filename>bmaptool</filename> command, use the
8182 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008183 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008184 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008185 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008186 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008187 </section>
8188
8189 <section id='making-images-more-secure'>
8190 <title>Making Images More Secure</title>
8191
8192 <para>
8193 Security is of increasing concern for embedded devices.
8194 Consider the issues and problems discussed in just this
8195 sampling of work found across the Internet:
8196 <itemizedlist>
8197 <listitem><para><emphasis>
8198 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8199 by Bruce Schneier
8200 </para></listitem>
8201 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008202 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008203 by Carna Botnet</para></listitem>
8204 <listitem><para><emphasis>
8205 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8206 by Jake Edge
8207 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008208 </itemizedlist>
8209 </para>
8210
8211 <para>
8212 When securing your image is of concern, there are steps, tools,
8213 and variables that you can consider to help you reach the
8214 security goals you need for your particular device.
8215 Not all situations are identical when it comes to making an
8216 image secure.
8217 Consequently, this section provides some guidance and suggestions
8218 for consideration when you want to make your image more secure.
8219 <note>
8220 Because the security requirements and risks are
8221 different for every type of device, this section cannot
8222 provide a complete reference on securing your custom OS.
8223 It is strongly recommended that you also consult other sources
8224 of information on embedded Linux system hardening and on
8225 security.
8226 </note>
8227 </para>
8228
8229 <section id='general-considerations'>
8230 <title>General Considerations</title>
8231
8232 <para>
8233 General considerations exist that help you create more
8234 secure images.
8235 You should consider the following suggestions to help
8236 make your device more secure:
8237 <itemizedlist>
8238 <listitem><para>
8239 Scan additional code you are adding to the system
8240 (e.g. application code) by using static analysis
8241 tools.
8242 Look for buffer overflows and other potential
8243 security problems.
8244 </para></listitem>
8245 <listitem><para>
8246 Pay particular attention to the security for
8247 any web-based administration interface.
8248 </para>
8249 <para>Web interfaces typically need to perform
8250 administrative functions and tend to need to run with
8251 elevated privileges.
8252 Thus, the consequences resulting from the interface's
8253 security becoming compromised can be serious.
8254 Look for common web vulnerabilities such as
8255 cross-site-scripting (XSS), unvalidated inputs,
8256 and so forth.</para>
8257 <para>As with system passwords, the default credentials
8258 for accessing a web-based interface should not be the
8259 same across all devices.
8260 This is particularly true if the interface is enabled
8261 by default as it can be assumed that many end-users
8262 will not change the credentials.
8263 </para></listitem>
8264 <listitem><para>
8265 Ensure you can update the software on the device to
8266 mitigate vulnerabilities discovered in the future.
8267 This consideration especially applies when your
8268 device is network-enabled.
8269 </para></listitem>
8270 <listitem><para>
8271 Ensure you remove or disable debugging functionality
8272 before producing the final image.
8273 For information on how to do this, see the
8274 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8275 section.
8276 </para></listitem>
8277 <listitem><para>
8278 Ensure you have no network services listening that
8279 are not needed.
8280 </para></listitem>
8281 <listitem><para>
8282 Remove any software from the image that is not needed.
8283 </para></listitem>
8284 <listitem><para>
8285 Enable hardware support for secure boot functionality
8286 when your device supports this functionality.
8287 </para></listitem>
8288 </itemizedlist>
8289 </para>
8290 </section>
8291
8292 <section id='security-flags'>
8293 <title>Security Flags</title>
8294
8295 <para>
8296 The Yocto Project has security flags that you can enable that
8297 help make your build output more secure.
8298 The security flags are in the
8299 <filename>meta/conf/distro/include/security_flags.inc</filename>
8300 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008301 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008302 (e.g. <filename>poky</filename>).
8303 <note>
8304 Depending on the recipe, certain security flags are enabled
8305 and disabled by default.
8306 </note>
8307 </para>
8308
8309 <para>
8310<!--
8311 The GCC/LD flags in <filename>security_flags.inc</filename>
8312 enable more secure code generation.
8313 By including the <filename>security_flags.inc</filename>
8314 file, you enable flags to the compiler and linker that cause
8315 them to generate more secure code.
8316 <note>
8317 The GCC/LD flags are enabled by default in the
8318 <filename>poky-lsb</filename> distribution.
8319 </note>
8320-->
8321 Use the following line in your
8322 <filename>local.conf</filename> file or in your custom
8323 distribution configuration file to enable the security
8324 compiler and linker flags for your build:
8325 <literallayout class='monospaced'>
8326 require conf/distro/include/security_flags.inc
8327 </literallayout>
8328 </para>
8329 </section>
8330
8331 <section id='considerations-specific-to-the-openembedded-build-system'>
8332 <title>Considerations Specific to the OpenEmbedded Build System</title>
8333
8334 <para>
8335 You can take some steps that are specific to the
8336 OpenEmbedded build system to make your images more secure:
8337 <itemizedlist>
8338 <listitem><para>
8339 Ensure "debug-tweaks" is not one of your selected
8340 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8341 When creating a new project, the default is to provide you
8342 with an initial <filename>local.conf</filename> file that
8343 enables this feature using the
8344 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8345 <literallayout class='monospaced'>
8346 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8347 </literallayout>
8348 To disable that feature, simply comment out that line in your
8349 <filename>local.conf</filename> file, or
8350 make sure <filename>IMAGE_FEATURES</filename> does not contain
8351 "debug-tweaks" before producing your final image.
8352 Among other things, leaving this in place sets the
8353 root password as blank, which makes logging in for
8354 debugging or inspection easy during
8355 development but also means anyone can easily log in
8356 during production.
8357 </para></listitem>
8358 <listitem><para>
8359 It is possible to set a root password for the image
8360 and also to set passwords for any extra users you might
8361 add (e.g. administrative or service type users).
8362 When you set up passwords for multiple images or
8363 users, you should not duplicate passwords.
8364 </para>
8365 <para>
8366 To set up passwords, use the
8367 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8368 class, which is the preferred method.
8369 For an example on how to set up both root and user
8370 passwords, see the
8371 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8372 section.
8373 <note>
8374 When adding extra user accounts or setting a
8375 root password, be cautious about setting the
8376 same password on every device.
8377 If you do this, and the password you have set
8378 is exposed, then every device is now potentially
8379 compromised.
8380 If you need this access but want to ensure
8381 security, consider setting a different,
8382 random password for each device.
8383 Typically, you do this as a separate step after
8384 you deploy the image onto the device.
8385 </note>
8386 </para></listitem>
8387 <listitem><para>
8388 Consider enabling a Mandatory Access Control (MAC)
8389 framework such as SMACK or SELinux and tuning it
8390 appropriately for your device's usage.
8391 You can find more information in the
8392 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8393 layer.
8394 </para></listitem>
8395 </itemizedlist>
8396 </para>
8397
8398 <para>
8399 </para>
8400 </section>
8401
8402 <section id='tools-for-hardening-your-image'>
8403 <title>Tools for Hardening Your Image</title>
8404
8405 <para>
8406 The Yocto Project provides tools for making your image
8407 more secure.
8408 You can find these tools in the
8409 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008410 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008411 </para>
8412 </section>
8413 </section>
8414
8415 <section id='creating-your-own-distribution'>
8416 <title>Creating Your Own Distribution</title>
8417
8418 <para>
8419 When you build an image using the Yocto Project and
8420 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008421 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8422 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008423 If you wish to gain more control over package alternative
8424 selections, compile-time options, and other low-level
8425 configurations, you can create your own distribution.
8426 </para>
8427
8428 <para>
8429 To create your own distribution, the basic steps consist of
8430 creating your own distribution layer, creating your own
8431 distribution configuration file, and then adding any needed
8432 code and Metadata to the layer.
8433 The following steps provide some more detail:
8434 <itemizedlist>
8435 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8436 Create your distribution layer so that you can keep your
8437 Metadata and code for the distribution separate.
8438 It is strongly recommended that you create and use your own
8439 layer for configuration and code.
8440 Using your own layer as compared to just placing
8441 configurations in a <filename>local.conf</filename>
8442 configuration file makes it easier to reproduce the same
8443 build configuration when using multiple build machines.
8444 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008445 "<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 -05008446 section for information on how to quickly set up a layer.
8447 </para></listitem>
8448 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8449 The distribution configuration file needs to be created in
8450 the <filename>conf/distro</filename> directory of your
8451 layer.
8452 You need to name it using your distribution name
8453 (e.g. <filename>mydistro.conf</filename>).
8454 <note>
8455 The
8456 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8457 variable in your
8458 <filename>local.conf</filename> file determines the
8459 name of your distribution.
8460 </note></para>
8461 <para>You can split out parts of your configuration file
8462 into include files and then "require" them from within
8463 your distribution configuration file.
8464 Be sure to place the include files in the
8465 <filename>conf/distro/include</filename> directory of
8466 your layer.
8467 A common example usage of include files would be to
8468 separate out the selection of desired version and revisions
8469 for individual recipes.
8470</para>
8471 <para>Your configuration file needs to set the following
8472 required variables:
8473 <literallayout class='monospaced'>
8474 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8475 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8476 </literallayout>
8477 These following variables are optional and you typically
8478 set them from the distribution configuration file:
8479 <literallayout class='monospaced'>
8480 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8481 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8482 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8483 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8484 </literallayout>
8485 <tip>
8486 If you want to base your distribution configuration file
8487 on the very basic configuration from OE-Core, you
8488 can use
8489 <filename>conf/distro/defaultsetup.conf</filename> as
8490 a reference and just include variables that differ
8491 as compared to <filename>defaultsetup.conf</filename>.
8492 Alternatively, you can create a distribution
8493 configuration file from scratch using the
8494 <filename>defaultsetup.conf</filename> file
8495 or configuration files from other distributions
8496 such as Poky or Angstrom as references.
8497 </tip></para></listitem>
8498 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8499 Be sure to define any other variables for which you want to
8500 create a default or enforce as part of the distribution
8501 configuration.
8502 You can include nearly any variable from the
8503 <filename>local.conf</filename> file.
8504 The variables you use are not limited to the list in the
8505 previous bulleted item.</para></listitem>
8506 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8507 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008508 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008509 set your
8510 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8511 variable to point to your distribution's configuration file.
8512 For example, if your distribution's configuration file is
8513 named <filename>mydistro.conf</filename>, then you point
8514 to it as follows:
8515 <literallayout class='monospaced'>
8516 DISTRO = "mydistro"
8517 </literallayout></para></listitem>
8518 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8519 Use your layer to hold other information needed for the
8520 distribution:
8521 <itemizedlist>
8522 <listitem><para>Add recipes for installing
8523 distro-specific configuration files that are not
8524 already installed by another recipe.
8525 If you have distro-specific configuration files
8526 that are included by an existing recipe, you should
8527 add an append file (<filename>.bbappend</filename>)
8528 for those.
8529 For general information and recommendations
8530 on how to add recipes to your layer, see the
8531 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8532 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008533 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008534 sections.</para></listitem>
8535 <listitem><para>Add any image recipes that are specific
8536 to your distribution.</para></listitem>
8537 <listitem><para>Add a <filename>psplash</filename>
8538 append file for a branded splash screen.
8539 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008540 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008541 section.</para></listitem>
8542 <listitem><para>Add any other append files to make
8543 custom changes that are specific to individual
8544 recipes.</para></listitem>
8545 </itemizedlist></para></listitem>
8546 </itemizedlist>
8547 </para>
8548 </section>
8549
8550 <section id='creating-a-custom-template-configuration-directory'>
8551 <title>Creating a Custom Template Configuration Directory</title>
8552
8553 <para>
8554 If you are producing your own customized version
8555 of the build system for use by other users, you might
8556 want to customize the message shown by the setup script or
8557 you might want to change the template configuration files (i.e.
8558 <filename>local.conf</filename> and
8559 <filename>bblayers.conf</filename>) that are created in
8560 a new build directory.
8561 </para>
8562
8563 <para>
8564 The OpenEmbedded build system uses the environment variable
8565 <filename>TEMPLATECONF</filename> to locate the directory
8566 from which it gathers configuration information that ultimately
8567 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008568 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008569 <filename>conf</filename> directory.
8570 By default, <filename>TEMPLATECONF</filename> is set as
8571 follows in the <filename>poky</filename> repository:
8572 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008573 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008574 </literallayout>
8575 This is the directory used by the build system to find templates
8576 from which to build some key configuration files.
8577 If you look at this directory, you will see the
8578 <filename>bblayers.conf.sample</filename>,
8579 <filename>local.conf.sample</filename>, and
8580 <filename>conf-notes.txt</filename> files.
8581 The build system uses these files to form the respective
8582 <filename>bblayers.conf</filename> file,
8583 <filename>local.conf</filename> file, and display the list of
8584 BitBake targets when running the setup script.
8585 </para>
8586
8587 <para>
8588 To override these default configuration files with
8589 configurations you want used within every new
8590 Build Directory, simply set the
8591 <filename>TEMPLATECONF</filename> variable to your directory.
8592 The <filename>TEMPLATECONF</filename> variable is set in the
8593 <filename>.templateconf</filename> file, which is in the
8594 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008595 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008596 folder (e.g. <filename>poky</filename>).
8597 Edit the <filename>.templateconf</filename> so that it can locate
8598 your directory.
8599 </para>
8600
8601 <para>
8602 Best practices dictate that you should keep your
8603 template configuration directory in your custom distribution layer.
8604 For example, suppose you have a layer named
8605 <filename>meta-mylayer</filename> located in your home directory
8606 and you want your template configuration directory named
8607 <filename>myconf</filename>.
8608 Changing the <filename>.templateconf</filename> as follows
8609 causes the OpenEmbedded build system to look in your directory
8610 and base its configuration files on the
8611 <filename>*.sample</filename> configuration files it finds.
8612 The final configuration files (i.e.
8613 <filename>local.conf</filename> and
8614 <filename>bblayers.conf</filename> ultimately still end up in
8615 your Build Directory, but they are based on your
8616 <filename>*.sample</filename> files.
8617 <literallayout class='monospaced'>
8618 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8619 </literallayout>
8620 </para>
8621
8622 <para>
8623 Aside from the <filename>*.sample</filename> configuration files,
8624 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008625 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008626 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008627 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008628 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8629 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008630 output.
8631 Customizing this <filename>conf-notes.txt</filename> file is a
8632 good way to make sure your list of custom targets appears
8633 as part of the script's output.
8634 </para>
8635
8636 <para>
8637 Here is the default list of targets displayed as a result of
8638 running either of the setup scripts:
8639 <literallayout class='monospaced'>
8640 You can now run 'bitbake &lt;target&gt;'
8641
8642 Common targets are:
8643 core-image-minimal
8644 core-image-sato
8645 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008646 meta-ide-support
8647 </literallayout>
8648 </para>
8649
8650 <para>
8651 Changing the listed common targets is as easy as editing your
8652 version of <filename>conf-notes.txt</filename> in your
8653 custom template configuration directory and making sure you
8654 have <filename>TEMPLATECONF</filename> set to your directory.
8655 </para>
8656 </section>
8657
Brad Bishop316dfdd2018-06-25 12:45:53 -04008658 <section id='dev-saving-memory-during-a-build'>
8659 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008660
8661 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008662 To help conserve disk space during builds, you can add the
8663 following statement to your project's
8664 <filename>local.conf</filename> configuration file found in the
8665 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8666 <literallayout class='monospaced'>
8667 INHERIT += "rm_work"
8668 </literallayout>
8669 Adding this statement deletes the work directory used for building
8670 a recipe once the recipe is built.
8671 For more information on "rm_work", see the
8672 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8673 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008674 </para>
8675 </section>
8676
8677 <section id='working-with-packages'>
8678 <title>Working with Packages</title>
8679
8680 <para>
8681 This section describes a few tasks that involve packages:
8682 <itemizedlist>
8683 <listitem><para>
8684 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8685 </para></listitem>
8686 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008687 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008688 </para></listitem>
8689 <listitem><para>
8690 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8691 </para></listitem>
8692 <listitem><para>
8693 <link linkend='using-runtime-package-management'>Using Runtime Package Management</link>
8694 </para></listitem>
8695 <listitem><para>
8696 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8697 </para></listitem>
8698 </itemizedlist>
8699 </para>
8700
8701 <section id='excluding-packages-from-an-image'>
8702 <title>Excluding Packages from an Image</title>
8703
8704 <para>
8705 You might find it necessary to prevent specific packages
8706 from being installed into an image.
8707 If so, you can use several variables to direct the build
8708 system to essentially ignore installing recommended packages
8709 or to not install a package at all.
8710 </para>
8711
8712 <para>
8713 The following list introduces variables you can use to
8714 prevent packages from being installed into your image.
8715 Each of these variables only works with IPK and RPM
8716 package types.
8717 Support for Debian packages does not exist.
8718 Also, you can use these variables from your
8719 <filename>local.conf</filename> file or attach them to a
8720 specific image recipe by using a recipe name override.
8721 For more detail on the variables, see the descriptions in the
8722 Yocto Project Reference Manual's glossary chapter.
8723 <itemizedlist>
8724 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
8725 Use this variable to specify "recommended-only"
8726 packages that you do not want installed.
8727 </para></listitem>
8728 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
8729 Use this variable to prevent all "recommended-only"
8730 packages from being installed.
8731 </para></listitem>
8732 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
8733 Use this variable to prevent specific packages from
8734 being installed regardless of whether they are
8735 "recommended-only" or not.
8736 You need to realize that the build process could
8737 fail with an error when you
8738 prevent the installation of a package whose presence
8739 is required by an installed package.
8740 </para></listitem>
8741 </itemizedlist>
8742 </para>
8743 </section>
8744
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008745 <section id='incrementing-a-binary-package-version'>
8746 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008747
8748 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008749 This section provides some background on how binary package
8750 versioning is accomplished and presents some of the services,
8751 variables, and terminology involved.
8752 </para>
8753
8754 <para>
8755 In order to understand binary package versioning, you need
8756 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008757 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008758 <listitem><para>
8759 Binary Package: The binary package that is eventually
8760 built and installed into an image.
8761 </para></listitem>
8762 <listitem><para>
8763 Binary Package Version: The binary package version
8764 is composed of two components - a version and a
8765 revision.
8766 <note>
8767 Technically, a third component, the "epoch" (i.e.
8768 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
8769 is involved but this discussion for the most part
8770 ignores <filename>PE</filename>.
8771 </note>
8772 The version and revision are taken from the
8773 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
8774 and
8775 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
8776 variables, respectively.
8777 </para></listitem>
8778 <listitem><para>
8779 <filename>PV</filename>: The recipe version.
8780 <filename>PV</filename> represents the version of the
8781 software being packaged.
8782 Do not confuse <filename>PV</filename> with the
8783 binary package version.
8784 </para></listitem>
8785 <listitem><para>
8786 <filename>PR</filename>: The recipe revision.
8787 </para></listitem>
8788 <listitem><para>
8789 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
8790 The OpenEmbedded build system uses this string
8791 to help define the value of <filename>PV</filename>
8792 when the source code revision needs to be included
8793 in it.
8794 </para></listitem>
8795 <listitem><para>
8796 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
8797 A network-based service that helps automate keeping
8798 package feeds compatible with existing package
8799 manager applications such as RPM, APT, and OPKG.
8800 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008801 </itemizedlist>
8802 </para>
8803
8804 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008805 Whenever the binary package content changes, the binary package
8806 version must change.
8807 Changing the binary package version is accomplished by changing
8808 or "bumping" the <filename>PR</filename> and/or
8809 <filename>PV</filename> values.
8810 Increasing these values occurs one of two ways:
8811 <itemizedlist>
8812 <listitem><para>Automatically using a Package Revision
8813 Service (PR Service).
8814 </para></listitem>
8815 <listitem><para>Manually incrementing the
8816 <filename>PR</filename> and/or
8817 <filename>PV</filename> variables.
8818 </para></listitem>
8819 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008820 </para>
8821
8822 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008823 Given a primary challenge of any build system and its users
8824 is how to maintain a package feed that is compatible with
8825 existing package manager applications such as RPM, APT, and
8826 OPKG, using an automated system is much preferred over a
8827 manual system.
8828 In either system, the main requirement is that binary package
8829 version numbering increases in a linear fashion and that a
8830 number of version components exist that support that linear
8831 progression.
8832 For information on how to ensure package revisioning remains
8833 linear, see the
8834 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
8835 section.
8836 </para>
8837
8838 <para>
8839 The following three sections provide related information on the
8840 PR Service, the manual method for "bumping"
8841 <filename>PR</filename> and/or <filename>PV</filename>, and
8842 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008843 </para>
8844
8845 <section id='working-with-a-pr-service'>
8846 <title>Working With a PR Service</title>
8847
8848 <para>
8849 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008850 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008851 is error prone, inaccurate, and causes problems for people
8852 submitting recipes.
8853 Conversely, the PR Service automatically generates
8854 increasing numbers, particularly the revision field,
8855 which removes the human element.
8856 <note>
8857 For additional information on using a PR Service, you
8858 can see the
8859 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
8860 wiki page.
8861 </note>
8862 </para>
8863
8864 <para>
8865 The Yocto Project uses variables in order of
8866 decreasing priority to facilitate revision numbering (i.e.
8867 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
8868 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
8869 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
8870 for epoch, version, and revision, respectively).
8871 The values are highly dependent on the policies and
8872 procedures of a given distribution and package feed.
8873 </para>
8874
8875 <para>
8876 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04008877 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008878 which are unique to a given build, the build system
8879 knows when to rebuild packages.
8880 All the inputs into a given task are represented by a
8881 signature, which can trigger a rebuild when different.
8882 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008883 <filename>PR</filename>, <filename>PV</filename>, and
8884 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008885 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008886 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008887 </para>
8888
8889 <para>
8890 The PR Service works with both
8891 <filename>OEBasic</filename> and
8892 <filename>OEBasicHash</filename> generators.
8893 The value of <filename>PR</filename> bumps when the
8894 checksum changes and the different generator mechanisms
8895 change signatures under different circumstances.
8896 </para>
8897
8898 <para>
8899 As implemented, the build system includes values from
8900 the PR Service into the <filename>PR</filename> field as
8901 an addition using the form "<filename>.x</filename>" so
8902 <filename>r0</filename> becomes <filename>r0.1</filename>,
8903 <filename>r0.2</filename> and so forth.
8904 This scheme allows existing <filename>PR</filename> values
8905 to be used for whatever reasons, which include manual
8906 <filename>PR</filename> bumps, should it be necessary.
8907 </para>
8908
8909 <para>
8910 By default, the PR Service is not enabled or running.
8911 Thus, the packages generated are just "self consistent".
8912 The build system adds and removes packages and
8913 there are no guarantees about upgrade paths but images
8914 will be consistent and correct with the latest changes.
8915 </para>
8916
8917 <para>
8918 The simplest form for a PR Service is for it to exist
8919 for a single host development system that builds the
8920 package feed (building system).
8921 For this scenario, you can enable a local PR Service by
8922 setting
8923 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
8924 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008925 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008926 <literallayout class='monospaced'>
8927 PRSERV_HOST = "localhost:0"
8928 </literallayout>
8929 Once the service is started, packages will automatically
8930 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008931 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008932 </para>
8933
8934 <para>
8935 If you have a more complex setup where multiple host
8936 development systems work against a common, shared package
8937 feed, you have a single PR Service running and it is
8938 connected to each building system.
8939 For this scenario, you need to start the PR Service using
8940 the <filename>bitbake-prserv</filename> command:
8941 <literallayout class='monospaced'>
8942 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
8943 </literallayout>
8944 In addition to hand-starting the service, you need to
8945 update the <filename>local.conf</filename> file of each
8946 building system as described earlier so each system
8947 points to the server and port.
8948 </para>
8949
8950 <para>
8951 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008952 some sanity checks to binary package versions, in
8953 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008954 To enable build history, add the following to each building
8955 system's <filename>local.conf</filename> file:
8956 <literallayout class='monospaced'>
8957 # It is recommended to activate "buildhistory" for testing the PR service
8958 INHERIT += "buildhistory"
8959 BUILDHISTORY_COMMIT = "1"
8960 </literallayout>
8961 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008962 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
8963 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008964 </para>
8965
8966 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008967 <para>
8968 The OpenEmbedded build system does not maintain
8969 <filename>PR</filename> information as part of the
8970 shared state (sstate) packages.
8971 If you maintain an sstate feed, its expected that either
8972 all your building systems that contribute to the sstate
8973 feed use a shared PR Service, or you do not run a PR
8974 Service on any of your building systems.
8975 Having some systems use a PR Service while others do
8976 not leads to obvious problems.
8977 </para>
8978
8979 <para>
8980 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008981 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
8982 section in the Yocto Project Overview and Concepts
8983 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008984 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008985 </note>
8986 </section>
8987
8988 <section id='manually-bumping-pr'>
8989 <title>Manually Bumping PR</title>
8990
8991 <para>
8992 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008993 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008994 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
8995 variable.
8996 </para>
8997
8998 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008999 If a committed change results in changing the package
9000 output, then the value of the PR variable needs to be
9001 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009002 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009003 variable and set its initial value equal to "r0", which is
9004 the default.
9005 Even though the default value is "r0", the practice of
9006 adding it to a new recipe makes it harder to forget to bump
9007 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009008 </para>
9009
9010 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009011 If you are sharing a common <filename>.inc</filename> file
9012 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009013 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009014 variable to ensure that the recipes sharing the
9015 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009016 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009017 The <filename>.inc</filename> file must set
9018 <filename>INC_PR</filename> (initially to "r0"), and all
9019 recipes referring to it should set <filename>PR</filename>
9020 to "${INC_PR}.0" initially, incrementing the last number
9021 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009022 If the <filename>.inc</filename> file is changed then its
9023 <filename>INC_PR</filename> should be incremented.
9024 </para>
9025
9026 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009027 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009028 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9029 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009030 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009031 <filename>INC_PR</filename>).
9032 </para>
9033
9034 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009035 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009036 However, if for some reason <filename>PV</filename> changes
9037 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009038 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9039 variable (Package Epoch).
9040 The <filename>PE</filename> variable defaults to "0".
9041 </para>
9042
9043 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009044 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009045 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9046 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009047 These guidelines define how versions are compared and what
9048 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009049 </para>
9050 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009051
9052 <section id='automatically-incrementing-a-binary-package-revision-number'>
9053 <title>Automatically Incrementing a Package Version Number</title>
9054
9055 <para>
9056 When fetching a repository, BitBake uses the
9057 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9058 variable to determine the specific source code revision
9059 from which to build.
9060 You set the <filename>SRCREV</filename> variable to
9061 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9062 to cause the OpenEmbedded build system to automatically use the
9063 latest revision of the software:
9064 <literallayout class='monospaced'>
9065 SRCREV = "${AUTOREV}"
9066 </literallayout>
9067 </para>
9068
9069 <para>
9070 Furthermore, you need to reference <filename>SRCPV</filename>
9071 in <filename>PV</filename> in order to automatically update
9072 the version whenever the revision of the source code
9073 changes.
9074 Here is an example:
9075 <literallayout class='monospaced'>
9076 PV = "1.0+git${SRCPV}"
9077 </literallayout>
9078 The OpenEmbedded build system substitutes
9079 <filename>SRCPV</filename> with the following:
9080 <literallayout class='monospaced'>
9081 AUTOINC+<replaceable>source_code_revision</replaceable>
9082 </literallayout>
9083 The build system replaces the <filename>AUTOINC</filename> with
9084 a number.
9085 The number used depends on the state of the PR Service:
9086 <itemizedlist>
9087 <listitem><para>
9088 If PR Service is enabled, the build system increments
9089 the number, which is similar to the behavior of
9090 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9091 This behavior results in linearly increasing package
9092 versions, which is desirable.
9093 Here is an example:
9094 <literallayout class='monospaced'>
9095 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9096 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9097 </literallayout>
9098 </para></listitem>
9099 <listitem><para>
9100 If PR Service is not enabled, the build system
9101 replaces the <filename>AUTOINC</filename>
9102 placeholder with zero (i.e. "0").
9103 This results in changing the package version since
9104 the source revision is included.
9105 However, package versions are not increased linearly.
9106 Here is an example:
9107 <literallayout class='monospaced'>
9108 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9109 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9110 </literallayout>
9111 </para></listitem>
9112 </itemizedlist>
9113 </para>
9114
9115 <para>
9116 In summary, the OpenEmbedded build system does not track the
9117 history of binary package versions for this purpose.
9118 <filename>AUTOINC</filename>, in this case, is comparable to
9119 <filename>PR</filename>.
9120 If PR server is not enabled, <filename>AUTOINC</filename>
9121 in the package version is simply replaced by "0".
9122 If PR server is enabled, the build system keeps track of the
9123 package versions and bumps the number when the package
9124 revision changes.
9125 </para>
9126 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009127 </section>
9128
9129 <section id='handling-optional-module-packaging'>
9130 <title>Handling Optional Module Packaging</title>
9131
9132 <para>
9133 Many pieces of software split functionality into optional
9134 modules (or plug-ins) and the plug-ins that are built
9135 might depend on configuration options.
9136 To avoid having to duplicate the logic that determines what
9137 modules are available in your recipe or to avoid having
9138 to package each module by hand, the OpenEmbedded build system
9139 provides functionality to handle module packaging dynamically.
9140 </para>
9141
9142 <para>
9143 To handle optional module packaging, you need to do two things:
9144 <itemizedlist>
9145 <listitem><para>Ensure the module packaging is actually
9146 done.</para></listitem>
9147 <listitem><para>Ensure that any dependencies on optional
9148 modules from other recipes are satisfied by your recipe.
9149 </para></listitem>
9150 </itemizedlist>
9151 </para>
9152
9153 <section id='making-sure-the-packaging-is-done'>
9154 <title>Making Sure the Packaging is Done</title>
9155
9156 <para>
9157 To ensure the module packaging actually gets done, you use
9158 the <filename>do_split_packages</filename> function within
9159 the <filename>populate_packages</filename> Python function
9160 in your recipe.
9161 The <filename>do_split_packages</filename> function
9162 searches for a pattern of files or directories under a
9163 specified path and creates a package for each one it finds
9164 by appending to the
9165 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9166 variable and setting the appropriate values for
9167 <filename>FILES_packagename</filename>,
9168 <filename>RDEPENDS_packagename</filename>,
9169 <filename>DESCRIPTION_packagename</filename>, and so forth.
9170 Here is an example from the <filename>lighttpd</filename>
9171 recipe:
9172 <literallayout class='monospaced'>
9173 python populate_packages_prepend () {
9174 lighttpd_libdir = d.expand('${libdir}')
9175 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9176 'lighttpd-module-%s', 'Lighttpd module for %s',
9177 extra_depends='')
9178 }
9179 </literallayout>
9180 The previous example specifies a number of things in the
9181 call to <filename>do_split_packages</filename>.
9182 <itemizedlist>
9183 <listitem><para>A directory within the files installed
9184 by your recipe through <filename>do_install</filename>
9185 in which to search.</para></listitem>
9186 <listitem><para>A regular expression used to match module
9187 files in that directory.
9188 In the example, note the parentheses () that mark
9189 the part of the expression from which the module
9190 name should be derived.</para></listitem>
9191 <listitem><para>A pattern to use for the package names.
9192 </para></listitem>
9193 <listitem><para>A description for each package.
9194 </para></listitem>
9195 <listitem><para>An empty string for
9196 <filename>extra_depends</filename>, which disables
9197 the default dependency on the main
9198 <filename>lighttpd</filename> package.
9199 Thus, if a file in <filename>${libdir}</filename>
9200 called <filename>mod_alias.so</filename> is found,
9201 a package called <filename>lighttpd-module-alias</filename>
9202 is created for it and the
9203 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9204 is set to "Lighttpd module for alias".</para></listitem>
9205 </itemizedlist>
9206 </para>
9207
9208 <para>
9209 Often, packaging modules is as simple as the previous
9210 example.
9211 However, more advanced options exist that you can use
9212 within <filename>do_split_packages</filename> to modify its
9213 behavior.
9214 And, if you need to, you can add more logic by specifying
9215 a hook function that is called for each package.
9216 It is also perfectly acceptable to call
9217 <filename>do_split_packages</filename> multiple times if
9218 you have more than one set of modules to package.
9219 </para>
9220
9221 <para>
9222 For more examples that show how to use
9223 <filename>do_split_packages</filename>, see the
9224 <filename>connman.inc</filename> file in the
9225 <filename>meta/recipes-connectivity/connman/</filename>
9226 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009227 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009228 You can also find examples in
9229 <filename>meta/classes/kernel.bbclass</filename>.
9230 </para>
9231
9232 <para>
9233 Following is a reference that shows
9234 <filename>do_split_packages</filename> mandatory and
9235 optional arguments:
9236 <literallayout class='monospaced'>
9237 Mandatory arguments
9238
9239 root
9240 The path in which to search
9241 file_regex
9242 Regular expression to match searched files.
9243 Use parentheses () to mark the part of this
9244 expression that should be used to derive the
9245 module name (to be substituted where %s is
9246 used in other function arguments as noted below)
9247 output_pattern
9248 Pattern to use for the package names. Must
9249 include %s.
9250 description
9251 Description to set for each package. Must
9252 include %s.
9253
9254 Optional arguments
9255
9256 postinst
9257 Postinstall script to use for all packages
9258 (as a string)
9259 recursive
9260 True to perform a recursive search - default
9261 False
9262 hook
9263 A hook function to be called for every match.
9264 The function will be called with the following
9265 arguments (in the order listed):
9266
9267 f
9268 Full path to the file/directory match
9269 pkg
9270 The package name
9271 file_regex
9272 As above
9273 output_pattern
9274 As above
9275 modulename
9276 The module name derived using file_regex
9277
9278 extra_depends
9279 Extra runtime dependencies (RDEPENDS) to be
9280 set for all packages. The default value of None
9281 causes a dependency on the main package
9282 (${PN}) - if you do not want this, pass empty
9283 string '' for this parameter.
9284 aux_files_pattern
9285 Extra item(s) to be added to FILES for each
9286 package. Can be a single string item or a list
9287 of strings for multiple items. Must include %s.
9288 postrm
9289 postrm script to use for all packages (as a
9290 string)
9291 allow_dirs
9292 True to allow directories to be matched -
9293 default False
9294 prepend
9295 If True, prepend created packages to PACKAGES
9296 instead of the default False which appends them
9297 match_path
9298 match file_regex on the whole relative path to
9299 the root rather than just the file name
9300 aux_files_pattern_verbatim
9301 Extra item(s) to be added to FILES for each
9302 package, using the actual derived module name
9303 rather than converting it to something legal
9304 for a package name. Can be a single string item
9305 or a list of strings for multiple items. Must
9306 include %s.
9307 allow_links
9308 True to allow symlinks to be matched - default
9309 False
9310 summary
9311 Summary to set for each package. Must include %s;
9312 defaults to description if not set.
9313 </literallayout>
9314 </para>
9315 </section>
9316
9317 <section id='satisfying-dependencies'>
9318 <title>Satisfying Dependencies</title>
9319
9320 <para>
9321 The second part for handling optional module packaging
9322 is to ensure that any dependencies on optional modules
9323 from other recipes are satisfied by your recipe.
9324 You can be sure these dependencies are satisfied by
9325 using the
9326 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9327 Here is an example that continues with the
9328 <filename>lighttpd</filename> recipe shown earlier:
9329 <literallayout class='monospaced'>
9330 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9331 </literallayout>
9332 The name specified in the regular expression can of
9333 course be anything.
9334 In this example, it is <filename>lighttpd-module-</filename>
9335 and is specified as the prefix to ensure that any
9336 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9337 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9338 on a package name starting with the prefix are satisfied
9339 during build time.
9340 If you are using <filename>do_split_packages</filename>
9341 as described in the previous section, the value you put in
9342 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9343 the name pattern specified in the call to
9344 <filename>do_split_packages</filename>.
9345 </para>
9346 </section>
9347 </section>
9348
9349 <section id='using-runtime-package-management'>
9350 <title>Using Runtime Package Management</title>
9351
9352 <para>
9353 During a build, BitBake always transforms a recipe into one or
9354 more packages.
9355 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009356 and produces a number of packages (e.g.
9357 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9358 <filename>bash-completion</filename>,
9359 <filename>bash-completion-dbg</filename>,
9360 <filename>bash-completion-dev</filename>,
9361 <filename>bash-completion-extra</filename>,
9362 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009363 Not all generated packages are included in an image.
9364 </para>
9365
9366 <para>
9367 In several situations, you might need to update, add, remove,
9368 or query the packages on a target device at runtime
9369 (i.e. without having to generate a new image).
9370 Examples of such situations include:
9371 <itemizedlist>
9372 <listitem><para>
9373 You want to provide in-the-field updates to deployed
9374 devices (e.g. security updates).
9375 </para></listitem>
9376 <listitem><para>
9377 You want to have a fast turn-around development cycle
9378 for one or more applications that run on your device.
9379 </para></listitem>
9380 <listitem><para>
9381 You want to temporarily install the "debug" packages
9382 of various applications on your device so that
9383 debugging can be greatly improved by allowing
9384 access to symbols and source debugging.
9385 </para></listitem>
9386 <listitem><para>
9387 You want to deploy a more minimal package selection of
9388 your device but allow in-the-field updates to add a
9389 larger selection for customization.
9390 </para></listitem>
9391 </itemizedlist>
9392 </para>
9393
9394 <para>
9395 In all these situations, you have something similar to a more
9396 traditional Linux distribution in that in-field devices
9397 are able to receive pre-compiled packages from a server for
9398 installation or update.
9399 Being able to install these packages on a running,
9400 in-field device is what is termed "runtime package
9401 management".
9402 </para>
9403
9404 <para>
9405 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009406 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009407 packages plus the required metadata.
9408 You also need package manipulation tools on the target.
9409 The build machine is a likely candidate to act as the server.
9410 However, that machine does not necessarily have to be the
9411 package server.
9412 The build machine could push its artifacts to another machine
9413 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009414 In fact, doing so is advantageous for a production
9415 environment as getting the packages away from the
9416 development system's build directory prevents accidental
9417 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009418 </para>
9419
9420 <para>
9421 A simple build that targets just one device produces
9422 more than one package database.
9423 In other words, the packages produced by a build are separated
9424 out into a couple of different package groupings based on
9425 criteria such as the target's CPU architecture, the target
9426 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009427 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009428 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009429 <filename>noarch</filename>, <filename>i586</filename>, and
9430 <filename>qemux86</filename>.
9431 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009432 aware of all the packages that were available to it,
9433 you would need to point it to each of these databases
9434 individually.
9435 In a similar way, a traditional Linux distribution usually is
9436 configured to be aware of a number of software repositories
9437 from which it retrieves packages.
9438 </para>
9439
9440 <para>
9441 Using runtime package management is completely optional and
9442 not required for a successful build or deployment in any
9443 way.
9444 But if you want to make use of runtime package management,
9445 you need to do a couple things above and beyond the basics.
9446 The remainder of this section describes what you need to do.
9447 </para>
9448
9449 <section id='runtime-package-management-build'>
9450 <title>Build Considerations</title>
9451
9452 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009453 This section describes build considerations of which you
9454 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009455 package management.
9456 </para>
9457
9458 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009459 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009460 what format or formats to use.
9461 In your configuration, you use the
9462 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009463 variable to specify the format:
9464 <orderedlist>
9465 <listitem><para>
9466 Open the <filename>local.conf</filename> file
9467 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009468 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009469 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9470 </para></listitem>
9471 <listitem><para>
9472 Select the desired package format as follows:
9473 <literallayout class='monospaced'>
9474 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9475 </literallayout>
9476 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009477 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009478 supported package formats.
9479 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009480 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009481 different package formats, you can set the
9482 variable with more than one argument.
9483 However, the OpenEmbedded build system only
9484 uses the first argument when creating an image
9485 or Software Development Kit (SDK).
9486 </note>
9487 </para></listitem>
9488 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009489 </para>
9490
9491 <para>
9492 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009493 package database containing the packages in your current
9494 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009495 target for runtime package management, you can include
9496 "package-management" in the
9497 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9498 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009499 Including "package-management" in this configuration
9500 variable ensures that when the image is assembled for your
9501 target, the image includes the currently-known package
9502 databases as well as the target-specific tools required
9503 for runtime package management to be performed on the
9504 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009505 However, this is not strictly necessary.
9506 You could start your image off without any databases
9507 but only include the required on-target package
9508 tool(s).
9509 As an example, you could include "opkg" in your
9510 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9511 variable if you are using the IPK package format.
9512 You can then initialize your target's package database(s)
9513 later once your image is up and running.
9514 </para>
9515
9516 <para>
9517 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009518 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009519 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009520 package index after the build by using the following
9521 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009522 <literallayout class='monospaced'>
9523 $ bitbake package-index
9524 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009525 It might be tempting to build the package and the
9526 package index at the same time with a command such as
9527 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009528 <literallayout class='monospaced'>
9529 $ bitbake <replaceable>some-package</replaceable> package-index
9530 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009531 Do not do this as BitBake does not schedule the package
9532 index for after the completion of the package you are
9533 building.
9534 Consequently, you cannot be sure of the package index
9535 including information for the package you just built.
9536 Thus, be sure to run the package update step separately
9537 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009538 </para>
9539
9540 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009541 You can use the
9542 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9543 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9544 and
9545 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9546 variables to pre-configure target images to use a package
9547 feed.
9548 If you do not define these variables, then manual steps
9549 as described in the subsequent sections are necessary to
9550 configure the target.
9551 You should set these variables before building the image
9552 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009553 </para>
9554
9555 <para>
9556 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009557 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009558 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009559 For example, if
9560 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009561 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009562 is RPM, then your RPM packages are available in
9563 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009564 </para>
9565 </section>
9566
9567 <section id='runtime-package-management-server'>
9568 <title>Host or Server Machine Setup</title>
9569
9570 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009571 Although other protocols are possible, a server using HTTP
9572 typically serves packages.
9573 If you want to use HTTP, then set up and configure a
9574 web server such as Apache 2, lighttpd, or
9575 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009576 </para>
9577
9578 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009579 To keep things simple, this section describes how to set
9580 up a SimpleHTTPServer web server to share package feeds
9581 from the developer's machine.
9582 Although this server might not be the best for a production
9583 environment, the setup is simple and straight forward.
9584 Should you want to use a different server more suited for
9585 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9586 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009587 </para>
9588
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009589 <para>
9590 From within the build directory where you have built an
9591 image based on your packaging choice (i.e. the
9592 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9593 setting), simply start the server.
9594 The following example assumes a build directory of
9595 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9596 <filename>PACKAGE_CLASSES</filename> setting of
9597 "package_rpm":
9598 <literallayout class='monospaced'>
9599 $ cd ~/poky/build/tmp/deploy/rpm
9600 $ python -m SimpleHTTPServer
9601 </literallayout>
9602 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009603 </section>
9604
9605 <section id='runtime-package-management-target'>
9606 <title>Target Setup</title>
9607
9608 <para>
9609 Setting up the target differs depending on the
9610 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009611 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009612 </para>
9613
9614 <section id='runtime-package-management-target-rpm'>
9615 <title>Using RPM</title>
9616
9617 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009618 The
9619 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9620 (DNF) performs runtime package management of RPM
9621 packages.
9622 In order to use DNF for runtime package management,
9623 you must perform an initial setup on the target
9624 machine for cases where the
9625 <filename>PACKAGE_FEED_*</filename> variables were not
9626 set as part of the image that is running on the
9627 target.
9628 This means if you built your image and did not not use
9629 these variables as part of the build and your image is
9630 now running on the target, you need to perform the
9631 steps in this section if you want to use runtime
9632 package management.
9633 <note>
9634 For information on the
9635 <filename>PACKAGE_FEED_*</filename> variables, see
9636 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9637 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9638 and
9639 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9640 in the Yocto Project Reference Manual variables
9641 glossary.
9642 </note>
9643 </para>
9644
9645 <para>
9646 On the target, you must inform DNF that package
9647 databases are available.
9648 You do this by creating a file named
9649 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9650 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009651 </para>
9652
9653 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009654 As an example, assume the target is able to use the
9655 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009656 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009657 and <filename>qemux86</filename> from a server named
9658 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009659 The specifics for setting up the web server are up to
9660 you.
9661 The critical requirement is that the URIs in the
9662 target repository configuration point to the
9663 correct remote location for the feeds.
9664 <note><title>Tip</title>
9665 For development purposes, you can point the web
9666 server to the build system's
9667 <filename>deploy</filename> directory.
9668 However, for production use, it is better to copy
9669 the package directories to a location outside of
9670 the build area and use that location.
9671 Doing so avoids situations where the build system
9672 overwrites or changes the
9673 <filename>deploy</filename> directory.
9674 </note>
9675 </para>
9676
9677 <para>
9678 When telling DNF where to look for the package
9679 databases, you must declare individual locations
9680 per architecture or a single location used for all
9681 architectures.
9682 You cannot do both:
9683 <itemizedlist>
9684 <listitem><para>
9685 <emphasis>Create an Explicit List of Architectures:</emphasis>
9686 Define individual base URLs to identify where
9687 each package database is located:
9688 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009689 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009690 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009691 </literallayout>
9692 This example informs DNF about individual
9693 package databases for all three architectures.
9694 </para></listitem>
9695 <listitem><para>
9696 <emphasis>Create a Single (Full) Package Index:</emphasis>
9697 Define a single base URL that identifies where
9698 a full package database is located:
9699 <literallayout class='monospaced'>
9700 [oe-packages]
9701 baseurl=http://my.server/rpm
9702 </literallayout>
9703 This example informs DNF about a single package
9704 database that contains all the package index
9705 information for all supported architectures.
9706 </para></listitem>
9707 </itemizedlist>
9708 </para>
9709
9710 <para>
9711 Once you have informed DNF where to find the package
9712 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009713 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009714 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009715 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009716 DNF is now able to find, install, and upgrade packages
9717 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009718 <note>
9719 See the
9720 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
9721 for additional information.
9722 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009723 </para>
9724 </section>
9725
9726 <section id='runtime-package-management-target-ipk'>
9727 <title>Using IPK</title>
9728
9729 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009730 The <filename>opkg</filename> application performs
9731 runtime package management of IPK packages.
9732 You must perform an initial setup for
9733 <filename>opkg</filename> on the target machine
9734 if the
9735 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9736 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
9737 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9738 variables have not been set or the target image was
9739 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009740 </para>
9741
9742 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009743 The <filename>opkg</filename> application uses
9744 configuration files to find available package
9745 databases.
9746 Thus, you need to create a configuration file inside
9747 the <filename>/etc/opkg/</filename> direction, which
9748 informs <filename>opkg</filename> of any repository
9749 you want to use.
9750 </para>
9751
9752 <para>
9753 As an example, suppose you are serving packages from a
9754 <filename>ipk/</filename> directory containing the
9755 <filename>i586</filename>,
9756 <filename>all</filename>, and
9757 <filename>qemux86</filename> databases through an
9758 HTTP server named <filename>my.server</filename>.
9759 On the target, create a configuration file
9760 (e.g. <filename>my_repo.conf</filename>) inside the
9761 <filename>/etc/opkg/</filename> directory containing
9762 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009763 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009764 src/gz all http://my.server/ipk/all
9765 src/gz i586 http://my.server/ipk/i586
9766 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009767 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009768 Next, instruct <filename>opkg</filename> to fetch
9769 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009770 <literallayout class='monospaced'>
9771 # opkg update
9772 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009773 The <filename>opkg</filename> application is now able
9774 to find, install, and upgrade packages from the
9775 specified repository.
9776 </para>
9777 </section>
9778
9779 <section id='runtime-package-management-target-deb'>
9780 <title>Using DEB</title>
9781
9782 <para>
9783 The <filename>apt</filename> application performs
9784 runtime package management of DEB packages.
9785 This application uses a source list file to find
9786 available package databases.
9787 You must perform an initial setup for
9788 <filename>apt</filename> on the target machine
9789 if the
9790 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9791 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
9792 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9793 variables have not been set or the target image was
9794 built before the variables were set.
9795 </para>
9796
9797 <para>
9798 To inform <filename>apt</filename> of the repository
9799 you want to use, you might create a list file (e.g.
9800 <filename>my_repo.list</filename>) inside the
9801 <filename>/etc/apt/sources.list.d/</filename>
9802 directory.
9803 As an example, suppose you are serving packages from a
9804 <filename>deb/</filename> directory containing the
9805 <filename>i586</filename>,
9806 <filename>all</filename>, and
9807 <filename>qemux86</filename> databases through an
9808 HTTP server named <filename>my.server</filename>.
9809 The list file should contain:
9810 <literallayout class='monospaced'>
9811 deb http://my.server/deb/all ./
9812 deb http://my.server/deb/i586 ./
9813 deb http://my.server/deb/qemux86 ./
9814 </literallayout>
9815 Next, instruct the <filename>apt</filename>
9816 application to fetch the repository information:
9817 <literallayout class='monospaced'>
9818 # apt-get update
9819 </literallayout>
9820 After this step, <filename>apt</filename> is able
9821 to find, install, and upgrade packages from the
9822 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009823 </para>
9824 </section>
9825 </section>
9826 </section>
9827
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009828 <section id='generating-and-using-signed-packages'>
9829 <title>Generating and Using Signed Packages</title>
9830 <para>
9831 In order to add security to RPM packages used during a build,
9832 you can take steps to securely sign them.
9833 Once a signature is verified, the OpenEmbedded build system
9834 can use the package in the build.
9835 If security fails for a signed package, the build system
9836 aborts the build.
9837 </para>
9838
9839 <para>
9840 This section describes how to sign RPM packages during a build
9841 and how to use signed package feeds (repositories) when
9842 doing a build.
9843 </para>
9844
9845 <section id='signing-rpm-packages'>
9846 <title>Signing RPM Packages</title>
9847
9848 <para>
9849 To enable signing RPM packages, you must set up the
9850 following configurations in either your
9851 <filename>local.config</filename> or
9852 <filename>distro.config</filename> file:
9853 <literallayout class='monospaced'>
9854 # Inherit sign_rpm.bbclass to enable signing functionality
9855 INHERIT += " sign_rpm"
9856 # Define the GPG key that will be used for signing.
9857 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
9858 # Provide passphrase for the key
9859 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
9860 </literallayout>
9861 <note>
9862 Be sure to supply appropriate values for both
9863 <replaceable>key_name</replaceable> and
9864 <replaceable>passphrase</replaceable>
9865 </note>
9866 Aside from the
9867 <filename>RPM_GPG_NAME</filename> and
9868 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
9869 previous example, two optional variables related to signing
9870 exist:
9871 <itemizedlist>
9872 <listitem><para>
9873 <emphasis><filename>GPG_BIN</filename>:</emphasis>
9874 Specifies a <filename>gpg</filename> binary/wrapper
9875 that is executed when the package is signed.
9876 </para></listitem>
9877 <listitem><para>
9878 <emphasis><filename>GPG_PATH</filename>:</emphasis>
9879 Specifies the <filename>gpg</filename> home
9880 directory used when the package is signed.
9881 </para></listitem>
9882 </itemizedlist>
9883 </para>
9884 </section>
9885
9886 <section id='processing-package-feeds'>
9887 <title>Processing Package Feeds</title>
9888
9889 <para>
9890 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009891 also enable signed package feeds for IPK and RPM packages.
9892 </para>
9893
9894 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009895 The steps you need to take to enable signed package feed
9896 use are similar to the steps used to sign RPM packages.
9897 You must define the following in your
9898 <filename>local.config</filename> or
9899 <filename>distro.config</filename> file:
9900 <literallayout class='monospaced'>
9901 INHERIT += "sign_package_feed"
9902 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
9903 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
9904 </literallayout>
9905 For signed package feeds, the passphrase must exist in a
9906 separate file, which is pointed to by the
9907 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
9908 variable.
9909 Regarding security, keeping a plain text passphrase out of
9910 the configuration is more secure.
9911 </para>
9912
9913 <para>
9914 Aside from the
9915 <filename>PACKAGE_FEED_GPG_NAME</filename> and
9916 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
9917 variables, three optional variables related to signed
9918 package feeds exist:
9919 <itemizedlist>
9920 <listitem><para>
9921 <emphasis><filename>GPG_BIN</filename>:</emphasis>
9922 Specifies a <filename>gpg</filename> binary/wrapper
9923 that is executed when the package is signed.
9924 </para></listitem>
9925 <listitem><para>
9926 <emphasis><filename>GPG_PATH</filename>:</emphasis>
9927 Specifies the <filename>gpg</filename> home
9928 directory used when the package is signed.
9929 </para></listitem>
9930 <listitem><para>
9931 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
9932 Specifies the type of <filename>gpg</filename>
9933 signature.
9934 This variable applies only to RPM and IPK package
9935 feeds.
9936 Allowable values for the
9937 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
9938 are "ASC", which is the default and specifies ascii
9939 armored, and "BIN", which specifies binary.
9940 </para></listitem>
9941 </itemizedlist>
9942 </para>
9943 </section>
9944 </section>
9945
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009946 <section id='testing-packages-with-ptest'>
9947 <title>Testing Packages With ptest</title>
9948
9949 <para>
9950 A Package Test (ptest) runs tests against packages built
9951 by the OpenEmbedded build system on the target machine.
9952 A ptest contains at least two items: the actual test, and
9953 a shell script (<filename>run-ptest</filename>) that starts
9954 the test.
9955 The shell script that starts the test must not contain
9956 the actual test - the script only starts the test.
9957 On the other hand, the test can be anything from a simple
9958 shell script that runs a binary and checks the output to
9959 an elaborate system of test binaries and data files.
9960 </para>
9961
9962 <para>
9963 The test generates output in the format used by
9964 Automake:
9965 <literallayout class='monospaced'>
9966 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
9967 </literallayout>
9968 where the result can be <filename>PASS</filename>,
9969 <filename>FAIL</filename>, or <filename>SKIP</filename>,
9970 and the testname can be any identifying string.
9971 </para>
9972
9973 <para>
9974 For a list of Yocto Project recipes that are already
9975 enabled with ptest, see the
9976 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
9977 wiki page.
9978 <note>
9979 A recipe is "ptest-enabled" if it inherits the
9980 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
9981 class.
9982 </note>
9983 </para>
9984
9985 <section id='adding-ptest-to-your-build'>
9986 <title>Adding ptest to Your Build</title>
9987
9988 <para>
9989 To add package testing to your build, add the
9990 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
9991 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
9992 variables to your <filename>local.conf</filename> file,
9993 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009994 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009995 <literallayout class='monospaced'>
9996 DISTRO_FEATURES_append = " ptest"
9997 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
9998 </literallayout>
9999 Once your build is complete, the ptest files are installed
10000 into the
10001 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10002 directory within the image, where
10003 <filename><replaceable>package</replaceable></filename>
10004 is the name of the package.
10005 </para>
10006 </section>
10007
10008 <section id='running-ptest'>
10009 <title>Running ptest</title>
10010
10011 <para>
10012 The <filename>ptest-runner</filename> package installs a
10013 shell script that loops through all installed ptest test
10014 suites and runs them in sequence.
10015 Consequently, you might want to add this package to
10016 your image.
10017 </para>
10018 </section>
10019
10020 <section id='getting-your-package-ready'>
10021 <title>Getting Your Package Ready</title>
10022
10023 <para>
10024 In order to enable a recipe to run installed ptests
10025 on target hardware,
10026 you need to prepare the recipes that build the packages
10027 you want to test.
10028 Here is what you have to do for each recipe:
10029 <itemizedlist>
10030 <listitem><para><emphasis>Be sure the recipe
10031 inherits the
10032 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10033 class:</emphasis>
10034 Include the following line in each recipe:
10035 <literallayout class='monospaced'>
10036 inherit ptest
10037 </literallayout>
10038 </para></listitem>
10039 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10040 This script starts your test.
10041 Locate the script where you will refer to it
10042 using
10043 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10044 Here is an example that starts a test for
10045 <filename>dbus</filename>:
10046 <literallayout class='monospaced'>
10047 #!/bin/sh
10048 cd test
10049 make -k runtest-TESTS
10050 </literallayout>
10051 </para></listitem>
10052 <listitem><para><emphasis>Ensure dependencies are
10053 met:</emphasis>
10054 If the test adds build or runtime dependencies
10055 that normally do not exist for the package
10056 (such as requiring "make" to run the test suite),
10057 use the
10058 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10059 and
10060 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10061 variables in your recipe in order for the package
10062 to meet the dependencies.
10063 Here is an example where the package has a runtime
10064 dependency on "make":
10065 <literallayout class='monospaced'>
10066 RDEPENDS_${PN}-ptest += "make"
10067 </literallayout>
10068 </para></listitem>
10069 <listitem><para><emphasis>Add a function to build the
10070 test suite:</emphasis>
10071 Not many packages support cross-compilation of
10072 their test suites.
10073 Consequently, you usually need to add a
10074 cross-compilation function to the package.
10075 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010076
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010077 <para>Many packages based on Automake compile and
10078 run the test suite by using a single command
10079 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010080 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010081 builds and runs on the same computer, while
10082 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010083 on the host but executed for the target
10084 architecture (though often, as in the case for
10085 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010086 The built version of Automake that ships with the
10087 Yocto Project includes a patch that separates
10088 building and execution.
10089 Consequently, packages that use the unaltered,
10090 patched version of <filename>make check</filename>
10091 automatically cross-compiles.</para>
10092 <para>Regardless, you still must add a
10093 <filename>do_compile_ptest</filename> function to
10094 build the test suite.
10095 Add a function similar to the following to your
10096 recipe:
10097 <literallayout class='monospaced'>
10098 do_compile_ptest() {
10099 oe_runmake buildtest-TESTS
10100 }
10101 </literallayout>
10102 </para></listitem>
10103 <listitem><para><emphasis>Ensure special configurations
10104 are set:</emphasis>
10105 If the package requires special configurations
10106 prior to compiling the test code, you must
10107 insert a <filename>do_configure_ptest</filename>
10108 function into the recipe.
10109 </para></listitem>
10110 <listitem><para><emphasis>Install the test
10111 suite:</emphasis>
10112 The <filename>ptest</filename> class
10113 automatically copies the file
10114 <filename>run-ptest</filename> to the target and
10115 then runs make <filename>install-ptest</filename>
10116 to run the tests.
10117 If this is not enough, you need to create a
10118 <filename>do_install_ptest</filename> function and
10119 make sure it gets called after the
10120 "make install-ptest" completes.
10121 </para></listitem>
10122 </itemizedlist>
10123 </para>
10124 </section>
10125 </section>
10126 </section>
10127
Brad Bishop316dfdd2018-06-25 12:45:53 -040010128 <section id='efficiently-fetching-source-files-during-a-build'>
10129 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010130
10131 <para>
10132 The OpenEmbedded build system works with source files located
10133 through the
10134 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10135 variable.
10136 When you build something using BitBake, a big part of the operation
10137 is locating and downloading all the source tarballs.
10138 For images, downloading all the source for various packages can
10139 take a significant amount of time.
10140 </para>
10141
10142 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010143 This section shows you how you can use mirrors to speed up
10144 fetching source files and how you can pre-fetch files all of which
10145 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010146 </para>
10147
10148 <section id='setting-up-effective-mirrors'>
10149 <title>Setting up Effective Mirrors</title>
10150
10151 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010152 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010153 build is simply downloading all of the source tarballs.
10154 Maybe you have been working with another build system
10155 (OpenEmbedded or Angstrom) for which you have built up a
10156 sizable directory of source tarballs.
10157 Or, perhaps someone else has such a directory for which you
10158 have read access.
10159 If so, you can save time by adding statements to your
10160 configuration file so that the build process checks local
10161 directories first for existing tarballs before checking the
10162 Internet.
10163 </para>
10164
10165 <para>
10166 Here is an efficient way to set it up in your
10167 <filename>local.conf</filename> file:
10168 <literallayout class='monospaced'>
10169 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10170 INHERIT += "own-mirrors"
10171 BB_GENERATE_MIRROR_TARBALLS = "1"
10172 # BB_NO_NETWORK = "1"
10173 </literallayout>
10174 </para>
10175
10176 <para>
10177 In the previous example, the
10178 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10179 variable causes the OpenEmbedded build system to generate
10180 tarballs of the Git repositories and store them in the
10181 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10182 directory.
10183 Due to performance reasons, generating and storing these
10184 tarballs is not the build system's default behavior.
10185 </para>
10186
10187 <para>
10188 You can also use the
10189 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10190 variable.
10191 For an example, see the variable's glossary entry in the
10192 Yocto Project Reference Manual.
10193 </para>
10194 </section>
10195
10196 <section id='getting-source-files-and-suppressing-the-build'>
10197 <title>Getting Source Files and Suppressing the Build</title>
10198
10199 <para>
10200 Another technique you can use to ready yourself for a
10201 successive string of build operations, is to pre-fetch
10202 all the source files without actually starting a build.
10203 This technique lets you work through any download issues
10204 and ultimately gathers all the source files into your
10205 download directory
10206 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10207 which is located with
10208 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10209 </para>
10210
10211 <para>
10212 Use the following BitBake command form to fetch all the
10213 necessary sources without starting the build:
10214 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010215 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010216 </literallayout>
10217 This variation of the BitBake command guarantees that you
10218 have all the sources for that BitBake target should you
10219 disconnect from the Internet and want to do the build
10220 later offline.
10221 </para>
10222 </section>
10223 </section>
10224
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010225 <section id="selecting-an-initialization-manager">
10226 <title>Selecting an Initialization Manager</title>
10227
10228 <para>
10229 By default, the Yocto Project uses SysVinit as the initialization
10230 manager.
10231 However, support also exists for systemd,
10232 which is a full replacement for init with
10233 parallel starting of services, reduced shell overhead and other
10234 features that are used by many distributions.
10235 </para>
10236
10237 <para>
10238 If you want to use SysVinit, you do
10239 not have to do anything.
10240 But, if you want to use systemd, you must
10241 take some steps as described in the following sections.
10242 </para>
10243
10244 <section id='using-systemd-exclusively'>
10245 <title>Using systemd Exclusively</title>
10246
10247 <para>
10248 Set the these variables in your distribution configuration
10249 file as follows:
10250 <literallayout class='monospaced'>
10251 DISTRO_FEATURES_append = " systemd"
10252 VIRTUAL-RUNTIME_init_manager = "systemd"
10253 </literallayout>
10254 You can also prevent the SysVinit
10255 distribution feature from
10256 being automatically enabled as follows:
10257 <literallayout class='monospaced'>
10258 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10259 </literallayout>
10260 Doing so removes any redundant SysVinit scripts.
10261 </para>
10262
10263 <para>
10264 To remove initscripts from your image altogether,
10265 set this variable also:
10266 <literallayout class='monospaced'>
10267 VIRTUAL-RUNTIME_initscripts = ""
10268 </literallayout>
10269 </para>
10270
10271 <para>
10272 For information on the backfill variable, see
10273 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10274 </para>
10275 </section>
10276
10277 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10278 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10279
10280 <para>
10281 Set these variables in your distribution configuration
10282 file as follows:
10283 <literallayout class='monospaced'>
10284 DISTRO_FEATURES_append = " systemd"
10285 VIRTUAL-RUNTIME_init_manager = "systemd"
10286 </literallayout>
10287 Doing so causes your main image to use the
10288 <filename>packagegroup-core-boot.bb</filename> recipe and
10289 systemd.
10290 The rescue/minimal image cannot use this package group.
10291 However, it can install SysVinit
10292 and the appropriate packages will have support for both
10293 systemd and SysVinit.
10294 </para>
10295 </section>
10296 </section>
10297
10298 <section id="selecting-dev-manager">
10299 <title>Selecting a Device Manager</title>
10300
10301 <para>
10302 The Yocto Project provides multiple ways to manage the device
10303 manager (<filename>/dev</filename>):
10304 <itemizedlist>
10305 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10306 For this case, the <filename>/dev</filename> directory
10307 is persistent and the required device nodes are created
10308 during the build.
10309 </para></listitem>
10310 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10311 For this case, the <filename>/dev</filename> directory
10312 is provided by the kernel as an in-memory file system and
10313 is automatically populated by the kernel at runtime.
10314 Additional configuration of device nodes is done in user
10315 space by a device manager like
10316 <filename>udev</filename> or
10317 <filename>busybox-mdev</filename>.
10318 </para></listitem>
10319 </itemizedlist>
10320 </para>
10321
10322 <section id="static-dev-management">
10323 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10324
10325 <para>
10326 To use the static method for device population, you need to
10327 set the
10328 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10329 variable to "0" as follows:
10330 <literallayout class='monospaced'>
10331 USE_DEVFS = "0"
10332 </literallayout>
10333 </para>
10334
10335 <para>
10336 The content of the resulting <filename>/dev</filename>
10337 directory is defined in a Device Table file.
10338 The
10339 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10340 variable defines the Device Table to use and should be set
10341 in the machine or distro configuration file.
10342 Alternatively, you can set this variable in your
10343 <filename>local.conf</filename> configuration file.
10344 </para>
10345
10346 <para>
10347 If you do not define the
10348 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10349 <filename>device_table-minimal.txt</filename> is used:
10350 <literallayout class='monospaced'>
10351 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10352 </literallayout>
10353 </para>
10354
10355 <para>
10356 The population is handled by the <filename>makedevs</filename>
10357 utility during image creation:
10358 </para>
10359 </section>
10360
10361 <section id="devtmpfs-dev-management">
10362 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10363
10364 <para>
10365 To use the dynamic method for device population, you need to
10366 use (or be sure to set) the
10367 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10368 variable to "1", which is the default:
10369 <literallayout class='monospaced'>
10370 USE_DEVFS = "1"
10371 </literallayout>
10372 With this setting, the resulting <filename>/dev</filename>
10373 directory is populated by the kernel using
10374 <filename>devtmpfs</filename>.
10375 Make sure the corresponding kernel configuration variable
10376 <filename>CONFIG_DEVTMPFS</filename> is set when building
10377 you build a Linux kernel.
10378 </para>
10379
10380 <para>
10381 All devices created by <filename>devtmpfs</filename> will be
10382 owned by <filename>root</filename> and have permissions
10383 <filename>0600</filename>.
10384 </para>
10385
10386 <para>
10387 To have more control over the device nodes, you can use a
10388 device manager like <filename>udev</filename> or
10389 <filename>busybox-mdev</filename>.
10390 You choose the device manager by defining the
10391 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10392 in your machine or distro configuration file.
10393 Alternatively, you can set this variable in your
10394 <filename>local.conf</filename> configuration file:
10395 <literallayout class='monospaced'>
10396 VIRTUAL-RUNTIME_dev_manager = "udev"
10397
10398 # Some alternative values
10399 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10400 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10401 </literallayout>
10402 </para>
10403 </section>
10404 </section>
10405
10406 <section id="platdev-appdev-srcrev">
10407 <title>Using an External SCM</title>
10408
10409 <para>
10410 If you're working on a recipe that pulls from an external Source
10411 Code Manager (SCM), it is possible to have the OpenEmbedded build
10412 system notice new recipe changes added to the SCM and then build
10413 the resulting packages that depend on the new recipes by using
10414 the latest versions.
10415 This only works for SCMs from which it is possible to get a
10416 sensible revision number for changes.
10417 Currently, you can do this with Apache Subversion (SVN), Git, and
10418 Bazaar (BZR) repositories.
10419 </para>
10420
10421 <para>
10422 To enable this behavior, the
10423 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
10424 of the recipe needs to reference
10425 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
10426 Here is an example:
10427 <literallayout class='monospaced'>
10428 PV = "1.2.3+git${SRCPV}"
10429 </literallayout>
10430 Then, you can add the following to your
10431 <filename>local.conf</filename>:
10432 <literallayout class='monospaced'>
10433 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
10434 </literallayout>
10435 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
10436 is the name of the recipe for which you want to enable automatic source
10437 revision updating.
10438 </para>
10439
10440 <para>
10441 If you do not want to update your local configuration file, you can
10442 add the following directly to the recipe to finish enabling
10443 the feature:
10444 <literallayout class='monospaced'>
10445 SRCREV = "${AUTOREV}"
10446 </literallayout>
10447 </para>
10448
10449 <para>
10450 The Yocto Project provides a distribution named
10451 <filename>poky-bleeding</filename>, whose configuration
10452 file contains the line:
10453 <literallayout class='monospaced'>
10454 require conf/distro/include/poky-floating-revisions.inc
10455 </literallayout>
10456 This line pulls in the listed include file that contains
10457 numerous lines of exactly that form:
10458 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010459 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
10460 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
10461 #SRCREV_pn-opkg ?= "${AUTOREV}"
10462 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
10463 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010464 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
10465 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
10466 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
10467 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
10468 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010469 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
10470 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
10471 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
10472 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010473 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
10474 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010475 .
10476 .
10477 .
10478 </literallayout>
10479 These lines allow you to experiment with building a
10480 distribution that tracks the latest development source
10481 for numerous packages.
10482 <note><title>Caution</title>
10483 The <filename>poky-bleeding</filename> distribution
10484 is not tested on a regular basis.
10485 Keep this in mind if you use it.
10486 </note>
10487 </para>
10488 </section>
10489
10490 <section id='creating-a-read-only-root-filesystem'>
10491 <title>Creating a Read-Only Root Filesystem</title>
10492
10493 <para>
10494 Suppose, for security reasons, you need to disable
10495 your target device's root filesystem's write permissions
10496 (i.e. you need a read-only root filesystem).
10497 Or, perhaps you are running the device's operating system
10498 from a read-only storage device.
10499 For either case, you can customize your image for
10500 that behavior.
10501 </para>
10502
10503 <note>
10504 Supporting a read-only root filesystem requires that the system and
10505 applications do not try to write to the root filesystem.
10506 You must configure all parts of the target system to write
10507 elsewhere, or to gracefully fail in the event of attempting to
10508 write to the root filesystem.
10509 </note>
10510
10511 <section id='creating-the-root-filesystem'>
10512 <title>Creating the Root Filesystem</title>
10513
10514 <para>
10515 To create the read-only root filesystem, simply add the
10516 "read-only-rootfs" feature to your image.
10517 Using either of the following statements in your
10518 image recipe or from within the
10519 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010520 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010521 causes the build system to create a read-only root filesystem:
10522 <literallayout class='monospaced'>
10523 IMAGE_FEATURES = "read-only-rootfs"
10524 </literallayout>
10525 or
10526 <literallayout class='monospaced'>
10527 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
10528 </literallayout>
10529 </para>
10530
10531 <para>
10532 For more information on how to use these variables, see the
10533 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
10534 section.
10535 For information on the variables, see
10536 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
10537 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
10538 </para>
10539 </section>
10540
10541 <section id='post-installation-scripts'>
10542 <title>Post-Installation Scripts</title>
10543
10544 <para>
10545 It is very important that you make sure all
10546 post-Installation (<filename>pkg_postinst</filename>) scripts
10547 for packages that are installed into the image can be run
10548 at the time when the root filesystem is created during the
10549 build on the host system.
10550 These scripts cannot attempt to run during first-boot on the
10551 target device.
10552 With the "read-only-rootfs" feature enabled,
10553 the build system checks during root filesystem creation to make
10554 sure all post-installation scripts succeed.
10555 If any of these scripts still need to be run after the root
10556 filesystem is created, the build immediately fails.
10557 These build-time checks ensure that the build fails
10558 rather than the target device fails later during its
10559 initial boot operation.
10560 </para>
10561
10562 <para>
10563 Most of the common post-installation scripts generated by the
10564 build system for the out-of-the-box Yocto Project are engineered
10565 so that they can run during root filesystem creation
10566 (e.g. post-installation scripts for caching fonts).
10567 However, if you create and add custom scripts, you need
10568 to be sure they can be run during this file system creation.
10569 </para>
10570
10571 <para>
10572 Here are some common problems that prevent
10573 post-installation scripts from running during root filesystem
10574 creation:
10575 <itemizedlist>
10576 <listitem><para>
10577 <emphasis>Not using $D in front of absolute
10578 paths:</emphasis>
10579 The build system defines
10580 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
10581 when the root filesystem is created.
10582 Furthermore, <filename>$D</filename> is blank when the
10583 script is run on the target device.
10584 This implies two purposes for <filename>$D</filename>:
10585 ensuring paths are valid in both the host and target
10586 environments, and checking to determine which
10587 environment is being used as a method for taking
10588 appropriate actions.
10589 </para></listitem>
10590 <listitem><para>
10591 <emphasis>Attempting to run processes that are
10592 specific to or dependent on the target
10593 architecture:</emphasis>
10594 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010595 tools, which run on the host system,
10596 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010597 by alternatively running the processes under QEMU,
10598 which has the <filename>qemu_run_binary</filename>
10599 function.
10600 For more information, see the
10601 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
10602 class.</para></listitem>
10603 </itemizedlist>
10604 </para>
10605 </section>
10606
10607 <section id='areas-with-write-access'>
10608 <title>Areas With Write Access</title>
10609
10610 <para>
10611 With the "read-only-rootfs" feature enabled,
10612 any attempt by the target to write to the root filesystem at
10613 runtime fails.
10614 Consequently, you must make sure that you configure processes
10615 and applications that attempt these types of writes do so
10616 to directories with write access (e.g.
10617 <filename>/tmp</filename> or <filename>/var/run</filename>).
10618 </para>
10619 </section>
10620 </section>
10621
Brad Bishop316dfdd2018-06-25 12:45:53 -040010622
10623
10624
10625 <section id='maintaining-build-output-quality'>
10626 <title>Maintaining Build Output Quality</title>
10627
10628 <para>
10629 Many factors can influence the quality of a build.
10630 For example, if you upgrade a recipe to use a new version of an
10631 upstream software package or you experiment with some new
10632 configuration options, subtle changes can occur that you might
10633 not detect until later.
10634 Consider the case where your recipe is using a newer version of
10635 an upstream package.
10636 In this case, a new version of a piece of software might
10637 introduce an optional dependency on another library, which is
10638 auto-detected.
10639 If that library has already been built when the software is
10640 building, the software will link to the built library and that
10641 library will be pulled into your image along with the new
10642 software even if you did not want the library.
10643 </para>
10644
10645 <para>
10646 The
10647 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
10648 class exists to help you maintain the quality of your build
10649 output.
10650 You can use the class to highlight unexpected and possibly
10651 unwanted changes in the build output.
10652 When you enable build history, it records information about the
10653 contents of each package and image and then commits that
10654 information to a local Git repository where you can examine
10655 the information.
10656 </para>
10657
10658 <para>
10659 The remainder of this section describes the following:
10660 <itemizedlist>
10661 <listitem><para>
10662 How you can enable and disable build history
10663 </para></listitem>
10664 <listitem><para>
10665 How to understand what the build history contains
10666 </para></listitem>
10667 <listitem><para>
10668 How to limit the information used for build history
10669 </para></listitem>
10670 <listitem><para>
10671 How to examine the build history from both a
10672 command-line and web interface
10673 </para></listitem>
10674 </itemizedlist>
10675 </para>
10676
10677 <section id='enabling-and-disabling-build-history'>
10678 <title>Enabling and Disabling Build History</title>
10679
10680 <para>
10681 Build history is disabled by default.
10682 To enable it, add the following <filename>INHERIT</filename>
10683 statement and set the
10684 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
10685 variable to "1" at the end of your
10686 <filename>conf/local.conf</filename> file found in the
10687 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
10688 <literallayout class='monospaced'>
10689 INHERIT += "buildhistory"
10690 BUILDHISTORY_COMMIT = "1"
10691 </literallayout>
10692 Enabling build history as previously described causes the
10693 OpenEmbedded build system to collect build output information
10694 and commit it as a single commit to a local
10695 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
10696 repository.
10697 <note>
10698 Enabling build history increases your build times slightly,
10699 particularly for images, and increases the amount of disk
10700 space used during the build.
10701 </note>
10702 </para>
10703
10704 <para>
10705 You can disable build history by removing the previous
10706 statements from your <filename>conf/local.conf</filename>
10707 file.
10708 </para>
10709 </section>
10710
10711 <section id='understanding-what-the-build-history-contains'>
10712 <title>Understanding What the Build History Contains</title>
10713
10714 <para>
10715 Build history information is kept in
10716 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
10717 in the Build Directory as defined by the
10718 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
10719 variable.
10720 The following is an example abbreviated listing:
10721 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
10722 </para>
10723
10724 <para>
10725 At the top level, a <filename>metadata-revs</filename>
10726 file exists that lists the revisions of the repositories for
10727 the enabled layers when the build was produced.
10728 The rest of the data splits into separate
10729 <filename>packages</filename>, <filename>images</filename>
10730 and <filename>sdk</filename> directories, the contents of
10731 which are described as follows.
10732 </para>
10733
10734 <section id='build-history-package-information'>
10735 <title>Build History Package Information</title>
10736
10737 <para>
10738 The history for each package contains a text file that has
10739 name-value pairs with information about the package.
10740 For example,
10741 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
10742 contains the following:
10743 <literallayout class='monospaced'>
10744 PV = 1.22.1
10745 PR = r32
10746 RPROVIDES =
10747 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
10748 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
10749 PKGSIZE = 540168
10750 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
10751 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
10752 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
10753 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
10754 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
10755 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
10756 /etc/busybox.links.nosuid /etc/busybox.links.suid
10757 </literallayout>
10758 Most of these name-value pairs correspond to variables
10759 used to produce the package.
10760 The exceptions are <filename>FILELIST</filename>, which
10761 is the actual list of files in the package, and
10762 <filename>PKGSIZE</filename>, which is the total size of
10763 files in the package in bytes.
10764 </para>
10765
10766 <para>
10767 A file also exists that corresponds to the recipe from
10768 which the package came (e.g.
10769 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
10770 <literallayout class='monospaced'>
10771 PV = 1.22.1
10772 PR = r32
10773 DEPENDS = initscripts kern-tools-native update-rc.d-native \
10774 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
10775 virtual/libc virtual/update-alternatives
10776 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
10777 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
10778 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
10779 </literallayout>
10780 </para>
10781
10782 <para>
10783 Finally, for those recipes fetched from a version control
10784 system (e.g., Git), a file exists that lists source
10785 revisions that are specified in the recipe and lists
10786 the actual revisions used during the build.
10787 Listed and actual revisions might differ when
10788 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
10789 is set to
10790 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
10791 Here is an example assuming
10792 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
10793 <literallayout class='monospaced'>
10794 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
10795 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
10796 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
10797 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
10798 </literallayout>
10799 You can use the
10800 <filename>buildhistory-collect-srcrevs</filename>
10801 command with the <filename>-a</filename> option to
10802 collect the stored <filename>SRCREV</filename> values
10803 from build history and report them in a format suitable for
10804 use in global configuration (e.g.,
10805 <filename>local.conf</filename> or a distro include file)
10806 to override floating <filename>AUTOREV</filename> values
10807 to a fixed set of revisions.
10808 Here is some example output from this command:
10809 <literallayout class='monospaced'>
10810 $ buildhistory-collect-srcrevs -a
10811 # i586-poky-linux
10812 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
10813 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
10814 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
10815 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
10816 # x86_64-linux
10817 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
10818 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
10819 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
10820 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
10821 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
10822 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
10823 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
10824 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
10825 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
10826 # qemux86-poky-linux
10827 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
10828 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
10829 # all-poky-linux
10830 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
10831 </literallayout>
10832 <note>
10833 Here are some notes on using the
10834 <filename>buildhistory-collect-srcrevs</filename>
10835 command:
10836 <itemizedlist>
10837 <listitem><para>
10838 By default, only values where the
10839 <filename>SRCREV</filename> was not hardcoded
10840 (usually when <filename>AUTOREV</filename>
10841 is used) are reported.
10842 Use the <filename>-a</filename> option to
10843 see all <filename>SRCREV</filename> values.
10844 </para></listitem>
10845 <listitem><para>
10846 The output statements might not have any effect
10847 if overrides are applied elsewhere in the
10848 build system configuration.
10849 Use the <filename>-f</filename> option to add
10850 the <filename>forcevariable</filename> override
10851 to each output line if you need to work around
10852 this restriction.
10853 </para></listitem>
10854 <listitem><para>
10855 The script does apply special handling when
10856 building for multiple machines.
10857 However, the script does place a comment before
10858 each set of values that specifies which
10859 triplet to which they belong as previously
10860 shown (e.g.,
10861 <filename>i586-poky-linux</filename>).
10862 </para></listitem>
10863 </itemizedlist>
10864 </note>
10865 </para>
10866 </section>
10867
10868 <section id='build-history-image-information'>
10869 <title>Build History Image Information</title>
10870
10871 <para>
10872 The files produced for each image are as follows:
10873 <itemizedlist>
10874 <listitem><para>
10875 <filename>image-files:</filename>
10876 A directory containing selected files from the root
10877 filesystem.
10878 The files are defined by
10879 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
10880 </para></listitem>
10881 <listitem><para>
10882 <filename>build-id.txt:</filename>
10883 Human-readable information about the build
10884 configuration and metadata source revisions.
10885 This file contains the full build header as printed
10886 by BitBake.
10887 </para></listitem>
10888 <listitem><para>
10889 <filename>*.dot:</filename>
10890 Dependency graphs for the image that are
10891 compatible with <filename>graphviz</filename>.
10892 </para></listitem>
10893 <listitem><para>
10894 <filename>files-in-image.txt:</filename>
10895 A list of files in the image with permissions,
10896 owner, group, size, and symlink information.
10897 </para></listitem>
10898 <listitem><para>
10899 <filename>image-info.txt:</filename>
10900 A text file containing name-value pairs with
10901 information about the image.
10902 See the following listing example for more
10903 information.
10904 </para></listitem>
10905 <listitem><para>
10906 <filename>installed-package-names.txt:</filename>
10907 A list of installed packages by name only.
10908 </para></listitem>
10909 <listitem><para>
10910 <filename>installed-package-sizes.txt:</filename>
10911 A list of installed packages ordered by size.
10912 </para></listitem>
10913 <listitem><para>
10914 <filename>installed-packages.txt:</filename>
10915 A list of installed packages with full package
10916 filenames.
10917 </para></listitem>
10918 </itemizedlist>
10919 <note>
10920 Installed package information is able to be gathered
10921 and produced even if package management is disabled
10922 for the final image.
10923 </note>
10924 </para>
10925
10926 <para>
10927 Here is an example of <filename>image-info.txt</filename>:
10928 <literallayout class='monospaced'>
10929 DISTRO = poky
10930 DISTRO_VERSION = 1.7
10931 USER_CLASSES = buildstats image-mklibs image-prelink
10932 IMAGE_CLASSES = image_types
10933 IMAGE_FEATURES = debug-tweaks
10934 IMAGE_LINGUAS =
10935 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
10936 BAD_RECOMMENDATIONS =
10937 NO_RECOMMENDATIONS =
10938 PACKAGE_EXCLUDE =
10939 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
10940 write_image_manifest ; buildhistory_list_installed_image ; \
10941 buildhistory_get_image_installed ; ssh_allow_empty_password; \
10942 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
10943 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
10944 IMAGESIZE = 6900
10945 </literallayout>
10946 Other than <filename>IMAGESIZE</filename>, which is the
10947 total size of the files in the image in Kbytes, the
10948 name-value pairs are variables that may have influenced the
10949 content of the image.
10950 This information is often useful when you are trying to
10951 determine why a change in the package or file
10952 listings has occurred.
10953 </para>
10954 </section>
10955
10956 <section id='using-build-history-to-gather-image-information-only'>
10957 <title>Using Build History to Gather Image Information Only</title>
10958
10959 <para>
10960 As you can see, build history produces image information,
10961 including dependency graphs, so you can see why something
10962 was pulled into the image.
10963 If you are just interested in this information and not
10964 interested in collecting specific package or SDK
10965 information, you can enable writing only image information
10966 without any history by adding the following to your
10967 <filename>conf/local.conf</filename> file found in the
10968 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
10969 <literallayout class='monospaced'>
10970 INHERIT += "buildhistory"
10971 BUILDHISTORY_COMMIT = "0"
10972 BUILDHISTORY_FEATURES = "image"
10973 </literallayout>
10974 Here, you set the
10975 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
10976 variable to use the image feature only.
10977 </para>
10978 </section>
10979
10980 <section id='build-history-sdk-information'>
10981 <title>Build History SDK Information</title>
10982
10983 <para>
10984 Build history collects similar information on the contents
10985 of SDKs
10986 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
10987 as compared to information it collects for images.
10988 Furthermore, this information differs depending on whether
10989 an extensible or standard SDK is being produced.
10990 </para>
10991
10992 <para>
10993 The following list shows the files produced for SDKs:
10994 <itemizedlist>
10995 <listitem><para>
10996 <filename>files-in-sdk.txt:</filename>
10997 A list of files in the SDK with permissions,
10998 owner, group, size, and symlink information.
10999 This list includes both the host and target parts
11000 of the SDK.
11001 </para></listitem>
11002 <listitem><para>
11003 <filename>sdk-info.txt:</filename>
11004 A text file containing name-value pairs with
11005 information about the SDK.
11006 See the following listing example for more
11007 information.
11008 </para></listitem>
11009 <listitem><para>
11010 <filename>sstate-task-sizes.txt:</filename>
11011 A text file containing name-value pairs with
11012 information about task group sizes
11013 (e.g. <filename>do_populate_sysroot</filename>
11014 tasks have a total size).
11015 The <filename>sstate-task-sizes.txt</filename> file
11016 exists only when an extensible SDK is created.
11017 </para></listitem>
11018 <listitem><para>
11019 <filename>sstate-package-sizes.txt:</filename>
11020 A text file containing name-value pairs with
11021 information for the shared-state packages and
11022 sizes in the SDK.
11023 The <filename>sstate-package-sizes.txt</filename>
11024 file exists only when an extensible SDK is created.
11025 </para></listitem>
11026 <listitem><para>
11027 <filename>sdk-files:</filename>
11028 A folder that contains copies of the files
11029 mentioned in
11030 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11031 files are present in the output.
11032 Additionally, the default value of
11033 <filename>BUILDHISTORY_SDK_FILES</filename> is
11034 specific to the extensible SDK although you can
11035 set it differently if you would like to pull in
11036 specific files from the standard SDK.</para>
11037
11038 <para>The default files are
11039 <filename>conf/local.conf</filename>,
11040 <filename>conf/bblayers.conf</filename>,
11041 <filename>conf/auto.conf</filename>,
11042 <filename>conf/locked-sigs.inc</filename>, and
11043 <filename>conf/devtool.conf</filename>.
11044 Thus, for an extensible SDK, these files get
11045 copied into the <filename>sdk-files</filename>
11046 directory.
11047 </para></listitem>
11048 <listitem><para>
11049 The following information appears under
11050 each of the <filename>host</filename>
11051 and <filename>target</filename> directories
11052 for the portions of the SDK that run on the host
11053 and on the target, respectively:
11054 <note>
11055 The following files for the most part are empty
11056 when producing an extensible SDK because this
11057 type of SDK is not constructed from packages
11058 as is the standard SDK.
11059 </note>
11060 <itemizedlist>
11061 <listitem><para>
11062 <filename>depends.dot:</filename>
11063 Dependency graph for the SDK that is
11064 compatible with
11065 <filename>graphviz</filename>.
11066 </para></listitem>
11067 <listitem><para>
11068 <filename>installed-package-names.txt:</filename>
11069 A list of installed packages by name only.
11070 </para></listitem>
11071 <listitem><para>
11072 <filename>installed-package-sizes.txt:</filename>
11073 A list of installed packages ordered by size.
11074 </para></listitem>
11075 <listitem><para>
11076 <filename>installed-packages.txt:</filename>
11077 A list of installed packages with full
11078 package filenames.
11079 </para></listitem>
11080 </itemizedlist>
11081 </para></listitem>
11082 </itemizedlist>
11083 </para>
11084
11085 <para>
11086 Here is an example of <filename>sdk-info.txt</filename>:
11087 <literallayout class='monospaced'>
11088 DISTRO = poky
11089 DISTRO_VERSION = 1.3+snapshot-20130327
11090 SDK_NAME = poky-glibc-i686-arm
11091 SDK_VERSION = 1.3+snapshot
11092 SDKMACHINE =
11093 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11094 BAD_RECOMMENDATIONS =
11095 SDKSIZE = 352712
11096 </literallayout>
11097 Other than <filename>SDKSIZE</filename>, which is the
11098 total size of the files in the SDK in Kbytes, the
11099 name-value pairs are variables that might have influenced
11100 the content of the SDK.
11101 This information is often useful when you are trying to
11102 determine why a change in the package or file listings
11103 has occurred.
11104 </para>
11105 </section>
11106
11107 <section id='examining-build-history-information'>
11108 <title>Examining Build History Information</title>
11109
11110 <para>
11111 You can examine build history output from the command
11112 line or from a web interface.
11113 </para>
11114
11115 <para>
11116 To see any changes that have occurred (assuming you have
11117 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11118 you can simply use any Git command that allows you to
11119 view the history of a repository.
11120 Here is one method:
11121 <literallayout class='monospaced'>
11122 $ git log -p
11123 </literallayout>
11124 You need to realize, however, that this method does show
11125 changes that are not significant (e.g. a package's size
11126 changing by a few bytes).
11127 </para>
11128
11129 <para>
11130 A command-line tool called
11131 <filename>buildhistory-diff</filename> does exist, though,
11132 that queries the Git repository and prints just the
11133 differences that might be significant in human-readable
11134 form.
11135 Here is an example:
11136 <literallayout class='monospaced'>
11137 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11138 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11139 /etc/anotherpkg.conf was added
11140 /sbin/anotherpkg was added
11141 * (installed-package-names.txt):
11142 * anotherpkg was added
11143 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11144 anotherpkg was added
11145 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11146 * PR changed from "r0" to "r1"
11147 * PV changed from "0.1.10" to "0.1.12"
11148 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11149 * PR changed from "r0" to "r1"
11150 * PV changed from "0.1.10" to "0.1.12"
11151 </literallayout>
11152 <note>
11153 The <filename>buildhistory-diff</filename> tool
11154 requires the <filename>GitPython</filename> package.
11155 Be sure to install it using Pip3 as follows:
11156 <literallayout class='monospaced'>
11157 $ pip3 install GitPython --user
11158 </literallayout>
11159 Alternatively, you can install
11160 <filename>python3-git</filename> using the appropriate
11161 distribution package manager (e.g.
11162 <filename>apt-get</filename>, <filename>dnf</filename>,
11163 or <filename>zipper</filename>).
11164 </note>
11165 </para>
11166
11167 <para>
11168 To see changes to the build history using a web interface,
11169 follow the instruction in the <filename>README</filename>
11170 file here.
11171 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11172 </para>
11173
11174 <para>
11175 Here is a sample screenshot of the interface:
11176 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11177 </para>
11178 </section>
11179 </section>
11180 </section>
11181
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011182 <section id="performing-automated-runtime-testing">
11183 <title>Performing Automated Runtime Testing</title>
11184
11185 <para>
11186 The OpenEmbedded build system makes available a series of automated
11187 tests for images to verify runtime functionality.
11188 You can run these tests on either QEMU or actual target hardware.
11189 Tests are written in Python making use of the
11190 <filename>unittest</filename> module, and the majority of them
11191 run commands on the target system over SSH.
11192 This section describes how you set up the environment to use these
11193 tests, run available tests, and write and add your own tests.
11194 </para>
11195
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011196 <para>
11197 For information on the test and QA infrastructure available
11198 within the Yocto Project, see the
11199 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11200 section in the Yocto Project Reference Manual.
11201 </para>
11202
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011203 <section id='enabling-tests'>
11204 <title>Enabling Tests</title>
11205
11206 <para>
11207 Depending on whether you are planning to run tests using
11208 QEMU or on the hardware, you have to take
11209 different steps to enable the tests.
11210 See the following subsections for information on how to
11211 enable both types of tests.
11212 </para>
11213
11214 <section id='qemu-image-enabling-tests'>
11215 <title>Enabling Runtime Tests on QEMU</title>
11216
11217 <para>
11218 In order to run tests, you need to do the following:
11219 <itemizedlist>
11220 <listitem><para><emphasis>Set up to avoid interaction
11221 with <filename>sudo</filename> for networking:</emphasis>
11222 To accomplish this, you must do one of the
11223 following:
11224 <itemizedlist>
11225 <listitem><para>Add
11226 <filename>NOPASSWD</filename> for your user
11227 in <filename>/etc/sudoers</filename> either for
11228 all commands or just for
11229 <filename>runqemu-ifup</filename>.
11230 You must provide the full path as that can
11231 change if you are using multiple clones of the
11232 source repository.
11233 <note>
11234 On some distributions, you also need to
11235 comment out "Defaults requiretty" in
11236 <filename>/etc/sudoers</filename>.
11237 </note></para></listitem>
11238 <listitem><para>Manually configure a tap interface
11239 for your system.</para></listitem>
11240 <listitem><para>Run as root the script in
11241 <filename>scripts/runqemu-gen-tapdevs</filename>,
11242 which should generate a list of tap devices.
11243 This is the option typically chosen for
11244 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011245 <note><title>Notes</title>
11246 <itemizedlist>
11247 <listitem><para>
11248 Be sure to use an absolute path
11249 when calling this script
11250 with sudo.
11251 </para></listitem>
11252 <listitem><para>
11253 The package recipe
11254 <filename>qemu-helper-native</filename>
11255 is required to run this script.
11256 Build the package using the
11257 following command:
11258 <literallayout class='monospaced'>
11259 $ bitbake qemu-helper-native
11260 </literallayout>
11261 </para></listitem>
11262 </itemizedlist>
11263 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011264 </para></listitem>
11265 </itemizedlist></para></listitem>
11266 <listitem><para><emphasis>Set the
11267 <filename>DISPLAY</filename> variable:</emphasis>
11268 You need to set this variable so that you have an X
11269 server available (e.g. start
11270 <filename>vncserver</filename> for a headless machine).
11271 </para></listitem>
11272 <listitem><para><emphasis>Be sure your host's firewall
11273 accepts incoming connections from
11274 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011275 Some of the tests (in particular DNF tests) start
11276 an HTTP server on a random high number port,
11277 which is used to serve files to the target.
11278 The DNF module serves
11279 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11280 so it can run DNF channel commands.
11281 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011282 must accept incoming connections from 192.168.7.0/24,
11283 which is the default IP range used for tap devices
11284 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011285 <listitem><para><emphasis>Be sure your host has the
11286 correct packages installed:</emphasis>
11287 Depending your host's distribution, you need
11288 to have the following packages installed:
11289 <itemizedlist>
11290 <listitem><para>Ubuntu and Debian:
11291 <filename>sysstat</filename> and
11292 <filename>iproute2</filename>
11293 </para></listitem>
11294 <listitem><para>OpenSUSE:
11295 <filename>sysstat</filename> and
11296 <filename>iproute2</filename>
11297 </para></listitem>
11298 <listitem><para>Fedora:
11299 <filename>sysstat</filename> and
11300 <filename>iproute</filename>
11301 </para></listitem>
11302 <listitem><para>CentOS:
11303 <filename>sysstat</filename> and
11304 <filename>iproute</filename>
11305 </para></listitem>
11306 </itemizedlist>
11307 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011308 </itemizedlist>
11309 </para>
11310
11311 <para>
11312 Once you start running the tests, the following happens:
11313 <orderedlist>
11314 <listitem><para>A copy of the root filesystem is written
11315 to <filename>${WORKDIR}/testimage</filename>.
11316 </para></listitem>
11317 <listitem><para>The image is booted under QEMU using the
11318 standard <filename>runqemu</filename> script.
11319 </para></listitem>
11320 <listitem><para>A default timeout of 500 seconds occurs
11321 to allow for the boot process to reach the login prompt.
11322 You can change the timeout period by setting
11323 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11324 in the <filename>local.conf</filename> file.
11325 </para></listitem>
11326 <listitem><para>Once the boot process is reached and the
11327 login prompt appears, the tests run.
11328 The full boot log is written to
11329 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11330 </para></listitem>
11331 <listitem><para>Each test module loads in the order found
11332 in <filename>TEST_SUITES</filename>.
11333 You can find the full output of the commands run over
11334 SSH in
11335 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11336 </para></listitem>
11337 <listitem><para>If no failures occur, the task running the
11338 tests ends successfully.
11339 You can find the output from the
11340 <filename>unittest</filename> in the task log at
11341 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11342 </para></listitem>
11343 </orderedlist>
11344 </para>
11345 </section>
11346
11347 <section id='hardware-image-enabling-tests'>
11348 <title>Enabling Runtime Tests on Hardware</title>
11349
11350 <para>
11351 The OpenEmbedded build system can run tests on real
11352 hardware, and for certain devices it can also deploy
11353 the image to be tested onto the device beforehand.
11354 </para>
11355
11356 <para>
11357 For automated deployment, a "master image" is installed
11358 onto the hardware once as part of setup.
11359 Then, each time tests are to be run, the following
11360 occurs:
11361 <orderedlist>
11362 <listitem><para>The master image is booted into and
11363 used to write the image to be tested to
11364 a second partition.
11365 </para></listitem>
11366 <listitem><para>The device is then rebooted using an
11367 external script that you need to provide.
11368 </para></listitem>
11369 <listitem><para>The device boots into the image to be
11370 tested.
11371 </para></listitem>
11372 </orderedlist>
11373 </para>
11374
11375 <para>
11376 When running tests (independent of whether the image
11377 has been deployed automatically or not), the device is
11378 expected to be connected to a network on a
11379 pre-determined IP address.
11380 You can either use static IP addresses written into
11381 the image, or set the image to use DHCP and have your
11382 DHCP server on the test network assign a known IP address
11383 based on the MAC address of the device.
11384 </para>
11385
11386 <para>
11387 In order to run tests on hardware, you need to set
11388 <filename>TEST_TARGET</filename> to an appropriate value.
11389 For QEMU, you do not have to change anything, the default
11390 value is "QemuTarget".
11391 For running tests on hardware, the following options exist:
11392 <itemizedlist>
11393 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11394 Choose "SimpleRemoteTarget" if you are going to
11395 run tests on a target system that is already
11396 running the image to be tested and is available
11397 on the network.
11398 You can use "SimpleRemoteTarget" in conjunction
11399 with either real hardware or an image running
11400 within a separately started QEMU or any
11401 other virtual machine manager.
11402 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011403 <listitem><para><emphasis>"Systemd-bootTarget":</emphasis>
11404 Choose "Systemd-bootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011405 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011406 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011407 <filename>core-image-testmaster</filename>
11408 (or something similar) is installed.
11409 Also, your hardware under test must be in a
11410 DHCP-enabled network that gives it the same IP
11411 address for each reboot.</para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011412 <para>If you choose "Systemd-bootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011413 additional requirements and considerations.
11414 See the
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011415 "<link linkend='selecting-systemd-boottarget'>Selecting Systemd-bootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011416 section, which follows, for more information.
11417 </para></listitem>
11418 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
11419 Choose "BeagleBoneTarget" if you are deploying
11420 images and running tests on the BeagleBone
11421 "Black" or original "White" hardware.
11422 For information on how to use these tests, see the
11423 comments at the top of the BeagleBoneTarget
11424 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
11425 file.
11426 </para></listitem>
11427 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
11428 Choose "EdgeRouterTarget" is you are deploying
11429 images and running tests on the Ubiquiti Networks
11430 EdgeRouter Lite.
11431 For information on how to use these tests, see the
11432 comments at the top of the EdgeRouterTarget
11433 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
11434 file.
11435 </para></listitem>
11436 <listitem><para><emphasis>"GrubTarget":</emphasis>
11437 Choose the "supports deploying images and running
11438 tests on any generic PC that boots using GRUB.
11439 For information on how to use these tests, see the
11440 comments at the top of the GrubTarget
11441 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
11442 file.
11443 </para></listitem>
11444 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
11445 Create your own custom target if you want to run
11446 tests when you are deploying images and running
11447 tests on a custom machine within your BSP layer.
11448 To do this, you need to add a Python unit that
11449 defines the target class under
11450 <filename>lib/oeqa/controllers/</filename> within
11451 your layer.
11452 You must also provide an empty
11453 <filename>__init__.py</filename>.
11454 For examples, see files in
11455 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
11456 </para></listitem>
11457 </itemizedlist>
11458 </para>
11459 </section>
11460
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011461 <section id='selecting-systemd-boottarget'>
11462 <title>Selecting Systemd-bootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011463
11464 <para>
11465 If you did not set <filename>TEST_TARGET</filename> to
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011466 "Systemd-bootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011467 in this section.
11468 You can skip down to the
11469 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
11470 section.
11471 </para>
11472
11473 <para>
11474 If you did set <filename>TEST_TARGET</filename> to
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011475 "Systemd-bootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011476 setup of your master image by doing the following:
11477 <orderedlist>
11478 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
11479 Be sure that <filename>EFI_PROVIDER</filename>
11480 is as follows:
11481 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011482 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011483 </literallayout>
11484 </para></listitem>
11485 <listitem><para><emphasis>Build the master image:</emphasis>
11486 Build the <filename>core-image-testmaster</filename>
11487 image.
11488 The <filename>core-image-testmaster</filename>
11489 recipe is provided as an example for a
11490 "master" image and you can customize the image
11491 recipe as you would any other recipe.
11492 </para>
11493 <para>Here are the image recipe requirements:
11494 <itemizedlist>
11495 <listitem><para>Inherits
11496 <filename>core-image</filename>
11497 so that kernel modules are installed.
11498 </para></listitem>
11499 <listitem><para>Installs normal linux utilities
11500 not busybox ones (e.g.
11501 <filename>bash</filename>,
11502 <filename>coreutils</filename>,
11503 <filename>tar</filename>,
11504 <filename>gzip</filename>, and
11505 <filename>kmod</filename>).
11506 </para></listitem>
11507 <listitem><para>Uses a custom
11508 Initial RAM Disk (initramfs) image with a
11509 custom installer.
11510 A normal image that you can install usually
11511 creates a single rootfs partition.
11512 This image uses another installer that
11513 creates a specific partition layout.
11514 Not all Board Support Packages (BSPs)
11515 can use an installer.
11516 For such cases, you need to manually create
11517 the following partition layout on the
11518 target:
11519 <itemizedlist>
11520 <listitem><para>First partition mounted
11521 under <filename>/boot</filename>,
11522 labeled "boot".
11523 </para></listitem>
11524 <listitem><para>The main rootfs
11525 partition where this image gets
11526 installed, which is mounted under
11527 <filename>/</filename>.
11528 </para></listitem>
11529 <listitem><para>Another partition
11530 labeled "testrootfs" where test
11531 images get deployed.
11532 </para></listitem>
11533 </itemizedlist>
11534 </para></listitem>
11535 </itemizedlist>
11536 </para></listitem>
11537 <listitem><para><emphasis>Install image:</emphasis>
11538 Install the image that you just built on the target
11539 system.
11540 </para></listitem>
11541 </orderedlist>
11542 </para>
11543
11544 <para>
11545 The final thing you need to do when setting
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011546 <filename>TEST_TARGET</filename> to "Systemd-bootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011547 to set up the test image:
11548 <orderedlist>
11549 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
11550 Make sure you have the following statements in
11551 your <filename>local.conf</filename> file:
11552 <literallayout class='monospaced'>
11553 IMAGE_FSTYPES += "tar.gz"
11554 INHERIT += "testimage"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011555 TEST_TARGET = "Systemd-bootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011556 TEST_TARGET_IP = "192.168.2.3"
11557 </literallayout>
11558 </para></listitem>
11559 <listitem><para><emphasis>Build your test image:</emphasis>
11560 Use BitBake to build the image:
11561 <literallayout class='monospaced'>
11562 $ bitbake core-image-sato
11563 </literallayout>
11564 </para></listitem>
11565 </orderedlist>
11566 </para>
11567 </section>
11568
11569 <section id='power-control'>
11570 <title>Power Control</title>
11571
11572 <para>
11573 For most hardware targets other than SimpleRemoteTarget,
11574 you can control power:
11575 <itemizedlist>
11576 <listitem><para>
11577 You can use
11578 <filename>TEST_POWERCONTROL_CMD</filename>
11579 together with
11580 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11581 as a command that runs on the host and does power
11582 cycling.
11583 The test code passes one argument to that command:
11584 off, on or cycle (off then on).
11585 Here is an example that could appear in your
11586 <filename>local.conf</filename> file:
11587 <literallayout class='monospaced'>
11588 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
11589 </literallayout>
11590 In this example, the expect script does the
11591 following:
11592 <literallayout class='monospaced'>
11593 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
11594 </literallayout>
11595 It then runs a Python script that controls power
11596 for a label called <filename>nuc1</filename>.
11597 <note>
11598 You need to customize
11599 <filename>TEST_POWERCONTROL_CMD</filename>
11600 and
11601 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11602 for your own setup.
11603 The one requirement is that it accepts
11604 "on", "off", and "cycle" as the last argument.
11605 </note>
11606 </para></listitem>
11607 <listitem><para>
11608 When no command is defined, it connects to the
11609 device over SSH and uses the classic reboot command
11610 to reboot the device.
11611 Classic reboot is fine as long as the machine
11612 actually reboots (i.e. the SSH test has not
11613 failed).
11614 It is useful for scenarios where you have a simple
11615 setup, typically with a single board, and where
11616 some manual interaction is okay from time to time.
11617 </para></listitem>
11618 </itemizedlist>
11619 If you have no hardware to automatically perform power
11620 control but still wish to experiment with automated
11621 hardware testing, you can use the dialog-power-control
11622 script that shows a dialog prompting you to perform the
11623 required power action.
11624 This script requires either KDialog or Zenity to be
11625 installed.
11626 To use this script, set the
11627 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
11628 variable as follows:
11629 <literallayout class='monospaced'>
11630 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
11631 </literallayout>
11632 </para>
11633 </section>
11634
11635 <section id='serial-console-connection'>
11636 <title>Serial Console Connection</title>
11637
11638 <para>
11639 For test target classes requiring a serial console
11640 to interact with the bootloader (e.g. BeagleBoneTarget,
11641 EdgeRouterTarget, and GrubTarget), you need to
11642 specify a command to use to connect to the serial console
11643 of the target machine by using the
11644 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
11645 variable and optionally the
11646 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
11647 variable.
11648 </para>
11649
11650 <para>
11651 These cases could be a serial terminal program if the
11652 machine is connected to a local serial port, or a
11653 <filename>telnet</filename> or
11654 <filename>ssh</filename> command connecting to a remote
11655 console server.
11656 Regardless of the case, the command simply needs to
11657 connect to the serial console and forward that connection
11658 to standard input and output as any normal terminal
11659 program does.
11660 For example, to use the picocom terminal program on
11661 serial device <filename>/dev/ttyUSB0</filename>
11662 at 115200bps, you would set the variable as follows:
11663 <literallayout class='monospaced'>
11664 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
11665 </literallayout>
11666 For local devices where the serial port device disappears
11667 when the device reboots, an additional "serdevtry" wrapper
11668 script is provided.
11669 To use this wrapper, simply prefix the terminal command
11670 with
11671 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
11672 <literallayout class='monospaced'>
11673 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
11674115200 /dev/ttyUSB0"
11675 </literallayout>
11676 </para>
11677 </section>
11678 </section>
11679
11680 <section id="qemu-image-running-tests">
11681 <title>Running Tests</title>
11682
11683 <para>
11684 You can start the tests automatically or manually:
11685 <itemizedlist>
11686 <listitem><para><emphasis>Automatically running tests:</emphasis>
11687 To run the tests automatically after the
11688 OpenEmbedded build system successfully creates an image,
11689 first set the
11690 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_IMAGE'><filename>TEST_IMAGE</filename></ulink>
11691 variable to "1" in your <filename>local.conf</filename>
11692 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011693 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011694 <literallayout class='monospaced'>
11695 TEST_IMAGE = "1"
11696 </literallayout>
11697 Next, build your image.
11698 If the image successfully builds, the tests will be
11699 run:
11700 <literallayout class='monospaced'>
11701 bitbake core-image-sato
11702 </literallayout></para></listitem>
11703 <listitem><para><emphasis>Manually running tests:</emphasis>
11704 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011705 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011706 class by editing your <filename>local.conf</filename>
11707 file:
11708 <literallayout class='monospaced'>
11709 INHERIT += "testimage"
11710 </literallayout>
11711 Next, use BitBake to run the tests:
11712 <literallayout class='monospaced'>
11713 bitbake -c testimage <replaceable>image</replaceable>
11714 </literallayout></para></listitem>
11715 </itemizedlist>
11716 </para>
11717
11718 <para>
11719 All test files reside in
11720 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011721 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011722 A test name maps directly to a Python module.
11723 Each test module may contain a number of individual tests.
11724 Tests are usually grouped together by the area
11725 tested (e.g tests for systemd reside in
11726 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
11727 </para>
11728
11729 <para>
11730 You can add tests to any layer provided you place them in the
11731 proper area and you extend
11732 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
11733 in the <filename>local.conf</filename> file as normal.
11734 Be sure that tests reside in
11735 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
11736 <note>
11737 Be sure that module names do not collide with module names
11738 used in the default set of test modules in
11739 <filename>meta/lib/oeqa/runtime</filename>.
11740 </note>
11741 </para>
11742
11743 <para>
11744 You can change the set of tests run by appending or overriding
11745 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
11746 variable in <filename>local.conf</filename>.
11747 Each name in <filename>TEST_SUITES</filename> represents a
11748 required test for the image.
11749 Test modules named within <filename>TEST_SUITES</filename>
11750 cannot be skipped even if a test is not suitable for an image
11751 (e.g. running the RPM tests on an image without
11752 <filename>rpm</filename>).
11753 Appending "auto" to <filename>TEST_SUITES</filename> causes the
11754 build system to try to run all tests that are suitable for the
11755 image (i.e. each test module may elect to skip itself).
11756 </para>
11757
11758 <para>
11759 The order you list tests in <filename>TEST_SUITES</filename>
11760 is important and influences test dependencies.
11761 Consequently, tests that depend on other tests should be added
11762 after the test on which they depend.
11763 For example, since the <filename>ssh</filename> test
11764 depends on the
11765 <filename>ping</filename> test, "ssh" needs to come after
11766 "ping" in the list.
11767 The test class provides no re-ordering or dependency handling.
11768 <note>
11769 Each module can have multiple classes with multiple test
11770 methods.
11771 And, Python <filename>unittest</filename> rules apply.
11772 </note>
11773 </para>
11774
11775 <para>
11776 Here are some things to keep in mind when running tests:
11777 <itemizedlist>
11778 <listitem><para>The default tests for the image are defined
11779 as:
11780 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011781 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 -050011782 </literallayout></para></listitem>
11783 <listitem><para>Add your own test to the list of the
11784 by using the following:
11785 <literallayout class='monospaced'>
11786 TEST_SUITES_append = " mytest"
11787 </literallayout></para></listitem>
11788 <listitem><para>Run a specific list of tests as follows:
11789 <literallayout class='monospaced'>
11790 TEST_SUITES = "test1 test2 test3"
11791 </literallayout>
11792 Remember, order is important.
11793 Be sure to place a test that is dependent on another test
11794 later in the order.</para></listitem>
11795 </itemizedlist>
11796 </para>
11797 </section>
11798
11799 <section id="exporting-tests">
11800 <title>Exporting Tests</title>
11801
11802 <para>
11803 You can export tests so that they can run independently of
11804 the build system.
11805 Exporting tests is required if you want to be able to hand
11806 the test execution off to a scheduler.
11807 You can only export tests that are defined in
11808 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
11809 </para>
11810
11811 <para>
11812 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011813 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011814 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011815 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011816 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
11817 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011818 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011819 You can then export the tests with the following BitBake
11820 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011821 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011822 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011823 </literallayout>
11824 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011825 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
11826 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011827 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
11828 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011829 <filename>TEST_EXPORT_DIR</filename> variable.
11830 </para>
11831
11832 <para>
11833 You can now run the tests outside of the build environment:
11834 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011835 $ cd tmp/testexport/<replaceable>image</replaceable>
11836 $ ./runexported.py testdata.json
11837 </literallayout>
11838 </para>
11839
11840 <para>
11841 Here is a complete example that shows IP addresses and uses
11842 the <filename>core-image-sato</filename> image:
11843 <literallayout class='monospaced'>
11844 INHERIT +="testexport"
11845 TEST_TARGET_IP = "192.168.7.2"
11846 TEST_SERVER_IP = "192.168.7.1"
11847 </literallayout>
11848 Use BitBake to export the tests:
11849 <literallayout class='monospaced'>
11850 $ bitbake core-image-sato -c testexport
11851 </literallayout>
11852 Run the tests outside of the build environment using the
11853 following:
11854 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011855 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011856 $ ./runexported.py testdata.json
11857 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011858 </para>
11859 </section>
11860
11861 <section id="qemu-image-writing-new-tests">
11862 <title>Writing New Tests</title>
11863
11864 <para>
11865 As mentioned previously, all new test files need to be in the
11866 proper place for the build system to find them.
11867 New tests for additional functionality outside of the core
11868 should be added to the layer that adds the functionality, in
11869 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
11870 (as long as
11871 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
11872 is extended in the layer's
11873 <filename>layer.conf</filename> file as normal).
11874 Just remember the following:
11875 <itemizedlist>
11876 <listitem><para>Filenames need to map directly to test
11877 (module) names.
11878 </para></listitem>
11879 <listitem><para>Do not use module names that
11880 collide with existing core tests.
11881 </para></listitem>
11882 <listitem><para>Minimally, an empty
11883 <filename>__init__.py</filename> file must exist
11884 in the runtime directory.
11885 </para></listitem>
11886 </itemizedlist>
11887 </para>
11888
11889 <para>
11890 To create a new test, start by copying an existing module
11891 (e.g. <filename>syslog.py</filename> or
11892 <filename>gcc.py</filename> are good ones to use).
11893 Test modules can use code from
11894 <filename>meta/lib/oeqa/utils</filename>, which are helper
11895 classes.
11896 </para>
11897
11898 <note>
11899 Structure shell commands such that you rely on them and they
11900 return a single code for success.
11901 Be aware that sometimes you will need to parse the output.
11902 See the <filename>df.py</filename> and
11903 <filename>date.py</filename> modules for examples.
11904 </note>
11905
11906 <para>
11907 You will notice that all test classes inherit
11908 <filename>oeRuntimeTest</filename>, which is found in
11909 <filename>meta/lib/oetest.py</filename>.
11910 This base class offers some helper attributes, which are
11911 described in the following sections:
11912 </para>
11913
11914 <section id='qemu-image-writing-tests-class-methods'>
11915 <title>Class Methods</title>
11916
11917 <para>
11918 Class methods are as follows:
11919 <itemizedlist>
11920 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
11921 Returns "True" if <filename>pkg</filename> is in the
11922 installed package list of the image, which is based
11923 on the manifest file that is generated during the
11924 <filename>do_rootfs</filename> task.
11925 </para></listitem>
11926 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
11927 Returns "True" if the feature is in
11928 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
11929 or
11930 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
11931 </para></listitem>
11932 </itemizedlist>
11933 </para>
11934 </section>
11935
11936 <section id='qemu-image-writing-tests-class-attributes'>
11937 <title>Class Attributes</title>
11938
11939 <para>
11940 Class attributes are as follows:
11941 <itemizedlist>
11942 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
11943 Equals "ps -ef" if <filename>procps</filename> is
11944 installed in the image.
11945 Otherwise, <filename>pscmd</filename> equals
11946 "ps" (busybox).
11947 </para></listitem>
11948 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
11949 The called test context, which gives access to the
11950 following attributes:
11951 <itemizedlist>
11952 <listitem><para><emphasis><filename>d</filename>:</emphasis>
11953 The BitBake datastore, which allows you to
11954 use stuff such as
11955 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
11956 </para></listitem>
11957 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
11958 Used internally.
11959 The tests do not need these.
11960 </para></listitem>
11961 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
11962 The absolute path to
11963 <filename>meta/lib/oeqa/runtime/files</filename>,
11964 which contains helper files for tests meant
11965 for copying on the target such as small
11966 files written in C for compilation.
11967 </para></listitem>
11968 <listitem><para><emphasis><filename>target</filename>:</emphasis>
11969 The target controller object used to deploy
11970 and start an image on a particular target
11971 (e.g. QemuTarget, SimpleRemote, and
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011972 Systemd-bootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011973 Tests usually use the following:
11974 <itemizedlist>
11975 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
11976 The target's IP address.
11977 </para></listitem>
11978 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
11979 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011980 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011981 suite.
11982 </para></listitem>
11983 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
11984 The single, most used method.
11985 This command is a wrapper for:
11986 <filename>ssh root@host "cmd"</filename>.
11987 The command returns a tuple:
11988 (status, output), which are what
11989 their names imply - the return code
11990 of "cmd" and whatever output
11991 it produces.
11992 The optional timeout argument
11993 represents the number of seconds the
11994 test should wait for "cmd" to
11995 return.
11996 If the argument is "None", the
11997 test uses the default instance's
11998 timeout period, which is 300
11999 seconds.
12000 If the argument is "0", the test
12001 runs until the command returns.
12002 </para></listitem>
12003 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12004 <filename>scp localpath root@ip:remotepath</filename>.
12005 </para></listitem>
12006 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12007 <filename>scp root@host:remotepath localpath</filename>.
12008 </para></listitem>
12009 </itemizedlist></para></listitem>
12010 </itemizedlist></para></listitem>
12011 </itemizedlist>
12012 </para>
12013 </section>
12014
12015 <section id='qemu-image-writing-tests-instance-attributes'>
12016 <title>Instance Attributes</title>
12017
12018 <para>
12019 A single instance attribute exists, which is
12020 <filename>target</filename>.
12021 The <filename>target</filename> instance attribute is
12022 identical to the class attribute of the same name, which
12023 is described in the previous section.
12024 This attribute exists as both an instance and class
12025 attribute so tests can use
12026 <filename>self.target.run(cmd)</filename> in instance
12027 methods instead of
12028 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12029 </para>
12030 </section>
12031 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012032
12033 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12034 <title>Installing Packages in the DUT Without the Package Manager</title>
12035
12036 <para>
12037 When a test requires a package built by BitBake, it is possible
12038 to install that package.
12039 Installing the package does not require a package manager be
12040 installed in the device under test (DUT).
12041 It does, however, require an SSH connection and the target must
12042 be using the <filename>sshcontrol</filename> class.
12043 <note>
12044 This method uses <filename>scp</filename> to copy files
12045 from the host to the target, which causes permissions and
12046 special attributes to be lost.
12047 </note>
12048 </para>
12049
12050 <para>
12051 A JSON file is used to define the packages needed by a test.
12052 This file must be in the same path as the file used to define
12053 the tests.
12054 Furthermore, the filename must map directly to the test
12055 module name with a <filename>.json</filename> extension.
12056 </para>
12057
12058 <para>
12059 The JSON file must include an object with the test name as
12060 keys of an object or an array.
12061 This object (or array of objects) uses the following data:
12062 <itemizedlist>
12063 <listitem><para>"pkg" - A mandatory string that is the
12064 name of the package to be installed.
12065 </para></listitem>
12066 <listitem><para>"rm" - An optional boolean, which defaults
12067 to "false", that specifies to remove the package after
12068 the test.
12069 </para></listitem>
12070 <listitem><para>"extract" - An optional boolean, which
12071 defaults to "false", that specifies if the package must
12072 be extracted from the package format.
12073 When set to "true", the package is not automatically
12074 installed into the DUT.
12075 </para></listitem>
12076 </itemizedlist>
12077 </para>
12078
12079 <para>
12080 Following is an example JSON file that handles test "foo"
12081 installing package "bar" and test "foobar" installing
12082 packages "foo" and "bar".
12083 Once the test is complete, the packages are removed from the
12084 DUT.
12085 <literallayout class='monospaced'>
12086 {
12087 "foo": {
12088 "pkg": "bar"
12089 },
12090 "foobar": [
12091 {
12092 "pkg": "foo",
12093 "rm": true
12094 },
12095 {
12096 "pkg": "bar",
12097 "rm": true
12098 }
12099 ]
12100 }
12101 </literallayout>
12102 </para>
12103 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012104 </section>
12105
Brad Bishop316dfdd2018-06-25 12:45:53 -040012106 <section id='usingpoky-debugging-tools-and-techniques'>
12107 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012108
12109 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012110 The exact method for debugging build failures depends on the nature
12111 of the problem and on the system's area from which the bug
12112 originates.
12113 Standard debugging practices such as comparison against the last
12114 known working version with examination of the changes and the
12115 re-application of steps to identify the one causing the problem are
12116 valid for the Yocto Project just as they are for any other system.
12117 Even though it is impossible to detail every possible potential
12118 failure, this section provides some general tips to aid in
12119 debugging given a variety of situations.
12120 <note><title>Tip</title>
12121 A useful feature for debugging is the error reporting tool.
12122 Configuring the Yocto Project to use this tool causes the
12123 OpenEmbedded build system to produce error reporting commands as
12124 part of the console output.
12125 You can enter the commands after the build completes to log
12126 error information into a common database, that can help you
12127 figure out what might be going wrong.
12128 For information on how to enable and use this feature, see the
12129 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12130 section.
12131 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012132 </para>
12133
12134 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012135 The following list shows the debugging topics in the remainder of
12136 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012137 <itemizedlist>
12138 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012139 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12140 describes how to find and view logs from tasks that
12141 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012142 </para></listitem>
12143 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012144 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12145 describes how to use the BitBake <filename>-e</filename>
12146 option to examine variable values after a recipe has been
12147 parsed.
12148 </para></listitem>
12149 <listitem><para>
12150 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12151 describes how to use the
12152 <filename>oe-pkgdata-util</filename> utility to query
12153 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12154 and display package-related information for built
12155 packages.
12156 </para></listitem>
12157 <listitem><para>
12158 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12159 describes how to use the BitBake <filename>-g</filename>
12160 option to display recipe dependency information used
12161 during the build.
12162 </para></listitem>
12163 <listitem><para>
12164 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12165 describes how to use the
12166 <filename>bitbake-dumpsig</filename> command in
12167 conjunction with key subdirectories in the
12168 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12169 to determine variable dependencies.
12170 </para></listitem>
12171 <listitem><para>
12172 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12173 describes how to use several BitBake options (e.g.
12174 <filename>-c</filename>, <filename>-C</filename>, and
12175 <filename>-f</filename>) to run specific tasks in the
12176 build chain.
12177 It can be useful to run tasks "out-of-order" when trying
12178 isolate build issues.
12179 </para></listitem>
12180 <listitem><para>
12181 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12182 describes how to use BitBake's <filename>-D</filename>
12183 debug output option to reveal more about what BitBake is
12184 doing during the build.
12185 </para></listitem>
12186 <listitem><para>
12187 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12188 describes how to use the BitBake <filename>-b</filename>
12189 option to build a recipe while ignoring dependencies.
12190 </para></listitem>
12191 <listitem><para>
12192 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12193 describes how to use the many recipe logging functions
12194 to produce debugging output and report errors and warnings.
12195 </para></listitem>
12196 <listitem><para>
12197 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12198 describes how to debug situations where the build consists
12199 of several parts that are run simultaneously and when the
12200 output or result of one part is not ready for use with a
12201 different part of the build that depends on that output.
12202 </para></listitem>
12203 <listitem><para>
12204 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12205 describes how to use GDB to allow you to examine running
12206 programs, which can help you fix problems.
12207 </para></listitem>
12208 <listitem><para>
12209 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12210 describes how to use GDB directly on target hardware for
12211 debugging.
12212 </para></listitem>
12213 <listitem><para>
12214 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12215 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012216 </para></listitem>
12217 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012218 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012219
12220 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012221 For debugging information within the popular
12222 <trademark class='trade'>Eclipse</trademark> IDE, see the
12223 "<ulink url='&YOCTO_DOCS_SDK_URL;#adt-eclipse'>Working within Eclipse</ulink>"
12224 section in the Yocto Project Application Development and the
12225 Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012226 </para>
12227
Brad Bishop316dfdd2018-06-25 12:45:53 -040012228 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12229 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012230
12231 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012232 You can find the log for a task in the file
12233 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12234 For example, the log for the
12235 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12236 task of the QEMU minimal image for the x86 machine
12237 (<filename>qemux86</filename>) might be in
12238 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12239 To see the commands
12240 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12241 ran to generate a log, look at the corresponding
12242 <filename>run.do_</filename><replaceable>taskname</replaceable>
12243 file in the same directory.
12244 </para>
12245
12246 <para>
12247 <filename>log.do_</filename><replaceable>taskname</replaceable>
12248 and
12249 <filename>run.do_</filename><replaceable>taskname</replaceable>
12250 are actually symbolic links to
12251 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12252 and
12253 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12254 where <replaceable>pid</replaceable> is the PID the task had
12255 when it ran.
12256 The symlinks always point to the files corresponding to the most
12257 recent run.
12258 </para>
12259 </section>
12260
12261 <section id='dev-debugging-viewing-variable-values'>
12262 <title>Viewing Variable Values</title>
12263
12264 <para>
12265 BitBake's <filename>-e</filename> option is used to display
12266 variable values after parsing.
12267 The following command displays the variable values after the
12268 configuration files (i.e. <filename>local.conf</filename>,
12269 <filename>bblayers.conf</filename>,
12270 <filename>bitbake.conf</filename> and so forth) have been
12271 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012272 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012273 $ bitbake -e
12274 </literallayout>
12275 The following command displays variable values after a specific
12276 recipe has been parsed.
12277 The variables include those from the configuration as well:
12278 <literallayout class='monospaced'>
12279 $ bitbake -e recipename
12280 </literallayout>
12281 <note><para>
12282 Each recipe has its own private set of variables
12283 (datastore).
12284 Internally, after parsing the configuration, a copy of the
12285 resulting datastore is made prior to parsing each recipe.
12286 This copying implies that variables set in one recipe will
12287 not be visible to other recipes.</para>
12288
12289 <para>Likewise, each task within a recipe gets a private
12290 datastore based on the recipe datastore, which means that
12291 variables set within one task will not be visible to
12292 other tasks.</para>
12293 </note>
12294 </para>
12295
12296 <para>
12297 In the output of <filename>bitbake -e</filename>, each
12298 variable is preceded by a description of how the variable
12299 got its value, including temporary values that were later
12300 overriden.
12301 This description also includes variable flags (varflags) set on
12302 the variable.
12303 The output can be very helpful during debugging.
12304 </para>
12305
12306 <para>
12307 Variables that are exported to the environment are preceded by
12308 <filename>export</filename> in the output of
12309 <filename>bitbake -e</filename>.
12310 See the following example:
12311 <literallayout class='monospaced'>
12312 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12313 </literallayout>
12314 </para>
12315
12316 <para>
12317 In addition to variable values, the output of the
12318 <filename>bitbake -e</filename> and
12319 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12320 commands includes the following information:
12321 <itemizedlist>
12322 <listitem><para>
12323 The output starts with a tree listing all configuration
12324 files and classes included globally, recursively listing
12325 the files they include or inherit in turn.
12326 Much of the behavior of the OpenEmbedded build system
12327 (including the behavior of the
12328 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12329 is implemented in the
12330 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12331 class and the classes it inherits, rather than being
12332 built into BitBake itself.
12333 </para></listitem>
12334 <listitem><para>
12335 After the variable values, all functions appear in the
12336 output.
12337 For shell functions, variables referenced within the
12338 function body are expanded.
12339 If a function has been modified using overrides or
12340 using override-style operators like
12341 <filename>_append</filename> and
12342 <filename>_prepend</filename>, then the final assembled
12343 function body appears in the output.
12344 </para></listitem>
12345 </itemizedlist>
12346 </para>
12347 </section>
12348
12349 <section id='viewing-package-information-with-oe-pkgdata-util'>
12350 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12351
12352 <para>
12353 You can use the <filename>oe-pkgdata-util</filename>
12354 command-line utility to query
12355 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12356 and display various package-related information.
12357 When you use the utility, you must use it to view information
12358 on packages that have already been built.
12359 </para>
12360
12361 <para>
12362 Following are a few of the available
12363 <filename>oe-pkgdata-util</filename> subcommands.
12364 <note>
12365 You can use the standard * and ? globbing wildcards as part
12366 of package names and paths.
12367 </note>
12368 <itemizedlist>
12369 <listitem><para>
12370 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12371 Lists all packages that have been built, optionally
12372 limiting the match to packages that match
12373 <replaceable>pattern</replaceable>.
12374 </para></listitem>
12375 <listitem><para>
12376 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12377 Lists the files and directories contained in the given
12378 packages.
12379 <note>
12380 <para>
12381 A different way to view the contents of a package is
12382 to look at the
12383 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12384 directory of the recipe that generates the
12385 package.
12386 This directory is created by the
12387 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12388 task and has one subdirectory for each package the
12389 recipe generates, which contains the files stored in
12390 that package.</para>
12391 <para>
12392 If you want to inspect the
12393 <filename>${WORKDIR}/packages-split</filename>
12394 directory, make sure that
12395 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12396 is not enabled when you build the recipe.
12397 </para>
12398 </note>
12399 </para></listitem>
12400 <listitem><para>
12401 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12402 Lists the names of the packages that contain the given
12403 paths.
12404 For example, the following tells us that
12405 <filename>/usr/share/man/man1/make.1</filename>
12406 is contained in the <filename>make-doc</filename>
12407 package:
12408 <literallayout class='monospaced'>
12409 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12410 make-doc: /usr/share/man/man1/make.1
12411 </literallayout>
12412 </para></listitem>
12413 <listitem><para>
12414 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12415 Lists the name of the recipes that
12416 produce the given packages.
12417 </para></listitem>
12418 </itemizedlist>
12419 </para>
12420
12421 <para>
12422 For more information on the <filename>oe-pkgdata-util</filename>
12423 command, use the help facility:
12424 <literallayout class='monospaced'>
12425 $ oe-pkgdata-util &dash;&dash;help
12426 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
12427 </literallayout>
12428 </para>
12429 </section>
12430
12431 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
12432 <title>Viewing Dependencies Between Recipes and Tasks</title>
12433
12434 <para>
12435 Sometimes it can be hard to see why BitBake wants to build other
12436 recipes before the one you have specified.
12437 Dependency information can help you understand why a recipe is
12438 built.
12439 </para>
12440
12441 <para>
12442 To generate dependency information for a recipe, run the
12443 following command:
12444 <literallayout class='monospaced'>
12445 $ bitbake -g <replaceable>recipename</replaceable>
12446 </literallayout>
12447 This command writes the following files in the current
12448 directory:
12449 <itemizedlist>
12450 <listitem><para>
12451 <filename>pn-buildlist</filename>: A list of
12452 recipes/targets involved in building
12453 <replaceable>recipename</replaceable>.
12454 "Involved" here means that at least one task from the
12455 recipe needs to run when building
12456 <replaceable>recipename</replaceable> from scratch.
12457 Targets that are in
12458 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
12459 are not listed.
12460 </para></listitem>
12461 <listitem><para>
12462 <filename>task-depends.dot</filename>: A graph showing
12463 dependencies between tasks.
12464 </para></listitem>
12465 </itemizedlist>
12466 </para>
12467
12468 <para>
12469 The graphs are in
12470 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
12471 format and can be converted to images (e.g. using the
12472 <filename>dot</filename> tool from
12473 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
12474 <note><title>Notes</title>
12475 <itemizedlist>
12476 <listitem><para>
12477 DOT files use a plain text format.
12478 The graphs generated using the
12479 <filename>bitbake -g</filename> command are often so
12480 large as to be difficult to read without special
12481 pruning (e.g. with Bitbake's
12482 <filename>-I</filename> option) and processing.
12483 Despite the form and size of the graphs, the
12484 corresponding <filename>.dot</filename> files can
12485 still be possible to read and provide useful
12486 information.
12487 </para>
12488
12489 <para>As an example, the
12490 <filename>task-depends.dot</filename> file contains
12491 lines such as the following:
12492 <literallayout class='monospaced'>
12493 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
12494 </literallayout>
12495 The above example line reveals that the
12496 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
12497 task in <filename>libxslt</filename> depends on the
12498 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
12499 task in <filename>libxml2</filename>, which is a
12500 normal
12501 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
12502 dependency between the two recipes.
12503 </para></listitem>
12504 <listitem><para>
12505 For an example of how <filename>.dot</filename>
12506 files can be processed, see the
12507 <filename>scripts/contrib/graph-tool</filename>
12508 Python script, which finds and displays paths
12509 between graph nodes.
12510 </para></listitem>
12511 </itemizedlist>
12512 </note>
12513 </para>
12514
12515 <para>
12516 You can use a different method to view dependency information
12517 by using the following command:
12518 <literallayout class='monospaced'>
12519 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
12520 </literallayout>
12521 This command displays a GUI window from which you can view
12522 build-time and runtime dependencies for the recipes involved in
12523 building <replaceable>recipename</replaceable>.
12524 </para>
12525 </section>
12526
12527 <section id='dev-viewing-task-variable-dependencies'>
12528 <title>Viewing Task Variable Dependencies</title>
12529
12530 <para>
12531 As mentioned in the
12532 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
12533 section of the BitBake User Manual, BitBake tries to
12534 automatically determine what variables a task depends on so
12535 that it can rerun the task if any values of the variables
12536 change.
12537 This determination is usually reliable.
12538 However, if you do things like construct variable names at
12539 runtime, then you might have to manually declare dependencies
12540 on those variables using <filename>vardeps</filename> as
12541 described in the
12542 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
12543 section of the BitBake User Manual.
12544 </para>
12545
12546 <para>
12547 If you are unsure whether a variable dependency is being
12548 picked up automatically for a given task, you can list the
12549 variable dependencies BitBake has determined by doing the
12550 following:
12551 <orderedlist>
12552 <listitem><para>
12553 Build the recipe containing the task:
12554 <literallayout class='monospaced'>
12555 $ bitbake <replaceable>recipename</replaceable>
12556 </literallayout>
12557 </para></listitem>
12558 <listitem><para>
12559 Inside the
12560 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
12561 directory, find the signature data
12562 (<filename>sigdata</filename>) file that corresponds
12563 to the task.
12564 The <filename>sigdata</filename> files contain a pickled
12565 Python database of all the metadata that went into
12566 creating the input checksum for the task.
12567 As an example, for the
12568 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
12569 task of the <filename>db</filename> recipe, the
12570 <filename>sigdata</filename> file might be found in the
12571 following location:
12572 <literallayout class='monospaced'>
12573 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12574 </literallayout>
12575 For tasks that are accelerated through the shared state
12576 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
12577 cache, an additional <filename>siginfo</filename> file
12578 is written into
12579 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
12580 along with the cached task output.
12581 The <filename>siginfo</filename> files contain exactly
12582 the same information as <filename>sigdata</filename>
12583 files.
12584 </para></listitem>
12585 <listitem><para>
12586 Run <filename>bitbake-dumpsig</filename> on the
12587 <filename>sigdata</filename> or
12588 <filename>siginfo</filename> file.
12589 Here is an example:
12590 <literallayout class='monospaced'>
12591 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12592 </literallayout>
12593 In the output of the above command, you will find a
12594 line like the following, which lists all the (inferred)
12595 variable dependencies for the task.
12596 This list also includes indirect dependencies from
12597 variables depending on other variables, recursively.
12598 <literallayout class='monospaced'>
12599 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
12600 </literallayout>
12601 <note>
12602 Functions (e.g. <filename>base_do_fetch</filename>)
12603 also count as variable dependencies.
12604 These functions in turn depend on the variables they
12605 reference.
12606 </note>
12607 The output of <filename>bitbake-dumpsig</filename> also
12608 includes the value each variable had, a list of
12609 dependencies for each variable, and
12610 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
12611 information.
12612 </para></listitem>
12613 </orderedlist>
12614 </para>
12615
12616 <para>
12617 There is also a <filename>bitbake-diffsigs</filename> command
12618 for comparing two <filename>siginfo</filename> or
12619 <filename>sigdata</filename> files.
12620 This command can be helpful when trying to figure out what
12621 changed between two versions of a task.
12622 If you call <filename>bitbake-diffsigs</filename> with just one
12623 file, the command behaves like
12624 <filename>bitbake-dumpsig</filename>.
12625 </para>
12626
12627 <para>
12628 You can also use BitBake to dump out the signature construction
12629 information without executing tasks by using either of the
12630 following BitBake command-line options:
12631 <literallayout class='monospaced'>
12632 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
12633 -S <replaceable>SIGNATURE_HANDLER</replaceable>
12634 </literallayout>
12635 <note>
12636 Two common values for
12637 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
12638 "printdiff", which dump only the signature or compare the
12639 dumped signature with the cached one, respectively.
12640 </note>
12641 Using BitBake with either of these options causes BitBake to
12642 dump out <filename>sigdata</filename> files in the
12643 <filename>stamps</filename> directory for every task it would
12644 have executed instead of building the specified target package.
12645 </para>
12646 </section>
12647
12648 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
12649 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
12650
12651 <para>
12652 Seeing what metadata went into creating the input signature
12653 of a shared state (sstate) task can be a useful debugging
12654 aid.
12655 This information is available in signature information
12656 (<filename>siginfo</filename>) files in
12657 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
12658 For information on how to view and interpret information in
12659 <filename>siginfo</filename> files, see the
12660 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12661 section.
12662 </para>
12663
12664 <para>
12665 For conceptual information on shared state, see the
12666 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
12667 section in the Yocto Project Overview and Concepts Manual.
12668 </para>
12669 </section>
12670
12671 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
12672 <title>Invalidating Shared State to Force a Task to Run</title>
12673
12674 <para>
12675 The OpenEmbedded build system uses
12676 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
12677 and
12678 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
12679 cache to avoid unnecessarily rebuilding tasks.
12680 Collectively, this scheme is known as "shared state code."
12681 </para>
12682
12683 <para>
12684 As with all schemes, this one has some drawbacks.
12685 It is possible that you could make implicit changes to your
12686 code that the checksum calculations do not take into
12687 account.
12688 These implicit changes affect a task's output but do not
12689 trigger the shared state code into rebuilding a recipe.
12690 Consider an example during which a tool changes its output.
12691 Assume that the output of <filename>rpmdeps</filename>
12692 changes.
12693 The result of the change should be that all the
12694 <filename>package</filename> and
12695 <filename>package_write_rpm</filename> shared state cache
12696 items become invalid.
12697 However, because the change to the output is
12698 external to the code and therefore implicit,
12699 the associated shared state cache items do not become
12700 invalidated.
12701 In this case, the build process uses the cached items
12702 rather than running the task again.
12703 Obviously, these types of implicit changes can cause
12704 problems.
12705 </para>
12706
12707 <para>
12708 To avoid these problems during the build, you need to
12709 understand the effects of any changes you make.
12710 Realize that changes you make directly to a function
12711 are automatically factored into the checksum calculation.
12712 Thus, these explicit changes invalidate the associated
12713 area of shared state cache.
12714 However, you need to be aware of any implicit changes that
12715 are not obvious changes to the code and could affect
12716 the output of a given task.
12717 </para>
12718
12719 <para>
12720 When you identify an implicit change, you can easily
12721 take steps to invalidate the cache and force the tasks
12722 to run.
12723 The steps you can take are as simple as changing a
12724 function's comments in the source code.
12725 For example, to invalidate package shared state files,
12726 change the comment statements of
12727 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12728 or the comments of one of the functions it calls.
12729 Even though the change is purely cosmetic, it causes the
12730 checksum to be recalculated and forces the build system to
12731 run the task again.
12732 <note>
12733 For an example of a commit that makes a cosmetic
12734 change to invalidate shared state, see this
12735 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
12736 </note>
12737 </para>
12738 </section>
12739
12740 <section id='dev-debugging-taskrunning'>
12741 <title>Running Specific Tasks</title>
12742
12743 <para>
12744 Any given recipe consists of a set of tasks.
12745 The standard BitBake behavior in most cases is:
12746 <filename>do_fetch</filename>,
12747 <filename>do_unpack</filename>,
12748 <filename>do_patch</filename>,
12749 <filename>do_configure</filename>,
12750 <filename>do_compile</filename>,
12751 <filename>do_install</filename>,
12752 <filename>do_package</filename>,
12753 <filename>do_package_write_*</filename>, and
12754 <filename>do_build</filename>.
12755 The default task is <filename>do_build</filename> and any tasks
12756 on which it depends build first.
12757 Some tasks, such as <filename>do_devshell</filename>, are not
12758 part of the default build chain.
12759 If you wish to run a task that is not part of the default build
12760 chain, you can use the <filename>-c</filename> option in
12761 BitBake.
12762 Here is an example:
12763 <literallayout class='monospaced'>
12764 $ bitbake matchbox-desktop -c devshell
12765 </literallayout>
12766 </para>
12767
12768 <para>
12769 The <filename>-c</filename> option respects task dependencies,
12770 which means that all other tasks (including tasks from other
12771 recipes) that the specified task depends on will be run before
12772 the task.
12773 Even when you manually specify a task to run with
12774 <filename>-c</filename>, BitBake will only run the task if it
12775 considers it "out of date".
12776 See the
12777 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
12778 section in the Yocto Project Overview and Concepts Manual for
12779 how BitBake determines whether a task is "out of date".
12780 </para>
12781
12782 <para>
12783 If you want to force an up-to-date task to be rerun (e.g.
12784 because you made manual modifications to the recipe's
12785 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
12786 that you want to try out), then you can use the
12787 <filename>-f</filename> option.
12788 <note>
12789 The reason <filename>-f</filename> is never required when
12790 running the
12791 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
12792 task is because the
12793 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
12794 variable flag is already set for the task.
12795 </note>
12796 The following example shows one way you can use the
12797 <filename>-f</filename> option:
12798 <literallayout class='monospaced'>
12799 $ bitbake matchbox-desktop
12800 .
12801 .
12802 make some changes to the source code in the work directory
12803 .
12804 .
12805 $ bitbake matchbox-desktop -c compile -f
12806 $ bitbake matchbox-desktop
12807 </literallayout>
12808 </para>
12809
12810 <para>
12811 This sequence first builds and then recompiles
12812 <filename>matchbox-desktop</filename>.
12813 The last command reruns all tasks (basically the packaging
12814 tasks) after the compile.
12815 BitBake recognizes that the <filename>do_compile</filename>
12816 task was rerun and therefore understands that the other tasks
12817 also need to be run again.
12818 </para>
12819
12820 <para>
12821 Another, shorter way to rerun a task and all
12822 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
12823 that depend on it is to use the <filename>-C</filename>
12824 option.
12825 <note>
12826 This option is upper-cased and is separate from the
12827 <filename>-c</filename> option, which is lower-cased.
12828 </note>
12829 Using this option invalidates the given task and then runs the
12830 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
12831 task, which is the default task if no task is given, and the
12832 tasks on which it depends.
12833 You could replace the final two commands in the previous example
12834 with the following single command:
12835 <literallayout class='monospaced'>
12836 $ bitbake matchbox-desktop -C compile
12837 </literallayout>
12838 Internally, the <filename>-f</filename> and
12839 <filename>-C</filename> options work by tainting (modifying) the
12840 input checksum of the specified task.
12841 This tainting indirectly causes the task and its
12842 dependent tasks to be rerun through the normal task dependency
12843 mechanisms.
12844 <note>
12845 BitBake explicitly keeps track of which tasks have been
12846 tainted in this fashion, and will print warnings such as the
12847 following for builds involving such tasks:
12848 <literallayout class='monospaced'>
12849 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
12850 </literallayout>
12851 The purpose of the warning is to let you know that the work
12852 directory and build output might not be in the clean state
12853 they would be in for a "normal" build, depending on what
12854 actions you took.
12855 To get rid of such warnings, you can remove the work
12856 directory and rebuild the recipe, as follows:
12857 <literallayout class='monospaced'>
12858 $ bitbake matchbox-desktop -c clean
12859 $ bitbake matchbox-desktop
12860 </literallayout>
12861 </note>
12862 </para>
12863
12864 <para>
12865 You can view a list of tasks in a given package by running the
12866 <filename>do_listtasks</filename> task as follows:
12867 <literallayout class='monospaced'>
12868 $ bitbake matchbox-desktop -c listtasks
12869 </literallayout>
12870 The results appear as output to the console and are also in the
12871 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
12872 </para>
12873 </section>
12874
12875 <section id='dev-debugging-bitbake'>
12876 <title>General BitBake Problems</title>
12877
12878 <para>
12879 You can see debug output from BitBake by using the
12880 <filename>-D</filename> option.
12881 The debug output gives more information about what BitBake
12882 is doing and the reason behind it.
12883 Each <filename>-D</filename> option you use increases the
12884 logging level.
12885 The most common usage is <filename>-DDD</filename>.
12886 </para>
12887
12888 <para>
12889 The output from
12890 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
12891 can reveal why BitBake chose a certain version of a package or
12892 why BitBake picked a certain provider.
12893 This command could also help you in a situation where you think
12894 BitBake did something unexpected.
12895 </para>
12896 </section>
12897
12898 <section id='dev-debugging-buildfile'>
12899 <title>Building with No Dependencies</title>
12900
12901 <para>
12902 To build a specific recipe (<filename>.bb</filename> file),
12903 you can use the following command form:
12904 <literallayout class='monospaced'>
12905 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
12906 </literallayout>
12907 This command form does not check for dependencies.
12908 Consequently, you should use it only when you know existing
12909 dependencies have been met.
12910 <note>
12911 You can also specify fragments of the filename.
12912 In this case, BitBake checks for a unique match.
12913 </note>
12914 </para>
12915 </section>
12916
12917 <section id='recipe-logging-mechanisms'>
12918 <title>Recipe Logging Mechanisms</title>
12919
12920 <para>
12921 The Yocto Project provides several logging functions for
12922 producing debugging output and reporting errors and warnings.
12923 For Python functions, the following logging functions exist.
12924 All of these functions log to
12925 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
12926 and can also log to standard output (stdout) with the right
12927 settings:
12928 <itemizedlist>
12929 <listitem><para>
12930 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
12931 Writes <replaceable>msg</replaceable> as is to the
12932 log while also logging to stdout.
12933 </para></listitem>
12934 <listitem><para>
12935 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
12936 Writes "NOTE: <replaceable>msg</replaceable>" to the
12937 log.
12938 Also logs to stdout if BitBake is called with "-v".
12939 </para></listitem>
12940 <listitem><para>
12941 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
12942 Writes "DEBUG: <replaceable>msg</replaceable>" to the
12943 log.
12944 Also logs to stdout if the log level is greater than or
12945 equal to <replaceable>level</replaceable>.
12946 See the
12947 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
12948 option in the BitBake User Manual for more information.
12949 </para></listitem>
12950 <listitem><para>
12951 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
12952 Writes "WARNING: <replaceable>msg</replaceable>" to the
12953 log while also logging to stdout.
12954 </para></listitem>
12955 <listitem><para>
12956 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
12957 Writes "ERROR: <replaceable>msg</replaceable>" to the
12958 log while also logging to standard out (stdout).
12959 <note>
12960 Calling this function does not cause the task to fail.
12961 </note>
12962 </para></listitem>
12963 <listitem><para>
12964 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
12965 This logging function is similar to
12966 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
12967 but also causes the calling task to fail.
12968 <note>
12969 <filename>bb.fatal()</filename> raises an exception,
12970 which means you do not need to put a "return"
12971 statement after the function.
12972 </note>
12973 </para></listitem>
12974 </itemizedlist>
12975 </para>
12976
12977 <para>
12978 The same logging functions are also available in shell
12979 functions, under the names
12980 <filename>bbplain</filename>, <filename>bbnote</filename>,
12981 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
12982 <filename>bberror</filename>, and <filename>bbfatal</filename>.
12983 The
12984 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
12985 class implements these functions.
12986 See that class in the
12987 <filename>meta/classes</filename> folder of the
12988 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
12989 for information.
12990 </para>
12991
12992 <section id='logging-with-python'>
12993 <title>Logging With Python</title>
12994
12995 <para>
12996 When creating recipes using Python and inserting code that
12997 handles build logs, keep in mind the goal is to have
12998 informative logs while keeping the console as "silent" as
12999 possible.
13000 Also, if you want status messages in the log, use the
13001 "debug" loglevel.
13002 </para>
13003
13004 <para>
13005 Following is an example written in Python.
13006 The code handles logging for a function that determines the
13007 number of tasks needed to be run.
13008 See the
13009 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13010 section for additional information:
13011 <literallayout class='monospaced'>
13012 python do_listtasks() {
13013 bb.debug(2, "Starting to figure out the task list")
13014 if noteworthy_condition:
13015 bb.note("There are 47 tasks to run")
13016 bb.debug(2, "Got to point xyz")
13017 if warning_trigger:
13018 bb.warn("Detected warning_trigger, this might be a problem later.")
13019 if recoverable_error:
13020 bb.error("Hit recoverable_error, you really need to fix this!")
13021 if fatal_error:
13022 bb.fatal("fatal_error detected, unable to print the task list")
13023 bb.plain("The tasks present are abc")
13024 bb.debug(2, "Finished figuring out the tasklist")
13025 }
13026 </literallayout>
13027 </para>
13028 </section>
13029
13030 <section id='logging-with-bash'>
13031 <title>Logging With Bash</title>
13032
13033 <para>
13034 When creating recipes using Bash and inserting code that
13035 handles build logs, you have the same goals - informative
13036 with minimal console output.
13037 The syntax you use for recipes written in Bash is similar
13038 to that of recipes written in Python described in the
13039 previous section.
13040 </para>
13041
13042 <para>
13043 Following is an example written in Bash.
13044 The code logs the progress of the <filename>do_my_function</filename> function.
13045 <literallayout class='monospaced'>
13046 do_my_function() {
13047 bbdebug 2 "Running do_my_function"
13048 if [ exceptional_condition ]; then
13049 bbnote "Hit exceptional_condition"
13050 fi
13051 bbdebug 2 "Got to point xyz"
13052 if [ warning_trigger ]; then
13053 bbwarn "Detected warning_trigger, this might cause a problem later."
13054 fi
13055 if [ recoverable_error ]; then
13056 bberror "Hit recoverable_error, correcting"
13057 fi
13058 if [ fatal_error ]; then
13059 bbfatal "fatal_error detected"
13060 fi
13061 bbdebug 2 "Completed do_my_function"
13062 }
13063 </literallayout>
13064 </para>
13065 </section>
13066 </section>
13067
13068 <section id='debugging-parallel-make-races'>
13069 <title>Debugging Parallel Make Races</title>
13070
13071 <para>
13072 A parallel <filename>make</filename> race occurs when the build
13073 consists of several parts that are run simultaneously and
13074 a situation occurs when the output or result of one
13075 part is not ready for use with a different part of the build
13076 that depends on that output.
13077 Parallel make races are annoying and can sometimes be difficult
13078 to reproduce and fix.
13079 However, some simple tips and tricks exist that can help
13080 you debug and fix them.
13081 This section presents a real-world example of an error
13082 encountered on the Yocto Project autobuilder and the process
13083 used to fix it.
13084 <note>
13085 If you cannot properly fix a <filename>make</filename> race
13086 condition, you can work around it by clearing either the
13087 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13088 or
13089 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13090 variables.
13091 </note>
13092 </para>
13093
13094 <section id='the-failure'>
13095 <title>The Failure</title>
13096
13097 <para>
13098 For this example, assume that you are building an image that
13099 depends on the "neard" package.
13100 And, during the build, BitBake runs into problems and
13101 creates the following output.
13102 <note>
13103 This example log file has longer lines artificially
13104 broken to make the listing easier to read.
13105 </note>
13106 If you examine the output or the log file, you see the
13107 failure during <filename>make</filename>:
13108 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013109 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13110 | DEBUG: Executing shell function do_compile
13111 | NOTE: make -j 16
13112 | make --no-print-directory all-am
13113 | /bin/mkdir -p include/near
13114 | /bin/mkdir -p include/near
13115 | /bin/mkdir -p include/near
13116 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13117 0.14-r0/neard-0.14/include/types.h include/near/types.h
13118 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13119 0.14-r0/neard-0.14/include/log.h include/near/log.h
13120 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13121 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13122 | /bin/mkdir -p include/near
13123 | /bin/mkdir -p include/near
13124 | /bin/mkdir -p include/near
13125 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13126 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13127 | /bin/mkdir -p include/near
13128 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13129 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13130 | /bin/mkdir -p include/near
13131 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13132 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13133 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13134 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13135 | /bin/mkdir -p include/near
13136 | /bin/mkdir -p include/near
13137 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13138 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13139 | /bin/mkdir -p include/near
13140 | /bin/mkdir -p include/near
13141 | /bin/mkdir -p include/near
13142 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13143 0.14-r0/neard-0.14/include/device.h include/near/device.h
13144 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13145 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13146 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13147 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13148 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13149 0.14-r0/neard-0.14/include/version.h include/near/version.h
13150 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13151 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13152 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13153 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13154 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13155 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13156 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13157 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13158 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13159 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13160 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13161 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13162 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13163 -o tools/snep-send.o tools/snep-send.c
13164 | In file included from tools/snep-send.c:16:0:
13165 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13166 | #include &lt;near/dbus.h&gt;
13167 | ^
13168 | compilation terminated.
13169 | make[1]: *** [tools/snep-send.o] Error 1
13170 | make[1]: *** Waiting for unfinished jobs....
13171 | make: *** [all] Error 2
13172 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013173 </literallayout>
13174 </para>
13175 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013176
Brad Bishop316dfdd2018-06-25 12:45:53 -040013177 <section id='reproducing-the-error'>
13178 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013179
Brad Bishop316dfdd2018-06-25 12:45:53 -040013180 <para>
13181 Because race conditions are intermittent, they do not
13182 manifest themselves every time you do the build.
13183 In fact, most times the build will complete without problems
13184 even though the potential race condition exists.
13185 Thus, once the error surfaces, you need a way to reproduce
13186 it.
13187 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013188
Brad Bishop316dfdd2018-06-25 12:45:53 -040013189 <para>
13190 In this example, compiling the "neard" package is causing
13191 the problem.
13192 So the first thing to do is build "neard" locally.
13193 Before you start the build, set the
13194 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13195 variable in your <filename>local.conf</filename> file to
13196 a high number (e.g. "-j 20").
13197 Using a high value for <filename>PARALLEL_MAKE</filename>
13198 increases the chances of the race condition showing up:
13199 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013200 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013201 </literallayout>
13202 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013203
Brad Bishop316dfdd2018-06-25 12:45:53 -040013204 <para>
13205 Once the local build for "neard" completes, start a
13206 <filename>devshell</filename> build:
13207 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013208 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013209 </literallayout>
13210 For information on how to use a
13211 <filename>devshell</filename>, see the
13212 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13213 section.
13214 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013215
Brad Bishop316dfdd2018-06-25 12:45:53 -040013216 <para>
13217 In the <filename>devshell</filename>, do the following:
13218 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013219 $ make clean
13220 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013221 </literallayout>
13222 The <filename>devshell</filename> commands cause the failure
13223 to clearly be visible.
13224 In this case, a missing dependency exists for the "neard"
13225 Makefile target.
13226 Here is some abbreviated, sample output with the
13227 missing dependency clearly visible at the end:
13228 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013229 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13230 .
13231 .
13232 .
13233 tools/snep-send.c
13234 In file included from tools/snep-send.c:16:0:
13235 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13236 #include &lt;near/dbus.h&gt;
13237 ^
13238 compilation terminated.
13239 make: *** [tools/snep-send.o] Error 1
13240 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013241 </literallayout>
13242 </para>
13243 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013244
Brad Bishop316dfdd2018-06-25 12:45:53 -040013245 <section id='creating-a-patch-for-the-fix'>
13246 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013247
Brad Bishop316dfdd2018-06-25 12:45:53 -040013248 <para>
13249 Because there is a missing dependency for the Makefile
13250 target, you need to patch the
13251 <filename>Makefile.am</filename> file, which is generated
13252 from <filename>Makefile.in</filename>.
13253 You can use Quilt to create the patch:
13254 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013255 $ quilt new parallelmake.patch
13256 Patch patches/parallelmake.patch is now on top
13257 $ quilt add Makefile.am
13258 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013259 </literallayout>
13260 For more information on using Quilt, see the
13261 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13262 section.
13263 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013264
Brad Bishop316dfdd2018-06-25 12:45:53 -040013265 <para>
13266 At this point you need to make the edits to
13267 <filename>Makefile.am</filename> to add the missing
13268 dependency.
13269 For our example, you have to add the following line
13270 to the file:
13271 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013272 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013273 </literallayout>
13274 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013275
Brad Bishop316dfdd2018-06-25 12:45:53 -040013276 <para>
13277 Once you have edited the file, use the
13278 <filename>refresh</filename> command to create the patch:
13279 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013280 $ quilt refresh
13281 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013282 </literallayout>
13283 Once the patch file exists, you need to add it back to the
13284 originating recipe folder.
13285 Here is an example assuming a top-level
13286 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13287 named <filename>poky</filename>:
13288 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013289 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013290 </literallayout>
13291 The final thing you need to do to implement the fix in the
13292 build is to update the "neard" recipe (i.e.
13293 <filename>neard-0.14.bb</filename>) so that the
13294 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13295 statement includes the patch file.
13296 The recipe file is in the folder above the patch.
13297 Here is what the edited <filename>SRC_URI</filename>
13298 statement would look like:
13299 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013300 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13301 file://neard.in \
13302 file://neard.service.in \
13303 file://parallelmake.patch \
13304 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013305 </literallayout>
13306 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013307
Brad Bishop316dfdd2018-06-25 12:45:53 -040013308 <para>
13309 With the patch complete and moved to the correct folder and
13310 the <filename>SRC_URI</filename> statement updated, you can
13311 exit the <filename>devshell</filename>:
13312 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013313 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013314 </literallayout>
13315 </para>
13316 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013317
Brad Bishop316dfdd2018-06-25 12:45:53 -040013318 <section id='testing-the-build'>
13319 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013320
Brad Bishop316dfdd2018-06-25 12:45:53 -040013321 <para>
13322 With everything in place, you can get back to trying the
13323 build again locally:
13324 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013325 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013326 </literallayout>
13327 This build should succeed.
13328 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013329
Brad Bishop316dfdd2018-06-25 12:45:53 -040013330 <para>
13331 Now you can open up a <filename>devshell</filename> again
13332 and repeat the clean and make operations as follows:
13333 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013334 $ bitbake neard -c devshell
13335 $ make clean
13336 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013337 </literallayout>
13338 The build should work without issue.
13339 </para>
13340
13341 <para>
13342 As with all solved problems, if they originated upstream,
13343 you need to submit the fix for the recipe in OE-Core and
13344 upstream so that the problem is taken care of at its
13345 source.
13346 See the
13347 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13348 section for more information.
13349 </para>
13350 </section>
13351 </section>
13352
13353 <section id="platdev-gdb-remotedebug">
13354 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13355
13356 <para>
13357 GDB allows you to examine running programs, which in turn helps
13358 you to understand and fix problems.
13359 It also allows you to perform post-mortem style analysis of
13360 program crashes.
13361 GDB is available as a package within the Yocto Project and is
13362 installed in SDK images by default.
13363 See the
13364 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13365 chapter in the Yocto Project Reference Manual for a description of
13366 these images.
13367 You can find information on GDB at
13368 <ulink url="http://sourceware.org/gdb/"/>.
13369 <note><title>Tip</title>
13370 For best results, install debug (<filename>-dbg</filename>)
13371 packages for the applications you are going to debug.
13372 Doing so makes extra debug symbols available that give you
13373 more meaningful output.
13374 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013375 </para>
13376
13377 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013378 Sometimes, due to memory or disk space constraints, it is not
13379 possible to use GDB directly on the remote target to debug
13380 applications.
13381 These constraints arise because GDB needs to load the debugging
13382 information and the binaries of the process being debugged.
13383 Additionally, GDB needs to perform many computations to locate
13384 information such as function names, variable names and values,
13385 stack traces and so forth - even before starting the debugging
13386 process.
13387 These extra computations place more load on the target system
13388 and can alter the characteristics of the program being debugged.
13389 </para>
13390
13391 <para>
13392 To help get past the previously mentioned constraints, you can
13393 use gdbserver, which runs on the remote target and does not
13394 load any debugging information from the debugged process.
13395 Instead, a GDB instance processes the debugging information that
13396 is run on a remote computer - the host GDB.
13397 The host GDB then sends control commands to gdbserver to make
13398 it stop or start the debugged program, as well as read or write
13399 memory regions of that debugged program.
13400 All the debugging information loaded and processed as well
13401 as all the heavy debugging is done by the host GDB.
13402 Offloading these processes gives the gdbserver running on the
13403 target a chance to remain small and fast.
13404 </para>
13405
13406 <para>
13407 Because the host GDB is responsible for loading the debugging
13408 information and for doing the necessary processing to make
13409 actual debugging happen, you have to make sure the host can
13410 access the unstripped binaries complete with their debugging
13411 information and also be sure the target is compiled with no
13412 optimizations.
13413 The host GDB must also have local access to all the libraries
13414 used by the debugged program.
13415 Because gdbserver does not need any local debugging information,
13416 the binaries on the remote target can remain stripped.
13417 However, the binaries must also be compiled without optimization
13418 so they match the host's binaries.
13419 </para>
13420
13421 <para>
13422 To remain consistent with GDB documentation and terminology,
13423 the binary being debugged on the remote target machine is
13424 referred to as the "inferior" binary.
13425 For documentation on GDB see the
13426 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
13427 </para>
13428
13429 <para>
13430 The following steps show you how to debug using the GNU project
13431 debugger.
13432 <orderedlist>
13433 <listitem><para>
13434 <emphasis>Configure your build system to construct the
13435 companion debug filesystem:</emphasis></para>
13436
13437 <para>In your <filename>local.conf</filename> file, set
13438 the following:
13439 <literallayout class='monospaced'>
13440 IMAGE_GEN_DEBUGFS = "1"
13441 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
13442 </literallayout>
13443 These options cause the OpenEmbedded build system
13444 to generate a special companion filesystem fragment,
13445 which contains the matching source and debug symbols to
13446 your deployable filesystem.
13447 The build system does this by looking at what is in the
13448 deployed filesystem, and pulling the corresponding
13449 <filename>-dbg</filename> packages.</para>
13450
13451 <para>The companion debug filesystem is not a complete
13452 filesystem, but only contains the debug fragments.
13453 This filesystem must be combined with the full filesystem
13454 for debugging.
13455 Subsequent steps in this procedure show how to combine
13456 the partial filesystem with the full filesystem.
13457 </para></listitem>
13458 <listitem><para>
13459 <emphasis>Configure the system to include gdbserver in
13460 the target filesystem:</emphasis></para>
13461
13462 <para>Make the following addition in either your
13463 <filename>local.conf</filename> file or in an image
13464 recipe:
13465 <literallayout class='monospaced'>
13466 IMAGE_INSTALL_append = “ gdbserver"
13467 </literallayout>
13468 The change makes sure the <filename>gdbserver</filename>
13469 package is included.
13470 </para></listitem>
13471 <listitem><para>
13472 <emphasis>Build the environment:</emphasis></para>
13473
13474 <para>Use the following command to construct the image
13475 and the companion Debug Filesystem:
13476 <literallayout class='monospaced'>
13477 $ bitbake <replaceable>image</replaceable>
13478 </literallayout>
13479 Build the cross GDB component and make it available
13480 for debugging.
13481 Build the SDK that matches the image.
13482 Building the SDK is best for a production build
13483 that can be used later for debugging, especially
13484 during long term maintenance:
13485 <literallayout class='monospaced'>
13486 $ bitbake -c populate_sdk <replaceable>image</replaceable>
13487 </literallayout></para>
13488
13489 <para>Alternatively, you can build the minimal
13490 toolchain components that match the target.
13491 Doing so creates a smaller than typical SDK and only
13492 contains a minimal set of components with which to
13493 build simple test applications, as well as run the
13494 debugger:
13495 <literallayout class='monospaced'>
13496 $ bitbake meta-toolchain
13497 </literallayout></para>
13498
13499 <para>A final method is to build Gdb itself within
13500 the build system:
13501 <literallayout class='monospaced'>
13502 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
13503 </literallayout>
13504 Doing so produces a temporary copy of
13505 <filename>cross-gdb</filename> you can use for
13506 debugging during development.
13507 While this is the quickest approach, the two previous
13508 methods in this step are better when considering
13509 long-term maintenance strategies.
13510 <note>
13511 If you run
13512 <filename>bitbake gdb-cross</filename>, the
13513 OpenEmbedded build system suggests the actual
13514 image (e.g. <filename>gdb-cross-i586</filename>).
13515 The suggestion is usually the actual name you want
13516 to use.
13517 </note>
13518 </para></listitem>
13519 <listitem><para>
13520 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
13521
13522 <para>Run the following commands to set up the
13523 <filename>debugfs</filename>:
13524 <literallayout class='monospaced'>
13525 $ mkdir debugfs
13526 $ cd debugfs
13527 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
13528 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
13529 </literallayout>
13530 </para></listitem>
13531 <listitem><para>
13532 <emphasis>Set up GDB</emphasis></para>
13533
13534 <para>Install the SDK (if you built one) and then
13535 source the correct environment file.
13536 Sourcing the environment file puts the SDK in your
13537 <filename>PATH</filename> environment variable.</para>
13538
13539 <para>If you are using the build system, Gdb is
13540 located in
13541 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
13542 </para></listitem>
13543 <listitem><para>
13544 <emphasis>Boot the target:</emphasis></para>
13545
13546 <para>For information on how to run QEMU, see the
13547 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
13548 <note>
13549 Be sure to verify that your host can access the
13550 target via TCP.
13551 </note>
13552 </para></listitem>
13553 <listitem><para>
13554 <emphasis>Debug a program:</emphasis></para>
13555
13556 <para>Debugging a program involves running gdbserver
13557 on the target and then running Gdb on the host.
13558 The example in this step debugs
13559 <filename>gzip</filename>:
13560 <literallayout class='monospaced'>
13561 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
13562 </literallayout>
13563 For additional gdbserver options, see the
13564 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
13565 </para>
13566
13567 <para>After running gdbserver on the target, you need
13568 to run Gdb on the host and configure it and connect to
13569 the target.
13570 Use these commands:
13571 <literallayout class='monospaced'>
13572 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
13573 $ <replaceable>arch</replaceable>-gdb
13574
13575 (gdb) set sysroot debugfs
13576 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
13577 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
13578 </literallayout>
13579 At this point, everything should automatically load
13580 (i.e. matching binaries, symbols and headers).
13581 <note>
13582 The Gdb <filename>set</filename> commands in the
13583 previous example can be placed into the users
13584 <filename>~/.gdbinit</filename> file.
13585 Upon starting, Gdb automatically runs whatever
13586 commands are in that file.
13587 </note>
13588 </para></listitem>
13589 <listitem><para>
13590 <emphasis>Deploying without a full image
13591 rebuild:</emphasis></para>
13592
13593 <para>In many cases, during development you want a
13594 quick method to deploy a new binary to the target and
13595 debug it, without waiting for a full image build.
13596 </para>
13597
13598 <para>One approach to solving this situation is to
13599 just build the component you want to debug.
13600 Once you have built the component, copy the
13601 executable directly to both the target and the
13602 host <filename>debugfs</filename>.</para>
13603
13604 <para>If the binary is processed through the debug
13605 splitting in OpenEmbedded, you should also
13606 copy the debug items (i.e. <filename>.debug</filename>
13607 contents and corresponding
13608 <filename>/usr/src/debug</filename> files)
13609 from the work directory.
13610 Here is an example:
13611 <literallayout class='monospaced'>
13612 $ bitbake bash
13613 $ bitbake -c devshell bash
13614 $ cd ..
13615 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
13616 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
13617 </literallayout>
13618 </para></listitem>
13619 </orderedlist>
13620 </para>
13621 </section>
13622
13623 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
13624 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
13625
13626 <para>
13627 The previous section addressed using GDB remotely for debugging
13628 purposes, which is the most usual case due to the inherent
13629 hardware limitations on many embedded devices.
13630 However, debugging in the target hardware itself is also
13631 possible with more powerful devices.
13632 This section describes what you need to do in order to support
13633 using GDB to debug on the target hardware.
13634 </para>
13635
13636 <para>
13637 To support this kind of debugging, you need do the following:
13638 <itemizedlist>
13639 <listitem><para>
13640 Ensure that GDB is on the target.
13641 You can do this by adding "gdb" to
13642 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
13643 <literallayout class='monospaced'>
13644 IMAGE_INSTALL_append = " gdb"
13645 </literallayout>
13646 Alternatively, you can add "tools-debug" to
13647 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
13648 <literallayout class='monospaced'>
13649 IMAGE_FEATURES_append = " tools-debug"
13650 </literallayout>
13651 </para></listitem>
13652 <listitem><para>
13653 Ensure that debug symbols are present.
13654 You can make sure these symbols are present by
13655 installing <filename>-dbg</filename>:
13656 <literallayout class='monospaced'>
13657 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
13658 </literallayout>
13659 Alternatively, you can do the following to include all
13660 the debug symbols:
13661 <literallayout class='monospaced'>
13662 IMAGE_FEATURES_append = " dbg-pkgs"
13663 </literallayout>
13664 </para></listitem>
13665 </itemizedlist>
13666 <note>
13667 To improve the debug information accuracy, you can reduce
13668 the level of optimization used by the compiler.
13669 For example, when adding the following line to your
13670 <filename>local.conf</filename> file, you will reduce
13671 optimization from
13672 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
13673 of "-O2" to
13674 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
13675 of "-O -fno-omit-frame-pointer":
13676 <literallayout class='monospaced'>
13677 DEBUG_BUILD = "1"
13678 </literallayout>
13679 Consider that this will reduce the application's performance
13680 and is recommended only for debugging purposes.
13681 </note>
13682 </para>
13683 </section>
13684
13685 <section id='dev-other-debugging-others'>
13686 <title>Other Debugging Tips</title>
13687
13688 <para>
13689 Here are some other tips that you might find useful:
13690 <itemizedlist>
13691 <listitem><para>
13692 When adding new packages, it is worth watching for
13693 undesirable items making their way into compiler command
13694 lines.
13695 For example, you do not want references to local system
13696 files like
13697 <filename>/usr/lib/</filename> or
13698 <filename>/usr/include/</filename>.
13699 </para></listitem>
13700 <listitem><para>
13701 If you want to remove the <filename>psplash</filename>
13702 boot splashscreen,
13703 add <filename>psplash=false</filename> to the kernel
13704 command line.
13705 Doing so prevents <filename>psplash</filename> from
13706 loading and thus allows you to see the console.
13707 It is also possible to switch out of the splashscreen by
13708 switching the virtual console (e.g. Fn+Left or Fn+Right
13709 on a Zaurus).
13710 </para></listitem>
13711 <listitem><para>
13712 Removing
13713 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
13714 (usually <filename>tmp/</filename>, within the
13715 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
13716 can often fix temporary build issues.
13717 Removing <filename>TMPDIR</filename> is usually a
13718 relatively cheap operation, because task output will be
13719 cached in
13720 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13721 (usually <filename>sstate-cache/</filename>, which is
13722 also in the Build Directory).
13723 <note>
13724 Removing <filename>TMPDIR</filename> might be a
13725 workaround rather than a fix.
13726 Consequently, trying to determine the underlying
13727 cause of an issue before removing the directory is
13728 a good idea.
13729 </note>
13730 </para></listitem>
13731 <listitem><para>
13732 Understanding how a feature is used in practice within
13733 existing recipes can be very helpful.
13734 It is recommended that you configure some method that
13735 allows you to quickly search through files.</para>
13736
13737 <para>Using GNU Grep, you can use the following shell
13738 function to recursively search through common
13739 recipe-related files, skipping binary files,
13740 <filename>.git</filename> directories, and the
13741 Build Directory (assuming its name starts with
13742 "build"):
13743 <literallayout class='monospaced'>
13744 g() {
13745 grep -Ir \
13746 --exclude-dir=.git \
13747 --exclude-dir='build*' \
13748 --include='*.bb*' \
13749 --include='*.inc*' \
13750 --include='*.conf*' \
13751 --include='*.py*' \
13752 "$@"
13753 }
13754 </literallayout>
13755 Following are some usage examples:
13756 <literallayout class='monospaced'>
13757 $ g FOO # Search recursively for "FOO"
13758 $ g -i foo # Search recursively for "foo", ignoring case
13759 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
13760 </literallayout>
13761 If figuring out how some feature works requires a lot of
13762 searching, it might indicate that the documentation
13763 should be extended or improved.
13764 In such cases, consider filing a documentation bug using
13765 the Yocto Project implementation of
13766 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
13767 For information on how to submit a bug against
13768 the Yocto Project, see the Yocto Project Bugzilla
13769 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
13770 and the
13771 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
13772 section.
13773 <note>
13774 The manuals might not be the right place to document
13775 variables that are purely internal and have a
13776 limited scope (e.g. internal variables used to
13777 implement a single <filename>.bbclass</filename>
13778 file).
13779 </note>
13780 </para></listitem>
13781 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013782 </para>
13783 </section>
13784 </section>
13785
Brad Bishop316dfdd2018-06-25 12:45:53 -040013786 <section id='making-changes-to-the-yocto-project'>
13787 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013788
13789 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013790 Because the Yocto Project is an open-source, community-based
13791 project, you can effect changes to the project.
13792 This section presents procedures that show you how to submit
13793 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013794 </para>
13795
Brad Bishop316dfdd2018-06-25 12:45:53 -040013796 <section id='submitting-a-defect-against-the-yocto-project'>
13797 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013798
13799 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013800 Use the Yocto Project implementation of
13801 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
13802 to submit a defect (bug) against the Yocto Project.
13803 For additional information on this implementation of Bugzilla see the
13804 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
13805 section in the Yocto Project Reference Manual.
13806 For more detail on any of the following steps, see the Yocto Project
13807 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013808 </para>
13809
13810 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013811 Use the following general steps to submit a bug"
13812
13813 <orderedlist>
13814 <listitem><para>
13815 Open the Yocto Project implementation of
13816 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
13817 </para></listitem>
13818 <listitem><para>
13819 Click "File a Bug" to enter a new bug.
13820 </para></listitem>
13821 <listitem><para>
13822 Choose the appropriate "Classification", "Product", and
13823 "Component" for which the bug was found.
13824 Bugs for the Yocto Project fall into one of several
13825 classifications, which in turn break down into several
13826 products and components.
13827 For example, for a bug against the
13828 <filename>meta-intel</filename> layer, you would choose
13829 "Build System, Metadata &amp; Runtime", "BSPs", and
13830 "bsps-meta-intel", respectively.
13831 </para></listitem>
13832 <listitem><para>
13833 Choose the "Version" of the Yocto Project for which you found
13834 the bug (e.g. &DISTRO;).
13835 </para></listitem>
13836 <listitem><para>
13837 Determine and select the "Severity" of the bug.
13838 The severity indicates how the bug impacted your work.
13839 </para></listitem>
13840 <listitem><para>
13841 Choose the "Hardware" that the bug impacts.
13842 </para></listitem>
13843 <listitem><para>
13844 Choose the "Architecture" that the bug impacts.
13845 </para></listitem>
13846 <listitem><para>
13847 Choose a "Documentation change" item for the bug.
13848 Fixing a bug might or might not affect the Yocto Project
13849 documentation.
13850 If you are unsure of the impact to the documentation, select
13851 "Don't Know".
13852 </para></listitem>
13853 <listitem><para>
13854 Provide a brief "Summary" of the bug.
13855 Try to limit your summary to just a line or two and be sure
13856 to capture the essence of the bug.
13857 </para></listitem>
13858 <listitem><para>
13859 Provide a detailed "Description" of the bug.
13860 You should provide as much detail as you can about the context,
13861 behavior, output, and so forth that surrounds the bug.
13862 You can even attach supporting files for output from logs by
13863 using the "Add an attachment" button.
13864 </para></listitem>
13865 <listitem><para>
13866 Click the "Submit Bug" button submit the bug.
13867 A new Bugzilla number is assigned to the bug and the defect
13868 is logged in the bug tracking system.
13869 </para></listitem>
13870 </orderedlist>
13871 Once you file a bug, the bug is processed by the Yocto Project Bug
13872 Triage Team and further details concerning the bug are assigned
13873 (e.g. priority and owner).
13874 You are the "Submitter" of the bug and any further categorization,
13875 progress, or comments on the bug result in Bugzilla sending you an
13876 automated email concerning the particular change or progress to the
13877 bug.
13878 </para>
13879 </section>
13880
13881 <section id='how-to-submit-a-change'>
13882 <title>Submitting a Change to the Yocto Project</title>
13883
13884 <para>
13885 Contributions to the Yocto Project and OpenEmbedded are very welcome.
13886 Because the system is extremely configurable and flexible, we recognize
13887 that developers will want to extend, configure or optimize it for
13888 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013889 </para>
13890
13891 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013892 The Yocto Project uses a mailing list and a patch-based workflow
13893 that is similar to the Linux kernel but contains important
13894 differences.
13895 In general, a mailing list exists through which you can submit
13896 patches.
13897 You should send patches to the appropriate mailing list so that they
13898 can be reviewed and merged by the appropriate maintainer.
13899 The specific mailing list you need to use depends on the
13900 location of the code you are changing.
13901 Each component (e.g. layer) should have a
13902 <filename>README</filename> file that indicates where to send
13903 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013904 </para>
13905
13906 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013907 You can send the patch to the mailing list using whichever approach
13908 you feel comfortable with to generate the patch.
13909 Once sent, the patch is usually reviewed by the community at large.
13910 If somebody has concerns with the patch, they will usually voice
13911 their concern over the mailing list.
13912 If a patch does not receive any negative reviews, the maintainer of
13913 the affected layer typically takes the patch, tests it, and then
13914 based on successful testing, merges the patch.
13915 </para>
13916
13917 <para id='figuring-out-the-mailing-list-to-use'>
13918 The "poky" repository, which is the Yocto Project's reference build
13919 environment, is a hybrid repository that contains several
13920 individual pieces (e.g. BitBake, Metadata, documentation,
13921 and so forth) built using the combo-layer tool.
13922 The upstream location used for submitting changes varies by
13923 component:
13924 <itemizedlist>
13925 <listitem><para>
13926 <emphasis>Core Metadata:</emphasis>
13927 Send your patch to the
13928 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
13929 mailing list. For example, a change to anything under
13930 the <filename>meta</filename> or
13931 <filename>scripts</filename> directories should be sent
13932 to this mailing list.
13933 </para></listitem>
13934 <listitem><para>
13935 <emphasis>BitBake:</emphasis>
13936 For changes to BitBake (i.e. anything under the
13937 <filename>bitbake</filename> directory), send your patch
13938 to the
13939 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
13940 mailing list.
13941 </para></listitem>
13942 <listitem><para>
13943 <emphasis>"meta-*" trees:</emphasis>
13944 These trees contain Metadata.
13945 Use the
13946 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
13947 mailing list.
13948 </para></listitem>
13949 </itemizedlist>
13950 </para>
13951
13952 <para>
13953 For changes to other layers hosted in the Yocto Project source
13954 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
13955 and the Yocto Project documentation, use the
13956 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
13957 general mailing list.
13958 <note>
13959 Sometimes a layer's documentation specifies to use a
13960 particular mailing list.
13961 If so, use that list.
13962 </note>
13963 For additional recipes that do not fit into the core Metadata, you
13964 should determine which layer the recipe should go into and submit
13965 the change in the manner recommended by the documentation (e.g.
13966 the <filename>README</filename> file) supplied with the layer.
13967 If in doubt, please ask on the Yocto general mailing list or on
13968 the openembedded-devel mailing list.
13969 </para>
13970
13971 <para>
13972 You can also push a change upstream and request a maintainer to
13973 pull the change into the component's upstream repository.
13974 You do this by pushing to a contribution repository that is upstream.
13975 See the
13976 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
13977 section in the Yocto Project Overview and Concepts Manual for additional
13978 concepts on working in the Yocto Project development environment.
13979 </para>
13980
13981 <para>
13982 Two commonly used testing repositories exist for
13983 OpenEmbedded-Core:
13984 <itemizedlist>
13985 <listitem><para>
13986 <emphasis>"ross/mut" branch:</emphasis>
13987 The "mut" (master-under-test) tree
13988 exists in the <filename>poky-contrib</filename> repository
13989 in the
13990 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
13991 </para></listitem>
13992 <listitem><para>
13993 <emphasis>"master-next" branch:</emphasis>
13994 This branch is part of the main
13995 "poky" repository in the Yocto Project source repositories.
13996 </para></listitem>
13997 </itemizedlist>
13998 Maintainers use these branches to test submissions prior to merging
13999 patches.
14000 Thus, you can get an idea of the status of a patch based on
14001 whether the patch has been merged into one of these branches.
14002 <note>
14003 This system is imperfect and changes can sometimes get lost in the
14004 flow.
14005 Asking about the status of a patch or change is reasonable if the
14006 change has been idle for a while with no feedback.
14007 The Yocto Project does have plans to use
14008 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14009 to track the status of patches and also to automatically preview
14010 patches.
14011 </note>
14012 </para>
14013
14014 <para>
14015 The following sections provide procedures for submitting a change.
14016 </para>
14017
14018 <section id='pushing-a-change-upstream'>
14019 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14020
14021 <para>
14022 Follow this procedure to push a change to an upstream "contrib"
14023 Git repository:
14024 <note>
14025 You can find general Git information on how to push a change
14026 upstream in the
14027 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14028 </note>
14029 <orderedlist>
14030 <listitem><para>
14031 <emphasis>Make Your Changes Locally:</emphasis>
14032 Make your changes in your local Git repository.
14033 You should make small, controlled, isolated changes.
14034 Keeping changes small and isolated aids review,
14035 makes merging/rebasing easier and keeps the change
14036 history clean should anyone need to refer to it in
14037 future.
14038 </para></listitem>
14039 <listitem><para>
14040 <emphasis>Stage Your Changes:</emphasis>
14041 Stage your changes by using the <filename>git add</filename>
14042 command on each file you changed.
14043 </para></listitem>
14044 <listitem><para id='making-sure-you-have-correct-commit-information'>
14045 <emphasis>Commit Your Changes:</emphasis>
14046 Commit the change by using the
14047 <filename>git commit</filename> command.
14048 Make sure your commit information follows standards by
14049 following these accepted conventions:
14050 <itemizedlist>
14051 <listitem><para>
14052 Be sure to include a "Signed-off-by:" line in the
14053 same style as required by the Linux kernel.
14054 Adding this line signifies that you, the submitter,
14055 have agreed to the Developer's Certificate of
14056 Origin 1.1 as follows:
14057 <literallayout class='monospaced'>
14058 Developer's Certificate of Origin 1.1
14059
14060 By making a contribution to this project, I certify that:
14061
14062 (a) The contribution was created in whole or in part by me and I
14063 have the right to submit it under the open source license
14064 indicated in the file; or
14065
14066 (b) The contribution is based upon previous work that, to the best
14067 of my knowledge, is covered under an appropriate open source
14068 license and I have the right under that license to submit that
14069 work with modifications, whether created in whole or in part
14070 by me, under the same open source license (unless I am
14071 permitted to submit under a different license), as indicated
14072 in the file; or
14073
14074 (c) The contribution was provided directly to me by some other
14075 person who certified (a), (b) or (c) and I have not modified
14076 it.
14077
14078 (d) I understand and agree that this project and the contribution
14079 are public and that a record of the contribution (including all
14080 personal information I submit with it, including my sign-off) is
14081 maintained indefinitely and may be redistributed consistent with
14082 this project or the open source license(s) involved.
14083 </literallayout>
14084 </para></listitem>
14085 <listitem><para>
14086 Provide a single-line summary of the change.
14087 and,
14088 if more explanation is needed, provide more
14089 detail in the body of the commit.
14090 This summary is typically viewable in the
14091 "shortlist" of changes.
14092 Thus, providing something short and descriptive
14093 that gives the reader a summary of the change is
14094 useful when viewing a list of many commits.
14095 You should prefix this short description with the
14096 recipe name (if changing a recipe), or else with
14097 the short form path to the file being changed.
14098 </para></listitem>
14099 <listitem><para>
14100 For the body of the commit message, provide
14101 detailed information that describes what you
14102 changed, why you made the change, and the approach
14103 you used.
14104 It might also be helpful if you mention how you
14105 tested the change.
14106 Provide as much detail as you can in the body of
14107 the commit message.
14108 <note>
14109 You do not need to provide a more detailed
14110 explanation of a change if the change is
14111 minor to the point of the single line
14112 summary providing all the information.
14113 </note>
14114 </para></listitem>
14115 <listitem><para>
14116 If the change addresses a specific bug or issue
14117 that is associated with a bug-tracking ID,
14118 include a reference to that ID in your detailed
14119 description.
14120 For example, the Yocto Project uses a specific
14121 convention for bug references - any commit that
14122 addresses a specific bug should use the following
14123 form for the detailed description.
14124 Be sure to use the actual bug-tracking ID from
14125 Bugzilla for
14126 <replaceable>bug-id</replaceable>:
14127 <literallayout class='monospaced'>
14128 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14129
14130 <replaceable>detailed description of change</replaceable>
14131 </literallayout>
14132 </para></listitem>
14133 </itemizedlist>
14134 </para></listitem>
14135 <listitem><para>
14136 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14137 If you have arranged for permissions to push to an
14138 upstream contrib repository, push the change to that
14139 repository:
14140 <literallayout class='monospaced'>
14141 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14142 </literallayout>
14143 For example, suppose you have permissions to push into the
14144 upstream <filename>meta-intel-contrib</filename>
14145 repository and you are working in a local branch named
14146 <replaceable>your_name</replaceable><filename>/README</filename>.
14147 The following command pushes your local commits to the
14148 <filename>meta-intel-contrib</filename> upstream
14149 repository and puts the commit in a branch named
14150 <replaceable>your_name</replaceable><filename>/README</filename>:
14151 <literallayout class='monospaced'>
14152 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14153 </literallayout>
14154 </para></listitem>
14155 <listitem><para id='push-determine-who-to-notify'>
14156 <emphasis>Determine Who to Notify:</emphasis>
14157 Determine the maintainer or the mailing list
14158 that you need to notify for the change.</para>
14159
14160 <para>Before submitting any change, you need to be sure
14161 who the maintainer is or what mailing list that you need
14162 to notify.
14163 Use either these methods to find out:
14164 <itemizedlist>
14165 <listitem><para>
14166 <emphasis>Maintenance File:</emphasis>
14167 Examine the <filename>maintainers.inc</filename>
14168 file, which is located in the
14169 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14170 at
14171 <filename>meta/conf/distro/include</filename>,
14172 to see who is responsible for code.
14173 </para></listitem>
14174 <listitem><para>
14175 <emphasis>Search by File:</emphasis>
14176 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14177 you can enter the following command to bring up a
14178 short list of all commits against a specific file:
14179 <literallayout class='monospaced'>
14180 git shortlog -- <replaceable>filename</replaceable>
14181 </literallayout>
14182 Just provide the name of the file for which you
14183 are interested.
14184 The information returned is not ordered by history
14185 but does include a list of everyone who has
14186 committed grouped by name.
14187 From the list, you can see who is responsible for
14188 the bulk of the changes against the file.
14189 </para></listitem>
14190 <listitem><para>
14191 <emphasis>Examine the List of Mailing Lists:</emphasis>
14192 For a list of the Yocto Project and related mailing
14193 lists, see the
14194 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14195 section in the Yocto Project Reference Manual.
14196 </para></listitem>
14197 </itemizedlist>
14198 </para></listitem>
14199 <listitem><para>
14200 <emphasis>Make a Pull Request:</emphasis>
14201 Notify the maintainer or the mailing list that you have
14202 pushed a change by making a pull request.</para>
14203
14204 <para>The Yocto Project provides two scripts that
14205 conveniently let you generate and send pull requests to the
14206 Yocto Project.
14207 These scripts are <filename>create-pull-request</filename>
14208 and <filename>send-pull-request</filename>.
14209 You can find these scripts in the
14210 <filename>scripts</filename> directory within the
14211 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14212 (e.g. <filename>~/poky/scripts</filename>).
14213 </para>
14214
14215 <para>Using these scripts correctly formats the requests
14216 without introducing any whitespace or HTML formatting.
14217 The maintainer that receives your patches either directly
14218 or through the mailing list needs to be able to save and
14219 apply them directly from your emails.
14220 Using these scripts is the preferred method for sending
14221 patches.</para>
14222
14223 <para>First, create the pull request.
14224 For example, the following command runs the script,
14225 specifies the upstream repository in the contrib directory
14226 into which you pushed the change, and provides a subject
14227 line in the created patch files:
14228 <literallayout class='monospaced'>
14229 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14230 </literallayout>
14231 Running this script forms
14232 <filename>*.patch</filename> files in a folder named
14233 <filename>pull-</filename><replaceable>PID</replaceable>
14234 in the current directory.
14235 One of the patch files is a cover letter.</para>
14236
14237 <para>Before running the
14238 <filename>send-pull-request</filename> script, you must
14239 edit the cover letter patch to insert information about
14240 your change.
14241 After editing the cover letter, send the pull request.
14242 For example, the following command runs the script and
14243 specifies the patch directory and email address.
14244 In this example, the email address is a mailing list:
14245 <literallayout class='monospaced'>
14246 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14247 </literallayout>
14248 You need to follow the prompts as the script is
14249 interactive.
14250 <note>
14251 For help on using these scripts, simply provide the
14252 <filename>-h</filename> argument as follows:
14253 <literallayout class='monospaced'>
14254 $ poky/scripts/create-pull-request -h
14255 $ poky/scripts/send-pull-request -h
14256 </literallayout>
14257 </note>
14258 </para></listitem>
14259 </orderedlist>
14260 </para>
14261 </section>
14262
14263 <section id='submitting-a-patch'>
14264 <title>Using Email to Submit a Patch</title>
14265
14266 <para>
14267 You can submit patches without using the
14268 <filename>create-pull-request</filename> and
14269 <filename>send-pull-request</filename> scripts described in the
14270 previous section.
14271 However, keep in mind, the preferred method is to use the scripts.
14272 </para>
14273
14274 <para>
14275 Depending on the components changed, you need to submit the email
14276 to a specific mailing list.
14277 For some guidance on which mailing list to use, see the
14278 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14279 at the beginning of this section.
14280 For a description of all the available mailing lists, see the
14281 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14282 section in the Yocto Project Reference Manual.
14283 </para>
14284
14285 <para>
14286 Here is the general procedure on how to submit a patch through
14287 email without using the scripts:
14288 <orderedlist>
14289 <listitem><para>
14290 <emphasis>Make Your Changes Locally:</emphasis>
14291 Make your changes in your local Git repository.
14292 You should make small, controlled, isolated changes.
14293 Keeping changes small and isolated aids review,
14294 makes merging/rebasing easier and keeps the change
14295 history clean should anyone need to refer to it in
14296 future.
14297 </para></listitem>
14298 <listitem><para>
14299 <emphasis>Stage Your Changes:</emphasis>
14300 Stage your changes by using the <filename>git add</filename>
14301 command on each file you changed.
14302 </para></listitem>
14303 <listitem><para>
14304 <emphasis>Commit Your Changes:</emphasis>
14305 Commit the change by using the
14306 <filename>git commit --signoff</filename> command.
14307 Using the <filename>--signoff</filename> option identifies
14308 you as the person making the change and also satisfies
14309 the Developer's Certificate of Origin (DCO) shown earlier.
14310 </para>
14311
14312 <para>When you form a commit, you must follow certain
14313 standards established by the Yocto Project development
14314 team.
14315 See
14316 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14317 in the previous section for information on how to
14318 provide commit information that meets Yocto Project
14319 commit message standards.
14320 </para></listitem>
14321 <listitem><para>
14322 <emphasis>Format the Commit:</emphasis>
14323 Format the commit into an email message.
14324 To format commits, use the
14325 <filename>git format-patch</filename> command.
14326 When you provide the command, you must include a revision
14327 list or a number of patches as part of the command.
14328 For example, either of these two commands takes your most
14329 recent single commit and formats it as an email message in
14330 the current directory:
14331 <literallayout class='monospaced'>
14332 $ git format-patch -1
14333 </literallayout>
14334 or
14335 <literallayout class='monospaced'>
14336 $ git format-patch HEAD~
14337 </literallayout></para>
14338
14339 <para>After the command is run, the current directory
14340 contains a numbered <filename>.patch</filename> file for
14341 the commit.</para>
14342
14343 <para>If you provide several commits as part of the
14344 command, the <filename>git format-patch</filename> command
14345 produces a series of numbered files in the current
14346 directory – one for each commit.
14347 If you have more than one patch, you should also use the
14348 <filename>--cover</filename> option with the command,
14349 which generates a cover letter as the first "patch" in
14350 the series.
14351 You can then edit the cover letter to provide a
14352 description for the series of patches.
14353 For information on the
14354 <filename>git format-patch</filename> command,
14355 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14356 using the <filename>man git-format-patch</filename>
14357 command.
14358 <note>
14359 If you are or will be a frequent contributor to the
14360 Yocto Project or to OpenEmbedded, you might consider
14361 requesting a contrib area and the necessary associated
14362 rights.
14363 </note>
14364 </para></listitem>
14365 <listitem><para>
14366 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14367 Import the files into your mail client by using the
14368 <filename>git send-email</filename> command.
14369 <note>
14370 In order to use <filename>git send-email</filename>,
14371 you must have the proper Git packages installed on
14372 your host.
14373 For Ubuntu, Debian, and Fedora the package is
14374 <filename>git-email</filename>.
14375 </note></para>
14376
14377 <para>The <filename>git send-email</filename> command
14378 sends email by using a local or remote Mail Transport Agent
14379 (MTA) such as <filename>msmtp</filename>,
14380 <filename>sendmail</filename>, or through a direct
14381 <filename>smtp</filename> configuration in your Git
14382 <filename>~/.gitconfig</filename> file.
14383 If you are submitting patches through email only, it is
14384 very important that you submit them without any whitespace
14385 or HTML formatting that either you or your mailer
14386 introduces.
14387 The maintainer that receives your patches needs to be able
14388 to save and apply them directly from your emails.
14389 A good way to verify that what you are sending will be
14390 applicable by the maintainer is to do a dry run and send
14391 them to yourself and then save and apply them as the
14392 maintainer would.</para>
14393
14394 <para>The <filename>git send-email</filename> command is
14395 the preferred method for sending your patches using
14396 email since there is no risk of compromising whitespace
14397 in the body of the message, which can occur when you use
14398 your own mail client.
14399 The command also has several options that let you
14400 specify recipients and perform further editing of the
14401 email message.
14402 For information on how to use the
14403 <filename>git send-email</filename> command,
14404 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14405 the <filename>man git-send-email</filename> command.
14406 </para></listitem>
14407 </orderedlist>
14408 </para>
14409 </section>
14410 </section>
14411 </section>
14412
14413 <section id='working-with-licenses'>
14414 <title>Working With Licenses</title>
14415
14416 <para>
14417 As mentioned in the
14418 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
14419 section in the Yocto Project Overview and Concepts Manual,
14420 open source projects are open to the public and they
14421 consequently have different licensing structures in place.
14422 This section describes the mechanism by which the
14423 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
14424 tracks changes to licensing text and covers how to maintain open
14425 source license compliance during your project's lifecycle.
14426 The section also describes how to enable commercially licensed
14427 recipes, which by default are disabled.
14428 </para>
14429
14430 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
14431 <title>Tracking License Changes</title>
14432
14433 <para>
14434 The license of an upstream project might change in the future.
14435 In order to prevent these changes going unnoticed, the
14436 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
14437 variable tracks changes to the license text. The checksums are
14438 validated at the end of the configure step, and if the
14439 checksums do not match, the build will fail.
14440 </para>
14441
14442 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
14443 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
14444
14445 <para>
14446 The <filename>LIC_FILES_CHKSUM</filename>
14447 variable contains checksums of the license text in the
14448 source code for the recipe.
14449 Following is an example of how to specify
14450 <filename>LIC_FILES_CHKSUM</filename>:
14451 <literallayout class='monospaced'>
14452 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
14453 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
14454 file://licfile2.txt;endline=50;md5=zzzz \
14455 ..."
14456 </literallayout>
14457 <note><title>Notes</title>
14458 <itemizedlist>
14459 <listitem><para>
14460 When using "beginline" and "endline", realize
14461 that line numbering begins with one and not
14462 zero.
14463 Also, the included lines are inclusive (i.e.
14464 lines five through and including 29 in the
14465 previous example for
14466 <filename>licfile1.txt</filename>).
14467 </para></listitem>
14468 <listitem><para>
14469 When a license check fails, the selected license
14470 text is included as part of the QA message.
14471 Using this output, you can determine the exact
14472 start and finish for the needed license text.
14473 </para></listitem>
14474 </itemizedlist>
14475 </note>
14476 </para>
14477
14478 <para>
14479 The build system uses the
14480 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
14481 variable as the default directory when searching files
14482 listed in <filename>LIC_FILES_CHKSUM</filename>.
14483 The previous example employs the default directory.
14484 </para>
14485
14486 <para>
14487 Consider this next example:
14488 <literallayout class='monospaced'>
14489 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
14490 md5=bb14ed3c4cda583abc85401304b5cd4e"
14491 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
14492 </literallayout>
14493 </para>
14494
14495 <para>
14496 The first line locates a file in
14497 <filename>${S}/src/ls.c</filename> and isolates lines five
14498 through 16 as license text.
14499 The second line refers to a file in
14500 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
14501 </para>
14502
14503 <para>
14504 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
14505 mandatory for all recipes, unless the
14506 <filename>LICENSE</filename> variable is set to "CLOSED".
14507 </para>
14508 </section>
14509
14510 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
14511 <title>Explanation of Syntax</title>
14512
14513 <para>
14514 As mentioned in the previous section, the
14515 <filename>LIC_FILES_CHKSUM</filename> variable lists all
14516 the important files that contain the license text for the
14517 source code.
14518 It is possible to specify a checksum for an entire file,
14519 or a specific section of a file (specified by beginning and
14520 ending line numbers with the "beginline" and "endline"
14521 parameters, respectively).
14522 The latter is useful for source files with a license
14523 notice header, README documents, and so forth.
14524 If you do not use the "beginline" parameter, then it is
14525 assumed that the text begins on the first line of the file.
14526 Similarly, if you do not use the "endline" parameter,
14527 it is assumed that the license text ends with the last
14528 line of the file.
14529 </para>
14530
14531 <para>
14532 The "md5" parameter stores the md5 checksum of the license
14533 text.
14534 If the license text changes in any way as compared to
14535 this parameter then a mismatch occurs.
14536 This mismatch triggers a build failure and notifies
14537 the developer.
14538 Notification allows the developer to review and address
14539 the license text changes.
14540 Also note that if a mismatch occurs during the build,
14541 the correct md5 checksum is placed in the build log and
14542 can be easily copied to the recipe.
14543 </para>
14544
14545 <para>
14546 There is no limit to how many files you can specify using
14547 the <filename>LIC_FILES_CHKSUM</filename> variable.
14548 Generally, however, every project requires a few
14549 specifications for license tracking.
14550 Many projects have a "COPYING" file that stores the
14551 license information for all the source code files.
14552 This practice allows you to just track the "COPYING"
14553 file as long as it is kept up to date.
14554 <note><title>Tips</title>
14555 <itemizedlist>
14556 <listitem><para>
14557 If you specify an empty or invalid "md5"
14558 parameter,
14559 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
14560 returns an md5 mis-match
14561 error and displays the correct "md5" parameter
14562 value during the build.
14563 The correct parameter is also captured in
14564 the build log.
14565 </para></listitem>
14566 <listitem><para>
14567 If the whole file contains only license text,
14568 you do not need to use the "beginline" and
14569 "endline" parameters.
14570 </para></listitem>
14571 </itemizedlist>
14572 </note>
14573 </para>
14574 </section>
14575 </section>
14576
14577 <section id="enabling-commercially-licensed-recipes">
14578 <title>Enabling Commercially Licensed Recipes</title>
14579
14580 <para>
14581 By default, the OpenEmbedded build system disables
14582 components that have commercial or other special licensing
14583 requirements.
14584 Such requirements are defined on a
14585 recipe-by-recipe basis through the
14586 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
14587 variable definition in the affected recipe.
14588 For instance, the
14589 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14590 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014591 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014592 LICENSE_FLAGS = "commercial"
14593 </literallayout>
14594 Here is a slightly more complicated example that contains both
14595 an explicit recipe name and version (after variable expansion):
14596 <literallayout class='monospaced'>
14597 LICENSE_FLAGS = "license_${PN}_${PV}"
14598 </literallayout>
14599 In order for a component restricted by a
14600 <filename>LICENSE_FLAGS</filename> definition to be enabled and
14601 included in an image, it needs to have a matching entry in the
14602 global
14603 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
14604 variable, which is a variable typically defined in your
14605 <filename>local.conf</filename> file.
14606 For example, to enable the
14607 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14608 package, you could add either the string
14609 "commercial_gst-plugins-ugly" or the more general string
14610 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
14611 See the
14612 "<link linkend='license-flag-matching'>License Flag Matching</link>"
14613 section for a full
14614 explanation of how <filename>LICENSE_FLAGS</filename> matching
14615 works.
14616 Here is the example:
14617 <literallayout class='monospaced'>
14618 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
14619 </literallayout>
14620 Likewise, to additionally enable the package built from the
14621 recipe containing
14622 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
14623 and assuming that the actual recipe name was
14624 <filename>emgd_1.10.bb</filename>, the following string would
14625 enable that package as well as the original
14626 <filename>gst-plugins-ugly</filename> package:
14627 <literallayout class='monospaced'>
14628 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
14629 </literallayout>
14630 As a convenience, you do not need to specify the complete
14631 license string in the whitelist for every package.
14632 You can use an abbreviated form, which consists
14633 of just the first portion or portions of the license
14634 string before the initial underscore character or characters.
14635 A partial string will match any license that contains the
14636 given string as the first portion of its license.
14637 For example, the following whitelist string will also match
14638 both of the packages previously mentioned as well as any other
14639 packages that have licenses starting with "commercial" or
14640 "license".
14641 <literallayout class='monospaced'>
14642 LICENSE_FLAGS_WHITELIST = "commercial license"
14643 </literallayout>
14644 </para>
14645
14646 <section id="license-flag-matching">
14647 <title>License Flag Matching</title>
14648
14649 <para>
14650 License flag matching allows you to control what recipes
14651 the OpenEmbedded build system includes in the build.
14652 Fundamentally, the build system attempts to match
14653 <filename>LICENSE_FLAGS</filename> strings found in recipes
14654 against <filename>LICENSE_FLAGS_WHITELIST</filename>
14655 strings found in the whitelist.
14656 A match causes the build system to include a recipe in the
14657 build, while failure to find a match causes the build
14658 system to exclude a recipe.
14659 </para>
14660
14661 <para>
14662 In general, license flag matching is simple.
14663 However, understanding some concepts will help you
14664 correctly and effectively use matching.
14665 </para>
14666
14667 <para>
14668 Before a flag
14669 defined by a particular recipe is tested against the
14670 contents of the whitelist, the expanded string
14671 <filename>_${PN}</filename> is appended to the flag.
14672 This expansion makes each
14673 <filename>LICENSE_FLAGS</filename> value recipe-specific.
14674 After expansion, the string is then matched against the
14675 whitelist.
14676 Thus, specifying
14677 <filename>LICENSE_FLAGS = "commercial"</filename>
14678 in recipe "foo", for example, results in the string
14679 <filename>"commercial_foo"</filename>.
14680 And, to create a match, that string must appear in the
14681 whitelist.
14682 </para>
14683
14684 <para>
14685 Judicious use of the <filename>LICENSE_FLAGS</filename>
14686 strings and the contents of the
14687 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
14688 allows you a lot of flexibility for including or excluding
14689 recipes based on licensing.
14690 For example, you can broaden the matching capabilities by
14691 using license flags string subsets in the whitelist.
14692 <note>
14693 When using a string subset, be sure to use the part of
14694 the expanded string that precedes the appended
14695 underscore character (e.g.
14696 <filename>usethispart_1.3</filename>,
14697 <filename>usethispart_1.4</filename>, and so forth).
14698 </note>
14699 For example, simply specifying the string "commercial" in
14700 the whitelist matches any expanded
14701 <filename>LICENSE_FLAGS</filename> definition that starts
14702 with the string "commercial" such as "commercial_foo" and
14703 "commercial_bar", which are the strings the build system
14704 automatically generates for hypothetical recipes named
14705 "foo" and "bar" assuming those recipes simply specify the
14706 following:
14707 <literallayout class='monospaced'>
14708 LICENSE_FLAGS = "commercial"
14709 </literallayout>
14710 Thus, you can choose to exhaustively
14711 enumerate each license flag in the whitelist and
14712 allow only specific recipes into the image, or
14713 you can use a string subset that causes a broader range of
14714 matches to allow a range of recipes into the image.
14715 </para>
14716
14717 <para>
14718 This scheme works even if the
14719 <filename>LICENSE_FLAGS</filename> string already
14720 has <filename>_${PN}</filename> appended.
14721 For example, the build system turns the license flag
14722 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
14723 would match both the general "commercial" and the specific
14724 "commercial_1.2_foo" strings found in the whitelist, as
14725 expected.
14726 </para>
14727
14728 <para>
14729 Here are some other scenarios:
14730 <itemizedlist>
14731 <listitem><para>
14732 You can specify a versioned string in the recipe
14733 such as "commercial_foo_1.2" in a "foo" recipe.
14734 The build system expands this string to
14735 "commercial_foo_1.2_foo".
14736 Combine this license flag with a whitelist that has
14737 the string "commercial" and you match the flag
14738 along with any other flag that starts with the
14739 string "commercial".
14740 </para></listitem>
14741 <listitem><para>
14742 Under the same circumstances, you can use
14743 "commercial_foo" in the whitelist and the build
14744 system not only matches "commercial_foo_1.2" but
14745 also matches any license flag with the string
14746 "commercial_foo", regardless of the version.
14747 </para></listitem>
14748 <listitem><para>
14749 You can be very specific and use both the
14750 package and version parts in the whitelist (e.g.
14751 "commercial_foo_1.2") to specifically match a
14752 versioned recipe.
14753 </para></listitem>
14754 </itemizedlist>
14755 </para>
14756 </section>
14757
14758 <section id="other-variables-related-to-commercial-licenses">
14759 <title>Other Variables Related to Commercial Licenses</title>
14760
14761 <para>
14762 Other helpful variables related to commercial
14763 license handling exist and are defined in the
14764 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
14765 <literallayout class='monospaced'>
14766 COMMERCIAL_AUDIO_PLUGINS ?= ""
14767 COMMERCIAL_VIDEO_PLUGINS ?= ""
14768 </literallayout>
14769 If you want to enable these components, you can do so by
14770 making sure you have statements similar to the following
14771 in your <filename>local.conf</filename> configuration file:
14772 <literallayout class='monospaced'>
14773 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
14774 gst-plugins-ugly-mpegaudioparse"
14775 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
14776 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
14777 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
14778 </literallayout>
14779 Of course, you could also create a matching whitelist
14780 for those components using the more general "commercial"
14781 in the whitelist, but that would also enable all the
14782 other packages with <filename>LICENSE_FLAGS</filename>
14783 containing "commercial", which you may or may not want:
14784 <literallayout class='monospaced'>
14785 LICENSE_FLAGS_WHITELIST = "commercial"
14786 </literallayout>
14787 </para>
14788
14789 <para>
14790 Specifying audio and video plug-ins as part of the
14791 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
14792 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
14793 (along with the enabling
14794 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
14795 plug-ins or components into built images, thus adding
14796 support for media formats or components.
14797 </para>
14798 </section>
14799 </section>
14800
14801 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
14802 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
14803
14804 <para>
14805 One of the concerns for a development organization using open source
14806 software is how to maintain compliance with various open source
14807 licensing during the lifecycle of the product.
14808 While this section does not provide legal advice or
14809 comprehensively cover all scenarios, it does
14810 present methods that you can use to
14811 assist you in meeting the compliance requirements during a software
14812 release.
14813 </para>
14814
14815 <para>
14816 With hundreds of different open source licenses that the Yocto
14817 Project tracks, it is difficult to know the requirements of each
14818 and every license.
14819 However, the requirements of the major FLOSS licenses can begin
14820 to be covered by
14821 assuming that three main areas of concern exist:
14822 <itemizedlist>
14823 <listitem><para>Source code must be provided.</para></listitem>
14824 <listitem><para>License text for the software must be
14825 provided.</para></listitem>
14826 <listitem><para>Compilation scripts and modifications to the
14827 source code must be provided.
14828 </para></listitem>
14829 </itemizedlist>
14830 There are other requirements beyond the scope of these
14831 three and the methods described in this section
14832 (e.g. the mechanism through which source code is distributed).
14833 </para>
14834
14835 <para>
14836 As different organizations have different methods of complying with
14837 open source licensing, this section is not meant to imply that
14838 there is only one single way to meet your compliance obligations,
14839 but rather to describe one method of achieving compliance.
14840 The remainder of this section describes methods supported to meet the
14841 previously mentioned three requirements.
14842 Once you take steps to meet these requirements,
14843 and prior to releasing images, sources, and the build system,
14844 you should audit all artifacts to ensure completeness.
14845 <note>
14846 The Yocto Project generates a license manifest during
14847 image creation that is located
14848 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
14849 to assist with any audits.
14850 </note>
14851 </para>
14852
14853 <section id='providing-the-source-code'>
14854 <title>Providing the Source Code</title>
14855
14856 <para>
14857 Compliance activities should begin before you generate the
14858 final image.
14859 The first thing you should look at is the requirement that
14860 tops the list for most compliance groups - providing
14861 the source.
14862 The Yocto Project has a few ways of meeting this
14863 requirement.
14864 </para>
14865
14866 <para>
14867 One of the easiest ways to meet this requirement is
14868 to provide the entire
14869 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
14870 used by the build.
14871 This method, however, has a few issues.
14872 The most obvious is the size of the directory since it includes
14873 all sources used in the build and not just the source used in
14874 the released image.
14875 It will include toolchain source, and other artifacts, which
14876 you would not generally release.
14877 However, the more serious issue for most companies is accidental
14878 release of proprietary software.
14879 The Yocto Project provides an
14880 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
14881 class to help avoid some of these concerns.
14882 </para>
14883
14884 <para>
14885 Before you employ <filename>DL_DIR</filename> or the
14886 <filename>archiver</filename> class, you need to decide how
14887 you choose to provide source.
14888 The source <filename>archiver</filename> class can generate
14889 tarballs and SRPMs and can create them with various levels of
14890 compliance in mind.
14891 </para>
14892
14893 <para>
14894 One way of doing this (but certainly not the only way) is to
14895 release just the source as a tarball.
14896 You can do this by adding the following to the
14897 <filename>local.conf</filename> file found in the
14898 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
14899 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014900 INHERIT += "archiver"
14901 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040014902 </literallayout>
14903 During the creation of your image, the source from all
14904 recipes that deploy packages to the image is placed within
14905 subdirectories of
14906 <filename>DEPLOY_DIR/sources</filename> based on the
14907 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
14908 for each recipe.
14909 Releasing the entire directory enables you to comply with
14910 requirements concerning providing the unmodified source.
14911 It is important to note that the size of the directory can
14912 get large.
14913 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014914
Brad Bishop316dfdd2018-06-25 12:45:53 -040014915 <para>
14916 A way to help mitigate the size issue is to only release
14917 tarballs for licenses that require the release of
14918 source.
14919 Let us assume you are only concerned with GPL code as
14920 identified by running the following script:
14921 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060014922 # Script to archive a subset of packages matching specific license(s)
14923 # Source and license files are copied into sub folders of package folder
14924 # Must be run from build folder
14925 #!/bin/bash
14926 src_release_dir="source-release"
14927 mkdir -p $src_release_dir
14928 for a in tmp/deploy/sources/*; do
14929 for d in $a/*; do
14930 # Get package name from path
14931 p=`basename $d`
14932 p=${p%-*}
14933 p=${p%-*}
14934 # Only archive GPL packages (update *GPL* regex for your license check)
14935 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
14936 if [ $numfiles -gt 1 ]; then
14937 echo Archiving $p
14938 mkdir -p $src_release_dir/$p/source
14939 cp $d/* $src_release_dir/$p/source 2> /dev/null
14940 mkdir -p $src_release_dir/$p/license
14941 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
14942 fi
14943 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040014944 done
14945 </literallayout>
14946 At this point, you could create a tarball from the
14947 <filename>gpl_source_release</filename> directory and
14948 provide that to the end user.
14949 This method would be a step toward achieving compliance
14950 with section 3a of GPLv2 and with section 6 of GPLv3.
14951 </para>
14952 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014953
Brad Bishop316dfdd2018-06-25 12:45:53 -040014954 <section id='providing-license-text'>
14955 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014956
Brad Bishop316dfdd2018-06-25 12:45:53 -040014957 <para>
14958 One requirement that is often overlooked is inclusion
14959 of license text.
14960 This requirement also needs to be dealt with prior to
14961 generating the final image.
14962 Some licenses require the license text to accompany
14963 the binary.
14964 You can achieve this by adding the following to your
14965 <filename>local.conf</filename> file:
14966 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014967 COPY_LIC_MANIFEST = "1"
14968 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014969 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040014970 </literallayout>
14971 Adding these statements to the configuration file ensures
14972 that the licenses collected during package generation
14973 are included on your image.
14974 <note>
14975 <para>Setting all three variables to "1" results in the
14976 image having two copies of the same license file.
14977 One copy resides in
14978 <filename>/usr/share/common-licenses</filename> and
14979 the other resides in
14980 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014981
Brad Bishop316dfdd2018-06-25 12:45:53 -040014982 <para>The reason for this behavior is because
14983 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
14984 and
14985 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
14986 add a copy of the license when the image is built but do
14987 not offer a path for adding licenses for newly installed
14988 packages to an image.
14989 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
14990 adds a separate package and an upgrade path for adding
14991 licenses to an image.</para>
14992 </note>
14993 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014994
Brad Bishop316dfdd2018-06-25 12:45:53 -040014995 <para>
14996 As the source <filename>archiver</filename> class has already
14997 archived the original
14998 unmodified source that contains the license files,
14999 you would have already met the requirements for inclusion
15000 of the license information with source as defined by the GPL
15001 and other open source licenses.
15002 </para>
15003 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015004
Brad Bishop316dfdd2018-06-25 12:45:53 -040015005 <section id='providing-compilation-scripts-and-source-code-modifications'>
15006 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015007
Brad Bishop316dfdd2018-06-25 12:45:53 -040015008 <para>
15009 At this point, we have addressed all we need to
15010 prior to generating the image.
15011 The next two requirements are addressed during the final
15012 packaging of the release.
15013 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015014
Brad Bishop316dfdd2018-06-25 12:45:53 -040015015 <para>
15016 By releasing the version of the OpenEmbedded build system
15017 and the layers used during the build, you will be providing both
15018 compilation scripts and the source code modifications in one
15019 step.
15020 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015021
Brad Bishop316dfdd2018-06-25 12:45:53 -040015022 <para>
15023 If the deployment team has a
15024 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15025 and a distro layer, and those those layers are used to patch,
15026 compile, package, or modify (in any way) any open source
15027 software included in your released images, you
15028 might be required to release those layers under section 3 of
15029 GPLv2 or section 1 of GPLv3.
15030 One way of doing that is with a clean
15031 checkout of the version of the Yocto Project and layers used
15032 during your build.
15033 Here is an example:
15034 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015035 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15036 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015037 $ cd poky
15038 # We built using the release_branch for our layers
15039 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15040 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15041 # clean up the .git repos
15042 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015043 </literallayout>
15044 One thing a development organization might want to consider
15045 for end-user convenience is to modify
15046 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15047 ensure that when the end user utilizes the released build
15048 system to build an image, the development organization's
15049 layers are included in the <filename>bblayers.conf</filename>
15050 file automatically:
15051 <literallayout class='monospaced'>
15052 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015053 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015054 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015055
15056 BBPATH = "${TOPDIR}"
15057 BBFILES ?= ""
15058
15059 BBLAYERS ?= " \
15060 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015061 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015062 ##OEROOT##/meta-yocto-bsp \
15063 ##OEROOT##/meta-mylayer \
15064 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015065 </literallayout>
15066 Creating and providing an archive of the
15067 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15068 layers (recipes, configuration files, and so forth)
15069 enables you to meet your
15070 requirements to include the scripts to control compilation
15071 as well as any modifications to the original source.
15072 </para>
15073 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015074 </section>
15075 </section>
15076
15077 <section id='using-the-error-reporting-tool'>
15078 <title>Using the Error Reporting Tool</title>
15079
15080 <para>
15081 The error reporting tool allows you to
15082 submit errors encountered during builds to a central database.
15083 Outside of the build environment, you can use a web interface to
15084 browse errors, view statistics, and query for errors.
15085 The tool works using a client-server system where the client
15086 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015087 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015088 (e.g. <filename>poky</filename>).
15089 The server receives the information collected and saves it in a
15090 database.
15091 </para>
15092
15093 <para>
15094 A live instance of the error reporting server exists at
15095 <ulink url='http://errors.yoctoproject.org'></ulink>.
15096 This server exists so that when you want to get help with
15097 build failures, you can submit all of the information on the
15098 failure easily and then point to the URL in your bug report
15099 or send an email to the mailing list.
15100 <note>
15101 If you send error reports to this server, the reports become
15102 publicly visible.
15103 </note>
15104 </para>
15105
15106 <section id='enabling-and-using-the-tool'>
15107 <title>Enabling and Using the Tool</title>
15108
15109 <para>
15110 By default, the error reporting tool is disabled.
15111 You can enable it by inheriting the
15112 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15113 class by adding the following statement to the end of
15114 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015115 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015116 <literallayout class='monospaced'>
15117 INHERIT += "report-error"
15118 </literallayout>
15119 </para>
15120
15121 <para>
15122 By default, the error reporting feature stores information in
15123 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15124 However, you can specify a directory to use by adding the following
15125 to your <filename>local.conf</filename> file:
15126 <literallayout class='monospaced'>
15127 ERR_REPORT_DIR = "path"
15128 </literallayout>
15129 Enabling error reporting causes the build process to collect
15130 the errors and store them in a file as previously described.
15131 When the build system encounters an error, it includes a
15132 command as part of the console output.
15133 You can run the command to send the error file to the server.
15134 For example, the following command sends the errors to an
15135 upstream server:
15136 <literallayout class='monospaced'>
15137 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15138 </literallayout>
15139 In the previous example, the errors are sent to a public
15140 database available at
15141 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15142 used by the entire community.
15143 If you specify a particular server, you can send the errors
15144 to a different database.
15145 Use the following command for more information on available
15146 options:
15147 <literallayout class='monospaced'>
15148 $ send-error-report --help
15149 </literallayout>
15150 </para>
15151
15152 <para>
15153 When sending the error file, you are prompted to review the
15154 data being sent as well as to provide a name and optional
15155 email address.
15156 Once you satisfy these prompts, the command returns a link
15157 from the server that corresponds to your entry in the database.
15158 For example, here is a typical link:
15159 <literallayout class='monospaced'>
15160 http://errors.yoctoproject.org/Errors/Details/9522/
15161 </literallayout>
15162 Following the link takes you to a web interface where you can
15163 browse, query the errors, and view statistics.
15164 </para>
15165 </section>
15166
15167 <section id='disabling-the-tool'>
15168 <title>Disabling the Tool</title>
15169
15170 <para>
15171 To disable the error reporting feature, simply remove or comment
15172 out the following statement from the end of your
15173 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015174 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015175 <literallayout class='monospaced'>
15176 INHERIT += "report-error"
15177 </literallayout>
15178 </para>
15179 </section>
15180
15181 <section id='setting-up-your-own-error-reporting-server'>
15182 <title>Setting Up Your Own Error Reporting Server</title>
15183
15184 <para>
15185 If you want to set up your own error reporting server, you
15186 can obtain the code from the Git repository at
15187 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15188 Instructions on how to set it up are in the README document.
15189 </para>
15190 </section>
15191 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015192
15193 <section id="dev-using-wayland-and-weston">
15194 <title>Using Wayland and Weston</title>
15195
15196 <para>
15197 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15198 is a computer display server protocol that
15199 provides a method for compositing window managers to communicate
15200 directly with applications and video hardware and expects them to
15201 communicate with input hardware using other libraries.
15202 Using Wayland with supporting targets can result in better control
15203 over graphics frame rendering than an application might otherwise
15204 achieve.
15205 </para>
15206
15207 <para>
15208 The Yocto Project provides the Wayland protocol libraries and the
15209 reference
15210 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15211 compositor as part of its release.
15212 You can find the integrated packages in the
15213 <filename>meta</filename> layer of the
15214 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15215 Specifically, you can find the recipes that build both Wayland
15216 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15217 </para>
15218
15219 <para>
15220 You can build both the Wayland and Weston packages for use only
15221 with targets that accept the
15222 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15223 which is also known as Mesa DRI.
15224 This implies that you cannot build and use the packages if your
15225 target uses, for example, the
15226 <trademark class='registered'>Intel</trademark> Embedded Media
15227 and Graphics Driver
15228 (<trademark class='registered'>Intel</trademark> EMGD) that
15229 overrides Mesa DRI.
15230 <note>
15231 Due to lack of EGL support, Weston 1.0.3 will not run
15232 directly on the emulated QEMU hardware.
15233 However, this version of Weston will run under X emulation
15234 without issues.
15235 </note>
15236 </para>
15237
15238 <para>
15239 This section describes what you need to do to implement Wayland and
15240 use the Weston compositor when building an image for a supporting
15241 target.
15242 </para>
15243
15244 <section id="enabling-wayland-in-an-image">
15245 <title>Enabling Wayland in an Image</title>
15246
15247 <para>
15248 To enable Wayland, you need to enable it to be built and enable
15249 it to be included (installed) in the image.
15250 </para>
15251
15252 <section id="enable-building">
15253 <title>Building</title>
15254
15255 <para>
15256 To cause Mesa to build the <filename>wayland-egl</filename>
15257 platform and Weston to build Wayland with Kernel Mode
15258 Setting
15259 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15260 support, include the "wayland" flag in the
15261 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15262 statement in your <filename>local.conf</filename> file:
15263 <literallayout class='monospaced'>
15264 DISTRO_FEATURES_append = " wayland"
15265 </literallayout>
15266 <note>
15267 If X11 has been enabled elsewhere, Weston will build
15268 Wayland with X11 support
15269 </note>
15270 </para>
15271 </section>
15272
15273 <section id="enable-installation-in-an-image">
15274 <title>Installing</title>
15275
15276 <para>
15277 To install the Wayland feature into an image, you must
15278 include the following
15279 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15280 statement in your <filename>local.conf</filename> file:
15281 <literallayout class='monospaced'>
15282 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15283 </literallayout>
15284 </para>
15285 </section>
15286 </section>
15287
15288 <section id="running-weston">
15289 <title>Running Weston</title>
15290
15291 <para>
15292 To run Weston inside X11, enabling it as described earlier and
15293 building a Sato image is sufficient.
15294 If you are running your image under Sato, a Weston Launcher
15295 appears in the "Utility" category.
15296 </para>
15297
15298 <para>
15299 Alternatively, you can run Weston through the command-line
15300 interpretor (CLI), which is better suited for development work.
15301 To run Weston under the CLI, you need to do the following after
15302 your image is built:
15303 <orderedlist>
15304 <listitem><para>
15305 Run these commands to export
15306 <filename>XDG_RUNTIME_DIR</filename>:
15307 <literallayout class='monospaced'>
15308 mkdir -p /tmp/$USER-weston
15309 chmod 0700 /tmp/$USER-weston
15310 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15311 </literallayout>
15312 </para></listitem>
15313 <listitem><para>
15314 Launch Weston in the shell:
15315 <literallayout class='monospaced'>
15316 weston
15317 </literallayout></para></listitem>
15318 </orderedlist>
15319 </para>
15320 </section>
15321 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015322</chapter>
15323
15324<!--
15325vim: expandtab tw=80 ts=4
15326-->