blob: c75e718d678b117e8b9c8fe2fc355353818831d1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='extendpoky'>
6
7<title>Common Tasks</title>
8 <para>
9 This chapter describes fundamental procedures such as creating layers,
10 adding new software packages, extending or customizing images,
11 porting work to new hardware (adding a new machine), and so forth.
12 You will find that the procedures documented here occur often in the
13 development cycle using the Yocto Project.
14 </para>
15
16 <section id="understanding-and-creating-layers">
17 <title>Understanding and Creating Layers</title>
18
19 <para>
20 The OpenEmbedded build system supports organizing
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> into
22 multiple layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 Layers allow you to isolate different types of customizations from
24 each other.
Brad Bishop316dfdd2018-06-25 12:45:53 -040025 For introductory information on the Yocto Project Layer Model,
26 see the
27 "<ulink url='&YOCTO_DOCS_OM_URL;#the-yocto-project-layer-model'>The Yocto Project Layer Model</ulink>"
28 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 </para>
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 <section id='creating-your-own-layer'>
32 <title>Creating Your Own Layer</title>
33
34 <para>
35 It is very easy to create your own layers to use with the
36 OpenEmbedded build system.
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 The Yocto Project ships with tools that speed up creating
38 layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 This section describes the steps you perform by hand to create
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 layers so that you can better understand them.
41 For information about the layer-creation tools, see the
42 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 section in the Yocto Project Board Support Package (BSP)
44 Developer's Guide and the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 section further down in this manual.
47 </para>
48
49 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040050 Follow these general steps to create your layer without using
51 tools:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 <orderedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -040053 <listitem><para>
54 <emphasis>Check Existing Layers:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 Before creating a new layer, you should be sure someone
56 has not already created a layer containing the Metadata
57 you need.
58 You can see the
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 <ulink url='http://layers.openembedded.org/layerindex/layers/'>OpenEmbedded Metadata Index</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 for a list of layers from the OpenEmbedded community
61 that can be used in the Yocto Project.
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 You could find a layer that is identical or close to
63 what you need.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 <listitem><para>
66 <emphasis>Create a Directory:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 Create the directory for your layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -040068 When you create the layer, be sure to create the
69 directory in an area not associated with the
70 Yocto Project
71 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
72 (e.g. the cloned <filename>poky</filename> repository).
73 </para>
74
75 <para>While not strictly required, prepend the name of
76 the directory with the string "meta-".
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 For example:
78 <literallayout class='monospaced'>
79 meta-mylayer
80 meta-GUI_xyz
81 meta-mymachine
82 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040083 With rare exceptions, a layer's name follows this
84 form:
85 <literallayout class='monospaced'>
86 meta-<replaceable>root_name</replaceable>
87 </literallayout>
88 Following this layer naming convention can
89 save you trouble later when tools, components, or
90 variables "assume" your layer name begins with "meta-".
91 A notable example is in configuration files as
92 shown in the following step where layer names without
93 the "meta-" string are appended
94 to several variables used in the configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 <listitem><para id='dev-layer-config-file-description'>
97 <emphasis>Create a Layer Configuration File:</emphasis>
98 Inside your new layer folder, you need to create a
99 <filename>conf/layer.conf</filename> file.
100 It is easiest to take an existing layer configuration
101 file and copy that to your layer's
102 <filename>conf</filename> directory and then modify the
103 file as needed.</para>
104
105 <para>The
106 <filename>meta-yocto-bsp/conf/layer.conf</filename> file
107 in the Yocto Project
108 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf'>Source Repositories</ulink>
109 demonstrates the required syntax.
110 For your layer, you need to replace "yoctobsp" with
111 a unique identifier for your layer (e.g. "machinexyz"
112 for a layer named "meta-machinexyz"):
113 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 # We have a conf and classes directory, add to BBPATH
115 BBPATH .= ":${LAYERDIR}"
116
117 # We have recipes-* directories, add to BBFILES
118 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
119 ${LAYERDIR}/recipes-*/*/*.bbappend"
120
121 BBFILE_COLLECTIONS += "yoctobsp"
122 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
123 BBFILE_PRIORITY_yoctobsp = "5"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 LAYERVERSION_yoctobsp = "4"
125 LAYERSERIES_COMPAT_yoctobsp = "&DISTRO_NAME_NO_CAP;"
126 </literallayout>
127 Following is an explanation of the layer configuration
128 file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130 <listitem><para>
131 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>:
132 Adds the layer's root directory to BitBake's
133 search path.
134 Through the use of the
135 <filename>BBPATH</filename> variable, BitBake
136 locates class files
137 (<filename>.bbclass</filename>),
138 configuration files, and files that are
139 included with <filename>include</filename> and
140 <filename>require</filename> statements.
141 For these cases, BitBake uses the first file
142 that matches the name found in
143 <filename>BBPATH</filename>.
144 This is similar to the way the
145 <filename>PATH</filename> variable is used for
146 binaries.
147 It is recommended, therefore, that you use
148 unique class and configuration filenames in
149 your custom layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400151 <listitem><para>
152 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>:
153 Defines the location for all recipes in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155 </para></listitem>
156 <listitem><para>
157 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'><filename>BBFILE_COLLECTIONS</filename></ulink>:
158 Establishes the current layer through a
159 unique identifier that is used throughout the
160 OpenEmbedded build system to refer to the layer.
161 In this example, the identifier "yoctobsp" is
162 the representation for the container layer
163 named "meta-yocto-bsp".
164 </para></listitem>
165 <listitem><para>
166 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'><filename>BBFILE_PATTERN</filename></ulink>:
167 Expands immediately during parsing to
168 provide the directory of the layer.
169 </para></listitem>
170 <listitem><para>
171 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>:
172 Establishes a priority to use for
173 recipes in the layer when the OpenEmbedded build
174 finds recipes of the same name in different
175 layers.
176 </para></listitem>
177 <listitem><para>
178 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'><filename>LAYERVERSION</filename></ulink>:
179 Establishes a version number for the layer.
180 You can use this version number to specify this
181 exact version of the layer as a dependency when
182 using the
183 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDEPENDS'><filename>LAYERDEPENDS</filename></ulink>
184 variable.
185 </para></listitem>
186 <listitem><para>
187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERSERIES_COMPAT'><filename>LAYERSERIES_COMPAT</filename></ulink>:
188 Lists the
189 <ulink url='&YOCTO_WIKI_URL;/wiki/Releases'>Yocto Project</ulink>
190 releases for which the current version is
191 compatible.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800192 This variable is a good way to indicate if
193 your particular layer is current.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194 </para></listitem>
195 </itemizedlist>
196 </para></listitem>
197 <listitem><para>
198 <emphasis>Add Content:</emphasis>
199 Depending on the type of layer, add the content.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 If the layer adds support for a machine, add the machine
201 configuration in a <filename>conf/machine/</filename>
202 file within the layer.
203 If the layer adds distro policy, add the distro
204 configuration in a <filename>conf/distro/</filename>
205 file within the layer.
206 If the layer introduces new recipes, put the recipes
207 you need in <filename>recipes-*</filename>
208 subdirectories within the layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400209 <note>
210 For an explanation of layer hierarchy that
211 is compliant with the Yocto Project, see
212 the
213 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout'>Example Filesystem Layout</ulink>"
214 section in the Yocto Project Board
215 Support Package (BSP) Developer's Guide.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 </note>
217 </para></listitem>
218 <listitem><para>
219 <emphasis>Optionally Test for Compatibility:</emphasis>
220 If you want permission to use the Yocto Project
221 Compatibility logo with your layer or application that
222 uses your layer, perform the steps to apply for
223 compatibility.
224 See the
225 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
226 section for more information.
227 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 </orderedlist>
229 </para>
230 </section>
231
232 <section id='best-practices-to-follow-when-creating-layers'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500233 <title>Following Best Practices When Creating Layers</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234
235 <para>
236 To create layers that are easier to maintain and that will
237 not impact builds for other machines, you should consider the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 information in the following list:
239 <itemizedlist>
240 <listitem><para>
241 <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis>
242 In other words, do not copy an entire recipe into your
243 layer and then modify it.
244 Rather, use an append file
245 (<filename>.bbappend</filename>) to override only those
246 parts of the original recipe you need to modify.
247 </para></listitem>
248 <listitem><para>
249 <emphasis>Avoid Duplicating Include Files:</emphasis>
250 Use append files (<filename>.bbappend</filename>)
251 for each recipe that uses an include file.
252 Or, if you are introducing a new recipe that requires
253 the included file, use the path relative to the
254 original layer directory to refer to the file.
255 For example, use
256 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
257 instead of
258 <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
259 If you're finding you have to overlay the include file,
260 it could indicate a deficiency in the include file in
261 the layer to which it originally belongs.
262 If this is the case, you should try to address that
263 deficiency instead of overlaying the include file.
264 For example, you could address this by getting the
265 maintainer of the include file to add a variable or
266 variables to make it easy to override the parts needing
267 to be overridden.
268 </para></listitem>
269 <listitem><para>
270 <emphasis>Structure Your Layers:</emphasis>
271 Proper use of overrides within append files and
272 placement of machine-specific files within your layer
273 can ensure that a build is not using the wrong Metadata
274 and negatively impacting a build for a different
275 machine.
276 Following are some examples:
277 <itemizedlist>
278 <listitem><para>
279 <emphasis>Modify Variables to Support a
280 Different Machine:</emphasis>
281 Suppose you have a layer named
282 <filename>meta-one</filename> that adds support
283 for building machine "one".
284 To do so, you use an append file named
285 <filename>base-files.bbappend</filename> and
286 create a dependency on "foo" by altering the
287 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
288 variable:
289 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 DEPENDS = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 </literallayout>
292 The dependency is created during any build that
293 includes the layer
294 <filename>meta-one</filename>.
295 However, you might not want this dependency
296 for all machines.
297 For example, suppose you are building for
298 machine "two" but your
299 <filename>bblayers.conf</filename> file has the
300 <filename>meta-one</filename> layer included.
301 During the build, the
302 <filename>base-files</filename> for machine
303 "two" will also have the dependency on
304 <filename>foo</filename>.</para>
305 <para>To make sure your changes apply only when
306 building machine "one", use a machine override
307 with the <filename>DEPENDS</filename> statement:
308 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 DEPENDS_one = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500310 </literallayout>
311 You should follow the same strategy when using
312 <filename>_append</filename> and
313 <filename>_prepend</filename> operations:
314 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 DEPENDS_append_one = " foo"
316 DEPENDS_prepend_one = "foo "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 </literallayout>
318 As an actual example, here's a line from the recipe
319 for gnutls, which adds dependencies on
320 "argp-standalone" when building with the musl C
321 library:
322 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323 DEPENDS_append_libc-musl = " argp-standalone"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500324 </literallayout>
325 <note>
326 Avoiding "+=" and "=+" and using
327 machine-specific
328 <filename>_append</filename>
329 and <filename>_prepend</filename> operations
330 is recommended as well.
331 </note>
332 </para></listitem>
333 <listitem><para>
334 <emphasis>Place Machine-Specific Files in
335 Machine-Specific Locations:</emphasis>
336 When you have a base recipe, such as
337 <filename>base-files.bb</filename>, that
338 contains a
339 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
340 statement to a file, you can use an append file
341 to cause the build to use your own version of
342 the file.
343 For example, an append file in your layer at
344 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
345 could extend
346 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
347 using
348 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
349 as follows:
350 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352 </literallayout>
353 The build for machine "one" will pick up your
354 machine-specific file as long as you have the
355 file in
356 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
357 However, if you are building for a different
358 machine and the
359 <filename>bblayers.conf</filename> file includes
360 the <filename>meta-one</filename> layer and
361 the location of your machine-specific file is
362 the first location where that file is found
363 according to <filename>FILESPATH</filename>,
364 builds for all machines will also use that
365 machine-specific file.</para>
366 <para>You can make sure that a machine-specific
367 file is used for a particular machine by putting
368 the file in a subdirectory specific to the
369 machine.
370 For example, rather than placing the file in
371 <filename>meta-one/recipes-core/base-files/base-files/</filename>
372 as shown above, put it in
373 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
374 Not only does this make sure the file is used
375 only when building for machine "one", but the
376 build process locates the file more quickly.</para>
377 <para>In summary, you need to place all files
378 referenced from <filename>SRC_URI</filename>
379 in a machine-specific subdirectory within the
380 layer in order to restrict those files to
381 machine-specific builds.
382 </para></listitem>
383 </itemizedlist>
384 </para></listitem>
385 <listitem><para>
386 <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis>
387 If you want permission to use the
388 Yocto Project Compatibility logo with your layer
389 or application that uses your layer, perform the
390 steps to apply for compatibility.
391 See the
392 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
393 section for more information.
394 </para></listitem>
395 <listitem><para>
396 <emphasis>Follow the Layer Naming Convention:</emphasis>
397 Store custom layers in a Git repository that use the
398 <filename>meta-<replaceable>layer_name</replaceable></filename>
399 format.
400 </para></listitem>
401 <listitem><para>
402 <emphasis>Group Your Layers Locally:</emphasis>
403 Clone your repository alongside other cloned
404 <filename>meta</filename> directories from the
405 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
406 </para></listitem>
407 </itemizedlist>
408 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 </section>
410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 <section id='making-sure-your-layer-is-compatible-with-yocto-project'>
412 <title>Making Sure Your Layer is Compatible With Yocto Project</title>
413
414 <para>
415 When you create a layer used with the Yocto Project, it is
416 advantageous to make sure that the layer interacts well with
417 existing Yocto Project layers (i.e. the layer is compatible
418 with the Yocto Project).
419 Ensuring compatibility makes the layer easy to be consumed
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500420 by others in the Yocto Project community and could allow you
421 permission to use the Yocto Project Compatible Logo.
422 <note>
423 Only Yocto Project member organizations are permitted to
424 use the Yocto Project Compatible Logo.
425 The logo is not available for general use.
426 For information on how to become a Yocto Project member
427 organization, see the
428 <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500429 </note>
430 </para>
431
432 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500433 The Yocto Project Compatibility Program consists of a layer
434 application process that requests permission to use the Yocto
435 Project Compatibility Logo for your layer and application.
436 The process consists of two parts:
437 <orderedlist>
438 <listitem><para>
439 Successfully passing a script
440 (<filename>yocto-check-layer</filename>) that
441 when run against your layer, tests it against
442 constraints based on experiences of how layers have
443 worked in the real world and where pitfalls have been
444 found.
445 Getting a "PASS" result from the script is required for
446 successful compatibility registration.
447 </para></listitem>
448 <listitem><para>
449 Completion of an application acceptance form, which
450 you can find at
451 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
452 </para></listitem>
453 </orderedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 </para>
455
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 <para>
457 To be granted permission to use the logo, you need to satisfy
458 the following:
459 <itemizedlist>
460 <listitem><para>
461 Be able to check the box indicating that you
462 got a "PASS" when running the script against your
463 layer.
464 </para></listitem>
465 <listitem><para>
466 Answer "Yes" to the questions on the form or have an
467 acceptable explanation for any questions answered "No".
468 </para></listitem>
469 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400470 Be a Yocto Project Member Organization.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500471 </para></listitem>
472 </itemizedlist>
473 </para>
474
475 <para>
476 The remainder of this section presents information on the
477 registration form and on the
478 <filename>yocto-check-layer</filename> script.
479 </para>
480
481 <section id='yocto-project-compatible-program-application'>
482 <title>Yocto Project Compatible Program Application</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483
484 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500485 Use the form to apply for your layer's approval.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486 Upon successful application, you can use the Yocto
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500487 Project Compatibility Logo with your layer and the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 application that uses your layer.
489 </para>
490
491 <para>
492 To access the form, use this link:
493 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
494 Follow the instructions on the form to complete your
495 application.
496 </para>
497
498 <para>
499 The application consists of the following sections:
500 <itemizedlist>
501 <listitem><para>
502 <emphasis>Contact Information:</emphasis>
503 Provide your contact information as the fields
504 require.
505 Along with your information, provide the
506 released versions of the Yocto Project for which
507 your layer is compatible.
508 </para></listitem>
509 <listitem><para>
510 <emphasis>Acceptance Criteria:</emphasis>
511 Provide "Yes" or "No" answers for each of the
512 items in the checklist.
513 Space exists at the bottom of the form for any
514 explanations for items for which you answered "No".
515 </para></listitem>
516 <listitem><para>
517 <emphasis>Recommendations:</emphasis>
518 Provide answers for the questions regarding Linux
519 kernel use and build success.
520 </para></listitem>
521 </itemizedlist>
522 </para>
523 </section>
524
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500525 <section id='yocto-check-layer-script'>
526 <title><filename>yocto-check-layer</filename> Script</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527
528 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500529 The <filename>yocto-check-layer</filename> script
530 provides you a way to assess how compatible your layer is
531 with the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500532 You should run this script prior to using the form to
533 apply for compatibility as described in the previous
534 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500535 You need to achieve a "PASS" result in order to have
536 your application form successfully processed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 </para>
538
539 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400540 The script divides tests into three areas: COMMON, BSP,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500541 and DISTRO.
542 For example, given a distribution layer (DISTRO), the
543 layer must pass both the COMMON and DISTRO related tests.
544 Furthermore, if your layer is a BSP layer, the layer must
545 pass the COMMON and BSP set of tests.
546 </para>
547
548 <para>
549 To execute the script, enter the following commands from
550 your build directory:
551 <literallayout class='monospaced'>
552 $ source oe-init-build-env
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 $ yocto-check-layer <replaceable>your_layer_directory</replaceable>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500554 </literallayout>
555 Be sure to provide the actual directory for your layer
556 as part of the command.
557 </para>
558
559 <para>
560 Entering the command causes the script to determine the
561 type of layer and then to execute a set of specific
562 tests against the layer.
563 The following list overviews the test:
564 <itemizedlist>
565 <listitem><para>
566 <filename>common.test_readme</filename>:
567 Tests if a <filename>README</filename> file
568 exists in the layer and the file is not empty.
569 </para></listitem>
570 <listitem><para>
571 <filename>common.test_parse</filename>:
572 Tests to make sure that BitBake can parse the
573 files without error (i.e.
574 <filename>bitbake -p</filename>).
575 </para></listitem>
576 <listitem><para>
577 <filename>common.test_show_environment</filename>:
578 Tests that the global or per-recipe environment
579 is in order without errors (i.e.
580 <filename>bitbake -e</filename>).
581 </para></listitem>
582 <listitem><para>
583 <filename>common.test_signatures</filename>:
584 Tests to be sure that BSP and DISTRO layers do not
585 come with recipes that change signatures.
586 </para></listitem>
587 <listitem><para>
588 <filename>bsp.test_bsp_defines_machines</filename>:
589 Tests if a BSP layer has machine configurations.
590 </para></listitem>
591 <listitem><para>
592 <filename>bsp.test_bsp_no_set_machine</filename>:
593 Tests to ensure a BSP layer does not set the
594 machine when the layer is added.
595 </para></listitem>
596 <listitem><para>
597 <filename>distro.test_distro_defines_distros</filename>:
598 Tests if a DISTRO layer has distro configurations.
599 </para></listitem>
600 <listitem><para>
601 <filename>distro.test_distro_no_set_distro</filename>:
602 Tests to ensure a DISTRO layer does not set the
603 distribution when the layer is added.
604 </para></listitem>
605 </itemizedlist>
606 </para>
607 </section>
608 </section>
609
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610 <section id='enabling-your-layer'>
611 <title>Enabling Your Layer</title>
612
613 <para>
614 Before the OpenEmbedded build system can use your new layer,
615 you need to enable it.
616 To enable your layer, simply add your layer's path to the
617 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
618 variable in your <filename>conf/bblayers.conf</filename> file,
619 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 The following example shows how to enable a layer named
622 <filename>meta-mylayer</filename>:
623 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400624 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
625 # changes incompatibly
626 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627
628 BBPATH = "${TOPDIR}"
629 BBFILES ?= ""
630
631 BBLAYERS ?= " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400632 /home/<replaceable>user</replaceable>/poky/meta \
633 /home/<replaceable>user</replaceable>/poky/meta-poky \
634 /home/<replaceable>user</replaceable>/poky/meta-yocto-bsp \
635 /home/<replaceable>user</replaceable>/poky/meta-mylayer \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500636 "
637 </literallayout>
638 </para>
639
640 <para>
641 BitBake parses each <filename>conf/layer.conf</filename> file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400642 from the top down as specified in the
643 <filename>BBLAYERS</filename> variable
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500644 within the <filename>conf/bblayers.conf</filename> file.
645 During the processing of each
646 <filename>conf/layer.conf</filename> file, BitBake adds the
647 recipes, classes and configurations contained within the
648 particular layer to the source directory.
649 </para>
650 </section>
651
652 <section id='using-bbappend-files'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500653 <title>Using .bbappend Files in Your Layer</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500654
655 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500656 A recipe that appends Metadata to another recipe is called a
657 BitBake append file.
658 A BitBake append file uses the <filename>.bbappend</filename>
659 file type suffix, while the corresponding recipe to which
660 Metadata is being appended uses the <filename>.bb</filename>
661 file type suffix.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500662 </para>
663
664 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500665 You can use a <filename>.bbappend</filename> file in your
666 layer to make additions or changes to the content of another
667 layer's recipe without having to copy the other layer's
668 recipe into your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669 Your <filename>.bbappend</filename> file resides in your layer,
670 while the main <filename>.bb</filename> recipe file to
671 which you are appending Metadata resides in a different layer.
672 </para>
673
674 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 Being able to append information to an existing recipe not only
676 avoids duplication, but also automatically applies recipe
677 changes from a different layer into your layer.
678 If you were copying recipes, you would have to manually merge
679 changes as they occur.
680 </para>
681
682 <para>
683 When you create an append file, you must use the same root
684 name as the corresponding recipe file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685 For example, the append file
686 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
687 <filename>someapp_&DISTRO;.bb</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500688 This means the original recipe and append file names are
689 version number-specific.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500690 If the corresponding recipe is renamed to update to a newer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500691 version, you must also rename and possibly update
692 the corresponding <filename>.bbappend</filename> as well.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 During the build process, BitBake displays an error on starting
694 if it detects a <filename>.bbappend</filename> file that does
695 not have a corresponding recipe with a matching name.
696 See the
697 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
698 variable for information on how to handle this error.
699 </para>
700
701 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702 As an example, consider the main formfactor recipe and a
703 corresponding formfactor append file both from the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500704 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500705 Here is the main formfactor recipe, which is named
706 <filename>formfactor_0.0.bb</filename> and located in the
707 "meta" layer at
708 <filename>meta/recipes-bsp/formfactor</filename>:
709 <literallayout class='monospaced'>
710 SUMMARY = "Device formfactor information"
711 SECTION = "base"
712 LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500713 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714 PR = "r45"
715
716 SRC_URI = "file://config file://machconfig"
717 S = "${WORKDIR}"
718
719 PACKAGE_ARCH = "${MACHINE_ARCH}"
720 INHIBIT_DEFAULT_DEPS = "1"
721
722 do_install() {
723 # Install file only if it has contents
724 install -d ${D}${sysconfdir}/formfactor/
725 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
726 if [ -s "${S}/machconfig" ]; then
727 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
728 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 } </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 In the main recipe, note the
731 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
732 variable, which tells the OpenEmbedded build system where to
733 find files during the build.
734 </para>
735
736 <para>
737 Following is the append file, which is named
738 <filename>formfactor_0.0.bbappend</filename> and is from the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500739 Raspberry Pi BSP Layer named
740 <filename>meta-raspberrypi</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500741 The file is in the layer at
742 <filename>recipes-bsp/formfactor</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 <literallayout class='monospaced'>
744 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
745 </literallayout>
746 </para>
747
748 <para>
749 By default, the build system uses the
750 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
751 variable to locate files.
752 This append file extends the locations by setting the
753 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
754 variable.
755 Setting this variable in the <filename>.bbappend</filename>
756 file is the most reliable and recommended method for adding
757 directories to the search path used by the build system
758 to find files.
759 </para>
760
761 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500762 The statement in this example extends the directories to
763 include
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500764 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>,
765 which resolves to a directory named
766 <filename>formfactor</filename> in the same directory
767 in which the append file resides (i.e.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500768 <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500769 This implies that you must have the supporting directory
770 structure set up that will contain any files or patches you
771 will be including from the layer.
772 </para>
773
774 <para>
775 Using the immediate expansion assignment operator
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500776 <filename>:=</filename> is important because of the reference
777 to <filename>THISDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500778 The trailing colon character is important as it ensures that
779 items in the list remain colon-separated.
780 <note>
781 <para>
782 BitBake automatically defines the
783 <filename>THISDIR</filename> variable.
784 You should never set this variable yourself.
785 Using "_prepend" as part of the
786 <filename>FILESEXTRAPATHS</filename> ensures your path
787 will be searched prior to other paths in the final
788 list.
789 </para>
790
791 <para>
792 Also, not all append files add extra files.
793 Many append files simply exist to add build options
794 (e.g. <filename>systemd</filename>).
795 For these cases, your append file would not even
796 use the <filename>FILESEXTRAPATHS</filename> statement.
797 </para>
798 </note>
799 </para>
800 </section>
801
802 <section id='prioritizing-your-layer'>
803 <title>Prioritizing Your Layer</title>
804
805 <para>
806 Each layer is assigned a priority value.
807 Priority values control which layer takes precedence if there
808 are recipe files with the same name in multiple layers.
809 For these cases, the recipe file from the layer with a higher
810 priority number takes precedence.
811 Priority values also affect the order in which multiple
812 <filename>.bbappend</filename> files for the same recipe are
813 applied.
814 You can either specify the priority manually, or allow the
815 build system to calculate it based on the layer's dependencies.
816 </para>
817
818 <para>
819 To specify the layer's priority manually, use the
820 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400821 variable and append the layer's root name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500822 <literallayout class='monospaced'>
823 BBFILE_PRIORITY_mylayer = "1"
824 </literallayout>
825 </para>
826
827 <note>
828 <para>It is possible for a recipe with a lower version number
829 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
830 in a layer that has a higher priority to take precedence.</para>
831 <para>Also, the layer priority does not currently affect the
832 precedence order of <filename>.conf</filename>
833 or <filename>.bbclass</filename> files.
834 Future versions of BitBake might address this.</para>
835 </note>
836 </section>
837
838 <section id='managing-layers'>
839 <title>Managing Layers</title>
840
841 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400842 You can use the BitBake layer management tool
843 <filename>bitbake-layers</filename> to provide a view
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844 into the structure of recipes across a multi-layer project.
845 Being able to generate output that reports on configured layers
846 with their paths and priorities and on
847 <filename>.bbappend</filename> files and their applicable
848 recipes can help to reveal potential problems.
849 </para>
850
851 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400852 For help on the BitBake layer management tool, use the
853 following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500854 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400855 $ bitbake-layers --help
856 NOTE: Starting bitbake server...
857 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] &lt;subcommand&gt; ...
858
859 BitBake layers utility
860
861 optional arguments:
862 -d, --debug Enable debug output
863 -q, --quiet Print only errors
864 -F, --force Force add without recipe parse verification
865 --color COLOR Colorize output (where COLOR is auto, always, never)
866 -h, --help show this help message and exit
867
868 subcommands:
869 &lt;subcommand&gt;
870 show-layers show current configured layers.
871 show-overlayed list overlayed recipes (where the same recipe exists
872 in another layer)
873 show-recipes list available recipes, showing the layer they are
874 provided by
875 show-appends list bbappend files and recipe files they apply to
876 show-cross-depends Show dependencies between recipes that cross layer
877 boundaries.
878 add-layer Add one or more layers to bblayers.conf.
879 remove-layer Remove one or more layers from bblayers.conf.
880 flatten flatten layer configuration into a separate output
881 directory.
882 layerindex-fetch Fetches a layer from a layer index along with its
883 dependent layers, and adds them to conf/bblayers.conf.
884 layerindex-show-depends
885 Find layer dependencies from layer index.
886 create-layer Create a basic layer
887
888 Use bitbake-layers &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500889 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400890 </para>
891
892 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500893 The following list describes the available commands:
894 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400895 <listitem><para>
896 <emphasis><filename>help:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500897 Displays general help or help on a specified command.
898 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400899 <listitem><para>
900 <emphasis><filename>show-layers:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500901 Shows the current configured layers.
902 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400903 <listitem><para>
904 <emphasis><filename>show-overlayed:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 Lists overlayed recipes.
906 A recipe is overlayed when a recipe with the same name
907 exists in another layer that has a higher layer
908 priority.
909 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400910 <listitem><para>
911 <emphasis><filename>show-recipes:</filename></emphasis>
912 Lists available recipes and the layers that provide them.
913 </para></listitem>
914 <listitem><para>
915 <emphasis><filename>show-appends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916 Lists <filename>.bbappend</filename> files and the
917 recipe files to which they apply.
918 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400919 <listitem><para>
920 <emphasis><filename>show-cross-depends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500921 Lists dependency relationships between recipes that
922 cross layer boundaries.
923 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400924 <listitem><para>
925 <emphasis><filename>add-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500926 Adds a layer to <filename>bblayers.conf</filename>.
927 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400928 <listitem><para>
929 <emphasis><filename>remove-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500930 Removes a layer from <filename>bblayers.conf</filename>
931 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400932 <listitem><para>
933 <emphasis><filename>flatten:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500934 Flattens the layer configuration into a separate output
935 directory.
936 Flattening your layer configuration builds a "flattened"
937 directory that contains the contents of all layers,
938 with any overlayed recipes removed and any
939 <filename>.bbappend</filename> files appended to the
940 corresponding recipes.
941 You might have to perform some manual cleanup of the
942 flattened layer as follows:
943 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400944 <listitem><para>
945 Non-recipe files (such as patches)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500946 are overwritten.
947 The flatten command shows a warning for these
948 files.
949 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400950 <listitem><para>
951 Anything beyond the normal layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952 setup has been added to the
953 <filename>layer.conf</filename> file.
954 Only the lowest priority layer's
955 <filename>layer.conf</filename> is used.
956 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400957 <listitem><para>
958 Overridden and appended items from
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500959 <filename>.bbappend</filename> files need to be
960 cleaned up.
961 The contents of each
962 <filename>.bbappend</filename> end up in the
963 flattened recipe.
964 However, if there are appended or changed
965 variable values, you need to tidy these up
966 yourself.
967 Consider the following example.
968 Here, the <filename>bitbake-layers</filename>
969 command adds the line
970 <filename>#### bbappended ...</filename> so that
971 you know where the following lines originate:
972 <literallayout class='monospaced'>
973 ...
974 DESCRIPTION = "A useful utility"
975 ...
976 EXTRA_OECONF = "--enable-something"
977 ...
978
979 #### bbappended from meta-anotherlayer ####
980
981 DESCRIPTION = "Customized utility"
982 EXTRA_OECONF += "--enable-somethingelse"
983 </literallayout>
984 Ideally, you would tidy up these utilities as
985 follows:
986 <literallayout class='monospaced'>
987 ...
988 DESCRIPTION = "Customized utility"
989 ...
990 EXTRA_OECONF = "--enable-something --enable-somethingelse"
991 ...
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500992 </literallayout>
993 </para></listitem>
994 </itemizedlist>
995 </para></listitem>
996 <listitem><para>
997 <emphasis><filename>layerindex-fetch</filename>:</emphasis>
998 Fetches a layer from a layer index, along with its
999 dependent layers, and adds the layers to the
1000 <filename>conf/bblayers.conf</filename> file.
1001 </para></listitem>
1002 <listitem><para>
1003 <emphasis><filename>layerindex-show-depends</filename>:</emphasis>
1004 Finds layer dependencies from the layer index.
1005 </para></listitem>
1006 <listitem><para>
1007 <emphasis><filename>create-layer</filename>:</emphasis>
1008 Creates a basic layer.
1009 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001010 </itemizedlist>
1011 </para>
1012 </section>
1013
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001014 <section id='creating-a-general-layer-using-the-bitbake-layers-script'>
1015 <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
1017 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001018 The <filename>bitbake-layers</filename> script with the
1019 <filename>create-layer</filename> subcommand simplifies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001020 creating a new general layer.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 <note><title>Notes</title>
1022 <itemizedlist>
1023 <listitem><para>
1024 For information on BSP layers, see the
1025 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
1026 section in the Yocto Project Board Specific (BSP)
1027 Developer's Guide.
1028 </para></listitem>
1029 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001030 In order to use a layer with the OpenEmbedded
1031 build system, you need to add the layer to your
1032 <filename>bblayers.conf</filename> configuration
1033 file.
1034 See the
1035 "<link linkend='adding-a-layer-using-the-bitbake-layers-script'>Adding a Layer Using the <filename>bitbake-layers</filename> Script</link>"
1036 section for more information.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001037 </para></listitem>
1038 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001039 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 The default mode of the script's operation with this
1041 subcommand is to create a layer with the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001042 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001043 <listitem><para>A layer priority of 6.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001044 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001045 <listitem><para>A <filename>conf</filename>
1046 subdirectory that contains a
1047 <filename>layer.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001048 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001049 <listitem><para>
1050 A <filename>recipes-example</filename> subdirectory
1051 that contains a further subdirectory named
1052 <filename>example</filename>, which contains
1053 an <filename>example.bb</filename> recipe file.
1054 </para></listitem>
1055 <listitem><para>A <filename >COPYING.MIT</filename>,
1056 which is the license statement for the layer.
1057 The script assumes you want to use the MIT license,
1058 which is typical for most layers, for the contents of
1059 the layer itself.
1060 </para></listitem>
1061 <listitem><para>
1062 A <filename>README</filename> file, which is a file
1063 describing the contents of your new layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001064 </para></listitem>
1065 </itemizedlist>
1066 </para>
1067
1068 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001069 In its simplest form, you can use the following command form
1070 to create a layer.
1071 The command creates a layer whose name corresponds to
1072 <replaceable>your_layer_name</replaceable> in the current
1073 directory:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001074 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001075 $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001076 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001077 As an example, the following command creates a layer named
1078 <filename>meta-scottrif</filename> in your home directory:
1079 <literallayout class='monospaced'>
1080 $ cd /usr/home
1081 $ bitbake-layers create-layer meta-scottrif
1082 NOTE: Starting bitbake server...
1083 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
1084 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 </para>
1086
1087 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001088 If you want to set the priority of the layer to other than the
1089 default value of "6", you can either use the
1090 <filename>&dash;&dash;priority</filename> option or you can
1091 edit the
1092 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
1093 value in the <filename>conf/layer.conf</filename> after the
1094 script creates it.
1095 Furthermore, if you want to give the example recipe file
1096 some name other than the default, you can
1097 use the
1098 <filename>&dash;&dash;example-recipe-name</filename> option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001099 </para>
1100
1101 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001102 The easiest way to see how the
1103 <filename>bitbake-layers create-layer</filename> command
1104 works is to experiment with the script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001105 You can also read the usage information by entering the
1106 following:
1107 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001108 $ bitbake-layers create-layer --help
1109 NOTE: Starting bitbake server...
1110 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
1111 [--example-recipe-name EXAMPLERECIPE]
1112 layerdir
1113
1114 Create a basic layer
1115
1116 positional arguments:
1117 layerdir Layer directory to create
1118
1119 optional arguments:
1120 -h, --help show this help message and exit
1121 --priority PRIORITY, -p PRIORITY
1122 Layer directory to create
1123 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
1124 Filename of the example recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001125 </literallayout>
1126 </para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001127 </section>
1128
1129 <section id='adding-a-layer-using-the-bitbake-layers-script'>
1130 <title>Adding a Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001131
1132 <para>
1133 Once you create your general layer, you must add it to your
1134 <filename>bblayers.conf</filename> file.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001135 Adding the layer to this configuration file makes the
1136 OpenEmbedded build system aware of your layer so that it can
1137 search it for metadata.
1138 </para>
1139
1140 <para>
1141 Add your layer by using the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001142 <filename>bitbake-layers add-layer</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001143 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001144 $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable>
1145 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001146 Here is an example that adds a layer named
1147 <filename>meta-scottrif</filename> to the configuration file.
1148 Following the command that adds the layer is another
1149 <filename>bitbake-layers</filename> command that shows the
1150 layers that are in your <filename>bblayers.conf</filename>
1151 file:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001152 <literallayout class='monospaced'>
1153 $ bitbake-layers add-layer meta-scottrif
1154 NOTE: Starting bitbake server...
Brad Bishop316dfdd2018-06-25 12:45:53 -04001155 Parsing recipes: 100% |##########################################################| Time: 0:00:49
1156 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001157 $ bitbake-layers show-layers
1158 NOTE: Starting bitbake server...
1159 layer path priority
1160 ==========================================================================
1161 meta /home/scottrif/poky/meta 5
1162 meta-poky /home/scottrif/poky/meta-poky 5
1163 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001164 workspace /home/scottrif/poky/build/workspace 99
1165 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001166 </literallayout>
1167 Adding the layer to this file enables the build system to
1168 locate the layer during the build.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001169 <note>
1170 During a build, the OpenEmbedded build system looks in
1171 the layers from the top of the list down to the bottom
1172 in that order.
1173 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001174 </para>
1175 </section>
1176 </section>
1177
1178 <section id='usingpoky-extend-customimage'>
1179 <title>Customizing Images</title>
1180
1181 <para>
1182 You can customize images to satisfy particular requirements.
1183 This section describes several methods and provides guidelines for each.
1184 </para>
1185
1186 <section id='usingpoky-extend-customimage-localconf'>
1187 <title>Customizing Images Using <filename>local.conf</filename></title>
1188
1189 <para>
1190 Probably the easiest way to customize an image is to add a
1191 package by way of the <filename>local.conf</filename>
1192 configuration file.
1193 Because it is limited to local use, this method generally only
1194 allows you to add packages and is not as flexible as creating
1195 your own customized image.
1196 When you add packages using local variables this way, you need
1197 to realize that these variable changes are in effect for every
1198 build and consequently affect all images, which might not
1199 be what you require.
1200 </para>
1201
1202 <para>
1203 To add a package to your image using the local configuration
1204 file, use the
1205 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1206 variable with the <filename>_append</filename> operator:
1207 <literallayout class='monospaced'>
1208 IMAGE_INSTALL_append = " strace"
1209 </literallayout>
1210 Use of the syntax is important - specifically, the space between
1211 the quote and the package name, which is
1212 <filename>strace</filename> in this example.
1213 This space is required since the <filename>_append</filename>
1214 operator does not add the space.
1215 </para>
1216
1217 <para>
1218 Furthermore, you must use <filename>_append</filename> instead
1219 of the <filename>+=</filename> operator if you want to avoid
1220 ordering issues.
1221 The reason for this is because doing so unconditionally appends
1222 to the variable and avoids ordering problems due to the
1223 variable being set in image recipes and
1224 <filename>.bbclass</filename> files with operators like
1225 <filename>?=</filename>.
1226 Using <filename>_append</filename> ensures the operation takes
1227 affect.
1228 </para>
1229
1230 <para>
1231 As shown in its simplest use,
1232 <filename>IMAGE_INSTALL_append</filename> affects all images.
1233 It is possible to extend the syntax so that the variable
1234 applies to a specific image only.
1235 Here is an example:
1236 <literallayout class='monospaced'>
1237 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
1238 </literallayout>
1239 This example adds <filename>strace</filename> to the
1240 <filename>core-image-minimal</filename> image only.
1241 </para>
1242
1243 <para>
1244 You can add packages using a similar approach through the
1245 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
1246 variable.
1247 If you use this variable, only
1248 <filename>core-image-*</filename> images are affected.
1249 </para>
1250 </section>
1251
1252 <section id='usingpoky-extend-customimage-imagefeatures'>
1253 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
1254 <filename>EXTRA_IMAGE_FEATURES</filename></title>
1255
1256 <para>
1257 Another method for customizing your image is to enable or
1258 disable high-level image features by using the
1259 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
1260 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
1261 variables.
1262 Although the functions for both variables are nearly equivalent,
1263 best practices dictate using <filename>IMAGE_FEATURES</filename>
1264 from within a recipe and using
1265 <filename>EXTRA_IMAGE_FEATURES</filename> from within
1266 your <filename>local.conf</filename> file, which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001267 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001268 </para>
1269
1270 <para>
1271 To understand how these features work, the best reference is
1272 <filename>meta/classes/core-image.bbclass</filename>.
1273 This class lists out the available
Brad Bishop316dfdd2018-06-25 12:45:53 -04001274 <filename>IMAGE_FEATURES</filename> of which most map to
1275 package groups while some, such as
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001276 <filename>debug-tweaks</filename> and
1277 <filename>read-only-rootfs</filename>, resolve as general
1278 configuration settings.
1279 </para>
1280
1281 <para>
1282 In summary, the file looks at the contents of the
1283 <filename>IMAGE_FEATURES</filename> variable and then maps
1284 or configures the feature accordingly.
1285 Based on this information, the build system automatically
1286 adds the appropriate packages or configurations to the
1287 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
1288 variable.
1289 Effectively, you are enabling extra features by extending the
1290 class or creating a custom class for use with specialized image
1291 <filename>.bb</filename> files.
1292 </para>
1293
1294 <para>
1295 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1296 from within your local configuration file.
1297 Using a separate area from which to enable features with
1298 this variable helps you avoid overwriting the features in the
1299 image recipe that are enabled with
1300 <filename>IMAGE_FEATURES</filename>.
1301 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1302 to <filename>IMAGE_FEATURES</filename> within
1303 <filename>meta/conf/bitbake.conf</filename>.
1304 </para>
1305
1306 <para>
1307 To illustrate how you can use these variables to modify your
1308 image, consider an example that selects the SSH server.
1309 The Yocto Project ships with two SSH servers you can use
1310 with your images: Dropbear and OpenSSH.
1311 Dropbear is a minimal SSH server appropriate for
1312 resource-constrained environments, while OpenSSH is a
1313 well-known standard SSH server implementation.
1314 By default, the <filename>core-image-sato</filename> image
1315 is configured to use Dropbear.
1316 The <filename>core-image-full-cmdline</filename> and
1317 <filename>core-image-lsb</filename> images both
1318 include OpenSSH.
1319 The <filename>core-image-minimal</filename> image does not
1320 contain an SSH server.
1321 </para>
1322
1323 <para>
1324 You can customize your image and change these defaults.
1325 Edit the <filename>IMAGE_FEATURES</filename> variable
1326 in your recipe or use the
1327 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1328 <filename>local.conf</filename> file so that it configures the
1329 image you are working with to include
1330 <filename>ssh-server-dropbear</filename> or
1331 <filename>ssh-server-openssh</filename>.
1332 </para>
1333
1334 <note>
1335 See the
1336 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1337 section in the Yocto Project Reference Manual for a complete
1338 list of image features that ship with the Yocto Project.
1339 </note>
1340 </section>
1341
1342 <section id='usingpoky-extend-customimage-custombb'>
1343 <title>Customizing Images Using Custom .bb Files</title>
1344
1345 <para>
1346 You can also customize an image by creating a custom recipe
1347 that defines additional software as part of the image.
1348 The following example shows the form for the two lines you need:
1349 <literallayout class='monospaced'>
1350 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1351
1352 inherit core-image
1353 </literallayout>
1354 </para>
1355
1356 <para>
1357 Defining the software using a custom recipe gives you total
1358 control over the contents of the image.
1359 It is important to use the correct names of packages in the
1360 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1361 variable.
1362 You must use the OpenEmbedded notation and not the Debian notation for the names
1363 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1364 </para>
1365
1366 <para>
1367 The other method for creating a custom image is to base it on an existing image.
1368 For example, if you want to create an image based on <filename>core-image-sato</filename>
1369 but add the additional package <filename>strace</filename> to the image,
1370 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1371 new <filename>.bb</filename> and add the following line to the end of the copy:
1372 <literallayout class='monospaced'>
1373 IMAGE_INSTALL += "strace"
1374 </literallayout>
1375 </para>
1376 </section>
1377
1378 <section id='usingpoky-extend-customimage-customtasks'>
1379 <title>Customizing Images Using Custom Package Groups</title>
1380
1381 <para>
1382 For complex custom images, the best approach for customizing
1383 an image is to create a custom package group recipe that is
1384 used to build the image or images.
1385 A good example of a package group recipe is
1386 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1387 </para>
1388
1389 <para>
1390 If you examine that recipe, you see that the
1391 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1392 variable lists the package group packages to produce.
1393 The <filename>inherit packagegroup</filename> statement
1394 sets appropriate default values and automatically adds
1395 <filename>-dev</filename>, <filename>-dbg</filename>, and
1396 <filename>-ptest</filename> complementary packages for each
1397 package specified in the <filename>PACKAGES</filename>
1398 statement.
1399 <note>
1400 The <filename>inherit packages</filename> should be
1401 located near the top of the recipe, certainly before
1402 the <filename>PACKAGES</filename> statement.
1403 </note>
1404 </para>
1405
1406 <para>
1407 For each package you specify in <filename>PACKAGES</filename>,
1408 you can use
1409 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1410 and
1411 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1412 entries to provide a list of packages the parent task package
1413 should contain.
1414 You can see examples of these further down in the
1415 <filename>packagegroup-base.bb</filename> recipe.
1416 </para>
1417
1418 <para>
1419 Here is a short, fabricated example showing the same basic
1420 pieces:
1421 <literallayout class='monospaced'>
1422 DESCRIPTION = "My Custom Package Groups"
1423
1424 inherit packagegroup
1425
1426 PACKAGES = "\
1427 packagegroup-custom-apps \
1428 packagegroup-custom-tools \
1429 "
1430
1431 RDEPENDS_packagegroup-custom-apps = "\
1432 dropbear \
1433 portmap \
1434 psplash"
1435
1436 RDEPENDS_packagegroup-custom-tools = "\
1437 oprofile \
1438 oprofileui-server \
1439 lttng-tools"
1440
1441 RRECOMMENDS_packagegroup-custom-tools = "\
1442 kernel-module-oprofile"
1443 </literallayout>
1444 </para>
1445
1446 <para>
1447 In the previous example, two package group packages are created with their dependencies and their
1448 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1449 <filename>packagegroup-custom-tools</filename>.
1450 To build an image using these package group packages, you need to add
1451 <filename>packagegroup-custom-apps</filename> and/or
1452 <filename>packagegroup-custom-tools</filename> to
1453 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1454 For other forms of image dependencies see the other areas of this section.
1455 </para>
1456 </section>
1457
1458 <section id='usingpoky-extend-customimage-image-name'>
1459 <title>Customizing an Image Hostname</title>
1460
1461 <para>
1462 By default, the configured hostname (i.e.
1463 <filename>/etc/hostname</filename>) in an image is the
1464 same as the machine name.
1465 For example, if
1466 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1467 equals "qemux86", the configured hostname written to
1468 <filename>/etc/hostname</filename> is "qemux86".
1469 </para>
1470
1471 <para>
1472 You can customize this name by altering the value of the
1473 "hostname" variable in the
1474 <filename>base-files</filename> recipe using either
1475 an append file or a configuration file.
1476 Use the following in an append file:
1477 <literallayout class='monospaced'>
1478 hostname="myhostname"
1479 </literallayout>
1480 Use the following in a configuration file:
1481 <literallayout class='monospaced'>
1482 hostname_pn-base-files = "myhostname"
1483 </literallayout>
1484 </para>
1485
1486 <para>
1487 Changing the default value of the variable "hostname" can be
1488 useful in certain situations.
1489 For example, suppose you need to do extensive testing on an
1490 image and you would like to easily identify the image
1491 under test from existing images with typical default
1492 hostnames.
1493 In this situation, you could change the default hostname to
1494 "testme", which results in all the images using the name
1495 "testme".
1496 Once testing is complete and you do not need to rebuild the
1497 image for test any longer, you can easily reset the default
1498 hostname.
1499 </para>
1500
1501 <para>
1502 Another point of interest is that if you unset the variable,
1503 the image will have no default hostname in the filesystem.
1504 Here is an example that unsets the variable in a
1505 configuration file:
1506 <literallayout class='monospaced'>
1507 hostname_pn-base-files = ""
1508 </literallayout>
1509 Having no default hostname in the filesystem is suitable for
1510 environments that use dynamic hostnames such as virtual
1511 machines.
1512 </para>
1513 </section>
1514 </section>
1515
1516 <section id='new-recipe-writing-a-new-recipe'>
1517 <title>Writing a New Recipe</title>
1518
1519 <para>
1520 Recipes (<filename>.bb</filename> files) are fundamental components
1521 in the Yocto Project environment.
1522 Each software component built by the OpenEmbedded build system
1523 requires a recipe to define the component.
1524 This section describes how to create, write, and test a new
1525 recipe.
1526 <note>
1527 For information on variables that are useful for recipes and
1528 for information about recipe naming issues, see the
1529 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1530 section of the Yocto Project Reference Manual.
1531 </note>
1532 </para>
1533
1534 <section id='new-recipe-overview'>
1535 <title>Overview</title>
1536
1537 <para>
1538 The following figure shows the basic process for creating a
1539 new recipe.
1540 The remainder of the section provides details for the steps.
1541 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1542 </para>
1543 </section>
1544
1545 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1546 <title>Locate or Automatically Create a Base Recipe</title>
1547
1548 <para>
1549 You can always write a recipe from scratch.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001550 However, three choices exist that can help you quickly get a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001551 start on a new recipe:
1552 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001553 <listitem><para>
1554 <emphasis><filename>devtool add</filename>:</emphasis>
1555 A command that assists in creating a recipe and
1556 an environment conducive to development.
1557 </para></listitem>
1558 <listitem><para>
1559 <emphasis><filename>recipetool create</filename>:</emphasis>
1560 A command provided by the Yocto Project that automates
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001561 creation of a base recipe based on the source
1562 files.
1563 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001564 <listitem><para>
1565 <emphasis>Existing Recipes:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001566 Location and modification of an existing recipe that is
1567 similar in function to the recipe you need.
1568 </para></listitem>
1569 </itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001570 <note>
1571 For information on recipe syntax, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001572 "<link linkend='recipe-syntax'>Recipe Syntax</link>"
1573 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001574 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001575 </para>
1576
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001577 <section id='new-recipe-creating-the-base-recipe-using-devtool'>
1578 <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001579
1580 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001581 The <filename>devtool add</filename> command uses the same
1582 logic for auto-creating the recipe as
1583 <filename>recipetool create</filename>, which is listed
1584 below.
1585 Additionally, however, <filename>devtool add</filename>
1586 sets up an environment that makes it easy for you to
1587 patch the source and to make changes to the recipe as
1588 is often necessary when adding a recipe to build a new
1589 piece of software to be included in a build.
1590 </para>
1591
1592 <para>
1593 You can find a complete description of the
1594 <filename>devtool add</filename> command in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001595 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>"
1596 section in the Yocto Project Application Development
1597 and the Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001598 </para>
1599 </section>
1600
1601 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1602 <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
1603
1604 <para>
1605 <filename>recipetool create</filename> automates creation
1606 of a base recipe given a set of source code files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001607 As long as you can extract or point to the source files,
1608 the tool will construct a recipe and automatically
1609 configure all pre-build information into the recipe.
1610 For example, suppose you have an application that builds
1611 using Autotools.
1612 Creating the base recipe using
1613 <filename>recipetool</filename> results in a recipe
1614 that has the pre-build dependencies, license requirements,
1615 and checksums configured.
1616 </para>
1617
1618 <para>
1619 To run the tool, you just need to be in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001621 and have sourced the build environment setup script
1622 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001623 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
Brad Bishop316dfdd2018-06-25 12:45:53 -04001624 To get help on the tool, use the following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001625 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001626 $ recipetool -h
1627 NOTE: Starting bitbake server...
1628 usage: recipetool [-d] [-q] [--color COLOR] [-h] &lt;subcommand&gt; ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001629
Brad Bishop316dfdd2018-06-25 12:45:53 -04001630 OpenEmbedded recipe tool
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001631
Brad Bishop316dfdd2018-06-25 12:45:53 -04001632 options:
1633 -d, --debug Enable debug output
1634 -q, --quiet Print only errors
1635 --color COLOR Colorize output (where COLOR is auto, always, never)
1636 -h, --help show this help message and exit
1637
1638 subcommands:
1639 create Create a new recipe
1640 newappend Create a bbappend for the specified target in the specified
1641 layer
1642 setvar Set a variable within a recipe
1643 appendfile Create/update a bbappend to replace a target file
1644 appendsrcfiles Create/update a bbappend to add or replace source files
1645 appendsrcfile Create/update a bbappend to add or replace a source file
1646 Use recipetool &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001647 </literallayout>
1648 </para>
1649
1650 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001651 Running
1652 <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001653 creates the base recipe and locates it properly in the
1654 layer that contains your source files.
1655 Following are some syntax examples:
1656 </para>
1657
1658 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001659 Use this syntax to generate a recipe based on
1660 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001661 Once generated, the recipe resides in the existing source
1662 code layer:
1663 <literallayout class='monospaced'>
1664 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1665 </literallayout>
1666 Use this syntax to generate a recipe using code that you
1667 extract from <replaceable>source</replaceable>.
1668 The extracted code is placed in its own layer defined
1669 by <replaceable>EXTERNALSRC</replaceable>.
1670 <literallayout class='monospaced'>
1671 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1672 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001673 Use this syntax to generate a recipe based on
1674 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001675 The options direct <filename>recipetool</filename> to
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001676 generate debugging information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001677 Once generated, the recipe resides in the existing source
1678 code layer:
1679 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001680 recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001681 </literallayout>
1682 </para>
1683 </section>
1684
1685 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1686 <title>Locating and Using a Similar Recipe</title>
1687
1688 <para>
1689 Before writing a recipe from scratch, it is often useful to
1690 discover whether someone else has already written one that
1691 meets (or comes close to meeting) your needs.
1692 The Yocto Project and OpenEmbedded communities maintain many
1693 recipes that might be candidates for what you are doing.
1694 You can find a good central index of these recipes in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001695 <ulink url='http://layers.openembedded.org'>OpenEmbedded Layer Index</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001696 </para>
1697
1698 <para>
1699 Working from an existing recipe or a skeleton recipe is the
1700 best way to get started.
1701 Here are some points on both methods:
1702 <itemizedlist>
1703 <listitem><para><emphasis>Locate and modify a recipe that
1704 is close to what you want to do:</emphasis>
1705 This method works when you are familiar with the
1706 current recipe space.
1707 The method does not work so well for those new to
1708 the Yocto Project or writing recipes.</para>
1709 <para>Some risks associated with this method are
1710 using a recipe that has areas totally unrelated to
1711 what you are trying to accomplish with your recipe,
1712 not recognizing areas of the recipe that you might
1713 have to add from scratch, and so forth.
1714 All these risks stem from unfamiliarity with the
1715 existing recipe space.</para></listitem>
1716 <listitem><para><emphasis>Use and modify the following
1717 skeleton recipe:</emphasis>
1718 If for some reason you do not want to use
1719 <filename>recipetool</filename> and you cannot
1720 find an existing recipe that is close to meeting
1721 your needs, you can use the following structure to
1722 provide the fundamental areas of a new recipe.
1723 <literallayout class='monospaced'>
1724 DESCRIPTION = ""
1725 HOMEPAGE = ""
1726 LICENSE = ""
1727 SECTION = ""
1728 DEPENDS = ""
1729 LIC_FILES_CHKSUM = ""
1730
1731 SRC_URI = ""
1732 </literallayout>
1733 </para></listitem>
1734 </itemizedlist>
1735 </para>
1736 </section>
1737 </section>
1738
1739 <section id='new-recipe-storing-and-naming-the-recipe'>
1740 <title>Storing and Naming the Recipe</title>
1741
1742 <para>
1743 Once you have your base recipe, you should put it in your
1744 own layer and name it appropriately.
1745 Locating it correctly ensures that the OpenEmbedded build
1746 system can find it when you use BitBake to process the
1747 recipe.
1748 </para>
1749
1750 <itemizedlist>
1751 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1752 The OpenEmbedded build system locates your recipe
1753 through the layer's <filename>conf/layer.conf</filename>
1754 file and the
1755 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1756 variable.
1757 This variable sets up a path from which the build system can
1758 locate recipes.
1759 Here is the typical use:
1760 <literallayout class='monospaced'>
1761 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1762 ${LAYERDIR}/recipes-*/*/*.bbappend"
1763 </literallayout>
1764 Consequently, you need to be sure you locate your new recipe
1765 inside your layer such that it can be found.</para>
1766 <para>You can find more information on how layers are
1767 structured in the
1768 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1769 section.</para></listitem>
1770 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1771 When you name your recipe, you need to follow this naming
1772 convention:
1773 <literallayout class='monospaced'>
1774 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1775 </literallayout>
1776 Use lower-cased characters and do not include the reserved
1777 suffixes <filename>-native</filename>,
1778 <filename>-cross</filename>, <filename>-initial</filename>,
1779 or <filename>-dev</filename> casually (i.e. do not use them
1780 as part of your recipe name unless the string applies).
1781 Here are some examples:
1782 <literallayout class='monospaced'>
1783 cups_1.7.0.bb
1784 gawk_4.0.2.bb
1785 irssi_0.8.16-rc1.bb
1786 </literallayout></para></listitem>
1787 </itemizedlist>
1788 </section>
1789
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001790 <section id='new-recipe-running-a-build-on-the-recipe'>
1791 <title>Running a Build on the Recipe</title>
1792
1793 <para>
1794 Creating a new recipe is usually an iterative process that
1795 requires using BitBake to process the recipe multiple times in
1796 order to progressively discover and add information to the
1797 recipe file.
1798 </para>
1799
1800 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001801 Assuming you have sourced the build environment setup script (i.e.
1802 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001803 and you are in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001804 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001805 use BitBake to process your recipe.
1806 All you need to provide is the
1807 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1808 in the previous section:
1809 <literallayout class='monospaced'>
1810 $ bitbake <replaceable>basename</replaceable>
1811 </literallayout>
1812
1813 </para>
1814
1815 <para>
1816 During the build, the OpenEmbedded build system creates a
1817 temporary work directory for each recipe
1818 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1819 where it keeps extracted source files, log files, intermediate
1820 compilation and packaging files, and so forth.
1821 </para>
1822
1823 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001824 The path to the per-recipe temporary work directory depends
1825 on the context in which it is being built.
1826 The quickest way to find this path is to have BitBake return it
1827 by running the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001828 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001829 $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001830 </literallayout>
1831 As an example, assume a Source Directory top-level folder named
1832 <filename>poky</filename>, a default Build Directory at
1833 <filename>poky/build</filename>, and a
1834 <filename>qemux86-poky-linux</filename> machine target system.
1835 Furthermore, suppose your recipe is named
1836 <filename>foo_1.3.0.bb</filename>.
1837 In this case, the work directory the build system uses to
1838 build the package would be as follows:
1839 <literallayout class='monospaced'>
1840 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1841 </literallayout>
1842 Inside this directory you can find sub-directories such as
1843 <filename>image</filename>, <filename>packages-split</filename>,
1844 and <filename>temp</filename>.
1845 After the build, you can examine these to determine how well
1846 the build went.
1847 <note>
1848 You can find log files for each task in the recipe's
1849 <filename>temp</filename> directory (e.g.
1850 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1851 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1852 (e.g. <filename>log.do_configure</filename>,
1853 <filename>log.do_fetch</filename>, and
1854 <filename>log.do_compile</filename>).
1855 </note>
1856 </para>
1857
1858 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001859 You can find more information about the build process in
Brad Bishop316dfdd2018-06-25 12:45:53 -04001860 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-development-environment'>The Yocto Project Development Environment</ulink>"
1861 chapter of the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001862 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863 </section>
1864
1865 <section id='new-recipe-fetching-code'>
1866 <title>Fetching Code</title>
1867
1868 <para>
1869 The first thing your recipe must do is specify how to fetch
1870 the source files.
1871 Fetching is controlled mainly through the
1872 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1873 variable.
1874 Your recipe must have a <filename>SRC_URI</filename> variable
1875 that points to where the source is located.
1876 For a graphical representation of source locations, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001877 "<ulink url='&YOCTO_DOCS_OM_URL;#sources-dev-environment'>Sources</ulink>"
1878 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001879 </para>
1880
1881 <para>
1882 The
1883 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1884 task uses the prefix of each entry in the
1885 <filename>SRC_URI</filename> variable value to determine which
1886 fetcher to use to get your source files.
1887 It is the <filename>SRC_URI</filename> variable that triggers
1888 the fetcher.
1889 The
1890 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1891 task uses the variable after source is fetched to apply
1892 patches.
1893 The OpenEmbedded build system uses
1894 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1895 for scanning directory locations for local files in
1896 <filename>SRC_URI</filename>.
1897 </para>
1898
1899 <para>
1900 The <filename>SRC_URI</filename> variable in your recipe must
1901 define each unique location for your source files.
1902 It is good practice to not hard-code pathnames in an URL used
1903 in <filename>SRC_URI</filename>.
1904 Rather than hard-code these paths, use
1905 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1906 which causes the fetch process to use the version specified in
1907 the recipe filename.
1908 Specifying the version in this manner means that upgrading the
1909 recipe to a future version is as simple as renaming the recipe
1910 to match the new version.
1911 </para>
1912
1913 <para>
1914 Here is a simple example from the
1915 <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
1916 recipe where the source comes from a single tarball.
1917 Notice the use of the
1918 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1919 variable:
1920 <literallayout class='monospaced'>
1921 SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
1922 </literallayout>
1923 </para>
1924
1925 <para>
1926 Files mentioned in <filename>SRC_URI</filename> whose names end
1927 in a typical archive extension (e.g. <filename>.tar</filename>,
1928 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1929 <filename>.zip</filename>, and so forth), are automatically
1930 extracted during the
1931 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1932 task.
1933 For another example that specifies these types of files, see
1934 the
1935 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1936 section.
1937 </para>
1938
1939 <para>
1940 Another way of specifying source is from an SCM.
1941 For Git repositories, you must specify
1942 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1943 and you should specify
1944 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1945 to include the revision with
1946 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1947 Here is an example from the recipe
1948 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1949 <literallayout class='monospaced'>
1950 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1951
1952 PR = "r6"
1953 PV = "1.0.5+git${SRCPV}"
1954
1955 SRC_URI = "git://git.kernel.dk/blktrace.git \
1956 file://ldflags.patch"
1957 </literallayout>
1958 </para>
1959
1960 <para>
1961 If your <filename>SRC_URI</filename> statement includes
1962 URLs pointing to individual files fetched from a remote server
1963 other than a version control system, BitBake attempts to
1964 verify the files against checksums defined in your recipe to
1965 ensure they have not been tampered with or otherwise modified
1966 since the recipe was written.
1967 Two checksums are used:
1968 <filename>SRC_URI[md5sum]</filename> and
1969 <filename>SRC_URI[sha256sum]</filename>.
1970 </para>
1971
1972 <para>
1973 If your <filename>SRC_URI</filename> variable points to
1974 more than a single URL (excluding SCM URLs), you need to
1975 provide the <filename>md5</filename> and
1976 <filename>sha256</filename> checksums for each URL.
1977 For these cases, you provide a name for each URL as part of
1978 the <filename>SRC_URI</filename> and then reference that name
1979 in the subsequent checksum statements.
1980 Here is an example:
1981 <literallayout class='monospaced'>
1982 SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001983 ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001984
1985 SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
1986 SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
1987
1988 SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
1989 SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
1990 </literallayout>
1991 </para>
1992
1993 <para>
1994 Proper values for <filename>md5</filename> and
1995 <filename>sha256</filename> checksums might be available
1996 with other signatures on the download page for the upstream
1997 source (e.g. <filename>md5</filename>,
1998 <filename>sha1</filename>, <filename>sha256</filename>,
1999 <filename>GPG</filename>, and so forth).
2000 Because the OpenEmbedded build system only deals with
2001 <filename>sha256sum</filename> and <filename>md5sum</filename>,
2002 you should verify all the signatures you find by hand.
2003 </para>
2004
2005 <para>
2006 If no <filename>SRC_URI</filename> checksums are specified
2007 when you attempt to build the recipe, or you provide an
2008 incorrect checksum, the build will produce an error for each
2009 missing or incorrect checksum.
2010 As part of the error message, the build system provides
2011 the checksum string corresponding to the fetched file.
2012 Once you have the correct checksums, you can copy and paste
2013 them into your recipe and then run the build again to continue.
2014 <note>
2015 As mentioned, if the upstream source provides signatures
2016 for verifying the downloaded source code, you should
2017 verify those manually before setting the checksum values
2018 in the recipe and continuing with the build.
2019 </note>
2020 </para>
2021
2022 <para>
2023 This final example is a bit more complicated and is from the
2024 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2025 recipe.
2026 The example's <filename>SRC_URI</filename> statement identifies
2027 multiple files as the source files for the recipe: a tarball, a
2028 patch file, a desktop file, and an icon.
2029 <literallayout class='monospaced'>
2030 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2031 file://xwc.patch \
2032 file://rxvt.desktop \
2033 file://rxvt.png"
2034 </literallayout>
2035 </para>
2036
2037 <para>
2038 When you specify local files using the
2039 <filename>file://</filename> URI protocol, the build system
2040 fetches files from the local machine.
2041 The path is relative to the
2042 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2043 variable and searches specific directories in a certain order:
2044 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2045 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2046 and <filename>files</filename>.
2047 The directories are assumed to be subdirectories of the
2048 directory in which the recipe or append file resides.
2049 For another example that specifies these types of files, see the
2050 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2051 section.
2052 </para>
2053
2054 <para>
2055 The previous example also specifies a patch file.
2056 Patch files are files whose names usually end in
2057 <filename>.patch</filename> or <filename>.diff</filename> but
2058 can end with compressed suffixes such as
2059 <filename>diff.gz</filename> and
2060 <filename>patch.bz2</filename>, for example.
2061 The build system automatically applies patches as described
2062 in the
2063 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2064 </para>
2065 </section>
2066
2067 <section id='new-recipe-unpacking-code'>
2068 <title>Unpacking Code</title>
2069
2070 <para>
2071 During the build, the
2072 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2073 task unpacks the source with
2074 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2075 pointing to where it is unpacked.
2076 </para>
2077
2078 <para>
2079 If you are fetching your source files from an upstream source
2080 archived tarball and the tarball's internal structure matches
2081 the common convention of a top-level subdirectory named
2082 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
2083 then you do not need to set <filename>S</filename>.
2084 However, if <filename>SRC_URI</filename> specifies to fetch
2085 source from an archive that does not use this convention,
2086 or from an SCM like Git or Subversion, your recipe needs to
2087 define <filename>S</filename>.
2088 </para>
2089
2090 <para>
2091 If processing your recipe using BitBake successfully unpacks
2092 the source files, you need to be sure that the directory
2093 pointed to by <filename>${S}</filename> matches the structure
2094 of the source.
2095 </para>
2096 </section>
2097
2098 <section id='new-recipe-patching-code'>
2099 <title>Patching Code</title>
2100
2101 <para>
2102 Sometimes it is necessary to patch code after it has been
2103 fetched.
2104 Any files mentioned in <filename>SRC_URI</filename> whose
2105 names end in <filename>.patch</filename> or
2106 <filename>.diff</filename> or compressed versions of these
2107 suffixes (e.g. <filename>diff.gz</filename> are treated as
2108 patches.
2109 The
2110 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2111 task automatically applies these patches.
2112 </para>
2113
2114 <para>
2115 The build system should be able to apply patches with the "-p1"
2116 option (i.e. one directory level in the path will be stripped
2117 off).
2118 If your patch needs to have more directory levels stripped off,
2119 specify the number of levels using the "striplevel" option in
2120 the <filename>SRC_URI</filename> entry for the patch.
2121 Alternatively, if your patch needs to be applied in a specific
2122 subdirectory that is not specified in the patch file, use the
2123 "patchdir" option in the entry.
2124 </para>
2125
2126 <para>
2127 As with all local files referenced in
2128 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2129 using <filename>file://</filename>, you should place
2130 patch files in a directory next to the recipe either
2131 named the same as the base name of the recipe
2132 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2133 and
2134 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2135 or "files".
2136 </para>
2137 </section>
2138
2139 <section id='new-recipe-licensing'>
2140 <title>Licensing</title>
2141
2142 <para>
2143 Your recipe needs to have both the
2144 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2145 and
2146 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2147 variables:
2148 <itemizedlist>
2149 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2150 This variable specifies the license for the software.
2151 If you do not know the license under which the software
2152 you are building is distributed, you should go to the
2153 source code and look for that information.
2154 Typical files containing this information include
2155 <filename>COPYING</filename>,
2156 <filename>LICENSE</filename>, and
2157 <filename>README</filename> files.
2158 You could also find the information near the top of
2159 a source file.
2160 For example, given a piece of software licensed under
2161 the GNU General Public License version 2, you would
2162 set <filename>LICENSE</filename> as follows:
2163 <literallayout class='monospaced'>
2164 LICENSE = "GPLv2"
2165 </literallayout></para>
2166 <para>The licenses you specify within
2167 <filename>LICENSE</filename> can have any name as long
2168 as you do not use spaces, since spaces are used as
2169 separators between license names.
2170 For standard licenses, use the names of the files in
2171 <filename>meta/files/common-licenses/</filename>
2172 or the <filename>SPDXLICENSEMAP</filename> flag names
2173 defined in <filename>meta/conf/licenses.conf</filename>.
2174 </para></listitem>
2175 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2176 The OpenEmbedded build system uses this variable to
2177 make sure the license text has not changed.
2178 If it has, the build produces an error and it affords
2179 you the chance to figure it out and correct the problem.
2180 </para>
2181 <para>You need to specify all applicable licensing
2182 files for the software.
2183 At the end of the configuration step, the build process
2184 will compare the checksums of the files to be sure
2185 the text has not changed.
2186 Any differences result in an error with the message
2187 containing the current checksum.
2188 For more explanation and examples of how to set the
2189 <filename>LIC_FILES_CHKSUM</filename> variable, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002190 "<link link='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
2191 section.</para>
2192
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002193 <para>To determine the correct checksum string, you
2194 can list the appropriate files in the
2195 <filename>LIC_FILES_CHKSUM</filename> variable with
2196 incorrect md5 strings, attempt to build the software,
2197 and then note the resulting error messages that will
2198 report the correct md5 strings.
2199 See the
2200 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2201 section for additional information.
2202 </para>
2203
2204 <para>
2205 Here is an example that assumes the software has a
2206 <filename>COPYING</filename> file:
2207 <literallayout class='monospaced'>
2208 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2209 </literallayout>
2210 When you try to build the software, the build system
2211 will produce an error and give you the correct string
2212 that you can substitute into the recipe file for a
2213 subsequent build.
2214 </para></listitem>
2215 </itemizedlist>
2216 </para>
2217
2218<!--
2219
2220 <para>
2221 For trying this out I created a new recipe named
2222 <filename>htop_1.0.2.bb</filename> and put it in
2223 <filename>poky/meta/recipes-extended/htop</filename>.
2224 There are two license type statements in my very simple
2225 recipe:
2226 <literallayout class='monospaced'>
2227 LICENSE = ""
2228
2229 LIC_FILES_CHKSUM = ""
2230
2231 SRC_URI[md5sum] = ""
2232 SRC_URI[sha256sum] = ""
2233 </literallayout>
2234 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2235 Next, you delete or comment out the two <filename>SRC_URI</filename>
2236 lines at the end and then attempt to build the software with
2237 <filename>bitbake htop</filename>.
2238 Doing so causes BitBake to report some errors and and give
2239 you the actual strings you need for the last two
2240 <filename>SRC_URI</filename> lines.
2241 Prior to this, you have to dig around in the home page of the
2242 source for <filename>htop</filename> and determine that the
2243 software is released under GPLv2.
2244 You can provide that in the <filename>LICENSE</filename>
2245 statement.
2246 Now you edit your recipe to have those two strings for
2247 the <filename>SRC_URI</filename> statements:
2248 <literallayout class='monospaced'>
2249 LICENSE = "GPLv2"
2250
2251 LIC_FILES_CHKSUM = ""
2252
2253 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2254 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2255 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2256 </literallayout>
2257 At this point, you can build the software again using the
2258 <filename>bitbake htop</filename> command.
2259 There is just a set of errors now associated with the
2260 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2261 </para>
2262-->
2263
2264 </section>
2265
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002266 <section id='new-dependencies'>
2267 <title>Dependencies</title>
2268
2269 <para>
2270 Most software packages have a short list of other packages
2271 that they require, which are called dependencies.
2272 These dependencies fall into two main categories: build-time
2273 dependencies, which are required when the software is built;
2274 and runtime dependencies, which are required to be installed
2275 on the target in order for the software to run.
2276 </para>
2277
2278 <para>
2279 Within a recipe, you specify build-time dependencies using the
2280 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2281 variable.
2282 Although nuances exist, items specified in
2283 <filename>DEPENDS</filename> should be names of other recipes.
2284 It is important that you specify all build-time dependencies
2285 explicitly.
2286 If you do not, due to the parallel nature of BitBake's
2287 execution, you can end up with a race condition where the
2288 dependency is present for one task of a recipe (e.g.
2289 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
2290 and then gone when the next task runs (e.g.
2291 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
2292 </para>
2293
2294 <para>
2295 Another consideration is that configure scripts might
2296 automatically check for optional dependencies and enable
2297 corresponding functionality if those dependencies are found.
2298 This behavior means that to ensure deterministic results and
2299 thus avoid more race conditions, you need to either explicitly
2300 specify these dependencies as well, or tell the configure
2301 script explicitly to disable the functionality.
2302 If you wish to make a recipe that is more generally useful
2303 (e.g. publish the recipe in a layer for others to use),
2304 instead of hard-disabling the functionality, you can use the
2305 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
2306 variable to allow functionality and the corresponding
2307 dependencies to be enabled and disabled easily by other
2308 users of the recipe.
2309 </para>
2310
2311 <para>
2312 Similar to build-time dependencies, you specify runtime
2313 dependencies through a variable -
2314 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
2315 which is package-specific.
2316 All variables that are package-specific need to have the name
2317 of the package added to the end as an override.
2318 Since the main package for a recipe has the same name as the
2319 recipe, and the recipe's name can be found through the
2320 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2321 variable, then you specify the dependencies for the main
2322 package by setting <filename>RDEPENDS_${PN}</filename>.
2323 If the package were named <filename>${PN}-tools</filename>,
2324 then you would set <filename>RDEPENDS_${PN}-tools</filename>,
2325 and so forth.
2326 </para>
2327
2328 <para>
2329 Some runtime dependencies will be set automatically at
2330 packaging time.
2331 These dependencies include any shared library dependencies
2332 (i.e. if a package "example" contains "libexample" and
2333 another package "mypackage" contains a binary that links to
2334 "libexample" then the OpenEmbedded build system will
2335 automatically add a runtime dependency to "mypackage" on
2336 "example").
2337 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002338 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
2339 section in the Yocto Project Overview and Concepts Manual for
2340 further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002341 </para>
2342 </section>
2343
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002344 <section id='new-recipe-configuring-the-recipe'>
2345 <title>Configuring the Recipe</title>
2346
2347 <para>
2348 Most software provides some means of setting build-time
2349 configuration options before compilation.
2350 Typically, setting these options is accomplished by running a
2351 configure script with some options, or by modifying a build
2352 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002353 <note>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002354 As of Yocto Project Release 1.7, some of the core recipes
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002355 that package binary configuration scripts now disable the
2356 scripts due to the scripts previously requiring error-prone
2357 path substitution.
2358 The OpenEmbedded build system uses
2359 <filename>pkg-config</filename> now, which is much more
2360 robust.
2361 You can find a list of the <filename>*-config</filename>
2362 scripts that are disabled list in the
2363 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2364 section in the Yocto Project Reference Manual.
2365 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002366 </para>
2367
2368 <para>
2369 A major part of build-time configuration is about checking for
2370 build-time dependencies and possibly enabling optional
2371 functionality as a result.
2372 You need to specify any build-time dependencies for the
2373 software you are building in your recipe's
2374 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2375 value, in terms of other recipes that satisfy those
2376 dependencies.
2377 You can often find build-time or runtime
2378 dependencies described in the software's documentation.
2379 </para>
2380
2381 <para>
2382 The following list provides configuration items of note based
2383 on how your software is built:
2384 <itemizedlist>
2385 <listitem><para><emphasis>Autotools:</emphasis>
2386 If your source files have a
2387 <filename>configure.ac</filename> file, then your
2388 software is built using Autotools.
2389 If this is the case, you just need to worry about
2390 modifying the configuration.</para>
2391 <para>When using Autotools, your recipe needs to inherit
2392 the
2393 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2394 class and your recipe does not have to contain a
2395 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2396 task.
2397 However, you might still want to make some adjustments.
2398 For example, you can set
2399 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002400 or
2401 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002402 to pass any needed configure options that are specific
2403 to the recipe.</para></listitem>
2404 <listitem><para><emphasis>CMake:</emphasis>
2405 If your source files have a
2406 <filename>CMakeLists.txt</filename> file, then your
2407 software is built using CMake.
2408 If this is the case, you just need to worry about
2409 modifying the configuration.</para>
2410 <para>When you use CMake, your recipe needs to inherit
2411 the
2412 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2413 class and your recipe does not have to contain a
2414 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2415 task.
2416 You can make some adjustments by setting
2417 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2418 to pass any needed configure options that are specific
2419 to the recipe.</para></listitem>
2420 <listitem><para><emphasis>Other:</emphasis>
2421 If your source files do not have a
2422 <filename>configure.ac</filename> or
2423 <filename>CMakeLists.txt</filename> file, then your
2424 software is built using some method other than Autotools
2425 or CMake.
2426 If this is the case, you normally need to provide a
2427 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2428 task in your recipe
2429 unless, of course, there is nothing to configure.
2430 </para>
2431 <para>Even if your software is not being built by
2432 Autotools or CMake, you still might not need to deal
2433 with any configuration issues.
2434 You need to determine if configuration is even a required step.
2435 You might need to modify a Makefile or some configuration file
2436 used for the build to specify necessary build options.
2437 Or, perhaps you might need to run a provided, custom
2438 configure script with the appropriate options.</para>
2439 <para>For the case involving a custom configure
2440 script, you would run
2441 <filename>./configure --help</filename> and look for
2442 the options you need to set.</para></listitem>
2443 </itemizedlist>
2444 </para>
2445
2446 <para>
2447 Once configuration succeeds, it is always good practice to
2448 look at the <filename>log.do_configure</filename> file to
2449 ensure that the appropriate options have been enabled and no
2450 additional build-time dependencies need to be added to
2451 <filename>DEPENDS</filename>.
2452 For example, if the configure script reports that it found
2453 something not mentioned in <filename>DEPENDS</filename>, or
2454 that it did not find something that it needed for some
2455 desired optional functionality, then you would need to add
2456 those to <filename>DEPENDS</filename>.
2457 Looking at the log might also reveal items being checked for,
2458 enabled, or both that you do not want, or items not being found
2459 that are in <filename>DEPENDS</filename>, in which case
2460 you would need to look at passing extra options to the
2461 configure script as needed.
2462 For reference information on configure options specific to the
2463 software you are building, you can consult the output of the
2464 <filename>./configure --help</filename> command within
2465 <filename>${S}</filename> or consult the software's upstream
2466 documentation.
2467 </para>
2468 </section>
2469
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002470 <section id='new-recipe-using-headers-to-interface-with-devices'>
2471 <title>Using Headers to Interface with Devices</title>
2472
2473 <para>
2474 If your recipe builds an application that needs to
2475 communicate with some device or needs an API into a custom
2476 kernel, you will need to provide appropriate header files.
2477 Under no circumstances should you ever modify the existing
2478 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>
2479 file.
2480 These headers are used to build <filename>libc</filename> and
2481 must not be compromised with custom or machine-specific
2482 header information.
2483 If you customize <filename>libc</filename> through modified
2484 headers all other applications that use
2485 <filename>libc</filename> thus become affected.
2486 <note><title>Warning</title>
2487 Never copy and customize the <filename>libc</filename>
2488 header file (i.e.
2489 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>).
2490 </note>
2491 The correct way to interface to a device or custom kernel is
2492 to use a separate package that provides the additional headers
2493 for the driver or other unique interfaces.
2494 When doing so, your application also becomes responsible for
2495 creating a dependency on that specific provider.
2496 </para>
2497
2498 <para>
2499 Consider the following:
2500 <itemizedlist>
2501 <listitem><para>
2502 Never modify
2503 <filename>linux-libc-headers.inc</filename>.
2504 Consider that file to be part of the
2505 <filename>libc</filename> system, and not something
2506 you use to access the kernel directly.
2507 You should access <filename>libc</filename> through
2508 specific <filename>libc</filename> calls.
2509 </para></listitem>
2510 <listitem><para>
2511 Applications that must talk directly to devices
2512 should either provide necessary headers themselves,
2513 or establish a dependency on a special headers package
2514 that is specific to that driver.
2515 </para></listitem>
2516 </itemizedlist>
2517 </para>
2518
2519 <para>
2520 For example, suppose you want to modify an existing header
2521 that adds I/O control or network support.
2522 If the modifications are used by a small number programs,
2523 providing a unique version of a header is easy and has little
2524 impact.
2525 When doing so, bear in mind the guidelines in the previous
2526 list.
2527 <note>
2528 If for some reason your changes need to modify the behavior
2529 of the <filename>libc</filename>, and subsequently all
2530 other applications on the system, use a
2531 <filename>.bbappend</filename> to modify the
2532 <filename>linux-kernel-headers.inc</filename> file.
2533 However, take care to not make the changes
2534 machine specific.
2535 </note>
2536 </para>
2537
2538 <para>
2539 Consider a case where your kernel is older and you need
2540 an older <filename>libc</filename> ABI.
2541 The headers installed by your recipe should still be a
2542 standard mainline kernel, not your own custom one.
2543 </para>
2544
2545 <para>
2546 When you use custom kernel headers you need to get them from
2547 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>,
2548 which is the directory with kernel headers that are
2549 required to build out-of-tree modules.
2550 Your recipe will also need the following:
2551 <literallayout class='monospaced'>
2552 do_configure[depends] += "virtual/kernel:do_shared_workdir"
2553 </literallayout>
2554 </para>
2555 </section>
2556
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002557 <section id='new-recipe-compilation'>
2558 <title>Compilation</title>
2559
2560 <para>
2561 During a build, the <filename>do_compile</filename> task
2562 happens after source is fetched, unpacked, and configured.
2563 If the recipe passes through <filename>do_compile</filename>
2564 successfully, nothing needs to be done.
2565 </para>
2566
2567 <para>
2568 However, if the compile step fails, you need to diagnose the
2569 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002570 Here are some common issues that cause failures.
2571 <note>
2572 For cases where improper paths are detected for
2573 configuration files or for when libraries/headers cannot
2574 be found, be sure you are using the more robust
2575 <filename>pkg-config</filename>.
2576 See the note in section
2577 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2578 for additional information.
2579 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002580 <itemizedlist>
2581 <listitem><para><emphasis>Parallel build failures:</emphasis>
2582 These failures manifest themselves as intermittent
2583 errors, or errors reporting that a file or directory
2584 that should be created by some other part of the build
2585 process could not be found.
2586 This type of failure can occur even if, upon inspection,
2587 the file or directory does exist after the build has
2588 failed, because that part of the build process happened
2589 in the wrong order.</para>
2590 <para>To fix the problem, you need to either satisfy
2591 the missing dependency in the Makefile or whatever
2592 script produced the Makefile, or (as a workaround)
2593 set
2594 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2595 to an empty string:
2596 <literallayout class='monospaced'>
2597 PARALLEL_MAKE = ""
2598 </literallayout></para>
2599 <para>
2600 For information on parallel Makefile issues, see the
2601 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2602 section.
2603 </para></listitem>
2604 <listitem><para><emphasis>Improper host path usage:</emphasis>
2605 This failure applies to recipes building for the target
2606 or <filename>nativesdk</filename> only.
2607 The failure occurs when the compilation process uses
2608 improper headers, libraries, or other files from the
2609 host system when cross-compiling for the target.
2610 </para>
2611 <para>To fix the problem, examine the
2612 <filename>log.do_compile</filename> file to identify
2613 the host paths being used (e.g.
2614 <filename>/usr/include</filename>,
2615 <filename>/usr/lib</filename>, and so forth) and then
2616 either add configure options, apply a patch, or do both.
2617 </para></listitem>
2618 <listitem><para><emphasis>Failure to find required
2619 libraries/headers:</emphasis>
2620 If a build-time dependency is missing because it has
2621 not been declared in
2622 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2623 or because the dependency exists but the path used by
2624 the build process to find the file is incorrect and the
2625 configure step did not detect it, the compilation
2626 process could fail.
2627 For either of these failures, the compilation process
2628 notes that files could not be found.
2629 In these cases, you need to go back and add additional
2630 options to the configure script as well as possibly
2631 add additional build-time dependencies to
2632 <filename>DEPENDS</filename>.</para>
2633 <para>Occasionally, it is necessary to apply a patch
2634 to the source to ensure the correct paths are used.
2635 If you need to specify paths to find files staged
2636 into the sysroot from other recipes, use the variables
2637 that the OpenEmbedded build system provides
2638 (e.g.
2639 <filename>STAGING_BINDIR</filename>,
2640 <filename>STAGING_INCDIR</filename>,
2641 <filename>STAGING_DATADIR</filename>, and so forth).
2642<!--
2643 (e.g.
2644 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2645 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2646 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2647 and so forth).
2648-->
2649 </para></listitem>
2650 </itemizedlist>
2651 </para>
2652 </section>
2653
2654 <section id='new-recipe-installing'>
2655 <title>Installing</title>
2656
2657 <para>
2658 During <filename>do_install</filename>, the task copies the
2659 built files along with their hierarchy to locations that
2660 would mirror their locations on the target device.
2661 The installation process copies files from the
2662 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2663 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2664 and
2665 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2666 directories to the
2667 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2668 directory to create the structure as it should appear on the
2669 target system.
2670 </para>
2671
2672 <para>
2673 How your software is built affects what you must do to be
2674 sure your software is installed correctly.
2675 The following list describes what you must do for installation
2676 depending on the type of build system used by the software
2677 being built:
2678 <itemizedlist>
2679 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2680 If the software your recipe is building uses Autotools
2681 or CMake, the OpenEmbedded build
2682 system understands how to install the software.
2683 Consequently, you do not have to have a
2684 <filename>do_install</filename> task as part of your
2685 recipe.
2686 You just need to make sure the install portion of the
2687 build completes with no issues.
2688 However, if you wish to install additional files not
2689 already being installed by
2690 <filename>make install</filename>, you should do this
2691 using a <filename>do_install_append</filename> function
2692 using the install command as described in
2693 the "Manual" bulleted item later in this list.
2694 </para></listitem>
2695 <listitem><para><emphasis>Other (using
2696 <filename>make install</filename>):</emphasis>
2697 You need to define a
2698 <filename>do_install</filename> function in your
2699 recipe.
2700 The function should call
2701 <filename>oe_runmake install</filename> and will likely
2702 need to pass in the destination directory as well.
2703 How you pass that path is dependent on how the
2704 <filename>Makefile</filename> being run is written
2705 (e.g. <filename>DESTDIR=${D}</filename>,
2706 <filename>PREFIX=${D}</filename>,
2707 <filename>INSTALLROOT=${D}</filename>, and so forth).
2708 </para>
2709 <para>For an example recipe using
2710 <filename>make install</filename>, see the
2711 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2712 section.</para></listitem>
2713 <listitem><para><emphasis>Manual:</emphasis>
2714 You need to define a
2715 <filename>do_install</filename> function in your
2716 recipe.
2717 The function must first use
2718 <filename>install -d</filename> to create the
2719 directories under
2720 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2721 Once the directories exist, your function can use
2722 <filename>install</filename> to manually install the
2723 built software into the directories.</para>
2724 <para>You can find more information on
2725 <filename>install</filename> at
2726 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2727 </para></listitem>
2728 </itemizedlist>
2729 </para>
2730
2731 <para>
2732 For the scenarios that do not use Autotools or
2733 CMake, you need to track the installation
2734 and diagnose and fix any issues until everything installs
2735 correctly.
2736 You need to look in the default location of
2737 <filename>${D}</filename>, which is
2738 <filename>${WORKDIR}/image</filename>, to be sure your
2739 files have been installed correctly.
2740 </para>
2741
2742 <note><title>Notes</title>
2743 <itemizedlist>
2744 <listitem><para>
2745 During the installation process, you might need to
2746 modify some of the installed files to suit the target
2747 layout.
2748 For example, you might need to replace hard-coded paths
2749 in an initscript with values of variables provided by
2750 the build system, such as replacing
2751 <filename>/usr/bin/</filename> with
2752 <filename>${bindir}</filename>.
2753 If you do perform such modifications during
2754 <filename>do_install</filename>, be sure to modify the
2755 destination file after copying rather than before
2756 copying.
2757 Modifying after copying ensures that the build system
2758 can re-execute <filename>do_install</filename> if
2759 needed.
2760 </para></listitem>
2761 <listitem><para>
2762 <filename>oe_runmake install</filename>, which can be
2763 run directly or can be run indirectly by the
2764 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2765 and
2766 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2767 classes, runs <filename>make install</filename> in
2768 parallel.
2769 Sometimes, a Makefile can have missing dependencies
2770 between targets that can result in race conditions.
2771 If you experience intermittent failures during
2772 <filename>do_install</filename>, you might be able to
2773 work around them by disabling parallel Makefile
2774 installs by adding the following to the recipe:
2775 <literallayout class='monospaced'>
2776 PARALLEL_MAKEINST = ""
2777 </literallayout>
2778 See
2779 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2780 for additional information.
2781 </para></listitem>
2782 </itemizedlist>
2783 </note>
2784 </section>
2785
2786 <section id='new-recipe-enabling-system-services'>
2787 <title>Enabling System Services</title>
2788
2789 <para>
2790 If you want to install a service, which is a process that
2791 usually starts on boot and runs in the background, then
2792 you must include some additional definitions in your recipe.
2793 </para>
2794
2795 <para>
2796 If you are adding services and the service initialization
2797 script or the service file itself is not installed, you must
2798 provide for that installation in your recipe using a
2799 <filename>do_install_append</filename> function.
2800 If your recipe already has a <filename>do_install</filename>
2801 function, update the function near its end rather than
2802 adding an additional <filename>do_install_append</filename>
2803 function.
2804 </para>
2805
2806 <para>
2807 When you create the installation for your services, you need
2808 to accomplish what is normally done by
2809 <filename>make install</filename>.
2810 In other words, make sure your installation arranges the output
2811 similar to how it is arranged on the target system.
2812 </para>
2813
2814 <para>
2815 The OpenEmbedded build system provides support for starting
2816 services two different ways:
2817 <itemizedlist>
2818 <listitem><para><emphasis>SysVinit:</emphasis>
2819 SysVinit is a system and service manager that
2820 manages the init system used to control the very basic
2821 functions of your system.
2822 The init program is the first program
2823 started by the Linux kernel when the system boots.
2824 Init then controls the startup, running and shutdown
2825 of all other programs.</para>
2826 <para>To enable a service using SysVinit, your recipe
2827 needs to inherit the
2828 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2829 class.
2830 The class helps facilitate safely installing the
2831 package on the target.</para>
2832 <para>You will need to set the
2833 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2834 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2835 and
2836 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2837 variables within your recipe.</para></listitem>
2838 <listitem><para><emphasis>systemd:</emphasis>
2839 System Management Daemon (systemd) was designed to
2840 replace SysVinit and to provide
2841 enhanced management of services.
2842 For more information on systemd, see the systemd
2843 homepage at
2844 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2845 </para>
2846 <para>To enable a service using systemd, your recipe
2847 needs to inherit the
2848 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2849 class.
2850 See the <filename>systemd.bbclass</filename> file
2851 located in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002852 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002853 section for more information.
2854 </para></listitem>
2855 </itemizedlist>
2856 </para>
2857 </section>
2858
2859 <section id='new-recipe-packaging'>
2860 <title>Packaging</title>
2861
2862 <para>
2863 Successful packaging is a combination of automated processes
2864 performed by the OpenEmbedded build system and some
2865 specific steps you need to take.
2866 The following list describes the process:
2867 <itemizedlist>
2868 <listitem><para><emphasis>Splitting Files</emphasis>:
2869 The <filename>do_package</filename> task splits the
2870 files produced by the recipe into logical components.
2871 Even software that produces a single binary might
2872 still have debug symbols, documentation, and other
2873 logical components that should be split out.
2874 The <filename>do_package</filename> task ensures
2875 that files are split up and packaged correctly.
2876 </para></listitem>
2877 <listitem><para><emphasis>Running QA Checks</emphasis>:
2878 The
2879 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2880 class adds a step to
2881 the package generation process so that output quality
2882 assurance checks are generated by the OpenEmbedded
2883 build system.
2884 This step performs a range of checks to be sure the
2885 build's output is free of common problems that show
2886 up during runtime.
2887 For information on these checks, see the
2888 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2889 class and the
2890 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2891 chapter in the Yocto Project Reference Manual.
2892 </para></listitem>
2893 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2894 After you build your software, you need to be sure
2895 your packages are correct.
2896 Examine the
2897 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2898 directory and make sure files are where you expect
2899 them to be.
2900 If you discover problems, you can set
2901 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2902 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2903 <filename>do_install(_append)</filename>, and so forth as
2904 needed.
2905 </para></listitem>
2906 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2907 If you need to split an application into several
2908 packages, see the
2909 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2910 section for an example.
2911 </para></listitem>
2912 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2913 For an example showing how to install a
2914 post-installation script, see the
2915 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2916 section.
2917 </para></listitem>
2918 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2919 Depending on what your recipe is building and how it
2920 is configured, it might be important to mark the
2921 packages produced as being specific to a particular
2922 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002923 a particular machine or architecture at all.</para>
2924 <para>By default, packages apply to any machine with the
2925 same architecture as the target machine.
2926 When a recipe produces packages that are
2927 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002928 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2929 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002930 is applied only for a particular machine), you should
2931 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002932 recipe:
2933 <literallayout class='monospaced'>
2934 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002935 </literallayout></para>
2936 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002937 that do not contain anything specific to the target
2938 machine or architecture at all (e.g. recipes
2939 that simply package script files or configuration
2940 files), you should use the
2941 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
2942 class to do this for you by adding this to your
2943 recipe:
2944 <literallayout class='monospaced'>
2945 inherit allarch
2946 </literallayout>
2947 Ensuring that the package architecture is correct is
2948 not critical while you are doing the first few builds
2949 of your recipe.
2950 However, it is important in order
2951 to ensure that your recipe rebuilds (or does not
2952 rebuild) appropriately in response to changes in
2953 configuration, and to ensure that you get the
2954 appropriate packages installed on the target machine,
2955 particularly if you run separate builds for more
2956 than one target machine.
2957 </para></listitem>
2958 </itemizedlist>
2959 </para>
2960 </section>
2961
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002962 <section id='new-sharing-files-between-recipes'>
2963 <title>Sharing Files Between Recipes</title>
2964
2965 <para>
2966 Recipes often need to use files provided by other recipes on
2967 the build host.
2968 For example, an application linking to a common library needs
2969 access to the library itself and its associated headers.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002970 The way this access is accomplished is by populating a sysroot
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002971 with files.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002972 Each recipe has two sysroots in its work directory, one for
2973 target files
2974 (<filename>recipe-sysroot</filename>) and one for files that
2975 are native to the build host
2976 (<filename>recipe-sysroot-native</filename>).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002977 <note>
2978 You could find the term "staging" used within the Yocto
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002979 project regarding files populating sysroots (e.g. the
Brad Bishop37a0e4d2017-12-04 01:01:44 -05002980 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink>
2981 variable).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002982 </note>
2983 </para>
2984
2985 <para>
2986 Recipes should never populate the sysroot directly (i.e. write
2987 files into sysroot).
2988 Instead, files should be installed into standard locations
2989 during the
2990 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2991 task within the
2992 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2993 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002994 The reason for this limitation is that almost all files that
2995 populate the sysroot are cataloged in manifests in order to
2996 ensure the files can be removed later when a recipe is either
2997 modified or removed.
2998 Thus, the sysroot is able to remain free from stale files.
2999 </para>
3000
3001 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003002 A subset of the files installed by the
3003 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3004 task are used by the
3005 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3006 task as defined by the the
3007 <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>
3008 variable to automatically populate the sysroot.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003009 It is possible to modify the list of directories that populate
3010 the sysroot.
3011 The following example shows how you could add the
3012 <filename>/opt</filename> directory to the list of
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003013 directories within a recipe:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003014 <literallayout class='monospaced'>
3015 SYSROOT_DIRS += "/opt"
3016 </literallayout>
3017 </para>
3018
3019 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003020 For a more complete description of the
3021 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3022 task and its associated functions, see the
3023 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink>
3024 class.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003025 </para>
3026 </section>
3027
Brad Bishop316dfdd2018-06-25 12:45:53 -04003028 <section id='metadata-virtual-providers'>
3029 <title>Using Virtual Providers</title>
3030
3031 <para>
3032 Prior to a build, if you know that several different recipes
3033 provide the same functionality, you can use a virtual provider
3034 (i.e. <filename>virtual/*</filename>) as a placeholder for the
3035 actual provider.
3036 The actual provider is determined at build-time.
3037 </para>
3038
3039 <para>
3040 A common scenario where a virtual provider is used would be
3041 for the kernel recipe.
3042 Suppose you have three kernel recipes whose
3043 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
3044 values map to <filename>kernel-big</filename>,
3045 <filename>kernel-mid</filename>, and
3046 <filename>kernel-small</filename>.
3047 Furthermore, each of these recipes in some way uses a
3048 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3049 statement that essentially identifies itself as being able
3050 to provide <filename>virtual/kernel</filename>.
3051 Here is one way through the
3052 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-kernel'><filename>kernel</filename></ulink>
3053 class:
3054 <literallayout class='monospaced'>
3055 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
3056 </literallayout>
3057 Any recipe that inherits the <filename>kernel</filename> class
3058 is going to utilize a <filename>PROVIDES</filename> statement
3059 that identifies that recipe as being able to provide the
3060 <filename>virtual/kernel</filename> item.
3061 </para>
3062
3063 <para>
3064 Now comes the time to actually build an image and you need a
3065 kernel recipe, but which one?
3066 You can configure your build to call out the kernel recipe
3067 you want by using the
3068 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></ulink>
3069 variable.
3070 As an example, consider the
3071 <ulink url='https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc'><filename>x86-base.inc</filename></ulink>
3072 include file, which is a machine
3073 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>)
3074 configuration file.
3075 This include file is the reason all x86-based machines use the
3076 <filename>linux-yocto</filename> kernel.
3077 Here are the relevant lines from the include file:
3078 <literallayout class='monospaced'>
3079 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
3080 PREFERRED_VERSION_linux-yocto ??= "4.15%"
3081 </literallayout>
3082 </para>
3083
3084 <para>
3085 When you use a virtual provider, you do not have to
3086 "hard code" a recipe name as a build dependency.
3087 You can use the
3088 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3089 variable to state the build is dependent on
3090 <filename>virtual/kernel</filename> for example:
3091 <literallayout class='monospaced'>
3092 DEPENDS = "virtual/kernel"
3093 </literallayout>
3094 During the build, the OpenEmbedded build system picks
3095 the correct recipe needed for the
3096 <filename>virtual/kernel</filename> dependency based on the
3097 <filename>PREFERRED_PROVIDER</filename> variable.
3098 If you want to use the small kernel mentioned at the beginning
3099 of this section, configure your build as follows:
3100 <literallayout class='monospaced'>
3101 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
3102 </literallayout>
3103 <note>
3104 Any recipe that
3105 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3106 a <filename>virtual/*</filename> item that is ultimately
3107 not selected through
3108 <filename>PREFERRED_PROVIDER</filename> does not get built.
3109 Preventing these recipes from building is usually the
3110 desired behavior since this mechanism's purpose is to
3111 select between mutually exclusive alternative providers.
3112 </note>
3113 </para>
3114
3115 <para>
3116 The following lists specific examples of virtual providers:
3117 <itemizedlist>
3118 <listitem><para>
3119 <filename>virtual/kernel</filename>:
3120 Provides the name of the kernel recipe to use when
3121 building a kernel image.
3122 </para></listitem>
3123 <listitem><para>
3124 <filename>virtual/bootloader</filename>:
3125 Provides the name of the bootloader to use when
3126 building an image.
3127 </para></listitem>
3128 <listitem><para>
3129 <filename>virtual/mesa</filename>:
3130 Provides <filename>gbm.pc</filename>.
3131 </para></listitem>
3132 <listitem><para>
3133 <filename>virtual/egl</filename>:
3134 Provides <filename>egl.pc</filename> and possibly
3135 <filename>wayland-egl.pc</filename>.
3136 </para></listitem>
3137 <listitem><para>
3138 <filename>virtual/libgl</filename>:
3139 Provides <filename>gl.pc</filename> (i.e. libGL).
3140 </para></listitem>
3141 <listitem><para>
3142 <filename>virtual/libgles1</filename>:
3143 Provides <filename>glesv1_cm.pc</filename>
3144 (i.e. libGLESv1_CM).
3145 </para></listitem>
3146 <listitem><para>
3147 <filename>virtual/libgles2</filename>:
3148 Provides <filename>glesv2.pc</filename>
3149 (i.e. libGLESv2).
3150 </para></listitem>
3151 </itemizedlist>
3152 </para>
3153 </section>
3154
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003155 <section id='properly-versioning-pre-release-recipes'>
3156 <title>Properly Versioning Pre-Release Recipes</title>
3157
3158 <para>
3159 Sometimes the name of a recipe can lead to versioning
3160 problems when the recipe is upgraded to a final release.
3161 For example, consider the
3162 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
3163 the list of example recipes in the
3164 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
3165 section.
3166 This recipe is at a release candidate stage (i.e.
3167 "rc1").
3168 When the recipe is released, the recipe filename becomes
3169 <filename>irssi_0.8.16.bb</filename>.
3170 The version change from <filename>0.8.16-rc1</filename>
3171 to <filename>0.8.16</filename> is seen as a decrease by the
3172 build system and package managers, so the resulting packages
3173 will not correctly trigger an upgrade.
3174 </para>
3175
3176 <para>
3177 In order to ensure the versions compare properly, the
3178 recommended convention is to set
3179 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
3180 within the recipe to
3181 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
3182 You can use an additional variable so that you can use the
3183 current version elsewhere.
3184 Here is an example:
3185 <literallayout class='monospaced'>
3186 REALPV = "0.8.16-rc1"
3187 PV = "0.8.15+${REALPV}"
3188 </literallayout>
3189 </para>
3190 </section>
3191
3192 <section id='new-recipe-post-installation-scripts'>
3193 <title>Post-Installation Scripts</title>
3194
3195 <para>
3196 Post-installation scripts run immediately after installing
3197 a package on the target or during image creation when a
3198 package is included in an image.
3199 To add a post-installation script to a package, add a
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003200 <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003201 the recipe file (<filename>.bb</filename>) and replace
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003202 <replaceable>PACKAGENAME</replaceable> with the name of the package
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003203 you want to attach to the <filename>postinst</filename>
3204 script.
3205 To apply the post-installation script to the main package
3206 for the recipe, which is usually what is required, specify
3207 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003208 in place of <replaceable>PACKAGENAME</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003209 </para>
3210
3211 <para>
3212 A post-installation function has the following structure:
3213 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003214 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003215 # Commands to carry out
3216 }
3217 </literallayout>
3218 </para>
3219
3220 <para>
3221 The script defined in the post-installation function is
3222 called when the root filesystem is created.
3223 If the script succeeds, the package is marked as installed.
3224 If the script fails, the package is marked as unpacked and
3225 the script is executed when the image boots again.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003226 <note>
3227 Any RPM post-installation script that runs on the target
3228 should return a 0 exit code.
3229 RPM does not allow non-zero exit codes for these scripts,
3230 and the RPM package manager will cause the package to fail
3231 installation on the target.
3232 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003233 </para>
3234
3235 <para>
3236 Sometimes it is necessary for the execution of a
3237 post-installation script to be delayed until the first boot.
3238 For example, the script might need to be executed on the
3239 device itself.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003240 To delay script execution until boot time, you must explicitly
3241 mark post installs to defer to the target.
3242 You can use <filename>pkg_postinst_ontarget()</filename> or
3243 call
3244 <filename>postinst-intercepts defer_to_first_boot</filename>
3245 from <filename>pkg_postinst()</filename>.
3246 Any failure of a <filename>pkg_postinst()</filename> script
3247 (including exit 1) triggers an error during the
3248 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
3249 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003250 </para>
3251
3252 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003253 If you have recipes that use
3254 <filename>pkg_postinst</filename> function
3255 and they require the use of non-standard native
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003256 tools that have dependencies during rootfs construction, you
3257 need to use the
3258 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3259 variable in your recipe to list these tools.
3260 If you do not use this variable, the tools might be missing and
3261 execution of the post-installation script is deferred until
3262 first boot.
3263 Deferring the script to first boot is undesirable and for
3264 read-only rootfs impossible.
3265 </para>
3266
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003267 <note>
3268 Equivalent support for pre-install, pre-uninstall, and
3269 post-uninstall scripts exist by way of
3270 <filename>pkg_preinst</filename>,
3271 <filename>pkg_prerm</filename>, and
3272 <filename>pkg_postrm</filename>, respectively.
3273 These scrips work in exactly the same way as does
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003274 <filename>pkg_postinst</filename> with the exception
3275 that they run at different times.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003276 Also, because of when they run, they are not applicable to
3277 being run at image creation time like
3278 <filename>pkg_postinst</filename>.
3279 </note>
3280 </section>
3281
3282 <section id='new-recipe-testing'>
3283 <title>Testing</title>
3284
3285 <para>
3286 The final step for completing your recipe is to be sure that
3287 the software you built runs correctly.
3288 To accomplish runtime testing, add the build's output
3289 packages to your image and test them on the target.
3290 </para>
3291
3292 <para>
3293 For information on how to customize your image by adding
3294 specific packages, see the
3295 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3296 section.
3297 </para>
3298 </section>
3299
3300 <section id='new-recipe-testing-examples'>
3301 <title>Examples</title>
3302
3303 <para>
3304 To help summarize how to write a recipe, this section provides
3305 some examples given various scenarios:
3306 <itemizedlist>
3307 <listitem><para>Recipes that use local files</para></listitem>
3308 <listitem><para>Using an Autotooled package</para></listitem>
3309 <listitem><para>Using a Makefile-based package</para></listitem>
3310 <listitem><para>Splitting an application into multiple packages</para></listitem>
3311 <listitem><para>Adding binaries to an image</para></listitem>
3312 </itemizedlist>
3313 </para>
3314
3315 <section id='new-recipe-single-c-file-package-hello-world'>
3316 <title>Single .c File Package (Hello World!)</title>
3317
3318 <para>
3319 Building an application from a single file that is stored
3320 locally (e.g. under <filename>files</filename>) requires
3321 a recipe that has the file listed in the
3322 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3323 variable.
3324 Additionally, you need to manually write the
3325 <filename>do_compile</filename> and
3326 <filename>do_install</filename> tasks.
3327 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3328 variable defines the directory containing the source code,
3329 which is set to
3330 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3331 in this case - the directory BitBake uses for the build.
3332 <literallayout class='monospaced'>
3333 SUMMARY = "Simple helloworld application"
3334 SECTION = "examples"
3335 LICENSE = "MIT"
3336 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3337
3338 SRC_URI = "file://helloworld.c"
3339
3340 S = "${WORKDIR}"
3341
3342 do_compile() {
3343 ${CC} helloworld.c -o helloworld
3344 }
3345
3346 do_install() {
3347 install -d ${D}${bindir}
3348 install -m 0755 helloworld ${D}${bindir}
3349 }
3350 </literallayout>
3351 </para>
3352
3353 <para>
3354 By default, the <filename>helloworld</filename>,
3355 <filename>helloworld-dbg</filename>, and
3356 <filename>helloworld-dev</filename> packages are built.
3357 For information on how to customize the packaging process,
3358 see the
3359 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3360 section.
3361 </para>
3362 </section>
3363
3364 <section id='new-recipe-autotooled-package'>
3365 <title>Autotooled Package</title>
3366 <para>
3367 Applications that use Autotools such as <filename>autoconf</filename> and
3368 <filename>automake</filename> require a recipe that has a source archive listed in
3369 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3370 also inherit the
3371 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3372 class, which contains the definitions of all the steps
3373 needed to build an Autotool-based application.
3374 The result of the build is automatically packaged.
3375 And, if the application uses NLS for localization, packages with local information are
3376 generated (one package per language).
3377 Following is one example: (<filename>hello_2.3.bb</filename>)
3378 <literallayout class='monospaced'>
3379 SUMMARY = "GNU Helloworld application"
3380 SECTION = "examples"
3381 LICENSE = "GPLv2+"
3382 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3383
3384 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3385
3386 inherit autotools gettext
3387 </literallayout>
3388 </para>
3389
3390 <para>
3391 The variable
3392 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3393 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003394 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3395 section in the Yocto Project Overview and Concepts Manual.
3396 You can quickly create Autotool-based recipes in a manner
3397 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003398 </para>
3399 </section>
3400
3401 <section id='new-recipe-makefile-based-package'>
3402 <title>Makefile-Based Package</title>
3403
3404 <para>
3405 Applications that use GNU <filename>make</filename> also require a recipe that has
3406 the source archive listed in
3407 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3408 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3409 starts the <filename>make</filename> command to compile the application.
3410 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003411 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3412 or
3413 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3414 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003415 BitBake passes these options into the GNU <filename>make</filename> invocation.
3416 Note that a <filename>do_install</filename> task is still required.
3417 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3418 </para>
3419
3420 <para>
3421 Some applications might require extra parameters to be passed to the compiler.
3422 For example, the application might need an additional header path.
3423 You can accomplish this by adding to the
3424 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3425 The following example shows this:
3426 <literallayout class='monospaced'>
3427 CFLAGS_prepend = "-I ${S}/include "
3428 </literallayout>
3429 </para>
3430
3431 <para>
3432 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3433 <literallayout class='monospaced'>
3434 SUMMARY = "Tools for managing memory technology devices"
3435 SECTION = "base"
3436 DEPENDS = "zlib lzo e2fsprogs util-linux"
3437 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3438 LICENSE = "GPLv2+"
3439 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3440 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3441
3442 # Use the latest version at 26 Oct, 2013
3443 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3444 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3445 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3446 "
3447
3448 PV = "1.5.1+git${SRCPV}"
3449
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003450 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003451
3452 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3453
3454 do_install () {
3455 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3456 }
3457
3458 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3459
3460 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3461 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3462 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3463
3464 PARALLEL_MAKE = ""
3465
3466 BBCLASSEXTEND = "native"
3467 </literallayout>
3468 </para>
3469 </section>
3470
3471 <section id='splitting-an-application-into-multiple-packages'>
3472 <title>Splitting an Application into Multiple Packages</title>
3473
3474 <para>
3475 You can use the variables
3476 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3477 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3478 to split an application into multiple packages.
3479 </para>
3480
3481 <para>
3482 Following is an example that uses the <filename>libxpm</filename> recipe.
3483 By default, this recipe generates a single package that contains the library along
3484 with a few binaries.
3485 You can modify the recipe to split the binaries into separate packages:
3486 <literallayout class='monospaced'>
3487 require xorg-lib-common.inc
3488
3489 SUMMARY = "Xpm: X Pixmap extension library"
3490 LICENSE = "BSD"
3491 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3492 DEPENDS += "libxext libsm libxt"
3493 PE = "1"
3494
3495 XORG_PN = "libXpm"
3496
3497 PACKAGES =+ "sxpm cxpm"
3498 FILES_cxpm = "${bindir}/cxpm"
3499 FILES_sxpm = "${bindir}/sxpm"
3500 </literallayout>
3501 </para>
3502
3503 <para>
3504 In the previous example, we want to ship the <filename>sxpm</filename>
3505 and <filename>cxpm</filename> binaries in separate packages.
3506 Since <filename>bindir</filename> would be packaged into the main
3507 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3508 package by default, we prepend the <filename>PACKAGES</filename>
3509 variable so additional package names are added to the start of list.
3510 This results in the extra <filename>FILES_*</filename>
3511 variables then containing information that define which files and
3512 directories go into which packages.
3513 Files included by earlier packages are skipped by latter packages.
3514 Thus, the main <filename>PN</filename> package
3515 does not include the above listed files.
3516 </para>
3517 </section>
3518
3519 <section id='packaging-externally-produced-binaries'>
3520 <title>Packaging Externally Produced Binaries</title>
3521
3522 <para>
3523 Sometimes, you need to add pre-compiled binaries to an
3524 image.
3525 For example, suppose that binaries for proprietary code
3526 exist, which are created by a particular division of a
3527 company.
3528 Your part of the company needs to use those binaries as
3529 part of an image that you are building using the
3530 OpenEmbedded build system.
3531 Since you only have the binaries and not the source code,
3532 you cannot use a typical recipe that expects to fetch the
3533 source specified in
3534 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3535 and then compile it.
3536 </para>
3537
3538 <para>
3539 One method is to package the binaries and then install them
3540 as part of the image.
3541 Generally, it is not a good idea to package binaries
3542 since, among other things, it can hinder the ability to
3543 reproduce builds and could lead to compatibility problems
3544 with ABI in the future.
3545 However, sometimes you have no choice.
3546 </para>
3547
3548 <para>
3549 The easiest solution is to create a recipe that uses
3550 the
3551 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3552 class and to be sure that you are using default locations
3553 for build artifacts.
3554 In most cases, the <filename>bin_package</filename> class
3555 handles "skipping" the configure and compile steps as well
3556 as sets things up to grab packages from the appropriate
3557 area.
3558 In particular, this class sets <filename>noexec</filename>
3559 on both the
3560 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3561 and
3562 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3563 tasks, sets
3564 <filename>FILES_${PN}</filename> to "/" so that it picks
3565 up all files, and sets up a
3566 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3567 task, which effectively copies all files from
3568 <filename>${S}</filename> to <filename>${D}</filename>.
3569 The <filename>bin_package</filename> class works well when
3570 the files extracted into <filename>${S}</filename> are
3571 already laid out in the way they should be laid out
3572 on the target.
3573 For more information on these variables, see the
3574 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3575 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3576 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3577 and
3578 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3579 variables in the Yocto Project Reference Manual's variable
3580 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003581 <note><title>Notes</title>
3582 <itemizedlist>
3583 <listitem><para>
3584 Using
3585 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3586 is a good idea even for components distributed
3587 in binary form, and is often necessary for
3588 shared libraries.
3589 For a shared library, listing the library
3590 dependencies in
3591 <filename>DEPENDS</filename> makes sure that
3592 the libraries are available in the staging
3593 sysroot when other recipes link against the
3594 library, which might be necessary for
3595 successful linking.
3596 </para></listitem>
3597 <listitem><para>
3598 Using <filename>DEPENDS</filename> also
3599 allows runtime dependencies between packages
3600 to be added automatically.
3601 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003602 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3603 section in the Yocto Project Overview and
3604 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003605 </para></listitem>
3606 </itemizedlist>
3607 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003608 </para>
3609
3610 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003611 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003612 class, you need to be sure you are doing the following:
3613 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003614 <listitem><para>
3615 Create a recipe where the
3616 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3617 and
3618 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3619 tasks do nothing:
3620 It is usually sufficient to just not define these
3621 tasks in the recipe, because the default
3622 implementations do nothing unless a Makefile is
3623 found in
3624 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3625 </para>
3626
3627 <para>If
3628 <filename>${S}</filename> might contain a Makefile,
3629 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003630 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003631 <filename>do_compile</filename> with custom
3632 versions, then you can use the
3633 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3634 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003635 <literallayout class='monospaced'>
3636 do_configure[noexec] = "1"
3637 do_compile[noexec] = "1"
3638 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003639 Unlike
3640 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3641 using the flag preserves the dependency chain from
3642 the
3643 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>, <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>,
3644 and
3645 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3646 tasks to the
3647 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3648 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003649 </para></listitem>
3650 <listitem><para>Make sure your
3651 <filename>do_install</filename> task installs the
3652 binaries appropriately.
3653 </para></listitem>
3654 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003655 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3656 (usually
3657 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3658 to point to the files you have installed, which of
3659 course depends on where you have installed them
3660 and whether those files are in different locations
3661 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003662 </para></listitem>
3663 </itemizedlist>
3664 </para>
3665 </section>
3666 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003667
3668 <section id="following-recipe-style-guidelines">
3669 <title>Following Recipe Style Guidelines</title>
3670
3671 <para>
3672 When writing recipes, it is good to conform to existing
3673 style guidelines.
3674 The
3675 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3676 wiki page provides rough guidelines for preferred recipe style.
3677 </para>
3678
3679 <para>
3680 It is common for existing recipes to deviate a bit from this
3681 style.
3682 However, aiming for at least a consistent style is a good idea.
3683 Some practices, such as omitting spaces around
3684 <filename>=</filename> operators in assignments or ordering
3685 recipe components in an erratic way, are widely seen as poor
3686 style.
3687 </para>
3688 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003689
3690 <section id='recipe-syntax'>
3691 <title>Recipe Syntax</title>
3692
3693 <para>
3694 Understanding recipe file syntax is important for writing
3695 recipes.
3696 The following list overviews the basic items that make up a
3697 BitBake recipe file.
3698 For more complete BitBake syntax descriptions, see the
3699 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3700 chapter of the BitBake User Manual.
3701 <itemizedlist>
3702 <listitem><para>
3703 <emphasis>Variable Assignments and Manipulations:</emphasis>
3704 Variable assignments allow a value to be assigned to a
3705 variable.
3706 The assignment can be static text or might include
3707 the contents of other variables.
3708 In addition to the assignment, appending and prepending
3709 operations are also supported.</para>
3710
3711 <para>The following example shows some of the ways
3712 you can use variables in recipes:
3713 <literallayout class='monospaced'>
3714 S = "${WORKDIR}/postfix-${PV}"
3715 CFLAGS += "-DNO_ASM"
3716 SRC_URI_append = " file://fixup.patch"
3717 </literallayout>
3718 </para></listitem>
3719 <listitem><para>
3720 <emphasis>Functions:</emphasis>
3721 Functions provide a series of actions to be performed.
3722 You usually use functions to override the default
3723 implementation of a task function or to complement
3724 a default function (i.e. append or prepend to an
3725 existing function).
3726 Standard functions use <filename>sh</filename> shell
3727 syntax, although access to OpenEmbedded variables and
3728 internal methods are also available.</para>
3729
3730 <para>The following is an example function from the
3731 <filename>sed</filename> recipe:
3732 <literallayout class='monospaced'>
3733 do_install () {
3734 autotools_do_install
3735 install -d ${D}${base_bindir}
3736 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3737 rmdir ${D}${bindir}/
3738 }
3739 </literallayout>
3740 It is also possible to implement new functions that
3741 are called between existing tasks as long as the
3742 new functions are not replacing or complementing the
3743 default functions.
3744 You can implement functions in Python
3745 instead of shell.
3746 Both of these options are not seen in the majority of
3747 recipes.
3748 </para></listitem>
3749 <listitem><para><emphasis>Keywords:</emphasis>
3750 BitBake recipes use only a few keywords.
3751 You use keywords to include common
3752 functions (<filename>inherit</filename>), load parts
3753 of a recipe from other files
3754 (<filename>include</filename> and
3755 <filename>require</filename>) and export variables
3756 to the environment (<filename>export</filename>).
3757 </para>
3758
3759 <para>The following example shows the use of some of
3760 these keywords:
3761 <literallayout class='monospaced'>
3762 export POSTCONF = "${STAGING_BINDIR}/postconf"
3763 inherit autoconf
3764 require otherfile.inc
3765 </literallayout>
3766 </para></listitem>
3767 <listitem><para>
3768 <emphasis>Comments (#):</emphasis>
3769 Any lines that begin with the hash character
3770 (<filename>#</filename>) are treated as comment lines
3771 and are ignored:
3772 <literallayout class='monospaced'>
3773 # This is a comment
3774 </literallayout>
3775 </para></listitem>
3776 </itemizedlist>
3777 </para>
3778
3779 <para>
3780 This next list summarizes the most important and most commonly
3781 used parts of the recipe syntax.
3782 For more information on these parts of the syntax, you can
3783 reference the
3784 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3785 chapter in the BitBake User Manual.
3786 <itemizedlist>
3787 <listitem><para>
3788 <emphasis>Line Continuation (\):</emphasis>
3789 Use the backward slash (<filename>\</filename>)
3790 character to split a statement over multiple lines.
3791 Place the slash character at the end of the line that
3792 is to be continued on the next line:
3793 <literallayout class='monospaced'>
3794 VAR = "A really long \
3795 line"
3796 </literallayout>
3797 <note>
3798 You cannot have any characters including spaces
3799 or tabs after the slash character.
3800 </note>
3801 </para></listitem>
3802 <listitem><para>
3803 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3804 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3805 syntax to access the contents of a variable:
3806 <literallayout class='monospaced'>
3807 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3808 </literallayout>
3809 <note>
3810 It is important to understand that the value of a
3811 variable expressed in this form does not get
3812 substituted automatically.
3813 The expansion of these expressions happens
3814 on-demand later (e.g. usually when a function that
3815 makes reference to the variable executes).
3816 This behavior ensures that the values are most
3817 appropriate for the context in which they are
3818 finally used.
3819 On the rare occasion that you do need the variable
3820 expression to be expanded immediately, you can use
3821 the <filename>:=</filename> operator instead of
3822 <filename>=</filename> when you make the
3823 assignment, but this is not generally needed.
3824 </note>
3825 </para></listitem>
3826 <listitem><para>
3827 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3828 Use double quotes around values in all variable
3829 assignments (e.g.
3830 <filename>"<replaceable>value</replaceable>"</filename>).
3831 Following is an example:
3832 <literallayout class='monospaced'>
3833 VAR1 = "${OTHERVAR}"
3834 VAR2 = "The version is ${PV}"
3835 </literallayout>
3836 </para></listitem>
3837 <listitem><para>
3838 <emphasis>Conditional Assignment (?=):</emphasis>
3839 Conditional assignment is used to assign a
3840 value to a variable, but only when the variable is
3841 currently unset.
3842 Use the question mark followed by the equal sign
3843 (<filename>?=</filename>) to make a "soft" assignment
3844 used for conditional assignment.
3845 Typically, "soft" assignments are used in the
3846 <filename>local.conf</filename> file for variables
3847 that are allowed to come through from the external
3848 environment.
3849 </para>
3850
3851 <para>Here is an example where
3852 <filename>VAR1</filename> is set to "New value" if
3853 it is currently empty.
3854 However, if <filename>VAR1</filename> has already been
3855 set, it remains unchanged:
3856 <literallayout class='monospaced'>
3857 VAR1 ?= "New value"
3858 </literallayout>
3859 In this next example, <filename>VAR1</filename>
3860 is left with the value "Original value":
3861 <literallayout class='monospaced'>
3862 VAR1 = "Original value"
3863 VAR1 ?= "New value"
3864 </literallayout>
3865 </para></listitem>
3866 <listitem><para>
3867 <emphasis>Appending (+=):</emphasis>
3868 Use the plus character followed by the equals sign
3869 (<filename>+=</filename>) to append values to existing
3870 variables.
3871 <note>
3872 This operator adds a space between the existing
3873 content of the variable and the new content.
3874 </note></para>
3875
3876 <para>Here is an example:
3877 <literallayout class='monospaced'>
3878 SRC_URI += "file://fix-makefile.patch"
3879 </literallayout>
3880 </para></listitem>
3881 <listitem><para>
3882 <emphasis>Prepending (=+):</emphasis>
3883 Use the equals sign followed by the plus character
3884 (<filename>=+</filename>) to prepend values to existing
3885 variables.
3886 <note>
3887 This operator adds a space between the new content
3888 and the existing content of the variable.
3889 </note></para>
3890
3891 <para>Here is an example:
3892 <literallayout class='monospaced'>
3893 VAR =+ "Starts"
3894 </literallayout>
3895 </para></listitem>
3896 <listitem><para>
3897 <emphasis>Appending (_append):</emphasis>
3898 Use the <filename>_append</filename> operator to
3899 append values to existing variables.
3900 This operator does not add any additional space.
3901 Also, the operator is applied after all the
3902 <filename>+=</filename>, and
3903 <filename>=+</filename> operators have been applied and
3904 after all <filename>=</filename> assignments have
3905 occurred.
3906 </para>
3907
3908 <para>The following example shows the space being
3909 explicitly added to the start to ensure the appended
3910 value is not merged with the existing value:
3911 <literallayout class='monospaced'>
3912 SRC_URI_append = " file://fix-makefile.patch"
3913 </literallayout>
3914 You can also use the <filename>_append</filename>
3915 operator with overrides, which results in the actions
3916 only being performed for the specified target or
3917 machine:
3918 <literallayout class='monospaced'>
3919 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3920 </literallayout>
3921 </para></listitem>
3922 <listitem><para>
3923 <emphasis>Prepending (_prepend):</emphasis>
3924 Use the <filename>_prepend</filename> operator to
3925 prepend values to existing variables.
3926 This operator does not add any additional space.
3927 Also, the operator is applied after all the
3928 <filename>+=</filename>, and
3929 <filename>=+</filename> operators have been applied and
3930 after all <filename>=</filename> assignments have
3931 occurred.
3932 </para>
3933
3934 <para>The following example shows the space being
3935 explicitly added to the end to ensure the prepended
3936 value is not merged with the existing value:
3937 <literallayout class='monospaced'>
3938 CFLAGS_prepend = "-I${S}/myincludes "
3939 </literallayout>
3940 You can also use the <filename>_prepend</filename>
3941 operator with overrides, which results in the actions
3942 only being performed for the specified target or
3943 machine:
3944 <literallayout class='monospaced'>
3945 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
3946 </literallayout>
3947 </para></listitem>
3948 <listitem><para>
3949 <emphasis>Overrides:</emphasis>
3950 You can use overrides to set a value conditionally,
3951 typically based on how the recipe is being built.
3952 For example, to set the
3953 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
3954 variable's value to "standard/base" for any target
3955 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
3956 except for qemuarm where it should be set to
3957 "standard/arm-versatile-926ejs", you would do the
3958 following:
3959 <literallayout class='monospaced'>
3960 KBRANCH = "standard/base"
3961 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
3962 </literallayout>
3963 Overrides are also used to separate alternate values
3964 of a variable in other situations.
3965 For example, when setting variables such as
3966 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3967 and
3968 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
3969 that are specific to individual packages produced by
3970 a recipe, you should always use an override that
3971 specifies the name of the package.
3972 </para></listitem>
3973 <listitem><para>
3974 <emphasis>Indentation:</emphasis>
3975 Use spaces for indentation rather than than tabs.
3976 For shell functions, both currently work.
3977 However, it is a policy decision of the Yocto Project
3978 to use tabs in shell functions.
3979 Realize that some layers have a policy to use spaces
3980 for all indentation.
3981 </para></listitem>
3982 <listitem><para>
3983 <emphasis>Using Python for Complex Operations:</emphasis>
3984 For more advanced processing, it is possible to use
3985 Python code during variable assignments (e.g.
3986 search and replacement on a variable).</para>
3987
3988 <para>You indicate Python code using the
3989 <filename>${@<replaceable>python_code</replaceable>}</filename>
3990 syntax for the variable assignment:
3991 <literallayout class='monospaced'>
3992 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
3993 </literallayout>
3994 </para></listitem>
3995 <listitem><para>
3996 <emphasis>Shell Function Syntax:</emphasis>
3997 Write shell functions as if you were writing a shell
3998 script when you describe a list of actions to take.
3999 You should ensure that your script works with a generic
4000 <filename>sh</filename> and that it does not require
4001 any <filename>bash</filename> or other shell-specific
4002 functionality.
4003 The same considerations apply to various system
4004 utilities (e.g. <filename>sed</filename>,
4005 <filename>grep</filename>, <filename>awk</filename>,
4006 and so forth) that you might wish to use.
4007 If in doubt, you should check with multiple
4008 implementations - including those from BusyBox.
4009 </para></listitem>
4010 </itemizedlist>
4011 </para>
4012 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004013 </section>
4014
4015 <section id="platdev-newmachine">
4016 <title>Adding a New Machine</title>
4017
4018 <para>
4019 Adding a new machine to the Yocto Project is a straightforward
4020 process.
4021 This section describes how to add machines that are similar
4022 to those that the Yocto Project already supports.
4023 <note>
4024 Although well within the capabilities of the Yocto Project,
4025 adding a totally new architecture might require
4026 changes to <filename>gcc/glibc</filename> and to the site
4027 information, which is beyond the scope of this manual.
4028 </note>
4029 </para>
4030
4031 <para>
4032 For a complete example that shows how to add a new machine,
4033 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004034 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
4035 section in the Yocto Project Board Support Package (BSP)
4036 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004037 </para>
4038
4039 <section id="platdev-newmachine-conffile">
4040 <title>Adding the Machine Configuration File</title>
4041
4042 <para>
4043 To add a new machine, you need to add a new machine
4044 configuration file to the layer's
4045 <filename>conf/machine</filename> directory.
4046 This configuration file provides details about the device
4047 you are adding.
4048 </para>
4049
4050 <para>
4051 The OpenEmbedded build system uses the root name of the
4052 machine configuration file to reference the new machine.
4053 For example, given a machine configuration file named
4054 <filename>crownbay.conf</filename>, the build system
4055 recognizes the machine as "crownbay".
4056 </para>
4057
4058 <para>
4059 The most important variables you must set in your machine
4060 configuration file or include from a lower-level configuration
4061 file are as follows:
4062 <itemizedlist>
4063 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4064 (e.g. "arm")</para></listitem>
4065 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4066 </para></listitem>
4067 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4068 (e.g. "apm screen wifi")</para></listitem>
4069 </itemizedlist>
4070 </para>
4071
4072 <para>
4073 You might also need these variables:
4074 <itemizedlist>
4075 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4076 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4077 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4078 (e.g. "zImage")</para></listitem>
4079 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4080 (e.g. "tar.gz jffs2")</para></listitem>
4081 </itemizedlist>
4082 </para>
4083
4084 <para>
4085 You can find full details on these variables in the reference
4086 section.
4087 You can leverage existing machine <filename>.conf</filename>
4088 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4089 </para>
4090 </section>
4091
4092 <section id="platdev-newmachine-kernel">
4093 <title>Adding a Kernel for the Machine</title>
4094
4095 <para>
4096 The OpenEmbedded build system needs to be able to build a kernel
4097 for the machine.
4098 You need to either create a new kernel recipe for this machine,
4099 or extend an existing kernel recipe.
4100 You can find several kernel recipe examples in the
4101 Source Directory at
4102 <filename>meta/recipes-kernel/linux</filename>
4103 that you can use as references.
4104 </para>
4105
4106 <para>
4107 If you are creating a new kernel recipe, normal recipe-writing
4108 rules apply for setting up a
4109 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4110 Thus, you need to specify any necessary patches and set
4111 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4112 to point at the source code.
4113 You need to create a <filename>do_configure</filename> task that
4114 configures the unpacked kernel with a
4115 <filename>defconfig</filename> file.
4116 You can do this by using a <filename>make defconfig</filename>
4117 command or, more commonly, by copying in a suitable
4118 <filename>defconfig</filename> file and then running
4119 <filename>make oldconfig</filename>.
4120 By making use of <filename>inherit kernel</filename> and
4121 potentially some of the <filename>linux-*.inc</filename> files,
4122 most other functionality is centralized and the defaults of the
4123 class normally work well.
4124 </para>
4125
4126 <para>
4127 If you are extending an existing kernel recipe, it is usually
4128 a matter of adding a suitable <filename>defconfig</filename>
4129 file.
4130 The file needs to be added into a location similar to
4131 <filename>defconfig</filename> files used for other machines
4132 in a given kernel recipe.
4133 A possible way to do this is by listing the file in the
4134 <filename>SRC_URI</filename> and adding the machine to the
4135 expression in
4136 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4137 <literallayout class='monospaced'>
4138 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4139 </literallayout>
4140 For more information on <filename>defconfig</filename> files,
4141 see the
4142 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4143 section in the Yocto Project Linux Kernel Development Manual.
4144 </para>
4145 </section>
4146
4147 <section id="platdev-newmachine-formfactor">
4148 <title>Adding a Formfactor Configuration File</title>
4149
4150 <para>
4151 A formfactor configuration file provides information about the
4152 target hardware for which the image is being built and information that
4153 the build system cannot obtain from other sources such as the kernel.
4154 Some examples of information contained in a formfactor configuration file include
4155 framebuffer orientation, whether or not the system has a keyboard,
4156 the positioning of the keyboard in relation to the screen, and
4157 the screen resolution.
4158 </para>
4159
4160 <para>
4161 The build system uses reasonable defaults in most cases.
4162 However, if customization is
4163 necessary, you need to create a <filename>machconfig</filename> file
4164 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4165 directory.
4166 This directory contains directories for specific machines such as
4167 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4168 For information about the settings available and the defaults, see the
4169 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4170 same area.
4171 </para>
4172
4173 <para>
4174 Following is an example for "qemuarm" machine:
4175 <literallayout class='monospaced'>
4176 HAVE_TOUCHSCREEN=1
4177 HAVE_KEYBOARD=1
4178
4179 DISPLAY_CAN_ROTATE=0
4180 DISPLAY_ORIENTATION=0
4181 #DISPLAY_WIDTH_PIXELS=640
4182 #DISPLAY_HEIGHT_PIXELS=480
4183 #DISPLAY_BPP=16
4184 DISPLAY_DPI=150
4185 DISPLAY_SUBPIXEL_ORDER=vrgb
4186 </literallayout>
4187 </para>
4188 </section>
4189 </section>
4190
Brad Bishop316dfdd2018-06-25 12:45:53 -04004191 <section id='gs-upgrading-recipes'>
4192 <title>Upgrading Recipes</title>
4193
4194 <para>
4195 Over time, upstream developers publish new versions for software
4196 built by layer recipes.
4197 It is recommended to keep recipes up-to-date with upstream
4198 version releases.
4199 You can use the Automated Upgrade Helper (AUH) to set up
4200 automatic version upgrades.
4201 Alternatively, you can use <filename>devtool upgrade</filename>
4202 to set up semi-automatic version upgrades.
4203 Finally, you can even manually upgrade a recipe by editing the
4204 recipe itself.
4205 </para>
4206
4207 <section id='gs-using-the-auto-upgrade-helper'>
4208 <title>Using the Auto Upgrade Helper (AUH)</title>
4209
4210 <para>
4211 The AUH utility works in conjunction with the
4212 OpenEmbedded build system in order to automatically generate
4213 upgrades for recipes based on new versions being
4214 published upstream.
4215 Use AUH when you want to create a service that performs the
4216 upgrades automatically and optionally sends you an email with
4217 the results.
4218 </para>
4219
4220 <para>
4221 AUH allows you to update several recipes with a single use.
4222 You can also optionally perform build and integration tests
4223 using images with the results saved to your hard drive and
4224 emails of results optionally sent to recipe maintainers.
4225 Finally, AUH creates Git commits with appropriate commit
4226 messages in the layer's tree for the changes made to recipes.
4227 <note>
4228 Conditions do exist when you should not use AUH to upgrade
4229 recipes and you should instead use either
4230 <filename>devtool upgrade</filename> or upgrade your
4231 recipes manually:
4232 <itemizedlist>
4233 <listitem><para>
4234 When AUH cannot complete the upgrade sequence.
4235 This situation usually results because custom
4236 patches carried by the recipe cannot be
4237 automatically rebased to the new version.
4238 In this case, <filename>devtool upgrade</filename>
4239 allows you to manually resolve conflicts.
4240 </para></listitem>
4241 <listitem><para>
4242 When for any reason you want fuller control over
4243 the upgrade process.
4244 For example, when you want special arrangements
4245 for testing.
4246 </para></listitem>
4247 </itemizedlist>
4248 </note>
4249 </para>
4250
4251 <para>
4252 The following steps describe how to set up the AUH utility:
4253 <orderedlist>
4254 <listitem><para>
4255 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4256 You need to be sure that your development host is
4257 set up to use the Yocto Project.
4258 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004259 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004260 section.
4261 </para></listitem>
4262 <listitem><para>
4263 <emphasis>Make Sure Git is Configured:</emphasis>
4264 The AUH utility requires Git to be configured because
4265 AUH uses Git to save upgrades.
4266 Thus, you must have Git user and email configured.
4267 The following command shows your configurations:
4268 <literallayout class='monospaced'>
4269 $ git config --list
4270 </literallayout>
4271 If you do not have the user and email configured, you
4272 can use the following commands to do so:
4273 <literallayout class='monospaced'>
4274 $ git config --global user.name <replaceable>some_name</replaceable>
4275 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4276 </literallayout>
4277 </para></listitem>
4278 <listitem><para>
4279 <emphasis>Clone the AUH Repository:</emphasis>
4280 To use AUH, you must clone the repository onto your
4281 development host.
4282 The following command uses Git to create a local
4283 copy of the repository on your system:
4284 <literallayout class='monospaced'>
4285 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4286 Cloning into 'auto-upgrade-helper'...
4287 remote: Counting objects: 768, done.
4288 remote: Compressing objects: 100% (300/300), done.
4289 remote: Total 768 (delta 499), reused 703 (delta 434)
4290 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4291 Resolving deltas: 100% (499/499), done.
4292 Checking connectivity... done.
4293 </literallayout>
4294 AUH is not part of the
4295 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4296 or
4297 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4298 repositories.
4299 </para></listitem>
4300 <listitem><para>
4301 <emphasis>Create a Dedicated Build Directory:</emphasis>
4302 Run the
4303 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4304 script to create a fresh build directory that you
4305 use exclusively for running the AUH utility:
4306 <literallayout class='monospaced'>
4307 $ cd ~/poky
4308 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4309 </literallayout>
4310 Re-using an existing build directory and its
4311 configurations is not recommended as existing settings
4312 could cause AUH to fail or behave undesirably.
4313 </para></listitem>
4314 <listitem><para>
4315 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4316 Several settings need to exist in the
4317 <filename>local.conf</filename> file in the build
4318 directory you just created for AUH.
4319 Make these following configurations:
4320 <itemizedlist>
4321 <listitem><para>
4322 Enable "distrodata" as follows:
4323 <literallayout class='monospaced'>
4324 INHERIT =+ "distrodata"
4325 </literallayout>
4326 </para></listitem>
4327 <listitem><para>
4328 If you want to enable
4329 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4330 which is optional, you need the following
4331 lines in the
4332 <filename>conf/local.conf</filename> file:
4333 <literallayout class='monospaced'>
4334 INHERIT =+ "buildhistory"
4335 BUILDHISTORY_COMMIT = "1"
4336 </literallayout>
4337 With this configuration and a successful
4338 upgrade, a build history "diff" file appears in
4339 the
4340 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4341 file found in your build directory.
4342 </para></listitem>
4343 <listitem><para>
4344 If you want to enable testing through the
4345 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4346 class, which is optional, you need to have the
4347 following set in your
4348 <filename>conf/local.conf</filename> file:
4349 <literallayout class='monospaced'>
4350 INHERIT += "testimage"
4351 </literallayout>
4352 <note>
4353 If your distro does not enable by default
4354 ptest, which Poky does, you need the
4355 following in your
4356 <filename>local.conf</filename> file:
4357 <literallayout class='monospaced'>
4358 DISTRO_FEATURES_append = " ptest"
4359 </literallayout>
4360 </note>
4361 </para></listitem>
4362 </itemizedlist>
4363 </para></listitem>
4364 <listitem><para>
4365 <emphasis>Optionally Start a vncserver:</emphasis>
4366 If you are running in a server without an X11 session,
4367 you need to start a vncserver:
4368 <literallayout class='monospaced'>
4369 $ vncserver :1
4370 $ export DISPLAY=:1
4371 </literallayout>
4372 </para></listitem>
4373 <listitem><para>
4374 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4375 You need to have the
4376 <filename>upgrade-helper/upgrade-helper.conf</filename>
4377 configuration file in your build directory.
4378 You can find a sample configuration file in the
4379 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4380 </para>
4381
4382 <para>Read through the sample file and make
4383 configurations as needed.
4384 For example, if you enabled build history in your
4385 <filename>local.conf</filename> as described earlier,
4386 you must enable it in
4387 <filename>upgrade-helper.conf</filename>.</para>
4388
4389 <para>Also, if you are using the default
4390 <filename>maintainers.inc</filename> file supplied
4391 with Poky and located in
4392 <filename>meta-yocto</filename> and you do not set a
4393 "maintainers_whitelist" or "global_maintainer_override"
4394 in the <filename>upgrade-helper.conf</filename>
4395 configuration, and you specify "-e all" on the
4396 AUH command-line, the utility automatically sends out
4397 emails to all the default maintainers.
4398 Please avoid this.
4399 </para></listitem>
4400 </orderedlist>
4401 </para>
4402
4403 <para>
4404 This next set of examples describes how to use the AUH:
4405 <itemizedlist>
4406 <listitem><para>
4407 <emphasis>Upgrading a Specific Recipe:</emphasis>
4408 To upgrade a specific recipe, use the following
4409 form:
4410 <literallayout class='monospaced'>
4411 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4412 </literallayout>
4413 For example, this command upgrades the
4414 <filename>xmodmap</filename> recipe:
4415 <literallayout class='monospaced'>
4416 $ upgrade-helper.py xmodmap
4417 </literallayout>
4418 </para></listitem>
4419 <listitem><para>
4420 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4421 To upgrade a specific recipe to a particular version,
4422 use the following form:
4423 <literallayout class='monospaced'>
4424 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4425 </literallayout>
4426 For example, this command upgrades the
4427 <filename>xmodmap</filename> recipe to version
4428 1.2.3:
4429 <literallayout class='monospaced'>
4430 $ upgrade-helper.py xmodmap -t 1.2.3
4431 </literallayout>
4432 </para></listitem>
4433 <listitem><para>
4434 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4435 To upgrade all recipes to their most recent versions
4436 and suppress the email notifications, use the following
4437 command:
4438 <literallayout class='monospaced'>
4439 $ upgrade-helper.py all
4440 </literallayout>
4441 </para></listitem>
4442 <listitem><para>
4443 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4444 To upgrade all recipes to their most recent versions
4445 and send email messages to maintainers for each
4446 attempted recipe as well as a status email, use the
4447 following command:
4448 <literallayout class='monospaced'>
4449 $ upgrade-helper.py -e all
4450 </literallayout>
4451 </para></listitem>
4452 </itemizedlist>
4453 </para>
4454
4455 <para>
4456 Once you have run the AUH utility, you can find the results
4457 in the AUH build directory:
4458 <literallayout class='monospaced'>
4459 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4460 </literallayout>
4461 The AUH utility also creates recipe update commits from
4462 successful upgrade attempts in the layer tree.
4463 </para>
4464
4465 <para>
4466 You can easily set up to run the AUH utility on a regular
4467 basis by using a cron job.
4468 See the
4469 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4470 file distributed with the utility for an example.
4471 </para>
4472 </section>
4473
4474 <section id='gs-using-devtool-upgrade'>
4475 <title>Using <filename>devtool upgrade</filename></title>
4476
4477 <para>
4478 As mentioned earlier, an alternative method for upgrading
4479 recipes to newer versions is to use
4480 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4481 You can read about <filename>devtool upgrade</filename> in
4482 general in the
4483 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software'>Use <filename>devtool upgrade</filename> to Create a Version of the Recipe that Supports a Newer Version of the Software</ulink>"
4484 section in the Yocto Project Application Development and the
4485 Extensible Software Development Kit (eSDK) Manual.
4486 </para>
4487
4488 <para>
4489 To see all the command-line options available with
4490 <filename>devtool upgrade</filename>, use the following help
4491 command:
4492 <literallayout class='monospaced'>
4493 $ devtool upgrade -h
4494 </literallayout>
4495 </para>
4496
4497 <para>
4498 If you want to find out what version a recipe is currently at
4499 upstream without any attempt to upgrade your local version of
4500 the recipe, you can use the following command:
4501 <literallayout class='monospaced'>
4502 $ devtool latest-version <replaceable>recipe_name</replaceable>
4503 </literallayout>
4504 </para>
4505
4506 <para>
4507 As mentioned in the previous section describing AUH,
4508 <filename>devtool upgrade</filename> works in a
4509 less-automated manner than AUH.
4510 Specifically, <filename>devtool upgrade</filename> only
4511 works on a single recipe that you name on the command line,
4512 cannot perform build and integration testing using images,
4513 and does not automatically generate commits for changes in
4514 the source tree.
4515 Despite all these "limitations",
4516 <filename>devtool upgrade</filename> updates the recipe file
4517 to the new upstream version and attempts to rebase custom
4518 patches contained by the recipe as needed.
4519 <note>
4520 AUH uses much of <filename>devtool upgrade</filename>
4521 behind the scenes making AUH somewhat of a "wrapper"
4522 application for <filename>devtool upgrade</filename>.
4523 </note>
4524 </para>
4525
4526 <para>
4527 A typical scenario involves having used Git to clone an
4528 upstream repository that you use during build operations.
4529 Because you are (or have) built the recipe in the past, the
4530 layer is likely added to your configuration already.
4531 If for some reason, the layer is not added, you could add
4532 it easily using the
4533 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4534 script.
4535 For example, suppose you use the <filename>nano.bb</filename>
4536 recipe from the <filename>meta-oe</filename> layer in the
4537 <filename>meta-openembedded</filename> repository.
4538 For this example, assume that the layer has been cloned into
4539 following area:
4540 <literallayout class='monospaced'>
4541 /home/scottrif/meta-openembedded
4542 </literallayout>
4543 The following command from your
4544 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4545 adds the layer to your build configuration (i.e.
4546 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4547 <literallayout class='monospaced'>
4548 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4549 NOTE: Starting bitbake server...
4550 Parsing recipes: 100% |##########################################| Time: 0:00:55
4551 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4552 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4553 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4554 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4555 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4556 </literallayout>
4557 For this example, assume that the <filename>nano.bb</filename>
4558 recipe that is upstream has a 2.9.3 version number.
4559 However, the version in the local repository is 2.7.4.
4560 The following command from your build directory automatically
4561 upgrades the recipe for you:
4562 <note>
4563 Using the <filename>-V</filename> option is not necessary.
4564 Omitting the version number causes
4565 <filename>devtool upgrade</filename> to upgrade the recipe
4566 to the most recent version.
4567 </note>
4568 <literallayout class='monospaced'>
4569 $ devtool upgrade nano -V 2.9.3
4570 NOTE: Starting bitbake server...
4571 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4572 Parsing recipes: 100% |##########################################| Time: 0:00:46
4573 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4574 NOTE: Extracting current version source...
4575 NOTE: Resolving any missing task queue dependencies
4576 .
4577 .
4578 .
4579 NOTE: Executing SetScene Tasks
4580 NOTE: Executing RunQueue Tasks
4581 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4582 Adding changed files: 100% |#####################################| Time: 0:00:00
4583 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4584 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4585 </literallayout>
4586 Continuing with this example, you can use
4587 <filename>devtool build</filename> to build the newly upgraded
4588 recipe:
4589 <literallayout class='monospaced'>
4590 $ devtool build nano
4591 NOTE: Starting bitbake server...
4592 Loading cache: 100% |################################################################################################| Time: 0:00:01
4593 Loaded 2040 entries from dependency cache.
4594 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4595 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4596 NOTE: Resolving any missing task queue dependencies
4597 .
4598 .
4599 .
4600 NOTE: Executing SetScene Tasks
4601 NOTE: Executing RunQueue Tasks
4602 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4603 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4604 </literallayout>
4605 Within the <filename>devtool upgrade</filename> workflow,
4606 opportunity exists to deploy and test your rebuilt software.
4607 For this example, however, running
4608 <filename>devtool finish</filename> cleans up the workspace
4609 once the source in your workspace is clean.
4610 This usually means using Git to stage and submit commits
4611 for the changes generated by the upgrade process.
4612 </para>
4613
4614 <para>
4615 Once the tree is clean, you can clean things up in this
4616 example with the following command from the
4617 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4618 directory:
4619 <literallayout class='monospaced'>
4620 $ devtool finish nano meta-oe
4621 NOTE: Starting bitbake server...
4622 Loading cache: 100% |################################################################################################| Time: 0:00:00
4623 Loaded 2040 entries from dependency cache.
4624 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4625 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4626 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4627 NOTE: Updating recipe nano_2.9.3.bb
4628 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4629 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4630 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4631 </literallayout>
4632 Using the <filename>devtool finish</filename> command cleans
4633 up the workspace and creates a patch file based on your
4634 commits.
4635 The tool puts all patch files back into the source directory
4636 in a sub-directory named <filename>nano</filename> in this
4637 case.
4638 </para>
4639 </section>
4640
4641 <section id='dev-manually-upgrading-a-recipe'>
4642 <title>Manually Upgrading a Recipe</title>
4643
4644 <para>
4645 If for some reason you choose not to upgrade recipes using the
4646 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4647 or by using
4648 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4649 you can manually edit the recipe files to upgrade the versions.
4650 <note><title>Caution</title>
4651 Manually updating multiple recipes scales poorly and
4652 involves many steps.
4653 The recommendation to upgrade recipe versions is through
4654 AUH or <filename>devtool upgrade</filename>, both of which
4655 automate some steps and provide guidance for others needed
4656 for the manual process.
4657 </note>
4658 </para>
4659
4660 <para>
4661 To manually upgrade recipe versions, follow these general steps:
4662 <orderedlist>
4663 <listitem><para>
4664 <emphasis>Change the Version:</emphasis>
4665 Rename the recipe such that the version (i.e. the
4666 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4667 part of the recipe name) changes appropriately.
4668 If the version is not part of the recipe name, change
4669 the value as it is set for <filename>PV</filename>
4670 within the recipe itself.
4671 </para></listitem>
4672 <listitem><para>
4673 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4674 If the source code your recipe builds is fetched from
4675 Git or some other version control system, update
4676 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4677 to point to the commit hash that matches the new
4678 version.
4679 </para></listitem>
4680 <listitem><para>
4681 <emphasis>Build the Software:</emphasis>
4682 Try to build the recipe using BitBake.
4683 Typical build failures include the following:
4684 <itemizedlist>
4685 <listitem><para>
4686 License statements were updated for the new
4687 version.
4688 For this case, you need to review any changes
4689 to the license and update the values of
4690 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4691 and
4692 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4693 as needed.
4694 <note>
4695 License changes are often inconsequential.
4696 For example, the license text's copyright
4697 year might have changed.
4698 </note>
4699 </para></listitem>
4700 <listitem><para>
4701 Custom patches carried by the older version of
4702 the recipe might fail to apply to the new
4703 version.
4704 For these cases, you need to review the
4705 failures.
4706 Patches might not be necessary for the new
4707 version of the software if the upgraded version
4708 has fixed those issues.
4709 If a patch is necessary and failing, you need
4710 to rebase it into the new version.
4711 </para></listitem>
4712 </itemizedlist>
4713 </para></listitem>
4714 <listitem><para>
4715 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4716 Once you successfully build the new software for a
4717 given architecture, you could test the build for
4718 other architectures by changing the
4719 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4720 variable and rebuilding the software.
4721 This optional step is especially important if the
4722 recipe is to be released publicly.
4723 </para></listitem>
4724 <listitem><para>
4725 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4726 Checking both these reveals if new features exist that
4727 could break backwards-compatibility.
4728 If so, you need to take steps to mitigate or eliminate
4729 that situation.
4730 </para></listitem>
4731 <listitem><para>
4732 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4733 If you want, you can test the new software by booting
4734 it onto actual hardware.
4735 </para></listitem>
4736 <listitem><para>
4737 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4738 After all builds work and any testing is successful,
4739 you can create commits for any changes in the layer
4740 holding your upgraded recipe.
4741 </para></listitem>
4742 </orderedlist>
4743 </para>
4744 </section>
4745 </section>
4746
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004747 <section id='finding-the-temporary-source-code'>
4748 <title>Finding Temporary Source Code</title>
4749
4750 <para>
4751 You might find it helpful during development to modify the
4752 temporary source code used by recipes to build packages.
4753 For example, suppose you are developing a patch and you need to
4754 experiment a bit to figure out your solution.
4755 After you have initially built the package, you can iteratively
4756 tweak the source code, which is located in the
4757 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4758 and then you can force a re-compile and quickly test your altered
4759 code.
4760 Once you settle on a solution, you can then preserve your changes
4761 in the form of patches.
4762 </para>
4763
4764 <para>
4765 During a build, the unpacked temporary source code used by recipes
4766 to build packages is available in the Build Directory as
4767 defined by the
4768 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4769 variable.
4770 Below is the default value for the <filename>S</filename> variable
4771 as defined in the
4772 <filename>meta/conf/bitbake.conf</filename> configuration file
4773 in the
4774 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4775 <literallayout class='monospaced'>
4776 S = "${WORKDIR}/${BP}"
4777 </literallayout>
4778 You should be aware that many recipes override the
4779 <filename>S</filename> variable.
4780 For example, recipes that fetch their source from Git usually set
4781 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4782 <note>
4783 The
4784 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4785 represents the base recipe name, which consists of the name
4786 and version:
4787 <literallayout class='monospaced'>
4788 BP = "${BPN}-${PV}"
4789 </literallayout>
4790 </note>
4791 </para>
4792
4793 <para>
4794 The path to the work directory for the recipe
4795 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4796 is defined as follows:
4797 <literallayout class='monospaced'>
4798 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4799 </literallayout>
4800 The actual directory depends on several things:
4801 <itemizedlist>
4802 <listitem><para>
4803 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4804 The top-level build output directory.
4805 </para></listitem>
4806 <listitem><para>
4807 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4808 The target system identifier.
4809 </para></listitem>
4810 <listitem><para>
4811 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4812 The recipe name.
4813 </para></listitem>
4814 <listitem><para>
4815 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4816 The epoch - (if
4817 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4818 is not specified, which is usually the case for most
4819 recipes, then <filename>EXTENDPE</filename> is blank).
4820 </para></listitem>
4821 <listitem><para>
4822 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4823 The recipe version.
4824 </para></listitem>
4825 <listitem><para>
4826 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4827 The recipe revision.
4828 </para></listitem>
4829 </itemizedlist>
4830 </para>
4831
4832 <para>
4833 As an example, assume a Source Directory top-level folder
4834 named <filename>poky</filename>, a default Build Directory at
4835 <filename>poky/build</filename>, and a
4836 <filename>qemux86-poky-linux</filename> machine target
4837 system.
4838 Furthermore, suppose your recipe is named
4839 <filename>foo_1.3.0.bb</filename>.
4840 In this case, the work directory the build system uses to
4841 build the package would be as follows:
4842 <literallayout class='monospaced'>
4843 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4844 </literallayout>
4845 </para>
4846 </section>
4847
4848 <section id="using-a-quilt-workflow">
4849 <title>Using Quilt in Your Workflow</title>
4850
4851 <para>
4852 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4853 is a powerful tool that allows you to capture source code changes
4854 without having a clean source tree.
4855 This section outlines the typical workflow you can use to modify
4856 source code, test changes, and then preserve the changes in the
4857 form of a patch all using Quilt.
4858 <note><title>Tip</title>
4859 With regard to preserving changes to source files, if you
4860 clean a recipe or have <filename>rm_work</filename> enabled,
4861 the
4862 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4863 as described in the Yocto Project Application Development
4864 and the Extensible Software Development Kit (eSDK) manual
4865 is a safer development flow than the flow that uses Quilt.
4866 </note>
4867 </para>
4868
4869 <para>
4870 Follow these general steps:
4871 <orderedlist>
4872 <listitem><para>
4873 <emphasis>Find the Source Code:</emphasis>
4874 Temporary source code used by the OpenEmbedded build system
4875 is kept in the
4876 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4877 See the
4878 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4879 section to learn how to locate the directory that has the
4880 temporary source code for a particular package.
4881 </para></listitem>
4882 <listitem><para>
4883 <emphasis>Change Your Working Directory:</emphasis>
4884 You need to be in the directory that has the temporary
4885 source code.
4886 That directory is defined by the
4887 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4888 variable.</para></listitem>
4889 <listitem><para>
4890 <emphasis>Create a New Patch:</emphasis>
4891 Before modifying source code, you need to create a new
4892 patch.
4893 To create a new patch file, use
4894 <filename>quilt new</filename> as below:
4895 <literallayout class='monospaced'>
4896 $ quilt new my_changes.patch
4897 </literallayout>
4898 </para></listitem>
4899 <listitem><para>
4900 <emphasis>Notify Quilt and Add Files:</emphasis>
4901 After creating the patch, you need to notify Quilt about
4902 the files you plan to edit.
4903 You notify Quilt by adding the files to the patch you
4904 just created:
4905 <literallayout class='monospaced'>
4906 $ quilt add file1.c file2.c file3.c
4907 </literallayout>
4908 </para></listitem>
4909 <listitem><para>
4910 <emphasis>Edit the Files:</emphasis>
4911 Make your changes in the source code to the files you added
4912 to the patch.
4913 </para></listitem>
4914 <listitem><para>
4915 <emphasis>Test Your Changes:</emphasis>
4916 Once you have modified the source code, the easiest way to
4917 test your changes is by calling the
4918 <filename>do_compile</filename> task as shown in the
4919 following example:
4920 <literallayout class='monospaced'>
4921 $ bitbake -c compile -f <replaceable>package</replaceable>
4922 </literallayout>
4923 The <filename>-f</filename> or <filename>--force</filename>
4924 option forces the specified task to execute.
4925 If you find problems with your code, you can just keep
4926 editing and re-testing iteratively until things work
4927 as expected.
4928 <note>
4929 All the modifications you make to the temporary
4930 source code disappear once you run the
4931 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4932 or
4933 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4934 tasks using BitBake (i.e.
4935 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4936 and
4937 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4938 Modifications will also disappear if you use the
4939 <filename>rm_work</filename> feature as described
4940 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004941 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4942 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004943 </note>
4944 </para></listitem>
4945 <listitem><para>
4946 <emphasis>Generate the Patch:</emphasis>
4947 Once your changes work as expected, you need to use Quilt
4948 to generate the final patch that contains all your
4949 modifications.
4950 <literallayout class='monospaced'>
4951 $ quilt refresh
4952 </literallayout>
4953 At this point, the <filename>my_changes.patch</filename>
4954 file has all your edits made to the
4955 <filename>file1.c</filename>, <filename>file2.c</filename>,
4956 and <filename>file3.c</filename> files.</para>
4957
4958 <para>You can find the resulting patch file in the
4959 <filename>patches/</filename> subdirectory of the source
4960 (<filename>S</filename>) directory.
4961 </para></listitem>
4962 <listitem><para>
4963 <emphasis>Copy the Patch File:</emphasis>
4964 For simplicity, copy the patch file into a directory
4965 named <filename>files</filename>, which you can create
4966 in the same directory that holds the recipe
4967 (<filename>.bb</filename>) file or the append
4968 (<filename>.bbappend</filename>) file.
4969 Placing the patch here guarantees that the OpenEmbedded
4970 build system will find the patch.
4971 Next, add the patch into the
4972 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4973 of the recipe.
4974 Here is an example:
4975 <literallayout class='monospaced'>
4976 SRC_URI += "file://my_changes.patch"
4977 </literallayout>
4978 </para></listitem>
4979 </orderedlist>
4980 </para>
4981 </section>
4982
4983 <section id="platdev-appdev-devshell">
4984 <title>Using a Development Shell</title>
4985
4986 <para>
4987 When debugging certain commands or even when just editing packages,
4988 <filename>devshell</filename> can be a useful tool.
4989 When you invoke <filename>devshell</filename>, all tasks up to and
4990 including
4991 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
4992 are run for the specified target.
4993 Then, a new terminal is opened and you are placed in
4994 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
4995 the source directory.
4996 In the new terminal, all the OpenEmbedded build-related environment variables are
4997 still defined so you can use commands such as <filename>configure</filename> and
4998 <filename>make</filename>.
4999 The commands execute just as if the OpenEmbedded build system were executing them.
5000 Consequently, working this way can be helpful when debugging a build or preparing
5001 software to be used with the OpenEmbedded build system.
5002 </para>
5003
5004 <para>
5005 Following is an example that uses <filename>devshell</filename> on a target named
5006 <filename>matchbox-desktop</filename>:
5007 <literallayout class='monospaced'>
5008 $ bitbake matchbox-desktop -c devshell
5009 </literallayout>
5010 </para>
5011
5012 <para>
5013 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5014 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5015 variable controls what type of shell is opened.
5016 </para>
5017
5018 <para>
5019 For spawned terminals, the following occurs:
5020 <itemizedlist>
5021 <listitem><para>The <filename>PATH</filename> variable includes the
5022 cross-toolchain.</para></listitem>
5023 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5024 <filename>.pc</filename> files.</para></listitem>
5025 <listitem><para>The <filename>configure</filename> command finds the
5026 Yocto Project site files as well as any other necessary files.</para></listitem>
5027 </itemizedlist>
5028 </para>
5029
5030 <para>
5031 Within this environment, you can run configure or compile
5032 commands as if they were being run by
5033 the OpenEmbedded build system itself.
5034 As noted earlier, the working directory also automatically changes to the
5035 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5036 </para>
5037
5038 <para>
5039 To manually run a specific task using <filename>devshell</filename>,
5040 run the corresponding <filename>run.*</filename> script in
5041 the
5042 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5043 directory (e.g.,
5044 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5045 If a task's script does not exist, which would be the case if the task was
5046 skipped by way of the sstate cache, you can create the task by first running
5047 it outside of the <filename>devshell</filename>:
5048 <literallayout class='monospaced'>
5049 $ bitbake -c <replaceable>task</replaceable>
5050 </literallayout>
5051 <note><title>Notes</title>
5052 <itemizedlist>
5053 <listitem><para>Execution of a task's <filename>run.*</filename>
5054 script and BitBake's execution of a task are identical.
5055 In other words, running the script re-runs the task
5056 just as it would be run using the
5057 <filename>bitbake -c</filename> command.
5058 </para></listitem>
5059 <listitem><para>Any <filename>run.*</filename> file that does not
5060 have a <filename>.pid</filename> extension is a
5061 symbolic link (symlink) to the most recent version of that
5062 file.
5063 </para></listitem>
5064 </itemizedlist>
5065 </note>
5066 </para>
5067
5068 <para>
5069 Remember, that the <filename>devshell</filename> is a mechanism that allows
5070 you to get into the BitBake task execution environment.
5071 And as such, all commands must be called just as BitBake would call them.
5072 That means you need to provide the appropriate options for
5073 cross-compilation and so forth as applicable.
5074 </para>
5075
5076 <para>
5077 When you are finished using <filename>devshell</filename>, exit the shell
5078 or close the terminal window.
5079 </para>
5080
5081 <note><title>Notes</title>
5082 <itemizedlist>
5083 <listitem><para>
5084 It is worth remembering that when using <filename>devshell</filename>
5085 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5086 instead of just using <filename>gcc</filename>.
5087 The same applies to other applications such as <filename>binutils</filename>,
5088 <filename>libtool</filename> and so forth.
5089 BitBake sets up environment variables such as <filename>CC</filename>
5090 to assist applications, such as <filename>make</filename> to find the correct tools.
5091 </para></listitem>
5092 <listitem><para>
5093 It is also worth noting that <filename>devshell</filename> still works over
5094 X11 forwarding and similar situations.
5095 </para></listitem>
5096 </itemizedlist>
5097 </note>
5098 </section>
5099
5100 <section id="platdev-appdev-devpyshell">
5101 <title>Using a Development Python Shell</title>
5102
5103 <para>
5104 Similar to working within a development shell as described in
5105 the previous section, you can also spawn and work within an
5106 interactive Python development shell.
5107 When debugging certain commands or even when just editing packages,
5108 <filename>devpyshell</filename> can be a useful tool.
5109 When you invoke <filename>devpyshell</filename>, all tasks up to and
5110 including
5111 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5112 are run for the specified target.
5113 Then a new terminal is opened.
5114 Additionally, key Python objects and code are available in the same
5115 way they are to BitBake tasks, in particular, the data store 'd'.
5116 So, commands such as the following are useful when exploring the data
5117 store and running functions:
5118 <literallayout class='monospaced'>
5119 pydevshell> d.getVar("STAGING_DIR", True)
5120 '/media/build1/poky/build/tmp/sysroots'
5121 pydevshell> d.getVar("STAGING_DIR", False)
5122 '${TMPDIR}/sysroots'
5123 pydevshell> d.setVar("FOO", "bar")
5124 pydevshell> d.getVar("FOO", True)
5125 'bar'
5126 pydevshell> d.delVar("FOO")
5127 pydevshell> d.getVar("FOO", True)
5128 pydevshell> bb.build.exec_func("do_unpack", d)
5129 pydevshell>
5130 </literallayout>
5131 The commands execute just as if the OpenEmbedded build system were executing them.
5132 Consequently, working this way can be helpful when debugging a build or preparing
5133 software to be used with the OpenEmbedded build system.
5134 </para>
5135
5136 <para>
5137 Following is an example that uses <filename>devpyshell</filename> on a target named
5138 <filename>matchbox-desktop</filename>:
5139 <literallayout class='monospaced'>
5140 $ bitbake matchbox-desktop -c devpyshell
5141 </literallayout>
5142 </para>
5143
5144 <para>
5145 This command spawns a terminal and places you in an interactive
5146 Python interpreter within the OpenEmbedded build environment.
5147 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5148 variable controls what type of shell is opened.
5149 </para>
5150
5151 <para>
5152 When you are finished using <filename>devpyshell</filename>, you
5153 can exit the shell either by using Ctrl+d or closing the terminal
5154 window.
5155 </para>
5156 </section>
5157
Brad Bishop316dfdd2018-06-25 12:45:53 -04005158 <section id='dev-building'>
5159 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005160
5161 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005162 This section describes various build procedures.
5163 For example, the steps needed for a simple build, a target that
5164 uses multiple configurations, building an image for more than
5165 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005166 </para>
5167
Brad Bishop316dfdd2018-06-25 12:45:53 -04005168 <section id='dev-building-a-simple-image'>
5169 <title>Building a Simple Image</title>
5170
5171 <para>
5172 In the development environment, you need to build an image
5173 whenever you change hardware support, add or change system
5174 libraries, or add or change services that have dependencies.
5175 Several methods exist that allow you to build an image within
5176 the Yocto Project.
5177 This section presents the basic steps you need to build a
5178 simple image using BitBake from a build host running Linux.
5179 <note><title>Notes</title>
5180 <itemizedlist>
5181 <listitem><para>
5182 For information on how to build an image using
5183 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5184 see the
5185 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5186 </para></listitem>
5187 <listitem><para>
5188 For information on how to use
5189 <filename>devtool</filename> to build images, see
5190 the
5191 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5192 section in the Yocto Project Application
5193 Development and the Extensible Software Development
5194 Kit (eSDK) manual.
5195 </para></listitem>
5196 <listitem><para>
5197 For a quick example on how to build an image using
5198 the OpenEmbedded build system, see the
5199 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5200 document.
5201 </para></listitem>
5202 </itemizedlist>
5203 </note>
5204 </para>
5205
5206 <para>
5207 The build process creates an entire Linux distribution from
5208 source and places it in your
5209 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5210 under <filename>tmp/deploy/images</filename>.
5211 For detailed information on the build process using BitBake,
5212 see the
5213 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5214 section in the Yocto Project Overview and Concepts Manual.
5215 </para>
5216
5217 <para>
5218 The following figure and list overviews the build process:
5219 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5220 <orderedlist>
5221 <listitem><para>
5222 <emphasis>Set up Your Host Development System to Support
5223 Development Using the Yocto Project</emphasis>:
5224 See the
5225 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5226 section for options on how to get a build host ready to
5227 use the Yocto Project.
5228 </para></listitem>
5229 <listitem><para>
5230 <emphasis>Initialize the Build Environment:</emphasis>
5231 Initialize the build environment by sourcing the build
5232 environment script (i.e.
5233 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5234 <literallayout class='monospaced'>
5235 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5236 </literallayout></para>
5237
5238 <para>When you use the initialization script, the
5239 OpenEmbedded build system uses
5240 <filename>build</filename> as the default Build
5241 Directory in your current work directory.
5242 You can use a <replaceable>build_dir</replaceable>
5243 argument with the script to specify a different build
5244 directory.
5245 <note><title>Tip</title>
5246 A common practice is to use a different Build
5247 Directory for different targets.
5248 For example, <filename>~/build/x86</filename> for a
5249 <filename>qemux86</filename> target, and
5250 <filename>~/build/arm</filename> for a
5251 <filename>qemuarm</filename> target.
5252 </note>
5253 </para></listitem>
5254 <listitem><para>
5255 <emphasis>Make Sure Your <filename>local.conf</filename>
5256 File is Correct:</emphasis>
5257 Ensure the <filename>conf/local.conf</filename>
5258 configuration file, which is found in the Build
5259 Directory, is set up how you want it.
5260 This file defines many aspects of the build environment
5261 including the target machine architecture through the
5262 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5263 the packaging format used during the build
5264 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5265 and a centralized tarball download directory through the
5266 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5267 </para></listitem>
5268 <listitem><para>
5269 <emphasis>Build the Image:</emphasis>
5270 Build the image using the <filename>bitbake</filename>
5271 command:
5272 <literallayout class='monospaced'>
5273 $ bitbake <replaceable>target</replaceable>
5274 </literallayout>
5275 <note>
5276 For information on BitBake, see the
5277 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5278 </note>
5279 The <replaceable>target</replaceable> is the name of the
5280 recipe you want to build.
5281 Common targets are the images in
5282 <filename>meta/recipes-core/images</filename>,
5283 <filename>meta/recipes-sato/images</filename>, and so
5284 forth all found in the
5285 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5286 Or, the target can be the name of a recipe for a
5287 specific piece of software such as BusyBox.
5288 For more details about the images the OpenEmbedded build
5289 system supports, see the
5290 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5291 chapter in the Yocto Project Reference Manual.</para>
5292
5293 <para>As an example, the following command builds the
5294 <filename>core-image-minimal</filename> image:
5295 <literallayout class='monospaced'>
5296 $ bitbake core-image-minimal
5297 </literallayout>
5298 Once an image has been built, it often needs to be
5299 installed.
5300 The images and kernels built by the OpenEmbedded
5301 build system are placed in the Build Directory in
5302 <filename class="directory">tmp/deploy/images</filename>.
5303 For information on how to run pre-built images such as
5304 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5305 see the
5306 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5307 manual.
5308 For information about how to install these images,
5309 see the documentation for your particular board or
5310 machine.
5311 </para></listitem>
5312 </orderedlist>
5313 </para>
5314 </section>
5315
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005316 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5317 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005318
5319 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005320 You can use a single <filename>bitbake</filename> command
5321 to build multiple images or packages for different targets
5322 where each image or package requires a different configuration
5323 (multiple configuration builds).
5324 The builds, in this scenario, are sometimes referred to as
5325 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005326 </para>
5327
5328 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005329 This section describes how to set up for multiple
5330 configuration builds and how to account for cross-build
5331 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005332 </para>
5333
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005334 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5335 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005336
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005337 <para>
5338 To accomplish a multiple configuration build, you must
5339 define each target's configuration separately using
5340 a parallel configuration file in the
5341 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5342 and you must follow a required file hierarchy.
5343 Additionally, you must enable the multiple configuration
5344 builds in your <filename>local.conf</filename> file.
5345 </para>
5346
5347 <para>
5348 Follow these steps to set up and execute multiple
5349 configuration builds:
5350 <itemizedlist>
5351 <listitem><para>
5352 <emphasis>Create Separate Configuration Files</emphasis>:
5353 You need to create a single configuration file for
5354 each build target (each multiconfig).
5355 Minimally, each configuration file must define the
5356 machine and the temporary directory BitBake uses
5357 for the build.
5358 Suggested practice dictates that you do not
5359 overlap the temporary directories
5360 used during the builds.
5361 However, it is possible that you can share the
5362 temporary directory
5363 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5364 For example, consider a scenario with two
5365 different multiconfigs for the same
5366 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5367 two distributions such as "poky" and "poky-lsb".
5368 In this case, you might want to use the same
5369 <filename>TMPDIR</filename>.</para>
5370
5371 <para>Here is an example showing the minimal
5372 statements needed in a configuration file for
5373 a "qemux86" target whose temporary build directory
5374 is <filename>tmpmultix86</filename>:
5375 <literallayout class='monospaced'>
5376 MACHINE="qemux86"
5377 TMPDIR="${TOPDIR}/tmpmultix86"
5378 </literallayout></para>
5379
5380 <para>The location for these multiconfig
5381 configuration files is specific.
5382 They must reside in the current build directory in
5383 a sub-directory of <filename>conf</filename> named
5384 <filename>multiconfig</filename>.
5385 Following is an example that defines two
5386 configuration files for the "x86" and "arm"
5387 multiconfigs:
5388 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5389 </para>
5390
5391 <para>The reason for this required file hierarchy
5392 is because the <filename>BBPATH</filename> variable
5393 is not constructed until the layers are parsed.
5394 Consequently, using the configuration file as a
5395 pre-configuration file is not possible unless it is
5396 located in the current working directory.
5397 </para></listitem>
5398 <listitem><para>
5399 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5400 Use the
5401 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5402 variable in your
5403 <filename>conf/local.conf</filename> configuration
5404 file to specify each multiconfig.
5405 Continuing with the example from the previous
5406 figure, the <filename>BBMULTICONFIG</filename>
5407 variable needs to enable two multiconfigs: "x86"
5408 and "arm" by specifying each configuration file:
5409 <literallayout class='monospaced'>
5410 BBMULTICONFIG = "x86 arm"
5411 </literallayout>
5412 </para></listitem>
5413 <listitem><para>
5414 <emphasis>Launch BitBake</emphasis>:
5415 Use the following BitBake command form to launch the
5416 multiple configuration build:
5417 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005418 $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005419 </literallayout>
5420 For the example in this section, the following
5421 command applies:
5422 <literallayout class='monospaced'>
5423 $ bitbake multiconfig:x86:core-image-minimal multiconfig:arm:core-image-sato
5424 </literallayout>
5425 The previous BitBake command builds a
5426 <filename>core-image-minimal</filename> image that
5427 is configured through the
5428 <filename>x86.conf</filename> configuration file
5429 and builds a <filename>core-image-sato</filename>
5430 image that is configured through the
5431 <filename>arm.conf</filename> configuration file.
5432 </para></listitem>
5433 </itemizedlist>
5434 <note>
5435 Support for multiple configuration builds in the
5436 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5437 not include Shared State (sstate) optimizations.
5438 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005439 in, for example, two different
5440 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005441 either loads from an existing sstate cache for that
5442 build at the start or builds the object fresh.
5443 </note>
5444 </para>
5445 </section>
5446
5447 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5448 <title>Enabling Multiple Configuration Build Dependencies</title>
5449
5450 <para>
5451 Sometimes dependencies can exist between targets
5452 (multiconfigs) in a multiple configuration build.
5453 For example, suppose that in order to build a
5454 <filename>core-image-sato</filename> image for an "x86"
5455 multiconfig, the root filesystem of an "arm"
5456 multiconfig must exist.
5457 This dependency is essentially that the
5458 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5459 task in the <filename>core-image-sato</filename> recipe
5460 depends on the completion of the
5461 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5462 task of the <filename>core-image-minimal</filename>
5463 recipe.
5464 </para>
5465
5466 <para>
5467 To enable dependencies in a multiple configuration
5468 build, you must declare the dependencies in the recipe
5469 using the following statement form:
5470 <literallayout class='monospaced'>
5471 <replaceable>task_or_package</replaceable>[mcdepends] = "multiconfig:<replaceable>from_multiconfig</replaceable>:<replaceable>to_multiconfig</replaceable>:<replaceable>recipe_name</replaceable>:<replaceable>task_on_which_to_depend</replaceable>"
5472 </literallayout>
5473 To better show how to use this statement, consider the
5474 example scenario from the first paragraph of this section.
5475 The following statement needs to be added to the recipe
5476 that builds the <filename>core-image-sato</filename>
5477 image:
5478 <literallayout class='monospaced'>
5479 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_rootfs"
5480 </literallayout>
5481 In this example, the
5482 <replaceable>from_multiconfig</replaceable> is "x86".
5483 The <replaceable>to_multiconfig</replaceable> is "arm".
5484 The task on which the <filename>do_image</filename> task
5485 in the recipe depends is the <filename>do_rootfs</filename>
5486 task from the <filename>core-image-minimal</filename>
5487 recipe associated with the "arm" multiconfig.
5488 </para>
5489
5490 <para>
5491 Once you set up this dependency, you can build the
5492 "x86" multiconfig using a BitBake command as follows:
5493 <literallayout class='monospaced'>
5494 $ bitbake multiconfig:x86:core-image-sato
5495 </literallayout>
5496 This command executes all the tasks needed to create
5497 the <filename>core-image-sato</filename> image for the
5498 "x86" multiconfig.
5499 Because of the dependency, BitBake also executes through
5500 the <filename>do_rootfs</filename> task for the "arm"
5501 multiconfig build.
5502 </para>
5503
5504 <para>
5505 Having a recipe depend on the root filesystem of another
5506 build might not seem that useful.
5507 Consider this change to the statement in the
5508 <filename>core-image-sato</filename> recipe:
5509 <literallayout class='monospaced'>
5510 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_image"
5511 </literallayout>
5512 In this case, BitBake must create the
5513 <filename>core-image-minimal</filename> image for the
5514 "arm" build since the "x86" build depends on it.
5515 </para>
5516
5517 <para>
5518 Because "x86" and "arm" are enabled for multiple
5519 configuration builds and have separate configuration
5520 files, BitBake places the artifacts for each build in the
5521 respective temporary build directories (i.e.
5522 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5523 </para>
5524 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005525 </section>
5526
5527 <section id='building-an-initramfs-image'>
5528 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5529
5530 <para>
5531 An initial RAM filesystem (initramfs) image provides a temporary
5532 root filesystem used for early system initialization (e.g.
5533 loading of modules needed to locate and mount the "real" root
5534 filesystem).
5535 <note>
5536 The initramfs image is the successor of initial RAM disk
5537 (initrd).
5538 It is a "copy in and out" (cpio) archive of the initial
5539 filesystem that gets loaded into memory during the Linux
5540 startup process.
5541 Because Linux uses the contents of the archive during
5542 initialization, the initramfs image needs to contain all of the
5543 device drivers and tools needed to mount the final root
5544 filesystem.
5545 </note>
5546 </para>
5547
5548 <para>
5549 Follow these steps to create an initramfs image:
5550 <orderedlist>
5551 <listitem><para>
5552 <emphasis>Create the initramfs Image Recipe:</emphasis>
5553 You can reference the
5554 <filename>core-image-minimal-initramfs.bb</filename>
5555 recipe found in the <filename>meta/recipes-core</filename>
5556 directory of the
5557 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5558 as an example from which to work.
5559 </para></listitem>
5560 <listitem><para>
5561 <emphasis>Decide if You Need to Bundle the initramfs Image
5562 Into the Kernel Image:</emphasis>
5563 If you want the initramfs image that is built to be
5564 bundled in with the kernel image, set the
5565 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5566 variable to "1" in your <filename>local.conf</filename>
5567 configuration file and set the
5568 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5569 variable in the recipe that builds the kernel image.
5570 <note><title>Tip</title>
5571 It is recommended that you do bundle the initramfs
5572 image with the kernel image to avoid circular
5573 dependencies between the kernel recipe and the
5574 initramfs recipe should the initramfs image
5575 include kernel modules.
5576 </note>
5577 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5578 flag causes the initramfs image to be unpacked
5579 into the <filename>${B}/usr/</filename> directory.
5580 The unpacked initramfs image is then passed to the kernel's
5581 <filename>Makefile</filename> using the
5582 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5583 variable, allowing the initramfs image to be built into
5584 the kernel normally.
5585 <note>
5586 If you choose to not bundle the initramfs image with
5587 the kernel image, you are essentially using an
5588 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5589 Creating an initrd is handled primarily through the
5590 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5591 <filename>INITRD_LIVE</filename>, and
5592 <filename>INITRD_IMAGE_LIVE</filename> variables.
5593 For more information, see the
5594 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5595 file.
5596 </note>
5597 </para></listitem>
5598 <listitem><para>
5599 <emphasis>Optionally Add Items to the initramfs Image
5600 Through the initramfs Image Recipe:</emphasis>
5601 If you add items to the initramfs image by way of its
5602 recipe, you should use
5603 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5604 rather than
5605 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5606 <filename>PACKAGE_INSTALL</filename> gives more direct
5607 control of what is added to the image as compared to
5608 the defaults you might not necessarily want that are
5609 set by the
5610 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5611 or
5612 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5613 classes.
5614 </para></listitem>
5615 <listitem><para>
5616 <emphasis>Build the Kernel Image and the initramfs
5617 Image:</emphasis>
5618 Build your kernel image using BitBake.
5619 Because the initramfs image recipe is a dependency of the
5620 kernel image, the initramfs image is built as well and
5621 bundled with the kernel image if you used the
5622 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5623 variable described earlier.
5624 </para></listitem>
5625 </orderedlist>
5626 </para>
5627 </section>
5628
5629 <section id='building-a-tiny-system'>
5630 <title>Building a Tiny System</title>
5631
5632 <para>
5633 Very small distributions have some significant advantages such
5634 as requiring less on-die or in-package memory (cheaper), better
5635 performance through efficient cache usage, lower power requirements
5636 due to less memory, faster boot times, and reduced development
5637 overhead.
5638 Some real-world examples where a very small distribution gives
5639 you distinct advantages are digital cameras, medical devices,
5640 and small headless systems.
5641 </para>
5642
5643 <para>
5644 This section presents information that shows you how you can
5645 trim your distribution to even smaller sizes than the
5646 <filename>poky-tiny</filename> distribution, which is around
5647 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5648 </para>
5649
5650 <section id='tiny-system-overview'>
5651 <title>Overview</title>
5652
5653 <para>
5654 The following list presents the overall steps you need to
5655 consider and perform to create distributions with smaller
5656 root filesystems, achieve faster boot times, maintain your critical
5657 functionality, and avoid initial RAM disks:
5658 <itemizedlist>
5659 <listitem><para>
5660 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5661 </para></listitem>
5662 <listitem><para>
5663 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5664 </para></listitem>
5665 <listitem><para>
5666 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5667 </para></listitem>
5668 <listitem><para>
5669 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5670 </para></listitem>
5671 <listitem><para>
5672 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5673 </para></listitem>
5674 <listitem><para>
5675 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5676 </para></listitem>
5677 <listitem><para>
5678 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5679 </para></listitem>
5680 </itemizedlist>
5681 </para>
5682 </section>
5683
5684 <section id='goals-and-guiding-principles'>
5685 <title>Goals and Guiding Principles</title>
5686
5687 <para>
5688 Before you can reach your destination, you need to know
5689 where you are going.
5690 Here is an example list that you can use as a guide when
5691 creating very small distributions:
5692 <itemizedlist>
5693 <listitem><para>Determine how much space you need
5694 (e.g. a kernel that is 1 Mbyte or less and
5695 a root filesystem that is 3 Mbytes or less).
5696 </para></listitem>
5697 <listitem><para>Find the areas that are currently
5698 taking 90% of the space and concentrate on reducing
5699 those areas.
5700 </para></listitem>
5701 <listitem><para>Do not create any difficult "hacks"
5702 to achieve your goals.</para></listitem>
5703 <listitem><para>Leverage the device-specific
5704 options.</para></listitem>
5705 <listitem><para>Work in a separate layer so that you
5706 keep changes isolated.
5707 For information on how to create layers, see
5708 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5709 </para></listitem>
5710 </itemizedlist>
5711 </para>
5712 </section>
5713
5714 <section id='understand-what-gives-your-image-size'>
5715 <title>Understand What Contributes to Your Image Size</title>
5716
5717 <para>
5718 It is easiest to have something to start with when creating
5719 your own distribution.
5720 You can use the Yocto Project out-of-the-box to create the
5721 <filename>poky-tiny</filename> distribution.
5722 Ultimately, you will want to make changes in your own
5723 distribution that are likely modeled after
5724 <filename>poky-tiny</filename>.
5725 <note>
5726 To use <filename>poky-tiny</filename> in your build,
5727 set the
5728 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5729 variable in your
5730 <filename>local.conf</filename> file to "poky-tiny"
5731 as described in the
5732 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5733 section.
5734 </note>
5735 </para>
5736
5737 <para>
5738 Understanding some memory concepts will help you reduce the
5739 system size.
5740 Memory consists of static, dynamic, and temporary memory.
5741 Static memory is the TEXT (code), DATA (initialized data
5742 in the code), and BSS (uninitialized data) sections.
5743 Dynamic memory represents memory that is allocated at runtime:
5744 stacks, hash tables, and so forth.
5745 Temporary memory is recovered after the boot process.
5746 This memory consists of memory used for decompressing
5747 the kernel and for the <filename>__init__</filename>
5748 functions.
5749 </para>
5750
5751 <para>
5752 To help you see where you currently are with kernel and root
5753 filesystem sizes, you can use two tools found in the
5754 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5755 the <filename>scripts/tiny/</filename> directory:
5756 <itemizedlist>
5757 <listitem><para><filename>ksize.py</filename>: Reports
5758 component sizes for the kernel build objects.
5759 </para></listitem>
5760 <listitem><para><filename>dirsize.py</filename>: Reports
5761 component sizes for the root filesystem.</para></listitem>
5762 </itemizedlist>
5763 This next tool and command help you organize configuration
5764 fragments and view file dependencies in a human-readable form:
5765 <itemizedlist>
5766 <listitem><para><filename>merge_config.sh</filename>:
5767 Helps you manage configuration files and fragments
5768 within the kernel.
5769 With this tool, you can merge individual configuration
5770 fragments together.
5771 The tool allows you to make overrides and warns you
5772 of any missing configuration options.
5773 The tool is ideal for allowing you to iterate on
5774 configurations, create minimal configurations, and
5775 create configuration files for different machines
5776 without having to duplicate your process.</para>
5777 <para>The <filename>merge_config.sh</filename> script is
5778 part of the Linux Yocto kernel Git repositories
5779 (i.e. <filename>linux-yocto-3.14</filename>,
5780 <filename>linux-yocto-3.10</filename>,
5781 <filename>linux-yocto-3.8</filename>, and so forth)
5782 in the
5783 <filename>scripts/kconfig</filename> directory.</para>
5784 <para>For more information on configuration fragments,
5785 see the
5786 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5787 section in the Yocto Project Linux Kernel Development
5788 Manual.
5789 </para></listitem>
5790 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5791 Using the BitBake command with these options brings up
5792 a Dependency Explorer from which you can view file
5793 dependencies.
5794 Understanding these dependencies allows you to make
5795 informed decisions when cutting out various pieces of the
5796 kernel and root filesystem.</para></listitem>
5797 </itemizedlist>
5798 </para>
5799 </section>
5800
5801 <section id='trim-the-root-filesystem'>
5802 <title>Trim the Root Filesystem</title>
5803
5804 <para>
5805 The root filesystem is made up of packages for booting,
5806 libraries, and applications.
5807 To change things, you can configure how the packaging happens,
5808 which changes the way you build them.
5809 You can also modify the filesystem itself or select a different
5810 filesystem.
5811 </para>
5812
5813 <para>
5814 First, find out what is hogging your root filesystem by running the
5815 <filename>dirsize.py</filename> script from your root directory:
5816 <literallayout class='monospaced'>
5817 $ cd <replaceable>root-directory-of-image</replaceable>
5818 $ dirsize.py 100000 > dirsize-100k.log
5819 $ cat dirsize-100k.log
5820 </literallayout>
5821 You can apply a filter to the script to ignore files under
5822 a certain size.
5823 The previous example filters out any files below 100 Kbytes.
5824 The sizes reported by the tool are uncompressed, and thus
5825 will be smaller by a relatively constant factor in a
5826 compressed root filesystem.
5827 When you examine your log file, you can focus on areas of the
5828 root filesystem that take up large amounts of memory.
5829 </para>
5830
5831 <para>
5832 You need to be sure that what you eliminate does not cripple
5833 the functionality you need.
5834 One way to see how packages relate to each other is by using
5835 the Dependency Explorer UI with the BitBake command:
5836 <literallayout class='monospaced'>
5837 $ cd <replaceable>image-directory</replaceable>
5838 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5839 </literallayout>
5840 Use the interface to select potential packages you wish to
5841 eliminate and see their dependency relationships.
5842 </para>
5843
5844 <para>
5845 When deciding how to reduce the size, get rid of packages that
5846 result in minimal impact on the feature set.
5847 For example, you might not need a VGA display.
5848 Or, you might be able to get by with <filename>devtmpfs</filename>
5849 and <filename>mdev</filename> instead of
5850 <filename>udev</filename>.
5851 </para>
5852
5853 <para>
5854 Use your <filename>local.conf</filename> file to make changes.
5855 For example, to eliminate <filename>udev</filename> and
5856 <filename>glib</filename>, set the following in the
5857 local configuration file:
5858 <literallayout class='monospaced'>
5859 VIRTUAL-RUNTIME_dev_manager = ""
5860 </literallayout>
5861 </para>
5862
5863 <para>
5864 Finally, you should consider exactly the type of root
5865 filesystem you need to meet your needs while also reducing
5866 its size.
5867 For example, consider <filename>cramfs</filename>,
5868 <filename>squashfs</filename>, <filename>ubifs</filename>,
5869 <filename>ext2</filename>, or an <filename>initramfs</filename>
5870 using <filename>initramfs</filename>.
5871 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5872 journal.
5873 If you are okay with running read-only, you do not need this
5874 journal.
5875 </para>
5876
5877 <note>
5878 After each round of elimination, you need to rebuild your
5879 system and then use the tools to see the effects of your
5880 reductions.
5881 </note>
5882 </section>
5883
5884 <section id='trim-the-kernel'>
5885 <title>Trim the Kernel</title>
5886
5887 <para>
5888 The kernel is built by including policies for hardware-independent
5889 aspects.
5890 What subsystems do you enable?
5891 For what architecture are you building?
5892 Which drivers do you build by default?
5893 <note>You can modify the kernel source if you want to help
5894 with boot time.
5895 </note>
5896 </para>
5897
5898 <para>
5899 Run the <filename>ksize.py</filename> script from the top-level
5900 Linux build directory to get an idea of what is making up
5901 the kernel:
5902 <literallayout class='monospaced'>
5903 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5904 $ ksize.py > ksize.log
5905 $ cat ksize.log
5906 </literallayout>
5907 When you examine the log, you will see how much space is
5908 taken up with the built-in <filename>.o</filename> files for
5909 drivers, networking, core kernel files, filesystem, sound,
5910 and so forth.
5911 The sizes reported by the tool are uncompressed, and thus
5912 will be smaller by a relatively constant factor in a compressed
5913 kernel image.
5914 Look to reduce the areas that are large and taking up around
5915 the "90% rule."
5916 </para>
5917
5918 <para>
5919 To examine, or drill down, into any particular area, use the
5920 <filename>-d</filename> option with the script:
5921 <literallayout class='monospaced'>
5922 $ ksize.py -d > ksize.log
5923 </literallayout>
5924 Using this option breaks out the individual file information
5925 for each area of the kernel (e.g. drivers, networking, and
5926 so forth).
5927 </para>
5928
5929 <para>
5930 Use your log file to see what you can eliminate from the kernel
5931 based on features you can let go.
5932 For example, if you are not going to need sound, you do not
5933 need any drivers that support sound.
5934 </para>
5935
5936 <para>
5937 After figuring out what to eliminate, you need to reconfigure
5938 the kernel to reflect those changes during the next build.
5939 You could run <filename>menuconfig</filename> and make all your
5940 changes at once.
5941 However, that makes it difficult to see the effects of your
5942 individual eliminations and also makes it difficult to replicate
5943 the changes for perhaps another target device.
5944 A better method is to start with no configurations using
5945 <filename>allnoconfig</filename>, create configuration
5946 fragments for individual changes, and then manage the
5947 fragments into a single configuration file using
5948 <filename>merge_config.sh</filename>.
5949 The tool makes it easy for you to iterate using the
5950 configuration change and build cycle.
5951 </para>
5952
5953 <para>
5954 Each time you make configuration changes, you need to rebuild
5955 the kernel and check to see what impact your changes had on
5956 the overall size.
5957 </para>
5958 </section>
5959
5960 <section id='remove-package-management-requirements'>
5961 <title>Remove Package Management Requirements</title>
5962
5963 <para>
5964 Packaging requirements add size to the image.
5965 One way to reduce the size of the image is to remove all the
5966 packaging requirements from the image.
5967 This reduction includes both removing the package manager
5968 and its unique dependencies as well as removing the package
5969 management data itself.
5970 </para>
5971
5972 <para>
5973 To eliminate all the packaging requirements for an image,
5974 be sure that "package-management" is not part of your
5975 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5976 statement for the image.
5977 When you remove this feature, you are removing the package
5978 manager as well as its dependencies from the root filesystem.
5979 </para>
5980 </section>
5981
5982 <section id='look-for-other-ways-to-minimize-size'>
5983 <title>Look for Other Ways to Minimize Size</title>
5984
5985 <para>
5986 Depending on your particular circumstances, other areas that you
5987 can trim likely exist.
5988 The key to finding these areas is through tools and methods
5989 described here combined with experimentation and iteration.
5990 Here are a couple of areas to experiment with:
5991 <itemizedlist>
5992 <listitem><para><filename>glibc</filename>:
5993 In general, follow this process:
5994 <orderedlist>
5995 <listitem><para>Remove <filename>glibc</filename>
5996 features from
5997 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
5998 that you think you do not need.</para></listitem>
5999 <listitem><para>Build your distribution.
6000 </para></listitem>
6001 <listitem><para>If the build fails due to missing
6002 symbols in a package, determine if you can
6003 reconfigure the package to not need those
6004 features.
6005 For example, change the configuration to not
6006 support wide character support as is done for
6007 <filename>ncurses</filename>.
6008 Or, if support for those characters is needed,
6009 determine what <filename>glibc</filename>
6010 features provide the support and restore the
6011 configuration.
6012 </para></listitem>
6013 <listitem><para>Rebuild and repeat the process.
6014 </para></listitem>
6015 </orderedlist></para></listitem>
6016 <listitem><para><filename>busybox</filename>:
6017 For BusyBox, use a process similar as described for
6018 <filename>glibc</filename>.
6019 A difference is you will need to boot the resulting
6020 system to see if you are able to do everything you
6021 expect from the running system.
6022 You need to be sure to integrate configuration fragments
6023 into Busybox because BusyBox handles its own core
6024 features and then allows you to add configuration
6025 fragments on top.
6026 </para></listitem>
6027 </itemizedlist>
6028 </para>
6029 </section>
6030
6031 <section id='iterate-on-the-process'>
6032 <title>Iterate on the Process</title>
6033
6034 <para>
6035 If you have not reached your goals on system size, you need
6036 to iterate on the process.
6037 The process is the same.
6038 Use the tools and see just what is taking up 90% of the root
6039 filesystem and the kernel.
6040 Decide what you can eliminate without limiting your device
6041 beyond what you need.
6042 </para>
6043
6044 <para>
6045 Depending on your system, a good place to look might be
6046 Busybox, which provides a stripped down
6047 version of Unix tools in a single, executable file.
6048 You might be able to drop virtual terminal services or perhaps
6049 ipv6.
6050 </para>
6051 </section>
6052 </section>
6053
6054 <section id='building-images-for-more-than-one-machine'>
6055 <title>Building Images for More than One Machine</title>
6056
6057 <para>
6058 A common scenario developers face is creating images for several
6059 different machines that use the same software environment.
6060 In this situation, it is tempting to set the
6061 tunings and optimization flags for each build specifically for
6062 the targeted hardware (i.e. "maxing out" the tunings).
6063 Doing so can considerably add to build times and package feed
6064 maintenance collectively for the machines.
6065 For example, selecting tunes that are extremely specific to a
6066 CPU core used in a system might enable some micro optimizations
6067 in GCC for that particular system but would otherwise not gain
6068 you much of a performance difference across the other systems
6069 as compared to using a more general tuning across all the builds
6070 (e.g. setting
6071 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6072 specifically for each machine's build).
6073 Rather than "max out" each build's tunings, you can take steps that
6074 cause the OpenEmbedded build system to reuse software across the
6075 various machines where it makes sense.
6076 </para>
6077
6078 <para>
6079 If build speed and package feed maintenance are considerations,
6080 you should consider the points in this section that can help you
6081 optimize your tunings to best consider build times and package
6082 feed maintenance.
6083 <itemizedlist>
6084 <listitem><para>
6085 <emphasis>Share the Build Directory:</emphasis>
6086 If at all possible, share the
6087 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6088 across builds.
6089 The Yocto Project supports switching between different
6090 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6091 values in the same <filename>TMPDIR</filename>.
6092 This practice is well supported and regularly used by
6093 developers when building for multiple machines.
6094 When you use the same <filename>TMPDIR</filename> for
6095 multiple machine builds, the OpenEmbedded build system can
6096 reuse the existing native and often cross-recipes for
6097 multiple machines.
6098 Thus, build time decreases.
6099 <note>
6100 If
6101 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6102 settings change or fundamental configuration settings
6103 such as the filesystem layout, you need to work with
6104 a clean <filename>TMPDIR</filename>.
6105 Sharing <filename>TMPDIR</filename> under these
6106 circumstances might work but since it is not
6107 guaranteed, you should use a clean
6108 <filename>TMPDIR</filename>.
6109 </note>
6110 </para></listitem>
6111 <listitem><para>
6112 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6113 By default, the OpenEmbedded build system enables three
6114 levels of package architectures: "all", "tune" or "package",
6115 and "machine".
6116 Any given recipe usually selects one of these package
6117 architectures (types) for its output.
6118 Depending for what a given recipe creates packages, making
6119 sure you enable the appropriate package architecture can
6120 directly impact the build time.</para>
6121
6122 <para>A recipe that just generates scripts can enable
6123 "all" architecture because there are no binaries to build.
6124 To specifically enable "all" architecture, be sure your
6125 recipe inherits the
6126 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6127 class.
6128 This class is useful for "all" architectures because it
6129 configures many variables so packages can be used across
6130 multiple architectures.</para>
6131
6132 <para>If your recipe needs to generate packages that are
6133 machine-specific or when one of the build or runtime
6134 dependencies is already machine-architecture dependent,
6135 which makes your recipe also machine-architecture dependent,
6136 make sure your recipe enables the "machine" package
6137 architecture through the
6138 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6139 variable:
6140 <literallayout class='monospaced'>
6141 PACKAGE_ARCH = "${MACHINE_ARCH}"
6142 </literallayout>
6143 When you do not specifically enable a package
6144 architecture through the
6145 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6146 The OpenEmbedded build system defaults to the
6147 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6148 setting:
6149 <literallayout class='monospaced'>
6150 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6151 </literallayout>
6152 </para></listitem>
6153 <listitem><para>
6154 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6155 Some tunes are more generic and can run on multiple targets
6156 (e.g. an <filename>armv5</filename> set of packages could
6157 run on <filename>armv6</filename> and
6158 <filename>armv7</filename> processors in most cases).
6159 Similarly, <filename>i486</filename> binaries could work
6160 on <filename>i586</filename> and higher processors.
6161 You should realize, however, that advances on newer
6162 processor versions would not be used.</para>
6163
6164 <para>If you select the same tune for several different
6165 machines, the OpenEmbedded build system reuses software
6166 previously built, thus speeding up the overall build time.
6167 Realize that even though a new sysroot for each machine is
6168 generated, the software is not recompiled and only one
6169 package feed exists.
6170 </para></listitem>
6171 <listitem><para>
6172 <emphasis>Manage Granular Level Packaging:</emphasis>
6173 Sometimes cases exist where injecting another level of
6174 package architecture beyond the three higher levels noted
6175 earlier can be useful.
6176 For example, consider how NXP (formerly Freescale) allows
6177 for the easy reuse of binary packages in their layer
6178 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6179 In this example, the
6180 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6181 class shares GPU packages for i.MX53 boards because
6182 all boards share the AMD GPU.
6183 The i.MX6-based boards can do the same because all boards
6184 share the Vivante GPU.
6185 This class inspects the BitBake datastore to identify if
6186 the package provides or depends on one of the
6187 sub-architecture values.
6188 If so, the class sets the
6189 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6190 value based on the <filename>MACHINE_SUBARCH</filename>
6191 value.
6192 If the package does not provide or depend on one of the
6193 sub-architecture values but it matches a value in the
6194 machine-specific filter, it sets
6195 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6196 This behavior reduces the number of packages built and
6197 saves build time by reusing binaries.
6198 </para></listitem>
6199 <listitem><para>
6200 <emphasis>Use Tools to Debug Issues:</emphasis>
6201 Sometimes you can run into situations where software is
6202 being rebuilt when you think it should not be.
6203 For example, the OpenEmbedded build system might not be
6204 using shared state between machines when you think it
6205 should be.
6206 These types of situations are usually due to references
6207 to machine-specific variables such as
6208 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6209 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6210 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6211 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6212 and so forth in code that is supposed to only be
6213 tune-specific or when the recipe depends
6214 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6215 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6216 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6217 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6218 and so forth) on some other recipe that already has
6219 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6220 defined as "${MACHINE_ARCH}".
6221 <note>
6222 Patches to fix any issues identified are most welcome
6223 as these issues occasionally do occur.
6224 </note></para>
6225
6226 <para>For such cases, you can use some tools to help you
6227 sort out the situation:
6228 <itemizedlist>
6229 <listitem><para>
6230 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6231 You can find this tool in the
6232 <filename>scripts</filename> directory of the
6233 Source Repositories.
6234 See the comments in the script for information on
6235 how to use the tool.
6236 </para></listitem>
6237 <listitem><para>
6238 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6239 Using this option causes BitBake to try to
6240 establish the closest signature match it can
6241 (e.g. in the shared state cache) and then run
6242 <filename>bitbake-diffsigs</filename> over the
6243 matches to determine the stamps and delta where
6244 these two stamp trees diverge.
6245 </para></listitem>
6246 </itemizedlist>
6247 </para></listitem>
6248 </itemizedlist>
6249 </para>
6250 </section>
6251
6252 <section id="building-software-from-an-external-source">
6253 <title>Building Software from an External Source</title>
6254
6255 <para>
6256 By default, the OpenEmbedded build system uses the
6257 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6258 when building source code.
6259 The build process involves fetching the source files, unpacking
6260 them, and then patching them if necessary before the build takes
6261 place.
6262 </para>
6263
6264 <para>
6265 Situations exist where you might want to build software from source
6266 files that are external to and thus outside of the
6267 OpenEmbedded build system.
6268 For example, suppose you have a project that includes a new BSP with
6269 a heavily customized kernel.
6270 And, you want to minimize exposing the build system to the
6271 development team so that they can focus on their project and
6272 maintain everyone's workflow as much as possible.
6273 In this case, you want a kernel source directory on the development
6274 machine where the development occurs.
6275 You want the recipe's
6276 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6277 variable to point to the external directory and use it as is, not
6278 copy it.
6279 </para>
6280
6281 <para>
6282 To build from software that comes from an external source, all you
6283 need to do is inherit the
6284 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6285 class and then set the
6286 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6287 variable to point to your external source code.
6288 Here are the statements to put in your
6289 <filename>local.conf</filename> file:
6290 <literallayout class='monospaced'>
6291 INHERIT += "externalsrc"
6292 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6293 </literallayout>
6294 </para>
6295
6296 <para>
6297 This next example shows how to accomplish the same thing by setting
6298 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6299 recipe's append file:
6300 <literallayout class='monospaced'>
6301 EXTERNALSRC = "<replaceable>path</replaceable>"
6302 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6303 </literallayout>
6304 <note>
6305 In order for these settings to take effect, you must globally
6306 or locally inherit the
6307 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6308 class.
6309 </note>
6310 </para>
6311
6312 <para>
6313 By default, <filename>externalsrc.bbclass</filename> builds
6314 the source code in a directory separate from the external source
6315 directory as specified by
6316 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6317 If you need to have the source built in the same directory in
6318 which it resides, or some other nominated directory, you can set
6319 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6320 to point to that directory:
6321 <literallayout class='monospaced'>
6322 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6323 </literallayout>
6324 </para>
6325 </section>
6326 </section>
6327
6328
6329
6330 <section id='speeding-up-a-build'>
6331 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006332
6333 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006334 Build time can be an issue.
6335 By default, the build system uses simple controls to try and maximize
6336 build efficiency.
6337 In general, the default settings for all the following variables
6338 result in the most efficient build times when dealing with single
6339 socket systems (i.e. a single CPU).
6340 If you have multiple CPUs, you might try increasing the default
6341 values to gain more speed.
6342 See the descriptions in the glossary for each variable for more
6343 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006344 <itemizedlist>
6345 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006346 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6347 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006348 </para></listitem>
6349 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006350 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6351 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006352 </para></listitem>
6353 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006354 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6355 Extra options passed to the <filename>make</filename> command
6356 during the
6357 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6358 task in order to specify parallel compilation on the
6359 local build host.
6360 </para></listitem>
6361 <listitem><para>
6362 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6363 Extra options passed to the <filename>make</filename> command
6364 during the
6365 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6366 task in order to specify parallel installation on the
6367 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006368 </para></listitem>
6369 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006370 As mentioned, these variables all scale to the number of processor
6371 cores available on the build system.
6372 For single socket systems, this auto-scaling ensures that the build
6373 system fundamentally takes advantage of potential parallel operations
6374 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006375 </para>
6376
6377 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006378 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006379 <itemizedlist>
6380 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006381 File system type:
6382 The file system type that the build is being performed on can
6383 also influence performance.
6384 Using <filename>ext4</filename> is recommended as compared
6385 to <filename>ext2</filename> and <filename>ext3</filename>
6386 due to <filename>ext4</filename> improved features
6387 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006388 </para></listitem>
6389 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006390 Disabling the updating of access time using
6391 <filename>noatime</filename>:
6392 The <filename>noatime</filename> mount option prevents the
6393 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006394 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006395 <listitem><para>
6396 Setting a longer commit:
6397 Using the "commit=" mount option increases the interval
6398 in seconds between disk cache writes.
6399 Changing this interval from the five second default to
6400 something longer increases the risk of data loss but decreases
6401 the need to write to the disk, thus increasing the build
6402 performance.
6403 </para></listitem>
6404 <listitem><para>
6405 Choosing the packaging backend:
6406 Of the available packaging backends, IPK is the fastest.
6407 Additionally, selecting a singular packaging backend also
6408 helps.
6409 </para></listitem>
6410 <listitem><para>
6411 Using <filename>tmpfs</filename> for
6412 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6413 as a temporary file system:
6414 While this can help speed up the build, the benefits are
6415 limited due to the compiler using
6416 <filename>-pipe</filename>.
6417 The build system goes to some lengths to avoid
6418 <filename>sync()</filename> calls into the
6419 file system on the principle that if there was a significant
6420 failure, the
6421 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6422 contents could easily be rebuilt.
6423 </para></listitem>
6424 <listitem><para>
6425 Inheriting the
6426 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6427 class:
6428 Inheriting this class has shown to speed up builds due to
6429 significantly lower amounts of data stored in the data
6430 cache as well as on disk.
6431 Inheriting this class also makes cleanup of
6432 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6433 faster, at the expense of being easily able to dive into the
6434 source code.
6435 File system maintainers have recommended that the fastest way
6436 to clean up large numbers of files is to reformat partitions
6437 rather than delete files due to the linear nature of
6438 partitions.
6439 This, of course, assumes you structure the disk partitions and
6440 file systems in a way that this is practical.
6441 </para></listitem>
6442 </itemizedlist>
6443 Aside from the previous list, you should keep some trade offs in
6444 mind that can help you speed up the build:
6445 <itemizedlist>
6446 <listitem><para>
6447 Remove items from
6448 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6449 that you might not need.
6450 </para></listitem>
6451 <listitem><para>
6452 Exclude debug symbols and other debug information:
6453 If you do not need these symbols and other debug information,
6454 disabling the <filename>*-dbg</filename> package generation
6455 can speed up the build.
6456 You can disable this generation by setting the
6457 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6458 variable to "1".
6459 </para></listitem>
6460 <listitem><para>
6461 Disable static library generation for recipes derived from
6462 <filename>autoconf</filename> or <filename>libtool</filename>:
6463 Following is an example showing how to disable static
6464 libraries and still provide an override to handle exceptions:
6465 <literallayout class='monospaced'>
6466 STATICLIBCONF = "--disable-static"
6467 STATICLIBCONF_sqlite3-native = ""
6468 EXTRA_OECONF += "${STATICLIBCONF}"
6469 </literallayout>
6470 <note><title>Notes</title>
6471 <itemizedlist>
6472 <listitem><para>
6473 Some recipes need static libraries in order to work
6474 correctly (e.g. <filename>pseudo-native</filename>
6475 needs <filename>sqlite3-native</filename>).
6476 Overrides, as in the previous example, account for
6477 these kinds of exceptions.
6478 </para></listitem>
6479 <listitem><para>
6480 Some packages have packaging code that assumes the
6481 presence of the static libraries.
6482 If so, you might need to exclude them as well.
6483 </para></listitem>
6484 </itemizedlist>
6485 </note>
6486 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006487 </itemizedlist>
6488 </para>
6489 </section>
6490
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006491 <section id="platdev-working-with-libraries">
6492 <title>Working With Libraries</title>
6493
6494 <para>
6495 Libraries are an integral part of your system.
6496 This section describes some common practices you might find
6497 helpful when working with libraries to build your system:
6498 <itemizedlist>
6499 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6500 </para></listitem>
6501 <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>
6502 </para></listitem>
6503 <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>
6504 </para></listitem>
6505 </itemizedlist>
6506 </para>
6507
6508 <section id='including-static-library-files'>
6509 <title>Including Static Library Files</title>
6510
6511 <para>
6512 If you are building a library and the library offers static linking, you can control
6513 which static library files (<filename>*.a</filename> files) get included in the
6514 built library.
6515 </para>
6516
6517 <para>
6518 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6519 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6520 variables in the
6521 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6522 by the <filename>do_install</filename> task are packaged.
6523 By default, the <filename>PACKAGES</filename> variable includes
6524 <filename>${PN}-staticdev</filename>, which represents all static library files.
6525 <note>
6526 Some previously released versions of the Yocto Project
6527 defined the static library files through
6528 <filename>${PN}-dev</filename>.
6529 </note>
6530 Following is part of the BitBake configuration file, where
6531 you can see how the static library files are defined:
6532 <literallayout class='monospaced'>
6533 PACKAGE_BEFORE_PN ?= ""
6534 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6535 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6536 FILES = ""
6537
6538 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6539 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6540 ${base_bindir}/* ${base_sbindir}/* \
6541 ${base_libdir}/*${SOLIBS} \
6542 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6543 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6544 ${datadir}/pixmaps ${datadir}/applications \
6545 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6546 ${libdir}/bonobo/servers"
6547
6548 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6549
6550 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6551 ${datadir}/gnome/help"
6552 SECTION_${PN}-doc = "doc"
6553
6554 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6555 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6556 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6557 ${datadir}/aclocal ${base_libdir}/*.o \
6558 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6559 SECTION_${PN}-dev = "devel"
6560 ALLOW_EMPTY_${PN}-dev = "1"
6561 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6562
6563 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6564 SECTION_${PN}-staticdev = "devel"
6565 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6566 </literallayout>
6567 </para>
6568 </section>
6569
6570 <section id="combining-multiple-versions-library-files-into-one-image">
6571 <title>Combining Multiple Versions of Library Files into One Image</title>
6572
6573 <para>
6574 The build system offers the ability to build libraries with different
6575 target optimizations or architecture formats and combine these together
6576 into one system image.
6577 You can link different binaries in the image
6578 against the different libraries as needed for specific use cases.
6579 This feature is called "Multilib."
6580 </para>
6581
6582 <para>
6583 An example would be where you have most of a system compiled in 32-bit
6584 mode using 32-bit libraries, but you have something large, like a database
6585 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6586 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6587 </para>
6588
6589 <para>
6590 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6591 the approach the build system uses facilitates different target optimizations.
6592 You could compile some binaries to use one set of libraries and other binaries
6593 to use a different set of libraries.
6594 The libraries could differ in architecture, compiler options, or other
6595 optimizations.
6596 </para>
6597
6598 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006599 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006600 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006601 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006602 <itemizedlist>
6603 <listitem><para><filename>conf/multilib-example.conf</filename>
6604 configuration file</para></listitem>
6605 <listitem><para><filename>conf/multilib-example2.conf</filename>
6606 configuration file</para></listitem>
6607 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6608 recipe</para></listitem>
6609 </itemizedlist>
6610 </para>
6611
6612 <section id='preparing-to-use-multilib'>
6613 <title>Preparing to Use Multilib</title>
6614
6615 <para>
6616 User-specific requirements drive the Multilib feature.
6617 Consequently, there is no one "out-of-the-box" configuration that likely
6618 exists to meet your needs.
6619 </para>
6620
6621 <para>
6622 In order to enable Multilib, you first need to ensure your recipe is
6623 extended to support multiple libraries.
6624 Many standard recipes are already extended and support multiple libraries.
6625 You can check in the <filename>meta/conf/multilib.conf</filename>
6626 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006627 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006628 done using the
6629 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6630 variable.
6631 Eventually, all recipes will be covered and this list will
6632 not be needed.
6633 </para>
6634
6635 <para>
6636 For the most part, the Multilib class extension works automatically to
6637 extend the package name from <filename>${PN}</filename> to
6638 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6639 is the particular multilib (e.g. "lib32-" or "lib64-").
6640 Standard variables such as
6641 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6642 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6643 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6644 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6645 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6646 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6647 are automatically extended by the system.
6648 If you are extending any manual code in the recipe, you can use the
6649 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6650 correctly.
6651 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6652 </para>
6653 </section>
6654
6655 <section id='using-multilib'>
6656 <title>Using Multilib</title>
6657
6658 <para>
6659 After you have set up the recipes, you need to define the actual
6660 combination of multiple libraries you want to build.
6661 You accomplish this through your <filename>local.conf</filename>
6662 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006663 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006664 An example configuration would be as follows:
6665 <literallayout class='monospaced'>
6666 MACHINE = "qemux86-64"
6667 require conf/multilib.conf
6668 MULTILIBS = "multilib:lib32"
6669 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006670 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006671 </literallayout>
6672 This example enables an
6673 additional library named <filename>lib32</filename> alongside the
6674 normal target packages.
6675 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6676 For information on this particular tuning, see
6677 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6678 </para>
6679
6680 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006681 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006682 in all the images, which illustrates one method of including a
6683 multiple library dependency.
6684 You can use a normal image build to include this dependency,
6685 for example:
6686 <literallayout class='monospaced'>
6687 $ bitbake core-image-sato
6688 </literallayout>
6689 You can also build Multilib packages specifically with a command like this:
6690 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006691 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006692 </literallayout>
6693 </para>
6694 </section>
6695
6696 <section id='additional-implementation-details'>
6697 <title>Additional Implementation Details</title>
6698
6699 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006700 Generic implementation details as well as details that are
6701 specific to package management systems exist.
6702 Following are implementation details that exist regardless
6703 of the package management system:
6704 <itemizedlist>
6705 <listitem><para>The typical convention used for the
6706 class extension code as used by
6707 Multilib assumes that all package names specified
6708 in
6709 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6710 that contain <filename>${PN}</filename> have
6711 <filename>${PN}</filename> at the start of the name.
6712 When that convention is not followed and
6713 <filename>${PN}</filename> appears at
6714 the middle or the end of a name, problems occur.
6715 </para></listitem>
6716 <listitem><para>The
6717 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6718 value under Multilib will be extended to
6719 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6720 (e.g. "-pokymllib32" for a "lib32" Multilib with
6721 Poky).
6722 The reason for this slightly unwieldy contraction
6723 is that any "-" characters in the vendor
6724 string presently break Autoconf's
6725 <filename>config.sub</filename>, and
6726 other separators are problematic for different
6727 reasons.
6728 </para></listitem>
6729 </itemizedlist>
6730 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006731
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006732 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006733 For the RPM Package Management System, the following implementation details
6734 exist:
6735 <itemizedlist>
6736 <listitem><para>A unique architecture is defined for the Multilib packages,
6737 along with creating a unique deploy folder under
6738 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006739 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006740 For example, consider <filename>lib32</filename> in a
6741 <filename>qemux86-64</filename> image.
6742 The possible architectures in the system are "all", "qemux86_64",
6743 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6744 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6745 <filename>${PN}</filename> during RPM packaging.
6746 The naming for a normal RPM package and a Multilib RPM package in a
6747 <filename>qemux86-64</filename> system resolves to something similar to
6748 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6749 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6750 </para></listitem>
6751 <listitem><para>When installing a Multilib image, the RPM backend first
6752 installs the base image and then installs the Multilib libraries.
6753 </para></listitem>
6754 <listitem><para>The build system relies on RPM to resolve the identical files in the
6755 two (or more) Multilib packages.</para></listitem>
6756 </itemizedlist>
6757 </para>
6758
6759 <para>
6760 For the IPK Package Management System, the following implementation details exist:
6761 <itemizedlist>
6762 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6763 <filename>${PN}</filename> during IPK packaging.
6764 The naming for a normal RPM package and a Multilib IPK package in a
6765 <filename>qemux86-64</filename> system resolves to something like
6766 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6767 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6768 </para></listitem>
6769 <listitem><para>The IPK deploy folder is not modified with
6770 <filename>${MLPREFIX}</filename> because packages with and without
6771 the Multilib feature can exist in the same folder due to the
6772 <filename>${PN}</filename> differences.</para></listitem>
6773 <listitem><para>IPK defines a sanity check for Multilib installation
6774 using certain rules for file comparison, overridden, etc.
6775 </para></listitem>
6776 </itemizedlist>
6777 </para>
6778 </section>
6779 </section>
6780
6781 <section id='installing-multiple-versions-of-the-same-library'>
6782 <title>Installing Multiple Versions of the Same Library</title>
6783
6784 <para>
6785 Situations can exist where you need to install and use
6786 multiple versions of the same library on the same system
6787 at the same time.
6788 These situations almost always exist when a library API
6789 changes and you have multiple pieces of software that
6790 depend on the separate versions of the library.
6791 To accommodate these situations, you can install multiple
6792 versions of the same library in parallel on the same system.
6793 </para>
6794
6795 <para>
6796 The process is straightforward as long as the libraries use
6797 proper versioning.
6798 With properly versioned libraries, all you need to do to
6799 individually specify the libraries is create separate,
6800 appropriately named recipes where the
6801 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6802 name includes a portion that differentiates each library version
6803 (e.g.the major part of the version number).
6804 Thus, instead of having a single recipe that loads one version
6805 of a library (e.g. <filename>clutter</filename>), you provide
6806 multiple recipes that result in different versions
6807 of the libraries you want.
6808 As an example, the following two recipes would allow the
6809 two separate versions of the <filename>clutter</filename>
6810 library to co-exist on the same system:
6811 <literallayout class='monospaced'>
6812 clutter-1.6_1.6.20.bb
6813 clutter-1.8_1.8.4.bb
6814 </literallayout>
6815 Additionally, if you have other recipes that depend on a given
6816 library, you need to use the
6817 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
6818 variable to create the dependency.
6819 Continuing with the same example, if you want to have a recipe
6820 depend on the 1.8 version of the <filename>clutter</filename>
6821 library, use the following in your recipe:
6822 <literallayout class='monospaced'>
6823 DEPENDS = "clutter-1.8"
6824 </literallayout>
6825 </para>
6826 </section>
6827 </section>
6828
Brad Bishop316dfdd2018-06-25 12:45:53 -04006829 <section id='using-x32-psabi'>
6830 <title>Using x32 psABI</title>
6831
6832 <para>
6833 x32 processor-specific Application Binary Interface
6834 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
6835 is a native 32-bit processor-specific ABI for
6836 <trademark class='registered'>Intel</trademark> 64 (x86-64)
6837 architectures.
6838 An ABI defines the calling conventions between functions in a
6839 processing environment.
6840 The interface determines what registers are used and what the
6841 sizes are for various C data types.
6842 </para>
6843
6844 <para>
6845 Some processing environments prefer using 32-bit applications even
6846 when running on Intel 64-bit platforms.
6847 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
6848 64-bit platforms.
6849 The i386 psABI does not provide efficient use and access of the
6850 Intel 64-bit processor resources, leaving the system underutilized.
6851 Now consider the x86_64 psABI.
6852 This ABI is newer and uses 64-bits for data sizes and program
6853 pointers.
6854 The extra bits increase the footprint size of the programs,
6855 libraries, and also increases the memory and file system size
6856 requirements.
6857 Executing under the x32 psABI enables user programs to utilize CPU
6858 and system resources more efficiently while keeping the memory
6859 footprint of the applications low.
6860 Extra bits are used for registers but not for addressing mechanisms.
6861 </para>
6862
6863 <para>
6864 The Yocto Project supports the final specifications of x32 psABI
6865 as follows:
6866 <itemizedlist>
6867 <listitem><para>
6868 You can create packages and images in x32 psABI format on
6869 x86_64 architecture targets.
6870 </para></listitem>
6871 <listitem><para>
6872 You can successfully build recipes with the x32 toolchain.
6873 </para></listitem>
6874 <listitem><para>
6875 You can create and boot
6876 <filename>core-image-minimal</filename> and
6877 <filename>core-image-sato</filename> images.
6878 </para></listitem>
6879 <listitem><para>
6880 RPM Package Manager (RPM) support exists for x32 binaries.
6881 </para></listitem>
6882 <listitem><para>
6883 Support for large images exists.
6884 </para></listitem>
6885 </itemizedlist>
6886 </para>
6887
6888 <para>
6889 To use the x32 psABI, you need to edit your
6890 <filename>conf/local.conf</filename> configuration file as
6891 follows:
6892 <literallayout class='monospaced'>
6893 MACHINE = "qemux86-64"
6894 DEFAULTTUNE = "x86-64-x32"
6895 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE', True) \
6896 or 'INVALID'), True) or 'lib'}"
6897 </literallayout>
6898 Once you have set up your configuration file, use BitBake to
6899 build an image that supports the x32 psABI.
6900 Here is an example:
6901 <literallayout class='monospaced'>
6902 $ bitbake core-image-sato
6903 </literallayout>
6904 </para>
6905 </section>
6906
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006907 <section id='enabling-gobject-introspection-support'>
6908 <title>Enabling GObject Introspection Support</title>
6909
6910 <para>
6911 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
6912 is the standard mechanism for accessing GObject-based software
6913 from runtime environments.
6914 GObject is a feature of the GLib library that provides an object
6915 framework for the GNOME desktop and related software.
6916 GObject Introspection adds information to GObject that allows
6917 objects created within it to be represented across different
6918 programming languages.
6919 If you want to construct GStreamer pipelines using Python, or
6920 control UPnP infrastructure using Javascript and GUPnP,
6921 GObject introspection is the only way to do it.
6922 </para>
6923
6924 <para>
6925 This section describes the Yocto Project support for generating
6926 and packaging GObject introspection data.
6927 GObject introspection data is a description of the
6928 API provided by libraries built on top of GLib framework,
6929 and, in particular, that framework's GObject mechanism.
6930 GObject Introspection Repository (GIR) files go to
6931 <filename>-dev</filename> packages,
6932 <filename>typelib</filename> files go to main packages as they
6933 are packaged together with libraries that are introspected.
6934 </para>
6935
6936 <para>
6937 The data is generated when building such a library, by linking
6938 the library with a small executable binary that asks the library
6939 to describe itself, and then executing the binary and
6940 processing its output.
6941 </para>
6942
6943 <para>
6944 Generating this data in a cross-compilation environment
6945 is difficult because the library is produced for the target
6946 architecture, but its code needs to be executed on the build host.
6947 This problem is solved with the OpenEmbedded build system by
6948 running the code through QEMU, which allows precisely that.
6949 Unfortunately, QEMU does not always work perfectly as mentioned
6950 in the xxx section.
6951 </para>
6952
6953 <section id='enabling-the-generation-of-introspection-data'>
6954 <title>Enabling the Generation of Introspection Data</title>
6955
6956 <para>
6957 Enabling the generation of introspection data (GIR files)
6958 in your library package involves the following:
6959 <orderedlist>
6960 <listitem><para>
6961 Inherit the
6962 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
6963 class.
6964 </para></listitem>
6965 <listitem><para>
6966 Make sure introspection is not disabled anywhere in
6967 the recipe or from anything the recipe includes.
6968 Also, make sure that "gobject-introspection-data" is
6969 not in
6970 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
6971 and that "qemu-usermode" is not in
6972 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
6973 If either of these conditions exist, nothing will
6974 happen.
6975 </para></listitem>
6976 <listitem><para>
6977 Try to build the recipe.
6978 If you encounter build errors that look like
6979 something is unable to find
6980 <filename>.so</filename> libraries, check where these
6981 libraries are located in the source tree and add
6982 the following to the recipe:
6983 <literallayout class='monospaced'>
6984 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
6985 </literallayout>
6986 <note>
6987 See recipes in the <filename>oe-core</filename>
6988 repository that use that
6989 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
6990 as an example.
6991 </note>
6992 </para></listitem>
6993 <listitem><para>
6994 Look for any other errors, which probably mean that
6995 introspection support in a package is not entirely
6996 standard, and thus breaks down in a cross-compilation
6997 environment.
6998 For such cases, custom-made fixes are needed.
6999 A good place to ask and receive help in these cases
7000 is the
7001 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7002 </para></listitem>
7003 </orderedlist>
7004 <note>
7005 Using a library that no longer builds against the latest
7006 Yocto Project release and prints introspection related
7007 errors is a good candidate for the previous procedure.
7008 </note>
7009 </para>
7010 </section>
7011
7012 <section id='disabling-the-generation-of-introspection-data'>
7013 <title>Disabling the Generation of Introspection Data</title>
7014
7015 <para>
7016 You might find that you do not want to generate
7017 introspection data.
7018 Or, perhaps QEMU does not work on your build host and
7019 target architecture combination.
7020 If so, you can use either of the following methods to
7021 disable GIR file generations:
7022 <itemizedlist>
7023 <listitem><para>
7024 Add the following to your distro configuration:
7025 <literallayout class='monospaced'>
7026 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7027 </literallayout>
7028 Adding this statement disables generating
7029 introspection data using QEMU but will still enable
7030 building introspection tools and libraries
7031 (i.e. building them does not require the use of QEMU).
7032 </para></listitem>
7033 <listitem><para>
7034 Add the following to your machine configuration:
7035 <literallayout class='monospaced'>
7036 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7037 </literallayout>
7038 Adding this statement disables the use of QEMU
7039 when building packages for your machine.
7040 Currently, this feature is used only by introspection
7041 recipes and has the same effect as the previously
7042 described option.
7043 <note>
7044 Future releases of the Yocto Project might have
7045 other features affected by this option.
7046 </note>
7047 </para></listitem>
7048 </itemizedlist>
7049 If you disable introspection data, you can still
7050 obtain it through other means such as copying the data
7051 from a suitable sysroot, or by generating it on the
7052 target hardware.
7053 The OpenEmbedded build system does not currently
7054 provide specific support for these techniques.
7055 </para>
7056 </section>
7057
7058 <section id='testing-that-introspection-works-in-an-image'>
7059 <title>Testing that Introspection Works in an Image</title>
7060
7061 <para>
7062 Use the following procedure to test if generating
7063 introspection data is working in an image:
7064 <orderedlist>
7065 <listitem><para>
7066 Make sure that "gobject-introspection-data" is not in
7067 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7068 and that "qemu-usermode" is not in
7069 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7070 </para></listitem>
7071 <listitem><para>
7072 Build <filename>core-image-sato</filename>.
7073 </para></listitem>
7074 <listitem><para>
7075 Launch a Terminal and then start Python in the
7076 terminal.
7077 </para></listitem>
7078 <listitem><para>
7079 Enter the following in the terminal:
7080 <literallayout class='monospaced'>
7081 >>> from gi.repository import GLib
7082 >>> GLib.get_host_name()
7083 </literallayout>
7084 </para></listitem>
7085 <listitem><para>
7086 For something a little more advanced, enter the
7087 following:
7088 <literallayout class='monospaced'>
7089 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7090 </literallayout>
7091 </para></listitem>
7092 </orderedlist>
7093 </para>
7094 </section>
7095
7096 <section id='known-issues'>
7097 <title>Known Issues</title>
7098
7099 <para>
7100 The following know issues exist for
7101 GObject Introspection Support:
7102 <itemizedlist>
7103 <listitem><para>
7104 <filename>qemu-ppc64</filename> immediately crashes.
7105 Consequently, you cannot build introspection data on
7106 that architecture.
7107 </para></listitem>
7108 <listitem><para>
7109 x32 is not supported by QEMU.
7110 Consequently, introspection data is disabled.
7111 </para></listitem>
7112 <listitem><para>
7113 musl causes transient GLib binaries to crash on
7114 assertion failures.
7115 Consequently, generating introspection data is
7116 disabled.
7117 </para></listitem>
7118 <listitem><para>
7119 Because QEMU is not able to run the binaries correctly,
7120 introspection is disabled for some specific packages
7121 under specific architectures (e.g.
7122 <filename>gcr</filename>,
7123 <filename>libsecret</filename>, and
7124 <filename>webkit</filename>).
7125 </para></listitem>
7126 <listitem><para>
7127 QEMU usermode might not work properly when running
7128 64-bit binaries under 32-bit host machines.
7129 In particular, "qemumips64" is known to not work under
7130 i686.
7131 </para></listitem>
7132 </itemizedlist>
7133 </para>
7134 </section>
7135 </section>
7136
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007137 <section id='dev-optionally-using-an-external-toolchain'>
7138 <title>Optionally Using an External Toolchain</title>
7139
7140 <para>
7141 You might want to use an external toolchain as part of your
7142 development.
7143 If this is the case, the fundamental steps you need to accomplish
7144 are as follows:
7145 <itemizedlist>
7146 <listitem><para>
7147 Understand where the installed toolchain resides.
7148 For cases where you need to build the external toolchain,
7149 you would need to take separate steps to build and install
7150 the toolchain.
7151 </para></listitem>
7152 <listitem><para>
7153 Make sure you add the layer that contains the toolchain to
7154 your <filename>bblayers.conf</filename> file through the
7155 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7156 variable.
7157 </para></listitem>
7158 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007159 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007160 variable in your <filename>local.conf</filename> file
7161 to the location in which you installed the toolchain.
7162 </para></listitem>
7163 </itemizedlist>
7164 A good example of an external toolchain used with the Yocto Project
7165 is <trademark class='registered'>Mentor Graphics</trademark>
7166 Sourcery G++ Toolchain.
7167 You can see information on how to use that particular layer in the
7168 <filename>README</filename> file at
7169 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7170 You can find further information by reading about the
7171 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7172 variable in the Yocto Project Reference Manual's variable glossary.
7173 </para>
7174 </section>
7175
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007176 <section id='creating-partitioned-images-using-wic'>
7177 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007178
7179 <para>
7180 Creating an image for a particular hardware target using the
7181 OpenEmbedded build system does not necessarily mean you can boot
7182 that image as is on your device.
7183 Physical devices accept and boot images in various ways depending
7184 on the specifics of the device.
7185 Usually, information about the hardware can tell you what image
7186 format the device requires.
7187 Should your device require multiple partitions on an SD card, flash,
7188 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007189 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007190 </para>
7191
7192 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007193 The <filename>wic</filename> command generates partitioned
7194 images from existing OpenEmbedded build artifacts.
7195 Image generation is driven by partitioning commands
7196 contained in an Openembedded kickstart file
7197 (<filename>.wks</filename>) specified either directly on
7198 the command line or as one of a selection of canned
7199 kickstart files as shown with the
7200 <filename>wic list images</filename> command in the
7201 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7202 section.
7203 When you apply the command to a given set of build
7204 artifacts, the result is an image or set of images that
7205 can be directly written onto media and used on a particular
7206 system.
7207 <note>
7208 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007209 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007210 Chapter in the Yocto Project Reference Manual.
7211 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007212 </para>
7213
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007214 <para>
7215 The <filename>wic</filename> command and the infrastructure
7216 it is based on is by definition incomplete.
7217 The purpose of the command is to allow the generation of
7218 customized images, and as such, was designed to be
7219 completely extensible through a plug-in interface.
7220 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007221 "<link linkend='wic-using-the-wic-plug-ins-interface'>Using the Wic Plug-Ins Interface</link>"
7222 section for information on these plug-ins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007223 </para>
7224
7225 <para>
7226 This section provides some background information on Wic,
7227 describes what you need to have in
7228 place to run the tool, provides instruction on how to use
Brad Bishop316dfdd2018-06-25 12:45:53 -04007229 the Wic utility, provides information on using the Wic plug-ins
7230 interface, and provides several examples that show how to use
7231 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007232 </para>
7233
7234 <section id='wic-background'>
7235 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007236
7237 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007238 This section provides some background on the Wic utility.
7239 While none of this information is required to use
7240 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007241 <itemizedlist>
7242 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007243 The name "Wic" is derived from OpenEmbedded
7244 Image Creator (oeic).
7245 The "oe" diphthong in "oeic" was promoted to the
7246 letter "w", because "oeic" is both difficult to
7247 remember and to pronounce.
7248 </para></listitem>
7249 <listitem><para>
7250 Wic is loosely based on the
7251 Meego Image Creator (<filename>mic</filename>)
7252 framework.
7253 The Wic implementation has been
7254 heavily modified to make direct use of OpenEmbedded
7255 build artifacts instead of package installation and
7256 configuration, which are already incorporated within
7257 the OpenEmbedded artifacts.
7258 </para></listitem>
7259 <listitem><para>
7260 Wic is a completely independent
7261 standalone utility that initially provides
7262 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007263 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007264 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007265 class.
7266 The difference between Wic and those examples is
7267 that with Wic the functionality of those scripts is
7268 implemented by a general-purpose partitioning language,
7269 which is based on Redhat kickstart syntax.
7270 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007271 </itemizedlist>
7272 </para>
7273 </section>
7274
7275 <section id='wic-requirements'>
7276 <title>Requirements</title>
7277
7278 <para>
7279 In order to use the Wic utility with the OpenEmbedded Build
7280 system, your system needs to meet the following
7281 requirements:
7282 <itemizedlist>
7283 <listitem><para>
7284 The Linux distribution on your development host must
7285 support the Yocto Project.
7286 See the
7287 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7288 section in the Yocto Project Reference Manual for
7289 the list of distributions that support the
7290 Yocto Project.
7291 </para></listitem>
7292 <listitem><para>
7293 The standard system utilities, such as
7294 <filename>cp</filename>, must be installed on your
7295 development host system.
7296 </para></listitem>
7297 <listitem><para>
7298 You must have sourced the build environment
7299 setup script (i.e.
7300 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7301 found in the
7302 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7303 </para></listitem>
7304 <listitem><para>
7305 You need to have the build artifacts already
7306 available, which typically means that you must
7307 have already created an image using the
7308 Openembedded build system (e.g.
7309 <filename>core-image-minimal</filename>).
7310 While it might seem redundant to generate an image
7311 in order to create an image using
7312 Wic, the current version of
7313 Wic requires the artifacts
7314 in the form generated by the OpenEmbedded build
7315 system.
7316 </para></listitem>
7317 <listitem><para>
7318 You must build several native tools, which are
7319 built to run on the build system:
7320 <literallayout class='monospaced'>
7321 $ bitbake parted-native dosfstools-native mtools-native
7322 </literallayout>
7323 </para></listitem>
7324 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007325 Include "wic" as part of the
7326 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7327 variable.
7328 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007329 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007330 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007331 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007332 as part of the
7333 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7334 variable
7335 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007336 </itemizedlist>
7337 </para>
7338 </section>
7339
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007340 <section id='wic-getting-help'>
7341 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007342
7343 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007344 You can get general help for the <filename>wic</filename>
7345 command by entering the <filename>wic</filename> command
7346 by itself or by entering the command with a help argument
7347 as follows:
7348 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007349 $ wic -h
7350 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007351 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007352 </literallayout>
7353 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007354
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007355 <para>
7356 Currently, Wic supports seven commands:
7357 <filename>cp</filename>, <filename>create</filename>,
7358 <filename>help</filename>, <filename>list</filename>,
7359 <filename>ls</filename>, <filename>rm</filename>, and
7360 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007361 You can get help for all these commands except "help" by
7362 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007363 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007364 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007365 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007366 For example, the following command returns help for the
7367 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007368 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007369 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007370 </literallayout>
7371 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007372
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007373 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007374 Wic supports help for three topics:
7375 <filename>overview</filename>,
7376 <filename>plugins</filename>, and
7377 <filename>kickstart</filename>.
7378 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007379 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007380 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007381 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007382 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007383 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007384 $ wic help overview
7385 </literallayout>
7386 </para>
7387
7388 <para>
7389 One additional level of help exists for Wic.
7390 You can get help on individual images through the
7391 <filename>list</filename> command.
7392 You can use the <filename>list</filename> command to return the
7393 available Wic images as follows:
7394 <literallayout class='monospaced'>
7395 $ wic list images
7396 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7397 genericx86 Create an EFI disk image for genericx86*
7398 beaglebone-yocto Create SD card image for Beaglebone
7399 edgerouter Create SD card image for Edgerouter
7400 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7401 directdisk-gpt Create a 'pcbios' direct disk image
7402 mkefidisk Create an EFI disk image
7403 directdisk Create a 'pcbios' direct disk image
7404 systemd-bootdisk Create an EFI disk image with systemd-boot
7405 mkhybridiso Create a hybrid ISO image
7406 sdimage-bootpart Create SD card image with a boot partition
7407 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7408 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7409 </literallayout>
7410 Once you know the list of available Wic images, you can use
7411 <filename>help</filename> with the command to get help on a
7412 particular image.
7413 For example, the following command returns help on the
7414 "beaglebone-yocto" image:
7415 <literallayout class='monospaced'>
7416 $ wic list beaglebone-yocto help
7417
7418
7419 Creates a partitioned SD card image for Beaglebone.
7420 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007421 </literallayout>
7422 </para>
7423 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007424
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007425 <section id='operational-modes'>
7426 <title>Operational Modes</title>
7427
7428 <para>
7429 You can use Wic in two different
7430 modes, depending on how much control you need for
7431 specifying the Openembedded build artifacts that are
7432 used for creating the image: Raw and Cooked:
7433 <itemizedlist>
7434 <listitem><para>
7435 <emphasis>Raw Mode:</emphasis>
7436 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007437 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007438 </para></listitem>
7439 <listitem><para>
7440 <emphasis>Cooked Mode:</emphasis>
7441 The current
7442 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7443 setting and image name are used to automatically
7444 locate and provide the build artifacts.
7445 You just supply a kickstart file and the name
7446 of the image from which to use artifacts.
7447 </para></listitem>
7448 </itemizedlist>
7449 </para>
7450
7451 <para>
7452 Regardless of the mode you use, you need to have the build
7453 artifacts ready and available.
7454 </para>
7455
7456 <section id='raw-mode'>
7457 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007458
7459 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007460 Running Wic in raw mode allows you to specify all the
7461 partitions through the <filename>wic</filename>
7462 command line.
7463 The primary use for raw mode is if you have built
7464 your kernel outside of the Yocto Project
7465 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7466 In other words, you can point to arbitrary kernel,
7467 root filesystem locations, and so forth.
7468 Contrast this behavior with cooked mode where Wic
7469 looks in the Build Directory (e.g.
7470 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007471 </para>
7472
7473 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007474 The general form of the
7475 <filename>wic</filename> command in raw mode is:
7476 <literallayout class='monospaced'>
7477 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007478
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007479 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007480
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007481 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007482 An OpenEmbedded kickstart file. You can provide
7483 your own custom file or use a file from a set of
7484 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007485
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007486 optional arguments:
7487 -h, --help show this help message and exit
7488 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7489 name of directory to create image in
7490 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7491 name of the image to use the artifacts from e.g. core-
7492 image-sato
7493 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7494 path to the /rootfs dir to use as the .wks rootfs
7495 source
7496 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7497 path to the dir containing the boot artifacts (e.g.
7498 /EFI or /syslinux dirs) to use as the .wks bootimg
7499 source
7500 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7501 path to the dir containing the kernel to use in the
7502 .wks bootimg
7503 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7504 path to the native sysroot containing the tools to use
7505 to build the image
7506 -s, --skip-build-check
7507 skip the build check
7508 -f, --build-rootfs build rootfs
7509 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7510 compress image with specified compressor
7511 -m, --bmap generate .bmap
7512 --no-fstab-update Do not change fstab file.
7513 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7514 directory with &lt;image&gt;.env files that store bitbake
7515 variables
7516 -D, --debug output debug information
7517 </literallayout>
7518 <note>
7519 You do not need root privileges to run
7520 Wic.
7521 In fact, you should not run as root when using the
7522 utility.
7523 </note>
7524 </para>
7525 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007526
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007527 <section id='cooked-mode'>
7528 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007529
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007530 <para>
7531 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007532 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007533 In other words, you do not have to specify kernel or
7534 root filesystem locations as part of the command.
7535 All you need to provide is a kickstart file and the
7536 name of the image from which to use artifacts by using
7537 the "-e" option.
7538 Wic looks in the Build Directory (e.g.
7539 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7540 for artifacts.
7541 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007542
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007543 <para>
7544 The general form of the <filename>wic</filename>
7545 command using Cooked Mode is as follows:
7546 <literallayout class='monospaced'>
7547 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007548
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007549 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007550
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007551 <replaceable>wks_file</replaceable>:
7552 An OpenEmbedded kickstart file. You can provide
7553 your own custom file or use a file from a set of
7554 existing files provided with the Yocto Project
7555 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007556
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007557 required argument:
7558 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7559 name of the image to use the artifacts from e.g. core-
7560 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007561 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007562 </para>
7563 </section>
7564 </section>
7565
7566 <section id='using-a-provided-kickstart-file'>
7567 <title>Using an Existing Kickstart File</title>
7568
7569 <para>
7570 If you do not want to create your own kickstart file, you
7571 can use an existing file provided by the Wic installation.
7572 As shipped, kickstart files can be found in the
7573 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007574 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007575 in the following two locations:
7576 <literallayout class='monospaced'>
7577 poky/meta-yocto-bsp/wic
7578 poky/scripts/lib/wic/canned-wks
7579 </literallayout>
7580 Use the following command to list the available kickstart
7581 files:
7582 <literallayout class='monospaced'>
7583 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007584 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7585 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007586 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007587 edgerouter Create SD card image for Edgerouter
7588 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7589 directdisk-gpt Create a 'pcbios' direct disk image
7590 mkefidisk Create an EFI disk image
7591 directdisk Create a 'pcbios' direct disk image
7592 systemd-bootdisk Create an EFI disk image with systemd-boot
7593 mkhybridiso Create a hybrid ISO image
7594 sdimage-bootpart Create SD card image with a boot partition
7595 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7596 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7597 </literallayout>
7598 When you use an existing file, you do not have to use the
7599 <filename>.wks</filename> extension.
7600 Here is an example in Raw Mode that uses the
7601 <filename>directdisk</filename> file:
7602 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007603 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7604 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007605 </literallayout>
7606 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007607
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007608 <para>
7609 Here are the actual partition language commands
7610 used in the <filename>genericx86.wks</filename> file to
7611 generate an image:
7612 <literallayout class='monospaced'>
7613 # short-description: Create an EFI disk image for genericx86*
7614 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7615 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7616 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007617 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7618
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007619 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7620 </literallayout>
7621 </para>
7622 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007623
Brad Bishop316dfdd2018-06-25 12:45:53 -04007624 <section id='wic-using-the-wic-plug-ins-interface'>
7625 <title>Using the Wic Plug-Ins Interface</title>
7626
7627 <para>
7628 You can extend and specialize Wic functionality by using
7629 Wic plug-ins.
7630 This section explains the Wic plug-in interface.
7631 <note>
7632 Wic plug-ins consist of "source" and "imager" plug-ins.
7633 Imager plug-ins are beyond the scope of this section.
7634 </note>
7635 </para>
7636
7637 <para>
7638 Source plug-ins provide a mechanism to customize partition
7639 content during the Wic image generation process.
7640 You can use source plug-ins to map values that you specify
7641 using <filename>--source</filename> commands in kickstart
7642 files (i.e. <filename>*.wks</filename>) to a plug-in
7643 implementation used to populate a given partition.
7644 <note>
7645 If you use plug-ins that have build-time dependencies
7646 (e.g. native tools, bootloaders, and so forth)
7647 when building a Wic image, you need to specify those
7648 dependencies using the
7649 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7650 variable.
7651 </note>
7652 </para>
7653
7654 <para>
7655 Source plug-ins are subclasses defined in plug-in files.
7656 As shipped, the Yocto Project provides several plug-in
7657 files.
7658 You can see the source plug-in files that ship with the
7659 Yocto Project
7660 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
7661 Each of these plug-in files contains source plug-ins that
7662 are designed to populate a specific Wic image partition.
7663 </para>
7664
7665 <para>
7666 Source plug-ins are subclasses of the
7667 <filename>SourcePlugin</filename> class, which is
7668 defined in the
7669 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7670 file.
7671 For example, the <filename>BootimgEFIPlugin</filename>
7672 source plug-in found in the
7673 <filename>bootimg-efi.py</filename> file is a subclass of
7674 the <filename>SourcePlugin</filename> class, which is found
7675 in the <filename>pluginbase.py</filename> file.
7676 </para>
7677
7678 <para>
7679 You can also implement source plug-ins in a layer outside
7680 of the Source Repositories (external layer).
7681 To do so, be sure that your plug-in files are located in
7682 a directory whose path is
7683 <filename>scripts/lib/wic/plugins/source/</filename>
7684 within your external layer.
7685 When the plug-in files are located there, the source
7686 plug-ins they contain are made available to Wic.
7687 </para>
7688
7689 <para>
7690 When the Wic implementation needs to invoke a
7691 partition-specific implementation, it looks for the plug-in
7692 with the same name as the <filename>--source</filename>
7693 parameter used in the kickstart file given to that
7694 partition.
7695 For example, if the partition is set up using the following
7696 command in a kickstart file:
7697 <literallayout class='monospaced'>
7698 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7699 </literallayout>
7700 The methods defined as class members of the matching
7701 source plug-in (i.e. <filename>bootimg-pcbios</filename>)
7702 in the <filename>bootimg-pcbios.py</filename> plug-in file
7703 are used.
7704 </para>
7705
7706 <para>
7707 To be more concrete, here is the corresponding plug-in
7708 definition from the <filename>bootimg-pcbios.py</filename>
7709 file for the previous command along with an example
7710 method called by the Wic implementation when it needs to
7711 prepare a partition using an implementation-specific
7712 function:
7713 <literallayout class='monospaced'>
7714 .
7715 .
7716 .
7717 class BootimgPcbiosPlugin(SourcePlugin):
7718 """
7719 Create MBR boot partition and install syslinux on it.
7720 """
7721
7722 name = 'bootimg-pcbios'
7723 .
7724 .
7725 .
7726 @classmethod
7727 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7728 oe_builddir, bootimg_dir, kernel_dir,
7729 rootfs_dir, native_sysroot):
7730 """
7731 Called to do the actual content population for a partition i.e. it
7732 'prepares' the partition to be incorporated into the image.
7733 In this case, prepare content for legacy bios boot partition.
7734 """
7735 .
7736 .
7737 .
7738 </literallayout>
7739 If a subclass (plug-in) itself does not implement a
7740 particular function, Wic locates and uses the default
7741 version in the superclass.
7742 It is for this reason that all source plug-ins are derived
7743 from the <filename>SourcePlugin</filename> class.
7744 </para>
7745
7746 <para>
7747 The <filename>SourcePlugin</filename> class defined in
7748 the <filename>pluginbase.py</filename> file defines
7749 a set of methods that source plug-ins can implement or
7750 override.
7751 Any plug-ins (subclass of
7752 <filename>SourcePlugin</filename>) that do not implement
7753 a particular method inherit the implementation of the
7754 method from the <filename>SourcePlugin</filename> class.
7755 For more information, see the
7756 <filename>SourcePlugin</filename> class in the
7757 <filename>pluginbase.py</filename> file for details:
7758 </para>
7759
7760 <para>
7761 The following list describes the methods implemented in the
7762 <filename>SourcePlugin</filename> class:
7763 <itemizedlist>
7764 <listitem><para>
7765 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7766 Called to populate a partition with actual content.
7767 In other words, the method prepares the final
7768 partition image that is incorporated into the
7769 disk image.
7770 </para></listitem>
7771 <listitem><para>
7772 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7773 Called before
7774 <filename>do_prepare_partition()</filename> to
7775 create custom configuration files for a partition
7776 (e.g. syslinux or grub configuration files).
7777 </para></listitem>
7778 <listitem><para>
7779 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7780 Called after all partitions have been prepared and
7781 assembled into a disk image.
7782 This method provides a hook to allow finalization
7783 of a disk image (e.g. writing an MBR).
7784 </para></listitem>
7785 <listitem><para>
7786 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7787 Special content-staging hook called before
7788 <filename>do_prepare_partition()</filename>.
7789 This method is normally empty.</para>
7790
7791 <para>Typically, a partition just uses the passed-in
7792 parameters (e.g. the unmodified value of
7793 <filename>bootimg_dir</filename>).
7794 However, in some cases, things might need to be
7795 more tailored.
7796 As an example, certain files might additionally
7797 need to be taken from
7798 <filename>bootimg_dir + /boot</filename>.
7799 This hook allows those files to be staged in a
7800 customized fashion.
7801 <note>
7802 <filename>get_bitbake_var()</filename>
7803 allows you to access non-standard variables
7804 that you might want to use for this
7805 behavior.
7806 </note>
7807 </para></listitem>
7808 </itemizedlist>
7809 </para>
7810
7811 <para>
7812 You can extend the source plug-in mechanism.
7813 To add more hooks, create more source plug-in methods
7814 within <filename>SourcePlugin</filename> and the
7815 corresponding derived subclasses.
7816 The code that calls the plug-in methods uses the
7817 <filename>plugin.get_source_plugin_methods()</filename>
7818 function to find the method or methods needed by the call.
7819 Retrieval of those methods is accomplished by filling up
7820 a dict with keys that contain the method names of interest.
7821 On success, these will be filled in with the actual
7822 methods.
7823 See the Wic implementation for examples and details.
7824 </para>
7825 </section>
7826
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007827 <section id='wic-usage-examples'>
7828 <title>Examples</title>
7829
7830 <para>
7831 This section provides several examples that show how to use
7832 the Wic utility.
7833 All the examples assume the list of requirements in the
7834 "<link linkend='wic-requirements'>Requirements</link>"
7835 section have been met.
7836 The examples assume the previously generated image is
7837 <filename>core-image-minimal</filename>.
7838 </para>
7839
7840 <section id='generate-an-image-using-a-provided-kickstart-file'>
7841 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007842
7843 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007844 This example runs in Cooked Mode and uses the
7845 <filename>mkefidisk</filename> kickstart file:
7846 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007847 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007848 INFO: Building wic-tools...
7849 .
7850 .
7851 .
7852 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007853 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007854
7855 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04007856 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
7857 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
7858 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
7859 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 -05007860
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007861 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04007862 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007863 </literallayout>
7864 The previous example shows the easiest way to create
7865 an image by running in cooked mode and supplying
7866 a kickstart file and the "-e" option to point to the
7867 existing build artifacts.
7868 Your <filename>local.conf</filename> file needs to have
7869 the
7870 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7871 variable set to the machine you are using, which is
7872 "qemux86" in this example.
7873 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007874
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007875 <para>
7876 Once the image builds, the output provides image
7877 location, artifact use, and kickstart file information.
7878 <note>
7879 You should always verify the details provided in the
7880 output to make sure that the image was indeed
7881 created exactly as expected.
7882 </note>
7883 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007884
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007885 <para>
7886 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007887 image from the Build Directory onto a USB stick, or
7888 whatever media for which you built your image, and boot
7889 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007890 You can write the image by using
7891 <filename>bmaptool</filename> or
7892 <filename>dd</filename>:
7893 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007894 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007895 </literallayout>
7896 or
7897 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007898 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007899 </literallayout>
7900 <note>
7901 For more information on how to use the
7902 <filename>bmaptool</filename> to flash a device
7903 with an image, see the
7904 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
7905 section.
7906 </note>
7907 </para>
7908 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007909
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007910 <section id='using-a-modified-kickstart-file'>
7911 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007912
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007913 <para>
7914 Because partitioned image creation is driven by the
7915 kickstart file, it is easy to affect image creation by
7916 changing the parameters in the file.
7917 This next example demonstrates that through modification
7918 of the <filename>directdisk-gpt</filename> kickstart
7919 file.
7920 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007921
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007922 <para>
7923 As mentioned earlier, you can use the command
7924 <filename>wic list images</filename> to show the list
7925 of existing kickstart files.
7926 The directory in which the
7927 <filename>directdisk-gpt.wks</filename> file resides is
7928 <filename>scripts/lib/image/canned-wks/</filename>,
7929 which is located in the
7930 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
7931 (e.g. <filename>poky</filename>).
7932 Because available files reside in this directory,
7933 you can create and add your own custom files to the
7934 directory.
7935 Subsequent use of the
7936 <filename>wic list images</filename> command would then
7937 include your kickstart files.
7938 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007939
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007940 <para>
7941 In this example, the existing
7942 <filename>directdisk-gpt</filename> file already does
7943 most of what is needed.
7944 However, for the hardware in this example, the image
7945 will need to boot from <filename>sdb</filename> instead
7946 of <filename>sda</filename>, which is what the
7947 <filename>directdisk-gpt</filename> kickstart file
7948 uses.
7949 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007950
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007951 <para>
7952 The example begins by making a copy of the
7953 <filename>directdisk-gpt.wks</filename> file in the
7954 <filename>scripts/lib/image/canned-wks</filename>
7955 directory and then by changing the lines that specify
7956 the target disk from which to boot.
7957 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007958 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
7959 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007960 </literallayout>
7961 Next, the example modifies the
7962 <filename>directdisksdb-gpt.wks</filename> file and
7963 changes all instances of
7964 "<filename>--ondisk sda</filename>" to
7965 "<filename>--ondisk sdb</filename>".
7966 The example changes the following two lines and leaves
7967 the remaining lines untouched:
7968 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007969 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007970 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
7971 </literallayout>
7972 Once the lines are changed, the example generates the
7973 <filename>directdisksdb-gpt</filename> image.
7974 The command points the process at the
7975 <filename>core-image-minimal</filename> artifacts for
7976 the Next Unit of Computing (nuc)
7977 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7978 the <filename>local.conf</filename>.
7979 <literallayout class='monospaced'>
7980 $ wic create directdisksdb-gpt -e core-image-minimal
7981 INFO: Building wic-tools...
7982 .
7983 .
7984 .
7985 Initialising tasks: 100% |#######################################| Time: 0:00:01
7986 NOTE: Executing SetScene Tasks
7987 NOTE: Executing RunQueue Tasks
7988 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
7989 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007990
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007991 INFO: The new image(s) can be found here:
7992 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007993
7994 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04007995 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
7996 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
7997 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
7998 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 -05007999
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008000 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008001 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008002 </literallayout>
8003 Continuing with the example, you can now directly
8004 <filename>dd</filename> the image to a USB stick, or
8005 whatever media for which you built your image,
8006 and boot the resulting media:
8007 <literallayout class='monospaced'>
8008 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8009 140966+0 records in
8010 140966+0 records out
8011 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8012 $ sudo eject /dev/sdb
8013 </literallayout>
8014 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008015 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008016
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008017 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8018 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008019
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008020 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008021 This next example manually specifies each build artifact
8022 (runs in Raw Mode) and uses a modified kickstart file.
8023 The example also uses the <filename>-o</filename> option
8024 to cause Wic to create the output
8025 somewhere other than the default output directory,
8026 which is the current directory:
8027 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008028 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8029 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8030 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8031 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8032 --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 -05008033
8034 INFO: Creating image(s)...
8035
8036 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008037 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008038
8039 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008040 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8041 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8042 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8043 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 -05008044
8045 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008046 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008047 </literallayout>
8048 For this example,
8049 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8050 did not have to be specified in the
8051 <filename>local.conf</filename> file since the
8052 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008053 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008054 </section>
8055
8056 <section id='using-wic-to-manipulate-an-image'>
8057 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008058
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008059 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008060 Wic image manipulation allows you to shorten turnaround
8061 time during image development.
8062 For example, you can use Wic to delete the kernel partition
8063 of a Wic image and then insert a newly built kernel.
8064 This saves you time from having to rebuild the entire image
8065 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008066 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008067 In order to use Wic to manipulate a Wic image as in
8068 this example, your development machine must have the
8069 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008070 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008071 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008072
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008073 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008074 The following example examines the contents of the Wic
8075 image, deletes the existing kernel, and then inserts a
8076 new kernel:
8077 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008078 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008079 <emphasis>List the Partitions:</emphasis>
8080 Use the <filename>wic ls</filename> command to list
8081 all the partitions in the Wic image:
8082 <literallayout class='monospaced'>
8083 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8084 Num Start End Size Fstype
8085 1 1048576 25041919 23993344 fat16
8086 2 25165824 72157183 46991360 ext4
8087 </literallayout>
8088 The previous output shows two partitions in the
8089 <filename>core-image-minimal-qemux86.wic</filename>
8090 image.
8091 </para></listitem>
8092 <listitem><para>
8093 <emphasis>Examine a Particular Partition:</emphasis>
8094 Use the <filename>wic ls</filename> command again
8095 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008096 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008097 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008098 You can get command usage on any Wic command
8099 using the following form:
8100 <literallayout class='monospaced'>
8101 $ wic help <replaceable>command</replaceable>
8102 </literallayout>
8103 For example, the following command shows you
8104 the various ways to use the
8105 <filename>wic ls</filename> command:
8106 <literallayout class='monospaced'>
8107 $ wic help ls
8108 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008109 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008110 The following command shows what is in Partition
8111 one:
8112 <literallayout class='monospaced'>
8113 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8114 Volume in drive : is boot
8115 Volume Serial Number is E894-1809
8116 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008117
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008118 libcom32 c32 186500 2017-10-09 16:06
8119 libutil c32 24148 2017-10-09 16:06
8120 syslinux cfg 220 2017-10-09 16:06
8121 vesamenu c32 27104 2017-10-09 16:06
8122 vmlinuz 6904608 2017-10-09 16:06
8123 5 files 7 142 580 bytes
8124 16 582 656 bytes free
8125 </literallayout>
8126 The previous output shows five files, with the
8127 <filename>vmlinuz</filename> being the kernel.
8128 <note>
8129 If you see the following error, you need to
8130 update or create a
8131 <filename>~/.mtoolsrc</filename> file and
8132 be sure to have the line “mtools_skip_check=1“
8133 in the file.
8134 Then, run the Wic command again:
8135 <literallayout class='monospaced'>
8136 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8137 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8138 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8139 </literallayout>
8140 </note>
8141 </para></listitem>
8142 <listitem><para>
8143 <emphasis>Remove the Old Kernel:</emphasis>
8144 Use the <filename>wic rm</filename> command to
8145 remove the <filename>vmlinuz</filename> file
8146 (kernel):
8147 <literallayout class='monospaced'>
8148 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8149 </literallayout>
8150 </para></listitem>
8151 <listitem><para>
8152 <emphasis>Add In the New Kernel:</emphasis>
8153 Use the <filename>wic cp</filename> command to
8154 add the updated kernel to the Wic image.
8155 Depending on how you built your kernel, it could
8156 be in different places.
8157 If you used <filename>devtool</filename> and
8158 an SDK to build your kernel, it resides in the
8159 <filename>tmp/work</filename> directory of the
8160 extensible SDK.
8161 If you used <filename>make</filename> to build the
8162 kernel, the kernel will be in the
8163 <filename>workspace/sources</filename> area.
8164 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008165
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008166 <para>The following example assumes
8167 <filename>devtool</filename> was used to build
8168 the kernel:
8169 <literallayout class='monospaced'>
8170 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 \
8171 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8172 </literallayout>
8173 Once the new kernel is added back into the image,
8174 you can use the <filename>dd</filename>
8175 command or
8176 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8177 to flash your wic image onto an SD card
8178 or USB stick and test your target.
8179 <note>
8180 Using <filename>bmaptool</filename> is
8181 generally 10 to 20 times faster than using
8182 <filename>dd</filename>.
8183 </note>
8184 </para></listitem>
8185 </orderedlist>
8186 </para>
8187 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008188 </section>
8189 </section>
8190
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008191 <section id='flashing-images-using-bmaptool'>
8192 <title>Flashing Images Using <filename>bmaptool</filename></title>
8193
8194 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008195 A fast and easy way to flash an image to a bootable device
8196 is to use Bmaptool, which is integrated into the OpenEmbedded
8197 build system.
8198 Bmaptool is a generic tool that creates a file's block map (bmap)
8199 and then uses that map to copy the file.
8200 As compared to traditional tools such as dd or cp, Bmaptool
8201 can copy (or flash) large files like raw system image files
8202 much faster.
8203 <note><title>Notes</title>
8204 <itemizedlist>
8205 <listitem><para>
8206 If you are using Ubuntu or Debian distributions, you
8207 can install the <filename>bmap-tools</filename> package
8208 using the following command and then use the tool
8209 without specifying <filename>PATH</filename> even from
8210 the root account:
8211 <literallayout class='monospaced'>
8212 $ sudo apt-get install bmap-tools
8213 </literallayout>
8214 </para></listitem>
8215 <listitem><para>
8216 If you are unable to install the
8217 <filename>bmap-tools</filename> package, you will
8218 need to build Bmaptool before using it.
8219 Use the following command:
8220 <literallayout class='monospaced'>
8221 $ bitbake bmap-tools-native
8222 </literallayout>
8223 </para></listitem>
8224 </itemizedlist>
8225 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008226 </para>
8227
8228 <para>
8229 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008230 Realize that while this example uses a Wic image, you can use
8231 Bmaptool to flash any type of image.
8232 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008233 <orderedlist>
8234 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008235 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8236 You need to have the following set in your
8237 <filename>local.conf</filename> file before building
8238 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008239 <literallayout class='monospaced'>
8240 IMAGE_FSTYPES += "wic wic.bmap"
8241 </literallayout>
8242 </para></listitem>
8243 <listitem><para>
8244 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008245 Either have your image ready (pre-built with the
8246 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8247 setting previously mentioned) or take the step to build
8248 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008249 <literallayout class='monospaced'>
8250 $ bitbake <replaceable>image</replaceable>
8251 </literallayout>
8252 </para></listitem>
8253 <listitem><para>
8254 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008255 Flash the device with the image by using Bmaptool
8256 depending on your particular setup.
8257 The following commands assume the image resides in the
8258 Build Directory's <filename>deploy/images/</filename>
8259 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008260 <itemizedlist>
8261 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008262 If you have write access to the media, use this
8263 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008264 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008265 $ 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 -05008266 </literallayout>
8267 </para></listitem>
8268 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008269 If you do not have write access to the media, set
8270 your permissions first and then use the same
8271 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008272 <literallayout class='monospaced'>
8273 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008274 $ 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 -05008275 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008276 </para></listitem>
8277 </itemizedlist>
8278 </para></listitem>
8279 </orderedlist>
8280 </para>
8281
8282 <para>
8283 For help on the <filename>bmaptool</filename> command, use the
8284 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008285 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008286 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008287 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008288 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008289 </section>
8290
8291 <section id='making-images-more-secure'>
8292 <title>Making Images More Secure</title>
8293
8294 <para>
8295 Security is of increasing concern for embedded devices.
8296 Consider the issues and problems discussed in just this
8297 sampling of work found across the Internet:
8298 <itemizedlist>
8299 <listitem><para><emphasis>
8300 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8301 by Bruce Schneier
8302 </para></listitem>
8303 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008304 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008305 by Carna Botnet</para></listitem>
8306 <listitem><para><emphasis>
8307 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8308 by Jake Edge
8309 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008310 </itemizedlist>
8311 </para>
8312
8313 <para>
8314 When securing your image is of concern, there are steps, tools,
8315 and variables that you can consider to help you reach the
8316 security goals you need for your particular device.
8317 Not all situations are identical when it comes to making an
8318 image secure.
8319 Consequently, this section provides some guidance and suggestions
8320 for consideration when you want to make your image more secure.
8321 <note>
8322 Because the security requirements and risks are
8323 different for every type of device, this section cannot
8324 provide a complete reference on securing your custom OS.
8325 It is strongly recommended that you also consult other sources
8326 of information on embedded Linux system hardening and on
8327 security.
8328 </note>
8329 </para>
8330
8331 <section id='general-considerations'>
8332 <title>General Considerations</title>
8333
8334 <para>
8335 General considerations exist that help you create more
8336 secure images.
8337 You should consider the following suggestions to help
8338 make your device more secure:
8339 <itemizedlist>
8340 <listitem><para>
8341 Scan additional code you are adding to the system
8342 (e.g. application code) by using static analysis
8343 tools.
8344 Look for buffer overflows and other potential
8345 security problems.
8346 </para></listitem>
8347 <listitem><para>
8348 Pay particular attention to the security for
8349 any web-based administration interface.
8350 </para>
8351 <para>Web interfaces typically need to perform
8352 administrative functions and tend to need to run with
8353 elevated privileges.
8354 Thus, the consequences resulting from the interface's
8355 security becoming compromised can be serious.
8356 Look for common web vulnerabilities such as
8357 cross-site-scripting (XSS), unvalidated inputs,
8358 and so forth.</para>
8359 <para>As with system passwords, the default credentials
8360 for accessing a web-based interface should not be the
8361 same across all devices.
8362 This is particularly true if the interface is enabled
8363 by default as it can be assumed that many end-users
8364 will not change the credentials.
8365 </para></listitem>
8366 <listitem><para>
8367 Ensure you can update the software on the device to
8368 mitigate vulnerabilities discovered in the future.
8369 This consideration especially applies when your
8370 device is network-enabled.
8371 </para></listitem>
8372 <listitem><para>
8373 Ensure you remove or disable debugging functionality
8374 before producing the final image.
8375 For information on how to do this, see the
8376 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8377 section.
8378 </para></listitem>
8379 <listitem><para>
8380 Ensure you have no network services listening that
8381 are not needed.
8382 </para></listitem>
8383 <listitem><para>
8384 Remove any software from the image that is not needed.
8385 </para></listitem>
8386 <listitem><para>
8387 Enable hardware support for secure boot functionality
8388 when your device supports this functionality.
8389 </para></listitem>
8390 </itemizedlist>
8391 </para>
8392 </section>
8393
8394 <section id='security-flags'>
8395 <title>Security Flags</title>
8396
8397 <para>
8398 The Yocto Project has security flags that you can enable that
8399 help make your build output more secure.
8400 The security flags are in the
8401 <filename>meta/conf/distro/include/security_flags.inc</filename>
8402 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008403 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008404 (e.g. <filename>poky</filename>).
8405 <note>
8406 Depending on the recipe, certain security flags are enabled
8407 and disabled by default.
8408 </note>
8409 </para>
8410
8411 <para>
8412<!--
8413 The GCC/LD flags in <filename>security_flags.inc</filename>
8414 enable more secure code generation.
8415 By including the <filename>security_flags.inc</filename>
8416 file, you enable flags to the compiler and linker that cause
8417 them to generate more secure code.
8418 <note>
8419 The GCC/LD flags are enabled by default in the
8420 <filename>poky-lsb</filename> distribution.
8421 </note>
8422-->
8423 Use the following line in your
8424 <filename>local.conf</filename> file or in your custom
8425 distribution configuration file to enable the security
8426 compiler and linker flags for your build:
8427 <literallayout class='monospaced'>
8428 require conf/distro/include/security_flags.inc
8429 </literallayout>
8430 </para>
8431 </section>
8432
8433 <section id='considerations-specific-to-the-openembedded-build-system'>
8434 <title>Considerations Specific to the OpenEmbedded Build System</title>
8435
8436 <para>
8437 You can take some steps that are specific to the
8438 OpenEmbedded build system to make your images more secure:
8439 <itemizedlist>
8440 <listitem><para>
8441 Ensure "debug-tweaks" is not one of your selected
8442 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8443 When creating a new project, the default is to provide you
8444 with an initial <filename>local.conf</filename> file that
8445 enables this feature using the
8446 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8447 <literallayout class='monospaced'>
8448 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8449 </literallayout>
8450 To disable that feature, simply comment out that line in your
8451 <filename>local.conf</filename> file, or
8452 make sure <filename>IMAGE_FEATURES</filename> does not contain
8453 "debug-tweaks" before producing your final image.
8454 Among other things, leaving this in place sets the
8455 root password as blank, which makes logging in for
8456 debugging or inspection easy during
8457 development but also means anyone can easily log in
8458 during production.
8459 </para></listitem>
8460 <listitem><para>
8461 It is possible to set a root password for the image
8462 and also to set passwords for any extra users you might
8463 add (e.g. administrative or service type users).
8464 When you set up passwords for multiple images or
8465 users, you should not duplicate passwords.
8466 </para>
8467 <para>
8468 To set up passwords, use the
8469 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8470 class, which is the preferred method.
8471 For an example on how to set up both root and user
8472 passwords, see the
8473 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8474 section.
8475 <note>
8476 When adding extra user accounts or setting a
8477 root password, be cautious about setting the
8478 same password on every device.
8479 If you do this, and the password you have set
8480 is exposed, then every device is now potentially
8481 compromised.
8482 If you need this access but want to ensure
8483 security, consider setting a different,
8484 random password for each device.
8485 Typically, you do this as a separate step after
8486 you deploy the image onto the device.
8487 </note>
8488 </para></listitem>
8489 <listitem><para>
8490 Consider enabling a Mandatory Access Control (MAC)
8491 framework such as SMACK or SELinux and tuning it
8492 appropriately for your device's usage.
8493 You can find more information in the
8494 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8495 layer.
8496 </para></listitem>
8497 </itemizedlist>
8498 </para>
8499
8500 <para>
8501 </para>
8502 </section>
8503
8504 <section id='tools-for-hardening-your-image'>
8505 <title>Tools for Hardening Your Image</title>
8506
8507 <para>
8508 The Yocto Project provides tools for making your image
8509 more secure.
8510 You can find these tools in the
8511 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008512 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008513 </para>
8514 </section>
8515 </section>
8516
8517 <section id='creating-your-own-distribution'>
8518 <title>Creating Your Own Distribution</title>
8519
8520 <para>
8521 When you build an image using the Yocto Project and
8522 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008523 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8524 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008525 If you wish to gain more control over package alternative
8526 selections, compile-time options, and other low-level
8527 configurations, you can create your own distribution.
8528 </para>
8529
8530 <para>
8531 To create your own distribution, the basic steps consist of
8532 creating your own distribution layer, creating your own
8533 distribution configuration file, and then adding any needed
8534 code and Metadata to the layer.
8535 The following steps provide some more detail:
8536 <itemizedlist>
8537 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8538 Create your distribution layer so that you can keep your
8539 Metadata and code for the distribution separate.
8540 It is strongly recommended that you create and use your own
8541 layer for configuration and code.
8542 Using your own layer as compared to just placing
8543 configurations in a <filename>local.conf</filename>
8544 configuration file makes it easier to reproduce the same
8545 build configuration when using multiple build machines.
8546 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008547 "<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 -05008548 section for information on how to quickly set up a layer.
8549 </para></listitem>
8550 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8551 The distribution configuration file needs to be created in
8552 the <filename>conf/distro</filename> directory of your
8553 layer.
8554 You need to name it using your distribution name
8555 (e.g. <filename>mydistro.conf</filename>).
8556 <note>
8557 The
8558 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8559 variable in your
8560 <filename>local.conf</filename> file determines the
8561 name of your distribution.
8562 </note></para>
8563 <para>You can split out parts of your configuration file
8564 into include files and then "require" them from within
8565 your distribution configuration file.
8566 Be sure to place the include files in the
8567 <filename>conf/distro/include</filename> directory of
8568 your layer.
8569 A common example usage of include files would be to
8570 separate out the selection of desired version and revisions
8571 for individual recipes.
8572</para>
8573 <para>Your configuration file needs to set the following
8574 required variables:
8575 <literallayout class='monospaced'>
8576 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8577 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8578 </literallayout>
8579 These following variables are optional and you typically
8580 set them from the distribution configuration file:
8581 <literallayout class='monospaced'>
8582 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8583 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8584 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8585 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8586 </literallayout>
8587 <tip>
8588 If you want to base your distribution configuration file
8589 on the very basic configuration from OE-Core, you
8590 can use
8591 <filename>conf/distro/defaultsetup.conf</filename> as
8592 a reference and just include variables that differ
8593 as compared to <filename>defaultsetup.conf</filename>.
8594 Alternatively, you can create a distribution
8595 configuration file from scratch using the
8596 <filename>defaultsetup.conf</filename> file
8597 or configuration files from other distributions
8598 such as Poky or Angstrom as references.
8599 </tip></para></listitem>
8600 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8601 Be sure to define any other variables for which you want to
8602 create a default or enforce as part of the distribution
8603 configuration.
8604 You can include nearly any variable from the
8605 <filename>local.conf</filename> file.
8606 The variables you use are not limited to the list in the
8607 previous bulleted item.</para></listitem>
8608 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8609 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008610 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008611 set your
8612 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8613 variable to point to your distribution's configuration file.
8614 For example, if your distribution's configuration file is
8615 named <filename>mydistro.conf</filename>, then you point
8616 to it as follows:
8617 <literallayout class='monospaced'>
8618 DISTRO = "mydistro"
8619 </literallayout></para></listitem>
8620 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8621 Use your layer to hold other information needed for the
8622 distribution:
8623 <itemizedlist>
8624 <listitem><para>Add recipes for installing
8625 distro-specific configuration files that are not
8626 already installed by another recipe.
8627 If you have distro-specific configuration files
8628 that are included by an existing recipe, you should
8629 add an append file (<filename>.bbappend</filename>)
8630 for those.
8631 For general information and recommendations
8632 on how to add recipes to your layer, see the
8633 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8634 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008635 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008636 sections.</para></listitem>
8637 <listitem><para>Add any image recipes that are specific
8638 to your distribution.</para></listitem>
8639 <listitem><para>Add a <filename>psplash</filename>
8640 append file for a branded splash screen.
8641 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008642 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008643 section.</para></listitem>
8644 <listitem><para>Add any other append files to make
8645 custom changes that are specific to individual
8646 recipes.</para></listitem>
8647 </itemizedlist></para></listitem>
8648 </itemizedlist>
8649 </para>
8650 </section>
8651
8652 <section id='creating-a-custom-template-configuration-directory'>
8653 <title>Creating a Custom Template Configuration Directory</title>
8654
8655 <para>
8656 If you are producing your own customized version
8657 of the build system for use by other users, you might
8658 want to customize the message shown by the setup script or
8659 you might want to change the template configuration files (i.e.
8660 <filename>local.conf</filename> and
8661 <filename>bblayers.conf</filename>) that are created in
8662 a new build directory.
8663 </para>
8664
8665 <para>
8666 The OpenEmbedded build system uses the environment variable
8667 <filename>TEMPLATECONF</filename> to locate the directory
8668 from which it gathers configuration information that ultimately
8669 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008670 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008671 <filename>conf</filename> directory.
8672 By default, <filename>TEMPLATECONF</filename> is set as
8673 follows in the <filename>poky</filename> repository:
8674 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008675 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008676 </literallayout>
8677 This is the directory used by the build system to find templates
8678 from which to build some key configuration files.
8679 If you look at this directory, you will see the
8680 <filename>bblayers.conf.sample</filename>,
8681 <filename>local.conf.sample</filename>, and
8682 <filename>conf-notes.txt</filename> files.
8683 The build system uses these files to form the respective
8684 <filename>bblayers.conf</filename> file,
8685 <filename>local.conf</filename> file, and display the list of
8686 BitBake targets when running the setup script.
8687 </para>
8688
8689 <para>
8690 To override these default configuration files with
8691 configurations you want used within every new
8692 Build Directory, simply set the
8693 <filename>TEMPLATECONF</filename> variable to your directory.
8694 The <filename>TEMPLATECONF</filename> variable is set in the
8695 <filename>.templateconf</filename> file, which is in the
8696 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008697 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008698 folder (e.g. <filename>poky</filename>).
8699 Edit the <filename>.templateconf</filename> so that it can locate
8700 your directory.
8701 </para>
8702
8703 <para>
8704 Best practices dictate that you should keep your
8705 template configuration directory in your custom distribution layer.
8706 For example, suppose you have a layer named
8707 <filename>meta-mylayer</filename> located in your home directory
8708 and you want your template configuration directory named
8709 <filename>myconf</filename>.
8710 Changing the <filename>.templateconf</filename> as follows
8711 causes the OpenEmbedded build system to look in your directory
8712 and base its configuration files on the
8713 <filename>*.sample</filename> configuration files it finds.
8714 The final configuration files (i.e.
8715 <filename>local.conf</filename> and
8716 <filename>bblayers.conf</filename> ultimately still end up in
8717 your Build Directory, but they are based on your
8718 <filename>*.sample</filename> files.
8719 <literallayout class='monospaced'>
8720 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8721 </literallayout>
8722 </para>
8723
8724 <para>
8725 Aside from the <filename>*.sample</filename> configuration files,
8726 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008727 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008728 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008729 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008730 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8731 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008732 output.
8733 Customizing this <filename>conf-notes.txt</filename> file is a
8734 good way to make sure your list of custom targets appears
8735 as part of the script's output.
8736 </para>
8737
8738 <para>
8739 Here is the default list of targets displayed as a result of
8740 running either of the setup scripts:
8741 <literallayout class='monospaced'>
8742 You can now run 'bitbake &lt;target&gt;'
8743
8744 Common targets are:
8745 core-image-minimal
8746 core-image-sato
8747 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008748 meta-ide-support
8749 </literallayout>
8750 </para>
8751
8752 <para>
8753 Changing the listed common targets is as easy as editing your
8754 version of <filename>conf-notes.txt</filename> in your
8755 custom template configuration directory and making sure you
8756 have <filename>TEMPLATECONF</filename> set to your directory.
8757 </para>
8758 </section>
8759
Brad Bishop316dfdd2018-06-25 12:45:53 -04008760 <section id='dev-saving-memory-during-a-build'>
8761 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008762
8763 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008764 To help conserve disk space during builds, you can add the
8765 following statement to your project's
8766 <filename>local.conf</filename> configuration file found in the
8767 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8768 <literallayout class='monospaced'>
8769 INHERIT += "rm_work"
8770 </literallayout>
8771 Adding this statement deletes the work directory used for building
8772 a recipe once the recipe is built.
8773 For more information on "rm_work", see the
8774 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8775 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008776 </para>
8777 </section>
8778
8779 <section id='working-with-packages'>
8780 <title>Working with Packages</title>
8781
8782 <para>
8783 This section describes a few tasks that involve packages:
8784 <itemizedlist>
8785 <listitem><para>
8786 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8787 </para></listitem>
8788 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008789 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008790 </para></listitem>
8791 <listitem><para>
8792 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8793 </para></listitem>
8794 <listitem><para>
8795 <link linkend='using-runtime-package-management'>Using Runtime Package Management</link>
8796 </para></listitem>
8797 <listitem><para>
8798 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8799 </para></listitem>
8800 </itemizedlist>
8801 </para>
8802
8803 <section id='excluding-packages-from-an-image'>
8804 <title>Excluding Packages from an Image</title>
8805
8806 <para>
8807 You might find it necessary to prevent specific packages
8808 from being installed into an image.
8809 If so, you can use several variables to direct the build
8810 system to essentially ignore installing recommended packages
8811 or to not install a package at all.
8812 </para>
8813
8814 <para>
8815 The following list introduces variables you can use to
8816 prevent packages from being installed into your image.
8817 Each of these variables only works with IPK and RPM
8818 package types.
8819 Support for Debian packages does not exist.
8820 Also, you can use these variables from your
8821 <filename>local.conf</filename> file or attach them to a
8822 specific image recipe by using a recipe name override.
8823 For more detail on the variables, see the descriptions in the
8824 Yocto Project Reference Manual's glossary chapter.
8825 <itemizedlist>
8826 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
8827 Use this variable to specify "recommended-only"
8828 packages that you do not want installed.
8829 </para></listitem>
8830 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
8831 Use this variable to prevent all "recommended-only"
8832 packages from being installed.
8833 </para></listitem>
8834 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
8835 Use this variable to prevent specific packages from
8836 being installed regardless of whether they are
8837 "recommended-only" or not.
8838 You need to realize that the build process could
8839 fail with an error when you
8840 prevent the installation of a package whose presence
8841 is required by an installed package.
8842 </para></listitem>
8843 </itemizedlist>
8844 </para>
8845 </section>
8846
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008847 <section id='incrementing-a-binary-package-version'>
8848 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008849
8850 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008851 This section provides some background on how binary package
8852 versioning is accomplished and presents some of the services,
8853 variables, and terminology involved.
8854 </para>
8855
8856 <para>
8857 In order to understand binary package versioning, you need
8858 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008859 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008860 <listitem><para>
8861 Binary Package: The binary package that is eventually
8862 built and installed into an image.
8863 </para></listitem>
8864 <listitem><para>
8865 Binary Package Version: The binary package version
8866 is composed of two components - a version and a
8867 revision.
8868 <note>
8869 Technically, a third component, the "epoch" (i.e.
8870 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
8871 is involved but this discussion for the most part
8872 ignores <filename>PE</filename>.
8873 </note>
8874 The version and revision are taken from the
8875 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
8876 and
8877 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
8878 variables, respectively.
8879 </para></listitem>
8880 <listitem><para>
8881 <filename>PV</filename>: The recipe version.
8882 <filename>PV</filename> represents the version of the
8883 software being packaged.
8884 Do not confuse <filename>PV</filename> with the
8885 binary package version.
8886 </para></listitem>
8887 <listitem><para>
8888 <filename>PR</filename>: The recipe revision.
8889 </para></listitem>
8890 <listitem><para>
8891 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
8892 The OpenEmbedded build system uses this string
8893 to help define the value of <filename>PV</filename>
8894 when the source code revision needs to be included
8895 in it.
8896 </para></listitem>
8897 <listitem><para>
8898 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
8899 A network-based service that helps automate keeping
8900 package feeds compatible with existing package
8901 manager applications such as RPM, APT, and OPKG.
8902 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008903 </itemizedlist>
8904 </para>
8905
8906 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008907 Whenever the binary package content changes, the binary package
8908 version must change.
8909 Changing the binary package version is accomplished by changing
8910 or "bumping" the <filename>PR</filename> and/or
8911 <filename>PV</filename> values.
8912 Increasing these values occurs one of two ways:
8913 <itemizedlist>
8914 <listitem><para>Automatically using a Package Revision
8915 Service (PR Service).
8916 </para></listitem>
8917 <listitem><para>Manually incrementing the
8918 <filename>PR</filename> and/or
8919 <filename>PV</filename> variables.
8920 </para></listitem>
8921 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008922 </para>
8923
8924 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008925 Given a primary challenge of any build system and its users
8926 is how to maintain a package feed that is compatible with
8927 existing package manager applications such as RPM, APT, and
8928 OPKG, using an automated system is much preferred over a
8929 manual system.
8930 In either system, the main requirement is that binary package
8931 version numbering increases in a linear fashion and that a
8932 number of version components exist that support that linear
8933 progression.
8934 For information on how to ensure package revisioning remains
8935 linear, see the
8936 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
8937 section.
8938 </para>
8939
8940 <para>
8941 The following three sections provide related information on the
8942 PR Service, the manual method for "bumping"
8943 <filename>PR</filename> and/or <filename>PV</filename>, and
8944 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008945 </para>
8946
8947 <section id='working-with-a-pr-service'>
8948 <title>Working With a PR Service</title>
8949
8950 <para>
8951 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008952 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008953 is error prone, inaccurate, and causes problems for people
8954 submitting recipes.
8955 Conversely, the PR Service automatically generates
8956 increasing numbers, particularly the revision field,
8957 which removes the human element.
8958 <note>
8959 For additional information on using a PR Service, you
8960 can see the
8961 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
8962 wiki page.
8963 </note>
8964 </para>
8965
8966 <para>
8967 The Yocto Project uses variables in order of
8968 decreasing priority to facilitate revision numbering (i.e.
8969 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
8970 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
8971 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
8972 for epoch, version, and revision, respectively).
8973 The values are highly dependent on the policies and
8974 procedures of a given distribution and package feed.
8975 </para>
8976
8977 <para>
8978 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04008979 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008980 which are unique to a given build, the build system
8981 knows when to rebuild packages.
8982 All the inputs into a given task are represented by a
8983 signature, which can trigger a rebuild when different.
8984 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008985 <filename>PR</filename>, <filename>PV</filename>, and
8986 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008987 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008988 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008989 </para>
8990
8991 <para>
8992 The PR Service works with both
8993 <filename>OEBasic</filename> and
8994 <filename>OEBasicHash</filename> generators.
8995 The value of <filename>PR</filename> bumps when the
8996 checksum changes and the different generator mechanisms
8997 change signatures under different circumstances.
8998 </para>
8999
9000 <para>
9001 As implemented, the build system includes values from
9002 the PR Service into the <filename>PR</filename> field as
9003 an addition using the form "<filename>.x</filename>" so
9004 <filename>r0</filename> becomes <filename>r0.1</filename>,
9005 <filename>r0.2</filename> and so forth.
9006 This scheme allows existing <filename>PR</filename> values
9007 to be used for whatever reasons, which include manual
9008 <filename>PR</filename> bumps, should it be necessary.
9009 </para>
9010
9011 <para>
9012 By default, the PR Service is not enabled or running.
9013 Thus, the packages generated are just "self consistent".
9014 The build system adds and removes packages and
9015 there are no guarantees about upgrade paths but images
9016 will be consistent and correct with the latest changes.
9017 </para>
9018
9019 <para>
9020 The simplest form for a PR Service is for it to exist
9021 for a single host development system that builds the
9022 package feed (building system).
9023 For this scenario, you can enable a local PR Service by
9024 setting
9025 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9026 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009027 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009028 <literallayout class='monospaced'>
9029 PRSERV_HOST = "localhost:0"
9030 </literallayout>
9031 Once the service is started, packages will automatically
9032 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009033 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009034 </para>
9035
9036 <para>
9037 If you have a more complex setup where multiple host
9038 development systems work against a common, shared package
9039 feed, you have a single PR Service running and it is
9040 connected to each building system.
9041 For this scenario, you need to start the PR Service using
9042 the <filename>bitbake-prserv</filename> command:
9043 <literallayout class='monospaced'>
9044 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9045 </literallayout>
9046 In addition to hand-starting the service, you need to
9047 update the <filename>local.conf</filename> file of each
9048 building system as described earlier so each system
9049 points to the server and port.
9050 </para>
9051
9052 <para>
9053 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009054 some sanity checks to binary package versions, in
9055 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009056 To enable build history, add the following to each building
9057 system's <filename>local.conf</filename> file:
9058 <literallayout class='monospaced'>
9059 # It is recommended to activate "buildhistory" for testing the PR service
9060 INHERIT += "buildhistory"
9061 BUILDHISTORY_COMMIT = "1"
9062 </literallayout>
9063 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009064 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9065 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009066 </para>
9067
9068 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009069 <para>
9070 The OpenEmbedded build system does not maintain
9071 <filename>PR</filename> information as part of the
9072 shared state (sstate) packages.
9073 If you maintain an sstate feed, its expected that either
9074 all your building systems that contribute to the sstate
9075 feed use a shared PR Service, or you do not run a PR
9076 Service on any of your building systems.
9077 Having some systems use a PR Service while others do
9078 not leads to obvious problems.
9079 </para>
9080
9081 <para>
9082 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009083 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9084 section in the Yocto Project Overview and Concepts
9085 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009086 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009087 </note>
9088 </section>
9089
9090 <section id='manually-bumping-pr'>
9091 <title>Manually Bumping PR</title>
9092
9093 <para>
9094 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009095 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009096 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9097 variable.
9098 </para>
9099
9100 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009101 If a committed change results in changing the package
9102 output, then the value of the PR variable needs to be
9103 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009104 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009105 variable and set its initial value equal to "r0", which is
9106 the default.
9107 Even though the default value is "r0", the practice of
9108 adding it to a new recipe makes it harder to forget to bump
9109 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009110 </para>
9111
9112 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009113 If you are sharing a common <filename>.inc</filename> file
9114 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009115 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009116 variable to ensure that the recipes sharing the
9117 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009118 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009119 The <filename>.inc</filename> file must set
9120 <filename>INC_PR</filename> (initially to "r0"), and all
9121 recipes referring to it should set <filename>PR</filename>
9122 to "${INC_PR}.0" initially, incrementing the last number
9123 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009124 If the <filename>.inc</filename> file is changed then its
9125 <filename>INC_PR</filename> should be incremented.
9126 </para>
9127
9128 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009129 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009130 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9131 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009132 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009133 <filename>INC_PR</filename>).
9134 </para>
9135
9136 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009137 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009138 However, if for some reason <filename>PV</filename> changes
9139 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009140 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9141 variable (Package Epoch).
9142 The <filename>PE</filename> variable defaults to "0".
9143 </para>
9144
9145 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009146 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009147 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9148 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009149 These guidelines define how versions are compared and what
9150 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009151 </para>
9152 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009153
9154 <section id='automatically-incrementing-a-binary-package-revision-number'>
9155 <title>Automatically Incrementing a Package Version Number</title>
9156
9157 <para>
9158 When fetching a repository, BitBake uses the
9159 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9160 variable to determine the specific source code revision
9161 from which to build.
9162 You set the <filename>SRCREV</filename> variable to
9163 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9164 to cause the OpenEmbedded build system to automatically use the
9165 latest revision of the software:
9166 <literallayout class='monospaced'>
9167 SRCREV = "${AUTOREV}"
9168 </literallayout>
9169 </para>
9170
9171 <para>
9172 Furthermore, you need to reference <filename>SRCPV</filename>
9173 in <filename>PV</filename> in order to automatically update
9174 the version whenever the revision of the source code
9175 changes.
9176 Here is an example:
9177 <literallayout class='monospaced'>
9178 PV = "1.0+git${SRCPV}"
9179 </literallayout>
9180 The OpenEmbedded build system substitutes
9181 <filename>SRCPV</filename> with the following:
9182 <literallayout class='monospaced'>
9183 AUTOINC+<replaceable>source_code_revision</replaceable>
9184 </literallayout>
9185 The build system replaces the <filename>AUTOINC</filename> with
9186 a number.
9187 The number used depends on the state of the PR Service:
9188 <itemizedlist>
9189 <listitem><para>
9190 If PR Service is enabled, the build system increments
9191 the number, which is similar to the behavior of
9192 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9193 This behavior results in linearly increasing package
9194 versions, which is desirable.
9195 Here is an example:
9196 <literallayout class='monospaced'>
9197 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9198 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9199 </literallayout>
9200 </para></listitem>
9201 <listitem><para>
9202 If PR Service is not enabled, the build system
9203 replaces the <filename>AUTOINC</filename>
9204 placeholder with zero (i.e. "0").
9205 This results in changing the package version since
9206 the source revision is included.
9207 However, package versions are not increased linearly.
9208 Here is an example:
9209 <literallayout class='monospaced'>
9210 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9211 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9212 </literallayout>
9213 </para></listitem>
9214 </itemizedlist>
9215 </para>
9216
9217 <para>
9218 In summary, the OpenEmbedded build system does not track the
9219 history of binary package versions for this purpose.
9220 <filename>AUTOINC</filename>, in this case, is comparable to
9221 <filename>PR</filename>.
9222 If PR server is not enabled, <filename>AUTOINC</filename>
9223 in the package version is simply replaced by "0".
9224 If PR server is enabled, the build system keeps track of the
9225 package versions and bumps the number when the package
9226 revision changes.
9227 </para>
9228 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009229 </section>
9230
9231 <section id='handling-optional-module-packaging'>
9232 <title>Handling Optional Module Packaging</title>
9233
9234 <para>
9235 Many pieces of software split functionality into optional
9236 modules (or plug-ins) and the plug-ins that are built
9237 might depend on configuration options.
9238 To avoid having to duplicate the logic that determines what
9239 modules are available in your recipe or to avoid having
9240 to package each module by hand, the OpenEmbedded build system
9241 provides functionality to handle module packaging dynamically.
9242 </para>
9243
9244 <para>
9245 To handle optional module packaging, you need to do two things:
9246 <itemizedlist>
9247 <listitem><para>Ensure the module packaging is actually
9248 done.</para></listitem>
9249 <listitem><para>Ensure that any dependencies on optional
9250 modules from other recipes are satisfied by your recipe.
9251 </para></listitem>
9252 </itemizedlist>
9253 </para>
9254
9255 <section id='making-sure-the-packaging-is-done'>
9256 <title>Making Sure the Packaging is Done</title>
9257
9258 <para>
9259 To ensure the module packaging actually gets done, you use
9260 the <filename>do_split_packages</filename> function within
9261 the <filename>populate_packages</filename> Python function
9262 in your recipe.
9263 The <filename>do_split_packages</filename> function
9264 searches for a pattern of files or directories under a
9265 specified path and creates a package for each one it finds
9266 by appending to the
9267 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9268 variable and setting the appropriate values for
9269 <filename>FILES_packagename</filename>,
9270 <filename>RDEPENDS_packagename</filename>,
9271 <filename>DESCRIPTION_packagename</filename>, and so forth.
9272 Here is an example from the <filename>lighttpd</filename>
9273 recipe:
9274 <literallayout class='monospaced'>
9275 python populate_packages_prepend () {
9276 lighttpd_libdir = d.expand('${libdir}')
9277 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9278 'lighttpd-module-%s', 'Lighttpd module for %s',
9279 extra_depends='')
9280 }
9281 </literallayout>
9282 The previous example specifies a number of things in the
9283 call to <filename>do_split_packages</filename>.
9284 <itemizedlist>
9285 <listitem><para>A directory within the files installed
9286 by your recipe through <filename>do_install</filename>
9287 in which to search.</para></listitem>
9288 <listitem><para>A regular expression used to match module
9289 files in that directory.
9290 In the example, note the parentheses () that mark
9291 the part of the expression from which the module
9292 name should be derived.</para></listitem>
9293 <listitem><para>A pattern to use for the package names.
9294 </para></listitem>
9295 <listitem><para>A description for each package.
9296 </para></listitem>
9297 <listitem><para>An empty string for
9298 <filename>extra_depends</filename>, which disables
9299 the default dependency on the main
9300 <filename>lighttpd</filename> package.
9301 Thus, if a file in <filename>${libdir}</filename>
9302 called <filename>mod_alias.so</filename> is found,
9303 a package called <filename>lighttpd-module-alias</filename>
9304 is created for it and the
9305 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9306 is set to "Lighttpd module for alias".</para></listitem>
9307 </itemizedlist>
9308 </para>
9309
9310 <para>
9311 Often, packaging modules is as simple as the previous
9312 example.
9313 However, more advanced options exist that you can use
9314 within <filename>do_split_packages</filename> to modify its
9315 behavior.
9316 And, if you need to, you can add more logic by specifying
9317 a hook function that is called for each package.
9318 It is also perfectly acceptable to call
9319 <filename>do_split_packages</filename> multiple times if
9320 you have more than one set of modules to package.
9321 </para>
9322
9323 <para>
9324 For more examples that show how to use
9325 <filename>do_split_packages</filename>, see the
9326 <filename>connman.inc</filename> file in the
9327 <filename>meta/recipes-connectivity/connman/</filename>
9328 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009329 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009330 You can also find examples in
9331 <filename>meta/classes/kernel.bbclass</filename>.
9332 </para>
9333
9334 <para>
9335 Following is a reference that shows
9336 <filename>do_split_packages</filename> mandatory and
9337 optional arguments:
9338 <literallayout class='monospaced'>
9339 Mandatory arguments
9340
9341 root
9342 The path in which to search
9343 file_regex
9344 Regular expression to match searched files.
9345 Use parentheses () to mark the part of this
9346 expression that should be used to derive the
9347 module name (to be substituted where %s is
9348 used in other function arguments as noted below)
9349 output_pattern
9350 Pattern to use for the package names. Must
9351 include %s.
9352 description
9353 Description to set for each package. Must
9354 include %s.
9355
9356 Optional arguments
9357
9358 postinst
9359 Postinstall script to use for all packages
9360 (as a string)
9361 recursive
9362 True to perform a recursive search - default
9363 False
9364 hook
9365 A hook function to be called for every match.
9366 The function will be called with the following
9367 arguments (in the order listed):
9368
9369 f
9370 Full path to the file/directory match
9371 pkg
9372 The package name
9373 file_regex
9374 As above
9375 output_pattern
9376 As above
9377 modulename
9378 The module name derived using file_regex
9379
9380 extra_depends
9381 Extra runtime dependencies (RDEPENDS) to be
9382 set for all packages. The default value of None
9383 causes a dependency on the main package
9384 (${PN}) - if you do not want this, pass empty
9385 string '' for this parameter.
9386 aux_files_pattern
9387 Extra item(s) to be added to FILES for each
9388 package. Can be a single string item or a list
9389 of strings for multiple items. Must include %s.
9390 postrm
9391 postrm script to use for all packages (as a
9392 string)
9393 allow_dirs
9394 True to allow directories to be matched -
9395 default False
9396 prepend
9397 If True, prepend created packages to PACKAGES
9398 instead of the default False which appends them
9399 match_path
9400 match file_regex on the whole relative path to
9401 the root rather than just the file name
9402 aux_files_pattern_verbatim
9403 Extra item(s) to be added to FILES for each
9404 package, using the actual derived module name
9405 rather than converting it to something legal
9406 for a package name. Can be a single string item
9407 or a list of strings for multiple items. Must
9408 include %s.
9409 allow_links
9410 True to allow symlinks to be matched - default
9411 False
9412 summary
9413 Summary to set for each package. Must include %s;
9414 defaults to description if not set.
9415 </literallayout>
9416 </para>
9417 </section>
9418
9419 <section id='satisfying-dependencies'>
9420 <title>Satisfying Dependencies</title>
9421
9422 <para>
9423 The second part for handling optional module packaging
9424 is to ensure that any dependencies on optional modules
9425 from other recipes are satisfied by your recipe.
9426 You can be sure these dependencies are satisfied by
9427 using the
9428 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9429 Here is an example that continues with the
9430 <filename>lighttpd</filename> recipe shown earlier:
9431 <literallayout class='monospaced'>
9432 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9433 </literallayout>
9434 The name specified in the regular expression can of
9435 course be anything.
9436 In this example, it is <filename>lighttpd-module-</filename>
9437 and is specified as the prefix to ensure that any
9438 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9439 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9440 on a package name starting with the prefix are satisfied
9441 during build time.
9442 If you are using <filename>do_split_packages</filename>
9443 as described in the previous section, the value you put in
9444 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9445 the name pattern specified in the call to
9446 <filename>do_split_packages</filename>.
9447 </para>
9448 </section>
9449 </section>
9450
9451 <section id='using-runtime-package-management'>
9452 <title>Using Runtime Package Management</title>
9453
9454 <para>
9455 During a build, BitBake always transforms a recipe into one or
9456 more packages.
9457 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009458 and produces a number of packages (e.g.
9459 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9460 <filename>bash-completion</filename>,
9461 <filename>bash-completion-dbg</filename>,
9462 <filename>bash-completion-dev</filename>,
9463 <filename>bash-completion-extra</filename>,
9464 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009465 Not all generated packages are included in an image.
9466 </para>
9467
9468 <para>
9469 In several situations, you might need to update, add, remove,
9470 or query the packages on a target device at runtime
9471 (i.e. without having to generate a new image).
9472 Examples of such situations include:
9473 <itemizedlist>
9474 <listitem><para>
9475 You want to provide in-the-field updates to deployed
9476 devices (e.g. security updates).
9477 </para></listitem>
9478 <listitem><para>
9479 You want to have a fast turn-around development cycle
9480 for one or more applications that run on your device.
9481 </para></listitem>
9482 <listitem><para>
9483 You want to temporarily install the "debug" packages
9484 of various applications on your device so that
9485 debugging can be greatly improved by allowing
9486 access to symbols and source debugging.
9487 </para></listitem>
9488 <listitem><para>
9489 You want to deploy a more minimal package selection of
9490 your device but allow in-the-field updates to add a
9491 larger selection for customization.
9492 </para></listitem>
9493 </itemizedlist>
9494 </para>
9495
9496 <para>
9497 In all these situations, you have something similar to a more
9498 traditional Linux distribution in that in-field devices
9499 are able to receive pre-compiled packages from a server for
9500 installation or update.
9501 Being able to install these packages on a running,
9502 in-field device is what is termed "runtime package
9503 management".
9504 </para>
9505
9506 <para>
9507 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009508 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009509 packages plus the required metadata.
9510 You also need package manipulation tools on the target.
9511 The build machine is a likely candidate to act as the server.
9512 However, that machine does not necessarily have to be the
9513 package server.
9514 The build machine could push its artifacts to another machine
9515 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009516 In fact, doing so is advantageous for a production
9517 environment as getting the packages away from the
9518 development system's build directory prevents accidental
9519 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009520 </para>
9521
9522 <para>
9523 A simple build that targets just one device produces
9524 more than one package database.
9525 In other words, the packages produced by a build are separated
9526 out into a couple of different package groupings based on
9527 criteria such as the target's CPU architecture, the target
9528 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009529 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009530 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009531 <filename>noarch</filename>, <filename>i586</filename>, and
9532 <filename>qemux86</filename>.
9533 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009534 aware of all the packages that were available to it,
9535 you would need to point it to each of these databases
9536 individually.
9537 In a similar way, a traditional Linux distribution usually is
9538 configured to be aware of a number of software repositories
9539 from which it retrieves packages.
9540 </para>
9541
9542 <para>
9543 Using runtime package management is completely optional and
9544 not required for a successful build or deployment in any
9545 way.
9546 But if you want to make use of runtime package management,
9547 you need to do a couple things above and beyond the basics.
9548 The remainder of this section describes what you need to do.
9549 </para>
9550
9551 <section id='runtime-package-management-build'>
9552 <title>Build Considerations</title>
9553
9554 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009555 This section describes build considerations of which you
9556 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009557 package management.
9558 </para>
9559
9560 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009561 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009562 what format or formats to use.
9563 In your configuration, you use the
9564 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009565 variable to specify the format:
9566 <orderedlist>
9567 <listitem><para>
9568 Open the <filename>local.conf</filename> file
9569 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009570 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009571 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9572 </para></listitem>
9573 <listitem><para>
9574 Select the desired package format as follows:
9575 <literallayout class='monospaced'>
9576 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9577 </literallayout>
9578 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009579 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009580 supported package formats.
9581 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009582 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009583 different package formats, you can set the
9584 variable with more than one argument.
9585 However, the OpenEmbedded build system only
9586 uses the first argument when creating an image
9587 or Software Development Kit (SDK).
9588 </note>
9589 </para></listitem>
9590 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009591 </para>
9592
9593 <para>
9594 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009595 package database containing the packages in your current
9596 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009597 target for runtime package management, you can include
9598 "package-management" in the
9599 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9600 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009601 Including "package-management" in this configuration
9602 variable ensures that when the image is assembled for your
9603 target, the image includes the currently-known package
9604 databases as well as the target-specific tools required
9605 for runtime package management to be performed on the
9606 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009607 However, this is not strictly necessary.
9608 You could start your image off without any databases
9609 but only include the required on-target package
9610 tool(s).
9611 As an example, you could include "opkg" in your
9612 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9613 variable if you are using the IPK package format.
9614 You can then initialize your target's package database(s)
9615 later once your image is up and running.
9616 </para>
9617
9618 <para>
9619 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009620 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009621 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009622 package index after the build by using the following
9623 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009624 <literallayout class='monospaced'>
9625 $ bitbake package-index
9626 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009627 It might be tempting to build the package and the
9628 package index at the same time with a command such as
9629 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009630 <literallayout class='monospaced'>
9631 $ bitbake <replaceable>some-package</replaceable> package-index
9632 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009633 Do not do this as BitBake does not schedule the package
9634 index for after the completion of the package you are
9635 building.
9636 Consequently, you cannot be sure of the package index
9637 including information for the package you just built.
9638 Thus, be sure to run the package update step separately
9639 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009640 </para>
9641
9642 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009643 You can use the
9644 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9645 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9646 and
9647 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9648 variables to pre-configure target images to use a package
9649 feed.
9650 If you do not define these variables, then manual steps
9651 as described in the subsequent sections are necessary to
9652 configure the target.
9653 You should set these variables before building the image
9654 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009655 </para>
9656
9657 <para>
9658 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009659 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009660 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009661 For example, if
9662 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009663 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009664 is RPM, then your RPM packages are available in
9665 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009666 </para>
9667 </section>
9668
9669 <section id='runtime-package-management-server'>
9670 <title>Host or Server Machine Setup</title>
9671
9672 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009673 Although other protocols are possible, a server using HTTP
9674 typically serves packages.
9675 If you want to use HTTP, then set up and configure a
9676 web server such as Apache 2, lighttpd, or
9677 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009678 </para>
9679
9680 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009681 To keep things simple, this section describes how to set
9682 up a SimpleHTTPServer web server to share package feeds
9683 from the developer's machine.
9684 Although this server might not be the best for a production
9685 environment, the setup is simple and straight forward.
9686 Should you want to use a different server more suited for
9687 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9688 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009689 </para>
9690
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009691 <para>
9692 From within the build directory where you have built an
9693 image based on your packaging choice (i.e. the
9694 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9695 setting), simply start the server.
9696 The following example assumes a build directory of
9697 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9698 <filename>PACKAGE_CLASSES</filename> setting of
9699 "package_rpm":
9700 <literallayout class='monospaced'>
9701 $ cd ~/poky/build/tmp/deploy/rpm
9702 $ python -m SimpleHTTPServer
9703 </literallayout>
9704 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009705 </section>
9706
9707 <section id='runtime-package-management-target'>
9708 <title>Target Setup</title>
9709
9710 <para>
9711 Setting up the target differs depending on the
9712 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009713 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009714 </para>
9715
9716 <section id='runtime-package-management-target-rpm'>
9717 <title>Using RPM</title>
9718
9719 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009720 The
9721 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9722 (DNF) performs runtime package management of RPM
9723 packages.
9724 In order to use DNF for runtime package management,
9725 you must perform an initial setup on the target
9726 machine for cases where the
9727 <filename>PACKAGE_FEED_*</filename> variables were not
9728 set as part of the image that is running on the
9729 target.
9730 This means if you built your image and did not not use
9731 these variables as part of the build and your image is
9732 now running on the target, you need to perform the
9733 steps in this section if you want to use runtime
9734 package management.
9735 <note>
9736 For information on the
9737 <filename>PACKAGE_FEED_*</filename> variables, see
9738 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9739 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9740 and
9741 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9742 in the Yocto Project Reference Manual variables
9743 glossary.
9744 </note>
9745 </para>
9746
9747 <para>
9748 On the target, you must inform DNF that package
9749 databases are available.
9750 You do this by creating a file named
9751 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9752 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009753 </para>
9754
9755 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009756 As an example, assume the target is able to use the
9757 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009758 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009759 and <filename>qemux86</filename> from a server named
9760 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009761 The specifics for setting up the web server are up to
9762 you.
9763 The critical requirement is that the URIs in the
9764 target repository configuration point to the
9765 correct remote location for the feeds.
9766 <note><title>Tip</title>
9767 For development purposes, you can point the web
9768 server to the build system's
9769 <filename>deploy</filename> directory.
9770 However, for production use, it is better to copy
9771 the package directories to a location outside of
9772 the build area and use that location.
9773 Doing so avoids situations where the build system
9774 overwrites or changes the
9775 <filename>deploy</filename> directory.
9776 </note>
9777 </para>
9778
9779 <para>
9780 When telling DNF where to look for the package
9781 databases, you must declare individual locations
9782 per architecture or a single location used for all
9783 architectures.
9784 You cannot do both:
9785 <itemizedlist>
9786 <listitem><para>
9787 <emphasis>Create an Explicit List of Architectures:</emphasis>
9788 Define individual base URLs to identify where
9789 each package database is located:
9790 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009791 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009792 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009793 </literallayout>
9794 This example informs DNF about individual
9795 package databases for all three architectures.
9796 </para></listitem>
9797 <listitem><para>
9798 <emphasis>Create a Single (Full) Package Index:</emphasis>
9799 Define a single base URL that identifies where
9800 a full package database is located:
9801 <literallayout class='monospaced'>
9802 [oe-packages]
9803 baseurl=http://my.server/rpm
9804 </literallayout>
9805 This example informs DNF about a single package
9806 database that contains all the package index
9807 information for all supported architectures.
9808 </para></listitem>
9809 </itemizedlist>
9810 </para>
9811
9812 <para>
9813 Once you have informed DNF where to find the package
9814 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009815 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009816 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009817 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009818 DNF is now able to find, install, and upgrade packages
9819 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009820 <note>
9821 See the
9822 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
9823 for additional information.
9824 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009825 </para>
9826 </section>
9827
9828 <section id='runtime-package-management-target-ipk'>
9829 <title>Using IPK</title>
9830
9831 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009832 The <filename>opkg</filename> application performs
9833 runtime package management of IPK packages.
9834 You must perform an initial setup for
9835 <filename>opkg</filename> on the target machine
9836 if the
9837 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9838 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
9839 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9840 variables have not been set or the target image was
9841 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009842 </para>
9843
9844 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009845 The <filename>opkg</filename> application uses
9846 configuration files to find available package
9847 databases.
9848 Thus, you need to create a configuration file inside
9849 the <filename>/etc/opkg/</filename> direction, which
9850 informs <filename>opkg</filename> of any repository
9851 you want to use.
9852 </para>
9853
9854 <para>
9855 As an example, suppose you are serving packages from a
9856 <filename>ipk/</filename> directory containing the
9857 <filename>i586</filename>,
9858 <filename>all</filename>, and
9859 <filename>qemux86</filename> databases through an
9860 HTTP server named <filename>my.server</filename>.
9861 On the target, create a configuration file
9862 (e.g. <filename>my_repo.conf</filename>) inside the
9863 <filename>/etc/opkg/</filename> directory containing
9864 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009865 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009866 src/gz all http://my.server/ipk/all
9867 src/gz i586 http://my.server/ipk/i586
9868 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009869 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009870 Next, instruct <filename>opkg</filename> to fetch
9871 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009872 <literallayout class='monospaced'>
9873 # opkg update
9874 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009875 The <filename>opkg</filename> application is now able
9876 to find, install, and upgrade packages from the
9877 specified repository.
9878 </para>
9879 </section>
9880
9881 <section id='runtime-package-management-target-deb'>
9882 <title>Using DEB</title>
9883
9884 <para>
9885 The <filename>apt</filename> application performs
9886 runtime package management of DEB packages.
9887 This application uses a source list file to find
9888 available package databases.
9889 You must perform an initial setup for
9890 <filename>apt</filename> on the target machine
9891 if the
9892 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9893 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
9894 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9895 variables have not been set or the target image was
9896 built before the variables were set.
9897 </para>
9898
9899 <para>
9900 To inform <filename>apt</filename> of the repository
9901 you want to use, you might create a list file (e.g.
9902 <filename>my_repo.list</filename>) inside the
9903 <filename>/etc/apt/sources.list.d/</filename>
9904 directory.
9905 As an example, suppose you are serving packages from a
9906 <filename>deb/</filename> directory containing the
9907 <filename>i586</filename>,
9908 <filename>all</filename>, and
9909 <filename>qemux86</filename> databases through an
9910 HTTP server named <filename>my.server</filename>.
9911 The list file should contain:
9912 <literallayout class='monospaced'>
9913 deb http://my.server/deb/all ./
9914 deb http://my.server/deb/i586 ./
9915 deb http://my.server/deb/qemux86 ./
9916 </literallayout>
9917 Next, instruct the <filename>apt</filename>
9918 application to fetch the repository information:
9919 <literallayout class='monospaced'>
9920 # apt-get update
9921 </literallayout>
9922 After this step, <filename>apt</filename> is able
9923 to find, install, and upgrade packages from the
9924 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009925 </para>
9926 </section>
9927 </section>
9928 </section>
9929
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009930 <section id='generating-and-using-signed-packages'>
9931 <title>Generating and Using Signed Packages</title>
9932 <para>
9933 In order to add security to RPM packages used during a build,
9934 you can take steps to securely sign them.
9935 Once a signature is verified, the OpenEmbedded build system
9936 can use the package in the build.
9937 If security fails for a signed package, the build system
9938 aborts the build.
9939 </para>
9940
9941 <para>
9942 This section describes how to sign RPM packages during a build
9943 and how to use signed package feeds (repositories) when
9944 doing a build.
9945 </para>
9946
9947 <section id='signing-rpm-packages'>
9948 <title>Signing RPM Packages</title>
9949
9950 <para>
9951 To enable signing RPM packages, you must set up the
9952 following configurations in either your
9953 <filename>local.config</filename> or
9954 <filename>distro.config</filename> file:
9955 <literallayout class='monospaced'>
9956 # Inherit sign_rpm.bbclass to enable signing functionality
9957 INHERIT += " sign_rpm"
9958 # Define the GPG key that will be used for signing.
9959 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
9960 # Provide passphrase for the key
9961 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
9962 </literallayout>
9963 <note>
9964 Be sure to supply appropriate values for both
9965 <replaceable>key_name</replaceable> and
9966 <replaceable>passphrase</replaceable>
9967 </note>
9968 Aside from the
9969 <filename>RPM_GPG_NAME</filename> and
9970 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
9971 previous example, two optional variables related to signing
9972 exist:
9973 <itemizedlist>
9974 <listitem><para>
9975 <emphasis><filename>GPG_BIN</filename>:</emphasis>
9976 Specifies a <filename>gpg</filename> binary/wrapper
9977 that is executed when the package is signed.
9978 </para></listitem>
9979 <listitem><para>
9980 <emphasis><filename>GPG_PATH</filename>:</emphasis>
9981 Specifies the <filename>gpg</filename> home
9982 directory used when the package is signed.
9983 </para></listitem>
9984 </itemizedlist>
9985 </para>
9986 </section>
9987
9988 <section id='processing-package-feeds'>
9989 <title>Processing Package Feeds</title>
9990
9991 <para>
9992 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009993 also enable signed package feeds for IPK and RPM packages.
9994 </para>
9995
9996 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009997 The steps you need to take to enable signed package feed
9998 use are similar to the steps used to sign RPM packages.
9999 You must define the following in your
10000 <filename>local.config</filename> or
10001 <filename>distro.config</filename> file:
10002 <literallayout class='monospaced'>
10003 INHERIT += "sign_package_feed"
10004 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10005 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10006 </literallayout>
10007 For signed package feeds, the passphrase must exist in a
10008 separate file, which is pointed to by the
10009 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10010 variable.
10011 Regarding security, keeping a plain text passphrase out of
10012 the configuration is more secure.
10013 </para>
10014
10015 <para>
10016 Aside from the
10017 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10018 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10019 variables, three optional variables related to signed
10020 package feeds exist:
10021 <itemizedlist>
10022 <listitem><para>
10023 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10024 Specifies a <filename>gpg</filename> binary/wrapper
10025 that is executed when the package is signed.
10026 </para></listitem>
10027 <listitem><para>
10028 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10029 Specifies the <filename>gpg</filename> home
10030 directory used when the package is signed.
10031 </para></listitem>
10032 <listitem><para>
10033 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10034 Specifies the type of <filename>gpg</filename>
10035 signature.
10036 This variable applies only to RPM and IPK package
10037 feeds.
10038 Allowable values for the
10039 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10040 are "ASC", which is the default and specifies ascii
10041 armored, and "BIN", which specifies binary.
10042 </para></listitem>
10043 </itemizedlist>
10044 </para>
10045 </section>
10046 </section>
10047
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010048 <section id='testing-packages-with-ptest'>
10049 <title>Testing Packages With ptest</title>
10050
10051 <para>
10052 A Package Test (ptest) runs tests against packages built
10053 by the OpenEmbedded build system on the target machine.
10054 A ptest contains at least two items: the actual test, and
10055 a shell script (<filename>run-ptest</filename>) that starts
10056 the test.
10057 The shell script that starts the test must not contain
10058 the actual test - the script only starts the test.
10059 On the other hand, the test can be anything from a simple
10060 shell script that runs a binary and checks the output to
10061 an elaborate system of test binaries and data files.
10062 </para>
10063
10064 <para>
10065 The test generates output in the format used by
10066 Automake:
10067 <literallayout class='monospaced'>
10068 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10069 </literallayout>
10070 where the result can be <filename>PASS</filename>,
10071 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10072 and the testname can be any identifying string.
10073 </para>
10074
10075 <para>
10076 For a list of Yocto Project recipes that are already
10077 enabled with ptest, see the
10078 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10079 wiki page.
10080 <note>
10081 A recipe is "ptest-enabled" if it inherits the
10082 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10083 class.
10084 </note>
10085 </para>
10086
10087 <section id='adding-ptest-to-your-build'>
10088 <title>Adding ptest to Your Build</title>
10089
10090 <para>
10091 To add package testing to your build, add the
10092 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10093 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10094 variables to your <filename>local.conf</filename> file,
10095 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010096 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010097 <literallayout class='monospaced'>
10098 DISTRO_FEATURES_append = " ptest"
10099 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10100 </literallayout>
10101 Once your build is complete, the ptest files are installed
10102 into the
10103 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10104 directory within the image, where
10105 <filename><replaceable>package</replaceable></filename>
10106 is the name of the package.
10107 </para>
10108 </section>
10109
10110 <section id='running-ptest'>
10111 <title>Running ptest</title>
10112
10113 <para>
10114 The <filename>ptest-runner</filename> package installs a
10115 shell script that loops through all installed ptest test
10116 suites and runs them in sequence.
10117 Consequently, you might want to add this package to
10118 your image.
10119 </para>
10120 </section>
10121
10122 <section id='getting-your-package-ready'>
10123 <title>Getting Your Package Ready</title>
10124
10125 <para>
10126 In order to enable a recipe to run installed ptests
10127 on target hardware,
10128 you need to prepare the recipes that build the packages
10129 you want to test.
10130 Here is what you have to do for each recipe:
10131 <itemizedlist>
10132 <listitem><para><emphasis>Be sure the recipe
10133 inherits the
10134 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10135 class:</emphasis>
10136 Include the following line in each recipe:
10137 <literallayout class='monospaced'>
10138 inherit ptest
10139 </literallayout>
10140 </para></listitem>
10141 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10142 This script starts your test.
10143 Locate the script where you will refer to it
10144 using
10145 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10146 Here is an example that starts a test for
10147 <filename>dbus</filename>:
10148 <literallayout class='monospaced'>
10149 #!/bin/sh
10150 cd test
10151 make -k runtest-TESTS
10152 </literallayout>
10153 </para></listitem>
10154 <listitem><para><emphasis>Ensure dependencies are
10155 met:</emphasis>
10156 If the test adds build or runtime dependencies
10157 that normally do not exist for the package
10158 (such as requiring "make" to run the test suite),
10159 use the
10160 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10161 and
10162 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10163 variables in your recipe in order for the package
10164 to meet the dependencies.
10165 Here is an example where the package has a runtime
10166 dependency on "make":
10167 <literallayout class='monospaced'>
10168 RDEPENDS_${PN}-ptest += "make"
10169 </literallayout>
10170 </para></listitem>
10171 <listitem><para><emphasis>Add a function to build the
10172 test suite:</emphasis>
10173 Not many packages support cross-compilation of
10174 their test suites.
10175 Consequently, you usually need to add a
10176 cross-compilation function to the package.
10177 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010178
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010179 <para>Many packages based on Automake compile and
10180 run the test suite by using a single command
10181 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010182 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010183 builds and runs on the same computer, while
10184 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010185 on the host but executed for the target
10186 architecture (though often, as in the case for
10187 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010188 The built version of Automake that ships with the
10189 Yocto Project includes a patch that separates
10190 building and execution.
10191 Consequently, packages that use the unaltered,
10192 patched version of <filename>make check</filename>
10193 automatically cross-compiles.</para>
10194 <para>Regardless, you still must add a
10195 <filename>do_compile_ptest</filename> function to
10196 build the test suite.
10197 Add a function similar to the following to your
10198 recipe:
10199 <literallayout class='monospaced'>
10200 do_compile_ptest() {
10201 oe_runmake buildtest-TESTS
10202 }
10203 </literallayout>
10204 </para></listitem>
10205 <listitem><para><emphasis>Ensure special configurations
10206 are set:</emphasis>
10207 If the package requires special configurations
10208 prior to compiling the test code, you must
10209 insert a <filename>do_configure_ptest</filename>
10210 function into the recipe.
10211 </para></listitem>
10212 <listitem><para><emphasis>Install the test
10213 suite:</emphasis>
10214 The <filename>ptest</filename> class
10215 automatically copies the file
10216 <filename>run-ptest</filename> to the target and
10217 then runs make <filename>install-ptest</filename>
10218 to run the tests.
10219 If this is not enough, you need to create a
10220 <filename>do_install_ptest</filename> function and
10221 make sure it gets called after the
10222 "make install-ptest" completes.
10223 </para></listitem>
10224 </itemizedlist>
10225 </para>
10226 </section>
10227 </section>
10228 </section>
10229
Brad Bishop316dfdd2018-06-25 12:45:53 -040010230 <section id='efficiently-fetching-source-files-during-a-build'>
10231 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010232
10233 <para>
10234 The OpenEmbedded build system works with source files located
10235 through the
10236 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10237 variable.
10238 When you build something using BitBake, a big part of the operation
10239 is locating and downloading all the source tarballs.
10240 For images, downloading all the source for various packages can
10241 take a significant amount of time.
10242 </para>
10243
10244 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010245 This section shows you how you can use mirrors to speed up
10246 fetching source files and how you can pre-fetch files all of which
10247 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010248 </para>
10249
10250 <section id='setting-up-effective-mirrors'>
10251 <title>Setting up Effective Mirrors</title>
10252
10253 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010254 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010255 build is simply downloading all of the source tarballs.
10256 Maybe you have been working with another build system
10257 (OpenEmbedded or Angstrom) for which you have built up a
10258 sizable directory of source tarballs.
10259 Or, perhaps someone else has such a directory for which you
10260 have read access.
10261 If so, you can save time by adding statements to your
10262 configuration file so that the build process checks local
10263 directories first for existing tarballs before checking the
10264 Internet.
10265 </para>
10266
10267 <para>
10268 Here is an efficient way to set it up in your
10269 <filename>local.conf</filename> file:
10270 <literallayout class='monospaced'>
10271 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10272 INHERIT += "own-mirrors"
10273 BB_GENERATE_MIRROR_TARBALLS = "1"
10274 # BB_NO_NETWORK = "1"
10275 </literallayout>
10276 </para>
10277
10278 <para>
10279 In the previous example, the
10280 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10281 variable causes the OpenEmbedded build system to generate
10282 tarballs of the Git repositories and store them in the
10283 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10284 directory.
10285 Due to performance reasons, generating and storing these
10286 tarballs is not the build system's default behavior.
10287 </para>
10288
10289 <para>
10290 You can also use the
10291 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10292 variable.
10293 For an example, see the variable's glossary entry in the
10294 Yocto Project Reference Manual.
10295 </para>
10296 </section>
10297
10298 <section id='getting-source-files-and-suppressing-the-build'>
10299 <title>Getting Source Files and Suppressing the Build</title>
10300
10301 <para>
10302 Another technique you can use to ready yourself for a
10303 successive string of build operations, is to pre-fetch
10304 all the source files without actually starting a build.
10305 This technique lets you work through any download issues
10306 and ultimately gathers all the source files into your
10307 download directory
10308 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10309 which is located with
10310 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10311 </para>
10312
10313 <para>
10314 Use the following BitBake command form to fetch all the
10315 necessary sources without starting the build:
10316 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010317 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010318 </literallayout>
10319 This variation of the BitBake command guarantees that you
10320 have all the sources for that BitBake target should you
10321 disconnect from the Internet and want to do the build
10322 later offline.
10323 </para>
10324 </section>
10325 </section>
10326
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010327 <section id="selecting-an-initialization-manager">
10328 <title>Selecting an Initialization Manager</title>
10329
10330 <para>
10331 By default, the Yocto Project uses SysVinit as the initialization
10332 manager.
10333 However, support also exists for systemd,
10334 which is a full replacement for init with
10335 parallel starting of services, reduced shell overhead and other
10336 features that are used by many distributions.
10337 </para>
10338
10339 <para>
10340 If you want to use SysVinit, you do
10341 not have to do anything.
10342 But, if you want to use systemd, you must
10343 take some steps as described in the following sections.
10344 </para>
10345
10346 <section id='using-systemd-exclusively'>
10347 <title>Using systemd Exclusively</title>
10348
10349 <para>
10350 Set the these variables in your distribution configuration
10351 file as follows:
10352 <literallayout class='monospaced'>
10353 DISTRO_FEATURES_append = " systemd"
10354 VIRTUAL-RUNTIME_init_manager = "systemd"
10355 </literallayout>
10356 You can also prevent the SysVinit
10357 distribution feature from
10358 being automatically enabled as follows:
10359 <literallayout class='monospaced'>
10360 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10361 </literallayout>
10362 Doing so removes any redundant SysVinit scripts.
10363 </para>
10364
10365 <para>
10366 To remove initscripts from your image altogether,
10367 set this variable also:
10368 <literallayout class='monospaced'>
10369 VIRTUAL-RUNTIME_initscripts = ""
10370 </literallayout>
10371 </para>
10372
10373 <para>
10374 For information on the backfill variable, see
10375 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10376 </para>
10377 </section>
10378
10379 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10380 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10381
10382 <para>
10383 Set these variables in your distribution configuration
10384 file as follows:
10385 <literallayout class='monospaced'>
10386 DISTRO_FEATURES_append = " systemd"
10387 VIRTUAL-RUNTIME_init_manager = "systemd"
10388 </literallayout>
10389 Doing so causes your main image to use the
10390 <filename>packagegroup-core-boot.bb</filename> recipe and
10391 systemd.
10392 The rescue/minimal image cannot use this package group.
10393 However, it can install SysVinit
10394 and the appropriate packages will have support for both
10395 systemd and SysVinit.
10396 </para>
10397 </section>
10398 </section>
10399
10400 <section id="selecting-dev-manager">
10401 <title>Selecting a Device Manager</title>
10402
10403 <para>
10404 The Yocto Project provides multiple ways to manage the device
10405 manager (<filename>/dev</filename>):
10406 <itemizedlist>
10407 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10408 For this case, the <filename>/dev</filename> directory
10409 is persistent and the required device nodes are created
10410 during the build.
10411 </para></listitem>
10412 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10413 For this case, the <filename>/dev</filename> directory
10414 is provided by the kernel as an in-memory file system and
10415 is automatically populated by the kernel at runtime.
10416 Additional configuration of device nodes is done in user
10417 space by a device manager like
10418 <filename>udev</filename> or
10419 <filename>busybox-mdev</filename>.
10420 </para></listitem>
10421 </itemizedlist>
10422 </para>
10423
10424 <section id="static-dev-management">
10425 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10426
10427 <para>
10428 To use the static method for device population, you need to
10429 set the
10430 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10431 variable to "0" as follows:
10432 <literallayout class='monospaced'>
10433 USE_DEVFS = "0"
10434 </literallayout>
10435 </para>
10436
10437 <para>
10438 The content of the resulting <filename>/dev</filename>
10439 directory is defined in a Device Table file.
10440 The
10441 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10442 variable defines the Device Table to use and should be set
10443 in the machine or distro configuration file.
10444 Alternatively, you can set this variable in your
10445 <filename>local.conf</filename> configuration file.
10446 </para>
10447
10448 <para>
10449 If you do not define the
10450 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10451 <filename>device_table-minimal.txt</filename> is used:
10452 <literallayout class='monospaced'>
10453 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10454 </literallayout>
10455 </para>
10456
10457 <para>
10458 The population is handled by the <filename>makedevs</filename>
10459 utility during image creation:
10460 </para>
10461 </section>
10462
10463 <section id="devtmpfs-dev-management">
10464 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10465
10466 <para>
10467 To use the dynamic method for device population, you need to
10468 use (or be sure to set) the
10469 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10470 variable to "1", which is the default:
10471 <literallayout class='monospaced'>
10472 USE_DEVFS = "1"
10473 </literallayout>
10474 With this setting, the resulting <filename>/dev</filename>
10475 directory is populated by the kernel using
10476 <filename>devtmpfs</filename>.
10477 Make sure the corresponding kernel configuration variable
10478 <filename>CONFIG_DEVTMPFS</filename> is set when building
10479 you build a Linux kernel.
10480 </para>
10481
10482 <para>
10483 All devices created by <filename>devtmpfs</filename> will be
10484 owned by <filename>root</filename> and have permissions
10485 <filename>0600</filename>.
10486 </para>
10487
10488 <para>
10489 To have more control over the device nodes, you can use a
10490 device manager like <filename>udev</filename> or
10491 <filename>busybox-mdev</filename>.
10492 You choose the device manager by defining the
10493 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10494 in your machine or distro configuration file.
10495 Alternatively, you can set this variable in your
10496 <filename>local.conf</filename> configuration file:
10497 <literallayout class='monospaced'>
10498 VIRTUAL-RUNTIME_dev_manager = "udev"
10499
10500 # Some alternative values
10501 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10502 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10503 </literallayout>
10504 </para>
10505 </section>
10506 </section>
10507
10508 <section id="platdev-appdev-srcrev">
10509 <title>Using an External SCM</title>
10510
10511 <para>
10512 If you're working on a recipe that pulls from an external Source
10513 Code Manager (SCM), it is possible to have the OpenEmbedded build
10514 system notice new recipe changes added to the SCM and then build
10515 the resulting packages that depend on the new recipes by using
10516 the latest versions.
10517 This only works for SCMs from which it is possible to get a
10518 sensible revision number for changes.
10519 Currently, you can do this with Apache Subversion (SVN), Git, and
10520 Bazaar (BZR) repositories.
10521 </para>
10522
10523 <para>
10524 To enable this behavior, the
10525 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
10526 of the recipe needs to reference
10527 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
10528 Here is an example:
10529 <literallayout class='monospaced'>
10530 PV = "1.2.3+git${SRCPV}"
10531 </literallayout>
10532 Then, you can add the following to your
10533 <filename>local.conf</filename>:
10534 <literallayout class='monospaced'>
10535 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
10536 </literallayout>
10537 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
10538 is the name of the recipe for which you want to enable automatic source
10539 revision updating.
10540 </para>
10541
10542 <para>
10543 If you do not want to update your local configuration file, you can
10544 add the following directly to the recipe to finish enabling
10545 the feature:
10546 <literallayout class='monospaced'>
10547 SRCREV = "${AUTOREV}"
10548 </literallayout>
10549 </para>
10550
10551 <para>
10552 The Yocto Project provides a distribution named
10553 <filename>poky-bleeding</filename>, whose configuration
10554 file contains the line:
10555 <literallayout class='monospaced'>
10556 require conf/distro/include/poky-floating-revisions.inc
10557 </literallayout>
10558 This line pulls in the listed include file that contains
10559 numerous lines of exactly that form:
10560 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010561 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
10562 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
10563 #SRCREV_pn-opkg ?= "${AUTOREV}"
10564 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
10565 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010566 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
10567 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
10568 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
10569 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
10570 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010571 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
10572 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
10573 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
10574 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010575 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
10576 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010577 .
10578 .
10579 .
10580 </literallayout>
10581 These lines allow you to experiment with building a
10582 distribution that tracks the latest development source
10583 for numerous packages.
10584 <note><title>Caution</title>
10585 The <filename>poky-bleeding</filename> distribution
10586 is not tested on a regular basis.
10587 Keep this in mind if you use it.
10588 </note>
10589 </para>
10590 </section>
10591
10592 <section id='creating-a-read-only-root-filesystem'>
10593 <title>Creating a Read-Only Root Filesystem</title>
10594
10595 <para>
10596 Suppose, for security reasons, you need to disable
10597 your target device's root filesystem's write permissions
10598 (i.e. you need a read-only root filesystem).
10599 Or, perhaps you are running the device's operating system
10600 from a read-only storage device.
10601 For either case, you can customize your image for
10602 that behavior.
10603 </para>
10604
10605 <note>
10606 Supporting a read-only root filesystem requires that the system and
10607 applications do not try to write to the root filesystem.
10608 You must configure all parts of the target system to write
10609 elsewhere, or to gracefully fail in the event of attempting to
10610 write to the root filesystem.
10611 </note>
10612
10613 <section id='creating-the-root-filesystem'>
10614 <title>Creating the Root Filesystem</title>
10615
10616 <para>
10617 To create the read-only root filesystem, simply add the
10618 "read-only-rootfs" feature to your image.
10619 Using either of the following statements in your
10620 image recipe or from within the
10621 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010622 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010623 causes the build system to create a read-only root filesystem:
10624 <literallayout class='monospaced'>
10625 IMAGE_FEATURES = "read-only-rootfs"
10626 </literallayout>
10627 or
10628 <literallayout class='monospaced'>
10629 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
10630 </literallayout>
10631 </para>
10632
10633 <para>
10634 For more information on how to use these variables, see the
10635 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
10636 section.
10637 For information on the variables, see
10638 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
10639 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
10640 </para>
10641 </section>
10642
10643 <section id='post-installation-scripts'>
10644 <title>Post-Installation Scripts</title>
10645
10646 <para>
10647 It is very important that you make sure all
10648 post-Installation (<filename>pkg_postinst</filename>) scripts
10649 for packages that are installed into the image can be run
10650 at the time when the root filesystem is created during the
10651 build on the host system.
10652 These scripts cannot attempt to run during first-boot on the
10653 target device.
10654 With the "read-only-rootfs" feature enabled,
10655 the build system checks during root filesystem creation to make
10656 sure all post-installation scripts succeed.
10657 If any of these scripts still need to be run after the root
10658 filesystem is created, the build immediately fails.
10659 These build-time checks ensure that the build fails
10660 rather than the target device fails later during its
10661 initial boot operation.
10662 </para>
10663
10664 <para>
10665 Most of the common post-installation scripts generated by the
10666 build system for the out-of-the-box Yocto Project are engineered
10667 so that they can run during root filesystem creation
10668 (e.g. post-installation scripts for caching fonts).
10669 However, if you create and add custom scripts, you need
10670 to be sure they can be run during this file system creation.
10671 </para>
10672
10673 <para>
10674 Here are some common problems that prevent
10675 post-installation scripts from running during root filesystem
10676 creation:
10677 <itemizedlist>
10678 <listitem><para>
10679 <emphasis>Not using $D in front of absolute
10680 paths:</emphasis>
10681 The build system defines
10682 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
10683 when the root filesystem is created.
10684 Furthermore, <filename>$D</filename> is blank when the
10685 script is run on the target device.
10686 This implies two purposes for <filename>$D</filename>:
10687 ensuring paths are valid in both the host and target
10688 environments, and checking to determine which
10689 environment is being used as a method for taking
10690 appropriate actions.
10691 </para></listitem>
10692 <listitem><para>
10693 <emphasis>Attempting to run processes that are
10694 specific to or dependent on the target
10695 architecture:</emphasis>
10696 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010697 tools, which run on the host system,
10698 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010699 by alternatively running the processes under QEMU,
10700 which has the <filename>qemu_run_binary</filename>
10701 function.
10702 For more information, see the
10703 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
10704 class.</para></listitem>
10705 </itemizedlist>
10706 </para>
10707 </section>
10708
10709 <section id='areas-with-write-access'>
10710 <title>Areas With Write Access</title>
10711
10712 <para>
10713 With the "read-only-rootfs" feature enabled,
10714 any attempt by the target to write to the root filesystem at
10715 runtime fails.
10716 Consequently, you must make sure that you configure processes
10717 and applications that attempt these types of writes do so
10718 to directories with write access (e.g.
10719 <filename>/tmp</filename> or <filename>/var/run</filename>).
10720 </para>
10721 </section>
10722 </section>
10723
Brad Bishop316dfdd2018-06-25 12:45:53 -040010724
10725
10726
10727 <section id='maintaining-build-output-quality'>
10728 <title>Maintaining Build Output Quality</title>
10729
10730 <para>
10731 Many factors can influence the quality of a build.
10732 For example, if you upgrade a recipe to use a new version of an
10733 upstream software package or you experiment with some new
10734 configuration options, subtle changes can occur that you might
10735 not detect until later.
10736 Consider the case where your recipe is using a newer version of
10737 an upstream package.
10738 In this case, a new version of a piece of software might
10739 introduce an optional dependency on another library, which is
10740 auto-detected.
10741 If that library has already been built when the software is
10742 building, the software will link to the built library and that
10743 library will be pulled into your image along with the new
10744 software even if you did not want the library.
10745 </para>
10746
10747 <para>
10748 The
10749 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
10750 class exists to help you maintain the quality of your build
10751 output.
10752 You can use the class to highlight unexpected and possibly
10753 unwanted changes in the build output.
10754 When you enable build history, it records information about the
10755 contents of each package and image and then commits that
10756 information to a local Git repository where you can examine
10757 the information.
10758 </para>
10759
10760 <para>
10761 The remainder of this section describes the following:
10762 <itemizedlist>
10763 <listitem><para>
10764 How you can enable and disable build history
10765 </para></listitem>
10766 <listitem><para>
10767 How to understand what the build history contains
10768 </para></listitem>
10769 <listitem><para>
10770 How to limit the information used for build history
10771 </para></listitem>
10772 <listitem><para>
10773 How to examine the build history from both a
10774 command-line and web interface
10775 </para></listitem>
10776 </itemizedlist>
10777 </para>
10778
10779 <section id='enabling-and-disabling-build-history'>
10780 <title>Enabling and Disabling Build History</title>
10781
10782 <para>
10783 Build history is disabled by default.
10784 To enable it, add the following <filename>INHERIT</filename>
10785 statement and set the
10786 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
10787 variable to "1" at the end of your
10788 <filename>conf/local.conf</filename> file found in the
10789 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
10790 <literallayout class='monospaced'>
10791 INHERIT += "buildhistory"
10792 BUILDHISTORY_COMMIT = "1"
10793 </literallayout>
10794 Enabling build history as previously described causes the
10795 OpenEmbedded build system to collect build output information
10796 and commit it as a single commit to a local
10797 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
10798 repository.
10799 <note>
10800 Enabling build history increases your build times slightly,
10801 particularly for images, and increases the amount of disk
10802 space used during the build.
10803 </note>
10804 </para>
10805
10806 <para>
10807 You can disable build history by removing the previous
10808 statements from your <filename>conf/local.conf</filename>
10809 file.
10810 </para>
10811 </section>
10812
10813 <section id='understanding-what-the-build-history-contains'>
10814 <title>Understanding What the Build History Contains</title>
10815
10816 <para>
10817 Build history information is kept in
10818 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
10819 in the Build Directory as defined by the
10820 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
10821 variable.
10822 The following is an example abbreviated listing:
10823 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
10824 </para>
10825
10826 <para>
10827 At the top level, a <filename>metadata-revs</filename>
10828 file exists that lists the revisions of the repositories for
10829 the enabled layers when the build was produced.
10830 The rest of the data splits into separate
10831 <filename>packages</filename>, <filename>images</filename>
10832 and <filename>sdk</filename> directories, the contents of
10833 which are described as follows.
10834 </para>
10835
10836 <section id='build-history-package-information'>
10837 <title>Build History Package Information</title>
10838
10839 <para>
10840 The history for each package contains a text file that has
10841 name-value pairs with information about the package.
10842 For example,
10843 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
10844 contains the following:
10845 <literallayout class='monospaced'>
10846 PV = 1.22.1
10847 PR = r32
10848 RPROVIDES =
10849 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
10850 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
10851 PKGSIZE = 540168
10852 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
10853 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
10854 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
10855 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
10856 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
10857 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
10858 /etc/busybox.links.nosuid /etc/busybox.links.suid
10859 </literallayout>
10860 Most of these name-value pairs correspond to variables
10861 used to produce the package.
10862 The exceptions are <filename>FILELIST</filename>, which
10863 is the actual list of files in the package, and
10864 <filename>PKGSIZE</filename>, which is the total size of
10865 files in the package in bytes.
10866 </para>
10867
10868 <para>
10869 A file also exists that corresponds to the recipe from
10870 which the package came (e.g.
10871 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
10872 <literallayout class='monospaced'>
10873 PV = 1.22.1
10874 PR = r32
10875 DEPENDS = initscripts kern-tools-native update-rc.d-native \
10876 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
10877 virtual/libc virtual/update-alternatives
10878 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
10879 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
10880 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
10881 </literallayout>
10882 </para>
10883
10884 <para>
10885 Finally, for those recipes fetched from a version control
10886 system (e.g., Git), a file exists that lists source
10887 revisions that are specified in the recipe and lists
10888 the actual revisions used during the build.
10889 Listed and actual revisions might differ when
10890 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
10891 is set to
10892 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
10893 Here is an example assuming
10894 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
10895 <literallayout class='monospaced'>
10896 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
10897 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
10898 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
10899 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
10900 </literallayout>
10901 You can use the
10902 <filename>buildhistory-collect-srcrevs</filename>
10903 command with the <filename>-a</filename> option to
10904 collect the stored <filename>SRCREV</filename> values
10905 from build history and report them in a format suitable for
10906 use in global configuration (e.g.,
10907 <filename>local.conf</filename> or a distro include file)
10908 to override floating <filename>AUTOREV</filename> values
10909 to a fixed set of revisions.
10910 Here is some example output from this command:
10911 <literallayout class='monospaced'>
10912 $ buildhistory-collect-srcrevs -a
10913 # i586-poky-linux
10914 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
10915 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
10916 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
10917 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
10918 # x86_64-linux
10919 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
10920 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
10921 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
10922 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
10923 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
10924 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
10925 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
10926 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
10927 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
10928 # qemux86-poky-linux
10929 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
10930 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
10931 # all-poky-linux
10932 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
10933 </literallayout>
10934 <note>
10935 Here are some notes on using the
10936 <filename>buildhistory-collect-srcrevs</filename>
10937 command:
10938 <itemizedlist>
10939 <listitem><para>
10940 By default, only values where the
10941 <filename>SRCREV</filename> was not hardcoded
10942 (usually when <filename>AUTOREV</filename>
10943 is used) are reported.
10944 Use the <filename>-a</filename> option to
10945 see all <filename>SRCREV</filename> values.
10946 </para></listitem>
10947 <listitem><para>
10948 The output statements might not have any effect
10949 if overrides are applied elsewhere in the
10950 build system configuration.
10951 Use the <filename>-f</filename> option to add
10952 the <filename>forcevariable</filename> override
10953 to each output line if you need to work around
10954 this restriction.
10955 </para></listitem>
10956 <listitem><para>
10957 The script does apply special handling when
10958 building for multiple machines.
10959 However, the script does place a comment before
10960 each set of values that specifies which
10961 triplet to which they belong as previously
10962 shown (e.g.,
10963 <filename>i586-poky-linux</filename>).
10964 </para></listitem>
10965 </itemizedlist>
10966 </note>
10967 </para>
10968 </section>
10969
10970 <section id='build-history-image-information'>
10971 <title>Build History Image Information</title>
10972
10973 <para>
10974 The files produced for each image are as follows:
10975 <itemizedlist>
10976 <listitem><para>
10977 <filename>image-files:</filename>
10978 A directory containing selected files from the root
10979 filesystem.
10980 The files are defined by
10981 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
10982 </para></listitem>
10983 <listitem><para>
10984 <filename>build-id.txt:</filename>
10985 Human-readable information about the build
10986 configuration and metadata source revisions.
10987 This file contains the full build header as printed
10988 by BitBake.
10989 </para></listitem>
10990 <listitem><para>
10991 <filename>*.dot:</filename>
10992 Dependency graphs for the image that are
10993 compatible with <filename>graphviz</filename>.
10994 </para></listitem>
10995 <listitem><para>
10996 <filename>files-in-image.txt:</filename>
10997 A list of files in the image with permissions,
10998 owner, group, size, and symlink information.
10999 </para></listitem>
11000 <listitem><para>
11001 <filename>image-info.txt:</filename>
11002 A text file containing name-value pairs with
11003 information about the image.
11004 See the following listing example for more
11005 information.
11006 </para></listitem>
11007 <listitem><para>
11008 <filename>installed-package-names.txt:</filename>
11009 A list of installed packages by name only.
11010 </para></listitem>
11011 <listitem><para>
11012 <filename>installed-package-sizes.txt:</filename>
11013 A list of installed packages ordered by size.
11014 </para></listitem>
11015 <listitem><para>
11016 <filename>installed-packages.txt:</filename>
11017 A list of installed packages with full package
11018 filenames.
11019 </para></listitem>
11020 </itemizedlist>
11021 <note>
11022 Installed package information is able to be gathered
11023 and produced even if package management is disabled
11024 for the final image.
11025 </note>
11026 </para>
11027
11028 <para>
11029 Here is an example of <filename>image-info.txt</filename>:
11030 <literallayout class='monospaced'>
11031 DISTRO = poky
11032 DISTRO_VERSION = 1.7
11033 USER_CLASSES = buildstats image-mklibs image-prelink
11034 IMAGE_CLASSES = image_types
11035 IMAGE_FEATURES = debug-tweaks
11036 IMAGE_LINGUAS =
11037 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11038 BAD_RECOMMENDATIONS =
11039 NO_RECOMMENDATIONS =
11040 PACKAGE_EXCLUDE =
11041 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11042 write_image_manifest ; buildhistory_list_installed_image ; \
11043 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11044 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11045 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11046 IMAGESIZE = 6900
11047 </literallayout>
11048 Other than <filename>IMAGESIZE</filename>, which is the
11049 total size of the files in the image in Kbytes, the
11050 name-value pairs are variables that may have influenced the
11051 content of the image.
11052 This information is often useful when you are trying to
11053 determine why a change in the package or file
11054 listings has occurred.
11055 </para>
11056 </section>
11057
11058 <section id='using-build-history-to-gather-image-information-only'>
11059 <title>Using Build History to Gather Image Information Only</title>
11060
11061 <para>
11062 As you can see, build history produces image information,
11063 including dependency graphs, so you can see why something
11064 was pulled into the image.
11065 If you are just interested in this information and not
11066 interested in collecting specific package or SDK
11067 information, you can enable writing only image information
11068 without any history by adding the following to your
11069 <filename>conf/local.conf</filename> file found in the
11070 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11071 <literallayout class='monospaced'>
11072 INHERIT += "buildhistory"
11073 BUILDHISTORY_COMMIT = "0"
11074 BUILDHISTORY_FEATURES = "image"
11075 </literallayout>
11076 Here, you set the
11077 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11078 variable to use the image feature only.
11079 </para>
11080 </section>
11081
11082 <section id='build-history-sdk-information'>
11083 <title>Build History SDK Information</title>
11084
11085 <para>
11086 Build history collects similar information on the contents
11087 of SDKs
11088 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11089 as compared to information it collects for images.
11090 Furthermore, this information differs depending on whether
11091 an extensible or standard SDK is being produced.
11092 </para>
11093
11094 <para>
11095 The following list shows the files produced for SDKs:
11096 <itemizedlist>
11097 <listitem><para>
11098 <filename>files-in-sdk.txt:</filename>
11099 A list of files in the SDK with permissions,
11100 owner, group, size, and symlink information.
11101 This list includes both the host and target parts
11102 of the SDK.
11103 </para></listitem>
11104 <listitem><para>
11105 <filename>sdk-info.txt:</filename>
11106 A text file containing name-value pairs with
11107 information about the SDK.
11108 See the following listing example for more
11109 information.
11110 </para></listitem>
11111 <listitem><para>
11112 <filename>sstate-task-sizes.txt:</filename>
11113 A text file containing name-value pairs with
11114 information about task group sizes
11115 (e.g. <filename>do_populate_sysroot</filename>
11116 tasks have a total size).
11117 The <filename>sstate-task-sizes.txt</filename> file
11118 exists only when an extensible SDK is created.
11119 </para></listitem>
11120 <listitem><para>
11121 <filename>sstate-package-sizes.txt:</filename>
11122 A text file containing name-value pairs with
11123 information for the shared-state packages and
11124 sizes in the SDK.
11125 The <filename>sstate-package-sizes.txt</filename>
11126 file exists only when an extensible SDK is created.
11127 </para></listitem>
11128 <listitem><para>
11129 <filename>sdk-files:</filename>
11130 A folder that contains copies of the files
11131 mentioned in
11132 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11133 files are present in the output.
11134 Additionally, the default value of
11135 <filename>BUILDHISTORY_SDK_FILES</filename> is
11136 specific to the extensible SDK although you can
11137 set it differently if you would like to pull in
11138 specific files from the standard SDK.</para>
11139
11140 <para>The default files are
11141 <filename>conf/local.conf</filename>,
11142 <filename>conf/bblayers.conf</filename>,
11143 <filename>conf/auto.conf</filename>,
11144 <filename>conf/locked-sigs.inc</filename>, and
11145 <filename>conf/devtool.conf</filename>.
11146 Thus, for an extensible SDK, these files get
11147 copied into the <filename>sdk-files</filename>
11148 directory.
11149 </para></listitem>
11150 <listitem><para>
11151 The following information appears under
11152 each of the <filename>host</filename>
11153 and <filename>target</filename> directories
11154 for the portions of the SDK that run on the host
11155 and on the target, respectively:
11156 <note>
11157 The following files for the most part are empty
11158 when producing an extensible SDK because this
11159 type of SDK is not constructed from packages
11160 as is the standard SDK.
11161 </note>
11162 <itemizedlist>
11163 <listitem><para>
11164 <filename>depends.dot:</filename>
11165 Dependency graph for the SDK that is
11166 compatible with
11167 <filename>graphviz</filename>.
11168 </para></listitem>
11169 <listitem><para>
11170 <filename>installed-package-names.txt:</filename>
11171 A list of installed packages by name only.
11172 </para></listitem>
11173 <listitem><para>
11174 <filename>installed-package-sizes.txt:</filename>
11175 A list of installed packages ordered by size.
11176 </para></listitem>
11177 <listitem><para>
11178 <filename>installed-packages.txt:</filename>
11179 A list of installed packages with full
11180 package filenames.
11181 </para></listitem>
11182 </itemizedlist>
11183 </para></listitem>
11184 </itemizedlist>
11185 </para>
11186
11187 <para>
11188 Here is an example of <filename>sdk-info.txt</filename>:
11189 <literallayout class='monospaced'>
11190 DISTRO = poky
11191 DISTRO_VERSION = 1.3+snapshot-20130327
11192 SDK_NAME = poky-glibc-i686-arm
11193 SDK_VERSION = 1.3+snapshot
11194 SDKMACHINE =
11195 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11196 BAD_RECOMMENDATIONS =
11197 SDKSIZE = 352712
11198 </literallayout>
11199 Other than <filename>SDKSIZE</filename>, which is the
11200 total size of the files in the SDK in Kbytes, the
11201 name-value pairs are variables that might have influenced
11202 the content of the SDK.
11203 This information is often useful when you are trying to
11204 determine why a change in the package or file listings
11205 has occurred.
11206 </para>
11207 </section>
11208
11209 <section id='examining-build-history-information'>
11210 <title>Examining Build History Information</title>
11211
11212 <para>
11213 You can examine build history output from the command
11214 line or from a web interface.
11215 </para>
11216
11217 <para>
11218 To see any changes that have occurred (assuming you have
11219 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11220 you can simply use any Git command that allows you to
11221 view the history of a repository.
11222 Here is one method:
11223 <literallayout class='monospaced'>
11224 $ git log -p
11225 </literallayout>
11226 You need to realize, however, that this method does show
11227 changes that are not significant (e.g. a package's size
11228 changing by a few bytes).
11229 </para>
11230
11231 <para>
11232 A command-line tool called
11233 <filename>buildhistory-diff</filename> does exist, though,
11234 that queries the Git repository and prints just the
11235 differences that might be significant in human-readable
11236 form.
11237 Here is an example:
11238 <literallayout class='monospaced'>
11239 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11240 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11241 /etc/anotherpkg.conf was added
11242 /sbin/anotherpkg was added
11243 * (installed-package-names.txt):
11244 * anotherpkg was added
11245 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11246 anotherpkg was added
11247 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11248 * PR changed from "r0" to "r1"
11249 * PV changed from "0.1.10" to "0.1.12"
11250 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11251 * PR changed from "r0" to "r1"
11252 * PV changed from "0.1.10" to "0.1.12"
11253 </literallayout>
11254 <note>
11255 The <filename>buildhistory-diff</filename> tool
11256 requires the <filename>GitPython</filename> package.
11257 Be sure to install it using Pip3 as follows:
11258 <literallayout class='monospaced'>
11259 $ pip3 install GitPython --user
11260 </literallayout>
11261 Alternatively, you can install
11262 <filename>python3-git</filename> using the appropriate
11263 distribution package manager (e.g.
11264 <filename>apt-get</filename>, <filename>dnf</filename>,
11265 or <filename>zipper</filename>).
11266 </note>
11267 </para>
11268
11269 <para>
11270 To see changes to the build history using a web interface,
11271 follow the instruction in the <filename>README</filename>
11272 file here.
11273 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11274 </para>
11275
11276 <para>
11277 Here is a sample screenshot of the interface:
11278 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11279 </para>
11280 </section>
11281 </section>
11282 </section>
11283
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011284 <section id="performing-automated-runtime-testing">
11285 <title>Performing Automated Runtime Testing</title>
11286
11287 <para>
11288 The OpenEmbedded build system makes available a series of automated
11289 tests for images to verify runtime functionality.
11290 You can run these tests on either QEMU or actual target hardware.
11291 Tests are written in Python making use of the
11292 <filename>unittest</filename> module, and the majority of them
11293 run commands on the target system over SSH.
11294 This section describes how you set up the environment to use these
11295 tests, run available tests, and write and add your own tests.
11296 </para>
11297
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011298 <para>
11299 For information on the test and QA infrastructure available
11300 within the Yocto Project, see the
11301 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11302 section in the Yocto Project Reference Manual.
11303 </para>
11304
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011305 <section id='enabling-tests'>
11306 <title>Enabling Tests</title>
11307
11308 <para>
11309 Depending on whether you are planning to run tests using
11310 QEMU or on the hardware, you have to take
11311 different steps to enable the tests.
11312 See the following subsections for information on how to
11313 enable both types of tests.
11314 </para>
11315
11316 <section id='qemu-image-enabling-tests'>
11317 <title>Enabling Runtime Tests on QEMU</title>
11318
11319 <para>
11320 In order to run tests, you need to do the following:
11321 <itemizedlist>
11322 <listitem><para><emphasis>Set up to avoid interaction
11323 with <filename>sudo</filename> for networking:</emphasis>
11324 To accomplish this, you must do one of the
11325 following:
11326 <itemizedlist>
11327 <listitem><para>Add
11328 <filename>NOPASSWD</filename> for your user
11329 in <filename>/etc/sudoers</filename> either for
11330 all commands or just for
11331 <filename>runqemu-ifup</filename>.
11332 You must provide the full path as that can
11333 change if you are using multiple clones of the
11334 source repository.
11335 <note>
11336 On some distributions, you also need to
11337 comment out "Defaults requiretty" in
11338 <filename>/etc/sudoers</filename>.
11339 </note></para></listitem>
11340 <listitem><para>Manually configure a tap interface
11341 for your system.</para></listitem>
11342 <listitem><para>Run as root the script in
11343 <filename>scripts/runqemu-gen-tapdevs</filename>,
11344 which should generate a list of tap devices.
11345 This is the option typically chosen for
11346 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011347 <note><title>Notes</title>
11348 <itemizedlist>
11349 <listitem><para>
11350 Be sure to use an absolute path
11351 when calling this script
11352 with sudo.
11353 </para></listitem>
11354 <listitem><para>
11355 The package recipe
11356 <filename>qemu-helper-native</filename>
11357 is required to run this script.
11358 Build the package using the
11359 following command:
11360 <literallayout class='monospaced'>
11361 $ bitbake qemu-helper-native
11362 </literallayout>
11363 </para></listitem>
11364 </itemizedlist>
11365 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011366 </para></listitem>
11367 </itemizedlist></para></listitem>
11368 <listitem><para><emphasis>Set the
11369 <filename>DISPLAY</filename> variable:</emphasis>
11370 You need to set this variable so that you have an X
11371 server available (e.g. start
11372 <filename>vncserver</filename> for a headless machine).
11373 </para></listitem>
11374 <listitem><para><emphasis>Be sure your host's firewall
11375 accepts incoming connections from
11376 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011377 Some of the tests (in particular DNF tests) start
11378 an HTTP server on a random high number port,
11379 which is used to serve files to the target.
11380 The DNF module serves
11381 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11382 so it can run DNF channel commands.
11383 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011384 must accept incoming connections from 192.168.7.0/24,
11385 which is the default IP range used for tap devices
11386 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011387 <listitem><para><emphasis>Be sure your host has the
11388 correct packages installed:</emphasis>
11389 Depending your host's distribution, you need
11390 to have the following packages installed:
11391 <itemizedlist>
11392 <listitem><para>Ubuntu and Debian:
11393 <filename>sysstat</filename> and
11394 <filename>iproute2</filename>
11395 </para></listitem>
11396 <listitem><para>OpenSUSE:
11397 <filename>sysstat</filename> and
11398 <filename>iproute2</filename>
11399 </para></listitem>
11400 <listitem><para>Fedora:
11401 <filename>sysstat</filename> and
11402 <filename>iproute</filename>
11403 </para></listitem>
11404 <listitem><para>CentOS:
11405 <filename>sysstat</filename> and
11406 <filename>iproute</filename>
11407 </para></listitem>
11408 </itemizedlist>
11409 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011410 </itemizedlist>
11411 </para>
11412
11413 <para>
11414 Once you start running the tests, the following happens:
11415 <orderedlist>
11416 <listitem><para>A copy of the root filesystem is written
11417 to <filename>${WORKDIR}/testimage</filename>.
11418 </para></listitem>
11419 <listitem><para>The image is booted under QEMU using the
11420 standard <filename>runqemu</filename> script.
11421 </para></listitem>
11422 <listitem><para>A default timeout of 500 seconds occurs
11423 to allow for the boot process to reach the login prompt.
11424 You can change the timeout period by setting
11425 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11426 in the <filename>local.conf</filename> file.
11427 </para></listitem>
11428 <listitem><para>Once the boot process is reached and the
11429 login prompt appears, the tests run.
11430 The full boot log is written to
11431 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11432 </para></listitem>
11433 <listitem><para>Each test module loads in the order found
11434 in <filename>TEST_SUITES</filename>.
11435 You can find the full output of the commands run over
11436 SSH in
11437 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11438 </para></listitem>
11439 <listitem><para>If no failures occur, the task running the
11440 tests ends successfully.
11441 You can find the output from the
11442 <filename>unittest</filename> in the task log at
11443 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11444 </para></listitem>
11445 </orderedlist>
11446 </para>
11447 </section>
11448
11449 <section id='hardware-image-enabling-tests'>
11450 <title>Enabling Runtime Tests on Hardware</title>
11451
11452 <para>
11453 The OpenEmbedded build system can run tests on real
11454 hardware, and for certain devices it can also deploy
11455 the image to be tested onto the device beforehand.
11456 </para>
11457
11458 <para>
11459 For automated deployment, a "master image" is installed
11460 onto the hardware once as part of setup.
11461 Then, each time tests are to be run, the following
11462 occurs:
11463 <orderedlist>
11464 <listitem><para>The master image is booted into and
11465 used to write the image to be tested to
11466 a second partition.
11467 </para></listitem>
11468 <listitem><para>The device is then rebooted using an
11469 external script that you need to provide.
11470 </para></listitem>
11471 <listitem><para>The device boots into the image to be
11472 tested.
11473 </para></listitem>
11474 </orderedlist>
11475 </para>
11476
11477 <para>
11478 When running tests (independent of whether the image
11479 has been deployed automatically or not), the device is
11480 expected to be connected to a network on a
11481 pre-determined IP address.
11482 You can either use static IP addresses written into
11483 the image, or set the image to use DHCP and have your
11484 DHCP server on the test network assign a known IP address
11485 based on the MAC address of the device.
11486 </para>
11487
11488 <para>
11489 In order to run tests on hardware, you need to set
11490 <filename>TEST_TARGET</filename> to an appropriate value.
11491 For QEMU, you do not have to change anything, the default
11492 value is "QemuTarget".
11493 For running tests on hardware, the following options exist:
11494 <itemizedlist>
11495 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11496 Choose "SimpleRemoteTarget" if you are going to
11497 run tests on a target system that is already
11498 running the image to be tested and is available
11499 on the network.
11500 You can use "SimpleRemoteTarget" in conjunction
11501 with either real hardware or an image running
11502 within a separately started QEMU or any
11503 other virtual machine manager.
11504 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011505 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
11506 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011507 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011508 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011509 <filename>core-image-testmaster</filename>
11510 (or something similar) is installed.
11511 Also, your hardware under test must be in a
11512 DHCP-enabled network that gives it the same IP
11513 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011514 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011515 additional requirements and considerations.
11516 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011517 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011518 section, which follows, for more information.
11519 </para></listitem>
11520 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
11521 Choose "BeagleBoneTarget" if you are deploying
11522 images and running tests on the BeagleBone
11523 "Black" or original "White" hardware.
11524 For information on how to use these tests, see the
11525 comments at the top of the BeagleBoneTarget
11526 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
11527 file.
11528 </para></listitem>
11529 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
11530 Choose "EdgeRouterTarget" is you are deploying
11531 images and running tests on the Ubiquiti Networks
11532 EdgeRouter Lite.
11533 For information on how to use these tests, see the
11534 comments at the top of the EdgeRouterTarget
11535 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
11536 file.
11537 </para></listitem>
11538 <listitem><para><emphasis>"GrubTarget":</emphasis>
11539 Choose the "supports deploying images and running
11540 tests on any generic PC that boots using GRUB.
11541 For information on how to use these tests, see the
11542 comments at the top of the GrubTarget
11543 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
11544 file.
11545 </para></listitem>
11546 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
11547 Create your own custom target if you want to run
11548 tests when you are deploying images and running
11549 tests on a custom machine within your BSP layer.
11550 To do this, you need to add a Python unit that
11551 defines the target class under
11552 <filename>lib/oeqa/controllers/</filename> within
11553 your layer.
11554 You must also provide an empty
11555 <filename>__init__.py</filename>.
11556 For examples, see files in
11557 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
11558 </para></listitem>
11559 </itemizedlist>
11560 </para>
11561 </section>
11562
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011563 <section id='selecting-systemdboottarget'>
11564 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011565
11566 <para>
11567 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011568 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011569 in this section.
11570 You can skip down to the
11571 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
11572 section.
11573 </para>
11574
11575 <para>
11576 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011577 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011578 setup of your master image by doing the following:
11579 <orderedlist>
11580 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
11581 Be sure that <filename>EFI_PROVIDER</filename>
11582 is as follows:
11583 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011584 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011585 </literallayout>
11586 </para></listitem>
11587 <listitem><para><emphasis>Build the master image:</emphasis>
11588 Build the <filename>core-image-testmaster</filename>
11589 image.
11590 The <filename>core-image-testmaster</filename>
11591 recipe is provided as an example for a
11592 "master" image and you can customize the image
11593 recipe as you would any other recipe.
11594 </para>
11595 <para>Here are the image recipe requirements:
11596 <itemizedlist>
11597 <listitem><para>Inherits
11598 <filename>core-image</filename>
11599 so that kernel modules are installed.
11600 </para></listitem>
11601 <listitem><para>Installs normal linux utilities
11602 not busybox ones (e.g.
11603 <filename>bash</filename>,
11604 <filename>coreutils</filename>,
11605 <filename>tar</filename>,
11606 <filename>gzip</filename>, and
11607 <filename>kmod</filename>).
11608 </para></listitem>
11609 <listitem><para>Uses a custom
11610 Initial RAM Disk (initramfs) image with a
11611 custom installer.
11612 A normal image that you can install usually
11613 creates a single rootfs partition.
11614 This image uses another installer that
11615 creates a specific partition layout.
11616 Not all Board Support Packages (BSPs)
11617 can use an installer.
11618 For such cases, you need to manually create
11619 the following partition layout on the
11620 target:
11621 <itemizedlist>
11622 <listitem><para>First partition mounted
11623 under <filename>/boot</filename>,
11624 labeled "boot".
11625 </para></listitem>
11626 <listitem><para>The main rootfs
11627 partition where this image gets
11628 installed, which is mounted under
11629 <filename>/</filename>.
11630 </para></listitem>
11631 <listitem><para>Another partition
11632 labeled "testrootfs" where test
11633 images get deployed.
11634 </para></listitem>
11635 </itemizedlist>
11636 </para></listitem>
11637 </itemizedlist>
11638 </para></listitem>
11639 <listitem><para><emphasis>Install image:</emphasis>
11640 Install the image that you just built on the target
11641 system.
11642 </para></listitem>
11643 </orderedlist>
11644 </para>
11645
11646 <para>
11647 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011648 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011649 to set up the test image:
11650 <orderedlist>
11651 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
11652 Make sure you have the following statements in
11653 your <filename>local.conf</filename> file:
11654 <literallayout class='monospaced'>
11655 IMAGE_FSTYPES += "tar.gz"
11656 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011657 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011658 TEST_TARGET_IP = "192.168.2.3"
11659 </literallayout>
11660 </para></listitem>
11661 <listitem><para><emphasis>Build your test image:</emphasis>
11662 Use BitBake to build the image:
11663 <literallayout class='monospaced'>
11664 $ bitbake core-image-sato
11665 </literallayout>
11666 </para></listitem>
11667 </orderedlist>
11668 </para>
11669 </section>
11670
11671 <section id='power-control'>
11672 <title>Power Control</title>
11673
11674 <para>
11675 For most hardware targets other than SimpleRemoteTarget,
11676 you can control power:
11677 <itemizedlist>
11678 <listitem><para>
11679 You can use
11680 <filename>TEST_POWERCONTROL_CMD</filename>
11681 together with
11682 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11683 as a command that runs on the host and does power
11684 cycling.
11685 The test code passes one argument to that command:
11686 off, on or cycle (off then on).
11687 Here is an example that could appear in your
11688 <filename>local.conf</filename> file:
11689 <literallayout class='monospaced'>
11690 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
11691 </literallayout>
11692 In this example, the expect script does the
11693 following:
11694 <literallayout class='monospaced'>
11695 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
11696 </literallayout>
11697 It then runs a Python script that controls power
11698 for a label called <filename>nuc1</filename>.
11699 <note>
11700 You need to customize
11701 <filename>TEST_POWERCONTROL_CMD</filename>
11702 and
11703 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
11704 for your own setup.
11705 The one requirement is that it accepts
11706 "on", "off", and "cycle" as the last argument.
11707 </note>
11708 </para></listitem>
11709 <listitem><para>
11710 When no command is defined, it connects to the
11711 device over SSH and uses the classic reboot command
11712 to reboot the device.
11713 Classic reboot is fine as long as the machine
11714 actually reboots (i.e. the SSH test has not
11715 failed).
11716 It is useful for scenarios where you have a simple
11717 setup, typically with a single board, and where
11718 some manual interaction is okay from time to time.
11719 </para></listitem>
11720 </itemizedlist>
11721 If you have no hardware to automatically perform power
11722 control but still wish to experiment with automated
11723 hardware testing, you can use the dialog-power-control
11724 script that shows a dialog prompting you to perform the
11725 required power action.
11726 This script requires either KDialog or Zenity to be
11727 installed.
11728 To use this script, set the
11729 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
11730 variable as follows:
11731 <literallayout class='monospaced'>
11732 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
11733 </literallayout>
11734 </para>
11735 </section>
11736
11737 <section id='serial-console-connection'>
11738 <title>Serial Console Connection</title>
11739
11740 <para>
11741 For test target classes requiring a serial console
11742 to interact with the bootloader (e.g. BeagleBoneTarget,
11743 EdgeRouterTarget, and GrubTarget), you need to
11744 specify a command to use to connect to the serial console
11745 of the target machine by using the
11746 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
11747 variable and optionally the
11748 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
11749 variable.
11750 </para>
11751
11752 <para>
11753 These cases could be a serial terminal program if the
11754 machine is connected to a local serial port, or a
11755 <filename>telnet</filename> or
11756 <filename>ssh</filename> command connecting to a remote
11757 console server.
11758 Regardless of the case, the command simply needs to
11759 connect to the serial console and forward that connection
11760 to standard input and output as any normal terminal
11761 program does.
11762 For example, to use the picocom terminal program on
11763 serial device <filename>/dev/ttyUSB0</filename>
11764 at 115200bps, you would set the variable as follows:
11765 <literallayout class='monospaced'>
11766 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
11767 </literallayout>
11768 For local devices where the serial port device disappears
11769 when the device reboots, an additional "serdevtry" wrapper
11770 script is provided.
11771 To use this wrapper, simply prefix the terminal command
11772 with
11773 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
11774 <literallayout class='monospaced'>
11775 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
11776115200 /dev/ttyUSB0"
11777 </literallayout>
11778 </para>
11779 </section>
11780 </section>
11781
11782 <section id="qemu-image-running-tests">
11783 <title>Running Tests</title>
11784
11785 <para>
11786 You can start the tests automatically or manually:
11787 <itemizedlist>
11788 <listitem><para><emphasis>Automatically running tests:</emphasis>
11789 To run the tests automatically after the
11790 OpenEmbedded build system successfully creates an image,
11791 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011792 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011793 variable to "1" in your <filename>local.conf</filename>
11794 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011795 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011796 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011797 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011798 </literallayout>
11799 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011800 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011801 <literallayout class='monospaced'>
11802 bitbake core-image-sato
11803 </literallayout></para></listitem>
11804 <listitem><para><emphasis>Manually running tests:</emphasis>
11805 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011806 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011807 class by editing your <filename>local.conf</filename>
11808 file:
11809 <literallayout class='monospaced'>
11810 INHERIT += "testimage"
11811 </literallayout>
11812 Next, use BitBake to run the tests:
11813 <literallayout class='monospaced'>
11814 bitbake -c testimage <replaceable>image</replaceable>
11815 </literallayout></para></listitem>
11816 </itemizedlist>
11817 </para>
11818
11819 <para>
11820 All test files reside in
11821 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011822 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011823 A test name maps directly to a Python module.
11824 Each test module may contain a number of individual tests.
11825 Tests are usually grouped together by the area
11826 tested (e.g tests for systemd reside in
11827 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
11828 </para>
11829
11830 <para>
11831 You can add tests to any layer provided you place them in the
11832 proper area and you extend
11833 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
11834 in the <filename>local.conf</filename> file as normal.
11835 Be sure that tests reside in
11836 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
11837 <note>
11838 Be sure that module names do not collide with module names
11839 used in the default set of test modules in
11840 <filename>meta/lib/oeqa/runtime</filename>.
11841 </note>
11842 </para>
11843
11844 <para>
11845 You can change the set of tests run by appending or overriding
11846 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
11847 variable in <filename>local.conf</filename>.
11848 Each name in <filename>TEST_SUITES</filename> represents a
11849 required test for the image.
11850 Test modules named within <filename>TEST_SUITES</filename>
11851 cannot be skipped even if a test is not suitable for an image
11852 (e.g. running the RPM tests on an image without
11853 <filename>rpm</filename>).
11854 Appending "auto" to <filename>TEST_SUITES</filename> causes the
11855 build system to try to run all tests that are suitable for the
11856 image (i.e. each test module may elect to skip itself).
11857 </para>
11858
11859 <para>
11860 The order you list tests in <filename>TEST_SUITES</filename>
11861 is important and influences test dependencies.
11862 Consequently, tests that depend on other tests should be added
11863 after the test on which they depend.
11864 For example, since the <filename>ssh</filename> test
11865 depends on the
11866 <filename>ping</filename> test, "ssh" needs to come after
11867 "ping" in the list.
11868 The test class provides no re-ordering or dependency handling.
11869 <note>
11870 Each module can have multiple classes with multiple test
11871 methods.
11872 And, Python <filename>unittest</filename> rules apply.
11873 </note>
11874 </para>
11875
11876 <para>
11877 Here are some things to keep in mind when running tests:
11878 <itemizedlist>
11879 <listitem><para>The default tests for the image are defined
11880 as:
11881 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011882 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 -050011883 </literallayout></para></listitem>
11884 <listitem><para>Add your own test to the list of the
11885 by using the following:
11886 <literallayout class='monospaced'>
11887 TEST_SUITES_append = " mytest"
11888 </literallayout></para></listitem>
11889 <listitem><para>Run a specific list of tests as follows:
11890 <literallayout class='monospaced'>
11891 TEST_SUITES = "test1 test2 test3"
11892 </literallayout>
11893 Remember, order is important.
11894 Be sure to place a test that is dependent on another test
11895 later in the order.</para></listitem>
11896 </itemizedlist>
11897 </para>
11898 </section>
11899
11900 <section id="exporting-tests">
11901 <title>Exporting Tests</title>
11902
11903 <para>
11904 You can export tests so that they can run independently of
11905 the build system.
11906 Exporting tests is required if you want to be able to hand
11907 the test execution off to a scheduler.
11908 You can only export tests that are defined in
11909 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
11910 </para>
11911
11912 <para>
11913 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011914 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011915 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011916 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011917 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
11918 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011919 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011920 You can then export the tests with the following BitBake
11921 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011922 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011923 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011924 </literallayout>
11925 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011926 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
11927 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011928 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
11929 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011930 <filename>TEST_EXPORT_DIR</filename> variable.
11931 </para>
11932
11933 <para>
11934 You can now run the tests outside of the build environment:
11935 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011936 $ cd tmp/testexport/<replaceable>image</replaceable>
11937 $ ./runexported.py testdata.json
11938 </literallayout>
11939 </para>
11940
11941 <para>
11942 Here is a complete example that shows IP addresses and uses
11943 the <filename>core-image-sato</filename> image:
11944 <literallayout class='monospaced'>
11945 INHERIT +="testexport"
11946 TEST_TARGET_IP = "192.168.7.2"
11947 TEST_SERVER_IP = "192.168.7.1"
11948 </literallayout>
11949 Use BitBake to export the tests:
11950 <literallayout class='monospaced'>
11951 $ bitbake core-image-sato -c testexport
11952 </literallayout>
11953 Run the tests outside of the build environment using the
11954 following:
11955 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011956 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011957 $ ./runexported.py testdata.json
11958 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011959 </para>
11960 </section>
11961
11962 <section id="qemu-image-writing-new-tests">
11963 <title>Writing New Tests</title>
11964
11965 <para>
11966 As mentioned previously, all new test files need to be in the
11967 proper place for the build system to find them.
11968 New tests for additional functionality outside of the core
11969 should be added to the layer that adds the functionality, in
11970 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
11971 (as long as
11972 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
11973 is extended in the layer's
11974 <filename>layer.conf</filename> file as normal).
11975 Just remember the following:
11976 <itemizedlist>
11977 <listitem><para>Filenames need to map directly to test
11978 (module) names.
11979 </para></listitem>
11980 <listitem><para>Do not use module names that
11981 collide with existing core tests.
11982 </para></listitem>
11983 <listitem><para>Minimally, an empty
11984 <filename>__init__.py</filename> file must exist
11985 in the runtime directory.
11986 </para></listitem>
11987 </itemizedlist>
11988 </para>
11989
11990 <para>
11991 To create a new test, start by copying an existing module
11992 (e.g. <filename>syslog.py</filename> or
11993 <filename>gcc.py</filename> are good ones to use).
11994 Test modules can use code from
11995 <filename>meta/lib/oeqa/utils</filename>, which are helper
11996 classes.
11997 </para>
11998
11999 <note>
12000 Structure shell commands such that you rely on them and they
12001 return a single code for success.
12002 Be aware that sometimes you will need to parse the output.
12003 See the <filename>df.py</filename> and
12004 <filename>date.py</filename> modules for examples.
12005 </note>
12006
12007 <para>
12008 You will notice that all test classes inherit
12009 <filename>oeRuntimeTest</filename>, which is found in
12010 <filename>meta/lib/oetest.py</filename>.
12011 This base class offers some helper attributes, which are
12012 described in the following sections:
12013 </para>
12014
12015 <section id='qemu-image-writing-tests-class-methods'>
12016 <title>Class Methods</title>
12017
12018 <para>
12019 Class methods are as follows:
12020 <itemizedlist>
12021 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12022 Returns "True" if <filename>pkg</filename> is in the
12023 installed package list of the image, which is based
12024 on the manifest file that is generated during the
12025 <filename>do_rootfs</filename> task.
12026 </para></listitem>
12027 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12028 Returns "True" if the feature is in
12029 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12030 or
12031 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12032 </para></listitem>
12033 </itemizedlist>
12034 </para>
12035 </section>
12036
12037 <section id='qemu-image-writing-tests-class-attributes'>
12038 <title>Class Attributes</title>
12039
12040 <para>
12041 Class attributes are as follows:
12042 <itemizedlist>
12043 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12044 Equals "ps -ef" if <filename>procps</filename> is
12045 installed in the image.
12046 Otherwise, <filename>pscmd</filename> equals
12047 "ps" (busybox).
12048 </para></listitem>
12049 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12050 The called test context, which gives access to the
12051 following attributes:
12052 <itemizedlist>
12053 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12054 The BitBake datastore, which allows you to
12055 use stuff such as
12056 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12057 </para></listitem>
12058 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12059 Used internally.
12060 The tests do not need these.
12061 </para></listitem>
12062 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12063 The absolute path to
12064 <filename>meta/lib/oeqa/runtime/files</filename>,
12065 which contains helper files for tests meant
12066 for copying on the target such as small
12067 files written in C for compilation.
12068 </para></listitem>
12069 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12070 The target controller object used to deploy
12071 and start an image on a particular target
12072 (e.g. QemuTarget, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012073 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012074 Tests usually use the following:
12075 <itemizedlist>
12076 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12077 The target's IP address.
12078 </para></listitem>
12079 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12080 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012081 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012082 suite.
12083 </para></listitem>
12084 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12085 The single, most used method.
12086 This command is a wrapper for:
12087 <filename>ssh root@host "cmd"</filename>.
12088 The command returns a tuple:
12089 (status, output), which are what
12090 their names imply - the return code
12091 of "cmd" and whatever output
12092 it produces.
12093 The optional timeout argument
12094 represents the number of seconds the
12095 test should wait for "cmd" to
12096 return.
12097 If the argument is "None", the
12098 test uses the default instance's
12099 timeout period, which is 300
12100 seconds.
12101 If the argument is "0", the test
12102 runs until the command returns.
12103 </para></listitem>
12104 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12105 <filename>scp localpath root@ip:remotepath</filename>.
12106 </para></listitem>
12107 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12108 <filename>scp root@host:remotepath localpath</filename>.
12109 </para></listitem>
12110 </itemizedlist></para></listitem>
12111 </itemizedlist></para></listitem>
12112 </itemizedlist>
12113 </para>
12114 </section>
12115
12116 <section id='qemu-image-writing-tests-instance-attributes'>
12117 <title>Instance Attributes</title>
12118
12119 <para>
12120 A single instance attribute exists, which is
12121 <filename>target</filename>.
12122 The <filename>target</filename> instance attribute is
12123 identical to the class attribute of the same name, which
12124 is described in the previous section.
12125 This attribute exists as both an instance and class
12126 attribute so tests can use
12127 <filename>self.target.run(cmd)</filename> in instance
12128 methods instead of
12129 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12130 </para>
12131 </section>
12132 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012133
12134 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12135 <title>Installing Packages in the DUT Without the Package Manager</title>
12136
12137 <para>
12138 When a test requires a package built by BitBake, it is possible
12139 to install that package.
12140 Installing the package does not require a package manager be
12141 installed in the device under test (DUT).
12142 It does, however, require an SSH connection and the target must
12143 be using the <filename>sshcontrol</filename> class.
12144 <note>
12145 This method uses <filename>scp</filename> to copy files
12146 from the host to the target, which causes permissions and
12147 special attributes to be lost.
12148 </note>
12149 </para>
12150
12151 <para>
12152 A JSON file is used to define the packages needed by a test.
12153 This file must be in the same path as the file used to define
12154 the tests.
12155 Furthermore, the filename must map directly to the test
12156 module name with a <filename>.json</filename> extension.
12157 </para>
12158
12159 <para>
12160 The JSON file must include an object with the test name as
12161 keys of an object or an array.
12162 This object (or array of objects) uses the following data:
12163 <itemizedlist>
12164 <listitem><para>"pkg" - A mandatory string that is the
12165 name of the package to be installed.
12166 </para></listitem>
12167 <listitem><para>"rm" - An optional boolean, which defaults
12168 to "false", that specifies to remove the package after
12169 the test.
12170 </para></listitem>
12171 <listitem><para>"extract" - An optional boolean, which
12172 defaults to "false", that specifies if the package must
12173 be extracted from the package format.
12174 When set to "true", the package is not automatically
12175 installed into the DUT.
12176 </para></listitem>
12177 </itemizedlist>
12178 </para>
12179
12180 <para>
12181 Following is an example JSON file that handles test "foo"
12182 installing package "bar" and test "foobar" installing
12183 packages "foo" and "bar".
12184 Once the test is complete, the packages are removed from the
12185 DUT.
12186 <literallayout class='monospaced'>
12187 {
12188 "foo": {
12189 "pkg": "bar"
12190 },
12191 "foobar": [
12192 {
12193 "pkg": "foo",
12194 "rm": true
12195 },
12196 {
12197 "pkg": "bar",
12198 "rm": true
12199 }
12200 ]
12201 }
12202 </literallayout>
12203 </para>
12204 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012205 </section>
12206
Brad Bishop316dfdd2018-06-25 12:45:53 -040012207 <section id='usingpoky-debugging-tools-and-techniques'>
12208 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012209
12210 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012211 The exact method for debugging build failures depends on the nature
12212 of the problem and on the system's area from which the bug
12213 originates.
12214 Standard debugging practices such as comparison against the last
12215 known working version with examination of the changes and the
12216 re-application of steps to identify the one causing the problem are
12217 valid for the Yocto Project just as they are for any other system.
12218 Even though it is impossible to detail every possible potential
12219 failure, this section provides some general tips to aid in
12220 debugging given a variety of situations.
12221 <note><title>Tip</title>
12222 A useful feature for debugging is the error reporting tool.
12223 Configuring the Yocto Project to use this tool causes the
12224 OpenEmbedded build system to produce error reporting commands as
12225 part of the console output.
12226 You can enter the commands after the build completes to log
12227 error information into a common database, that can help you
12228 figure out what might be going wrong.
12229 For information on how to enable and use this feature, see the
12230 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12231 section.
12232 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012233 </para>
12234
12235 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012236 The following list shows the debugging topics in the remainder of
12237 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012238 <itemizedlist>
12239 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012240 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12241 describes how to find and view logs from tasks that
12242 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012243 </para></listitem>
12244 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012245 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12246 describes how to use the BitBake <filename>-e</filename>
12247 option to examine variable values after a recipe has been
12248 parsed.
12249 </para></listitem>
12250 <listitem><para>
12251 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12252 describes how to use the
12253 <filename>oe-pkgdata-util</filename> utility to query
12254 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12255 and display package-related information for built
12256 packages.
12257 </para></listitem>
12258 <listitem><para>
12259 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12260 describes how to use the BitBake <filename>-g</filename>
12261 option to display recipe dependency information used
12262 during the build.
12263 </para></listitem>
12264 <listitem><para>
12265 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12266 describes how to use the
12267 <filename>bitbake-dumpsig</filename> command in
12268 conjunction with key subdirectories in the
12269 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12270 to determine variable dependencies.
12271 </para></listitem>
12272 <listitem><para>
12273 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12274 describes how to use several BitBake options (e.g.
12275 <filename>-c</filename>, <filename>-C</filename>, and
12276 <filename>-f</filename>) to run specific tasks in the
12277 build chain.
12278 It can be useful to run tasks "out-of-order" when trying
12279 isolate build issues.
12280 </para></listitem>
12281 <listitem><para>
12282 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12283 describes how to use BitBake's <filename>-D</filename>
12284 debug output option to reveal more about what BitBake is
12285 doing during the build.
12286 </para></listitem>
12287 <listitem><para>
12288 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12289 describes how to use the BitBake <filename>-b</filename>
12290 option to build a recipe while ignoring dependencies.
12291 </para></listitem>
12292 <listitem><para>
12293 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12294 describes how to use the many recipe logging functions
12295 to produce debugging output and report errors and warnings.
12296 </para></listitem>
12297 <listitem><para>
12298 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12299 describes how to debug situations where the build consists
12300 of several parts that are run simultaneously and when the
12301 output or result of one part is not ready for use with a
12302 different part of the build that depends on that output.
12303 </para></listitem>
12304 <listitem><para>
12305 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12306 describes how to use GDB to allow you to examine running
12307 programs, which can help you fix problems.
12308 </para></listitem>
12309 <listitem><para>
12310 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12311 describes how to use GDB directly on target hardware for
12312 debugging.
12313 </para></listitem>
12314 <listitem><para>
12315 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12316 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012317 </para></listitem>
12318 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012319 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012320
12321 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012322 For debugging information within the popular
12323 <trademark class='trade'>Eclipse</trademark> IDE, see the
12324 "<ulink url='&YOCTO_DOCS_SDK_URL;#adt-eclipse'>Working within Eclipse</ulink>"
12325 section in the Yocto Project Application Development and the
12326 Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012327 </para>
12328
Brad Bishop316dfdd2018-06-25 12:45:53 -040012329 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12330 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012331
12332 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012333 You can find the log for a task in the file
12334 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12335 For example, the log for the
12336 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12337 task of the QEMU minimal image for the x86 machine
12338 (<filename>qemux86</filename>) might be in
12339 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12340 To see the commands
12341 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12342 ran to generate a log, look at the corresponding
12343 <filename>run.do_</filename><replaceable>taskname</replaceable>
12344 file in the same directory.
12345 </para>
12346
12347 <para>
12348 <filename>log.do_</filename><replaceable>taskname</replaceable>
12349 and
12350 <filename>run.do_</filename><replaceable>taskname</replaceable>
12351 are actually symbolic links to
12352 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12353 and
12354 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12355 where <replaceable>pid</replaceable> is the PID the task had
12356 when it ran.
12357 The symlinks always point to the files corresponding to the most
12358 recent run.
12359 </para>
12360 </section>
12361
12362 <section id='dev-debugging-viewing-variable-values'>
12363 <title>Viewing Variable Values</title>
12364
12365 <para>
12366 BitBake's <filename>-e</filename> option is used to display
12367 variable values after parsing.
12368 The following command displays the variable values after the
12369 configuration files (i.e. <filename>local.conf</filename>,
12370 <filename>bblayers.conf</filename>,
12371 <filename>bitbake.conf</filename> and so forth) have been
12372 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012373 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012374 $ bitbake -e
12375 </literallayout>
12376 The following command displays variable values after a specific
12377 recipe has been parsed.
12378 The variables include those from the configuration as well:
12379 <literallayout class='monospaced'>
12380 $ bitbake -e recipename
12381 </literallayout>
12382 <note><para>
12383 Each recipe has its own private set of variables
12384 (datastore).
12385 Internally, after parsing the configuration, a copy of the
12386 resulting datastore is made prior to parsing each recipe.
12387 This copying implies that variables set in one recipe will
12388 not be visible to other recipes.</para>
12389
12390 <para>Likewise, each task within a recipe gets a private
12391 datastore based on the recipe datastore, which means that
12392 variables set within one task will not be visible to
12393 other tasks.</para>
12394 </note>
12395 </para>
12396
12397 <para>
12398 In the output of <filename>bitbake -e</filename>, each
12399 variable is preceded by a description of how the variable
12400 got its value, including temporary values that were later
12401 overriden.
12402 This description also includes variable flags (varflags) set on
12403 the variable.
12404 The output can be very helpful during debugging.
12405 </para>
12406
12407 <para>
12408 Variables that are exported to the environment are preceded by
12409 <filename>export</filename> in the output of
12410 <filename>bitbake -e</filename>.
12411 See the following example:
12412 <literallayout class='monospaced'>
12413 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12414 </literallayout>
12415 </para>
12416
12417 <para>
12418 In addition to variable values, the output of the
12419 <filename>bitbake -e</filename> and
12420 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12421 commands includes the following information:
12422 <itemizedlist>
12423 <listitem><para>
12424 The output starts with a tree listing all configuration
12425 files and classes included globally, recursively listing
12426 the files they include or inherit in turn.
12427 Much of the behavior of the OpenEmbedded build system
12428 (including the behavior of the
12429 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12430 is implemented in the
12431 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12432 class and the classes it inherits, rather than being
12433 built into BitBake itself.
12434 </para></listitem>
12435 <listitem><para>
12436 After the variable values, all functions appear in the
12437 output.
12438 For shell functions, variables referenced within the
12439 function body are expanded.
12440 If a function has been modified using overrides or
12441 using override-style operators like
12442 <filename>_append</filename> and
12443 <filename>_prepend</filename>, then the final assembled
12444 function body appears in the output.
12445 </para></listitem>
12446 </itemizedlist>
12447 </para>
12448 </section>
12449
12450 <section id='viewing-package-information-with-oe-pkgdata-util'>
12451 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12452
12453 <para>
12454 You can use the <filename>oe-pkgdata-util</filename>
12455 command-line utility to query
12456 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12457 and display various package-related information.
12458 When you use the utility, you must use it to view information
12459 on packages that have already been built.
12460 </para>
12461
12462 <para>
12463 Following are a few of the available
12464 <filename>oe-pkgdata-util</filename> subcommands.
12465 <note>
12466 You can use the standard * and ? globbing wildcards as part
12467 of package names and paths.
12468 </note>
12469 <itemizedlist>
12470 <listitem><para>
12471 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12472 Lists all packages that have been built, optionally
12473 limiting the match to packages that match
12474 <replaceable>pattern</replaceable>.
12475 </para></listitem>
12476 <listitem><para>
12477 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12478 Lists the files and directories contained in the given
12479 packages.
12480 <note>
12481 <para>
12482 A different way to view the contents of a package is
12483 to look at the
12484 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12485 directory of the recipe that generates the
12486 package.
12487 This directory is created by the
12488 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12489 task and has one subdirectory for each package the
12490 recipe generates, which contains the files stored in
12491 that package.</para>
12492 <para>
12493 If you want to inspect the
12494 <filename>${WORKDIR}/packages-split</filename>
12495 directory, make sure that
12496 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12497 is not enabled when you build the recipe.
12498 </para>
12499 </note>
12500 </para></listitem>
12501 <listitem><para>
12502 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12503 Lists the names of the packages that contain the given
12504 paths.
12505 For example, the following tells us that
12506 <filename>/usr/share/man/man1/make.1</filename>
12507 is contained in the <filename>make-doc</filename>
12508 package:
12509 <literallayout class='monospaced'>
12510 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12511 make-doc: /usr/share/man/man1/make.1
12512 </literallayout>
12513 </para></listitem>
12514 <listitem><para>
12515 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12516 Lists the name of the recipes that
12517 produce the given packages.
12518 </para></listitem>
12519 </itemizedlist>
12520 </para>
12521
12522 <para>
12523 For more information on the <filename>oe-pkgdata-util</filename>
12524 command, use the help facility:
12525 <literallayout class='monospaced'>
12526 $ oe-pkgdata-util &dash;&dash;help
12527 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
12528 </literallayout>
12529 </para>
12530 </section>
12531
12532 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
12533 <title>Viewing Dependencies Between Recipes and Tasks</title>
12534
12535 <para>
12536 Sometimes it can be hard to see why BitBake wants to build other
12537 recipes before the one you have specified.
12538 Dependency information can help you understand why a recipe is
12539 built.
12540 </para>
12541
12542 <para>
12543 To generate dependency information for a recipe, run the
12544 following command:
12545 <literallayout class='monospaced'>
12546 $ bitbake -g <replaceable>recipename</replaceable>
12547 </literallayout>
12548 This command writes the following files in the current
12549 directory:
12550 <itemizedlist>
12551 <listitem><para>
12552 <filename>pn-buildlist</filename>: A list of
12553 recipes/targets involved in building
12554 <replaceable>recipename</replaceable>.
12555 "Involved" here means that at least one task from the
12556 recipe needs to run when building
12557 <replaceable>recipename</replaceable> from scratch.
12558 Targets that are in
12559 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
12560 are not listed.
12561 </para></listitem>
12562 <listitem><para>
12563 <filename>task-depends.dot</filename>: A graph showing
12564 dependencies between tasks.
12565 </para></listitem>
12566 </itemizedlist>
12567 </para>
12568
12569 <para>
12570 The graphs are in
12571 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
12572 format and can be converted to images (e.g. using the
12573 <filename>dot</filename> tool from
12574 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
12575 <note><title>Notes</title>
12576 <itemizedlist>
12577 <listitem><para>
12578 DOT files use a plain text format.
12579 The graphs generated using the
12580 <filename>bitbake -g</filename> command are often so
12581 large as to be difficult to read without special
12582 pruning (e.g. with Bitbake's
12583 <filename>-I</filename> option) and processing.
12584 Despite the form and size of the graphs, the
12585 corresponding <filename>.dot</filename> files can
12586 still be possible to read and provide useful
12587 information.
12588 </para>
12589
12590 <para>As an example, the
12591 <filename>task-depends.dot</filename> file contains
12592 lines such as the following:
12593 <literallayout class='monospaced'>
12594 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
12595 </literallayout>
12596 The above example line reveals that the
12597 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
12598 task in <filename>libxslt</filename> depends on the
12599 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
12600 task in <filename>libxml2</filename>, which is a
12601 normal
12602 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
12603 dependency between the two recipes.
12604 </para></listitem>
12605 <listitem><para>
12606 For an example of how <filename>.dot</filename>
12607 files can be processed, see the
12608 <filename>scripts/contrib/graph-tool</filename>
12609 Python script, which finds and displays paths
12610 between graph nodes.
12611 </para></listitem>
12612 </itemizedlist>
12613 </note>
12614 </para>
12615
12616 <para>
12617 You can use a different method to view dependency information
12618 by using the following command:
12619 <literallayout class='monospaced'>
12620 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
12621 </literallayout>
12622 This command displays a GUI window from which you can view
12623 build-time and runtime dependencies for the recipes involved in
12624 building <replaceable>recipename</replaceable>.
12625 </para>
12626 </section>
12627
12628 <section id='dev-viewing-task-variable-dependencies'>
12629 <title>Viewing Task Variable Dependencies</title>
12630
12631 <para>
12632 As mentioned in the
12633 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
12634 section of the BitBake User Manual, BitBake tries to
12635 automatically determine what variables a task depends on so
12636 that it can rerun the task if any values of the variables
12637 change.
12638 This determination is usually reliable.
12639 However, if you do things like construct variable names at
12640 runtime, then you might have to manually declare dependencies
12641 on those variables using <filename>vardeps</filename> as
12642 described in the
12643 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
12644 section of the BitBake User Manual.
12645 </para>
12646
12647 <para>
12648 If you are unsure whether a variable dependency is being
12649 picked up automatically for a given task, you can list the
12650 variable dependencies BitBake has determined by doing the
12651 following:
12652 <orderedlist>
12653 <listitem><para>
12654 Build the recipe containing the task:
12655 <literallayout class='monospaced'>
12656 $ bitbake <replaceable>recipename</replaceable>
12657 </literallayout>
12658 </para></listitem>
12659 <listitem><para>
12660 Inside the
12661 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
12662 directory, find the signature data
12663 (<filename>sigdata</filename>) file that corresponds
12664 to the task.
12665 The <filename>sigdata</filename> files contain a pickled
12666 Python database of all the metadata that went into
12667 creating the input checksum for the task.
12668 As an example, for the
12669 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
12670 task of the <filename>db</filename> recipe, the
12671 <filename>sigdata</filename> file might be found in the
12672 following location:
12673 <literallayout class='monospaced'>
12674 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12675 </literallayout>
12676 For tasks that are accelerated through the shared state
12677 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
12678 cache, an additional <filename>siginfo</filename> file
12679 is written into
12680 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
12681 along with the cached task output.
12682 The <filename>siginfo</filename> files contain exactly
12683 the same information as <filename>sigdata</filename>
12684 files.
12685 </para></listitem>
12686 <listitem><para>
12687 Run <filename>bitbake-dumpsig</filename> on the
12688 <filename>sigdata</filename> or
12689 <filename>siginfo</filename> file.
12690 Here is an example:
12691 <literallayout class='monospaced'>
12692 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
12693 </literallayout>
12694 In the output of the above command, you will find a
12695 line like the following, which lists all the (inferred)
12696 variable dependencies for the task.
12697 This list also includes indirect dependencies from
12698 variables depending on other variables, recursively.
12699 <literallayout class='monospaced'>
12700 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
12701 </literallayout>
12702 <note>
12703 Functions (e.g. <filename>base_do_fetch</filename>)
12704 also count as variable dependencies.
12705 These functions in turn depend on the variables they
12706 reference.
12707 </note>
12708 The output of <filename>bitbake-dumpsig</filename> also
12709 includes the value each variable had, a list of
12710 dependencies for each variable, and
12711 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
12712 information.
12713 </para></listitem>
12714 </orderedlist>
12715 </para>
12716
12717 <para>
12718 There is also a <filename>bitbake-diffsigs</filename> command
12719 for comparing two <filename>siginfo</filename> or
12720 <filename>sigdata</filename> files.
12721 This command can be helpful when trying to figure out what
12722 changed between two versions of a task.
12723 If you call <filename>bitbake-diffsigs</filename> with just one
12724 file, the command behaves like
12725 <filename>bitbake-dumpsig</filename>.
12726 </para>
12727
12728 <para>
12729 You can also use BitBake to dump out the signature construction
12730 information without executing tasks by using either of the
12731 following BitBake command-line options:
12732 <literallayout class='monospaced'>
12733 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
12734 -S <replaceable>SIGNATURE_HANDLER</replaceable>
12735 </literallayout>
12736 <note>
12737 Two common values for
12738 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
12739 "printdiff", which dump only the signature or compare the
12740 dumped signature with the cached one, respectively.
12741 </note>
12742 Using BitBake with either of these options causes BitBake to
12743 dump out <filename>sigdata</filename> files in the
12744 <filename>stamps</filename> directory for every task it would
12745 have executed instead of building the specified target package.
12746 </para>
12747 </section>
12748
12749 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
12750 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
12751
12752 <para>
12753 Seeing what metadata went into creating the input signature
12754 of a shared state (sstate) task can be a useful debugging
12755 aid.
12756 This information is available in signature information
12757 (<filename>siginfo</filename>) files in
12758 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
12759 For information on how to view and interpret information in
12760 <filename>siginfo</filename> files, see the
12761 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12762 section.
12763 </para>
12764
12765 <para>
12766 For conceptual information on shared state, see the
12767 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
12768 section in the Yocto Project Overview and Concepts Manual.
12769 </para>
12770 </section>
12771
12772 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
12773 <title>Invalidating Shared State to Force a Task to Run</title>
12774
12775 <para>
12776 The OpenEmbedded build system uses
12777 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
12778 and
12779 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
12780 cache to avoid unnecessarily rebuilding tasks.
12781 Collectively, this scheme is known as "shared state code."
12782 </para>
12783
12784 <para>
12785 As with all schemes, this one has some drawbacks.
12786 It is possible that you could make implicit changes to your
12787 code that the checksum calculations do not take into
12788 account.
12789 These implicit changes affect a task's output but do not
12790 trigger the shared state code into rebuilding a recipe.
12791 Consider an example during which a tool changes its output.
12792 Assume that the output of <filename>rpmdeps</filename>
12793 changes.
12794 The result of the change should be that all the
12795 <filename>package</filename> and
12796 <filename>package_write_rpm</filename> shared state cache
12797 items become invalid.
12798 However, because the change to the output is
12799 external to the code and therefore implicit,
12800 the associated shared state cache items do not become
12801 invalidated.
12802 In this case, the build process uses the cached items
12803 rather than running the task again.
12804 Obviously, these types of implicit changes can cause
12805 problems.
12806 </para>
12807
12808 <para>
12809 To avoid these problems during the build, you need to
12810 understand the effects of any changes you make.
12811 Realize that changes you make directly to a function
12812 are automatically factored into the checksum calculation.
12813 Thus, these explicit changes invalidate the associated
12814 area of shared state cache.
12815 However, you need to be aware of any implicit changes that
12816 are not obvious changes to the code and could affect
12817 the output of a given task.
12818 </para>
12819
12820 <para>
12821 When you identify an implicit change, you can easily
12822 take steps to invalidate the cache and force the tasks
12823 to run.
12824 The steps you can take are as simple as changing a
12825 function's comments in the source code.
12826 For example, to invalidate package shared state files,
12827 change the comment statements of
12828 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12829 or the comments of one of the functions it calls.
12830 Even though the change is purely cosmetic, it causes the
12831 checksum to be recalculated and forces the build system to
12832 run the task again.
12833 <note>
12834 For an example of a commit that makes a cosmetic
12835 change to invalidate shared state, see this
12836 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
12837 </note>
12838 </para>
12839 </section>
12840
12841 <section id='dev-debugging-taskrunning'>
12842 <title>Running Specific Tasks</title>
12843
12844 <para>
12845 Any given recipe consists of a set of tasks.
12846 The standard BitBake behavior in most cases is:
12847 <filename>do_fetch</filename>,
12848 <filename>do_unpack</filename>,
12849 <filename>do_patch</filename>,
12850 <filename>do_configure</filename>,
12851 <filename>do_compile</filename>,
12852 <filename>do_install</filename>,
12853 <filename>do_package</filename>,
12854 <filename>do_package_write_*</filename>, and
12855 <filename>do_build</filename>.
12856 The default task is <filename>do_build</filename> and any tasks
12857 on which it depends build first.
12858 Some tasks, such as <filename>do_devshell</filename>, are not
12859 part of the default build chain.
12860 If you wish to run a task that is not part of the default build
12861 chain, you can use the <filename>-c</filename> option in
12862 BitBake.
12863 Here is an example:
12864 <literallayout class='monospaced'>
12865 $ bitbake matchbox-desktop -c devshell
12866 </literallayout>
12867 </para>
12868
12869 <para>
12870 The <filename>-c</filename> option respects task dependencies,
12871 which means that all other tasks (including tasks from other
12872 recipes) that the specified task depends on will be run before
12873 the task.
12874 Even when you manually specify a task to run with
12875 <filename>-c</filename>, BitBake will only run the task if it
12876 considers it "out of date".
12877 See the
12878 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
12879 section in the Yocto Project Overview and Concepts Manual for
12880 how BitBake determines whether a task is "out of date".
12881 </para>
12882
12883 <para>
12884 If you want to force an up-to-date task to be rerun (e.g.
12885 because you made manual modifications to the recipe's
12886 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
12887 that you want to try out), then you can use the
12888 <filename>-f</filename> option.
12889 <note>
12890 The reason <filename>-f</filename> is never required when
12891 running the
12892 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
12893 task is because the
12894 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
12895 variable flag is already set for the task.
12896 </note>
12897 The following example shows one way you can use the
12898 <filename>-f</filename> option:
12899 <literallayout class='monospaced'>
12900 $ bitbake matchbox-desktop
12901 .
12902 .
12903 make some changes to the source code in the work directory
12904 .
12905 .
12906 $ bitbake matchbox-desktop -c compile -f
12907 $ bitbake matchbox-desktop
12908 </literallayout>
12909 </para>
12910
12911 <para>
12912 This sequence first builds and then recompiles
12913 <filename>matchbox-desktop</filename>.
12914 The last command reruns all tasks (basically the packaging
12915 tasks) after the compile.
12916 BitBake recognizes that the <filename>do_compile</filename>
12917 task was rerun and therefore understands that the other tasks
12918 also need to be run again.
12919 </para>
12920
12921 <para>
12922 Another, shorter way to rerun a task and all
12923 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
12924 that depend on it is to use the <filename>-C</filename>
12925 option.
12926 <note>
12927 This option is upper-cased and is separate from the
12928 <filename>-c</filename> option, which is lower-cased.
12929 </note>
12930 Using this option invalidates the given task and then runs the
12931 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
12932 task, which is the default task if no task is given, and the
12933 tasks on which it depends.
12934 You could replace the final two commands in the previous example
12935 with the following single command:
12936 <literallayout class='monospaced'>
12937 $ bitbake matchbox-desktop -C compile
12938 </literallayout>
12939 Internally, the <filename>-f</filename> and
12940 <filename>-C</filename> options work by tainting (modifying) the
12941 input checksum of the specified task.
12942 This tainting indirectly causes the task and its
12943 dependent tasks to be rerun through the normal task dependency
12944 mechanisms.
12945 <note>
12946 BitBake explicitly keeps track of which tasks have been
12947 tainted in this fashion, and will print warnings such as the
12948 following for builds involving such tasks:
12949 <literallayout class='monospaced'>
12950 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
12951 </literallayout>
12952 The purpose of the warning is to let you know that the work
12953 directory and build output might not be in the clean state
12954 they would be in for a "normal" build, depending on what
12955 actions you took.
12956 To get rid of such warnings, you can remove the work
12957 directory and rebuild the recipe, as follows:
12958 <literallayout class='monospaced'>
12959 $ bitbake matchbox-desktop -c clean
12960 $ bitbake matchbox-desktop
12961 </literallayout>
12962 </note>
12963 </para>
12964
12965 <para>
12966 You can view a list of tasks in a given package by running the
12967 <filename>do_listtasks</filename> task as follows:
12968 <literallayout class='monospaced'>
12969 $ bitbake matchbox-desktop -c listtasks
12970 </literallayout>
12971 The results appear as output to the console and are also in the
12972 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
12973 </para>
12974 </section>
12975
12976 <section id='dev-debugging-bitbake'>
12977 <title>General BitBake Problems</title>
12978
12979 <para>
12980 You can see debug output from BitBake by using the
12981 <filename>-D</filename> option.
12982 The debug output gives more information about what BitBake
12983 is doing and the reason behind it.
12984 Each <filename>-D</filename> option you use increases the
12985 logging level.
12986 The most common usage is <filename>-DDD</filename>.
12987 </para>
12988
12989 <para>
12990 The output from
12991 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
12992 can reveal why BitBake chose a certain version of a package or
12993 why BitBake picked a certain provider.
12994 This command could also help you in a situation where you think
12995 BitBake did something unexpected.
12996 </para>
12997 </section>
12998
12999 <section id='dev-debugging-buildfile'>
13000 <title>Building with No Dependencies</title>
13001
13002 <para>
13003 To build a specific recipe (<filename>.bb</filename> file),
13004 you can use the following command form:
13005 <literallayout class='monospaced'>
13006 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13007 </literallayout>
13008 This command form does not check for dependencies.
13009 Consequently, you should use it only when you know existing
13010 dependencies have been met.
13011 <note>
13012 You can also specify fragments of the filename.
13013 In this case, BitBake checks for a unique match.
13014 </note>
13015 </para>
13016 </section>
13017
13018 <section id='recipe-logging-mechanisms'>
13019 <title>Recipe Logging Mechanisms</title>
13020
13021 <para>
13022 The Yocto Project provides several logging functions for
13023 producing debugging output and reporting errors and warnings.
13024 For Python functions, the following logging functions exist.
13025 All of these functions log to
13026 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13027 and can also log to standard output (stdout) with the right
13028 settings:
13029 <itemizedlist>
13030 <listitem><para>
13031 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13032 Writes <replaceable>msg</replaceable> as is to the
13033 log while also logging to stdout.
13034 </para></listitem>
13035 <listitem><para>
13036 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13037 Writes "NOTE: <replaceable>msg</replaceable>" to the
13038 log.
13039 Also logs to stdout if BitBake is called with "-v".
13040 </para></listitem>
13041 <listitem><para>
13042 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13043 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13044 log.
13045 Also logs to stdout if the log level is greater than or
13046 equal to <replaceable>level</replaceable>.
13047 See the
13048 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13049 option in the BitBake User Manual for more information.
13050 </para></listitem>
13051 <listitem><para>
13052 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13053 Writes "WARNING: <replaceable>msg</replaceable>" to the
13054 log while also logging to stdout.
13055 </para></listitem>
13056 <listitem><para>
13057 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13058 Writes "ERROR: <replaceable>msg</replaceable>" to the
13059 log while also logging to standard out (stdout).
13060 <note>
13061 Calling this function does not cause the task to fail.
13062 </note>
13063 </para></listitem>
13064 <listitem><para>
13065 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13066 This logging function is similar to
13067 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13068 but also causes the calling task to fail.
13069 <note>
13070 <filename>bb.fatal()</filename> raises an exception,
13071 which means you do not need to put a "return"
13072 statement after the function.
13073 </note>
13074 </para></listitem>
13075 </itemizedlist>
13076 </para>
13077
13078 <para>
13079 The same logging functions are also available in shell
13080 functions, under the names
13081 <filename>bbplain</filename>, <filename>bbnote</filename>,
13082 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13083 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13084 The
13085 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13086 class implements these functions.
13087 See that class in the
13088 <filename>meta/classes</filename> folder of the
13089 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13090 for information.
13091 </para>
13092
13093 <section id='logging-with-python'>
13094 <title>Logging With Python</title>
13095
13096 <para>
13097 When creating recipes using Python and inserting code that
13098 handles build logs, keep in mind the goal is to have
13099 informative logs while keeping the console as "silent" as
13100 possible.
13101 Also, if you want status messages in the log, use the
13102 "debug" loglevel.
13103 </para>
13104
13105 <para>
13106 Following is an example written in Python.
13107 The code handles logging for a function that determines the
13108 number of tasks needed to be run.
13109 See the
13110 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13111 section for additional information:
13112 <literallayout class='monospaced'>
13113 python do_listtasks() {
13114 bb.debug(2, "Starting to figure out the task list")
13115 if noteworthy_condition:
13116 bb.note("There are 47 tasks to run")
13117 bb.debug(2, "Got to point xyz")
13118 if warning_trigger:
13119 bb.warn("Detected warning_trigger, this might be a problem later.")
13120 if recoverable_error:
13121 bb.error("Hit recoverable_error, you really need to fix this!")
13122 if fatal_error:
13123 bb.fatal("fatal_error detected, unable to print the task list")
13124 bb.plain("The tasks present are abc")
13125 bb.debug(2, "Finished figuring out the tasklist")
13126 }
13127 </literallayout>
13128 </para>
13129 </section>
13130
13131 <section id='logging-with-bash'>
13132 <title>Logging With Bash</title>
13133
13134 <para>
13135 When creating recipes using Bash and inserting code that
13136 handles build logs, you have the same goals - informative
13137 with minimal console output.
13138 The syntax you use for recipes written in Bash is similar
13139 to that of recipes written in Python described in the
13140 previous section.
13141 </para>
13142
13143 <para>
13144 Following is an example written in Bash.
13145 The code logs the progress of the <filename>do_my_function</filename> function.
13146 <literallayout class='monospaced'>
13147 do_my_function() {
13148 bbdebug 2 "Running do_my_function"
13149 if [ exceptional_condition ]; then
13150 bbnote "Hit exceptional_condition"
13151 fi
13152 bbdebug 2 "Got to point xyz"
13153 if [ warning_trigger ]; then
13154 bbwarn "Detected warning_trigger, this might cause a problem later."
13155 fi
13156 if [ recoverable_error ]; then
13157 bberror "Hit recoverable_error, correcting"
13158 fi
13159 if [ fatal_error ]; then
13160 bbfatal "fatal_error detected"
13161 fi
13162 bbdebug 2 "Completed do_my_function"
13163 }
13164 </literallayout>
13165 </para>
13166 </section>
13167 </section>
13168
13169 <section id='debugging-parallel-make-races'>
13170 <title>Debugging Parallel Make Races</title>
13171
13172 <para>
13173 A parallel <filename>make</filename> race occurs when the build
13174 consists of several parts that are run simultaneously and
13175 a situation occurs when the output or result of one
13176 part is not ready for use with a different part of the build
13177 that depends on that output.
13178 Parallel make races are annoying and can sometimes be difficult
13179 to reproduce and fix.
13180 However, some simple tips and tricks exist that can help
13181 you debug and fix them.
13182 This section presents a real-world example of an error
13183 encountered on the Yocto Project autobuilder and the process
13184 used to fix it.
13185 <note>
13186 If you cannot properly fix a <filename>make</filename> race
13187 condition, you can work around it by clearing either the
13188 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13189 or
13190 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13191 variables.
13192 </note>
13193 </para>
13194
13195 <section id='the-failure'>
13196 <title>The Failure</title>
13197
13198 <para>
13199 For this example, assume that you are building an image that
13200 depends on the "neard" package.
13201 And, during the build, BitBake runs into problems and
13202 creates the following output.
13203 <note>
13204 This example log file has longer lines artificially
13205 broken to make the listing easier to read.
13206 </note>
13207 If you examine the output or the log file, you see the
13208 failure during <filename>make</filename>:
13209 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013210 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13211 | DEBUG: Executing shell function do_compile
13212 | NOTE: make -j 16
13213 | make --no-print-directory all-am
13214 | /bin/mkdir -p include/near
13215 | /bin/mkdir -p include/near
13216 | /bin/mkdir -p include/near
13217 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13218 0.14-r0/neard-0.14/include/types.h include/near/types.h
13219 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13220 0.14-r0/neard-0.14/include/log.h include/near/log.h
13221 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13222 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13223 | /bin/mkdir -p include/near
13224 | /bin/mkdir -p include/near
13225 | /bin/mkdir -p include/near
13226 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13227 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13228 | /bin/mkdir -p include/near
13229 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13230 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13231 | /bin/mkdir -p include/near
13232 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13233 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13234 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13235 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13236 | /bin/mkdir -p include/near
13237 | /bin/mkdir -p include/near
13238 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13239 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13240 | /bin/mkdir -p include/near
13241 | /bin/mkdir -p include/near
13242 | /bin/mkdir -p include/near
13243 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13244 0.14-r0/neard-0.14/include/device.h include/near/device.h
13245 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13246 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13247 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13248 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13249 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13250 0.14-r0/neard-0.14/include/version.h include/near/version.h
13251 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13252 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13253 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13254 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13255 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13256 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13257 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13258 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13259 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13260 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13261 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13262 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13263 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13264 -o tools/snep-send.o tools/snep-send.c
13265 | In file included from tools/snep-send.c:16:0:
13266 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13267 | #include &lt;near/dbus.h&gt;
13268 | ^
13269 | compilation terminated.
13270 | make[1]: *** [tools/snep-send.o] Error 1
13271 | make[1]: *** Waiting for unfinished jobs....
13272 | make: *** [all] Error 2
13273 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013274 </literallayout>
13275 </para>
13276 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013277
Brad Bishop316dfdd2018-06-25 12:45:53 -040013278 <section id='reproducing-the-error'>
13279 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013280
Brad Bishop316dfdd2018-06-25 12:45:53 -040013281 <para>
13282 Because race conditions are intermittent, they do not
13283 manifest themselves every time you do the build.
13284 In fact, most times the build will complete without problems
13285 even though the potential race condition exists.
13286 Thus, once the error surfaces, you need a way to reproduce
13287 it.
13288 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013289
Brad Bishop316dfdd2018-06-25 12:45:53 -040013290 <para>
13291 In this example, compiling the "neard" package is causing
13292 the problem.
13293 So the first thing to do is build "neard" locally.
13294 Before you start the build, set the
13295 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13296 variable in your <filename>local.conf</filename> file to
13297 a high number (e.g. "-j 20").
13298 Using a high value for <filename>PARALLEL_MAKE</filename>
13299 increases the chances of the race condition showing up:
13300 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013301 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013302 </literallayout>
13303 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013304
Brad Bishop316dfdd2018-06-25 12:45:53 -040013305 <para>
13306 Once the local build for "neard" completes, start a
13307 <filename>devshell</filename> build:
13308 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013309 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013310 </literallayout>
13311 For information on how to use a
13312 <filename>devshell</filename>, see the
13313 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13314 section.
13315 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013316
Brad Bishop316dfdd2018-06-25 12:45:53 -040013317 <para>
13318 In the <filename>devshell</filename>, do the following:
13319 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013320 $ make clean
13321 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013322 </literallayout>
13323 The <filename>devshell</filename> commands cause the failure
13324 to clearly be visible.
13325 In this case, a missing dependency exists for the "neard"
13326 Makefile target.
13327 Here is some abbreviated, sample output with the
13328 missing dependency clearly visible at the end:
13329 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013330 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13331 .
13332 .
13333 .
13334 tools/snep-send.c
13335 In file included from tools/snep-send.c:16:0:
13336 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13337 #include &lt;near/dbus.h&gt;
13338 ^
13339 compilation terminated.
13340 make: *** [tools/snep-send.o] Error 1
13341 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013342 </literallayout>
13343 </para>
13344 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013345
Brad Bishop316dfdd2018-06-25 12:45:53 -040013346 <section id='creating-a-patch-for-the-fix'>
13347 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013348
Brad Bishop316dfdd2018-06-25 12:45:53 -040013349 <para>
13350 Because there is a missing dependency for the Makefile
13351 target, you need to patch the
13352 <filename>Makefile.am</filename> file, which is generated
13353 from <filename>Makefile.in</filename>.
13354 You can use Quilt to create the patch:
13355 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013356 $ quilt new parallelmake.patch
13357 Patch patches/parallelmake.patch is now on top
13358 $ quilt add Makefile.am
13359 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013360 </literallayout>
13361 For more information on using Quilt, see the
13362 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13363 section.
13364 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013365
Brad Bishop316dfdd2018-06-25 12:45:53 -040013366 <para>
13367 At this point you need to make the edits to
13368 <filename>Makefile.am</filename> to add the missing
13369 dependency.
13370 For our example, you have to add the following line
13371 to the file:
13372 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013373 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013374 </literallayout>
13375 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013376
Brad Bishop316dfdd2018-06-25 12:45:53 -040013377 <para>
13378 Once you have edited the file, use the
13379 <filename>refresh</filename> command to create the patch:
13380 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013381 $ quilt refresh
13382 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013383 </literallayout>
13384 Once the patch file exists, you need to add it back to the
13385 originating recipe folder.
13386 Here is an example assuming a top-level
13387 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13388 named <filename>poky</filename>:
13389 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013390 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013391 </literallayout>
13392 The final thing you need to do to implement the fix in the
13393 build is to update the "neard" recipe (i.e.
13394 <filename>neard-0.14.bb</filename>) so that the
13395 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13396 statement includes the patch file.
13397 The recipe file is in the folder above the patch.
13398 Here is what the edited <filename>SRC_URI</filename>
13399 statement would look like:
13400 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013401 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13402 file://neard.in \
13403 file://neard.service.in \
13404 file://parallelmake.patch \
13405 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013406 </literallayout>
13407 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013408
Brad Bishop316dfdd2018-06-25 12:45:53 -040013409 <para>
13410 With the patch complete and moved to the correct folder and
13411 the <filename>SRC_URI</filename> statement updated, you can
13412 exit the <filename>devshell</filename>:
13413 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013414 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013415 </literallayout>
13416 </para>
13417 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013418
Brad Bishop316dfdd2018-06-25 12:45:53 -040013419 <section id='testing-the-build'>
13420 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013421
Brad Bishop316dfdd2018-06-25 12:45:53 -040013422 <para>
13423 With everything in place, you can get back to trying the
13424 build again locally:
13425 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013426 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013427 </literallayout>
13428 This build should succeed.
13429 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013430
Brad Bishop316dfdd2018-06-25 12:45:53 -040013431 <para>
13432 Now you can open up a <filename>devshell</filename> again
13433 and repeat the clean and make operations as follows:
13434 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013435 $ bitbake neard -c devshell
13436 $ make clean
13437 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013438 </literallayout>
13439 The build should work without issue.
13440 </para>
13441
13442 <para>
13443 As with all solved problems, if they originated upstream,
13444 you need to submit the fix for the recipe in OE-Core and
13445 upstream so that the problem is taken care of at its
13446 source.
13447 See the
13448 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13449 section for more information.
13450 </para>
13451 </section>
13452 </section>
13453
13454 <section id="platdev-gdb-remotedebug">
13455 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13456
13457 <para>
13458 GDB allows you to examine running programs, which in turn helps
13459 you to understand and fix problems.
13460 It also allows you to perform post-mortem style analysis of
13461 program crashes.
13462 GDB is available as a package within the Yocto Project and is
13463 installed in SDK images by default.
13464 See the
13465 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13466 chapter in the Yocto Project Reference Manual for a description of
13467 these images.
13468 You can find information on GDB at
13469 <ulink url="http://sourceware.org/gdb/"/>.
13470 <note><title>Tip</title>
13471 For best results, install debug (<filename>-dbg</filename>)
13472 packages for the applications you are going to debug.
13473 Doing so makes extra debug symbols available that give you
13474 more meaningful output.
13475 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013476 </para>
13477
13478 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013479 Sometimes, due to memory or disk space constraints, it is not
13480 possible to use GDB directly on the remote target to debug
13481 applications.
13482 These constraints arise because GDB needs to load the debugging
13483 information and the binaries of the process being debugged.
13484 Additionally, GDB needs to perform many computations to locate
13485 information such as function names, variable names and values,
13486 stack traces and so forth - even before starting the debugging
13487 process.
13488 These extra computations place more load on the target system
13489 and can alter the characteristics of the program being debugged.
13490 </para>
13491
13492 <para>
13493 To help get past the previously mentioned constraints, you can
13494 use gdbserver, which runs on the remote target and does not
13495 load any debugging information from the debugged process.
13496 Instead, a GDB instance processes the debugging information that
13497 is run on a remote computer - the host GDB.
13498 The host GDB then sends control commands to gdbserver to make
13499 it stop or start the debugged program, as well as read or write
13500 memory regions of that debugged program.
13501 All the debugging information loaded and processed as well
13502 as all the heavy debugging is done by the host GDB.
13503 Offloading these processes gives the gdbserver running on the
13504 target a chance to remain small and fast.
13505 </para>
13506
13507 <para>
13508 Because the host GDB is responsible for loading the debugging
13509 information and for doing the necessary processing to make
13510 actual debugging happen, you have to make sure the host can
13511 access the unstripped binaries complete with their debugging
13512 information and also be sure the target is compiled with no
13513 optimizations.
13514 The host GDB must also have local access to all the libraries
13515 used by the debugged program.
13516 Because gdbserver does not need any local debugging information,
13517 the binaries on the remote target can remain stripped.
13518 However, the binaries must also be compiled without optimization
13519 so they match the host's binaries.
13520 </para>
13521
13522 <para>
13523 To remain consistent with GDB documentation and terminology,
13524 the binary being debugged on the remote target machine is
13525 referred to as the "inferior" binary.
13526 For documentation on GDB see the
13527 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
13528 </para>
13529
13530 <para>
13531 The following steps show you how to debug using the GNU project
13532 debugger.
13533 <orderedlist>
13534 <listitem><para>
13535 <emphasis>Configure your build system to construct the
13536 companion debug filesystem:</emphasis></para>
13537
13538 <para>In your <filename>local.conf</filename> file, set
13539 the following:
13540 <literallayout class='monospaced'>
13541 IMAGE_GEN_DEBUGFS = "1"
13542 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
13543 </literallayout>
13544 These options cause the OpenEmbedded build system
13545 to generate a special companion filesystem fragment,
13546 which contains the matching source and debug symbols to
13547 your deployable filesystem.
13548 The build system does this by looking at what is in the
13549 deployed filesystem, and pulling the corresponding
13550 <filename>-dbg</filename> packages.</para>
13551
13552 <para>The companion debug filesystem is not a complete
13553 filesystem, but only contains the debug fragments.
13554 This filesystem must be combined with the full filesystem
13555 for debugging.
13556 Subsequent steps in this procedure show how to combine
13557 the partial filesystem with the full filesystem.
13558 </para></listitem>
13559 <listitem><para>
13560 <emphasis>Configure the system to include gdbserver in
13561 the target filesystem:</emphasis></para>
13562
13563 <para>Make the following addition in either your
13564 <filename>local.conf</filename> file or in an image
13565 recipe:
13566 <literallayout class='monospaced'>
13567 IMAGE_INSTALL_append = “ gdbserver"
13568 </literallayout>
13569 The change makes sure the <filename>gdbserver</filename>
13570 package is included.
13571 </para></listitem>
13572 <listitem><para>
13573 <emphasis>Build the environment:</emphasis></para>
13574
13575 <para>Use the following command to construct the image
13576 and the companion Debug Filesystem:
13577 <literallayout class='monospaced'>
13578 $ bitbake <replaceable>image</replaceable>
13579 </literallayout>
13580 Build the cross GDB component and make it available
13581 for debugging.
13582 Build the SDK that matches the image.
13583 Building the SDK is best for a production build
13584 that can be used later for debugging, especially
13585 during long term maintenance:
13586 <literallayout class='monospaced'>
13587 $ bitbake -c populate_sdk <replaceable>image</replaceable>
13588 </literallayout></para>
13589
13590 <para>Alternatively, you can build the minimal
13591 toolchain components that match the target.
13592 Doing so creates a smaller than typical SDK and only
13593 contains a minimal set of components with which to
13594 build simple test applications, as well as run the
13595 debugger:
13596 <literallayout class='monospaced'>
13597 $ bitbake meta-toolchain
13598 </literallayout></para>
13599
13600 <para>A final method is to build Gdb itself within
13601 the build system:
13602 <literallayout class='monospaced'>
13603 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
13604 </literallayout>
13605 Doing so produces a temporary copy of
13606 <filename>cross-gdb</filename> you can use for
13607 debugging during development.
13608 While this is the quickest approach, the two previous
13609 methods in this step are better when considering
13610 long-term maintenance strategies.
13611 <note>
13612 If you run
13613 <filename>bitbake gdb-cross</filename>, the
13614 OpenEmbedded build system suggests the actual
13615 image (e.g. <filename>gdb-cross-i586</filename>).
13616 The suggestion is usually the actual name you want
13617 to use.
13618 </note>
13619 </para></listitem>
13620 <listitem><para>
13621 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
13622
13623 <para>Run the following commands to set up the
13624 <filename>debugfs</filename>:
13625 <literallayout class='monospaced'>
13626 $ mkdir debugfs
13627 $ cd debugfs
13628 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
13629 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
13630 </literallayout>
13631 </para></listitem>
13632 <listitem><para>
13633 <emphasis>Set up GDB</emphasis></para>
13634
13635 <para>Install the SDK (if you built one) and then
13636 source the correct environment file.
13637 Sourcing the environment file puts the SDK in your
13638 <filename>PATH</filename> environment variable.</para>
13639
13640 <para>If you are using the build system, Gdb is
13641 located in
13642 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
13643 </para></listitem>
13644 <listitem><para>
13645 <emphasis>Boot the target:</emphasis></para>
13646
13647 <para>For information on how to run QEMU, see the
13648 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
13649 <note>
13650 Be sure to verify that your host can access the
13651 target via TCP.
13652 </note>
13653 </para></listitem>
13654 <listitem><para>
13655 <emphasis>Debug a program:</emphasis></para>
13656
13657 <para>Debugging a program involves running gdbserver
13658 on the target and then running Gdb on the host.
13659 The example in this step debugs
13660 <filename>gzip</filename>:
13661 <literallayout class='monospaced'>
13662 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
13663 </literallayout>
13664 For additional gdbserver options, see the
13665 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
13666 </para>
13667
13668 <para>After running gdbserver on the target, you need
13669 to run Gdb on the host and configure it and connect to
13670 the target.
13671 Use these commands:
13672 <literallayout class='monospaced'>
13673 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
13674 $ <replaceable>arch</replaceable>-gdb
13675
13676 (gdb) set sysroot debugfs
13677 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
13678 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
13679 </literallayout>
13680 At this point, everything should automatically load
13681 (i.e. matching binaries, symbols and headers).
13682 <note>
13683 The Gdb <filename>set</filename> commands in the
13684 previous example can be placed into the users
13685 <filename>~/.gdbinit</filename> file.
13686 Upon starting, Gdb automatically runs whatever
13687 commands are in that file.
13688 </note>
13689 </para></listitem>
13690 <listitem><para>
13691 <emphasis>Deploying without a full image
13692 rebuild:</emphasis></para>
13693
13694 <para>In many cases, during development you want a
13695 quick method to deploy a new binary to the target and
13696 debug it, without waiting for a full image build.
13697 </para>
13698
13699 <para>One approach to solving this situation is to
13700 just build the component you want to debug.
13701 Once you have built the component, copy the
13702 executable directly to both the target and the
13703 host <filename>debugfs</filename>.</para>
13704
13705 <para>If the binary is processed through the debug
13706 splitting in OpenEmbedded, you should also
13707 copy the debug items (i.e. <filename>.debug</filename>
13708 contents and corresponding
13709 <filename>/usr/src/debug</filename> files)
13710 from the work directory.
13711 Here is an example:
13712 <literallayout class='monospaced'>
13713 $ bitbake bash
13714 $ bitbake -c devshell bash
13715 $ cd ..
13716 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
13717 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
13718 </literallayout>
13719 </para></listitem>
13720 </orderedlist>
13721 </para>
13722 </section>
13723
13724 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
13725 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
13726
13727 <para>
13728 The previous section addressed using GDB remotely for debugging
13729 purposes, which is the most usual case due to the inherent
13730 hardware limitations on many embedded devices.
13731 However, debugging in the target hardware itself is also
13732 possible with more powerful devices.
13733 This section describes what you need to do in order to support
13734 using GDB to debug on the target hardware.
13735 </para>
13736
13737 <para>
13738 To support this kind of debugging, you need do the following:
13739 <itemizedlist>
13740 <listitem><para>
13741 Ensure that GDB is on the target.
13742 You can do this by adding "gdb" to
13743 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
13744 <literallayout class='monospaced'>
13745 IMAGE_INSTALL_append = " gdb"
13746 </literallayout>
13747 Alternatively, you can add "tools-debug" to
13748 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
13749 <literallayout class='monospaced'>
13750 IMAGE_FEATURES_append = " tools-debug"
13751 </literallayout>
13752 </para></listitem>
13753 <listitem><para>
13754 Ensure that debug symbols are present.
13755 You can make sure these symbols are present by
13756 installing <filename>-dbg</filename>:
13757 <literallayout class='monospaced'>
13758 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
13759 </literallayout>
13760 Alternatively, you can do the following to include all
13761 the debug symbols:
13762 <literallayout class='monospaced'>
13763 IMAGE_FEATURES_append = " dbg-pkgs"
13764 </literallayout>
13765 </para></listitem>
13766 </itemizedlist>
13767 <note>
13768 To improve the debug information accuracy, you can reduce
13769 the level of optimization used by the compiler.
13770 For example, when adding the following line to your
13771 <filename>local.conf</filename> file, you will reduce
13772 optimization from
13773 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
13774 of "-O2" to
13775 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
13776 of "-O -fno-omit-frame-pointer":
13777 <literallayout class='monospaced'>
13778 DEBUG_BUILD = "1"
13779 </literallayout>
13780 Consider that this will reduce the application's performance
13781 and is recommended only for debugging purposes.
13782 </note>
13783 </para>
13784 </section>
13785
13786 <section id='dev-other-debugging-others'>
13787 <title>Other Debugging Tips</title>
13788
13789 <para>
13790 Here are some other tips that you might find useful:
13791 <itemizedlist>
13792 <listitem><para>
13793 When adding new packages, it is worth watching for
13794 undesirable items making their way into compiler command
13795 lines.
13796 For example, you do not want references to local system
13797 files like
13798 <filename>/usr/lib/</filename> or
13799 <filename>/usr/include/</filename>.
13800 </para></listitem>
13801 <listitem><para>
13802 If you want to remove the <filename>psplash</filename>
13803 boot splashscreen,
13804 add <filename>psplash=false</filename> to the kernel
13805 command line.
13806 Doing so prevents <filename>psplash</filename> from
13807 loading and thus allows you to see the console.
13808 It is also possible to switch out of the splashscreen by
13809 switching the virtual console (e.g. Fn+Left or Fn+Right
13810 on a Zaurus).
13811 </para></listitem>
13812 <listitem><para>
13813 Removing
13814 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
13815 (usually <filename>tmp/</filename>, within the
13816 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
13817 can often fix temporary build issues.
13818 Removing <filename>TMPDIR</filename> is usually a
13819 relatively cheap operation, because task output will be
13820 cached in
13821 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13822 (usually <filename>sstate-cache/</filename>, which is
13823 also in the Build Directory).
13824 <note>
13825 Removing <filename>TMPDIR</filename> might be a
13826 workaround rather than a fix.
13827 Consequently, trying to determine the underlying
13828 cause of an issue before removing the directory is
13829 a good idea.
13830 </note>
13831 </para></listitem>
13832 <listitem><para>
13833 Understanding how a feature is used in practice within
13834 existing recipes can be very helpful.
13835 It is recommended that you configure some method that
13836 allows you to quickly search through files.</para>
13837
13838 <para>Using GNU Grep, you can use the following shell
13839 function to recursively search through common
13840 recipe-related files, skipping binary files,
13841 <filename>.git</filename> directories, and the
13842 Build Directory (assuming its name starts with
13843 "build"):
13844 <literallayout class='monospaced'>
13845 g() {
13846 grep -Ir \
13847 --exclude-dir=.git \
13848 --exclude-dir='build*' \
13849 --include='*.bb*' \
13850 --include='*.inc*' \
13851 --include='*.conf*' \
13852 --include='*.py*' \
13853 "$@"
13854 }
13855 </literallayout>
13856 Following are some usage examples:
13857 <literallayout class='monospaced'>
13858 $ g FOO # Search recursively for "FOO"
13859 $ g -i foo # Search recursively for "foo", ignoring case
13860 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
13861 </literallayout>
13862 If figuring out how some feature works requires a lot of
13863 searching, it might indicate that the documentation
13864 should be extended or improved.
13865 In such cases, consider filing a documentation bug using
13866 the Yocto Project implementation of
13867 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
13868 For information on how to submit a bug against
13869 the Yocto Project, see the Yocto Project Bugzilla
13870 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
13871 and the
13872 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
13873 section.
13874 <note>
13875 The manuals might not be the right place to document
13876 variables that are purely internal and have a
13877 limited scope (e.g. internal variables used to
13878 implement a single <filename>.bbclass</filename>
13879 file).
13880 </note>
13881 </para></listitem>
13882 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013883 </para>
13884 </section>
13885 </section>
13886
Brad Bishop316dfdd2018-06-25 12:45:53 -040013887 <section id='making-changes-to-the-yocto-project'>
13888 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013889
13890 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013891 Because the Yocto Project is an open-source, community-based
13892 project, you can effect changes to the project.
13893 This section presents procedures that show you how to submit
13894 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013895 </para>
13896
Brad Bishop316dfdd2018-06-25 12:45:53 -040013897 <section id='submitting-a-defect-against-the-yocto-project'>
13898 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013899
13900 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013901 Use the Yocto Project implementation of
13902 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
13903 to submit a defect (bug) against the Yocto Project.
13904 For additional information on this implementation of Bugzilla see the
13905 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
13906 section in the Yocto Project Reference Manual.
13907 For more detail on any of the following steps, see the Yocto Project
13908 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013909 </para>
13910
13911 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013912 Use the following general steps to submit a bug"
13913
13914 <orderedlist>
13915 <listitem><para>
13916 Open the Yocto Project implementation of
13917 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
13918 </para></listitem>
13919 <listitem><para>
13920 Click "File a Bug" to enter a new bug.
13921 </para></listitem>
13922 <listitem><para>
13923 Choose the appropriate "Classification", "Product", and
13924 "Component" for which the bug was found.
13925 Bugs for the Yocto Project fall into one of several
13926 classifications, which in turn break down into several
13927 products and components.
13928 For example, for a bug against the
13929 <filename>meta-intel</filename> layer, you would choose
13930 "Build System, Metadata &amp; Runtime", "BSPs", and
13931 "bsps-meta-intel", respectively.
13932 </para></listitem>
13933 <listitem><para>
13934 Choose the "Version" of the Yocto Project for which you found
13935 the bug (e.g. &DISTRO;).
13936 </para></listitem>
13937 <listitem><para>
13938 Determine and select the "Severity" of the bug.
13939 The severity indicates how the bug impacted your work.
13940 </para></listitem>
13941 <listitem><para>
13942 Choose the "Hardware" that the bug impacts.
13943 </para></listitem>
13944 <listitem><para>
13945 Choose the "Architecture" that the bug impacts.
13946 </para></listitem>
13947 <listitem><para>
13948 Choose a "Documentation change" item for the bug.
13949 Fixing a bug might or might not affect the Yocto Project
13950 documentation.
13951 If you are unsure of the impact to the documentation, select
13952 "Don't Know".
13953 </para></listitem>
13954 <listitem><para>
13955 Provide a brief "Summary" of the bug.
13956 Try to limit your summary to just a line or two and be sure
13957 to capture the essence of the bug.
13958 </para></listitem>
13959 <listitem><para>
13960 Provide a detailed "Description" of the bug.
13961 You should provide as much detail as you can about the context,
13962 behavior, output, and so forth that surrounds the bug.
13963 You can even attach supporting files for output from logs by
13964 using the "Add an attachment" button.
13965 </para></listitem>
13966 <listitem><para>
13967 Click the "Submit Bug" button submit the bug.
13968 A new Bugzilla number is assigned to the bug and the defect
13969 is logged in the bug tracking system.
13970 </para></listitem>
13971 </orderedlist>
13972 Once you file a bug, the bug is processed by the Yocto Project Bug
13973 Triage Team and further details concerning the bug are assigned
13974 (e.g. priority and owner).
13975 You are the "Submitter" of the bug and any further categorization,
13976 progress, or comments on the bug result in Bugzilla sending you an
13977 automated email concerning the particular change or progress to the
13978 bug.
13979 </para>
13980 </section>
13981
13982 <section id='how-to-submit-a-change'>
13983 <title>Submitting a Change to the Yocto Project</title>
13984
13985 <para>
13986 Contributions to the Yocto Project and OpenEmbedded are very welcome.
13987 Because the system is extremely configurable and flexible, we recognize
13988 that developers will want to extend, configure or optimize it for
13989 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013990 </para>
13991
13992 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013993 The Yocto Project uses a mailing list and a patch-based workflow
13994 that is similar to the Linux kernel but contains important
13995 differences.
13996 In general, a mailing list exists through which you can submit
13997 patches.
13998 You should send patches to the appropriate mailing list so that they
13999 can be reviewed and merged by the appropriate maintainer.
14000 The specific mailing list you need to use depends on the
14001 location of the code you are changing.
14002 Each component (e.g. layer) should have a
14003 <filename>README</filename> file that indicates where to send
14004 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014005 </para>
14006
14007 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014008 You can send the patch to the mailing list using whichever approach
14009 you feel comfortable with to generate the patch.
14010 Once sent, the patch is usually reviewed by the community at large.
14011 If somebody has concerns with the patch, they will usually voice
14012 their concern over the mailing list.
14013 If a patch does not receive any negative reviews, the maintainer of
14014 the affected layer typically takes the patch, tests it, and then
14015 based on successful testing, merges the patch.
14016 </para>
14017
14018 <para id='figuring-out-the-mailing-list-to-use'>
14019 The "poky" repository, which is the Yocto Project's reference build
14020 environment, is a hybrid repository that contains several
14021 individual pieces (e.g. BitBake, Metadata, documentation,
14022 and so forth) built using the combo-layer tool.
14023 The upstream location used for submitting changes varies by
14024 component:
14025 <itemizedlist>
14026 <listitem><para>
14027 <emphasis>Core Metadata:</emphasis>
14028 Send your patch to the
14029 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14030 mailing list. For example, a change to anything under
14031 the <filename>meta</filename> or
14032 <filename>scripts</filename> directories should be sent
14033 to this mailing list.
14034 </para></listitem>
14035 <listitem><para>
14036 <emphasis>BitBake:</emphasis>
14037 For changes to BitBake (i.e. anything under the
14038 <filename>bitbake</filename> directory), send your patch
14039 to the
14040 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14041 mailing list.
14042 </para></listitem>
14043 <listitem><para>
14044 <emphasis>"meta-*" trees:</emphasis>
14045 These trees contain Metadata.
14046 Use the
14047 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14048 mailing list.
14049 </para></listitem>
14050 </itemizedlist>
14051 </para>
14052
14053 <para>
14054 For changes to other layers hosted in the Yocto Project source
14055 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14056 and the Yocto Project documentation, use the
14057 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14058 general mailing list.
14059 <note>
14060 Sometimes a layer's documentation specifies to use a
14061 particular mailing list.
14062 If so, use that list.
14063 </note>
14064 For additional recipes that do not fit into the core Metadata, you
14065 should determine which layer the recipe should go into and submit
14066 the change in the manner recommended by the documentation (e.g.
14067 the <filename>README</filename> file) supplied with the layer.
14068 If in doubt, please ask on the Yocto general mailing list or on
14069 the openembedded-devel mailing list.
14070 </para>
14071
14072 <para>
14073 You can also push a change upstream and request a maintainer to
14074 pull the change into the component's upstream repository.
14075 You do this by pushing to a contribution repository that is upstream.
14076 See the
14077 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14078 section in the Yocto Project Overview and Concepts Manual for additional
14079 concepts on working in the Yocto Project development environment.
14080 </para>
14081
14082 <para>
14083 Two commonly used testing repositories exist for
14084 OpenEmbedded-Core:
14085 <itemizedlist>
14086 <listitem><para>
14087 <emphasis>"ross/mut" branch:</emphasis>
14088 The "mut" (master-under-test) tree
14089 exists in the <filename>poky-contrib</filename> repository
14090 in the
14091 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14092 </para></listitem>
14093 <listitem><para>
14094 <emphasis>"master-next" branch:</emphasis>
14095 This branch is part of the main
14096 "poky" repository in the Yocto Project source repositories.
14097 </para></listitem>
14098 </itemizedlist>
14099 Maintainers use these branches to test submissions prior to merging
14100 patches.
14101 Thus, you can get an idea of the status of a patch based on
14102 whether the patch has been merged into one of these branches.
14103 <note>
14104 This system is imperfect and changes can sometimes get lost in the
14105 flow.
14106 Asking about the status of a patch or change is reasonable if the
14107 change has been idle for a while with no feedback.
14108 The Yocto Project does have plans to use
14109 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14110 to track the status of patches and also to automatically preview
14111 patches.
14112 </note>
14113 </para>
14114
14115 <para>
14116 The following sections provide procedures for submitting a change.
14117 </para>
14118
14119 <section id='pushing-a-change-upstream'>
14120 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14121
14122 <para>
14123 Follow this procedure to push a change to an upstream "contrib"
14124 Git repository:
14125 <note>
14126 You can find general Git information on how to push a change
14127 upstream in the
14128 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14129 </note>
14130 <orderedlist>
14131 <listitem><para>
14132 <emphasis>Make Your Changes Locally:</emphasis>
14133 Make your changes in your local Git repository.
14134 You should make small, controlled, isolated changes.
14135 Keeping changes small and isolated aids review,
14136 makes merging/rebasing easier and keeps the change
14137 history clean should anyone need to refer to it in
14138 future.
14139 </para></listitem>
14140 <listitem><para>
14141 <emphasis>Stage Your Changes:</emphasis>
14142 Stage your changes by using the <filename>git add</filename>
14143 command on each file you changed.
14144 </para></listitem>
14145 <listitem><para id='making-sure-you-have-correct-commit-information'>
14146 <emphasis>Commit Your Changes:</emphasis>
14147 Commit the change by using the
14148 <filename>git commit</filename> command.
14149 Make sure your commit information follows standards by
14150 following these accepted conventions:
14151 <itemizedlist>
14152 <listitem><para>
14153 Be sure to include a "Signed-off-by:" line in the
14154 same style as required by the Linux kernel.
14155 Adding this line signifies that you, the submitter,
14156 have agreed to the Developer's Certificate of
14157 Origin 1.1 as follows:
14158 <literallayout class='monospaced'>
14159 Developer's Certificate of Origin 1.1
14160
14161 By making a contribution to this project, I certify that:
14162
14163 (a) The contribution was created in whole or in part by me and I
14164 have the right to submit it under the open source license
14165 indicated in the file; or
14166
14167 (b) The contribution is based upon previous work that, to the best
14168 of my knowledge, is covered under an appropriate open source
14169 license and I have the right under that license to submit that
14170 work with modifications, whether created in whole or in part
14171 by me, under the same open source license (unless I am
14172 permitted to submit under a different license), as indicated
14173 in the file; or
14174
14175 (c) The contribution was provided directly to me by some other
14176 person who certified (a), (b) or (c) and I have not modified
14177 it.
14178
14179 (d) I understand and agree that this project and the contribution
14180 are public and that a record of the contribution (including all
14181 personal information I submit with it, including my sign-off) is
14182 maintained indefinitely and may be redistributed consistent with
14183 this project or the open source license(s) involved.
14184 </literallayout>
14185 </para></listitem>
14186 <listitem><para>
14187 Provide a single-line summary of the change.
14188 and,
14189 if more explanation is needed, provide more
14190 detail in the body of the commit.
14191 This summary is typically viewable in the
14192 "shortlist" of changes.
14193 Thus, providing something short and descriptive
14194 that gives the reader a summary of the change is
14195 useful when viewing a list of many commits.
14196 You should prefix this short description with the
14197 recipe name (if changing a recipe), or else with
14198 the short form path to the file being changed.
14199 </para></listitem>
14200 <listitem><para>
14201 For the body of the commit message, provide
14202 detailed information that describes what you
14203 changed, why you made the change, and the approach
14204 you used.
14205 It might also be helpful if you mention how you
14206 tested the change.
14207 Provide as much detail as you can in the body of
14208 the commit message.
14209 <note>
14210 You do not need to provide a more detailed
14211 explanation of a change if the change is
14212 minor to the point of the single line
14213 summary providing all the information.
14214 </note>
14215 </para></listitem>
14216 <listitem><para>
14217 If the change addresses a specific bug or issue
14218 that is associated with a bug-tracking ID,
14219 include a reference to that ID in your detailed
14220 description.
14221 For example, the Yocto Project uses a specific
14222 convention for bug references - any commit that
14223 addresses a specific bug should use the following
14224 form for the detailed description.
14225 Be sure to use the actual bug-tracking ID from
14226 Bugzilla for
14227 <replaceable>bug-id</replaceable>:
14228 <literallayout class='monospaced'>
14229 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14230
14231 <replaceable>detailed description of change</replaceable>
14232 </literallayout>
14233 </para></listitem>
14234 </itemizedlist>
14235 </para></listitem>
14236 <listitem><para>
14237 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14238 If you have arranged for permissions to push to an
14239 upstream contrib repository, push the change to that
14240 repository:
14241 <literallayout class='monospaced'>
14242 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14243 </literallayout>
14244 For example, suppose you have permissions to push into the
14245 upstream <filename>meta-intel-contrib</filename>
14246 repository and you are working in a local branch named
14247 <replaceable>your_name</replaceable><filename>/README</filename>.
14248 The following command pushes your local commits to the
14249 <filename>meta-intel-contrib</filename> upstream
14250 repository and puts the commit in a branch named
14251 <replaceable>your_name</replaceable><filename>/README</filename>:
14252 <literallayout class='monospaced'>
14253 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14254 </literallayout>
14255 </para></listitem>
14256 <listitem><para id='push-determine-who-to-notify'>
14257 <emphasis>Determine Who to Notify:</emphasis>
14258 Determine the maintainer or the mailing list
14259 that you need to notify for the change.</para>
14260
14261 <para>Before submitting any change, you need to be sure
14262 who the maintainer is or what mailing list that you need
14263 to notify.
14264 Use either these methods to find out:
14265 <itemizedlist>
14266 <listitem><para>
14267 <emphasis>Maintenance File:</emphasis>
14268 Examine the <filename>maintainers.inc</filename>
14269 file, which is located in the
14270 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14271 at
14272 <filename>meta/conf/distro/include</filename>,
14273 to see who is responsible for code.
14274 </para></listitem>
14275 <listitem><para>
14276 <emphasis>Search by File:</emphasis>
14277 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14278 you can enter the following command to bring up a
14279 short list of all commits against a specific file:
14280 <literallayout class='monospaced'>
14281 git shortlog -- <replaceable>filename</replaceable>
14282 </literallayout>
14283 Just provide the name of the file for which you
14284 are interested.
14285 The information returned is not ordered by history
14286 but does include a list of everyone who has
14287 committed grouped by name.
14288 From the list, you can see who is responsible for
14289 the bulk of the changes against the file.
14290 </para></listitem>
14291 <listitem><para>
14292 <emphasis>Examine the List of Mailing Lists:</emphasis>
14293 For a list of the Yocto Project and related mailing
14294 lists, see the
14295 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14296 section in the Yocto Project Reference Manual.
14297 </para></listitem>
14298 </itemizedlist>
14299 </para></listitem>
14300 <listitem><para>
14301 <emphasis>Make a Pull Request:</emphasis>
14302 Notify the maintainer or the mailing list that you have
14303 pushed a change by making a pull request.</para>
14304
14305 <para>The Yocto Project provides two scripts that
14306 conveniently let you generate and send pull requests to the
14307 Yocto Project.
14308 These scripts are <filename>create-pull-request</filename>
14309 and <filename>send-pull-request</filename>.
14310 You can find these scripts in the
14311 <filename>scripts</filename> directory within the
14312 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14313 (e.g. <filename>~/poky/scripts</filename>).
14314 </para>
14315
14316 <para>Using these scripts correctly formats the requests
14317 without introducing any whitespace or HTML formatting.
14318 The maintainer that receives your patches either directly
14319 or through the mailing list needs to be able to save and
14320 apply them directly from your emails.
14321 Using these scripts is the preferred method for sending
14322 patches.</para>
14323
14324 <para>First, create the pull request.
14325 For example, the following command runs the script,
14326 specifies the upstream repository in the contrib directory
14327 into which you pushed the change, and provides a subject
14328 line in the created patch files:
14329 <literallayout class='monospaced'>
14330 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14331 </literallayout>
14332 Running this script forms
14333 <filename>*.patch</filename> files in a folder named
14334 <filename>pull-</filename><replaceable>PID</replaceable>
14335 in the current directory.
14336 One of the patch files is a cover letter.</para>
14337
14338 <para>Before running the
14339 <filename>send-pull-request</filename> script, you must
14340 edit the cover letter patch to insert information about
14341 your change.
14342 After editing the cover letter, send the pull request.
14343 For example, the following command runs the script and
14344 specifies the patch directory and email address.
14345 In this example, the email address is a mailing list:
14346 <literallayout class='monospaced'>
14347 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14348 </literallayout>
14349 You need to follow the prompts as the script is
14350 interactive.
14351 <note>
14352 For help on using these scripts, simply provide the
14353 <filename>-h</filename> argument as follows:
14354 <literallayout class='monospaced'>
14355 $ poky/scripts/create-pull-request -h
14356 $ poky/scripts/send-pull-request -h
14357 </literallayout>
14358 </note>
14359 </para></listitem>
14360 </orderedlist>
14361 </para>
14362 </section>
14363
14364 <section id='submitting-a-patch'>
14365 <title>Using Email to Submit a Patch</title>
14366
14367 <para>
14368 You can submit patches without using the
14369 <filename>create-pull-request</filename> and
14370 <filename>send-pull-request</filename> scripts described in the
14371 previous section.
14372 However, keep in mind, the preferred method is to use the scripts.
14373 </para>
14374
14375 <para>
14376 Depending on the components changed, you need to submit the email
14377 to a specific mailing list.
14378 For some guidance on which mailing list to use, see the
14379 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14380 at the beginning of this section.
14381 For a description of all the available mailing lists, see the
14382 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14383 section in the Yocto Project Reference Manual.
14384 </para>
14385
14386 <para>
14387 Here is the general procedure on how to submit a patch through
14388 email without using the scripts:
14389 <orderedlist>
14390 <listitem><para>
14391 <emphasis>Make Your Changes Locally:</emphasis>
14392 Make your changes in your local Git repository.
14393 You should make small, controlled, isolated changes.
14394 Keeping changes small and isolated aids review,
14395 makes merging/rebasing easier and keeps the change
14396 history clean should anyone need to refer to it in
14397 future.
14398 </para></listitem>
14399 <listitem><para>
14400 <emphasis>Stage Your Changes:</emphasis>
14401 Stage your changes by using the <filename>git add</filename>
14402 command on each file you changed.
14403 </para></listitem>
14404 <listitem><para>
14405 <emphasis>Commit Your Changes:</emphasis>
14406 Commit the change by using the
14407 <filename>git commit --signoff</filename> command.
14408 Using the <filename>--signoff</filename> option identifies
14409 you as the person making the change and also satisfies
14410 the Developer's Certificate of Origin (DCO) shown earlier.
14411 </para>
14412
14413 <para>When you form a commit, you must follow certain
14414 standards established by the Yocto Project development
14415 team.
14416 See
14417 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14418 in the previous section for information on how to
14419 provide commit information that meets Yocto Project
14420 commit message standards.
14421 </para></listitem>
14422 <listitem><para>
14423 <emphasis>Format the Commit:</emphasis>
14424 Format the commit into an email message.
14425 To format commits, use the
14426 <filename>git format-patch</filename> command.
14427 When you provide the command, you must include a revision
14428 list or a number of patches as part of the command.
14429 For example, either of these two commands takes your most
14430 recent single commit and formats it as an email message in
14431 the current directory:
14432 <literallayout class='monospaced'>
14433 $ git format-patch -1
14434 </literallayout>
14435 or
14436 <literallayout class='monospaced'>
14437 $ git format-patch HEAD~
14438 </literallayout></para>
14439
14440 <para>After the command is run, the current directory
14441 contains a numbered <filename>.patch</filename> file for
14442 the commit.</para>
14443
14444 <para>If you provide several commits as part of the
14445 command, the <filename>git format-patch</filename> command
14446 produces a series of numbered files in the current
14447 directory – one for each commit.
14448 If you have more than one patch, you should also use the
14449 <filename>--cover</filename> option with the command,
14450 which generates a cover letter as the first "patch" in
14451 the series.
14452 You can then edit the cover letter to provide a
14453 description for the series of patches.
14454 For information on the
14455 <filename>git format-patch</filename> command,
14456 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14457 using the <filename>man git-format-patch</filename>
14458 command.
14459 <note>
14460 If you are or will be a frequent contributor to the
14461 Yocto Project or to OpenEmbedded, you might consider
14462 requesting a contrib area and the necessary associated
14463 rights.
14464 </note>
14465 </para></listitem>
14466 <listitem><para>
14467 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14468 Import the files into your mail client by using the
14469 <filename>git send-email</filename> command.
14470 <note>
14471 In order to use <filename>git send-email</filename>,
14472 you must have the proper Git packages installed on
14473 your host.
14474 For Ubuntu, Debian, and Fedora the package is
14475 <filename>git-email</filename>.
14476 </note></para>
14477
14478 <para>The <filename>git send-email</filename> command
14479 sends email by using a local or remote Mail Transport Agent
14480 (MTA) such as <filename>msmtp</filename>,
14481 <filename>sendmail</filename>, or through a direct
14482 <filename>smtp</filename> configuration in your Git
14483 <filename>~/.gitconfig</filename> file.
14484 If you are submitting patches through email only, it is
14485 very important that you submit them without any whitespace
14486 or HTML formatting that either you or your mailer
14487 introduces.
14488 The maintainer that receives your patches needs to be able
14489 to save and apply them directly from your emails.
14490 A good way to verify that what you are sending will be
14491 applicable by the maintainer is to do a dry run and send
14492 them to yourself and then save and apply them as the
14493 maintainer would.</para>
14494
14495 <para>The <filename>git send-email</filename> command is
14496 the preferred method for sending your patches using
14497 email since there is no risk of compromising whitespace
14498 in the body of the message, which can occur when you use
14499 your own mail client.
14500 The command also has several options that let you
14501 specify recipients and perform further editing of the
14502 email message.
14503 For information on how to use the
14504 <filename>git send-email</filename> command,
14505 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14506 the <filename>man git-send-email</filename> command.
14507 </para></listitem>
14508 </orderedlist>
14509 </para>
14510 </section>
14511 </section>
14512 </section>
14513
14514 <section id='working-with-licenses'>
14515 <title>Working With Licenses</title>
14516
14517 <para>
14518 As mentioned in the
14519 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
14520 section in the Yocto Project Overview and Concepts Manual,
14521 open source projects are open to the public and they
14522 consequently have different licensing structures in place.
14523 This section describes the mechanism by which the
14524 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
14525 tracks changes to licensing text and covers how to maintain open
14526 source license compliance during your project's lifecycle.
14527 The section also describes how to enable commercially licensed
14528 recipes, which by default are disabled.
14529 </para>
14530
14531 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
14532 <title>Tracking License Changes</title>
14533
14534 <para>
14535 The license of an upstream project might change in the future.
14536 In order to prevent these changes going unnoticed, the
14537 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
14538 variable tracks changes to the license text. The checksums are
14539 validated at the end of the configure step, and if the
14540 checksums do not match, the build will fail.
14541 </para>
14542
14543 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
14544 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
14545
14546 <para>
14547 The <filename>LIC_FILES_CHKSUM</filename>
14548 variable contains checksums of the license text in the
14549 source code for the recipe.
14550 Following is an example of how to specify
14551 <filename>LIC_FILES_CHKSUM</filename>:
14552 <literallayout class='monospaced'>
14553 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
14554 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
14555 file://licfile2.txt;endline=50;md5=zzzz \
14556 ..."
14557 </literallayout>
14558 <note><title>Notes</title>
14559 <itemizedlist>
14560 <listitem><para>
14561 When using "beginline" and "endline", realize
14562 that line numbering begins with one and not
14563 zero.
14564 Also, the included lines are inclusive (i.e.
14565 lines five through and including 29 in the
14566 previous example for
14567 <filename>licfile1.txt</filename>).
14568 </para></listitem>
14569 <listitem><para>
14570 When a license check fails, the selected license
14571 text is included as part of the QA message.
14572 Using this output, you can determine the exact
14573 start and finish for the needed license text.
14574 </para></listitem>
14575 </itemizedlist>
14576 </note>
14577 </para>
14578
14579 <para>
14580 The build system uses the
14581 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
14582 variable as the default directory when searching files
14583 listed in <filename>LIC_FILES_CHKSUM</filename>.
14584 The previous example employs the default directory.
14585 </para>
14586
14587 <para>
14588 Consider this next example:
14589 <literallayout class='monospaced'>
14590 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
14591 md5=bb14ed3c4cda583abc85401304b5cd4e"
14592 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
14593 </literallayout>
14594 </para>
14595
14596 <para>
14597 The first line locates a file in
14598 <filename>${S}/src/ls.c</filename> and isolates lines five
14599 through 16 as license text.
14600 The second line refers to a file in
14601 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
14602 </para>
14603
14604 <para>
14605 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
14606 mandatory for all recipes, unless the
14607 <filename>LICENSE</filename> variable is set to "CLOSED".
14608 </para>
14609 </section>
14610
14611 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
14612 <title>Explanation of Syntax</title>
14613
14614 <para>
14615 As mentioned in the previous section, the
14616 <filename>LIC_FILES_CHKSUM</filename> variable lists all
14617 the important files that contain the license text for the
14618 source code.
14619 It is possible to specify a checksum for an entire file,
14620 or a specific section of a file (specified by beginning and
14621 ending line numbers with the "beginline" and "endline"
14622 parameters, respectively).
14623 The latter is useful for source files with a license
14624 notice header, README documents, and so forth.
14625 If you do not use the "beginline" parameter, then it is
14626 assumed that the text begins on the first line of the file.
14627 Similarly, if you do not use the "endline" parameter,
14628 it is assumed that the license text ends with the last
14629 line of the file.
14630 </para>
14631
14632 <para>
14633 The "md5" parameter stores the md5 checksum of the license
14634 text.
14635 If the license text changes in any way as compared to
14636 this parameter then a mismatch occurs.
14637 This mismatch triggers a build failure and notifies
14638 the developer.
14639 Notification allows the developer to review and address
14640 the license text changes.
14641 Also note that if a mismatch occurs during the build,
14642 the correct md5 checksum is placed in the build log and
14643 can be easily copied to the recipe.
14644 </para>
14645
14646 <para>
14647 There is no limit to how many files you can specify using
14648 the <filename>LIC_FILES_CHKSUM</filename> variable.
14649 Generally, however, every project requires a few
14650 specifications for license tracking.
14651 Many projects have a "COPYING" file that stores the
14652 license information for all the source code files.
14653 This practice allows you to just track the "COPYING"
14654 file as long as it is kept up to date.
14655 <note><title>Tips</title>
14656 <itemizedlist>
14657 <listitem><para>
14658 If you specify an empty or invalid "md5"
14659 parameter,
14660 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
14661 returns an md5 mis-match
14662 error and displays the correct "md5" parameter
14663 value during the build.
14664 The correct parameter is also captured in
14665 the build log.
14666 </para></listitem>
14667 <listitem><para>
14668 If the whole file contains only license text,
14669 you do not need to use the "beginline" and
14670 "endline" parameters.
14671 </para></listitem>
14672 </itemizedlist>
14673 </note>
14674 </para>
14675 </section>
14676 </section>
14677
14678 <section id="enabling-commercially-licensed-recipes">
14679 <title>Enabling Commercially Licensed Recipes</title>
14680
14681 <para>
14682 By default, the OpenEmbedded build system disables
14683 components that have commercial or other special licensing
14684 requirements.
14685 Such requirements are defined on a
14686 recipe-by-recipe basis through the
14687 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
14688 variable definition in the affected recipe.
14689 For instance, the
14690 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14691 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014692 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014693 LICENSE_FLAGS = "commercial"
14694 </literallayout>
14695 Here is a slightly more complicated example that contains both
14696 an explicit recipe name and version (after variable expansion):
14697 <literallayout class='monospaced'>
14698 LICENSE_FLAGS = "license_${PN}_${PV}"
14699 </literallayout>
14700 In order for a component restricted by a
14701 <filename>LICENSE_FLAGS</filename> definition to be enabled and
14702 included in an image, it needs to have a matching entry in the
14703 global
14704 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
14705 variable, which is a variable typically defined in your
14706 <filename>local.conf</filename> file.
14707 For example, to enable the
14708 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
14709 package, you could add either the string
14710 "commercial_gst-plugins-ugly" or the more general string
14711 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
14712 See the
14713 "<link linkend='license-flag-matching'>License Flag Matching</link>"
14714 section for a full
14715 explanation of how <filename>LICENSE_FLAGS</filename> matching
14716 works.
14717 Here is the example:
14718 <literallayout class='monospaced'>
14719 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
14720 </literallayout>
14721 Likewise, to additionally enable the package built from the
14722 recipe containing
14723 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
14724 and assuming that the actual recipe name was
14725 <filename>emgd_1.10.bb</filename>, the following string would
14726 enable that package as well as the original
14727 <filename>gst-plugins-ugly</filename> package:
14728 <literallayout class='monospaced'>
14729 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
14730 </literallayout>
14731 As a convenience, you do not need to specify the complete
14732 license string in the whitelist for every package.
14733 You can use an abbreviated form, which consists
14734 of just the first portion or portions of the license
14735 string before the initial underscore character or characters.
14736 A partial string will match any license that contains the
14737 given string as the first portion of its license.
14738 For example, the following whitelist string will also match
14739 both of the packages previously mentioned as well as any other
14740 packages that have licenses starting with "commercial" or
14741 "license".
14742 <literallayout class='monospaced'>
14743 LICENSE_FLAGS_WHITELIST = "commercial license"
14744 </literallayout>
14745 </para>
14746
14747 <section id="license-flag-matching">
14748 <title>License Flag Matching</title>
14749
14750 <para>
14751 License flag matching allows you to control what recipes
14752 the OpenEmbedded build system includes in the build.
14753 Fundamentally, the build system attempts to match
14754 <filename>LICENSE_FLAGS</filename> strings found in recipes
14755 against <filename>LICENSE_FLAGS_WHITELIST</filename>
14756 strings found in the whitelist.
14757 A match causes the build system to include a recipe in the
14758 build, while failure to find a match causes the build
14759 system to exclude a recipe.
14760 </para>
14761
14762 <para>
14763 In general, license flag matching is simple.
14764 However, understanding some concepts will help you
14765 correctly and effectively use matching.
14766 </para>
14767
14768 <para>
14769 Before a flag
14770 defined by a particular recipe is tested against the
14771 contents of the whitelist, the expanded string
14772 <filename>_${PN}</filename> is appended to the flag.
14773 This expansion makes each
14774 <filename>LICENSE_FLAGS</filename> value recipe-specific.
14775 After expansion, the string is then matched against the
14776 whitelist.
14777 Thus, specifying
14778 <filename>LICENSE_FLAGS = "commercial"</filename>
14779 in recipe "foo", for example, results in the string
14780 <filename>"commercial_foo"</filename>.
14781 And, to create a match, that string must appear in the
14782 whitelist.
14783 </para>
14784
14785 <para>
14786 Judicious use of the <filename>LICENSE_FLAGS</filename>
14787 strings and the contents of the
14788 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
14789 allows you a lot of flexibility for including or excluding
14790 recipes based on licensing.
14791 For example, you can broaden the matching capabilities by
14792 using license flags string subsets in the whitelist.
14793 <note>
14794 When using a string subset, be sure to use the part of
14795 the expanded string that precedes the appended
14796 underscore character (e.g.
14797 <filename>usethispart_1.3</filename>,
14798 <filename>usethispart_1.4</filename>, and so forth).
14799 </note>
14800 For example, simply specifying the string "commercial" in
14801 the whitelist matches any expanded
14802 <filename>LICENSE_FLAGS</filename> definition that starts
14803 with the string "commercial" such as "commercial_foo" and
14804 "commercial_bar", which are the strings the build system
14805 automatically generates for hypothetical recipes named
14806 "foo" and "bar" assuming those recipes simply specify the
14807 following:
14808 <literallayout class='monospaced'>
14809 LICENSE_FLAGS = "commercial"
14810 </literallayout>
14811 Thus, you can choose to exhaustively
14812 enumerate each license flag in the whitelist and
14813 allow only specific recipes into the image, or
14814 you can use a string subset that causes a broader range of
14815 matches to allow a range of recipes into the image.
14816 </para>
14817
14818 <para>
14819 This scheme works even if the
14820 <filename>LICENSE_FLAGS</filename> string already
14821 has <filename>_${PN}</filename> appended.
14822 For example, the build system turns the license flag
14823 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
14824 would match both the general "commercial" and the specific
14825 "commercial_1.2_foo" strings found in the whitelist, as
14826 expected.
14827 </para>
14828
14829 <para>
14830 Here are some other scenarios:
14831 <itemizedlist>
14832 <listitem><para>
14833 You can specify a versioned string in the recipe
14834 such as "commercial_foo_1.2" in a "foo" recipe.
14835 The build system expands this string to
14836 "commercial_foo_1.2_foo".
14837 Combine this license flag with a whitelist that has
14838 the string "commercial" and you match the flag
14839 along with any other flag that starts with the
14840 string "commercial".
14841 </para></listitem>
14842 <listitem><para>
14843 Under the same circumstances, you can use
14844 "commercial_foo" in the whitelist and the build
14845 system not only matches "commercial_foo_1.2" but
14846 also matches any license flag with the string
14847 "commercial_foo", regardless of the version.
14848 </para></listitem>
14849 <listitem><para>
14850 You can be very specific and use both the
14851 package and version parts in the whitelist (e.g.
14852 "commercial_foo_1.2") to specifically match a
14853 versioned recipe.
14854 </para></listitem>
14855 </itemizedlist>
14856 </para>
14857 </section>
14858
14859 <section id="other-variables-related-to-commercial-licenses">
14860 <title>Other Variables Related to Commercial Licenses</title>
14861
14862 <para>
14863 Other helpful variables related to commercial
14864 license handling exist and are defined in the
14865 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
14866 <literallayout class='monospaced'>
14867 COMMERCIAL_AUDIO_PLUGINS ?= ""
14868 COMMERCIAL_VIDEO_PLUGINS ?= ""
14869 </literallayout>
14870 If you want to enable these components, you can do so by
14871 making sure you have statements similar to the following
14872 in your <filename>local.conf</filename> configuration file:
14873 <literallayout class='monospaced'>
14874 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
14875 gst-plugins-ugly-mpegaudioparse"
14876 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
14877 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
14878 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
14879 </literallayout>
14880 Of course, you could also create a matching whitelist
14881 for those components using the more general "commercial"
14882 in the whitelist, but that would also enable all the
14883 other packages with <filename>LICENSE_FLAGS</filename>
14884 containing "commercial", which you may or may not want:
14885 <literallayout class='monospaced'>
14886 LICENSE_FLAGS_WHITELIST = "commercial"
14887 </literallayout>
14888 </para>
14889
14890 <para>
14891 Specifying audio and video plug-ins as part of the
14892 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
14893 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
14894 (along with the enabling
14895 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
14896 plug-ins or components into built images, thus adding
14897 support for media formats or components.
14898 </para>
14899 </section>
14900 </section>
14901
14902 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
14903 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
14904
14905 <para>
14906 One of the concerns for a development organization using open source
14907 software is how to maintain compliance with various open source
14908 licensing during the lifecycle of the product.
14909 While this section does not provide legal advice or
14910 comprehensively cover all scenarios, it does
14911 present methods that you can use to
14912 assist you in meeting the compliance requirements during a software
14913 release.
14914 </para>
14915
14916 <para>
14917 With hundreds of different open source licenses that the Yocto
14918 Project tracks, it is difficult to know the requirements of each
14919 and every license.
14920 However, the requirements of the major FLOSS licenses can begin
14921 to be covered by
14922 assuming that three main areas of concern exist:
14923 <itemizedlist>
14924 <listitem><para>Source code must be provided.</para></listitem>
14925 <listitem><para>License text for the software must be
14926 provided.</para></listitem>
14927 <listitem><para>Compilation scripts and modifications to the
14928 source code must be provided.
14929 </para></listitem>
14930 </itemizedlist>
14931 There are other requirements beyond the scope of these
14932 three and the methods described in this section
14933 (e.g. the mechanism through which source code is distributed).
14934 </para>
14935
14936 <para>
14937 As different organizations have different methods of complying with
14938 open source licensing, this section is not meant to imply that
14939 there is only one single way to meet your compliance obligations,
14940 but rather to describe one method of achieving compliance.
14941 The remainder of this section describes methods supported to meet the
14942 previously mentioned three requirements.
14943 Once you take steps to meet these requirements,
14944 and prior to releasing images, sources, and the build system,
14945 you should audit all artifacts to ensure completeness.
14946 <note>
14947 The Yocto Project generates a license manifest during
14948 image creation that is located
14949 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
14950 to assist with any audits.
14951 </note>
14952 </para>
14953
14954 <section id='providing-the-source-code'>
14955 <title>Providing the Source Code</title>
14956
14957 <para>
14958 Compliance activities should begin before you generate the
14959 final image.
14960 The first thing you should look at is the requirement that
14961 tops the list for most compliance groups - providing
14962 the source.
14963 The Yocto Project has a few ways of meeting this
14964 requirement.
14965 </para>
14966
14967 <para>
14968 One of the easiest ways to meet this requirement is
14969 to provide the entire
14970 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
14971 used by the build.
14972 This method, however, has a few issues.
14973 The most obvious is the size of the directory since it includes
14974 all sources used in the build and not just the source used in
14975 the released image.
14976 It will include toolchain source, and other artifacts, which
14977 you would not generally release.
14978 However, the more serious issue for most companies is accidental
14979 release of proprietary software.
14980 The Yocto Project provides an
14981 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
14982 class to help avoid some of these concerns.
14983 </para>
14984
14985 <para>
14986 Before you employ <filename>DL_DIR</filename> or the
14987 <filename>archiver</filename> class, you need to decide how
14988 you choose to provide source.
14989 The source <filename>archiver</filename> class can generate
14990 tarballs and SRPMs and can create them with various levels of
14991 compliance in mind.
14992 </para>
14993
14994 <para>
14995 One way of doing this (but certainly not the only way) is to
14996 release just the source as a tarball.
14997 You can do this by adding the following to the
14998 <filename>local.conf</filename> file found in the
14999 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15000 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015001 INHERIT += "archiver"
15002 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015003 </literallayout>
15004 During the creation of your image, the source from all
15005 recipes that deploy packages to the image is placed within
15006 subdirectories of
15007 <filename>DEPLOY_DIR/sources</filename> based on the
15008 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15009 for each recipe.
15010 Releasing the entire directory enables you to comply with
15011 requirements concerning providing the unmodified source.
15012 It is important to note that the size of the directory can
15013 get large.
15014 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015015
Brad Bishop316dfdd2018-06-25 12:45:53 -040015016 <para>
15017 A way to help mitigate the size issue is to only release
15018 tarballs for licenses that require the release of
15019 source.
15020 Let us assume you are only concerned with GPL code as
15021 identified by running the following script:
15022 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015023 # Script to archive a subset of packages matching specific license(s)
15024 # Source and license files are copied into sub folders of package folder
15025 # Must be run from build folder
15026 #!/bin/bash
15027 src_release_dir="source-release"
15028 mkdir -p $src_release_dir
15029 for a in tmp/deploy/sources/*; do
15030 for d in $a/*; do
15031 # Get package name from path
15032 p=`basename $d`
15033 p=${p%-*}
15034 p=${p%-*}
15035 # Only archive GPL packages (update *GPL* regex for your license check)
15036 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15037 if [ $numfiles -gt 1 ]; then
15038 echo Archiving $p
15039 mkdir -p $src_release_dir/$p/source
15040 cp $d/* $src_release_dir/$p/source 2> /dev/null
15041 mkdir -p $src_release_dir/$p/license
15042 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15043 fi
15044 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015045 done
15046 </literallayout>
15047 At this point, you could create a tarball from the
15048 <filename>gpl_source_release</filename> directory and
15049 provide that to the end user.
15050 This method would be a step toward achieving compliance
15051 with section 3a of GPLv2 and with section 6 of GPLv3.
15052 </para>
15053 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015054
Brad Bishop316dfdd2018-06-25 12:45:53 -040015055 <section id='providing-license-text'>
15056 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015057
Brad Bishop316dfdd2018-06-25 12:45:53 -040015058 <para>
15059 One requirement that is often overlooked is inclusion
15060 of license text.
15061 This requirement also needs to be dealt with prior to
15062 generating the final image.
15063 Some licenses require the license text to accompany
15064 the binary.
15065 You can achieve this by adding the following to your
15066 <filename>local.conf</filename> file:
15067 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015068 COPY_LIC_MANIFEST = "1"
15069 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015070 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015071 </literallayout>
15072 Adding these statements to the configuration file ensures
15073 that the licenses collected during package generation
15074 are included on your image.
15075 <note>
15076 <para>Setting all three variables to "1" results in the
15077 image having two copies of the same license file.
15078 One copy resides in
15079 <filename>/usr/share/common-licenses</filename> and
15080 the other resides in
15081 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015082
Brad Bishop316dfdd2018-06-25 12:45:53 -040015083 <para>The reason for this behavior is because
15084 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15085 and
15086 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15087 add a copy of the license when the image is built but do
15088 not offer a path for adding licenses for newly installed
15089 packages to an image.
15090 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15091 adds a separate package and an upgrade path for adding
15092 licenses to an image.</para>
15093 </note>
15094 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015095
Brad Bishop316dfdd2018-06-25 12:45:53 -040015096 <para>
15097 As the source <filename>archiver</filename> class has already
15098 archived the original
15099 unmodified source that contains the license files,
15100 you would have already met the requirements for inclusion
15101 of the license information with source as defined by the GPL
15102 and other open source licenses.
15103 </para>
15104 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015105
Brad Bishop316dfdd2018-06-25 12:45:53 -040015106 <section id='providing-compilation-scripts-and-source-code-modifications'>
15107 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015108
Brad Bishop316dfdd2018-06-25 12:45:53 -040015109 <para>
15110 At this point, we have addressed all we need to
15111 prior to generating the image.
15112 The next two requirements are addressed during the final
15113 packaging of the release.
15114 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015115
Brad Bishop316dfdd2018-06-25 12:45:53 -040015116 <para>
15117 By releasing the version of the OpenEmbedded build system
15118 and the layers used during the build, you will be providing both
15119 compilation scripts and the source code modifications in one
15120 step.
15121 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015122
Brad Bishop316dfdd2018-06-25 12:45:53 -040015123 <para>
15124 If the deployment team has a
15125 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15126 and a distro layer, and those those layers are used to patch,
15127 compile, package, or modify (in any way) any open source
15128 software included in your released images, you
15129 might be required to release those layers under section 3 of
15130 GPLv2 or section 1 of GPLv3.
15131 One way of doing that is with a clean
15132 checkout of the version of the Yocto Project and layers used
15133 during your build.
15134 Here is an example:
15135 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015136 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15137 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015138 $ cd poky
15139 # We built using the release_branch for our layers
15140 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15141 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15142 # clean up the .git repos
15143 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015144 </literallayout>
15145 One thing a development organization might want to consider
15146 for end-user convenience is to modify
15147 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15148 ensure that when the end user utilizes the released build
15149 system to build an image, the development organization's
15150 layers are included in the <filename>bblayers.conf</filename>
15151 file automatically:
15152 <literallayout class='monospaced'>
15153 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015154 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015155 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015156
15157 BBPATH = "${TOPDIR}"
15158 BBFILES ?= ""
15159
15160 BBLAYERS ?= " \
15161 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015162 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015163 ##OEROOT##/meta-yocto-bsp \
15164 ##OEROOT##/meta-mylayer \
15165 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015166 </literallayout>
15167 Creating and providing an archive of the
15168 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15169 layers (recipes, configuration files, and so forth)
15170 enables you to meet your
15171 requirements to include the scripts to control compilation
15172 as well as any modifications to the original source.
15173 </para>
15174 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015175 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015176
15177 <section id='copying-licenses-that-do-not-exist'>
15178 <title>Copying Licenses that Do Not Exist</title>
15179
15180 <para>
15181 Some packages, such as the linux-firmware package, have many
15182 licenses that are not in any way common.
15183 You can avoid adding a lot of these types of common license
15184 files, which are only applicable to a specific package, by using
15185 the
15186 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15187 variable.
15188 Using this variable also avoids QA errors when you use a
15189 non-common, non-CLOSED license in a recipe.
15190 </para>
15191
15192 <para>
15193 The following is an example that uses the
15194 <filename>LICENSE.Abilis.txt</filename>
15195 file as the license from the fetched source:
15196 <literallayout class='monospaced'>
15197 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15198 </literallayout>
15199 </para>
15200 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015201 </section>
15202
15203 <section id='using-the-error-reporting-tool'>
15204 <title>Using the Error Reporting Tool</title>
15205
15206 <para>
15207 The error reporting tool allows you to
15208 submit errors encountered during builds to a central database.
15209 Outside of the build environment, you can use a web interface to
15210 browse errors, view statistics, and query for errors.
15211 The tool works using a client-server system where the client
15212 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015213 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015214 (e.g. <filename>poky</filename>).
15215 The server receives the information collected and saves it in a
15216 database.
15217 </para>
15218
15219 <para>
15220 A live instance of the error reporting server exists at
15221 <ulink url='http://errors.yoctoproject.org'></ulink>.
15222 This server exists so that when you want to get help with
15223 build failures, you can submit all of the information on the
15224 failure easily and then point to the URL in your bug report
15225 or send an email to the mailing list.
15226 <note>
15227 If you send error reports to this server, the reports become
15228 publicly visible.
15229 </note>
15230 </para>
15231
15232 <section id='enabling-and-using-the-tool'>
15233 <title>Enabling and Using the Tool</title>
15234
15235 <para>
15236 By default, the error reporting tool is disabled.
15237 You can enable it by inheriting the
15238 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15239 class by adding the following statement to the end of
15240 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015241 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015242 <literallayout class='monospaced'>
15243 INHERIT += "report-error"
15244 </literallayout>
15245 </para>
15246
15247 <para>
15248 By default, the error reporting feature stores information in
15249 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15250 However, you can specify a directory to use by adding the following
15251 to your <filename>local.conf</filename> file:
15252 <literallayout class='monospaced'>
15253 ERR_REPORT_DIR = "path"
15254 </literallayout>
15255 Enabling error reporting causes the build process to collect
15256 the errors and store them in a file as previously described.
15257 When the build system encounters an error, it includes a
15258 command as part of the console output.
15259 You can run the command to send the error file to the server.
15260 For example, the following command sends the errors to an
15261 upstream server:
15262 <literallayout class='monospaced'>
15263 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15264 </literallayout>
15265 In the previous example, the errors are sent to a public
15266 database available at
15267 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15268 used by the entire community.
15269 If you specify a particular server, you can send the errors
15270 to a different database.
15271 Use the following command for more information on available
15272 options:
15273 <literallayout class='monospaced'>
15274 $ send-error-report --help
15275 </literallayout>
15276 </para>
15277
15278 <para>
15279 When sending the error file, you are prompted to review the
15280 data being sent as well as to provide a name and optional
15281 email address.
15282 Once you satisfy these prompts, the command returns a link
15283 from the server that corresponds to your entry in the database.
15284 For example, here is a typical link:
15285 <literallayout class='monospaced'>
15286 http://errors.yoctoproject.org/Errors/Details/9522/
15287 </literallayout>
15288 Following the link takes you to a web interface where you can
15289 browse, query the errors, and view statistics.
15290 </para>
15291 </section>
15292
15293 <section id='disabling-the-tool'>
15294 <title>Disabling the Tool</title>
15295
15296 <para>
15297 To disable the error reporting feature, simply remove or comment
15298 out the following statement from the end of your
15299 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015300 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015301 <literallayout class='monospaced'>
15302 INHERIT += "report-error"
15303 </literallayout>
15304 </para>
15305 </section>
15306
15307 <section id='setting-up-your-own-error-reporting-server'>
15308 <title>Setting Up Your Own Error Reporting Server</title>
15309
15310 <para>
15311 If you want to set up your own error reporting server, you
15312 can obtain the code from the Git repository at
15313 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15314 Instructions on how to set it up are in the README document.
15315 </para>
15316 </section>
15317 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015318
15319 <section id="dev-using-wayland-and-weston">
15320 <title>Using Wayland and Weston</title>
15321
15322 <para>
15323 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15324 is a computer display server protocol that
15325 provides a method for compositing window managers to communicate
15326 directly with applications and video hardware and expects them to
15327 communicate with input hardware using other libraries.
15328 Using Wayland with supporting targets can result in better control
15329 over graphics frame rendering than an application might otherwise
15330 achieve.
15331 </para>
15332
15333 <para>
15334 The Yocto Project provides the Wayland protocol libraries and the
15335 reference
15336 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15337 compositor as part of its release.
15338 You can find the integrated packages in the
15339 <filename>meta</filename> layer of the
15340 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15341 Specifically, you can find the recipes that build both Wayland
15342 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15343 </para>
15344
15345 <para>
15346 You can build both the Wayland and Weston packages for use only
15347 with targets that accept the
15348 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15349 which is also known as Mesa DRI.
15350 This implies that you cannot build and use the packages if your
15351 target uses, for example, the
15352 <trademark class='registered'>Intel</trademark> Embedded Media
15353 and Graphics Driver
15354 (<trademark class='registered'>Intel</trademark> EMGD) that
15355 overrides Mesa DRI.
15356 <note>
15357 Due to lack of EGL support, Weston 1.0.3 will not run
15358 directly on the emulated QEMU hardware.
15359 However, this version of Weston will run under X emulation
15360 without issues.
15361 </note>
15362 </para>
15363
15364 <para>
15365 This section describes what you need to do to implement Wayland and
15366 use the Weston compositor when building an image for a supporting
15367 target.
15368 </para>
15369
15370 <section id="enabling-wayland-in-an-image">
15371 <title>Enabling Wayland in an Image</title>
15372
15373 <para>
15374 To enable Wayland, you need to enable it to be built and enable
15375 it to be included (installed) in the image.
15376 </para>
15377
15378 <section id="enable-building">
15379 <title>Building</title>
15380
15381 <para>
15382 To cause Mesa to build the <filename>wayland-egl</filename>
15383 platform and Weston to build Wayland with Kernel Mode
15384 Setting
15385 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15386 support, include the "wayland" flag in the
15387 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15388 statement in your <filename>local.conf</filename> file:
15389 <literallayout class='monospaced'>
15390 DISTRO_FEATURES_append = " wayland"
15391 </literallayout>
15392 <note>
15393 If X11 has been enabled elsewhere, Weston will build
15394 Wayland with X11 support
15395 </note>
15396 </para>
15397 </section>
15398
15399 <section id="enable-installation-in-an-image">
15400 <title>Installing</title>
15401
15402 <para>
15403 To install the Wayland feature into an image, you must
15404 include the following
15405 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15406 statement in your <filename>local.conf</filename> file:
15407 <literallayout class='monospaced'>
15408 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15409 </literallayout>
15410 </para>
15411 </section>
15412 </section>
15413
15414 <section id="running-weston">
15415 <title>Running Weston</title>
15416
15417 <para>
15418 To run Weston inside X11, enabling it as described earlier and
15419 building a Sato image is sufficient.
15420 If you are running your image under Sato, a Weston Launcher
15421 appears in the "Utility" category.
15422 </para>
15423
15424 <para>
15425 Alternatively, you can run Weston through the command-line
15426 interpretor (CLI), which is better suited for development work.
15427 To run Weston under the CLI, you need to do the following after
15428 your image is built:
15429 <orderedlist>
15430 <listitem><para>
15431 Run these commands to export
15432 <filename>XDG_RUNTIME_DIR</filename>:
15433 <literallayout class='monospaced'>
15434 mkdir -p /tmp/$USER-weston
15435 chmod 0700 /tmp/$USER-weston
15436 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15437 </literallayout>
15438 </para></listitem>
15439 <listitem><para>
15440 Launch Weston in the shell:
15441 <literallayout class='monospaced'>
15442 weston
15443 </literallayout></para></listitem>
15444 </orderedlist>
15445 </para>
15446 </section>
15447 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015448</chapter>
15449
15450<!--
15451vim: expandtab tw=80 ts=4
15452-->