blob: 8ddcd5b075163f13c4b188096c6302a27f232433 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='extendpoky'>
6
7<title>Common Tasks</title>
8 <para>
9 This chapter describes fundamental procedures such as creating layers,
10 adding new software packages, extending or customizing images,
11 porting work to new hardware (adding a new machine), and so forth.
12 You will find that the procedures documented here occur often in the
13 development cycle using the Yocto Project.
14 </para>
15
16 <section id="understanding-and-creating-layers">
17 <title>Understanding and Creating Layers</title>
18
19 <para>
20 The OpenEmbedded build system supports organizing
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> into
22 multiple layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 Layers allow you to isolate different types of customizations from
24 each other.
Brad Bishop316dfdd2018-06-25 12:45:53 -040025 For introductory information on the Yocto Project Layer Model,
26 see the
27 "<ulink url='&YOCTO_DOCS_OM_URL;#the-yocto-project-layer-model'>The Yocto Project Layer Model</ulink>"
28 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 </para>
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 <section id='creating-your-own-layer'>
32 <title>Creating Your Own Layer</title>
33
34 <para>
35 It is very easy to create your own layers to use with the
36 OpenEmbedded build system.
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 The Yocto Project ships with tools that speed up creating
38 layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 This section describes the steps you perform by hand to create
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 layers so that you can better understand them.
41 For information about the layer-creation tools, see the
42 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 section in the Yocto Project Board Support Package (BSP)
44 Developer's Guide and the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 section further down in this manual.
47 </para>
48
49 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040050 Follow these general steps to create your layer without using
51 tools:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 <orderedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -040053 <listitem><para>
54 <emphasis>Check Existing Layers:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 Before creating a new layer, you should be sure someone
56 has not already created a layer containing the Metadata
57 you need.
58 You can see the
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 <ulink url='http://layers.openembedded.org/layerindex/layers/'>OpenEmbedded Metadata Index</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 for a list of layers from the OpenEmbedded community
61 that can be used in the Yocto Project.
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 You could find a layer that is identical or close to
63 what you need.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 <listitem><para>
66 <emphasis>Create a Directory:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 Create the directory for your layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -040068 When you create the layer, be sure to create the
69 directory in an area not associated with the
70 Yocto Project
71 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
72 (e.g. the cloned <filename>poky</filename> repository).
73 </para>
74
75 <para>While not strictly required, prepend the name of
76 the directory with the string "meta-".
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 For example:
78 <literallayout class='monospaced'>
79 meta-mylayer
80 meta-GUI_xyz
81 meta-mymachine
82 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040083 With rare exceptions, a layer's name follows this
84 form:
85 <literallayout class='monospaced'>
86 meta-<replaceable>root_name</replaceable>
87 </literallayout>
88 Following this layer naming convention can
89 save you trouble later when tools, components, or
90 variables "assume" your layer name begins with "meta-".
91 A notable example is in configuration files as
92 shown in the following step where layer names without
93 the "meta-" string are appended
94 to several variables used in the configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 <listitem><para id='dev-layer-config-file-description'>
97 <emphasis>Create a Layer Configuration File:</emphasis>
98 Inside your new layer folder, you need to create a
99 <filename>conf/layer.conf</filename> file.
100 It is easiest to take an existing layer configuration
101 file and copy that to your layer's
102 <filename>conf</filename> directory and then modify the
103 file as needed.</para>
104
105 <para>The
106 <filename>meta-yocto-bsp/conf/layer.conf</filename> file
107 in the Yocto Project
108 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf'>Source Repositories</ulink>
109 demonstrates the required syntax.
110 For your layer, you need to replace "yoctobsp" with
111 a unique identifier for your layer (e.g. "machinexyz"
112 for a layer named "meta-machinexyz"):
113 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 # We have a conf and classes directory, add to BBPATH
115 BBPATH .= ":${LAYERDIR}"
116
117 # We have recipes-* directories, add to BBFILES
118 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
119 ${LAYERDIR}/recipes-*/*/*.bbappend"
120
121 BBFILE_COLLECTIONS += "yoctobsp"
122 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
123 BBFILE_PRIORITY_yoctobsp = "5"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 LAYERVERSION_yoctobsp = "4"
125 LAYERSERIES_COMPAT_yoctobsp = "&DISTRO_NAME_NO_CAP;"
126 </literallayout>
127 Following is an explanation of the layer configuration
128 file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130 <listitem><para>
131 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>:
132 Adds the layer's root directory to BitBake's
133 search path.
134 Through the use of the
135 <filename>BBPATH</filename> variable, BitBake
136 locates class files
137 (<filename>.bbclass</filename>),
138 configuration files, and files that are
139 included with <filename>include</filename> and
140 <filename>require</filename> statements.
141 For these cases, BitBake uses the first file
142 that matches the name found in
143 <filename>BBPATH</filename>.
144 This is similar to the way the
145 <filename>PATH</filename> variable is used for
146 binaries.
147 It is recommended, therefore, that you use
148 unique class and configuration filenames in
149 your custom layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400151 <listitem><para>
152 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>:
153 Defines the location for all recipes in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155 </para></listitem>
156 <listitem><para>
157 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'><filename>BBFILE_COLLECTIONS</filename></ulink>:
158 Establishes the current layer through a
159 unique identifier that is used throughout the
160 OpenEmbedded build system to refer to the layer.
161 In this example, the identifier "yoctobsp" is
162 the representation for the container layer
163 named "meta-yocto-bsp".
164 </para></listitem>
165 <listitem><para>
166 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'><filename>BBFILE_PATTERN</filename></ulink>:
167 Expands immediately during parsing to
168 provide the directory of the layer.
169 </para></listitem>
170 <listitem><para>
171 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>:
172 Establishes a priority to use for
173 recipes in the layer when the OpenEmbedded build
174 finds recipes of the same name in different
175 layers.
176 </para></listitem>
177 <listitem><para>
178 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'><filename>LAYERVERSION</filename></ulink>:
179 Establishes a version number for the layer.
180 You can use this version number to specify this
181 exact version of the layer as a dependency when
182 using the
183 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDEPENDS'><filename>LAYERDEPENDS</filename></ulink>
184 variable.
185 </para></listitem>
186 <listitem><para>
187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERSERIES_COMPAT'><filename>LAYERSERIES_COMPAT</filename></ulink>:
188 Lists the
189 <ulink url='&YOCTO_WIKI_URL;/wiki/Releases'>Yocto Project</ulink>
190 releases for which the current version is
191 compatible.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800192 This variable is a good way to indicate if
193 your particular layer is current.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194 </para></listitem>
195 </itemizedlist>
196 </para></listitem>
197 <listitem><para>
198 <emphasis>Add Content:</emphasis>
199 Depending on the type of layer, add the content.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 If the layer adds support for a machine, add the machine
201 configuration in a <filename>conf/machine/</filename>
202 file within the layer.
203 If the layer adds distro policy, add the distro
204 configuration in a <filename>conf/distro/</filename>
205 file within the layer.
206 If the layer introduces new recipes, put the recipes
207 you need in <filename>recipes-*</filename>
208 subdirectories within the layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400209 <note>
210 For an explanation of layer hierarchy that
211 is compliant with the Yocto Project, see
212 the
213 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout'>Example Filesystem Layout</ulink>"
214 section in the Yocto Project Board
215 Support Package (BSP) Developer's Guide.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 </note>
217 </para></listitem>
218 <listitem><para>
219 <emphasis>Optionally Test for Compatibility:</emphasis>
220 If you want permission to use the Yocto Project
221 Compatibility logo with your layer or application that
222 uses your layer, perform the steps to apply for
223 compatibility.
224 See the
225 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
226 section for more information.
227 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 </orderedlist>
229 </para>
230 </section>
231
232 <section id='best-practices-to-follow-when-creating-layers'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500233 <title>Following Best Practices When Creating Layers</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234
235 <para>
236 To create layers that are easier to maintain and that will
237 not impact builds for other machines, you should consider the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 information in the following list:
239 <itemizedlist>
240 <listitem><para>
241 <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis>
242 In other words, do not copy an entire recipe into your
243 layer and then modify it.
244 Rather, use an append file
245 (<filename>.bbappend</filename>) to override only those
246 parts of the original recipe you need to modify.
247 </para></listitem>
248 <listitem><para>
249 <emphasis>Avoid Duplicating Include Files:</emphasis>
250 Use append files (<filename>.bbappend</filename>)
251 for each recipe that uses an include file.
252 Or, if you are introducing a new recipe that requires
253 the included file, use the path relative to the
254 original layer directory to refer to the file.
255 For example, use
256 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
257 instead of
258 <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
259 If you're finding you have to overlay the include file,
260 it could indicate a deficiency in the include file in
261 the layer to which it originally belongs.
262 If this is the case, you should try to address that
263 deficiency instead of overlaying the include file.
264 For example, you could address this by getting the
265 maintainer of the include file to add a variable or
266 variables to make it easy to override the parts needing
267 to be overridden.
268 </para></listitem>
269 <listitem><para>
270 <emphasis>Structure Your Layers:</emphasis>
271 Proper use of overrides within append files and
272 placement of machine-specific files within your layer
273 can ensure that a build is not using the wrong Metadata
274 and negatively impacting a build for a different
275 machine.
276 Following are some examples:
277 <itemizedlist>
278 <listitem><para>
279 <emphasis>Modify Variables to Support a
280 Different Machine:</emphasis>
281 Suppose you have a layer named
282 <filename>meta-one</filename> that adds support
283 for building machine "one".
284 To do so, you use an append file named
285 <filename>base-files.bbappend</filename> and
286 create a dependency on "foo" by altering the
287 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
288 variable:
289 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 DEPENDS = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 </literallayout>
292 The dependency is created during any build that
293 includes the layer
294 <filename>meta-one</filename>.
295 However, you might not want this dependency
296 for all machines.
297 For example, suppose you are building for
298 machine "two" but your
299 <filename>bblayers.conf</filename> file has the
300 <filename>meta-one</filename> layer included.
301 During the build, the
302 <filename>base-files</filename> for machine
303 "two" will also have the dependency on
304 <filename>foo</filename>.</para>
305 <para>To make sure your changes apply only when
306 building machine "one", use a machine override
307 with the <filename>DEPENDS</filename> statement:
308 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 DEPENDS_one = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500310 </literallayout>
311 You should follow the same strategy when using
312 <filename>_append</filename> and
313 <filename>_prepend</filename> operations:
314 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 DEPENDS_append_one = " foo"
316 DEPENDS_prepend_one = "foo "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 </literallayout>
318 As an actual example, here's a line from the recipe
319 for gnutls, which adds dependencies on
320 "argp-standalone" when building with the musl C
321 library:
322 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323 DEPENDS_append_libc-musl = " argp-standalone"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500324 </literallayout>
325 <note>
326 Avoiding "+=" and "=+" and using
327 machine-specific
328 <filename>_append</filename>
329 and <filename>_prepend</filename> operations
330 is recommended as well.
331 </note>
332 </para></listitem>
333 <listitem><para>
334 <emphasis>Place Machine-Specific Files in
335 Machine-Specific Locations:</emphasis>
336 When you have a base recipe, such as
337 <filename>base-files.bb</filename>, that
338 contains a
339 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
340 statement to a file, you can use an append file
341 to cause the build to use your own version of
342 the file.
343 For example, an append file in your layer at
344 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
345 could extend
346 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
347 using
348 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
349 as follows:
350 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352 </literallayout>
353 The build for machine "one" will pick up your
354 machine-specific file as long as you have the
355 file in
356 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
357 However, if you are building for a different
358 machine and the
359 <filename>bblayers.conf</filename> file includes
360 the <filename>meta-one</filename> layer and
361 the location of your machine-specific file is
362 the first location where that file is found
363 according to <filename>FILESPATH</filename>,
364 builds for all machines will also use that
365 machine-specific file.</para>
366 <para>You can make sure that a machine-specific
367 file is used for a particular machine by putting
368 the file in a subdirectory specific to the
369 machine.
370 For example, rather than placing the file in
371 <filename>meta-one/recipes-core/base-files/base-files/</filename>
372 as shown above, put it in
373 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
374 Not only does this make sure the file is used
375 only when building for machine "one", but the
376 build process locates the file more quickly.</para>
377 <para>In summary, you need to place all files
378 referenced from <filename>SRC_URI</filename>
379 in a machine-specific subdirectory within the
380 layer in order to restrict those files to
381 machine-specific builds.
382 </para></listitem>
383 </itemizedlist>
384 </para></listitem>
385 <listitem><para>
386 <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis>
387 If you want permission to use the
388 Yocto Project Compatibility logo with your layer
389 or application that uses your layer, perform the
390 steps to apply for compatibility.
391 See the
392 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
393 section for more information.
394 </para></listitem>
395 <listitem><para>
396 <emphasis>Follow the Layer Naming Convention:</emphasis>
397 Store custom layers in a Git repository that use the
398 <filename>meta-<replaceable>layer_name</replaceable></filename>
399 format.
400 </para></listitem>
401 <listitem><para>
402 <emphasis>Group Your Layers Locally:</emphasis>
403 Clone your repository alongside other cloned
404 <filename>meta</filename> directories from the
405 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
406 </para></listitem>
407 </itemizedlist>
408 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 </section>
410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 <section id='making-sure-your-layer-is-compatible-with-yocto-project'>
412 <title>Making Sure Your Layer is Compatible With Yocto Project</title>
413
414 <para>
415 When you create a layer used with the Yocto Project, it is
416 advantageous to make sure that the layer interacts well with
417 existing Yocto Project layers (i.e. the layer is compatible
418 with the Yocto Project).
419 Ensuring compatibility makes the layer easy to be consumed
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500420 by others in the Yocto Project community and could allow you
421 permission to use the Yocto Project Compatible Logo.
422 <note>
423 Only Yocto Project member organizations are permitted to
424 use the Yocto Project Compatible Logo.
425 The logo is not available for general use.
426 For information on how to become a Yocto Project member
427 organization, see the
428 <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500429 </note>
430 </para>
431
432 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500433 The Yocto Project Compatibility Program consists of a layer
434 application process that requests permission to use the Yocto
435 Project Compatibility Logo for your layer and application.
436 The process consists of two parts:
437 <orderedlist>
438 <listitem><para>
439 Successfully passing a script
440 (<filename>yocto-check-layer</filename>) that
441 when run against your layer, tests it against
442 constraints based on experiences of how layers have
443 worked in the real world and where pitfalls have been
444 found.
445 Getting a "PASS" result from the script is required for
446 successful compatibility registration.
447 </para></listitem>
448 <listitem><para>
449 Completion of an application acceptance form, which
450 you can find at
451 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
452 </para></listitem>
453 </orderedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 </para>
455
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 <para>
457 To be granted permission to use the logo, you need to satisfy
458 the following:
459 <itemizedlist>
460 <listitem><para>
461 Be able to check the box indicating that you
462 got a "PASS" when running the script against your
463 layer.
464 </para></listitem>
465 <listitem><para>
466 Answer "Yes" to the questions on the form or have an
467 acceptable explanation for any questions answered "No".
468 </para></listitem>
469 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400470 Be a Yocto Project Member Organization.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500471 </para></listitem>
472 </itemizedlist>
473 </para>
474
475 <para>
476 The remainder of this section presents information on the
477 registration form and on the
478 <filename>yocto-check-layer</filename> script.
479 </para>
480
481 <section id='yocto-project-compatible-program-application'>
482 <title>Yocto Project Compatible Program Application</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483
484 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500485 Use the form to apply for your layer's approval.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486 Upon successful application, you can use the Yocto
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500487 Project Compatibility Logo with your layer and the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 application that uses your layer.
489 </para>
490
491 <para>
492 To access the form, use this link:
493 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
494 Follow the instructions on the form to complete your
495 application.
496 </para>
497
498 <para>
499 The application consists of the following sections:
500 <itemizedlist>
501 <listitem><para>
502 <emphasis>Contact Information:</emphasis>
503 Provide your contact information as the fields
504 require.
505 Along with your information, provide the
506 released versions of the Yocto Project for which
507 your layer is compatible.
508 </para></listitem>
509 <listitem><para>
510 <emphasis>Acceptance Criteria:</emphasis>
511 Provide "Yes" or "No" answers for each of the
512 items in the checklist.
513 Space exists at the bottom of the form for any
514 explanations for items for which you answered "No".
515 </para></listitem>
516 <listitem><para>
517 <emphasis>Recommendations:</emphasis>
518 Provide answers for the questions regarding Linux
519 kernel use and build success.
520 </para></listitem>
521 </itemizedlist>
522 </para>
523 </section>
524
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500525 <section id='yocto-check-layer-script'>
526 <title><filename>yocto-check-layer</filename> Script</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527
528 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500529 The <filename>yocto-check-layer</filename> script
530 provides you a way to assess how compatible your layer is
531 with the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500532 You should run this script prior to using the form to
533 apply for compatibility as described in the previous
534 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500535 You need to achieve a "PASS" result in order to have
536 your application form successfully processed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 </para>
538
539 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400540 The script divides tests into three areas: COMMON, BSP,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500541 and DISTRO.
542 For example, given a distribution layer (DISTRO), the
543 layer must pass both the COMMON and DISTRO related tests.
544 Furthermore, if your layer is a BSP layer, the layer must
545 pass the COMMON and BSP set of tests.
546 </para>
547
548 <para>
549 To execute the script, enter the following commands from
550 your build directory:
551 <literallayout class='monospaced'>
552 $ source oe-init-build-env
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 $ yocto-check-layer <replaceable>your_layer_directory</replaceable>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500554 </literallayout>
555 Be sure to provide the actual directory for your layer
556 as part of the command.
557 </para>
558
559 <para>
560 Entering the command causes the script to determine the
561 type of layer and then to execute a set of specific
562 tests against the layer.
563 The following list overviews the test:
564 <itemizedlist>
565 <listitem><para>
566 <filename>common.test_readme</filename>:
567 Tests if a <filename>README</filename> file
568 exists in the layer and the file is not empty.
569 </para></listitem>
570 <listitem><para>
571 <filename>common.test_parse</filename>:
572 Tests to make sure that BitBake can parse the
573 files without error (i.e.
574 <filename>bitbake -p</filename>).
575 </para></listitem>
576 <listitem><para>
577 <filename>common.test_show_environment</filename>:
578 Tests that the global or per-recipe environment
579 is in order without errors (i.e.
580 <filename>bitbake -e</filename>).
581 </para></listitem>
582 <listitem><para>
583 <filename>common.test_signatures</filename>:
584 Tests to be sure that BSP and DISTRO layers do not
585 come with recipes that change signatures.
586 </para></listitem>
587 <listitem><para>
588 <filename>bsp.test_bsp_defines_machines</filename>:
589 Tests if a BSP layer has machine configurations.
590 </para></listitem>
591 <listitem><para>
592 <filename>bsp.test_bsp_no_set_machine</filename>:
593 Tests to ensure a BSP layer does not set the
594 machine when the layer is added.
595 </para></listitem>
596 <listitem><para>
597 <filename>distro.test_distro_defines_distros</filename>:
598 Tests if a DISTRO layer has distro configurations.
599 </para></listitem>
600 <listitem><para>
601 <filename>distro.test_distro_no_set_distro</filename>:
602 Tests to ensure a DISTRO layer does not set the
603 distribution when the layer is added.
604 </para></listitem>
605 </itemizedlist>
606 </para>
607 </section>
608 </section>
609
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610 <section id='enabling-your-layer'>
611 <title>Enabling Your Layer</title>
612
613 <para>
614 Before the OpenEmbedded build system can use your new layer,
615 you need to enable it.
616 To enable your layer, simply add your layer's path to the
617 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
618 variable in your <filename>conf/bblayers.conf</filename> file,
619 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 The following example shows how to enable a layer named
622 <filename>meta-mylayer</filename>:
623 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400624 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
625 # changes incompatibly
626 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627
628 BBPATH = "${TOPDIR}"
629 BBFILES ?= ""
630
631 BBLAYERS ?= " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400632 /home/<replaceable>user</replaceable>/poky/meta \
633 /home/<replaceable>user</replaceable>/poky/meta-poky \
634 /home/<replaceable>user</replaceable>/poky/meta-yocto-bsp \
635 /home/<replaceable>user</replaceable>/poky/meta-mylayer \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500636 "
637 </literallayout>
638 </para>
639
640 <para>
641 BitBake parses each <filename>conf/layer.conf</filename> file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400642 from the top down as specified in the
643 <filename>BBLAYERS</filename> variable
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500644 within the <filename>conf/bblayers.conf</filename> file.
645 During the processing of each
646 <filename>conf/layer.conf</filename> file, BitBake adds the
647 recipes, classes and configurations contained within the
648 particular layer to the source directory.
649 </para>
650 </section>
651
652 <section id='using-bbappend-files'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500653 <title>Using .bbappend Files in Your Layer</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500654
655 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500656 A recipe that appends Metadata to another recipe is called a
657 BitBake append file.
658 A BitBake append file uses the <filename>.bbappend</filename>
659 file type suffix, while the corresponding recipe to which
660 Metadata is being appended uses the <filename>.bb</filename>
661 file type suffix.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500662 </para>
663
664 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500665 You can use a <filename>.bbappend</filename> file in your
666 layer to make additions or changes to the content of another
667 layer's recipe without having to copy the other layer's
668 recipe into your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669 Your <filename>.bbappend</filename> file resides in your layer,
670 while the main <filename>.bb</filename> recipe file to
671 which you are appending Metadata resides in a different layer.
672 </para>
673
674 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 Being able to append information to an existing recipe not only
676 avoids duplication, but also automatically applies recipe
677 changes from a different layer into your layer.
678 If you were copying recipes, you would have to manually merge
679 changes as they occur.
680 </para>
681
682 <para>
683 When you create an append file, you must use the same root
684 name as the corresponding recipe file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685 For example, the append file
686 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
687 <filename>someapp_&DISTRO;.bb</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500688 This means the original recipe and append file names are
689 version number-specific.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500690 If the corresponding recipe is renamed to update to a newer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500691 version, you must also rename and possibly update
692 the corresponding <filename>.bbappend</filename> as well.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 During the build process, BitBake displays an error on starting
694 if it detects a <filename>.bbappend</filename> file that does
695 not have a corresponding recipe with a matching name.
696 See the
697 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
698 variable for information on how to handle this error.
699 </para>
700
701 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702 As an example, consider the main formfactor recipe and a
703 corresponding formfactor append file both from the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500704 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500705 Here is the main formfactor recipe, which is named
706 <filename>formfactor_0.0.bb</filename> and located in the
707 "meta" layer at
708 <filename>meta/recipes-bsp/formfactor</filename>:
709 <literallayout class='monospaced'>
710 SUMMARY = "Device formfactor information"
711 SECTION = "base"
712 LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500713 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714 PR = "r45"
715
716 SRC_URI = "file://config file://machconfig"
717 S = "${WORKDIR}"
718
719 PACKAGE_ARCH = "${MACHINE_ARCH}"
720 INHIBIT_DEFAULT_DEPS = "1"
721
722 do_install() {
723 # Install file only if it has contents
724 install -d ${D}${sysconfdir}/formfactor/
725 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
726 if [ -s "${S}/machconfig" ]; then
727 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
728 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 } </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 In the main recipe, note the
731 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
732 variable, which tells the OpenEmbedded build system where to
733 find files during the build.
734 </para>
735
736 <para>
737 Following is the append file, which is named
738 <filename>formfactor_0.0.bbappend</filename> and is from the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500739 Raspberry Pi BSP Layer named
740 <filename>meta-raspberrypi</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500741 The file is in the layer at
742 <filename>recipes-bsp/formfactor</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 <literallayout class='monospaced'>
744 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
745 </literallayout>
746 </para>
747
748 <para>
749 By default, the build system uses the
750 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
751 variable to locate files.
752 This append file extends the locations by setting the
753 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
754 variable.
755 Setting this variable in the <filename>.bbappend</filename>
756 file is the most reliable and recommended method for adding
757 directories to the search path used by the build system
758 to find files.
759 </para>
760
761 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500762 The statement in this example extends the directories to
763 include
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500764 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>,
765 which resolves to a directory named
766 <filename>formfactor</filename> in the same directory
767 in which the append file resides (i.e.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500768 <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500769 This implies that you must have the supporting directory
770 structure set up that will contain any files or patches you
771 will be including from the layer.
772 </para>
773
774 <para>
775 Using the immediate expansion assignment operator
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500776 <filename>:=</filename> is important because of the reference
777 to <filename>THISDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500778 The trailing colon character is important as it ensures that
779 items in the list remain colon-separated.
780 <note>
781 <para>
782 BitBake automatically defines the
783 <filename>THISDIR</filename> variable.
784 You should never set this variable yourself.
785 Using "_prepend" as part of the
786 <filename>FILESEXTRAPATHS</filename> ensures your path
787 will be searched prior to other paths in the final
788 list.
789 </para>
790
791 <para>
792 Also, not all append files add extra files.
793 Many append files simply exist to add build options
794 (e.g. <filename>systemd</filename>).
795 For these cases, your append file would not even
796 use the <filename>FILESEXTRAPATHS</filename> statement.
797 </para>
798 </note>
799 </para>
800 </section>
801
802 <section id='prioritizing-your-layer'>
803 <title>Prioritizing Your Layer</title>
804
805 <para>
806 Each layer is assigned a priority value.
807 Priority values control which layer takes precedence if there
808 are recipe files with the same name in multiple layers.
809 For these cases, the recipe file from the layer with a higher
810 priority number takes precedence.
811 Priority values also affect the order in which multiple
812 <filename>.bbappend</filename> files for the same recipe are
813 applied.
814 You can either specify the priority manually, or allow the
815 build system to calculate it based on the layer's dependencies.
816 </para>
817
818 <para>
819 To specify the layer's priority manually, use the
820 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400821 variable and append the layer's root name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500822 <literallayout class='monospaced'>
823 BBFILE_PRIORITY_mylayer = "1"
824 </literallayout>
825 </para>
826
827 <note>
828 <para>It is possible for a recipe with a lower version number
829 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
830 in a layer that has a higher priority to take precedence.</para>
831 <para>Also, the layer priority does not currently affect the
832 precedence order of <filename>.conf</filename>
833 or <filename>.bbclass</filename> files.
834 Future versions of BitBake might address this.</para>
835 </note>
836 </section>
837
838 <section id='managing-layers'>
839 <title>Managing Layers</title>
840
841 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400842 You can use the BitBake layer management tool
843 <filename>bitbake-layers</filename> to provide a view
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844 into the structure of recipes across a multi-layer project.
845 Being able to generate output that reports on configured layers
846 with their paths and priorities and on
847 <filename>.bbappend</filename> files and their applicable
848 recipes can help to reveal potential problems.
849 </para>
850
851 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400852 For help on the BitBake layer management tool, use the
853 following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500854 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400855 $ bitbake-layers --help
856 NOTE: Starting bitbake server...
857 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] &lt;subcommand&gt; ...
858
859 BitBake layers utility
860
861 optional arguments:
862 -d, --debug Enable debug output
863 -q, --quiet Print only errors
864 -F, --force Force add without recipe parse verification
865 --color COLOR Colorize output (where COLOR is auto, always, never)
866 -h, --help show this help message and exit
867
868 subcommands:
869 &lt;subcommand&gt;
870 show-layers show current configured layers.
871 show-overlayed list overlayed recipes (where the same recipe exists
872 in another layer)
873 show-recipes list available recipes, showing the layer they are
874 provided by
875 show-appends list bbappend files and recipe files they apply to
876 show-cross-depends Show dependencies between recipes that cross layer
877 boundaries.
878 add-layer Add one or more layers to bblayers.conf.
879 remove-layer Remove one or more layers from bblayers.conf.
880 flatten flatten layer configuration into a separate output
881 directory.
882 layerindex-fetch Fetches a layer from a layer index along with its
883 dependent layers, and adds them to conf/bblayers.conf.
884 layerindex-show-depends
885 Find layer dependencies from layer index.
886 create-layer Create a basic layer
887
888 Use bitbake-layers &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500889 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400890 </para>
891
892 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500893 The following list describes the available commands:
894 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400895 <listitem><para>
896 <emphasis><filename>help:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500897 Displays general help or help on a specified command.
898 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400899 <listitem><para>
900 <emphasis><filename>show-layers:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500901 Shows the current configured layers.
902 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400903 <listitem><para>
904 <emphasis><filename>show-overlayed:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 Lists overlayed recipes.
906 A recipe is overlayed when a recipe with the same name
907 exists in another layer that has a higher layer
908 priority.
909 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400910 <listitem><para>
911 <emphasis><filename>show-recipes:</filename></emphasis>
912 Lists available recipes and the layers that provide them.
913 </para></listitem>
914 <listitem><para>
915 <emphasis><filename>show-appends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916 Lists <filename>.bbappend</filename> files and the
917 recipe files to which they apply.
918 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400919 <listitem><para>
920 <emphasis><filename>show-cross-depends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500921 Lists dependency relationships between recipes that
922 cross layer boundaries.
923 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400924 <listitem><para>
925 <emphasis><filename>add-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500926 Adds a layer to <filename>bblayers.conf</filename>.
927 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400928 <listitem><para>
929 <emphasis><filename>remove-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500930 Removes a layer from <filename>bblayers.conf</filename>
931 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400932 <listitem><para>
933 <emphasis><filename>flatten:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500934 Flattens the layer configuration into a separate output
935 directory.
936 Flattening your layer configuration builds a "flattened"
937 directory that contains the contents of all layers,
938 with any overlayed recipes removed and any
939 <filename>.bbappend</filename> files appended to the
940 corresponding recipes.
941 You might have to perform some manual cleanup of the
942 flattened layer as follows:
943 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400944 <listitem><para>
945 Non-recipe files (such as patches)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500946 are overwritten.
947 The flatten command shows a warning for these
948 files.
949 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400950 <listitem><para>
951 Anything beyond the normal layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952 setup has been added to the
953 <filename>layer.conf</filename> file.
954 Only the lowest priority layer's
955 <filename>layer.conf</filename> is used.
956 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400957 <listitem><para>
958 Overridden and appended items from
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500959 <filename>.bbappend</filename> files need to be
960 cleaned up.
961 The contents of each
962 <filename>.bbappend</filename> end up in the
963 flattened recipe.
964 However, if there are appended or changed
965 variable values, you need to tidy these up
966 yourself.
967 Consider the following example.
968 Here, the <filename>bitbake-layers</filename>
969 command adds the line
970 <filename>#### bbappended ...</filename> so that
971 you know where the following lines originate:
972 <literallayout class='monospaced'>
973 ...
974 DESCRIPTION = "A useful utility"
975 ...
976 EXTRA_OECONF = "--enable-something"
977 ...
978
979 #### bbappended from meta-anotherlayer ####
980
981 DESCRIPTION = "Customized utility"
982 EXTRA_OECONF += "--enable-somethingelse"
983 </literallayout>
984 Ideally, you would tidy up these utilities as
985 follows:
986 <literallayout class='monospaced'>
987 ...
988 DESCRIPTION = "Customized utility"
989 ...
990 EXTRA_OECONF = "--enable-something --enable-somethingelse"
991 ...
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500992 </literallayout>
993 </para></listitem>
994 </itemizedlist>
995 </para></listitem>
996 <listitem><para>
997 <emphasis><filename>layerindex-fetch</filename>:</emphasis>
998 Fetches a layer from a layer index, along with its
999 dependent layers, and adds the layers to the
1000 <filename>conf/bblayers.conf</filename> file.
1001 </para></listitem>
1002 <listitem><para>
1003 <emphasis><filename>layerindex-show-depends</filename>:</emphasis>
1004 Finds layer dependencies from the layer index.
1005 </para></listitem>
1006 <listitem><para>
1007 <emphasis><filename>create-layer</filename>:</emphasis>
1008 Creates a basic layer.
1009 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001010 </itemizedlist>
1011 </para>
1012 </section>
1013
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001014 <section id='creating-a-general-layer-using-the-bitbake-layers-script'>
1015 <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
1017 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001018 The <filename>bitbake-layers</filename> script with the
1019 <filename>create-layer</filename> subcommand simplifies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001020 creating a new general layer.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 <note><title>Notes</title>
1022 <itemizedlist>
1023 <listitem><para>
1024 For information on BSP layers, see the
1025 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
1026 section in the Yocto Project Board Specific (BSP)
1027 Developer's Guide.
1028 </para></listitem>
1029 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001030 In order to use a layer with the OpenEmbedded
1031 build system, you need to add the layer to your
1032 <filename>bblayers.conf</filename> configuration
1033 file.
1034 See the
1035 "<link linkend='adding-a-layer-using-the-bitbake-layers-script'>Adding a Layer Using the <filename>bitbake-layers</filename> Script</link>"
1036 section for more information.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001037 </para></listitem>
1038 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001039 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 The default mode of the script's operation with this
1041 subcommand is to create a layer with the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001042 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001043 <listitem><para>A layer priority of 6.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001044 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001045 <listitem><para>A <filename>conf</filename>
1046 subdirectory that contains a
1047 <filename>layer.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001048 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001049 <listitem><para>
1050 A <filename>recipes-example</filename> subdirectory
1051 that contains a further subdirectory named
1052 <filename>example</filename>, which contains
1053 an <filename>example.bb</filename> recipe file.
1054 </para></listitem>
1055 <listitem><para>A <filename >COPYING.MIT</filename>,
1056 which is the license statement for the layer.
1057 The script assumes you want to use the MIT license,
1058 which is typical for most layers, for the contents of
1059 the layer itself.
1060 </para></listitem>
1061 <listitem><para>
1062 A <filename>README</filename> file, which is a file
1063 describing the contents of your new layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001064 </para></listitem>
1065 </itemizedlist>
1066 </para>
1067
1068 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001069 In its simplest form, you can use the following command form
1070 to create a layer.
1071 The command creates a layer whose name corresponds to
1072 <replaceable>your_layer_name</replaceable> in the current
1073 directory:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001074 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001075 $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001076 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001077 As an example, the following command creates a layer named
1078 <filename>meta-scottrif</filename> in your home directory:
1079 <literallayout class='monospaced'>
1080 $ cd /usr/home
1081 $ bitbake-layers create-layer meta-scottrif
1082 NOTE: Starting bitbake server...
1083 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
1084 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 </para>
1086
1087 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001088 If you want to set the priority of the layer to other than the
1089 default value of "6", you can either use the
1090 <filename>&dash;&dash;priority</filename> option or you can
1091 edit the
1092 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
1093 value in the <filename>conf/layer.conf</filename> after the
1094 script creates it.
1095 Furthermore, if you want to give the example recipe file
1096 some name other than the default, you can
1097 use the
1098 <filename>&dash;&dash;example-recipe-name</filename> option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001099 </para>
1100
1101 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001102 The easiest way to see how the
1103 <filename>bitbake-layers create-layer</filename> command
1104 works is to experiment with the script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001105 You can also read the usage information by entering the
1106 following:
1107 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001108 $ bitbake-layers create-layer --help
1109 NOTE: Starting bitbake server...
1110 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
1111 [--example-recipe-name EXAMPLERECIPE]
1112 layerdir
1113
1114 Create a basic layer
1115
1116 positional arguments:
1117 layerdir Layer directory to create
1118
1119 optional arguments:
1120 -h, --help show this help message and exit
1121 --priority PRIORITY, -p PRIORITY
1122 Layer directory to create
1123 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
1124 Filename of the example recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001125 </literallayout>
1126 </para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001127 </section>
1128
1129 <section id='adding-a-layer-using-the-bitbake-layers-script'>
1130 <title>Adding a Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001131
1132 <para>
1133 Once you create your general layer, you must add it to your
1134 <filename>bblayers.conf</filename> file.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001135 Adding the layer to this configuration file makes the
1136 OpenEmbedded build system aware of your layer so that it can
1137 search it for metadata.
1138 </para>
1139
1140 <para>
1141 Add your layer by using the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001142 <filename>bitbake-layers add-layer</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001143 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001144 $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable>
1145 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001146 Here is an example that adds a layer named
1147 <filename>meta-scottrif</filename> to the configuration file.
1148 Following the command that adds the layer is another
1149 <filename>bitbake-layers</filename> command that shows the
1150 layers that are in your <filename>bblayers.conf</filename>
1151 file:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001152 <literallayout class='monospaced'>
1153 $ bitbake-layers add-layer meta-scottrif
1154 NOTE: Starting bitbake server...
Brad Bishop316dfdd2018-06-25 12:45:53 -04001155 Parsing recipes: 100% |##########################################################| Time: 0:00:49
1156 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001157 $ bitbake-layers show-layers
1158 NOTE: Starting bitbake server...
1159 layer path priority
1160 ==========================================================================
1161 meta /home/scottrif/poky/meta 5
1162 meta-poky /home/scottrif/poky/meta-poky 5
1163 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001164 workspace /home/scottrif/poky/build/workspace 99
1165 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001166 </literallayout>
1167 Adding the layer to this file enables the build system to
1168 locate the layer during the build.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001169 <note>
1170 During a build, the OpenEmbedded build system looks in
1171 the layers from the top of the list down to the bottom
1172 in that order.
1173 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001174 </para>
1175 </section>
1176 </section>
1177
1178 <section id='usingpoky-extend-customimage'>
1179 <title>Customizing Images</title>
1180
1181 <para>
1182 You can customize images to satisfy particular requirements.
1183 This section describes several methods and provides guidelines for each.
1184 </para>
1185
1186 <section id='usingpoky-extend-customimage-localconf'>
1187 <title>Customizing Images Using <filename>local.conf</filename></title>
1188
1189 <para>
1190 Probably the easiest way to customize an image is to add a
1191 package by way of the <filename>local.conf</filename>
1192 configuration file.
1193 Because it is limited to local use, this method generally only
1194 allows you to add packages and is not as flexible as creating
1195 your own customized image.
1196 When you add packages using local variables this way, you need
1197 to realize that these variable changes are in effect for every
1198 build and consequently affect all images, which might not
1199 be what you require.
1200 </para>
1201
1202 <para>
1203 To add a package to your image using the local configuration
1204 file, use the
1205 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1206 variable with the <filename>_append</filename> operator:
1207 <literallayout class='monospaced'>
1208 IMAGE_INSTALL_append = " strace"
1209 </literallayout>
1210 Use of the syntax is important - specifically, the space between
1211 the quote and the package name, which is
1212 <filename>strace</filename> in this example.
1213 This space is required since the <filename>_append</filename>
1214 operator does not add the space.
1215 </para>
1216
1217 <para>
1218 Furthermore, you must use <filename>_append</filename> instead
1219 of the <filename>+=</filename> operator if you want to avoid
1220 ordering issues.
1221 The reason for this is because doing so unconditionally appends
1222 to the variable and avoids ordering problems due to the
1223 variable being set in image recipes and
1224 <filename>.bbclass</filename> files with operators like
1225 <filename>?=</filename>.
1226 Using <filename>_append</filename> ensures the operation takes
1227 affect.
1228 </para>
1229
1230 <para>
1231 As shown in its simplest use,
1232 <filename>IMAGE_INSTALL_append</filename> affects all images.
1233 It is possible to extend the syntax so that the variable
1234 applies to a specific image only.
1235 Here is an example:
1236 <literallayout class='monospaced'>
1237 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
1238 </literallayout>
1239 This example adds <filename>strace</filename> to the
1240 <filename>core-image-minimal</filename> image only.
1241 </para>
1242
1243 <para>
1244 You can add packages using a similar approach through the
1245 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
1246 variable.
1247 If you use this variable, only
1248 <filename>core-image-*</filename> images are affected.
1249 </para>
1250 </section>
1251
1252 <section id='usingpoky-extend-customimage-imagefeatures'>
1253 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
1254 <filename>EXTRA_IMAGE_FEATURES</filename></title>
1255
1256 <para>
1257 Another method for customizing your image is to enable or
1258 disable high-level image features by using the
1259 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
1260 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
1261 variables.
1262 Although the functions for both variables are nearly equivalent,
1263 best practices dictate using <filename>IMAGE_FEATURES</filename>
1264 from within a recipe and using
1265 <filename>EXTRA_IMAGE_FEATURES</filename> from within
1266 your <filename>local.conf</filename> file, which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001267 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001268 </para>
1269
1270 <para>
1271 To understand how these features work, the best reference is
1272 <filename>meta/classes/core-image.bbclass</filename>.
1273 This class lists out the available
Brad Bishop316dfdd2018-06-25 12:45:53 -04001274 <filename>IMAGE_FEATURES</filename> of which most map to
1275 package groups while some, such as
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001276 <filename>debug-tweaks</filename> and
1277 <filename>read-only-rootfs</filename>, resolve as general
1278 configuration settings.
1279 </para>
1280
1281 <para>
1282 In summary, the file looks at the contents of the
1283 <filename>IMAGE_FEATURES</filename> variable and then maps
1284 or configures the feature accordingly.
1285 Based on this information, the build system automatically
1286 adds the appropriate packages or configurations to the
1287 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
1288 variable.
1289 Effectively, you are enabling extra features by extending the
1290 class or creating a custom class for use with specialized image
1291 <filename>.bb</filename> files.
1292 </para>
1293
1294 <para>
1295 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1296 from within your local configuration file.
1297 Using a separate area from which to enable features with
1298 this variable helps you avoid overwriting the features in the
1299 image recipe that are enabled with
1300 <filename>IMAGE_FEATURES</filename>.
1301 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1302 to <filename>IMAGE_FEATURES</filename> within
1303 <filename>meta/conf/bitbake.conf</filename>.
1304 </para>
1305
1306 <para>
1307 To illustrate how you can use these variables to modify your
1308 image, consider an example that selects the SSH server.
1309 The Yocto Project ships with two SSH servers you can use
1310 with your images: Dropbear and OpenSSH.
1311 Dropbear is a minimal SSH server appropriate for
1312 resource-constrained environments, while OpenSSH is a
1313 well-known standard SSH server implementation.
1314 By default, the <filename>core-image-sato</filename> image
1315 is configured to use Dropbear.
1316 The <filename>core-image-full-cmdline</filename> and
1317 <filename>core-image-lsb</filename> images both
1318 include OpenSSH.
1319 The <filename>core-image-minimal</filename> image does not
1320 contain an SSH server.
1321 </para>
1322
1323 <para>
1324 You can customize your image and change these defaults.
1325 Edit the <filename>IMAGE_FEATURES</filename> variable
1326 in your recipe or use the
1327 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1328 <filename>local.conf</filename> file so that it configures the
1329 image you are working with to include
1330 <filename>ssh-server-dropbear</filename> or
1331 <filename>ssh-server-openssh</filename>.
1332 </para>
1333
1334 <note>
1335 See the
1336 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1337 section in the Yocto Project Reference Manual for a complete
1338 list of image features that ship with the Yocto Project.
1339 </note>
1340 </section>
1341
1342 <section id='usingpoky-extend-customimage-custombb'>
1343 <title>Customizing Images Using Custom .bb Files</title>
1344
1345 <para>
1346 You can also customize an image by creating a custom recipe
1347 that defines additional software as part of the image.
1348 The following example shows the form for the two lines you need:
1349 <literallayout class='monospaced'>
1350 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1351
1352 inherit core-image
1353 </literallayout>
1354 </para>
1355
1356 <para>
1357 Defining the software using a custom recipe gives you total
1358 control over the contents of the image.
1359 It is important to use the correct names of packages in the
1360 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1361 variable.
1362 You must use the OpenEmbedded notation and not the Debian notation for the names
1363 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1364 </para>
1365
1366 <para>
1367 The other method for creating a custom image is to base it on an existing image.
1368 For example, if you want to create an image based on <filename>core-image-sato</filename>
1369 but add the additional package <filename>strace</filename> to the image,
1370 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1371 new <filename>.bb</filename> and add the following line to the end of the copy:
1372 <literallayout class='monospaced'>
1373 IMAGE_INSTALL += "strace"
1374 </literallayout>
1375 </para>
1376 </section>
1377
1378 <section id='usingpoky-extend-customimage-customtasks'>
1379 <title>Customizing Images Using Custom Package Groups</title>
1380
1381 <para>
1382 For complex custom images, the best approach for customizing
1383 an image is to create a custom package group recipe that is
1384 used to build the image or images.
1385 A good example of a package group recipe is
1386 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1387 </para>
1388
1389 <para>
1390 If you examine that recipe, you see that the
1391 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1392 variable lists the package group packages to produce.
1393 The <filename>inherit packagegroup</filename> statement
1394 sets appropriate default values and automatically adds
1395 <filename>-dev</filename>, <filename>-dbg</filename>, and
1396 <filename>-ptest</filename> complementary packages for each
1397 package specified in the <filename>PACKAGES</filename>
1398 statement.
1399 <note>
1400 The <filename>inherit packages</filename> should be
1401 located near the top of the recipe, certainly before
1402 the <filename>PACKAGES</filename> statement.
1403 </note>
1404 </para>
1405
1406 <para>
1407 For each package you specify in <filename>PACKAGES</filename>,
1408 you can use
1409 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1410 and
1411 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1412 entries to provide a list of packages the parent task package
1413 should contain.
1414 You can see examples of these further down in the
1415 <filename>packagegroup-base.bb</filename> recipe.
1416 </para>
1417
1418 <para>
1419 Here is a short, fabricated example showing the same basic
1420 pieces:
1421 <literallayout class='monospaced'>
1422 DESCRIPTION = "My Custom Package Groups"
1423
1424 inherit packagegroup
1425
1426 PACKAGES = "\
1427 packagegroup-custom-apps \
1428 packagegroup-custom-tools \
1429 "
1430
1431 RDEPENDS_packagegroup-custom-apps = "\
1432 dropbear \
1433 portmap \
1434 psplash"
1435
1436 RDEPENDS_packagegroup-custom-tools = "\
1437 oprofile \
1438 oprofileui-server \
1439 lttng-tools"
1440
1441 RRECOMMENDS_packagegroup-custom-tools = "\
1442 kernel-module-oprofile"
1443 </literallayout>
1444 </para>
1445
1446 <para>
1447 In the previous example, two package group packages are created with their dependencies and their
1448 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1449 <filename>packagegroup-custom-tools</filename>.
1450 To build an image using these package group packages, you need to add
1451 <filename>packagegroup-custom-apps</filename> and/or
1452 <filename>packagegroup-custom-tools</filename> to
1453 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1454 For other forms of image dependencies see the other areas of this section.
1455 </para>
1456 </section>
1457
1458 <section id='usingpoky-extend-customimage-image-name'>
1459 <title>Customizing an Image Hostname</title>
1460
1461 <para>
1462 By default, the configured hostname (i.e.
1463 <filename>/etc/hostname</filename>) in an image is the
1464 same as the machine name.
1465 For example, if
1466 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1467 equals "qemux86", the configured hostname written to
1468 <filename>/etc/hostname</filename> is "qemux86".
1469 </para>
1470
1471 <para>
1472 You can customize this name by altering the value of the
1473 "hostname" variable in the
1474 <filename>base-files</filename> recipe using either
1475 an append file or a configuration file.
1476 Use the following in an append file:
1477 <literallayout class='monospaced'>
1478 hostname="myhostname"
1479 </literallayout>
1480 Use the following in a configuration file:
1481 <literallayout class='monospaced'>
1482 hostname_pn-base-files = "myhostname"
1483 </literallayout>
1484 </para>
1485
1486 <para>
1487 Changing the default value of the variable "hostname" can be
1488 useful in certain situations.
1489 For example, suppose you need to do extensive testing on an
1490 image and you would like to easily identify the image
1491 under test from existing images with typical default
1492 hostnames.
1493 In this situation, you could change the default hostname to
1494 "testme", which results in all the images using the name
1495 "testme".
1496 Once testing is complete and you do not need to rebuild the
1497 image for test any longer, you can easily reset the default
1498 hostname.
1499 </para>
1500
1501 <para>
1502 Another point of interest is that if you unset the variable,
1503 the image will have no default hostname in the filesystem.
1504 Here is an example that unsets the variable in a
1505 configuration file:
1506 <literallayout class='monospaced'>
1507 hostname_pn-base-files = ""
1508 </literallayout>
1509 Having no default hostname in the filesystem is suitable for
1510 environments that use dynamic hostnames such as virtual
1511 machines.
1512 </para>
1513 </section>
1514 </section>
1515
1516 <section id='new-recipe-writing-a-new-recipe'>
1517 <title>Writing a New Recipe</title>
1518
1519 <para>
1520 Recipes (<filename>.bb</filename> files) are fundamental components
1521 in the Yocto Project environment.
1522 Each software component built by the OpenEmbedded build system
1523 requires a recipe to define the component.
1524 This section describes how to create, write, and test a new
1525 recipe.
1526 <note>
1527 For information on variables that are useful for recipes and
1528 for information about recipe naming issues, see the
1529 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1530 section of the Yocto Project Reference Manual.
1531 </note>
1532 </para>
1533
1534 <section id='new-recipe-overview'>
1535 <title>Overview</title>
1536
1537 <para>
1538 The following figure shows the basic process for creating a
1539 new recipe.
1540 The remainder of the section provides details for the steps.
1541 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1542 </para>
1543 </section>
1544
1545 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1546 <title>Locate or Automatically Create a Base Recipe</title>
1547
1548 <para>
1549 You can always write a recipe from scratch.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001550 However, three choices exist that can help you quickly get a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001551 start on a new recipe:
1552 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001553 <listitem><para>
1554 <emphasis><filename>devtool add</filename>:</emphasis>
1555 A command that assists in creating a recipe and
1556 an environment conducive to development.
1557 </para></listitem>
1558 <listitem><para>
1559 <emphasis><filename>recipetool create</filename>:</emphasis>
1560 A command provided by the Yocto Project that automates
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001561 creation of a base recipe based on the source
1562 files.
1563 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001564 <listitem><para>
1565 <emphasis>Existing Recipes:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001566 Location and modification of an existing recipe that is
1567 similar in function to the recipe you need.
1568 </para></listitem>
1569 </itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001570 <note>
1571 For information on recipe syntax, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001572 "<link linkend='recipe-syntax'>Recipe Syntax</link>"
1573 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001574 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001575 </para>
1576
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001577 <section id='new-recipe-creating-the-base-recipe-using-devtool'>
1578 <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001579
1580 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001581 The <filename>devtool add</filename> command uses the same
1582 logic for auto-creating the recipe as
1583 <filename>recipetool create</filename>, which is listed
1584 below.
1585 Additionally, however, <filename>devtool add</filename>
1586 sets up an environment that makes it easy for you to
1587 patch the source and to make changes to the recipe as
1588 is often necessary when adding a recipe to build a new
1589 piece of software to be included in a build.
1590 </para>
1591
1592 <para>
1593 You can find a complete description of the
1594 <filename>devtool add</filename> command in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001595 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>"
1596 section in the Yocto Project Application Development
1597 and the Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001598 </para>
1599 </section>
1600
1601 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1602 <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
1603
1604 <para>
1605 <filename>recipetool create</filename> automates creation
1606 of a base recipe given a set of source code files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001607 As long as you can extract or point to the source files,
1608 the tool will construct a recipe and automatically
1609 configure all pre-build information into the recipe.
1610 For example, suppose you have an application that builds
1611 using Autotools.
1612 Creating the base recipe using
1613 <filename>recipetool</filename> results in a recipe
1614 that has the pre-build dependencies, license requirements,
1615 and checksums configured.
1616 </para>
1617
1618 <para>
1619 To run the tool, you just need to be in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001621 and have sourced the build environment setup script
1622 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001623 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
Brad Bishop316dfdd2018-06-25 12:45:53 -04001624 To get help on the tool, use the following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001625 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001626 $ recipetool -h
1627 NOTE: Starting bitbake server...
1628 usage: recipetool [-d] [-q] [--color COLOR] [-h] &lt;subcommand&gt; ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001629
Brad Bishop316dfdd2018-06-25 12:45:53 -04001630 OpenEmbedded recipe tool
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001631
Brad Bishop316dfdd2018-06-25 12:45:53 -04001632 options:
1633 -d, --debug Enable debug output
1634 -q, --quiet Print only errors
1635 --color COLOR Colorize output (where COLOR is auto, always, never)
1636 -h, --help show this help message and exit
1637
1638 subcommands:
1639 create Create a new recipe
1640 newappend Create a bbappend for the specified target in the specified
1641 layer
1642 setvar Set a variable within a recipe
1643 appendfile Create/update a bbappend to replace a target file
1644 appendsrcfiles Create/update a bbappend to add or replace source files
1645 appendsrcfile Create/update a bbappend to add or replace a source file
1646 Use recipetool &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001647 </literallayout>
1648 </para>
1649
1650 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001651 Running
1652 <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001653 creates the base recipe and locates it properly in the
1654 layer that contains your source files.
1655 Following are some syntax examples:
1656 </para>
1657
1658 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001659 Use this syntax to generate a recipe based on
1660 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001661 Once generated, the recipe resides in the existing source
1662 code layer:
1663 <literallayout class='monospaced'>
1664 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1665 </literallayout>
1666 Use this syntax to generate a recipe using code that you
1667 extract from <replaceable>source</replaceable>.
1668 The extracted code is placed in its own layer defined
1669 by <replaceable>EXTERNALSRC</replaceable>.
1670 <literallayout class='monospaced'>
1671 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1672 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001673 Use this syntax to generate a recipe based on
1674 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001675 The options direct <filename>recipetool</filename> to
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001676 generate debugging information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001677 Once generated, the recipe resides in the existing source
1678 code layer:
1679 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001680 recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001681 </literallayout>
1682 </para>
1683 </section>
1684
1685 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1686 <title>Locating and Using a Similar Recipe</title>
1687
1688 <para>
1689 Before writing a recipe from scratch, it is often useful to
1690 discover whether someone else has already written one that
1691 meets (or comes close to meeting) your needs.
1692 The Yocto Project and OpenEmbedded communities maintain many
1693 recipes that might be candidates for what you are doing.
1694 You can find a good central index of these recipes in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001695 <ulink url='http://layers.openembedded.org'>OpenEmbedded Layer Index</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001696 </para>
1697
1698 <para>
1699 Working from an existing recipe or a skeleton recipe is the
1700 best way to get started.
1701 Here are some points on both methods:
1702 <itemizedlist>
1703 <listitem><para><emphasis>Locate and modify a recipe that
1704 is close to what you want to do:</emphasis>
1705 This method works when you are familiar with the
1706 current recipe space.
1707 The method does not work so well for those new to
1708 the Yocto Project or writing recipes.</para>
1709 <para>Some risks associated with this method are
1710 using a recipe that has areas totally unrelated to
1711 what you are trying to accomplish with your recipe,
1712 not recognizing areas of the recipe that you might
1713 have to add from scratch, and so forth.
1714 All these risks stem from unfamiliarity with the
1715 existing recipe space.</para></listitem>
1716 <listitem><para><emphasis>Use and modify the following
1717 skeleton recipe:</emphasis>
1718 If for some reason you do not want to use
1719 <filename>recipetool</filename> and you cannot
1720 find an existing recipe that is close to meeting
1721 your needs, you can use the following structure to
1722 provide the fundamental areas of a new recipe.
1723 <literallayout class='monospaced'>
1724 DESCRIPTION = ""
1725 HOMEPAGE = ""
1726 LICENSE = ""
1727 SECTION = ""
1728 DEPENDS = ""
1729 LIC_FILES_CHKSUM = ""
1730
1731 SRC_URI = ""
1732 </literallayout>
1733 </para></listitem>
1734 </itemizedlist>
1735 </para>
1736 </section>
1737 </section>
1738
1739 <section id='new-recipe-storing-and-naming-the-recipe'>
1740 <title>Storing and Naming the Recipe</title>
1741
1742 <para>
1743 Once you have your base recipe, you should put it in your
1744 own layer and name it appropriately.
1745 Locating it correctly ensures that the OpenEmbedded build
1746 system can find it when you use BitBake to process the
1747 recipe.
1748 </para>
1749
1750 <itemizedlist>
1751 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1752 The OpenEmbedded build system locates your recipe
1753 through the layer's <filename>conf/layer.conf</filename>
1754 file and the
1755 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1756 variable.
1757 This variable sets up a path from which the build system can
1758 locate recipes.
1759 Here is the typical use:
1760 <literallayout class='monospaced'>
1761 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1762 ${LAYERDIR}/recipes-*/*/*.bbappend"
1763 </literallayout>
1764 Consequently, you need to be sure you locate your new recipe
1765 inside your layer such that it can be found.</para>
1766 <para>You can find more information on how layers are
1767 structured in the
1768 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1769 section.</para></listitem>
1770 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1771 When you name your recipe, you need to follow this naming
1772 convention:
1773 <literallayout class='monospaced'>
1774 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1775 </literallayout>
1776 Use lower-cased characters and do not include the reserved
1777 suffixes <filename>-native</filename>,
1778 <filename>-cross</filename>, <filename>-initial</filename>,
1779 or <filename>-dev</filename> casually (i.e. do not use them
1780 as part of your recipe name unless the string applies).
1781 Here are some examples:
1782 <literallayout class='monospaced'>
1783 cups_1.7.0.bb
1784 gawk_4.0.2.bb
1785 irssi_0.8.16-rc1.bb
1786 </literallayout></para></listitem>
1787 </itemizedlist>
1788 </section>
1789
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001790 <section id='new-recipe-running-a-build-on-the-recipe'>
1791 <title>Running a Build on the Recipe</title>
1792
1793 <para>
1794 Creating a new recipe is usually an iterative process that
1795 requires using BitBake to process the recipe multiple times in
1796 order to progressively discover and add information to the
1797 recipe file.
1798 </para>
1799
1800 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001801 Assuming you have sourced the build environment setup script (i.e.
1802 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001803 and you are in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001804 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001805 use BitBake to process your recipe.
1806 All you need to provide is the
1807 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1808 in the previous section:
1809 <literallayout class='monospaced'>
1810 $ bitbake <replaceable>basename</replaceable>
1811 </literallayout>
1812
1813 </para>
1814
1815 <para>
1816 During the build, the OpenEmbedded build system creates a
1817 temporary work directory for each recipe
1818 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1819 where it keeps extracted source files, log files, intermediate
1820 compilation and packaging files, and so forth.
1821 </para>
1822
1823 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001824 The path to the per-recipe temporary work directory depends
1825 on the context in which it is being built.
1826 The quickest way to find this path is to have BitBake return it
1827 by running the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001828 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001829 $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001830 </literallayout>
1831 As an example, assume a Source Directory top-level folder named
1832 <filename>poky</filename>, a default Build Directory at
1833 <filename>poky/build</filename>, and a
1834 <filename>qemux86-poky-linux</filename> machine target system.
1835 Furthermore, suppose your recipe is named
1836 <filename>foo_1.3.0.bb</filename>.
1837 In this case, the work directory the build system uses to
1838 build the package would be as follows:
1839 <literallayout class='monospaced'>
1840 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1841 </literallayout>
1842 Inside this directory you can find sub-directories such as
1843 <filename>image</filename>, <filename>packages-split</filename>,
1844 and <filename>temp</filename>.
1845 After the build, you can examine these to determine how well
1846 the build went.
1847 <note>
1848 You can find log files for each task in the recipe's
1849 <filename>temp</filename> directory (e.g.
1850 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1851 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1852 (e.g. <filename>log.do_configure</filename>,
1853 <filename>log.do_fetch</filename>, and
1854 <filename>log.do_compile</filename>).
1855 </note>
1856 </para>
1857
1858 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001859 You can find more information about the build process in
Brad Bishop316dfdd2018-06-25 12:45:53 -04001860 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-development-environment'>The Yocto Project Development Environment</ulink>"
1861 chapter of the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001862 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863 </section>
1864
1865 <section id='new-recipe-fetching-code'>
1866 <title>Fetching Code</title>
1867
1868 <para>
1869 The first thing your recipe must do is specify how to fetch
1870 the source files.
1871 Fetching is controlled mainly through the
1872 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1873 variable.
1874 Your recipe must have a <filename>SRC_URI</filename> variable
1875 that points to where the source is located.
1876 For a graphical representation of source locations, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001877 "<ulink url='&YOCTO_DOCS_OM_URL;#sources-dev-environment'>Sources</ulink>"
1878 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001879 </para>
1880
1881 <para>
1882 The
1883 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1884 task uses the prefix of each entry in the
1885 <filename>SRC_URI</filename> variable value to determine which
Brad Bishopc342db32019-05-15 21:57:59 -04001886 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>
1887 to use to get your source files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001888 It is the <filename>SRC_URI</filename> variable that triggers
1889 the fetcher.
1890 The
1891 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1892 task uses the variable after source is fetched to apply
1893 patches.
1894 The OpenEmbedded build system uses
1895 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1896 for scanning directory locations for local files in
1897 <filename>SRC_URI</filename>.
1898 </para>
1899
1900 <para>
1901 The <filename>SRC_URI</filename> variable in your recipe must
1902 define each unique location for your source files.
1903 It is good practice to not hard-code pathnames in an URL used
1904 in <filename>SRC_URI</filename>.
1905 Rather than hard-code these paths, use
1906 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1907 which causes the fetch process to use the version specified in
1908 the recipe filename.
1909 Specifying the version in this manner means that upgrading the
1910 recipe to a future version is as simple as renaming the recipe
1911 to match the new version.
1912 </para>
1913
1914 <para>
1915 Here is a simple example from the
1916 <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
1917 recipe where the source comes from a single tarball.
1918 Notice the use of the
1919 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1920 variable:
1921 <literallayout class='monospaced'>
1922 SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
1923 </literallayout>
1924 </para>
1925
1926 <para>
1927 Files mentioned in <filename>SRC_URI</filename> whose names end
1928 in a typical archive extension (e.g. <filename>.tar</filename>,
1929 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1930 <filename>.zip</filename>, and so forth), are automatically
1931 extracted during the
1932 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1933 task.
1934 For another example that specifies these types of files, see
1935 the
1936 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1937 section.
1938 </para>
1939
1940 <para>
1941 Another way of specifying source is from an SCM.
1942 For Git repositories, you must specify
1943 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1944 and you should specify
1945 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1946 to include the revision with
1947 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1948 Here is an example from the recipe
1949 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1950 <literallayout class='monospaced'>
1951 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1952
1953 PR = "r6"
1954 PV = "1.0.5+git${SRCPV}"
1955
1956 SRC_URI = "git://git.kernel.dk/blktrace.git \
1957 file://ldflags.patch"
1958 </literallayout>
1959 </para>
1960
1961 <para>
1962 If your <filename>SRC_URI</filename> statement includes
1963 URLs pointing to individual files fetched from a remote server
1964 other than a version control system, BitBake attempts to
1965 verify the files against checksums defined in your recipe to
1966 ensure they have not been tampered with or otherwise modified
1967 since the recipe was written.
1968 Two checksums are used:
1969 <filename>SRC_URI[md5sum]</filename> and
1970 <filename>SRC_URI[sha256sum]</filename>.
1971 </para>
1972
1973 <para>
1974 If your <filename>SRC_URI</filename> variable points to
1975 more than a single URL (excluding SCM URLs), you need to
1976 provide the <filename>md5</filename> and
1977 <filename>sha256</filename> checksums for each URL.
1978 For these cases, you provide a name for each URL as part of
1979 the <filename>SRC_URI</filename> and then reference that name
1980 in the subsequent checksum statements.
1981 Here is an example:
1982 <literallayout class='monospaced'>
1983 SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001984 ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001985
1986 SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
1987 SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
1988
1989 SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
1990 SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
1991 </literallayout>
1992 </para>
1993
1994 <para>
1995 Proper values for <filename>md5</filename> and
1996 <filename>sha256</filename> checksums might be available
1997 with other signatures on the download page for the upstream
1998 source (e.g. <filename>md5</filename>,
1999 <filename>sha1</filename>, <filename>sha256</filename>,
2000 <filename>GPG</filename>, and so forth).
2001 Because the OpenEmbedded build system only deals with
2002 <filename>sha256sum</filename> and <filename>md5sum</filename>,
2003 you should verify all the signatures you find by hand.
2004 </para>
2005
2006 <para>
2007 If no <filename>SRC_URI</filename> checksums are specified
2008 when you attempt to build the recipe, or you provide an
2009 incorrect checksum, the build will produce an error for each
2010 missing or incorrect checksum.
2011 As part of the error message, the build system provides
2012 the checksum string corresponding to the fetched file.
2013 Once you have the correct checksums, you can copy and paste
2014 them into your recipe and then run the build again to continue.
2015 <note>
2016 As mentioned, if the upstream source provides signatures
2017 for verifying the downloaded source code, you should
2018 verify those manually before setting the checksum values
2019 in the recipe and continuing with the build.
2020 </note>
2021 </para>
2022
2023 <para>
2024 This final example is a bit more complicated and is from the
2025 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2026 recipe.
2027 The example's <filename>SRC_URI</filename> statement identifies
2028 multiple files as the source files for the recipe: a tarball, a
2029 patch file, a desktop file, and an icon.
2030 <literallayout class='monospaced'>
2031 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2032 file://xwc.patch \
2033 file://rxvt.desktop \
2034 file://rxvt.png"
2035 </literallayout>
2036 </para>
2037
2038 <para>
2039 When you specify local files using the
2040 <filename>file://</filename> URI protocol, the build system
2041 fetches files from the local machine.
2042 The path is relative to the
2043 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2044 variable and searches specific directories in a certain order:
2045 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2046 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2047 and <filename>files</filename>.
2048 The directories are assumed to be subdirectories of the
2049 directory in which the recipe or append file resides.
2050 For another example that specifies these types of files, see the
2051 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2052 section.
2053 </para>
2054
2055 <para>
2056 The previous example also specifies a patch file.
2057 Patch files are files whose names usually end in
2058 <filename>.patch</filename> or <filename>.diff</filename> but
2059 can end with compressed suffixes such as
2060 <filename>diff.gz</filename> and
2061 <filename>patch.bz2</filename>, for example.
2062 The build system automatically applies patches as described
2063 in the
2064 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2065 </para>
2066 </section>
2067
2068 <section id='new-recipe-unpacking-code'>
2069 <title>Unpacking Code</title>
2070
2071 <para>
2072 During the build, the
2073 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2074 task unpacks the source with
2075 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2076 pointing to where it is unpacked.
2077 </para>
2078
2079 <para>
2080 If you are fetching your source files from an upstream source
2081 archived tarball and the tarball's internal structure matches
2082 the common convention of a top-level subdirectory named
2083 <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>,
2084 then you do not need to set <filename>S</filename>.
2085 However, if <filename>SRC_URI</filename> specifies to fetch
2086 source from an archive that does not use this convention,
2087 or from an SCM like Git or Subversion, your recipe needs to
2088 define <filename>S</filename>.
2089 </para>
2090
2091 <para>
2092 If processing your recipe using BitBake successfully unpacks
2093 the source files, you need to be sure that the directory
2094 pointed to by <filename>${S}</filename> matches the structure
2095 of the source.
2096 </para>
2097 </section>
2098
2099 <section id='new-recipe-patching-code'>
2100 <title>Patching Code</title>
2101
2102 <para>
2103 Sometimes it is necessary to patch code after it has been
2104 fetched.
2105 Any files mentioned in <filename>SRC_URI</filename> whose
2106 names end in <filename>.patch</filename> or
2107 <filename>.diff</filename> or compressed versions of these
2108 suffixes (e.g. <filename>diff.gz</filename> are treated as
2109 patches.
2110 The
2111 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2112 task automatically applies these patches.
2113 </para>
2114
2115 <para>
2116 The build system should be able to apply patches with the "-p1"
2117 option (i.e. one directory level in the path will be stripped
2118 off).
2119 If your patch needs to have more directory levels stripped off,
2120 specify the number of levels using the "striplevel" option in
2121 the <filename>SRC_URI</filename> entry for the patch.
2122 Alternatively, if your patch needs to be applied in a specific
2123 subdirectory that is not specified in the patch file, use the
2124 "patchdir" option in the entry.
2125 </para>
2126
2127 <para>
2128 As with all local files referenced in
2129 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2130 using <filename>file://</filename>, you should place
2131 patch files in a directory next to the recipe either
2132 named the same as the base name of the recipe
2133 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2134 and
2135 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2136 or "files".
2137 </para>
2138 </section>
2139
2140 <section id='new-recipe-licensing'>
2141 <title>Licensing</title>
2142
2143 <para>
2144 Your recipe needs to have both the
2145 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2146 and
2147 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2148 variables:
2149 <itemizedlist>
2150 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2151 This variable specifies the license for the software.
2152 If you do not know the license under which the software
2153 you are building is distributed, you should go to the
2154 source code and look for that information.
2155 Typical files containing this information include
2156 <filename>COPYING</filename>,
2157 <filename>LICENSE</filename>, and
2158 <filename>README</filename> files.
2159 You could also find the information near the top of
2160 a source file.
2161 For example, given a piece of software licensed under
2162 the GNU General Public License version 2, you would
2163 set <filename>LICENSE</filename> as follows:
2164 <literallayout class='monospaced'>
2165 LICENSE = "GPLv2"
2166 </literallayout></para>
2167 <para>The licenses you specify within
2168 <filename>LICENSE</filename> can have any name as long
2169 as you do not use spaces, since spaces are used as
2170 separators between license names.
2171 For standard licenses, use the names of the files in
2172 <filename>meta/files/common-licenses/</filename>
2173 or the <filename>SPDXLICENSEMAP</filename> flag names
2174 defined in <filename>meta/conf/licenses.conf</filename>.
2175 </para></listitem>
2176 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2177 The OpenEmbedded build system uses this variable to
2178 make sure the license text has not changed.
2179 If it has, the build produces an error and it affords
2180 you the chance to figure it out and correct the problem.
2181 </para>
2182 <para>You need to specify all applicable licensing
2183 files for the software.
2184 At the end of the configuration step, the build process
2185 will compare the checksums of the files to be sure
2186 the text has not changed.
2187 Any differences result in an error with the message
2188 containing the current checksum.
2189 For more explanation and examples of how to set the
2190 <filename>LIC_FILES_CHKSUM</filename> variable, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002191 "<link link='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
2192 section.</para>
2193
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002194 <para>To determine the correct checksum string, you
2195 can list the appropriate files in the
2196 <filename>LIC_FILES_CHKSUM</filename> variable with
2197 incorrect md5 strings, attempt to build the software,
2198 and then note the resulting error messages that will
2199 report the correct md5 strings.
2200 See the
2201 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2202 section for additional information.
2203 </para>
2204
2205 <para>
2206 Here is an example that assumes the software has a
2207 <filename>COPYING</filename> file:
2208 <literallayout class='monospaced'>
2209 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2210 </literallayout>
2211 When you try to build the software, the build system
2212 will produce an error and give you the correct string
2213 that you can substitute into the recipe file for a
2214 subsequent build.
2215 </para></listitem>
2216 </itemizedlist>
2217 </para>
2218
2219<!--
2220
2221 <para>
2222 For trying this out I created a new recipe named
2223 <filename>htop_1.0.2.bb</filename> and put it in
2224 <filename>poky/meta/recipes-extended/htop</filename>.
2225 There are two license type statements in my very simple
2226 recipe:
2227 <literallayout class='monospaced'>
2228 LICENSE = ""
2229
2230 LIC_FILES_CHKSUM = ""
2231
2232 SRC_URI[md5sum] = ""
2233 SRC_URI[sha256sum] = ""
2234 </literallayout>
2235 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2236 Next, you delete or comment out the two <filename>SRC_URI</filename>
2237 lines at the end and then attempt to build the software with
2238 <filename>bitbake htop</filename>.
2239 Doing so causes BitBake to report some errors and and give
2240 you the actual strings you need for the last two
2241 <filename>SRC_URI</filename> lines.
2242 Prior to this, you have to dig around in the home page of the
2243 source for <filename>htop</filename> and determine that the
2244 software is released under GPLv2.
2245 You can provide that in the <filename>LICENSE</filename>
2246 statement.
2247 Now you edit your recipe to have those two strings for
2248 the <filename>SRC_URI</filename> statements:
2249 <literallayout class='monospaced'>
2250 LICENSE = "GPLv2"
2251
2252 LIC_FILES_CHKSUM = ""
2253
2254 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2255 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2256 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2257 </literallayout>
2258 At this point, you can build the software again using the
2259 <filename>bitbake htop</filename> command.
2260 There is just a set of errors now associated with the
2261 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2262 </para>
2263-->
2264
2265 </section>
2266
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002267 <section id='new-dependencies'>
2268 <title>Dependencies</title>
2269
2270 <para>
2271 Most software packages have a short list of other packages
2272 that they require, which are called dependencies.
2273 These dependencies fall into two main categories: build-time
2274 dependencies, which are required when the software is built;
2275 and runtime dependencies, which are required to be installed
2276 on the target in order for the software to run.
2277 </para>
2278
2279 <para>
2280 Within a recipe, you specify build-time dependencies using the
2281 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2282 variable.
2283 Although nuances exist, items specified in
2284 <filename>DEPENDS</filename> should be names of other recipes.
2285 It is important that you specify all build-time dependencies
2286 explicitly.
2287 If you do not, due to the parallel nature of BitBake's
2288 execution, you can end up with a race condition where the
2289 dependency is present for one task of a recipe (e.g.
2290 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
2291 and then gone when the next task runs (e.g.
2292 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
2293 </para>
2294
2295 <para>
2296 Another consideration is that configure scripts might
2297 automatically check for optional dependencies and enable
2298 corresponding functionality if those dependencies are found.
2299 This behavior means that to ensure deterministic results and
2300 thus avoid more race conditions, you need to either explicitly
2301 specify these dependencies as well, or tell the configure
2302 script explicitly to disable the functionality.
2303 If you wish to make a recipe that is more generally useful
2304 (e.g. publish the recipe in a layer for others to use),
2305 instead of hard-disabling the functionality, you can use the
2306 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
2307 variable to allow functionality and the corresponding
2308 dependencies to be enabled and disabled easily by other
2309 users of the recipe.
2310 </para>
2311
2312 <para>
2313 Similar to build-time dependencies, you specify runtime
2314 dependencies through a variable -
2315 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
2316 which is package-specific.
2317 All variables that are package-specific need to have the name
2318 of the package added to the end as an override.
2319 Since the main package for a recipe has the same name as the
2320 recipe, and the recipe's name can be found through the
2321 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2322 variable, then you specify the dependencies for the main
2323 package by setting <filename>RDEPENDS_${PN}</filename>.
2324 If the package were named <filename>${PN}-tools</filename>,
2325 then you would set <filename>RDEPENDS_${PN}-tools</filename>,
2326 and so forth.
2327 </para>
2328
2329 <para>
2330 Some runtime dependencies will be set automatically at
2331 packaging time.
2332 These dependencies include any shared library dependencies
2333 (i.e. if a package "example" contains "libexample" and
2334 another package "mypackage" contains a binary that links to
2335 "libexample" then the OpenEmbedded build system will
2336 automatically add a runtime dependency to "mypackage" on
2337 "example").
2338 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002339 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
2340 section in the Yocto Project Overview and Concepts Manual for
2341 further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002342 </para>
2343 </section>
2344
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002345 <section id='new-recipe-configuring-the-recipe'>
2346 <title>Configuring the Recipe</title>
2347
2348 <para>
2349 Most software provides some means of setting build-time
2350 configuration options before compilation.
2351 Typically, setting these options is accomplished by running a
2352 configure script with some options, or by modifying a build
2353 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002354 <note>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002355 As of Yocto Project Release 1.7, some of the core recipes
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002356 that package binary configuration scripts now disable the
2357 scripts due to the scripts previously requiring error-prone
2358 path substitution.
2359 The OpenEmbedded build system uses
2360 <filename>pkg-config</filename> now, which is much more
2361 robust.
2362 You can find a list of the <filename>*-config</filename>
2363 scripts that are disabled list in the
2364 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2365 section in the Yocto Project Reference Manual.
2366 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002367 </para>
2368
2369 <para>
2370 A major part of build-time configuration is about checking for
2371 build-time dependencies and possibly enabling optional
2372 functionality as a result.
2373 You need to specify any build-time dependencies for the
2374 software you are building in your recipe's
2375 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2376 value, in terms of other recipes that satisfy those
2377 dependencies.
2378 You can often find build-time or runtime
2379 dependencies described in the software's documentation.
2380 </para>
2381
2382 <para>
2383 The following list provides configuration items of note based
2384 on how your software is built:
2385 <itemizedlist>
2386 <listitem><para><emphasis>Autotools:</emphasis>
2387 If your source files have a
2388 <filename>configure.ac</filename> file, then your
2389 software is built using Autotools.
2390 If this is the case, you just need to worry about
2391 modifying the configuration.</para>
2392 <para>When using Autotools, your recipe needs to inherit
2393 the
2394 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2395 class and your recipe does not have to contain a
2396 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2397 task.
2398 However, you might still want to make some adjustments.
2399 For example, you can set
2400 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002401 or
2402 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002403 to pass any needed configure options that are specific
2404 to the recipe.</para></listitem>
2405 <listitem><para><emphasis>CMake:</emphasis>
2406 If your source files have a
2407 <filename>CMakeLists.txt</filename> file, then your
2408 software is built using CMake.
2409 If this is the case, you just need to worry about
2410 modifying the configuration.</para>
2411 <para>When you use CMake, your recipe needs to inherit
2412 the
2413 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2414 class and your recipe does not have to contain a
2415 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2416 task.
2417 You can make some adjustments by setting
2418 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2419 to pass any needed configure options that are specific
2420 to the recipe.</para></listitem>
2421 <listitem><para><emphasis>Other:</emphasis>
2422 If your source files do not have a
2423 <filename>configure.ac</filename> or
2424 <filename>CMakeLists.txt</filename> file, then your
2425 software is built using some method other than Autotools
2426 or CMake.
2427 If this is the case, you normally need to provide a
2428 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2429 task in your recipe
2430 unless, of course, there is nothing to configure.
2431 </para>
2432 <para>Even if your software is not being built by
2433 Autotools or CMake, you still might not need to deal
2434 with any configuration issues.
2435 You need to determine if configuration is even a required step.
2436 You might need to modify a Makefile or some configuration file
2437 used for the build to specify necessary build options.
2438 Or, perhaps you might need to run a provided, custom
2439 configure script with the appropriate options.</para>
2440 <para>For the case involving a custom configure
2441 script, you would run
2442 <filename>./configure --help</filename> and look for
2443 the options you need to set.</para></listitem>
2444 </itemizedlist>
2445 </para>
2446
2447 <para>
2448 Once configuration succeeds, it is always good practice to
2449 look at the <filename>log.do_configure</filename> file to
2450 ensure that the appropriate options have been enabled and no
2451 additional build-time dependencies need to be added to
2452 <filename>DEPENDS</filename>.
2453 For example, if the configure script reports that it found
2454 something not mentioned in <filename>DEPENDS</filename>, or
2455 that it did not find something that it needed for some
2456 desired optional functionality, then you would need to add
2457 those to <filename>DEPENDS</filename>.
2458 Looking at the log might also reveal items being checked for,
2459 enabled, or both that you do not want, or items not being found
2460 that are in <filename>DEPENDS</filename>, in which case
2461 you would need to look at passing extra options to the
2462 configure script as needed.
2463 For reference information on configure options specific to the
2464 software you are building, you can consult the output of the
2465 <filename>./configure --help</filename> command within
2466 <filename>${S}</filename> or consult the software's upstream
2467 documentation.
2468 </para>
2469 </section>
2470
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002471 <section id='new-recipe-using-headers-to-interface-with-devices'>
2472 <title>Using Headers to Interface with Devices</title>
2473
2474 <para>
2475 If your recipe builds an application that needs to
2476 communicate with some device or needs an API into a custom
2477 kernel, you will need to provide appropriate header files.
2478 Under no circumstances should you ever modify the existing
2479 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>
2480 file.
2481 These headers are used to build <filename>libc</filename> and
2482 must not be compromised with custom or machine-specific
2483 header information.
2484 If you customize <filename>libc</filename> through modified
2485 headers all other applications that use
2486 <filename>libc</filename> thus become affected.
2487 <note><title>Warning</title>
2488 Never copy and customize the <filename>libc</filename>
2489 header file (i.e.
2490 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>).
2491 </note>
2492 The correct way to interface to a device or custom kernel is
2493 to use a separate package that provides the additional headers
2494 for the driver or other unique interfaces.
2495 When doing so, your application also becomes responsible for
2496 creating a dependency on that specific provider.
2497 </para>
2498
2499 <para>
2500 Consider the following:
2501 <itemizedlist>
2502 <listitem><para>
2503 Never modify
2504 <filename>linux-libc-headers.inc</filename>.
2505 Consider that file to be part of the
2506 <filename>libc</filename> system, and not something
2507 you use to access the kernel directly.
2508 You should access <filename>libc</filename> through
2509 specific <filename>libc</filename> calls.
2510 </para></listitem>
2511 <listitem><para>
2512 Applications that must talk directly to devices
2513 should either provide necessary headers themselves,
2514 or establish a dependency on a special headers package
2515 that is specific to that driver.
2516 </para></listitem>
2517 </itemizedlist>
2518 </para>
2519
2520 <para>
2521 For example, suppose you want to modify an existing header
2522 that adds I/O control or network support.
2523 If the modifications are used by a small number programs,
2524 providing a unique version of a header is easy and has little
2525 impact.
2526 When doing so, bear in mind the guidelines in the previous
2527 list.
2528 <note>
2529 If for some reason your changes need to modify the behavior
2530 of the <filename>libc</filename>, and subsequently all
2531 other applications on the system, use a
2532 <filename>.bbappend</filename> to modify the
2533 <filename>linux-kernel-headers.inc</filename> file.
2534 However, take care to not make the changes
2535 machine specific.
2536 </note>
2537 </para>
2538
2539 <para>
2540 Consider a case where your kernel is older and you need
2541 an older <filename>libc</filename> ABI.
2542 The headers installed by your recipe should still be a
2543 standard mainline kernel, not your own custom one.
2544 </para>
2545
2546 <para>
2547 When you use custom kernel headers you need to get them from
2548 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>,
2549 which is the directory with kernel headers that are
2550 required to build out-of-tree modules.
2551 Your recipe will also need the following:
2552 <literallayout class='monospaced'>
2553 do_configure[depends] += "virtual/kernel:do_shared_workdir"
2554 </literallayout>
2555 </para>
2556 </section>
2557
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002558 <section id='new-recipe-compilation'>
2559 <title>Compilation</title>
2560
2561 <para>
2562 During a build, the <filename>do_compile</filename> task
2563 happens after source is fetched, unpacked, and configured.
2564 If the recipe passes through <filename>do_compile</filename>
2565 successfully, nothing needs to be done.
2566 </para>
2567
2568 <para>
2569 However, if the compile step fails, you need to diagnose the
2570 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002571 Here are some common issues that cause failures.
2572 <note>
2573 For cases where improper paths are detected for
2574 configuration files or for when libraries/headers cannot
2575 be found, be sure you are using the more robust
2576 <filename>pkg-config</filename>.
2577 See the note in section
2578 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2579 for additional information.
2580 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002581 <itemizedlist>
2582 <listitem><para><emphasis>Parallel build failures:</emphasis>
2583 These failures manifest themselves as intermittent
2584 errors, or errors reporting that a file or directory
2585 that should be created by some other part of the build
2586 process could not be found.
2587 This type of failure can occur even if, upon inspection,
2588 the file or directory does exist after the build has
2589 failed, because that part of the build process happened
2590 in the wrong order.</para>
2591 <para>To fix the problem, you need to either satisfy
2592 the missing dependency in the Makefile or whatever
2593 script produced the Makefile, or (as a workaround)
2594 set
2595 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2596 to an empty string:
2597 <literallayout class='monospaced'>
2598 PARALLEL_MAKE = ""
2599 </literallayout></para>
2600 <para>
2601 For information on parallel Makefile issues, see the
2602 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2603 section.
2604 </para></listitem>
2605 <listitem><para><emphasis>Improper host path usage:</emphasis>
2606 This failure applies to recipes building for the target
2607 or <filename>nativesdk</filename> only.
2608 The failure occurs when the compilation process uses
2609 improper headers, libraries, or other files from the
2610 host system when cross-compiling for the target.
2611 </para>
2612 <para>To fix the problem, examine the
2613 <filename>log.do_compile</filename> file to identify
2614 the host paths being used (e.g.
2615 <filename>/usr/include</filename>,
2616 <filename>/usr/lib</filename>, and so forth) and then
2617 either add configure options, apply a patch, or do both.
2618 </para></listitem>
2619 <listitem><para><emphasis>Failure to find required
2620 libraries/headers:</emphasis>
2621 If a build-time dependency is missing because it has
2622 not been declared in
2623 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2624 or because the dependency exists but the path used by
2625 the build process to find the file is incorrect and the
2626 configure step did not detect it, the compilation
2627 process could fail.
2628 For either of these failures, the compilation process
2629 notes that files could not be found.
2630 In these cases, you need to go back and add additional
2631 options to the configure script as well as possibly
2632 add additional build-time dependencies to
2633 <filename>DEPENDS</filename>.</para>
2634 <para>Occasionally, it is necessary to apply a patch
2635 to the source to ensure the correct paths are used.
2636 If you need to specify paths to find files staged
2637 into the sysroot from other recipes, use the variables
2638 that the OpenEmbedded build system provides
2639 (e.g.
2640 <filename>STAGING_BINDIR</filename>,
2641 <filename>STAGING_INCDIR</filename>,
2642 <filename>STAGING_DATADIR</filename>, and so forth).
2643<!--
2644 (e.g.
2645 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2646 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2647 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2648 and so forth).
2649-->
2650 </para></listitem>
2651 </itemizedlist>
2652 </para>
2653 </section>
2654
2655 <section id='new-recipe-installing'>
2656 <title>Installing</title>
2657
2658 <para>
2659 During <filename>do_install</filename>, the task copies the
2660 built files along with their hierarchy to locations that
2661 would mirror their locations on the target device.
2662 The installation process copies files from the
2663 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2664 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2665 and
2666 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2667 directories to the
2668 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2669 directory to create the structure as it should appear on the
2670 target system.
2671 </para>
2672
2673 <para>
2674 How your software is built affects what you must do to be
2675 sure your software is installed correctly.
2676 The following list describes what you must do for installation
2677 depending on the type of build system used by the software
2678 being built:
2679 <itemizedlist>
2680 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2681 If the software your recipe is building uses Autotools
2682 or CMake, the OpenEmbedded build
2683 system understands how to install the software.
2684 Consequently, you do not have to have a
2685 <filename>do_install</filename> task as part of your
2686 recipe.
2687 You just need to make sure the install portion of the
2688 build completes with no issues.
2689 However, if you wish to install additional files not
2690 already being installed by
2691 <filename>make install</filename>, you should do this
2692 using a <filename>do_install_append</filename> function
2693 using the install command as described in
2694 the "Manual" bulleted item later in this list.
2695 </para></listitem>
2696 <listitem><para><emphasis>Other (using
2697 <filename>make install</filename>):</emphasis>
2698 You need to define a
2699 <filename>do_install</filename> function in your
2700 recipe.
2701 The function should call
2702 <filename>oe_runmake install</filename> and will likely
2703 need to pass in the destination directory as well.
2704 How you pass that path is dependent on how the
2705 <filename>Makefile</filename> being run is written
2706 (e.g. <filename>DESTDIR=${D}</filename>,
2707 <filename>PREFIX=${D}</filename>,
2708 <filename>INSTALLROOT=${D}</filename>, and so forth).
2709 </para>
2710 <para>For an example recipe using
2711 <filename>make install</filename>, see the
2712 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2713 section.</para></listitem>
2714 <listitem><para><emphasis>Manual:</emphasis>
2715 You need to define a
2716 <filename>do_install</filename> function in your
2717 recipe.
2718 The function must first use
2719 <filename>install -d</filename> to create the
2720 directories under
2721 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2722 Once the directories exist, your function can use
2723 <filename>install</filename> to manually install the
2724 built software into the directories.</para>
2725 <para>You can find more information on
2726 <filename>install</filename> at
2727 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2728 </para></listitem>
2729 </itemizedlist>
2730 </para>
2731
2732 <para>
2733 For the scenarios that do not use Autotools or
2734 CMake, you need to track the installation
2735 and diagnose and fix any issues until everything installs
2736 correctly.
2737 You need to look in the default location of
2738 <filename>${D}</filename>, which is
2739 <filename>${WORKDIR}/image</filename>, to be sure your
2740 files have been installed correctly.
2741 </para>
2742
2743 <note><title>Notes</title>
2744 <itemizedlist>
2745 <listitem><para>
2746 During the installation process, you might need to
2747 modify some of the installed files to suit the target
2748 layout.
2749 For example, you might need to replace hard-coded paths
2750 in an initscript with values of variables provided by
2751 the build system, such as replacing
2752 <filename>/usr/bin/</filename> with
2753 <filename>${bindir}</filename>.
2754 If you do perform such modifications during
2755 <filename>do_install</filename>, be sure to modify the
2756 destination file after copying rather than before
2757 copying.
2758 Modifying after copying ensures that the build system
2759 can re-execute <filename>do_install</filename> if
2760 needed.
2761 </para></listitem>
2762 <listitem><para>
2763 <filename>oe_runmake install</filename>, which can be
2764 run directly or can be run indirectly by the
2765 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2766 and
2767 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2768 classes, runs <filename>make install</filename> in
2769 parallel.
2770 Sometimes, a Makefile can have missing dependencies
2771 between targets that can result in race conditions.
2772 If you experience intermittent failures during
2773 <filename>do_install</filename>, you might be able to
2774 work around them by disabling parallel Makefile
2775 installs by adding the following to the recipe:
2776 <literallayout class='monospaced'>
2777 PARALLEL_MAKEINST = ""
2778 </literallayout>
2779 See
2780 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2781 for additional information.
2782 </para></listitem>
2783 </itemizedlist>
2784 </note>
2785 </section>
2786
2787 <section id='new-recipe-enabling-system-services'>
2788 <title>Enabling System Services</title>
2789
2790 <para>
2791 If you want to install a service, which is a process that
2792 usually starts on boot and runs in the background, then
2793 you must include some additional definitions in your recipe.
2794 </para>
2795
2796 <para>
2797 If you are adding services and the service initialization
2798 script or the service file itself is not installed, you must
2799 provide for that installation in your recipe using a
2800 <filename>do_install_append</filename> function.
2801 If your recipe already has a <filename>do_install</filename>
2802 function, update the function near its end rather than
2803 adding an additional <filename>do_install_append</filename>
2804 function.
2805 </para>
2806
2807 <para>
2808 When you create the installation for your services, you need
2809 to accomplish what is normally done by
2810 <filename>make install</filename>.
2811 In other words, make sure your installation arranges the output
2812 similar to how it is arranged on the target system.
2813 </para>
2814
2815 <para>
2816 The OpenEmbedded build system provides support for starting
2817 services two different ways:
2818 <itemizedlist>
2819 <listitem><para><emphasis>SysVinit:</emphasis>
2820 SysVinit is a system and service manager that
2821 manages the init system used to control the very basic
2822 functions of your system.
2823 The init program is the first program
2824 started by the Linux kernel when the system boots.
2825 Init then controls the startup, running and shutdown
2826 of all other programs.</para>
2827 <para>To enable a service using SysVinit, your recipe
2828 needs to inherit the
2829 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2830 class.
2831 The class helps facilitate safely installing the
2832 package on the target.</para>
2833 <para>You will need to set the
2834 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2835 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2836 and
2837 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2838 variables within your recipe.</para></listitem>
2839 <listitem><para><emphasis>systemd:</emphasis>
2840 System Management Daemon (systemd) was designed to
2841 replace SysVinit and to provide
2842 enhanced management of services.
2843 For more information on systemd, see the systemd
2844 homepage at
2845 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2846 </para>
2847 <para>To enable a service using systemd, your recipe
2848 needs to inherit the
2849 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2850 class.
2851 See the <filename>systemd.bbclass</filename> file
2852 located in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002853 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002854 section for more information.
2855 </para></listitem>
2856 </itemizedlist>
2857 </para>
2858 </section>
2859
2860 <section id='new-recipe-packaging'>
2861 <title>Packaging</title>
2862
2863 <para>
2864 Successful packaging is a combination of automated processes
2865 performed by the OpenEmbedded build system and some
2866 specific steps you need to take.
2867 The following list describes the process:
2868 <itemizedlist>
2869 <listitem><para><emphasis>Splitting Files</emphasis>:
2870 The <filename>do_package</filename> task splits the
2871 files produced by the recipe into logical components.
2872 Even software that produces a single binary might
2873 still have debug symbols, documentation, and other
2874 logical components that should be split out.
2875 The <filename>do_package</filename> task ensures
2876 that files are split up and packaged correctly.
2877 </para></listitem>
2878 <listitem><para><emphasis>Running QA Checks</emphasis>:
2879 The
2880 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2881 class adds a step to
2882 the package generation process so that output quality
2883 assurance checks are generated by the OpenEmbedded
2884 build system.
2885 This step performs a range of checks to be sure the
2886 build's output is free of common problems that show
2887 up during runtime.
2888 For information on these checks, see the
2889 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2890 class and the
2891 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2892 chapter in the Yocto Project Reference Manual.
2893 </para></listitem>
2894 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2895 After you build your software, you need to be sure
2896 your packages are correct.
2897 Examine the
2898 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2899 directory and make sure files are where you expect
2900 them to be.
2901 If you discover problems, you can set
2902 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2903 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2904 <filename>do_install(_append)</filename>, and so forth as
2905 needed.
2906 </para></listitem>
2907 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2908 If you need to split an application into several
2909 packages, see the
2910 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2911 section for an example.
2912 </para></listitem>
2913 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2914 For an example showing how to install a
2915 post-installation script, see the
2916 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2917 section.
2918 </para></listitem>
2919 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2920 Depending on what your recipe is building and how it
2921 is configured, it might be important to mark the
2922 packages produced as being specific to a particular
2923 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002924 a particular machine or architecture at all.</para>
2925 <para>By default, packages apply to any machine with the
2926 same architecture as the target machine.
2927 When a recipe produces packages that are
2928 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002929 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2930 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002931 is applied only for a particular machine), you should
2932 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002933 recipe:
2934 <literallayout class='monospaced'>
2935 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002936 </literallayout></para>
2937 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002938 that do not contain anything specific to the target
2939 machine or architecture at all (e.g. recipes
2940 that simply package script files or configuration
2941 files), you should use the
2942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
2943 class to do this for you by adding this to your
2944 recipe:
2945 <literallayout class='monospaced'>
2946 inherit allarch
2947 </literallayout>
2948 Ensuring that the package architecture is correct is
2949 not critical while you are doing the first few builds
2950 of your recipe.
2951 However, it is important in order
2952 to ensure that your recipe rebuilds (or does not
2953 rebuild) appropriately in response to changes in
2954 configuration, and to ensure that you get the
2955 appropriate packages installed on the target machine,
2956 particularly if you run separate builds for more
2957 than one target machine.
2958 </para></listitem>
2959 </itemizedlist>
2960 </para>
2961 </section>
2962
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002963 <section id='new-sharing-files-between-recipes'>
2964 <title>Sharing Files Between Recipes</title>
2965
2966 <para>
2967 Recipes often need to use files provided by other recipes on
2968 the build host.
2969 For example, an application linking to a common library needs
2970 access to the library itself and its associated headers.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002971 The way this access is accomplished is by populating a sysroot
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002972 with files.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002973 Each recipe has two sysroots in its work directory, one for
2974 target files
2975 (<filename>recipe-sysroot</filename>) and one for files that
2976 are native to the build host
2977 (<filename>recipe-sysroot-native</filename>).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002978 <note>
2979 You could find the term "staging" used within the Yocto
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002980 project regarding files populating sysroots (e.g. the
Brad Bishop37a0e4d2017-12-04 01:01:44 -05002981 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink>
2982 variable).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002983 </note>
2984 </para>
2985
2986 <para>
2987 Recipes should never populate the sysroot directly (i.e. write
2988 files into sysroot).
2989 Instead, files should be installed into standard locations
2990 during the
2991 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2992 task within the
2993 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2994 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002995 The reason for this limitation is that almost all files that
2996 populate the sysroot are cataloged in manifests in order to
2997 ensure the files can be removed later when a recipe is either
2998 modified or removed.
2999 Thus, the sysroot is able to remain free from stale files.
3000 </para>
3001
3002 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003003 A subset of the files installed by the
3004 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3005 task are used by the
3006 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3007 task as defined by the the
3008 <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>
3009 variable to automatically populate the sysroot.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003010 It is possible to modify the list of directories that populate
3011 the sysroot.
3012 The following example shows how you could add the
3013 <filename>/opt</filename> directory to the list of
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003014 directories within a recipe:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003015 <literallayout class='monospaced'>
3016 SYSROOT_DIRS += "/opt"
3017 </literallayout>
3018 </para>
3019
3020 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003021 For a more complete description of the
3022 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3023 task and its associated functions, see the
3024 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink>
3025 class.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003026 </para>
3027 </section>
3028
Brad Bishop316dfdd2018-06-25 12:45:53 -04003029 <section id='metadata-virtual-providers'>
3030 <title>Using Virtual Providers</title>
3031
3032 <para>
3033 Prior to a build, if you know that several different recipes
3034 provide the same functionality, you can use a virtual provider
3035 (i.e. <filename>virtual/*</filename>) as a placeholder for the
3036 actual provider.
3037 The actual provider is determined at build-time.
3038 </para>
3039
3040 <para>
3041 A common scenario where a virtual provider is used would be
3042 for the kernel recipe.
3043 Suppose you have three kernel recipes whose
3044 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
3045 values map to <filename>kernel-big</filename>,
3046 <filename>kernel-mid</filename>, and
3047 <filename>kernel-small</filename>.
3048 Furthermore, each of these recipes in some way uses a
3049 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3050 statement that essentially identifies itself as being able
3051 to provide <filename>virtual/kernel</filename>.
3052 Here is one way through the
3053 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-kernel'><filename>kernel</filename></ulink>
3054 class:
3055 <literallayout class='monospaced'>
3056 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
3057 </literallayout>
3058 Any recipe that inherits the <filename>kernel</filename> class
3059 is going to utilize a <filename>PROVIDES</filename> statement
3060 that identifies that recipe as being able to provide the
3061 <filename>virtual/kernel</filename> item.
3062 </para>
3063
3064 <para>
3065 Now comes the time to actually build an image and you need a
3066 kernel recipe, but which one?
3067 You can configure your build to call out the kernel recipe
3068 you want by using the
3069 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></ulink>
3070 variable.
3071 As an example, consider the
3072 <ulink url='https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc'><filename>x86-base.inc</filename></ulink>
3073 include file, which is a machine
3074 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>)
3075 configuration file.
3076 This include file is the reason all x86-based machines use the
3077 <filename>linux-yocto</filename> kernel.
3078 Here are the relevant lines from the include file:
3079 <literallayout class='monospaced'>
3080 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
3081 PREFERRED_VERSION_linux-yocto ??= "4.15%"
3082 </literallayout>
3083 </para>
3084
3085 <para>
3086 When you use a virtual provider, you do not have to
3087 "hard code" a recipe name as a build dependency.
3088 You can use the
3089 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3090 variable to state the build is dependent on
3091 <filename>virtual/kernel</filename> for example:
3092 <literallayout class='monospaced'>
3093 DEPENDS = "virtual/kernel"
3094 </literallayout>
3095 During the build, the OpenEmbedded build system picks
3096 the correct recipe needed for the
3097 <filename>virtual/kernel</filename> dependency based on the
3098 <filename>PREFERRED_PROVIDER</filename> variable.
3099 If you want to use the small kernel mentioned at the beginning
3100 of this section, configure your build as follows:
3101 <literallayout class='monospaced'>
3102 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
3103 </literallayout>
3104 <note>
3105 Any recipe that
3106 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3107 a <filename>virtual/*</filename> item that is ultimately
3108 not selected through
3109 <filename>PREFERRED_PROVIDER</filename> does not get built.
3110 Preventing these recipes from building is usually the
3111 desired behavior since this mechanism's purpose is to
3112 select between mutually exclusive alternative providers.
3113 </note>
3114 </para>
3115
3116 <para>
3117 The following lists specific examples of virtual providers:
3118 <itemizedlist>
3119 <listitem><para>
3120 <filename>virtual/kernel</filename>:
3121 Provides the name of the kernel recipe to use when
3122 building a kernel image.
3123 </para></listitem>
3124 <listitem><para>
3125 <filename>virtual/bootloader</filename>:
3126 Provides the name of the bootloader to use when
3127 building an image.
3128 </para></listitem>
3129 <listitem><para>
3130 <filename>virtual/mesa</filename>:
3131 Provides <filename>gbm.pc</filename>.
3132 </para></listitem>
3133 <listitem><para>
3134 <filename>virtual/egl</filename>:
3135 Provides <filename>egl.pc</filename> and possibly
3136 <filename>wayland-egl.pc</filename>.
3137 </para></listitem>
3138 <listitem><para>
3139 <filename>virtual/libgl</filename>:
3140 Provides <filename>gl.pc</filename> (i.e. libGL).
3141 </para></listitem>
3142 <listitem><para>
3143 <filename>virtual/libgles1</filename>:
3144 Provides <filename>glesv1_cm.pc</filename>
3145 (i.e. libGLESv1_CM).
3146 </para></listitem>
3147 <listitem><para>
3148 <filename>virtual/libgles2</filename>:
3149 Provides <filename>glesv2.pc</filename>
3150 (i.e. libGLESv2).
3151 </para></listitem>
3152 </itemizedlist>
3153 </para>
3154 </section>
3155
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003156 <section id='properly-versioning-pre-release-recipes'>
3157 <title>Properly Versioning Pre-Release Recipes</title>
3158
3159 <para>
3160 Sometimes the name of a recipe can lead to versioning
3161 problems when the recipe is upgraded to a final release.
3162 For example, consider the
3163 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
3164 the list of example recipes in the
3165 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
3166 section.
3167 This recipe is at a release candidate stage (i.e.
3168 "rc1").
3169 When the recipe is released, the recipe filename becomes
3170 <filename>irssi_0.8.16.bb</filename>.
3171 The version change from <filename>0.8.16-rc1</filename>
3172 to <filename>0.8.16</filename> is seen as a decrease by the
3173 build system and package managers, so the resulting packages
3174 will not correctly trigger an upgrade.
3175 </para>
3176
3177 <para>
3178 In order to ensure the versions compare properly, the
3179 recommended convention is to set
3180 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
3181 within the recipe to
3182 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
3183 You can use an additional variable so that you can use the
3184 current version elsewhere.
3185 Here is an example:
3186 <literallayout class='monospaced'>
3187 REALPV = "0.8.16-rc1"
3188 PV = "0.8.15+${REALPV}"
3189 </literallayout>
3190 </para>
3191 </section>
3192
3193 <section id='new-recipe-post-installation-scripts'>
3194 <title>Post-Installation Scripts</title>
3195
3196 <para>
3197 Post-installation scripts run immediately after installing
3198 a package on the target or during image creation when a
3199 package is included in an image.
3200 To add a post-installation script to a package, add a
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003201 <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003202 the recipe file (<filename>.bb</filename>) and replace
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003203 <replaceable>PACKAGENAME</replaceable> with the name of the package
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003204 you want to attach to the <filename>postinst</filename>
3205 script.
3206 To apply the post-installation script to the main package
3207 for the recipe, which is usually what is required, specify
3208 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003209 in place of <replaceable>PACKAGENAME</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003210 </para>
3211
3212 <para>
3213 A post-installation function has the following structure:
3214 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003215 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003216 # Commands to carry out
3217 }
3218 </literallayout>
3219 </para>
3220
3221 <para>
3222 The script defined in the post-installation function is
3223 called when the root filesystem is created.
3224 If the script succeeds, the package is marked as installed.
3225 If the script fails, the package is marked as unpacked and
3226 the script is executed when the image boots again.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003227 <note>
3228 Any RPM post-installation script that runs on the target
3229 should return a 0 exit code.
3230 RPM does not allow non-zero exit codes for these scripts,
3231 and the RPM package manager will cause the package to fail
3232 installation on the target.
3233 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003234 </para>
3235
3236 <para>
3237 Sometimes it is necessary for the execution of a
3238 post-installation script to be delayed until the first boot.
3239 For example, the script might need to be executed on the
3240 device itself.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003241 To delay script execution until boot time, you must explicitly
3242 mark post installs to defer to the target.
3243 You can use <filename>pkg_postinst_ontarget()</filename> or
3244 call
3245 <filename>postinst-intercepts defer_to_first_boot</filename>
3246 from <filename>pkg_postinst()</filename>.
3247 Any failure of a <filename>pkg_postinst()</filename> script
3248 (including exit 1) triggers an error during the
3249 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
3250 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003251 </para>
3252
3253 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003254 If you have recipes that use
3255 <filename>pkg_postinst</filename> function
3256 and they require the use of non-standard native
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003257 tools that have dependencies during rootfs construction, you
3258 need to use the
3259 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3260 variable in your recipe to list these tools.
3261 If you do not use this variable, the tools might be missing and
3262 execution of the post-installation script is deferred until
3263 first boot.
3264 Deferring the script to first boot is undesirable and for
3265 read-only rootfs impossible.
3266 </para>
3267
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003268 <note>
3269 Equivalent support for pre-install, pre-uninstall, and
3270 post-uninstall scripts exist by way of
3271 <filename>pkg_preinst</filename>,
3272 <filename>pkg_prerm</filename>, and
3273 <filename>pkg_postrm</filename>, respectively.
3274 These scrips work in exactly the same way as does
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003275 <filename>pkg_postinst</filename> with the exception
3276 that they run at different times.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003277 Also, because of when they run, they are not applicable to
3278 being run at image creation time like
3279 <filename>pkg_postinst</filename>.
3280 </note>
3281 </section>
3282
3283 <section id='new-recipe-testing'>
3284 <title>Testing</title>
3285
3286 <para>
3287 The final step for completing your recipe is to be sure that
3288 the software you built runs correctly.
3289 To accomplish runtime testing, add the build's output
3290 packages to your image and test them on the target.
3291 </para>
3292
3293 <para>
3294 For information on how to customize your image by adding
3295 specific packages, see the
3296 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3297 section.
3298 </para>
3299 </section>
3300
3301 <section id='new-recipe-testing-examples'>
3302 <title>Examples</title>
3303
3304 <para>
3305 To help summarize how to write a recipe, this section provides
3306 some examples given various scenarios:
3307 <itemizedlist>
3308 <listitem><para>Recipes that use local files</para></listitem>
3309 <listitem><para>Using an Autotooled package</para></listitem>
3310 <listitem><para>Using a Makefile-based package</para></listitem>
3311 <listitem><para>Splitting an application into multiple packages</para></listitem>
3312 <listitem><para>Adding binaries to an image</para></listitem>
3313 </itemizedlist>
3314 </para>
3315
3316 <section id='new-recipe-single-c-file-package-hello-world'>
3317 <title>Single .c File Package (Hello World!)</title>
3318
3319 <para>
3320 Building an application from a single file that is stored
3321 locally (e.g. under <filename>files</filename>) requires
3322 a recipe that has the file listed in the
3323 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3324 variable.
3325 Additionally, you need to manually write the
3326 <filename>do_compile</filename> and
3327 <filename>do_install</filename> tasks.
3328 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3329 variable defines the directory containing the source code,
3330 which is set to
3331 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3332 in this case - the directory BitBake uses for the build.
3333 <literallayout class='monospaced'>
3334 SUMMARY = "Simple helloworld application"
3335 SECTION = "examples"
3336 LICENSE = "MIT"
3337 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3338
3339 SRC_URI = "file://helloworld.c"
3340
3341 S = "${WORKDIR}"
3342
3343 do_compile() {
3344 ${CC} helloworld.c -o helloworld
3345 }
3346
3347 do_install() {
3348 install -d ${D}${bindir}
3349 install -m 0755 helloworld ${D}${bindir}
3350 }
3351 </literallayout>
3352 </para>
3353
3354 <para>
3355 By default, the <filename>helloworld</filename>,
3356 <filename>helloworld-dbg</filename>, and
3357 <filename>helloworld-dev</filename> packages are built.
3358 For information on how to customize the packaging process,
3359 see the
3360 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3361 section.
3362 </para>
3363 </section>
3364
3365 <section id='new-recipe-autotooled-package'>
3366 <title>Autotooled Package</title>
3367 <para>
3368 Applications that use Autotools such as <filename>autoconf</filename> and
3369 <filename>automake</filename> require a recipe that has a source archive listed in
3370 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3371 also inherit the
3372 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3373 class, which contains the definitions of all the steps
3374 needed to build an Autotool-based application.
3375 The result of the build is automatically packaged.
3376 And, if the application uses NLS for localization, packages with local information are
3377 generated (one package per language).
3378 Following is one example: (<filename>hello_2.3.bb</filename>)
3379 <literallayout class='monospaced'>
3380 SUMMARY = "GNU Helloworld application"
3381 SECTION = "examples"
3382 LICENSE = "GPLv2+"
3383 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3384
3385 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3386
3387 inherit autotools gettext
3388 </literallayout>
3389 </para>
3390
3391 <para>
3392 The variable
3393 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3394 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003395 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3396 section in the Yocto Project Overview and Concepts Manual.
3397 You can quickly create Autotool-based recipes in a manner
3398 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003399 </para>
3400 </section>
3401
3402 <section id='new-recipe-makefile-based-package'>
3403 <title>Makefile-Based Package</title>
3404
3405 <para>
3406 Applications that use GNU <filename>make</filename> also require a recipe that has
3407 the source archive listed in
3408 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3409 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3410 starts the <filename>make</filename> command to compile the application.
3411 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003412 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3413 or
3414 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3415 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003416 BitBake passes these options into the GNU <filename>make</filename> invocation.
3417 Note that a <filename>do_install</filename> task is still required.
3418 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3419 </para>
3420
3421 <para>
3422 Some applications might require extra parameters to be passed to the compiler.
3423 For example, the application might need an additional header path.
3424 You can accomplish this by adding to the
3425 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3426 The following example shows this:
3427 <literallayout class='monospaced'>
3428 CFLAGS_prepend = "-I ${S}/include "
3429 </literallayout>
3430 </para>
3431
3432 <para>
3433 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3434 <literallayout class='monospaced'>
3435 SUMMARY = "Tools for managing memory technology devices"
3436 SECTION = "base"
3437 DEPENDS = "zlib lzo e2fsprogs util-linux"
3438 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3439 LICENSE = "GPLv2+"
3440 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3441 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3442
3443 # Use the latest version at 26 Oct, 2013
3444 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3445 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3446 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3447 "
3448
3449 PV = "1.5.1+git${SRCPV}"
3450
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003451 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003452
3453 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3454
3455 do_install () {
3456 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3457 }
3458
3459 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3460
3461 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3462 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3463 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3464
3465 PARALLEL_MAKE = ""
3466
3467 BBCLASSEXTEND = "native"
3468 </literallayout>
3469 </para>
3470 </section>
3471
3472 <section id='splitting-an-application-into-multiple-packages'>
3473 <title>Splitting an Application into Multiple Packages</title>
3474
3475 <para>
3476 You can use the variables
3477 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3478 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3479 to split an application into multiple packages.
3480 </para>
3481
3482 <para>
3483 Following is an example that uses the <filename>libxpm</filename> recipe.
3484 By default, this recipe generates a single package that contains the library along
3485 with a few binaries.
3486 You can modify the recipe to split the binaries into separate packages:
3487 <literallayout class='monospaced'>
3488 require xorg-lib-common.inc
3489
3490 SUMMARY = "Xpm: X Pixmap extension library"
3491 LICENSE = "BSD"
3492 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3493 DEPENDS += "libxext libsm libxt"
3494 PE = "1"
3495
3496 XORG_PN = "libXpm"
3497
3498 PACKAGES =+ "sxpm cxpm"
3499 FILES_cxpm = "${bindir}/cxpm"
3500 FILES_sxpm = "${bindir}/sxpm"
3501 </literallayout>
3502 </para>
3503
3504 <para>
3505 In the previous example, we want to ship the <filename>sxpm</filename>
3506 and <filename>cxpm</filename> binaries in separate packages.
3507 Since <filename>bindir</filename> would be packaged into the main
3508 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3509 package by default, we prepend the <filename>PACKAGES</filename>
3510 variable so additional package names are added to the start of list.
3511 This results in the extra <filename>FILES_*</filename>
3512 variables then containing information that define which files and
3513 directories go into which packages.
3514 Files included by earlier packages are skipped by latter packages.
3515 Thus, the main <filename>PN</filename> package
3516 does not include the above listed files.
3517 </para>
3518 </section>
3519
3520 <section id='packaging-externally-produced-binaries'>
3521 <title>Packaging Externally Produced Binaries</title>
3522
3523 <para>
3524 Sometimes, you need to add pre-compiled binaries to an
3525 image.
3526 For example, suppose that binaries for proprietary code
3527 exist, which are created by a particular division of a
3528 company.
3529 Your part of the company needs to use those binaries as
3530 part of an image that you are building using the
3531 OpenEmbedded build system.
3532 Since you only have the binaries and not the source code,
3533 you cannot use a typical recipe that expects to fetch the
3534 source specified in
3535 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3536 and then compile it.
3537 </para>
3538
3539 <para>
3540 One method is to package the binaries and then install them
3541 as part of the image.
3542 Generally, it is not a good idea to package binaries
3543 since, among other things, it can hinder the ability to
3544 reproduce builds and could lead to compatibility problems
3545 with ABI in the future.
3546 However, sometimes you have no choice.
3547 </para>
3548
3549 <para>
3550 The easiest solution is to create a recipe that uses
3551 the
3552 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3553 class and to be sure that you are using default locations
3554 for build artifacts.
3555 In most cases, the <filename>bin_package</filename> class
3556 handles "skipping" the configure and compile steps as well
3557 as sets things up to grab packages from the appropriate
3558 area.
3559 In particular, this class sets <filename>noexec</filename>
3560 on both the
3561 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3562 and
3563 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3564 tasks, sets
3565 <filename>FILES_${PN}</filename> to "/" so that it picks
3566 up all files, and sets up a
3567 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3568 task, which effectively copies all files from
3569 <filename>${S}</filename> to <filename>${D}</filename>.
3570 The <filename>bin_package</filename> class works well when
3571 the files extracted into <filename>${S}</filename> are
3572 already laid out in the way they should be laid out
3573 on the target.
3574 For more information on these variables, see the
3575 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3576 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3577 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3578 and
3579 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3580 variables in the Yocto Project Reference Manual's variable
3581 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003582 <note><title>Notes</title>
3583 <itemizedlist>
3584 <listitem><para>
3585 Using
3586 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3587 is a good idea even for components distributed
3588 in binary form, and is often necessary for
3589 shared libraries.
3590 For a shared library, listing the library
3591 dependencies in
3592 <filename>DEPENDS</filename> makes sure that
3593 the libraries are available in the staging
3594 sysroot when other recipes link against the
3595 library, which might be necessary for
3596 successful linking.
3597 </para></listitem>
3598 <listitem><para>
3599 Using <filename>DEPENDS</filename> also
3600 allows runtime dependencies between packages
3601 to be added automatically.
3602 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003603 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3604 section in the Yocto Project Overview and
3605 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003606 </para></listitem>
3607 </itemizedlist>
3608 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003609 </para>
3610
3611 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003612 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003613 class, you need to be sure you are doing the following:
3614 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003615 <listitem><para>
3616 Create a recipe where the
3617 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3618 and
3619 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3620 tasks do nothing:
3621 It is usually sufficient to just not define these
3622 tasks in the recipe, because the default
3623 implementations do nothing unless a Makefile is
3624 found in
3625 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3626 </para>
3627
3628 <para>If
3629 <filename>${S}</filename> might contain a Makefile,
3630 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003631 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003632 <filename>do_compile</filename> with custom
3633 versions, then you can use the
3634 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3635 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003636 <literallayout class='monospaced'>
3637 do_configure[noexec] = "1"
3638 do_compile[noexec] = "1"
3639 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003640 Unlike
3641 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3642 using the flag preserves the dependency chain from
3643 the
3644 <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>,
3645 and
3646 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3647 tasks to the
3648 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3649 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003650 </para></listitem>
3651 <listitem><para>Make sure your
3652 <filename>do_install</filename> task installs the
3653 binaries appropriately.
3654 </para></listitem>
3655 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003656 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3657 (usually
3658 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3659 to point to the files you have installed, which of
3660 course depends on where you have installed them
3661 and whether those files are in different locations
3662 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003663 </para></listitem>
3664 </itemizedlist>
3665 </para>
3666 </section>
3667 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003668
3669 <section id="following-recipe-style-guidelines">
3670 <title>Following Recipe Style Guidelines</title>
3671
3672 <para>
3673 When writing recipes, it is good to conform to existing
3674 style guidelines.
3675 The
3676 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3677 wiki page provides rough guidelines for preferred recipe style.
3678 </para>
3679
3680 <para>
3681 It is common for existing recipes to deviate a bit from this
3682 style.
3683 However, aiming for at least a consistent style is a good idea.
3684 Some practices, such as omitting spaces around
3685 <filename>=</filename> operators in assignments or ordering
3686 recipe components in an erratic way, are widely seen as poor
3687 style.
3688 </para>
3689 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003690
3691 <section id='recipe-syntax'>
3692 <title>Recipe Syntax</title>
3693
3694 <para>
3695 Understanding recipe file syntax is important for writing
3696 recipes.
3697 The following list overviews the basic items that make up a
3698 BitBake recipe file.
3699 For more complete BitBake syntax descriptions, see the
3700 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3701 chapter of the BitBake User Manual.
3702 <itemizedlist>
3703 <listitem><para>
3704 <emphasis>Variable Assignments and Manipulations:</emphasis>
3705 Variable assignments allow a value to be assigned to a
3706 variable.
3707 The assignment can be static text or might include
3708 the contents of other variables.
3709 In addition to the assignment, appending and prepending
3710 operations are also supported.</para>
3711
3712 <para>The following example shows some of the ways
3713 you can use variables in recipes:
3714 <literallayout class='monospaced'>
3715 S = "${WORKDIR}/postfix-${PV}"
3716 CFLAGS += "-DNO_ASM"
3717 SRC_URI_append = " file://fixup.patch"
3718 </literallayout>
3719 </para></listitem>
3720 <listitem><para>
3721 <emphasis>Functions:</emphasis>
3722 Functions provide a series of actions to be performed.
3723 You usually use functions to override the default
3724 implementation of a task function or to complement
3725 a default function (i.e. append or prepend to an
3726 existing function).
3727 Standard functions use <filename>sh</filename> shell
3728 syntax, although access to OpenEmbedded variables and
3729 internal methods are also available.</para>
3730
3731 <para>The following is an example function from the
3732 <filename>sed</filename> recipe:
3733 <literallayout class='monospaced'>
3734 do_install () {
3735 autotools_do_install
3736 install -d ${D}${base_bindir}
3737 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3738 rmdir ${D}${bindir}/
3739 }
3740 </literallayout>
3741 It is also possible to implement new functions that
3742 are called between existing tasks as long as the
3743 new functions are not replacing or complementing the
3744 default functions.
3745 You can implement functions in Python
3746 instead of shell.
3747 Both of these options are not seen in the majority of
3748 recipes.
3749 </para></listitem>
3750 <listitem><para><emphasis>Keywords:</emphasis>
3751 BitBake recipes use only a few keywords.
3752 You use keywords to include common
3753 functions (<filename>inherit</filename>), load parts
3754 of a recipe from other files
3755 (<filename>include</filename> and
3756 <filename>require</filename>) and export variables
3757 to the environment (<filename>export</filename>).
3758 </para>
3759
3760 <para>The following example shows the use of some of
3761 these keywords:
3762 <literallayout class='monospaced'>
3763 export POSTCONF = "${STAGING_BINDIR}/postconf"
3764 inherit autoconf
3765 require otherfile.inc
3766 </literallayout>
3767 </para></listitem>
3768 <listitem><para>
3769 <emphasis>Comments (#):</emphasis>
3770 Any lines that begin with the hash character
3771 (<filename>#</filename>) are treated as comment lines
3772 and are ignored:
3773 <literallayout class='monospaced'>
3774 # This is a comment
3775 </literallayout>
3776 </para></listitem>
3777 </itemizedlist>
3778 </para>
3779
3780 <para>
3781 This next list summarizes the most important and most commonly
3782 used parts of the recipe syntax.
3783 For more information on these parts of the syntax, you can
3784 reference the
3785 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3786 chapter in the BitBake User Manual.
3787 <itemizedlist>
3788 <listitem><para>
3789 <emphasis>Line Continuation (\):</emphasis>
3790 Use the backward slash (<filename>\</filename>)
3791 character to split a statement over multiple lines.
3792 Place the slash character at the end of the line that
3793 is to be continued on the next line:
3794 <literallayout class='monospaced'>
3795 VAR = "A really long \
3796 line"
3797 </literallayout>
3798 <note>
3799 You cannot have any characters including spaces
3800 or tabs after the slash character.
3801 </note>
3802 </para></listitem>
3803 <listitem><para>
3804 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3805 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3806 syntax to access the contents of a variable:
3807 <literallayout class='monospaced'>
3808 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3809 </literallayout>
3810 <note>
3811 It is important to understand that the value of a
3812 variable expressed in this form does not get
3813 substituted automatically.
3814 The expansion of these expressions happens
3815 on-demand later (e.g. usually when a function that
3816 makes reference to the variable executes).
3817 This behavior ensures that the values are most
3818 appropriate for the context in which they are
3819 finally used.
3820 On the rare occasion that you do need the variable
3821 expression to be expanded immediately, you can use
3822 the <filename>:=</filename> operator instead of
3823 <filename>=</filename> when you make the
3824 assignment, but this is not generally needed.
3825 </note>
3826 </para></listitem>
3827 <listitem><para>
3828 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3829 Use double quotes around values in all variable
3830 assignments (e.g.
3831 <filename>"<replaceable>value</replaceable>"</filename>).
3832 Following is an example:
3833 <literallayout class='monospaced'>
3834 VAR1 = "${OTHERVAR}"
3835 VAR2 = "The version is ${PV}"
3836 </literallayout>
3837 </para></listitem>
3838 <listitem><para>
3839 <emphasis>Conditional Assignment (?=):</emphasis>
3840 Conditional assignment is used to assign a
3841 value to a variable, but only when the variable is
3842 currently unset.
3843 Use the question mark followed by the equal sign
3844 (<filename>?=</filename>) to make a "soft" assignment
3845 used for conditional assignment.
3846 Typically, "soft" assignments are used in the
3847 <filename>local.conf</filename> file for variables
3848 that are allowed to come through from the external
3849 environment.
3850 </para>
3851
3852 <para>Here is an example where
3853 <filename>VAR1</filename> is set to "New value" if
3854 it is currently empty.
3855 However, if <filename>VAR1</filename> has already been
3856 set, it remains unchanged:
3857 <literallayout class='monospaced'>
3858 VAR1 ?= "New value"
3859 </literallayout>
3860 In this next example, <filename>VAR1</filename>
3861 is left with the value "Original value":
3862 <literallayout class='monospaced'>
3863 VAR1 = "Original value"
3864 VAR1 ?= "New value"
3865 </literallayout>
3866 </para></listitem>
3867 <listitem><para>
3868 <emphasis>Appending (+=):</emphasis>
3869 Use the plus character followed by the equals sign
3870 (<filename>+=</filename>) to append values to existing
3871 variables.
3872 <note>
3873 This operator adds a space between the existing
3874 content of the variable and the new content.
3875 </note></para>
3876
3877 <para>Here is an example:
3878 <literallayout class='monospaced'>
3879 SRC_URI += "file://fix-makefile.patch"
3880 </literallayout>
3881 </para></listitem>
3882 <listitem><para>
3883 <emphasis>Prepending (=+):</emphasis>
3884 Use the equals sign followed by the plus character
3885 (<filename>=+</filename>) to prepend values to existing
3886 variables.
3887 <note>
3888 This operator adds a space between the new content
3889 and the existing content of the variable.
3890 </note></para>
3891
3892 <para>Here is an example:
3893 <literallayout class='monospaced'>
3894 VAR =+ "Starts"
3895 </literallayout>
3896 </para></listitem>
3897 <listitem><para>
3898 <emphasis>Appending (_append):</emphasis>
3899 Use the <filename>_append</filename> operator to
3900 append values to existing variables.
3901 This operator does not add any additional space.
3902 Also, the operator is applied after all the
3903 <filename>+=</filename>, and
3904 <filename>=+</filename> operators have been applied and
3905 after all <filename>=</filename> assignments have
3906 occurred.
3907 </para>
3908
3909 <para>The following example shows the space being
3910 explicitly added to the start to ensure the appended
3911 value is not merged with the existing value:
3912 <literallayout class='monospaced'>
3913 SRC_URI_append = " file://fix-makefile.patch"
3914 </literallayout>
3915 You can also use the <filename>_append</filename>
3916 operator with overrides, which results in the actions
3917 only being performed for the specified target or
3918 machine:
3919 <literallayout class='monospaced'>
3920 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3921 </literallayout>
3922 </para></listitem>
3923 <listitem><para>
3924 <emphasis>Prepending (_prepend):</emphasis>
3925 Use the <filename>_prepend</filename> operator to
3926 prepend values to existing variables.
3927 This operator does not add any additional space.
3928 Also, the operator is applied after all the
3929 <filename>+=</filename>, and
3930 <filename>=+</filename> operators have been applied and
3931 after all <filename>=</filename> assignments have
3932 occurred.
3933 </para>
3934
3935 <para>The following example shows the space being
3936 explicitly added to the end to ensure the prepended
3937 value is not merged with the existing value:
3938 <literallayout class='monospaced'>
3939 CFLAGS_prepend = "-I${S}/myincludes "
3940 </literallayout>
3941 You can also use the <filename>_prepend</filename>
3942 operator with overrides, which results in the actions
3943 only being performed for the specified target or
3944 machine:
3945 <literallayout class='monospaced'>
3946 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
3947 </literallayout>
3948 </para></listitem>
3949 <listitem><para>
3950 <emphasis>Overrides:</emphasis>
3951 You can use overrides to set a value conditionally,
3952 typically based on how the recipe is being built.
3953 For example, to set the
3954 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
3955 variable's value to "standard/base" for any target
3956 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
3957 except for qemuarm where it should be set to
3958 "standard/arm-versatile-926ejs", you would do the
3959 following:
3960 <literallayout class='monospaced'>
3961 KBRANCH = "standard/base"
3962 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
3963 </literallayout>
3964 Overrides are also used to separate alternate values
3965 of a variable in other situations.
3966 For example, when setting variables such as
3967 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3968 and
3969 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
3970 that are specific to individual packages produced by
3971 a recipe, you should always use an override that
3972 specifies the name of the package.
3973 </para></listitem>
3974 <listitem><para>
3975 <emphasis>Indentation:</emphasis>
3976 Use spaces for indentation rather than than tabs.
3977 For shell functions, both currently work.
3978 However, it is a policy decision of the Yocto Project
3979 to use tabs in shell functions.
3980 Realize that some layers have a policy to use spaces
3981 for all indentation.
3982 </para></listitem>
3983 <listitem><para>
3984 <emphasis>Using Python for Complex Operations:</emphasis>
3985 For more advanced processing, it is possible to use
3986 Python code during variable assignments (e.g.
3987 search and replacement on a variable).</para>
3988
3989 <para>You indicate Python code using the
3990 <filename>${@<replaceable>python_code</replaceable>}</filename>
3991 syntax for the variable assignment:
3992 <literallayout class='monospaced'>
3993 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
3994 </literallayout>
3995 </para></listitem>
3996 <listitem><para>
3997 <emphasis>Shell Function Syntax:</emphasis>
3998 Write shell functions as if you were writing a shell
3999 script when you describe a list of actions to take.
4000 You should ensure that your script works with a generic
4001 <filename>sh</filename> and that it does not require
4002 any <filename>bash</filename> or other shell-specific
4003 functionality.
4004 The same considerations apply to various system
4005 utilities (e.g. <filename>sed</filename>,
4006 <filename>grep</filename>, <filename>awk</filename>,
4007 and so forth) that you might wish to use.
4008 If in doubt, you should check with multiple
4009 implementations - including those from BusyBox.
4010 </para></listitem>
4011 </itemizedlist>
4012 </para>
4013 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004014 </section>
4015
4016 <section id="platdev-newmachine">
4017 <title>Adding a New Machine</title>
4018
4019 <para>
4020 Adding a new machine to the Yocto Project is a straightforward
4021 process.
4022 This section describes how to add machines that are similar
4023 to those that the Yocto Project already supports.
4024 <note>
4025 Although well within the capabilities of the Yocto Project,
4026 adding a totally new architecture might require
4027 changes to <filename>gcc/glibc</filename> and to the site
4028 information, which is beyond the scope of this manual.
4029 </note>
4030 </para>
4031
4032 <para>
4033 For a complete example that shows how to add a new machine,
4034 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004035 "<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>"
4036 section in the Yocto Project Board Support Package (BSP)
4037 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004038 </para>
4039
4040 <section id="platdev-newmachine-conffile">
4041 <title>Adding the Machine Configuration File</title>
4042
4043 <para>
4044 To add a new machine, you need to add a new machine
4045 configuration file to the layer's
4046 <filename>conf/machine</filename> directory.
4047 This configuration file provides details about the device
4048 you are adding.
4049 </para>
4050
4051 <para>
4052 The OpenEmbedded build system uses the root name of the
4053 machine configuration file to reference the new machine.
4054 For example, given a machine configuration file named
4055 <filename>crownbay.conf</filename>, the build system
4056 recognizes the machine as "crownbay".
4057 </para>
4058
4059 <para>
4060 The most important variables you must set in your machine
4061 configuration file or include from a lower-level configuration
4062 file are as follows:
4063 <itemizedlist>
4064 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4065 (e.g. "arm")</para></listitem>
4066 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4067 </para></listitem>
4068 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4069 (e.g. "apm screen wifi")</para></listitem>
4070 </itemizedlist>
4071 </para>
4072
4073 <para>
4074 You might also need these variables:
4075 <itemizedlist>
4076 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4077 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4078 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4079 (e.g. "zImage")</para></listitem>
4080 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4081 (e.g. "tar.gz jffs2")</para></listitem>
4082 </itemizedlist>
4083 </para>
4084
4085 <para>
4086 You can find full details on these variables in the reference
4087 section.
4088 You can leverage existing machine <filename>.conf</filename>
4089 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4090 </para>
4091 </section>
4092
4093 <section id="platdev-newmachine-kernel">
4094 <title>Adding a Kernel for the Machine</title>
4095
4096 <para>
4097 The OpenEmbedded build system needs to be able to build a kernel
4098 for the machine.
4099 You need to either create a new kernel recipe for this machine,
4100 or extend an existing kernel recipe.
4101 You can find several kernel recipe examples in the
4102 Source Directory at
4103 <filename>meta/recipes-kernel/linux</filename>
4104 that you can use as references.
4105 </para>
4106
4107 <para>
4108 If you are creating a new kernel recipe, normal recipe-writing
4109 rules apply for setting up a
4110 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4111 Thus, you need to specify any necessary patches and set
4112 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4113 to point at the source code.
4114 You need to create a <filename>do_configure</filename> task that
4115 configures the unpacked kernel with a
4116 <filename>defconfig</filename> file.
4117 You can do this by using a <filename>make defconfig</filename>
4118 command or, more commonly, by copying in a suitable
4119 <filename>defconfig</filename> file and then running
4120 <filename>make oldconfig</filename>.
4121 By making use of <filename>inherit kernel</filename> and
4122 potentially some of the <filename>linux-*.inc</filename> files,
4123 most other functionality is centralized and the defaults of the
4124 class normally work well.
4125 </para>
4126
4127 <para>
4128 If you are extending an existing kernel recipe, it is usually
4129 a matter of adding a suitable <filename>defconfig</filename>
4130 file.
4131 The file needs to be added into a location similar to
4132 <filename>defconfig</filename> files used for other machines
4133 in a given kernel recipe.
4134 A possible way to do this is by listing the file in the
4135 <filename>SRC_URI</filename> and adding the machine to the
4136 expression in
4137 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4138 <literallayout class='monospaced'>
4139 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4140 </literallayout>
4141 For more information on <filename>defconfig</filename> files,
4142 see the
4143 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4144 section in the Yocto Project Linux Kernel Development Manual.
4145 </para>
4146 </section>
4147
4148 <section id="platdev-newmachine-formfactor">
4149 <title>Adding a Formfactor Configuration File</title>
4150
4151 <para>
4152 A formfactor configuration file provides information about the
4153 target hardware for which the image is being built and information that
4154 the build system cannot obtain from other sources such as the kernel.
4155 Some examples of information contained in a formfactor configuration file include
4156 framebuffer orientation, whether or not the system has a keyboard,
4157 the positioning of the keyboard in relation to the screen, and
4158 the screen resolution.
4159 </para>
4160
4161 <para>
4162 The build system uses reasonable defaults in most cases.
4163 However, if customization is
4164 necessary, you need to create a <filename>machconfig</filename> file
4165 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4166 directory.
4167 This directory contains directories for specific machines such as
4168 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4169 For information about the settings available and the defaults, see the
4170 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4171 same area.
4172 </para>
4173
4174 <para>
4175 Following is an example for "qemuarm" machine:
4176 <literallayout class='monospaced'>
4177 HAVE_TOUCHSCREEN=1
4178 HAVE_KEYBOARD=1
4179
4180 DISPLAY_CAN_ROTATE=0
4181 DISPLAY_ORIENTATION=0
4182 #DISPLAY_WIDTH_PIXELS=640
4183 #DISPLAY_HEIGHT_PIXELS=480
4184 #DISPLAY_BPP=16
4185 DISPLAY_DPI=150
4186 DISPLAY_SUBPIXEL_ORDER=vrgb
4187 </literallayout>
4188 </para>
4189 </section>
4190 </section>
4191
Brad Bishop316dfdd2018-06-25 12:45:53 -04004192 <section id='gs-upgrading-recipes'>
4193 <title>Upgrading Recipes</title>
4194
4195 <para>
4196 Over time, upstream developers publish new versions for software
4197 built by layer recipes.
4198 It is recommended to keep recipes up-to-date with upstream
4199 version releases.
4200 You can use the Automated Upgrade Helper (AUH) to set up
4201 automatic version upgrades.
4202 Alternatively, you can use <filename>devtool upgrade</filename>
4203 to set up semi-automatic version upgrades.
4204 Finally, you can even manually upgrade a recipe by editing the
4205 recipe itself.
4206 </para>
4207
4208 <section id='gs-using-the-auto-upgrade-helper'>
4209 <title>Using the Auto Upgrade Helper (AUH)</title>
4210
4211 <para>
4212 The AUH utility works in conjunction with the
4213 OpenEmbedded build system in order to automatically generate
4214 upgrades for recipes based on new versions being
4215 published upstream.
4216 Use AUH when you want to create a service that performs the
4217 upgrades automatically and optionally sends you an email with
4218 the results.
4219 </para>
4220
4221 <para>
4222 AUH allows you to update several recipes with a single use.
4223 You can also optionally perform build and integration tests
4224 using images with the results saved to your hard drive and
4225 emails of results optionally sent to recipe maintainers.
4226 Finally, AUH creates Git commits with appropriate commit
4227 messages in the layer's tree for the changes made to recipes.
4228 <note>
4229 Conditions do exist when you should not use AUH to upgrade
4230 recipes and you should instead use either
4231 <filename>devtool upgrade</filename> or upgrade your
4232 recipes manually:
4233 <itemizedlist>
4234 <listitem><para>
4235 When AUH cannot complete the upgrade sequence.
4236 This situation usually results because custom
4237 patches carried by the recipe cannot be
4238 automatically rebased to the new version.
4239 In this case, <filename>devtool upgrade</filename>
4240 allows you to manually resolve conflicts.
4241 </para></listitem>
4242 <listitem><para>
4243 When for any reason you want fuller control over
4244 the upgrade process.
4245 For example, when you want special arrangements
4246 for testing.
4247 </para></listitem>
4248 </itemizedlist>
4249 </note>
4250 </para>
4251
4252 <para>
4253 The following steps describe how to set up the AUH utility:
4254 <orderedlist>
4255 <listitem><para>
4256 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4257 You need to be sure that your development host is
4258 set up to use the Yocto Project.
4259 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004260 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004261 section.
4262 </para></listitem>
4263 <listitem><para>
4264 <emphasis>Make Sure Git is Configured:</emphasis>
4265 The AUH utility requires Git to be configured because
4266 AUH uses Git to save upgrades.
4267 Thus, you must have Git user and email configured.
4268 The following command shows your configurations:
4269 <literallayout class='monospaced'>
4270 $ git config --list
4271 </literallayout>
4272 If you do not have the user and email configured, you
4273 can use the following commands to do so:
4274 <literallayout class='monospaced'>
4275 $ git config --global user.name <replaceable>some_name</replaceable>
4276 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4277 </literallayout>
4278 </para></listitem>
4279 <listitem><para>
4280 <emphasis>Clone the AUH Repository:</emphasis>
4281 To use AUH, you must clone the repository onto your
4282 development host.
4283 The following command uses Git to create a local
4284 copy of the repository on your system:
4285 <literallayout class='monospaced'>
4286 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4287 Cloning into 'auto-upgrade-helper'...
4288 remote: Counting objects: 768, done.
4289 remote: Compressing objects: 100% (300/300), done.
4290 remote: Total 768 (delta 499), reused 703 (delta 434)
4291 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4292 Resolving deltas: 100% (499/499), done.
4293 Checking connectivity... done.
4294 </literallayout>
4295 AUH is not part of the
4296 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4297 or
4298 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4299 repositories.
4300 </para></listitem>
4301 <listitem><para>
4302 <emphasis>Create a Dedicated Build Directory:</emphasis>
4303 Run the
4304 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4305 script to create a fresh build directory that you
4306 use exclusively for running the AUH utility:
4307 <literallayout class='monospaced'>
4308 $ cd ~/poky
4309 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4310 </literallayout>
4311 Re-using an existing build directory and its
4312 configurations is not recommended as existing settings
4313 could cause AUH to fail or behave undesirably.
4314 </para></listitem>
4315 <listitem><para>
4316 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4317 Several settings need to exist in the
4318 <filename>local.conf</filename> file in the build
4319 directory you just created for AUH.
4320 Make these following configurations:
4321 <itemizedlist>
4322 <listitem><para>
4323 Enable "distrodata" as follows:
4324 <literallayout class='monospaced'>
4325 INHERIT =+ "distrodata"
4326 </literallayout>
4327 </para></listitem>
4328 <listitem><para>
4329 If you want to enable
4330 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4331 which is optional, you need the following
4332 lines in the
4333 <filename>conf/local.conf</filename> file:
4334 <literallayout class='monospaced'>
4335 INHERIT =+ "buildhistory"
4336 BUILDHISTORY_COMMIT = "1"
4337 </literallayout>
4338 With this configuration and a successful
4339 upgrade, a build history "diff" file appears in
4340 the
4341 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4342 file found in your build directory.
4343 </para></listitem>
4344 <listitem><para>
4345 If you want to enable testing through the
4346 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4347 class, which is optional, you need to have the
4348 following set in your
4349 <filename>conf/local.conf</filename> file:
4350 <literallayout class='monospaced'>
4351 INHERIT += "testimage"
4352 </literallayout>
4353 <note>
4354 If your distro does not enable by default
4355 ptest, which Poky does, you need the
4356 following in your
4357 <filename>local.conf</filename> file:
4358 <literallayout class='monospaced'>
4359 DISTRO_FEATURES_append = " ptest"
4360 </literallayout>
4361 </note>
4362 </para></listitem>
4363 </itemizedlist>
4364 </para></listitem>
4365 <listitem><para>
4366 <emphasis>Optionally Start a vncserver:</emphasis>
4367 If you are running in a server without an X11 session,
4368 you need to start a vncserver:
4369 <literallayout class='monospaced'>
4370 $ vncserver :1
4371 $ export DISPLAY=:1
4372 </literallayout>
4373 </para></listitem>
4374 <listitem><para>
4375 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4376 You need to have the
4377 <filename>upgrade-helper/upgrade-helper.conf</filename>
4378 configuration file in your build directory.
4379 You can find a sample configuration file in the
4380 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4381 </para>
4382
4383 <para>Read through the sample file and make
4384 configurations as needed.
4385 For example, if you enabled build history in your
4386 <filename>local.conf</filename> as described earlier,
4387 you must enable it in
4388 <filename>upgrade-helper.conf</filename>.</para>
4389
4390 <para>Also, if you are using the default
4391 <filename>maintainers.inc</filename> file supplied
4392 with Poky and located in
4393 <filename>meta-yocto</filename> and you do not set a
4394 "maintainers_whitelist" or "global_maintainer_override"
4395 in the <filename>upgrade-helper.conf</filename>
4396 configuration, and you specify "-e all" on the
4397 AUH command-line, the utility automatically sends out
4398 emails to all the default maintainers.
4399 Please avoid this.
4400 </para></listitem>
4401 </orderedlist>
4402 </para>
4403
4404 <para>
4405 This next set of examples describes how to use the AUH:
4406 <itemizedlist>
4407 <listitem><para>
4408 <emphasis>Upgrading a Specific Recipe:</emphasis>
4409 To upgrade a specific recipe, use the following
4410 form:
4411 <literallayout class='monospaced'>
4412 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4413 </literallayout>
4414 For example, this command upgrades the
4415 <filename>xmodmap</filename> recipe:
4416 <literallayout class='monospaced'>
4417 $ upgrade-helper.py xmodmap
4418 </literallayout>
4419 </para></listitem>
4420 <listitem><para>
4421 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4422 To upgrade a specific recipe to a particular version,
4423 use the following form:
4424 <literallayout class='monospaced'>
4425 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4426 </literallayout>
4427 For example, this command upgrades the
4428 <filename>xmodmap</filename> recipe to version
4429 1.2.3:
4430 <literallayout class='monospaced'>
4431 $ upgrade-helper.py xmodmap -t 1.2.3
4432 </literallayout>
4433 </para></listitem>
4434 <listitem><para>
4435 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4436 To upgrade all recipes to their most recent versions
4437 and suppress the email notifications, use the following
4438 command:
4439 <literallayout class='monospaced'>
4440 $ upgrade-helper.py all
4441 </literallayout>
4442 </para></listitem>
4443 <listitem><para>
4444 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4445 To upgrade all recipes to their most recent versions
4446 and send email messages to maintainers for each
4447 attempted recipe as well as a status email, use the
4448 following command:
4449 <literallayout class='monospaced'>
4450 $ upgrade-helper.py -e all
4451 </literallayout>
4452 </para></listitem>
4453 </itemizedlist>
4454 </para>
4455
4456 <para>
4457 Once you have run the AUH utility, you can find the results
4458 in the AUH build directory:
4459 <literallayout class='monospaced'>
4460 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4461 </literallayout>
4462 The AUH utility also creates recipe update commits from
4463 successful upgrade attempts in the layer tree.
4464 </para>
4465
4466 <para>
4467 You can easily set up to run the AUH utility on a regular
4468 basis by using a cron job.
4469 See the
4470 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4471 file distributed with the utility for an example.
4472 </para>
4473 </section>
4474
4475 <section id='gs-using-devtool-upgrade'>
4476 <title>Using <filename>devtool upgrade</filename></title>
4477
4478 <para>
4479 As mentioned earlier, an alternative method for upgrading
4480 recipes to newer versions is to use
4481 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4482 You can read about <filename>devtool upgrade</filename> in
4483 general in the
4484 "<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>"
4485 section in the Yocto Project Application Development and the
4486 Extensible Software Development Kit (eSDK) Manual.
4487 </para>
4488
4489 <para>
4490 To see all the command-line options available with
4491 <filename>devtool upgrade</filename>, use the following help
4492 command:
4493 <literallayout class='monospaced'>
4494 $ devtool upgrade -h
4495 </literallayout>
4496 </para>
4497
4498 <para>
4499 If you want to find out what version a recipe is currently at
4500 upstream without any attempt to upgrade your local version of
4501 the recipe, you can use the following command:
4502 <literallayout class='monospaced'>
4503 $ devtool latest-version <replaceable>recipe_name</replaceable>
4504 </literallayout>
4505 </para>
4506
4507 <para>
4508 As mentioned in the previous section describing AUH,
4509 <filename>devtool upgrade</filename> works in a
4510 less-automated manner than AUH.
4511 Specifically, <filename>devtool upgrade</filename> only
4512 works on a single recipe that you name on the command line,
4513 cannot perform build and integration testing using images,
4514 and does not automatically generate commits for changes in
4515 the source tree.
4516 Despite all these "limitations",
4517 <filename>devtool upgrade</filename> updates the recipe file
4518 to the new upstream version and attempts to rebase custom
4519 patches contained by the recipe as needed.
4520 <note>
4521 AUH uses much of <filename>devtool upgrade</filename>
4522 behind the scenes making AUH somewhat of a "wrapper"
4523 application for <filename>devtool upgrade</filename>.
4524 </note>
4525 </para>
4526
4527 <para>
4528 A typical scenario involves having used Git to clone an
4529 upstream repository that you use during build operations.
4530 Because you are (or have) built the recipe in the past, the
4531 layer is likely added to your configuration already.
4532 If for some reason, the layer is not added, you could add
4533 it easily using the
4534 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4535 script.
4536 For example, suppose you use the <filename>nano.bb</filename>
4537 recipe from the <filename>meta-oe</filename> layer in the
4538 <filename>meta-openembedded</filename> repository.
4539 For this example, assume that the layer has been cloned into
4540 following area:
4541 <literallayout class='monospaced'>
4542 /home/scottrif/meta-openembedded
4543 </literallayout>
4544 The following command from your
4545 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4546 adds the layer to your build configuration (i.e.
4547 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4548 <literallayout class='monospaced'>
4549 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4550 NOTE: Starting bitbake server...
4551 Parsing recipes: 100% |##########################################| Time: 0:00:55
4552 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4553 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4554 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4555 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4556 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4557 </literallayout>
4558 For this example, assume that the <filename>nano.bb</filename>
4559 recipe that is upstream has a 2.9.3 version number.
4560 However, the version in the local repository is 2.7.4.
4561 The following command from your build directory automatically
4562 upgrades the recipe for you:
4563 <note>
4564 Using the <filename>-V</filename> option is not necessary.
4565 Omitting the version number causes
4566 <filename>devtool upgrade</filename> to upgrade the recipe
4567 to the most recent version.
4568 </note>
4569 <literallayout class='monospaced'>
4570 $ devtool upgrade nano -V 2.9.3
4571 NOTE: Starting bitbake server...
4572 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4573 Parsing recipes: 100% |##########################################| Time: 0:00:46
4574 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4575 NOTE: Extracting current version source...
4576 NOTE: Resolving any missing task queue dependencies
4577 .
4578 .
4579 .
4580 NOTE: Executing SetScene Tasks
4581 NOTE: Executing RunQueue Tasks
4582 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4583 Adding changed files: 100% |#####################################| Time: 0:00:00
4584 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4585 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4586 </literallayout>
4587 Continuing with this example, you can use
4588 <filename>devtool build</filename> to build the newly upgraded
4589 recipe:
4590 <literallayout class='monospaced'>
4591 $ devtool build nano
4592 NOTE: Starting bitbake server...
4593 Loading cache: 100% |################################################################################################| Time: 0:00:01
4594 Loaded 2040 entries from dependency cache.
4595 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4596 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4597 NOTE: Resolving any missing task queue dependencies
4598 .
4599 .
4600 .
4601 NOTE: Executing SetScene Tasks
4602 NOTE: Executing RunQueue Tasks
4603 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4604 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4605 </literallayout>
4606 Within the <filename>devtool upgrade</filename> workflow,
4607 opportunity exists to deploy and test your rebuilt software.
4608 For this example, however, running
4609 <filename>devtool finish</filename> cleans up the workspace
4610 once the source in your workspace is clean.
4611 This usually means using Git to stage and submit commits
4612 for the changes generated by the upgrade process.
4613 </para>
4614
4615 <para>
4616 Once the tree is clean, you can clean things up in this
4617 example with the following command from the
4618 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4619 directory:
4620 <literallayout class='monospaced'>
4621 $ devtool finish nano meta-oe
4622 NOTE: Starting bitbake server...
4623 Loading cache: 100% |################################################################################################| Time: 0:00:00
4624 Loaded 2040 entries from dependency cache.
4625 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4626 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4627 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4628 NOTE: Updating recipe nano_2.9.3.bb
4629 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4630 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4631 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4632 </literallayout>
4633 Using the <filename>devtool finish</filename> command cleans
4634 up the workspace and creates a patch file based on your
4635 commits.
4636 The tool puts all patch files back into the source directory
4637 in a sub-directory named <filename>nano</filename> in this
4638 case.
4639 </para>
4640 </section>
4641
4642 <section id='dev-manually-upgrading-a-recipe'>
4643 <title>Manually Upgrading a Recipe</title>
4644
4645 <para>
4646 If for some reason you choose not to upgrade recipes using the
4647 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4648 or by using
4649 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4650 you can manually edit the recipe files to upgrade the versions.
4651 <note><title>Caution</title>
4652 Manually updating multiple recipes scales poorly and
4653 involves many steps.
4654 The recommendation to upgrade recipe versions is through
4655 AUH or <filename>devtool upgrade</filename>, both of which
4656 automate some steps and provide guidance for others needed
4657 for the manual process.
4658 </note>
4659 </para>
4660
4661 <para>
4662 To manually upgrade recipe versions, follow these general steps:
4663 <orderedlist>
4664 <listitem><para>
4665 <emphasis>Change the Version:</emphasis>
4666 Rename the recipe such that the version (i.e. the
4667 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4668 part of the recipe name) changes appropriately.
4669 If the version is not part of the recipe name, change
4670 the value as it is set for <filename>PV</filename>
4671 within the recipe itself.
4672 </para></listitem>
4673 <listitem><para>
4674 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4675 If the source code your recipe builds is fetched from
4676 Git or some other version control system, update
4677 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4678 to point to the commit hash that matches the new
4679 version.
4680 </para></listitem>
4681 <listitem><para>
4682 <emphasis>Build the Software:</emphasis>
4683 Try to build the recipe using BitBake.
4684 Typical build failures include the following:
4685 <itemizedlist>
4686 <listitem><para>
4687 License statements were updated for the new
4688 version.
4689 For this case, you need to review any changes
4690 to the license and update the values of
4691 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4692 and
4693 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4694 as needed.
4695 <note>
4696 License changes are often inconsequential.
4697 For example, the license text's copyright
4698 year might have changed.
4699 </note>
4700 </para></listitem>
4701 <listitem><para>
4702 Custom patches carried by the older version of
4703 the recipe might fail to apply to the new
4704 version.
4705 For these cases, you need to review the
4706 failures.
4707 Patches might not be necessary for the new
4708 version of the software if the upgraded version
4709 has fixed those issues.
4710 If a patch is necessary and failing, you need
4711 to rebase it into the new version.
4712 </para></listitem>
4713 </itemizedlist>
4714 </para></listitem>
4715 <listitem><para>
4716 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4717 Once you successfully build the new software for a
4718 given architecture, you could test the build for
4719 other architectures by changing the
4720 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4721 variable and rebuilding the software.
4722 This optional step is especially important if the
4723 recipe is to be released publicly.
4724 </para></listitem>
4725 <listitem><para>
4726 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4727 Checking both these reveals if new features exist that
4728 could break backwards-compatibility.
4729 If so, you need to take steps to mitigate or eliminate
4730 that situation.
4731 </para></listitem>
4732 <listitem><para>
4733 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4734 If you want, you can test the new software by booting
4735 it onto actual hardware.
4736 </para></listitem>
4737 <listitem><para>
4738 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4739 After all builds work and any testing is successful,
4740 you can create commits for any changes in the layer
4741 holding your upgraded recipe.
4742 </para></listitem>
4743 </orderedlist>
4744 </para>
4745 </section>
4746 </section>
4747
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004748 <section id='finding-the-temporary-source-code'>
4749 <title>Finding Temporary Source Code</title>
4750
4751 <para>
4752 You might find it helpful during development to modify the
4753 temporary source code used by recipes to build packages.
4754 For example, suppose you are developing a patch and you need to
4755 experiment a bit to figure out your solution.
4756 After you have initially built the package, you can iteratively
4757 tweak the source code, which is located in the
4758 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4759 and then you can force a re-compile and quickly test your altered
4760 code.
4761 Once you settle on a solution, you can then preserve your changes
4762 in the form of patches.
4763 </para>
4764
4765 <para>
4766 During a build, the unpacked temporary source code used by recipes
4767 to build packages is available in the Build Directory as
4768 defined by the
4769 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4770 variable.
4771 Below is the default value for the <filename>S</filename> variable
4772 as defined in the
4773 <filename>meta/conf/bitbake.conf</filename> configuration file
4774 in the
4775 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4776 <literallayout class='monospaced'>
4777 S = "${WORKDIR}/${BP}"
4778 </literallayout>
4779 You should be aware that many recipes override the
4780 <filename>S</filename> variable.
4781 For example, recipes that fetch their source from Git usually set
4782 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4783 <note>
4784 The
4785 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4786 represents the base recipe name, which consists of the name
4787 and version:
4788 <literallayout class='monospaced'>
4789 BP = "${BPN}-${PV}"
4790 </literallayout>
4791 </note>
4792 </para>
4793
4794 <para>
4795 The path to the work directory for the recipe
4796 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4797 is defined as follows:
4798 <literallayout class='monospaced'>
4799 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4800 </literallayout>
4801 The actual directory depends on several things:
4802 <itemizedlist>
4803 <listitem><para>
4804 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4805 The top-level build output directory.
4806 </para></listitem>
4807 <listitem><para>
4808 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4809 The target system identifier.
4810 </para></listitem>
4811 <listitem><para>
4812 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4813 The recipe name.
4814 </para></listitem>
4815 <listitem><para>
4816 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4817 The epoch - (if
4818 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4819 is not specified, which is usually the case for most
4820 recipes, then <filename>EXTENDPE</filename> is blank).
4821 </para></listitem>
4822 <listitem><para>
4823 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4824 The recipe version.
4825 </para></listitem>
4826 <listitem><para>
4827 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4828 The recipe revision.
4829 </para></listitem>
4830 </itemizedlist>
4831 </para>
4832
4833 <para>
4834 As an example, assume a Source Directory top-level folder
4835 named <filename>poky</filename>, a default Build Directory at
4836 <filename>poky/build</filename>, and a
4837 <filename>qemux86-poky-linux</filename> machine target
4838 system.
4839 Furthermore, suppose your recipe is named
4840 <filename>foo_1.3.0.bb</filename>.
4841 In this case, the work directory the build system uses to
4842 build the package would be as follows:
4843 <literallayout class='monospaced'>
4844 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4845 </literallayout>
4846 </para>
4847 </section>
4848
4849 <section id="using-a-quilt-workflow">
4850 <title>Using Quilt in Your Workflow</title>
4851
4852 <para>
4853 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4854 is a powerful tool that allows you to capture source code changes
4855 without having a clean source tree.
4856 This section outlines the typical workflow you can use to modify
4857 source code, test changes, and then preserve the changes in the
4858 form of a patch all using Quilt.
4859 <note><title>Tip</title>
4860 With regard to preserving changes to source files, if you
4861 clean a recipe or have <filename>rm_work</filename> enabled,
4862 the
4863 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4864 as described in the Yocto Project Application Development
4865 and the Extensible Software Development Kit (eSDK) manual
4866 is a safer development flow than the flow that uses Quilt.
4867 </note>
4868 </para>
4869
4870 <para>
4871 Follow these general steps:
4872 <orderedlist>
4873 <listitem><para>
4874 <emphasis>Find the Source Code:</emphasis>
4875 Temporary source code used by the OpenEmbedded build system
4876 is kept in the
4877 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4878 See the
4879 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4880 section to learn how to locate the directory that has the
4881 temporary source code for a particular package.
4882 </para></listitem>
4883 <listitem><para>
4884 <emphasis>Change Your Working Directory:</emphasis>
4885 You need to be in the directory that has the temporary
4886 source code.
4887 That directory is defined by the
4888 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4889 variable.</para></listitem>
4890 <listitem><para>
4891 <emphasis>Create a New Patch:</emphasis>
4892 Before modifying source code, you need to create a new
4893 patch.
4894 To create a new patch file, use
4895 <filename>quilt new</filename> as below:
4896 <literallayout class='monospaced'>
4897 $ quilt new my_changes.patch
4898 </literallayout>
4899 </para></listitem>
4900 <listitem><para>
4901 <emphasis>Notify Quilt and Add Files:</emphasis>
4902 After creating the patch, you need to notify Quilt about
4903 the files you plan to edit.
4904 You notify Quilt by adding the files to the patch you
4905 just created:
4906 <literallayout class='monospaced'>
4907 $ quilt add file1.c file2.c file3.c
4908 </literallayout>
4909 </para></listitem>
4910 <listitem><para>
4911 <emphasis>Edit the Files:</emphasis>
4912 Make your changes in the source code to the files you added
4913 to the patch.
4914 </para></listitem>
4915 <listitem><para>
4916 <emphasis>Test Your Changes:</emphasis>
4917 Once you have modified the source code, the easiest way to
4918 test your changes is by calling the
4919 <filename>do_compile</filename> task as shown in the
4920 following example:
4921 <literallayout class='monospaced'>
4922 $ bitbake -c compile -f <replaceable>package</replaceable>
4923 </literallayout>
4924 The <filename>-f</filename> or <filename>--force</filename>
4925 option forces the specified task to execute.
4926 If you find problems with your code, you can just keep
4927 editing and re-testing iteratively until things work
4928 as expected.
4929 <note>
4930 All the modifications you make to the temporary
4931 source code disappear once you run the
4932 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4933 or
4934 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4935 tasks using BitBake (i.e.
4936 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4937 and
4938 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4939 Modifications will also disappear if you use the
4940 <filename>rm_work</filename> feature as described
4941 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004942 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4943 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004944 </note>
4945 </para></listitem>
4946 <listitem><para>
4947 <emphasis>Generate the Patch:</emphasis>
4948 Once your changes work as expected, you need to use Quilt
4949 to generate the final patch that contains all your
4950 modifications.
4951 <literallayout class='monospaced'>
4952 $ quilt refresh
4953 </literallayout>
4954 At this point, the <filename>my_changes.patch</filename>
4955 file has all your edits made to the
4956 <filename>file1.c</filename>, <filename>file2.c</filename>,
4957 and <filename>file3.c</filename> files.</para>
4958
4959 <para>You can find the resulting patch file in the
4960 <filename>patches/</filename> subdirectory of the source
4961 (<filename>S</filename>) directory.
4962 </para></listitem>
4963 <listitem><para>
4964 <emphasis>Copy the Patch File:</emphasis>
4965 For simplicity, copy the patch file into a directory
4966 named <filename>files</filename>, which you can create
4967 in the same directory that holds the recipe
4968 (<filename>.bb</filename>) file or the append
4969 (<filename>.bbappend</filename>) file.
4970 Placing the patch here guarantees that the OpenEmbedded
4971 build system will find the patch.
4972 Next, add the patch into the
4973 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4974 of the recipe.
4975 Here is an example:
4976 <literallayout class='monospaced'>
4977 SRC_URI += "file://my_changes.patch"
4978 </literallayout>
4979 </para></listitem>
4980 </orderedlist>
4981 </para>
4982 </section>
4983
4984 <section id="platdev-appdev-devshell">
4985 <title>Using a Development Shell</title>
4986
4987 <para>
4988 When debugging certain commands or even when just editing packages,
4989 <filename>devshell</filename> can be a useful tool.
4990 When you invoke <filename>devshell</filename>, all tasks up to and
4991 including
4992 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
4993 are run for the specified target.
4994 Then, a new terminal is opened and you are placed in
4995 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
4996 the source directory.
4997 In the new terminal, all the OpenEmbedded build-related environment variables are
4998 still defined so you can use commands such as <filename>configure</filename> and
4999 <filename>make</filename>.
5000 The commands execute just as if the OpenEmbedded build system were executing them.
5001 Consequently, working this way can be helpful when debugging a build or preparing
5002 software to be used with the OpenEmbedded build system.
5003 </para>
5004
5005 <para>
5006 Following is an example that uses <filename>devshell</filename> on a target named
5007 <filename>matchbox-desktop</filename>:
5008 <literallayout class='monospaced'>
5009 $ bitbake matchbox-desktop -c devshell
5010 </literallayout>
5011 </para>
5012
5013 <para>
5014 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5015 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5016 variable controls what type of shell is opened.
5017 </para>
5018
5019 <para>
5020 For spawned terminals, the following occurs:
5021 <itemizedlist>
5022 <listitem><para>The <filename>PATH</filename> variable includes the
5023 cross-toolchain.</para></listitem>
5024 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5025 <filename>.pc</filename> files.</para></listitem>
5026 <listitem><para>The <filename>configure</filename> command finds the
5027 Yocto Project site files as well as any other necessary files.</para></listitem>
5028 </itemizedlist>
5029 </para>
5030
5031 <para>
5032 Within this environment, you can run configure or compile
5033 commands as if they were being run by
5034 the OpenEmbedded build system itself.
5035 As noted earlier, the working directory also automatically changes to the
5036 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5037 </para>
5038
5039 <para>
5040 To manually run a specific task using <filename>devshell</filename>,
5041 run the corresponding <filename>run.*</filename> script in
5042 the
5043 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5044 directory (e.g.,
5045 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5046 If a task's script does not exist, which would be the case if the task was
5047 skipped by way of the sstate cache, you can create the task by first running
5048 it outside of the <filename>devshell</filename>:
5049 <literallayout class='monospaced'>
5050 $ bitbake -c <replaceable>task</replaceable>
5051 </literallayout>
5052 <note><title>Notes</title>
5053 <itemizedlist>
5054 <listitem><para>Execution of a task's <filename>run.*</filename>
5055 script and BitBake's execution of a task are identical.
5056 In other words, running the script re-runs the task
5057 just as it would be run using the
5058 <filename>bitbake -c</filename> command.
5059 </para></listitem>
5060 <listitem><para>Any <filename>run.*</filename> file that does not
5061 have a <filename>.pid</filename> extension is a
5062 symbolic link (symlink) to the most recent version of that
5063 file.
5064 </para></listitem>
5065 </itemizedlist>
5066 </note>
5067 </para>
5068
5069 <para>
5070 Remember, that the <filename>devshell</filename> is a mechanism that allows
5071 you to get into the BitBake task execution environment.
5072 And as such, all commands must be called just as BitBake would call them.
5073 That means you need to provide the appropriate options for
5074 cross-compilation and so forth as applicable.
5075 </para>
5076
5077 <para>
5078 When you are finished using <filename>devshell</filename>, exit the shell
5079 or close the terminal window.
5080 </para>
5081
5082 <note><title>Notes</title>
5083 <itemizedlist>
5084 <listitem><para>
5085 It is worth remembering that when using <filename>devshell</filename>
5086 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5087 instead of just using <filename>gcc</filename>.
5088 The same applies to other applications such as <filename>binutils</filename>,
5089 <filename>libtool</filename> and so forth.
5090 BitBake sets up environment variables such as <filename>CC</filename>
5091 to assist applications, such as <filename>make</filename> to find the correct tools.
5092 </para></listitem>
5093 <listitem><para>
5094 It is also worth noting that <filename>devshell</filename> still works over
5095 X11 forwarding and similar situations.
5096 </para></listitem>
5097 </itemizedlist>
5098 </note>
5099 </section>
5100
5101 <section id="platdev-appdev-devpyshell">
5102 <title>Using a Development Python Shell</title>
5103
5104 <para>
5105 Similar to working within a development shell as described in
5106 the previous section, you can also spawn and work within an
5107 interactive Python development shell.
5108 When debugging certain commands or even when just editing packages,
5109 <filename>devpyshell</filename> can be a useful tool.
5110 When you invoke <filename>devpyshell</filename>, all tasks up to and
5111 including
5112 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5113 are run for the specified target.
5114 Then a new terminal is opened.
5115 Additionally, key Python objects and code are available in the same
5116 way they are to BitBake tasks, in particular, the data store 'd'.
5117 So, commands such as the following are useful when exploring the data
5118 store and running functions:
5119 <literallayout class='monospaced'>
Brad Bishop19323692019-04-05 15:28:33 -04005120 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005121 '/media/build1/poky/build/tmp/sysroots'
Brad Bishop19323692019-04-05 15:28:33 -04005122 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005123 '${TMPDIR}/sysroots'
5124 pydevshell> d.setVar("FOO", "bar")
Brad Bishop19323692019-04-05 15:28:33 -04005125 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005126 'bar'
5127 pydevshell> d.delVar("FOO")
Brad Bishop19323692019-04-05 15:28:33 -04005128 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005129 pydevshell> bb.build.exec_func("do_unpack", d)
5130 pydevshell>
5131 </literallayout>
5132 The commands execute just as if the OpenEmbedded build system were executing them.
5133 Consequently, working this way can be helpful when debugging a build or preparing
5134 software to be used with the OpenEmbedded build system.
5135 </para>
5136
5137 <para>
5138 Following is an example that uses <filename>devpyshell</filename> on a target named
5139 <filename>matchbox-desktop</filename>:
5140 <literallayout class='monospaced'>
5141 $ bitbake matchbox-desktop -c devpyshell
5142 </literallayout>
5143 </para>
5144
5145 <para>
5146 This command spawns a terminal and places you in an interactive
5147 Python interpreter within the OpenEmbedded build environment.
5148 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5149 variable controls what type of shell is opened.
5150 </para>
5151
5152 <para>
5153 When you are finished using <filename>devpyshell</filename>, you
5154 can exit the shell either by using Ctrl+d or closing the terminal
5155 window.
5156 </para>
5157 </section>
5158
Brad Bishop316dfdd2018-06-25 12:45:53 -04005159 <section id='dev-building'>
5160 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005161
5162 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005163 This section describes various build procedures.
5164 For example, the steps needed for a simple build, a target that
5165 uses multiple configurations, building an image for more than
5166 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005167 </para>
5168
Brad Bishop316dfdd2018-06-25 12:45:53 -04005169 <section id='dev-building-a-simple-image'>
5170 <title>Building a Simple Image</title>
5171
5172 <para>
5173 In the development environment, you need to build an image
5174 whenever you change hardware support, add or change system
5175 libraries, or add or change services that have dependencies.
5176 Several methods exist that allow you to build an image within
5177 the Yocto Project.
5178 This section presents the basic steps you need to build a
5179 simple image using BitBake from a build host running Linux.
5180 <note><title>Notes</title>
5181 <itemizedlist>
5182 <listitem><para>
5183 For information on how to build an image using
5184 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5185 see the
5186 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5187 </para></listitem>
5188 <listitem><para>
5189 For information on how to use
5190 <filename>devtool</filename> to build images, see
5191 the
5192 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5193 section in the Yocto Project Application
5194 Development and the Extensible Software Development
5195 Kit (eSDK) manual.
5196 </para></listitem>
5197 <listitem><para>
5198 For a quick example on how to build an image using
5199 the OpenEmbedded build system, see the
5200 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5201 document.
5202 </para></listitem>
5203 </itemizedlist>
5204 </note>
5205 </para>
5206
5207 <para>
5208 The build process creates an entire Linux distribution from
5209 source and places it in your
5210 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5211 under <filename>tmp/deploy/images</filename>.
5212 For detailed information on the build process using BitBake,
5213 see the
5214 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5215 section in the Yocto Project Overview and Concepts Manual.
5216 </para>
5217
5218 <para>
5219 The following figure and list overviews the build process:
5220 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5221 <orderedlist>
5222 <listitem><para>
5223 <emphasis>Set up Your Host Development System to Support
5224 Development Using the Yocto Project</emphasis>:
5225 See the
5226 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5227 section for options on how to get a build host ready to
5228 use the Yocto Project.
5229 </para></listitem>
5230 <listitem><para>
5231 <emphasis>Initialize the Build Environment:</emphasis>
5232 Initialize the build environment by sourcing the build
5233 environment script (i.e.
5234 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5235 <literallayout class='monospaced'>
5236 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5237 </literallayout></para>
5238
5239 <para>When you use the initialization script, the
5240 OpenEmbedded build system uses
5241 <filename>build</filename> as the default Build
5242 Directory in your current work directory.
5243 You can use a <replaceable>build_dir</replaceable>
5244 argument with the script to specify a different build
5245 directory.
5246 <note><title>Tip</title>
5247 A common practice is to use a different Build
5248 Directory for different targets.
5249 For example, <filename>~/build/x86</filename> for a
5250 <filename>qemux86</filename> target, and
5251 <filename>~/build/arm</filename> for a
5252 <filename>qemuarm</filename> target.
5253 </note>
5254 </para></listitem>
5255 <listitem><para>
5256 <emphasis>Make Sure Your <filename>local.conf</filename>
5257 File is Correct:</emphasis>
5258 Ensure the <filename>conf/local.conf</filename>
5259 configuration file, which is found in the Build
5260 Directory, is set up how you want it.
5261 This file defines many aspects of the build environment
5262 including the target machine architecture through the
5263 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5264 the packaging format used during the build
5265 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5266 and a centralized tarball download directory through the
5267 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5268 </para></listitem>
5269 <listitem><para>
5270 <emphasis>Build the Image:</emphasis>
5271 Build the image using the <filename>bitbake</filename>
5272 command:
5273 <literallayout class='monospaced'>
5274 $ bitbake <replaceable>target</replaceable>
5275 </literallayout>
5276 <note>
5277 For information on BitBake, see the
5278 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5279 </note>
5280 The <replaceable>target</replaceable> is the name of the
5281 recipe you want to build.
5282 Common targets are the images in
5283 <filename>meta/recipes-core/images</filename>,
5284 <filename>meta/recipes-sato/images</filename>, and so
5285 forth all found in the
5286 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5287 Or, the target can be the name of a recipe for a
5288 specific piece of software such as BusyBox.
5289 For more details about the images the OpenEmbedded build
5290 system supports, see the
5291 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5292 chapter in the Yocto Project Reference Manual.</para>
5293
5294 <para>As an example, the following command builds the
5295 <filename>core-image-minimal</filename> image:
5296 <literallayout class='monospaced'>
5297 $ bitbake core-image-minimal
5298 </literallayout>
5299 Once an image has been built, it often needs to be
5300 installed.
5301 The images and kernels built by the OpenEmbedded
5302 build system are placed in the Build Directory in
5303 <filename class="directory">tmp/deploy/images</filename>.
5304 For information on how to run pre-built images such as
5305 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5306 see the
5307 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5308 manual.
5309 For information about how to install these images,
5310 see the documentation for your particular board or
5311 machine.
5312 </para></listitem>
5313 </orderedlist>
5314 </para>
5315 </section>
5316
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005317 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5318 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005319
5320 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005321 You can use a single <filename>bitbake</filename> command
5322 to build multiple images or packages for different targets
5323 where each image or package requires a different configuration
5324 (multiple configuration builds).
5325 The builds, in this scenario, are sometimes referred to as
5326 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005327 </para>
5328
5329 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005330 This section describes how to set up for multiple
5331 configuration builds and how to account for cross-build
5332 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005333 </para>
5334
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005335 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5336 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005337
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005338 <para>
5339 To accomplish a multiple configuration build, you must
5340 define each target's configuration separately using
5341 a parallel configuration file in the
5342 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5343 and you must follow a required file hierarchy.
5344 Additionally, you must enable the multiple configuration
5345 builds in your <filename>local.conf</filename> file.
5346 </para>
5347
5348 <para>
5349 Follow these steps to set up and execute multiple
5350 configuration builds:
5351 <itemizedlist>
5352 <listitem><para>
5353 <emphasis>Create Separate Configuration Files</emphasis>:
5354 You need to create a single configuration file for
5355 each build target (each multiconfig).
5356 Minimally, each configuration file must define the
5357 machine and the temporary directory BitBake uses
5358 for the build.
5359 Suggested practice dictates that you do not
5360 overlap the temporary directories
5361 used during the builds.
5362 However, it is possible that you can share the
5363 temporary directory
5364 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5365 For example, consider a scenario with two
5366 different multiconfigs for the same
5367 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5368 two distributions such as "poky" and "poky-lsb".
5369 In this case, you might want to use the same
5370 <filename>TMPDIR</filename>.</para>
5371
5372 <para>Here is an example showing the minimal
5373 statements needed in a configuration file for
5374 a "qemux86" target whose temporary build directory
5375 is <filename>tmpmultix86</filename>:
5376 <literallayout class='monospaced'>
5377 MACHINE="qemux86"
5378 TMPDIR="${TOPDIR}/tmpmultix86"
5379 </literallayout></para>
5380
5381 <para>The location for these multiconfig
5382 configuration files is specific.
5383 They must reside in the current build directory in
5384 a sub-directory of <filename>conf</filename> named
5385 <filename>multiconfig</filename>.
5386 Following is an example that defines two
5387 configuration files for the "x86" and "arm"
5388 multiconfigs:
5389 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5390 </para>
5391
5392 <para>The reason for this required file hierarchy
5393 is because the <filename>BBPATH</filename> variable
5394 is not constructed until the layers are parsed.
5395 Consequently, using the configuration file as a
5396 pre-configuration file is not possible unless it is
5397 located in the current working directory.
5398 </para></listitem>
5399 <listitem><para>
5400 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5401 Use the
5402 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5403 variable in your
5404 <filename>conf/local.conf</filename> configuration
5405 file to specify each multiconfig.
5406 Continuing with the example from the previous
5407 figure, the <filename>BBMULTICONFIG</filename>
5408 variable needs to enable two multiconfigs: "x86"
5409 and "arm" by specifying each configuration file:
5410 <literallayout class='monospaced'>
5411 BBMULTICONFIG = "x86 arm"
5412 </literallayout>
5413 </para></listitem>
5414 <listitem><para>
5415 <emphasis>Launch BitBake</emphasis>:
5416 Use the following BitBake command form to launch the
5417 multiple configuration build:
5418 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005419 $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005420 </literallayout>
5421 For the example in this section, the following
5422 command applies:
5423 <literallayout class='monospaced'>
5424 $ bitbake multiconfig:x86:core-image-minimal multiconfig:arm:core-image-sato
5425 </literallayout>
5426 The previous BitBake command builds a
5427 <filename>core-image-minimal</filename> image that
5428 is configured through the
5429 <filename>x86.conf</filename> configuration file
5430 and builds a <filename>core-image-sato</filename>
5431 image that is configured through the
5432 <filename>arm.conf</filename> configuration file.
5433 </para></listitem>
5434 </itemizedlist>
5435 <note>
5436 Support for multiple configuration builds in the
5437 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5438 not include Shared State (sstate) optimizations.
5439 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005440 in, for example, two different
5441 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005442 either loads from an existing sstate cache for that
5443 build at the start or builds the object fresh.
5444 </note>
5445 </para>
5446 </section>
5447
5448 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5449 <title>Enabling Multiple Configuration Build Dependencies</title>
5450
5451 <para>
5452 Sometimes dependencies can exist between targets
5453 (multiconfigs) in a multiple configuration build.
5454 For example, suppose that in order to build a
5455 <filename>core-image-sato</filename> image for an "x86"
5456 multiconfig, the root filesystem of an "arm"
5457 multiconfig must exist.
5458 This dependency is essentially that the
5459 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5460 task in the <filename>core-image-sato</filename> recipe
5461 depends on the completion of the
5462 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5463 task of the <filename>core-image-minimal</filename>
5464 recipe.
5465 </para>
5466
5467 <para>
5468 To enable dependencies in a multiple configuration
5469 build, you must declare the dependencies in the recipe
5470 using the following statement form:
5471 <literallayout class='monospaced'>
5472 <replaceable>task_or_package</replaceable>[mcdepends] = "multiconfig:<replaceable>from_multiconfig</replaceable>:<replaceable>to_multiconfig</replaceable>:<replaceable>recipe_name</replaceable>:<replaceable>task_on_which_to_depend</replaceable>"
5473 </literallayout>
5474 To better show how to use this statement, consider the
5475 example scenario from the first paragraph of this section.
5476 The following statement needs to be added to the recipe
5477 that builds the <filename>core-image-sato</filename>
5478 image:
5479 <literallayout class='monospaced'>
5480 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_rootfs"
5481 </literallayout>
5482 In this example, the
5483 <replaceable>from_multiconfig</replaceable> is "x86".
5484 The <replaceable>to_multiconfig</replaceable> is "arm".
5485 The task on which the <filename>do_image</filename> task
5486 in the recipe depends is the <filename>do_rootfs</filename>
5487 task from the <filename>core-image-minimal</filename>
5488 recipe associated with the "arm" multiconfig.
5489 </para>
5490
5491 <para>
5492 Once you set up this dependency, you can build the
5493 "x86" multiconfig using a BitBake command as follows:
5494 <literallayout class='monospaced'>
5495 $ bitbake multiconfig:x86:core-image-sato
5496 </literallayout>
5497 This command executes all the tasks needed to create
5498 the <filename>core-image-sato</filename> image for the
5499 "x86" multiconfig.
5500 Because of the dependency, BitBake also executes through
5501 the <filename>do_rootfs</filename> task for the "arm"
5502 multiconfig build.
5503 </para>
5504
5505 <para>
5506 Having a recipe depend on the root filesystem of another
5507 build might not seem that useful.
5508 Consider this change to the statement in the
5509 <filename>core-image-sato</filename> recipe:
5510 <literallayout class='monospaced'>
5511 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_image"
5512 </literallayout>
5513 In this case, BitBake must create the
5514 <filename>core-image-minimal</filename> image for the
5515 "arm" build since the "x86" build depends on it.
5516 </para>
5517
5518 <para>
5519 Because "x86" and "arm" are enabled for multiple
5520 configuration builds and have separate configuration
5521 files, BitBake places the artifacts for each build in the
5522 respective temporary build directories (i.e.
5523 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5524 </para>
5525 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005526 </section>
5527
5528 <section id='building-an-initramfs-image'>
5529 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5530
5531 <para>
5532 An initial RAM filesystem (initramfs) image provides a temporary
5533 root filesystem used for early system initialization (e.g.
5534 loading of modules needed to locate and mount the "real" root
5535 filesystem).
5536 <note>
5537 The initramfs image is the successor of initial RAM disk
5538 (initrd).
5539 It is a "copy in and out" (cpio) archive of the initial
5540 filesystem that gets loaded into memory during the Linux
5541 startup process.
5542 Because Linux uses the contents of the archive during
5543 initialization, the initramfs image needs to contain all of the
5544 device drivers and tools needed to mount the final root
5545 filesystem.
5546 </note>
5547 </para>
5548
5549 <para>
5550 Follow these steps to create an initramfs image:
5551 <orderedlist>
5552 <listitem><para>
5553 <emphasis>Create the initramfs Image Recipe:</emphasis>
5554 You can reference the
5555 <filename>core-image-minimal-initramfs.bb</filename>
5556 recipe found in the <filename>meta/recipes-core</filename>
5557 directory of the
5558 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5559 as an example from which to work.
5560 </para></listitem>
5561 <listitem><para>
5562 <emphasis>Decide if You Need to Bundle the initramfs Image
5563 Into the Kernel Image:</emphasis>
5564 If you want the initramfs image that is built to be
5565 bundled in with the kernel image, set the
5566 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5567 variable to "1" in your <filename>local.conf</filename>
5568 configuration file and set the
5569 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5570 variable in the recipe that builds the kernel image.
5571 <note><title>Tip</title>
5572 It is recommended that you do bundle the initramfs
5573 image with the kernel image to avoid circular
5574 dependencies between the kernel recipe and the
5575 initramfs recipe should the initramfs image
5576 include kernel modules.
5577 </note>
5578 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5579 flag causes the initramfs image to be unpacked
5580 into the <filename>${B}/usr/</filename> directory.
5581 The unpacked initramfs image is then passed to the kernel's
5582 <filename>Makefile</filename> using the
5583 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5584 variable, allowing the initramfs image to be built into
5585 the kernel normally.
5586 <note>
5587 If you choose to not bundle the initramfs image with
5588 the kernel image, you are essentially using an
5589 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5590 Creating an initrd is handled primarily through the
5591 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5592 <filename>INITRD_LIVE</filename>, and
5593 <filename>INITRD_IMAGE_LIVE</filename> variables.
5594 For more information, see the
5595 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5596 file.
5597 </note>
5598 </para></listitem>
5599 <listitem><para>
5600 <emphasis>Optionally Add Items to the initramfs Image
5601 Through the initramfs Image Recipe:</emphasis>
5602 If you add items to the initramfs image by way of its
5603 recipe, you should use
5604 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5605 rather than
5606 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5607 <filename>PACKAGE_INSTALL</filename> gives more direct
5608 control of what is added to the image as compared to
5609 the defaults you might not necessarily want that are
5610 set by the
5611 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5612 or
5613 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5614 classes.
5615 </para></listitem>
5616 <listitem><para>
5617 <emphasis>Build the Kernel Image and the initramfs
5618 Image:</emphasis>
5619 Build your kernel image using BitBake.
5620 Because the initramfs image recipe is a dependency of the
5621 kernel image, the initramfs image is built as well and
5622 bundled with the kernel image if you used the
5623 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5624 variable described earlier.
5625 </para></listitem>
5626 </orderedlist>
5627 </para>
5628 </section>
5629
5630 <section id='building-a-tiny-system'>
5631 <title>Building a Tiny System</title>
5632
5633 <para>
5634 Very small distributions have some significant advantages such
5635 as requiring less on-die or in-package memory (cheaper), better
5636 performance through efficient cache usage, lower power requirements
5637 due to less memory, faster boot times, and reduced development
5638 overhead.
5639 Some real-world examples where a very small distribution gives
5640 you distinct advantages are digital cameras, medical devices,
5641 and small headless systems.
5642 </para>
5643
5644 <para>
5645 This section presents information that shows you how you can
5646 trim your distribution to even smaller sizes than the
5647 <filename>poky-tiny</filename> distribution, which is around
5648 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5649 </para>
5650
5651 <section id='tiny-system-overview'>
5652 <title>Overview</title>
5653
5654 <para>
5655 The following list presents the overall steps you need to
5656 consider and perform to create distributions with smaller
5657 root filesystems, achieve faster boot times, maintain your critical
5658 functionality, and avoid initial RAM disks:
5659 <itemizedlist>
5660 <listitem><para>
5661 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5662 </para></listitem>
5663 <listitem><para>
5664 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5665 </para></listitem>
5666 <listitem><para>
5667 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5668 </para></listitem>
5669 <listitem><para>
5670 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5671 </para></listitem>
5672 <listitem><para>
5673 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5674 </para></listitem>
5675 <listitem><para>
5676 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5677 </para></listitem>
5678 <listitem><para>
5679 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5680 </para></listitem>
5681 </itemizedlist>
5682 </para>
5683 </section>
5684
5685 <section id='goals-and-guiding-principles'>
5686 <title>Goals and Guiding Principles</title>
5687
5688 <para>
5689 Before you can reach your destination, you need to know
5690 where you are going.
5691 Here is an example list that you can use as a guide when
5692 creating very small distributions:
5693 <itemizedlist>
5694 <listitem><para>Determine how much space you need
5695 (e.g. a kernel that is 1 Mbyte or less and
5696 a root filesystem that is 3 Mbytes or less).
5697 </para></listitem>
5698 <listitem><para>Find the areas that are currently
5699 taking 90% of the space and concentrate on reducing
5700 those areas.
5701 </para></listitem>
5702 <listitem><para>Do not create any difficult "hacks"
5703 to achieve your goals.</para></listitem>
5704 <listitem><para>Leverage the device-specific
5705 options.</para></listitem>
5706 <listitem><para>Work in a separate layer so that you
5707 keep changes isolated.
5708 For information on how to create layers, see
5709 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5710 </para></listitem>
5711 </itemizedlist>
5712 </para>
5713 </section>
5714
5715 <section id='understand-what-gives-your-image-size'>
5716 <title>Understand What Contributes to Your Image Size</title>
5717
5718 <para>
5719 It is easiest to have something to start with when creating
5720 your own distribution.
5721 You can use the Yocto Project out-of-the-box to create the
5722 <filename>poky-tiny</filename> distribution.
5723 Ultimately, you will want to make changes in your own
5724 distribution that are likely modeled after
5725 <filename>poky-tiny</filename>.
5726 <note>
5727 To use <filename>poky-tiny</filename> in your build,
5728 set the
5729 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5730 variable in your
5731 <filename>local.conf</filename> file to "poky-tiny"
5732 as described in the
5733 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5734 section.
5735 </note>
5736 </para>
5737
5738 <para>
5739 Understanding some memory concepts will help you reduce the
5740 system size.
5741 Memory consists of static, dynamic, and temporary memory.
5742 Static memory is the TEXT (code), DATA (initialized data
5743 in the code), and BSS (uninitialized data) sections.
5744 Dynamic memory represents memory that is allocated at runtime:
5745 stacks, hash tables, and so forth.
5746 Temporary memory is recovered after the boot process.
5747 This memory consists of memory used for decompressing
5748 the kernel and for the <filename>__init__</filename>
5749 functions.
5750 </para>
5751
5752 <para>
5753 To help you see where you currently are with kernel and root
5754 filesystem sizes, you can use two tools found in the
5755 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5756 the <filename>scripts/tiny/</filename> directory:
5757 <itemizedlist>
5758 <listitem><para><filename>ksize.py</filename>: Reports
5759 component sizes for the kernel build objects.
5760 </para></listitem>
5761 <listitem><para><filename>dirsize.py</filename>: Reports
5762 component sizes for the root filesystem.</para></listitem>
5763 </itemizedlist>
5764 This next tool and command help you organize configuration
5765 fragments and view file dependencies in a human-readable form:
5766 <itemizedlist>
5767 <listitem><para><filename>merge_config.sh</filename>:
5768 Helps you manage configuration files and fragments
5769 within the kernel.
5770 With this tool, you can merge individual configuration
5771 fragments together.
5772 The tool allows you to make overrides and warns you
5773 of any missing configuration options.
5774 The tool is ideal for allowing you to iterate on
5775 configurations, create minimal configurations, and
5776 create configuration files for different machines
5777 without having to duplicate your process.</para>
5778 <para>The <filename>merge_config.sh</filename> script is
5779 part of the Linux Yocto kernel Git repositories
5780 (i.e. <filename>linux-yocto-3.14</filename>,
5781 <filename>linux-yocto-3.10</filename>,
5782 <filename>linux-yocto-3.8</filename>, and so forth)
5783 in the
5784 <filename>scripts/kconfig</filename> directory.</para>
5785 <para>For more information on configuration fragments,
5786 see the
5787 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5788 section in the Yocto Project Linux Kernel Development
5789 Manual.
5790 </para></listitem>
5791 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5792 Using the BitBake command with these options brings up
5793 a Dependency Explorer from which you can view file
5794 dependencies.
5795 Understanding these dependencies allows you to make
5796 informed decisions when cutting out various pieces of the
5797 kernel and root filesystem.</para></listitem>
5798 </itemizedlist>
5799 </para>
5800 </section>
5801
5802 <section id='trim-the-root-filesystem'>
5803 <title>Trim the Root Filesystem</title>
5804
5805 <para>
5806 The root filesystem is made up of packages for booting,
5807 libraries, and applications.
5808 To change things, you can configure how the packaging happens,
5809 which changes the way you build them.
5810 You can also modify the filesystem itself or select a different
5811 filesystem.
5812 </para>
5813
5814 <para>
5815 First, find out what is hogging your root filesystem by running the
5816 <filename>dirsize.py</filename> script from your root directory:
5817 <literallayout class='monospaced'>
5818 $ cd <replaceable>root-directory-of-image</replaceable>
5819 $ dirsize.py 100000 > dirsize-100k.log
5820 $ cat dirsize-100k.log
5821 </literallayout>
5822 You can apply a filter to the script to ignore files under
5823 a certain size.
5824 The previous example filters out any files below 100 Kbytes.
5825 The sizes reported by the tool are uncompressed, and thus
5826 will be smaller by a relatively constant factor in a
5827 compressed root filesystem.
5828 When you examine your log file, you can focus on areas of the
5829 root filesystem that take up large amounts of memory.
5830 </para>
5831
5832 <para>
5833 You need to be sure that what you eliminate does not cripple
5834 the functionality you need.
5835 One way to see how packages relate to each other is by using
5836 the Dependency Explorer UI with the BitBake command:
5837 <literallayout class='monospaced'>
5838 $ cd <replaceable>image-directory</replaceable>
5839 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5840 </literallayout>
5841 Use the interface to select potential packages you wish to
5842 eliminate and see their dependency relationships.
5843 </para>
5844
5845 <para>
5846 When deciding how to reduce the size, get rid of packages that
5847 result in minimal impact on the feature set.
5848 For example, you might not need a VGA display.
5849 Or, you might be able to get by with <filename>devtmpfs</filename>
5850 and <filename>mdev</filename> instead of
5851 <filename>udev</filename>.
5852 </para>
5853
5854 <para>
5855 Use your <filename>local.conf</filename> file to make changes.
5856 For example, to eliminate <filename>udev</filename> and
5857 <filename>glib</filename>, set the following in the
5858 local configuration file:
5859 <literallayout class='monospaced'>
5860 VIRTUAL-RUNTIME_dev_manager = ""
5861 </literallayout>
5862 </para>
5863
5864 <para>
5865 Finally, you should consider exactly the type of root
5866 filesystem you need to meet your needs while also reducing
5867 its size.
5868 For example, consider <filename>cramfs</filename>,
5869 <filename>squashfs</filename>, <filename>ubifs</filename>,
5870 <filename>ext2</filename>, or an <filename>initramfs</filename>
5871 using <filename>initramfs</filename>.
5872 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5873 journal.
5874 If you are okay with running read-only, you do not need this
5875 journal.
5876 </para>
5877
5878 <note>
5879 After each round of elimination, you need to rebuild your
5880 system and then use the tools to see the effects of your
5881 reductions.
5882 </note>
5883 </section>
5884
5885 <section id='trim-the-kernel'>
5886 <title>Trim the Kernel</title>
5887
5888 <para>
5889 The kernel is built by including policies for hardware-independent
5890 aspects.
5891 What subsystems do you enable?
5892 For what architecture are you building?
5893 Which drivers do you build by default?
5894 <note>You can modify the kernel source if you want to help
5895 with boot time.
5896 </note>
5897 </para>
5898
5899 <para>
5900 Run the <filename>ksize.py</filename> script from the top-level
5901 Linux build directory to get an idea of what is making up
5902 the kernel:
5903 <literallayout class='monospaced'>
5904 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5905 $ ksize.py > ksize.log
5906 $ cat ksize.log
5907 </literallayout>
5908 When you examine the log, you will see how much space is
5909 taken up with the built-in <filename>.o</filename> files for
5910 drivers, networking, core kernel files, filesystem, sound,
5911 and so forth.
5912 The sizes reported by the tool are uncompressed, and thus
5913 will be smaller by a relatively constant factor in a compressed
5914 kernel image.
5915 Look to reduce the areas that are large and taking up around
5916 the "90% rule."
5917 </para>
5918
5919 <para>
5920 To examine, or drill down, into any particular area, use the
5921 <filename>-d</filename> option with the script:
5922 <literallayout class='monospaced'>
5923 $ ksize.py -d > ksize.log
5924 </literallayout>
5925 Using this option breaks out the individual file information
5926 for each area of the kernel (e.g. drivers, networking, and
5927 so forth).
5928 </para>
5929
5930 <para>
5931 Use your log file to see what you can eliminate from the kernel
5932 based on features you can let go.
5933 For example, if you are not going to need sound, you do not
5934 need any drivers that support sound.
5935 </para>
5936
5937 <para>
5938 After figuring out what to eliminate, you need to reconfigure
5939 the kernel to reflect those changes during the next build.
5940 You could run <filename>menuconfig</filename> and make all your
5941 changes at once.
5942 However, that makes it difficult to see the effects of your
5943 individual eliminations and also makes it difficult to replicate
5944 the changes for perhaps another target device.
5945 A better method is to start with no configurations using
5946 <filename>allnoconfig</filename>, create configuration
5947 fragments for individual changes, and then manage the
5948 fragments into a single configuration file using
5949 <filename>merge_config.sh</filename>.
5950 The tool makes it easy for you to iterate using the
5951 configuration change and build cycle.
5952 </para>
5953
5954 <para>
5955 Each time you make configuration changes, you need to rebuild
5956 the kernel and check to see what impact your changes had on
5957 the overall size.
5958 </para>
5959 </section>
5960
5961 <section id='remove-package-management-requirements'>
5962 <title>Remove Package Management Requirements</title>
5963
5964 <para>
5965 Packaging requirements add size to the image.
5966 One way to reduce the size of the image is to remove all the
5967 packaging requirements from the image.
5968 This reduction includes both removing the package manager
5969 and its unique dependencies as well as removing the package
5970 management data itself.
5971 </para>
5972
5973 <para>
5974 To eliminate all the packaging requirements for an image,
5975 be sure that "package-management" is not part of your
5976 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5977 statement for the image.
5978 When you remove this feature, you are removing the package
5979 manager as well as its dependencies from the root filesystem.
5980 </para>
5981 </section>
5982
5983 <section id='look-for-other-ways-to-minimize-size'>
5984 <title>Look for Other Ways to Minimize Size</title>
5985
5986 <para>
5987 Depending on your particular circumstances, other areas that you
5988 can trim likely exist.
5989 The key to finding these areas is through tools and methods
5990 described here combined with experimentation and iteration.
5991 Here are a couple of areas to experiment with:
5992 <itemizedlist>
5993 <listitem><para><filename>glibc</filename>:
5994 In general, follow this process:
5995 <orderedlist>
5996 <listitem><para>Remove <filename>glibc</filename>
5997 features from
5998 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
5999 that you think you do not need.</para></listitem>
6000 <listitem><para>Build your distribution.
6001 </para></listitem>
6002 <listitem><para>If the build fails due to missing
6003 symbols in a package, determine if you can
6004 reconfigure the package to not need those
6005 features.
6006 For example, change the configuration to not
6007 support wide character support as is done for
6008 <filename>ncurses</filename>.
6009 Or, if support for those characters is needed,
6010 determine what <filename>glibc</filename>
6011 features provide the support and restore the
6012 configuration.
6013 </para></listitem>
6014 <listitem><para>Rebuild and repeat the process.
6015 </para></listitem>
6016 </orderedlist></para></listitem>
6017 <listitem><para><filename>busybox</filename>:
6018 For BusyBox, use a process similar as described for
6019 <filename>glibc</filename>.
6020 A difference is you will need to boot the resulting
6021 system to see if you are able to do everything you
6022 expect from the running system.
6023 You need to be sure to integrate configuration fragments
6024 into Busybox because BusyBox handles its own core
6025 features and then allows you to add configuration
6026 fragments on top.
6027 </para></listitem>
6028 </itemizedlist>
6029 </para>
6030 </section>
6031
6032 <section id='iterate-on-the-process'>
6033 <title>Iterate on the Process</title>
6034
6035 <para>
6036 If you have not reached your goals on system size, you need
6037 to iterate on the process.
6038 The process is the same.
6039 Use the tools and see just what is taking up 90% of the root
6040 filesystem and the kernel.
6041 Decide what you can eliminate without limiting your device
6042 beyond what you need.
6043 </para>
6044
6045 <para>
6046 Depending on your system, a good place to look might be
6047 Busybox, which provides a stripped down
6048 version of Unix tools in a single, executable file.
6049 You might be able to drop virtual terminal services or perhaps
6050 ipv6.
6051 </para>
6052 </section>
6053 </section>
6054
6055 <section id='building-images-for-more-than-one-machine'>
6056 <title>Building Images for More than One Machine</title>
6057
6058 <para>
6059 A common scenario developers face is creating images for several
6060 different machines that use the same software environment.
6061 In this situation, it is tempting to set the
6062 tunings and optimization flags for each build specifically for
6063 the targeted hardware (i.e. "maxing out" the tunings).
6064 Doing so can considerably add to build times and package feed
6065 maintenance collectively for the machines.
6066 For example, selecting tunes that are extremely specific to a
6067 CPU core used in a system might enable some micro optimizations
6068 in GCC for that particular system but would otherwise not gain
6069 you much of a performance difference across the other systems
6070 as compared to using a more general tuning across all the builds
6071 (e.g. setting
6072 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6073 specifically for each machine's build).
6074 Rather than "max out" each build's tunings, you can take steps that
6075 cause the OpenEmbedded build system to reuse software across the
6076 various machines where it makes sense.
6077 </para>
6078
6079 <para>
6080 If build speed and package feed maintenance are considerations,
6081 you should consider the points in this section that can help you
6082 optimize your tunings to best consider build times and package
6083 feed maintenance.
6084 <itemizedlist>
6085 <listitem><para>
6086 <emphasis>Share the Build Directory:</emphasis>
6087 If at all possible, share the
6088 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6089 across builds.
6090 The Yocto Project supports switching between different
6091 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6092 values in the same <filename>TMPDIR</filename>.
6093 This practice is well supported and regularly used by
6094 developers when building for multiple machines.
6095 When you use the same <filename>TMPDIR</filename> for
6096 multiple machine builds, the OpenEmbedded build system can
6097 reuse the existing native and often cross-recipes for
6098 multiple machines.
6099 Thus, build time decreases.
6100 <note>
6101 If
6102 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6103 settings change or fundamental configuration settings
6104 such as the filesystem layout, you need to work with
6105 a clean <filename>TMPDIR</filename>.
6106 Sharing <filename>TMPDIR</filename> under these
6107 circumstances might work but since it is not
6108 guaranteed, you should use a clean
6109 <filename>TMPDIR</filename>.
6110 </note>
6111 </para></listitem>
6112 <listitem><para>
6113 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6114 By default, the OpenEmbedded build system enables three
6115 levels of package architectures: "all", "tune" or "package",
6116 and "machine".
6117 Any given recipe usually selects one of these package
6118 architectures (types) for its output.
6119 Depending for what a given recipe creates packages, making
6120 sure you enable the appropriate package architecture can
6121 directly impact the build time.</para>
6122
6123 <para>A recipe that just generates scripts can enable
6124 "all" architecture because there are no binaries to build.
6125 To specifically enable "all" architecture, be sure your
6126 recipe inherits the
6127 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6128 class.
6129 This class is useful for "all" architectures because it
6130 configures many variables so packages can be used across
6131 multiple architectures.</para>
6132
6133 <para>If your recipe needs to generate packages that are
6134 machine-specific or when one of the build or runtime
6135 dependencies is already machine-architecture dependent,
6136 which makes your recipe also machine-architecture dependent,
6137 make sure your recipe enables the "machine" package
6138 architecture through the
6139 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6140 variable:
6141 <literallayout class='monospaced'>
6142 PACKAGE_ARCH = "${MACHINE_ARCH}"
6143 </literallayout>
6144 When you do not specifically enable a package
6145 architecture through the
6146 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6147 The OpenEmbedded build system defaults to the
6148 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6149 setting:
6150 <literallayout class='monospaced'>
6151 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6152 </literallayout>
6153 </para></listitem>
6154 <listitem><para>
6155 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6156 Some tunes are more generic and can run on multiple targets
6157 (e.g. an <filename>armv5</filename> set of packages could
6158 run on <filename>armv6</filename> and
6159 <filename>armv7</filename> processors in most cases).
6160 Similarly, <filename>i486</filename> binaries could work
6161 on <filename>i586</filename> and higher processors.
6162 You should realize, however, that advances on newer
6163 processor versions would not be used.</para>
6164
6165 <para>If you select the same tune for several different
6166 machines, the OpenEmbedded build system reuses software
6167 previously built, thus speeding up the overall build time.
6168 Realize that even though a new sysroot for each machine is
6169 generated, the software is not recompiled and only one
6170 package feed exists.
6171 </para></listitem>
6172 <listitem><para>
6173 <emphasis>Manage Granular Level Packaging:</emphasis>
6174 Sometimes cases exist where injecting another level of
6175 package architecture beyond the three higher levels noted
6176 earlier can be useful.
6177 For example, consider how NXP (formerly Freescale) allows
6178 for the easy reuse of binary packages in their layer
6179 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6180 In this example, the
6181 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6182 class shares GPU packages for i.MX53 boards because
6183 all boards share the AMD GPU.
6184 The i.MX6-based boards can do the same because all boards
6185 share the Vivante GPU.
6186 This class inspects the BitBake datastore to identify if
6187 the package provides or depends on one of the
6188 sub-architecture values.
6189 If so, the class sets the
6190 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6191 value based on the <filename>MACHINE_SUBARCH</filename>
6192 value.
6193 If the package does not provide or depend on one of the
6194 sub-architecture values but it matches a value in the
6195 machine-specific filter, it sets
6196 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6197 This behavior reduces the number of packages built and
6198 saves build time by reusing binaries.
6199 </para></listitem>
6200 <listitem><para>
6201 <emphasis>Use Tools to Debug Issues:</emphasis>
6202 Sometimes you can run into situations where software is
6203 being rebuilt when you think it should not be.
6204 For example, the OpenEmbedded build system might not be
6205 using shared state between machines when you think it
6206 should be.
6207 These types of situations are usually due to references
6208 to machine-specific variables such as
6209 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6210 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6211 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6212 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6213 and so forth in code that is supposed to only be
6214 tune-specific or when the recipe depends
6215 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6216 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6217 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6218 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6219 and so forth) on some other recipe that already has
6220 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6221 defined as "${MACHINE_ARCH}".
6222 <note>
6223 Patches to fix any issues identified are most welcome
6224 as these issues occasionally do occur.
6225 </note></para>
6226
6227 <para>For such cases, you can use some tools to help you
6228 sort out the situation:
6229 <itemizedlist>
6230 <listitem><para>
6231 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6232 You can find this tool in the
6233 <filename>scripts</filename> directory of the
6234 Source Repositories.
6235 See the comments in the script for information on
6236 how to use the tool.
6237 </para></listitem>
6238 <listitem><para>
6239 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6240 Using this option causes BitBake to try to
6241 establish the closest signature match it can
6242 (e.g. in the shared state cache) and then run
6243 <filename>bitbake-diffsigs</filename> over the
6244 matches to determine the stamps and delta where
6245 these two stamp trees diverge.
6246 </para></listitem>
6247 </itemizedlist>
6248 </para></listitem>
6249 </itemizedlist>
6250 </para>
6251 </section>
6252
6253 <section id="building-software-from-an-external-source">
6254 <title>Building Software from an External Source</title>
6255
6256 <para>
6257 By default, the OpenEmbedded build system uses the
6258 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6259 when building source code.
6260 The build process involves fetching the source files, unpacking
6261 them, and then patching them if necessary before the build takes
6262 place.
6263 </para>
6264
6265 <para>
6266 Situations exist where you might want to build software from source
6267 files that are external to and thus outside of the
6268 OpenEmbedded build system.
6269 For example, suppose you have a project that includes a new BSP with
6270 a heavily customized kernel.
6271 And, you want to minimize exposing the build system to the
6272 development team so that they can focus on their project and
6273 maintain everyone's workflow as much as possible.
6274 In this case, you want a kernel source directory on the development
6275 machine where the development occurs.
6276 You want the recipe's
6277 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6278 variable to point to the external directory and use it as is, not
6279 copy it.
6280 </para>
6281
6282 <para>
6283 To build from software that comes from an external source, all you
6284 need to do is inherit the
6285 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6286 class and then set the
6287 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6288 variable to point to your external source code.
6289 Here are the statements to put in your
6290 <filename>local.conf</filename> file:
6291 <literallayout class='monospaced'>
6292 INHERIT += "externalsrc"
6293 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6294 </literallayout>
6295 </para>
6296
6297 <para>
6298 This next example shows how to accomplish the same thing by setting
6299 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6300 recipe's append file:
6301 <literallayout class='monospaced'>
6302 EXTERNALSRC = "<replaceable>path</replaceable>"
6303 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6304 </literallayout>
6305 <note>
6306 In order for these settings to take effect, you must globally
6307 or locally inherit the
6308 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6309 class.
6310 </note>
6311 </para>
6312
6313 <para>
6314 By default, <filename>externalsrc.bbclass</filename> builds
6315 the source code in a directory separate from the external source
6316 directory as specified by
6317 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6318 If you need to have the source built in the same directory in
6319 which it resides, or some other nominated directory, you can set
6320 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6321 to point to that directory:
6322 <literallayout class='monospaced'>
6323 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6324 </literallayout>
6325 </para>
6326 </section>
Brad Bishop19323692019-04-05 15:28:33 -04006327
6328 <section id="replicating-a-build-offline">
6329 <title>Replicating a Build Offline</title>
6330
6331 <para>
6332 It can be useful to take a "snapshot" of upstream sources
6333 used in a build and then use that "snapshot" later to
6334 replicate the build offline.
6335 To do so, you need to first prepare and populate your downloads
6336 directory your "snapshot" of files.
6337 Once your downloads directory is ready, you can use it at
6338 any time and from any machine to replicate your build.
6339 </para>
6340
6341 <para>
6342 Follow these steps to populate your Downloads directory:
6343 <orderedlist>
6344 <listitem><para>
6345 <emphasis>Create a Clean Downloads Directory:</emphasis>
6346 Start with an empty downloads directory
6347 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>).
6348 You start with an empty downloads directory by either
6349 removing the files in the existing directory or by
6350 setting
6351 <filename>DL_DIR</filename> to point to either an
6352 empty location or one that does not yet exist.
6353 </para></listitem>
6354 <listitem><para>
6355 <emphasis>Generate Tarballs of the Source Git Repositories:</emphasis>
6356 Edit your <filename>local.conf</filename> configuration
6357 file as follows:
6358 <literallayout class='monospaced'>
6359 DL_DIR = "/home/<replaceable>your-download-dir</replaceable>/"
6360 BB_GENERATE_MIRROR_TARBALLS = "1"
6361 </literallayout>
6362 During the fetch process in the next step, BitBake
6363 gathers the source files and creates tarballs in
6364 the directory pointed to by <filename>DL_DIR</filename>.
6365 See the
6366 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
6367 variable for more information.
6368 </para></listitem>
6369 <listitem><para>
6370 <emphasis>Populate Your Downloads Directory Without Building:</emphasis>
6371 Use BitBake to fetch your sources but inhibit the
6372 build:
6373 <literallayout class='monospaced'>
6374 $ bitbake <replaceable>target</replaceable> --runonly=fetch
6375 </literallayout>
6376 The downloads directory (i.e.
6377 <filename>${DL_DIR}</filename>) now has a "snapshot" of
6378 the source files in the form of tarballs, which can
6379 be used for the build.
6380 </para></listitem>
6381 <listitem><para>
6382 <emphasis>Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory:</emphasis>
6383 If you want, you can clean up your downloads directory
6384 by removing any Git or other Source Control Management
6385 (SCM) subdirectories such as
6386 <filename>${DL_DIR}/git2/*</filename>.
6387 The tarballs already contain these subdirectories.
6388 </para></listitem>
6389 </orderedlist>
6390 </para>
6391
6392 <para>
6393 Once your downloads directory has everything it needs regarding
6394 source files, you can create your "own-mirror" and build
6395 your target.
6396 Understand that you can use the files to build the target
6397 offline from any machine and at any time.
6398 </para>
6399
6400 <para>
6401 Follow these steps to build your target using the files in the
6402 downloads directory:
6403 <orderedlist>
6404 <listitem><para>
6405 <emphasis>Using Local Files Only:</emphasis>
6406 Inside your <filename>local.conf</filename> file, add
6407 the
6408 <ulink url='&YOCTO_DOCS_REF_URL;#var-SOURCE_MIRROR_URL'><filename>SOURCE_MIRROR_URL</filename></ulink>
6409 variable,
6410 inherit the <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-own-mirrors'><filename>own-mirrors</filename></ulink>
6411 class, and use the
6412 <ulink url='&YOCTO_DOCS_BB_URL;#var-bb-BB_NO_NETWORK'><filename>BB_NO_NETWORK</filename></ulink>
6413 variable to your <filename>local.conf</filename>.
6414 <literallayout class='monospaced'>
6415 SOURCE_MIRROR_URL ?= "file:///home/<replaceable>your-download-dir</replaceable>/"
6416 INHERIT += "own-mirrors"
6417 BB_NO_NETWORK = "1"
6418 </literallayout>
6419 The <filename>SOURCE_MIRROR_URL</filename> and
6420 <filename>own-mirror</filename> class set up the system
6421 to use the downloads directory as your "own mirror".
6422 Using the <filename>BB_NO_NETWORK</filename>
6423 variable makes sure that BitBake's fetching process
6424 in step 3 stays local, which means files from
6425 your "own-mirror" are used.
6426 </para></listitem>
6427 <listitem><para>
6428 <emphasis>Start With a Clean Build:</emphasis>
6429 You can start with a clean build by removing the
6430 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
6431 directory or using a new
6432 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
6433 </para></listitem>
6434 <listitem><para>
6435 <emphasis>Build Your Target:</emphasis>
6436 Use BitBake to build your target:
6437 <literallayout class='monospaced'>
6438 $ bitbake <replaceable>target</replaceable>
6439 </literallayout>
6440 The build completes using the known local "snapshot" of
6441 source files from your mirror.
6442 The resulting tarballs for your "snapshot" of source
6443 files are in the downloads directory.
6444 <note>
6445 <para>The offline build does not work if recipes
6446 attempt to find the latest version of software
6447 by setting
6448 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
6449 to
6450 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink><filename>}</filename>:
6451 <literallayout class='monospaced'>
6452 SRCREV = "${AUTOREV}"
6453 </literallayout>
6454 When a recipe sets
6455 <filename>SRCREV</filename> to
6456 <filename>${AUTOREV}</filename>, the build system
6457 accesses the network in an attempt to determine the
6458 latest version of software from the SCM.
6459 Typically, recipes that use
6460 <filename>AUTOREV</filename> are custom or
6461 modified recipes.
6462 Recipes that reside in public repositories
6463 usually do not use <filename>AUTOREV</filename>.
6464 </para>
6465
6466 <para>If you do have recipes that use
6467 <filename>AUTOREV</filename>, you can take steps to
6468 still use the recipes in an offline build.
6469 Do the following:
6470 <orderedlist>
6471 <listitem><para>
6472 Use a configuration generated by
6473 enabling
6474 <link linkend='maintaining-build-output-quality'>build history</link>.
6475 </para></listitem>
6476 <listitem><para>
6477 Use the
6478 <filename>buildhistory-collect-srcrevs</filename>
6479 command to collect the stored
6480 <filename>SRCREV</filename> values from
6481 the build's history.
6482 For more information on collecting these
6483 values, see the
6484 "<link linkend='build-history-package-information'>Build History Package Information</link>"
6485 section.
6486 </para></listitem>
6487 <listitem><para>
6488 Once you have the correct source
6489 revisions, you can modify those recipes
6490 to to set <filename>SRCREV</filename>
6491 to specific versions of the software.
6492 </para></listitem>
6493 </orderedlist>
6494 </para>
6495 </note>
6496 </para></listitem>
6497 </orderedlist>
6498 </para>
6499 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006500 </section>
6501
Brad Bishop316dfdd2018-06-25 12:45:53 -04006502 <section id='speeding-up-a-build'>
6503 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006504
6505 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006506 Build time can be an issue.
6507 By default, the build system uses simple controls to try and maximize
6508 build efficiency.
6509 In general, the default settings for all the following variables
6510 result in the most efficient build times when dealing with single
6511 socket systems (i.e. a single CPU).
6512 If you have multiple CPUs, you might try increasing the default
6513 values to gain more speed.
6514 See the descriptions in the glossary for each variable for more
6515 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006516 <itemizedlist>
6517 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006518 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6519 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006520 </para></listitem>
6521 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006522 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6523 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006524 </para></listitem>
6525 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006526 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6527 Extra options passed to the <filename>make</filename> command
6528 during the
6529 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6530 task in order to specify parallel compilation on the
6531 local build host.
6532 </para></listitem>
6533 <listitem><para>
6534 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6535 Extra options passed to the <filename>make</filename> command
6536 during the
6537 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6538 task in order to specify parallel installation on the
6539 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006540 </para></listitem>
6541 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006542 As mentioned, these variables all scale to the number of processor
6543 cores available on the build system.
6544 For single socket systems, this auto-scaling ensures that the build
6545 system fundamentally takes advantage of potential parallel operations
6546 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006547 </para>
6548
6549 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006550 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006551 <itemizedlist>
6552 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006553 File system type:
6554 The file system type that the build is being performed on can
6555 also influence performance.
6556 Using <filename>ext4</filename> is recommended as compared
6557 to <filename>ext2</filename> and <filename>ext3</filename>
6558 due to <filename>ext4</filename> improved features
6559 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006560 </para></listitem>
6561 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006562 Disabling the updating of access time using
6563 <filename>noatime</filename>:
6564 The <filename>noatime</filename> mount option prevents the
6565 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006566 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006567 <listitem><para>
6568 Setting a longer commit:
6569 Using the "commit=" mount option increases the interval
6570 in seconds between disk cache writes.
6571 Changing this interval from the five second default to
6572 something longer increases the risk of data loss but decreases
6573 the need to write to the disk, thus increasing the build
6574 performance.
6575 </para></listitem>
6576 <listitem><para>
6577 Choosing the packaging backend:
6578 Of the available packaging backends, IPK is the fastest.
6579 Additionally, selecting a singular packaging backend also
6580 helps.
6581 </para></listitem>
6582 <listitem><para>
6583 Using <filename>tmpfs</filename> for
6584 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6585 as a temporary file system:
6586 While this can help speed up the build, the benefits are
6587 limited due to the compiler using
6588 <filename>-pipe</filename>.
6589 The build system goes to some lengths to avoid
6590 <filename>sync()</filename> calls into the
6591 file system on the principle that if there was a significant
6592 failure, the
6593 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6594 contents could easily be rebuilt.
6595 </para></listitem>
6596 <listitem><para>
6597 Inheriting the
6598 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6599 class:
6600 Inheriting this class has shown to speed up builds due to
6601 significantly lower amounts of data stored in the data
6602 cache as well as on disk.
6603 Inheriting this class also makes cleanup of
6604 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6605 faster, at the expense of being easily able to dive into the
6606 source code.
6607 File system maintainers have recommended that the fastest way
6608 to clean up large numbers of files is to reformat partitions
6609 rather than delete files due to the linear nature of
6610 partitions.
6611 This, of course, assumes you structure the disk partitions and
6612 file systems in a way that this is practical.
6613 </para></listitem>
6614 </itemizedlist>
6615 Aside from the previous list, you should keep some trade offs in
6616 mind that can help you speed up the build:
6617 <itemizedlist>
6618 <listitem><para>
6619 Remove items from
6620 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6621 that you might not need.
6622 </para></listitem>
6623 <listitem><para>
6624 Exclude debug symbols and other debug information:
6625 If you do not need these symbols and other debug information,
6626 disabling the <filename>*-dbg</filename> package generation
6627 can speed up the build.
6628 You can disable this generation by setting the
6629 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6630 variable to "1".
6631 </para></listitem>
6632 <listitem><para>
6633 Disable static library generation for recipes derived from
6634 <filename>autoconf</filename> or <filename>libtool</filename>:
6635 Following is an example showing how to disable static
6636 libraries and still provide an override to handle exceptions:
6637 <literallayout class='monospaced'>
6638 STATICLIBCONF = "--disable-static"
6639 STATICLIBCONF_sqlite3-native = ""
6640 EXTRA_OECONF += "${STATICLIBCONF}"
6641 </literallayout>
6642 <note><title>Notes</title>
6643 <itemizedlist>
6644 <listitem><para>
6645 Some recipes need static libraries in order to work
6646 correctly (e.g. <filename>pseudo-native</filename>
6647 needs <filename>sqlite3-native</filename>).
6648 Overrides, as in the previous example, account for
6649 these kinds of exceptions.
6650 </para></listitem>
6651 <listitem><para>
6652 Some packages have packaging code that assumes the
6653 presence of the static libraries.
6654 If so, you might need to exclude them as well.
6655 </para></listitem>
6656 </itemizedlist>
6657 </note>
6658 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006659 </itemizedlist>
6660 </para>
6661 </section>
6662
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006663 <section id="platdev-working-with-libraries">
6664 <title>Working With Libraries</title>
6665
6666 <para>
6667 Libraries are an integral part of your system.
6668 This section describes some common practices you might find
6669 helpful when working with libraries to build your system:
6670 <itemizedlist>
6671 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6672 </para></listitem>
6673 <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>
6674 </para></listitem>
6675 <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>
6676 </para></listitem>
6677 </itemizedlist>
6678 </para>
6679
6680 <section id='including-static-library-files'>
6681 <title>Including Static Library Files</title>
6682
6683 <para>
6684 If you are building a library and the library offers static linking, you can control
6685 which static library files (<filename>*.a</filename> files) get included in the
6686 built library.
6687 </para>
6688
6689 <para>
6690 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6691 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6692 variables in the
6693 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6694 by the <filename>do_install</filename> task are packaged.
6695 By default, the <filename>PACKAGES</filename> variable includes
6696 <filename>${PN}-staticdev</filename>, which represents all static library files.
6697 <note>
6698 Some previously released versions of the Yocto Project
6699 defined the static library files through
6700 <filename>${PN}-dev</filename>.
6701 </note>
6702 Following is part of the BitBake configuration file, where
6703 you can see how the static library files are defined:
6704 <literallayout class='monospaced'>
6705 PACKAGE_BEFORE_PN ?= ""
6706 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6707 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6708 FILES = ""
6709
6710 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6711 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6712 ${base_bindir}/* ${base_sbindir}/* \
6713 ${base_libdir}/*${SOLIBS} \
6714 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6715 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6716 ${datadir}/pixmaps ${datadir}/applications \
6717 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6718 ${libdir}/bonobo/servers"
6719
6720 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6721
6722 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6723 ${datadir}/gnome/help"
6724 SECTION_${PN}-doc = "doc"
6725
6726 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6727 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6728 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6729 ${datadir}/aclocal ${base_libdir}/*.o \
6730 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6731 SECTION_${PN}-dev = "devel"
6732 ALLOW_EMPTY_${PN}-dev = "1"
6733 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6734
6735 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6736 SECTION_${PN}-staticdev = "devel"
6737 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6738 </literallayout>
6739 </para>
6740 </section>
6741
6742 <section id="combining-multiple-versions-library-files-into-one-image">
6743 <title>Combining Multiple Versions of Library Files into One Image</title>
6744
6745 <para>
6746 The build system offers the ability to build libraries with different
6747 target optimizations or architecture formats and combine these together
6748 into one system image.
6749 You can link different binaries in the image
6750 against the different libraries as needed for specific use cases.
6751 This feature is called "Multilib."
6752 </para>
6753
6754 <para>
6755 An example would be where you have most of a system compiled in 32-bit
6756 mode using 32-bit libraries, but you have something large, like a database
6757 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6758 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6759 </para>
6760
6761 <para>
6762 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6763 the approach the build system uses facilitates different target optimizations.
6764 You could compile some binaries to use one set of libraries and other binaries
6765 to use a different set of libraries.
6766 The libraries could differ in architecture, compiler options, or other
6767 optimizations.
6768 </para>
6769
6770 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006771 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006772 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006773 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006774 <itemizedlist>
6775 <listitem><para><filename>conf/multilib-example.conf</filename>
6776 configuration file</para></listitem>
6777 <listitem><para><filename>conf/multilib-example2.conf</filename>
6778 configuration file</para></listitem>
6779 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6780 recipe</para></listitem>
6781 </itemizedlist>
6782 </para>
6783
6784 <section id='preparing-to-use-multilib'>
6785 <title>Preparing to Use Multilib</title>
6786
6787 <para>
6788 User-specific requirements drive the Multilib feature.
6789 Consequently, there is no one "out-of-the-box" configuration that likely
6790 exists to meet your needs.
6791 </para>
6792
6793 <para>
6794 In order to enable Multilib, you first need to ensure your recipe is
6795 extended to support multiple libraries.
6796 Many standard recipes are already extended and support multiple libraries.
6797 You can check in the <filename>meta/conf/multilib.conf</filename>
6798 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006799 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006800 done using the
6801 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6802 variable.
6803 Eventually, all recipes will be covered and this list will
6804 not be needed.
6805 </para>
6806
6807 <para>
6808 For the most part, the Multilib class extension works automatically to
6809 extend the package name from <filename>${PN}</filename> to
6810 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6811 is the particular multilib (e.g. "lib32-" or "lib64-").
6812 Standard variables such as
6813 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6814 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6815 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6816 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6817 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6818 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6819 are automatically extended by the system.
6820 If you are extending any manual code in the recipe, you can use the
6821 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6822 correctly.
6823 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6824 </para>
6825 </section>
6826
6827 <section id='using-multilib'>
6828 <title>Using Multilib</title>
6829
6830 <para>
6831 After you have set up the recipes, you need to define the actual
6832 combination of multiple libraries you want to build.
6833 You accomplish this through your <filename>local.conf</filename>
6834 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006835 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006836 An example configuration would be as follows:
6837 <literallayout class='monospaced'>
6838 MACHINE = "qemux86-64"
6839 require conf/multilib.conf
6840 MULTILIBS = "multilib:lib32"
6841 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006842 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006843 </literallayout>
6844 This example enables an
6845 additional library named <filename>lib32</filename> alongside the
6846 normal target packages.
6847 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6848 For information on this particular tuning, see
6849 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6850 </para>
6851
6852 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006853 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006854 in all the images, which illustrates one method of including a
6855 multiple library dependency.
6856 You can use a normal image build to include this dependency,
6857 for example:
6858 <literallayout class='monospaced'>
6859 $ bitbake core-image-sato
6860 </literallayout>
6861 You can also build Multilib packages specifically with a command like this:
6862 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006863 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006864 </literallayout>
6865 </para>
6866 </section>
6867
6868 <section id='additional-implementation-details'>
6869 <title>Additional Implementation Details</title>
6870
6871 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006872 Generic implementation details as well as details that are
6873 specific to package management systems exist.
6874 Following are implementation details that exist regardless
6875 of the package management system:
6876 <itemizedlist>
6877 <listitem><para>The typical convention used for the
6878 class extension code as used by
6879 Multilib assumes that all package names specified
6880 in
6881 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6882 that contain <filename>${PN}</filename> have
6883 <filename>${PN}</filename> at the start of the name.
6884 When that convention is not followed and
6885 <filename>${PN}</filename> appears at
6886 the middle or the end of a name, problems occur.
6887 </para></listitem>
6888 <listitem><para>The
6889 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6890 value under Multilib will be extended to
6891 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6892 (e.g. "-pokymllib32" for a "lib32" Multilib with
6893 Poky).
6894 The reason for this slightly unwieldy contraction
6895 is that any "-" characters in the vendor
6896 string presently break Autoconf's
6897 <filename>config.sub</filename>, and
6898 other separators are problematic for different
6899 reasons.
6900 </para></listitem>
6901 </itemizedlist>
6902 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006903
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006904 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006905 For the RPM Package Management System, the following implementation details
6906 exist:
6907 <itemizedlist>
6908 <listitem><para>A unique architecture is defined for the Multilib packages,
6909 along with creating a unique deploy folder under
6910 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006911 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006912 For example, consider <filename>lib32</filename> in a
6913 <filename>qemux86-64</filename> image.
6914 The possible architectures in the system are "all", "qemux86_64",
6915 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6916 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6917 <filename>${PN}</filename> during RPM packaging.
6918 The naming for a normal RPM package and a Multilib RPM package in a
6919 <filename>qemux86-64</filename> system resolves to something similar to
6920 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6921 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6922 </para></listitem>
6923 <listitem><para>When installing a Multilib image, the RPM backend first
6924 installs the base image and then installs the Multilib libraries.
6925 </para></listitem>
6926 <listitem><para>The build system relies on RPM to resolve the identical files in the
6927 two (or more) Multilib packages.</para></listitem>
6928 </itemizedlist>
6929 </para>
6930
6931 <para>
6932 For the IPK Package Management System, the following implementation details exist:
6933 <itemizedlist>
6934 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6935 <filename>${PN}</filename> during IPK packaging.
6936 The naming for a normal RPM package and a Multilib IPK package in a
6937 <filename>qemux86-64</filename> system resolves to something like
6938 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6939 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6940 </para></listitem>
6941 <listitem><para>The IPK deploy folder is not modified with
6942 <filename>${MLPREFIX}</filename> because packages with and without
6943 the Multilib feature can exist in the same folder due to the
6944 <filename>${PN}</filename> differences.</para></listitem>
6945 <listitem><para>IPK defines a sanity check for Multilib installation
6946 using certain rules for file comparison, overridden, etc.
6947 </para></listitem>
6948 </itemizedlist>
6949 </para>
6950 </section>
6951 </section>
6952
6953 <section id='installing-multiple-versions-of-the-same-library'>
6954 <title>Installing Multiple Versions of the Same Library</title>
6955
6956 <para>
6957 Situations can exist where you need to install and use
6958 multiple versions of the same library on the same system
6959 at the same time.
6960 These situations almost always exist when a library API
6961 changes and you have multiple pieces of software that
6962 depend on the separate versions of the library.
6963 To accommodate these situations, you can install multiple
6964 versions of the same library in parallel on the same system.
6965 </para>
6966
6967 <para>
6968 The process is straightforward as long as the libraries use
6969 proper versioning.
6970 With properly versioned libraries, all you need to do to
6971 individually specify the libraries is create separate,
6972 appropriately named recipes where the
6973 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6974 name includes a portion that differentiates each library version
6975 (e.g.the major part of the version number).
6976 Thus, instead of having a single recipe that loads one version
6977 of a library (e.g. <filename>clutter</filename>), you provide
6978 multiple recipes that result in different versions
6979 of the libraries you want.
6980 As an example, the following two recipes would allow the
6981 two separate versions of the <filename>clutter</filename>
6982 library to co-exist on the same system:
6983 <literallayout class='monospaced'>
6984 clutter-1.6_1.6.20.bb
6985 clutter-1.8_1.8.4.bb
6986 </literallayout>
6987 Additionally, if you have other recipes that depend on a given
6988 library, you need to use the
6989 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
6990 variable to create the dependency.
6991 Continuing with the same example, if you want to have a recipe
6992 depend on the 1.8 version of the <filename>clutter</filename>
6993 library, use the following in your recipe:
6994 <literallayout class='monospaced'>
6995 DEPENDS = "clutter-1.8"
6996 </literallayout>
6997 </para>
6998 </section>
6999 </section>
7000
Brad Bishop316dfdd2018-06-25 12:45:53 -04007001 <section id='using-x32-psabi'>
7002 <title>Using x32 psABI</title>
7003
7004 <para>
7005 x32 processor-specific Application Binary Interface
7006 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
7007 is a native 32-bit processor-specific ABI for
7008 <trademark class='registered'>Intel</trademark> 64 (x86-64)
7009 architectures.
7010 An ABI defines the calling conventions between functions in a
7011 processing environment.
7012 The interface determines what registers are used and what the
7013 sizes are for various C data types.
7014 </para>
7015
7016 <para>
7017 Some processing environments prefer using 32-bit applications even
7018 when running on Intel 64-bit platforms.
7019 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
7020 64-bit platforms.
7021 The i386 psABI does not provide efficient use and access of the
7022 Intel 64-bit processor resources, leaving the system underutilized.
7023 Now consider the x86_64 psABI.
7024 This ABI is newer and uses 64-bits for data sizes and program
7025 pointers.
7026 The extra bits increase the footprint size of the programs,
7027 libraries, and also increases the memory and file system size
7028 requirements.
7029 Executing under the x32 psABI enables user programs to utilize CPU
7030 and system resources more efficiently while keeping the memory
7031 footprint of the applications low.
7032 Extra bits are used for registers but not for addressing mechanisms.
7033 </para>
7034
7035 <para>
7036 The Yocto Project supports the final specifications of x32 psABI
7037 as follows:
7038 <itemizedlist>
7039 <listitem><para>
7040 You can create packages and images in x32 psABI format on
7041 x86_64 architecture targets.
7042 </para></listitem>
7043 <listitem><para>
7044 You can successfully build recipes with the x32 toolchain.
7045 </para></listitem>
7046 <listitem><para>
7047 You can create and boot
7048 <filename>core-image-minimal</filename> and
7049 <filename>core-image-sato</filename> images.
7050 </para></listitem>
7051 <listitem><para>
7052 RPM Package Manager (RPM) support exists for x32 binaries.
7053 </para></listitem>
7054 <listitem><para>
7055 Support for large images exists.
7056 </para></listitem>
7057 </itemizedlist>
7058 </para>
7059
7060 <para>
7061 To use the x32 psABI, you need to edit your
7062 <filename>conf/local.conf</filename> configuration file as
7063 follows:
7064 <literallayout class='monospaced'>
7065 MACHINE = "qemux86-64"
7066 DEFAULTTUNE = "x86-64-x32"
Brad Bishop19323692019-04-05 15:28:33 -04007067 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
7068 or 'INVALID')) or 'lib'}"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007069 </literallayout>
7070 Once you have set up your configuration file, use BitBake to
7071 build an image that supports the x32 psABI.
7072 Here is an example:
7073 <literallayout class='monospaced'>
7074 $ bitbake core-image-sato
7075 </literallayout>
7076 </para>
7077 </section>
7078
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007079 <section id='enabling-gobject-introspection-support'>
7080 <title>Enabling GObject Introspection Support</title>
7081
7082 <para>
7083 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
7084 is the standard mechanism for accessing GObject-based software
7085 from runtime environments.
7086 GObject is a feature of the GLib library that provides an object
7087 framework for the GNOME desktop and related software.
7088 GObject Introspection adds information to GObject that allows
7089 objects created within it to be represented across different
7090 programming languages.
7091 If you want to construct GStreamer pipelines using Python, or
7092 control UPnP infrastructure using Javascript and GUPnP,
7093 GObject introspection is the only way to do it.
7094 </para>
7095
7096 <para>
7097 This section describes the Yocto Project support for generating
7098 and packaging GObject introspection data.
7099 GObject introspection data is a description of the
7100 API provided by libraries built on top of GLib framework,
7101 and, in particular, that framework's GObject mechanism.
7102 GObject Introspection Repository (GIR) files go to
7103 <filename>-dev</filename> packages,
7104 <filename>typelib</filename> files go to main packages as they
7105 are packaged together with libraries that are introspected.
7106 </para>
7107
7108 <para>
7109 The data is generated when building such a library, by linking
7110 the library with a small executable binary that asks the library
7111 to describe itself, and then executing the binary and
7112 processing its output.
7113 </para>
7114
7115 <para>
7116 Generating this data in a cross-compilation environment
7117 is difficult because the library is produced for the target
7118 architecture, but its code needs to be executed on the build host.
7119 This problem is solved with the OpenEmbedded build system by
7120 running the code through QEMU, which allows precisely that.
7121 Unfortunately, QEMU does not always work perfectly as mentioned
7122 in the xxx section.
7123 </para>
7124
7125 <section id='enabling-the-generation-of-introspection-data'>
7126 <title>Enabling the Generation of Introspection Data</title>
7127
7128 <para>
7129 Enabling the generation of introspection data (GIR files)
7130 in your library package involves the following:
7131 <orderedlist>
7132 <listitem><para>
7133 Inherit the
7134 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
7135 class.
7136 </para></listitem>
7137 <listitem><para>
7138 Make sure introspection is not disabled anywhere in
7139 the recipe or from anything the recipe includes.
7140 Also, make sure that "gobject-introspection-data" is
7141 not in
7142 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7143 and that "qemu-usermode" is not in
7144 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7145 If either of these conditions exist, nothing will
7146 happen.
7147 </para></listitem>
7148 <listitem><para>
7149 Try to build the recipe.
7150 If you encounter build errors that look like
7151 something is unable to find
7152 <filename>.so</filename> libraries, check where these
7153 libraries are located in the source tree and add
7154 the following to the recipe:
7155 <literallayout class='monospaced'>
7156 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
7157 </literallayout>
7158 <note>
7159 See recipes in the <filename>oe-core</filename>
7160 repository that use that
7161 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
7162 as an example.
7163 </note>
7164 </para></listitem>
7165 <listitem><para>
7166 Look for any other errors, which probably mean that
7167 introspection support in a package is not entirely
7168 standard, and thus breaks down in a cross-compilation
7169 environment.
7170 For such cases, custom-made fixes are needed.
7171 A good place to ask and receive help in these cases
7172 is the
7173 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7174 </para></listitem>
7175 </orderedlist>
7176 <note>
7177 Using a library that no longer builds against the latest
7178 Yocto Project release and prints introspection related
7179 errors is a good candidate for the previous procedure.
7180 </note>
7181 </para>
7182 </section>
7183
7184 <section id='disabling-the-generation-of-introspection-data'>
7185 <title>Disabling the Generation of Introspection Data</title>
7186
7187 <para>
7188 You might find that you do not want to generate
7189 introspection data.
7190 Or, perhaps QEMU does not work on your build host and
7191 target architecture combination.
7192 If so, you can use either of the following methods to
7193 disable GIR file generations:
7194 <itemizedlist>
7195 <listitem><para>
7196 Add the following to your distro configuration:
7197 <literallayout class='monospaced'>
7198 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7199 </literallayout>
7200 Adding this statement disables generating
7201 introspection data using QEMU but will still enable
7202 building introspection tools and libraries
7203 (i.e. building them does not require the use of QEMU).
7204 </para></listitem>
7205 <listitem><para>
7206 Add the following to your machine configuration:
7207 <literallayout class='monospaced'>
7208 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7209 </literallayout>
7210 Adding this statement disables the use of QEMU
7211 when building packages for your machine.
7212 Currently, this feature is used only by introspection
7213 recipes and has the same effect as the previously
7214 described option.
7215 <note>
7216 Future releases of the Yocto Project might have
7217 other features affected by this option.
7218 </note>
7219 </para></listitem>
7220 </itemizedlist>
7221 If you disable introspection data, you can still
7222 obtain it through other means such as copying the data
7223 from a suitable sysroot, or by generating it on the
7224 target hardware.
7225 The OpenEmbedded build system does not currently
7226 provide specific support for these techniques.
7227 </para>
7228 </section>
7229
7230 <section id='testing-that-introspection-works-in-an-image'>
7231 <title>Testing that Introspection Works in an Image</title>
7232
7233 <para>
7234 Use the following procedure to test if generating
7235 introspection data is working in an image:
7236 <orderedlist>
7237 <listitem><para>
7238 Make sure that "gobject-introspection-data" is not in
7239 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7240 and that "qemu-usermode" is not in
7241 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7242 </para></listitem>
7243 <listitem><para>
7244 Build <filename>core-image-sato</filename>.
7245 </para></listitem>
7246 <listitem><para>
7247 Launch a Terminal and then start Python in the
7248 terminal.
7249 </para></listitem>
7250 <listitem><para>
7251 Enter the following in the terminal:
7252 <literallayout class='monospaced'>
7253 >>> from gi.repository import GLib
7254 >>> GLib.get_host_name()
7255 </literallayout>
7256 </para></listitem>
7257 <listitem><para>
7258 For something a little more advanced, enter the
7259 following:
7260 <literallayout class='monospaced'>
7261 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7262 </literallayout>
7263 </para></listitem>
7264 </orderedlist>
7265 </para>
7266 </section>
7267
7268 <section id='known-issues'>
7269 <title>Known Issues</title>
7270
7271 <para>
7272 The following know issues exist for
7273 GObject Introspection Support:
7274 <itemizedlist>
7275 <listitem><para>
7276 <filename>qemu-ppc64</filename> immediately crashes.
7277 Consequently, you cannot build introspection data on
7278 that architecture.
7279 </para></listitem>
7280 <listitem><para>
7281 x32 is not supported by QEMU.
7282 Consequently, introspection data is disabled.
7283 </para></listitem>
7284 <listitem><para>
7285 musl causes transient GLib binaries to crash on
7286 assertion failures.
7287 Consequently, generating introspection data is
7288 disabled.
7289 </para></listitem>
7290 <listitem><para>
7291 Because QEMU is not able to run the binaries correctly,
7292 introspection is disabled for some specific packages
7293 under specific architectures (e.g.
7294 <filename>gcr</filename>,
7295 <filename>libsecret</filename>, and
7296 <filename>webkit</filename>).
7297 </para></listitem>
7298 <listitem><para>
7299 QEMU usermode might not work properly when running
7300 64-bit binaries under 32-bit host machines.
7301 In particular, "qemumips64" is known to not work under
7302 i686.
7303 </para></listitem>
7304 </itemizedlist>
7305 </para>
7306 </section>
7307 </section>
7308
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007309 <section id='dev-optionally-using-an-external-toolchain'>
7310 <title>Optionally Using an External Toolchain</title>
7311
7312 <para>
7313 You might want to use an external toolchain as part of your
7314 development.
7315 If this is the case, the fundamental steps you need to accomplish
7316 are as follows:
7317 <itemizedlist>
7318 <listitem><para>
7319 Understand where the installed toolchain resides.
7320 For cases where you need to build the external toolchain,
7321 you would need to take separate steps to build and install
7322 the toolchain.
7323 </para></listitem>
7324 <listitem><para>
7325 Make sure you add the layer that contains the toolchain to
7326 your <filename>bblayers.conf</filename> file through the
7327 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7328 variable.
7329 </para></listitem>
7330 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007331 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007332 variable in your <filename>local.conf</filename> file
7333 to the location in which you installed the toolchain.
7334 </para></listitem>
7335 </itemizedlist>
7336 A good example of an external toolchain used with the Yocto Project
7337 is <trademark class='registered'>Mentor Graphics</trademark>
7338 Sourcery G++ Toolchain.
7339 You can see information on how to use that particular layer in the
7340 <filename>README</filename> file at
7341 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7342 You can find further information by reading about the
7343 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7344 variable in the Yocto Project Reference Manual's variable glossary.
7345 </para>
7346 </section>
7347
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007348 <section id='creating-partitioned-images-using-wic'>
7349 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007350
7351 <para>
7352 Creating an image for a particular hardware target using the
7353 OpenEmbedded build system does not necessarily mean you can boot
7354 that image as is on your device.
7355 Physical devices accept and boot images in various ways depending
7356 on the specifics of the device.
7357 Usually, information about the hardware can tell you what image
7358 format the device requires.
7359 Should your device require multiple partitions on an SD card, flash,
7360 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007361 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007362 </para>
7363
7364 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007365 The <filename>wic</filename> command generates partitioned
7366 images from existing OpenEmbedded build artifacts.
7367 Image generation is driven by partitioning commands
7368 contained in an Openembedded kickstart file
7369 (<filename>.wks</filename>) specified either directly on
7370 the command line or as one of a selection of canned
7371 kickstart files as shown with the
7372 <filename>wic list images</filename> command in the
7373 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7374 section.
7375 When you apply the command to a given set of build
7376 artifacts, the result is an image or set of images that
7377 can be directly written onto media and used on a particular
7378 system.
7379 <note>
7380 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007381 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007382 Chapter in the Yocto Project Reference Manual.
7383 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007384 </para>
7385
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007386 <para>
7387 The <filename>wic</filename> command and the infrastructure
7388 it is based on is by definition incomplete.
7389 The purpose of the command is to allow the generation of
7390 customized images, and as such, was designed to be
Brad Bishopc342db32019-05-15 21:57:59 -04007391 completely extensible through a plugin interface.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007392 See the
Brad Bishopc342db32019-05-15 21:57:59 -04007393 "<link linkend='wic-using-the-wic-plugin-interface'>Using the Wic PlugIn Interface</link>"
7394 section for information on these plugins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007395 </para>
7396
7397 <para>
7398 This section provides some background information on Wic,
7399 describes what you need to have in
7400 place to run the tool, provides instruction on how to use
Brad Bishopc342db32019-05-15 21:57:59 -04007401 the Wic utility, provides information on using the Wic plugins
Brad Bishop316dfdd2018-06-25 12:45:53 -04007402 interface, and provides several examples that show how to use
7403 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007404 </para>
7405
7406 <section id='wic-background'>
7407 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007408
7409 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007410 This section provides some background on the Wic utility.
7411 While none of this information is required to use
7412 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007413 <itemizedlist>
7414 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007415 The name "Wic" is derived from OpenEmbedded
7416 Image Creator (oeic).
7417 The "oe" diphthong in "oeic" was promoted to the
7418 letter "w", because "oeic" is both difficult to
7419 remember and to pronounce.
7420 </para></listitem>
7421 <listitem><para>
7422 Wic is loosely based on the
7423 Meego Image Creator (<filename>mic</filename>)
7424 framework.
7425 The Wic implementation has been
7426 heavily modified to make direct use of OpenEmbedded
7427 build artifacts instead of package installation and
7428 configuration, which are already incorporated within
7429 the OpenEmbedded artifacts.
7430 </para></listitem>
7431 <listitem><para>
7432 Wic is a completely independent
7433 standalone utility that initially provides
7434 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007435 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007436 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007437 class.
7438 The difference between Wic and those examples is
7439 that with Wic the functionality of those scripts is
7440 implemented by a general-purpose partitioning language,
7441 which is based on Redhat kickstart syntax.
7442 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007443 </itemizedlist>
7444 </para>
7445 </section>
7446
7447 <section id='wic-requirements'>
7448 <title>Requirements</title>
7449
7450 <para>
7451 In order to use the Wic utility with the OpenEmbedded Build
7452 system, your system needs to meet the following
7453 requirements:
7454 <itemizedlist>
7455 <listitem><para>
7456 The Linux distribution on your development host must
7457 support the Yocto Project.
7458 See the
7459 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7460 section in the Yocto Project Reference Manual for
7461 the list of distributions that support the
7462 Yocto Project.
7463 </para></listitem>
7464 <listitem><para>
7465 The standard system utilities, such as
7466 <filename>cp</filename>, must be installed on your
7467 development host system.
7468 </para></listitem>
7469 <listitem><para>
7470 You must have sourced the build environment
7471 setup script (i.e.
7472 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7473 found in the
7474 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7475 </para></listitem>
7476 <listitem><para>
7477 You need to have the build artifacts already
7478 available, which typically means that you must
7479 have already created an image using the
7480 Openembedded build system (e.g.
7481 <filename>core-image-minimal</filename>).
7482 While it might seem redundant to generate an image
7483 in order to create an image using
7484 Wic, the current version of
7485 Wic requires the artifacts
7486 in the form generated by the OpenEmbedded build
7487 system.
7488 </para></listitem>
7489 <listitem><para>
7490 You must build several native tools, which are
7491 built to run on the build system:
7492 <literallayout class='monospaced'>
7493 $ bitbake parted-native dosfstools-native mtools-native
7494 </literallayout>
7495 </para></listitem>
7496 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007497 Include "wic" as part of the
7498 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7499 variable.
7500 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007501 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007502 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007503 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007504 as part of the
7505 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7506 variable
7507 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007508 </itemizedlist>
7509 </para>
7510 </section>
7511
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007512 <section id='wic-getting-help'>
7513 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007514
7515 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007516 You can get general help for the <filename>wic</filename>
7517 command by entering the <filename>wic</filename> command
7518 by itself or by entering the command with a help argument
7519 as follows:
7520 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007521 $ wic -h
7522 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007523 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007524 </literallayout>
7525 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007526
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007527 <para>
7528 Currently, Wic supports seven commands:
7529 <filename>cp</filename>, <filename>create</filename>,
7530 <filename>help</filename>, <filename>list</filename>,
7531 <filename>ls</filename>, <filename>rm</filename>, and
7532 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007533 You can get help for all these commands except "help" by
7534 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007535 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007536 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007537 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007538 For example, the following command returns help for the
7539 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007540 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007541 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007542 </literallayout>
7543 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007544
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007545 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007546 Wic supports help for three topics:
7547 <filename>overview</filename>,
7548 <filename>plugins</filename>, and
7549 <filename>kickstart</filename>.
7550 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007551 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007552 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007553 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007554 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007555 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007556 $ wic help overview
7557 </literallayout>
7558 </para>
7559
7560 <para>
7561 One additional level of help exists for Wic.
7562 You can get help on individual images through the
7563 <filename>list</filename> command.
7564 You can use the <filename>list</filename> command to return the
7565 available Wic images as follows:
7566 <literallayout class='monospaced'>
7567 $ wic list images
7568 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7569 genericx86 Create an EFI disk image for genericx86*
7570 beaglebone-yocto Create SD card image for Beaglebone
7571 edgerouter Create SD card image for Edgerouter
7572 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7573 directdisk-gpt Create a 'pcbios' direct disk image
7574 mkefidisk Create an EFI disk image
7575 directdisk Create a 'pcbios' direct disk image
7576 systemd-bootdisk Create an EFI disk image with systemd-boot
7577 mkhybridiso Create a hybrid ISO image
7578 sdimage-bootpart Create SD card image with a boot partition
7579 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7580 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7581 </literallayout>
7582 Once you know the list of available Wic images, you can use
7583 <filename>help</filename> with the command to get help on a
7584 particular image.
7585 For example, the following command returns help on the
7586 "beaglebone-yocto" image:
7587 <literallayout class='monospaced'>
7588 $ wic list beaglebone-yocto help
7589
7590
7591 Creates a partitioned SD card image for Beaglebone.
7592 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007593 </literallayout>
7594 </para>
7595 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007596
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007597 <section id='operational-modes'>
7598 <title>Operational Modes</title>
7599
7600 <para>
7601 You can use Wic in two different
7602 modes, depending on how much control you need for
7603 specifying the Openembedded build artifacts that are
7604 used for creating the image: Raw and Cooked:
7605 <itemizedlist>
7606 <listitem><para>
7607 <emphasis>Raw Mode:</emphasis>
7608 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007609 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007610 </para></listitem>
7611 <listitem><para>
7612 <emphasis>Cooked Mode:</emphasis>
7613 The current
7614 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7615 setting and image name are used to automatically
7616 locate and provide the build artifacts.
7617 You just supply a kickstart file and the name
7618 of the image from which to use artifacts.
7619 </para></listitem>
7620 </itemizedlist>
7621 </para>
7622
7623 <para>
7624 Regardless of the mode you use, you need to have the build
7625 artifacts ready and available.
7626 </para>
7627
7628 <section id='raw-mode'>
7629 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007630
7631 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007632 Running Wic in raw mode allows you to specify all the
7633 partitions through the <filename>wic</filename>
7634 command line.
7635 The primary use for raw mode is if you have built
7636 your kernel outside of the Yocto Project
7637 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7638 In other words, you can point to arbitrary kernel,
7639 root filesystem locations, and so forth.
7640 Contrast this behavior with cooked mode where Wic
7641 looks in the Build Directory (e.g.
7642 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007643 </para>
7644
7645 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007646 The general form of the
7647 <filename>wic</filename> command in raw mode is:
7648 <literallayout class='monospaced'>
7649 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007650
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007651 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007652
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007653 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007654 An OpenEmbedded kickstart file. You can provide
7655 your own custom file or use a file from a set of
7656 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007657
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007658 optional arguments:
7659 -h, --help show this help message and exit
7660 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7661 name of directory to create image in
7662 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7663 name of the image to use the artifacts from e.g. core-
7664 image-sato
7665 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7666 path to the /rootfs dir to use as the .wks rootfs
7667 source
7668 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7669 path to the dir containing the boot artifacts (e.g.
7670 /EFI or /syslinux dirs) to use as the .wks bootimg
7671 source
7672 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7673 path to the dir containing the kernel to use in the
7674 .wks bootimg
7675 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7676 path to the native sysroot containing the tools to use
7677 to build the image
7678 -s, --skip-build-check
7679 skip the build check
7680 -f, --build-rootfs build rootfs
7681 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7682 compress image with specified compressor
7683 -m, --bmap generate .bmap
7684 --no-fstab-update Do not change fstab file.
7685 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7686 directory with &lt;image&gt;.env files that store bitbake
7687 variables
7688 -D, --debug output debug information
7689 </literallayout>
7690 <note>
7691 You do not need root privileges to run
7692 Wic.
7693 In fact, you should not run as root when using the
7694 utility.
7695 </note>
7696 </para>
7697 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007698
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007699 <section id='cooked-mode'>
7700 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007701
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007702 <para>
7703 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007704 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007705 In other words, you do not have to specify kernel or
7706 root filesystem locations as part of the command.
7707 All you need to provide is a kickstart file and the
7708 name of the image from which to use artifacts by using
7709 the "-e" option.
7710 Wic looks in the Build Directory (e.g.
7711 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7712 for artifacts.
7713 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007714
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007715 <para>
7716 The general form of the <filename>wic</filename>
7717 command using Cooked Mode is as follows:
7718 <literallayout class='monospaced'>
7719 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007720
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007721 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007722
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007723 <replaceable>wks_file</replaceable>:
7724 An OpenEmbedded kickstart file. You can provide
7725 your own custom file or use a file from a set of
7726 existing files provided with the Yocto Project
7727 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007728
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007729 required argument:
7730 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7731 name of the image to use the artifacts from e.g. core-
7732 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007733 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007734 </para>
7735 </section>
7736 </section>
7737
7738 <section id='using-a-provided-kickstart-file'>
7739 <title>Using an Existing Kickstart File</title>
7740
7741 <para>
7742 If you do not want to create your own kickstart file, you
7743 can use an existing file provided by the Wic installation.
7744 As shipped, kickstart files can be found in the
7745 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007746 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007747 in the following two locations:
7748 <literallayout class='monospaced'>
7749 poky/meta-yocto-bsp/wic
7750 poky/scripts/lib/wic/canned-wks
7751 </literallayout>
7752 Use the following command to list the available kickstart
7753 files:
7754 <literallayout class='monospaced'>
7755 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007756 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7757 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007758 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007759 edgerouter Create SD card image for Edgerouter
7760 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7761 directdisk-gpt Create a 'pcbios' direct disk image
7762 mkefidisk Create an EFI disk image
7763 directdisk Create a 'pcbios' direct disk image
7764 systemd-bootdisk Create an EFI disk image with systemd-boot
7765 mkhybridiso Create a hybrid ISO image
7766 sdimage-bootpart Create SD card image with a boot partition
7767 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7768 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7769 </literallayout>
7770 When you use an existing file, you do not have to use the
7771 <filename>.wks</filename> extension.
7772 Here is an example in Raw Mode that uses the
7773 <filename>directdisk</filename> file:
7774 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007775 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7776 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007777 </literallayout>
7778 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007779
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007780 <para>
7781 Here are the actual partition language commands
7782 used in the <filename>genericx86.wks</filename> file to
7783 generate an image:
7784 <literallayout class='monospaced'>
7785 # short-description: Create an EFI disk image for genericx86*
7786 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7787 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7788 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007789 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7790
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007791 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7792 </literallayout>
7793 </para>
7794 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007795
Brad Bishopc342db32019-05-15 21:57:59 -04007796 <section id='wic-using-the-wic-plugin-interface'>
7797 <title>Using the Wic Plugin Interface</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007798
7799 <para>
7800 You can extend and specialize Wic functionality by using
Brad Bishopc342db32019-05-15 21:57:59 -04007801 Wic plugins.
7802 This section explains the Wic plugin interface.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007803 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007804 Wic plugins consist of "source" and "imager" plugins.
7805 Imager plugins are beyond the scope of this section.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007806 </note>
7807 </para>
7808
7809 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007810 Source plugins provide a mechanism to customize partition
Brad Bishop316dfdd2018-06-25 12:45:53 -04007811 content during the Wic image generation process.
Brad Bishopc342db32019-05-15 21:57:59 -04007812 You can use source plugins to map values that you specify
Brad Bishop316dfdd2018-06-25 12:45:53 -04007813 using <filename>--source</filename> commands in kickstart
Brad Bishopc342db32019-05-15 21:57:59 -04007814 files (i.e. <filename>*.wks</filename>) to a plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007815 implementation used to populate a given partition.
7816 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007817 If you use plugins that have build-time dependencies
Brad Bishop316dfdd2018-06-25 12:45:53 -04007818 (e.g. native tools, bootloaders, and so forth)
7819 when building a Wic image, you need to specify those
7820 dependencies using the
7821 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7822 variable.
7823 </note>
7824 </para>
7825
7826 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007827 Source plugins are subclasses defined in plugin files.
7828 As shipped, the Yocto Project provides several plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007829 files.
Brad Bishopc342db32019-05-15 21:57:59 -04007830 You can see the source plugin files that ship with the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007831 Yocto Project
7832 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
Brad Bishopc342db32019-05-15 21:57:59 -04007833 Each of these plugin files contains source plugins that
Brad Bishop316dfdd2018-06-25 12:45:53 -04007834 are designed to populate a specific Wic image partition.
7835 </para>
7836
7837 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007838 Source plugins are subclasses of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007839 <filename>SourcePlugin</filename> class, which is
7840 defined in the
7841 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7842 file.
7843 For example, the <filename>BootimgEFIPlugin</filename>
Brad Bishopc342db32019-05-15 21:57:59 -04007844 source plugin found in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007845 <filename>bootimg-efi.py</filename> file is a subclass of
7846 the <filename>SourcePlugin</filename> class, which is found
7847 in the <filename>pluginbase.py</filename> file.
7848 </para>
7849
7850 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007851 You can also implement source plugins in a layer outside
Brad Bishop316dfdd2018-06-25 12:45:53 -04007852 of the Source Repositories (external layer).
Brad Bishopc342db32019-05-15 21:57:59 -04007853 To do so, be sure that your plugin files are located in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007854 a directory whose path is
7855 <filename>scripts/lib/wic/plugins/source/</filename>
7856 within your external layer.
Brad Bishopc342db32019-05-15 21:57:59 -04007857 When the plugin files are located there, the source
7858 plugins they contain are made available to Wic.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007859 </para>
7860
7861 <para>
7862 When the Wic implementation needs to invoke a
Brad Bishopc342db32019-05-15 21:57:59 -04007863 partition-specific implementation, it looks for the plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007864 with the same name as the <filename>--source</filename>
7865 parameter used in the kickstart file given to that
7866 partition.
7867 For example, if the partition is set up using the following
7868 command in a kickstart file:
7869 <literallayout class='monospaced'>
7870 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7871 </literallayout>
7872 The methods defined as class members of the matching
Brad Bishopc342db32019-05-15 21:57:59 -04007873 source plugin (i.e. <filename>bootimg-pcbios</filename>)
7874 in the <filename>bootimg-pcbios.py</filename> plugin file
Brad Bishop316dfdd2018-06-25 12:45:53 -04007875 are used.
7876 </para>
7877
7878 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007879 To be more concrete, here is the corresponding plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007880 definition from the <filename>bootimg-pcbios.py</filename>
7881 file for the previous command along with an example
7882 method called by the Wic implementation when it needs to
7883 prepare a partition using an implementation-specific
7884 function:
7885 <literallayout class='monospaced'>
7886 .
7887 .
7888 .
7889 class BootimgPcbiosPlugin(SourcePlugin):
7890 """
7891 Create MBR boot partition and install syslinux on it.
7892 """
7893
7894 name = 'bootimg-pcbios'
7895 .
7896 .
7897 .
7898 @classmethod
7899 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7900 oe_builddir, bootimg_dir, kernel_dir,
7901 rootfs_dir, native_sysroot):
7902 """
7903 Called to do the actual content population for a partition i.e. it
7904 'prepares' the partition to be incorporated into the image.
7905 In this case, prepare content for legacy bios boot partition.
7906 """
7907 .
7908 .
7909 .
7910 </literallayout>
Brad Bishopc342db32019-05-15 21:57:59 -04007911 If a subclass (plugin) itself does not implement a
Brad Bishop316dfdd2018-06-25 12:45:53 -04007912 particular function, Wic locates and uses the default
7913 version in the superclass.
Brad Bishopc342db32019-05-15 21:57:59 -04007914 It is for this reason that all source plugins are derived
Brad Bishop316dfdd2018-06-25 12:45:53 -04007915 from the <filename>SourcePlugin</filename> class.
7916 </para>
7917
7918 <para>
7919 The <filename>SourcePlugin</filename> class defined in
7920 the <filename>pluginbase.py</filename> file defines
Brad Bishopc342db32019-05-15 21:57:59 -04007921 a set of methods that source plugins can implement or
Brad Bishop316dfdd2018-06-25 12:45:53 -04007922 override.
Brad Bishopc342db32019-05-15 21:57:59 -04007923 Any plugins (subclass of
Brad Bishop316dfdd2018-06-25 12:45:53 -04007924 <filename>SourcePlugin</filename>) that do not implement
7925 a particular method inherit the implementation of the
7926 method from the <filename>SourcePlugin</filename> class.
7927 For more information, see the
7928 <filename>SourcePlugin</filename> class in the
7929 <filename>pluginbase.py</filename> file for details:
7930 </para>
7931
7932 <para>
7933 The following list describes the methods implemented in the
7934 <filename>SourcePlugin</filename> class:
7935 <itemizedlist>
7936 <listitem><para>
7937 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7938 Called to populate a partition with actual content.
7939 In other words, the method prepares the final
7940 partition image that is incorporated into the
7941 disk image.
7942 </para></listitem>
7943 <listitem><para>
7944 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7945 Called before
7946 <filename>do_prepare_partition()</filename> to
7947 create custom configuration files for a partition
7948 (e.g. syslinux or grub configuration files).
7949 </para></listitem>
7950 <listitem><para>
7951 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7952 Called after all partitions have been prepared and
7953 assembled into a disk image.
7954 This method provides a hook to allow finalization
7955 of a disk image (e.g. writing an MBR).
7956 </para></listitem>
7957 <listitem><para>
7958 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7959 Special content-staging hook called before
7960 <filename>do_prepare_partition()</filename>.
7961 This method is normally empty.</para>
7962
7963 <para>Typically, a partition just uses the passed-in
7964 parameters (e.g. the unmodified value of
7965 <filename>bootimg_dir</filename>).
7966 However, in some cases, things might need to be
7967 more tailored.
7968 As an example, certain files might additionally
7969 need to be taken from
7970 <filename>bootimg_dir + /boot</filename>.
7971 This hook allows those files to be staged in a
7972 customized fashion.
7973 <note>
7974 <filename>get_bitbake_var()</filename>
7975 allows you to access non-standard variables
7976 that you might want to use for this
7977 behavior.
7978 </note>
7979 </para></listitem>
7980 </itemizedlist>
7981 </para>
7982
7983 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007984 You can extend the source plugin mechanism.
7985 To add more hooks, create more source plugin methods
Brad Bishop316dfdd2018-06-25 12:45:53 -04007986 within <filename>SourcePlugin</filename> and the
7987 corresponding derived subclasses.
Brad Bishopc342db32019-05-15 21:57:59 -04007988 The code that calls the plugin methods uses the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007989 <filename>plugin.get_source_plugin_methods()</filename>
7990 function to find the method or methods needed by the call.
7991 Retrieval of those methods is accomplished by filling up
7992 a dict with keys that contain the method names of interest.
7993 On success, these will be filled in with the actual
7994 methods.
7995 See the Wic implementation for examples and details.
7996 </para>
7997 </section>
7998
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007999 <section id='wic-usage-examples'>
8000 <title>Examples</title>
8001
8002 <para>
8003 This section provides several examples that show how to use
8004 the Wic utility.
8005 All the examples assume the list of requirements in the
8006 "<link linkend='wic-requirements'>Requirements</link>"
8007 section have been met.
8008 The examples assume the previously generated image is
8009 <filename>core-image-minimal</filename>.
8010 </para>
8011
8012 <section id='generate-an-image-using-a-provided-kickstart-file'>
8013 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008014
8015 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008016 This example runs in Cooked Mode and uses the
8017 <filename>mkefidisk</filename> kickstart file:
8018 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008019 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008020 INFO: Building wic-tools...
8021 .
8022 .
8023 .
8024 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008025 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008026
8027 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008028 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8029 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8030 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8031 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 -05008032
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008033 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008034 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008035 </literallayout>
8036 The previous example shows the easiest way to create
8037 an image by running in cooked mode and supplying
8038 a kickstart file and the "-e" option to point to the
8039 existing build artifacts.
8040 Your <filename>local.conf</filename> file needs to have
8041 the
8042 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8043 variable set to the machine you are using, which is
8044 "qemux86" in this example.
8045 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008046
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008047 <para>
8048 Once the image builds, the output provides image
8049 location, artifact use, and kickstart file information.
8050 <note>
8051 You should always verify the details provided in the
8052 output to make sure that the image was indeed
8053 created exactly as expected.
8054 </note>
8055 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008056
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008057 <para>
8058 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008059 image from the Build Directory onto a USB stick, or
8060 whatever media for which you built your image, and boot
8061 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008062 You can write the image by using
8063 <filename>bmaptool</filename> or
8064 <filename>dd</filename>:
8065 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008066 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008067 </literallayout>
8068 or
8069 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008070 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008071 </literallayout>
8072 <note>
8073 For more information on how to use the
8074 <filename>bmaptool</filename> to flash a device
8075 with an image, see the
8076 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
8077 section.
8078 </note>
8079 </para>
8080 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008081
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008082 <section id='using-a-modified-kickstart-file'>
8083 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008084
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008085 <para>
8086 Because partitioned image creation is driven by the
8087 kickstart file, it is easy to affect image creation by
8088 changing the parameters in the file.
8089 This next example demonstrates that through modification
8090 of the <filename>directdisk-gpt</filename> kickstart
8091 file.
8092 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008093
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008094 <para>
8095 As mentioned earlier, you can use the command
8096 <filename>wic list images</filename> to show the list
8097 of existing kickstart files.
8098 The directory in which the
8099 <filename>directdisk-gpt.wks</filename> file resides is
8100 <filename>scripts/lib/image/canned-wks/</filename>,
8101 which is located in the
8102 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
8103 (e.g. <filename>poky</filename>).
8104 Because available files reside in this directory,
8105 you can create and add your own custom files to the
8106 directory.
8107 Subsequent use of the
8108 <filename>wic list images</filename> command would then
8109 include your kickstart files.
8110 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008111
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008112 <para>
8113 In this example, the existing
8114 <filename>directdisk-gpt</filename> file already does
8115 most of what is needed.
8116 However, for the hardware in this example, the image
8117 will need to boot from <filename>sdb</filename> instead
8118 of <filename>sda</filename>, which is what the
8119 <filename>directdisk-gpt</filename> kickstart file
8120 uses.
8121 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008122
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008123 <para>
8124 The example begins by making a copy of the
8125 <filename>directdisk-gpt.wks</filename> file in the
8126 <filename>scripts/lib/image/canned-wks</filename>
8127 directory and then by changing the lines that specify
8128 the target disk from which to boot.
8129 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008130 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
8131 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008132 </literallayout>
8133 Next, the example modifies the
8134 <filename>directdisksdb-gpt.wks</filename> file and
8135 changes all instances of
8136 "<filename>--ondisk sda</filename>" to
8137 "<filename>--ondisk sdb</filename>".
8138 The example changes the following two lines and leaves
8139 the remaining lines untouched:
8140 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008141 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008142 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
8143 </literallayout>
8144 Once the lines are changed, the example generates the
8145 <filename>directdisksdb-gpt</filename> image.
8146 The command points the process at the
8147 <filename>core-image-minimal</filename> artifacts for
8148 the Next Unit of Computing (nuc)
8149 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8150 the <filename>local.conf</filename>.
8151 <literallayout class='monospaced'>
8152 $ wic create directdisksdb-gpt -e core-image-minimal
8153 INFO: Building wic-tools...
8154 .
8155 .
8156 .
8157 Initialising tasks: 100% |#######################################| Time: 0:00:01
8158 NOTE: Executing SetScene Tasks
8159 NOTE: Executing RunQueue Tasks
8160 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
8161 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008162
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008163 INFO: The new image(s) can be found here:
8164 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008165
8166 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008167 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8168 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8169 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8170 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 -05008171
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008172 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008173 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008174 </literallayout>
8175 Continuing with the example, you can now directly
8176 <filename>dd</filename> the image to a USB stick, or
8177 whatever media for which you built your image,
8178 and boot the resulting media:
8179 <literallayout class='monospaced'>
8180 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8181 140966+0 records in
8182 140966+0 records out
8183 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8184 $ sudo eject /dev/sdb
8185 </literallayout>
8186 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008187 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008188
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008189 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8190 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008191
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008192 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008193 This next example manually specifies each build artifact
8194 (runs in Raw Mode) and uses a modified kickstart file.
8195 The example also uses the <filename>-o</filename> option
8196 to cause Wic to create the output
8197 somewhere other than the default output directory,
8198 which is the current directory:
8199 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008200 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8201 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8202 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8203 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8204 --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 -05008205
8206 INFO: Creating image(s)...
8207
8208 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008209 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008210
8211 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008212 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8213 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8214 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8215 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 -05008216
8217 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008218 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008219 </literallayout>
8220 For this example,
8221 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8222 did not have to be specified in the
8223 <filename>local.conf</filename> file since the
8224 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008225 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008226 </section>
8227
8228 <section id='using-wic-to-manipulate-an-image'>
8229 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008230
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008231 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008232 Wic image manipulation allows you to shorten turnaround
8233 time during image development.
8234 For example, you can use Wic to delete the kernel partition
8235 of a Wic image and then insert a newly built kernel.
8236 This saves you time from having to rebuild the entire image
8237 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008238 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008239 In order to use Wic to manipulate a Wic image as in
8240 this example, your development machine must have the
8241 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008242 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008243 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008244
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008245 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008246 The following example examines the contents of the Wic
8247 image, deletes the existing kernel, and then inserts a
8248 new kernel:
8249 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008250 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008251 <emphasis>List the Partitions:</emphasis>
8252 Use the <filename>wic ls</filename> command to list
8253 all the partitions in the Wic image:
8254 <literallayout class='monospaced'>
8255 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8256 Num Start End Size Fstype
8257 1 1048576 25041919 23993344 fat16
8258 2 25165824 72157183 46991360 ext4
8259 </literallayout>
8260 The previous output shows two partitions in the
8261 <filename>core-image-minimal-qemux86.wic</filename>
8262 image.
8263 </para></listitem>
8264 <listitem><para>
8265 <emphasis>Examine a Particular Partition:</emphasis>
8266 Use the <filename>wic ls</filename> command again
8267 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008268 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008269 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008270 You can get command usage on any Wic command
8271 using the following form:
8272 <literallayout class='monospaced'>
8273 $ wic help <replaceable>command</replaceable>
8274 </literallayout>
8275 For example, the following command shows you
8276 the various ways to use the
8277 <filename>wic ls</filename> command:
8278 <literallayout class='monospaced'>
8279 $ wic help ls
8280 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008281 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008282 The following command shows what is in Partition
8283 one:
8284 <literallayout class='monospaced'>
8285 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8286 Volume in drive : is boot
8287 Volume Serial Number is E894-1809
8288 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008289
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008290 libcom32 c32 186500 2017-10-09 16:06
8291 libutil c32 24148 2017-10-09 16:06
8292 syslinux cfg 220 2017-10-09 16:06
8293 vesamenu c32 27104 2017-10-09 16:06
8294 vmlinuz 6904608 2017-10-09 16:06
8295 5 files 7 142 580 bytes
8296 16 582 656 bytes free
8297 </literallayout>
8298 The previous output shows five files, with the
8299 <filename>vmlinuz</filename> being the kernel.
8300 <note>
8301 If you see the following error, you need to
8302 update or create a
8303 <filename>~/.mtoolsrc</filename> file and
8304 be sure to have the line “mtools_skip_check=1“
8305 in the file.
8306 Then, run the Wic command again:
8307 <literallayout class='monospaced'>
8308 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8309 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8310 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8311 </literallayout>
8312 </note>
8313 </para></listitem>
8314 <listitem><para>
8315 <emphasis>Remove the Old Kernel:</emphasis>
8316 Use the <filename>wic rm</filename> command to
8317 remove the <filename>vmlinuz</filename> file
8318 (kernel):
8319 <literallayout class='monospaced'>
8320 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8321 </literallayout>
8322 </para></listitem>
8323 <listitem><para>
8324 <emphasis>Add In the New Kernel:</emphasis>
8325 Use the <filename>wic cp</filename> command to
8326 add the updated kernel to the Wic image.
8327 Depending on how you built your kernel, it could
8328 be in different places.
8329 If you used <filename>devtool</filename> and
8330 an SDK to build your kernel, it resides in the
8331 <filename>tmp/work</filename> directory of the
8332 extensible SDK.
8333 If you used <filename>make</filename> to build the
8334 kernel, the kernel will be in the
8335 <filename>workspace/sources</filename> area.
8336 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008337
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008338 <para>The following example assumes
8339 <filename>devtool</filename> was used to build
8340 the kernel:
8341 <literallayout class='monospaced'>
8342 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 \
8343 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8344 </literallayout>
8345 Once the new kernel is added back into the image,
8346 you can use the <filename>dd</filename>
8347 command or
8348 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8349 to flash your wic image onto an SD card
8350 or USB stick and test your target.
8351 <note>
8352 Using <filename>bmaptool</filename> is
8353 generally 10 to 20 times faster than using
8354 <filename>dd</filename>.
8355 </note>
8356 </para></listitem>
8357 </orderedlist>
8358 </para>
8359 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008360 </section>
8361 </section>
8362
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008363 <section id='flashing-images-using-bmaptool'>
8364 <title>Flashing Images Using <filename>bmaptool</filename></title>
8365
8366 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008367 A fast and easy way to flash an image to a bootable device
8368 is to use Bmaptool, which is integrated into the OpenEmbedded
8369 build system.
8370 Bmaptool is a generic tool that creates a file's block map (bmap)
8371 and then uses that map to copy the file.
8372 As compared to traditional tools such as dd or cp, Bmaptool
8373 can copy (or flash) large files like raw system image files
8374 much faster.
8375 <note><title>Notes</title>
8376 <itemizedlist>
8377 <listitem><para>
8378 If you are using Ubuntu or Debian distributions, you
8379 can install the <filename>bmap-tools</filename> package
8380 using the following command and then use the tool
8381 without specifying <filename>PATH</filename> even from
8382 the root account:
8383 <literallayout class='monospaced'>
8384 $ sudo apt-get install bmap-tools
8385 </literallayout>
8386 </para></listitem>
8387 <listitem><para>
8388 If you are unable to install the
8389 <filename>bmap-tools</filename> package, you will
8390 need to build Bmaptool before using it.
8391 Use the following command:
8392 <literallayout class='monospaced'>
8393 $ bitbake bmap-tools-native
8394 </literallayout>
8395 </para></listitem>
8396 </itemizedlist>
8397 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008398 </para>
8399
8400 <para>
8401 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008402 Realize that while this example uses a Wic image, you can use
8403 Bmaptool to flash any type of image.
8404 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008405 <orderedlist>
8406 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008407 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8408 You need to have the following set in your
8409 <filename>local.conf</filename> file before building
8410 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008411 <literallayout class='monospaced'>
8412 IMAGE_FSTYPES += "wic wic.bmap"
8413 </literallayout>
8414 </para></listitem>
8415 <listitem><para>
8416 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008417 Either have your image ready (pre-built with the
8418 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8419 setting previously mentioned) or take the step to build
8420 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008421 <literallayout class='monospaced'>
8422 $ bitbake <replaceable>image</replaceable>
8423 </literallayout>
8424 </para></listitem>
8425 <listitem><para>
8426 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008427 Flash the device with the image by using Bmaptool
8428 depending on your particular setup.
8429 The following commands assume the image resides in the
8430 Build Directory's <filename>deploy/images/</filename>
8431 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008432 <itemizedlist>
8433 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008434 If you have write access to the media, use this
8435 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008436 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008437 $ 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 -05008438 </literallayout>
8439 </para></listitem>
8440 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008441 If you do not have write access to the media, set
8442 your permissions first and then use the same
8443 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008444 <literallayout class='monospaced'>
8445 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008446 $ 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 -05008447 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008448 </para></listitem>
8449 </itemizedlist>
8450 </para></listitem>
8451 </orderedlist>
8452 </para>
8453
8454 <para>
8455 For help on the <filename>bmaptool</filename> command, use the
8456 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008457 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008458 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008459 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008460 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008461 </section>
8462
8463 <section id='making-images-more-secure'>
8464 <title>Making Images More Secure</title>
8465
8466 <para>
8467 Security is of increasing concern for embedded devices.
8468 Consider the issues and problems discussed in just this
8469 sampling of work found across the Internet:
8470 <itemizedlist>
8471 <listitem><para><emphasis>
8472 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8473 by Bruce Schneier
8474 </para></listitem>
8475 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008476 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008477 by Carna Botnet</para></listitem>
8478 <listitem><para><emphasis>
8479 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8480 by Jake Edge
8481 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008482 </itemizedlist>
8483 </para>
8484
8485 <para>
8486 When securing your image is of concern, there are steps, tools,
8487 and variables that you can consider to help you reach the
8488 security goals you need for your particular device.
8489 Not all situations are identical when it comes to making an
8490 image secure.
8491 Consequently, this section provides some guidance and suggestions
8492 for consideration when you want to make your image more secure.
8493 <note>
8494 Because the security requirements and risks are
8495 different for every type of device, this section cannot
8496 provide a complete reference on securing your custom OS.
8497 It is strongly recommended that you also consult other sources
8498 of information on embedded Linux system hardening and on
8499 security.
8500 </note>
8501 </para>
8502
8503 <section id='general-considerations'>
8504 <title>General Considerations</title>
8505
8506 <para>
8507 General considerations exist that help you create more
8508 secure images.
8509 You should consider the following suggestions to help
8510 make your device more secure:
8511 <itemizedlist>
8512 <listitem><para>
8513 Scan additional code you are adding to the system
8514 (e.g. application code) by using static analysis
8515 tools.
8516 Look for buffer overflows and other potential
8517 security problems.
8518 </para></listitem>
8519 <listitem><para>
8520 Pay particular attention to the security for
8521 any web-based administration interface.
8522 </para>
8523 <para>Web interfaces typically need to perform
8524 administrative functions and tend to need to run with
8525 elevated privileges.
8526 Thus, the consequences resulting from the interface's
8527 security becoming compromised can be serious.
8528 Look for common web vulnerabilities such as
8529 cross-site-scripting (XSS), unvalidated inputs,
8530 and so forth.</para>
8531 <para>As with system passwords, the default credentials
8532 for accessing a web-based interface should not be the
8533 same across all devices.
8534 This is particularly true if the interface is enabled
8535 by default as it can be assumed that many end-users
8536 will not change the credentials.
8537 </para></listitem>
8538 <listitem><para>
8539 Ensure you can update the software on the device to
8540 mitigate vulnerabilities discovered in the future.
8541 This consideration especially applies when your
8542 device is network-enabled.
8543 </para></listitem>
8544 <listitem><para>
8545 Ensure you remove or disable debugging functionality
8546 before producing the final image.
8547 For information on how to do this, see the
8548 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8549 section.
8550 </para></listitem>
8551 <listitem><para>
8552 Ensure you have no network services listening that
8553 are not needed.
8554 </para></listitem>
8555 <listitem><para>
8556 Remove any software from the image that is not needed.
8557 </para></listitem>
8558 <listitem><para>
8559 Enable hardware support for secure boot functionality
8560 when your device supports this functionality.
8561 </para></listitem>
8562 </itemizedlist>
8563 </para>
8564 </section>
8565
8566 <section id='security-flags'>
8567 <title>Security Flags</title>
8568
8569 <para>
8570 The Yocto Project has security flags that you can enable that
8571 help make your build output more secure.
8572 The security flags are in the
8573 <filename>meta/conf/distro/include/security_flags.inc</filename>
8574 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008575 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008576 (e.g. <filename>poky</filename>).
8577 <note>
8578 Depending on the recipe, certain security flags are enabled
8579 and disabled by default.
8580 </note>
8581 </para>
8582
8583 <para>
8584<!--
8585 The GCC/LD flags in <filename>security_flags.inc</filename>
8586 enable more secure code generation.
8587 By including the <filename>security_flags.inc</filename>
8588 file, you enable flags to the compiler and linker that cause
8589 them to generate more secure code.
8590 <note>
8591 The GCC/LD flags are enabled by default in the
8592 <filename>poky-lsb</filename> distribution.
8593 </note>
8594-->
8595 Use the following line in your
8596 <filename>local.conf</filename> file or in your custom
8597 distribution configuration file to enable the security
8598 compiler and linker flags for your build:
8599 <literallayout class='monospaced'>
8600 require conf/distro/include/security_flags.inc
8601 </literallayout>
8602 </para>
8603 </section>
8604
8605 <section id='considerations-specific-to-the-openembedded-build-system'>
8606 <title>Considerations Specific to the OpenEmbedded Build System</title>
8607
8608 <para>
8609 You can take some steps that are specific to the
8610 OpenEmbedded build system to make your images more secure:
8611 <itemizedlist>
8612 <listitem><para>
8613 Ensure "debug-tweaks" is not one of your selected
8614 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8615 When creating a new project, the default is to provide you
8616 with an initial <filename>local.conf</filename> file that
8617 enables this feature using the
8618 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8619 <literallayout class='monospaced'>
8620 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8621 </literallayout>
8622 To disable that feature, simply comment out that line in your
8623 <filename>local.conf</filename> file, or
8624 make sure <filename>IMAGE_FEATURES</filename> does not contain
8625 "debug-tweaks" before producing your final image.
8626 Among other things, leaving this in place sets the
8627 root password as blank, which makes logging in for
8628 debugging or inspection easy during
8629 development but also means anyone can easily log in
8630 during production.
8631 </para></listitem>
8632 <listitem><para>
8633 It is possible to set a root password for the image
8634 and also to set passwords for any extra users you might
8635 add (e.g. administrative or service type users).
8636 When you set up passwords for multiple images or
8637 users, you should not duplicate passwords.
8638 </para>
8639 <para>
8640 To set up passwords, use the
8641 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8642 class, which is the preferred method.
8643 For an example on how to set up both root and user
8644 passwords, see the
8645 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8646 section.
8647 <note>
8648 When adding extra user accounts or setting a
8649 root password, be cautious about setting the
8650 same password on every device.
8651 If you do this, and the password you have set
8652 is exposed, then every device is now potentially
8653 compromised.
8654 If you need this access but want to ensure
8655 security, consider setting a different,
8656 random password for each device.
8657 Typically, you do this as a separate step after
8658 you deploy the image onto the device.
8659 </note>
8660 </para></listitem>
8661 <listitem><para>
8662 Consider enabling a Mandatory Access Control (MAC)
8663 framework such as SMACK or SELinux and tuning it
8664 appropriately for your device's usage.
8665 You can find more information in the
8666 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8667 layer.
8668 </para></listitem>
8669 </itemizedlist>
8670 </para>
8671
8672 <para>
8673 </para>
8674 </section>
8675
8676 <section id='tools-for-hardening-your-image'>
8677 <title>Tools for Hardening Your Image</title>
8678
8679 <para>
8680 The Yocto Project provides tools for making your image
8681 more secure.
8682 You can find these tools in the
8683 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008684 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008685 </para>
8686 </section>
8687 </section>
8688
8689 <section id='creating-your-own-distribution'>
8690 <title>Creating Your Own Distribution</title>
8691
8692 <para>
8693 When you build an image using the Yocto Project and
8694 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008695 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8696 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008697 If you wish to gain more control over package alternative
8698 selections, compile-time options, and other low-level
8699 configurations, you can create your own distribution.
8700 </para>
8701
8702 <para>
8703 To create your own distribution, the basic steps consist of
8704 creating your own distribution layer, creating your own
8705 distribution configuration file, and then adding any needed
8706 code and Metadata to the layer.
8707 The following steps provide some more detail:
8708 <itemizedlist>
8709 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8710 Create your distribution layer so that you can keep your
8711 Metadata and code for the distribution separate.
8712 It is strongly recommended that you create and use your own
8713 layer for configuration and code.
8714 Using your own layer as compared to just placing
8715 configurations in a <filename>local.conf</filename>
8716 configuration file makes it easier to reproduce the same
8717 build configuration when using multiple build machines.
8718 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008719 "<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 -05008720 section for information on how to quickly set up a layer.
8721 </para></listitem>
8722 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8723 The distribution configuration file needs to be created in
8724 the <filename>conf/distro</filename> directory of your
8725 layer.
8726 You need to name it using your distribution name
8727 (e.g. <filename>mydistro.conf</filename>).
8728 <note>
8729 The
8730 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8731 variable in your
8732 <filename>local.conf</filename> file determines the
8733 name of your distribution.
8734 </note></para>
8735 <para>You can split out parts of your configuration file
8736 into include files and then "require" them from within
8737 your distribution configuration file.
8738 Be sure to place the include files in the
8739 <filename>conf/distro/include</filename> directory of
8740 your layer.
8741 A common example usage of include files would be to
8742 separate out the selection of desired version and revisions
8743 for individual recipes.
8744</para>
8745 <para>Your configuration file needs to set the following
8746 required variables:
8747 <literallayout class='monospaced'>
8748 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8749 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8750 </literallayout>
8751 These following variables are optional and you typically
8752 set them from the distribution configuration file:
8753 <literallayout class='monospaced'>
8754 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8755 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8756 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8757 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8758 </literallayout>
8759 <tip>
8760 If you want to base your distribution configuration file
8761 on the very basic configuration from OE-Core, you
8762 can use
8763 <filename>conf/distro/defaultsetup.conf</filename> as
8764 a reference and just include variables that differ
8765 as compared to <filename>defaultsetup.conf</filename>.
8766 Alternatively, you can create a distribution
8767 configuration file from scratch using the
8768 <filename>defaultsetup.conf</filename> file
8769 or configuration files from other distributions
8770 such as Poky or Angstrom as references.
8771 </tip></para></listitem>
8772 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8773 Be sure to define any other variables for which you want to
8774 create a default or enforce as part of the distribution
8775 configuration.
8776 You can include nearly any variable from the
8777 <filename>local.conf</filename> file.
8778 The variables you use are not limited to the list in the
8779 previous bulleted item.</para></listitem>
8780 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8781 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008782 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008783 set your
8784 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8785 variable to point to your distribution's configuration file.
8786 For example, if your distribution's configuration file is
8787 named <filename>mydistro.conf</filename>, then you point
8788 to it as follows:
8789 <literallayout class='monospaced'>
8790 DISTRO = "mydistro"
8791 </literallayout></para></listitem>
8792 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8793 Use your layer to hold other information needed for the
8794 distribution:
8795 <itemizedlist>
8796 <listitem><para>Add recipes for installing
8797 distro-specific configuration files that are not
8798 already installed by another recipe.
8799 If you have distro-specific configuration files
8800 that are included by an existing recipe, you should
8801 add an append file (<filename>.bbappend</filename>)
8802 for those.
8803 For general information and recommendations
8804 on how to add recipes to your layer, see the
8805 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8806 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008807 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008808 sections.</para></listitem>
8809 <listitem><para>Add any image recipes that are specific
8810 to your distribution.</para></listitem>
8811 <listitem><para>Add a <filename>psplash</filename>
8812 append file for a branded splash screen.
8813 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008814 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008815 section.</para></listitem>
8816 <listitem><para>Add any other append files to make
8817 custom changes that are specific to individual
8818 recipes.</para></listitem>
8819 </itemizedlist></para></listitem>
8820 </itemizedlist>
8821 </para>
8822 </section>
8823
8824 <section id='creating-a-custom-template-configuration-directory'>
8825 <title>Creating a Custom Template Configuration Directory</title>
8826
8827 <para>
8828 If you are producing your own customized version
8829 of the build system for use by other users, you might
8830 want to customize the message shown by the setup script or
8831 you might want to change the template configuration files (i.e.
8832 <filename>local.conf</filename> and
8833 <filename>bblayers.conf</filename>) that are created in
8834 a new build directory.
8835 </para>
8836
8837 <para>
8838 The OpenEmbedded build system uses the environment variable
8839 <filename>TEMPLATECONF</filename> to locate the directory
8840 from which it gathers configuration information that ultimately
8841 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008842 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008843 <filename>conf</filename> directory.
8844 By default, <filename>TEMPLATECONF</filename> is set as
8845 follows in the <filename>poky</filename> repository:
8846 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008847 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008848 </literallayout>
8849 This is the directory used by the build system to find templates
8850 from which to build some key configuration files.
8851 If you look at this directory, you will see the
8852 <filename>bblayers.conf.sample</filename>,
8853 <filename>local.conf.sample</filename>, and
8854 <filename>conf-notes.txt</filename> files.
8855 The build system uses these files to form the respective
8856 <filename>bblayers.conf</filename> file,
8857 <filename>local.conf</filename> file, and display the list of
8858 BitBake targets when running the setup script.
8859 </para>
8860
8861 <para>
8862 To override these default configuration files with
8863 configurations you want used within every new
8864 Build Directory, simply set the
8865 <filename>TEMPLATECONF</filename> variable to your directory.
8866 The <filename>TEMPLATECONF</filename> variable is set in the
8867 <filename>.templateconf</filename> file, which is in the
8868 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008869 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008870 folder (e.g. <filename>poky</filename>).
8871 Edit the <filename>.templateconf</filename> so that it can locate
8872 your directory.
8873 </para>
8874
8875 <para>
8876 Best practices dictate that you should keep your
8877 template configuration directory in your custom distribution layer.
8878 For example, suppose you have a layer named
8879 <filename>meta-mylayer</filename> located in your home directory
8880 and you want your template configuration directory named
8881 <filename>myconf</filename>.
8882 Changing the <filename>.templateconf</filename> as follows
8883 causes the OpenEmbedded build system to look in your directory
8884 and base its configuration files on the
8885 <filename>*.sample</filename> configuration files it finds.
8886 The final configuration files (i.e.
8887 <filename>local.conf</filename> and
8888 <filename>bblayers.conf</filename> ultimately still end up in
8889 your Build Directory, but they are based on your
8890 <filename>*.sample</filename> files.
8891 <literallayout class='monospaced'>
8892 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8893 </literallayout>
8894 </para>
8895
8896 <para>
8897 Aside from the <filename>*.sample</filename> configuration files,
8898 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008899 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008900 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008901 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008902 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8903 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008904 output.
8905 Customizing this <filename>conf-notes.txt</filename> file is a
8906 good way to make sure your list of custom targets appears
8907 as part of the script's output.
8908 </para>
8909
8910 <para>
8911 Here is the default list of targets displayed as a result of
8912 running either of the setup scripts:
8913 <literallayout class='monospaced'>
8914 You can now run 'bitbake &lt;target&gt;'
8915
8916 Common targets are:
8917 core-image-minimal
8918 core-image-sato
8919 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008920 meta-ide-support
8921 </literallayout>
8922 </para>
8923
8924 <para>
8925 Changing the listed common targets is as easy as editing your
8926 version of <filename>conf-notes.txt</filename> in your
8927 custom template configuration directory and making sure you
8928 have <filename>TEMPLATECONF</filename> set to your directory.
8929 </para>
8930 </section>
8931
Brad Bishop316dfdd2018-06-25 12:45:53 -04008932 <section id='dev-saving-memory-during-a-build'>
8933 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008934
8935 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008936 To help conserve disk space during builds, you can add the
8937 following statement to your project's
8938 <filename>local.conf</filename> configuration file found in the
8939 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8940 <literallayout class='monospaced'>
8941 INHERIT += "rm_work"
8942 </literallayout>
8943 Adding this statement deletes the work directory used for building
8944 a recipe once the recipe is built.
8945 For more information on "rm_work", see the
8946 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8947 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008948 </para>
8949 </section>
8950
8951 <section id='working-with-packages'>
8952 <title>Working with Packages</title>
8953
8954 <para>
8955 This section describes a few tasks that involve packages:
8956 <itemizedlist>
8957 <listitem><para>
8958 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8959 </para></listitem>
8960 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008961 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008962 </para></listitem>
8963 <listitem><para>
8964 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8965 </para></listitem>
8966 <listitem><para>
8967 <link linkend='using-runtime-package-management'>Using Runtime Package Management</link>
8968 </para></listitem>
8969 <listitem><para>
8970 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8971 </para></listitem>
8972 </itemizedlist>
8973 </para>
8974
8975 <section id='excluding-packages-from-an-image'>
8976 <title>Excluding Packages from an Image</title>
8977
8978 <para>
8979 You might find it necessary to prevent specific packages
8980 from being installed into an image.
8981 If so, you can use several variables to direct the build
8982 system to essentially ignore installing recommended packages
8983 or to not install a package at all.
8984 </para>
8985
8986 <para>
8987 The following list introduces variables you can use to
8988 prevent packages from being installed into your image.
8989 Each of these variables only works with IPK and RPM
8990 package types.
8991 Support for Debian packages does not exist.
8992 Also, you can use these variables from your
8993 <filename>local.conf</filename> file or attach them to a
8994 specific image recipe by using a recipe name override.
8995 For more detail on the variables, see the descriptions in the
8996 Yocto Project Reference Manual's glossary chapter.
8997 <itemizedlist>
8998 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
8999 Use this variable to specify "recommended-only"
9000 packages that you do not want installed.
9001 </para></listitem>
9002 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
9003 Use this variable to prevent all "recommended-only"
9004 packages from being installed.
9005 </para></listitem>
9006 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
9007 Use this variable to prevent specific packages from
9008 being installed regardless of whether they are
9009 "recommended-only" or not.
9010 You need to realize that the build process could
9011 fail with an error when you
9012 prevent the installation of a package whose presence
9013 is required by an installed package.
9014 </para></listitem>
9015 </itemizedlist>
9016 </para>
9017 </section>
9018
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009019 <section id='incrementing-a-binary-package-version'>
9020 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009021
9022 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009023 This section provides some background on how binary package
9024 versioning is accomplished and presents some of the services,
9025 variables, and terminology involved.
9026 </para>
9027
9028 <para>
9029 In order to understand binary package versioning, you need
9030 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009031 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009032 <listitem><para>
9033 Binary Package: The binary package that is eventually
9034 built and installed into an image.
9035 </para></listitem>
9036 <listitem><para>
9037 Binary Package Version: The binary package version
9038 is composed of two components - a version and a
9039 revision.
9040 <note>
9041 Technically, a third component, the "epoch" (i.e.
9042 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
9043 is involved but this discussion for the most part
9044 ignores <filename>PE</filename>.
9045 </note>
9046 The version and revision are taken from the
9047 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
9048 and
9049 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9050 variables, respectively.
9051 </para></listitem>
9052 <listitem><para>
9053 <filename>PV</filename>: The recipe version.
9054 <filename>PV</filename> represents the version of the
9055 software being packaged.
9056 Do not confuse <filename>PV</filename> with the
9057 binary package version.
9058 </para></listitem>
9059 <listitem><para>
9060 <filename>PR</filename>: The recipe revision.
9061 </para></listitem>
9062 <listitem><para>
9063 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
9064 The OpenEmbedded build system uses this string
9065 to help define the value of <filename>PV</filename>
9066 when the source code revision needs to be included
9067 in it.
9068 </para></listitem>
9069 <listitem><para>
9070 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
9071 A network-based service that helps automate keeping
9072 package feeds compatible with existing package
9073 manager applications such as RPM, APT, and OPKG.
9074 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009075 </itemizedlist>
9076 </para>
9077
9078 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009079 Whenever the binary package content changes, the binary package
9080 version must change.
9081 Changing the binary package version is accomplished by changing
9082 or "bumping" the <filename>PR</filename> and/or
9083 <filename>PV</filename> values.
9084 Increasing these values occurs one of two ways:
9085 <itemizedlist>
9086 <listitem><para>Automatically using a Package Revision
9087 Service (PR Service).
9088 </para></listitem>
9089 <listitem><para>Manually incrementing the
9090 <filename>PR</filename> and/or
9091 <filename>PV</filename> variables.
9092 </para></listitem>
9093 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009094 </para>
9095
9096 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009097 Given a primary challenge of any build system and its users
9098 is how to maintain a package feed that is compatible with
9099 existing package manager applications such as RPM, APT, and
9100 OPKG, using an automated system is much preferred over a
9101 manual system.
9102 In either system, the main requirement is that binary package
9103 version numbering increases in a linear fashion and that a
9104 number of version components exist that support that linear
9105 progression.
9106 For information on how to ensure package revisioning remains
9107 linear, see the
9108 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
9109 section.
9110 </para>
9111
9112 <para>
9113 The following three sections provide related information on the
9114 PR Service, the manual method for "bumping"
9115 <filename>PR</filename> and/or <filename>PV</filename>, and
9116 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009117 </para>
9118
9119 <section id='working-with-a-pr-service'>
9120 <title>Working With a PR Service</title>
9121
9122 <para>
9123 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009124 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009125 is error prone, inaccurate, and causes problems for people
9126 submitting recipes.
9127 Conversely, the PR Service automatically generates
9128 increasing numbers, particularly the revision field,
9129 which removes the human element.
9130 <note>
9131 For additional information on using a PR Service, you
9132 can see the
9133 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
9134 wiki page.
9135 </note>
9136 </para>
9137
9138 <para>
9139 The Yocto Project uses variables in order of
9140 decreasing priority to facilitate revision numbering (i.e.
9141 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
9142 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
9143 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9144 for epoch, version, and revision, respectively).
9145 The values are highly dependent on the policies and
9146 procedures of a given distribution and package feed.
9147 </para>
9148
9149 <para>
9150 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04009151 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009152 which are unique to a given build, the build system
9153 knows when to rebuild packages.
9154 All the inputs into a given task are represented by a
9155 signature, which can trigger a rebuild when different.
9156 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009157 <filename>PR</filename>, <filename>PV</filename>, and
9158 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009159 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009160 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009161 </para>
9162
9163 <para>
9164 The PR Service works with both
9165 <filename>OEBasic</filename> and
9166 <filename>OEBasicHash</filename> generators.
9167 The value of <filename>PR</filename> bumps when the
9168 checksum changes and the different generator mechanisms
9169 change signatures under different circumstances.
9170 </para>
9171
9172 <para>
9173 As implemented, the build system includes values from
9174 the PR Service into the <filename>PR</filename> field as
9175 an addition using the form "<filename>.x</filename>" so
9176 <filename>r0</filename> becomes <filename>r0.1</filename>,
9177 <filename>r0.2</filename> and so forth.
9178 This scheme allows existing <filename>PR</filename> values
9179 to be used for whatever reasons, which include manual
9180 <filename>PR</filename> bumps, should it be necessary.
9181 </para>
9182
9183 <para>
9184 By default, the PR Service is not enabled or running.
9185 Thus, the packages generated are just "self consistent".
9186 The build system adds and removes packages and
9187 there are no guarantees about upgrade paths but images
9188 will be consistent and correct with the latest changes.
9189 </para>
9190
9191 <para>
9192 The simplest form for a PR Service is for it to exist
9193 for a single host development system that builds the
9194 package feed (building system).
9195 For this scenario, you can enable a local PR Service by
9196 setting
9197 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9198 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009199 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009200 <literallayout class='monospaced'>
9201 PRSERV_HOST = "localhost:0"
9202 </literallayout>
9203 Once the service is started, packages will automatically
9204 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009205 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009206 </para>
9207
9208 <para>
9209 If you have a more complex setup where multiple host
9210 development systems work against a common, shared package
9211 feed, you have a single PR Service running and it is
9212 connected to each building system.
9213 For this scenario, you need to start the PR Service using
9214 the <filename>bitbake-prserv</filename> command:
9215 <literallayout class='monospaced'>
9216 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9217 </literallayout>
9218 In addition to hand-starting the service, you need to
9219 update the <filename>local.conf</filename> file of each
9220 building system as described earlier so each system
9221 points to the server and port.
9222 </para>
9223
9224 <para>
9225 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009226 some sanity checks to binary package versions, in
9227 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009228 To enable build history, add the following to each building
9229 system's <filename>local.conf</filename> file:
9230 <literallayout class='monospaced'>
9231 # It is recommended to activate "buildhistory" for testing the PR service
9232 INHERIT += "buildhistory"
9233 BUILDHISTORY_COMMIT = "1"
9234 </literallayout>
9235 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009236 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9237 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009238 </para>
9239
9240 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009241 <para>
9242 The OpenEmbedded build system does not maintain
9243 <filename>PR</filename> information as part of the
9244 shared state (sstate) packages.
9245 If you maintain an sstate feed, its expected that either
9246 all your building systems that contribute to the sstate
9247 feed use a shared PR Service, or you do not run a PR
9248 Service on any of your building systems.
9249 Having some systems use a PR Service while others do
9250 not leads to obvious problems.
9251 </para>
9252
9253 <para>
9254 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009255 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9256 section in the Yocto Project Overview and Concepts
9257 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009258 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009259 </note>
9260 </section>
9261
9262 <section id='manually-bumping-pr'>
9263 <title>Manually Bumping PR</title>
9264
9265 <para>
9266 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009267 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009268 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9269 variable.
9270 </para>
9271
9272 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009273 If a committed change results in changing the package
9274 output, then the value of the PR variable needs to be
9275 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009276 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009277 variable and set its initial value equal to "r0", which is
9278 the default.
9279 Even though the default value is "r0", the practice of
9280 adding it to a new recipe makes it harder to forget to bump
9281 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009282 </para>
9283
9284 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009285 If you are sharing a common <filename>.inc</filename> file
9286 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009287 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009288 variable to ensure that the recipes sharing the
9289 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009290 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009291 The <filename>.inc</filename> file must set
9292 <filename>INC_PR</filename> (initially to "r0"), and all
9293 recipes referring to it should set <filename>PR</filename>
9294 to "${INC_PR}.0" initially, incrementing the last number
9295 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009296 If the <filename>.inc</filename> file is changed then its
9297 <filename>INC_PR</filename> should be incremented.
9298 </para>
9299
9300 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009301 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009302 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9303 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009304 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009305 <filename>INC_PR</filename>).
9306 </para>
9307
9308 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009309 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009310 However, if for some reason <filename>PV</filename> changes
9311 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009312 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9313 variable (Package Epoch).
9314 The <filename>PE</filename> variable defaults to "0".
9315 </para>
9316
9317 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009318 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009319 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9320 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009321 These guidelines define how versions are compared and what
9322 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009323 </para>
9324 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009325
9326 <section id='automatically-incrementing-a-binary-package-revision-number'>
9327 <title>Automatically Incrementing a Package Version Number</title>
9328
9329 <para>
9330 When fetching a repository, BitBake uses the
9331 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9332 variable to determine the specific source code revision
9333 from which to build.
9334 You set the <filename>SRCREV</filename> variable to
9335 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9336 to cause the OpenEmbedded build system to automatically use the
9337 latest revision of the software:
9338 <literallayout class='monospaced'>
9339 SRCREV = "${AUTOREV}"
9340 </literallayout>
9341 </para>
9342
9343 <para>
9344 Furthermore, you need to reference <filename>SRCPV</filename>
9345 in <filename>PV</filename> in order to automatically update
9346 the version whenever the revision of the source code
9347 changes.
9348 Here is an example:
9349 <literallayout class='monospaced'>
9350 PV = "1.0+git${SRCPV}"
9351 </literallayout>
9352 The OpenEmbedded build system substitutes
9353 <filename>SRCPV</filename> with the following:
9354 <literallayout class='monospaced'>
9355 AUTOINC+<replaceable>source_code_revision</replaceable>
9356 </literallayout>
9357 The build system replaces the <filename>AUTOINC</filename> with
9358 a number.
9359 The number used depends on the state of the PR Service:
9360 <itemizedlist>
9361 <listitem><para>
9362 If PR Service is enabled, the build system increments
9363 the number, which is similar to the behavior of
9364 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9365 This behavior results in linearly increasing package
9366 versions, which is desirable.
9367 Here is an example:
9368 <literallayout class='monospaced'>
9369 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9370 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9371 </literallayout>
9372 </para></listitem>
9373 <listitem><para>
9374 If PR Service is not enabled, the build system
9375 replaces the <filename>AUTOINC</filename>
9376 placeholder with zero (i.e. "0").
9377 This results in changing the package version since
9378 the source revision is included.
9379 However, package versions are not increased linearly.
9380 Here is an example:
9381 <literallayout class='monospaced'>
9382 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9383 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9384 </literallayout>
9385 </para></listitem>
9386 </itemizedlist>
9387 </para>
9388
9389 <para>
9390 In summary, the OpenEmbedded build system does not track the
9391 history of binary package versions for this purpose.
9392 <filename>AUTOINC</filename>, in this case, is comparable to
9393 <filename>PR</filename>.
9394 If PR server is not enabled, <filename>AUTOINC</filename>
9395 in the package version is simply replaced by "0".
9396 If PR server is enabled, the build system keeps track of the
9397 package versions and bumps the number when the package
9398 revision changes.
9399 </para>
9400 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009401 </section>
9402
9403 <section id='handling-optional-module-packaging'>
9404 <title>Handling Optional Module Packaging</title>
9405
9406 <para>
9407 Many pieces of software split functionality into optional
Brad Bishopc342db32019-05-15 21:57:59 -04009408 modules (or plugins) and the plugins that are built
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009409 might depend on configuration options.
9410 To avoid having to duplicate the logic that determines what
9411 modules are available in your recipe or to avoid having
9412 to package each module by hand, the OpenEmbedded build system
9413 provides functionality to handle module packaging dynamically.
9414 </para>
9415
9416 <para>
9417 To handle optional module packaging, you need to do two things:
9418 <itemizedlist>
9419 <listitem><para>Ensure the module packaging is actually
9420 done.</para></listitem>
9421 <listitem><para>Ensure that any dependencies on optional
9422 modules from other recipes are satisfied by your recipe.
9423 </para></listitem>
9424 </itemizedlist>
9425 </para>
9426
9427 <section id='making-sure-the-packaging-is-done'>
9428 <title>Making Sure the Packaging is Done</title>
9429
9430 <para>
9431 To ensure the module packaging actually gets done, you use
9432 the <filename>do_split_packages</filename> function within
9433 the <filename>populate_packages</filename> Python function
9434 in your recipe.
9435 The <filename>do_split_packages</filename> function
9436 searches for a pattern of files or directories under a
9437 specified path and creates a package for each one it finds
9438 by appending to the
9439 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9440 variable and setting the appropriate values for
9441 <filename>FILES_packagename</filename>,
9442 <filename>RDEPENDS_packagename</filename>,
9443 <filename>DESCRIPTION_packagename</filename>, and so forth.
9444 Here is an example from the <filename>lighttpd</filename>
9445 recipe:
9446 <literallayout class='monospaced'>
9447 python populate_packages_prepend () {
9448 lighttpd_libdir = d.expand('${libdir}')
9449 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9450 'lighttpd-module-%s', 'Lighttpd module for %s',
9451 extra_depends='')
9452 }
9453 </literallayout>
9454 The previous example specifies a number of things in the
9455 call to <filename>do_split_packages</filename>.
9456 <itemizedlist>
9457 <listitem><para>A directory within the files installed
9458 by your recipe through <filename>do_install</filename>
9459 in which to search.</para></listitem>
9460 <listitem><para>A regular expression used to match module
9461 files in that directory.
9462 In the example, note the parentheses () that mark
9463 the part of the expression from which the module
9464 name should be derived.</para></listitem>
9465 <listitem><para>A pattern to use for the package names.
9466 </para></listitem>
9467 <listitem><para>A description for each package.
9468 </para></listitem>
9469 <listitem><para>An empty string for
9470 <filename>extra_depends</filename>, which disables
9471 the default dependency on the main
9472 <filename>lighttpd</filename> package.
9473 Thus, if a file in <filename>${libdir}</filename>
9474 called <filename>mod_alias.so</filename> is found,
9475 a package called <filename>lighttpd-module-alias</filename>
9476 is created for it and the
9477 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9478 is set to "Lighttpd module for alias".</para></listitem>
9479 </itemizedlist>
9480 </para>
9481
9482 <para>
9483 Often, packaging modules is as simple as the previous
9484 example.
9485 However, more advanced options exist that you can use
9486 within <filename>do_split_packages</filename> to modify its
9487 behavior.
9488 And, if you need to, you can add more logic by specifying
9489 a hook function that is called for each package.
9490 It is also perfectly acceptable to call
9491 <filename>do_split_packages</filename> multiple times if
9492 you have more than one set of modules to package.
9493 </para>
9494
9495 <para>
9496 For more examples that show how to use
9497 <filename>do_split_packages</filename>, see the
9498 <filename>connman.inc</filename> file in the
9499 <filename>meta/recipes-connectivity/connman/</filename>
9500 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009501 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009502 You can also find examples in
9503 <filename>meta/classes/kernel.bbclass</filename>.
9504 </para>
9505
9506 <para>
9507 Following is a reference that shows
9508 <filename>do_split_packages</filename> mandatory and
9509 optional arguments:
9510 <literallayout class='monospaced'>
9511 Mandatory arguments
9512
9513 root
9514 The path in which to search
9515 file_regex
9516 Regular expression to match searched files.
9517 Use parentheses () to mark the part of this
9518 expression that should be used to derive the
9519 module name (to be substituted where %s is
9520 used in other function arguments as noted below)
9521 output_pattern
9522 Pattern to use for the package names. Must
9523 include %s.
9524 description
9525 Description to set for each package. Must
9526 include %s.
9527
9528 Optional arguments
9529
9530 postinst
9531 Postinstall script to use for all packages
9532 (as a string)
9533 recursive
9534 True to perform a recursive search - default
9535 False
9536 hook
9537 A hook function to be called for every match.
9538 The function will be called with the following
9539 arguments (in the order listed):
9540
9541 f
9542 Full path to the file/directory match
9543 pkg
9544 The package name
9545 file_regex
9546 As above
9547 output_pattern
9548 As above
9549 modulename
9550 The module name derived using file_regex
9551
9552 extra_depends
9553 Extra runtime dependencies (RDEPENDS) to be
9554 set for all packages. The default value of None
9555 causes a dependency on the main package
9556 (${PN}) - if you do not want this, pass empty
9557 string '' for this parameter.
9558 aux_files_pattern
9559 Extra item(s) to be added to FILES for each
9560 package. Can be a single string item or a list
9561 of strings for multiple items. Must include %s.
9562 postrm
9563 postrm script to use for all packages (as a
9564 string)
9565 allow_dirs
9566 True to allow directories to be matched -
9567 default False
9568 prepend
9569 If True, prepend created packages to PACKAGES
9570 instead of the default False which appends them
9571 match_path
9572 match file_regex on the whole relative path to
9573 the root rather than just the file name
9574 aux_files_pattern_verbatim
9575 Extra item(s) to be added to FILES for each
9576 package, using the actual derived module name
9577 rather than converting it to something legal
9578 for a package name. Can be a single string item
9579 or a list of strings for multiple items. Must
9580 include %s.
9581 allow_links
9582 True to allow symlinks to be matched - default
9583 False
9584 summary
9585 Summary to set for each package. Must include %s;
9586 defaults to description if not set.
9587 </literallayout>
9588 </para>
9589 </section>
9590
9591 <section id='satisfying-dependencies'>
9592 <title>Satisfying Dependencies</title>
9593
9594 <para>
9595 The second part for handling optional module packaging
9596 is to ensure that any dependencies on optional modules
9597 from other recipes are satisfied by your recipe.
9598 You can be sure these dependencies are satisfied by
9599 using the
9600 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9601 Here is an example that continues with the
9602 <filename>lighttpd</filename> recipe shown earlier:
9603 <literallayout class='monospaced'>
9604 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9605 </literallayout>
9606 The name specified in the regular expression can of
9607 course be anything.
9608 In this example, it is <filename>lighttpd-module-</filename>
9609 and is specified as the prefix to ensure that any
9610 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9611 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9612 on a package name starting with the prefix are satisfied
9613 during build time.
9614 If you are using <filename>do_split_packages</filename>
9615 as described in the previous section, the value you put in
9616 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9617 the name pattern specified in the call to
9618 <filename>do_split_packages</filename>.
9619 </para>
9620 </section>
9621 </section>
9622
9623 <section id='using-runtime-package-management'>
9624 <title>Using Runtime Package Management</title>
9625
9626 <para>
9627 During a build, BitBake always transforms a recipe into one or
9628 more packages.
9629 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009630 and produces a number of packages (e.g.
9631 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9632 <filename>bash-completion</filename>,
9633 <filename>bash-completion-dbg</filename>,
9634 <filename>bash-completion-dev</filename>,
9635 <filename>bash-completion-extra</filename>,
9636 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009637 Not all generated packages are included in an image.
9638 </para>
9639
9640 <para>
9641 In several situations, you might need to update, add, remove,
9642 or query the packages on a target device at runtime
9643 (i.e. without having to generate a new image).
9644 Examples of such situations include:
9645 <itemizedlist>
9646 <listitem><para>
9647 You want to provide in-the-field updates to deployed
9648 devices (e.g. security updates).
9649 </para></listitem>
9650 <listitem><para>
9651 You want to have a fast turn-around development cycle
9652 for one or more applications that run on your device.
9653 </para></listitem>
9654 <listitem><para>
9655 You want to temporarily install the "debug" packages
9656 of various applications on your device so that
9657 debugging can be greatly improved by allowing
9658 access to symbols and source debugging.
9659 </para></listitem>
9660 <listitem><para>
9661 You want to deploy a more minimal package selection of
9662 your device but allow in-the-field updates to add a
9663 larger selection for customization.
9664 </para></listitem>
9665 </itemizedlist>
9666 </para>
9667
9668 <para>
9669 In all these situations, you have something similar to a more
9670 traditional Linux distribution in that in-field devices
9671 are able to receive pre-compiled packages from a server for
9672 installation or update.
9673 Being able to install these packages on a running,
9674 in-field device is what is termed "runtime package
9675 management".
9676 </para>
9677
9678 <para>
9679 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009680 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009681 packages plus the required metadata.
9682 You also need package manipulation tools on the target.
9683 The build machine is a likely candidate to act as the server.
9684 However, that machine does not necessarily have to be the
9685 package server.
9686 The build machine could push its artifacts to another machine
9687 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009688 In fact, doing so is advantageous for a production
9689 environment as getting the packages away from the
9690 development system's build directory prevents accidental
9691 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009692 </para>
9693
9694 <para>
9695 A simple build that targets just one device produces
9696 more than one package database.
9697 In other words, the packages produced by a build are separated
9698 out into a couple of different package groupings based on
9699 criteria such as the target's CPU architecture, the target
9700 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009701 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009702 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009703 <filename>noarch</filename>, <filename>i586</filename>, and
9704 <filename>qemux86</filename>.
9705 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009706 aware of all the packages that were available to it,
9707 you would need to point it to each of these databases
9708 individually.
9709 In a similar way, a traditional Linux distribution usually is
9710 configured to be aware of a number of software repositories
9711 from which it retrieves packages.
9712 </para>
9713
9714 <para>
9715 Using runtime package management is completely optional and
9716 not required for a successful build or deployment in any
9717 way.
9718 But if you want to make use of runtime package management,
9719 you need to do a couple things above and beyond the basics.
9720 The remainder of this section describes what you need to do.
9721 </para>
9722
9723 <section id='runtime-package-management-build'>
9724 <title>Build Considerations</title>
9725
9726 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009727 This section describes build considerations of which you
9728 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009729 package management.
9730 </para>
9731
9732 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009733 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009734 what format or formats to use.
9735 In your configuration, you use the
9736 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009737 variable to specify the format:
9738 <orderedlist>
9739 <listitem><para>
9740 Open the <filename>local.conf</filename> file
9741 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009742 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009743 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9744 </para></listitem>
9745 <listitem><para>
9746 Select the desired package format as follows:
9747 <literallayout class='monospaced'>
9748 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9749 </literallayout>
9750 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009751 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009752 supported package formats.
9753 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009754 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009755 different package formats, you can set the
9756 variable with more than one argument.
9757 However, the OpenEmbedded build system only
9758 uses the first argument when creating an image
9759 or Software Development Kit (SDK).
9760 </note>
9761 </para></listitem>
9762 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009763 </para>
9764
9765 <para>
9766 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009767 package database containing the packages in your current
9768 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009769 target for runtime package management, you can include
9770 "package-management" in the
9771 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9772 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009773 Including "package-management" in this configuration
9774 variable ensures that when the image is assembled for your
9775 target, the image includes the currently-known package
9776 databases as well as the target-specific tools required
9777 for runtime package management to be performed on the
9778 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009779 However, this is not strictly necessary.
9780 You could start your image off without any databases
9781 but only include the required on-target package
9782 tool(s).
9783 As an example, you could include "opkg" in your
9784 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9785 variable if you are using the IPK package format.
9786 You can then initialize your target's package database(s)
9787 later once your image is up and running.
9788 </para>
9789
9790 <para>
9791 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009792 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009793 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009794 package index after the build by using the following
9795 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009796 <literallayout class='monospaced'>
9797 $ bitbake package-index
9798 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009799 It might be tempting to build the package and the
9800 package index at the same time with a command such as
9801 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009802 <literallayout class='monospaced'>
9803 $ bitbake <replaceable>some-package</replaceable> package-index
9804 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009805 Do not do this as BitBake does not schedule the package
9806 index for after the completion of the package you are
9807 building.
9808 Consequently, you cannot be sure of the package index
9809 including information for the package you just built.
9810 Thus, be sure to run the package update step separately
9811 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009812 </para>
9813
9814 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009815 You can use the
9816 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9817 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9818 and
9819 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9820 variables to pre-configure target images to use a package
9821 feed.
9822 If you do not define these variables, then manual steps
9823 as described in the subsequent sections are necessary to
9824 configure the target.
9825 You should set these variables before building the image
9826 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009827 </para>
9828
9829 <para>
9830 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009831 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009832 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009833 For example, if
9834 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009835 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009836 is RPM, then your RPM packages are available in
9837 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009838 </para>
9839 </section>
9840
9841 <section id='runtime-package-management-server'>
9842 <title>Host or Server Machine Setup</title>
9843
9844 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009845 Although other protocols are possible, a server using HTTP
9846 typically serves packages.
9847 If you want to use HTTP, then set up and configure a
9848 web server such as Apache 2, lighttpd, or
9849 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009850 </para>
9851
9852 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009853 To keep things simple, this section describes how to set
9854 up a SimpleHTTPServer web server to share package feeds
9855 from the developer's machine.
9856 Although this server might not be the best for a production
9857 environment, the setup is simple and straight forward.
9858 Should you want to use a different server more suited for
9859 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9860 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009861 </para>
9862
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009863 <para>
9864 From within the build directory where you have built an
9865 image based on your packaging choice (i.e. the
9866 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9867 setting), simply start the server.
9868 The following example assumes a build directory of
9869 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9870 <filename>PACKAGE_CLASSES</filename> setting of
9871 "package_rpm":
9872 <literallayout class='monospaced'>
9873 $ cd ~/poky/build/tmp/deploy/rpm
9874 $ python -m SimpleHTTPServer
9875 </literallayout>
9876 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009877 </section>
9878
9879 <section id='runtime-package-management-target'>
9880 <title>Target Setup</title>
9881
9882 <para>
9883 Setting up the target differs depending on the
9884 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009885 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009886 </para>
9887
9888 <section id='runtime-package-management-target-rpm'>
9889 <title>Using RPM</title>
9890
9891 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009892 The
9893 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9894 (DNF) performs runtime package management of RPM
9895 packages.
9896 In order to use DNF for runtime package management,
9897 you must perform an initial setup on the target
9898 machine for cases where the
9899 <filename>PACKAGE_FEED_*</filename> variables were not
9900 set as part of the image that is running on the
9901 target.
9902 This means if you built your image and did not not use
9903 these variables as part of the build and your image is
9904 now running on the target, you need to perform the
9905 steps in this section if you want to use runtime
9906 package management.
9907 <note>
9908 For information on the
9909 <filename>PACKAGE_FEED_*</filename> variables, see
9910 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9911 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9912 and
9913 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9914 in the Yocto Project Reference Manual variables
9915 glossary.
9916 </note>
9917 </para>
9918
9919 <para>
9920 On the target, you must inform DNF that package
9921 databases are available.
9922 You do this by creating a file named
9923 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9924 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009925 </para>
9926
9927 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009928 As an example, assume the target is able to use the
9929 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009930 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009931 and <filename>qemux86</filename> from a server named
9932 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009933 The specifics for setting up the web server are up to
9934 you.
9935 The critical requirement is that the URIs in the
9936 target repository configuration point to the
9937 correct remote location for the feeds.
9938 <note><title>Tip</title>
9939 For development purposes, you can point the web
9940 server to the build system's
9941 <filename>deploy</filename> directory.
9942 However, for production use, it is better to copy
9943 the package directories to a location outside of
9944 the build area and use that location.
9945 Doing so avoids situations where the build system
9946 overwrites or changes the
9947 <filename>deploy</filename> directory.
9948 </note>
9949 </para>
9950
9951 <para>
9952 When telling DNF where to look for the package
9953 databases, you must declare individual locations
9954 per architecture or a single location used for all
9955 architectures.
9956 You cannot do both:
9957 <itemizedlist>
9958 <listitem><para>
9959 <emphasis>Create an Explicit List of Architectures:</emphasis>
9960 Define individual base URLs to identify where
9961 each package database is located:
9962 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009963 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009964 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009965 </literallayout>
9966 This example informs DNF about individual
9967 package databases for all three architectures.
9968 </para></listitem>
9969 <listitem><para>
9970 <emphasis>Create a Single (Full) Package Index:</emphasis>
9971 Define a single base URL that identifies where
9972 a full package database is located:
9973 <literallayout class='monospaced'>
9974 [oe-packages]
9975 baseurl=http://my.server/rpm
9976 </literallayout>
9977 This example informs DNF about a single package
9978 database that contains all the package index
9979 information for all supported architectures.
9980 </para></listitem>
9981 </itemizedlist>
9982 </para>
9983
9984 <para>
9985 Once you have informed DNF where to find the package
9986 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009987 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009988 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009989 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009990 DNF is now able to find, install, and upgrade packages
9991 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009992 <note>
9993 See the
9994 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
9995 for additional information.
9996 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009997 </para>
9998 </section>
9999
10000 <section id='runtime-package-management-target-ipk'>
10001 <title>Using IPK</title>
10002
10003 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010004 The <filename>opkg</filename> application performs
10005 runtime package management of IPK packages.
10006 You must perform an initial setup for
10007 <filename>opkg</filename> on the target machine
10008 if the
10009 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10010 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10011 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10012 variables have not been set or the target image was
10013 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010014 </para>
10015
10016 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010017 The <filename>opkg</filename> application uses
10018 configuration files to find available package
10019 databases.
10020 Thus, you need to create a configuration file inside
10021 the <filename>/etc/opkg/</filename> direction, which
10022 informs <filename>opkg</filename> of any repository
10023 you want to use.
10024 </para>
10025
10026 <para>
10027 As an example, suppose you are serving packages from a
10028 <filename>ipk/</filename> directory containing the
10029 <filename>i586</filename>,
10030 <filename>all</filename>, and
10031 <filename>qemux86</filename> databases through an
10032 HTTP server named <filename>my.server</filename>.
10033 On the target, create a configuration file
10034 (e.g. <filename>my_repo.conf</filename>) inside the
10035 <filename>/etc/opkg/</filename> directory containing
10036 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010037 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010038 src/gz all http://my.server/ipk/all
10039 src/gz i586 http://my.server/ipk/i586
10040 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010041 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010042 Next, instruct <filename>opkg</filename> to fetch
10043 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010044 <literallayout class='monospaced'>
10045 # opkg update
10046 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010047 The <filename>opkg</filename> application is now able
10048 to find, install, and upgrade packages from the
10049 specified repository.
10050 </para>
10051 </section>
10052
10053 <section id='runtime-package-management-target-deb'>
10054 <title>Using DEB</title>
10055
10056 <para>
10057 The <filename>apt</filename> application performs
10058 runtime package management of DEB packages.
10059 This application uses a source list file to find
10060 available package databases.
10061 You must perform an initial setup for
10062 <filename>apt</filename> on the target machine
10063 if the
10064 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10065 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10066 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10067 variables have not been set or the target image was
10068 built before the variables were set.
10069 </para>
10070
10071 <para>
10072 To inform <filename>apt</filename> of the repository
10073 you want to use, you might create a list file (e.g.
10074 <filename>my_repo.list</filename>) inside the
10075 <filename>/etc/apt/sources.list.d/</filename>
10076 directory.
10077 As an example, suppose you are serving packages from a
10078 <filename>deb/</filename> directory containing the
10079 <filename>i586</filename>,
10080 <filename>all</filename>, and
10081 <filename>qemux86</filename> databases through an
10082 HTTP server named <filename>my.server</filename>.
10083 The list file should contain:
10084 <literallayout class='monospaced'>
10085 deb http://my.server/deb/all ./
10086 deb http://my.server/deb/i586 ./
10087 deb http://my.server/deb/qemux86 ./
10088 </literallayout>
10089 Next, instruct the <filename>apt</filename>
10090 application to fetch the repository information:
10091 <literallayout class='monospaced'>
10092 # apt-get update
10093 </literallayout>
10094 After this step, <filename>apt</filename> is able
10095 to find, install, and upgrade packages from the
10096 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010097 </para>
10098 </section>
10099 </section>
10100 </section>
10101
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010102 <section id='generating-and-using-signed-packages'>
10103 <title>Generating and Using Signed Packages</title>
10104 <para>
10105 In order to add security to RPM packages used during a build,
10106 you can take steps to securely sign them.
10107 Once a signature is verified, the OpenEmbedded build system
10108 can use the package in the build.
10109 If security fails for a signed package, the build system
10110 aborts the build.
10111 </para>
10112
10113 <para>
10114 This section describes how to sign RPM packages during a build
10115 and how to use signed package feeds (repositories) when
10116 doing a build.
10117 </para>
10118
10119 <section id='signing-rpm-packages'>
10120 <title>Signing RPM Packages</title>
10121
10122 <para>
10123 To enable signing RPM packages, you must set up the
10124 following configurations in either your
10125 <filename>local.config</filename> or
10126 <filename>distro.config</filename> file:
10127 <literallayout class='monospaced'>
10128 # Inherit sign_rpm.bbclass to enable signing functionality
10129 INHERIT += " sign_rpm"
10130 # Define the GPG key that will be used for signing.
10131 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
10132 # Provide passphrase for the key
10133 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
10134 </literallayout>
10135 <note>
10136 Be sure to supply appropriate values for both
10137 <replaceable>key_name</replaceable> and
10138 <replaceable>passphrase</replaceable>
10139 </note>
10140 Aside from the
10141 <filename>RPM_GPG_NAME</filename> and
10142 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
10143 previous example, two optional variables related to signing
10144 exist:
10145 <itemizedlist>
10146 <listitem><para>
10147 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10148 Specifies a <filename>gpg</filename> binary/wrapper
10149 that is executed when the package is signed.
10150 </para></listitem>
10151 <listitem><para>
10152 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10153 Specifies the <filename>gpg</filename> home
10154 directory used when the package is signed.
10155 </para></listitem>
10156 </itemizedlist>
10157 </para>
10158 </section>
10159
10160 <section id='processing-package-feeds'>
10161 <title>Processing Package Feeds</title>
10162
10163 <para>
10164 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010165 also enable signed package feeds for IPK and RPM packages.
10166 </para>
10167
10168 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010169 The steps you need to take to enable signed package feed
10170 use are similar to the steps used to sign RPM packages.
10171 You must define the following in your
10172 <filename>local.config</filename> or
10173 <filename>distro.config</filename> file:
10174 <literallayout class='monospaced'>
10175 INHERIT += "sign_package_feed"
10176 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10177 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10178 </literallayout>
10179 For signed package feeds, the passphrase must exist in a
10180 separate file, which is pointed to by the
10181 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10182 variable.
10183 Regarding security, keeping a plain text passphrase out of
10184 the configuration is more secure.
10185 </para>
10186
10187 <para>
10188 Aside from the
10189 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10190 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10191 variables, three optional variables related to signed
10192 package feeds exist:
10193 <itemizedlist>
10194 <listitem><para>
10195 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10196 Specifies a <filename>gpg</filename> binary/wrapper
10197 that is executed when the package is signed.
10198 </para></listitem>
10199 <listitem><para>
10200 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10201 Specifies the <filename>gpg</filename> home
10202 directory used when the package is signed.
10203 </para></listitem>
10204 <listitem><para>
10205 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10206 Specifies the type of <filename>gpg</filename>
10207 signature.
10208 This variable applies only to RPM and IPK package
10209 feeds.
10210 Allowable values for the
10211 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10212 are "ASC", which is the default and specifies ascii
10213 armored, and "BIN", which specifies binary.
10214 </para></listitem>
10215 </itemizedlist>
10216 </para>
10217 </section>
10218 </section>
10219
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010220 <section id='testing-packages-with-ptest'>
10221 <title>Testing Packages With ptest</title>
10222
10223 <para>
10224 A Package Test (ptest) runs tests against packages built
10225 by the OpenEmbedded build system on the target machine.
10226 A ptest contains at least two items: the actual test, and
10227 a shell script (<filename>run-ptest</filename>) that starts
10228 the test.
10229 The shell script that starts the test must not contain
10230 the actual test - the script only starts the test.
10231 On the other hand, the test can be anything from a simple
10232 shell script that runs a binary and checks the output to
10233 an elaborate system of test binaries and data files.
10234 </para>
10235
10236 <para>
10237 The test generates output in the format used by
10238 Automake:
10239 <literallayout class='monospaced'>
10240 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10241 </literallayout>
10242 where the result can be <filename>PASS</filename>,
10243 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10244 and the testname can be any identifying string.
10245 </para>
10246
10247 <para>
10248 For a list of Yocto Project recipes that are already
10249 enabled with ptest, see the
10250 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10251 wiki page.
10252 <note>
10253 A recipe is "ptest-enabled" if it inherits the
10254 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10255 class.
10256 </note>
10257 </para>
10258
10259 <section id='adding-ptest-to-your-build'>
10260 <title>Adding ptest to Your Build</title>
10261
10262 <para>
10263 To add package testing to your build, add the
10264 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10265 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10266 variables to your <filename>local.conf</filename> file,
10267 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010268 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010269 <literallayout class='monospaced'>
10270 DISTRO_FEATURES_append = " ptest"
10271 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10272 </literallayout>
10273 Once your build is complete, the ptest files are installed
10274 into the
10275 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10276 directory within the image, where
10277 <filename><replaceable>package</replaceable></filename>
10278 is the name of the package.
10279 </para>
10280 </section>
10281
10282 <section id='running-ptest'>
10283 <title>Running ptest</title>
10284
10285 <para>
10286 The <filename>ptest-runner</filename> package installs a
10287 shell script that loops through all installed ptest test
10288 suites and runs them in sequence.
10289 Consequently, you might want to add this package to
10290 your image.
10291 </para>
10292 </section>
10293
10294 <section id='getting-your-package-ready'>
10295 <title>Getting Your Package Ready</title>
10296
10297 <para>
10298 In order to enable a recipe to run installed ptests
10299 on target hardware,
10300 you need to prepare the recipes that build the packages
10301 you want to test.
10302 Here is what you have to do for each recipe:
10303 <itemizedlist>
10304 <listitem><para><emphasis>Be sure the recipe
10305 inherits the
10306 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10307 class:</emphasis>
10308 Include the following line in each recipe:
10309 <literallayout class='monospaced'>
10310 inherit ptest
10311 </literallayout>
10312 </para></listitem>
10313 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10314 This script starts your test.
10315 Locate the script where you will refer to it
10316 using
10317 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10318 Here is an example that starts a test for
10319 <filename>dbus</filename>:
10320 <literallayout class='monospaced'>
10321 #!/bin/sh
10322 cd test
10323 make -k runtest-TESTS
10324 </literallayout>
10325 </para></listitem>
10326 <listitem><para><emphasis>Ensure dependencies are
10327 met:</emphasis>
10328 If the test adds build or runtime dependencies
10329 that normally do not exist for the package
10330 (such as requiring "make" to run the test suite),
10331 use the
10332 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10333 and
10334 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10335 variables in your recipe in order for the package
10336 to meet the dependencies.
10337 Here is an example where the package has a runtime
10338 dependency on "make":
10339 <literallayout class='monospaced'>
10340 RDEPENDS_${PN}-ptest += "make"
10341 </literallayout>
10342 </para></listitem>
10343 <listitem><para><emphasis>Add a function to build the
10344 test suite:</emphasis>
10345 Not many packages support cross-compilation of
10346 their test suites.
10347 Consequently, you usually need to add a
10348 cross-compilation function to the package.
10349 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010350
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010351 <para>Many packages based on Automake compile and
10352 run the test suite by using a single command
10353 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010354 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010355 builds and runs on the same computer, while
10356 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010357 on the host but executed for the target
10358 architecture (though often, as in the case for
10359 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010360 The built version of Automake that ships with the
10361 Yocto Project includes a patch that separates
10362 building and execution.
10363 Consequently, packages that use the unaltered,
10364 patched version of <filename>make check</filename>
10365 automatically cross-compiles.</para>
10366 <para>Regardless, you still must add a
10367 <filename>do_compile_ptest</filename> function to
10368 build the test suite.
10369 Add a function similar to the following to your
10370 recipe:
10371 <literallayout class='monospaced'>
10372 do_compile_ptest() {
10373 oe_runmake buildtest-TESTS
10374 }
10375 </literallayout>
10376 </para></listitem>
10377 <listitem><para><emphasis>Ensure special configurations
10378 are set:</emphasis>
10379 If the package requires special configurations
10380 prior to compiling the test code, you must
10381 insert a <filename>do_configure_ptest</filename>
10382 function into the recipe.
10383 </para></listitem>
10384 <listitem><para><emphasis>Install the test
10385 suite:</emphasis>
10386 The <filename>ptest</filename> class
10387 automatically copies the file
10388 <filename>run-ptest</filename> to the target and
10389 then runs make <filename>install-ptest</filename>
10390 to run the tests.
10391 If this is not enough, you need to create a
10392 <filename>do_install_ptest</filename> function and
10393 make sure it gets called after the
10394 "make install-ptest" completes.
10395 </para></listitem>
10396 </itemizedlist>
10397 </para>
10398 </section>
10399 </section>
10400 </section>
10401
Brad Bishop316dfdd2018-06-25 12:45:53 -040010402 <section id='efficiently-fetching-source-files-during-a-build'>
10403 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010404
10405 <para>
10406 The OpenEmbedded build system works with source files located
10407 through the
10408 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10409 variable.
10410 When you build something using BitBake, a big part of the operation
10411 is locating and downloading all the source tarballs.
10412 For images, downloading all the source for various packages can
10413 take a significant amount of time.
10414 </para>
10415
10416 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010417 This section shows you how you can use mirrors to speed up
10418 fetching source files and how you can pre-fetch files all of which
10419 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010420 </para>
10421
10422 <section id='setting-up-effective-mirrors'>
10423 <title>Setting up Effective Mirrors</title>
10424
10425 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010426 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010427 build is simply downloading all of the source tarballs.
10428 Maybe you have been working with another build system
10429 (OpenEmbedded or Angstrom) for which you have built up a
10430 sizable directory of source tarballs.
10431 Or, perhaps someone else has such a directory for which you
10432 have read access.
10433 If so, you can save time by adding statements to your
10434 configuration file so that the build process checks local
10435 directories first for existing tarballs before checking the
10436 Internet.
10437 </para>
10438
10439 <para>
10440 Here is an efficient way to set it up in your
10441 <filename>local.conf</filename> file:
10442 <literallayout class='monospaced'>
10443 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10444 INHERIT += "own-mirrors"
10445 BB_GENERATE_MIRROR_TARBALLS = "1"
10446 # BB_NO_NETWORK = "1"
10447 </literallayout>
10448 </para>
10449
10450 <para>
10451 In the previous example, the
10452 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10453 variable causes the OpenEmbedded build system to generate
10454 tarballs of the Git repositories and store them in the
10455 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10456 directory.
10457 Due to performance reasons, generating and storing these
10458 tarballs is not the build system's default behavior.
10459 </para>
10460
10461 <para>
10462 You can also use the
10463 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10464 variable.
10465 For an example, see the variable's glossary entry in the
10466 Yocto Project Reference Manual.
10467 </para>
10468 </section>
10469
10470 <section id='getting-source-files-and-suppressing-the-build'>
10471 <title>Getting Source Files and Suppressing the Build</title>
10472
10473 <para>
10474 Another technique you can use to ready yourself for a
10475 successive string of build operations, is to pre-fetch
10476 all the source files without actually starting a build.
10477 This technique lets you work through any download issues
10478 and ultimately gathers all the source files into your
10479 download directory
10480 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10481 which is located with
10482 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10483 </para>
10484
10485 <para>
10486 Use the following BitBake command form to fetch all the
10487 necessary sources without starting the build:
10488 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010489 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010490 </literallayout>
10491 This variation of the BitBake command guarantees that you
10492 have all the sources for that BitBake target should you
10493 disconnect from the Internet and want to do the build
10494 later offline.
10495 </para>
10496 </section>
10497 </section>
10498
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010499 <section id="selecting-an-initialization-manager">
10500 <title>Selecting an Initialization Manager</title>
10501
10502 <para>
10503 By default, the Yocto Project uses SysVinit as the initialization
10504 manager.
10505 However, support also exists for systemd,
10506 which is a full replacement for init with
10507 parallel starting of services, reduced shell overhead and other
10508 features that are used by many distributions.
10509 </para>
10510
10511 <para>
10512 If you want to use SysVinit, you do
10513 not have to do anything.
10514 But, if you want to use systemd, you must
10515 take some steps as described in the following sections.
10516 </para>
10517
10518 <section id='using-systemd-exclusively'>
10519 <title>Using systemd Exclusively</title>
10520
10521 <para>
10522 Set the these variables in your distribution configuration
10523 file as follows:
10524 <literallayout class='monospaced'>
10525 DISTRO_FEATURES_append = " systemd"
10526 VIRTUAL-RUNTIME_init_manager = "systemd"
10527 </literallayout>
10528 You can also prevent the SysVinit
10529 distribution feature from
10530 being automatically enabled as follows:
10531 <literallayout class='monospaced'>
10532 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10533 </literallayout>
10534 Doing so removes any redundant SysVinit scripts.
10535 </para>
10536
10537 <para>
10538 To remove initscripts from your image altogether,
10539 set this variable also:
10540 <literallayout class='monospaced'>
10541 VIRTUAL-RUNTIME_initscripts = ""
10542 </literallayout>
10543 </para>
10544
10545 <para>
10546 For information on the backfill variable, see
10547 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10548 </para>
10549 </section>
10550
10551 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10552 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10553
10554 <para>
10555 Set these variables in your distribution configuration
10556 file as follows:
10557 <literallayout class='monospaced'>
10558 DISTRO_FEATURES_append = " systemd"
10559 VIRTUAL-RUNTIME_init_manager = "systemd"
10560 </literallayout>
10561 Doing so causes your main image to use the
10562 <filename>packagegroup-core-boot.bb</filename> recipe and
10563 systemd.
10564 The rescue/minimal image cannot use this package group.
10565 However, it can install SysVinit
10566 and the appropriate packages will have support for both
10567 systemd and SysVinit.
10568 </para>
10569 </section>
10570 </section>
10571
10572 <section id="selecting-dev-manager">
10573 <title>Selecting a Device Manager</title>
10574
10575 <para>
10576 The Yocto Project provides multiple ways to manage the device
10577 manager (<filename>/dev</filename>):
10578 <itemizedlist>
10579 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10580 For this case, the <filename>/dev</filename> directory
10581 is persistent and the required device nodes are created
10582 during the build.
10583 </para></listitem>
10584 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10585 For this case, the <filename>/dev</filename> directory
10586 is provided by the kernel as an in-memory file system and
10587 is automatically populated by the kernel at runtime.
10588 Additional configuration of device nodes is done in user
10589 space by a device manager like
10590 <filename>udev</filename> or
10591 <filename>busybox-mdev</filename>.
10592 </para></listitem>
10593 </itemizedlist>
10594 </para>
10595
10596 <section id="static-dev-management">
10597 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10598
10599 <para>
10600 To use the static method for device population, you need to
10601 set the
10602 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10603 variable to "0" as follows:
10604 <literallayout class='monospaced'>
10605 USE_DEVFS = "0"
10606 </literallayout>
10607 </para>
10608
10609 <para>
10610 The content of the resulting <filename>/dev</filename>
10611 directory is defined in a Device Table file.
10612 The
10613 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10614 variable defines the Device Table to use and should be set
10615 in the machine or distro configuration file.
10616 Alternatively, you can set this variable in your
10617 <filename>local.conf</filename> configuration file.
10618 </para>
10619
10620 <para>
10621 If you do not define the
10622 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10623 <filename>device_table-minimal.txt</filename> is used:
10624 <literallayout class='monospaced'>
10625 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10626 </literallayout>
10627 </para>
10628
10629 <para>
10630 The population is handled by the <filename>makedevs</filename>
10631 utility during image creation:
10632 </para>
10633 </section>
10634
10635 <section id="devtmpfs-dev-management">
10636 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10637
10638 <para>
10639 To use the dynamic method for device population, you need to
10640 use (or be sure to set) the
10641 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10642 variable to "1", which is the default:
10643 <literallayout class='monospaced'>
10644 USE_DEVFS = "1"
10645 </literallayout>
10646 With this setting, the resulting <filename>/dev</filename>
10647 directory is populated by the kernel using
10648 <filename>devtmpfs</filename>.
10649 Make sure the corresponding kernel configuration variable
10650 <filename>CONFIG_DEVTMPFS</filename> is set when building
10651 you build a Linux kernel.
10652 </para>
10653
10654 <para>
10655 All devices created by <filename>devtmpfs</filename> will be
10656 owned by <filename>root</filename> and have permissions
10657 <filename>0600</filename>.
10658 </para>
10659
10660 <para>
10661 To have more control over the device nodes, you can use a
10662 device manager like <filename>udev</filename> or
10663 <filename>busybox-mdev</filename>.
10664 You choose the device manager by defining the
10665 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10666 in your machine or distro configuration file.
10667 Alternatively, you can set this variable in your
10668 <filename>local.conf</filename> configuration file:
10669 <literallayout class='monospaced'>
10670 VIRTUAL-RUNTIME_dev_manager = "udev"
10671
10672 # Some alternative values
10673 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10674 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10675 </literallayout>
10676 </para>
10677 </section>
10678 </section>
10679
10680 <section id="platdev-appdev-srcrev">
10681 <title>Using an External SCM</title>
10682
10683 <para>
10684 If you're working on a recipe that pulls from an external Source
10685 Code Manager (SCM), it is possible to have the OpenEmbedded build
10686 system notice new recipe changes added to the SCM and then build
10687 the resulting packages that depend on the new recipes by using
10688 the latest versions.
10689 This only works for SCMs from which it is possible to get a
10690 sensible revision number for changes.
10691 Currently, you can do this with Apache Subversion (SVN), Git, and
10692 Bazaar (BZR) repositories.
10693 </para>
10694
10695 <para>
10696 To enable this behavior, the
10697 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
10698 of the recipe needs to reference
10699 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
10700 Here is an example:
10701 <literallayout class='monospaced'>
10702 PV = "1.2.3+git${SRCPV}"
10703 </literallayout>
10704 Then, you can add the following to your
10705 <filename>local.conf</filename>:
10706 <literallayout class='monospaced'>
10707 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
10708 </literallayout>
10709 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
10710 is the name of the recipe for which you want to enable automatic source
10711 revision updating.
10712 </para>
10713
10714 <para>
10715 If you do not want to update your local configuration file, you can
10716 add the following directly to the recipe to finish enabling
10717 the feature:
10718 <literallayout class='monospaced'>
10719 SRCREV = "${AUTOREV}"
10720 </literallayout>
10721 </para>
10722
10723 <para>
10724 The Yocto Project provides a distribution named
10725 <filename>poky-bleeding</filename>, whose configuration
10726 file contains the line:
10727 <literallayout class='monospaced'>
10728 require conf/distro/include/poky-floating-revisions.inc
10729 </literallayout>
10730 This line pulls in the listed include file that contains
10731 numerous lines of exactly that form:
10732 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010733 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
10734 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
10735 #SRCREV_pn-opkg ?= "${AUTOREV}"
10736 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
10737 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010738 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
10739 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
10740 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
10741 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
10742 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010743 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
10744 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
10745 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
10746 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010747 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
10748 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010749 .
10750 .
10751 .
10752 </literallayout>
10753 These lines allow you to experiment with building a
10754 distribution that tracks the latest development source
10755 for numerous packages.
10756 <note><title>Caution</title>
10757 The <filename>poky-bleeding</filename> distribution
10758 is not tested on a regular basis.
10759 Keep this in mind if you use it.
10760 </note>
10761 </para>
10762 </section>
10763
10764 <section id='creating-a-read-only-root-filesystem'>
10765 <title>Creating a Read-Only Root Filesystem</title>
10766
10767 <para>
10768 Suppose, for security reasons, you need to disable
10769 your target device's root filesystem's write permissions
10770 (i.e. you need a read-only root filesystem).
10771 Or, perhaps you are running the device's operating system
10772 from a read-only storage device.
10773 For either case, you can customize your image for
10774 that behavior.
10775 </para>
10776
10777 <note>
10778 Supporting a read-only root filesystem requires that the system and
10779 applications do not try to write to the root filesystem.
10780 You must configure all parts of the target system to write
10781 elsewhere, or to gracefully fail in the event of attempting to
10782 write to the root filesystem.
10783 </note>
10784
10785 <section id='creating-the-root-filesystem'>
10786 <title>Creating the Root Filesystem</title>
10787
10788 <para>
10789 To create the read-only root filesystem, simply add the
10790 "read-only-rootfs" feature to your image.
10791 Using either of the following statements in your
10792 image recipe or from within the
10793 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010794 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010795 causes the build system to create a read-only root filesystem:
10796 <literallayout class='monospaced'>
10797 IMAGE_FEATURES = "read-only-rootfs"
10798 </literallayout>
10799 or
10800 <literallayout class='monospaced'>
10801 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
10802 </literallayout>
10803 </para>
10804
10805 <para>
10806 For more information on how to use these variables, see the
10807 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
10808 section.
10809 For information on the variables, see
10810 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
10811 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
10812 </para>
10813 </section>
10814
10815 <section id='post-installation-scripts'>
10816 <title>Post-Installation Scripts</title>
10817
10818 <para>
10819 It is very important that you make sure all
10820 post-Installation (<filename>pkg_postinst</filename>) scripts
10821 for packages that are installed into the image can be run
10822 at the time when the root filesystem is created during the
10823 build on the host system.
10824 These scripts cannot attempt to run during first-boot on the
10825 target device.
10826 With the "read-only-rootfs" feature enabled,
10827 the build system checks during root filesystem creation to make
10828 sure all post-installation scripts succeed.
10829 If any of these scripts still need to be run after the root
10830 filesystem is created, the build immediately fails.
10831 These build-time checks ensure that the build fails
10832 rather than the target device fails later during its
10833 initial boot operation.
10834 </para>
10835
10836 <para>
10837 Most of the common post-installation scripts generated by the
10838 build system for the out-of-the-box Yocto Project are engineered
10839 so that they can run during root filesystem creation
10840 (e.g. post-installation scripts for caching fonts).
10841 However, if you create and add custom scripts, you need
10842 to be sure they can be run during this file system creation.
10843 </para>
10844
10845 <para>
10846 Here are some common problems that prevent
10847 post-installation scripts from running during root filesystem
10848 creation:
10849 <itemizedlist>
10850 <listitem><para>
10851 <emphasis>Not using $D in front of absolute
10852 paths:</emphasis>
10853 The build system defines
10854 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
10855 when the root filesystem is created.
10856 Furthermore, <filename>$D</filename> is blank when the
10857 script is run on the target device.
10858 This implies two purposes for <filename>$D</filename>:
10859 ensuring paths are valid in both the host and target
10860 environments, and checking to determine which
10861 environment is being used as a method for taking
10862 appropriate actions.
10863 </para></listitem>
10864 <listitem><para>
10865 <emphasis>Attempting to run processes that are
10866 specific to or dependent on the target
10867 architecture:</emphasis>
10868 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010869 tools, which run on the host system,
10870 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010871 by alternatively running the processes under QEMU,
10872 which has the <filename>qemu_run_binary</filename>
10873 function.
10874 For more information, see the
10875 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
10876 class.</para></listitem>
10877 </itemizedlist>
10878 </para>
10879 </section>
10880
10881 <section id='areas-with-write-access'>
10882 <title>Areas With Write Access</title>
10883
10884 <para>
10885 With the "read-only-rootfs" feature enabled,
10886 any attempt by the target to write to the root filesystem at
10887 runtime fails.
10888 Consequently, you must make sure that you configure processes
10889 and applications that attempt these types of writes do so
10890 to directories with write access (e.g.
10891 <filename>/tmp</filename> or <filename>/var/run</filename>).
10892 </para>
10893 </section>
10894 </section>
10895
Brad Bishop316dfdd2018-06-25 12:45:53 -040010896
10897
10898
10899 <section id='maintaining-build-output-quality'>
10900 <title>Maintaining Build Output Quality</title>
10901
10902 <para>
10903 Many factors can influence the quality of a build.
10904 For example, if you upgrade a recipe to use a new version of an
10905 upstream software package or you experiment with some new
10906 configuration options, subtle changes can occur that you might
10907 not detect until later.
10908 Consider the case where your recipe is using a newer version of
10909 an upstream package.
10910 In this case, a new version of a piece of software might
10911 introduce an optional dependency on another library, which is
10912 auto-detected.
10913 If that library has already been built when the software is
10914 building, the software will link to the built library and that
10915 library will be pulled into your image along with the new
10916 software even if you did not want the library.
10917 </para>
10918
10919 <para>
10920 The
10921 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
10922 class exists to help you maintain the quality of your build
10923 output.
10924 You can use the class to highlight unexpected and possibly
10925 unwanted changes in the build output.
10926 When you enable build history, it records information about the
10927 contents of each package and image and then commits that
10928 information to a local Git repository where you can examine
10929 the information.
10930 </para>
10931
10932 <para>
10933 The remainder of this section describes the following:
10934 <itemizedlist>
10935 <listitem><para>
10936 How you can enable and disable build history
10937 </para></listitem>
10938 <listitem><para>
10939 How to understand what the build history contains
10940 </para></listitem>
10941 <listitem><para>
10942 How to limit the information used for build history
10943 </para></listitem>
10944 <listitem><para>
10945 How to examine the build history from both a
10946 command-line and web interface
10947 </para></listitem>
10948 </itemizedlist>
10949 </para>
10950
10951 <section id='enabling-and-disabling-build-history'>
10952 <title>Enabling and Disabling Build History</title>
10953
10954 <para>
10955 Build history is disabled by default.
10956 To enable it, add the following <filename>INHERIT</filename>
10957 statement and set the
10958 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
10959 variable to "1" at the end of your
10960 <filename>conf/local.conf</filename> file found in the
10961 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
10962 <literallayout class='monospaced'>
10963 INHERIT += "buildhistory"
10964 BUILDHISTORY_COMMIT = "1"
10965 </literallayout>
10966 Enabling build history as previously described causes the
10967 OpenEmbedded build system to collect build output information
10968 and commit it as a single commit to a local
10969 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
10970 repository.
10971 <note>
10972 Enabling build history increases your build times slightly,
10973 particularly for images, and increases the amount of disk
10974 space used during the build.
10975 </note>
10976 </para>
10977
10978 <para>
10979 You can disable build history by removing the previous
10980 statements from your <filename>conf/local.conf</filename>
10981 file.
10982 </para>
10983 </section>
10984
10985 <section id='understanding-what-the-build-history-contains'>
10986 <title>Understanding What the Build History Contains</title>
10987
10988 <para>
10989 Build history information is kept in
10990 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
10991 in the Build Directory as defined by the
10992 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
10993 variable.
10994 The following is an example abbreviated listing:
10995 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
10996 </para>
10997
10998 <para>
10999 At the top level, a <filename>metadata-revs</filename>
11000 file exists that lists the revisions of the repositories for
11001 the enabled layers when the build was produced.
11002 The rest of the data splits into separate
11003 <filename>packages</filename>, <filename>images</filename>
11004 and <filename>sdk</filename> directories, the contents of
11005 which are described as follows.
11006 </para>
11007
11008 <section id='build-history-package-information'>
11009 <title>Build History Package Information</title>
11010
11011 <para>
11012 The history for each package contains a text file that has
11013 name-value pairs with information about the package.
11014 For example,
11015 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
11016 contains the following:
11017 <literallayout class='monospaced'>
11018 PV = 1.22.1
11019 PR = r32
11020 RPROVIDES =
11021 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
11022 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
11023 PKGSIZE = 540168
11024 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
11025 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
11026 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
11027 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
11028 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
11029 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
11030 /etc/busybox.links.nosuid /etc/busybox.links.suid
11031 </literallayout>
11032 Most of these name-value pairs correspond to variables
11033 used to produce the package.
11034 The exceptions are <filename>FILELIST</filename>, which
11035 is the actual list of files in the package, and
11036 <filename>PKGSIZE</filename>, which is the total size of
11037 files in the package in bytes.
11038 </para>
11039
11040 <para>
11041 A file also exists that corresponds to the recipe from
11042 which the package came (e.g.
11043 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
11044 <literallayout class='monospaced'>
11045 PV = 1.22.1
11046 PR = r32
11047 DEPENDS = initscripts kern-tools-native update-rc.d-native \
11048 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
11049 virtual/libc virtual/update-alternatives
11050 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
11051 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
11052 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
11053 </literallayout>
11054 </para>
11055
11056 <para>
11057 Finally, for those recipes fetched from a version control
11058 system (e.g., Git), a file exists that lists source
11059 revisions that are specified in the recipe and lists
11060 the actual revisions used during the build.
11061 Listed and actual revisions might differ when
11062 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
11063 is set to
11064 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
11065 Here is an example assuming
11066 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
11067 <literallayout class='monospaced'>
11068 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11069 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11070 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11071 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11072 </literallayout>
11073 You can use the
11074 <filename>buildhistory-collect-srcrevs</filename>
11075 command with the <filename>-a</filename> option to
11076 collect the stored <filename>SRCREV</filename> values
11077 from build history and report them in a format suitable for
11078 use in global configuration (e.g.,
11079 <filename>local.conf</filename> or a distro include file)
11080 to override floating <filename>AUTOREV</filename> values
11081 to a fixed set of revisions.
11082 Here is some example output from this command:
11083 <literallayout class='monospaced'>
11084 $ buildhistory-collect-srcrevs -a
11085 # i586-poky-linux
11086 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
11087 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
11088 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
11089 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11090 # x86_64-linux
11091 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
11092 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
11093 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
11094 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
11095 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
11096 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
11097 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
11098 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
11099 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11100 # qemux86-poky-linux
11101 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11102 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
11103 # all-poky-linux
11104 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
11105 </literallayout>
11106 <note>
11107 Here are some notes on using the
11108 <filename>buildhistory-collect-srcrevs</filename>
11109 command:
11110 <itemizedlist>
11111 <listitem><para>
11112 By default, only values where the
11113 <filename>SRCREV</filename> was not hardcoded
11114 (usually when <filename>AUTOREV</filename>
11115 is used) are reported.
11116 Use the <filename>-a</filename> option to
11117 see all <filename>SRCREV</filename> values.
11118 </para></listitem>
11119 <listitem><para>
11120 The output statements might not have any effect
11121 if overrides are applied elsewhere in the
11122 build system configuration.
11123 Use the <filename>-f</filename> option to add
11124 the <filename>forcevariable</filename> override
11125 to each output line if you need to work around
11126 this restriction.
11127 </para></listitem>
11128 <listitem><para>
11129 The script does apply special handling when
11130 building for multiple machines.
11131 However, the script does place a comment before
11132 each set of values that specifies which
11133 triplet to which they belong as previously
11134 shown (e.g.,
11135 <filename>i586-poky-linux</filename>).
11136 </para></listitem>
11137 </itemizedlist>
11138 </note>
11139 </para>
11140 </section>
11141
11142 <section id='build-history-image-information'>
11143 <title>Build History Image Information</title>
11144
11145 <para>
11146 The files produced for each image are as follows:
11147 <itemizedlist>
11148 <listitem><para>
11149 <filename>image-files:</filename>
11150 A directory containing selected files from the root
11151 filesystem.
11152 The files are defined by
11153 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
11154 </para></listitem>
11155 <listitem><para>
11156 <filename>build-id.txt:</filename>
11157 Human-readable information about the build
11158 configuration and metadata source revisions.
11159 This file contains the full build header as printed
11160 by BitBake.
11161 </para></listitem>
11162 <listitem><para>
11163 <filename>*.dot:</filename>
11164 Dependency graphs for the image that are
11165 compatible with <filename>graphviz</filename>.
11166 </para></listitem>
11167 <listitem><para>
11168 <filename>files-in-image.txt:</filename>
11169 A list of files in the image with permissions,
11170 owner, group, size, and symlink information.
11171 </para></listitem>
11172 <listitem><para>
11173 <filename>image-info.txt:</filename>
11174 A text file containing name-value pairs with
11175 information about the image.
11176 See the following listing example for more
11177 information.
11178 </para></listitem>
11179 <listitem><para>
11180 <filename>installed-package-names.txt:</filename>
11181 A list of installed packages by name only.
11182 </para></listitem>
11183 <listitem><para>
11184 <filename>installed-package-sizes.txt:</filename>
11185 A list of installed packages ordered by size.
11186 </para></listitem>
11187 <listitem><para>
11188 <filename>installed-packages.txt:</filename>
11189 A list of installed packages with full package
11190 filenames.
11191 </para></listitem>
11192 </itemizedlist>
11193 <note>
11194 Installed package information is able to be gathered
11195 and produced even if package management is disabled
11196 for the final image.
11197 </note>
11198 </para>
11199
11200 <para>
11201 Here is an example of <filename>image-info.txt</filename>:
11202 <literallayout class='monospaced'>
11203 DISTRO = poky
11204 DISTRO_VERSION = 1.7
11205 USER_CLASSES = buildstats image-mklibs image-prelink
11206 IMAGE_CLASSES = image_types
11207 IMAGE_FEATURES = debug-tweaks
11208 IMAGE_LINGUAS =
11209 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11210 BAD_RECOMMENDATIONS =
11211 NO_RECOMMENDATIONS =
11212 PACKAGE_EXCLUDE =
11213 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11214 write_image_manifest ; buildhistory_list_installed_image ; \
11215 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11216 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11217 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11218 IMAGESIZE = 6900
11219 </literallayout>
11220 Other than <filename>IMAGESIZE</filename>, which is the
11221 total size of the files in the image in Kbytes, the
11222 name-value pairs are variables that may have influenced the
11223 content of the image.
11224 This information is often useful when you are trying to
11225 determine why a change in the package or file
11226 listings has occurred.
11227 </para>
11228 </section>
11229
11230 <section id='using-build-history-to-gather-image-information-only'>
11231 <title>Using Build History to Gather Image Information Only</title>
11232
11233 <para>
11234 As you can see, build history produces image information,
11235 including dependency graphs, so you can see why something
11236 was pulled into the image.
11237 If you are just interested in this information and not
11238 interested in collecting specific package or SDK
11239 information, you can enable writing only image information
11240 without any history by adding the following to your
11241 <filename>conf/local.conf</filename> file found in the
11242 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11243 <literallayout class='monospaced'>
11244 INHERIT += "buildhistory"
11245 BUILDHISTORY_COMMIT = "0"
11246 BUILDHISTORY_FEATURES = "image"
11247 </literallayout>
11248 Here, you set the
11249 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11250 variable to use the image feature only.
11251 </para>
11252 </section>
11253
11254 <section id='build-history-sdk-information'>
11255 <title>Build History SDK Information</title>
11256
11257 <para>
11258 Build history collects similar information on the contents
11259 of SDKs
11260 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11261 as compared to information it collects for images.
11262 Furthermore, this information differs depending on whether
11263 an extensible or standard SDK is being produced.
11264 </para>
11265
11266 <para>
11267 The following list shows the files produced for SDKs:
11268 <itemizedlist>
11269 <listitem><para>
11270 <filename>files-in-sdk.txt:</filename>
11271 A list of files in the SDK with permissions,
11272 owner, group, size, and symlink information.
11273 This list includes both the host and target parts
11274 of the SDK.
11275 </para></listitem>
11276 <listitem><para>
11277 <filename>sdk-info.txt:</filename>
11278 A text file containing name-value pairs with
11279 information about the SDK.
11280 See the following listing example for more
11281 information.
11282 </para></listitem>
11283 <listitem><para>
11284 <filename>sstate-task-sizes.txt:</filename>
11285 A text file containing name-value pairs with
11286 information about task group sizes
11287 (e.g. <filename>do_populate_sysroot</filename>
11288 tasks have a total size).
11289 The <filename>sstate-task-sizes.txt</filename> file
11290 exists only when an extensible SDK is created.
11291 </para></listitem>
11292 <listitem><para>
11293 <filename>sstate-package-sizes.txt:</filename>
11294 A text file containing name-value pairs with
11295 information for the shared-state packages and
11296 sizes in the SDK.
11297 The <filename>sstate-package-sizes.txt</filename>
11298 file exists only when an extensible SDK is created.
11299 </para></listitem>
11300 <listitem><para>
11301 <filename>sdk-files:</filename>
11302 A folder that contains copies of the files
11303 mentioned in
11304 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11305 files are present in the output.
11306 Additionally, the default value of
11307 <filename>BUILDHISTORY_SDK_FILES</filename> is
11308 specific to the extensible SDK although you can
11309 set it differently if you would like to pull in
11310 specific files from the standard SDK.</para>
11311
11312 <para>The default files are
11313 <filename>conf/local.conf</filename>,
11314 <filename>conf/bblayers.conf</filename>,
11315 <filename>conf/auto.conf</filename>,
11316 <filename>conf/locked-sigs.inc</filename>, and
11317 <filename>conf/devtool.conf</filename>.
11318 Thus, for an extensible SDK, these files get
11319 copied into the <filename>sdk-files</filename>
11320 directory.
11321 </para></listitem>
11322 <listitem><para>
11323 The following information appears under
11324 each of the <filename>host</filename>
11325 and <filename>target</filename> directories
11326 for the portions of the SDK that run on the host
11327 and on the target, respectively:
11328 <note>
11329 The following files for the most part are empty
11330 when producing an extensible SDK because this
11331 type of SDK is not constructed from packages
11332 as is the standard SDK.
11333 </note>
11334 <itemizedlist>
11335 <listitem><para>
11336 <filename>depends.dot:</filename>
11337 Dependency graph for the SDK that is
11338 compatible with
11339 <filename>graphviz</filename>.
11340 </para></listitem>
11341 <listitem><para>
11342 <filename>installed-package-names.txt:</filename>
11343 A list of installed packages by name only.
11344 </para></listitem>
11345 <listitem><para>
11346 <filename>installed-package-sizes.txt:</filename>
11347 A list of installed packages ordered by size.
11348 </para></listitem>
11349 <listitem><para>
11350 <filename>installed-packages.txt:</filename>
11351 A list of installed packages with full
11352 package filenames.
11353 </para></listitem>
11354 </itemizedlist>
11355 </para></listitem>
11356 </itemizedlist>
11357 </para>
11358
11359 <para>
11360 Here is an example of <filename>sdk-info.txt</filename>:
11361 <literallayout class='monospaced'>
11362 DISTRO = poky
11363 DISTRO_VERSION = 1.3+snapshot-20130327
11364 SDK_NAME = poky-glibc-i686-arm
11365 SDK_VERSION = 1.3+snapshot
11366 SDKMACHINE =
11367 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11368 BAD_RECOMMENDATIONS =
11369 SDKSIZE = 352712
11370 </literallayout>
11371 Other than <filename>SDKSIZE</filename>, which is the
11372 total size of the files in the SDK in Kbytes, the
11373 name-value pairs are variables that might have influenced
11374 the content of the SDK.
11375 This information is often useful when you are trying to
11376 determine why a change in the package or file listings
11377 has occurred.
11378 </para>
11379 </section>
11380
11381 <section id='examining-build-history-information'>
11382 <title>Examining Build History Information</title>
11383
11384 <para>
11385 You can examine build history output from the command
11386 line or from a web interface.
11387 </para>
11388
11389 <para>
11390 To see any changes that have occurred (assuming you have
11391 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11392 you can simply use any Git command that allows you to
11393 view the history of a repository.
11394 Here is one method:
11395 <literallayout class='monospaced'>
11396 $ git log -p
11397 </literallayout>
11398 You need to realize, however, that this method does show
11399 changes that are not significant (e.g. a package's size
11400 changing by a few bytes).
11401 </para>
11402
11403 <para>
11404 A command-line tool called
11405 <filename>buildhistory-diff</filename> does exist, though,
11406 that queries the Git repository and prints just the
11407 differences that might be significant in human-readable
11408 form.
11409 Here is an example:
11410 <literallayout class='monospaced'>
11411 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11412 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11413 /etc/anotherpkg.conf was added
11414 /sbin/anotherpkg was added
11415 * (installed-package-names.txt):
11416 * anotherpkg was added
11417 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11418 anotherpkg was added
11419 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11420 * PR changed from "r0" to "r1"
11421 * PV changed from "0.1.10" to "0.1.12"
11422 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11423 * PR changed from "r0" to "r1"
11424 * PV changed from "0.1.10" to "0.1.12"
11425 </literallayout>
11426 <note>
11427 The <filename>buildhistory-diff</filename> tool
11428 requires the <filename>GitPython</filename> package.
11429 Be sure to install it using Pip3 as follows:
11430 <literallayout class='monospaced'>
11431 $ pip3 install GitPython --user
11432 </literallayout>
11433 Alternatively, you can install
11434 <filename>python3-git</filename> using the appropriate
11435 distribution package manager (e.g.
11436 <filename>apt-get</filename>, <filename>dnf</filename>,
11437 or <filename>zipper</filename>).
11438 </note>
11439 </para>
11440
11441 <para>
11442 To see changes to the build history using a web interface,
11443 follow the instruction in the <filename>README</filename>
11444 file here.
11445 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11446 </para>
11447
11448 <para>
11449 Here is a sample screenshot of the interface:
11450 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11451 </para>
11452 </section>
11453 </section>
11454 </section>
11455
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011456 <section id="performing-automated-runtime-testing">
11457 <title>Performing Automated Runtime Testing</title>
11458
11459 <para>
11460 The OpenEmbedded build system makes available a series of automated
11461 tests for images to verify runtime functionality.
11462 You can run these tests on either QEMU or actual target hardware.
11463 Tests are written in Python making use of the
11464 <filename>unittest</filename> module, and the majority of them
11465 run commands on the target system over SSH.
11466 This section describes how you set up the environment to use these
11467 tests, run available tests, and write and add your own tests.
11468 </para>
11469
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011470 <para>
11471 For information on the test and QA infrastructure available
11472 within the Yocto Project, see the
11473 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11474 section in the Yocto Project Reference Manual.
11475 </para>
11476
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011477 <section id='enabling-tests'>
11478 <title>Enabling Tests</title>
11479
11480 <para>
11481 Depending on whether you are planning to run tests using
11482 QEMU or on the hardware, you have to take
11483 different steps to enable the tests.
11484 See the following subsections for information on how to
11485 enable both types of tests.
11486 </para>
11487
11488 <section id='qemu-image-enabling-tests'>
11489 <title>Enabling Runtime Tests on QEMU</title>
11490
11491 <para>
11492 In order to run tests, you need to do the following:
11493 <itemizedlist>
11494 <listitem><para><emphasis>Set up to avoid interaction
11495 with <filename>sudo</filename> for networking:</emphasis>
11496 To accomplish this, you must do one of the
11497 following:
11498 <itemizedlist>
11499 <listitem><para>Add
11500 <filename>NOPASSWD</filename> for your user
11501 in <filename>/etc/sudoers</filename> either for
11502 all commands or just for
11503 <filename>runqemu-ifup</filename>.
11504 You must provide the full path as that can
11505 change if you are using multiple clones of the
11506 source repository.
11507 <note>
11508 On some distributions, you also need to
11509 comment out "Defaults requiretty" in
11510 <filename>/etc/sudoers</filename>.
11511 </note></para></listitem>
11512 <listitem><para>Manually configure a tap interface
11513 for your system.</para></listitem>
11514 <listitem><para>Run as root the script in
11515 <filename>scripts/runqemu-gen-tapdevs</filename>,
11516 which should generate a list of tap devices.
11517 This is the option typically chosen for
11518 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011519 <note><title>Notes</title>
11520 <itemizedlist>
11521 <listitem><para>
11522 Be sure to use an absolute path
11523 when calling this script
11524 with sudo.
11525 </para></listitem>
11526 <listitem><para>
11527 The package recipe
11528 <filename>qemu-helper-native</filename>
11529 is required to run this script.
11530 Build the package using the
11531 following command:
11532 <literallayout class='monospaced'>
11533 $ bitbake qemu-helper-native
11534 </literallayout>
11535 </para></listitem>
11536 </itemizedlist>
11537 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011538 </para></listitem>
11539 </itemizedlist></para></listitem>
11540 <listitem><para><emphasis>Set the
11541 <filename>DISPLAY</filename> variable:</emphasis>
11542 You need to set this variable so that you have an X
11543 server available (e.g. start
11544 <filename>vncserver</filename> for a headless machine).
11545 </para></listitem>
11546 <listitem><para><emphasis>Be sure your host's firewall
11547 accepts incoming connections from
11548 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011549 Some of the tests (in particular DNF tests) start
11550 an HTTP server on a random high number port,
11551 which is used to serve files to the target.
11552 The DNF module serves
11553 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11554 so it can run DNF channel commands.
11555 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011556 must accept incoming connections from 192.168.7.0/24,
11557 which is the default IP range used for tap devices
11558 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011559 <listitem><para><emphasis>Be sure your host has the
11560 correct packages installed:</emphasis>
11561 Depending your host's distribution, you need
11562 to have the following packages installed:
11563 <itemizedlist>
11564 <listitem><para>Ubuntu and Debian:
11565 <filename>sysstat</filename> and
11566 <filename>iproute2</filename>
11567 </para></listitem>
11568 <listitem><para>OpenSUSE:
11569 <filename>sysstat</filename> and
11570 <filename>iproute2</filename>
11571 </para></listitem>
11572 <listitem><para>Fedora:
11573 <filename>sysstat</filename> and
11574 <filename>iproute</filename>
11575 </para></listitem>
11576 <listitem><para>CentOS:
11577 <filename>sysstat</filename> and
11578 <filename>iproute</filename>
11579 </para></listitem>
11580 </itemizedlist>
11581 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011582 </itemizedlist>
11583 </para>
11584
11585 <para>
11586 Once you start running the tests, the following happens:
11587 <orderedlist>
11588 <listitem><para>A copy of the root filesystem is written
11589 to <filename>${WORKDIR}/testimage</filename>.
11590 </para></listitem>
11591 <listitem><para>The image is booted under QEMU using the
11592 standard <filename>runqemu</filename> script.
11593 </para></listitem>
11594 <listitem><para>A default timeout of 500 seconds occurs
11595 to allow for the boot process to reach the login prompt.
11596 You can change the timeout period by setting
11597 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11598 in the <filename>local.conf</filename> file.
11599 </para></listitem>
11600 <listitem><para>Once the boot process is reached and the
11601 login prompt appears, the tests run.
11602 The full boot log is written to
11603 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11604 </para></listitem>
11605 <listitem><para>Each test module loads in the order found
11606 in <filename>TEST_SUITES</filename>.
11607 You can find the full output of the commands run over
11608 SSH in
11609 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11610 </para></listitem>
11611 <listitem><para>If no failures occur, the task running the
11612 tests ends successfully.
11613 You can find the output from the
11614 <filename>unittest</filename> in the task log at
11615 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11616 </para></listitem>
11617 </orderedlist>
11618 </para>
11619 </section>
11620
11621 <section id='hardware-image-enabling-tests'>
11622 <title>Enabling Runtime Tests on Hardware</title>
11623
11624 <para>
11625 The OpenEmbedded build system can run tests on real
11626 hardware, and for certain devices it can also deploy
11627 the image to be tested onto the device beforehand.
11628 </para>
11629
11630 <para>
11631 For automated deployment, a "master image" is installed
11632 onto the hardware once as part of setup.
11633 Then, each time tests are to be run, the following
11634 occurs:
11635 <orderedlist>
11636 <listitem><para>The master image is booted into and
11637 used to write the image to be tested to
11638 a second partition.
11639 </para></listitem>
11640 <listitem><para>The device is then rebooted using an
11641 external script that you need to provide.
11642 </para></listitem>
11643 <listitem><para>The device boots into the image to be
11644 tested.
11645 </para></listitem>
11646 </orderedlist>
11647 </para>
11648
11649 <para>
11650 When running tests (independent of whether the image
11651 has been deployed automatically or not), the device is
11652 expected to be connected to a network on a
11653 pre-determined IP address.
11654 You can either use static IP addresses written into
11655 the image, or set the image to use DHCP and have your
11656 DHCP server on the test network assign a known IP address
11657 based on the MAC address of the device.
11658 </para>
11659
11660 <para>
11661 In order to run tests on hardware, you need to set
11662 <filename>TEST_TARGET</filename> to an appropriate value.
11663 For QEMU, you do not have to change anything, the default
11664 value is "QemuTarget".
11665 For running tests on hardware, the following options exist:
11666 <itemizedlist>
11667 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11668 Choose "SimpleRemoteTarget" if you are going to
11669 run tests on a target system that is already
11670 running the image to be tested and is available
11671 on the network.
11672 You can use "SimpleRemoteTarget" in conjunction
11673 with either real hardware or an image running
11674 within a separately started QEMU or any
11675 other virtual machine manager.
11676 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011677 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
11678 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011679 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011680 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011681 <filename>core-image-testmaster</filename>
11682 (or something similar) is installed.
11683 Also, your hardware under test must be in a
11684 DHCP-enabled network that gives it the same IP
11685 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011686 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011687 additional requirements and considerations.
11688 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011689 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011690 section, which follows, for more information.
11691 </para></listitem>
11692 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
11693 Choose "BeagleBoneTarget" if you are deploying
11694 images and running tests on the BeagleBone
11695 "Black" or original "White" hardware.
11696 For information on how to use these tests, see the
11697 comments at the top of the BeagleBoneTarget
11698 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
11699 file.
11700 </para></listitem>
11701 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
11702 Choose "EdgeRouterTarget" is you are deploying
11703 images and running tests on the Ubiquiti Networks
11704 EdgeRouter Lite.
11705 For information on how to use these tests, see the
11706 comments at the top of the EdgeRouterTarget
11707 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
11708 file.
11709 </para></listitem>
11710 <listitem><para><emphasis>"GrubTarget":</emphasis>
11711 Choose the "supports deploying images and running
11712 tests on any generic PC that boots using GRUB.
11713 For information on how to use these tests, see the
11714 comments at the top of the GrubTarget
11715 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
11716 file.
11717 </para></listitem>
11718 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
11719 Create your own custom target if you want to run
11720 tests when you are deploying images and running
11721 tests on a custom machine within your BSP layer.
11722 To do this, you need to add a Python unit that
11723 defines the target class under
11724 <filename>lib/oeqa/controllers/</filename> within
11725 your layer.
11726 You must also provide an empty
11727 <filename>__init__.py</filename>.
11728 For examples, see files in
11729 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
11730 </para></listitem>
11731 </itemizedlist>
11732 </para>
11733 </section>
11734
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011735 <section id='selecting-systemdboottarget'>
11736 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011737
11738 <para>
11739 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011740 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011741 in this section.
11742 You can skip down to the
11743 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
11744 section.
11745 </para>
11746
11747 <para>
11748 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011749 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011750 setup of your master image by doing the following:
11751 <orderedlist>
11752 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
11753 Be sure that <filename>EFI_PROVIDER</filename>
11754 is as follows:
11755 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011756 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011757 </literallayout>
11758 </para></listitem>
11759 <listitem><para><emphasis>Build the master image:</emphasis>
11760 Build the <filename>core-image-testmaster</filename>
11761 image.
11762 The <filename>core-image-testmaster</filename>
11763 recipe is provided as an example for a
11764 "master" image and you can customize the image
11765 recipe as you would any other recipe.
11766 </para>
11767 <para>Here are the image recipe requirements:
11768 <itemizedlist>
11769 <listitem><para>Inherits
11770 <filename>core-image</filename>
11771 so that kernel modules are installed.
11772 </para></listitem>
11773 <listitem><para>Installs normal linux utilities
11774 not busybox ones (e.g.
11775 <filename>bash</filename>,
11776 <filename>coreutils</filename>,
11777 <filename>tar</filename>,
11778 <filename>gzip</filename>, and
11779 <filename>kmod</filename>).
11780 </para></listitem>
11781 <listitem><para>Uses a custom
11782 Initial RAM Disk (initramfs) image with a
11783 custom installer.
11784 A normal image that you can install usually
11785 creates a single rootfs partition.
11786 This image uses another installer that
11787 creates a specific partition layout.
11788 Not all Board Support Packages (BSPs)
11789 can use an installer.
11790 For such cases, you need to manually create
11791 the following partition layout on the
11792 target:
11793 <itemizedlist>
11794 <listitem><para>First partition mounted
11795 under <filename>/boot</filename>,
11796 labeled "boot".
11797 </para></listitem>
11798 <listitem><para>The main rootfs
11799 partition where this image gets
11800 installed, which is mounted under
11801 <filename>/</filename>.
11802 </para></listitem>
11803 <listitem><para>Another partition
11804 labeled "testrootfs" where test
11805 images get deployed.
11806 </para></listitem>
11807 </itemizedlist>
11808 </para></listitem>
11809 </itemizedlist>
11810 </para></listitem>
11811 <listitem><para><emphasis>Install image:</emphasis>
11812 Install the image that you just built on the target
11813 system.
11814 </para></listitem>
11815 </orderedlist>
11816 </para>
11817
11818 <para>
11819 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011820 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011821 to set up the test image:
11822 <orderedlist>
11823 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
11824 Make sure you have the following statements in
11825 your <filename>local.conf</filename> file:
11826 <literallayout class='monospaced'>
11827 IMAGE_FSTYPES += "tar.gz"
11828 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011829 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011830 TEST_TARGET_IP = "192.168.2.3"
11831 </literallayout>
11832 </para></listitem>
11833 <listitem><para><emphasis>Build your test image:</emphasis>
11834 Use BitBake to build the image:
11835 <literallayout class='monospaced'>
11836 $ bitbake core-image-sato
11837 </literallayout>
11838 </para></listitem>
11839 </orderedlist>
11840 </para>
11841 </section>
11842
11843 <section id='power-control'>
11844 <title>Power Control</title>
11845
11846 <para>
11847 For most hardware targets other than SimpleRemoteTarget,
11848 you can control power:
11849 <itemizedlist>
11850 <listitem><para>
11851 You can use
11852 <filename>TEST_POWERCONTROL_CMD</filename>
11853 together with
11854 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11855 as a command that runs on the host and does power
11856 cycling.
11857 The test code passes one argument to that command:
11858 off, on or cycle (off then on).
11859 Here is an example that could appear in your
11860 <filename>local.conf</filename> file:
11861 <literallayout class='monospaced'>
11862 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
11863 </literallayout>
11864 In this example, the expect script does the
11865 following:
11866 <literallayout class='monospaced'>
11867 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
11868 </literallayout>
11869 It then runs a Python script that controls power
11870 for a label called <filename>nuc1</filename>.
11871 <note>
11872 You need to customize
11873 <filename>TEST_POWERCONTROL_CMD</filename>
11874 and
11875 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11876 for your own setup.
11877 The one requirement is that it accepts
11878 "on", "off", and "cycle" as the last argument.
11879 </note>
11880 </para></listitem>
11881 <listitem><para>
11882 When no command is defined, it connects to the
11883 device over SSH and uses the classic reboot command
11884 to reboot the device.
11885 Classic reboot is fine as long as the machine
11886 actually reboots (i.e. the SSH test has not
11887 failed).
11888 It is useful for scenarios where you have a simple
11889 setup, typically with a single board, and where
11890 some manual interaction is okay from time to time.
11891 </para></listitem>
11892 </itemizedlist>
11893 If you have no hardware to automatically perform power
11894 control but still wish to experiment with automated
11895 hardware testing, you can use the dialog-power-control
11896 script that shows a dialog prompting you to perform the
11897 required power action.
11898 This script requires either KDialog or Zenity to be
11899 installed.
11900 To use this script, set the
11901 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
11902 variable as follows:
11903 <literallayout class='monospaced'>
11904 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
11905 </literallayout>
11906 </para>
11907 </section>
11908
11909 <section id='serial-console-connection'>
11910 <title>Serial Console Connection</title>
11911
11912 <para>
11913 For test target classes requiring a serial console
11914 to interact with the bootloader (e.g. BeagleBoneTarget,
11915 EdgeRouterTarget, and GrubTarget), you need to
11916 specify a command to use to connect to the serial console
11917 of the target machine by using the
11918 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
11919 variable and optionally the
11920 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
11921 variable.
11922 </para>
11923
11924 <para>
11925 These cases could be a serial terminal program if the
11926 machine is connected to a local serial port, or a
11927 <filename>telnet</filename> or
11928 <filename>ssh</filename> command connecting to a remote
11929 console server.
11930 Regardless of the case, the command simply needs to
11931 connect to the serial console and forward that connection
11932 to standard input and output as any normal terminal
11933 program does.
11934 For example, to use the picocom terminal program on
11935 serial device <filename>/dev/ttyUSB0</filename>
11936 at 115200bps, you would set the variable as follows:
11937 <literallayout class='monospaced'>
11938 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
11939 </literallayout>
11940 For local devices where the serial port device disappears
11941 when the device reboots, an additional "serdevtry" wrapper
11942 script is provided.
11943 To use this wrapper, simply prefix the terminal command
11944 with
11945 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
11946 <literallayout class='monospaced'>
11947 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
11948115200 /dev/ttyUSB0"
11949 </literallayout>
11950 </para>
11951 </section>
11952 </section>
11953
11954 <section id="qemu-image-running-tests">
11955 <title>Running Tests</title>
11956
11957 <para>
11958 You can start the tests automatically or manually:
11959 <itemizedlist>
11960 <listitem><para><emphasis>Automatically running tests:</emphasis>
11961 To run the tests automatically after the
11962 OpenEmbedded build system successfully creates an image,
11963 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011964 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011965 variable to "1" in your <filename>local.conf</filename>
11966 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011967 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011968 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011969 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011970 </literallayout>
11971 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011972 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011973 <literallayout class='monospaced'>
11974 bitbake core-image-sato
11975 </literallayout></para></listitem>
11976 <listitem><para><emphasis>Manually running tests:</emphasis>
11977 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011978 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011979 class by editing your <filename>local.conf</filename>
11980 file:
11981 <literallayout class='monospaced'>
11982 INHERIT += "testimage"
11983 </literallayout>
11984 Next, use BitBake to run the tests:
11985 <literallayout class='monospaced'>
11986 bitbake -c testimage <replaceable>image</replaceable>
11987 </literallayout></para></listitem>
11988 </itemizedlist>
11989 </para>
11990
11991 <para>
11992 All test files reside in
11993 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011994 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011995 A test name maps directly to a Python module.
11996 Each test module may contain a number of individual tests.
11997 Tests are usually grouped together by the area
11998 tested (e.g tests for systemd reside in
11999 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
12000 </para>
12001
12002 <para>
12003 You can add tests to any layer provided you place them in the
12004 proper area and you extend
12005 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12006 in the <filename>local.conf</filename> file as normal.
12007 Be sure that tests reside in
12008 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
12009 <note>
12010 Be sure that module names do not collide with module names
12011 used in the default set of test modules in
12012 <filename>meta/lib/oeqa/runtime</filename>.
12013 </note>
12014 </para>
12015
12016 <para>
12017 You can change the set of tests run by appending or overriding
12018 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
12019 variable in <filename>local.conf</filename>.
12020 Each name in <filename>TEST_SUITES</filename> represents a
12021 required test for the image.
12022 Test modules named within <filename>TEST_SUITES</filename>
12023 cannot be skipped even if a test is not suitable for an image
12024 (e.g. running the RPM tests on an image without
12025 <filename>rpm</filename>).
12026 Appending "auto" to <filename>TEST_SUITES</filename> causes the
12027 build system to try to run all tests that are suitable for the
12028 image (i.e. each test module may elect to skip itself).
12029 </para>
12030
12031 <para>
12032 The order you list tests in <filename>TEST_SUITES</filename>
12033 is important and influences test dependencies.
12034 Consequently, tests that depend on other tests should be added
12035 after the test on which they depend.
12036 For example, since the <filename>ssh</filename> test
12037 depends on the
12038 <filename>ping</filename> test, "ssh" needs to come after
12039 "ping" in the list.
12040 The test class provides no re-ordering or dependency handling.
12041 <note>
12042 Each module can have multiple classes with multiple test
12043 methods.
12044 And, Python <filename>unittest</filename> rules apply.
12045 </note>
12046 </para>
12047
12048 <para>
12049 Here are some things to keep in mind when running tests:
12050 <itemizedlist>
12051 <listitem><para>The default tests for the image are defined
12052 as:
12053 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012054 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 -050012055 </literallayout></para></listitem>
12056 <listitem><para>Add your own test to the list of the
12057 by using the following:
12058 <literallayout class='monospaced'>
12059 TEST_SUITES_append = " mytest"
12060 </literallayout></para></listitem>
12061 <listitem><para>Run a specific list of tests as follows:
12062 <literallayout class='monospaced'>
12063 TEST_SUITES = "test1 test2 test3"
12064 </literallayout>
12065 Remember, order is important.
12066 Be sure to place a test that is dependent on another test
12067 later in the order.</para></listitem>
12068 </itemizedlist>
12069 </para>
12070 </section>
12071
12072 <section id="exporting-tests">
12073 <title>Exporting Tests</title>
12074
12075 <para>
12076 You can export tests so that they can run independently of
12077 the build system.
12078 Exporting tests is required if you want to be able to hand
12079 the test execution off to a scheduler.
12080 You can only export tests that are defined in
12081 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
12082 </para>
12083
12084 <para>
12085 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012086 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012087 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012088 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012089 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
12090 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012091 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012092 You can then export the tests with the following BitBake
12093 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012094 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012095 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012096 </literallayout>
12097 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012098 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12099 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012100 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
12101 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012102 <filename>TEST_EXPORT_DIR</filename> variable.
12103 </para>
12104
12105 <para>
12106 You can now run the tests outside of the build environment:
12107 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012108 $ cd tmp/testexport/<replaceable>image</replaceable>
12109 $ ./runexported.py testdata.json
12110 </literallayout>
12111 </para>
12112
12113 <para>
12114 Here is a complete example that shows IP addresses and uses
12115 the <filename>core-image-sato</filename> image:
12116 <literallayout class='monospaced'>
12117 INHERIT +="testexport"
12118 TEST_TARGET_IP = "192.168.7.2"
12119 TEST_SERVER_IP = "192.168.7.1"
12120 </literallayout>
12121 Use BitBake to export the tests:
12122 <literallayout class='monospaced'>
12123 $ bitbake core-image-sato -c testexport
12124 </literallayout>
12125 Run the tests outside of the build environment using the
12126 following:
12127 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012128 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012129 $ ./runexported.py testdata.json
12130 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012131 </para>
12132 </section>
12133
12134 <section id="qemu-image-writing-new-tests">
12135 <title>Writing New Tests</title>
12136
12137 <para>
12138 As mentioned previously, all new test files need to be in the
12139 proper place for the build system to find them.
12140 New tests for additional functionality outside of the core
12141 should be added to the layer that adds the functionality, in
12142 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
12143 (as long as
12144 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12145 is extended in the layer's
12146 <filename>layer.conf</filename> file as normal).
12147 Just remember the following:
12148 <itemizedlist>
12149 <listitem><para>Filenames need to map directly to test
12150 (module) names.
12151 </para></listitem>
12152 <listitem><para>Do not use module names that
12153 collide with existing core tests.
12154 </para></listitem>
12155 <listitem><para>Minimally, an empty
12156 <filename>__init__.py</filename> file must exist
12157 in the runtime directory.
12158 </para></listitem>
12159 </itemizedlist>
12160 </para>
12161
12162 <para>
12163 To create a new test, start by copying an existing module
12164 (e.g. <filename>syslog.py</filename> or
12165 <filename>gcc.py</filename> are good ones to use).
12166 Test modules can use code from
12167 <filename>meta/lib/oeqa/utils</filename>, which are helper
12168 classes.
12169 </para>
12170
12171 <note>
12172 Structure shell commands such that you rely on them and they
12173 return a single code for success.
12174 Be aware that sometimes you will need to parse the output.
12175 See the <filename>df.py</filename> and
12176 <filename>date.py</filename> modules for examples.
12177 </note>
12178
12179 <para>
12180 You will notice that all test classes inherit
12181 <filename>oeRuntimeTest</filename>, which is found in
12182 <filename>meta/lib/oetest.py</filename>.
12183 This base class offers some helper attributes, which are
12184 described in the following sections:
12185 </para>
12186
12187 <section id='qemu-image-writing-tests-class-methods'>
12188 <title>Class Methods</title>
12189
12190 <para>
12191 Class methods are as follows:
12192 <itemizedlist>
12193 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12194 Returns "True" if <filename>pkg</filename> is in the
12195 installed package list of the image, which is based
12196 on the manifest file that is generated during the
12197 <filename>do_rootfs</filename> task.
12198 </para></listitem>
12199 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12200 Returns "True" if the feature is in
12201 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12202 or
12203 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12204 </para></listitem>
12205 </itemizedlist>
12206 </para>
12207 </section>
12208
12209 <section id='qemu-image-writing-tests-class-attributes'>
12210 <title>Class Attributes</title>
12211
12212 <para>
12213 Class attributes are as follows:
12214 <itemizedlist>
12215 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12216 Equals "ps -ef" if <filename>procps</filename> is
12217 installed in the image.
12218 Otherwise, <filename>pscmd</filename> equals
12219 "ps" (busybox).
12220 </para></listitem>
12221 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12222 The called test context, which gives access to the
12223 following attributes:
12224 <itemizedlist>
12225 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12226 The BitBake datastore, which allows you to
12227 use stuff such as
12228 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12229 </para></listitem>
12230 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12231 Used internally.
12232 The tests do not need these.
12233 </para></listitem>
12234 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12235 The absolute path to
12236 <filename>meta/lib/oeqa/runtime/files</filename>,
12237 which contains helper files for tests meant
12238 for copying on the target such as small
12239 files written in C for compilation.
12240 </para></listitem>
12241 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12242 The target controller object used to deploy
12243 and start an image on a particular target
12244 (e.g. QemuTarget, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012245 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012246 Tests usually use the following:
12247 <itemizedlist>
12248 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12249 The target's IP address.
12250 </para></listitem>
12251 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12252 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012253 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012254 suite.
12255 </para></listitem>
12256 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12257 The single, most used method.
12258 This command is a wrapper for:
12259 <filename>ssh root@host "cmd"</filename>.
12260 The command returns a tuple:
12261 (status, output), which are what
12262 their names imply - the return code
12263 of "cmd" and whatever output
12264 it produces.
12265 The optional timeout argument
12266 represents the number of seconds the
12267 test should wait for "cmd" to
12268 return.
12269 If the argument is "None", the
12270 test uses the default instance's
12271 timeout period, which is 300
12272 seconds.
12273 If the argument is "0", the test
12274 runs until the command returns.
12275 </para></listitem>
12276 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12277 <filename>scp localpath root@ip:remotepath</filename>.
12278 </para></listitem>
12279 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12280 <filename>scp root@host:remotepath localpath</filename>.
12281 </para></listitem>
12282 </itemizedlist></para></listitem>
12283 </itemizedlist></para></listitem>
12284 </itemizedlist>
12285 </para>
12286 </section>
12287
12288 <section id='qemu-image-writing-tests-instance-attributes'>
12289 <title>Instance Attributes</title>
12290
12291 <para>
12292 A single instance attribute exists, which is
12293 <filename>target</filename>.
12294 The <filename>target</filename> instance attribute is
12295 identical to the class attribute of the same name, which
12296 is described in the previous section.
12297 This attribute exists as both an instance and class
12298 attribute so tests can use
12299 <filename>self.target.run(cmd)</filename> in instance
12300 methods instead of
12301 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12302 </para>
12303 </section>
12304 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012305
12306 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12307 <title>Installing Packages in the DUT Without the Package Manager</title>
12308
12309 <para>
12310 When a test requires a package built by BitBake, it is possible
12311 to install that package.
12312 Installing the package does not require a package manager be
12313 installed in the device under test (DUT).
12314 It does, however, require an SSH connection and the target must
12315 be using the <filename>sshcontrol</filename> class.
12316 <note>
12317 This method uses <filename>scp</filename> to copy files
12318 from the host to the target, which causes permissions and
12319 special attributes to be lost.
12320 </note>
12321 </para>
12322
12323 <para>
12324 A JSON file is used to define the packages needed by a test.
12325 This file must be in the same path as the file used to define
12326 the tests.
12327 Furthermore, the filename must map directly to the test
12328 module name with a <filename>.json</filename> extension.
12329 </para>
12330
12331 <para>
12332 The JSON file must include an object with the test name as
12333 keys of an object or an array.
12334 This object (or array of objects) uses the following data:
12335 <itemizedlist>
12336 <listitem><para>"pkg" - A mandatory string that is the
12337 name of the package to be installed.
12338 </para></listitem>
12339 <listitem><para>"rm" - An optional boolean, which defaults
12340 to "false", that specifies to remove the package after
12341 the test.
12342 </para></listitem>
12343 <listitem><para>"extract" - An optional boolean, which
12344 defaults to "false", that specifies if the package must
12345 be extracted from the package format.
12346 When set to "true", the package is not automatically
12347 installed into the DUT.
12348 </para></listitem>
12349 </itemizedlist>
12350 </para>
12351
12352 <para>
12353 Following is an example JSON file that handles test "foo"
12354 installing package "bar" and test "foobar" installing
12355 packages "foo" and "bar".
12356 Once the test is complete, the packages are removed from the
12357 DUT.
12358 <literallayout class='monospaced'>
12359 {
12360 "foo": {
12361 "pkg": "bar"
12362 },
12363 "foobar": [
12364 {
12365 "pkg": "foo",
12366 "rm": true
12367 },
12368 {
12369 "pkg": "bar",
12370 "rm": true
12371 }
12372 ]
12373 }
12374 </literallayout>
12375 </para>
12376 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012377 </section>
12378
Brad Bishop316dfdd2018-06-25 12:45:53 -040012379 <section id='usingpoky-debugging-tools-and-techniques'>
12380 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012381
12382 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012383 The exact method for debugging build failures depends on the nature
12384 of the problem and on the system's area from which the bug
12385 originates.
12386 Standard debugging practices such as comparison against the last
12387 known working version with examination of the changes and the
12388 re-application of steps to identify the one causing the problem are
12389 valid for the Yocto Project just as they are for any other system.
12390 Even though it is impossible to detail every possible potential
12391 failure, this section provides some general tips to aid in
12392 debugging given a variety of situations.
12393 <note><title>Tip</title>
12394 A useful feature for debugging is the error reporting tool.
12395 Configuring the Yocto Project to use this tool causes the
12396 OpenEmbedded build system to produce error reporting commands as
12397 part of the console output.
12398 You can enter the commands after the build completes to log
12399 error information into a common database, that can help you
12400 figure out what might be going wrong.
12401 For information on how to enable and use this feature, see the
12402 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12403 section.
12404 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012405 </para>
12406
12407 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012408 The following list shows the debugging topics in the remainder of
12409 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012410 <itemizedlist>
12411 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012412 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12413 describes how to find and view logs from tasks that
12414 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012415 </para></listitem>
12416 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012417 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12418 describes how to use the BitBake <filename>-e</filename>
12419 option to examine variable values after a recipe has been
12420 parsed.
12421 </para></listitem>
12422 <listitem><para>
12423 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12424 describes how to use the
12425 <filename>oe-pkgdata-util</filename> utility to query
12426 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12427 and display package-related information for built
12428 packages.
12429 </para></listitem>
12430 <listitem><para>
12431 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12432 describes how to use the BitBake <filename>-g</filename>
12433 option to display recipe dependency information used
12434 during the build.
12435 </para></listitem>
12436 <listitem><para>
12437 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12438 describes how to use the
12439 <filename>bitbake-dumpsig</filename> command in
12440 conjunction with key subdirectories in the
12441 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12442 to determine variable dependencies.
12443 </para></listitem>
12444 <listitem><para>
12445 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12446 describes how to use several BitBake options (e.g.
12447 <filename>-c</filename>, <filename>-C</filename>, and
12448 <filename>-f</filename>) to run specific tasks in the
12449 build chain.
12450 It can be useful to run tasks "out-of-order" when trying
12451 isolate build issues.
12452 </para></listitem>
12453 <listitem><para>
12454 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12455 describes how to use BitBake's <filename>-D</filename>
12456 debug output option to reveal more about what BitBake is
12457 doing during the build.
12458 </para></listitem>
12459 <listitem><para>
12460 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12461 describes how to use the BitBake <filename>-b</filename>
12462 option to build a recipe while ignoring dependencies.
12463 </para></listitem>
12464 <listitem><para>
12465 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12466 describes how to use the many recipe logging functions
12467 to produce debugging output and report errors and warnings.
12468 </para></listitem>
12469 <listitem><para>
12470 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12471 describes how to debug situations where the build consists
12472 of several parts that are run simultaneously and when the
12473 output or result of one part is not ready for use with a
12474 different part of the build that depends on that output.
12475 </para></listitem>
12476 <listitem><para>
12477 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12478 describes how to use GDB to allow you to examine running
12479 programs, which can help you fix problems.
12480 </para></listitem>
12481 <listitem><para>
12482 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12483 describes how to use GDB directly on target hardware for
12484 debugging.
12485 </para></listitem>
12486 <listitem><para>
12487 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12488 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012489 </para></listitem>
12490 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012491 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012492
Brad Bishop316dfdd2018-06-25 12:45:53 -040012493 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12494 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012495
12496 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012497 You can find the log for a task in the file
12498 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12499 For example, the log for the
12500 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12501 task of the QEMU minimal image for the x86 machine
12502 (<filename>qemux86</filename>) might be in
12503 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12504 To see the commands
12505 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12506 ran to generate a log, look at the corresponding
12507 <filename>run.do_</filename><replaceable>taskname</replaceable>
12508 file in the same directory.
12509 </para>
12510
12511 <para>
12512 <filename>log.do_</filename><replaceable>taskname</replaceable>
12513 and
12514 <filename>run.do_</filename><replaceable>taskname</replaceable>
12515 are actually symbolic links to
12516 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12517 and
12518 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12519 where <replaceable>pid</replaceable> is the PID the task had
12520 when it ran.
12521 The symlinks always point to the files corresponding to the most
12522 recent run.
12523 </para>
12524 </section>
12525
12526 <section id='dev-debugging-viewing-variable-values'>
12527 <title>Viewing Variable Values</title>
12528
12529 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040012530 Sometimes you need to know the value of a variable as a
12531 result of BitBake's parsing step.
12532 This could be because some unexpected behavior occurred
12533 in your project.
12534 Perhaps an attempt to
12535 <ulink url='&YOCTO_DOCS_BB_URL;#modifying-existing-variables'>modify a variable</ulink>
12536 did not work out as expected.
12537 </para>
12538
12539 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012540 BitBake's <filename>-e</filename> option is used to display
12541 variable values after parsing.
12542 The following command displays the variable values after the
12543 configuration files (i.e. <filename>local.conf</filename>,
12544 <filename>bblayers.conf</filename>,
12545 <filename>bitbake.conf</filename> and so forth) have been
12546 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012547 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012548 $ bitbake -e
12549 </literallayout>
12550 The following command displays variable values after a specific
12551 recipe has been parsed.
12552 The variables include those from the configuration as well:
12553 <literallayout class='monospaced'>
12554 $ bitbake -e recipename
12555 </literallayout>
12556 <note><para>
12557 Each recipe has its own private set of variables
12558 (datastore).
12559 Internally, after parsing the configuration, a copy of the
12560 resulting datastore is made prior to parsing each recipe.
12561 This copying implies that variables set in one recipe will
12562 not be visible to other recipes.</para>
12563
12564 <para>Likewise, each task within a recipe gets a private
12565 datastore based on the recipe datastore, which means that
12566 variables set within one task will not be visible to
12567 other tasks.</para>
12568 </note>
12569 </para>
12570
12571 <para>
12572 In the output of <filename>bitbake -e</filename>, each
12573 variable is preceded by a description of how the variable
12574 got its value, including temporary values that were later
12575 overriden.
12576 This description also includes variable flags (varflags) set on
12577 the variable.
12578 The output can be very helpful during debugging.
12579 </para>
12580
12581 <para>
12582 Variables that are exported to the environment are preceded by
12583 <filename>export</filename> in the output of
12584 <filename>bitbake -e</filename>.
12585 See the following example:
12586 <literallayout class='monospaced'>
12587 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12588 </literallayout>
12589 </para>
12590
12591 <para>
12592 In addition to variable values, the output of the
12593 <filename>bitbake -e</filename> and
12594 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12595 commands includes the following information:
12596 <itemizedlist>
12597 <listitem><para>
12598 The output starts with a tree listing all configuration
12599 files and classes included globally, recursively listing
12600 the files they include or inherit in turn.
12601 Much of the behavior of the OpenEmbedded build system
12602 (including the behavior of the
12603 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12604 is implemented in the
12605 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12606 class and the classes it inherits, rather than being
12607 built into BitBake itself.
12608 </para></listitem>
12609 <listitem><para>
12610 After the variable values, all functions appear in the
12611 output.
12612 For shell functions, variables referenced within the
12613 function body are expanded.
12614 If a function has been modified using overrides or
12615 using override-style operators like
12616 <filename>_append</filename> and
12617 <filename>_prepend</filename>, then the final assembled
12618 function body appears in the output.
12619 </para></listitem>
12620 </itemizedlist>
12621 </para>
12622 </section>
12623
12624 <section id='viewing-package-information-with-oe-pkgdata-util'>
12625 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12626
12627 <para>
12628 You can use the <filename>oe-pkgdata-util</filename>
12629 command-line utility to query
12630 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12631 and display various package-related information.
12632 When you use the utility, you must use it to view information
12633 on packages that have already been built.
12634 </para>
12635
12636 <para>
12637 Following are a few of the available
12638 <filename>oe-pkgdata-util</filename> subcommands.
12639 <note>
12640 You can use the standard * and ? globbing wildcards as part
12641 of package names and paths.
12642 </note>
12643 <itemizedlist>
12644 <listitem><para>
12645 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12646 Lists all packages that have been built, optionally
12647 limiting the match to packages that match
12648 <replaceable>pattern</replaceable>.
12649 </para></listitem>
12650 <listitem><para>
12651 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12652 Lists the files and directories contained in the given
12653 packages.
12654 <note>
12655 <para>
12656 A different way to view the contents of a package is
12657 to look at the
12658 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12659 directory of the recipe that generates the
12660 package.
12661 This directory is created by the
12662 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12663 task and has one subdirectory for each package the
12664 recipe generates, which contains the files stored in
12665 that package.</para>
12666 <para>
12667 If you want to inspect the
12668 <filename>${WORKDIR}/packages-split</filename>
12669 directory, make sure that
12670 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12671 is not enabled when you build the recipe.
12672 </para>
12673 </note>
12674 </para></listitem>
12675 <listitem><para>
12676 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12677 Lists the names of the packages that contain the given
12678 paths.
12679 For example, the following tells us that
12680 <filename>/usr/share/man/man1/make.1</filename>
12681 is contained in the <filename>make-doc</filename>
12682 package:
12683 <literallayout class='monospaced'>
12684 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12685 make-doc: /usr/share/man/man1/make.1
12686 </literallayout>
12687 </para></listitem>
12688 <listitem><para>
12689 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12690 Lists the name of the recipes that
12691 produce the given packages.
12692 </para></listitem>
12693 </itemizedlist>
12694 </para>
12695
12696 <para>
12697 For more information on the <filename>oe-pkgdata-util</filename>
12698 command, use the help facility:
12699 <literallayout class='monospaced'>
12700 $ oe-pkgdata-util &dash;&dash;help
12701 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
12702 </literallayout>
12703 </para>
12704 </section>
12705
12706 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
12707 <title>Viewing Dependencies Between Recipes and Tasks</title>
12708
12709 <para>
12710 Sometimes it can be hard to see why BitBake wants to build other
12711 recipes before the one you have specified.
12712 Dependency information can help you understand why a recipe is
12713 built.
12714 </para>
12715
12716 <para>
12717 To generate dependency information for a recipe, run the
12718 following command:
12719 <literallayout class='monospaced'>
12720 $ bitbake -g <replaceable>recipename</replaceable>
12721 </literallayout>
12722 This command writes the following files in the current
12723 directory:
12724 <itemizedlist>
12725 <listitem><para>
12726 <filename>pn-buildlist</filename>: A list of
12727 recipes/targets involved in building
12728 <replaceable>recipename</replaceable>.
12729 "Involved" here means that at least one task from the
12730 recipe needs to run when building
12731 <replaceable>recipename</replaceable> from scratch.
12732 Targets that are in
12733 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
12734 are not listed.
12735 </para></listitem>
12736 <listitem><para>
12737 <filename>task-depends.dot</filename>: A graph showing
12738 dependencies between tasks.
12739 </para></listitem>
12740 </itemizedlist>
12741 </para>
12742
12743 <para>
12744 The graphs are in
12745 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
12746 format and can be converted to images (e.g. using the
12747 <filename>dot</filename> tool from
12748 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
12749 <note><title>Notes</title>
12750 <itemizedlist>
12751 <listitem><para>
12752 DOT files use a plain text format.
12753 The graphs generated using the
12754 <filename>bitbake -g</filename> command are often so
12755 large as to be difficult to read without special
12756 pruning (e.g. with Bitbake's
12757 <filename>-I</filename> option) and processing.
12758 Despite the form and size of the graphs, the
12759 corresponding <filename>.dot</filename> files can
12760 still be possible to read and provide useful
12761 information.
12762 </para>
12763
12764 <para>As an example, the
12765 <filename>task-depends.dot</filename> file contains
12766 lines such as the following:
12767 <literallayout class='monospaced'>
12768 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
12769 </literallayout>
12770 The above example line reveals that the
12771 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
12772 task in <filename>libxslt</filename> depends on the
12773 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
12774 task in <filename>libxml2</filename>, which is a
12775 normal
12776 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
12777 dependency between the two recipes.
12778 </para></listitem>
12779 <listitem><para>
12780 For an example of how <filename>.dot</filename>
12781 files can be processed, see the
12782 <filename>scripts/contrib/graph-tool</filename>
12783 Python script, which finds and displays paths
12784 between graph nodes.
12785 </para></listitem>
12786 </itemizedlist>
12787 </note>
12788 </para>
12789
12790 <para>
12791 You can use a different method to view dependency information
12792 by using the following command:
12793 <literallayout class='monospaced'>
12794 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
12795 </literallayout>
12796 This command displays a GUI window from which you can view
12797 build-time and runtime dependencies for the recipes involved in
12798 building <replaceable>recipename</replaceable>.
12799 </para>
12800 </section>
12801
12802 <section id='dev-viewing-task-variable-dependencies'>
12803 <title>Viewing Task Variable Dependencies</title>
12804
12805 <para>
12806 As mentioned in the
12807 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
12808 section of the BitBake User Manual, BitBake tries to
12809 automatically determine what variables a task depends on so
12810 that it can rerun the task if any values of the variables
12811 change.
12812 This determination is usually reliable.
12813 However, if you do things like construct variable names at
12814 runtime, then you might have to manually declare dependencies
12815 on those variables using <filename>vardeps</filename> as
12816 described in the
12817 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
12818 section of the BitBake User Manual.
12819 </para>
12820
12821 <para>
12822 If you are unsure whether a variable dependency is being
12823 picked up automatically for a given task, you can list the
12824 variable dependencies BitBake has determined by doing the
12825 following:
12826 <orderedlist>
12827 <listitem><para>
12828 Build the recipe containing the task:
12829 <literallayout class='monospaced'>
12830 $ bitbake <replaceable>recipename</replaceable>
12831 </literallayout>
12832 </para></listitem>
12833 <listitem><para>
12834 Inside the
12835 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
12836 directory, find the signature data
12837 (<filename>sigdata</filename>) file that corresponds
12838 to the task.
12839 The <filename>sigdata</filename> files contain a pickled
12840 Python database of all the metadata that went into
12841 creating the input checksum for the task.
12842 As an example, for the
12843 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
12844 task of the <filename>db</filename> recipe, the
12845 <filename>sigdata</filename> file might be found in the
12846 following location:
12847 <literallayout class='monospaced'>
12848 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12849 </literallayout>
12850 For tasks that are accelerated through the shared state
12851 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
12852 cache, an additional <filename>siginfo</filename> file
12853 is written into
12854 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
12855 along with the cached task output.
12856 The <filename>siginfo</filename> files contain exactly
12857 the same information as <filename>sigdata</filename>
12858 files.
12859 </para></listitem>
12860 <listitem><para>
12861 Run <filename>bitbake-dumpsig</filename> on the
12862 <filename>sigdata</filename> or
12863 <filename>siginfo</filename> file.
12864 Here is an example:
12865 <literallayout class='monospaced'>
12866 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12867 </literallayout>
12868 In the output of the above command, you will find a
12869 line like the following, which lists all the (inferred)
12870 variable dependencies for the task.
12871 This list also includes indirect dependencies from
12872 variables depending on other variables, recursively.
12873 <literallayout class='monospaced'>
12874 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
12875 </literallayout>
12876 <note>
12877 Functions (e.g. <filename>base_do_fetch</filename>)
12878 also count as variable dependencies.
12879 These functions in turn depend on the variables they
12880 reference.
12881 </note>
12882 The output of <filename>bitbake-dumpsig</filename> also
12883 includes the value each variable had, a list of
12884 dependencies for each variable, and
12885 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
12886 information.
12887 </para></listitem>
12888 </orderedlist>
12889 </para>
12890
12891 <para>
12892 There is also a <filename>bitbake-diffsigs</filename> command
12893 for comparing two <filename>siginfo</filename> or
12894 <filename>sigdata</filename> files.
12895 This command can be helpful when trying to figure out what
12896 changed between two versions of a task.
12897 If you call <filename>bitbake-diffsigs</filename> with just one
12898 file, the command behaves like
12899 <filename>bitbake-dumpsig</filename>.
12900 </para>
12901
12902 <para>
12903 You can also use BitBake to dump out the signature construction
12904 information without executing tasks by using either of the
12905 following BitBake command-line options:
12906 <literallayout class='monospaced'>
12907 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
12908 -S <replaceable>SIGNATURE_HANDLER</replaceable>
12909 </literallayout>
12910 <note>
12911 Two common values for
12912 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
12913 "printdiff", which dump only the signature or compare the
12914 dumped signature with the cached one, respectively.
12915 </note>
12916 Using BitBake with either of these options causes BitBake to
12917 dump out <filename>sigdata</filename> files in the
12918 <filename>stamps</filename> directory for every task it would
12919 have executed instead of building the specified target package.
12920 </para>
12921 </section>
12922
12923 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
12924 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
12925
12926 <para>
12927 Seeing what metadata went into creating the input signature
12928 of a shared state (sstate) task can be a useful debugging
12929 aid.
12930 This information is available in signature information
12931 (<filename>siginfo</filename>) files in
12932 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
12933 For information on how to view and interpret information in
12934 <filename>siginfo</filename> files, see the
12935 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12936 section.
12937 </para>
12938
12939 <para>
12940 For conceptual information on shared state, see the
12941 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
12942 section in the Yocto Project Overview and Concepts Manual.
12943 </para>
12944 </section>
12945
12946 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
12947 <title>Invalidating Shared State to Force a Task to Run</title>
12948
12949 <para>
12950 The OpenEmbedded build system uses
12951 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
12952 and
12953 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
12954 cache to avoid unnecessarily rebuilding tasks.
12955 Collectively, this scheme is known as "shared state code."
12956 </para>
12957
12958 <para>
12959 As with all schemes, this one has some drawbacks.
12960 It is possible that you could make implicit changes to your
12961 code that the checksum calculations do not take into
12962 account.
12963 These implicit changes affect a task's output but do not
12964 trigger the shared state code into rebuilding a recipe.
12965 Consider an example during which a tool changes its output.
12966 Assume that the output of <filename>rpmdeps</filename>
12967 changes.
12968 The result of the change should be that all the
12969 <filename>package</filename> and
12970 <filename>package_write_rpm</filename> shared state cache
12971 items become invalid.
12972 However, because the change to the output is
12973 external to the code and therefore implicit,
12974 the associated shared state cache items do not become
12975 invalidated.
12976 In this case, the build process uses the cached items
12977 rather than running the task again.
12978 Obviously, these types of implicit changes can cause
12979 problems.
12980 </para>
12981
12982 <para>
12983 To avoid these problems during the build, you need to
12984 understand the effects of any changes you make.
12985 Realize that changes you make directly to a function
12986 are automatically factored into the checksum calculation.
12987 Thus, these explicit changes invalidate the associated
12988 area of shared state cache.
12989 However, you need to be aware of any implicit changes that
12990 are not obvious changes to the code and could affect
12991 the output of a given task.
12992 </para>
12993
12994 <para>
12995 When you identify an implicit change, you can easily
12996 take steps to invalidate the cache and force the tasks
12997 to run.
12998 The steps you can take are as simple as changing a
12999 function's comments in the source code.
13000 For example, to invalidate package shared state files,
13001 change the comment statements of
13002 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13003 or the comments of one of the functions it calls.
13004 Even though the change is purely cosmetic, it causes the
13005 checksum to be recalculated and forces the build system to
13006 run the task again.
13007 <note>
13008 For an example of a commit that makes a cosmetic
13009 change to invalidate shared state, see this
13010 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
13011 </note>
13012 </para>
13013 </section>
13014
13015 <section id='dev-debugging-taskrunning'>
13016 <title>Running Specific Tasks</title>
13017
13018 <para>
13019 Any given recipe consists of a set of tasks.
13020 The standard BitBake behavior in most cases is:
13021 <filename>do_fetch</filename>,
13022 <filename>do_unpack</filename>,
13023 <filename>do_patch</filename>,
13024 <filename>do_configure</filename>,
13025 <filename>do_compile</filename>,
13026 <filename>do_install</filename>,
13027 <filename>do_package</filename>,
13028 <filename>do_package_write_*</filename>, and
13029 <filename>do_build</filename>.
13030 The default task is <filename>do_build</filename> and any tasks
13031 on which it depends build first.
13032 Some tasks, such as <filename>do_devshell</filename>, are not
13033 part of the default build chain.
13034 If you wish to run a task that is not part of the default build
13035 chain, you can use the <filename>-c</filename> option in
13036 BitBake.
13037 Here is an example:
13038 <literallayout class='monospaced'>
13039 $ bitbake matchbox-desktop -c devshell
13040 </literallayout>
13041 </para>
13042
13043 <para>
13044 The <filename>-c</filename> option respects task dependencies,
13045 which means that all other tasks (including tasks from other
13046 recipes) that the specified task depends on will be run before
13047 the task.
13048 Even when you manually specify a task to run with
13049 <filename>-c</filename>, BitBake will only run the task if it
13050 considers it "out of date".
13051 See the
13052 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
13053 section in the Yocto Project Overview and Concepts Manual for
13054 how BitBake determines whether a task is "out of date".
13055 </para>
13056
13057 <para>
13058 If you want to force an up-to-date task to be rerun (e.g.
13059 because you made manual modifications to the recipe's
13060 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
13061 that you want to try out), then you can use the
13062 <filename>-f</filename> option.
13063 <note>
13064 The reason <filename>-f</filename> is never required when
13065 running the
13066 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
13067 task is because the
13068 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
13069 variable flag is already set for the task.
13070 </note>
13071 The following example shows one way you can use the
13072 <filename>-f</filename> option:
13073 <literallayout class='monospaced'>
13074 $ bitbake matchbox-desktop
13075 .
13076 .
13077 make some changes to the source code in the work directory
13078 .
13079 .
13080 $ bitbake matchbox-desktop -c compile -f
13081 $ bitbake matchbox-desktop
13082 </literallayout>
13083 </para>
13084
13085 <para>
13086 This sequence first builds and then recompiles
13087 <filename>matchbox-desktop</filename>.
13088 The last command reruns all tasks (basically the packaging
13089 tasks) after the compile.
13090 BitBake recognizes that the <filename>do_compile</filename>
13091 task was rerun and therefore understands that the other tasks
13092 also need to be run again.
13093 </para>
13094
13095 <para>
13096 Another, shorter way to rerun a task and all
13097 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
13098 that depend on it is to use the <filename>-C</filename>
13099 option.
13100 <note>
13101 This option is upper-cased and is separate from the
13102 <filename>-c</filename> option, which is lower-cased.
13103 </note>
13104 Using this option invalidates the given task and then runs the
13105 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
13106 task, which is the default task if no task is given, and the
13107 tasks on which it depends.
13108 You could replace the final two commands in the previous example
13109 with the following single command:
13110 <literallayout class='monospaced'>
13111 $ bitbake matchbox-desktop -C compile
13112 </literallayout>
13113 Internally, the <filename>-f</filename> and
13114 <filename>-C</filename> options work by tainting (modifying) the
13115 input checksum of the specified task.
13116 This tainting indirectly causes the task and its
13117 dependent tasks to be rerun through the normal task dependency
13118 mechanisms.
13119 <note>
13120 BitBake explicitly keeps track of which tasks have been
13121 tainted in this fashion, and will print warnings such as the
13122 following for builds involving such tasks:
13123 <literallayout class='monospaced'>
13124 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
13125 </literallayout>
13126 The purpose of the warning is to let you know that the work
13127 directory and build output might not be in the clean state
13128 they would be in for a "normal" build, depending on what
13129 actions you took.
13130 To get rid of such warnings, you can remove the work
13131 directory and rebuild the recipe, as follows:
13132 <literallayout class='monospaced'>
13133 $ bitbake matchbox-desktop -c clean
13134 $ bitbake matchbox-desktop
13135 </literallayout>
13136 </note>
13137 </para>
13138
13139 <para>
13140 You can view a list of tasks in a given package by running the
13141 <filename>do_listtasks</filename> task as follows:
13142 <literallayout class='monospaced'>
13143 $ bitbake matchbox-desktop -c listtasks
13144 </literallayout>
13145 The results appear as output to the console and are also in the
13146 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
13147 </para>
13148 </section>
13149
13150 <section id='dev-debugging-bitbake'>
13151 <title>General BitBake Problems</title>
13152
13153 <para>
13154 You can see debug output from BitBake by using the
13155 <filename>-D</filename> option.
13156 The debug output gives more information about what BitBake
13157 is doing and the reason behind it.
13158 Each <filename>-D</filename> option you use increases the
13159 logging level.
13160 The most common usage is <filename>-DDD</filename>.
13161 </para>
13162
13163 <para>
13164 The output from
13165 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
13166 can reveal why BitBake chose a certain version of a package or
13167 why BitBake picked a certain provider.
13168 This command could also help you in a situation where you think
13169 BitBake did something unexpected.
13170 </para>
13171 </section>
13172
13173 <section id='dev-debugging-buildfile'>
13174 <title>Building with No Dependencies</title>
13175
13176 <para>
13177 To build a specific recipe (<filename>.bb</filename> file),
13178 you can use the following command form:
13179 <literallayout class='monospaced'>
13180 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13181 </literallayout>
13182 This command form does not check for dependencies.
13183 Consequently, you should use it only when you know existing
13184 dependencies have been met.
13185 <note>
13186 You can also specify fragments of the filename.
13187 In this case, BitBake checks for a unique match.
13188 </note>
13189 </para>
13190 </section>
13191
13192 <section id='recipe-logging-mechanisms'>
13193 <title>Recipe Logging Mechanisms</title>
13194
13195 <para>
13196 The Yocto Project provides several logging functions for
13197 producing debugging output and reporting errors and warnings.
13198 For Python functions, the following logging functions exist.
13199 All of these functions log to
13200 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13201 and can also log to standard output (stdout) with the right
13202 settings:
13203 <itemizedlist>
13204 <listitem><para>
13205 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13206 Writes <replaceable>msg</replaceable> as is to the
13207 log while also logging to stdout.
13208 </para></listitem>
13209 <listitem><para>
13210 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13211 Writes "NOTE: <replaceable>msg</replaceable>" to the
13212 log.
13213 Also logs to stdout if BitBake is called with "-v".
13214 </para></listitem>
13215 <listitem><para>
13216 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13217 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13218 log.
13219 Also logs to stdout if the log level is greater than or
13220 equal to <replaceable>level</replaceable>.
13221 See the
13222 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13223 option in the BitBake User Manual for more information.
13224 </para></listitem>
13225 <listitem><para>
13226 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13227 Writes "WARNING: <replaceable>msg</replaceable>" to the
13228 log while also logging to stdout.
13229 </para></listitem>
13230 <listitem><para>
13231 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13232 Writes "ERROR: <replaceable>msg</replaceable>" to the
13233 log while also logging to standard out (stdout).
13234 <note>
13235 Calling this function does not cause the task to fail.
13236 </note>
13237 </para></listitem>
13238 <listitem><para>
13239 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13240 This logging function is similar to
13241 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13242 but also causes the calling task to fail.
13243 <note>
13244 <filename>bb.fatal()</filename> raises an exception,
13245 which means you do not need to put a "return"
13246 statement after the function.
13247 </note>
13248 </para></listitem>
13249 </itemizedlist>
13250 </para>
13251
13252 <para>
13253 The same logging functions are also available in shell
13254 functions, under the names
13255 <filename>bbplain</filename>, <filename>bbnote</filename>,
13256 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13257 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13258 The
13259 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13260 class implements these functions.
13261 See that class in the
13262 <filename>meta/classes</filename> folder of the
13263 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13264 for information.
13265 </para>
13266
13267 <section id='logging-with-python'>
13268 <title>Logging With Python</title>
13269
13270 <para>
13271 When creating recipes using Python and inserting code that
13272 handles build logs, keep in mind the goal is to have
13273 informative logs while keeping the console as "silent" as
13274 possible.
13275 Also, if you want status messages in the log, use the
13276 "debug" loglevel.
13277 </para>
13278
13279 <para>
13280 Following is an example written in Python.
13281 The code handles logging for a function that determines the
13282 number of tasks needed to be run.
13283 See the
13284 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13285 section for additional information:
13286 <literallayout class='monospaced'>
13287 python do_listtasks() {
13288 bb.debug(2, "Starting to figure out the task list")
13289 if noteworthy_condition:
13290 bb.note("There are 47 tasks to run")
13291 bb.debug(2, "Got to point xyz")
13292 if warning_trigger:
13293 bb.warn("Detected warning_trigger, this might be a problem later.")
13294 if recoverable_error:
13295 bb.error("Hit recoverable_error, you really need to fix this!")
13296 if fatal_error:
13297 bb.fatal("fatal_error detected, unable to print the task list")
13298 bb.plain("The tasks present are abc")
13299 bb.debug(2, "Finished figuring out the tasklist")
13300 }
13301 </literallayout>
13302 </para>
13303 </section>
13304
13305 <section id='logging-with-bash'>
13306 <title>Logging With Bash</title>
13307
13308 <para>
13309 When creating recipes using Bash and inserting code that
13310 handles build logs, you have the same goals - informative
13311 with minimal console output.
13312 The syntax you use for recipes written in Bash is similar
13313 to that of recipes written in Python described in the
13314 previous section.
13315 </para>
13316
13317 <para>
13318 Following is an example written in Bash.
13319 The code logs the progress of the <filename>do_my_function</filename> function.
13320 <literallayout class='monospaced'>
13321 do_my_function() {
13322 bbdebug 2 "Running do_my_function"
13323 if [ exceptional_condition ]; then
13324 bbnote "Hit exceptional_condition"
13325 fi
13326 bbdebug 2 "Got to point xyz"
13327 if [ warning_trigger ]; then
13328 bbwarn "Detected warning_trigger, this might cause a problem later."
13329 fi
13330 if [ recoverable_error ]; then
13331 bberror "Hit recoverable_error, correcting"
13332 fi
13333 if [ fatal_error ]; then
13334 bbfatal "fatal_error detected"
13335 fi
13336 bbdebug 2 "Completed do_my_function"
13337 }
13338 </literallayout>
13339 </para>
13340 </section>
13341 </section>
13342
13343 <section id='debugging-parallel-make-races'>
13344 <title>Debugging Parallel Make Races</title>
13345
13346 <para>
13347 A parallel <filename>make</filename> race occurs when the build
13348 consists of several parts that are run simultaneously and
13349 a situation occurs when the output or result of one
13350 part is not ready for use with a different part of the build
13351 that depends on that output.
13352 Parallel make races are annoying and can sometimes be difficult
13353 to reproduce and fix.
13354 However, some simple tips and tricks exist that can help
13355 you debug and fix them.
13356 This section presents a real-world example of an error
13357 encountered on the Yocto Project autobuilder and the process
13358 used to fix it.
13359 <note>
13360 If you cannot properly fix a <filename>make</filename> race
13361 condition, you can work around it by clearing either the
13362 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13363 or
13364 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13365 variables.
13366 </note>
13367 </para>
13368
13369 <section id='the-failure'>
13370 <title>The Failure</title>
13371
13372 <para>
13373 For this example, assume that you are building an image that
13374 depends on the "neard" package.
13375 And, during the build, BitBake runs into problems and
13376 creates the following output.
13377 <note>
13378 This example log file has longer lines artificially
13379 broken to make the listing easier to read.
13380 </note>
13381 If you examine the output or the log file, you see the
13382 failure during <filename>make</filename>:
13383 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013384 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13385 | DEBUG: Executing shell function do_compile
13386 | NOTE: make -j 16
13387 | make --no-print-directory all-am
13388 | /bin/mkdir -p include/near
13389 | /bin/mkdir -p include/near
13390 | /bin/mkdir -p include/near
13391 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13392 0.14-r0/neard-0.14/include/types.h include/near/types.h
13393 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13394 0.14-r0/neard-0.14/include/log.h include/near/log.h
13395 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13396 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13397 | /bin/mkdir -p include/near
13398 | /bin/mkdir -p include/near
13399 | /bin/mkdir -p include/near
13400 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13401 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13402 | /bin/mkdir -p include/near
13403 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13404 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13405 | /bin/mkdir -p include/near
13406 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13407 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13408 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13409 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13410 | /bin/mkdir -p include/near
13411 | /bin/mkdir -p include/near
13412 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13413 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13414 | /bin/mkdir -p include/near
13415 | /bin/mkdir -p include/near
13416 | /bin/mkdir -p include/near
13417 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13418 0.14-r0/neard-0.14/include/device.h include/near/device.h
13419 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13420 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13421 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13422 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13423 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13424 0.14-r0/neard-0.14/include/version.h include/near/version.h
13425 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13426 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13427 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13428 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13429 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13430 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13431 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13432 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13433 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13434 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13435 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13436 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13437 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13438 -o tools/snep-send.o tools/snep-send.c
13439 | In file included from tools/snep-send.c:16:0:
13440 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13441 | #include &lt;near/dbus.h&gt;
13442 | ^
13443 | compilation terminated.
13444 | make[1]: *** [tools/snep-send.o] Error 1
13445 | make[1]: *** Waiting for unfinished jobs....
13446 | make: *** [all] Error 2
13447 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013448 </literallayout>
13449 </para>
13450 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013451
Brad Bishop316dfdd2018-06-25 12:45:53 -040013452 <section id='reproducing-the-error'>
13453 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013454
Brad Bishop316dfdd2018-06-25 12:45:53 -040013455 <para>
13456 Because race conditions are intermittent, they do not
13457 manifest themselves every time you do the build.
13458 In fact, most times the build will complete without problems
13459 even though the potential race condition exists.
13460 Thus, once the error surfaces, you need a way to reproduce
13461 it.
13462 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013463
Brad Bishop316dfdd2018-06-25 12:45:53 -040013464 <para>
13465 In this example, compiling the "neard" package is causing
13466 the problem.
13467 So the first thing to do is build "neard" locally.
13468 Before you start the build, set the
13469 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13470 variable in your <filename>local.conf</filename> file to
13471 a high number (e.g. "-j 20").
13472 Using a high value for <filename>PARALLEL_MAKE</filename>
13473 increases the chances of the race condition showing up:
13474 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013475 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013476 </literallayout>
13477 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013478
Brad Bishop316dfdd2018-06-25 12:45:53 -040013479 <para>
13480 Once the local build for "neard" completes, start a
13481 <filename>devshell</filename> build:
13482 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013483 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013484 </literallayout>
13485 For information on how to use a
13486 <filename>devshell</filename>, see the
13487 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13488 section.
13489 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013490
Brad Bishop316dfdd2018-06-25 12:45:53 -040013491 <para>
13492 In the <filename>devshell</filename>, do the following:
13493 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013494 $ make clean
13495 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013496 </literallayout>
13497 The <filename>devshell</filename> commands cause the failure
13498 to clearly be visible.
13499 In this case, a missing dependency exists for the "neard"
13500 Makefile target.
13501 Here is some abbreviated, sample output with the
13502 missing dependency clearly visible at the end:
13503 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013504 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13505 .
13506 .
13507 .
13508 tools/snep-send.c
13509 In file included from tools/snep-send.c:16:0:
13510 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13511 #include &lt;near/dbus.h&gt;
13512 ^
13513 compilation terminated.
13514 make: *** [tools/snep-send.o] Error 1
13515 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013516 </literallayout>
13517 </para>
13518 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013519
Brad Bishop316dfdd2018-06-25 12:45:53 -040013520 <section id='creating-a-patch-for-the-fix'>
13521 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013522
Brad Bishop316dfdd2018-06-25 12:45:53 -040013523 <para>
13524 Because there is a missing dependency for the Makefile
13525 target, you need to patch the
13526 <filename>Makefile.am</filename> file, which is generated
13527 from <filename>Makefile.in</filename>.
13528 You can use Quilt to create the patch:
13529 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013530 $ quilt new parallelmake.patch
13531 Patch patches/parallelmake.patch is now on top
13532 $ quilt add Makefile.am
13533 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013534 </literallayout>
13535 For more information on using Quilt, see the
13536 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13537 section.
13538 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013539
Brad Bishop316dfdd2018-06-25 12:45:53 -040013540 <para>
13541 At this point you need to make the edits to
13542 <filename>Makefile.am</filename> to add the missing
13543 dependency.
13544 For our example, you have to add the following line
13545 to the file:
13546 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013547 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013548 </literallayout>
13549 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013550
Brad Bishop316dfdd2018-06-25 12:45:53 -040013551 <para>
13552 Once you have edited the file, use the
13553 <filename>refresh</filename> command to create the patch:
13554 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013555 $ quilt refresh
13556 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013557 </literallayout>
13558 Once the patch file exists, you need to add it back to the
13559 originating recipe folder.
13560 Here is an example assuming a top-level
13561 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13562 named <filename>poky</filename>:
13563 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013564 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013565 </literallayout>
13566 The final thing you need to do to implement the fix in the
13567 build is to update the "neard" recipe (i.e.
13568 <filename>neard-0.14.bb</filename>) so that the
13569 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13570 statement includes the patch file.
13571 The recipe file is in the folder above the patch.
13572 Here is what the edited <filename>SRC_URI</filename>
13573 statement would look like:
13574 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013575 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13576 file://neard.in \
13577 file://neard.service.in \
13578 file://parallelmake.patch \
13579 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013580 </literallayout>
13581 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013582
Brad Bishop316dfdd2018-06-25 12:45:53 -040013583 <para>
13584 With the patch complete and moved to the correct folder and
13585 the <filename>SRC_URI</filename> statement updated, you can
13586 exit the <filename>devshell</filename>:
13587 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013588 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013589 </literallayout>
13590 </para>
13591 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013592
Brad Bishop316dfdd2018-06-25 12:45:53 -040013593 <section id='testing-the-build'>
13594 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013595
Brad Bishop316dfdd2018-06-25 12:45:53 -040013596 <para>
13597 With everything in place, you can get back to trying the
13598 build again locally:
13599 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013600 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013601 </literallayout>
13602 This build should succeed.
13603 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013604
Brad Bishop316dfdd2018-06-25 12:45:53 -040013605 <para>
13606 Now you can open up a <filename>devshell</filename> again
13607 and repeat the clean and make operations as follows:
13608 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013609 $ bitbake neard -c devshell
13610 $ make clean
13611 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013612 </literallayout>
13613 The build should work without issue.
13614 </para>
13615
13616 <para>
13617 As with all solved problems, if they originated upstream,
13618 you need to submit the fix for the recipe in OE-Core and
13619 upstream so that the problem is taken care of at its
13620 source.
13621 See the
13622 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13623 section for more information.
13624 </para>
13625 </section>
13626 </section>
13627
13628 <section id="platdev-gdb-remotedebug">
13629 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13630
13631 <para>
13632 GDB allows you to examine running programs, which in turn helps
13633 you to understand and fix problems.
13634 It also allows you to perform post-mortem style analysis of
13635 program crashes.
13636 GDB is available as a package within the Yocto Project and is
13637 installed in SDK images by default.
13638 See the
13639 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13640 chapter in the Yocto Project Reference Manual for a description of
13641 these images.
13642 You can find information on GDB at
13643 <ulink url="http://sourceware.org/gdb/"/>.
13644 <note><title>Tip</title>
13645 For best results, install debug (<filename>-dbg</filename>)
13646 packages for the applications you are going to debug.
13647 Doing so makes extra debug symbols available that give you
13648 more meaningful output.
13649 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013650 </para>
13651
13652 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013653 Sometimes, due to memory or disk space constraints, it is not
13654 possible to use GDB directly on the remote target to debug
13655 applications.
13656 These constraints arise because GDB needs to load the debugging
13657 information and the binaries of the process being debugged.
13658 Additionally, GDB needs to perform many computations to locate
13659 information such as function names, variable names and values,
13660 stack traces and so forth - even before starting the debugging
13661 process.
13662 These extra computations place more load on the target system
13663 and can alter the characteristics of the program being debugged.
13664 </para>
13665
13666 <para>
13667 To help get past the previously mentioned constraints, you can
13668 use gdbserver, which runs on the remote target and does not
13669 load any debugging information from the debugged process.
13670 Instead, a GDB instance processes the debugging information that
13671 is run on a remote computer - the host GDB.
13672 The host GDB then sends control commands to gdbserver to make
13673 it stop or start the debugged program, as well as read or write
13674 memory regions of that debugged program.
13675 All the debugging information loaded and processed as well
13676 as all the heavy debugging is done by the host GDB.
13677 Offloading these processes gives the gdbserver running on the
13678 target a chance to remain small and fast.
13679 </para>
13680
13681 <para>
13682 Because the host GDB is responsible for loading the debugging
13683 information and for doing the necessary processing to make
13684 actual debugging happen, you have to make sure the host can
13685 access the unstripped binaries complete with their debugging
13686 information and also be sure the target is compiled with no
13687 optimizations.
13688 The host GDB must also have local access to all the libraries
13689 used by the debugged program.
13690 Because gdbserver does not need any local debugging information,
13691 the binaries on the remote target can remain stripped.
13692 However, the binaries must also be compiled without optimization
13693 so they match the host's binaries.
13694 </para>
13695
13696 <para>
13697 To remain consistent with GDB documentation and terminology,
13698 the binary being debugged on the remote target machine is
13699 referred to as the "inferior" binary.
13700 For documentation on GDB see the
13701 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
13702 </para>
13703
13704 <para>
13705 The following steps show you how to debug using the GNU project
13706 debugger.
13707 <orderedlist>
13708 <listitem><para>
13709 <emphasis>Configure your build system to construct the
13710 companion debug filesystem:</emphasis></para>
13711
13712 <para>In your <filename>local.conf</filename> file, set
13713 the following:
13714 <literallayout class='monospaced'>
13715 IMAGE_GEN_DEBUGFS = "1"
13716 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
13717 </literallayout>
13718 These options cause the OpenEmbedded build system
13719 to generate a special companion filesystem fragment,
13720 which contains the matching source and debug symbols to
13721 your deployable filesystem.
13722 The build system does this by looking at what is in the
13723 deployed filesystem, and pulling the corresponding
13724 <filename>-dbg</filename> packages.</para>
13725
13726 <para>The companion debug filesystem is not a complete
13727 filesystem, but only contains the debug fragments.
13728 This filesystem must be combined with the full filesystem
13729 for debugging.
13730 Subsequent steps in this procedure show how to combine
13731 the partial filesystem with the full filesystem.
13732 </para></listitem>
13733 <listitem><para>
13734 <emphasis>Configure the system to include gdbserver in
13735 the target filesystem:</emphasis></para>
13736
13737 <para>Make the following addition in either your
13738 <filename>local.conf</filename> file or in an image
13739 recipe:
13740 <literallayout class='monospaced'>
13741 IMAGE_INSTALL_append = “ gdbserver"
13742 </literallayout>
13743 The change makes sure the <filename>gdbserver</filename>
13744 package is included.
13745 </para></listitem>
13746 <listitem><para>
13747 <emphasis>Build the environment:</emphasis></para>
13748
13749 <para>Use the following command to construct the image
13750 and the companion Debug Filesystem:
13751 <literallayout class='monospaced'>
13752 $ bitbake <replaceable>image</replaceable>
13753 </literallayout>
13754 Build the cross GDB component and make it available
13755 for debugging.
13756 Build the SDK that matches the image.
13757 Building the SDK is best for a production build
13758 that can be used later for debugging, especially
13759 during long term maintenance:
13760 <literallayout class='monospaced'>
13761 $ bitbake -c populate_sdk <replaceable>image</replaceable>
13762 </literallayout></para>
13763
13764 <para>Alternatively, you can build the minimal
13765 toolchain components that match the target.
13766 Doing so creates a smaller than typical SDK and only
13767 contains a minimal set of components with which to
13768 build simple test applications, as well as run the
13769 debugger:
13770 <literallayout class='monospaced'>
13771 $ bitbake meta-toolchain
13772 </literallayout></para>
13773
13774 <para>A final method is to build Gdb itself within
13775 the build system:
13776 <literallayout class='monospaced'>
13777 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
13778 </literallayout>
13779 Doing so produces a temporary copy of
13780 <filename>cross-gdb</filename> you can use for
13781 debugging during development.
13782 While this is the quickest approach, the two previous
13783 methods in this step are better when considering
13784 long-term maintenance strategies.
13785 <note>
13786 If you run
13787 <filename>bitbake gdb-cross</filename>, the
13788 OpenEmbedded build system suggests the actual
13789 image (e.g. <filename>gdb-cross-i586</filename>).
13790 The suggestion is usually the actual name you want
13791 to use.
13792 </note>
13793 </para></listitem>
13794 <listitem><para>
13795 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
13796
13797 <para>Run the following commands to set up the
13798 <filename>debugfs</filename>:
13799 <literallayout class='monospaced'>
13800 $ mkdir debugfs
13801 $ cd debugfs
13802 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
13803 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
13804 </literallayout>
13805 </para></listitem>
13806 <listitem><para>
13807 <emphasis>Set up GDB</emphasis></para>
13808
13809 <para>Install the SDK (if you built one) and then
13810 source the correct environment file.
13811 Sourcing the environment file puts the SDK in your
13812 <filename>PATH</filename> environment variable.</para>
13813
13814 <para>If you are using the build system, Gdb is
13815 located in
13816 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
13817 </para></listitem>
13818 <listitem><para>
13819 <emphasis>Boot the target:</emphasis></para>
13820
13821 <para>For information on how to run QEMU, see the
13822 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
13823 <note>
13824 Be sure to verify that your host can access the
13825 target via TCP.
13826 </note>
13827 </para></listitem>
13828 <listitem><para>
13829 <emphasis>Debug a program:</emphasis></para>
13830
13831 <para>Debugging a program involves running gdbserver
13832 on the target and then running Gdb on the host.
13833 The example in this step debugs
13834 <filename>gzip</filename>:
13835 <literallayout class='monospaced'>
13836 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
13837 </literallayout>
13838 For additional gdbserver options, see the
13839 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
13840 </para>
13841
13842 <para>After running gdbserver on the target, you need
13843 to run Gdb on the host and configure it and connect to
13844 the target.
13845 Use these commands:
13846 <literallayout class='monospaced'>
13847 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
13848 $ <replaceable>arch</replaceable>-gdb
13849
13850 (gdb) set sysroot debugfs
13851 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
13852 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
13853 </literallayout>
13854 At this point, everything should automatically load
13855 (i.e. matching binaries, symbols and headers).
13856 <note>
13857 The Gdb <filename>set</filename> commands in the
13858 previous example can be placed into the users
13859 <filename>~/.gdbinit</filename> file.
13860 Upon starting, Gdb automatically runs whatever
13861 commands are in that file.
13862 </note>
13863 </para></listitem>
13864 <listitem><para>
13865 <emphasis>Deploying without a full image
13866 rebuild:</emphasis></para>
13867
13868 <para>In many cases, during development you want a
13869 quick method to deploy a new binary to the target and
13870 debug it, without waiting for a full image build.
13871 </para>
13872
13873 <para>One approach to solving this situation is to
13874 just build the component you want to debug.
13875 Once you have built the component, copy the
13876 executable directly to both the target and the
13877 host <filename>debugfs</filename>.</para>
13878
13879 <para>If the binary is processed through the debug
13880 splitting in OpenEmbedded, you should also
13881 copy the debug items (i.e. <filename>.debug</filename>
13882 contents and corresponding
13883 <filename>/usr/src/debug</filename> files)
13884 from the work directory.
13885 Here is an example:
13886 <literallayout class='monospaced'>
13887 $ bitbake bash
13888 $ bitbake -c devshell bash
13889 $ cd ..
13890 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
13891 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
13892 </literallayout>
13893 </para></listitem>
13894 </orderedlist>
13895 </para>
13896 </section>
13897
13898 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
13899 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
13900
13901 <para>
13902 The previous section addressed using GDB remotely for debugging
13903 purposes, which is the most usual case due to the inherent
13904 hardware limitations on many embedded devices.
13905 However, debugging in the target hardware itself is also
13906 possible with more powerful devices.
13907 This section describes what you need to do in order to support
13908 using GDB to debug on the target hardware.
13909 </para>
13910
13911 <para>
13912 To support this kind of debugging, you need do the following:
13913 <itemizedlist>
13914 <listitem><para>
13915 Ensure that GDB is on the target.
13916 You can do this by adding "gdb" to
13917 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
13918 <literallayout class='monospaced'>
13919 IMAGE_INSTALL_append = " gdb"
13920 </literallayout>
13921 Alternatively, you can add "tools-debug" to
13922 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
13923 <literallayout class='monospaced'>
13924 IMAGE_FEATURES_append = " tools-debug"
13925 </literallayout>
13926 </para></listitem>
13927 <listitem><para>
13928 Ensure that debug symbols are present.
13929 You can make sure these symbols are present by
13930 installing <filename>-dbg</filename>:
13931 <literallayout class='monospaced'>
13932 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
13933 </literallayout>
13934 Alternatively, you can do the following to include all
13935 the debug symbols:
13936 <literallayout class='monospaced'>
13937 IMAGE_FEATURES_append = " dbg-pkgs"
13938 </literallayout>
13939 </para></listitem>
13940 </itemizedlist>
13941 <note>
13942 To improve the debug information accuracy, you can reduce
13943 the level of optimization used by the compiler.
13944 For example, when adding the following line to your
13945 <filename>local.conf</filename> file, you will reduce
13946 optimization from
13947 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
13948 of "-O2" to
13949 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
13950 of "-O -fno-omit-frame-pointer":
13951 <literallayout class='monospaced'>
13952 DEBUG_BUILD = "1"
13953 </literallayout>
13954 Consider that this will reduce the application's performance
13955 and is recommended only for debugging purposes.
13956 </note>
13957 </para>
13958 </section>
13959
13960 <section id='dev-other-debugging-others'>
13961 <title>Other Debugging Tips</title>
13962
13963 <para>
13964 Here are some other tips that you might find useful:
13965 <itemizedlist>
13966 <listitem><para>
13967 When adding new packages, it is worth watching for
13968 undesirable items making their way into compiler command
13969 lines.
13970 For example, you do not want references to local system
13971 files like
13972 <filename>/usr/lib/</filename> or
13973 <filename>/usr/include/</filename>.
13974 </para></listitem>
13975 <listitem><para>
13976 If you want to remove the <filename>psplash</filename>
13977 boot splashscreen,
13978 add <filename>psplash=false</filename> to the kernel
13979 command line.
13980 Doing so prevents <filename>psplash</filename> from
13981 loading and thus allows you to see the console.
13982 It is also possible to switch out of the splashscreen by
13983 switching the virtual console (e.g. Fn+Left or Fn+Right
13984 on a Zaurus).
13985 </para></listitem>
13986 <listitem><para>
13987 Removing
13988 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
13989 (usually <filename>tmp/</filename>, within the
13990 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
13991 can often fix temporary build issues.
13992 Removing <filename>TMPDIR</filename> is usually a
13993 relatively cheap operation, because task output will be
13994 cached in
13995 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13996 (usually <filename>sstate-cache/</filename>, which is
13997 also in the Build Directory).
13998 <note>
13999 Removing <filename>TMPDIR</filename> might be a
14000 workaround rather than a fix.
14001 Consequently, trying to determine the underlying
14002 cause of an issue before removing the directory is
14003 a good idea.
14004 </note>
14005 </para></listitem>
14006 <listitem><para>
14007 Understanding how a feature is used in practice within
14008 existing recipes can be very helpful.
14009 It is recommended that you configure some method that
14010 allows you to quickly search through files.</para>
14011
14012 <para>Using GNU Grep, you can use the following shell
14013 function to recursively search through common
14014 recipe-related files, skipping binary files,
14015 <filename>.git</filename> directories, and the
14016 Build Directory (assuming its name starts with
14017 "build"):
14018 <literallayout class='monospaced'>
14019 g() {
14020 grep -Ir \
14021 --exclude-dir=.git \
14022 --exclude-dir='build*' \
14023 --include='*.bb*' \
14024 --include='*.inc*' \
14025 --include='*.conf*' \
14026 --include='*.py*' \
14027 "$@"
14028 }
14029 </literallayout>
14030 Following are some usage examples:
14031 <literallayout class='monospaced'>
14032 $ g FOO # Search recursively for "FOO"
14033 $ g -i foo # Search recursively for "foo", ignoring case
14034 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
14035 </literallayout>
14036 If figuring out how some feature works requires a lot of
14037 searching, it might indicate that the documentation
14038 should be extended or improved.
14039 In such cases, consider filing a documentation bug using
14040 the Yocto Project implementation of
14041 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
14042 For information on how to submit a bug against
14043 the Yocto Project, see the Yocto Project Bugzilla
14044 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
14045 and the
14046 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
14047 section.
14048 <note>
14049 The manuals might not be the right place to document
14050 variables that are purely internal and have a
14051 limited scope (e.g. internal variables used to
14052 implement a single <filename>.bbclass</filename>
14053 file).
14054 </note>
14055 </para></listitem>
14056 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014057 </para>
14058 </section>
14059 </section>
14060
Brad Bishop316dfdd2018-06-25 12:45:53 -040014061 <section id='making-changes-to-the-yocto-project'>
14062 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014063
14064 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014065 Because the Yocto Project is an open-source, community-based
14066 project, you can effect changes to the project.
14067 This section presents procedures that show you how to submit
14068 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014069 </para>
14070
Brad Bishop316dfdd2018-06-25 12:45:53 -040014071 <section id='submitting-a-defect-against-the-yocto-project'>
14072 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014073
14074 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014075 Use the Yocto Project implementation of
14076 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
14077 to submit a defect (bug) against the Yocto Project.
14078 For additional information on this implementation of Bugzilla see the
14079 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
14080 section in the Yocto Project Reference Manual.
14081 For more detail on any of the following steps, see the Yocto Project
14082 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014083 </para>
14084
14085 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014086 Use the following general steps to submit a bug"
14087
14088 <orderedlist>
14089 <listitem><para>
14090 Open the Yocto Project implementation of
14091 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
14092 </para></listitem>
14093 <listitem><para>
14094 Click "File a Bug" to enter a new bug.
14095 </para></listitem>
14096 <listitem><para>
14097 Choose the appropriate "Classification", "Product", and
14098 "Component" for which the bug was found.
14099 Bugs for the Yocto Project fall into one of several
14100 classifications, which in turn break down into several
14101 products and components.
14102 For example, for a bug against the
14103 <filename>meta-intel</filename> layer, you would choose
14104 "Build System, Metadata &amp; Runtime", "BSPs", and
14105 "bsps-meta-intel", respectively.
14106 </para></listitem>
14107 <listitem><para>
14108 Choose the "Version" of the Yocto Project for which you found
14109 the bug (e.g. &DISTRO;).
14110 </para></listitem>
14111 <listitem><para>
14112 Determine and select the "Severity" of the bug.
14113 The severity indicates how the bug impacted your work.
14114 </para></listitem>
14115 <listitem><para>
14116 Choose the "Hardware" that the bug impacts.
14117 </para></listitem>
14118 <listitem><para>
14119 Choose the "Architecture" that the bug impacts.
14120 </para></listitem>
14121 <listitem><para>
14122 Choose a "Documentation change" item for the bug.
14123 Fixing a bug might or might not affect the Yocto Project
14124 documentation.
14125 If you are unsure of the impact to the documentation, select
14126 "Don't Know".
14127 </para></listitem>
14128 <listitem><para>
14129 Provide a brief "Summary" of the bug.
14130 Try to limit your summary to just a line or two and be sure
14131 to capture the essence of the bug.
14132 </para></listitem>
14133 <listitem><para>
14134 Provide a detailed "Description" of the bug.
14135 You should provide as much detail as you can about the context,
14136 behavior, output, and so forth that surrounds the bug.
14137 You can even attach supporting files for output from logs by
14138 using the "Add an attachment" button.
14139 </para></listitem>
14140 <listitem><para>
14141 Click the "Submit Bug" button submit the bug.
14142 A new Bugzilla number is assigned to the bug and the defect
14143 is logged in the bug tracking system.
14144 </para></listitem>
14145 </orderedlist>
14146 Once you file a bug, the bug is processed by the Yocto Project Bug
14147 Triage Team and further details concerning the bug are assigned
14148 (e.g. priority and owner).
14149 You are the "Submitter" of the bug and any further categorization,
14150 progress, or comments on the bug result in Bugzilla sending you an
14151 automated email concerning the particular change or progress to the
14152 bug.
14153 </para>
14154 </section>
14155
14156 <section id='how-to-submit-a-change'>
14157 <title>Submitting a Change to the Yocto Project</title>
14158
14159 <para>
14160 Contributions to the Yocto Project and OpenEmbedded are very welcome.
14161 Because the system is extremely configurable and flexible, we recognize
14162 that developers will want to extend, configure or optimize it for
14163 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014164 </para>
14165
14166 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014167 The Yocto Project uses a mailing list and a patch-based workflow
14168 that is similar to the Linux kernel but contains important
14169 differences.
14170 In general, a mailing list exists through which you can submit
14171 patches.
14172 You should send patches to the appropriate mailing list so that they
14173 can be reviewed and merged by the appropriate maintainer.
14174 The specific mailing list you need to use depends on the
14175 location of the code you are changing.
14176 Each component (e.g. layer) should have a
14177 <filename>README</filename> file that indicates where to send
14178 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014179 </para>
14180
14181 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014182 You can send the patch to the mailing list using whichever approach
14183 you feel comfortable with to generate the patch.
14184 Once sent, the patch is usually reviewed by the community at large.
14185 If somebody has concerns with the patch, they will usually voice
14186 their concern over the mailing list.
14187 If a patch does not receive any negative reviews, the maintainer of
14188 the affected layer typically takes the patch, tests it, and then
14189 based on successful testing, merges the patch.
14190 </para>
14191
14192 <para id='figuring-out-the-mailing-list-to-use'>
14193 The "poky" repository, which is the Yocto Project's reference build
14194 environment, is a hybrid repository that contains several
14195 individual pieces (e.g. BitBake, Metadata, documentation,
14196 and so forth) built using the combo-layer tool.
14197 The upstream location used for submitting changes varies by
14198 component:
14199 <itemizedlist>
14200 <listitem><para>
14201 <emphasis>Core Metadata:</emphasis>
14202 Send your patch to the
14203 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14204 mailing list. For example, a change to anything under
14205 the <filename>meta</filename> or
14206 <filename>scripts</filename> directories should be sent
14207 to this mailing list.
14208 </para></listitem>
14209 <listitem><para>
14210 <emphasis>BitBake:</emphasis>
14211 For changes to BitBake (i.e. anything under the
14212 <filename>bitbake</filename> directory), send your patch
14213 to the
14214 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14215 mailing list.
14216 </para></listitem>
14217 <listitem><para>
14218 <emphasis>"meta-*" trees:</emphasis>
14219 These trees contain Metadata.
14220 Use the
14221 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14222 mailing list.
14223 </para></listitem>
14224 </itemizedlist>
14225 </para>
14226
14227 <para>
14228 For changes to other layers hosted in the Yocto Project source
14229 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14230 and the Yocto Project documentation, use the
14231 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14232 general mailing list.
14233 <note>
14234 Sometimes a layer's documentation specifies to use a
14235 particular mailing list.
14236 If so, use that list.
14237 </note>
14238 For additional recipes that do not fit into the core Metadata, you
14239 should determine which layer the recipe should go into and submit
14240 the change in the manner recommended by the documentation (e.g.
14241 the <filename>README</filename> file) supplied with the layer.
14242 If in doubt, please ask on the Yocto general mailing list or on
14243 the openembedded-devel mailing list.
14244 </para>
14245
14246 <para>
14247 You can also push a change upstream and request a maintainer to
14248 pull the change into the component's upstream repository.
14249 You do this by pushing to a contribution repository that is upstream.
14250 See the
14251 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14252 section in the Yocto Project Overview and Concepts Manual for additional
14253 concepts on working in the Yocto Project development environment.
14254 </para>
14255
14256 <para>
14257 Two commonly used testing repositories exist for
14258 OpenEmbedded-Core:
14259 <itemizedlist>
14260 <listitem><para>
14261 <emphasis>"ross/mut" branch:</emphasis>
14262 The "mut" (master-under-test) tree
14263 exists in the <filename>poky-contrib</filename> repository
14264 in the
14265 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14266 </para></listitem>
14267 <listitem><para>
14268 <emphasis>"master-next" branch:</emphasis>
14269 This branch is part of the main
14270 "poky" repository in the Yocto Project source repositories.
14271 </para></listitem>
14272 </itemizedlist>
14273 Maintainers use these branches to test submissions prior to merging
14274 patches.
14275 Thus, you can get an idea of the status of a patch based on
14276 whether the patch has been merged into one of these branches.
14277 <note>
14278 This system is imperfect and changes can sometimes get lost in the
14279 flow.
14280 Asking about the status of a patch or change is reasonable if the
14281 change has been idle for a while with no feedback.
14282 The Yocto Project does have plans to use
14283 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14284 to track the status of patches and also to automatically preview
14285 patches.
14286 </note>
14287 </para>
14288
14289 <para>
14290 The following sections provide procedures for submitting a change.
14291 </para>
14292
14293 <section id='pushing-a-change-upstream'>
14294 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14295
14296 <para>
14297 Follow this procedure to push a change to an upstream "contrib"
14298 Git repository:
14299 <note>
14300 You can find general Git information on how to push a change
14301 upstream in the
14302 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14303 </note>
14304 <orderedlist>
14305 <listitem><para>
14306 <emphasis>Make Your Changes Locally:</emphasis>
14307 Make your changes in your local Git repository.
14308 You should make small, controlled, isolated changes.
14309 Keeping changes small and isolated aids review,
14310 makes merging/rebasing easier and keeps the change
14311 history clean should anyone need to refer to it in
14312 future.
14313 </para></listitem>
14314 <listitem><para>
14315 <emphasis>Stage Your Changes:</emphasis>
14316 Stage your changes by using the <filename>git add</filename>
14317 command on each file you changed.
14318 </para></listitem>
14319 <listitem><para id='making-sure-you-have-correct-commit-information'>
14320 <emphasis>Commit Your Changes:</emphasis>
14321 Commit the change by using the
14322 <filename>git commit</filename> command.
14323 Make sure your commit information follows standards by
14324 following these accepted conventions:
14325 <itemizedlist>
14326 <listitem><para>
14327 Be sure to include a "Signed-off-by:" line in the
14328 same style as required by the Linux kernel.
14329 Adding this line signifies that you, the submitter,
14330 have agreed to the Developer's Certificate of
14331 Origin 1.1 as follows:
14332 <literallayout class='monospaced'>
14333 Developer's Certificate of Origin 1.1
14334
14335 By making a contribution to this project, I certify that:
14336
14337 (a) The contribution was created in whole or in part by me and I
14338 have the right to submit it under the open source license
14339 indicated in the file; or
14340
14341 (b) The contribution is based upon previous work that, to the best
14342 of my knowledge, is covered under an appropriate open source
14343 license and I have the right under that license to submit that
14344 work with modifications, whether created in whole or in part
14345 by me, under the same open source license (unless I am
14346 permitted to submit under a different license), as indicated
14347 in the file; or
14348
14349 (c) The contribution was provided directly to me by some other
14350 person who certified (a), (b) or (c) and I have not modified
14351 it.
14352
14353 (d) I understand and agree that this project and the contribution
14354 are public and that a record of the contribution (including all
14355 personal information I submit with it, including my sign-off) is
14356 maintained indefinitely and may be redistributed consistent with
14357 this project or the open source license(s) involved.
14358 </literallayout>
14359 </para></listitem>
14360 <listitem><para>
14361 Provide a single-line summary of the change.
14362 and,
14363 if more explanation is needed, provide more
14364 detail in the body of the commit.
14365 This summary is typically viewable in the
14366 "shortlist" of changes.
14367 Thus, providing something short and descriptive
14368 that gives the reader a summary of the change is
14369 useful when viewing a list of many commits.
14370 You should prefix this short description with the
14371 recipe name (if changing a recipe), or else with
14372 the short form path to the file being changed.
14373 </para></listitem>
14374 <listitem><para>
14375 For the body of the commit message, provide
14376 detailed information that describes what you
14377 changed, why you made the change, and the approach
14378 you used.
14379 It might also be helpful if you mention how you
14380 tested the change.
14381 Provide as much detail as you can in the body of
14382 the commit message.
14383 <note>
14384 You do not need to provide a more detailed
14385 explanation of a change if the change is
14386 minor to the point of the single line
14387 summary providing all the information.
14388 </note>
14389 </para></listitem>
14390 <listitem><para>
14391 If the change addresses a specific bug or issue
14392 that is associated with a bug-tracking ID,
14393 include a reference to that ID in your detailed
14394 description.
14395 For example, the Yocto Project uses a specific
14396 convention for bug references - any commit that
14397 addresses a specific bug should use the following
14398 form for the detailed description.
14399 Be sure to use the actual bug-tracking ID from
14400 Bugzilla for
14401 <replaceable>bug-id</replaceable>:
14402 <literallayout class='monospaced'>
14403 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14404
14405 <replaceable>detailed description of change</replaceable>
14406 </literallayout>
14407 </para></listitem>
14408 </itemizedlist>
14409 </para></listitem>
14410 <listitem><para>
14411 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14412 If you have arranged for permissions to push to an
14413 upstream contrib repository, push the change to that
14414 repository:
14415 <literallayout class='monospaced'>
14416 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14417 </literallayout>
14418 For example, suppose you have permissions to push into the
14419 upstream <filename>meta-intel-contrib</filename>
14420 repository and you are working in a local branch named
14421 <replaceable>your_name</replaceable><filename>/README</filename>.
14422 The following command pushes your local commits to the
14423 <filename>meta-intel-contrib</filename> upstream
14424 repository and puts the commit in a branch named
14425 <replaceable>your_name</replaceable><filename>/README</filename>:
14426 <literallayout class='monospaced'>
14427 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14428 </literallayout>
14429 </para></listitem>
14430 <listitem><para id='push-determine-who-to-notify'>
14431 <emphasis>Determine Who to Notify:</emphasis>
14432 Determine the maintainer or the mailing list
14433 that you need to notify for the change.</para>
14434
14435 <para>Before submitting any change, you need to be sure
14436 who the maintainer is or what mailing list that you need
14437 to notify.
14438 Use either these methods to find out:
14439 <itemizedlist>
14440 <listitem><para>
14441 <emphasis>Maintenance File:</emphasis>
14442 Examine the <filename>maintainers.inc</filename>
14443 file, which is located in the
14444 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14445 at
14446 <filename>meta/conf/distro/include</filename>,
14447 to see who is responsible for code.
14448 </para></listitem>
14449 <listitem><para>
14450 <emphasis>Search by File:</emphasis>
14451 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14452 you can enter the following command to bring up a
14453 short list of all commits against a specific file:
14454 <literallayout class='monospaced'>
14455 git shortlog -- <replaceable>filename</replaceable>
14456 </literallayout>
14457 Just provide the name of the file for which you
14458 are interested.
14459 The information returned is not ordered by history
14460 but does include a list of everyone who has
14461 committed grouped by name.
14462 From the list, you can see who is responsible for
14463 the bulk of the changes against the file.
14464 </para></listitem>
14465 <listitem><para>
14466 <emphasis>Examine the List of Mailing Lists:</emphasis>
14467 For a list of the Yocto Project and related mailing
14468 lists, see the
14469 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14470 section in the Yocto Project Reference Manual.
14471 </para></listitem>
14472 </itemizedlist>
14473 </para></listitem>
14474 <listitem><para>
14475 <emphasis>Make a Pull Request:</emphasis>
14476 Notify the maintainer or the mailing list that you have
14477 pushed a change by making a pull request.</para>
14478
14479 <para>The Yocto Project provides two scripts that
14480 conveniently let you generate and send pull requests to the
14481 Yocto Project.
14482 These scripts are <filename>create-pull-request</filename>
14483 and <filename>send-pull-request</filename>.
14484 You can find these scripts in the
14485 <filename>scripts</filename> directory within the
14486 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14487 (e.g. <filename>~/poky/scripts</filename>).
14488 </para>
14489
14490 <para>Using these scripts correctly formats the requests
14491 without introducing any whitespace or HTML formatting.
14492 The maintainer that receives your patches either directly
14493 or through the mailing list needs to be able to save and
14494 apply them directly from your emails.
14495 Using these scripts is the preferred method for sending
14496 patches.</para>
14497
14498 <para>First, create the pull request.
14499 For example, the following command runs the script,
14500 specifies the upstream repository in the contrib directory
14501 into which you pushed the change, and provides a subject
14502 line in the created patch files:
14503 <literallayout class='monospaced'>
14504 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14505 </literallayout>
14506 Running this script forms
14507 <filename>*.patch</filename> files in a folder named
14508 <filename>pull-</filename><replaceable>PID</replaceable>
14509 in the current directory.
14510 One of the patch files is a cover letter.</para>
14511
14512 <para>Before running the
14513 <filename>send-pull-request</filename> script, you must
14514 edit the cover letter patch to insert information about
14515 your change.
14516 After editing the cover letter, send the pull request.
14517 For example, the following command runs the script and
14518 specifies the patch directory and email address.
14519 In this example, the email address is a mailing list:
14520 <literallayout class='monospaced'>
14521 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14522 </literallayout>
14523 You need to follow the prompts as the script is
14524 interactive.
14525 <note>
14526 For help on using these scripts, simply provide the
14527 <filename>-h</filename> argument as follows:
14528 <literallayout class='monospaced'>
14529 $ poky/scripts/create-pull-request -h
14530 $ poky/scripts/send-pull-request -h
14531 </literallayout>
14532 </note>
14533 </para></listitem>
14534 </orderedlist>
14535 </para>
14536 </section>
14537
14538 <section id='submitting-a-patch'>
14539 <title>Using Email to Submit a Patch</title>
14540
14541 <para>
14542 You can submit patches without using the
14543 <filename>create-pull-request</filename> and
14544 <filename>send-pull-request</filename> scripts described in the
14545 previous section.
14546 However, keep in mind, the preferred method is to use the scripts.
14547 </para>
14548
14549 <para>
14550 Depending on the components changed, you need to submit the email
14551 to a specific mailing list.
14552 For some guidance on which mailing list to use, see the
14553 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14554 at the beginning of this section.
14555 For a description of all the available mailing lists, see the
14556 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14557 section in the Yocto Project Reference Manual.
14558 </para>
14559
14560 <para>
14561 Here is the general procedure on how to submit a patch through
14562 email without using the scripts:
14563 <orderedlist>
14564 <listitem><para>
14565 <emphasis>Make Your Changes Locally:</emphasis>
14566 Make your changes in your local Git repository.
14567 You should make small, controlled, isolated changes.
14568 Keeping changes small and isolated aids review,
14569 makes merging/rebasing easier and keeps the change
14570 history clean should anyone need to refer to it in
14571 future.
14572 </para></listitem>
14573 <listitem><para>
14574 <emphasis>Stage Your Changes:</emphasis>
14575 Stage your changes by using the <filename>git add</filename>
14576 command on each file you changed.
14577 </para></listitem>
14578 <listitem><para>
14579 <emphasis>Commit Your Changes:</emphasis>
14580 Commit the change by using the
14581 <filename>git commit --signoff</filename> command.
14582 Using the <filename>--signoff</filename> option identifies
14583 you as the person making the change and also satisfies
14584 the Developer's Certificate of Origin (DCO) shown earlier.
14585 </para>
14586
14587 <para>When you form a commit, you must follow certain
14588 standards established by the Yocto Project development
14589 team.
14590 See
14591 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14592 in the previous section for information on how to
14593 provide commit information that meets Yocto Project
14594 commit message standards.
14595 </para></listitem>
14596 <listitem><para>
14597 <emphasis>Format the Commit:</emphasis>
14598 Format the commit into an email message.
14599 To format commits, use the
14600 <filename>git format-patch</filename> command.
14601 When you provide the command, you must include a revision
14602 list or a number of patches as part of the command.
14603 For example, either of these two commands takes your most
14604 recent single commit and formats it as an email message in
14605 the current directory:
14606 <literallayout class='monospaced'>
14607 $ git format-patch -1
14608 </literallayout>
14609 or
14610 <literallayout class='monospaced'>
14611 $ git format-patch HEAD~
14612 </literallayout></para>
14613
14614 <para>After the command is run, the current directory
14615 contains a numbered <filename>.patch</filename> file for
14616 the commit.</para>
14617
14618 <para>If you provide several commits as part of the
14619 command, the <filename>git format-patch</filename> command
14620 produces a series of numbered files in the current
14621 directory – one for each commit.
14622 If you have more than one patch, you should also use the
14623 <filename>--cover</filename> option with the command,
14624 which generates a cover letter as the first "patch" in
14625 the series.
14626 You can then edit the cover letter to provide a
14627 description for the series of patches.
14628 For information on the
14629 <filename>git format-patch</filename> command,
14630 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14631 using the <filename>man git-format-patch</filename>
14632 command.
14633 <note>
14634 If you are or will be a frequent contributor to the
14635 Yocto Project or to OpenEmbedded, you might consider
14636 requesting a contrib area and the necessary associated
14637 rights.
14638 </note>
14639 </para></listitem>
14640 <listitem><para>
14641 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14642 Import the files into your mail client by using the
14643 <filename>git send-email</filename> command.
14644 <note>
14645 In order to use <filename>git send-email</filename>,
14646 you must have the proper Git packages installed on
14647 your host.
14648 For Ubuntu, Debian, and Fedora the package is
14649 <filename>git-email</filename>.
14650 </note></para>
14651
14652 <para>The <filename>git send-email</filename> command
14653 sends email by using a local or remote Mail Transport Agent
14654 (MTA) such as <filename>msmtp</filename>,
14655 <filename>sendmail</filename>, or through a direct
14656 <filename>smtp</filename> configuration in your Git
14657 <filename>~/.gitconfig</filename> file.
14658 If you are submitting patches through email only, it is
14659 very important that you submit them without any whitespace
14660 or HTML formatting that either you or your mailer
14661 introduces.
14662 The maintainer that receives your patches needs to be able
14663 to save and apply them directly from your emails.
14664 A good way to verify that what you are sending will be
14665 applicable by the maintainer is to do a dry run and send
14666 them to yourself and then save and apply them as the
14667 maintainer would.</para>
14668
14669 <para>The <filename>git send-email</filename> command is
14670 the preferred method for sending your patches using
14671 email since there is no risk of compromising whitespace
14672 in the body of the message, which can occur when you use
14673 your own mail client.
14674 The command also has several options that let you
14675 specify recipients and perform further editing of the
14676 email message.
14677 For information on how to use the
14678 <filename>git send-email</filename> command,
14679 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14680 the <filename>man git-send-email</filename> command.
14681 </para></listitem>
14682 </orderedlist>
14683 </para>
14684 </section>
14685 </section>
14686 </section>
14687
14688 <section id='working-with-licenses'>
14689 <title>Working With Licenses</title>
14690
14691 <para>
14692 As mentioned in the
14693 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
14694 section in the Yocto Project Overview and Concepts Manual,
14695 open source projects are open to the public and they
14696 consequently have different licensing structures in place.
14697 This section describes the mechanism by which the
14698 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
14699 tracks changes to licensing text and covers how to maintain open
14700 source license compliance during your project's lifecycle.
14701 The section also describes how to enable commercially licensed
14702 recipes, which by default are disabled.
14703 </para>
14704
14705 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
14706 <title>Tracking License Changes</title>
14707
14708 <para>
14709 The license of an upstream project might change in the future.
14710 In order to prevent these changes going unnoticed, the
14711 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
14712 variable tracks changes to the license text. The checksums are
14713 validated at the end of the configure step, and if the
14714 checksums do not match, the build will fail.
14715 </para>
14716
14717 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
14718 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
14719
14720 <para>
14721 The <filename>LIC_FILES_CHKSUM</filename>
14722 variable contains checksums of the license text in the
14723 source code for the recipe.
14724 Following is an example of how to specify
14725 <filename>LIC_FILES_CHKSUM</filename>:
14726 <literallayout class='monospaced'>
14727 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
14728 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
14729 file://licfile2.txt;endline=50;md5=zzzz \
14730 ..."
14731 </literallayout>
14732 <note><title>Notes</title>
14733 <itemizedlist>
14734 <listitem><para>
14735 When using "beginline" and "endline", realize
14736 that line numbering begins with one and not
14737 zero.
14738 Also, the included lines are inclusive (i.e.
14739 lines five through and including 29 in the
14740 previous example for
14741 <filename>licfile1.txt</filename>).
14742 </para></listitem>
14743 <listitem><para>
14744 When a license check fails, the selected license
14745 text is included as part of the QA message.
14746 Using this output, you can determine the exact
14747 start and finish for the needed license text.
14748 </para></listitem>
14749 </itemizedlist>
14750 </note>
14751 </para>
14752
14753 <para>
14754 The build system uses the
14755 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
14756 variable as the default directory when searching files
14757 listed in <filename>LIC_FILES_CHKSUM</filename>.
14758 The previous example employs the default directory.
14759 </para>
14760
14761 <para>
14762 Consider this next example:
14763 <literallayout class='monospaced'>
14764 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
14765 md5=bb14ed3c4cda583abc85401304b5cd4e"
14766 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
14767 </literallayout>
14768 </para>
14769
14770 <para>
14771 The first line locates a file in
14772 <filename>${S}/src/ls.c</filename> and isolates lines five
14773 through 16 as license text.
14774 The second line refers to a file in
14775 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
14776 </para>
14777
14778 <para>
14779 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
14780 mandatory for all recipes, unless the
14781 <filename>LICENSE</filename> variable is set to "CLOSED".
14782 </para>
14783 </section>
14784
14785 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
14786 <title>Explanation of Syntax</title>
14787
14788 <para>
14789 As mentioned in the previous section, the
14790 <filename>LIC_FILES_CHKSUM</filename> variable lists all
14791 the important files that contain the license text for the
14792 source code.
14793 It is possible to specify a checksum for an entire file,
14794 or a specific section of a file (specified by beginning and
14795 ending line numbers with the "beginline" and "endline"
14796 parameters, respectively).
14797 The latter is useful for source files with a license
14798 notice header, README documents, and so forth.
14799 If you do not use the "beginline" parameter, then it is
14800 assumed that the text begins on the first line of the file.
14801 Similarly, if you do not use the "endline" parameter,
14802 it is assumed that the license text ends with the last
14803 line of the file.
14804 </para>
14805
14806 <para>
14807 The "md5" parameter stores the md5 checksum of the license
14808 text.
14809 If the license text changes in any way as compared to
14810 this parameter then a mismatch occurs.
14811 This mismatch triggers a build failure and notifies
14812 the developer.
14813 Notification allows the developer to review and address
14814 the license text changes.
14815 Also note that if a mismatch occurs during the build,
14816 the correct md5 checksum is placed in the build log and
14817 can be easily copied to the recipe.
14818 </para>
14819
14820 <para>
14821 There is no limit to how many files you can specify using
14822 the <filename>LIC_FILES_CHKSUM</filename> variable.
14823 Generally, however, every project requires a few
14824 specifications for license tracking.
14825 Many projects have a "COPYING" file that stores the
14826 license information for all the source code files.
14827 This practice allows you to just track the "COPYING"
14828 file as long as it is kept up to date.
14829 <note><title>Tips</title>
14830 <itemizedlist>
14831 <listitem><para>
14832 If you specify an empty or invalid "md5"
14833 parameter,
14834 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
14835 returns an md5 mis-match
14836 error and displays the correct "md5" parameter
14837 value during the build.
14838 The correct parameter is also captured in
14839 the build log.
14840 </para></listitem>
14841 <listitem><para>
14842 If the whole file contains only license text,
14843 you do not need to use the "beginline" and
14844 "endline" parameters.
14845 </para></listitem>
14846 </itemizedlist>
14847 </note>
14848 </para>
14849 </section>
14850 </section>
14851
14852 <section id="enabling-commercially-licensed-recipes">
14853 <title>Enabling Commercially Licensed Recipes</title>
14854
14855 <para>
14856 By default, the OpenEmbedded build system disables
14857 components that have commercial or other special licensing
14858 requirements.
14859 Such requirements are defined on a
14860 recipe-by-recipe basis through the
14861 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
14862 variable definition in the affected recipe.
14863 For instance, the
14864 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14865 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014866 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014867 LICENSE_FLAGS = "commercial"
14868 </literallayout>
14869 Here is a slightly more complicated example that contains both
14870 an explicit recipe name and version (after variable expansion):
14871 <literallayout class='monospaced'>
14872 LICENSE_FLAGS = "license_${PN}_${PV}"
14873 </literallayout>
14874 In order for a component restricted by a
14875 <filename>LICENSE_FLAGS</filename> definition to be enabled and
14876 included in an image, it needs to have a matching entry in the
14877 global
14878 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
14879 variable, which is a variable typically defined in your
14880 <filename>local.conf</filename> file.
14881 For example, to enable the
14882 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14883 package, you could add either the string
14884 "commercial_gst-plugins-ugly" or the more general string
14885 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
14886 See the
14887 "<link linkend='license-flag-matching'>License Flag Matching</link>"
14888 section for a full
14889 explanation of how <filename>LICENSE_FLAGS</filename> matching
14890 works.
14891 Here is the example:
14892 <literallayout class='monospaced'>
14893 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
14894 </literallayout>
14895 Likewise, to additionally enable the package built from the
14896 recipe containing
14897 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
14898 and assuming that the actual recipe name was
14899 <filename>emgd_1.10.bb</filename>, the following string would
14900 enable that package as well as the original
14901 <filename>gst-plugins-ugly</filename> package:
14902 <literallayout class='monospaced'>
14903 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
14904 </literallayout>
14905 As a convenience, you do not need to specify the complete
14906 license string in the whitelist for every package.
14907 You can use an abbreviated form, which consists
14908 of just the first portion or portions of the license
14909 string before the initial underscore character or characters.
14910 A partial string will match any license that contains the
14911 given string as the first portion of its license.
14912 For example, the following whitelist string will also match
14913 both of the packages previously mentioned as well as any other
14914 packages that have licenses starting with "commercial" or
14915 "license".
14916 <literallayout class='monospaced'>
14917 LICENSE_FLAGS_WHITELIST = "commercial license"
14918 </literallayout>
14919 </para>
14920
14921 <section id="license-flag-matching">
14922 <title>License Flag Matching</title>
14923
14924 <para>
14925 License flag matching allows you to control what recipes
14926 the OpenEmbedded build system includes in the build.
14927 Fundamentally, the build system attempts to match
14928 <filename>LICENSE_FLAGS</filename> strings found in recipes
14929 against <filename>LICENSE_FLAGS_WHITELIST</filename>
14930 strings found in the whitelist.
14931 A match causes the build system to include a recipe in the
14932 build, while failure to find a match causes the build
14933 system to exclude a recipe.
14934 </para>
14935
14936 <para>
14937 In general, license flag matching is simple.
14938 However, understanding some concepts will help you
14939 correctly and effectively use matching.
14940 </para>
14941
14942 <para>
14943 Before a flag
14944 defined by a particular recipe is tested against the
14945 contents of the whitelist, the expanded string
14946 <filename>_${PN}</filename> is appended to the flag.
14947 This expansion makes each
14948 <filename>LICENSE_FLAGS</filename> value recipe-specific.
14949 After expansion, the string is then matched against the
14950 whitelist.
14951 Thus, specifying
14952 <filename>LICENSE_FLAGS = "commercial"</filename>
14953 in recipe "foo", for example, results in the string
14954 <filename>"commercial_foo"</filename>.
14955 And, to create a match, that string must appear in the
14956 whitelist.
14957 </para>
14958
14959 <para>
14960 Judicious use of the <filename>LICENSE_FLAGS</filename>
14961 strings and the contents of the
14962 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
14963 allows you a lot of flexibility for including or excluding
14964 recipes based on licensing.
14965 For example, you can broaden the matching capabilities by
14966 using license flags string subsets in the whitelist.
14967 <note>
14968 When using a string subset, be sure to use the part of
14969 the expanded string that precedes the appended
14970 underscore character (e.g.
14971 <filename>usethispart_1.3</filename>,
14972 <filename>usethispart_1.4</filename>, and so forth).
14973 </note>
14974 For example, simply specifying the string "commercial" in
14975 the whitelist matches any expanded
14976 <filename>LICENSE_FLAGS</filename> definition that starts
14977 with the string "commercial" such as "commercial_foo" and
14978 "commercial_bar", which are the strings the build system
14979 automatically generates for hypothetical recipes named
14980 "foo" and "bar" assuming those recipes simply specify the
14981 following:
14982 <literallayout class='monospaced'>
14983 LICENSE_FLAGS = "commercial"
14984 </literallayout>
14985 Thus, you can choose to exhaustively
14986 enumerate each license flag in the whitelist and
14987 allow only specific recipes into the image, or
14988 you can use a string subset that causes a broader range of
14989 matches to allow a range of recipes into the image.
14990 </para>
14991
14992 <para>
14993 This scheme works even if the
14994 <filename>LICENSE_FLAGS</filename> string already
14995 has <filename>_${PN}</filename> appended.
14996 For example, the build system turns the license flag
14997 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
14998 would match both the general "commercial" and the specific
14999 "commercial_1.2_foo" strings found in the whitelist, as
15000 expected.
15001 </para>
15002
15003 <para>
15004 Here are some other scenarios:
15005 <itemizedlist>
15006 <listitem><para>
15007 You can specify a versioned string in the recipe
15008 such as "commercial_foo_1.2" in a "foo" recipe.
15009 The build system expands this string to
15010 "commercial_foo_1.2_foo".
15011 Combine this license flag with a whitelist that has
15012 the string "commercial" and you match the flag
15013 along with any other flag that starts with the
15014 string "commercial".
15015 </para></listitem>
15016 <listitem><para>
15017 Under the same circumstances, you can use
15018 "commercial_foo" in the whitelist and the build
15019 system not only matches "commercial_foo_1.2" but
15020 also matches any license flag with the string
15021 "commercial_foo", regardless of the version.
15022 </para></listitem>
15023 <listitem><para>
15024 You can be very specific and use both the
15025 package and version parts in the whitelist (e.g.
15026 "commercial_foo_1.2") to specifically match a
15027 versioned recipe.
15028 </para></listitem>
15029 </itemizedlist>
15030 </para>
15031 </section>
15032
15033 <section id="other-variables-related-to-commercial-licenses">
15034 <title>Other Variables Related to Commercial Licenses</title>
15035
15036 <para>
15037 Other helpful variables related to commercial
15038 license handling exist and are defined in the
15039 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
15040 <literallayout class='monospaced'>
15041 COMMERCIAL_AUDIO_PLUGINS ?= ""
15042 COMMERCIAL_VIDEO_PLUGINS ?= ""
15043 </literallayout>
15044 If you want to enable these components, you can do so by
15045 making sure you have statements similar to the following
15046 in your <filename>local.conf</filename> configuration file:
15047 <literallayout class='monospaced'>
15048 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
15049 gst-plugins-ugly-mpegaudioparse"
15050 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
15051 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
15052 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
15053 </literallayout>
15054 Of course, you could also create a matching whitelist
15055 for those components using the more general "commercial"
15056 in the whitelist, but that would also enable all the
15057 other packages with <filename>LICENSE_FLAGS</filename>
15058 containing "commercial", which you may or may not want:
15059 <literallayout class='monospaced'>
15060 LICENSE_FLAGS_WHITELIST = "commercial"
15061 </literallayout>
15062 </para>
15063
15064 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040015065 Specifying audio and video plugins as part of the
Brad Bishop316dfdd2018-06-25 12:45:53 -040015066 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
15067 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
15068 (along with the enabling
15069 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
Brad Bishopc342db32019-05-15 21:57:59 -040015070 plugins or components into built images, thus adding
Brad Bishop316dfdd2018-06-25 12:45:53 -040015071 support for media formats or components.
15072 </para>
15073 </section>
15074 </section>
15075
15076 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
15077 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
15078
15079 <para>
15080 One of the concerns for a development organization using open source
15081 software is how to maintain compliance with various open source
15082 licensing during the lifecycle of the product.
15083 While this section does not provide legal advice or
15084 comprehensively cover all scenarios, it does
15085 present methods that you can use to
15086 assist you in meeting the compliance requirements during a software
15087 release.
15088 </para>
15089
15090 <para>
15091 With hundreds of different open source licenses that the Yocto
15092 Project tracks, it is difficult to know the requirements of each
15093 and every license.
15094 However, the requirements of the major FLOSS licenses can begin
15095 to be covered by
15096 assuming that three main areas of concern exist:
15097 <itemizedlist>
15098 <listitem><para>Source code must be provided.</para></listitem>
15099 <listitem><para>License text for the software must be
15100 provided.</para></listitem>
15101 <listitem><para>Compilation scripts and modifications to the
15102 source code must be provided.
15103 </para></listitem>
15104 </itemizedlist>
15105 There are other requirements beyond the scope of these
15106 three and the methods described in this section
15107 (e.g. the mechanism through which source code is distributed).
15108 </para>
15109
15110 <para>
15111 As different organizations have different methods of complying with
15112 open source licensing, this section is not meant to imply that
15113 there is only one single way to meet your compliance obligations,
15114 but rather to describe one method of achieving compliance.
15115 The remainder of this section describes methods supported to meet the
15116 previously mentioned three requirements.
15117 Once you take steps to meet these requirements,
15118 and prior to releasing images, sources, and the build system,
15119 you should audit all artifacts to ensure completeness.
15120 <note>
15121 The Yocto Project generates a license manifest during
15122 image creation that is located
15123 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
15124 to assist with any audits.
15125 </note>
15126 </para>
15127
15128 <section id='providing-the-source-code'>
15129 <title>Providing the Source Code</title>
15130
15131 <para>
15132 Compliance activities should begin before you generate the
15133 final image.
15134 The first thing you should look at is the requirement that
15135 tops the list for most compliance groups - providing
15136 the source.
15137 The Yocto Project has a few ways of meeting this
15138 requirement.
15139 </para>
15140
15141 <para>
15142 One of the easiest ways to meet this requirement is
15143 to provide the entire
15144 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
15145 used by the build.
15146 This method, however, has a few issues.
15147 The most obvious is the size of the directory since it includes
15148 all sources used in the build and not just the source used in
15149 the released image.
15150 It will include toolchain source, and other artifacts, which
15151 you would not generally release.
15152 However, the more serious issue for most companies is accidental
15153 release of proprietary software.
15154 The Yocto Project provides an
15155 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
15156 class to help avoid some of these concerns.
15157 </para>
15158
15159 <para>
15160 Before you employ <filename>DL_DIR</filename> or the
15161 <filename>archiver</filename> class, you need to decide how
15162 you choose to provide source.
15163 The source <filename>archiver</filename> class can generate
15164 tarballs and SRPMs and can create them with various levels of
15165 compliance in mind.
15166 </para>
15167
15168 <para>
15169 One way of doing this (but certainly not the only way) is to
15170 release just the source as a tarball.
15171 You can do this by adding the following to the
15172 <filename>local.conf</filename> file found in the
15173 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15174 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015175 INHERIT += "archiver"
15176 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015177 </literallayout>
15178 During the creation of your image, the source from all
15179 recipes that deploy packages to the image is placed within
15180 subdirectories of
15181 <filename>DEPLOY_DIR/sources</filename> based on the
15182 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15183 for each recipe.
15184 Releasing the entire directory enables you to comply with
15185 requirements concerning providing the unmodified source.
15186 It is important to note that the size of the directory can
15187 get large.
15188 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015189
Brad Bishop316dfdd2018-06-25 12:45:53 -040015190 <para>
15191 A way to help mitigate the size issue is to only release
15192 tarballs for licenses that require the release of
15193 source.
15194 Let us assume you are only concerned with GPL code as
15195 identified by running the following script:
15196 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015197 # Script to archive a subset of packages matching specific license(s)
15198 # Source and license files are copied into sub folders of package folder
15199 # Must be run from build folder
15200 #!/bin/bash
15201 src_release_dir="source-release"
15202 mkdir -p $src_release_dir
15203 for a in tmp/deploy/sources/*; do
15204 for d in $a/*; do
15205 # Get package name from path
15206 p=`basename $d`
15207 p=${p%-*}
15208 p=${p%-*}
15209 # Only archive GPL packages (update *GPL* regex for your license check)
15210 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15211 if [ $numfiles -gt 1 ]; then
15212 echo Archiving $p
15213 mkdir -p $src_release_dir/$p/source
15214 cp $d/* $src_release_dir/$p/source 2> /dev/null
15215 mkdir -p $src_release_dir/$p/license
15216 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15217 fi
15218 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015219 done
15220 </literallayout>
15221 At this point, you could create a tarball from the
15222 <filename>gpl_source_release</filename> directory and
15223 provide that to the end user.
15224 This method would be a step toward achieving compliance
15225 with section 3a of GPLv2 and with section 6 of GPLv3.
15226 </para>
15227 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015228
Brad Bishop316dfdd2018-06-25 12:45:53 -040015229 <section id='providing-license-text'>
15230 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015231
Brad Bishop316dfdd2018-06-25 12:45:53 -040015232 <para>
15233 One requirement that is often overlooked is inclusion
15234 of license text.
15235 This requirement also needs to be dealt with prior to
15236 generating the final image.
15237 Some licenses require the license text to accompany
15238 the binary.
15239 You can achieve this by adding the following to your
15240 <filename>local.conf</filename> file:
15241 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015242 COPY_LIC_MANIFEST = "1"
15243 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015244 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015245 </literallayout>
15246 Adding these statements to the configuration file ensures
15247 that the licenses collected during package generation
15248 are included on your image.
15249 <note>
15250 <para>Setting all three variables to "1" results in the
15251 image having two copies of the same license file.
15252 One copy resides in
15253 <filename>/usr/share/common-licenses</filename> and
15254 the other resides in
15255 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015256
Brad Bishop316dfdd2018-06-25 12:45:53 -040015257 <para>The reason for this behavior is because
15258 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15259 and
15260 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15261 add a copy of the license when the image is built but do
15262 not offer a path for adding licenses for newly installed
15263 packages to an image.
15264 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15265 adds a separate package and an upgrade path for adding
15266 licenses to an image.</para>
15267 </note>
15268 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015269
Brad Bishop316dfdd2018-06-25 12:45:53 -040015270 <para>
15271 As the source <filename>archiver</filename> class has already
15272 archived the original
15273 unmodified source that contains the license files,
15274 you would have already met the requirements for inclusion
15275 of the license information with source as defined by the GPL
15276 and other open source licenses.
15277 </para>
15278 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015279
Brad Bishop316dfdd2018-06-25 12:45:53 -040015280 <section id='providing-compilation-scripts-and-source-code-modifications'>
15281 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015282
Brad Bishop316dfdd2018-06-25 12:45:53 -040015283 <para>
15284 At this point, we have addressed all we need to
15285 prior to generating the image.
15286 The next two requirements are addressed during the final
15287 packaging of the release.
15288 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015289
Brad Bishop316dfdd2018-06-25 12:45:53 -040015290 <para>
15291 By releasing the version of the OpenEmbedded build system
15292 and the layers used during the build, you will be providing both
15293 compilation scripts and the source code modifications in one
15294 step.
15295 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015296
Brad Bishop316dfdd2018-06-25 12:45:53 -040015297 <para>
15298 If the deployment team has a
15299 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15300 and a distro layer, and those those layers are used to patch,
15301 compile, package, or modify (in any way) any open source
15302 software included in your released images, you
15303 might be required to release those layers under section 3 of
15304 GPLv2 or section 1 of GPLv3.
15305 One way of doing that is with a clean
15306 checkout of the version of the Yocto Project and layers used
15307 during your build.
15308 Here is an example:
15309 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015310 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15311 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015312 $ cd poky
15313 # We built using the release_branch for our layers
15314 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15315 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15316 # clean up the .git repos
15317 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015318 </literallayout>
15319 One thing a development organization might want to consider
15320 for end-user convenience is to modify
15321 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15322 ensure that when the end user utilizes the released build
15323 system to build an image, the development organization's
15324 layers are included in the <filename>bblayers.conf</filename>
15325 file automatically:
15326 <literallayout class='monospaced'>
15327 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015328 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015329 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015330
15331 BBPATH = "${TOPDIR}"
15332 BBFILES ?= ""
15333
15334 BBLAYERS ?= " \
15335 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015336 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015337 ##OEROOT##/meta-yocto-bsp \
15338 ##OEROOT##/meta-mylayer \
15339 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015340 </literallayout>
15341 Creating and providing an archive of the
15342 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15343 layers (recipes, configuration files, and so forth)
15344 enables you to meet your
15345 requirements to include the scripts to control compilation
15346 as well as any modifications to the original source.
15347 </para>
15348 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015349 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015350
15351 <section id='copying-licenses-that-do-not-exist'>
15352 <title>Copying Licenses that Do Not Exist</title>
15353
15354 <para>
15355 Some packages, such as the linux-firmware package, have many
15356 licenses that are not in any way common.
15357 You can avoid adding a lot of these types of common license
15358 files, which are only applicable to a specific package, by using
15359 the
15360 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15361 variable.
15362 Using this variable also avoids QA errors when you use a
15363 non-common, non-CLOSED license in a recipe.
15364 </para>
15365
15366 <para>
15367 The following is an example that uses the
15368 <filename>LICENSE.Abilis.txt</filename>
15369 file as the license from the fetched source:
15370 <literallayout class='monospaced'>
15371 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15372 </literallayout>
15373 </para>
15374 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015375 </section>
15376
15377 <section id='using-the-error-reporting-tool'>
15378 <title>Using the Error Reporting Tool</title>
15379
15380 <para>
15381 The error reporting tool allows you to
15382 submit errors encountered during builds to a central database.
15383 Outside of the build environment, you can use a web interface to
15384 browse errors, view statistics, and query for errors.
15385 The tool works using a client-server system where the client
15386 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015387 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015388 (e.g. <filename>poky</filename>).
15389 The server receives the information collected and saves it in a
15390 database.
15391 </para>
15392
15393 <para>
15394 A live instance of the error reporting server exists at
15395 <ulink url='http://errors.yoctoproject.org'></ulink>.
15396 This server exists so that when you want to get help with
15397 build failures, you can submit all of the information on the
15398 failure easily and then point to the URL in your bug report
15399 or send an email to the mailing list.
15400 <note>
15401 If you send error reports to this server, the reports become
15402 publicly visible.
15403 </note>
15404 </para>
15405
15406 <section id='enabling-and-using-the-tool'>
15407 <title>Enabling and Using the Tool</title>
15408
15409 <para>
15410 By default, the error reporting tool is disabled.
15411 You can enable it by inheriting the
15412 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15413 class by adding the following statement to the end of
15414 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015415 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015416 <literallayout class='monospaced'>
15417 INHERIT += "report-error"
15418 </literallayout>
15419 </para>
15420
15421 <para>
15422 By default, the error reporting feature stores information in
15423 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15424 However, you can specify a directory to use by adding the following
15425 to your <filename>local.conf</filename> file:
15426 <literallayout class='monospaced'>
15427 ERR_REPORT_DIR = "path"
15428 </literallayout>
15429 Enabling error reporting causes the build process to collect
15430 the errors and store them in a file as previously described.
15431 When the build system encounters an error, it includes a
15432 command as part of the console output.
15433 You can run the command to send the error file to the server.
15434 For example, the following command sends the errors to an
15435 upstream server:
15436 <literallayout class='monospaced'>
15437 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15438 </literallayout>
15439 In the previous example, the errors are sent to a public
15440 database available at
15441 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15442 used by the entire community.
15443 If you specify a particular server, you can send the errors
15444 to a different database.
15445 Use the following command for more information on available
15446 options:
15447 <literallayout class='monospaced'>
15448 $ send-error-report --help
15449 </literallayout>
15450 </para>
15451
15452 <para>
15453 When sending the error file, you are prompted to review the
15454 data being sent as well as to provide a name and optional
15455 email address.
15456 Once you satisfy these prompts, the command returns a link
15457 from the server that corresponds to your entry in the database.
15458 For example, here is a typical link:
15459 <literallayout class='monospaced'>
15460 http://errors.yoctoproject.org/Errors/Details/9522/
15461 </literallayout>
15462 Following the link takes you to a web interface where you can
15463 browse, query the errors, and view statistics.
15464 </para>
15465 </section>
15466
15467 <section id='disabling-the-tool'>
15468 <title>Disabling the Tool</title>
15469
15470 <para>
15471 To disable the error reporting feature, simply remove or comment
15472 out the following statement from the end of your
15473 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015474 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015475 <literallayout class='monospaced'>
15476 INHERIT += "report-error"
15477 </literallayout>
15478 </para>
15479 </section>
15480
15481 <section id='setting-up-your-own-error-reporting-server'>
15482 <title>Setting Up Your Own Error Reporting Server</title>
15483
15484 <para>
15485 If you want to set up your own error reporting server, you
15486 can obtain the code from the Git repository at
15487 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15488 Instructions on how to set it up are in the README document.
15489 </para>
15490 </section>
15491 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015492
15493 <section id="dev-using-wayland-and-weston">
15494 <title>Using Wayland and Weston</title>
15495
15496 <para>
15497 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15498 is a computer display server protocol that
15499 provides a method for compositing window managers to communicate
15500 directly with applications and video hardware and expects them to
15501 communicate with input hardware using other libraries.
15502 Using Wayland with supporting targets can result in better control
15503 over graphics frame rendering than an application might otherwise
15504 achieve.
15505 </para>
15506
15507 <para>
15508 The Yocto Project provides the Wayland protocol libraries and the
15509 reference
15510 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15511 compositor as part of its release.
15512 You can find the integrated packages in the
15513 <filename>meta</filename> layer of the
15514 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15515 Specifically, you can find the recipes that build both Wayland
15516 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15517 </para>
15518
15519 <para>
15520 You can build both the Wayland and Weston packages for use only
15521 with targets that accept the
15522 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15523 which is also known as Mesa DRI.
15524 This implies that you cannot build and use the packages if your
15525 target uses, for example, the
15526 <trademark class='registered'>Intel</trademark> Embedded Media
15527 and Graphics Driver
15528 (<trademark class='registered'>Intel</trademark> EMGD) that
15529 overrides Mesa DRI.
15530 <note>
15531 Due to lack of EGL support, Weston 1.0.3 will not run
15532 directly on the emulated QEMU hardware.
15533 However, this version of Weston will run under X emulation
15534 without issues.
15535 </note>
15536 </para>
15537
15538 <para>
15539 This section describes what you need to do to implement Wayland and
15540 use the Weston compositor when building an image for a supporting
15541 target.
15542 </para>
15543
15544 <section id="enabling-wayland-in-an-image">
15545 <title>Enabling Wayland in an Image</title>
15546
15547 <para>
15548 To enable Wayland, you need to enable it to be built and enable
15549 it to be included (installed) in the image.
15550 </para>
15551
15552 <section id="enable-building">
15553 <title>Building</title>
15554
15555 <para>
15556 To cause Mesa to build the <filename>wayland-egl</filename>
15557 platform and Weston to build Wayland with Kernel Mode
15558 Setting
15559 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15560 support, include the "wayland" flag in the
15561 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15562 statement in your <filename>local.conf</filename> file:
15563 <literallayout class='monospaced'>
15564 DISTRO_FEATURES_append = " wayland"
15565 </literallayout>
15566 <note>
15567 If X11 has been enabled elsewhere, Weston will build
15568 Wayland with X11 support
15569 </note>
15570 </para>
15571 </section>
15572
15573 <section id="enable-installation-in-an-image">
15574 <title>Installing</title>
15575
15576 <para>
15577 To install the Wayland feature into an image, you must
15578 include the following
15579 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15580 statement in your <filename>local.conf</filename> file:
15581 <literallayout class='monospaced'>
15582 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15583 </literallayout>
15584 </para>
15585 </section>
15586 </section>
15587
15588 <section id="running-weston">
15589 <title>Running Weston</title>
15590
15591 <para>
15592 To run Weston inside X11, enabling it as described earlier and
15593 building a Sato image is sufficient.
15594 If you are running your image under Sato, a Weston Launcher
15595 appears in the "Utility" category.
15596 </para>
15597
15598 <para>
15599 Alternatively, you can run Weston through the command-line
15600 interpretor (CLI), which is better suited for development work.
15601 To run Weston under the CLI, you need to do the following after
15602 your image is built:
15603 <orderedlist>
15604 <listitem><para>
15605 Run these commands to export
15606 <filename>XDG_RUNTIME_DIR</filename>:
15607 <literallayout class='monospaced'>
15608 mkdir -p /tmp/$USER-weston
15609 chmod 0700 /tmp/$USER-weston
15610 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15611 </literallayout>
15612 </para></listitem>
15613 <listitem><para>
15614 Launch Weston in the shell:
15615 <literallayout class='monospaced'>
15616 weston
15617 </literallayout></para></listitem>
15618 </orderedlist>
15619 </para>
15620 </section>
15621 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015622</chapter>
15623
15624<!--
15625vim: expandtab tw=80 ts=4
15626-->