blob: 9231d1416ead0eb237fe3cf4254dbc2642fa3849 [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.
Brad Bishop15ae2502019-06-18 21:44:24 -04004200 </para>
4201
4202 <para>
4203 While several methods exist that allow you upgrade a recipe,
4204 you might consider checking on the upgrade status of a recipe
4205 first.
4206 You can do so using the
4207 <filename>devtool check-upgrade-status</filename> command.
4208 See the
4209 "<ulink url='&YOCTO_DOCS_REF_URL;#devtool-checking-on-the-upgrade-status-of-a-recipe'>Checking on the Upgrade Status of a Recipe</ulink>"
4210 section in the Yocto Project Reference Manual for more information.
4211 </para>
4212
4213 <para>
4214 The remainder of this section describes three ways you can
4215 upgrade a recipe.
Brad Bishop316dfdd2018-06-25 12:45:53 -04004216 You can use the Automated Upgrade Helper (AUH) to set up
4217 automatic version upgrades.
4218 Alternatively, you can use <filename>devtool upgrade</filename>
4219 to set up semi-automatic version upgrades.
Brad Bishop15ae2502019-06-18 21:44:24 -04004220 Finally, you can manually upgrade a recipe by editing the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004221 recipe itself.
4222 </para>
4223
4224 <section id='gs-using-the-auto-upgrade-helper'>
4225 <title>Using the Auto Upgrade Helper (AUH)</title>
4226
4227 <para>
4228 The AUH utility works in conjunction with the
4229 OpenEmbedded build system in order to automatically generate
4230 upgrades for recipes based on new versions being
4231 published upstream.
4232 Use AUH when you want to create a service that performs the
4233 upgrades automatically and optionally sends you an email with
4234 the results.
4235 </para>
4236
4237 <para>
4238 AUH allows you to update several recipes with a single use.
4239 You can also optionally perform build and integration tests
4240 using images with the results saved to your hard drive and
4241 emails of results optionally sent to recipe maintainers.
4242 Finally, AUH creates Git commits with appropriate commit
4243 messages in the layer's tree for the changes made to recipes.
4244 <note>
4245 Conditions do exist when you should not use AUH to upgrade
4246 recipes and you should instead use either
4247 <filename>devtool upgrade</filename> or upgrade your
4248 recipes manually:
4249 <itemizedlist>
4250 <listitem><para>
4251 When AUH cannot complete the upgrade sequence.
4252 This situation usually results because custom
4253 patches carried by the recipe cannot be
4254 automatically rebased to the new version.
4255 In this case, <filename>devtool upgrade</filename>
4256 allows you to manually resolve conflicts.
4257 </para></listitem>
4258 <listitem><para>
4259 When for any reason you want fuller control over
4260 the upgrade process.
4261 For example, when you want special arrangements
4262 for testing.
4263 </para></listitem>
4264 </itemizedlist>
4265 </note>
4266 </para>
4267
4268 <para>
4269 The following steps describe how to set up the AUH utility:
4270 <orderedlist>
4271 <listitem><para>
4272 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4273 You need to be sure that your development host is
4274 set up to use the Yocto Project.
4275 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004276 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004277 section.
4278 </para></listitem>
4279 <listitem><para>
4280 <emphasis>Make Sure Git is Configured:</emphasis>
4281 The AUH utility requires Git to be configured because
4282 AUH uses Git to save upgrades.
4283 Thus, you must have Git user and email configured.
4284 The following command shows your configurations:
4285 <literallayout class='monospaced'>
4286 $ git config --list
4287 </literallayout>
4288 If you do not have the user and email configured, you
4289 can use the following commands to do so:
4290 <literallayout class='monospaced'>
4291 $ git config --global user.name <replaceable>some_name</replaceable>
4292 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4293 </literallayout>
4294 </para></listitem>
4295 <listitem><para>
4296 <emphasis>Clone the AUH Repository:</emphasis>
4297 To use AUH, you must clone the repository onto your
4298 development host.
4299 The following command uses Git to create a local
4300 copy of the repository on your system:
4301 <literallayout class='monospaced'>
4302 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4303 Cloning into 'auto-upgrade-helper'...
4304 remote: Counting objects: 768, done.
4305 remote: Compressing objects: 100% (300/300), done.
4306 remote: Total 768 (delta 499), reused 703 (delta 434)
4307 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4308 Resolving deltas: 100% (499/499), done.
4309 Checking connectivity... done.
4310 </literallayout>
4311 AUH is not part of the
4312 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4313 or
4314 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4315 repositories.
4316 </para></listitem>
4317 <listitem><para>
4318 <emphasis>Create a Dedicated Build Directory:</emphasis>
4319 Run the
4320 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4321 script to create a fresh build directory that you
4322 use exclusively for running the AUH utility:
4323 <literallayout class='monospaced'>
4324 $ cd ~/poky
4325 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4326 </literallayout>
4327 Re-using an existing build directory and its
4328 configurations is not recommended as existing settings
4329 could cause AUH to fail or behave undesirably.
4330 </para></listitem>
4331 <listitem><para>
4332 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4333 Several settings need to exist in the
4334 <filename>local.conf</filename> file in the build
4335 directory you just created for AUH.
4336 Make these following configurations:
4337 <itemizedlist>
4338 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04004339 If you want to enable
4340 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4341 which is optional, you need the following
4342 lines in the
4343 <filename>conf/local.conf</filename> file:
4344 <literallayout class='monospaced'>
4345 INHERIT =+ "buildhistory"
4346 BUILDHISTORY_COMMIT = "1"
4347 </literallayout>
4348 With this configuration and a successful
4349 upgrade, a build history "diff" file appears in
4350 the
4351 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4352 file found in your build directory.
4353 </para></listitem>
4354 <listitem><para>
4355 If you want to enable testing through the
4356 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4357 class, which is optional, you need to have the
4358 following set in your
4359 <filename>conf/local.conf</filename> file:
4360 <literallayout class='monospaced'>
4361 INHERIT += "testimage"
4362 </literallayout>
4363 <note>
4364 If your distro does not enable by default
4365 ptest, which Poky does, you need the
4366 following in your
4367 <filename>local.conf</filename> file:
4368 <literallayout class='monospaced'>
4369 DISTRO_FEATURES_append = " ptest"
4370 </literallayout>
4371 </note>
4372 </para></listitem>
4373 </itemizedlist>
4374 </para></listitem>
4375 <listitem><para>
4376 <emphasis>Optionally Start a vncserver:</emphasis>
4377 If you are running in a server without an X11 session,
4378 you need to start a vncserver:
4379 <literallayout class='monospaced'>
4380 $ vncserver :1
4381 $ export DISPLAY=:1
4382 </literallayout>
4383 </para></listitem>
4384 <listitem><para>
4385 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4386 You need to have the
4387 <filename>upgrade-helper/upgrade-helper.conf</filename>
4388 configuration file in your build directory.
4389 You can find a sample configuration file in the
4390 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4391 </para>
4392
4393 <para>Read through the sample file and make
4394 configurations as needed.
4395 For example, if you enabled build history in your
4396 <filename>local.conf</filename> as described earlier,
4397 you must enable it in
4398 <filename>upgrade-helper.conf</filename>.</para>
4399
4400 <para>Also, if you are using the default
4401 <filename>maintainers.inc</filename> file supplied
4402 with Poky and located in
4403 <filename>meta-yocto</filename> and you do not set a
4404 "maintainers_whitelist" or "global_maintainer_override"
4405 in the <filename>upgrade-helper.conf</filename>
4406 configuration, and you specify "-e all" on the
4407 AUH command-line, the utility automatically sends out
4408 emails to all the default maintainers.
4409 Please avoid this.
4410 </para></listitem>
4411 </orderedlist>
4412 </para>
4413
4414 <para>
4415 This next set of examples describes how to use the AUH:
4416 <itemizedlist>
4417 <listitem><para>
4418 <emphasis>Upgrading a Specific Recipe:</emphasis>
4419 To upgrade a specific recipe, use the following
4420 form:
4421 <literallayout class='monospaced'>
4422 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4423 </literallayout>
4424 For example, this command upgrades the
4425 <filename>xmodmap</filename> recipe:
4426 <literallayout class='monospaced'>
4427 $ upgrade-helper.py xmodmap
4428 </literallayout>
4429 </para></listitem>
4430 <listitem><para>
4431 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4432 To upgrade a specific recipe to a particular version,
4433 use the following form:
4434 <literallayout class='monospaced'>
4435 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4436 </literallayout>
4437 For example, this command upgrades the
4438 <filename>xmodmap</filename> recipe to version
4439 1.2.3:
4440 <literallayout class='monospaced'>
4441 $ upgrade-helper.py xmodmap -t 1.2.3
4442 </literallayout>
4443 </para></listitem>
4444 <listitem><para>
4445 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4446 To upgrade all recipes to their most recent versions
4447 and suppress the email notifications, use the following
4448 command:
4449 <literallayout class='monospaced'>
4450 $ upgrade-helper.py all
4451 </literallayout>
4452 </para></listitem>
4453 <listitem><para>
4454 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4455 To upgrade all recipes to their most recent versions
4456 and send email messages to maintainers for each
4457 attempted recipe as well as a status email, use the
4458 following command:
4459 <literallayout class='monospaced'>
4460 $ upgrade-helper.py -e all
4461 </literallayout>
4462 </para></listitem>
4463 </itemizedlist>
4464 </para>
4465
4466 <para>
4467 Once you have run the AUH utility, you can find the results
4468 in the AUH build directory:
4469 <literallayout class='monospaced'>
4470 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4471 </literallayout>
4472 The AUH utility also creates recipe update commits from
4473 successful upgrade attempts in the layer tree.
4474 </para>
4475
4476 <para>
4477 You can easily set up to run the AUH utility on a regular
4478 basis by using a cron job.
4479 See the
4480 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4481 file distributed with the utility for an example.
4482 </para>
4483 </section>
4484
4485 <section id='gs-using-devtool-upgrade'>
4486 <title>Using <filename>devtool upgrade</filename></title>
4487
4488 <para>
4489 As mentioned earlier, an alternative method for upgrading
4490 recipes to newer versions is to use
4491 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4492 You can read about <filename>devtool upgrade</filename> in
4493 general in the
4494 "<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>"
4495 section in the Yocto Project Application Development and the
4496 Extensible Software Development Kit (eSDK) Manual.
4497 </para>
4498
4499 <para>
4500 To see all the command-line options available with
4501 <filename>devtool upgrade</filename>, use the following help
4502 command:
4503 <literallayout class='monospaced'>
4504 $ devtool upgrade -h
4505 </literallayout>
4506 </para>
4507
4508 <para>
4509 If you want to find out what version a recipe is currently at
4510 upstream without any attempt to upgrade your local version of
4511 the recipe, you can use the following command:
4512 <literallayout class='monospaced'>
4513 $ devtool latest-version <replaceable>recipe_name</replaceable>
4514 </literallayout>
4515 </para>
4516
4517 <para>
4518 As mentioned in the previous section describing AUH,
4519 <filename>devtool upgrade</filename> works in a
4520 less-automated manner than AUH.
4521 Specifically, <filename>devtool upgrade</filename> only
4522 works on a single recipe that you name on the command line,
4523 cannot perform build and integration testing using images,
4524 and does not automatically generate commits for changes in
4525 the source tree.
4526 Despite all these "limitations",
4527 <filename>devtool upgrade</filename> updates the recipe file
4528 to the new upstream version and attempts to rebase custom
4529 patches contained by the recipe as needed.
4530 <note>
4531 AUH uses much of <filename>devtool upgrade</filename>
4532 behind the scenes making AUH somewhat of a "wrapper"
4533 application for <filename>devtool upgrade</filename>.
4534 </note>
4535 </para>
4536
4537 <para>
4538 A typical scenario involves having used Git to clone an
4539 upstream repository that you use during build operations.
4540 Because you are (or have) built the recipe in the past, the
4541 layer is likely added to your configuration already.
4542 If for some reason, the layer is not added, you could add
4543 it easily using the
4544 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4545 script.
4546 For example, suppose you use the <filename>nano.bb</filename>
4547 recipe from the <filename>meta-oe</filename> layer in the
4548 <filename>meta-openembedded</filename> repository.
4549 For this example, assume that the layer has been cloned into
4550 following area:
4551 <literallayout class='monospaced'>
4552 /home/scottrif/meta-openembedded
4553 </literallayout>
4554 The following command from your
4555 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4556 adds the layer to your build configuration (i.e.
4557 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4558 <literallayout class='monospaced'>
4559 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4560 NOTE: Starting bitbake server...
4561 Parsing recipes: 100% |##########################################| Time: 0:00:55
4562 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4563 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4564 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4565 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4566 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4567 </literallayout>
4568 For this example, assume that the <filename>nano.bb</filename>
4569 recipe that is upstream has a 2.9.3 version number.
4570 However, the version in the local repository is 2.7.4.
4571 The following command from your build directory automatically
4572 upgrades the recipe for you:
4573 <note>
4574 Using the <filename>-V</filename> option is not necessary.
4575 Omitting the version number causes
4576 <filename>devtool upgrade</filename> to upgrade the recipe
4577 to the most recent version.
4578 </note>
4579 <literallayout class='monospaced'>
4580 $ devtool upgrade nano -V 2.9.3
4581 NOTE: Starting bitbake server...
4582 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4583 Parsing recipes: 100% |##########################################| Time: 0:00:46
4584 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4585 NOTE: Extracting current version source...
4586 NOTE: Resolving any missing task queue dependencies
4587 .
4588 .
4589 .
4590 NOTE: Executing SetScene Tasks
4591 NOTE: Executing RunQueue Tasks
4592 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4593 Adding changed files: 100% |#####################################| Time: 0:00:00
4594 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4595 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4596 </literallayout>
4597 Continuing with this example, you can use
4598 <filename>devtool build</filename> to build the newly upgraded
4599 recipe:
4600 <literallayout class='monospaced'>
4601 $ devtool build nano
4602 NOTE: Starting bitbake server...
4603 Loading cache: 100% |################################################################################################| Time: 0:00:01
4604 Loaded 2040 entries from dependency cache.
4605 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4606 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4607 NOTE: Resolving any missing task queue dependencies
4608 .
4609 .
4610 .
4611 NOTE: Executing SetScene Tasks
4612 NOTE: Executing RunQueue Tasks
4613 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4614 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4615 </literallayout>
4616 Within the <filename>devtool upgrade</filename> workflow,
4617 opportunity exists to deploy and test your rebuilt software.
4618 For this example, however, running
4619 <filename>devtool finish</filename> cleans up the workspace
4620 once the source in your workspace is clean.
4621 This usually means using Git to stage and submit commits
4622 for the changes generated by the upgrade process.
4623 </para>
4624
4625 <para>
4626 Once the tree is clean, you can clean things up in this
4627 example with the following command from the
4628 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4629 directory:
4630 <literallayout class='monospaced'>
4631 $ devtool finish nano meta-oe
4632 NOTE: Starting bitbake server...
4633 Loading cache: 100% |################################################################################################| Time: 0:00:00
4634 Loaded 2040 entries from dependency cache.
4635 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4636 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4637 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4638 NOTE: Updating recipe nano_2.9.3.bb
4639 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4640 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4641 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4642 </literallayout>
4643 Using the <filename>devtool finish</filename> command cleans
4644 up the workspace and creates a patch file based on your
4645 commits.
4646 The tool puts all patch files back into the source directory
4647 in a sub-directory named <filename>nano</filename> in this
4648 case.
4649 </para>
4650 </section>
4651
4652 <section id='dev-manually-upgrading-a-recipe'>
4653 <title>Manually Upgrading a Recipe</title>
4654
4655 <para>
4656 If for some reason you choose not to upgrade recipes using the
4657 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4658 or by using
4659 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4660 you can manually edit the recipe files to upgrade the versions.
4661 <note><title>Caution</title>
4662 Manually updating multiple recipes scales poorly and
4663 involves many steps.
4664 The recommendation to upgrade recipe versions is through
4665 AUH or <filename>devtool upgrade</filename>, both of which
4666 automate some steps and provide guidance for others needed
4667 for the manual process.
4668 </note>
4669 </para>
4670
4671 <para>
4672 To manually upgrade recipe versions, follow these general steps:
4673 <orderedlist>
4674 <listitem><para>
4675 <emphasis>Change the Version:</emphasis>
4676 Rename the recipe such that the version (i.e. the
4677 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4678 part of the recipe name) changes appropriately.
4679 If the version is not part of the recipe name, change
4680 the value as it is set for <filename>PV</filename>
4681 within the recipe itself.
4682 </para></listitem>
4683 <listitem><para>
4684 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4685 If the source code your recipe builds is fetched from
4686 Git or some other version control system, update
4687 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4688 to point to the commit hash that matches the new
4689 version.
4690 </para></listitem>
4691 <listitem><para>
4692 <emphasis>Build the Software:</emphasis>
4693 Try to build the recipe using BitBake.
4694 Typical build failures include the following:
4695 <itemizedlist>
4696 <listitem><para>
4697 License statements were updated for the new
4698 version.
4699 For this case, you need to review any changes
4700 to the license and update the values of
4701 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4702 and
4703 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4704 as needed.
4705 <note>
4706 License changes are often inconsequential.
4707 For example, the license text's copyright
4708 year might have changed.
4709 </note>
4710 </para></listitem>
4711 <listitem><para>
4712 Custom patches carried by the older version of
4713 the recipe might fail to apply to the new
4714 version.
4715 For these cases, you need to review the
4716 failures.
4717 Patches might not be necessary for the new
4718 version of the software if the upgraded version
4719 has fixed those issues.
4720 If a patch is necessary and failing, you need
4721 to rebase it into the new version.
4722 </para></listitem>
4723 </itemizedlist>
4724 </para></listitem>
4725 <listitem><para>
4726 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4727 Once you successfully build the new software for a
4728 given architecture, you could test the build for
4729 other architectures by changing the
4730 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4731 variable and rebuilding the software.
4732 This optional step is especially important if the
4733 recipe is to be released publicly.
4734 </para></listitem>
4735 <listitem><para>
4736 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4737 Checking both these reveals if new features exist that
4738 could break backwards-compatibility.
4739 If so, you need to take steps to mitigate or eliminate
4740 that situation.
4741 </para></listitem>
4742 <listitem><para>
4743 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4744 If you want, you can test the new software by booting
4745 it onto actual hardware.
4746 </para></listitem>
4747 <listitem><para>
4748 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4749 After all builds work and any testing is successful,
4750 you can create commits for any changes in the layer
4751 holding your upgraded recipe.
4752 </para></listitem>
4753 </orderedlist>
4754 </para>
4755 </section>
4756 </section>
4757
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004758 <section id='finding-the-temporary-source-code'>
4759 <title>Finding Temporary Source Code</title>
4760
4761 <para>
4762 You might find it helpful during development to modify the
4763 temporary source code used by recipes to build packages.
4764 For example, suppose you are developing a patch and you need to
4765 experiment a bit to figure out your solution.
4766 After you have initially built the package, you can iteratively
4767 tweak the source code, which is located in the
4768 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4769 and then you can force a re-compile and quickly test your altered
4770 code.
4771 Once you settle on a solution, you can then preserve your changes
4772 in the form of patches.
4773 </para>
4774
4775 <para>
4776 During a build, the unpacked temporary source code used by recipes
4777 to build packages is available in the Build Directory as
4778 defined by the
4779 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4780 variable.
4781 Below is the default value for the <filename>S</filename> variable
4782 as defined in the
4783 <filename>meta/conf/bitbake.conf</filename> configuration file
4784 in the
4785 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4786 <literallayout class='monospaced'>
4787 S = "${WORKDIR}/${BP}"
4788 </literallayout>
4789 You should be aware that many recipes override the
4790 <filename>S</filename> variable.
4791 For example, recipes that fetch their source from Git usually set
4792 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4793 <note>
4794 The
4795 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4796 represents the base recipe name, which consists of the name
4797 and version:
4798 <literallayout class='monospaced'>
4799 BP = "${BPN}-${PV}"
4800 </literallayout>
4801 </note>
4802 </para>
4803
4804 <para>
4805 The path to the work directory for the recipe
4806 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4807 is defined as follows:
4808 <literallayout class='monospaced'>
4809 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4810 </literallayout>
4811 The actual directory depends on several things:
4812 <itemizedlist>
4813 <listitem><para>
4814 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4815 The top-level build output directory.
4816 </para></listitem>
4817 <listitem><para>
4818 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4819 The target system identifier.
4820 </para></listitem>
4821 <listitem><para>
4822 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4823 The recipe name.
4824 </para></listitem>
4825 <listitem><para>
4826 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4827 The epoch - (if
4828 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4829 is not specified, which is usually the case for most
4830 recipes, then <filename>EXTENDPE</filename> is blank).
4831 </para></listitem>
4832 <listitem><para>
4833 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4834 The recipe version.
4835 </para></listitem>
4836 <listitem><para>
4837 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4838 The recipe revision.
4839 </para></listitem>
4840 </itemizedlist>
4841 </para>
4842
4843 <para>
4844 As an example, assume a Source Directory top-level folder
4845 named <filename>poky</filename>, a default Build Directory at
4846 <filename>poky/build</filename>, and a
4847 <filename>qemux86-poky-linux</filename> machine target
4848 system.
4849 Furthermore, suppose your recipe is named
4850 <filename>foo_1.3.0.bb</filename>.
4851 In this case, the work directory the build system uses to
4852 build the package would be as follows:
4853 <literallayout class='monospaced'>
4854 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4855 </literallayout>
4856 </para>
4857 </section>
4858
4859 <section id="using-a-quilt-workflow">
4860 <title>Using Quilt in Your Workflow</title>
4861
4862 <para>
4863 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4864 is a powerful tool that allows you to capture source code changes
4865 without having a clean source tree.
4866 This section outlines the typical workflow you can use to modify
4867 source code, test changes, and then preserve the changes in the
4868 form of a patch all using Quilt.
4869 <note><title>Tip</title>
4870 With regard to preserving changes to source files, if you
4871 clean a recipe or have <filename>rm_work</filename> enabled,
4872 the
4873 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4874 as described in the Yocto Project Application Development
4875 and the Extensible Software Development Kit (eSDK) manual
4876 is a safer development flow than the flow that uses Quilt.
4877 </note>
4878 </para>
4879
4880 <para>
4881 Follow these general steps:
4882 <orderedlist>
4883 <listitem><para>
4884 <emphasis>Find the Source Code:</emphasis>
4885 Temporary source code used by the OpenEmbedded build system
4886 is kept in the
4887 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4888 See the
4889 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4890 section to learn how to locate the directory that has the
4891 temporary source code for a particular package.
4892 </para></listitem>
4893 <listitem><para>
4894 <emphasis>Change Your Working Directory:</emphasis>
4895 You need to be in the directory that has the temporary
4896 source code.
4897 That directory is defined by the
4898 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4899 variable.</para></listitem>
4900 <listitem><para>
4901 <emphasis>Create a New Patch:</emphasis>
4902 Before modifying source code, you need to create a new
4903 patch.
4904 To create a new patch file, use
4905 <filename>quilt new</filename> as below:
4906 <literallayout class='monospaced'>
4907 $ quilt new my_changes.patch
4908 </literallayout>
4909 </para></listitem>
4910 <listitem><para>
4911 <emphasis>Notify Quilt and Add Files:</emphasis>
4912 After creating the patch, you need to notify Quilt about
4913 the files you plan to edit.
4914 You notify Quilt by adding the files to the patch you
4915 just created:
4916 <literallayout class='monospaced'>
4917 $ quilt add file1.c file2.c file3.c
4918 </literallayout>
4919 </para></listitem>
4920 <listitem><para>
4921 <emphasis>Edit the Files:</emphasis>
4922 Make your changes in the source code to the files you added
4923 to the patch.
4924 </para></listitem>
4925 <listitem><para>
4926 <emphasis>Test Your Changes:</emphasis>
4927 Once you have modified the source code, the easiest way to
4928 test your changes is by calling the
4929 <filename>do_compile</filename> task as shown in the
4930 following example:
4931 <literallayout class='monospaced'>
4932 $ bitbake -c compile -f <replaceable>package</replaceable>
4933 </literallayout>
4934 The <filename>-f</filename> or <filename>--force</filename>
4935 option forces the specified task to execute.
4936 If you find problems with your code, you can just keep
4937 editing and re-testing iteratively until things work
4938 as expected.
4939 <note>
4940 All the modifications you make to the temporary
4941 source code disappear once you run the
4942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4943 or
4944 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4945 tasks using BitBake (i.e.
4946 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4947 and
4948 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4949 Modifications will also disappear if you use the
4950 <filename>rm_work</filename> feature as described
4951 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004952 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4953 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004954 </note>
4955 </para></listitem>
4956 <listitem><para>
4957 <emphasis>Generate the Patch:</emphasis>
4958 Once your changes work as expected, you need to use Quilt
4959 to generate the final patch that contains all your
4960 modifications.
4961 <literallayout class='monospaced'>
4962 $ quilt refresh
4963 </literallayout>
4964 At this point, the <filename>my_changes.patch</filename>
4965 file has all your edits made to the
4966 <filename>file1.c</filename>, <filename>file2.c</filename>,
4967 and <filename>file3.c</filename> files.</para>
4968
4969 <para>You can find the resulting patch file in the
4970 <filename>patches/</filename> subdirectory of the source
4971 (<filename>S</filename>) directory.
4972 </para></listitem>
4973 <listitem><para>
4974 <emphasis>Copy the Patch File:</emphasis>
4975 For simplicity, copy the patch file into a directory
4976 named <filename>files</filename>, which you can create
4977 in the same directory that holds the recipe
4978 (<filename>.bb</filename>) file or the append
4979 (<filename>.bbappend</filename>) file.
4980 Placing the patch here guarantees that the OpenEmbedded
4981 build system will find the patch.
4982 Next, add the patch into the
4983 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4984 of the recipe.
4985 Here is an example:
4986 <literallayout class='monospaced'>
4987 SRC_URI += "file://my_changes.patch"
4988 </literallayout>
4989 </para></listitem>
4990 </orderedlist>
4991 </para>
4992 </section>
4993
4994 <section id="platdev-appdev-devshell">
4995 <title>Using a Development Shell</title>
4996
4997 <para>
4998 When debugging certain commands or even when just editing packages,
4999 <filename>devshell</filename> can be a useful tool.
5000 When you invoke <filename>devshell</filename>, all tasks up to and
5001 including
5002 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5003 are run for the specified target.
5004 Then, a new terminal is opened and you are placed in
5005 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
5006 the source directory.
5007 In the new terminal, all the OpenEmbedded build-related environment variables are
5008 still defined so you can use commands such as <filename>configure</filename> and
5009 <filename>make</filename>.
5010 The commands execute just as if the OpenEmbedded build system were executing them.
5011 Consequently, working this way can be helpful when debugging a build or preparing
5012 software to be used with the OpenEmbedded build system.
5013 </para>
5014
5015 <para>
5016 Following is an example that uses <filename>devshell</filename> on a target named
5017 <filename>matchbox-desktop</filename>:
5018 <literallayout class='monospaced'>
5019 $ bitbake matchbox-desktop -c devshell
5020 </literallayout>
5021 </para>
5022
5023 <para>
5024 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5025 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5026 variable controls what type of shell is opened.
5027 </para>
5028
5029 <para>
5030 For spawned terminals, the following occurs:
5031 <itemizedlist>
5032 <listitem><para>The <filename>PATH</filename> variable includes the
5033 cross-toolchain.</para></listitem>
5034 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5035 <filename>.pc</filename> files.</para></listitem>
5036 <listitem><para>The <filename>configure</filename> command finds the
5037 Yocto Project site files as well as any other necessary files.</para></listitem>
5038 </itemizedlist>
5039 </para>
5040
5041 <para>
5042 Within this environment, you can run configure or compile
5043 commands as if they were being run by
5044 the OpenEmbedded build system itself.
5045 As noted earlier, the working directory also automatically changes to the
5046 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5047 </para>
5048
5049 <para>
5050 To manually run a specific task using <filename>devshell</filename>,
5051 run the corresponding <filename>run.*</filename> script in
5052 the
5053 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5054 directory (e.g.,
5055 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5056 If a task's script does not exist, which would be the case if the task was
5057 skipped by way of the sstate cache, you can create the task by first running
5058 it outside of the <filename>devshell</filename>:
5059 <literallayout class='monospaced'>
5060 $ bitbake -c <replaceable>task</replaceable>
5061 </literallayout>
5062 <note><title>Notes</title>
5063 <itemizedlist>
5064 <listitem><para>Execution of a task's <filename>run.*</filename>
5065 script and BitBake's execution of a task are identical.
5066 In other words, running the script re-runs the task
5067 just as it would be run using the
5068 <filename>bitbake -c</filename> command.
5069 </para></listitem>
5070 <listitem><para>Any <filename>run.*</filename> file that does not
5071 have a <filename>.pid</filename> extension is a
5072 symbolic link (symlink) to the most recent version of that
5073 file.
5074 </para></listitem>
5075 </itemizedlist>
5076 </note>
5077 </para>
5078
5079 <para>
5080 Remember, that the <filename>devshell</filename> is a mechanism that allows
5081 you to get into the BitBake task execution environment.
5082 And as such, all commands must be called just as BitBake would call them.
5083 That means you need to provide the appropriate options for
5084 cross-compilation and so forth as applicable.
5085 </para>
5086
5087 <para>
5088 When you are finished using <filename>devshell</filename>, exit the shell
5089 or close the terminal window.
5090 </para>
5091
5092 <note><title>Notes</title>
5093 <itemizedlist>
5094 <listitem><para>
5095 It is worth remembering that when using <filename>devshell</filename>
5096 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5097 instead of just using <filename>gcc</filename>.
5098 The same applies to other applications such as <filename>binutils</filename>,
5099 <filename>libtool</filename> and so forth.
5100 BitBake sets up environment variables such as <filename>CC</filename>
5101 to assist applications, such as <filename>make</filename> to find the correct tools.
5102 </para></listitem>
5103 <listitem><para>
5104 It is also worth noting that <filename>devshell</filename> still works over
5105 X11 forwarding and similar situations.
5106 </para></listitem>
5107 </itemizedlist>
5108 </note>
5109 </section>
5110
5111 <section id="platdev-appdev-devpyshell">
5112 <title>Using a Development Python Shell</title>
5113
5114 <para>
5115 Similar to working within a development shell as described in
5116 the previous section, you can also spawn and work within an
5117 interactive Python development shell.
5118 When debugging certain commands or even when just editing packages,
5119 <filename>devpyshell</filename> can be a useful tool.
5120 When you invoke <filename>devpyshell</filename>, all tasks up to and
5121 including
5122 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5123 are run for the specified target.
5124 Then a new terminal is opened.
5125 Additionally, key Python objects and code are available in the same
5126 way they are to BitBake tasks, in particular, the data store 'd'.
5127 So, commands such as the following are useful when exploring the data
5128 store and running functions:
5129 <literallayout class='monospaced'>
Brad Bishop19323692019-04-05 15:28:33 -04005130 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005131 '/media/build1/poky/build/tmp/sysroots'
Brad Bishop19323692019-04-05 15:28:33 -04005132 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005133 '${TMPDIR}/sysroots'
5134 pydevshell> d.setVar("FOO", "bar")
Brad Bishop19323692019-04-05 15:28:33 -04005135 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005136 'bar'
5137 pydevshell> d.delVar("FOO")
Brad Bishop19323692019-04-05 15:28:33 -04005138 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005139 pydevshell> bb.build.exec_func("do_unpack", d)
5140 pydevshell>
5141 </literallayout>
5142 The commands execute just as if the OpenEmbedded build system were executing them.
5143 Consequently, working this way can be helpful when debugging a build or preparing
5144 software to be used with the OpenEmbedded build system.
5145 </para>
5146
5147 <para>
5148 Following is an example that uses <filename>devpyshell</filename> on a target named
5149 <filename>matchbox-desktop</filename>:
5150 <literallayout class='monospaced'>
5151 $ bitbake matchbox-desktop -c devpyshell
5152 </literallayout>
5153 </para>
5154
5155 <para>
5156 This command spawns a terminal and places you in an interactive
5157 Python interpreter within the OpenEmbedded build environment.
5158 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5159 variable controls what type of shell is opened.
5160 </para>
5161
5162 <para>
5163 When you are finished using <filename>devpyshell</filename>, you
5164 can exit the shell either by using Ctrl+d or closing the terminal
5165 window.
5166 </para>
5167 </section>
5168
Brad Bishop316dfdd2018-06-25 12:45:53 -04005169 <section id='dev-building'>
5170 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005171
5172 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005173 This section describes various build procedures.
5174 For example, the steps needed for a simple build, a target that
5175 uses multiple configurations, building an image for more than
5176 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005177 </para>
5178
Brad Bishop316dfdd2018-06-25 12:45:53 -04005179 <section id='dev-building-a-simple-image'>
5180 <title>Building a Simple Image</title>
5181
5182 <para>
5183 In the development environment, you need to build an image
5184 whenever you change hardware support, add or change system
5185 libraries, or add or change services that have dependencies.
5186 Several methods exist that allow you to build an image within
5187 the Yocto Project.
5188 This section presents the basic steps you need to build a
5189 simple image using BitBake from a build host running Linux.
5190 <note><title>Notes</title>
5191 <itemizedlist>
5192 <listitem><para>
5193 For information on how to build an image using
5194 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5195 see the
5196 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5197 </para></listitem>
5198 <listitem><para>
5199 For information on how to use
5200 <filename>devtool</filename> to build images, see
5201 the
5202 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5203 section in the Yocto Project Application
5204 Development and the Extensible Software Development
5205 Kit (eSDK) manual.
5206 </para></listitem>
5207 <listitem><para>
5208 For a quick example on how to build an image using
5209 the OpenEmbedded build system, see the
5210 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5211 document.
5212 </para></listitem>
5213 </itemizedlist>
5214 </note>
5215 </para>
5216
5217 <para>
5218 The build process creates an entire Linux distribution from
5219 source and places it in your
5220 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5221 under <filename>tmp/deploy/images</filename>.
5222 For detailed information on the build process using BitBake,
5223 see the
5224 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5225 section in the Yocto Project Overview and Concepts Manual.
5226 </para>
5227
5228 <para>
5229 The following figure and list overviews the build process:
5230 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5231 <orderedlist>
5232 <listitem><para>
5233 <emphasis>Set up Your Host Development System to Support
5234 Development Using the Yocto Project</emphasis>:
5235 See the
5236 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5237 section for options on how to get a build host ready to
5238 use the Yocto Project.
5239 </para></listitem>
5240 <listitem><para>
5241 <emphasis>Initialize the Build Environment:</emphasis>
5242 Initialize the build environment by sourcing the build
5243 environment script (i.e.
5244 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5245 <literallayout class='monospaced'>
5246 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5247 </literallayout></para>
5248
5249 <para>When you use the initialization script, the
5250 OpenEmbedded build system uses
5251 <filename>build</filename> as the default Build
5252 Directory in your current work directory.
5253 You can use a <replaceable>build_dir</replaceable>
5254 argument with the script to specify a different build
5255 directory.
5256 <note><title>Tip</title>
5257 A common practice is to use a different Build
5258 Directory for different targets.
5259 For example, <filename>~/build/x86</filename> for a
5260 <filename>qemux86</filename> target, and
5261 <filename>~/build/arm</filename> for a
5262 <filename>qemuarm</filename> target.
5263 </note>
5264 </para></listitem>
5265 <listitem><para>
5266 <emphasis>Make Sure Your <filename>local.conf</filename>
5267 File is Correct:</emphasis>
5268 Ensure the <filename>conf/local.conf</filename>
5269 configuration file, which is found in the Build
5270 Directory, is set up how you want it.
5271 This file defines many aspects of the build environment
5272 including the target machine architecture through the
5273 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5274 the packaging format used during the build
5275 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5276 and a centralized tarball download directory through the
5277 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5278 </para></listitem>
5279 <listitem><para>
5280 <emphasis>Build the Image:</emphasis>
5281 Build the image using the <filename>bitbake</filename>
5282 command:
5283 <literallayout class='monospaced'>
5284 $ bitbake <replaceable>target</replaceable>
5285 </literallayout>
5286 <note>
5287 For information on BitBake, see the
5288 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5289 </note>
5290 The <replaceable>target</replaceable> is the name of the
5291 recipe you want to build.
5292 Common targets are the images in
5293 <filename>meta/recipes-core/images</filename>,
5294 <filename>meta/recipes-sato/images</filename>, and so
5295 forth all found in the
5296 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5297 Or, the target can be the name of a recipe for a
5298 specific piece of software such as BusyBox.
5299 For more details about the images the OpenEmbedded build
5300 system supports, see the
5301 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5302 chapter in the Yocto Project Reference Manual.</para>
5303
5304 <para>As an example, the following command builds the
5305 <filename>core-image-minimal</filename> image:
5306 <literallayout class='monospaced'>
5307 $ bitbake core-image-minimal
5308 </literallayout>
5309 Once an image has been built, it often needs to be
5310 installed.
5311 The images and kernels built by the OpenEmbedded
5312 build system are placed in the Build Directory in
5313 <filename class="directory">tmp/deploy/images</filename>.
5314 For information on how to run pre-built images such as
5315 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5316 see the
5317 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5318 manual.
5319 For information about how to install these images,
5320 see the documentation for your particular board or
5321 machine.
5322 </para></listitem>
5323 </orderedlist>
5324 </para>
5325 </section>
5326
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005327 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5328 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005329
5330 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005331 You can use a single <filename>bitbake</filename> command
5332 to build multiple images or packages for different targets
5333 where each image or package requires a different configuration
5334 (multiple configuration builds).
5335 The builds, in this scenario, are sometimes referred to as
5336 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005337 </para>
5338
5339 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005340 This section describes how to set up for multiple
5341 configuration builds and how to account for cross-build
5342 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005343 </para>
5344
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005345 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5346 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005347
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005348 <para>
5349 To accomplish a multiple configuration build, you must
5350 define each target's configuration separately using
5351 a parallel configuration file in the
5352 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5353 and you must follow a required file hierarchy.
5354 Additionally, you must enable the multiple configuration
5355 builds in your <filename>local.conf</filename> file.
5356 </para>
5357
5358 <para>
5359 Follow these steps to set up and execute multiple
5360 configuration builds:
5361 <itemizedlist>
5362 <listitem><para>
5363 <emphasis>Create Separate Configuration Files</emphasis>:
5364 You need to create a single configuration file for
5365 each build target (each multiconfig).
5366 Minimally, each configuration file must define the
5367 machine and the temporary directory BitBake uses
5368 for the build.
5369 Suggested practice dictates that you do not
5370 overlap the temporary directories
5371 used during the builds.
5372 However, it is possible that you can share the
5373 temporary directory
5374 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5375 For example, consider a scenario with two
5376 different multiconfigs for the same
5377 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5378 two distributions such as "poky" and "poky-lsb".
5379 In this case, you might want to use the same
5380 <filename>TMPDIR</filename>.</para>
5381
5382 <para>Here is an example showing the minimal
5383 statements needed in a configuration file for
5384 a "qemux86" target whose temporary build directory
5385 is <filename>tmpmultix86</filename>:
5386 <literallayout class='monospaced'>
5387 MACHINE="qemux86"
5388 TMPDIR="${TOPDIR}/tmpmultix86"
5389 </literallayout></para>
5390
5391 <para>The location for these multiconfig
5392 configuration files is specific.
5393 They must reside in the current build directory in
5394 a sub-directory of <filename>conf</filename> named
5395 <filename>multiconfig</filename>.
5396 Following is an example that defines two
5397 configuration files for the "x86" and "arm"
5398 multiconfigs:
5399 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5400 </para>
5401
5402 <para>The reason for this required file hierarchy
5403 is because the <filename>BBPATH</filename> variable
5404 is not constructed until the layers are parsed.
5405 Consequently, using the configuration file as a
5406 pre-configuration file is not possible unless it is
5407 located in the current working directory.
5408 </para></listitem>
5409 <listitem><para>
5410 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5411 Use the
5412 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5413 variable in your
5414 <filename>conf/local.conf</filename> configuration
5415 file to specify each multiconfig.
5416 Continuing with the example from the previous
5417 figure, the <filename>BBMULTICONFIG</filename>
5418 variable needs to enable two multiconfigs: "x86"
5419 and "arm" by specifying each configuration file:
5420 <literallayout class='monospaced'>
5421 BBMULTICONFIG = "x86 arm"
5422 </literallayout>
5423 </para></listitem>
5424 <listitem><para>
5425 <emphasis>Launch BitBake</emphasis>:
5426 Use the following BitBake command form to launch the
5427 multiple configuration build:
5428 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005429 $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005430 </literallayout>
5431 For the example in this section, the following
5432 command applies:
5433 <literallayout class='monospaced'>
5434 $ bitbake multiconfig:x86:core-image-minimal multiconfig:arm:core-image-sato
5435 </literallayout>
5436 The previous BitBake command builds a
5437 <filename>core-image-minimal</filename> image that
5438 is configured through the
5439 <filename>x86.conf</filename> configuration file
5440 and builds a <filename>core-image-sato</filename>
5441 image that is configured through the
5442 <filename>arm.conf</filename> configuration file.
5443 </para></listitem>
5444 </itemizedlist>
5445 <note>
5446 Support for multiple configuration builds in the
5447 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5448 not include Shared State (sstate) optimizations.
5449 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005450 in, for example, two different
5451 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005452 either loads from an existing sstate cache for that
5453 build at the start or builds the object fresh.
5454 </note>
5455 </para>
5456 </section>
5457
5458 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5459 <title>Enabling Multiple Configuration Build Dependencies</title>
5460
5461 <para>
5462 Sometimes dependencies can exist between targets
5463 (multiconfigs) in a multiple configuration build.
5464 For example, suppose that in order to build a
5465 <filename>core-image-sato</filename> image for an "x86"
5466 multiconfig, the root filesystem of an "arm"
5467 multiconfig must exist.
5468 This dependency is essentially that the
5469 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5470 task in the <filename>core-image-sato</filename> recipe
5471 depends on the completion of the
5472 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5473 task of the <filename>core-image-minimal</filename>
5474 recipe.
5475 </para>
5476
5477 <para>
5478 To enable dependencies in a multiple configuration
5479 build, you must declare the dependencies in the recipe
5480 using the following statement form:
5481 <literallayout class='monospaced'>
5482 <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>"
5483 </literallayout>
5484 To better show how to use this statement, consider the
5485 example scenario from the first paragraph of this section.
5486 The following statement needs to be added to the recipe
5487 that builds the <filename>core-image-sato</filename>
5488 image:
5489 <literallayout class='monospaced'>
5490 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_rootfs"
5491 </literallayout>
5492 In this example, the
5493 <replaceable>from_multiconfig</replaceable> is "x86".
5494 The <replaceable>to_multiconfig</replaceable> is "arm".
5495 The task on which the <filename>do_image</filename> task
5496 in the recipe depends is the <filename>do_rootfs</filename>
5497 task from the <filename>core-image-minimal</filename>
5498 recipe associated with the "arm" multiconfig.
5499 </para>
5500
5501 <para>
5502 Once you set up this dependency, you can build the
5503 "x86" multiconfig using a BitBake command as follows:
5504 <literallayout class='monospaced'>
5505 $ bitbake multiconfig:x86:core-image-sato
5506 </literallayout>
5507 This command executes all the tasks needed to create
5508 the <filename>core-image-sato</filename> image for the
5509 "x86" multiconfig.
5510 Because of the dependency, BitBake also executes through
5511 the <filename>do_rootfs</filename> task for the "arm"
5512 multiconfig build.
5513 </para>
5514
5515 <para>
5516 Having a recipe depend on the root filesystem of another
5517 build might not seem that useful.
5518 Consider this change to the statement in the
5519 <filename>core-image-sato</filename> recipe:
5520 <literallayout class='monospaced'>
5521 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_image"
5522 </literallayout>
5523 In this case, BitBake must create the
5524 <filename>core-image-minimal</filename> image for the
5525 "arm" build since the "x86" build depends on it.
5526 </para>
5527
5528 <para>
5529 Because "x86" and "arm" are enabled for multiple
5530 configuration builds and have separate configuration
5531 files, BitBake places the artifacts for each build in the
5532 respective temporary build directories (i.e.
5533 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5534 </para>
5535 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005536 </section>
5537
5538 <section id='building-an-initramfs-image'>
5539 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5540
5541 <para>
5542 An initial RAM filesystem (initramfs) image provides a temporary
5543 root filesystem used for early system initialization (e.g.
5544 loading of modules needed to locate and mount the "real" root
5545 filesystem).
5546 <note>
5547 The initramfs image is the successor of initial RAM disk
5548 (initrd).
5549 It is a "copy in and out" (cpio) archive of the initial
5550 filesystem that gets loaded into memory during the Linux
5551 startup process.
5552 Because Linux uses the contents of the archive during
5553 initialization, the initramfs image needs to contain all of the
5554 device drivers and tools needed to mount the final root
5555 filesystem.
5556 </note>
5557 </para>
5558
5559 <para>
5560 Follow these steps to create an initramfs image:
5561 <orderedlist>
5562 <listitem><para>
5563 <emphasis>Create the initramfs Image Recipe:</emphasis>
5564 You can reference the
5565 <filename>core-image-minimal-initramfs.bb</filename>
5566 recipe found in the <filename>meta/recipes-core</filename>
5567 directory of the
5568 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5569 as an example from which to work.
5570 </para></listitem>
5571 <listitem><para>
5572 <emphasis>Decide if You Need to Bundle the initramfs Image
5573 Into the Kernel Image:</emphasis>
5574 If you want the initramfs image that is built to be
5575 bundled in with the kernel image, set the
5576 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5577 variable to "1" in your <filename>local.conf</filename>
5578 configuration file and set the
5579 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5580 variable in the recipe that builds the kernel image.
5581 <note><title>Tip</title>
5582 It is recommended that you do bundle the initramfs
5583 image with the kernel image to avoid circular
5584 dependencies between the kernel recipe and the
5585 initramfs recipe should the initramfs image
5586 include kernel modules.
5587 </note>
5588 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5589 flag causes the initramfs image to be unpacked
5590 into the <filename>${B}/usr/</filename> directory.
5591 The unpacked initramfs image is then passed to the kernel's
5592 <filename>Makefile</filename> using the
5593 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5594 variable, allowing the initramfs image to be built into
5595 the kernel normally.
5596 <note>
5597 If you choose to not bundle the initramfs image with
5598 the kernel image, you are essentially using an
5599 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5600 Creating an initrd is handled primarily through the
5601 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5602 <filename>INITRD_LIVE</filename>, and
5603 <filename>INITRD_IMAGE_LIVE</filename> variables.
5604 For more information, see the
5605 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5606 file.
5607 </note>
5608 </para></listitem>
5609 <listitem><para>
5610 <emphasis>Optionally Add Items to the initramfs Image
5611 Through the initramfs Image Recipe:</emphasis>
5612 If you add items to the initramfs image by way of its
5613 recipe, you should use
5614 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5615 rather than
5616 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5617 <filename>PACKAGE_INSTALL</filename> gives more direct
5618 control of what is added to the image as compared to
5619 the defaults you might not necessarily want that are
5620 set by the
5621 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5622 or
5623 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5624 classes.
5625 </para></listitem>
5626 <listitem><para>
5627 <emphasis>Build the Kernel Image and the initramfs
5628 Image:</emphasis>
5629 Build your kernel image using BitBake.
5630 Because the initramfs image recipe is a dependency of the
5631 kernel image, the initramfs image is built as well and
5632 bundled with the kernel image if you used the
5633 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5634 variable described earlier.
5635 </para></listitem>
5636 </orderedlist>
5637 </para>
5638 </section>
5639
5640 <section id='building-a-tiny-system'>
5641 <title>Building a Tiny System</title>
5642
5643 <para>
5644 Very small distributions have some significant advantages such
5645 as requiring less on-die or in-package memory (cheaper), better
5646 performance through efficient cache usage, lower power requirements
5647 due to less memory, faster boot times, and reduced development
5648 overhead.
5649 Some real-world examples where a very small distribution gives
5650 you distinct advantages are digital cameras, medical devices,
5651 and small headless systems.
5652 </para>
5653
5654 <para>
5655 This section presents information that shows you how you can
5656 trim your distribution to even smaller sizes than the
5657 <filename>poky-tiny</filename> distribution, which is around
5658 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5659 </para>
5660
5661 <section id='tiny-system-overview'>
5662 <title>Overview</title>
5663
5664 <para>
5665 The following list presents the overall steps you need to
5666 consider and perform to create distributions with smaller
5667 root filesystems, achieve faster boot times, maintain your critical
5668 functionality, and avoid initial RAM disks:
5669 <itemizedlist>
5670 <listitem><para>
5671 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5672 </para></listitem>
5673 <listitem><para>
5674 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5675 </para></listitem>
5676 <listitem><para>
5677 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5678 </para></listitem>
5679 <listitem><para>
5680 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5681 </para></listitem>
5682 <listitem><para>
5683 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5684 </para></listitem>
5685 <listitem><para>
5686 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5687 </para></listitem>
5688 <listitem><para>
5689 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5690 </para></listitem>
5691 </itemizedlist>
5692 </para>
5693 </section>
5694
5695 <section id='goals-and-guiding-principles'>
5696 <title>Goals and Guiding Principles</title>
5697
5698 <para>
5699 Before you can reach your destination, you need to know
5700 where you are going.
5701 Here is an example list that you can use as a guide when
5702 creating very small distributions:
5703 <itemizedlist>
5704 <listitem><para>Determine how much space you need
5705 (e.g. a kernel that is 1 Mbyte or less and
5706 a root filesystem that is 3 Mbytes or less).
5707 </para></listitem>
5708 <listitem><para>Find the areas that are currently
5709 taking 90% of the space and concentrate on reducing
5710 those areas.
5711 </para></listitem>
5712 <listitem><para>Do not create any difficult "hacks"
5713 to achieve your goals.</para></listitem>
5714 <listitem><para>Leverage the device-specific
5715 options.</para></listitem>
5716 <listitem><para>Work in a separate layer so that you
5717 keep changes isolated.
5718 For information on how to create layers, see
5719 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5720 </para></listitem>
5721 </itemizedlist>
5722 </para>
5723 </section>
5724
5725 <section id='understand-what-gives-your-image-size'>
5726 <title>Understand What Contributes to Your Image Size</title>
5727
5728 <para>
5729 It is easiest to have something to start with when creating
5730 your own distribution.
5731 You can use the Yocto Project out-of-the-box to create the
5732 <filename>poky-tiny</filename> distribution.
5733 Ultimately, you will want to make changes in your own
5734 distribution that are likely modeled after
5735 <filename>poky-tiny</filename>.
5736 <note>
5737 To use <filename>poky-tiny</filename> in your build,
5738 set the
5739 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5740 variable in your
5741 <filename>local.conf</filename> file to "poky-tiny"
5742 as described in the
5743 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5744 section.
5745 </note>
5746 </para>
5747
5748 <para>
5749 Understanding some memory concepts will help you reduce the
5750 system size.
5751 Memory consists of static, dynamic, and temporary memory.
5752 Static memory is the TEXT (code), DATA (initialized data
5753 in the code), and BSS (uninitialized data) sections.
5754 Dynamic memory represents memory that is allocated at runtime:
5755 stacks, hash tables, and so forth.
5756 Temporary memory is recovered after the boot process.
5757 This memory consists of memory used for decompressing
5758 the kernel and for the <filename>__init__</filename>
5759 functions.
5760 </para>
5761
5762 <para>
5763 To help you see where you currently are with kernel and root
5764 filesystem sizes, you can use two tools found in the
5765 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5766 the <filename>scripts/tiny/</filename> directory:
5767 <itemizedlist>
5768 <listitem><para><filename>ksize.py</filename>: Reports
5769 component sizes for the kernel build objects.
5770 </para></listitem>
5771 <listitem><para><filename>dirsize.py</filename>: Reports
5772 component sizes for the root filesystem.</para></listitem>
5773 </itemizedlist>
5774 This next tool and command help you organize configuration
5775 fragments and view file dependencies in a human-readable form:
5776 <itemizedlist>
5777 <listitem><para><filename>merge_config.sh</filename>:
5778 Helps you manage configuration files and fragments
5779 within the kernel.
5780 With this tool, you can merge individual configuration
5781 fragments together.
5782 The tool allows you to make overrides and warns you
5783 of any missing configuration options.
5784 The tool is ideal for allowing you to iterate on
5785 configurations, create minimal configurations, and
5786 create configuration files for different machines
5787 without having to duplicate your process.</para>
5788 <para>The <filename>merge_config.sh</filename> script is
5789 part of the Linux Yocto kernel Git repositories
5790 (i.e. <filename>linux-yocto-3.14</filename>,
5791 <filename>linux-yocto-3.10</filename>,
5792 <filename>linux-yocto-3.8</filename>, and so forth)
5793 in the
5794 <filename>scripts/kconfig</filename> directory.</para>
5795 <para>For more information on configuration fragments,
5796 see the
5797 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5798 section in the Yocto Project Linux Kernel Development
5799 Manual.
5800 </para></listitem>
5801 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5802 Using the BitBake command with these options brings up
5803 a Dependency Explorer from which you can view file
5804 dependencies.
5805 Understanding these dependencies allows you to make
5806 informed decisions when cutting out various pieces of the
5807 kernel and root filesystem.</para></listitem>
5808 </itemizedlist>
5809 </para>
5810 </section>
5811
5812 <section id='trim-the-root-filesystem'>
5813 <title>Trim the Root Filesystem</title>
5814
5815 <para>
5816 The root filesystem is made up of packages for booting,
5817 libraries, and applications.
5818 To change things, you can configure how the packaging happens,
5819 which changes the way you build them.
5820 You can also modify the filesystem itself or select a different
5821 filesystem.
5822 </para>
5823
5824 <para>
5825 First, find out what is hogging your root filesystem by running the
5826 <filename>dirsize.py</filename> script from your root directory:
5827 <literallayout class='monospaced'>
5828 $ cd <replaceable>root-directory-of-image</replaceable>
5829 $ dirsize.py 100000 > dirsize-100k.log
5830 $ cat dirsize-100k.log
5831 </literallayout>
5832 You can apply a filter to the script to ignore files under
5833 a certain size.
5834 The previous example filters out any files below 100 Kbytes.
5835 The sizes reported by the tool are uncompressed, and thus
5836 will be smaller by a relatively constant factor in a
5837 compressed root filesystem.
5838 When you examine your log file, you can focus on areas of the
5839 root filesystem that take up large amounts of memory.
5840 </para>
5841
5842 <para>
5843 You need to be sure that what you eliminate does not cripple
5844 the functionality you need.
5845 One way to see how packages relate to each other is by using
5846 the Dependency Explorer UI with the BitBake command:
5847 <literallayout class='monospaced'>
5848 $ cd <replaceable>image-directory</replaceable>
5849 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5850 </literallayout>
5851 Use the interface to select potential packages you wish to
5852 eliminate and see their dependency relationships.
5853 </para>
5854
5855 <para>
5856 When deciding how to reduce the size, get rid of packages that
5857 result in minimal impact on the feature set.
5858 For example, you might not need a VGA display.
5859 Or, you might be able to get by with <filename>devtmpfs</filename>
5860 and <filename>mdev</filename> instead of
5861 <filename>udev</filename>.
5862 </para>
5863
5864 <para>
5865 Use your <filename>local.conf</filename> file to make changes.
5866 For example, to eliminate <filename>udev</filename> and
5867 <filename>glib</filename>, set the following in the
5868 local configuration file:
5869 <literallayout class='monospaced'>
5870 VIRTUAL-RUNTIME_dev_manager = ""
5871 </literallayout>
5872 </para>
5873
5874 <para>
5875 Finally, you should consider exactly the type of root
5876 filesystem you need to meet your needs while also reducing
5877 its size.
5878 For example, consider <filename>cramfs</filename>,
5879 <filename>squashfs</filename>, <filename>ubifs</filename>,
5880 <filename>ext2</filename>, or an <filename>initramfs</filename>
5881 using <filename>initramfs</filename>.
5882 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5883 journal.
5884 If you are okay with running read-only, you do not need this
5885 journal.
5886 </para>
5887
5888 <note>
5889 After each round of elimination, you need to rebuild your
5890 system and then use the tools to see the effects of your
5891 reductions.
5892 </note>
5893 </section>
5894
5895 <section id='trim-the-kernel'>
5896 <title>Trim the Kernel</title>
5897
5898 <para>
5899 The kernel is built by including policies for hardware-independent
5900 aspects.
5901 What subsystems do you enable?
5902 For what architecture are you building?
5903 Which drivers do you build by default?
5904 <note>You can modify the kernel source if you want to help
5905 with boot time.
5906 </note>
5907 </para>
5908
5909 <para>
5910 Run the <filename>ksize.py</filename> script from the top-level
5911 Linux build directory to get an idea of what is making up
5912 the kernel:
5913 <literallayout class='monospaced'>
5914 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5915 $ ksize.py > ksize.log
5916 $ cat ksize.log
5917 </literallayout>
5918 When you examine the log, you will see how much space is
5919 taken up with the built-in <filename>.o</filename> files for
5920 drivers, networking, core kernel files, filesystem, sound,
5921 and so forth.
5922 The sizes reported by the tool are uncompressed, and thus
5923 will be smaller by a relatively constant factor in a compressed
5924 kernel image.
5925 Look to reduce the areas that are large and taking up around
5926 the "90% rule."
5927 </para>
5928
5929 <para>
5930 To examine, or drill down, into any particular area, use the
5931 <filename>-d</filename> option with the script:
5932 <literallayout class='monospaced'>
5933 $ ksize.py -d > ksize.log
5934 </literallayout>
5935 Using this option breaks out the individual file information
5936 for each area of the kernel (e.g. drivers, networking, and
5937 so forth).
5938 </para>
5939
5940 <para>
5941 Use your log file to see what you can eliminate from the kernel
5942 based on features you can let go.
5943 For example, if you are not going to need sound, you do not
5944 need any drivers that support sound.
5945 </para>
5946
5947 <para>
5948 After figuring out what to eliminate, you need to reconfigure
5949 the kernel to reflect those changes during the next build.
5950 You could run <filename>menuconfig</filename> and make all your
5951 changes at once.
5952 However, that makes it difficult to see the effects of your
5953 individual eliminations and also makes it difficult to replicate
5954 the changes for perhaps another target device.
5955 A better method is to start with no configurations using
5956 <filename>allnoconfig</filename>, create configuration
5957 fragments for individual changes, and then manage the
5958 fragments into a single configuration file using
5959 <filename>merge_config.sh</filename>.
5960 The tool makes it easy for you to iterate using the
5961 configuration change and build cycle.
5962 </para>
5963
5964 <para>
5965 Each time you make configuration changes, you need to rebuild
5966 the kernel and check to see what impact your changes had on
5967 the overall size.
5968 </para>
5969 </section>
5970
5971 <section id='remove-package-management-requirements'>
5972 <title>Remove Package Management Requirements</title>
5973
5974 <para>
5975 Packaging requirements add size to the image.
5976 One way to reduce the size of the image is to remove all the
5977 packaging requirements from the image.
5978 This reduction includes both removing the package manager
5979 and its unique dependencies as well as removing the package
5980 management data itself.
5981 </para>
5982
5983 <para>
5984 To eliminate all the packaging requirements for an image,
5985 be sure that "package-management" is not part of your
5986 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5987 statement for the image.
5988 When you remove this feature, you are removing the package
5989 manager as well as its dependencies from the root filesystem.
5990 </para>
5991 </section>
5992
5993 <section id='look-for-other-ways-to-minimize-size'>
5994 <title>Look for Other Ways to Minimize Size</title>
5995
5996 <para>
5997 Depending on your particular circumstances, other areas that you
5998 can trim likely exist.
5999 The key to finding these areas is through tools and methods
6000 described here combined with experimentation and iteration.
6001 Here are a couple of areas to experiment with:
6002 <itemizedlist>
6003 <listitem><para><filename>glibc</filename>:
6004 In general, follow this process:
6005 <orderedlist>
6006 <listitem><para>Remove <filename>glibc</filename>
6007 features from
6008 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6009 that you think you do not need.</para></listitem>
6010 <listitem><para>Build your distribution.
6011 </para></listitem>
6012 <listitem><para>If the build fails due to missing
6013 symbols in a package, determine if you can
6014 reconfigure the package to not need those
6015 features.
6016 For example, change the configuration to not
6017 support wide character support as is done for
6018 <filename>ncurses</filename>.
6019 Or, if support for those characters is needed,
6020 determine what <filename>glibc</filename>
6021 features provide the support and restore the
6022 configuration.
6023 </para></listitem>
6024 <listitem><para>Rebuild and repeat the process.
6025 </para></listitem>
6026 </orderedlist></para></listitem>
6027 <listitem><para><filename>busybox</filename>:
6028 For BusyBox, use a process similar as described for
6029 <filename>glibc</filename>.
6030 A difference is you will need to boot the resulting
6031 system to see if you are able to do everything you
6032 expect from the running system.
6033 You need to be sure to integrate configuration fragments
6034 into Busybox because BusyBox handles its own core
6035 features and then allows you to add configuration
6036 fragments on top.
6037 </para></listitem>
6038 </itemizedlist>
6039 </para>
6040 </section>
6041
6042 <section id='iterate-on-the-process'>
6043 <title>Iterate on the Process</title>
6044
6045 <para>
6046 If you have not reached your goals on system size, you need
6047 to iterate on the process.
6048 The process is the same.
6049 Use the tools and see just what is taking up 90% of the root
6050 filesystem and the kernel.
6051 Decide what you can eliminate without limiting your device
6052 beyond what you need.
6053 </para>
6054
6055 <para>
6056 Depending on your system, a good place to look might be
6057 Busybox, which provides a stripped down
6058 version of Unix tools in a single, executable file.
6059 You might be able to drop virtual terminal services or perhaps
6060 ipv6.
6061 </para>
6062 </section>
6063 </section>
6064
6065 <section id='building-images-for-more-than-one-machine'>
6066 <title>Building Images for More than One Machine</title>
6067
6068 <para>
6069 A common scenario developers face is creating images for several
6070 different machines that use the same software environment.
6071 In this situation, it is tempting to set the
6072 tunings and optimization flags for each build specifically for
6073 the targeted hardware (i.e. "maxing out" the tunings).
6074 Doing so can considerably add to build times and package feed
6075 maintenance collectively for the machines.
6076 For example, selecting tunes that are extremely specific to a
6077 CPU core used in a system might enable some micro optimizations
6078 in GCC for that particular system but would otherwise not gain
6079 you much of a performance difference across the other systems
6080 as compared to using a more general tuning across all the builds
6081 (e.g. setting
6082 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6083 specifically for each machine's build).
6084 Rather than "max out" each build's tunings, you can take steps that
6085 cause the OpenEmbedded build system to reuse software across the
6086 various machines where it makes sense.
6087 </para>
6088
6089 <para>
6090 If build speed and package feed maintenance are considerations,
6091 you should consider the points in this section that can help you
6092 optimize your tunings to best consider build times and package
6093 feed maintenance.
6094 <itemizedlist>
6095 <listitem><para>
6096 <emphasis>Share the Build Directory:</emphasis>
6097 If at all possible, share the
6098 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6099 across builds.
6100 The Yocto Project supports switching between different
6101 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6102 values in the same <filename>TMPDIR</filename>.
6103 This practice is well supported and regularly used by
6104 developers when building for multiple machines.
6105 When you use the same <filename>TMPDIR</filename> for
6106 multiple machine builds, the OpenEmbedded build system can
6107 reuse the existing native and often cross-recipes for
6108 multiple machines.
6109 Thus, build time decreases.
6110 <note>
6111 If
6112 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6113 settings change or fundamental configuration settings
6114 such as the filesystem layout, you need to work with
6115 a clean <filename>TMPDIR</filename>.
6116 Sharing <filename>TMPDIR</filename> under these
6117 circumstances might work but since it is not
6118 guaranteed, you should use a clean
6119 <filename>TMPDIR</filename>.
6120 </note>
6121 </para></listitem>
6122 <listitem><para>
6123 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6124 By default, the OpenEmbedded build system enables three
6125 levels of package architectures: "all", "tune" or "package",
6126 and "machine".
6127 Any given recipe usually selects one of these package
6128 architectures (types) for its output.
6129 Depending for what a given recipe creates packages, making
6130 sure you enable the appropriate package architecture can
6131 directly impact the build time.</para>
6132
6133 <para>A recipe that just generates scripts can enable
6134 "all" architecture because there are no binaries to build.
6135 To specifically enable "all" architecture, be sure your
6136 recipe inherits the
6137 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6138 class.
6139 This class is useful for "all" architectures because it
6140 configures many variables so packages can be used across
6141 multiple architectures.</para>
6142
6143 <para>If your recipe needs to generate packages that are
6144 machine-specific or when one of the build or runtime
6145 dependencies is already machine-architecture dependent,
6146 which makes your recipe also machine-architecture dependent,
6147 make sure your recipe enables the "machine" package
6148 architecture through the
6149 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6150 variable:
6151 <literallayout class='monospaced'>
6152 PACKAGE_ARCH = "${MACHINE_ARCH}"
6153 </literallayout>
6154 When you do not specifically enable a package
6155 architecture through the
6156 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6157 The OpenEmbedded build system defaults to the
6158 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6159 setting:
6160 <literallayout class='monospaced'>
6161 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6162 </literallayout>
6163 </para></listitem>
6164 <listitem><para>
6165 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6166 Some tunes are more generic and can run on multiple targets
6167 (e.g. an <filename>armv5</filename> set of packages could
6168 run on <filename>armv6</filename> and
6169 <filename>armv7</filename> processors in most cases).
6170 Similarly, <filename>i486</filename> binaries could work
6171 on <filename>i586</filename> and higher processors.
6172 You should realize, however, that advances on newer
6173 processor versions would not be used.</para>
6174
6175 <para>If you select the same tune for several different
6176 machines, the OpenEmbedded build system reuses software
6177 previously built, thus speeding up the overall build time.
6178 Realize that even though a new sysroot for each machine is
6179 generated, the software is not recompiled and only one
6180 package feed exists.
6181 </para></listitem>
6182 <listitem><para>
6183 <emphasis>Manage Granular Level Packaging:</emphasis>
6184 Sometimes cases exist where injecting another level of
6185 package architecture beyond the three higher levels noted
6186 earlier can be useful.
6187 For example, consider how NXP (formerly Freescale) allows
6188 for the easy reuse of binary packages in their layer
6189 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6190 In this example, the
6191 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6192 class shares GPU packages for i.MX53 boards because
6193 all boards share the AMD GPU.
6194 The i.MX6-based boards can do the same because all boards
6195 share the Vivante GPU.
6196 This class inspects the BitBake datastore to identify if
6197 the package provides or depends on one of the
6198 sub-architecture values.
6199 If so, the class sets the
6200 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6201 value based on the <filename>MACHINE_SUBARCH</filename>
6202 value.
6203 If the package does not provide or depend on one of the
6204 sub-architecture values but it matches a value in the
6205 machine-specific filter, it sets
6206 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6207 This behavior reduces the number of packages built and
6208 saves build time by reusing binaries.
6209 </para></listitem>
6210 <listitem><para>
6211 <emphasis>Use Tools to Debug Issues:</emphasis>
6212 Sometimes you can run into situations where software is
6213 being rebuilt when you think it should not be.
6214 For example, the OpenEmbedded build system might not be
6215 using shared state between machines when you think it
6216 should be.
6217 These types of situations are usually due to references
6218 to machine-specific variables such as
6219 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6220 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6221 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6222 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6223 and so forth in code that is supposed to only be
6224 tune-specific or when the recipe depends
6225 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6226 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6227 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6228 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6229 and so forth) on some other recipe that already has
6230 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6231 defined as "${MACHINE_ARCH}".
6232 <note>
6233 Patches to fix any issues identified are most welcome
6234 as these issues occasionally do occur.
6235 </note></para>
6236
6237 <para>For such cases, you can use some tools to help you
6238 sort out the situation:
6239 <itemizedlist>
6240 <listitem><para>
6241 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6242 You can find this tool in the
6243 <filename>scripts</filename> directory of the
6244 Source Repositories.
6245 See the comments in the script for information on
6246 how to use the tool.
6247 </para></listitem>
6248 <listitem><para>
6249 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6250 Using this option causes BitBake to try to
6251 establish the closest signature match it can
6252 (e.g. in the shared state cache) and then run
6253 <filename>bitbake-diffsigs</filename> over the
6254 matches to determine the stamps and delta where
6255 these two stamp trees diverge.
6256 </para></listitem>
6257 </itemizedlist>
6258 </para></listitem>
6259 </itemizedlist>
6260 </para>
6261 </section>
6262
6263 <section id="building-software-from-an-external-source">
6264 <title>Building Software from an External Source</title>
6265
6266 <para>
6267 By default, the OpenEmbedded build system uses the
6268 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6269 when building source code.
6270 The build process involves fetching the source files, unpacking
6271 them, and then patching them if necessary before the build takes
6272 place.
6273 </para>
6274
6275 <para>
6276 Situations exist where you might want to build software from source
6277 files that are external to and thus outside of the
6278 OpenEmbedded build system.
6279 For example, suppose you have a project that includes a new BSP with
6280 a heavily customized kernel.
6281 And, you want to minimize exposing the build system to the
6282 development team so that they can focus on their project and
6283 maintain everyone's workflow as much as possible.
6284 In this case, you want a kernel source directory on the development
6285 machine where the development occurs.
6286 You want the recipe's
6287 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6288 variable to point to the external directory and use it as is, not
6289 copy it.
6290 </para>
6291
6292 <para>
6293 To build from software that comes from an external source, all you
6294 need to do is inherit the
6295 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6296 class and then set the
6297 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6298 variable to point to your external source code.
6299 Here are the statements to put in your
6300 <filename>local.conf</filename> file:
6301 <literallayout class='monospaced'>
6302 INHERIT += "externalsrc"
6303 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6304 </literallayout>
6305 </para>
6306
6307 <para>
6308 This next example shows how to accomplish the same thing by setting
6309 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6310 recipe's append file:
6311 <literallayout class='monospaced'>
6312 EXTERNALSRC = "<replaceable>path</replaceable>"
6313 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6314 </literallayout>
6315 <note>
6316 In order for these settings to take effect, you must globally
6317 or locally inherit the
6318 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6319 class.
6320 </note>
6321 </para>
6322
6323 <para>
6324 By default, <filename>externalsrc.bbclass</filename> builds
6325 the source code in a directory separate from the external source
6326 directory as specified by
6327 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6328 If you need to have the source built in the same directory in
6329 which it resides, or some other nominated directory, you can set
6330 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6331 to point to that directory:
6332 <literallayout class='monospaced'>
6333 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6334 </literallayout>
6335 </para>
6336 </section>
Brad Bishop19323692019-04-05 15:28:33 -04006337
6338 <section id="replicating-a-build-offline">
6339 <title>Replicating a Build Offline</title>
6340
6341 <para>
6342 It can be useful to take a "snapshot" of upstream sources
6343 used in a build and then use that "snapshot" later to
6344 replicate the build offline.
6345 To do so, you need to first prepare and populate your downloads
6346 directory your "snapshot" of files.
6347 Once your downloads directory is ready, you can use it at
6348 any time and from any machine to replicate your build.
6349 </para>
6350
6351 <para>
6352 Follow these steps to populate your Downloads directory:
6353 <orderedlist>
6354 <listitem><para>
6355 <emphasis>Create a Clean Downloads Directory:</emphasis>
6356 Start with an empty downloads directory
6357 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>).
6358 You start with an empty downloads directory by either
6359 removing the files in the existing directory or by
6360 setting
6361 <filename>DL_DIR</filename> to point to either an
6362 empty location or one that does not yet exist.
6363 </para></listitem>
6364 <listitem><para>
6365 <emphasis>Generate Tarballs of the Source Git Repositories:</emphasis>
6366 Edit your <filename>local.conf</filename> configuration
6367 file as follows:
6368 <literallayout class='monospaced'>
6369 DL_DIR = "/home/<replaceable>your-download-dir</replaceable>/"
6370 BB_GENERATE_MIRROR_TARBALLS = "1"
6371 </literallayout>
6372 During the fetch process in the next step, BitBake
6373 gathers the source files and creates tarballs in
6374 the directory pointed to by <filename>DL_DIR</filename>.
6375 See the
6376 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
6377 variable for more information.
6378 </para></listitem>
6379 <listitem><para>
6380 <emphasis>Populate Your Downloads Directory Without Building:</emphasis>
6381 Use BitBake to fetch your sources but inhibit the
6382 build:
6383 <literallayout class='monospaced'>
6384 $ bitbake <replaceable>target</replaceable> --runonly=fetch
6385 </literallayout>
6386 The downloads directory (i.e.
6387 <filename>${DL_DIR}</filename>) now has a "snapshot" of
6388 the source files in the form of tarballs, which can
6389 be used for the build.
6390 </para></listitem>
6391 <listitem><para>
6392 <emphasis>Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory:</emphasis>
6393 If you want, you can clean up your downloads directory
6394 by removing any Git or other Source Control Management
6395 (SCM) subdirectories such as
6396 <filename>${DL_DIR}/git2/*</filename>.
6397 The tarballs already contain these subdirectories.
6398 </para></listitem>
6399 </orderedlist>
6400 </para>
6401
6402 <para>
6403 Once your downloads directory has everything it needs regarding
6404 source files, you can create your "own-mirror" and build
6405 your target.
6406 Understand that you can use the files to build the target
6407 offline from any machine and at any time.
6408 </para>
6409
6410 <para>
6411 Follow these steps to build your target using the files in the
6412 downloads directory:
6413 <orderedlist>
6414 <listitem><para>
6415 <emphasis>Using Local Files Only:</emphasis>
6416 Inside your <filename>local.conf</filename> file, add
6417 the
6418 <ulink url='&YOCTO_DOCS_REF_URL;#var-SOURCE_MIRROR_URL'><filename>SOURCE_MIRROR_URL</filename></ulink>
6419 variable,
6420 inherit the <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-own-mirrors'><filename>own-mirrors</filename></ulink>
6421 class, and use the
6422 <ulink url='&YOCTO_DOCS_BB_URL;#var-bb-BB_NO_NETWORK'><filename>BB_NO_NETWORK</filename></ulink>
6423 variable to your <filename>local.conf</filename>.
6424 <literallayout class='monospaced'>
6425 SOURCE_MIRROR_URL ?= "file:///home/<replaceable>your-download-dir</replaceable>/"
6426 INHERIT += "own-mirrors"
6427 BB_NO_NETWORK = "1"
6428 </literallayout>
6429 The <filename>SOURCE_MIRROR_URL</filename> and
6430 <filename>own-mirror</filename> class set up the system
6431 to use the downloads directory as your "own mirror".
6432 Using the <filename>BB_NO_NETWORK</filename>
6433 variable makes sure that BitBake's fetching process
6434 in step 3 stays local, which means files from
6435 your "own-mirror" are used.
6436 </para></listitem>
6437 <listitem><para>
6438 <emphasis>Start With a Clean Build:</emphasis>
6439 You can start with a clean build by removing the
6440 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
6441 directory or using a new
6442 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
6443 </para></listitem>
6444 <listitem><para>
6445 <emphasis>Build Your Target:</emphasis>
6446 Use BitBake to build your target:
6447 <literallayout class='monospaced'>
6448 $ bitbake <replaceable>target</replaceable>
6449 </literallayout>
6450 The build completes using the known local "snapshot" of
6451 source files from your mirror.
6452 The resulting tarballs for your "snapshot" of source
6453 files are in the downloads directory.
6454 <note>
6455 <para>The offline build does not work if recipes
6456 attempt to find the latest version of software
6457 by setting
6458 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
6459 to
6460 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink><filename>}</filename>:
6461 <literallayout class='monospaced'>
6462 SRCREV = "${AUTOREV}"
6463 </literallayout>
6464 When a recipe sets
6465 <filename>SRCREV</filename> to
6466 <filename>${AUTOREV}</filename>, the build system
6467 accesses the network in an attempt to determine the
6468 latest version of software from the SCM.
6469 Typically, recipes that use
6470 <filename>AUTOREV</filename> are custom or
6471 modified recipes.
6472 Recipes that reside in public repositories
6473 usually do not use <filename>AUTOREV</filename>.
6474 </para>
6475
6476 <para>If you do have recipes that use
6477 <filename>AUTOREV</filename>, you can take steps to
6478 still use the recipes in an offline build.
6479 Do the following:
6480 <orderedlist>
6481 <listitem><para>
6482 Use a configuration generated by
6483 enabling
6484 <link linkend='maintaining-build-output-quality'>build history</link>.
6485 </para></listitem>
6486 <listitem><para>
6487 Use the
6488 <filename>buildhistory-collect-srcrevs</filename>
6489 command to collect the stored
6490 <filename>SRCREV</filename> values from
6491 the build's history.
6492 For more information on collecting these
6493 values, see the
6494 "<link linkend='build-history-package-information'>Build History Package Information</link>"
6495 section.
6496 </para></listitem>
6497 <listitem><para>
6498 Once you have the correct source
6499 revisions, you can modify those recipes
6500 to to set <filename>SRCREV</filename>
6501 to specific versions of the software.
6502 </para></listitem>
6503 </orderedlist>
6504 </para>
6505 </note>
6506 </para></listitem>
6507 </orderedlist>
6508 </para>
6509 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006510 </section>
6511
Brad Bishop316dfdd2018-06-25 12:45:53 -04006512 <section id='speeding-up-a-build'>
6513 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006514
6515 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006516 Build time can be an issue.
6517 By default, the build system uses simple controls to try and maximize
6518 build efficiency.
6519 In general, the default settings for all the following variables
6520 result in the most efficient build times when dealing with single
6521 socket systems (i.e. a single CPU).
6522 If you have multiple CPUs, you might try increasing the default
6523 values to gain more speed.
6524 See the descriptions in the glossary for each variable for more
6525 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006526 <itemizedlist>
6527 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006528 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6529 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006530 </para></listitem>
6531 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006532 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6533 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006534 </para></listitem>
6535 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006536 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6537 Extra options passed to the <filename>make</filename> command
6538 during the
6539 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6540 task in order to specify parallel compilation on the
6541 local build host.
6542 </para></listitem>
6543 <listitem><para>
6544 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6545 Extra options passed to the <filename>make</filename> command
6546 during the
6547 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6548 task in order to specify parallel installation on the
6549 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006550 </para></listitem>
6551 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006552 As mentioned, these variables all scale to the number of processor
6553 cores available on the build system.
6554 For single socket systems, this auto-scaling ensures that the build
6555 system fundamentally takes advantage of potential parallel operations
6556 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006557 </para>
6558
6559 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006560 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006561 <itemizedlist>
6562 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006563 File system type:
6564 The file system type that the build is being performed on can
6565 also influence performance.
6566 Using <filename>ext4</filename> is recommended as compared
6567 to <filename>ext2</filename> and <filename>ext3</filename>
6568 due to <filename>ext4</filename> improved features
6569 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006570 </para></listitem>
6571 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006572 Disabling the updating of access time using
6573 <filename>noatime</filename>:
6574 The <filename>noatime</filename> mount option prevents the
6575 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006576 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006577 <listitem><para>
6578 Setting a longer commit:
6579 Using the "commit=" mount option increases the interval
6580 in seconds between disk cache writes.
6581 Changing this interval from the five second default to
6582 something longer increases the risk of data loss but decreases
6583 the need to write to the disk, thus increasing the build
6584 performance.
6585 </para></listitem>
6586 <listitem><para>
6587 Choosing the packaging backend:
6588 Of the available packaging backends, IPK is the fastest.
6589 Additionally, selecting a singular packaging backend also
6590 helps.
6591 </para></listitem>
6592 <listitem><para>
6593 Using <filename>tmpfs</filename> for
6594 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6595 as a temporary file system:
6596 While this can help speed up the build, the benefits are
6597 limited due to the compiler using
6598 <filename>-pipe</filename>.
6599 The build system goes to some lengths to avoid
6600 <filename>sync()</filename> calls into the
6601 file system on the principle that if there was a significant
6602 failure, the
6603 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6604 contents could easily be rebuilt.
6605 </para></listitem>
6606 <listitem><para>
6607 Inheriting the
6608 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6609 class:
6610 Inheriting this class has shown to speed up builds due to
6611 significantly lower amounts of data stored in the data
6612 cache as well as on disk.
6613 Inheriting this class also makes cleanup of
6614 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6615 faster, at the expense of being easily able to dive into the
6616 source code.
6617 File system maintainers have recommended that the fastest way
6618 to clean up large numbers of files is to reformat partitions
6619 rather than delete files due to the linear nature of
6620 partitions.
6621 This, of course, assumes you structure the disk partitions and
6622 file systems in a way that this is practical.
6623 </para></listitem>
6624 </itemizedlist>
6625 Aside from the previous list, you should keep some trade offs in
6626 mind that can help you speed up the build:
6627 <itemizedlist>
6628 <listitem><para>
6629 Remove items from
6630 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6631 that you might not need.
6632 </para></listitem>
6633 <listitem><para>
6634 Exclude debug symbols and other debug information:
6635 If you do not need these symbols and other debug information,
6636 disabling the <filename>*-dbg</filename> package generation
6637 can speed up the build.
6638 You can disable this generation by setting the
6639 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6640 variable to "1".
6641 </para></listitem>
6642 <listitem><para>
6643 Disable static library generation for recipes derived from
6644 <filename>autoconf</filename> or <filename>libtool</filename>:
6645 Following is an example showing how to disable static
6646 libraries and still provide an override to handle exceptions:
6647 <literallayout class='monospaced'>
6648 STATICLIBCONF = "--disable-static"
6649 STATICLIBCONF_sqlite3-native = ""
6650 EXTRA_OECONF += "${STATICLIBCONF}"
6651 </literallayout>
6652 <note><title>Notes</title>
6653 <itemizedlist>
6654 <listitem><para>
6655 Some recipes need static libraries in order to work
6656 correctly (e.g. <filename>pseudo-native</filename>
6657 needs <filename>sqlite3-native</filename>).
6658 Overrides, as in the previous example, account for
6659 these kinds of exceptions.
6660 </para></listitem>
6661 <listitem><para>
6662 Some packages have packaging code that assumes the
6663 presence of the static libraries.
6664 If so, you might need to exclude them as well.
6665 </para></listitem>
6666 </itemizedlist>
6667 </note>
6668 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006669 </itemizedlist>
6670 </para>
6671 </section>
6672
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006673 <section id="platdev-working-with-libraries">
6674 <title>Working With Libraries</title>
6675
6676 <para>
6677 Libraries are an integral part of your system.
6678 This section describes some common practices you might find
6679 helpful when working with libraries to build your system:
6680 <itemizedlist>
6681 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6682 </para></listitem>
6683 <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>
6684 </para></listitem>
6685 <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>
6686 </para></listitem>
6687 </itemizedlist>
6688 </para>
6689
6690 <section id='including-static-library-files'>
6691 <title>Including Static Library Files</title>
6692
6693 <para>
6694 If you are building a library and the library offers static linking, you can control
6695 which static library files (<filename>*.a</filename> files) get included in the
6696 built library.
6697 </para>
6698
6699 <para>
6700 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6701 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6702 variables in the
6703 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6704 by the <filename>do_install</filename> task are packaged.
6705 By default, the <filename>PACKAGES</filename> variable includes
6706 <filename>${PN}-staticdev</filename>, which represents all static library files.
6707 <note>
6708 Some previously released versions of the Yocto Project
6709 defined the static library files through
6710 <filename>${PN}-dev</filename>.
6711 </note>
6712 Following is part of the BitBake configuration file, where
6713 you can see how the static library files are defined:
6714 <literallayout class='monospaced'>
6715 PACKAGE_BEFORE_PN ?= ""
6716 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6717 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6718 FILES = ""
6719
6720 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6721 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6722 ${base_bindir}/* ${base_sbindir}/* \
6723 ${base_libdir}/*${SOLIBS} \
6724 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6725 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6726 ${datadir}/pixmaps ${datadir}/applications \
6727 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6728 ${libdir}/bonobo/servers"
6729
6730 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6731
6732 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6733 ${datadir}/gnome/help"
6734 SECTION_${PN}-doc = "doc"
6735
6736 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6737 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6738 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6739 ${datadir}/aclocal ${base_libdir}/*.o \
6740 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6741 SECTION_${PN}-dev = "devel"
6742 ALLOW_EMPTY_${PN}-dev = "1"
6743 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6744
6745 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6746 SECTION_${PN}-staticdev = "devel"
6747 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6748 </literallayout>
6749 </para>
6750 </section>
6751
6752 <section id="combining-multiple-versions-library-files-into-one-image">
6753 <title>Combining Multiple Versions of Library Files into One Image</title>
6754
6755 <para>
6756 The build system offers the ability to build libraries with different
6757 target optimizations or architecture formats and combine these together
6758 into one system image.
6759 You can link different binaries in the image
6760 against the different libraries as needed for specific use cases.
6761 This feature is called "Multilib."
6762 </para>
6763
6764 <para>
6765 An example would be where you have most of a system compiled in 32-bit
6766 mode using 32-bit libraries, but you have something large, like a database
6767 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6768 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6769 </para>
6770
6771 <para>
6772 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6773 the approach the build system uses facilitates different target optimizations.
6774 You could compile some binaries to use one set of libraries and other binaries
6775 to use a different set of libraries.
6776 The libraries could differ in architecture, compiler options, or other
6777 optimizations.
6778 </para>
6779
6780 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006781 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006782 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006783 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006784 <itemizedlist>
6785 <listitem><para><filename>conf/multilib-example.conf</filename>
6786 configuration file</para></listitem>
6787 <listitem><para><filename>conf/multilib-example2.conf</filename>
6788 configuration file</para></listitem>
6789 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6790 recipe</para></listitem>
6791 </itemizedlist>
6792 </para>
6793
6794 <section id='preparing-to-use-multilib'>
6795 <title>Preparing to Use Multilib</title>
6796
6797 <para>
6798 User-specific requirements drive the Multilib feature.
6799 Consequently, there is no one "out-of-the-box" configuration that likely
6800 exists to meet your needs.
6801 </para>
6802
6803 <para>
6804 In order to enable Multilib, you first need to ensure your recipe is
6805 extended to support multiple libraries.
6806 Many standard recipes are already extended and support multiple libraries.
6807 You can check in the <filename>meta/conf/multilib.conf</filename>
6808 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006809 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006810 done using the
6811 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6812 variable.
6813 Eventually, all recipes will be covered and this list will
6814 not be needed.
6815 </para>
6816
6817 <para>
6818 For the most part, the Multilib class extension works automatically to
6819 extend the package name from <filename>${PN}</filename> to
6820 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6821 is the particular multilib (e.g. "lib32-" or "lib64-").
6822 Standard variables such as
6823 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6824 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6825 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6826 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6827 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6828 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6829 are automatically extended by the system.
6830 If you are extending any manual code in the recipe, you can use the
6831 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6832 correctly.
6833 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6834 </para>
6835 </section>
6836
6837 <section id='using-multilib'>
6838 <title>Using Multilib</title>
6839
6840 <para>
6841 After you have set up the recipes, you need to define the actual
6842 combination of multiple libraries you want to build.
6843 You accomplish this through your <filename>local.conf</filename>
6844 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006845 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006846 An example configuration would be as follows:
6847 <literallayout class='monospaced'>
6848 MACHINE = "qemux86-64"
6849 require conf/multilib.conf
6850 MULTILIBS = "multilib:lib32"
6851 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006852 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006853 </literallayout>
6854 This example enables an
6855 additional library named <filename>lib32</filename> alongside the
6856 normal target packages.
6857 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6858 For information on this particular tuning, see
6859 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6860 </para>
6861
6862 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006863 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006864 in all the images, which illustrates one method of including a
6865 multiple library dependency.
6866 You can use a normal image build to include this dependency,
6867 for example:
6868 <literallayout class='monospaced'>
6869 $ bitbake core-image-sato
6870 </literallayout>
6871 You can also build Multilib packages specifically with a command like this:
6872 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006873 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006874 </literallayout>
6875 </para>
6876 </section>
6877
6878 <section id='additional-implementation-details'>
6879 <title>Additional Implementation Details</title>
6880
6881 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006882 Generic implementation details as well as details that are
6883 specific to package management systems exist.
6884 Following are implementation details that exist regardless
6885 of the package management system:
6886 <itemizedlist>
6887 <listitem><para>The typical convention used for the
6888 class extension code as used by
6889 Multilib assumes that all package names specified
6890 in
6891 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6892 that contain <filename>${PN}</filename> have
6893 <filename>${PN}</filename> at the start of the name.
6894 When that convention is not followed and
6895 <filename>${PN}</filename> appears at
6896 the middle or the end of a name, problems occur.
6897 </para></listitem>
6898 <listitem><para>The
6899 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6900 value under Multilib will be extended to
6901 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6902 (e.g. "-pokymllib32" for a "lib32" Multilib with
6903 Poky).
6904 The reason for this slightly unwieldy contraction
6905 is that any "-" characters in the vendor
6906 string presently break Autoconf's
6907 <filename>config.sub</filename>, and
6908 other separators are problematic for different
6909 reasons.
6910 </para></listitem>
6911 </itemizedlist>
6912 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006913
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006914 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006915 For the RPM Package Management System, the following implementation details
6916 exist:
6917 <itemizedlist>
6918 <listitem><para>A unique architecture is defined for the Multilib packages,
6919 along with creating a unique deploy folder under
6920 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006921 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006922 For example, consider <filename>lib32</filename> in a
6923 <filename>qemux86-64</filename> image.
6924 The possible architectures in the system are "all", "qemux86_64",
6925 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6926 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6927 <filename>${PN}</filename> during RPM packaging.
6928 The naming for a normal RPM package and a Multilib RPM package in a
6929 <filename>qemux86-64</filename> system resolves to something similar to
6930 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6931 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6932 </para></listitem>
6933 <listitem><para>When installing a Multilib image, the RPM backend first
6934 installs the base image and then installs the Multilib libraries.
6935 </para></listitem>
6936 <listitem><para>The build system relies on RPM to resolve the identical files in the
6937 two (or more) Multilib packages.</para></listitem>
6938 </itemizedlist>
6939 </para>
6940
6941 <para>
6942 For the IPK Package Management System, the following implementation details exist:
6943 <itemizedlist>
6944 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6945 <filename>${PN}</filename> during IPK packaging.
6946 The naming for a normal RPM package and a Multilib IPK package in a
6947 <filename>qemux86-64</filename> system resolves to something like
6948 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6949 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6950 </para></listitem>
6951 <listitem><para>The IPK deploy folder is not modified with
6952 <filename>${MLPREFIX}</filename> because packages with and without
6953 the Multilib feature can exist in the same folder due to the
6954 <filename>${PN}</filename> differences.</para></listitem>
6955 <listitem><para>IPK defines a sanity check for Multilib installation
6956 using certain rules for file comparison, overridden, etc.
6957 </para></listitem>
6958 </itemizedlist>
6959 </para>
6960 </section>
6961 </section>
6962
6963 <section id='installing-multiple-versions-of-the-same-library'>
6964 <title>Installing Multiple Versions of the Same Library</title>
6965
6966 <para>
6967 Situations can exist where you need to install and use
6968 multiple versions of the same library on the same system
6969 at the same time.
6970 These situations almost always exist when a library API
6971 changes and you have multiple pieces of software that
6972 depend on the separate versions of the library.
6973 To accommodate these situations, you can install multiple
6974 versions of the same library in parallel on the same system.
6975 </para>
6976
6977 <para>
6978 The process is straightforward as long as the libraries use
6979 proper versioning.
6980 With properly versioned libraries, all you need to do to
6981 individually specify the libraries is create separate,
6982 appropriately named recipes where the
6983 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6984 name includes a portion that differentiates each library version
6985 (e.g.the major part of the version number).
6986 Thus, instead of having a single recipe that loads one version
6987 of a library (e.g. <filename>clutter</filename>), you provide
6988 multiple recipes that result in different versions
6989 of the libraries you want.
6990 As an example, the following two recipes would allow the
6991 two separate versions of the <filename>clutter</filename>
6992 library to co-exist on the same system:
6993 <literallayout class='monospaced'>
6994 clutter-1.6_1.6.20.bb
6995 clutter-1.8_1.8.4.bb
6996 </literallayout>
6997 Additionally, if you have other recipes that depend on a given
6998 library, you need to use the
6999 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
7000 variable to create the dependency.
7001 Continuing with the same example, if you want to have a recipe
7002 depend on the 1.8 version of the <filename>clutter</filename>
7003 library, use the following in your recipe:
7004 <literallayout class='monospaced'>
7005 DEPENDS = "clutter-1.8"
7006 </literallayout>
7007 </para>
7008 </section>
7009 </section>
7010
Brad Bishop316dfdd2018-06-25 12:45:53 -04007011 <section id='using-x32-psabi'>
7012 <title>Using x32 psABI</title>
7013
7014 <para>
7015 x32 processor-specific Application Binary Interface
7016 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
7017 is a native 32-bit processor-specific ABI for
7018 <trademark class='registered'>Intel</trademark> 64 (x86-64)
7019 architectures.
7020 An ABI defines the calling conventions between functions in a
7021 processing environment.
7022 The interface determines what registers are used and what the
7023 sizes are for various C data types.
7024 </para>
7025
7026 <para>
7027 Some processing environments prefer using 32-bit applications even
7028 when running on Intel 64-bit platforms.
7029 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
7030 64-bit platforms.
7031 The i386 psABI does not provide efficient use and access of the
7032 Intel 64-bit processor resources, leaving the system underutilized.
7033 Now consider the x86_64 psABI.
7034 This ABI is newer and uses 64-bits for data sizes and program
7035 pointers.
7036 The extra bits increase the footprint size of the programs,
7037 libraries, and also increases the memory and file system size
7038 requirements.
7039 Executing under the x32 psABI enables user programs to utilize CPU
7040 and system resources more efficiently while keeping the memory
7041 footprint of the applications low.
7042 Extra bits are used for registers but not for addressing mechanisms.
7043 </para>
7044
7045 <para>
7046 The Yocto Project supports the final specifications of x32 psABI
7047 as follows:
7048 <itemizedlist>
7049 <listitem><para>
7050 You can create packages and images in x32 psABI format on
7051 x86_64 architecture targets.
7052 </para></listitem>
7053 <listitem><para>
7054 You can successfully build recipes with the x32 toolchain.
7055 </para></listitem>
7056 <listitem><para>
7057 You can create and boot
7058 <filename>core-image-minimal</filename> and
7059 <filename>core-image-sato</filename> images.
7060 </para></listitem>
7061 <listitem><para>
7062 RPM Package Manager (RPM) support exists for x32 binaries.
7063 </para></listitem>
7064 <listitem><para>
7065 Support for large images exists.
7066 </para></listitem>
7067 </itemizedlist>
7068 </para>
7069
7070 <para>
7071 To use the x32 psABI, you need to edit your
7072 <filename>conf/local.conf</filename> configuration file as
7073 follows:
7074 <literallayout class='monospaced'>
7075 MACHINE = "qemux86-64"
7076 DEFAULTTUNE = "x86-64-x32"
Brad Bishop19323692019-04-05 15:28:33 -04007077 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
7078 or 'INVALID')) or 'lib'}"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007079 </literallayout>
7080 Once you have set up your configuration file, use BitBake to
7081 build an image that supports the x32 psABI.
7082 Here is an example:
7083 <literallayout class='monospaced'>
7084 $ bitbake core-image-sato
7085 </literallayout>
7086 </para>
7087 </section>
7088
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007089 <section id='enabling-gobject-introspection-support'>
7090 <title>Enabling GObject Introspection Support</title>
7091
7092 <para>
7093 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
7094 is the standard mechanism for accessing GObject-based software
7095 from runtime environments.
7096 GObject is a feature of the GLib library that provides an object
7097 framework for the GNOME desktop and related software.
7098 GObject Introspection adds information to GObject that allows
7099 objects created within it to be represented across different
7100 programming languages.
7101 If you want to construct GStreamer pipelines using Python, or
7102 control UPnP infrastructure using Javascript and GUPnP,
7103 GObject introspection is the only way to do it.
7104 </para>
7105
7106 <para>
7107 This section describes the Yocto Project support for generating
7108 and packaging GObject introspection data.
7109 GObject introspection data is a description of the
7110 API provided by libraries built on top of GLib framework,
7111 and, in particular, that framework's GObject mechanism.
7112 GObject Introspection Repository (GIR) files go to
7113 <filename>-dev</filename> packages,
7114 <filename>typelib</filename> files go to main packages as they
7115 are packaged together with libraries that are introspected.
7116 </para>
7117
7118 <para>
7119 The data is generated when building such a library, by linking
7120 the library with a small executable binary that asks the library
7121 to describe itself, and then executing the binary and
7122 processing its output.
7123 </para>
7124
7125 <para>
7126 Generating this data in a cross-compilation environment
7127 is difficult because the library is produced for the target
7128 architecture, but its code needs to be executed on the build host.
7129 This problem is solved with the OpenEmbedded build system by
7130 running the code through QEMU, which allows precisely that.
7131 Unfortunately, QEMU does not always work perfectly as mentioned
7132 in the xxx section.
7133 </para>
7134
7135 <section id='enabling-the-generation-of-introspection-data'>
7136 <title>Enabling the Generation of Introspection Data</title>
7137
7138 <para>
7139 Enabling the generation of introspection data (GIR files)
7140 in your library package involves the following:
7141 <orderedlist>
7142 <listitem><para>
7143 Inherit the
7144 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
7145 class.
7146 </para></listitem>
7147 <listitem><para>
7148 Make sure introspection is not disabled anywhere in
7149 the recipe or from anything the recipe includes.
7150 Also, make sure that "gobject-introspection-data" is
7151 not in
7152 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7153 and that "qemu-usermode" is not in
7154 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7155 If either of these conditions exist, nothing will
7156 happen.
7157 </para></listitem>
7158 <listitem><para>
7159 Try to build the recipe.
7160 If you encounter build errors that look like
7161 something is unable to find
7162 <filename>.so</filename> libraries, check where these
7163 libraries are located in the source tree and add
7164 the following to the recipe:
7165 <literallayout class='monospaced'>
7166 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
7167 </literallayout>
7168 <note>
7169 See recipes in the <filename>oe-core</filename>
7170 repository that use that
7171 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
7172 as an example.
7173 </note>
7174 </para></listitem>
7175 <listitem><para>
7176 Look for any other errors, which probably mean that
7177 introspection support in a package is not entirely
7178 standard, and thus breaks down in a cross-compilation
7179 environment.
7180 For such cases, custom-made fixes are needed.
7181 A good place to ask and receive help in these cases
7182 is the
7183 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7184 </para></listitem>
7185 </orderedlist>
7186 <note>
7187 Using a library that no longer builds against the latest
7188 Yocto Project release and prints introspection related
7189 errors is a good candidate for the previous procedure.
7190 </note>
7191 </para>
7192 </section>
7193
7194 <section id='disabling-the-generation-of-introspection-data'>
7195 <title>Disabling the Generation of Introspection Data</title>
7196
7197 <para>
7198 You might find that you do not want to generate
7199 introspection data.
7200 Or, perhaps QEMU does not work on your build host and
7201 target architecture combination.
7202 If so, you can use either of the following methods to
7203 disable GIR file generations:
7204 <itemizedlist>
7205 <listitem><para>
7206 Add the following to your distro configuration:
7207 <literallayout class='monospaced'>
7208 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7209 </literallayout>
7210 Adding this statement disables generating
7211 introspection data using QEMU but will still enable
7212 building introspection tools and libraries
7213 (i.e. building them does not require the use of QEMU).
7214 </para></listitem>
7215 <listitem><para>
7216 Add the following to your machine configuration:
7217 <literallayout class='monospaced'>
7218 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7219 </literallayout>
7220 Adding this statement disables the use of QEMU
7221 when building packages for your machine.
7222 Currently, this feature is used only by introspection
7223 recipes and has the same effect as the previously
7224 described option.
7225 <note>
7226 Future releases of the Yocto Project might have
7227 other features affected by this option.
7228 </note>
7229 </para></listitem>
7230 </itemizedlist>
7231 If you disable introspection data, you can still
7232 obtain it through other means such as copying the data
7233 from a suitable sysroot, or by generating it on the
7234 target hardware.
7235 The OpenEmbedded build system does not currently
7236 provide specific support for these techniques.
7237 </para>
7238 </section>
7239
7240 <section id='testing-that-introspection-works-in-an-image'>
7241 <title>Testing that Introspection Works in an Image</title>
7242
7243 <para>
7244 Use the following procedure to test if generating
7245 introspection data is working in an image:
7246 <orderedlist>
7247 <listitem><para>
7248 Make sure that "gobject-introspection-data" is not in
7249 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7250 and that "qemu-usermode" is not in
7251 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7252 </para></listitem>
7253 <listitem><para>
7254 Build <filename>core-image-sato</filename>.
7255 </para></listitem>
7256 <listitem><para>
7257 Launch a Terminal and then start Python in the
7258 terminal.
7259 </para></listitem>
7260 <listitem><para>
7261 Enter the following in the terminal:
7262 <literallayout class='monospaced'>
7263 >>> from gi.repository import GLib
7264 >>> GLib.get_host_name()
7265 </literallayout>
7266 </para></listitem>
7267 <listitem><para>
7268 For something a little more advanced, enter the
7269 following:
7270 <literallayout class='monospaced'>
7271 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7272 </literallayout>
7273 </para></listitem>
7274 </orderedlist>
7275 </para>
7276 </section>
7277
7278 <section id='known-issues'>
7279 <title>Known Issues</title>
7280
7281 <para>
7282 The following know issues exist for
7283 GObject Introspection Support:
7284 <itemizedlist>
7285 <listitem><para>
7286 <filename>qemu-ppc64</filename> immediately crashes.
7287 Consequently, you cannot build introspection data on
7288 that architecture.
7289 </para></listitem>
7290 <listitem><para>
7291 x32 is not supported by QEMU.
7292 Consequently, introspection data is disabled.
7293 </para></listitem>
7294 <listitem><para>
7295 musl causes transient GLib binaries to crash on
7296 assertion failures.
7297 Consequently, generating introspection data is
7298 disabled.
7299 </para></listitem>
7300 <listitem><para>
7301 Because QEMU is not able to run the binaries correctly,
7302 introspection is disabled for some specific packages
7303 under specific architectures (e.g.
7304 <filename>gcr</filename>,
7305 <filename>libsecret</filename>, and
7306 <filename>webkit</filename>).
7307 </para></listitem>
7308 <listitem><para>
7309 QEMU usermode might not work properly when running
7310 64-bit binaries under 32-bit host machines.
7311 In particular, "qemumips64" is known to not work under
7312 i686.
7313 </para></listitem>
7314 </itemizedlist>
7315 </para>
7316 </section>
7317 </section>
7318
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007319 <section id='dev-optionally-using-an-external-toolchain'>
7320 <title>Optionally Using an External Toolchain</title>
7321
7322 <para>
7323 You might want to use an external toolchain as part of your
7324 development.
7325 If this is the case, the fundamental steps you need to accomplish
7326 are as follows:
7327 <itemizedlist>
7328 <listitem><para>
7329 Understand where the installed toolchain resides.
7330 For cases where you need to build the external toolchain,
7331 you would need to take separate steps to build and install
7332 the toolchain.
7333 </para></listitem>
7334 <listitem><para>
7335 Make sure you add the layer that contains the toolchain to
7336 your <filename>bblayers.conf</filename> file through the
7337 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7338 variable.
7339 </para></listitem>
7340 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007341 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007342 variable in your <filename>local.conf</filename> file
7343 to the location in which you installed the toolchain.
7344 </para></listitem>
7345 </itemizedlist>
7346 A good example of an external toolchain used with the Yocto Project
7347 is <trademark class='registered'>Mentor Graphics</trademark>
7348 Sourcery G++ Toolchain.
7349 You can see information on how to use that particular layer in the
7350 <filename>README</filename> file at
7351 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7352 You can find further information by reading about the
7353 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7354 variable in the Yocto Project Reference Manual's variable glossary.
7355 </para>
7356 </section>
7357
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007358 <section id='creating-partitioned-images-using-wic'>
7359 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007360
7361 <para>
7362 Creating an image for a particular hardware target using the
7363 OpenEmbedded build system does not necessarily mean you can boot
7364 that image as is on your device.
7365 Physical devices accept and boot images in various ways depending
7366 on the specifics of the device.
7367 Usually, information about the hardware can tell you what image
7368 format the device requires.
7369 Should your device require multiple partitions on an SD card, flash,
7370 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007371 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007372 </para>
7373
7374 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007375 The <filename>wic</filename> command generates partitioned
7376 images from existing OpenEmbedded build artifacts.
7377 Image generation is driven by partitioning commands
7378 contained in an Openembedded kickstart file
7379 (<filename>.wks</filename>) specified either directly on
7380 the command line or as one of a selection of canned
7381 kickstart files as shown with the
7382 <filename>wic list images</filename> command in the
7383 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7384 section.
7385 When you apply the command to a given set of build
7386 artifacts, the result is an image or set of images that
7387 can be directly written onto media and used on a particular
7388 system.
7389 <note>
7390 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007391 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007392 Chapter in the Yocto Project Reference Manual.
7393 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007394 </para>
7395
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007396 <para>
7397 The <filename>wic</filename> command and the infrastructure
7398 it is based on is by definition incomplete.
7399 The purpose of the command is to allow the generation of
7400 customized images, and as such, was designed to be
Brad Bishopc342db32019-05-15 21:57:59 -04007401 completely extensible through a plugin interface.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007402 See the
Brad Bishopc342db32019-05-15 21:57:59 -04007403 "<link linkend='wic-using-the-wic-plugin-interface'>Using the Wic PlugIn Interface</link>"
7404 section for information on these plugins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007405 </para>
7406
7407 <para>
7408 This section provides some background information on Wic,
7409 describes what you need to have in
7410 place to run the tool, provides instruction on how to use
Brad Bishopc342db32019-05-15 21:57:59 -04007411 the Wic utility, provides information on using the Wic plugins
Brad Bishop316dfdd2018-06-25 12:45:53 -04007412 interface, and provides several examples that show how to use
7413 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007414 </para>
7415
7416 <section id='wic-background'>
7417 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007418
7419 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007420 This section provides some background on the Wic utility.
7421 While none of this information is required to use
7422 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007423 <itemizedlist>
7424 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007425 The name "Wic" is derived from OpenEmbedded
7426 Image Creator (oeic).
7427 The "oe" diphthong in "oeic" was promoted to the
7428 letter "w", because "oeic" is both difficult to
7429 remember and to pronounce.
7430 </para></listitem>
7431 <listitem><para>
7432 Wic is loosely based on the
7433 Meego Image Creator (<filename>mic</filename>)
7434 framework.
7435 The Wic implementation has been
7436 heavily modified to make direct use of OpenEmbedded
7437 build artifacts instead of package installation and
7438 configuration, which are already incorporated within
7439 the OpenEmbedded artifacts.
7440 </para></listitem>
7441 <listitem><para>
7442 Wic is a completely independent
7443 standalone utility that initially provides
7444 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007445 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007446 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007447 class.
7448 The difference between Wic and those examples is
7449 that with Wic the functionality of those scripts is
7450 implemented by a general-purpose partitioning language,
7451 which is based on Redhat kickstart syntax.
7452 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007453 </itemizedlist>
7454 </para>
7455 </section>
7456
7457 <section id='wic-requirements'>
7458 <title>Requirements</title>
7459
7460 <para>
7461 In order to use the Wic utility with the OpenEmbedded Build
7462 system, your system needs to meet the following
7463 requirements:
7464 <itemizedlist>
7465 <listitem><para>
7466 The Linux distribution on your development host must
7467 support the Yocto Project.
7468 See the
7469 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7470 section in the Yocto Project Reference Manual for
7471 the list of distributions that support the
7472 Yocto Project.
7473 </para></listitem>
7474 <listitem><para>
7475 The standard system utilities, such as
7476 <filename>cp</filename>, must be installed on your
7477 development host system.
7478 </para></listitem>
7479 <listitem><para>
7480 You must have sourced the build environment
7481 setup script (i.e.
7482 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7483 found in the
7484 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7485 </para></listitem>
7486 <listitem><para>
7487 You need to have the build artifacts already
7488 available, which typically means that you must
7489 have already created an image using the
7490 Openembedded build system (e.g.
7491 <filename>core-image-minimal</filename>).
7492 While it might seem redundant to generate an image
7493 in order to create an image using
7494 Wic, the current version of
7495 Wic requires the artifacts
7496 in the form generated by the OpenEmbedded build
7497 system.
7498 </para></listitem>
7499 <listitem><para>
7500 You must build several native tools, which are
7501 built to run on the build system:
7502 <literallayout class='monospaced'>
7503 $ bitbake parted-native dosfstools-native mtools-native
7504 </literallayout>
7505 </para></listitem>
7506 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007507 Include "wic" as part of the
7508 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7509 variable.
7510 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007511 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007512 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007513 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007514 as part of the
7515 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7516 variable
7517 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007518 </itemizedlist>
7519 </para>
7520 </section>
7521
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007522 <section id='wic-getting-help'>
7523 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007524
7525 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007526 You can get general help for the <filename>wic</filename>
7527 command by entering the <filename>wic</filename> command
7528 by itself or by entering the command with a help argument
7529 as follows:
7530 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007531 $ wic -h
7532 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007533 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007534 </literallayout>
7535 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007536
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007537 <para>
7538 Currently, Wic supports seven commands:
7539 <filename>cp</filename>, <filename>create</filename>,
7540 <filename>help</filename>, <filename>list</filename>,
7541 <filename>ls</filename>, <filename>rm</filename>, and
7542 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007543 You can get help for all these commands except "help" by
7544 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007545 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007546 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007547 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007548 For example, the following command returns help for the
7549 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007550 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007551 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007552 </literallayout>
7553 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007554
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007555 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007556 Wic supports help for three topics:
7557 <filename>overview</filename>,
7558 <filename>plugins</filename>, and
7559 <filename>kickstart</filename>.
7560 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007561 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007562 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007563 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007564 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007565 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007566 $ wic help overview
7567 </literallayout>
7568 </para>
7569
7570 <para>
7571 One additional level of help exists for Wic.
7572 You can get help on individual images through the
7573 <filename>list</filename> command.
7574 You can use the <filename>list</filename> command to return the
7575 available Wic images as follows:
7576 <literallayout class='monospaced'>
7577 $ wic list images
7578 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7579 genericx86 Create an EFI disk image for genericx86*
7580 beaglebone-yocto Create SD card image for Beaglebone
7581 edgerouter Create SD card image for Edgerouter
7582 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7583 directdisk-gpt Create a 'pcbios' direct disk image
7584 mkefidisk Create an EFI disk image
7585 directdisk Create a 'pcbios' direct disk image
7586 systemd-bootdisk Create an EFI disk image with systemd-boot
7587 mkhybridiso Create a hybrid ISO image
7588 sdimage-bootpart Create SD card image with a boot partition
7589 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7590 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7591 </literallayout>
7592 Once you know the list of available Wic images, you can use
7593 <filename>help</filename> with the command to get help on a
7594 particular image.
7595 For example, the following command returns help on the
7596 "beaglebone-yocto" image:
7597 <literallayout class='monospaced'>
7598 $ wic list beaglebone-yocto help
7599
7600
7601 Creates a partitioned SD card image for Beaglebone.
7602 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007603 </literallayout>
7604 </para>
7605 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007606
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007607 <section id='operational-modes'>
7608 <title>Operational Modes</title>
7609
7610 <para>
7611 You can use Wic in two different
7612 modes, depending on how much control you need for
7613 specifying the Openembedded build artifacts that are
7614 used for creating the image: Raw and Cooked:
7615 <itemizedlist>
7616 <listitem><para>
7617 <emphasis>Raw Mode:</emphasis>
7618 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007619 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007620 </para></listitem>
7621 <listitem><para>
7622 <emphasis>Cooked Mode:</emphasis>
7623 The current
7624 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7625 setting and image name are used to automatically
7626 locate and provide the build artifacts.
7627 You just supply a kickstart file and the name
7628 of the image from which to use artifacts.
7629 </para></listitem>
7630 </itemizedlist>
7631 </para>
7632
7633 <para>
7634 Regardless of the mode you use, you need to have the build
7635 artifacts ready and available.
7636 </para>
7637
7638 <section id='raw-mode'>
7639 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007640
7641 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007642 Running Wic in raw mode allows you to specify all the
7643 partitions through the <filename>wic</filename>
7644 command line.
7645 The primary use for raw mode is if you have built
7646 your kernel outside of the Yocto Project
7647 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7648 In other words, you can point to arbitrary kernel,
7649 root filesystem locations, and so forth.
7650 Contrast this behavior with cooked mode where Wic
7651 looks in the Build Directory (e.g.
7652 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007653 </para>
7654
7655 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007656 The general form of the
7657 <filename>wic</filename> command in raw mode is:
7658 <literallayout class='monospaced'>
7659 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007660
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007661 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007662
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007663 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007664 An OpenEmbedded kickstart file. You can provide
7665 your own custom file or use a file from a set of
7666 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007667
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007668 optional arguments:
7669 -h, --help show this help message and exit
7670 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7671 name of directory to create image in
7672 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7673 name of the image to use the artifacts from e.g. core-
7674 image-sato
7675 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7676 path to the /rootfs dir to use as the .wks rootfs
7677 source
7678 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7679 path to the dir containing the boot artifacts (e.g.
7680 /EFI or /syslinux dirs) to use as the .wks bootimg
7681 source
7682 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7683 path to the dir containing the kernel to use in the
7684 .wks bootimg
7685 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7686 path to the native sysroot containing the tools to use
7687 to build the image
7688 -s, --skip-build-check
7689 skip the build check
7690 -f, --build-rootfs build rootfs
7691 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7692 compress image with specified compressor
7693 -m, --bmap generate .bmap
7694 --no-fstab-update Do not change fstab file.
7695 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7696 directory with &lt;image&gt;.env files that store bitbake
7697 variables
7698 -D, --debug output debug information
7699 </literallayout>
7700 <note>
7701 You do not need root privileges to run
7702 Wic.
7703 In fact, you should not run as root when using the
7704 utility.
7705 </note>
7706 </para>
7707 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007708
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007709 <section id='cooked-mode'>
7710 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007711
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007712 <para>
7713 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007714 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007715 In other words, you do not have to specify kernel or
7716 root filesystem locations as part of the command.
7717 All you need to provide is a kickstart file and the
7718 name of the image from which to use artifacts by using
7719 the "-e" option.
7720 Wic looks in the Build Directory (e.g.
7721 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7722 for artifacts.
7723 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007724
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007725 <para>
7726 The general form of the <filename>wic</filename>
7727 command using Cooked Mode is as follows:
7728 <literallayout class='monospaced'>
7729 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007730
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007731 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007732
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007733 <replaceable>wks_file</replaceable>:
7734 An OpenEmbedded kickstart file. You can provide
7735 your own custom file or use a file from a set of
7736 existing files provided with the Yocto Project
7737 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007738
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007739 required argument:
7740 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7741 name of the image to use the artifacts from e.g. core-
7742 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007743 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007744 </para>
7745 </section>
7746 </section>
7747
7748 <section id='using-a-provided-kickstart-file'>
7749 <title>Using an Existing Kickstart File</title>
7750
7751 <para>
7752 If you do not want to create your own kickstart file, you
7753 can use an existing file provided by the Wic installation.
7754 As shipped, kickstart files can be found in the
7755 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007756 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007757 in the following two locations:
7758 <literallayout class='monospaced'>
7759 poky/meta-yocto-bsp/wic
7760 poky/scripts/lib/wic/canned-wks
7761 </literallayout>
7762 Use the following command to list the available kickstart
7763 files:
7764 <literallayout class='monospaced'>
7765 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007766 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7767 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007768 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007769 edgerouter Create SD card image for Edgerouter
7770 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7771 directdisk-gpt Create a 'pcbios' direct disk image
7772 mkefidisk Create an EFI disk image
7773 directdisk Create a 'pcbios' direct disk image
7774 systemd-bootdisk Create an EFI disk image with systemd-boot
7775 mkhybridiso Create a hybrid ISO image
7776 sdimage-bootpart Create SD card image with a boot partition
7777 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7778 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7779 </literallayout>
7780 When you use an existing file, you do not have to use the
7781 <filename>.wks</filename> extension.
7782 Here is an example in Raw Mode that uses the
7783 <filename>directdisk</filename> file:
7784 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007785 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7786 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007787 </literallayout>
7788 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007789
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007790 <para>
7791 Here are the actual partition language commands
7792 used in the <filename>genericx86.wks</filename> file to
7793 generate an image:
7794 <literallayout class='monospaced'>
7795 # short-description: Create an EFI disk image for genericx86*
7796 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7797 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7798 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007799 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7800
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007801 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7802 </literallayout>
7803 </para>
7804 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007805
Brad Bishopc342db32019-05-15 21:57:59 -04007806 <section id='wic-using-the-wic-plugin-interface'>
7807 <title>Using the Wic Plugin Interface</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007808
7809 <para>
7810 You can extend and specialize Wic functionality by using
Brad Bishopc342db32019-05-15 21:57:59 -04007811 Wic plugins.
7812 This section explains the Wic plugin interface.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007813 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007814 Wic plugins consist of "source" and "imager" plugins.
7815 Imager plugins are beyond the scope of this section.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007816 </note>
7817 </para>
7818
7819 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007820 Source plugins provide a mechanism to customize partition
Brad Bishop316dfdd2018-06-25 12:45:53 -04007821 content during the Wic image generation process.
Brad Bishopc342db32019-05-15 21:57:59 -04007822 You can use source plugins to map values that you specify
Brad Bishop316dfdd2018-06-25 12:45:53 -04007823 using <filename>--source</filename> commands in kickstart
Brad Bishopc342db32019-05-15 21:57:59 -04007824 files (i.e. <filename>*.wks</filename>) to a plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007825 implementation used to populate a given partition.
7826 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007827 If you use plugins that have build-time dependencies
Brad Bishop316dfdd2018-06-25 12:45:53 -04007828 (e.g. native tools, bootloaders, and so forth)
7829 when building a Wic image, you need to specify those
7830 dependencies using the
7831 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7832 variable.
7833 </note>
7834 </para>
7835
7836 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007837 Source plugins are subclasses defined in plugin files.
7838 As shipped, the Yocto Project provides several plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007839 files.
Brad Bishopc342db32019-05-15 21:57:59 -04007840 You can see the source plugin files that ship with the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007841 Yocto Project
7842 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
Brad Bishopc342db32019-05-15 21:57:59 -04007843 Each of these plugin files contains source plugins that
Brad Bishop316dfdd2018-06-25 12:45:53 -04007844 are designed to populate a specific Wic image partition.
7845 </para>
7846
7847 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007848 Source plugins are subclasses of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007849 <filename>SourcePlugin</filename> class, which is
7850 defined in the
7851 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7852 file.
7853 For example, the <filename>BootimgEFIPlugin</filename>
Brad Bishopc342db32019-05-15 21:57:59 -04007854 source plugin found in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007855 <filename>bootimg-efi.py</filename> file is a subclass of
7856 the <filename>SourcePlugin</filename> class, which is found
7857 in the <filename>pluginbase.py</filename> file.
7858 </para>
7859
7860 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007861 You can also implement source plugins in a layer outside
Brad Bishop316dfdd2018-06-25 12:45:53 -04007862 of the Source Repositories (external layer).
Brad Bishopc342db32019-05-15 21:57:59 -04007863 To do so, be sure that your plugin files are located in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007864 a directory whose path is
7865 <filename>scripts/lib/wic/plugins/source/</filename>
7866 within your external layer.
Brad Bishopc342db32019-05-15 21:57:59 -04007867 When the plugin files are located there, the source
7868 plugins they contain are made available to Wic.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007869 </para>
7870
7871 <para>
7872 When the Wic implementation needs to invoke a
Brad Bishopc342db32019-05-15 21:57:59 -04007873 partition-specific implementation, it looks for the plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007874 with the same name as the <filename>--source</filename>
7875 parameter used in the kickstart file given to that
7876 partition.
7877 For example, if the partition is set up using the following
7878 command in a kickstart file:
7879 <literallayout class='monospaced'>
7880 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7881 </literallayout>
7882 The methods defined as class members of the matching
Brad Bishopc342db32019-05-15 21:57:59 -04007883 source plugin (i.e. <filename>bootimg-pcbios</filename>)
7884 in the <filename>bootimg-pcbios.py</filename> plugin file
Brad Bishop316dfdd2018-06-25 12:45:53 -04007885 are used.
7886 </para>
7887
7888 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007889 To be more concrete, here is the corresponding plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007890 definition from the <filename>bootimg-pcbios.py</filename>
7891 file for the previous command along with an example
7892 method called by the Wic implementation when it needs to
7893 prepare a partition using an implementation-specific
7894 function:
7895 <literallayout class='monospaced'>
7896 .
7897 .
7898 .
7899 class BootimgPcbiosPlugin(SourcePlugin):
7900 """
7901 Create MBR boot partition and install syslinux on it.
7902 """
7903
7904 name = 'bootimg-pcbios'
7905 .
7906 .
7907 .
7908 @classmethod
7909 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7910 oe_builddir, bootimg_dir, kernel_dir,
7911 rootfs_dir, native_sysroot):
7912 """
7913 Called to do the actual content population for a partition i.e. it
7914 'prepares' the partition to be incorporated into the image.
7915 In this case, prepare content for legacy bios boot partition.
7916 """
7917 .
7918 .
7919 .
7920 </literallayout>
Brad Bishopc342db32019-05-15 21:57:59 -04007921 If a subclass (plugin) itself does not implement a
Brad Bishop316dfdd2018-06-25 12:45:53 -04007922 particular function, Wic locates and uses the default
7923 version in the superclass.
Brad Bishopc342db32019-05-15 21:57:59 -04007924 It is for this reason that all source plugins are derived
Brad Bishop316dfdd2018-06-25 12:45:53 -04007925 from the <filename>SourcePlugin</filename> class.
7926 </para>
7927
7928 <para>
7929 The <filename>SourcePlugin</filename> class defined in
7930 the <filename>pluginbase.py</filename> file defines
Brad Bishopc342db32019-05-15 21:57:59 -04007931 a set of methods that source plugins can implement or
Brad Bishop316dfdd2018-06-25 12:45:53 -04007932 override.
Brad Bishopc342db32019-05-15 21:57:59 -04007933 Any plugins (subclass of
Brad Bishop316dfdd2018-06-25 12:45:53 -04007934 <filename>SourcePlugin</filename>) that do not implement
7935 a particular method inherit the implementation of the
7936 method from the <filename>SourcePlugin</filename> class.
7937 For more information, see the
7938 <filename>SourcePlugin</filename> class in the
7939 <filename>pluginbase.py</filename> file for details:
7940 </para>
7941
7942 <para>
7943 The following list describes the methods implemented in the
7944 <filename>SourcePlugin</filename> class:
7945 <itemizedlist>
7946 <listitem><para>
7947 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7948 Called to populate a partition with actual content.
7949 In other words, the method prepares the final
7950 partition image that is incorporated into the
7951 disk image.
7952 </para></listitem>
7953 <listitem><para>
7954 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7955 Called before
7956 <filename>do_prepare_partition()</filename> to
7957 create custom configuration files for a partition
7958 (e.g. syslinux or grub configuration files).
7959 </para></listitem>
7960 <listitem><para>
7961 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7962 Called after all partitions have been prepared and
7963 assembled into a disk image.
7964 This method provides a hook to allow finalization
7965 of a disk image (e.g. writing an MBR).
7966 </para></listitem>
7967 <listitem><para>
7968 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7969 Special content-staging hook called before
7970 <filename>do_prepare_partition()</filename>.
7971 This method is normally empty.</para>
7972
7973 <para>Typically, a partition just uses the passed-in
7974 parameters (e.g. the unmodified value of
7975 <filename>bootimg_dir</filename>).
7976 However, in some cases, things might need to be
7977 more tailored.
7978 As an example, certain files might additionally
7979 need to be taken from
7980 <filename>bootimg_dir + /boot</filename>.
7981 This hook allows those files to be staged in a
7982 customized fashion.
7983 <note>
7984 <filename>get_bitbake_var()</filename>
7985 allows you to access non-standard variables
7986 that you might want to use for this
7987 behavior.
7988 </note>
7989 </para></listitem>
7990 </itemizedlist>
7991 </para>
7992
7993 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007994 You can extend the source plugin mechanism.
7995 To add more hooks, create more source plugin methods
Brad Bishop316dfdd2018-06-25 12:45:53 -04007996 within <filename>SourcePlugin</filename> and the
7997 corresponding derived subclasses.
Brad Bishopc342db32019-05-15 21:57:59 -04007998 The code that calls the plugin methods uses the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007999 <filename>plugin.get_source_plugin_methods()</filename>
8000 function to find the method or methods needed by the call.
8001 Retrieval of those methods is accomplished by filling up
8002 a dict with keys that contain the method names of interest.
8003 On success, these will be filled in with the actual
8004 methods.
8005 See the Wic implementation for examples and details.
8006 </para>
8007 </section>
8008
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008009 <section id='wic-usage-examples'>
8010 <title>Examples</title>
8011
8012 <para>
8013 This section provides several examples that show how to use
8014 the Wic utility.
8015 All the examples assume the list of requirements in the
8016 "<link linkend='wic-requirements'>Requirements</link>"
8017 section have been met.
8018 The examples assume the previously generated image is
8019 <filename>core-image-minimal</filename>.
8020 </para>
8021
8022 <section id='generate-an-image-using-a-provided-kickstart-file'>
8023 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008024
8025 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008026 This example runs in Cooked Mode and uses the
8027 <filename>mkefidisk</filename> kickstart file:
8028 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008029 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008030 INFO: Building wic-tools...
8031 .
8032 .
8033 .
8034 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008035 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008036
8037 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008038 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8039 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8040 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8041 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 -05008042
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008043 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008044 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008045 </literallayout>
8046 The previous example shows the easiest way to create
8047 an image by running in cooked mode and supplying
8048 a kickstart file and the "-e" option to point to the
8049 existing build artifacts.
8050 Your <filename>local.conf</filename> file needs to have
8051 the
8052 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8053 variable set to the machine you are using, which is
8054 "qemux86" in this example.
8055 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008056
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008057 <para>
8058 Once the image builds, the output provides image
8059 location, artifact use, and kickstart file information.
8060 <note>
8061 You should always verify the details provided in the
8062 output to make sure that the image was indeed
8063 created exactly as expected.
8064 </note>
8065 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008066
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008067 <para>
8068 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008069 image from the Build Directory onto a USB stick, or
8070 whatever media for which you built your image, and boot
8071 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008072 You can write the image by using
8073 <filename>bmaptool</filename> or
8074 <filename>dd</filename>:
8075 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008076 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008077 </literallayout>
8078 or
8079 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008080 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008081 </literallayout>
8082 <note>
8083 For more information on how to use the
8084 <filename>bmaptool</filename> to flash a device
8085 with an image, see the
8086 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
8087 section.
8088 </note>
8089 </para>
8090 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008091
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008092 <section id='using-a-modified-kickstart-file'>
8093 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008094
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008095 <para>
8096 Because partitioned image creation is driven by the
8097 kickstart file, it is easy to affect image creation by
8098 changing the parameters in the file.
8099 This next example demonstrates that through modification
8100 of the <filename>directdisk-gpt</filename> kickstart
8101 file.
8102 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008103
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008104 <para>
8105 As mentioned earlier, you can use the command
8106 <filename>wic list images</filename> to show the list
8107 of existing kickstart files.
8108 The directory in which the
8109 <filename>directdisk-gpt.wks</filename> file resides is
8110 <filename>scripts/lib/image/canned-wks/</filename>,
8111 which is located in the
8112 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
8113 (e.g. <filename>poky</filename>).
8114 Because available files reside in this directory,
8115 you can create and add your own custom files to the
8116 directory.
8117 Subsequent use of the
8118 <filename>wic list images</filename> command would then
8119 include your kickstart files.
8120 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008121
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008122 <para>
8123 In this example, the existing
8124 <filename>directdisk-gpt</filename> file already does
8125 most of what is needed.
8126 However, for the hardware in this example, the image
8127 will need to boot from <filename>sdb</filename> instead
8128 of <filename>sda</filename>, which is what the
8129 <filename>directdisk-gpt</filename> kickstart file
8130 uses.
8131 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008132
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008133 <para>
8134 The example begins by making a copy of the
8135 <filename>directdisk-gpt.wks</filename> file in the
8136 <filename>scripts/lib/image/canned-wks</filename>
8137 directory and then by changing the lines that specify
8138 the target disk from which to boot.
8139 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008140 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
8141 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008142 </literallayout>
8143 Next, the example modifies the
8144 <filename>directdisksdb-gpt.wks</filename> file and
8145 changes all instances of
8146 "<filename>--ondisk sda</filename>" to
8147 "<filename>--ondisk sdb</filename>".
8148 The example changes the following two lines and leaves
8149 the remaining lines untouched:
8150 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008151 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008152 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
8153 </literallayout>
8154 Once the lines are changed, the example generates the
8155 <filename>directdisksdb-gpt</filename> image.
8156 The command points the process at the
8157 <filename>core-image-minimal</filename> artifacts for
8158 the Next Unit of Computing (nuc)
8159 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8160 the <filename>local.conf</filename>.
8161 <literallayout class='monospaced'>
8162 $ wic create directdisksdb-gpt -e core-image-minimal
8163 INFO: Building wic-tools...
8164 .
8165 .
8166 .
8167 Initialising tasks: 100% |#######################################| Time: 0:00:01
8168 NOTE: Executing SetScene Tasks
8169 NOTE: Executing RunQueue Tasks
8170 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
8171 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008172
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008173 INFO: The new image(s) can be found here:
8174 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008175
8176 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008177 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8178 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8179 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8180 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 -05008181
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008182 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008183 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008184 </literallayout>
8185 Continuing with the example, you can now directly
8186 <filename>dd</filename> the image to a USB stick, or
8187 whatever media for which you built your image,
8188 and boot the resulting media:
8189 <literallayout class='monospaced'>
8190 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8191 140966+0 records in
8192 140966+0 records out
8193 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8194 $ sudo eject /dev/sdb
8195 </literallayout>
8196 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008197 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008198
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008199 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8200 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008201
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008202 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008203 This next example manually specifies each build artifact
8204 (runs in Raw Mode) and uses a modified kickstart file.
8205 The example also uses the <filename>-o</filename> option
8206 to cause Wic to create the output
8207 somewhere other than the default output directory,
8208 which is the current directory:
8209 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008210 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8211 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8212 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8213 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8214 --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 -05008215
8216 INFO: Creating image(s)...
8217
8218 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008219 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008220
8221 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008222 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8223 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8224 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8225 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 -05008226
8227 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008228 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008229 </literallayout>
8230 For this example,
8231 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8232 did not have to be specified in the
8233 <filename>local.conf</filename> file since the
8234 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008235 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008236 </section>
8237
8238 <section id='using-wic-to-manipulate-an-image'>
8239 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008240
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008241 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008242 Wic image manipulation allows you to shorten turnaround
8243 time during image development.
8244 For example, you can use Wic to delete the kernel partition
8245 of a Wic image and then insert a newly built kernel.
8246 This saves you time from having to rebuild the entire image
8247 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008248 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008249 In order to use Wic to manipulate a Wic image as in
8250 this example, your development machine must have the
8251 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008252 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008253 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008254
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008255 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008256 The following example examines the contents of the Wic
8257 image, deletes the existing kernel, and then inserts a
8258 new kernel:
8259 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008260 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008261 <emphasis>List the Partitions:</emphasis>
8262 Use the <filename>wic ls</filename> command to list
8263 all the partitions in the Wic image:
8264 <literallayout class='monospaced'>
8265 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8266 Num Start End Size Fstype
8267 1 1048576 25041919 23993344 fat16
8268 2 25165824 72157183 46991360 ext4
8269 </literallayout>
8270 The previous output shows two partitions in the
8271 <filename>core-image-minimal-qemux86.wic</filename>
8272 image.
8273 </para></listitem>
8274 <listitem><para>
8275 <emphasis>Examine a Particular Partition:</emphasis>
8276 Use the <filename>wic ls</filename> command again
8277 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008278 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008279 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008280 You can get command usage on any Wic command
8281 using the following form:
8282 <literallayout class='monospaced'>
8283 $ wic help <replaceable>command</replaceable>
8284 </literallayout>
8285 For example, the following command shows you
8286 the various ways to use the
8287 <filename>wic ls</filename> command:
8288 <literallayout class='monospaced'>
8289 $ wic help ls
8290 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008291 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008292 The following command shows what is in Partition
8293 one:
8294 <literallayout class='monospaced'>
8295 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8296 Volume in drive : is boot
8297 Volume Serial Number is E894-1809
8298 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008299
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008300 libcom32 c32 186500 2017-10-09 16:06
8301 libutil c32 24148 2017-10-09 16:06
8302 syslinux cfg 220 2017-10-09 16:06
8303 vesamenu c32 27104 2017-10-09 16:06
8304 vmlinuz 6904608 2017-10-09 16:06
8305 5 files 7 142 580 bytes
8306 16 582 656 bytes free
8307 </literallayout>
8308 The previous output shows five files, with the
8309 <filename>vmlinuz</filename> being the kernel.
8310 <note>
8311 If you see the following error, you need to
8312 update or create a
8313 <filename>~/.mtoolsrc</filename> file and
8314 be sure to have the line “mtools_skip_check=1“
8315 in the file.
8316 Then, run the Wic command again:
8317 <literallayout class='monospaced'>
8318 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8319 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8320 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8321 </literallayout>
8322 </note>
8323 </para></listitem>
8324 <listitem><para>
8325 <emphasis>Remove the Old Kernel:</emphasis>
8326 Use the <filename>wic rm</filename> command to
8327 remove the <filename>vmlinuz</filename> file
8328 (kernel):
8329 <literallayout class='monospaced'>
8330 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8331 </literallayout>
8332 </para></listitem>
8333 <listitem><para>
8334 <emphasis>Add In the New Kernel:</emphasis>
8335 Use the <filename>wic cp</filename> command to
8336 add the updated kernel to the Wic image.
8337 Depending on how you built your kernel, it could
8338 be in different places.
8339 If you used <filename>devtool</filename> and
8340 an SDK to build your kernel, it resides in the
8341 <filename>tmp/work</filename> directory of the
8342 extensible SDK.
8343 If you used <filename>make</filename> to build the
8344 kernel, the kernel will be in the
8345 <filename>workspace/sources</filename> area.
8346 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008347
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008348 <para>The following example assumes
8349 <filename>devtool</filename> was used to build
8350 the kernel:
8351 <literallayout class='monospaced'>
8352 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 \
8353 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8354 </literallayout>
8355 Once the new kernel is added back into the image,
8356 you can use the <filename>dd</filename>
8357 command or
8358 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8359 to flash your wic image onto an SD card
8360 or USB stick and test your target.
8361 <note>
8362 Using <filename>bmaptool</filename> is
8363 generally 10 to 20 times faster than using
8364 <filename>dd</filename>.
8365 </note>
8366 </para></listitem>
8367 </orderedlist>
8368 </para>
8369 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008370 </section>
8371 </section>
8372
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008373 <section id='flashing-images-using-bmaptool'>
8374 <title>Flashing Images Using <filename>bmaptool</filename></title>
8375
8376 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008377 A fast and easy way to flash an image to a bootable device
8378 is to use Bmaptool, which is integrated into the OpenEmbedded
8379 build system.
8380 Bmaptool is a generic tool that creates a file's block map (bmap)
8381 and then uses that map to copy the file.
8382 As compared to traditional tools such as dd or cp, Bmaptool
8383 can copy (or flash) large files like raw system image files
8384 much faster.
8385 <note><title>Notes</title>
8386 <itemizedlist>
8387 <listitem><para>
8388 If you are using Ubuntu or Debian distributions, you
8389 can install the <filename>bmap-tools</filename> package
8390 using the following command and then use the tool
8391 without specifying <filename>PATH</filename> even from
8392 the root account:
8393 <literallayout class='monospaced'>
8394 $ sudo apt-get install bmap-tools
8395 </literallayout>
8396 </para></listitem>
8397 <listitem><para>
8398 If you are unable to install the
8399 <filename>bmap-tools</filename> package, you will
8400 need to build Bmaptool before using it.
8401 Use the following command:
8402 <literallayout class='monospaced'>
8403 $ bitbake bmap-tools-native
8404 </literallayout>
8405 </para></listitem>
8406 </itemizedlist>
8407 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008408 </para>
8409
8410 <para>
8411 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008412 Realize that while this example uses a Wic image, you can use
8413 Bmaptool to flash any type of image.
8414 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008415 <orderedlist>
8416 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008417 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8418 You need to have the following set in your
8419 <filename>local.conf</filename> file before building
8420 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008421 <literallayout class='monospaced'>
8422 IMAGE_FSTYPES += "wic wic.bmap"
8423 </literallayout>
8424 </para></listitem>
8425 <listitem><para>
8426 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008427 Either have your image ready (pre-built with the
8428 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8429 setting previously mentioned) or take the step to build
8430 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008431 <literallayout class='monospaced'>
8432 $ bitbake <replaceable>image</replaceable>
8433 </literallayout>
8434 </para></listitem>
8435 <listitem><para>
8436 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008437 Flash the device with the image by using Bmaptool
8438 depending on your particular setup.
8439 The following commands assume the image resides in the
8440 Build Directory's <filename>deploy/images/</filename>
8441 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008442 <itemizedlist>
8443 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008444 If you have write access to the media, use this
8445 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008446 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008447 $ 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 -05008448 </literallayout>
8449 </para></listitem>
8450 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008451 If you do not have write access to the media, set
8452 your permissions first and then use the same
8453 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008454 <literallayout class='monospaced'>
8455 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008456 $ 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 -05008457 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008458 </para></listitem>
8459 </itemizedlist>
8460 </para></listitem>
8461 </orderedlist>
8462 </para>
8463
8464 <para>
8465 For help on the <filename>bmaptool</filename> command, use the
8466 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008467 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008468 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008469 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008470 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008471 </section>
8472
8473 <section id='making-images-more-secure'>
8474 <title>Making Images More Secure</title>
8475
8476 <para>
8477 Security is of increasing concern for embedded devices.
8478 Consider the issues and problems discussed in just this
8479 sampling of work found across the Internet:
8480 <itemizedlist>
8481 <listitem><para><emphasis>
8482 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8483 by Bruce Schneier
8484 </para></listitem>
8485 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008486 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008487 by Carna Botnet</para></listitem>
8488 <listitem><para><emphasis>
8489 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8490 by Jake Edge
8491 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008492 </itemizedlist>
8493 </para>
8494
8495 <para>
8496 When securing your image is of concern, there are steps, tools,
8497 and variables that you can consider to help you reach the
8498 security goals you need for your particular device.
8499 Not all situations are identical when it comes to making an
8500 image secure.
8501 Consequently, this section provides some guidance and suggestions
8502 for consideration when you want to make your image more secure.
8503 <note>
8504 Because the security requirements and risks are
8505 different for every type of device, this section cannot
8506 provide a complete reference on securing your custom OS.
8507 It is strongly recommended that you also consult other sources
8508 of information on embedded Linux system hardening and on
8509 security.
8510 </note>
8511 </para>
8512
8513 <section id='general-considerations'>
8514 <title>General Considerations</title>
8515
8516 <para>
8517 General considerations exist that help you create more
8518 secure images.
8519 You should consider the following suggestions to help
8520 make your device more secure:
8521 <itemizedlist>
8522 <listitem><para>
8523 Scan additional code you are adding to the system
8524 (e.g. application code) by using static analysis
8525 tools.
8526 Look for buffer overflows and other potential
8527 security problems.
8528 </para></listitem>
8529 <listitem><para>
8530 Pay particular attention to the security for
8531 any web-based administration interface.
8532 </para>
8533 <para>Web interfaces typically need to perform
8534 administrative functions and tend to need to run with
8535 elevated privileges.
8536 Thus, the consequences resulting from the interface's
8537 security becoming compromised can be serious.
8538 Look for common web vulnerabilities such as
8539 cross-site-scripting (XSS), unvalidated inputs,
8540 and so forth.</para>
8541 <para>As with system passwords, the default credentials
8542 for accessing a web-based interface should not be the
8543 same across all devices.
8544 This is particularly true if the interface is enabled
8545 by default as it can be assumed that many end-users
8546 will not change the credentials.
8547 </para></listitem>
8548 <listitem><para>
8549 Ensure you can update the software on the device to
8550 mitigate vulnerabilities discovered in the future.
8551 This consideration especially applies when your
8552 device is network-enabled.
8553 </para></listitem>
8554 <listitem><para>
8555 Ensure you remove or disable debugging functionality
8556 before producing the final image.
8557 For information on how to do this, see the
8558 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8559 section.
8560 </para></listitem>
8561 <listitem><para>
8562 Ensure you have no network services listening that
8563 are not needed.
8564 </para></listitem>
8565 <listitem><para>
8566 Remove any software from the image that is not needed.
8567 </para></listitem>
8568 <listitem><para>
8569 Enable hardware support for secure boot functionality
8570 when your device supports this functionality.
8571 </para></listitem>
8572 </itemizedlist>
8573 </para>
8574 </section>
8575
8576 <section id='security-flags'>
8577 <title>Security Flags</title>
8578
8579 <para>
8580 The Yocto Project has security flags that you can enable that
8581 help make your build output more secure.
8582 The security flags are in the
8583 <filename>meta/conf/distro/include/security_flags.inc</filename>
8584 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008585 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008586 (e.g. <filename>poky</filename>).
8587 <note>
8588 Depending on the recipe, certain security flags are enabled
8589 and disabled by default.
8590 </note>
8591 </para>
8592
8593 <para>
8594<!--
8595 The GCC/LD flags in <filename>security_flags.inc</filename>
8596 enable more secure code generation.
8597 By including the <filename>security_flags.inc</filename>
8598 file, you enable flags to the compiler and linker that cause
8599 them to generate more secure code.
8600 <note>
8601 The GCC/LD flags are enabled by default in the
8602 <filename>poky-lsb</filename> distribution.
8603 </note>
8604-->
8605 Use the following line in your
8606 <filename>local.conf</filename> file or in your custom
8607 distribution configuration file to enable the security
8608 compiler and linker flags for your build:
8609 <literallayout class='monospaced'>
8610 require conf/distro/include/security_flags.inc
8611 </literallayout>
8612 </para>
8613 </section>
8614
8615 <section id='considerations-specific-to-the-openembedded-build-system'>
8616 <title>Considerations Specific to the OpenEmbedded Build System</title>
8617
8618 <para>
8619 You can take some steps that are specific to the
8620 OpenEmbedded build system to make your images more secure:
8621 <itemizedlist>
8622 <listitem><para>
8623 Ensure "debug-tweaks" is not one of your selected
8624 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8625 When creating a new project, the default is to provide you
8626 with an initial <filename>local.conf</filename> file that
8627 enables this feature using the
8628 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8629 <literallayout class='monospaced'>
8630 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8631 </literallayout>
8632 To disable that feature, simply comment out that line in your
8633 <filename>local.conf</filename> file, or
8634 make sure <filename>IMAGE_FEATURES</filename> does not contain
8635 "debug-tweaks" before producing your final image.
8636 Among other things, leaving this in place sets the
8637 root password as blank, which makes logging in for
8638 debugging or inspection easy during
8639 development but also means anyone can easily log in
8640 during production.
8641 </para></listitem>
8642 <listitem><para>
8643 It is possible to set a root password for the image
8644 and also to set passwords for any extra users you might
8645 add (e.g. administrative or service type users).
8646 When you set up passwords for multiple images or
8647 users, you should not duplicate passwords.
8648 </para>
8649 <para>
8650 To set up passwords, use the
8651 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8652 class, which is the preferred method.
8653 For an example on how to set up both root and user
8654 passwords, see the
8655 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8656 section.
8657 <note>
8658 When adding extra user accounts or setting a
8659 root password, be cautious about setting the
8660 same password on every device.
8661 If you do this, and the password you have set
8662 is exposed, then every device is now potentially
8663 compromised.
8664 If you need this access but want to ensure
8665 security, consider setting a different,
8666 random password for each device.
8667 Typically, you do this as a separate step after
8668 you deploy the image onto the device.
8669 </note>
8670 </para></listitem>
8671 <listitem><para>
8672 Consider enabling a Mandatory Access Control (MAC)
8673 framework such as SMACK or SELinux and tuning it
8674 appropriately for your device's usage.
8675 You can find more information in the
8676 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8677 layer.
8678 </para></listitem>
8679 </itemizedlist>
8680 </para>
8681
8682 <para>
8683 </para>
8684 </section>
8685
8686 <section id='tools-for-hardening-your-image'>
8687 <title>Tools for Hardening Your Image</title>
8688
8689 <para>
8690 The Yocto Project provides tools for making your image
8691 more secure.
8692 You can find these tools in the
8693 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008694 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008695 </para>
8696 </section>
8697 </section>
8698
8699 <section id='creating-your-own-distribution'>
8700 <title>Creating Your Own Distribution</title>
8701
8702 <para>
8703 When you build an image using the Yocto Project and
8704 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008705 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8706 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008707 If you wish to gain more control over package alternative
8708 selections, compile-time options, and other low-level
8709 configurations, you can create your own distribution.
8710 </para>
8711
8712 <para>
8713 To create your own distribution, the basic steps consist of
8714 creating your own distribution layer, creating your own
8715 distribution configuration file, and then adding any needed
8716 code and Metadata to the layer.
8717 The following steps provide some more detail:
8718 <itemizedlist>
8719 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8720 Create your distribution layer so that you can keep your
8721 Metadata and code for the distribution separate.
8722 It is strongly recommended that you create and use your own
8723 layer for configuration and code.
8724 Using your own layer as compared to just placing
8725 configurations in a <filename>local.conf</filename>
8726 configuration file makes it easier to reproduce the same
8727 build configuration when using multiple build machines.
8728 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008729 "<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 -05008730 section for information on how to quickly set up a layer.
8731 </para></listitem>
8732 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8733 The distribution configuration file needs to be created in
8734 the <filename>conf/distro</filename> directory of your
8735 layer.
8736 You need to name it using your distribution name
8737 (e.g. <filename>mydistro.conf</filename>).
8738 <note>
8739 The
8740 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8741 variable in your
8742 <filename>local.conf</filename> file determines the
8743 name of your distribution.
8744 </note></para>
8745 <para>You can split out parts of your configuration file
8746 into include files and then "require" them from within
8747 your distribution configuration file.
8748 Be sure to place the include files in the
8749 <filename>conf/distro/include</filename> directory of
8750 your layer.
8751 A common example usage of include files would be to
8752 separate out the selection of desired version and revisions
8753 for individual recipes.
8754</para>
8755 <para>Your configuration file needs to set the following
8756 required variables:
8757 <literallayout class='monospaced'>
8758 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8759 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8760 </literallayout>
8761 These following variables are optional and you typically
8762 set them from the distribution configuration file:
8763 <literallayout class='monospaced'>
8764 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8765 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8766 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8767 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8768 </literallayout>
8769 <tip>
8770 If you want to base your distribution configuration file
8771 on the very basic configuration from OE-Core, you
8772 can use
8773 <filename>conf/distro/defaultsetup.conf</filename> as
8774 a reference and just include variables that differ
8775 as compared to <filename>defaultsetup.conf</filename>.
8776 Alternatively, you can create a distribution
8777 configuration file from scratch using the
8778 <filename>defaultsetup.conf</filename> file
8779 or configuration files from other distributions
8780 such as Poky or Angstrom as references.
8781 </tip></para></listitem>
8782 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8783 Be sure to define any other variables for which you want to
8784 create a default or enforce as part of the distribution
8785 configuration.
8786 You can include nearly any variable from the
8787 <filename>local.conf</filename> file.
8788 The variables you use are not limited to the list in the
8789 previous bulleted item.</para></listitem>
8790 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8791 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008792 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008793 set your
8794 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8795 variable to point to your distribution's configuration file.
8796 For example, if your distribution's configuration file is
8797 named <filename>mydistro.conf</filename>, then you point
8798 to it as follows:
8799 <literallayout class='monospaced'>
8800 DISTRO = "mydistro"
8801 </literallayout></para></listitem>
8802 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8803 Use your layer to hold other information needed for the
8804 distribution:
8805 <itemizedlist>
8806 <listitem><para>Add recipes for installing
8807 distro-specific configuration files that are not
8808 already installed by another recipe.
8809 If you have distro-specific configuration files
8810 that are included by an existing recipe, you should
8811 add an append file (<filename>.bbappend</filename>)
8812 for those.
8813 For general information and recommendations
8814 on how to add recipes to your layer, see the
8815 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8816 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008817 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008818 sections.</para></listitem>
8819 <listitem><para>Add any image recipes that are specific
8820 to your distribution.</para></listitem>
8821 <listitem><para>Add a <filename>psplash</filename>
8822 append file for a branded splash screen.
8823 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008824 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008825 section.</para></listitem>
8826 <listitem><para>Add any other append files to make
8827 custom changes that are specific to individual
8828 recipes.</para></listitem>
8829 </itemizedlist></para></listitem>
8830 </itemizedlist>
8831 </para>
8832 </section>
8833
8834 <section id='creating-a-custom-template-configuration-directory'>
8835 <title>Creating a Custom Template Configuration Directory</title>
8836
8837 <para>
8838 If you are producing your own customized version
8839 of the build system for use by other users, you might
8840 want to customize the message shown by the setup script or
8841 you might want to change the template configuration files (i.e.
8842 <filename>local.conf</filename> and
8843 <filename>bblayers.conf</filename>) that are created in
8844 a new build directory.
8845 </para>
8846
8847 <para>
8848 The OpenEmbedded build system uses the environment variable
8849 <filename>TEMPLATECONF</filename> to locate the directory
8850 from which it gathers configuration information that ultimately
8851 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008852 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008853 <filename>conf</filename> directory.
8854 By default, <filename>TEMPLATECONF</filename> is set as
8855 follows in the <filename>poky</filename> repository:
8856 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008857 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008858 </literallayout>
8859 This is the directory used by the build system to find templates
8860 from which to build some key configuration files.
8861 If you look at this directory, you will see the
8862 <filename>bblayers.conf.sample</filename>,
8863 <filename>local.conf.sample</filename>, and
8864 <filename>conf-notes.txt</filename> files.
8865 The build system uses these files to form the respective
8866 <filename>bblayers.conf</filename> file,
8867 <filename>local.conf</filename> file, and display the list of
8868 BitBake targets when running the setup script.
8869 </para>
8870
8871 <para>
8872 To override these default configuration files with
8873 configurations you want used within every new
8874 Build Directory, simply set the
8875 <filename>TEMPLATECONF</filename> variable to your directory.
8876 The <filename>TEMPLATECONF</filename> variable is set in the
8877 <filename>.templateconf</filename> file, which is in the
8878 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008879 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008880 folder (e.g. <filename>poky</filename>).
8881 Edit the <filename>.templateconf</filename> so that it can locate
8882 your directory.
8883 </para>
8884
8885 <para>
8886 Best practices dictate that you should keep your
8887 template configuration directory in your custom distribution layer.
8888 For example, suppose you have a layer named
8889 <filename>meta-mylayer</filename> located in your home directory
8890 and you want your template configuration directory named
8891 <filename>myconf</filename>.
8892 Changing the <filename>.templateconf</filename> as follows
8893 causes the OpenEmbedded build system to look in your directory
8894 and base its configuration files on the
8895 <filename>*.sample</filename> configuration files it finds.
8896 The final configuration files (i.e.
8897 <filename>local.conf</filename> and
8898 <filename>bblayers.conf</filename> ultimately still end up in
8899 your Build Directory, but they are based on your
8900 <filename>*.sample</filename> files.
8901 <literallayout class='monospaced'>
8902 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8903 </literallayout>
8904 </para>
8905
8906 <para>
8907 Aside from the <filename>*.sample</filename> configuration files,
8908 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008909 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008910 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008911 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008912 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8913 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008914 output.
8915 Customizing this <filename>conf-notes.txt</filename> file is a
8916 good way to make sure your list of custom targets appears
8917 as part of the script's output.
8918 </para>
8919
8920 <para>
8921 Here is the default list of targets displayed as a result of
8922 running either of the setup scripts:
8923 <literallayout class='monospaced'>
8924 You can now run 'bitbake &lt;target&gt;'
8925
8926 Common targets are:
8927 core-image-minimal
8928 core-image-sato
8929 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008930 meta-ide-support
8931 </literallayout>
8932 </para>
8933
8934 <para>
8935 Changing the listed common targets is as easy as editing your
8936 version of <filename>conf-notes.txt</filename> in your
8937 custom template configuration directory and making sure you
8938 have <filename>TEMPLATECONF</filename> set to your directory.
8939 </para>
8940 </section>
8941
Brad Bishop316dfdd2018-06-25 12:45:53 -04008942 <section id='dev-saving-memory-during-a-build'>
8943 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008944
8945 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008946 To help conserve disk space during builds, you can add the
8947 following statement to your project's
8948 <filename>local.conf</filename> configuration file found in the
8949 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8950 <literallayout class='monospaced'>
8951 INHERIT += "rm_work"
8952 </literallayout>
8953 Adding this statement deletes the work directory used for building
8954 a recipe once the recipe is built.
8955 For more information on "rm_work", see the
8956 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8957 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008958 </para>
8959 </section>
8960
8961 <section id='working-with-packages'>
8962 <title>Working with Packages</title>
8963
8964 <para>
8965 This section describes a few tasks that involve packages:
8966 <itemizedlist>
8967 <listitem><para>
8968 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8969 </para></listitem>
8970 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008971 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008972 </para></listitem>
8973 <listitem><para>
8974 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8975 </para></listitem>
8976 <listitem><para>
Brad Bishop15ae2502019-06-18 21:44:24 -04008977 <link linkend='using-runtime-package-management'>Using runtime package management</link>
8978 </para></listitem>
8979 <listitem><para>
8980 <link linkend='generating-and-using-signed-packages'>Generating and using signed packages</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008981 </para></listitem>
8982 <listitem><para>
8983 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8984 </para></listitem>
Brad Bishop15ae2502019-06-18 21:44:24 -04008985 <listitem><para>
8986 <link linkend='creating-node-package-manager-npm-packages'>Creating node package manager (NPM) packages</link>
8987 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008988 </itemizedlist>
8989 </para>
8990
8991 <section id='excluding-packages-from-an-image'>
8992 <title>Excluding Packages from an Image</title>
8993
8994 <para>
8995 You might find it necessary to prevent specific packages
8996 from being installed into an image.
8997 If so, you can use several variables to direct the build
8998 system to essentially ignore installing recommended packages
8999 or to not install a package at all.
9000 </para>
9001
9002 <para>
9003 The following list introduces variables you can use to
9004 prevent packages from being installed into your image.
9005 Each of these variables only works with IPK and RPM
9006 package types.
9007 Support for Debian packages does not exist.
9008 Also, you can use these variables from your
9009 <filename>local.conf</filename> file or attach them to a
9010 specific image recipe by using a recipe name override.
9011 For more detail on the variables, see the descriptions in the
9012 Yocto Project Reference Manual's glossary chapter.
9013 <itemizedlist>
9014 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
9015 Use this variable to specify "recommended-only"
9016 packages that you do not want installed.
9017 </para></listitem>
9018 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
9019 Use this variable to prevent all "recommended-only"
9020 packages from being installed.
9021 </para></listitem>
9022 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
9023 Use this variable to prevent specific packages from
9024 being installed regardless of whether they are
9025 "recommended-only" or not.
9026 You need to realize that the build process could
9027 fail with an error when you
9028 prevent the installation of a package whose presence
9029 is required by an installed package.
9030 </para></listitem>
9031 </itemizedlist>
9032 </para>
9033 </section>
9034
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009035 <section id='incrementing-a-binary-package-version'>
9036 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009037
9038 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009039 This section provides some background on how binary package
9040 versioning is accomplished and presents some of the services,
9041 variables, and terminology involved.
9042 </para>
9043
9044 <para>
9045 In order to understand binary package versioning, you need
9046 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009047 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009048 <listitem><para>
9049 Binary Package: The binary package that is eventually
9050 built and installed into an image.
9051 </para></listitem>
9052 <listitem><para>
9053 Binary Package Version: The binary package version
9054 is composed of two components - a version and a
9055 revision.
9056 <note>
9057 Technically, a third component, the "epoch" (i.e.
9058 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
9059 is involved but this discussion for the most part
9060 ignores <filename>PE</filename>.
9061 </note>
9062 The version and revision are taken from the
9063 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
9064 and
9065 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9066 variables, respectively.
9067 </para></listitem>
9068 <listitem><para>
9069 <filename>PV</filename>: The recipe version.
9070 <filename>PV</filename> represents the version of the
9071 software being packaged.
9072 Do not confuse <filename>PV</filename> with the
9073 binary package version.
9074 </para></listitem>
9075 <listitem><para>
9076 <filename>PR</filename>: The recipe revision.
9077 </para></listitem>
9078 <listitem><para>
9079 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
9080 The OpenEmbedded build system uses this string
9081 to help define the value of <filename>PV</filename>
9082 when the source code revision needs to be included
9083 in it.
9084 </para></listitem>
9085 <listitem><para>
9086 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
9087 A network-based service that helps automate keeping
9088 package feeds compatible with existing package
9089 manager applications such as RPM, APT, and OPKG.
9090 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009091 </itemizedlist>
9092 </para>
9093
9094 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009095 Whenever the binary package content changes, the binary package
9096 version must change.
9097 Changing the binary package version is accomplished by changing
9098 or "bumping" the <filename>PR</filename> and/or
9099 <filename>PV</filename> values.
9100 Increasing these values occurs one of two ways:
9101 <itemizedlist>
9102 <listitem><para>Automatically using a Package Revision
9103 Service (PR Service).
9104 </para></listitem>
9105 <listitem><para>Manually incrementing the
9106 <filename>PR</filename> and/or
9107 <filename>PV</filename> variables.
9108 </para></listitem>
9109 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009110 </para>
9111
9112 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009113 Given a primary challenge of any build system and its users
9114 is how to maintain a package feed that is compatible with
9115 existing package manager applications such as RPM, APT, and
9116 OPKG, using an automated system is much preferred over a
9117 manual system.
9118 In either system, the main requirement is that binary package
9119 version numbering increases in a linear fashion and that a
9120 number of version components exist that support that linear
9121 progression.
9122 For information on how to ensure package revisioning remains
9123 linear, see the
9124 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
9125 section.
9126 </para>
9127
9128 <para>
9129 The following three sections provide related information on the
9130 PR Service, the manual method for "bumping"
9131 <filename>PR</filename> and/or <filename>PV</filename>, and
9132 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009133 </para>
9134
9135 <section id='working-with-a-pr-service'>
9136 <title>Working With a PR Service</title>
9137
9138 <para>
9139 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009140 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009141 is error prone, inaccurate, and causes problems for people
9142 submitting recipes.
9143 Conversely, the PR Service automatically generates
9144 increasing numbers, particularly the revision field,
9145 which removes the human element.
9146 <note>
9147 For additional information on using a PR Service, you
9148 can see the
9149 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
9150 wiki page.
9151 </note>
9152 </para>
9153
9154 <para>
9155 The Yocto Project uses variables in order of
9156 decreasing priority to facilitate revision numbering (i.e.
9157 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
9158 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
9159 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9160 for epoch, version, and revision, respectively).
9161 The values are highly dependent on the policies and
9162 procedures of a given distribution and package feed.
9163 </para>
9164
9165 <para>
9166 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04009167 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009168 which are unique to a given build, the build system
9169 knows when to rebuild packages.
9170 All the inputs into a given task are represented by a
9171 signature, which can trigger a rebuild when different.
9172 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009173 <filename>PR</filename>, <filename>PV</filename>, and
9174 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009175 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009176 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009177 </para>
9178
9179 <para>
9180 The PR Service works with both
9181 <filename>OEBasic</filename> and
9182 <filename>OEBasicHash</filename> generators.
9183 The value of <filename>PR</filename> bumps when the
9184 checksum changes and the different generator mechanisms
9185 change signatures under different circumstances.
9186 </para>
9187
9188 <para>
9189 As implemented, the build system includes values from
9190 the PR Service into the <filename>PR</filename> field as
9191 an addition using the form "<filename>.x</filename>" so
9192 <filename>r0</filename> becomes <filename>r0.1</filename>,
9193 <filename>r0.2</filename> and so forth.
9194 This scheme allows existing <filename>PR</filename> values
9195 to be used for whatever reasons, which include manual
9196 <filename>PR</filename> bumps, should it be necessary.
9197 </para>
9198
9199 <para>
9200 By default, the PR Service is not enabled or running.
9201 Thus, the packages generated are just "self consistent".
9202 The build system adds and removes packages and
9203 there are no guarantees about upgrade paths but images
9204 will be consistent and correct with the latest changes.
9205 </para>
9206
9207 <para>
9208 The simplest form for a PR Service is for it to exist
9209 for a single host development system that builds the
9210 package feed (building system).
9211 For this scenario, you can enable a local PR Service by
9212 setting
9213 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9214 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009215 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009216 <literallayout class='monospaced'>
9217 PRSERV_HOST = "localhost:0"
9218 </literallayout>
9219 Once the service is started, packages will automatically
9220 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009221 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009222 </para>
9223
9224 <para>
9225 If you have a more complex setup where multiple host
9226 development systems work against a common, shared package
9227 feed, you have a single PR Service running and it is
9228 connected to each building system.
9229 For this scenario, you need to start the PR Service using
9230 the <filename>bitbake-prserv</filename> command:
9231 <literallayout class='monospaced'>
9232 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9233 </literallayout>
9234 In addition to hand-starting the service, you need to
9235 update the <filename>local.conf</filename> file of each
9236 building system as described earlier so each system
9237 points to the server and port.
9238 </para>
9239
9240 <para>
9241 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009242 some sanity checks to binary package versions, in
9243 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009244 To enable build history, add the following to each building
9245 system's <filename>local.conf</filename> file:
9246 <literallayout class='monospaced'>
9247 # It is recommended to activate "buildhistory" for testing the PR service
9248 INHERIT += "buildhistory"
9249 BUILDHISTORY_COMMIT = "1"
9250 </literallayout>
9251 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009252 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9253 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009254 </para>
9255
9256 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009257 <para>
9258 The OpenEmbedded build system does not maintain
9259 <filename>PR</filename> information as part of the
9260 shared state (sstate) packages.
9261 If you maintain an sstate feed, its expected that either
9262 all your building systems that contribute to the sstate
9263 feed use a shared PR Service, or you do not run a PR
9264 Service on any of your building systems.
9265 Having some systems use a PR Service while others do
9266 not leads to obvious problems.
9267 </para>
9268
9269 <para>
9270 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009271 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9272 section in the Yocto Project Overview and Concepts
9273 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009274 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009275 </note>
9276 </section>
9277
9278 <section id='manually-bumping-pr'>
9279 <title>Manually Bumping PR</title>
9280
9281 <para>
9282 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009283 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009284 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9285 variable.
9286 </para>
9287
9288 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009289 If a committed change results in changing the package
9290 output, then the value of the PR variable needs to be
9291 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009292 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009293 variable and set its initial value equal to "r0", which is
9294 the default.
9295 Even though the default value is "r0", the practice of
9296 adding it to a new recipe makes it harder to forget to bump
9297 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009298 </para>
9299
9300 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009301 If you are sharing a common <filename>.inc</filename> file
9302 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009303 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009304 variable to ensure that the recipes sharing the
9305 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009306 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009307 The <filename>.inc</filename> file must set
9308 <filename>INC_PR</filename> (initially to "r0"), and all
9309 recipes referring to it should set <filename>PR</filename>
9310 to "${INC_PR}.0" initially, incrementing the last number
9311 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009312 If the <filename>.inc</filename> file is changed then its
9313 <filename>INC_PR</filename> should be incremented.
9314 </para>
9315
9316 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009317 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009318 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9319 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009320 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009321 <filename>INC_PR</filename>).
9322 </para>
9323
9324 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009325 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009326 However, if for some reason <filename>PV</filename> changes
9327 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009328 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9329 variable (Package Epoch).
9330 The <filename>PE</filename> variable defaults to "0".
9331 </para>
9332
9333 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009334 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009335 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9336 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009337 These guidelines define how versions are compared and what
9338 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009339 </para>
9340 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009341
9342 <section id='automatically-incrementing-a-binary-package-revision-number'>
9343 <title>Automatically Incrementing a Package Version Number</title>
9344
9345 <para>
9346 When fetching a repository, BitBake uses the
9347 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9348 variable to determine the specific source code revision
9349 from which to build.
9350 You set the <filename>SRCREV</filename> variable to
9351 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9352 to cause the OpenEmbedded build system to automatically use the
9353 latest revision of the software:
9354 <literallayout class='monospaced'>
9355 SRCREV = "${AUTOREV}"
9356 </literallayout>
9357 </para>
9358
9359 <para>
9360 Furthermore, you need to reference <filename>SRCPV</filename>
9361 in <filename>PV</filename> in order to automatically update
9362 the version whenever the revision of the source code
9363 changes.
9364 Here is an example:
9365 <literallayout class='monospaced'>
9366 PV = "1.0+git${SRCPV}"
9367 </literallayout>
9368 The OpenEmbedded build system substitutes
9369 <filename>SRCPV</filename> with the following:
9370 <literallayout class='monospaced'>
9371 AUTOINC+<replaceable>source_code_revision</replaceable>
9372 </literallayout>
9373 The build system replaces the <filename>AUTOINC</filename> with
9374 a number.
9375 The number used depends on the state of the PR Service:
9376 <itemizedlist>
9377 <listitem><para>
9378 If PR Service is enabled, the build system increments
9379 the number, which is similar to the behavior of
9380 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9381 This behavior results in linearly increasing package
9382 versions, which is desirable.
9383 Here is an example:
9384 <literallayout class='monospaced'>
9385 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9386 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9387 </literallayout>
9388 </para></listitem>
9389 <listitem><para>
9390 If PR Service is not enabled, the build system
9391 replaces the <filename>AUTOINC</filename>
9392 placeholder with zero (i.e. "0").
9393 This results in changing the package version since
9394 the source revision is included.
9395 However, package versions are not increased linearly.
9396 Here is an example:
9397 <literallayout class='monospaced'>
9398 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9399 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9400 </literallayout>
9401 </para></listitem>
9402 </itemizedlist>
9403 </para>
9404
9405 <para>
9406 In summary, the OpenEmbedded build system does not track the
9407 history of binary package versions for this purpose.
9408 <filename>AUTOINC</filename>, in this case, is comparable to
9409 <filename>PR</filename>.
9410 If PR server is not enabled, <filename>AUTOINC</filename>
9411 in the package version is simply replaced by "0".
9412 If PR server is enabled, the build system keeps track of the
9413 package versions and bumps the number when the package
9414 revision changes.
9415 </para>
9416 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009417 </section>
9418
9419 <section id='handling-optional-module-packaging'>
9420 <title>Handling Optional Module Packaging</title>
9421
9422 <para>
9423 Many pieces of software split functionality into optional
Brad Bishopc342db32019-05-15 21:57:59 -04009424 modules (or plugins) and the plugins that are built
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009425 might depend on configuration options.
9426 To avoid having to duplicate the logic that determines what
9427 modules are available in your recipe or to avoid having
9428 to package each module by hand, the OpenEmbedded build system
9429 provides functionality to handle module packaging dynamically.
9430 </para>
9431
9432 <para>
9433 To handle optional module packaging, you need to do two things:
9434 <itemizedlist>
9435 <listitem><para>Ensure the module packaging is actually
9436 done.</para></listitem>
9437 <listitem><para>Ensure that any dependencies on optional
9438 modules from other recipes are satisfied by your recipe.
9439 </para></listitem>
9440 </itemizedlist>
9441 </para>
9442
9443 <section id='making-sure-the-packaging-is-done'>
9444 <title>Making Sure the Packaging is Done</title>
9445
9446 <para>
9447 To ensure the module packaging actually gets done, you use
9448 the <filename>do_split_packages</filename> function within
9449 the <filename>populate_packages</filename> Python function
9450 in your recipe.
9451 The <filename>do_split_packages</filename> function
9452 searches for a pattern of files or directories under a
9453 specified path and creates a package for each one it finds
9454 by appending to the
9455 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9456 variable and setting the appropriate values for
9457 <filename>FILES_packagename</filename>,
9458 <filename>RDEPENDS_packagename</filename>,
9459 <filename>DESCRIPTION_packagename</filename>, and so forth.
9460 Here is an example from the <filename>lighttpd</filename>
9461 recipe:
9462 <literallayout class='monospaced'>
9463 python populate_packages_prepend () {
9464 lighttpd_libdir = d.expand('${libdir}')
9465 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9466 'lighttpd-module-%s', 'Lighttpd module for %s',
9467 extra_depends='')
9468 }
9469 </literallayout>
9470 The previous example specifies a number of things in the
9471 call to <filename>do_split_packages</filename>.
9472 <itemizedlist>
9473 <listitem><para>A directory within the files installed
9474 by your recipe through <filename>do_install</filename>
9475 in which to search.</para></listitem>
9476 <listitem><para>A regular expression used to match module
9477 files in that directory.
9478 In the example, note the parentheses () that mark
9479 the part of the expression from which the module
9480 name should be derived.</para></listitem>
9481 <listitem><para>A pattern to use for the package names.
9482 </para></listitem>
9483 <listitem><para>A description for each package.
9484 </para></listitem>
9485 <listitem><para>An empty string for
9486 <filename>extra_depends</filename>, which disables
9487 the default dependency on the main
9488 <filename>lighttpd</filename> package.
9489 Thus, if a file in <filename>${libdir}</filename>
9490 called <filename>mod_alias.so</filename> is found,
9491 a package called <filename>lighttpd-module-alias</filename>
9492 is created for it and the
9493 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9494 is set to "Lighttpd module for alias".</para></listitem>
9495 </itemizedlist>
9496 </para>
9497
9498 <para>
9499 Often, packaging modules is as simple as the previous
9500 example.
9501 However, more advanced options exist that you can use
9502 within <filename>do_split_packages</filename> to modify its
9503 behavior.
9504 And, if you need to, you can add more logic by specifying
9505 a hook function that is called for each package.
9506 It is also perfectly acceptable to call
9507 <filename>do_split_packages</filename> multiple times if
9508 you have more than one set of modules to package.
9509 </para>
9510
9511 <para>
9512 For more examples that show how to use
9513 <filename>do_split_packages</filename>, see the
9514 <filename>connman.inc</filename> file in the
9515 <filename>meta/recipes-connectivity/connman/</filename>
9516 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009517 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009518 You can also find examples in
9519 <filename>meta/classes/kernel.bbclass</filename>.
9520 </para>
9521
9522 <para>
9523 Following is a reference that shows
9524 <filename>do_split_packages</filename> mandatory and
9525 optional arguments:
9526 <literallayout class='monospaced'>
9527 Mandatory arguments
9528
9529 root
9530 The path in which to search
9531 file_regex
9532 Regular expression to match searched files.
9533 Use parentheses () to mark the part of this
9534 expression that should be used to derive the
9535 module name (to be substituted where %s is
9536 used in other function arguments as noted below)
9537 output_pattern
9538 Pattern to use for the package names. Must
9539 include %s.
9540 description
9541 Description to set for each package. Must
9542 include %s.
9543
9544 Optional arguments
9545
9546 postinst
9547 Postinstall script to use for all packages
9548 (as a string)
9549 recursive
9550 True to perform a recursive search - default
9551 False
9552 hook
9553 A hook function to be called for every match.
9554 The function will be called with the following
9555 arguments (in the order listed):
9556
9557 f
9558 Full path to the file/directory match
9559 pkg
9560 The package name
9561 file_regex
9562 As above
9563 output_pattern
9564 As above
9565 modulename
9566 The module name derived using file_regex
9567
9568 extra_depends
9569 Extra runtime dependencies (RDEPENDS) to be
9570 set for all packages. The default value of None
9571 causes a dependency on the main package
9572 (${PN}) - if you do not want this, pass empty
9573 string '' for this parameter.
9574 aux_files_pattern
9575 Extra item(s) to be added to FILES for each
9576 package. Can be a single string item or a list
9577 of strings for multiple items. Must include %s.
9578 postrm
9579 postrm script to use for all packages (as a
9580 string)
9581 allow_dirs
9582 True to allow directories to be matched -
9583 default False
9584 prepend
9585 If True, prepend created packages to PACKAGES
9586 instead of the default False which appends them
9587 match_path
9588 match file_regex on the whole relative path to
9589 the root rather than just the file name
9590 aux_files_pattern_verbatim
9591 Extra item(s) to be added to FILES for each
9592 package, using the actual derived module name
9593 rather than converting it to something legal
9594 for a package name. Can be a single string item
9595 or a list of strings for multiple items. Must
9596 include %s.
9597 allow_links
9598 True to allow symlinks to be matched - default
9599 False
9600 summary
9601 Summary to set for each package. Must include %s;
9602 defaults to description if not set.
9603 </literallayout>
9604 </para>
9605 </section>
9606
9607 <section id='satisfying-dependencies'>
9608 <title>Satisfying Dependencies</title>
9609
9610 <para>
9611 The second part for handling optional module packaging
9612 is to ensure that any dependencies on optional modules
9613 from other recipes are satisfied by your recipe.
9614 You can be sure these dependencies are satisfied by
9615 using the
9616 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9617 Here is an example that continues with the
9618 <filename>lighttpd</filename> recipe shown earlier:
9619 <literallayout class='monospaced'>
9620 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9621 </literallayout>
9622 The name specified in the regular expression can of
9623 course be anything.
9624 In this example, it is <filename>lighttpd-module-</filename>
9625 and is specified as the prefix to ensure that any
9626 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9627 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9628 on a package name starting with the prefix are satisfied
9629 during build time.
9630 If you are using <filename>do_split_packages</filename>
9631 as described in the previous section, the value you put in
9632 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9633 the name pattern specified in the call to
9634 <filename>do_split_packages</filename>.
9635 </para>
9636 </section>
9637 </section>
9638
9639 <section id='using-runtime-package-management'>
9640 <title>Using Runtime Package Management</title>
9641
9642 <para>
9643 During a build, BitBake always transforms a recipe into one or
9644 more packages.
9645 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009646 and produces a number of packages (e.g.
9647 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9648 <filename>bash-completion</filename>,
9649 <filename>bash-completion-dbg</filename>,
9650 <filename>bash-completion-dev</filename>,
9651 <filename>bash-completion-extra</filename>,
9652 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009653 Not all generated packages are included in an image.
9654 </para>
9655
9656 <para>
9657 In several situations, you might need to update, add, remove,
9658 or query the packages on a target device at runtime
9659 (i.e. without having to generate a new image).
9660 Examples of such situations include:
9661 <itemizedlist>
9662 <listitem><para>
9663 You want to provide in-the-field updates to deployed
9664 devices (e.g. security updates).
9665 </para></listitem>
9666 <listitem><para>
9667 You want to have a fast turn-around development cycle
9668 for one or more applications that run on your device.
9669 </para></listitem>
9670 <listitem><para>
9671 You want to temporarily install the "debug" packages
9672 of various applications on your device so that
9673 debugging can be greatly improved by allowing
9674 access to symbols and source debugging.
9675 </para></listitem>
9676 <listitem><para>
9677 You want to deploy a more minimal package selection of
9678 your device but allow in-the-field updates to add a
9679 larger selection for customization.
9680 </para></listitem>
9681 </itemizedlist>
9682 </para>
9683
9684 <para>
9685 In all these situations, you have something similar to a more
9686 traditional Linux distribution in that in-field devices
9687 are able to receive pre-compiled packages from a server for
9688 installation or update.
9689 Being able to install these packages on a running,
9690 in-field device is what is termed "runtime package
9691 management".
9692 </para>
9693
9694 <para>
9695 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009696 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009697 packages plus the required metadata.
9698 You also need package manipulation tools on the target.
9699 The build machine is a likely candidate to act as the server.
9700 However, that machine does not necessarily have to be the
9701 package server.
9702 The build machine could push its artifacts to another machine
9703 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009704 In fact, doing so is advantageous for a production
9705 environment as getting the packages away from the
9706 development system's build directory prevents accidental
9707 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009708 </para>
9709
9710 <para>
9711 A simple build that targets just one device produces
9712 more than one package database.
9713 In other words, the packages produced by a build are separated
9714 out into a couple of different package groupings based on
9715 criteria such as the target's CPU architecture, the target
9716 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009717 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009718 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009719 <filename>noarch</filename>, <filename>i586</filename>, and
9720 <filename>qemux86</filename>.
9721 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009722 aware of all the packages that were available to it,
9723 you would need to point it to each of these databases
9724 individually.
9725 In a similar way, a traditional Linux distribution usually is
9726 configured to be aware of a number of software repositories
9727 from which it retrieves packages.
9728 </para>
9729
9730 <para>
9731 Using runtime package management is completely optional and
9732 not required for a successful build or deployment in any
9733 way.
9734 But if you want to make use of runtime package management,
9735 you need to do a couple things above and beyond the basics.
9736 The remainder of this section describes what you need to do.
9737 </para>
9738
9739 <section id='runtime-package-management-build'>
9740 <title>Build Considerations</title>
9741
9742 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009743 This section describes build considerations of which you
9744 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009745 package management.
9746 </para>
9747
9748 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009749 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009750 what format or formats to use.
9751 In your configuration, you use the
9752 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009753 variable to specify the format:
9754 <orderedlist>
9755 <listitem><para>
9756 Open the <filename>local.conf</filename> file
9757 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009758 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009759 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9760 </para></listitem>
9761 <listitem><para>
9762 Select the desired package format as follows:
9763 <literallayout class='monospaced'>
9764 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9765 </literallayout>
9766 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009767 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009768 supported package formats.
9769 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009770 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009771 different package formats, you can set the
9772 variable with more than one argument.
9773 However, the OpenEmbedded build system only
9774 uses the first argument when creating an image
9775 or Software Development Kit (SDK).
9776 </note>
9777 </para></listitem>
9778 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009779 </para>
9780
9781 <para>
9782 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009783 package database containing the packages in your current
9784 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009785 target for runtime package management, you can include
9786 "package-management" in the
9787 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9788 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009789 Including "package-management" in this configuration
9790 variable ensures that when the image is assembled for your
9791 target, the image includes the currently-known package
9792 databases as well as the target-specific tools required
9793 for runtime package management to be performed on the
9794 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009795 However, this is not strictly necessary.
9796 You could start your image off without any databases
9797 but only include the required on-target package
9798 tool(s).
9799 As an example, you could include "opkg" in your
9800 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9801 variable if you are using the IPK package format.
9802 You can then initialize your target's package database(s)
9803 later once your image is up and running.
9804 </para>
9805
9806 <para>
9807 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009808 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009809 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009810 package index after the build by using the following
9811 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009812 <literallayout class='monospaced'>
9813 $ bitbake package-index
9814 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009815 It might be tempting to build the package and the
9816 package index at the same time with a command such as
9817 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009818 <literallayout class='monospaced'>
9819 $ bitbake <replaceable>some-package</replaceable> package-index
9820 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009821 Do not do this as BitBake does not schedule the package
9822 index for after the completion of the package you are
9823 building.
9824 Consequently, you cannot be sure of the package index
9825 including information for the package you just built.
9826 Thus, be sure to run the package update step separately
9827 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009828 </para>
9829
9830 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009831 You can use the
9832 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9833 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9834 and
9835 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9836 variables to pre-configure target images to use a package
9837 feed.
9838 If you do not define these variables, then manual steps
9839 as described in the subsequent sections are necessary to
9840 configure the target.
9841 You should set these variables before building the image
9842 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009843 </para>
9844
9845 <para>
9846 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009847 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009848 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009849 For example, if
9850 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009851 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009852 is RPM, then your RPM packages are available in
9853 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009854 </para>
9855 </section>
9856
9857 <section id='runtime-package-management-server'>
9858 <title>Host or Server Machine Setup</title>
9859
9860 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009861 Although other protocols are possible, a server using HTTP
9862 typically serves packages.
9863 If you want to use HTTP, then set up and configure a
9864 web server such as Apache 2, lighttpd, or
9865 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009866 </para>
9867
9868 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009869 To keep things simple, this section describes how to set
9870 up a SimpleHTTPServer web server to share package feeds
9871 from the developer's machine.
9872 Although this server might not be the best for a production
9873 environment, the setup is simple and straight forward.
9874 Should you want to use a different server more suited for
9875 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9876 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009877 </para>
9878
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009879 <para>
9880 From within the build directory where you have built an
9881 image based on your packaging choice (i.e. the
9882 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9883 setting), simply start the server.
9884 The following example assumes a build directory of
9885 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9886 <filename>PACKAGE_CLASSES</filename> setting of
9887 "package_rpm":
9888 <literallayout class='monospaced'>
9889 $ cd ~/poky/build/tmp/deploy/rpm
9890 $ python -m SimpleHTTPServer
9891 </literallayout>
9892 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009893 </section>
9894
9895 <section id='runtime-package-management-target'>
9896 <title>Target Setup</title>
9897
9898 <para>
9899 Setting up the target differs depending on the
9900 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009901 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009902 </para>
9903
9904 <section id='runtime-package-management-target-rpm'>
9905 <title>Using RPM</title>
9906
9907 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009908 The
9909 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9910 (DNF) performs runtime package management of RPM
9911 packages.
9912 In order to use DNF for runtime package management,
9913 you must perform an initial setup on the target
9914 machine for cases where the
9915 <filename>PACKAGE_FEED_*</filename> variables were not
9916 set as part of the image that is running on the
9917 target.
9918 This means if you built your image and did not not use
9919 these variables as part of the build and your image is
9920 now running on the target, you need to perform the
9921 steps in this section if you want to use runtime
9922 package management.
9923 <note>
9924 For information on the
9925 <filename>PACKAGE_FEED_*</filename> variables, see
9926 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9927 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9928 and
9929 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9930 in the Yocto Project Reference Manual variables
9931 glossary.
9932 </note>
9933 </para>
9934
9935 <para>
9936 On the target, you must inform DNF that package
9937 databases are available.
9938 You do this by creating a file named
9939 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9940 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009941 </para>
9942
9943 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009944 As an example, assume the target is able to use the
9945 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009946 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009947 and <filename>qemux86</filename> from a server named
9948 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009949 The specifics for setting up the web server are up to
9950 you.
9951 The critical requirement is that the URIs in the
9952 target repository configuration point to the
9953 correct remote location for the feeds.
9954 <note><title>Tip</title>
9955 For development purposes, you can point the web
9956 server to the build system's
9957 <filename>deploy</filename> directory.
9958 However, for production use, it is better to copy
9959 the package directories to a location outside of
9960 the build area and use that location.
9961 Doing so avoids situations where the build system
9962 overwrites or changes the
9963 <filename>deploy</filename> directory.
9964 </note>
9965 </para>
9966
9967 <para>
9968 When telling DNF where to look for the package
9969 databases, you must declare individual locations
9970 per architecture or a single location used for all
9971 architectures.
9972 You cannot do both:
9973 <itemizedlist>
9974 <listitem><para>
9975 <emphasis>Create an Explicit List of Architectures:</emphasis>
9976 Define individual base URLs to identify where
9977 each package database is located:
9978 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009979 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009980 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009981 </literallayout>
9982 This example informs DNF about individual
9983 package databases for all three architectures.
9984 </para></listitem>
9985 <listitem><para>
9986 <emphasis>Create a Single (Full) Package Index:</emphasis>
9987 Define a single base URL that identifies where
9988 a full package database is located:
9989 <literallayout class='monospaced'>
9990 [oe-packages]
9991 baseurl=http://my.server/rpm
9992 </literallayout>
9993 This example informs DNF about a single package
9994 database that contains all the package index
9995 information for all supported architectures.
9996 </para></listitem>
9997 </itemizedlist>
9998 </para>
9999
10000 <para>
10001 Once you have informed DNF where to find the package
10002 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010003 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010004 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010005 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010006 DNF is now able to find, install, and upgrade packages
10007 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010008 <note>
10009 See the
10010 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
10011 for additional information.
10012 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010013 </para>
10014 </section>
10015
10016 <section id='runtime-package-management-target-ipk'>
10017 <title>Using IPK</title>
10018
10019 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010020 The <filename>opkg</filename> application performs
10021 runtime package management of IPK packages.
10022 You must perform an initial setup for
10023 <filename>opkg</filename> on the target machine
10024 if the
10025 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10026 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10027 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10028 variables have not been set or the target image was
10029 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010030 </para>
10031
10032 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010033 The <filename>opkg</filename> application uses
10034 configuration files to find available package
10035 databases.
10036 Thus, you need to create a configuration file inside
10037 the <filename>/etc/opkg/</filename> direction, which
10038 informs <filename>opkg</filename> of any repository
10039 you want to use.
10040 </para>
10041
10042 <para>
10043 As an example, suppose you are serving packages from a
10044 <filename>ipk/</filename> directory containing the
10045 <filename>i586</filename>,
10046 <filename>all</filename>, and
10047 <filename>qemux86</filename> databases through an
10048 HTTP server named <filename>my.server</filename>.
10049 On the target, create a configuration file
10050 (e.g. <filename>my_repo.conf</filename>) inside the
10051 <filename>/etc/opkg/</filename> directory containing
10052 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010053 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010054 src/gz all http://my.server/ipk/all
10055 src/gz i586 http://my.server/ipk/i586
10056 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010057 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010058 Next, instruct <filename>opkg</filename> to fetch
10059 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010060 <literallayout class='monospaced'>
10061 # opkg update
10062 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010063 The <filename>opkg</filename> application is now able
10064 to find, install, and upgrade packages from the
10065 specified repository.
10066 </para>
10067 </section>
10068
10069 <section id='runtime-package-management-target-deb'>
10070 <title>Using DEB</title>
10071
10072 <para>
10073 The <filename>apt</filename> application performs
10074 runtime package management of DEB packages.
10075 This application uses a source list file to find
10076 available package databases.
10077 You must perform an initial setup for
10078 <filename>apt</filename> on the target machine
10079 if the
10080 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10081 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10082 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10083 variables have not been set or the target image was
10084 built before the variables were set.
10085 </para>
10086
10087 <para>
10088 To inform <filename>apt</filename> of the repository
10089 you want to use, you might create a list file (e.g.
10090 <filename>my_repo.list</filename>) inside the
10091 <filename>/etc/apt/sources.list.d/</filename>
10092 directory.
10093 As an example, suppose you are serving packages from a
10094 <filename>deb/</filename> directory containing the
10095 <filename>i586</filename>,
10096 <filename>all</filename>, and
10097 <filename>qemux86</filename> databases through an
10098 HTTP server named <filename>my.server</filename>.
10099 The list file should contain:
10100 <literallayout class='monospaced'>
10101 deb http://my.server/deb/all ./
10102 deb http://my.server/deb/i586 ./
10103 deb http://my.server/deb/qemux86 ./
10104 </literallayout>
10105 Next, instruct the <filename>apt</filename>
10106 application to fetch the repository information:
10107 <literallayout class='monospaced'>
10108 # apt-get update
10109 </literallayout>
10110 After this step, <filename>apt</filename> is able
10111 to find, install, and upgrade packages from the
10112 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010113 </para>
10114 </section>
10115 </section>
10116 </section>
10117
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010118 <section id='generating-and-using-signed-packages'>
10119 <title>Generating and Using Signed Packages</title>
10120 <para>
10121 In order to add security to RPM packages used during a build,
10122 you can take steps to securely sign them.
10123 Once a signature is verified, the OpenEmbedded build system
10124 can use the package in the build.
10125 If security fails for a signed package, the build system
10126 aborts the build.
10127 </para>
10128
10129 <para>
10130 This section describes how to sign RPM packages during a build
10131 and how to use signed package feeds (repositories) when
10132 doing a build.
10133 </para>
10134
10135 <section id='signing-rpm-packages'>
10136 <title>Signing RPM Packages</title>
10137
10138 <para>
10139 To enable signing RPM packages, you must set up the
10140 following configurations in either your
10141 <filename>local.config</filename> or
10142 <filename>distro.config</filename> file:
10143 <literallayout class='monospaced'>
10144 # Inherit sign_rpm.bbclass to enable signing functionality
10145 INHERIT += " sign_rpm"
10146 # Define the GPG key that will be used for signing.
10147 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
10148 # Provide passphrase for the key
10149 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
10150 </literallayout>
10151 <note>
10152 Be sure to supply appropriate values for both
10153 <replaceable>key_name</replaceable> and
10154 <replaceable>passphrase</replaceable>
10155 </note>
10156 Aside from the
10157 <filename>RPM_GPG_NAME</filename> and
10158 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
10159 previous example, two optional variables related to signing
10160 exist:
10161 <itemizedlist>
10162 <listitem><para>
10163 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10164 Specifies a <filename>gpg</filename> binary/wrapper
10165 that is executed when the package is signed.
10166 </para></listitem>
10167 <listitem><para>
10168 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10169 Specifies the <filename>gpg</filename> home
10170 directory used when the package is signed.
10171 </para></listitem>
10172 </itemizedlist>
10173 </para>
10174 </section>
10175
10176 <section id='processing-package-feeds'>
10177 <title>Processing Package Feeds</title>
10178
10179 <para>
10180 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010181 also enable signed package feeds for IPK and RPM packages.
10182 </para>
10183
10184 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010185 The steps you need to take to enable signed package feed
10186 use are similar to the steps used to sign RPM packages.
10187 You must define the following in your
10188 <filename>local.config</filename> or
10189 <filename>distro.config</filename> file:
10190 <literallayout class='monospaced'>
10191 INHERIT += "sign_package_feed"
10192 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10193 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10194 </literallayout>
10195 For signed package feeds, the passphrase must exist in a
10196 separate file, which is pointed to by the
10197 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10198 variable.
10199 Regarding security, keeping a plain text passphrase out of
10200 the configuration is more secure.
10201 </para>
10202
10203 <para>
10204 Aside from the
10205 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10206 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10207 variables, three optional variables related to signed
10208 package feeds exist:
10209 <itemizedlist>
10210 <listitem><para>
10211 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10212 Specifies a <filename>gpg</filename> binary/wrapper
10213 that is executed when the package is signed.
10214 </para></listitem>
10215 <listitem><para>
10216 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10217 Specifies the <filename>gpg</filename> home
10218 directory used when the package is signed.
10219 </para></listitem>
10220 <listitem><para>
10221 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10222 Specifies the type of <filename>gpg</filename>
10223 signature.
10224 This variable applies only to RPM and IPK package
10225 feeds.
10226 Allowable values for the
10227 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10228 are "ASC", which is the default and specifies ascii
10229 armored, and "BIN", which specifies binary.
10230 </para></listitem>
10231 </itemizedlist>
10232 </para>
10233 </section>
10234 </section>
10235
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010236 <section id='testing-packages-with-ptest'>
10237 <title>Testing Packages With ptest</title>
10238
10239 <para>
10240 A Package Test (ptest) runs tests against packages built
10241 by the OpenEmbedded build system on the target machine.
10242 A ptest contains at least two items: the actual test, and
10243 a shell script (<filename>run-ptest</filename>) that starts
10244 the test.
10245 The shell script that starts the test must not contain
10246 the actual test - the script only starts the test.
10247 On the other hand, the test can be anything from a simple
10248 shell script that runs a binary and checks the output to
10249 an elaborate system of test binaries and data files.
10250 </para>
10251
10252 <para>
10253 The test generates output in the format used by
10254 Automake:
10255 <literallayout class='monospaced'>
10256 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10257 </literallayout>
10258 where the result can be <filename>PASS</filename>,
10259 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10260 and the testname can be any identifying string.
10261 </para>
10262
10263 <para>
10264 For a list of Yocto Project recipes that are already
10265 enabled with ptest, see the
10266 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10267 wiki page.
10268 <note>
10269 A recipe is "ptest-enabled" if it inherits the
10270 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10271 class.
10272 </note>
10273 </para>
10274
10275 <section id='adding-ptest-to-your-build'>
10276 <title>Adding ptest to Your Build</title>
10277
10278 <para>
10279 To add package testing to your build, add the
10280 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10281 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10282 variables to your <filename>local.conf</filename> file,
10283 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010284 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010285 <literallayout class='monospaced'>
10286 DISTRO_FEATURES_append = " ptest"
10287 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10288 </literallayout>
10289 Once your build is complete, the ptest files are installed
10290 into the
10291 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10292 directory within the image, where
10293 <filename><replaceable>package</replaceable></filename>
10294 is the name of the package.
10295 </para>
10296 </section>
10297
10298 <section id='running-ptest'>
10299 <title>Running ptest</title>
10300
10301 <para>
10302 The <filename>ptest-runner</filename> package installs a
10303 shell script that loops through all installed ptest test
10304 suites and runs them in sequence.
10305 Consequently, you might want to add this package to
10306 your image.
10307 </para>
10308 </section>
10309
10310 <section id='getting-your-package-ready'>
10311 <title>Getting Your Package Ready</title>
10312
10313 <para>
10314 In order to enable a recipe to run installed ptests
10315 on target hardware,
10316 you need to prepare the recipes that build the packages
10317 you want to test.
10318 Here is what you have to do for each recipe:
10319 <itemizedlist>
10320 <listitem><para><emphasis>Be sure the recipe
10321 inherits the
10322 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10323 class:</emphasis>
10324 Include the following line in each recipe:
10325 <literallayout class='monospaced'>
10326 inherit ptest
10327 </literallayout>
10328 </para></listitem>
10329 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10330 This script starts your test.
10331 Locate the script where you will refer to it
10332 using
10333 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10334 Here is an example that starts a test for
10335 <filename>dbus</filename>:
10336 <literallayout class='monospaced'>
10337 #!/bin/sh
10338 cd test
10339 make -k runtest-TESTS
10340 </literallayout>
10341 </para></listitem>
10342 <listitem><para><emphasis>Ensure dependencies are
10343 met:</emphasis>
10344 If the test adds build or runtime dependencies
10345 that normally do not exist for the package
10346 (such as requiring "make" to run the test suite),
10347 use the
10348 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10349 and
10350 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10351 variables in your recipe in order for the package
10352 to meet the dependencies.
10353 Here is an example where the package has a runtime
10354 dependency on "make":
10355 <literallayout class='monospaced'>
10356 RDEPENDS_${PN}-ptest += "make"
10357 </literallayout>
10358 </para></listitem>
10359 <listitem><para><emphasis>Add a function to build the
10360 test suite:</emphasis>
10361 Not many packages support cross-compilation of
10362 their test suites.
10363 Consequently, you usually need to add a
10364 cross-compilation function to the package.
10365 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010366
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010367 <para>Many packages based on Automake compile and
10368 run the test suite by using a single command
10369 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010370 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010371 builds and runs on the same computer, while
10372 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010373 on the host but executed for the target
10374 architecture (though often, as in the case for
10375 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010376 The built version of Automake that ships with the
10377 Yocto Project includes a patch that separates
10378 building and execution.
10379 Consequently, packages that use the unaltered,
10380 patched version of <filename>make check</filename>
10381 automatically cross-compiles.</para>
10382 <para>Regardless, you still must add a
10383 <filename>do_compile_ptest</filename> function to
10384 build the test suite.
10385 Add a function similar to the following to your
10386 recipe:
10387 <literallayout class='monospaced'>
10388 do_compile_ptest() {
10389 oe_runmake buildtest-TESTS
10390 }
10391 </literallayout>
10392 </para></listitem>
10393 <listitem><para><emphasis>Ensure special configurations
10394 are set:</emphasis>
10395 If the package requires special configurations
10396 prior to compiling the test code, you must
10397 insert a <filename>do_configure_ptest</filename>
10398 function into the recipe.
10399 </para></listitem>
10400 <listitem><para><emphasis>Install the test
10401 suite:</emphasis>
10402 The <filename>ptest</filename> class
10403 automatically copies the file
10404 <filename>run-ptest</filename> to the target and
10405 then runs make <filename>install-ptest</filename>
10406 to run the tests.
10407 If this is not enough, you need to create a
10408 <filename>do_install_ptest</filename> function and
10409 make sure it gets called after the
10410 "make install-ptest" completes.
10411 </para></listitem>
10412 </itemizedlist>
10413 </para>
10414 </section>
10415 </section>
Brad Bishop15ae2502019-06-18 21:44:24 -040010416
10417 <section id='creating-node-package-manager-npm-packages'>
10418 <title>Creating Node Package Manager (NPM) Packages</title>
10419
10420 <para>
10421 <ulink url='https://en.wikipedia.org/wiki/Npm_(software)'>NPM</ulink>
10422 is a package manager for the JavaScript programming
10423 language.
10424 The Yocto Project supports the NPM
10425 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>.
10426 You can use this fetcher in combination with
10427 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>
10428 to create recipes that produce NPM packages.
10429 </para>
10430
10431 <para>
10432 Two workflows exist that allow you to create NPM packages
10433 using <filename>devtool</filename>: the NPM registry modules
10434 method and the NPM project code method.
10435 <note>
10436 While it is possible to create NPM recipes manually,
10437 using <filename>devtool</filename> is far simpler.
10438 </note>
10439 Additionally, some requirements and caveats exist.
10440 </para>
10441
10442 <section id='npm-package-creation-requirements'>
10443 <title>Requirements and Caveats</title>
10444
10445 <para>
10446 You need to be aware of the following before using
10447 <filename>devtool</filename> to create NPM packages:
10448 <itemizedlist>
10449 <listitem><para>
10450 Of the two methods that you can use
10451 <filename>devtool</filename> to create NPM
10452 packages, the registry approach is slightly
10453 simpler.
10454 However, you might consider the project
10455 approach because you do not have to publish
10456 your module in the NPM registry
10457 (<ulink url='https://docs.npmjs.com/misc/registry'><filename>npm-registry</filename></ulink>),
10458 which is NPM's public registry.
10459 </para></listitem>
10460 <listitem><para>
10461 Be familiar with
10462 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>.
10463 </para></listitem>
10464 <listitem><para>
10465 The NPM host tools need the native
10466 <filename>nodejs-npm</filename> package, which
10467 is part of the OpenEmbedded environment.
10468 You need to get the package by cloning the
10469 <ulink url='https://github.com/openembedded/meta-openembedded'></ulink>
10470 repository out of GitHub.
10471 Be sure to add the path to your local copy to
10472 your <filename>bblayers.conf</filename> file.
10473 </para></listitem>
10474 <listitem><para>
10475 <filename>devtool</filename> cannot detect
10476 native libraries in module dependencies.
10477 Consequently, you must manually add packages
10478 to your recipe.
10479 </para></listitem>
10480 <listitem><para>
10481 While deploying NPM packages,
10482 <filename>devtool</filename> cannot determine
10483 which dependent packages are missing on the
10484 target (e.g. the node runtime
10485 <filename>nodejs</filename>).
10486 Consequently, you need to find out what
10487 files are missing and be sure they are on the
10488 target.
10489 </para></listitem>
10490 <listitem><para>
10491 Although you might not need NPM to run your
10492 node package, it is useful to have NPM on your
10493 target.
10494 The NPM package name is
10495 <filename>nodejs-npm</filename>.
10496 </para></listitem>
10497 </itemizedlist>
10498 </para>
10499 </section>
10500
10501 <section id='npm-using-the-registry-modules-method'>
10502 <title>Using the Registry Modules Method</title>
10503
10504 <para>
10505 This section presents an example that uses the
10506 <filename>cute-files</filename> module, which is a
10507 file browser web application.
10508 <note>
10509 You must know the <filename>cute-files</filename>
10510 module version.
10511 </note>
10512 </para>
10513
10514 <para>
10515 The first thing you need to do is use
10516 <filename>devtool</filename> and the NPM fetcher to
10517 create the recipe:
10518 <literallayout class='monospaced'>
10519 $ devtool add "npm://registry.npmjs.org;name=cute-files;version=1.0.2"
10520 </literallayout>
10521 The <filename>devtool add</filename> command runs
10522 <filename>recipetool create</filename> and uses the
10523 same fetch URI to download each dependency and capture
10524 license details where possible.
10525 The result is a generated recipe.
10526 </para>
10527
10528 <para>
10529 The recipe file is fairly simple and contains every
10530 license that <filename>recipetool</filename> finds
10531 and includes the licenses in the recipe's
10532 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
10533 variables.
10534 You need to examine the variables and look for those
10535 with "unknown" in the
10536 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
10537 field.
10538 You need to track down the license information for
10539 "unknown" modules and manually add the information to the
10540 recipe.
10541 </para>
10542
10543 <para>
10544 <filename>recipetool</filename> creates "shrinkwrap" and
10545 "lockdown" files for your recipe.
10546 Shrinkwrap files capture the version of all dependent
10547 modules.
10548 Many packages do not provide shrinkwrap files.
10549 <filename>recipetool</filename> create a shrinkwrap
10550 file as it runs.
10551 You can replace the shrinkwrap file with your own file
10552 by setting the <filename>NPM_SHRINKWRAP</filename>
10553 variable.
10554 </para>
10555
10556 <para>
10557 Lockdown files contain the checksum for each module
10558 to determine if your users download the same files when
10559 building with a recipe.
10560 Lockdown files ensure that dependencies have not been
10561 changed and that your NPM registry is still providing
10562 the same file.
10563 <note>
10564 A package is created for each sub-module.
10565 This policy is the only practical way to have the
10566 licenses for all of the dependencies represented
10567 in the license manifest of the image.
10568 </note>
10569 </para>
10570
10571 <para>
10572 The <filename>devtool edit-recipe</filename> command
10573 lets you take a look at the recipe:
10574 <literallayout class='monospaced'>
10575 $ devtool edit-recipe cute-files
10576 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
10577 LICENSE = "BSD-3-Clause &amp; Unknown &amp; MIT &amp; ISC"
10578 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
10579 file://node_modules/content-disposition/LICENSE;md5=c6e0ce1e688c5ff16db06b7259e9cd20 \
10580 file://node_modules/express/LICENSE;md5=5513c00a5c36cd361da863dd9aa8875d \
10581 ...
10582
10583 SRC_URI = "npm://registry.npmjs.org;name=cute-files;version=${PV}"
10584 NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json"
10585 NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"
10586 inherit npm
10587 # Must be set after inherit npm since that itself sets S
10588 S = "${WORKDIR}/npmpkg"
10589
10590 LICENSE_${PN}-content-disposition = "MIT"
10591 ...
10592 LICENSE_${PN}-express = "MIT"
10593 LICENSE_${PN} = "MIT"
10594 </literallayout>
10595 Three key points exist in the previous example:
10596 <itemizedlist>
10597 <listitem><para>
10598 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10599 uses the NPM scheme so that the NPM fetcher
10600 is used.
10601 </para></listitem>
10602 <listitem><para>
10603 <filename>recipetool</filename> collects all
10604 the license information.
10605 If a sub-module's license is unavailable,
10606 the sub-module's name appears in the comments.
10607 </para></listitem>
10608 <listitem><para>
10609 The <filename>inherit npm</filename> statement
10610 causes the
10611 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-npm'><filename>npm</filename></ulink>
10612 class to package up all the modules.
10613 </para></listitem>
10614 </itemizedlist>
10615 </para>
10616
10617 <para>
10618 You can run the following command to build the
10619 <filename>cute-files</filename> package:
10620 <literallayout class='monospaced'>
10621 $ devtool build cute-files
10622 </literallayout>
10623 Remember that <filename>nodejs</filename> must be
10624 installed on the target before your package.
10625 </para>
10626
10627 <para>
10628 Assuming 192.168.7.2 for the target's IP address, use
10629 the following command to deploy your package:
10630 <literallayout class='monospaced'>
10631 $ devtool deploy-target -s cute-files root@192.168.7.2
10632 </literallayout>
10633 Once the package is installed on the target, you can
10634 test the application:
10635 <note>
10636 Because of a know issue, you cannot simply run
10637 <filename>cute-files</filename> as you would if you
10638 had run <filename>npm install</filename>.
10639 </note>
10640 <literallayout class='monospaced'>
10641 $ cd /usr/lib/node_modules/cute-files
10642 $ node cute-files.js
10643 </literallayout>
10644 On a browser, go to
10645 <filename>http://192.168.7.2:3000</filename> and you
10646 see the following:
10647 <imagedata fileref="figures/cute-files-npm-example.png" align="center" width="6in" depth="4in" />
10648 </para>
10649
10650 <para>
10651 You can find the recipe in
10652 <filename>workspace/recipes/cute-files</filename>.
10653 You can use the recipe in any layer you choose.
10654 </para>
10655 </section>
10656
10657 <section id='npm-using-the-npm-projects-method'>
10658 <title>Using the NPM Projects Code Method</title>
10659
10660 <para>
10661 Although it is useful to package modules already in the
10662 NPM registry, adding <filename>node.js</filename> projects
10663 under development is a more common developer use case.
10664 </para>
10665
10666 <para>
10667 This section covers the NPM projects code method, which is
10668 very similar to the "registry" approach described in the
10669 previous section.
10670 In the NPM projects method, you provide
10671 <filename>devtool</filename> with an URL that points to the
10672 source files.
10673 </para>
10674
10675 <para>
10676 Replicating the same example, (i.e.
10677 <filename>cute-files</filename>) use the following command:
10678 <literallayout class='monospaced'>
10679 $ devtool add https://github.com/martinaglv/cute-files.git
10680 </literallayout>
10681 The recipe this command generates is very similar to the
10682 recipe created in the previous section.
10683 However, the <filename>SRC_URI</filename> looks like the
10684 following:
10685 <literallayout class='monospaced'>
10686 SRC_URI = "git://github.com/martinaglv/cute-files.git;protocol=https \
10687 npm://registry.npmjs.org;name=commander;version=2.9.0;subdir=node_modules/commander \
10688 npm://registry.npmjs.org;name=express;version=4.14.0;subdir=node_modules/express \
10689 npm://registry.npmjs.org;name=content-disposition;version=0.3.0;subdir=node_modules/content-disposition \
10690 "
10691 </literallayout>
10692 In this example, the main module is taken from the Git
10693 repository and dependents are taken from the NPM registry.
10694 Other than those differences, the recipe is basically the
10695 same between the two methods.
10696 You can build and deploy the package exactly as described
10697 in the previous section that uses the registry modules
10698 method.
10699 </para>
10700 </section>
10701 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010702 </section>
10703
Brad Bishop316dfdd2018-06-25 12:45:53 -040010704 <section id='efficiently-fetching-source-files-during-a-build'>
10705 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010706
10707 <para>
10708 The OpenEmbedded build system works with source files located
10709 through the
10710 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10711 variable.
10712 When you build something using BitBake, a big part of the operation
10713 is locating and downloading all the source tarballs.
10714 For images, downloading all the source for various packages can
10715 take a significant amount of time.
10716 </para>
10717
10718 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010719 This section shows you how you can use mirrors to speed up
10720 fetching source files and how you can pre-fetch files all of which
10721 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010722 </para>
10723
10724 <section id='setting-up-effective-mirrors'>
10725 <title>Setting up Effective Mirrors</title>
10726
10727 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010728 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010729 build is simply downloading all of the source tarballs.
10730 Maybe you have been working with another build system
10731 (OpenEmbedded or Angstrom) for which you have built up a
10732 sizable directory of source tarballs.
10733 Or, perhaps someone else has such a directory for which you
10734 have read access.
10735 If so, you can save time by adding statements to your
10736 configuration file so that the build process checks local
10737 directories first for existing tarballs before checking the
10738 Internet.
10739 </para>
10740
10741 <para>
10742 Here is an efficient way to set it up in your
10743 <filename>local.conf</filename> file:
10744 <literallayout class='monospaced'>
10745 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10746 INHERIT += "own-mirrors"
10747 BB_GENERATE_MIRROR_TARBALLS = "1"
10748 # BB_NO_NETWORK = "1"
10749 </literallayout>
10750 </para>
10751
10752 <para>
10753 In the previous example, the
10754 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10755 variable causes the OpenEmbedded build system to generate
10756 tarballs of the Git repositories and store them in the
10757 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10758 directory.
10759 Due to performance reasons, generating and storing these
10760 tarballs is not the build system's default behavior.
10761 </para>
10762
10763 <para>
10764 You can also use the
10765 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10766 variable.
10767 For an example, see the variable's glossary entry in the
10768 Yocto Project Reference Manual.
10769 </para>
10770 </section>
10771
10772 <section id='getting-source-files-and-suppressing-the-build'>
10773 <title>Getting Source Files and Suppressing the Build</title>
10774
10775 <para>
10776 Another technique you can use to ready yourself for a
10777 successive string of build operations, is to pre-fetch
10778 all the source files without actually starting a build.
10779 This technique lets you work through any download issues
10780 and ultimately gathers all the source files into your
10781 download directory
10782 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10783 which is located with
10784 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10785 </para>
10786
10787 <para>
10788 Use the following BitBake command form to fetch all the
10789 necessary sources without starting the build:
10790 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010791 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010792 </literallayout>
10793 This variation of the BitBake command guarantees that you
10794 have all the sources for that BitBake target should you
10795 disconnect from the Internet and want to do the build
10796 later offline.
10797 </para>
10798 </section>
10799 </section>
10800
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010801 <section id="selecting-an-initialization-manager">
10802 <title>Selecting an Initialization Manager</title>
10803
10804 <para>
10805 By default, the Yocto Project uses SysVinit as the initialization
10806 manager.
10807 However, support also exists for systemd,
10808 which is a full replacement for init with
10809 parallel starting of services, reduced shell overhead and other
10810 features that are used by many distributions.
10811 </para>
10812
10813 <para>
10814 If you want to use SysVinit, you do
10815 not have to do anything.
10816 But, if you want to use systemd, you must
10817 take some steps as described in the following sections.
10818 </para>
10819
10820 <section id='using-systemd-exclusively'>
10821 <title>Using systemd Exclusively</title>
10822
10823 <para>
Brad Bishop15ae2502019-06-18 21:44:24 -040010824 Set these variables in your distribution configuration
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010825 file as follows:
10826 <literallayout class='monospaced'>
10827 DISTRO_FEATURES_append = " systemd"
10828 VIRTUAL-RUNTIME_init_manager = "systemd"
10829 </literallayout>
10830 You can also prevent the SysVinit
10831 distribution feature from
10832 being automatically enabled as follows:
10833 <literallayout class='monospaced'>
10834 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10835 </literallayout>
10836 Doing so removes any redundant SysVinit scripts.
10837 </para>
10838
10839 <para>
10840 To remove initscripts from your image altogether,
10841 set this variable also:
10842 <literallayout class='monospaced'>
10843 VIRTUAL-RUNTIME_initscripts = ""
10844 </literallayout>
10845 </para>
10846
10847 <para>
10848 For information on the backfill variable, see
10849 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10850 </para>
10851 </section>
10852
10853 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10854 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10855
10856 <para>
10857 Set these variables in your distribution configuration
10858 file as follows:
10859 <literallayout class='monospaced'>
10860 DISTRO_FEATURES_append = " systemd"
10861 VIRTUAL-RUNTIME_init_manager = "systemd"
10862 </literallayout>
10863 Doing so causes your main image to use the
10864 <filename>packagegroup-core-boot.bb</filename> recipe and
10865 systemd.
10866 The rescue/minimal image cannot use this package group.
10867 However, it can install SysVinit
10868 and the appropriate packages will have support for both
10869 systemd and SysVinit.
10870 </para>
10871 </section>
10872 </section>
10873
10874 <section id="selecting-dev-manager">
10875 <title>Selecting a Device Manager</title>
10876
10877 <para>
10878 The Yocto Project provides multiple ways to manage the device
10879 manager (<filename>/dev</filename>):
10880 <itemizedlist>
10881 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10882 For this case, the <filename>/dev</filename> directory
10883 is persistent and the required device nodes are created
10884 during the build.
10885 </para></listitem>
10886 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10887 For this case, the <filename>/dev</filename> directory
10888 is provided by the kernel as an in-memory file system and
10889 is automatically populated by the kernel at runtime.
10890 Additional configuration of device nodes is done in user
10891 space by a device manager like
10892 <filename>udev</filename> or
10893 <filename>busybox-mdev</filename>.
10894 </para></listitem>
10895 </itemizedlist>
10896 </para>
10897
10898 <section id="static-dev-management">
10899 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10900
10901 <para>
10902 To use the static method for device population, you need to
10903 set the
10904 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10905 variable to "0" as follows:
10906 <literallayout class='monospaced'>
10907 USE_DEVFS = "0"
10908 </literallayout>
10909 </para>
10910
10911 <para>
10912 The content of the resulting <filename>/dev</filename>
10913 directory is defined in a Device Table file.
10914 The
10915 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10916 variable defines the Device Table to use and should be set
10917 in the machine or distro configuration file.
10918 Alternatively, you can set this variable in your
10919 <filename>local.conf</filename> configuration file.
10920 </para>
10921
10922 <para>
10923 If you do not define the
10924 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10925 <filename>device_table-minimal.txt</filename> is used:
10926 <literallayout class='monospaced'>
10927 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10928 </literallayout>
10929 </para>
10930
10931 <para>
10932 The population is handled by the <filename>makedevs</filename>
10933 utility during image creation:
10934 </para>
10935 </section>
10936
10937 <section id="devtmpfs-dev-management">
10938 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10939
10940 <para>
10941 To use the dynamic method for device population, you need to
10942 use (or be sure to set) the
10943 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10944 variable to "1", which is the default:
10945 <literallayout class='monospaced'>
10946 USE_DEVFS = "1"
10947 </literallayout>
10948 With this setting, the resulting <filename>/dev</filename>
10949 directory is populated by the kernel using
10950 <filename>devtmpfs</filename>.
10951 Make sure the corresponding kernel configuration variable
10952 <filename>CONFIG_DEVTMPFS</filename> is set when building
10953 you build a Linux kernel.
10954 </para>
10955
10956 <para>
10957 All devices created by <filename>devtmpfs</filename> will be
10958 owned by <filename>root</filename> and have permissions
10959 <filename>0600</filename>.
10960 </para>
10961
10962 <para>
10963 To have more control over the device nodes, you can use a
10964 device manager like <filename>udev</filename> or
10965 <filename>busybox-mdev</filename>.
10966 You choose the device manager by defining the
10967 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10968 in your machine or distro configuration file.
10969 Alternatively, you can set this variable in your
10970 <filename>local.conf</filename> configuration file:
10971 <literallayout class='monospaced'>
10972 VIRTUAL-RUNTIME_dev_manager = "udev"
10973
10974 # Some alternative values
10975 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10976 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10977 </literallayout>
10978 </para>
10979 </section>
10980 </section>
10981
10982 <section id="platdev-appdev-srcrev">
10983 <title>Using an External SCM</title>
10984
10985 <para>
10986 If you're working on a recipe that pulls from an external Source
10987 Code Manager (SCM), it is possible to have the OpenEmbedded build
10988 system notice new recipe changes added to the SCM and then build
10989 the resulting packages that depend on the new recipes by using
10990 the latest versions.
10991 This only works for SCMs from which it is possible to get a
10992 sensible revision number for changes.
10993 Currently, you can do this with Apache Subversion (SVN), Git, and
10994 Bazaar (BZR) repositories.
10995 </para>
10996
10997 <para>
10998 To enable this behavior, the
10999 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
11000 of the recipe needs to reference
11001 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
11002 Here is an example:
11003 <literallayout class='monospaced'>
11004 PV = "1.2.3+git${SRCPV}"
11005 </literallayout>
11006 Then, you can add the following to your
11007 <filename>local.conf</filename>:
11008 <literallayout class='monospaced'>
11009 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
11010 </literallayout>
11011 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
11012 is the name of the recipe for which you want to enable automatic source
11013 revision updating.
11014 </para>
11015
11016 <para>
11017 If you do not want to update your local configuration file, you can
11018 add the following directly to the recipe to finish enabling
11019 the feature:
11020 <literallayout class='monospaced'>
11021 SRCREV = "${AUTOREV}"
11022 </literallayout>
11023 </para>
11024
11025 <para>
11026 The Yocto Project provides a distribution named
11027 <filename>poky-bleeding</filename>, whose configuration
11028 file contains the line:
11029 <literallayout class='monospaced'>
11030 require conf/distro/include/poky-floating-revisions.inc
11031 </literallayout>
11032 This line pulls in the listed include file that contains
11033 numerous lines of exactly that form:
11034 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011035 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
11036 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
11037 #SRCREV_pn-opkg ?= "${AUTOREV}"
11038 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
11039 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011040 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
11041 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
11042 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
11043 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
11044 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011045 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
11046 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
11047 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
11048 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011049 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
11050 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011051 .
11052 .
11053 .
11054 </literallayout>
11055 These lines allow you to experiment with building a
11056 distribution that tracks the latest development source
11057 for numerous packages.
11058 <note><title>Caution</title>
11059 The <filename>poky-bleeding</filename> distribution
11060 is not tested on a regular basis.
11061 Keep this in mind if you use it.
11062 </note>
11063 </para>
11064 </section>
11065
11066 <section id='creating-a-read-only-root-filesystem'>
11067 <title>Creating a Read-Only Root Filesystem</title>
11068
11069 <para>
11070 Suppose, for security reasons, you need to disable
11071 your target device's root filesystem's write permissions
11072 (i.e. you need a read-only root filesystem).
11073 Or, perhaps you are running the device's operating system
11074 from a read-only storage device.
11075 For either case, you can customize your image for
11076 that behavior.
11077 </para>
11078
11079 <note>
11080 Supporting a read-only root filesystem requires that the system and
11081 applications do not try to write to the root filesystem.
11082 You must configure all parts of the target system to write
11083 elsewhere, or to gracefully fail in the event of attempting to
11084 write to the root filesystem.
11085 </note>
11086
11087 <section id='creating-the-root-filesystem'>
11088 <title>Creating the Root Filesystem</title>
11089
11090 <para>
11091 To create the read-only root filesystem, simply add the
11092 "read-only-rootfs" feature to your image.
11093 Using either of the following statements in your
11094 image recipe or from within the
11095 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011096 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011097 causes the build system to create a read-only root filesystem:
11098 <literallayout class='monospaced'>
11099 IMAGE_FEATURES = "read-only-rootfs"
11100 </literallayout>
11101 or
11102 <literallayout class='monospaced'>
11103 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
11104 </literallayout>
11105 </para>
11106
11107 <para>
11108 For more information on how to use these variables, see the
11109 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
11110 section.
11111 For information on the variables, see
11112 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
11113 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
11114 </para>
11115 </section>
11116
11117 <section id='post-installation-scripts'>
11118 <title>Post-Installation Scripts</title>
11119
11120 <para>
11121 It is very important that you make sure all
11122 post-Installation (<filename>pkg_postinst</filename>) scripts
11123 for packages that are installed into the image can be run
11124 at the time when the root filesystem is created during the
11125 build on the host system.
11126 These scripts cannot attempt to run during first-boot on the
11127 target device.
11128 With the "read-only-rootfs" feature enabled,
11129 the build system checks during root filesystem creation to make
11130 sure all post-installation scripts succeed.
11131 If any of these scripts still need to be run after the root
11132 filesystem is created, the build immediately fails.
11133 These build-time checks ensure that the build fails
11134 rather than the target device fails later during its
11135 initial boot operation.
11136 </para>
11137
11138 <para>
11139 Most of the common post-installation scripts generated by the
11140 build system for the out-of-the-box Yocto Project are engineered
11141 so that they can run during root filesystem creation
11142 (e.g. post-installation scripts for caching fonts).
11143 However, if you create and add custom scripts, you need
11144 to be sure they can be run during this file system creation.
11145 </para>
11146
11147 <para>
11148 Here are some common problems that prevent
11149 post-installation scripts from running during root filesystem
11150 creation:
11151 <itemizedlist>
11152 <listitem><para>
11153 <emphasis>Not using $D in front of absolute
11154 paths:</emphasis>
11155 The build system defines
11156 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
11157 when the root filesystem is created.
11158 Furthermore, <filename>$D</filename> is blank when the
11159 script is run on the target device.
11160 This implies two purposes for <filename>$D</filename>:
11161 ensuring paths are valid in both the host and target
11162 environments, and checking to determine which
11163 environment is being used as a method for taking
11164 appropriate actions.
11165 </para></listitem>
11166 <listitem><para>
11167 <emphasis>Attempting to run processes that are
11168 specific to or dependent on the target
11169 architecture:</emphasis>
11170 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011171 tools, which run on the host system,
11172 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011173 by alternatively running the processes under QEMU,
11174 which has the <filename>qemu_run_binary</filename>
11175 function.
11176 For more information, see the
11177 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
11178 class.</para></listitem>
11179 </itemizedlist>
11180 </para>
11181 </section>
11182
11183 <section id='areas-with-write-access'>
11184 <title>Areas With Write Access</title>
11185
11186 <para>
11187 With the "read-only-rootfs" feature enabled,
11188 any attempt by the target to write to the root filesystem at
11189 runtime fails.
11190 Consequently, you must make sure that you configure processes
11191 and applications that attempt these types of writes do so
11192 to directories with write access (e.g.
11193 <filename>/tmp</filename> or <filename>/var/run</filename>).
11194 </para>
11195 </section>
11196 </section>
11197
Brad Bishop316dfdd2018-06-25 12:45:53 -040011198
11199
11200
11201 <section id='maintaining-build-output-quality'>
11202 <title>Maintaining Build Output Quality</title>
11203
11204 <para>
11205 Many factors can influence the quality of a build.
11206 For example, if you upgrade a recipe to use a new version of an
11207 upstream software package or you experiment with some new
11208 configuration options, subtle changes can occur that you might
11209 not detect until later.
11210 Consider the case where your recipe is using a newer version of
11211 an upstream package.
11212 In this case, a new version of a piece of software might
11213 introduce an optional dependency on another library, which is
11214 auto-detected.
11215 If that library has already been built when the software is
11216 building, the software will link to the built library and that
11217 library will be pulled into your image along with the new
11218 software even if you did not want the library.
11219 </para>
11220
11221 <para>
11222 The
11223 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
11224 class exists to help you maintain the quality of your build
11225 output.
11226 You can use the class to highlight unexpected and possibly
11227 unwanted changes in the build output.
11228 When you enable build history, it records information about the
11229 contents of each package and image and then commits that
11230 information to a local Git repository where you can examine
11231 the information.
11232 </para>
11233
11234 <para>
11235 The remainder of this section describes the following:
11236 <itemizedlist>
11237 <listitem><para>
11238 How you can enable and disable build history
11239 </para></listitem>
11240 <listitem><para>
11241 How to understand what the build history contains
11242 </para></listitem>
11243 <listitem><para>
11244 How to limit the information used for build history
11245 </para></listitem>
11246 <listitem><para>
11247 How to examine the build history from both a
11248 command-line and web interface
11249 </para></listitem>
11250 </itemizedlist>
11251 </para>
11252
11253 <section id='enabling-and-disabling-build-history'>
11254 <title>Enabling and Disabling Build History</title>
11255
11256 <para>
11257 Build history is disabled by default.
11258 To enable it, add the following <filename>INHERIT</filename>
11259 statement and set the
11260 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
11261 variable to "1" at the end of your
11262 <filename>conf/local.conf</filename> file found in the
11263 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11264 <literallayout class='monospaced'>
11265 INHERIT += "buildhistory"
11266 BUILDHISTORY_COMMIT = "1"
11267 </literallayout>
11268 Enabling build history as previously described causes the
11269 OpenEmbedded build system to collect build output information
11270 and commit it as a single commit to a local
11271 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
11272 repository.
11273 <note>
11274 Enabling build history increases your build times slightly,
11275 particularly for images, and increases the amount of disk
11276 space used during the build.
11277 </note>
11278 </para>
11279
11280 <para>
11281 You can disable build history by removing the previous
11282 statements from your <filename>conf/local.conf</filename>
11283 file.
11284 </para>
11285 </section>
11286
11287 <section id='understanding-what-the-build-history-contains'>
11288 <title>Understanding What the Build History Contains</title>
11289
11290 <para>
11291 Build history information is kept in
11292 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
11293 in the Build Directory as defined by the
11294 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
11295 variable.
11296 The following is an example abbreviated listing:
11297 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
11298 </para>
11299
11300 <para>
11301 At the top level, a <filename>metadata-revs</filename>
11302 file exists that lists the revisions of the repositories for
11303 the enabled layers when the build was produced.
11304 The rest of the data splits into separate
11305 <filename>packages</filename>, <filename>images</filename>
11306 and <filename>sdk</filename> directories, the contents of
11307 which are described as follows.
11308 </para>
11309
11310 <section id='build-history-package-information'>
11311 <title>Build History Package Information</title>
11312
11313 <para>
11314 The history for each package contains a text file that has
11315 name-value pairs with information about the package.
11316 For example,
11317 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
11318 contains the following:
11319 <literallayout class='monospaced'>
11320 PV = 1.22.1
11321 PR = r32
11322 RPROVIDES =
11323 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
11324 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
11325 PKGSIZE = 540168
11326 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
11327 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
11328 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
11329 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
11330 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
11331 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
11332 /etc/busybox.links.nosuid /etc/busybox.links.suid
11333 </literallayout>
11334 Most of these name-value pairs correspond to variables
11335 used to produce the package.
11336 The exceptions are <filename>FILELIST</filename>, which
11337 is the actual list of files in the package, and
11338 <filename>PKGSIZE</filename>, which is the total size of
11339 files in the package in bytes.
11340 </para>
11341
11342 <para>
11343 A file also exists that corresponds to the recipe from
11344 which the package came (e.g.
11345 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
11346 <literallayout class='monospaced'>
11347 PV = 1.22.1
11348 PR = r32
11349 DEPENDS = initscripts kern-tools-native update-rc.d-native \
11350 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
11351 virtual/libc virtual/update-alternatives
11352 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
11353 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
11354 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
11355 </literallayout>
11356 </para>
11357
11358 <para>
11359 Finally, for those recipes fetched from a version control
11360 system (e.g., Git), a file exists that lists source
11361 revisions that are specified in the recipe and lists
11362 the actual revisions used during the build.
11363 Listed and actual revisions might differ when
11364 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
11365 is set to
11366 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
11367 Here is an example assuming
11368 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
11369 <literallayout class='monospaced'>
11370 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11371 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11372 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11373 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11374 </literallayout>
11375 You can use the
11376 <filename>buildhistory-collect-srcrevs</filename>
11377 command with the <filename>-a</filename> option to
11378 collect the stored <filename>SRCREV</filename> values
11379 from build history and report them in a format suitable for
11380 use in global configuration (e.g.,
11381 <filename>local.conf</filename> or a distro include file)
11382 to override floating <filename>AUTOREV</filename> values
11383 to a fixed set of revisions.
11384 Here is some example output from this command:
11385 <literallayout class='monospaced'>
11386 $ buildhistory-collect-srcrevs -a
11387 # i586-poky-linux
11388 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
11389 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
11390 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
11391 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11392 # x86_64-linux
11393 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
11394 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
11395 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
11396 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
11397 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
11398 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
11399 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
11400 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
11401 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11402 # qemux86-poky-linux
11403 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11404 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
11405 # all-poky-linux
11406 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
11407 </literallayout>
11408 <note>
11409 Here are some notes on using the
11410 <filename>buildhistory-collect-srcrevs</filename>
11411 command:
11412 <itemizedlist>
11413 <listitem><para>
11414 By default, only values where the
11415 <filename>SRCREV</filename> was not hardcoded
11416 (usually when <filename>AUTOREV</filename>
11417 is used) are reported.
11418 Use the <filename>-a</filename> option to
11419 see all <filename>SRCREV</filename> values.
11420 </para></listitem>
11421 <listitem><para>
11422 The output statements might not have any effect
11423 if overrides are applied elsewhere in the
11424 build system configuration.
11425 Use the <filename>-f</filename> option to add
11426 the <filename>forcevariable</filename> override
11427 to each output line if you need to work around
11428 this restriction.
11429 </para></listitem>
11430 <listitem><para>
11431 The script does apply special handling when
11432 building for multiple machines.
11433 However, the script does place a comment before
11434 each set of values that specifies which
11435 triplet to which they belong as previously
11436 shown (e.g.,
11437 <filename>i586-poky-linux</filename>).
11438 </para></listitem>
11439 </itemizedlist>
11440 </note>
11441 </para>
11442 </section>
11443
11444 <section id='build-history-image-information'>
11445 <title>Build History Image Information</title>
11446
11447 <para>
11448 The files produced for each image are as follows:
11449 <itemizedlist>
11450 <listitem><para>
11451 <filename>image-files:</filename>
11452 A directory containing selected files from the root
11453 filesystem.
11454 The files are defined by
11455 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
11456 </para></listitem>
11457 <listitem><para>
11458 <filename>build-id.txt:</filename>
11459 Human-readable information about the build
11460 configuration and metadata source revisions.
11461 This file contains the full build header as printed
11462 by BitBake.
11463 </para></listitem>
11464 <listitem><para>
11465 <filename>*.dot:</filename>
11466 Dependency graphs for the image that are
11467 compatible with <filename>graphviz</filename>.
11468 </para></listitem>
11469 <listitem><para>
11470 <filename>files-in-image.txt:</filename>
11471 A list of files in the image with permissions,
11472 owner, group, size, and symlink information.
11473 </para></listitem>
11474 <listitem><para>
11475 <filename>image-info.txt:</filename>
11476 A text file containing name-value pairs with
11477 information about the image.
11478 See the following listing example for more
11479 information.
11480 </para></listitem>
11481 <listitem><para>
11482 <filename>installed-package-names.txt:</filename>
11483 A list of installed packages by name only.
11484 </para></listitem>
11485 <listitem><para>
11486 <filename>installed-package-sizes.txt:</filename>
11487 A list of installed packages ordered by size.
11488 </para></listitem>
11489 <listitem><para>
11490 <filename>installed-packages.txt:</filename>
11491 A list of installed packages with full package
11492 filenames.
11493 </para></listitem>
11494 </itemizedlist>
11495 <note>
11496 Installed package information is able to be gathered
11497 and produced even if package management is disabled
11498 for the final image.
11499 </note>
11500 </para>
11501
11502 <para>
11503 Here is an example of <filename>image-info.txt</filename>:
11504 <literallayout class='monospaced'>
11505 DISTRO = poky
11506 DISTRO_VERSION = 1.7
11507 USER_CLASSES = buildstats image-mklibs image-prelink
11508 IMAGE_CLASSES = image_types
11509 IMAGE_FEATURES = debug-tweaks
11510 IMAGE_LINGUAS =
11511 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11512 BAD_RECOMMENDATIONS =
11513 NO_RECOMMENDATIONS =
11514 PACKAGE_EXCLUDE =
11515 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11516 write_image_manifest ; buildhistory_list_installed_image ; \
11517 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11518 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11519 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11520 IMAGESIZE = 6900
11521 </literallayout>
11522 Other than <filename>IMAGESIZE</filename>, which is the
11523 total size of the files in the image in Kbytes, the
11524 name-value pairs are variables that may have influenced the
11525 content of the image.
11526 This information is often useful when you are trying to
11527 determine why a change in the package or file
11528 listings has occurred.
11529 </para>
11530 </section>
11531
11532 <section id='using-build-history-to-gather-image-information-only'>
11533 <title>Using Build History to Gather Image Information Only</title>
11534
11535 <para>
11536 As you can see, build history produces image information,
11537 including dependency graphs, so you can see why something
11538 was pulled into the image.
11539 If you are just interested in this information and not
11540 interested in collecting specific package or SDK
11541 information, you can enable writing only image information
11542 without any history by adding the following to your
11543 <filename>conf/local.conf</filename> file found in the
11544 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11545 <literallayout class='monospaced'>
11546 INHERIT += "buildhistory"
11547 BUILDHISTORY_COMMIT = "0"
11548 BUILDHISTORY_FEATURES = "image"
11549 </literallayout>
11550 Here, you set the
11551 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11552 variable to use the image feature only.
11553 </para>
11554 </section>
11555
11556 <section id='build-history-sdk-information'>
11557 <title>Build History SDK Information</title>
11558
11559 <para>
11560 Build history collects similar information on the contents
11561 of SDKs
11562 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11563 as compared to information it collects for images.
11564 Furthermore, this information differs depending on whether
11565 an extensible or standard SDK is being produced.
11566 </para>
11567
11568 <para>
11569 The following list shows the files produced for SDKs:
11570 <itemizedlist>
11571 <listitem><para>
11572 <filename>files-in-sdk.txt:</filename>
11573 A list of files in the SDK with permissions,
11574 owner, group, size, and symlink information.
11575 This list includes both the host and target parts
11576 of the SDK.
11577 </para></listitem>
11578 <listitem><para>
11579 <filename>sdk-info.txt:</filename>
11580 A text file containing name-value pairs with
11581 information about the SDK.
11582 See the following listing example for more
11583 information.
11584 </para></listitem>
11585 <listitem><para>
11586 <filename>sstate-task-sizes.txt:</filename>
11587 A text file containing name-value pairs with
11588 information about task group sizes
11589 (e.g. <filename>do_populate_sysroot</filename>
11590 tasks have a total size).
11591 The <filename>sstate-task-sizes.txt</filename> file
11592 exists only when an extensible SDK is created.
11593 </para></listitem>
11594 <listitem><para>
11595 <filename>sstate-package-sizes.txt:</filename>
11596 A text file containing name-value pairs with
11597 information for the shared-state packages and
11598 sizes in the SDK.
11599 The <filename>sstate-package-sizes.txt</filename>
11600 file exists only when an extensible SDK is created.
11601 </para></listitem>
11602 <listitem><para>
11603 <filename>sdk-files:</filename>
11604 A folder that contains copies of the files
11605 mentioned in
11606 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11607 files are present in the output.
11608 Additionally, the default value of
11609 <filename>BUILDHISTORY_SDK_FILES</filename> is
11610 specific to the extensible SDK although you can
11611 set it differently if you would like to pull in
11612 specific files from the standard SDK.</para>
11613
11614 <para>The default files are
11615 <filename>conf/local.conf</filename>,
11616 <filename>conf/bblayers.conf</filename>,
11617 <filename>conf/auto.conf</filename>,
11618 <filename>conf/locked-sigs.inc</filename>, and
11619 <filename>conf/devtool.conf</filename>.
11620 Thus, for an extensible SDK, these files get
11621 copied into the <filename>sdk-files</filename>
11622 directory.
11623 </para></listitem>
11624 <listitem><para>
11625 The following information appears under
11626 each of the <filename>host</filename>
11627 and <filename>target</filename> directories
11628 for the portions of the SDK that run on the host
11629 and on the target, respectively:
11630 <note>
11631 The following files for the most part are empty
11632 when producing an extensible SDK because this
11633 type of SDK is not constructed from packages
11634 as is the standard SDK.
11635 </note>
11636 <itemizedlist>
11637 <listitem><para>
11638 <filename>depends.dot:</filename>
11639 Dependency graph for the SDK that is
11640 compatible with
11641 <filename>graphviz</filename>.
11642 </para></listitem>
11643 <listitem><para>
11644 <filename>installed-package-names.txt:</filename>
11645 A list of installed packages by name only.
11646 </para></listitem>
11647 <listitem><para>
11648 <filename>installed-package-sizes.txt:</filename>
11649 A list of installed packages ordered by size.
11650 </para></listitem>
11651 <listitem><para>
11652 <filename>installed-packages.txt:</filename>
11653 A list of installed packages with full
11654 package filenames.
11655 </para></listitem>
11656 </itemizedlist>
11657 </para></listitem>
11658 </itemizedlist>
11659 </para>
11660
11661 <para>
11662 Here is an example of <filename>sdk-info.txt</filename>:
11663 <literallayout class='monospaced'>
11664 DISTRO = poky
11665 DISTRO_VERSION = 1.3+snapshot-20130327
11666 SDK_NAME = poky-glibc-i686-arm
11667 SDK_VERSION = 1.3+snapshot
11668 SDKMACHINE =
11669 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11670 BAD_RECOMMENDATIONS =
11671 SDKSIZE = 352712
11672 </literallayout>
11673 Other than <filename>SDKSIZE</filename>, which is the
11674 total size of the files in the SDK in Kbytes, the
11675 name-value pairs are variables that might have influenced
11676 the content of the SDK.
11677 This information is often useful when you are trying to
11678 determine why a change in the package or file listings
11679 has occurred.
11680 </para>
11681 </section>
11682
11683 <section id='examining-build-history-information'>
11684 <title>Examining Build History Information</title>
11685
11686 <para>
11687 You can examine build history output from the command
11688 line or from a web interface.
11689 </para>
11690
11691 <para>
11692 To see any changes that have occurred (assuming you have
11693 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11694 you can simply use any Git command that allows you to
11695 view the history of a repository.
11696 Here is one method:
11697 <literallayout class='monospaced'>
11698 $ git log -p
11699 </literallayout>
11700 You need to realize, however, that this method does show
11701 changes that are not significant (e.g. a package's size
11702 changing by a few bytes).
11703 </para>
11704
11705 <para>
11706 A command-line tool called
11707 <filename>buildhistory-diff</filename> does exist, though,
11708 that queries the Git repository and prints just the
11709 differences that might be significant in human-readable
11710 form.
11711 Here is an example:
11712 <literallayout class='monospaced'>
11713 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11714 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11715 /etc/anotherpkg.conf was added
11716 /sbin/anotherpkg was added
11717 * (installed-package-names.txt):
11718 * anotherpkg was added
11719 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11720 anotherpkg was added
11721 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11722 * PR changed from "r0" to "r1"
11723 * PV changed from "0.1.10" to "0.1.12"
11724 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11725 * PR changed from "r0" to "r1"
11726 * PV changed from "0.1.10" to "0.1.12"
11727 </literallayout>
11728 <note>
11729 The <filename>buildhistory-diff</filename> tool
11730 requires the <filename>GitPython</filename> package.
11731 Be sure to install it using Pip3 as follows:
11732 <literallayout class='monospaced'>
11733 $ pip3 install GitPython --user
11734 </literallayout>
11735 Alternatively, you can install
11736 <filename>python3-git</filename> using the appropriate
11737 distribution package manager (e.g.
11738 <filename>apt-get</filename>, <filename>dnf</filename>,
11739 or <filename>zipper</filename>).
11740 </note>
11741 </para>
11742
11743 <para>
11744 To see changes to the build history using a web interface,
11745 follow the instruction in the <filename>README</filename>
11746 file here.
11747 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11748 </para>
11749
11750 <para>
11751 Here is a sample screenshot of the interface:
11752 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11753 </para>
11754 </section>
11755 </section>
11756 </section>
11757
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011758 <section id="performing-automated-runtime-testing">
11759 <title>Performing Automated Runtime Testing</title>
11760
11761 <para>
11762 The OpenEmbedded build system makes available a series of automated
11763 tests for images to verify runtime functionality.
11764 You can run these tests on either QEMU or actual target hardware.
11765 Tests are written in Python making use of the
11766 <filename>unittest</filename> module, and the majority of them
11767 run commands on the target system over SSH.
11768 This section describes how you set up the environment to use these
11769 tests, run available tests, and write and add your own tests.
11770 </para>
11771
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011772 <para>
11773 For information on the test and QA infrastructure available
11774 within the Yocto Project, see the
11775 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11776 section in the Yocto Project Reference Manual.
11777 </para>
11778
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011779 <section id='enabling-tests'>
11780 <title>Enabling Tests</title>
11781
11782 <para>
11783 Depending on whether you are planning to run tests using
11784 QEMU or on the hardware, you have to take
11785 different steps to enable the tests.
11786 See the following subsections for information on how to
11787 enable both types of tests.
11788 </para>
11789
11790 <section id='qemu-image-enabling-tests'>
11791 <title>Enabling Runtime Tests on QEMU</title>
11792
11793 <para>
11794 In order to run tests, you need to do the following:
11795 <itemizedlist>
11796 <listitem><para><emphasis>Set up to avoid interaction
11797 with <filename>sudo</filename> for networking:</emphasis>
11798 To accomplish this, you must do one of the
11799 following:
11800 <itemizedlist>
11801 <listitem><para>Add
11802 <filename>NOPASSWD</filename> for your user
11803 in <filename>/etc/sudoers</filename> either for
11804 all commands or just for
11805 <filename>runqemu-ifup</filename>.
11806 You must provide the full path as that can
11807 change if you are using multiple clones of the
11808 source repository.
11809 <note>
11810 On some distributions, you also need to
11811 comment out "Defaults requiretty" in
11812 <filename>/etc/sudoers</filename>.
11813 </note></para></listitem>
11814 <listitem><para>Manually configure a tap interface
11815 for your system.</para></listitem>
11816 <listitem><para>Run as root the script in
11817 <filename>scripts/runqemu-gen-tapdevs</filename>,
11818 which should generate a list of tap devices.
11819 This is the option typically chosen for
11820 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011821 <note><title>Notes</title>
11822 <itemizedlist>
11823 <listitem><para>
11824 Be sure to use an absolute path
11825 when calling this script
11826 with sudo.
11827 </para></listitem>
11828 <listitem><para>
11829 The package recipe
11830 <filename>qemu-helper-native</filename>
11831 is required to run this script.
11832 Build the package using the
11833 following command:
11834 <literallayout class='monospaced'>
11835 $ bitbake qemu-helper-native
11836 </literallayout>
11837 </para></listitem>
11838 </itemizedlist>
11839 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011840 </para></listitem>
11841 </itemizedlist></para></listitem>
11842 <listitem><para><emphasis>Set the
11843 <filename>DISPLAY</filename> variable:</emphasis>
11844 You need to set this variable so that you have an X
11845 server available (e.g. start
11846 <filename>vncserver</filename> for a headless machine).
11847 </para></listitem>
11848 <listitem><para><emphasis>Be sure your host's firewall
11849 accepts incoming connections from
11850 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011851 Some of the tests (in particular DNF tests) start
11852 an HTTP server on a random high number port,
11853 which is used to serve files to the target.
11854 The DNF module serves
11855 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11856 so it can run DNF channel commands.
11857 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011858 must accept incoming connections from 192.168.7.0/24,
11859 which is the default IP range used for tap devices
11860 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011861 <listitem><para><emphasis>Be sure your host has the
11862 correct packages installed:</emphasis>
11863 Depending your host's distribution, you need
11864 to have the following packages installed:
11865 <itemizedlist>
11866 <listitem><para>Ubuntu and Debian:
11867 <filename>sysstat</filename> and
11868 <filename>iproute2</filename>
11869 </para></listitem>
11870 <listitem><para>OpenSUSE:
11871 <filename>sysstat</filename> and
11872 <filename>iproute2</filename>
11873 </para></listitem>
11874 <listitem><para>Fedora:
11875 <filename>sysstat</filename> and
11876 <filename>iproute</filename>
11877 </para></listitem>
11878 <listitem><para>CentOS:
11879 <filename>sysstat</filename> and
11880 <filename>iproute</filename>
11881 </para></listitem>
11882 </itemizedlist>
11883 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011884 </itemizedlist>
11885 </para>
11886
11887 <para>
11888 Once you start running the tests, the following happens:
11889 <orderedlist>
11890 <listitem><para>A copy of the root filesystem is written
11891 to <filename>${WORKDIR}/testimage</filename>.
11892 </para></listitem>
11893 <listitem><para>The image is booted under QEMU using the
11894 standard <filename>runqemu</filename> script.
11895 </para></listitem>
11896 <listitem><para>A default timeout of 500 seconds occurs
11897 to allow for the boot process to reach the login prompt.
11898 You can change the timeout period by setting
11899 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11900 in the <filename>local.conf</filename> file.
11901 </para></listitem>
11902 <listitem><para>Once the boot process is reached and the
11903 login prompt appears, the tests run.
11904 The full boot log is written to
11905 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11906 </para></listitem>
11907 <listitem><para>Each test module loads in the order found
11908 in <filename>TEST_SUITES</filename>.
11909 You can find the full output of the commands run over
11910 SSH in
11911 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11912 </para></listitem>
11913 <listitem><para>If no failures occur, the task running the
11914 tests ends successfully.
11915 You can find the output from the
11916 <filename>unittest</filename> in the task log at
11917 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11918 </para></listitem>
11919 </orderedlist>
11920 </para>
11921 </section>
11922
11923 <section id='hardware-image-enabling-tests'>
11924 <title>Enabling Runtime Tests on Hardware</title>
11925
11926 <para>
11927 The OpenEmbedded build system can run tests on real
11928 hardware, and for certain devices it can also deploy
11929 the image to be tested onto the device beforehand.
11930 </para>
11931
11932 <para>
11933 For automated deployment, a "master image" is installed
11934 onto the hardware once as part of setup.
11935 Then, each time tests are to be run, the following
11936 occurs:
11937 <orderedlist>
11938 <listitem><para>The master image is booted into and
11939 used to write the image to be tested to
11940 a second partition.
11941 </para></listitem>
11942 <listitem><para>The device is then rebooted using an
11943 external script that you need to provide.
11944 </para></listitem>
11945 <listitem><para>The device boots into the image to be
11946 tested.
11947 </para></listitem>
11948 </orderedlist>
11949 </para>
11950
11951 <para>
11952 When running tests (independent of whether the image
11953 has been deployed automatically or not), the device is
11954 expected to be connected to a network on a
11955 pre-determined IP address.
11956 You can either use static IP addresses written into
11957 the image, or set the image to use DHCP and have your
11958 DHCP server on the test network assign a known IP address
11959 based on the MAC address of the device.
11960 </para>
11961
11962 <para>
11963 In order to run tests on hardware, you need to set
11964 <filename>TEST_TARGET</filename> to an appropriate value.
11965 For QEMU, you do not have to change anything, the default
11966 value is "QemuTarget".
11967 For running tests on hardware, the following options exist:
11968 <itemizedlist>
11969 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11970 Choose "SimpleRemoteTarget" if you are going to
11971 run tests on a target system that is already
11972 running the image to be tested and is available
11973 on the network.
11974 You can use "SimpleRemoteTarget" in conjunction
11975 with either real hardware or an image running
11976 within a separately started QEMU or any
11977 other virtual machine manager.
11978 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011979 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
11980 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011981 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011982 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011983 <filename>core-image-testmaster</filename>
11984 (or something similar) is installed.
11985 Also, your hardware under test must be in a
11986 DHCP-enabled network that gives it the same IP
11987 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011988 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011989 additional requirements and considerations.
11990 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011991 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011992 section, which follows, for more information.
11993 </para></listitem>
11994 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
11995 Choose "BeagleBoneTarget" if you are deploying
11996 images and running tests on the BeagleBone
11997 "Black" or original "White" hardware.
11998 For information on how to use these tests, see the
11999 comments at the top of the BeagleBoneTarget
12000 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
12001 file.
12002 </para></listitem>
12003 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
12004 Choose "EdgeRouterTarget" is you are deploying
12005 images and running tests on the Ubiquiti Networks
12006 EdgeRouter Lite.
12007 For information on how to use these tests, see the
12008 comments at the top of the EdgeRouterTarget
12009 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
12010 file.
12011 </para></listitem>
12012 <listitem><para><emphasis>"GrubTarget":</emphasis>
12013 Choose the "supports deploying images and running
12014 tests on any generic PC that boots using GRUB.
12015 For information on how to use these tests, see the
12016 comments at the top of the GrubTarget
12017 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
12018 file.
12019 </para></listitem>
12020 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
12021 Create your own custom target if you want to run
12022 tests when you are deploying images and running
12023 tests on a custom machine within your BSP layer.
12024 To do this, you need to add a Python unit that
12025 defines the target class under
12026 <filename>lib/oeqa/controllers/</filename> within
12027 your layer.
12028 You must also provide an empty
12029 <filename>__init__.py</filename>.
12030 For examples, see files in
12031 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
12032 </para></listitem>
12033 </itemizedlist>
12034 </para>
12035 </section>
12036
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012037 <section id='selecting-systemdboottarget'>
12038 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012039
12040 <para>
12041 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012042 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012043 in this section.
12044 You can skip down to the
12045 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
12046 section.
12047 </para>
12048
12049 <para>
12050 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012051 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012052 setup of your master image by doing the following:
12053 <orderedlist>
12054 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
12055 Be sure that <filename>EFI_PROVIDER</filename>
12056 is as follows:
12057 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012058 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012059 </literallayout>
12060 </para></listitem>
12061 <listitem><para><emphasis>Build the master image:</emphasis>
12062 Build the <filename>core-image-testmaster</filename>
12063 image.
12064 The <filename>core-image-testmaster</filename>
12065 recipe is provided as an example for a
12066 "master" image and you can customize the image
12067 recipe as you would any other recipe.
12068 </para>
12069 <para>Here are the image recipe requirements:
12070 <itemizedlist>
12071 <listitem><para>Inherits
12072 <filename>core-image</filename>
12073 so that kernel modules are installed.
12074 </para></listitem>
12075 <listitem><para>Installs normal linux utilities
12076 not busybox ones (e.g.
12077 <filename>bash</filename>,
12078 <filename>coreutils</filename>,
12079 <filename>tar</filename>,
12080 <filename>gzip</filename>, and
12081 <filename>kmod</filename>).
12082 </para></listitem>
12083 <listitem><para>Uses a custom
12084 Initial RAM Disk (initramfs) image with a
12085 custom installer.
12086 A normal image that you can install usually
12087 creates a single rootfs partition.
12088 This image uses another installer that
12089 creates a specific partition layout.
12090 Not all Board Support Packages (BSPs)
12091 can use an installer.
12092 For such cases, you need to manually create
12093 the following partition layout on the
12094 target:
12095 <itemizedlist>
12096 <listitem><para>First partition mounted
12097 under <filename>/boot</filename>,
12098 labeled "boot".
12099 </para></listitem>
12100 <listitem><para>The main rootfs
12101 partition where this image gets
12102 installed, which is mounted under
12103 <filename>/</filename>.
12104 </para></listitem>
12105 <listitem><para>Another partition
12106 labeled "testrootfs" where test
12107 images get deployed.
12108 </para></listitem>
12109 </itemizedlist>
12110 </para></listitem>
12111 </itemizedlist>
12112 </para></listitem>
12113 <listitem><para><emphasis>Install image:</emphasis>
12114 Install the image that you just built on the target
12115 system.
12116 </para></listitem>
12117 </orderedlist>
12118 </para>
12119
12120 <para>
12121 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012122 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012123 to set up the test image:
12124 <orderedlist>
12125 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
12126 Make sure you have the following statements in
12127 your <filename>local.conf</filename> file:
12128 <literallayout class='monospaced'>
12129 IMAGE_FSTYPES += "tar.gz"
12130 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012131 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012132 TEST_TARGET_IP = "192.168.2.3"
12133 </literallayout>
12134 </para></listitem>
12135 <listitem><para><emphasis>Build your test image:</emphasis>
12136 Use BitBake to build the image:
12137 <literallayout class='monospaced'>
12138 $ bitbake core-image-sato
12139 </literallayout>
12140 </para></listitem>
12141 </orderedlist>
12142 </para>
12143 </section>
12144
12145 <section id='power-control'>
12146 <title>Power Control</title>
12147
12148 <para>
12149 For most hardware targets other than SimpleRemoteTarget,
12150 you can control power:
12151 <itemizedlist>
12152 <listitem><para>
12153 You can use
12154 <filename>TEST_POWERCONTROL_CMD</filename>
12155 together with
12156 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12157 as a command that runs on the host and does power
12158 cycling.
12159 The test code passes one argument to that command:
12160 off, on or cycle (off then on).
12161 Here is an example that could appear in your
12162 <filename>local.conf</filename> file:
12163 <literallayout class='monospaced'>
12164 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
12165 </literallayout>
12166 In this example, the expect script does the
12167 following:
12168 <literallayout class='monospaced'>
12169 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
12170 </literallayout>
12171 It then runs a Python script that controls power
12172 for a label called <filename>nuc1</filename>.
12173 <note>
12174 You need to customize
12175 <filename>TEST_POWERCONTROL_CMD</filename>
12176 and
12177 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12178 for your own setup.
12179 The one requirement is that it accepts
12180 "on", "off", and "cycle" as the last argument.
12181 </note>
12182 </para></listitem>
12183 <listitem><para>
12184 When no command is defined, it connects to the
12185 device over SSH and uses the classic reboot command
12186 to reboot the device.
12187 Classic reboot is fine as long as the machine
12188 actually reboots (i.e. the SSH test has not
12189 failed).
12190 It is useful for scenarios where you have a simple
12191 setup, typically with a single board, and where
12192 some manual interaction is okay from time to time.
12193 </para></listitem>
12194 </itemizedlist>
12195 If you have no hardware to automatically perform power
12196 control but still wish to experiment with automated
12197 hardware testing, you can use the dialog-power-control
12198 script that shows a dialog prompting you to perform the
12199 required power action.
12200 This script requires either KDialog or Zenity to be
12201 installed.
12202 To use this script, set the
12203 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
12204 variable as follows:
12205 <literallayout class='monospaced'>
12206 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
12207 </literallayout>
12208 </para>
12209 </section>
12210
12211 <section id='serial-console-connection'>
12212 <title>Serial Console Connection</title>
12213
12214 <para>
12215 For test target classes requiring a serial console
12216 to interact with the bootloader (e.g. BeagleBoneTarget,
12217 EdgeRouterTarget, and GrubTarget), you need to
12218 specify a command to use to connect to the serial console
12219 of the target machine by using the
12220 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
12221 variable and optionally the
12222 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
12223 variable.
12224 </para>
12225
12226 <para>
12227 These cases could be a serial terminal program if the
12228 machine is connected to a local serial port, or a
12229 <filename>telnet</filename> or
12230 <filename>ssh</filename> command connecting to a remote
12231 console server.
12232 Regardless of the case, the command simply needs to
12233 connect to the serial console and forward that connection
12234 to standard input and output as any normal terminal
12235 program does.
12236 For example, to use the picocom terminal program on
12237 serial device <filename>/dev/ttyUSB0</filename>
12238 at 115200bps, you would set the variable as follows:
12239 <literallayout class='monospaced'>
12240 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
12241 </literallayout>
12242 For local devices where the serial port device disappears
12243 when the device reboots, an additional "serdevtry" wrapper
12244 script is provided.
12245 To use this wrapper, simply prefix the terminal command
12246 with
12247 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
12248 <literallayout class='monospaced'>
12249 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
12250115200 /dev/ttyUSB0"
12251 </literallayout>
12252 </para>
12253 </section>
12254 </section>
12255
12256 <section id="qemu-image-running-tests">
12257 <title>Running Tests</title>
12258
12259 <para>
12260 You can start the tests automatically or manually:
12261 <itemizedlist>
12262 <listitem><para><emphasis>Automatically running tests:</emphasis>
12263 To run the tests automatically after the
12264 OpenEmbedded build system successfully creates an image,
12265 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012266 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012267 variable to "1" in your <filename>local.conf</filename>
12268 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012269 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012270 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012271 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012272 </literallayout>
12273 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012274 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012275 <literallayout class='monospaced'>
12276 bitbake core-image-sato
12277 </literallayout></para></listitem>
12278 <listitem><para><emphasis>Manually running tests:</emphasis>
12279 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012280 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012281 class by editing your <filename>local.conf</filename>
12282 file:
12283 <literallayout class='monospaced'>
12284 INHERIT += "testimage"
12285 </literallayout>
12286 Next, use BitBake to run the tests:
12287 <literallayout class='monospaced'>
12288 bitbake -c testimage <replaceable>image</replaceable>
12289 </literallayout></para></listitem>
12290 </itemizedlist>
12291 </para>
12292
12293 <para>
12294 All test files reside in
12295 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012296 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012297 A test name maps directly to a Python module.
12298 Each test module may contain a number of individual tests.
12299 Tests are usually grouped together by the area
12300 tested (e.g tests for systemd reside in
12301 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
12302 </para>
12303
12304 <para>
12305 You can add tests to any layer provided you place them in the
12306 proper area and you extend
12307 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12308 in the <filename>local.conf</filename> file as normal.
12309 Be sure that tests reside in
12310 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
12311 <note>
12312 Be sure that module names do not collide with module names
12313 used in the default set of test modules in
12314 <filename>meta/lib/oeqa/runtime</filename>.
12315 </note>
12316 </para>
12317
12318 <para>
12319 You can change the set of tests run by appending or overriding
12320 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
12321 variable in <filename>local.conf</filename>.
12322 Each name in <filename>TEST_SUITES</filename> represents a
12323 required test for the image.
12324 Test modules named within <filename>TEST_SUITES</filename>
12325 cannot be skipped even if a test is not suitable for an image
12326 (e.g. running the RPM tests on an image without
12327 <filename>rpm</filename>).
12328 Appending "auto" to <filename>TEST_SUITES</filename> causes the
12329 build system to try to run all tests that are suitable for the
12330 image (i.e. each test module may elect to skip itself).
12331 </para>
12332
12333 <para>
12334 The order you list tests in <filename>TEST_SUITES</filename>
12335 is important and influences test dependencies.
12336 Consequently, tests that depend on other tests should be added
12337 after the test on which they depend.
12338 For example, since the <filename>ssh</filename> test
12339 depends on the
12340 <filename>ping</filename> test, "ssh" needs to come after
12341 "ping" in the list.
12342 The test class provides no re-ordering or dependency handling.
12343 <note>
12344 Each module can have multiple classes with multiple test
12345 methods.
12346 And, Python <filename>unittest</filename> rules apply.
12347 </note>
12348 </para>
12349
12350 <para>
12351 Here are some things to keep in mind when running tests:
12352 <itemizedlist>
12353 <listitem><para>The default tests for the image are defined
12354 as:
12355 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012356 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 -050012357 </literallayout></para></listitem>
12358 <listitem><para>Add your own test to the list of the
12359 by using the following:
12360 <literallayout class='monospaced'>
12361 TEST_SUITES_append = " mytest"
12362 </literallayout></para></listitem>
12363 <listitem><para>Run a specific list of tests as follows:
12364 <literallayout class='monospaced'>
12365 TEST_SUITES = "test1 test2 test3"
12366 </literallayout>
12367 Remember, order is important.
12368 Be sure to place a test that is dependent on another test
12369 later in the order.</para></listitem>
12370 </itemizedlist>
12371 </para>
12372 </section>
12373
12374 <section id="exporting-tests">
12375 <title>Exporting Tests</title>
12376
12377 <para>
12378 You can export tests so that they can run independently of
12379 the build system.
12380 Exporting tests is required if you want to be able to hand
12381 the test execution off to a scheduler.
12382 You can only export tests that are defined in
12383 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
12384 </para>
12385
12386 <para>
12387 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012388 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012389 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012390 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012391 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
12392 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012393 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012394 You can then export the tests with the following BitBake
12395 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012396 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012397 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012398 </literallayout>
12399 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012400 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12401 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012402 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
12403 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012404 <filename>TEST_EXPORT_DIR</filename> variable.
12405 </para>
12406
12407 <para>
12408 You can now run the tests outside of the build environment:
12409 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012410 $ cd tmp/testexport/<replaceable>image</replaceable>
12411 $ ./runexported.py testdata.json
12412 </literallayout>
12413 </para>
12414
12415 <para>
12416 Here is a complete example that shows IP addresses and uses
12417 the <filename>core-image-sato</filename> image:
12418 <literallayout class='monospaced'>
12419 INHERIT +="testexport"
12420 TEST_TARGET_IP = "192.168.7.2"
12421 TEST_SERVER_IP = "192.168.7.1"
12422 </literallayout>
12423 Use BitBake to export the tests:
12424 <literallayout class='monospaced'>
12425 $ bitbake core-image-sato -c testexport
12426 </literallayout>
12427 Run the tests outside of the build environment using the
12428 following:
12429 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012430 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012431 $ ./runexported.py testdata.json
12432 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012433 </para>
12434 </section>
12435
12436 <section id="qemu-image-writing-new-tests">
12437 <title>Writing New Tests</title>
12438
12439 <para>
12440 As mentioned previously, all new test files need to be in the
12441 proper place for the build system to find them.
12442 New tests for additional functionality outside of the core
12443 should be added to the layer that adds the functionality, in
12444 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
12445 (as long as
12446 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12447 is extended in the layer's
12448 <filename>layer.conf</filename> file as normal).
12449 Just remember the following:
12450 <itemizedlist>
12451 <listitem><para>Filenames need to map directly to test
12452 (module) names.
12453 </para></listitem>
12454 <listitem><para>Do not use module names that
12455 collide with existing core tests.
12456 </para></listitem>
12457 <listitem><para>Minimally, an empty
12458 <filename>__init__.py</filename> file must exist
12459 in the runtime directory.
12460 </para></listitem>
12461 </itemizedlist>
12462 </para>
12463
12464 <para>
12465 To create a new test, start by copying an existing module
12466 (e.g. <filename>syslog.py</filename> or
12467 <filename>gcc.py</filename> are good ones to use).
12468 Test modules can use code from
12469 <filename>meta/lib/oeqa/utils</filename>, which are helper
12470 classes.
12471 </para>
12472
12473 <note>
12474 Structure shell commands such that you rely on them and they
12475 return a single code for success.
12476 Be aware that sometimes you will need to parse the output.
12477 See the <filename>df.py</filename> and
12478 <filename>date.py</filename> modules for examples.
12479 </note>
12480
12481 <para>
12482 You will notice that all test classes inherit
12483 <filename>oeRuntimeTest</filename>, which is found in
12484 <filename>meta/lib/oetest.py</filename>.
12485 This base class offers some helper attributes, which are
12486 described in the following sections:
12487 </para>
12488
12489 <section id='qemu-image-writing-tests-class-methods'>
12490 <title>Class Methods</title>
12491
12492 <para>
12493 Class methods are as follows:
12494 <itemizedlist>
12495 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12496 Returns "True" if <filename>pkg</filename> is in the
12497 installed package list of the image, which is based
12498 on the manifest file that is generated during the
12499 <filename>do_rootfs</filename> task.
12500 </para></listitem>
12501 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12502 Returns "True" if the feature is in
12503 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12504 or
12505 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12506 </para></listitem>
12507 </itemizedlist>
12508 </para>
12509 </section>
12510
12511 <section id='qemu-image-writing-tests-class-attributes'>
12512 <title>Class Attributes</title>
12513
12514 <para>
12515 Class attributes are as follows:
12516 <itemizedlist>
12517 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12518 Equals "ps -ef" if <filename>procps</filename> is
12519 installed in the image.
12520 Otherwise, <filename>pscmd</filename> equals
12521 "ps" (busybox).
12522 </para></listitem>
12523 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12524 The called test context, which gives access to the
12525 following attributes:
12526 <itemizedlist>
12527 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12528 The BitBake datastore, which allows you to
12529 use stuff such as
12530 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12531 </para></listitem>
12532 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12533 Used internally.
12534 The tests do not need these.
12535 </para></listitem>
12536 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12537 The absolute path to
12538 <filename>meta/lib/oeqa/runtime/files</filename>,
12539 which contains helper files for tests meant
12540 for copying on the target such as small
12541 files written in C for compilation.
12542 </para></listitem>
12543 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12544 The target controller object used to deploy
12545 and start an image on a particular target
12546 (e.g. QemuTarget, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012547 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012548 Tests usually use the following:
12549 <itemizedlist>
12550 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12551 The target's IP address.
12552 </para></listitem>
12553 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12554 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012555 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012556 suite.
12557 </para></listitem>
12558 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12559 The single, most used method.
12560 This command is a wrapper for:
12561 <filename>ssh root@host "cmd"</filename>.
12562 The command returns a tuple:
12563 (status, output), which are what
12564 their names imply - the return code
12565 of "cmd" and whatever output
12566 it produces.
12567 The optional timeout argument
12568 represents the number of seconds the
12569 test should wait for "cmd" to
12570 return.
12571 If the argument is "None", the
12572 test uses the default instance's
12573 timeout period, which is 300
12574 seconds.
12575 If the argument is "0", the test
12576 runs until the command returns.
12577 </para></listitem>
12578 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12579 <filename>scp localpath root@ip:remotepath</filename>.
12580 </para></listitem>
12581 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12582 <filename>scp root@host:remotepath localpath</filename>.
12583 </para></listitem>
12584 </itemizedlist></para></listitem>
12585 </itemizedlist></para></listitem>
12586 </itemizedlist>
12587 </para>
12588 </section>
12589
12590 <section id='qemu-image-writing-tests-instance-attributes'>
12591 <title>Instance Attributes</title>
12592
12593 <para>
12594 A single instance attribute exists, which is
12595 <filename>target</filename>.
12596 The <filename>target</filename> instance attribute is
12597 identical to the class attribute of the same name, which
12598 is described in the previous section.
12599 This attribute exists as both an instance and class
12600 attribute so tests can use
12601 <filename>self.target.run(cmd)</filename> in instance
12602 methods instead of
12603 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12604 </para>
12605 </section>
12606 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012607
12608 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12609 <title>Installing Packages in the DUT Without the Package Manager</title>
12610
12611 <para>
12612 When a test requires a package built by BitBake, it is possible
12613 to install that package.
12614 Installing the package does not require a package manager be
12615 installed in the device under test (DUT).
12616 It does, however, require an SSH connection and the target must
12617 be using the <filename>sshcontrol</filename> class.
12618 <note>
12619 This method uses <filename>scp</filename> to copy files
12620 from the host to the target, which causes permissions and
12621 special attributes to be lost.
12622 </note>
12623 </para>
12624
12625 <para>
12626 A JSON file is used to define the packages needed by a test.
12627 This file must be in the same path as the file used to define
12628 the tests.
12629 Furthermore, the filename must map directly to the test
12630 module name with a <filename>.json</filename> extension.
12631 </para>
12632
12633 <para>
12634 The JSON file must include an object with the test name as
12635 keys of an object or an array.
12636 This object (or array of objects) uses the following data:
12637 <itemizedlist>
12638 <listitem><para>"pkg" - A mandatory string that is the
12639 name of the package to be installed.
12640 </para></listitem>
12641 <listitem><para>"rm" - An optional boolean, which defaults
12642 to "false", that specifies to remove the package after
12643 the test.
12644 </para></listitem>
12645 <listitem><para>"extract" - An optional boolean, which
12646 defaults to "false", that specifies if the package must
12647 be extracted from the package format.
12648 When set to "true", the package is not automatically
12649 installed into the DUT.
12650 </para></listitem>
12651 </itemizedlist>
12652 </para>
12653
12654 <para>
12655 Following is an example JSON file that handles test "foo"
12656 installing package "bar" and test "foobar" installing
12657 packages "foo" and "bar".
12658 Once the test is complete, the packages are removed from the
12659 DUT.
12660 <literallayout class='monospaced'>
12661 {
12662 "foo": {
12663 "pkg": "bar"
12664 },
12665 "foobar": [
12666 {
12667 "pkg": "foo",
12668 "rm": true
12669 },
12670 {
12671 "pkg": "bar",
12672 "rm": true
12673 }
12674 ]
12675 }
12676 </literallayout>
12677 </para>
12678 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012679 </section>
12680
Brad Bishop316dfdd2018-06-25 12:45:53 -040012681 <section id='usingpoky-debugging-tools-and-techniques'>
12682 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012683
12684 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012685 The exact method for debugging build failures depends on the nature
12686 of the problem and on the system's area from which the bug
12687 originates.
12688 Standard debugging practices such as comparison against the last
12689 known working version with examination of the changes and the
12690 re-application of steps to identify the one causing the problem are
12691 valid for the Yocto Project just as they are for any other system.
12692 Even though it is impossible to detail every possible potential
12693 failure, this section provides some general tips to aid in
12694 debugging given a variety of situations.
12695 <note><title>Tip</title>
12696 A useful feature for debugging is the error reporting tool.
12697 Configuring the Yocto Project to use this tool causes the
12698 OpenEmbedded build system to produce error reporting commands as
12699 part of the console output.
12700 You can enter the commands after the build completes to log
12701 error information into a common database, that can help you
12702 figure out what might be going wrong.
12703 For information on how to enable and use this feature, see the
12704 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12705 section.
12706 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012707 </para>
12708
12709 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012710 The following list shows the debugging topics in the remainder of
12711 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012712 <itemizedlist>
12713 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012714 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12715 describes how to find and view logs from tasks that
12716 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012717 </para></listitem>
12718 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012719 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12720 describes how to use the BitBake <filename>-e</filename>
12721 option to examine variable values after a recipe has been
12722 parsed.
12723 </para></listitem>
12724 <listitem><para>
12725 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12726 describes how to use the
12727 <filename>oe-pkgdata-util</filename> utility to query
12728 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12729 and display package-related information for built
12730 packages.
12731 </para></listitem>
12732 <listitem><para>
12733 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12734 describes how to use the BitBake <filename>-g</filename>
12735 option to display recipe dependency information used
12736 during the build.
12737 </para></listitem>
12738 <listitem><para>
12739 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12740 describes how to use the
12741 <filename>bitbake-dumpsig</filename> command in
12742 conjunction with key subdirectories in the
12743 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12744 to determine variable dependencies.
12745 </para></listitem>
12746 <listitem><para>
12747 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12748 describes how to use several BitBake options (e.g.
12749 <filename>-c</filename>, <filename>-C</filename>, and
12750 <filename>-f</filename>) to run specific tasks in the
12751 build chain.
12752 It can be useful to run tasks "out-of-order" when trying
12753 isolate build issues.
12754 </para></listitem>
12755 <listitem><para>
12756 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12757 describes how to use BitBake's <filename>-D</filename>
12758 debug output option to reveal more about what BitBake is
12759 doing during the build.
12760 </para></listitem>
12761 <listitem><para>
12762 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12763 describes how to use the BitBake <filename>-b</filename>
12764 option to build a recipe while ignoring dependencies.
12765 </para></listitem>
12766 <listitem><para>
12767 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12768 describes how to use the many recipe logging functions
12769 to produce debugging output and report errors and warnings.
12770 </para></listitem>
12771 <listitem><para>
12772 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12773 describes how to debug situations where the build consists
12774 of several parts that are run simultaneously and when the
12775 output or result of one part is not ready for use with a
12776 different part of the build that depends on that output.
12777 </para></listitem>
12778 <listitem><para>
12779 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12780 describes how to use GDB to allow you to examine running
12781 programs, which can help you fix problems.
12782 </para></listitem>
12783 <listitem><para>
12784 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12785 describes how to use GDB directly on target hardware for
12786 debugging.
12787 </para></listitem>
12788 <listitem><para>
12789 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12790 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012791 </para></listitem>
12792 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012793 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012794
Brad Bishop316dfdd2018-06-25 12:45:53 -040012795 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12796 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012797
12798 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012799 You can find the log for a task in the file
12800 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12801 For example, the log for the
12802 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12803 task of the QEMU minimal image for the x86 machine
12804 (<filename>qemux86</filename>) might be in
12805 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12806 To see the commands
12807 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12808 ran to generate a log, look at the corresponding
12809 <filename>run.do_</filename><replaceable>taskname</replaceable>
12810 file in the same directory.
12811 </para>
12812
12813 <para>
12814 <filename>log.do_</filename><replaceable>taskname</replaceable>
12815 and
12816 <filename>run.do_</filename><replaceable>taskname</replaceable>
12817 are actually symbolic links to
12818 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12819 and
12820 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12821 where <replaceable>pid</replaceable> is the PID the task had
12822 when it ran.
12823 The symlinks always point to the files corresponding to the most
12824 recent run.
12825 </para>
12826 </section>
12827
12828 <section id='dev-debugging-viewing-variable-values'>
12829 <title>Viewing Variable Values</title>
12830
12831 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040012832 Sometimes you need to know the value of a variable as a
12833 result of BitBake's parsing step.
12834 This could be because some unexpected behavior occurred
12835 in your project.
12836 Perhaps an attempt to
12837 <ulink url='&YOCTO_DOCS_BB_URL;#modifying-existing-variables'>modify a variable</ulink>
12838 did not work out as expected.
12839 </para>
12840
12841 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012842 BitBake's <filename>-e</filename> option is used to display
12843 variable values after parsing.
12844 The following command displays the variable values after the
12845 configuration files (i.e. <filename>local.conf</filename>,
12846 <filename>bblayers.conf</filename>,
12847 <filename>bitbake.conf</filename> and so forth) have been
12848 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012849 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012850 $ bitbake -e
12851 </literallayout>
12852 The following command displays variable values after a specific
12853 recipe has been parsed.
12854 The variables include those from the configuration as well:
12855 <literallayout class='monospaced'>
12856 $ bitbake -e recipename
12857 </literallayout>
12858 <note><para>
12859 Each recipe has its own private set of variables
12860 (datastore).
12861 Internally, after parsing the configuration, a copy of the
12862 resulting datastore is made prior to parsing each recipe.
12863 This copying implies that variables set in one recipe will
12864 not be visible to other recipes.</para>
12865
12866 <para>Likewise, each task within a recipe gets a private
12867 datastore based on the recipe datastore, which means that
12868 variables set within one task will not be visible to
12869 other tasks.</para>
12870 </note>
12871 </para>
12872
12873 <para>
12874 In the output of <filename>bitbake -e</filename>, each
12875 variable is preceded by a description of how the variable
12876 got its value, including temporary values that were later
12877 overriden.
12878 This description also includes variable flags (varflags) set on
12879 the variable.
12880 The output can be very helpful during debugging.
12881 </para>
12882
12883 <para>
12884 Variables that are exported to the environment are preceded by
12885 <filename>export</filename> in the output of
12886 <filename>bitbake -e</filename>.
12887 See the following example:
12888 <literallayout class='monospaced'>
12889 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12890 </literallayout>
12891 </para>
12892
12893 <para>
12894 In addition to variable values, the output of the
12895 <filename>bitbake -e</filename> and
12896 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12897 commands includes the following information:
12898 <itemizedlist>
12899 <listitem><para>
12900 The output starts with a tree listing all configuration
12901 files and classes included globally, recursively listing
12902 the files they include or inherit in turn.
12903 Much of the behavior of the OpenEmbedded build system
12904 (including the behavior of the
12905 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12906 is implemented in the
12907 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12908 class and the classes it inherits, rather than being
12909 built into BitBake itself.
12910 </para></listitem>
12911 <listitem><para>
12912 After the variable values, all functions appear in the
12913 output.
12914 For shell functions, variables referenced within the
12915 function body are expanded.
12916 If a function has been modified using overrides or
12917 using override-style operators like
12918 <filename>_append</filename> and
12919 <filename>_prepend</filename>, then the final assembled
12920 function body appears in the output.
12921 </para></listitem>
12922 </itemizedlist>
12923 </para>
12924 </section>
12925
12926 <section id='viewing-package-information-with-oe-pkgdata-util'>
12927 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12928
12929 <para>
12930 You can use the <filename>oe-pkgdata-util</filename>
12931 command-line utility to query
12932 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12933 and display various package-related information.
12934 When you use the utility, you must use it to view information
12935 on packages that have already been built.
12936 </para>
12937
12938 <para>
12939 Following are a few of the available
12940 <filename>oe-pkgdata-util</filename> subcommands.
12941 <note>
12942 You can use the standard * and ? globbing wildcards as part
12943 of package names and paths.
12944 </note>
12945 <itemizedlist>
12946 <listitem><para>
12947 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12948 Lists all packages that have been built, optionally
12949 limiting the match to packages that match
12950 <replaceable>pattern</replaceable>.
12951 </para></listitem>
12952 <listitem><para>
12953 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12954 Lists the files and directories contained in the given
12955 packages.
12956 <note>
12957 <para>
12958 A different way to view the contents of a package is
12959 to look at the
12960 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12961 directory of the recipe that generates the
12962 package.
12963 This directory is created by the
12964 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12965 task and has one subdirectory for each package the
12966 recipe generates, which contains the files stored in
12967 that package.</para>
12968 <para>
12969 If you want to inspect the
12970 <filename>${WORKDIR}/packages-split</filename>
12971 directory, make sure that
12972 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12973 is not enabled when you build the recipe.
12974 </para>
12975 </note>
12976 </para></listitem>
12977 <listitem><para>
12978 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12979 Lists the names of the packages that contain the given
12980 paths.
12981 For example, the following tells us that
12982 <filename>/usr/share/man/man1/make.1</filename>
12983 is contained in the <filename>make-doc</filename>
12984 package:
12985 <literallayout class='monospaced'>
12986 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12987 make-doc: /usr/share/man/man1/make.1
12988 </literallayout>
12989 </para></listitem>
12990 <listitem><para>
12991 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12992 Lists the name of the recipes that
12993 produce the given packages.
12994 </para></listitem>
12995 </itemizedlist>
12996 </para>
12997
12998 <para>
12999 For more information on the <filename>oe-pkgdata-util</filename>
13000 command, use the help facility:
13001 <literallayout class='monospaced'>
13002 $ oe-pkgdata-util &dash;&dash;help
13003 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
13004 </literallayout>
13005 </para>
13006 </section>
13007
13008 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
13009 <title>Viewing Dependencies Between Recipes and Tasks</title>
13010
13011 <para>
13012 Sometimes it can be hard to see why BitBake wants to build other
13013 recipes before the one you have specified.
13014 Dependency information can help you understand why a recipe is
13015 built.
13016 </para>
13017
13018 <para>
13019 To generate dependency information for a recipe, run the
13020 following command:
13021 <literallayout class='monospaced'>
13022 $ bitbake -g <replaceable>recipename</replaceable>
13023 </literallayout>
13024 This command writes the following files in the current
13025 directory:
13026 <itemizedlist>
13027 <listitem><para>
13028 <filename>pn-buildlist</filename>: A list of
13029 recipes/targets involved in building
13030 <replaceable>recipename</replaceable>.
13031 "Involved" here means that at least one task from the
13032 recipe needs to run when building
13033 <replaceable>recipename</replaceable> from scratch.
13034 Targets that are in
13035 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
13036 are not listed.
13037 </para></listitem>
13038 <listitem><para>
13039 <filename>task-depends.dot</filename>: A graph showing
13040 dependencies between tasks.
13041 </para></listitem>
13042 </itemizedlist>
13043 </para>
13044
13045 <para>
13046 The graphs are in
13047 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
13048 format and can be converted to images (e.g. using the
13049 <filename>dot</filename> tool from
13050 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
13051 <note><title>Notes</title>
13052 <itemizedlist>
13053 <listitem><para>
13054 DOT files use a plain text format.
13055 The graphs generated using the
13056 <filename>bitbake -g</filename> command are often so
13057 large as to be difficult to read without special
13058 pruning (e.g. with Bitbake's
13059 <filename>-I</filename> option) and processing.
13060 Despite the form and size of the graphs, the
13061 corresponding <filename>.dot</filename> files can
13062 still be possible to read and provide useful
13063 information.
13064 </para>
13065
13066 <para>As an example, the
13067 <filename>task-depends.dot</filename> file contains
13068 lines such as the following:
13069 <literallayout class='monospaced'>
13070 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
13071 </literallayout>
13072 The above example line reveals that the
13073 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
13074 task in <filename>libxslt</filename> depends on the
13075 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
13076 task in <filename>libxml2</filename>, which is a
13077 normal
13078 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
13079 dependency between the two recipes.
13080 </para></listitem>
13081 <listitem><para>
13082 For an example of how <filename>.dot</filename>
13083 files can be processed, see the
13084 <filename>scripts/contrib/graph-tool</filename>
13085 Python script, which finds and displays paths
13086 between graph nodes.
13087 </para></listitem>
13088 </itemizedlist>
13089 </note>
13090 </para>
13091
13092 <para>
13093 You can use a different method to view dependency information
13094 by using the following command:
13095 <literallayout class='monospaced'>
13096 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
13097 </literallayout>
13098 This command displays a GUI window from which you can view
13099 build-time and runtime dependencies for the recipes involved in
13100 building <replaceable>recipename</replaceable>.
13101 </para>
13102 </section>
13103
13104 <section id='dev-viewing-task-variable-dependencies'>
13105 <title>Viewing Task Variable Dependencies</title>
13106
13107 <para>
13108 As mentioned in the
13109 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
13110 section of the BitBake User Manual, BitBake tries to
13111 automatically determine what variables a task depends on so
13112 that it can rerun the task if any values of the variables
13113 change.
13114 This determination is usually reliable.
13115 However, if you do things like construct variable names at
13116 runtime, then you might have to manually declare dependencies
13117 on those variables using <filename>vardeps</filename> as
13118 described in the
13119 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
13120 section of the BitBake User Manual.
13121 </para>
13122
13123 <para>
13124 If you are unsure whether a variable dependency is being
13125 picked up automatically for a given task, you can list the
13126 variable dependencies BitBake has determined by doing the
13127 following:
13128 <orderedlist>
13129 <listitem><para>
13130 Build the recipe containing the task:
13131 <literallayout class='monospaced'>
13132 $ bitbake <replaceable>recipename</replaceable>
13133 </literallayout>
13134 </para></listitem>
13135 <listitem><para>
13136 Inside the
13137 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
13138 directory, find the signature data
13139 (<filename>sigdata</filename>) file that corresponds
13140 to the task.
13141 The <filename>sigdata</filename> files contain a pickled
13142 Python database of all the metadata that went into
13143 creating the input checksum for the task.
13144 As an example, for the
13145 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
13146 task of the <filename>db</filename> recipe, the
13147 <filename>sigdata</filename> file might be found in the
13148 following location:
13149 <literallayout class='monospaced'>
13150 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13151 </literallayout>
13152 For tasks that are accelerated through the shared state
13153 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
13154 cache, an additional <filename>siginfo</filename> file
13155 is written into
13156 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13157 along with the cached task output.
13158 The <filename>siginfo</filename> files contain exactly
13159 the same information as <filename>sigdata</filename>
13160 files.
13161 </para></listitem>
13162 <listitem><para>
13163 Run <filename>bitbake-dumpsig</filename> on the
13164 <filename>sigdata</filename> or
13165 <filename>siginfo</filename> file.
13166 Here is an example:
13167 <literallayout class='monospaced'>
13168 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13169 </literallayout>
13170 In the output of the above command, you will find a
13171 line like the following, which lists all the (inferred)
13172 variable dependencies for the task.
13173 This list also includes indirect dependencies from
13174 variables depending on other variables, recursively.
13175 <literallayout class='monospaced'>
13176 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
13177 </literallayout>
13178 <note>
13179 Functions (e.g. <filename>base_do_fetch</filename>)
13180 also count as variable dependencies.
13181 These functions in turn depend on the variables they
13182 reference.
13183 </note>
13184 The output of <filename>bitbake-dumpsig</filename> also
13185 includes the value each variable had, a list of
13186 dependencies for each variable, and
13187 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
13188 information.
13189 </para></listitem>
13190 </orderedlist>
13191 </para>
13192
13193 <para>
13194 There is also a <filename>bitbake-diffsigs</filename> command
13195 for comparing two <filename>siginfo</filename> or
13196 <filename>sigdata</filename> files.
13197 This command can be helpful when trying to figure out what
13198 changed between two versions of a task.
13199 If you call <filename>bitbake-diffsigs</filename> with just one
13200 file, the command behaves like
13201 <filename>bitbake-dumpsig</filename>.
13202 </para>
13203
13204 <para>
13205 You can also use BitBake to dump out the signature construction
13206 information without executing tasks by using either of the
13207 following BitBake command-line options:
13208 <literallayout class='monospaced'>
13209 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
13210 -S <replaceable>SIGNATURE_HANDLER</replaceable>
13211 </literallayout>
13212 <note>
13213 Two common values for
13214 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
13215 "printdiff", which dump only the signature or compare the
13216 dumped signature with the cached one, respectively.
13217 </note>
13218 Using BitBake with either of these options causes BitBake to
13219 dump out <filename>sigdata</filename> files in the
13220 <filename>stamps</filename> directory for every task it would
13221 have executed instead of building the specified target package.
13222 </para>
13223 </section>
13224
13225 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
13226 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
13227
13228 <para>
13229 Seeing what metadata went into creating the input signature
13230 of a shared state (sstate) task can be a useful debugging
13231 aid.
13232 This information is available in signature information
13233 (<filename>siginfo</filename>) files in
13234 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
13235 For information on how to view and interpret information in
13236 <filename>siginfo</filename> files, see the
13237 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
13238 section.
13239 </para>
13240
13241 <para>
13242 For conceptual information on shared state, see the
13243 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
13244 section in the Yocto Project Overview and Concepts Manual.
13245 </para>
13246 </section>
13247
13248 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
13249 <title>Invalidating Shared State to Force a Task to Run</title>
13250
13251 <para>
13252 The OpenEmbedded build system uses
13253 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
13254 and
13255 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
13256 cache to avoid unnecessarily rebuilding tasks.
13257 Collectively, this scheme is known as "shared state code."
13258 </para>
13259
13260 <para>
13261 As with all schemes, this one has some drawbacks.
13262 It is possible that you could make implicit changes to your
13263 code that the checksum calculations do not take into
13264 account.
13265 These implicit changes affect a task's output but do not
13266 trigger the shared state code into rebuilding a recipe.
13267 Consider an example during which a tool changes its output.
13268 Assume that the output of <filename>rpmdeps</filename>
13269 changes.
13270 The result of the change should be that all the
13271 <filename>package</filename> and
13272 <filename>package_write_rpm</filename> shared state cache
13273 items become invalid.
13274 However, because the change to the output is
13275 external to the code and therefore implicit,
13276 the associated shared state cache items do not become
13277 invalidated.
13278 In this case, the build process uses the cached items
13279 rather than running the task again.
13280 Obviously, these types of implicit changes can cause
13281 problems.
13282 </para>
13283
13284 <para>
13285 To avoid these problems during the build, you need to
13286 understand the effects of any changes you make.
13287 Realize that changes you make directly to a function
13288 are automatically factored into the checksum calculation.
13289 Thus, these explicit changes invalidate the associated
13290 area of shared state cache.
13291 However, you need to be aware of any implicit changes that
13292 are not obvious changes to the code and could affect
13293 the output of a given task.
13294 </para>
13295
13296 <para>
13297 When you identify an implicit change, you can easily
13298 take steps to invalidate the cache and force the tasks
13299 to run.
13300 The steps you can take are as simple as changing a
13301 function's comments in the source code.
13302 For example, to invalidate package shared state files,
13303 change the comment statements of
13304 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13305 or the comments of one of the functions it calls.
13306 Even though the change is purely cosmetic, it causes the
13307 checksum to be recalculated and forces the build system to
13308 run the task again.
13309 <note>
13310 For an example of a commit that makes a cosmetic
13311 change to invalidate shared state, see this
13312 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
13313 </note>
13314 </para>
13315 </section>
13316
13317 <section id='dev-debugging-taskrunning'>
13318 <title>Running Specific Tasks</title>
13319
13320 <para>
13321 Any given recipe consists of a set of tasks.
13322 The standard BitBake behavior in most cases is:
13323 <filename>do_fetch</filename>,
13324 <filename>do_unpack</filename>,
13325 <filename>do_patch</filename>,
13326 <filename>do_configure</filename>,
13327 <filename>do_compile</filename>,
13328 <filename>do_install</filename>,
13329 <filename>do_package</filename>,
13330 <filename>do_package_write_*</filename>, and
13331 <filename>do_build</filename>.
13332 The default task is <filename>do_build</filename> and any tasks
13333 on which it depends build first.
13334 Some tasks, such as <filename>do_devshell</filename>, are not
13335 part of the default build chain.
13336 If you wish to run a task that is not part of the default build
13337 chain, you can use the <filename>-c</filename> option in
13338 BitBake.
13339 Here is an example:
13340 <literallayout class='monospaced'>
13341 $ bitbake matchbox-desktop -c devshell
13342 </literallayout>
13343 </para>
13344
13345 <para>
13346 The <filename>-c</filename> option respects task dependencies,
13347 which means that all other tasks (including tasks from other
13348 recipes) that the specified task depends on will be run before
13349 the task.
13350 Even when you manually specify a task to run with
13351 <filename>-c</filename>, BitBake will only run the task if it
13352 considers it "out of date".
13353 See the
13354 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
13355 section in the Yocto Project Overview and Concepts Manual for
13356 how BitBake determines whether a task is "out of date".
13357 </para>
13358
13359 <para>
13360 If you want to force an up-to-date task to be rerun (e.g.
13361 because you made manual modifications to the recipe's
13362 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
13363 that you want to try out), then you can use the
13364 <filename>-f</filename> option.
13365 <note>
13366 The reason <filename>-f</filename> is never required when
13367 running the
13368 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
13369 task is because the
13370 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
13371 variable flag is already set for the task.
13372 </note>
13373 The following example shows one way you can use the
13374 <filename>-f</filename> option:
13375 <literallayout class='monospaced'>
13376 $ bitbake matchbox-desktop
13377 .
13378 .
13379 make some changes to the source code in the work directory
13380 .
13381 .
13382 $ bitbake matchbox-desktop -c compile -f
13383 $ bitbake matchbox-desktop
13384 </literallayout>
13385 </para>
13386
13387 <para>
13388 This sequence first builds and then recompiles
13389 <filename>matchbox-desktop</filename>.
13390 The last command reruns all tasks (basically the packaging
13391 tasks) after the compile.
13392 BitBake recognizes that the <filename>do_compile</filename>
13393 task was rerun and therefore understands that the other tasks
13394 also need to be run again.
13395 </para>
13396
13397 <para>
13398 Another, shorter way to rerun a task and all
13399 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
13400 that depend on it is to use the <filename>-C</filename>
13401 option.
13402 <note>
13403 This option is upper-cased and is separate from the
13404 <filename>-c</filename> option, which is lower-cased.
13405 </note>
13406 Using this option invalidates the given task and then runs the
13407 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
13408 task, which is the default task if no task is given, and the
13409 tasks on which it depends.
13410 You could replace the final two commands in the previous example
13411 with the following single command:
13412 <literallayout class='monospaced'>
13413 $ bitbake matchbox-desktop -C compile
13414 </literallayout>
13415 Internally, the <filename>-f</filename> and
13416 <filename>-C</filename> options work by tainting (modifying) the
13417 input checksum of the specified task.
13418 This tainting indirectly causes the task and its
13419 dependent tasks to be rerun through the normal task dependency
13420 mechanisms.
13421 <note>
13422 BitBake explicitly keeps track of which tasks have been
13423 tainted in this fashion, and will print warnings such as the
13424 following for builds involving such tasks:
13425 <literallayout class='monospaced'>
13426 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
13427 </literallayout>
13428 The purpose of the warning is to let you know that the work
13429 directory and build output might not be in the clean state
13430 they would be in for a "normal" build, depending on what
13431 actions you took.
13432 To get rid of such warnings, you can remove the work
13433 directory and rebuild the recipe, as follows:
13434 <literallayout class='monospaced'>
13435 $ bitbake matchbox-desktop -c clean
13436 $ bitbake matchbox-desktop
13437 </literallayout>
13438 </note>
13439 </para>
13440
13441 <para>
13442 You can view a list of tasks in a given package by running the
13443 <filename>do_listtasks</filename> task as follows:
13444 <literallayout class='monospaced'>
13445 $ bitbake matchbox-desktop -c listtasks
13446 </literallayout>
13447 The results appear as output to the console and are also in the
13448 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
13449 </para>
13450 </section>
13451
13452 <section id='dev-debugging-bitbake'>
13453 <title>General BitBake Problems</title>
13454
13455 <para>
13456 You can see debug output from BitBake by using the
13457 <filename>-D</filename> option.
13458 The debug output gives more information about what BitBake
13459 is doing and the reason behind it.
13460 Each <filename>-D</filename> option you use increases the
13461 logging level.
13462 The most common usage is <filename>-DDD</filename>.
13463 </para>
13464
13465 <para>
13466 The output from
13467 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
13468 can reveal why BitBake chose a certain version of a package or
13469 why BitBake picked a certain provider.
13470 This command could also help you in a situation where you think
13471 BitBake did something unexpected.
13472 </para>
13473 </section>
13474
13475 <section id='dev-debugging-buildfile'>
13476 <title>Building with No Dependencies</title>
13477
13478 <para>
13479 To build a specific recipe (<filename>.bb</filename> file),
13480 you can use the following command form:
13481 <literallayout class='monospaced'>
13482 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13483 </literallayout>
13484 This command form does not check for dependencies.
13485 Consequently, you should use it only when you know existing
13486 dependencies have been met.
13487 <note>
13488 You can also specify fragments of the filename.
13489 In this case, BitBake checks for a unique match.
13490 </note>
13491 </para>
13492 </section>
13493
13494 <section id='recipe-logging-mechanisms'>
13495 <title>Recipe Logging Mechanisms</title>
13496
13497 <para>
13498 The Yocto Project provides several logging functions for
13499 producing debugging output and reporting errors and warnings.
13500 For Python functions, the following logging functions exist.
13501 All of these functions log to
13502 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13503 and can also log to standard output (stdout) with the right
13504 settings:
13505 <itemizedlist>
13506 <listitem><para>
13507 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13508 Writes <replaceable>msg</replaceable> as is to the
13509 log while also logging to stdout.
13510 </para></listitem>
13511 <listitem><para>
13512 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13513 Writes "NOTE: <replaceable>msg</replaceable>" to the
13514 log.
13515 Also logs to stdout if BitBake is called with "-v".
13516 </para></listitem>
13517 <listitem><para>
13518 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13519 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13520 log.
13521 Also logs to stdout if the log level is greater than or
13522 equal to <replaceable>level</replaceable>.
13523 See the
13524 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13525 option in the BitBake User Manual for more information.
13526 </para></listitem>
13527 <listitem><para>
13528 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13529 Writes "WARNING: <replaceable>msg</replaceable>" to the
13530 log while also logging to stdout.
13531 </para></listitem>
13532 <listitem><para>
13533 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13534 Writes "ERROR: <replaceable>msg</replaceable>" to the
13535 log while also logging to standard out (stdout).
13536 <note>
13537 Calling this function does not cause the task to fail.
13538 </note>
13539 </para></listitem>
13540 <listitem><para>
13541 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13542 This logging function is similar to
13543 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13544 but also causes the calling task to fail.
13545 <note>
13546 <filename>bb.fatal()</filename> raises an exception,
13547 which means you do not need to put a "return"
13548 statement after the function.
13549 </note>
13550 </para></listitem>
13551 </itemizedlist>
13552 </para>
13553
13554 <para>
13555 The same logging functions are also available in shell
13556 functions, under the names
13557 <filename>bbplain</filename>, <filename>bbnote</filename>,
13558 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13559 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13560 The
13561 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13562 class implements these functions.
13563 See that class in the
13564 <filename>meta/classes</filename> folder of the
13565 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13566 for information.
13567 </para>
13568
13569 <section id='logging-with-python'>
13570 <title>Logging With Python</title>
13571
13572 <para>
13573 When creating recipes using Python and inserting code that
13574 handles build logs, keep in mind the goal is to have
13575 informative logs while keeping the console as "silent" as
13576 possible.
13577 Also, if you want status messages in the log, use the
13578 "debug" loglevel.
13579 </para>
13580
13581 <para>
13582 Following is an example written in Python.
13583 The code handles logging for a function that determines the
13584 number of tasks needed to be run.
13585 See the
13586 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13587 section for additional information:
13588 <literallayout class='monospaced'>
13589 python do_listtasks() {
13590 bb.debug(2, "Starting to figure out the task list")
13591 if noteworthy_condition:
13592 bb.note("There are 47 tasks to run")
13593 bb.debug(2, "Got to point xyz")
13594 if warning_trigger:
13595 bb.warn("Detected warning_trigger, this might be a problem later.")
13596 if recoverable_error:
13597 bb.error("Hit recoverable_error, you really need to fix this!")
13598 if fatal_error:
13599 bb.fatal("fatal_error detected, unable to print the task list")
13600 bb.plain("The tasks present are abc")
13601 bb.debug(2, "Finished figuring out the tasklist")
13602 }
13603 </literallayout>
13604 </para>
13605 </section>
13606
13607 <section id='logging-with-bash'>
13608 <title>Logging With Bash</title>
13609
13610 <para>
13611 When creating recipes using Bash and inserting code that
13612 handles build logs, you have the same goals - informative
13613 with minimal console output.
13614 The syntax you use for recipes written in Bash is similar
13615 to that of recipes written in Python described in the
13616 previous section.
13617 </para>
13618
13619 <para>
13620 Following is an example written in Bash.
13621 The code logs the progress of the <filename>do_my_function</filename> function.
13622 <literallayout class='monospaced'>
13623 do_my_function() {
13624 bbdebug 2 "Running do_my_function"
13625 if [ exceptional_condition ]; then
13626 bbnote "Hit exceptional_condition"
13627 fi
13628 bbdebug 2 "Got to point xyz"
13629 if [ warning_trigger ]; then
13630 bbwarn "Detected warning_trigger, this might cause a problem later."
13631 fi
13632 if [ recoverable_error ]; then
13633 bberror "Hit recoverable_error, correcting"
13634 fi
13635 if [ fatal_error ]; then
13636 bbfatal "fatal_error detected"
13637 fi
13638 bbdebug 2 "Completed do_my_function"
13639 }
13640 </literallayout>
13641 </para>
13642 </section>
13643 </section>
13644
13645 <section id='debugging-parallel-make-races'>
13646 <title>Debugging Parallel Make Races</title>
13647
13648 <para>
13649 A parallel <filename>make</filename> race occurs when the build
13650 consists of several parts that are run simultaneously and
13651 a situation occurs when the output or result of one
13652 part is not ready for use with a different part of the build
13653 that depends on that output.
13654 Parallel make races are annoying and can sometimes be difficult
13655 to reproduce and fix.
13656 However, some simple tips and tricks exist that can help
13657 you debug and fix them.
13658 This section presents a real-world example of an error
13659 encountered on the Yocto Project autobuilder and the process
13660 used to fix it.
13661 <note>
13662 If you cannot properly fix a <filename>make</filename> race
13663 condition, you can work around it by clearing either the
13664 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13665 or
13666 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13667 variables.
13668 </note>
13669 </para>
13670
13671 <section id='the-failure'>
13672 <title>The Failure</title>
13673
13674 <para>
13675 For this example, assume that you are building an image that
13676 depends on the "neard" package.
13677 And, during the build, BitBake runs into problems and
13678 creates the following output.
13679 <note>
13680 This example log file has longer lines artificially
13681 broken to make the listing easier to read.
13682 </note>
13683 If you examine the output or the log file, you see the
13684 failure during <filename>make</filename>:
13685 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013686 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13687 | DEBUG: Executing shell function do_compile
13688 | NOTE: make -j 16
13689 | make --no-print-directory all-am
13690 | /bin/mkdir -p include/near
13691 | /bin/mkdir -p include/near
13692 | /bin/mkdir -p include/near
13693 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13694 0.14-r0/neard-0.14/include/types.h include/near/types.h
13695 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13696 0.14-r0/neard-0.14/include/log.h include/near/log.h
13697 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13698 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13699 | /bin/mkdir -p include/near
13700 | /bin/mkdir -p include/near
13701 | /bin/mkdir -p include/near
13702 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13703 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13704 | /bin/mkdir -p include/near
13705 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13706 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13707 | /bin/mkdir -p include/near
13708 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13709 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13710 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13711 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13712 | /bin/mkdir -p include/near
13713 | /bin/mkdir -p include/near
13714 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13715 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13716 | /bin/mkdir -p include/near
13717 | /bin/mkdir -p include/near
13718 | /bin/mkdir -p include/near
13719 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13720 0.14-r0/neard-0.14/include/device.h include/near/device.h
13721 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13722 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13723 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13724 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13725 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13726 0.14-r0/neard-0.14/include/version.h include/near/version.h
13727 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13728 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13729 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13730 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13731 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13732 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13733 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13734 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13735 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13736 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13737 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13738 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13739 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13740 -o tools/snep-send.o tools/snep-send.c
13741 | In file included from tools/snep-send.c:16:0:
13742 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13743 | #include &lt;near/dbus.h&gt;
13744 | ^
13745 | compilation terminated.
13746 | make[1]: *** [tools/snep-send.o] Error 1
13747 | make[1]: *** Waiting for unfinished jobs....
13748 | make: *** [all] Error 2
13749 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013750 </literallayout>
13751 </para>
13752 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013753
Brad Bishop316dfdd2018-06-25 12:45:53 -040013754 <section id='reproducing-the-error'>
13755 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013756
Brad Bishop316dfdd2018-06-25 12:45:53 -040013757 <para>
13758 Because race conditions are intermittent, they do not
13759 manifest themselves every time you do the build.
13760 In fact, most times the build will complete without problems
13761 even though the potential race condition exists.
13762 Thus, once the error surfaces, you need a way to reproduce
13763 it.
13764 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013765
Brad Bishop316dfdd2018-06-25 12:45:53 -040013766 <para>
13767 In this example, compiling the "neard" package is causing
13768 the problem.
13769 So the first thing to do is build "neard" locally.
13770 Before you start the build, set the
13771 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13772 variable in your <filename>local.conf</filename> file to
13773 a high number (e.g. "-j 20").
13774 Using a high value for <filename>PARALLEL_MAKE</filename>
13775 increases the chances of the race condition showing up:
13776 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013777 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013778 </literallayout>
13779 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013780
Brad Bishop316dfdd2018-06-25 12:45:53 -040013781 <para>
13782 Once the local build for "neard" completes, start a
13783 <filename>devshell</filename> build:
13784 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013785 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013786 </literallayout>
13787 For information on how to use a
13788 <filename>devshell</filename>, see the
13789 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13790 section.
13791 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013792
Brad Bishop316dfdd2018-06-25 12:45:53 -040013793 <para>
13794 In the <filename>devshell</filename>, do the following:
13795 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013796 $ make clean
13797 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013798 </literallayout>
13799 The <filename>devshell</filename> commands cause the failure
13800 to clearly be visible.
13801 In this case, a missing dependency exists for the "neard"
13802 Makefile target.
13803 Here is some abbreviated, sample output with the
13804 missing dependency clearly visible at the end:
13805 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013806 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13807 .
13808 .
13809 .
13810 tools/snep-send.c
13811 In file included from tools/snep-send.c:16:0:
13812 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13813 #include &lt;near/dbus.h&gt;
13814 ^
13815 compilation terminated.
13816 make: *** [tools/snep-send.o] Error 1
13817 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013818 </literallayout>
13819 </para>
13820 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013821
Brad Bishop316dfdd2018-06-25 12:45:53 -040013822 <section id='creating-a-patch-for-the-fix'>
13823 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013824
Brad Bishop316dfdd2018-06-25 12:45:53 -040013825 <para>
13826 Because there is a missing dependency for the Makefile
13827 target, you need to patch the
13828 <filename>Makefile.am</filename> file, which is generated
13829 from <filename>Makefile.in</filename>.
13830 You can use Quilt to create the patch:
13831 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013832 $ quilt new parallelmake.patch
13833 Patch patches/parallelmake.patch is now on top
13834 $ quilt add Makefile.am
13835 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013836 </literallayout>
13837 For more information on using Quilt, see the
13838 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13839 section.
13840 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013841
Brad Bishop316dfdd2018-06-25 12:45:53 -040013842 <para>
13843 At this point you need to make the edits to
13844 <filename>Makefile.am</filename> to add the missing
13845 dependency.
13846 For our example, you have to add the following line
13847 to the file:
13848 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013849 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013850 </literallayout>
13851 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013852
Brad Bishop316dfdd2018-06-25 12:45:53 -040013853 <para>
13854 Once you have edited the file, use the
13855 <filename>refresh</filename> command to create the patch:
13856 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013857 $ quilt refresh
13858 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013859 </literallayout>
13860 Once the patch file exists, you need to add it back to the
13861 originating recipe folder.
13862 Here is an example assuming a top-level
13863 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13864 named <filename>poky</filename>:
13865 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013866 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013867 </literallayout>
13868 The final thing you need to do to implement the fix in the
13869 build is to update the "neard" recipe (i.e.
13870 <filename>neard-0.14.bb</filename>) so that the
13871 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13872 statement includes the patch file.
13873 The recipe file is in the folder above the patch.
13874 Here is what the edited <filename>SRC_URI</filename>
13875 statement would look like:
13876 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013877 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13878 file://neard.in \
13879 file://neard.service.in \
13880 file://parallelmake.patch \
13881 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013882 </literallayout>
13883 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013884
Brad Bishop316dfdd2018-06-25 12:45:53 -040013885 <para>
13886 With the patch complete and moved to the correct folder and
13887 the <filename>SRC_URI</filename> statement updated, you can
13888 exit the <filename>devshell</filename>:
13889 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013890 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013891 </literallayout>
13892 </para>
13893 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013894
Brad Bishop316dfdd2018-06-25 12:45:53 -040013895 <section id='testing-the-build'>
13896 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013897
Brad Bishop316dfdd2018-06-25 12:45:53 -040013898 <para>
13899 With everything in place, you can get back to trying the
13900 build again locally:
13901 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013902 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013903 </literallayout>
13904 This build should succeed.
13905 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013906
Brad Bishop316dfdd2018-06-25 12:45:53 -040013907 <para>
13908 Now you can open up a <filename>devshell</filename> again
13909 and repeat the clean and make operations as follows:
13910 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013911 $ bitbake neard -c devshell
13912 $ make clean
13913 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013914 </literallayout>
13915 The build should work without issue.
13916 </para>
13917
13918 <para>
13919 As with all solved problems, if they originated upstream,
13920 you need to submit the fix for the recipe in OE-Core and
13921 upstream so that the problem is taken care of at its
13922 source.
13923 See the
13924 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13925 section for more information.
13926 </para>
13927 </section>
13928 </section>
13929
13930 <section id="platdev-gdb-remotedebug">
13931 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13932
13933 <para>
13934 GDB allows you to examine running programs, which in turn helps
13935 you to understand and fix problems.
13936 It also allows you to perform post-mortem style analysis of
13937 program crashes.
13938 GDB is available as a package within the Yocto Project and is
13939 installed in SDK images by default.
13940 See the
13941 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13942 chapter in the Yocto Project Reference Manual for a description of
13943 these images.
13944 You can find information on GDB at
13945 <ulink url="http://sourceware.org/gdb/"/>.
13946 <note><title>Tip</title>
13947 For best results, install debug (<filename>-dbg</filename>)
13948 packages for the applications you are going to debug.
13949 Doing so makes extra debug symbols available that give you
13950 more meaningful output.
13951 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013952 </para>
13953
13954 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013955 Sometimes, due to memory or disk space constraints, it is not
13956 possible to use GDB directly on the remote target to debug
13957 applications.
13958 These constraints arise because GDB needs to load the debugging
13959 information and the binaries of the process being debugged.
13960 Additionally, GDB needs to perform many computations to locate
13961 information such as function names, variable names and values,
13962 stack traces and so forth - even before starting the debugging
13963 process.
13964 These extra computations place more load on the target system
13965 and can alter the characteristics of the program being debugged.
13966 </para>
13967
13968 <para>
13969 To help get past the previously mentioned constraints, you can
13970 use gdbserver, which runs on the remote target and does not
13971 load any debugging information from the debugged process.
13972 Instead, a GDB instance processes the debugging information that
13973 is run on a remote computer - the host GDB.
13974 The host GDB then sends control commands to gdbserver to make
13975 it stop or start the debugged program, as well as read or write
13976 memory regions of that debugged program.
13977 All the debugging information loaded and processed as well
13978 as all the heavy debugging is done by the host GDB.
13979 Offloading these processes gives the gdbserver running on the
13980 target a chance to remain small and fast.
13981 </para>
13982
13983 <para>
13984 Because the host GDB is responsible for loading the debugging
13985 information and for doing the necessary processing to make
13986 actual debugging happen, you have to make sure the host can
13987 access the unstripped binaries complete with their debugging
13988 information and also be sure the target is compiled with no
13989 optimizations.
13990 The host GDB must also have local access to all the libraries
13991 used by the debugged program.
13992 Because gdbserver does not need any local debugging information,
13993 the binaries on the remote target can remain stripped.
13994 However, the binaries must also be compiled without optimization
13995 so they match the host's binaries.
13996 </para>
13997
13998 <para>
13999 To remain consistent with GDB documentation and terminology,
14000 the binary being debugged on the remote target machine is
14001 referred to as the "inferior" binary.
14002 For documentation on GDB see the
14003 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
14004 </para>
14005
14006 <para>
14007 The following steps show you how to debug using the GNU project
14008 debugger.
14009 <orderedlist>
14010 <listitem><para>
14011 <emphasis>Configure your build system to construct the
14012 companion debug filesystem:</emphasis></para>
14013
14014 <para>In your <filename>local.conf</filename> file, set
14015 the following:
14016 <literallayout class='monospaced'>
14017 IMAGE_GEN_DEBUGFS = "1"
14018 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
14019 </literallayout>
14020 These options cause the OpenEmbedded build system
14021 to generate a special companion filesystem fragment,
14022 which contains the matching source and debug symbols to
14023 your deployable filesystem.
14024 The build system does this by looking at what is in the
14025 deployed filesystem, and pulling the corresponding
14026 <filename>-dbg</filename> packages.</para>
14027
14028 <para>The companion debug filesystem is not a complete
14029 filesystem, but only contains the debug fragments.
14030 This filesystem must be combined with the full filesystem
14031 for debugging.
14032 Subsequent steps in this procedure show how to combine
14033 the partial filesystem with the full filesystem.
14034 </para></listitem>
14035 <listitem><para>
14036 <emphasis>Configure the system to include gdbserver in
14037 the target filesystem:</emphasis></para>
14038
14039 <para>Make the following addition in either your
14040 <filename>local.conf</filename> file or in an image
14041 recipe:
14042 <literallayout class='monospaced'>
14043 IMAGE_INSTALL_append = “ gdbserver"
14044 </literallayout>
14045 The change makes sure the <filename>gdbserver</filename>
14046 package is included.
14047 </para></listitem>
14048 <listitem><para>
14049 <emphasis>Build the environment:</emphasis></para>
14050
14051 <para>Use the following command to construct the image
14052 and the companion Debug Filesystem:
14053 <literallayout class='monospaced'>
14054 $ bitbake <replaceable>image</replaceable>
14055 </literallayout>
14056 Build the cross GDB component and make it available
14057 for debugging.
14058 Build the SDK that matches the image.
14059 Building the SDK is best for a production build
14060 that can be used later for debugging, especially
14061 during long term maintenance:
14062 <literallayout class='monospaced'>
14063 $ bitbake -c populate_sdk <replaceable>image</replaceable>
14064 </literallayout></para>
14065
14066 <para>Alternatively, you can build the minimal
14067 toolchain components that match the target.
14068 Doing so creates a smaller than typical SDK and only
14069 contains a minimal set of components with which to
14070 build simple test applications, as well as run the
14071 debugger:
14072 <literallayout class='monospaced'>
14073 $ bitbake meta-toolchain
14074 </literallayout></para>
14075
14076 <para>A final method is to build Gdb itself within
14077 the build system:
14078 <literallayout class='monospaced'>
14079 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
14080 </literallayout>
14081 Doing so produces a temporary copy of
14082 <filename>cross-gdb</filename> you can use for
14083 debugging during development.
14084 While this is the quickest approach, the two previous
14085 methods in this step are better when considering
14086 long-term maintenance strategies.
14087 <note>
14088 If you run
14089 <filename>bitbake gdb-cross</filename>, the
14090 OpenEmbedded build system suggests the actual
14091 image (e.g. <filename>gdb-cross-i586</filename>).
14092 The suggestion is usually the actual name you want
14093 to use.
14094 </note>
14095 </para></listitem>
14096 <listitem><para>
14097 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
14098
14099 <para>Run the following commands to set up the
14100 <filename>debugfs</filename>:
14101 <literallayout class='monospaced'>
14102 $ mkdir debugfs
14103 $ cd debugfs
14104 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
14105 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
14106 </literallayout>
14107 </para></listitem>
14108 <listitem><para>
14109 <emphasis>Set up GDB</emphasis></para>
14110
14111 <para>Install the SDK (if you built one) and then
14112 source the correct environment file.
14113 Sourcing the environment file puts the SDK in your
14114 <filename>PATH</filename> environment variable.</para>
14115
14116 <para>If you are using the build system, Gdb is
14117 located in
14118 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
14119 </para></listitem>
14120 <listitem><para>
14121 <emphasis>Boot the target:</emphasis></para>
14122
14123 <para>For information on how to run QEMU, see the
14124 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
14125 <note>
14126 Be sure to verify that your host can access the
14127 target via TCP.
14128 </note>
14129 </para></listitem>
14130 <listitem><para>
14131 <emphasis>Debug a program:</emphasis></para>
14132
14133 <para>Debugging a program involves running gdbserver
14134 on the target and then running Gdb on the host.
14135 The example in this step debugs
14136 <filename>gzip</filename>:
14137 <literallayout class='monospaced'>
14138 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
14139 </literallayout>
14140 For additional gdbserver options, see the
14141 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
14142 </para>
14143
14144 <para>After running gdbserver on the target, you need
14145 to run Gdb on the host and configure it and connect to
14146 the target.
14147 Use these commands:
14148 <literallayout class='monospaced'>
14149 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
14150 $ <replaceable>arch</replaceable>-gdb
14151
14152 (gdb) set sysroot debugfs
14153 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
14154 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
14155 </literallayout>
14156 At this point, everything should automatically load
14157 (i.e. matching binaries, symbols and headers).
14158 <note>
14159 The Gdb <filename>set</filename> commands in the
14160 previous example can be placed into the users
14161 <filename>~/.gdbinit</filename> file.
14162 Upon starting, Gdb automatically runs whatever
14163 commands are in that file.
14164 </note>
14165 </para></listitem>
14166 <listitem><para>
14167 <emphasis>Deploying without a full image
14168 rebuild:</emphasis></para>
14169
14170 <para>In many cases, during development you want a
14171 quick method to deploy a new binary to the target and
14172 debug it, without waiting for a full image build.
14173 </para>
14174
14175 <para>One approach to solving this situation is to
14176 just build the component you want to debug.
14177 Once you have built the component, copy the
14178 executable directly to both the target and the
14179 host <filename>debugfs</filename>.</para>
14180
14181 <para>If the binary is processed through the debug
14182 splitting in OpenEmbedded, you should also
14183 copy the debug items (i.e. <filename>.debug</filename>
14184 contents and corresponding
14185 <filename>/usr/src/debug</filename> files)
14186 from the work directory.
14187 Here is an example:
14188 <literallayout class='monospaced'>
14189 $ bitbake bash
14190 $ bitbake -c devshell bash
14191 $ cd ..
14192 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
14193 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
14194 </literallayout>
14195 </para></listitem>
14196 </orderedlist>
14197 </para>
14198 </section>
14199
14200 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
14201 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
14202
14203 <para>
14204 The previous section addressed using GDB remotely for debugging
14205 purposes, which is the most usual case due to the inherent
14206 hardware limitations on many embedded devices.
14207 However, debugging in the target hardware itself is also
14208 possible with more powerful devices.
14209 This section describes what you need to do in order to support
14210 using GDB to debug on the target hardware.
14211 </para>
14212
14213 <para>
14214 To support this kind of debugging, you need do the following:
14215 <itemizedlist>
14216 <listitem><para>
14217 Ensure that GDB is on the target.
14218 You can do this by adding "gdb" to
14219 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
14220 <literallayout class='monospaced'>
14221 IMAGE_INSTALL_append = " gdb"
14222 </literallayout>
14223 Alternatively, you can add "tools-debug" to
14224 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
14225 <literallayout class='monospaced'>
14226 IMAGE_FEATURES_append = " tools-debug"
14227 </literallayout>
14228 </para></listitem>
14229 <listitem><para>
14230 Ensure that debug symbols are present.
14231 You can make sure these symbols are present by
14232 installing <filename>-dbg</filename>:
14233 <literallayout class='monospaced'>
14234 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
14235 </literallayout>
14236 Alternatively, you can do the following to include all
14237 the debug symbols:
14238 <literallayout class='monospaced'>
14239 IMAGE_FEATURES_append = " dbg-pkgs"
14240 </literallayout>
14241 </para></listitem>
14242 </itemizedlist>
14243 <note>
14244 To improve the debug information accuracy, you can reduce
14245 the level of optimization used by the compiler.
14246 For example, when adding the following line to your
14247 <filename>local.conf</filename> file, you will reduce
14248 optimization from
14249 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
14250 of "-O2" to
14251 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
14252 of "-O -fno-omit-frame-pointer":
14253 <literallayout class='monospaced'>
14254 DEBUG_BUILD = "1"
14255 </literallayout>
14256 Consider that this will reduce the application's performance
14257 and is recommended only for debugging purposes.
14258 </note>
14259 </para>
14260 </section>
14261
14262 <section id='dev-other-debugging-others'>
14263 <title>Other Debugging Tips</title>
14264
14265 <para>
14266 Here are some other tips that you might find useful:
14267 <itemizedlist>
14268 <listitem><para>
14269 When adding new packages, it is worth watching for
14270 undesirable items making their way into compiler command
14271 lines.
14272 For example, you do not want references to local system
14273 files like
14274 <filename>/usr/lib/</filename> or
14275 <filename>/usr/include/</filename>.
14276 </para></listitem>
14277 <listitem><para>
14278 If you want to remove the <filename>psplash</filename>
14279 boot splashscreen,
14280 add <filename>psplash=false</filename> to the kernel
14281 command line.
14282 Doing so prevents <filename>psplash</filename> from
14283 loading and thus allows you to see the console.
14284 It is also possible to switch out of the splashscreen by
14285 switching the virtual console (e.g. Fn+Left or Fn+Right
14286 on a Zaurus).
14287 </para></listitem>
14288 <listitem><para>
14289 Removing
14290 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
14291 (usually <filename>tmp/</filename>, within the
14292 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
14293 can often fix temporary build issues.
14294 Removing <filename>TMPDIR</filename> is usually a
14295 relatively cheap operation, because task output will be
14296 cached in
14297 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
14298 (usually <filename>sstate-cache/</filename>, which is
14299 also in the Build Directory).
14300 <note>
14301 Removing <filename>TMPDIR</filename> might be a
14302 workaround rather than a fix.
14303 Consequently, trying to determine the underlying
14304 cause of an issue before removing the directory is
14305 a good idea.
14306 </note>
14307 </para></listitem>
14308 <listitem><para>
14309 Understanding how a feature is used in practice within
14310 existing recipes can be very helpful.
14311 It is recommended that you configure some method that
14312 allows you to quickly search through files.</para>
14313
14314 <para>Using GNU Grep, you can use the following shell
14315 function to recursively search through common
14316 recipe-related files, skipping binary files,
14317 <filename>.git</filename> directories, and the
14318 Build Directory (assuming its name starts with
14319 "build"):
14320 <literallayout class='monospaced'>
14321 g() {
14322 grep -Ir \
14323 --exclude-dir=.git \
14324 --exclude-dir='build*' \
14325 --include='*.bb*' \
14326 --include='*.inc*' \
14327 --include='*.conf*' \
14328 --include='*.py*' \
14329 "$@"
14330 }
14331 </literallayout>
14332 Following are some usage examples:
14333 <literallayout class='monospaced'>
14334 $ g FOO # Search recursively for "FOO"
14335 $ g -i foo # Search recursively for "foo", ignoring case
14336 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
14337 </literallayout>
14338 If figuring out how some feature works requires a lot of
14339 searching, it might indicate that the documentation
14340 should be extended or improved.
14341 In such cases, consider filing a documentation bug using
14342 the Yocto Project implementation of
14343 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
14344 For information on how to submit a bug against
14345 the Yocto Project, see the Yocto Project Bugzilla
14346 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
14347 and the
14348 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
14349 section.
14350 <note>
14351 The manuals might not be the right place to document
14352 variables that are purely internal and have a
14353 limited scope (e.g. internal variables used to
14354 implement a single <filename>.bbclass</filename>
14355 file).
14356 </note>
14357 </para></listitem>
14358 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014359 </para>
14360 </section>
14361 </section>
14362
Brad Bishop316dfdd2018-06-25 12:45:53 -040014363 <section id='making-changes-to-the-yocto-project'>
14364 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014365
14366 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014367 Because the Yocto Project is an open-source, community-based
14368 project, you can effect changes to the project.
14369 This section presents procedures that show you how to submit
14370 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014371 </para>
14372
Brad Bishop316dfdd2018-06-25 12:45:53 -040014373 <section id='submitting-a-defect-against-the-yocto-project'>
14374 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014375
14376 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014377 Use the Yocto Project implementation of
14378 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
14379 to submit a defect (bug) against the Yocto Project.
14380 For additional information on this implementation of Bugzilla see the
14381 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
14382 section in the Yocto Project Reference Manual.
14383 For more detail on any of the following steps, see the Yocto Project
14384 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014385 </para>
14386
14387 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014388 Use the following general steps to submit a bug"
14389
14390 <orderedlist>
14391 <listitem><para>
14392 Open the Yocto Project implementation of
14393 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
14394 </para></listitem>
14395 <listitem><para>
14396 Click "File a Bug" to enter a new bug.
14397 </para></listitem>
14398 <listitem><para>
14399 Choose the appropriate "Classification", "Product", and
14400 "Component" for which the bug was found.
14401 Bugs for the Yocto Project fall into one of several
14402 classifications, which in turn break down into several
14403 products and components.
14404 For example, for a bug against the
14405 <filename>meta-intel</filename> layer, you would choose
14406 "Build System, Metadata &amp; Runtime", "BSPs", and
14407 "bsps-meta-intel", respectively.
14408 </para></listitem>
14409 <listitem><para>
14410 Choose the "Version" of the Yocto Project for which you found
14411 the bug (e.g. &DISTRO;).
14412 </para></listitem>
14413 <listitem><para>
14414 Determine and select the "Severity" of the bug.
14415 The severity indicates how the bug impacted your work.
14416 </para></listitem>
14417 <listitem><para>
14418 Choose the "Hardware" that the bug impacts.
14419 </para></listitem>
14420 <listitem><para>
14421 Choose the "Architecture" that the bug impacts.
14422 </para></listitem>
14423 <listitem><para>
14424 Choose a "Documentation change" item for the bug.
14425 Fixing a bug might or might not affect the Yocto Project
14426 documentation.
14427 If you are unsure of the impact to the documentation, select
14428 "Don't Know".
14429 </para></listitem>
14430 <listitem><para>
14431 Provide a brief "Summary" of the bug.
14432 Try to limit your summary to just a line or two and be sure
14433 to capture the essence of the bug.
14434 </para></listitem>
14435 <listitem><para>
14436 Provide a detailed "Description" of the bug.
14437 You should provide as much detail as you can about the context,
14438 behavior, output, and so forth that surrounds the bug.
14439 You can even attach supporting files for output from logs by
14440 using the "Add an attachment" button.
14441 </para></listitem>
14442 <listitem><para>
14443 Click the "Submit Bug" button submit the bug.
14444 A new Bugzilla number is assigned to the bug and the defect
14445 is logged in the bug tracking system.
14446 </para></listitem>
14447 </orderedlist>
14448 Once you file a bug, the bug is processed by the Yocto Project Bug
14449 Triage Team and further details concerning the bug are assigned
14450 (e.g. priority and owner).
14451 You are the "Submitter" of the bug and any further categorization,
14452 progress, or comments on the bug result in Bugzilla sending you an
14453 automated email concerning the particular change or progress to the
14454 bug.
14455 </para>
14456 </section>
14457
14458 <section id='how-to-submit-a-change'>
14459 <title>Submitting a Change to the Yocto Project</title>
14460
14461 <para>
14462 Contributions to the Yocto Project and OpenEmbedded are very welcome.
14463 Because the system is extremely configurable and flexible, we recognize
14464 that developers will want to extend, configure or optimize it for
14465 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014466 </para>
14467
14468 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014469 The Yocto Project uses a mailing list and a patch-based workflow
14470 that is similar to the Linux kernel but contains important
14471 differences.
14472 In general, a mailing list exists through which you can submit
14473 patches.
14474 You should send patches to the appropriate mailing list so that they
14475 can be reviewed and merged by the appropriate maintainer.
14476 The specific mailing list you need to use depends on the
14477 location of the code you are changing.
14478 Each component (e.g. layer) should have a
14479 <filename>README</filename> file that indicates where to send
14480 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014481 </para>
14482
14483 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014484 You can send the patch to the mailing list using whichever approach
14485 you feel comfortable with to generate the patch.
14486 Once sent, the patch is usually reviewed by the community at large.
14487 If somebody has concerns with the patch, they will usually voice
14488 their concern over the mailing list.
14489 If a patch does not receive any negative reviews, the maintainer of
14490 the affected layer typically takes the patch, tests it, and then
14491 based on successful testing, merges the patch.
14492 </para>
14493
14494 <para id='figuring-out-the-mailing-list-to-use'>
14495 The "poky" repository, which is the Yocto Project's reference build
14496 environment, is a hybrid repository that contains several
14497 individual pieces (e.g. BitBake, Metadata, documentation,
14498 and so forth) built using the combo-layer tool.
14499 The upstream location used for submitting changes varies by
14500 component:
14501 <itemizedlist>
14502 <listitem><para>
14503 <emphasis>Core Metadata:</emphasis>
14504 Send your patch to the
14505 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14506 mailing list. For example, a change to anything under
14507 the <filename>meta</filename> or
14508 <filename>scripts</filename> directories should be sent
14509 to this mailing list.
14510 </para></listitem>
14511 <listitem><para>
14512 <emphasis>BitBake:</emphasis>
14513 For changes to BitBake (i.e. anything under the
14514 <filename>bitbake</filename> directory), send your patch
14515 to the
14516 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14517 mailing list.
14518 </para></listitem>
14519 <listitem><para>
14520 <emphasis>"meta-*" trees:</emphasis>
14521 These trees contain Metadata.
14522 Use the
14523 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14524 mailing list.
14525 </para></listitem>
14526 </itemizedlist>
14527 </para>
14528
14529 <para>
14530 For changes to other layers hosted in the Yocto Project source
14531 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14532 and the Yocto Project documentation, use the
14533 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14534 general mailing list.
14535 <note>
14536 Sometimes a layer's documentation specifies to use a
14537 particular mailing list.
14538 If so, use that list.
14539 </note>
14540 For additional recipes that do not fit into the core Metadata, you
14541 should determine which layer the recipe should go into and submit
14542 the change in the manner recommended by the documentation (e.g.
14543 the <filename>README</filename> file) supplied with the layer.
14544 If in doubt, please ask on the Yocto general mailing list or on
14545 the openembedded-devel mailing list.
14546 </para>
14547
14548 <para>
14549 You can also push a change upstream and request a maintainer to
14550 pull the change into the component's upstream repository.
14551 You do this by pushing to a contribution repository that is upstream.
14552 See the
14553 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14554 section in the Yocto Project Overview and Concepts Manual for additional
14555 concepts on working in the Yocto Project development environment.
14556 </para>
14557
14558 <para>
14559 Two commonly used testing repositories exist for
14560 OpenEmbedded-Core:
14561 <itemizedlist>
14562 <listitem><para>
14563 <emphasis>"ross/mut" branch:</emphasis>
14564 The "mut" (master-under-test) tree
14565 exists in the <filename>poky-contrib</filename> repository
14566 in the
14567 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14568 </para></listitem>
14569 <listitem><para>
14570 <emphasis>"master-next" branch:</emphasis>
14571 This branch is part of the main
14572 "poky" repository in the Yocto Project source repositories.
14573 </para></listitem>
14574 </itemizedlist>
14575 Maintainers use these branches to test submissions prior to merging
14576 patches.
14577 Thus, you can get an idea of the status of a patch based on
14578 whether the patch has been merged into one of these branches.
14579 <note>
14580 This system is imperfect and changes can sometimes get lost in the
14581 flow.
14582 Asking about the status of a patch or change is reasonable if the
14583 change has been idle for a while with no feedback.
14584 The Yocto Project does have plans to use
14585 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14586 to track the status of patches and also to automatically preview
14587 patches.
14588 </note>
14589 </para>
14590
14591 <para>
14592 The following sections provide procedures for submitting a change.
14593 </para>
14594
14595 <section id='pushing-a-change-upstream'>
14596 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14597
14598 <para>
14599 Follow this procedure to push a change to an upstream "contrib"
14600 Git repository:
14601 <note>
14602 You can find general Git information on how to push a change
14603 upstream in the
14604 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14605 </note>
14606 <orderedlist>
14607 <listitem><para>
14608 <emphasis>Make Your Changes Locally:</emphasis>
14609 Make your changes in your local Git repository.
14610 You should make small, controlled, isolated changes.
14611 Keeping changes small and isolated aids review,
14612 makes merging/rebasing easier and keeps the change
14613 history clean should anyone need to refer to it in
14614 future.
14615 </para></listitem>
14616 <listitem><para>
14617 <emphasis>Stage Your Changes:</emphasis>
14618 Stage your changes by using the <filename>git add</filename>
14619 command on each file you changed.
14620 </para></listitem>
14621 <listitem><para id='making-sure-you-have-correct-commit-information'>
14622 <emphasis>Commit Your Changes:</emphasis>
14623 Commit the change by using the
14624 <filename>git commit</filename> command.
14625 Make sure your commit information follows standards by
14626 following these accepted conventions:
14627 <itemizedlist>
14628 <listitem><para>
14629 Be sure to include a "Signed-off-by:" line in the
14630 same style as required by the Linux kernel.
14631 Adding this line signifies that you, the submitter,
14632 have agreed to the Developer's Certificate of
14633 Origin 1.1 as follows:
14634 <literallayout class='monospaced'>
14635 Developer's Certificate of Origin 1.1
14636
14637 By making a contribution to this project, I certify that:
14638
14639 (a) The contribution was created in whole or in part by me and I
14640 have the right to submit it under the open source license
14641 indicated in the file; or
14642
14643 (b) The contribution is based upon previous work that, to the best
14644 of my knowledge, is covered under an appropriate open source
14645 license and I have the right under that license to submit that
14646 work with modifications, whether created in whole or in part
14647 by me, under the same open source license (unless I am
14648 permitted to submit under a different license), as indicated
14649 in the file; or
14650
14651 (c) The contribution was provided directly to me by some other
14652 person who certified (a), (b) or (c) and I have not modified
14653 it.
14654
14655 (d) I understand and agree that this project and the contribution
14656 are public and that a record of the contribution (including all
14657 personal information I submit with it, including my sign-off) is
14658 maintained indefinitely and may be redistributed consistent with
14659 this project or the open source license(s) involved.
14660 </literallayout>
14661 </para></listitem>
14662 <listitem><para>
14663 Provide a single-line summary of the change.
14664 and,
14665 if more explanation is needed, provide more
14666 detail in the body of the commit.
14667 This summary is typically viewable in the
14668 "shortlist" of changes.
14669 Thus, providing something short and descriptive
14670 that gives the reader a summary of the change is
14671 useful when viewing a list of many commits.
14672 You should prefix this short description with the
14673 recipe name (if changing a recipe), or else with
14674 the short form path to the file being changed.
14675 </para></listitem>
14676 <listitem><para>
14677 For the body of the commit message, provide
14678 detailed information that describes what you
14679 changed, why you made the change, and the approach
14680 you used.
14681 It might also be helpful if you mention how you
14682 tested the change.
14683 Provide as much detail as you can in the body of
14684 the commit message.
14685 <note>
14686 You do not need to provide a more detailed
14687 explanation of a change if the change is
14688 minor to the point of the single line
14689 summary providing all the information.
14690 </note>
14691 </para></listitem>
14692 <listitem><para>
14693 If the change addresses a specific bug or issue
14694 that is associated with a bug-tracking ID,
14695 include a reference to that ID in your detailed
14696 description.
14697 For example, the Yocto Project uses a specific
14698 convention for bug references - any commit that
14699 addresses a specific bug should use the following
14700 form for the detailed description.
14701 Be sure to use the actual bug-tracking ID from
14702 Bugzilla for
14703 <replaceable>bug-id</replaceable>:
14704 <literallayout class='monospaced'>
14705 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14706
14707 <replaceable>detailed description of change</replaceable>
14708 </literallayout>
14709 </para></listitem>
14710 </itemizedlist>
14711 </para></listitem>
14712 <listitem><para>
14713 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14714 If you have arranged for permissions to push to an
14715 upstream contrib repository, push the change to that
14716 repository:
14717 <literallayout class='monospaced'>
14718 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14719 </literallayout>
14720 For example, suppose you have permissions to push into the
14721 upstream <filename>meta-intel-contrib</filename>
14722 repository and you are working in a local branch named
14723 <replaceable>your_name</replaceable><filename>/README</filename>.
14724 The following command pushes your local commits to the
14725 <filename>meta-intel-contrib</filename> upstream
14726 repository and puts the commit in a branch named
14727 <replaceable>your_name</replaceable><filename>/README</filename>:
14728 <literallayout class='monospaced'>
14729 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14730 </literallayout>
14731 </para></listitem>
14732 <listitem><para id='push-determine-who-to-notify'>
14733 <emphasis>Determine Who to Notify:</emphasis>
14734 Determine the maintainer or the mailing list
14735 that you need to notify for the change.</para>
14736
14737 <para>Before submitting any change, you need to be sure
14738 who the maintainer is or what mailing list that you need
14739 to notify.
14740 Use either these methods to find out:
14741 <itemizedlist>
14742 <listitem><para>
14743 <emphasis>Maintenance File:</emphasis>
14744 Examine the <filename>maintainers.inc</filename>
14745 file, which is located in the
14746 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14747 at
14748 <filename>meta/conf/distro/include</filename>,
14749 to see who is responsible for code.
14750 </para></listitem>
14751 <listitem><para>
14752 <emphasis>Search by File:</emphasis>
14753 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14754 you can enter the following command to bring up a
14755 short list of all commits against a specific file:
14756 <literallayout class='monospaced'>
14757 git shortlog -- <replaceable>filename</replaceable>
14758 </literallayout>
14759 Just provide the name of the file for which you
14760 are interested.
14761 The information returned is not ordered by history
14762 but does include a list of everyone who has
14763 committed grouped by name.
14764 From the list, you can see who is responsible for
14765 the bulk of the changes against the file.
14766 </para></listitem>
14767 <listitem><para>
14768 <emphasis>Examine the List of Mailing Lists:</emphasis>
14769 For a list of the Yocto Project and related mailing
14770 lists, see the
14771 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14772 section in the Yocto Project Reference Manual.
14773 </para></listitem>
14774 </itemizedlist>
14775 </para></listitem>
14776 <listitem><para>
14777 <emphasis>Make a Pull Request:</emphasis>
14778 Notify the maintainer or the mailing list that you have
14779 pushed a change by making a pull request.</para>
14780
14781 <para>The Yocto Project provides two scripts that
14782 conveniently let you generate and send pull requests to the
14783 Yocto Project.
14784 These scripts are <filename>create-pull-request</filename>
14785 and <filename>send-pull-request</filename>.
14786 You can find these scripts in the
14787 <filename>scripts</filename> directory within the
14788 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14789 (e.g. <filename>~/poky/scripts</filename>).
14790 </para>
14791
14792 <para>Using these scripts correctly formats the requests
14793 without introducing any whitespace or HTML formatting.
14794 The maintainer that receives your patches either directly
14795 or through the mailing list needs to be able to save and
14796 apply them directly from your emails.
14797 Using these scripts is the preferred method for sending
14798 patches.</para>
14799
14800 <para>First, create the pull request.
14801 For example, the following command runs the script,
14802 specifies the upstream repository in the contrib directory
14803 into which you pushed the change, and provides a subject
14804 line in the created patch files:
14805 <literallayout class='monospaced'>
14806 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14807 </literallayout>
14808 Running this script forms
14809 <filename>*.patch</filename> files in a folder named
14810 <filename>pull-</filename><replaceable>PID</replaceable>
14811 in the current directory.
14812 One of the patch files is a cover letter.</para>
14813
14814 <para>Before running the
14815 <filename>send-pull-request</filename> script, you must
14816 edit the cover letter patch to insert information about
14817 your change.
14818 After editing the cover letter, send the pull request.
14819 For example, the following command runs the script and
14820 specifies the patch directory and email address.
14821 In this example, the email address is a mailing list:
14822 <literallayout class='monospaced'>
14823 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14824 </literallayout>
14825 You need to follow the prompts as the script is
14826 interactive.
14827 <note>
14828 For help on using these scripts, simply provide the
14829 <filename>-h</filename> argument as follows:
14830 <literallayout class='monospaced'>
14831 $ poky/scripts/create-pull-request -h
14832 $ poky/scripts/send-pull-request -h
14833 </literallayout>
14834 </note>
14835 </para></listitem>
14836 </orderedlist>
14837 </para>
14838 </section>
14839
14840 <section id='submitting-a-patch'>
14841 <title>Using Email to Submit a Patch</title>
14842
14843 <para>
14844 You can submit patches without using the
14845 <filename>create-pull-request</filename> and
14846 <filename>send-pull-request</filename> scripts described in the
14847 previous section.
14848 However, keep in mind, the preferred method is to use the scripts.
14849 </para>
14850
14851 <para>
14852 Depending on the components changed, you need to submit the email
14853 to a specific mailing list.
14854 For some guidance on which mailing list to use, see the
14855 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14856 at the beginning of this section.
14857 For a description of all the available mailing lists, see the
14858 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14859 section in the Yocto Project Reference Manual.
14860 </para>
14861
14862 <para>
14863 Here is the general procedure on how to submit a patch through
14864 email without using the scripts:
14865 <orderedlist>
14866 <listitem><para>
14867 <emphasis>Make Your Changes Locally:</emphasis>
14868 Make your changes in your local Git repository.
14869 You should make small, controlled, isolated changes.
14870 Keeping changes small and isolated aids review,
14871 makes merging/rebasing easier and keeps the change
14872 history clean should anyone need to refer to it in
14873 future.
14874 </para></listitem>
14875 <listitem><para>
14876 <emphasis>Stage Your Changes:</emphasis>
14877 Stage your changes by using the <filename>git add</filename>
14878 command on each file you changed.
14879 </para></listitem>
14880 <listitem><para>
14881 <emphasis>Commit Your Changes:</emphasis>
14882 Commit the change by using the
14883 <filename>git commit --signoff</filename> command.
14884 Using the <filename>--signoff</filename> option identifies
14885 you as the person making the change and also satisfies
14886 the Developer's Certificate of Origin (DCO) shown earlier.
14887 </para>
14888
14889 <para>When you form a commit, you must follow certain
14890 standards established by the Yocto Project development
14891 team.
14892 See
14893 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14894 in the previous section for information on how to
14895 provide commit information that meets Yocto Project
14896 commit message standards.
14897 </para></listitem>
14898 <listitem><para>
14899 <emphasis>Format the Commit:</emphasis>
14900 Format the commit into an email message.
14901 To format commits, use the
14902 <filename>git format-patch</filename> command.
14903 When you provide the command, you must include a revision
14904 list or a number of patches as part of the command.
14905 For example, either of these two commands takes your most
14906 recent single commit and formats it as an email message in
14907 the current directory:
14908 <literallayout class='monospaced'>
14909 $ git format-patch -1
14910 </literallayout>
14911 or
14912 <literallayout class='monospaced'>
14913 $ git format-patch HEAD~
14914 </literallayout></para>
14915
14916 <para>After the command is run, the current directory
14917 contains a numbered <filename>.patch</filename> file for
14918 the commit.</para>
14919
14920 <para>If you provide several commits as part of the
14921 command, the <filename>git format-patch</filename> command
14922 produces a series of numbered files in the current
14923 directory – one for each commit.
14924 If you have more than one patch, you should also use the
14925 <filename>--cover</filename> option with the command,
14926 which generates a cover letter as the first "patch" in
14927 the series.
14928 You can then edit the cover letter to provide a
14929 description for the series of patches.
14930 For information on the
14931 <filename>git format-patch</filename> command,
14932 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14933 using the <filename>man git-format-patch</filename>
14934 command.
14935 <note>
14936 If you are or will be a frequent contributor to the
14937 Yocto Project or to OpenEmbedded, you might consider
14938 requesting a contrib area and the necessary associated
14939 rights.
14940 </note>
14941 </para></listitem>
14942 <listitem><para>
14943 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14944 Import the files into your mail client by using the
14945 <filename>git send-email</filename> command.
14946 <note>
14947 In order to use <filename>git send-email</filename>,
14948 you must have the proper Git packages installed on
14949 your host.
14950 For Ubuntu, Debian, and Fedora the package is
14951 <filename>git-email</filename>.
14952 </note></para>
14953
14954 <para>The <filename>git send-email</filename> command
14955 sends email by using a local or remote Mail Transport Agent
14956 (MTA) such as <filename>msmtp</filename>,
14957 <filename>sendmail</filename>, or through a direct
14958 <filename>smtp</filename> configuration in your Git
14959 <filename>~/.gitconfig</filename> file.
14960 If you are submitting patches through email only, it is
14961 very important that you submit them without any whitespace
14962 or HTML formatting that either you or your mailer
14963 introduces.
14964 The maintainer that receives your patches needs to be able
14965 to save and apply them directly from your emails.
14966 A good way to verify that what you are sending will be
14967 applicable by the maintainer is to do a dry run and send
14968 them to yourself and then save and apply them as the
14969 maintainer would.</para>
14970
14971 <para>The <filename>git send-email</filename> command is
14972 the preferred method for sending your patches using
14973 email since there is no risk of compromising whitespace
14974 in the body of the message, which can occur when you use
14975 your own mail client.
14976 The command also has several options that let you
14977 specify recipients and perform further editing of the
14978 email message.
14979 For information on how to use the
14980 <filename>git send-email</filename> command,
14981 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14982 the <filename>man git-send-email</filename> command.
14983 </para></listitem>
14984 </orderedlist>
14985 </para>
14986 </section>
14987 </section>
14988 </section>
14989
14990 <section id='working-with-licenses'>
14991 <title>Working With Licenses</title>
14992
14993 <para>
14994 As mentioned in the
14995 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
14996 section in the Yocto Project Overview and Concepts Manual,
14997 open source projects are open to the public and they
14998 consequently have different licensing structures in place.
14999 This section describes the mechanism by which the
15000 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
15001 tracks changes to licensing text and covers how to maintain open
15002 source license compliance during your project's lifecycle.
15003 The section also describes how to enable commercially licensed
15004 recipes, which by default are disabled.
15005 </para>
15006
15007 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
15008 <title>Tracking License Changes</title>
15009
15010 <para>
15011 The license of an upstream project might change in the future.
15012 In order to prevent these changes going unnoticed, the
15013 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
15014 variable tracks changes to the license text. The checksums are
15015 validated at the end of the configure step, and if the
15016 checksums do not match, the build will fail.
15017 </para>
15018
15019 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
15020 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
15021
15022 <para>
15023 The <filename>LIC_FILES_CHKSUM</filename>
15024 variable contains checksums of the license text in the
15025 source code for the recipe.
15026 Following is an example of how to specify
15027 <filename>LIC_FILES_CHKSUM</filename>:
15028 <literallayout class='monospaced'>
15029 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
15030 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
15031 file://licfile2.txt;endline=50;md5=zzzz \
15032 ..."
15033 </literallayout>
15034 <note><title>Notes</title>
15035 <itemizedlist>
15036 <listitem><para>
15037 When using "beginline" and "endline", realize
15038 that line numbering begins with one and not
15039 zero.
15040 Also, the included lines are inclusive (i.e.
15041 lines five through and including 29 in the
15042 previous example for
15043 <filename>licfile1.txt</filename>).
15044 </para></listitem>
15045 <listitem><para>
15046 When a license check fails, the selected license
15047 text is included as part of the QA message.
15048 Using this output, you can determine the exact
15049 start and finish for the needed license text.
15050 </para></listitem>
15051 </itemizedlist>
15052 </note>
15053 </para>
15054
15055 <para>
15056 The build system uses the
15057 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
15058 variable as the default directory when searching files
15059 listed in <filename>LIC_FILES_CHKSUM</filename>.
15060 The previous example employs the default directory.
15061 </para>
15062
15063 <para>
15064 Consider this next example:
15065 <literallayout class='monospaced'>
15066 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
15067 md5=bb14ed3c4cda583abc85401304b5cd4e"
15068 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
15069 </literallayout>
15070 </para>
15071
15072 <para>
15073 The first line locates a file in
15074 <filename>${S}/src/ls.c</filename> and isolates lines five
15075 through 16 as license text.
15076 The second line refers to a file in
15077 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
15078 </para>
15079
15080 <para>
15081 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
15082 mandatory for all recipes, unless the
15083 <filename>LICENSE</filename> variable is set to "CLOSED".
15084 </para>
15085 </section>
15086
15087 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
15088 <title>Explanation of Syntax</title>
15089
15090 <para>
15091 As mentioned in the previous section, the
15092 <filename>LIC_FILES_CHKSUM</filename> variable lists all
15093 the important files that contain the license text for the
15094 source code.
15095 It is possible to specify a checksum for an entire file,
15096 or a specific section of a file (specified by beginning and
15097 ending line numbers with the "beginline" and "endline"
15098 parameters, respectively).
15099 The latter is useful for source files with a license
15100 notice header, README documents, and so forth.
15101 If you do not use the "beginline" parameter, then it is
15102 assumed that the text begins on the first line of the file.
15103 Similarly, if you do not use the "endline" parameter,
15104 it is assumed that the license text ends with the last
15105 line of the file.
15106 </para>
15107
15108 <para>
15109 The "md5" parameter stores the md5 checksum of the license
15110 text.
15111 If the license text changes in any way as compared to
15112 this parameter then a mismatch occurs.
15113 This mismatch triggers a build failure and notifies
15114 the developer.
15115 Notification allows the developer to review and address
15116 the license text changes.
15117 Also note that if a mismatch occurs during the build,
15118 the correct md5 checksum is placed in the build log and
15119 can be easily copied to the recipe.
15120 </para>
15121
15122 <para>
15123 There is no limit to how many files you can specify using
15124 the <filename>LIC_FILES_CHKSUM</filename> variable.
15125 Generally, however, every project requires a few
15126 specifications for license tracking.
15127 Many projects have a "COPYING" file that stores the
15128 license information for all the source code files.
15129 This practice allows you to just track the "COPYING"
15130 file as long as it is kept up to date.
15131 <note><title>Tips</title>
15132 <itemizedlist>
15133 <listitem><para>
15134 If you specify an empty or invalid "md5"
15135 parameter,
15136 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
15137 returns an md5 mis-match
15138 error and displays the correct "md5" parameter
15139 value during the build.
15140 The correct parameter is also captured in
15141 the build log.
15142 </para></listitem>
15143 <listitem><para>
15144 If the whole file contains only license text,
15145 you do not need to use the "beginline" and
15146 "endline" parameters.
15147 </para></listitem>
15148 </itemizedlist>
15149 </note>
15150 </para>
15151 </section>
15152 </section>
15153
15154 <section id="enabling-commercially-licensed-recipes">
15155 <title>Enabling Commercially Licensed Recipes</title>
15156
15157 <para>
15158 By default, the OpenEmbedded build system disables
15159 components that have commercial or other special licensing
15160 requirements.
15161 Such requirements are defined on a
15162 recipe-by-recipe basis through the
15163 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
15164 variable definition in the affected recipe.
15165 For instance, the
15166 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15167 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015168 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015169 LICENSE_FLAGS = "commercial"
15170 </literallayout>
15171 Here is a slightly more complicated example that contains both
15172 an explicit recipe name and version (after variable expansion):
15173 <literallayout class='monospaced'>
15174 LICENSE_FLAGS = "license_${PN}_${PV}"
15175 </literallayout>
15176 In order for a component restricted by a
15177 <filename>LICENSE_FLAGS</filename> definition to be enabled and
15178 included in an image, it needs to have a matching entry in the
15179 global
15180 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
15181 variable, which is a variable typically defined in your
15182 <filename>local.conf</filename> file.
15183 For example, to enable the
15184 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15185 package, you could add either the string
15186 "commercial_gst-plugins-ugly" or the more general string
15187 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
15188 See the
15189 "<link linkend='license-flag-matching'>License Flag Matching</link>"
15190 section for a full
15191 explanation of how <filename>LICENSE_FLAGS</filename> matching
15192 works.
15193 Here is the example:
15194 <literallayout class='monospaced'>
15195 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
15196 </literallayout>
15197 Likewise, to additionally enable the package built from the
15198 recipe containing
15199 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
15200 and assuming that the actual recipe name was
15201 <filename>emgd_1.10.bb</filename>, the following string would
15202 enable that package as well as the original
15203 <filename>gst-plugins-ugly</filename> package:
15204 <literallayout class='monospaced'>
15205 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
15206 </literallayout>
15207 As a convenience, you do not need to specify the complete
15208 license string in the whitelist for every package.
15209 You can use an abbreviated form, which consists
15210 of just the first portion or portions of the license
15211 string before the initial underscore character or characters.
15212 A partial string will match any license that contains the
15213 given string as the first portion of its license.
15214 For example, the following whitelist string will also match
15215 both of the packages previously mentioned as well as any other
15216 packages that have licenses starting with "commercial" or
15217 "license".
15218 <literallayout class='monospaced'>
15219 LICENSE_FLAGS_WHITELIST = "commercial license"
15220 </literallayout>
15221 </para>
15222
15223 <section id="license-flag-matching">
15224 <title>License Flag Matching</title>
15225
15226 <para>
15227 License flag matching allows you to control what recipes
15228 the OpenEmbedded build system includes in the build.
15229 Fundamentally, the build system attempts to match
15230 <filename>LICENSE_FLAGS</filename> strings found in recipes
15231 against <filename>LICENSE_FLAGS_WHITELIST</filename>
15232 strings found in the whitelist.
15233 A match causes the build system to include a recipe in the
15234 build, while failure to find a match causes the build
15235 system to exclude a recipe.
15236 </para>
15237
15238 <para>
15239 In general, license flag matching is simple.
15240 However, understanding some concepts will help you
15241 correctly and effectively use matching.
15242 </para>
15243
15244 <para>
15245 Before a flag
15246 defined by a particular recipe is tested against the
15247 contents of the whitelist, the expanded string
15248 <filename>_${PN}</filename> is appended to the flag.
15249 This expansion makes each
15250 <filename>LICENSE_FLAGS</filename> value recipe-specific.
15251 After expansion, the string is then matched against the
15252 whitelist.
15253 Thus, specifying
15254 <filename>LICENSE_FLAGS = "commercial"</filename>
15255 in recipe "foo", for example, results in the string
15256 <filename>"commercial_foo"</filename>.
15257 And, to create a match, that string must appear in the
15258 whitelist.
15259 </para>
15260
15261 <para>
15262 Judicious use of the <filename>LICENSE_FLAGS</filename>
15263 strings and the contents of the
15264 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
15265 allows you a lot of flexibility for including or excluding
15266 recipes based on licensing.
15267 For example, you can broaden the matching capabilities by
15268 using license flags string subsets in the whitelist.
15269 <note>
15270 When using a string subset, be sure to use the part of
15271 the expanded string that precedes the appended
15272 underscore character (e.g.
15273 <filename>usethispart_1.3</filename>,
15274 <filename>usethispart_1.4</filename>, and so forth).
15275 </note>
15276 For example, simply specifying the string "commercial" in
15277 the whitelist matches any expanded
15278 <filename>LICENSE_FLAGS</filename> definition that starts
15279 with the string "commercial" such as "commercial_foo" and
15280 "commercial_bar", which are the strings the build system
15281 automatically generates for hypothetical recipes named
15282 "foo" and "bar" assuming those recipes simply specify the
15283 following:
15284 <literallayout class='monospaced'>
15285 LICENSE_FLAGS = "commercial"
15286 </literallayout>
15287 Thus, you can choose to exhaustively
15288 enumerate each license flag in the whitelist and
15289 allow only specific recipes into the image, or
15290 you can use a string subset that causes a broader range of
15291 matches to allow a range of recipes into the image.
15292 </para>
15293
15294 <para>
15295 This scheme works even if the
15296 <filename>LICENSE_FLAGS</filename> string already
15297 has <filename>_${PN}</filename> appended.
15298 For example, the build system turns the license flag
15299 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
15300 would match both the general "commercial" and the specific
15301 "commercial_1.2_foo" strings found in the whitelist, as
15302 expected.
15303 </para>
15304
15305 <para>
15306 Here are some other scenarios:
15307 <itemizedlist>
15308 <listitem><para>
15309 You can specify a versioned string in the recipe
15310 such as "commercial_foo_1.2" in a "foo" recipe.
15311 The build system expands this string to
15312 "commercial_foo_1.2_foo".
15313 Combine this license flag with a whitelist that has
15314 the string "commercial" and you match the flag
15315 along with any other flag that starts with the
15316 string "commercial".
15317 </para></listitem>
15318 <listitem><para>
15319 Under the same circumstances, you can use
15320 "commercial_foo" in the whitelist and the build
15321 system not only matches "commercial_foo_1.2" but
15322 also matches any license flag with the string
15323 "commercial_foo", regardless of the version.
15324 </para></listitem>
15325 <listitem><para>
15326 You can be very specific and use both the
15327 package and version parts in the whitelist (e.g.
15328 "commercial_foo_1.2") to specifically match a
15329 versioned recipe.
15330 </para></listitem>
15331 </itemizedlist>
15332 </para>
15333 </section>
15334
15335 <section id="other-variables-related-to-commercial-licenses">
15336 <title>Other Variables Related to Commercial Licenses</title>
15337
15338 <para>
15339 Other helpful variables related to commercial
15340 license handling exist and are defined in the
15341 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
15342 <literallayout class='monospaced'>
15343 COMMERCIAL_AUDIO_PLUGINS ?= ""
15344 COMMERCIAL_VIDEO_PLUGINS ?= ""
15345 </literallayout>
15346 If you want to enable these components, you can do so by
15347 making sure you have statements similar to the following
15348 in your <filename>local.conf</filename> configuration file:
15349 <literallayout class='monospaced'>
15350 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
15351 gst-plugins-ugly-mpegaudioparse"
15352 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
15353 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
15354 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
15355 </literallayout>
15356 Of course, you could also create a matching whitelist
15357 for those components using the more general "commercial"
15358 in the whitelist, but that would also enable all the
15359 other packages with <filename>LICENSE_FLAGS</filename>
15360 containing "commercial", which you may or may not want:
15361 <literallayout class='monospaced'>
15362 LICENSE_FLAGS_WHITELIST = "commercial"
15363 </literallayout>
15364 </para>
15365
15366 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040015367 Specifying audio and video plugins as part of the
Brad Bishop316dfdd2018-06-25 12:45:53 -040015368 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
15369 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
15370 (along with the enabling
15371 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
Brad Bishopc342db32019-05-15 21:57:59 -040015372 plugins or components into built images, thus adding
Brad Bishop316dfdd2018-06-25 12:45:53 -040015373 support for media formats or components.
15374 </para>
15375 </section>
15376 </section>
15377
15378 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
15379 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
15380
15381 <para>
15382 One of the concerns for a development organization using open source
15383 software is how to maintain compliance with various open source
15384 licensing during the lifecycle of the product.
15385 While this section does not provide legal advice or
15386 comprehensively cover all scenarios, it does
15387 present methods that you can use to
15388 assist you in meeting the compliance requirements during a software
15389 release.
15390 </para>
15391
15392 <para>
15393 With hundreds of different open source licenses that the Yocto
15394 Project tracks, it is difficult to know the requirements of each
15395 and every license.
15396 However, the requirements of the major FLOSS licenses can begin
15397 to be covered by
15398 assuming that three main areas of concern exist:
15399 <itemizedlist>
15400 <listitem><para>Source code must be provided.</para></listitem>
15401 <listitem><para>License text for the software must be
15402 provided.</para></listitem>
15403 <listitem><para>Compilation scripts and modifications to the
15404 source code must be provided.
15405 </para></listitem>
15406 </itemizedlist>
15407 There are other requirements beyond the scope of these
15408 three and the methods described in this section
15409 (e.g. the mechanism through which source code is distributed).
15410 </para>
15411
15412 <para>
15413 As different organizations have different methods of complying with
15414 open source licensing, this section is not meant to imply that
15415 there is only one single way to meet your compliance obligations,
15416 but rather to describe one method of achieving compliance.
15417 The remainder of this section describes methods supported to meet the
15418 previously mentioned three requirements.
15419 Once you take steps to meet these requirements,
15420 and prior to releasing images, sources, and the build system,
15421 you should audit all artifacts to ensure completeness.
15422 <note>
15423 The Yocto Project generates a license manifest during
15424 image creation that is located
15425 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
15426 to assist with any audits.
15427 </note>
15428 </para>
15429
15430 <section id='providing-the-source-code'>
15431 <title>Providing the Source Code</title>
15432
15433 <para>
15434 Compliance activities should begin before you generate the
15435 final image.
15436 The first thing you should look at is the requirement that
15437 tops the list for most compliance groups - providing
15438 the source.
15439 The Yocto Project has a few ways of meeting this
15440 requirement.
15441 </para>
15442
15443 <para>
15444 One of the easiest ways to meet this requirement is
15445 to provide the entire
15446 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
15447 used by the build.
15448 This method, however, has a few issues.
15449 The most obvious is the size of the directory since it includes
15450 all sources used in the build and not just the source used in
15451 the released image.
15452 It will include toolchain source, and other artifacts, which
15453 you would not generally release.
15454 However, the more serious issue for most companies is accidental
15455 release of proprietary software.
15456 The Yocto Project provides an
15457 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
15458 class to help avoid some of these concerns.
15459 </para>
15460
15461 <para>
15462 Before you employ <filename>DL_DIR</filename> or the
15463 <filename>archiver</filename> class, you need to decide how
15464 you choose to provide source.
15465 The source <filename>archiver</filename> class can generate
15466 tarballs and SRPMs and can create them with various levels of
15467 compliance in mind.
15468 </para>
15469
15470 <para>
15471 One way of doing this (but certainly not the only way) is to
15472 release just the source as a tarball.
15473 You can do this by adding the following to the
15474 <filename>local.conf</filename> file found in the
15475 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15476 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015477 INHERIT += "archiver"
15478 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015479 </literallayout>
15480 During the creation of your image, the source from all
15481 recipes that deploy packages to the image is placed within
15482 subdirectories of
15483 <filename>DEPLOY_DIR/sources</filename> based on the
15484 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15485 for each recipe.
15486 Releasing the entire directory enables you to comply with
15487 requirements concerning providing the unmodified source.
15488 It is important to note that the size of the directory can
15489 get large.
15490 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015491
Brad Bishop316dfdd2018-06-25 12:45:53 -040015492 <para>
15493 A way to help mitigate the size issue is to only release
15494 tarballs for licenses that require the release of
15495 source.
15496 Let us assume you are only concerned with GPL code as
15497 identified by running the following script:
15498 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015499 # Script to archive a subset of packages matching specific license(s)
15500 # Source and license files are copied into sub folders of package folder
15501 # Must be run from build folder
15502 #!/bin/bash
15503 src_release_dir="source-release"
15504 mkdir -p $src_release_dir
15505 for a in tmp/deploy/sources/*; do
15506 for d in $a/*; do
15507 # Get package name from path
15508 p=`basename $d`
15509 p=${p%-*}
15510 p=${p%-*}
15511 # Only archive GPL packages (update *GPL* regex for your license check)
15512 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15513 if [ $numfiles -gt 1 ]; then
15514 echo Archiving $p
15515 mkdir -p $src_release_dir/$p/source
15516 cp $d/* $src_release_dir/$p/source 2> /dev/null
15517 mkdir -p $src_release_dir/$p/license
15518 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15519 fi
15520 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015521 done
15522 </literallayout>
15523 At this point, you could create a tarball from the
15524 <filename>gpl_source_release</filename> directory and
15525 provide that to the end user.
15526 This method would be a step toward achieving compliance
15527 with section 3a of GPLv2 and with section 6 of GPLv3.
15528 </para>
15529 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015530
Brad Bishop316dfdd2018-06-25 12:45:53 -040015531 <section id='providing-license-text'>
15532 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015533
Brad Bishop316dfdd2018-06-25 12:45:53 -040015534 <para>
15535 One requirement that is often overlooked is inclusion
15536 of license text.
15537 This requirement also needs to be dealt with prior to
15538 generating the final image.
15539 Some licenses require the license text to accompany
15540 the binary.
15541 You can achieve this by adding the following to your
15542 <filename>local.conf</filename> file:
15543 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015544 COPY_LIC_MANIFEST = "1"
15545 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015546 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015547 </literallayout>
15548 Adding these statements to the configuration file ensures
15549 that the licenses collected during package generation
15550 are included on your image.
15551 <note>
15552 <para>Setting all three variables to "1" results in the
15553 image having two copies of the same license file.
15554 One copy resides in
15555 <filename>/usr/share/common-licenses</filename> and
15556 the other resides in
15557 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015558
Brad Bishop316dfdd2018-06-25 12:45:53 -040015559 <para>The reason for this behavior is because
15560 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15561 and
15562 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15563 add a copy of the license when the image is built but do
15564 not offer a path for adding licenses for newly installed
15565 packages to an image.
15566 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15567 adds a separate package and an upgrade path for adding
15568 licenses to an image.</para>
15569 </note>
15570 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015571
Brad Bishop316dfdd2018-06-25 12:45:53 -040015572 <para>
15573 As the source <filename>archiver</filename> class has already
15574 archived the original
15575 unmodified source that contains the license files,
15576 you would have already met the requirements for inclusion
15577 of the license information with source as defined by the GPL
15578 and other open source licenses.
15579 </para>
15580 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015581
Brad Bishop316dfdd2018-06-25 12:45:53 -040015582 <section id='providing-compilation-scripts-and-source-code-modifications'>
15583 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015584
Brad Bishop316dfdd2018-06-25 12:45:53 -040015585 <para>
15586 At this point, we have addressed all we need to
15587 prior to generating the image.
15588 The next two requirements are addressed during the final
15589 packaging of the release.
15590 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015591
Brad Bishop316dfdd2018-06-25 12:45:53 -040015592 <para>
15593 By releasing the version of the OpenEmbedded build system
15594 and the layers used during the build, you will be providing both
15595 compilation scripts and the source code modifications in one
15596 step.
15597 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015598
Brad Bishop316dfdd2018-06-25 12:45:53 -040015599 <para>
15600 If the deployment team has a
15601 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15602 and a distro layer, and those those layers are used to patch,
15603 compile, package, or modify (in any way) any open source
15604 software included in your released images, you
15605 might be required to release those layers under section 3 of
15606 GPLv2 or section 1 of GPLv3.
15607 One way of doing that is with a clean
15608 checkout of the version of the Yocto Project and layers used
15609 during your build.
15610 Here is an example:
15611 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015612 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15613 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015614 $ cd poky
15615 # We built using the release_branch for our layers
15616 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15617 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15618 # clean up the .git repos
15619 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015620 </literallayout>
15621 One thing a development organization might want to consider
15622 for end-user convenience is to modify
15623 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15624 ensure that when the end user utilizes the released build
15625 system to build an image, the development organization's
15626 layers are included in the <filename>bblayers.conf</filename>
15627 file automatically:
15628 <literallayout class='monospaced'>
15629 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015630 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015631 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015632
15633 BBPATH = "${TOPDIR}"
15634 BBFILES ?= ""
15635
15636 BBLAYERS ?= " \
15637 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015638 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015639 ##OEROOT##/meta-yocto-bsp \
15640 ##OEROOT##/meta-mylayer \
15641 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015642 </literallayout>
15643 Creating and providing an archive of the
15644 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15645 layers (recipes, configuration files, and so forth)
15646 enables you to meet your
15647 requirements to include the scripts to control compilation
15648 as well as any modifications to the original source.
15649 </para>
15650 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015651 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015652
15653 <section id='copying-licenses-that-do-not-exist'>
15654 <title>Copying Licenses that Do Not Exist</title>
15655
15656 <para>
15657 Some packages, such as the linux-firmware package, have many
15658 licenses that are not in any way common.
15659 You can avoid adding a lot of these types of common license
15660 files, which are only applicable to a specific package, by using
15661 the
15662 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15663 variable.
15664 Using this variable also avoids QA errors when you use a
15665 non-common, non-CLOSED license in a recipe.
15666 </para>
15667
15668 <para>
15669 The following is an example that uses the
15670 <filename>LICENSE.Abilis.txt</filename>
15671 file as the license from the fetched source:
15672 <literallayout class='monospaced'>
15673 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15674 </literallayout>
15675 </para>
15676 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015677 </section>
15678
15679 <section id='using-the-error-reporting-tool'>
15680 <title>Using the Error Reporting Tool</title>
15681
15682 <para>
15683 The error reporting tool allows you to
15684 submit errors encountered during builds to a central database.
15685 Outside of the build environment, you can use a web interface to
15686 browse errors, view statistics, and query for errors.
15687 The tool works using a client-server system where the client
15688 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015689 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015690 (e.g. <filename>poky</filename>).
15691 The server receives the information collected and saves it in a
15692 database.
15693 </para>
15694
15695 <para>
15696 A live instance of the error reporting server exists at
15697 <ulink url='http://errors.yoctoproject.org'></ulink>.
15698 This server exists so that when you want to get help with
15699 build failures, you can submit all of the information on the
15700 failure easily and then point to the URL in your bug report
15701 or send an email to the mailing list.
15702 <note>
15703 If you send error reports to this server, the reports become
15704 publicly visible.
15705 </note>
15706 </para>
15707
15708 <section id='enabling-and-using-the-tool'>
15709 <title>Enabling and Using the Tool</title>
15710
15711 <para>
15712 By default, the error reporting tool is disabled.
15713 You can enable it by inheriting the
15714 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15715 class by adding the following statement to the end of
15716 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015717 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015718 <literallayout class='monospaced'>
15719 INHERIT += "report-error"
15720 </literallayout>
15721 </para>
15722
15723 <para>
15724 By default, the error reporting feature stores information in
15725 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15726 However, you can specify a directory to use by adding the following
15727 to your <filename>local.conf</filename> file:
15728 <literallayout class='monospaced'>
15729 ERR_REPORT_DIR = "path"
15730 </literallayout>
15731 Enabling error reporting causes the build process to collect
15732 the errors and store them in a file as previously described.
15733 When the build system encounters an error, it includes a
15734 command as part of the console output.
15735 You can run the command to send the error file to the server.
15736 For example, the following command sends the errors to an
15737 upstream server:
15738 <literallayout class='monospaced'>
15739 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15740 </literallayout>
15741 In the previous example, the errors are sent to a public
15742 database available at
15743 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15744 used by the entire community.
15745 If you specify a particular server, you can send the errors
15746 to a different database.
15747 Use the following command for more information on available
15748 options:
15749 <literallayout class='monospaced'>
15750 $ send-error-report --help
15751 </literallayout>
15752 </para>
15753
15754 <para>
15755 When sending the error file, you are prompted to review the
15756 data being sent as well as to provide a name and optional
15757 email address.
15758 Once you satisfy these prompts, the command returns a link
15759 from the server that corresponds to your entry in the database.
15760 For example, here is a typical link:
15761 <literallayout class='monospaced'>
15762 http://errors.yoctoproject.org/Errors/Details/9522/
15763 </literallayout>
15764 Following the link takes you to a web interface where you can
15765 browse, query the errors, and view statistics.
15766 </para>
15767 </section>
15768
15769 <section id='disabling-the-tool'>
15770 <title>Disabling the Tool</title>
15771
15772 <para>
15773 To disable the error reporting feature, simply remove or comment
15774 out the following statement from the end of your
15775 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015776 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015777 <literallayout class='monospaced'>
15778 INHERIT += "report-error"
15779 </literallayout>
15780 </para>
15781 </section>
15782
15783 <section id='setting-up-your-own-error-reporting-server'>
15784 <title>Setting Up Your Own Error Reporting Server</title>
15785
15786 <para>
15787 If you want to set up your own error reporting server, you
15788 can obtain the code from the Git repository at
15789 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15790 Instructions on how to set it up are in the README document.
15791 </para>
15792 </section>
15793 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015794
15795 <section id="dev-using-wayland-and-weston">
15796 <title>Using Wayland and Weston</title>
15797
15798 <para>
15799 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15800 is a computer display server protocol that
15801 provides a method for compositing window managers to communicate
15802 directly with applications and video hardware and expects them to
15803 communicate with input hardware using other libraries.
15804 Using Wayland with supporting targets can result in better control
15805 over graphics frame rendering than an application might otherwise
15806 achieve.
15807 </para>
15808
15809 <para>
15810 The Yocto Project provides the Wayland protocol libraries and the
15811 reference
15812 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15813 compositor as part of its release.
15814 You can find the integrated packages in the
15815 <filename>meta</filename> layer of the
15816 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15817 Specifically, you can find the recipes that build both Wayland
15818 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15819 </para>
15820
15821 <para>
15822 You can build both the Wayland and Weston packages for use only
15823 with targets that accept the
15824 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15825 which is also known as Mesa DRI.
15826 This implies that you cannot build and use the packages if your
15827 target uses, for example, the
15828 <trademark class='registered'>Intel</trademark> Embedded Media
15829 and Graphics Driver
15830 (<trademark class='registered'>Intel</trademark> EMGD) that
15831 overrides Mesa DRI.
15832 <note>
15833 Due to lack of EGL support, Weston 1.0.3 will not run
15834 directly on the emulated QEMU hardware.
15835 However, this version of Weston will run under X emulation
15836 without issues.
15837 </note>
15838 </para>
15839
15840 <para>
15841 This section describes what you need to do to implement Wayland and
15842 use the Weston compositor when building an image for a supporting
15843 target.
15844 </para>
15845
15846 <section id="enabling-wayland-in-an-image">
15847 <title>Enabling Wayland in an Image</title>
15848
15849 <para>
15850 To enable Wayland, you need to enable it to be built and enable
15851 it to be included (installed) in the image.
15852 </para>
15853
15854 <section id="enable-building">
15855 <title>Building</title>
15856
15857 <para>
15858 To cause Mesa to build the <filename>wayland-egl</filename>
15859 platform and Weston to build Wayland with Kernel Mode
15860 Setting
15861 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15862 support, include the "wayland" flag in the
15863 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15864 statement in your <filename>local.conf</filename> file:
15865 <literallayout class='monospaced'>
15866 DISTRO_FEATURES_append = " wayland"
15867 </literallayout>
15868 <note>
15869 If X11 has been enabled elsewhere, Weston will build
15870 Wayland with X11 support
15871 </note>
15872 </para>
15873 </section>
15874
15875 <section id="enable-installation-in-an-image">
15876 <title>Installing</title>
15877
15878 <para>
15879 To install the Wayland feature into an image, you must
15880 include the following
15881 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15882 statement in your <filename>local.conf</filename> file:
15883 <literallayout class='monospaced'>
15884 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15885 </literallayout>
15886 </para>
15887 </section>
15888 </section>
15889
15890 <section id="running-weston">
15891 <title>Running Weston</title>
15892
15893 <para>
15894 To run Weston inside X11, enabling it as described earlier and
15895 building a Sato image is sufficient.
15896 If you are running your image under Sato, a Weston Launcher
15897 appears in the "Utility" category.
15898 </para>
15899
15900 <para>
15901 Alternatively, you can run Weston through the command-line
15902 interpretor (CLI), which is better suited for development work.
15903 To run Weston under the CLI, you need to do the following after
15904 your image is built:
15905 <orderedlist>
15906 <listitem><para>
15907 Run these commands to export
15908 <filename>XDG_RUNTIME_DIR</filename>:
15909 <literallayout class='monospaced'>
15910 mkdir -p /tmp/$USER-weston
15911 chmod 0700 /tmp/$USER-weston
15912 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15913 </literallayout>
15914 </para></listitem>
15915 <listitem><para>
15916 Launch Weston in the shell:
15917 <literallayout class='monospaced'>
15918 weston
15919 </literallayout></para></listitem>
15920 </orderedlist>
15921 </para>
15922 </section>
15923 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015924</chapter>
15925
15926<!--
15927vim: expandtab tw=80 ts=4
15928-->