blob: e9ce182a5915b398e61a3d1cad4fbb9697c5a451 [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>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDEPENDS'><filename>LAYERDEPENDS</filename></ulink>:
188 Lists all layers on which this layer depends (if any).
189 </para></listitem>
190 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400191 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERSERIES_COMPAT'><filename>LAYERSERIES_COMPAT</filename></ulink>:
192 Lists the
193 <ulink url='&YOCTO_WIKI_URL;/wiki/Releases'>Yocto Project</ulink>
194 releases for which the current version is
195 compatible.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800196 This variable is a good way to indicate if
197 your particular layer is current.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400198 </para></listitem>
199 </itemizedlist>
200 </para></listitem>
201 <listitem><para>
202 <emphasis>Add Content:</emphasis>
203 Depending on the type of layer, add the content.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204 If the layer adds support for a machine, add the machine
205 configuration in a <filename>conf/machine/</filename>
206 file within the layer.
207 If the layer adds distro policy, add the distro
208 configuration in a <filename>conf/distro/</filename>
209 file within the layer.
210 If the layer introduces new recipes, put the recipes
211 you need in <filename>recipes-*</filename>
212 subdirectories within the layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400213 <note>
214 For an explanation of layer hierarchy that
215 is compliant with the Yocto Project, see
216 the
217 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout'>Example Filesystem Layout</ulink>"
218 section in the Yocto Project Board
219 Support Package (BSP) Developer's Guide.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500220 </note>
221 </para></listitem>
222 <listitem><para>
223 <emphasis>Optionally Test for Compatibility:</emphasis>
224 If you want permission to use the Yocto Project
225 Compatibility logo with your layer or application that
226 uses your layer, perform the steps to apply for
227 compatibility.
228 See the
229 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
230 section for more information.
231 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232 </orderedlist>
233 </para>
234 </section>
235
236 <section id='best-practices-to-follow-when-creating-layers'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500237 <title>Following Best Practices When Creating Layers</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238
239 <para>
240 To create layers that are easier to maintain and that will
241 not impact builds for other machines, you should consider the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500242 information in the following list:
243 <itemizedlist>
244 <listitem><para>
245 <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis>
246 In other words, do not copy an entire recipe into your
247 layer and then modify it.
248 Rather, use an append file
249 (<filename>.bbappend</filename>) to override only those
250 parts of the original recipe you need to modify.
251 </para></listitem>
252 <listitem><para>
253 <emphasis>Avoid Duplicating Include Files:</emphasis>
254 Use append files (<filename>.bbappend</filename>)
255 for each recipe that uses an include file.
256 Or, if you are introducing a new recipe that requires
257 the included file, use the path relative to the
258 original layer directory to refer to the file.
259 For example, use
260 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
261 instead of
262 <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
263 If you're finding you have to overlay the include file,
264 it could indicate a deficiency in the include file in
265 the layer to which it originally belongs.
266 If this is the case, you should try to address that
267 deficiency instead of overlaying the include file.
268 For example, you could address this by getting the
269 maintainer of the include file to add a variable or
270 variables to make it easy to override the parts needing
271 to be overridden.
272 </para></listitem>
273 <listitem><para>
274 <emphasis>Structure Your Layers:</emphasis>
275 Proper use of overrides within append files and
276 placement of machine-specific files within your layer
277 can ensure that a build is not using the wrong Metadata
278 and negatively impacting a build for a different
279 machine.
280 Following are some examples:
281 <itemizedlist>
282 <listitem><para>
283 <emphasis>Modify Variables to Support a
284 Different Machine:</emphasis>
285 Suppose you have a layer named
286 <filename>meta-one</filename> that adds support
287 for building machine "one".
288 To do so, you use an append file named
289 <filename>base-files.bbappend</filename> and
290 create a dependency on "foo" by altering the
291 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
292 variable:
293 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294 DEPENDS = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500295 </literallayout>
296 The dependency is created during any build that
297 includes the layer
298 <filename>meta-one</filename>.
299 However, you might not want this dependency
300 for all machines.
301 For example, suppose you are building for
302 machine "two" but your
303 <filename>bblayers.conf</filename> file has the
304 <filename>meta-one</filename> layer included.
305 During the build, the
306 <filename>base-files</filename> for machine
307 "two" will also have the dependency on
308 <filename>foo</filename>.</para>
309 <para>To make sure your changes apply only when
310 building machine "one", use a machine override
311 with the <filename>DEPENDS</filename> statement:
312 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313 DEPENDS_one = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500314 </literallayout>
315 You should follow the same strategy when using
316 <filename>_append</filename> and
317 <filename>_prepend</filename> operations:
318 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500319 DEPENDS_append_one = " foo"
320 DEPENDS_prepend_one = "foo "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500321 </literallayout>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500322 As an actual example, here's a snippet from the
323 generic kernel include file
324 <filename>linux-yocto.inc</filename>,
325 wherein the kernel compile and link options are
326 adjusted in the case of a subset of the supported
327 architectures:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500328 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500329 DEPENDS_append_aarch64 = " libgcc"
330 KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
331 KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
332
333 DEPENDS_append_nios2 = " libgcc"
334 KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
335 KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
336
337 DEPENDS_append_arc = " libgcc"
338 KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
339 KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
340
341 KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500342 </literallayout>
343 <note>
344 Avoiding "+=" and "=+" and using
345 machine-specific
346 <filename>_append</filename>
347 and <filename>_prepend</filename> operations
348 is recommended as well.
349 </note>
350 </para></listitem>
351 <listitem><para>
352 <emphasis>Place Machine-Specific Files in
353 Machine-Specific Locations:</emphasis>
354 When you have a base recipe, such as
355 <filename>base-files.bb</filename>, that
356 contains a
357 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
358 statement to a file, you can use an append file
359 to cause the build to use your own version of
360 the file.
361 For example, an append file in your layer at
362 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
363 could extend
364 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
365 using
366 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
367 as follows:
368 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500370 </literallayout>
371 The build for machine "one" will pick up your
372 machine-specific file as long as you have the
373 file in
374 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
375 However, if you are building for a different
376 machine and the
377 <filename>bblayers.conf</filename> file includes
378 the <filename>meta-one</filename> layer and
379 the location of your machine-specific file is
380 the first location where that file is found
381 according to <filename>FILESPATH</filename>,
382 builds for all machines will also use that
383 machine-specific file.</para>
384 <para>You can make sure that a machine-specific
385 file is used for a particular machine by putting
386 the file in a subdirectory specific to the
387 machine.
388 For example, rather than placing the file in
389 <filename>meta-one/recipes-core/base-files/base-files/</filename>
390 as shown above, put it in
391 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
392 Not only does this make sure the file is used
393 only when building for machine "one", but the
394 build process locates the file more quickly.</para>
395 <para>In summary, you need to place all files
396 referenced from <filename>SRC_URI</filename>
397 in a machine-specific subdirectory within the
398 layer in order to restrict those files to
399 machine-specific builds.
400 </para></listitem>
401 </itemizedlist>
402 </para></listitem>
403 <listitem><para>
404 <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis>
405 If you want permission to use the
406 Yocto Project Compatibility logo with your layer
407 or application that uses your layer, perform the
408 steps to apply for compatibility.
409 See the
410 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
411 section for more information.
412 </para></listitem>
413 <listitem><para>
414 <emphasis>Follow the Layer Naming Convention:</emphasis>
415 Store custom layers in a Git repository that use the
416 <filename>meta-<replaceable>layer_name</replaceable></filename>
417 format.
418 </para></listitem>
419 <listitem><para>
420 <emphasis>Group Your Layers Locally:</emphasis>
421 Clone your repository alongside other cloned
422 <filename>meta</filename> directories from the
423 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
424 </para></listitem>
425 </itemizedlist>
426 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500427 </section>
428
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500429 <section id='making-sure-your-layer-is-compatible-with-yocto-project'>
430 <title>Making Sure Your Layer is Compatible With Yocto Project</title>
431
432 <para>
433 When you create a layer used with the Yocto Project, it is
434 advantageous to make sure that the layer interacts well with
435 existing Yocto Project layers (i.e. the layer is compatible
436 with the Yocto Project).
437 Ensuring compatibility makes the layer easy to be consumed
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500438 by others in the Yocto Project community and could allow you
439 permission to use the Yocto Project Compatible Logo.
440 <note>
441 Only Yocto Project member organizations are permitted to
442 use the Yocto Project Compatible Logo.
443 The logo is not available for general use.
444 For information on how to become a Yocto Project member
445 organization, see the
446 <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500447 </note>
448 </para>
449
450 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500451 The Yocto Project Compatibility Program consists of a layer
452 application process that requests permission to use the Yocto
453 Project Compatibility Logo for your layer and application.
454 The process consists of two parts:
455 <orderedlist>
456 <listitem><para>
457 Successfully passing a script
458 (<filename>yocto-check-layer</filename>) that
459 when run against your layer, tests it against
460 constraints based on experiences of how layers have
461 worked in the real world and where pitfalls have been
462 found.
463 Getting a "PASS" result from the script is required for
464 successful compatibility registration.
465 </para></listitem>
466 <listitem><para>
467 Completion of an application acceptance form, which
468 you can find at
469 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
470 </para></listitem>
471 </orderedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500472 </para>
473
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500474 <para>
475 To be granted permission to use the logo, you need to satisfy
476 the following:
477 <itemizedlist>
478 <listitem><para>
479 Be able to check the box indicating that you
480 got a "PASS" when running the script against your
481 layer.
482 </para></listitem>
483 <listitem><para>
484 Answer "Yes" to the questions on the form or have an
485 acceptable explanation for any questions answered "No".
486 </para></listitem>
487 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400488 Be a Yocto Project Member Organization.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500489 </para></listitem>
490 </itemizedlist>
491 </para>
492
493 <para>
494 The remainder of this section presents information on the
495 registration form and on the
496 <filename>yocto-check-layer</filename> script.
497 </para>
498
499 <section id='yocto-project-compatible-program-application'>
500 <title>Yocto Project Compatible Program Application</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500501
502 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500503 Use the form to apply for your layer's approval.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500504 Upon successful application, you can use the Yocto
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500505 Project Compatibility Logo with your layer and the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500506 application that uses your layer.
507 </para>
508
509 <para>
510 To access the form, use this link:
511 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
512 Follow the instructions on the form to complete your
513 application.
514 </para>
515
516 <para>
517 The application consists of the following sections:
518 <itemizedlist>
519 <listitem><para>
520 <emphasis>Contact Information:</emphasis>
521 Provide your contact information as the fields
522 require.
523 Along with your information, provide the
524 released versions of the Yocto Project for which
525 your layer is compatible.
526 </para></listitem>
527 <listitem><para>
528 <emphasis>Acceptance Criteria:</emphasis>
529 Provide "Yes" or "No" answers for each of the
530 items in the checklist.
531 Space exists at the bottom of the form for any
532 explanations for items for which you answered "No".
533 </para></listitem>
534 <listitem><para>
535 <emphasis>Recommendations:</emphasis>
536 Provide answers for the questions regarding Linux
537 kernel use and build success.
538 </para></listitem>
539 </itemizedlist>
540 </para>
541 </section>
542
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500543 <section id='yocto-check-layer-script'>
544 <title><filename>yocto-check-layer</filename> Script</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500545
546 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500547 The <filename>yocto-check-layer</filename> script
548 provides you a way to assess how compatible your layer is
549 with the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500550 You should run this script prior to using the form to
551 apply for compatibility as described in the previous
552 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 You need to achieve a "PASS" result in order to have
554 your application form successfully processed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500555 </para>
556
557 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400558 The script divides tests into three areas: COMMON, BSP,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500559 and DISTRO.
560 For example, given a distribution layer (DISTRO), the
561 layer must pass both the COMMON and DISTRO related tests.
562 Furthermore, if your layer is a BSP layer, the layer must
563 pass the COMMON and BSP set of tests.
564 </para>
565
566 <para>
567 To execute the script, enter the following commands from
568 your build directory:
569 <literallayout class='monospaced'>
570 $ source oe-init-build-env
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500571 $ yocto-check-layer <replaceable>your_layer_directory</replaceable>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500572 </literallayout>
573 Be sure to provide the actual directory for your layer
574 as part of the command.
575 </para>
576
577 <para>
578 Entering the command causes the script to determine the
579 type of layer and then to execute a set of specific
580 tests against the layer.
581 The following list overviews the test:
582 <itemizedlist>
583 <listitem><para>
584 <filename>common.test_readme</filename>:
585 Tests if a <filename>README</filename> file
586 exists in the layer and the file is not empty.
587 </para></listitem>
588 <listitem><para>
589 <filename>common.test_parse</filename>:
590 Tests to make sure that BitBake can parse the
591 files without error (i.e.
592 <filename>bitbake -p</filename>).
593 </para></listitem>
594 <listitem><para>
595 <filename>common.test_show_environment</filename>:
596 Tests that the global or per-recipe environment
597 is in order without errors (i.e.
598 <filename>bitbake -e</filename>).
599 </para></listitem>
600 <listitem><para>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500601 <filename>common.test_world</filename>:
602 Verifies that <filename>bitbake world</filename> works.
603 </para></listitem>
604 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500605 <filename>common.test_signatures</filename>:
606 Tests to be sure that BSP and DISTRO layers do not
607 come with recipes that change signatures.
608 </para></listitem>
609 <listitem><para>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500610 <filename>common.test_layerseries_compat</filename>:
611 Verifies layer compatibility is set properly.
612 </para></listitem>
613 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500614 <filename>bsp.test_bsp_defines_machines</filename>:
615 Tests if a BSP layer has machine configurations.
616 </para></listitem>
617 <listitem><para>
618 <filename>bsp.test_bsp_no_set_machine</filename>:
619 Tests to ensure a BSP layer does not set the
620 machine when the layer is added.
621 </para></listitem>
622 <listitem><para>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500623 <filename>bsp.test_machine_world</filename>:
624 Verifies that <filename>bitbake world</filename>
625 works regardless of which machine is selected.
626 </para></listitem>
627 <listitem><para>
628 <filename>bsp.test_machine_signatures</filename>:
629 Verifies that building for a particular machine
630 affects only the signature of tasks specific to that
631 machine.
632 </para></listitem>
633 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500634 <filename>distro.test_distro_defines_distros</filename>:
635 Tests if a DISTRO layer has distro configurations.
636 </para></listitem>
637 <listitem><para>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500638 <filename>distro.test_distro_no_set_distros</filename>:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500639 Tests to ensure a DISTRO layer does not set the
640 distribution when the layer is added.
641 </para></listitem>
642 </itemizedlist>
643 </para>
644 </section>
645 </section>
646
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500647 <section id='enabling-your-layer'>
648 <title>Enabling Your Layer</title>
649
650 <para>
651 Before the OpenEmbedded build system can use your new layer,
652 you need to enable it.
653 To enable your layer, simply add your layer's path to the
654 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
655 variable in your <filename>conf/bblayers.conf</filename> file,
656 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500657 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500658 The following example shows how to enable a layer named
659 <filename>meta-mylayer</filename>:
660 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400661 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
662 # changes incompatibly
663 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500664
665 BBPATH = "${TOPDIR}"
666 BBFILES ?= ""
667
668 BBLAYERS ?= " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400669 /home/<replaceable>user</replaceable>/poky/meta \
670 /home/<replaceable>user</replaceable>/poky/meta-poky \
671 /home/<replaceable>user</replaceable>/poky/meta-yocto-bsp \
672 /home/<replaceable>user</replaceable>/poky/meta-mylayer \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500673 "
674 </literallayout>
675 </para>
676
677 <para>
678 BitBake parses each <filename>conf/layer.conf</filename> file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400679 from the top down as specified in the
680 <filename>BBLAYERS</filename> variable
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500681 within the <filename>conf/bblayers.conf</filename> file.
682 During the processing of each
683 <filename>conf/layer.conf</filename> file, BitBake adds the
684 recipes, classes and configurations contained within the
685 particular layer to the source directory.
686 </para>
687 </section>
688
689 <section id='using-bbappend-files'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500690 <title>Using .bbappend Files in Your Layer</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500691
692 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500693 A recipe that appends Metadata to another recipe is called a
694 BitBake append file.
695 A BitBake append file uses the <filename>.bbappend</filename>
696 file type suffix, while the corresponding recipe to which
697 Metadata is being appended uses the <filename>.bb</filename>
698 file type suffix.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500699 </para>
700
701 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500702 You can use a <filename>.bbappend</filename> file in your
703 layer to make additions or changes to the content of another
704 layer's recipe without having to copy the other layer's
705 recipe into your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500706 Your <filename>.bbappend</filename> file resides in your layer,
707 while the main <filename>.bb</filename> recipe file to
708 which you are appending Metadata resides in a different layer.
709 </para>
710
711 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500712 Being able to append information to an existing recipe not only
713 avoids duplication, but also automatically applies recipe
714 changes from a different layer into your layer.
715 If you were copying recipes, you would have to manually merge
716 changes as they occur.
717 </para>
718
719 <para>
720 When you create an append file, you must use the same root
721 name as the corresponding recipe file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500722 For example, the append file
723 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
724 <filename>someapp_&DISTRO;.bb</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500725 This means the original recipe and append file names are
726 version number-specific.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500727 If the corresponding recipe is renamed to update to a newer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500728 version, you must also rename and possibly update
729 the corresponding <filename>.bbappend</filename> as well.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 During the build process, BitBake displays an error on starting
731 if it detects a <filename>.bbappend</filename> file that does
732 not have a corresponding recipe with a matching name.
733 See the
734 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
735 variable for information on how to handle this error.
736 </para>
737
738 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500739 As an example, consider the main formfactor recipe and a
740 corresponding formfactor append file both from the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500741 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500742 Here is the main formfactor recipe, which is named
743 <filename>formfactor_0.0.bb</filename> and located in the
744 "meta" layer at
745 <filename>meta/recipes-bsp/formfactor</filename>:
746 <literallayout class='monospaced'>
747 SUMMARY = "Device formfactor information"
748 SECTION = "base"
749 LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500750 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500751 PR = "r45"
752
753 SRC_URI = "file://config file://machconfig"
754 S = "${WORKDIR}"
755
756 PACKAGE_ARCH = "${MACHINE_ARCH}"
757 INHIBIT_DEFAULT_DEPS = "1"
758
759 do_install() {
760 # Install file only if it has contents
761 install -d ${D}${sysconfdir}/formfactor/
762 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
763 if [ -s "${S}/machconfig" ]; then
764 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
765 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500766 } </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500767 In the main recipe, note the
768 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
769 variable, which tells the OpenEmbedded build system where to
770 find files during the build.
771 </para>
772
773 <para>
774 Following is the append file, which is named
775 <filename>formfactor_0.0.bbappend</filename> and is from the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500776 Raspberry Pi BSP Layer named
777 <filename>meta-raspberrypi</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500778 The file is in the layer at
779 <filename>recipes-bsp/formfactor</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500780 <literallayout class='monospaced'>
781 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
782 </literallayout>
783 </para>
784
785 <para>
786 By default, the build system uses the
787 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
788 variable to locate files.
789 This append file extends the locations by setting the
790 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
791 variable.
792 Setting this variable in the <filename>.bbappend</filename>
793 file is the most reliable and recommended method for adding
794 directories to the search path used by the build system
795 to find files.
796 </para>
797
798 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500799 The statement in this example extends the directories to
800 include
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500801 <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>,
802 which resolves to a directory named
803 <filename>formfactor</filename> in the same directory
804 in which the append file resides (i.e.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500805 <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500806 This implies that you must have the supporting directory
807 structure set up that will contain any files or patches you
808 will be including from the layer.
809 </para>
810
811 <para>
812 Using the immediate expansion assignment operator
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500813 <filename>:=</filename> is important because of the reference
814 to <filename>THISDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500815 The trailing colon character is important as it ensures that
816 items in the list remain colon-separated.
817 <note>
818 <para>
819 BitBake automatically defines the
820 <filename>THISDIR</filename> variable.
821 You should never set this variable yourself.
822 Using "_prepend" as part of the
823 <filename>FILESEXTRAPATHS</filename> ensures your path
824 will be searched prior to other paths in the final
825 list.
826 </para>
827
828 <para>
829 Also, not all append files add extra files.
830 Many append files simply exist to add build options
831 (e.g. <filename>systemd</filename>).
832 For these cases, your append file would not even
833 use the <filename>FILESEXTRAPATHS</filename> statement.
834 </para>
835 </note>
836 </para>
837 </section>
838
839 <section id='prioritizing-your-layer'>
840 <title>Prioritizing Your Layer</title>
841
842 <para>
843 Each layer is assigned a priority value.
844 Priority values control which layer takes precedence if there
845 are recipe files with the same name in multiple layers.
846 For these cases, the recipe file from the layer with a higher
847 priority number takes precedence.
848 Priority values also affect the order in which multiple
849 <filename>.bbappend</filename> files for the same recipe are
850 applied.
851 You can either specify the priority manually, or allow the
852 build system to calculate it based on the layer's dependencies.
853 </para>
854
855 <para>
856 To specify the layer's priority manually, use the
857 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400858 variable and append the layer's root name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500859 <literallayout class='monospaced'>
860 BBFILE_PRIORITY_mylayer = "1"
861 </literallayout>
862 </para>
863
864 <note>
865 <para>It is possible for a recipe with a lower version number
866 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
867 in a layer that has a higher priority to take precedence.</para>
868 <para>Also, the layer priority does not currently affect the
869 precedence order of <filename>.conf</filename>
870 or <filename>.bbclass</filename> files.
871 Future versions of BitBake might address this.</para>
872 </note>
873 </section>
874
875 <section id='managing-layers'>
876 <title>Managing Layers</title>
877
878 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400879 You can use the BitBake layer management tool
880 <filename>bitbake-layers</filename> to provide a view
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500881 into the structure of recipes across a multi-layer project.
882 Being able to generate output that reports on configured layers
883 with their paths and priorities and on
884 <filename>.bbappend</filename> files and their applicable
885 recipes can help to reveal potential problems.
886 </para>
887
888 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400889 For help on the BitBake layer management tool, use the
890 following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500891 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400892 $ bitbake-layers --help
893 NOTE: Starting bitbake server...
894 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] &lt;subcommand&gt; ...
895
896 BitBake layers utility
897
898 optional arguments:
899 -d, --debug Enable debug output
900 -q, --quiet Print only errors
901 -F, --force Force add without recipe parse verification
902 --color COLOR Colorize output (where COLOR is auto, always, never)
903 -h, --help show this help message and exit
904
905 subcommands:
906 &lt;subcommand&gt;
907 show-layers show current configured layers.
908 show-overlayed list overlayed recipes (where the same recipe exists
909 in another layer)
910 show-recipes list available recipes, showing the layer they are
911 provided by
912 show-appends list bbappend files and recipe files they apply to
913 show-cross-depends Show dependencies between recipes that cross layer
914 boundaries.
915 add-layer Add one or more layers to bblayers.conf.
916 remove-layer Remove one or more layers from bblayers.conf.
917 flatten flatten layer configuration into a separate output
918 directory.
919 layerindex-fetch Fetches a layer from a layer index along with its
920 dependent layers, and adds them to conf/bblayers.conf.
921 layerindex-show-depends
922 Find layer dependencies from layer index.
923 create-layer Create a basic layer
924
925 Use bitbake-layers &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500926 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400927 </para>
928
929 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500930 The following list describes the available commands:
931 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400932 <listitem><para>
933 <emphasis><filename>help:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500934 Displays general help or help on a specified command.
935 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400936 <listitem><para>
937 <emphasis><filename>show-layers:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500938 Shows the current configured layers.
939 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400940 <listitem><para>
941 <emphasis><filename>show-overlayed:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500942 Lists overlayed recipes.
943 A recipe is overlayed when a recipe with the same name
944 exists in another layer that has a higher layer
945 priority.
946 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400947 <listitem><para>
948 <emphasis><filename>show-recipes:</filename></emphasis>
949 Lists available recipes and the layers that provide them.
950 </para></listitem>
951 <listitem><para>
952 <emphasis><filename>show-appends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500953 Lists <filename>.bbappend</filename> files and the
954 recipe files to which they apply.
955 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400956 <listitem><para>
957 <emphasis><filename>show-cross-depends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500958 Lists dependency relationships between recipes that
959 cross layer boundaries.
960 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400961 <listitem><para>
962 <emphasis><filename>add-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500963 Adds a layer to <filename>bblayers.conf</filename>.
964 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400965 <listitem><para>
966 <emphasis><filename>remove-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500967 Removes a layer from <filename>bblayers.conf</filename>
968 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400969 <listitem><para>
970 <emphasis><filename>flatten:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500971 Flattens the layer configuration into a separate output
972 directory.
973 Flattening your layer configuration builds a "flattened"
974 directory that contains the contents of all layers,
975 with any overlayed recipes removed and any
976 <filename>.bbappend</filename> files appended to the
977 corresponding recipes.
978 You might have to perform some manual cleanup of the
979 flattened layer as follows:
980 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400981 <listitem><para>
982 Non-recipe files (such as patches)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500983 are overwritten.
984 The flatten command shows a warning for these
985 files.
986 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400987 <listitem><para>
988 Anything beyond the normal layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500989 setup has been added to the
990 <filename>layer.conf</filename> file.
991 Only the lowest priority layer's
992 <filename>layer.conf</filename> is used.
993 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400994 <listitem><para>
995 Overridden and appended items from
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500996 <filename>.bbappend</filename> files need to be
997 cleaned up.
998 The contents of each
999 <filename>.bbappend</filename> end up in the
1000 flattened recipe.
1001 However, if there are appended or changed
1002 variable values, you need to tidy these up
1003 yourself.
1004 Consider the following example.
1005 Here, the <filename>bitbake-layers</filename>
1006 command adds the line
1007 <filename>#### bbappended ...</filename> so that
1008 you know where the following lines originate:
1009 <literallayout class='monospaced'>
1010 ...
1011 DESCRIPTION = "A useful utility"
1012 ...
1013 EXTRA_OECONF = "--enable-something"
1014 ...
1015
1016 #### bbappended from meta-anotherlayer ####
1017
1018 DESCRIPTION = "Customized utility"
1019 EXTRA_OECONF += "--enable-somethingelse"
1020 </literallayout>
1021 Ideally, you would tidy up these utilities as
1022 follows:
1023 <literallayout class='monospaced'>
1024 ...
1025 DESCRIPTION = "Customized utility"
1026 ...
1027 EXTRA_OECONF = "--enable-something --enable-somethingelse"
1028 ...
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001029 </literallayout>
1030 </para></listitem>
1031 </itemizedlist>
1032 </para></listitem>
1033 <listitem><para>
1034 <emphasis><filename>layerindex-fetch</filename>:</emphasis>
1035 Fetches a layer from a layer index, along with its
1036 dependent layers, and adds the layers to the
1037 <filename>conf/bblayers.conf</filename> file.
1038 </para></listitem>
1039 <listitem><para>
1040 <emphasis><filename>layerindex-show-depends</filename>:</emphasis>
1041 Finds layer dependencies from the layer index.
1042 </para></listitem>
1043 <listitem><para>
1044 <emphasis><filename>create-layer</filename>:</emphasis>
1045 Creates a basic layer.
1046 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001047 </itemizedlist>
1048 </para>
1049 </section>
1050
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001051 <section id='creating-a-general-layer-using-the-bitbake-layers-script'>
1052 <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001053
1054 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001055 The <filename>bitbake-layers</filename> script with the
1056 <filename>create-layer</filename> subcommand simplifies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001057 creating a new general layer.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001058 <note><title>Notes</title>
1059 <itemizedlist>
1060 <listitem><para>
1061 For information on BSP layers, see the
1062 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
1063 section in the Yocto Project Board Specific (BSP)
1064 Developer's Guide.
1065 </para></listitem>
1066 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001067 In order to use a layer with the OpenEmbedded
1068 build system, you need to add the layer to your
1069 <filename>bblayers.conf</filename> configuration
1070 file.
1071 See the
1072 "<link linkend='adding-a-layer-using-the-bitbake-layers-script'>Adding a Layer Using the <filename>bitbake-layers</filename> Script</link>"
1073 section for more information.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001074 </para></listitem>
1075 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001076 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001077 The default mode of the script's operation with this
1078 subcommand is to create a layer with the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001079 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001080 <listitem><para>A layer priority of 6.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001081 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001082 <listitem><para>A <filename>conf</filename>
1083 subdirectory that contains a
1084 <filename>layer.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001086 <listitem><para>
1087 A <filename>recipes-example</filename> subdirectory
1088 that contains a further subdirectory named
1089 <filename>example</filename>, which contains
1090 an <filename>example.bb</filename> recipe file.
1091 </para></listitem>
1092 <listitem><para>A <filename >COPYING.MIT</filename>,
1093 which is the license statement for the layer.
1094 The script assumes you want to use the MIT license,
1095 which is typical for most layers, for the contents of
1096 the layer itself.
1097 </para></listitem>
1098 <listitem><para>
1099 A <filename>README</filename> file, which is a file
1100 describing the contents of your new layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001101 </para></listitem>
1102 </itemizedlist>
1103 </para>
1104
1105 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001106 In its simplest form, you can use the following command form
1107 to create a layer.
1108 The command creates a layer whose name corresponds to
1109 <replaceable>your_layer_name</replaceable> in the current
1110 directory:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001111 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001112 $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001113 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001114 As an example, the following command creates a layer named
1115 <filename>meta-scottrif</filename> in your home directory:
1116 <literallayout class='monospaced'>
1117 $ cd /usr/home
1118 $ bitbake-layers create-layer meta-scottrif
1119 NOTE: Starting bitbake server...
1120 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
1121 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001122 </para>
1123
1124 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001125 If you want to set the priority of the layer to other than the
1126 default value of "6", you can either use the
1127 <filename>&dash;&dash;priority</filename> option or you can
1128 edit the
1129 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
1130 value in the <filename>conf/layer.conf</filename> after the
1131 script creates it.
1132 Furthermore, if you want to give the example recipe file
1133 some name other than the default, you can
1134 use the
1135 <filename>&dash;&dash;example-recipe-name</filename> option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001136 </para>
1137
1138 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001139 The easiest way to see how the
1140 <filename>bitbake-layers create-layer</filename> command
1141 works is to experiment with the script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001142 You can also read the usage information by entering the
1143 following:
1144 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001145 $ bitbake-layers create-layer --help
1146 NOTE: Starting bitbake server...
1147 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
1148 [--example-recipe-name EXAMPLERECIPE]
1149 layerdir
1150
1151 Create a basic layer
1152
1153 positional arguments:
1154 layerdir Layer directory to create
1155
1156 optional arguments:
1157 -h, --help show this help message and exit
1158 --priority PRIORITY, -p PRIORITY
1159 Layer directory to create
1160 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
1161 Filename of the example recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001162 </literallayout>
1163 </para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001164 </section>
1165
1166 <section id='adding-a-layer-using-the-bitbake-layers-script'>
1167 <title>Adding a Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001168
1169 <para>
1170 Once you create your general layer, you must add it to your
1171 <filename>bblayers.conf</filename> file.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001172 Adding the layer to this configuration file makes the
1173 OpenEmbedded build system aware of your layer so that it can
1174 search it for metadata.
1175 </para>
1176
1177 <para>
1178 Add your layer by using the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001179 <filename>bitbake-layers add-layer</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001180 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001181 $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable>
1182 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001183 Here is an example that adds a layer named
1184 <filename>meta-scottrif</filename> to the configuration file.
1185 Following the command that adds the layer is another
1186 <filename>bitbake-layers</filename> command that shows the
1187 layers that are in your <filename>bblayers.conf</filename>
1188 file:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001189 <literallayout class='monospaced'>
1190 $ bitbake-layers add-layer meta-scottrif
1191 NOTE: Starting bitbake server...
Brad Bishop316dfdd2018-06-25 12:45:53 -04001192 Parsing recipes: 100% |##########################################################| Time: 0:00:49
1193 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 -05001194 $ bitbake-layers show-layers
1195 NOTE: Starting bitbake server...
1196 layer path priority
1197 ==========================================================================
1198 meta /home/scottrif/poky/meta 5
1199 meta-poky /home/scottrif/poky/meta-poky 5
1200 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001201 workspace /home/scottrif/poky/build/workspace 99
1202 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001203 </literallayout>
1204 Adding the layer to this file enables the build system to
1205 locate the layer during the build.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001206 <note>
1207 During a build, the OpenEmbedded build system looks in
1208 the layers from the top of the list down to the bottom
1209 in that order.
1210 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001211 </para>
1212 </section>
1213 </section>
1214
1215 <section id='usingpoky-extend-customimage'>
1216 <title>Customizing Images</title>
1217
1218 <para>
1219 You can customize images to satisfy particular requirements.
1220 This section describes several methods and provides guidelines for each.
1221 </para>
1222
1223 <section id='usingpoky-extend-customimage-localconf'>
1224 <title>Customizing Images Using <filename>local.conf</filename></title>
1225
1226 <para>
1227 Probably the easiest way to customize an image is to add a
1228 package by way of the <filename>local.conf</filename>
1229 configuration file.
1230 Because it is limited to local use, this method generally only
1231 allows you to add packages and is not as flexible as creating
1232 your own customized image.
1233 When you add packages using local variables this way, you need
1234 to realize that these variable changes are in effect for every
1235 build and consequently affect all images, which might not
1236 be what you require.
1237 </para>
1238
1239 <para>
1240 To add a package to your image using the local configuration
1241 file, use the
1242 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1243 variable with the <filename>_append</filename> operator:
1244 <literallayout class='monospaced'>
1245 IMAGE_INSTALL_append = " strace"
1246 </literallayout>
1247 Use of the syntax is important - specifically, the space between
1248 the quote and the package name, which is
1249 <filename>strace</filename> in this example.
1250 This space is required since the <filename>_append</filename>
1251 operator does not add the space.
1252 </para>
1253
1254 <para>
1255 Furthermore, you must use <filename>_append</filename> instead
1256 of the <filename>+=</filename> operator if you want to avoid
1257 ordering issues.
1258 The reason for this is because doing so unconditionally appends
1259 to the variable and avoids ordering problems due to the
1260 variable being set in image recipes and
1261 <filename>.bbclass</filename> files with operators like
1262 <filename>?=</filename>.
1263 Using <filename>_append</filename> ensures the operation takes
1264 affect.
1265 </para>
1266
1267 <para>
1268 As shown in its simplest use,
1269 <filename>IMAGE_INSTALL_append</filename> affects all images.
1270 It is possible to extend the syntax so that the variable
1271 applies to a specific image only.
1272 Here is an example:
1273 <literallayout class='monospaced'>
1274 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
1275 </literallayout>
1276 This example adds <filename>strace</filename> to the
1277 <filename>core-image-minimal</filename> image only.
1278 </para>
1279
1280 <para>
1281 You can add packages using a similar approach through the
1282 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
1283 variable.
1284 If you use this variable, only
1285 <filename>core-image-*</filename> images are affected.
1286 </para>
1287 </section>
1288
1289 <section id='usingpoky-extend-customimage-imagefeatures'>
1290 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
1291 <filename>EXTRA_IMAGE_FEATURES</filename></title>
1292
1293 <para>
1294 Another method for customizing your image is to enable or
1295 disable high-level image features by using the
1296 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
1297 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
1298 variables.
1299 Although the functions for both variables are nearly equivalent,
1300 best practices dictate using <filename>IMAGE_FEATURES</filename>
1301 from within a recipe and using
1302 <filename>EXTRA_IMAGE_FEATURES</filename> from within
1303 your <filename>local.conf</filename> file, which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001304 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001305 </para>
1306
1307 <para>
1308 To understand how these features work, the best reference is
1309 <filename>meta/classes/core-image.bbclass</filename>.
1310 This class lists out the available
Brad Bishop316dfdd2018-06-25 12:45:53 -04001311 <filename>IMAGE_FEATURES</filename> of which most map to
1312 package groups while some, such as
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001313 <filename>debug-tweaks</filename> and
1314 <filename>read-only-rootfs</filename>, resolve as general
1315 configuration settings.
1316 </para>
1317
1318 <para>
1319 In summary, the file looks at the contents of the
1320 <filename>IMAGE_FEATURES</filename> variable and then maps
1321 or configures the feature accordingly.
1322 Based on this information, the build system automatically
1323 adds the appropriate packages or configurations to the
1324 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
1325 variable.
1326 Effectively, you are enabling extra features by extending the
1327 class or creating a custom class for use with specialized image
1328 <filename>.bb</filename> files.
1329 </para>
1330
1331 <para>
1332 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1333 from within your local configuration file.
1334 Using a separate area from which to enable features with
1335 this variable helps you avoid overwriting the features in the
1336 image recipe that are enabled with
1337 <filename>IMAGE_FEATURES</filename>.
1338 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1339 to <filename>IMAGE_FEATURES</filename> within
1340 <filename>meta/conf/bitbake.conf</filename>.
1341 </para>
1342
1343 <para>
1344 To illustrate how you can use these variables to modify your
1345 image, consider an example that selects the SSH server.
1346 The Yocto Project ships with two SSH servers you can use
1347 with your images: Dropbear and OpenSSH.
1348 Dropbear is a minimal SSH server appropriate for
1349 resource-constrained environments, while OpenSSH is a
1350 well-known standard SSH server implementation.
1351 By default, the <filename>core-image-sato</filename> image
1352 is configured to use Dropbear.
1353 The <filename>core-image-full-cmdline</filename> and
1354 <filename>core-image-lsb</filename> images both
1355 include OpenSSH.
1356 The <filename>core-image-minimal</filename> image does not
1357 contain an SSH server.
1358 </para>
1359
1360 <para>
1361 You can customize your image and change these defaults.
1362 Edit the <filename>IMAGE_FEATURES</filename> variable
1363 in your recipe or use the
1364 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1365 <filename>local.conf</filename> file so that it configures the
1366 image you are working with to include
1367 <filename>ssh-server-dropbear</filename> or
1368 <filename>ssh-server-openssh</filename>.
1369 </para>
1370
1371 <note>
1372 See the
1373 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1374 section in the Yocto Project Reference Manual for a complete
1375 list of image features that ship with the Yocto Project.
1376 </note>
1377 </section>
1378
1379 <section id='usingpoky-extend-customimage-custombb'>
1380 <title>Customizing Images Using Custom .bb Files</title>
1381
1382 <para>
1383 You can also customize an image by creating a custom recipe
1384 that defines additional software as part of the image.
1385 The following example shows the form for the two lines you need:
1386 <literallayout class='monospaced'>
1387 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1388
1389 inherit core-image
1390 </literallayout>
1391 </para>
1392
1393 <para>
1394 Defining the software using a custom recipe gives you total
1395 control over the contents of the image.
1396 It is important to use the correct names of packages in the
1397 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1398 variable.
1399 You must use the OpenEmbedded notation and not the Debian notation for the names
1400 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1401 </para>
1402
1403 <para>
1404 The other method for creating a custom image is to base it on an existing image.
1405 For example, if you want to create an image based on <filename>core-image-sato</filename>
1406 but add the additional package <filename>strace</filename> to the image,
1407 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1408 new <filename>.bb</filename> and add the following line to the end of the copy:
1409 <literallayout class='monospaced'>
1410 IMAGE_INSTALL += "strace"
1411 </literallayout>
1412 </para>
1413 </section>
1414
1415 <section id='usingpoky-extend-customimage-customtasks'>
1416 <title>Customizing Images Using Custom Package Groups</title>
1417
1418 <para>
1419 For complex custom images, the best approach for customizing
1420 an image is to create a custom package group recipe that is
1421 used to build the image or images.
1422 A good example of a package group recipe is
1423 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1424 </para>
1425
1426 <para>
1427 If you examine that recipe, you see that the
1428 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1429 variable lists the package group packages to produce.
1430 The <filename>inherit packagegroup</filename> statement
1431 sets appropriate default values and automatically adds
1432 <filename>-dev</filename>, <filename>-dbg</filename>, and
1433 <filename>-ptest</filename> complementary packages for each
1434 package specified in the <filename>PACKAGES</filename>
1435 statement.
1436 <note>
Andrew Geissler82c905d2020-04-13 13:39:40 -05001437 The <filename>inherit packagegroup</filename> line should be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001438 located near the top of the recipe, certainly before
1439 the <filename>PACKAGES</filename> statement.
1440 </note>
1441 </para>
1442
1443 <para>
1444 For each package you specify in <filename>PACKAGES</filename>,
1445 you can use
1446 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1447 and
1448 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1449 entries to provide a list of packages the parent task package
1450 should contain.
1451 You can see examples of these further down in the
1452 <filename>packagegroup-base.bb</filename> recipe.
1453 </para>
1454
1455 <para>
1456 Here is a short, fabricated example showing the same basic
Andrew Geissler82c905d2020-04-13 13:39:40 -05001457 pieces for a hypothetical packagegroup defined in
1458 <filename>packagegroup-custom.bb</filename>, where the
1459 variable <filename>PN</filename> is the standard way to
1460 abbreviate the reference to the full packagegroup name
1461 <filename>packagegroup-custom</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001462 <literallayout class='monospaced'>
1463 DESCRIPTION = "My Custom Package Groups"
1464
1465 inherit packagegroup
1466
1467 PACKAGES = "\
Andrew Geissler82c905d2020-04-13 13:39:40 -05001468 ${PN}-apps \
1469 ${PN}-tools \
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001470 "
1471
Andrew Geissler82c905d2020-04-13 13:39:40 -05001472 RDEPENDS_${PN}-apps = "\
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001473 dropbear \
1474 portmap \
1475 psplash"
1476
Andrew Geissler82c905d2020-04-13 13:39:40 -05001477 RDEPENDS_${PN}-tools = "\
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001478 oprofile \
1479 oprofileui-server \
1480 lttng-tools"
1481
Andrew Geissler82c905d2020-04-13 13:39:40 -05001482 RRECOMMENDS_${PN}-tools = "\
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001483 kernel-module-oprofile"
1484 </literallayout>
1485 </para>
1486
1487 <para>
1488 In the previous example, two package group packages are created with their dependencies and their
1489 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1490 <filename>packagegroup-custom-tools</filename>.
1491 To build an image using these package group packages, you need to add
1492 <filename>packagegroup-custom-apps</filename> and/or
1493 <filename>packagegroup-custom-tools</filename> to
1494 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1495 For other forms of image dependencies see the other areas of this section.
1496 </para>
1497 </section>
1498
1499 <section id='usingpoky-extend-customimage-image-name'>
1500 <title>Customizing an Image Hostname</title>
1501
1502 <para>
1503 By default, the configured hostname (i.e.
1504 <filename>/etc/hostname</filename>) in an image is the
1505 same as the machine name.
1506 For example, if
1507 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1508 equals "qemux86", the configured hostname written to
1509 <filename>/etc/hostname</filename> is "qemux86".
1510 </para>
1511
1512 <para>
1513 You can customize this name by altering the value of the
1514 "hostname" variable in the
1515 <filename>base-files</filename> recipe using either
1516 an append file or a configuration file.
1517 Use the following in an append file:
1518 <literallayout class='monospaced'>
1519 hostname="myhostname"
1520 </literallayout>
1521 Use the following in a configuration file:
1522 <literallayout class='monospaced'>
1523 hostname_pn-base-files = "myhostname"
1524 </literallayout>
1525 </para>
1526
1527 <para>
1528 Changing the default value of the variable "hostname" can be
1529 useful in certain situations.
1530 For example, suppose you need to do extensive testing on an
1531 image and you would like to easily identify the image
1532 under test from existing images with typical default
1533 hostnames.
1534 In this situation, you could change the default hostname to
1535 "testme", which results in all the images using the name
1536 "testme".
1537 Once testing is complete and you do not need to rebuild the
1538 image for test any longer, you can easily reset the default
1539 hostname.
1540 </para>
1541
1542 <para>
1543 Another point of interest is that if you unset the variable,
1544 the image will have no default hostname in the filesystem.
1545 Here is an example that unsets the variable in a
1546 configuration file:
1547 <literallayout class='monospaced'>
1548 hostname_pn-base-files = ""
1549 </literallayout>
1550 Having no default hostname in the filesystem is suitable for
1551 environments that use dynamic hostnames such as virtual
1552 machines.
1553 </para>
1554 </section>
1555 </section>
1556
1557 <section id='new-recipe-writing-a-new-recipe'>
1558 <title>Writing a New Recipe</title>
1559
1560 <para>
1561 Recipes (<filename>.bb</filename> files) are fundamental components
1562 in the Yocto Project environment.
1563 Each software component built by the OpenEmbedded build system
1564 requires a recipe to define the component.
1565 This section describes how to create, write, and test a new
1566 recipe.
1567 <note>
1568 For information on variables that are useful for recipes and
1569 for information about recipe naming issues, see the
1570 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1571 section of the Yocto Project Reference Manual.
1572 </note>
1573 </para>
1574
1575 <section id='new-recipe-overview'>
1576 <title>Overview</title>
1577
1578 <para>
1579 The following figure shows the basic process for creating a
1580 new recipe.
1581 The remainder of the section provides details for the steps.
1582 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1583 </para>
1584 </section>
1585
1586 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1587 <title>Locate or Automatically Create a Base Recipe</title>
1588
1589 <para>
1590 You can always write a recipe from scratch.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001591 However, three choices exist that can help you quickly get a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001592 start on a new recipe:
1593 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001594 <listitem><para>
1595 <emphasis><filename>devtool add</filename>:</emphasis>
1596 A command that assists in creating a recipe and
1597 an environment conducive to development.
1598 </para></listitem>
1599 <listitem><para>
1600 <emphasis><filename>recipetool create</filename>:</emphasis>
1601 A command provided by the Yocto Project that automates
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001602 creation of a base recipe based on the source
1603 files.
1604 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001605 <listitem><para>
1606 <emphasis>Existing Recipes:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001607 Location and modification of an existing recipe that is
1608 similar in function to the recipe you need.
1609 </para></listitem>
1610 </itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001611 <note>
1612 For information on recipe syntax, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001613 "<link linkend='recipe-syntax'>Recipe Syntax</link>"
1614 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001615 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001616 </para>
1617
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001618 <section id='new-recipe-creating-the-base-recipe-using-devtool'>
1619 <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001620
1621 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001622 The <filename>devtool add</filename> command uses the same
1623 logic for auto-creating the recipe as
1624 <filename>recipetool create</filename>, which is listed
1625 below.
1626 Additionally, however, <filename>devtool add</filename>
1627 sets up an environment that makes it easy for you to
1628 patch the source and to make changes to the recipe as
1629 is often necessary when adding a recipe to build a new
1630 piece of software to be included in a build.
1631 </para>
1632
1633 <para>
1634 You can find a complete description of the
1635 <filename>devtool add</filename> command in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001636 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>"
1637 section in the Yocto Project Application Development
1638 and the Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001639 </para>
1640 </section>
1641
1642 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1643 <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
1644
1645 <para>
1646 <filename>recipetool create</filename> automates creation
1647 of a base recipe given a set of source code files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001648 As long as you can extract or point to the source files,
1649 the tool will construct a recipe and automatically
1650 configure all pre-build information into the recipe.
1651 For example, suppose you have an application that builds
1652 using Autotools.
1653 Creating the base recipe using
1654 <filename>recipetool</filename> results in a recipe
1655 that has the pre-build dependencies, license requirements,
1656 and checksums configured.
1657 </para>
1658
1659 <para>
1660 To run the tool, you just need to be in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001661 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001662 and have sourced the build environment setup script
1663 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001664 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
Brad Bishop316dfdd2018-06-25 12:45:53 -04001665 To get help on the tool, use the following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001666 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001667 $ recipetool -h
1668 NOTE: Starting bitbake server...
1669 usage: recipetool [-d] [-q] [--color COLOR] [-h] &lt;subcommand&gt; ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001670
Brad Bishop316dfdd2018-06-25 12:45:53 -04001671 OpenEmbedded recipe tool
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001672
Brad Bishop316dfdd2018-06-25 12:45:53 -04001673 options:
1674 -d, --debug Enable debug output
1675 -q, --quiet Print only errors
1676 --color COLOR Colorize output (where COLOR is auto, always, never)
1677 -h, --help show this help message and exit
1678
1679 subcommands:
1680 create Create a new recipe
1681 newappend Create a bbappend for the specified target in the specified
1682 layer
1683 setvar Set a variable within a recipe
1684 appendfile Create/update a bbappend to replace a target file
1685 appendsrcfiles Create/update a bbappend to add or replace source files
1686 appendsrcfile Create/update a bbappend to add or replace a source file
1687 Use recipetool &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001688 </literallayout>
1689 </para>
1690
1691 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001692 Running
1693 <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001694 creates the base recipe and locates it properly in the
1695 layer that contains your source files.
1696 Following are some syntax examples:
1697 </para>
1698
1699 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001700 Use this syntax to generate a recipe based on
1701 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001702 Once generated, the recipe resides in the existing source
1703 code layer:
1704 <literallayout class='monospaced'>
1705 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1706 </literallayout>
1707 Use this syntax to generate a recipe using code that you
1708 extract from <replaceable>source</replaceable>.
1709 The extracted code is placed in its own layer defined
1710 by <replaceable>EXTERNALSRC</replaceable>.
1711 <literallayout class='monospaced'>
1712 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1713 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001714 Use this syntax to generate a recipe based on
1715 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001716 The options direct <filename>recipetool</filename> to
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001717 generate debugging information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001718 Once generated, the recipe resides in the existing source
1719 code layer:
1720 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001721 recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001722 </literallayout>
1723 </para>
1724 </section>
1725
1726 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1727 <title>Locating and Using a Similar Recipe</title>
1728
1729 <para>
1730 Before writing a recipe from scratch, it is often useful to
1731 discover whether someone else has already written one that
1732 meets (or comes close to meeting) your needs.
1733 The Yocto Project and OpenEmbedded communities maintain many
1734 recipes that might be candidates for what you are doing.
1735 You can find a good central index of these recipes in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001736 <ulink url='http://layers.openembedded.org'>OpenEmbedded Layer Index</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001737 </para>
1738
1739 <para>
1740 Working from an existing recipe or a skeleton recipe is the
1741 best way to get started.
1742 Here are some points on both methods:
1743 <itemizedlist>
1744 <listitem><para><emphasis>Locate and modify a recipe that
1745 is close to what you want to do:</emphasis>
1746 This method works when you are familiar with the
1747 current recipe space.
1748 The method does not work so well for those new to
1749 the Yocto Project or writing recipes.</para>
1750 <para>Some risks associated with this method are
1751 using a recipe that has areas totally unrelated to
1752 what you are trying to accomplish with your recipe,
1753 not recognizing areas of the recipe that you might
1754 have to add from scratch, and so forth.
1755 All these risks stem from unfamiliarity with the
1756 existing recipe space.</para></listitem>
1757 <listitem><para><emphasis>Use and modify the following
1758 skeleton recipe:</emphasis>
1759 If for some reason you do not want to use
1760 <filename>recipetool</filename> and you cannot
1761 find an existing recipe that is close to meeting
1762 your needs, you can use the following structure to
1763 provide the fundamental areas of a new recipe.
1764 <literallayout class='monospaced'>
1765 DESCRIPTION = ""
1766 HOMEPAGE = ""
1767 LICENSE = ""
1768 SECTION = ""
1769 DEPENDS = ""
1770 LIC_FILES_CHKSUM = ""
1771
1772 SRC_URI = ""
1773 </literallayout>
1774 </para></listitem>
1775 </itemizedlist>
1776 </para>
1777 </section>
1778 </section>
1779
1780 <section id='new-recipe-storing-and-naming-the-recipe'>
1781 <title>Storing and Naming the Recipe</title>
1782
1783 <para>
1784 Once you have your base recipe, you should put it in your
1785 own layer and name it appropriately.
1786 Locating it correctly ensures that the OpenEmbedded build
1787 system can find it when you use BitBake to process the
1788 recipe.
1789 </para>
1790
1791 <itemizedlist>
1792 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1793 The OpenEmbedded build system locates your recipe
1794 through the layer's <filename>conf/layer.conf</filename>
1795 file and the
1796 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1797 variable.
1798 This variable sets up a path from which the build system can
1799 locate recipes.
1800 Here is the typical use:
1801 <literallayout class='monospaced'>
1802 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1803 ${LAYERDIR}/recipes-*/*/*.bbappend"
1804 </literallayout>
1805 Consequently, you need to be sure you locate your new recipe
1806 inside your layer such that it can be found.</para>
1807 <para>You can find more information on how layers are
1808 structured in the
1809 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1810 section.</para></listitem>
1811 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1812 When you name your recipe, you need to follow this naming
1813 convention:
1814 <literallayout class='monospaced'>
1815 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1816 </literallayout>
1817 Use lower-cased characters and do not include the reserved
1818 suffixes <filename>-native</filename>,
1819 <filename>-cross</filename>, <filename>-initial</filename>,
1820 or <filename>-dev</filename> casually (i.e. do not use them
1821 as part of your recipe name unless the string applies).
1822 Here are some examples:
1823 <literallayout class='monospaced'>
1824 cups_1.7.0.bb
1825 gawk_4.0.2.bb
1826 irssi_0.8.16-rc1.bb
1827 </literallayout></para></listitem>
1828 </itemizedlist>
1829 </section>
1830
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001831 <section id='new-recipe-running-a-build-on-the-recipe'>
1832 <title>Running a Build on the Recipe</title>
1833
1834 <para>
1835 Creating a new recipe is usually an iterative process that
1836 requires using BitBake to process the recipe multiple times in
1837 order to progressively discover and add information to the
1838 recipe file.
1839 </para>
1840
1841 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001842 Assuming you have sourced the build environment setup script (i.e.
1843 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001844 and you are in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001845 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001846 use BitBake to process your recipe.
1847 All you need to provide is the
1848 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1849 in the previous section:
1850 <literallayout class='monospaced'>
1851 $ bitbake <replaceable>basename</replaceable>
1852 </literallayout>
1853
1854 </para>
1855
1856 <para>
1857 During the build, the OpenEmbedded build system creates a
1858 temporary work directory for each recipe
1859 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1860 where it keeps extracted source files, log files, intermediate
1861 compilation and packaging files, and so forth.
1862 </para>
1863
1864 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001865 The path to the per-recipe temporary work directory depends
1866 on the context in which it is being built.
1867 The quickest way to find this path is to have BitBake return it
1868 by running the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001869 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001870 $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001871 </literallayout>
1872 As an example, assume a Source Directory top-level folder named
1873 <filename>poky</filename>, a default Build Directory at
1874 <filename>poky/build</filename>, and a
1875 <filename>qemux86-poky-linux</filename> machine target system.
1876 Furthermore, suppose your recipe is named
1877 <filename>foo_1.3.0.bb</filename>.
1878 In this case, the work directory the build system uses to
1879 build the package would be as follows:
1880 <literallayout class='monospaced'>
1881 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1882 </literallayout>
1883 Inside this directory you can find sub-directories such as
1884 <filename>image</filename>, <filename>packages-split</filename>,
1885 and <filename>temp</filename>.
1886 After the build, you can examine these to determine how well
1887 the build went.
1888 <note>
1889 You can find log files for each task in the recipe's
1890 <filename>temp</filename> directory (e.g.
1891 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1892 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1893 (e.g. <filename>log.do_configure</filename>,
1894 <filename>log.do_fetch</filename>, and
1895 <filename>log.do_compile</filename>).
1896 </note>
1897 </para>
1898
1899 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001900 You can find more information about the build process in
Brad Bishop316dfdd2018-06-25 12:45:53 -04001901 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-development-environment'>The Yocto Project Development Environment</ulink>"
1902 chapter of the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001903 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001904 </section>
1905
1906 <section id='new-recipe-fetching-code'>
1907 <title>Fetching Code</title>
1908
1909 <para>
1910 The first thing your recipe must do is specify how to fetch
1911 the source files.
1912 Fetching is controlled mainly through the
1913 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1914 variable.
1915 Your recipe must have a <filename>SRC_URI</filename> variable
1916 that points to where the source is located.
1917 For a graphical representation of source locations, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001918 "<ulink url='&YOCTO_DOCS_OM_URL;#sources-dev-environment'>Sources</ulink>"
1919 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001920 </para>
1921
1922 <para>
1923 The
1924 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1925 task uses the prefix of each entry in the
1926 <filename>SRC_URI</filename> variable value to determine which
Brad Bishopc342db32019-05-15 21:57:59 -04001927 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>
1928 to use to get your source files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001929 It is the <filename>SRC_URI</filename> variable that triggers
1930 the fetcher.
1931 The
1932 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1933 task uses the variable after source is fetched to apply
1934 patches.
1935 The OpenEmbedded build system uses
1936 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1937 for scanning directory locations for local files in
1938 <filename>SRC_URI</filename>.
1939 </para>
1940
1941 <para>
1942 The <filename>SRC_URI</filename> variable in your recipe must
1943 define each unique location for your source files.
Andrew Geissler82c905d2020-04-13 13:39:40 -05001944 It is good practice to not hard-code version numbers in a URL used
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001945 in <filename>SRC_URI</filename>.
Andrew Geissler82c905d2020-04-13 13:39:40 -05001946 Rather than hard-code these values, use
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001947 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1948 which causes the fetch process to use the version specified in
1949 the recipe filename.
1950 Specifying the version in this manner means that upgrading the
1951 recipe to a future version is as simple as renaming the recipe
1952 to match the new version.
1953 </para>
1954
1955 <para>
1956 Here is a simple example from the
Andrew Geissler82c905d2020-04-13 13:39:40 -05001957 <filename>meta/recipes-devtools/strace/strace_5.5.bb</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001958 recipe where the source comes from a single tarball.
1959 Notice the use of the
1960 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1961 variable:
1962 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -05001963 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001964 </literallayout>
1965 </para>
1966
1967 <para>
1968 Files mentioned in <filename>SRC_URI</filename> whose names end
1969 in a typical archive extension (e.g. <filename>.tar</filename>,
1970 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1971 <filename>.zip</filename>, and so forth), are automatically
1972 extracted during the
1973 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1974 task.
1975 For another example that specifies these types of files, see
1976 the
1977 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1978 section.
1979 </para>
1980
1981 <para>
1982 Another way of specifying source is from an SCM.
1983 For Git repositories, you must specify
1984 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1985 and you should specify
1986 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1987 to include the revision with
1988 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1989 Here is an example from the recipe
1990 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1991 <literallayout class='monospaced'>
1992 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1993
1994 PR = "r6"
1995 PV = "1.0.5+git${SRCPV}"
1996
1997 SRC_URI = "git://git.kernel.dk/blktrace.git \
1998 file://ldflags.patch"
1999 </literallayout>
2000 </para>
2001
2002 <para>
2003 If your <filename>SRC_URI</filename> statement includes
2004 URLs pointing to individual files fetched from a remote server
2005 other than a version control system, BitBake attempts to
2006 verify the files against checksums defined in your recipe to
2007 ensure they have not been tampered with or otherwise modified
2008 since the recipe was written.
2009 Two checksums are used:
2010 <filename>SRC_URI[md5sum]</filename> and
2011 <filename>SRC_URI[sha256sum]</filename>.
2012 </para>
2013
2014 <para>
2015 If your <filename>SRC_URI</filename> variable points to
2016 more than a single URL (excluding SCM URLs), you need to
2017 provide the <filename>md5</filename> and
2018 <filename>sha256</filename> checksums for each URL.
2019 For these cases, you provide a name for each URL as part of
2020 the <filename>SRC_URI</filename> and then reference that name
2021 in the subsequent checksum statements.
Andrew Geissler82c905d2020-04-13 13:39:40 -05002022 Here is an example combining lines from the files
2023 <filename>git.inc</filename> and
2024 <filename>git_2.24.1.bb</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002025 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -05002026 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
2027 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002028
Andrew Geissler82c905d2020-04-13 13:39:40 -05002029 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
2030 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
2031 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
2032 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002033 </literallayout>
2034 </para>
2035
2036 <para>
2037 Proper values for <filename>md5</filename> and
2038 <filename>sha256</filename> checksums might be available
2039 with other signatures on the download page for the upstream
2040 source (e.g. <filename>md5</filename>,
2041 <filename>sha1</filename>, <filename>sha256</filename>,
2042 <filename>GPG</filename>, and so forth).
2043 Because the OpenEmbedded build system only deals with
2044 <filename>sha256sum</filename> and <filename>md5sum</filename>,
2045 you should verify all the signatures you find by hand.
2046 </para>
2047
2048 <para>
2049 If no <filename>SRC_URI</filename> checksums are specified
2050 when you attempt to build the recipe, or you provide an
2051 incorrect checksum, the build will produce an error for each
2052 missing or incorrect checksum.
2053 As part of the error message, the build system provides
2054 the checksum string corresponding to the fetched file.
2055 Once you have the correct checksums, you can copy and paste
2056 them into your recipe and then run the build again to continue.
2057 <note>
2058 As mentioned, if the upstream source provides signatures
2059 for verifying the downloaded source code, you should
2060 verify those manually before setting the checksum values
2061 in the recipe and continuing with the build.
2062 </note>
2063 </para>
2064
2065 <para>
2066 This final example is a bit more complicated and is from the
2067 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2068 recipe.
2069 The example's <filename>SRC_URI</filename> statement identifies
2070 multiple files as the source files for the recipe: a tarball, a
2071 patch file, a desktop file, and an icon.
2072 <literallayout class='monospaced'>
2073 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2074 file://xwc.patch \
2075 file://rxvt.desktop \
2076 file://rxvt.png"
2077 </literallayout>
2078 </para>
2079
2080 <para>
2081 When you specify local files using the
2082 <filename>file://</filename> URI protocol, the build system
2083 fetches files from the local machine.
2084 The path is relative to the
2085 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2086 variable and searches specific directories in a certain order:
2087 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2088 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2089 and <filename>files</filename>.
2090 The directories are assumed to be subdirectories of the
2091 directory in which the recipe or append file resides.
2092 For another example that specifies these types of files, see the
2093 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2094 section.
2095 </para>
2096
2097 <para>
2098 The previous example also specifies a patch file.
2099 Patch files are files whose names usually end in
2100 <filename>.patch</filename> or <filename>.diff</filename> but
2101 can end with compressed suffixes such as
2102 <filename>diff.gz</filename> and
2103 <filename>patch.bz2</filename>, for example.
2104 The build system automatically applies patches as described
2105 in the
2106 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2107 </para>
2108 </section>
2109
2110 <section id='new-recipe-unpacking-code'>
2111 <title>Unpacking Code</title>
2112
2113 <para>
2114 During the build, the
2115 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2116 task unpacks the source with
2117 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2118 pointing to where it is unpacked.
2119 </para>
2120
2121 <para>
2122 If you are fetching your source files from an upstream source
2123 archived tarball and the tarball's internal structure matches
2124 the common convention of a top-level subdirectory named
2125 <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>,
2126 then you do not need to set <filename>S</filename>.
2127 However, if <filename>SRC_URI</filename> specifies to fetch
2128 source from an archive that does not use this convention,
2129 or from an SCM like Git or Subversion, your recipe needs to
2130 define <filename>S</filename>.
2131 </para>
2132
2133 <para>
2134 If processing your recipe using BitBake successfully unpacks
2135 the source files, you need to be sure that the directory
2136 pointed to by <filename>${S}</filename> matches the structure
2137 of the source.
2138 </para>
2139 </section>
2140
2141 <section id='new-recipe-patching-code'>
2142 <title>Patching Code</title>
2143
2144 <para>
2145 Sometimes it is necessary to patch code after it has been
2146 fetched.
2147 Any files mentioned in <filename>SRC_URI</filename> whose
2148 names end in <filename>.patch</filename> or
2149 <filename>.diff</filename> or compressed versions of these
2150 suffixes (e.g. <filename>diff.gz</filename> are treated as
2151 patches.
2152 The
2153 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2154 task automatically applies these patches.
2155 </para>
2156
2157 <para>
2158 The build system should be able to apply patches with the "-p1"
2159 option (i.e. one directory level in the path will be stripped
2160 off).
2161 If your patch needs to have more directory levels stripped off,
2162 specify the number of levels using the "striplevel" option in
2163 the <filename>SRC_URI</filename> entry for the patch.
2164 Alternatively, if your patch needs to be applied in a specific
2165 subdirectory that is not specified in the patch file, use the
2166 "patchdir" option in the entry.
2167 </para>
2168
2169 <para>
2170 As with all local files referenced in
2171 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2172 using <filename>file://</filename>, you should place
2173 patch files in a directory next to the recipe either
2174 named the same as the base name of the recipe
2175 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2176 and
2177 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2178 or "files".
2179 </para>
2180 </section>
2181
2182 <section id='new-recipe-licensing'>
2183 <title>Licensing</title>
2184
2185 <para>
2186 Your recipe needs to have both the
2187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2188 and
2189 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2190 variables:
2191 <itemizedlist>
2192 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2193 This variable specifies the license for the software.
2194 If you do not know the license under which the software
2195 you are building is distributed, you should go to the
2196 source code and look for that information.
2197 Typical files containing this information include
2198 <filename>COPYING</filename>,
2199 <filename>LICENSE</filename>, and
2200 <filename>README</filename> files.
2201 You could also find the information near the top of
2202 a source file.
2203 For example, given a piece of software licensed under
2204 the GNU General Public License version 2, you would
2205 set <filename>LICENSE</filename> as follows:
2206 <literallayout class='monospaced'>
2207 LICENSE = "GPLv2"
2208 </literallayout></para>
2209 <para>The licenses you specify within
2210 <filename>LICENSE</filename> can have any name as long
2211 as you do not use spaces, since spaces are used as
2212 separators between license names.
2213 For standard licenses, use the names of the files in
2214 <filename>meta/files/common-licenses/</filename>
2215 or the <filename>SPDXLICENSEMAP</filename> flag names
2216 defined in <filename>meta/conf/licenses.conf</filename>.
2217 </para></listitem>
2218 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2219 The OpenEmbedded build system uses this variable to
2220 make sure the license text has not changed.
2221 If it has, the build produces an error and it affords
2222 you the chance to figure it out and correct the problem.
2223 </para>
2224 <para>You need to specify all applicable licensing
2225 files for the software.
2226 At the end of the configuration step, the build process
2227 will compare the checksums of the files to be sure
2228 the text has not changed.
2229 Any differences result in an error with the message
2230 containing the current checksum.
2231 For more explanation and examples of how to set the
2232 <filename>LIC_FILES_CHKSUM</filename> variable, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002233 "<link link='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
2234 section.</para>
2235
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002236 <para>To determine the correct checksum string, you
2237 can list the appropriate files in the
2238 <filename>LIC_FILES_CHKSUM</filename> variable with
2239 incorrect md5 strings, attempt to build the software,
2240 and then note the resulting error messages that will
2241 report the correct md5 strings.
2242 See the
2243 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2244 section for additional information.
2245 </para>
2246
2247 <para>
2248 Here is an example that assumes the software has a
2249 <filename>COPYING</filename> file:
2250 <literallayout class='monospaced'>
2251 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2252 </literallayout>
2253 When you try to build the software, the build system
2254 will produce an error and give you the correct string
2255 that you can substitute into the recipe file for a
2256 subsequent build.
2257 </para></listitem>
2258 </itemizedlist>
2259 </para>
2260
2261<!--
2262
2263 <para>
2264 For trying this out I created a new recipe named
2265 <filename>htop_1.0.2.bb</filename> and put it in
2266 <filename>poky/meta/recipes-extended/htop</filename>.
2267 There are two license type statements in my very simple
2268 recipe:
2269 <literallayout class='monospaced'>
2270 LICENSE = ""
2271
2272 LIC_FILES_CHKSUM = ""
2273
2274 SRC_URI[md5sum] = ""
2275 SRC_URI[sha256sum] = ""
2276 </literallayout>
2277 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2278 Next, you delete or comment out the two <filename>SRC_URI</filename>
2279 lines at the end and then attempt to build the software with
2280 <filename>bitbake htop</filename>.
2281 Doing so causes BitBake to report some errors and and give
2282 you the actual strings you need for the last two
2283 <filename>SRC_URI</filename> lines.
2284 Prior to this, you have to dig around in the home page of the
2285 source for <filename>htop</filename> and determine that the
2286 software is released under GPLv2.
2287 You can provide that in the <filename>LICENSE</filename>
2288 statement.
2289 Now you edit your recipe to have those two strings for
2290 the <filename>SRC_URI</filename> statements:
2291 <literallayout class='monospaced'>
2292 LICENSE = "GPLv2"
2293
2294 LIC_FILES_CHKSUM = ""
2295
2296 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2297 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2298 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2299 </literallayout>
2300 At this point, you can build the software again using the
2301 <filename>bitbake htop</filename> command.
2302 There is just a set of errors now associated with the
2303 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2304 </para>
2305-->
2306
2307 </section>
2308
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002309 <section id='new-dependencies'>
2310 <title>Dependencies</title>
2311
2312 <para>
2313 Most software packages have a short list of other packages
2314 that they require, which are called dependencies.
2315 These dependencies fall into two main categories: build-time
2316 dependencies, which are required when the software is built;
2317 and runtime dependencies, which are required to be installed
2318 on the target in order for the software to run.
2319 </para>
2320
2321 <para>
2322 Within a recipe, you specify build-time dependencies using the
2323 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2324 variable.
2325 Although nuances exist, items specified in
2326 <filename>DEPENDS</filename> should be names of other recipes.
2327 It is important that you specify all build-time dependencies
2328 explicitly.
2329 If you do not, due to the parallel nature of BitBake's
2330 execution, you can end up with a race condition where the
2331 dependency is present for one task of a recipe (e.g.
2332 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
2333 and then gone when the next task runs (e.g.
2334 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
2335 </para>
2336
2337 <para>
2338 Another consideration is that configure scripts might
2339 automatically check for optional dependencies and enable
2340 corresponding functionality if those dependencies are found.
2341 This behavior means that to ensure deterministic results and
2342 thus avoid more race conditions, you need to either explicitly
2343 specify these dependencies as well, or tell the configure
2344 script explicitly to disable the functionality.
2345 If you wish to make a recipe that is more generally useful
2346 (e.g. publish the recipe in a layer for others to use),
2347 instead of hard-disabling the functionality, you can use the
2348 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
2349 variable to allow functionality and the corresponding
2350 dependencies to be enabled and disabled easily by other
2351 users of the recipe.
2352 </para>
2353
2354 <para>
2355 Similar to build-time dependencies, you specify runtime
2356 dependencies through a variable -
2357 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
2358 which is package-specific.
2359 All variables that are package-specific need to have the name
2360 of the package added to the end as an override.
2361 Since the main package for a recipe has the same name as the
2362 recipe, and the recipe's name can be found through the
2363 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2364 variable, then you specify the dependencies for the main
2365 package by setting <filename>RDEPENDS_${PN}</filename>.
2366 If the package were named <filename>${PN}-tools</filename>,
2367 then you would set <filename>RDEPENDS_${PN}-tools</filename>,
2368 and so forth.
2369 </para>
2370
2371 <para>
2372 Some runtime dependencies will be set automatically at
2373 packaging time.
2374 These dependencies include any shared library dependencies
2375 (i.e. if a package "example" contains "libexample" and
2376 another package "mypackage" contains a binary that links to
2377 "libexample" then the OpenEmbedded build system will
2378 automatically add a runtime dependency to "mypackage" on
2379 "example").
2380 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002381 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
2382 section in the Yocto Project Overview and Concepts Manual for
2383 further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002384 </para>
2385 </section>
2386
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002387 <section id='new-recipe-configuring-the-recipe'>
2388 <title>Configuring the Recipe</title>
2389
2390 <para>
2391 Most software provides some means of setting build-time
2392 configuration options before compilation.
2393 Typically, setting these options is accomplished by running a
Brad Bishop64c979e2019-11-04 13:55:29 -05002394 configure script with options, or by modifying a build
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002395 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002396 <note>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002397 As of Yocto Project Release 1.7, some of the core recipes
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002398 that package binary configuration scripts now disable the
2399 scripts due to the scripts previously requiring error-prone
2400 path substitution.
2401 The OpenEmbedded build system uses
2402 <filename>pkg-config</filename> now, which is much more
2403 robust.
2404 You can find a list of the <filename>*-config</filename>
2405 scripts that are disabled list in the
2406 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2407 section in the Yocto Project Reference Manual.
2408 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002409 </para>
2410
2411 <para>
2412 A major part of build-time configuration is about checking for
2413 build-time dependencies and possibly enabling optional
2414 functionality as a result.
2415 You need to specify any build-time dependencies for the
2416 software you are building in your recipe's
2417 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2418 value, in terms of other recipes that satisfy those
2419 dependencies.
2420 You can often find build-time or runtime
2421 dependencies described in the software's documentation.
2422 </para>
2423
2424 <para>
2425 The following list provides configuration items of note based
2426 on how your software is built:
2427 <itemizedlist>
2428 <listitem><para><emphasis>Autotools:</emphasis>
2429 If your source files have a
2430 <filename>configure.ac</filename> file, then your
2431 software is built using Autotools.
2432 If this is the case, you just need to worry about
2433 modifying the configuration.</para>
Brad Bishop64c979e2019-11-04 13:55:29 -05002434
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002435 <para>When using Autotools, your recipe needs to inherit
2436 the
2437 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2438 class and your recipe does not have to contain a
2439 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2440 task.
2441 However, you might still want to make some adjustments.
2442 For example, you can set
2443 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002444 or
2445 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002446 to pass any needed configure options that are specific
Brad Bishop64c979e2019-11-04 13:55:29 -05002447 to the recipe.
2448 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002449 <listitem><para><emphasis>CMake:</emphasis>
2450 If your source files have a
2451 <filename>CMakeLists.txt</filename> file, then your
2452 software is built using CMake.
2453 If this is the case, you just need to worry about
2454 modifying the configuration.</para>
Brad Bishop64c979e2019-11-04 13:55:29 -05002455
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002456 <para>When you use CMake, your recipe needs to inherit
2457 the
2458 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2459 class and your recipe does not have to contain a
2460 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2461 task.
2462 You can make some adjustments by setting
2463 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2464 to pass any needed configure options that are specific
Brad Bishop64c979e2019-11-04 13:55:29 -05002465 to the recipe.
2466 <note>
2467 If you need to install one or more custom CMake
2468 toolchain files that are supplied by the
2469 application you are building, install the files to
2470 <filename>${D}${datadir}/cmake/</filename> Modules
2471 during
2472 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>.
2473 </note>
2474 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002475 <listitem><para><emphasis>Other:</emphasis>
2476 If your source files do not have a
2477 <filename>configure.ac</filename> or
2478 <filename>CMakeLists.txt</filename> file, then your
2479 software is built using some method other than Autotools
2480 or CMake.
2481 If this is the case, you normally need to provide a
2482 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2483 task in your recipe
2484 unless, of course, there is nothing to configure.
2485 </para>
2486 <para>Even if your software is not being built by
2487 Autotools or CMake, you still might not need to deal
2488 with any configuration issues.
2489 You need to determine if configuration is even a required step.
2490 You might need to modify a Makefile or some configuration file
2491 used for the build to specify necessary build options.
2492 Or, perhaps you might need to run a provided, custom
2493 configure script with the appropriate options.</para>
2494 <para>For the case involving a custom configure
2495 script, you would run
2496 <filename>./configure --help</filename> and look for
2497 the options you need to set.</para></listitem>
2498 </itemizedlist>
2499 </para>
2500
2501 <para>
2502 Once configuration succeeds, it is always good practice to
2503 look at the <filename>log.do_configure</filename> file to
2504 ensure that the appropriate options have been enabled and no
2505 additional build-time dependencies need to be added to
2506 <filename>DEPENDS</filename>.
2507 For example, if the configure script reports that it found
2508 something not mentioned in <filename>DEPENDS</filename>, or
2509 that it did not find something that it needed for some
2510 desired optional functionality, then you would need to add
2511 those to <filename>DEPENDS</filename>.
2512 Looking at the log might also reveal items being checked for,
2513 enabled, or both that you do not want, or items not being found
2514 that are in <filename>DEPENDS</filename>, in which case
2515 you would need to look at passing extra options to the
2516 configure script as needed.
2517 For reference information on configure options specific to the
2518 software you are building, you can consult the output of the
2519 <filename>./configure --help</filename> command within
2520 <filename>${S}</filename> or consult the software's upstream
2521 documentation.
2522 </para>
2523 </section>
2524
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002525 <section id='new-recipe-using-headers-to-interface-with-devices'>
2526 <title>Using Headers to Interface with Devices</title>
2527
2528 <para>
2529 If your recipe builds an application that needs to
2530 communicate with some device or needs an API into a custom
2531 kernel, you will need to provide appropriate header files.
2532 Under no circumstances should you ever modify the existing
2533 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>
2534 file.
2535 These headers are used to build <filename>libc</filename> and
2536 must not be compromised with custom or machine-specific
2537 header information.
2538 If you customize <filename>libc</filename> through modified
2539 headers all other applications that use
2540 <filename>libc</filename> thus become affected.
2541 <note><title>Warning</title>
2542 Never copy and customize the <filename>libc</filename>
2543 header file (i.e.
2544 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>).
2545 </note>
2546 The correct way to interface to a device or custom kernel is
2547 to use a separate package that provides the additional headers
2548 for the driver or other unique interfaces.
2549 When doing so, your application also becomes responsible for
2550 creating a dependency on that specific provider.
2551 </para>
2552
2553 <para>
2554 Consider the following:
2555 <itemizedlist>
2556 <listitem><para>
2557 Never modify
2558 <filename>linux-libc-headers.inc</filename>.
2559 Consider that file to be part of the
2560 <filename>libc</filename> system, and not something
2561 you use to access the kernel directly.
2562 You should access <filename>libc</filename> through
2563 specific <filename>libc</filename> calls.
2564 </para></listitem>
2565 <listitem><para>
2566 Applications that must talk directly to devices
2567 should either provide necessary headers themselves,
2568 or establish a dependency on a special headers package
2569 that is specific to that driver.
2570 </para></listitem>
2571 </itemizedlist>
2572 </para>
2573
2574 <para>
2575 For example, suppose you want to modify an existing header
2576 that adds I/O control or network support.
2577 If the modifications are used by a small number programs,
2578 providing a unique version of a header is easy and has little
2579 impact.
2580 When doing so, bear in mind the guidelines in the previous
2581 list.
2582 <note>
2583 If for some reason your changes need to modify the behavior
2584 of the <filename>libc</filename>, and subsequently all
2585 other applications on the system, use a
2586 <filename>.bbappend</filename> to modify the
2587 <filename>linux-kernel-headers.inc</filename> file.
2588 However, take care to not make the changes
2589 machine specific.
2590 </note>
2591 </para>
2592
2593 <para>
2594 Consider a case where your kernel is older and you need
2595 an older <filename>libc</filename> ABI.
2596 The headers installed by your recipe should still be a
2597 standard mainline kernel, not your own custom one.
2598 </para>
2599
2600 <para>
2601 When you use custom kernel headers you need to get them from
2602 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>,
2603 which is the directory with kernel headers that are
2604 required to build out-of-tree modules.
2605 Your recipe will also need the following:
2606 <literallayout class='monospaced'>
2607 do_configure[depends] += "virtual/kernel:do_shared_workdir"
2608 </literallayout>
2609 </para>
2610 </section>
2611
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002612 <section id='new-recipe-compilation'>
2613 <title>Compilation</title>
2614
2615 <para>
2616 During a build, the <filename>do_compile</filename> task
2617 happens after source is fetched, unpacked, and configured.
2618 If the recipe passes through <filename>do_compile</filename>
2619 successfully, nothing needs to be done.
2620 </para>
2621
2622 <para>
2623 However, if the compile step fails, you need to diagnose the
2624 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002625 Here are some common issues that cause failures.
2626 <note>
2627 For cases where improper paths are detected for
2628 configuration files or for when libraries/headers cannot
2629 be found, be sure you are using the more robust
2630 <filename>pkg-config</filename>.
2631 See the note in section
2632 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2633 for additional information.
2634 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002635 <itemizedlist>
2636 <listitem><para><emphasis>Parallel build failures:</emphasis>
2637 These failures manifest themselves as intermittent
2638 errors, or errors reporting that a file or directory
2639 that should be created by some other part of the build
2640 process could not be found.
2641 This type of failure can occur even if, upon inspection,
2642 the file or directory does exist after the build has
2643 failed, because that part of the build process happened
2644 in the wrong order.</para>
2645 <para>To fix the problem, you need to either satisfy
2646 the missing dependency in the Makefile or whatever
2647 script produced the Makefile, or (as a workaround)
2648 set
2649 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2650 to an empty string:
2651 <literallayout class='monospaced'>
2652 PARALLEL_MAKE = ""
2653 </literallayout></para>
2654 <para>
2655 For information on parallel Makefile issues, see the
2656 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2657 section.
2658 </para></listitem>
2659 <listitem><para><emphasis>Improper host path usage:</emphasis>
2660 This failure applies to recipes building for the target
2661 or <filename>nativesdk</filename> only.
2662 The failure occurs when the compilation process uses
2663 improper headers, libraries, or other files from the
2664 host system when cross-compiling for the target.
2665 </para>
2666 <para>To fix the problem, examine the
2667 <filename>log.do_compile</filename> file to identify
2668 the host paths being used (e.g.
2669 <filename>/usr/include</filename>,
2670 <filename>/usr/lib</filename>, and so forth) and then
2671 either add configure options, apply a patch, or do both.
2672 </para></listitem>
2673 <listitem><para><emphasis>Failure to find required
2674 libraries/headers:</emphasis>
2675 If a build-time dependency is missing because it has
2676 not been declared in
2677 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2678 or because the dependency exists but the path used by
2679 the build process to find the file is incorrect and the
2680 configure step did not detect it, the compilation
2681 process could fail.
2682 For either of these failures, the compilation process
2683 notes that files could not be found.
2684 In these cases, you need to go back and add additional
2685 options to the configure script as well as possibly
2686 add additional build-time dependencies to
2687 <filename>DEPENDS</filename>.</para>
2688 <para>Occasionally, it is necessary to apply a patch
2689 to the source to ensure the correct paths are used.
2690 If you need to specify paths to find files staged
2691 into the sysroot from other recipes, use the variables
2692 that the OpenEmbedded build system provides
2693 (e.g.
2694 <filename>STAGING_BINDIR</filename>,
2695 <filename>STAGING_INCDIR</filename>,
2696 <filename>STAGING_DATADIR</filename>, and so forth).
2697<!--
2698 (e.g.
2699 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2700 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2701 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2702 and so forth).
2703-->
2704 </para></listitem>
2705 </itemizedlist>
2706 </para>
2707 </section>
2708
2709 <section id='new-recipe-installing'>
2710 <title>Installing</title>
2711
2712 <para>
2713 During <filename>do_install</filename>, the task copies the
2714 built files along with their hierarchy to locations that
2715 would mirror their locations on the target device.
2716 The installation process copies files from the
2717 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2718 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2719 and
2720 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2721 directories to the
2722 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2723 directory to create the structure as it should appear on the
2724 target system.
2725 </para>
2726
2727 <para>
2728 How your software is built affects what you must do to be
2729 sure your software is installed correctly.
2730 The following list describes what you must do for installation
2731 depending on the type of build system used by the software
2732 being built:
2733 <itemizedlist>
2734 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2735 If the software your recipe is building uses Autotools
2736 or CMake, the OpenEmbedded build
2737 system understands how to install the software.
2738 Consequently, you do not have to have a
2739 <filename>do_install</filename> task as part of your
2740 recipe.
2741 You just need to make sure the install portion of the
2742 build completes with no issues.
2743 However, if you wish to install additional files not
2744 already being installed by
2745 <filename>make install</filename>, you should do this
2746 using a <filename>do_install_append</filename> function
2747 using the install command as described in
2748 the "Manual" bulleted item later in this list.
2749 </para></listitem>
2750 <listitem><para><emphasis>Other (using
2751 <filename>make install</filename>):</emphasis>
2752 You need to define a
2753 <filename>do_install</filename> function in your
2754 recipe.
2755 The function should call
2756 <filename>oe_runmake install</filename> and will likely
2757 need to pass in the destination directory as well.
2758 How you pass that path is dependent on how the
2759 <filename>Makefile</filename> being run is written
2760 (e.g. <filename>DESTDIR=${D}</filename>,
2761 <filename>PREFIX=${D}</filename>,
2762 <filename>INSTALLROOT=${D}</filename>, and so forth).
2763 </para>
2764 <para>For an example recipe using
2765 <filename>make install</filename>, see the
2766 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2767 section.</para></listitem>
2768 <listitem><para><emphasis>Manual:</emphasis>
2769 You need to define a
2770 <filename>do_install</filename> function in your
2771 recipe.
2772 The function must first use
2773 <filename>install -d</filename> to create the
2774 directories under
2775 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2776 Once the directories exist, your function can use
2777 <filename>install</filename> to manually install the
2778 built software into the directories.</para>
2779 <para>You can find more information on
2780 <filename>install</filename> at
2781 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2782 </para></listitem>
2783 </itemizedlist>
2784 </para>
2785
2786 <para>
2787 For the scenarios that do not use Autotools or
2788 CMake, you need to track the installation
2789 and diagnose and fix any issues until everything installs
2790 correctly.
2791 You need to look in the default location of
2792 <filename>${D}</filename>, which is
2793 <filename>${WORKDIR}/image</filename>, to be sure your
2794 files have been installed correctly.
2795 </para>
2796
2797 <note><title>Notes</title>
2798 <itemizedlist>
2799 <listitem><para>
2800 During the installation process, you might need to
2801 modify some of the installed files to suit the target
2802 layout.
2803 For example, you might need to replace hard-coded paths
2804 in an initscript with values of variables provided by
2805 the build system, such as replacing
2806 <filename>/usr/bin/</filename> with
2807 <filename>${bindir}</filename>.
2808 If you do perform such modifications during
2809 <filename>do_install</filename>, be sure to modify the
2810 destination file after copying rather than before
2811 copying.
2812 Modifying after copying ensures that the build system
2813 can re-execute <filename>do_install</filename> if
2814 needed.
2815 </para></listitem>
2816 <listitem><para>
2817 <filename>oe_runmake install</filename>, which can be
2818 run directly or can be run indirectly by the
2819 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2820 and
2821 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2822 classes, runs <filename>make install</filename> in
2823 parallel.
2824 Sometimes, a Makefile can have missing dependencies
2825 between targets that can result in race conditions.
2826 If you experience intermittent failures during
2827 <filename>do_install</filename>, you might be able to
2828 work around them by disabling parallel Makefile
2829 installs by adding the following to the recipe:
2830 <literallayout class='monospaced'>
2831 PARALLEL_MAKEINST = ""
2832 </literallayout>
2833 See
2834 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2835 for additional information.
2836 </para></listitem>
Brad Bishop64c979e2019-11-04 13:55:29 -05002837 <listitem><para>
2838 If you need to install one or more custom CMake
2839 toolchain files that are supplied by the
2840 application you are building, install the files to
2841 <filename>${D}${datadir}/cmake/</filename> Modules
2842 during
2843 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>.
2844 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002845 </itemizedlist>
2846 </note>
2847 </section>
2848
2849 <section id='new-recipe-enabling-system-services'>
2850 <title>Enabling System Services</title>
2851
2852 <para>
2853 If you want to install a service, which is a process that
2854 usually starts on boot and runs in the background, then
2855 you must include some additional definitions in your recipe.
2856 </para>
2857
2858 <para>
2859 If you are adding services and the service initialization
2860 script or the service file itself is not installed, you must
2861 provide for that installation in your recipe using a
2862 <filename>do_install_append</filename> function.
2863 If your recipe already has a <filename>do_install</filename>
2864 function, update the function near its end rather than
2865 adding an additional <filename>do_install_append</filename>
2866 function.
2867 </para>
2868
2869 <para>
2870 When you create the installation for your services, you need
2871 to accomplish what is normally done by
2872 <filename>make install</filename>.
2873 In other words, make sure your installation arranges the output
2874 similar to how it is arranged on the target system.
2875 </para>
2876
2877 <para>
2878 The OpenEmbedded build system provides support for starting
2879 services two different ways:
2880 <itemizedlist>
2881 <listitem><para><emphasis>SysVinit:</emphasis>
2882 SysVinit is a system and service manager that
2883 manages the init system used to control the very basic
2884 functions of your system.
2885 The init program is the first program
2886 started by the Linux kernel when the system boots.
2887 Init then controls the startup, running and shutdown
2888 of all other programs.</para>
2889 <para>To enable a service using SysVinit, your recipe
2890 needs to inherit the
2891 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2892 class.
2893 The class helps facilitate safely installing the
2894 package on the target.</para>
2895 <para>You will need to set the
2896 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2897 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2898 and
2899 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2900 variables within your recipe.</para></listitem>
2901 <listitem><para><emphasis>systemd:</emphasis>
2902 System Management Daemon (systemd) was designed to
2903 replace SysVinit and to provide
2904 enhanced management of services.
2905 For more information on systemd, see the systemd
2906 homepage at
2907 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2908 </para>
2909 <para>To enable a service using systemd, your recipe
2910 needs to inherit the
2911 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2912 class.
2913 See the <filename>systemd.bbclass</filename> file
2914 located in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002915 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002916 section for more information.
2917 </para></listitem>
2918 </itemizedlist>
2919 </para>
2920 </section>
2921
2922 <section id='new-recipe-packaging'>
2923 <title>Packaging</title>
2924
2925 <para>
2926 Successful packaging is a combination of automated processes
2927 performed by the OpenEmbedded build system and some
2928 specific steps you need to take.
2929 The following list describes the process:
2930 <itemizedlist>
2931 <listitem><para><emphasis>Splitting Files</emphasis>:
2932 The <filename>do_package</filename> task splits the
2933 files produced by the recipe into logical components.
2934 Even software that produces a single binary might
2935 still have debug symbols, documentation, and other
2936 logical components that should be split out.
2937 The <filename>do_package</filename> task ensures
2938 that files are split up and packaged correctly.
2939 </para></listitem>
2940 <listitem><para><emphasis>Running QA Checks</emphasis>:
2941 The
2942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2943 class adds a step to
2944 the package generation process so that output quality
2945 assurance checks are generated by the OpenEmbedded
2946 build system.
2947 This step performs a range of checks to be sure the
2948 build's output is free of common problems that show
2949 up during runtime.
2950 For information on these checks, see the
2951 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2952 class and the
2953 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2954 chapter in the Yocto Project Reference Manual.
2955 </para></listitem>
2956 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2957 After you build your software, you need to be sure
2958 your packages are correct.
2959 Examine the
2960 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2961 directory and make sure files are where you expect
2962 them to be.
2963 If you discover problems, you can set
2964 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2965 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2966 <filename>do_install(_append)</filename>, and so forth as
2967 needed.
2968 </para></listitem>
2969 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2970 If you need to split an application into several
2971 packages, see the
2972 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2973 section for an example.
2974 </para></listitem>
2975 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2976 For an example showing how to install a
2977 post-installation script, see the
2978 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2979 section.
2980 </para></listitem>
2981 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2982 Depending on what your recipe is building and how it
2983 is configured, it might be important to mark the
2984 packages produced as being specific to a particular
2985 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002986 a particular machine or architecture at all.</para>
2987 <para>By default, packages apply to any machine with the
2988 same architecture as the target machine.
2989 When a recipe produces packages that are
2990 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002991 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2992 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002993 is applied only for a particular machine), you should
2994 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002995 recipe:
2996 <literallayout class='monospaced'>
2997 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002998 </literallayout></para>
2999 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003000 that do not contain anything specific to the target
3001 machine or architecture at all (e.g. recipes
3002 that simply package script files or configuration
3003 files), you should use the
3004 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
3005 class to do this for you by adding this to your
3006 recipe:
3007 <literallayout class='monospaced'>
3008 inherit allarch
3009 </literallayout>
3010 Ensuring that the package architecture is correct is
3011 not critical while you are doing the first few builds
3012 of your recipe.
3013 However, it is important in order
3014 to ensure that your recipe rebuilds (or does not
3015 rebuild) appropriately in response to changes in
3016 configuration, and to ensure that you get the
3017 appropriate packages installed on the target machine,
3018 particularly if you run separate builds for more
3019 than one target machine.
3020 </para></listitem>
3021 </itemizedlist>
3022 </para>
3023 </section>
3024
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003025 <section id='new-sharing-files-between-recipes'>
3026 <title>Sharing Files Between Recipes</title>
3027
3028 <para>
3029 Recipes often need to use files provided by other recipes on
3030 the build host.
3031 For example, an application linking to a common library needs
3032 access to the library itself and its associated headers.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003033 The way this access is accomplished is by populating a sysroot
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003034 with files.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003035 Each recipe has two sysroots in its work directory, one for
3036 target files
3037 (<filename>recipe-sysroot</filename>) and one for files that
3038 are native to the build host
3039 (<filename>recipe-sysroot-native</filename>).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003040 <note>
3041 You could find the term "staging" used within the Yocto
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003042 project regarding files populating sysroots (e.g. the
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003043 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink>
3044 variable).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003045 </note>
3046 </para>
3047
3048 <para>
3049 Recipes should never populate the sysroot directly (i.e. write
3050 files into sysroot).
3051 Instead, files should be installed into standard locations
3052 during the
3053 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3054 task within the
3055 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
3056 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003057 The reason for this limitation is that almost all files that
3058 populate the sysroot are cataloged in manifests in order to
3059 ensure the files can be removed later when a recipe is either
3060 modified or removed.
3061 Thus, the sysroot is able to remain free from stale files.
3062 </para>
3063
3064 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003065 A subset of the files installed by the
3066 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3067 task are used by the
3068 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3069 task as defined by the the
3070 <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>
3071 variable to automatically populate the sysroot.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003072 It is possible to modify the list of directories that populate
3073 the sysroot.
3074 The following example shows how you could add the
3075 <filename>/opt</filename> directory to the list of
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003076 directories within a recipe:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003077 <literallayout class='monospaced'>
3078 SYSROOT_DIRS += "/opt"
3079 </literallayout>
3080 </para>
3081
3082 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003083 For a more complete description of the
3084 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3085 task and its associated functions, see the
3086 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink>
3087 class.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003088 </para>
3089 </section>
3090
Brad Bishop316dfdd2018-06-25 12:45:53 -04003091 <section id='metadata-virtual-providers'>
3092 <title>Using Virtual Providers</title>
3093
3094 <para>
3095 Prior to a build, if you know that several different recipes
3096 provide the same functionality, you can use a virtual provider
3097 (i.e. <filename>virtual/*</filename>) as a placeholder for the
3098 actual provider.
3099 The actual provider is determined at build-time.
3100 </para>
3101
3102 <para>
3103 A common scenario where a virtual provider is used would be
3104 for the kernel recipe.
3105 Suppose you have three kernel recipes whose
3106 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
3107 values map to <filename>kernel-big</filename>,
3108 <filename>kernel-mid</filename>, and
3109 <filename>kernel-small</filename>.
3110 Furthermore, each of these recipes in some way uses a
3111 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3112 statement that essentially identifies itself as being able
3113 to provide <filename>virtual/kernel</filename>.
3114 Here is one way through the
3115 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-kernel'><filename>kernel</filename></ulink>
3116 class:
3117 <literallayout class='monospaced'>
3118 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
3119 </literallayout>
3120 Any recipe that inherits the <filename>kernel</filename> class
3121 is going to utilize a <filename>PROVIDES</filename> statement
3122 that identifies that recipe as being able to provide the
3123 <filename>virtual/kernel</filename> item.
3124 </para>
3125
3126 <para>
3127 Now comes the time to actually build an image and you need a
3128 kernel recipe, but which one?
3129 You can configure your build to call out the kernel recipe
3130 you want by using the
3131 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></ulink>
3132 variable.
3133 As an example, consider the
3134 <ulink url='https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc'><filename>x86-base.inc</filename></ulink>
3135 include file, which is a machine
3136 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>)
3137 configuration file.
3138 This include file is the reason all x86-based machines use the
3139 <filename>linux-yocto</filename> kernel.
3140 Here are the relevant lines from the include file:
3141 <literallayout class='monospaced'>
3142 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
3143 PREFERRED_VERSION_linux-yocto ??= "4.15%"
3144 </literallayout>
3145 </para>
3146
3147 <para>
3148 When you use a virtual provider, you do not have to
3149 "hard code" a recipe name as a build dependency.
3150 You can use the
3151 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3152 variable to state the build is dependent on
3153 <filename>virtual/kernel</filename> for example:
3154 <literallayout class='monospaced'>
3155 DEPENDS = "virtual/kernel"
3156 </literallayout>
3157 During the build, the OpenEmbedded build system picks
3158 the correct recipe needed for the
3159 <filename>virtual/kernel</filename> dependency based on the
3160 <filename>PREFERRED_PROVIDER</filename> variable.
3161 If you want to use the small kernel mentioned at the beginning
3162 of this section, configure your build as follows:
3163 <literallayout class='monospaced'>
3164 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
3165 </literallayout>
3166 <note>
3167 Any recipe that
3168 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3169 a <filename>virtual/*</filename> item that is ultimately
3170 not selected through
3171 <filename>PREFERRED_PROVIDER</filename> does not get built.
3172 Preventing these recipes from building is usually the
3173 desired behavior since this mechanism's purpose is to
3174 select between mutually exclusive alternative providers.
3175 </note>
3176 </para>
3177
3178 <para>
3179 The following lists specific examples of virtual providers:
3180 <itemizedlist>
3181 <listitem><para>
3182 <filename>virtual/kernel</filename>:
3183 Provides the name of the kernel recipe to use when
3184 building a kernel image.
3185 </para></listitem>
3186 <listitem><para>
3187 <filename>virtual/bootloader</filename>:
3188 Provides the name of the bootloader to use when
3189 building an image.
3190 </para></listitem>
3191 <listitem><para>
3192 <filename>virtual/mesa</filename>:
3193 Provides <filename>gbm.pc</filename>.
3194 </para></listitem>
3195 <listitem><para>
3196 <filename>virtual/egl</filename>:
3197 Provides <filename>egl.pc</filename> and possibly
3198 <filename>wayland-egl.pc</filename>.
3199 </para></listitem>
3200 <listitem><para>
3201 <filename>virtual/libgl</filename>:
3202 Provides <filename>gl.pc</filename> (i.e. libGL).
3203 </para></listitem>
3204 <listitem><para>
3205 <filename>virtual/libgles1</filename>:
3206 Provides <filename>glesv1_cm.pc</filename>
3207 (i.e. libGLESv1_CM).
3208 </para></listitem>
3209 <listitem><para>
3210 <filename>virtual/libgles2</filename>:
3211 Provides <filename>glesv2.pc</filename>
3212 (i.e. libGLESv2).
3213 </para></listitem>
3214 </itemizedlist>
3215 </para>
3216 </section>
3217
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003218 <section id='properly-versioning-pre-release-recipes'>
3219 <title>Properly Versioning Pre-Release Recipes</title>
3220
3221 <para>
3222 Sometimes the name of a recipe can lead to versioning
3223 problems when the recipe is upgraded to a final release.
3224 For example, consider the
3225 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
3226 the list of example recipes in the
3227 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
3228 section.
3229 This recipe is at a release candidate stage (i.e.
3230 "rc1").
3231 When the recipe is released, the recipe filename becomes
3232 <filename>irssi_0.8.16.bb</filename>.
3233 The version change from <filename>0.8.16-rc1</filename>
3234 to <filename>0.8.16</filename> is seen as a decrease by the
3235 build system and package managers, so the resulting packages
3236 will not correctly trigger an upgrade.
3237 </para>
3238
3239 <para>
3240 In order to ensure the versions compare properly, the
3241 recommended convention is to set
3242 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
3243 within the recipe to
3244 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
3245 You can use an additional variable so that you can use the
3246 current version elsewhere.
3247 Here is an example:
3248 <literallayout class='monospaced'>
3249 REALPV = "0.8.16-rc1"
3250 PV = "0.8.15+${REALPV}"
3251 </literallayout>
3252 </para>
3253 </section>
3254
3255 <section id='new-recipe-post-installation-scripts'>
3256 <title>Post-Installation Scripts</title>
3257
3258 <para>
3259 Post-installation scripts run immediately after installing
3260 a package on the target or during image creation when a
3261 package is included in an image.
3262 To add a post-installation script to a package, add a
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003263 <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003264 the recipe file (<filename>.bb</filename>) and replace
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003265 <replaceable>PACKAGENAME</replaceable> with the name of the package
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003266 you want to attach to the <filename>postinst</filename>
3267 script.
3268 To apply the post-installation script to the main package
3269 for the recipe, which is usually what is required, specify
3270 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003271 in place of <replaceable>PACKAGENAME</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003272 </para>
3273
3274 <para>
3275 A post-installation function has the following structure:
3276 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003277 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003278 # Commands to carry out
3279 }
3280 </literallayout>
3281 </para>
3282
3283 <para>
3284 The script defined in the post-installation function is
3285 called when the root filesystem is created.
3286 If the script succeeds, the package is marked as installed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003287 <note>
3288 Any RPM post-installation script that runs on the target
3289 should return a 0 exit code.
3290 RPM does not allow non-zero exit codes for these scripts,
3291 and the RPM package manager will cause the package to fail
3292 installation on the target.
3293 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003294 </para>
3295
3296 <para>
3297 Sometimes it is necessary for the execution of a
3298 post-installation script to be delayed until the first boot.
3299 For example, the script might need to be executed on the
3300 device itself.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003301 To delay script execution until boot time, you must explicitly
3302 mark post installs to defer to the target.
3303 You can use <filename>pkg_postinst_ontarget()</filename> or
3304 call
Andrew Geissler82c905d2020-04-13 13:39:40 -05003305 <filename>postinst_intercept delay_to_first_boot</filename>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003306 from <filename>pkg_postinst()</filename>.
3307 Any failure of a <filename>pkg_postinst()</filename> script
3308 (including exit 1) triggers an error during the
3309 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
3310 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003311 </para>
3312
3313 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003314 If you have recipes that use
3315 <filename>pkg_postinst</filename> function
3316 and they require the use of non-standard native
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003317 tools that have dependencies during rootfs construction, you
3318 need to use the
3319 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3320 variable in your recipe to list these tools.
3321 If you do not use this variable, the tools might be missing and
3322 execution of the post-installation script is deferred until
3323 first boot.
3324 Deferring the script to first boot is undesirable and for
3325 read-only rootfs impossible.
3326 </para>
3327
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003328 <note>
3329 Equivalent support for pre-install, pre-uninstall, and
3330 post-uninstall scripts exist by way of
3331 <filename>pkg_preinst</filename>,
3332 <filename>pkg_prerm</filename>, and
3333 <filename>pkg_postrm</filename>, respectively.
3334 These scrips work in exactly the same way as does
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003335 <filename>pkg_postinst</filename> with the exception
3336 that they run at different times.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003337 Also, because of when they run, they are not applicable to
3338 being run at image creation time like
3339 <filename>pkg_postinst</filename>.
3340 </note>
3341 </section>
3342
3343 <section id='new-recipe-testing'>
3344 <title>Testing</title>
3345
3346 <para>
3347 The final step for completing your recipe is to be sure that
3348 the software you built runs correctly.
3349 To accomplish runtime testing, add the build's output
3350 packages to your image and test them on the target.
3351 </para>
3352
3353 <para>
3354 For information on how to customize your image by adding
3355 specific packages, see the
3356 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3357 section.
3358 </para>
3359 </section>
3360
3361 <section id='new-recipe-testing-examples'>
3362 <title>Examples</title>
3363
3364 <para>
3365 To help summarize how to write a recipe, this section provides
3366 some examples given various scenarios:
3367 <itemizedlist>
3368 <listitem><para>Recipes that use local files</para></listitem>
3369 <listitem><para>Using an Autotooled package</para></listitem>
3370 <listitem><para>Using a Makefile-based package</para></listitem>
3371 <listitem><para>Splitting an application into multiple packages</para></listitem>
3372 <listitem><para>Adding binaries to an image</para></listitem>
3373 </itemizedlist>
3374 </para>
3375
3376 <section id='new-recipe-single-c-file-package-hello-world'>
3377 <title>Single .c File Package (Hello World!)</title>
3378
3379 <para>
3380 Building an application from a single file that is stored
3381 locally (e.g. under <filename>files</filename>) requires
3382 a recipe that has the file listed in the
3383 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3384 variable.
3385 Additionally, you need to manually write the
3386 <filename>do_compile</filename> and
3387 <filename>do_install</filename> tasks.
3388 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3389 variable defines the directory containing the source code,
3390 which is set to
3391 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3392 in this case - the directory BitBake uses for the build.
3393 <literallayout class='monospaced'>
3394 SUMMARY = "Simple helloworld application"
3395 SECTION = "examples"
3396 LICENSE = "MIT"
3397 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3398
3399 SRC_URI = "file://helloworld.c"
3400
3401 S = "${WORKDIR}"
3402
3403 do_compile() {
3404 ${CC} helloworld.c -o helloworld
3405 }
3406
3407 do_install() {
3408 install -d ${D}${bindir}
3409 install -m 0755 helloworld ${D}${bindir}
3410 }
3411 </literallayout>
3412 </para>
3413
3414 <para>
3415 By default, the <filename>helloworld</filename>,
3416 <filename>helloworld-dbg</filename>, and
3417 <filename>helloworld-dev</filename> packages are built.
3418 For information on how to customize the packaging process,
3419 see the
3420 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3421 section.
3422 </para>
3423 </section>
3424
3425 <section id='new-recipe-autotooled-package'>
3426 <title>Autotooled Package</title>
3427 <para>
3428 Applications that use Autotools such as <filename>autoconf</filename> and
3429 <filename>automake</filename> require a recipe that has a source archive listed in
3430 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3431 also inherit the
3432 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3433 class, which contains the definitions of all the steps
3434 needed to build an Autotool-based application.
3435 The result of the build is automatically packaged.
3436 And, if the application uses NLS for localization, packages with local information are
3437 generated (one package per language).
3438 Following is one example: (<filename>hello_2.3.bb</filename>)
3439 <literallayout class='monospaced'>
3440 SUMMARY = "GNU Helloworld application"
3441 SECTION = "examples"
3442 LICENSE = "GPLv2+"
3443 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3444
3445 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3446
3447 inherit autotools gettext
3448 </literallayout>
3449 </para>
3450
3451 <para>
3452 The variable
3453 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3454 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003455 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3456 section in the Yocto Project Overview and Concepts Manual.
3457 You can quickly create Autotool-based recipes in a manner
3458 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003459 </para>
3460 </section>
3461
3462 <section id='new-recipe-makefile-based-package'>
3463 <title>Makefile-Based Package</title>
3464
3465 <para>
3466 Applications that use GNU <filename>make</filename> also require a recipe that has
3467 the source archive listed in
3468 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3469 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3470 starts the <filename>make</filename> command to compile the application.
3471 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003472 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3473 or
3474 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3475 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003476 BitBake passes these options into the GNU <filename>make</filename> invocation.
3477 Note that a <filename>do_install</filename> task is still required.
3478 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3479 </para>
3480
3481 <para>
3482 Some applications might require extra parameters to be passed to the compiler.
3483 For example, the application might need an additional header path.
3484 You can accomplish this by adding to the
3485 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3486 The following example shows this:
3487 <literallayout class='monospaced'>
3488 CFLAGS_prepend = "-I ${S}/include "
3489 </literallayout>
3490 </para>
3491
3492 <para>
3493 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3494 <literallayout class='monospaced'>
3495 SUMMARY = "Tools for managing memory technology devices"
3496 SECTION = "base"
3497 DEPENDS = "zlib lzo e2fsprogs util-linux"
3498 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3499 LICENSE = "GPLv2+"
3500 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3501 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3502
3503 # Use the latest version at 26 Oct, 2013
3504 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3505 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3506 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3507 "
3508
3509 PV = "1.5.1+git${SRCPV}"
3510
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003511 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003512
3513 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3514
3515 do_install () {
3516 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3517 }
3518
3519 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3520
3521 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3522 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3523 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3524
3525 PARALLEL_MAKE = ""
3526
3527 BBCLASSEXTEND = "native"
3528 </literallayout>
3529 </para>
3530 </section>
3531
3532 <section id='splitting-an-application-into-multiple-packages'>
3533 <title>Splitting an Application into Multiple Packages</title>
3534
3535 <para>
3536 You can use the variables
3537 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3538 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3539 to split an application into multiple packages.
3540 </para>
3541
3542 <para>
3543 Following is an example that uses the <filename>libxpm</filename> recipe.
3544 By default, this recipe generates a single package that contains the library along
3545 with a few binaries.
3546 You can modify the recipe to split the binaries into separate packages:
3547 <literallayout class='monospaced'>
3548 require xorg-lib-common.inc
3549
3550 SUMMARY = "Xpm: X Pixmap extension library"
3551 LICENSE = "BSD"
3552 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3553 DEPENDS += "libxext libsm libxt"
3554 PE = "1"
3555
3556 XORG_PN = "libXpm"
3557
3558 PACKAGES =+ "sxpm cxpm"
3559 FILES_cxpm = "${bindir}/cxpm"
3560 FILES_sxpm = "${bindir}/sxpm"
3561 </literallayout>
3562 </para>
3563
3564 <para>
3565 In the previous example, we want to ship the <filename>sxpm</filename>
3566 and <filename>cxpm</filename> binaries in separate packages.
3567 Since <filename>bindir</filename> would be packaged into the main
3568 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3569 package by default, we prepend the <filename>PACKAGES</filename>
3570 variable so additional package names are added to the start of list.
3571 This results in the extra <filename>FILES_*</filename>
3572 variables then containing information that define which files and
3573 directories go into which packages.
3574 Files included by earlier packages are skipped by latter packages.
3575 Thus, the main <filename>PN</filename> package
3576 does not include the above listed files.
3577 </para>
3578 </section>
3579
3580 <section id='packaging-externally-produced-binaries'>
3581 <title>Packaging Externally Produced Binaries</title>
3582
3583 <para>
3584 Sometimes, you need to add pre-compiled binaries to an
3585 image.
3586 For example, suppose that binaries for proprietary code
3587 exist, which are created by a particular division of a
3588 company.
3589 Your part of the company needs to use those binaries as
3590 part of an image that you are building using the
3591 OpenEmbedded build system.
3592 Since you only have the binaries and not the source code,
3593 you cannot use a typical recipe that expects to fetch the
3594 source specified in
3595 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3596 and then compile it.
3597 </para>
3598
3599 <para>
3600 One method is to package the binaries and then install them
3601 as part of the image.
3602 Generally, it is not a good idea to package binaries
3603 since, among other things, it can hinder the ability to
3604 reproduce builds and could lead to compatibility problems
3605 with ABI in the future.
3606 However, sometimes you have no choice.
3607 </para>
3608
3609 <para>
3610 The easiest solution is to create a recipe that uses
3611 the
3612 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3613 class and to be sure that you are using default locations
3614 for build artifacts.
3615 In most cases, the <filename>bin_package</filename> class
3616 handles "skipping" the configure and compile steps as well
3617 as sets things up to grab packages from the appropriate
3618 area.
3619 In particular, this class sets <filename>noexec</filename>
3620 on both the
3621 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3622 and
3623 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3624 tasks, sets
3625 <filename>FILES_${PN}</filename> to "/" so that it picks
3626 up all files, and sets up a
3627 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3628 task, which effectively copies all files from
3629 <filename>${S}</filename> to <filename>${D}</filename>.
3630 The <filename>bin_package</filename> class works well when
3631 the files extracted into <filename>${S}</filename> are
3632 already laid out in the way they should be laid out
3633 on the target.
3634 For more information on these variables, see the
3635 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3636 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3637 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3638 and
3639 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3640 variables in the Yocto Project Reference Manual's variable
3641 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003642 <note><title>Notes</title>
3643 <itemizedlist>
3644 <listitem><para>
3645 Using
3646 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3647 is a good idea even for components distributed
3648 in binary form, and is often necessary for
3649 shared libraries.
3650 For a shared library, listing the library
3651 dependencies in
3652 <filename>DEPENDS</filename> makes sure that
3653 the libraries are available in the staging
3654 sysroot when other recipes link against the
3655 library, which might be necessary for
3656 successful linking.
3657 </para></listitem>
3658 <listitem><para>
3659 Using <filename>DEPENDS</filename> also
3660 allows runtime dependencies between packages
3661 to be added automatically.
3662 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003663 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3664 section in the Yocto Project Overview and
3665 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003666 </para></listitem>
3667 </itemizedlist>
3668 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003669 </para>
3670
3671 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003672 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003673 class, you need to be sure you are doing the following:
3674 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003675 <listitem><para>
3676 Create a recipe where the
3677 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3678 and
3679 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3680 tasks do nothing:
3681 It is usually sufficient to just not define these
3682 tasks in the recipe, because the default
3683 implementations do nothing unless a Makefile is
3684 found in
3685 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3686 </para>
3687
3688 <para>If
3689 <filename>${S}</filename> might contain a Makefile,
3690 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003691 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003692 <filename>do_compile</filename> with custom
3693 versions, then you can use the
3694 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3695 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003696 <literallayout class='monospaced'>
3697 do_configure[noexec] = "1"
3698 do_compile[noexec] = "1"
3699 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003700 Unlike
3701 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3702 using the flag preserves the dependency chain from
3703 the
3704 <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>,
3705 and
3706 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3707 tasks to the
3708 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3709 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003710 </para></listitem>
3711 <listitem><para>Make sure your
3712 <filename>do_install</filename> task installs the
3713 binaries appropriately.
3714 </para></listitem>
3715 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003716 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3717 (usually
3718 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3719 to point to the files you have installed, which of
3720 course depends on where you have installed them
3721 and whether those files are in different locations
3722 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003723 </para></listitem>
3724 </itemizedlist>
3725 </para>
3726 </section>
3727 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003728
3729 <section id="following-recipe-style-guidelines">
3730 <title>Following Recipe Style Guidelines</title>
3731
3732 <para>
3733 When writing recipes, it is good to conform to existing
3734 style guidelines.
3735 The
3736 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3737 wiki page provides rough guidelines for preferred recipe style.
3738 </para>
3739
3740 <para>
3741 It is common for existing recipes to deviate a bit from this
3742 style.
3743 However, aiming for at least a consistent style is a good idea.
3744 Some practices, such as omitting spaces around
3745 <filename>=</filename> operators in assignments or ordering
3746 recipe components in an erratic way, are widely seen as poor
3747 style.
3748 </para>
3749 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003750
3751 <section id='recipe-syntax'>
3752 <title>Recipe Syntax</title>
3753
3754 <para>
3755 Understanding recipe file syntax is important for writing
3756 recipes.
3757 The following list overviews the basic items that make up a
3758 BitBake recipe file.
3759 For more complete BitBake syntax descriptions, see the
3760 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3761 chapter of the BitBake User Manual.
3762 <itemizedlist>
3763 <listitem><para>
3764 <emphasis>Variable Assignments and Manipulations:</emphasis>
3765 Variable assignments allow a value to be assigned to a
3766 variable.
3767 The assignment can be static text or might include
3768 the contents of other variables.
3769 In addition to the assignment, appending and prepending
3770 operations are also supported.</para>
3771
3772 <para>The following example shows some of the ways
3773 you can use variables in recipes:
3774 <literallayout class='monospaced'>
3775 S = "${WORKDIR}/postfix-${PV}"
3776 CFLAGS += "-DNO_ASM"
3777 SRC_URI_append = " file://fixup.patch"
3778 </literallayout>
3779 </para></listitem>
3780 <listitem><para>
3781 <emphasis>Functions:</emphasis>
3782 Functions provide a series of actions to be performed.
3783 You usually use functions to override the default
3784 implementation of a task function or to complement
3785 a default function (i.e. append or prepend to an
3786 existing function).
3787 Standard functions use <filename>sh</filename> shell
3788 syntax, although access to OpenEmbedded variables and
3789 internal methods are also available.</para>
3790
3791 <para>The following is an example function from the
3792 <filename>sed</filename> recipe:
3793 <literallayout class='monospaced'>
3794 do_install () {
3795 autotools_do_install
3796 install -d ${D}${base_bindir}
3797 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3798 rmdir ${D}${bindir}/
3799 }
3800 </literallayout>
3801 It is also possible to implement new functions that
3802 are called between existing tasks as long as the
3803 new functions are not replacing or complementing the
3804 default functions.
3805 You can implement functions in Python
3806 instead of shell.
3807 Both of these options are not seen in the majority of
3808 recipes.
3809 </para></listitem>
3810 <listitem><para><emphasis>Keywords:</emphasis>
3811 BitBake recipes use only a few keywords.
3812 You use keywords to include common
3813 functions (<filename>inherit</filename>), load parts
3814 of a recipe from other files
3815 (<filename>include</filename> and
3816 <filename>require</filename>) and export variables
3817 to the environment (<filename>export</filename>).
3818 </para>
3819
3820 <para>The following example shows the use of some of
3821 these keywords:
3822 <literallayout class='monospaced'>
3823 export POSTCONF = "${STAGING_BINDIR}/postconf"
3824 inherit autoconf
3825 require otherfile.inc
3826 </literallayout>
3827 </para></listitem>
3828 <listitem><para>
3829 <emphasis>Comments (#):</emphasis>
3830 Any lines that begin with the hash character
3831 (<filename>#</filename>) are treated as comment lines
3832 and are ignored:
3833 <literallayout class='monospaced'>
3834 # This is a comment
3835 </literallayout>
3836 </para></listitem>
3837 </itemizedlist>
3838 </para>
3839
3840 <para>
3841 This next list summarizes the most important and most commonly
3842 used parts of the recipe syntax.
3843 For more information on these parts of the syntax, you can
3844 reference the
3845 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3846 chapter in the BitBake User Manual.
3847 <itemizedlist>
3848 <listitem><para>
3849 <emphasis>Line Continuation (\):</emphasis>
3850 Use the backward slash (<filename>\</filename>)
3851 character to split a statement over multiple lines.
3852 Place the slash character at the end of the line that
3853 is to be continued on the next line:
3854 <literallayout class='monospaced'>
3855 VAR = "A really long \
3856 line"
3857 </literallayout>
3858 <note>
3859 You cannot have any characters including spaces
3860 or tabs after the slash character.
3861 </note>
3862 </para></listitem>
3863 <listitem><para>
3864 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3865 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3866 syntax to access the contents of a variable:
3867 <literallayout class='monospaced'>
3868 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3869 </literallayout>
3870 <note>
3871 It is important to understand that the value of a
3872 variable expressed in this form does not get
3873 substituted automatically.
3874 The expansion of these expressions happens
3875 on-demand later (e.g. usually when a function that
3876 makes reference to the variable executes).
3877 This behavior ensures that the values are most
3878 appropriate for the context in which they are
3879 finally used.
3880 On the rare occasion that you do need the variable
3881 expression to be expanded immediately, you can use
3882 the <filename>:=</filename> operator instead of
3883 <filename>=</filename> when you make the
3884 assignment, but this is not generally needed.
3885 </note>
3886 </para></listitem>
3887 <listitem><para>
3888 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3889 Use double quotes around values in all variable
3890 assignments (e.g.
3891 <filename>"<replaceable>value</replaceable>"</filename>).
3892 Following is an example:
3893 <literallayout class='monospaced'>
3894 VAR1 = "${OTHERVAR}"
3895 VAR2 = "The version is ${PV}"
3896 </literallayout>
3897 </para></listitem>
3898 <listitem><para>
3899 <emphasis>Conditional Assignment (?=):</emphasis>
3900 Conditional assignment is used to assign a
3901 value to a variable, but only when the variable is
3902 currently unset.
3903 Use the question mark followed by the equal sign
3904 (<filename>?=</filename>) to make a "soft" assignment
3905 used for conditional assignment.
3906 Typically, "soft" assignments are used in the
3907 <filename>local.conf</filename> file for variables
3908 that are allowed to come through from the external
3909 environment.
3910 </para>
3911
3912 <para>Here is an example where
3913 <filename>VAR1</filename> is set to "New value" if
3914 it is currently empty.
3915 However, if <filename>VAR1</filename> has already been
3916 set, it remains unchanged:
3917 <literallayout class='monospaced'>
3918 VAR1 ?= "New value"
3919 </literallayout>
3920 In this next example, <filename>VAR1</filename>
3921 is left with the value "Original value":
3922 <literallayout class='monospaced'>
3923 VAR1 = "Original value"
3924 VAR1 ?= "New value"
3925 </literallayout>
3926 </para></listitem>
3927 <listitem><para>
3928 <emphasis>Appending (+=):</emphasis>
3929 Use the plus character followed by the equals sign
3930 (<filename>+=</filename>) to append values to existing
3931 variables.
3932 <note>
3933 This operator adds a space between the existing
3934 content of the variable and the new content.
3935 </note></para>
3936
3937 <para>Here is an example:
3938 <literallayout class='monospaced'>
3939 SRC_URI += "file://fix-makefile.patch"
3940 </literallayout>
3941 </para></listitem>
3942 <listitem><para>
3943 <emphasis>Prepending (=+):</emphasis>
3944 Use the equals sign followed by the plus character
3945 (<filename>=+</filename>) to prepend values to existing
3946 variables.
3947 <note>
3948 This operator adds a space between the new content
3949 and the existing content of the variable.
3950 </note></para>
3951
3952 <para>Here is an example:
3953 <literallayout class='monospaced'>
3954 VAR =+ "Starts"
3955 </literallayout>
3956 </para></listitem>
3957 <listitem><para>
3958 <emphasis>Appending (_append):</emphasis>
3959 Use the <filename>_append</filename> operator to
3960 append values to existing variables.
3961 This operator does not add any additional space.
3962 Also, the operator is applied after all the
3963 <filename>+=</filename>, and
3964 <filename>=+</filename> operators have been applied and
3965 after all <filename>=</filename> assignments have
3966 occurred.
3967 </para>
3968
3969 <para>The following example shows the space being
3970 explicitly added to the start to ensure the appended
3971 value is not merged with the existing value:
3972 <literallayout class='monospaced'>
3973 SRC_URI_append = " file://fix-makefile.patch"
3974 </literallayout>
3975 You can also use the <filename>_append</filename>
3976 operator with overrides, which results in the actions
3977 only being performed for the specified target or
3978 machine:
3979 <literallayout class='monospaced'>
3980 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3981 </literallayout>
3982 </para></listitem>
3983 <listitem><para>
3984 <emphasis>Prepending (_prepend):</emphasis>
3985 Use the <filename>_prepend</filename> operator to
3986 prepend values to existing variables.
3987 This operator does not add any additional space.
3988 Also, the operator is applied after all the
3989 <filename>+=</filename>, and
3990 <filename>=+</filename> operators have been applied and
3991 after all <filename>=</filename> assignments have
3992 occurred.
3993 </para>
3994
3995 <para>The following example shows the space being
3996 explicitly added to the end to ensure the prepended
3997 value is not merged with the existing value:
3998 <literallayout class='monospaced'>
3999 CFLAGS_prepend = "-I${S}/myincludes "
4000 </literallayout>
4001 You can also use the <filename>_prepend</filename>
4002 operator with overrides, which results in the actions
4003 only being performed for the specified target or
4004 machine:
4005 <literallayout class='monospaced'>
4006 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
4007 </literallayout>
4008 </para></listitem>
4009 <listitem><para>
4010 <emphasis>Overrides:</emphasis>
4011 You can use overrides to set a value conditionally,
4012 typically based on how the recipe is being built.
4013 For example, to set the
4014 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
4015 variable's value to "standard/base" for any target
4016 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
4017 except for qemuarm where it should be set to
4018 "standard/arm-versatile-926ejs", you would do the
4019 following:
4020 <literallayout class='monospaced'>
4021 KBRANCH = "standard/base"
4022 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
4023 </literallayout>
4024 Overrides are also used to separate alternate values
4025 of a variable in other situations.
4026 For example, when setting variables such as
4027 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
4028 and
4029 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
4030 that are specific to individual packages produced by
4031 a recipe, you should always use an override that
4032 specifies the name of the package.
4033 </para></listitem>
4034 <listitem><para>
4035 <emphasis>Indentation:</emphasis>
4036 Use spaces for indentation rather than than tabs.
4037 For shell functions, both currently work.
4038 However, it is a policy decision of the Yocto Project
4039 to use tabs in shell functions.
4040 Realize that some layers have a policy to use spaces
4041 for all indentation.
4042 </para></listitem>
4043 <listitem><para>
4044 <emphasis>Using Python for Complex Operations:</emphasis>
4045 For more advanced processing, it is possible to use
4046 Python code during variable assignments (e.g.
4047 search and replacement on a variable).</para>
4048
4049 <para>You indicate Python code using the
4050 <filename>${@<replaceable>python_code</replaceable>}</filename>
4051 syntax for the variable assignment:
4052 <literallayout class='monospaced'>
4053 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
4054 </literallayout>
4055 </para></listitem>
4056 <listitem><para>
4057 <emphasis>Shell Function Syntax:</emphasis>
4058 Write shell functions as if you were writing a shell
4059 script when you describe a list of actions to take.
4060 You should ensure that your script works with a generic
4061 <filename>sh</filename> and that it does not require
4062 any <filename>bash</filename> or other shell-specific
4063 functionality.
4064 The same considerations apply to various system
4065 utilities (e.g. <filename>sed</filename>,
4066 <filename>grep</filename>, <filename>awk</filename>,
4067 and so forth) that you might wish to use.
4068 If in doubt, you should check with multiple
4069 implementations - including those from BusyBox.
4070 </para></listitem>
4071 </itemizedlist>
4072 </para>
4073 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004074 </section>
4075
4076 <section id="platdev-newmachine">
4077 <title>Adding a New Machine</title>
4078
4079 <para>
4080 Adding a new machine to the Yocto Project is a straightforward
4081 process.
4082 This section describes how to add machines that are similar
4083 to those that the Yocto Project already supports.
4084 <note>
4085 Although well within the capabilities of the Yocto Project,
4086 adding a totally new architecture might require
4087 changes to <filename>gcc/glibc</filename> and to the site
4088 information, which is beyond the scope of this manual.
4089 </note>
4090 </para>
4091
4092 <para>
4093 For a complete example that shows how to add a new machine,
4094 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004095 "<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>"
4096 section in the Yocto Project Board Support Package (BSP)
4097 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004098 </para>
4099
4100 <section id="platdev-newmachine-conffile">
4101 <title>Adding the Machine Configuration File</title>
4102
4103 <para>
4104 To add a new machine, you need to add a new machine
4105 configuration file to the layer's
4106 <filename>conf/machine</filename> directory.
4107 This configuration file provides details about the device
4108 you are adding.
4109 </para>
4110
4111 <para>
4112 The OpenEmbedded build system uses the root name of the
4113 machine configuration file to reference the new machine.
4114 For example, given a machine configuration file named
4115 <filename>crownbay.conf</filename>, the build system
4116 recognizes the machine as "crownbay".
4117 </para>
4118
4119 <para>
4120 The most important variables you must set in your machine
4121 configuration file or include from a lower-level configuration
4122 file are as follows:
4123 <itemizedlist>
4124 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4125 (e.g. "arm")</para></listitem>
4126 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4127 </para></listitem>
4128 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4129 (e.g. "apm screen wifi")</para></listitem>
4130 </itemizedlist>
4131 </para>
4132
4133 <para>
4134 You might also need these variables:
4135 <itemizedlist>
4136 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4137 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4138 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4139 (e.g. "zImage")</para></listitem>
4140 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4141 (e.g. "tar.gz jffs2")</para></listitem>
4142 </itemizedlist>
4143 </para>
4144
4145 <para>
4146 You can find full details on these variables in the reference
4147 section.
4148 You can leverage existing machine <filename>.conf</filename>
4149 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4150 </para>
4151 </section>
4152
4153 <section id="platdev-newmachine-kernel">
4154 <title>Adding a Kernel for the Machine</title>
4155
4156 <para>
4157 The OpenEmbedded build system needs to be able to build a kernel
4158 for the machine.
4159 You need to either create a new kernel recipe for this machine,
4160 or extend an existing kernel recipe.
4161 You can find several kernel recipe examples in the
4162 Source Directory at
4163 <filename>meta/recipes-kernel/linux</filename>
4164 that you can use as references.
4165 </para>
4166
4167 <para>
4168 If you are creating a new kernel recipe, normal recipe-writing
4169 rules apply for setting up a
4170 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4171 Thus, you need to specify any necessary patches and set
4172 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4173 to point at the source code.
4174 You need to create a <filename>do_configure</filename> task that
4175 configures the unpacked kernel with a
4176 <filename>defconfig</filename> file.
4177 You can do this by using a <filename>make defconfig</filename>
4178 command or, more commonly, by copying in a suitable
4179 <filename>defconfig</filename> file and then running
4180 <filename>make oldconfig</filename>.
4181 By making use of <filename>inherit kernel</filename> and
4182 potentially some of the <filename>linux-*.inc</filename> files,
4183 most other functionality is centralized and the defaults of the
4184 class normally work well.
4185 </para>
4186
4187 <para>
4188 If you are extending an existing kernel recipe, it is usually
4189 a matter of adding a suitable <filename>defconfig</filename>
4190 file.
4191 The file needs to be added into a location similar to
4192 <filename>defconfig</filename> files used for other machines
4193 in a given kernel recipe.
4194 A possible way to do this is by listing the file in the
4195 <filename>SRC_URI</filename> and adding the machine to the
4196 expression in
4197 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4198 <literallayout class='monospaced'>
4199 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4200 </literallayout>
4201 For more information on <filename>defconfig</filename> files,
4202 see the
4203 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4204 section in the Yocto Project Linux Kernel Development Manual.
4205 </para>
4206 </section>
4207
4208 <section id="platdev-newmachine-formfactor">
4209 <title>Adding a Formfactor Configuration File</title>
4210
4211 <para>
4212 A formfactor configuration file provides information about the
4213 target hardware for which the image is being built and information that
4214 the build system cannot obtain from other sources such as the kernel.
4215 Some examples of information contained in a formfactor configuration file include
4216 framebuffer orientation, whether or not the system has a keyboard,
4217 the positioning of the keyboard in relation to the screen, and
4218 the screen resolution.
4219 </para>
4220
4221 <para>
4222 The build system uses reasonable defaults in most cases.
4223 However, if customization is
4224 necessary, you need to create a <filename>machconfig</filename> file
4225 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4226 directory.
4227 This directory contains directories for specific machines such as
4228 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4229 For information about the settings available and the defaults, see the
4230 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4231 same area.
4232 </para>
4233
4234 <para>
4235 Following is an example for "qemuarm" machine:
4236 <literallayout class='monospaced'>
4237 HAVE_TOUCHSCREEN=1
4238 HAVE_KEYBOARD=1
4239
4240 DISPLAY_CAN_ROTATE=0
4241 DISPLAY_ORIENTATION=0
4242 #DISPLAY_WIDTH_PIXELS=640
4243 #DISPLAY_HEIGHT_PIXELS=480
4244 #DISPLAY_BPP=16
4245 DISPLAY_DPI=150
4246 DISPLAY_SUBPIXEL_ORDER=vrgb
4247 </literallayout>
4248 </para>
4249 </section>
4250 </section>
4251
Brad Bishop316dfdd2018-06-25 12:45:53 -04004252 <section id='gs-upgrading-recipes'>
4253 <title>Upgrading Recipes</title>
4254
4255 <para>
4256 Over time, upstream developers publish new versions for software
4257 built by layer recipes.
4258 It is recommended to keep recipes up-to-date with upstream
4259 version releases.
Brad Bishop15ae2502019-06-18 21:44:24 -04004260 </para>
4261
4262 <para>
4263 While several methods exist that allow you upgrade a recipe,
4264 you might consider checking on the upgrade status of a recipe
4265 first.
4266 You can do so using the
4267 <filename>devtool check-upgrade-status</filename> command.
4268 See the
4269 "<ulink url='&YOCTO_DOCS_REF_URL;#devtool-checking-on-the-upgrade-status-of-a-recipe'>Checking on the Upgrade Status of a Recipe</ulink>"
4270 section in the Yocto Project Reference Manual for more information.
4271 </para>
4272
4273 <para>
4274 The remainder of this section describes three ways you can
4275 upgrade a recipe.
Brad Bishop316dfdd2018-06-25 12:45:53 -04004276 You can use the Automated Upgrade Helper (AUH) to set up
4277 automatic version upgrades.
4278 Alternatively, you can use <filename>devtool upgrade</filename>
4279 to set up semi-automatic version upgrades.
Brad Bishop15ae2502019-06-18 21:44:24 -04004280 Finally, you can manually upgrade a recipe by editing the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004281 recipe itself.
4282 </para>
4283
4284 <section id='gs-using-the-auto-upgrade-helper'>
4285 <title>Using the Auto Upgrade Helper (AUH)</title>
4286
4287 <para>
4288 The AUH utility works in conjunction with the
4289 OpenEmbedded build system in order to automatically generate
4290 upgrades for recipes based on new versions being
4291 published upstream.
4292 Use AUH when you want to create a service that performs the
4293 upgrades automatically and optionally sends you an email with
4294 the results.
4295 </para>
4296
4297 <para>
4298 AUH allows you to update several recipes with a single use.
4299 You can also optionally perform build and integration tests
4300 using images with the results saved to your hard drive and
4301 emails of results optionally sent to recipe maintainers.
4302 Finally, AUH creates Git commits with appropriate commit
4303 messages in the layer's tree for the changes made to recipes.
4304 <note>
4305 Conditions do exist when you should not use AUH to upgrade
4306 recipes and you should instead use either
4307 <filename>devtool upgrade</filename> or upgrade your
4308 recipes manually:
4309 <itemizedlist>
4310 <listitem><para>
4311 When AUH cannot complete the upgrade sequence.
4312 This situation usually results because custom
4313 patches carried by the recipe cannot be
4314 automatically rebased to the new version.
4315 In this case, <filename>devtool upgrade</filename>
4316 allows you to manually resolve conflicts.
4317 </para></listitem>
4318 <listitem><para>
4319 When for any reason you want fuller control over
4320 the upgrade process.
4321 For example, when you want special arrangements
4322 for testing.
4323 </para></listitem>
4324 </itemizedlist>
4325 </note>
4326 </para>
4327
4328 <para>
4329 The following steps describe how to set up the AUH utility:
4330 <orderedlist>
4331 <listitem><para>
4332 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4333 You need to be sure that your development host is
4334 set up to use the Yocto Project.
4335 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004336 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004337 section.
4338 </para></listitem>
4339 <listitem><para>
4340 <emphasis>Make Sure Git is Configured:</emphasis>
4341 The AUH utility requires Git to be configured because
4342 AUH uses Git to save upgrades.
4343 Thus, you must have Git user and email configured.
4344 The following command shows your configurations:
4345 <literallayout class='monospaced'>
4346 $ git config --list
4347 </literallayout>
4348 If you do not have the user and email configured, you
4349 can use the following commands to do so:
4350 <literallayout class='monospaced'>
4351 $ git config --global user.name <replaceable>some_name</replaceable>
4352 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4353 </literallayout>
4354 </para></listitem>
4355 <listitem><para>
4356 <emphasis>Clone the AUH Repository:</emphasis>
4357 To use AUH, you must clone the repository onto your
4358 development host.
4359 The following command uses Git to create a local
4360 copy of the repository on your system:
4361 <literallayout class='monospaced'>
4362 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4363 Cloning into 'auto-upgrade-helper'...
4364 remote: Counting objects: 768, done.
4365 remote: Compressing objects: 100% (300/300), done.
4366 remote: Total 768 (delta 499), reused 703 (delta 434)
4367 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4368 Resolving deltas: 100% (499/499), done.
4369 Checking connectivity... done.
4370 </literallayout>
4371 AUH is not part of the
4372 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4373 or
4374 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4375 repositories.
4376 </para></listitem>
4377 <listitem><para>
4378 <emphasis>Create a Dedicated Build Directory:</emphasis>
4379 Run the
4380 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4381 script to create a fresh build directory that you
4382 use exclusively for running the AUH utility:
4383 <literallayout class='monospaced'>
4384 $ cd ~/poky
4385 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4386 </literallayout>
4387 Re-using an existing build directory and its
4388 configurations is not recommended as existing settings
4389 could cause AUH to fail or behave undesirably.
4390 </para></listitem>
4391 <listitem><para>
4392 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4393 Several settings need to exist in the
4394 <filename>local.conf</filename> file in the build
4395 directory you just created for AUH.
4396 Make these following configurations:
4397 <itemizedlist>
4398 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04004399 If you want to enable
4400 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4401 which is optional, you need the following
4402 lines in the
4403 <filename>conf/local.conf</filename> file:
4404 <literallayout class='monospaced'>
4405 INHERIT =+ "buildhistory"
4406 BUILDHISTORY_COMMIT = "1"
4407 </literallayout>
4408 With this configuration and a successful
4409 upgrade, a build history "diff" file appears in
4410 the
4411 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4412 file found in your build directory.
4413 </para></listitem>
4414 <listitem><para>
4415 If you want to enable testing through the
4416 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4417 class, which is optional, you need to have the
4418 following set in your
4419 <filename>conf/local.conf</filename> file:
4420 <literallayout class='monospaced'>
4421 INHERIT += "testimage"
4422 </literallayout>
4423 <note>
4424 If your distro does not enable by default
4425 ptest, which Poky does, you need the
4426 following in your
4427 <filename>local.conf</filename> file:
4428 <literallayout class='monospaced'>
4429 DISTRO_FEATURES_append = " ptest"
4430 </literallayout>
4431 </note>
4432 </para></listitem>
4433 </itemizedlist>
4434 </para></listitem>
4435 <listitem><para>
4436 <emphasis>Optionally Start a vncserver:</emphasis>
4437 If you are running in a server without an X11 session,
4438 you need to start a vncserver:
4439 <literallayout class='monospaced'>
4440 $ vncserver :1
4441 $ export DISPLAY=:1
4442 </literallayout>
4443 </para></listitem>
4444 <listitem><para>
4445 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4446 You need to have the
4447 <filename>upgrade-helper/upgrade-helper.conf</filename>
4448 configuration file in your build directory.
4449 You can find a sample configuration file in the
4450 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4451 </para>
4452
4453 <para>Read through the sample file and make
4454 configurations as needed.
4455 For example, if you enabled build history in your
4456 <filename>local.conf</filename> as described earlier,
4457 you must enable it in
4458 <filename>upgrade-helper.conf</filename>.</para>
4459
4460 <para>Also, if you are using the default
4461 <filename>maintainers.inc</filename> file supplied
4462 with Poky and located in
4463 <filename>meta-yocto</filename> and you do not set a
4464 "maintainers_whitelist" or "global_maintainer_override"
4465 in the <filename>upgrade-helper.conf</filename>
4466 configuration, and you specify "-e all" on the
4467 AUH command-line, the utility automatically sends out
4468 emails to all the default maintainers.
4469 Please avoid this.
4470 </para></listitem>
4471 </orderedlist>
4472 </para>
4473
4474 <para>
4475 This next set of examples describes how to use the AUH:
4476 <itemizedlist>
4477 <listitem><para>
4478 <emphasis>Upgrading a Specific Recipe:</emphasis>
4479 To upgrade a specific recipe, use the following
4480 form:
4481 <literallayout class='monospaced'>
4482 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4483 </literallayout>
4484 For example, this command upgrades the
4485 <filename>xmodmap</filename> recipe:
4486 <literallayout class='monospaced'>
4487 $ upgrade-helper.py xmodmap
4488 </literallayout>
4489 </para></listitem>
4490 <listitem><para>
4491 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4492 To upgrade a specific recipe to a particular version,
4493 use the following form:
4494 <literallayout class='monospaced'>
4495 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4496 </literallayout>
4497 For example, this command upgrades the
4498 <filename>xmodmap</filename> recipe to version
4499 1.2.3:
4500 <literallayout class='monospaced'>
4501 $ upgrade-helper.py xmodmap -t 1.2.3
4502 </literallayout>
4503 </para></listitem>
4504 <listitem><para>
4505 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4506 To upgrade all recipes to their most recent versions
4507 and suppress the email notifications, use the following
4508 command:
4509 <literallayout class='monospaced'>
4510 $ upgrade-helper.py all
4511 </literallayout>
4512 </para></listitem>
4513 <listitem><para>
4514 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4515 To upgrade all recipes to their most recent versions
4516 and send email messages to maintainers for each
4517 attempted recipe as well as a status email, use the
4518 following command:
4519 <literallayout class='monospaced'>
4520 $ upgrade-helper.py -e all
4521 </literallayout>
4522 </para></listitem>
4523 </itemizedlist>
4524 </para>
4525
4526 <para>
4527 Once you have run the AUH utility, you can find the results
4528 in the AUH build directory:
4529 <literallayout class='monospaced'>
4530 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4531 </literallayout>
4532 The AUH utility also creates recipe update commits from
4533 successful upgrade attempts in the layer tree.
4534 </para>
4535
4536 <para>
4537 You can easily set up to run the AUH utility on a regular
4538 basis by using a cron job.
4539 See the
4540 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4541 file distributed with the utility for an example.
4542 </para>
4543 </section>
4544
4545 <section id='gs-using-devtool-upgrade'>
4546 <title>Using <filename>devtool upgrade</filename></title>
4547
4548 <para>
4549 As mentioned earlier, an alternative method for upgrading
4550 recipes to newer versions is to use
4551 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4552 You can read about <filename>devtool upgrade</filename> in
4553 general in the
4554 "<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>"
4555 section in the Yocto Project Application Development and the
4556 Extensible Software Development Kit (eSDK) Manual.
4557 </para>
4558
4559 <para>
4560 To see all the command-line options available with
4561 <filename>devtool upgrade</filename>, use the following help
4562 command:
4563 <literallayout class='monospaced'>
4564 $ devtool upgrade -h
4565 </literallayout>
4566 </para>
4567
4568 <para>
4569 If you want to find out what version a recipe is currently at
4570 upstream without any attempt to upgrade your local version of
4571 the recipe, you can use the following command:
4572 <literallayout class='monospaced'>
4573 $ devtool latest-version <replaceable>recipe_name</replaceable>
4574 </literallayout>
4575 </para>
4576
4577 <para>
4578 As mentioned in the previous section describing AUH,
4579 <filename>devtool upgrade</filename> works in a
4580 less-automated manner than AUH.
4581 Specifically, <filename>devtool upgrade</filename> only
4582 works on a single recipe that you name on the command line,
4583 cannot perform build and integration testing using images,
4584 and does not automatically generate commits for changes in
4585 the source tree.
4586 Despite all these "limitations",
4587 <filename>devtool upgrade</filename> updates the recipe file
4588 to the new upstream version and attempts to rebase custom
4589 patches contained by the recipe as needed.
4590 <note>
4591 AUH uses much of <filename>devtool upgrade</filename>
4592 behind the scenes making AUH somewhat of a "wrapper"
4593 application for <filename>devtool upgrade</filename>.
4594 </note>
4595 </para>
4596
4597 <para>
4598 A typical scenario involves having used Git to clone an
4599 upstream repository that you use during build operations.
4600 Because you are (or have) built the recipe in the past, the
4601 layer is likely added to your configuration already.
4602 If for some reason, the layer is not added, you could add
4603 it easily using the
4604 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4605 script.
4606 For example, suppose you use the <filename>nano.bb</filename>
4607 recipe from the <filename>meta-oe</filename> layer in the
4608 <filename>meta-openembedded</filename> repository.
4609 For this example, assume that the layer has been cloned into
4610 following area:
4611 <literallayout class='monospaced'>
4612 /home/scottrif/meta-openembedded
4613 </literallayout>
4614 The following command from your
4615 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4616 adds the layer to your build configuration (i.e.
4617 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4618 <literallayout class='monospaced'>
4619 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4620 NOTE: Starting bitbake server...
4621 Parsing recipes: 100% |##########################################| Time: 0:00:55
4622 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4623 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4624 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4625 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4626 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4627 </literallayout>
4628 For this example, assume that the <filename>nano.bb</filename>
4629 recipe that is upstream has a 2.9.3 version number.
4630 However, the version in the local repository is 2.7.4.
4631 The following command from your build directory automatically
4632 upgrades the recipe for you:
4633 <note>
4634 Using the <filename>-V</filename> option is not necessary.
4635 Omitting the version number causes
4636 <filename>devtool upgrade</filename> to upgrade the recipe
4637 to the most recent version.
4638 </note>
4639 <literallayout class='monospaced'>
4640 $ devtool upgrade nano -V 2.9.3
4641 NOTE: Starting bitbake server...
4642 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4643 Parsing recipes: 100% |##########################################| Time: 0:00:46
4644 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4645 NOTE: Extracting current version source...
4646 NOTE: Resolving any missing task queue dependencies
4647 .
4648 .
4649 .
4650 NOTE: Executing SetScene Tasks
4651 NOTE: Executing RunQueue Tasks
4652 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4653 Adding changed files: 100% |#####################################| Time: 0:00:00
4654 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4655 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4656 </literallayout>
4657 Continuing with this example, you can use
4658 <filename>devtool build</filename> to build the newly upgraded
4659 recipe:
4660 <literallayout class='monospaced'>
4661 $ devtool build nano
4662 NOTE: Starting bitbake server...
4663 Loading cache: 100% |################################################################################################| Time: 0:00:01
4664 Loaded 2040 entries from dependency cache.
4665 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4666 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4667 NOTE: Resolving any missing task queue dependencies
4668 .
4669 .
4670 .
4671 NOTE: Executing SetScene Tasks
4672 NOTE: Executing RunQueue Tasks
4673 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4674 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4675 </literallayout>
4676 Within the <filename>devtool upgrade</filename> workflow,
4677 opportunity exists to deploy and test your rebuilt software.
4678 For this example, however, running
4679 <filename>devtool finish</filename> cleans up the workspace
4680 once the source in your workspace is clean.
4681 This usually means using Git to stage and submit commits
4682 for the changes generated by the upgrade process.
4683 </para>
4684
4685 <para>
4686 Once the tree is clean, you can clean things up in this
4687 example with the following command from the
4688 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4689 directory:
4690 <literallayout class='monospaced'>
4691 $ devtool finish nano meta-oe
4692 NOTE: Starting bitbake server...
4693 Loading cache: 100% |################################################################################################| Time: 0:00:00
4694 Loaded 2040 entries from dependency cache.
4695 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4696 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4697 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4698 NOTE: Updating recipe nano_2.9.3.bb
4699 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4700 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4701 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4702 </literallayout>
4703 Using the <filename>devtool finish</filename> command cleans
4704 up the workspace and creates a patch file based on your
4705 commits.
4706 The tool puts all patch files back into the source directory
4707 in a sub-directory named <filename>nano</filename> in this
4708 case.
4709 </para>
4710 </section>
4711
4712 <section id='dev-manually-upgrading-a-recipe'>
4713 <title>Manually Upgrading a Recipe</title>
4714
4715 <para>
4716 If for some reason you choose not to upgrade recipes using the
4717 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4718 or by using
4719 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4720 you can manually edit the recipe files to upgrade the versions.
4721 <note><title>Caution</title>
4722 Manually updating multiple recipes scales poorly and
4723 involves many steps.
4724 The recommendation to upgrade recipe versions is through
4725 AUH or <filename>devtool upgrade</filename>, both of which
4726 automate some steps and provide guidance for others needed
4727 for the manual process.
4728 </note>
4729 </para>
4730
4731 <para>
4732 To manually upgrade recipe versions, follow these general steps:
4733 <orderedlist>
4734 <listitem><para>
4735 <emphasis>Change the Version:</emphasis>
4736 Rename the recipe such that the version (i.e. the
4737 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4738 part of the recipe name) changes appropriately.
4739 If the version is not part of the recipe name, change
4740 the value as it is set for <filename>PV</filename>
4741 within the recipe itself.
4742 </para></listitem>
4743 <listitem><para>
4744 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4745 If the source code your recipe builds is fetched from
4746 Git or some other version control system, update
4747 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4748 to point to the commit hash that matches the new
4749 version.
4750 </para></listitem>
4751 <listitem><para>
4752 <emphasis>Build the Software:</emphasis>
4753 Try to build the recipe using BitBake.
4754 Typical build failures include the following:
4755 <itemizedlist>
4756 <listitem><para>
4757 License statements were updated for the new
4758 version.
4759 For this case, you need to review any changes
4760 to the license and update the values of
4761 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4762 and
4763 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4764 as needed.
4765 <note>
4766 License changes are often inconsequential.
4767 For example, the license text's copyright
4768 year might have changed.
4769 </note>
4770 </para></listitem>
4771 <listitem><para>
4772 Custom patches carried by the older version of
4773 the recipe might fail to apply to the new
4774 version.
4775 For these cases, you need to review the
4776 failures.
4777 Patches might not be necessary for the new
4778 version of the software if the upgraded version
4779 has fixed those issues.
4780 If a patch is necessary and failing, you need
4781 to rebase it into the new version.
4782 </para></listitem>
4783 </itemizedlist>
4784 </para></listitem>
4785 <listitem><para>
4786 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4787 Once you successfully build the new software for a
4788 given architecture, you could test the build for
4789 other architectures by changing the
4790 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4791 variable and rebuilding the software.
4792 This optional step is especially important if the
4793 recipe is to be released publicly.
4794 </para></listitem>
4795 <listitem><para>
4796 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4797 Checking both these reveals if new features exist that
4798 could break backwards-compatibility.
4799 If so, you need to take steps to mitigate or eliminate
4800 that situation.
4801 </para></listitem>
4802 <listitem><para>
4803 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4804 If you want, you can test the new software by booting
4805 it onto actual hardware.
4806 </para></listitem>
4807 <listitem><para>
4808 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4809 After all builds work and any testing is successful,
4810 you can create commits for any changes in the layer
4811 holding your upgraded recipe.
4812 </para></listitem>
4813 </orderedlist>
4814 </para>
4815 </section>
4816 </section>
4817
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004818 <section id='finding-the-temporary-source-code'>
4819 <title>Finding Temporary Source Code</title>
4820
4821 <para>
4822 You might find it helpful during development to modify the
4823 temporary source code used by recipes to build packages.
4824 For example, suppose you are developing a patch and you need to
4825 experiment a bit to figure out your solution.
4826 After you have initially built the package, you can iteratively
4827 tweak the source code, which is located in the
4828 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4829 and then you can force a re-compile and quickly test your altered
4830 code.
4831 Once you settle on a solution, you can then preserve your changes
4832 in the form of patches.
4833 </para>
4834
4835 <para>
4836 During a build, the unpacked temporary source code used by recipes
4837 to build packages is available in the Build Directory as
4838 defined by the
4839 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4840 variable.
4841 Below is the default value for the <filename>S</filename> variable
4842 as defined in the
4843 <filename>meta/conf/bitbake.conf</filename> configuration file
4844 in the
4845 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4846 <literallayout class='monospaced'>
4847 S = "${WORKDIR}/${BP}"
4848 </literallayout>
4849 You should be aware that many recipes override the
4850 <filename>S</filename> variable.
4851 For example, recipes that fetch their source from Git usually set
4852 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4853 <note>
4854 The
4855 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4856 represents the base recipe name, which consists of the name
4857 and version:
4858 <literallayout class='monospaced'>
4859 BP = "${BPN}-${PV}"
4860 </literallayout>
4861 </note>
4862 </para>
4863
4864 <para>
4865 The path to the work directory for the recipe
4866 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4867 is defined as follows:
4868 <literallayout class='monospaced'>
4869 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4870 </literallayout>
4871 The actual directory depends on several things:
4872 <itemizedlist>
4873 <listitem><para>
4874 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4875 The top-level build output directory.
4876 </para></listitem>
4877 <listitem><para>
4878 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4879 The target system identifier.
4880 </para></listitem>
4881 <listitem><para>
4882 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4883 The recipe name.
4884 </para></listitem>
4885 <listitem><para>
4886 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4887 The epoch - (if
4888 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4889 is not specified, which is usually the case for most
4890 recipes, then <filename>EXTENDPE</filename> is blank).
4891 </para></listitem>
4892 <listitem><para>
4893 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4894 The recipe version.
4895 </para></listitem>
4896 <listitem><para>
4897 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4898 The recipe revision.
4899 </para></listitem>
4900 </itemizedlist>
4901 </para>
4902
4903 <para>
4904 As an example, assume a Source Directory top-level folder
4905 named <filename>poky</filename>, a default Build Directory at
4906 <filename>poky/build</filename>, and a
4907 <filename>qemux86-poky-linux</filename> machine target
4908 system.
4909 Furthermore, suppose your recipe is named
4910 <filename>foo_1.3.0.bb</filename>.
4911 In this case, the work directory the build system uses to
4912 build the package would be as follows:
4913 <literallayout class='monospaced'>
4914 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4915 </literallayout>
4916 </para>
4917 </section>
4918
4919 <section id="using-a-quilt-workflow">
4920 <title>Using Quilt in Your Workflow</title>
4921
4922 <para>
4923 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4924 is a powerful tool that allows you to capture source code changes
4925 without having a clean source tree.
4926 This section outlines the typical workflow you can use to modify
4927 source code, test changes, and then preserve the changes in the
4928 form of a patch all using Quilt.
4929 <note><title>Tip</title>
4930 With regard to preserving changes to source files, if you
4931 clean a recipe or have <filename>rm_work</filename> enabled,
4932 the
4933 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4934 as described in the Yocto Project Application Development
4935 and the Extensible Software Development Kit (eSDK) manual
4936 is a safer development flow than the flow that uses Quilt.
4937 </note>
4938 </para>
4939
4940 <para>
4941 Follow these general steps:
4942 <orderedlist>
4943 <listitem><para>
4944 <emphasis>Find the Source Code:</emphasis>
4945 Temporary source code used by the OpenEmbedded build system
4946 is kept in the
4947 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4948 See the
4949 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4950 section to learn how to locate the directory that has the
4951 temporary source code for a particular package.
4952 </para></listitem>
4953 <listitem><para>
4954 <emphasis>Change Your Working Directory:</emphasis>
4955 You need to be in the directory that has the temporary
4956 source code.
4957 That directory is defined by the
4958 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4959 variable.</para></listitem>
4960 <listitem><para>
4961 <emphasis>Create a New Patch:</emphasis>
4962 Before modifying source code, you need to create a new
4963 patch.
4964 To create a new patch file, use
4965 <filename>quilt new</filename> as below:
4966 <literallayout class='monospaced'>
4967 $ quilt new my_changes.patch
4968 </literallayout>
4969 </para></listitem>
4970 <listitem><para>
4971 <emphasis>Notify Quilt and Add Files:</emphasis>
4972 After creating the patch, you need to notify Quilt about
4973 the files you plan to edit.
4974 You notify Quilt by adding the files to the patch you
4975 just created:
4976 <literallayout class='monospaced'>
4977 $ quilt add file1.c file2.c file3.c
4978 </literallayout>
4979 </para></listitem>
4980 <listitem><para>
4981 <emphasis>Edit the Files:</emphasis>
4982 Make your changes in the source code to the files you added
4983 to the patch.
4984 </para></listitem>
4985 <listitem><para>
4986 <emphasis>Test Your Changes:</emphasis>
4987 Once you have modified the source code, the easiest way to
4988 test your changes is by calling the
4989 <filename>do_compile</filename> task as shown in the
4990 following example:
4991 <literallayout class='monospaced'>
4992 $ bitbake -c compile -f <replaceable>package</replaceable>
4993 </literallayout>
4994 The <filename>-f</filename> or <filename>--force</filename>
4995 option forces the specified task to execute.
4996 If you find problems with your code, you can just keep
4997 editing and re-testing iteratively until things work
4998 as expected.
4999 <note>
5000 All the modifications you make to the temporary
5001 source code disappear once you run the
5002 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
5003 or
5004 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
5005 tasks using BitBake (i.e.
5006 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
5007 and
5008 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
5009 Modifications will also disappear if you use the
5010 <filename>rm_work</filename> feature as described
5011 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04005012 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
5013 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005014 </note>
5015 </para></listitem>
5016 <listitem><para>
5017 <emphasis>Generate the Patch:</emphasis>
5018 Once your changes work as expected, you need to use Quilt
5019 to generate the final patch that contains all your
5020 modifications.
5021 <literallayout class='monospaced'>
5022 $ quilt refresh
5023 </literallayout>
5024 At this point, the <filename>my_changes.patch</filename>
5025 file has all your edits made to the
5026 <filename>file1.c</filename>, <filename>file2.c</filename>,
5027 and <filename>file3.c</filename> files.</para>
5028
5029 <para>You can find the resulting patch file in the
5030 <filename>patches/</filename> subdirectory of the source
5031 (<filename>S</filename>) directory.
5032 </para></listitem>
5033 <listitem><para>
5034 <emphasis>Copy the Patch File:</emphasis>
5035 For simplicity, copy the patch file into a directory
5036 named <filename>files</filename>, which you can create
5037 in the same directory that holds the recipe
5038 (<filename>.bb</filename>) file or the append
5039 (<filename>.bbappend</filename>) file.
5040 Placing the patch here guarantees that the OpenEmbedded
5041 build system will find the patch.
5042 Next, add the patch into the
5043 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
5044 of the recipe.
5045 Here is an example:
5046 <literallayout class='monospaced'>
5047 SRC_URI += "file://my_changes.patch"
5048 </literallayout>
5049 </para></listitem>
5050 </orderedlist>
5051 </para>
5052 </section>
5053
5054 <section id="platdev-appdev-devshell">
5055 <title>Using a Development Shell</title>
5056
5057 <para>
5058 When debugging certain commands or even when just editing packages,
5059 <filename>devshell</filename> can be a useful tool.
5060 When you invoke <filename>devshell</filename>, all tasks up to and
5061 including
5062 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5063 are run for the specified target.
5064 Then, a new terminal is opened and you are placed in
5065 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
5066 the source directory.
5067 In the new terminal, all the OpenEmbedded build-related environment variables are
5068 still defined so you can use commands such as <filename>configure</filename> and
5069 <filename>make</filename>.
5070 The commands execute just as if the OpenEmbedded build system were executing them.
5071 Consequently, working this way can be helpful when debugging a build or preparing
5072 software to be used with the OpenEmbedded build system.
5073 </para>
5074
5075 <para>
5076 Following is an example that uses <filename>devshell</filename> on a target named
5077 <filename>matchbox-desktop</filename>:
5078 <literallayout class='monospaced'>
5079 $ bitbake matchbox-desktop -c devshell
5080 </literallayout>
5081 </para>
5082
5083 <para>
5084 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5085 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5086 variable controls what type of shell is opened.
5087 </para>
5088
5089 <para>
5090 For spawned terminals, the following occurs:
5091 <itemizedlist>
5092 <listitem><para>The <filename>PATH</filename> variable includes the
5093 cross-toolchain.</para></listitem>
5094 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5095 <filename>.pc</filename> files.</para></listitem>
5096 <listitem><para>The <filename>configure</filename> command finds the
5097 Yocto Project site files as well as any other necessary files.</para></listitem>
5098 </itemizedlist>
5099 </para>
5100
5101 <para>
5102 Within this environment, you can run configure or compile
5103 commands as if they were being run by
5104 the OpenEmbedded build system itself.
5105 As noted earlier, the working directory also automatically changes to the
5106 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5107 </para>
5108
5109 <para>
5110 To manually run a specific task using <filename>devshell</filename>,
5111 run the corresponding <filename>run.*</filename> script in
5112 the
5113 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5114 directory (e.g.,
5115 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5116 If a task's script does not exist, which would be the case if the task was
5117 skipped by way of the sstate cache, you can create the task by first running
5118 it outside of the <filename>devshell</filename>:
5119 <literallayout class='monospaced'>
5120 $ bitbake -c <replaceable>task</replaceable>
5121 </literallayout>
5122 <note><title>Notes</title>
5123 <itemizedlist>
5124 <listitem><para>Execution of a task's <filename>run.*</filename>
5125 script and BitBake's execution of a task are identical.
5126 In other words, running the script re-runs the task
5127 just as it would be run using the
5128 <filename>bitbake -c</filename> command.
5129 </para></listitem>
5130 <listitem><para>Any <filename>run.*</filename> file that does not
5131 have a <filename>.pid</filename> extension is a
5132 symbolic link (symlink) to the most recent version of that
5133 file.
5134 </para></listitem>
5135 </itemizedlist>
5136 </note>
5137 </para>
5138
5139 <para>
5140 Remember, that the <filename>devshell</filename> is a mechanism that allows
5141 you to get into the BitBake task execution environment.
5142 And as such, all commands must be called just as BitBake would call them.
5143 That means you need to provide the appropriate options for
5144 cross-compilation and so forth as applicable.
5145 </para>
5146
5147 <para>
5148 When you are finished using <filename>devshell</filename>, exit the shell
5149 or close the terminal window.
5150 </para>
5151
5152 <note><title>Notes</title>
5153 <itemizedlist>
5154 <listitem><para>
5155 It is worth remembering that when using <filename>devshell</filename>
5156 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5157 instead of just using <filename>gcc</filename>.
5158 The same applies to other applications such as <filename>binutils</filename>,
5159 <filename>libtool</filename> and so forth.
5160 BitBake sets up environment variables such as <filename>CC</filename>
5161 to assist applications, such as <filename>make</filename> to find the correct tools.
5162 </para></listitem>
5163 <listitem><para>
5164 It is also worth noting that <filename>devshell</filename> still works over
5165 X11 forwarding and similar situations.
5166 </para></listitem>
5167 </itemizedlist>
5168 </note>
5169 </section>
5170
5171 <section id="platdev-appdev-devpyshell">
5172 <title>Using a Development Python Shell</title>
5173
5174 <para>
5175 Similar to working within a development shell as described in
5176 the previous section, you can also spawn and work within an
5177 interactive Python development shell.
5178 When debugging certain commands or even when just editing packages,
5179 <filename>devpyshell</filename> can be a useful tool.
5180 When you invoke <filename>devpyshell</filename>, all tasks up to and
5181 including
5182 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5183 are run for the specified target.
5184 Then a new terminal is opened.
5185 Additionally, key Python objects and code are available in the same
5186 way they are to BitBake tasks, in particular, the data store 'd'.
5187 So, commands such as the following are useful when exploring the data
5188 store and running functions:
5189 <literallayout class='monospaced'>
Brad Bishop19323692019-04-05 15:28:33 -04005190 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005191 '/media/build1/poky/build/tmp/sysroots'
Brad Bishop19323692019-04-05 15:28:33 -04005192 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005193 '${TMPDIR}/sysroots'
5194 pydevshell> d.setVar("FOO", "bar")
Brad Bishop19323692019-04-05 15:28:33 -04005195 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005196 'bar'
5197 pydevshell> d.delVar("FOO")
Brad Bishop19323692019-04-05 15:28:33 -04005198 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005199 pydevshell> bb.build.exec_func("do_unpack", d)
5200 pydevshell>
5201 </literallayout>
5202 The commands execute just as if the OpenEmbedded build system were executing them.
5203 Consequently, working this way can be helpful when debugging a build or preparing
5204 software to be used with the OpenEmbedded build system.
5205 </para>
5206
5207 <para>
5208 Following is an example that uses <filename>devpyshell</filename> on a target named
5209 <filename>matchbox-desktop</filename>:
5210 <literallayout class='monospaced'>
5211 $ bitbake matchbox-desktop -c devpyshell
5212 </literallayout>
5213 </para>
5214
5215 <para>
5216 This command spawns a terminal and places you in an interactive
5217 Python interpreter within the OpenEmbedded build environment.
5218 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5219 variable controls what type of shell is opened.
5220 </para>
5221
5222 <para>
5223 When you are finished using <filename>devpyshell</filename>, you
5224 can exit the shell either by using Ctrl+d or closing the terminal
5225 window.
5226 </para>
5227 </section>
5228
Brad Bishop316dfdd2018-06-25 12:45:53 -04005229 <section id='dev-building'>
5230 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005231
5232 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005233 This section describes various build procedures.
5234 For example, the steps needed for a simple build, a target that
5235 uses multiple configurations, building an image for more than
5236 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005237 </para>
5238
Brad Bishop316dfdd2018-06-25 12:45:53 -04005239 <section id='dev-building-a-simple-image'>
5240 <title>Building a Simple Image</title>
5241
5242 <para>
5243 In the development environment, you need to build an image
5244 whenever you change hardware support, add or change system
5245 libraries, or add or change services that have dependencies.
5246 Several methods exist that allow you to build an image within
5247 the Yocto Project.
5248 This section presents the basic steps you need to build a
5249 simple image using BitBake from a build host running Linux.
5250 <note><title>Notes</title>
5251 <itemizedlist>
5252 <listitem><para>
5253 For information on how to build an image using
5254 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5255 see the
5256 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5257 </para></listitem>
5258 <listitem><para>
5259 For information on how to use
5260 <filename>devtool</filename> to build images, see
5261 the
5262 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5263 section in the Yocto Project Application
5264 Development and the Extensible Software Development
5265 Kit (eSDK) manual.
5266 </para></listitem>
5267 <listitem><para>
5268 For a quick example on how to build an image using
5269 the OpenEmbedded build system, see the
5270 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5271 document.
5272 </para></listitem>
5273 </itemizedlist>
5274 </note>
5275 </para>
5276
5277 <para>
5278 The build process creates an entire Linux distribution from
5279 source and places it in your
5280 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5281 under <filename>tmp/deploy/images</filename>.
5282 For detailed information on the build process using BitBake,
5283 see the
5284 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5285 section in the Yocto Project Overview and Concepts Manual.
5286 </para>
5287
5288 <para>
5289 The following figure and list overviews the build process:
5290 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5291 <orderedlist>
5292 <listitem><para>
5293 <emphasis>Set up Your Host Development System to Support
5294 Development Using the Yocto Project</emphasis>:
5295 See the
5296 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5297 section for options on how to get a build host ready to
5298 use the Yocto Project.
5299 </para></listitem>
5300 <listitem><para>
5301 <emphasis>Initialize the Build Environment:</emphasis>
5302 Initialize the build environment by sourcing the build
5303 environment script (i.e.
5304 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5305 <literallayout class='monospaced'>
5306 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5307 </literallayout></para>
5308
5309 <para>When you use the initialization script, the
5310 OpenEmbedded build system uses
5311 <filename>build</filename> as the default Build
5312 Directory in your current work directory.
5313 You can use a <replaceable>build_dir</replaceable>
5314 argument with the script to specify a different build
5315 directory.
5316 <note><title>Tip</title>
5317 A common practice is to use a different Build
5318 Directory for different targets.
5319 For example, <filename>~/build/x86</filename> for a
5320 <filename>qemux86</filename> target, and
5321 <filename>~/build/arm</filename> for a
5322 <filename>qemuarm</filename> target.
5323 </note>
5324 </para></listitem>
5325 <listitem><para>
5326 <emphasis>Make Sure Your <filename>local.conf</filename>
5327 File is Correct:</emphasis>
5328 Ensure the <filename>conf/local.conf</filename>
5329 configuration file, which is found in the Build
5330 Directory, is set up how you want it.
5331 This file defines many aspects of the build environment
5332 including the target machine architecture through the
5333 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5334 the packaging format used during the build
5335 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5336 and a centralized tarball download directory through the
5337 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5338 </para></listitem>
5339 <listitem><para>
5340 <emphasis>Build the Image:</emphasis>
5341 Build the image using the <filename>bitbake</filename>
5342 command:
5343 <literallayout class='monospaced'>
5344 $ bitbake <replaceable>target</replaceable>
5345 </literallayout>
5346 <note>
5347 For information on BitBake, see the
5348 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5349 </note>
5350 The <replaceable>target</replaceable> is the name of the
5351 recipe you want to build.
5352 Common targets are the images in
5353 <filename>meta/recipes-core/images</filename>,
5354 <filename>meta/recipes-sato/images</filename>, and so
5355 forth all found in the
5356 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5357 Or, the target can be the name of a recipe for a
5358 specific piece of software such as BusyBox.
5359 For more details about the images the OpenEmbedded build
5360 system supports, see the
5361 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5362 chapter in the Yocto Project Reference Manual.</para>
5363
5364 <para>As an example, the following command builds the
5365 <filename>core-image-minimal</filename> image:
5366 <literallayout class='monospaced'>
5367 $ bitbake core-image-minimal
5368 </literallayout>
5369 Once an image has been built, it often needs to be
5370 installed.
5371 The images and kernels built by the OpenEmbedded
5372 build system are placed in the Build Directory in
5373 <filename class="directory">tmp/deploy/images</filename>.
5374 For information on how to run pre-built images such as
5375 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5376 see the
5377 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5378 manual.
5379 For information about how to install these images,
5380 see the documentation for your particular board or
5381 machine.
5382 </para></listitem>
5383 </orderedlist>
5384 </para>
5385 </section>
5386
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005387 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5388 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005389
5390 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005391 You can use a single <filename>bitbake</filename> command
5392 to build multiple images or packages for different targets
5393 where each image or package requires a different configuration
5394 (multiple configuration builds).
5395 The builds, in this scenario, are sometimes referred to as
5396 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005397 </para>
5398
5399 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005400 This section describes how to set up for multiple
5401 configuration builds and how to account for cross-build
5402 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005403 </para>
5404
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005405 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5406 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005407
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005408 <para>
5409 To accomplish a multiple configuration build, you must
5410 define each target's configuration separately using
5411 a parallel configuration file in the
5412 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5413 and you must follow a required file hierarchy.
5414 Additionally, you must enable the multiple configuration
5415 builds in your <filename>local.conf</filename> file.
5416 </para>
5417
5418 <para>
5419 Follow these steps to set up and execute multiple
5420 configuration builds:
5421 <itemizedlist>
5422 <listitem><para>
5423 <emphasis>Create Separate Configuration Files</emphasis>:
5424 You need to create a single configuration file for
5425 each build target (each multiconfig).
5426 Minimally, each configuration file must define the
5427 machine and the temporary directory BitBake uses
5428 for the build.
5429 Suggested practice dictates that you do not
5430 overlap the temporary directories
5431 used during the builds.
5432 However, it is possible that you can share the
5433 temporary directory
5434 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5435 For example, consider a scenario with two
5436 different multiconfigs for the same
5437 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5438 two distributions such as "poky" and "poky-lsb".
5439 In this case, you might want to use the same
5440 <filename>TMPDIR</filename>.</para>
5441
5442 <para>Here is an example showing the minimal
5443 statements needed in a configuration file for
5444 a "qemux86" target whose temporary build directory
5445 is <filename>tmpmultix86</filename>:
5446 <literallayout class='monospaced'>
5447 MACHINE="qemux86"
5448 TMPDIR="${TOPDIR}/tmpmultix86"
5449 </literallayout></para>
5450
5451 <para>The location for these multiconfig
5452 configuration files is specific.
5453 They must reside in the current build directory in
5454 a sub-directory of <filename>conf</filename> named
5455 <filename>multiconfig</filename>.
5456 Following is an example that defines two
5457 configuration files for the "x86" and "arm"
5458 multiconfigs:
5459 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5460 </para>
5461
5462 <para>The reason for this required file hierarchy
5463 is because the <filename>BBPATH</filename> variable
5464 is not constructed until the layers are parsed.
5465 Consequently, using the configuration file as a
5466 pre-configuration file is not possible unless it is
5467 located in the current working directory.
5468 </para></listitem>
5469 <listitem><para>
5470 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5471 Use the
5472 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5473 variable in your
5474 <filename>conf/local.conf</filename> configuration
5475 file to specify each multiconfig.
5476 Continuing with the example from the previous
5477 figure, the <filename>BBMULTICONFIG</filename>
5478 variable needs to enable two multiconfigs: "x86"
5479 and "arm" by specifying each configuration file:
5480 <literallayout class='monospaced'>
5481 BBMULTICONFIG = "x86 arm"
5482 </literallayout>
Brad Bishop64c979e2019-11-04 13:55:29 -05005483 <note>
5484 A "default" configuration already exists by
5485 definition.
5486 This configuration is named: "" (i.e. empty
5487 string) and is defined by the variables coming
5488 from your <filename>local.conf</filename> file.
5489 Consequently, the previous example actually
5490 adds two additional configurations to your
5491 build: "arm" and "x86" along with "".
5492 </note>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005493 </para></listitem>
5494 <listitem><para>
5495 <emphasis>Launch BitBake</emphasis>:
5496 Use the following BitBake command form to launch the
5497 multiple configuration build:
5498 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005499 $ bitbake [mc:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[mc:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005500 </literallayout>
5501 For the example in this section, the following
5502 command applies:
5503 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005504 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005505 </literallayout>
5506 The previous BitBake command builds a
5507 <filename>core-image-minimal</filename> image that
5508 is configured through the
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005509 <filename>x86.conf</filename> configuration file,
5510 a <filename>core-image-sato</filename>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005511 image that is configured through the
Brad Bishop64c979e2019-11-04 13:55:29 -05005512 <filename>arm.conf</filename> configuration file
5513 and a <filename>core-image-base</filename> that is
5514 configured through your
5515 <filename>local.conf</filename> configuration file.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005516 </para></listitem>
5517 </itemizedlist>
5518 <note>
5519 Support for multiple configuration builds in the
5520 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5521 not include Shared State (sstate) optimizations.
5522 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005523 in, for example, two different
5524 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005525 either loads from an existing sstate cache for that
5526 build at the start or builds the object fresh.
5527 </note>
5528 </para>
5529 </section>
5530
5531 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5532 <title>Enabling Multiple Configuration Build Dependencies</title>
5533
5534 <para>
5535 Sometimes dependencies can exist between targets
5536 (multiconfigs) in a multiple configuration build.
5537 For example, suppose that in order to build a
5538 <filename>core-image-sato</filename> image for an "x86"
5539 multiconfig, the root filesystem of an "arm"
5540 multiconfig must exist.
5541 This dependency is essentially that the
5542 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5543 task in the <filename>core-image-sato</filename> recipe
5544 depends on the completion of the
5545 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5546 task of the <filename>core-image-minimal</filename>
5547 recipe.
5548 </para>
5549
5550 <para>
5551 To enable dependencies in a multiple configuration
5552 build, you must declare the dependencies in the recipe
5553 using the following statement form:
5554 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005555 <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 -08005556 </literallayout>
5557 To better show how to use this statement, consider the
5558 example scenario from the first paragraph of this section.
5559 The following statement needs to be added to the recipe
5560 that builds the <filename>core-image-sato</filename>
5561 image:
5562 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005563 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005564 </literallayout>
5565 In this example, the
5566 <replaceable>from_multiconfig</replaceable> is "x86".
5567 The <replaceable>to_multiconfig</replaceable> is "arm".
5568 The task on which the <filename>do_image</filename> task
5569 in the recipe depends is the <filename>do_rootfs</filename>
5570 task from the <filename>core-image-minimal</filename>
5571 recipe associated with the "arm" multiconfig.
5572 </para>
5573
5574 <para>
5575 Once you set up this dependency, you can build the
5576 "x86" multiconfig using a BitBake command as follows:
5577 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005578 $ bitbake mc:x86:core-image-sato
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005579 </literallayout>
5580 This command executes all the tasks needed to create
5581 the <filename>core-image-sato</filename> image for the
5582 "x86" multiconfig.
5583 Because of the dependency, BitBake also executes through
5584 the <filename>do_rootfs</filename> task for the "arm"
5585 multiconfig build.
5586 </para>
5587
5588 <para>
5589 Having a recipe depend on the root filesystem of another
5590 build might not seem that useful.
5591 Consider this change to the statement in the
5592 <filename>core-image-sato</filename> recipe:
5593 <literallayout class='monospaced'>
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005594 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005595 </literallayout>
5596 In this case, BitBake must create the
5597 <filename>core-image-minimal</filename> image for the
5598 "arm" build since the "x86" build depends on it.
5599 </para>
5600
5601 <para>
5602 Because "x86" and "arm" are enabled for multiple
5603 configuration builds and have separate configuration
5604 files, BitBake places the artifacts for each build in the
5605 respective temporary build directories (i.e.
5606 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5607 </para>
5608 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005609 </section>
5610
5611 <section id='building-an-initramfs-image'>
5612 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5613
5614 <para>
5615 An initial RAM filesystem (initramfs) image provides a temporary
5616 root filesystem used for early system initialization (e.g.
5617 loading of modules needed to locate and mount the "real" root
5618 filesystem).
5619 <note>
5620 The initramfs image is the successor of initial RAM disk
5621 (initrd).
5622 It is a "copy in and out" (cpio) archive of the initial
5623 filesystem that gets loaded into memory during the Linux
5624 startup process.
5625 Because Linux uses the contents of the archive during
5626 initialization, the initramfs image needs to contain all of the
5627 device drivers and tools needed to mount the final root
5628 filesystem.
5629 </note>
5630 </para>
5631
5632 <para>
5633 Follow these steps to create an initramfs image:
5634 <orderedlist>
5635 <listitem><para>
5636 <emphasis>Create the initramfs Image Recipe:</emphasis>
5637 You can reference the
5638 <filename>core-image-minimal-initramfs.bb</filename>
5639 recipe found in the <filename>meta/recipes-core</filename>
5640 directory of the
5641 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5642 as an example from which to work.
5643 </para></listitem>
5644 <listitem><para>
5645 <emphasis>Decide if You Need to Bundle the initramfs Image
5646 Into the Kernel Image:</emphasis>
5647 If you want the initramfs image that is built to be
5648 bundled in with the kernel image, set the
5649 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5650 variable to "1" in your <filename>local.conf</filename>
5651 configuration file and set the
5652 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5653 variable in the recipe that builds the kernel image.
5654 <note><title>Tip</title>
5655 It is recommended that you do bundle the initramfs
5656 image with the kernel image to avoid circular
5657 dependencies between the kernel recipe and the
5658 initramfs recipe should the initramfs image
5659 include kernel modules.
5660 </note>
5661 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5662 flag causes the initramfs image to be unpacked
5663 into the <filename>${B}/usr/</filename> directory.
5664 The unpacked initramfs image is then passed to the kernel's
5665 <filename>Makefile</filename> using the
5666 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5667 variable, allowing the initramfs image to be built into
5668 the kernel normally.
5669 <note>
5670 If you choose to not bundle the initramfs image with
5671 the kernel image, you are essentially using an
5672 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5673 Creating an initrd is handled primarily through the
5674 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5675 <filename>INITRD_LIVE</filename>, and
5676 <filename>INITRD_IMAGE_LIVE</filename> variables.
5677 For more information, see the
5678 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5679 file.
5680 </note>
5681 </para></listitem>
5682 <listitem><para>
5683 <emphasis>Optionally Add Items to the initramfs Image
5684 Through the initramfs Image Recipe:</emphasis>
5685 If you add items to the initramfs image by way of its
5686 recipe, you should use
5687 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5688 rather than
5689 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5690 <filename>PACKAGE_INSTALL</filename> gives more direct
5691 control of what is added to the image as compared to
5692 the defaults you might not necessarily want that are
5693 set by the
5694 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5695 or
5696 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5697 classes.
5698 </para></listitem>
5699 <listitem><para>
5700 <emphasis>Build the Kernel Image and the initramfs
5701 Image:</emphasis>
5702 Build your kernel image using BitBake.
5703 Because the initramfs image recipe is a dependency of the
5704 kernel image, the initramfs image is built as well and
5705 bundled with the kernel image if you used the
5706 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5707 variable described earlier.
5708 </para></listitem>
5709 </orderedlist>
5710 </para>
5711 </section>
5712
5713 <section id='building-a-tiny-system'>
5714 <title>Building a Tiny System</title>
5715
5716 <para>
5717 Very small distributions have some significant advantages such
5718 as requiring less on-die or in-package memory (cheaper), better
5719 performance through efficient cache usage, lower power requirements
5720 due to less memory, faster boot times, and reduced development
5721 overhead.
5722 Some real-world examples where a very small distribution gives
5723 you distinct advantages are digital cameras, medical devices,
5724 and small headless systems.
5725 </para>
5726
5727 <para>
5728 This section presents information that shows you how you can
5729 trim your distribution to even smaller sizes than the
5730 <filename>poky-tiny</filename> distribution, which is around
5731 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5732 </para>
5733
5734 <section id='tiny-system-overview'>
5735 <title>Overview</title>
5736
5737 <para>
5738 The following list presents the overall steps you need to
5739 consider and perform to create distributions with smaller
5740 root filesystems, achieve faster boot times, maintain your critical
5741 functionality, and avoid initial RAM disks:
5742 <itemizedlist>
5743 <listitem><para>
5744 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5745 </para></listitem>
5746 <listitem><para>
5747 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5748 </para></listitem>
5749 <listitem><para>
5750 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5751 </para></listitem>
5752 <listitem><para>
5753 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5754 </para></listitem>
5755 <listitem><para>
5756 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5757 </para></listitem>
5758 <listitem><para>
5759 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5760 </para></listitem>
5761 <listitem><para>
5762 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5763 </para></listitem>
5764 </itemizedlist>
5765 </para>
5766 </section>
5767
5768 <section id='goals-and-guiding-principles'>
5769 <title>Goals and Guiding Principles</title>
5770
5771 <para>
5772 Before you can reach your destination, you need to know
5773 where you are going.
5774 Here is an example list that you can use as a guide when
5775 creating very small distributions:
5776 <itemizedlist>
5777 <listitem><para>Determine how much space you need
5778 (e.g. a kernel that is 1 Mbyte or less and
5779 a root filesystem that is 3 Mbytes or less).
5780 </para></listitem>
5781 <listitem><para>Find the areas that are currently
5782 taking 90% of the space and concentrate on reducing
5783 those areas.
5784 </para></listitem>
5785 <listitem><para>Do not create any difficult "hacks"
5786 to achieve your goals.</para></listitem>
5787 <listitem><para>Leverage the device-specific
5788 options.</para></listitem>
5789 <listitem><para>Work in a separate layer so that you
5790 keep changes isolated.
5791 For information on how to create layers, see
5792 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5793 </para></listitem>
5794 </itemizedlist>
5795 </para>
5796 </section>
5797
5798 <section id='understand-what-gives-your-image-size'>
5799 <title>Understand What Contributes to Your Image Size</title>
5800
5801 <para>
5802 It is easiest to have something to start with when creating
5803 your own distribution.
5804 You can use the Yocto Project out-of-the-box to create the
5805 <filename>poky-tiny</filename> distribution.
5806 Ultimately, you will want to make changes in your own
5807 distribution that are likely modeled after
5808 <filename>poky-tiny</filename>.
5809 <note>
5810 To use <filename>poky-tiny</filename> in your build,
5811 set the
5812 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5813 variable in your
5814 <filename>local.conf</filename> file to "poky-tiny"
5815 as described in the
5816 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5817 section.
5818 </note>
5819 </para>
5820
5821 <para>
5822 Understanding some memory concepts will help you reduce the
5823 system size.
5824 Memory consists of static, dynamic, and temporary memory.
5825 Static memory is the TEXT (code), DATA (initialized data
5826 in the code), and BSS (uninitialized data) sections.
5827 Dynamic memory represents memory that is allocated at runtime:
5828 stacks, hash tables, and so forth.
5829 Temporary memory is recovered after the boot process.
5830 This memory consists of memory used for decompressing
5831 the kernel and for the <filename>__init__</filename>
5832 functions.
5833 </para>
5834
5835 <para>
5836 To help you see where you currently are with kernel and root
5837 filesystem sizes, you can use two tools found in the
5838 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5839 the <filename>scripts/tiny/</filename> directory:
5840 <itemizedlist>
5841 <listitem><para><filename>ksize.py</filename>: Reports
5842 component sizes for the kernel build objects.
5843 </para></listitem>
5844 <listitem><para><filename>dirsize.py</filename>: Reports
5845 component sizes for the root filesystem.</para></listitem>
5846 </itemizedlist>
5847 This next tool and command help you organize configuration
5848 fragments and view file dependencies in a human-readable form:
5849 <itemizedlist>
5850 <listitem><para><filename>merge_config.sh</filename>:
5851 Helps you manage configuration files and fragments
5852 within the kernel.
5853 With this tool, you can merge individual configuration
5854 fragments together.
5855 The tool allows you to make overrides and warns you
5856 of any missing configuration options.
5857 The tool is ideal for allowing you to iterate on
5858 configurations, create minimal configurations, and
5859 create configuration files for different machines
5860 without having to duplicate your process.</para>
5861 <para>The <filename>merge_config.sh</filename> script is
5862 part of the Linux Yocto kernel Git repositories
5863 (i.e. <filename>linux-yocto-3.14</filename>,
5864 <filename>linux-yocto-3.10</filename>,
5865 <filename>linux-yocto-3.8</filename>, and so forth)
5866 in the
5867 <filename>scripts/kconfig</filename> directory.</para>
5868 <para>For more information on configuration fragments,
5869 see the
5870 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5871 section in the Yocto Project Linux Kernel Development
5872 Manual.
5873 </para></listitem>
5874 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5875 Using the BitBake command with these options brings up
5876 a Dependency Explorer from which you can view file
5877 dependencies.
5878 Understanding these dependencies allows you to make
5879 informed decisions when cutting out various pieces of the
5880 kernel and root filesystem.</para></listitem>
5881 </itemizedlist>
5882 </para>
5883 </section>
5884
5885 <section id='trim-the-root-filesystem'>
5886 <title>Trim the Root Filesystem</title>
5887
5888 <para>
5889 The root filesystem is made up of packages for booting,
5890 libraries, and applications.
5891 To change things, you can configure how the packaging happens,
5892 which changes the way you build them.
5893 You can also modify the filesystem itself or select a different
5894 filesystem.
5895 </para>
5896
5897 <para>
5898 First, find out what is hogging your root filesystem by running the
5899 <filename>dirsize.py</filename> script from your root directory:
5900 <literallayout class='monospaced'>
5901 $ cd <replaceable>root-directory-of-image</replaceable>
5902 $ dirsize.py 100000 > dirsize-100k.log
5903 $ cat dirsize-100k.log
5904 </literallayout>
5905 You can apply a filter to the script to ignore files under
5906 a certain size.
5907 The previous example filters out any files below 100 Kbytes.
5908 The sizes reported by the tool are uncompressed, and thus
5909 will be smaller by a relatively constant factor in a
5910 compressed root filesystem.
5911 When you examine your log file, you can focus on areas of the
5912 root filesystem that take up large amounts of memory.
5913 </para>
5914
5915 <para>
5916 You need to be sure that what you eliminate does not cripple
5917 the functionality you need.
5918 One way to see how packages relate to each other is by using
5919 the Dependency Explorer UI with the BitBake command:
5920 <literallayout class='monospaced'>
5921 $ cd <replaceable>image-directory</replaceable>
5922 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5923 </literallayout>
5924 Use the interface to select potential packages you wish to
5925 eliminate and see their dependency relationships.
5926 </para>
5927
5928 <para>
5929 When deciding how to reduce the size, get rid of packages that
5930 result in minimal impact on the feature set.
5931 For example, you might not need a VGA display.
5932 Or, you might be able to get by with <filename>devtmpfs</filename>
5933 and <filename>mdev</filename> instead of
5934 <filename>udev</filename>.
5935 </para>
5936
5937 <para>
5938 Use your <filename>local.conf</filename> file to make changes.
5939 For example, to eliminate <filename>udev</filename> and
5940 <filename>glib</filename>, set the following in the
5941 local configuration file:
5942 <literallayout class='monospaced'>
5943 VIRTUAL-RUNTIME_dev_manager = ""
5944 </literallayout>
5945 </para>
5946
5947 <para>
5948 Finally, you should consider exactly the type of root
5949 filesystem you need to meet your needs while also reducing
5950 its size.
5951 For example, consider <filename>cramfs</filename>,
5952 <filename>squashfs</filename>, <filename>ubifs</filename>,
5953 <filename>ext2</filename>, or an <filename>initramfs</filename>
5954 using <filename>initramfs</filename>.
5955 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5956 journal.
5957 If you are okay with running read-only, you do not need this
5958 journal.
5959 </para>
5960
5961 <note>
5962 After each round of elimination, you need to rebuild your
5963 system and then use the tools to see the effects of your
5964 reductions.
5965 </note>
5966 </section>
5967
5968 <section id='trim-the-kernel'>
5969 <title>Trim the Kernel</title>
5970
5971 <para>
5972 The kernel is built by including policies for hardware-independent
5973 aspects.
5974 What subsystems do you enable?
5975 For what architecture are you building?
5976 Which drivers do you build by default?
5977 <note>You can modify the kernel source if you want to help
5978 with boot time.
5979 </note>
5980 </para>
5981
5982 <para>
5983 Run the <filename>ksize.py</filename> script from the top-level
5984 Linux build directory to get an idea of what is making up
5985 the kernel:
5986 <literallayout class='monospaced'>
5987 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5988 $ ksize.py > ksize.log
5989 $ cat ksize.log
5990 </literallayout>
5991 When you examine the log, you will see how much space is
5992 taken up with the built-in <filename>.o</filename> files for
5993 drivers, networking, core kernel files, filesystem, sound,
5994 and so forth.
5995 The sizes reported by the tool are uncompressed, and thus
5996 will be smaller by a relatively constant factor in a compressed
5997 kernel image.
5998 Look to reduce the areas that are large and taking up around
5999 the "90% rule."
6000 </para>
6001
6002 <para>
6003 To examine, or drill down, into any particular area, use the
6004 <filename>-d</filename> option with the script:
6005 <literallayout class='monospaced'>
6006 $ ksize.py -d > ksize.log
6007 </literallayout>
6008 Using this option breaks out the individual file information
6009 for each area of the kernel (e.g. drivers, networking, and
6010 so forth).
6011 </para>
6012
6013 <para>
6014 Use your log file to see what you can eliminate from the kernel
6015 based on features you can let go.
6016 For example, if you are not going to need sound, you do not
6017 need any drivers that support sound.
6018 </para>
6019
6020 <para>
6021 After figuring out what to eliminate, you need to reconfigure
6022 the kernel to reflect those changes during the next build.
6023 You could run <filename>menuconfig</filename> and make all your
6024 changes at once.
6025 However, that makes it difficult to see the effects of your
6026 individual eliminations and also makes it difficult to replicate
6027 the changes for perhaps another target device.
6028 A better method is to start with no configurations using
6029 <filename>allnoconfig</filename>, create configuration
6030 fragments for individual changes, and then manage the
6031 fragments into a single configuration file using
6032 <filename>merge_config.sh</filename>.
6033 The tool makes it easy for you to iterate using the
6034 configuration change and build cycle.
6035 </para>
6036
6037 <para>
6038 Each time you make configuration changes, you need to rebuild
6039 the kernel and check to see what impact your changes had on
6040 the overall size.
6041 </para>
6042 </section>
6043
6044 <section id='remove-package-management-requirements'>
6045 <title>Remove Package Management Requirements</title>
6046
6047 <para>
6048 Packaging requirements add size to the image.
6049 One way to reduce the size of the image is to remove all the
6050 packaging requirements from the image.
6051 This reduction includes both removing the package manager
6052 and its unique dependencies as well as removing the package
6053 management data itself.
6054 </para>
6055
6056 <para>
6057 To eliminate all the packaging requirements for an image,
6058 be sure that "package-management" is not part of your
6059 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
6060 statement for the image.
6061 When you remove this feature, you are removing the package
6062 manager as well as its dependencies from the root filesystem.
6063 </para>
6064 </section>
6065
6066 <section id='look-for-other-ways-to-minimize-size'>
6067 <title>Look for Other Ways to Minimize Size</title>
6068
6069 <para>
6070 Depending on your particular circumstances, other areas that you
6071 can trim likely exist.
6072 The key to finding these areas is through tools and methods
6073 described here combined with experimentation and iteration.
6074 Here are a couple of areas to experiment with:
6075 <itemizedlist>
6076 <listitem><para><filename>glibc</filename>:
6077 In general, follow this process:
6078 <orderedlist>
6079 <listitem><para>Remove <filename>glibc</filename>
6080 features from
6081 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6082 that you think you do not need.</para></listitem>
6083 <listitem><para>Build your distribution.
6084 </para></listitem>
6085 <listitem><para>If the build fails due to missing
6086 symbols in a package, determine if you can
6087 reconfigure the package to not need those
6088 features.
6089 For example, change the configuration to not
6090 support wide character support as is done for
6091 <filename>ncurses</filename>.
6092 Or, if support for those characters is needed,
6093 determine what <filename>glibc</filename>
6094 features provide the support and restore the
6095 configuration.
6096 </para></listitem>
6097 <listitem><para>Rebuild and repeat the process.
6098 </para></listitem>
6099 </orderedlist></para></listitem>
6100 <listitem><para><filename>busybox</filename>:
6101 For BusyBox, use a process similar as described for
6102 <filename>glibc</filename>.
6103 A difference is you will need to boot the resulting
6104 system to see if you are able to do everything you
6105 expect from the running system.
6106 You need to be sure to integrate configuration fragments
6107 into Busybox because BusyBox handles its own core
6108 features and then allows you to add configuration
6109 fragments on top.
6110 </para></listitem>
6111 </itemizedlist>
6112 </para>
6113 </section>
6114
6115 <section id='iterate-on-the-process'>
6116 <title>Iterate on the Process</title>
6117
6118 <para>
6119 If you have not reached your goals on system size, you need
6120 to iterate on the process.
6121 The process is the same.
6122 Use the tools and see just what is taking up 90% of the root
6123 filesystem and the kernel.
6124 Decide what you can eliminate without limiting your device
6125 beyond what you need.
6126 </para>
6127
6128 <para>
6129 Depending on your system, a good place to look might be
6130 Busybox, which provides a stripped down
6131 version of Unix tools in a single, executable file.
6132 You might be able to drop virtual terminal services or perhaps
6133 ipv6.
6134 </para>
6135 </section>
6136 </section>
6137
6138 <section id='building-images-for-more-than-one-machine'>
6139 <title>Building Images for More than One Machine</title>
6140
6141 <para>
6142 A common scenario developers face is creating images for several
6143 different machines that use the same software environment.
6144 In this situation, it is tempting to set the
6145 tunings and optimization flags for each build specifically for
6146 the targeted hardware (i.e. "maxing out" the tunings).
6147 Doing so can considerably add to build times and package feed
6148 maintenance collectively for the machines.
6149 For example, selecting tunes that are extremely specific to a
6150 CPU core used in a system might enable some micro optimizations
6151 in GCC for that particular system but would otherwise not gain
6152 you much of a performance difference across the other systems
6153 as compared to using a more general tuning across all the builds
6154 (e.g. setting
6155 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6156 specifically for each machine's build).
6157 Rather than "max out" each build's tunings, you can take steps that
6158 cause the OpenEmbedded build system to reuse software across the
6159 various machines where it makes sense.
6160 </para>
6161
6162 <para>
6163 If build speed and package feed maintenance are considerations,
6164 you should consider the points in this section that can help you
6165 optimize your tunings to best consider build times and package
6166 feed maintenance.
6167 <itemizedlist>
6168 <listitem><para>
6169 <emphasis>Share the Build Directory:</emphasis>
6170 If at all possible, share the
6171 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6172 across builds.
6173 The Yocto Project supports switching between different
6174 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6175 values in the same <filename>TMPDIR</filename>.
6176 This practice is well supported and regularly used by
6177 developers when building for multiple machines.
6178 When you use the same <filename>TMPDIR</filename> for
6179 multiple machine builds, the OpenEmbedded build system can
6180 reuse the existing native and often cross-recipes for
6181 multiple machines.
6182 Thus, build time decreases.
6183 <note>
6184 If
6185 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6186 settings change or fundamental configuration settings
6187 such as the filesystem layout, you need to work with
6188 a clean <filename>TMPDIR</filename>.
6189 Sharing <filename>TMPDIR</filename> under these
6190 circumstances might work but since it is not
6191 guaranteed, you should use a clean
6192 <filename>TMPDIR</filename>.
6193 </note>
6194 </para></listitem>
6195 <listitem><para>
6196 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6197 By default, the OpenEmbedded build system enables three
6198 levels of package architectures: "all", "tune" or "package",
6199 and "machine".
6200 Any given recipe usually selects one of these package
6201 architectures (types) for its output.
6202 Depending for what a given recipe creates packages, making
6203 sure you enable the appropriate package architecture can
6204 directly impact the build time.</para>
6205
6206 <para>A recipe that just generates scripts can enable
6207 "all" architecture because there are no binaries to build.
6208 To specifically enable "all" architecture, be sure your
6209 recipe inherits the
6210 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6211 class.
6212 This class is useful for "all" architectures because it
6213 configures many variables so packages can be used across
6214 multiple architectures.</para>
6215
6216 <para>If your recipe needs to generate packages that are
6217 machine-specific or when one of the build or runtime
6218 dependencies is already machine-architecture dependent,
6219 which makes your recipe also machine-architecture dependent,
6220 make sure your recipe enables the "machine" package
6221 architecture through the
6222 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6223 variable:
6224 <literallayout class='monospaced'>
6225 PACKAGE_ARCH = "${MACHINE_ARCH}"
6226 </literallayout>
6227 When you do not specifically enable a package
6228 architecture through the
6229 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6230 The OpenEmbedded build system defaults to the
6231 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6232 setting:
6233 <literallayout class='monospaced'>
6234 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6235 </literallayout>
6236 </para></listitem>
6237 <listitem><para>
6238 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6239 Some tunes are more generic and can run on multiple targets
6240 (e.g. an <filename>armv5</filename> set of packages could
6241 run on <filename>armv6</filename> and
6242 <filename>armv7</filename> processors in most cases).
6243 Similarly, <filename>i486</filename> binaries could work
6244 on <filename>i586</filename> and higher processors.
6245 You should realize, however, that advances on newer
6246 processor versions would not be used.</para>
6247
6248 <para>If you select the same tune for several different
6249 machines, the OpenEmbedded build system reuses software
6250 previously built, thus speeding up the overall build time.
6251 Realize that even though a new sysroot for each machine is
6252 generated, the software is not recompiled and only one
6253 package feed exists.
6254 </para></listitem>
6255 <listitem><para>
6256 <emphasis>Manage Granular Level Packaging:</emphasis>
6257 Sometimes cases exist where injecting another level of
6258 package architecture beyond the three higher levels noted
6259 earlier can be useful.
6260 For example, consider how NXP (formerly Freescale) allows
6261 for the easy reuse of binary packages in their layer
6262 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6263 In this example, the
6264 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6265 class shares GPU packages for i.MX53 boards because
6266 all boards share the AMD GPU.
6267 The i.MX6-based boards can do the same because all boards
6268 share the Vivante GPU.
6269 This class inspects the BitBake datastore to identify if
6270 the package provides or depends on one of the
6271 sub-architecture values.
6272 If so, the class sets the
6273 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6274 value based on the <filename>MACHINE_SUBARCH</filename>
6275 value.
6276 If the package does not provide or depend on one of the
6277 sub-architecture values but it matches a value in the
6278 machine-specific filter, it sets
6279 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6280 This behavior reduces the number of packages built and
6281 saves build time by reusing binaries.
6282 </para></listitem>
6283 <listitem><para>
6284 <emphasis>Use Tools to Debug Issues:</emphasis>
6285 Sometimes you can run into situations where software is
6286 being rebuilt when you think it should not be.
6287 For example, the OpenEmbedded build system might not be
6288 using shared state between machines when you think it
6289 should be.
6290 These types of situations are usually due to references
6291 to machine-specific variables such as
6292 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6293 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6294 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6295 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6296 and so forth in code that is supposed to only be
6297 tune-specific or when the recipe depends
6298 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6299 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6300 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6301 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6302 and so forth) on some other recipe that already has
6303 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6304 defined as "${MACHINE_ARCH}".
6305 <note>
6306 Patches to fix any issues identified are most welcome
6307 as these issues occasionally do occur.
6308 </note></para>
6309
6310 <para>For such cases, you can use some tools to help you
6311 sort out the situation:
6312 <itemizedlist>
6313 <listitem><para>
6314 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6315 You can find this tool in the
6316 <filename>scripts</filename> directory of the
6317 Source Repositories.
6318 See the comments in the script for information on
6319 how to use the tool.
6320 </para></listitem>
6321 <listitem><para>
6322 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6323 Using this option causes BitBake to try to
6324 establish the closest signature match it can
6325 (e.g. in the shared state cache) and then run
6326 <filename>bitbake-diffsigs</filename> over the
6327 matches to determine the stamps and delta where
6328 these two stamp trees diverge.
6329 </para></listitem>
6330 </itemizedlist>
6331 </para></listitem>
6332 </itemizedlist>
6333 </para>
6334 </section>
6335
6336 <section id="building-software-from-an-external-source">
6337 <title>Building Software from an External Source</title>
6338
6339 <para>
6340 By default, the OpenEmbedded build system uses the
6341 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6342 when building source code.
6343 The build process involves fetching the source files, unpacking
6344 them, and then patching them if necessary before the build takes
6345 place.
6346 </para>
6347
6348 <para>
6349 Situations exist where you might want to build software from source
6350 files that are external to and thus outside of the
6351 OpenEmbedded build system.
6352 For example, suppose you have a project that includes a new BSP with
6353 a heavily customized kernel.
6354 And, you want to minimize exposing the build system to the
6355 development team so that they can focus on their project and
6356 maintain everyone's workflow as much as possible.
6357 In this case, you want a kernel source directory on the development
6358 machine where the development occurs.
6359 You want the recipe's
6360 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6361 variable to point to the external directory and use it as is, not
6362 copy it.
6363 </para>
6364
6365 <para>
6366 To build from software that comes from an external source, all you
6367 need to do is inherit the
6368 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6369 class and then set the
6370 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6371 variable to point to your external source code.
6372 Here are the statements to put in your
6373 <filename>local.conf</filename> file:
6374 <literallayout class='monospaced'>
6375 INHERIT += "externalsrc"
6376 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6377 </literallayout>
6378 </para>
6379
6380 <para>
6381 This next example shows how to accomplish the same thing by setting
6382 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6383 recipe's append file:
6384 <literallayout class='monospaced'>
6385 EXTERNALSRC = "<replaceable>path</replaceable>"
6386 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6387 </literallayout>
6388 <note>
6389 In order for these settings to take effect, you must globally
6390 or locally inherit the
6391 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6392 class.
6393 </note>
6394 </para>
6395
6396 <para>
6397 By default, <filename>externalsrc.bbclass</filename> builds
6398 the source code in a directory separate from the external source
6399 directory as specified by
6400 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6401 If you need to have the source built in the same directory in
6402 which it resides, or some other nominated directory, you can set
6403 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6404 to point to that directory:
6405 <literallayout class='monospaced'>
6406 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6407 </literallayout>
6408 </para>
6409 </section>
Brad Bishop19323692019-04-05 15:28:33 -04006410
6411 <section id="replicating-a-build-offline">
6412 <title>Replicating a Build Offline</title>
6413
6414 <para>
6415 It can be useful to take a "snapshot" of upstream sources
6416 used in a build and then use that "snapshot" later to
6417 replicate the build offline.
6418 To do so, you need to first prepare and populate your downloads
6419 directory your "snapshot" of files.
6420 Once your downloads directory is ready, you can use it at
6421 any time and from any machine to replicate your build.
6422 </para>
6423
6424 <para>
6425 Follow these steps to populate your Downloads directory:
6426 <orderedlist>
6427 <listitem><para>
6428 <emphasis>Create a Clean Downloads Directory:</emphasis>
6429 Start with an empty downloads directory
6430 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>).
6431 You start with an empty downloads directory by either
6432 removing the files in the existing directory or by
6433 setting
6434 <filename>DL_DIR</filename> to point to either an
6435 empty location or one that does not yet exist.
6436 </para></listitem>
6437 <listitem><para>
6438 <emphasis>Generate Tarballs of the Source Git Repositories:</emphasis>
6439 Edit your <filename>local.conf</filename> configuration
6440 file as follows:
6441 <literallayout class='monospaced'>
6442 DL_DIR = "/home/<replaceable>your-download-dir</replaceable>/"
6443 BB_GENERATE_MIRROR_TARBALLS = "1"
6444 </literallayout>
6445 During the fetch process in the next step, BitBake
6446 gathers the source files and creates tarballs in
6447 the directory pointed to by <filename>DL_DIR</filename>.
6448 See the
6449 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
6450 variable for more information.
6451 </para></listitem>
6452 <listitem><para>
6453 <emphasis>Populate Your Downloads Directory Without Building:</emphasis>
6454 Use BitBake to fetch your sources but inhibit the
6455 build:
6456 <literallayout class='monospaced'>
6457 $ bitbake <replaceable>target</replaceable> --runonly=fetch
6458 </literallayout>
6459 The downloads directory (i.e.
6460 <filename>${DL_DIR}</filename>) now has a "snapshot" of
6461 the source files in the form of tarballs, which can
6462 be used for the build.
6463 </para></listitem>
6464 <listitem><para>
6465 <emphasis>Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory:</emphasis>
6466 If you want, you can clean up your downloads directory
6467 by removing any Git or other Source Control Management
6468 (SCM) subdirectories such as
6469 <filename>${DL_DIR}/git2/*</filename>.
6470 The tarballs already contain these subdirectories.
6471 </para></listitem>
6472 </orderedlist>
6473 </para>
6474
6475 <para>
6476 Once your downloads directory has everything it needs regarding
6477 source files, you can create your "own-mirror" and build
6478 your target.
6479 Understand that you can use the files to build the target
6480 offline from any machine and at any time.
6481 </para>
6482
6483 <para>
6484 Follow these steps to build your target using the files in the
6485 downloads directory:
6486 <orderedlist>
6487 <listitem><para>
6488 <emphasis>Using Local Files Only:</emphasis>
6489 Inside your <filename>local.conf</filename> file, add
6490 the
6491 <ulink url='&YOCTO_DOCS_REF_URL;#var-SOURCE_MIRROR_URL'><filename>SOURCE_MIRROR_URL</filename></ulink>
6492 variable,
6493 inherit the <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-own-mirrors'><filename>own-mirrors</filename></ulink>
6494 class, and use the
6495 <ulink url='&YOCTO_DOCS_BB_URL;#var-bb-BB_NO_NETWORK'><filename>BB_NO_NETWORK</filename></ulink>
6496 variable to your <filename>local.conf</filename>.
6497 <literallayout class='monospaced'>
6498 SOURCE_MIRROR_URL ?= "file:///home/<replaceable>your-download-dir</replaceable>/"
6499 INHERIT += "own-mirrors"
6500 BB_NO_NETWORK = "1"
6501 </literallayout>
6502 The <filename>SOURCE_MIRROR_URL</filename> and
6503 <filename>own-mirror</filename> class set up the system
6504 to use the downloads directory as your "own mirror".
6505 Using the <filename>BB_NO_NETWORK</filename>
6506 variable makes sure that BitBake's fetching process
6507 in step 3 stays local, which means files from
6508 your "own-mirror" are used.
6509 </para></listitem>
6510 <listitem><para>
6511 <emphasis>Start With a Clean Build:</emphasis>
6512 You can start with a clean build by removing the
6513 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
6514 directory or using a new
6515 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
6516 </para></listitem>
6517 <listitem><para>
6518 <emphasis>Build Your Target:</emphasis>
6519 Use BitBake to build your target:
6520 <literallayout class='monospaced'>
6521 $ bitbake <replaceable>target</replaceable>
6522 </literallayout>
6523 The build completes using the known local "snapshot" of
6524 source files from your mirror.
6525 The resulting tarballs for your "snapshot" of source
6526 files are in the downloads directory.
6527 <note>
6528 <para>The offline build does not work if recipes
6529 attempt to find the latest version of software
6530 by setting
6531 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
6532 to
6533 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink><filename>}</filename>:
6534 <literallayout class='monospaced'>
6535 SRCREV = "${AUTOREV}"
6536 </literallayout>
6537 When a recipe sets
6538 <filename>SRCREV</filename> to
6539 <filename>${AUTOREV}</filename>, the build system
6540 accesses the network in an attempt to determine the
6541 latest version of software from the SCM.
6542 Typically, recipes that use
6543 <filename>AUTOREV</filename> are custom or
6544 modified recipes.
6545 Recipes that reside in public repositories
6546 usually do not use <filename>AUTOREV</filename>.
6547 </para>
6548
6549 <para>If you do have recipes that use
6550 <filename>AUTOREV</filename>, you can take steps to
6551 still use the recipes in an offline build.
6552 Do the following:
6553 <orderedlist>
6554 <listitem><para>
6555 Use a configuration generated by
6556 enabling
6557 <link linkend='maintaining-build-output-quality'>build history</link>.
6558 </para></listitem>
6559 <listitem><para>
6560 Use the
6561 <filename>buildhistory-collect-srcrevs</filename>
6562 command to collect the stored
6563 <filename>SRCREV</filename> values from
6564 the build's history.
6565 For more information on collecting these
6566 values, see the
6567 "<link linkend='build-history-package-information'>Build History Package Information</link>"
6568 section.
6569 </para></listitem>
6570 <listitem><para>
6571 Once you have the correct source
6572 revisions, you can modify those recipes
6573 to to set <filename>SRCREV</filename>
6574 to specific versions of the software.
6575 </para></listitem>
6576 </orderedlist>
6577 </para>
6578 </note>
6579 </para></listitem>
6580 </orderedlist>
6581 </para>
6582 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006583 </section>
6584
Brad Bishop316dfdd2018-06-25 12:45:53 -04006585 <section id='speeding-up-a-build'>
6586 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006587
6588 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006589 Build time can be an issue.
6590 By default, the build system uses simple controls to try and maximize
6591 build efficiency.
6592 In general, the default settings for all the following variables
6593 result in the most efficient build times when dealing with single
6594 socket systems (i.e. a single CPU).
6595 If you have multiple CPUs, you might try increasing the default
6596 values to gain more speed.
6597 See the descriptions in the glossary for each variable for more
6598 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006599 <itemizedlist>
6600 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006601 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6602 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006603 </para></listitem>
6604 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006605 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6606 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006607 </para></listitem>
6608 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006609 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6610 Extra options passed to the <filename>make</filename> command
6611 during the
6612 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6613 task in order to specify parallel compilation on the
6614 local build host.
6615 </para></listitem>
6616 <listitem><para>
6617 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6618 Extra options passed to the <filename>make</filename> command
6619 during the
6620 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6621 task in order to specify parallel installation on the
6622 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006623 </para></listitem>
6624 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006625 As mentioned, these variables all scale to the number of processor
6626 cores available on the build system.
6627 For single socket systems, this auto-scaling ensures that the build
6628 system fundamentally takes advantage of potential parallel operations
6629 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006630 </para>
6631
6632 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006633 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006634 <itemizedlist>
6635 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006636 File system type:
6637 The file system type that the build is being performed on can
6638 also influence performance.
6639 Using <filename>ext4</filename> is recommended as compared
6640 to <filename>ext2</filename> and <filename>ext3</filename>
6641 due to <filename>ext4</filename> improved features
6642 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006643 </para></listitem>
6644 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006645 Disabling the updating of access time using
6646 <filename>noatime</filename>:
6647 The <filename>noatime</filename> mount option prevents the
6648 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006649 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006650 <listitem><para>
6651 Setting a longer commit:
6652 Using the "commit=" mount option increases the interval
6653 in seconds between disk cache writes.
6654 Changing this interval from the five second default to
6655 something longer increases the risk of data loss but decreases
6656 the need to write to the disk, thus increasing the build
6657 performance.
6658 </para></listitem>
6659 <listitem><para>
6660 Choosing the packaging backend:
6661 Of the available packaging backends, IPK is the fastest.
6662 Additionally, selecting a singular packaging backend also
6663 helps.
6664 </para></listitem>
6665 <listitem><para>
6666 Using <filename>tmpfs</filename> for
6667 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6668 as a temporary file system:
6669 While this can help speed up the build, the benefits are
6670 limited due to the compiler using
6671 <filename>-pipe</filename>.
6672 The build system goes to some lengths to avoid
6673 <filename>sync()</filename> calls into the
6674 file system on the principle that if there was a significant
6675 failure, the
6676 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6677 contents could easily be rebuilt.
6678 </para></listitem>
6679 <listitem><para>
6680 Inheriting the
6681 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6682 class:
6683 Inheriting this class has shown to speed up builds due to
6684 significantly lower amounts of data stored in the data
6685 cache as well as on disk.
6686 Inheriting this class also makes cleanup of
6687 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6688 faster, at the expense of being easily able to dive into the
6689 source code.
6690 File system maintainers have recommended that the fastest way
6691 to clean up large numbers of files is to reformat partitions
6692 rather than delete files due to the linear nature of
6693 partitions.
6694 This, of course, assumes you structure the disk partitions and
6695 file systems in a way that this is practical.
6696 </para></listitem>
6697 </itemizedlist>
6698 Aside from the previous list, you should keep some trade offs in
6699 mind that can help you speed up the build:
6700 <itemizedlist>
6701 <listitem><para>
6702 Remove items from
6703 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6704 that you might not need.
6705 </para></listitem>
6706 <listitem><para>
6707 Exclude debug symbols and other debug information:
6708 If you do not need these symbols and other debug information,
6709 disabling the <filename>*-dbg</filename> package generation
6710 can speed up the build.
6711 You can disable this generation by setting the
6712 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6713 variable to "1".
6714 </para></listitem>
6715 <listitem><para>
6716 Disable static library generation for recipes derived from
6717 <filename>autoconf</filename> or <filename>libtool</filename>:
6718 Following is an example showing how to disable static
6719 libraries and still provide an override to handle exceptions:
6720 <literallayout class='monospaced'>
6721 STATICLIBCONF = "--disable-static"
6722 STATICLIBCONF_sqlite3-native = ""
6723 EXTRA_OECONF += "${STATICLIBCONF}"
6724 </literallayout>
6725 <note><title>Notes</title>
6726 <itemizedlist>
6727 <listitem><para>
6728 Some recipes need static libraries in order to work
6729 correctly (e.g. <filename>pseudo-native</filename>
6730 needs <filename>sqlite3-native</filename>).
6731 Overrides, as in the previous example, account for
6732 these kinds of exceptions.
6733 </para></listitem>
6734 <listitem><para>
6735 Some packages have packaging code that assumes the
6736 presence of the static libraries.
6737 If so, you might need to exclude them as well.
6738 </para></listitem>
6739 </itemizedlist>
6740 </note>
6741 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006742 </itemizedlist>
6743 </para>
6744 </section>
6745
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006746 <section id="platdev-working-with-libraries">
6747 <title>Working With Libraries</title>
6748
6749 <para>
6750 Libraries are an integral part of your system.
6751 This section describes some common practices you might find
6752 helpful when working with libraries to build your system:
6753 <itemizedlist>
6754 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6755 </para></listitem>
6756 <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>
6757 </para></listitem>
6758 <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>
6759 </para></listitem>
6760 </itemizedlist>
6761 </para>
6762
6763 <section id='including-static-library-files'>
6764 <title>Including Static Library Files</title>
6765
6766 <para>
6767 If you are building a library and the library offers static linking, you can control
6768 which static library files (<filename>*.a</filename> files) get included in the
6769 built library.
6770 </para>
6771
6772 <para>
6773 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6774 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6775 variables in the
6776 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6777 by the <filename>do_install</filename> task are packaged.
6778 By default, the <filename>PACKAGES</filename> variable includes
6779 <filename>${PN}-staticdev</filename>, which represents all static library files.
6780 <note>
6781 Some previously released versions of the Yocto Project
6782 defined the static library files through
6783 <filename>${PN}-dev</filename>.
6784 </note>
6785 Following is part of the BitBake configuration file, where
6786 you can see how the static library files are defined:
6787 <literallayout class='monospaced'>
6788 PACKAGE_BEFORE_PN ?= ""
6789 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6790 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6791 FILES = ""
6792
6793 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6794 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6795 ${base_bindir}/* ${base_sbindir}/* \
6796 ${base_libdir}/*${SOLIBS} \
6797 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6798 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6799 ${datadir}/pixmaps ${datadir}/applications \
6800 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6801 ${libdir}/bonobo/servers"
6802
6803 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6804
6805 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6806 ${datadir}/gnome/help"
6807 SECTION_${PN}-doc = "doc"
6808
6809 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6810 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6811 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6812 ${datadir}/aclocal ${base_libdir}/*.o \
6813 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6814 SECTION_${PN}-dev = "devel"
6815 ALLOW_EMPTY_${PN}-dev = "1"
6816 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6817
6818 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6819 SECTION_${PN}-staticdev = "devel"
6820 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6821 </literallayout>
6822 </para>
6823 </section>
6824
6825 <section id="combining-multiple-versions-library-files-into-one-image">
6826 <title>Combining Multiple Versions of Library Files into One Image</title>
6827
6828 <para>
6829 The build system offers the ability to build libraries with different
6830 target optimizations or architecture formats and combine these together
6831 into one system image.
6832 You can link different binaries in the image
6833 against the different libraries as needed for specific use cases.
6834 This feature is called "Multilib."
6835 </para>
6836
6837 <para>
6838 An example would be where you have most of a system compiled in 32-bit
6839 mode using 32-bit libraries, but you have something large, like a database
6840 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6841 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6842 </para>
6843
6844 <para>
6845 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6846 the approach the build system uses facilitates different target optimizations.
6847 You could compile some binaries to use one set of libraries and other binaries
6848 to use a different set of libraries.
6849 The libraries could differ in architecture, compiler options, or other
6850 optimizations.
6851 </para>
6852
6853 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006854 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006855 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006856 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006857 <itemizedlist>
6858 <listitem><para><filename>conf/multilib-example.conf</filename>
6859 configuration file</para></listitem>
6860 <listitem><para><filename>conf/multilib-example2.conf</filename>
6861 configuration file</para></listitem>
6862 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6863 recipe</para></listitem>
6864 </itemizedlist>
6865 </para>
6866
6867 <section id='preparing-to-use-multilib'>
6868 <title>Preparing to Use Multilib</title>
6869
6870 <para>
6871 User-specific requirements drive the Multilib feature.
6872 Consequently, there is no one "out-of-the-box" configuration that likely
6873 exists to meet your needs.
6874 </para>
6875
6876 <para>
6877 In order to enable Multilib, you first need to ensure your recipe is
6878 extended to support multiple libraries.
6879 Many standard recipes are already extended and support multiple libraries.
6880 You can check in the <filename>meta/conf/multilib.conf</filename>
6881 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006882 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006883 done using the
6884 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6885 variable.
6886 Eventually, all recipes will be covered and this list will
6887 not be needed.
6888 </para>
6889
6890 <para>
6891 For the most part, the Multilib class extension works automatically to
6892 extend the package name from <filename>${PN}</filename> to
6893 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6894 is the particular multilib (e.g. "lib32-" or "lib64-").
6895 Standard variables such as
6896 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6897 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6898 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6899 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6900 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6901 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6902 are automatically extended by the system.
6903 If you are extending any manual code in the recipe, you can use the
6904 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6905 correctly.
6906 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6907 </para>
6908 </section>
6909
6910 <section id='using-multilib'>
6911 <title>Using Multilib</title>
6912
6913 <para>
6914 After you have set up the recipes, you need to define the actual
6915 combination of multiple libraries you want to build.
6916 You accomplish this through your <filename>local.conf</filename>
6917 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006918 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006919 An example configuration would be as follows:
6920 <literallayout class='monospaced'>
6921 MACHINE = "qemux86-64"
6922 require conf/multilib.conf
6923 MULTILIBS = "multilib:lib32"
6924 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006925 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006926 </literallayout>
6927 This example enables an
6928 additional library named <filename>lib32</filename> alongside the
6929 normal target packages.
6930 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6931 For information on this particular tuning, see
6932 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6933 </para>
6934
6935 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006936 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006937 in all the images, which illustrates one method of including a
6938 multiple library dependency.
6939 You can use a normal image build to include this dependency,
6940 for example:
6941 <literallayout class='monospaced'>
6942 $ bitbake core-image-sato
6943 </literallayout>
6944 You can also build Multilib packages specifically with a command like this:
6945 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006946 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006947 </literallayout>
6948 </para>
6949 </section>
6950
6951 <section id='additional-implementation-details'>
6952 <title>Additional Implementation Details</title>
6953
6954 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006955 Generic implementation details as well as details that are
6956 specific to package management systems exist.
6957 Following are implementation details that exist regardless
6958 of the package management system:
6959 <itemizedlist>
6960 <listitem><para>The typical convention used for the
6961 class extension code as used by
6962 Multilib assumes that all package names specified
6963 in
6964 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6965 that contain <filename>${PN}</filename> have
6966 <filename>${PN}</filename> at the start of the name.
6967 When that convention is not followed and
6968 <filename>${PN}</filename> appears at
6969 the middle or the end of a name, problems occur.
6970 </para></listitem>
6971 <listitem><para>The
6972 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6973 value under Multilib will be extended to
6974 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6975 (e.g. "-pokymllib32" for a "lib32" Multilib with
6976 Poky).
6977 The reason for this slightly unwieldy contraction
6978 is that any "-" characters in the vendor
6979 string presently break Autoconf's
6980 <filename>config.sub</filename>, and
6981 other separators are problematic for different
6982 reasons.
6983 </para></listitem>
6984 </itemizedlist>
6985 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006986
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006987 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006988 For the RPM Package Management System, the following implementation details
6989 exist:
6990 <itemizedlist>
6991 <listitem><para>A unique architecture is defined for the Multilib packages,
6992 along with creating a unique deploy folder under
6993 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006994 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006995 For example, consider <filename>lib32</filename> in a
6996 <filename>qemux86-64</filename> image.
6997 The possible architectures in the system are "all", "qemux86_64",
6998 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6999 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
7000 <filename>${PN}</filename> during RPM packaging.
7001 The naming for a normal RPM package and a Multilib RPM package in a
7002 <filename>qemux86-64</filename> system resolves to something similar to
7003 <filename>bash-4.1-r2.x86_64.rpm</filename> and
7004 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
7005 </para></listitem>
7006 <listitem><para>When installing a Multilib image, the RPM backend first
7007 installs the base image and then installs the Multilib libraries.
7008 </para></listitem>
7009 <listitem><para>The build system relies on RPM to resolve the identical files in the
7010 two (or more) Multilib packages.</para></listitem>
7011 </itemizedlist>
7012 </para>
7013
7014 <para>
7015 For the IPK Package Management System, the following implementation details exist:
7016 <itemizedlist>
7017 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
7018 <filename>${PN}</filename> during IPK packaging.
7019 The naming for a normal RPM package and a Multilib IPK package in a
7020 <filename>qemux86-64</filename> system resolves to something like
7021 <filename>bash_4.1-r2.x86_64.ipk</filename> and
7022 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
7023 </para></listitem>
7024 <listitem><para>The IPK deploy folder is not modified with
7025 <filename>${MLPREFIX}</filename> because packages with and without
7026 the Multilib feature can exist in the same folder due to the
7027 <filename>${PN}</filename> differences.</para></listitem>
7028 <listitem><para>IPK defines a sanity check for Multilib installation
7029 using certain rules for file comparison, overridden, etc.
7030 </para></listitem>
7031 </itemizedlist>
7032 </para>
7033 </section>
7034 </section>
7035
7036 <section id='installing-multiple-versions-of-the-same-library'>
7037 <title>Installing Multiple Versions of the Same Library</title>
7038
7039 <para>
7040 Situations can exist where you need to install and use
7041 multiple versions of the same library on the same system
7042 at the same time.
7043 These situations almost always exist when a library API
7044 changes and you have multiple pieces of software that
7045 depend on the separate versions of the library.
7046 To accommodate these situations, you can install multiple
7047 versions of the same library in parallel on the same system.
7048 </para>
7049
7050 <para>
7051 The process is straightforward as long as the libraries use
7052 proper versioning.
7053 With properly versioned libraries, all you need to do to
7054 individually specify the libraries is create separate,
7055 appropriately named recipes where the
7056 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
7057 name includes a portion that differentiates each library version
7058 (e.g.the major part of the version number).
7059 Thus, instead of having a single recipe that loads one version
7060 of a library (e.g. <filename>clutter</filename>), you provide
7061 multiple recipes that result in different versions
7062 of the libraries you want.
7063 As an example, the following two recipes would allow the
7064 two separate versions of the <filename>clutter</filename>
7065 library to co-exist on the same system:
7066 <literallayout class='monospaced'>
7067 clutter-1.6_1.6.20.bb
7068 clutter-1.8_1.8.4.bb
7069 </literallayout>
7070 Additionally, if you have other recipes that depend on a given
7071 library, you need to use the
7072 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
7073 variable to create the dependency.
7074 Continuing with the same example, if you want to have a recipe
7075 depend on the 1.8 version of the <filename>clutter</filename>
7076 library, use the following in your recipe:
7077 <literallayout class='monospaced'>
7078 DEPENDS = "clutter-1.8"
7079 </literallayout>
7080 </para>
7081 </section>
7082 </section>
7083
Brad Bishop316dfdd2018-06-25 12:45:53 -04007084 <section id='using-x32-psabi'>
7085 <title>Using x32 psABI</title>
7086
7087 <para>
7088 x32 processor-specific Application Binary Interface
7089 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
7090 is a native 32-bit processor-specific ABI for
7091 <trademark class='registered'>Intel</trademark> 64 (x86-64)
7092 architectures.
7093 An ABI defines the calling conventions between functions in a
7094 processing environment.
7095 The interface determines what registers are used and what the
7096 sizes are for various C data types.
7097 </para>
7098
7099 <para>
7100 Some processing environments prefer using 32-bit applications even
7101 when running on Intel 64-bit platforms.
7102 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
7103 64-bit platforms.
7104 The i386 psABI does not provide efficient use and access of the
7105 Intel 64-bit processor resources, leaving the system underutilized.
7106 Now consider the x86_64 psABI.
7107 This ABI is newer and uses 64-bits for data sizes and program
7108 pointers.
7109 The extra bits increase the footprint size of the programs,
7110 libraries, and also increases the memory and file system size
7111 requirements.
7112 Executing under the x32 psABI enables user programs to utilize CPU
7113 and system resources more efficiently while keeping the memory
7114 footprint of the applications low.
7115 Extra bits are used for registers but not for addressing mechanisms.
7116 </para>
7117
7118 <para>
7119 The Yocto Project supports the final specifications of x32 psABI
7120 as follows:
7121 <itemizedlist>
7122 <listitem><para>
7123 You can create packages and images in x32 psABI format on
7124 x86_64 architecture targets.
7125 </para></listitem>
7126 <listitem><para>
7127 You can successfully build recipes with the x32 toolchain.
7128 </para></listitem>
7129 <listitem><para>
7130 You can create and boot
7131 <filename>core-image-minimal</filename> and
7132 <filename>core-image-sato</filename> images.
7133 </para></listitem>
7134 <listitem><para>
7135 RPM Package Manager (RPM) support exists for x32 binaries.
7136 </para></listitem>
7137 <listitem><para>
7138 Support for large images exists.
7139 </para></listitem>
7140 </itemizedlist>
7141 </para>
7142
7143 <para>
7144 To use the x32 psABI, you need to edit your
7145 <filename>conf/local.conf</filename> configuration file as
7146 follows:
7147 <literallayout class='monospaced'>
7148 MACHINE = "qemux86-64"
7149 DEFAULTTUNE = "x86-64-x32"
Brad Bishop19323692019-04-05 15:28:33 -04007150 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
7151 or 'INVALID')) or 'lib'}"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007152 </literallayout>
7153 Once you have set up your configuration file, use BitBake to
7154 build an image that supports the x32 psABI.
7155 Here is an example:
7156 <literallayout class='monospaced'>
7157 $ bitbake core-image-sato
7158 </literallayout>
7159 </para>
7160 </section>
7161
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007162 <section id='enabling-gobject-introspection-support'>
7163 <title>Enabling GObject Introspection Support</title>
7164
7165 <para>
7166 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
7167 is the standard mechanism for accessing GObject-based software
7168 from runtime environments.
7169 GObject is a feature of the GLib library that provides an object
7170 framework for the GNOME desktop and related software.
7171 GObject Introspection adds information to GObject that allows
7172 objects created within it to be represented across different
7173 programming languages.
7174 If you want to construct GStreamer pipelines using Python, or
7175 control UPnP infrastructure using Javascript and GUPnP,
7176 GObject introspection is the only way to do it.
7177 </para>
7178
7179 <para>
7180 This section describes the Yocto Project support for generating
7181 and packaging GObject introspection data.
7182 GObject introspection data is a description of the
7183 API provided by libraries built on top of GLib framework,
7184 and, in particular, that framework's GObject mechanism.
7185 GObject Introspection Repository (GIR) files go to
7186 <filename>-dev</filename> packages,
7187 <filename>typelib</filename> files go to main packages as they
7188 are packaged together with libraries that are introspected.
7189 </para>
7190
7191 <para>
7192 The data is generated when building such a library, by linking
7193 the library with a small executable binary that asks the library
7194 to describe itself, and then executing the binary and
7195 processing its output.
7196 </para>
7197
7198 <para>
7199 Generating this data in a cross-compilation environment
7200 is difficult because the library is produced for the target
7201 architecture, but its code needs to be executed on the build host.
7202 This problem is solved with the OpenEmbedded build system by
7203 running the code through QEMU, which allows precisely that.
7204 Unfortunately, QEMU does not always work perfectly as mentioned
Brad Bishop96ff1982019-08-19 13:50:42 -04007205 in the
7206 "<link linkend='known-issues'>Known Issues</link>" section.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007207 </para>
7208
7209 <section id='enabling-the-generation-of-introspection-data'>
7210 <title>Enabling the Generation of Introspection Data</title>
7211
7212 <para>
7213 Enabling the generation of introspection data (GIR files)
7214 in your library package involves the following:
7215 <orderedlist>
7216 <listitem><para>
7217 Inherit the
7218 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
7219 class.
7220 </para></listitem>
7221 <listitem><para>
7222 Make sure introspection is not disabled anywhere in
7223 the recipe or from anything the recipe includes.
7224 Also, make sure that "gobject-introspection-data" is
7225 not in
7226 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7227 and that "qemu-usermode" is not in
7228 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7229 If either of these conditions exist, nothing will
7230 happen.
7231 </para></listitem>
7232 <listitem><para>
7233 Try to build the recipe.
7234 If you encounter build errors that look like
7235 something is unable to find
7236 <filename>.so</filename> libraries, check where these
7237 libraries are located in the source tree and add
7238 the following to the recipe:
7239 <literallayout class='monospaced'>
7240 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
7241 </literallayout>
7242 <note>
7243 See recipes in the <filename>oe-core</filename>
7244 repository that use that
7245 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
7246 as an example.
7247 </note>
7248 </para></listitem>
7249 <listitem><para>
7250 Look for any other errors, which probably mean that
7251 introspection support in a package is not entirely
7252 standard, and thus breaks down in a cross-compilation
7253 environment.
7254 For such cases, custom-made fixes are needed.
7255 A good place to ask and receive help in these cases
7256 is the
7257 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7258 </para></listitem>
7259 </orderedlist>
7260 <note>
7261 Using a library that no longer builds against the latest
7262 Yocto Project release and prints introspection related
7263 errors is a good candidate for the previous procedure.
7264 </note>
7265 </para>
7266 </section>
7267
7268 <section id='disabling-the-generation-of-introspection-data'>
7269 <title>Disabling the Generation of Introspection Data</title>
7270
7271 <para>
7272 You might find that you do not want to generate
7273 introspection data.
7274 Or, perhaps QEMU does not work on your build host and
7275 target architecture combination.
7276 If so, you can use either of the following methods to
7277 disable GIR file generations:
7278 <itemizedlist>
7279 <listitem><para>
7280 Add the following to your distro configuration:
7281 <literallayout class='monospaced'>
7282 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7283 </literallayout>
7284 Adding this statement disables generating
7285 introspection data using QEMU but will still enable
7286 building introspection tools and libraries
7287 (i.e. building them does not require the use of QEMU).
7288 </para></listitem>
7289 <listitem><para>
7290 Add the following to your machine configuration:
7291 <literallayout class='monospaced'>
7292 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7293 </literallayout>
7294 Adding this statement disables the use of QEMU
7295 when building packages for your machine.
7296 Currently, this feature is used only by introspection
7297 recipes and has the same effect as the previously
7298 described option.
7299 <note>
7300 Future releases of the Yocto Project might have
7301 other features affected by this option.
7302 </note>
7303 </para></listitem>
7304 </itemizedlist>
7305 If you disable introspection data, you can still
7306 obtain it through other means such as copying the data
7307 from a suitable sysroot, or by generating it on the
7308 target hardware.
7309 The OpenEmbedded build system does not currently
7310 provide specific support for these techniques.
7311 </para>
7312 </section>
7313
7314 <section id='testing-that-introspection-works-in-an-image'>
7315 <title>Testing that Introspection Works in an Image</title>
7316
7317 <para>
7318 Use the following procedure to test if generating
7319 introspection data is working in an image:
7320 <orderedlist>
7321 <listitem><para>
7322 Make sure that "gobject-introspection-data" is not in
7323 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7324 and that "qemu-usermode" is not in
7325 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7326 </para></listitem>
7327 <listitem><para>
7328 Build <filename>core-image-sato</filename>.
7329 </para></listitem>
7330 <listitem><para>
7331 Launch a Terminal and then start Python in the
7332 terminal.
7333 </para></listitem>
7334 <listitem><para>
7335 Enter the following in the terminal:
7336 <literallayout class='monospaced'>
7337 >>> from gi.repository import GLib
7338 >>> GLib.get_host_name()
7339 </literallayout>
7340 </para></listitem>
7341 <listitem><para>
7342 For something a little more advanced, enter the
7343 following:
7344 <literallayout class='monospaced'>
7345 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7346 </literallayout>
7347 </para></listitem>
7348 </orderedlist>
7349 </para>
7350 </section>
7351
7352 <section id='known-issues'>
7353 <title>Known Issues</title>
7354
7355 <para>
7356 The following know issues exist for
7357 GObject Introspection Support:
7358 <itemizedlist>
7359 <listitem><para>
7360 <filename>qemu-ppc64</filename> immediately crashes.
7361 Consequently, you cannot build introspection data on
7362 that architecture.
7363 </para></listitem>
7364 <listitem><para>
7365 x32 is not supported by QEMU.
7366 Consequently, introspection data is disabled.
7367 </para></listitem>
7368 <listitem><para>
7369 musl causes transient GLib binaries to crash on
7370 assertion failures.
7371 Consequently, generating introspection data is
7372 disabled.
7373 </para></listitem>
7374 <listitem><para>
7375 Because QEMU is not able to run the binaries correctly,
7376 introspection is disabled for some specific packages
7377 under specific architectures (e.g.
7378 <filename>gcr</filename>,
7379 <filename>libsecret</filename>, and
7380 <filename>webkit</filename>).
7381 </para></listitem>
7382 <listitem><para>
7383 QEMU usermode might not work properly when running
7384 64-bit binaries under 32-bit host machines.
7385 In particular, "qemumips64" is known to not work under
7386 i686.
7387 </para></listitem>
7388 </itemizedlist>
7389 </para>
7390 </section>
7391 </section>
7392
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007393 <section id='dev-optionally-using-an-external-toolchain'>
7394 <title>Optionally Using an External Toolchain</title>
7395
7396 <para>
7397 You might want to use an external toolchain as part of your
7398 development.
7399 If this is the case, the fundamental steps you need to accomplish
7400 are as follows:
7401 <itemizedlist>
7402 <listitem><para>
7403 Understand where the installed toolchain resides.
7404 For cases where you need to build the external toolchain,
7405 you would need to take separate steps to build and install
7406 the toolchain.
7407 </para></listitem>
7408 <listitem><para>
7409 Make sure you add the layer that contains the toolchain to
7410 your <filename>bblayers.conf</filename> file through the
7411 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7412 variable.
7413 </para></listitem>
7414 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007415 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007416 variable in your <filename>local.conf</filename> file
7417 to the location in which you installed the toolchain.
7418 </para></listitem>
7419 </itemizedlist>
7420 A good example of an external toolchain used with the Yocto Project
7421 is <trademark class='registered'>Mentor Graphics</trademark>
7422 Sourcery G++ Toolchain.
7423 You can see information on how to use that particular layer in the
7424 <filename>README</filename> file at
7425 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7426 You can find further information by reading about the
7427 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7428 variable in the Yocto Project Reference Manual's variable glossary.
7429 </para>
7430 </section>
7431
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007432 <section id='creating-partitioned-images-using-wic'>
7433 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007434
7435 <para>
7436 Creating an image for a particular hardware target using the
7437 OpenEmbedded build system does not necessarily mean you can boot
7438 that image as is on your device.
7439 Physical devices accept and boot images in various ways depending
7440 on the specifics of the device.
7441 Usually, information about the hardware can tell you what image
7442 format the device requires.
7443 Should your device require multiple partitions on an SD card, flash,
7444 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007445 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007446 </para>
7447
7448 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007449 The <filename>wic</filename> command generates partitioned
7450 images from existing OpenEmbedded build artifacts.
7451 Image generation is driven by partitioning commands
7452 contained in an Openembedded kickstart file
7453 (<filename>.wks</filename>) specified either directly on
7454 the command line or as one of a selection of canned
7455 kickstart files as shown with the
7456 <filename>wic list images</filename> command in the
7457 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7458 section.
7459 When you apply the command to a given set of build
7460 artifacts, the result is an image or set of images that
7461 can be directly written onto media and used on a particular
7462 system.
7463 <note>
7464 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007465 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007466 Chapter in the Yocto Project Reference Manual.
7467 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007468 </para>
7469
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007470 <para>
7471 The <filename>wic</filename> command and the infrastructure
7472 it is based on is by definition incomplete.
7473 The purpose of the command is to allow the generation of
7474 customized images, and as such, was designed to be
Brad Bishopc342db32019-05-15 21:57:59 -04007475 completely extensible through a plugin interface.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007476 See the
Brad Bishopc342db32019-05-15 21:57:59 -04007477 "<link linkend='wic-using-the-wic-plugin-interface'>Using the Wic PlugIn Interface</link>"
7478 section for information on these plugins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007479 </para>
7480
7481 <para>
7482 This section provides some background information on Wic,
7483 describes what you need to have in
7484 place to run the tool, provides instruction on how to use
Brad Bishopc342db32019-05-15 21:57:59 -04007485 the Wic utility, provides information on using the Wic plugins
Brad Bishop316dfdd2018-06-25 12:45:53 -04007486 interface, and provides several examples that show how to use
7487 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007488 </para>
7489
7490 <section id='wic-background'>
7491 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007492
7493 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007494 This section provides some background on the Wic utility.
7495 While none of this information is required to use
7496 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007497 <itemizedlist>
7498 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007499 The name "Wic" is derived from OpenEmbedded
7500 Image Creator (oeic).
7501 The "oe" diphthong in "oeic" was promoted to the
7502 letter "w", because "oeic" is both difficult to
7503 remember and to pronounce.
7504 </para></listitem>
7505 <listitem><para>
7506 Wic is loosely based on the
7507 Meego Image Creator (<filename>mic</filename>)
7508 framework.
7509 The Wic implementation has been
7510 heavily modified to make direct use of OpenEmbedded
7511 build artifacts instead of package installation and
7512 configuration, which are already incorporated within
7513 the OpenEmbedded artifacts.
7514 </para></listitem>
7515 <listitem><para>
7516 Wic is a completely independent
7517 standalone utility that initially provides
7518 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007519 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007520 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007521 class.
7522 The difference between Wic and those examples is
7523 that with Wic the functionality of those scripts is
7524 implemented by a general-purpose partitioning language,
7525 which is based on Redhat kickstart syntax.
7526 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007527 </itemizedlist>
7528 </para>
7529 </section>
7530
7531 <section id='wic-requirements'>
7532 <title>Requirements</title>
7533
7534 <para>
7535 In order to use the Wic utility with the OpenEmbedded Build
7536 system, your system needs to meet the following
7537 requirements:
7538 <itemizedlist>
7539 <listitem><para>
7540 The Linux distribution on your development host must
7541 support the Yocto Project.
7542 See the
7543 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7544 section in the Yocto Project Reference Manual for
7545 the list of distributions that support the
7546 Yocto Project.
7547 </para></listitem>
7548 <listitem><para>
7549 The standard system utilities, such as
7550 <filename>cp</filename>, must be installed on your
7551 development host system.
7552 </para></listitem>
7553 <listitem><para>
7554 You must have sourced the build environment
7555 setup script (i.e.
7556 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7557 found in the
7558 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7559 </para></listitem>
7560 <listitem><para>
7561 You need to have the build artifacts already
7562 available, which typically means that you must
7563 have already created an image using the
7564 Openembedded build system (e.g.
7565 <filename>core-image-minimal</filename>).
7566 While it might seem redundant to generate an image
7567 in order to create an image using
7568 Wic, the current version of
7569 Wic requires the artifacts
7570 in the form generated by the OpenEmbedded build
7571 system.
7572 </para></listitem>
7573 <listitem><para>
7574 You must build several native tools, which are
7575 built to run on the build system:
7576 <literallayout class='monospaced'>
7577 $ bitbake parted-native dosfstools-native mtools-native
7578 </literallayout>
7579 </para></listitem>
7580 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007581 Include "wic" as part of the
7582 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7583 variable.
7584 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007585 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007586 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007587 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007588 as part of the
7589 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7590 variable
7591 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007592 </itemizedlist>
7593 </para>
7594 </section>
7595
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007596 <section id='wic-getting-help'>
7597 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007598
7599 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007600 You can get general help for the <filename>wic</filename>
7601 command by entering the <filename>wic</filename> command
7602 by itself or by entering the command with a help argument
7603 as follows:
7604 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007605 $ wic -h
7606 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007607 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007608 </literallayout>
7609 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007610
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007611 <para>
7612 Currently, Wic supports seven commands:
7613 <filename>cp</filename>, <filename>create</filename>,
7614 <filename>help</filename>, <filename>list</filename>,
7615 <filename>ls</filename>, <filename>rm</filename>, and
7616 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007617 You can get help for all these commands except "help" by
7618 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007619 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007620 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007621 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007622 For example, the following command returns help for the
7623 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007624 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007625 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007626 </literallayout>
7627 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007628
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007629 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007630 Wic supports help for three topics:
7631 <filename>overview</filename>,
7632 <filename>plugins</filename>, and
7633 <filename>kickstart</filename>.
7634 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007635 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007636 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007637 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007638 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007639 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007640 $ wic help overview
7641 </literallayout>
7642 </para>
7643
7644 <para>
7645 One additional level of help exists for Wic.
7646 You can get help on individual images through the
7647 <filename>list</filename> command.
7648 You can use the <filename>list</filename> command to return the
7649 available Wic images as follows:
7650 <literallayout class='monospaced'>
7651 $ wic list images
Brad Bishop316dfdd2018-06-25 12:45:53 -04007652 genericx86 Create an EFI disk image for genericx86*
7653 beaglebone-yocto Create SD card image for Beaglebone
7654 edgerouter Create SD card image for Edgerouter
7655 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7656 directdisk-gpt Create a 'pcbios' direct disk image
7657 mkefidisk Create an EFI disk image
7658 directdisk Create a 'pcbios' direct disk image
7659 systemd-bootdisk Create an EFI disk image with systemd-boot
7660 mkhybridiso Create a hybrid ISO image
7661 sdimage-bootpart Create SD card image with a boot partition
7662 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7663 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7664 </literallayout>
7665 Once you know the list of available Wic images, you can use
7666 <filename>help</filename> with the command to get help on a
7667 particular image.
7668 For example, the following command returns help on the
7669 "beaglebone-yocto" image:
7670 <literallayout class='monospaced'>
7671 $ wic list beaglebone-yocto help
7672
7673
7674 Creates a partitioned SD card image for Beaglebone.
7675 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007676 </literallayout>
7677 </para>
7678 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007679
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007680 <section id='operational-modes'>
7681 <title>Operational Modes</title>
7682
7683 <para>
7684 You can use Wic in two different
7685 modes, depending on how much control you need for
7686 specifying the Openembedded build artifacts that are
7687 used for creating the image: Raw and Cooked:
7688 <itemizedlist>
7689 <listitem><para>
7690 <emphasis>Raw Mode:</emphasis>
7691 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007692 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007693 </para></listitem>
7694 <listitem><para>
7695 <emphasis>Cooked Mode:</emphasis>
7696 The current
7697 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7698 setting and image name are used to automatically
7699 locate and provide the build artifacts.
7700 You just supply a kickstart file and the name
7701 of the image from which to use artifacts.
7702 </para></listitem>
7703 </itemizedlist>
7704 </para>
7705
7706 <para>
7707 Regardless of the mode you use, you need to have the build
7708 artifacts ready and available.
7709 </para>
7710
7711 <section id='raw-mode'>
7712 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007713
7714 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007715 Running Wic in raw mode allows you to specify all the
7716 partitions through the <filename>wic</filename>
7717 command line.
7718 The primary use for raw mode is if you have built
7719 your kernel outside of the Yocto Project
7720 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7721 In other words, you can point to arbitrary kernel,
7722 root filesystem locations, and so forth.
7723 Contrast this behavior with cooked mode where Wic
7724 looks in the Build Directory (e.g.
7725 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007726 </para>
7727
7728 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007729 The general form of the
7730 <filename>wic</filename> command in raw mode is:
7731 <literallayout class='monospaced'>
7732 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007733
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007734 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007735
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007736 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007737 An OpenEmbedded kickstart file. You can provide
7738 your own custom file or use a file from a set of
7739 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007740
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007741 optional arguments:
7742 -h, --help show this help message and exit
7743 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7744 name of directory to create image in
7745 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7746 name of the image to use the artifacts from e.g. core-
7747 image-sato
7748 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7749 path to the /rootfs dir to use as the .wks rootfs
7750 source
7751 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7752 path to the dir containing the boot artifacts (e.g.
7753 /EFI or /syslinux dirs) to use as the .wks bootimg
7754 source
7755 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7756 path to the dir containing the kernel to use in the
7757 .wks bootimg
7758 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7759 path to the native sysroot containing the tools to use
7760 to build the image
7761 -s, --skip-build-check
7762 skip the build check
7763 -f, --build-rootfs build rootfs
7764 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7765 compress image with specified compressor
7766 -m, --bmap generate .bmap
7767 --no-fstab-update Do not change fstab file.
7768 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7769 directory with &lt;image&gt;.env files that store bitbake
7770 variables
7771 -D, --debug output debug information
7772 </literallayout>
7773 <note>
7774 You do not need root privileges to run
7775 Wic.
7776 In fact, you should not run as root when using the
7777 utility.
7778 </note>
7779 </para>
7780 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007781
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007782 <section id='cooked-mode'>
7783 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007784
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007785 <para>
7786 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007787 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007788 In other words, you do not have to specify kernel or
7789 root filesystem locations as part of the command.
7790 All you need to provide is a kickstart file and the
7791 name of the image from which to use artifacts by using
7792 the "-e" option.
7793 Wic looks in the Build Directory (e.g.
7794 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7795 for artifacts.
7796 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007797
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007798 <para>
7799 The general form of the <filename>wic</filename>
7800 command using Cooked Mode is as follows:
7801 <literallayout class='monospaced'>
7802 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007803
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007804 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007805
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007806 <replaceable>wks_file</replaceable>:
7807 An OpenEmbedded kickstart file. You can provide
7808 your own custom file or use a file from a set of
7809 existing files provided with the Yocto Project
7810 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007811
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007812 required argument:
7813 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7814 name of the image to use the artifacts from e.g. core-
7815 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007816 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007817 </para>
7818 </section>
7819 </section>
7820
7821 <section id='using-a-provided-kickstart-file'>
7822 <title>Using an Existing Kickstart File</title>
7823
7824 <para>
7825 If you do not want to create your own kickstart file, you
7826 can use an existing file provided by the Wic installation.
7827 As shipped, kickstart files can be found in the
7828 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007829 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007830 in the following two locations:
7831 <literallayout class='monospaced'>
7832 poky/meta-yocto-bsp/wic
7833 poky/scripts/lib/wic/canned-wks
7834 </literallayout>
7835 Use the following command to list the available kickstart
7836 files:
7837 <literallayout class='monospaced'>
7838 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007839 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007840 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007841 edgerouter Create SD card image for Edgerouter
7842 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7843 directdisk-gpt Create a 'pcbios' direct disk image
7844 mkefidisk Create an EFI disk image
7845 directdisk Create a 'pcbios' direct disk image
7846 systemd-bootdisk Create an EFI disk image with systemd-boot
7847 mkhybridiso Create a hybrid ISO image
7848 sdimage-bootpart Create SD card image with a boot partition
7849 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7850 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7851 </literallayout>
7852 When you use an existing file, you do not have to use the
7853 <filename>.wks</filename> extension.
7854 Here is an example in Raw Mode that uses the
7855 <filename>directdisk</filename> file:
7856 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007857 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7858 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007859 </literallayout>
7860 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007861
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007862 <para>
7863 Here are the actual partition language commands
7864 used in the <filename>genericx86.wks</filename> file to
7865 generate an image:
7866 <literallayout class='monospaced'>
7867 # short-description: Create an EFI disk image for genericx86*
7868 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7869 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7870 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007871 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7872
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007873 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7874 </literallayout>
7875 </para>
7876 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007877
Brad Bishopc342db32019-05-15 21:57:59 -04007878 <section id='wic-using-the-wic-plugin-interface'>
7879 <title>Using the Wic Plugin Interface</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007880
7881 <para>
7882 You can extend and specialize Wic functionality by using
Brad Bishopc342db32019-05-15 21:57:59 -04007883 Wic plugins.
7884 This section explains the Wic plugin interface.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007885 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007886 Wic plugins consist of "source" and "imager" plugins.
7887 Imager plugins are beyond the scope of this section.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007888 </note>
7889 </para>
7890
7891 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007892 Source plugins provide a mechanism to customize partition
Brad Bishop316dfdd2018-06-25 12:45:53 -04007893 content during the Wic image generation process.
Brad Bishopc342db32019-05-15 21:57:59 -04007894 You can use source plugins to map values that you specify
Brad Bishop316dfdd2018-06-25 12:45:53 -04007895 using <filename>--source</filename> commands in kickstart
Brad Bishopc342db32019-05-15 21:57:59 -04007896 files (i.e. <filename>*.wks</filename>) to a plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007897 implementation used to populate a given partition.
7898 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007899 If you use plugins that have build-time dependencies
Brad Bishop316dfdd2018-06-25 12:45:53 -04007900 (e.g. native tools, bootloaders, and so forth)
7901 when building a Wic image, you need to specify those
7902 dependencies using the
7903 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7904 variable.
7905 </note>
7906 </para>
7907
7908 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007909 Source plugins are subclasses defined in plugin files.
7910 As shipped, the Yocto Project provides several plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007911 files.
Brad Bishopc342db32019-05-15 21:57:59 -04007912 You can see the source plugin files that ship with the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007913 Yocto Project
7914 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
Brad Bishopc342db32019-05-15 21:57:59 -04007915 Each of these plugin files contains source plugins that
Brad Bishop316dfdd2018-06-25 12:45:53 -04007916 are designed to populate a specific Wic image partition.
7917 </para>
7918
7919 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007920 Source plugins are subclasses of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007921 <filename>SourcePlugin</filename> class, which is
7922 defined in the
7923 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7924 file.
7925 For example, the <filename>BootimgEFIPlugin</filename>
Brad Bishopc342db32019-05-15 21:57:59 -04007926 source plugin found in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007927 <filename>bootimg-efi.py</filename> file is a subclass of
7928 the <filename>SourcePlugin</filename> class, which is found
7929 in the <filename>pluginbase.py</filename> file.
7930 </para>
7931
7932 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007933 You can also implement source plugins in a layer outside
Brad Bishop316dfdd2018-06-25 12:45:53 -04007934 of the Source Repositories (external layer).
Brad Bishopc342db32019-05-15 21:57:59 -04007935 To do so, be sure that your plugin files are located in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007936 a directory whose path is
7937 <filename>scripts/lib/wic/plugins/source/</filename>
7938 within your external layer.
Brad Bishopc342db32019-05-15 21:57:59 -04007939 When the plugin files are located there, the source
7940 plugins they contain are made available to Wic.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007941 </para>
7942
7943 <para>
7944 When the Wic implementation needs to invoke a
Brad Bishopc342db32019-05-15 21:57:59 -04007945 partition-specific implementation, it looks for the plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007946 with the same name as the <filename>--source</filename>
7947 parameter used in the kickstart file given to that
7948 partition.
7949 For example, if the partition is set up using the following
7950 command in a kickstart file:
7951 <literallayout class='monospaced'>
7952 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7953 </literallayout>
7954 The methods defined as class members of the matching
Brad Bishopc342db32019-05-15 21:57:59 -04007955 source plugin (i.e. <filename>bootimg-pcbios</filename>)
7956 in the <filename>bootimg-pcbios.py</filename> plugin file
Brad Bishop316dfdd2018-06-25 12:45:53 -04007957 are used.
7958 </para>
7959
7960 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007961 To be more concrete, here is the corresponding plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007962 definition from the <filename>bootimg-pcbios.py</filename>
7963 file for the previous command along with an example
7964 method called by the Wic implementation when it needs to
7965 prepare a partition using an implementation-specific
7966 function:
7967 <literallayout class='monospaced'>
7968 .
7969 .
7970 .
7971 class BootimgPcbiosPlugin(SourcePlugin):
7972 """
7973 Create MBR boot partition and install syslinux on it.
7974 """
7975
7976 name = 'bootimg-pcbios'
7977 .
7978 .
7979 .
7980 @classmethod
7981 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7982 oe_builddir, bootimg_dir, kernel_dir,
7983 rootfs_dir, native_sysroot):
7984 """
7985 Called to do the actual content population for a partition i.e. it
7986 'prepares' the partition to be incorporated into the image.
7987 In this case, prepare content for legacy bios boot partition.
7988 """
7989 .
7990 .
7991 .
7992 </literallayout>
Brad Bishopc342db32019-05-15 21:57:59 -04007993 If a subclass (plugin) itself does not implement a
Brad Bishop316dfdd2018-06-25 12:45:53 -04007994 particular function, Wic locates and uses the default
7995 version in the superclass.
Brad Bishopc342db32019-05-15 21:57:59 -04007996 It is for this reason that all source plugins are derived
Brad Bishop316dfdd2018-06-25 12:45:53 -04007997 from the <filename>SourcePlugin</filename> class.
7998 </para>
7999
8000 <para>
8001 The <filename>SourcePlugin</filename> class defined in
8002 the <filename>pluginbase.py</filename> file defines
Brad Bishopc342db32019-05-15 21:57:59 -04008003 a set of methods that source plugins can implement or
Brad Bishop316dfdd2018-06-25 12:45:53 -04008004 override.
Brad Bishopc342db32019-05-15 21:57:59 -04008005 Any plugins (subclass of
Brad Bishop316dfdd2018-06-25 12:45:53 -04008006 <filename>SourcePlugin</filename>) that do not implement
8007 a particular method inherit the implementation of the
8008 method from the <filename>SourcePlugin</filename> class.
8009 For more information, see the
8010 <filename>SourcePlugin</filename> class in the
8011 <filename>pluginbase.py</filename> file for details:
8012 </para>
8013
8014 <para>
8015 The following list describes the methods implemented in the
8016 <filename>SourcePlugin</filename> class:
8017 <itemizedlist>
8018 <listitem><para>
8019 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
8020 Called to populate a partition with actual content.
8021 In other words, the method prepares the final
8022 partition image that is incorporated into the
8023 disk image.
8024 </para></listitem>
8025 <listitem><para>
8026 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
8027 Called before
8028 <filename>do_prepare_partition()</filename> to
8029 create custom configuration files for a partition
8030 (e.g. syslinux or grub configuration files).
8031 </para></listitem>
8032 <listitem><para>
8033 <emphasis><filename>do_install_disk()</filename>:</emphasis>
8034 Called after all partitions have been prepared and
8035 assembled into a disk image.
8036 This method provides a hook to allow finalization
8037 of a disk image (e.g. writing an MBR).
8038 </para></listitem>
8039 <listitem><para>
8040 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
8041 Special content-staging hook called before
8042 <filename>do_prepare_partition()</filename>.
8043 This method is normally empty.</para>
8044
8045 <para>Typically, a partition just uses the passed-in
8046 parameters (e.g. the unmodified value of
8047 <filename>bootimg_dir</filename>).
8048 However, in some cases, things might need to be
8049 more tailored.
8050 As an example, certain files might additionally
8051 need to be taken from
8052 <filename>bootimg_dir + /boot</filename>.
8053 This hook allows those files to be staged in a
8054 customized fashion.
8055 <note>
8056 <filename>get_bitbake_var()</filename>
8057 allows you to access non-standard variables
8058 that you might want to use for this
8059 behavior.
8060 </note>
8061 </para></listitem>
8062 </itemizedlist>
8063 </para>
8064
8065 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04008066 You can extend the source plugin mechanism.
8067 To add more hooks, create more source plugin methods
Brad Bishop316dfdd2018-06-25 12:45:53 -04008068 within <filename>SourcePlugin</filename> and the
8069 corresponding derived subclasses.
Brad Bishopc342db32019-05-15 21:57:59 -04008070 The code that calls the plugin methods uses the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008071 <filename>plugin.get_source_plugin_methods()</filename>
8072 function to find the method or methods needed by the call.
8073 Retrieval of those methods is accomplished by filling up
8074 a dict with keys that contain the method names of interest.
8075 On success, these will be filled in with the actual
8076 methods.
8077 See the Wic implementation for examples and details.
8078 </para>
8079 </section>
8080
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008081 <section id='wic-usage-examples'>
8082 <title>Examples</title>
8083
8084 <para>
8085 This section provides several examples that show how to use
8086 the Wic utility.
8087 All the examples assume the list of requirements in the
8088 "<link linkend='wic-requirements'>Requirements</link>"
8089 section have been met.
8090 The examples assume the previously generated image is
8091 <filename>core-image-minimal</filename>.
8092 </para>
8093
8094 <section id='generate-an-image-using-a-provided-kickstart-file'>
8095 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008096
8097 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008098 This example runs in Cooked Mode and uses the
8099 <filename>mkefidisk</filename> kickstart file:
8100 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008101 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008102 INFO: Building wic-tools...
8103 .
8104 .
8105 .
8106 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008107 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008108
8109 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008110 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8111 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8112 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8113 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 -05008114
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008115 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008116 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008117 </literallayout>
8118 The previous example shows the easiest way to create
8119 an image by running in cooked mode and supplying
8120 a kickstart file and the "-e" option to point to the
8121 existing build artifacts.
8122 Your <filename>local.conf</filename> file needs to have
8123 the
8124 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8125 variable set to the machine you are using, which is
8126 "qemux86" in this example.
8127 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008128
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008129 <para>
8130 Once the image builds, the output provides image
8131 location, artifact use, and kickstart file information.
8132 <note>
8133 You should always verify the details provided in the
8134 output to make sure that the image was indeed
8135 created exactly as expected.
8136 </note>
8137 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008138
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008139 <para>
8140 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008141 image from the Build Directory onto a USB stick, or
8142 whatever media for which you built your image, and boot
8143 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008144 You can write the image by using
8145 <filename>bmaptool</filename> or
8146 <filename>dd</filename>:
8147 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008148 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008149 </literallayout>
8150 or
8151 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008152 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008153 </literallayout>
8154 <note>
8155 For more information on how to use the
8156 <filename>bmaptool</filename> to flash a device
8157 with an image, see the
8158 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
8159 section.
8160 </note>
8161 </para>
8162 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008163
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008164 <section id='using-a-modified-kickstart-file'>
8165 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008166
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008167 <para>
8168 Because partitioned image creation is driven by the
8169 kickstart file, it is easy to affect image creation by
8170 changing the parameters in the file.
8171 This next example demonstrates that through modification
8172 of the <filename>directdisk-gpt</filename> kickstart
8173 file.
8174 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008175
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008176 <para>
8177 As mentioned earlier, you can use the command
8178 <filename>wic list images</filename> to show the list
8179 of existing kickstart files.
8180 The directory in which the
8181 <filename>directdisk-gpt.wks</filename> file resides is
8182 <filename>scripts/lib/image/canned-wks/</filename>,
8183 which is located in the
8184 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
8185 (e.g. <filename>poky</filename>).
8186 Because available files reside in this directory,
8187 you can create and add your own custom files to the
8188 directory.
8189 Subsequent use of the
8190 <filename>wic list images</filename> command would then
8191 include your kickstart files.
8192 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008193
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008194 <para>
8195 In this example, the existing
8196 <filename>directdisk-gpt</filename> file already does
8197 most of what is needed.
8198 However, for the hardware in this example, the image
8199 will need to boot from <filename>sdb</filename> instead
8200 of <filename>sda</filename>, which is what the
8201 <filename>directdisk-gpt</filename> kickstart file
8202 uses.
8203 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008204
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008205 <para>
8206 The example begins by making a copy of the
8207 <filename>directdisk-gpt.wks</filename> file in the
8208 <filename>scripts/lib/image/canned-wks</filename>
8209 directory and then by changing the lines that specify
8210 the target disk from which to boot.
8211 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008212 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
8213 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008214 </literallayout>
8215 Next, the example modifies the
8216 <filename>directdisksdb-gpt.wks</filename> file and
8217 changes all instances of
8218 "<filename>--ondisk sda</filename>" to
8219 "<filename>--ondisk sdb</filename>".
8220 The example changes the following two lines and leaves
8221 the remaining lines untouched:
8222 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008223 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008224 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
8225 </literallayout>
8226 Once the lines are changed, the example generates the
8227 <filename>directdisksdb-gpt</filename> image.
8228 The command points the process at the
8229 <filename>core-image-minimal</filename> artifacts for
8230 the Next Unit of Computing (nuc)
8231 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8232 the <filename>local.conf</filename>.
8233 <literallayout class='monospaced'>
8234 $ wic create directdisksdb-gpt -e core-image-minimal
8235 INFO: Building wic-tools...
8236 .
8237 .
8238 .
8239 Initialising tasks: 100% |#######################################| Time: 0:00:01
8240 NOTE: Executing SetScene Tasks
8241 NOTE: Executing RunQueue Tasks
8242 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
8243 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008244
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008245 INFO: The new image(s) can be found here:
8246 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008247
8248 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008249 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8250 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8251 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8252 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 -05008253
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008254 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008255 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008256 </literallayout>
8257 Continuing with the example, you can now directly
8258 <filename>dd</filename> the image to a USB stick, or
8259 whatever media for which you built your image,
8260 and boot the resulting media:
8261 <literallayout class='monospaced'>
8262 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8263 140966+0 records in
8264 140966+0 records out
8265 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8266 $ sudo eject /dev/sdb
8267 </literallayout>
8268 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008269 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008270
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008271 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8272 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008273
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008274 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008275 This next example manually specifies each build artifact
8276 (runs in Raw Mode) and uses a modified kickstart file.
8277 The example also uses the <filename>-o</filename> option
8278 to cause Wic to create the output
8279 somewhere other than the default output directory,
8280 which is the current directory:
8281 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008282 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8283 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8284 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8285 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8286 --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 -05008287
8288 INFO: Creating image(s)...
8289
8290 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008291 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008292
8293 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008294 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8295 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8296 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8297 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 -05008298
8299 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008300 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008301 </literallayout>
8302 For this example,
8303 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8304 did not have to be specified in the
8305 <filename>local.conf</filename> file since the
8306 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008307 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008308 </section>
8309
8310 <section id='using-wic-to-manipulate-an-image'>
8311 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008312
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008313 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008314 Wic image manipulation allows you to shorten turnaround
8315 time during image development.
8316 For example, you can use Wic to delete the kernel partition
8317 of a Wic image and then insert a newly built kernel.
8318 This saves you time from having to rebuild the entire image
8319 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008320 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008321 In order to use Wic to manipulate a Wic image as in
8322 this example, your development machine must have the
8323 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008324 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008325 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008326
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008327 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008328 The following example examines the contents of the Wic
8329 image, deletes the existing kernel, and then inserts a
8330 new kernel:
8331 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008332 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008333 <emphasis>List the Partitions:</emphasis>
8334 Use the <filename>wic ls</filename> command to list
8335 all the partitions in the Wic image:
8336 <literallayout class='monospaced'>
8337 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8338 Num Start End Size Fstype
8339 1 1048576 25041919 23993344 fat16
8340 2 25165824 72157183 46991360 ext4
8341 </literallayout>
8342 The previous output shows two partitions in the
8343 <filename>core-image-minimal-qemux86.wic</filename>
8344 image.
8345 </para></listitem>
8346 <listitem><para>
8347 <emphasis>Examine a Particular Partition:</emphasis>
8348 Use the <filename>wic ls</filename> command again
8349 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008350 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008351 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008352 You can get command usage on any Wic command
8353 using the following form:
8354 <literallayout class='monospaced'>
8355 $ wic help <replaceable>command</replaceable>
8356 </literallayout>
8357 For example, the following command shows you
8358 the various ways to use the
8359 <filename>wic ls</filename> command:
8360 <literallayout class='monospaced'>
8361 $ wic help ls
8362 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008363 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008364 The following command shows what is in Partition
8365 one:
8366 <literallayout class='monospaced'>
8367 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8368 Volume in drive : is boot
8369 Volume Serial Number is E894-1809
8370 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008371
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008372 libcom32 c32 186500 2017-10-09 16:06
8373 libutil c32 24148 2017-10-09 16:06
8374 syslinux cfg 220 2017-10-09 16:06
8375 vesamenu c32 27104 2017-10-09 16:06
8376 vmlinuz 6904608 2017-10-09 16:06
8377 5 files 7 142 580 bytes
8378 16 582 656 bytes free
8379 </literallayout>
8380 The previous output shows five files, with the
8381 <filename>vmlinuz</filename> being the kernel.
8382 <note>
8383 If you see the following error, you need to
8384 update or create a
8385 <filename>~/.mtoolsrc</filename> file and
8386 be sure to have the line “mtools_skip_check=1“
8387 in the file.
8388 Then, run the Wic command again:
8389 <literallayout class='monospaced'>
8390 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8391 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8392 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8393 </literallayout>
8394 </note>
8395 </para></listitem>
8396 <listitem><para>
8397 <emphasis>Remove the Old Kernel:</emphasis>
8398 Use the <filename>wic rm</filename> command to
8399 remove the <filename>vmlinuz</filename> file
8400 (kernel):
8401 <literallayout class='monospaced'>
8402 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8403 </literallayout>
8404 </para></listitem>
8405 <listitem><para>
8406 <emphasis>Add In the New Kernel:</emphasis>
8407 Use the <filename>wic cp</filename> command to
8408 add the updated kernel to the Wic image.
8409 Depending on how you built your kernel, it could
8410 be in different places.
8411 If you used <filename>devtool</filename> and
8412 an SDK to build your kernel, it resides in the
8413 <filename>tmp/work</filename> directory of the
8414 extensible SDK.
8415 If you used <filename>make</filename> to build the
8416 kernel, the kernel will be in the
8417 <filename>workspace/sources</filename> area.
8418 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008419
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008420 <para>The following example assumes
8421 <filename>devtool</filename> was used to build
8422 the kernel:
8423 <literallayout class='monospaced'>
8424 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 \
8425 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8426 </literallayout>
8427 Once the new kernel is added back into the image,
8428 you can use the <filename>dd</filename>
8429 command or
8430 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8431 to flash your wic image onto an SD card
8432 or USB stick and test your target.
8433 <note>
8434 Using <filename>bmaptool</filename> is
8435 generally 10 to 20 times faster than using
8436 <filename>dd</filename>.
8437 </note>
8438 </para></listitem>
8439 </orderedlist>
8440 </para>
8441 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008442 </section>
8443 </section>
8444
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008445 <section id='flashing-images-using-bmaptool'>
8446 <title>Flashing Images Using <filename>bmaptool</filename></title>
8447
8448 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008449 A fast and easy way to flash an image to a bootable device
8450 is to use Bmaptool, which is integrated into the OpenEmbedded
8451 build system.
8452 Bmaptool is a generic tool that creates a file's block map (bmap)
8453 and then uses that map to copy the file.
8454 As compared to traditional tools such as dd or cp, Bmaptool
8455 can copy (or flash) large files like raw system image files
8456 much faster.
8457 <note><title>Notes</title>
8458 <itemizedlist>
8459 <listitem><para>
8460 If you are using Ubuntu or Debian distributions, you
8461 can install the <filename>bmap-tools</filename> package
8462 using the following command and then use the tool
8463 without specifying <filename>PATH</filename> even from
8464 the root account:
8465 <literallayout class='monospaced'>
8466 $ sudo apt-get install bmap-tools
8467 </literallayout>
8468 </para></listitem>
8469 <listitem><para>
8470 If you are unable to install the
8471 <filename>bmap-tools</filename> package, you will
8472 need to build Bmaptool before using it.
8473 Use the following command:
8474 <literallayout class='monospaced'>
8475 $ bitbake bmap-tools-native
8476 </literallayout>
8477 </para></listitem>
8478 </itemizedlist>
8479 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008480 </para>
8481
8482 <para>
8483 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008484 Realize that while this example uses a Wic image, you can use
8485 Bmaptool to flash any type of image.
8486 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008487 <orderedlist>
8488 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008489 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8490 You need to have the following set in your
8491 <filename>local.conf</filename> file before building
8492 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008493 <literallayout class='monospaced'>
8494 IMAGE_FSTYPES += "wic wic.bmap"
8495 </literallayout>
8496 </para></listitem>
8497 <listitem><para>
8498 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008499 Either have your image ready (pre-built with the
8500 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8501 setting previously mentioned) or take the step to build
8502 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008503 <literallayout class='monospaced'>
8504 $ bitbake <replaceable>image</replaceable>
8505 </literallayout>
8506 </para></listitem>
8507 <listitem><para>
8508 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008509 Flash the device with the image by using Bmaptool
8510 depending on your particular setup.
8511 The following commands assume the image resides in the
8512 Build Directory's <filename>deploy/images/</filename>
8513 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008514 <itemizedlist>
8515 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008516 If you have write access to the media, use this
8517 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008518 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008519 $ 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 -05008520 </literallayout>
8521 </para></listitem>
8522 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008523 If you do not have write access to the media, set
8524 your permissions first and then use the same
8525 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008526 <literallayout class='monospaced'>
8527 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008528 $ 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 -05008529 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008530 </para></listitem>
8531 </itemizedlist>
8532 </para></listitem>
8533 </orderedlist>
8534 </para>
8535
8536 <para>
8537 For help on the <filename>bmaptool</filename> command, use the
8538 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008539 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008540 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008541 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008542 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008543 </section>
8544
8545 <section id='making-images-more-secure'>
8546 <title>Making Images More Secure</title>
8547
8548 <para>
8549 Security is of increasing concern for embedded devices.
8550 Consider the issues and problems discussed in just this
8551 sampling of work found across the Internet:
8552 <itemizedlist>
8553 <listitem><para><emphasis>
8554 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8555 by Bruce Schneier
8556 </para></listitem>
8557 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008558 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008559 by Carna Botnet</para></listitem>
8560 <listitem><para><emphasis>
8561 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8562 by Jake Edge
8563 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008564 </itemizedlist>
8565 </para>
8566
8567 <para>
8568 When securing your image is of concern, there are steps, tools,
8569 and variables that you can consider to help you reach the
8570 security goals you need for your particular device.
8571 Not all situations are identical when it comes to making an
8572 image secure.
8573 Consequently, this section provides some guidance and suggestions
8574 for consideration when you want to make your image more secure.
8575 <note>
8576 Because the security requirements and risks are
8577 different for every type of device, this section cannot
8578 provide a complete reference on securing your custom OS.
8579 It is strongly recommended that you also consult other sources
8580 of information on embedded Linux system hardening and on
8581 security.
8582 </note>
8583 </para>
8584
8585 <section id='general-considerations'>
8586 <title>General Considerations</title>
8587
8588 <para>
8589 General considerations exist that help you create more
8590 secure images.
8591 You should consider the following suggestions to help
8592 make your device more secure:
8593 <itemizedlist>
8594 <listitem><para>
8595 Scan additional code you are adding to the system
8596 (e.g. application code) by using static analysis
8597 tools.
8598 Look for buffer overflows and other potential
8599 security problems.
8600 </para></listitem>
8601 <listitem><para>
8602 Pay particular attention to the security for
8603 any web-based administration interface.
8604 </para>
8605 <para>Web interfaces typically need to perform
8606 administrative functions and tend to need to run with
8607 elevated privileges.
8608 Thus, the consequences resulting from the interface's
8609 security becoming compromised can be serious.
8610 Look for common web vulnerabilities such as
8611 cross-site-scripting (XSS), unvalidated inputs,
8612 and so forth.</para>
8613 <para>As with system passwords, the default credentials
8614 for accessing a web-based interface should not be the
8615 same across all devices.
8616 This is particularly true if the interface is enabled
8617 by default as it can be assumed that many end-users
8618 will not change the credentials.
8619 </para></listitem>
8620 <listitem><para>
8621 Ensure you can update the software on the device to
8622 mitigate vulnerabilities discovered in the future.
8623 This consideration especially applies when your
8624 device is network-enabled.
8625 </para></listitem>
8626 <listitem><para>
8627 Ensure you remove or disable debugging functionality
8628 before producing the final image.
8629 For information on how to do this, see the
8630 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8631 section.
8632 </para></listitem>
8633 <listitem><para>
8634 Ensure you have no network services listening that
8635 are not needed.
8636 </para></listitem>
8637 <listitem><para>
8638 Remove any software from the image that is not needed.
8639 </para></listitem>
8640 <listitem><para>
8641 Enable hardware support for secure boot functionality
8642 when your device supports this functionality.
8643 </para></listitem>
8644 </itemizedlist>
8645 </para>
8646 </section>
8647
8648 <section id='security-flags'>
8649 <title>Security Flags</title>
8650
8651 <para>
8652 The Yocto Project has security flags that you can enable that
8653 help make your build output more secure.
8654 The security flags are in the
8655 <filename>meta/conf/distro/include/security_flags.inc</filename>
8656 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008657 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008658 (e.g. <filename>poky</filename>).
8659 <note>
8660 Depending on the recipe, certain security flags are enabled
8661 and disabled by default.
8662 </note>
8663 </para>
8664
8665 <para>
8666<!--
8667 The GCC/LD flags in <filename>security_flags.inc</filename>
8668 enable more secure code generation.
8669 By including the <filename>security_flags.inc</filename>
8670 file, you enable flags to the compiler and linker that cause
8671 them to generate more secure code.
8672 <note>
8673 The GCC/LD flags are enabled by default in the
8674 <filename>poky-lsb</filename> distribution.
8675 </note>
8676-->
8677 Use the following line in your
8678 <filename>local.conf</filename> file or in your custom
8679 distribution configuration file to enable the security
8680 compiler and linker flags for your build:
8681 <literallayout class='monospaced'>
8682 require conf/distro/include/security_flags.inc
8683 </literallayout>
8684 </para>
8685 </section>
8686
8687 <section id='considerations-specific-to-the-openembedded-build-system'>
8688 <title>Considerations Specific to the OpenEmbedded Build System</title>
8689
8690 <para>
8691 You can take some steps that are specific to the
8692 OpenEmbedded build system to make your images more secure:
8693 <itemizedlist>
8694 <listitem><para>
8695 Ensure "debug-tweaks" is not one of your selected
8696 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8697 When creating a new project, the default is to provide you
8698 with an initial <filename>local.conf</filename> file that
8699 enables this feature using the
8700 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8701 <literallayout class='monospaced'>
8702 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8703 </literallayout>
8704 To disable that feature, simply comment out that line in your
8705 <filename>local.conf</filename> file, or
8706 make sure <filename>IMAGE_FEATURES</filename> does not contain
8707 "debug-tweaks" before producing your final image.
8708 Among other things, leaving this in place sets the
8709 root password as blank, which makes logging in for
8710 debugging or inspection easy during
8711 development but also means anyone can easily log in
8712 during production.
8713 </para></listitem>
8714 <listitem><para>
8715 It is possible to set a root password for the image
8716 and also to set passwords for any extra users you might
8717 add (e.g. administrative or service type users).
8718 When you set up passwords for multiple images or
8719 users, you should not duplicate passwords.
8720 </para>
8721 <para>
8722 To set up passwords, use the
8723 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8724 class, which is the preferred method.
8725 For an example on how to set up both root and user
8726 passwords, see the
8727 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8728 section.
8729 <note>
8730 When adding extra user accounts or setting a
8731 root password, be cautious about setting the
8732 same password on every device.
8733 If you do this, and the password you have set
8734 is exposed, then every device is now potentially
8735 compromised.
8736 If you need this access but want to ensure
8737 security, consider setting a different,
8738 random password for each device.
8739 Typically, you do this as a separate step after
8740 you deploy the image onto the device.
8741 </note>
8742 </para></listitem>
8743 <listitem><para>
8744 Consider enabling a Mandatory Access Control (MAC)
8745 framework such as SMACK or SELinux and tuning it
8746 appropriately for your device's usage.
8747 You can find more information in the
8748 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8749 layer.
8750 </para></listitem>
8751 </itemizedlist>
8752 </para>
8753
8754 <para>
8755 </para>
8756 </section>
8757
8758 <section id='tools-for-hardening-your-image'>
8759 <title>Tools for Hardening Your Image</title>
8760
8761 <para>
8762 The Yocto Project provides tools for making your image
8763 more secure.
8764 You can find these tools in the
8765 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008766 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008767 </para>
8768 </section>
8769 </section>
8770
8771 <section id='creating-your-own-distribution'>
8772 <title>Creating Your Own Distribution</title>
8773
8774 <para>
8775 When you build an image using the Yocto Project and
8776 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008777 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8778 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008779 If you wish to gain more control over package alternative
8780 selections, compile-time options, and other low-level
8781 configurations, you can create your own distribution.
8782 </para>
8783
8784 <para>
8785 To create your own distribution, the basic steps consist of
8786 creating your own distribution layer, creating your own
8787 distribution configuration file, and then adding any needed
8788 code and Metadata to the layer.
8789 The following steps provide some more detail:
8790 <itemizedlist>
8791 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8792 Create your distribution layer so that you can keep your
8793 Metadata and code for the distribution separate.
8794 It is strongly recommended that you create and use your own
8795 layer for configuration and code.
8796 Using your own layer as compared to just placing
8797 configurations in a <filename>local.conf</filename>
8798 configuration file makes it easier to reproduce the same
8799 build configuration when using multiple build machines.
8800 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008801 "<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 -05008802 section for information on how to quickly set up a layer.
8803 </para></listitem>
8804 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8805 The distribution configuration file needs to be created in
8806 the <filename>conf/distro</filename> directory of your
8807 layer.
8808 You need to name it using your distribution name
8809 (e.g. <filename>mydistro.conf</filename>).
8810 <note>
8811 The
8812 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8813 variable in your
8814 <filename>local.conf</filename> file determines the
8815 name of your distribution.
8816 </note></para>
8817 <para>You can split out parts of your configuration file
8818 into include files and then "require" them from within
8819 your distribution configuration file.
8820 Be sure to place the include files in the
8821 <filename>conf/distro/include</filename> directory of
8822 your layer.
8823 A common example usage of include files would be to
8824 separate out the selection of desired version and revisions
8825 for individual recipes.
8826</para>
8827 <para>Your configuration file needs to set the following
8828 required variables:
8829 <literallayout class='monospaced'>
8830 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8831 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8832 </literallayout>
8833 These following variables are optional and you typically
8834 set them from the distribution configuration file:
8835 <literallayout class='monospaced'>
8836 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8837 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8838 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8839 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8840 </literallayout>
8841 <tip>
8842 If you want to base your distribution configuration file
8843 on the very basic configuration from OE-Core, you
8844 can use
8845 <filename>conf/distro/defaultsetup.conf</filename> as
8846 a reference and just include variables that differ
8847 as compared to <filename>defaultsetup.conf</filename>.
8848 Alternatively, you can create a distribution
8849 configuration file from scratch using the
8850 <filename>defaultsetup.conf</filename> file
8851 or configuration files from other distributions
8852 such as Poky or Angstrom as references.
8853 </tip></para></listitem>
8854 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8855 Be sure to define any other variables for which you want to
8856 create a default or enforce as part of the distribution
8857 configuration.
8858 You can include nearly any variable from the
8859 <filename>local.conf</filename> file.
8860 The variables you use are not limited to the list in the
8861 previous bulleted item.</para></listitem>
8862 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8863 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008864 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008865 set your
8866 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8867 variable to point to your distribution's configuration file.
8868 For example, if your distribution's configuration file is
8869 named <filename>mydistro.conf</filename>, then you point
8870 to it as follows:
8871 <literallayout class='monospaced'>
8872 DISTRO = "mydistro"
8873 </literallayout></para></listitem>
8874 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8875 Use your layer to hold other information needed for the
8876 distribution:
8877 <itemizedlist>
8878 <listitem><para>Add recipes for installing
8879 distro-specific configuration files that are not
8880 already installed by another recipe.
8881 If you have distro-specific configuration files
8882 that are included by an existing recipe, you should
8883 add an append file (<filename>.bbappend</filename>)
8884 for those.
8885 For general information and recommendations
8886 on how to add recipes to your layer, see the
8887 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8888 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008889 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008890 sections.</para></listitem>
8891 <listitem><para>Add any image recipes that are specific
8892 to your distribution.</para></listitem>
8893 <listitem><para>Add a <filename>psplash</filename>
8894 append file for a branded splash screen.
8895 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008896 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008897 section.</para></listitem>
8898 <listitem><para>Add any other append files to make
8899 custom changes that are specific to individual
8900 recipes.</para></listitem>
8901 </itemizedlist></para></listitem>
8902 </itemizedlist>
8903 </para>
8904 </section>
8905
8906 <section id='creating-a-custom-template-configuration-directory'>
8907 <title>Creating a Custom Template Configuration Directory</title>
8908
8909 <para>
8910 If you are producing your own customized version
8911 of the build system for use by other users, you might
8912 want to customize the message shown by the setup script or
8913 you might want to change the template configuration files (i.e.
8914 <filename>local.conf</filename> and
8915 <filename>bblayers.conf</filename>) that are created in
8916 a new build directory.
8917 </para>
8918
8919 <para>
8920 The OpenEmbedded build system uses the environment variable
8921 <filename>TEMPLATECONF</filename> to locate the directory
8922 from which it gathers configuration information that ultimately
8923 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008924 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008925 <filename>conf</filename> directory.
8926 By default, <filename>TEMPLATECONF</filename> is set as
8927 follows in the <filename>poky</filename> repository:
8928 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008929 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008930 </literallayout>
8931 This is the directory used by the build system to find templates
8932 from which to build some key configuration files.
8933 If you look at this directory, you will see the
8934 <filename>bblayers.conf.sample</filename>,
8935 <filename>local.conf.sample</filename>, and
8936 <filename>conf-notes.txt</filename> files.
8937 The build system uses these files to form the respective
8938 <filename>bblayers.conf</filename> file,
8939 <filename>local.conf</filename> file, and display the list of
8940 BitBake targets when running the setup script.
8941 </para>
8942
8943 <para>
8944 To override these default configuration files with
8945 configurations you want used within every new
8946 Build Directory, simply set the
8947 <filename>TEMPLATECONF</filename> variable to your directory.
8948 The <filename>TEMPLATECONF</filename> variable is set in the
8949 <filename>.templateconf</filename> file, which is in the
8950 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008951 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008952 folder (e.g. <filename>poky</filename>).
8953 Edit the <filename>.templateconf</filename> so that it can locate
8954 your directory.
8955 </para>
8956
8957 <para>
8958 Best practices dictate that you should keep your
8959 template configuration directory in your custom distribution layer.
8960 For example, suppose you have a layer named
8961 <filename>meta-mylayer</filename> located in your home directory
8962 and you want your template configuration directory named
8963 <filename>myconf</filename>.
8964 Changing the <filename>.templateconf</filename> as follows
8965 causes the OpenEmbedded build system to look in your directory
8966 and base its configuration files on the
8967 <filename>*.sample</filename> configuration files it finds.
8968 The final configuration files (i.e.
8969 <filename>local.conf</filename> and
8970 <filename>bblayers.conf</filename> ultimately still end up in
8971 your Build Directory, but they are based on your
8972 <filename>*.sample</filename> files.
8973 <literallayout class='monospaced'>
8974 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8975 </literallayout>
8976 </para>
8977
8978 <para>
8979 Aside from the <filename>*.sample</filename> configuration files,
8980 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008981 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008982 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008983 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008984 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8985 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008986 output.
8987 Customizing this <filename>conf-notes.txt</filename> file is a
8988 good way to make sure your list of custom targets appears
8989 as part of the script's output.
8990 </para>
8991
8992 <para>
8993 Here is the default list of targets displayed as a result of
8994 running either of the setup scripts:
8995 <literallayout class='monospaced'>
8996 You can now run 'bitbake &lt;target&gt;'
8997
8998 Common targets are:
8999 core-image-minimal
9000 core-image-sato
9001 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009002 meta-ide-support
9003 </literallayout>
9004 </para>
9005
9006 <para>
9007 Changing the listed common targets is as easy as editing your
9008 version of <filename>conf-notes.txt</filename> in your
9009 custom template configuration directory and making sure you
9010 have <filename>TEMPLATECONF</filename> set to your directory.
9011 </para>
9012 </section>
9013
Brad Bishop316dfdd2018-06-25 12:45:53 -04009014 <section id='dev-saving-memory-during-a-build'>
9015 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009016
9017 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009018 To help conserve disk space during builds, you can add the
9019 following statement to your project's
9020 <filename>local.conf</filename> configuration file found in the
9021 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
9022 <literallayout class='monospaced'>
9023 INHERIT += "rm_work"
9024 </literallayout>
9025 Adding this statement deletes the work directory used for building
9026 a recipe once the recipe is built.
9027 For more information on "rm_work", see the
9028 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
9029 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009030 </para>
9031 </section>
9032
9033 <section id='working-with-packages'>
9034 <title>Working with Packages</title>
9035
9036 <para>
9037 This section describes a few tasks that involve packages:
9038 <itemizedlist>
9039 <listitem><para>
9040 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
9041 </para></listitem>
9042 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009043 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009044 </para></listitem>
9045 <listitem><para>
9046 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
9047 </para></listitem>
9048 <listitem><para>
Brad Bishop15ae2502019-06-18 21:44:24 -04009049 <link linkend='using-runtime-package-management'>Using runtime package management</link>
9050 </para></listitem>
9051 <listitem><para>
9052 <link linkend='generating-and-using-signed-packages'>Generating and using signed packages</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009053 </para></listitem>
9054 <listitem><para>
9055 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
9056 </para></listitem>
Brad Bishop15ae2502019-06-18 21:44:24 -04009057 <listitem><para>
9058 <link linkend='creating-node-package-manager-npm-packages'>Creating node package manager (NPM) packages</link>
9059 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009060 </itemizedlist>
9061 </para>
9062
9063 <section id='excluding-packages-from-an-image'>
9064 <title>Excluding Packages from an Image</title>
9065
9066 <para>
9067 You might find it necessary to prevent specific packages
9068 from being installed into an image.
9069 If so, you can use several variables to direct the build
9070 system to essentially ignore installing recommended packages
9071 or to not install a package at all.
9072 </para>
9073
9074 <para>
9075 The following list introduces variables you can use to
9076 prevent packages from being installed into your image.
9077 Each of these variables only works with IPK and RPM
9078 package types.
9079 Support for Debian packages does not exist.
9080 Also, you can use these variables from your
9081 <filename>local.conf</filename> file or attach them to a
9082 specific image recipe by using a recipe name override.
9083 For more detail on the variables, see the descriptions in the
9084 Yocto Project Reference Manual's glossary chapter.
9085 <itemizedlist>
9086 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
9087 Use this variable to specify "recommended-only"
9088 packages that you do not want installed.
9089 </para></listitem>
9090 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
9091 Use this variable to prevent all "recommended-only"
9092 packages from being installed.
9093 </para></listitem>
9094 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
9095 Use this variable to prevent specific packages from
9096 being installed regardless of whether they are
9097 "recommended-only" or not.
9098 You need to realize that the build process could
9099 fail with an error when you
9100 prevent the installation of a package whose presence
9101 is required by an installed package.
9102 </para></listitem>
9103 </itemizedlist>
9104 </para>
9105 </section>
9106
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009107 <section id='incrementing-a-binary-package-version'>
9108 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009109
9110 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009111 This section provides some background on how binary package
9112 versioning is accomplished and presents some of the services,
9113 variables, and terminology involved.
9114 </para>
9115
9116 <para>
9117 In order to understand binary package versioning, you need
9118 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009119 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009120 <listitem><para>
9121 Binary Package: The binary package that is eventually
9122 built and installed into an image.
9123 </para></listitem>
9124 <listitem><para>
9125 Binary Package Version: The binary package version
9126 is composed of two components - a version and a
9127 revision.
9128 <note>
9129 Technically, a third component, the "epoch" (i.e.
9130 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
9131 is involved but this discussion for the most part
9132 ignores <filename>PE</filename>.
9133 </note>
9134 The version and revision are taken from the
9135 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
9136 and
9137 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9138 variables, respectively.
9139 </para></listitem>
9140 <listitem><para>
9141 <filename>PV</filename>: The recipe version.
9142 <filename>PV</filename> represents the version of the
9143 software being packaged.
9144 Do not confuse <filename>PV</filename> with the
9145 binary package version.
9146 </para></listitem>
9147 <listitem><para>
9148 <filename>PR</filename>: The recipe revision.
9149 </para></listitem>
9150 <listitem><para>
9151 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
9152 The OpenEmbedded build system uses this string
9153 to help define the value of <filename>PV</filename>
9154 when the source code revision needs to be included
9155 in it.
9156 </para></listitem>
9157 <listitem><para>
9158 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
9159 A network-based service that helps automate keeping
9160 package feeds compatible with existing package
9161 manager applications such as RPM, APT, and OPKG.
9162 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009163 </itemizedlist>
9164 </para>
9165
9166 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009167 Whenever the binary package content changes, the binary package
9168 version must change.
9169 Changing the binary package version is accomplished by changing
9170 or "bumping" the <filename>PR</filename> and/or
9171 <filename>PV</filename> values.
9172 Increasing these values occurs one of two ways:
9173 <itemizedlist>
9174 <listitem><para>Automatically using a Package Revision
9175 Service (PR Service).
9176 </para></listitem>
9177 <listitem><para>Manually incrementing the
9178 <filename>PR</filename> and/or
9179 <filename>PV</filename> variables.
9180 </para></listitem>
9181 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009182 </para>
9183
9184 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009185 Given a primary challenge of any build system and its users
9186 is how to maintain a package feed that is compatible with
9187 existing package manager applications such as RPM, APT, and
9188 OPKG, using an automated system is much preferred over a
9189 manual system.
9190 In either system, the main requirement is that binary package
9191 version numbering increases in a linear fashion and that a
9192 number of version components exist that support that linear
9193 progression.
9194 For information on how to ensure package revisioning remains
9195 linear, see the
9196 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
9197 section.
9198 </para>
9199
9200 <para>
9201 The following three sections provide related information on the
9202 PR Service, the manual method for "bumping"
9203 <filename>PR</filename> and/or <filename>PV</filename>, and
9204 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009205 </para>
9206
9207 <section id='working-with-a-pr-service'>
9208 <title>Working With a PR Service</title>
9209
9210 <para>
9211 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009212 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009213 is error prone, inaccurate, and causes problems for people
9214 submitting recipes.
9215 Conversely, the PR Service automatically generates
9216 increasing numbers, particularly the revision field,
9217 which removes the human element.
9218 <note>
9219 For additional information on using a PR Service, you
9220 can see the
9221 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
9222 wiki page.
9223 </note>
9224 </para>
9225
9226 <para>
9227 The Yocto Project uses variables in order of
9228 decreasing priority to facilitate revision numbering (i.e.
9229 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
9230 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
9231 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9232 for epoch, version, and revision, respectively).
9233 The values are highly dependent on the policies and
9234 procedures of a given distribution and package feed.
9235 </para>
9236
9237 <para>
9238 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04009239 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009240 which are unique to a given build, the build system
9241 knows when to rebuild packages.
9242 All the inputs into a given task are represented by a
9243 signature, which can trigger a rebuild when different.
9244 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009245 <filename>PR</filename>, <filename>PV</filename>, and
9246 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009247 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009248 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009249 </para>
9250
9251 <para>
9252 The PR Service works with both
9253 <filename>OEBasic</filename> and
9254 <filename>OEBasicHash</filename> generators.
9255 The value of <filename>PR</filename> bumps when the
9256 checksum changes and the different generator mechanisms
9257 change signatures under different circumstances.
9258 </para>
9259
9260 <para>
9261 As implemented, the build system includes values from
9262 the PR Service into the <filename>PR</filename> field as
9263 an addition using the form "<filename>.x</filename>" so
9264 <filename>r0</filename> becomes <filename>r0.1</filename>,
9265 <filename>r0.2</filename> and so forth.
9266 This scheme allows existing <filename>PR</filename> values
9267 to be used for whatever reasons, which include manual
9268 <filename>PR</filename> bumps, should it be necessary.
9269 </para>
9270
9271 <para>
9272 By default, the PR Service is not enabled or running.
9273 Thus, the packages generated are just "self consistent".
9274 The build system adds and removes packages and
9275 there are no guarantees about upgrade paths but images
9276 will be consistent and correct with the latest changes.
9277 </para>
9278
9279 <para>
9280 The simplest form for a PR Service is for it to exist
9281 for a single host development system that builds the
9282 package feed (building system).
9283 For this scenario, you can enable a local PR Service by
9284 setting
9285 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9286 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009287 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009288 <literallayout class='monospaced'>
9289 PRSERV_HOST = "localhost:0"
9290 </literallayout>
9291 Once the service is started, packages will automatically
9292 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009293 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009294 </para>
9295
9296 <para>
9297 If you have a more complex setup where multiple host
9298 development systems work against a common, shared package
9299 feed, you have a single PR Service running and it is
9300 connected to each building system.
9301 For this scenario, you need to start the PR Service using
9302 the <filename>bitbake-prserv</filename> command:
9303 <literallayout class='monospaced'>
9304 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9305 </literallayout>
9306 In addition to hand-starting the service, you need to
9307 update the <filename>local.conf</filename> file of each
9308 building system as described earlier so each system
9309 points to the server and port.
9310 </para>
9311
9312 <para>
9313 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009314 some sanity checks to binary package versions, in
9315 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009316 To enable build history, add the following to each building
9317 system's <filename>local.conf</filename> file:
9318 <literallayout class='monospaced'>
9319 # It is recommended to activate "buildhistory" for testing the PR service
9320 INHERIT += "buildhistory"
9321 BUILDHISTORY_COMMIT = "1"
9322 </literallayout>
9323 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009324 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9325 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009326 </para>
9327
9328 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009329 <para>
9330 The OpenEmbedded build system does not maintain
9331 <filename>PR</filename> information as part of the
9332 shared state (sstate) packages.
9333 If you maintain an sstate feed, its expected that either
9334 all your building systems that contribute to the sstate
9335 feed use a shared PR Service, or you do not run a PR
9336 Service on any of your building systems.
9337 Having some systems use a PR Service while others do
9338 not leads to obvious problems.
9339 </para>
9340
9341 <para>
9342 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009343 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9344 section in the Yocto Project Overview and Concepts
9345 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009346 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009347 </note>
9348 </section>
9349
9350 <section id='manually-bumping-pr'>
9351 <title>Manually Bumping PR</title>
9352
9353 <para>
9354 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009355 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009356 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9357 variable.
9358 </para>
9359
9360 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009361 If a committed change results in changing the package
9362 output, then the value of the PR variable needs to be
9363 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009364 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009365 variable and set its initial value equal to "r0", which is
9366 the default.
9367 Even though the default value is "r0", the practice of
9368 adding it to a new recipe makes it harder to forget to bump
9369 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009370 </para>
9371
9372 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009373 If you are sharing a common <filename>.inc</filename> file
9374 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009375 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009376 variable to ensure that the recipes sharing the
9377 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009378 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009379 The <filename>.inc</filename> file must set
9380 <filename>INC_PR</filename> (initially to "r0"), and all
9381 recipes referring to it should set <filename>PR</filename>
9382 to "${INC_PR}.0" initially, incrementing the last number
9383 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009384 If the <filename>.inc</filename> file is changed then its
9385 <filename>INC_PR</filename> should be incremented.
9386 </para>
9387
9388 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009389 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009390 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9391 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009392 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009393 <filename>INC_PR</filename>).
9394 </para>
9395
9396 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009397 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009398 However, if for some reason <filename>PV</filename> changes
9399 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009400 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9401 variable (Package Epoch).
9402 The <filename>PE</filename> variable defaults to "0".
9403 </para>
9404
9405 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009406 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009407 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9408 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009409 These guidelines define how versions are compared and what
9410 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009411 </para>
9412 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009413
9414 <section id='automatically-incrementing-a-binary-package-revision-number'>
9415 <title>Automatically Incrementing a Package Version Number</title>
9416
9417 <para>
9418 When fetching a repository, BitBake uses the
9419 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9420 variable to determine the specific source code revision
9421 from which to build.
9422 You set the <filename>SRCREV</filename> variable to
9423 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9424 to cause the OpenEmbedded build system to automatically use the
9425 latest revision of the software:
9426 <literallayout class='monospaced'>
9427 SRCREV = "${AUTOREV}"
9428 </literallayout>
9429 </para>
9430
9431 <para>
9432 Furthermore, you need to reference <filename>SRCPV</filename>
9433 in <filename>PV</filename> in order to automatically update
9434 the version whenever the revision of the source code
9435 changes.
9436 Here is an example:
9437 <literallayout class='monospaced'>
9438 PV = "1.0+git${SRCPV}"
9439 </literallayout>
9440 The OpenEmbedded build system substitutes
9441 <filename>SRCPV</filename> with the following:
9442 <literallayout class='monospaced'>
9443 AUTOINC+<replaceable>source_code_revision</replaceable>
9444 </literallayout>
9445 The build system replaces the <filename>AUTOINC</filename> with
9446 a number.
9447 The number used depends on the state of the PR Service:
9448 <itemizedlist>
9449 <listitem><para>
9450 If PR Service is enabled, the build system increments
9451 the number, which is similar to the behavior of
9452 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9453 This behavior results in linearly increasing package
9454 versions, which is desirable.
9455 Here is an example:
9456 <literallayout class='monospaced'>
9457 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9458 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9459 </literallayout>
9460 </para></listitem>
9461 <listitem><para>
9462 If PR Service is not enabled, the build system
9463 replaces the <filename>AUTOINC</filename>
9464 placeholder with zero (i.e. "0").
9465 This results in changing the package version since
9466 the source revision is included.
9467 However, package versions are not increased linearly.
9468 Here is an example:
9469 <literallayout class='monospaced'>
9470 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9471 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9472 </literallayout>
9473 </para></listitem>
9474 </itemizedlist>
9475 </para>
9476
9477 <para>
9478 In summary, the OpenEmbedded build system does not track the
9479 history of binary package versions for this purpose.
9480 <filename>AUTOINC</filename>, in this case, is comparable to
9481 <filename>PR</filename>.
9482 If PR server is not enabled, <filename>AUTOINC</filename>
9483 in the package version is simply replaced by "0".
9484 If PR server is enabled, the build system keeps track of the
9485 package versions and bumps the number when the package
9486 revision changes.
9487 </para>
9488 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009489 </section>
9490
9491 <section id='handling-optional-module-packaging'>
9492 <title>Handling Optional Module Packaging</title>
9493
9494 <para>
9495 Many pieces of software split functionality into optional
Brad Bishopc342db32019-05-15 21:57:59 -04009496 modules (or plugins) and the plugins that are built
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009497 might depend on configuration options.
9498 To avoid having to duplicate the logic that determines what
9499 modules are available in your recipe or to avoid having
9500 to package each module by hand, the OpenEmbedded build system
9501 provides functionality to handle module packaging dynamically.
9502 </para>
9503
9504 <para>
9505 To handle optional module packaging, you need to do two things:
9506 <itemizedlist>
9507 <listitem><para>Ensure the module packaging is actually
9508 done.</para></listitem>
9509 <listitem><para>Ensure that any dependencies on optional
9510 modules from other recipes are satisfied by your recipe.
9511 </para></listitem>
9512 </itemizedlist>
9513 </para>
9514
9515 <section id='making-sure-the-packaging-is-done'>
9516 <title>Making Sure the Packaging is Done</title>
9517
9518 <para>
9519 To ensure the module packaging actually gets done, you use
9520 the <filename>do_split_packages</filename> function within
9521 the <filename>populate_packages</filename> Python function
9522 in your recipe.
9523 The <filename>do_split_packages</filename> function
9524 searches for a pattern of files or directories under a
9525 specified path and creates a package for each one it finds
9526 by appending to the
9527 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9528 variable and setting the appropriate values for
9529 <filename>FILES_packagename</filename>,
9530 <filename>RDEPENDS_packagename</filename>,
9531 <filename>DESCRIPTION_packagename</filename>, and so forth.
9532 Here is an example from the <filename>lighttpd</filename>
9533 recipe:
9534 <literallayout class='monospaced'>
9535 python populate_packages_prepend () {
9536 lighttpd_libdir = d.expand('${libdir}')
9537 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9538 'lighttpd-module-%s', 'Lighttpd module for %s',
9539 extra_depends='')
9540 }
9541 </literallayout>
9542 The previous example specifies a number of things in the
9543 call to <filename>do_split_packages</filename>.
9544 <itemizedlist>
9545 <listitem><para>A directory within the files installed
9546 by your recipe through <filename>do_install</filename>
9547 in which to search.</para></listitem>
9548 <listitem><para>A regular expression used to match module
9549 files in that directory.
9550 In the example, note the parentheses () that mark
9551 the part of the expression from which the module
9552 name should be derived.</para></listitem>
9553 <listitem><para>A pattern to use for the package names.
9554 </para></listitem>
9555 <listitem><para>A description for each package.
9556 </para></listitem>
9557 <listitem><para>An empty string for
9558 <filename>extra_depends</filename>, which disables
9559 the default dependency on the main
9560 <filename>lighttpd</filename> package.
9561 Thus, if a file in <filename>${libdir}</filename>
9562 called <filename>mod_alias.so</filename> is found,
9563 a package called <filename>lighttpd-module-alias</filename>
9564 is created for it and the
9565 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9566 is set to "Lighttpd module for alias".</para></listitem>
9567 </itemizedlist>
9568 </para>
9569
9570 <para>
9571 Often, packaging modules is as simple as the previous
9572 example.
9573 However, more advanced options exist that you can use
9574 within <filename>do_split_packages</filename> to modify its
9575 behavior.
9576 And, if you need to, you can add more logic by specifying
9577 a hook function that is called for each package.
9578 It is also perfectly acceptable to call
9579 <filename>do_split_packages</filename> multiple times if
9580 you have more than one set of modules to package.
9581 </para>
9582
9583 <para>
9584 For more examples that show how to use
9585 <filename>do_split_packages</filename>, see the
9586 <filename>connman.inc</filename> file in the
9587 <filename>meta/recipes-connectivity/connman/</filename>
9588 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009589 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009590 You can also find examples in
9591 <filename>meta/classes/kernel.bbclass</filename>.
9592 </para>
9593
9594 <para>
9595 Following is a reference that shows
9596 <filename>do_split_packages</filename> mandatory and
9597 optional arguments:
9598 <literallayout class='monospaced'>
9599 Mandatory arguments
9600
9601 root
9602 The path in which to search
9603 file_regex
9604 Regular expression to match searched files.
9605 Use parentheses () to mark the part of this
9606 expression that should be used to derive the
9607 module name (to be substituted where %s is
9608 used in other function arguments as noted below)
9609 output_pattern
9610 Pattern to use for the package names. Must
9611 include %s.
9612 description
9613 Description to set for each package. Must
9614 include %s.
9615
9616 Optional arguments
9617
9618 postinst
9619 Postinstall script to use for all packages
9620 (as a string)
9621 recursive
9622 True to perform a recursive search - default
9623 False
9624 hook
9625 A hook function to be called for every match.
9626 The function will be called with the following
9627 arguments (in the order listed):
9628
9629 f
9630 Full path to the file/directory match
9631 pkg
9632 The package name
9633 file_regex
9634 As above
9635 output_pattern
9636 As above
9637 modulename
9638 The module name derived using file_regex
9639
9640 extra_depends
9641 Extra runtime dependencies (RDEPENDS) to be
9642 set for all packages. The default value of None
9643 causes a dependency on the main package
9644 (${PN}) - if you do not want this, pass empty
9645 string '' for this parameter.
9646 aux_files_pattern
9647 Extra item(s) to be added to FILES for each
9648 package. Can be a single string item or a list
9649 of strings for multiple items. Must include %s.
9650 postrm
9651 postrm script to use for all packages (as a
9652 string)
9653 allow_dirs
9654 True to allow directories to be matched -
9655 default False
9656 prepend
9657 If True, prepend created packages to PACKAGES
9658 instead of the default False which appends them
9659 match_path
9660 match file_regex on the whole relative path to
9661 the root rather than just the file name
9662 aux_files_pattern_verbatim
9663 Extra item(s) to be added to FILES for each
9664 package, using the actual derived module name
9665 rather than converting it to something legal
9666 for a package name. Can be a single string item
9667 or a list of strings for multiple items. Must
9668 include %s.
9669 allow_links
9670 True to allow symlinks to be matched - default
9671 False
9672 summary
9673 Summary to set for each package. Must include %s;
9674 defaults to description if not set.
9675 </literallayout>
9676 </para>
9677 </section>
9678
9679 <section id='satisfying-dependencies'>
9680 <title>Satisfying Dependencies</title>
9681
9682 <para>
9683 The second part for handling optional module packaging
9684 is to ensure that any dependencies on optional modules
9685 from other recipes are satisfied by your recipe.
9686 You can be sure these dependencies are satisfied by
9687 using the
9688 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9689 Here is an example that continues with the
9690 <filename>lighttpd</filename> recipe shown earlier:
9691 <literallayout class='monospaced'>
9692 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9693 </literallayout>
9694 The name specified in the regular expression can of
9695 course be anything.
9696 In this example, it is <filename>lighttpd-module-</filename>
9697 and is specified as the prefix to ensure that any
9698 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9699 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9700 on a package name starting with the prefix are satisfied
9701 during build time.
9702 If you are using <filename>do_split_packages</filename>
9703 as described in the previous section, the value you put in
9704 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9705 the name pattern specified in the call to
9706 <filename>do_split_packages</filename>.
9707 </para>
9708 </section>
9709 </section>
9710
9711 <section id='using-runtime-package-management'>
9712 <title>Using Runtime Package Management</title>
9713
9714 <para>
9715 During a build, BitBake always transforms a recipe into one or
9716 more packages.
9717 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009718 and produces a number of packages (e.g.
9719 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9720 <filename>bash-completion</filename>,
9721 <filename>bash-completion-dbg</filename>,
9722 <filename>bash-completion-dev</filename>,
9723 <filename>bash-completion-extra</filename>,
9724 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009725 Not all generated packages are included in an image.
9726 </para>
9727
9728 <para>
9729 In several situations, you might need to update, add, remove,
9730 or query the packages on a target device at runtime
9731 (i.e. without having to generate a new image).
9732 Examples of such situations include:
9733 <itemizedlist>
9734 <listitem><para>
9735 You want to provide in-the-field updates to deployed
9736 devices (e.g. security updates).
9737 </para></listitem>
9738 <listitem><para>
9739 You want to have a fast turn-around development cycle
9740 for one or more applications that run on your device.
9741 </para></listitem>
9742 <listitem><para>
9743 You want to temporarily install the "debug" packages
9744 of various applications on your device so that
9745 debugging can be greatly improved by allowing
9746 access to symbols and source debugging.
9747 </para></listitem>
9748 <listitem><para>
9749 You want to deploy a more minimal package selection of
9750 your device but allow in-the-field updates to add a
9751 larger selection for customization.
9752 </para></listitem>
9753 </itemizedlist>
9754 </para>
9755
9756 <para>
9757 In all these situations, you have something similar to a more
9758 traditional Linux distribution in that in-field devices
9759 are able to receive pre-compiled packages from a server for
9760 installation or update.
9761 Being able to install these packages on a running,
9762 in-field device is what is termed "runtime package
9763 management".
9764 </para>
9765
9766 <para>
9767 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009768 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009769 packages plus the required metadata.
9770 You also need package manipulation tools on the target.
9771 The build machine is a likely candidate to act as the server.
9772 However, that machine does not necessarily have to be the
9773 package server.
9774 The build machine could push its artifacts to another machine
9775 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009776 In fact, doing so is advantageous for a production
9777 environment as getting the packages away from the
9778 development system's build directory prevents accidental
9779 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009780 </para>
9781
9782 <para>
9783 A simple build that targets just one device produces
9784 more than one package database.
9785 In other words, the packages produced by a build are separated
9786 out into a couple of different package groupings based on
9787 criteria such as the target's CPU architecture, the target
9788 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009789 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009790 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009791 <filename>noarch</filename>, <filename>i586</filename>, and
9792 <filename>qemux86</filename>.
9793 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009794 aware of all the packages that were available to it,
9795 you would need to point it to each of these databases
9796 individually.
9797 In a similar way, a traditional Linux distribution usually is
9798 configured to be aware of a number of software repositories
9799 from which it retrieves packages.
9800 </para>
9801
9802 <para>
9803 Using runtime package management is completely optional and
9804 not required for a successful build or deployment in any
9805 way.
9806 But if you want to make use of runtime package management,
9807 you need to do a couple things above and beyond the basics.
9808 The remainder of this section describes what you need to do.
9809 </para>
9810
9811 <section id='runtime-package-management-build'>
9812 <title>Build Considerations</title>
9813
9814 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009815 This section describes build considerations of which you
9816 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009817 package management.
9818 </para>
9819
9820 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009821 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009822 what format or formats to use.
9823 In your configuration, you use the
9824 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009825 variable to specify the format:
9826 <orderedlist>
9827 <listitem><para>
9828 Open the <filename>local.conf</filename> file
9829 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009830 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009831 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9832 </para></listitem>
9833 <listitem><para>
9834 Select the desired package format as follows:
9835 <literallayout class='monospaced'>
9836 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9837 </literallayout>
9838 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009839 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009840 supported package formats.
9841 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009842 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009843 different package formats, you can set the
9844 variable with more than one argument.
9845 However, the OpenEmbedded build system only
9846 uses the first argument when creating an image
9847 or Software Development Kit (SDK).
9848 </note>
9849 </para></listitem>
9850 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009851 </para>
9852
9853 <para>
9854 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009855 package database containing the packages in your current
9856 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009857 target for runtime package management, you can include
9858 "package-management" in the
9859 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9860 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009861 Including "package-management" in this configuration
9862 variable ensures that when the image is assembled for your
9863 target, the image includes the currently-known package
9864 databases as well as the target-specific tools required
9865 for runtime package management to be performed on the
9866 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009867 However, this is not strictly necessary.
9868 You could start your image off without any databases
9869 but only include the required on-target package
9870 tool(s).
9871 As an example, you could include "opkg" in your
9872 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9873 variable if you are using the IPK package format.
9874 You can then initialize your target's package database(s)
9875 later once your image is up and running.
9876 </para>
9877
9878 <para>
9879 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009880 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009881 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009882 package index after the build by using the following
9883 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009884 <literallayout class='monospaced'>
9885 $ bitbake package-index
9886 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009887 It might be tempting to build the package and the
9888 package index at the same time with a command such as
9889 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009890 <literallayout class='monospaced'>
9891 $ bitbake <replaceable>some-package</replaceable> package-index
9892 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009893 Do not do this as BitBake does not schedule the package
9894 index for after the completion of the package you are
9895 building.
9896 Consequently, you cannot be sure of the package index
9897 including information for the package you just built.
9898 Thus, be sure to run the package update step separately
9899 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009900 </para>
9901
9902 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009903 You can use the
9904 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9905 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9906 and
9907 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9908 variables to pre-configure target images to use a package
9909 feed.
9910 If you do not define these variables, then manual steps
9911 as described in the subsequent sections are necessary to
9912 configure the target.
9913 You should set these variables before building the image
9914 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009915 </para>
9916
9917 <para>
9918 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009919 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009920 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009921 For example, if
9922 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009923 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009924 is RPM, then your RPM packages are available in
9925 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009926 </para>
9927 </section>
9928
9929 <section id='runtime-package-management-server'>
9930 <title>Host or Server Machine Setup</title>
9931
9932 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009933 Although other protocols are possible, a server using HTTP
9934 typically serves packages.
9935 If you want to use HTTP, then set up and configure a
9936 web server such as Apache 2, lighttpd, or
9937 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009938 </para>
9939
9940 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009941 To keep things simple, this section describes how to set
9942 up a SimpleHTTPServer web server to share package feeds
9943 from the developer's machine.
9944 Although this server might not be the best for a production
9945 environment, the setup is simple and straight forward.
9946 Should you want to use a different server more suited for
9947 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9948 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009949 </para>
9950
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009951 <para>
9952 From within the build directory where you have built an
9953 image based on your packaging choice (i.e. the
9954 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9955 setting), simply start the server.
9956 The following example assumes a build directory of
9957 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9958 <filename>PACKAGE_CLASSES</filename> setting of
9959 "package_rpm":
9960 <literallayout class='monospaced'>
9961 $ cd ~/poky/build/tmp/deploy/rpm
9962 $ python -m SimpleHTTPServer
9963 </literallayout>
9964 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009965 </section>
9966
9967 <section id='runtime-package-management-target'>
9968 <title>Target Setup</title>
9969
9970 <para>
9971 Setting up the target differs depending on the
9972 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009973 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009974 </para>
9975
9976 <section id='runtime-package-management-target-rpm'>
9977 <title>Using RPM</title>
9978
9979 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009980 The
9981 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9982 (DNF) performs runtime package management of RPM
9983 packages.
9984 In order to use DNF for runtime package management,
9985 you must perform an initial setup on the target
9986 machine for cases where the
9987 <filename>PACKAGE_FEED_*</filename> variables were not
9988 set as part of the image that is running on the
9989 target.
9990 This means if you built your image and did not not use
9991 these variables as part of the build and your image is
9992 now running on the target, you need to perform the
9993 steps in this section if you want to use runtime
9994 package management.
9995 <note>
9996 For information on the
9997 <filename>PACKAGE_FEED_*</filename> variables, see
9998 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9999 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
10000 and
10001 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10002 in the Yocto Project Reference Manual variables
10003 glossary.
10004 </note>
10005 </para>
10006
10007 <para>
10008 On the target, you must inform DNF that package
10009 databases are available.
10010 You do this by creating a file named
10011 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
10012 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010013 </para>
10014
10015 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010016 As an example, assume the target is able to use the
10017 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010018 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010019 and <filename>qemux86</filename> from a server named
10020 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -040010021 The specifics for setting up the web server are up to
10022 you.
10023 The critical requirement is that the URIs in the
10024 target repository configuration point to the
10025 correct remote location for the feeds.
10026 <note><title>Tip</title>
10027 For development purposes, you can point the web
10028 server to the build system's
10029 <filename>deploy</filename> directory.
10030 However, for production use, it is better to copy
10031 the package directories to a location outside of
10032 the build area and use that location.
10033 Doing so avoids situations where the build system
10034 overwrites or changes the
10035 <filename>deploy</filename> directory.
10036 </note>
10037 </para>
10038
10039 <para>
10040 When telling DNF where to look for the package
10041 databases, you must declare individual locations
10042 per architecture or a single location used for all
10043 architectures.
10044 You cannot do both:
10045 <itemizedlist>
10046 <listitem><para>
10047 <emphasis>Create an Explicit List of Architectures:</emphasis>
10048 Define individual base URLs to identify where
10049 each package database is located:
10050 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010051 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010052 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -040010053 </literallayout>
10054 This example informs DNF about individual
10055 package databases for all three architectures.
10056 </para></listitem>
10057 <listitem><para>
10058 <emphasis>Create a Single (Full) Package Index:</emphasis>
10059 Define a single base URL that identifies where
10060 a full package database is located:
10061 <literallayout class='monospaced'>
10062 [oe-packages]
10063 baseurl=http://my.server/rpm
10064 </literallayout>
10065 This example informs DNF about a single package
10066 database that contains all the package index
10067 information for all supported architectures.
10068 </para></listitem>
10069 </itemizedlist>
10070 </para>
10071
10072 <para>
10073 Once you have informed DNF where to find the package
10074 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010075 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010076 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010077 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010078 DNF is now able to find, install, and upgrade packages
10079 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010080 <note>
10081 See the
10082 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
10083 for additional information.
10084 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010085 </para>
10086 </section>
10087
10088 <section id='runtime-package-management-target-ipk'>
10089 <title>Using IPK</title>
10090
10091 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010092 The <filename>opkg</filename> application performs
10093 runtime package management of IPK packages.
10094 You must perform an initial setup for
10095 <filename>opkg</filename> on the target machine
10096 if the
10097 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10098 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10099 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10100 variables have not been set or the target image was
10101 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010102 </para>
10103
10104 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010105 The <filename>opkg</filename> application uses
10106 configuration files to find available package
10107 databases.
10108 Thus, you need to create a configuration file inside
10109 the <filename>/etc/opkg/</filename> direction, which
10110 informs <filename>opkg</filename> of any repository
10111 you want to use.
10112 </para>
10113
10114 <para>
10115 As an example, suppose you are serving packages from a
10116 <filename>ipk/</filename> directory containing the
10117 <filename>i586</filename>,
10118 <filename>all</filename>, and
10119 <filename>qemux86</filename> databases through an
10120 HTTP server named <filename>my.server</filename>.
10121 On the target, create a configuration file
10122 (e.g. <filename>my_repo.conf</filename>) inside the
10123 <filename>/etc/opkg/</filename> directory containing
10124 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010125 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010126 src/gz all http://my.server/ipk/all
10127 src/gz i586 http://my.server/ipk/i586
10128 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010129 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010130 Next, instruct <filename>opkg</filename> to fetch
10131 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010132 <literallayout class='monospaced'>
10133 # opkg update
10134 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010135 The <filename>opkg</filename> application is now able
10136 to find, install, and upgrade packages from the
10137 specified repository.
10138 </para>
10139 </section>
10140
10141 <section id='runtime-package-management-target-deb'>
10142 <title>Using DEB</title>
10143
10144 <para>
10145 The <filename>apt</filename> application performs
10146 runtime package management of DEB packages.
10147 This application uses a source list file to find
10148 available package databases.
10149 You must perform an initial setup for
10150 <filename>apt</filename> on the target machine
10151 if the
10152 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10153 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10154 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10155 variables have not been set or the target image was
10156 built before the variables were set.
10157 </para>
10158
10159 <para>
10160 To inform <filename>apt</filename> of the repository
10161 you want to use, you might create a list file (e.g.
10162 <filename>my_repo.list</filename>) inside the
10163 <filename>/etc/apt/sources.list.d/</filename>
10164 directory.
10165 As an example, suppose you are serving packages from a
10166 <filename>deb/</filename> directory containing the
10167 <filename>i586</filename>,
10168 <filename>all</filename>, and
10169 <filename>qemux86</filename> databases through an
10170 HTTP server named <filename>my.server</filename>.
10171 The list file should contain:
10172 <literallayout class='monospaced'>
10173 deb http://my.server/deb/all ./
10174 deb http://my.server/deb/i586 ./
10175 deb http://my.server/deb/qemux86 ./
10176 </literallayout>
10177 Next, instruct the <filename>apt</filename>
10178 application to fetch the repository information:
10179 <literallayout class='monospaced'>
10180 # apt-get update
10181 </literallayout>
10182 After this step, <filename>apt</filename> is able
10183 to find, install, and upgrade packages from the
10184 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010185 </para>
10186 </section>
10187 </section>
10188 </section>
10189
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010190 <section id='generating-and-using-signed-packages'>
10191 <title>Generating and Using Signed Packages</title>
10192 <para>
10193 In order to add security to RPM packages used during a build,
10194 you can take steps to securely sign them.
10195 Once a signature is verified, the OpenEmbedded build system
10196 can use the package in the build.
10197 If security fails for a signed package, the build system
10198 aborts the build.
10199 </para>
10200
10201 <para>
10202 This section describes how to sign RPM packages during a build
10203 and how to use signed package feeds (repositories) when
10204 doing a build.
10205 </para>
10206
10207 <section id='signing-rpm-packages'>
10208 <title>Signing RPM Packages</title>
10209
10210 <para>
10211 To enable signing RPM packages, you must set up the
10212 following configurations in either your
10213 <filename>local.config</filename> or
10214 <filename>distro.config</filename> file:
10215 <literallayout class='monospaced'>
10216 # Inherit sign_rpm.bbclass to enable signing functionality
10217 INHERIT += " sign_rpm"
10218 # Define the GPG key that will be used for signing.
10219 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
10220 # Provide passphrase for the key
10221 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
10222 </literallayout>
10223 <note>
10224 Be sure to supply appropriate values for both
10225 <replaceable>key_name</replaceable> and
10226 <replaceable>passphrase</replaceable>
10227 </note>
10228 Aside from the
10229 <filename>RPM_GPG_NAME</filename> and
10230 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
10231 previous example, two optional variables related to signing
10232 exist:
10233 <itemizedlist>
10234 <listitem><para>
10235 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10236 Specifies a <filename>gpg</filename> binary/wrapper
10237 that is executed when the package is signed.
10238 </para></listitem>
10239 <listitem><para>
10240 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10241 Specifies the <filename>gpg</filename> home
10242 directory used when the package is signed.
10243 </para></listitem>
10244 </itemizedlist>
10245 </para>
10246 </section>
10247
10248 <section id='processing-package-feeds'>
10249 <title>Processing Package Feeds</title>
10250
10251 <para>
10252 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010253 also enable signed package feeds for IPK and RPM packages.
10254 </para>
10255
10256 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010257 The steps you need to take to enable signed package feed
10258 use are similar to the steps used to sign RPM packages.
10259 You must define the following in your
10260 <filename>local.config</filename> or
10261 <filename>distro.config</filename> file:
10262 <literallayout class='monospaced'>
10263 INHERIT += "sign_package_feed"
10264 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10265 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10266 </literallayout>
10267 For signed package feeds, the passphrase must exist in a
10268 separate file, which is pointed to by the
10269 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10270 variable.
10271 Regarding security, keeping a plain text passphrase out of
10272 the configuration is more secure.
10273 </para>
10274
10275 <para>
10276 Aside from the
10277 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10278 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10279 variables, three optional variables related to signed
10280 package feeds exist:
10281 <itemizedlist>
10282 <listitem><para>
10283 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10284 Specifies a <filename>gpg</filename> binary/wrapper
10285 that is executed when the package is signed.
10286 </para></listitem>
10287 <listitem><para>
10288 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10289 Specifies the <filename>gpg</filename> home
10290 directory used when the package is signed.
10291 </para></listitem>
10292 <listitem><para>
10293 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10294 Specifies the type of <filename>gpg</filename>
10295 signature.
10296 This variable applies only to RPM and IPK package
10297 feeds.
10298 Allowable values for the
10299 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10300 are "ASC", which is the default and specifies ascii
10301 armored, and "BIN", which specifies binary.
10302 </para></listitem>
10303 </itemizedlist>
10304 </para>
10305 </section>
10306 </section>
10307
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010308 <section id='testing-packages-with-ptest'>
10309 <title>Testing Packages With ptest</title>
10310
10311 <para>
10312 A Package Test (ptest) runs tests against packages built
10313 by the OpenEmbedded build system on the target machine.
10314 A ptest contains at least two items: the actual test, and
10315 a shell script (<filename>run-ptest</filename>) that starts
10316 the test.
10317 The shell script that starts the test must not contain
10318 the actual test - the script only starts the test.
10319 On the other hand, the test can be anything from a simple
10320 shell script that runs a binary and checks the output to
10321 an elaborate system of test binaries and data files.
10322 </para>
10323
10324 <para>
10325 The test generates output in the format used by
10326 Automake:
10327 <literallayout class='monospaced'>
10328 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10329 </literallayout>
10330 where the result can be <filename>PASS</filename>,
10331 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10332 and the testname can be any identifying string.
10333 </para>
10334
10335 <para>
10336 For a list of Yocto Project recipes that are already
10337 enabled with ptest, see the
10338 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10339 wiki page.
10340 <note>
10341 A recipe is "ptest-enabled" if it inherits the
10342 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10343 class.
10344 </note>
10345 </para>
10346
10347 <section id='adding-ptest-to-your-build'>
10348 <title>Adding ptest to Your Build</title>
10349
10350 <para>
10351 To add package testing to your build, add the
10352 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10353 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10354 variables to your <filename>local.conf</filename> file,
10355 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010356 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010357 <literallayout class='monospaced'>
10358 DISTRO_FEATURES_append = " ptest"
10359 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10360 </literallayout>
10361 Once your build is complete, the ptest files are installed
10362 into the
10363 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10364 directory within the image, where
10365 <filename><replaceable>package</replaceable></filename>
10366 is the name of the package.
10367 </para>
10368 </section>
10369
10370 <section id='running-ptest'>
10371 <title>Running ptest</title>
10372
10373 <para>
10374 The <filename>ptest-runner</filename> package installs a
10375 shell script that loops through all installed ptest test
10376 suites and runs them in sequence.
10377 Consequently, you might want to add this package to
10378 your image.
10379 </para>
10380 </section>
10381
10382 <section id='getting-your-package-ready'>
10383 <title>Getting Your Package Ready</title>
10384
10385 <para>
10386 In order to enable a recipe to run installed ptests
10387 on target hardware,
10388 you need to prepare the recipes that build the packages
10389 you want to test.
10390 Here is what you have to do for each recipe:
10391 <itemizedlist>
10392 <listitem><para><emphasis>Be sure the recipe
10393 inherits the
10394 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10395 class:</emphasis>
10396 Include the following line in each recipe:
10397 <literallayout class='monospaced'>
10398 inherit ptest
10399 </literallayout>
10400 </para></listitem>
10401 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10402 This script starts your test.
10403 Locate the script where you will refer to it
10404 using
10405 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10406 Here is an example that starts a test for
10407 <filename>dbus</filename>:
10408 <literallayout class='monospaced'>
10409 #!/bin/sh
10410 cd test
10411 make -k runtest-TESTS
10412 </literallayout>
10413 </para></listitem>
10414 <listitem><para><emphasis>Ensure dependencies are
10415 met:</emphasis>
10416 If the test adds build or runtime dependencies
10417 that normally do not exist for the package
10418 (such as requiring "make" to run the test suite),
10419 use the
10420 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10421 and
10422 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10423 variables in your recipe in order for the package
10424 to meet the dependencies.
10425 Here is an example where the package has a runtime
10426 dependency on "make":
10427 <literallayout class='monospaced'>
10428 RDEPENDS_${PN}-ptest += "make"
10429 </literallayout>
10430 </para></listitem>
10431 <listitem><para><emphasis>Add a function to build the
10432 test suite:</emphasis>
10433 Not many packages support cross-compilation of
10434 their test suites.
10435 Consequently, you usually need to add a
10436 cross-compilation function to the package.
10437 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010438
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010439 <para>Many packages based on Automake compile and
10440 run the test suite by using a single command
10441 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010442 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010443 builds and runs on the same computer, while
10444 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010445 on the host but executed for the target
10446 architecture (though often, as in the case for
10447 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010448 The built version of Automake that ships with the
10449 Yocto Project includes a patch that separates
10450 building and execution.
10451 Consequently, packages that use the unaltered,
10452 patched version of <filename>make check</filename>
10453 automatically cross-compiles.</para>
10454 <para>Regardless, you still must add a
10455 <filename>do_compile_ptest</filename> function to
10456 build the test suite.
10457 Add a function similar to the following to your
10458 recipe:
10459 <literallayout class='monospaced'>
10460 do_compile_ptest() {
10461 oe_runmake buildtest-TESTS
10462 }
10463 </literallayout>
10464 </para></listitem>
10465 <listitem><para><emphasis>Ensure special configurations
10466 are set:</emphasis>
10467 If the package requires special configurations
10468 prior to compiling the test code, you must
10469 insert a <filename>do_configure_ptest</filename>
10470 function into the recipe.
10471 </para></listitem>
10472 <listitem><para><emphasis>Install the test
10473 suite:</emphasis>
10474 The <filename>ptest</filename> class
10475 automatically copies the file
10476 <filename>run-ptest</filename> to the target and
10477 then runs make <filename>install-ptest</filename>
10478 to run the tests.
10479 If this is not enough, you need to create a
10480 <filename>do_install_ptest</filename> function and
10481 make sure it gets called after the
10482 "make install-ptest" completes.
10483 </para></listitem>
10484 </itemizedlist>
10485 </para>
10486 </section>
10487 </section>
Brad Bishop15ae2502019-06-18 21:44:24 -040010488
10489 <section id='creating-node-package-manager-npm-packages'>
10490 <title>Creating Node Package Manager (NPM) Packages</title>
10491
10492 <para>
10493 <ulink url='https://en.wikipedia.org/wiki/Npm_(software)'>NPM</ulink>
10494 is a package manager for the JavaScript programming
10495 language.
10496 The Yocto Project supports the NPM
10497 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>.
10498 You can use this fetcher in combination with
10499 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>
10500 to create recipes that produce NPM packages.
10501 </para>
10502
10503 <para>
10504 Two workflows exist that allow you to create NPM packages
10505 using <filename>devtool</filename>: the NPM registry modules
10506 method and the NPM project code method.
10507 <note>
10508 While it is possible to create NPM recipes manually,
10509 using <filename>devtool</filename> is far simpler.
10510 </note>
10511 Additionally, some requirements and caveats exist.
10512 </para>
10513
10514 <section id='npm-package-creation-requirements'>
10515 <title>Requirements and Caveats</title>
10516
10517 <para>
10518 You need to be aware of the following before using
10519 <filename>devtool</filename> to create NPM packages:
10520 <itemizedlist>
10521 <listitem><para>
10522 Of the two methods that you can use
10523 <filename>devtool</filename> to create NPM
10524 packages, the registry approach is slightly
10525 simpler.
10526 However, you might consider the project
10527 approach because you do not have to publish
10528 your module in the NPM registry
10529 (<ulink url='https://docs.npmjs.com/misc/registry'><filename>npm-registry</filename></ulink>),
10530 which is NPM's public registry.
10531 </para></listitem>
10532 <listitem><para>
10533 Be familiar with
10534 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>.
10535 </para></listitem>
10536 <listitem><para>
10537 The NPM host tools need the native
10538 <filename>nodejs-npm</filename> package, which
10539 is part of the OpenEmbedded environment.
10540 You need to get the package by cloning the
10541 <ulink url='https://github.com/openembedded/meta-openembedded'></ulink>
10542 repository out of GitHub.
10543 Be sure to add the path to your local copy to
10544 your <filename>bblayers.conf</filename> file.
10545 </para></listitem>
10546 <listitem><para>
10547 <filename>devtool</filename> cannot detect
10548 native libraries in module dependencies.
10549 Consequently, you must manually add packages
10550 to your recipe.
10551 </para></listitem>
10552 <listitem><para>
10553 While deploying NPM packages,
10554 <filename>devtool</filename> cannot determine
10555 which dependent packages are missing on the
10556 target (e.g. the node runtime
10557 <filename>nodejs</filename>).
10558 Consequently, you need to find out what
10559 files are missing and be sure they are on the
10560 target.
10561 </para></listitem>
10562 <listitem><para>
10563 Although you might not need NPM to run your
10564 node package, it is useful to have NPM on your
10565 target.
10566 The NPM package name is
10567 <filename>nodejs-npm</filename>.
10568 </para></listitem>
10569 </itemizedlist>
10570 </para>
10571 </section>
10572
10573 <section id='npm-using-the-registry-modules-method'>
10574 <title>Using the Registry Modules Method</title>
10575
10576 <para>
10577 This section presents an example that uses the
10578 <filename>cute-files</filename> module, which is a
10579 file browser web application.
10580 <note>
10581 You must know the <filename>cute-files</filename>
10582 module version.
10583 </note>
10584 </para>
10585
10586 <para>
10587 The first thing you need to do is use
10588 <filename>devtool</filename> and the NPM fetcher to
10589 create the recipe:
10590 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -050010591 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
Brad Bishop15ae2502019-06-18 21:44:24 -040010592 </literallayout>
10593 The <filename>devtool add</filename> command runs
10594 <filename>recipetool create</filename> and uses the
10595 same fetch URI to download each dependency and capture
10596 license details where possible.
10597 The result is a generated recipe.
10598 </para>
10599
10600 <para>
10601 The recipe file is fairly simple and contains every
10602 license that <filename>recipetool</filename> finds
10603 and includes the licenses in the recipe's
10604 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
10605 variables.
10606 You need to examine the variables and look for those
10607 with "unknown" in the
10608 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
10609 field.
10610 You need to track down the license information for
10611 "unknown" modules and manually add the information to the
10612 recipe.
10613 </para>
10614
10615 <para>
Andrew Geissler82c905d2020-04-13 13:39:40 -050010616 <filename>recipetool</filename> creates a "shrinkwrap" file
10617 for your recipe.
Brad Bishop15ae2502019-06-18 21:44:24 -040010618 Shrinkwrap files capture the version of all dependent
10619 modules.
10620 Many packages do not provide shrinkwrap files.
10621 <filename>recipetool</filename> create a shrinkwrap
10622 file as it runs.
Brad Bishop15ae2502019-06-18 21:44:24 -040010623 <note>
10624 A package is created for each sub-module.
10625 This policy is the only practical way to have the
10626 licenses for all of the dependencies represented
10627 in the license manifest of the image.
10628 </note>
10629 </para>
10630
10631 <para>
10632 The <filename>devtool edit-recipe</filename> command
10633 lets you take a look at the recipe:
10634 <literallayout class='monospaced'>
10635 $ devtool edit-recipe cute-files
10636 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
Andrew Geissler82c905d2020-04-13 13:39:40 -050010637 LICENSE = "MIT &amp; ISC &amp; Unknown"
Brad Bishop15ae2502019-06-18 21:44:24 -040010638 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
Andrew Geissler82c905d2020-04-13 13:39:40 -050010639 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
10640 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
Brad Bishop15ae2502019-06-18 21:44:24 -040010641 ...
10642
Andrew Geissler82c905d2020-04-13 13:39:40 -050010643 SRC_URI = " \
10644 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
10645 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
10646 "
Brad Bishop15ae2502019-06-18 21:44:24 -040010647
Andrew Geissler82c905d2020-04-13 13:39:40 -050010648 S = "${WORKDIR}/npm"
10649
10650 inherit npm
10651
Brad Bishop15ae2502019-06-18 21:44:24 -040010652 LICENSE_${PN} = "MIT"
Andrew Geissler82c905d2020-04-13 13:39:40 -050010653 LICENSE_${PN}-accepts = "MIT"
10654 LICENSE_${PN}-array-flatten = "MIT"
10655 ...
10656 LICENSE_${PN}-vary = "MIT"
Brad Bishop15ae2502019-06-18 21:44:24 -040010657 </literallayout>
10658 Three key points exist in the previous example:
10659 <itemizedlist>
10660 <listitem><para>
10661 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10662 uses the NPM scheme so that the NPM fetcher
10663 is used.
10664 </para></listitem>
10665 <listitem><para>
10666 <filename>recipetool</filename> collects all
10667 the license information.
10668 If a sub-module's license is unavailable,
10669 the sub-module's name appears in the comments.
10670 </para></listitem>
10671 <listitem><para>
10672 The <filename>inherit npm</filename> statement
10673 causes the
10674 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-npm'><filename>npm</filename></ulink>
10675 class to package up all the modules.
10676 </para></listitem>
10677 </itemizedlist>
10678 </para>
10679
10680 <para>
10681 You can run the following command to build the
10682 <filename>cute-files</filename> package:
10683 <literallayout class='monospaced'>
10684 $ devtool build cute-files
10685 </literallayout>
10686 Remember that <filename>nodejs</filename> must be
10687 installed on the target before your package.
10688 </para>
10689
10690 <para>
10691 Assuming 192.168.7.2 for the target's IP address, use
10692 the following command to deploy your package:
10693 <literallayout class='monospaced'>
10694 $ devtool deploy-target -s cute-files root@192.168.7.2
10695 </literallayout>
10696 Once the package is installed on the target, you can
10697 test the application:
10698 <note>
10699 Because of a know issue, you cannot simply run
10700 <filename>cute-files</filename> as you would if you
10701 had run <filename>npm install</filename>.
10702 </note>
10703 <literallayout class='monospaced'>
10704 $ cd /usr/lib/node_modules/cute-files
10705 $ node cute-files.js
10706 </literallayout>
10707 On a browser, go to
10708 <filename>http://192.168.7.2:3000</filename> and you
10709 see the following:
10710 <imagedata fileref="figures/cute-files-npm-example.png" align="center" width="6in" depth="4in" />
10711 </para>
10712
10713 <para>
10714 You can find the recipe in
10715 <filename>workspace/recipes/cute-files</filename>.
10716 You can use the recipe in any layer you choose.
10717 </para>
10718 </section>
10719
10720 <section id='npm-using-the-npm-projects-method'>
10721 <title>Using the NPM Projects Code Method</title>
10722
10723 <para>
10724 Although it is useful to package modules already in the
10725 NPM registry, adding <filename>node.js</filename> projects
10726 under development is a more common developer use case.
10727 </para>
10728
10729 <para>
10730 This section covers the NPM projects code method, which is
10731 very similar to the "registry" approach described in the
10732 previous section.
10733 In the NPM projects method, you provide
10734 <filename>devtool</filename> with an URL that points to the
10735 source files.
10736 </para>
10737
10738 <para>
10739 Replicating the same example, (i.e.
10740 <filename>cute-files</filename>) use the following command:
10741 <literallayout class='monospaced'>
10742 $ devtool add https://github.com/martinaglv/cute-files.git
10743 </literallayout>
10744 The recipe this command generates is very similar to the
10745 recipe created in the previous section.
10746 However, the <filename>SRC_URI</filename> looks like the
10747 following:
10748 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -050010749 SRC_URI = " \
10750 git://github.com/martinaglv/cute-files.git;protocol=https \
10751 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
10752 "
Brad Bishop15ae2502019-06-18 21:44:24 -040010753 </literallayout>
10754 In this example, the main module is taken from the Git
10755 repository and dependents are taken from the NPM registry.
10756 Other than those differences, the recipe is basically the
10757 same between the two methods.
10758 You can build and deploy the package exactly as described
10759 in the previous section that uses the registry modules
10760 method.
10761 </para>
10762 </section>
10763 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010764 </section>
10765
Brad Bishop316dfdd2018-06-25 12:45:53 -040010766 <section id='efficiently-fetching-source-files-during-a-build'>
10767 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010768
10769 <para>
10770 The OpenEmbedded build system works with source files located
10771 through the
10772 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10773 variable.
10774 When you build something using BitBake, a big part of the operation
10775 is locating and downloading all the source tarballs.
10776 For images, downloading all the source for various packages can
10777 take a significant amount of time.
10778 </para>
10779
10780 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010781 This section shows you how you can use mirrors to speed up
10782 fetching source files and how you can pre-fetch files all of which
10783 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010784 </para>
10785
10786 <section id='setting-up-effective-mirrors'>
10787 <title>Setting up Effective Mirrors</title>
10788
10789 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010790 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010791 build is simply downloading all of the source tarballs.
10792 Maybe you have been working with another build system
10793 (OpenEmbedded or Angstrom) for which you have built up a
10794 sizable directory of source tarballs.
10795 Or, perhaps someone else has such a directory for which you
10796 have read access.
10797 If so, you can save time by adding statements to your
10798 configuration file so that the build process checks local
10799 directories first for existing tarballs before checking the
10800 Internet.
10801 </para>
10802
10803 <para>
10804 Here is an efficient way to set it up in your
10805 <filename>local.conf</filename> file:
10806 <literallayout class='monospaced'>
10807 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10808 INHERIT += "own-mirrors"
10809 BB_GENERATE_MIRROR_TARBALLS = "1"
10810 # BB_NO_NETWORK = "1"
10811 </literallayout>
10812 </para>
10813
10814 <para>
10815 In the previous example, the
10816 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10817 variable causes the OpenEmbedded build system to generate
10818 tarballs of the Git repositories and store them in the
10819 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10820 directory.
10821 Due to performance reasons, generating and storing these
10822 tarballs is not the build system's default behavior.
10823 </para>
10824
10825 <para>
10826 You can also use the
10827 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10828 variable.
10829 For an example, see the variable's glossary entry in the
10830 Yocto Project Reference Manual.
10831 </para>
10832 </section>
10833
10834 <section id='getting-source-files-and-suppressing-the-build'>
10835 <title>Getting Source Files and Suppressing the Build</title>
10836
10837 <para>
10838 Another technique you can use to ready yourself for a
10839 successive string of build operations, is to pre-fetch
10840 all the source files without actually starting a build.
10841 This technique lets you work through any download issues
10842 and ultimately gathers all the source files into your
10843 download directory
10844 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10845 which is located with
10846 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10847 </para>
10848
10849 <para>
10850 Use the following BitBake command form to fetch all the
10851 necessary sources without starting the build:
10852 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -050010853 $ bitbake <replaceable>target</replaceable> --runall=fetch
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010854 </literallayout>
10855 This variation of the BitBake command guarantees that you
10856 have all the sources for that BitBake target should you
10857 disconnect from the Internet and want to do the build
10858 later offline.
10859 </para>
10860 </section>
10861 </section>
10862
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010863 <section id="selecting-an-initialization-manager">
10864 <title>Selecting an Initialization Manager</title>
10865
10866 <para>
10867 By default, the Yocto Project uses SysVinit as the initialization
10868 manager.
10869 However, support also exists for systemd,
10870 which is a full replacement for init with
10871 parallel starting of services, reduced shell overhead and other
10872 features that are used by many distributions.
10873 </para>
10874
10875 <para>
Brad Bishop64c979e2019-11-04 13:55:29 -050010876 Within the system, SysVinit treats system components as services.
10877 These services are maintained as shell scripts stored in the
10878 <filename>/etc/init.d/</filename> directory.
10879 Services organize into different run levels.
10880 This organization is maintained by putting links to the services
10881 in the <filename>/etc/rcN.d/</filename> directories, where
10882 <replaceable>N/</replaceable> is one of the following options:
10883 "S", "0", "1", "2", "3", "4", "5", or "6".
10884 <note>
10885 Each runlevel has a dependency on the previous runlevel.
10886 This dependency allows the services to work properly.
10887 </note>
10888 </para>
10889
10890 <para>
10891 In comparison, systemd treats components as units.
10892 Using units is a broader concept as compared to using a service.
10893 A unit includes several different types of entities.
10894 Service is one of the types of entities.
10895 The runlevel concept in SysVinit corresponds to the concept of a
10896 target in systemd, where target is also a type of supported unit.
10897 </para>
10898
10899 <para>
10900 In a SysVinit-based system, services load sequentially (i.e. one
10901 by one) during and parallelization is not supported.
10902 With systemd, services start in parallel.
10903 Needless to say, the method can have an impact on system startup
10904 performance.
10905 </para>
10906
10907 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010908 If you want to use SysVinit, you do
10909 not have to do anything.
10910 But, if you want to use systemd, you must
10911 take some steps as described in the following sections.
10912 </para>
10913
10914 <section id='using-systemd-exclusively'>
10915 <title>Using systemd Exclusively</title>
10916
10917 <para>
Brad Bishop15ae2502019-06-18 21:44:24 -040010918 Set these variables in your distribution configuration
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010919 file as follows:
10920 <literallayout class='monospaced'>
10921 DISTRO_FEATURES_append = " systemd"
10922 VIRTUAL-RUNTIME_init_manager = "systemd"
10923 </literallayout>
10924 You can also prevent the SysVinit
10925 distribution feature from
10926 being automatically enabled as follows:
10927 <literallayout class='monospaced'>
10928 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10929 </literallayout>
10930 Doing so removes any redundant SysVinit scripts.
10931 </para>
10932
10933 <para>
10934 To remove initscripts from your image altogether,
10935 set this variable also:
10936 <literallayout class='monospaced'>
10937 VIRTUAL-RUNTIME_initscripts = ""
10938 </literallayout>
10939 </para>
10940
10941 <para>
10942 For information on the backfill variable, see
10943 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10944 </para>
10945 </section>
10946
10947 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10948 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10949
10950 <para>
10951 Set these variables in your distribution configuration
10952 file as follows:
10953 <literallayout class='monospaced'>
10954 DISTRO_FEATURES_append = " systemd"
10955 VIRTUAL-RUNTIME_init_manager = "systemd"
10956 </literallayout>
10957 Doing so causes your main image to use the
10958 <filename>packagegroup-core-boot.bb</filename> recipe and
10959 systemd.
10960 The rescue/minimal image cannot use this package group.
10961 However, it can install SysVinit
10962 and the appropriate packages will have support for both
10963 systemd and SysVinit.
10964 </para>
10965 </section>
10966 </section>
10967
10968 <section id="selecting-dev-manager">
10969 <title>Selecting a Device Manager</title>
10970
10971 <para>
10972 The Yocto Project provides multiple ways to manage the device
10973 manager (<filename>/dev</filename>):
10974 <itemizedlist>
10975 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10976 For this case, the <filename>/dev</filename> directory
10977 is persistent and the required device nodes are created
10978 during the build.
10979 </para></listitem>
10980 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10981 For this case, the <filename>/dev</filename> directory
10982 is provided by the kernel as an in-memory file system and
10983 is automatically populated by the kernel at runtime.
10984 Additional configuration of device nodes is done in user
10985 space by a device manager like
10986 <filename>udev</filename> or
10987 <filename>busybox-mdev</filename>.
10988 </para></listitem>
10989 </itemizedlist>
10990 </para>
10991
10992 <section id="static-dev-management">
10993 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10994
10995 <para>
10996 To use the static method for device population, you need to
10997 set the
10998 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10999 variable to "0" as follows:
11000 <literallayout class='monospaced'>
11001 USE_DEVFS = "0"
11002 </literallayout>
11003 </para>
11004
11005 <para>
11006 The content of the resulting <filename>/dev</filename>
11007 directory is defined in a Device Table file.
11008 The
11009 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
11010 variable defines the Device Table to use and should be set
11011 in the machine or distro configuration file.
11012 Alternatively, you can set this variable in your
11013 <filename>local.conf</filename> configuration file.
11014 </para>
11015
11016 <para>
11017 If you do not define the
11018 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
11019 <filename>device_table-minimal.txt</filename> is used:
11020 <literallayout class='monospaced'>
11021 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
11022 </literallayout>
11023 </para>
11024
11025 <para>
11026 The population is handled by the <filename>makedevs</filename>
11027 utility during image creation:
11028 </para>
11029 </section>
11030
11031 <section id="devtmpfs-dev-management">
11032 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
11033
11034 <para>
11035 To use the dynamic method for device population, you need to
11036 use (or be sure to set) the
11037 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
11038 variable to "1", which is the default:
11039 <literallayout class='monospaced'>
11040 USE_DEVFS = "1"
11041 </literallayout>
11042 With this setting, the resulting <filename>/dev</filename>
11043 directory is populated by the kernel using
11044 <filename>devtmpfs</filename>.
11045 Make sure the corresponding kernel configuration variable
11046 <filename>CONFIG_DEVTMPFS</filename> is set when building
11047 you build a Linux kernel.
11048 </para>
11049
11050 <para>
11051 All devices created by <filename>devtmpfs</filename> will be
11052 owned by <filename>root</filename> and have permissions
11053 <filename>0600</filename>.
11054 </para>
11055
11056 <para>
11057 To have more control over the device nodes, you can use a
11058 device manager like <filename>udev</filename> or
11059 <filename>busybox-mdev</filename>.
11060 You choose the device manager by defining the
11061 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
11062 in your machine or distro configuration file.
11063 Alternatively, you can set this variable in your
11064 <filename>local.conf</filename> configuration file:
11065 <literallayout class='monospaced'>
11066 VIRTUAL-RUNTIME_dev_manager = "udev"
11067
11068 # Some alternative values
11069 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
11070 # VIRTUAL-RUNTIME_dev_manager = "systemd"
11071 </literallayout>
11072 </para>
11073 </section>
11074 </section>
11075
11076 <section id="platdev-appdev-srcrev">
11077 <title>Using an External SCM</title>
11078
11079 <para>
11080 If you're working on a recipe that pulls from an external Source
11081 Code Manager (SCM), it is possible to have the OpenEmbedded build
11082 system notice new recipe changes added to the SCM and then build
11083 the resulting packages that depend on the new recipes by using
11084 the latest versions.
11085 This only works for SCMs from which it is possible to get a
11086 sensible revision number for changes.
11087 Currently, you can do this with Apache Subversion (SVN), Git, and
11088 Bazaar (BZR) repositories.
11089 </para>
11090
11091 <para>
11092 To enable this behavior, the
11093 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
11094 of the recipe needs to reference
11095 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
11096 Here is an example:
11097 <literallayout class='monospaced'>
11098 PV = "1.2.3+git${SRCPV}"
11099 </literallayout>
11100 Then, you can add the following to your
11101 <filename>local.conf</filename>:
11102 <literallayout class='monospaced'>
11103 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
11104 </literallayout>
11105 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
11106 is the name of the recipe for which you want to enable automatic source
11107 revision updating.
11108 </para>
11109
11110 <para>
11111 If you do not want to update your local configuration file, you can
11112 add the following directly to the recipe to finish enabling
11113 the feature:
11114 <literallayout class='monospaced'>
11115 SRCREV = "${AUTOREV}"
11116 </literallayout>
11117 </para>
11118
11119 <para>
11120 The Yocto Project provides a distribution named
11121 <filename>poky-bleeding</filename>, whose configuration
11122 file contains the line:
11123 <literallayout class='monospaced'>
11124 require conf/distro/include/poky-floating-revisions.inc
11125 </literallayout>
11126 This line pulls in the listed include file that contains
11127 numerous lines of exactly that form:
11128 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011129 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
11130 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
11131 #SRCREV_pn-opkg ?= "${AUTOREV}"
11132 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
11133 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011134 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
11135 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
11136 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
11137 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
11138 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011139 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
11140 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
11141 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
11142 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011143 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
11144 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011145 .
11146 .
11147 .
11148 </literallayout>
11149 These lines allow you to experiment with building a
11150 distribution that tracks the latest development source
11151 for numerous packages.
11152 <note><title>Caution</title>
11153 The <filename>poky-bleeding</filename> distribution
11154 is not tested on a regular basis.
11155 Keep this in mind if you use it.
11156 </note>
11157 </para>
11158 </section>
11159
11160 <section id='creating-a-read-only-root-filesystem'>
11161 <title>Creating a Read-Only Root Filesystem</title>
11162
11163 <para>
11164 Suppose, for security reasons, you need to disable
11165 your target device's root filesystem's write permissions
11166 (i.e. you need a read-only root filesystem).
11167 Or, perhaps you are running the device's operating system
11168 from a read-only storage device.
11169 For either case, you can customize your image for
11170 that behavior.
11171 </para>
11172
11173 <note>
11174 Supporting a read-only root filesystem requires that the system and
11175 applications do not try to write to the root filesystem.
11176 You must configure all parts of the target system to write
11177 elsewhere, or to gracefully fail in the event of attempting to
11178 write to the root filesystem.
11179 </note>
11180
11181 <section id='creating-the-root-filesystem'>
11182 <title>Creating the Root Filesystem</title>
11183
11184 <para>
11185 To create the read-only root filesystem, simply add the
Andrew Geissler82c905d2020-04-13 13:39:40 -050011186 "read-only-rootfs" feature to your image, normally in one of two ways.
11187 The first way is to add the "read-only-rootfs" image feature
11188 in the image's recipe file via the
11189 <filename>IMAGE_FEATURES</filename> variable:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011190 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -050011191 IMAGE_FEATURES += "read-only-rootfs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011192 </literallayout>
Andrew Geissler82c905d2020-04-13 13:39:40 -050011193 As an alternative, you can add the same feature from within your
11194 build directory's <filename>local.conf</filename> file with the
11195 associated <filename>EXTRA_IMAGE_FEATURES</filename> variable, as in:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011196 <literallayout class='monospaced'>
Andrew Geissler82c905d2020-04-13 13:39:40 -050011197 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011198 </literallayout>
11199 </para>
11200
11201 <para>
11202 For more information on how to use these variables, see the
11203 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
11204 section.
11205 For information on the variables, see
11206 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
11207 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
11208 </para>
11209 </section>
11210
11211 <section id='post-installation-scripts'>
11212 <title>Post-Installation Scripts</title>
11213
11214 <para>
11215 It is very important that you make sure all
11216 post-Installation (<filename>pkg_postinst</filename>) scripts
11217 for packages that are installed into the image can be run
11218 at the time when the root filesystem is created during the
11219 build on the host system.
11220 These scripts cannot attempt to run during first-boot on the
11221 target device.
11222 With the "read-only-rootfs" feature enabled,
11223 the build system checks during root filesystem creation to make
11224 sure all post-installation scripts succeed.
11225 If any of these scripts still need to be run after the root
11226 filesystem is created, the build immediately fails.
11227 These build-time checks ensure that the build fails
11228 rather than the target device fails later during its
11229 initial boot operation.
11230 </para>
11231
11232 <para>
11233 Most of the common post-installation scripts generated by the
11234 build system for the out-of-the-box Yocto Project are engineered
11235 so that they can run during root filesystem creation
11236 (e.g. post-installation scripts for caching fonts).
11237 However, if you create and add custom scripts, you need
11238 to be sure they can be run during this file system creation.
11239 </para>
11240
11241 <para>
11242 Here are some common problems that prevent
11243 post-installation scripts from running during root filesystem
11244 creation:
11245 <itemizedlist>
11246 <listitem><para>
11247 <emphasis>Not using $D in front of absolute
11248 paths:</emphasis>
11249 The build system defines
11250 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
11251 when the root filesystem is created.
11252 Furthermore, <filename>$D</filename> is blank when the
11253 script is run on the target device.
11254 This implies two purposes for <filename>$D</filename>:
11255 ensuring paths are valid in both the host and target
11256 environments, and checking to determine which
11257 environment is being used as a method for taking
11258 appropriate actions.
11259 </para></listitem>
11260 <listitem><para>
11261 <emphasis>Attempting to run processes that are
11262 specific to or dependent on the target
11263 architecture:</emphasis>
11264 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011265 tools, which run on the host system,
11266 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011267 by alternatively running the processes under QEMU,
11268 which has the <filename>qemu_run_binary</filename>
11269 function.
11270 For more information, see the
11271 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
11272 class.</para></listitem>
11273 </itemizedlist>
11274 </para>
11275 </section>
11276
11277 <section id='areas-with-write-access'>
11278 <title>Areas With Write Access</title>
11279
11280 <para>
11281 With the "read-only-rootfs" feature enabled,
11282 any attempt by the target to write to the root filesystem at
11283 runtime fails.
11284 Consequently, you must make sure that you configure processes
11285 and applications that attempt these types of writes do so
11286 to directories with write access (e.g.
11287 <filename>/tmp</filename> or <filename>/var/run</filename>).
11288 </para>
11289 </section>
11290 </section>
11291
Brad Bishop316dfdd2018-06-25 12:45:53 -040011292
11293
11294
11295 <section id='maintaining-build-output-quality'>
11296 <title>Maintaining Build Output Quality</title>
11297
11298 <para>
11299 Many factors can influence the quality of a build.
11300 For example, if you upgrade a recipe to use a new version of an
11301 upstream software package or you experiment with some new
11302 configuration options, subtle changes can occur that you might
11303 not detect until later.
11304 Consider the case where your recipe is using a newer version of
11305 an upstream package.
11306 In this case, a new version of a piece of software might
11307 introduce an optional dependency on another library, which is
11308 auto-detected.
11309 If that library has already been built when the software is
11310 building, the software will link to the built library and that
11311 library will be pulled into your image along with the new
11312 software even if you did not want the library.
11313 </para>
11314
11315 <para>
11316 The
11317 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
11318 class exists to help you maintain the quality of your build
11319 output.
11320 You can use the class to highlight unexpected and possibly
11321 unwanted changes in the build output.
11322 When you enable build history, it records information about the
11323 contents of each package and image and then commits that
11324 information to a local Git repository where you can examine
11325 the information.
11326 </para>
11327
11328 <para>
11329 The remainder of this section describes the following:
11330 <itemizedlist>
11331 <listitem><para>
11332 How you can enable and disable build history
11333 </para></listitem>
11334 <listitem><para>
11335 How to understand what the build history contains
11336 </para></listitem>
11337 <listitem><para>
11338 How to limit the information used for build history
11339 </para></listitem>
11340 <listitem><para>
11341 How to examine the build history from both a
11342 command-line and web interface
11343 </para></listitem>
11344 </itemizedlist>
11345 </para>
11346
11347 <section id='enabling-and-disabling-build-history'>
11348 <title>Enabling and Disabling Build History</title>
11349
11350 <para>
11351 Build history is disabled by default.
11352 To enable it, add the following <filename>INHERIT</filename>
11353 statement and set the
11354 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
11355 variable to "1" at the end of your
11356 <filename>conf/local.conf</filename> file found in the
11357 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11358 <literallayout class='monospaced'>
11359 INHERIT += "buildhistory"
11360 BUILDHISTORY_COMMIT = "1"
11361 </literallayout>
11362 Enabling build history as previously described causes the
11363 OpenEmbedded build system to collect build output information
11364 and commit it as a single commit to a local
11365 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
11366 repository.
11367 <note>
11368 Enabling build history increases your build times slightly,
11369 particularly for images, and increases the amount of disk
11370 space used during the build.
11371 </note>
11372 </para>
11373
11374 <para>
11375 You can disable build history by removing the previous
11376 statements from your <filename>conf/local.conf</filename>
11377 file.
11378 </para>
11379 </section>
11380
11381 <section id='understanding-what-the-build-history-contains'>
11382 <title>Understanding What the Build History Contains</title>
11383
11384 <para>
11385 Build history information is kept in
11386 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
11387 in the Build Directory as defined by the
11388 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
11389 variable.
11390 The following is an example abbreviated listing:
11391 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
11392 </para>
11393
11394 <para>
11395 At the top level, a <filename>metadata-revs</filename>
11396 file exists that lists the revisions of the repositories for
11397 the enabled layers when the build was produced.
11398 The rest of the data splits into separate
11399 <filename>packages</filename>, <filename>images</filename>
11400 and <filename>sdk</filename> directories, the contents of
11401 which are described as follows.
11402 </para>
11403
11404 <section id='build-history-package-information'>
11405 <title>Build History Package Information</title>
11406
11407 <para>
11408 The history for each package contains a text file that has
11409 name-value pairs with information about the package.
11410 For example,
11411 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
11412 contains the following:
11413 <literallayout class='monospaced'>
11414 PV = 1.22.1
11415 PR = r32
11416 RPROVIDES =
11417 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
11418 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
11419 PKGSIZE = 540168
11420 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
11421 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
11422 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
11423 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
11424 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
11425 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
11426 /etc/busybox.links.nosuid /etc/busybox.links.suid
11427 </literallayout>
11428 Most of these name-value pairs correspond to variables
11429 used to produce the package.
11430 The exceptions are <filename>FILELIST</filename>, which
11431 is the actual list of files in the package, and
11432 <filename>PKGSIZE</filename>, which is the total size of
11433 files in the package in bytes.
11434 </para>
11435
11436 <para>
11437 A file also exists that corresponds to the recipe from
11438 which the package came (e.g.
11439 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
11440 <literallayout class='monospaced'>
11441 PV = 1.22.1
11442 PR = r32
11443 DEPENDS = initscripts kern-tools-native update-rc.d-native \
11444 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
11445 virtual/libc virtual/update-alternatives
11446 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
11447 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
11448 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
11449 </literallayout>
11450 </para>
11451
11452 <para>
11453 Finally, for those recipes fetched from a version control
11454 system (e.g., Git), a file exists that lists source
11455 revisions that are specified in the recipe and lists
11456 the actual revisions used during the build.
11457 Listed and actual revisions might differ when
11458 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
11459 is set to
11460 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
11461 Here is an example assuming
11462 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
11463 <literallayout class='monospaced'>
11464 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11465 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11466 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11467 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11468 </literallayout>
11469 You can use the
11470 <filename>buildhistory-collect-srcrevs</filename>
11471 command with the <filename>-a</filename> option to
11472 collect the stored <filename>SRCREV</filename> values
11473 from build history and report them in a format suitable for
11474 use in global configuration (e.g.,
11475 <filename>local.conf</filename> or a distro include file)
11476 to override floating <filename>AUTOREV</filename> values
11477 to a fixed set of revisions.
11478 Here is some example output from this command:
11479 <literallayout class='monospaced'>
11480 $ buildhistory-collect-srcrevs -a
11481 # i586-poky-linux
11482 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
11483 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
11484 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
11485 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11486 # x86_64-linux
11487 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
11488 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
11489 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
11490 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
11491 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
11492 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
11493 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
11494 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
11495 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11496 # qemux86-poky-linux
11497 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11498 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
11499 # all-poky-linux
11500 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
11501 </literallayout>
11502 <note>
11503 Here are some notes on using the
11504 <filename>buildhistory-collect-srcrevs</filename>
11505 command:
11506 <itemizedlist>
11507 <listitem><para>
11508 By default, only values where the
11509 <filename>SRCREV</filename> was not hardcoded
11510 (usually when <filename>AUTOREV</filename>
11511 is used) are reported.
11512 Use the <filename>-a</filename> option to
11513 see all <filename>SRCREV</filename> values.
11514 </para></listitem>
11515 <listitem><para>
11516 The output statements might not have any effect
11517 if overrides are applied elsewhere in the
11518 build system configuration.
11519 Use the <filename>-f</filename> option to add
11520 the <filename>forcevariable</filename> override
11521 to each output line if you need to work around
11522 this restriction.
11523 </para></listitem>
11524 <listitem><para>
11525 The script does apply special handling when
11526 building for multiple machines.
11527 However, the script does place a comment before
11528 each set of values that specifies which
11529 triplet to which they belong as previously
11530 shown (e.g.,
11531 <filename>i586-poky-linux</filename>).
11532 </para></listitem>
11533 </itemizedlist>
11534 </note>
11535 </para>
11536 </section>
11537
11538 <section id='build-history-image-information'>
11539 <title>Build History Image Information</title>
11540
11541 <para>
11542 The files produced for each image are as follows:
11543 <itemizedlist>
11544 <listitem><para>
11545 <filename>image-files:</filename>
11546 A directory containing selected files from the root
11547 filesystem.
11548 The files are defined by
11549 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
11550 </para></listitem>
11551 <listitem><para>
11552 <filename>build-id.txt:</filename>
11553 Human-readable information about the build
11554 configuration and metadata source revisions.
11555 This file contains the full build header as printed
11556 by BitBake.
11557 </para></listitem>
11558 <listitem><para>
11559 <filename>*.dot:</filename>
11560 Dependency graphs for the image that are
11561 compatible with <filename>graphviz</filename>.
11562 </para></listitem>
11563 <listitem><para>
11564 <filename>files-in-image.txt:</filename>
11565 A list of files in the image with permissions,
11566 owner, group, size, and symlink information.
11567 </para></listitem>
11568 <listitem><para>
11569 <filename>image-info.txt:</filename>
11570 A text file containing name-value pairs with
11571 information about the image.
11572 See the following listing example for more
11573 information.
11574 </para></listitem>
11575 <listitem><para>
11576 <filename>installed-package-names.txt:</filename>
11577 A list of installed packages by name only.
11578 </para></listitem>
11579 <listitem><para>
11580 <filename>installed-package-sizes.txt:</filename>
11581 A list of installed packages ordered by size.
11582 </para></listitem>
11583 <listitem><para>
11584 <filename>installed-packages.txt:</filename>
11585 A list of installed packages with full package
11586 filenames.
11587 </para></listitem>
11588 </itemizedlist>
11589 <note>
11590 Installed package information is able to be gathered
11591 and produced even if package management is disabled
11592 for the final image.
11593 </note>
11594 </para>
11595
11596 <para>
11597 Here is an example of <filename>image-info.txt</filename>:
11598 <literallayout class='monospaced'>
11599 DISTRO = poky
11600 DISTRO_VERSION = 1.7
11601 USER_CLASSES = buildstats image-mklibs image-prelink
11602 IMAGE_CLASSES = image_types
11603 IMAGE_FEATURES = debug-tweaks
11604 IMAGE_LINGUAS =
11605 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11606 BAD_RECOMMENDATIONS =
11607 NO_RECOMMENDATIONS =
11608 PACKAGE_EXCLUDE =
11609 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11610 write_image_manifest ; buildhistory_list_installed_image ; \
11611 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11612 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11613 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11614 IMAGESIZE = 6900
11615 </literallayout>
11616 Other than <filename>IMAGESIZE</filename>, which is the
11617 total size of the files in the image in Kbytes, the
11618 name-value pairs are variables that may have influenced the
11619 content of the image.
11620 This information is often useful when you are trying to
11621 determine why a change in the package or file
11622 listings has occurred.
11623 </para>
11624 </section>
11625
11626 <section id='using-build-history-to-gather-image-information-only'>
11627 <title>Using Build History to Gather Image Information Only</title>
11628
11629 <para>
11630 As you can see, build history produces image information,
11631 including dependency graphs, so you can see why something
11632 was pulled into the image.
11633 If you are just interested in this information and not
11634 interested in collecting specific package or SDK
11635 information, you can enable writing only image information
11636 without any history by adding the following to your
11637 <filename>conf/local.conf</filename> file found in the
11638 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11639 <literallayout class='monospaced'>
11640 INHERIT += "buildhistory"
11641 BUILDHISTORY_COMMIT = "0"
11642 BUILDHISTORY_FEATURES = "image"
11643 </literallayout>
11644 Here, you set the
11645 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11646 variable to use the image feature only.
11647 </para>
11648 </section>
11649
11650 <section id='build-history-sdk-information'>
11651 <title>Build History SDK Information</title>
11652
11653 <para>
11654 Build history collects similar information on the contents
11655 of SDKs
11656 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11657 as compared to information it collects for images.
11658 Furthermore, this information differs depending on whether
11659 an extensible or standard SDK is being produced.
11660 </para>
11661
11662 <para>
11663 The following list shows the files produced for SDKs:
11664 <itemizedlist>
11665 <listitem><para>
11666 <filename>files-in-sdk.txt:</filename>
11667 A list of files in the SDK with permissions,
11668 owner, group, size, and symlink information.
11669 This list includes both the host and target parts
11670 of the SDK.
11671 </para></listitem>
11672 <listitem><para>
11673 <filename>sdk-info.txt:</filename>
11674 A text file containing name-value pairs with
11675 information about the SDK.
11676 See the following listing example for more
11677 information.
11678 </para></listitem>
11679 <listitem><para>
11680 <filename>sstate-task-sizes.txt:</filename>
11681 A text file containing name-value pairs with
11682 information about task group sizes
11683 (e.g. <filename>do_populate_sysroot</filename>
11684 tasks have a total size).
11685 The <filename>sstate-task-sizes.txt</filename> file
11686 exists only when an extensible SDK is created.
11687 </para></listitem>
11688 <listitem><para>
11689 <filename>sstate-package-sizes.txt:</filename>
11690 A text file containing name-value pairs with
11691 information for the shared-state packages and
11692 sizes in the SDK.
11693 The <filename>sstate-package-sizes.txt</filename>
11694 file exists only when an extensible SDK is created.
11695 </para></listitem>
11696 <listitem><para>
11697 <filename>sdk-files:</filename>
11698 A folder that contains copies of the files
11699 mentioned in
11700 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11701 files are present in the output.
11702 Additionally, the default value of
11703 <filename>BUILDHISTORY_SDK_FILES</filename> is
11704 specific to the extensible SDK although you can
11705 set it differently if you would like to pull in
11706 specific files from the standard SDK.</para>
11707
11708 <para>The default files are
11709 <filename>conf/local.conf</filename>,
11710 <filename>conf/bblayers.conf</filename>,
11711 <filename>conf/auto.conf</filename>,
11712 <filename>conf/locked-sigs.inc</filename>, and
11713 <filename>conf/devtool.conf</filename>.
11714 Thus, for an extensible SDK, these files get
11715 copied into the <filename>sdk-files</filename>
11716 directory.
11717 </para></listitem>
11718 <listitem><para>
11719 The following information appears under
11720 each of the <filename>host</filename>
11721 and <filename>target</filename> directories
11722 for the portions of the SDK that run on the host
11723 and on the target, respectively:
11724 <note>
11725 The following files for the most part are empty
11726 when producing an extensible SDK because this
11727 type of SDK is not constructed from packages
11728 as is the standard SDK.
11729 </note>
11730 <itemizedlist>
11731 <listitem><para>
11732 <filename>depends.dot:</filename>
11733 Dependency graph for the SDK that is
11734 compatible with
11735 <filename>graphviz</filename>.
11736 </para></listitem>
11737 <listitem><para>
11738 <filename>installed-package-names.txt:</filename>
11739 A list of installed packages by name only.
11740 </para></listitem>
11741 <listitem><para>
11742 <filename>installed-package-sizes.txt:</filename>
11743 A list of installed packages ordered by size.
11744 </para></listitem>
11745 <listitem><para>
11746 <filename>installed-packages.txt:</filename>
11747 A list of installed packages with full
11748 package filenames.
11749 </para></listitem>
11750 </itemizedlist>
11751 </para></listitem>
11752 </itemizedlist>
11753 </para>
11754
11755 <para>
11756 Here is an example of <filename>sdk-info.txt</filename>:
11757 <literallayout class='monospaced'>
11758 DISTRO = poky
11759 DISTRO_VERSION = 1.3+snapshot-20130327
11760 SDK_NAME = poky-glibc-i686-arm
11761 SDK_VERSION = 1.3+snapshot
11762 SDKMACHINE =
11763 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11764 BAD_RECOMMENDATIONS =
11765 SDKSIZE = 352712
11766 </literallayout>
11767 Other than <filename>SDKSIZE</filename>, which is the
11768 total size of the files in the SDK in Kbytes, the
11769 name-value pairs are variables that might have influenced
11770 the content of the SDK.
11771 This information is often useful when you are trying to
11772 determine why a change in the package or file listings
11773 has occurred.
11774 </para>
11775 </section>
11776
11777 <section id='examining-build-history-information'>
11778 <title>Examining Build History Information</title>
11779
11780 <para>
11781 You can examine build history output from the command
11782 line or from a web interface.
11783 </para>
11784
11785 <para>
11786 To see any changes that have occurred (assuming you have
11787 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11788 you can simply use any Git command that allows you to
11789 view the history of a repository.
11790 Here is one method:
11791 <literallayout class='monospaced'>
11792 $ git log -p
11793 </literallayout>
11794 You need to realize, however, that this method does show
11795 changes that are not significant (e.g. a package's size
11796 changing by a few bytes).
11797 </para>
11798
11799 <para>
11800 A command-line tool called
11801 <filename>buildhistory-diff</filename> does exist, though,
11802 that queries the Git repository and prints just the
11803 differences that might be significant in human-readable
11804 form.
11805 Here is an example:
11806 <literallayout class='monospaced'>
11807 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11808 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11809 /etc/anotherpkg.conf was added
11810 /sbin/anotherpkg was added
11811 * (installed-package-names.txt):
11812 * anotherpkg was added
11813 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11814 anotherpkg was added
11815 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11816 * PR changed from "r0" to "r1"
11817 * PV changed from "0.1.10" to "0.1.12"
11818 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11819 * PR changed from "r0" to "r1"
11820 * PV changed from "0.1.10" to "0.1.12"
11821 </literallayout>
11822 <note>
11823 The <filename>buildhistory-diff</filename> tool
11824 requires the <filename>GitPython</filename> package.
11825 Be sure to install it using Pip3 as follows:
11826 <literallayout class='monospaced'>
11827 $ pip3 install GitPython --user
11828 </literallayout>
11829 Alternatively, you can install
11830 <filename>python3-git</filename> using the appropriate
11831 distribution package manager (e.g.
11832 <filename>apt-get</filename>, <filename>dnf</filename>,
11833 or <filename>zipper</filename>).
11834 </note>
11835 </para>
11836
11837 <para>
11838 To see changes to the build history using a web interface,
11839 follow the instruction in the <filename>README</filename>
11840 file here.
11841 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11842 </para>
11843
11844 <para>
11845 Here is a sample screenshot of the interface:
11846 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11847 </para>
11848 </section>
11849 </section>
11850 </section>
11851
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011852 <section id="performing-automated-runtime-testing">
11853 <title>Performing Automated Runtime Testing</title>
11854
11855 <para>
11856 The OpenEmbedded build system makes available a series of automated
11857 tests for images to verify runtime functionality.
11858 You can run these tests on either QEMU or actual target hardware.
11859 Tests are written in Python making use of the
11860 <filename>unittest</filename> module, and the majority of them
11861 run commands on the target system over SSH.
11862 This section describes how you set up the environment to use these
11863 tests, run available tests, and write and add your own tests.
11864 </para>
11865
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011866 <para>
11867 For information on the test and QA infrastructure available
11868 within the Yocto Project, see the
11869 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11870 section in the Yocto Project Reference Manual.
11871 </para>
11872
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011873 <section id='enabling-tests'>
11874 <title>Enabling Tests</title>
11875
11876 <para>
11877 Depending on whether you are planning to run tests using
11878 QEMU or on the hardware, you have to take
11879 different steps to enable the tests.
11880 See the following subsections for information on how to
11881 enable both types of tests.
11882 </para>
11883
11884 <section id='qemu-image-enabling-tests'>
11885 <title>Enabling Runtime Tests on QEMU</title>
11886
11887 <para>
11888 In order to run tests, you need to do the following:
11889 <itemizedlist>
11890 <listitem><para><emphasis>Set up to avoid interaction
11891 with <filename>sudo</filename> for networking:</emphasis>
11892 To accomplish this, you must do one of the
11893 following:
11894 <itemizedlist>
11895 <listitem><para>Add
11896 <filename>NOPASSWD</filename> for your user
11897 in <filename>/etc/sudoers</filename> either for
11898 all commands or just for
11899 <filename>runqemu-ifup</filename>.
11900 You must provide the full path as that can
11901 change if you are using multiple clones of the
11902 source repository.
11903 <note>
11904 On some distributions, you also need to
11905 comment out "Defaults requiretty" in
11906 <filename>/etc/sudoers</filename>.
11907 </note></para></listitem>
11908 <listitem><para>Manually configure a tap interface
11909 for your system.</para></listitem>
11910 <listitem><para>Run as root the script in
11911 <filename>scripts/runqemu-gen-tapdevs</filename>,
11912 which should generate a list of tap devices.
11913 This is the option typically chosen for
11914 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011915 <note><title>Notes</title>
11916 <itemizedlist>
11917 <listitem><para>
11918 Be sure to use an absolute path
11919 when calling this script
11920 with sudo.
11921 </para></listitem>
11922 <listitem><para>
11923 The package recipe
11924 <filename>qemu-helper-native</filename>
11925 is required to run this script.
11926 Build the package using the
11927 following command:
11928 <literallayout class='monospaced'>
11929 $ bitbake qemu-helper-native
11930 </literallayout>
11931 </para></listitem>
11932 </itemizedlist>
11933 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011934 </para></listitem>
11935 </itemizedlist></para></listitem>
11936 <listitem><para><emphasis>Set the
11937 <filename>DISPLAY</filename> variable:</emphasis>
11938 You need to set this variable so that you have an X
11939 server available (e.g. start
11940 <filename>vncserver</filename> for a headless machine).
11941 </para></listitem>
11942 <listitem><para><emphasis>Be sure your host's firewall
11943 accepts incoming connections from
11944 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011945 Some of the tests (in particular DNF tests) start
11946 an HTTP server on a random high number port,
11947 which is used to serve files to the target.
11948 The DNF module serves
11949 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11950 so it can run DNF channel commands.
11951 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011952 must accept incoming connections from 192.168.7.0/24,
11953 which is the default IP range used for tap devices
11954 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011955 <listitem><para><emphasis>Be sure your host has the
11956 correct packages installed:</emphasis>
11957 Depending your host's distribution, you need
11958 to have the following packages installed:
11959 <itemizedlist>
11960 <listitem><para>Ubuntu and Debian:
11961 <filename>sysstat</filename> and
11962 <filename>iproute2</filename>
11963 </para></listitem>
11964 <listitem><para>OpenSUSE:
11965 <filename>sysstat</filename> and
11966 <filename>iproute2</filename>
11967 </para></listitem>
11968 <listitem><para>Fedora:
11969 <filename>sysstat</filename> and
11970 <filename>iproute</filename>
11971 </para></listitem>
11972 <listitem><para>CentOS:
11973 <filename>sysstat</filename> and
11974 <filename>iproute</filename>
11975 </para></listitem>
11976 </itemizedlist>
11977 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011978 </itemizedlist>
11979 </para>
11980
11981 <para>
11982 Once you start running the tests, the following happens:
11983 <orderedlist>
11984 <listitem><para>A copy of the root filesystem is written
11985 to <filename>${WORKDIR}/testimage</filename>.
11986 </para></listitem>
11987 <listitem><para>The image is booted under QEMU using the
11988 standard <filename>runqemu</filename> script.
11989 </para></listitem>
11990 <listitem><para>A default timeout of 500 seconds occurs
11991 to allow for the boot process to reach the login prompt.
11992 You can change the timeout period by setting
11993 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11994 in the <filename>local.conf</filename> file.
11995 </para></listitem>
11996 <listitem><para>Once the boot process is reached and the
11997 login prompt appears, the tests run.
11998 The full boot log is written to
11999 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
12000 </para></listitem>
12001 <listitem><para>Each test module loads in the order found
12002 in <filename>TEST_SUITES</filename>.
12003 You can find the full output of the commands run over
12004 SSH in
12005 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
12006 </para></listitem>
12007 <listitem><para>If no failures occur, the task running the
12008 tests ends successfully.
12009 You can find the output from the
12010 <filename>unittest</filename> in the task log at
12011 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
12012 </para></listitem>
12013 </orderedlist>
12014 </para>
12015 </section>
12016
12017 <section id='hardware-image-enabling-tests'>
12018 <title>Enabling Runtime Tests on Hardware</title>
12019
12020 <para>
12021 The OpenEmbedded build system can run tests on real
12022 hardware, and for certain devices it can also deploy
12023 the image to be tested onto the device beforehand.
12024 </para>
12025
12026 <para>
12027 For automated deployment, a "master image" is installed
12028 onto the hardware once as part of setup.
12029 Then, each time tests are to be run, the following
12030 occurs:
12031 <orderedlist>
12032 <listitem><para>The master image is booted into and
12033 used to write the image to be tested to
12034 a second partition.
12035 </para></listitem>
12036 <listitem><para>The device is then rebooted using an
12037 external script that you need to provide.
12038 </para></listitem>
12039 <listitem><para>The device boots into the image to be
12040 tested.
12041 </para></listitem>
12042 </orderedlist>
12043 </para>
12044
12045 <para>
12046 When running tests (independent of whether the image
12047 has been deployed automatically or not), the device is
12048 expected to be connected to a network on a
12049 pre-determined IP address.
12050 You can either use static IP addresses written into
12051 the image, or set the image to use DHCP and have your
12052 DHCP server on the test network assign a known IP address
12053 based on the MAC address of the device.
12054 </para>
12055
12056 <para>
12057 In order to run tests on hardware, you need to set
12058 <filename>TEST_TARGET</filename> to an appropriate value.
12059 For QEMU, you do not have to change anything, the default
Andrew Geissler82c905d2020-04-13 13:39:40 -050012060 value is "qemu".
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012061 For running tests on hardware, the following options exist:
12062 <itemizedlist>
Andrew Geissler82c905d2020-04-13 13:39:40 -050012063 <listitem><para><emphasis>"simpleremote":</emphasis>
12064 Choose "simpleremote" if you are going to
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012065 run tests on a target system that is already
12066 running the image to be tested and is available
12067 on the network.
Andrew Geissler82c905d2020-04-13 13:39:40 -050012068 You can use "simpleremote" in conjunction
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012069 with either real hardware or an image running
12070 within a separately started QEMU or any
12071 other virtual machine manager.
12072 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012073 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
12074 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012075 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012076 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012077 <filename>core-image-testmaster</filename>
12078 (or something similar) is installed.
12079 Also, your hardware under test must be in a
12080 DHCP-enabled network that gives it the same IP
12081 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012082 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012083 additional requirements and considerations.
12084 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012085 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012086 section, which follows, for more information.
12087 </para></listitem>
12088 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
12089 Choose "BeagleBoneTarget" if you are deploying
12090 images and running tests on the BeagleBone
12091 "Black" or original "White" hardware.
12092 For information on how to use these tests, see the
12093 comments at the top of the BeagleBoneTarget
12094 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
12095 file.
12096 </para></listitem>
12097 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
12098 Choose "EdgeRouterTarget" is you are deploying
12099 images and running tests on the Ubiquiti Networks
12100 EdgeRouter Lite.
12101 For information on how to use these tests, see the
12102 comments at the top of the EdgeRouterTarget
12103 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
12104 file.
12105 </para></listitem>
12106 <listitem><para><emphasis>"GrubTarget":</emphasis>
12107 Choose the "supports deploying images and running
12108 tests on any generic PC that boots using GRUB.
12109 For information on how to use these tests, see the
12110 comments at the top of the GrubTarget
12111 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
12112 file.
12113 </para></listitem>
12114 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
12115 Create your own custom target if you want to run
12116 tests when you are deploying images and running
12117 tests on a custom machine within your BSP layer.
12118 To do this, you need to add a Python unit that
12119 defines the target class under
12120 <filename>lib/oeqa/controllers/</filename> within
12121 your layer.
12122 You must also provide an empty
12123 <filename>__init__.py</filename>.
12124 For examples, see files in
12125 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
12126 </para></listitem>
12127 </itemizedlist>
12128 </para>
12129 </section>
12130
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012131 <section id='selecting-systemdboottarget'>
12132 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012133
12134 <para>
12135 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012136 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012137 in this section.
12138 You can skip down to the
12139 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
12140 section.
12141 </para>
12142
12143 <para>
12144 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012145 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012146 setup of your master image by doing the following:
12147 <orderedlist>
12148 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
12149 Be sure that <filename>EFI_PROVIDER</filename>
12150 is as follows:
12151 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012152 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012153 </literallayout>
12154 </para></listitem>
12155 <listitem><para><emphasis>Build the master image:</emphasis>
12156 Build the <filename>core-image-testmaster</filename>
12157 image.
12158 The <filename>core-image-testmaster</filename>
12159 recipe is provided as an example for a
12160 "master" image and you can customize the image
12161 recipe as you would any other recipe.
12162 </para>
12163 <para>Here are the image recipe requirements:
12164 <itemizedlist>
12165 <listitem><para>Inherits
12166 <filename>core-image</filename>
12167 so that kernel modules are installed.
12168 </para></listitem>
12169 <listitem><para>Installs normal linux utilities
12170 not busybox ones (e.g.
12171 <filename>bash</filename>,
12172 <filename>coreutils</filename>,
12173 <filename>tar</filename>,
12174 <filename>gzip</filename>, and
12175 <filename>kmod</filename>).
12176 </para></listitem>
12177 <listitem><para>Uses a custom
12178 Initial RAM Disk (initramfs) image with a
12179 custom installer.
12180 A normal image that you can install usually
12181 creates a single rootfs partition.
12182 This image uses another installer that
12183 creates a specific partition layout.
12184 Not all Board Support Packages (BSPs)
12185 can use an installer.
12186 For such cases, you need to manually create
12187 the following partition layout on the
12188 target:
12189 <itemizedlist>
12190 <listitem><para>First partition mounted
12191 under <filename>/boot</filename>,
12192 labeled "boot".
12193 </para></listitem>
12194 <listitem><para>The main rootfs
12195 partition where this image gets
12196 installed, which is mounted under
12197 <filename>/</filename>.
12198 </para></listitem>
12199 <listitem><para>Another partition
12200 labeled "testrootfs" where test
12201 images get deployed.
12202 </para></listitem>
12203 </itemizedlist>
12204 </para></listitem>
12205 </itemizedlist>
12206 </para></listitem>
12207 <listitem><para><emphasis>Install image:</emphasis>
12208 Install the image that you just built on the target
12209 system.
12210 </para></listitem>
12211 </orderedlist>
12212 </para>
12213
12214 <para>
12215 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012216 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012217 to set up the test image:
12218 <orderedlist>
12219 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
12220 Make sure you have the following statements in
12221 your <filename>local.conf</filename> file:
12222 <literallayout class='monospaced'>
12223 IMAGE_FSTYPES += "tar.gz"
12224 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012225 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012226 TEST_TARGET_IP = "192.168.2.3"
12227 </literallayout>
12228 </para></listitem>
12229 <listitem><para><emphasis>Build your test image:</emphasis>
12230 Use BitBake to build the image:
12231 <literallayout class='monospaced'>
12232 $ bitbake core-image-sato
12233 </literallayout>
12234 </para></listitem>
12235 </orderedlist>
12236 </para>
12237 </section>
12238
12239 <section id='power-control'>
12240 <title>Power Control</title>
12241
12242 <para>
Andrew Geissler82c905d2020-04-13 13:39:40 -050012243 For most hardware targets other than "simpleremote",
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012244 you can control power:
12245 <itemizedlist>
12246 <listitem><para>
12247 You can use
12248 <filename>TEST_POWERCONTROL_CMD</filename>
12249 together with
12250 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12251 as a command that runs on the host and does power
12252 cycling.
12253 The test code passes one argument to that command:
12254 off, on or cycle (off then on).
12255 Here is an example that could appear in your
12256 <filename>local.conf</filename> file:
12257 <literallayout class='monospaced'>
12258 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
12259 </literallayout>
12260 In this example, the expect script does the
12261 following:
12262 <literallayout class='monospaced'>
12263 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
12264 </literallayout>
12265 It then runs a Python script that controls power
12266 for a label called <filename>nuc1</filename>.
12267 <note>
12268 You need to customize
12269 <filename>TEST_POWERCONTROL_CMD</filename>
12270 and
12271 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12272 for your own setup.
12273 The one requirement is that it accepts
12274 "on", "off", and "cycle" as the last argument.
12275 </note>
12276 </para></listitem>
12277 <listitem><para>
12278 When no command is defined, it connects to the
12279 device over SSH and uses the classic reboot command
12280 to reboot the device.
12281 Classic reboot is fine as long as the machine
12282 actually reboots (i.e. the SSH test has not
12283 failed).
12284 It is useful for scenarios where you have a simple
12285 setup, typically with a single board, and where
12286 some manual interaction is okay from time to time.
12287 </para></listitem>
12288 </itemizedlist>
12289 If you have no hardware to automatically perform power
12290 control but still wish to experiment with automated
12291 hardware testing, you can use the dialog-power-control
12292 script that shows a dialog prompting you to perform the
12293 required power action.
12294 This script requires either KDialog or Zenity to be
12295 installed.
12296 To use this script, set the
12297 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
12298 variable as follows:
12299 <literallayout class='monospaced'>
12300 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
12301 </literallayout>
12302 </para>
12303 </section>
12304
12305 <section id='serial-console-connection'>
12306 <title>Serial Console Connection</title>
12307
12308 <para>
12309 For test target classes requiring a serial console
12310 to interact with the bootloader (e.g. BeagleBoneTarget,
12311 EdgeRouterTarget, and GrubTarget), you need to
12312 specify a command to use to connect to the serial console
12313 of the target machine by using the
12314 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
12315 variable and optionally the
12316 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
12317 variable.
12318 </para>
12319
12320 <para>
12321 These cases could be a serial terminal program if the
12322 machine is connected to a local serial port, or a
12323 <filename>telnet</filename> or
12324 <filename>ssh</filename> command connecting to a remote
12325 console server.
12326 Regardless of the case, the command simply needs to
12327 connect to the serial console and forward that connection
12328 to standard input and output as any normal terminal
12329 program does.
12330 For example, to use the picocom terminal program on
12331 serial device <filename>/dev/ttyUSB0</filename>
12332 at 115200bps, you would set the variable as follows:
12333 <literallayout class='monospaced'>
12334 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
12335 </literallayout>
12336 For local devices where the serial port device disappears
12337 when the device reboots, an additional "serdevtry" wrapper
12338 script is provided.
12339 To use this wrapper, simply prefix the terminal command
12340 with
12341 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
12342 <literallayout class='monospaced'>
12343 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
12344115200 /dev/ttyUSB0"
12345 </literallayout>
12346 </para>
12347 </section>
12348 </section>
12349
12350 <section id="qemu-image-running-tests">
12351 <title>Running Tests</title>
12352
12353 <para>
12354 You can start the tests automatically or manually:
12355 <itemizedlist>
12356 <listitem><para><emphasis>Automatically running tests:</emphasis>
12357 To run the tests automatically after the
12358 OpenEmbedded build system successfully creates an image,
12359 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012360 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012361 variable to "1" in your <filename>local.conf</filename>
12362 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012363 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012364 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012365 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012366 </literallayout>
12367 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012368 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012369 <literallayout class='monospaced'>
12370 bitbake core-image-sato
12371 </literallayout></para></listitem>
12372 <listitem><para><emphasis>Manually running tests:</emphasis>
12373 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012374 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012375 class by editing your <filename>local.conf</filename>
12376 file:
12377 <literallayout class='monospaced'>
12378 INHERIT += "testimage"
12379 </literallayout>
12380 Next, use BitBake to run the tests:
12381 <literallayout class='monospaced'>
12382 bitbake -c testimage <replaceable>image</replaceable>
12383 </literallayout></para></listitem>
12384 </itemizedlist>
12385 </para>
12386
12387 <para>
12388 All test files reside in
12389 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012390 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012391 A test name maps directly to a Python module.
12392 Each test module may contain a number of individual tests.
12393 Tests are usually grouped together by the area
12394 tested (e.g tests for systemd reside in
12395 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
12396 </para>
12397
12398 <para>
12399 You can add tests to any layer provided you place them in the
12400 proper area and you extend
12401 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12402 in the <filename>local.conf</filename> file as normal.
12403 Be sure that tests reside in
12404 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
12405 <note>
12406 Be sure that module names do not collide with module names
12407 used in the default set of test modules in
12408 <filename>meta/lib/oeqa/runtime</filename>.
12409 </note>
12410 </para>
12411
12412 <para>
12413 You can change the set of tests run by appending or overriding
12414 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
12415 variable in <filename>local.conf</filename>.
12416 Each name in <filename>TEST_SUITES</filename> represents a
12417 required test for the image.
12418 Test modules named within <filename>TEST_SUITES</filename>
12419 cannot be skipped even if a test is not suitable for an image
12420 (e.g. running the RPM tests on an image without
12421 <filename>rpm</filename>).
12422 Appending "auto" to <filename>TEST_SUITES</filename> causes the
12423 build system to try to run all tests that are suitable for the
12424 image (i.e. each test module may elect to skip itself).
12425 </para>
12426
12427 <para>
12428 The order you list tests in <filename>TEST_SUITES</filename>
12429 is important and influences test dependencies.
12430 Consequently, tests that depend on other tests should be added
12431 after the test on which they depend.
12432 For example, since the <filename>ssh</filename> test
12433 depends on the
12434 <filename>ping</filename> test, "ssh" needs to come after
12435 "ping" in the list.
12436 The test class provides no re-ordering or dependency handling.
12437 <note>
12438 Each module can have multiple classes with multiple test
12439 methods.
12440 And, Python <filename>unittest</filename> rules apply.
12441 </note>
12442 </para>
12443
12444 <para>
12445 Here are some things to keep in mind when running tests:
12446 <itemizedlist>
12447 <listitem><para>The default tests for the image are defined
12448 as:
12449 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012450 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 -050012451 </literallayout></para></listitem>
12452 <listitem><para>Add your own test to the list of the
12453 by using the following:
12454 <literallayout class='monospaced'>
12455 TEST_SUITES_append = " mytest"
12456 </literallayout></para></listitem>
12457 <listitem><para>Run a specific list of tests as follows:
12458 <literallayout class='monospaced'>
12459 TEST_SUITES = "test1 test2 test3"
12460 </literallayout>
12461 Remember, order is important.
12462 Be sure to place a test that is dependent on another test
12463 later in the order.</para></listitem>
12464 </itemizedlist>
12465 </para>
12466 </section>
12467
12468 <section id="exporting-tests">
12469 <title>Exporting Tests</title>
12470
12471 <para>
12472 You can export tests so that they can run independently of
12473 the build system.
12474 Exporting tests is required if you want to be able to hand
12475 the test execution off to a scheduler.
12476 You can only export tests that are defined in
12477 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
12478 </para>
12479
12480 <para>
12481 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012482 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012483 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012484 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012485 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
12486 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012487 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012488 You can then export the tests with the following BitBake
12489 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012490 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012491 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012492 </literallayout>
12493 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012494 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12495 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012496 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
12497 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012498 <filename>TEST_EXPORT_DIR</filename> variable.
12499 </para>
12500
12501 <para>
12502 You can now run the tests outside of the build environment:
12503 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012504 $ cd tmp/testexport/<replaceable>image</replaceable>
12505 $ ./runexported.py testdata.json
12506 </literallayout>
12507 </para>
12508
12509 <para>
12510 Here is a complete example that shows IP addresses and uses
12511 the <filename>core-image-sato</filename> image:
12512 <literallayout class='monospaced'>
12513 INHERIT +="testexport"
12514 TEST_TARGET_IP = "192.168.7.2"
12515 TEST_SERVER_IP = "192.168.7.1"
12516 </literallayout>
12517 Use BitBake to export the tests:
12518 <literallayout class='monospaced'>
12519 $ bitbake core-image-sato -c testexport
12520 </literallayout>
12521 Run the tests outside of the build environment using the
12522 following:
12523 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012524 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012525 $ ./runexported.py testdata.json
12526 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012527 </para>
12528 </section>
12529
12530 <section id="qemu-image-writing-new-tests">
12531 <title>Writing New Tests</title>
12532
12533 <para>
12534 As mentioned previously, all new test files need to be in the
12535 proper place for the build system to find them.
12536 New tests for additional functionality outside of the core
12537 should be added to the layer that adds the functionality, in
12538 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
12539 (as long as
12540 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12541 is extended in the layer's
12542 <filename>layer.conf</filename> file as normal).
12543 Just remember the following:
12544 <itemizedlist>
12545 <listitem><para>Filenames need to map directly to test
12546 (module) names.
12547 </para></listitem>
12548 <listitem><para>Do not use module names that
12549 collide with existing core tests.
12550 </para></listitem>
12551 <listitem><para>Minimally, an empty
12552 <filename>__init__.py</filename> file must exist
12553 in the runtime directory.
12554 </para></listitem>
12555 </itemizedlist>
12556 </para>
12557
12558 <para>
12559 To create a new test, start by copying an existing module
12560 (e.g. <filename>syslog.py</filename> or
12561 <filename>gcc.py</filename> are good ones to use).
12562 Test modules can use code from
12563 <filename>meta/lib/oeqa/utils</filename>, which are helper
12564 classes.
12565 </para>
12566
12567 <note>
12568 Structure shell commands such that you rely on them and they
12569 return a single code for success.
12570 Be aware that sometimes you will need to parse the output.
12571 See the <filename>df.py</filename> and
12572 <filename>date.py</filename> modules for examples.
12573 </note>
12574
12575 <para>
12576 You will notice that all test classes inherit
12577 <filename>oeRuntimeTest</filename>, which is found in
12578 <filename>meta/lib/oetest.py</filename>.
12579 This base class offers some helper attributes, which are
12580 described in the following sections:
12581 </para>
12582
12583 <section id='qemu-image-writing-tests-class-methods'>
12584 <title>Class Methods</title>
12585
12586 <para>
12587 Class methods are as follows:
12588 <itemizedlist>
12589 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12590 Returns "True" if <filename>pkg</filename> is in the
12591 installed package list of the image, which is based
12592 on the manifest file that is generated during the
12593 <filename>do_rootfs</filename> task.
12594 </para></listitem>
12595 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12596 Returns "True" if the feature is in
12597 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12598 or
12599 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12600 </para></listitem>
12601 </itemizedlist>
12602 </para>
12603 </section>
12604
12605 <section id='qemu-image-writing-tests-class-attributes'>
12606 <title>Class Attributes</title>
12607
12608 <para>
12609 Class attributes are as follows:
12610 <itemizedlist>
12611 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12612 Equals "ps -ef" if <filename>procps</filename> is
12613 installed in the image.
12614 Otherwise, <filename>pscmd</filename> equals
12615 "ps" (busybox).
12616 </para></listitem>
12617 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12618 The called test context, which gives access to the
12619 following attributes:
12620 <itemizedlist>
12621 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12622 The BitBake datastore, which allows you to
12623 use stuff such as
12624 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12625 </para></listitem>
12626 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12627 Used internally.
12628 The tests do not need these.
12629 </para></listitem>
12630 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12631 The absolute path to
12632 <filename>meta/lib/oeqa/runtime/files</filename>,
12633 which contains helper files for tests meant
12634 for copying on the target such as small
12635 files written in C for compilation.
12636 </para></listitem>
12637 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12638 The target controller object used to deploy
12639 and start an image on a particular target
Andrew Geissler82c905d2020-04-13 13:39:40 -050012640 (e.g. Qemu, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012641 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012642 Tests usually use the following:
12643 <itemizedlist>
12644 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12645 The target's IP address.
12646 </para></listitem>
12647 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12648 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012649 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012650 suite.
12651 </para></listitem>
12652 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12653 The single, most used method.
12654 This command is a wrapper for:
12655 <filename>ssh root@host "cmd"</filename>.
12656 The command returns a tuple:
12657 (status, output), which are what
12658 their names imply - the return code
12659 of "cmd" and whatever output
12660 it produces.
12661 The optional timeout argument
12662 represents the number of seconds the
12663 test should wait for "cmd" to
12664 return.
12665 If the argument is "None", the
12666 test uses the default instance's
12667 timeout period, which is 300
12668 seconds.
12669 If the argument is "0", the test
12670 runs until the command returns.
12671 </para></listitem>
12672 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12673 <filename>scp localpath root@ip:remotepath</filename>.
12674 </para></listitem>
12675 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12676 <filename>scp root@host:remotepath localpath</filename>.
12677 </para></listitem>
12678 </itemizedlist></para></listitem>
12679 </itemizedlist></para></listitem>
12680 </itemizedlist>
12681 </para>
12682 </section>
12683
12684 <section id='qemu-image-writing-tests-instance-attributes'>
12685 <title>Instance Attributes</title>
12686
12687 <para>
12688 A single instance attribute exists, which is
12689 <filename>target</filename>.
12690 The <filename>target</filename> instance attribute is
12691 identical to the class attribute of the same name, which
12692 is described in the previous section.
12693 This attribute exists as both an instance and class
12694 attribute so tests can use
12695 <filename>self.target.run(cmd)</filename> in instance
12696 methods instead of
12697 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12698 </para>
12699 </section>
12700 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012701
12702 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12703 <title>Installing Packages in the DUT Without the Package Manager</title>
12704
12705 <para>
12706 When a test requires a package built by BitBake, it is possible
12707 to install that package.
12708 Installing the package does not require a package manager be
12709 installed in the device under test (DUT).
12710 It does, however, require an SSH connection and the target must
12711 be using the <filename>sshcontrol</filename> class.
12712 <note>
12713 This method uses <filename>scp</filename> to copy files
12714 from the host to the target, which causes permissions and
12715 special attributes to be lost.
12716 </note>
12717 </para>
12718
12719 <para>
12720 A JSON file is used to define the packages needed by a test.
12721 This file must be in the same path as the file used to define
12722 the tests.
12723 Furthermore, the filename must map directly to the test
12724 module name with a <filename>.json</filename> extension.
12725 </para>
12726
12727 <para>
12728 The JSON file must include an object with the test name as
12729 keys of an object or an array.
12730 This object (or array of objects) uses the following data:
12731 <itemizedlist>
12732 <listitem><para>"pkg" - A mandatory string that is the
12733 name of the package to be installed.
12734 </para></listitem>
12735 <listitem><para>"rm" - An optional boolean, which defaults
12736 to "false", that specifies to remove the package after
12737 the test.
12738 </para></listitem>
12739 <listitem><para>"extract" - An optional boolean, which
12740 defaults to "false", that specifies if the package must
12741 be extracted from the package format.
12742 When set to "true", the package is not automatically
12743 installed into the DUT.
12744 </para></listitem>
12745 </itemizedlist>
12746 </para>
12747
12748 <para>
12749 Following is an example JSON file that handles test "foo"
12750 installing package "bar" and test "foobar" installing
12751 packages "foo" and "bar".
12752 Once the test is complete, the packages are removed from the
12753 DUT.
12754 <literallayout class='monospaced'>
12755 {
12756 "foo": {
12757 "pkg": "bar"
12758 },
12759 "foobar": [
12760 {
12761 "pkg": "foo",
12762 "rm": true
12763 },
12764 {
12765 "pkg": "bar",
12766 "rm": true
12767 }
12768 ]
12769 }
12770 </literallayout>
12771 </para>
12772 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012773 </section>
12774
Brad Bishop316dfdd2018-06-25 12:45:53 -040012775 <section id='usingpoky-debugging-tools-and-techniques'>
12776 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012777
12778 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012779 The exact method for debugging build failures depends on the nature
12780 of the problem and on the system's area from which the bug
12781 originates.
12782 Standard debugging practices such as comparison against the last
12783 known working version with examination of the changes and the
12784 re-application of steps to identify the one causing the problem are
12785 valid for the Yocto Project just as they are for any other system.
12786 Even though it is impossible to detail every possible potential
12787 failure, this section provides some general tips to aid in
12788 debugging given a variety of situations.
12789 <note><title>Tip</title>
12790 A useful feature for debugging is the error reporting tool.
12791 Configuring the Yocto Project to use this tool causes the
12792 OpenEmbedded build system to produce error reporting commands as
12793 part of the console output.
12794 You can enter the commands after the build completes to log
12795 error information into a common database, that can help you
12796 figure out what might be going wrong.
12797 For information on how to enable and use this feature, see the
12798 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12799 section.
12800 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012801 </para>
12802
12803 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012804 The following list shows the debugging topics in the remainder of
12805 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012806 <itemizedlist>
12807 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012808 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12809 describes how to find and view logs from tasks that
12810 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012811 </para></listitem>
12812 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012813 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12814 describes how to use the BitBake <filename>-e</filename>
12815 option to examine variable values after a recipe has been
12816 parsed.
12817 </para></listitem>
12818 <listitem><para>
12819 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12820 describes how to use the
12821 <filename>oe-pkgdata-util</filename> utility to query
12822 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12823 and display package-related information for built
12824 packages.
12825 </para></listitem>
12826 <listitem><para>
12827 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12828 describes how to use the BitBake <filename>-g</filename>
12829 option to display recipe dependency information used
12830 during the build.
12831 </para></listitem>
12832 <listitem><para>
12833 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12834 describes how to use the
12835 <filename>bitbake-dumpsig</filename> command in
12836 conjunction with key subdirectories in the
12837 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12838 to determine variable dependencies.
12839 </para></listitem>
12840 <listitem><para>
12841 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12842 describes how to use several BitBake options (e.g.
12843 <filename>-c</filename>, <filename>-C</filename>, and
12844 <filename>-f</filename>) to run specific tasks in the
12845 build chain.
12846 It can be useful to run tasks "out-of-order" when trying
12847 isolate build issues.
12848 </para></listitem>
12849 <listitem><para>
12850 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12851 describes how to use BitBake's <filename>-D</filename>
12852 debug output option to reveal more about what BitBake is
12853 doing during the build.
12854 </para></listitem>
12855 <listitem><para>
12856 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12857 describes how to use the BitBake <filename>-b</filename>
12858 option to build a recipe while ignoring dependencies.
12859 </para></listitem>
12860 <listitem><para>
12861 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12862 describes how to use the many recipe logging functions
12863 to produce debugging output and report errors and warnings.
12864 </para></listitem>
12865 <listitem><para>
12866 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12867 describes how to debug situations where the build consists
12868 of several parts that are run simultaneously and when the
12869 output or result of one part is not ready for use with a
12870 different part of the build that depends on that output.
12871 </para></listitem>
12872 <listitem><para>
12873 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12874 describes how to use GDB to allow you to examine running
12875 programs, which can help you fix problems.
12876 </para></listitem>
12877 <listitem><para>
12878 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12879 describes how to use GDB directly on target hardware for
12880 debugging.
12881 </para></listitem>
12882 <listitem><para>
12883 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12884 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012885 </para></listitem>
12886 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012887 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012888
Brad Bishop316dfdd2018-06-25 12:45:53 -040012889 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12890 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012891
12892 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012893 You can find the log for a task in the file
12894 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12895 For example, the log for the
12896 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12897 task of the QEMU minimal image for the x86 machine
12898 (<filename>qemux86</filename>) might be in
12899 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12900 To see the commands
12901 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12902 ran to generate a log, look at the corresponding
12903 <filename>run.do_</filename><replaceable>taskname</replaceable>
12904 file in the same directory.
12905 </para>
12906
12907 <para>
12908 <filename>log.do_</filename><replaceable>taskname</replaceable>
12909 and
12910 <filename>run.do_</filename><replaceable>taskname</replaceable>
12911 are actually symbolic links to
12912 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12913 and
12914 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12915 where <replaceable>pid</replaceable> is the PID the task had
12916 when it ran.
12917 The symlinks always point to the files corresponding to the most
12918 recent run.
12919 </para>
12920 </section>
12921
12922 <section id='dev-debugging-viewing-variable-values'>
12923 <title>Viewing Variable Values</title>
12924
12925 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040012926 Sometimes you need to know the value of a variable as a
12927 result of BitBake's parsing step.
12928 This could be because some unexpected behavior occurred
12929 in your project.
12930 Perhaps an attempt to
12931 <ulink url='&YOCTO_DOCS_BB_URL;#modifying-existing-variables'>modify a variable</ulink>
12932 did not work out as expected.
12933 </para>
12934
12935 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012936 BitBake's <filename>-e</filename> option is used to display
12937 variable values after parsing.
12938 The following command displays the variable values after the
12939 configuration files (i.e. <filename>local.conf</filename>,
12940 <filename>bblayers.conf</filename>,
12941 <filename>bitbake.conf</filename> and so forth) have been
12942 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012943 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012944 $ bitbake -e
12945 </literallayout>
12946 The following command displays variable values after a specific
12947 recipe has been parsed.
12948 The variables include those from the configuration as well:
12949 <literallayout class='monospaced'>
12950 $ bitbake -e recipename
12951 </literallayout>
12952 <note><para>
12953 Each recipe has its own private set of variables
12954 (datastore).
12955 Internally, after parsing the configuration, a copy of the
12956 resulting datastore is made prior to parsing each recipe.
12957 This copying implies that variables set in one recipe will
12958 not be visible to other recipes.</para>
12959
12960 <para>Likewise, each task within a recipe gets a private
12961 datastore based on the recipe datastore, which means that
12962 variables set within one task will not be visible to
12963 other tasks.</para>
12964 </note>
12965 </para>
12966
12967 <para>
12968 In the output of <filename>bitbake -e</filename>, each
12969 variable is preceded by a description of how the variable
12970 got its value, including temporary values that were later
12971 overriden.
12972 This description also includes variable flags (varflags) set on
12973 the variable.
12974 The output can be very helpful during debugging.
12975 </para>
12976
12977 <para>
12978 Variables that are exported to the environment are preceded by
12979 <filename>export</filename> in the output of
12980 <filename>bitbake -e</filename>.
12981 See the following example:
12982 <literallayout class='monospaced'>
12983 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12984 </literallayout>
12985 </para>
12986
12987 <para>
12988 In addition to variable values, the output of the
12989 <filename>bitbake -e</filename> and
12990 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12991 commands includes the following information:
12992 <itemizedlist>
12993 <listitem><para>
12994 The output starts with a tree listing all configuration
12995 files and classes included globally, recursively listing
12996 the files they include or inherit in turn.
12997 Much of the behavior of the OpenEmbedded build system
12998 (including the behavior of the
12999 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
13000 is implemented in the
13001 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
13002 class and the classes it inherits, rather than being
13003 built into BitBake itself.
13004 </para></listitem>
13005 <listitem><para>
13006 After the variable values, all functions appear in the
13007 output.
13008 For shell functions, variables referenced within the
13009 function body are expanded.
13010 If a function has been modified using overrides or
13011 using override-style operators like
13012 <filename>_append</filename> and
13013 <filename>_prepend</filename>, then the final assembled
13014 function body appears in the output.
13015 </para></listitem>
13016 </itemizedlist>
13017 </para>
13018 </section>
13019
13020 <section id='viewing-package-information-with-oe-pkgdata-util'>
13021 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
13022
13023 <para>
13024 You can use the <filename>oe-pkgdata-util</filename>
13025 command-line utility to query
13026 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
13027 and display various package-related information.
13028 When you use the utility, you must use it to view information
13029 on packages that have already been built.
13030 </para>
13031
13032 <para>
13033 Following are a few of the available
13034 <filename>oe-pkgdata-util</filename> subcommands.
13035 <note>
13036 You can use the standard * and ? globbing wildcards as part
13037 of package names and paths.
13038 </note>
13039 <itemizedlist>
13040 <listitem><para>
13041 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
13042 Lists all packages that have been built, optionally
13043 limiting the match to packages that match
13044 <replaceable>pattern</replaceable>.
13045 </para></listitem>
13046 <listitem><para>
13047 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
13048 Lists the files and directories contained in the given
13049 packages.
13050 <note>
13051 <para>
13052 A different way to view the contents of a package is
13053 to look at the
13054 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
13055 directory of the recipe that generates the
13056 package.
13057 This directory is created by the
13058 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13059 task and has one subdirectory for each package the
13060 recipe generates, which contains the files stored in
13061 that package.</para>
13062 <para>
13063 If you want to inspect the
13064 <filename>${WORKDIR}/packages-split</filename>
13065 directory, make sure that
13066 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
13067 is not enabled when you build the recipe.
13068 </para>
13069 </note>
13070 </para></listitem>
13071 <listitem><para>
13072 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
13073 Lists the names of the packages that contain the given
13074 paths.
13075 For example, the following tells us that
13076 <filename>/usr/share/man/man1/make.1</filename>
13077 is contained in the <filename>make-doc</filename>
13078 package:
13079 <literallayout class='monospaced'>
13080 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
13081 make-doc: /usr/share/man/man1/make.1
13082 </literallayout>
13083 </para></listitem>
13084 <listitem><para>
13085 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
13086 Lists the name of the recipes that
13087 produce the given packages.
13088 </para></listitem>
13089 </itemizedlist>
13090 </para>
13091
13092 <para>
13093 For more information on the <filename>oe-pkgdata-util</filename>
13094 command, use the help facility:
13095 <literallayout class='monospaced'>
13096 $ oe-pkgdata-util &dash;&dash;help
13097 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
13098 </literallayout>
13099 </para>
13100 </section>
13101
13102 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
13103 <title>Viewing Dependencies Between Recipes and Tasks</title>
13104
13105 <para>
13106 Sometimes it can be hard to see why BitBake wants to build other
13107 recipes before the one you have specified.
13108 Dependency information can help you understand why a recipe is
13109 built.
13110 </para>
13111
13112 <para>
13113 To generate dependency information for a recipe, run the
13114 following command:
13115 <literallayout class='monospaced'>
13116 $ bitbake -g <replaceable>recipename</replaceable>
13117 </literallayout>
13118 This command writes the following files in the current
13119 directory:
13120 <itemizedlist>
13121 <listitem><para>
13122 <filename>pn-buildlist</filename>: A list of
13123 recipes/targets involved in building
13124 <replaceable>recipename</replaceable>.
13125 "Involved" here means that at least one task from the
13126 recipe needs to run when building
13127 <replaceable>recipename</replaceable> from scratch.
13128 Targets that are in
13129 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
13130 are not listed.
13131 </para></listitem>
13132 <listitem><para>
13133 <filename>task-depends.dot</filename>: A graph showing
13134 dependencies between tasks.
13135 </para></listitem>
13136 </itemizedlist>
13137 </para>
13138
13139 <para>
13140 The graphs are in
13141 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
13142 format and can be converted to images (e.g. using the
13143 <filename>dot</filename> tool from
13144 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
13145 <note><title>Notes</title>
13146 <itemizedlist>
13147 <listitem><para>
13148 DOT files use a plain text format.
13149 The graphs generated using the
13150 <filename>bitbake -g</filename> command are often so
13151 large as to be difficult to read without special
13152 pruning (e.g. with Bitbake's
13153 <filename>-I</filename> option) and processing.
13154 Despite the form and size of the graphs, the
13155 corresponding <filename>.dot</filename> files can
13156 still be possible to read and provide useful
13157 information.
13158 </para>
13159
13160 <para>As an example, the
13161 <filename>task-depends.dot</filename> file contains
13162 lines such as the following:
13163 <literallayout class='monospaced'>
13164 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
13165 </literallayout>
13166 The above example line reveals that the
13167 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
13168 task in <filename>libxslt</filename> depends on the
13169 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
13170 task in <filename>libxml2</filename>, which is a
13171 normal
13172 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
13173 dependency between the two recipes.
13174 </para></listitem>
13175 <listitem><para>
13176 For an example of how <filename>.dot</filename>
13177 files can be processed, see the
13178 <filename>scripts/contrib/graph-tool</filename>
13179 Python script, which finds and displays paths
13180 between graph nodes.
13181 </para></listitem>
13182 </itemizedlist>
13183 </note>
13184 </para>
13185
13186 <para>
13187 You can use a different method to view dependency information
13188 by using the following command:
13189 <literallayout class='monospaced'>
13190 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
13191 </literallayout>
13192 This command displays a GUI window from which you can view
13193 build-time and runtime dependencies for the recipes involved in
13194 building <replaceable>recipename</replaceable>.
13195 </para>
13196 </section>
13197
13198 <section id='dev-viewing-task-variable-dependencies'>
13199 <title>Viewing Task Variable Dependencies</title>
13200
13201 <para>
13202 As mentioned in the
13203 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
13204 section of the BitBake User Manual, BitBake tries to
13205 automatically determine what variables a task depends on so
13206 that it can rerun the task if any values of the variables
13207 change.
13208 This determination is usually reliable.
13209 However, if you do things like construct variable names at
13210 runtime, then you might have to manually declare dependencies
13211 on those variables using <filename>vardeps</filename> as
13212 described in the
13213 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
13214 section of the BitBake User Manual.
13215 </para>
13216
13217 <para>
13218 If you are unsure whether a variable dependency is being
13219 picked up automatically for a given task, you can list the
13220 variable dependencies BitBake has determined by doing the
13221 following:
13222 <orderedlist>
13223 <listitem><para>
13224 Build the recipe containing the task:
13225 <literallayout class='monospaced'>
13226 $ bitbake <replaceable>recipename</replaceable>
13227 </literallayout>
13228 </para></listitem>
13229 <listitem><para>
13230 Inside the
13231 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
13232 directory, find the signature data
13233 (<filename>sigdata</filename>) file that corresponds
13234 to the task.
13235 The <filename>sigdata</filename> files contain a pickled
13236 Python database of all the metadata that went into
13237 creating the input checksum for the task.
13238 As an example, for the
13239 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
13240 task of the <filename>db</filename> recipe, the
13241 <filename>sigdata</filename> file might be found in the
13242 following location:
13243 <literallayout class='monospaced'>
13244 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13245 </literallayout>
13246 For tasks that are accelerated through the shared state
13247 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
13248 cache, an additional <filename>siginfo</filename> file
13249 is written into
13250 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13251 along with the cached task output.
13252 The <filename>siginfo</filename> files contain exactly
13253 the same information as <filename>sigdata</filename>
13254 files.
13255 </para></listitem>
13256 <listitem><para>
13257 Run <filename>bitbake-dumpsig</filename> on the
13258 <filename>sigdata</filename> or
13259 <filename>siginfo</filename> file.
13260 Here is an example:
13261 <literallayout class='monospaced'>
13262 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13263 </literallayout>
13264 In the output of the above command, you will find a
13265 line like the following, which lists all the (inferred)
13266 variable dependencies for the task.
13267 This list also includes indirect dependencies from
13268 variables depending on other variables, recursively.
13269 <literallayout class='monospaced'>
13270 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
13271 </literallayout>
13272 <note>
13273 Functions (e.g. <filename>base_do_fetch</filename>)
13274 also count as variable dependencies.
13275 These functions in turn depend on the variables they
13276 reference.
13277 </note>
13278 The output of <filename>bitbake-dumpsig</filename> also
13279 includes the value each variable had, a list of
13280 dependencies for each variable, and
13281 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
13282 information.
13283 </para></listitem>
13284 </orderedlist>
13285 </para>
13286
13287 <para>
13288 There is also a <filename>bitbake-diffsigs</filename> command
13289 for comparing two <filename>siginfo</filename> or
13290 <filename>sigdata</filename> files.
13291 This command can be helpful when trying to figure out what
13292 changed between two versions of a task.
13293 If you call <filename>bitbake-diffsigs</filename> with just one
13294 file, the command behaves like
13295 <filename>bitbake-dumpsig</filename>.
13296 </para>
13297
13298 <para>
13299 You can also use BitBake to dump out the signature construction
13300 information without executing tasks by using either of the
13301 following BitBake command-line options:
13302 <literallayout class='monospaced'>
13303 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
13304 -S <replaceable>SIGNATURE_HANDLER</replaceable>
13305 </literallayout>
13306 <note>
13307 Two common values for
13308 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
13309 "printdiff", which dump only the signature or compare the
13310 dumped signature with the cached one, respectively.
13311 </note>
13312 Using BitBake with either of these options causes BitBake to
13313 dump out <filename>sigdata</filename> files in the
13314 <filename>stamps</filename> directory for every task it would
13315 have executed instead of building the specified target package.
13316 </para>
13317 </section>
13318
13319 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
13320 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
13321
13322 <para>
13323 Seeing what metadata went into creating the input signature
13324 of a shared state (sstate) task can be a useful debugging
13325 aid.
13326 This information is available in signature information
13327 (<filename>siginfo</filename>) files in
13328 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
13329 For information on how to view and interpret information in
13330 <filename>siginfo</filename> files, see the
13331 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
13332 section.
13333 </para>
13334
13335 <para>
13336 For conceptual information on shared state, see the
13337 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
13338 section in the Yocto Project Overview and Concepts Manual.
13339 </para>
13340 </section>
13341
13342 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
13343 <title>Invalidating Shared State to Force a Task to Run</title>
13344
13345 <para>
13346 The OpenEmbedded build system uses
13347 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
13348 and
13349 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
13350 cache to avoid unnecessarily rebuilding tasks.
13351 Collectively, this scheme is known as "shared state code."
13352 </para>
13353
13354 <para>
13355 As with all schemes, this one has some drawbacks.
13356 It is possible that you could make implicit changes to your
13357 code that the checksum calculations do not take into
13358 account.
13359 These implicit changes affect a task's output but do not
13360 trigger the shared state code into rebuilding a recipe.
13361 Consider an example during which a tool changes its output.
13362 Assume that the output of <filename>rpmdeps</filename>
13363 changes.
13364 The result of the change should be that all the
13365 <filename>package</filename> and
13366 <filename>package_write_rpm</filename> shared state cache
13367 items become invalid.
13368 However, because the change to the output is
13369 external to the code and therefore implicit,
13370 the associated shared state cache items do not become
13371 invalidated.
13372 In this case, the build process uses the cached items
13373 rather than running the task again.
13374 Obviously, these types of implicit changes can cause
13375 problems.
13376 </para>
13377
13378 <para>
13379 To avoid these problems during the build, you need to
13380 understand the effects of any changes you make.
13381 Realize that changes you make directly to a function
13382 are automatically factored into the checksum calculation.
13383 Thus, these explicit changes invalidate the associated
13384 area of shared state cache.
13385 However, you need to be aware of any implicit changes that
13386 are not obvious changes to the code and could affect
13387 the output of a given task.
13388 </para>
13389
13390 <para>
13391 When you identify an implicit change, you can easily
13392 take steps to invalidate the cache and force the tasks
13393 to run.
13394 The steps you can take are as simple as changing a
13395 function's comments in the source code.
13396 For example, to invalidate package shared state files,
13397 change the comment statements of
13398 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13399 or the comments of one of the functions it calls.
13400 Even though the change is purely cosmetic, it causes the
13401 checksum to be recalculated and forces the build system to
13402 run the task again.
13403 <note>
13404 For an example of a commit that makes a cosmetic
13405 change to invalidate shared state, see this
13406 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
13407 </note>
13408 </para>
13409 </section>
13410
13411 <section id='dev-debugging-taskrunning'>
13412 <title>Running Specific Tasks</title>
13413
13414 <para>
13415 Any given recipe consists of a set of tasks.
13416 The standard BitBake behavior in most cases is:
13417 <filename>do_fetch</filename>,
13418 <filename>do_unpack</filename>,
13419 <filename>do_patch</filename>,
13420 <filename>do_configure</filename>,
13421 <filename>do_compile</filename>,
13422 <filename>do_install</filename>,
13423 <filename>do_package</filename>,
13424 <filename>do_package_write_*</filename>, and
13425 <filename>do_build</filename>.
13426 The default task is <filename>do_build</filename> and any tasks
13427 on which it depends build first.
13428 Some tasks, such as <filename>do_devshell</filename>, are not
13429 part of the default build chain.
13430 If you wish to run a task that is not part of the default build
13431 chain, you can use the <filename>-c</filename> option in
13432 BitBake.
13433 Here is an example:
13434 <literallayout class='monospaced'>
13435 $ bitbake matchbox-desktop -c devshell
13436 </literallayout>
13437 </para>
13438
13439 <para>
13440 The <filename>-c</filename> option respects task dependencies,
13441 which means that all other tasks (including tasks from other
13442 recipes) that the specified task depends on will be run before
13443 the task.
13444 Even when you manually specify a task to run with
13445 <filename>-c</filename>, BitBake will only run the task if it
13446 considers it "out of date".
13447 See the
13448 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
13449 section in the Yocto Project Overview and Concepts Manual for
13450 how BitBake determines whether a task is "out of date".
13451 </para>
13452
13453 <para>
13454 If you want to force an up-to-date task to be rerun (e.g.
13455 because you made manual modifications to the recipe's
13456 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
13457 that you want to try out), then you can use the
13458 <filename>-f</filename> option.
13459 <note>
13460 The reason <filename>-f</filename> is never required when
13461 running the
13462 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
13463 task is because the
13464 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
13465 variable flag is already set for the task.
13466 </note>
13467 The following example shows one way you can use the
13468 <filename>-f</filename> option:
13469 <literallayout class='monospaced'>
13470 $ bitbake matchbox-desktop
13471 .
13472 .
13473 make some changes to the source code in the work directory
13474 .
13475 .
13476 $ bitbake matchbox-desktop -c compile -f
13477 $ bitbake matchbox-desktop
13478 </literallayout>
13479 </para>
13480
13481 <para>
13482 This sequence first builds and then recompiles
13483 <filename>matchbox-desktop</filename>.
13484 The last command reruns all tasks (basically the packaging
13485 tasks) after the compile.
13486 BitBake recognizes that the <filename>do_compile</filename>
13487 task was rerun and therefore understands that the other tasks
13488 also need to be run again.
13489 </para>
13490
13491 <para>
13492 Another, shorter way to rerun a task and all
13493 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
13494 that depend on it is to use the <filename>-C</filename>
13495 option.
13496 <note>
13497 This option is upper-cased and is separate from the
13498 <filename>-c</filename> option, which is lower-cased.
13499 </note>
13500 Using this option invalidates the given task and then runs the
13501 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
13502 task, which is the default task if no task is given, and the
13503 tasks on which it depends.
13504 You could replace the final two commands in the previous example
13505 with the following single command:
13506 <literallayout class='monospaced'>
13507 $ bitbake matchbox-desktop -C compile
13508 </literallayout>
13509 Internally, the <filename>-f</filename> and
13510 <filename>-C</filename> options work by tainting (modifying) the
13511 input checksum of the specified task.
13512 This tainting indirectly causes the task and its
13513 dependent tasks to be rerun through the normal task dependency
13514 mechanisms.
13515 <note>
13516 BitBake explicitly keeps track of which tasks have been
13517 tainted in this fashion, and will print warnings such as the
13518 following for builds involving such tasks:
13519 <literallayout class='monospaced'>
13520 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
13521 </literallayout>
13522 The purpose of the warning is to let you know that the work
13523 directory and build output might not be in the clean state
13524 they would be in for a "normal" build, depending on what
13525 actions you took.
13526 To get rid of such warnings, you can remove the work
13527 directory and rebuild the recipe, as follows:
13528 <literallayout class='monospaced'>
13529 $ bitbake matchbox-desktop -c clean
13530 $ bitbake matchbox-desktop
13531 </literallayout>
13532 </note>
13533 </para>
13534
13535 <para>
13536 You can view a list of tasks in a given package by running the
13537 <filename>do_listtasks</filename> task as follows:
13538 <literallayout class='monospaced'>
13539 $ bitbake matchbox-desktop -c listtasks
13540 </literallayout>
13541 The results appear as output to the console and are also in the
13542 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
13543 </para>
13544 </section>
13545
13546 <section id='dev-debugging-bitbake'>
13547 <title>General BitBake Problems</title>
13548
13549 <para>
13550 You can see debug output from BitBake by using the
13551 <filename>-D</filename> option.
13552 The debug output gives more information about what BitBake
13553 is doing and the reason behind it.
13554 Each <filename>-D</filename> option you use increases the
13555 logging level.
13556 The most common usage is <filename>-DDD</filename>.
13557 </para>
13558
13559 <para>
13560 The output from
13561 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
13562 can reveal why BitBake chose a certain version of a package or
13563 why BitBake picked a certain provider.
13564 This command could also help you in a situation where you think
13565 BitBake did something unexpected.
13566 </para>
13567 </section>
13568
13569 <section id='dev-debugging-buildfile'>
13570 <title>Building with No Dependencies</title>
13571
13572 <para>
13573 To build a specific recipe (<filename>.bb</filename> file),
13574 you can use the following command form:
13575 <literallayout class='monospaced'>
13576 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13577 </literallayout>
13578 This command form does not check for dependencies.
13579 Consequently, you should use it only when you know existing
13580 dependencies have been met.
13581 <note>
13582 You can also specify fragments of the filename.
13583 In this case, BitBake checks for a unique match.
13584 </note>
13585 </para>
13586 </section>
13587
13588 <section id='recipe-logging-mechanisms'>
13589 <title>Recipe Logging Mechanisms</title>
13590
13591 <para>
13592 The Yocto Project provides several logging functions for
13593 producing debugging output and reporting errors and warnings.
13594 For Python functions, the following logging functions exist.
13595 All of these functions log to
13596 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13597 and can also log to standard output (stdout) with the right
13598 settings:
13599 <itemizedlist>
13600 <listitem><para>
13601 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13602 Writes <replaceable>msg</replaceable> as is to the
13603 log while also logging to stdout.
13604 </para></listitem>
13605 <listitem><para>
13606 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13607 Writes "NOTE: <replaceable>msg</replaceable>" to the
13608 log.
13609 Also logs to stdout if BitBake is called with "-v".
13610 </para></listitem>
13611 <listitem><para>
13612 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13613 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13614 log.
13615 Also logs to stdout if the log level is greater than or
13616 equal to <replaceable>level</replaceable>.
13617 See the
13618 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13619 option in the BitBake User Manual for more information.
13620 </para></listitem>
13621 <listitem><para>
13622 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13623 Writes "WARNING: <replaceable>msg</replaceable>" to the
13624 log while also logging to stdout.
13625 </para></listitem>
13626 <listitem><para>
13627 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13628 Writes "ERROR: <replaceable>msg</replaceable>" to the
13629 log while also logging to standard out (stdout).
13630 <note>
13631 Calling this function does not cause the task to fail.
13632 </note>
13633 </para></listitem>
13634 <listitem><para>
13635 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13636 This logging function is similar to
13637 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13638 but also causes the calling task to fail.
13639 <note>
13640 <filename>bb.fatal()</filename> raises an exception,
13641 which means you do not need to put a "return"
13642 statement after the function.
13643 </note>
13644 </para></listitem>
13645 </itemizedlist>
13646 </para>
13647
13648 <para>
13649 The same logging functions are also available in shell
13650 functions, under the names
13651 <filename>bbplain</filename>, <filename>bbnote</filename>,
13652 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13653 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13654 The
13655 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13656 class implements these functions.
13657 See that class in the
13658 <filename>meta/classes</filename> folder of the
13659 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13660 for information.
13661 </para>
13662
13663 <section id='logging-with-python'>
13664 <title>Logging With Python</title>
13665
13666 <para>
13667 When creating recipes using Python and inserting code that
13668 handles build logs, keep in mind the goal is to have
13669 informative logs while keeping the console as "silent" as
13670 possible.
13671 Also, if you want status messages in the log, use the
13672 "debug" loglevel.
13673 </para>
13674
13675 <para>
13676 Following is an example written in Python.
13677 The code handles logging for a function that determines the
13678 number of tasks needed to be run.
13679 See the
13680 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13681 section for additional information:
13682 <literallayout class='monospaced'>
13683 python do_listtasks() {
13684 bb.debug(2, "Starting to figure out the task list")
13685 if noteworthy_condition:
13686 bb.note("There are 47 tasks to run")
13687 bb.debug(2, "Got to point xyz")
13688 if warning_trigger:
13689 bb.warn("Detected warning_trigger, this might be a problem later.")
13690 if recoverable_error:
13691 bb.error("Hit recoverable_error, you really need to fix this!")
13692 if fatal_error:
13693 bb.fatal("fatal_error detected, unable to print the task list")
13694 bb.plain("The tasks present are abc")
13695 bb.debug(2, "Finished figuring out the tasklist")
13696 }
13697 </literallayout>
13698 </para>
13699 </section>
13700
13701 <section id='logging-with-bash'>
13702 <title>Logging With Bash</title>
13703
13704 <para>
13705 When creating recipes using Bash and inserting code that
13706 handles build logs, you have the same goals - informative
13707 with minimal console output.
13708 The syntax you use for recipes written in Bash is similar
13709 to that of recipes written in Python described in the
13710 previous section.
13711 </para>
13712
13713 <para>
13714 Following is an example written in Bash.
13715 The code logs the progress of the <filename>do_my_function</filename> function.
13716 <literallayout class='monospaced'>
13717 do_my_function() {
13718 bbdebug 2 "Running do_my_function"
13719 if [ exceptional_condition ]; then
13720 bbnote "Hit exceptional_condition"
13721 fi
13722 bbdebug 2 "Got to point xyz"
13723 if [ warning_trigger ]; then
13724 bbwarn "Detected warning_trigger, this might cause a problem later."
13725 fi
13726 if [ recoverable_error ]; then
13727 bberror "Hit recoverable_error, correcting"
13728 fi
13729 if [ fatal_error ]; then
13730 bbfatal "fatal_error detected"
13731 fi
13732 bbdebug 2 "Completed do_my_function"
13733 }
13734 </literallayout>
13735 </para>
13736 </section>
13737 </section>
13738
13739 <section id='debugging-parallel-make-races'>
13740 <title>Debugging Parallel Make Races</title>
13741
13742 <para>
13743 A parallel <filename>make</filename> race occurs when the build
13744 consists of several parts that are run simultaneously and
13745 a situation occurs when the output or result of one
13746 part is not ready for use with a different part of the build
13747 that depends on that output.
13748 Parallel make races are annoying and can sometimes be difficult
13749 to reproduce and fix.
13750 However, some simple tips and tricks exist that can help
13751 you debug and fix them.
13752 This section presents a real-world example of an error
13753 encountered on the Yocto Project autobuilder and the process
13754 used to fix it.
13755 <note>
13756 If you cannot properly fix a <filename>make</filename> race
13757 condition, you can work around it by clearing either the
13758 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13759 or
13760 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13761 variables.
13762 </note>
13763 </para>
13764
13765 <section id='the-failure'>
13766 <title>The Failure</title>
13767
13768 <para>
13769 For this example, assume that you are building an image that
13770 depends on the "neard" package.
13771 And, during the build, BitBake runs into problems and
13772 creates the following output.
13773 <note>
13774 This example log file has longer lines artificially
13775 broken to make the listing easier to read.
13776 </note>
13777 If you examine the output or the log file, you see the
13778 failure during <filename>make</filename>:
13779 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013780 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13781 | DEBUG: Executing shell function do_compile
13782 | NOTE: make -j 16
13783 | make --no-print-directory all-am
13784 | /bin/mkdir -p include/near
13785 | /bin/mkdir -p include/near
13786 | /bin/mkdir -p include/near
13787 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13788 0.14-r0/neard-0.14/include/types.h include/near/types.h
13789 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13790 0.14-r0/neard-0.14/include/log.h include/near/log.h
13791 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13792 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13793 | /bin/mkdir -p include/near
13794 | /bin/mkdir -p include/near
13795 | /bin/mkdir -p include/near
13796 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13797 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13798 | /bin/mkdir -p include/near
13799 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13800 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13801 | /bin/mkdir -p include/near
13802 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13803 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13804 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13805 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13806 | /bin/mkdir -p include/near
13807 | /bin/mkdir -p include/near
13808 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13809 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13810 | /bin/mkdir -p include/near
13811 | /bin/mkdir -p include/near
13812 | /bin/mkdir -p include/near
13813 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13814 0.14-r0/neard-0.14/include/device.h include/near/device.h
13815 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13816 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13817 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13818 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13819 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13820 0.14-r0/neard-0.14/include/version.h include/near/version.h
13821 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13822 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13823 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13824 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13825 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13826 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13827 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13828 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13829 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13830 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13831 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13832 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13833 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13834 -o tools/snep-send.o tools/snep-send.c
13835 | In file included from tools/snep-send.c:16:0:
13836 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13837 | #include &lt;near/dbus.h&gt;
13838 | ^
13839 | compilation terminated.
13840 | make[1]: *** [tools/snep-send.o] Error 1
13841 | make[1]: *** Waiting for unfinished jobs....
13842 | make: *** [all] Error 2
13843 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013844 </literallayout>
13845 </para>
13846 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013847
Brad Bishop316dfdd2018-06-25 12:45:53 -040013848 <section id='reproducing-the-error'>
13849 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013850
Brad Bishop316dfdd2018-06-25 12:45:53 -040013851 <para>
13852 Because race conditions are intermittent, they do not
13853 manifest themselves every time you do the build.
13854 In fact, most times the build will complete without problems
13855 even though the potential race condition exists.
13856 Thus, once the error surfaces, you need a way to reproduce
13857 it.
13858 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013859
Brad Bishop316dfdd2018-06-25 12:45:53 -040013860 <para>
13861 In this example, compiling the "neard" package is causing
13862 the problem.
13863 So the first thing to do is build "neard" locally.
13864 Before you start the build, set the
13865 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13866 variable in your <filename>local.conf</filename> file to
13867 a high number (e.g. "-j 20").
13868 Using a high value for <filename>PARALLEL_MAKE</filename>
13869 increases the chances of the race condition showing up:
13870 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013871 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013872 </literallayout>
13873 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013874
Brad Bishop316dfdd2018-06-25 12:45:53 -040013875 <para>
13876 Once the local build for "neard" completes, start a
13877 <filename>devshell</filename> build:
13878 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013879 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013880 </literallayout>
13881 For information on how to use a
13882 <filename>devshell</filename>, see the
13883 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13884 section.
13885 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013886
Brad Bishop316dfdd2018-06-25 12:45:53 -040013887 <para>
13888 In the <filename>devshell</filename>, do the following:
13889 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013890 $ make clean
13891 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013892 </literallayout>
13893 The <filename>devshell</filename> commands cause the failure
13894 to clearly be visible.
13895 In this case, a missing dependency exists for the "neard"
13896 Makefile target.
13897 Here is some abbreviated, sample output with the
13898 missing dependency clearly visible at the end:
13899 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013900 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13901 .
13902 .
13903 .
13904 tools/snep-send.c
13905 In file included from tools/snep-send.c:16:0:
13906 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13907 #include &lt;near/dbus.h&gt;
13908 ^
13909 compilation terminated.
13910 make: *** [tools/snep-send.o] Error 1
13911 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013912 </literallayout>
13913 </para>
13914 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013915
Brad Bishop316dfdd2018-06-25 12:45:53 -040013916 <section id='creating-a-patch-for-the-fix'>
13917 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013918
Brad Bishop316dfdd2018-06-25 12:45:53 -040013919 <para>
13920 Because there is a missing dependency for the Makefile
13921 target, you need to patch the
13922 <filename>Makefile.am</filename> file, which is generated
13923 from <filename>Makefile.in</filename>.
13924 You can use Quilt to create the patch:
13925 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013926 $ quilt new parallelmake.patch
13927 Patch patches/parallelmake.patch is now on top
13928 $ quilt add Makefile.am
13929 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013930 </literallayout>
13931 For more information on using Quilt, see the
13932 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13933 section.
13934 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013935
Brad Bishop316dfdd2018-06-25 12:45:53 -040013936 <para>
13937 At this point you need to make the edits to
13938 <filename>Makefile.am</filename> to add the missing
13939 dependency.
13940 For our example, you have to add the following line
13941 to the file:
13942 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013943 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013944 </literallayout>
13945 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013946
Brad Bishop316dfdd2018-06-25 12:45:53 -040013947 <para>
13948 Once you have edited the file, use the
13949 <filename>refresh</filename> command to create the patch:
13950 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013951 $ quilt refresh
13952 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013953 </literallayout>
13954 Once the patch file exists, you need to add it back to the
13955 originating recipe folder.
13956 Here is an example assuming a top-level
13957 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13958 named <filename>poky</filename>:
13959 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013960 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013961 </literallayout>
13962 The final thing you need to do to implement the fix in the
13963 build is to update the "neard" recipe (i.e.
13964 <filename>neard-0.14.bb</filename>) so that the
13965 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13966 statement includes the patch file.
13967 The recipe file is in the folder above the patch.
13968 Here is what the edited <filename>SRC_URI</filename>
13969 statement would look like:
13970 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013971 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13972 file://neard.in \
13973 file://neard.service.in \
13974 file://parallelmake.patch \
13975 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013976 </literallayout>
13977 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013978
Brad Bishop316dfdd2018-06-25 12:45:53 -040013979 <para>
13980 With the patch complete and moved to the correct folder and
13981 the <filename>SRC_URI</filename> statement updated, you can
13982 exit the <filename>devshell</filename>:
13983 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013984 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013985 </literallayout>
13986 </para>
13987 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013988
Brad Bishop316dfdd2018-06-25 12:45:53 -040013989 <section id='testing-the-build'>
13990 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013991
Brad Bishop316dfdd2018-06-25 12:45:53 -040013992 <para>
13993 With everything in place, you can get back to trying the
13994 build again locally:
13995 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013996 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013997 </literallayout>
13998 This build should succeed.
13999 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014000
Brad Bishop316dfdd2018-06-25 12:45:53 -040014001 <para>
14002 Now you can open up a <filename>devshell</filename> again
14003 and repeat the clean and make operations as follows:
14004 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014005 $ bitbake neard -c devshell
14006 $ make clean
14007 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040014008 </literallayout>
14009 The build should work without issue.
14010 </para>
14011
14012 <para>
14013 As with all solved problems, if they originated upstream,
14014 you need to submit the fix for the recipe in OE-Core and
14015 upstream so that the problem is taken care of at its
14016 source.
14017 See the
14018 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
14019 section for more information.
14020 </para>
14021 </section>
14022 </section>
14023
14024 <section id="platdev-gdb-remotedebug">
14025 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
14026
14027 <para>
14028 GDB allows you to examine running programs, which in turn helps
14029 you to understand and fix problems.
14030 It also allows you to perform post-mortem style analysis of
14031 program crashes.
14032 GDB is available as a package within the Yocto Project and is
14033 installed in SDK images by default.
14034 See the
14035 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
14036 chapter in the Yocto Project Reference Manual for a description of
14037 these images.
14038 You can find information on GDB at
14039 <ulink url="http://sourceware.org/gdb/"/>.
14040 <note><title>Tip</title>
14041 For best results, install debug (<filename>-dbg</filename>)
14042 packages for the applications you are going to debug.
14043 Doing so makes extra debug symbols available that give you
14044 more meaningful output.
14045 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014046 </para>
14047
14048 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014049 Sometimes, due to memory or disk space constraints, it is not
14050 possible to use GDB directly on the remote target to debug
14051 applications.
14052 These constraints arise because GDB needs to load the debugging
14053 information and the binaries of the process being debugged.
14054 Additionally, GDB needs to perform many computations to locate
14055 information such as function names, variable names and values,
14056 stack traces and so forth - even before starting the debugging
14057 process.
14058 These extra computations place more load on the target system
14059 and can alter the characteristics of the program being debugged.
14060 </para>
14061
14062 <para>
14063 To help get past the previously mentioned constraints, you can
14064 use gdbserver, which runs on the remote target and does not
14065 load any debugging information from the debugged process.
14066 Instead, a GDB instance processes the debugging information that
14067 is run on a remote computer - the host GDB.
14068 The host GDB then sends control commands to gdbserver to make
14069 it stop or start the debugged program, as well as read or write
14070 memory regions of that debugged program.
14071 All the debugging information loaded and processed as well
14072 as all the heavy debugging is done by the host GDB.
14073 Offloading these processes gives the gdbserver running on the
14074 target a chance to remain small and fast.
14075 </para>
14076
14077 <para>
14078 Because the host GDB is responsible for loading the debugging
14079 information and for doing the necessary processing to make
14080 actual debugging happen, you have to make sure the host can
14081 access the unstripped binaries complete with their debugging
14082 information and also be sure the target is compiled with no
14083 optimizations.
14084 The host GDB must also have local access to all the libraries
14085 used by the debugged program.
14086 Because gdbserver does not need any local debugging information,
14087 the binaries on the remote target can remain stripped.
14088 However, the binaries must also be compiled without optimization
14089 so they match the host's binaries.
14090 </para>
14091
14092 <para>
14093 To remain consistent with GDB documentation and terminology,
14094 the binary being debugged on the remote target machine is
14095 referred to as the "inferior" binary.
14096 For documentation on GDB see the
14097 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
14098 </para>
14099
14100 <para>
14101 The following steps show you how to debug using the GNU project
14102 debugger.
14103 <orderedlist>
14104 <listitem><para>
14105 <emphasis>Configure your build system to construct the
14106 companion debug filesystem:</emphasis></para>
14107
14108 <para>In your <filename>local.conf</filename> file, set
14109 the following:
14110 <literallayout class='monospaced'>
14111 IMAGE_GEN_DEBUGFS = "1"
14112 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
14113 </literallayout>
14114 These options cause the OpenEmbedded build system
14115 to generate a special companion filesystem fragment,
14116 which contains the matching source and debug symbols to
14117 your deployable filesystem.
14118 The build system does this by looking at what is in the
14119 deployed filesystem, and pulling the corresponding
14120 <filename>-dbg</filename> packages.</para>
14121
14122 <para>The companion debug filesystem is not a complete
14123 filesystem, but only contains the debug fragments.
14124 This filesystem must be combined with the full filesystem
14125 for debugging.
14126 Subsequent steps in this procedure show how to combine
14127 the partial filesystem with the full filesystem.
14128 </para></listitem>
14129 <listitem><para>
14130 <emphasis>Configure the system to include gdbserver in
14131 the target filesystem:</emphasis></para>
14132
14133 <para>Make the following addition in either your
14134 <filename>local.conf</filename> file or in an image
14135 recipe:
14136 <literallayout class='monospaced'>
14137 IMAGE_INSTALL_append = “ gdbserver"
14138 </literallayout>
14139 The change makes sure the <filename>gdbserver</filename>
14140 package is included.
14141 </para></listitem>
14142 <listitem><para>
14143 <emphasis>Build the environment:</emphasis></para>
14144
14145 <para>Use the following command to construct the image
14146 and the companion Debug Filesystem:
14147 <literallayout class='monospaced'>
14148 $ bitbake <replaceable>image</replaceable>
14149 </literallayout>
14150 Build the cross GDB component and make it available
14151 for debugging.
14152 Build the SDK that matches the image.
14153 Building the SDK is best for a production build
14154 that can be used later for debugging, especially
14155 during long term maintenance:
14156 <literallayout class='monospaced'>
14157 $ bitbake -c populate_sdk <replaceable>image</replaceable>
14158 </literallayout></para>
14159
14160 <para>Alternatively, you can build the minimal
14161 toolchain components that match the target.
14162 Doing so creates a smaller than typical SDK and only
14163 contains a minimal set of components with which to
14164 build simple test applications, as well as run the
14165 debugger:
14166 <literallayout class='monospaced'>
14167 $ bitbake meta-toolchain
14168 </literallayout></para>
14169
14170 <para>A final method is to build Gdb itself within
14171 the build system:
14172 <literallayout class='monospaced'>
14173 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
14174 </literallayout>
14175 Doing so produces a temporary copy of
14176 <filename>cross-gdb</filename> you can use for
14177 debugging during development.
14178 While this is the quickest approach, the two previous
14179 methods in this step are better when considering
14180 long-term maintenance strategies.
14181 <note>
14182 If you run
14183 <filename>bitbake gdb-cross</filename>, the
14184 OpenEmbedded build system suggests the actual
14185 image (e.g. <filename>gdb-cross-i586</filename>).
14186 The suggestion is usually the actual name you want
14187 to use.
14188 </note>
14189 </para></listitem>
14190 <listitem><para>
14191 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
14192
14193 <para>Run the following commands to set up the
14194 <filename>debugfs</filename>:
14195 <literallayout class='monospaced'>
14196 $ mkdir debugfs
14197 $ cd debugfs
14198 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
14199 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
14200 </literallayout>
14201 </para></listitem>
14202 <listitem><para>
14203 <emphasis>Set up GDB</emphasis></para>
14204
14205 <para>Install the SDK (if you built one) and then
14206 source the correct environment file.
14207 Sourcing the environment file puts the SDK in your
14208 <filename>PATH</filename> environment variable.</para>
14209
14210 <para>If you are using the build system, Gdb is
14211 located in
14212 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
14213 </para></listitem>
14214 <listitem><para>
14215 <emphasis>Boot the target:</emphasis></para>
14216
14217 <para>For information on how to run QEMU, see the
14218 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
14219 <note>
14220 Be sure to verify that your host can access the
14221 target via TCP.
14222 </note>
14223 </para></listitem>
14224 <listitem><para>
14225 <emphasis>Debug a program:</emphasis></para>
14226
14227 <para>Debugging a program involves running gdbserver
14228 on the target and then running Gdb on the host.
14229 The example in this step debugs
14230 <filename>gzip</filename>:
14231 <literallayout class='monospaced'>
14232 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
14233 </literallayout>
14234 For additional gdbserver options, see the
14235 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
14236 </para>
14237
14238 <para>After running gdbserver on the target, you need
14239 to run Gdb on the host and configure it and connect to
14240 the target.
14241 Use these commands:
14242 <literallayout class='monospaced'>
14243 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
14244 $ <replaceable>arch</replaceable>-gdb
14245
14246 (gdb) set sysroot debugfs
14247 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
14248 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
14249 </literallayout>
14250 At this point, everything should automatically load
14251 (i.e. matching binaries, symbols and headers).
14252 <note>
14253 The Gdb <filename>set</filename> commands in the
14254 previous example can be placed into the users
14255 <filename>~/.gdbinit</filename> file.
14256 Upon starting, Gdb automatically runs whatever
14257 commands are in that file.
14258 </note>
14259 </para></listitem>
14260 <listitem><para>
14261 <emphasis>Deploying without a full image
14262 rebuild:</emphasis></para>
14263
14264 <para>In many cases, during development you want a
14265 quick method to deploy a new binary to the target and
14266 debug it, without waiting for a full image build.
14267 </para>
14268
14269 <para>One approach to solving this situation is to
14270 just build the component you want to debug.
14271 Once you have built the component, copy the
14272 executable directly to both the target and the
14273 host <filename>debugfs</filename>.</para>
14274
14275 <para>If the binary is processed through the debug
14276 splitting in OpenEmbedded, you should also
14277 copy the debug items (i.e. <filename>.debug</filename>
14278 contents and corresponding
14279 <filename>/usr/src/debug</filename> files)
14280 from the work directory.
14281 Here is an example:
14282 <literallayout class='monospaced'>
14283 $ bitbake bash
14284 $ bitbake -c devshell bash
14285 $ cd ..
14286 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
14287 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
14288 </literallayout>
14289 </para></listitem>
14290 </orderedlist>
14291 </para>
14292 </section>
14293
14294 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
14295 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
14296
14297 <para>
14298 The previous section addressed using GDB remotely for debugging
14299 purposes, which is the most usual case due to the inherent
14300 hardware limitations on many embedded devices.
14301 However, debugging in the target hardware itself is also
14302 possible with more powerful devices.
14303 This section describes what you need to do in order to support
14304 using GDB to debug on the target hardware.
14305 </para>
14306
14307 <para>
14308 To support this kind of debugging, you need do the following:
14309 <itemizedlist>
14310 <listitem><para>
14311 Ensure that GDB is on the target.
14312 You can do this by adding "gdb" to
14313 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
14314 <literallayout class='monospaced'>
14315 IMAGE_INSTALL_append = " gdb"
14316 </literallayout>
14317 Alternatively, you can add "tools-debug" to
14318 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
14319 <literallayout class='monospaced'>
14320 IMAGE_FEATURES_append = " tools-debug"
14321 </literallayout>
14322 </para></listitem>
14323 <listitem><para>
14324 Ensure that debug symbols are present.
14325 You can make sure these symbols are present by
14326 installing <filename>-dbg</filename>:
14327 <literallayout class='monospaced'>
14328 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
14329 </literallayout>
14330 Alternatively, you can do the following to include all
14331 the debug symbols:
14332 <literallayout class='monospaced'>
14333 IMAGE_FEATURES_append = " dbg-pkgs"
14334 </literallayout>
14335 </para></listitem>
14336 </itemizedlist>
14337 <note>
14338 To improve the debug information accuracy, you can reduce
14339 the level of optimization used by the compiler.
14340 For example, when adding the following line to your
14341 <filename>local.conf</filename> file, you will reduce
14342 optimization from
14343 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
14344 of "-O2" to
14345 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
14346 of "-O -fno-omit-frame-pointer":
14347 <literallayout class='monospaced'>
14348 DEBUG_BUILD = "1"
14349 </literallayout>
14350 Consider that this will reduce the application's performance
14351 and is recommended only for debugging purposes.
14352 </note>
14353 </para>
14354 </section>
14355
14356 <section id='dev-other-debugging-others'>
14357 <title>Other Debugging Tips</title>
14358
14359 <para>
14360 Here are some other tips that you might find useful:
14361 <itemizedlist>
14362 <listitem><para>
14363 When adding new packages, it is worth watching for
14364 undesirable items making their way into compiler command
14365 lines.
14366 For example, you do not want references to local system
14367 files like
14368 <filename>/usr/lib/</filename> or
14369 <filename>/usr/include/</filename>.
14370 </para></listitem>
14371 <listitem><para>
14372 If you want to remove the <filename>psplash</filename>
14373 boot splashscreen,
14374 add <filename>psplash=false</filename> to the kernel
14375 command line.
14376 Doing so prevents <filename>psplash</filename> from
14377 loading and thus allows you to see the console.
14378 It is also possible to switch out of the splashscreen by
14379 switching the virtual console (e.g. Fn+Left or Fn+Right
14380 on a Zaurus).
14381 </para></listitem>
14382 <listitem><para>
14383 Removing
14384 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
14385 (usually <filename>tmp/</filename>, within the
14386 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
14387 can often fix temporary build issues.
14388 Removing <filename>TMPDIR</filename> is usually a
14389 relatively cheap operation, because task output will be
14390 cached in
14391 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
14392 (usually <filename>sstate-cache/</filename>, which is
14393 also in the Build Directory).
14394 <note>
14395 Removing <filename>TMPDIR</filename> might be a
14396 workaround rather than a fix.
14397 Consequently, trying to determine the underlying
14398 cause of an issue before removing the directory is
14399 a good idea.
14400 </note>
14401 </para></listitem>
14402 <listitem><para>
14403 Understanding how a feature is used in practice within
14404 existing recipes can be very helpful.
14405 It is recommended that you configure some method that
14406 allows you to quickly search through files.</para>
14407
14408 <para>Using GNU Grep, you can use the following shell
14409 function to recursively search through common
14410 recipe-related files, skipping binary files,
14411 <filename>.git</filename> directories, and the
14412 Build Directory (assuming its name starts with
14413 "build"):
14414 <literallayout class='monospaced'>
14415 g() {
14416 grep -Ir \
14417 --exclude-dir=.git \
14418 --exclude-dir='build*' \
14419 --include='*.bb*' \
14420 --include='*.inc*' \
14421 --include='*.conf*' \
14422 --include='*.py*' \
14423 "$@"
14424 }
14425 </literallayout>
14426 Following are some usage examples:
14427 <literallayout class='monospaced'>
14428 $ g FOO # Search recursively for "FOO"
14429 $ g -i foo # Search recursively for "foo", ignoring case
14430 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
14431 </literallayout>
14432 If figuring out how some feature works requires a lot of
14433 searching, it might indicate that the documentation
14434 should be extended or improved.
14435 In such cases, consider filing a documentation bug using
14436 the Yocto Project implementation of
14437 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
14438 For information on how to submit a bug against
14439 the Yocto Project, see the Yocto Project Bugzilla
14440 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
14441 and the
14442 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
14443 section.
14444 <note>
14445 The manuals might not be the right place to document
14446 variables that are purely internal and have a
14447 limited scope (e.g. internal variables used to
14448 implement a single <filename>.bbclass</filename>
14449 file).
14450 </note>
14451 </para></listitem>
14452 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014453 </para>
14454 </section>
14455 </section>
14456
Brad Bishop316dfdd2018-06-25 12:45:53 -040014457 <section id='making-changes-to-the-yocto-project'>
14458 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014459
14460 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014461 Because the Yocto Project is an open-source, community-based
14462 project, you can effect changes to the project.
14463 This section presents procedures that show you how to submit
14464 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014465 </para>
14466
Brad Bishop316dfdd2018-06-25 12:45:53 -040014467 <section id='submitting-a-defect-against-the-yocto-project'>
14468 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014469
14470 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014471 Use the Yocto Project implementation of
14472 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
14473 to submit a defect (bug) against the Yocto Project.
14474 For additional information on this implementation of Bugzilla see the
14475 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
14476 section in the Yocto Project Reference Manual.
14477 For more detail on any of the following steps, see the Yocto Project
14478 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014479 </para>
14480
14481 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014482 Use the following general steps to submit a bug"
14483
14484 <orderedlist>
14485 <listitem><para>
14486 Open the Yocto Project implementation of
14487 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
14488 </para></listitem>
14489 <listitem><para>
14490 Click "File a Bug" to enter a new bug.
14491 </para></listitem>
14492 <listitem><para>
14493 Choose the appropriate "Classification", "Product", and
14494 "Component" for which the bug was found.
14495 Bugs for the Yocto Project fall into one of several
14496 classifications, which in turn break down into several
14497 products and components.
14498 For example, for a bug against the
14499 <filename>meta-intel</filename> layer, you would choose
14500 "Build System, Metadata &amp; Runtime", "BSPs", and
14501 "bsps-meta-intel", respectively.
14502 </para></listitem>
14503 <listitem><para>
14504 Choose the "Version" of the Yocto Project for which you found
14505 the bug (e.g. &DISTRO;).
14506 </para></listitem>
14507 <listitem><para>
14508 Determine and select the "Severity" of the bug.
14509 The severity indicates how the bug impacted your work.
14510 </para></listitem>
14511 <listitem><para>
14512 Choose the "Hardware" that the bug impacts.
14513 </para></listitem>
14514 <listitem><para>
14515 Choose the "Architecture" that the bug impacts.
14516 </para></listitem>
14517 <listitem><para>
14518 Choose a "Documentation change" item for the bug.
14519 Fixing a bug might or might not affect the Yocto Project
14520 documentation.
14521 If you are unsure of the impact to the documentation, select
14522 "Don't Know".
14523 </para></listitem>
14524 <listitem><para>
14525 Provide a brief "Summary" of the bug.
14526 Try to limit your summary to just a line or two and be sure
14527 to capture the essence of the bug.
14528 </para></listitem>
14529 <listitem><para>
14530 Provide a detailed "Description" of the bug.
14531 You should provide as much detail as you can about the context,
14532 behavior, output, and so forth that surrounds the bug.
14533 You can even attach supporting files for output from logs by
14534 using the "Add an attachment" button.
14535 </para></listitem>
14536 <listitem><para>
14537 Click the "Submit Bug" button submit the bug.
14538 A new Bugzilla number is assigned to the bug and the defect
14539 is logged in the bug tracking system.
14540 </para></listitem>
14541 </orderedlist>
14542 Once you file a bug, the bug is processed by the Yocto Project Bug
14543 Triage Team and further details concerning the bug are assigned
14544 (e.g. priority and owner).
14545 You are the "Submitter" of the bug and any further categorization,
14546 progress, or comments on the bug result in Bugzilla sending you an
14547 automated email concerning the particular change or progress to the
14548 bug.
14549 </para>
14550 </section>
14551
14552 <section id='how-to-submit-a-change'>
14553 <title>Submitting a Change to the Yocto Project</title>
14554
14555 <para>
14556 Contributions to the Yocto Project and OpenEmbedded are very welcome.
14557 Because the system is extremely configurable and flexible, we recognize
14558 that developers will want to extend, configure or optimize it for
14559 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014560 </para>
14561
14562 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014563 The Yocto Project uses a mailing list and a patch-based workflow
14564 that is similar to the Linux kernel but contains important
14565 differences.
14566 In general, a mailing list exists through which you can submit
14567 patches.
14568 You should send patches to the appropriate mailing list so that they
14569 can be reviewed and merged by the appropriate maintainer.
14570 The specific mailing list you need to use depends on the
14571 location of the code you are changing.
14572 Each component (e.g. layer) should have a
14573 <filename>README</filename> file that indicates where to send
14574 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014575 </para>
14576
14577 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014578 You can send the patch to the mailing list using whichever approach
14579 you feel comfortable with to generate the patch.
14580 Once sent, the patch is usually reviewed by the community at large.
14581 If somebody has concerns with the patch, they will usually voice
14582 their concern over the mailing list.
14583 If a patch does not receive any negative reviews, the maintainer of
14584 the affected layer typically takes the patch, tests it, and then
14585 based on successful testing, merges the patch.
14586 </para>
14587
14588 <para id='figuring-out-the-mailing-list-to-use'>
14589 The "poky" repository, which is the Yocto Project's reference build
14590 environment, is a hybrid repository that contains several
14591 individual pieces (e.g. BitBake, Metadata, documentation,
14592 and so forth) built using the combo-layer tool.
14593 The upstream location used for submitting changes varies by
14594 component:
14595 <itemizedlist>
14596 <listitem><para>
14597 <emphasis>Core Metadata:</emphasis>
14598 Send your patch to the
14599 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14600 mailing list. For example, a change to anything under
14601 the <filename>meta</filename> or
14602 <filename>scripts</filename> directories should be sent
14603 to this mailing list.
14604 </para></listitem>
14605 <listitem><para>
14606 <emphasis>BitBake:</emphasis>
14607 For changes to BitBake (i.e. anything under the
14608 <filename>bitbake</filename> directory), send your patch
14609 to the
14610 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14611 mailing list.
14612 </para></listitem>
14613 <listitem><para>
14614 <emphasis>"meta-*" trees:</emphasis>
14615 These trees contain Metadata.
14616 Use the
14617 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14618 mailing list.
14619 </para></listitem>
14620 </itemizedlist>
14621 </para>
14622
14623 <para>
14624 For changes to other layers hosted in the Yocto Project source
14625 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14626 and the Yocto Project documentation, use the
14627 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14628 general mailing list.
14629 <note>
14630 Sometimes a layer's documentation specifies to use a
14631 particular mailing list.
14632 If so, use that list.
14633 </note>
14634 For additional recipes that do not fit into the core Metadata, you
14635 should determine which layer the recipe should go into and submit
14636 the change in the manner recommended by the documentation (e.g.
14637 the <filename>README</filename> file) supplied with the layer.
14638 If in doubt, please ask on the Yocto general mailing list or on
14639 the openembedded-devel mailing list.
14640 </para>
14641
14642 <para>
14643 You can also push a change upstream and request a maintainer to
14644 pull the change into the component's upstream repository.
14645 You do this by pushing to a contribution repository that is upstream.
14646 See the
14647 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14648 section in the Yocto Project Overview and Concepts Manual for additional
14649 concepts on working in the Yocto Project development environment.
14650 </para>
14651
14652 <para>
14653 Two commonly used testing repositories exist for
14654 OpenEmbedded-Core:
14655 <itemizedlist>
14656 <listitem><para>
14657 <emphasis>"ross/mut" branch:</emphasis>
14658 The "mut" (master-under-test) tree
14659 exists in the <filename>poky-contrib</filename> repository
14660 in the
14661 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14662 </para></listitem>
14663 <listitem><para>
14664 <emphasis>"master-next" branch:</emphasis>
14665 This branch is part of the main
14666 "poky" repository in the Yocto Project source repositories.
14667 </para></listitem>
14668 </itemizedlist>
14669 Maintainers use these branches to test submissions prior to merging
14670 patches.
14671 Thus, you can get an idea of the status of a patch based on
14672 whether the patch has been merged into one of these branches.
14673 <note>
14674 This system is imperfect and changes can sometimes get lost in the
14675 flow.
14676 Asking about the status of a patch or change is reasonable if the
14677 change has been idle for a while with no feedback.
14678 The Yocto Project does have plans to use
14679 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14680 to track the status of patches and also to automatically preview
14681 patches.
14682 </note>
14683 </para>
14684
14685 <para>
14686 The following sections provide procedures for submitting a change.
14687 </para>
14688
14689 <section id='pushing-a-change-upstream'>
14690 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14691
14692 <para>
14693 Follow this procedure to push a change to an upstream "contrib"
14694 Git repository:
14695 <note>
14696 You can find general Git information on how to push a change
14697 upstream in the
14698 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14699 </note>
14700 <orderedlist>
14701 <listitem><para>
14702 <emphasis>Make Your Changes Locally:</emphasis>
14703 Make your changes in your local Git repository.
14704 You should make small, controlled, isolated changes.
14705 Keeping changes small and isolated aids review,
14706 makes merging/rebasing easier and keeps the change
14707 history clean should anyone need to refer to it in
14708 future.
14709 </para></listitem>
14710 <listitem><para>
14711 <emphasis>Stage Your Changes:</emphasis>
14712 Stage your changes by using the <filename>git add</filename>
14713 command on each file you changed.
14714 </para></listitem>
14715 <listitem><para id='making-sure-you-have-correct-commit-information'>
14716 <emphasis>Commit Your Changes:</emphasis>
14717 Commit the change by using the
14718 <filename>git commit</filename> command.
14719 Make sure your commit information follows standards by
14720 following these accepted conventions:
14721 <itemizedlist>
14722 <listitem><para>
14723 Be sure to include a "Signed-off-by:" line in the
14724 same style as required by the Linux kernel.
14725 Adding this line signifies that you, the submitter,
14726 have agreed to the Developer's Certificate of
14727 Origin 1.1 as follows:
14728 <literallayout class='monospaced'>
14729 Developer's Certificate of Origin 1.1
14730
14731 By making a contribution to this project, I certify that:
14732
14733 (a) The contribution was created in whole or in part by me and I
14734 have the right to submit it under the open source license
14735 indicated in the file; or
14736
14737 (b) The contribution is based upon previous work that, to the best
14738 of my knowledge, is covered under an appropriate open source
14739 license and I have the right under that license to submit that
14740 work with modifications, whether created in whole or in part
14741 by me, under the same open source license (unless I am
14742 permitted to submit under a different license), as indicated
14743 in the file; or
14744
14745 (c) The contribution was provided directly to me by some other
14746 person who certified (a), (b) or (c) and I have not modified
14747 it.
14748
14749 (d) I understand and agree that this project and the contribution
14750 are public and that a record of the contribution (including all
14751 personal information I submit with it, including my sign-off) is
14752 maintained indefinitely and may be redistributed consistent with
14753 this project or the open source license(s) involved.
14754 </literallayout>
14755 </para></listitem>
14756 <listitem><para>
14757 Provide a single-line summary of the change.
14758 and,
14759 if more explanation is needed, provide more
14760 detail in the body of the commit.
14761 This summary is typically viewable in the
14762 "shortlist" of changes.
14763 Thus, providing something short and descriptive
14764 that gives the reader a summary of the change is
14765 useful when viewing a list of many commits.
14766 You should prefix this short description with the
14767 recipe name (if changing a recipe), or else with
14768 the short form path to the file being changed.
14769 </para></listitem>
14770 <listitem><para>
14771 For the body of the commit message, provide
14772 detailed information that describes what you
14773 changed, why you made the change, and the approach
14774 you used.
14775 It might also be helpful if you mention how you
14776 tested the change.
14777 Provide as much detail as you can in the body of
14778 the commit message.
14779 <note>
14780 You do not need to provide a more detailed
14781 explanation of a change if the change is
14782 minor to the point of the single line
14783 summary providing all the information.
14784 </note>
14785 </para></listitem>
14786 <listitem><para>
14787 If the change addresses a specific bug or issue
14788 that is associated with a bug-tracking ID,
14789 include a reference to that ID in your detailed
14790 description.
14791 For example, the Yocto Project uses a specific
14792 convention for bug references - any commit that
14793 addresses a specific bug should use the following
14794 form for the detailed description.
14795 Be sure to use the actual bug-tracking ID from
14796 Bugzilla for
14797 <replaceable>bug-id</replaceable>:
14798 <literallayout class='monospaced'>
14799 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14800
14801 <replaceable>detailed description of change</replaceable>
14802 </literallayout>
14803 </para></listitem>
14804 </itemizedlist>
14805 </para></listitem>
14806 <listitem><para>
14807 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14808 If you have arranged for permissions to push to an
14809 upstream contrib repository, push the change to that
14810 repository:
14811 <literallayout class='monospaced'>
14812 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14813 </literallayout>
14814 For example, suppose you have permissions to push into the
14815 upstream <filename>meta-intel-contrib</filename>
14816 repository and you are working in a local branch named
14817 <replaceable>your_name</replaceable><filename>/README</filename>.
14818 The following command pushes your local commits to the
14819 <filename>meta-intel-contrib</filename> upstream
14820 repository and puts the commit in a branch named
14821 <replaceable>your_name</replaceable><filename>/README</filename>:
14822 <literallayout class='monospaced'>
14823 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14824 </literallayout>
14825 </para></listitem>
14826 <listitem><para id='push-determine-who-to-notify'>
14827 <emphasis>Determine Who to Notify:</emphasis>
14828 Determine the maintainer or the mailing list
14829 that you need to notify for the change.</para>
14830
14831 <para>Before submitting any change, you need to be sure
14832 who the maintainer is or what mailing list that you need
14833 to notify.
14834 Use either these methods to find out:
14835 <itemizedlist>
14836 <listitem><para>
14837 <emphasis>Maintenance File:</emphasis>
14838 Examine the <filename>maintainers.inc</filename>
14839 file, which is located in the
14840 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14841 at
14842 <filename>meta/conf/distro/include</filename>,
14843 to see who is responsible for code.
14844 </para></listitem>
14845 <listitem><para>
14846 <emphasis>Search by File:</emphasis>
14847 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14848 you can enter the following command to bring up a
14849 short list of all commits against a specific file:
14850 <literallayout class='monospaced'>
14851 git shortlog -- <replaceable>filename</replaceable>
14852 </literallayout>
14853 Just provide the name of the file for which you
14854 are interested.
14855 The information returned is not ordered by history
14856 but does include a list of everyone who has
14857 committed grouped by name.
14858 From the list, you can see who is responsible for
14859 the bulk of the changes against the file.
14860 </para></listitem>
14861 <listitem><para>
14862 <emphasis>Examine the List of Mailing Lists:</emphasis>
14863 For a list of the Yocto Project and related mailing
14864 lists, see the
14865 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14866 section in the Yocto Project Reference Manual.
14867 </para></listitem>
14868 </itemizedlist>
14869 </para></listitem>
14870 <listitem><para>
14871 <emphasis>Make a Pull Request:</emphasis>
14872 Notify the maintainer or the mailing list that you have
14873 pushed a change by making a pull request.</para>
14874
14875 <para>The Yocto Project provides two scripts that
14876 conveniently let you generate and send pull requests to the
14877 Yocto Project.
14878 These scripts are <filename>create-pull-request</filename>
14879 and <filename>send-pull-request</filename>.
14880 You can find these scripts in the
14881 <filename>scripts</filename> directory within the
14882 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14883 (e.g. <filename>~/poky/scripts</filename>).
14884 </para>
14885
14886 <para>Using these scripts correctly formats the requests
14887 without introducing any whitespace or HTML formatting.
14888 The maintainer that receives your patches either directly
14889 or through the mailing list needs to be able to save and
14890 apply them directly from your emails.
14891 Using these scripts is the preferred method for sending
14892 patches.</para>
14893
14894 <para>First, create the pull request.
14895 For example, the following command runs the script,
14896 specifies the upstream repository in the contrib directory
14897 into which you pushed the change, and provides a subject
14898 line in the created patch files:
14899 <literallayout class='monospaced'>
14900 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14901 </literallayout>
14902 Running this script forms
14903 <filename>*.patch</filename> files in a folder named
14904 <filename>pull-</filename><replaceable>PID</replaceable>
14905 in the current directory.
14906 One of the patch files is a cover letter.</para>
14907
14908 <para>Before running the
14909 <filename>send-pull-request</filename> script, you must
14910 edit the cover letter patch to insert information about
14911 your change.
14912 After editing the cover letter, send the pull request.
14913 For example, the following command runs the script and
14914 specifies the patch directory and email address.
14915 In this example, the email address is a mailing list:
14916 <literallayout class='monospaced'>
14917 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14918 </literallayout>
14919 You need to follow the prompts as the script is
14920 interactive.
14921 <note>
14922 For help on using these scripts, simply provide the
14923 <filename>-h</filename> argument as follows:
14924 <literallayout class='monospaced'>
14925 $ poky/scripts/create-pull-request -h
14926 $ poky/scripts/send-pull-request -h
14927 </literallayout>
14928 </note>
14929 </para></listitem>
14930 </orderedlist>
14931 </para>
14932 </section>
14933
14934 <section id='submitting-a-patch'>
14935 <title>Using Email to Submit a Patch</title>
14936
14937 <para>
14938 You can submit patches without using the
14939 <filename>create-pull-request</filename> and
14940 <filename>send-pull-request</filename> scripts described in the
14941 previous section.
14942 However, keep in mind, the preferred method is to use the scripts.
14943 </para>
14944
14945 <para>
14946 Depending on the components changed, you need to submit the email
14947 to a specific mailing list.
14948 For some guidance on which mailing list to use, see the
14949 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14950 at the beginning of this section.
14951 For a description of all the available mailing lists, see the
14952 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14953 section in the Yocto Project Reference Manual.
14954 </para>
14955
14956 <para>
14957 Here is the general procedure on how to submit a patch through
14958 email without using the scripts:
14959 <orderedlist>
14960 <listitem><para>
14961 <emphasis>Make Your Changes Locally:</emphasis>
14962 Make your changes in your local Git repository.
14963 You should make small, controlled, isolated changes.
14964 Keeping changes small and isolated aids review,
14965 makes merging/rebasing easier and keeps the change
14966 history clean should anyone need to refer to it in
14967 future.
14968 </para></listitem>
14969 <listitem><para>
14970 <emphasis>Stage Your Changes:</emphasis>
14971 Stage your changes by using the <filename>git add</filename>
14972 command on each file you changed.
14973 </para></listitem>
14974 <listitem><para>
14975 <emphasis>Commit Your Changes:</emphasis>
14976 Commit the change by using the
14977 <filename>git commit --signoff</filename> command.
14978 Using the <filename>--signoff</filename> option identifies
14979 you as the person making the change and also satisfies
14980 the Developer's Certificate of Origin (DCO) shown earlier.
14981 </para>
14982
14983 <para>When you form a commit, you must follow certain
14984 standards established by the Yocto Project development
14985 team.
14986 See
14987 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14988 in the previous section for information on how to
14989 provide commit information that meets Yocto Project
14990 commit message standards.
14991 </para></listitem>
14992 <listitem><para>
14993 <emphasis>Format the Commit:</emphasis>
14994 Format the commit into an email message.
14995 To format commits, use the
14996 <filename>git format-patch</filename> command.
14997 When you provide the command, you must include a revision
14998 list or a number of patches as part of the command.
14999 For example, either of these two commands takes your most
15000 recent single commit and formats it as an email message in
15001 the current directory:
15002 <literallayout class='monospaced'>
15003 $ git format-patch -1
15004 </literallayout>
15005 or
15006 <literallayout class='monospaced'>
15007 $ git format-patch HEAD~
15008 </literallayout></para>
15009
15010 <para>After the command is run, the current directory
15011 contains a numbered <filename>.patch</filename> file for
15012 the commit.</para>
15013
15014 <para>If you provide several commits as part of the
15015 command, the <filename>git format-patch</filename> command
15016 produces a series of numbered files in the current
15017 directory – one for each commit.
15018 If you have more than one patch, you should also use the
15019 <filename>--cover</filename> option with the command,
15020 which generates a cover letter as the first "patch" in
15021 the series.
15022 You can then edit the cover letter to provide a
15023 description for the series of patches.
15024 For information on the
15025 <filename>git format-patch</filename> command,
15026 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
15027 using the <filename>man git-format-patch</filename>
15028 command.
15029 <note>
15030 If you are or will be a frequent contributor to the
15031 Yocto Project or to OpenEmbedded, you might consider
15032 requesting a contrib area and the necessary associated
15033 rights.
15034 </note>
15035 </para></listitem>
15036 <listitem><para>
15037 <emphasis>Import the Files Into Your Mail Client:</emphasis>
15038 Import the files into your mail client by using the
15039 <filename>git send-email</filename> command.
15040 <note>
15041 In order to use <filename>git send-email</filename>,
15042 you must have the proper Git packages installed on
15043 your host.
15044 For Ubuntu, Debian, and Fedora the package is
15045 <filename>git-email</filename>.
15046 </note></para>
15047
15048 <para>The <filename>git send-email</filename> command
15049 sends email by using a local or remote Mail Transport Agent
15050 (MTA) such as <filename>msmtp</filename>,
15051 <filename>sendmail</filename>, or through a direct
15052 <filename>smtp</filename> configuration in your Git
15053 <filename>~/.gitconfig</filename> file.
15054 If you are submitting patches through email only, it is
15055 very important that you submit them without any whitespace
15056 or HTML formatting that either you or your mailer
15057 introduces.
15058 The maintainer that receives your patches needs to be able
15059 to save and apply them directly from your emails.
15060 A good way to verify that what you are sending will be
15061 applicable by the maintainer is to do a dry run and send
15062 them to yourself and then save and apply them as the
15063 maintainer would.</para>
15064
15065 <para>The <filename>git send-email</filename> command is
15066 the preferred method for sending your patches using
15067 email since there is no risk of compromising whitespace
15068 in the body of the message, which can occur when you use
15069 your own mail client.
15070 The command also has several options that let you
15071 specify recipients and perform further editing of the
15072 email message.
15073 For information on how to use the
15074 <filename>git send-email</filename> command,
15075 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
15076 the <filename>man git-send-email</filename> command.
15077 </para></listitem>
15078 </orderedlist>
15079 </para>
15080 </section>
15081 </section>
15082 </section>
15083
15084 <section id='working-with-licenses'>
15085 <title>Working With Licenses</title>
15086
15087 <para>
15088 As mentioned in the
15089 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
15090 section in the Yocto Project Overview and Concepts Manual,
15091 open source projects are open to the public and they
15092 consequently have different licensing structures in place.
15093 This section describes the mechanism by which the
15094 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
15095 tracks changes to licensing text and covers how to maintain open
15096 source license compliance during your project's lifecycle.
15097 The section also describes how to enable commercially licensed
15098 recipes, which by default are disabled.
15099 </para>
15100
15101 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
15102 <title>Tracking License Changes</title>
15103
15104 <para>
15105 The license of an upstream project might change in the future.
15106 In order to prevent these changes going unnoticed, the
15107 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
15108 variable tracks changes to the license text. The checksums are
15109 validated at the end of the configure step, and if the
15110 checksums do not match, the build will fail.
15111 </para>
15112
15113 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
15114 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
15115
15116 <para>
15117 The <filename>LIC_FILES_CHKSUM</filename>
15118 variable contains checksums of the license text in the
15119 source code for the recipe.
15120 Following is an example of how to specify
15121 <filename>LIC_FILES_CHKSUM</filename>:
15122 <literallayout class='monospaced'>
15123 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
15124 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
15125 file://licfile2.txt;endline=50;md5=zzzz \
15126 ..."
15127 </literallayout>
15128 <note><title>Notes</title>
15129 <itemizedlist>
15130 <listitem><para>
15131 When using "beginline" and "endline", realize
15132 that line numbering begins with one and not
15133 zero.
15134 Also, the included lines are inclusive (i.e.
15135 lines five through and including 29 in the
15136 previous example for
15137 <filename>licfile1.txt</filename>).
15138 </para></listitem>
15139 <listitem><para>
15140 When a license check fails, the selected license
15141 text is included as part of the QA message.
15142 Using this output, you can determine the exact
15143 start and finish for the needed license text.
15144 </para></listitem>
15145 </itemizedlist>
15146 </note>
15147 </para>
15148
15149 <para>
15150 The build system uses the
15151 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
15152 variable as the default directory when searching files
15153 listed in <filename>LIC_FILES_CHKSUM</filename>.
15154 The previous example employs the default directory.
15155 </para>
15156
15157 <para>
15158 Consider this next example:
15159 <literallayout class='monospaced'>
15160 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
15161 md5=bb14ed3c4cda583abc85401304b5cd4e"
15162 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
15163 </literallayout>
15164 </para>
15165
15166 <para>
15167 The first line locates a file in
15168 <filename>${S}/src/ls.c</filename> and isolates lines five
15169 through 16 as license text.
15170 The second line refers to a file in
15171 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
15172 </para>
15173
15174 <para>
15175 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
15176 mandatory for all recipes, unless the
15177 <filename>LICENSE</filename> variable is set to "CLOSED".
15178 </para>
15179 </section>
15180
15181 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
15182 <title>Explanation of Syntax</title>
15183
15184 <para>
15185 As mentioned in the previous section, the
15186 <filename>LIC_FILES_CHKSUM</filename> variable lists all
15187 the important files that contain the license text for the
15188 source code.
15189 It is possible to specify a checksum for an entire file,
15190 or a specific section of a file (specified by beginning and
15191 ending line numbers with the "beginline" and "endline"
15192 parameters, respectively).
15193 The latter is useful for source files with a license
15194 notice header, README documents, and so forth.
15195 If you do not use the "beginline" parameter, then it is
15196 assumed that the text begins on the first line of the file.
15197 Similarly, if you do not use the "endline" parameter,
15198 it is assumed that the license text ends with the last
15199 line of the file.
15200 </para>
15201
15202 <para>
15203 The "md5" parameter stores the md5 checksum of the license
15204 text.
15205 If the license text changes in any way as compared to
15206 this parameter then a mismatch occurs.
15207 This mismatch triggers a build failure and notifies
15208 the developer.
15209 Notification allows the developer to review and address
15210 the license text changes.
15211 Also note that if a mismatch occurs during the build,
15212 the correct md5 checksum is placed in the build log and
15213 can be easily copied to the recipe.
15214 </para>
15215
15216 <para>
15217 There is no limit to how many files you can specify using
15218 the <filename>LIC_FILES_CHKSUM</filename> variable.
15219 Generally, however, every project requires a few
15220 specifications for license tracking.
15221 Many projects have a "COPYING" file that stores the
15222 license information for all the source code files.
15223 This practice allows you to just track the "COPYING"
15224 file as long as it is kept up to date.
15225 <note><title>Tips</title>
15226 <itemizedlist>
15227 <listitem><para>
15228 If you specify an empty or invalid "md5"
15229 parameter,
15230 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
15231 returns an md5 mis-match
15232 error and displays the correct "md5" parameter
15233 value during the build.
15234 The correct parameter is also captured in
15235 the build log.
15236 </para></listitem>
15237 <listitem><para>
15238 If the whole file contains only license text,
15239 you do not need to use the "beginline" and
15240 "endline" parameters.
15241 </para></listitem>
15242 </itemizedlist>
15243 </note>
15244 </para>
15245 </section>
15246 </section>
15247
15248 <section id="enabling-commercially-licensed-recipes">
15249 <title>Enabling Commercially Licensed Recipes</title>
15250
15251 <para>
15252 By default, the OpenEmbedded build system disables
15253 components that have commercial or other special licensing
15254 requirements.
15255 Such requirements are defined on a
15256 recipe-by-recipe basis through the
15257 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
15258 variable definition in the affected recipe.
15259 For instance, the
15260 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15261 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015262 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015263 LICENSE_FLAGS = "commercial"
15264 </literallayout>
15265 Here is a slightly more complicated example that contains both
15266 an explicit recipe name and version (after variable expansion):
15267 <literallayout class='monospaced'>
15268 LICENSE_FLAGS = "license_${PN}_${PV}"
15269 </literallayout>
15270 In order for a component restricted by a
15271 <filename>LICENSE_FLAGS</filename> definition to be enabled and
15272 included in an image, it needs to have a matching entry in the
15273 global
15274 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
15275 variable, which is a variable typically defined in your
15276 <filename>local.conf</filename> file.
15277 For example, to enable the
15278 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15279 package, you could add either the string
15280 "commercial_gst-plugins-ugly" or the more general string
15281 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
15282 See the
15283 "<link linkend='license-flag-matching'>License Flag Matching</link>"
15284 section for a full
15285 explanation of how <filename>LICENSE_FLAGS</filename> matching
15286 works.
15287 Here is the example:
15288 <literallayout class='monospaced'>
15289 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
15290 </literallayout>
15291 Likewise, to additionally enable the package built from the
15292 recipe containing
15293 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
15294 and assuming that the actual recipe name was
15295 <filename>emgd_1.10.bb</filename>, the following string would
15296 enable that package as well as the original
15297 <filename>gst-plugins-ugly</filename> package:
15298 <literallayout class='monospaced'>
15299 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
15300 </literallayout>
15301 As a convenience, you do not need to specify the complete
15302 license string in the whitelist for every package.
15303 You can use an abbreviated form, which consists
15304 of just the first portion or portions of the license
15305 string before the initial underscore character or characters.
15306 A partial string will match any license that contains the
15307 given string as the first portion of its license.
15308 For example, the following whitelist string will also match
15309 both of the packages previously mentioned as well as any other
15310 packages that have licenses starting with "commercial" or
15311 "license".
15312 <literallayout class='monospaced'>
15313 LICENSE_FLAGS_WHITELIST = "commercial license"
15314 </literallayout>
15315 </para>
15316
15317 <section id="license-flag-matching">
15318 <title>License Flag Matching</title>
15319
15320 <para>
15321 License flag matching allows you to control what recipes
15322 the OpenEmbedded build system includes in the build.
15323 Fundamentally, the build system attempts to match
15324 <filename>LICENSE_FLAGS</filename> strings found in recipes
15325 against <filename>LICENSE_FLAGS_WHITELIST</filename>
15326 strings found in the whitelist.
15327 A match causes the build system to include a recipe in the
15328 build, while failure to find a match causes the build
15329 system to exclude a recipe.
15330 </para>
15331
15332 <para>
15333 In general, license flag matching is simple.
15334 However, understanding some concepts will help you
15335 correctly and effectively use matching.
15336 </para>
15337
15338 <para>
15339 Before a flag
15340 defined by a particular recipe is tested against the
15341 contents of the whitelist, the expanded string
15342 <filename>_${PN}</filename> is appended to the flag.
15343 This expansion makes each
15344 <filename>LICENSE_FLAGS</filename> value recipe-specific.
15345 After expansion, the string is then matched against the
15346 whitelist.
15347 Thus, specifying
15348 <filename>LICENSE_FLAGS = "commercial"</filename>
15349 in recipe "foo", for example, results in the string
15350 <filename>"commercial_foo"</filename>.
15351 And, to create a match, that string must appear in the
15352 whitelist.
15353 </para>
15354
15355 <para>
15356 Judicious use of the <filename>LICENSE_FLAGS</filename>
15357 strings and the contents of the
15358 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
15359 allows you a lot of flexibility for including or excluding
15360 recipes based on licensing.
15361 For example, you can broaden the matching capabilities by
15362 using license flags string subsets in the whitelist.
15363 <note>
15364 When using a string subset, be sure to use the part of
15365 the expanded string that precedes the appended
15366 underscore character (e.g.
15367 <filename>usethispart_1.3</filename>,
15368 <filename>usethispart_1.4</filename>, and so forth).
15369 </note>
15370 For example, simply specifying the string "commercial" in
15371 the whitelist matches any expanded
15372 <filename>LICENSE_FLAGS</filename> definition that starts
15373 with the string "commercial" such as "commercial_foo" and
15374 "commercial_bar", which are the strings the build system
15375 automatically generates for hypothetical recipes named
15376 "foo" and "bar" assuming those recipes simply specify the
15377 following:
15378 <literallayout class='monospaced'>
15379 LICENSE_FLAGS = "commercial"
15380 </literallayout>
15381 Thus, you can choose to exhaustively
15382 enumerate each license flag in the whitelist and
15383 allow only specific recipes into the image, or
15384 you can use a string subset that causes a broader range of
15385 matches to allow a range of recipes into the image.
15386 </para>
15387
15388 <para>
15389 This scheme works even if the
15390 <filename>LICENSE_FLAGS</filename> string already
15391 has <filename>_${PN}</filename> appended.
15392 For example, the build system turns the license flag
15393 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
15394 would match both the general "commercial" and the specific
15395 "commercial_1.2_foo" strings found in the whitelist, as
15396 expected.
15397 </para>
15398
15399 <para>
15400 Here are some other scenarios:
15401 <itemizedlist>
15402 <listitem><para>
15403 You can specify a versioned string in the recipe
15404 such as "commercial_foo_1.2" in a "foo" recipe.
15405 The build system expands this string to
15406 "commercial_foo_1.2_foo".
15407 Combine this license flag with a whitelist that has
15408 the string "commercial" and you match the flag
15409 along with any other flag that starts with the
15410 string "commercial".
15411 </para></listitem>
15412 <listitem><para>
15413 Under the same circumstances, you can use
15414 "commercial_foo" in the whitelist and the build
15415 system not only matches "commercial_foo_1.2" but
15416 also matches any license flag with the string
15417 "commercial_foo", regardless of the version.
15418 </para></listitem>
15419 <listitem><para>
15420 You can be very specific and use both the
15421 package and version parts in the whitelist (e.g.
15422 "commercial_foo_1.2") to specifically match a
15423 versioned recipe.
15424 </para></listitem>
15425 </itemizedlist>
15426 </para>
15427 </section>
15428
15429 <section id="other-variables-related-to-commercial-licenses">
15430 <title>Other Variables Related to Commercial Licenses</title>
15431
15432 <para>
15433 Other helpful variables related to commercial
15434 license handling exist and are defined in the
15435 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
15436 <literallayout class='monospaced'>
15437 COMMERCIAL_AUDIO_PLUGINS ?= ""
15438 COMMERCIAL_VIDEO_PLUGINS ?= ""
15439 </literallayout>
15440 If you want to enable these components, you can do so by
15441 making sure you have statements similar to the following
15442 in your <filename>local.conf</filename> configuration file:
15443 <literallayout class='monospaced'>
15444 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
15445 gst-plugins-ugly-mpegaudioparse"
15446 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
15447 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
15448 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
15449 </literallayout>
15450 Of course, you could also create a matching whitelist
15451 for those components using the more general "commercial"
15452 in the whitelist, but that would also enable all the
15453 other packages with <filename>LICENSE_FLAGS</filename>
15454 containing "commercial", which you may or may not want:
15455 <literallayout class='monospaced'>
15456 LICENSE_FLAGS_WHITELIST = "commercial"
15457 </literallayout>
15458 </para>
15459
15460 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040015461 Specifying audio and video plugins as part of the
Brad Bishop316dfdd2018-06-25 12:45:53 -040015462 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
15463 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
15464 (along with the enabling
15465 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
Brad Bishopc342db32019-05-15 21:57:59 -040015466 plugins or components into built images, thus adding
Brad Bishop316dfdd2018-06-25 12:45:53 -040015467 support for media formats or components.
15468 </para>
15469 </section>
15470 </section>
15471
15472 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
15473 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
15474
15475 <para>
15476 One of the concerns for a development organization using open source
15477 software is how to maintain compliance with various open source
15478 licensing during the lifecycle of the product.
15479 While this section does not provide legal advice or
15480 comprehensively cover all scenarios, it does
15481 present methods that you can use to
15482 assist you in meeting the compliance requirements during a software
15483 release.
15484 </para>
15485
15486 <para>
15487 With hundreds of different open source licenses that the Yocto
15488 Project tracks, it is difficult to know the requirements of each
15489 and every license.
15490 However, the requirements of the major FLOSS licenses can begin
15491 to be covered by
15492 assuming that three main areas of concern exist:
15493 <itemizedlist>
15494 <listitem><para>Source code must be provided.</para></listitem>
15495 <listitem><para>License text for the software must be
15496 provided.</para></listitem>
15497 <listitem><para>Compilation scripts and modifications to the
15498 source code must be provided.
15499 </para></listitem>
15500 </itemizedlist>
15501 There are other requirements beyond the scope of these
15502 three and the methods described in this section
15503 (e.g. the mechanism through which source code is distributed).
15504 </para>
15505
15506 <para>
15507 As different organizations have different methods of complying with
15508 open source licensing, this section is not meant to imply that
15509 there is only one single way to meet your compliance obligations,
15510 but rather to describe one method of achieving compliance.
15511 The remainder of this section describes methods supported to meet the
15512 previously mentioned three requirements.
15513 Once you take steps to meet these requirements,
15514 and prior to releasing images, sources, and the build system,
15515 you should audit all artifacts to ensure completeness.
15516 <note>
15517 The Yocto Project generates a license manifest during
15518 image creation that is located
15519 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
15520 to assist with any audits.
15521 </note>
15522 </para>
15523
15524 <section id='providing-the-source-code'>
15525 <title>Providing the Source Code</title>
15526
15527 <para>
15528 Compliance activities should begin before you generate the
15529 final image.
15530 The first thing you should look at is the requirement that
15531 tops the list for most compliance groups - providing
15532 the source.
15533 The Yocto Project has a few ways of meeting this
15534 requirement.
15535 </para>
15536
15537 <para>
15538 One of the easiest ways to meet this requirement is
15539 to provide the entire
15540 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
15541 used by the build.
15542 This method, however, has a few issues.
15543 The most obvious is the size of the directory since it includes
15544 all sources used in the build and not just the source used in
15545 the released image.
15546 It will include toolchain source, and other artifacts, which
15547 you would not generally release.
15548 However, the more serious issue for most companies is accidental
15549 release of proprietary software.
15550 The Yocto Project provides an
15551 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
15552 class to help avoid some of these concerns.
15553 </para>
15554
15555 <para>
15556 Before you employ <filename>DL_DIR</filename> or the
15557 <filename>archiver</filename> class, you need to decide how
15558 you choose to provide source.
15559 The source <filename>archiver</filename> class can generate
15560 tarballs and SRPMs and can create them with various levels of
15561 compliance in mind.
15562 </para>
15563
15564 <para>
15565 One way of doing this (but certainly not the only way) is to
15566 release just the source as a tarball.
15567 You can do this by adding the following to the
15568 <filename>local.conf</filename> file found in the
15569 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15570 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015571 INHERIT += "archiver"
15572 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015573 </literallayout>
15574 During the creation of your image, the source from all
15575 recipes that deploy packages to the image is placed within
15576 subdirectories of
15577 <filename>DEPLOY_DIR/sources</filename> based on the
15578 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15579 for each recipe.
15580 Releasing the entire directory enables you to comply with
15581 requirements concerning providing the unmodified source.
15582 It is important to note that the size of the directory can
15583 get large.
15584 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015585
Brad Bishop316dfdd2018-06-25 12:45:53 -040015586 <para>
15587 A way to help mitigate the size issue is to only release
15588 tarballs for licenses that require the release of
15589 source.
15590 Let us assume you are only concerned with GPL code as
15591 identified by running the following script:
15592 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015593 # Script to archive a subset of packages matching specific license(s)
15594 # Source and license files are copied into sub folders of package folder
15595 # Must be run from build folder
15596 #!/bin/bash
15597 src_release_dir="source-release"
15598 mkdir -p $src_release_dir
15599 for a in tmp/deploy/sources/*; do
15600 for d in $a/*; do
15601 # Get package name from path
15602 p=`basename $d`
15603 p=${p%-*}
15604 p=${p%-*}
15605 # Only archive GPL packages (update *GPL* regex for your license check)
15606 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15607 if [ $numfiles -gt 1 ]; then
15608 echo Archiving $p
15609 mkdir -p $src_release_dir/$p/source
15610 cp $d/* $src_release_dir/$p/source 2> /dev/null
15611 mkdir -p $src_release_dir/$p/license
15612 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15613 fi
15614 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015615 done
15616 </literallayout>
15617 At this point, you could create a tarball from the
15618 <filename>gpl_source_release</filename> directory and
15619 provide that to the end user.
15620 This method would be a step toward achieving compliance
15621 with section 3a of GPLv2 and with section 6 of GPLv3.
15622 </para>
15623 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015624
Brad Bishop316dfdd2018-06-25 12:45:53 -040015625 <section id='providing-license-text'>
15626 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015627
Brad Bishop316dfdd2018-06-25 12:45:53 -040015628 <para>
15629 One requirement that is often overlooked is inclusion
15630 of license text.
15631 This requirement also needs to be dealt with prior to
15632 generating the final image.
15633 Some licenses require the license text to accompany
15634 the binary.
15635 You can achieve this by adding the following to your
15636 <filename>local.conf</filename> file:
15637 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015638 COPY_LIC_MANIFEST = "1"
15639 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015640 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015641 </literallayout>
15642 Adding these statements to the configuration file ensures
15643 that the licenses collected during package generation
15644 are included on your image.
15645 <note>
15646 <para>Setting all three variables to "1" results in the
15647 image having two copies of the same license file.
15648 One copy resides in
15649 <filename>/usr/share/common-licenses</filename> and
15650 the other resides in
15651 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015652
Brad Bishop316dfdd2018-06-25 12:45:53 -040015653 <para>The reason for this behavior is because
15654 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15655 and
15656 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15657 add a copy of the license when the image is built but do
15658 not offer a path for adding licenses for newly installed
15659 packages to an image.
15660 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15661 adds a separate package and an upgrade path for adding
15662 licenses to an image.</para>
15663 </note>
15664 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015665
Brad Bishop316dfdd2018-06-25 12:45:53 -040015666 <para>
15667 As the source <filename>archiver</filename> class has already
15668 archived the original
15669 unmodified source that contains the license files,
15670 you would have already met the requirements for inclusion
15671 of the license information with source as defined by the GPL
15672 and other open source licenses.
15673 </para>
15674 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015675
Brad Bishop316dfdd2018-06-25 12:45:53 -040015676 <section id='providing-compilation-scripts-and-source-code-modifications'>
15677 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015678
Brad Bishop316dfdd2018-06-25 12:45:53 -040015679 <para>
15680 At this point, we have addressed all we need to
15681 prior to generating the image.
15682 The next two requirements are addressed during the final
15683 packaging of the release.
15684 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015685
Brad Bishop316dfdd2018-06-25 12:45:53 -040015686 <para>
15687 By releasing the version of the OpenEmbedded build system
15688 and the layers used during the build, you will be providing both
15689 compilation scripts and the source code modifications in one
15690 step.
15691 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015692
Brad Bishop316dfdd2018-06-25 12:45:53 -040015693 <para>
15694 If the deployment team has a
15695 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15696 and a distro layer, and those those layers are used to patch,
15697 compile, package, or modify (in any way) any open source
15698 software included in your released images, you
15699 might be required to release those layers under section 3 of
15700 GPLv2 or section 1 of GPLv3.
15701 One way of doing that is with a clean
15702 checkout of the version of the Yocto Project and layers used
15703 during your build.
15704 Here is an example:
15705 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015706 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15707 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015708 $ cd poky
15709 # We built using the release_branch for our layers
15710 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15711 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15712 # clean up the .git repos
15713 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015714 </literallayout>
15715 One thing a development organization might want to consider
15716 for end-user convenience is to modify
15717 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15718 ensure that when the end user utilizes the released build
15719 system to build an image, the development organization's
15720 layers are included in the <filename>bblayers.conf</filename>
15721 file automatically:
15722 <literallayout class='monospaced'>
15723 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015724 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015725 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015726
15727 BBPATH = "${TOPDIR}"
15728 BBFILES ?= ""
15729
15730 BBLAYERS ?= " \
15731 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015732 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015733 ##OEROOT##/meta-yocto-bsp \
15734 ##OEROOT##/meta-mylayer \
15735 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015736 </literallayout>
15737 Creating and providing an archive of the
15738 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15739 layers (recipes, configuration files, and so forth)
15740 enables you to meet your
15741 requirements to include the scripts to control compilation
15742 as well as any modifications to the original source.
15743 </para>
15744 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015745 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015746
15747 <section id='copying-licenses-that-do-not-exist'>
15748 <title>Copying Licenses that Do Not Exist</title>
15749
15750 <para>
15751 Some packages, such as the linux-firmware package, have many
15752 licenses that are not in any way common.
15753 You can avoid adding a lot of these types of common license
15754 files, which are only applicable to a specific package, by using
15755 the
15756 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15757 variable.
15758 Using this variable also avoids QA errors when you use a
15759 non-common, non-CLOSED license in a recipe.
15760 </para>
15761
15762 <para>
15763 The following is an example that uses the
15764 <filename>LICENSE.Abilis.txt</filename>
15765 file as the license from the fetched source:
15766 <literallayout class='monospaced'>
15767 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15768 </literallayout>
15769 </para>
15770 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015771 </section>
15772
15773 <section id='using-the-error-reporting-tool'>
15774 <title>Using the Error Reporting Tool</title>
15775
15776 <para>
15777 The error reporting tool allows you to
15778 submit errors encountered during builds to a central database.
15779 Outside of the build environment, you can use a web interface to
15780 browse errors, view statistics, and query for errors.
15781 The tool works using a client-server system where the client
15782 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015783 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015784 (e.g. <filename>poky</filename>).
15785 The server receives the information collected and saves it in a
15786 database.
15787 </para>
15788
15789 <para>
15790 A live instance of the error reporting server exists at
15791 <ulink url='http://errors.yoctoproject.org'></ulink>.
15792 This server exists so that when you want to get help with
15793 build failures, you can submit all of the information on the
15794 failure easily and then point to the URL in your bug report
15795 or send an email to the mailing list.
15796 <note>
15797 If you send error reports to this server, the reports become
15798 publicly visible.
15799 </note>
15800 </para>
15801
15802 <section id='enabling-and-using-the-tool'>
15803 <title>Enabling and Using the Tool</title>
15804
15805 <para>
15806 By default, the error reporting tool is disabled.
15807 You can enable it by inheriting the
15808 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15809 class by adding the following statement to the end of
15810 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015811 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015812 <literallayout class='monospaced'>
15813 INHERIT += "report-error"
15814 </literallayout>
15815 </para>
15816
15817 <para>
15818 By default, the error reporting feature stores information in
15819 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15820 However, you can specify a directory to use by adding the following
15821 to your <filename>local.conf</filename> file:
15822 <literallayout class='monospaced'>
15823 ERR_REPORT_DIR = "path"
15824 </literallayout>
15825 Enabling error reporting causes the build process to collect
15826 the errors and store them in a file as previously described.
15827 When the build system encounters an error, it includes a
15828 command as part of the console output.
15829 You can run the command to send the error file to the server.
15830 For example, the following command sends the errors to an
15831 upstream server:
15832 <literallayout class='monospaced'>
15833 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15834 </literallayout>
15835 In the previous example, the errors are sent to a public
15836 database available at
15837 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15838 used by the entire community.
15839 If you specify a particular server, you can send the errors
15840 to a different database.
15841 Use the following command for more information on available
15842 options:
15843 <literallayout class='monospaced'>
15844 $ send-error-report --help
15845 </literallayout>
15846 </para>
15847
15848 <para>
15849 When sending the error file, you are prompted to review the
15850 data being sent as well as to provide a name and optional
15851 email address.
15852 Once you satisfy these prompts, the command returns a link
15853 from the server that corresponds to your entry in the database.
15854 For example, here is a typical link:
15855 <literallayout class='monospaced'>
15856 http://errors.yoctoproject.org/Errors/Details/9522/
15857 </literallayout>
15858 Following the link takes you to a web interface where you can
15859 browse, query the errors, and view statistics.
15860 </para>
15861 </section>
15862
15863 <section id='disabling-the-tool'>
15864 <title>Disabling the Tool</title>
15865
15866 <para>
15867 To disable the error reporting feature, simply remove or comment
15868 out the following statement from the end of your
15869 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015870 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015871 <literallayout class='monospaced'>
15872 INHERIT += "report-error"
15873 </literallayout>
15874 </para>
15875 </section>
15876
15877 <section id='setting-up-your-own-error-reporting-server'>
15878 <title>Setting Up Your Own Error Reporting Server</title>
15879
15880 <para>
15881 If you want to set up your own error reporting server, you
15882 can obtain the code from the Git repository at
15883 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15884 Instructions on how to set it up are in the README document.
15885 </para>
15886 </section>
15887 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015888
15889 <section id="dev-using-wayland-and-weston">
15890 <title>Using Wayland and Weston</title>
15891
15892 <para>
15893 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15894 is a computer display server protocol that
15895 provides a method for compositing window managers to communicate
15896 directly with applications and video hardware and expects them to
15897 communicate with input hardware using other libraries.
15898 Using Wayland with supporting targets can result in better control
15899 over graphics frame rendering than an application might otherwise
15900 achieve.
15901 </para>
15902
15903 <para>
15904 The Yocto Project provides the Wayland protocol libraries and the
15905 reference
15906 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15907 compositor as part of its release.
15908 You can find the integrated packages in the
15909 <filename>meta</filename> layer of the
15910 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15911 Specifically, you can find the recipes that build both Wayland
15912 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15913 </para>
15914
15915 <para>
15916 You can build both the Wayland and Weston packages for use only
15917 with targets that accept the
15918 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15919 which is also known as Mesa DRI.
15920 This implies that you cannot build and use the packages if your
15921 target uses, for example, the
15922 <trademark class='registered'>Intel</trademark> Embedded Media
15923 and Graphics Driver
15924 (<trademark class='registered'>Intel</trademark> EMGD) that
15925 overrides Mesa DRI.
15926 <note>
15927 Due to lack of EGL support, Weston 1.0.3 will not run
15928 directly on the emulated QEMU hardware.
15929 However, this version of Weston will run under X emulation
15930 without issues.
15931 </note>
15932 </para>
15933
15934 <para>
15935 This section describes what you need to do to implement Wayland and
15936 use the Weston compositor when building an image for a supporting
15937 target.
15938 </para>
15939
15940 <section id="enabling-wayland-in-an-image">
15941 <title>Enabling Wayland in an Image</title>
15942
15943 <para>
15944 To enable Wayland, you need to enable it to be built and enable
15945 it to be included (installed) in the image.
15946 </para>
15947
15948 <section id="enable-building">
15949 <title>Building</title>
15950
15951 <para>
15952 To cause Mesa to build the <filename>wayland-egl</filename>
15953 platform and Weston to build Wayland with Kernel Mode
15954 Setting
15955 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15956 support, include the "wayland" flag in the
15957 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15958 statement in your <filename>local.conf</filename> file:
15959 <literallayout class='monospaced'>
15960 DISTRO_FEATURES_append = " wayland"
15961 </literallayout>
15962 <note>
15963 If X11 has been enabled elsewhere, Weston will build
15964 Wayland with X11 support
15965 </note>
15966 </para>
15967 </section>
15968
15969 <section id="enable-installation-in-an-image">
15970 <title>Installing</title>
15971
15972 <para>
15973 To install the Wayland feature into an image, you must
15974 include the following
15975 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15976 statement in your <filename>local.conf</filename> file:
15977 <literallayout class='monospaced'>
15978 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15979 </literallayout>
15980 </para>
15981 </section>
15982 </section>
15983
15984 <section id="running-weston">
15985 <title>Running Weston</title>
15986
15987 <para>
15988 To run Weston inside X11, enabling it as described earlier and
15989 building a Sato image is sufficient.
15990 If you are running your image under Sato, a Weston Launcher
15991 appears in the "Utility" category.
15992 </para>
15993
15994 <para>
15995 Alternatively, you can run Weston through the command-line
15996 interpretor (CLI), which is better suited for development work.
15997 To run Weston under the CLI, you need to do the following after
15998 your image is built:
15999 <orderedlist>
16000 <listitem><para>
16001 Run these commands to export
16002 <filename>XDG_RUNTIME_DIR</filename>:
16003 <literallayout class='monospaced'>
16004 mkdir -p /tmp/$USER-weston
16005 chmod 0700 /tmp/$USER-weston
16006 export XDG_RUNTIME_DIR=/tmp/$USER-weston
16007 </literallayout>
16008 </para></listitem>
16009 <listitem><para>
16010 Launch Weston in the shell:
16011 <literallayout class='monospaced'>
16012 weston
16013 </literallayout></para></listitem>
16014 </orderedlist>
16015 </para>
16016 </section>
16017 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016018</chapter>
16019
16020<!--
16021vim: expandtab tw=80 ts=4
16022-->