blob: f72f81f5518f934d470ac23a1095731d8b615dbb [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='extendpoky'>
6
7<title>Common Tasks</title>
8 <para>
9 This chapter describes fundamental procedures such as creating layers,
10 adding new software packages, extending or customizing images,
11 porting work to new hardware (adding a new machine), and so forth.
12 You will find that the procedures documented here occur often in the
13 development cycle using the Yocto Project.
14 </para>
15
16 <section id="understanding-and-creating-layers">
17 <title>Understanding and Creating Layers</title>
18
19 <para>
20 The OpenEmbedded build system supports organizing
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> into
22 multiple layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 Layers allow you to isolate different types of customizations from
24 each other.
Brad Bishop316dfdd2018-06-25 12:45:53 -040025 For introductory information on the Yocto Project Layer Model,
26 see the
27 "<ulink url='&YOCTO_DOCS_OM_URL;#the-yocto-project-layer-model'>The Yocto Project Layer Model</ulink>"
28 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 </para>
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 <section id='creating-your-own-layer'>
32 <title>Creating Your Own Layer</title>
33
34 <para>
35 It is very easy to create your own layers to use with the
36 OpenEmbedded build system.
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 The Yocto Project ships with tools that speed up creating
38 layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 This section describes the steps you perform by hand to create
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 layers so that you can better understand them.
41 For information about the layer-creation tools, see the
42 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 section in the Yocto Project Board Support Package (BSP)
44 Developer's Guide and the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 section further down in this manual.
47 </para>
48
49 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040050 Follow these general steps to create your layer without using
51 tools:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 <orderedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -040053 <listitem><para>
54 <emphasis>Check Existing Layers:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 Before creating a new layer, you should be sure someone
56 has not already created a layer containing the Metadata
57 you need.
58 You can see the
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 <ulink url='http://layers.openembedded.org/layerindex/layers/'>OpenEmbedded Metadata Index</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 for a list of layers from the OpenEmbedded community
61 that can be used in the Yocto Project.
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 You could find a layer that is identical or close to
63 what you need.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 <listitem><para>
66 <emphasis>Create a Directory:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 Create the directory for your layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -040068 When you create the layer, be sure to create the
69 directory in an area not associated with the
70 Yocto Project
71 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
72 (e.g. the cloned <filename>poky</filename> repository).
73 </para>
74
75 <para>While not strictly required, prepend the name of
76 the directory with the string "meta-".
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 For example:
78 <literallayout class='monospaced'>
79 meta-mylayer
80 meta-GUI_xyz
81 meta-mymachine
82 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040083 With rare exceptions, a layer's name follows this
84 form:
85 <literallayout class='monospaced'>
86 meta-<replaceable>root_name</replaceable>
87 </literallayout>
88 Following this layer naming convention can
89 save you trouble later when tools, components, or
90 variables "assume" your layer name begins with "meta-".
91 A notable example is in configuration files as
92 shown in the following step where layer names without
93 the "meta-" string are appended
94 to several variables used in the configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 <listitem><para id='dev-layer-config-file-description'>
97 <emphasis>Create a Layer Configuration File:</emphasis>
98 Inside your new layer folder, you need to create a
99 <filename>conf/layer.conf</filename> file.
100 It is easiest to take an existing layer configuration
101 file and copy that to your layer's
102 <filename>conf</filename> directory and then modify the
103 file as needed.</para>
104
105 <para>The
106 <filename>meta-yocto-bsp/conf/layer.conf</filename> file
107 in the Yocto Project
108 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf'>Source Repositories</ulink>
109 demonstrates the required syntax.
110 For your layer, you need to replace "yoctobsp" with
111 a unique identifier for your layer (e.g. "machinexyz"
112 for a layer named "meta-machinexyz"):
113 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 # We have a conf and classes directory, add to BBPATH
115 BBPATH .= ":${LAYERDIR}"
116
117 # We have recipes-* directories, add to BBFILES
118 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
119 ${LAYERDIR}/recipes-*/*/*.bbappend"
120
121 BBFILE_COLLECTIONS += "yoctobsp"
122 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
123 BBFILE_PRIORITY_yoctobsp = "5"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 LAYERVERSION_yoctobsp = "4"
125 LAYERSERIES_COMPAT_yoctobsp = "&DISTRO_NAME_NO_CAP;"
126 </literallayout>
127 Following is an explanation of the layer configuration
128 file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130 <listitem><para>
131 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>:
132 Adds the layer's root directory to BitBake's
133 search path.
134 Through the use of the
135 <filename>BBPATH</filename> variable, BitBake
136 locates class files
137 (<filename>.bbclass</filename>),
138 configuration files, and files that are
139 included with <filename>include</filename> and
140 <filename>require</filename> statements.
141 For these cases, BitBake uses the first file
142 that matches the name found in
143 <filename>BBPATH</filename>.
144 This is similar to the way the
145 <filename>PATH</filename> variable is used for
146 binaries.
147 It is recommended, therefore, that you use
148 unique class and configuration filenames in
149 your custom layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400151 <listitem><para>
152 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>:
153 Defines the location for all recipes in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155 </para></listitem>
156 <listitem><para>
157 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'><filename>BBFILE_COLLECTIONS</filename></ulink>:
158 Establishes the current layer through a
159 unique identifier that is used throughout the
160 OpenEmbedded build system to refer to the layer.
161 In this example, the identifier "yoctobsp" is
162 the representation for the container layer
163 named "meta-yocto-bsp".
164 </para></listitem>
165 <listitem><para>
166 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'><filename>BBFILE_PATTERN</filename></ulink>:
167 Expands immediately during parsing to
168 provide the directory of the layer.
169 </para></listitem>
170 <listitem><para>
171 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>:
172 Establishes a priority to use for
173 recipes in the layer when the OpenEmbedded build
174 finds recipes of the same name in different
175 layers.
176 </para></listitem>
177 <listitem><para>
178 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'><filename>LAYERVERSION</filename></ulink>:
179 Establishes a version number for the layer.
180 You can use this version number to specify this
181 exact version of the layer as a dependency when
182 using the
183 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDEPENDS'><filename>LAYERDEPENDS</filename></ulink>
184 variable.
185 </para></listitem>
186 <listitem><para>
187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERSERIES_COMPAT'><filename>LAYERSERIES_COMPAT</filename></ulink>:
188 Lists the
189 <ulink url='&YOCTO_WIKI_URL;/wiki/Releases'>Yocto Project</ulink>
190 releases for which the current version is
191 compatible.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800192 This variable is a good way to indicate if
193 your particular layer is current.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194 </para></listitem>
195 </itemizedlist>
196 </para></listitem>
197 <listitem><para>
198 <emphasis>Add Content:</emphasis>
199 Depending on the type of layer, add the content.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 If the layer adds support for a machine, add the machine
201 configuration in a <filename>conf/machine/</filename>
202 file within the layer.
203 If the layer adds distro policy, add the distro
204 configuration in a <filename>conf/distro/</filename>
205 file within the layer.
206 If the layer introduces new recipes, put the recipes
207 you need in <filename>recipes-*</filename>
208 subdirectories within the layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400209 <note>
210 For an explanation of layer hierarchy that
211 is compliant with the Yocto Project, see
212 the
213 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout'>Example Filesystem Layout</ulink>"
214 section in the Yocto Project Board
215 Support Package (BSP) Developer's Guide.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 </note>
217 </para></listitem>
218 <listitem><para>
219 <emphasis>Optionally Test for Compatibility:</emphasis>
220 If you want permission to use the Yocto Project
221 Compatibility logo with your layer or application that
222 uses your layer, perform the steps to apply for
223 compatibility.
224 See the
225 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
226 section for more information.
227 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 </orderedlist>
229 </para>
230 </section>
231
232 <section id='best-practices-to-follow-when-creating-layers'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500233 <title>Following Best Practices When Creating Layers</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234
235 <para>
236 To create layers that are easier to maintain and that will
237 not impact builds for other machines, you should consider the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 information in the following list:
239 <itemizedlist>
240 <listitem><para>
241 <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis>
242 In other words, do not copy an entire recipe into your
243 layer and then modify it.
244 Rather, use an append file
245 (<filename>.bbappend</filename>) to override only those
246 parts of the original recipe you need to modify.
247 </para></listitem>
248 <listitem><para>
249 <emphasis>Avoid Duplicating Include Files:</emphasis>
250 Use append files (<filename>.bbappend</filename>)
251 for each recipe that uses an include file.
252 Or, if you are introducing a new recipe that requires
253 the included file, use the path relative to the
254 original layer directory to refer to the file.
255 For example, use
256 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
257 instead of
258 <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
259 If you're finding you have to overlay the include file,
260 it could indicate a deficiency in the include file in
261 the layer to which it originally belongs.
262 If this is the case, you should try to address that
263 deficiency instead of overlaying the include file.
264 For example, you could address this by getting the
265 maintainer of the include file to add a variable or
266 variables to make it easy to override the parts needing
267 to be overridden.
268 </para></listitem>
269 <listitem><para>
270 <emphasis>Structure Your Layers:</emphasis>
271 Proper use of overrides within append files and
272 placement of machine-specific files within your layer
273 can ensure that a build is not using the wrong Metadata
274 and negatively impacting a build for a different
275 machine.
276 Following are some examples:
277 <itemizedlist>
278 <listitem><para>
279 <emphasis>Modify Variables to Support a
280 Different Machine:</emphasis>
281 Suppose you have a layer named
282 <filename>meta-one</filename> that adds support
283 for building machine "one".
284 To do so, you use an append file named
285 <filename>base-files.bbappend</filename> and
286 create a dependency on "foo" by altering the
287 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
288 variable:
289 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 DEPENDS = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 </literallayout>
292 The dependency is created during any build that
293 includes the layer
294 <filename>meta-one</filename>.
295 However, you might not want this dependency
296 for all machines.
297 For example, suppose you are building for
298 machine "two" but your
299 <filename>bblayers.conf</filename> file has the
300 <filename>meta-one</filename> layer included.
301 During the build, the
302 <filename>base-files</filename> for machine
303 "two" will also have the dependency on
304 <filename>foo</filename>.</para>
305 <para>To make sure your changes apply only when
306 building machine "one", use a machine override
307 with the <filename>DEPENDS</filename> statement:
308 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 DEPENDS_one = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500310 </literallayout>
311 You should follow the same strategy when using
312 <filename>_append</filename> and
313 <filename>_prepend</filename> operations:
314 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 DEPENDS_append_one = " foo"
316 DEPENDS_prepend_one = "foo "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 </literallayout>
318 As an actual example, here's a line from the recipe
319 for gnutls, which adds dependencies on
320 "argp-standalone" when building with the musl C
321 library:
322 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323 DEPENDS_append_libc-musl = " argp-standalone"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500324 </literallayout>
325 <note>
326 Avoiding "+=" and "=+" and using
327 machine-specific
328 <filename>_append</filename>
329 and <filename>_prepend</filename> operations
330 is recommended as well.
331 </note>
332 </para></listitem>
333 <listitem><para>
334 <emphasis>Place Machine-Specific Files in
335 Machine-Specific Locations:</emphasis>
336 When you have a base recipe, such as
337 <filename>base-files.bb</filename>, that
338 contains a
339 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
340 statement to a file, you can use an append file
341 to cause the build to use your own version of
342 the file.
343 For example, an append file in your layer at
344 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
345 could extend
346 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
347 using
348 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
349 as follows:
350 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352 </literallayout>
353 The build for machine "one" will pick up your
354 machine-specific file as long as you have the
355 file in
356 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
357 However, if you are building for a different
358 machine and the
359 <filename>bblayers.conf</filename> file includes
360 the <filename>meta-one</filename> layer and
361 the location of your machine-specific file is
362 the first location where that file is found
363 according to <filename>FILESPATH</filename>,
364 builds for all machines will also use that
365 machine-specific file.</para>
366 <para>You can make sure that a machine-specific
367 file is used for a particular machine by putting
368 the file in a subdirectory specific to the
369 machine.
370 For example, rather than placing the file in
371 <filename>meta-one/recipes-core/base-files/base-files/</filename>
372 as shown above, put it in
373 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
374 Not only does this make sure the file is used
375 only when building for machine "one", but the
376 build process locates the file more quickly.</para>
377 <para>In summary, you need to place all files
378 referenced from <filename>SRC_URI</filename>
379 in a machine-specific subdirectory within the
380 layer in order to restrict those files to
381 machine-specific builds.
382 </para></listitem>
383 </itemizedlist>
384 </para></listitem>
385 <listitem><para>
386 <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis>
387 If you want permission to use the
388 Yocto Project Compatibility logo with your layer
389 or application that uses your layer, perform the
390 steps to apply for compatibility.
391 See the
392 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
393 section for more information.
394 </para></listitem>
395 <listitem><para>
396 <emphasis>Follow the Layer Naming Convention:</emphasis>
397 Store custom layers in a Git repository that use the
398 <filename>meta-<replaceable>layer_name</replaceable></filename>
399 format.
400 </para></listitem>
401 <listitem><para>
402 <emphasis>Group Your Layers Locally:</emphasis>
403 Clone your repository alongside other cloned
404 <filename>meta</filename> directories from the
405 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
406 </para></listitem>
407 </itemizedlist>
408 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 </section>
410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 <section id='making-sure-your-layer-is-compatible-with-yocto-project'>
412 <title>Making Sure Your Layer is Compatible With Yocto Project</title>
413
414 <para>
415 When you create a layer used with the Yocto Project, it is
416 advantageous to make sure that the layer interacts well with
417 existing Yocto Project layers (i.e. the layer is compatible
418 with the Yocto Project).
419 Ensuring compatibility makes the layer easy to be consumed
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500420 by others in the Yocto Project community and could allow you
421 permission to use the Yocto Project Compatible Logo.
422 <note>
423 Only Yocto Project member organizations are permitted to
424 use the Yocto Project Compatible Logo.
425 The logo is not available for general use.
426 For information on how to become a Yocto Project member
427 organization, see the
428 <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500429 </note>
430 </para>
431
432 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500433 The Yocto Project Compatibility Program consists of a layer
434 application process that requests permission to use the Yocto
435 Project Compatibility Logo for your layer and application.
436 The process consists of two parts:
437 <orderedlist>
438 <listitem><para>
439 Successfully passing a script
440 (<filename>yocto-check-layer</filename>) that
441 when run against your layer, tests it against
442 constraints based on experiences of how layers have
443 worked in the real world and where pitfalls have been
444 found.
445 Getting a "PASS" result from the script is required for
446 successful compatibility registration.
447 </para></listitem>
448 <listitem><para>
449 Completion of an application acceptance form, which
450 you can find at
451 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
452 </para></listitem>
453 </orderedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 </para>
455
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 <para>
457 To be granted permission to use the logo, you need to satisfy
458 the following:
459 <itemizedlist>
460 <listitem><para>
461 Be able to check the box indicating that you
462 got a "PASS" when running the script against your
463 layer.
464 </para></listitem>
465 <listitem><para>
466 Answer "Yes" to the questions on the form or have an
467 acceptable explanation for any questions answered "No".
468 </para></listitem>
469 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400470 Be a Yocto Project Member Organization.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500471 </para></listitem>
472 </itemizedlist>
473 </para>
474
475 <para>
476 The remainder of this section presents information on the
477 registration form and on the
478 <filename>yocto-check-layer</filename> script.
479 </para>
480
481 <section id='yocto-project-compatible-program-application'>
482 <title>Yocto Project Compatible Program Application</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483
484 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500485 Use the form to apply for your layer's approval.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486 Upon successful application, you can use the Yocto
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500487 Project Compatibility Logo with your layer and the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 application that uses your layer.
489 </para>
490
491 <para>
492 To access the form, use this link:
493 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
494 Follow the instructions on the form to complete your
495 application.
496 </para>
497
498 <para>
499 The application consists of the following sections:
500 <itemizedlist>
501 <listitem><para>
502 <emphasis>Contact Information:</emphasis>
503 Provide your contact information as the fields
504 require.
505 Along with your information, provide the
506 released versions of the Yocto Project for which
507 your layer is compatible.
508 </para></listitem>
509 <listitem><para>
510 <emphasis>Acceptance Criteria:</emphasis>
511 Provide "Yes" or "No" answers for each of the
512 items in the checklist.
513 Space exists at the bottom of the form for any
514 explanations for items for which you answered "No".
515 </para></listitem>
516 <listitem><para>
517 <emphasis>Recommendations:</emphasis>
518 Provide answers for the questions regarding Linux
519 kernel use and build success.
520 </para></listitem>
521 </itemizedlist>
522 </para>
523 </section>
524
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500525 <section id='yocto-check-layer-script'>
526 <title><filename>yocto-check-layer</filename> Script</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527
528 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500529 The <filename>yocto-check-layer</filename> script
530 provides you a way to assess how compatible your layer is
531 with the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500532 You should run this script prior to using the form to
533 apply for compatibility as described in the previous
534 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500535 You need to achieve a "PASS" result in order to have
536 your application form successfully processed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 </para>
538
539 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400540 The script divides tests into three areas: COMMON, BSP,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500541 and DISTRO.
542 For example, given a distribution layer (DISTRO), the
543 layer must pass both the COMMON and DISTRO related tests.
544 Furthermore, if your layer is a BSP layer, the layer must
545 pass the COMMON and BSP set of tests.
546 </para>
547
548 <para>
549 To execute the script, enter the following commands from
550 your build directory:
551 <literallayout class='monospaced'>
552 $ source oe-init-build-env
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 $ yocto-check-layer <replaceable>your_layer_directory</replaceable>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500554 </literallayout>
555 Be sure to provide the actual directory for your layer
556 as part of the command.
557 </para>
558
559 <para>
560 Entering the command causes the script to determine the
561 type of layer and then to execute a set of specific
562 tests against the layer.
563 The following list overviews the test:
564 <itemizedlist>
565 <listitem><para>
566 <filename>common.test_readme</filename>:
567 Tests if a <filename>README</filename> file
568 exists in the layer and the file is not empty.
569 </para></listitem>
570 <listitem><para>
571 <filename>common.test_parse</filename>:
572 Tests to make sure that BitBake can parse the
573 files without error (i.e.
574 <filename>bitbake -p</filename>).
575 </para></listitem>
576 <listitem><para>
577 <filename>common.test_show_environment</filename>:
578 Tests that the global or per-recipe environment
579 is in order without errors (i.e.
580 <filename>bitbake -e</filename>).
581 </para></listitem>
582 <listitem><para>
583 <filename>common.test_signatures</filename>:
584 Tests to be sure that BSP and DISTRO layers do not
585 come with recipes that change signatures.
586 </para></listitem>
587 <listitem><para>
588 <filename>bsp.test_bsp_defines_machines</filename>:
589 Tests if a BSP layer has machine configurations.
590 </para></listitem>
591 <listitem><para>
592 <filename>bsp.test_bsp_no_set_machine</filename>:
593 Tests to ensure a BSP layer does not set the
594 machine when the layer is added.
595 </para></listitem>
596 <listitem><para>
597 <filename>distro.test_distro_defines_distros</filename>:
598 Tests if a DISTRO layer has distro configurations.
599 </para></listitem>
600 <listitem><para>
601 <filename>distro.test_distro_no_set_distro</filename>:
602 Tests to ensure a DISTRO layer does not set the
603 distribution when the layer is added.
604 </para></listitem>
605 </itemizedlist>
606 </para>
607 </section>
608 </section>
609
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610 <section id='enabling-your-layer'>
611 <title>Enabling Your Layer</title>
612
613 <para>
614 Before the OpenEmbedded build system can use your new layer,
615 you need to enable it.
616 To enable your layer, simply add your layer's path to the
617 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
618 variable in your <filename>conf/bblayers.conf</filename> file,
619 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 The following example shows how to enable a layer named
622 <filename>meta-mylayer</filename>:
623 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400624 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
625 # changes incompatibly
626 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627
628 BBPATH = "${TOPDIR}"
629 BBFILES ?= ""
630
631 BBLAYERS ?= " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400632 /home/<replaceable>user</replaceable>/poky/meta \
633 /home/<replaceable>user</replaceable>/poky/meta-poky \
634 /home/<replaceable>user</replaceable>/poky/meta-yocto-bsp \
635 /home/<replaceable>user</replaceable>/poky/meta-mylayer \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500636 "
637 </literallayout>
638 </para>
639
640 <para>
641 BitBake parses each <filename>conf/layer.conf</filename> file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400642 from the top down as specified in the
643 <filename>BBLAYERS</filename> variable
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500644 within the <filename>conf/bblayers.conf</filename> file.
645 During the processing of each
646 <filename>conf/layer.conf</filename> file, BitBake adds the
647 recipes, classes and configurations contained within the
648 particular layer to the source directory.
649 </para>
650 </section>
651
652 <section id='using-bbappend-files'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500653 <title>Using .bbappend Files in Your Layer</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500654
655 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500656 A recipe that appends Metadata to another recipe is called a
657 BitBake append file.
658 A BitBake append file uses the <filename>.bbappend</filename>
659 file type suffix, while the corresponding recipe to which
660 Metadata is being appended uses the <filename>.bb</filename>
661 file type suffix.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500662 </para>
663
664 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500665 You can use a <filename>.bbappend</filename> file in your
666 layer to make additions or changes to the content of another
667 layer's recipe without having to copy the other layer's
668 recipe into your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669 Your <filename>.bbappend</filename> file resides in your layer,
670 while the main <filename>.bb</filename> recipe file to
671 which you are appending Metadata resides in a different layer.
672 </para>
673
674 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 Being able to append information to an existing recipe not only
676 avoids duplication, but also automatically applies recipe
677 changes from a different layer into your layer.
678 If you were copying recipes, you would have to manually merge
679 changes as they occur.
680 </para>
681
682 <para>
683 When you create an append file, you must use the same root
684 name as the corresponding recipe file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685 For example, the append file
686 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
687 <filename>someapp_&DISTRO;.bb</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500688 This means the original recipe and append file names are
689 version number-specific.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500690 If the corresponding recipe is renamed to update to a newer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500691 version, you must also rename and possibly update
692 the corresponding <filename>.bbappend</filename> as well.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 During the build process, BitBake displays an error on starting
694 if it detects a <filename>.bbappend</filename> file that does
695 not have a corresponding recipe with a matching name.
696 See the
697 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
698 variable for information on how to handle this error.
699 </para>
700
701 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702 As an example, consider the main formfactor recipe and a
703 corresponding formfactor append file both from the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500704 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500705 Here is the main formfactor recipe, which is named
706 <filename>formfactor_0.0.bb</filename> and located in the
707 "meta" layer at
708 <filename>meta/recipes-bsp/formfactor</filename>:
709 <literallayout class='monospaced'>
710 SUMMARY = "Device formfactor information"
711 SECTION = "base"
712 LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500713 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714 PR = "r45"
715
716 SRC_URI = "file://config file://machconfig"
717 S = "${WORKDIR}"
718
719 PACKAGE_ARCH = "${MACHINE_ARCH}"
720 INHIBIT_DEFAULT_DEPS = "1"
721
722 do_install() {
723 # Install file only if it has contents
724 install -d ${D}${sysconfdir}/formfactor/
725 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
726 if [ -s "${S}/machconfig" ]; then
727 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
728 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 } </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 In the main recipe, note the
731 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
732 variable, which tells the OpenEmbedded build system where to
733 find files during the build.
734 </para>
735
736 <para>
737 Following is the append file, which is named
738 <filename>formfactor_0.0.bbappend</filename> and is from the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500739 Raspberry Pi BSP Layer named
740 <filename>meta-raspberrypi</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500741 The file is in the layer at
742 <filename>recipes-bsp/formfactor</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 <literallayout class='monospaced'>
744 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
745 </literallayout>
746 </para>
747
748 <para>
749 By default, the build system uses the
750 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
751 variable to locate files.
752 This append file extends the locations by setting the
753 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
754 variable.
755 Setting this variable in the <filename>.bbappend</filename>
756 file is the most reliable and recommended method for adding
757 directories to the search path used by the build system
758 to find files.
759 </para>
760
761 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500762 The statement in this example extends the directories to
763 include
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500764 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>,
765 which resolves to a directory named
766 <filename>formfactor</filename> in the same directory
767 in which the append file resides (i.e.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500768 <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500769 This implies that you must have the supporting directory
770 structure set up that will contain any files or patches you
771 will be including from the layer.
772 </para>
773
774 <para>
775 Using the immediate expansion assignment operator
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500776 <filename>:=</filename> is important because of the reference
777 to <filename>THISDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500778 The trailing colon character is important as it ensures that
779 items in the list remain colon-separated.
780 <note>
781 <para>
782 BitBake automatically defines the
783 <filename>THISDIR</filename> variable.
784 You should never set this variable yourself.
785 Using "_prepend" as part of the
786 <filename>FILESEXTRAPATHS</filename> ensures your path
787 will be searched prior to other paths in the final
788 list.
789 </para>
790
791 <para>
792 Also, not all append files add extra files.
793 Many append files simply exist to add build options
794 (e.g. <filename>systemd</filename>).
795 For these cases, your append file would not even
796 use the <filename>FILESEXTRAPATHS</filename> statement.
797 </para>
798 </note>
799 </para>
800 </section>
801
802 <section id='prioritizing-your-layer'>
803 <title>Prioritizing Your Layer</title>
804
805 <para>
806 Each layer is assigned a priority value.
807 Priority values control which layer takes precedence if there
808 are recipe files with the same name in multiple layers.
809 For these cases, the recipe file from the layer with a higher
810 priority number takes precedence.
811 Priority values also affect the order in which multiple
812 <filename>.bbappend</filename> files for the same recipe are
813 applied.
814 You can either specify the priority manually, or allow the
815 build system to calculate it based on the layer's dependencies.
816 </para>
817
818 <para>
819 To specify the layer's priority manually, use the
820 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400821 variable and append the layer's root name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500822 <literallayout class='monospaced'>
823 BBFILE_PRIORITY_mylayer = "1"
824 </literallayout>
825 </para>
826
827 <note>
828 <para>It is possible for a recipe with a lower version number
829 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
830 in a layer that has a higher priority to take precedence.</para>
831 <para>Also, the layer priority does not currently affect the
832 precedence order of <filename>.conf</filename>
833 or <filename>.bbclass</filename> files.
834 Future versions of BitBake might address this.</para>
835 </note>
836 </section>
837
838 <section id='managing-layers'>
839 <title>Managing Layers</title>
840
841 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400842 You can use the BitBake layer management tool
843 <filename>bitbake-layers</filename> to provide a view
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844 into the structure of recipes across a multi-layer project.
845 Being able to generate output that reports on configured layers
846 with their paths and priorities and on
847 <filename>.bbappend</filename> files and their applicable
848 recipes can help to reveal potential problems.
849 </para>
850
851 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400852 For help on the BitBake layer management tool, use the
853 following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500854 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400855 $ bitbake-layers --help
856 NOTE: Starting bitbake server...
857 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] &lt;subcommand&gt; ...
858
859 BitBake layers utility
860
861 optional arguments:
862 -d, --debug Enable debug output
863 -q, --quiet Print only errors
864 -F, --force Force add without recipe parse verification
865 --color COLOR Colorize output (where COLOR is auto, always, never)
866 -h, --help show this help message and exit
867
868 subcommands:
869 &lt;subcommand&gt;
870 show-layers show current configured layers.
871 show-overlayed list overlayed recipes (where the same recipe exists
872 in another layer)
873 show-recipes list available recipes, showing the layer they are
874 provided by
875 show-appends list bbappend files and recipe files they apply to
876 show-cross-depends Show dependencies between recipes that cross layer
877 boundaries.
878 add-layer Add one or more layers to bblayers.conf.
879 remove-layer Remove one or more layers from bblayers.conf.
880 flatten flatten layer configuration into a separate output
881 directory.
882 layerindex-fetch Fetches a layer from a layer index along with its
883 dependent layers, and adds them to conf/bblayers.conf.
884 layerindex-show-depends
885 Find layer dependencies from layer index.
886 create-layer Create a basic layer
887
888 Use bitbake-layers &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500889 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400890 </para>
891
892 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500893 The following list describes the available commands:
894 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400895 <listitem><para>
896 <emphasis><filename>help:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500897 Displays general help or help on a specified command.
898 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400899 <listitem><para>
900 <emphasis><filename>show-layers:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500901 Shows the current configured layers.
902 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400903 <listitem><para>
904 <emphasis><filename>show-overlayed:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 Lists overlayed recipes.
906 A recipe is overlayed when a recipe with the same name
907 exists in another layer that has a higher layer
908 priority.
909 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400910 <listitem><para>
911 <emphasis><filename>show-recipes:</filename></emphasis>
912 Lists available recipes and the layers that provide them.
913 </para></listitem>
914 <listitem><para>
915 <emphasis><filename>show-appends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916 Lists <filename>.bbappend</filename> files and the
917 recipe files to which they apply.
918 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400919 <listitem><para>
920 <emphasis><filename>show-cross-depends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500921 Lists dependency relationships between recipes that
922 cross layer boundaries.
923 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400924 <listitem><para>
925 <emphasis><filename>add-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500926 Adds a layer to <filename>bblayers.conf</filename>.
927 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400928 <listitem><para>
929 <emphasis><filename>remove-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500930 Removes a layer from <filename>bblayers.conf</filename>
931 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400932 <listitem><para>
933 <emphasis><filename>flatten:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500934 Flattens the layer configuration into a separate output
935 directory.
936 Flattening your layer configuration builds a "flattened"
937 directory that contains the contents of all layers,
938 with any overlayed recipes removed and any
939 <filename>.bbappend</filename> files appended to the
940 corresponding recipes.
941 You might have to perform some manual cleanup of the
942 flattened layer as follows:
943 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400944 <listitem><para>
945 Non-recipe files (such as patches)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500946 are overwritten.
947 The flatten command shows a warning for these
948 files.
949 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400950 <listitem><para>
951 Anything beyond the normal layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952 setup has been added to the
953 <filename>layer.conf</filename> file.
954 Only the lowest priority layer's
955 <filename>layer.conf</filename> is used.
956 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400957 <listitem><para>
958 Overridden and appended items from
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500959 <filename>.bbappend</filename> files need to be
960 cleaned up.
961 The contents of each
962 <filename>.bbappend</filename> end up in the
963 flattened recipe.
964 However, if there are appended or changed
965 variable values, you need to tidy these up
966 yourself.
967 Consider the following example.
968 Here, the <filename>bitbake-layers</filename>
969 command adds the line
970 <filename>#### bbappended ...</filename> so that
971 you know where the following lines originate:
972 <literallayout class='monospaced'>
973 ...
974 DESCRIPTION = "A useful utility"
975 ...
976 EXTRA_OECONF = "--enable-something"
977 ...
978
979 #### bbappended from meta-anotherlayer ####
980
981 DESCRIPTION = "Customized utility"
982 EXTRA_OECONF += "--enable-somethingelse"
983 </literallayout>
984 Ideally, you would tidy up these utilities as
985 follows:
986 <literallayout class='monospaced'>
987 ...
988 DESCRIPTION = "Customized utility"
989 ...
990 EXTRA_OECONF = "--enable-something --enable-somethingelse"
991 ...
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500992 </literallayout>
993 </para></listitem>
994 </itemizedlist>
995 </para></listitem>
996 <listitem><para>
997 <emphasis><filename>layerindex-fetch</filename>:</emphasis>
998 Fetches a layer from a layer index, along with its
999 dependent layers, and adds the layers to the
1000 <filename>conf/bblayers.conf</filename> file.
1001 </para></listitem>
1002 <listitem><para>
1003 <emphasis><filename>layerindex-show-depends</filename>:</emphasis>
1004 Finds layer dependencies from the layer index.
1005 </para></listitem>
1006 <listitem><para>
1007 <emphasis><filename>create-layer</filename>:</emphasis>
1008 Creates a basic layer.
1009 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001010 </itemizedlist>
1011 </para>
1012 </section>
1013
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001014 <section id='creating-a-general-layer-using-the-bitbake-layers-script'>
1015 <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
1017 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001018 The <filename>bitbake-layers</filename> script with the
1019 <filename>create-layer</filename> subcommand simplifies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001020 creating a new general layer.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 <note><title>Notes</title>
1022 <itemizedlist>
1023 <listitem><para>
1024 For information on BSP layers, see the
1025 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
1026 section in the Yocto Project Board Specific (BSP)
1027 Developer's Guide.
1028 </para></listitem>
1029 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001030 In order to use a layer with the OpenEmbedded
1031 build system, you need to add the layer to your
1032 <filename>bblayers.conf</filename> configuration
1033 file.
1034 See the
1035 "<link linkend='adding-a-layer-using-the-bitbake-layers-script'>Adding a Layer Using the <filename>bitbake-layers</filename> Script</link>"
1036 section for more information.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001037 </para></listitem>
1038 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001039 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 The default mode of the script's operation with this
1041 subcommand is to create a layer with the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001042 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001043 <listitem><para>A layer priority of 6.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001044 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001045 <listitem><para>A <filename>conf</filename>
1046 subdirectory that contains a
1047 <filename>layer.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001048 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001049 <listitem><para>
1050 A <filename>recipes-example</filename> subdirectory
1051 that contains a further subdirectory named
1052 <filename>example</filename>, which contains
1053 an <filename>example.bb</filename> recipe file.
1054 </para></listitem>
1055 <listitem><para>A <filename >COPYING.MIT</filename>,
1056 which is the license statement for the layer.
1057 The script assumes you want to use the MIT license,
1058 which is typical for most layers, for the contents of
1059 the layer itself.
1060 </para></listitem>
1061 <listitem><para>
1062 A <filename>README</filename> file, which is a file
1063 describing the contents of your new layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001064 </para></listitem>
1065 </itemizedlist>
1066 </para>
1067
1068 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001069 In its simplest form, you can use the following command form
1070 to create a layer.
1071 The command creates a layer whose name corresponds to
1072 <replaceable>your_layer_name</replaceable> in the current
1073 directory:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001074 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001075 $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001076 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001077 As an example, the following command creates a layer named
1078 <filename>meta-scottrif</filename> in your home directory:
1079 <literallayout class='monospaced'>
1080 $ cd /usr/home
1081 $ bitbake-layers create-layer meta-scottrif
1082 NOTE: Starting bitbake server...
1083 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
1084 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 </para>
1086
1087 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001088 If you want to set the priority of the layer to other than the
1089 default value of "6", you can either use the
1090 <filename>&dash;&dash;priority</filename> option or you can
1091 edit the
1092 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
1093 value in the <filename>conf/layer.conf</filename> after the
1094 script creates it.
1095 Furthermore, if you want to give the example recipe file
1096 some name other than the default, you can
1097 use the
1098 <filename>&dash;&dash;example-recipe-name</filename> option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001099 </para>
1100
1101 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001102 The easiest way to see how the
1103 <filename>bitbake-layers create-layer</filename> command
1104 works is to experiment with the script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001105 You can also read the usage information by entering the
1106 following:
1107 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001108 $ bitbake-layers create-layer --help
1109 NOTE: Starting bitbake server...
1110 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
1111 [--example-recipe-name EXAMPLERECIPE]
1112 layerdir
1113
1114 Create a basic layer
1115
1116 positional arguments:
1117 layerdir Layer directory to create
1118
1119 optional arguments:
1120 -h, --help show this help message and exit
1121 --priority PRIORITY, -p PRIORITY
1122 Layer directory to create
1123 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
1124 Filename of the example recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001125 </literallayout>
1126 </para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001127 </section>
1128
1129 <section id='adding-a-layer-using-the-bitbake-layers-script'>
1130 <title>Adding a Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001131
1132 <para>
1133 Once you create your general layer, you must add it to your
1134 <filename>bblayers.conf</filename> file.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001135 Adding the layer to this configuration file makes the
1136 OpenEmbedded build system aware of your layer so that it can
1137 search it for metadata.
1138 </para>
1139
1140 <para>
1141 Add your layer by using the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001142 <filename>bitbake-layers add-layer</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001143 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001144 $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable>
1145 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001146 Here is an example that adds a layer named
1147 <filename>meta-scottrif</filename> to the configuration file.
1148 Following the command that adds the layer is another
1149 <filename>bitbake-layers</filename> command that shows the
1150 layers that are in your <filename>bblayers.conf</filename>
1151 file:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001152 <literallayout class='monospaced'>
1153 $ bitbake-layers add-layer meta-scottrif
1154 NOTE: Starting bitbake server...
Brad Bishop316dfdd2018-06-25 12:45:53 -04001155 Parsing recipes: 100% |##########################################################| Time: 0:00:49
1156 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001157 $ bitbake-layers show-layers
1158 NOTE: Starting bitbake server...
1159 layer path priority
1160 ==========================================================================
1161 meta /home/scottrif/poky/meta 5
1162 meta-poky /home/scottrif/poky/meta-poky 5
1163 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001164 workspace /home/scottrif/poky/build/workspace 99
1165 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001166 </literallayout>
1167 Adding the layer to this file enables the build system to
1168 locate the layer during the build.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001169 <note>
1170 During a build, the OpenEmbedded build system looks in
1171 the layers from the top of the list down to the bottom
1172 in that order.
1173 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001174 </para>
1175 </section>
1176 </section>
1177
1178 <section id='usingpoky-extend-customimage'>
1179 <title>Customizing Images</title>
1180
1181 <para>
1182 You can customize images to satisfy particular requirements.
1183 This section describes several methods and provides guidelines for each.
1184 </para>
1185
1186 <section id='usingpoky-extend-customimage-localconf'>
1187 <title>Customizing Images Using <filename>local.conf</filename></title>
1188
1189 <para>
1190 Probably the easiest way to customize an image is to add a
1191 package by way of the <filename>local.conf</filename>
1192 configuration file.
1193 Because it is limited to local use, this method generally only
1194 allows you to add packages and is not as flexible as creating
1195 your own customized image.
1196 When you add packages using local variables this way, you need
1197 to realize that these variable changes are in effect for every
1198 build and consequently affect all images, which might not
1199 be what you require.
1200 </para>
1201
1202 <para>
1203 To add a package to your image using the local configuration
1204 file, use the
1205 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1206 variable with the <filename>_append</filename> operator:
1207 <literallayout class='monospaced'>
1208 IMAGE_INSTALL_append = " strace"
1209 </literallayout>
1210 Use of the syntax is important - specifically, the space between
1211 the quote and the package name, which is
1212 <filename>strace</filename> in this example.
1213 This space is required since the <filename>_append</filename>
1214 operator does not add the space.
1215 </para>
1216
1217 <para>
1218 Furthermore, you must use <filename>_append</filename> instead
1219 of the <filename>+=</filename> operator if you want to avoid
1220 ordering issues.
1221 The reason for this is because doing so unconditionally appends
1222 to the variable and avoids ordering problems due to the
1223 variable being set in image recipes and
1224 <filename>.bbclass</filename> files with operators like
1225 <filename>?=</filename>.
1226 Using <filename>_append</filename> ensures the operation takes
1227 affect.
1228 </para>
1229
1230 <para>
1231 As shown in its simplest use,
1232 <filename>IMAGE_INSTALL_append</filename> affects all images.
1233 It is possible to extend the syntax so that the variable
1234 applies to a specific image only.
1235 Here is an example:
1236 <literallayout class='monospaced'>
1237 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
1238 </literallayout>
1239 This example adds <filename>strace</filename> to the
1240 <filename>core-image-minimal</filename> image only.
1241 </para>
1242
1243 <para>
1244 You can add packages using a similar approach through the
1245 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
1246 variable.
1247 If you use this variable, only
1248 <filename>core-image-*</filename> images are affected.
1249 </para>
1250 </section>
1251
1252 <section id='usingpoky-extend-customimage-imagefeatures'>
1253 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
1254 <filename>EXTRA_IMAGE_FEATURES</filename></title>
1255
1256 <para>
1257 Another method for customizing your image is to enable or
1258 disable high-level image features by using the
1259 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
1260 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
1261 variables.
1262 Although the functions for both variables are nearly equivalent,
1263 best practices dictate using <filename>IMAGE_FEATURES</filename>
1264 from within a recipe and using
1265 <filename>EXTRA_IMAGE_FEATURES</filename> from within
1266 your <filename>local.conf</filename> file, which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001267 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001268 </para>
1269
1270 <para>
1271 To understand how these features work, the best reference is
1272 <filename>meta/classes/core-image.bbclass</filename>.
1273 This class lists out the available
Brad Bishop316dfdd2018-06-25 12:45:53 -04001274 <filename>IMAGE_FEATURES</filename> of which most map to
1275 package groups while some, such as
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001276 <filename>debug-tweaks</filename> and
1277 <filename>read-only-rootfs</filename>, resolve as general
1278 configuration settings.
1279 </para>
1280
1281 <para>
1282 In summary, the file looks at the contents of the
1283 <filename>IMAGE_FEATURES</filename> variable and then maps
1284 or configures the feature accordingly.
1285 Based on this information, the build system automatically
1286 adds the appropriate packages or configurations to the
1287 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
1288 variable.
1289 Effectively, you are enabling extra features by extending the
1290 class or creating a custom class for use with specialized image
1291 <filename>.bb</filename> files.
1292 </para>
1293
1294 <para>
1295 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1296 from within your local configuration file.
1297 Using a separate area from which to enable features with
1298 this variable helps you avoid overwriting the features in the
1299 image recipe that are enabled with
1300 <filename>IMAGE_FEATURES</filename>.
1301 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1302 to <filename>IMAGE_FEATURES</filename> within
1303 <filename>meta/conf/bitbake.conf</filename>.
1304 </para>
1305
1306 <para>
1307 To illustrate how you can use these variables to modify your
1308 image, consider an example that selects the SSH server.
1309 The Yocto Project ships with two SSH servers you can use
1310 with your images: Dropbear and OpenSSH.
1311 Dropbear is a minimal SSH server appropriate for
1312 resource-constrained environments, while OpenSSH is a
1313 well-known standard SSH server implementation.
1314 By default, the <filename>core-image-sato</filename> image
1315 is configured to use Dropbear.
1316 The <filename>core-image-full-cmdline</filename> and
1317 <filename>core-image-lsb</filename> images both
1318 include OpenSSH.
1319 The <filename>core-image-minimal</filename> image does not
1320 contain an SSH server.
1321 </para>
1322
1323 <para>
1324 You can customize your image and change these defaults.
1325 Edit the <filename>IMAGE_FEATURES</filename> variable
1326 in your recipe or use the
1327 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1328 <filename>local.conf</filename> file so that it configures the
1329 image you are working with to include
1330 <filename>ssh-server-dropbear</filename> or
1331 <filename>ssh-server-openssh</filename>.
1332 </para>
1333
1334 <note>
1335 See the
1336 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1337 section in the Yocto Project Reference Manual for a complete
1338 list of image features that ship with the Yocto Project.
1339 </note>
1340 </section>
1341
1342 <section id='usingpoky-extend-customimage-custombb'>
1343 <title>Customizing Images Using Custom .bb Files</title>
1344
1345 <para>
1346 You can also customize an image by creating a custom recipe
1347 that defines additional software as part of the image.
1348 The following example shows the form for the two lines you need:
1349 <literallayout class='monospaced'>
1350 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1351
1352 inherit core-image
1353 </literallayout>
1354 </para>
1355
1356 <para>
1357 Defining the software using a custom recipe gives you total
1358 control over the contents of the image.
1359 It is important to use the correct names of packages in the
1360 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1361 variable.
1362 You must use the OpenEmbedded notation and not the Debian notation for the names
1363 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1364 </para>
1365
1366 <para>
1367 The other method for creating a custom image is to base it on an existing image.
1368 For example, if you want to create an image based on <filename>core-image-sato</filename>
1369 but add the additional package <filename>strace</filename> to the image,
1370 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1371 new <filename>.bb</filename> and add the following line to the end of the copy:
1372 <literallayout class='monospaced'>
1373 IMAGE_INSTALL += "strace"
1374 </literallayout>
1375 </para>
1376 </section>
1377
1378 <section id='usingpoky-extend-customimage-customtasks'>
1379 <title>Customizing Images Using Custom Package Groups</title>
1380
1381 <para>
1382 For complex custom images, the best approach for customizing
1383 an image is to create a custom package group recipe that is
1384 used to build the image or images.
1385 A good example of a package group recipe is
1386 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1387 </para>
1388
1389 <para>
1390 If you examine that recipe, you see that the
1391 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1392 variable lists the package group packages to produce.
1393 The <filename>inherit packagegroup</filename> statement
1394 sets appropriate default values and automatically adds
1395 <filename>-dev</filename>, <filename>-dbg</filename>, and
1396 <filename>-ptest</filename> complementary packages for each
1397 package specified in the <filename>PACKAGES</filename>
1398 statement.
1399 <note>
1400 The <filename>inherit packages</filename> should be
1401 located near the top of the recipe, certainly before
1402 the <filename>PACKAGES</filename> statement.
1403 </note>
1404 </para>
1405
1406 <para>
1407 For each package you specify in <filename>PACKAGES</filename>,
1408 you can use
1409 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1410 and
1411 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1412 entries to provide a list of packages the parent task package
1413 should contain.
1414 You can see examples of these further down in the
1415 <filename>packagegroup-base.bb</filename> recipe.
1416 </para>
1417
1418 <para>
1419 Here is a short, fabricated example showing the same basic
1420 pieces:
1421 <literallayout class='monospaced'>
1422 DESCRIPTION = "My Custom Package Groups"
1423
1424 inherit packagegroup
1425
1426 PACKAGES = "\
1427 packagegroup-custom-apps \
1428 packagegroup-custom-tools \
1429 "
1430
1431 RDEPENDS_packagegroup-custom-apps = "\
1432 dropbear \
1433 portmap \
1434 psplash"
1435
1436 RDEPENDS_packagegroup-custom-tools = "\
1437 oprofile \
1438 oprofileui-server \
1439 lttng-tools"
1440
1441 RRECOMMENDS_packagegroup-custom-tools = "\
1442 kernel-module-oprofile"
1443 </literallayout>
1444 </para>
1445
1446 <para>
1447 In the previous example, two package group packages are created with their dependencies and their
1448 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1449 <filename>packagegroup-custom-tools</filename>.
1450 To build an image using these package group packages, you need to add
1451 <filename>packagegroup-custom-apps</filename> and/or
1452 <filename>packagegroup-custom-tools</filename> to
1453 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1454 For other forms of image dependencies see the other areas of this section.
1455 </para>
1456 </section>
1457
1458 <section id='usingpoky-extend-customimage-image-name'>
1459 <title>Customizing an Image Hostname</title>
1460
1461 <para>
1462 By default, the configured hostname (i.e.
1463 <filename>/etc/hostname</filename>) in an image is the
1464 same as the machine name.
1465 For example, if
1466 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1467 equals "qemux86", the configured hostname written to
1468 <filename>/etc/hostname</filename> is "qemux86".
1469 </para>
1470
1471 <para>
1472 You can customize this name by altering the value of the
1473 "hostname" variable in the
1474 <filename>base-files</filename> recipe using either
1475 an append file or a configuration file.
1476 Use the following in an append file:
1477 <literallayout class='monospaced'>
1478 hostname="myhostname"
1479 </literallayout>
1480 Use the following in a configuration file:
1481 <literallayout class='monospaced'>
1482 hostname_pn-base-files = "myhostname"
1483 </literallayout>
1484 </para>
1485
1486 <para>
1487 Changing the default value of the variable "hostname" can be
1488 useful in certain situations.
1489 For example, suppose you need to do extensive testing on an
1490 image and you would like to easily identify the image
1491 under test from existing images with typical default
1492 hostnames.
1493 In this situation, you could change the default hostname to
1494 "testme", which results in all the images using the name
1495 "testme".
1496 Once testing is complete and you do not need to rebuild the
1497 image for test any longer, you can easily reset the default
1498 hostname.
1499 </para>
1500
1501 <para>
1502 Another point of interest is that if you unset the variable,
1503 the image will have no default hostname in the filesystem.
1504 Here is an example that unsets the variable in a
1505 configuration file:
1506 <literallayout class='monospaced'>
1507 hostname_pn-base-files = ""
1508 </literallayout>
1509 Having no default hostname in the filesystem is suitable for
1510 environments that use dynamic hostnames such as virtual
1511 machines.
1512 </para>
1513 </section>
1514 </section>
1515
1516 <section id='new-recipe-writing-a-new-recipe'>
1517 <title>Writing a New Recipe</title>
1518
1519 <para>
1520 Recipes (<filename>.bb</filename> files) are fundamental components
1521 in the Yocto Project environment.
1522 Each software component built by the OpenEmbedded build system
1523 requires a recipe to define the component.
1524 This section describes how to create, write, and test a new
1525 recipe.
1526 <note>
1527 For information on variables that are useful for recipes and
1528 for information about recipe naming issues, see the
1529 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1530 section of the Yocto Project Reference Manual.
1531 </note>
1532 </para>
1533
1534 <section id='new-recipe-overview'>
1535 <title>Overview</title>
1536
1537 <para>
1538 The following figure shows the basic process for creating a
1539 new recipe.
1540 The remainder of the section provides details for the steps.
1541 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1542 </para>
1543 </section>
1544
1545 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1546 <title>Locate or Automatically Create a Base Recipe</title>
1547
1548 <para>
1549 You can always write a recipe from scratch.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001550 However, three choices exist that can help you quickly get a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001551 start on a new recipe:
1552 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001553 <listitem><para>
1554 <emphasis><filename>devtool add</filename>:</emphasis>
1555 A command that assists in creating a recipe and
1556 an environment conducive to development.
1557 </para></listitem>
1558 <listitem><para>
1559 <emphasis><filename>recipetool create</filename>:</emphasis>
1560 A command provided by the Yocto Project that automates
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001561 creation of a base recipe based on the source
1562 files.
1563 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001564 <listitem><para>
1565 <emphasis>Existing Recipes:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001566 Location and modification of an existing recipe that is
1567 similar in function to the recipe you need.
1568 </para></listitem>
1569 </itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001570 <note>
1571 For information on recipe syntax, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001572 "<link linkend='recipe-syntax'>Recipe Syntax</link>"
1573 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001574 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001575 </para>
1576
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001577 <section id='new-recipe-creating-the-base-recipe-using-devtool'>
1578 <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001579
1580 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001581 The <filename>devtool add</filename> command uses the same
1582 logic for auto-creating the recipe as
1583 <filename>recipetool create</filename>, which is listed
1584 below.
1585 Additionally, however, <filename>devtool add</filename>
1586 sets up an environment that makes it easy for you to
1587 patch the source and to make changes to the recipe as
1588 is often necessary when adding a recipe to build a new
1589 piece of software to be included in a build.
1590 </para>
1591
1592 <para>
1593 You can find a complete description of the
1594 <filename>devtool add</filename> command in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001595 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>"
1596 section in the Yocto Project Application Development
1597 and the Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001598 </para>
1599 </section>
1600
1601 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1602 <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
1603
1604 <para>
1605 <filename>recipetool create</filename> automates creation
1606 of a base recipe given a set of source code files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001607 As long as you can extract or point to the source files,
1608 the tool will construct a recipe and automatically
1609 configure all pre-build information into the recipe.
1610 For example, suppose you have an application that builds
1611 using Autotools.
1612 Creating the base recipe using
1613 <filename>recipetool</filename> results in a recipe
1614 that has the pre-build dependencies, license requirements,
1615 and checksums configured.
1616 </para>
1617
1618 <para>
1619 To run the tool, you just need to be in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001621 and have sourced the build environment setup script
1622 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001623 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
Brad Bishop316dfdd2018-06-25 12:45:53 -04001624 To get help on the tool, use the following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001625 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001626 $ recipetool -h
1627 NOTE: Starting bitbake server...
1628 usage: recipetool [-d] [-q] [--color COLOR] [-h] &lt;subcommand&gt; ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001629
Brad Bishop316dfdd2018-06-25 12:45:53 -04001630 OpenEmbedded recipe tool
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001631
Brad Bishop316dfdd2018-06-25 12:45:53 -04001632 options:
1633 -d, --debug Enable debug output
1634 -q, --quiet Print only errors
1635 --color COLOR Colorize output (where COLOR is auto, always, never)
1636 -h, --help show this help message and exit
1637
1638 subcommands:
1639 create Create a new recipe
1640 newappend Create a bbappend for the specified target in the specified
1641 layer
1642 setvar Set a variable within a recipe
1643 appendfile Create/update a bbappend to replace a target file
1644 appendsrcfiles Create/update a bbappend to add or replace source files
1645 appendsrcfile Create/update a bbappend to add or replace a source file
1646 Use recipetool &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001647 </literallayout>
1648 </para>
1649
1650 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001651 Running
1652 <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001653 creates the base recipe and locates it properly in the
1654 layer that contains your source files.
1655 Following are some syntax examples:
1656 </para>
1657
1658 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001659 Use this syntax to generate a recipe based on
1660 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001661 Once generated, the recipe resides in the existing source
1662 code layer:
1663 <literallayout class='monospaced'>
1664 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1665 </literallayout>
1666 Use this syntax to generate a recipe using code that you
1667 extract from <replaceable>source</replaceable>.
1668 The extracted code is placed in its own layer defined
1669 by <replaceable>EXTERNALSRC</replaceable>.
1670 <literallayout class='monospaced'>
1671 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1672 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001673 Use this syntax to generate a recipe based on
1674 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001675 The options direct <filename>recipetool</filename> to
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001676 generate debugging information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001677 Once generated, the recipe resides in the existing source
1678 code layer:
1679 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001680 recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001681 </literallayout>
1682 </para>
1683 </section>
1684
1685 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1686 <title>Locating and Using a Similar Recipe</title>
1687
1688 <para>
1689 Before writing a recipe from scratch, it is often useful to
1690 discover whether someone else has already written one that
1691 meets (or comes close to meeting) your needs.
1692 The Yocto Project and OpenEmbedded communities maintain many
1693 recipes that might be candidates for what you are doing.
1694 You can find a good central index of these recipes in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001695 <ulink url='http://layers.openembedded.org'>OpenEmbedded Layer Index</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001696 </para>
1697
1698 <para>
1699 Working from an existing recipe or a skeleton recipe is the
1700 best way to get started.
1701 Here are some points on both methods:
1702 <itemizedlist>
1703 <listitem><para><emphasis>Locate and modify a recipe that
1704 is close to what you want to do:</emphasis>
1705 This method works when you are familiar with the
1706 current recipe space.
1707 The method does not work so well for those new to
1708 the Yocto Project or writing recipes.</para>
1709 <para>Some risks associated with this method are
1710 using a recipe that has areas totally unrelated to
1711 what you are trying to accomplish with your recipe,
1712 not recognizing areas of the recipe that you might
1713 have to add from scratch, and so forth.
1714 All these risks stem from unfamiliarity with the
1715 existing recipe space.</para></listitem>
1716 <listitem><para><emphasis>Use and modify the following
1717 skeleton recipe:</emphasis>
1718 If for some reason you do not want to use
1719 <filename>recipetool</filename> and you cannot
1720 find an existing recipe that is close to meeting
1721 your needs, you can use the following structure to
1722 provide the fundamental areas of a new recipe.
1723 <literallayout class='monospaced'>
1724 DESCRIPTION = ""
1725 HOMEPAGE = ""
1726 LICENSE = ""
1727 SECTION = ""
1728 DEPENDS = ""
1729 LIC_FILES_CHKSUM = ""
1730
1731 SRC_URI = ""
1732 </literallayout>
1733 </para></listitem>
1734 </itemizedlist>
1735 </para>
1736 </section>
1737 </section>
1738
1739 <section id='new-recipe-storing-and-naming-the-recipe'>
1740 <title>Storing and Naming the Recipe</title>
1741
1742 <para>
1743 Once you have your base recipe, you should put it in your
1744 own layer and name it appropriately.
1745 Locating it correctly ensures that the OpenEmbedded build
1746 system can find it when you use BitBake to process the
1747 recipe.
1748 </para>
1749
1750 <itemizedlist>
1751 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1752 The OpenEmbedded build system locates your recipe
1753 through the layer's <filename>conf/layer.conf</filename>
1754 file and the
1755 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1756 variable.
1757 This variable sets up a path from which the build system can
1758 locate recipes.
1759 Here is the typical use:
1760 <literallayout class='monospaced'>
1761 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1762 ${LAYERDIR}/recipes-*/*/*.bbappend"
1763 </literallayout>
1764 Consequently, you need to be sure you locate your new recipe
1765 inside your layer such that it can be found.</para>
1766 <para>You can find more information on how layers are
1767 structured in the
1768 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1769 section.</para></listitem>
1770 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1771 When you name your recipe, you need to follow this naming
1772 convention:
1773 <literallayout class='monospaced'>
1774 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1775 </literallayout>
1776 Use lower-cased characters and do not include the reserved
1777 suffixes <filename>-native</filename>,
1778 <filename>-cross</filename>, <filename>-initial</filename>,
1779 or <filename>-dev</filename> casually (i.e. do not use them
1780 as part of your recipe name unless the string applies).
1781 Here are some examples:
1782 <literallayout class='monospaced'>
1783 cups_1.7.0.bb
1784 gawk_4.0.2.bb
1785 irssi_0.8.16-rc1.bb
1786 </literallayout></para></listitem>
1787 </itemizedlist>
1788 </section>
1789
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001790 <section id='new-recipe-running-a-build-on-the-recipe'>
1791 <title>Running a Build on the Recipe</title>
1792
1793 <para>
1794 Creating a new recipe is usually an iterative process that
1795 requires using BitBake to process the recipe multiple times in
1796 order to progressively discover and add information to the
1797 recipe file.
1798 </para>
1799
1800 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001801 Assuming you have sourced the build environment setup script (i.e.
1802 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001803 and you are in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001804 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001805 use BitBake to process your recipe.
1806 All you need to provide is the
1807 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1808 in the previous section:
1809 <literallayout class='monospaced'>
1810 $ bitbake <replaceable>basename</replaceable>
1811 </literallayout>
1812
1813 </para>
1814
1815 <para>
1816 During the build, the OpenEmbedded build system creates a
1817 temporary work directory for each recipe
1818 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1819 where it keeps extracted source files, log files, intermediate
1820 compilation and packaging files, and so forth.
1821 </para>
1822
1823 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001824 The path to the per-recipe temporary work directory depends
1825 on the context in which it is being built.
1826 The quickest way to find this path is to have BitBake return it
1827 by running the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001828 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001829 $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001830 </literallayout>
1831 As an example, assume a Source Directory top-level folder named
1832 <filename>poky</filename>, a default Build Directory at
1833 <filename>poky/build</filename>, and a
1834 <filename>qemux86-poky-linux</filename> machine target system.
1835 Furthermore, suppose your recipe is named
1836 <filename>foo_1.3.0.bb</filename>.
1837 In this case, the work directory the build system uses to
1838 build the package would be as follows:
1839 <literallayout class='monospaced'>
1840 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1841 </literallayout>
1842 Inside this directory you can find sub-directories such as
1843 <filename>image</filename>, <filename>packages-split</filename>,
1844 and <filename>temp</filename>.
1845 After the build, you can examine these to determine how well
1846 the build went.
1847 <note>
1848 You can find log files for each task in the recipe's
1849 <filename>temp</filename> directory (e.g.
1850 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1851 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1852 (e.g. <filename>log.do_configure</filename>,
1853 <filename>log.do_fetch</filename>, and
1854 <filename>log.do_compile</filename>).
1855 </note>
1856 </para>
1857
1858 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001859 You can find more information about the build process in
Brad Bishop316dfdd2018-06-25 12:45:53 -04001860 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-development-environment'>The Yocto Project Development Environment</ulink>"
1861 chapter of the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001862 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863 </section>
1864
1865 <section id='new-recipe-fetching-code'>
1866 <title>Fetching Code</title>
1867
1868 <para>
1869 The first thing your recipe must do is specify how to fetch
1870 the source files.
1871 Fetching is controlled mainly through the
1872 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1873 variable.
1874 Your recipe must have a <filename>SRC_URI</filename> variable
1875 that points to where the source is located.
1876 For a graphical representation of source locations, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001877 "<ulink url='&YOCTO_DOCS_OM_URL;#sources-dev-environment'>Sources</ulink>"
1878 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001879 </para>
1880
1881 <para>
1882 The
1883 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1884 task uses the prefix of each entry in the
1885 <filename>SRC_URI</filename> variable value to determine which
Brad Bishopc342db32019-05-15 21:57:59 -04001886 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>
1887 to use to get your source files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001888 It is the <filename>SRC_URI</filename> variable that triggers
1889 the fetcher.
1890 The
1891 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1892 task uses the variable after source is fetched to apply
1893 patches.
1894 The OpenEmbedded build system uses
1895 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1896 for scanning directory locations for local files in
1897 <filename>SRC_URI</filename>.
1898 </para>
1899
1900 <para>
1901 The <filename>SRC_URI</filename> variable in your recipe must
1902 define each unique location for your source files.
1903 It is good practice to not hard-code pathnames in an URL used
1904 in <filename>SRC_URI</filename>.
1905 Rather than hard-code these paths, use
1906 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1907 which causes the fetch process to use the version specified in
1908 the recipe filename.
1909 Specifying the version in this manner means that upgrading the
1910 recipe to a future version is as simple as renaming the recipe
1911 to match the new version.
1912 </para>
1913
1914 <para>
1915 Here is a simple example from the
1916 <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
1917 recipe where the source comes from a single tarball.
1918 Notice the use of the
1919 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1920 variable:
1921 <literallayout class='monospaced'>
1922 SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
1923 </literallayout>
1924 </para>
1925
1926 <para>
1927 Files mentioned in <filename>SRC_URI</filename> whose names end
1928 in a typical archive extension (e.g. <filename>.tar</filename>,
1929 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1930 <filename>.zip</filename>, and so forth), are automatically
1931 extracted during the
1932 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1933 task.
1934 For another example that specifies these types of files, see
1935 the
1936 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1937 section.
1938 </para>
1939
1940 <para>
1941 Another way of specifying source is from an SCM.
1942 For Git repositories, you must specify
1943 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1944 and you should specify
1945 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1946 to include the revision with
1947 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1948 Here is an example from the recipe
1949 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1950 <literallayout class='monospaced'>
1951 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1952
1953 PR = "r6"
1954 PV = "1.0.5+git${SRCPV}"
1955
1956 SRC_URI = "git://git.kernel.dk/blktrace.git \
1957 file://ldflags.patch"
1958 </literallayout>
1959 </para>
1960
1961 <para>
1962 If your <filename>SRC_URI</filename> statement includes
1963 URLs pointing to individual files fetched from a remote server
1964 other than a version control system, BitBake attempts to
1965 verify the files against checksums defined in your recipe to
1966 ensure they have not been tampered with or otherwise modified
1967 since the recipe was written.
1968 Two checksums are used:
1969 <filename>SRC_URI[md5sum]</filename> and
1970 <filename>SRC_URI[sha256sum]</filename>.
1971 </para>
1972
1973 <para>
1974 If your <filename>SRC_URI</filename> variable points to
1975 more than a single URL (excluding SCM URLs), you need to
1976 provide the <filename>md5</filename> and
1977 <filename>sha256</filename> checksums for each URL.
1978 For these cases, you provide a name for each URL as part of
1979 the <filename>SRC_URI</filename> and then reference that name
1980 in the subsequent checksum statements.
1981 Here is an example:
1982 <literallayout class='monospaced'>
1983 SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001984 ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001985
1986 SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
1987 SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
1988
1989 SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
1990 SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
1991 </literallayout>
1992 </para>
1993
1994 <para>
1995 Proper values for <filename>md5</filename> and
1996 <filename>sha256</filename> checksums might be available
1997 with other signatures on the download page for the upstream
1998 source (e.g. <filename>md5</filename>,
1999 <filename>sha1</filename>, <filename>sha256</filename>,
2000 <filename>GPG</filename>, and so forth).
2001 Because the OpenEmbedded build system only deals with
2002 <filename>sha256sum</filename> and <filename>md5sum</filename>,
2003 you should verify all the signatures you find by hand.
2004 </para>
2005
2006 <para>
2007 If no <filename>SRC_URI</filename> checksums are specified
2008 when you attempt to build the recipe, or you provide an
2009 incorrect checksum, the build will produce an error for each
2010 missing or incorrect checksum.
2011 As part of the error message, the build system provides
2012 the checksum string corresponding to the fetched file.
2013 Once you have the correct checksums, you can copy and paste
2014 them into your recipe and then run the build again to continue.
2015 <note>
2016 As mentioned, if the upstream source provides signatures
2017 for verifying the downloaded source code, you should
2018 verify those manually before setting the checksum values
2019 in the recipe and continuing with the build.
2020 </note>
2021 </para>
2022
2023 <para>
2024 This final example is a bit more complicated and is from the
2025 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2026 recipe.
2027 The example's <filename>SRC_URI</filename> statement identifies
2028 multiple files as the source files for the recipe: a tarball, a
2029 patch file, a desktop file, and an icon.
2030 <literallayout class='monospaced'>
2031 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2032 file://xwc.patch \
2033 file://rxvt.desktop \
2034 file://rxvt.png"
2035 </literallayout>
2036 </para>
2037
2038 <para>
2039 When you specify local files using the
2040 <filename>file://</filename> URI protocol, the build system
2041 fetches files from the local machine.
2042 The path is relative to the
2043 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2044 variable and searches specific directories in a certain order:
2045 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2046 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2047 and <filename>files</filename>.
2048 The directories are assumed to be subdirectories of the
2049 directory in which the recipe or append file resides.
2050 For another example that specifies these types of files, see the
2051 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2052 section.
2053 </para>
2054
2055 <para>
2056 The previous example also specifies a patch file.
2057 Patch files are files whose names usually end in
2058 <filename>.patch</filename> or <filename>.diff</filename> but
2059 can end with compressed suffixes such as
2060 <filename>diff.gz</filename> and
2061 <filename>patch.bz2</filename>, for example.
2062 The build system automatically applies patches as described
2063 in the
2064 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2065 </para>
2066 </section>
2067
2068 <section id='new-recipe-unpacking-code'>
2069 <title>Unpacking Code</title>
2070
2071 <para>
2072 During the build, the
2073 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2074 task unpacks the source with
2075 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2076 pointing to where it is unpacked.
2077 </para>
2078
2079 <para>
2080 If you are fetching your source files from an upstream source
2081 archived tarball and the tarball's internal structure matches
2082 the common convention of a top-level subdirectory named
2083 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
2084 then you do not need to set <filename>S</filename>.
2085 However, if <filename>SRC_URI</filename> specifies to fetch
2086 source from an archive that does not use this convention,
2087 or from an SCM like Git or Subversion, your recipe needs to
2088 define <filename>S</filename>.
2089 </para>
2090
2091 <para>
2092 If processing your recipe using BitBake successfully unpacks
2093 the source files, you need to be sure that the directory
2094 pointed to by <filename>${S}</filename> matches the structure
2095 of the source.
2096 </para>
2097 </section>
2098
2099 <section id='new-recipe-patching-code'>
2100 <title>Patching Code</title>
2101
2102 <para>
2103 Sometimes it is necessary to patch code after it has been
2104 fetched.
2105 Any files mentioned in <filename>SRC_URI</filename> whose
2106 names end in <filename>.patch</filename> or
2107 <filename>.diff</filename> or compressed versions of these
2108 suffixes (e.g. <filename>diff.gz</filename> are treated as
2109 patches.
2110 The
2111 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2112 task automatically applies these patches.
2113 </para>
2114
2115 <para>
2116 The build system should be able to apply patches with the "-p1"
2117 option (i.e. one directory level in the path will be stripped
2118 off).
2119 If your patch needs to have more directory levels stripped off,
2120 specify the number of levels using the "striplevel" option in
2121 the <filename>SRC_URI</filename> entry for the patch.
2122 Alternatively, if your patch needs to be applied in a specific
2123 subdirectory that is not specified in the patch file, use the
2124 "patchdir" option in the entry.
2125 </para>
2126
2127 <para>
2128 As with all local files referenced in
2129 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2130 using <filename>file://</filename>, you should place
2131 patch files in a directory next to the recipe either
2132 named the same as the base name of the recipe
2133 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2134 and
2135 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2136 or "files".
2137 </para>
2138 </section>
2139
2140 <section id='new-recipe-licensing'>
2141 <title>Licensing</title>
2142
2143 <para>
2144 Your recipe needs to have both the
2145 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2146 and
2147 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2148 variables:
2149 <itemizedlist>
2150 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2151 This variable specifies the license for the software.
2152 If you do not know the license under which the software
2153 you are building is distributed, you should go to the
2154 source code and look for that information.
2155 Typical files containing this information include
2156 <filename>COPYING</filename>,
2157 <filename>LICENSE</filename>, and
2158 <filename>README</filename> files.
2159 You could also find the information near the top of
2160 a source file.
2161 For example, given a piece of software licensed under
2162 the GNU General Public License version 2, you would
2163 set <filename>LICENSE</filename> as follows:
2164 <literallayout class='monospaced'>
2165 LICENSE = "GPLv2"
2166 </literallayout></para>
2167 <para>The licenses you specify within
2168 <filename>LICENSE</filename> can have any name as long
2169 as you do not use spaces, since spaces are used as
2170 separators between license names.
2171 For standard licenses, use the names of the files in
2172 <filename>meta/files/common-licenses/</filename>
2173 or the <filename>SPDXLICENSEMAP</filename> flag names
2174 defined in <filename>meta/conf/licenses.conf</filename>.
2175 </para></listitem>
2176 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2177 The OpenEmbedded build system uses this variable to
2178 make sure the license text has not changed.
2179 If it has, the build produces an error and it affords
2180 you the chance to figure it out and correct the problem.
2181 </para>
2182 <para>You need to specify all applicable licensing
2183 files for the software.
2184 At the end of the configuration step, the build process
2185 will compare the checksums of the files to be sure
2186 the text has not changed.
2187 Any differences result in an error with the message
2188 containing the current checksum.
2189 For more explanation and examples of how to set the
2190 <filename>LIC_FILES_CHKSUM</filename> variable, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002191 "<link link='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
2192 section.</para>
2193
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002194 <para>To determine the correct checksum string, you
2195 can list the appropriate files in the
2196 <filename>LIC_FILES_CHKSUM</filename> variable with
2197 incorrect md5 strings, attempt to build the software,
2198 and then note the resulting error messages that will
2199 report the correct md5 strings.
2200 See the
2201 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2202 section for additional information.
2203 </para>
2204
2205 <para>
2206 Here is an example that assumes the software has a
2207 <filename>COPYING</filename> file:
2208 <literallayout class='monospaced'>
2209 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2210 </literallayout>
2211 When you try to build the software, the build system
2212 will produce an error and give you the correct string
2213 that you can substitute into the recipe file for a
2214 subsequent build.
2215 </para></listitem>
2216 </itemizedlist>
2217 </para>
2218
2219<!--
2220
2221 <para>
2222 For trying this out I created a new recipe named
2223 <filename>htop_1.0.2.bb</filename> and put it in
2224 <filename>poky/meta/recipes-extended/htop</filename>.
2225 There are two license type statements in my very simple
2226 recipe:
2227 <literallayout class='monospaced'>
2228 LICENSE = ""
2229
2230 LIC_FILES_CHKSUM = ""
2231
2232 SRC_URI[md5sum] = ""
2233 SRC_URI[sha256sum] = ""
2234 </literallayout>
2235 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2236 Next, you delete or comment out the two <filename>SRC_URI</filename>
2237 lines at the end and then attempt to build the software with
2238 <filename>bitbake htop</filename>.
2239 Doing so causes BitBake to report some errors and and give
2240 you the actual strings you need for the last two
2241 <filename>SRC_URI</filename> lines.
2242 Prior to this, you have to dig around in the home page of the
2243 source for <filename>htop</filename> and determine that the
2244 software is released under GPLv2.
2245 You can provide that in the <filename>LICENSE</filename>
2246 statement.
2247 Now you edit your recipe to have those two strings for
2248 the <filename>SRC_URI</filename> statements:
2249 <literallayout class='monospaced'>
2250 LICENSE = "GPLv2"
2251
2252 LIC_FILES_CHKSUM = ""
2253
2254 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2255 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2256 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2257 </literallayout>
2258 At this point, you can build the software again using the
2259 <filename>bitbake htop</filename> command.
2260 There is just a set of errors now associated with the
2261 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2262 </para>
2263-->
2264
2265 </section>
2266
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002267 <section id='new-dependencies'>
2268 <title>Dependencies</title>
2269
2270 <para>
2271 Most software packages have a short list of other packages
2272 that they require, which are called dependencies.
2273 These dependencies fall into two main categories: build-time
2274 dependencies, which are required when the software is built;
2275 and runtime dependencies, which are required to be installed
2276 on the target in order for the software to run.
2277 </para>
2278
2279 <para>
2280 Within a recipe, you specify build-time dependencies using the
2281 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2282 variable.
2283 Although nuances exist, items specified in
2284 <filename>DEPENDS</filename> should be names of other recipes.
2285 It is important that you specify all build-time dependencies
2286 explicitly.
2287 If you do not, due to the parallel nature of BitBake's
2288 execution, you can end up with a race condition where the
2289 dependency is present for one task of a recipe (e.g.
2290 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
2291 and then gone when the next task runs (e.g.
2292 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
2293 </para>
2294
2295 <para>
2296 Another consideration is that configure scripts might
2297 automatically check for optional dependencies and enable
2298 corresponding functionality if those dependencies are found.
2299 This behavior means that to ensure deterministic results and
2300 thus avoid more race conditions, you need to either explicitly
2301 specify these dependencies as well, or tell the configure
2302 script explicitly to disable the functionality.
2303 If you wish to make a recipe that is more generally useful
2304 (e.g. publish the recipe in a layer for others to use),
2305 instead of hard-disabling the functionality, you can use the
2306 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
2307 variable to allow functionality and the corresponding
2308 dependencies to be enabled and disabled easily by other
2309 users of the recipe.
2310 </para>
2311
2312 <para>
2313 Similar to build-time dependencies, you specify runtime
2314 dependencies through a variable -
2315 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
2316 which is package-specific.
2317 All variables that are package-specific need to have the name
2318 of the package added to the end as an override.
2319 Since the main package for a recipe has the same name as the
2320 recipe, and the recipe's name can be found through the
2321 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2322 variable, then you specify the dependencies for the main
2323 package by setting <filename>RDEPENDS_${PN}</filename>.
2324 If the package were named <filename>${PN}-tools</filename>,
2325 then you would set <filename>RDEPENDS_${PN}-tools</filename>,
2326 and so forth.
2327 </para>
2328
2329 <para>
2330 Some runtime dependencies will be set automatically at
2331 packaging time.
2332 These dependencies include any shared library dependencies
2333 (i.e. if a package "example" contains "libexample" and
2334 another package "mypackage" contains a binary that links to
2335 "libexample" then the OpenEmbedded build system will
2336 automatically add a runtime dependency to "mypackage" on
2337 "example").
2338 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002339 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
2340 section in the Yocto Project Overview and Concepts Manual for
2341 further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002342 </para>
2343 </section>
2344
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002345 <section id='new-recipe-configuring-the-recipe'>
2346 <title>Configuring the Recipe</title>
2347
2348 <para>
2349 Most software provides some means of setting build-time
2350 configuration options before compilation.
2351 Typically, setting these options is accomplished by running a
2352 configure script with some options, or by modifying a build
2353 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002354 <note>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002355 As of Yocto Project Release 1.7, some of the core recipes
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002356 that package binary configuration scripts now disable the
2357 scripts due to the scripts previously requiring error-prone
2358 path substitution.
2359 The OpenEmbedded build system uses
2360 <filename>pkg-config</filename> now, which is much more
2361 robust.
2362 You can find a list of the <filename>*-config</filename>
2363 scripts that are disabled list in the
2364 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2365 section in the Yocto Project Reference Manual.
2366 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002367 </para>
2368
2369 <para>
2370 A major part of build-time configuration is about checking for
2371 build-time dependencies and possibly enabling optional
2372 functionality as a result.
2373 You need to specify any build-time dependencies for the
2374 software you are building in your recipe's
2375 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2376 value, in terms of other recipes that satisfy those
2377 dependencies.
2378 You can often find build-time or runtime
2379 dependencies described in the software's documentation.
2380 </para>
2381
2382 <para>
2383 The following list provides configuration items of note based
2384 on how your software is built:
2385 <itemizedlist>
2386 <listitem><para><emphasis>Autotools:</emphasis>
2387 If your source files have a
2388 <filename>configure.ac</filename> file, then your
2389 software is built using Autotools.
2390 If this is the case, you just need to worry about
2391 modifying the configuration.</para>
2392 <para>When using Autotools, your recipe needs to inherit
2393 the
2394 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2395 class and your recipe does not have to contain a
2396 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2397 task.
2398 However, you might still want to make some adjustments.
2399 For example, you can set
2400 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002401 or
2402 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002403 to pass any needed configure options that are specific
2404 to the recipe.</para></listitem>
2405 <listitem><para><emphasis>CMake:</emphasis>
2406 If your source files have a
2407 <filename>CMakeLists.txt</filename> file, then your
2408 software is built using CMake.
2409 If this is the case, you just need to worry about
2410 modifying the configuration.</para>
2411 <para>When you use CMake, your recipe needs to inherit
2412 the
2413 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2414 class and your recipe does not have to contain a
2415 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2416 task.
2417 You can make some adjustments by setting
2418 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2419 to pass any needed configure options that are specific
2420 to the recipe.</para></listitem>
2421 <listitem><para><emphasis>Other:</emphasis>
2422 If your source files do not have a
2423 <filename>configure.ac</filename> or
2424 <filename>CMakeLists.txt</filename> file, then your
2425 software is built using some method other than Autotools
2426 or CMake.
2427 If this is the case, you normally need to provide a
2428 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2429 task in your recipe
2430 unless, of course, there is nothing to configure.
2431 </para>
2432 <para>Even if your software is not being built by
2433 Autotools or CMake, you still might not need to deal
2434 with any configuration issues.
2435 You need to determine if configuration is even a required step.
2436 You might need to modify a Makefile or some configuration file
2437 used for the build to specify necessary build options.
2438 Or, perhaps you might need to run a provided, custom
2439 configure script with the appropriate options.</para>
2440 <para>For the case involving a custom configure
2441 script, you would run
2442 <filename>./configure --help</filename> and look for
2443 the options you need to set.</para></listitem>
2444 </itemizedlist>
2445 </para>
2446
2447 <para>
2448 Once configuration succeeds, it is always good practice to
2449 look at the <filename>log.do_configure</filename> file to
2450 ensure that the appropriate options have been enabled and no
2451 additional build-time dependencies need to be added to
2452 <filename>DEPENDS</filename>.
2453 For example, if the configure script reports that it found
2454 something not mentioned in <filename>DEPENDS</filename>, or
2455 that it did not find something that it needed for some
2456 desired optional functionality, then you would need to add
2457 those to <filename>DEPENDS</filename>.
2458 Looking at the log might also reveal items being checked for,
2459 enabled, or both that you do not want, or items not being found
2460 that are in <filename>DEPENDS</filename>, in which case
2461 you would need to look at passing extra options to the
2462 configure script as needed.
2463 For reference information on configure options specific to the
2464 software you are building, you can consult the output of the
2465 <filename>./configure --help</filename> command within
2466 <filename>${S}</filename> or consult the software's upstream
2467 documentation.
2468 </para>
2469 </section>
2470
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002471 <section id='new-recipe-using-headers-to-interface-with-devices'>
2472 <title>Using Headers to Interface with Devices</title>
2473
2474 <para>
2475 If your recipe builds an application that needs to
2476 communicate with some device or needs an API into a custom
2477 kernel, you will need to provide appropriate header files.
2478 Under no circumstances should you ever modify the existing
2479 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>
2480 file.
2481 These headers are used to build <filename>libc</filename> and
2482 must not be compromised with custom or machine-specific
2483 header information.
2484 If you customize <filename>libc</filename> through modified
2485 headers all other applications that use
2486 <filename>libc</filename> thus become affected.
2487 <note><title>Warning</title>
2488 Never copy and customize the <filename>libc</filename>
2489 header file (i.e.
2490 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>).
2491 </note>
2492 The correct way to interface to a device or custom kernel is
2493 to use a separate package that provides the additional headers
2494 for the driver or other unique interfaces.
2495 When doing so, your application also becomes responsible for
2496 creating a dependency on that specific provider.
2497 </para>
2498
2499 <para>
2500 Consider the following:
2501 <itemizedlist>
2502 <listitem><para>
2503 Never modify
2504 <filename>linux-libc-headers.inc</filename>.
2505 Consider that file to be part of the
2506 <filename>libc</filename> system, and not something
2507 you use to access the kernel directly.
2508 You should access <filename>libc</filename> through
2509 specific <filename>libc</filename> calls.
2510 </para></listitem>
2511 <listitem><para>
2512 Applications that must talk directly to devices
2513 should either provide necessary headers themselves,
2514 or establish a dependency on a special headers package
2515 that is specific to that driver.
2516 </para></listitem>
2517 </itemizedlist>
2518 </para>
2519
2520 <para>
2521 For example, suppose you want to modify an existing header
2522 that adds I/O control or network support.
2523 If the modifications are used by a small number programs,
2524 providing a unique version of a header is easy and has little
2525 impact.
2526 When doing so, bear in mind the guidelines in the previous
2527 list.
2528 <note>
2529 If for some reason your changes need to modify the behavior
2530 of the <filename>libc</filename>, and subsequently all
2531 other applications on the system, use a
2532 <filename>.bbappend</filename> to modify the
2533 <filename>linux-kernel-headers.inc</filename> file.
2534 However, take care to not make the changes
2535 machine specific.
2536 </note>
2537 </para>
2538
2539 <para>
2540 Consider a case where your kernel is older and you need
2541 an older <filename>libc</filename> ABI.
2542 The headers installed by your recipe should still be a
2543 standard mainline kernel, not your own custom one.
2544 </para>
2545
2546 <para>
2547 When you use custom kernel headers you need to get them from
2548 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>,
2549 which is the directory with kernel headers that are
2550 required to build out-of-tree modules.
2551 Your recipe will also need the following:
2552 <literallayout class='monospaced'>
2553 do_configure[depends] += "virtual/kernel:do_shared_workdir"
2554 </literallayout>
2555 </para>
2556 </section>
2557
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002558 <section id='new-recipe-compilation'>
2559 <title>Compilation</title>
2560
2561 <para>
2562 During a build, the <filename>do_compile</filename> task
2563 happens after source is fetched, unpacked, and configured.
2564 If the recipe passes through <filename>do_compile</filename>
2565 successfully, nothing needs to be done.
2566 </para>
2567
2568 <para>
2569 However, if the compile step fails, you need to diagnose the
2570 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002571 Here are some common issues that cause failures.
2572 <note>
2573 For cases where improper paths are detected for
2574 configuration files or for when libraries/headers cannot
2575 be found, be sure you are using the more robust
2576 <filename>pkg-config</filename>.
2577 See the note in section
2578 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2579 for additional information.
2580 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002581 <itemizedlist>
2582 <listitem><para><emphasis>Parallel build failures:</emphasis>
2583 These failures manifest themselves as intermittent
2584 errors, or errors reporting that a file or directory
2585 that should be created by some other part of the build
2586 process could not be found.
2587 This type of failure can occur even if, upon inspection,
2588 the file or directory does exist after the build has
2589 failed, because that part of the build process happened
2590 in the wrong order.</para>
2591 <para>To fix the problem, you need to either satisfy
2592 the missing dependency in the Makefile or whatever
2593 script produced the Makefile, or (as a workaround)
2594 set
2595 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2596 to an empty string:
2597 <literallayout class='monospaced'>
2598 PARALLEL_MAKE = ""
2599 </literallayout></para>
2600 <para>
2601 For information on parallel Makefile issues, see the
2602 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2603 section.
2604 </para></listitem>
2605 <listitem><para><emphasis>Improper host path usage:</emphasis>
2606 This failure applies to recipes building for the target
2607 or <filename>nativesdk</filename> only.
2608 The failure occurs when the compilation process uses
2609 improper headers, libraries, or other files from the
2610 host system when cross-compiling for the target.
2611 </para>
2612 <para>To fix the problem, examine the
2613 <filename>log.do_compile</filename> file to identify
2614 the host paths being used (e.g.
2615 <filename>/usr/include</filename>,
2616 <filename>/usr/lib</filename>, and so forth) and then
2617 either add configure options, apply a patch, or do both.
2618 </para></listitem>
2619 <listitem><para><emphasis>Failure to find required
2620 libraries/headers:</emphasis>
2621 If a build-time dependency is missing because it has
2622 not been declared in
2623 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2624 or because the dependency exists but the path used by
2625 the build process to find the file is incorrect and the
2626 configure step did not detect it, the compilation
2627 process could fail.
2628 For either of these failures, the compilation process
2629 notes that files could not be found.
2630 In these cases, you need to go back and add additional
2631 options to the configure script as well as possibly
2632 add additional build-time dependencies to
2633 <filename>DEPENDS</filename>.</para>
2634 <para>Occasionally, it is necessary to apply a patch
2635 to the source to ensure the correct paths are used.
2636 If you need to specify paths to find files staged
2637 into the sysroot from other recipes, use the variables
2638 that the OpenEmbedded build system provides
2639 (e.g.
2640 <filename>STAGING_BINDIR</filename>,
2641 <filename>STAGING_INCDIR</filename>,
2642 <filename>STAGING_DATADIR</filename>, and so forth).
2643<!--
2644 (e.g.
2645 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2646 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2647 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2648 and so forth).
2649-->
2650 </para></listitem>
2651 </itemizedlist>
2652 </para>
2653 </section>
2654
2655 <section id='new-recipe-installing'>
2656 <title>Installing</title>
2657
2658 <para>
2659 During <filename>do_install</filename>, the task copies the
2660 built files along with their hierarchy to locations that
2661 would mirror their locations on the target device.
2662 The installation process copies files from the
2663 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2664 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2665 and
2666 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2667 directories to the
2668 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2669 directory to create the structure as it should appear on the
2670 target system.
2671 </para>
2672
2673 <para>
2674 How your software is built affects what you must do to be
2675 sure your software is installed correctly.
2676 The following list describes what you must do for installation
2677 depending on the type of build system used by the software
2678 being built:
2679 <itemizedlist>
2680 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2681 If the software your recipe is building uses Autotools
2682 or CMake, the OpenEmbedded build
2683 system understands how to install the software.
2684 Consequently, you do not have to have a
2685 <filename>do_install</filename> task as part of your
2686 recipe.
2687 You just need to make sure the install portion of the
2688 build completes with no issues.
2689 However, if you wish to install additional files not
2690 already being installed by
2691 <filename>make install</filename>, you should do this
2692 using a <filename>do_install_append</filename> function
2693 using the install command as described in
2694 the "Manual" bulleted item later in this list.
2695 </para></listitem>
2696 <listitem><para><emphasis>Other (using
2697 <filename>make install</filename>):</emphasis>
2698 You need to define a
2699 <filename>do_install</filename> function in your
2700 recipe.
2701 The function should call
2702 <filename>oe_runmake install</filename> and will likely
2703 need to pass in the destination directory as well.
2704 How you pass that path is dependent on how the
2705 <filename>Makefile</filename> being run is written
2706 (e.g. <filename>DESTDIR=${D}</filename>,
2707 <filename>PREFIX=${D}</filename>,
2708 <filename>INSTALLROOT=${D}</filename>, and so forth).
2709 </para>
2710 <para>For an example recipe using
2711 <filename>make install</filename>, see the
2712 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2713 section.</para></listitem>
2714 <listitem><para><emphasis>Manual:</emphasis>
2715 You need to define a
2716 <filename>do_install</filename> function in your
2717 recipe.
2718 The function must first use
2719 <filename>install -d</filename> to create the
2720 directories under
2721 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2722 Once the directories exist, your function can use
2723 <filename>install</filename> to manually install the
2724 built software into the directories.</para>
2725 <para>You can find more information on
2726 <filename>install</filename> at
2727 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2728 </para></listitem>
2729 </itemizedlist>
2730 </para>
2731
2732 <para>
2733 For the scenarios that do not use Autotools or
2734 CMake, you need to track the installation
2735 and diagnose and fix any issues until everything installs
2736 correctly.
2737 You need to look in the default location of
2738 <filename>${D}</filename>, which is
2739 <filename>${WORKDIR}/image</filename>, to be sure your
2740 files have been installed correctly.
2741 </para>
2742
2743 <note><title>Notes</title>
2744 <itemizedlist>
2745 <listitem><para>
2746 During the installation process, you might need to
2747 modify some of the installed files to suit the target
2748 layout.
2749 For example, you might need to replace hard-coded paths
2750 in an initscript with values of variables provided by
2751 the build system, such as replacing
2752 <filename>/usr/bin/</filename> with
2753 <filename>${bindir}</filename>.
2754 If you do perform such modifications during
2755 <filename>do_install</filename>, be sure to modify the
2756 destination file after copying rather than before
2757 copying.
2758 Modifying after copying ensures that the build system
2759 can re-execute <filename>do_install</filename> if
2760 needed.
2761 </para></listitem>
2762 <listitem><para>
2763 <filename>oe_runmake install</filename>, which can be
2764 run directly or can be run indirectly by the
2765 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2766 and
2767 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2768 classes, runs <filename>make install</filename> in
2769 parallel.
2770 Sometimes, a Makefile can have missing dependencies
2771 between targets that can result in race conditions.
2772 If you experience intermittent failures during
2773 <filename>do_install</filename>, you might be able to
2774 work around them by disabling parallel Makefile
2775 installs by adding the following to the recipe:
2776 <literallayout class='monospaced'>
2777 PARALLEL_MAKEINST = ""
2778 </literallayout>
2779 See
2780 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2781 for additional information.
2782 </para></listitem>
2783 </itemizedlist>
2784 </note>
2785 </section>
2786
2787 <section id='new-recipe-enabling-system-services'>
2788 <title>Enabling System Services</title>
2789
2790 <para>
2791 If you want to install a service, which is a process that
2792 usually starts on boot and runs in the background, then
2793 you must include some additional definitions in your recipe.
2794 </para>
2795
2796 <para>
2797 If you are adding services and the service initialization
2798 script or the service file itself is not installed, you must
2799 provide for that installation in your recipe using a
2800 <filename>do_install_append</filename> function.
2801 If your recipe already has a <filename>do_install</filename>
2802 function, update the function near its end rather than
2803 adding an additional <filename>do_install_append</filename>
2804 function.
2805 </para>
2806
2807 <para>
2808 When you create the installation for your services, you need
2809 to accomplish what is normally done by
2810 <filename>make install</filename>.
2811 In other words, make sure your installation arranges the output
2812 similar to how it is arranged on the target system.
2813 </para>
2814
2815 <para>
2816 The OpenEmbedded build system provides support for starting
2817 services two different ways:
2818 <itemizedlist>
2819 <listitem><para><emphasis>SysVinit:</emphasis>
2820 SysVinit is a system and service manager that
2821 manages the init system used to control the very basic
2822 functions of your system.
2823 The init program is the first program
2824 started by the Linux kernel when the system boots.
2825 Init then controls the startup, running and shutdown
2826 of all other programs.</para>
2827 <para>To enable a service using SysVinit, your recipe
2828 needs to inherit the
2829 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2830 class.
2831 The class helps facilitate safely installing the
2832 package on the target.</para>
2833 <para>You will need to set the
2834 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2835 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2836 and
2837 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2838 variables within your recipe.</para></listitem>
2839 <listitem><para><emphasis>systemd:</emphasis>
2840 System Management Daemon (systemd) was designed to
2841 replace SysVinit and to provide
2842 enhanced management of services.
2843 For more information on systemd, see the systemd
2844 homepage at
2845 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2846 </para>
2847 <para>To enable a service using systemd, your recipe
2848 needs to inherit the
2849 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2850 class.
2851 See the <filename>systemd.bbclass</filename> file
2852 located in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002853 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002854 section for more information.
2855 </para></listitem>
2856 </itemizedlist>
2857 </para>
2858 </section>
2859
2860 <section id='new-recipe-packaging'>
2861 <title>Packaging</title>
2862
2863 <para>
2864 Successful packaging is a combination of automated processes
2865 performed by the OpenEmbedded build system and some
2866 specific steps you need to take.
2867 The following list describes the process:
2868 <itemizedlist>
2869 <listitem><para><emphasis>Splitting Files</emphasis>:
2870 The <filename>do_package</filename> task splits the
2871 files produced by the recipe into logical components.
2872 Even software that produces a single binary might
2873 still have debug symbols, documentation, and other
2874 logical components that should be split out.
2875 The <filename>do_package</filename> task ensures
2876 that files are split up and packaged correctly.
2877 </para></listitem>
2878 <listitem><para><emphasis>Running QA Checks</emphasis>:
2879 The
2880 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2881 class adds a step to
2882 the package generation process so that output quality
2883 assurance checks are generated by the OpenEmbedded
2884 build system.
2885 This step performs a range of checks to be sure the
2886 build's output is free of common problems that show
2887 up during runtime.
2888 For information on these checks, see the
2889 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2890 class and the
2891 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2892 chapter in the Yocto Project Reference Manual.
2893 </para></listitem>
2894 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2895 After you build your software, you need to be sure
2896 your packages are correct.
2897 Examine the
2898 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2899 directory and make sure files are where you expect
2900 them to be.
2901 If you discover problems, you can set
2902 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2903 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2904 <filename>do_install(_append)</filename>, and so forth as
2905 needed.
2906 </para></listitem>
2907 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2908 If you need to split an application into several
2909 packages, see the
2910 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2911 section for an example.
2912 </para></listitem>
2913 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2914 For an example showing how to install a
2915 post-installation script, see the
2916 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2917 section.
2918 </para></listitem>
2919 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2920 Depending on what your recipe is building and how it
2921 is configured, it might be important to mark the
2922 packages produced as being specific to a particular
2923 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002924 a particular machine or architecture at all.</para>
2925 <para>By default, packages apply to any machine with the
2926 same architecture as the target machine.
2927 When a recipe produces packages that are
2928 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002929 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2930 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002931 is applied only for a particular machine), you should
2932 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002933 recipe:
2934 <literallayout class='monospaced'>
2935 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002936 </literallayout></para>
2937 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002938 that do not contain anything specific to the target
2939 machine or architecture at all (e.g. recipes
2940 that simply package script files or configuration
2941 files), you should use the
2942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
2943 class to do this for you by adding this to your
2944 recipe:
2945 <literallayout class='monospaced'>
2946 inherit allarch
2947 </literallayout>
2948 Ensuring that the package architecture is correct is
2949 not critical while you are doing the first few builds
2950 of your recipe.
2951 However, it is important in order
2952 to ensure that your recipe rebuilds (or does not
2953 rebuild) appropriately in response to changes in
2954 configuration, and to ensure that you get the
2955 appropriate packages installed on the target machine,
2956 particularly if you run separate builds for more
2957 than one target machine.
2958 </para></listitem>
2959 </itemizedlist>
2960 </para>
2961 </section>
2962
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002963 <section id='new-sharing-files-between-recipes'>
2964 <title>Sharing Files Between Recipes</title>
2965
2966 <para>
2967 Recipes often need to use files provided by other recipes on
2968 the build host.
2969 For example, an application linking to a common library needs
2970 access to the library itself and its associated headers.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002971 The way this access is accomplished is by populating a sysroot
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002972 with files.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002973 Each recipe has two sysroots in its work directory, one for
2974 target files
2975 (<filename>recipe-sysroot</filename>) and one for files that
2976 are native to the build host
2977 (<filename>recipe-sysroot-native</filename>).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002978 <note>
2979 You could find the term "staging" used within the Yocto
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002980 project regarding files populating sysroots (e.g. the
Brad Bishop37a0e4d2017-12-04 01:01:44 -05002981 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink>
2982 variable).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002983 </note>
2984 </para>
2985
2986 <para>
2987 Recipes should never populate the sysroot directly (i.e. write
2988 files into sysroot).
2989 Instead, files should be installed into standard locations
2990 during the
2991 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2992 task within the
2993 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2994 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002995 The reason for this limitation is that almost all files that
2996 populate the sysroot are cataloged in manifests in order to
2997 ensure the files can be removed later when a recipe is either
2998 modified or removed.
2999 Thus, the sysroot is able to remain free from stale files.
3000 </para>
3001
3002 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003003 A subset of the files installed by the
3004 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3005 task are used by the
3006 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3007 task as defined by the the
3008 <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>
3009 variable to automatically populate the sysroot.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003010 It is possible to modify the list of directories that populate
3011 the sysroot.
3012 The following example shows how you could add the
3013 <filename>/opt</filename> directory to the list of
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003014 directories within a recipe:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003015 <literallayout class='monospaced'>
3016 SYSROOT_DIRS += "/opt"
3017 </literallayout>
3018 </para>
3019
3020 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003021 For a more complete description of the
3022 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3023 task and its associated functions, see the
3024 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink>
3025 class.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003026 </para>
3027 </section>
3028
Brad Bishop316dfdd2018-06-25 12:45:53 -04003029 <section id='metadata-virtual-providers'>
3030 <title>Using Virtual Providers</title>
3031
3032 <para>
3033 Prior to a build, if you know that several different recipes
3034 provide the same functionality, you can use a virtual provider
3035 (i.e. <filename>virtual/*</filename>) as a placeholder for the
3036 actual provider.
3037 The actual provider is determined at build-time.
3038 </para>
3039
3040 <para>
3041 A common scenario where a virtual provider is used would be
3042 for the kernel recipe.
3043 Suppose you have three kernel recipes whose
3044 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
3045 values map to <filename>kernel-big</filename>,
3046 <filename>kernel-mid</filename>, and
3047 <filename>kernel-small</filename>.
3048 Furthermore, each of these recipes in some way uses a
3049 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3050 statement that essentially identifies itself as being able
3051 to provide <filename>virtual/kernel</filename>.
3052 Here is one way through the
3053 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-kernel'><filename>kernel</filename></ulink>
3054 class:
3055 <literallayout class='monospaced'>
3056 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
3057 </literallayout>
3058 Any recipe that inherits the <filename>kernel</filename> class
3059 is going to utilize a <filename>PROVIDES</filename> statement
3060 that identifies that recipe as being able to provide the
3061 <filename>virtual/kernel</filename> item.
3062 </para>
3063
3064 <para>
3065 Now comes the time to actually build an image and you need a
3066 kernel recipe, but which one?
3067 You can configure your build to call out the kernel recipe
3068 you want by using the
3069 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></ulink>
3070 variable.
3071 As an example, consider the
3072 <ulink url='https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc'><filename>x86-base.inc</filename></ulink>
3073 include file, which is a machine
3074 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>)
3075 configuration file.
3076 This include file is the reason all x86-based machines use the
3077 <filename>linux-yocto</filename> kernel.
3078 Here are the relevant lines from the include file:
3079 <literallayout class='monospaced'>
3080 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
3081 PREFERRED_VERSION_linux-yocto ??= "4.15%"
3082 </literallayout>
3083 </para>
3084
3085 <para>
3086 When you use a virtual provider, you do not have to
3087 "hard code" a recipe name as a build dependency.
3088 You can use the
3089 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3090 variable to state the build is dependent on
3091 <filename>virtual/kernel</filename> for example:
3092 <literallayout class='monospaced'>
3093 DEPENDS = "virtual/kernel"
3094 </literallayout>
3095 During the build, the OpenEmbedded build system picks
3096 the correct recipe needed for the
3097 <filename>virtual/kernel</filename> dependency based on the
3098 <filename>PREFERRED_PROVIDER</filename> variable.
3099 If you want to use the small kernel mentioned at the beginning
3100 of this section, configure your build as follows:
3101 <literallayout class='monospaced'>
3102 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
3103 </literallayout>
3104 <note>
3105 Any recipe that
3106 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3107 a <filename>virtual/*</filename> item that is ultimately
3108 not selected through
3109 <filename>PREFERRED_PROVIDER</filename> does not get built.
3110 Preventing these recipes from building is usually the
3111 desired behavior since this mechanism's purpose is to
3112 select between mutually exclusive alternative providers.
3113 </note>
3114 </para>
3115
3116 <para>
3117 The following lists specific examples of virtual providers:
3118 <itemizedlist>
3119 <listitem><para>
3120 <filename>virtual/kernel</filename>:
3121 Provides the name of the kernel recipe to use when
3122 building a kernel image.
3123 </para></listitem>
3124 <listitem><para>
3125 <filename>virtual/bootloader</filename>:
3126 Provides the name of the bootloader to use when
3127 building an image.
3128 </para></listitem>
3129 <listitem><para>
3130 <filename>virtual/mesa</filename>:
3131 Provides <filename>gbm.pc</filename>.
3132 </para></listitem>
3133 <listitem><para>
3134 <filename>virtual/egl</filename>:
3135 Provides <filename>egl.pc</filename> and possibly
3136 <filename>wayland-egl.pc</filename>.
3137 </para></listitem>
3138 <listitem><para>
3139 <filename>virtual/libgl</filename>:
3140 Provides <filename>gl.pc</filename> (i.e. libGL).
3141 </para></listitem>
3142 <listitem><para>
3143 <filename>virtual/libgles1</filename>:
3144 Provides <filename>glesv1_cm.pc</filename>
3145 (i.e. libGLESv1_CM).
3146 </para></listitem>
3147 <listitem><para>
3148 <filename>virtual/libgles2</filename>:
3149 Provides <filename>glesv2.pc</filename>
3150 (i.e. libGLESv2).
3151 </para></listitem>
3152 </itemizedlist>
3153 </para>
3154 </section>
3155
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003156 <section id='properly-versioning-pre-release-recipes'>
3157 <title>Properly Versioning Pre-Release Recipes</title>
3158
3159 <para>
3160 Sometimes the name of a recipe can lead to versioning
3161 problems when the recipe is upgraded to a final release.
3162 For example, consider the
3163 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
3164 the list of example recipes in the
3165 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
3166 section.
3167 This recipe is at a release candidate stage (i.e.
3168 "rc1").
3169 When the recipe is released, the recipe filename becomes
3170 <filename>irssi_0.8.16.bb</filename>.
3171 The version change from <filename>0.8.16-rc1</filename>
3172 to <filename>0.8.16</filename> is seen as a decrease by the
3173 build system and package managers, so the resulting packages
3174 will not correctly trigger an upgrade.
3175 </para>
3176
3177 <para>
3178 In order to ensure the versions compare properly, the
3179 recommended convention is to set
3180 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
3181 within the recipe to
3182 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
3183 You can use an additional variable so that you can use the
3184 current version elsewhere.
3185 Here is an example:
3186 <literallayout class='monospaced'>
3187 REALPV = "0.8.16-rc1"
3188 PV = "0.8.15+${REALPV}"
3189 </literallayout>
3190 </para>
3191 </section>
3192
3193 <section id='new-recipe-post-installation-scripts'>
3194 <title>Post-Installation Scripts</title>
3195
3196 <para>
3197 Post-installation scripts run immediately after installing
3198 a package on the target or during image creation when a
3199 package is included in an image.
3200 To add a post-installation script to a package, add a
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003201 <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003202 the recipe file (<filename>.bb</filename>) and replace
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003203 <replaceable>PACKAGENAME</replaceable> with the name of the package
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003204 you want to attach to the <filename>postinst</filename>
3205 script.
3206 To apply the post-installation script to the main package
3207 for the recipe, which is usually what is required, specify
3208 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003209 in place of <replaceable>PACKAGENAME</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003210 </para>
3211
3212 <para>
3213 A post-installation function has the following structure:
3214 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003215 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003216 # Commands to carry out
3217 }
3218 </literallayout>
3219 </para>
3220
3221 <para>
3222 The script defined in the post-installation function is
3223 called when the root filesystem is created.
3224 If the script succeeds, the package is marked as installed.
3225 If the script fails, the package is marked as unpacked and
3226 the script is executed when the image boots again.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003227 <note>
3228 Any RPM post-installation script that runs on the target
3229 should return a 0 exit code.
3230 RPM does not allow non-zero exit codes for these scripts,
3231 and the RPM package manager will cause the package to fail
3232 installation on the target.
3233 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003234 </para>
3235
3236 <para>
3237 Sometimes it is necessary for the execution of a
3238 post-installation script to be delayed until the first boot.
3239 For example, the script might need to be executed on the
3240 device itself.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003241 To delay script execution until boot time, you must explicitly
3242 mark post installs to defer to the target.
3243 You can use <filename>pkg_postinst_ontarget()</filename> or
3244 call
3245 <filename>postinst-intercepts defer_to_first_boot</filename>
3246 from <filename>pkg_postinst()</filename>.
3247 Any failure of a <filename>pkg_postinst()</filename> script
3248 (including exit 1) triggers an error during the
3249 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
3250 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003251 </para>
3252
3253 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003254 If you have recipes that use
3255 <filename>pkg_postinst</filename> function
3256 and they require the use of non-standard native
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003257 tools that have dependencies during rootfs construction, you
3258 need to use the
3259 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3260 variable in your recipe to list these tools.
3261 If you do not use this variable, the tools might be missing and
3262 execution of the post-installation script is deferred until
3263 first boot.
3264 Deferring the script to first boot is undesirable and for
3265 read-only rootfs impossible.
3266 </para>
3267
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003268 <note>
3269 Equivalent support for pre-install, pre-uninstall, and
3270 post-uninstall scripts exist by way of
3271 <filename>pkg_preinst</filename>,
3272 <filename>pkg_prerm</filename>, and
3273 <filename>pkg_postrm</filename>, respectively.
3274 These scrips work in exactly the same way as does
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003275 <filename>pkg_postinst</filename> with the exception
3276 that they run at different times.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003277 Also, because of when they run, they are not applicable to
3278 being run at image creation time like
3279 <filename>pkg_postinst</filename>.
3280 </note>
3281 </section>
3282
3283 <section id='new-recipe-testing'>
3284 <title>Testing</title>
3285
3286 <para>
3287 The final step for completing your recipe is to be sure that
3288 the software you built runs correctly.
3289 To accomplish runtime testing, add the build's output
3290 packages to your image and test them on the target.
3291 </para>
3292
3293 <para>
3294 For information on how to customize your image by adding
3295 specific packages, see the
3296 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3297 section.
3298 </para>
3299 </section>
3300
3301 <section id='new-recipe-testing-examples'>
3302 <title>Examples</title>
3303
3304 <para>
3305 To help summarize how to write a recipe, this section provides
3306 some examples given various scenarios:
3307 <itemizedlist>
3308 <listitem><para>Recipes that use local files</para></listitem>
3309 <listitem><para>Using an Autotooled package</para></listitem>
3310 <listitem><para>Using a Makefile-based package</para></listitem>
3311 <listitem><para>Splitting an application into multiple packages</para></listitem>
3312 <listitem><para>Adding binaries to an image</para></listitem>
3313 </itemizedlist>
3314 </para>
3315
3316 <section id='new-recipe-single-c-file-package-hello-world'>
3317 <title>Single .c File Package (Hello World!)</title>
3318
3319 <para>
3320 Building an application from a single file that is stored
3321 locally (e.g. under <filename>files</filename>) requires
3322 a recipe that has the file listed in the
3323 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3324 variable.
3325 Additionally, you need to manually write the
3326 <filename>do_compile</filename> and
3327 <filename>do_install</filename> tasks.
3328 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3329 variable defines the directory containing the source code,
3330 which is set to
3331 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3332 in this case - the directory BitBake uses for the build.
3333 <literallayout class='monospaced'>
3334 SUMMARY = "Simple helloworld application"
3335 SECTION = "examples"
3336 LICENSE = "MIT"
3337 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3338
3339 SRC_URI = "file://helloworld.c"
3340
3341 S = "${WORKDIR}"
3342
3343 do_compile() {
3344 ${CC} helloworld.c -o helloworld
3345 }
3346
3347 do_install() {
3348 install -d ${D}${bindir}
3349 install -m 0755 helloworld ${D}${bindir}
3350 }
3351 </literallayout>
3352 </para>
3353
3354 <para>
3355 By default, the <filename>helloworld</filename>,
3356 <filename>helloworld-dbg</filename>, and
3357 <filename>helloworld-dev</filename> packages are built.
3358 For information on how to customize the packaging process,
3359 see the
3360 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3361 section.
3362 </para>
3363 </section>
3364
3365 <section id='new-recipe-autotooled-package'>
3366 <title>Autotooled Package</title>
3367 <para>
3368 Applications that use Autotools such as <filename>autoconf</filename> and
3369 <filename>automake</filename> require a recipe that has a source archive listed in
3370 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3371 also inherit the
3372 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3373 class, which contains the definitions of all the steps
3374 needed to build an Autotool-based application.
3375 The result of the build is automatically packaged.
3376 And, if the application uses NLS for localization, packages with local information are
3377 generated (one package per language).
3378 Following is one example: (<filename>hello_2.3.bb</filename>)
3379 <literallayout class='monospaced'>
3380 SUMMARY = "GNU Helloworld application"
3381 SECTION = "examples"
3382 LICENSE = "GPLv2+"
3383 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3384
3385 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3386
3387 inherit autotools gettext
3388 </literallayout>
3389 </para>
3390
3391 <para>
3392 The variable
3393 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3394 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003395 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3396 section in the Yocto Project Overview and Concepts Manual.
3397 You can quickly create Autotool-based recipes in a manner
3398 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003399 </para>
3400 </section>
3401
3402 <section id='new-recipe-makefile-based-package'>
3403 <title>Makefile-Based Package</title>
3404
3405 <para>
3406 Applications that use GNU <filename>make</filename> also require a recipe that has
3407 the source archive listed in
3408 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3409 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3410 starts the <filename>make</filename> command to compile the application.
3411 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003412 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3413 or
3414 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3415 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003416 BitBake passes these options into the GNU <filename>make</filename> invocation.
3417 Note that a <filename>do_install</filename> task is still required.
3418 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3419 </para>
3420
3421 <para>
3422 Some applications might require extra parameters to be passed to the compiler.
3423 For example, the application might need an additional header path.
3424 You can accomplish this by adding to the
3425 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3426 The following example shows this:
3427 <literallayout class='monospaced'>
3428 CFLAGS_prepend = "-I ${S}/include "
3429 </literallayout>
3430 </para>
3431
3432 <para>
3433 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3434 <literallayout class='monospaced'>
3435 SUMMARY = "Tools for managing memory technology devices"
3436 SECTION = "base"
3437 DEPENDS = "zlib lzo e2fsprogs util-linux"
3438 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3439 LICENSE = "GPLv2+"
3440 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3441 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3442
3443 # Use the latest version at 26 Oct, 2013
3444 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3445 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3446 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3447 "
3448
3449 PV = "1.5.1+git${SRCPV}"
3450
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003451 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003452
3453 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3454
3455 do_install () {
3456 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3457 }
3458
3459 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3460
3461 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3462 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3463 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3464
3465 PARALLEL_MAKE = ""
3466
3467 BBCLASSEXTEND = "native"
3468 </literallayout>
3469 </para>
3470 </section>
3471
3472 <section id='splitting-an-application-into-multiple-packages'>
3473 <title>Splitting an Application into Multiple Packages</title>
3474
3475 <para>
3476 You can use the variables
3477 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3478 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3479 to split an application into multiple packages.
3480 </para>
3481
3482 <para>
3483 Following is an example that uses the <filename>libxpm</filename> recipe.
3484 By default, this recipe generates a single package that contains the library along
3485 with a few binaries.
3486 You can modify the recipe to split the binaries into separate packages:
3487 <literallayout class='monospaced'>
3488 require xorg-lib-common.inc
3489
3490 SUMMARY = "Xpm: X Pixmap extension library"
3491 LICENSE = "BSD"
3492 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3493 DEPENDS += "libxext libsm libxt"
3494 PE = "1"
3495
3496 XORG_PN = "libXpm"
3497
3498 PACKAGES =+ "sxpm cxpm"
3499 FILES_cxpm = "${bindir}/cxpm"
3500 FILES_sxpm = "${bindir}/sxpm"
3501 </literallayout>
3502 </para>
3503
3504 <para>
3505 In the previous example, we want to ship the <filename>sxpm</filename>
3506 and <filename>cxpm</filename> binaries in separate packages.
3507 Since <filename>bindir</filename> would be packaged into the main
3508 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3509 package by default, we prepend the <filename>PACKAGES</filename>
3510 variable so additional package names are added to the start of list.
3511 This results in the extra <filename>FILES_*</filename>
3512 variables then containing information that define which files and
3513 directories go into which packages.
3514 Files included by earlier packages are skipped by latter packages.
3515 Thus, the main <filename>PN</filename> package
3516 does not include the above listed files.
3517 </para>
3518 </section>
3519
3520 <section id='packaging-externally-produced-binaries'>
3521 <title>Packaging Externally Produced Binaries</title>
3522
3523 <para>
3524 Sometimes, you need to add pre-compiled binaries to an
3525 image.
3526 For example, suppose that binaries for proprietary code
3527 exist, which are created by a particular division of a
3528 company.
3529 Your part of the company needs to use those binaries as
3530 part of an image that you are building using the
3531 OpenEmbedded build system.
3532 Since you only have the binaries and not the source code,
3533 you cannot use a typical recipe that expects to fetch the
3534 source specified in
3535 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3536 and then compile it.
3537 </para>
3538
3539 <para>
3540 One method is to package the binaries and then install them
3541 as part of the image.
3542 Generally, it is not a good idea to package binaries
3543 since, among other things, it can hinder the ability to
3544 reproduce builds and could lead to compatibility problems
3545 with ABI in the future.
3546 However, sometimes you have no choice.
3547 </para>
3548
3549 <para>
3550 The easiest solution is to create a recipe that uses
3551 the
3552 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3553 class and to be sure that you are using default locations
3554 for build artifacts.
3555 In most cases, the <filename>bin_package</filename> class
3556 handles "skipping" the configure and compile steps as well
3557 as sets things up to grab packages from the appropriate
3558 area.
3559 In particular, this class sets <filename>noexec</filename>
3560 on both the
3561 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3562 and
3563 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3564 tasks, sets
3565 <filename>FILES_${PN}</filename> to "/" so that it picks
3566 up all files, and sets up a
3567 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3568 task, which effectively copies all files from
3569 <filename>${S}</filename> to <filename>${D}</filename>.
3570 The <filename>bin_package</filename> class works well when
3571 the files extracted into <filename>${S}</filename> are
3572 already laid out in the way they should be laid out
3573 on the target.
3574 For more information on these variables, see the
3575 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3576 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3577 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3578 and
3579 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3580 variables in the Yocto Project Reference Manual's variable
3581 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003582 <note><title>Notes</title>
3583 <itemizedlist>
3584 <listitem><para>
3585 Using
3586 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3587 is a good idea even for components distributed
3588 in binary form, and is often necessary for
3589 shared libraries.
3590 For a shared library, listing the library
3591 dependencies in
3592 <filename>DEPENDS</filename> makes sure that
3593 the libraries are available in the staging
3594 sysroot when other recipes link against the
3595 library, which might be necessary for
3596 successful linking.
3597 </para></listitem>
3598 <listitem><para>
3599 Using <filename>DEPENDS</filename> also
3600 allows runtime dependencies between packages
3601 to be added automatically.
3602 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003603 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3604 section in the Yocto Project Overview and
3605 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003606 </para></listitem>
3607 </itemizedlist>
3608 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003609 </para>
3610
3611 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003612 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003613 class, you need to be sure you are doing the following:
3614 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003615 <listitem><para>
3616 Create a recipe where the
3617 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3618 and
3619 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3620 tasks do nothing:
3621 It is usually sufficient to just not define these
3622 tasks in the recipe, because the default
3623 implementations do nothing unless a Makefile is
3624 found in
3625 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3626 </para>
3627
3628 <para>If
3629 <filename>${S}</filename> might contain a Makefile,
3630 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003631 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003632 <filename>do_compile</filename> with custom
3633 versions, then you can use the
3634 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3635 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003636 <literallayout class='monospaced'>
3637 do_configure[noexec] = "1"
3638 do_compile[noexec] = "1"
3639 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003640 Unlike
3641 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3642 using the flag preserves the dependency chain from
3643 the
3644 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>, <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>,
3645 and
3646 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3647 tasks to the
3648 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3649 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003650 </para></listitem>
3651 <listitem><para>Make sure your
3652 <filename>do_install</filename> task installs the
3653 binaries appropriately.
3654 </para></listitem>
3655 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003656 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3657 (usually
3658 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3659 to point to the files you have installed, which of
3660 course depends on where you have installed them
3661 and whether those files are in different locations
3662 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003663 </para></listitem>
3664 </itemizedlist>
3665 </para>
3666 </section>
3667 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003668
3669 <section id="following-recipe-style-guidelines">
3670 <title>Following Recipe Style Guidelines</title>
3671
3672 <para>
3673 When writing recipes, it is good to conform to existing
3674 style guidelines.
3675 The
3676 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3677 wiki page provides rough guidelines for preferred recipe style.
3678 </para>
3679
3680 <para>
3681 It is common for existing recipes to deviate a bit from this
3682 style.
3683 However, aiming for at least a consistent style is a good idea.
3684 Some practices, such as omitting spaces around
3685 <filename>=</filename> operators in assignments or ordering
3686 recipe components in an erratic way, are widely seen as poor
3687 style.
3688 </para>
3689 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003690
3691 <section id='recipe-syntax'>
3692 <title>Recipe Syntax</title>
3693
3694 <para>
3695 Understanding recipe file syntax is important for writing
3696 recipes.
3697 The following list overviews the basic items that make up a
3698 BitBake recipe file.
3699 For more complete BitBake syntax descriptions, see the
3700 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3701 chapter of the BitBake User Manual.
3702 <itemizedlist>
3703 <listitem><para>
3704 <emphasis>Variable Assignments and Manipulations:</emphasis>
3705 Variable assignments allow a value to be assigned to a
3706 variable.
3707 The assignment can be static text or might include
3708 the contents of other variables.
3709 In addition to the assignment, appending and prepending
3710 operations are also supported.</para>
3711
3712 <para>The following example shows some of the ways
3713 you can use variables in recipes:
3714 <literallayout class='monospaced'>
3715 S = "${WORKDIR}/postfix-${PV}"
3716 CFLAGS += "-DNO_ASM"
3717 SRC_URI_append = " file://fixup.patch"
3718 </literallayout>
3719 </para></listitem>
3720 <listitem><para>
3721 <emphasis>Functions:</emphasis>
3722 Functions provide a series of actions to be performed.
3723 You usually use functions to override the default
3724 implementation of a task function or to complement
3725 a default function (i.e. append or prepend to an
3726 existing function).
3727 Standard functions use <filename>sh</filename> shell
3728 syntax, although access to OpenEmbedded variables and
3729 internal methods are also available.</para>
3730
3731 <para>The following is an example function from the
3732 <filename>sed</filename> recipe:
3733 <literallayout class='monospaced'>
3734 do_install () {
3735 autotools_do_install
3736 install -d ${D}${base_bindir}
3737 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3738 rmdir ${D}${bindir}/
3739 }
3740 </literallayout>
3741 It is also possible to implement new functions that
3742 are called between existing tasks as long as the
3743 new functions are not replacing or complementing the
3744 default functions.
3745 You can implement functions in Python
3746 instead of shell.
3747 Both of these options are not seen in the majority of
3748 recipes.
3749 </para></listitem>
3750 <listitem><para><emphasis>Keywords:</emphasis>
3751 BitBake recipes use only a few keywords.
3752 You use keywords to include common
3753 functions (<filename>inherit</filename>), load parts
3754 of a recipe from other files
3755 (<filename>include</filename> and
3756 <filename>require</filename>) and export variables
3757 to the environment (<filename>export</filename>).
3758 </para>
3759
3760 <para>The following example shows the use of some of
3761 these keywords:
3762 <literallayout class='monospaced'>
3763 export POSTCONF = "${STAGING_BINDIR}/postconf"
3764 inherit autoconf
3765 require otherfile.inc
3766 </literallayout>
3767 </para></listitem>
3768 <listitem><para>
3769 <emphasis>Comments (#):</emphasis>
3770 Any lines that begin with the hash character
3771 (<filename>#</filename>) are treated as comment lines
3772 and are ignored:
3773 <literallayout class='monospaced'>
3774 # This is a comment
3775 </literallayout>
3776 </para></listitem>
3777 </itemizedlist>
3778 </para>
3779
3780 <para>
3781 This next list summarizes the most important and most commonly
3782 used parts of the recipe syntax.
3783 For more information on these parts of the syntax, you can
3784 reference the
3785 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3786 chapter in the BitBake User Manual.
3787 <itemizedlist>
3788 <listitem><para>
3789 <emphasis>Line Continuation (\):</emphasis>
3790 Use the backward slash (<filename>\</filename>)
3791 character to split a statement over multiple lines.
3792 Place the slash character at the end of the line that
3793 is to be continued on the next line:
3794 <literallayout class='monospaced'>
3795 VAR = "A really long \
3796 line"
3797 </literallayout>
3798 <note>
3799 You cannot have any characters including spaces
3800 or tabs after the slash character.
3801 </note>
3802 </para></listitem>
3803 <listitem><para>
3804 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3805 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3806 syntax to access the contents of a variable:
3807 <literallayout class='monospaced'>
3808 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3809 </literallayout>
3810 <note>
3811 It is important to understand that the value of a
3812 variable expressed in this form does not get
3813 substituted automatically.
3814 The expansion of these expressions happens
3815 on-demand later (e.g. usually when a function that
3816 makes reference to the variable executes).
3817 This behavior ensures that the values are most
3818 appropriate for the context in which they are
3819 finally used.
3820 On the rare occasion that you do need the variable
3821 expression to be expanded immediately, you can use
3822 the <filename>:=</filename> operator instead of
3823 <filename>=</filename> when you make the
3824 assignment, but this is not generally needed.
3825 </note>
3826 </para></listitem>
3827 <listitem><para>
3828 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3829 Use double quotes around values in all variable
3830 assignments (e.g.
3831 <filename>"<replaceable>value</replaceable>"</filename>).
3832 Following is an example:
3833 <literallayout class='monospaced'>
3834 VAR1 = "${OTHERVAR}"
3835 VAR2 = "The version is ${PV}"
3836 </literallayout>
3837 </para></listitem>
3838 <listitem><para>
3839 <emphasis>Conditional Assignment (?=):</emphasis>
3840 Conditional assignment is used to assign a
3841 value to a variable, but only when the variable is
3842 currently unset.
3843 Use the question mark followed by the equal sign
3844 (<filename>?=</filename>) to make a "soft" assignment
3845 used for conditional assignment.
3846 Typically, "soft" assignments are used in the
3847 <filename>local.conf</filename> file for variables
3848 that are allowed to come through from the external
3849 environment.
3850 </para>
3851
3852 <para>Here is an example where
3853 <filename>VAR1</filename> is set to "New value" if
3854 it is currently empty.
3855 However, if <filename>VAR1</filename> has already been
3856 set, it remains unchanged:
3857 <literallayout class='monospaced'>
3858 VAR1 ?= "New value"
3859 </literallayout>
3860 In this next example, <filename>VAR1</filename>
3861 is left with the value "Original value":
3862 <literallayout class='monospaced'>
3863 VAR1 = "Original value"
3864 VAR1 ?= "New value"
3865 </literallayout>
3866 </para></listitem>
3867 <listitem><para>
3868 <emphasis>Appending (+=):</emphasis>
3869 Use the plus character followed by the equals sign
3870 (<filename>+=</filename>) to append values to existing
3871 variables.
3872 <note>
3873 This operator adds a space between the existing
3874 content of the variable and the new content.
3875 </note></para>
3876
3877 <para>Here is an example:
3878 <literallayout class='monospaced'>
3879 SRC_URI += "file://fix-makefile.patch"
3880 </literallayout>
3881 </para></listitem>
3882 <listitem><para>
3883 <emphasis>Prepending (=+):</emphasis>
3884 Use the equals sign followed by the plus character
3885 (<filename>=+</filename>) to prepend values to existing
3886 variables.
3887 <note>
3888 This operator adds a space between the new content
3889 and the existing content of the variable.
3890 </note></para>
3891
3892 <para>Here is an example:
3893 <literallayout class='monospaced'>
3894 VAR =+ "Starts"
3895 </literallayout>
3896 </para></listitem>
3897 <listitem><para>
3898 <emphasis>Appending (_append):</emphasis>
3899 Use the <filename>_append</filename> operator to
3900 append values to existing variables.
3901 This operator does not add any additional space.
3902 Also, the operator is applied after all the
3903 <filename>+=</filename>, and
3904 <filename>=+</filename> operators have been applied and
3905 after all <filename>=</filename> assignments have
3906 occurred.
3907 </para>
3908
3909 <para>The following example shows the space being
3910 explicitly added to the start to ensure the appended
3911 value is not merged with the existing value:
3912 <literallayout class='monospaced'>
3913 SRC_URI_append = " file://fix-makefile.patch"
3914 </literallayout>
3915 You can also use the <filename>_append</filename>
3916 operator with overrides, which results in the actions
3917 only being performed for the specified target or
3918 machine:
3919 <literallayout class='monospaced'>
3920 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3921 </literallayout>
3922 </para></listitem>
3923 <listitem><para>
3924 <emphasis>Prepending (_prepend):</emphasis>
3925 Use the <filename>_prepend</filename> operator to
3926 prepend values to existing variables.
3927 This operator does not add any additional space.
3928 Also, the operator is applied after all the
3929 <filename>+=</filename>, and
3930 <filename>=+</filename> operators have been applied and
3931 after all <filename>=</filename> assignments have
3932 occurred.
3933 </para>
3934
3935 <para>The following example shows the space being
3936 explicitly added to the end to ensure the prepended
3937 value is not merged with the existing value:
3938 <literallayout class='monospaced'>
3939 CFLAGS_prepend = "-I${S}/myincludes "
3940 </literallayout>
3941 You can also use the <filename>_prepend</filename>
3942 operator with overrides, which results in the actions
3943 only being performed for the specified target or
3944 machine:
3945 <literallayout class='monospaced'>
3946 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
3947 </literallayout>
3948 </para></listitem>
3949 <listitem><para>
3950 <emphasis>Overrides:</emphasis>
3951 You can use overrides to set a value conditionally,
3952 typically based on how the recipe is being built.
3953 For example, to set the
3954 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
3955 variable's value to "standard/base" for any target
3956 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
3957 except for qemuarm where it should be set to
3958 "standard/arm-versatile-926ejs", you would do the
3959 following:
3960 <literallayout class='monospaced'>
3961 KBRANCH = "standard/base"
3962 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
3963 </literallayout>
3964 Overrides are also used to separate alternate values
3965 of a variable in other situations.
3966 For example, when setting variables such as
3967 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3968 and
3969 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
3970 that are specific to individual packages produced by
3971 a recipe, you should always use an override that
3972 specifies the name of the package.
3973 </para></listitem>
3974 <listitem><para>
3975 <emphasis>Indentation:</emphasis>
3976 Use spaces for indentation rather than than tabs.
3977 For shell functions, both currently work.
3978 However, it is a policy decision of the Yocto Project
3979 to use tabs in shell functions.
3980 Realize that some layers have a policy to use spaces
3981 for all indentation.
3982 </para></listitem>
3983 <listitem><para>
3984 <emphasis>Using Python for Complex Operations:</emphasis>
3985 For more advanced processing, it is possible to use
3986 Python code during variable assignments (e.g.
3987 search and replacement on a variable).</para>
3988
3989 <para>You indicate Python code using the
3990 <filename>${@<replaceable>python_code</replaceable>}</filename>
3991 syntax for the variable assignment:
3992 <literallayout class='monospaced'>
3993 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
3994 </literallayout>
3995 </para></listitem>
3996 <listitem><para>
3997 <emphasis>Shell Function Syntax:</emphasis>
3998 Write shell functions as if you were writing a shell
3999 script when you describe a list of actions to take.
4000 You should ensure that your script works with a generic
4001 <filename>sh</filename> and that it does not require
4002 any <filename>bash</filename> or other shell-specific
4003 functionality.
4004 The same considerations apply to various system
4005 utilities (e.g. <filename>sed</filename>,
4006 <filename>grep</filename>, <filename>awk</filename>,
4007 and so forth) that you might wish to use.
4008 If in doubt, you should check with multiple
4009 implementations - including those from BusyBox.
4010 </para></listitem>
4011 </itemizedlist>
4012 </para>
4013 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004014 </section>
4015
4016 <section id="platdev-newmachine">
4017 <title>Adding a New Machine</title>
4018
4019 <para>
4020 Adding a new machine to the Yocto Project is a straightforward
4021 process.
4022 This section describes how to add machines that are similar
4023 to those that the Yocto Project already supports.
4024 <note>
4025 Although well within the capabilities of the Yocto Project,
4026 adding a totally new architecture might require
4027 changes to <filename>gcc/glibc</filename> and to the site
4028 information, which is beyond the scope of this manual.
4029 </note>
4030 </para>
4031
4032 <para>
4033 For a complete example that shows how to add a new machine,
4034 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004035 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
4036 section in the Yocto Project Board Support Package (BSP)
4037 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004038 </para>
4039
4040 <section id="platdev-newmachine-conffile">
4041 <title>Adding the Machine Configuration File</title>
4042
4043 <para>
4044 To add a new machine, you need to add a new machine
4045 configuration file to the layer's
4046 <filename>conf/machine</filename> directory.
4047 This configuration file provides details about the device
4048 you are adding.
4049 </para>
4050
4051 <para>
4052 The OpenEmbedded build system uses the root name of the
4053 machine configuration file to reference the new machine.
4054 For example, given a machine configuration file named
4055 <filename>crownbay.conf</filename>, the build system
4056 recognizes the machine as "crownbay".
4057 </para>
4058
4059 <para>
4060 The most important variables you must set in your machine
4061 configuration file or include from a lower-level configuration
4062 file are as follows:
4063 <itemizedlist>
4064 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4065 (e.g. "arm")</para></listitem>
4066 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4067 </para></listitem>
4068 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4069 (e.g. "apm screen wifi")</para></listitem>
4070 </itemizedlist>
4071 </para>
4072
4073 <para>
4074 You might also need these variables:
4075 <itemizedlist>
4076 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4077 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4078 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4079 (e.g. "zImage")</para></listitem>
4080 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4081 (e.g. "tar.gz jffs2")</para></listitem>
4082 </itemizedlist>
4083 </para>
4084
4085 <para>
4086 You can find full details on these variables in the reference
4087 section.
4088 You can leverage existing machine <filename>.conf</filename>
4089 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4090 </para>
4091 </section>
4092
4093 <section id="platdev-newmachine-kernel">
4094 <title>Adding a Kernel for the Machine</title>
4095
4096 <para>
4097 The OpenEmbedded build system needs to be able to build a kernel
4098 for the machine.
4099 You need to either create a new kernel recipe for this machine,
4100 or extend an existing kernel recipe.
4101 You can find several kernel recipe examples in the
4102 Source Directory at
4103 <filename>meta/recipes-kernel/linux</filename>
4104 that you can use as references.
4105 </para>
4106
4107 <para>
4108 If you are creating a new kernel recipe, normal recipe-writing
4109 rules apply for setting up a
4110 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4111 Thus, you need to specify any necessary patches and set
4112 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4113 to point at the source code.
4114 You need to create a <filename>do_configure</filename> task that
4115 configures the unpacked kernel with a
4116 <filename>defconfig</filename> file.
4117 You can do this by using a <filename>make defconfig</filename>
4118 command or, more commonly, by copying in a suitable
4119 <filename>defconfig</filename> file and then running
4120 <filename>make oldconfig</filename>.
4121 By making use of <filename>inherit kernel</filename> and
4122 potentially some of the <filename>linux-*.inc</filename> files,
4123 most other functionality is centralized and the defaults of the
4124 class normally work well.
4125 </para>
4126
4127 <para>
4128 If you are extending an existing kernel recipe, it is usually
4129 a matter of adding a suitable <filename>defconfig</filename>
4130 file.
4131 The file needs to be added into a location similar to
4132 <filename>defconfig</filename> files used for other machines
4133 in a given kernel recipe.
4134 A possible way to do this is by listing the file in the
4135 <filename>SRC_URI</filename> and adding the machine to the
4136 expression in
4137 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4138 <literallayout class='monospaced'>
4139 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4140 </literallayout>
4141 For more information on <filename>defconfig</filename> files,
4142 see the
4143 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4144 section in the Yocto Project Linux Kernel Development Manual.
4145 </para>
4146 </section>
4147
4148 <section id="platdev-newmachine-formfactor">
4149 <title>Adding a Formfactor Configuration File</title>
4150
4151 <para>
4152 A formfactor configuration file provides information about the
4153 target hardware for which the image is being built and information that
4154 the build system cannot obtain from other sources such as the kernel.
4155 Some examples of information contained in a formfactor configuration file include
4156 framebuffer orientation, whether or not the system has a keyboard,
4157 the positioning of the keyboard in relation to the screen, and
4158 the screen resolution.
4159 </para>
4160
4161 <para>
4162 The build system uses reasonable defaults in most cases.
4163 However, if customization is
4164 necessary, you need to create a <filename>machconfig</filename> file
4165 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4166 directory.
4167 This directory contains directories for specific machines such as
4168 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4169 For information about the settings available and the defaults, see the
4170 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4171 same area.
4172 </para>
4173
4174 <para>
4175 Following is an example for "qemuarm" machine:
4176 <literallayout class='monospaced'>
4177 HAVE_TOUCHSCREEN=1
4178 HAVE_KEYBOARD=1
4179
4180 DISPLAY_CAN_ROTATE=0
4181 DISPLAY_ORIENTATION=0
4182 #DISPLAY_WIDTH_PIXELS=640
4183 #DISPLAY_HEIGHT_PIXELS=480
4184 #DISPLAY_BPP=16
4185 DISPLAY_DPI=150
4186 DISPLAY_SUBPIXEL_ORDER=vrgb
4187 </literallayout>
4188 </para>
4189 </section>
4190 </section>
4191
Brad Bishop316dfdd2018-06-25 12:45:53 -04004192 <section id='gs-upgrading-recipes'>
4193 <title>Upgrading Recipes</title>
4194
4195 <para>
4196 Over time, upstream developers publish new versions for software
4197 built by layer recipes.
4198 It is recommended to keep recipes up-to-date with upstream
4199 version releases.
Brad Bishop15ae2502019-06-18 21:44:24 -04004200 </para>
4201
4202 <para>
4203 While several methods exist that allow you upgrade a recipe,
4204 you might consider checking on the upgrade status of a recipe
4205 first.
4206 You can do so using the
4207 <filename>devtool check-upgrade-status</filename> command.
4208 See the
4209 "<ulink url='&YOCTO_DOCS_REF_URL;#devtool-checking-on-the-upgrade-status-of-a-recipe'>Checking on the Upgrade Status of a Recipe</ulink>"
4210 section in the Yocto Project Reference Manual for more information.
4211 </para>
4212
4213 <para>
4214 The remainder of this section describes three ways you can
4215 upgrade a recipe.
Brad Bishop316dfdd2018-06-25 12:45:53 -04004216 You can use the Automated Upgrade Helper (AUH) to set up
4217 automatic version upgrades.
4218 Alternatively, you can use <filename>devtool upgrade</filename>
4219 to set up semi-automatic version upgrades.
Brad Bishop15ae2502019-06-18 21:44:24 -04004220 Finally, you can manually upgrade a recipe by editing the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004221 recipe itself.
4222 </para>
4223
4224 <section id='gs-using-the-auto-upgrade-helper'>
4225 <title>Using the Auto Upgrade Helper (AUH)</title>
4226
4227 <para>
4228 The AUH utility works in conjunction with the
4229 OpenEmbedded build system in order to automatically generate
4230 upgrades for recipes based on new versions being
4231 published upstream.
4232 Use AUH when you want to create a service that performs the
4233 upgrades automatically and optionally sends you an email with
4234 the results.
4235 </para>
4236
4237 <para>
4238 AUH allows you to update several recipes with a single use.
4239 You can also optionally perform build and integration tests
4240 using images with the results saved to your hard drive and
4241 emails of results optionally sent to recipe maintainers.
4242 Finally, AUH creates Git commits with appropriate commit
4243 messages in the layer's tree for the changes made to recipes.
4244 <note>
4245 Conditions do exist when you should not use AUH to upgrade
4246 recipes and you should instead use either
4247 <filename>devtool upgrade</filename> or upgrade your
4248 recipes manually:
4249 <itemizedlist>
4250 <listitem><para>
4251 When AUH cannot complete the upgrade sequence.
4252 This situation usually results because custom
4253 patches carried by the recipe cannot be
4254 automatically rebased to the new version.
4255 In this case, <filename>devtool upgrade</filename>
4256 allows you to manually resolve conflicts.
4257 </para></listitem>
4258 <listitem><para>
4259 When for any reason you want fuller control over
4260 the upgrade process.
4261 For example, when you want special arrangements
4262 for testing.
4263 </para></listitem>
4264 </itemizedlist>
4265 </note>
4266 </para>
4267
4268 <para>
4269 The following steps describe how to set up the AUH utility:
4270 <orderedlist>
4271 <listitem><para>
4272 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4273 You need to be sure that your development host is
4274 set up to use the Yocto Project.
4275 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004276 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004277 section.
4278 </para></listitem>
4279 <listitem><para>
4280 <emphasis>Make Sure Git is Configured:</emphasis>
4281 The AUH utility requires Git to be configured because
4282 AUH uses Git to save upgrades.
4283 Thus, you must have Git user and email configured.
4284 The following command shows your configurations:
4285 <literallayout class='monospaced'>
4286 $ git config --list
4287 </literallayout>
4288 If you do not have the user and email configured, you
4289 can use the following commands to do so:
4290 <literallayout class='monospaced'>
4291 $ git config --global user.name <replaceable>some_name</replaceable>
4292 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4293 </literallayout>
4294 </para></listitem>
4295 <listitem><para>
4296 <emphasis>Clone the AUH Repository:</emphasis>
4297 To use AUH, you must clone the repository onto your
4298 development host.
4299 The following command uses Git to create a local
4300 copy of the repository on your system:
4301 <literallayout class='monospaced'>
4302 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4303 Cloning into 'auto-upgrade-helper'...
4304 remote: Counting objects: 768, done.
4305 remote: Compressing objects: 100% (300/300), done.
4306 remote: Total 768 (delta 499), reused 703 (delta 434)
4307 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4308 Resolving deltas: 100% (499/499), done.
4309 Checking connectivity... done.
4310 </literallayout>
4311 AUH is not part of the
4312 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4313 or
4314 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4315 repositories.
4316 </para></listitem>
4317 <listitem><para>
4318 <emphasis>Create a Dedicated Build Directory:</emphasis>
4319 Run the
4320 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4321 script to create a fresh build directory that you
4322 use exclusively for running the AUH utility:
4323 <literallayout class='monospaced'>
4324 $ cd ~/poky
4325 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4326 </literallayout>
4327 Re-using an existing build directory and its
4328 configurations is not recommended as existing settings
4329 could cause AUH to fail or behave undesirably.
4330 </para></listitem>
4331 <listitem><para>
4332 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4333 Several settings need to exist in the
4334 <filename>local.conf</filename> file in the build
4335 directory you just created for AUH.
4336 Make these following configurations:
4337 <itemizedlist>
4338 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04004339 If you want to enable
4340 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4341 which is optional, you need the following
4342 lines in the
4343 <filename>conf/local.conf</filename> file:
4344 <literallayout class='monospaced'>
4345 INHERIT =+ "buildhistory"
4346 BUILDHISTORY_COMMIT = "1"
4347 </literallayout>
4348 With this configuration and a successful
4349 upgrade, a build history "diff" file appears in
4350 the
4351 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4352 file found in your build directory.
4353 </para></listitem>
4354 <listitem><para>
4355 If you want to enable testing through the
4356 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4357 class, which is optional, you need to have the
4358 following set in your
4359 <filename>conf/local.conf</filename> file:
4360 <literallayout class='monospaced'>
4361 INHERIT += "testimage"
4362 </literallayout>
4363 <note>
4364 If your distro does not enable by default
4365 ptest, which Poky does, you need the
4366 following in your
4367 <filename>local.conf</filename> file:
4368 <literallayout class='monospaced'>
4369 DISTRO_FEATURES_append = " ptest"
4370 </literallayout>
4371 </note>
4372 </para></listitem>
4373 </itemizedlist>
4374 </para></listitem>
4375 <listitem><para>
4376 <emphasis>Optionally Start a vncserver:</emphasis>
4377 If you are running in a server without an X11 session,
4378 you need to start a vncserver:
4379 <literallayout class='monospaced'>
4380 $ vncserver :1
4381 $ export DISPLAY=:1
4382 </literallayout>
4383 </para></listitem>
4384 <listitem><para>
4385 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4386 You need to have the
4387 <filename>upgrade-helper/upgrade-helper.conf</filename>
4388 configuration file in your build directory.
4389 You can find a sample configuration file in the
4390 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4391 </para>
4392
4393 <para>Read through the sample file and make
4394 configurations as needed.
4395 For example, if you enabled build history in your
4396 <filename>local.conf</filename> as described earlier,
4397 you must enable it in
4398 <filename>upgrade-helper.conf</filename>.</para>
4399
4400 <para>Also, if you are using the default
4401 <filename>maintainers.inc</filename> file supplied
4402 with Poky and located in
4403 <filename>meta-yocto</filename> and you do not set a
4404 "maintainers_whitelist" or "global_maintainer_override"
4405 in the <filename>upgrade-helper.conf</filename>
4406 configuration, and you specify "-e all" on the
4407 AUH command-line, the utility automatically sends out
4408 emails to all the default maintainers.
4409 Please avoid this.
4410 </para></listitem>
4411 </orderedlist>
4412 </para>
4413
4414 <para>
4415 This next set of examples describes how to use the AUH:
4416 <itemizedlist>
4417 <listitem><para>
4418 <emphasis>Upgrading a Specific Recipe:</emphasis>
4419 To upgrade a specific recipe, use the following
4420 form:
4421 <literallayout class='monospaced'>
4422 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4423 </literallayout>
4424 For example, this command upgrades the
4425 <filename>xmodmap</filename> recipe:
4426 <literallayout class='monospaced'>
4427 $ upgrade-helper.py xmodmap
4428 </literallayout>
4429 </para></listitem>
4430 <listitem><para>
4431 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4432 To upgrade a specific recipe to a particular version,
4433 use the following form:
4434 <literallayout class='monospaced'>
4435 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4436 </literallayout>
4437 For example, this command upgrades the
4438 <filename>xmodmap</filename> recipe to version
4439 1.2.3:
4440 <literallayout class='monospaced'>
4441 $ upgrade-helper.py xmodmap -t 1.2.3
4442 </literallayout>
4443 </para></listitem>
4444 <listitem><para>
4445 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4446 To upgrade all recipes to their most recent versions
4447 and suppress the email notifications, use the following
4448 command:
4449 <literallayout class='monospaced'>
4450 $ upgrade-helper.py all
4451 </literallayout>
4452 </para></listitem>
4453 <listitem><para>
4454 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4455 To upgrade all recipes to their most recent versions
4456 and send email messages to maintainers for each
4457 attempted recipe as well as a status email, use the
4458 following command:
4459 <literallayout class='monospaced'>
4460 $ upgrade-helper.py -e all
4461 </literallayout>
4462 </para></listitem>
4463 </itemizedlist>
4464 </para>
4465
4466 <para>
4467 Once you have run the AUH utility, you can find the results
4468 in the AUH build directory:
4469 <literallayout class='monospaced'>
4470 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4471 </literallayout>
4472 The AUH utility also creates recipe update commits from
4473 successful upgrade attempts in the layer tree.
4474 </para>
4475
4476 <para>
4477 You can easily set up to run the AUH utility on a regular
4478 basis by using a cron job.
4479 See the
4480 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4481 file distributed with the utility for an example.
4482 </para>
4483 </section>
4484
4485 <section id='gs-using-devtool-upgrade'>
4486 <title>Using <filename>devtool upgrade</filename></title>
4487
4488 <para>
4489 As mentioned earlier, an alternative method for upgrading
4490 recipes to newer versions is to use
4491 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4492 You can read about <filename>devtool upgrade</filename> in
4493 general in the
4494 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software'>Use <filename>devtool upgrade</filename> to Create a Version of the Recipe that Supports a Newer Version of the Software</ulink>"
4495 section in the Yocto Project Application Development and the
4496 Extensible Software Development Kit (eSDK) Manual.
4497 </para>
4498
4499 <para>
4500 To see all the command-line options available with
4501 <filename>devtool upgrade</filename>, use the following help
4502 command:
4503 <literallayout class='monospaced'>
4504 $ devtool upgrade -h
4505 </literallayout>
4506 </para>
4507
4508 <para>
4509 If you want to find out what version a recipe is currently at
4510 upstream without any attempt to upgrade your local version of
4511 the recipe, you can use the following command:
4512 <literallayout class='monospaced'>
4513 $ devtool latest-version <replaceable>recipe_name</replaceable>
4514 </literallayout>
4515 </para>
4516
4517 <para>
4518 As mentioned in the previous section describing AUH,
4519 <filename>devtool upgrade</filename> works in a
4520 less-automated manner than AUH.
4521 Specifically, <filename>devtool upgrade</filename> only
4522 works on a single recipe that you name on the command line,
4523 cannot perform build and integration testing using images,
4524 and does not automatically generate commits for changes in
4525 the source tree.
4526 Despite all these "limitations",
4527 <filename>devtool upgrade</filename> updates the recipe file
4528 to the new upstream version and attempts to rebase custom
4529 patches contained by the recipe as needed.
4530 <note>
4531 AUH uses much of <filename>devtool upgrade</filename>
4532 behind the scenes making AUH somewhat of a "wrapper"
4533 application for <filename>devtool upgrade</filename>.
4534 </note>
4535 </para>
4536
4537 <para>
4538 A typical scenario involves having used Git to clone an
4539 upstream repository that you use during build operations.
4540 Because you are (or have) built the recipe in the past, the
4541 layer is likely added to your configuration already.
4542 If for some reason, the layer is not added, you could add
4543 it easily using the
4544 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4545 script.
4546 For example, suppose you use the <filename>nano.bb</filename>
4547 recipe from the <filename>meta-oe</filename> layer in the
4548 <filename>meta-openembedded</filename> repository.
4549 For this example, assume that the layer has been cloned into
4550 following area:
4551 <literallayout class='monospaced'>
4552 /home/scottrif/meta-openembedded
4553 </literallayout>
4554 The following command from your
4555 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4556 adds the layer to your build configuration (i.e.
4557 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4558 <literallayout class='monospaced'>
4559 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4560 NOTE: Starting bitbake server...
4561 Parsing recipes: 100% |##########################################| Time: 0:00:55
4562 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4563 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4564 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4565 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4566 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4567 </literallayout>
4568 For this example, assume that the <filename>nano.bb</filename>
4569 recipe that is upstream has a 2.9.3 version number.
4570 However, the version in the local repository is 2.7.4.
4571 The following command from your build directory automatically
4572 upgrades the recipe for you:
4573 <note>
4574 Using the <filename>-V</filename> option is not necessary.
4575 Omitting the version number causes
4576 <filename>devtool upgrade</filename> to upgrade the recipe
4577 to the most recent version.
4578 </note>
4579 <literallayout class='monospaced'>
4580 $ devtool upgrade nano -V 2.9.3
4581 NOTE: Starting bitbake server...
4582 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4583 Parsing recipes: 100% |##########################################| Time: 0:00:46
4584 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4585 NOTE: Extracting current version source...
4586 NOTE: Resolving any missing task queue dependencies
4587 .
4588 .
4589 .
4590 NOTE: Executing SetScene Tasks
4591 NOTE: Executing RunQueue Tasks
4592 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4593 Adding changed files: 100% |#####################################| Time: 0:00:00
4594 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4595 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4596 </literallayout>
4597 Continuing with this example, you can use
4598 <filename>devtool build</filename> to build the newly upgraded
4599 recipe:
4600 <literallayout class='monospaced'>
4601 $ devtool build nano
4602 NOTE: Starting bitbake server...
4603 Loading cache: 100% |################################################################################################| Time: 0:00:01
4604 Loaded 2040 entries from dependency cache.
4605 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4606 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4607 NOTE: Resolving any missing task queue dependencies
4608 .
4609 .
4610 .
4611 NOTE: Executing SetScene Tasks
4612 NOTE: Executing RunQueue Tasks
4613 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4614 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4615 </literallayout>
4616 Within the <filename>devtool upgrade</filename> workflow,
4617 opportunity exists to deploy and test your rebuilt software.
4618 For this example, however, running
4619 <filename>devtool finish</filename> cleans up the workspace
4620 once the source in your workspace is clean.
4621 This usually means using Git to stage and submit commits
4622 for the changes generated by the upgrade process.
4623 </para>
4624
4625 <para>
4626 Once the tree is clean, you can clean things up in this
4627 example with the following command from the
4628 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4629 directory:
4630 <literallayout class='monospaced'>
4631 $ devtool finish nano meta-oe
4632 NOTE: Starting bitbake server...
4633 Loading cache: 100% |################################################################################################| Time: 0:00:00
4634 Loaded 2040 entries from dependency cache.
4635 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4636 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4637 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4638 NOTE: Updating recipe nano_2.9.3.bb
4639 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4640 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4641 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4642 </literallayout>
4643 Using the <filename>devtool finish</filename> command cleans
4644 up the workspace and creates a patch file based on your
4645 commits.
4646 The tool puts all patch files back into the source directory
4647 in a sub-directory named <filename>nano</filename> in this
4648 case.
4649 </para>
4650 </section>
4651
4652 <section id='dev-manually-upgrading-a-recipe'>
4653 <title>Manually Upgrading a Recipe</title>
4654
4655 <para>
4656 If for some reason you choose not to upgrade recipes using the
4657 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4658 or by using
4659 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4660 you can manually edit the recipe files to upgrade the versions.
4661 <note><title>Caution</title>
4662 Manually updating multiple recipes scales poorly and
4663 involves many steps.
4664 The recommendation to upgrade recipe versions is through
4665 AUH or <filename>devtool upgrade</filename>, both of which
4666 automate some steps and provide guidance for others needed
4667 for the manual process.
4668 </note>
4669 </para>
4670
4671 <para>
4672 To manually upgrade recipe versions, follow these general steps:
4673 <orderedlist>
4674 <listitem><para>
4675 <emphasis>Change the Version:</emphasis>
4676 Rename the recipe such that the version (i.e. the
4677 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4678 part of the recipe name) changes appropriately.
4679 If the version is not part of the recipe name, change
4680 the value as it is set for <filename>PV</filename>
4681 within the recipe itself.
4682 </para></listitem>
4683 <listitem><para>
4684 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4685 If the source code your recipe builds is fetched from
4686 Git or some other version control system, update
4687 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4688 to point to the commit hash that matches the new
4689 version.
4690 </para></listitem>
4691 <listitem><para>
4692 <emphasis>Build the Software:</emphasis>
4693 Try to build the recipe using BitBake.
4694 Typical build failures include the following:
4695 <itemizedlist>
4696 <listitem><para>
4697 License statements were updated for the new
4698 version.
4699 For this case, you need to review any changes
4700 to the license and update the values of
4701 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4702 and
4703 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4704 as needed.
4705 <note>
4706 License changes are often inconsequential.
4707 For example, the license text's copyright
4708 year might have changed.
4709 </note>
4710 </para></listitem>
4711 <listitem><para>
4712 Custom patches carried by the older version of
4713 the recipe might fail to apply to the new
4714 version.
4715 For these cases, you need to review the
4716 failures.
4717 Patches might not be necessary for the new
4718 version of the software if the upgraded version
4719 has fixed those issues.
4720 If a patch is necessary and failing, you need
4721 to rebase it into the new version.
4722 </para></listitem>
4723 </itemizedlist>
4724 </para></listitem>
4725 <listitem><para>
4726 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4727 Once you successfully build the new software for a
4728 given architecture, you could test the build for
4729 other architectures by changing the
4730 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4731 variable and rebuilding the software.
4732 This optional step is especially important if the
4733 recipe is to be released publicly.
4734 </para></listitem>
4735 <listitem><para>
4736 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4737 Checking both these reveals if new features exist that
4738 could break backwards-compatibility.
4739 If so, you need to take steps to mitigate or eliminate
4740 that situation.
4741 </para></listitem>
4742 <listitem><para>
4743 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4744 If you want, you can test the new software by booting
4745 it onto actual hardware.
4746 </para></listitem>
4747 <listitem><para>
4748 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4749 After all builds work and any testing is successful,
4750 you can create commits for any changes in the layer
4751 holding your upgraded recipe.
4752 </para></listitem>
4753 </orderedlist>
4754 </para>
4755 </section>
4756 </section>
4757
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004758 <section id='finding-the-temporary-source-code'>
4759 <title>Finding Temporary Source Code</title>
4760
4761 <para>
4762 You might find it helpful during development to modify the
4763 temporary source code used by recipes to build packages.
4764 For example, suppose you are developing a patch and you need to
4765 experiment a bit to figure out your solution.
4766 After you have initially built the package, you can iteratively
4767 tweak the source code, which is located in the
4768 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4769 and then you can force a re-compile and quickly test your altered
4770 code.
4771 Once you settle on a solution, you can then preserve your changes
4772 in the form of patches.
4773 </para>
4774
4775 <para>
4776 During a build, the unpacked temporary source code used by recipes
4777 to build packages is available in the Build Directory as
4778 defined by the
4779 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4780 variable.
4781 Below is the default value for the <filename>S</filename> variable
4782 as defined in the
4783 <filename>meta/conf/bitbake.conf</filename> configuration file
4784 in the
4785 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4786 <literallayout class='monospaced'>
4787 S = "${WORKDIR}/${BP}"
4788 </literallayout>
4789 You should be aware that many recipes override the
4790 <filename>S</filename> variable.
4791 For example, recipes that fetch their source from Git usually set
4792 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4793 <note>
4794 The
4795 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4796 represents the base recipe name, which consists of the name
4797 and version:
4798 <literallayout class='monospaced'>
4799 BP = "${BPN}-${PV}"
4800 </literallayout>
4801 </note>
4802 </para>
4803
4804 <para>
4805 The path to the work directory for the recipe
4806 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4807 is defined as follows:
4808 <literallayout class='monospaced'>
4809 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4810 </literallayout>
4811 The actual directory depends on several things:
4812 <itemizedlist>
4813 <listitem><para>
4814 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4815 The top-level build output directory.
4816 </para></listitem>
4817 <listitem><para>
4818 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4819 The target system identifier.
4820 </para></listitem>
4821 <listitem><para>
4822 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4823 The recipe name.
4824 </para></listitem>
4825 <listitem><para>
4826 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4827 The epoch - (if
4828 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4829 is not specified, which is usually the case for most
4830 recipes, then <filename>EXTENDPE</filename> is blank).
4831 </para></listitem>
4832 <listitem><para>
4833 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4834 The recipe version.
4835 </para></listitem>
4836 <listitem><para>
4837 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4838 The recipe revision.
4839 </para></listitem>
4840 </itemizedlist>
4841 </para>
4842
4843 <para>
4844 As an example, assume a Source Directory top-level folder
4845 named <filename>poky</filename>, a default Build Directory at
4846 <filename>poky/build</filename>, and a
4847 <filename>qemux86-poky-linux</filename> machine target
4848 system.
4849 Furthermore, suppose your recipe is named
4850 <filename>foo_1.3.0.bb</filename>.
4851 In this case, the work directory the build system uses to
4852 build the package would be as follows:
4853 <literallayout class='monospaced'>
4854 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4855 </literallayout>
4856 </para>
4857 </section>
4858
4859 <section id="using-a-quilt-workflow">
4860 <title>Using Quilt in Your Workflow</title>
4861
4862 <para>
4863 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4864 is a powerful tool that allows you to capture source code changes
4865 without having a clean source tree.
4866 This section outlines the typical workflow you can use to modify
4867 source code, test changes, and then preserve the changes in the
4868 form of a patch all using Quilt.
4869 <note><title>Tip</title>
4870 With regard to preserving changes to source files, if you
4871 clean a recipe or have <filename>rm_work</filename> enabled,
4872 the
4873 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4874 as described in the Yocto Project Application Development
4875 and the Extensible Software Development Kit (eSDK) manual
4876 is a safer development flow than the flow that uses Quilt.
4877 </note>
4878 </para>
4879
4880 <para>
4881 Follow these general steps:
4882 <orderedlist>
4883 <listitem><para>
4884 <emphasis>Find the Source Code:</emphasis>
4885 Temporary source code used by the OpenEmbedded build system
4886 is kept in the
4887 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4888 See the
4889 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4890 section to learn how to locate the directory that has the
4891 temporary source code for a particular package.
4892 </para></listitem>
4893 <listitem><para>
4894 <emphasis>Change Your Working Directory:</emphasis>
4895 You need to be in the directory that has the temporary
4896 source code.
4897 That directory is defined by the
4898 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4899 variable.</para></listitem>
4900 <listitem><para>
4901 <emphasis>Create a New Patch:</emphasis>
4902 Before modifying source code, you need to create a new
4903 patch.
4904 To create a new patch file, use
4905 <filename>quilt new</filename> as below:
4906 <literallayout class='monospaced'>
4907 $ quilt new my_changes.patch
4908 </literallayout>
4909 </para></listitem>
4910 <listitem><para>
4911 <emphasis>Notify Quilt and Add Files:</emphasis>
4912 After creating the patch, you need to notify Quilt about
4913 the files you plan to edit.
4914 You notify Quilt by adding the files to the patch you
4915 just created:
4916 <literallayout class='monospaced'>
4917 $ quilt add file1.c file2.c file3.c
4918 </literallayout>
4919 </para></listitem>
4920 <listitem><para>
4921 <emphasis>Edit the Files:</emphasis>
4922 Make your changes in the source code to the files you added
4923 to the patch.
4924 </para></listitem>
4925 <listitem><para>
4926 <emphasis>Test Your Changes:</emphasis>
4927 Once you have modified the source code, the easiest way to
4928 test your changes is by calling the
4929 <filename>do_compile</filename> task as shown in the
4930 following example:
4931 <literallayout class='monospaced'>
4932 $ bitbake -c compile -f <replaceable>package</replaceable>
4933 </literallayout>
4934 The <filename>-f</filename> or <filename>--force</filename>
4935 option forces the specified task to execute.
4936 If you find problems with your code, you can just keep
4937 editing and re-testing iteratively until things work
4938 as expected.
4939 <note>
4940 All the modifications you make to the temporary
4941 source code disappear once you run the
4942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4943 or
4944 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4945 tasks using BitBake (i.e.
4946 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4947 and
4948 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4949 Modifications will also disappear if you use the
4950 <filename>rm_work</filename> feature as described
4951 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004952 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4953 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004954 </note>
4955 </para></listitem>
4956 <listitem><para>
4957 <emphasis>Generate the Patch:</emphasis>
4958 Once your changes work as expected, you need to use Quilt
4959 to generate the final patch that contains all your
4960 modifications.
4961 <literallayout class='monospaced'>
4962 $ quilt refresh
4963 </literallayout>
4964 At this point, the <filename>my_changes.patch</filename>
4965 file has all your edits made to the
4966 <filename>file1.c</filename>, <filename>file2.c</filename>,
4967 and <filename>file3.c</filename> files.</para>
4968
4969 <para>You can find the resulting patch file in the
4970 <filename>patches/</filename> subdirectory of the source
4971 (<filename>S</filename>) directory.
4972 </para></listitem>
4973 <listitem><para>
4974 <emphasis>Copy the Patch File:</emphasis>
4975 For simplicity, copy the patch file into a directory
4976 named <filename>files</filename>, which you can create
4977 in the same directory that holds the recipe
4978 (<filename>.bb</filename>) file or the append
4979 (<filename>.bbappend</filename>) file.
4980 Placing the patch here guarantees that the OpenEmbedded
4981 build system will find the patch.
4982 Next, add the patch into the
4983 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4984 of the recipe.
4985 Here is an example:
4986 <literallayout class='monospaced'>
4987 SRC_URI += "file://my_changes.patch"
4988 </literallayout>
4989 </para></listitem>
4990 </orderedlist>
4991 </para>
4992 </section>
4993
4994 <section id="platdev-appdev-devshell">
4995 <title>Using a Development Shell</title>
4996
4997 <para>
4998 When debugging certain commands or even when just editing packages,
4999 <filename>devshell</filename> can be a useful tool.
5000 When you invoke <filename>devshell</filename>, all tasks up to and
5001 including
5002 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5003 are run for the specified target.
5004 Then, a new terminal is opened and you are placed in
5005 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
5006 the source directory.
5007 In the new terminal, all the OpenEmbedded build-related environment variables are
5008 still defined so you can use commands such as <filename>configure</filename> and
5009 <filename>make</filename>.
5010 The commands execute just as if the OpenEmbedded build system were executing them.
5011 Consequently, working this way can be helpful when debugging a build or preparing
5012 software to be used with the OpenEmbedded build system.
5013 </para>
5014
5015 <para>
5016 Following is an example that uses <filename>devshell</filename> on a target named
5017 <filename>matchbox-desktop</filename>:
5018 <literallayout class='monospaced'>
5019 $ bitbake matchbox-desktop -c devshell
5020 </literallayout>
5021 </para>
5022
5023 <para>
5024 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5025 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5026 variable controls what type of shell is opened.
5027 </para>
5028
5029 <para>
5030 For spawned terminals, the following occurs:
5031 <itemizedlist>
5032 <listitem><para>The <filename>PATH</filename> variable includes the
5033 cross-toolchain.</para></listitem>
5034 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5035 <filename>.pc</filename> files.</para></listitem>
5036 <listitem><para>The <filename>configure</filename> command finds the
5037 Yocto Project site files as well as any other necessary files.</para></listitem>
5038 </itemizedlist>
5039 </para>
5040
5041 <para>
5042 Within this environment, you can run configure or compile
5043 commands as if they were being run by
5044 the OpenEmbedded build system itself.
5045 As noted earlier, the working directory also automatically changes to the
5046 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5047 </para>
5048
5049 <para>
5050 To manually run a specific task using <filename>devshell</filename>,
5051 run the corresponding <filename>run.*</filename> script in
5052 the
5053 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5054 directory (e.g.,
5055 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5056 If a task's script does not exist, which would be the case if the task was
5057 skipped by way of the sstate cache, you can create the task by first running
5058 it outside of the <filename>devshell</filename>:
5059 <literallayout class='monospaced'>
5060 $ bitbake -c <replaceable>task</replaceable>
5061 </literallayout>
5062 <note><title>Notes</title>
5063 <itemizedlist>
5064 <listitem><para>Execution of a task's <filename>run.*</filename>
5065 script and BitBake's execution of a task are identical.
5066 In other words, running the script re-runs the task
5067 just as it would be run using the
5068 <filename>bitbake -c</filename> command.
5069 </para></listitem>
5070 <listitem><para>Any <filename>run.*</filename> file that does not
5071 have a <filename>.pid</filename> extension is a
5072 symbolic link (symlink) to the most recent version of that
5073 file.
5074 </para></listitem>
5075 </itemizedlist>
5076 </note>
5077 </para>
5078
5079 <para>
5080 Remember, that the <filename>devshell</filename> is a mechanism that allows
5081 you to get into the BitBake task execution environment.
5082 And as such, all commands must be called just as BitBake would call them.
5083 That means you need to provide the appropriate options for
5084 cross-compilation and so forth as applicable.
5085 </para>
5086
5087 <para>
5088 When you are finished using <filename>devshell</filename>, exit the shell
5089 or close the terminal window.
5090 </para>
5091
5092 <note><title>Notes</title>
5093 <itemizedlist>
5094 <listitem><para>
5095 It is worth remembering that when using <filename>devshell</filename>
5096 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5097 instead of just using <filename>gcc</filename>.
5098 The same applies to other applications such as <filename>binutils</filename>,
5099 <filename>libtool</filename> and so forth.
5100 BitBake sets up environment variables such as <filename>CC</filename>
5101 to assist applications, such as <filename>make</filename> to find the correct tools.
5102 </para></listitem>
5103 <listitem><para>
5104 It is also worth noting that <filename>devshell</filename> still works over
5105 X11 forwarding and similar situations.
5106 </para></listitem>
5107 </itemizedlist>
5108 </note>
5109 </section>
5110
5111 <section id="platdev-appdev-devpyshell">
5112 <title>Using a Development Python Shell</title>
5113
5114 <para>
5115 Similar to working within a development shell as described in
5116 the previous section, you can also spawn and work within an
5117 interactive Python development shell.
5118 When debugging certain commands or even when just editing packages,
5119 <filename>devpyshell</filename> can be a useful tool.
5120 When you invoke <filename>devpyshell</filename>, all tasks up to and
5121 including
5122 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5123 are run for the specified target.
5124 Then a new terminal is opened.
5125 Additionally, key Python objects and code are available in the same
5126 way they are to BitBake tasks, in particular, the data store 'd'.
5127 So, commands such as the following are useful when exploring the data
5128 store and running functions:
5129 <literallayout class='monospaced'>
Brad Bishop19323692019-04-05 15:28:33 -04005130 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005131 '/media/build1/poky/build/tmp/sysroots'
Brad Bishop19323692019-04-05 15:28:33 -04005132 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005133 '${TMPDIR}/sysroots'
5134 pydevshell> d.setVar("FOO", "bar")
Brad Bishop19323692019-04-05 15:28:33 -04005135 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005136 'bar'
5137 pydevshell> d.delVar("FOO")
Brad Bishop19323692019-04-05 15:28:33 -04005138 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005139 pydevshell> bb.build.exec_func("do_unpack", d)
5140 pydevshell>
5141 </literallayout>
5142 The commands execute just as if the OpenEmbedded build system were executing them.
5143 Consequently, working this way can be helpful when debugging a build or preparing
5144 software to be used with the OpenEmbedded build system.
5145 </para>
5146
5147 <para>
5148 Following is an example that uses <filename>devpyshell</filename> on a target named
5149 <filename>matchbox-desktop</filename>:
5150 <literallayout class='monospaced'>
5151 $ bitbake matchbox-desktop -c devpyshell
5152 </literallayout>
5153 </para>
5154
5155 <para>
5156 This command spawns a terminal and places you in an interactive
5157 Python interpreter within the OpenEmbedded build environment.
5158 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5159 variable controls what type of shell is opened.
5160 </para>
5161
5162 <para>
5163 When you are finished using <filename>devpyshell</filename>, you
5164 can exit the shell either by using Ctrl+d or closing the terminal
5165 window.
5166 </para>
5167 </section>
5168
Brad Bishop316dfdd2018-06-25 12:45:53 -04005169 <section id='dev-building'>
5170 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005171
5172 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005173 This section describes various build procedures.
5174 For example, the steps needed for a simple build, a target that
5175 uses multiple configurations, building an image for more than
5176 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005177 </para>
5178
Brad Bishop316dfdd2018-06-25 12:45:53 -04005179 <section id='dev-building-a-simple-image'>
5180 <title>Building a Simple Image</title>
5181
5182 <para>
5183 In the development environment, you need to build an image
5184 whenever you change hardware support, add or change system
5185 libraries, or add or change services that have dependencies.
5186 Several methods exist that allow you to build an image within
5187 the Yocto Project.
5188 This section presents the basic steps you need to build a
5189 simple image using BitBake from a build host running Linux.
5190 <note><title>Notes</title>
5191 <itemizedlist>
5192 <listitem><para>
5193 For information on how to build an image using
5194 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5195 see the
5196 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5197 </para></listitem>
5198 <listitem><para>
5199 For information on how to use
5200 <filename>devtool</filename> to build images, see
5201 the
5202 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5203 section in the Yocto Project Application
5204 Development and the Extensible Software Development
5205 Kit (eSDK) manual.
5206 </para></listitem>
5207 <listitem><para>
5208 For a quick example on how to build an image using
5209 the OpenEmbedded build system, see the
5210 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5211 document.
5212 </para></listitem>
5213 </itemizedlist>
5214 </note>
5215 </para>
5216
5217 <para>
5218 The build process creates an entire Linux distribution from
5219 source and places it in your
5220 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5221 under <filename>tmp/deploy/images</filename>.
5222 For detailed information on the build process using BitBake,
5223 see the
5224 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5225 section in the Yocto Project Overview and Concepts Manual.
5226 </para>
5227
5228 <para>
5229 The following figure and list overviews the build process:
5230 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5231 <orderedlist>
5232 <listitem><para>
5233 <emphasis>Set up Your Host Development System to Support
5234 Development Using the Yocto Project</emphasis>:
5235 See the
5236 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5237 section for options on how to get a build host ready to
5238 use the Yocto Project.
5239 </para></listitem>
5240 <listitem><para>
5241 <emphasis>Initialize the Build Environment:</emphasis>
5242 Initialize the build environment by sourcing the build
5243 environment script (i.e.
5244 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5245 <literallayout class='monospaced'>
5246 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5247 </literallayout></para>
5248
5249 <para>When you use the initialization script, the
5250 OpenEmbedded build system uses
5251 <filename>build</filename> as the default Build
5252 Directory in your current work directory.
5253 You can use a <replaceable>build_dir</replaceable>
5254 argument with the script to specify a different build
5255 directory.
5256 <note><title>Tip</title>
5257 A common practice is to use a different Build
5258 Directory for different targets.
5259 For example, <filename>~/build/x86</filename> for a
5260 <filename>qemux86</filename> target, and
5261 <filename>~/build/arm</filename> for a
5262 <filename>qemuarm</filename> target.
5263 </note>
5264 </para></listitem>
5265 <listitem><para>
5266 <emphasis>Make Sure Your <filename>local.conf</filename>
5267 File is Correct:</emphasis>
5268 Ensure the <filename>conf/local.conf</filename>
5269 configuration file, which is found in the Build
5270 Directory, is set up how you want it.
5271 This file defines many aspects of the build environment
5272 including the target machine architecture through the
5273 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5274 the packaging format used during the build
5275 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5276 and a centralized tarball download directory through the
5277 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5278 </para></listitem>
5279 <listitem><para>
5280 <emphasis>Build the Image:</emphasis>
5281 Build the image using the <filename>bitbake</filename>
5282 command:
5283 <literallayout class='monospaced'>
5284 $ bitbake <replaceable>target</replaceable>
5285 </literallayout>
5286 <note>
5287 For information on BitBake, see the
5288 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5289 </note>
5290 The <replaceable>target</replaceable> is the name of the
5291 recipe you want to build.
5292 Common targets are the images in
5293 <filename>meta/recipes-core/images</filename>,
5294 <filename>meta/recipes-sato/images</filename>, and so
5295 forth all found in the
5296 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5297 Or, the target can be the name of a recipe for a
5298 specific piece of software such as BusyBox.
5299 For more details about the images the OpenEmbedded build
5300 system supports, see the
5301 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5302 chapter in the Yocto Project Reference Manual.</para>
5303
5304 <para>As an example, the following command builds the
5305 <filename>core-image-minimal</filename> image:
5306 <literallayout class='monospaced'>
5307 $ bitbake core-image-minimal
5308 </literallayout>
5309 Once an image has been built, it often needs to be
5310 installed.
5311 The images and kernels built by the OpenEmbedded
5312 build system are placed in the Build Directory in
5313 <filename class="directory">tmp/deploy/images</filename>.
5314 For information on how to run pre-built images such as
5315 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5316 see the
5317 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5318 manual.
5319 For information about how to install these images,
5320 see the documentation for your particular board or
5321 machine.
5322 </para></listitem>
5323 </orderedlist>
5324 </para>
5325 </section>
5326
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005327 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5328 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005329
5330 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005331 You can use a single <filename>bitbake</filename> command
5332 to build multiple images or packages for different targets
5333 where each image or package requires a different configuration
5334 (multiple configuration builds).
5335 The builds, in this scenario, are sometimes referred to as
5336 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005337 </para>
5338
5339 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005340 This section describes how to set up for multiple
5341 configuration builds and how to account for cross-build
5342 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005343 </para>
5344
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005345 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5346 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005347
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005348 <para>
5349 To accomplish a multiple configuration build, you must
5350 define each target's configuration separately using
5351 a parallel configuration file in the
5352 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5353 and you must follow a required file hierarchy.
5354 Additionally, you must enable the multiple configuration
5355 builds in your <filename>local.conf</filename> file.
5356 </para>
5357
5358 <para>
5359 Follow these steps to set up and execute multiple
5360 configuration builds:
5361 <itemizedlist>
5362 <listitem><para>
5363 <emphasis>Create Separate Configuration Files</emphasis>:
5364 You need to create a single configuration file for
5365 each build target (each multiconfig).
5366 Minimally, each configuration file must define the
5367 machine and the temporary directory BitBake uses
5368 for the build.
5369 Suggested practice dictates that you do not
5370 overlap the temporary directories
5371 used during the builds.
5372 However, it is possible that you can share the
5373 temporary directory
5374 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5375 For example, consider a scenario with two
5376 different multiconfigs for the same
5377 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5378 two distributions such as "poky" and "poky-lsb".
5379 In this case, you might want to use the same
5380 <filename>TMPDIR</filename>.</para>
5381
5382 <para>Here is an example showing the minimal
5383 statements needed in a configuration file for
5384 a "qemux86" target whose temporary build directory
5385 is <filename>tmpmultix86</filename>:
5386 <literallayout class='monospaced'>
5387 MACHINE="qemux86"
5388 TMPDIR="${TOPDIR}/tmpmultix86"
5389 </literallayout></para>
5390
5391 <para>The location for these multiconfig
5392 configuration files is specific.
5393 They must reside in the current build directory in
5394 a sub-directory of <filename>conf</filename> named
5395 <filename>multiconfig</filename>.
5396 Following is an example that defines two
5397 configuration files for the "x86" and "arm"
5398 multiconfigs:
5399 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5400 </para>
5401
5402 <para>The reason for this required file hierarchy
5403 is because the <filename>BBPATH</filename> variable
5404 is not constructed until the layers are parsed.
5405 Consequently, using the configuration file as a
5406 pre-configuration file is not possible unless it is
5407 located in the current working directory.
5408 </para></listitem>
5409 <listitem><para>
5410 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5411 Use the
5412 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5413 variable in your
5414 <filename>conf/local.conf</filename> configuration
5415 file to specify each multiconfig.
5416 Continuing with the example from the previous
5417 figure, the <filename>BBMULTICONFIG</filename>
5418 variable needs to enable two multiconfigs: "x86"
5419 and "arm" by specifying each configuration file:
5420 <literallayout class='monospaced'>
5421 BBMULTICONFIG = "x86 arm"
5422 </literallayout>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005423 </para>
5424
5425 <para>Please note, that a "default" configuration already exists by definition,
5426 this configuration is named: "" (empty string) and is defined by the variables
5427 coming from your local.conf file. So, the previous example actually adds two
5428 additional configurations to your build "arm" and "x86" along with "".
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005429 </para></listitem>
5430 <listitem><para>
5431 <emphasis>Launch BitBake</emphasis>:
5432 Use the following BitBake command form to launch the
5433 multiple configuration build:
5434 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005435 $ bitbake [mc:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[mc:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005436 </literallayout>
5437 For the example in this section, the following
5438 command applies:
5439 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005440 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005441 </literallayout>
5442 The previous BitBake command builds a
5443 <filename>core-image-minimal</filename> image that
5444 is configured through the
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005445 <filename>x86.conf</filename> configuration file,
5446 a <filename>core-image-sato</filename>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005447 image that is configured through the
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005448 <filename>arm.conf</filename> configuration file and a
5449 <filename>core-image-base</filename> that is configured
5450 through your <filename>local.conf</filename> configuration file.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005451 </para></listitem>
5452 </itemizedlist>
5453 <note>
5454 Support for multiple configuration builds in the
5455 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5456 not include Shared State (sstate) optimizations.
5457 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005458 in, for example, two different
5459 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005460 either loads from an existing sstate cache for that
5461 build at the start or builds the object fresh.
5462 </note>
5463 </para>
5464 </section>
5465
5466 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5467 <title>Enabling Multiple Configuration Build Dependencies</title>
5468
5469 <para>
5470 Sometimes dependencies can exist between targets
5471 (multiconfigs) in a multiple configuration build.
5472 For example, suppose that in order to build a
5473 <filename>core-image-sato</filename> image for an "x86"
5474 multiconfig, the root filesystem of an "arm"
5475 multiconfig must exist.
5476 This dependency is essentially that the
5477 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5478 task in the <filename>core-image-sato</filename> recipe
5479 depends on the completion of the
5480 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5481 task of the <filename>core-image-minimal</filename>
5482 recipe.
5483 </para>
5484
5485 <para>
5486 To enable dependencies in a multiple configuration
5487 build, you must declare the dependencies in the recipe
5488 using the following statement form:
5489 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005490 <replaceable>task_or_package</replaceable>[mcdepends] = "mc:<replaceable>from_multiconfig</replaceable>:<replaceable>to_multiconfig</replaceable>:<replaceable>recipe_name</replaceable>:<replaceable>task_on_which_to_depend</replaceable>"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005491 </literallayout>
5492 To better show how to use this statement, consider the
5493 example scenario from the first paragraph of this section.
5494 The following statement needs to be added to the recipe
5495 that builds the <filename>core-image-sato</filename>
5496 image:
5497 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005498 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005499 </literallayout>
5500 In this example, the
5501 <replaceable>from_multiconfig</replaceable> is "x86".
5502 The <replaceable>to_multiconfig</replaceable> is "arm".
5503 The task on which the <filename>do_image</filename> task
5504 in the recipe depends is the <filename>do_rootfs</filename>
5505 task from the <filename>core-image-minimal</filename>
5506 recipe associated with the "arm" multiconfig.
5507 </para>
5508
5509 <para>
5510 Once you set up this dependency, you can build the
5511 "x86" multiconfig using a BitBake command as follows:
5512 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005513 $ bitbake mc:x86:core-image-sato
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005514 </literallayout>
5515 This command executes all the tasks needed to create
5516 the <filename>core-image-sato</filename> image for the
5517 "x86" multiconfig.
5518 Because of the dependency, BitBake also executes through
5519 the <filename>do_rootfs</filename> task for the "arm"
5520 multiconfig build.
5521 </para>
5522
5523 <para>
5524 Having a recipe depend on the root filesystem of another
5525 build might not seem that useful.
5526 Consider this change to the statement in the
5527 <filename>core-image-sato</filename> recipe:
5528 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005529 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005530 </literallayout>
5531 In this case, BitBake must create the
5532 <filename>core-image-minimal</filename> image for the
5533 "arm" build since the "x86" build depends on it.
5534 </para>
5535
5536 <para>
5537 Because "x86" and "arm" are enabled for multiple
5538 configuration builds and have separate configuration
5539 files, BitBake places the artifacts for each build in the
5540 respective temporary build directories (i.e.
5541 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5542 </para>
5543 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005544 </section>
5545
5546 <section id='building-an-initramfs-image'>
5547 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5548
5549 <para>
5550 An initial RAM filesystem (initramfs) image provides a temporary
5551 root filesystem used for early system initialization (e.g.
5552 loading of modules needed to locate and mount the "real" root
5553 filesystem).
5554 <note>
5555 The initramfs image is the successor of initial RAM disk
5556 (initrd).
5557 It is a "copy in and out" (cpio) archive of the initial
5558 filesystem that gets loaded into memory during the Linux
5559 startup process.
5560 Because Linux uses the contents of the archive during
5561 initialization, the initramfs image needs to contain all of the
5562 device drivers and tools needed to mount the final root
5563 filesystem.
5564 </note>
5565 </para>
5566
5567 <para>
5568 Follow these steps to create an initramfs image:
5569 <orderedlist>
5570 <listitem><para>
5571 <emphasis>Create the initramfs Image Recipe:</emphasis>
5572 You can reference the
5573 <filename>core-image-minimal-initramfs.bb</filename>
5574 recipe found in the <filename>meta/recipes-core</filename>
5575 directory of the
5576 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5577 as an example from which to work.
5578 </para></listitem>
5579 <listitem><para>
5580 <emphasis>Decide if You Need to Bundle the initramfs Image
5581 Into the Kernel Image:</emphasis>
5582 If you want the initramfs image that is built to be
5583 bundled in with the kernel image, set the
5584 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5585 variable to "1" in your <filename>local.conf</filename>
5586 configuration file and set the
5587 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5588 variable in the recipe that builds the kernel image.
5589 <note><title>Tip</title>
5590 It is recommended that you do bundle the initramfs
5591 image with the kernel image to avoid circular
5592 dependencies between the kernel recipe and the
5593 initramfs recipe should the initramfs image
5594 include kernel modules.
5595 </note>
5596 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5597 flag causes the initramfs image to be unpacked
5598 into the <filename>${B}/usr/</filename> directory.
5599 The unpacked initramfs image is then passed to the kernel's
5600 <filename>Makefile</filename> using the
5601 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5602 variable, allowing the initramfs image to be built into
5603 the kernel normally.
5604 <note>
5605 If you choose to not bundle the initramfs image with
5606 the kernel image, you are essentially using an
5607 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5608 Creating an initrd is handled primarily through the
5609 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5610 <filename>INITRD_LIVE</filename>, and
5611 <filename>INITRD_IMAGE_LIVE</filename> variables.
5612 For more information, see the
5613 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5614 file.
5615 </note>
5616 </para></listitem>
5617 <listitem><para>
5618 <emphasis>Optionally Add Items to the initramfs Image
5619 Through the initramfs Image Recipe:</emphasis>
5620 If you add items to the initramfs image by way of its
5621 recipe, you should use
5622 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5623 rather than
5624 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5625 <filename>PACKAGE_INSTALL</filename> gives more direct
5626 control of what is added to the image as compared to
5627 the defaults you might not necessarily want that are
5628 set by the
5629 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5630 or
5631 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5632 classes.
5633 </para></listitem>
5634 <listitem><para>
5635 <emphasis>Build the Kernel Image and the initramfs
5636 Image:</emphasis>
5637 Build your kernel image using BitBake.
5638 Because the initramfs image recipe is a dependency of the
5639 kernel image, the initramfs image is built as well and
5640 bundled with the kernel image if you used the
5641 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5642 variable described earlier.
5643 </para></listitem>
5644 </orderedlist>
5645 </para>
5646 </section>
5647
5648 <section id='building-a-tiny-system'>
5649 <title>Building a Tiny System</title>
5650
5651 <para>
5652 Very small distributions have some significant advantages such
5653 as requiring less on-die or in-package memory (cheaper), better
5654 performance through efficient cache usage, lower power requirements
5655 due to less memory, faster boot times, and reduced development
5656 overhead.
5657 Some real-world examples where a very small distribution gives
5658 you distinct advantages are digital cameras, medical devices,
5659 and small headless systems.
5660 </para>
5661
5662 <para>
5663 This section presents information that shows you how you can
5664 trim your distribution to even smaller sizes than the
5665 <filename>poky-tiny</filename> distribution, which is around
5666 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5667 </para>
5668
5669 <section id='tiny-system-overview'>
5670 <title>Overview</title>
5671
5672 <para>
5673 The following list presents the overall steps you need to
5674 consider and perform to create distributions with smaller
5675 root filesystems, achieve faster boot times, maintain your critical
5676 functionality, and avoid initial RAM disks:
5677 <itemizedlist>
5678 <listitem><para>
5679 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5680 </para></listitem>
5681 <listitem><para>
5682 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5683 </para></listitem>
5684 <listitem><para>
5685 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5686 </para></listitem>
5687 <listitem><para>
5688 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5689 </para></listitem>
5690 <listitem><para>
5691 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5692 </para></listitem>
5693 <listitem><para>
5694 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5695 </para></listitem>
5696 <listitem><para>
5697 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5698 </para></listitem>
5699 </itemizedlist>
5700 </para>
5701 </section>
5702
5703 <section id='goals-and-guiding-principles'>
5704 <title>Goals and Guiding Principles</title>
5705
5706 <para>
5707 Before you can reach your destination, you need to know
5708 where you are going.
5709 Here is an example list that you can use as a guide when
5710 creating very small distributions:
5711 <itemizedlist>
5712 <listitem><para>Determine how much space you need
5713 (e.g. a kernel that is 1 Mbyte or less and
5714 a root filesystem that is 3 Mbytes or less).
5715 </para></listitem>
5716 <listitem><para>Find the areas that are currently
5717 taking 90% of the space and concentrate on reducing
5718 those areas.
5719 </para></listitem>
5720 <listitem><para>Do not create any difficult "hacks"
5721 to achieve your goals.</para></listitem>
5722 <listitem><para>Leverage the device-specific
5723 options.</para></listitem>
5724 <listitem><para>Work in a separate layer so that you
5725 keep changes isolated.
5726 For information on how to create layers, see
5727 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5728 </para></listitem>
5729 </itemizedlist>
5730 </para>
5731 </section>
5732
5733 <section id='understand-what-gives-your-image-size'>
5734 <title>Understand What Contributes to Your Image Size</title>
5735
5736 <para>
5737 It is easiest to have something to start with when creating
5738 your own distribution.
5739 You can use the Yocto Project out-of-the-box to create the
5740 <filename>poky-tiny</filename> distribution.
5741 Ultimately, you will want to make changes in your own
5742 distribution that are likely modeled after
5743 <filename>poky-tiny</filename>.
5744 <note>
5745 To use <filename>poky-tiny</filename> in your build,
5746 set the
5747 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5748 variable in your
5749 <filename>local.conf</filename> file to "poky-tiny"
5750 as described in the
5751 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5752 section.
5753 </note>
5754 </para>
5755
5756 <para>
5757 Understanding some memory concepts will help you reduce the
5758 system size.
5759 Memory consists of static, dynamic, and temporary memory.
5760 Static memory is the TEXT (code), DATA (initialized data
5761 in the code), and BSS (uninitialized data) sections.
5762 Dynamic memory represents memory that is allocated at runtime:
5763 stacks, hash tables, and so forth.
5764 Temporary memory is recovered after the boot process.
5765 This memory consists of memory used for decompressing
5766 the kernel and for the <filename>__init__</filename>
5767 functions.
5768 </para>
5769
5770 <para>
5771 To help you see where you currently are with kernel and root
5772 filesystem sizes, you can use two tools found in the
5773 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5774 the <filename>scripts/tiny/</filename> directory:
5775 <itemizedlist>
5776 <listitem><para><filename>ksize.py</filename>: Reports
5777 component sizes for the kernel build objects.
5778 </para></listitem>
5779 <listitem><para><filename>dirsize.py</filename>: Reports
5780 component sizes for the root filesystem.</para></listitem>
5781 </itemizedlist>
5782 This next tool and command help you organize configuration
5783 fragments and view file dependencies in a human-readable form:
5784 <itemizedlist>
5785 <listitem><para><filename>merge_config.sh</filename>:
5786 Helps you manage configuration files and fragments
5787 within the kernel.
5788 With this tool, you can merge individual configuration
5789 fragments together.
5790 The tool allows you to make overrides and warns you
5791 of any missing configuration options.
5792 The tool is ideal for allowing you to iterate on
5793 configurations, create minimal configurations, and
5794 create configuration files for different machines
5795 without having to duplicate your process.</para>
5796 <para>The <filename>merge_config.sh</filename> script is
5797 part of the Linux Yocto kernel Git repositories
5798 (i.e. <filename>linux-yocto-3.14</filename>,
5799 <filename>linux-yocto-3.10</filename>,
5800 <filename>linux-yocto-3.8</filename>, and so forth)
5801 in the
5802 <filename>scripts/kconfig</filename> directory.</para>
5803 <para>For more information on configuration fragments,
5804 see the
5805 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5806 section in the Yocto Project Linux Kernel Development
5807 Manual.
5808 </para></listitem>
5809 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5810 Using the BitBake command with these options brings up
5811 a Dependency Explorer from which you can view file
5812 dependencies.
5813 Understanding these dependencies allows you to make
5814 informed decisions when cutting out various pieces of the
5815 kernel and root filesystem.</para></listitem>
5816 </itemizedlist>
5817 </para>
5818 </section>
5819
5820 <section id='trim-the-root-filesystem'>
5821 <title>Trim the Root Filesystem</title>
5822
5823 <para>
5824 The root filesystem is made up of packages for booting,
5825 libraries, and applications.
5826 To change things, you can configure how the packaging happens,
5827 which changes the way you build them.
5828 You can also modify the filesystem itself or select a different
5829 filesystem.
5830 </para>
5831
5832 <para>
5833 First, find out what is hogging your root filesystem by running the
5834 <filename>dirsize.py</filename> script from your root directory:
5835 <literallayout class='monospaced'>
5836 $ cd <replaceable>root-directory-of-image</replaceable>
5837 $ dirsize.py 100000 > dirsize-100k.log
5838 $ cat dirsize-100k.log
5839 </literallayout>
5840 You can apply a filter to the script to ignore files under
5841 a certain size.
5842 The previous example filters out any files below 100 Kbytes.
5843 The sizes reported by the tool are uncompressed, and thus
5844 will be smaller by a relatively constant factor in a
5845 compressed root filesystem.
5846 When you examine your log file, you can focus on areas of the
5847 root filesystem that take up large amounts of memory.
5848 </para>
5849
5850 <para>
5851 You need to be sure that what you eliminate does not cripple
5852 the functionality you need.
5853 One way to see how packages relate to each other is by using
5854 the Dependency Explorer UI with the BitBake command:
5855 <literallayout class='monospaced'>
5856 $ cd <replaceable>image-directory</replaceable>
5857 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5858 </literallayout>
5859 Use the interface to select potential packages you wish to
5860 eliminate and see their dependency relationships.
5861 </para>
5862
5863 <para>
5864 When deciding how to reduce the size, get rid of packages that
5865 result in minimal impact on the feature set.
5866 For example, you might not need a VGA display.
5867 Or, you might be able to get by with <filename>devtmpfs</filename>
5868 and <filename>mdev</filename> instead of
5869 <filename>udev</filename>.
5870 </para>
5871
5872 <para>
5873 Use your <filename>local.conf</filename> file to make changes.
5874 For example, to eliminate <filename>udev</filename> and
5875 <filename>glib</filename>, set the following in the
5876 local configuration file:
5877 <literallayout class='monospaced'>
5878 VIRTUAL-RUNTIME_dev_manager = ""
5879 </literallayout>
5880 </para>
5881
5882 <para>
5883 Finally, you should consider exactly the type of root
5884 filesystem you need to meet your needs while also reducing
5885 its size.
5886 For example, consider <filename>cramfs</filename>,
5887 <filename>squashfs</filename>, <filename>ubifs</filename>,
5888 <filename>ext2</filename>, or an <filename>initramfs</filename>
5889 using <filename>initramfs</filename>.
5890 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5891 journal.
5892 If you are okay with running read-only, you do not need this
5893 journal.
5894 </para>
5895
5896 <note>
5897 After each round of elimination, you need to rebuild your
5898 system and then use the tools to see the effects of your
5899 reductions.
5900 </note>
5901 </section>
5902
5903 <section id='trim-the-kernel'>
5904 <title>Trim the Kernel</title>
5905
5906 <para>
5907 The kernel is built by including policies for hardware-independent
5908 aspects.
5909 What subsystems do you enable?
5910 For what architecture are you building?
5911 Which drivers do you build by default?
5912 <note>You can modify the kernel source if you want to help
5913 with boot time.
5914 </note>
5915 </para>
5916
5917 <para>
5918 Run the <filename>ksize.py</filename> script from the top-level
5919 Linux build directory to get an idea of what is making up
5920 the kernel:
5921 <literallayout class='monospaced'>
5922 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5923 $ ksize.py > ksize.log
5924 $ cat ksize.log
5925 </literallayout>
5926 When you examine the log, you will see how much space is
5927 taken up with the built-in <filename>.o</filename> files for
5928 drivers, networking, core kernel files, filesystem, sound,
5929 and so forth.
5930 The sizes reported by the tool are uncompressed, and thus
5931 will be smaller by a relatively constant factor in a compressed
5932 kernel image.
5933 Look to reduce the areas that are large and taking up around
5934 the "90% rule."
5935 </para>
5936
5937 <para>
5938 To examine, or drill down, into any particular area, use the
5939 <filename>-d</filename> option with the script:
5940 <literallayout class='monospaced'>
5941 $ ksize.py -d > ksize.log
5942 </literallayout>
5943 Using this option breaks out the individual file information
5944 for each area of the kernel (e.g. drivers, networking, and
5945 so forth).
5946 </para>
5947
5948 <para>
5949 Use your log file to see what you can eliminate from the kernel
5950 based on features you can let go.
5951 For example, if you are not going to need sound, you do not
5952 need any drivers that support sound.
5953 </para>
5954
5955 <para>
5956 After figuring out what to eliminate, you need to reconfigure
5957 the kernel to reflect those changes during the next build.
5958 You could run <filename>menuconfig</filename> and make all your
5959 changes at once.
5960 However, that makes it difficult to see the effects of your
5961 individual eliminations and also makes it difficult to replicate
5962 the changes for perhaps another target device.
5963 A better method is to start with no configurations using
5964 <filename>allnoconfig</filename>, create configuration
5965 fragments for individual changes, and then manage the
5966 fragments into a single configuration file using
5967 <filename>merge_config.sh</filename>.
5968 The tool makes it easy for you to iterate using the
5969 configuration change and build cycle.
5970 </para>
5971
5972 <para>
5973 Each time you make configuration changes, you need to rebuild
5974 the kernel and check to see what impact your changes had on
5975 the overall size.
5976 </para>
5977 </section>
5978
5979 <section id='remove-package-management-requirements'>
5980 <title>Remove Package Management Requirements</title>
5981
5982 <para>
5983 Packaging requirements add size to the image.
5984 One way to reduce the size of the image is to remove all the
5985 packaging requirements from the image.
5986 This reduction includes both removing the package manager
5987 and its unique dependencies as well as removing the package
5988 management data itself.
5989 </para>
5990
5991 <para>
5992 To eliminate all the packaging requirements for an image,
5993 be sure that "package-management" is not part of your
5994 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5995 statement for the image.
5996 When you remove this feature, you are removing the package
5997 manager as well as its dependencies from the root filesystem.
5998 </para>
5999 </section>
6000
6001 <section id='look-for-other-ways-to-minimize-size'>
6002 <title>Look for Other Ways to Minimize Size</title>
6003
6004 <para>
6005 Depending on your particular circumstances, other areas that you
6006 can trim likely exist.
6007 The key to finding these areas is through tools and methods
6008 described here combined with experimentation and iteration.
6009 Here are a couple of areas to experiment with:
6010 <itemizedlist>
6011 <listitem><para><filename>glibc</filename>:
6012 In general, follow this process:
6013 <orderedlist>
6014 <listitem><para>Remove <filename>glibc</filename>
6015 features from
6016 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6017 that you think you do not need.</para></listitem>
6018 <listitem><para>Build your distribution.
6019 </para></listitem>
6020 <listitem><para>If the build fails due to missing
6021 symbols in a package, determine if you can
6022 reconfigure the package to not need those
6023 features.
6024 For example, change the configuration to not
6025 support wide character support as is done for
6026 <filename>ncurses</filename>.
6027 Or, if support for those characters is needed,
6028 determine what <filename>glibc</filename>
6029 features provide the support and restore the
6030 configuration.
6031 </para></listitem>
6032 <listitem><para>Rebuild and repeat the process.
6033 </para></listitem>
6034 </orderedlist></para></listitem>
6035 <listitem><para><filename>busybox</filename>:
6036 For BusyBox, use a process similar as described for
6037 <filename>glibc</filename>.
6038 A difference is you will need to boot the resulting
6039 system to see if you are able to do everything you
6040 expect from the running system.
6041 You need to be sure to integrate configuration fragments
6042 into Busybox because BusyBox handles its own core
6043 features and then allows you to add configuration
6044 fragments on top.
6045 </para></listitem>
6046 </itemizedlist>
6047 </para>
6048 </section>
6049
6050 <section id='iterate-on-the-process'>
6051 <title>Iterate on the Process</title>
6052
6053 <para>
6054 If you have not reached your goals on system size, you need
6055 to iterate on the process.
6056 The process is the same.
6057 Use the tools and see just what is taking up 90% of the root
6058 filesystem and the kernel.
6059 Decide what you can eliminate without limiting your device
6060 beyond what you need.
6061 </para>
6062
6063 <para>
6064 Depending on your system, a good place to look might be
6065 Busybox, which provides a stripped down
6066 version of Unix tools in a single, executable file.
6067 You might be able to drop virtual terminal services or perhaps
6068 ipv6.
6069 </para>
6070 </section>
6071 </section>
6072
6073 <section id='building-images-for-more-than-one-machine'>
6074 <title>Building Images for More than One Machine</title>
6075
6076 <para>
6077 A common scenario developers face is creating images for several
6078 different machines that use the same software environment.
6079 In this situation, it is tempting to set the
6080 tunings and optimization flags for each build specifically for
6081 the targeted hardware (i.e. "maxing out" the tunings).
6082 Doing so can considerably add to build times and package feed
6083 maintenance collectively for the machines.
6084 For example, selecting tunes that are extremely specific to a
6085 CPU core used in a system might enable some micro optimizations
6086 in GCC for that particular system but would otherwise not gain
6087 you much of a performance difference across the other systems
6088 as compared to using a more general tuning across all the builds
6089 (e.g. setting
6090 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6091 specifically for each machine's build).
6092 Rather than "max out" each build's tunings, you can take steps that
6093 cause the OpenEmbedded build system to reuse software across the
6094 various machines where it makes sense.
6095 </para>
6096
6097 <para>
6098 If build speed and package feed maintenance are considerations,
6099 you should consider the points in this section that can help you
6100 optimize your tunings to best consider build times and package
6101 feed maintenance.
6102 <itemizedlist>
6103 <listitem><para>
6104 <emphasis>Share the Build Directory:</emphasis>
6105 If at all possible, share the
6106 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6107 across builds.
6108 The Yocto Project supports switching between different
6109 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6110 values in the same <filename>TMPDIR</filename>.
6111 This practice is well supported and regularly used by
6112 developers when building for multiple machines.
6113 When you use the same <filename>TMPDIR</filename> for
6114 multiple machine builds, the OpenEmbedded build system can
6115 reuse the existing native and often cross-recipes for
6116 multiple machines.
6117 Thus, build time decreases.
6118 <note>
6119 If
6120 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6121 settings change or fundamental configuration settings
6122 such as the filesystem layout, you need to work with
6123 a clean <filename>TMPDIR</filename>.
6124 Sharing <filename>TMPDIR</filename> under these
6125 circumstances might work but since it is not
6126 guaranteed, you should use a clean
6127 <filename>TMPDIR</filename>.
6128 </note>
6129 </para></listitem>
6130 <listitem><para>
6131 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6132 By default, the OpenEmbedded build system enables three
6133 levels of package architectures: "all", "tune" or "package",
6134 and "machine".
6135 Any given recipe usually selects one of these package
6136 architectures (types) for its output.
6137 Depending for what a given recipe creates packages, making
6138 sure you enable the appropriate package architecture can
6139 directly impact the build time.</para>
6140
6141 <para>A recipe that just generates scripts can enable
6142 "all" architecture because there are no binaries to build.
6143 To specifically enable "all" architecture, be sure your
6144 recipe inherits the
6145 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6146 class.
6147 This class is useful for "all" architectures because it
6148 configures many variables so packages can be used across
6149 multiple architectures.</para>
6150
6151 <para>If your recipe needs to generate packages that are
6152 machine-specific or when one of the build or runtime
6153 dependencies is already machine-architecture dependent,
6154 which makes your recipe also machine-architecture dependent,
6155 make sure your recipe enables the "machine" package
6156 architecture through the
6157 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6158 variable:
6159 <literallayout class='monospaced'>
6160 PACKAGE_ARCH = "${MACHINE_ARCH}"
6161 </literallayout>
6162 When you do not specifically enable a package
6163 architecture through the
6164 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6165 The OpenEmbedded build system defaults to the
6166 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6167 setting:
6168 <literallayout class='monospaced'>
6169 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6170 </literallayout>
6171 </para></listitem>
6172 <listitem><para>
6173 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6174 Some tunes are more generic and can run on multiple targets
6175 (e.g. an <filename>armv5</filename> set of packages could
6176 run on <filename>armv6</filename> and
6177 <filename>armv7</filename> processors in most cases).
6178 Similarly, <filename>i486</filename> binaries could work
6179 on <filename>i586</filename> and higher processors.
6180 You should realize, however, that advances on newer
6181 processor versions would not be used.</para>
6182
6183 <para>If you select the same tune for several different
6184 machines, the OpenEmbedded build system reuses software
6185 previously built, thus speeding up the overall build time.
6186 Realize that even though a new sysroot for each machine is
6187 generated, the software is not recompiled and only one
6188 package feed exists.
6189 </para></listitem>
6190 <listitem><para>
6191 <emphasis>Manage Granular Level Packaging:</emphasis>
6192 Sometimes cases exist where injecting another level of
6193 package architecture beyond the three higher levels noted
6194 earlier can be useful.
6195 For example, consider how NXP (formerly Freescale) allows
6196 for the easy reuse of binary packages in their layer
6197 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6198 In this example, the
6199 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6200 class shares GPU packages for i.MX53 boards because
6201 all boards share the AMD GPU.
6202 The i.MX6-based boards can do the same because all boards
6203 share the Vivante GPU.
6204 This class inspects the BitBake datastore to identify if
6205 the package provides or depends on one of the
6206 sub-architecture values.
6207 If so, the class sets the
6208 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6209 value based on the <filename>MACHINE_SUBARCH</filename>
6210 value.
6211 If the package does not provide or depend on one of the
6212 sub-architecture values but it matches a value in the
6213 machine-specific filter, it sets
6214 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6215 This behavior reduces the number of packages built and
6216 saves build time by reusing binaries.
6217 </para></listitem>
6218 <listitem><para>
6219 <emphasis>Use Tools to Debug Issues:</emphasis>
6220 Sometimes you can run into situations where software is
6221 being rebuilt when you think it should not be.
6222 For example, the OpenEmbedded build system might not be
6223 using shared state between machines when you think it
6224 should be.
6225 These types of situations are usually due to references
6226 to machine-specific variables such as
6227 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6228 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6229 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6230 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6231 and so forth in code that is supposed to only be
6232 tune-specific or when the recipe depends
6233 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6234 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6235 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6236 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6237 and so forth) on some other recipe that already has
6238 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6239 defined as "${MACHINE_ARCH}".
6240 <note>
6241 Patches to fix any issues identified are most welcome
6242 as these issues occasionally do occur.
6243 </note></para>
6244
6245 <para>For such cases, you can use some tools to help you
6246 sort out the situation:
6247 <itemizedlist>
6248 <listitem><para>
6249 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6250 You can find this tool in the
6251 <filename>scripts</filename> directory of the
6252 Source Repositories.
6253 See the comments in the script for information on
6254 how to use the tool.
6255 </para></listitem>
6256 <listitem><para>
6257 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6258 Using this option causes BitBake to try to
6259 establish the closest signature match it can
6260 (e.g. in the shared state cache) and then run
6261 <filename>bitbake-diffsigs</filename> over the
6262 matches to determine the stamps and delta where
6263 these two stamp trees diverge.
6264 </para></listitem>
6265 </itemizedlist>
6266 </para></listitem>
6267 </itemizedlist>
6268 </para>
6269 </section>
6270
6271 <section id="building-software-from-an-external-source">
6272 <title>Building Software from an External Source</title>
6273
6274 <para>
6275 By default, the OpenEmbedded build system uses the
6276 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6277 when building source code.
6278 The build process involves fetching the source files, unpacking
6279 them, and then patching them if necessary before the build takes
6280 place.
6281 </para>
6282
6283 <para>
6284 Situations exist where you might want to build software from source
6285 files that are external to and thus outside of the
6286 OpenEmbedded build system.
6287 For example, suppose you have a project that includes a new BSP with
6288 a heavily customized kernel.
6289 And, you want to minimize exposing the build system to the
6290 development team so that they can focus on their project and
6291 maintain everyone's workflow as much as possible.
6292 In this case, you want a kernel source directory on the development
6293 machine where the development occurs.
6294 You want the recipe's
6295 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6296 variable to point to the external directory and use it as is, not
6297 copy it.
6298 </para>
6299
6300 <para>
6301 To build from software that comes from an external source, all you
6302 need to do is inherit the
6303 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6304 class and then set the
6305 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6306 variable to point to your external source code.
6307 Here are the statements to put in your
6308 <filename>local.conf</filename> file:
6309 <literallayout class='monospaced'>
6310 INHERIT += "externalsrc"
6311 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6312 </literallayout>
6313 </para>
6314
6315 <para>
6316 This next example shows how to accomplish the same thing by setting
6317 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6318 recipe's append file:
6319 <literallayout class='monospaced'>
6320 EXTERNALSRC = "<replaceable>path</replaceable>"
6321 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6322 </literallayout>
6323 <note>
6324 In order for these settings to take effect, you must globally
6325 or locally inherit the
6326 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6327 class.
6328 </note>
6329 </para>
6330
6331 <para>
6332 By default, <filename>externalsrc.bbclass</filename> builds
6333 the source code in a directory separate from the external source
6334 directory as specified by
6335 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6336 If you need to have the source built in the same directory in
6337 which it resides, or some other nominated directory, you can set
6338 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6339 to point to that directory:
6340 <literallayout class='monospaced'>
6341 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6342 </literallayout>
6343 </para>
6344 </section>
Brad Bishop19323692019-04-05 15:28:33 -04006345
6346 <section id="replicating-a-build-offline">
6347 <title>Replicating a Build Offline</title>
6348
6349 <para>
6350 It can be useful to take a "snapshot" of upstream sources
6351 used in a build and then use that "snapshot" later to
6352 replicate the build offline.
6353 To do so, you need to first prepare and populate your downloads
6354 directory your "snapshot" of files.
6355 Once your downloads directory is ready, you can use it at
6356 any time and from any machine to replicate your build.
6357 </para>
6358
6359 <para>
6360 Follow these steps to populate your Downloads directory:
6361 <orderedlist>
6362 <listitem><para>
6363 <emphasis>Create a Clean Downloads Directory:</emphasis>
6364 Start with an empty downloads directory
6365 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>).
6366 You start with an empty downloads directory by either
6367 removing the files in the existing directory or by
6368 setting
6369 <filename>DL_DIR</filename> to point to either an
6370 empty location or one that does not yet exist.
6371 </para></listitem>
6372 <listitem><para>
6373 <emphasis>Generate Tarballs of the Source Git Repositories:</emphasis>
6374 Edit your <filename>local.conf</filename> configuration
6375 file as follows:
6376 <literallayout class='monospaced'>
6377 DL_DIR = "/home/<replaceable>your-download-dir</replaceable>/"
6378 BB_GENERATE_MIRROR_TARBALLS = "1"
6379 </literallayout>
6380 During the fetch process in the next step, BitBake
6381 gathers the source files and creates tarballs in
6382 the directory pointed to by <filename>DL_DIR</filename>.
6383 See the
6384 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
6385 variable for more information.
6386 </para></listitem>
6387 <listitem><para>
6388 <emphasis>Populate Your Downloads Directory Without Building:</emphasis>
6389 Use BitBake to fetch your sources but inhibit the
6390 build:
6391 <literallayout class='monospaced'>
6392 $ bitbake <replaceable>target</replaceable> --runonly=fetch
6393 </literallayout>
6394 The downloads directory (i.e.
6395 <filename>${DL_DIR}</filename>) now has a "snapshot" of
6396 the source files in the form of tarballs, which can
6397 be used for the build.
6398 </para></listitem>
6399 <listitem><para>
6400 <emphasis>Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory:</emphasis>
6401 If you want, you can clean up your downloads directory
6402 by removing any Git or other Source Control Management
6403 (SCM) subdirectories such as
6404 <filename>${DL_DIR}/git2/*</filename>.
6405 The tarballs already contain these subdirectories.
6406 </para></listitem>
6407 </orderedlist>
6408 </para>
6409
6410 <para>
6411 Once your downloads directory has everything it needs regarding
6412 source files, you can create your "own-mirror" and build
6413 your target.
6414 Understand that you can use the files to build the target
6415 offline from any machine and at any time.
6416 </para>
6417
6418 <para>
6419 Follow these steps to build your target using the files in the
6420 downloads directory:
6421 <orderedlist>
6422 <listitem><para>
6423 <emphasis>Using Local Files Only:</emphasis>
6424 Inside your <filename>local.conf</filename> file, add
6425 the
6426 <ulink url='&YOCTO_DOCS_REF_URL;#var-SOURCE_MIRROR_URL'><filename>SOURCE_MIRROR_URL</filename></ulink>
6427 variable,
6428 inherit the <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-own-mirrors'><filename>own-mirrors</filename></ulink>
6429 class, and use the
6430 <ulink url='&YOCTO_DOCS_BB_URL;#var-bb-BB_NO_NETWORK'><filename>BB_NO_NETWORK</filename></ulink>
6431 variable to your <filename>local.conf</filename>.
6432 <literallayout class='monospaced'>
6433 SOURCE_MIRROR_URL ?= "file:///home/<replaceable>your-download-dir</replaceable>/"
6434 INHERIT += "own-mirrors"
6435 BB_NO_NETWORK = "1"
6436 </literallayout>
6437 The <filename>SOURCE_MIRROR_URL</filename> and
6438 <filename>own-mirror</filename> class set up the system
6439 to use the downloads directory as your "own mirror".
6440 Using the <filename>BB_NO_NETWORK</filename>
6441 variable makes sure that BitBake's fetching process
6442 in step 3 stays local, which means files from
6443 your "own-mirror" are used.
6444 </para></listitem>
6445 <listitem><para>
6446 <emphasis>Start With a Clean Build:</emphasis>
6447 You can start with a clean build by removing the
6448 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
6449 directory or using a new
6450 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
6451 </para></listitem>
6452 <listitem><para>
6453 <emphasis>Build Your Target:</emphasis>
6454 Use BitBake to build your target:
6455 <literallayout class='monospaced'>
6456 $ bitbake <replaceable>target</replaceable>
6457 </literallayout>
6458 The build completes using the known local "snapshot" of
6459 source files from your mirror.
6460 The resulting tarballs for your "snapshot" of source
6461 files are in the downloads directory.
6462 <note>
6463 <para>The offline build does not work if recipes
6464 attempt to find the latest version of software
6465 by setting
6466 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
6467 to
6468 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink><filename>}</filename>:
6469 <literallayout class='monospaced'>
6470 SRCREV = "${AUTOREV}"
6471 </literallayout>
6472 When a recipe sets
6473 <filename>SRCREV</filename> to
6474 <filename>${AUTOREV}</filename>, the build system
6475 accesses the network in an attempt to determine the
6476 latest version of software from the SCM.
6477 Typically, recipes that use
6478 <filename>AUTOREV</filename> are custom or
6479 modified recipes.
6480 Recipes that reside in public repositories
6481 usually do not use <filename>AUTOREV</filename>.
6482 </para>
6483
6484 <para>If you do have recipes that use
6485 <filename>AUTOREV</filename>, you can take steps to
6486 still use the recipes in an offline build.
6487 Do the following:
6488 <orderedlist>
6489 <listitem><para>
6490 Use a configuration generated by
6491 enabling
6492 <link linkend='maintaining-build-output-quality'>build history</link>.
6493 </para></listitem>
6494 <listitem><para>
6495 Use the
6496 <filename>buildhistory-collect-srcrevs</filename>
6497 command to collect the stored
6498 <filename>SRCREV</filename> values from
6499 the build's history.
6500 For more information on collecting these
6501 values, see the
6502 "<link linkend='build-history-package-information'>Build History Package Information</link>"
6503 section.
6504 </para></listitem>
6505 <listitem><para>
6506 Once you have the correct source
6507 revisions, you can modify those recipes
6508 to to set <filename>SRCREV</filename>
6509 to specific versions of the software.
6510 </para></listitem>
6511 </orderedlist>
6512 </para>
6513 </note>
6514 </para></listitem>
6515 </orderedlist>
6516 </para>
6517 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006518 </section>
6519
Brad Bishop316dfdd2018-06-25 12:45:53 -04006520 <section id='speeding-up-a-build'>
6521 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006522
6523 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006524 Build time can be an issue.
6525 By default, the build system uses simple controls to try and maximize
6526 build efficiency.
6527 In general, the default settings for all the following variables
6528 result in the most efficient build times when dealing with single
6529 socket systems (i.e. a single CPU).
6530 If you have multiple CPUs, you might try increasing the default
6531 values to gain more speed.
6532 See the descriptions in the glossary for each variable for more
6533 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006534 <itemizedlist>
6535 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006536 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6537 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006538 </para></listitem>
6539 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006540 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6541 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006542 </para></listitem>
6543 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006544 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6545 Extra options passed to the <filename>make</filename> command
6546 during the
6547 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6548 task in order to specify parallel compilation on the
6549 local build host.
6550 </para></listitem>
6551 <listitem><para>
6552 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6553 Extra options passed to the <filename>make</filename> command
6554 during the
6555 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6556 task in order to specify parallel installation on the
6557 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006558 </para></listitem>
6559 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006560 As mentioned, these variables all scale to the number of processor
6561 cores available on the build system.
6562 For single socket systems, this auto-scaling ensures that the build
6563 system fundamentally takes advantage of potential parallel operations
6564 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006565 </para>
6566
6567 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006568 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006569 <itemizedlist>
6570 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006571 File system type:
6572 The file system type that the build is being performed on can
6573 also influence performance.
6574 Using <filename>ext4</filename> is recommended as compared
6575 to <filename>ext2</filename> and <filename>ext3</filename>
6576 due to <filename>ext4</filename> improved features
6577 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006578 </para></listitem>
6579 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006580 Disabling the updating of access time using
6581 <filename>noatime</filename>:
6582 The <filename>noatime</filename> mount option prevents the
6583 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006584 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006585 <listitem><para>
6586 Setting a longer commit:
6587 Using the "commit=" mount option increases the interval
6588 in seconds between disk cache writes.
6589 Changing this interval from the five second default to
6590 something longer increases the risk of data loss but decreases
6591 the need to write to the disk, thus increasing the build
6592 performance.
6593 </para></listitem>
6594 <listitem><para>
6595 Choosing the packaging backend:
6596 Of the available packaging backends, IPK is the fastest.
6597 Additionally, selecting a singular packaging backend also
6598 helps.
6599 </para></listitem>
6600 <listitem><para>
6601 Using <filename>tmpfs</filename> for
6602 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6603 as a temporary file system:
6604 While this can help speed up the build, the benefits are
6605 limited due to the compiler using
6606 <filename>-pipe</filename>.
6607 The build system goes to some lengths to avoid
6608 <filename>sync()</filename> calls into the
6609 file system on the principle that if there was a significant
6610 failure, the
6611 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6612 contents could easily be rebuilt.
6613 </para></listitem>
6614 <listitem><para>
6615 Inheriting the
6616 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6617 class:
6618 Inheriting this class has shown to speed up builds due to
6619 significantly lower amounts of data stored in the data
6620 cache as well as on disk.
6621 Inheriting this class also makes cleanup of
6622 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6623 faster, at the expense of being easily able to dive into the
6624 source code.
6625 File system maintainers have recommended that the fastest way
6626 to clean up large numbers of files is to reformat partitions
6627 rather than delete files due to the linear nature of
6628 partitions.
6629 This, of course, assumes you structure the disk partitions and
6630 file systems in a way that this is practical.
6631 </para></listitem>
6632 </itemizedlist>
6633 Aside from the previous list, you should keep some trade offs in
6634 mind that can help you speed up the build:
6635 <itemizedlist>
6636 <listitem><para>
6637 Remove items from
6638 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6639 that you might not need.
6640 </para></listitem>
6641 <listitem><para>
6642 Exclude debug symbols and other debug information:
6643 If you do not need these symbols and other debug information,
6644 disabling the <filename>*-dbg</filename> package generation
6645 can speed up the build.
6646 You can disable this generation by setting the
6647 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6648 variable to "1".
6649 </para></listitem>
6650 <listitem><para>
6651 Disable static library generation for recipes derived from
6652 <filename>autoconf</filename> or <filename>libtool</filename>:
6653 Following is an example showing how to disable static
6654 libraries and still provide an override to handle exceptions:
6655 <literallayout class='monospaced'>
6656 STATICLIBCONF = "--disable-static"
6657 STATICLIBCONF_sqlite3-native = ""
6658 EXTRA_OECONF += "${STATICLIBCONF}"
6659 </literallayout>
6660 <note><title>Notes</title>
6661 <itemizedlist>
6662 <listitem><para>
6663 Some recipes need static libraries in order to work
6664 correctly (e.g. <filename>pseudo-native</filename>
6665 needs <filename>sqlite3-native</filename>).
6666 Overrides, as in the previous example, account for
6667 these kinds of exceptions.
6668 </para></listitem>
6669 <listitem><para>
6670 Some packages have packaging code that assumes the
6671 presence of the static libraries.
6672 If so, you might need to exclude them as well.
6673 </para></listitem>
6674 </itemizedlist>
6675 </note>
6676 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006677 </itemizedlist>
6678 </para>
6679 </section>
6680
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006681 <section id="platdev-working-with-libraries">
6682 <title>Working With Libraries</title>
6683
6684 <para>
6685 Libraries are an integral part of your system.
6686 This section describes some common practices you might find
6687 helpful when working with libraries to build your system:
6688 <itemizedlist>
6689 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6690 </para></listitem>
6691 <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>
6692 </para></listitem>
6693 <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>
6694 </para></listitem>
6695 </itemizedlist>
6696 </para>
6697
6698 <section id='including-static-library-files'>
6699 <title>Including Static Library Files</title>
6700
6701 <para>
6702 If you are building a library and the library offers static linking, you can control
6703 which static library files (<filename>*.a</filename> files) get included in the
6704 built library.
6705 </para>
6706
6707 <para>
6708 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6709 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6710 variables in the
6711 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6712 by the <filename>do_install</filename> task are packaged.
6713 By default, the <filename>PACKAGES</filename> variable includes
6714 <filename>${PN}-staticdev</filename>, which represents all static library files.
6715 <note>
6716 Some previously released versions of the Yocto Project
6717 defined the static library files through
6718 <filename>${PN}-dev</filename>.
6719 </note>
6720 Following is part of the BitBake configuration file, where
6721 you can see how the static library files are defined:
6722 <literallayout class='monospaced'>
6723 PACKAGE_BEFORE_PN ?= ""
6724 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6725 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6726 FILES = ""
6727
6728 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6729 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6730 ${base_bindir}/* ${base_sbindir}/* \
6731 ${base_libdir}/*${SOLIBS} \
6732 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6733 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6734 ${datadir}/pixmaps ${datadir}/applications \
6735 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6736 ${libdir}/bonobo/servers"
6737
6738 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6739
6740 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6741 ${datadir}/gnome/help"
6742 SECTION_${PN}-doc = "doc"
6743
6744 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6745 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6746 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6747 ${datadir}/aclocal ${base_libdir}/*.o \
6748 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6749 SECTION_${PN}-dev = "devel"
6750 ALLOW_EMPTY_${PN}-dev = "1"
6751 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6752
6753 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6754 SECTION_${PN}-staticdev = "devel"
6755 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6756 </literallayout>
6757 </para>
6758 </section>
6759
6760 <section id="combining-multiple-versions-library-files-into-one-image">
6761 <title>Combining Multiple Versions of Library Files into One Image</title>
6762
6763 <para>
6764 The build system offers the ability to build libraries with different
6765 target optimizations or architecture formats and combine these together
6766 into one system image.
6767 You can link different binaries in the image
6768 against the different libraries as needed for specific use cases.
6769 This feature is called "Multilib."
6770 </para>
6771
6772 <para>
6773 An example would be where you have most of a system compiled in 32-bit
6774 mode using 32-bit libraries, but you have something large, like a database
6775 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6776 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6777 </para>
6778
6779 <para>
6780 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6781 the approach the build system uses facilitates different target optimizations.
6782 You could compile some binaries to use one set of libraries and other binaries
6783 to use a different set of libraries.
6784 The libraries could differ in architecture, compiler options, or other
6785 optimizations.
6786 </para>
6787
6788 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006789 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006790 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006791 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006792 <itemizedlist>
6793 <listitem><para><filename>conf/multilib-example.conf</filename>
6794 configuration file</para></listitem>
6795 <listitem><para><filename>conf/multilib-example2.conf</filename>
6796 configuration file</para></listitem>
6797 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6798 recipe</para></listitem>
6799 </itemizedlist>
6800 </para>
6801
6802 <section id='preparing-to-use-multilib'>
6803 <title>Preparing to Use Multilib</title>
6804
6805 <para>
6806 User-specific requirements drive the Multilib feature.
6807 Consequently, there is no one "out-of-the-box" configuration that likely
6808 exists to meet your needs.
6809 </para>
6810
6811 <para>
6812 In order to enable Multilib, you first need to ensure your recipe is
6813 extended to support multiple libraries.
6814 Many standard recipes are already extended and support multiple libraries.
6815 You can check in the <filename>meta/conf/multilib.conf</filename>
6816 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006817 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006818 done using the
6819 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6820 variable.
6821 Eventually, all recipes will be covered and this list will
6822 not be needed.
6823 </para>
6824
6825 <para>
6826 For the most part, the Multilib class extension works automatically to
6827 extend the package name from <filename>${PN}</filename> to
6828 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6829 is the particular multilib (e.g. "lib32-" or "lib64-").
6830 Standard variables such as
6831 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6832 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6833 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6834 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6835 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6836 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6837 are automatically extended by the system.
6838 If you are extending any manual code in the recipe, you can use the
6839 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6840 correctly.
6841 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6842 </para>
6843 </section>
6844
6845 <section id='using-multilib'>
6846 <title>Using Multilib</title>
6847
6848 <para>
6849 After you have set up the recipes, you need to define the actual
6850 combination of multiple libraries you want to build.
6851 You accomplish this through your <filename>local.conf</filename>
6852 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006853 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006854 An example configuration would be as follows:
6855 <literallayout class='monospaced'>
6856 MACHINE = "qemux86-64"
6857 require conf/multilib.conf
6858 MULTILIBS = "multilib:lib32"
6859 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006860 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006861 </literallayout>
6862 This example enables an
6863 additional library named <filename>lib32</filename> alongside the
6864 normal target packages.
6865 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6866 For information on this particular tuning, see
6867 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6868 </para>
6869
6870 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006871 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006872 in all the images, which illustrates one method of including a
6873 multiple library dependency.
6874 You can use a normal image build to include this dependency,
6875 for example:
6876 <literallayout class='monospaced'>
6877 $ bitbake core-image-sato
6878 </literallayout>
6879 You can also build Multilib packages specifically with a command like this:
6880 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006881 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006882 </literallayout>
6883 </para>
6884 </section>
6885
6886 <section id='additional-implementation-details'>
6887 <title>Additional Implementation Details</title>
6888
6889 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006890 Generic implementation details as well as details that are
6891 specific to package management systems exist.
6892 Following are implementation details that exist regardless
6893 of the package management system:
6894 <itemizedlist>
6895 <listitem><para>The typical convention used for the
6896 class extension code as used by
6897 Multilib assumes that all package names specified
6898 in
6899 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6900 that contain <filename>${PN}</filename> have
6901 <filename>${PN}</filename> at the start of the name.
6902 When that convention is not followed and
6903 <filename>${PN}</filename> appears at
6904 the middle or the end of a name, problems occur.
6905 </para></listitem>
6906 <listitem><para>The
6907 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6908 value under Multilib will be extended to
6909 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6910 (e.g. "-pokymllib32" for a "lib32" Multilib with
6911 Poky).
6912 The reason for this slightly unwieldy contraction
6913 is that any "-" characters in the vendor
6914 string presently break Autoconf's
6915 <filename>config.sub</filename>, and
6916 other separators are problematic for different
6917 reasons.
6918 </para></listitem>
6919 </itemizedlist>
6920 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006921
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006922 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006923 For the RPM Package Management System, the following implementation details
6924 exist:
6925 <itemizedlist>
6926 <listitem><para>A unique architecture is defined for the Multilib packages,
6927 along with creating a unique deploy folder under
6928 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006929 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006930 For example, consider <filename>lib32</filename> in a
6931 <filename>qemux86-64</filename> image.
6932 The possible architectures in the system are "all", "qemux86_64",
6933 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6934 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6935 <filename>${PN}</filename> during RPM packaging.
6936 The naming for a normal RPM package and a Multilib RPM package in a
6937 <filename>qemux86-64</filename> system resolves to something similar to
6938 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6939 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6940 </para></listitem>
6941 <listitem><para>When installing a Multilib image, the RPM backend first
6942 installs the base image and then installs the Multilib libraries.
6943 </para></listitem>
6944 <listitem><para>The build system relies on RPM to resolve the identical files in the
6945 two (or more) Multilib packages.</para></listitem>
6946 </itemizedlist>
6947 </para>
6948
6949 <para>
6950 For the IPK Package Management System, the following implementation details exist:
6951 <itemizedlist>
6952 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6953 <filename>${PN}</filename> during IPK packaging.
6954 The naming for a normal RPM package and a Multilib IPK package in a
6955 <filename>qemux86-64</filename> system resolves to something like
6956 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6957 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6958 </para></listitem>
6959 <listitem><para>The IPK deploy folder is not modified with
6960 <filename>${MLPREFIX}</filename> because packages with and without
6961 the Multilib feature can exist in the same folder due to the
6962 <filename>${PN}</filename> differences.</para></listitem>
6963 <listitem><para>IPK defines a sanity check for Multilib installation
6964 using certain rules for file comparison, overridden, etc.
6965 </para></listitem>
6966 </itemizedlist>
6967 </para>
6968 </section>
6969 </section>
6970
6971 <section id='installing-multiple-versions-of-the-same-library'>
6972 <title>Installing Multiple Versions of the Same Library</title>
6973
6974 <para>
6975 Situations can exist where you need to install and use
6976 multiple versions of the same library on the same system
6977 at the same time.
6978 These situations almost always exist when a library API
6979 changes and you have multiple pieces of software that
6980 depend on the separate versions of the library.
6981 To accommodate these situations, you can install multiple
6982 versions of the same library in parallel on the same system.
6983 </para>
6984
6985 <para>
6986 The process is straightforward as long as the libraries use
6987 proper versioning.
6988 With properly versioned libraries, all you need to do to
6989 individually specify the libraries is create separate,
6990 appropriately named recipes where the
6991 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6992 name includes a portion that differentiates each library version
6993 (e.g.the major part of the version number).
6994 Thus, instead of having a single recipe that loads one version
6995 of a library (e.g. <filename>clutter</filename>), you provide
6996 multiple recipes that result in different versions
6997 of the libraries you want.
6998 As an example, the following two recipes would allow the
6999 two separate versions of the <filename>clutter</filename>
7000 library to co-exist on the same system:
7001 <literallayout class='monospaced'>
7002 clutter-1.6_1.6.20.bb
7003 clutter-1.8_1.8.4.bb
7004 </literallayout>
7005 Additionally, if you have other recipes that depend on a given
7006 library, you need to use the
7007 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
7008 variable to create the dependency.
7009 Continuing with the same example, if you want to have a recipe
7010 depend on the 1.8 version of the <filename>clutter</filename>
7011 library, use the following in your recipe:
7012 <literallayout class='monospaced'>
7013 DEPENDS = "clutter-1.8"
7014 </literallayout>
7015 </para>
7016 </section>
7017 </section>
7018
Brad Bishop316dfdd2018-06-25 12:45:53 -04007019 <section id='using-x32-psabi'>
7020 <title>Using x32 psABI</title>
7021
7022 <para>
7023 x32 processor-specific Application Binary Interface
7024 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
7025 is a native 32-bit processor-specific ABI for
7026 <trademark class='registered'>Intel</trademark> 64 (x86-64)
7027 architectures.
7028 An ABI defines the calling conventions between functions in a
7029 processing environment.
7030 The interface determines what registers are used and what the
7031 sizes are for various C data types.
7032 </para>
7033
7034 <para>
7035 Some processing environments prefer using 32-bit applications even
7036 when running on Intel 64-bit platforms.
7037 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
7038 64-bit platforms.
7039 The i386 psABI does not provide efficient use and access of the
7040 Intel 64-bit processor resources, leaving the system underutilized.
7041 Now consider the x86_64 psABI.
7042 This ABI is newer and uses 64-bits for data sizes and program
7043 pointers.
7044 The extra bits increase the footprint size of the programs,
7045 libraries, and also increases the memory and file system size
7046 requirements.
7047 Executing under the x32 psABI enables user programs to utilize CPU
7048 and system resources more efficiently while keeping the memory
7049 footprint of the applications low.
7050 Extra bits are used for registers but not for addressing mechanisms.
7051 </para>
7052
7053 <para>
7054 The Yocto Project supports the final specifications of x32 psABI
7055 as follows:
7056 <itemizedlist>
7057 <listitem><para>
7058 You can create packages and images in x32 psABI format on
7059 x86_64 architecture targets.
7060 </para></listitem>
7061 <listitem><para>
7062 You can successfully build recipes with the x32 toolchain.
7063 </para></listitem>
7064 <listitem><para>
7065 You can create and boot
7066 <filename>core-image-minimal</filename> and
7067 <filename>core-image-sato</filename> images.
7068 </para></listitem>
7069 <listitem><para>
7070 RPM Package Manager (RPM) support exists for x32 binaries.
7071 </para></listitem>
7072 <listitem><para>
7073 Support for large images exists.
7074 </para></listitem>
7075 </itemizedlist>
7076 </para>
7077
7078 <para>
7079 To use the x32 psABI, you need to edit your
7080 <filename>conf/local.conf</filename> configuration file as
7081 follows:
7082 <literallayout class='monospaced'>
7083 MACHINE = "qemux86-64"
7084 DEFAULTTUNE = "x86-64-x32"
Brad Bishop19323692019-04-05 15:28:33 -04007085 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
7086 or 'INVALID')) or 'lib'}"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007087 </literallayout>
7088 Once you have set up your configuration file, use BitBake to
7089 build an image that supports the x32 psABI.
7090 Here is an example:
7091 <literallayout class='monospaced'>
7092 $ bitbake core-image-sato
7093 </literallayout>
7094 </para>
7095 </section>
7096
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007097 <section id='enabling-gobject-introspection-support'>
7098 <title>Enabling GObject Introspection Support</title>
7099
7100 <para>
7101 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
7102 is the standard mechanism for accessing GObject-based software
7103 from runtime environments.
7104 GObject is a feature of the GLib library that provides an object
7105 framework for the GNOME desktop and related software.
7106 GObject Introspection adds information to GObject that allows
7107 objects created within it to be represented across different
7108 programming languages.
7109 If you want to construct GStreamer pipelines using Python, or
7110 control UPnP infrastructure using Javascript and GUPnP,
7111 GObject introspection is the only way to do it.
7112 </para>
7113
7114 <para>
7115 This section describes the Yocto Project support for generating
7116 and packaging GObject introspection data.
7117 GObject introspection data is a description of the
7118 API provided by libraries built on top of GLib framework,
7119 and, in particular, that framework's GObject mechanism.
7120 GObject Introspection Repository (GIR) files go to
7121 <filename>-dev</filename> packages,
7122 <filename>typelib</filename> files go to main packages as they
7123 are packaged together with libraries that are introspected.
7124 </para>
7125
7126 <para>
7127 The data is generated when building such a library, by linking
7128 the library with a small executable binary that asks the library
7129 to describe itself, and then executing the binary and
7130 processing its output.
7131 </para>
7132
7133 <para>
7134 Generating this data in a cross-compilation environment
7135 is difficult because the library is produced for the target
7136 architecture, but its code needs to be executed on the build host.
7137 This problem is solved with the OpenEmbedded build system by
7138 running the code through QEMU, which allows precisely that.
7139 Unfortunately, QEMU does not always work perfectly as mentioned
Brad Bishop96ff1982019-08-19 13:50:42 -04007140 in the
7141 "<link linkend='known-issues'>Known Issues</link>" section.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007142 </para>
7143
7144 <section id='enabling-the-generation-of-introspection-data'>
7145 <title>Enabling the Generation of Introspection Data</title>
7146
7147 <para>
7148 Enabling the generation of introspection data (GIR files)
7149 in your library package involves the following:
7150 <orderedlist>
7151 <listitem><para>
7152 Inherit the
7153 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
7154 class.
7155 </para></listitem>
7156 <listitem><para>
7157 Make sure introspection is not disabled anywhere in
7158 the recipe or from anything the recipe includes.
7159 Also, make sure that "gobject-introspection-data" is
7160 not in
7161 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7162 and that "qemu-usermode" is not in
7163 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7164 If either of these conditions exist, nothing will
7165 happen.
7166 </para></listitem>
7167 <listitem><para>
7168 Try to build the recipe.
7169 If you encounter build errors that look like
7170 something is unable to find
7171 <filename>.so</filename> libraries, check where these
7172 libraries are located in the source tree and add
7173 the following to the recipe:
7174 <literallayout class='monospaced'>
7175 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
7176 </literallayout>
7177 <note>
7178 See recipes in the <filename>oe-core</filename>
7179 repository that use that
7180 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
7181 as an example.
7182 </note>
7183 </para></listitem>
7184 <listitem><para>
7185 Look for any other errors, which probably mean that
7186 introspection support in a package is not entirely
7187 standard, and thus breaks down in a cross-compilation
7188 environment.
7189 For such cases, custom-made fixes are needed.
7190 A good place to ask and receive help in these cases
7191 is the
7192 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7193 </para></listitem>
7194 </orderedlist>
7195 <note>
7196 Using a library that no longer builds against the latest
7197 Yocto Project release and prints introspection related
7198 errors is a good candidate for the previous procedure.
7199 </note>
7200 </para>
7201 </section>
7202
7203 <section id='disabling-the-generation-of-introspection-data'>
7204 <title>Disabling the Generation of Introspection Data</title>
7205
7206 <para>
7207 You might find that you do not want to generate
7208 introspection data.
7209 Or, perhaps QEMU does not work on your build host and
7210 target architecture combination.
7211 If so, you can use either of the following methods to
7212 disable GIR file generations:
7213 <itemizedlist>
7214 <listitem><para>
7215 Add the following to your distro configuration:
7216 <literallayout class='monospaced'>
7217 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7218 </literallayout>
7219 Adding this statement disables generating
7220 introspection data using QEMU but will still enable
7221 building introspection tools and libraries
7222 (i.e. building them does not require the use of QEMU).
7223 </para></listitem>
7224 <listitem><para>
7225 Add the following to your machine configuration:
7226 <literallayout class='monospaced'>
7227 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7228 </literallayout>
7229 Adding this statement disables the use of QEMU
7230 when building packages for your machine.
7231 Currently, this feature is used only by introspection
7232 recipes and has the same effect as the previously
7233 described option.
7234 <note>
7235 Future releases of the Yocto Project might have
7236 other features affected by this option.
7237 </note>
7238 </para></listitem>
7239 </itemizedlist>
7240 If you disable introspection data, you can still
7241 obtain it through other means such as copying the data
7242 from a suitable sysroot, or by generating it on the
7243 target hardware.
7244 The OpenEmbedded build system does not currently
7245 provide specific support for these techniques.
7246 </para>
7247 </section>
7248
7249 <section id='testing-that-introspection-works-in-an-image'>
7250 <title>Testing that Introspection Works in an Image</title>
7251
7252 <para>
7253 Use the following procedure to test if generating
7254 introspection data is working in an image:
7255 <orderedlist>
7256 <listitem><para>
7257 Make sure that "gobject-introspection-data" is not in
7258 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7259 and that "qemu-usermode" is not in
7260 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7261 </para></listitem>
7262 <listitem><para>
7263 Build <filename>core-image-sato</filename>.
7264 </para></listitem>
7265 <listitem><para>
7266 Launch a Terminal and then start Python in the
7267 terminal.
7268 </para></listitem>
7269 <listitem><para>
7270 Enter the following in the terminal:
7271 <literallayout class='monospaced'>
7272 >>> from gi.repository import GLib
7273 >>> GLib.get_host_name()
7274 </literallayout>
7275 </para></listitem>
7276 <listitem><para>
7277 For something a little more advanced, enter the
7278 following:
7279 <literallayout class='monospaced'>
7280 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7281 </literallayout>
7282 </para></listitem>
7283 </orderedlist>
7284 </para>
7285 </section>
7286
7287 <section id='known-issues'>
7288 <title>Known Issues</title>
7289
7290 <para>
7291 The following know issues exist for
7292 GObject Introspection Support:
7293 <itemizedlist>
7294 <listitem><para>
7295 <filename>qemu-ppc64</filename> immediately crashes.
7296 Consequently, you cannot build introspection data on
7297 that architecture.
7298 </para></listitem>
7299 <listitem><para>
7300 x32 is not supported by QEMU.
7301 Consequently, introspection data is disabled.
7302 </para></listitem>
7303 <listitem><para>
7304 musl causes transient GLib binaries to crash on
7305 assertion failures.
7306 Consequently, generating introspection data is
7307 disabled.
7308 </para></listitem>
7309 <listitem><para>
7310 Because QEMU is not able to run the binaries correctly,
7311 introspection is disabled for some specific packages
7312 under specific architectures (e.g.
7313 <filename>gcr</filename>,
7314 <filename>libsecret</filename>, and
7315 <filename>webkit</filename>).
7316 </para></listitem>
7317 <listitem><para>
7318 QEMU usermode might not work properly when running
7319 64-bit binaries under 32-bit host machines.
7320 In particular, "qemumips64" is known to not work under
7321 i686.
7322 </para></listitem>
7323 </itemizedlist>
7324 </para>
7325 </section>
7326 </section>
7327
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007328 <section id='dev-optionally-using-an-external-toolchain'>
7329 <title>Optionally Using an External Toolchain</title>
7330
7331 <para>
7332 You might want to use an external toolchain as part of your
7333 development.
7334 If this is the case, the fundamental steps you need to accomplish
7335 are as follows:
7336 <itemizedlist>
7337 <listitem><para>
7338 Understand where the installed toolchain resides.
7339 For cases where you need to build the external toolchain,
7340 you would need to take separate steps to build and install
7341 the toolchain.
7342 </para></listitem>
7343 <listitem><para>
7344 Make sure you add the layer that contains the toolchain to
7345 your <filename>bblayers.conf</filename> file through the
7346 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7347 variable.
7348 </para></listitem>
7349 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007350 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007351 variable in your <filename>local.conf</filename> file
7352 to the location in which you installed the toolchain.
7353 </para></listitem>
7354 </itemizedlist>
7355 A good example of an external toolchain used with the Yocto Project
7356 is <trademark class='registered'>Mentor Graphics</trademark>
7357 Sourcery G++ Toolchain.
7358 You can see information on how to use that particular layer in the
7359 <filename>README</filename> file at
7360 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7361 You can find further information by reading about the
7362 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7363 variable in the Yocto Project Reference Manual's variable glossary.
7364 </para>
7365 </section>
7366
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007367 <section id='creating-partitioned-images-using-wic'>
7368 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007369
7370 <para>
7371 Creating an image for a particular hardware target using the
7372 OpenEmbedded build system does not necessarily mean you can boot
7373 that image as is on your device.
7374 Physical devices accept and boot images in various ways depending
7375 on the specifics of the device.
7376 Usually, information about the hardware can tell you what image
7377 format the device requires.
7378 Should your device require multiple partitions on an SD card, flash,
7379 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007380 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007381 </para>
7382
7383 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007384 The <filename>wic</filename> command generates partitioned
7385 images from existing OpenEmbedded build artifacts.
7386 Image generation is driven by partitioning commands
7387 contained in an Openembedded kickstart file
7388 (<filename>.wks</filename>) specified either directly on
7389 the command line or as one of a selection of canned
7390 kickstart files as shown with the
7391 <filename>wic list images</filename> command in the
7392 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7393 section.
7394 When you apply the command to a given set of build
7395 artifacts, the result is an image or set of images that
7396 can be directly written onto media and used on a particular
7397 system.
7398 <note>
7399 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007400 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007401 Chapter in the Yocto Project Reference Manual.
7402 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007403 </para>
7404
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007405 <para>
7406 The <filename>wic</filename> command and the infrastructure
7407 it is based on is by definition incomplete.
7408 The purpose of the command is to allow the generation of
7409 customized images, and as such, was designed to be
Brad Bishopc342db32019-05-15 21:57:59 -04007410 completely extensible through a plugin interface.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007411 See the
Brad Bishopc342db32019-05-15 21:57:59 -04007412 "<link linkend='wic-using-the-wic-plugin-interface'>Using the Wic PlugIn Interface</link>"
7413 section for information on these plugins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007414 </para>
7415
7416 <para>
7417 This section provides some background information on Wic,
7418 describes what you need to have in
7419 place to run the tool, provides instruction on how to use
Brad Bishopc342db32019-05-15 21:57:59 -04007420 the Wic utility, provides information on using the Wic plugins
Brad Bishop316dfdd2018-06-25 12:45:53 -04007421 interface, and provides several examples that show how to use
7422 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007423 </para>
7424
7425 <section id='wic-background'>
7426 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007427
7428 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007429 This section provides some background on the Wic utility.
7430 While none of this information is required to use
7431 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007432 <itemizedlist>
7433 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007434 The name "Wic" is derived from OpenEmbedded
7435 Image Creator (oeic).
7436 The "oe" diphthong in "oeic" was promoted to the
7437 letter "w", because "oeic" is both difficult to
7438 remember and to pronounce.
7439 </para></listitem>
7440 <listitem><para>
7441 Wic is loosely based on the
7442 Meego Image Creator (<filename>mic</filename>)
7443 framework.
7444 The Wic implementation has been
7445 heavily modified to make direct use of OpenEmbedded
7446 build artifacts instead of package installation and
7447 configuration, which are already incorporated within
7448 the OpenEmbedded artifacts.
7449 </para></listitem>
7450 <listitem><para>
7451 Wic is a completely independent
7452 standalone utility that initially provides
7453 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007454 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007455 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007456 class.
7457 The difference between Wic and those examples is
7458 that with Wic the functionality of those scripts is
7459 implemented by a general-purpose partitioning language,
7460 which is based on Redhat kickstart syntax.
7461 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007462 </itemizedlist>
7463 </para>
7464 </section>
7465
7466 <section id='wic-requirements'>
7467 <title>Requirements</title>
7468
7469 <para>
7470 In order to use the Wic utility with the OpenEmbedded Build
7471 system, your system needs to meet the following
7472 requirements:
7473 <itemizedlist>
7474 <listitem><para>
7475 The Linux distribution on your development host must
7476 support the Yocto Project.
7477 See the
7478 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7479 section in the Yocto Project Reference Manual for
7480 the list of distributions that support the
7481 Yocto Project.
7482 </para></listitem>
7483 <listitem><para>
7484 The standard system utilities, such as
7485 <filename>cp</filename>, must be installed on your
7486 development host system.
7487 </para></listitem>
7488 <listitem><para>
7489 You must have sourced the build environment
7490 setup script (i.e.
7491 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7492 found in the
7493 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7494 </para></listitem>
7495 <listitem><para>
7496 You need to have the build artifacts already
7497 available, which typically means that you must
7498 have already created an image using the
7499 Openembedded build system (e.g.
7500 <filename>core-image-minimal</filename>).
7501 While it might seem redundant to generate an image
7502 in order to create an image using
7503 Wic, the current version of
7504 Wic requires the artifacts
7505 in the form generated by the OpenEmbedded build
7506 system.
7507 </para></listitem>
7508 <listitem><para>
7509 You must build several native tools, which are
7510 built to run on the build system:
7511 <literallayout class='monospaced'>
7512 $ bitbake parted-native dosfstools-native mtools-native
7513 </literallayout>
7514 </para></listitem>
7515 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007516 Include "wic" as part of the
7517 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7518 variable.
7519 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007520 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007521 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007522 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007523 as part of the
7524 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7525 variable
7526 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007527 </itemizedlist>
7528 </para>
7529 </section>
7530
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007531 <section id='wic-getting-help'>
7532 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007533
7534 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007535 You can get general help for the <filename>wic</filename>
7536 command by entering the <filename>wic</filename> command
7537 by itself or by entering the command with a help argument
7538 as follows:
7539 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007540 $ wic -h
7541 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007542 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007543 </literallayout>
7544 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007545
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007546 <para>
7547 Currently, Wic supports seven commands:
7548 <filename>cp</filename>, <filename>create</filename>,
7549 <filename>help</filename>, <filename>list</filename>,
7550 <filename>ls</filename>, <filename>rm</filename>, and
7551 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007552 You can get help for all these commands except "help" by
7553 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007554 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007555 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007556 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007557 For example, the following command returns help for the
7558 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007559 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007560 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007561 </literallayout>
7562 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007563
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007564 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007565 Wic supports help for three topics:
7566 <filename>overview</filename>,
7567 <filename>plugins</filename>, and
7568 <filename>kickstart</filename>.
7569 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007570 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007571 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007572 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007573 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007574 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007575 $ wic help overview
7576 </literallayout>
7577 </para>
7578
7579 <para>
7580 One additional level of help exists for Wic.
7581 You can get help on individual images through the
7582 <filename>list</filename> command.
7583 You can use the <filename>list</filename> command to return the
7584 available Wic images as follows:
7585 <literallayout class='monospaced'>
7586 $ wic list images
7587 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7588 genericx86 Create an EFI disk image for genericx86*
7589 beaglebone-yocto Create SD card image for Beaglebone
7590 edgerouter Create SD card image for Edgerouter
7591 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7592 directdisk-gpt Create a 'pcbios' direct disk image
7593 mkefidisk Create an EFI disk image
7594 directdisk Create a 'pcbios' direct disk image
7595 systemd-bootdisk Create an EFI disk image with systemd-boot
7596 mkhybridiso Create a hybrid ISO image
7597 sdimage-bootpart Create SD card image with a boot partition
7598 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7599 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7600 </literallayout>
7601 Once you know the list of available Wic images, you can use
7602 <filename>help</filename> with the command to get help on a
7603 particular image.
7604 For example, the following command returns help on the
7605 "beaglebone-yocto" image:
7606 <literallayout class='monospaced'>
7607 $ wic list beaglebone-yocto help
7608
7609
7610 Creates a partitioned SD card image for Beaglebone.
7611 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007612 </literallayout>
7613 </para>
7614 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007615
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007616 <section id='operational-modes'>
7617 <title>Operational Modes</title>
7618
7619 <para>
7620 You can use Wic in two different
7621 modes, depending on how much control you need for
7622 specifying the Openembedded build artifacts that are
7623 used for creating the image: Raw and Cooked:
7624 <itemizedlist>
7625 <listitem><para>
7626 <emphasis>Raw Mode:</emphasis>
7627 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007628 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007629 </para></listitem>
7630 <listitem><para>
7631 <emphasis>Cooked Mode:</emphasis>
7632 The current
7633 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7634 setting and image name are used to automatically
7635 locate and provide the build artifacts.
7636 You just supply a kickstart file and the name
7637 of the image from which to use artifacts.
7638 </para></listitem>
7639 </itemizedlist>
7640 </para>
7641
7642 <para>
7643 Regardless of the mode you use, you need to have the build
7644 artifacts ready and available.
7645 </para>
7646
7647 <section id='raw-mode'>
7648 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007649
7650 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007651 Running Wic in raw mode allows you to specify all the
7652 partitions through the <filename>wic</filename>
7653 command line.
7654 The primary use for raw mode is if you have built
7655 your kernel outside of the Yocto Project
7656 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7657 In other words, you can point to arbitrary kernel,
7658 root filesystem locations, and so forth.
7659 Contrast this behavior with cooked mode where Wic
7660 looks in the Build Directory (e.g.
7661 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007662 </para>
7663
7664 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007665 The general form of the
7666 <filename>wic</filename> command in raw mode is:
7667 <literallayout class='monospaced'>
7668 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007669
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007670 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007671
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007672 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007673 An OpenEmbedded kickstart file. You can provide
7674 your own custom file or use a file from a set of
7675 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007676
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007677 optional arguments:
7678 -h, --help show this help message and exit
7679 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7680 name of directory to create image in
7681 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7682 name of the image to use the artifacts from e.g. core-
7683 image-sato
7684 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7685 path to the /rootfs dir to use as the .wks rootfs
7686 source
7687 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7688 path to the dir containing the boot artifacts (e.g.
7689 /EFI or /syslinux dirs) to use as the .wks bootimg
7690 source
7691 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7692 path to the dir containing the kernel to use in the
7693 .wks bootimg
7694 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7695 path to the native sysroot containing the tools to use
7696 to build the image
7697 -s, --skip-build-check
7698 skip the build check
7699 -f, --build-rootfs build rootfs
7700 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7701 compress image with specified compressor
7702 -m, --bmap generate .bmap
7703 --no-fstab-update Do not change fstab file.
7704 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7705 directory with &lt;image&gt;.env files that store bitbake
7706 variables
7707 -D, --debug output debug information
7708 </literallayout>
7709 <note>
7710 You do not need root privileges to run
7711 Wic.
7712 In fact, you should not run as root when using the
7713 utility.
7714 </note>
7715 </para>
7716 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007717
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007718 <section id='cooked-mode'>
7719 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007720
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007721 <para>
7722 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007723 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007724 In other words, you do not have to specify kernel or
7725 root filesystem locations as part of the command.
7726 All you need to provide is a kickstart file and the
7727 name of the image from which to use artifacts by using
7728 the "-e" option.
7729 Wic looks in the Build Directory (e.g.
7730 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7731 for artifacts.
7732 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007733
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007734 <para>
7735 The general form of the <filename>wic</filename>
7736 command using Cooked Mode is as follows:
7737 <literallayout class='monospaced'>
7738 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007739
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007740 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007741
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007742 <replaceable>wks_file</replaceable>:
7743 An OpenEmbedded kickstart file. You can provide
7744 your own custom file or use a file from a set of
7745 existing files provided with the Yocto Project
7746 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007747
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007748 required argument:
7749 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7750 name of the image to use the artifacts from e.g. core-
7751 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007752 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007753 </para>
7754 </section>
7755 </section>
7756
7757 <section id='using-a-provided-kickstart-file'>
7758 <title>Using an Existing Kickstart File</title>
7759
7760 <para>
7761 If you do not want to create your own kickstart file, you
7762 can use an existing file provided by the Wic installation.
7763 As shipped, kickstart files can be found in the
7764 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007765 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007766 in the following two locations:
7767 <literallayout class='monospaced'>
7768 poky/meta-yocto-bsp/wic
7769 poky/scripts/lib/wic/canned-wks
7770 </literallayout>
7771 Use the following command to list the available kickstart
7772 files:
7773 <literallayout class='monospaced'>
7774 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007775 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7776 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007777 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007778 edgerouter Create SD card image for Edgerouter
7779 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7780 directdisk-gpt Create a 'pcbios' direct disk image
7781 mkefidisk Create an EFI disk image
7782 directdisk Create a 'pcbios' direct disk image
7783 systemd-bootdisk Create an EFI disk image with systemd-boot
7784 mkhybridiso Create a hybrid ISO image
7785 sdimage-bootpart Create SD card image with a boot partition
7786 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7787 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7788 </literallayout>
7789 When you use an existing file, you do not have to use the
7790 <filename>.wks</filename> extension.
7791 Here is an example in Raw Mode that uses the
7792 <filename>directdisk</filename> file:
7793 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007794 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7795 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007796 </literallayout>
7797 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007798
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007799 <para>
7800 Here are the actual partition language commands
7801 used in the <filename>genericx86.wks</filename> file to
7802 generate an image:
7803 <literallayout class='monospaced'>
7804 # short-description: Create an EFI disk image for genericx86*
7805 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7806 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7807 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007808 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7809
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007810 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7811 </literallayout>
7812 </para>
7813 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007814
Brad Bishopc342db32019-05-15 21:57:59 -04007815 <section id='wic-using-the-wic-plugin-interface'>
7816 <title>Using the Wic Plugin Interface</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007817
7818 <para>
7819 You can extend and specialize Wic functionality by using
Brad Bishopc342db32019-05-15 21:57:59 -04007820 Wic plugins.
7821 This section explains the Wic plugin interface.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007822 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007823 Wic plugins consist of "source" and "imager" plugins.
7824 Imager plugins are beyond the scope of this section.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007825 </note>
7826 </para>
7827
7828 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007829 Source plugins provide a mechanism to customize partition
Brad Bishop316dfdd2018-06-25 12:45:53 -04007830 content during the Wic image generation process.
Brad Bishopc342db32019-05-15 21:57:59 -04007831 You can use source plugins to map values that you specify
Brad Bishop316dfdd2018-06-25 12:45:53 -04007832 using <filename>--source</filename> commands in kickstart
Brad Bishopc342db32019-05-15 21:57:59 -04007833 files (i.e. <filename>*.wks</filename>) to a plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007834 implementation used to populate a given partition.
7835 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007836 If you use plugins that have build-time dependencies
Brad Bishop316dfdd2018-06-25 12:45:53 -04007837 (e.g. native tools, bootloaders, and so forth)
7838 when building a Wic image, you need to specify those
7839 dependencies using the
7840 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7841 variable.
7842 </note>
7843 </para>
7844
7845 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007846 Source plugins are subclasses defined in plugin files.
7847 As shipped, the Yocto Project provides several plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007848 files.
Brad Bishopc342db32019-05-15 21:57:59 -04007849 You can see the source plugin files that ship with the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007850 Yocto Project
7851 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
Brad Bishopc342db32019-05-15 21:57:59 -04007852 Each of these plugin files contains source plugins that
Brad Bishop316dfdd2018-06-25 12:45:53 -04007853 are designed to populate a specific Wic image partition.
7854 </para>
7855
7856 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007857 Source plugins are subclasses of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007858 <filename>SourcePlugin</filename> class, which is
7859 defined in the
7860 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7861 file.
7862 For example, the <filename>BootimgEFIPlugin</filename>
Brad Bishopc342db32019-05-15 21:57:59 -04007863 source plugin found in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007864 <filename>bootimg-efi.py</filename> file is a subclass of
7865 the <filename>SourcePlugin</filename> class, which is found
7866 in the <filename>pluginbase.py</filename> file.
7867 </para>
7868
7869 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007870 You can also implement source plugins in a layer outside
Brad Bishop316dfdd2018-06-25 12:45:53 -04007871 of the Source Repositories (external layer).
Brad Bishopc342db32019-05-15 21:57:59 -04007872 To do so, be sure that your plugin files are located in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007873 a directory whose path is
7874 <filename>scripts/lib/wic/plugins/source/</filename>
7875 within your external layer.
Brad Bishopc342db32019-05-15 21:57:59 -04007876 When the plugin files are located there, the source
7877 plugins they contain are made available to Wic.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007878 </para>
7879
7880 <para>
7881 When the Wic implementation needs to invoke a
Brad Bishopc342db32019-05-15 21:57:59 -04007882 partition-specific implementation, it looks for the plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007883 with the same name as the <filename>--source</filename>
7884 parameter used in the kickstart file given to that
7885 partition.
7886 For example, if the partition is set up using the following
7887 command in a kickstart file:
7888 <literallayout class='monospaced'>
7889 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7890 </literallayout>
7891 The methods defined as class members of the matching
Brad Bishopc342db32019-05-15 21:57:59 -04007892 source plugin (i.e. <filename>bootimg-pcbios</filename>)
7893 in the <filename>bootimg-pcbios.py</filename> plugin file
Brad Bishop316dfdd2018-06-25 12:45:53 -04007894 are used.
7895 </para>
7896
7897 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007898 To be more concrete, here is the corresponding plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007899 definition from the <filename>bootimg-pcbios.py</filename>
7900 file for the previous command along with an example
7901 method called by the Wic implementation when it needs to
7902 prepare a partition using an implementation-specific
7903 function:
7904 <literallayout class='monospaced'>
7905 .
7906 .
7907 .
7908 class BootimgPcbiosPlugin(SourcePlugin):
7909 """
7910 Create MBR boot partition and install syslinux on it.
7911 """
7912
7913 name = 'bootimg-pcbios'
7914 .
7915 .
7916 .
7917 @classmethod
7918 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7919 oe_builddir, bootimg_dir, kernel_dir,
7920 rootfs_dir, native_sysroot):
7921 """
7922 Called to do the actual content population for a partition i.e. it
7923 'prepares' the partition to be incorporated into the image.
7924 In this case, prepare content for legacy bios boot partition.
7925 """
7926 .
7927 .
7928 .
7929 </literallayout>
Brad Bishopc342db32019-05-15 21:57:59 -04007930 If a subclass (plugin) itself does not implement a
Brad Bishop316dfdd2018-06-25 12:45:53 -04007931 particular function, Wic locates and uses the default
7932 version in the superclass.
Brad Bishopc342db32019-05-15 21:57:59 -04007933 It is for this reason that all source plugins are derived
Brad Bishop316dfdd2018-06-25 12:45:53 -04007934 from the <filename>SourcePlugin</filename> class.
7935 </para>
7936
7937 <para>
7938 The <filename>SourcePlugin</filename> class defined in
7939 the <filename>pluginbase.py</filename> file defines
Brad Bishopc342db32019-05-15 21:57:59 -04007940 a set of methods that source plugins can implement or
Brad Bishop316dfdd2018-06-25 12:45:53 -04007941 override.
Brad Bishopc342db32019-05-15 21:57:59 -04007942 Any plugins (subclass of
Brad Bishop316dfdd2018-06-25 12:45:53 -04007943 <filename>SourcePlugin</filename>) that do not implement
7944 a particular method inherit the implementation of the
7945 method from the <filename>SourcePlugin</filename> class.
7946 For more information, see the
7947 <filename>SourcePlugin</filename> class in the
7948 <filename>pluginbase.py</filename> file for details:
7949 </para>
7950
7951 <para>
7952 The following list describes the methods implemented in the
7953 <filename>SourcePlugin</filename> class:
7954 <itemizedlist>
7955 <listitem><para>
7956 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7957 Called to populate a partition with actual content.
7958 In other words, the method prepares the final
7959 partition image that is incorporated into the
7960 disk image.
7961 </para></listitem>
7962 <listitem><para>
7963 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7964 Called before
7965 <filename>do_prepare_partition()</filename> to
7966 create custom configuration files for a partition
7967 (e.g. syslinux or grub configuration files).
7968 </para></listitem>
7969 <listitem><para>
7970 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7971 Called after all partitions have been prepared and
7972 assembled into a disk image.
7973 This method provides a hook to allow finalization
7974 of a disk image (e.g. writing an MBR).
7975 </para></listitem>
7976 <listitem><para>
7977 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7978 Special content-staging hook called before
7979 <filename>do_prepare_partition()</filename>.
7980 This method is normally empty.</para>
7981
7982 <para>Typically, a partition just uses the passed-in
7983 parameters (e.g. the unmodified value of
7984 <filename>bootimg_dir</filename>).
7985 However, in some cases, things might need to be
7986 more tailored.
7987 As an example, certain files might additionally
7988 need to be taken from
7989 <filename>bootimg_dir + /boot</filename>.
7990 This hook allows those files to be staged in a
7991 customized fashion.
7992 <note>
7993 <filename>get_bitbake_var()</filename>
7994 allows you to access non-standard variables
7995 that you might want to use for this
7996 behavior.
7997 </note>
7998 </para></listitem>
7999 </itemizedlist>
8000 </para>
8001
8002 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04008003 You can extend the source plugin mechanism.
8004 To add more hooks, create more source plugin methods
Brad Bishop316dfdd2018-06-25 12:45:53 -04008005 within <filename>SourcePlugin</filename> and the
8006 corresponding derived subclasses.
Brad Bishopc342db32019-05-15 21:57:59 -04008007 The code that calls the plugin methods uses the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008008 <filename>plugin.get_source_plugin_methods()</filename>
8009 function to find the method or methods needed by the call.
8010 Retrieval of those methods is accomplished by filling up
8011 a dict with keys that contain the method names of interest.
8012 On success, these will be filled in with the actual
8013 methods.
8014 See the Wic implementation for examples and details.
8015 </para>
8016 </section>
8017
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008018 <section id='wic-usage-examples'>
8019 <title>Examples</title>
8020
8021 <para>
8022 This section provides several examples that show how to use
8023 the Wic utility.
8024 All the examples assume the list of requirements in the
8025 "<link linkend='wic-requirements'>Requirements</link>"
8026 section have been met.
8027 The examples assume the previously generated image is
8028 <filename>core-image-minimal</filename>.
8029 </para>
8030
8031 <section id='generate-an-image-using-a-provided-kickstart-file'>
8032 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008033
8034 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008035 This example runs in Cooked Mode and uses the
8036 <filename>mkefidisk</filename> kickstart file:
8037 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008038 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008039 INFO: Building wic-tools...
8040 .
8041 .
8042 .
8043 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008044 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008045
8046 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008047 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8048 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8049 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8050 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 -05008051
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008052 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008053 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008054 </literallayout>
8055 The previous example shows the easiest way to create
8056 an image by running in cooked mode and supplying
8057 a kickstart file and the "-e" option to point to the
8058 existing build artifacts.
8059 Your <filename>local.conf</filename> file needs to have
8060 the
8061 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8062 variable set to the machine you are using, which is
8063 "qemux86" in this example.
8064 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008065
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008066 <para>
8067 Once the image builds, the output provides image
8068 location, artifact use, and kickstart file information.
8069 <note>
8070 You should always verify the details provided in the
8071 output to make sure that the image was indeed
8072 created exactly as expected.
8073 </note>
8074 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008075
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008076 <para>
8077 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008078 image from the Build Directory onto a USB stick, or
8079 whatever media for which you built your image, and boot
8080 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008081 You can write the image by using
8082 <filename>bmaptool</filename> or
8083 <filename>dd</filename>:
8084 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008085 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008086 </literallayout>
8087 or
8088 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008089 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008090 </literallayout>
8091 <note>
8092 For more information on how to use the
8093 <filename>bmaptool</filename> to flash a device
8094 with an image, see the
8095 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
8096 section.
8097 </note>
8098 </para>
8099 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008100
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008101 <section id='using-a-modified-kickstart-file'>
8102 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008103
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008104 <para>
8105 Because partitioned image creation is driven by the
8106 kickstart file, it is easy to affect image creation by
8107 changing the parameters in the file.
8108 This next example demonstrates that through modification
8109 of the <filename>directdisk-gpt</filename> kickstart
8110 file.
8111 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008112
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008113 <para>
8114 As mentioned earlier, you can use the command
8115 <filename>wic list images</filename> to show the list
8116 of existing kickstart files.
8117 The directory in which the
8118 <filename>directdisk-gpt.wks</filename> file resides is
8119 <filename>scripts/lib/image/canned-wks/</filename>,
8120 which is located in the
8121 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
8122 (e.g. <filename>poky</filename>).
8123 Because available files reside in this directory,
8124 you can create and add your own custom files to the
8125 directory.
8126 Subsequent use of the
8127 <filename>wic list images</filename> command would then
8128 include your kickstart files.
8129 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008130
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008131 <para>
8132 In this example, the existing
8133 <filename>directdisk-gpt</filename> file already does
8134 most of what is needed.
8135 However, for the hardware in this example, the image
8136 will need to boot from <filename>sdb</filename> instead
8137 of <filename>sda</filename>, which is what the
8138 <filename>directdisk-gpt</filename> kickstart file
8139 uses.
8140 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008141
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008142 <para>
8143 The example begins by making a copy of the
8144 <filename>directdisk-gpt.wks</filename> file in the
8145 <filename>scripts/lib/image/canned-wks</filename>
8146 directory and then by changing the lines that specify
8147 the target disk from which to boot.
8148 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008149 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
8150 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008151 </literallayout>
8152 Next, the example modifies the
8153 <filename>directdisksdb-gpt.wks</filename> file and
8154 changes all instances of
8155 "<filename>--ondisk sda</filename>" to
8156 "<filename>--ondisk sdb</filename>".
8157 The example changes the following two lines and leaves
8158 the remaining lines untouched:
8159 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008160 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008161 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
8162 </literallayout>
8163 Once the lines are changed, the example generates the
8164 <filename>directdisksdb-gpt</filename> image.
8165 The command points the process at the
8166 <filename>core-image-minimal</filename> artifacts for
8167 the Next Unit of Computing (nuc)
8168 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8169 the <filename>local.conf</filename>.
8170 <literallayout class='monospaced'>
8171 $ wic create directdisksdb-gpt -e core-image-minimal
8172 INFO: Building wic-tools...
8173 .
8174 .
8175 .
8176 Initialising tasks: 100% |#######################################| Time: 0:00:01
8177 NOTE: Executing SetScene Tasks
8178 NOTE: Executing RunQueue Tasks
8179 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
8180 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008181
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008182 INFO: The new image(s) can be found here:
8183 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008184
8185 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008186 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8187 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8188 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8189 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 -05008190
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008191 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008192 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008193 </literallayout>
8194 Continuing with the example, you can now directly
8195 <filename>dd</filename> the image to a USB stick, or
8196 whatever media for which you built your image,
8197 and boot the resulting media:
8198 <literallayout class='monospaced'>
8199 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8200 140966+0 records in
8201 140966+0 records out
8202 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8203 $ sudo eject /dev/sdb
8204 </literallayout>
8205 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008206 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008207
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008208 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8209 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008210
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008211 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008212 This next example manually specifies each build artifact
8213 (runs in Raw Mode) and uses a modified kickstart file.
8214 The example also uses the <filename>-o</filename> option
8215 to cause Wic to create the output
8216 somewhere other than the default output directory,
8217 which is the current directory:
8218 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008219 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8220 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8221 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8222 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8223 --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 -05008224
8225 INFO: Creating image(s)...
8226
8227 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008228 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008229
8230 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008231 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8232 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8233 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8234 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 -05008235
8236 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008237 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008238 </literallayout>
8239 For this example,
8240 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8241 did not have to be specified in the
8242 <filename>local.conf</filename> file since the
8243 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008244 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008245 </section>
8246
8247 <section id='using-wic-to-manipulate-an-image'>
8248 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008249
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008250 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008251 Wic image manipulation allows you to shorten turnaround
8252 time during image development.
8253 For example, you can use Wic to delete the kernel partition
8254 of a Wic image and then insert a newly built kernel.
8255 This saves you time from having to rebuild the entire image
8256 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008257 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008258 In order to use Wic to manipulate a Wic image as in
8259 this example, your development machine must have the
8260 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008261 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008262 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008263
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008264 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008265 The following example examines the contents of the Wic
8266 image, deletes the existing kernel, and then inserts a
8267 new kernel:
8268 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008269 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008270 <emphasis>List the Partitions:</emphasis>
8271 Use the <filename>wic ls</filename> command to list
8272 all the partitions in the Wic image:
8273 <literallayout class='monospaced'>
8274 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8275 Num Start End Size Fstype
8276 1 1048576 25041919 23993344 fat16
8277 2 25165824 72157183 46991360 ext4
8278 </literallayout>
8279 The previous output shows two partitions in the
8280 <filename>core-image-minimal-qemux86.wic</filename>
8281 image.
8282 </para></listitem>
8283 <listitem><para>
8284 <emphasis>Examine a Particular Partition:</emphasis>
8285 Use the <filename>wic ls</filename> command again
8286 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008287 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008288 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008289 You can get command usage on any Wic command
8290 using the following form:
8291 <literallayout class='monospaced'>
8292 $ wic help <replaceable>command</replaceable>
8293 </literallayout>
8294 For example, the following command shows you
8295 the various ways to use the
8296 <filename>wic ls</filename> command:
8297 <literallayout class='monospaced'>
8298 $ wic help ls
8299 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008300 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008301 The following command shows what is in Partition
8302 one:
8303 <literallayout class='monospaced'>
8304 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8305 Volume in drive : is boot
8306 Volume Serial Number is E894-1809
8307 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008308
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008309 libcom32 c32 186500 2017-10-09 16:06
8310 libutil c32 24148 2017-10-09 16:06
8311 syslinux cfg 220 2017-10-09 16:06
8312 vesamenu c32 27104 2017-10-09 16:06
8313 vmlinuz 6904608 2017-10-09 16:06
8314 5 files 7 142 580 bytes
8315 16 582 656 bytes free
8316 </literallayout>
8317 The previous output shows five files, with the
8318 <filename>vmlinuz</filename> being the kernel.
8319 <note>
8320 If you see the following error, you need to
8321 update or create a
8322 <filename>~/.mtoolsrc</filename> file and
8323 be sure to have the line “mtools_skip_check=1“
8324 in the file.
8325 Then, run the Wic command again:
8326 <literallayout class='monospaced'>
8327 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8328 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8329 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8330 </literallayout>
8331 </note>
8332 </para></listitem>
8333 <listitem><para>
8334 <emphasis>Remove the Old Kernel:</emphasis>
8335 Use the <filename>wic rm</filename> command to
8336 remove the <filename>vmlinuz</filename> file
8337 (kernel):
8338 <literallayout class='monospaced'>
8339 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8340 </literallayout>
8341 </para></listitem>
8342 <listitem><para>
8343 <emphasis>Add In the New Kernel:</emphasis>
8344 Use the <filename>wic cp</filename> command to
8345 add the updated kernel to the Wic image.
8346 Depending on how you built your kernel, it could
8347 be in different places.
8348 If you used <filename>devtool</filename> and
8349 an SDK to build your kernel, it resides in the
8350 <filename>tmp/work</filename> directory of the
8351 extensible SDK.
8352 If you used <filename>make</filename> to build the
8353 kernel, the kernel will be in the
8354 <filename>workspace/sources</filename> area.
8355 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008356
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008357 <para>The following example assumes
8358 <filename>devtool</filename> was used to build
8359 the kernel:
8360 <literallayout class='monospaced'>
8361 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 \
8362 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8363 </literallayout>
8364 Once the new kernel is added back into the image,
8365 you can use the <filename>dd</filename>
8366 command or
8367 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8368 to flash your wic image onto an SD card
8369 or USB stick and test your target.
8370 <note>
8371 Using <filename>bmaptool</filename> is
8372 generally 10 to 20 times faster than using
8373 <filename>dd</filename>.
8374 </note>
8375 </para></listitem>
8376 </orderedlist>
8377 </para>
8378 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008379 </section>
8380 </section>
8381
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008382 <section id='flashing-images-using-bmaptool'>
8383 <title>Flashing Images Using <filename>bmaptool</filename></title>
8384
8385 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008386 A fast and easy way to flash an image to a bootable device
8387 is to use Bmaptool, which is integrated into the OpenEmbedded
8388 build system.
8389 Bmaptool is a generic tool that creates a file's block map (bmap)
8390 and then uses that map to copy the file.
8391 As compared to traditional tools such as dd or cp, Bmaptool
8392 can copy (or flash) large files like raw system image files
8393 much faster.
8394 <note><title>Notes</title>
8395 <itemizedlist>
8396 <listitem><para>
8397 If you are using Ubuntu or Debian distributions, you
8398 can install the <filename>bmap-tools</filename> package
8399 using the following command and then use the tool
8400 without specifying <filename>PATH</filename> even from
8401 the root account:
8402 <literallayout class='monospaced'>
8403 $ sudo apt-get install bmap-tools
8404 </literallayout>
8405 </para></listitem>
8406 <listitem><para>
8407 If you are unable to install the
8408 <filename>bmap-tools</filename> package, you will
8409 need to build Bmaptool before using it.
8410 Use the following command:
8411 <literallayout class='monospaced'>
8412 $ bitbake bmap-tools-native
8413 </literallayout>
8414 </para></listitem>
8415 </itemizedlist>
8416 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008417 </para>
8418
8419 <para>
8420 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008421 Realize that while this example uses a Wic image, you can use
8422 Bmaptool to flash any type of image.
8423 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008424 <orderedlist>
8425 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008426 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8427 You need to have the following set in your
8428 <filename>local.conf</filename> file before building
8429 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008430 <literallayout class='monospaced'>
8431 IMAGE_FSTYPES += "wic wic.bmap"
8432 </literallayout>
8433 </para></listitem>
8434 <listitem><para>
8435 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008436 Either have your image ready (pre-built with the
8437 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8438 setting previously mentioned) or take the step to build
8439 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008440 <literallayout class='monospaced'>
8441 $ bitbake <replaceable>image</replaceable>
8442 </literallayout>
8443 </para></listitem>
8444 <listitem><para>
8445 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008446 Flash the device with the image by using Bmaptool
8447 depending on your particular setup.
8448 The following commands assume the image resides in the
8449 Build Directory's <filename>deploy/images/</filename>
8450 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008451 <itemizedlist>
8452 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008453 If you have write access to the media, use this
8454 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008455 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008456 $ oe-run-native bmap-tools-native bmaptool copy <replaceable>build-directory</replaceable>/tmp/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.wic /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008457 </literallayout>
8458 </para></listitem>
8459 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008460 If you do not have write access to the media, set
8461 your permissions first and then use the same
8462 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008463 <literallayout class='monospaced'>
8464 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008465 $ 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 -05008466 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008467 </para></listitem>
8468 </itemizedlist>
8469 </para></listitem>
8470 </orderedlist>
8471 </para>
8472
8473 <para>
8474 For help on the <filename>bmaptool</filename> command, use the
8475 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008476 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008477 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008478 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008479 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008480 </section>
8481
8482 <section id='making-images-more-secure'>
8483 <title>Making Images More Secure</title>
8484
8485 <para>
8486 Security is of increasing concern for embedded devices.
8487 Consider the issues and problems discussed in just this
8488 sampling of work found across the Internet:
8489 <itemizedlist>
8490 <listitem><para><emphasis>
8491 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8492 by Bruce Schneier
8493 </para></listitem>
8494 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008495 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008496 by Carna Botnet</para></listitem>
8497 <listitem><para><emphasis>
8498 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8499 by Jake Edge
8500 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008501 </itemizedlist>
8502 </para>
8503
8504 <para>
8505 When securing your image is of concern, there are steps, tools,
8506 and variables that you can consider to help you reach the
8507 security goals you need for your particular device.
8508 Not all situations are identical when it comes to making an
8509 image secure.
8510 Consequently, this section provides some guidance and suggestions
8511 for consideration when you want to make your image more secure.
8512 <note>
8513 Because the security requirements and risks are
8514 different for every type of device, this section cannot
8515 provide a complete reference on securing your custom OS.
8516 It is strongly recommended that you also consult other sources
8517 of information on embedded Linux system hardening and on
8518 security.
8519 </note>
8520 </para>
8521
8522 <section id='general-considerations'>
8523 <title>General Considerations</title>
8524
8525 <para>
8526 General considerations exist that help you create more
8527 secure images.
8528 You should consider the following suggestions to help
8529 make your device more secure:
8530 <itemizedlist>
8531 <listitem><para>
8532 Scan additional code you are adding to the system
8533 (e.g. application code) by using static analysis
8534 tools.
8535 Look for buffer overflows and other potential
8536 security problems.
8537 </para></listitem>
8538 <listitem><para>
8539 Pay particular attention to the security for
8540 any web-based administration interface.
8541 </para>
8542 <para>Web interfaces typically need to perform
8543 administrative functions and tend to need to run with
8544 elevated privileges.
8545 Thus, the consequences resulting from the interface's
8546 security becoming compromised can be serious.
8547 Look for common web vulnerabilities such as
8548 cross-site-scripting (XSS), unvalidated inputs,
8549 and so forth.</para>
8550 <para>As with system passwords, the default credentials
8551 for accessing a web-based interface should not be the
8552 same across all devices.
8553 This is particularly true if the interface is enabled
8554 by default as it can be assumed that many end-users
8555 will not change the credentials.
8556 </para></listitem>
8557 <listitem><para>
8558 Ensure you can update the software on the device to
8559 mitigate vulnerabilities discovered in the future.
8560 This consideration especially applies when your
8561 device is network-enabled.
8562 </para></listitem>
8563 <listitem><para>
8564 Ensure you remove or disable debugging functionality
8565 before producing the final image.
8566 For information on how to do this, see the
8567 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8568 section.
8569 </para></listitem>
8570 <listitem><para>
8571 Ensure you have no network services listening that
8572 are not needed.
8573 </para></listitem>
8574 <listitem><para>
8575 Remove any software from the image that is not needed.
8576 </para></listitem>
8577 <listitem><para>
8578 Enable hardware support for secure boot functionality
8579 when your device supports this functionality.
8580 </para></listitem>
8581 </itemizedlist>
8582 </para>
8583 </section>
8584
8585 <section id='security-flags'>
8586 <title>Security Flags</title>
8587
8588 <para>
8589 The Yocto Project has security flags that you can enable that
8590 help make your build output more secure.
8591 The security flags are in the
8592 <filename>meta/conf/distro/include/security_flags.inc</filename>
8593 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008594 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008595 (e.g. <filename>poky</filename>).
8596 <note>
8597 Depending on the recipe, certain security flags are enabled
8598 and disabled by default.
8599 </note>
8600 </para>
8601
8602 <para>
8603<!--
8604 The GCC/LD flags in <filename>security_flags.inc</filename>
8605 enable more secure code generation.
8606 By including the <filename>security_flags.inc</filename>
8607 file, you enable flags to the compiler and linker that cause
8608 them to generate more secure code.
8609 <note>
8610 The GCC/LD flags are enabled by default in the
8611 <filename>poky-lsb</filename> distribution.
8612 </note>
8613-->
8614 Use the following line in your
8615 <filename>local.conf</filename> file or in your custom
8616 distribution configuration file to enable the security
8617 compiler and linker flags for your build:
8618 <literallayout class='monospaced'>
8619 require conf/distro/include/security_flags.inc
8620 </literallayout>
8621 </para>
8622 </section>
8623
8624 <section id='considerations-specific-to-the-openembedded-build-system'>
8625 <title>Considerations Specific to the OpenEmbedded Build System</title>
8626
8627 <para>
8628 You can take some steps that are specific to the
8629 OpenEmbedded build system to make your images more secure:
8630 <itemizedlist>
8631 <listitem><para>
8632 Ensure "debug-tweaks" is not one of your selected
8633 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8634 When creating a new project, the default is to provide you
8635 with an initial <filename>local.conf</filename> file that
8636 enables this feature using the
8637 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8638 <literallayout class='monospaced'>
8639 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8640 </literallayout>
8641 To disable that feature, simply comment out that line in your
8642 <filename>local.conf</filename> file, or
8643 make sure <filename>IMAGE_FEATURES</filename> does not contain
8644 "debug-tweaks" before producing your final image.
8645 Among other things, leaving this in place sets the
8646 root password as blank, which makes logging in for
8647 debugging or inspection easy during
8648 development but also means anyone can easily log in
8649 during production.
8650 </para></listitem>
8651 <listitem><para>
8652 It is possible to set a root password for the image
8653 and also to set passwords for any extra users you might
8654 add (e.g. administrative or service type users).
8655 When you set up passwords for multiple images or
8656 users, you should not duplicate passwords.
8657 </para>
8658 <para>
8659 To set up passwords, use the
8660 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8661 class, which is the preferred method.
8662 For an example on how to set up both root and user
8663 passwords, see the
8664 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8665 section.
8666 <note>
8667 When adding extra user accounts or setting a
8668 root password, be cautious about setting the
8669 same password on every device.
8670 If you do this, and the password you have set
8671 is exposed, then every device is now potentially
8672 compromised.
8673 If you need this access but want to ensure
8674 security, consider setting a different,
8675 random password for each device.
8676 Typically, you do this as a separate step after
8677 you deploy the image onto the device.
8678 </note>
8679 </para></listitem>
8680 <listitem><para>
8681 Consider enabling a Mandatory Access Control (MAC)
8682 framework such as SMACK or SELinux and tuning it
8683 appropriately for your device's usage.
8684 You can find more information in the
8685 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8686 layer.
8687 </para></listitem>
8688 </itemizedlist>
8689 </para>
8690
8691 <para>
8692 </para>
8693 </section>
8694
8695 <section id='tools-for-hardening-your-image'>
8696 <title>Tools for Hardening Your Image</title>
8697
8698 <para>
8699 The Yocto Project provides tools for making your image
8700 more secure.
8701 You can find these tools in the
8702 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008703 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008704 </para>
8705 </section>
8706 </section>
8707
8708 <section id='creating-your-own-distribution'>
8709 <title>Creating Your Own Distribution</title>
8710
8711 <para>
8712 When you build an image using the Yocto Project and
8713 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008714 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8715 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008716 If you wish to gain more control over package alternative
8717 selections, compile-time options, and other low-level
8718 configurations, you can create your own distribution.
8719 </para>
8720
8721 <para>
8722 To create your own distribution, the basic steps consist of
8723 creating your own distribution layer, creating your own
8724 distribution configuration file, and then adding any needed
8725 code and Metadata to the layer.
8726 The following steps provide some more detail:
8727 <itemizedlist>
8728 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8729 Create your distribution layer so that you can keep your
8730 Metadata and code for the distribution separate.
8731 It is strongly recommended that you create and use your own
8732 layer for configuration and code.
8733 Using your own layer as compared to just placing
8734 configurations in a <filename>local.conf</filename>
8735 configuration file makes it easier to reproduce the same
8736 build configuration when using multiple build machines.
8737 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008738 "<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 -05008739 section for information on how to quickly set up a layer.
8740 </para></listitem>
8741 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8742 The distribution configuration file needs to be created in
8743 the <filename>conf/distro</filename> directory of your
8744 layer.
8745 You need to name it using your distribution name
8746 (e.g. <filename>mydistro.conf</filename>).
8747 <note>
8748 The
8749 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8750 variable in your
8751 <filename>local.conf</filename> file determines the
8752 name of your distribution.
8753 </note></para>
8754 <para>You can split out parts of your configuration file
8755 into include files and then "require" them from within
8756 your distribution configuration file.
8757 Be sure to place the include files in the
8758 <filename>conf/distro/include</filename> directory of
8759 your layer.
8760 A common example usage of include files would be to
8761 separate out the selection of desired version and revisions
8762 for individual recipes.
8763</para>
8764 <para>Your configuration file needs to set the following
8765 required variables:
8766 <literallayout class='monospaced'>
8767 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8768 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8769 </literallayout>
8770 These following variables are optional and you typically
8771 set them from the distribution configuration file:
8772 <literallayout class='monospaced'>
8773 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8774 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8775 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8776 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8777 </literallayout>
8778 <tip>
8779 If you want to base your distribution configuration file
8780 on the very basic configuration from OE-Core, you
8781 can use
8782 <filename>conf/distro/defaultsetup.conf</filename> as
8783 a reference and just include variables that differ
8784 as compared to <filename>defaultsetup.conf</filename>.
8785 Alternatively, you can create a distribution
8786 configuration file from scratch using the
8787 <filename>defaultsetup.conf</filename> file
8788 or configuration files from other distributions
8789 such as Poky or Angstrom as references.
8790 </tip></para></listitem>
8791 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8792 Be sure to define any other variables for which you want to
8793 create a default or enforce as part of the distribution
8794 configuration.
8795 You can include nearly any variable from the
8796 <filename>local.conf</filename> file.
8797 The variables you use are not limited to the list in the
8798 previous bulleted item.</para></listitem>
8799 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8800 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008801 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008802 set your
8803 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8804 variable to point to your distribution's configuration file.
8805 For example, if your distribution's configuration file is
8806 named <filename>mydistro.conf</filename>, then you point
8807 to it as follows:
8808 <literallayout class='monospaced'>
8809 DISTRO = "mydistro"
8810 </literallayout></para></listitem>
8811 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8812 Use your layer to hold other information needed for the
8813 distribution:
8814 <itemizedlist>
8815 <listitem><para>Add recipes for installing
8816 distro-specific configuration files that are not
8817 already installed by another recipe.
8818 If you have distro-specific configuration files
8819 that are included by an existing recipe, you should
8820 add an append file (<filename>.bbappend</filename>)
8821 for those.
8822 For general information and recommendations
8823 on how to add recipes to your layer, see the
8824 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8825 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008826 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008827 sections.</para></listitem>
8828 <listitem><para>Add any image recipes that are specific
8829 to your distribution.</para></listitem>
8830 <listitem><para>Add a <filename>psplash</filename>
8831 append file for a branded splash screen.
8832 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008833 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008834 section.</para></listitem>
8835 <listitem><para>Add any other append files to make
8836 custom changes that are specific to individual
8837 recipes.</para></listitem>
8838 </itemizedlist></para></listitem>
8839 </itemizedlist>
8840 </para>
8841 </section>
8842
8843 <section id='creating-a-custom-template-configuration-directory'>
8844 <title>Creating a Custom Template Configuration Directory</title>
8845
8846 <para>
8847 If you are producing your own customized version
8848 of the build system for use by other users, you might
8849 want to customize the message shown by the setup script or
8850 you might want to change the template configuration files (i.e.
8851 <filename>local.conf</filename> and
8852 <filename>bblayers.conf</filename>) that are created in
8853 a new build directory.
8854 </para>
8855
8856 <para>
8857 The OpenEmbedded build system uses the environment variable
8858 <filename>TEMPLATECONF</filename> to locate the directory
8859 from which it gathers configuration information that ultimately
8860 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008861 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008862 <filename>conf</filename> directory.
8863 By default, <filename>TEMPLATECONF</filename> is set as
8864 follows in the <filename>poky</filename> repository:
8865 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008866 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008867 </literallayout>
8868 This is the directory used by the build system to find templates
8869 from which to build some key configuration files.
8870 If you look at this directory, you will see the
8871 <filename>bblayers.conf.sample</filename>,
8872 <filename>local.conf.sample</filename>, and
8873 <filename>conf-notes.txt</filename> files.
8874 The build system uses these files to form the respective
8875 <filename>bblayers.conf</filename> file,
8876 <filename>local.conf</filename> file, and display the list of
8877 BitBake targets when running the setup script.
8878 </para>
8879
8880 <para>
8881 To override these default configuration files with
8882 configurations you want used within every new
8883 Build Directory, simply set the
8884 <filename>TEMPLATECONF</filename> variable to your directory.
8885 The <filename>TEMPLATECONF</filename> variable is set in the
8886 <filename>.templateconf</filename> file, which is in the
8887 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008888 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008889 folder (e.g. <filename>poky</filename>).
8890 Edit the <filename>.templateconf</filename> so that it can locate
8891 your directory.
8892 </para>
8893
8894 <para>
8895 Best practices dictate that you should keep your
8896 template configuration directory in your custom distribution layer.
8897 For example, suppose you have a layer named
8898 <filename>meta-mylayer</filename> located in your home directory
8899 and you want your template configuration directory named
8900 <filename>myconf</filename>.
8901 Changing the <filename>.templateconf</filename> as follows
8902 causes the OpenEmbedded build system to look in your directory
8903 and base its configuration files on the
8904 <filename>*.sample</filename> configuration files it finds.
8905 The final configuration files (i.e.
8906 <filename>local.conf</filename> and
8907 <filename>bblayers.conf</filename> ultimately still end up in
8908 your Build Directory, but they are based on your
8909 <filename>*.sample</filename> files.
8910 <literallayout class='monospaced'>
8911 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8912 </literallayout>
8913 </para>
8914
8915 <para>
8916 Aside from the <filename>*.sample</filename> configuration files,
8917 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008918 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008919 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008920 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008921 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8922 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008923 output.
8924 Customizing this <filename>conf-notes.txt</filename> file is a
8925 good way to make sure your list of custom targets appears
8926 as part of the script's output.
8927 </para>
8928
8929 <para>
8930 Here is the default list of targets displayed as a result of
8931 running either of the setup scripts:
8932 <literallayout class='monospaced'>
8933 You can now run 'bitbake &lt;target&gt;'
8934
8935 Common targets are:
8936 core-image-minimal
8937 core-image-sato
8938 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008939 meta-ide-support
8940 </literallayout>
8941 </para>
8942
8943 <para>
8944 Changing the listed common targets is as easy as editing your
8945 version of <filename>conf-notes.txt</filename> in your
8946 custom template configuration directory and making sure you
8947 have <filename>TEMPLATECONF</filename> set to your directory.
8948 </para>
8949 </section>
8950
Brad Bishop316dfdd2018-06-25 12:45:53 -04008951 <section id='dev-saving-memory-during-a-build'>
8952 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008953
8954 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008955 To help conserve disk space during builds, you can add the
8956 following statement to your project's
8957 <filename>local.conf</filename> configuration file found in the
8958 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8959 <literallayout class='monospaced'>
8960 INHERIT += "rm_work"
8961 </literallayout>
8962 Adding this statement deletes the work directory used for building
8963 a recipe once the recipe is built.
8964 For more information on "rm_work", see the
8965 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8966 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008967 </para>
8968 </section>
8969
8970 <section id='working-with-packages'>
8971 <title>Working with Packages</title>
8972
8973 <para>
8974 This section describes a few tasks that involve packages:
8975 <itemizedlist>
8976 <listitem><para>
8977 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8978 </para></listitem>
8979 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008980 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008981 </para></listitem>
8982 <listitem><para>
8983 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8984 </para></listitem>
8985 <listitem><para>
Brad Bishop15ae2502019-06-18 21:44:24 -04008986 <link linkend='using-runtime-package-management'>Using runtime package management</link>
8987 </para></listitem>
8988 <listitem><para>
8989 <link linkend='generating-and-using-signed-packages'>Generating and using signed packages</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008990 </para></listitem>
8991 <listitem><para>
8992 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8993 </para></listitem>
Brad Bishop15ae2502019-06-18 21:44:24 -04008994 <listitem><para>
8995 <link linkend='creating-node-package-manager-npm-packages'>Creating node package manager (NPM) packages</link>
8996 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008997 </itemizedlist>
8998 </para>
8999
9000 <section id='excluding-packages-from-an-image'>
9001 <title>Excluding Packages from an Image</title>
9002
9003 <para>
9004 You might find it necessary to prevent specific packages
9005 from being installed into an image.
9006 If so, you can use several variables to direct the build
9007 system to essentially ignore installing recommended packages
9008 or to not install a package at all.
9009 </para>
9010
9011 <para>
9012 The following list introduces variables you can use to
9013 prevent packages from being installed into your image.
9014 Each of these variables only works with IPK and RPM
9015 package types.
9016 Support for Debian packages does not exist.
9017 Also, you can use these variables from your
9018 <filename>local.conf</filename> file or attach them to a
9019 specific image recipe by using a recipe name override.
9020 For more detail on the variables, see the descriptions in the
9021 Yocto Project Reference Manual's glossary chapter.
9022 <itemizedlist>
9023 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
9024 Use this variable to specify "recommended-only"
9025 packages that you do not want installed.
9026 </para></listitem>
9027 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
9028 Use this variable to prevent all "recommended-only"
9029 packages from being installed.
9030 </para></listitem>
9031 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
9032 Use this variable to prevent specific packages from
9033 being installed regardless of whether they are
9034 "recommended-only" or not.
9035 You need to realize that the build process could
9036 fail with an error when you
9037 prevent the installation of a package whose presence
9038 is required by an installed package.
9039 </para></listitem>
9040 </itemizedlist>
9041 </para>
9042 </section>
9043
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009044 <section id='incrementing-a-binary-package-version'>
9045 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009046
9047 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009048 This section provides some background on how binary package
9049 versioning is accomplished and presents some of the services,
9050 variables, and terminology involved.
9051 </para>
9052
9053 <para>
9054 In order to understand binary package versioning, you need
9055 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009056 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009057 <listitem><para>
9058 Binary Package: The binary package that is eventually
9059 built and installed into an image.
9060 </para></listitem>
9061 <listitem><para>
9062 Binary Package Version: The binary package version
9063 is composed of two components - a version and a
9064 revision.
9065 <note>
9066 Technically, a third component, the "epoch" (i.e.
9067 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
9068 is involved but this discussion for the most part
9069 ignores <filename>PE</filename>.
9070 </note>
9071 The version and revision are taken from the
9072 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
9073 and
9074 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9075 variables, respectively.
9076 </para></listitem>
9077 <listitem><para>
9078 <filename>PV</filename>: The recipe version.
9079 <filename>PV</filename> represents the version of the
9080 software being packaged.
9081 Do not confuse <filename>PV</filename> with the
9082 binary package version.
9083 </para></listitem>
9084 <listitem><para>
9085 <filename>PR</filename>: The recipe revision.
9086 </para></listitem>
9087 <listitem><para>
9088 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
9089 The OpenEmbedded build system uses this string
9090 to help define the value of <filename>PV</filename>
9091 when the source code revision needs to be included
9092 in it.
9093 </para></listitem>
9094 <listitem><para>
9095 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
9096 A network-based service that helps automate keeping
9097 package feeds compatible with existing package
9098 manager applications such as RPM, APT, and OPKG.
9099 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009100 </itemizedlist>
9101 </para>
9102
9103 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009104 Whenever the binary package content changes, the binary package
9105 version must change.
9106 Changing the binary package version is accomplished by changing
9107 or "bumping" the <filename>PR</filename> and/or
9108 <filename>PV</filename> values.
9109 Increasing these values occurs one of two ways:
9110 <itemizedlist>
9111 <listitem><para>Automatically using a Package Revision
9112 Service (PR Service).
9113 </para></listitem>
9114 <listitem><para>Manually incrementing the
9115 <filename>PR</filename> and/or
9116 <filename>PV</filename> variables.
9117 </para></listitem>
9118 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009119 </para>
9120
9121 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009122 Given a primary challenge of any build system and its users
9123 is how to maintain a package feed that is compatible with
9124 existing package manager applications such as RPM, APT, and
9125 OPKG, using an automated system is much preferred over a
9126 manual system.
9127 In either system, the main requirement is that binary package
9128 version numbering increases in a linear fashion and that a
9129 number of version components exist that support that linear
9130 progression.
9131 For information on how to ensure package revisioning remains
9132 linear, see the
9133 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
9134 section.
9135 </para>
9136
9137 <para>
9138 The following three sections provide related information on the
9139 PR Service, the manual method for "bumping"
9140 <filename>PR</filename> and/or <filename>PV</filename>, and
9141 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009142 </para>
9143
9144 <section id='working-with-a-pr-service'>
9145 <title>Working With a PR Service</title>
9146
9147 <para>
9148 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009149 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009150 is error prone, inaccurate, and causes problems for people
9151 submitting recipes.
9152 Conversely, the PR Service automatically generates
9153 increasing numbers, particularly the revision field,
9154 which removes the human element.
9155 <note>
9156 For additional information on using a PR Service, you
9157 can see the
9158 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
9159 wiki page.
9160 </note>
9161 </para>
9162
9163 <para>
9164 The Yocto Project uses variables in order of
9165 decreasing priority to facilitate revision numbering (i.e.
9166 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
9167 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
9168 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9169 for epoch, version, and revision, respectively).
9170 The values are highly dependent on the policies and
9171 procedures of a given distribution and package feed.
9172 </para>
9173
9174 <para>
9175 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04009176 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009177 which are unique to a given build, the build system
9178 knows when to rebuild packages.
9179 All the inputs into a given task are represented by a
9180 signature, which can trigger a rebuild when different.
9181 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009182 <filename>PR</filename>, <filename>PV</filename>, and
9183 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009184 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009185 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009186 </para>
9187
9188 <para>
9189 The PR Service works with both
9190 <filename>OEBasic</filename> and
9191 <filename>OEBasicHash</filename> generators.
9192 The value of <filename>PR</filename> bumps when the
9193 checksum changes and the different generator mechanisms
9194 change signatures under different circumstances.
9195 </para>
9196
9197 <para>
9198 As implemented, the build system includes values from
9199 the PR Service into the <filename>PR</filename> field as
9200 an addition using the form "<filename>.x</filename>" so
9201 <filename>r0</filename> becomes <filename>r0.1</filename>,
9202 <filename>r0.2</filename> and so forth.
9203 This scheme allows existing <filename>PR</filename> values
9204 to be used for whatever reasons, which include manual
9205 <filename>PR</filename> bumps, should it be necessary.
9206 </para>
9207
9208 <para>
9209 By default, the PR Service is not enabled or running.
9210 Thus, the packages generated are just "self consistent".
9211 The build system adds and removes packages and
9212 there are no guarantees about upgrade paths but images
9213 will be consistent and correct with the latest changes.
9214 </para>
9215
9216 <para>
9217 The simplest form for a PR Service is for it to exist
9218 for a single host development system that builds the
9219 package feed (building system).
9220 For this scenario, you can enable a local PR Service by
9221 setting
9222 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9223 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009224 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009225 <literallayout class='monospaced'>
9226 PRSERV_HOST = "localhost:0"
9227 </literallayout>
9228 Once the service is started, packages will automatically
9229 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009230 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009231 </para>
9232
9233 <para>
9234 If you have a more complex setup where multiple host
9235 development systems work against a common, shared package
9236 feed, you have a single PR Service running and it is
9237 connected to each building system.
9238 For this scenario, you need to start the PR Service using
9239 the <filename>bitbake-prserv</filename> command:
9240 <literallayout class='monospaced'>
9241 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9242 </literallayout>
9243 In addition to hand-starting the service, you need to
9244 update the <filename>local.conf</filename> file of each
9245 building system as described earlier so each system
9246 points to the server and port.
9247 </para>
9248
9249 <para>
9250 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009251 some sanity checks to binary package versions, in
9252 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009253 To enable build history, add the following to each building
9254 system's <filename>local.conf</filename> file:
9255 <literallayout class='monospaced'>
9256 # It is recommended to activate "buildhistory" for testing the PR service
9257 INHERIT += "buildhistory"
9258 BUILDHISTORY_COMMIT = "1"
9259 </literallayout>
9260 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009261 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9262 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009263 </para>
9264
9265 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009266 <para>
9267 The OpenEmbedded build system does not maintain
9268 <filename>PR</filename> information as part of the
9269 shared state (sstate) packages.
9270 If you maintain an sstate feed, its expected that either
9271 all your building systems that contribute to the sstate
9272 feed use a shared PR Service, or you do not run a PR
9273 Service on any of your building systems.
9274 Having some systems use a PR Service while others do
9275 not leads to obvious problems.
9276 </para>
9277
9278 <para>
9279 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009280 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9281 section in the Yocto Project Overview and Concepts
9282 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009283 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009284 </note>
9285 </section>
9286
9287 <section id='manually-bumping-pr'>
9288 <title>Manually Bumping PR</title>
9289
9290 <para>
9291 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009292 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009293 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9294 variable.
9295 </para>
9296
9297 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009298 If a committed change results in changing the package
9299 output, then the value of the PR variable needs to be
9300 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009301 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009302 variable and set its initial value equal to "r0", which is
9303 the default.
9304 Even though the default value is "r0", the practice of
9305 adding it to a new recipe makes it harder to forget to bump
9306 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009307 </para>
9308
9309 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009310 If you are sharing a common <filename>.inc</filename> file
9311 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009312 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009313 variable to ensure that the recipes sharing the
9314 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009315 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009316 The <filename>.inc</filename> file must set
9317 <filename>INC_PR</filename> (initially to "r0"), and all
9318 recipes referring to it should set <filename>PR</filename>
9319 to "${INC_PR}.0" initially, incrementing the last number
9320 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009321 If the <filename>.inc</filename> file is changed then its
9322 <filename>INC_PR</filename> should be incremented.
9323 </para>
9324
9325 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009326 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009327 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9328 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009329 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009330 <filename>INC_PR</filename>).
9331 </para>
9332
9333 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009334 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009335 However, if for some reason <filename>PV</filename> changes
9336 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009337 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9338 variable (Package Epoch).
9339 The <filename>PE</filename> variable defaults to "0".
9340 </para>
9341
9342 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009343 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009344 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9345 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009346 These guidelines define how versions are compared and what
9347 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009348 </para>
9349 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009350
9351 <section id='automatically-incrementing-a-binary-package-revision-number'>
9352 <title>Automatically Incrementing a Package Version Number</title>
9353
9354 <para>
9355 When fetching a repository, BitBake uses the
9356 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9357 variable to determine the specific source code revision
9358 from which to build.
9359 You set the <filename>SRCREV</filename> variable to
9360 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9361 to cause the OpenEmbedded build system to automatically use the
9362 latest revision of the software:
9363 <literallayout class='monospaced'>
9364 SRCREV = "${AUTOREV}"
9365 </literallayout>
9366 </para>
9367
9368 <para>
9369 Furthermore, you need to reference <filename>SRCPV</filename>
9370 in <filename>PV</filename> in order to automatically update
9371 the version whenever the revision of the source code
9372 changes.
9373 Here is an example:
9374 <literallayout class='monospaced'>
9375 PV = "1.0+git${SRCPV}"
9376 </literallayout>
9377 The OpenEmbedded build system substitutes
9378 <filename>SRCPV</filename> with the following:
9379 <literallayout class='monospaced'>
9380 AUTOINC+<replaceable>source_code_revision</replaceable>
9381 </literallayout>
9382 The build system replaces the <filename>AUTOINC</filename> with
9383 a number.
9384 The number used depends on the state of the PR Service:
9385 <itemizedlist>
9386 <listitem><para>
9387 If PR Service is enabled, the build system increments
9388 the number, which is similar to the behavior of
9389 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9390 This behavior results in linearly increasing package
9391 versions, which is desirable.
9392 Here is an example:
9393 <literallayout class='monospaced'>
9394 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9395 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9396 </literallayout>
9397 </para></listitem>
9398 <listitem><para>
9399 If PR Service is not enabled, the build system
9400 replaces the <filename>AUTOINC</filename>
9401 placeholder with zero (i.e. "0").
9402 This results in changing the package version since
9403 the source revision is included.
9404 However, package versions are not increased linearly.
9405 Here is an example:
9406 <literallayout class='monospaced'>
9407 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9408 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9409 </literallayout>
9410 </para></listitem>
9411 </itemizedlist>
9412 </para>
9413
9414 <para>
9415 In summary, the OpenEmbedded build system does not track the
9416 history of binary package versions for this purpose.
9417 <filename>AUTOINC</filename>, in this case, is comparable to
9418 <filename>PR</filename>.
9419 If PR server is not enabled, <filename>AUTOINC</filename>
9420 in the package version is simply replaced by "0".
9421 If PR server is enabled, the build system keeps track of the
9422 package versions and bumps the number when the package
9423 revision changes.
9424 </para>
9425 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009426 </section>
9427
9428 <section id='handling-optional-module-packaging'>
9429 <title>Handling Optional Module Packaging</title>
9430
9431 <para>
9432 Many pieces of software split functionality into optional
Brad Bishopc342db32019-05-15 21:57:59 -04009433 modules (or plugins) and the plugins that are built
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009434 might depend on configuration options.
9435 To avoid having to duplicate the logic that determines what
9436 modules are available in your recipe or to avoid having
9437 to package each module by hand, the OpenEmbedded build system
9438 provides functionality to handle module packaging dynamically.
9439 </para>
9440
9441 <para>
9442 To handle optional module packaging, you need to do two things:
9443 <itemizedlist>
9444 <listitem><para>Ensure the module packaging is actually
9445 done.</para></listitem>
9446 <listitem><para>Ensure that any dependencies on optional
9447 modules from other recipes are satisfied by your recipe.
9448 </para></listitem>
9449 </itemizedlist>
9450 </para>
9451
9452 <section id='making-sure-the-packaging-is-done'>
9453 <title>Making Sure the Packaging is Done</title>
9454
9455 <para>
9456 To ensure the module packaging actually gets done, you use
9457 the <filename>do_split_packages</filename> function within
9458 the <filename>populate_packages</filename> Python function
9459 in your recipe.
9460 The <filename>do_split_packages</filename> function
9461 searches for a pattern of files or directories under a
9462 specified path and creates a package for each one it finds
9463 by appending to the
9464 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9465 variable and setting the appropriate values for
9466 <filename>FILES_packagename</filename>,
9467 <filename>RDEPENDS_packagename</filename>,
9468 <filename>DESCRIPTION_packagename</filename>, and so forth.
9469 Here is an example from the <filename>lighttpd</filename>
9470 recipe:
9471 <literallayout class='monospaced'>
9472 python populate_packages_prepend () {
9473 lighttpd_libdir = d.expand('${libdir}')
9474 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9475 'lighttpd-module-%s', 'Lighttpd module for %s',
9476 extra_depends='')
9477 }
9478 </literallayout>
9479 The previous example specifies a number of things in the
9480 call to <filename>do_split_packages</filename>.
9481 <itemizedlist>
9482 <listitem><para>A directory within the files installed
9483 by your recipe through <filename>do_install</filename>
9484 in which to search.</para></listitem>
9485 <listitem><para>A regular expression used to match module
9486 files in that directory.
9487 In the example, note the parentheses () that mark
9488 the part of the expression from which the module
9489 name should be derived.</para></listitem>
9490 <listitem><para>A pattern to use for the package names.
9491 </para></listitem>
9492 <listitem><para>A description for each package.
9493 </para></listitem>
9494 <listitem><para>An empty string for
9495 <filename>extra_depends</filename>, which disables
9496 the default dependency on the main
9497 <filename>lighttpd</filename> package.
9498 Thus, if a file in <filename>${libdir}</filename>
9499 called <filename>mod_alias.so</filename> is found,
9500 a package called <filename>lighttpd-module-alias</filename>
9501 is created for it and the
9502 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9503 is set to "Lighttpd module for alias".</para></listitem>
9504 </itemizedlist>
9505 </para>
9506
9507 <para>
9508 Often, packaging modules is as simple as the previous
9509 example.
9510 However, more advanced options exist that you can use
9511 within <filename>do_split_packages</filename> to modify its
9512 behavior.
9513 And, if you need to, you can add more logic by specifying
9514 a hook function that is called for each package.
9515 It is also perfectly acceptable to call
9516 <filename>do_split_packages</filename> multiple times if
9517 you have more than one set of modules to package.
9518 </para>
9519
9520 <para>
9521 For more examples that show how to use
9522 <filename>do_split_packages</filename>, see the
9523 <filename>connman.inc</filename> file in the
9524 <filename>meta/recipes-connectivity/connman/</filename>
9525 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009526 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009527 You can also find examples in
9528 <filename>meta/classes/kernel.bbclass</filename>.
9529 </para>
9530
9531 <para>
9532 Following is a reference that shows
9533 <filename>do_split_packages</filename> mandatory and
9534 optional arguments:
9535 <literallayout class='monospaced'>
9536 Mandatory arguments
9537
9538 root
9539 The path in which to search
9540 file_regex
9541 Regular expression to match searched files.
9542 Use parentheses () to mark the part of this
9543 expression that should be used to derive the
9544 module name (to be substituted where %s is
9545 used in other function arguments as noted below)
9546 output_pattern
9547 Pattern to use for the package names. Must
9548 include %s.
9549 description
9550 Description to set for each package. Must
9551 include %s.
9552
9553 Optional arguments
9554
9555 postinst
9556 Postinstall script to use for all packages
9557 (as a string)
9558 recursive
9559 True to perform a recursive search - default
9560 False
9561 hook
9562 A hook function to be called for every match.
9563 The function will be called with the following
9564 arguments (in the order listed):
9565
9566 f
9567 Full path to the file/directory match
9568 pkg
9569 The package name
9570 file_regex
9571 As above
9572 output_pattern
9573 As above
9574 modulename
9575 The module name derived using file_regex
9576
9577 extra_depends
9578 Extra runtime dependencies (RDEPENDS) to be
9579 set for all packages. The default value of None
9580 causes a dependency on the main package
9581 (${PN}) - if you do not want this, pass empty
9582 string '' for this parameter.
9583 aux_files_pattern
9584 Extra item(s) to be added to FILES for each
9585 package. Can be a single string item or a list
9586 of strings for multiple items. Must include %s.
9587 postrm
9588 postrm script to use for all packages (as a
9589 string)
9590 allow_dirs
9591 True to allow directories to be matched -
9592 default False
9593 prepend
9594 If True, prepend created packages to PACKAGES
9595 instead of the default False which appends them
9596 match_path
9597 match file_regex on the whole relative path to
9598 the root rather than just the file name
9599 aux_files_pattern_verbatim
9600 Extra item(s) to be added to FILES for each
9601 package, using the actual derived module name
9602 rather than converting it to something legal
9603 for a package name. Can be a single string item
9604 or a list of strings for multiple items. Must
9605 include %s.
9606 allow_links
9607 True to allow symlinks to be matched - default
9608 False
9609 summary
9610 Summary to set for each package. Must include %s;
9611 defaults to description if not set.
9612 </literallayout>
9613 </para>
9614 </section>
9615
9616 <section id='satisfying-dependencies'>
9617 <title>Satisfying Dependencies</title>
9618
9619 <para>
9620 The second part for handling optional module packaging
9621 is to ensure that any dependencies on optional modules
9622 from other recipes are satisfied by your recipe.
9623 You can be sure these dependencies are satisfied by
9624 using the
9625 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9626 Here is an example that continues with the
9627 <filename>lighttpd</filename> recipe shown earlier:
9628 <literallayout class='monospaced'>
9629 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9630 </literallayout>
9631 The name specified in the regular expression can of
9632 course be anything.
9633 In this example, it is <filename>lighttpd-module-</filename>
9634 and is specified as the prefix to ensure that any
9635 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9636 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9637 on a package name starting with the prefix are satisfied
9638 during build time.
9639 If you are using <filename>do_split_packages</filename>
9640 as described in the previous section, the value you put in
9641 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9642 the name pattern specified in the call to
9643 <filename>do_split_packages</filename>.
9644 </para>
9645 </section>
9646 </section>
9647
9648 <section id='using-runtime-package-management'>
9649 <title>Using Runtime Package Management</title>
9650
9651 <para>
9652 During a build, BitBake always transforms a recipe into one or
9653 more packages.
9654 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009655 and produces a number of packages (e.g.
9656 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9657 <filename>bash-completion</filename>,
9658 <filename>bash-completion-dbg</filename>,
9659 <filename>bash-completion-dev</filename>,
9660 <filename>bash-completion-extra</filename>,
9661 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009662 Not all generated packages are included in an image.
9663 </para>
9664
9665 <para>
9666 In several situations, you might need to update, add, remove,
9667 or query the packages on a target device at runtime
9668 (i.e. without having to generate a new image).
9669 Examples of such situations include:
9670 <itemizedlist>
9671 <listitem><para>
9672 You want to provide in-the-field updates to deployed
9673 devices (e.g. security updates).
9674 </para></listitem>
9675 <listitem><para>
9676 You want to have a fast turn-around development cycle
9677 for one or more applications that run on your device.
9678 </para></listitem>
9679 <listitem><para>
9680 You want to temporarily install the "debug" packages
9681 of various applications on your device so that
9682 debugging can be greatly improved by allowing
9683 access to symbols and source debugging.
9684 </para></listitem>
9685 <listitem><para>
9686 You want to deploy a more minimal package selection of
9687 your device but allow in-the-field updates to add a
9688 larger selection for customization.
9689 </para></listitem>
9690 </itemizedlist>
9691 </para>
9692
9693 <para>
9694 In all these situations, you have something similar to a more
9695 traditional Linux distribution in that in-field devices
9696 are able to receive pre-compiled packages from a server for
9697 installation or update.
9698 Being able to install these packages on a running,
9699 in-field device is what is termed "runtime package
9700 management".
9701 </para>
9702
9703 <para>
9704 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009705 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009706 packages plus the required metadata.
9707 You also need package manipulation tools on the target.
9708 The build machine is a likely candidate to act as the server.
9709 However, that machine does not necessarily have to be the
9710 package server.
9711 The build machine could push its artifacts to another machine
9712 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009713 In fact, doing so is advantageous for a production
9714 environment as getting the packages away from the
9715 development system's build directory prevents accidental
9716 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009717 </para>
9718
9719 <para>
9720 A simple build that targets just one device produces
9721 more than one package database.
9722 In other words, the packages produced by a build are separated
9723 out into a couple of different package groupings based on
9724 criteria such as the target's CPU architecture, the target
9725 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009726 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009727 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009728 <filename>noarch</filename>, <filename>i586</filename>, and
9729 <filename>qemux86</filename>.
9730 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009731 aware of all the packages that were available to it,
9732 you would need to point it to each of these databases
9733 individually.
9734 In a similar way, a traditional Linux distribution usually is
9735 configured to be aware of a number of software repositories
9736 from which it retrieves packages.
9737 </para>
9738
9739 <para>
9740 Using runtime package management is completely optional and
9741 not required for a successful build or deployment in any
9742 way.
9743 But if you want to make use of runtime package management,
9744 you need to do a couple things above and beyond the basics.
9745 The remainder of this section describes what you need to do.
9746 </para>
9747
9748 <section id='runtime-package-management-build'>
9749 <title>Build Considerations</title>
9750
9751 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009752 This section describes build considerations of which you
9753 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009754 package management.
9755 </para>
9756
9757 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009758 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009759 what format or formats to use.
9760 In your configuration, you use the
9761 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009762 variable to specify the format:
9763 <orderedlist>
9764 <listitem><para>
9765 Open the <filename>local.conf</filename> file
9766 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009767 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009768 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9769 </para></listitem>
9770 <listitem><para>
9771 Select the desired package format as follows:
9772 <literallayout class='monospaced'>
9773 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9774 </literallayout>
9775 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009776 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009777 supported package formats.
9778 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009779 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009780 different package formats, you can set the
9781 variable with more than one argument.
9782 However, the OpenEmbedded build system only
9783 uses the first argument when creating an image
9784 or Software Development Kit (SDK).
9785 </note>
9786 </para></listitem>
9787 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009788 </para>
9789
9790 <para>
9791 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009792 package database containing the packages in your current
9793 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009794 target for runtime package management, you can include
9795 "package-management" in the
9796 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9797 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009798 Including "package-management" in this configuration
9799 variable ensures that when the image is assembled for your
9800 target, the image includes the currently-known package
9801 databases as well as the target-specific tools required
9802 for runtime package management to be performed on the
9803 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009804 However, this is not strictly necessary.
9805 You could start your image off without any databases
9806 but only include the required on-target package
9807 tool(s).
9808 As an example, you could include "opkg" in your
9809 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9810 variable if you are using the IPK package format.
9811 You can then initialize your target's package database(s)
9812 later once your image is up and running.
9813 </para>
9814
9815 <para>
9816 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009817 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009818 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009819 package index after the build by using the following
9820 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009821 <literallayout class='monospaced'>
9822 $ bitbake package-index
9823 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009824 It might be tempting to build the package and the
9825 package index at the same time with a command such as
9826 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009827 <literallayout class='monospaced'>
9828 $ bitbake <replaceable>some-package</replaceable> package-index
9829 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009830 Do not do this as BitBake does not schedule the package
9831 index for after the completion of the package you are
9832 building.
9833 Consequently, you cannot be sure of the package index
9834 including information for the package you just built.
9835 Thus, be sure to run the package update step separately
9836 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009837 </para>
9838
9839 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009840 You can use the
9841 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9842 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9843 and
9844 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9845 variables to pre-configure target images to use a package
9846 feed.
9847 If you do not define these variables, then manual steps
9848 as described in the subsequent sections are necessary to
9849 configure the target.
9850 You should set these variables before building the image
9851 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009852 </para>
9853
9854 <para>
9855 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009856 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009857 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009858 For example, if
9859 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009860 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009861 is RPM, then your RPM packages are available in
9862 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009863 </para>
9864 </section>
9865
9866 <section id='runtime-package-management-server'>
9867 <title>Host or Server Machine Setup</title>
9868
9869 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009870 Although other protocols are possible, a server using HTTP
9871 typically serves packages.
9872 If you want to use HTTP, then set up and configure a
9873 web server such as Apache 2, lighttpd, or
9874 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009875 </para>
9876
9877 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009878 To keep things simple, this section describes how to set
9879 up a SimpleHTTPServer web server to share package feeds
9880 from the developer's machine.
9881 Although this server might not be the best for a production
9882 environment, the setup is simple and straight forward.
9883 Should you want to use a different server more suited for
9884 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9885 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009886 </para>
9887
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009888 <para>
9889 From within the build directory where you have built an
9890 image based on your packaging choice (i.e. the
9891 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9892 setting), simply start the server.
9893 The following example assumes a build directory of
9894 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9895 <filename>PACKAGE_CLASSES</filename> setting of
9896 "package_rpm":
9897 <literallayout class='monospaced'>
9898 $ cd ~/poky/build/tmp/deploy/rpm
9899 $ python -m SimpleHTTPServer
9900 </literallayout>
9901 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009902 </section>
9903
9904 <section id='runtime-package-management-target'>
9905 <title>Target Setup</title>
9906
9907 <para>
9908 Setting up the target differs depending on the
9909 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009910 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009911 </para>
9912
9913 <section id='runtime-package-management-target-rpm'>
9914 <title>Using RPM</title>
9915
9916 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009917 The
9918 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9919 (DNF) performs runtime package management of RPM
9920 packages.
9921 In order to use DNF for runtime package management,
9922 you must perform an initial setup on the target
9923 machine for cases where the
9924 <filename>PACKAGE_FEED_*</filename> variables were not
9925 set as part of the image that is running on the
9926 target.
9927 This means if you built your image and did not not use
9928 these variables as part of the build and your image is
9929 now running on the target, you need to perform the
9930 steps in this section if you want to use runtime
9931 package management.
9932 <note>
9933 For information on the
9934 <filename>PACKAGE_FEED_*</filename> variables, see
9935 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9936 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9937 and
9938 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9939 in the Yocto Project Reference Manual variables
9940 glossary.
9941 </note>
9942 </para>
9943
9944 <para>
9945 On the target, you must inform DNF that package
9946 databases are available.
9947 You do this by creating a file named
9948 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9949 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009950 </para>
9951
9952 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009953 As an example, assume the target is able to use the
9954 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009955 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009956 and <filename>qemux86</filename> from a server named
9957 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009958 The specifics for setting up the web server are up to
9959 you.
9960 The critical requirement is that the URIs in the
9961 target repository configuration point to the
9962 correct remote location for the feeds.
9963 <note><title>Tip</title>
9964 For development purposes, you can point the web
9965 server to the build system's
9966 <filename>deploy</filename> directory.
9967 However, for production use, it is better to copy
9968 the package directories to a location outside of
9969 the build area and use that location.
9970 Doing so avoids situations where the build system
9971 overwrites or changes the
9972 <filename>deploy</filename> directory.
9973 </note>
9974 </para>
9975
9976 <para>
9977 When telling DNF where to look for the package
9978 databases, you must declare individual locations
9979 per architecture or a single location used for all
9980 architectures.
9981 You cannot do both:
9982 <itemizedlist>
9983 <listitem><para>
9984 <emphasis>Create an Explicit List of Architectures:</emphasis>
9985 Define individual base URLs to identify where
9986 each package database is located:
9987 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009988 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009989 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009990 </literallayout>
9991 This example informs DNF about individual
9992 package databases for all three architectures.
9993 </para></listitem>
9994 <listitem><para>
9995 <emphasis>Create a Single (Full) Package Index:</emphasis>
9996 Define a single base URL that identifies where
9997 a full package database is located:
9998 <literallayout class='monospaced'>
9999 [oe-packages]
10000 baseurl=http://my.server/rpm
10001 </literallayout>
10002 This example informs DNF about a single package
10003 database that contains all the package index
10004 information for all supported architectures.
10005 </para></listitem>
10006 </itemizedlist>
10007 </para>
10008
10009 <para>
10010 Once you have informed DNF where to find the package
10011 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010012 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010013 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010014 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010015 DNF is now able to find, install, and upgrade packages
10016 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010017 <note>
10018 See the
10019 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
10020 for additional information.
10021 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010022 </para>
10023 </section>
10024
10025 <section id='runtime-package-management-target-ipk'>
10026 <title>Using IPK</title>
10027
10028 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010029 The <filename>opkg</filename> application performs
10030 runtime package management of IPK packages.
10031 You must perform an initial setup for
10032 <filename>opkg</filename> on the target machine
10033 if the
10034 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10035 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10036 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10037 variables have not been set or the target image was
10038 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010039 </para>
10040
10041 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010042 The <filename>opkg</filename> application uses
10043 configuration files to find available package
10044 databases.
10045 Thus, you need to create a configuration file inside
10046 the <filename>/etc/opkg/</filename> direction, which
10047 informs <filename>opkg</filename> of any repository
10048 you want to use.
10049 </para>
10050
10051 <para>
10052 As an example, suppose you are serving packages from a
10053 <filename>ipk/</filename> directory containing the
10054 <filename>i586</filename>,
10055 <filename>all</filename>, and
10056 <filename>qemux86</filename> databases through an
10057 HTTP server named <filename>my.server</filename>.
10058 On the target, create a configuration file
10059 (e.g. <filename>my_repo.conf</filename>) inside the
10060 <filename>/etc/opkg/</filename> directory containing
10061 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010062 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010063 src/gz all http://my.server/ipk/all
10064 src/gz i586 http://my.server/ipk/i586
10065 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010066 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010067 Next, instruct <filename>opkg</filename> to fetch
10068 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010069 <literallayout class='monospaced'>
10070 # opkg update
10071 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010072 The <filename>opkg</filename> application is now able
10073 to find, install, and upgrade packages from the
10074 specified repository.
10075 </para>
10076 </section>
10077
10078 <section id='runtime-package-management-target-deb'>
10079 <title>Using DEB</title>
10080
10081 <para>
10082 The <filename>apt</filename> application performs
10083 runtime package management of DEB packages.
10084 This application uses a source list file to find
10085 available package databases.
10086 You must perform an initial setup for
10087 <filename>apt</filename> on the target machine
10088 if the
10089 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10090 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10091 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10092 variables have not been set or the target image was
10093 built before the variables were set.
10094 </para>
10095
10096 <para>
10097 To inform <filename>apt</filename> of the repository
10098 you want to use, you might create a list file (e.g.
10099 <filename>my_repo.list</filename>) inside the
10100 <filename>/etc/apt/sources.list.d/</filename>
10101 directory.
10102 As an example, suppose you are serving packages from a
10103 <filename>deb/</filename> directory containing the
10104 <filename>i586</filename>,
10105 <filename>all</filename>, and
10106 <filename>qemux86</filename> databases through an
10107 HTTP server named <filename>my.server</filename>.
10108 The list file should contain:
10109 <literallayout class='monospaced'>
10110 deb http://my.server/deb/all ./
10111 deb http://my.server/deb/i586 ./
10112 deb http://my.server/deb/qemux86 ./
10113 </literallayout>
10114 Next, instruct the <filename>apt</filename>
10115 application to fetch the repository information:
10116 <literallayout class='monospaced'>
10117 # apt-get update
10118 </literallayout>
10119 After this step, <filename>apt</filename> is able
10120 to find, install, and upgrade packages from the
10121 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010122 </para>
10123 </section>
10124 </section>
10125 </section>
10126
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010127 <section id='generating-and-using-signed-packages'>
10128 <title>Generating and Using Signed Packages</title>
10129 <para>
10130 In order to add security to RPM packages used during a build,
10131 you can take steps to securely sign them.
10132 Once a signature is verified, the OpenEmbedded build system
10133 can use the package in the build.
10134 If security fails for a signed package, the build system
10135 aborts the build.
10136 </para>
10137
10138 <para>
10139 This section describes how to sign RPM packages during a build
10140 and how to use signed package feeds (repositories) when
10141 doing a build.
10142 </para>
10143
10144 <section id='signing-rpm-packages'>
10145 <title>Signing RPM Packages</title>
10146
10147 <para>
10148 To enable signing RPM packages, you must set up the
10149 following configurations in either your
10150 <filename>local.config</filename> or
10151 <filename>distro.config</filename> file:
10152 <literallayout class='monospaced'>
10153 # Inherit sign_rpm.bbclass to enable signing functionality
10154 INHERIT += " sign_rpm"
10155 # Define the GPG key that will be used for signing.
10156 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
10157 # Provide passphrase for the key
10158 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
10159 </literallayout>
10160 <note>
10161 Be sure to supply appropriate values for both
10162 <replaceable>key_name</replaceable> and
10163 <replaceable>passphrase</replaceable>
10164 </note>
10165 Aside from the
10166 <filename>RPM_GPG_NAME</filename> and
10167 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
10168 previous example, two optional variables related to signing
10169 exist:
10170 <itemizedlist>
10171 <listitem><para>
10172 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10173 Specifies a <filename>gpg</filename> binary/wrapper
10174 that is executed when the package is signed.
10175 </para></listitem>
10176 <listitem><para>
10177 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10178 Specifies the <filename>gpg</filename> home
10179 directory used when the package is signed.
10180 </para></listitem>
10181 </itemizedlist>
10182 </para>
10183 </section>
10184
10185 <section id='processing-package-feeds'>
10186 <title>Processing Package Feeds</title>
10187
10188 <para>
10189 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010190 also enable signed package feeds for IPK and RPM packages.
10191 </para>
10192
10193 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010194 The steps you need to take to enable signed package feed
10195 use are similar to the steps used to sign RPM packages.
10196 You must define the following in your
10197 <filename>local.config</filename> or
10198 <filename>distro.config</filename> file:
10199 <literallayout class='monospaced'>
10200 INHERIT += "sign_package_feed"
10201 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10202 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10203 </literallayout>
10204 For signed package feeds, the passphrase must exist in a
10205 separate file, which is pointed to by the
10206 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10207 variable.
10208 Regarding security, keeping a plain text passphrase out of
10209 the configuration is more secure.
10210 </para>
10211
10212 <para>
10213 Aside from the
10214 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10215 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10216 variables, three optional variables related to signed
10217 package feeds exist:
10218 <itemizedlist>
10219 <listitem><para>
10220 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10221 Specifies a <filename>gpg</filename> binary/wrapper
10222 that is executed when the package is signed.
10223 </para></listitem>
10224 <listitem><para>
10225 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10226 Specifies the <filename>gpg</filename> home
10227 directory used when the package is signed.
10228 </para></listitem>
10229 <listitem><para>
10230 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10231 Specifies the type of <filename>gpg</filename>
10232 signature.
10233 This variable applies only to RPM and IPK package
10234 feeds.
10235 Allowable values for the
10236 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10237 are "ASC", which is the default and specifies ascii
10238 armored, and "BIN", which specifies binary.
10239 </para></listitem>
10240 </itemizedlist>
10241 </para>
10242 </section>
10243 </section>
10244
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010245 <section id='testing-packages-with-ptest'>
10246 <title>Testing Packages With ptest</title>
10247
10248 <para>
10249 A Package Test (ptest) runs tests against packages built
10250 by the OpenEmbedded build system on the target machine.
10251 A ptest contains at least two items: the actual test, and
10252 a shell script (<filename>run-ptest</filename>) that starts
10253 the test.
10254 The shell script that starts the test must not contain
10255 the actual test - the script only starts the test.
10256 On the other hand, the test can be anything from a simple
10257 shell script that runs a binary and checks the output to
10258 an elaborate system of test binaries and data files.
10259 </para>
10260
10261 <para>
10262 The test generates output in the format used by
10263 Automake:
10264 <literallayout class='monospaced'>
10265 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10266 </literallayout>
10267 where the result can be <filename>PASS</filename>,
10268 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10269 and the testname can be any identifying string.
10270 </para>
10271
10272 <para>
10273 For a list of Yocto Project recipes that are already
10274 enabled with ptest, see the
10275 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10276 wiki page.
10277 <note>
10278 A recipe is "ptest-enabled" if it inherits the
10279 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10280 class.
10281 </note>
10282 </para>
10283
10284 <section id='adding-ptest-to-your-build'>
10285 <title>Adding ptest to Your Build</title>
10286
10287 <para>
10288 To add package testing to your build, add the
10289 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10290 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10291 variables to your <filename>local.conf</filename> file,
10292 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010293 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010294 <literallayout class='monospaced'>
10295 DISTRO_FEATURES_append = " ptest"
10296 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10297 </literallayout>
10298 Once your build is complete, the ptest files are installed
10299 into the
10300 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10301 directory within the image, where
10302 <filename><replaceable>package</replaceable></filename>
10303 is the name of the package.
10304 </para>
10305 </section>
10306
10307 <section id='running-ptest'>
10308 <title>Running ptest</title>
10309
10310 <para>
10311 The <filename>ptest-runner</filename> package installs a
10312 shell script that loops through all installed ptest test
10313 suites and runs them in sequence.
10314 Consequently, you might want to add this package to
10315 your image.
10316 </para>
10317 </section>
10318
10319 <section id='getting-your-package-ready'>
10320 <title>Getting Your Package Ready</title>
10321
10322 <para>
10323 In order to enable a recipe to run installed ptests
10324 on target hardware,
10325 you need to prepare the recipes that build the packages
10326 you want to test.
10327 Here is what you have to do for each recipe:
10328 <itemizedlist>
10329 <listitem><para><emphasis>Be sure the recipe
10330 inherits the
10331 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10332 class:</emphasis>
10333 Include the following line in each recipe:
10334 <literallayout class='monospaced'>
10335 inherit ptest
10336 </literallayout>
10337 </para></listitem>
10338 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10339 This script starts your test.
10340 Locate the script where you will refer to it
10341 using
10342 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10343 Here is an example that starts a test for
10344 <filename>dbus</filename>:
10345 <literallayout class='monospaced'>
10346 #!/bin/sh
10347 cd test
10348 make -k runtest-TESTS
10349 </literallayout>
10350 </para></listitem>
10351 <listitem><para><emphasis>Ensure dependencies are
10352 met:</emphasis>
10353 If the test adds build or runtime dependencies
10354 that normally do not exist for the package
10355 (such as requiring "make" to run the test suite),
10356 use the
10357 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10358 and
10359 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10360 variables in your recipe in order for the package
10361 to meet the dependencies.
10362 Here is an example where the package has a runtime
10363 dependency on "make":
10364 <literallayout class='monospaced'>
10365 RDEPENDS_${PN}-ptest += "make"
10366 </literallayout>
10367 </para></listitem>
10368 <listitem><para><emphasis>Add a function to build the
10369 test suite:</emphasis>
10370 Not many packages support cross-compilation of
10371 their test suites.
10372 Consequently, you usually need to add a
10373 cross-compilation function to the package.
10374 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010375
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010376 <para>Many packages based on Automake compile and
10377 run the test suite by using a single command
10378 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010379 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010380 builds and runs on the same computer, while
10381 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010382 on the host but executed for the target
10383 architecture (though often, as in the case for
10384 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010385 The built version of Automake that ships with the
10386 Yocto Project includes a patch that separates
10387 building and execution.
10388 Consequently, packages that use the unaltered,
10389 patched version of <filename>make check</filename>
10390 automatically cross-compiles.</para>
10391 <para>Regardless, you still must add a
10392 <filename>do_compile_ptest</filename> function to
10393 build the test suite.
10394 Add a function similar to the following to your
10395 recipe:
10396 <literallayout class='monospaced'>
10397 do_compile_ptest() {
10398 oe_runmake buildtest-TESTS
10399 }
10400 </literallayout>
10401 </para></listitem>
10402 <listitem><para><emphasis>Ensure special configurations
10403 are set:</emphasis>
10404 If the package requires special configurations
10405 prior to compiling the test code, you must
10406 insert a <filename>do_configure_ptest</filename>
10407 function into the recipe.
10408 </para></listitem>
10409 <listitem><para><emphasis>Install the test
10410 suite:</emphasis>
10411 The <filename>ptest</filename> class
10412 automatically copies the file
10413 <filename>run-ptest</filename> to the target and
10414 then runs make <filename>install-ptest</filename>
10415 to run the tests.
10416 If this is not enough, you need to create a
10417 <filename>do_install_ptest</filename> function and
10418 make sure it gets called after the
10419 "make install-ptest" completes.
10420 </para></listitem>
10421 </itemizedlist>
10422 </para>
10423 </section>
10424 </section>
Brad Bishop15ae2502019-06-18 21:44:24 -040010425
10426 <section id='creating-node-package-manager-npm-packages'>
10427 <title>Creating Node Package Manager (NPM) Packages</title>
10428
10429 <para>
10430 <ulink url='https://en.wikipedia.org/wiki/Npm_(software)'>NPM</ulink>
10431 is a package manager for the JavaScript programming
10432 language.
10433 The Yocto Project supports the NPM
10434 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>.
10435 You can use this fetcher in combination with
10436 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>
10437 to create recipes that produce NPM packages.
10438 </para>
10439
10440 <para>
10441 Two workflows exist that allow you to create NPM packages
10442 using <filename>devtool</filename>: the NPM registry modules
10443 method and the NPM project code method.
10444 <note>
10445 While it is possible to create NPM recipes manually,
10446 using <filename>devtool</filename> is far simpler.
10447 </note>
10448 Additionally, some requirements and caveats exist.
10449 </para>
10450
10451 <section id='npm-package-creation-requirements'>
10452 <title>Requirements and Caveats</title>
10453
10454 <para>
10455 You need to be aware of the following before using
10456 <filename>devtool</filename> to create NPM packages:
10457 <itemizedlist>
10458 <listitem><para>
10459 Of the two methods that you can use
10460 <filename>devtool</filename> to create NPM
10461 packages, the registry approach is slightly
10462 simpler.
10463 However, you might consider the project
10464 approach because you do not have to publish
10465 your module in the NPM registry
10466 (<ulink url='https://docs.npmjs.com/misc/registry'><filename>npm-registry</filename></ulink>),
10467 which is NPM's public registry.
10468 </para></listitem>
10469 <listitem><para>
10470 Be familiar with
10471 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>.
10472 </para></listitem>
10473 <listitem><para>
10474 The NPM host tools need the native
10475 <filename>nodejs-npm</filename> package, which
10476 is part of the OpenEmbedded environment.
10477 You need to get the package by cloning the
10478 <ulink url='https://github.com/openembedded/meta-openembedded'></ulink>
10479 repository out of GitHub.
10480 Be sure to add the path to your local copy to
10481 your <filename>bblayers.conf</filename> file.
10482 </para></listitem>
10483 <listitem><para>
10484 <filename>devtool</filename> cannot detect
10485 native libraries in module dependencies.
10486 Consequently, you must manually add packages
10487 to your recipe.
10488 </para></listitem>
10489 <listitem><para>
10490 While deploying NPM packages,
10491 <filename>devtool</filename> cannot determine
10492 which dependent packages are missing on the
10493 target (e.g. the node runtime
10494 <filename>nodejs</filename>).
10495 Consequently, you need to find out what
10496 files are missing and be sure they are on the
10497 target.
10498 </para></listitem>
10499 <listitem><para>
10500 Although you might not need NPM to run your
10501 node package, it is useful to have NPM on your
10502 target.
10503 The NPM package name is
10504 <filename>nodejs-npm</filename>.
10505 </para></listitem>
10506 </itemizedlist>
10507 </para>
10508 </section>
10509
10510 <section id='npm-using-the-registry-modules-method'>
10511 <title>Using the Registry Modules Method</title>
10512
10513 <para>
10514 This section presents an example that uses the
10515 <filename>cute-files</filename> module, which is a
10516 file browser web application.
10517 <note>
10518 You must know the <filename>cute-files</filename>
10519 module version.
10520 </note>
10521 </para>
10522
10523 <para>
10524 The first thing you need to do is use
10525 <filename>devtool</filename> and the NPM fetcher to
10526 create the recipe:
10527 <literallayout class='monospaced'>
10528 $ devtool add "npm://registry.npmjs.org;name=cute-files;version=1.0.2"
10529 </literallayout>
10530 The <filename>devtool add</filename> command runs
10531 <filename>recipetool create</filename> and uses the
10532 same fetch URI to download each dependency and capture
10533 license details where possible.
10534 The result is a generated recipe.
10535 </para>
10536
10537 <para>
10538 The recipe file is fairly simple and contains every
10539 license that <filename>recipetool</filename> finds
10540 and includes the licenses in the recipe's
10541 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
10542 variables.
10543 You need to examine the variables and look for those
10544 with "unknown" in the
10545 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
10546 field.
10547 You need to track down the license information for
10548 "unknown" modules and manually add the information to the
10549 recipe.
10550 </para>
10551
10552 <para>
10553 <filename>recipetool</filename> creates "shrinkwrap" and
10554 "lockdown" files for your recipe.
10555 Shrinkwrap files capture the version of all dependent
10556 modules.
10557 Many packages do not provide shrinkwrap files.
10558 <filename>recipetool</filename> create a shrinkwrap
10559 file as it runs.
10560 You can replace the shrinkwrap file with your own file
10561 by setting the <filename>NPM_SHRINKWRAP</filename>
10562 variable.
10563 </para>
10564
10565 <para>
10566 Lockdown files contain the checksum for each module
10567 to determine if your users download the same files when
10568 building with a recipe.
10569 Lockdown files ensure that dependencies have not been
10570 changed and that your NPM registry is still providing
10571 the same file.
10572 <note>
10573 A package is created for each sub-module.
10574 This policy is the only practical way to have the
10575 licenses for all of the dependencies represented
10576 in the license manifest of the image.
10577 </note>
10578 </para>
10579
10580 <para>
10581 The <filename>devtool edit-recipe</filename> command
10582 lets you take a look at the recipe:
10583 <literallayout class='monospaced'>
10584 $ devtool edit-recipe cute-files
10585 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
10586 LICENSE = "BSD-3-Clause &amp; Unknown &amp; MIT &amp; ISC"
10587 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
10588 file://node_modules/content-disposition/LICENSE;md5=c6e0ce1e688c5ff16db06b7259e9cd20 \
10589 file://node_modules/express/LICENSE;md5=5513c00a5c36cd361da863dd9aa8875d \
10590 ...
10591
10592 SRC_URI = "npm://registry.npmjs.org;name=cute-files;version=${PV}"
10593 NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json"
10594 NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"
10595 inherit npm
10596 # Must be set after inherit npm since that itself sets S
10597 S = "${WORKDIR}/npmpkg"
10598
10599 LICENSE_${PN}-content-disposition = "MIT"
10600 ...
10601 LICENSE_${PN}-express = "MIT"
10602 LICENSE_${PN} = "MIT"
10603 </literallayout>
10604 Three key points exist in the previous example:
10605 <itemizedlist>
10606 <listitem><para>
10607 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10608 uses the NPM scheme so that the NPM fetcher
10609 is used.
10610 </para></listitem>
10611 <listitem><para>
10612 <filename>recipetool</filename> collects all
10613 the license information.
10614 If a sub-module's license is unavailable,
10615 the sub-module's name appears in the comments.
10616 </para></listitem>
10617 <listitem><para>
10618 The <filename>inherit npm</filename> statement
10619 causes the
10620 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-npm'><filename>npm</filename></ulink>
10621 class to package up all the modules.
10622 </para></listitem>
10623 </itemizedlist>
10624 </para>
10625
10626 <para>
10627 You can run the following command to build the
10628 <filename>cute-files</filename> package:
10629 <literallayout class='monospaced'>
10630 $ devtool build cute-files
10631 </literallayout>
10632 Remember that <filename>nodejs</filename> must be
10633 installed on the target before your package.
10634 </para>
10635
10636 <para>
10637 Assuming 192.168.7.2 for the target's IP address, use
10638 the following command to deploy your package:
10639 <literallayout class='monospaced'>
10640 $ devtool deploy-target -s cute-files root@192.168.7.2
10641 </literallayout>
10642 Once the package is installed on the target, you can
10643 test the application:
10644 <note>
10645 Because of a know issue, you cannot simply run
10646 <filename>cute-files</filename> as you would if you
10647 had run <filename>npm install</filename>.
10648 </note>
10649 <literallayout class='monospaced'>
10650 $ cd /usr/lib/node_modules/cute-files
10651 $ node cute-files.js
10652 </literallayout>
10653 On a browser, go to
10654 <filename>http://192.168.7.2:3000</filename> and you
10655 see the following:
10656 <imagedata fileref="figures/cute-files-npm-example.png" align="center" width="6in" depth="4in" />
10657 </para>
10658
10659 <para>
10660 You can find the recipe in
10661 <filename>workspace/recipes/cute-files</filename>.
10662 You can use the recipe in any layer you choose.
10663 </para>
10664 </section>
10665
10666 <section id='npm-using-the-npm-projects-method'>
10667 <title>Using the NPM Projects Code Method</title>
10668
10669 <para>
10670 Although it is useful to package modules already in the
10671 NPM registry, adding <filename>node.js</filename> projects
10672 under development is a more common developer use case.
10673 </para>
10674
10675 <para>
10676 This section covers the NPM projects code method, which is
10677 very similar to the "registry" approach described in the
10678 previous section.
10679 In the NPM projects method, you provide
10680 <filename>devtool</filename> with an URL that points to the
10681 source files.
10682 </para>
10683
10684 <para>
10685 Replicating the same example, (i.e.
10686 <filename>cute-files</filename>) use the following command:
10687 <literallayout class='monospaced'>
10688 $ devtool add https://github.com/martinaglv/cute-files.git
10689 </literallayout>
10690 The recipe this command generates is very similar to the
10691 recipe created in the previous section.
10692 However, the <filename>SRC_URI</filename> looks like the
10693 following:
10694 <literallayout class='monospaced'>
10695 SRC_URI = "git://github.com/martinaglv/cute-files.git;protocol=https \
10696 npm://registry.npmjs.org;name=commander;version=2.9.0;subdir=node_modules/commander \
10697 npm://registry.npmjs.org;name=express;version=4.14.0;subdir=node_modules/express \
10698 npm://registry.npmjs.org;name=content-disposition;version=0.3.0;subdir=node_modules/content-disposition \
10699 "
10700 </literallayout>
10701 In this example, the main module is taken from the Git
10702 repository and dependents are taken from the NPM registry.
10703 Other than those differences, the recipe is basically the
10704 same between the two methods.
10705 You can build and deploy the package exactly as described
10706 in the previous section that uses the registry modules
10707 method.
10708 </para>
10709 </section>
10710 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010711 </section>
10712
Brad Bishop316dfdd2018-06-25 12:45:53 -040010713 <section id='efficiently-fetching-source-files-during-a-build'>
10714 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010715
10716 <para>
10717 The OpenEmbedded build system works with source files located
10718 through the
10719 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10720 variable.
10721 When you build something using BitBake, a big part of the operation
10722 is locating and downloading all the source tarballs.
10723 For images, downloading all the source for various packages can
10724 take a significant amount of time.
10725 </para>
10726
10727 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010728 This section shows you how you can use mirrors to speed up
10729 fetching source files and how you can pre-fetch files all of which
10730 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010731 </para>
10732
10733 <section id='setting-up-effective-mirrors'>
10734 <title>Setting up Effective Mirrors</title>
10735
10736 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010737 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010738 build is simply downloading all of the source tarballs.
10739 Maybe you have been working with another build system
10740 (OpenEmbedded or Angstrom) for which you have built up a
10741 sizable directory of source tarballs.
10742 Or, perhaps someone else has such a directory for which you
10743 have read access.
10744 If so, you can save time by adding statements to your
10745 configuration file so that the build process checks local
10746 directories first for existing tarballs before checking the
10747 Internet.
10748 </para>
10749
10750 <para>
10751 Here is an efficient way to set it up in your
10752 <filename>local.conf</filename> file:
10753 <literallayout class='monospaced'>
10754 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10755 INHERIT += "own-mirrors"
10756 BB_GENERATE_MIRROR_TARBALLS = "1"
10757 # BB_NO_NETWORK = "1"
10758 </literallayout>
10759 </para>
10760
10761 <para>
10762 In the previous example, the
10763 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10764 variable causes the OpenEmbedded build system to generate
10765 tarballs of the Git repositories and store them in the
10766 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10767 directory.
10768 Due to performance reasons, generating and storing these
10769 tarballs is not the build system's default behavior.
10770 </para>
10771
10772 <para>
10773 You can also use the
10774 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10775 variable.
10776 For an example, see the variable's glossary entry in the
10777 Yocto Project Reference Manual.
10778 </para>
10779 </section>
10780
10781 <section id='getting-source-files-and-suppressing-the-build'>
10782 <title>Getting Source Files and Suppressing the Build</title>
10783
10784 <para>
10785 Another technique you can use to ready yourself for a
10786 successive string of build operations, is to pre-fetch
10787 all the source files without actually starting a build.
10788 This technique lets you work through any download issues
10789 and ultimately gathers all the source files into your
10790 download directory
10791 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10792 which is located with
10793 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10794 </para>
10795
10796 <para>
10797 Use the following BitBake command form to fetch all the
10798 necessary sources without starting the build:
10799 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010800 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010801 </literallayout>
10802 This variation of the BitBake command guarantees that you
10803 have all the sources for that BitBake target should you
10804 disconnect from the Internet and want to do the build
10805 later offline.
10806 </para>
10807 </section>
10808 </section>
10809
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010810 <section id="selecting-an-initialization-manager">
10811 <title>Selecting an Initialization Manager</title>
10812
10813 <para>
10814 By default, the Yocto Project uses SysVinit as the initialization
10815 manager.
10816 However, support also exists for systemd,
10817 which is a full replacement for init with
10818 parallel starting of services, reduced shell overhead and other
10819 features that are used by many distributions.
10820 </para>
10821
10822 <para>
10823 If you want to use SysVinit, you do
10824 not have to do anything.
10825 But, if you want to use systemd, you must
10826 take some steps as described in the following sections.
10827 </para>
10828
10829 <section id='using-systemd-exclusively'>
10830 <title>Using systemd Exclusively</title>
10831
10832 <para>
Brad Bishop15ae2502019-06-18 21:44:24 -040010833 Set these variables in your distribution configuration
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010834 file as follows:
10835 <literallayout class='monospaced'>
10836 DISTRO_FEATURES_append = " systemd"
10837 VIRTUAL-RUNTIME_init_manager = "systemd"
10838 </literallayout>
10839 You can also prevent the SysVinit
10840 distribution feature from
10841 being automatically enabled as follows:
10842 <literallayout class='monospaced'>
10843 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10844 </literallayout>
10845 Doing so removes any redundant SysVinit scripts.
10846 </para>
10847
10848 <para>
10849 To remove initscripts from your image altogether,
10850 set this variable also:
10851 <literallayout class='monospaced'>
10852 VIRTUAL-RUNTIME_initscripts = ""
10853 </literallayout>
10854 </para>
10855
10856 <para>
10857 For information on the backfill variable, see
10858 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10859 </para>
10860 </section>
10861
10862 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10863 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10864
10865 <para>
10866 Set these variables in your distribution configuration
10867 file as follows:
10868 <literallayout class='monospaced'>
10869 DISTRO_FEATURES_append = " systemd"
10870 VIRTUAL-RUNTIME_init_manager = "systemd"
10871 </literallayout>
10872 Doing so causes your main image to use the
10873 <filename>packagegroup-core-boot.bb</filename> recipe and
10874 systemd.
10875 The rescue/minimal image cannot use this package group.
10876 However, it can install SysVinit
10877 and the appropriate packages will have support for both
10878 systemd and SysVinit.
10879 </para>
10880 </section>
10881 </section>
10882
10883 <section id="selecting-dev-manager">
10884 <title>Selecting a Device Manager</title>
10885
10886 <para>
10887 The Yocto Project provides multiple ways to manage the device
10888 manager (<filename>/dev</filename>):
10889 <itemizedlist>
10890 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10891 For this case, the <filename>/dev</filename> directory
10892 is persistent and the required device nodes are created
10893 during the build.
10894 </para></listitem>
10895 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10896 For this case, the <filename>/dev</filename> directory
10897 is provided by the kernel as an in-memory file system and
10898 is automatically populated by the kernel at runtime.
10899 Additional configuration of device nodes is done in user
10900 space by a device manager like
10901 <filename>udev</filename> or
10902 <filename>busybox-mdev</filename>.
10903 </para></listitem>
10904 </itemizedlist>
10905 </para>
10906
10907 <section id="static-dev-management">
10908 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10909
10910 <para>
10911 To use the static method for device population, you need to
10912 set the
10913 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10914 variable to "0" as follows:
10915 <literallayout class='monospaced'>
10916 USE_DEVFS = "0"
10917 </literallayout>
10918 </para>
10919
10920 <para>
10921 The content of the resulting <filename>/dev</filename>
10922 directory is defined in a Device Table file.
10923 The
10924 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10925 variable defines the Device Table to use and should be set
10926 in the machine or distro configuration file.
10927 Alternatively, you can set this variable in your
10928 <filename>local.conf</filename> configuration file.
10929 </para>
10930
10931 <para>
10932 If you do not define the
10933 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10934 <filename>device_table-minimal.txt</filename> is used:
10935 <literallayout class='monospaced'>
10936 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10937 </literallayout>
10938 </para>
10939
10940 <para>
10941 The population is handled by the <filename>makedevs</filename>
10942 utility during image creation:
10943 </para>
10944 </section>
10945
10946 <section id="devtmpfs-dev-management">
10947 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10948
10949 <para>
10950 To use the dynamic method for device population, you need to
10951 use (or be sure to set) the
10952 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10953 variable to "1", which is the default:
10954 <literallayout class='monospaced'>
10955 USE_DEVFS = "1"
10956 </literallayout>
10957 With this setting, the resulting <filename>/dev</filename>
10958 directory is populated by the kernel using
10959 <filename>devtmpfs</filename>.
10960 Make sure the corresponding kernel configuration variable
10961 <filename>CONFIG_DEVTMPFS</filename> is set when building
10962 you build a Linux kernel.
10963 </para>
10964
10965 <para>
10966 All devices created by <filename>devtmpfs</filename> will be
10967 owned by <filename>root</filename> and have permissions
10968 <filename>0600</filename>.
10969 </para>
10970
10971 <para>
10972 To have more control over the device nodes, you can use a
10973 device manager like <filename>udev</filename> or
10974 <filename>busybox-mdev</filename>.
10975 You choose the device manager by defining the
10976 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10977 in your machine or distro configuration file.
10978 Alternatively, you can set this variable in your
10979 <filename>local.conf</filename> configuration file:
10980 <literallayout class='monospaced'>
10981 VIRTUAL-RUNTIME_dev_manager = "udev"
10982
10983 # Some alternative values
10984 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10985 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10986 </literallayout>
10987 </para>
10988 </section>
10989 </section>
10990
10991 <section id="platdev-appdev-srcrev">
10992 <title>Using an External SCM</title>
10993
10994 <para>
10995 If you're working on a recipe that pulls from an external Source
10996 Code Manager (SCM), it is possible to have the OpenEmbedded build
10997 system notice new recipe changes added to the SCM and then build
10998 the resulting packages that depend on the new recipes by using
10999 the latest versions.
11000 This only works for SCMs from which it is possible to get a
11001 sensible revision number for changes.
11002 Currently, you can do this with Apache Subversion (SVN), Git, and
11003 Bazaar (BZR) repositories.
11004 </para>
11005
11006 <para>
11007 To enable this behavior, the
11008 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
11009 of the recipe needs to reference
11010 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
11011 Here is an example:
11012 <literallayout class='monospaced'>
11013 PV = "1.2.3+git${SRCPV}"
11014 </literallayout>
11015 Then, you can add the following to your
11016 <filename>local.conf</filename>:
11017 <literallayout class='monospaced'>
11018 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
11019 </literallayout>
11020 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
11021 is the name of the recipe for which you want to enable automatic source
11022 revision updating.
11023 </para>
11024
11025 <para>
11026 If you do not want to update your local configuration file, you can
11027 add the following directly to the recipe to finish enabling
11028 the feature:
11029 <literallayout class='monospaced'>
11030 SRCREV = "${AUTOREV}"
11031 </literallayout>
11032 </para>
11033
11034 <para>
11035 The Yocto Project provides a distribution named
11036 <filename>poky-bleeding</filename>, whose configuration
11037 file contains the line:
11038 <literallayout class='monospaced'>
11039 require conf/distro/include/poky-floating-revisions.inc
11040 </literallayout>
11041 This line pulls in the listed include file that contains
11042 numerous lines of exactly that form:
11043 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011044 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
11045 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
11046 #SRCREV_pn-opkg ?= "${AUTOREV}"
11047 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
11048 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011049 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
11050 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
11051 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
11052 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
11053 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011054 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
11055 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
11056 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
11057 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011058 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
11059 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011060 .
11061 .
11062 .
11063 </literallayout>
11064 These lines allow you to experiment with building a
11065 distribution that tracks the latest development source
11066 for numerous packages.
11067 <note><title>Caution</title>
11068 The <filename>poky-bleeding</filename> distribution
11069 is not tested on a regular basis.
11070 Keep this in mind if you use it.
11071 </note>
11072 </para>
11073 </section>
11074
11075 <section id='creating-a-read-only-root-filesystem'>
11076 <title>Creating a Read-Only Root Filesystem</title>
11077
11078 <para>
11079 Suppose, for security reasons, you need to disable
11080 your target device's root filesystem's write permissions
11081 (i.e. you need a read-only root filesystem).
11082 Or, perhaps you are running the device's operating system
11083 from a read-only storage device.
11084 For either case, you can customize your image for
11085 that behavior.
11086 </para>
11087
11088 <note>
11089 Supporting a read-only root filesystem requires that the system and
11090 applications do not try to write to the root filesystem.
11091 You must configure all parts of the target system to write
11092 elsewhere, or to gracefully fail in the event of attempting to
11093 write to the root filesystem.
11094 </note>
11095
11096 <section id='creating-the-root-filesystem'>
11097 <title>Creating the Root Filesystem</title>
11098
11099 <para>
11100 To create the read-only root filesystem, simply add the
11101 "read-only-rootfs" feature to your image.
11102 Using either of the following statements in your
11103 image recipe or from within the
11104 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011105 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011106 causes the build system to create a read-only root filesystem:
11107 <literallayout class='monospaced'>
11108 IMAGE_FEATURES = "read-only-rootfs"
11109 </literallayout>
11110 or
11111 <literallayout class='monospaced'>
11112 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
11113 </literallayout>
11114 </para>
11115
11116 <para>
11117 For more information on how to use these variables, see the
11118 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
11119 section.
11120 For information on the variables, see
11121 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
11122 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
11123 </para>
11124 </section>
11125
11126 <section id='post-installation-scripts'>
11127 <title>Post-Installation Scripts</title>
11128
11129 <para>
11130 It is very important that you make sure all
11131 post-Installation (<filename>pkg_postinst</filename>) scripts
11132 for packages that are installed into the image can be run
11133 at the time when the root filesystem is created during the
11134 build on the host system.
11135 These scripts cannot attempt to run during first-boot on the
11136 target device.
11137 With the "read-only-rootfs" feature enabled,
11138 the build system checks during root filesystem creation to make
11139 sure all post-installation scripts succeed.
11140 If any of these scripts still need to be run after the root
11141 filesystem is created, the build immediately fails.
11142 These build-time checks ensure that the build fails
11143 rather than the target device fails later during its
11144 initial boot operation.
11145 </para>
11146
11147 <para>
11148 Most of the common post-installation scripts generated by the
11149 build system for the out-of-the-box Yocto Project are engineered
11150 so that they can run during root filesystem creation
11151 (e.g. post-installation scripts for caching fonts).
11152 However, if you create and add custom scripts, you need
11153 to be sure they can be run during this file system creation.
11154 </para>
11155
11156 <para>
11157 Here are some common problems that prevent
11158 post-installation scripts from running during root filesystem
11159 creation:
11160 <itemizedlist>
11161 <listitem><para>
11162 <emphasis>Not using $D in front of absolute
11163 paths:</emphasis>
11164 The build system defines
11165 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
11166 when the root filesystem is created.
11167 Furthermore, <filename>$D</filename> is blank when the
11168 script is run on the target device.
11169 This implies two purposes for <filename>$D</filename>:
11170 ensuring paths are valid in both the host and target
11171 environments, and checking to determine which
11172 environment is being used as a method for taking
11173 appropriate actions.
11174 </para></listitem>
11175 <listitem><para>
11176 <emphasis>Attempting to run processes that are
11177 specific to or dependent on the target
11178 architecture:</emphasis>
11179 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011180 tools, which run on the host system,
11181 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011182 by alternatively running the processes under QEMU,
11183 which has the <filename>qemu_run_binary</filename>
11184 function.
11185 For more information, see the
11186 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
11187 class.</para></listitem>
11188 </itemizedlist>
11189 </para>
11190 </section>
11191
11192 <section id='areas-with-write-access'>
11193 <title>Areas With Write Access</title>
11194
11195 <para>
11196 With the "read-only-rootfs" feature enabled,
11197 any attempt by the target to write to the root filesystem at
11198 runtime fails.
11199 Consequently, you must make sure that you configure processes
11200 and applications that attempt these types of writes do so
11201 to directories with write access (e.g.
11202 <filename>/tmp</filename> or <filename>/var/run</filename>).
11203 </para>
11204 </section>
11205 </section>
11206
Brad Bishop316dfdd2018-06-25 12:45:53 -040011207
11208
11209
11210 <section id='maintaining-build-output-quality'>
11211 <title>Maintaining Build Output Quality</title>
11212
11213 <para>
11214 Many factors can influence the quality of a build.
11215 For example, if you upgrade a recipe to use a new version of an
11216 upstream software package or you experiment with some new
11217 configuration options, subtle changes can occur that you might
11218 not detect until later.
11219 Consider the case where your recipe is using a newer version of
11220 an upstream package.
11221 In this case, a new version of a piece of software might
11222 introduce an optional dependency on another library, which is
11223 auto-detected.
11224 If that library has already been built when the software is
11225 building, the software will link to the built library and that
11226 library will be pulled into your image along with the new
11227 software even if you did not want the library.
11228 </para>
11229
11230 <para>
11231 The
11232 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
11233 class exists to help you maintain the quality of your build
11234 output.
11235 You can use the class to highlight unexpected and possibly
11236 unwanted changes in the build output.
11237 When you enable build history, it records information about the
11238 contents of each package and image and then commits that
11239 information to a local Git repository where you can examine
11240 the information.
11241 </para>
11242
11243 <para>
11244 The remainder of this section describes the following:
11245 <itemizedlist>
11246 <listitem><para>
11247 How you can enable and disable build history
11248 </para></listitem>
11249 <listitem><para>
11250 How to understand what the build history contains
11251 </para></listitem>
11252 <listitem><para>
11253 How to limit the information used for build history
11254 </para></listitem>
11255 <listitem><para>
11256 How to examine the build history from both a
11257 command-line and web interface
11258 </para></listitem>
11259 </itemizedlist>
11260 </para>
11261
11262 <section id='enabling-and-disabling-build-history'>
11263 <title>Enabling and Disabling Build History</title>
11264
11265 <para>
11266 Build history is disabled by default.
11267 To enable it, add the following <filename>INHERIT</filename>
11268 statement and set the
11269 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
11270 variable to "1" at the end of your
11271 <filename>conf/local.conf</filename> file found in the
11272 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11273 <literallayout class='monospaced'>
11274 INHERIT += "buildhistory"
11275 BUILDHISTORY_COMMIT = "1"
11276 </literallayout>
11277 Enabling build history as previously described causes the
11278 OpenEmbedded build system to collect build output information
11279 and commit it as a single commit to a local
11280 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
11281 repository.
11282 <note>
11283 Enabling build history increases your build times slightly,
11284 particularly for images, and increases the amount of disk
11285 space used during the build.
11286 </note>
11287 </para>
11288
11289 <para>
11290 You can disable build history by removing the previous
11291 statements from your <filename>conf/local.conf</filename>
11292 file.
11293 </para>
11294 </section>
11295
11296 <section id='understanding-what-the-build-history-contains'>
11297 <title>Understanding What the Build History Contains</title>
11298
11299 <para>
11300 Build history information is kept in
11301 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
11302 in the Build Directory as defined by the
11303 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
11304 variable.
11305 The following is an example abbreviated listing:
11306 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
11307 </para>
11308
11309 <para>
11310 At the top level, a <filename>metadata-revs</filename>
11311 file exists that lists the revisions of the repositories for
11312 the enabled layers when the build was produced.
11313 The rest of the data splits into separate
11314 <filename>packages</filename>, <filename>images</filename>
11315 and <filename>sdk</filename> directories, the contents of
11316 which are described as follows.
11317 </para>
11318
11319 <section id='build-history-package-information'>
11320 <title>Build History Package Information</title>
11321
11322 <para>
11323 The history for each package contains a text file that has
11324 name-value pairs with information about the package.
11325 For example,
11326 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
11327 contains the following:
11328 <literallayout class='monospaced'>
11329 PV = 1.22.1
11330 PR = r32
11331 RPROVIDES =
11332 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
11333 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
11334 PKGSIZE = 540168
11335 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
11336 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
11337 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
11338 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
11339 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
11340 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
11341 /etc/busybox.links.nosuid /etc/busybox.links.suid
11342 </literallayout>
11343 Most of these name-value pairs correspond to variables
11344 used to produce the package.
11345 The exceptions are <filename>FILELIST</filename>, which
11346 is the actual list of files in the package, and
11347 <filename>PKGSIZE</filename>, which is the total size of
11348 files in the package in bytes.
11349 </para>
11350
11351 <para>
11352 A file also exists that corresponds to the recipe from
11353 which the package came (e.g.
11354 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
11355 <literallayout class='monospaced'>
11356 PV = 1.22.1
11357 PR = r32
11358 DEPENDS = initscripts kern-tools-native update-rc.d-native \
11359 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
11360 virtual/libc virtual/update-alternatives
11361 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
11362 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
11363 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
11364 </literallayout>
11365 </para>
11366
11367 <para>
11368 Finally, for those recipes fetched from a version control
11369 system (e.g., Git), a file exists that lists source
11370 revisions that are specified in the recipe and lists
11371 the actual revisions used during the build.
11372 Listed and actual revisions might differ when
11373 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
11374 is set to
11375 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
11376 Here is an example assuming
11377 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
11378 <literallayout class='monospaced'>
11379 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11380 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11381 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11382 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11383 </literallayout>
11384 You can use the
11385 <filename>buildhistory-collect-srcrevs</filename>
11386 command with the <filename>-a</filename> option to
11387 collect the stored <filename>SRCREV</filename> values
11388 from build history and report them in a format suitable for
11389 use in global configuration (e.g.,
11390 <filename>local.conf</filename> or a distro include file)
11391 to override floating <filename>AUTOREV</filename> values
11392 to a fixed set of revisions.
11393 Here is some example output from this command:
11394 <literallayout class='monospaced'>
11395 $ buildhistory-collect-srcrevs -a
11396 # i586-poky-linux
11397 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
11398 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
11399 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
11400 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11401 # x86_64-linux
11402 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
11403 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
11404 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
11405 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
11406 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
11407 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
11408 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
11409 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
11410 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11411 # qemux86-poky-linux
11412 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11413 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
11414 # all-poky-linux
11415 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
11416 </literallayout>
11417 <note>
11418 Here are some notes on using the
11419 <filename>buildhistory-collect-srcrevs</filename>
11420 command:
11421 <itemizedlist>
11422 <listitem><para>
11423 By default, only values where the
11424 <filename>SRCREV</filename> was not hardcoded
11425 (usually when <filename>AUTOREV</filename>
11426 is used) are reported.
11427 Use the <filename>-a</filename> option to
11428 see all <filename>SRCREV</filename> values.
11429 </para></listitem>
11430 <listitem><para>
11431 The output statements might not have any effect
11432 if overrides are applied elsewhere in the
11433 build system configuration.
11434 Use the <filename>-f</filename> option to add
11435 the <filename>forcevariable</filename> override
11436 to each output line if you need to work around
11437 this restriction.
11438 </para></listitem>
11439 <listitem><para>
11440 The script does apply special handling when
11441 building for multiple machines.
11442 However, the script does place a comment before
11443 each set of values that specifies which
11444 triplet to which they belong as previously
11445 shown (e.g.,
11446 <filename>i586-poky-linux</filename>).
11447 </para></listitem>
11448 </itemizedlist>
11449 </note>
11450 </para>
11451 </section>
11452
11453 <section id='build-history-image-information'>
11454 <title>Build History Image Information</title>
11455
11456 <para>
11457 The files produced for each image are as follows:
11458 <itemizedlist>
11459 <listitem><para>
11460 <filename>image-files:</filename>
11461 A directory containing selected files from the root
11462 filesystem.
11463 The files are defined by
11464 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
11465 </para></listitem>
11466 <listitem><para>
11467 <filename>build-id.txt:</filename>
11468 Human-readable information about the build
11469 configuration and metadata source revisions.
11470 This file contains the full build header as printed
11471 by BitBake.
11472 </para></listitem>
11473 <listitem><para>
11474 <filename>*.dot:</filename>
11475 Dependency graphs for the image that are
11476 compatible with <filename>graphviz</filename>.
11477 </para></listitem>
11478 <listitem><para>
11479 <filename>files-in-image.txt:</filename>
11480 A list of files in the image with permissions,
11481 owner, group, size, and symlink information.
11482 </para></listitem>
11483 <listitem><para>
11484 <filename>image-info.txt:</filename>
11485 A text file containing name-value pairs with
11486 information about the image.
11487 See the following listing example for more
11488 information.
11489 </para></listitem>
11490 <listitem><para>
11491 <filename>installed-package-names.txt:</filename>
11492 A list of installed packages by name only.
11493 </para></listitem>
11494 <listitem><para>
11495 <filename>installed-package-sizes.txt:</filename>
11496 A list of installed packages ordered by size.
11497 </para></listitem>
11498 <listitem><para>
11499 <filename>installed-packages.txt:</filename>
11500 A list of installed packages with full package
11501 filenames.
11502 </para></listitem>
11503 </itemizedlist>
11504 <note>
11505 Installed package information is able to be gathered
11506 and produced even if package management is disabled
11507 for the final image.
11508 </note>
11509 </para>
11510
11511 <para>
11512 Here is an example of <filename>image-info.txt</filename>:
11513 <literallayout class='monospaced'>
11514 DISTRO = poky
11515 DISTRO_VERSION = 1.7
11516 USER_CLASSES = buildstats image-mklibs image-prelink
11517 IMAGE_CLASSES = image_types
11518 IMAGE_FEATURES = debug-tweaks
11519 IMAGE_LINGUAS =
11520 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11521 BAD_RECOMMENDATIONS =
11522 NO_RECOMMENDATIONS =
11523 PACKAGE_EXCLUDE =
11524 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11525 write_image_manifest ; buildhistory_list_installed_image ; \
11526 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11527 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11528 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11529 IMAGESIZE = 6900
11530 </literallayout>
11531 Other than <filename>IMAGESIZE</filename>, which is the
11532 total size of the files in the image in Kbytes, the
11533 name-value pairs are variables that may have influenced the
11534 content of the image.
11535 This information is often useful when you are trying to
11536 determine why a change in the package or file
11537 listings has occurred.
11538 </para>
11539 </section>
11540
11541 <section id='using-build-history-to-gather-image-information-only'>
11542 <title>Using Build History to Gather Image Information Only</title>
11543
11544 <para>
11545 As you can see, build history produces image information,
11546 including dependency graphs, so you can see why something
11547 was pulled into the image.
11548 If you are just interested in this information and not
11549 interested in collecting specific package or SDK
11550 information, you can enable writing only image information
11551 without any history by adding the following to your
11552 <filename>conf/local.conf</filename> file found in the
11553 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11554 <literallayout class='monospaced'>
11555 INHERIT += "buildhistory"
11556 BUILDHISTORY_COMMIT = "0"
11557 BUILDHISTORY_FEATURES = "image"
11558 </literallayout>
11559 Here, you set the
11560 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11561 variable to use the image feature only.
11562 </para>
11563 </section>
11564
11565 <section id='build-history-sdk-information'>
11566 <title>Build History SDK Information</title>
11567
11568 <para>
11569 Build history collects similar information on the contents
11570 of SDKs
11571 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11572 as compared to information it collects for images.
11573 Furthermore, this information differs depending on whether
11574 an extensible or standard SDK is being produced.
11575 </para>
11576
11577 <para>
11578 The following list shows the files produced for SDKs:
11579 <itemizedlist>
11580 <listitem><para>
11581 <filename>files-in-sdk.txt:</filename>
11582 A list of files in the SDK with permissions,
11583 owner, group, size, and symlink information.
11584 This list includes both the host and target parts
11585 of the SDK.
11586 </para></listitem>
11587 <listitem><para>
11588 <filename>sdk-info.txt:</filename>
11589 A text file containing name-value pairs with
11590 information about the SDK.
11591 See the following listing example for more
11592 information.
11593 </para></listitem>
11594 <listitem><para>
11595 <filename>sstate-task-sizes.txt:</filename>
11596 A text file containing name-value pairs with
11597 information about task group sizes
11598 (e.g. <filename>do_populate_sysroot</filename>
11599 tasks have a total size).
11600 The <filename>sstate-task-sizes.txt</filename> file
11601 exists only when an extensible SDK is created.
11602 </para></listitem>
11603 <listitem><para>
11604 <filename>sstate-package-sizes.txt:</filename>
11605 A text file containing name-value pairs with
11606 information for the shared-state packages and
11607 sizes in the SDK.
11608 The <filename>sstate-package-sizes.txt</filename>
11609 file exists only when an extensible SDK is created.
11610 </para></listitem>
11611 <listitem><para>
11612 <filename>sdk-files:</filename>
11613 A folder that contains copies of the files
11614 mentioned in
11615 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11616 files are present in the output.
11617 Additionally, the default value of
11618 <filename>BUILDHISTORY_SDK_FILES</filename> is
11619 specific to the extensible SDK although you can
11620 set it differently if you would like to pull in
11621 specific files from the standard SDK.</para>
11622
11623 <para>The default files are
11624 <filename>conf/local.conf</filename>,
11625 <filename>conf/bblayers.conf</filename>,
11626 <filename>conf/auto.conf</filename>,
11627 <filename>conf/locked-sigs.inc</filename>, and
11628 <filename>conf/devtool.conf</filename>.
11629 Thus, for an extensible SDK, these files get
11630 copied into the <filename>sdk-files</filename>
11631 directory.
11632 </para></listitem>
11633 <listitem><para>
11634 The following information appears under
11635 each of the <filename>host</filename>
11636 and <filename>target</filename> directories
11637 for the portions of the SDK that run on the host
11638 and on the target, respectively:
11639 <note>
11640 The following files for the most part are empty
11641 when producing an extensible SDK because this
11642 type of SDK is not constructed from packages
11643 as is the standard SDK.
11644 </note>
11645 <itemizedlist>
11646 <listitem><para>
11647 <filename>depends.dot:</filename>
11648 Dependency graph for the SDK that is
11649 compatible with
11650 <filename>graphviz</filename>.
11651 </para></listitem>
11652 <listitem><para>
11653 <filename>installed-package-names.txt:</filename>
11654 A list of installed packages by name only.
11655 </para></listitem>
11656 <listitem><para>
11657 <filename>installed-package-sizes.txt:</filename>
11658 A list of installed packages ordered by size.
11659 </para></listitem>
11660 <listitem><para>
11661 <filename>installed-packages.txt:</filename>
11662 A list of installed packages with full
11663 package filenames.
11664 </para></listitem>
11665 </itemizedlist>
11666 </para></listitem>
11667 </itemizedlist>
11668 </para>
11669
11670 <para>
11671 Here is an example of <filename>sdk-info.txt</filename>:
11672 <literallayout class='monospaced'>
11673 DISTRO = poky
11674 DISTRO_VERSION = 1.3+snapshot-20130327
11675 SDK_NAME = poky-glibc-i686-arm
11676 SDK_VERSION = 1.3+snapshot
11677 SDKMACHINE =
11678 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11679 BAD_RECOMMENDATIONS =
11680 SDKSIZE = 352712
11681 </literallayout>
11682 Other than <filename>SDKSIZE</filename>, which is the
11683 total size of the files in the SDK in Kbytes, the
11684 name-value pairs are variables that might have influenced
11685 the content of the SDK.
11686 This information is often useful when you are trying to
11687 determine why a change in the package or file listings
11688 has occurred.
11689 </para>
11690 </section>
11691
11692 <section id='examining-build-history-information'>
11693 <title>Examining Build History Information</title>
11694
11695 <para>
11696 You can examine build history output from the command
11697 line or from a web interface.
11698 </para>
11699
11700 <para>
11701 To see any changes that have occurred (assuming you have
11702 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11703 you can simply use any Git command that allows you to
11704 view the history of a repository.
11705 Here is one method:
11706 <literallayout class='monospaced'>
11707 $ git log -p
11708 </literallayout>
11709 You need to realize, however, that this method does show
11710 changes that are not significant (e.g. a package's size
11711 changing by a few bytes).
11712 </para>
11713
11714 <para>
11715 A command-line tool called
11716 <filename>buildhistory-diff</filename> does exist, though,
11717 that queries the Git repository and prints just the
11718 differences that might be significant in human-readable
11719 form.
11720 Here is an example:
11721 <literallayout class='monospaced'>
11722 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11723 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11724 /etc/anotherpkg.conf was added
11725 /sbin/anotherpkg was added
11726 * (installed-package-names.txt):
11727 * anotherpkg was added
11728 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11729 anotherpkg was added
11730 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11731 * PR changed from "r0" to "r1"
11732 * PV changed from "0.1.10" to "0.1.12"
11733 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11734 * PR changed from "r0" to "r1"
11735 * PV changed from "0.1.10" to "0.1.12"
11736 </literallayout>
11737 <note>
11738 The <filename>buildhistory-diff</filename> tool
11739 requires the <filename>GitPython</filename> package.
11740 Be sure to install it using Pip3 as follows:
11741 <literallayout class='monospaced'>
11742 $ pip3 install GitPython --user
11743 </literallayout>
11744 Alternatively, you can install
11745 <filename>python3-git</filename> using the appropriate
11746 distribution package manager (e.g.
11747 <filename>apt-get</filename>, <filename>dnf</filename>,
11748 or <filename>zipper</filename>).
11749 </note>
11750 </para>
11751
11752 <para>
11753 To see changes to the build history using a web interface,
11754 follow the instruction in the <filename>README</filename>
11755 file here.
11756 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11757 </para>
11758
11759 <para>
11760 Here is a sample screenshot of the interface:
11761 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11762 </para>
11763 </section>
11764 </section>
11765 </section>
11766
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011767 <section id="performing-automated-runtime-testing">
11768 <title>Performing Automated Runtime Testing</title>
11769
11770 <para>
11771 The OpenEmbedded build system makes available a series of automated
11772 tests for images to verify runtime functionality.
11773 You can run these tests on either QEMU or actual target hardware.
11774 Tests are written in Python making use of the
11775 <filename>unittest</filename> module, and the majority of them
11776 run commands on the target system over SSH.
11777 This section describes how you set up the environment to use these
11778 tests, run available tests, and write and add your own tests.
11779 </para>
11780
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011781 <para>
11782 For information on the test and QA infrastructure available
11783 within the Yocto Project, see the
11784 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11785 section in the Yocto Project Reference Manual.
11786 </para>
11787
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011788 <section id='enabling-tests'>
11789 <title>Enabling Tests</title>
11790
11791 <para>
11792 Depending on whether you are planning to run tests using
11793 QEMU or on the hardware, you have to take
11794 different steps to enable the tests.
11795 See the following subsections for information on how to
11796 enable both types of tests.
11797 </para>
11798
11799 <section id='qemu-image-enabling-tests'>
11800 <title>Enabling Runtime Tests on QEMU</title>
11801
11802 <para>
11803 In order to run tests, you need to do the following:
11804 <itemizedlist>
11805 <listitem><para><emphasis>Set up to avoid interaction
11806 with <filename>sudo</filename> for networking:</emphasis>
11807 To accomplish this, you must do one of the
11808 following:
11809 <itemizedlist>
11810 <listitem><para>Add
11811 <filename>NOPASSWD</filename> for your user
11812 in <filename>/etc/sudoers</filename> either for
11813 all commands or just for
11814 <filename>runqemu-ifup</filename>.
11815 You must provide the full path as that can
11816 change if you are using multiple clones of the
11817 source repository.
11818 <note>
11819 On some distributions, you also need to
11820 comment out "Defaults requiretty" in
11821 <filename>/etc/sudoers</filename>.
11822 </note></para></listitem>
11823 <listitem><para>Manually configure a tap interface
11824 for your system.</para></listitem>
11825 <listitem><para>Run as root the script in
11826 <filename>scripts/runqemu-gen-tapdevs</filename>,
11827 which should generate a list of tap devices.
11828 This is the option typically chosen for
11829 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011830 <note><title>Notes</title>
11831 <itemizedlist>
11832 <listitem><para>
11833 Be sure to use an absolute path
11834 when calling this script
11835 with sudo.
11836 </para></listitem>
11837 <listitem><para>
11838 The package recipe
11839 <filename>qemu-helper-native</filename>
11840 is required to run this script.
11841 Build the package using the
11842 following command:
11843 <literallayout class='monospaced'>
11844 $ bitbake qemu-helper-native
11845 </literallayout>
11846 </para></listitem>
11847 </itemizedlist>
11848 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011849 </para></listitem>
11850 </itemizedlist></para></listitem>
11851 <listitem><para><emphasis>Set the
11852 <filename>DISPLAY</filename> variable:</emphasis>
11853 You need to set this variable so that you have an X
11854 server available (e.g. start
11855 <filename>vncserver</filename> for a headless machine).
11856 </para></listitem>
11857 <listitem><para><emphasis>Be sure your host's firewall
11858 accepts incoming connections from
11859 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011860 Some of the tests (in particular DNF tests) start
11861 an HTTP server on a random high number port,
11862 which is used to serve files to the target.
11863 The DNF module serves
11864 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11865 so it can run DNF channel commands.
11866 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011867 must accept incoming connections from 192.168.7.0/24,
11868 which is the default IP range used for tap devices
11869 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011870 <listitem><para><emphasis>Be sure your host has the
11871 correct packages installed:</emphasis>
11872 Depending your host's distribution, you need
11873 to have the following packages installed:
11874 <itemizedlist>
11875 <listitem><para>Ubuntu and Debian:
11876 <filename>sysstat</filename> and
11877 <filename>iproute2</filename>
11878 </para></listitem>
11879 <listitem><para>OpenSUSE:
11880 <filename>sysstat</filename> and
11881 <filename>iproute2</filename>
11882 </para></listitem>
11883 <listitem><para>Fedora:
11884 <filename>sysstat</filename> and
11885 <filename>iproute</filename>
11886 </para></listitem>
11887 <listitem><para>CentOS:
11888 <filename>sysstat</filename> and
11889 <filename>iproute</filename>
11890 </para></listitem>
11891 </itemizedlist>
11892 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011893 </itemizedlist>
11894 </para>
11895
11896 <para>
11897 Once you start running the tests, the following happens:
11898 <orderedlist>
11899 <listitem><para>A copy of the root filesystem is written
11900 to <filename>${WORKDIR}/testimage</filename>.
11901 </para></listitem>
11902 <listitem><para>The image is booted under QEMU using the
11903 standard <filename>runqemu</filename> script.
11904 </para></listitem>
11905 <listitem><para>A default timeout of 500 seconds occurs
11906 to allow for the boot process to reach the login prompt.
11907 You can change the timeout period by setting
11908 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11909 in the <filename>local.conf</filename> file.
11910 </para></listitem>
11911 <listitem><para>Once the boot process is reached and the
11912 login prompt appears, the tests run.
11913 The full boot log is written to
11914 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11915 </para></listitem>
11916 <listitem><para>Each test module loads in the order found
11917 in <filename>TEST_SUITES</filename>.
11918 You can find the full output of the commands run over
11919 SSH in
11920 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11921 </para></listitem>
11922 <listitem><para>If no failures occur, the task running the
11923 tests ends successfully.
11924 You can find the output from the
11925 <filename>unittest</filename> in the task log at
11926 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11927 </para></listitem>
11928 </orderedlist>
11929 </para>
11930 </section>
11931
11932 <section id='hardware-image-enabling-tests'>
11933 <title>Enabling Runtime Tests on Hardware</title>
11934
11935 <para>
11936 The OpenEmbedded build system can run tests on real
11937 hardware, and for certain devices it can also deploy
11938 the image to be tested onto the device beforehand.
11939 </para>
11940
11941 <para>
11942 For automated deployment, a "master image" is installed
11943 onto the hardware once as part of setup.
11944 Then, each time tests are to be run, the following
11945 occurs:
11946 <orderedlist>
11947 <listitem><para>The master image is booted into and
11948 used to write the image to be tested to
11949 a second partition.
11950 </para></listitem>
11951 <listitem><para>The device is then rebooted using an
11952 external script that you need to provide.
11953 </para></listitem>
11954 <listitem><para>The device boots into the image to be
11955 tested.
11956 </para></listitem>
11957 </orderedlist>
11958 </para>
11959
11960 <para>
11961 When running tests (independent of whether the image
11962 has been deployed automatically or not), the device is
11963 expected to be connected to a network on a
11964 pre-determined IP address.
11965 You can either use static IP addresses written into
11966 the image, or set the image to use DHCP and have your
11967 DHCP server on the test network assign a known IP address
11968 based on the MAC address of the device.
11969 </para>
11970
11971 <para>
11972 In order to run tests on hardware, you need to set
11973 <filename>TEST_TARGET</filename> to an appropriate value.
11974 For QEMU, you do not have to change anything, the default
11975 value is "QemuTarget".
11976 For running tests on hardware, the following options exist:
11977 <itemizedlist>
11978 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11979 Choose "SimpleRemoteTarget" if you are going to
11980 run tests on a target system that is already
11981 running the image to be tested and is available
11982 on the network.
11983 You can use "SimpleRemoteTarget" in conjunction
11984 with either real hardware or an image running
11985 within a separately started QEMU or any
11986 other virtual machine manager.
11987 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011988 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
11989 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011990 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011991 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011992 <filename>core-image-testmaster</filename>
11993 (or something similar) is installed.
11994 Also, your hardware under test must be in a
11995 DHCP-enabled network that gives it the same IP
11996 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011997 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011998 additional requirements and considerations.
11999 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012000 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012001 section, which follows, for more information.
12002 </para></listitem>
12003 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
12004 Choose "BeagleBoneTarget" if you are deploying
12005 images and running tests on the BeagleBone
12006 "Black" or original "White" hardware.
12007 For information on how to use these tests, see the
12008 comments at the top of the BeagleBoneTarget
12009 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
12010 file.
12011 </para></listitem>
12012 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
12013 Choose "EdgeRouterTarget" is you are deploying
12014 images and running tests on the Ubiquiti Networks
12015 EdgeRouter Lite.
12016 For information on how to use these tests, see the
12017 comments at the top of the EdgeRouterTarget
12018 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
12019 file.
12020 </para></listitem>
12021 <listitem><para><emphasis>"GrubTarget":</emphasis>
12022 Choose the "supports deploying images and running
12023 tests on any generic PC that boots using GRUB.
12024 For information on how to use these tests, see the
12025 comments at the top of the GrubTarget
12026 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
12027 file.
12028 </para></listitem>
12029 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
12030 Create your own custom target if you want to run
12031 tests when you are deploying images and running
12032 tests on a custom machine within your BSP layer.
12033 To do this, you need to add a Python unit that
12034 defines the target class under
12035 <filename>lib/oeqa/controllers/</filename> within
12036 your layer.
12037 You must also provide an empty
12038 <filename>__init__.py</filename>.
12039 For examples, see files in
12040 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
12041 </para></listitem>
12042 </itemizedlist>
12043 </para>
12044 </section>
12045
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012046 <section id='selecting-systemdboottarget'>
12047 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012048
12049 <para>
12050 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012051 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012052 in this section.
12053 You can skip down to the
12054 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
12055 section.
12056 </para>
12057
12058 <para>
12059 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012060 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012061 setup of your master image by doing the following:
12062 <orderedlist>
12063 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
12064 Be sure that <filename>EFI_PROVIDER</filename>
12065 is as follows:
12066 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012067 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012068 </literallayout>
12069 </para></listitem>
12070 <listitem><para><emphasis>Build the master image:</emphasis>
12071 Build the <filename>core-image-testmaster</filename>
12072 image.
12073 The <filename>core-image-testmaster</filename>
12074 recipe is provided as an example for a
12075 "master" image and you can customize the image
12076 recipe as you would any other recipe.
12077 </para>
12078 <para>Here are the image recipe requirements:
12079 <itemizedlist>
12080 <listitem><para>Inherits
12081 <filename>core-image</filename>
12082 so that kernel modules are installed.
12083 </para></listitem>
12084 <listitem><para>Installs normal linux utilities
12085 not busybox ones (e.g.
12086 <filename>bash</filename>,
12087 <filename>coreutils</filename>,
12088 <filename>tar</filename>,
12089 <filename>gzip</filename>, and
12090 <filename>kmod</filename>).
12091 </para></listitem>
12092 <listitem><para>Uses a custom
12093 Initial RAM Disk (initramfs) image with a
12094 custom installer.
12095 A normal image that you can install usually
12096 creates a single rootfs partition.
12097 This image uses another installer that
12098 creates a specific partition layout.
12099 Not all Board Support Packages (BSPs)
12100 can use an installer.
12101 For such cases, you need to manually create
12102 the following partition layout on the
12103 target:
12104 <itemizedlist>
12105 <listitem><para>First partition mounted
12106 under <filename>/boot</filename>,
12107 labeled "boot".
12108 </para></listitem>
12109 <listitem><para>The main rootfs
12110 partition where this image gets
12111 installed, which is mounted under
12112 <filename>/</filename>.
12113 </para></listitem>
12114 <listitem><para>Another partition
12115 labeled "testrootfs" where test
12116 images get deployed.
12117 </para></listitem>
12118 </itemizedlist>
12119 </para></listitem>
12120 </itemizedlist>
12121 </para></listitem>
12122 <listitem><para><emphasis>Install image:</emphasis>
12123 Install the image that you just built on the target
12124 system.
12125 </para></listitem>
12126 </orderedlist>
12127 </para>
12128
12129 <para>
12130 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012131 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012132 to set up the test image:
12133 <orderedlist>
12134 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
12135 Make sure you have the following statements in
12136 your <filename>local.conf</filename> file:
12137 <literallayout class='monospaced'>
12138 IMAGE_FSTYPES += "tar.gz"
12139 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012140 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012141 TEST_TARGET_IP = "192.168.2.3"
12142 </literallayout>
12143 </para></listitem>
12144 <listitem><para><emphasis>Build your test image:</emphasis>
12145 Use BitBake to build the image:
12146 <literallayout class='monospaced'>
12147 $ bitbake core-image-sato
12148 </literallayout>
12149 </para></listitem>
12150 </orderedlist>
12151 </para>
12152 </section>
12153
12154 <section id='power-control'>
12155 <title>Power Control</title>
12156
12157 <para>
12158 For most hardware targets other than SimpleRemoteTarget,
12159 you can control power:
12160 <itemizedlist>
12161 <listitem><para>
12162 You can use
12163 <filename>TEST_POWERCONTROL_CMD</filename>
12164 together with
12165 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12166 as a command that runs on the host and does power
12167 cycling.
12168 The test code passes one argument to that command:
12169 off, on or cycle (off then on).
12170 Here is an example that could appear in your
12171 <filename>local.conf</filename> file:
12172 <literallayout class='monospaced'>
12173 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
12174 </literallayout>
12175 In this example, the expect script does the
12176 following:
12177 <literallayout class='monospaced'>
12178 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
12179 </literallayout>
12180 It then runs a Python script that controls power
12181 for a label called <filename>nuc1</filename>.
12182 <note>
12183 You need to customize
12184 <filename>TEST_POWERCONTROL_CMD</filename>
12185 and
12186 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12187 for your own setup.
12188 The one requirement is that it accepts
12189 "on", "off", and "cycle" as the last argument.
12190 </note>
12191 </para></listitem>
12192 <listitem><para>
12193 When no command is defined, it connects to the
12194 device over SSH and uses the classic reboot command
12195 to reboot the device.
12196 Classic reboot is fine as long as the machine
12197 actually reboots (i.e. the SSH test has not
12198 failed).
12199 It is useful for scenarios where you have a simple
12200 setup, typically with a single board, and where
12201 some manual interaction is okay from time to time.
12202 </para></listitem>
12203 </itemizedlist>
12204 If you have no hardware to automatically perform power
12205 control but still wish to experiment with automated
12206 hardware testing, you can use the dialog-power-control
12207 script that shows a dialog prompting you to perform the
12208 required power action.
12209 This script requires either KDialog or Zenity to be
12210 installed.
12211 To use this script, set the
12212 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
12213 variable as follows:
12214 <literallayout class='monospaced'>
12215 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
12216 </literallayout>
12217 </para>
12218 </section>
12219
12220 <section id='serial-console-connection'>
12221 <title>Serial Console Connection</title>
12222
12223 <para>
12224 For test target classes requiring a serial console
12225 to interact with the bootloader (e.g. BeagleBoneTarget,
12226 EdgeRouterTarget, and GrubTarget), you need to
12227 specify a command to use to connect to the serial console
12228 of the target machine by using the
12229 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
12230 variable and optionally the
12231 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
12232 variable.
12233 </para>
12234
12235 <para>
12236 These cases could be a serial terminal program if the
12237 machine is connected to a local serial port, or a
12238 <filename>telnet</filename> or
12239 <filename>ssh</filename> command connecting to a remote
12240 console server.
12241 Regardless of the case, the command simply needs to
12242 connect to the serial console and forward that connection
12243 to standard input and output as any normal terminal
12244 program does.
12245 For example, to use the picocom terminal program on
12246 serial device <filename>/dev/ttyUSB0</filename>
12247 at 115200bps, you would set the variable as follows:
12248 <literallayout class='monospaced'>
12249 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
12250 </literallayout>
12251 For local devices where the serial port device disappears
12252 when the device reboots, an additional "serdevtry" wrapper
12253 script is provided.
12254 To use this wrapper, simply prefix the terminal command
12255 with
12256 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
12257 <literallayout class='monospaced'>
12258 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
12259115200 /dev/ttyUSB0"
12260 </literallayout>
12261 </para>
12262 </section>
12263 </section>
12264
12265 <section id="qemu-image-running-tests">
12266 <title>Running Tests</title>
12267
12268 <para>
12269 You can start the tests automatically or manually:
12270 <itemizedlist>
12271 <listitem><para><emphasis>Automatically running tests:</emphasis>
12272 To run the tests automatically after the
12273 OpenEmbedded build system successfully creates an image,
12274 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012275 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012276 variable to "1" in your <filename>local.conf</filename>
12277 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012278 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012279 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012280 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012281 </literallayout>
12282 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012283 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012284 <literallayout class='monospaced'>
12285 bitbake core-image-sato
12286 </literallayout></para></listitem>
12287 <listitem><para><emphasis>Manually running tests:</emphasis>
12288 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012289 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012290 class by editing your <filename>local.conf</filename>
12291 file:
12292 <literallayout class='monospaced'>
12293 INHERIT += "testimage"
12294 </literallayout>
12295 Next, use BitBake to run the tests:
12296 <literallayout class='monospaced'>
12297 bitbake -c testimage <replaceable>image</replaceable>
12298 </literallayout></para></listitem>
12299 </itemizedlist>
12300 </para>
12301
12302 <para>
12303 All test files reside in
12304 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012305 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012306 A test name maps directly to a Python module.
12307 Each test module may contain a number of individual tests.
12308 Tests are usually grouped together by the area
12309 tested (e.g tests for systemd reside in
12310 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
12311 </para>
12312
12313 <para>
12314 You can add tests to any layer provided you place them in the
12315 proper area and you extend
12316 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12317 in the <filename>local.conf</filename> file as normal.
12318 Be sure that tests reside in
12319 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
12320 <note>
12321 Be sure that module names do not collide with module names
12322 used in the default set of test modules in
12323 <filename>meta/lib/oeqa/runtime</filename>.
12324 </note>
12325 </para>
12326
12327 <para>
12328 You can change the set of tests run by appending or overriding
12329 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
12330 variable in <filename>local.conf</filename>.
12331 Each name in <filename>TEST_SUITES</filename> represents a
12332 required test for the image.
12333 Test modules named within <filename>TEST_SUITES</filename>
12334 cannot be skipped even if a test is not suitable for an image
12335 (e.g. running the RPM tests on an image without
12336 <filename>rpm</filename>).
12337 Appending "auto" to <filename>TEST_SUITES</filename> causes the
12338 build system to try to run all tests that are suitable for the
12339 image (i.e. each test module may elect to skip itself).
12340 </para>
12341
12342 <para>
12343 The order you list tests in <filename>TEST_SUITES</filename>
12344 is important and influences test dependencies.
12345 Consequently, tests that depend on other tests should be added
12346 after the test on which they depend.
12347 For example, since the <filename>ssh</filename> test
12348 depends on the
12349 <filename>ping</filename> test, "ssh" needs to come after
12350 "ping" in the list.
12351 The test class provides no re-ordering or dependency handling.
12352 <note>
12353 Each module can have multiple classes with multiple test
12354 methods.
12355 And, Python <filename>unittest</filename> rules apply.
12356 </note>
12357 </para>
12358
12359 <para>
12360 Here are some things to keep in mind when running tests:
12361 <itemizedlist>
12362 <listitem><para>The default tests for the image are defined
12363 as:
12364 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012365 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 -050012366 </literallayout></para></listitem>
12367 <listitem><para>Add your own test to the list of the
12368 by using the following:
12369 <literallayout class='monospaced'>
12370 TEST_SUITES_append = " mytest"
12371 </literallayout></para></listitem>
12372 <listitem><para>Run a specific list of tests as follows:
12373 <literallayout class='monospaced'>
12374 TEST_SUITES = "test1 test2 test3"
12375 </literallayout>
12376 Remember, order is important.
12377 Be sure to place a test that is dependent on another test
12378 later in the order.</para></listitem>
12379 </itemizedlist>
12380 </para>
12381 </section>
12382
12383 <section id="exporting-tests">
12384 <title>Exporting Tests</title>
12385
12386 <para>
12387 You can export tests so that they can run independently of
12388 the build system.
12389 Exporting tests is required if you want to be able to hand
12390 the test execution off to a scheduler.
12391 You can only export tests that are defined in
12392 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
12393 </para>
12394
12395 <para>
12396 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012397 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012398 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012399 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012400 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
12401 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012402 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012403 You can then export the tests with the following BitBake
12404 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012405 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012406 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012407 </literallayout>
12408 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012409 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12410 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012411 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
12412 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012413 <filename>TEST_EXPORT_DIR</filename> variable.
12414 </para>
12415
12416 <para>
12417 You can now run the tests outside of the build environment:
12418 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012419 $ cd tmp/testexport/<replaceable>image</replaceable>
12420 $ ./runexported.py testdata.json
12421 </literallayout>
12422 </para>
12423
12424 <para>
12425 Here is a complete example that shows IP addresses and uses
12426 the <filename>core-image-sato</filename> image:
12427 <literallayout class='monospaced'>
12428 INHERIT +="testexport"
12429 TEST_TARGET_IP = "192.168.7.2"
12430 TEST_SERVER_IP = "192.168.7.1"
12431 </literallayout>
12432 Use BitBake to export the tests:
12433 <literallayout class='monospaced'>
12434 $ bitbake core-image-sato -c testexport
12435 </literallayout>
12436 Run the tests outside of the build environment using the
12437 following:
12438 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012439 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012440 $ ./runexported.py testdata.json
12441 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012442 </para>
12443 </section>
12444
12445 <section id="qemu-image-writing-new-tests">
12446 <title>Writing New Tests</title>
12447
12448 <para>
12449 As mentioned previously, all new test files need to be in the
12450 proper place for the build system to find them.
12451 New tests for additional functionality outside of the core
12452 should be added to the layer that adds the functionality, in
12453 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
12454 (as long as
12455 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12456 is extended in the layer's
12457 <filename>layer.conf</filename> file as normal).
12458 Just remember the following:
12459 <itemizedlist>
12460 <listitem><para>Filenames need to map directly to test
12461 (module) names.
12462 </para></listitem>
12463 <listitem><para>Do not use module names that
12464 collide with existing core tests.
12465 </para></listitem>
12466 <listitem><para>Minimally, an empty
12467 <filename>__init__.py</filename> file must exist
12468 in the runtime directory.
12469 </para></listitem>
12470 </itemizedlist>
12471 </para>
12472
12473 <para>
12474 To create a new test, start by copying an existing module
12475 (e.g. <filename>syslog.py</filename> or
12476 <filename>gcc.py</filename> are good ones to use).
12477 Test modules can use code from
12478 <filename>meta/lib/oeqa/utils</filename>, which are helper
12479 classes.
12480 </para>
12481
12482 <note>
12483 Structure shell commands such that you rely on them and they
12484 return a single code for success.
12485 Be aware that sometimes you will need to parse the output.
12486 See the <filename>df.py</filename> and
12487 <filename>date.py</filename> modules for examples.
12488 </note>
12489
12490 <para>
12491 You will notice that all test classes inherit
12492 <filename>oeRuntimeTest</filename>, which is found in
12493 <filename>meta/lib/oetest.py</filename>.
12494 This base class offers some helper attributes, which are
12495 described in the following sections:
12496 </para>
12497
12498 <section id='qemu-image-writing-tests-class-methods'>
12499 <title>Class Methods</title>
12500
12501 <para>
12502 Class methods are as follows:
12503 <itemizedlist>
12504 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12505 Returns "True" if <filename>pkg</filename> is in the
12506 installed package list of the image, which is based
12507 on the manifest file that is generated during the
12508 <filename>do_rootfs</filename> task.
12509 </para></listitem>
12510 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12511 Returns "True" if the feature is in
12512 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12513 or
12514 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12515 </para></listitem>
12516 </itemizedlist>
12517 </para>
12518 </section>
12519
12520 <section id='qemu-image-writing-tests-class-attributes'>
12521 <title>Class Attributes</title>
12522
12523 <para>
12524 Class attributes are as follows:
12525 <itemizedlist>
12526 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12527 Equals "ps -ef" if <filename>procps</filename> is
12528 installed in the image.
12529 Otherwise, <filename>pscmd</filename> equals
12530 "ps" (busybox).
12531 </para></listitem>
12532 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12533 The called test context, which gives access to the
12534 following attributes:
12535 <itemizedlist>
12536 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12537 The BitBake datastore, which allows you to
12538 use stuff such as
12539 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12540 </para></listitem>
12541 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12542 Used internally.
12543 The tests do not need these.
12544 </para></listitem>
12545 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12546 The absolute path to
12547 <filename>meta/lib/oeqa/runtime/files</filename>,
12548 which contains helper files for tests meant
12549 for copying on the target such as small
12550 files written in C for compilation.
12551 </para></listitem>
12552 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12553 The target controller object used to deploy
12554 and start an image on a particular target
12555 (e.g. QemuTarget, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012556 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012557 Tests usually use the following:
12558 <itemizedlist>
12559 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12560 The target's IP address.
12561 </para></listitem>
12562 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12563 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012564 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012565 suite.
12566 </para></listitem>
12567 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12568 The single, most used method.
12569 This command is a wrapper for:
12570 <filename>ssh root@host "cmd"</filename>.
12571 The command returns a tuple:
12572 (status, output), which are what
12573 their names imply - the return code
12574 of "cmd" and whatever output
12575 it produces.
12576 The optional timeout argument
12577 represents the number of seconds the
12578 test should wait for "cmd" to
12579 return.
12580 If the argument is "None", the
12581 test uses the default instance's
12582 timeout period, which is 300
12583 seconds.
12584 If the argument is "0", the test
12585 runs until the command returns.
12586 </para></listitem>
12587 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12588 <filename>scp localpath root@ip:remotepath</filename>.
12589 </para></listitem>
12590 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12591 <filename>scp root@host:remotepath localpath</filename>.
12592 </para></listitem>
12593 </itemizedlist></para></listitem>
12594 </itemizedlist></para></listitem>
12595 </itemizedlist>
12596 </para>
12597 </section>
12598
12599 <section id='qemu-image-writing-tests-instance-attributes'>
12600 <title>Instance Attributes</title>
12601
12602 <para>
12603 A single instance attribute exists, which is
12604 <filename>target</filename>.
12605 The <filename>target</filename> instance attribute is
12606 identical to the class attribute of the same name, which
12607 is described in the previous section.
12608 This attribute exists as both an instance and class
12609 attribute so tests can use
12610 <filename>self.target.run(cmd)</filename> in instance
12611 methods instead of
12612 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12613 </para>
12614 </section>
12615 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012616
12617 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12618 <title>Installing Packages in the DUT Without the Package Manager</title>
12619
12620 <para>
12621 When a test requires a package built by BitBake, it is possible
12622 to install that package.
12623 Installing the package does not require a package manager be
12624 installed in the device under test (DUT).
12625 It does, however, require an SSH connection and the target must
12626 be using the <filename>sshcontrol</filename> class.
12627 <note>
12628 This method uses <filename>scp</filename> to copy files
12629 from the host to the target, which causes permissions and
12630 special attributes to be lost.
12631 </note>
12632 </para>
12633
12634 <para>
12635 A JSON file is used to define the packages needed by a test.
12636 This file must be in the same path as the file used to define
12637 the tests.
12638 Furthermore, the filename must map directly to the test
12639 module name with a <filename>.json</filename> extension.
12640 </para>
12641
12642 <para>
12643 The JSON file must include an object with the test name as
12644 keys of an object or an array.
12645 This object (or array of objects) uses the following data:
12646 <itemizedlist>
12647 <listitem><para>"pkg" - A mandatory string that is the
12648 name of the package to be installed.
12649 </para></listitem>
12650 <listitem><para>"rm" - An optional boolean, which defaults
12651 to "false", that specifies to remove the package after
12652 the test.
12653 </para></listitem>
12654 <listitem><para>"extract" - An optional boolean, which
12655 defaults to "false", that specifies if the package must
12656 be extracted from the package format.
12657 When set to "true", the package is not automatically
12658 installed into the DUT.
12659 </para></listitem>
12660 </itemizedlist>
12661 </para>
12662
12663 <para>
12664 Following is an example JSON file that handles test "foo"
12665 installing package "bar" and test "foobar" installing
12666 packages "foo" and "bar".
12667 Once the test is complete, the packages are removed from the
12668 DUT.
12669 <literallayout class='monospaced'>
12670 {
12671 "foo": {
12672 "pkg": "bar"
12673 },
12674 "foobar": [
12675 {
12676 "pkg": "foo",
12677 "rm": true
12678 },
12679 {
12680 "pkg": "bar",
12681 "rm": true
12682 }
12683 ]
12684 }
12685 </literallayout>
12686 </para>
12687 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012688 </section>
12689
Brad Bishop316dfdd2018-06-25 12:45:53 -040012690 <section id='usingpoky-debugging-tools-and-techniques'>
12691 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012692
12693 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012694 The exact method for debugging build failures depends on the nature
12695 of the problem and on the system's area from which the bug
12696 originates.
12697 Standard debugging practices such as comparison against the last
12698 known working version with examination of the changes and the
12699 re-application of steps to identify the one causing the problem are
12700 valid for the Yocto Project just as they are for any other system.
12701 Even though it is impossible to detail every possible potential
12702 failure, this section provides some general tips to aid in
12703 debugging given a variety of situations.
12704 <note><title>Tip</title>
12705 A useful feature for debugging is the error reporting tool.
12706 Configuring the Yocto Project to use this tool causes the
12707 OpenEmbedded build system to produce error reporting commands as
12708 part of the console output.
12709 You can enter the commands after the build completes to log
12710 error information into a common database, that can help you
12711 figure out what might be going wrong.
12712 For information on how to enable and use this feature, see the
12713 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12714 section.
12715 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012716 </para>
12717
12718 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012719 The following list shows the debugging topics in the remainder of
12720 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012721 <itemizedlist>
12722 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012723 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12724 describes how to find and view logs from tasks that
12725 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012726 </para></listitem>
12727 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012728 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12729 describes how to use the BitBake <filename>-e</filename>
12730 option to examine variable values after a recipe has been
12731 parsed.
12732 </para></listitem>
12733 <listitem><para>
12734 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12735 describes how to use the
12736 <filename>oe-pkgdata-util</filename> utility to query
12737 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12738 and display package-related information for built
12739 packages.
12740 </para></listitem>
12741 <listitem><para>
12742 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12743 describes how to use the BitBake <filename>-g</filename>
12744 option to display recipe dependency information used
12745 during the build.
12746 </para></listitem>
12747 <listitem><para>
12748 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12749 describes how to use the
12750 <filename>bitbake-dumpsig</filename> command in
12751 conjunction with key subdirectories in the
12752 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12753 to determine variable dependencies.
12754 </para></listitem>
12755 <listitem><para>
12756 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12757 describes how to use several BitBake options (e.g.
12758 <filename>-c</filename>, <filename>-C</filename>, and
12759 <filename>-f</filename>) to run specific tasks in the
12760 build chain.
12761 It can be useful to run tasks "out-of-order" when trying
12762 isolate build issues.
12763 </para></listitem>
12764 <listitem><para>
12765 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12766 describes how to use BitBake's <filename>-D</filename>
12767 debug output option to reveal more about what BitBake is
12768 doing during the build.
12769 </para></listitem>
12770 <listitem><para>
12771 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12772 describes how to use the BitBake <filename>-b</filename>
12773 option to build a recipe while ignoring dependencies.
12774 </para></listitem>
12775 <listitem><para>
12776 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12777 describes how to use the many recipe logging functions
12778 to produce debugging output and report errors and warnings.
12779 </para></listitem>
12780 <listitem><para>
12781 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12782 describes how to debug situations where the build consists
12783 of several parts that are run simultaneously and when the
12784 output or result of one part is not ready for use with a
12785 different part of the build that depends on that output.
12786 </para></listitem>
12787 <listitem><para>
12788 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12789 describes how to use GDB to allow you to examine running
12790 programs, which can help you fix problems.
12791 </para></listitem>
12792 <listitem><para>
12793 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12794 describes how to use GDB directly on target hardware for
12795 debugging.
12796 </para></listitem>
12797 <listitem><para>
12798 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12799 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012800 </para></listitem>
12801 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012802 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012803
Brad Bishop316dfdd2018-06-25 12:45:53 -040012804 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12805 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012806
12807 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012808 You can find the log for a task in the file
12809 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12810 For example, the log for the
12811 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12812 task of the QEMU minimal image for the x86 machine
12813 (<filename>qemux86</filename>) might be in
12814 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12815 To see the commands
12816 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12817 ran to generate a log, look at the corresponding
12818 <filename>run.do_</filename><replaceable>taskname</replaceable>
12819 file in the same directory.
12820 </para>
12821
12822 <para>
12823 <filename>log.do_</filename><replaceable>taskname</replaceable>
12824 and
12825 <filename>run.do_</filename><replaceable>taskname</replaceable>
12826 are actually symbolic links to
12827 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12828 and
12829 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12830 where <replaceable>pid</replaceable> is the PID the task had
12831 when it ran.
12832 The symlinks always point to the files corresponding to the most
12833 recent run.
12834 </para>
12835 </section>
12836
12837 <section id='dev-debugging-viewing-variable-values'>
12838 <title>Viewing Variable Values</title>
12839
12840 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040012841 Sometimes you need to know the value of a variable as a
12842 result of BitBake's parsing step.
12843 This could be because some unexpected behavior occurred
12844 in your project.
12845 Perhaps an attempt to
12846 <ulink url='&YOCTO_DOCS_BB_URL;#modifying-existing-variables'>modify a variable</ulink>
12847 did not work out as expected.
12848 </para>
12849
12850 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012851 BitBake's <filename>-e</filename> option is used to display
12852 variable values after parsing.
12853 The following command displays the variable values after the
12854 configuration files (i.e. <filename>local.conf</filename>,
12855 <filename>bblayers.conf</filename>,
12856 <filename>bitbake.conf</filename> and so forth) have been
12857 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012858 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012859 $ bitbake -e
12860 </literallayout>
12861 The following command displays variable values after a specific
12862 recipe has been parsed.
12863 The variables include those from the configuration as well:
12864 <literallayout class='monospaced'>
12865 $ bitbake -e recipename
12866 </literallayout>
12867 <note><para>
12868 Each recipe has its own private set of variables
12869 (datastore).
12870 Internally, after parsing the configuration, a copy of the
12871 resulting datastore is made prior to parsing each recipe.
12872 This copying implies that variables set in one recipe will
12873 not be visible to other recipes.</para>
12874
12875 <para>Likewise, each task within a recipe gets a private
12876 datastore based on the recipe datastore, which means that
12877 variables set within one task will not be visible to
12878 other tasks.</para>
12879 </note>
12880 </para>
12881
12882 <para>
12883 In the output of <filename>bitbake -e</filename>, each
12884 variable is preceded by a description of how the variable
12885 got its value, including temporary values that were later
12886 overriden.
12887 This description also includes variable flags (varflags) set on
12888 the variable.
12889 The output can be very helpful during debugging.
12890 </para>
12891
12892 <para>
12893 Variables that are exported to the environment are preceded by
12894 <filename>export</filename> in the output of
12895 <filename>bitbake -e</filename>.
12896 See the following example:
12897 <literallayout class='monospaced'>
12898 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12899 </literallayout>
12900 </para>
12901
12902 <para>
12903 In addition to variable values, the output of the
12904 <filename>bitbake -e</filename> and
12905 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12906 commands includes the following information:
12907 <itemizedlist>
12908 <listitem><para>
12909 The output starts with a tree listing all configuration
12910 files and classes included globally, recursively listing
12911 the files they include or inherit in turn.
12912 Much of the behavior of the OpenEmbedded build system
12913 (including the behavior of the
12914 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12915 is implemented in the
12916 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12917 class and the classes it inherits, rather than being
12918 built into BitBake itself.
12919 </para></listitem>
12920 <listitem><para>
12921 After the variable values, all functions appear in the
12922 output.
12923 For shell functions, variables referenced within the
12924 function body are expanded.
12925 If a function has been modified using overrides or
12926 using override-style operators like
12927 <filename>_append</filename> and
12928 <filename>_prepend</filename>, then the final assembled
12929 function body appears in the output.
12930 </para></listitem>
12931 </itemizedlist>
12932 </para>
12933 </section>
12934
12935 <section id='viewing-package-information-with-oe-pkgdata-util'>
12936 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12937
12938 <para>
12939 You can use the <filename>oe-pkgdata-util</filename>
12940 command-line utility to query
12941 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12942 and display various package-related information.
12943 When you use the utility, you must use it to view information
12944 on packages that have already been built.
12945 </para>
12946
12947 <para>
12948 Following are a few of the available
12949 <filename>oe-pkgdata-util</filename> subcommands.
12950 <note>
12951 You can use the standard * and ? globbing wildcards as part
12952 of package names and paths.
12953 </note>
12954 <itemizedlist>
12955 <listitem><para>
12956 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12957 Lists all packages that have been built, optionally
12958 limiting the match to packages that match
12959 <replaceable>pattern</replaceable>.
12960 </para></listitem>
12961 <listitem><para>
12962 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12963 Lists the files and directories contained in the given
12964 packages.
12965 <note>
12966 <para>
12967 A different way to view the contents of a package is
12968 to look at the
12969 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12970 directory of the recipe that generates the
12971 package.
12972 This directory is created by the
12973 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12974 task and has one subdirectory for each package the
12975 recipe generates, which contains the files stored in
12976 that package.</para>
12977 <para>
12978 If you want to inspect the
12979 <filename>${WORKDIR}/packages-split</filename>
12980 directory, make sure that
12981 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12982 is not enabled when you build the recipe.
12983 </para>
12984 </note>
12985 </para></listitem>
12986 <listitem><para>
12987 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12988 Lists the names of the packages that contain the given
12989 paths.
12990 For example, the following tells us that
12991 <filename>/usr/share/man/man1/make.1</filename>
12992 is contained in the <filename>make-doc</filename>
12993 package:
12994 <literallayout class='monospaced'>
12995 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12996 make-doc: /usr/share/man/man1/make.1
12997 </literallayout>
12998 </para></listitem>
12999 <listitem><para>
13000 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
13001 Lists the name of the recipes that
13002 produce the given packages.
13003 </para></listitem>
13004 </itemizedlist>
13005 </para>
13006
13007 <para>
13008 For more information on the <filename>oe-pkgdata-util</filename>
13009 command, use the help facility:
13010 <literallayout class='monospaced'>
13011 $ oe-pkgdata-util &dash;&dash;help
13012 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
13013 </literallayout>
13014 </para>
13015 </section>
13016
13017 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
13018 <title>Viewing Dependencies Between Recipes and Tasks</title>
13019
13020 <para>
13021 Sometimes it can be hard to see why BitBake wants to build other
13022 recipes before the one you have specified.
13023 Dependency information can help you understand why a recipe is
13024 built.
13025 </para>
13026
13027 <para>
13028 To generate dependency information for a recipe, run the
13029 following command:
13030 <literallayout class='monospaced'>
13031 $ bitbake -g <replaceable>recipename</replaceable>
13032 </literallayout>
13033 This command writes the following files in the current
13034 directory:
13035 <itemizedlist>
13036 <listitem><para>
13037 <filename>pn-buildlist</filename>: A list of
13038 recipes/targets involved in building
13039 <replaceable>recipename</replaceable>.
13040 "Involved" here means that at least one task from the
13041 recipe needs to run when building
13042 <replaceable>recipename</replaceable> from scratch.
13043 Targets that are in
13044 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
13045 are not listed.
13046 </para></listitem>
13047 <listitem><para>
13048 <filename>task-depends.dot</filename>: A graph showing
13049 dependencies between tasks.
13050 </para></listitem>
13051 </itemizedlist>
13052 </para>
13053
13054 <para>
13055 The graphs are in
13056 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
13057 format and can be converted to images (e.g. using the
13058 <filename>dot</filename> tool from
13059 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
13060 <note><title>Notes</title>
13061 <itemizedlist>
13062 <listitem><para>
13063 DOT files use a plain text format.
13064 The graphs generated using the
13065 <filename>bitbake -g</filename> command are often so
13066 large as to be difficult to read without special
13067 pruning (e.g. with Bitbake's
13068 <filename>-I</filename> option) and processing.
13069 Despite the form and size of the graphs, the
13070 corresponding <filename>.dot</filename> files can
13071 still be possible to read and provide useful
13072 information.
13073 </para>
13074
13075 <para>As an example, the
13076 <filename>task-depends.dot</filename> file contains
13077 lines such as the following:
13078 <literallayout class='monospaced'>
13079 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
13080 </literallayout>
13081 The above example line reveals that the
13082 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
13083 task in <filename>libxslt</filename> depends on the
13084 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
13085 task in <filename>libxml2</filename>, which is a
13086 normal
13087 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
13088 dependency between the two recipes.
13089 </para></listitem>
13090 <listitem><para>
13091 For an example of how <filename>.dot</filename>
13092 files can be processed, see the
13093 <filename>scripts/contrib/graph-tool</filename>
13094 Python script, which finds and displays paths
13095 between graph nodes.
13096 </para></listitem>
13097 </itemizedlist>
13098 </note>
13099 </para>
13100
13101 <para>
13102 You can use a different method to view dependency information
13103 by using the following command:
13104 <literallayout class='monospaced'>
13105 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
13106 </literallayout>
13107 This command displays a GUI window from which you can view
13108 build-time and runtime dependencies for the recipes involved in
13109 building <replaceable>recipename</replaceable>.
13110 </para>
13111 </section>
13112
13113 <section id='dev-viewing-task-variable-dependencies'>
13114 <title>Viewing Task Variable Dependencies</title>
13115
13116 <para>
13117 As mentioned in the
13118 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
13119 section of the BitBake User Manual, BitBake tries to
13120 automatically determine what variables a task depends on so
13121 that it can rerun the task if any values of the variables
13122 change.
13123 This determination is usually reliable.
13124 However, if you do things like construct variable names at
13125 runtime, then you might have to manually declare dependencies
13126 on those variables using <filename>vardeps</filename> as
13127 described in the
13128 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
13129 section of the BitBake User Manual.
13130 </para>
13131
13132 <para>
13133 If you are unsure whether a variable dependency is being
13134 picked up automatically for a given task, you can list the
13135 variable dependencies BitBake has determined by doing the
13136 following:
13137 <orderedlist>
13138 <listitem><para>
13139 Build the recipe containing the task:
13140 <literallayout class='monospaced'>
13141 $ bitbake <replaceable>recipename</replaceable>
13142 </literallayout>
13143 </para></listitem>
13144 <listitem><para>
13145 Inside the
13146 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
13147 directory, find the signature data
13148 (<filename>sigdata</filename>) file that corresponds
13149 to the task.
13150 The <filename>sigdata</filename> files contain a pickled
13151 Python database of all the metadata that went into
13152 creating the input checksum for the task.
13153 As an example, for the
13154 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
13155 task of the <filename>db</filename> recipe, the
13156 <filename>sigdata</filename> file might be found in the
13157 following location:
13158 <literallayout class='monospaced'>
13159 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13160 </literallayout>
13161 For tasks that are accelerated through the shared state
13162 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
13163 cache, an additional <filename>siginfo</filename> file
13164 is written into
13165 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13166 along with the cached task output.
13167 The <filename>siginfo</filename> files contain exactly
13168 the same information as <filename>sigdata</filename>
13169 files.
13170 </para></listitem>
13171 <listitem><para>
13172 Run <filename>bitbake-dumpsig</filename> on the
13173 <filename>sigdata</filename> or
13174 <filename>siginfo</filename> file.
13175 Here is an example:
13176 <literallayout class='monospaced'>
13177 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13178 </literallayout>
13179 In the output of the above command, you will find a
13180 line like the following, which lists all the (inferred)
13181 variable dependencies for the task.
13182 This list also includes indirect dependencies from
13183 variables depending on other variables, recursively.
13184 <literallayout class='monospaced'>
13185 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
13186 </literallayout>
13187 <note>
13188 Functions (e.g. <filename>base_do_fetch</filename>)
13189 also count as variable dependencies.
13190 These functions in turn depend on the variables they
13191 reference.
13192 </note>
13193 The output of <filename>bitbake-dumpsig</filename> also
13194 includes the value each variable had, a list of
13195 dependencies for each variable, and
13196 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
13197 information.
13198 </para></listitem>
13199 </orderedlist>
13200 </para>
13201
13202 <para>
13203 There is also a <filename>bitbake-diffsigs</filename> command
13204 for comparing two <filename>siginfo</filename> or
13205 <filename>sigdata</filename> files.
13206 This command can be helpful when trying to figure out what
13207 changed between two versions of a task.
13208 If you call <filename>bitbake-diffsigs</filename> with just one
13209 file, the command behaves like
13210 <filename>bitbake-dumpsig</filename>.
13211 </para>
13212
13213 <para>
13214 You can also use BitBake to dump out the signature construction
13215 information without executing tasks by using either of the
13216 following BitBake command-line options:
13217 <literallayout class='monospaced'>
13218 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
13219 -S <replaceable>SIGNATURE_HANDLER</replaceable>
13220 </literallayout>
13221 <note>
13222 Two common values for
13223 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
13224 "printdiff", which dump only the signature or compare the
13225 dumped signature with the cached one, respectively.
13226 </note>
13227 Using BitBake with either of these options causes BitBake to
13228 dump out <filename>sigdata</filename> files in the
13229 <filename>stamps</filename> directory for every task it would
13230 have executed instead of building the specified target package.
13231 </para>
13232 </section>
13233
13234 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
13235 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
13236
13237 <para>
13238 Seeing what metadata went into creating the input signature
13239 of a shared state (sstate) task can be a useful debugging
13240 aid.
13241 This information is available in signature information
13242 (<filename>siginfo</filename>) files in
13243 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
13244 For information on how to view and interpret information in
13245 <filename>siginfo</filename> files, see the
13246 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
13247 section.
13248 </para>
13249
13250 <para>
13251 For conceptual information on shared state, see the
13252 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
13253 section in the Yocto Project Overview and Concepts Manual.
13254 </para>
13255 </section>
13256
13257 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
13258 <title>Invalidating Shared State to Force a Task to Run</title>
13259
13260 <para>
13261 The OpenEmbedded build system uses
13262 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
13263 and
13264 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
13265 cache to avoid unnecessarily rebuilding tasks.
13266 Collectively, this scheme is known as "shared state code."
13267 </para>
13268
13269 <para>
13270 As with all schemes, this one has some drawbacks.
13271 It is possible that you could make implicit changes to your
13272 code that the checksum calculations do not take into
13273 account.
13274 These implicit changes affect a task's output but do not
13275 trigger the shared state code into rebuilding a recipe.
13276 Consider an example during which a tool changes its output.
13277 Assume that the output of <filename>rpmdeps</filename>
13278 changes.
13279 The result of the change should be that all the
13280 <filename>package</filename> and
13281 <filename>package_write_rpm</filename> shared state cache
13282 items become invalid.
13283 However, because the change to the output is
13284 external to the code and therefore implicit,
13285 the associated shared state cache items do not become
13286 invalidated.
13287 In this case, the build process uses the cached items
13288 rather than running the task again.
13289 Obviously, these types of implicit changes can cause
13290 problems.
13291 </para>
13292
13293 <para>
13294 To avoid these problems during the build, you need to
13295 understand the effects of any changes you make.
13296 Realize that changes you make directly to a function
13297 are automatically factored into the checksum calculation.
13298 Thus, these explicit changes invalidate the associated
13299 area of shared state cache.
13300 However, you need to be aware of any implicit changes that
13301 are not obvious changes to the code and could affect
13302 the output of a given task.
13303 </para>
13304
13305 <para>
13306 When you identify an implicit change, you can easily
13307 take steps to invalidate the cache and force the tasks
13308 to run.
13309 The steps you can take are as simple as changing a
13310 function's comments in the source code.
13311 For example, to invalidate package shared state files,
13312 change the comment statements of
13313 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13314 or the comments of one of the functions it calls.
13315 Even though the change is purely cosmetic, it causes the
13316 checksum to be recalculated and forces the build system to
13317 run the task again.
13318 <note>
13319 For an example of a commit that makes a cosmetic
13320 change to invalidate shared state, see this
13321 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
13322 </note>
13323 </para>
13324 </section>
13325
13326 <section id='dev-debugging-taskrunning'>
13327 <title>Running Specific Tasks</title>
13328
13329 <para>
13330 Any given recipe consists of a set of tasks.
13331 The standard BitBake behavior in most cases is:
13332 <filename>do_fetch</filename>,
13333 <filename>do_unpack</filename>,
13334 <filename>do_patch</filename>,
13335 <filename>do_configure</filename>,
13336 <filename>do_compile</filename>,
13337 <filename>do_install</filename>,
13338 <filename>do_package</filename>,
13339 <filename>do_package_write_*</filename>, and
13340 <filename>do_build</filename>.
13341 The default task is <filename>do_build</filename> and any tasks
13342 on which it depends build first.
13343 Some tasks, such as <filename>do_devshell</filename>, are not
13344 part of the default build chain.
13345 If you wish to run a task that is not part of the default build
13346 chain, you can use the <filename>-c</filename> option in
13347 BitBake.
13348 Here is an example:
13349 <literallayout class='monospaced'>
13350 $ bitbake matchbox-desktop -c devshell
13351 </literallayout>
13352 </para>
13353
13354 <para>
13355 The <filename>-c</filename> option respects task dependencies,
13356 which means that all other tasks (including tasks from other
13357 recipes) that the specified task depends on will be run before
13358 the task.
13359 Even when you manually specify a task to run with
13360 <filename>-c</filename>, BitBake will only run the task if it
13361 considers it "out of date".
13362 See the
13363 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
13364 section in the Yocto Project Overview and Concepts Manual for
13365 how BitBake determines whether a task is "out of date".
13366 </para>
13367
13368 <para>
13369 If you want to force an up-to-date task to be rerun (e.g.
13370 because you made manual modifications to the recipe's
13371 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
13372 that you want to try out), then you can use the
13373 <filename>-f</filename> option.
13374 <note>
13375 The reason <filename>-f</filename> is never required when
13376 running the
13377 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
13378 task is because the
13379 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
13380 variable flag is already set for the task.
13381 </note>
13382 The following example shows one way you can use the
13383 <filename>-f</filename> option:
13384 <literallayout class='monospaced'>
13385 $ bitbake matchbox-desktop
13386 .
13387 .
13388 make some changes to the source code in the work directory
13389 .
13390 .
13391 $ bitbake matchbox-desktop -c compile -f
13392 $ bitbake matchbox-desktop
13393 </literallayout>
13394 </para>
13395
13396 <para>
13397 This sequence first builds and then recompiles
13398 <filename>matchbox-desktop</filename>.
13399 The last command reruns all tasks (basically the packaging
13400 tasks) after the compile.
13401 BitBake recognizes that the <filename>do_compile</filename>
13402 task was rerun and therefore understands that the other tasks
13403 also need to be run again.
13404 </para>
13405
13406 <para>
13407 Another, shorter way to rerun a task and all
13408 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
13409 that depend on it is to use the <filename>-C</filename>
13410 option.
13411 <note>
13412 This option is upper-cased and is separate from the
13413 <filename>-c</filename> option, which is lower-cased.
13414 </note>
13415 Using this option invalidates the given task and then runs the
13416 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
13417 task, which is the default task if no task is given, and the
13418 tasks on which it depends.
13419 You could replace the final two commands in the previous example
13420 with the following single command:
13421 <literallayout class='monospaced'>
13422 $ bitbake matchbox-desktop -C compile
13423 </literallayout>
13424 Internally, the <filename>-f</filename> and
13425 <filename>-C</filename> options work by tainting (modifying) the
13426 input checksum of the specified task.
13427 This tainting indirectly causes the task and its
13428 dependent tasks to be rerun through the normal task dependency
13429 mechanisms.
13430 <note>
13431 BitBake explicitly keeps track of which tasks have been
13432 tainted in this fashion, and will print warnings such as the
13433 following for builds involving such tasks:
13434 <literallayout class='monospaced'>
13435 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
13436 </literallayout>
13437 The purpose of the warning is to let you know that the work
13438 directory and build output might not be in the clean state
13439 they would be in for a "normal" build, depending on what
13440 actions you took.
13441 To get rid of such warnings, you can remove the work
13442 directory and rebuild the recipe, as follows:
13443 <literallayout class='monospaced'>
13444 $ bitbake matchbox-desktop -c clean
13445 $ bitbake matchbox-desktop
13446 </literallayout>
13447 </note>
13448 </para>
13449
13450 <para>
13451 You can view a list of tasks in a given package by running the
13452 <filename>do_listtasks</filename> task as follows:
13453 <literallayout class='monospaced'>
13454 $ bitbake matchbox-desktop -c listtasks
13455 </literallayout>
13456 The results appear as output to the console and are also in the
13457 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
13458 </para>
13459 </section>
13460
13461 <section id='dev-debugging-bitbake'>
13462 <title>General BitBake Problems</title>
13463
13464 <para>
13465 You can see debug output from BitBake by using the
13466 <filename>-D</filename> option.
13467 The debug output gives more information about what BitBake
13468 is doing and the reason behind it.
13469 Each <filename>-D</filename> option you use increases the
13470 logging level.
13471 The most common usage is <filename>-DDD</filename>.
13472 </para>
13473
13474 <para>
13475 The output from
13476 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
13477 can reveal why BitBake chose a certain version of a package or
13478 why BitBake picked a certain provider.
13479 This command could also help you in a situation where you think
13480 BitBake did something unexpected.
13481 </para>
13482 </section>
13483
13484 <section id='dev-debugging-buildfile'>
13485 <title>Building with No Dependencies</title>
13486
13487 <para>
13488 To build a specific recipe (<filename>.bb</filename> file),
13489 you can use the following command form:
13490 <literallayout class='monospaced'>
13491 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13492 </literallayout>
13493 This command form does not check for dependencies.
13494 Consequently, you should use it only when you know existing
13495 dependencies have been met.
13496 <note>
13497 You can also specify fragments of the filename.
13498 In this case, BitBake checks for a unique match.
13499 </note>
13500 </para>
13501 </section>
13502
13503 <section id='recipe-logging-mechanisms'>
13504 <title>Recipe Logging Mechanisms</title>
13505
13506 <para>
13507 The Yocto Project provides several logging functions for
13508 producing debugging output and reporting errors and warnings.
13509 For Python functions, the following logging functions exist.
13510 All of these functions log to
13511 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13512 and can also log to standard output (stdout) with the right
13513 settings:
13514 <itemizedlist>
13515 <listitem><para>
13516 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13517 Writes <replaceable>msg</replaceable> as is to the
13518 log while also logging to stdout.
13519 </para></listitem>
13520 <listitem><para>
13521 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13522 Writes "NOTE: <replaceable>msg</replaceable>" to the
13523 log.
13524 Also logs to stdout if BitBake is called with "-v".
13525 </para></listitem>
13526 <listitem><para>
13527 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13528 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13529 log.
13530 Also logs to stdout if the log level is greater than or
13531 equal to <replaceable>level</replaceable>.
13532 See the
13533 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13534 option in the BitBake User Manual for more information.
13535 </para></listitem>
13536 <listitem><para>
13537 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13538 Writes "WARNING: <replaceable>msg</replaceable>" to the
13539 log while also logging to stdout.
13540 </para></listitem>
13541 <listitem><para>
13542 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13543 Writes "ERROR: <replaceable>msg</replaceable>" to the
13544 log while also logging to standard out (stdout).
13545 <note>
13546 Calling this function does not cause the task to fail.
13547 </note>
13548 </para></listitem>
13549 <listitem><para>
13550 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13551 This logging function is similar to
13552 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13553 but also causes the calling task to fail.
13554 <note>
13555 <filename>bb.fatal()</filename> raises an exception,
13556 which means you do not need to put a "return"
13557 statement after the function.
13558 </note>
13559 </para></listitem>
13560 </itemizedlist>
13561 </para>
13562
13563 <para>
13564 The same logging functions are also available in shell
13565 functions, under the names
13566 <filename>bbplain</filename>, <filename>bbnote</filename>,
13567 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13568 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13569 The
13570 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13571 class implements these functions.
13572 See that class in the
13573 <filename>meta/classes</filename> folder of the
13574 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13575 for information.
13576 </para>
13577
13578 <section id='logging-with-python'>
13579 <title>Logging With Python</title>
13580
13581 <para>
13582 When creating recipes using Python and inserting code that
13583 handles build logs, keep in mind the goal is to have
13584 informative logs while keeping the console as "silent" as
13585 possible.
13586 Also, if you want status messages in the log, use the
13587 "debug" loglevel.
13588 </para>
13589
13590 <para>
13591 Following is an example written in Python.
13592 The code handles logging for a function that determines the
13593 number of tasks needed to be run.
13594 See the
13595 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13596 section for additional information:
13597 <literallayout class='monospaced'>
13598 python do_listtasks() {
13599 bb.debug(2, "Starting to figure out the task list")
13600 if noteworthy_condition:
13601 bb.note("There are 47 tasks to run")
13602 bb.debug(2, "Got to point xyz")
13603 if warning_trigger:
13604 bb.warn("Detected warning_trigger, this might be a problem later.")
13605 if recoverable_error:
13606 bb.error("Hit recoverable_error, you really need to fix this!")
13607 if fatal_error:
13608 bb.fatal("fatal_error detected, unable to print the task list")
13609 bb.plain("The tasks present are abc")
13610 bb.debug(2, "Finished figuring out the tasklist")
13611 }
13612 </literallayout>
13613 </para>
13614 </section>
13615
13616 <section id='logging-with-bash'>
13617 <title>Logging With Bash</title>
13618
13619 <para>
13620 When creating recipes using Bash and inserting code that
13621 handles build logs, you have the same goals - informative
13622 with minimal console output.
13623 The syntax you use for recipes written in Bash is similar
13624 to that of recipes written in Python described in the
13625 previous section.
13626 </para>
13627
13628 <para>
13629 Following is an example written in Bash.
13630 The code logs the progress of the <filename>do_my_function</filename> function.
13631 <literallayout class='monospaced'>
13632 do_my_function() {
13633 bbdebug 2 "Running do_my_function"
13634 if [ exceptional_condition ]; then
13635 bbnote "Hit exceptional_condition"
13636 fi
13637 bbdebug 2 "Got to point xyz"
13638 if [ warning_trigger ]; then
13639 bbwarn "Detected warning_trigger, this might cause a problem later."
13640 fi
13641 if [ recoverable_error ]; then
13642 bberror "Hit recoverable_error, correcting"
13643 fi
13644 if [ fatal_error ]; then
13645 bbfatal "fatal_error detected"
13646 fi
13647 bbdebug 2 "Completed do_my_function"
13648 }
13649 </literallayout>
13650 </para>
13651 </section>
13652 </section>
13653
13654 <section id='debugging-parallel-make-races'>
13655 <title>Debugging Parallel Make Races</title>
13656
13657 <para>
13658 A parallel <filename>make</filename> race occurs when the build
13659 consists of several parts that are run simultaneously and
13660 a situation occurs when the output or result of one
13661 part is not ready for use with a different part of the build
13662 that depends on that output.
13663 Parallel make races are annoying and can sometimes be difficult
13664 to reproduce and fix.
13665 However, some simple tips and tricks exist that can help
13666 you debug and fix them.
13667 This section presents a real-world example of an error
13668 encountered on the Yocto Project autobuilder and the process
13669 used to fix it.
13670 <note>
13671 If you cannot properly fix a <filename>make</filename> race
13672 condition, you can work around it by clearing either the
13673 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13674 or
13675 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13676 variables.
13677 </note>
13678 </para>
13679
13680 <section id='the-failure'>
13681 <title>The Failure</title>
13682
13683 <para>
13684 For this example, assume that you are building an image that
13685 depends on the "neard" package.
13686 And, during the build, BitBake runs into problems and
13687 creates the following output.
13688 <note>
13689 This example log file has longer lines artificially
13690 broken to make the listing easier to read.
13691 </note>
13692 If you examine the output or the log file, you see the
13693 failure during <filename>make</filename>:
13694 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013695 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13696 | DEBUG: Executing shell function do_compile
13697 | NOTE: make -j 16
13698 | make --no-print-directory all-am
13699 | /bin/mkdir -p include/near
13700 | /bin/mkdir -p include/near
13701 | /bin/mkdir -p include/near
13702 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13703 0.14-r0/neard-0.14/include/types.h include/near/types.h
13704 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13705 0.14-r0/neard-0.14/include/log.h include/near/log.h
13706 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13707 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13708 | /bin/mkdir -p include/near
13709 | /bin/mkdir -p include/near
13710 | /bin/mkdir -p include/near
13711 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13712 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13713 | /bin/mkdir -p include/near
13714 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13715 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13716 | /bin/mkdir -p include/near
13717 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13718 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13719 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13720 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13721 | /bin/mkdir -p include/near
13722 | /bin/mkdir -p include/near
13723 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13724 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13725 | /bin/mkdir -p include/near
13726 | /bin/mkdir -p include/near
13727 | /bin/mkdir -p include/near
13728 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13729 0.14-r0/neard-0.14/include/device.h include/near/device.h
13730 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13731 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13732 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13733 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13734 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13735 0.14-r0/neard-0.14/include/version.h include/near/version.h
13736 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13737 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13738 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13739 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13740 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13741 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13742 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13743 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13744 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13745 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13746 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13747 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13748 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13749 -o tools/snep-send.o tools/snep-send.c
13750 | In file included from tools/snep-send.c:16:0:
13751 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13752 | #include &lt;near/dbus.h&gt;
13753 | ^
13754 | compilation terminated.
13755 | make[1]: *** [tools/snep-send.o] Error 1
13756 | make[1]: *** Waiting for unfinished jobs....
13757 | make: *** [all] Error 2
13758 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013759 </literallayout>
13760 </para>
13761 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013762
Brad Bishop316dfdd2018-06-25 12:45:53 -040013763 <section id='reproducing-the-error'>
13764 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013765
Brad Bishop316dfdd2018-06-25 12:45:53 -040013766 <para>
13767 Because race conditions are intermittent, they do not
13768 manifest themselves every time you do the build.
13769 In fact, most times the build will complete without problems
13770 even though the potential race condition exists.
13771 Thus, once the error surfaces, you need a way to reproduce
13772 it.
13773 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013774
Brad Bishop316dfdd2018-06-25 12:45:53 -040013775 <para>
13776 In this example, compiling the "neard" package is causing
13777 the problem.
13778 So the first thing to do is build "neard" locally.
13779 Before you start the build, set the
13780 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13781 variable in your <filename>local.conf</filename> file to
13782 a high number (e.g. "-j 20").
13783 Using a high value for <filename>PARALLEL_MAKE</filename>
13784 increases the chances of the race condition showing up:
13785 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013786 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013787 </literallayout>
13788 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013789
Brad Bishop316dfdd2018-06-25 12:45:53 -040013790 <para>
13791 Once the local build for "neard" completes, start a
13792 <filename>devshell</filename> build:
13793 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013794 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013795 </literallayout>
13796 For information on how to use a
13797 <filename>devshell</filename>, see the
13798 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13799 section.
13800 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013801
Brad Bishop316dfdd2018-06-25 12:45:53 -040013802 <para>
13803 In the <filename>devshell</filename>, do the following:
13804 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013805 $ make clean
13806 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013807 </literallayout>
13808 The <filename>devshell</filename> commands cause the failure
13809 to clearly be visible.
13810 In this case, a missing dependency exists for the "neard"
13811 Makefile target.
13812 Here is some abbreviated, sample output with the
13813 missing dependency clearly visible at the end:
13814 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013815 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13816 .
13817 .
13818 .
13819 tools/snep-send.c
13820 In file included from tools/snep-send.c:16:0:
13821 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13822 #include &lt;near/dbus.h&gt;
13823 ^
13824 compilation terminated.
13825 make: *** [tools/snep-send.o] Error 1
13826 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013827 </literallayout>
13828 </para>
13829 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013830
Brad Bishop316dfdd2018-06-25 12:45:53 -040013831 <section id='creating-a-patch-for-the-fix'>
13832 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013833
Brad Bishop316dfdd2018-06-25 12:45:53 -040013834 <para>
13835 Because there is a missing dependency for the Makefile
13836 target, you need to patch the
13837 <filename>Makefile.am</filename> file, which is generated
13838 from <filename>Makefile.in</filename>.
13839 You can use Quilt to create the patch:
13840 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013841 $ quilt new parallelmake.patch
13842 Patch patches/parallelmake.patch is now on top
13843 $ quilt add Makefile.am
13844 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013845 </literallayout>
13846 For more information on using Quilt, see the
13847 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13848 section.
13849 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013850
Brad Bishop316dfdd2018-06-25 12:45:53 -040013851 <para>
13852 At this point you need to make the edits to
13853 <filename>Makefile.am</filename> to add the missing
13854 dependency.
13855 For our example, you have to add the following line
13856 to the file:
13857 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013858 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013859 </literallayout>
13860 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013861
Brad Bishop316dfdd2018-06-25 12:45:53 -040013862 <para>
13863 Once you have edited the file, use the
13864 <filename>refresh</filename> command to create the patch:
13865 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013866 $ quilt refresh
13867 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013868 </literallayout>
13869 Once the patch file exists, you need to add it back to the
13870 originating recipe folder.
13871 Here is an example assuming a top-level
13872 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13873 named <filename>poky</filename>:
13874 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013875 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013876 </literallayout>
13877 The final thing you need to do to implement the fix in the
13878 build is to update the "neard" recipe (i.e.
13879 <filename>neard-0.14.bb</filename>) so that the
13880 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13881 statement includes the patch file.
13882 The recipe file is in the folder above the patch.
13883 Here is what the edited <filename>SRC_URI</filename>
13884 statement would look like:
13885 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013886 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13887 file://neard.in \
13888 file://neard.service.in \
13889 file://parallelmake.patch \
13890 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013891 </literallayout>
13892 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013893
Brad Bishop316dfdd2018-06-25 12:45:53 -040013894 <para>
13895 With the patch complete and moved to the correct folder and
13896 the <filename>SRC_URI</filename> statement updated, you can
13897 exit the <filename>devshell</filename>:
13898 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013899 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013900 </literallayout>
13901 </para>
13902 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013903
Brad Bishop316dfdd2018-06-25 12:45:53 -040013904 <section id='testing-the-build'>
13905 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013906
Brad Bishop316dfdd2018-06-25 12:45:53 -040013907 <para>
13908 With everything in place, you can get back to trying the
13909 build again locally:
13910 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013911 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013912 </literallayout>
13913 This build should succeed.
13914 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013915
Brad Bishop316dfdd2018-06-25 12:45:53 -040013916 <para>
13917 Now you can open up a <filename>devshell</filename> again
13918 and repeat the clean and make operations as follows:
13919 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013920 $ bitbake neard -c devshell
13921 $ make clean
13922 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013923 </literallayout>
13924 The build should work without issue.
13925 </para>
13926
13927 <para>
13928 As with all solved problems, if they originated upstream,
13929 you need to submit the fix for the recipe in OE-Core and
13930 upstream so that the problem is taken care of at its
13931 source.
13932 See the
13933 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13934 section for more information.
13935 </para>
13936 </section>
13937 </section>
13938
13939 <section id="platdev-gdb-remotedebug">
13940 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13941
13942 <para>
13943 GDB allows you to examine running programs, which in turn helps
13944 you to understand and fix problems.
13945 It also allows you to perform post-mortem style analysis of
13946 program crashes.
13947 GDB is available as a package within the Yocto Project and is
13948 installed in SDK images by default.
13949 See the
13950 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13951 chapter in the Yocto Project Reference Manual for a description of
13952 these images.
13953 You can find information on GDB at
13954 <ulink url="http://sourceware.org/gdb/"/>.
13955 <note><title>Tip</title>
13956 For best results, install debug (<filename>-dbg</filename>)
13957 packages for the applications you are going to debug.
13958 Doing so makes extra debug symbols available that give you
13959 more meaningful output.
13960 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013961 </para>
13962
13963 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013964 Sometimes, due to memory or disk space constraints, it is not
13965 possible to use GDB directly on the remote target to debug
13966 applications.
13967 These constraints arise because GDB needs to load the debugging
13968 information and the binaries of the process being debugged.
13969 Additionally, GDB needs to perform many computations to locate
13970 information such as function names, variable names and values,
13971 stack traces and so forth - even before starting the debugging
13972 process.
13973 These extra computations place more load on the target system
13974 and can alter the characteristics of the program being debugged.
13975 </para>
13976
13977 <para>
13978 To help get past the previously mentioned constraints, you can
13979 use gdbserver, which runs on the remote target and does not
13980 load any debugging information from the debugged process.
13981 Instead, a GDB instance processes the debugging information that
13982 is run on a remote computer - the host GDB.
13983 The host GDB then sends control commands to gdbserver to make
13984 it stop or start the debugged program, as well as read or write
13985 memory regions of that debugged program.
13986 All the debugging information loaded and processed as well
13987 as all the heavy debugging is done by the host GDB.
13988 Offloading these processes gives the gdbserver running on the
13989 target a chance to remain small and fast.
13990 </para>
13991
13992 <para>
13993 Because the host GDB is responsible for loading the debugging
13994 information and for doing the necessary processing to make
13995 actual debugging happen, you have to make sure the host can
13996 access the unstripped binaries complete with their debugging
13997 information and also be sure the target is compiled with no
13998 optimizations.
13999 The host GDB must also have local access to all the libraries
14000 used by the debugged program.
14001 Because gdbserver does not need any local debugging information,
14002 the binaries on the remote target can remain stripped.
14003 However, the binaries must also be compiled without optimization
14004 so they match the host's binaries.
14005 </para>
14006
14007 <para>
14008 To remain consistent with GDB documentation and terminology,
14009 the binary being debugged on the remote target machine is
14010 referred to as the "inferior" binary.
14011 For documentation on GDB see the
14012 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
14013 </para>
14014
14015 <para>
14016 The following steps show you how to debug using the GNU project
14017 debugger.
14018 <orderedlist>
14019 <listitem><para>
14020 <emphasis>Configure your build system to construct the
14021 companion debug filesystem:</emphasis></para>
14022
14023 <para>In your <filename>local.conf</filename> file, set
14024 the following:
14025 <literallayout class='monospaced'>
14026 IMAGE_GEN_DEBUGFS = "1"
14027 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
14028 </literallayout>
14029 These options cause the OpenEmbedded build system
14030 to generate a special companion filesystem fragment,
14031 which contains the matching source and debug symbols to
14032 your deployable filesystem.
14033 The build system does this by looking at what is in the
14034 deployed filesystem, and pulling the corresponding
14035 <filename>-dbg</filename> packages.</para>
14036
14037 <para>The companion debug filesystem is not a complete
14038 filesystem, but only contains the debug fragments.
14039 This filesystem must be combined with the full filesystem
14040 for debugging.
14041 Subsequent steps in this procedure show how to combine
14042 the partial filesystem with the full filesystem.
14043 </para></listitem>
14044 <listitem><para>
14045 <emphasis>Configure the system to include gdbserver in
14046 the target filesystem:</emphasis></para>
14047
14048 <para>Make the following addition in either your
14049 <filename>local.conf</filename> file or in an image
14050 recipe:
14051 <literallayout class='monospaced'>
14052 IMAGE_INSTALL_append = “ gdbserver"
14053 </literallayout>
14054 The change makes sure the <filename>gdbserver</filename>
14055 package is included.
14056 </para></listitem>
14057 <listitem><para>
14058 <emphasis>Build the environment:</emphasis></para>
14059
14060 <para>Use the following command to construct the image
14061 and the companion Debug Filesystem:
14062 <literallayout class='monospaced'>
14063 $ bitbake <replaceable>image</replaceable>
14064 </literallayout>
14065 Build the cross GDB component and make it available
14066 for debugging.
14067 Build the SDK that matches the image.
14068 Building the SDK is best for a production build
14069 that can be used later for debugging, especially
14070 during long term maintenance:
14071 <literallayout class='monospaced'>
14072 $ bitbake -c populate_sdk <replaceable>image</replaceable>
14073 </literallayout></para>
14074
14075 <para>Alternatively, you can build the minimal
14076 toolchain components that match the target.
14077 Doing so creates a smaller than typical SDK and only
14078 contains a minimal set of components with which to
14079 build simple test applications, as well as run the
14080 debugger:
14081 <literallayout class='monospaced'>
14082 $ bitbake meta-toolchain
14083 </literallayout></para>
14084
14085 <para>A final method is to build Gdb itself within
14086 the build system:
14087 <literallayout class='monospaced'>
14088 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
14089 </literallayout>
14090 Doing so produces a temporary copy of
14091 <filename>cross-gdb</filename> you can use for
14092 debugging during development.
14093 While this is the quickest approach, the two previous
14094 methods in this step are better when considering
14095 long-term maintenance strategies.
14096 <note>
14097 If you run
14098 <filename>bitbake gdb-cross</filename>, the
14099 OpenEmbedded build system suggests the actual
14100 image (e.g. <filename>gdb-cross-i586</filename>).
14101 The suggestion is usually the actual name you want
14102 to use.
14103 </note>
14104 </para></listitem>
14105 <listitem><para>
14106 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
14107
14108 <para>Run the following commands to set up the
14109 <filename>debugfs</filename>:
14110 <literallayout class='monospaced'>
14111 $ mkdir debugfs
14112 $ cd debugfs
14113 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
14114 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
14115 </literallayout>
14116 </para></listitem>
14117 <listitem><para>
14118 <emphasis>Set up GDB</emphasis></para>
14119
14120 <para>Install the SDK (if you built one) and then
14121 source the correct environment file.
14122 Sourcing the environment file puts the SDK in your
14123 <filename>PATH</filename> environment variable.</para>
14124
14125 <para>If you are using the build system, Gdb is
14126 located in
14127 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
14128 </para></listitem>
14129 <listitem><para>
14130 <emphasis>Boot the target:</emphasis></para>
14131
14132 <para>For information on how to run QEMU, see the
14133 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
14134 <note>
14135 Be sure to verify that your host can access the
14136 target via TCP.
14137 </note>
14138 </para></listitem>
14139 <listitem><para>
14140 <emphasis>Debug a program:</emphasis></para>
14141
14142 <para>Debugging a program involves running gdbserver
14143 on the target and then running Gdb on the host.
14144 The example in this step debugs
14145 <filename>gzip</filename>:
14146 <literallayout class='monospaced'>
14147 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
14148 </literallayout>
14149 For additional gdbserver options, see the
14150 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
14151 </para>
14152
14153 <para>After running gdbserver on the target, you need
14154 to run Gdb on the host and configure it and connect to
14155 the target.
14156 Use these commands:
14157 <literallayout class='monospaced'>
14158 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
14159 $ <replaceable>arch</replaceable>-gdb
14160
14161 (gdb) set sysroot debugfs
14162 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
14163 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
14164 </literallayout>
14165 At this point, everything should automatically load
14166 (i.e. matching binaries, symbols and headers).
14167 <note>
14168 The Gdb <filename>set</filename> commands in the
14169 previous example can be placed into the users
14170 <filename>~/.gdbinit</filename> file.
14171 Upon starting, Gdb automatically runs whatever
14172 commands are in that file.
14173 </note>
14174 </para></listitem>
14175 <listitem><para>
14176 <emphasis>Deploying without a full image
14177 rebuild:</emphasis></para>
14178
14179 <para>In many cases, during development you want a
14180 quick method to deploy a new binary to the target and
14181 debug it, without waiting for a full image build.
14182 </para>
14183
14184 <para>One approach to solving this situation is to
14185 just build the component you want to debug.
14186 Once you have built the component, copy the
14187 executable directly to both the target and the
14188 host <filename>debugfs</filename>.</para>
14189
14190 <para>If the binary is processed through the debug
14191 splitting in OpenEmbedded, you should also
14192 copy the debug items (i.e. <filename>.debug</filename>
14193 contents and corresponding
14194 <filename>/usr/src/debug</filename> files)
14195 from the work directory.
14196 Here is an example:
14197 <literallayout class='monospaced'>
14198 $ bitbake bash
14199 $ bitbake -c devshell bash
14200 $ cd ..
14201 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
14202 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
14203 </literallayout>
14204 </para></listitem>
14205 </orderedlist>
14206 </para>
14207 </section>
14208
14209 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
14210 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
14211
14212 <para>
14213 The previous section addressed using GDB remotely for debugging
14214 purposes, which is the most usual case due to the inherent
14215 hardware limitations on many embedded devices.
14216 However, debugging in the target hardware itself is also
14217 possible with more powerful devices.
14218 This section describes what you need to do in order to support
14219 using GDB to debug on the target hardware.
14220 </para>
14221
14222 <para>
14223 To support this kind of debugging, you need do the following:
14224 <itemizedlist>
14225 <listitem><para>
14226 Ensure that GDB is on the target.
14227 You can do this by adding "gdb" to
14228 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
14229 <literallayout class='monospaced'>
14230 IMAGE_INSTALL_append = " gdb"
14231 </literallayout>
14232 Alternatively, you can add "tools-debug" to
14233 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
14234 <literallayout class='monospaced'>
14235 IMAGE_FEATURES_append = " tools-debug"
14236 </literallayout>
14237 </para></listitem>
14238 <listitem><para>
14239 Ensure that debug symbols are present.
14240 You can make sure these symbols are present by
14241 installing <filename>-dbg</filename>:
14242 <literallayout class='monospaced'>
14243 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
14244 </literallayout>
14245 Alternatively, you can do the following to include all
14246 the debug symbols:
14247 <literallayout class='monospaced'>
14248 IMAGE_FEATURES_append = " dbg-pkgs"
14249 </literallayout>
14250 </para></listitem>
14251 </itemizedlist>
14252 <note>
14253 To improve the debug information accuracy, you can reduce
14254 the level of optimization used by the compiler.
14255 For example, when adding the following line to your
14256 <filename>local.conf</filename> file, you will reduce
14257 optimization from
14258 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
14259 of "-O2" to
14260 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
14261 of "-O -fno-omit-frame-pointer":
14262 <literallayout class='monospaced'>
14263 DEBUG_BUILD = "1"
14264 </literallayout>
14265 Consider that this will reduce the application's performance
14266 and is recommended only for debugging purposes.
14267 </note>
14268 </para>
14269 </section>
14270
14271 <section id='dev-other-debugging-others'>
14272 <title>Other Debugging Tips</title>
14273
14274 <para>
14275 Here are some other tips that you might find useful:
14276 <itemizedlist>
14277 <listitem><para>
14278 When adding new packages, it is worth watching for
14279 undesirable items making their way into compiler command
14280 lines.
14281 For example, you do not want references to local system
14282 files like
14283 <filename>/usr/lib/</filename> or
14284 <filename>/usr/include/</filename>.
14285 </para></listitem>
14286 <listitem><para>
14287 If you want to remove the <filename>psplash</filename>
14288 boot splashscreen,
14289 add <filename>psplash=false</filename> to the kernel
14290 command line.
14291 Doing so prevents <filename>psplash</filename> from
14292 loading and thus allows you to see the console.
14293 It is also possible to switch out of the splashscreen by
14294 switching the virtual console (e.g. Fn+Left or Fn+Right
14295 on a Zaurus).
14296 </para></listitem>
14297 <listitem><para>
14298 Removing
14299 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
14300 (usually <filename>tmp/</filename>, within the
14301 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
14302 can often fix temporary build issues.
14303 Removing <filename>TMPDIR</filename> is usually a
14304 relatively cheap operation, because task output will be
14305 cached in
14306 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
14307 (usually <filename>sstate-cache/</filename>, which is
14308 also in the Build Directory).
14309 <note>
14310 Removing <filename>TMPDIR</filename> might be a
14311 workaround rather than a fix.
14312 Consequently, trying to determine the underlying
14313 cause of an issue before removing the directory is
14314 a good idea.
14315 </note>
14316 </para></listitem>
14317 <listitem><para>
14318 Understanding how a feature is used in practice within
14319 existing recipes can be very helpful.
14320 It is recommended that you configure some method that
14321 allows you to quickly search through files.</para>
14322
14323 <para>Using GNU Grep, you can use the following shell
14324 function to recursively search through common
14325 recipe-related files, skipping binary files,
14326 <filename>.git</filename> directories, and the
14327 Build Directory (assuming its name starts with
14328 "build"):
14329 <literallayout class='monospaced'>
14330 g() {
14331 grep -Ir \
14332 --exclude-dir=.git \
14333 --exclude-dir='build*' \
14334 --include='*.bb*' \
14335 --include='*.inc*' \
14336 --include='*.conf*' \
14337 --include='*.py*' \
14338 "$@"
14339 }
14340 </literallayout>
14341 Following are some usage examples:
14342 <literallayout class='monospaced'>
14343 $ g FOO # Search recursively for "FOO"
14344 $ g -i foo # Search recursively for "foo", ignoring case
14345 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
14346 </literallayout>
14347 If figuring out how some feature works requires a lot of
14348 searching, it might indicate that the documentation
14349 should be extended or improved.
14350 In such cases, consider filing a documentation bug using
14351 the Yocto Project implementation of
14352 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
14353 For information on how to submit a bug against
14354 the Yocto Project, see the Yocto Project Bugzilla
14355 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
14356 and the
14357 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
14358 section.
14359 <note>
14360 The manuals might not be the right place to document
14361 variables that are purely internal and have a
14362 limited scope (e.g. internal variables used to
14363 implement a single <filename>.bbclass</filename>
14364 file).
14365 </note>
14366 </para></listitem>
14367 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014368 </para>
14369 </section>
14370 </section>
14371
Brad Bishop316dfdd2018-06-25 12:45:53 -040014372 <section id='making-changes-to-the-yocto-project'>
14373 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014374
14375 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014376 Because the Yocto Project is an open-source, community-based
14377 project, you can effect changes to the project.
14378 This section presents procedures that show you how to submit
14379 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014380 </para>
14381
Brad Bishop316dfdd2018-06-25 12:45:53 -040014382 <section id='submitting-a-defect-against-the-yocto-project'>
14383 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014384
14385 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014386 Use the Yocto Project implementation of
14387 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
14388 to submit a defect (bug) against the Yocto Project.
14389 For additional information on this implementation of Bugzilla see the
14390 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
14391 section in the Yocto Project Reference Manual.
14392 For more detail on any of the following steps, see the Yocto Project
14393 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014394 </para>
14395
14396 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014397 Use the following general steps to submit a bug"
14398
14399 <orderedlist>
14400 <listitem><para>
14401 Open the Yocto Project implementation of
14402 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
14403 </para></listitem>
14404 <listitem><para>
14405 Click "File a Bug" to enter a new bug.
14406 </para></listitem>
14407 <listitem><para>
14408 Choose the appropriate "Classification", "Product", and
14409 "Component" for which the bug was found.
14410 Bugs for the Yocto Project fall into one of several
14411 classifications, which in turn break down into several
14412 products and components.
14413 For example, for a bug against the
14414 <filename>meta-intel</filename> layer, you would choose
14415 "Build System, Metadata &amp; Runtime", "BSPs", and
14416 "bsps-meta-intel", respectively.
14417 </para></listitem>
14418 <listitem><para>
14419 Choose the "Version" of the Yocto Project for which you found
14420 the bug (e.g. &DISTRO;).
14421 </para></listitem>
14422 <listitem><para>
14423 Determine and select the "Severity" of the bug.
14424 The severity indicates how the bug impacted your work.
14425 </para></listitem>
14426 <listitem><para>
14427 Choose the "Hardware" that the bug impacts.
14428 </para></listitem>
14429 <listitem><para>
14430 Choose the "Architecture" that the bug impacts.
14431 </para></listitem>
14432 <listitem><para>
14433 Choose a "Documentation change" item for the bug.
14434 Fixing a bug might or might not affect the Yocto Project
14435 documentation.
14436 If you are unsure of the impact to the documentation, select
14437 "Don't Know".
14438 </para></listitem>
14439 <listitem><para>
14440 Provide a brief "Summary" of the bug.
14441 Try to limit your summary to just a line or two and be sure
14442 to capture the essence of the bug.
14443 </para></listitem>
14444 <listitem><para>
14445 Provide a detailed "Description" of the bug.
14446 You should provide as much detail as you can about the context,
14447 behavior, output, and so forth that surrounds the bug.
14448 You can even attach supporting files for output from logs by
14449 using the "Add an attachment" button.
14450 </para></listitem>
14451 <listitem><para>
14452 Click the "Submit Bug" button submit the bug.
14453 A new Bugzilla number is assigned to the bug and the defect
14454 is logged in the bug tracking system.
14455 </para></listitem>
14456 </orderedlist>
14457 Once you file a bug, the bug is processed by the Yocto Project Bug
14458 Triage Team and further details concerning the bug are assigned
14459 (e.g. priority and owner).
14460 You are the "Submitter" of the bug and any further categorization,
14461 progress, or comments on the bug result in Bugzilla sending you an
14462 automated email concerning the particular change or progress to the
14463 bug.
14464 </para>
14465 </section>
14466
14467 <section id='how-to-submit-a-change'>
14468 <title>Submitting a Change to the Yocto Project</title>
14469
14470 <para>
14471 Contributions to the Yocto Project and OpenEmbedded are very welcome.
14472 Because the system is extremely configurable and flexible, we recognize
14473 that developers will want to extend, configure or optimize it for
14474 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014475 </para>
14476
14477 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014478 The Yocto Project uses a mailing list and a patch-based workflow
14479 that is similar to the Linux kernel but contains important
14480 differences.
14481 In general, a mailing list exists through which you can submit
14482 patches.
14483 You should send patches to the appropriate mailing list so that they
14484 can be reviewed and merged by the appropriate maintainer.
14485 The specific mailing list you need to use depends on the
14486 location of the code you are changing.
14487 Each component (e.g. layer) should have a
14488 <filename>README</filename> file that indicates where to send
14489 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014490 </para>
14491
14492 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014493 You can send the patch to the mailing list using whichever approach
14494 you feel comfortable with to generate the patch.
14495 Once sent, the patch is usually reviewed by the community at large.
14496 If somebody has concerns with the patch, they will usually voice
14497 their concern over the mailing list.
14498 If a patch does not receive any negative reviews, the maintainer of
14499 the affected layer typically takes the patch, tests it, and then
14500 based on successful testing, merges the patch.
14501 </para>
14502
14503 <para id='figuring-out-the-mailing-list-to-use'>
14504 The "poky" repository, which is the Yocto Project's reference build
14505 environment, is a hybrid repository that contains several
14506 individual pieces (e.g. BitBake, Metadata, documentation,
14507 and so forth) built using the combo-layer tool.
14508 The upstream location used for submitting changes varies by
14509 component:
14510 <itemizedlist>
14511 <listitem><para>
14512 <emphasis>Core Metadata:</emphasis>
14513 Send your patch to the
14514 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14515 mailing list. For example, a change to anything under
14516 the <filename>meta</filename> or
14517 <filename>scripts</filename> directories should be sent
14518 to this mailing list.
14519 </para></listitem>
14520 <listitem><para>
14521 <emphasis>BitBake:</emphasis>
14522 For changes to BitBake (i.e. anything under the
14523 <filename>bitbake</filename> directory), send your patch
14524 to the
14525 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14526 mailing list.
14527 </para></listitem>
14528 <listitem><para>
14529 <emphasis>"meta-*" trees:</emphasis>
14530 These trees contain Metadata.
14531 Use the
14532 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14533 mailing list.
14534 </para></listitem>
14535 </itemizedlist>
14536 </para>
14537
14538 <para>
14539 For changes to other layers hosted in the Yocto Project source
14540 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14541 and the Yocto Project documentation, use the
14542 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14543 general mailing list.
14544 <note>
14545 Sometimes a layer's documentation specifies to use a
14546 particular mailing list.
14547 If so, use that list.
14548 </note>
14549 For additional recipes that do not fit into the core Metadata, you
14550 should determine which layer the recipe should go into and submit
14551 the change in the manner recommended by the documentation (e.g.
14552 the <filename>README</filename> file) supplied with the layer.
14553 If in doubt, please ask on the Yocto general mailing list or on
14554 the openembedded-devel mailing list.
14555 </para>
14556
14557 <para>
14558 You can also push a change upstream and request a maintainer to
14559 pull the change into the component's upstream repository.
14560 You do this by pushing to a contribution repository that is upstream.
14561 See the
14562 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14563 section in the Yocto Project Overview and Concepts Manual for additional
14564 concepts on working in the Yocto Project development environment.
14565 </para>
14566
14567 <para>
14568 Two commonly used testing repositories exist for
14569 OpenEmbedded-Core:
14570 <itemizedlist>
14571 <listitem><para>
14572 <emphasis>"ross/mut" branch:</emphasis>
14573 The "mut" (master-under-test) tree
14574 exists in the <filename>poky-contrib</filename> repository
14575 in the
14576 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14577 </para></listitem>
14578 <listitem><para>
14579 <emphasis>"master-next" branch:</emphasis>
14580 This branch is part of the main
14581 "poky" repository in the Yocto Project source repositories.
14582 </para></listitem>
14583 </itemizedlist>
14584 Maintainers use these branches to test submissions prior to merging
14585 patches.
14586 Thus, you can get an idea of the status of a patch based on
14587 whether the patch has been merged into one of these branches.
14588 <note>
14589 This system is imperfect and changes can sometimes get lost in the
14590 flow.
14591 Asking about the status of a patch or change is reasonable if the
14592 change has been idle for a while with no feedback.
14593 The Yocto Project does have plans to use
14594 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14595 to track the status of patches and also to automatically preview
14596 patches.
14597 </note>
14598 </para>
14599
14600 <para>
14601 The following sections provide procedures for submitting a change.
14602 </para>
14603
14604 <section id='pushing-a-change-upstream'>
14605 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14606
14607 <para>
14608 Follow this procedure to push a change to an upstream "contrib"
14609 Git repository:
14610 <note>
14611 You can find general Git information on how to push a change
14612 upstream in the
14613 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14614 </note>
14615 <orderedlist>
14616 <listitem><para>
14617 <emphasis>Make Your Changes Locally:</emphasis>
14618 Make your changes in your local Git repository.
14619 You should make small, controlled, isolated changes.
14620 Keeping changes small and isolated aids review,
14621 makes merging/rebasing easier and keeps the change
14622 history clean should anyone need to refer to it in
14623 future.
14624 </para></listitem>
14625 <listitem><para>
14626 <emphasis>Stage Your Changes:</emphasis>
14627 Stage your changes by using the <filename>git add</filename>
14628 command on each file you changed.
14629 </para></listitem>
14630 <listitem><para id='making-sure-you-have-correct-commit-information'>
14631 <emphasis>Commit Your Changes:</emphasis>
14632 Commit the change by using the
14633 <filename>git commit</filename> command.
14634 Make sure your commit information follows standards by
14635 following these accepted conventions:
14636 <itemizedlist>
14637 <listitem><para>
14638 Be sure to include a "Signed-off-by:" line in the
14639 same style as required by the Linux kernel.
14640 Adding this line signifies that you, the submitter,
14641 have agreed to the Developer's Certificate of
14642 Origin 1.1 as follows:
14643 <literallayout class='monospaced'>
14644 Developer's Certificate of Origin 1.1
14645
14646 By making a contribution to this project, I certify that:
14647
14648 (a) The contribution was created in whole or in part by me and I
14649 have the right to submit it under the open source license
14650 indicated in the file; or
14651
14652 (b) The contribution is based upon previous work that, to the best
14653 of my knowledge, is covered under an appropriate open source
14654 license and I have the right under that license to submit that
14655 work with modifications, whether created in whole or in part
14656 by me, under the same open source license (unless I am
14657 permitted to submit under a different license), as indicated
14658 in the file; or
14659
14660 (c) The contribution was provided directly to me by some other
14661 person who certified (a), (b) or (c) and I have not modified
14662 it.
14663
14664 (d) I understand and agree that this project and the contribution
14665 are public and that a record of the contribution (including all
14666 personal information I submit with it, including my sign-off) is
14667 maintained indefinitely and may be redistributed consistent with
14668 this project or the open source license(s) involved.
14669 </literallayout>
14670 </para></listitem>
14671 <listitem><para>
14672 Provide a single-line summary of the change.
14673 and,
14674 if more explanation is needed, provide more
14675 detail in the body of the commit.
14676 This summary is typically viewable in the
14677 "shortlist" of changes.
14678 Thus, providing something short and descriptive
14679 that gives the reader a summary of the change is
14680 useful when viewing a list of many commits.
14681 You should prefix this short description with the
14682 recipe name (if changing a recipe), or else with
14683 the short form path to the file being changed.
14684 </para></listitem>
14685 <listitem><para>
14686 For the body of the commit message, provide
14687 detailed information that describes what you
14688 changed, why you made the change, and the approach
14689 you used.
14690 It might also be helpful if you mention how you
14691 tested the change.
14692 Provide as much detail as you can in the body of
14693 the commit message.
14694 <note>
14695 You do not need to provide a more detailed
14696 explanation of a change if the change is
14697 minor to the point of the single line
14698 summary providing all the information.
14699 </note>
14700 </para></listitem>
14701 <listitem><para>
14702 If the change addresses a specific bug or issue
14703 that is associated with a bug-tracking ID,
14704 include a reference to that ID in your detailed
14705 description.
14706 For example, the Yocto Project uses a specific
14707 convention for bug references - any commit that
14708 addresses a specific bug should use the following
14709 form for the detailed description.
14710 Be sure to use the actual bug-tracking ID from
14711 Bugzilla for
14712 <replaceable>bug-id</replaceable>:
14713 <literallayout class='monospaced'>
14714 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14715
14716 <replaceable>detailed description of change</replaceable>
14717 </literallayout>
14718 </para></listitem>
14719 </itemizedlist>
14720 </para></listitem>
14721 <listitem><para>
14722 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14723 If you have arranged for permissions to push to an
14724 upstream contrib repository, push the change to that
14725 repository:
14726 <literallayout class='monospaced'>
14727 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14728 </literallayout>
14729 For example, suppose you have permissions to push into the
14730 upstream <filename>meta-intel-contrib</filename>
14731 repository and you are working in a local branch named
14732 <replaceable>your_name</replaceable><filename>/README</filename>.
14733 The following command pushes your local commits to the
14734 <filename>meta-intel-contrib</filename> upstream
14735 repository and puts the commit in a branch named
14736 <replaceable>your_name</replaceable><filename>/README</filename>:
14737 <literallayout class='monospaced'>
14738 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14739 </literallayout>
14740 </para></listitem>
14741 <listitem><para id='push-determine-who-to-notify'>
14742 <emphasis>Determine Who to Notify:</emphasis>
14743 Determine the maintainer or the mailing list
14744 that you need to notify for the change.</para>
14745
14746 <para>Before submitting any change, you need to be sure
14747 who the maintainer is or what mailing list that you need
14748 to notify.
14749 Use either these methods to find out:
14750 <itemizedlist>
14751 <listitem><para>
14752 <emphasis>Maintenance File:</emphasis>
14753 Examine the <filename>maintainers.inc</filename>
14754 file, which is located in the
14755 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14756 at
14757 <filename>meta/conf/distro/include</filename>,
14758 to see who is responsible for code.
14759 </para></listitem>
14760 <listitem><para>
14761 <emphasis>Search by File:</emphasis>
14762 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14763 you can enter the following command to bring up a
14764 short list of all commits against a specific file:
14765 <literallayout class='monospaced'>
14766 git shortlog -- <replaceable>filename</replaceable>
14767 </literallayout>
14768 Just provide the name of the file for which you
14769 are interested.
14770 The information returned is not ordered by history
14771 but does include a list of everyone who has
14772 committed grouped by name.
14773 From the list, you can see who is responsible for
14774 the bulk of the changes against the file.
14775 </para></listitem>
14776 <listitem><para>
14777 <emphasis>Examine the List of Mailing Lists:</emphasis>
14778 For a list of the Yocto Project and related mailing
14779 lists, see the
14780 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14781 section in the Yocto Project Reference Manual.
14782 </para></listitem>
14783 </itemizedlist>
14784 </para></listitem>
14785 <listitem><para>
14786 <emphasis>Make a Pull Request:</emphasis>
14787 Notify the maintainer or the mailing list that you have
14788 pushed a change by making a pull request.</para>
14789
14790 <para>The Yocto Project provides two scripts that
14791 conveniently let you generate and send pull requests to the
14792 Yocto Project.
14793 These scripts are <filename>create-pull-request</filename>
14794 and <filename>send-pull-request</filename>.
14795 You can find these scripts in the
14796 <filename>scripts</filename> directory within the
14797 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14798 (e.g. <filename>~/poky/scripts</filename>).
14799 </para>
14800
14801 <para>Using these scripts correctly formats the requests
14802 without introducing any whitespace or HTML formatting.
14803 The maintainer that receives your patches either directly
14804 or through the mailing list needs to be able to save and
14805 apply them directly from your emails.
14806 Using these scripts is the preferred method for sending
14807 patches.</para>
14808
14809 <para>First, create the pull request.
14810 For example, the following command runs the script,
14811 specifies the upstream repository in the contrib directory
14812 into which you pushed the change, and provides a subject
14813 line in the created patch files:
14814 <literallayout class='monospaced'>
14815 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14816 </literallayout>
14817 Running this script forms
14818 <filename>*.patch</filename> files in a folder named
14819 <filename>pull-</filename><replaceable>PID</replaceable>
14820 in the current directory.
14821 One of the patch files is a cover letter.</para>
14822
14823 <para>Before running the
14824 <filename>send-pull-request</filename> script, you must
14825 edit the cover letter patch to insert information about
14826 your change.
14827 After editing the cover letter, send the pull request.
14828 For example, the following command runs the script and
14829 specifies the patch directory and email address.
14830 In this example, the email address is a mailing list:
14831 <literallayout class='monospaced'>
14832 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14833 </literallayout>
14834 You need to follow the prompts as the script is
14835 interactive.
14836 <note>
14837 For help on using these scripts, simply provide the
14838 <filename>-h</filename> argument as follows:
14839 <literallayout class='monospaced'>
14840 $ poky/scripts/create-pull-request -h
14841 $ poky/scripts/send-pull-request -h
14842 </literallayout>
14843 </note>
14844 </para></listitem>
14845 </orderedlist>
14846 </para>
14847 </section>
14848
14849 <section id='submitting-a-patch'>
14850 <title>Using Email to Submit a Patch</title>
14851
14852 <para>
14853 You can submit patches without using the
14854 <filename>create-pull-request</filename> and
14855 <filename>send-pull-request</filename> scripts described in the
14856 previous section.
14857 However, keep in mind, the preferred method is to use the scripts.
14858 </para>
14859
14860 <para>
14861 Depending on the components changed, you need to submit the email
14862 to a specific mailing list.
14863 For some guidance on which mailing list to use, see the
14864 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14865 at the beginning of this section.
14866 For a description of all the available mailing lists, see the
14867 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14868 section in the Yocto Project Reference Manual.
14869 </para>
14870
14871 <para>
14872 Here is the general procedure on how to submit a patch through
14873 email without using the scripts:
14874 <orderedlist>
14875 <listitem><para>
14876 <emphasis>Make Your Changes Locally:</emphasis>
14877 Make your changes in your local Git repository.
14878 You should make small, controlled, isolated changes.
14879 Keeping changes small and isolated aids review,
14880 makes merging/rebasing easier and keeps the change
14881 history clean should anyone need to refer to it in
14882 future.
14883 </para></listitem>
14884 <listitem><para>
14885 <emphasis>Stage Your Changes:</emphasis>
14886 Stage your changes by using the <filename>git add</filename>
14887 command on each file you changed.
14888 </para></listitem>
14889 <listitem><para>
14890 <emphasis>Commit Your Changes:</emphasis>
14891 Commit the change by using the
14892 <filename>git commit --signoff</filename> command.
14893 Using the <filename>--signoff</filename> option identifies
14894 you as the person making the change and also satisfies
14895 the Developer's Certificate of Origin (DCO) shown earlier.
14896 </para>
14897
14898 <para>When you form a commit, you must follow certain
14899 standards established by the Yocto Project development
14900 team.
14901 See
14902 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14903 in the previous section for information on how to
14904 provide commit information that meets Yocto Project
14905 commit message standards.
14906 </para></listitem>
14907 <listitem><para>
14908 <emphasis>Format the Commit:</emphasis>
14909 Format the commit into an email message.
14910 To format commits, use the
14911 <filename>git format-patch</filename> command.
14912 When you provide the command, you must include a revision
14913 list or a number of patches as part of the command.
14914 For example, either of these two commands takes your most
14915 recent single commit and formats it as an email message in
14916 the current directory:
14917 <literallayout class='monospaced'>
14918 $ git format-patch -1
14919 </literallayout>
14920 or
14921 <literallayout class='monospaced'>
14922 $ git format-patch HEAD~
14923 </literallayout></para>
14924
14925 <para>After the command is run, the current directory
14926 contains a numbered <filename>.patch</filename> file for
14927 the commit.</para>
14928
14929 <para>If you provide several commits as part of the
14930 command, the <filename>git format-patch</filename> command
14931 produces a series of numbered files in the current
14932 directory – one for each commit.
14933 If you have more than one patch, you should also use the
14934 <filename>--cover</filename> option with the command,
14935 which generates a cover letter as the first "patch" in
14936 the series.
14937 You can then edit the cover letter to provide a
14938 description for the series of patches.
14939 For information on the
14940 <filename>git format-patch</filename> command,
14941 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14942 using the <filename>man git-format-patch</filename>
14943 command.
14944 <note>
14945 If you are or will be a frequent contributor to the
14946 Yocto Project or to OpenEmbedded, you might consider
14947 requesting a contrib area and the necessary associated
14948 rights.
14949 </note>
14950 </para></listitem>
14951 <listitem><para>
14952 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14953 Import the files into your mail client by using the
14954 <filename>git send-email</filename> command.
14955 <note>
14956 In order to use <filename>git send-email</filename>,
14957 you must have the proper Git packages installed on
14958 your host.
14959 For Ubuntu, Debian, and Fedora the package is
14960 <filename>git-email</filename>.
14961 </note></para>
14962
14963 <para>The <filename>git send-email</filename> command
14964 sends email by using a local or remote Mail Transport Agent
14965 (MTA) such as <filename>msmtp</filename>,
14966 <filename>sendmail</filename>, or through a direct
14967 <filename>smtp</filename> configuration in your Git
14968 <filename>~/.gitconfig</filename> file.
14969 If you are submitting patches through email only, it is
14970 very important that you submit them without any whitespace
14971 or HTML formatting that either you or your mailer
14972 introduces.
14973 The maintainer that receives your patches needs to be able
14974 to save and apply them directly from your emails.
14975 A good way to verify that what you are sending will be
14976 applicable by the maintainer is to do a dry run and send
14977 them to yourself and then save and apply them as the
14978 maintainer would.</para>
14979
14980 <para>The <filename>git send-email</filename> command is
14981 the preferred method for sending your patches using
14982 email since there is no risk of compromising whitespace
14983 in the body of the message, which can occur when you use
14984 your own mail client.
14985 The command also has several options that let you
14986 specify recipients and perform further editing of the
14987 email message.
14988 For information on how to use the
14989 <filename>git send-email</filename> command,
14990 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14991 the <filename>man git-send-email</filename> command.
14992 </para></listitem>
14993 </orderedlist>
14994 </para>
14995 </section>
14996 </section>
14997 </section>
14998
14999 <section id='working-with-licenses'>
15000 <title>Working With Licenses</title>
15001
15002 <para>
15003 As mentioned in the
15004 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
15005 section in the Yocto Project Overview and Concepts Manual,
15006 open source projects are open to the public and they
15007 consequently have different licensing structures in place.
15008 This section describes the mechanism by which the
15009 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
15010 tracks changes to licensing text and covers how to maintain open
15011 source license compliance during your project's lifecycle.
15012 The section also describes how to enable commercially licensed
15013 recipes, which by default are disabled.
15014 </para>
15015
15016 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
15017 <title>Tracking License Changes</title>
15018
15019 <para>
15020 The license of an upstream project might change in the future.
15021 In order to prevent these changes going unnoticed, the
15022 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
15023 variable tracks changes to the license text. The checksums are
15024 validated at the end of the configure step, and if the
15025 checksums do not match, the build will fail.
15026 </para>
15027
15028 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
15029 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
15030
15031 <para>
15032 The <filename>LIC_FILES_CHKSUM</filename>
15033 variable contains checksums of the license text in the
15034 source code for the recipe.
15035 Following is an example of how to specify
15036 <filename>LIC_FILES_CHKSUM</filename>:
15037 <literallayout class='monospaced'>
15038 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
15039 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
15040 file://licfile2.txt;endline=50;md5=zzzz \
15041 ..."
15042 </literallayout>
15043 <note><title>Notes</title>
15044 <itemizedlist>
15045 <listitem><para>
15046 When using "beginline" and "endline", realize
15047 that line numbering begins with one and not
15048 zero.
15049 Also, the included lines are inclusive (i.e.
15050 lines five through and including 29 in the
15051 previous example for
15052 <filename>licfile1.txt</filename>).
15053 </para></listitem>
15054 <listitem><para>
15055 When a license check fails, the selected license
15056 text is included as part of the QA message.
15057 Using this output, you can determine the exact
15058 start and finish for the needed license text.
15059 </para></listitem>
15060 </itemizedlist>
15061 </note>
15062 </para>
15063
15064 <para>
15065 The build system uses the
15066 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
15067 variable as the default directory when searching files
15068 listed in <filename>LIC_FILES_CHKSUM</filename>.
15069 The previous example employs the default directory.
15070 </para>
15071
15072 <para>
15073 Consider this next example:
15074 <literallayout class='monospaced'>
15075 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
15076 md5=bb14ed3c4cda583abc85401304b5cd4e"
15077 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
15078 </literallayout>
15079 </para>
15080
15081 <para>
15082 The first line locates a file in
15083 <filename>${S}/src/ls.c</filename> and isolates lines five
15084 through 16 as license text.
15085 The second line refers to a file in
15086 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
15087 </para>
15088
15089 <para>
15090 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
15091 mandatory for all recipes, unless the
15092 <filename>LICENSE</filename> variable is set to "CLOSED".
15093 </para>
15094 </section>
15095
15096 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
15097 <title>Explanation of Syntax</title>
15098
15099 <para>
15100 As mentioned in the previous section, the
15101 <filename>LIC_FILES_CHKSUM</filename> variable lists all
15102 the important files that contain the license text for the
15103 source code.
15104 It is possible to specify a checksum for an entire file,
15105 or a specific section of a file (specified by beginning and
15106 ending line numbers with the "beginline" and "endline"
15107 parameters, respectively).
15108 The latter is useful for source files with a license
15109 notice header, README documents, and so forth.
15110 If you do not use the "beginline" parameter, then it is
15111 assumed that the text begins on the first line of the file.
15112 Similarly, if you do not use the "endline" parameter,
15113 it is assumed that the license text ends with the last
15114 line of the file.
15115 </para>
15116
15117 <para>
15118 The "md5" parameter stores the md5 checksum of the license
15119 text.
15120 If the license text changes in any way as compared to
15121 this parameter then a mismatch occurs.
15122 This mismatch triggers a build failure and notifies
15123 the developer.
15124 Notification allows the developer to review and address
15125 the license text changes.
15126 Also note that if a mismatch occurs during the build,
15127 the correct md5 checksum is placed in the build log and
15128 can be easily copied to the recipe.
15129 </para>
15130
15131 <para>
15132 There is no limit to how many files you can specify using
15133 the <filename>LIC_FILES_CHKSUM</filename> variable.
15134 Generally, however, every project requires a few
15135 specifications for license tracking.
15136 Many projects have a "COPYING" file that stores the
15137 license information for all the source code files.
15138 This practice allows you to just track the "COPYING"
15139 file as long as it is kept up to date.
15140 <note><title>Tips</title>
15141 <itemizedlist>
15142 <listitem><para>
15143 If you specify an empty or invalid "md5"
15144 parameter,
15145 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
15146 returns an md5 mis-match
15147 error and displays the correct "md5" parameter
15148 value during the build.
15149 The correct parameter is also captured in
15150 the build log.
15151 </para></listitem>
15152 <listitem><para>
15153 If the whole file contains only license text,
15154 you do not need to use the "beginline" and
15155 "endline" parameters.
15156 </para></listitem>
15157 </itemizedlist>
15158 </note>
15159 </para>
15160 </section>
15161 </section>
15162
15163 <section id="enabling-commercially-licensed-recipes">
15164 <title>Enabling Commercially Licensed Recipes</title>
15165
15166 <para>
15167 By default, the OpenEmbedded build system disables
15168 components that have commercial or other special licensing
15169 requirements.
15170 Such requirements are defined on a
15171 recipe-by-recipe basis through the
15172 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
15173 variable definition in the affected recipe.
15174 For instance, the
15175 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15176 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015177 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015178 LICENSE_FLAGS = "commercial"
15179 </literallayout>
15180 Here is a slightly more complicated example that contains both
15181 an explicit recipe name and version (after variable expansion):
15182 <literallayout class='monospaced'>
15183 LICENSE_FLAGS = "license_${PN}_${PV}"
15184 </literallayout>
15185 In order for a component restricted by a
15186 <filename>LICENSE_FLAGS</filename> definition to be enabled and
15187 included in an image, it needs to have a matching entry in the
15188 global
15189 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
15190 variable, which is a variable typically defined in your
15191 <filename>local.conf</filename> file.
15192 For example, to enable the
15193 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15194 package, you could add either the string
15195 "commercial_gst-plugins-ugly" or the more general string
15196 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
15197 See the
15198 "<link linkend='license-flag-matching'>License Flag Matching</link>"
15199 section for a full
15200 explanation of how <filename>LICENSE_FLAGS</filename> matching
15201 works.
15202 Here is the example:
15203 <literallayout class='monospaced'>
15204 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
15205 </literallayout>
15206 Likewise, to additionally enable the package built from the
15207 recipe containing
15208 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
15209 and assuming that the actual recipe name was
15210 <filename>emgd_1.10.bb</filename>, the following string would
15211 enable that package as well as the original
15212 <filename>gst-plugins-ugly</filename> package:
15213 <literallayout class='monospaced'>
15214 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
15215 </literallayout>
15216 As a convenience, you do not need to specify the complete
15217 license string in the whitelist for every package.
15218 You can use an abbreviated form, which consists
15219 of just the first portion or portions of the license
15220 string before the initial underscore character or characters.
15221 A partial string will match any license that contains the
15222 given string as the first portion of its license.
15223 For example, the following whitelist string will also match
15224 both of the packages previously mentioned as well as any other
15225 packages that have licenses starting with "commercial" or
15226 "license".
15227 <literallayout class='monospaced'>
15228 LICENSE_FLAGS_WHITELIST = "commercial license"
15229 </literallayout>
15230 </para>
15231
15232 <section id="license-flag-matching">
15233 <title>License Flag Matching</title>
15234
15235 <para>
15236 License flag matching allows you to control what recipes
15237 the OpenEmbedded build system includes in the build.
15238 Fundamentally, the build system attempts to match
15239 <filename>LICENSE_FLAGS</filename> strings found in recipes
15240 against <filename>LICENSE_FLAGS_WHITELIST</filename>
15241 strings found in the whitelist.
15242 A match causes the build system to include a recipe in the
15243 build, while failure to find a match causes the build
15244 system to exclude a recipe.
15245 </para>
15246
15247 <para>
15248 In general, license flag matching is simple.
15249 However, understanding some concepts will help you
15250 correctly and effectively use matching.
15251 </para>
15252
15253 <para>
15254 Before a flag
15255 defined by a particular recipe is tested against the
15256 contents of the whitelist, the expanded string
15257 <filename>_${PN}</filename> is appended to the flag.
15258 This expansion makes each
15259 <filename>LICENSE_FLAGS</filename> value recipe-specific.
15260 After expansion, the string is then matched against the
15261 whitelist.
15262 Thus, specifying
15263 <filename>LICENSE_FLAGS = "commercial"</filename>
15264 in recipe "foo", for example, results in the string
15265 <filename>"commercial_foo"</filename>.
15266 And, to create a match, that string must appear in the
15267 whitelist.
15268 </para>
15269
15270 <para>
15271 Judicious use of the <filename>LICENSE_FLAGS</filename>
15272 strings and the contents of the
15273 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
15274 allows you a lot of flexibility for including or excluding
15275 recipes based on licensing.
15276 For example, you can broaden the matching capabilities by
15277 using license flags string subsets in the whitelist.
15278 <note>
15279 When using a string subset, be sure to use the part of
15280 the expanded string that precedes the appended
15281 underscore character (e.g.
15282 <filename>usethispart_1.3</filename>,
15283 <filename>usethispart_1.4</filename>, and so forth).
15284 </note>
15285 For example, simply specifying the string "commercial" in
15286 the whitelist matches any expanded
15287 <filename>LICENSE_FLAGS</filename> definition that starts
15288 with the string "commercial" such as "commercial_foo" and
15289 "commercial_bar", which are the strings the build system
15290 automatically generates for hypothetical recipes named
15291 "foo" and "bar" assuming those recipes simply specify the
15292 following:
15293 <literallayout class='monospaced'>
15294 LICENSE_FLAGS = "commercial"
15295 </literallayout>
15296 Thus, you can choose to exhaustively
15297 enumerate each license flag in the whitelist and
15298 allow only specific recipes into the image, or
15299 you can use a string subset that causes a broader range of
15300 matches to allow a range of recipes into the image.
15301 </para>
15302
15303 <para>
15304 This scheme works even if the
15305 <filename>LICENSE_FLAGS</filename> string already
15306 has <filename>_${PN}</filename> appended.
15307 For example, the build system turns the license flag
15308 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
15309 would match both the general "commercial" and the specific
15310 "commercial_1.2_foo" strings found in the whitelist, as
15311 expected.
15312 </para>
15313
15314 <para>
15315 Here are some other scenarios:
15316 <itemizedlist>
15317 <listitem><para>
15318 You can specify a versioned string in the recipe
15319 such as "commercial_foo_1.2" in a "foo" recipe.
15320 The build system expands this string to
15321 "commercial_foo_1.2_foo".
15322 Combine this license flag with a whitelist that has
15323 the string "commercial" and you match the flag
15324 along with any other flag that starts with the
15325 string "commercial".
15326 </para></listitem>
15327 <listitem><para>
15328 Under the same circumstances, you can use
15329 "commercial_foo" in the whitelist and the build
15330 system not only matches "commercial_foo_1.2" but
15331 also matches any license flag with the string
15332 "commercial_foo", regardless of the version.
15333 </para></listitem>
15334 <listitem><para>
15335 You can be very specific and use both the
15336 package and version parts in the whitelist (e.g.
15337 "commercial_foo_1.2") to specifically match a
15338 versioned recipe.
15339 </para></listitem>
15340 </itemizedlist>
15341 </para>
15342 </section>
15343
15344 <section id="other-variables-related-to-commercial-licenses">
15345 <title>Other Variables Related to Commercial Licenses</title>
15346
15347 <para>
15348 Other helpful variables related to commercial
15349 license handling exist and are defined in the
15350 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
15351 <literallayout class='monospaced'>
15352 COMMERCIAL_AUDIO_PLUGINS ?= ""
15353 COMMERCIAL_VIDEO_PLUGINS ?= ""
15354 </literallayout>
15355 If you want to enable these components, you can do so by
15356 making sure you have statements similar to the following
15357 in your <filename>local.conf</filename> configuration file:
15358 <literallayout class='monospaced'>
15359 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
15360 gst-plugins-ugly-mpegaudioparse"
15361 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
15362 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
15363 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
15364 </literallayout>
15365 Of course, you could also create a matching whitelist
15366 for those components using the more general "commercial"
15367 in the whitelist, but that would also enable all the
15368 other packages with <filename>LICENSE_FLAGS</filename>
15369 containing "commercial", which you may or may not want:
15370 <literallayout class='monospaced'>
15371 LICENSE_FLAGS_WHITELIST = "commercial"
15372 </literallayout>
15373 </para>
15374
15375 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040015376 Specifying audio and video plugins as part of the
Brad Bishop316dfdd2018-06-25 12:45:53 -040015377 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
15378 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
15379 (along with the enabling
15380 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
Brad Bishopc342db32019-05-15 21:57:59 -040015381 plugins or components into built images, thus adding
Brad Bishop316dfdd2018-06-25 12:45:53 -040015382 support for media formats or components.
15383 </para>
15384 </section>
15385 </section>
15386
15387 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
15388 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
15389
15390 <para>
15391 One of the concerns for a development organization using open source
15392 software is how to maintain compliance with various open source
15393 licensing during the lifecycle of the product.
15394 While this section does not provide legal advice or
15395 comprehensively cover all scenarios, it does
15396 present methods that you can use to
15397 assist you in meeting the compliance requirements during a software
15398 release.
15399 </para>
15400
15401 <para>
15402 With hundreds of different open source licenses that the Yocto
15403 Project tracks, it is difficult to know the requirements of each
15404 and every license.
15405 However, the requirements of the major FLOSS licenses can begin
15406 to be covered by
15407 assuming that three main areas of concern exist:
15408 <itemizedlist>
15409 <listitem><para>Source code must be provided.</para></listitem>
15410 <listitem><para>License text for the software must be
15411 provided.</para></listitem>
15412 <listitem><para>Compilation scripts and modifications to the
15413 source code must be provided.
15414 </para></listitem>
15415 </itemizedlist>
15416 There are other requirements beyond the scope of these
15417 three and the methods described in this section
15418 (e.g. the mechanism through which source code is distributed).
15419 </para>
15420
15421 <para>
15422 As different organizations have different methods of complying with
15423 open source licensing, this section is not meant to imply that
15424 there is only one single way to meet your compliance obligations,
15425 but rather to describe one method of achieving compliance.
15426 The remainder of this section describes methods supported to meet the
15427 previously mentioned three requirements.
15428 Once you take steps to meet these requirements,
15429 and prior to releasing images, sources, and the build system,
15430 you should audit all artifacts to ensure completeness.
15431 <note>
15432 The Yocto Project generates a license manifest during
15433 image creation that is located
15434 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
15435 to assist with any audits.
15436 </note>
15437 </para>
15438
15439 <section id='providing-the-source-code'>
15440 <title>Providing the Source Code</title>
15441
15442 <para>
15443 Compliance activities should begin before you generate the
15444 final image.
15445 The first thing you should look at is the requirement that
15446 tops the list for most compliance groups - providing
15447 the source.
15448 The Yocto Project has a few ways of meeting this
15449 requirement.
15450 </para>
15451
15452 <para>
15453 One of the easiest ways to meet this requirement is
15454 to provide the entire
15455 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
15456 used by the build.
15457 This method, however, has a few issues.
15458 The most obvious is the size of the directory since it includes
15459 all sources used in the build and not just the source used in
15460 the released image.
15461 It will include toolchain source, and other artifacts, which
15462 you would not generally release.
15463 However, the more serious issue for most companies is accidental
15464 release of proprietary software.
15465 The Yocto Project provides an
15466 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
15467 class to help avoid some of these concerns.
15468 </para>
15469
15470 <para>
15471 Before you employ <filename>DL_DIR</filename> or the
15472 <filename>archiver</filename> class, you need to decide how
15473 you choose to provide source.
15474 The source <filename>archiver</filename> class can generate
15475 tarballs and SRPMs and can create them with various levels of
15476 compliance in mind.
15477 </para>
15478
15479 <para>
15480 One way of doing this (but certainly not the only way) is to
15481 release just the source as a tarball.
15482 You can do this by adding the following to the
15483 <filename>local.conf</filename> file found in the
15484 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15485 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015486 INHERIT += "archiver"
15487 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015488 </literallayout>
15489 During the creation of your image, the source from all
15490 recipes that deploy packages to the image is placed within
15491 subdirectories of
15492 <filename>DEPLOY_DIR/sources</filename> based on the
15493 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15494 for each recipe.
15495 Releasing the entire directory enables you to comply with
15496 requirements concerning providing the unmodified source.
15497 It is important to note that the size of the directory can
15498 get large.
15499 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015500
Brad Bishop316dfdd2018-06-25 12:45:53 -040015501 <para>
15502 A way to help mitigate the size issue is to only release
15503 tarballs for licenses that require the release of
15504 source.
15505 Let us assume you are only concerned with GPL code as
15506 identified by running the following script:
15507 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015508 # Script to archive a subset of packages matching specific license(s)
15509 # Source and license files are copied into sub folders of package folder
15510 # Must be run from build folder
15511 #!/bin/bash
15512 src_release_dir="source-release"
15513 mkdir -p $src_release_dir
15514 for a in tmp/deploy/sources/*; do
15515 for d in $a/*; do
15516 # Get package name from path
15517 p=`basename $d`
15518 p=${p%-*}
15519 p=${p%-*}
15520 # Only archive GPL packages (update *GPL* regex for your license check)
15521 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15522 if [ $numfiles -gt 1 ]; then
15523 echo Archiving $p
15524 mkdir -p $src_release_dir/$p/source
15525 cp $d/* $src_release_dir/$p/source 2> /dev/null
15526 mkdir -p $src_release_dir/$p/license
15527 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15528 fi
15529 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015530 done
15531 </literallayout>
15532 At this point, you could create a tarball from the
15533 <filename>gpl_source_release</filename> directory and
15534 provide that to the end user.
15535 This method would be a step toward achieving compliance
15536 with section 3a of GPLv2 and with section 6 of GPLv3.
15537 </para>
15538 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015539
Brad Bishop316dfdd2018-06-25 12:45:53 -040015540 <section id='providing-license-text'>
15541 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015542
Brad Bishop316dfdd2018-06-25 12:45:53 -040015543 <para>
15544 One requirement that is often overlooked is inclusion
15545 of license text.
15546 This requirement also needs to be dealt with prior to
15547 generating the final image.
15548 Some licenses require the license text to accompany
15549 the binary.
15550 You can achieve this by adding the following to your
15551 <filename>local.conf</filename> file:
15552 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015553 COPY_LIC_MANIFEST = "1"
15554 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015555 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015556 </literallayout>
15557 Adding these statements to the configuration file ensures
15558 that the licenses collected during package generation
15559 are included on your image.
15560 <note>
15561 <para>Setting all three variables to "1" results in the
15562 image having two copies of the same license file.
15563 One copy resides in
15564 <filename>/usr/share/common-licenses</filename> and
15565 the other resides in
15566 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015567
Brad Bishop316dfdd2018-06-25 12:45:53 -040015568 <para>The reason for this behavior is because
15569 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15570 and
15571 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15572 add a copy of the license when the image is built but do
15573 not offer a path for adding licenses for newly installed
15574 packages to an image.
15575 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15576 adds a separate package and an upgrade path for adding
15577 licenses to an image.</para>
15578 </note>
15579 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015580
Brad Bishop316dfdd2018-06-25 12:45:53 -040015581 <para>
15582 As the source <filename>archiver</filename> class has already
15583 archived the original
15584 unmodified source that contains the license files,
15585 you would have already met the requirements for inclusion
15586 of the license information with source as defined by the GPL
15587 and other open source licenses.
15588 </para>
15589 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015590
Brad Bishop316dfdd2018-06-25 12:45:53 -040015591 <section id='providing-compilation-scripts-and-source-code-modifications'>
15592 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015593
Brad Bishop316dfdd2018-06-25 12:45:53 -040015594 <para>
15595 At this point, we have addressed all we need to
15596 prior to generating the image.
15597 The next two requirements are addressed during the final
15598 packaging of the release.
15599 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015600
Brad Bishop316dfdd2018-06-25 12:45:53 -040015601 <para>
15602 By releasing the version of the OpenEmbedded build system
15603 and the layers used during the build, you will be providing both
15604 compilation scripts and the source code modifications in one
15605 step.
15606 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015607
Brad Bishop316dfdd2018-06-25 12:45:53 -040015608 <para>
15609 If the deployment team has a
15610 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15611 and a distro layer, and those those layers are used to patch,
15612 compile, package, or modify (in any way) any open source
15613 software included in your released images, you
15614 might be required to release those layers under section 3 of
15615 GPLv2 or section 1 of GPLv3.
15616 One way of doing that is with a clean
15617 checkout of the version of the Yocto Project and layers used
15618 during your build.
15619 Here is an example:
15620 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015621 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15622 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015623 $ cd poky
15624 # We built using the release_branch for our layers
15625 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15626 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15627 # clean up the .git repos
15628 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015629 </literallayout>
15630 One thing a development organization might want to consider
15631 for end-user convenience is to modify
15632 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15633 ensure that when the end user utilizes the released build
15634 system to build an image, the development organization's
15635 layers are included in the <filename>bblayers.conf</filename>
15636 file automatically:
15637 <literallayout class='monospaced'>
15638 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015639 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015640 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015641
15642 BBPATH = "${TOPDIR}"
15643 BBFILES ?= ""
15644
15645 BBLAYERS ?= " \
15646 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015647 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015648 ##OEROOT##/meta-yocto-bsp \
15649 ##OEROOT##/meta-mylayer \
15650 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015651 </literallayout>
15652 Creating and providing an archive of the
15653 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15654 layers (recipes, configuration files, and so forth)
15655 enables you to meet your
15656 requirements to include the scripts to control compilation
15657 as well as any modifications to the original source.
15658 </para>
15659 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015660 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015661
15662 <section id='copying-licenses-that-do-not-exist'>
15663 <title>Copying Licenses that Do Not Exist</title>
15664
15665 <para>
15666 Some packages, such as the linux-firmware package, have many
15667 licenses that are not in any way common.
15668 You can avoid adding a lot of these types of common license
15669 files, which are only applicable to a specific package, by using
15670 the
15671 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15672 variable.
15673 Using this variable also avoids QA errors when you use a
15674 non-common, non-CLOSED license in a recipe.
15675 </para>
15676
15677 <para>
15678 The following is an example that uses the
15679 <filename>LICENSE.Abilis.txt</filename>
15680 file as the license from the fetched source:
15681 <literallayout class='monospaced'>
15682 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15683 </literallayout>
15684 </para>
15685 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015686 </section>
15687
15688 <section id='using-the-error-reporting-tool'>
15689 <title>Using the Error Reporting Tool</title>
15690
15691 <para>
15692 The error reporting tool allows you to
15693 submit errors encountered during builds to a central database.
15694 Outside of the build environment, you can use a web interface to
15695 browse errors, view statistics, and query for errors.
15696 The tool works using a client-server system where the client
15697 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015698 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015699 (e.g. <filename>poky</filename>).
15700 The server receives the information collected and saves it in a
15701 database.
15702 </para>
15703
15704 <para>
15705 A live instance of the error reporting server exists at
15706 <ulink url='http://errors.yoctoproject.org'></ulink>.
15707 This server exists so that when you want to get help with
15708 build failures, you can submit all of the information on the
15709 failure easily and then point to the URL in your bug report
15710 or send an email to the mailing list.
15711 <note>
15712 If you send error reports to this server, the reports become
15713 publicly visible.
15714 </note>
15715 </para>
15716
15717 <section id='enabling-and-using-the-tool'>
15718 <title>Enabling and Using the Tool</title>
15719
15720 <para>
15721 By default, the error reporting tool is disabled.
15722 You can enable it by inheriting the
15723 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15724 class by adding the following statement to the end of
15725 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015726 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015727 <literallayout class='monospaced'>
15728 INHERIT += "report-error"
15729 </literallayout>
15730 </para>
15731
15732 <para>
15733 By default, the error reporting feature stores information in
15734 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15735 However, you can specify a directory to use by adding the following
15736 to your <filename>local.conf</filename> file:
15737 <literallayout class='monospaced'>
15738 ERR_REPORT_DIR = "path"
15739 </literallayout>
15740 Enabling error reporting causes the build process to collect
15741 the errors and store them in a file as previously described.
15742 When the build system encounters an error, it includes a
15743 command as part of the console output.
15744 You can run the command to send the error file to the server.
15745 For example, the following command sends the errors to an
15746 upstream server:
15747 <literallayout class='monospaced'>
15748 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15749 </literallayout>
15750 In the previous example, the errors are sent to a public
15751 database available at
15752 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15753 used by the entire community.
15754 If you specify a particular server, you can send the errors
15755 to a different database.
15756 Use the following command for more information on available
15757 options:
15758 <literallayout class='monospaced'>
15759 $ send-error-report --help
15760 </literallayout>
15761 </para>
15762
15763 <para>
15764 When sending the error file, you are prompted to review the
15765 data being sent as well as to provide a name and optional
15766 email address.
15767 Once you satisfy these prompts, the command returns a link
15768 from the server that corresponds to your entry in the database.
15769 For example, here is a typical link:
15770 <literallayout class='monospaced'>
15771 http://errors.yoctoproject.org/Errors/Details/9522/
15772 </literallayout>
15773 Following the link takes you to a web interface where you can
15774 browse, query the errors, and view statistics.
15775 </para>
15776 </section>
15777
15778 <section id='disabling-the-tool'>
15779 <title>Disabling the Tool</title>
15780
15781 <para>
15782 To disable the error reporting feature, simply remove or comment
15783 out the following statement from the end of your
15784 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015785 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015786 <literallayout class='monospaced'>
15787 INHERIT += "report-error"
15788 </literallayout>
15789 </para>
15790 </section>
15791
15792 <section id='setting-up-your-own-error-reporting-server'>
15793 <title>Setting Up Your Own Error Reporting Server</title>
15794
15795 <para>
15796 If you want to set up your own error reporting server, you
15797 can obtain the code from the Git repository at
15798 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15799 Instructions on how to set it up are in the README document.
15800 </para>
15801 </section>
15802 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015803
15804 <section id="dev-using-wayland-and-weston">
15805 <title>Using Wayland and Weston</title>
15806
15807 <para>
15808 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15809 is a computer display server protocol that
15810 provides a method for compositing window managers to communicate
15811 directly with applications and video hardware and expects them to
15812 communicate with input hardware using other libraries.
15813 Using Wayland with supporting targets can result in better control
15814 over graphics frame rendering than an application might otherwise
15815 achieve.
15816 </para>
15817
15818 <para>
15819 The Yocto Project provides the Wayland protocol libraries and the
15820 reference
15821 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15822 compositor as part of its release.
15823 You can find the integrated packages in the
15824 <filename>meta</filename> layer of the
15825 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15826 Specifically, you can find the recipes that build both Wayland
15827 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15828 </para>
15829
15830 <para>
15831 You can build both the Wayland and Weston packages for use only
15832 with targets that accept the
15833 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15834 which is also known as Mesa DRI.
15835 This implies that you cannot build and use the packages if your
15836 target uses, for example, the
15837 <trademark class='registered'>Intel</trademark> Embedded Media
15838 and Graphics Driver
15839 (<trademark class='registered'>Intel</trademark> EMGD) that
15840 overrides Mesa DRI.
15841 <note>
15842 Due to lack of EGL support, Weston 1.0.3 will not run
15843 directly on the emulated QEMU hardware.
15844 However, this version of Weston will run under X emulation
15845 without issues.
15846 </note>
15847 </para>
15848
15849 <para>
15850 This section describes what you need to do to implement Wayland and
15851 use the Weston compositor when building an image for a supporting
15852 target.
15853 </para>
15854
15855 <section id="enabling-wayland-in-an-image">
15856 <title>Enabling Wayland in an Image</title>
15857
15858 <para>
15859 To enable Wayland, you need to enable it to be built and enable
15860 it to be included (installed) in the image.
15861 </para>
15862
15863 <section id="enable-building">
15864 <title>Building</title>
15865
15866 <para>
15867 To cause Mesa to build the <filename>wayland-egl</filename>
15868 platform and Weston to build Wayland with Kernel Mode
15869 Setting
15870 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15871 support, include the "wayland" flag in the
15872 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15873 statement in your <filename>local.conf</filename> file:
15874 <literallayout class='monospaced'>
15875 DISTRO_FEATURES_append = " wayland"
15876 </literallayout>
15877 <note>
15878 If X11 has been enabled elsewhere, Weston will build
15879 Wayland with X11 support
15880 </note>
15881 </para>
15882 </section>
15883
15884 <section id="enable-installation-in-an-image">
15885 <title>Installing</title>
15886
15887 <para>
15888 To install the Wayland feature into an image, you must
15889 include the following
15890 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15891 statement in your <filename>local.conf</filename> file:
15892 <literallayout class='monospaced'>
15893 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15894 </literallayout>
15895 </para>
15896 </section>
15897 </section>
15898
15899 <section id="running-weston">
15900 <title>Running Weston</title>
15901
15902 <para>
15903 To run Weston inside X11, enabling it as described earlier and
15904 building a Sato image is sufficient.
15905 If you are running your image under Sato, a Weston Launcher
15906 appears in the "Utility" category.
15907 </para>
15908
15909 <para>
15910 Alternatively, you can run Weston through the command-line
15911 interpretor (CLI), which is better suited for development work.
15912 To run Weston under the CLI, you need to do the following after
15913 your image is built:
15914 <orderedlist>
15915 <listitem><para>
15916 Run these commands to export
15917 <filename>XDG_RUNTIME_DIR</filename>:
15918 <literallayout class='monospaced'>
15919 mkdir -p /tmp/$USER-weston
15920 chmod 0700 /tmp/$USER-weston
15921 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15922 </literallayout>
15923 </para></listitem>
15924 <listitem><para>
15925 Launch Weston in the shell:
15926 <literallayout class='monospaced'>
15927 weston
15928 </literallayout></para></listitem>
15929 </orderedlist>
15930 </para>
15931 </section>
15932 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015933</chapter>
15934
15935<!--
15936vim: expandtab tw=80 ts=4
15937-->