blob: 165c3aa6a7c582c2e7c2a7cc6928f3b7ece18926 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='extendpoky'>
6
7<title>Common Tasks</title>
8 <para>
9 This chapter describes fundamental procedures such as creating layers,
10 adding new software packages, extending or customizing images,
11 porting work to new hardware (adding a new machine), and so forth.
12 You will find that the procedures documented here occur often in the
13 development cycle using the Yocto Project.
14 </para>
15
16 <section id="understanding-and-creating-layers">
17 <title>Understanding and Creating Layers</title>
18
19 <para>
20 The OpenEmbedded build system supports organizing
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> into
22 multiple layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 Layers allow you to isolate different types of customizations from
24 each other.
Brad Bishop316dfdd2018-06-25 12:45:53 -040025 For introductory information on the Yocto Project Layer Model,
26 see the
27 "<ulink url='&YOCTO_DOCS_OM_URL;#the-yocto-project-layer-model'>The Yocto Project Layer Model</ulink>"
28 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 </para>
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 <section id='creating-your-own-layer'>
32 <title>Creating Your Own Layer</title>
33
34 <para>
35 It is very easy to create your own layers to use with the
36 OpenEmbedded build system.
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 The Yocto Project ships with tools that speed up creating
38 layers.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 This section describes the steps you perform by hand to create
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 layers so that you can better understand them.
41 For information about the layer-creation tools, see the
42 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 section in the Yocto Project Board Support Package (BSP)
44 Developer's Guide and the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 section further down in this manual.
47 </para>
48
49 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040050 Follow these general steps to create your layer without using
51 tools:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 <orderedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -040053 <listitem><para>
54 <emphasis>Check Existing Layers:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 Before creating a new layer, you should be sure someone
56 has not already created a layer containing the Metadata
57 you need.
58 You can see the
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 <ulink url='http://layers.openembedded.org/layerindex/layers/'>OpenEmbedded Metadata Index</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 for a list of layers from the OpenEmbedded community
61 that can be used in the Yocto Project.
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 You could find a layer that is identical or close to
63 what you need.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 <listitem><para>
66 <emphasis>Create a Directory:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 Create the directory for your layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -040068 When you create the layer, be sure to create the
69 directory in an area not associated with the
70 Yocto Project
71 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
72 (e.g. the cloned <filename>poky</filename> repository).
73 </para>
74
75 <para>While not strictly required, prepend the name of
76 the directory with the string "meta-".
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 For example:
78 <literallayout class='monospaced'>
79 meta-mylayer
80 meta-GUI_xyz
81 meta-mymachine
82 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040083 With rare exceptions, a layer's name follows this
84 form:
85 <literallayout class='monospaced'>
86 meta-<replaceable>root_name</replaceable>
87 </literallayout>
88 Following this layer naming convention can
89 save you trouble later when tools, components, or
90 variables "assume" your layer name begins with "meta-".
91 A notable example is in configuration files as
92 shown in the following step where layer names without
93 the "meta-" string are appended
94 to several variables used in the configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 <listitem><para id='dev-layer-config-file-description'>
97 <emphasis>Create a Layer Configuration File:</emphasis>
98 Inside your new layer folder, you need to create a
99 <filename>conf/layer.conf</filename> file.
100 It is easiest to take an existing layer configuration
101 file and copy that to your layer's
102 <filename>conf</filename> directory and then modify the
103 file as needed.</para>
104
105 <para>The
106 <filename>meta-yocto-bsp/conf/layer.conf</filename> file
107 in the Yocto Project
108 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf'>Source Repositories</ulink>
109 demonstrates the required syntax.
110 For your layer, you need to replace "yoctobsp" with
111 a unique identifier for your layer (e.g. "machinexyz"
112 for a layer named "meta-machinexyz"):
113 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 # We have a conf and classes directory, add to BBPATH
115 BBPATH .= ":${LAYERDIR}"
116
117 # We have recipes-* directories, add to BBFILES
118 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
119 ${LAYERDIR}/recipes-*/*/*.bbappend"
120
121 BBFILE_COLLECTIONS += "yoctobsp"
122 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
123 BBFILE_PRIORITY_yoctobsp = "5"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400124 LAYERVERSION_yoctobsp = "4"
125 LAYERSERIES_COMPAT_yoctobsp = "&DISTRO_NAME_NO_CAP;"
126 </literallayout>
127 Following is an explanation of the layer configuration
128 file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130 <listitem><para>
131 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>:
132 Adds the layer's root directory to BitBake's
133 search path.
134 Through the use of the
135 <filename>BBPATH</filename> variable, BitBake
136 locates class files
137 (<filename>.bbclass</filename>),
138 configuration files, and files that are
139 included with <filename>include</filename> and
140 <filename>require</filename> statements.
141 For these cases, BitBake uses the first file
142 that matches the name found in
143 <filename>BBPATH</filename>.
144 This is similar to the way the
145 <filename>PATH</filename> variable is used for
146 binaries.
147 It is recommended, therefore, that you use
148 unique class and configuration filenames in
149 your custom layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400151 <listitem><para>
152 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>:
153 Defines the location for all recipes in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155 </para></listitem>
156 <listitem><para>
157 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'><filename>BBFILE_COLLECTIONS</filename></ulink>:
158 Establishes the current layer through a
159 unique identifier that is used throughout the
160 OpenEmbedded build system to refer to the layer.
161 In this example, the identifier "yoctobsp" is
162 the representation for the container layer
163 named "meta-yocto-bsp".
164 </para></listitem>
165 <listitem><para>
166 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'><filename>BBFILE_PATTERN</filename></ulink>:
167 Expands immediately during parsing to
168 provide the directory of the layer.
169 </para></listitem>
170 <listitem><para>
171 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>:
172 Establishes a priority to use for
173 recipes in the layer when the OpenEmbedded build
174 finds recipes of the same name in different
175 layers.
176 </para></listitem>
177 <listitem><para>
178 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'><filename>LAYERVERSION</filename></ulink>:
179 Establishes a version number for the layer.
180 You can use this version number to specify this
181 exact version of the layer as a dependency when
182 using the
183 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDEPENDS'><filename>LAYERDEPENDS</filename></ulink>
184 variable.
185 </para></listitem>
186 <listitem><para>
187 <ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERSERIES_COMPAT'><filename>LAYERSERIES_COMPAT</filename></ulink>:
188 Lists the
189 <ulink url='&YOCTO_WIKI_URL;/wiki/Releases'>Yocto Project</ulink>
190 releases for which the current version is
191 compatible.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800192 This variable is a good way to indicate if
193 your particular layer is current.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194 </para></listitem>
195 </itemizedlist>
196 </para></listitem>
197 <listitem><para>
198 <emphasis>Add Content:</emphasis>
199 Depending on the type of layer, add the content.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 If the layer adds support for a machine, add the machine
201 configuration in a <filename>conf/machine/</filename>
202 file within the layer.
203 If the layer adds distro policy, add the distro
204 configuration in a <filename>conf/distro/</filename>
205 file within the layer.
206 If the layer introduces new recipes, put the recipes
207 you need in <filename>recipes-*</filename>
208 subdirectories within the layer.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400209 <note>
210 For an explanation of layer hierarchy that
211 is compliant with the Yocto Project, see
212 the
213 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout'>Example Filesystem Layout</ulink>"
214 section in the Yocto Project Board
215 Support Package (BSP) Developer's Guide.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 </note>
217 </para></listitem>
218 <listitem><para>
219 <emphasis>Optionally Test for Compatibility:</emphasis>
220 If you want permission to use the Yocto Project
221 Compatibility logo with your layer or application that
222 uses your layer, perform the steps to apply for
223 compatibility.
224 See the
225 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
226 section for more information.
227 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 </orderedlist>
229 </para>
230 </section>
231
232 <section id='best-practices-to-follow-when-creating-layers'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500233 <title>Following Best Practices When Creating Layers</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234
235 <para>
236 To create layers that are easier to maintain and that will
237 not impact builds for other machines, you should consider the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 information in the following list:
239 <itemizedlist>
240 <listitem><para>
241 <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis>
242 In other words, do not copy an entire recipe into your
243 layer and then modify it.
244 Rather, use an append file
245 (<filename>.bbappend</filename>) to override only those
246 parts of the original recipe you need to modify.
247 </para></listitem>
248 <listitem><para>
249 <emphasis>Avoid Duplicating Include Files:</emphasis>
250 Use append files (<filename>.bbappend</filename>)
251 for each recipe that uses an include file.
252 Or, if you are introducing a new recipe that requires
253 the included file, use the path relative to the
254 original layer directory to refer to the file.
255 For example, use
256 <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename>
257 instead of
258 <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>.
259 If you're finding you have to overlay the include file,
260 it could indicate a deficiency in the include file in
261 the layer to which it originally belongs.
262 If this is the case, you should try to address that
263 deficiency instead of overlaying the include file.
264 For example, you could address this by getting the
265 maintainer of the include file to add a variable or
266 variables to make it easy to override the parts needing
267 to be overridden.
268 </para></listitem>
269 <listitem><para>
270 <emphasis>Structure Your Layers:</emphasis>
271 Proper use of overrides within append files and
272 placement of machine-specific files within your layer
273 can ensure that a build is not using the wrong Metadata
274 and negatively impacting a build for a different
275 machine.
276 Following are some examples:
277 <itemizedlist>
278 <listitem><para>
279 <emphasis>Modify Variables to Support a
280 Different Machine:</emphasis>
281 Suppose you have a layer named
282 <filename>meta-one</filename> that adds support
283 for building machine "one".
284 To do so, you use an append file named
285 <filename>base-files.bbappend</filename> and
286 create a dependency on "foo" by altering the
287 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
288 variable:
289 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 DEPENDS = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 </literallayout>
292 The dependency is created during any build that
293 includes the layer
294 <filename>meta-one</filename>.
295 However, you might not want this dependency
296 for all machines.
297 For example, suppose you are building for
298 machine "two" but your
299 <filename>bblayers.conf</filename> file has the
300 <filename>meta-one</filename> layer included.
301 During the build, the
302 <filename>base-files</filename> for machine
303 "two" will also have the dependency on
304 <filename>foo</filename>.</para>
305 <para>To make sure your changes apply only when
306 building machine "one", use a machine override
307 with the <filename>DEPENDS</filename> statement:
308 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 DEPENDS_one = "foo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500310 </literallayout>
311 You should follow the same strategy when using
312 <filename>_append</filename> and
313 <filename>_prepend</filename> operations:
314 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 DEPENDS_append_one = " foo"
316 DEPENDS_prepend_one = "foo "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 </literallayout>
318 As an actual example, here's a line from the recipe
319 for gnutls, which adds dependencies on
320 "argp-standalone" when building with the musl C
321 library:
322 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323 DEPENDS_append_libc-musl = " argp-standalone"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500324 </literallayout>
325 <note>
326 Avoiding "+=" and "=+" and using
327 machine-specific
328 <filename>_append</filename>
329 and <filename>_prepend</filename> operations
330 is recommended as well.
331 </note>
332 </para></listitem>
333 <listitem><para>
334 <emphasis>Place Machine-Specific Files in
335 Machine-Specific Locations:</emphasis>
336 When you have a base recipe, such as
337 <filename>base-files.bb</filename>, that
338 contains a
339 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
340 statement to a file, you can use an append file
341 to cause the build to use your own version of
342 the file.
343 For example, an append file in your layer at
344 <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename>
345 could extend
346 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
347 using
348 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
349 as follows:
350 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352 </literallayout>
353 The build for machine "one" will pick up your
354 machine-specific file as long as you have the
355 file in
356 <filename>meta-one/recipes-core/base-files/base-files/</filename>.
357 However, if you are building for a different
358 machine and the
359 <filename>bblayers.conf</filename> file includes
360 the <filename>meta-one</filename> layer and
361 the location of your machine-specific file is
362 the first location where that file is found
363 according to <filename>FILESPATH</filename>,
364 builds for all machines will also use that
365 machine-specific file.</para>
366 <para>You can make sure that a machine-specific
367 file is used for a particular machine by putting
368 the file in a subdirectory specific to the
369 machine.
370 For example, rather than placing the file in
371 <filename>meta-one/recipes-core/base-files/base-files/</filename>
372 as shown above, put it in
373 <filename>meta-one/recipes-core/base-files/base-files/one/</filename>.
374 Not only does this make sure the file is used
375 only when building for machine "one", but the
376 build process locates the file more quickly.</para>
377 <para>In summary, you need to place all files
378 referenced from <filename>SRC_URI</filename>
379 in a machine-specific subdirectory within the
380 layer in order to restrict those files to
381 machine-specific builds.
382 </para></listitem>
383 </itemizedlist>
384 </para></listitem>
385 <listitem><para>
386 <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis>
387 If you want permission to use the
388 Yocto Project Compatibility logo with your layer
389 or application that uses your layer, perform the
390 steps to apply for compatibility.
391 See the
392 "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>"
393 section for more information.
394 </para></listitem>
395 <listitem><para>
396 <emphasis>Follow the Layer Naming Convention:</emphasis>
397 Store custom layers in a Git repository that use the
398 <filename>meta-<replaceable>layer_name</replaceable></filename>
399 format.
400 </para></listitem>
401 <listitem><para>
402 <emphasis>Group Your Layers Locally:</emphasis>
403 Clone your repository alongside other cloned
404 <filename>meta</filename> directories from the
405 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
406 </para></listitem>
407 </itemizedlist>
408 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 </section>
410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 <section id='making-sure-your-layer-is-compatible-with-yocto-project'>
412 <title>Making Sure Your Layer is Compatible With Yocto Project</title>
413
414 <para>
415 When you create a layer used with the Yocto Project, it is
416 advantageous to make sure that the layer interacts well with
417 existing Yocto Project layers (i.e. the layer is compatible
418 with the Yocto Project).
419 Ensuring compatibility makes the layer easy to be consumed
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500420 by others in the Yocto Project community and could allow you
421 permission to use the Yocto Project Compatible Logo.
422 <note>
423 Only Yocto Project member organizations are permitted to
424 use the Yocto Project Compatible Logo.
425 The logo is not available for general use.
426 For information on how to become a Yocto Project member
427 organization, see the
428 <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500429 </note>
430 </para>
431
432 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500433 The Yocto Project Compatibility Program consists of a layer
434 application process that requests permission to use the Yocto
435 Project Compatibility Logo for your layer and application.
436 The process consists of two parts:
437 <orderedlist>
438 <listitem><para>
439 Successfully passing a script
440 (<filename>yocto-check-layer</filename>) that
441 when run against your layer, tests it against
442 constraints based on experiences of how layers have
443 worked in the real world and where pitfalls have been
444 found.
445 Getting a "PASS" result from the script is required for
446 successful compatibility registration.
447 </para></listitem>
448 <listitem><para>
449 Completion of an application acceptance form, which
450 you can find at
451 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
452 </para></listitem>
453 </orderedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 </para>
455
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 <para>
457 To be granted permission to use the logo, you need to satisfy
458 the following:
459 <itemizedlist>
460 <listitem><para>
461 Be able to check the box indicating that you
462 got a "PASS" when running the script against your
463 layer.
464 </para></listitem>
465 <listitem><para>
466 Answer "Yes" to the questions on the form or have an
467 acceptable explanation for any questions answered "No".
468 </para></listitem>
469 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400470 Be a Yocto Project Member Organization.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500471 </para></listitem>
472 </itemizedlist>
473 </para>
474
475 <para>
476 The remainder of this section presents information on the
477 registration form and on the
478 <filename>yocto-check-layer</filename> script.
479 </para>
480
481 <section id='yocto-project-compatible-program-application'>
482 <title>Yocto Project Compatible Program Application</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483
484 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500485 Use the form to apply for your layer's approval.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500486 Upon successful application, you can use the Yocto
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500487 Project Compatibility Logo with your layer and the
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 application that uses your layer.
489 </para>
490
491 <para>
492 To access the form, use this link:
493 <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>.
494 Follow the instructions on the form to complete your
495 application.
496 </para>
497
498 <para>
499 The application consists of the following sections:
500 <itemizedlist>
501 <listitem><para>
502 <emphasis>Contact Information:</emphasis>
503 Provide your contact information as the fields
504 require.
505 Along with your information, provide the
506 released versions of the Yocto Project for which
507 your layer is compatible.
508 </para></listitem>
509 <listitem><para>
510 <emphasis>Acceptance Criteria:</emphasis>
511 Provide "Yes" or "No" answers for each of the
512 items in the checklist.
513 Space exists at the bottom of the form for any
514 explanations for items for which you answered "No".
515 </para></listitem>
516 <listitem><para>
517 <emphasis>Recommendations:</emphasis>
518 Provide answers for the questions regarding Linux
519 kernel use and build success.
520 </para></listitem>
521 </itemizedlist>
522 </para>
523 </section>
524
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500525 <section id='yocto-check-layer-script'>
526 <title><filename>yocto-check-layer</filename> Script</title>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527
528 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500529 The <filename>yocto-check-layer</filename> script
530 provides you a way to assess how compatible your layer is
531 with the Yocto Project.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500532 You should run this script prior to using the form to
533 apply for compatibility as described in the previous
534 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500535 You need to achieve a "PASS" result in order to have
536 your application form successfully processed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 </para>
538
539 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400540 The script divides tests into three areas: COMMON, BSP,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500541 and DISTRO.
542 For example, given a distribution layer (DISTRO), the
543 layer must pass both the COMMON and DISTRO related tests.
544 Furthermore, if your layer is a BSP layer, the layer must
545 pass the COMMON and BSP set of tests.
546 </para>
547
548 <para>
549 To execute the script, enter the following commands from
550 your build directory:
551 <literallayout class='monospaced'>
552 $ source oe-init-build-env
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500553 $ yocto-check-layer <replaceable>your_layer_directory</replaceable>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500554 </literallayout>
555 Be sure to provide the actual directory for your layer
556 as part of the command.
557 </para>
558
559 <para>
560 Entering the command causes the script to determine the
561 type of layer and then to execute a set of specific
562 tests against the layer.
563 The following list overviews the test:
564 <itemizedlist>
565 <listitem><para>
566 <filename>common.test_readme</filename>:
567 Tests if a <filename>README</filename> file
568 exists in the layer and the file is not empty.
569 </para></listitem>
570 <listitem><para>
571 <filename>common.test_parse</filename>:
572 Tests to make sure that BitBake can parse the
573 files without error (i.e.
574 <filename>bitbake -p</filename>).
575 </para></listitem>
576 <listitem><para>
577 <filename>common.test_show_environment</filename>:
578 Tests that the global or per-recipe environment
579 is in order without errors (i.e.
580 <filename>bitbake -e</filename>).
581 </para></listitem>
582 <listitem><para>
583 <filename>common.test_signatures</filename>:
584 Tests to be sure that BSP and DISTRO layers do not
585 come with recipes that change signatures.
586 </para></listitem>
587 <listitem><para>
588 <filename>bsp.test_bsp_defines_machines</filename>:
589 Tests if a BSP layer has machine configurations.
590 </para></listitem>
591 <listitem><para>
592 <filename>bsp.test_bsp_no_set_machine</filename>:
593 Tests to ensure a BSP layer does not set the
594 machine when the layer is added.
595 </para></listitem>
596 <listitem><para>
597 <filename>distro.test_distro_defines_distros</filename>:
598 Tests if a DISTRO layer has distro configurations.
599 </para></listitem>
600 <listitem><para>
601 <filename>distro.test_distro_no_set_distro</filename>:
602 Tests to ensure a DISTRO layer does not set the
603 distribution when the layer is added.
604 </para></listitem>
605 </itemizedlist>
606 </para>
607 </section>
608 </section>
609
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610 <section id='enabling-your-layer'>
611 <title>Enabling Your Layer</title>
612
613 <para>
614 Before the OpenEmbedded build system can use your new layer,
615 you need to enable it.
616 To enable your layer, simply add your layer's path to the
617 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename>
618 variable in your <filename>conf/bblayers.conf</filename> file,
619 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 The following example shows how to enable a layer named
622 <filename>meta-mylayer</filename>:
623 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400624 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
625 # changes incompatibly
626 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627
628 BBPATH = "${TOPDIR}"
629 BBFILES ?= ""
630
631 BBLAYERS ?= " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400632 /home/<replaceable>user</replaceable>/poky/meta \
633 /home/<replaceable>user</replaceable>/poky/meta-poky \
634 /home/<replaceable>user</replaceable>/poky/meta-yocto-bsp \
635 /home/<replaceable>user</replaceable>/poky/meta-mylayer \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500636 "
637 </literallayout>
638 </para>
639
640 <para>
641 BitBake parses each <filename>conf/layer.conf</filename> file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400642 from the top down as specified in the
643 <filename>BBLAYERS</filename> variable
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500644 within the <filename>conf/bblayers.conf</filename> file.
645 During the processing of each
646 <filename>conf/layer.conf</filename> file, BitBake adds the
647 recipes, classes and configurations contained within the
648 particular layer to the source directory.
649 </para>
650 </section>
651
652 <section id='using-bbappend-files'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500653 <title>Using .bbappend Files in Your Layer</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500654
655 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500656 A recipe that appends Metadata to another recipe is called a
657 BitBake append file.
658 A BitBake append file uses the <filename>.bbappend</filename>
659 file type suffix, while the corresponding recipe to which
660 Metadata is being appended uses the <filename>.bb</filename>
661 file type suffix.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500662 </para>
663
664 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500665 You can use a <filename>.bbappend</filename> file in your
666 layer to make additions or changes to the content of another
667 layer's recipe without having to copy the other layer's
668 recipe into your layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669 Your <filename>.bbappend</filename> file resides in your layer,
670 while the main <filename>.bb</filename> recipe file to
671 which you are appending Metadata resides in a different layer.
672 </para>
673
674 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 Being able to append information to an existing recipe not only
676 avoids duplication, but also automatically applies recipe
677 changes from a different layer into your layer.
678 If you were copying recipes, you would have to manually merge
679 changes as they occur.
680 </para>
681
682 <para>
683 When you create an append file, you must use the same root
684 name as the corresponding recipe file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685 For example, the append file
686 <filename>someapp_&DISTRO;.bbappend</filename> must apply to
687 <filename>someapp_&DISTRO;.bb</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500688 This means the original recipe and append file names are
689 version number-specific.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500690 If the corresponding recipe is renamed to update to a newer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500691 version, you must also rename and possibly update
692 the corresponding <filename>.bbappend</filename> as well.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 During the build process, BitBake displays an error on starting
694 if it detects a <filename>.bbappend</filename> file that does
695 not have a corresponding recipe with a matching name.
696 See the
697 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink>
698 variable for information on how to handle this error.
699 </para>
700
701 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702 As an example, consider the main formfactor recipe and a
703 corresponding formfactor append file both from the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500704 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500705 Here is the main formfactor recipe, which is named
706 <filename>formfactor_0.0.bb</filename> and located in the
707 "meta" layer at
708 <filename>meta/recipes-bsp/formfactor</filename>:
709 <literallayout class='monospaced'>
710 SUMMARY = "Device formfactor information"
711 SECTION = "base"
712 LICENSE = "MIT"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500713 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714 PR = "r45"
715
716 SRC_URI = "file://config file://machconfig"
717 S = "${WORKDIR}"
718
719 PACKAGE_ARCH = "${MACHINE_ARCH}"
720 INHIBIT_DEFAULT_DEPS = "1"
721
722 do_install() {
723 # Install file only if it has contents
724 install -d ${D}${sysconfdir}/formfactor/
725 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
726 if [ -s "${S}/machconfig" ]; then
727 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
728 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 } </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 In the main recipe, note the
731 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
732 variable, which tells the OpenEmbedded build system where to
733 find files during the build.
734 </para>
735
736 <para>
737 Following is the append file, which is named
738 <filename>formfactor_0.0.bbappend</filename> and is from the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500739 Raspberry Pi BSP Layer named
740 <filename>meta-raspberrypi</filename>.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500741 The file is in the layer at
742 <filename>recipes-bsp/formfactor</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 <literallayout class='monospaced'>
744 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
745 </literallayout>
746 </para>
747
748 <para>
749 By default, the build system uses the
750 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
751 variable to locate files.
752 This append file extends the locations by setting the
753 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
754 variable.
755 Setting this variable in the <filename>.bbappend</filename>
756 file is the most reliable and recommended method for adding
757 directories to the search path used by the build system
758 to find files.
759 </para>
760
761 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500762 The statement in this example extends the directories to
763 include
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500764 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>,
765 which resolves to a directory named
766 <filename>formfactor</filename> in the same directory
767 in which the append file resides (i.e.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500768 <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500769 This implies that you must have the supporting directory
770 structure set up that will contain any files or patches you
771 will be including from the layer.
772 </para>
773
774 <para>
775 Using the immediate expansion assignment operator
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500776 <filename>:=</filename> is important because of the reference
777 to <filename>THISDIR</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500778 The trailing colon character is important as it ensures that
779 items in the list remain colon-separated.
780 <note>
781 <para>
782 BitBake automatically defines the
783 <filename>THISDIR</filename> variable.
784 You should never set this variable yourself.
785 Using "_prepend" as part of the
786 <filename>FILESEXTRAPATHS</filename> ensures your path
787 will be searched prior to other paths in the final
788 list.
789 </para>
790
791 <para>
792 Also, not all append files add extra files.
793 Many append files simply exist to add build options
794 (e.g. <filename>systemd</filename>).
795 For these cases, your append file would not even
796 use the <filename>FILESEXTRAPATHS</filename> statement.
797 </para>
798 </note>
799 </para>
800 </section>
801
802 <section id='prioritizing-your-layer'>
803 <title>Prioritizing Your Layer</title>
804
805 <para>
806 Each layer is assigned a priority value.
807 Priority values control which layer takes precedence if there
808 are recipe files with the same name in multiple layers.
809 For these cases, the recipe file from the layer with a higher
810 priority number takes precedence.
811 Priority values also affect the order in which multiple
812 <filename>.bbappend</filename> files for the same recipe are
813 applied.
814 You can either specify the priority manually, or allow the
815 build system to calculate it based on the layer's dependencies.
816 </para>
817
818 <para>
819 To specify the layer's priority manually, use the
820 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400821 variable and append the layer's root name:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500822 <literallayout class='monospaced'>
823 BBFILE_PRIORITY_mylayer = "1"
824 </literallayout>
825 </para>
826
827 <note>
828 <para>It is possible for a recipe with a lower version number
829 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
830 in a layer that has a higher priority to take precedence.</para>
831 <para>Also, the layer priority does not currently affect the
832 precedence order of <filename>.conf</filename>
833 or <filename>.bbclass</filename> files.
834 Future versions of BitBake might address this.</para>
835 </note>
836 </section>
837
838 <section id='managing-layers'>
839 <title>Managing Layers</title>
840
841 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400842 You can use the BitBake layer management tool
843 <filename>bitbake-layers</filename> to provide a view
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844 into the structure of recipes across a multi-layer project.
845 Being able to generate output that reports on configured layers
846 with their paths and priorities and on
847 <filename>.bbappend</filename> files and their applicable
848 recipes can help to reveal potential problems.
849 </para>
850
851 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400852 For help on the BitBake layer management tool, use the
853 following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500854 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400855 $ bitbake-layers --help
856 NOTE: Starting bitbake server...
857 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] &lt;subcommand&gt; ...
858
859 BitBake layers utility
860
861 optional arguments:
862 -d, --debug Enable debug output
863 -q, --quiet Print only errors
864 -F, --force Force add without recipe parse verification
865 --color COLOR Colorize output (where COLOR is auto, always, never)
866 -h, --help show this help message and exit
867
868 subcommands:
869 &lt;subcommand&gt;
870 show-layers show current configured layers.
871 show-overlayed list overlayed recipes (where the same recipe exists
872 in another layer)
873 show-recipes list available recipes, showing the layer they are
874 provided by
875 show-appends list bbappend files and recipe files they apply to
876 show-cross-depends Show dependencies between recipes that cross layer
877 boundaries.
878 add-layer Add one or more layers to bblayers.conf.
879 remove-layer Remove one or more layers from bblayers.conf.
880 flatten flatten layer configuration into a separate output
881 directory.
882 layerindex-fetch Fetches a layer from a layer index along with its
883 dependent layers, and adds them to conf/bblayers.conf.
884 layerindex-show-depends
885 Find layer dependencies from layer index.
886 create-layer Create a basic layer
887
888 Use bitbake-layers &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500889 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400890 </para>
891
892 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500893 The following list describes the available commands:
894 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400895 <listitem><para>
896 <emphasis><filename>help:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500897 Displays general help or help on a specified command.
898 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400899 <listitem><para>
900 <emphasis><filename>show-layers:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500901 Shows the current configured layers.
902 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400903 <listitem><para>
904 <emphasis><filename>show-overlayed:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 Lists overlayed recipes.
906 A recipe is overlayed when a recipe with the same name
907 exists in another layer that has a higher layer
908 priority.
909 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400910 <listitem><para>
911 <emphasis><filename>show-recipes:</filename></emphasis>
912 Lists available recipes and the layers that provide them.
913 </para></listitem>
914 <listitem><para>
915 <emphasis><filename>show-appends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916 Lists <filename>.bbappend</filename> files and the
917 recipe files to which they apply.
918 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400919 <listitem><para>
920 <emphasis><filename>show-cross-depends:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500921 Lists dependency relationships between recipes that
922 cross layer boundaries.
923 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400924 <listitem><para>
925 <emphasis><filename>add-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500926 Adds a layer to <filename>bblayers.conf</filename>.
927 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400928 <listitem><para>
929 <emphasis><filename>remove-layer:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500930 Removes a layer from <filename>bblayers.conf</filename>
931 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400932 <listitem><para>
933 <emphasis><filename>flatten:</filename></emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500934 Flattens the layer configuration into a separate output
935 directory.
936 Flattening your layer configuration builds a "flattened"
937 directory that contains the contents of all layers,
938 with any overlayed recipes removed and any
939 <filename>.bbappend</filename> files appended to the
940 corresponding recipes.
941 You might have to perform some manual cleanup of the
942 flattened layer as follows:
943 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400944 <listitem><para>
945 Non-recipe files (such as patches)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500946 are overwritten.
947 The flatten command shows a warning for these
948 files.
949 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400950 <listitem><para>
951 Anything beyond the normal layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952 setup has been added to the
953 <filename>layer.conf</filename> file.
954 Only the lowest priority layer's
955 <filename>layer.conf</filename> is used.
956 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400957 <listitem><para>
958 Overridden and appended items from
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500959 <filename>.bbappend</filename> files need to be
960 cleaned up.
961 The contents of each
962 <filename>.bbappend</filename> end up in the
963 flattened recipe.
964 However, if there are appended or changed
965 variable values, you need to tidy these up
966 yourself.
967 Consider the following example.
968 Here, the <filename>bitbake-layers</filename>
969 command adds the line
970 <filename>#### bbappended ...</filename> so that
971 you know where the following lines originate:
972 <literallayout class='monospaced'>
973 ...
974 DESCRIPTION = "A useful utility"
975 ...
976 EXTRA_OECONF = "--enable-something"
977 ...
978
979 #### bbappended from meta-anotherlayer ####
980
981 DESCRIPTION = "Customized utility"
982 EXTRA_OECONF += "--enable-somethingelse"
983 </literallayout>
984 Ideally, you would tidy up these utilities as
985 follows:
986 <literallayout class='monospaced'>
987 ...
988 DESCRIPTION = "Customized utility"
989 ...
990 EXTRA_OECONF = "--enable-something --enable-somethingelse"
991 ...
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500992 </literallayout>
993 </para></listitem>
994 </itemizedlist>
995 </para></listitem>
996 <listitem><para>
997 <emphasis><filename>layerindex-fetch</filename>:</emphasis>
998 Fetches a layer from a layer index, along with its
999 dependent layers, and adds the layers to the
1000 <filename>conf/bblayers.conf</filename> file.
1001 </para></listitem>
1002 <listitem><para>
1003 <emphasis><filename>layerindex-show-depends</filename>:</emphasis>
1004 Finds layer dependencies from the layer index.
1005 </para></listitem>
1006 <listitem><para>
1007 <emphasis><filename>create-layer</filename>:</emphasis>
1008 Creates a basic layer.
1009 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001010 </itemizedlist>
1011 </para>
1012 </section>
1013
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001014 <section id='creating-a-general-layer-using-the-bitbake-layers-script'>
1015 <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
1017 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001018 The <filename>bitbake-layers</filename> script with the
1019 <filename>create-layer</filename> subcommand simplifies
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001020 creating a new general layer.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 <note><title>Notes</title>
1022 <itemizedlist>
1023 <listitem><para>
1024 For information on BSP layers, see the
1025 "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>"
1026 section in the Yocto Project Board Specific (BSP)
1027 Developer's Guide.
1028 </para></listitem>
1029 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001030 In order to use a layer with the OpenEmbedded
1031 build system, you need to add the layer to your
1032 <filename>bblayers.conf</filename> configuration
1033 file.
1034 See the
1035 "<link linkend='adding-a-layer-using-the-bitbake-layers-script'>Adding a Layer Using the <filename>bitbake-layers</filename> Script</link>"
1036 section for more information.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001037 </para></listitem>
1038 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001039 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 The default mode of the script's operation with this
1041 subcommand is to create a layer with the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001042 <itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001043 <listitem><para>A layer priority of 6.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001044 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001045 <listitem><para>A <filename>conf</filename>
1046 subdirectory that contains a
1047 <filename>layer.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001048 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001049 <listitem><para>
1050 A <filename>recipes-example</filename> subdirectory
1051 that contains a further subdirectory named
1052 <filename>example</filename>, which contains
1053 an <filename>example.bb</filename> recipe file.
1054 </para></listitem>
1055 <listitem><para>A <filename >COPYING.MIT</filename>,
1056 which is the license statement for the layer.
1057 The script assumes you want to use the MIT license,
1058 which is typical for most layers, for the contents of
1059 the layer itself.
1060 </para></listitem>
1061 <listitem><para>
1062 A <filename>README</filename> file, which is a file
1063 describing the contents of your new layer.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001064 </para></listitem>
1065 </itemizedlist>
1066 </para>
1067
1068 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001069 In its simplest form, you can use the following command form
1070 to create a layer.
1071 The command creates a layer whose name corresponds to
1072 <replaceable>your_layer_name</replaceable> in the current
1073 directory:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001074 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001075 $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001076 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001077 As an example, the following command creates a layer named
1078 <filename>meta-scottrif</filename> in your home directory:
1079 <literallayout class='monospaced'>
1080 $ cd /usr/home
1081 $ bitbake-layers create-layer meta-scottrif
1082 NOTE: Starting bitbake server...
1083 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
1084 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 </para>
1086
1087 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001088 If you want to set the priority of the layer to other than the
1089 default value of "6", you can either use the
1090 <filename>&dash;&dash;priority</filename> option or you can
1091 edit the
1092 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink>
1093 value in the <filename>conf/layer.conf</filename> after the
1094 script creates it.
1095 Furthermore, if you want to give the example recipe file
1096 some name other than the default, you can
1097 use the
1098 <filename>&dash;&dash;example-recipe-name</filename> option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001099 </para>
1100
1101 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001102 The easiest way to see how the
1103 <filename>bitbake-layers create-layer</filename> command
1104 works is to experiment with the script.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001105 You can also read the usage information by entering the
1106 following:
1107 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001108 $ bitbake-layers create-layer --help
1109 NOTE: Starting bitbake server...
1110 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
1111 [--example-recipe-name EXAMPLERECIPE]
1112 layerdir
1113
1114 Create a basic layer
1115
1116 positional arguments:
1117 layerdir Layer directory to create
1118
1119 optional arguments:
1120 -h, --help show this help message and exit
1121 --priority PRIORITY, -p PRIORITY
1122 Layer directory to create
1123 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
1124 Filename of the example recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001125 </literallayout>
1126 </para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001127 </section>
1128
1129 <section id='adding-a-layer-using-the-bitbake-layers-script'>
1130 <title>Adding a Layer Using the <filename>bitbake-layers</filename> Script</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001131
1132 <para>
1133 Once you create your general layer, you must add it to your
1134 <filename>bblayers.conf</filename> file.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001135 Adding the layer to this configuration file makes the
1136 OpenEmbedded build system aware of your layer so that it can
1137 search it for metadata.
1138 </para>
1139
1140 <para>
1141 Add your layer by using the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001142 <filename>bitbake-layers add-layer</filename> command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001143 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001144 $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable>
1145 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001146 Here is an example that adds a layer named
1147 <filename>meta-scottrif</filename> to the configuration file.
1148 Following the command that adds the layer is another
1149 <filename>bitbake-layers</filename> command that shows the
1150 layers that are in your <filename>bblayers.conf</filename>
1151 file:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001152 <literallayout class='monospaced'>
1153 $ bitbake-layers add-layer meta-scottrif
1154 NOTE: Starting bitbake server...
Brad Bishop316dfdd2018-06-25 12:45:53 -04001155 Parsing recipes: 100% |##########################################################| Time: 0:00:49
1156 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001157 $ bitbake-layers show-layers
1158 NOTE: Starting bitbake server...
1159 layer path priority
1160 ==========================================================================
1161 meta /home/scottrif/poky/meta 5
1162 meta-poky /home/scottrif/poky/meta-poky 5
1163 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001164 workspace /home/scottrif/poky/build/workspace 99
1165 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001166 </literallayout>
1167 Adding the layer to this file enables the build system to
1168 locate the layer during the build.
Brad Bishop316dfdd2018-06-25 12:45:53 -04001169 <note>
1170 During a build, the OpenEmbedded build system looks in
1171 the layers from the top of the list down to the bottom
1172 in that order.
1173 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001174 </para>
1175 </section>
1176 </section>
1177
1178 <section id='usingpoky-extend-customimage'>
1179 <title>Customizing Images</title>
1180
1181 <para>
1182 You can customize images to satisfy particular requirements.
1183 This section describes several methods and provides guidelines for each.
1184 </para>
1185
1186 <section id='usingpoky-extend-customimage-localconf'>
1187 <title>Customizing Images Using <filename>local.conf</filename></title>
1188
1189 <para>
1190 Probably the easiest way to customize an image is to add a
1191 package by way of the <filename>local.conf</filename>
1192 configuration file.
1193 Because it is limited to local use, this method generally only
1194 allows you to add packages and is not as flexible as creating
1195 your own customized image.
1196 When you add packages using local variables this way, you need
1197 to realize that these variable changes are in effect for every
1198 build and consequently affect all images, which might not
1199 be what you require.
1200 </para>
1201
1202 <para>
1203 To add a package to your image using the local configuration
1204 file, use the
1205 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1206 variable with the <filename>_append</filename> operator:
1207 <literallayout class='monospaced'>
1208 IMAGE_INSTALL_append = " strace"
1209 </literallayout>
1210 Use of the syntax is important - specifically, the space between
1211 the quote and the package name, which is
1212 <filename>strace</filename> in this example.
1213 This space is required since the <filename>_append</filename>
1214 operator does not add the space.
1215 </para>
1216
1217 <para>
1218 Furthermore, you must use <filename>_append</filename> instead
1219 of the <filename>+=</filename> operator if you want to avoid
1220 ordering issues.
1221 The reason for this is because doing so unconditionally appends
1222 to the variable and avoids ordering problems due to the
1223 variable being set in image recipes and
1224 <filename>.bbclass</filename> files with operators like
1225 <filename>?=</filename>.
1226 Using <filename>_append</filename> ensures the operation takes
1227 affect.
1228 </para>
1229
1230 <para>
1231 As shown in its simplest use,
1232 <filename>IMAGE_INSTALL_append</filename> affects all images.
1233 It is possible to extend the syntax so that the variable
1234 applies to a specific image only.
1235 Here is an example:
1236 <literallayout class='monospaced'>
1237 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
1238 </literallayout>
1239 This example adds <filename>strace</filename> to the
1240 <filename>core-image-minimal</filename> image only.
1241 </para>
1242
1243 <para>
1244 You can add packages using a similar approach through the
1245 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename>
1246 variable.
1247 If you use this variable, only
1248 <filename>core-image-*</filename> images are affected.
1249 </para>
1250 </section>
1251
1252 <section id='usingpoky-extend-customimage-imagefeatures'>
1253 <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and
1254 <filename>EXTRA_IMAGE_FEATURES</filename></title>
1255
1256 <para>
1257 Another method for customizing your image is to enable or
1258 disable high-level image features by using the
1259 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
1260 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
1261 variables.
1262 Although the functions for both variables are nearly equivalent,
1263 best practices dictate using <filename>IMAGE_FEATURES</filename>
1264 from within a recipe and using
1265 <filename>EXTRA_IMAGE_FEATURES</filename> from within
1266 your <filename>local.conf</filename> file, which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001267 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001268 </para>
1269
1270 <para>
1271 To understand how these features work, the best reference is
1272 <filename>meta/classes/core-image.bbclass</filename>.
1273 This class lists out the available
Brad Bishop316dfdd2018-06-25 12:45:53 -04001274 <filename>IMAGE_FEATURES</filename> of which most map to
1275 package groups while some, such as
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001276 <filename>debug-tweaks</filename> and
1277 <filename>read-only-rootfs</filename>, resolve as general
1278 configuration settings.
1279 </para>
1280
1281 <para>
1282 In summary, the file looks at the contents of the
1283 <filename>IMAGE_FEATURES</filename> variable and then maps
1284 or configures the feature accordingly.
1285 Based on this information, the build system automatically
1286 adds the appropriate packages or configurations to the
1287 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
1288 variable.
1289 Effectively, you are enabling extra features by extending the
1290 class or creating a custom class for use with specialized image
1291 <filename>.bb</filename> files.
1292 </para>
1293
1294 <para>
1295 Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable
1296 from within your local configuration file.
1297 Using a separate area from which to enable features with
1298 this variable helps you avoid overwriting the features in the
1299 image recipe that are enabled with
1300 <filename>IMAGE_FEATURES</filename>.
1301 The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added
1302 to <filename>IMAGE_FEATURES</filename> within
1303 <filename>meta/conf/bitbake.conf</filename>.
1304 </para>
1305
1306 <para>
1307 To illustrate how you can use these variables to modify your
1308 image, consider an example that selects the SSH server.
1309 The Yocto Project ships with two SSH servers you can use
1310 with your images: Dropbear and OpenSSH.
1311 Dropbear is a minimal SSH server appropriate for
1312 resource-constrained environments, while OpenSSH is a
1313 well-known standard SSH server implementation.
1314 By default, the <filename>core-image-sato</filename> image
1315 is configured to use Dropbear.
1316 The <filename>core-image-full-cmdline</filename> and
1317 <filename>core-image-lsb</filename> images both
1318 include OpenSSH.
1319 The <filename>core-image-minimal</filename> image does not
1320 contain an SSH server.
1321 </para>
1322
1323 <para>
1324 You can customize your image and change these defaults.
1325 Edit the <filename>IMAGE_FEATURES</filename> variable
1326 in your recipe or use the
1327 <filename>EXTRA_IMAGE_FEATURES</filename> in your
1328 <filename>local.conf</filename> file so that it configures the
1329 image you are working with to include
1330 <filename>ssh-server-dropbear</filename> or
1331 <filename>ssh-server-openssh</filename>.
1332 </para>
1333
1334 <note>
1335 See the
1336 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
1337 section in the Yocto Project Reference Manual for a complete
1338 list of image features that ship with the Yocto Project.
1339 </note>
1340 </section>
1341
1342 <section id='usingpoky-extend-customimage-custombb'>
1343 <title>Customizing Images Using Custom .bb Files</title>
1344
1345 <para>
1346 You can also customize an image by creating a custom recipe
1347 that defines additional software as part of the image.
1348 The following example shows the form for the two lines you need:
1349 <literallayout class='monospaced'>
1350 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1351
1352 inherit core-image
1353 </literallayout>
1354 </para>
1355
1356 <para>
1357 Defining the software using a custom recipe gives you total
1358 control over the contents of the image.
1359 It is important to use the correct names of packages in the
1360 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>
1361 variable.
1362 You must use the OpenEmbedded notation and not the Debian notation for the names
1363 (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>).
1364 </para>
1365
1366 <para>
1367 The other method for creating a custom image is to base it on an existing image.
1368 For example, if you want to create an image based on <filename>core-image-sato</filename>
1369 but add the additional package <filename>strace</filename> to the image,
1370 copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a
1371 new <filename>.bb</filename> and add the following line to the end of the copy:
1372 <literallayout class='monospaced'>
1373 IMAGE_INSTALL += "strace"
1374 </literallayout>
1375 </para>
1376 </section>
1377
1378 <section id='usingpoky-extend-customimage-customtasks'>
1379 <title>Customizing Images Using Custom Package Groups</title>
1380
1381 <para>
1382 For complex custom images, the best approach for customizing
1383 an image is to create a custom package group recipe that is
1384 used to build the image or images.
1385 A good example of a package group recipe is
1386 <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>.
1387 </para>
1388
1389 <para>
1390 If you examine that recipe, you see that the
1391 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename>
1392 variable lists the package group packages to produce.
1393 The <filename>inherit packagegroup</filename> statement
1394 sets appropriate default values and automatically adds
1395 <filename>-dev</filename>, <filename>-dbg</filename>, and
1396 <filename>-ptest</filename> complementary packages for each
1397 package specified in the <filename>PACKAGES</filename>
1398 statement.
1399 <note>
1400 The <filename>inherit packages</filename> should be
1401 located near the top of the recipe, certainly before
1402 the <filename>PACKAGES</filename> statement.
1403 </note>
1404 </para>
1405
1406 <para>
1407 For each package you specify in <filename>PACKAGES</filename>,
1408 you can use
1409 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename>
1410 and
1411 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename>
1412 entries to provide a list of packages the parent task package
1413 should contain.
1414 You can see examples of these further down in the
1415 <filename>packagegroup-base.bb</filename> recipe.
1416 </para>
1417
1418 <para>
1419 Here is a short, fabricated example showing the same basic
1420 pieces:
1421 <literallayout class='monospaced'>
1422 DESCRIPTION = "My Custom Package Groups"
1423
1424 inherit packagegroup
1425
1426 PACKAGES = "\
1427 packagegroup-custom-apps \
1428 packagegroup-custom-tools \
1429 "
1430
1431 RDEPENDS_packagegroup-custom-apps = "\
1432 dropbear \
1433 portmap \
1434 psplash"
1435
1436 RDEPENDS_packagegroup-custom-tools = "\
1437 oprofile \
1438 oprofileui-server \
1439 lttng-tools"
1440
1441 RRECOMMENDS_packagegroup-custom-tools = "\
1442 kernel-module-oprofile"
1443 </literallayout>
1444 </para>
1445
1446 <para>
1447 In the previous example, two package group packages are created with their dependencies and their
1448 recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and
1449 <filename>packagegroup-custom-tools</filename>.
1450 To build an image using these package group packages, you need to add
1451 <filename>packagegroup-custom-apps</filename> and/or
1452 <filename>packagegroup-custom-tools</filename> to
1453 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>.
1454 For other forms of image dependencies see the other areas of this section.
1455 </para>
1456 </section>
1457
1458 <section id='usingpoky-extend-customimage-image-name'>
1459 <title>Customizing an Image Hostname</title>
1460
1461 <para>
1462 By default, the configured hostname (i.e.
1463 <filename>/etc/hostname</filename>) in an image is the
1464 same as the machine name.
1465 For example, if
1466 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
1467 equals "qemux86", the configured hostname written to
1468 <filename>/etc/hostname</filename> is "qemux86".
1469 </para>
1470
1471 <para>
1472 You can customize this name by altering the value of the
1473 "hostname" variable in the
1474 <filename>base-files</filename> recipe using either
1475 an append file or a configuration file.
1476 Use the following in an append file:
1477 <literallayout class='monospaced'>
1478 hostname="myhostname"
1479 </literallayout>
1480 Use the following in a configuration file:
1481 <literallayout class='monospaced'>
1482 hostname_pn-base-files = "myhostname"
1483 </literallayout>
1484 </para>
1485
1486 <para>
1487 Changing the default value of the variable "hostname" can be
1488 useful in certain situations.
1489 For example, suppose you need to do extensive testing on an
1490 image and you would like to easily identify the image
1491 under test from existing images with typical default
1492 hostnames.
1493 In this situation, you could change the default hostname to
1494 "testme", which results in all the images using the name
1495 "testme".
1496 Once testing is complete and you do not need to rebuild the
1497 image for test any longer, you can easily reset the default
1498 hostname.
1499 </para>
1500
1501 <para>
1502 Another point of interest is that if you unset the variable,
1503 the image will have no default hostname in the filesystem.
1504 Here is an example that unsets the variable in a
1505 configuration file:
1506 <literallayout class='monospaced'>
1507 hostname_pn-base-files = ""
1508 </literallayout>
1509 Having no default hostname in the filesystem is suitable for
1510 environments that use dynamic hostnames such as virtual
1511 machines.
1512 </para>
1513 </section>
1514 </section>
1515
1516 <section id='new-recipe-writing-a-new-recipe'>
1517 <title>Writing a New Recipe</title>
1518
1519 <para>
1520 Recipes (<filename>.bb</filename> files) are fundamental components
1521 in the Yocto Project environment.
1522 Each software component built by the OpenEmbedded build system
1523 requires a recipe to define the component.
1524 This section describes how to create, write, and test a new
1525 recipe.
1526 <note>
1527 For information on variables that are useful for recipes and
1528 for information about recipe naming issues, see the
1529 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>"
1530 section of the Yocto Project Reference Manual.
1531 </note>
1532 </para>
1533
1534 <section id='new-recipe-overview'>
1535 <title>Overview</title>
1536
1537 <para>
1538 The following figure shows the basic process for creating a
1539 new recipe.
1540 The remainder of the section provides details for the steps.
1541 <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" />
1542 </para>
1543 </section>
1544
1545 <section id='new-recipe-locate-or-automatically-create-a-base-recipe'>
1546 <title>Locate or Automatically Create a Base Recipe</title>
1547
1548 <para>
1549 You can always write a recipe from scratch.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001550 However, three choices exist that can help you quickly get a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001551 start on a new recipe:
1552 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001553 <listitem><para>
1554 <emphasis><filename>devtool add</filename>:</emphasis>
1555 A command that assists in creating a recipe and
1556 an environment conducive to development.
1557 </para></listitem>
1558 <listitem><para>
1559 <emphasis><filename>recipetool create</filename>:</emphasis>
1560 A command provided by the Yocto Project that automates
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001561 creation of a base recipe based on the source
1562 files.
1563 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001564 <listitem><para>
1565 <emphasis>Existing Recipes:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001566 Location and modification of an existing recipe that is
1567 similar in function to the recipe you need.
1568 </para></listitem>
1569 </itemizedlist>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001570 <note>
1571 For information on recipe syntax, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001572 "<link linkend='recipe-syntax'>Recipe Syntax</link>"
1573 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001574 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001575 </para>
1576
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001577 <section id='new-recipe-creating-the-base-recipe-using-devtool'>
1578 <title>Creating the Base Recipe Using <filename>devtool add</filename></title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001579
1580 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001581 The <filename>devtool add</filename> command uses the same
1582 logic for auto-creating the recipe as
1583 <filename>recipetool create</filename>, which is listed
1584 below.
1585 Additionally, however, <filename>devtool add</filename>
1586 sets up an environment that makes it easy for you to
1587 patch the source and to make changes to the recipe as
1588 is often necessary when adding a recipe to build a new
1589 piece of software to be included in a build.
1590 </para>
1591
1592 <para>
1593 You can find a complete description of the
1594 <filename>devtool add</filename> command in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001595 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>"
1596 section in the Yocto Project Application Development
1597 and the Extensible Software Development Kit (eSDK) manual.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001598 </para>
1599 </section>
1600
1601 <section id='new-recipe-creating-the-base-recipe-using-recipetool'>
1602 <title>Creating the Base Recipe Using <filename>recipetool create</filename></title>
1603
1604 <para>
1605 <filename>recipetool create</filename> automates creation
1606 of a base recipe given a set of source code files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001607 As long as you can extract or point to the source files,
1608 the tool will construct a recipe and automatically
1609 configure all pre-build information into the recipe.
1610 For example, suppose you have an application that builds
1611 using Autotools.
1612 Creating the base recipe using
1613 <filename>recipetool</filename> results in a recipe
1614 that has the pre-build dependencies, license requirements,
1615 and checksums configured.
1616 </para>
1617
1618 <para>
1619 To run the tool, you just need to be in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001620 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001621 and have sourced the build environment setup script
1622 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001623 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>).
Brad Bishop316dfdd2018-06-25 12:45:53 -04001624 To get help on the tool, use the following command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001625 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001626 $ recipetool -h
1627 NOTE: Starting bitbake server...
1628 usage: recipetool [-d] [-q] [--color COLOR] [-h] &lt;subcommand&gt; ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001629
Brad Bishop316dfdd2018-06-25 12:45:53 -04001630 OpenEmbedded recipe tool
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001631
Brad Bishop316dfdd2018-06-25 12:45:53 -04001632 options:
1633 -d, --debug Enable debug output
1634 -q, --quiet Print only errors
1635 --color COLOR Colorize output (where COLOR is auto, always, never)
1636 -h, --help show this help message and exit
1637
1638 subcommands:
1639 create Create a new recipe
1640 newappend Create a bbappend for the specified target in the specified
1641 layer
1642 setvar Set a variable within a recipe
1643 appendfile Create/update a bbappend to replace a target file
1644 appendsrcfiles Create/update a bbappend to add or replace source files
1645 appendsrcfile Create/update a bbappend to add or replace a source file
1646 Use recipetool &lt;subcommand&gt; --help to get help on a specific command
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001647 </literallayout>
1648 </para>
1649
1650 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001651 Running
1652 <filename>recipetool create -o</filename>&nbsp;<replaceable>OUTFILE</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001653 creates the base recipe and locates it properly in the
1654 layer that contains your source files.
1655 Following are some syntax examples:
1656 </para>
1657
1658 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001659 Use this syntax to generate a recipe based on
1660 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001661 Once generated, the recipe resides in the existing source
1662 code layer:
1663 <literallayout class='monospaced'>
1664 recipetool create -o <replaceable>OUTFILE</replaceable>&nbsp;<replaceable>source</replaceable>
1665 </literallayout>
1666 Use this syntax to generate a recipe using code that you
1667 extract from <replaceable>source</replaceable>.
1668 The extracted code is placed in its own layer defined
1669 by <replaceable>EXTERNALSRC</replaceable>.
1670 <literallayout class='monospaced'>
1671 recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable>
1672 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04001673 Use this syntax to generate a recipe based on
1674 <replaceable>source</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001675 The options direct <filename>recipetool</filename> to
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001676 generate debugging information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001677 Once generated, the recipe resides in the existing source
1678 code layer:
1679 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001680 recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001681 </literallayout>
1682 </para>
1683 </section>
1684
1685 <section id='new-recipe-locating-and-using-a-similar-recipe'>
1686 <title>Locating and Using a Similar Recipe</title>
1687
1688 <para>
1689 Before writing a recipe from scratch, it is often useful to
1690 discover whether someone else has already written one that
1691 meets (or comes close to meeting) your needs.
1692 The Yocto Project and OpenEmbedded communities maintain many
1693 recipes that might be candidates for what you are doing.
1694 You can find a good central index of these recipes in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001695 <ulink url='http://layers.openembedded.org'>OpenEmbedded Layer Index</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001696 </para>
1697
1698 <para>
1699 Working from an existing recipe or a skeleton recipe is the
1700 best way to get started.
1701 Here are some points on both methods:
1702 <itemizedlist>
1703 <listitem><para><emphasis>Locate and modify a recipe that
1704 is close to what you want to do:</emphasis>
1705 This method works when you are familiar with the
1706 current recipe space.
1707 The method does not work so well for those new to
1708 the Yocto Project or writing recipes.</para>
1709 <para>Some risks associated with this method are
1710 using a recipe that has areas totally unrelated to
1711 what you are trying to accomplish with your recipe,
1712 not recognizing areas of the recipe that you might
1713 have to add from scratch, and so forth.
1714 All these risks stem from unfamiliarity with the
1715 existing recipe space.</para></listitem>
1716 <listitem><para><emphasis>Use and modify the following
1717 skeleton recipe:</emphasis>
1718 If for some reason you do not want to use
1719 <filename>recipetool</filename> and you cannot
1720 find an existing recipe that is close to meeting
1721 your needs, you can use the following structure to
1722 provide the fundamental areas of a new recipe.
1723 <literallayout class='monospaced'>
1724 DESCRIPTION = ""
1725 HOMEPAGE = ""
1726 LICENSE = ""
1727 SECTION = ""
1728 DEPENDS = ""
1729 LIC_FILES_CHKSUM = ""
1730
1731 SRC_URI = ""
1732 </literallayout>
1733 </para></listitem>
1734 </itemizedlist>
1735 </para>
1736 </section>
1737 </section>
1738
1739 <section id='new-recipe-storing-and-naming-the-recipe'>
1740 <title>Storing and Naming the Recipe</title>
1741
1742 <para>
1743 Once you have your base recipe, you should put it in your
1744 own layer and name it appropriately.
1745 Locating it correctly ensures that the OpenEmbedded build
1746 system can find it when you use BitBake to process the
1747 recipe.
1748 </para>
1749
1750 <itemizedlist>
1751 <listitem><para><emphasis>Storing Your Recipe:</emphasis>
1752 The OpenEmbedded build system locates your recipe
1753 through the layer's <filename>conf/layer.conf</filename>
1754 file and the
1755 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink>
1756 variable.
1757 This variable sets up a path from which the build system can
1758 locate recipes.
1759 Here is the typical use:
1760 <literallayout class='monospaced'>
1761 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1762 ${LAYERDIR}/recipes-*/*/*.bbappend"
1763 </literallayout>
1764 Consequently, you need to be sure you locate your new recipe
1765 inside your layer such that it can be found.</para>
1766 <para>You can find more information on how layers are
1767 structured in the
1768 "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>"
1769 section.</para></listitem>
1770 <listitem><para><emphasis>Naming Your Recipe:</emphasis>
1771 When you name your recipe, you need to follow this naming
1772 convention:
1773 <literallayout class='monospaced'>
1774 <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb
1775 </literallayout>
1776 Use lower-cased characters and do not include the reserved
1777 suffixes <filename>-native</filename>,
1778 <filename>-cross</filename>, <filename>-initial</filename>,
1779 or <filename>-dev</filename> casually (i.e. do not use them
1780 as part of your recipe name unless the string applies).
1781 Here are some examples:
1782 <literallayout class='monospaced'>
1783 cups_1.7.0.bb
1784 gawk_4.0.2.bb
1785 irssi_0.8.16-rc1.bb
1786 </literallayout></para></listitem>
1787 </itemizedlist>
1788 </section>
1789
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001790 <section id='new-recipe-running-a-build-on-the-recipe'>
1791 <title>Running a Build on the Recipe</title>
1792
1793 <para>
1794 Creating a new recipe is usually an iterative process that
1795 requires using BitBake to process the recipe multiple times in
1796 order to progressively discover and add information to the
1797 recipe file.
1798 </para>
1799
1800 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001801 Assuming you have sourced the build environment setup script (i.e.
1802 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001803 and you are in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001804 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001805 use BitBake to process your recipe.
1806 All you need to provide is the
1807 <filename><replaceable>basename</replaceable></filename> of the recipe as described
1808 in the previous section:
1809 <literallayout class='monospaced'>
1810 $ bitbake <replaceable>basename</replaceable>
1811 </literallayout>
1812
1813 </para>
1814
1815 <para>
1816 During the build, the OpenEmbedded build system creates a
1817 temporary work directory for each recipe
1818 (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>)
1819 where it keeps extracted source files, log files, intermediate
1820 compilation and packaging files, and so forth.
1821 </para>
1822
1823 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001824 The path to the per-recipe temporary work directory depends
1825 on the context in which it is being built.
1826 The quickest way to find this path is to have BitBake return it
1827 by running the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001828 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001829 $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR=
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001830 </literallayout>
1831 As an example, assume a Source Directory top-level folder named
1832 <filename>poky</filename>, a default Build Directory at
1833 <filename>poky/build</filename>, and a
1834 <filename>qemux86-poky-linux</filename> machine target system.
1835 Furthermore, suppose your recipe is named
1836 <filename>foo_1.3.0.bb</filename>.
1837 In this case, the work directory the build system uses to
1838 build the package would be as follows:
1839 <literallayout class='monospaced'>
1840 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1841 </literallayout>
1842 Inside this directory you can find sub-directories such as
1843 <filename>image</filename>, <filename>packages-split</filename>,
1844 and <filename>temp</filename>.
1845 After the build, you can examine these to determine how well
1846 the build went.
1847 <note>
1848 You can find log files for each task in the recipe's
1849 <filename>temp</filename> directory (e.g.
1850 <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>).
1851 Log files are named <filename>log.<replaceable>taskname</replaceable></filename>
1852 (e.g. <filename>log.do_configure</filename>,
1853 <filename>log.do_fetch</filename>, and
1854 <filename>log.do_compile</filename>).
1855 </note>
1856 </para>
1857
1858 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001859 You can find more information about the build process in
Brad Bishop316dfdd2018-06-25 12:45:53 -04001860 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-development-environment'>The Yocto Project Development Environment</ulink>"
1861 chapter of the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001862 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863 </section>
1864
1865 <section id='new-recipe-fetching-code'>
1866 <title>Fetching Code</title>
1867
1868 <para>
1869 The first thing your recipe must do is specify how to fetch
1870 the source files.
1871 Fetching is controlled mainly through the
1872 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1873 variable.
1874 Your recipe must have a <filename>SRC_URI</filename> variable
1875 that points to where the source is located.
1876 For a graphical representation of source locations, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04001877 "<ulink url='&YOCTO_DOCS_OM_URL;#sources-dev-environment'>Sources</ulink>"
1878 section in the Yocto Project Overview and Concepts Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001879 </para>
1880
1881 <para>
1882 The
1883 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
1884 task uses the prefix of each entry in the
1885 <filename>SRC_URI</filename> variable value to determine which
Brad Bishopc342db32019-05-15 21:57:59 -04001886 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>
1887 to use to get your source files.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001888 It is the <filename>SRC_URI</filename> variable that triggers
1889 the fetcher.
1890 The
1891 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
1892 task uses the variable after source is fetched to apply
1893 patches.
1894 The OpenEmbedded build system uses
1895 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink>
1896 for scanning directory locations for local files in
1897 <filename>SRC_URI</filename>.
1898 </para>
1899
1900 <para>
1901 The <filename>SRC_URI</filename> variable in your recipe must
1902 define each unique location for your source files.
1903 It is good practice to not hard-code pathnames in an URL used
1904 in <filename>SRC_URI</filename>.
1905 Rather than hard-code these paths, use
1906 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
1907 which causes the fetch process to use the version specified in
1908 the recipe filename.
1909 Specifying the version in this manner means that upgrading the
1910 recipe to a future version is as simple as renaming the recipe
1911 to match the new version.
1912 </para>
1913
1914 <para>
1915 Here is a simple example from the
1916 <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename>
1917 recipe where the source comes from a single tarball.
1918 Notice the use of the
1919 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1920 variable:
1921 <literallayout class='monospaced'>
1922 SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2"
1923 </literallayout>
1924 </para>
1925
1926 <para>
1927 Files mentioned in <filename>SRC_URI</filename> whose names end
1928 in a typical archive extension (e.g. <filename>.tar</filename>,
1929 <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>,
1930 <filename>.zip</filename>, and so forth), are automatically
1931 extracted during the
1932 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
1933 task.
1934 For another example that specifies these types of files, see
1935 the
1936 "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>"
1937 section.
1938 </para>
1939
1940 <para>
1941 Another way of specifying source is from an SCM.
1942 For Git repositories, you must specify
1943 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
1944 and you should specify
1945 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
1946 to include the revision with
1947 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
1948 Here is an example from the recipe
1949 <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>:
1950 <literallayout class='monospaced'>
1951 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1952
1953 PR = "r6"
1954 PV = "1.0.5+git${SRCPV}"
1955
1956 SRC_URI = "git://git.kernel.dk/blktrace.git \
1957 file://ldflags.patch"
1958 </literallayout>
1959 </para>
1960
1961 <para>
1962 If your <filename>SRC_URI</filename> statement includes
1963 URLs pointing to individual files fetched from a remote server
1964 other than a version control system, BitBake attempts to
1965 verify the files against checksums defined in your recipe to
1966 ensure they have not been tampered with or otherwise modified
1967 since the recipe was written.
1968 Two checksums are used:
1969 <filename>SRC_URI[md5sum]</filename> and
1970 <filename>SRC_URI[sha256sum]</filename>.
1971 </para>
1972
1973 <para>
1974 If your <filename>SRC_URI</filename> variable points to
1975 more than a single URL (excluding SCM URLs), you need to
1976 provide the <filename>md5</filename> and
1977 <filename>sha256</filename> checksums for each URL.
1978 For these cases, you provide a name for each URL as part of
1979 the <filename>SRC_URI</filename> and then reference that name
1980 in the subsequent checksum statements.
1981 Here is an example:
1982 <literallayout class='monospaced'>
1983 SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001984 ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001985
1986 SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8"
1987 SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d"
1988
1989 SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92"
1990 SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430"
1991 </literallayout>
1992 </para>
1993
1994 <para>
1995 Proper values for <filename>md5</filename> and
1996 <filename>sha256</filename> checksums might be available
1997 with other signatures on the download page for the upstream
1998 source (e.g. <filename>md5</filename>,
1999 <filename>sha1</filename>, <filename>sha256</filename>,
2000 <filename>GPG</filename>, and so forth).
2001 Because the OpenEmbedded build system only deals with
2002 <filename>sha256sum</filename> and <filename>md5sum</filename>,
2003 you should verify all the signatures you find by hand.
2004 </para>
2005
2006 <para>
2007 If no <filename>SRC_URI</filename> checksums are specified
2008 when you attempt to build the recipe, or you provide an
2009 incorrect checksum, the build will produce an error for each
2010 missing or incorrect checksum.
2011 As part of the error message, the build system provides
2012 the checksum string corresponding to the fetched file.
2013 Once you have the correct checksums, you can copy and paste
2014 them into your recipe and then run the build again to continue.
2015 <note>
2016 As mentioned, if the upstream source provides signatures
2017 for verifying the downloaded source code, you should
2018 verify those manually before setting the checksum values
2019 in the recipe and continuing with the build.
2020 </note>
2021 </para>
2022
2023 <para>
2024 This final example is a bit more complicated and is from the
2025 <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename>
2026 recipe.
2027 The example's <filename>SRC_URI</filename> statement identifies
2028 multiple files as the source files for the recipe: a tarball, a
2029 patch file, a desktop file, and an icon.
2030 <literallayout class='monospaced'>
2031 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
2032 file://xwc.patch \
2033 file://rxvt.desktop \
2034 file://rxvt.png"
2035 </literallayout>
2036 </para>
2037
2038 <para>
2039 When you specify local files using the
2040 <filename>file://</filename> URI protocol, the build system
2041 fetches files from the local machine.
2042 The path is relative to the
2043 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink>
2044 variable and searches specific directories in a certain order:
2045 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>,
2046 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>,
2047 and <filename>files</filename>.
2048 The directories are assumed to be subdirectories of the
2049 directory in which the recipe or append file resides.
2050 For another example that specifies these types of files, see the
2051 "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>"
2052 section.
2053 </para>
2054
2055 <para>
2056 The previous example also specifies a patch file.
2057 Patch files are files whose names usually end in
2058 <filename>.patch</filename> or <filename>.diff</filename> but
2059 can end with compressed suffixes such as
2060 <filename>diff.gz</filename> and
2061 <filename>patch.bz2</filename>, for example.
2062 The build system automatically applies patches as described
2063 in the
2064 "<link linkend='new-recipe-patching-code'>Patching Code</link>" section.
2065 </para>
2066 </section>
2067
2068 <section id='new-recipe-unpacking-code'>
2069 <title>Unpacking Code</title>
2070
2071 <para>
2072 During the build, the
2073 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>
2074 task unpacks the source with
2075 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>
2076 pointing to where it is unpacked.
2077 </para>
2078
2079 <para>
2080 If you are fetching your source files from an upstream source
2081 archived tarball and the tarball's internal structure matches
2082 the common convention of a top-level subdirectory named
2083 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>,
2084 then you do not need to set <filename>S</filename>.
2085 However, if <filename>SRC_URI</filename> specifies to fetch
2086 source from an archive that does not use this convention,
2087 or from an SCM like Git or Subversion, your recipe needs to
2088 define <filename>S</filename>.
2089 </para>
2090
2091 <para>
2092 If processing your recipe using BitBake successfully unpacks
2093 the source files, you need to be sure that the directory
2094 pointed to by <filename>${S}</filename> matches the structure
2095 of the source.
2096 </para>
2097 </section>
2098
2099 <section id='new-recipe-patching-code'>
2100 <title>Patching Code</title>
2101
2102 <para>
2103 Sometimes it is necessary to patch code after it has been
2104 fetched.
2105 Any files mentioned in <filename>SRC_URI</filename> whose
2106 names end in <filename>.patch</filename> or
2107 <filename>.diff</filename> or compressed versions of these
2108 suffixes (e.g. <filename>diff.gz</filename> are treated as
2109 patches.
2110 The
2111 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
2112 task automatically applies these patches.
2113 </para>
2114
2115 <para>
2116 The build system should be able to apply patches with the "-p1"
2117 option (i.e. one directory level in the path will be stripped
2118 off).
2119 If your patch needs to have more directory levels stripped off,
2120 specify the number of levels using the "striplevel" option in
2121 the <filename>SRC_URI</filename> entry for the patch.
2122 Alternatively, if your patch needs to be applied in a specific
2123 subdirectory that is not specified in the patch file, use the
2124 "patchdir" option in the entry.
2125 </para>
2126
2127 <para>
2128 As with all local files referenced in
2129 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
2130 using <filename>file://</filename>, you should place
2131 patch files in a directory next to the recipe either
2132 named the same as the base name of the recipe
2133 (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
2134 and
2135 <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>)
2136 or "files".
2137 </para>
2138 </section>
2139
2140 <section id='new-recipe-licensing'>
2141 <title>Licensing</title>
2142
2143 <para>
2144 Your recipe needs to have both the
2145 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
2146 and
2147 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
2148 variables:
2149 <itemizedlist>
2150 <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis>
2151 This variable specifies the license for the software.
2152 If you do not know the license under which the software
2153 you are building is distributed, you should go to the
2154 source code and look for that information.
2155 Typical files containing this information include
2156 <filename>COPYING</filename>,
2157 <filename>LICENSE</filename>, and
2158 <filename>README</filename> files.
2159 You could also find the information near the top of
2160 a source file.
2161 For example, given a piece of software licensed under
2162 the GNU General Public License version 2, you would
2163 set <filename>LICENSE</filename> as follows:
2164 <literallayout class='monospaced'>
2165 LICENSE = "GPLv2"
2166 </literallayout></para>
2167 <para>The licenses you specify within
2168 <filename>LICENSE</filename> can have any name as long
2169 as you do not use spaces, since spaces are used as
2170 separators between license names.
2171 For standard licenses, use the names of the files in
2172 <filename>meta/files/common-licenses/</filename>
2173 or the <filename>SPDXLICENSEMAP</filename> flag names
2174 defined in <filename>meta/conf/licenses.conf</filename>.
2175 </para></listitem>
2176 <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis>
2177 The OpenEmbedded build system uses this variable to
2178 make sure the license text has not changed.
2179 If it has, the build produces an error and it affords
2180 you the chance to figure it out and correct the problem.
2181 </para>
2182 <para>You need to specify all applicable licensing
2183 files for the software.
2184 At the end of the configuration step, the build process
2185 will compare the checksums of the files to be sure
2186 the text has not changed.
2187 Any differences result in an error with the message
2188 containing the current checksum.
2189 For more explanation and examples of how to set the
2190 <filename>LIC_FILES_CHKSUM</filename> variable, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002191 "<link link='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
2192 section.</para>
2193
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002194 <para>To determine the correct checksum string, you
2195 can list the appropriate files in the
2196 <filename>LIC_FILES_CHKSUM</filename> variable with
2197 incorrect md5 strings, attempt to build the software,
2198 and then note the resulting error messages that will
2199 report the correct md5 strings.
2200 See the
2201 "<link linkend='new-recipe-fetching-code'>Fetching Code</link>"
2202 section for additional information.
2203 </para>
2204
2205 <para>
2206 Here is an example that assumes the software has a
2207 <filename>COPYING</filename> file:
2208 <literallayout class='monospaced'>
2209 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
2210 </literallayout>
2211 When you try to build the software, the build system
2212 will produce an error and give you the correct string
2213 that you can substitute into the recipe file for a
2214 subsequent build.
2215 </para></listitem>
2216 </itemizedlist>
2217 </para>
2218
2219<!--
2220
2221 <para>
2222 For trying this out I created a new recipe named
2223 <filename>htop_1.0.2.bb</filename> and put it in
2224 <filename>poky/meta/recipes-extended/htop</filename>.
2225 There are two license type statements in my very simple
2226 recipe:
2227 <literallayout class='monospaced'>
2228 LICENSE = ""
2229
2230 LIC_FILES_CHKSUM = ""
2231
2232 SRC_URI[md5sum] = ""
2233 SRC_URI[sha256sum] = ""
2234 </literallayout>
2235 Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>.
2236 Next, you delete or comment out the two <filename>SRC_URI</filename>
2237 lines at the end and then attempt to build the software with
2238 <filename>bitbake htop</filename>.
2239 Doing so causes BitBake to report some errors and and give
2240 you the actual strings you need for the last two
2241 <filename>SRC_URI</filename> lines.
2242 Prior to this, you have to dig around in the home page of the
2243 source for <filename>htop</filename> and determine that the
2244 software is released under GPLv2.
2245 You can provide that in the <filename>LICENSE</filename>
2246 statement.
2247 Now you edit your recipe to have those two strings for
2248 the <filename>SRC_URI</filename> statements:
2249 <literallayout class='monospaced'>
2250 LICENSE = "GPLv2"
2251
2252 LIC_FILES_CHKSUM = ""
2253
2254 SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz"
2255 SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e"
2256 SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1"
2257 </literallayout>
2258 At this point, you can build the software again using the
2259 <filename>bitbake htop</filename> command.
2260 There is just a set of errors now associated with the
2261 empty <filename>LIC_FILES_CHKSUM</filename> variable now.
2262 </para>
2263-->
2264
2265 </section>
2266
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002267 <section id='new-dependencies'>
2268 <title>Dependencies</title>
2269
2270 <para>
2271 Most software packages have a short list of other packages
2272 that they require, which are called dependencies.
2273 These dependencies fall into two main categories: build-time
2274 dependencies, which are required when the software is built;
2275 and runtime dependencies, which are required to be installed
2276 on the target in order for the software to run.
2277 </para>
2278
2279 <para>
2280 Within a recipe, you specify build-time dependencies using the
2281 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2282 variable.
2283 Although nuances exist, items specified in
2284 <filename>DEPENDS</filename> should be names of other recipes.
2285 It is important that you specify all build-time dependencies
2286 explicitly.
2287 If you do not, due to the parallel nature of BitBake's
2288 execution, you can end up with a race condition where the
2289 dependency is present for one task of a recipe (e.g.
2290 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>)
2291 and then gone when the next task runs (e.g.
2292 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>).
2293 </para>
2294
2295 <para>
2296 Another consideration is that configure scripts might
2297 automatically check for optional dependencies and enable
2298 corresponding functionality if those dependencies are found.
2299 This behavior means that to ensure deterministic results and
2300 thus avoid more race conditions, you need to either explicitly
2301 specify these dependencies as well, or tell the configure
2302 script explicitly to disable the functionality.
2303 If you wish to make a recipe that is more generally useful
2304 (e.g. publish the recipe in a layer for others to use),
2305 instead of hard-disabling the functionality, you can use the
2306 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink>
2307 variable to allow functionality and the corresponding
2308 dependencies to be enabled and disabled easily by other
2309 users of the recipe.
2310 </para>
2311
2312 <para>
2313 Similar to build-time dependencies, you specify runtime
2314 dependencies through a variable -
2315 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
2316 which is package-specific.
2317 All variables that are package-specific need to have the name
2318 of the package added to the end as an override.
2319 Since the main package for a recipe has the same name as the
2320 recipe, and the recipe's name can be found through the
2321 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
2322 variable, then you specify the dependencies for the main
2323 package by setting <filename>RDEPENDS_${PN}</filename>.
2324 If the package were named <filename>${PN}-tools</filename>,
2325 then you would set <filename>RDEPENDS_${PN}-tools</filename>,
2326 and so forth.
2327 </para>
2328
2329 <para>
2330 Some runtime dependencies will be set automatically at
2331 packaging time.
2332 These dependencies include any shared library dependencies
2333 (i.e. if a package "example" contains "libexample" and
2334 another package "mypackage" contains a binary that links to
2335 "libexample" then the OpenEmbedded build system will
2336 automatically add a runtime dependency to "mypackage" on
2337 "example").
2338 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04002339 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
2340 section in the Yocto Project Overview and Concepts Manual for
2341 further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002342 </para>
2343 </section>
2344
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002345 <section id='new-recipe-configuring-the-recipe'>
2346 <title>Configuring the Recipe</title>
2347
2348 <para>
2349 Most software provides some means of setting build-time
2350 configuration options before compilation.
2351 Typically, setting these options is accomplished by running a
2352 configure script with some options, or by modifying a build
2353 configuration file.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002354 <note>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002355 As of Yocto Project Release 1.7, some of the core recipes
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002356 that package binary configuration scripts now disable the
2357 scripts due to the scripts previously requiring error-prone
2358 path substitution.
2359 The OpenEmbedded build system uses
2360 <filename>pkg-config</filename> now, which is much more
2361 robust.
2362 You can find a list of the <filename>*-config</filename>
2363 scripts that are disabled list in the
2364 "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>"
2365 section in the Yocto Project Reference Manual.
2366 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002367 </para>
2368
2369 <para>
2370 A major part of build-time configuration is about checking for
2371 build-time dependencies and possibly enabling optional
2372 functionality as a result.
2373 You need to specify any build-time dependencies for the
2374 software you are building in your recipe's
2375 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
2376 value, in terms of other recipes that satisfy those
2377 dependencies.
2378 You can often find build-time or runtime
2379 dependencies described in the software's documentation.
2380 </para>
2381
2382 <para>
2383 The following list provides configuration items of note based
2384 on how your software is built:
2385 <itemizedlist>
2386 <listitem><para><emphasis>Autotools:</emphasis>
2387 If your source files have a
2388 <filename>configure.ac</filename> file, then your
2389 software is built using Autotools.
2390 If this is the case, you just need to worry about
2391 modifying the configuration.</para>
2392 <para>When using Autotools, your recipe needs to inherit
2393 the
2394 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2395 class and your recipe does not have to contain a
2396 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2397 task.
2398 However, you might still want to make some adjustments.
2399 For example, you can set
2400 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002401 or
2402 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002403 to pass any needed configure options that are specific
2404 to the recipe.</para></listitem>
2405 <listitem><para><emphasis>CMake:</emphasis>
2406 If your source files have a
2407 <filename>CMakeLists.txt</filename> file, then your
2408 software is built using CMake.
2409 If this is the case, you just need to worry about
2410 modifying the configuration.</para>
2411 <para>When you use CMake, your recipe needs to inherit
2412 the
2413 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2414 class and your recipe does not have to contain a
2415 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2416 task.
2417 You can make some adjustments by setting
2418 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
2419 to pass any needed configure options that are specific
2420 to the recipe.</para></listitem>
2421 <listitem><para><emphasis>Other:</emphasis>
2422 If your source files do not have a
2423 <filename>configure.ac</filename> or
2424 <filename>CMakeLists.txt</filename> file, then your
2425 software is built using some method other than Autotools
2426 or CMake.
2427 If this is the case, you normally need to provide a
2428 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
2429 task in your recipe
2430 unless, of course, there is nothing to configure.
2431 </para>
2432 <para>Even if your software is not being built by
2433 Autotools or CMake, you still might not need to deal
2434 with any configuration issues.
2435 You need to determine if configuration is even a required step.
2436 You might need to modify a Makefile or some configuration file
2437 used for the build to specify necessary build options.
2438 Or, perhaps you might need to run a provided, custom
2439 configure script with the appropriate options.</para>
2440 <para>For the case involving a custom configure
2441 script, you would run
2442 <filename>./configure --help</filename> and look for
2443 the options you need to set.</para></listitem>
2444 </itemizedlist>
2445 </para>
2446
2447 <para>
2448 Once configuration succeeds, it is always good practice to
2449 look at the <filename>log.do_configure</filename> file to
2450 ensure that the appropriate options have been enabled and no
2451 additional build-time dependencies need to be added to
2452 <filename>DEPENDS</filename>.
2453 For example, if the configure script reports that it found
2454 something not mentioned in <filename>DEPENDS</filename>, or
2455 that it did not find something that it needed for some
2456 desired optional functionality, then you would need to add
2457 those to <filename>DEPENDS</filename>.
2458 Looking at the log might also reveal items being checked for,
2459 enabled, or both that you do not want, or items not being found
2460 that are in <filename>DEPENDS</filename>, in which case
2461 you would need to look at passing extra options to the
2462 configure script as needed.
2463 For reference information on configure options specific to the
2464 software you are building, you can consult the output of the
2465 <filename>./configure --help</filename> command within
2466 <filename>${S}</filename> or consult the software's upstream
2467 documentation.
2468 </para>
2469 </section>
2470
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002471 <section id='new-recipe-using-headers-to-interface-with-devices'>
2472 <title>Using Headers to Interface with Devices</title>
2473
2474 <para>
2475 If your recipe builds an application that needs to
2476 communicate with some device or needs an API into a custom
2477 kernel, you will need to provide appropriate header files.
2478 Under no circumstances should you ever modify the existing
2479 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>
2480 file.
2481 These headers are used to build <filename>libc</filename> and
2482 must not be compromised with custom or machine-specific
2483 header information.
2484 If you customize <filename>libc</filename> through modified
2485 headers all other applications that use
2486 <filename>libc</filename> thus become affected.
2487 <note><title>Warning</title>
2488 Never copy and customize the <filename>libc</filename>
2489 header file (i.e.
2490 <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>).
2491 </note>
2492 The correct way to interface to a device or custom kernel is
2493 to use a separate package that provides the additional headers
2494 for the driver or other unique interfaces.
2495 When doing so, your application also becomes responsible for
2496 creating a dependency on that specific provider.
2497 </para>
2498
2499 <para>
2500 Consider the following:
2501 <itemizedlist>
2502 <listitem><para>
2503 Never modify
2504 <filename>linux-libc-headers.inc</filename>.
2505 Consider that file to be part of the
2506 <filename>libc</filename> system, and not something
2507 you use to access the kernel directly.
2508 You should access <filename>libc</filename> through
2509 specific <filename>libc</filename> calls.
2510 </para></listitem>
2511 <listitem><para>
2512 Applications that must talk directly to devices
2513 should either provide necessary headers themselves,
2514 or establish a dependency on a special headers package
2515 that is specific to that driver.
2516 </para></listitem>
2517 </itemizedlist>
2518 </para>
2519
2520 <para>
2521 For example, suppose you want to modify an existing header
2522 that adds I/O control or network support.
2523 If the modifications are used by a small number programs,
2524 providing a unique version of a header is easy and has little
2525 impact.
2526 When doing so, bear in mind the guidelines in the previous
2527 list.
2528 <note>
2529 If for some reason your changes need to modify the behavior
2530 of the <filename>libc</filename>, and subsequently all
2531 other applications on the system, use a
2532 <filename>.bbappend</filename> to modify the
2533 <filename>linux-kernel-headers.inc</filename> file.
2534 However, take care to not make the changes
2535 machine specific.
2536 </note>
2537 </para>
2538
2539 <para>
2540 Consider a case where your kernel is older and you need
2541 an older <filename>libc</filename> ABI.
2542 The headers installed by your recipe should still be a
2543 standard mainline kernel, not your own custom one.
2544 </para>
2545
2546 <para>
2547 When you use custom kernel headers you need to get them from
2548 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>,
2549 which is the directory with kernel headers that are
2550 required to build out-of-tree modules.
2551 Your recipe will also need the following:
2552 <literallayout class='monospaced'>
2553 do_configure[depends] += "virtual/kernel:do_shared_workdir"
2554 </literallayout>
2555 </para>
2556 </section>
2557
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002558 <section id='new-recipe-compilation'>
2559 <title>Compilation</title>
2560
2561 <para>
2562 During a build, the <filename>do_compile</filename> task
2563 happens after source is fetched, unpacked, and configured.
2564 If the recipe passes through <filename>do_compile</filename>
2565 successfully, nothing needs to be done.
2566 </para>
2567
2568 <para>
2569 However, if the compile step fails, you need to diagnose the
2570 failure.
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002571 Here are some common issues that cause failures.
2572 <note>
2573 For cases where improper paths are detected for
2574 configuration files or for when libraries/headers cannot
2575 be found, be sure you are using the more robust
2576 <filename>pkg-config</filename>.
2577 See the note in section
2578 "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>"
2579 for additional information.
2580 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002581 <itemizedlist>
2582 <listitem><para><emphasis>Parallel build failures:</emphasis>
2583 These failures manifest themselves as intermittent
2584 errors, or errors reporting that a file or directory
2585 that should be created by some other part of the build
2586 process could not be found.
2587 This type of failure can occur even if, upon inspection,
2588 the file or directory does exist after the build has
2589 failed, because that part of the build process happened
2590 in the wrong order.</para>
2591 <para>To fix the problem, you need to either satisfy
2592 the missing dependency in the Makefile or whatever
2593 script produced the Makefile, or (as a workaround)
2594 set
2595 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
2596 to an empty string:
2597 <literallayout class='monospaced'>
2598 PARALLEL_MAKE = ""
2599 </literallayout></para>
2600 <para>
2601 For information on parallel Makefile issues, see the
2602 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
2603 section.
2604 </para></listitem>
2605 <listitem><para><emphasis>Improper host path usage:</emphasis>
2606 This failure applies to recipes building for the target
2607 or <filename>nativesdk</filename> only.
2608 The failure occurs when the compilation process uses
2609 improper headers, libraries, or other files from the
2610 host system when cross-compiling for the target.
2611 </para>
2612 <para>To fix the problem, examine the
2613 <filename>log.do_compile</filename> file to identify
2614 the host paths being used (e.g.
2615 <filename>/usr/include</filename>,
2616 <filename>/usr/lib</filename>, and so forth) and then
2617 either add configure options, apply a patch, or do both.
2618 </para></listitem>
2619 <listitem><para><emphasis>Failure to find required
2620 libraries/headers:</emphasis>
2621 If a build-time dependency is missing because it has
2622 not been declared in
2623 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
2624 or because the dependency exists but the path used by
2625 the build process to find the file is incorrect and the
2626 configure step did not detect it, the compilation
2627 process could fail.
2628 For either of these failures, the compilation process
2629 notes that files could not be found.
2630 In these cases, you need to go back and add additional
2631 options to the configure script as well as possibly
2632 add additional build-time dependencies to
2633 <filename>DEPENDS</filename>.</para>
2634 <para>Occasionally, it is necessary to apply a patch
2635 to the source to ensure the correct paths are used.
2636 If you need to specify paths to find files staged
2637 into the sysroot from other recipes, use the variables
2638 that the OpenEmbedded build system provides
2639 (e.g.
2640 <filename>STAGING_BINDIR</filename>,
2641 <filename>STAGING_INCDIR</filename>,
2642 <filename>STAGING_DATADIR</filename>, and so forth).
2643<!--
2644 (e.g.
2645 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>,
2646 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>,
2647 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>,
2648 and so forth).
2649-->
2650 </para></listitem>
2651 </itemizedlist>
2652 </para>
2653 </section>
2654
2655 <section id='new-recipe-installing'>
2656 <title>Installing</title>
2657
2658 <para>
2659 During <filename>do_install</filename>, the task copies the
2660 built files along with their hierarchy to locations that
2661 would mirror their locations on the target device.
2662 The installation process copies files from the
2663 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
2664 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>,
2665 and
2666 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>
2667 directories to the
2668 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2669 directory to create the structure as it should appear on the
2670 target system.
2671 </para>
2672
2673 <para>
2674 How your software is built affects what you must do to be
2675 sure your software is installed correctly.
2676 The following list describes what you must do for installation
2677 depending on the type of build system used by the software
2678 being built:
2679 <itemizedlist>
2680 <listitem><para><emphasis>Autotools and CMake:</emphasis>
2681 If the software your recipe is building uses Autotools
2682 or CMake, the OpenEmbedded build
2683 system understands how to install the software.
2684 Consequently, you do not have to have a
2685 <filename>do_install</filename> task as part of your
2686 recipe.
2687 You just need to make sure the install portion of the
2688 build completes with no issues.
2689 However, if you wish to install additional files not
2690 already being installed by
2691 <filename>make install</filename>, you should do this
2692 using a <filename>do_install_append</filename> function
2693 using the install command as described in
2694 the "Manual" bulleted item later in this list.
2695 </para></listitem>
2696 <listitem><para><emphasis>Other (using
2697 <filename>make install</filename>):</emphasis>
2698 You need to define a
2699 <filename>do_install</filename> function in your
2700 recipe.
2701 The function should call
2702 <filename>oe_runmake install</filename> and will likely
2703 need to pass in the destination directory as well.
2704 How you pass that path is dependent on how the
2705 <filename>Makefile</filename> being run is written
2706 (e.g. <filename>DESTDIR=${D}</filename>,
2707 <filename>PREFIX=${D}</filename>,
2708 <filename>INSTALLROOT=${D}</filename>, and so forth).
2709 </para>
2710 <para>For an example recipe using
2711 <filename>make install</filename>, see the
2712 "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>"
2713 section.</para></listitem>
2714 <listitem><para><emphasis>Manual:</emphasis>
2715 You need to define a
2716 <filename>do_install</filename> function in your
2717 recipe.
2718 The function must first use
2719 <filename>install -d</filename> to create the
2720 directories under
2721 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
2722 Once the directories exist, your function can use
2723 <filename>install</filename> to manually install the
2724 built software into the directories.</para>
2725 <para>You can find more information on
2726 <filename>install</filename> at
2727 <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>.
2728 </para></listitem>
2729 </itemizedlist>
2730 </para>
2731
2732 <para>
2733 For the scenarios that do not use Autotools or
2734 CMake, you need to track the installation
2735 and diagnose and fix any issues until everything installs
2736 correctly.
2737 You need to look in the default location of
2738 <filename>${D}</filename>, which is
2739 <filename>${WORKDIR}/image</filename>, to be sure your
2740 files have been installed correctly.
2741 </para>
2742
2743 <note><title>Notes</title>
2744 <itemizedlist>
2745 <listitem><para>
2746 During the installation process, you might need to
2747 modify some of the installed files to suit the target
2748 layout.
2749 For example, you might need to replace hard-coded paths
2750 in an initscript with values of variables provided by
2751 the build system, such as replacing
2752 <filename>/usr/bin/</filename> with
2753 <filename>${bindir}</filename>.
2754 If you do perform such modifications during
2755 <filename>do_install</filename>, be sure to modify the
2756 destination file after copying rather than before
2757 copying.
2758 Modifying after copying ensures that the build system
2759 can re-execute <filename>do_install</filename> if
2760 needed.
2761 </para></listitem>
2762 <listitem><para>
2763 <filename>oe_runmake install</filename>, which can be
2764 run directly or can be run indirectly by the
2765 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
2766 and
2767 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink>
2768 classes, runs <filename>make install</filename> in
2769 parallel.
2770 Sometimes, a Makefile can have missing dependencies
2771 between targets that can result in race conditions.
2772 If you experience intermittent failures during
2773 <filename>do_install</filename>, you might be able to
2774 work around them by disabling parallel Makefile
2775 installs by adding the following to the recipe:
2776 <literallayout class='monospaced'>
2777 PARALLEL_MAKEINST = ""
2778 </literallayout>
2779 See
2780 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
2781 for additional information.
2782 </para></listitem>
2783 </itemizedlist>
2784 </note>
2785 </section>
2786
2787 <section id='new-recipe-enabling-system-services'>
2788 <title>Enabling System Services</title>
2789
2790 <para>
2791 If you want to install a service, which is a process that
2792 usually starts on boot and runs in the background, then
2793 you must include some additional definitions in your recipe.
2794 </para>
2795
2796 <para>
2797 If you are adding services and the service initialization
2798 script or the service file itself is not installed, you must
2799 provide for that installation in your recipe using a
2800 <filename>do_install_append</filename> function.
2801 If your recipe already has a <filename>do_install</filename>
2802 function, update the function near its end rather than
2803 adding an additional <filename>do_install_append</filename>
2804 function.
2805 </para>
2806
2807 <para>
2808 When you create the installation for your services, you need
2809 to accomplish what is normally done by
2810 <filename>make install</filename>.
2811 In other words, make sure your installation arranges the output
2812 similar to how it is arranged on the target system.
2813 </para>
2814
2815 <para>
2816 The OpenEmbedded build system provides support for starting
2817 services two different ways:
2818 <itemizedlist>
2819 <listitem><para><emphasis>SysVinit:</emphasis>
2820 SysVinit is a system and service manager that
2821 manages the init system used to control the very basic
2822 functions of your system.
2823 The init program is the first program
2824 started by the Linux kernel when the system boots.
2825 Init then controls the startup, running and shutdown
2826 of all other programs.</para>
2827 <para>To enable a service using SysVinit, your recipe
2828 needs to inherit the
2829 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink>
2830 class.
2831 The class helps facilitate safely installing the
2832 package on the target.</para>
2833 <para>You will need to set the
2834 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>,
2835 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>,
2836 and
2837 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink>
2838 variables within your recipe.</para></listitem>
2839 <listitem><para><emphasis>systemd:</emphasis>
2840 System Management Daemon (systemd) was designed to
2841 replace SysVinit and to provide
2842 enhanced management of services.
2843 For more information on systemd, see the systemd
2844 homepage at
2845 <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>.
2846 </para>
2847 <para>To enable a service using systemd, your recipe
2848 needs to inherit the
2849 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink>
2850 class.
2851 See the <filename>systemd.bbclass</filename> file
2852 located in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002853 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002854 section for more information.
2855 </para></listitem>
2856 </itemizedlist>
2857 </para>
2858 </section>
2859
2860 <section id='new-recipe-packaging'>
2861 <title>Packaging</title>
2862
2863 <para>
2864 Successful packaging is a combination of automated processes
2865 performed by the OpenEmbedded build system and some
2866 specific steps you need to take.
2867 The following list describes the process:
2868 <itemizedlist>
2869 <listitem><para><emphasis>Splitting Files</emphasis>:
2870 The <filename>do_package</filename> task splits the
2871 files produced by the recipe into logical components.
2872 Even software that produces a single binary might
2873 still have debug symbols, documentation, and other
2874 logical components that should be split out.
2875 The <filename>do_package</filename> task ensures
2876 that files are split up and packaged correctly.
2877 </para></listitem>
2878 <listitem><para><emphasis>Running QA Checks</emphasis>:
2879 The
2880 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2881 class adds a step to
2882 the package generation process so that output quality
2883 assurance checks are generated by the OpenEmbedded
2884 build system.
2885 This step performs a range of checks to be sure the
2886 build's output is free of common problems that show
2887 up during runtime.
2888 For information on these checks, see the
2889 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink>
2890 class and the
2891 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>"
2892 chapter in the Yocto Project Reference Manual.
2893 </para></listitem>
2894 <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>:
2895 After you build your software, you need to be sure
2896 your packages are correct.
2897 Examine the
2898 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
2899 directory and make sure files are where you expect
2900 them to be.
2901 If you discover problems, you can set
2902 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>,
2903 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
2904 <filename>do_install(_append)</filename>, and so forth as
2905 needed.
2906 </para></listitem>
2907 <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>:
2908 If you need to split an application into several
2909 packages, see the
2910 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
2911 section for an example.
2912 </para></listitem>
2913 <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>:
2914 For an example showing how to install a
2915 post-installation script, see the
2916 "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>"
2917 section.
2918 </para></listitem>
2919 <listitem><para><emphasis>Marking Package Architecture</emphasis>:
2920 Depending on what your recipe is building and how it
2921 is configured, it might be important to mark the
2922 packages produced as being specific to a particular
2923 machine, or to mark them as not being specific to
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002924 a particular machine or architecture at all.</para>
2925 <para>By default, packages apply to any machine with the
2926 same architecture as the target machine.
2927 When a recipe produces packages that are
2928 machine-specific (e.g. the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002929 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
2930 value is passed into the configure script or a patch
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002931 is applied only for a particular machine), you should
2932 mark them as such by adding the following to the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002933 recipe:
2934 <literallayout class='monospaced'>
2935 PACKAGE_ARCH = "${MACHINE_ARCH}"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002936 </literallayout></para>
2937 <para>On the other hand, if the recipe produces packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002938 that do not contain anything specific to the target
2939 machine or architecture at all (e.g. recipes
2940 that simply package script files or configuration
2941 files), you should use the
2942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
2943 class to do this for you by adding this to your
2944 recipe:
2945 <literallayout class='monospaced'>
2946 inherit allarch
2947 </literallayout>
2948 Ensuring that the package architecture is correct is
2949 not critical while you are doing the first few builds
2950 of your recipe.
2951 However, it is important in order
2952 to ensure that your recipe rebuilds (or does not
2953 rebuild) appropriately in response to changes in
2954 configuration, and to ensure that you get the
2955 appropriate packages installed on the target machine,
2956 particularly if you run separate builds for more
2957 than one target machine.
2958 </para></listitem>
2959 </itemizedlist>
2960 </para>
2961 </section>
2962
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002963 <section id='new-sharing-files-between-recipes'>
2964 <title>Sharing Files Between Recipes</title>
2965
2966 <para>
2967 Recipes often need to use files provided by other recipes on
2968 the build host.
2969 For example, an application linking to a common library needs
2970 access to the library itself and its associated headers.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002971 The way this access is accomplished is by populating a sysroot
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002972 with files.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002973 Each recipe has two sysroots in its work directory, one for
2974 target files
2975 (<filename>recipe-sysroot</filename>) and one for files that
2976 are native to the build host
2977 (<filename>recipe-sysroot-native</filename>).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002978 <note>
2979 You could find the term "staging" used within the Yocto
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002980 project regarding files populating sysroots (e.g. the
Brad Bishop37a0e4d2017-12-04 01:01:44 -05002981 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink>
2982 variable).
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002983 </note>
2984 </para>
2985
2986 <para>
2987 Recipes should never populate the sysroot directly (i.e. write
2988 files into sysroot).
2989 Instead, files should be installed into standard locations
2990 during the
2991 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
2992 task within the
2993 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
2994 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002995 The reason for this limitation is that almost all files that
2996 populate the sysroot are cataloged in manifests in order to
2997 ensure the files can be removed later when a recipe is either
2998 modified or removed.
2999 Thus, the sysroot is able to remain free from stale files.
3000 </para>
3001
3002 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003003 A subset of the files installed by the
3004 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3005 task are used by the
3006 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3007 task as defined by the the
3008 <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink>
3009 variable to automatically populate the sysroot.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003010 It is possible to modify the list of directories that populate
3011 the sysroot.
3012 The following example shows how you could add the
3013 <filename>/opt</filename> directory to the list of
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003014 directories within a recipe:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003015 <literallayout class='monospaced'>
3016 SYSROOT_DIRS += "/opt"
3017 </literallayout>
3018 </para>
3019
3020 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003021 For a more complete description of the
3022 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
3023 task and its associated functions, see the
3024 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink>
3025 class.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003026 </para>
3027 </section>
3028
Brad Bishop316dfdd2018-06-25 12:45:53 -04003029 <section id='metadata-virtual-providers'>
3030 <title>Using Virtual Providers</title>
3031
3032 <para>
3033 Prior to a build, if you know that several different recipes
3034 provide the same functionality, you can use a virtual provider
3035 (i.e. <filename>virtual/*</filename>) as a placeholder for the
3036 actual provider.
3037 The actual provider is determined at build-time.
3038 </para>
3039
3040 <para>
3041 A common scenario where a virtual provider is used would be
3042 for the kernel recipe.
3043 Suppose you have three kernel recipes whose
3044 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
3045 values map to <filename>kernel-big</filename>,
3046 <filename>kernel-mid</filename>, and
3047 <filename>kernel-small</filename>.
3048 Furthermore, each of these recipes in some way uses a
3049 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3050 statement that essentially identifies itself as being able
3051 to provide <filename>virtual/kernel</filename>.
3052 Here is one way through the
3053 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-kernel'><filename>kernel</filename></ulink>
3054 class:
3055 <literallayout class='monospaced'>
3056 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
3057 </literallayout>
3058 Any recipe that inherits the <filename>kernel</filename> class
3059 is going to utilize a <filename>PROVIDES</filename> statement
3060 that identifies that recipe as being able to provide the
3061 <filename>virtual/kernel</filename> item.
3062 </para>
3063
3064 <para>
3065 Now comes the time to actually build an image and you need a
3066 kernel recipe, but which one?
3067 You can configure your build to call out the kernel recipe
3068 you want by using the
3069 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></ulink>
3070 variable.
3071 As an example, consider the
3072 <ulink url='https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc'><filename>x86-base.inc</filename></ulink>
3073 include file, which is a machine
3074 (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>)
3075 configuration file.
3076 This include file is the reason all x86-based machines use the
3077 <filename>linux-yocto</filename> kernel.
3078 Here are the relevant lines from the include file:
3079 <literallayout class='monospaced'>
3080 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
3081 PREFERRED_VERSION_linux-yocto ??= "4.15%"
3082 </literallayout>
3083 </para>
3084
3085 <para>
3086 When you use a virtual provider, you do not have to
3087 "hard code" a recipe name as a build dependency.
3088 You can use the
3089 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3090 variable to state the build is dependent on
3091 <filename>virtual/kernel</filename> for example:
3092 <literallayout class='monospaced'>
3093 DEPENDS = "virtual/kernel"
3094 </literallayout>
3095 During the build, the OpenEmbedded build system picks
3096 the correct recipe needed for the
3097 <filename>virtual/kernel</filename> dependency based on the
3098 <filename>PREFERRED_PROVIDER</filename> variable.
3099 If you want to use the small kernel mentioned at the beginning
3100 of this section, configure your build as follows:
3101 <literallayout class='monospaced'>
3102 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
3103 </literallayout>
3104 <note>
3105 Any recipe that
3106 <ulink url='&YOCTO_DOCS_REF_URL;#var-PROVIDES'><filename>PROVIDES</filename></ulink>
3107 a <filename>virtual/*</filename> item that is ultimately
3108 not selected through
3109 <filename>PREFERRED_PROVIDER</filename> does not get built.
3110 Preventing these recipes from building is usually the
3111 desired behavior since this mechanism's purpose is to
3112 select between mutually exclusive alternative providers.
3113 </note>
3114 </para>
3115
3116 <para>
3117 The following lists specific examples of virtual providers:
3118 <itemizedlist>
3119 <listitem><para>
3120 <filename>virtual/kernel</filename>:
3121 Provides the name of the kernel recipe to use when
3122 building a kernel image.
3123 </para></listitem>
3124 <listitem><para>
3125 <filename>virtual/bootloader</filename>:
3126 Provides the name of the bootloader to use when
3127 building an image.
3128 </para></listitem>
3129 <listitem><para>
3130 <filename>virtual/mesa</filename>:
3131 Provides <filename>gbm.pc</filename>.
3132 </para></listitem>
3133 <listitem><para>
3134 <filename>virtual/egl</filename>:
3135 Provides <filename>egl.pc</filename> and possibly
3136 <filename>wayland-egl.pc</filename>.
3137 </para></listitem>
3138 <listitem><para>
3139 <filename>virtual/libgl</filename>:
3140 Provides <filename>gl.pc</filename> (i.e. libGL).
3141 </para></listitem>
3142 <listitem><para>
3143 <filename>virtual/libgles1</filename>:
3144 Provides <filename>glesv1_cm.pc</filename>
3145 (i.e. libGLESv1_CM).
3146 </para></listitem>
3147 <listitem><para>
3148 <filename>virtual/libgles2</filename>:
3149 Provides <filename>glesv2.pc</filename>
3150 (i.e. libGLESv2).
3151 </para></listitem>
3152 </itemizedlist>
3153 </para>
3154 </section>
3155
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003156 <section id='properly-versioning-pre-release-recipes'>
3157 <title>Properly Versioning Pre-Release Recipes</title>
3158
3159 <para>
3160 Sometimes the name of a recipe can lead to versioning
3161 problems when the recipe is upgraded to a final release.
3162 For example, consider the
3163 <filename>irssi_0.8.16-rc1.bb</filename> recipe file in
3164 the list of example recipes in the
3165 "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>"
3166 section.
3167 This recipe is at a release candidate stage (i.e.
3168 "rc1").
3169 When the recipe is released, the recipe filename becomes
3170 <filename>irssi_0.8.16.bb</filename>.
3171 The version change from <filename>0.8.16-rc1</filename>
3172 to <filename>0.8.16</filename> is seen as a decrease by the
3173 build system and package managers, so the resulting packages
3174 will not correctly trigger an upgrade.
3175 </para>
3176
3177 <para>
3178 In order to ensure the versions compare properly, the
3179 recommended convention is to set
3180 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
3181 within the recipe to
3182 "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>".
3183 You can use an additional variable so that you can use the
3184 current version elsewhere.
3185 Here is an example:
3186 <literallayout class='monospaced'>
3187 REALPV = "0.8.16-rc1"
3188 PV = "0.8.15+${REALPV}"
3189 </literallayout>
3190 </para>
3191 </section>
3192
3193 <section id='new-recipe-post-installation-scripts'>
3194 <title>Post-Installation Scripts</title>
3195
3196 <para>
3197 Post-installation scripts run immediately after installing
3198 a package on the target or during image creation when a
3199 package is included in an image.
3200 To add a post-installation script to a package, add a
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003201 <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003202 the recipe file (<filename>.bb</filename>) and replace
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003203 <replaceable>PACKAGENAME</replaceable> with the name of the package
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003204 you want to attach to the <filename>postinst</filename>
3205 script.
3206 To apply the post-installation script to the main package
3207 for the recipe, which is usually what is required, specify
3208 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003209 in place of <replaceable>PACKAGENAME</replaceable>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003210 </para>
3211
3212 <para>
3213 A post-installation function has the following structure:
3214 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003215 pkg_postinst_<replaceable>PACKAGENAME</replaceable>() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003216 # Commands to carry out
3217 }
3218 </literallayout>
3219 </para>
3220
3221 <para>
3222 The script defined in the post-installation function is
3223 called when the root filesystem is created.
3224 If the script succeeds, the package is marked as installed.
3225 If the script fails, the package is marked as unpacked and
3226 the script is executed when the image boots again.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05003227 <note>
3228 Any RPM post-installation script that runs on the target
3229 should return a 0 exit code.
3230 RPM does not allow non-zero exit codes for these scripts,
3231 and the RPM package manager will cause the package to fail
3232 installation on the target.
3233 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003234 </para>
3235
3236 <para>
3237 Sometimes it is necessary for the execution of a
3238 post-installation script to be delayed until the first boot.
3239 For example, the script might need to be executed on the
3240 device itself.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003241 To delay script execution until boot time, you must explicitly
3242 mark post installs to defer to the target.
3243 You can use <filename>pkg_postinst_ontarget()</filename> or
3244 call
3245 <filename>postinst-intercepts defer_to_first_boot</filename>
3246 from <filename>pkg_postinst()</filename>.
3247 Any failure of a <filename>pkg_postinst()</filename> script
3248 (including exit 1) triggers an error during the
3249 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
3250 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003251 </para>
3252
3253 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003254 If you have recipes that use
3255 <filename>pkg_postinst</filename> function
3256 and they require the use of non-standard native
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003257 tools that have dependencies during rootfs construction, you
3258 need to use the
3259 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink>
3260 variable in your recipe to list these tools.
3261 If you do not use this variable, the tools might be missing and
3262 execution of the post-installation script is deferred until
3263 first boot.
3264 Deferring the script to first boot is undesirable and for
3265 read-only rootfs impossible.
3266 </para>
3267
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003268 <note>
3269 Equivalent support for pre-install, pre-uninstall, and
3270 post-uninstall scripts exist by way of
3271 <filename>pkg_preinst</filename>,
3272 <filename>pkg_prerm</filename>, and
3273 <filename>pkg_postrm</filename>, respectively.
3274 These scrips work in exactly the same way as does
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003275 <filename>pkg_postinst</filename> with the exception
3276 that they run at different times.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003277 Also, because of when they run, they are not applicable to
3278 being run at image creation time like
3279 <filename>pkg_postinst</filename>.
3280 </note>
3281 </section>
3282
3283 <section id='new-recipe-testing'>
3284 <title>Testing</title>
3285
3286 <para>
3287 The final step for completing your recipe is to be sure that
3288 the software you built runs correctly.
3289 To accomplish runtime testing, add the build's output
3290 packages to your image and test them on the target.
3291 </para>
3292
3293 <para>
3294 For information on how to customize your image by adding
3295 specific packages, see the
3296 "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>"
3297 section.
3298 </para>
3299 </section>
3300
3301 <section id='new-recipe-testing-examples'>
3302 <title>Examples</title>
3303
3304 <para>
3305 To help summarize how to write a recipe, this section provides
3306 some examples given various scenarios:
3307 <itemizedlist>
3308 <listitem><para>Recipes that use local files</para></listitem>
3309 <listitem><para>Using an Autotooled package</para></listitem>
3310 <listitem><para>Using a Makefile-based package</para></listitem>
3311 <listitem><para>Splitting an application into multiple packages</para></listitem>
3312 <listitem><para>Adding binaries to an image</para></listitem>
3313 </itemizedlist>
3314 </para>
3315
3316 <section id='new-recipe-single-c-file-package-hello-world'>
3317 <title>Single .c File Package (Hello World!)</title>
3318
3319 <para>
3320 Building an application from a single file that is stored
3321 locally (e.g. under <filename>files</filename>) requires
3322 a recipe that has the file listed in the
3323 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
3324 variable.
3325 Additionally, you need to manually write the
3326 <filename>do_compile</filename> and
3327 <filename>do_install</filename> tasks.
3328 The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
3329 variable defines the directory containing the source code,
3330 which is set to
3331 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
3332 in this case - the directory BitBake uses for the build.
3333 <literallayout class='monospaced'>
3334 SUMMARY = "Simple helloworld application"
3335 SECTION = "examples"
3336 LICENSE = "MIT"
3337 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
3338
3339 SRC_URI = "file://helloworld.c"
3340
3341 S = "${WORKDIR}"
3342
3343 do_compile() {
3344 ${CC} helloworld.c -o helloworld
3345 }
3346
3347 do_install() {
3348 install -d ${D}${bindir}
3349 install -m 0755 helloworld ${D}${bindir}
3350 }
3351 </literallayout>
3352 </para>
3353
3354 <para>
3355 By default, the <filename>helloworld</filename>,
3356 <filename>helloworld-dbg</filename>, and
3357 <filename>helloworld-dev</filename> packages are built.
3358 For information on how to customize the packaging process,
3359 see the
3360 "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>"
3361 section.
3362 </para>
3363 </section>
3364
3365 <section id='new-recipe-autotooled-package'>
3366 <title>Autotooled Package</title>
3367 <para>
3368 Applications that use Autotools such as <filename>autoconf</filename> and
3369 <filename>automake</filename> require a recipe that has a source archive listed in
3370 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and
3371 also inherit the
3372 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink>
3373 class, which contains the definitions of all the steps
3374 needed to build an Autotool-based application.
3375 The result of the build is automatically packaged.
3376 And, if the application uses NLS for localization, packages with local information are
3377 generated (one package per language).
3378 Following is one example: (<filename>hello_2.3.bb</filename>)
3379 <literallayout class='monospaced'>
3380 SUMMARY = "GNU Helloworld application"
3381 SECTION = "examples"
3382 LICENSE = "GPLv2+"
3383 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
3384
3385 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
3386
3387 inherit autotools gettext
3388 </literallayout>
3389 </para>
3390
3391 <para>
3392 The variable
3393 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename>
3394 is used to track source license changes as described in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003395 "<link linkend='usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</link>"
3396 section in the Yocto Project Overview and Concepts Manual.
3397 You can quickly create Autotool-based recipes in a manner
3398 similar to the previous example.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003399 </para>
3400 </section>
3401
3402 <section id='new-recipe-makefile-based-package'>
3403 <title>Makefile-Based Package</title>
3404
3405 <para>
3406 Applications that use GNU <filename>make</filename> also require a recipe that has
3407 the source archive listed in
3408 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
3409 You do not need to add a <filename>do_compile</filename> step since by default BitBake
3410 starts the <filename>make</filename> command to compile the application.
3411 If you need additional <filename>make</filename> options, you should store them in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003412 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
3413 or
3414 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
3415 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003416 BitBake passes these options into the GNU <filename>make</filename> invocation.
3417 Note that a <filename>do_install</filename> task is still required.
3418 Otherwise, BitBake runs an empty <filename>do_install</filename> task by default.
3419 </para>
3420
3421 <para>
3422 Some applications might require extra parameters to be passed to the compiler.
3423 For example, the application might need an additional header path.
3424 You can accomplish this by adding to the
3425 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable.
3426 The following example shows this:
3427 <literallayout class='monospaced'>
3428 CFLAGS_prepend = "-I ${S}/include "
3429 </literallayout>
3430 </para>
3431
3432 <para>
3433 In the following example, <filename>mtd-utils</filename> is a makefile-based package:
3434 <literallayout class='monospaced'>
3435 SUMMARY = "Tools for managing memory technology devices"
3436 SECTION = "base"
3437 DEPENDS = "zlib lzo e2fsprogs util-linux"
3438 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
3439 LICENSE = "GPLv2+"
3440 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
3441 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
3442
3443 # Use the latest version at 26 Oct, 2013
3444 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
3445 SRC_URI = "git://git.infradead.org/mtd-utils.git \
3446 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
3447 "
3448
3449 PV = "1.5.1+git${SRCPV}"
3450
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003451 S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003452
3453 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
3454
3455 do_install () {
3456 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
3457 }
3458
3459 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
3460
3461 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
3462 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
3463 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
3464
3465 PARALLEL_MAKE = ""
3466
3467 BBCLASSEXTEND = "native"
3468 </literallayout>
3469 </para>
3470 </section>
3471
3472 <section id='splitting-an-application-into-multiple-packages'>
3473 <title>Splitting an Application into Multiple Packages</title>
3474
3475 <para>
3476 You can use the variables
3477 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and
3478 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename>
3479 to split an application into multiple packages.
3480 </para>
3481
3482 <para>
3483 Following is an example that uses the <filename>libxpm</filename> recipe.
3484 By default, this recipe generates a single package that contains the library along
3485 with a few binaries.
3486 You can modify the recipe to split the binaries into separate packages:
3487 <literallayout class='monospaced'>
3488 require xorg-lib-common.inc
3489
3490 SUMMARY = "Xpm: X Pixmap extension library"
3491 LICENSE = "BSD"
3492 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
3493 DEPENDS += "libxext libsm libxt"
3494 PE = "1"
3495
3496 XORG_PN = "libXpm"
3497
3498 PACKAGES =+ "sxpm cxpm"
3499 FILES_cxpm = "${bindir}/cxpm"
3500 FILES_sxpm = "${bindir}/sxpm"
3501 </literallayout>
3502 </para>
3503
3504 <para>
3505 In the previous example, we want to ship the <filename>sxpm</filename>
3506 and <filename>cxpm</filename> binaries in separate packages.
3507 Since <filename>bindir</filename> would be packaged into the main
3508 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename>
3509 package by default, we prepend the <filename>PACKAGES</filename>
3510 variable so additional package names are added to the start of list.
3511 This results in the extra <filename>FILES_*</filename>
3512 variables then containing information that define which files and
3513 directories go into which packages.
3514 Files included by earlier packages are skipped by latter packages.
3515 Thus, the main <filename>PN</filename> package
3516 does not include the above listed files.
3517 </para>
3518 </section>
3519
3520 <section id='packaging-externally-produced-binaries'>
3521 <title>Packaging Externally Produced Binaries</title>
3522
3523 <para>
3524 Sometimes, you need to add pre-compiled binaries to an
3525 image.
3526 For example, suppose that binaries for proprietary code
3527 exist, which are created by a particular division of a
3528 company.
3529 Your part of the company needs to use those binaries as
3530 part of an image that you are building using the
3531 OpenEmbedded build system.
3532 Since you only have the binaries and not the source code,
3533 you cannot use a typical recipe that expects to fetch the
3534 source specified in
3535 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
3536 and then compile it.
3537 </para>
3538
3539 <para>
3540 One method is to package the binaries and then install them
3541 as part of the image.
3542 Generally, it is not a good idea to package binaries
3543 since, among other things, it can hinder the ability to
3544 reproduce builds and could lead to compatibility problems
3545 with ABI in the future.
3546 However, sometimes you have no choice.
3547 </para>
3548
3549 <para>
3550 The easiest solution is to create a recipe that uses
3551 the
3552 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink>
3553 class and to be sure that you are using default locations
3554 for build artifacts.
3555 In most cases, the <filename>bin_package</filename> class
3556 handles "skipping" the configure and compile steps as well
3557 as sets things up to grab packages from the appropriate
3558 area.
3559 In particular, this class sets <filename>noexec</filename>
3560 on both the
3561 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3562 and
3563 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3564 tasks, sets
3565 <filename>FILES_${PN}</filename> to "/" so that it picks
3566 up all files, and sets up a
3567 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3568 task, which effectively copies all files from
3569 <filename>${S}</filename> to <filename>${D}</filename>.
3570 The <filename>bin_package</filename> class works well when
3571 the files extracted into <filename>${S}</filename> are
3572 already laid out in the way they should be laid out
3573 on the target.
3574 For more information on these variables, see the
3575 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>,
3576 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>,
3577 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>,
3578 and
3579 <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
3580 variables in the Yocto Project Reference Manual's variable
3581 glossary.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003582 <note><title>Notes</title>
3583 <itemizedlist>
3584 <listitem><para>
3585 Using
3586 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
3587 is a good idea even for components distributed
3588 in binary form, and is often necessary for
3589 shared libraries.
3590 For a shared library, listing the library
3591 dependencies in
3592 <filename>DEPENDS</filename> makes sure that
3593 the libraries are available in the staging
3594 sysroot when other recipes link against the
3595 library, which might be necessary for
3596 successful linking.
3597 </para></listitem>
3598 <listitem><para>
3599 Using <filename>DEPENDS</filename> also
3600 allows runtime dependencies between packages
3601 to be added automatically.
3602 See the
Brad Bishop316dfdd2018-06-25 12:45:53 -04003603 "<ulink url='&YOCTO_DOCS_OM_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>"
3604 section in the Yocto Project Overview and
3605 Concepts Manual for more information.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003606 </para></listitem>
3607 </itemizedlist>
3608 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003609 </para>
3610
3611 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003612 If you cannot use the <filename>bin_package</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003613 class, you need to be sure you are doing the following:
3614 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003615 <listitem><para>
3616 Create a recipe where the
3617 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
3618 and
3619 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
3620 tasks do nothing:
3621 It is usually sufficient to just not define these
3622 tasks in the recipe, because the default
3623 implementations do nothing unless a Makefile is
3624 found in
3625 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>.
3626 </para>
3627
3628 <para>If
3629 <filename>${S}</filename> might contain a Makefile,
3630 or if you inherit some class that replaces
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003631 <filename>do_configure</filename> and
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003632 <filename>do_compile</filename> with custom
3633 versions, then you can use the
3634 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename>
3635 flag to turn the tasks into no-ops, as follows:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003636 <literallayout class='monospaced'>
3637 do_configure[noexec] = "1"
3638 do_compile[noexec] = "1"
3639 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003640 Unlike
3641 <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>,
3642 using the flag preserves the dependency chain from
3643 the
3644 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>, <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>,
3645 and
3646 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
3647 tasks to the
3648 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
3649 task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003650 </para></listitem>
3651 <listitem><para>Make sure your
3652 <filename>do_install</filename> task installs the
3653 binaries appropriately.
3654 </para></listitem>
3655 <listitem><para>Ensure that you set up
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003656 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3657 (usually
3658 <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>)
3659 to point to the files you have installed, which of
3660 course depends on where you have installed them
3661 and whether those files are in different locations
3662 than the defaults.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003663 </para></listitem>
3664 </itemizedlist>
3665 </para>
3666 </section>
3667 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003668
3669 <section id="following-recipe-style-guidelines">
3670 <title>Following Recipe Style Guidelines</title>
3671
3672 <para>
3673 When writing recipes, it is good to conform to existing
3674 style guidelines.
3675 The
3676 <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink>
3677 wiki page provides rough guidelines for preferred recipe style.
3678 </para>
3679
3680 <para>
3681 It is common for existing recipes to deviate a bit from this
3682 style.
3683 However, aiming for at least a consistent style is a good idea.
3684 Some practices, such as omitting spaces around
3685 <filename>=</filename> operators in assignments or ordering
3686 recipe components in an erratic way, are widely seen as poor
3687 style.
3688 </para>
3689 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04003690
3691 <section id='recipe-syntax'>
3692 <title>Recipe Syntax</title>
3693
3694 <para>
3695 Understanding recipe file syntax is important for writing
3696 recipes.
3697 The following list overviews the basic items that make up a
3698 BitBake recipe file.
3699 For more complete BitBake syntax descriptions, see the
3700 "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>"
3701 chapter of the BitBake User Manual.
3702 <itemizedlist>
3703 <listitem><para>
3704 <emphasis>Variable Assignments and Manipulations:</emphasis>
3705 Variable assignments allow a value to be assigned to a
3706 variable.
3707 The assignment can be static text or might include
3708 the contents of other variables.
3709 In addition to the assignment, appending and prepending
3710 operations are also supported.</para>
3711
3712 <para>The following example shows some of the ways
3713 you can use variables in recipes:
3714 <literallayout class='monospaced'>
3715 S = "${WORKDIR}/postfix-${PV}"
3716 CFLAGS += "-DNO_ASM"
3717 SRC_URI_append = " file://fixup.patch"
3718 </literallayout>
3719 </para></listitem>
3720 <listitem><para>
3721 <emphasis>Functions:</emphasis>
3722 Functions provide a series of actions to be performed.
3723 You usually use functions to override the default
3724 implementation of a task function or to complement
3725 a default function (i.e. append or prepend to an
3726 existing function).
3727 Standard functions use <filename>sh</filename> shell
3728 syntax, although access to OpenEmbedded variables and
3729 internal methods are also available.</para>
3730
3731 <para>The following is an example function from the
3732 <filename>sed</filename> recipe:
3733 <literallayout class='monospaced'>
3734 do_install () {
3735 autotools_do_install
3736 install -d ${D}${base_bindir}
3737 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
3738 rmdir ${D}${bindir}/
3739 }
3740 </literallayout>
3741 It is also possible to implement new functions that
3742 are called between existing tasks as long as the
3743 new functions are not replacing or complementing the
3744 default functions.
3745 You can implement functions in Python
3746 instead of shell.
3747 Both of these options are not seen in the majority of
3748 recipes.
3749 </para></listitem>
3750 <listitem><para><emphasis>Keywords:</emphasis>
3751 BitBake recipes use only a few keywords.
3752 You use keywords to include common
3753 functions (<filename>inherit</filename>), load parts
3754 of a recipe from other files
3755 (<filename>include</filename> and
3756 <filename>require</filename>) and export variables
3757 to the environment (<filename>export</filename>).
3758 </para>
3759
3760 <para>The following example shows the use of some of
3761 these keywords:
3762 <literallayout class='monospaced'>
3763 export POSTCONF = "${STAGING_BINDIR}/postconf"
3764 inherit autoconf
3765 require otherfile.inc
3766 </literallayout>
3767 </para></listitem>
3768 <listitem><para>
3769 <emphasis>Comments (#):</emphasis>
3770 Any lines that begin with the hash character
3771 (<filename>#</filename>) are treated as comment lines
3772 and are ignored:
3773 <literallayout class='monospaced'>
3774 # This is a comment
3775 </literallayout>
3776 </para></listitem>
3777 </itemizedlist>
3778 </para>
3779
3780 <para>
3781 This next list summarizes the most important and most commonly
3782 used parts of the recipe syntax.
3783 For more information on these parts of the syntax, you can
3784 reference the
3785 <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>
3786 chapter in the BitBake User Manual.
3787 <itemizedlist>
3788 <listitem><para>
3789 <emphasis>Line Continuation (\):</emphasis>
3790 Use the backward slash (<filename>\</filename>)
3791 character to split a statement over multiple lines.
3792 Place the slash character at the end of the line that
3793 is to be continued on the next line:
3794 <literallayout class='monospaced'>
3795 VAR = "A really long \
3796 line"
3797 </literallayout>
3798 <note>
3799 You cannot have any characters including spaces
3800 or tabs after the slash character.
3801 </note>
3802 </para></listitem>
3803 <listitem><para>
3804 <emphasis>Using Variables (${<replaceable>VARNAME</replaceable>}):</emphasis>
3805 Use the <filename>${<replaceable>VARNAME</replaceable>}</filename>
3806 syntax to access the contents of a variable:
3807 <literallayout class='monospaced'>
3808 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
3809 </literallayout>
3810 <note>
3811 It is important to understand that the value of a
3812 variable expressed in this form does not get
3813 substituted automatically.
3814 The expansion of these expressions happens
3815 on-demand later (e.g. usually when a function that
3816 makes reference to the variable executes).
3817 This behavior ensures that the values are most
3818 appropriate for the context in which they are
3819 finally used.
3820 On the rare occasion that you do need the variable
3821 expression to be expanded immediately, you can use
3822 the <filename>:=</filename> operator instead of
3823 <filename>=</filename> when you make the
3824 assignment, but this is not generally needed.
3825 </note>
3826 </para></listitem>
3827 <listitem><para>
3828 <emphasis>Quote All Assignments ("<replaceable>value</replaceable>"):</emphasis>
3829 Use double quotes around values in all variable
3830 assignments (e.g.
3831 <filename>"<replaceable>value</replaceable>"</filename>).
3832 Following is an example:
3833 <literallayout class='monospaced'>
3834 VAR1 = "${OTHERVAR}"
3835 VAR2 = "The version is ${PV}"
3836 </literallayout>
3837 </para></listitem>
3838 <listitem><para>
3839 <emphasis>Conditional Assignment (?=):</emphasis>
3840 Conditional assignment is used to assign a
3841 value to a variable, but only when the variable is
3842 currently unset.
3843 Use the question mark followed by the equal sign
3844 (<filename>?=</filename>) to make a "soft" assignment
3845 used for conditional assignment.
3846 Typically, "soft" assignments are used in the
3847 <filename>local.conf</filename> file for variables
3848 that are allowed to come through from the external
3849 environment.
3850 </para>
3851
3852 <para>Here is an example where
3853 <filename>VAR1</filename> is set to "New value" if
3854 it is currently empty.
3855 However, if <filename>VAR1</filename> has already been
3856 set, it remains unchanged:
3857 <literallayout class='monospaced'>
3858 VAR1 ?= "New value"
3859 </literallayout>
3860 In this next example, <filename>VAR1</filename>
3861 is left with the value "Original value":
3862 <literallayout class='monospaced'>
3863 VAR1 = "Original value"
3864 VAR1 ?= "New value"
3865 </literallayout>
3866 </para></listitem>
3867 <listitem><para>
3868 <emphasis>Appending (+=):</emphasis>
3869 Use the plus character followed by the equals sign
3870 (<filename>+=</filename>) to append values to existing
3871 variables.
3872 <note>
3873 This operator adds a space between the existing
3874 content of the variable and the new content.
3875 </note></para>
3876
3877 <para>Here is an example:
3878 <literallayout class='monospaced'>
3879 SRC_URI += "file://fix-makefile.patch"
3880 </literallayout>
3881 </para></listitem>
3882 <listitem><para>
3883 <emphasis>Prepending (=+):</emphasis>
3884 Use the equals sign followed by the plus character
3885 (<filename>=+</filename>) to prepend values to existing
3886 variables.
3887 <note>
3888 This operator adds a space between the new content
3889 and the existing content of the variable.
3890 </note></para>
3891
3892 <para>Here is an example:
3893 <literallayout class='monospaced'>
3894 VAR =+ "Starts"
3895 </literallayout>
3896 </para></listitem>
3897 <listitem><para>
3898 <emphasis>Appending (_append):</emphasis>
3899 Use the <filename>_append</filename> operator to
3900 append values to existing variables.
3901 This operator does not add any additional space.
3902 Also, the operator is applied after all the
3903 <filename>+=</filename>, and
3904 <filename>=+</filename> operators have been applied and
3905 after all <filename>=</filename> assignments have
3906 occurred.
3907 </para>
3908
3909 <para>The following example shows the space being
3910 explicitly added to the start to ensure the appended
3911 value is not merged with the existing value:
3912 <literallayout class='monospaced'>
3913 SRC_URI_append = " file://fix-makefile.patch"
3914 </literallayout>
3915 You can also use the <filename>_append</filename>
3916 operator with overrides, which results in the actions
3917 only being performed for the specified target or
3918 machine:
3919 <literallayout class='monospaced'>
3920 SRC_URI_append_sh4 = " file://fix-makefile.patch"
3921 </literallayout>
3922 </para></listitem>
3923 <listitem><para>
3924 <emphasis>Prepending (_prepend):</emphasis>
3925 Use the <filename>_prepend</filename> operator to
3926 prepend values to existing variables.
3927 This operator does not add any additional space.
3928 Also, the operator is applied after all the
3929 <filename>+=</filename>, and
3930 <filename>=+</filename> operators have been applied and
3931 after all <filename>=</filename> assignments have
3932 occurred.
3933 </para>
3934
3935 <para>The following example shows the space being
3936 explicitly added to the end to ensure the prepended
3937 value is not merged with the existing value:
3938 <literallayout class='monospaced'>
3939 CFLAGS_prepend = "-I${S}/myincludes "
3940 </literallayout>
3941 You can also use the <filename>_prepend</filename>
3942 operator with overrides, which results in the actions
3943 only being performed for the specified target or
3944 machine:
3945 <literallayout class='monospaced'>
3946 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
3947 </literallayout>
3948 </para></listitem>
3949 <listitem><para>
3950 <emphasis>Overrides:</emphasis>
3951 You can use overrides to set a value conditionally,
3952 typically based on how the recipe is being built.
3953 For example, to set the
3954 <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink>
3955 variable's value to "standard/base" for any target
3956 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
3957 except for qemuarm where it should be set to
3958 "standard/arm-versatile-926ejs", you would do the
3959 following:
3960 <literallayout class='monospaced'>
3961 KBRANCH = "standard/base"
3962 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
3963 </literallayout>
3964 Overrides are also used to separate alternate values
3965 of a variable in other situations.
3966 For example, when setting variables such as
3967 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
3968 and
3969 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
3970 that are specific to individual packages produced by
3971 a recipe, you should always use an override that
3972 specifies the name of the package.
3973 </para></listitem>
3974 <listitem><para>
3975 <emphasis>Indentation:</emphasis>
3976 Use spaces for indentation rather than than tabs.
3977 For shell functions, both currently work.
3978 However, it is a policy decision of the Yocto Project
3979 to use tabs in shell functions.
3980 Realize that some layers have a policy to use spaces
3981 for all indentation.
3982 </para></listitem>
3983 <listitem><para>
3984 <emphasis>Using Python for Complex Operations:</emphasis>
3985 For more advanced processing, it is possible to use
3986 Python code during variable assignments (e.g.
3987 search and replacement on a variable).</para>
3988
3989 <para>You indicate Python code using the
3990 <filename>${@<replaceable>python_code</replaceable>}</filename>
3991 syntax for the variable assignment:
3992 <literallayout class='monospaced'>
3993 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
3994 </literallayout>
3995 </para></listitem>
3996 <listitem><para>
3997 <emphasis>Shell Function Syntax:</emphasis>
3998 Write shell functions as if you were writing a shell
3999 script when you describe a list of actions to take.
4000 You should ensure that your script works with a generic
4001 <filename>sh</filename> and that it does not require
4002 any <filename>bash</filename> or other shell-specific
4003 functionality.
4004 The same considerations apply to various system
4005 utilities (e.g. <filename>sed</filename>,
4006 <filename>grep</filename>, <filename>awk</filename>,
4007 and so forth) that you might wish to use.
4008 If in doubt, you should check with multiple
4009 implementations - including those from BusyBox.
4010 </para></listitem>
4011 </itemizedlist>
4012 </para>
4013 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004014 </section>
4015
4016 <section id="platdev-newmachine">
4017 <title>Adding a New Machine</title>
4018
4019 <para>
4020 Adding a new machine to the Yocto Project is a straightforward
4021 process.
4022 This section describes how to add machines that are similar
4023 to those that the Yocto Project already supports.
4024 <note>
4025 Although well within the capabilities of the Yocto Project,
4026 adding a totally new architecture might require
4027 changes to <filename>gcc/glibc</filename> and to the site
4028 information, which is beyond the scope of this manual.
4029 </note>
4030 </para>
4031
4032 <para>
4033 For a complete example that shows how to add a new machine,
4034 see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004035 "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'>Creating a New BSP Layer Using the <filename>bitbake-layers</filename> Script</ulink>"
4036 section in the Yocto Project Board Support Package (BSP)
4037 Developer's Guide.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004038 </para>
4039
4040 <section id="platdev-newmachine-conffile">
4041 <title>Adding the Machine Configuration File</title>
4042
4043 <para>
4044 To add a new machine, you need to add a new machine
4045 configuration file to the layer's
4046 <filename>conf/machine</filename> directory.
4047 This configuration file provides details about the device
4048 you are adding.
4049 </para>
4050
4051 <para>
4052 The OpenEmbedded build system uses the root name of the
4053 machine configuration file to reference the new machine.
4054 For example, given a machine configuration file named
4055 <filename>crownbay.conf</filename>, the build system
4056 recognizes the machine as "crownbay".
4057 </para>
4058
4059 <para>
4060 The most important variables you must set in your machine
4061 configuration file or include from a lower-level configuration
4062 file are as follows:
4063 <itemizedlist>
4064 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename>
4065 (e.g. "arm")</para></listitem>
4066 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename>
4067 </para></listitem>
4068 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename>
4069 (e.g. "apm screen wifi")</para></listitem>
4070 </itemizedlist>
4071 </para>
4072
4073 <para>
4074 You might also need these variables:
4075 <itemizedlist>
4076 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename>
4077 (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem>
4078 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename>
4079 (e.g. "zImage")</para></listitem>
4080 <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename>
4081 (e.g. "tar.gz jffs2")</para></listitem>
4082 </itemizedlist>
4083 </para>
4084
4085 <para>
4086 You can find full details on these variables in the reference
4087 section.
4088 You can leverage existing machine <filename>.conf</filename>
4089 files from <filename>meta-yocto-bsp/conf/machine/</filename>.
4090 </para>
4091 </section>
4092
4093 <section id="platdev-newmachine-kernel">
4094 <title>Adding a Kernel for the Machine</title>
4095
4096 <para>
4097 The OpenEmbedded build system needs to be able to build a kernel
4098 for the machine.
4099 You need to either create a new kernel recipe for this machine,
4100 or extend an existing kernel recipe.
4101 You can find several kernel recipe examples in the
4102 Source Directory at
4103 <filename>meta/recipes-kernel/linux</filename>
4104 that you can use as references.
4105 </para>
4106
4107 <para>
4108 If you are creating a new kernel recipe, normal recipe-writing
4109 rules apply for setting up a
4110 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>.
4111 Thus, you need to specify any necessary patches and set
4112 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename>
4113 to point at the source code.
4114 You need to create a <filename>do_configure</filename> task that
4115 configures the unpacked kernel with a
4116 <filename>defconfig</filename> file.
4117 You can do this by using a <filename>make defconfig</filename>
4118 command or, more commonly, by copying in a suitable
4119 <filename>defconfig</filename> file and then running
4120 <filename>make oldconfig</filename>.
4121 By making use of <filename>inherit kernel</filename> and
4122 potentially some of the <filename>linux-*.inc</filename> files,
4123 most other functionality is centralized and the defaults of the
4124 class normally work well.
4125 </para>
4126
4127 <para>
4128 If you are extending an existing kernel recipe, it is usually
4129 a matter of adding a suitable <filename>defconfig</filename>
4130 file.
4131 The file needs to be added into a location similar to
4132 <filename>defconfig</filename> files used for other machines
4133 in a given kernel recipe.
4134 A possible way to do this is by listing the file in the
4135 <filename>SRC_URI</filename> and adding the machine to the
4136 expression in
4137 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>:
4138 <literallayout class='monospaced'>
4139 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
4140 </literallayout>
4141 For more information on <filename>defconfig</filename> files,
4142 see the
4143 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>"
4144 section in the Yocto Project Linux Kernel Development Manual.
4145 </para>
4146 </section>
4147
4148 <section id="platdev-newmachine-formfactor">
4149 <title>Adding a Formfactor Configuration File</title>
4150
4151 <para>
4152 A formfactor configuration file provides information about the
4153 target hardware for which the image is being built and information that
4154 the build system cannot obtain from other sources such as the kernel.
4155 Some examples of information contained in a formfactor configuration file include
4156 framebuffer orientation, whether or not the system has a keyboard,
4157 the positioning of the keyboard in relation to the screen, and
4158 the screen resolution.
4159 </para>
4160
4161 <para>
4162 The build system uses reasonable defaults in most cases.
4163 However, if customization is
4164 necessary, you need to create a <filename>machconfig</filename> file
4165 in the <filename>meta/recipes-bsp/formfactor/files</filename>
4166 directory.
4167 This directory contains directories for specific machines such as
4168 <filename>qemuarm</filename> and <filename>qemux86</filename>.
4169 For information about the settings available and the defaults, see the
4170 <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the
4171 same area.
4172 </para>
4173
4174 <para>
4175 Following is an example for "qemuarm" machine:
4176 <literallayout class='monospaced'>
4177 HAVE_TOUCHSCREEN=1
4178 HAVE_KEYBOARD=1
4179
4180 DISPLAY_CAN_ROTATE=0
4181 DISPLAY_ORIENTATION=0
4182 #DISPLAY_WIDTH_PIXELS=640
4183 #DISPLAY_HEIGHT_PIXELS=480
4184 #DISPLAY_BPP=16
4185 DISPLAY_DPI=150
4186 DISPLAY_SUBPIXEL_ORDER=vrgb
4187 </literallayout>
4188 </para>
4189 </section>
4190 </section>
4191
Brad Bishop316dfdd2018-06-25 12:45:53 -04004192 <section id='gs-upgrading-recipes'>
4193 <title>Upgrading Recipes</title>
4194
4195 <para>
4196 Over time, upstream developers publish new versions for software
4197 built by layer recipes.
4198 It is recommended to keep recipes up-to-date with upstream
4199 version releases.
Brad Bishop15ae2502019-06-18 21:44:24 -04004200 </para>
4201
4202 <para>
4203 While several methods exist that allow you upgrade a recipe,
4204 you might consider checking on the upgrade status of a recipe
4205 first.
4206 You can do so using the
4207 <filename>devtool check-upgrade-status</filename> command.
4208 See the
4209 "<ulink url='&YOCTO_DOCS_REF_URL;#devtool-checking-on-the-upgrade-status-of-a-recipe'>Checking on the Upgrade Status of a Recipe</ulink>"
4210 section in the Yocto Project Reference Manual for more information.
4211 </para>
4212
4213 <para>
4214 The remainder of this section describes three ways you can
4215 upgrade a recipe.
Brad Bishop316dfdd2018-06-25 12:45:53 -04004216 You can use the Automated Upgrade Helper (AUH) to set up
4217 automatic version upgrades.
4218 Alternatively, you can use <filename>devtool upgrade</filename>
4219 to set up semi-automatic version upgrades.
Brad Bishop15ae2502019-06-18 21:44:24 -04004220 Finally, you can manually upgrade a recipe by editing the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004221 recipe itself.
4222 </para>
4223
4224 <section id='gs-using-the-auto-upgrade-helper'>
4225 <title>Using the Auto Upgrade Helper (AUH)</title>
4226
4227 <para>
4228 The AUH utility works in conjunction with the
4229 OpenEmbedded build system in order to automatically generate
4230 upgrades for recipes based on new versions being
4231 published upstream.
4232 Use AUH when you want to create a service that performs the
4233 upgrades automatically and optionally sends you an email with
4234 the results.
4235 </para>
4236
4237 <para>
4238 AUH allows you to update several recipes with a single use.
4239 You can also optionally perform build and integration tests
4240 using images with the results saved to your hard drive and
4241 emails of results optionally sent to recipe maintainers.
4242 Finally, AUH creates Git commits with appropriate commit
4243 messages in the layer's tree for the changes made to recipes.
4244 <note>
4245 Conditions do exist when you should not use AUH to upgrade
4246 recipes and you should instead use either
4247 <filename>devtool upgrade</filename> or upgrade your
4248 recipes manually:
4249 <itemizedlist>
4250 <listitem><para>
4251 When AUH cannot complete the upgrade sequence.
4252 This situation usually results because custom
4253 patches carried by the recipe cannot be
4254 automatically rebased to the new version.
4255 In this case, <filename>devtool upgrade</filename>
4256 allows you to manually resolve conflicts.
4257 </para></listitem>
4258 <listitem><para>
4259 When for any reason you want fuller control over
4260 the upgrade process.
4261 For example, when you want special arrangements
4262 for testing.
4263 </para></listitem>
4264 </itemizedlist>
4265 </note>
4266 </para>
4267
4268 <para>
4269 The following steps describe how to set up the AUH utility:
4270 <orderedlist>
4271 <listitem><para>
4272 <emphasis>Be Sure the Development Host is Set Up:</emphasis>
4273 You need to be sure that your development host is
4274 set up to use the Yocto Project.
4275 For information on how to set up your host, see the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004276 "<link linkend='dev-preparing-the-build-host'>Preparing the Build Host</link>"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004277 section.
4278 </para></listitem>
4279 <listitem><para>
4280 <emphasis>Make Sure Git is Configured:</emphasis>
4281 The AUH utility requires Git to be configured because
4282 AUH uses Git to save upgrades.
4283 Thus, you must have Git user and email configured.
4284 The following command shows your configurations:
4285 <literallayout class='monospaced'>
4286 $ git config --list
4287 </literallayout>
4288 If you do not have the user and email configured, you
4289 can use the following commands to do so:
4290 <literallayout class='monospaced'>
4291 $ git config --global user.name <replaceable>some_name</replaceable>
4292 $ git config --global user.email <replaceable>username</replaceable>@<replaceable>domain</replaceable>.com
4293 </literallayout>
4294 </para></listitem>
4295 <listitem><para>
4296 <emphasis>Clone the AUH Repository:</emphasis>
4297 To use AUH, you must clone the repository onto your
4298 development host.
4299 The following command uses Git to create a local
4300 copy of the repository on your system:
4301 <literallayout class='monospaced'>
4302 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
4303 Cloning into 'auto-upgrade-helper'...
4304 remote: Counting objects: 768, done.
4305 remote: Compressing objects: 100% (300/300), done.
4306 remote: Total 768 (delta 499), reused 703 (delta 434)
4307 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
4308 Resolving deltas: 100% (499/499), done.
4309 Checking connectivity... done.
4310 </literallayout>
4311 AUH is not part of the
4312 <ulink url='&YOCTO_DOCS_REF_URL;#oe-core'>OpenEmbedded-Core (OE-Core)</ulink>
4313 or
4314 <ulink url='&YOCTO_DOCS_REF_URL;#poky'>Poky</ulink>
4315 repositories.
4316 </para></listitem>
4317 <listitem><para>
4318 <emphasis>Create a Dedicated Build Directory:</emphasis>
4319 Run the
4320 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>
4321 script to create a fresh build directory that you
4322 use exclusively for running the AUH utility:
4323 <literallayout class='monospaced'>
4324 $ cd ~/poky
4325 $ source oe-init-build-env <replaceable>your_AUH_build_directory</replaceable>
4326 </literallayout>
4327 Re-using an existing build directory and its
4328 configurations is not recommended as existing settings
4329 could cause AUH to fail or behave undesirably.
4330 </para></listitem>
4331 <listitem><para>
4332 <emphasis>Make Configurations in Your Local Configuration File:</emphasis>
4333 Several settings need to exist in the
4334 <filename>local.conf</filename> file in the build
4335 directory you just created for AUH.
4336 Make these following configurations:
4337 <itemizedlist>
4338 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04004339 If you want to enable
4340 <ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-build-output-quality'>Build History</ulink>,
4341 which is optional, you need the following
4342 lines in the
4343 <filename>conf/local.conf</filename> file:
4344 <literallayout class='monospaced'>
4345 INHERIT =+ "buildhistory"
4346 BUILDHISTORY_COMMIT = "1"
4347 </literallayout>
4348 With this configuration and a successful
4349 upgrade, a build history "diff" file appears in
4350 the
4351 <filename>upgrade-helper/work/recipe/buildhistory-diff.txt</filename>
4352 file found in your build directory.
4353 </para></listitem>
4354 <listitem><para>
4355 If you want to enable testing through the
4356 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
4357 class, which is optional, you need to have the
4358 following set in your
4359 <filename>conf/local.conf</filename> file:
4360 <literallayout class='monospaced'>
4361 INHERIT += "testimage"
4362 </literallayout>
4363 <note>
4364 If your distro does not enable by default
4365 ptest, which Poky does, you need the
4366 following in your
4367 <filename>local.conf</filename> file:
4368 <literallayout class='monospaced'>
4369 DISTRO_FEATURES_append = " ptest"
4370 </literallayout>
4371 </note>
4372 </para></listitem>
4373 </itemizedlist>
4374 </para></listitem>
4375 <listitem><para>
4376 <emphasis>Optionally Start a vncserver:</emphasis>
4377 If you are running in a server without an X11 session,
4378 you need to start a vncserver:
4379 <literallayout class='monospaced'>
4380 $ vncserver :1
4381 $ export DISPLAY=:1
4382 </literallayout>
4383 </para></listitem>
4384 <listitem><para>
4385 <emphasis>Create and Edit an AUH Configuration File:</emphasis>
4386 You need to have the
4387 <filename>upgrade-helper/upgrade-helper.conf</filename>
4388 configuration file in your build directory.
4389 You can find a sample configuration file in the
4390 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/'>AUH source repository</ulink>.
4391 </para>
4392
4393 <para>Read through the sample file and make
4394 configurations as needed.
4395 For example, if you enabled build history in your
4396 <filename>local.conf</filename> as described earlier,
4397 you must enable it in
4398 <filename>upgrade-helper.conf</filename>.</para>
4399
4400 <para>Also, if you are using the default
4401 <filename>maintainers.inc</filename> file supplied
4402 with Poky and located in
4403 <filename>meta-yocto</filename> and you do not set a
4404 "maintainers_whitelist" or "global_maintainer_override"
4405 in the <filename>upgrade-helper.conf</filename>
4406 configuration, and you specify "-e all" on the
4407 AUH command-line, the utility automatically sends out
4408 emails to all the default maintainers.
4409 Please avoid this.
4410 </para></listitem>
4411 </orderedlist>
4412 </para>
4413
4414 <para>
4415 This next set of examples describes how to use the AUH:
4416 <itemizedlist>
4417 <listitem><para>
4418 <emphasis>Upgrading a Specific Recipe:</emphasis>
4419 To upgrade a specific recipe, use the following
4420 form:
4421 <literallayout class='monospaced'>
4422 $ upgrade-helper.py <replaceable>recipe_name</replaceable>
4423 </literallayout>
4424 For example, this command upgrades the
4425 <filename>xmodmap</filename> recipe:
4426 <literallayout class='monospaced'>
4427 $ upgrade-helper.py xmodmap
4428 </literallayout>
4429 </para></listitem>
4430 <listitem><para>
4431 <emphasis>Upgrading a Specific Recipe to a Particular Version:</emphasis>
4432 To upgrade a specific recipe to a particular version,
4433 use the following form:
4434 <literallayout class='monospaced'>
4435 $ upgrade-helper.py <replaceable>recipe_name</replaceable> -t <replaceable>version</replaceable>
4436 </literallayout>
4437 For example, this command upgrades the
4438 <filename>xmodmap</filename> recipe to version
4439 1.2.3:
4440 <literallayout class='monospaced'>
4441 $ upgrade-helper.py xmodmap -t 1.2.3
4442 </literallayout>
4443 </para></listitem>
4444 <listitem><para>
4445 <emphasis>Upgrading all Recipes to the Latest Versions and Suppressing Email Notifications:</emphasis>
4446 To upgrade all recipes to their most recent versions
4447 and suppress the email notifications, use the following
4448 command:
4449 <literallayout class='monospaced'>
4450 $ upgrade-helper.py all
4451 </literallayout>
4452 </para></listitem>
4453 <listitem><para>
4454 <emphasis>Upgrading all Recipes to the Latest Versions and Send Email Notifications:</emphasis>
4455 To upgrade all recipes to their most recent versions
4456 and send email messages to maintainers for each
4457 attempted recipe as well as a status email, use the
4458 following command:
4459 <literallayout class='monospaced'>
4460 $ upgrade-helper.py -e all
4461 </literallayout>
4462 </para></listitem>
4463 </itemizedlist>
4464 </para>
4465
4466 <para>
4467 Once you have run the AUH utility, you can find the results
4468 in the AUH build directory:
4469 <literallayout class='monospaced'>
4470 ${BUILDDIR}/upgrade-helper/<replaceable>timestamp</replaceable>
4471 </literallayout>
4472 The AUH utility also creates recipe update commits from
4473 successful upgrade attempts in the layer tree.
4474 </para>
4475
4476 <para>
4477 You can easily set up to run the AUH utility on a regular
4478 basis by using a cron job.
4479 See the
4480 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh'><filename>weeklyjob.sh</filename></ulink>
4481 file distributed with the utility for an example.
4482 </para>
4483 </section>
4484
4485 <section id='gs-using-devtool-upgrade'>
4486 <title>Using <filename>devtool upgrade</filename></title>
4487
4488 <para>
4489 As mentioned earlier, an alternative method for upgrading
4490 recipes to newer versions is to use
4491 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool upgrade</filename></ulink>.
4492 You can read about <filename>devtool upgrade</filename> in
4493 general in the
4494 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software'>Use <filename>devtool upgrade</filename> to Create a Version of the Recipe that Supports a Newer Version of the Software</ulink>"
4495 section in the Yocto Project Application Development and the
4496 Extensible Software Development Kit (eSDK) Manual.
4497 </para>
4498
4499 <para>
4500 To see all the command-line options available with
4501 <filename>devtool upgrade</filename>, use the following help
4502 command:
4503 <literallayout class='monospaced'>
4504 $ devtool upgrade -h
4505 </literallayout>
4506 </para>
4507
4508 <para>
4509 If you want to find out what version a recipe is currently at
4510 upstream without any attempt to upgrade your local version of
4511 the recipe, you can use the following command:
4512 <literallayout class='monospaced'>
4513 $ devtool latest-version <replaceable>recipe_name</replaceable>
4514 </literallayout>
4515 </para>
4516
4517 <para>
4518 As mentioned in the previous section describing AUH,
4519 <filename>devtool upgrade</filename> works in a
4520 less-automated manner than AUH.
4521 Specifically, <filename>devtool upgrade</filename> only
4522 works on a single recipe that you name on the command line,
4523 cannot perform build and integration testing using images,
4524 and does not automatically generate commits for changes in
4525 the source tree.
4526 Despite all these "limitations",
4527 <filename>devtool upgrade</filename> updates the recipe file
4528 to the new upstream version and attempts to rebase custom
4529 patches contained by the recipe as needed.
4530 <note>
4531 AUH uses much of <filename>devtool upgrade</filename>
4532 behind the scenes making AUH somewhat of a "wrapper"
4533 application for <filename>devtool upgrade</filename>.
4534 </note>
4535 </para>
4536
4537 <para>
4538 A typical scenario involves having used Git to clone an
4539 upstream repository that you use during build operations.
4540 Because you are (or have) built the recipe in the past, the
4541 layer is likely added to your configuration already.
4542 If for some reason, the layer is not added, you could add
4543 it easily using the
4544 <ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-bitbake-layers-script'><filename>bitbake-layers</filename></ulink>
4545 script.
4546 For example, suppose you use the <filename>nano.bb</filename>
4547 recipe from the <filename>meta-oe</filename> layer in the
4548 <filename>meta-openembedded</filename> repository.
4549 For this example, assume that the layer has been cloned into
4550 following area:
4551 <literallayout class='monospaced'>
4552 /home/scottrif/meta-openembedded
4553 </literallayout>
4554 The following command from your
4555 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
4556 adds the layer to your build configuration (i.e.
4557 <filename>${BUILDDIR}/conf/bblayers.conf</filename>):
4558 <literallayout class='monospaced'>
4559 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
4560 NOTE: Starting bitbake server...
4561 Parsing recipes: 100% |##########################################| Time: 0:00:55
4562 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4563 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
4564 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
4565 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
4566 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
4567 </literallayout>
4568 For this example, assume that the <filename>nano.bb</filename>
4569 recipe that is upstream has a 2.9.3 version number.
4570 However, the version in the local repository is 2.7.4.
4571 The following command from your build directory automatically
4572 upgrades the recipe for you:
4573 <note>
4574 Using the <filename>-V</filename> option is not necessary.
4575 Omitting the version number causes
4576 <filename>devtool upgrade</filename> to upgrade the recipe
4577 to the most recent version.
4578 </note>
4579 <literallayout class='monospaced'>
4580 $ devtool upgrade nano -V 2.9.3
4581 NOTE: Starting bitbake server...
4582 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
4583 Parsing recipes: 100% |##########################################| Time: 0:00:46
4584 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
4585 NOTE: Extracting current version source...
4586 NOTE: Resolving any missing task queue dependencies
4587 .
4588 .
4589 .
4590 NOTE: Executing SetScene Tasks
4591 NOTE: Executing RunQueue Tasks
4592 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
4593 Adding changed files: 100% |#####################################| Time: 0:00:00
4594 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
4595 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
4596 </literallayout>
4597 Continuing with this example, you can use
4598 <filename>devtool build</filename> to build the newly upgraded
4599 recipe:
4600 <literallayout class='monospaced'>
4601 $ devtool build nano
4602 NOTE: Starting bitbake server...
4603 Loading cache: 100% |################################################################################################| Time: 0:00:01
4604 Loaded 2040 entries from dependency cache.
4605 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
4606 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4607 NOTE: Resolving any missing task queue dependencies
4608 .
4609 .
4610 .
4611 NOTE: Executing SetScene Tasks
4612 NOTE: Executing RunQueue Tasks
4613 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
4614 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
4615 </literallayout>
4616 Within the <filename>devtool upgrade</filename> workflow,
4617 opportunity exists to deploy and test your rebuilt software.
4618 For this example, however, running
4619 <filename>devtool finish</filename> cleans up the workspace
4620 once the source in your workspace is clean.
4621 This usually means using Git to stage and submit commits
4622 for the changes generated by the upgrade process.
4623 </para>
4624
4625 <para>
4626 Once the tree is clean, you can clean things up in this
4627 example with the following command from the
4628 <filename>${BUILDDIR}/workspace/sources/nano</filename>
4629 directory:
4630 <literallayout class='monospaced'>
4631 $ devtool finish nano meta-oe
4632 NOTE: Starting bitbake server...
4633 Loading cache: 100% |################################################################################################| Time: 0:00:00
4634 Loaded 2040 entries from dependency cache.
4635 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
4636 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
4637 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
4638 NOTE: Updating recipe nano_2.9.3.bb
4639 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
4640 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
4641 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
4642 </literallayout>
4643 Using the <filename>devtool finish</filename> command cleans
4644 up the workspace and creates a patch file based on your
4645 commits.
4646 The tool puts all patch files back into the source directory
4647 in a sub-directory named <filename>nano</filename> in this
4648 case.
4649 </para>
4650 </section>
4651
4652 <section id='dev-manually-upgrading-a-recipe'>
4653 <title>Manually Upgrading a Recipe</title>
4654
4655 <para>
4656 If for some reason you choose not to upgrade recipes using the
4657 <link linkend='gs-using-the-auto-upgrade-helper'>Auto Upgrade Helper (AUH)</link>
4658 or by using
4659 <link linkend='gs-using-devtool-upgrade'><filename>devtool upgrade</filename></link>,
4660 you can manually edit the recipe files to upgrade the versions.
4661 <note><title>Caution</title>
4662 Manually updating multiple recipes scales poorly and
4663 involves many steps.
4664 The recommendation to upgrade recipe versions is through
4665 AUH or <filename>devtool upgrade</filename>, both of which
4666 automate some steps and provide guidance for others needed
4667 for the manual process.
4668 </note>
4669 </para>
4670
4671 <para>
4672 To manually upgrade recipe versions, follow these general steps:
4673 <orderedlist>
4674 <listitem><para>
4675 <emphasis>Change the Version:</emphasis>
4676 Rename the recipe such that the version (i.e. the
4677 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
4678 part of the recipe name) changes appropriately.
4679 If the version is not part of the recipe name, change
4680 the value as it is set for <filename>PV</filename>
4681 within the recipe itself.
4682 </para></listitem>
4683 <listitem><para>
4684 <emphasis>Update <filename>SRCREV</filename> if Needed:</emphasis>
4685 If the source code your recipe builds is fetched from
4686 Git or some other version control system, update
4687 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
4688 to point to the commit hash that matches the new
4689 version.
4690 </para></listitem>
4691 <listitem><para>
4692 <emphasis>Build the Software:</emphasis>
4693 Try to build the recipe using BitBake.
4694 Typical build failures include the following:
4695 <itemizedlist>
4696 <listitem><para>
4697 License statements were updated for the new
4698 version.
4699 For this case, you need to review any changes
4700 to the license and update the values of
4701 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
4702 and
4703 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
4704 as needed.
4705 <note>
4706 License changes are often inconsequential.
4707 For example, the license text's copyright
4708 year might have changed.
4709 </note>
4710 </para></listitem>
4711 <listitem><para>
4712 Custom patches carried by the older version of
4713 the recipe might fail to apply to the new
4714 version.
4715 For these cases, you need to review the
4716 failures.
4717 Patches might not be necessary for the new
4718 version of the software if the upgraded version
4719 has fixed those issues.
4720 If a patch is necessary and failing, you need
4721 to rebase it into the new version.
4722 </para></listitem>
4723 </itemizedlist>
4724 </para></listitem>
4725 <listitem><para>
4726 <emphasis>Optionally Attempt to Build for Several Architectures:</emphasis>
4727 Once you successfully build the new software for a
4728 given architecture, you could test the build for
4729 other architectures by changing the
4730 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
4731 variable and rebuilding the software.
4732 This optional step is especially important if the
4733 recipe is to be released publicly.
4734 </para></listitem>
4735 <listitem><para>
4736 <emphasis>Check the Upstream Change Log or Release Notes:</emphasis>
4737 Checking both these reveals if new features exist that
4738 could break backwards-compatibility.
4739 If so, you need to take steps to mitigate or eliminate
4740 that situation.
4741 </para></listitem>
4742 <listitem><para>
4743 <emphasis>Optionally Create a Bootable Image and Test:</emphasis>
4744 If you want, you can test the new software by booting
4745 it onto actual hardware.
4746 </para></listitem>
4747 <listitem><para>
4748 <emphasis>Create a Commit with the Change in the Layer Repository:</emphasis>
4749 After all builds work and any testing is successful,
4750 you can create commits for any changes in the layer
4751 holding your upgraded recipe.
4752 </para></listitem>
4753 </orderedlist>
4754 </para>
4755 </section>
4756 </section>
4757
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004758 <section id='finding-the-temporary-source-code'>
4759 <title>Finding Temporary Source Code</title>
4760
4761 <para>
4762 You might find it helpful during development to modify the
4763 temporary source code used by recipes to build packages.
4764 For example, suppose you are developing a patch and you need to
4765 experiment a bit to figure out your solution.
4766 After you have initially built the package, you can iteratively
4767 tweak the source code, which is located in the
4768 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
4769 and then you can force a re-compile and quickly test your altered
4770 code.
4771 Once you settle on a solution, you can then preserve your changes
4772 in the form of patches.
4773 </para>
4774
4775 <para>
4776 During a build, the unpacked temporary source code used by recipes
4777 to build packages is available in the Build Directory as
4778 defined by the
4779 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4780 variable.
4781 Below is the default value for the <filename>S</filename> variable
4782 as defined in the
4783 <filename>meta/conf/bitbake.conf</filename> configuration file
4784 in the
4785 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
4786 <literallayout class='monospaced'>
4787 S = "${WORKDIR}/${BP}"
4788 </literallayout>
4789 You should be aware that many recipes override the
4790 <filename>S</filename> variable.
4791 For example, recipes that fetch their source from Git usually set
4792 <filename>S</filename> to <filename>${WORKDIR}/git</filename>.
4793 <note>
4794 The
4795 <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink>
4796 represents the base recipe name, which consists of the name
4797 and version:
4798 <literallayout class='monospaced'>
4799 BP = "${BPN}-${PV}"
4800 </literallayout>
4801 </note>
4802 </para>
4803
4804 <para>
4805 The path to the work directory for the recipe
4806 (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>)
4807 is defined as follows:
4808 <literallayout class='monospaced'>
4809 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
4810 </literallayout>
4811 The actual directory depends on several things:
4812 <itemizedlist>
4813 <listitem><para>
4814 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>:
4815 The top-level build output directory.
4816 </para></listitem>
4817 <listitem><para>
4818 <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>:
4819 The target system identifier.
4820 </para></listitem>
4821 <listitem><para>
4822 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>:
4823 The recipe name.
4824 </para></listitem>
4825 <listitem><para>
4826 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>:
4827 The epoch - (if
4828 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>
4829 is not specified, which is usually the case for most
4830 recipes, then <filename>EXTENDPE</filename> is blank).
4831 </para></listitem>
4832 <listitem><para>
4833 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>:
4834 The recipe version.
4835 </para></listitem>
4836 <listitem><para>
4837 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>:
4838 The recipe revision.
4839 </para></listitem>
4840 </itemizedlist>
4841 </para>
4842
4843 <para>
4844 As an example, assume a Source Directory top-level folder
4845 named <filename>poky</filename>, a default Build Directory at
4846 <filename>poky/build</filename>, and a
4847 <filename>qemux86-poky-linux</filename> machine target
4848 system.
4849 Furthermore, suppose your recipe is named
4850 <filename>foo_1.3.0.bb</filename>.
4851 In this case, the work directory the build system uses to
4852 build the package would be as follows:
4853 <literallayout class='monospaced'>
4854 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
4855 </literallayout>
4856 </para>
4857 </section>
4858
4859 <section id="using-a-quilt-workflow">
4860 <title>Using Quilt in Your Workflow</title>
4861
4862 <para>
4863 <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink>
4864 is a powerful tool that allows you to capture source code changes
4865 without having a clean source tree.
4866 This section outlines the typical workflow you can use to modify
4867 source code, test changes, and then preserve the changes in the
4868 form of a patch all using Quilt.
4869 <note><title>Tip</title>
4870 With regard to preserving changes to source files, if you
4871 clean a recipe or have <filename>rm_work</filename> enabled,
4872 the
4873 <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink>
4874 as described in the Yocto Project Application Development
4875 and the Extensible Software Development Kit (eSDK) manual
4876 is a safer development flow than the flow that uses Quilt.
4877 </note>
4878 </para>
4879
4880 <para>
4881 Follow these general steps:
4882 <orderedlist>
4883 <listitem><para>
4884 <emphasis>Find the Source Code:</emphasis>
4885 Temporary source code used by the OpenEmbedded build system
4886 is kept in the
4887 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
4888 See the
4889 "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>"
4890 section to learn how to locate the directory that has the
4891 temporary source code for a particular package.
4892 </para></listitem>
4893 <listitem><para>
4894 <emphasis>Change Your Working Directory:</emphasis>
4895 You need to be in the directory that has the temporary
4896 source code.
4897 That directory is defined by the
4898 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
4899 variable.</para></listitem>
4900 <listitem><para>
4901 <emphasis>Create a New Patch:</emphasis>
4902 Before modifying source code, you need to create a new
4903 patch.
4904 To create a new patch file, use
4905 <filename>quilt new</filename> as below:
4906 <literallayout class='monospaced'>
4907 $ quilt new my_changes.patch
4908 </literallayout>
4909 </para></listitem>
4910 <listitem><para>
4911 <emphasis>Notify Quilt and Add Files:</emphasis>
4912 After creating the patch, you need to notify Quilt about
4913 the files you plan to edit.
4914 You notify Quilt by adding the files to the patch you
4915 just created:
4916 <literallayout class='monospaced'>
4917 $ quilt add file1.c file2.c file3.c
4918 </literallayout>
4919 </para></listitem>
4920 <listitem><para>
4921 <emphasis>Edit the Files:</emphasis>
4922 Make your changes in the source code to the files you added
4923 to the patch.
4924 </para></listitem>
4925 <listitem><para>
4926 <emphasis>Test Your Changes:</emphasis>
4927 Once you have modified the source code, the easiest way to
4928 test your changes is by calling the
4929 <filename>do_compile</filename> task as shown in the
4930 following example:
4931 <literallayout class='monospaced'>
4932 $ bitbake -c compile -f <replaceable>package</replaceable>
4933 </literallayout>
4934 The <filename>-f</filename> or <filename>--force</filename>
4935 option forces the specified task to execute.
4936 If you find problems with your code, you can just keep
4937 editing and re-testing iteratively until things work
4938 as expected.
4939 <note>
4940 All the modifications you make to the temporary
4941 source code disappear once you run the
4942 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>
4943 or
4944 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>
4945 tasks using BitBake (i.e.
4946 <filename>bitbake -c clean <replaceable>package</replaceable></filename>
4947 and
4948 <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>).
4949 Modifications will also disappear if you use the
4950 <filename>rm_work</filename> feature as described
4951 in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04004952 "<ulink url='&YOCTO_DOCS_DEV_URL;#dev-saving-memory-during-a-build'>Conserving Disk Space During Builds</ulink>"
4953 section.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004954 </note>
4955 </para></listitem>
4956 <listitem><para>
4957 <emphasis>Generate the Patch:</emphasis>
4958 Once your changes work as expected, you need to use Quilt
4959 to generate the final patch that contains all your
4960 modifications.
4961 <literallayout class='monospaced'>
4962 $ quilt refresh
4963 </literallayout>
4964 At this point, the <filename>my_changes.patch</filename>
4965 file has all your edits made to the
4966 <filename>file1.c</filename>, <filename>file2.c</filename>,
4967 and <filename>file3.c</filename> files.</para>
4968
4969 <para>You can find the resulting patch file in the
4970 <filename>patches/</filename> subdirectory of the source
4971 (<filename>S</filename>) directory.
4972 </para></listitem>
4973 <listitem><para>
4974 <emphasis>Copy the Patch File:</emphasis>
4975 For simplicity, copy the patch file into a directory
4976 named <filename>files</filename>, which you can create
4977 in the same directory that holds the recipe
4978 (<filename>.bb</filename>) file or the append
4979 (<filename>.bbappend</filename>) file.
4980 Placing the patch here guarantees that the OpenEmbedded
4981 build system will find the patch.
4982 Next, add the patch into the
4983 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>
4984 of the recipe.
4985 Here is an example:
4986 <literallayout class='monospaced'>
4987 SRC_URI += "file://my_changes.patch"
4988 </literallayout>
4989 </para></listitem>
4990 </orderedlist>
4991 </para>
4992 </section>
4993
4994 <section id="platdev-appdev-devshell">
4995 <title>Using a Development Shell</title>
4996
4997 <para>
4998 When debugging certain commands or even when just editing packages,
4999 <filename>devshell</filename> can be a useful tool.
5000 When you invoke <filename>devshell</filename>, all tasks up to and
5001 including
5002 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5003 are run for the specified target.
5004 Then, a new terminal is opened and you are placed in
5005 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>,
5006 the source directory.
5007 In the new terminal, all the OpenEmbedded build-related environment variables are
5008 still defined so you can use commands such as <filename>configure</filename> and
5009 <filename>make</filename>.
5010 The commands execute just as if the OpenEmbedded build system were executing them.
5011 Consequently, working this way can be helpful when debugging a build or preparing
5012 software to be used with the OpenEmbedded build system.
5013 </para>
5014
5015 <para>
5016 Following is an example that uses <filename>devshell</filename> on a target named
5017 <filename>matchbox-desktop</filename>:
5018 <literallayout class='monospaced'>
5019 $ bitbake matchbox-desktop -c devshell
5020 </literallayout>
5021 </para>
5022
5023 <para>
5024 This command spawns a terminal with a shell prompt within the OpenEmbedded build environment.
5025 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5026 variable controls what type of shell is opened.
5027 </para>
5028
5029 <para>
5030 For spawned terminals, the following occurs:
5031 <itemizedlist>
5032 <listitem><para>The <filename>PATH</filename> variable includes the
5033 cross-toolchain.</para></listitem>
5034 <listitem><para>The <filename>pkgconfig</filename> variables find the correct
5035 <filename>.pc</filename> files.</para></listitem>
5036 <listitem><para>The <filename>configure</filename> command finds the
5037 Yocto Project site files as well as any other necessary files.</para></listitem>
5038 </itemizedlist>
5039 </para>
5040
5041 <para>
5042 Within this environment, you can run configure or compile
5043 commands as if they were being run by
5044 the OpenEmbedded build system itself.
5045 As noted earlier, the working directory also automatically changes to the
5046 Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>).
5047 </para>
5048
5049 <para>
5050 To manually run a specific task using <filename>devshell</filename>,
5051 run the corresponding <filename>run.*</filename> script in
5052 the
5053 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename>
5054 directory (e.g.,
5055 <filename>run.do_configure.</filename><replaceable>pid</replaceable>).
5056 If a task's script does not exist, which would be the case if the task was
5057 skipped by way of the sstate cache, you can create the task by first running
5058 it outside of the <filename>devshell</filename>:
5059 <literallayout class='monospaced'>
5060 $ bitbake -c <replaceable>task</replaceable>
5061 </literallayout>
5062 <note><title>Notes</title>
5063 <itemizedlist>
5064 <listitem><para>Execution of a task's <filename>run.*</filename>
5065 script and BitBake's execution of a task are identical.
5066 In other words, running the script re-runs the task
5067 just as it would be run using the
5068 <filename>bitbake -c</filename> command.
5069 </para></listitem>
5070 <listitem><para>Any <filename>run.*</filename> file that does not
5071 have a <filename>.pid</filename> extension is a
5072 symbolic link (symlink) to the most recent version of that
5073 file.
5074 </para></listitem>
5075 </itemizedlist>
5076 </note>
5077 </para>
5078
5079 <para>
5080 Remember, that the <filename>devshell</filename> is a mechanism that allows
5081 you to get into the BitBake task execution environment.
5082 And as such, all commands must be called just as BitBake would call them.
5083 That means you need to provide the appropriate options for
5084 cross-compilation and so forth as applicable.
5085 </para>
5086
5087 <para>
5088 When you are finished using <filename>devshell</filename>, exit the shell
5089 or close the terminal window.
5090 </para>
5091
5092 <note><title>Notes</title>
5093 <itemizedlist>
5094 <listitem><para>
5095 It is worth remembering that when using <filename>devshell</filename>
5096 you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename>
5097 instead of just using <filename>gcc</filename>.
5098 The same applies to other applications such as <filename>binutils</filename>,
5099 <filename>libtool</filename> and so forth.
5100 BitBake sets up environment variables such as <filename>CC</filename>
5101 to assist applications, such as <filename>make</filename> to find the correct tools.
5102 </para></listitem>
5103 <listitem><para>
5104 It is also worth noting that <filename>devshell</filename> still works over
5105 X11 forwarding and similar situations.
5106 </para></listitem>
5107 </itemizedlist>
5108 </note>
5109 </section>
5110
5111 <section id="platdev-appdev-devpyshell">
5112 <title>Using a Development Python Shell</title>
5113
5114 <para>
5115 Similar to working within a development shell as described in
5116 the previous section, you can also spawn and work within an
5117 interactive Python development shell.
5118 When debugging certain commands or even when just editing packages,
5119 <filename>devpyshell</filename> can be a useful tool.
5120 When you invoke <filename>devpyshell</filename>, all tasks up to and
5121 including
5122 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink>
5123 are run for the specified target.
5124 Then a new terminal is opened.
5125 Additionally, key Python objects and code are available in the same
5126 way they are to BitBake tasks, in particular, the data store 'd'.
5127 So, commands such as the following are useful when exploring the data
5128 store and running functions:
5129 <literallayout class='monospaced'>
Brad Bishop19323692019-04-05 15:28:33 -04005130 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005131 '/media/build1/poky/build/tmp/sysroots'
Brad Bishop19323692019-04-05 15:28:33 -04005132 pydevshell> d.getVar("STAGING_DIR")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005133 '${TMPDIR}/sysroots'
5134 pydevshell> d.setVar("FOO", "bar")
Brad Bishop19323692019-04-05 15:28:33 -04005135 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005136 'bar'
5137 pydevshell> d.delVar("FOO")
Brad Bishop19323692019-04-05 15:28:33 -04005138 pydevshell> d.getVar("FOO")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005139 pydevshell> bb.build.exec_func("do_unpack", d)
5140 pydevshell>
5141 </literallayout>
5142 The commands execute just as if the OpenEmbedded build system were executing them.
5143 Consequently, working this way can be helpful when debugging a build or preparing
5144 software to be used with the OpenEmbedded build system.
5145 </para>
5146
5147 <para>
5148 Following is an example that uses <filename>devpyshell</filename> on a target named
5149 <filename>matchbox-desktop</filename>:
5150 <literallayout class='monospaced'>
5151 $ bitbake matchbox-desktop -c devpyshell
5152 </literallayout>
5153 </para>
5154
5155 <para>
5156 This command spawns a terminal and places you in an interactive
5157 Python interpreter within the OpenEmbedded build environment.
5158 The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink>
5159 variable controls what type of shell is opened.
5160 </para>
5161
5162 <para>
5163 When you are finished using <filename>devpyshell</filename>, you
5164 can exit the shell either by using Ctrl+d or closing the terminal
5165 window.
5166 </para>
5167 </section>
5168
Brad Bishop316dfdd2018-06-25 12:45:53 -04005169 <section id='dev-building'>
5170 <title>Building</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005171
5172 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005173 This section describes various build procedures.
5174 For example, the steps needed for a simple build, a target that
5175 uses multiple configurations, building an image for more than
5176 one machine, and so forth.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005177 </para>
5178
Brad Bishop316dfdd2018-06-25 12:45:53 -04005179 <section id='dev-building-a-simple-image'>
5180 <title>Building a Simple Image</title>
5181
5182 <para>
5183 In the development environment, you need to build an image
5184 whenever you change hardware support, add or change system
5185 libraries, or add or change services that have dependencies.
5186 Several methods exist that allow you to build an image within
5187 the Yocto Project.
5188 This section presents the basic steps you need to build a
5189 simple image using BitBake from a build host running Linux.
5190 <note><title>Notes</title>
5191 <itemizedlist>
5192 <listitem><para>
5193 For information on how to build an image using
5194 <ulink url='&YOCTO_DOCS_REF_URL;#toaster-term'>Toaster</ulink>,
5195 see the
5196 <ulink url='&YOCTO_DOCS_TOAST_URL;'>Toaster User Manual</ulink>.
5197 </para></listitem>
5198 <listitem><para>
5199 For information on how to use
5200 <filename>devtool</filename> to build images, see
5201 the
5202 "<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'>Using <filename>devtool</filename> in Your SDK Workflow</ulink>"
5203 section in the Yocto Project Application
5204 Development and the Extensible Software Development
5205 Kit (eSDK) manual.
5206 </para></listitem>
5207 <listitem><para>
5208 For a quick example on how to build an image using
5209 the OpenEmbedded build system, see the
5210 <ulink url='&YOCTO_DOCS_BRIEF_URL;'>Yocto Project Quick Build</ulink>
5211 document.
5212 </para></listitem>
5213 </itemizedlist>
5214 </note>
5215 </para>
5216
5217 <para>
5218 The build process creates an entire Linux distribution from
5219 source and places it in your
5220 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
5221 under <filename>tmp/deploy/images</filename>.
5222 For detailed information on the build process using BitBake,
5223 see the
5224 "<ulink url='&YOCTO_DOCS_OM_URL;#images-dev-environment'>Images</ulink>"
5225 section in the Yocto Project Overview and Concepts Manual.
5226 </para>
5227
5228 <para>
5229 The following figure and list overviews the build process:
5230 <imagedata fileref="figures/bitbake-build-flow.png" width="7in" depth="4in" align="center" scalefit="1" />
5231 <orderedlist>
5232 <listitem><para>
5233 <emphasis>Set up Your Host Development System to Support
5234 Development Using the Yocto Project</emphasis>:
5235 See the
5236 "<link linkend='dev-manual-start'>Setting Up to Use the Yocto Project</link>"
5237 section for options on how to get a build host ready to
5238 use the Yocto Project.
5239 </para></listitem>
5240 <listitem><para>
5241 <emphasis>Initialize the Build Environment:</emphasis>
5242 Initialize the build environment by sourcing the build
5243 environment script (i.e.
5244 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
5245 <literallayout class='monospaced'>
5246 $ source &OE_INIT_FILE; [<replaceable>build_dir</replaceable>]
5247 </literallayout></para>
5248
5249 <para>When you use the initialization script, the
5250 OpenEmbedded build system uses
5251 <filename>build</filename> as the default Build
5252 Directory in your current work directory.
5253 You can use a <replaceable>build_dir</replaceable>
5254 argument with the script to specify a different build
5255 directory.
5256 <note><title>Tip</title>
5257 A common practice is to use a different Build
5258 Directory for different targets.
5259 For example, <filename>~/build/x86</filename> for a
5260 <filename>qemux86</filename> target, and
5261 <filename>~/build/arm</filename> for a
5262 <filename>qemuarm</filename> target.
5263 </note>
5264 </para></listitem>
5265 <listitem><para>
5266 <emphasis>Make Sure Your <filename>local.conf</filename>
5267 File is Correct:</emphasis>
5268 Ensure the <filename>conf/local.conf</filename>
5269 configuration file, which is found in the Build
5270 Directory, is set up how you want it.
5271 This file defines many aspects of the build environment
5272 including the target machine architecture through the
5273 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'>MACHINE</ulink></filename> variable,
5274 the packaging format used during the build
5275 (<ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>),
5276 and a centralized tarball download directory through the
5277 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> variable.
5278 </para></listitem>
5279 <listitem><para>
5280 <emphasis>Build the Image:</emphasis>
5281 Build the image using the <filename>bitbake</filename>
5282 command:
5283 <literallayout class='monospaced'>
5284 $ bitbake <replaceable>target</replaceable>
5285 </literallayout>
5286 <note>
5287 For information on BitBake, see the
5288 <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>.
5289 </note>
5290 The <replaceable>target</replaceable> is the name of the
5291 recipe you want to build.
5292 Common targets are the images in
5293 <filename>meta/recipes-core/images</filename>,
5294 <filename>meta/recipes-sato/images</filename>, and so
5295 forth all found in the
5296 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
5297 Or, the target can be the name of a recipe for a
5298 specific piece of software such as BusyBox.
5299 For more details about the images the OpenEmbedded build
5300 system supports, see the
5301 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
5302 chapter in the Yocto Project Reference Manual.</para>
5303
5304 <para>As an example, the following command builds the
5305 <filename>core-image-minimal</filename> image:
5306 <literallayout class='monospaced'>
5307 $ bitbake core-image-minimal
5308 </literallayout>
5309 Once an image has been built, it often needs to be
5310 installed.
5311 The images and kernels built by the OpenEmbedded
5312 build system are placed in the Build Directory in
5313 <filename class="directory">tmp/deploy/images</filename>.
5314 For information on how to run pre-built images such as
5315 <filename>qemux86</filename> and <filename>qemuarm</filename>,
5316 see the
5317 <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
5318 manual.
5319 For information about how to install these images,
5320 see the documentation for your particular board or
5321 machine.
5322 </para></listitem>
5323 </orderedlist>
5324 </para>
5325 </section>
5326
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005327 <section id='dev-building-images-for-multiple-targets-using-multiple-configurations'>
5328 <title>Building Images for Multiple Targets Using Multiple Configurations</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005329
5330 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005331 You can use a single <filename>bitbake</filename> command
5332 to build multiple images or packages for different targets
5333 where each image or package requires a different configuration
5334 (multiple configuration builds).
5335 The builds, in this scenario, are sometimes referred to as
5336 "multiconfigs", and this section uses that term throughout.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005337 </para>
5338
5339 <para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005340 This section describes how to set up for multiple
5341 configuration builds and how to account for cross-build
5342 dependencies between the multiconfigs.
Brad Bishop316dfdd2018-06-25 12:45:53 -04005343 </para>
5344
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005345 <section id='dev-setting-up-and-running-a-multiple-configuration-build'>
5346 <title>Setting Up and Running a Multiple Configuration Build</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005347
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005348 <para>
5349 To accomplish a multiple configuration build, you must
5350 define each target's configuration separately using
5351 a parallel configuration file in the
5352 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
5353 and you must follow a required file hierarchy.
5354 Additionally, you must enable the multiple configuration
5355 builds in your <filename>local.conf</filename> file.
5356 </para>
5357
5358 <para>
5359 Follow these steps to set up and execute multiple
5360 configuration builds:
5361 <itemizedlist>
5362 <listitem><para>
5363 <emphasis>Create Separate Configuration Files</emphasis>:
5364 You need to create a single configuration file for
5365 each build target (each multiconfig).
5366 Minimally, each configuration file must define the
5367 machine and the temporary directory BitBake uses
5368 for the build.
5369 Suggested practice dictates that you do not
5370 overlap the temporary directories
5371 used during the builds.
5372 However, it is possible that you can share the
5373 temporary directory
5374 (<ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5375 For example, consider a scenario with two
5376 different multiconfigs for the same
5377 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>: "qemux86" built for
5378 two distributions such as "poky" and "poky-lsb".
5379 In this case, you might want to use the same
5380 <filename>TMPDIR</filename>.</para>
5381
5382 <para>Here is an example showing the minimal
5383 statements needed in a configuration file for
5384 a "qemux86" target whose temporary build directory
5385 is <filename>tmpmultix86</filename>:
5386 <literallayout class='monospaced'>
5387 MACHINE="qemux86"
5388 TMPDIR="${TOPDIR}/tmpmultix86"
5389 </literallayout></para>
5390
5391 <para>The location for these multiconfig
5392 configuration files is specific.
5393 They must reside in the current build directory in
5394 a sub-directory of <filename>conf</filename> named
5395 <filename>multiconfig</filename>.
5396 Following is an example that defines two
5397 configuration files for the "x86" and "arm"
5398 multiconfigs:
5399 <imagedata fileref="figures/multiconfig_files.png" align="center" width="4in" depth="3in" />
5400 </para>
5401
5402 <para>The reason for this required file hierarchy
5403 is because the <filename>BBPATH</filename> variable
5404 is not constructed until the layers are parsed.
5405 Consequently, using the configuration file as a
5406 pre-configuration file is not possible unless it is
5407 located in the current working directory.
5408 </para></listitem>
5409 <listitem><para>
5410 <emphasis>Add the BitBake Multi-configuration Variable to the Local Configuration File</emphasis>:
5411 Use the
5412 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBMULTICONFIG'><filename>BBMULTICONFIG</filename></ulink>
5413 variable in your
5414 <filename>conf/local.conf</filename> configuration
5415 file to specify each multiconfig.
5416 Continuing with the example from the previous
5417 figure, the <filename>BBMULTICONFIG</filename>
5418 variable needs to enable two multiconfigs: "x86"
5419 and "arm" by specifying each configuration file:
5420 <literallayout class='monospaced'>
5421 BBMULTICONFIG = "x86 arm"
5422 </literallayout>
5423 </para></listitem>
5424 <listitem><para>
5425 <emphasis>Launch BitBake</emphasis>:
5426 Use the following BitBake command form to launch the
5427 multiple configuration build:
5428 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005429 $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005430 </literallayout>
5431 For the example in this section, the following
5432 command applies:
5433 <literallayout class='monospaced'>
5434 $ bitbake multiconfig:x86:core-image-minimal multiconfig:arm:core-image-sato
5435 </literallayout>
5436 The previous BitBake command builds a
5437 <filename>core-image-minimal</filename> image that
5438 is configured through the
5439 <filename>x86.conf</filename> configuration file
5440 and builds a <filename>core-image-sato</filename>
5441 image that is configured through the
5442 <filename>arm.conf</filename> configuration file.
5443 </para></listitem>
5444 </itemizedlist>
5445 <note>
5446 Support for multiple configuration builds in the
5447 Yocto Project &DISTRO; (&DISTRO_NAME;) Release does
5448 not include Shared State (sstate) optimizations.
5449 Consequently, if a build uses the same object twice
Brad Bishop316dfdd2018-06-25 12:45:53 -04005450 in, for example, two different
5451 <filename>TMPDIR</filename> directories, the build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005452 either loads from an existing sstate cache for that
5453 build at the start or builds the object fresh.
5454 </note>
5455 </para>
5456 </section>
5457
5458 <section id='dev-enabling-multiple-configuration-build-dependencies'>
5459 <title>Enabling Multiple Configuration Build Dependencies</title>
5460
5461 <para>
5462 Sometimes dependencies can exist between targets
5463 (multiconfigs) in a multiple configuration build.
5464 For example, suppose that in order to build a
5465 <filename>core-image-sato</filename> image for an "x86"
5466 multiconfig, the root filesystem of an "arm"
5467 multiconfig must exist.
5468 This dependency is essentially that the
5469 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-image'><filename>do_image</filename></ulink>
5470 task in the <filename>core-image-sato</filename> recipe
5471 depends on the completion of the
5472 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-rootfs'><filename>do_rootfs</filename></ulink>
5473 task of the <filename>core-image-minimal</filename>
5474 recipe.
5475 </para>
5476
5477 <para>
5478 To enable dependencies in a multiple configuration
5479 build, you must declare the dependencies in the recipe
5480 using the following statement form:
5481 <literallayout class='monospaced'>
5482 <replaceable>task_or_package</replaceable>[mcdepends] = "multiconfig:<replaceable>from_multiconfig</replaceable>:<replaceable>to_multiconfig</replaceable>:<replaceable>recipe_name</replaceable>:<replaceable>task_on_which_to_depend</replaceable>"
5483 </literallayout>
5484 To better show how to use this statement, consider the
5485 example scenario from the first paragraph of this section.
5486 The following statement needs to be added to the recipe
5487 that builds the <filename>core-image-sato</filename>
5488 image:
5489 <literallayout class='monospaced'>
5490 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_rootfs"
5491 </literallayout>
5492 In this example, the
5493 <replaceable>from_multiconfig</replaceable> is "x86".
5494 The <replaceable>to_multiconfig</replaceable> is "arm".
5495 The task on which the <filename>do_image</filename> task
5496 in the recipe depends is the <filename>do_rootfs</filename>
5497 task from the <filename>core-image-minimal</filename>
5498 recipe associated with the "arm" multiconfig.
5499 </para>
5500
5501 <para>
5502 Once you set up this dependency, you can build the
5503 "x86" multiconfig using a BitBake command as follows:
5504 <literallayout class='monospaced'>
5505 $ bitbake multiconfig:x86:core-image-sato
5506 </literallayout>
5507 This command executes all the tasks needed to create
5508 the <filename>core-image-sato</filename> image for the
5509 "x86" multiconfig.
5510 Because of the dependency, BitBake also executes through
5511 the <filename>do_rootfs</filename> task for the "arm"
5512 multiconfig build.
5513 </para>
5514
5515 <para>
5516 Having a recipe depend on the root filesystem of another
5517 build might not seem that useful.
5518 Consider this change to the statement in the
5519 <filename>core-image-sato</filename> recipe:
5520 <literallayout class='monospaced'>
5521 do_image[mcdepends] = "multiconfig:x86:arm:core-image-minimal:do_image"
5522 </literallayout>
5523 In this case, BitBake must create the
5524 <filename>core-image-minimal</filename> image for the
5525 "arm" build since the "x86" build depends on it.
5526 </para>
5527
5528 <para>
5529 Because "x86" and "arm" are enabled for multiple
5530 configuration builds and have separate configuration
5531 files, BitBake places the artifacts for each build in the
5532 respective temporary build directories (i.e.
5533 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>).
5534 </para>
5535 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04005536 </section>
5537
5538 <section id='building-an-initramfs-image'>
5539 <title>Building an Initial RAM Filesystem (initramfs) Image</title>
5540
5541 <para>
5542 An initial RAM filesystem (initramfs) image provides a temporary
5543 root filesystem used for early system initialization (e.g.
5544 loading of modules needed to locate and mount the "real" root
5545 filesystem).
5546 <note>
5547 The initramfs image is the successor of initial RAM disk
5548 (initrd).
5549 It is a "copy in and out" (cpio) archive of the initial
5550 filesystem that gets loaded into memory during the Linux
5551 startup process.
5552 Because Linux uses the contents of the archive during
5553 initialization, the initramfs image needs to contain all of the
5554 device drivers and tools needed to mount the final root
5555 filesystem.
5556 </note>
5557 </para>
5558
5559 <para>
5560 Follow these steps to create an initramfs image:
5561 <orderedlist>
5562 <listitem><para>
5563 <emphasis>Create the initramfs Image Recipe:</emphasis>
5564 You can reference the
5565 <filename>core-image-minimal-initramfs.bb</filename>
5566 recipe found in the <filename>meta/recipes-core</filename>
5567 directory of the
5568 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
5569 as an example from which to work.
5570 </para></listitem>
5571 <listitem><para>
5572 <emphasis>Decide if You Need to Bundle the initramfs Image
5573 Into the Kernel Image:</emphasis>
5574 If you want the initramfs image that is built to be
5575 bundled in with the kernel image, set the
5576 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5577 variable to "1" in your <filename>local.conf</filename>
5578 configuration file and set the
5579 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink>
5580 variable in the recipe that builds the kernel image.
5581 <note><title>Tip</title>
5582 It is recommended that you do bundle the initramfs
5583 image with the kernel image to avoid circular
5584 dependencies between the kernel recipe and the
5585 initramfs recipe should the initramfs image
5586 include kernel modules.
5587 </note>
5588 Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename>
5589 flag causes the initramfs image to be unpacked
5590 into the <filename>${B}/usr/</filename> directory.
5591 The unpacked initramfs image is then passed to the kernel's
5592 <filename>Makefile</filename> using the
5593 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink>
5594 variable, allowing the initramfs image to be built into
5595 the kernel normally.
5596 <note>
5597 If you choose to not bundle the initramfs image with
5598 the kernel image, you are essentially using an
5599 <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>.
5600 Creating an initrd is handled primarily through the
5601 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>,
5602 <filename>INITRD_LIVE</filename>, and
5603 <filename>INITRD_IMAGE_LIVE</filename> variables.
5604 For more information, see the
5605 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink>
5606 file.
5607 </note>
5608 </para></listitem>
5609 <listitem><para>
5610 <emphasis>Optionally Add Items to the initramfs Image
5611 Through the initramfs Image Recipe:</emphasis>
5612 If you add items to the initramfs image by way of its
5613 recipe, you should use
5614 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink>
5615 rather than
5616 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>.
5617 <filename>PACKAGE_INSTALL</filename> gives more direct
5618 control of what is added to the image as compared to
5619 the defaults you might not necessarily want that are
5620 set by the
5621 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink>
5622 or
5623 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink>
5624 classes.
5625 </para></listitem>
5626 <listitem><para>
5627 <emphasis>Build the Kernel Image and the initramfs
5628 Image:</emphasis>
5629 Build your kernel image using BitBake.
5630 Because the initramfs image recipe is a dependency of the
5631 kernel image, the initramfs image is built as well and
5632 bundled with the kernel image if you used the
5633 <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink>
5634 variable described earlier.
5635 </para></listitem>
5636 </orderedlist>
5637 </para>
5638 </section>
5639
5640 <section id='building-a-tiny-system'>
5641 <title>Building a Tiny System</title>
5642
5643 <para>
5644 Very small distributions have some significant advantages such
5645 as requiring less on-die or in-package memory (cheaper), better
5646 performance through efficient cache usage, lower power requirements
5647 due to less memory, faster boot times, and reduced development
5648 overhead.
5649 Some real-world examples where a very small distribution gives
5650 you distinct advantages are digital cameras, medical devices,
5651 and small headless systems.
5652 </para>
5653
5654 <para>
5655 This section presents information that shows you how you can
5656 trim your distribution to even smaller sizes than the
5657 <filename>poky-tiny</filename> distribution, which is around
5658 5 Mbytes, that can be built out-of-the-box using the Yocto Project.
5659 </para>
5660
5661 <section id='tiny-system-overview'>
5662 <title>Overview</title>
5663
5664 <para>
5665 The following list presents the overall steps you need to
5666 consider and perform to create distributions with smaller
5667 root filesystems, achieve faster boot times, maintain your critical
5668 functionality, and avoid initial RAM disks:
5669 <itemizedlist>
5670 <listitem><para>
5671 <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link>
5672 </para></listitem>
5673 <listitem><para>
5674 <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link>
5675 </para></listitem>
5676 <listitem><para>
5677 <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link>
5678 </para></listitem>
5679 <listitem><para>
5680 <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link>
5681 </para></listitem>
5682 <listitem><para>
5683 <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link>
5684 </para></listitem>
5685 <listitem><para>
5686 <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link>
5687 </para></listitem>
5688 <listitem><para>
5689 <link linkend='iterate-on-the-process'>Iterate on the process.</link>
5690 </para></listitem>
5691 </itemizedlist>
5692 </para>
5693 </section>
5694
5695 <section id='goals-and-guiding-principles'>
5696 <title>Goals and Guiding Principles</title>
5697
5698 <para>
5699 Before you can reach your destination, you need to know
5700 where you are going.
5701 Here is an example list that you can use as a guide when
5702 creating very small distributions:
5703 <itemizedlist>
5704 <listitem><para>Determine how much space you need
5705 (e.g. a kernel that is 1 Mbyte or less and
5706 a root filesystem that is 3 Mbytes or less).
5707 </para></listitem>
5708 <listitem><para>Find the areas that are currently
5709 taking 90% of the space and concentrate on reducing
5710 those areas.
5711 </para></listitem>
5712 <listitem><para>Do not create any difficult "hacks"
5713 to achieve your goals.</para></listitem>
5714 <listitem><para>Leverage the device-specific
5715 options.</para></listitem>
5716 <listitem><para>Work in a separate layer so that you
5717 keep changes isolated.
5718 For information on how to create layers, see
5719 the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section.
5720 </para></listitem>
5721 </itemizedlist>
5722 </para>
5723 </section>
5724
5725 <section id='understand-what-gives-your-image-size'>
5726 <title>Understand What Contributes to Your Image Size</title>
5727
5728 <para>
5729 It is easiest to have something to start with when creating
5730 your own distribution.
5731 You can use the Yocto Project out-of-the-box to create the
5732 <filename>poky-tiny</filename> distribution.
5733 Ultimately, you will want to make changes in your own
5734 distribution that are likely modeled after
5735 <filename>poky-tiny</filename>.
5736 <note>
5737 To use <filename>poky-tiny</filename> in your build,
5738 set the
5739 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
5740 variable in your
5741 <filename>local.conf</filename> file to "poky-tiny"
5742 as described in the
5743 "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>"
5744 section.
5745 </note>
5746 </para>
5747
5748 <para>
5749 Understanding some memory concepts will help you reduce the
5750 system size.
5751 Memory consists of static, dynamic, and temporary memory.
5752 Static memory is the TEXT (code), DATA (initialized data
5753 in the code), and BSS (uninitialized data) sections.
5754 Dynamic memory represents memory that is allocated at runtime:
5755 stacks, hash tables, and so forth.
5756 Temporary memory is recovered after the boot process.
5757 This memory consists of memory used for decompressing
5758 the kernel and for the <filename>__init__</filename>
5759 functions.
5760 </para>
5761
5762 <para>
5763 To help you see where you currently are with kernel and root
5764 filesystem sizes, you can use two tools found in the
5765 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in
5766 the <filename>scripts/tiny/</filename> directory:
5767 <itemizedlist>
5768 <listitem><para><filename>ksize.py</filename>: Reports
5769 component sizes for the kernel build objects.
5770 </para></listitem>
5771 <listitem><para><filename>dirsize.py</filename>: Reports
5772 component sizes for the root filesystem.</para></listitem>
5773 </itemizedlist>
5774 This next tool and command help you organize configuration
5775 fragments and view file dependencies in a human-readable form:
5776 <itemizedlist>
5777 <listitem><para><filename>merge_config.sh</filename>:
5778 Helps you manage configuration files and fragments
5779 within the kernel.
5780 With this tool, you can merge individual configuration
5781 fragments together.
5782 The tool allows you to make overrides and warns you
5783 of any missing configuration options.
5784 The tool is ideal for allowing you to iterate on
5785 configurations, create minimal configurations, and
5786 create configuration files for different machines
5787 without having to duplicate your process.</para>
5788 <para>The <filename>merge_config.sh</filename> script is
5789 part of the Linux Yocto kernel Git repositories
5790 (i.e. <filename>linux-yocto-3.14</filename>,
5791 <filename>linux-yocto-3.10</filename>,
5792 <filename>linux-yocto-3.8</filename>, and so forth)
5793 in the
5794 <filename>scripts/kconfig</filename> directory.</para>
5795 <para>For more information on configuration fragments,
5796 see the
5797 "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>"
5798 section in the Yocto Project Linux Kernel Development
5799 Manual.
5800 </para></listitem>
5801 <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>:
5802 Using the BitBake command with these options brings up
5803 a Dependency Explorer from which you can view file
5804 dependencies.
5805 Understanding these dependencies allows you to make
5806 informed decisions when cutting out various pieces of the
5807 kernel and root filesystem.</para></listitem>
5808 </itemizedlist>
5809 </para>
5810 </section>
5811
5812 <section id='trim-the-root-filesystem'>
5813 <title>Trim the Root Filesystem</title>
5814
5815 <para>
5816 The root filesystem is made up of packages for booting,
5817 libraries, and applications.
5818 To change things, you can configure how the packaging happens,
5819 which changes the way you build them.
5820 You can also modify the filesystem itself or select a different
5821 filesystem.
5822 </para>
5823
5824 <para>
5825 First, find out what is hogging your root filesystem by running the
5826 <filename>dirsize.py</filename> script from your root directory:
5827 <literallayout class='monospaced'>
5828 $ cd <replaceable>root-directory-of-image</replaceable>
5829 $ dirsize.py 100000 > dirsize-100k.log
5830 $ cat dirsize-100k.log
5831 </literallayout>
5832 You can apply a filter to the script to ignore files under
5833 a certain size.
5834 The previous example filters out any files below 100 Kbytes.
5835 The sizes reported by the tool are uncompressed, and thus
5836 will be smaller by a relatively constant factor in a
5837 compressed root filesystem.
5838 When you examine your log file, you can focus on areas of the
5839 root filesystem that take up large amounts of memory.
5840 </para>
5841
5842 <para>
5843 You need to be sure that what you eliminate does not cripple
5844 the functionality you need.
5845 One way to see how packages relate to each other is by using
5846 the Dependency Explorer UI with the BitBake command:
5847 <literallayout class='monospaced'>
5848 $ cd <replaceable>image-directory</replaceable>
5849 $ bitbake -u taskexp -g <replaceable>image</replaceable>
5850 </literallayout>
5851 Use the interface to select potential packages you wish to
5852 eliminate and see their dependency relationships.
5853 </para>
5854
5855 <para>
5856 When deciding how to reduce the size, get rid of packages that
5857 result in minimal impact on the feature set.
5858 For example, you might not need a VGA display.
5859 Or, you might be able to get by with <filename>devtmpfs</filename>
5860 and <filename>mdev</filename> instead of
5861 <filename>udev</filename>.
5862 </para>
5863
5864 <para>
5865 Use your <filename>local.conf</filename> file to make changes.
5866 For example, to eliminate <filename>udev</filename> and
5867 <filename>glib</filename>, set the following in the
5868 local configuration file:
5869 <literallayout class='monospaced'>
5870 VIRTUAL-RUNTIME_dev_manager = ""
5871 </literallayout>
5872 </para>
5873
5874 <para>
5875 Finally, you should consider exactly the type of root
5876 filesystem you need to meet your needs while also reducing
5877 its size.
5878 For example, consider <filename>cramfs</filename>,
5879 <filename>squashfs</filename>, <filename>ubifs</filename>,
5880 <filename>ext2</filename>, or an <filename>initramfs</filename>
5881 using <filename>initramfs</filename>.
5882 Be aware that <filename>ext3</filename> requires a 1 Mbyte
5883 journal.
5884 If you are okay with running read-only, you do not need this
5885 journal.
5886 </para>
5887
5888 <note>
5889 After each round of elimination, you need to rebuild your
5890 system and then use the tools to see the effects of your
5891 reductions.
5892 </note>
5893 </section>
5894
5895 <section id='trim-the-kernel'>
5896 <title>Trim the Kernel</title>
5897
5898 <para>
5899 The kernel is built by including policies for hardware-independent
5900 aspects.
5901 What subsystems do you enable?
5902 For what architecture are you building?
5903 Which drivers do you build by default?
5904 <note>You can modify the kernel source if you want to help
5905 with boot time.
5906 </note>
5907 </para>
5908
5909 <para>
5910 Run the <filename>ksize.py</filename> script from the top-level
5911 Linux build directory to get an idea of what is making up
5912 the kernel:
5913 <literallayout class='monospaced'>
5914 $ cd <replaceable>top-level-linux-build-directory</replaceable>
5915 $ ksize.py > ksize.log
5916 $ cat ksize.log
5917 </literallayout>
5918 When you examine the log, you will see how much space is
5919 taken up with the built-in <filename>.o</filename> files for
5920 drivers, networking, core kernel files, filesystem, sound,
5921 and so forth.
5922 The sizes reported by the tool are uncompressed, and thus
5923 will be smaller by a relatively constant factor in a compressed
5924 kernel image.
5925 Look to reduce the areas that are large and taking up around
5926 the "90% rule."
5927 </para>
5928
5929 <para>
5930 To examine, or drill down, into any particular area, use the
5931 <filename>-d</filename> option with the script:
5932 <literallayout class='monospaced'>
5933 $ ksize.py -d > ksize.log
5934 </literallayout>
5935 Using this option breaks out the individual file information
5936 for each area of the kernel (e.g. drivers, networking, and
5937 so forth).
5938 </para>
5939
5940 <para>
5941 Use your log file to see what you can eliminate from the kernel
5942 based on features you can let go.
5943 For example, if you are not going to need sound, you do not
5944 need any drivers that support sound.
5945 </para>
5946
5947 <para>
5948 After figuring out what to eliminate, you need to reconfigure
5949 the kernel to reflect those changes during the next build.
5950 You could run <filename>menuconfig</filename> and make all your
5951 changes at once.
5952 However, that makes it difficult to see the effects of your
5953 individual eliminations and also makes it difficult to replicate
5954 the changes for perhaps another target device.
5955 A better method is to start with no configurations using
5956 <filename>allnoconfig</filename>, create configuration
5957 fragments for individual changes, and then manage the
5958 fragments into a single configuration file using
5959 <filename>merge_config.sh</filename>.
5960 The tool makes it easy for you to iterate using the
5961 configuration change and build cycle.
5962 </para>
5963
5964 <para>
5965 Each time you make configuration changes, you need to rebuild
5966 the kernel and check to see what impact your changes had on
5967 the overall size.
5968 </para>
5969 </section>
5970
5971 <section id='remove-package-management-requirements'>
5972 <title>Remove Package Management Requirements</title>
5973
5974 <para>
5975 Packaging requirements add size to the image.
5976 One way to reduce the size of the image is to remove all the
5977 packaging requirements from the image.
5978 This reduction includes both removing the package manager
5979 and its unique dependencies as well as removing the package
5980 management data itself.
5981 </para>
5982
5983 <para>
5984 To eliminate all the packaging requirements for an image,
5985 be sure that "package-management" is not part of your
5986 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
5987 statement for the image.
5988 When you remove this feature, you are removing the package
5989 manager as well as its dependencies from the root filesystem.
5990 </para>
5991 </section>
5992
5993 <section id='look-for-other-ways-to-minimize-size'>
5994 <title>Look for Other Ways to Minimize Size</title>
5995
5996 <para>
5997 Depending on your particular circumstances, other areas that you
5998 can trim likely exist.
5999 The key to finding these areas is through tools and methods
6000 described here combined with experimentation and iteration.
6001 Here are a couple of areas to experiment with:
6002 <itemizedlist>
6003 <listitem><para><filename>glibc</filename>:
6004 In general, follow this process:
6005 <orderedlist>
6006 <listitem><para>Remove <filename>glibc</filename>
6007 features from
6008 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6009 that you think you do not need.</para></listitem>
6010 <listitem><para>Build your distribution.
6011 </para></listitem>
6012 <listitem><para>If the build fails due to missing
6013 symbols in a package, determine if you can
6014 reconfigure the package to not need those
6015 features.
6016 For example, change the configuration to not
6017 support wide character support as is done for
6018 <filename>ncurses</filename>.
6019 Or, if support for those characters is needed,
6020 determine what <filename>glibc</filename>
6021 features provide the support and restore the
6022 configuration.
6023 </para></listitem>
6024 <listitem><para>Rebuild and repeat the process.
6025 </para></listitem>
6026 </orderedlist></para></listitem>
6027 <listitem><para><filename>busybox</filename>:
6028 For BusyBox, use a process similar as described for
6029 <filename>glibc</filename>.
6030 A difference is you will need to boot the resulting
6031 system to see if you are able to do everything you
6032 expect from the running system.
6033 You need to be sure to integrate configuration fragments
6034 into Busybox because BusyBox handles its own core
6035 features and then allows you to add configuration
6036 fragments on top.
6037 </para></listitem>
6038 </itemizedlist>
6039 </para>
6040 </section>
6041
6042 <section id='iterate-on-the-process'>
6043 <title>Iterate on the Process</title>
6044
6045 <para>
6046 If you have not reached your goals on system size, you need
6047 to iterate on the process.
6048 The process is the same.
6049 Use the tools and see just what is taking up 90% of the root
6050 filesystem and the kernel.
6051 Decide what you can eliminate without limiting your device
6052 beyond what you need.
6053 </para>
6054
6055 <para>
6056 Depending on your system, a good place to look might be
6057 Busybox, which provides a stripped down
6058 version of Unix tools in a single, executable file.
6059 You might be able to drop virtual terminal services or perhaps
6060 ipv6.
6061 </para>
6062 </section>
6063 </section>
6064
6065 <section id='building-images-for-more-than-one-machine'>
6066 <title>Building Images for More than One Machine</title>
6067
6068 <para>
6069 A common scenario developers face is creating images for several
6070 different machines that use the same software environment.
6071 In this situation, it is tempting to set the
6072 tunings and optimization flags for each build specifically for
6073 the targeted hardware (i.e. "maxing out" the tunings).
6074 Doing so can considerably add to build times and package feed
6075 maintenance collectively for the machines.
6076 For example, selecting tunes that are extremely specific to a
6077 CPU core used in a system might enable some micro optimizations
6078 in GCC for that particular system but would otherwise not gain
6079 you much of a performance difference across the other systems
6080 as compared to using a more general tuning across all the builds
6081 (e.g. setting
6082 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink>
6083 specifically for each machine's build).
6084 Rather than "max out" each build's tunings, you can take steps that
6085 cause the OpenEmbedded build system to reuse software across the
6086 various machines where it makes sense.
6087 </para>
6088
6089 <para>
6090 If build speed and package feed maintenance are considerations,
6091 you should consider the points in this section that can help you
6092 optimize your tunings to best consider build times and package
6093 feed maintenance.
6094 <itemizedlist>
6095 <listitem><para>
6096 <emphasis>Share the Build Directory:</emphasis>
6097 If at all possible, share the
6098 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6099 across builds.
6100 The Yocto Project supports switching between different
6101 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
6102 values in the same <filename>TMPDIR</filename>.
6103 This practice is well supported and regularly used by
6104 developers when building for multiple machines.
6105 When you use the same <filename>TMPDIR</filename> for
6106 multiple machine builds, the OpenEmbedded build system can
6107 reuse the existing native and often cross-recipes for
6108 multiple machines.
6109 Thus, build time decreases.
6110 <note>
6111 If
6112 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
6113 settings change or fundamental configuration settings
6114 such as the filesystem layout, you need to work with
6115 a clean <filename>TMPDIR</filename>.
6116 Sharing <filename>TMPDIR</filename> under these
6117 circumstances might work but since it is not
6118 guaranteed, you should use a clean
6119 <filename>TMPDIR</filename>.
6120 </note>
6121 </para></listitem>
6122 <listitem><para>
6123 <emphasis>Enable the Appropriate Package Architecture:</emphasis>
6124 By default, the OpenEmbedded build system enables three
6125 levels of package architectures: "all", "tune" or "package",
6126 and "machine".
6127 Any given recipe usually selects one of these package
6128 architectures (types) for its output.
6129 Depending for what a given recipe creates packages, making
6130 sure you enable the appropriate package architecture can
6131 directly impact the build time.</para>
6132
6133 <para>A recipe that just generates scripts can enable
6134 "all" architecture because there are no binaries to build.
6135 To specifically enable "all" architecture, be sure your
6136 recipe inherits the
6137 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink>
6138 class.
6139 This class is useful for "all" architectures because it
6140 configures many variables so packages can be used across
6141 multiple architectures.</para>
6142
6143 <para>If your recipe needs to generate packages that are
6144 machine-specific or when one of the build or runtime
6145 dependencies is already machine-architecture dependent,
6146 which makes your recipe also machine-architecture dependent,
6147 make sure your recipe enables the "machine" package
6148 architecture through the
6149 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>
6150 variable:
6151 <literallayout class='monospaced'>
6152 PACKAGE_ARCH = "${MACHINE_ARCH}"
6153 </literallayout>
6154 When you do not specifically enable a package
6155 architecture through the
6156 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>,
6157 The OpenEmbedded build system defaults to the
6158 <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink>
6159 setting:
6160 <literallayout class='monospaced'>
6161 PACKAGE_ARCH = "${TUNE_PKGARCH}"
6162 </literallayout>
6163 </para></listitem>
6164 <listitem><para>
6165 <emphasis>Choose a Generic Tuning File if Possible:</emphasis>
6166 Some tunes are more generic and can run on multiple targets
6167 (e.g. an <filename>armv5</filename> set of packages could
6168 run on <filename>armv6</filename> and
6169 <filename>armv7</filename> processors in most cases).
6170 Similarly, <filename>i486</filename> binaries could work
6171 on <filename>i586</filename> and higher processors.
6172 You should realize, however, that advances on newer
6173 processor versions would not be used.</para>
6174
6175 <para>If you select the same tune for several different
6176 machines, the OpenEmbedded build system reuses software
6177 previously built, thus speeding up the overall build time.
6178 Realize that even though a new sysroot for each machine is
6179 generated, the software is not recompiled and only one
6180 package feed exists.
6181 </para></listitem>
6182 <listitem><para>
6183 <emphasis>Manage Granular Level Packaging:</emphasis>
6184 Sometimes cases exist where injecting another level of
6185 package architecture beyond the three higher levels noted
6186 earlier can be useful.
6187 For example, consider how NXP (formerly Freescale) allows
6188 for the easy reuse of binary packages in their layer
6189 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/'><filename>meta-freescale</filename></ulink>.
6190 In this example, the
6191 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass'><filename>fsl-dynamic-packagearch</filename></ulink>
6192 class shares GPU packages for i.MX53 boards because
6193 all boards share the AMD GPU.
6194 The i.MX6-based boards can do the same because all boards
6195 share the Vivante GPU.
6196 This class inspects the BitBake datastore to identify if
6197 the package provides or depends on one of the
6198 sub-architecture values.
6199 If so, the class sets the
6200 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6201 value based on the <filename>MACHINE_SUBARCH</filename>
6202 value.
6203 If the package does not provide or depend on one of the
6204 sub-architecture values but it matches a value in the
6205 machine-specific filter, it sets
6206 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink>.
6207 This behavior reduces the number of packages built and
6208 saves build time by reusing binaries.
6209 </para></listitem>
6210 <listitem><para>
6211 <emphasis>Use Tools to Debug Issues:</emphasis>
6212 Sometimes you can run into situations where software is
6213 being rebuilt when you think it should not be.
6214 For example, the OpenEmbedded build system might not be
6215 using shared state between machines when you think it
6216 should be.
6217 These types of situations are usually due to references
6218 to machine-specific variables such as
6219 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>,
6220 <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'><filename>SERIAL_CONSOLES</filename></ulink>,
6221 <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>,
6222 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>,
6223 and so forth in code that is supposed to only be
6224 tune-specific or when the recipe depends
6225 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6226 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6227 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6228 <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>,
6229 and so forth) on some other recipe that already has
6230 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>
6231 defined as "${MACHINE_ARCH}".
6232 <note>
6233 Patches to fix any issues identified are most welcome
6234 as these issues occasionally do occur.
6235 </note></para>
6236
6237 <para>For such cases, you can use some tools to help you
6238 sort out the situation:
6239 <itemizedlist>
6240 <listitem><para>
6241 <emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis>
6242 You can find this tool in the
6243 <filename>scripts</filename> directory of the
6244 Source Repositories.
6245 See the comments in the script for information on
6246 how to use the tool.
6247 </para></listitem>
6248 <listitem><para>
6249 <emphasis>BitBake's "-S printdiff" Option:</emphasis>
6250 Using this option causes BitBake to try to
6251 establish the closest signature match it can
6252 (e.g. in the shared state cache) and then run
6253 <filename>bitbake-diffsigs</filename> over the
6254 matches to determine the stamps and delta where
6255 these two stamp trees diverge.
6256 </para></listitem>
6257 </itemizedlist>
6258 </para></listitem>
6259 </itemizedlist>
6260 </para>
6261 </section>
6262
6263 <section id="building-software-from-an-external-source">
6264 <title>Building Software from an External Source</title>
6265
6266 <para>
6267 By default, the OpenEmbedded build system uses the
6268 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6269 when building source code.
6270 The build process involves fetching the source files, unpacking
6271 them, and then patching them if necessary before the build takes
6272 place.
6273 </para>
6274
6275 <para>
6276 Situations exist where you might want to build software from source
6277 files that are external to and thus outside of the
6278 OpenEmbedded build system.
6279 For example, suppose you have a project that includes a new BSP with
6280 a heavily customized kernel.
6281 And, you want to minimize exposing the build system to the
6282 development team so that they can focus on their project and
6283 maintain everyone's workflow as much as possible.
6284 In this case, you want a kernel source directory on the development
6285 machine where the development occurs.
6286 You want the recipe's
6287 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
6288 variable to point to the external directory and use it as is, not
6289 copy it.
6290 </para>
6291
6292 <para>
6293 To build from software that comes from an external source, all you
6294 need to do is inherit the
6295 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6296 class and then set the
6297 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>
6298 variable to point to your external source code.
6299 Here are the statements to put in your
6300 <filename>local.conf</filename> file:
6301 <literallayout class='monospaced'>
6302 INHERIT += "externalsrc"
6303 EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6304 </literallayout>
6305 </para>
6306
6307 <para>
6308 This next example shows how to accomplish the same thing by setting
6309 <filename>EXTERNALSRC</filename> in the recipe itself or in the
6310 recipe's append file:
6311 <literallayout class='monospaced'>
6312 EXTERNALSRC = "<replaceable>path</replaceable>"
6313 EXTERNALSRC_BUILD = "<replaceable>path</replaceable>"
6314 </literallayout>
6315 <note>
6316 In order for these settings to take effect, you must globally
6317 or locally inherit the
6318 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink>
6319 class.
6320 </note>
6321 </para>
6322
6323 <para>
6324 By default, <filename>externalsrc.bbclass</filename> builds
6325 the source code in a directory separate from the external source
6326 directory as specified by
6327 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>.
6328 If you need to have the source built in the same directory in
6329 which it resides, or some other nominated directory, you can set
6330 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink>
6331 to point to that directory:
6332 <literallayout class='monospaced'>
6333 EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>"
6334 </literallayout>
6335 </para>
6336 </section>
Brad Bishop19323692019-04-05 15:28:33 -04006337
6338 <section id="replicating-a-build-offline">
6339 <title>Replicating a Build Offline</title>
6340
6341 <para>
6342 It can be useful to take a "snapshot" of upstream sources
6343 used in a build and then use that "snapshot" later to
6344 replicate the build offline.
6345 To do so, you need to first prepare and populate your downloads
6346 directory your "snapshot" of files.
6347 Once your downloads directory is ready, you can use it at
6348 any time and from any machine to replicate your build.
6349 </para>
6350
6351 <para>
6352 Follow these steps to populate your Downloads directory:
6353 <orderedlist>
6354 <listitem><para>
6355 <emphasis>Create a Clean Downloads Directory:</emphasis>
6356 Start with an empty downloads directory
6357 (<ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>).
6358 You start with an empty downloads directory by either
6359 removing the files in the existing directory or by
6360 setting
6361 <filename>DL_DIR</filename> to point to either an
6362 empty location or one that does not yet exist.
6363 </para></listitem>
6364 <listitem><para>
6365 <emphasis>Generate Tarballs of the Source Git Repositories:</emphasis>
6366 Edit your <filename>local.conf</filename> configuration
6367 file as follows:
6368 <literallayout class='monospaced'>
6369 DL_DIR = "/home/<replaceable>your-download-dir</replaceable>/"
6370 BB_GENERATE_MIRROR_TARBALLS = "1"
6371 </literallayout>
6372 During the fetch process in the next step, BitBake
6373 gathers the source files and creates tarballs in
6374 the directory pointed to by <filename>DL_DIR</filename>.
6375 See the
6376 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
6377 variable for more information.
6378 </para></listitem>
6379 <listitem><para>
6380 <emphasis>Populate Your Downloads Directory Without Building:</emphasis>
6381 Use BitBake to fetch your sources but inhibit the
6382 build:
6383 <literallayout class='monospaced'>
6384 $ bitbake <replaceable>target</replaceable> --runonly=fetch
6385 </literallayout>
6386 The downloads directory (i.e.
6387 <filename>${DL_DIR}</filename>) now has a "snapshot" of
6388 the source files in the form of tarballs, which can
6389 be used for the build.
6390 </para></listitem>
6391 <listitem><para>
6392 <emphasis>Optionally Remove Any Git or other SCM Subdirectories From the Downloads Directory:</emphasis>
6393 If you want, you can clean up your downloads directory
6394 by removing any Git or other Source Control Management
6395 (SCM) subdirectories such as
6396 <filename>${DL_DIR}/git2/*</filename>.
6397 The tarballs already contain these subdirectories.
6398 </para></listitem>
6399 </orderedlist>
6400 </para>
6401
6402 <para>
6403 Once your downloads directory has everything it needs regarding
6404 source files, you can create your "own-mirror" and build
6405 your target.
6406 Understand that you can use the files to build the target
6407 offline from any machine and at any time.
6408 </para>
6409
6410 <para>
6411 Follow these steps to build your target using the files in the
6412 downloads directory:
6413 <orderedlist>
6414 <listitem><para>
6415 <emphasis>Using Local Files Only:</emphasis>
6416 Inside your <filename>local.conf</filename> file, add
6417 the
6418 <ulink url='&YOCTO_DOCS_REF_URL;#var-SOURCE_MIRROR_URL'><filename>SOURCE_MIRROR_URL</filename></ulink>
6419 variable,
6420 inherit the <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-own-mirrors'><filename>own-mirrors</filename></ulink>
6421 class, and use the
6422 <ulink url='&YOCTO_DOCS_BB_URL;#var-bb-BB_NO_NETWORK'><filename>BB_NO_NETWORK</filename></ulink>
6423 variable to your <filename>local.conf</filename>.
6424 <literallayout class='monospaced'>
6425 SOURCE_MIRROR_URL ?= "file:///home/<replaceable>your-download-dir</replaceable>/"
6426 INHERIT += "own-mirrors"
6427 BB_NO_NETWORK = "1"
6428 </literallayout>
6429 The <filename>SOURCE_MIRROR_URL</filename> and
6430 <filename>own-mirror</filename> class set up the system
6431 to use the downloads directory as your "own mirror".
6432 Using the <filename>BB_NO_NETWORK</filename>
6433 variable makes sure that BitBake's fetching process
6434 in step 3 stays local, which means files from
6435 your "own-mirror" are used.
6436 </para></listitem>
6437 <listitem><para>
6438 <emphasis>Start With a Clean Build:</emphasis>
6439 You can start with a clean build by removing the
6440 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
6441 directory or using a new
6442 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
6443 </para></listitem>
6444 <listitem><para>
6445 <emphasis>Build Your Target:</emphasis>
6446 Use BitBake to build your target:
6447 <literallayout class='monospaced'>
6448 $ bitbake <replaceable>target</replaceable>
6449 </literallayout>
6450 The build completes using the known local "snapshot" of
6451 source files from your mirror.
6452 The resulting tarballs for your "snapshot" of source
6453 files are in the downloads directory.
6454 <note>
6455 <para>The offline build does not work if recipes
6456 attempt to find the latest version of software
6457 by setting
6458 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
6459 to
6460 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink><filename>}</filename>:
6461 <literallayout class='monospaced'>
6462 SRCREV = "${AUTOREV}"
6463 </literallayout>
6464 When a recipe sets
6465 <filename>SRCREV</filename> to
6466 <filename>${AUTOREV}</filename>, the build system
6467 accesses the network in an attempt to determine the
6468 latest version of software from the SCM.
6469 Typically, recipes that use
6470 <filename>AUTOREV</filename> are custom or
6471 modified recipes.
6472 Recipes that reside in public repositories
6473 usually do not use <filename>AUTOREV</filename>.
6474 </para>
6475
6476 <para>If you do have recipes that use
6477 <filename>AUTOREV</filename>, you can take steps to
6478 still use the recipes in an offline build.
6479 Do the following:
6480 <orderedlist>
6481 <listitem><para>
6482 Use a configuration generated by
6483 enabling
6484 <link linkend='maintaining-build-output-quality'>build history</link>.
6485 </para></listitem>
6486 <listitem><para>
6487 Use the
6488 <filename>buildhistory-collect-srcrevs</filename>
6489 command to collect the stored
6490 <filename>SRCREV</filename> values from
6491 the build's history.
6492 For more information on collecting these
6493 values, see the
6494 "<link linkend='build-history-package-information'>Build History Package Information</link>"
6495 section.
6496 </para></listitem>
6497 <listitem><para>
6498 Once you have the correct source
6499 revisions, you can modify those recipes
6500 to to set <filename>SRCREV</filename>
6501 to specific versions of the software.
6502 </para></listitem>
6503 </orderedlist>
6504 </para>
6505 </note>
6506 </para></listitem>
6507 </orderedlist>
6508 </para>
6509 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006510 </section>
6511
Brad Bishop316dfdd2018-06-25 12:45:53 -04006512 <section id='speeding-up-a-build'>
6513 <title>Speeding Up a Build</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006514
6515 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006516 Build time can be an issue.
6517 By default, the build system uses simple controls to try and maximize
6518 build efficiency.
6519 In general, the default settings for all the following variables
6520 result in the most efficient build times when dealing with single
6521 socket systems (i.e. a single CPU).
6522 If you have multiple CPUs, you might try increasing the default
6523 values to gain more speed.
6524 See the descriptions in the glossary for each variable for more
6525 information:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006526 <itemizedlist>
6527 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006528 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename>:</ulink>
6529 The maximum number of threads BitBake simultaneously executes.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006530 </para></listitem>
6531 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006532 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_NUMBER_PARSE_THREADS'><filename>BB_NUMBER_PARSE_THREADS</filename>:</ulink>
6533 The number of threads BitBake uses during parsing.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006534 </para></listitem>
6535 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006536 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename>:</ulink>
6537 Extra options passed to the <filename>make</filename> command
6538 during the
6539 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
6540 task in order to specify parallel compilation on the
6541 local build host.
6542 </para></listitem>
6543 <listitem><para>
6544 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename>:</ulink>
6545 Extra options passed to the <filename>make</filename> command
6546 during the
6547 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
6548 task in order to specify parallel installation on the
6549 local build host.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006550 </para></listitem>
6551 </itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006552 As mentioned, these variables all scale to the number of processor
6553 cores available on the build system.
6554 For single socket systems, this auto-scaling ensures that the build
6555 system fundamentally takes advantage of potential parallel operations
6556 during the build based on the build machine's capabilities.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006557 </para>
6558
6559 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006560 Following are additional factors that can affect build speed:
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006561 <itemizedlist>
6562 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006563 File system type:
6564 The file system type that the build is being performed on can
6565 also influence performance.
6566 Using <filename>ext4</filename> is recommended as compared
6567 to <filename>ext2</filename> and <filename>ext3</filename>
6568 due to <filename>ext4</filename> improved features
6569 such as extents.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006570 </para></listitem>
6571 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006572 Disabling the updating of access time using
6573 <filename>noatime</filename>:
6574 The <filename>noatime</filename> mount option prevents the
6575 build system from updating file and directory access times.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006576 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04006577 <listitem><para>
6578 Setting a longer commit:
6579 Using the "commit=" mount option increases the interval
6580 in seconds between disk cache writes.
6581 Changing this interval from the five second default to
6582 something longer increases the risk of data loss but decreases
6583 the need to write to the disk, thus increasing the build
6584 performance.
6585 </para></listitem>
6586 <listitem><para>
6587 Choosing the packaging backend:
6588 Of the available packaging backends, IPK is the fastest.
6589 Additionally, selecting a singular packaging backend also
6590 helps.
6591 </para></listitem>
6592 <listitem><para>
6593 Using <filename>tmpfs</filename> for
6594 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6595 as a temporary file system:
6596 While this can help speed up the build, the benefits are
6597 limited due to the compiler using
6598 <filename>-pipe</filename>.
6599 The build system goes to some lengths to avoid
6600 <filename>sync()</filename> calls into the
6601 file system on the principle that if there was a significant
6602 failure, the
6603 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
6604 contents could easily be rebuilt.
6605 </para></listitem>
6606 <listitem><para>
6607 Inheriting the
6608 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
6609 class:
6610 Inheriting this class has shown to speed up builds due to
6611 significantly lower amounts of data stored in the data
6612 cache as well as on disk.
6613 Inheriting this class also makes cleanup of
6614 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
6615 faster, at the expense of being easily able to dive into the
6616 source code.
6617 File system maintainers have recommended that the fastest way
6618 to clean up large numbers of files is to reformat partitions
6619 rather than delete files due to the linear nature of
6620 partitions.
6621 This, of course, assumes you structure the disk partitions and
6622 file systems in a way that this is practical.
6623 </para></listitem>
6624 </itemizedlist>
6625 Aside from the previous list, you should keep some trade offs in
6626 mind that can help you speed up the build:
6627 <itemizedlist>
6628 <listitem><para>
6629 Remove items from
6630 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
6631 that you might not need.
6632 </para></listitem>
6633 <listitem><para>
6634 Exclude debug symbols and other debug information:
6635 If you do not need these symbols and other debug information,
6636 disabling the <filename>*-dbg</filename> package generation
6637 can speed up the build.
6638 You can disable this generation by setting the
6639 <ulink url='&YOCTO_DOCS_REF_URL;#var-INHIBIT_PACKAGE_DEBUG_SPLIT'><filename>INHIBIT_PACKAGE_DEBUG_SPLIT</filename></ulink>
6640 variable to "1".
6641 </para></listitem>
6642 <listitem><para>
6643 Disable static library generation for recipes derived from
6644 <filename>autoconf</filename> or <filename>libtool</filename>:
6645 Following is an example showing how to disable static
6646 libraries and still provide an override to handle exceptions:
6647 <literallayout class='monospaced'>
6648 STATICLIBCONF = "--disable-static"
6649 STATICLIBCONF_sqlite3-native = ""
6650 EXTRA_OECONF += "${STATICLIBCONF}"
6651 </literallayout>
6652 <note><title>Notes</title>
6653 <itemizedlist>
6654 <listitem><para>
6655 Some recipes need static libraries in order to work
6656 correctly (e.g. <filename>pseudo-native</filename>
6657 needs <filename>sqlite3-native</filename>).
6658 Overrides, as in the previous example, account for
6659 these kinds of exceptions.
6660 </para></listitem>
6661 <listitem><para>
6662 Some packages have packaging code that assumes the
6663 presence of the static libraries.
6664 If so, you might need to exclude them as well.
6665 </para></listitem>
6666 </itemizedlist>
6667 </note>
6668 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006669 </itemizedlist>
6670 </para>
6671 </section>
6672
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006673 <section id="platdev-working-with-libraries">
6674 <title>Working With Libraries</title>
6675
6676 <para>
6677 Libraries are an integral part of your system.
6678 This section describes some common practices you might find
6679 helpful when working with libraries to build your system:
6680 <itemizedlist>
6681 <listitem><para><link linkend='including-static-library-files'>How to include static library files</link>
6682 </para></listitem>
6683 <listitem><para><link linkend='combining-multiple-versions-library-files-into-one-image'>How to use the Multilib feature to combine multiple versions of library files into a single image</link>
6684 </para></listitem>
6685 <listitem><para><link linkend='installing-multiple-versions-of-the-same-library'>How to install multiple versions of the same library in parallel on the same system</link>
6686 </para></listitem>
6687 </itemizedlist>
6688 </para>
6689
6690 <section id='including-static-library-files'>
6691 <title>Including Static Library Files</title>
6692
6693 <para>
6694 If you are building a library and the library offers static linking, you can control
6695 which static library files (<filename>*.a</filename> files) get included in the
6696 built library.
6697 </para>
6698
6699 <para>
6700 The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6701 and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink>
6702 variables in the
6703 <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed
6704 by the <filename>do_install</filename> task are packaged.
6705 By default, the <filename>PACKAGES</filename> variable includes
6706 <filename>${PN}-staticdev</filename>, which represents all static library files.
6707 <note>
6708 Some previously released versions of the Yocto Project
6709 defined the static library files through
6710 <filename>${PN}-dev</filename>.
6711 </note>
6712 Following is part of the BitBake configuration file, where
6713 you can see how the static library files are defined:
6714 <literallayout class='monospaced'>
6715 PACKAGE_BEFORE_PN ?= ""
6716 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
6717 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
6718 FILES = ""
6719
6720 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
6721 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
6722 ${base_bindir}/* ${base_sbindir}/* \
6723 ${base_libdir}/*${SOLIBS} \
6724 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
6725 ${datadir}/${BPN} ${libdir}/${BPN}/* \
6726 ${datadir}/pixmaps ${datadir}/applications \
6727 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
6728 ${libdir}/bonobo/servers"
6729
6730 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
6731
6732 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
6733 ${datadir}/gnome/help"
6734 SECTION_${PN}-doc = "doc"
6735
6736 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
6737 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
6738 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
6739 ${datadir}/aclocal ${base_libdir}/*.o \
6740 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
6741 SECTION_${PN}-dev = "devel"
6742 ALLOW_EMPTY_${PN}-dev = "1"
6743 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
6744
6745 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
6746 SECTION_${PN}-staticdev = "devel"
6747 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
6748 </literallayout>
6749 </para>
6750 </section>
6751
6752 <section id="combining-multiple-versions-library-files-into-one-image">
6753 <title>Combining Multiple Versions of Library Files into One Image</title>
6754
6755 <para>
6756 The build system offers the ability to build libraries with different
6757 target optimizations or architecture formats and combine these together
6758 into one system image.
6759 You can link different binaries in the image
6760 against the different libraries as needed for specific use cases.
6761 This feature is called "Multilib."
6762 </para>
6763
6764 <para>
6765 An example would be where you have most of a system compiled in 32-bit
6766 mode using 32-bit libraries, but you have something large, like a database
6767 engine, that needs to be a 64-bit application and uses 64-bit libraries.
6768 Multilib allows you to get the best of both 32-bit and 64-bit libraries.
6769 </para>
6770
6771 <para>
6772 While the Multilib feature is most commonly used for 32 and 64-bit differences,
6773 the approach the build system uses facilitates different target optimizations.
6774 You could compile some binaries to use one set of libraries and other binaries
6775 to use a different set of libraries.
6776 The libraries could differ in architecture, compiler options, or other
6777 optimizations.
6778 </para>
6779
6780 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006781 Several examples exist in the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006782 <filename>meta-skeleton</filename> layer found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006783 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006784 <itemizedlist>
6785 <listitem><para><filename>conf/multilib-example.conf</filename>
6786 configuration file</para></listitem>
6787 <listitem><para><filename>conf/multilib-example2.conf</filename>
6788 configuration file</para></listitem>
6789 <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename>
6790 recipe</para></listitem>
6791 </itemizedlist>
6792 </para>
6793
6794 <section id='preparing-to-use-multilib'>
6795 <title>Preparing to Use Multilib</title>
6796
6797 <para>
6798 User-specific requirements drive the Multilib feature.
6799 Consequently, there is no one "out-of-the-box" configuration that likely
6800 exists to meet your needs.
6801 </para>
6802
6803 <para>
6804 In order to enable Multilib, you first need to ensure your recipe is
6805 extended to support multiple libraries.
6806 Many standard recipes are already extended and support multiple libraries.
6807 You can check in the <filename>meta/conf/multilib.conf</filename>
6808 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006809 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006810 done using the
6811 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink>
6812 variable.
6813 Eventually, all recipes will be covered and this list will
6814 not be needed.
6815 </para>
6816
6817 <para>
6818 For the most part, the Multilib class extension works automatically to
6819 extend the package name from <filename>${PN}</filename> to
6820 <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename>
6821 is the particular multilib (e.g. "lib32-" or "lib64-").
6822 Standard variables such as
6823 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>,
6824 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>,
6825 <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>,
6826 <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>,
6827 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and
6828 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink>
6829 are automatically extended by the system.
6830 If you are extending any manual code in the recipe, you can use the
6831 <filename>${MLPREFIX}</filename> variable to ensure those names are extended
6832 correctly.
6833 This automatic extension code resides in <filename>multilib.bbclass</filename>.
6834 </para>
6835 </section>
6836
6837 <section id='using-multilib'>
6838 <title>Using Multilib</title>
6839
6840 <para>
6841 After you have set up the recipes, you need to define the actual
6842 combination of multiple libraries you want to build.
6843 You accomplish this through your <filename>local.conf</filename>
6844 configuration file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006845 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006846 An example configuration would be as follows:
6847 <literallayout class='monospaced'>
6848 MACHINE = "qemux86-64"
6849 require conf/multilib.conf
6850 MULTILIBS = "multilib:lib32"
6851 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006852 IMAGE_INSTALL_append = " lib32-glib-2.0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006853 </literallayout>
6854 This example enables an
6855 additional library named <filename>lib32</filename> alongside the
6856 normal target packages.
6857 When combining these "lib32" alternatives, the example uses "x86" for tuning.
6858 For information on this particular tuning, see
6859 <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>.
6860 </para>
6861
6862 <para>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006863 The example then includes <filename>lib32-glib-2.0</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006864 in all the images, which illustrates one method of including a
6865 multiple library dependency.
6866 You can use a normal image build to include this dependency,
6867 for example:
6868 <literallayout class='monospaced'>
6869 $ bitbake core-image-sato
6870 </literallayout>
6871 You can also build Multilib packages specifically with a command like this:
6872 <literallayout class='monospaced'>
Patrick Williamsf1e5d692016-03-30 15:21:19 -05006873 $ bitbake lib32-glib-2.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006874 </literallayout>
6875 </para>
6876 </section>
6877
6878 <section id='additional-implementation-details'>
6879 <title>Additional Implementation Details</title>
6880
6881 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006882 Generic implementation details as well as details that are
6883 specific to package management systems exist.
6884 Following are implementation details that exist regardless
6885 of the package management system:
6886 <itemizedlist>
6887 <listitem><para>The typical convention used for the
6888 class extension code as used by
6889 Multilib assumes that all package names specified
6890 in
6891 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
6892 that contain <filename>${PN}</filename> have
6893 <filename>${PN}</filename> at the start of the name.
6894 When that convention is not followed and
6895 <filename>${PN}</filename> appears at
6896 the middle or the end of a name, problems occur.
6897 </para></listitem>
6898 <listitem><para>The
6899 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink>
6900 value under Multilib will be extended to
6901 "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>"
6902 (e.g. "-pokymllib32" for a "lib32" Multilib with
6903 Poky).
6904 The reason for this slightly unwieldy contraction
6905 is that any "-" characters in the vendor
6906 string presently break Autoconf's
6907 <filename>config.sub</filename>, and
6908 other separators are problematic for different
6909 reasons.
6910 </para></listitem>
6911 </itemizedlist>
6912 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05006913
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006914 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006915 For the RPM Package Management System, the following implementation details
6916 exist:
6917 <itemizedlist>
6918 <listitem><para>A unique architecture is defined for the Multilib packages,
6919 along with creating a unique deploy folder under
6920 <filename>tmp/deploy/rpm</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006921 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006922 For example, consider <filename>lib32</filename> in a
6923 <filename>qemux86-64</filename> image.
6924 The possible architectures in the system are "all", "qemux86_64",
6925 "lib32_qemux86_64", and "lib32_x86".</para></listitem>
6926 <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from
6927 <filename>${PN}</filename> during RPM packaging.
6928 The naming for a normal RPM package and a Multilib RPM package in a
6929 <filename>qemux86-64</filename> system resolves to something similar to
6930 <filename>bash-4.1-r2.x86_64.rpm</filename> and
6931 <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively.
6932 </para></listitem>
6933 <listitem><para>When installing a Multilib image, the RPM backend first
6934 installs the base image and then installs the Multilib libraries.
6935 </para></listitem>
6936 <listitem><para>The build system relies on RPM to resolve the identical files in the
6937 two (or more) Multilib packages.</para></listitem>
6938 </itemizedlist>
6939 </para>
6940
6941 <para>
6942 For the IPK Package Management System, the following implementation details exist:
6943 <itemizedlist>
6944 <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from
6945 <filename>${PN}</filename> during IPK packaging.
6946 The naming for a normal RPM package and a Multilib IPK package in a
6947 <filename>qemux86-64</filename> system resolves to something like
6948 <filename>bash_4.1-r2.x86_64.ipk</filename> and
6949 <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively.
6950 </para></listitem>
6951 <listitem><para>The IPK deploy folder is not modified with
6952 <filename>${MLPREFIX}</filename> because packages with and without
6953 the Multilib feature can exist in the same folder due to the
6954 <filename>${PN}</filename> differences.</para></listitem>
6955 <listitem><para>IPK defines a sanity check for Multilib installation
6956 using certain rules for file comparison, overridden, etc.
6957 </para></listitem>
6958 </itemizedlist>
6959 </para>
6960 </section>
6961 </section>
6962
6963 <section id='installing-multiple-versions-of-the-same-library'>
6964 <title>Installing Multiple Versions of the Same Library</title>
6965
6966 <para>
6967 Situations can exist where you need to install and use
6968 multiple versions of the same library on the same system
6969 at the same time.
6970 These situations almost always exist when a library API
6971 changes and you have multiple pieces of software that
6972 depend on the separate versions of the library.
6973 To accommodate these situations, you can install multiple
6974 versions of the same library in parallel on the same system.
6975 </para>
6976
6977 <para>
6978 The process is straightforward as long as the libraries use
6979 proper versioning.
6980 With properly versioned libraries, all you need to do to
6981 individually specify the libraries is create separate,
6982 appropriately named recipes where the
6983 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the
6984 name includes a portion that differentiates each library version
6985 (e.g.the major part of the version number).
6986 Thus, instead of having a single recipe that loads one version
6987 of a library (e.g. <filename>clutter</filename>), you provide
6988 multiple recipes that result in different versions
6989 of the libraries you want.
6990 As an example, the following two recipes would allow the
6991 two separate versions of the <filename>clutter</filename>
6992 library to co-exist on the same system:
6993 <literallayout class='monospaced'>
6994 clutter-1.6_1.6.20.bb
6995 clutter-1.8_1.8.4.bb
6996 </literallayout>
6997 Additionally, if you have other recipes that depend on a given
6998 library, you need to use the
6999 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
7000 variable to create the dependency.
7001 Continuing with the same example, if you want to have a recipe
7002 depend on the 1.8 version of the <filename>clutter</filename>
7003 library, use the following in your recipe:
7004 <literallayout class='monospaced'>
7005 DEPENDS = "clutter-1.8"
7006 </literallayout>
7007 </para>
7008 </section>
7009 </section>
7010
Brad Bishop316dfdd2018-06-25 12:45:53 -04007011 <section id='using-x32-psabi'>
7012 <title>Using x32 psABI</title>
7013
7014 <para>
7015 x32 processor-specific Application Binary Interface
7016 (<ulink url='https://software.intel.com/en-us/node/628948'>x32 psABI</ulink>)
7017 is a native 32-bit processor-specific ABI for
7018 <trademark class='registered'>Intel</trademark> 64 (x86-64)
7019 architectures.
7020 An ABI defines the calling conventions between functions in a
7021 processing environment.
7022 The interface determines what registers are used and what the
7023 sizes are for various C data types.
7024 </para>
7025
7026 <para>
7027 Some processing environments prefer using 32-bit applications even
7028 when running on Intel 64-bit platforms.
7029 Consider the i386 psABI, which is a very old 32-bit ABI for Intel
7030 64-bit platforms.
7031 The i386 psABI does not provide efficient use and access of the
7032 Intel 64-bit processor resources, leaving the system underutilized.
7033 Now consider the x86_64 psABI.
7034 This ABI is newer and uses 64-bits for data sizes and program
7035 pointers.
7036 The extra bits increase the footprint size of the programs,
7037 libraries, and also increases the memory and file system size
7038 requirements.
7039 Executing under the x32 psABI enables user programs to utilize CPU
7040 and system resources more efficiently while keeping the memory
7041 footprint of the applications low.
7042 Extra bits are used for registers but not for addressing mechanisms.
7043 </para>
7044
7045 <para>
7046 The Yocto Project supports the final specifications of x32 psABI
7047 as follows:
7048 <itemizedlist>
7049 <listitem><para>
7050 You can create packages and images in x32 psABI format on
7051 x86_64 architecture targets.
7052 </para></listitem>
7053 <listitem><para>
7054 You can successfully build recipes with the x32 toolchain.
7055 </para></listitem>
7056 <listitem><para>
7057 You can create and boot
7058 <filename>core-image-minimal</filename> and
7059 <filename>core-image-sato</filename> images.
7060 </para></listitem>
7061 <listitem><para>
7062 RPM Package Manager (RPM) support exists for x32 binaries.
7063 </para></listitem>
7064 <listitem><para>
7065 Support for large images exists.
7066 </para></listitem>
7067 </itemizedlist>
7068 </para>
7069
7070 <para>
7071 To use the x32 psABI, you need to edit your
7072 <filename>conf/local.conf</filename> configuration file as
7073 follows:
7074 <literallayout class='monospaced'>
7075 MACHINE = "qemux86-64"
7076 DEFAULTTUNE = "x86-64-x32"
Brad Bishop19323692019-04-05 15:28:33 -04007077 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
7078 or 'INVALID')) or 'lib'}"
Brad Bishop316dfdd2018-06-25 12:45:53 -04007079 </literallayout>
7080 Once you have set up your configuration file, use BitBake to
7081 build an image that supports the x32 psABI.
7082 Here is an example:
7083 <literallayout class='monospaced'>
7084 $ bitbake core-image-sato
7085 </literallayout>
7086 </para>
7087 </section>
7088
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007089 <section id='enabling-gobject-introspection-support'>
7090 <title>Enabling GObject Introspection Support</title>
7091
7092 <para>
7093 <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink>
7094 is the standard mechanism for accessing GObject-based software
7095 from runtime environments.
7096 GObject is a feature of the GLib library that provides an object
7097 framework for the GNOME desktop and related software.
7098 GObject Introspection adds information to GObject that allows
7099 objects created within it to be represented across different
7100 programming languages.
7101 If you want to construct GStreamer pipelines using Python, or
7102 control UPnP infrastructure using Javascript and GUPnP,
7103 GObject introspection is the only way to do it.
7104 </para>
7105
7106 <para>
7107 This section describes the Yocto Project support for generating
7108 and packaging GObject introspection data.
7109 GObject introspection data is a description of the
7110 API provided by libraries built on top of GLib framework,
7111 and, in particular, that framework's GObject mechanism.
7112 GObject Introspection Repository (GIR) files go to
7113 <filename>-dev</filename> packages,
7114 <filename>typelib</filename> files go to main packages as they
7115 are packaged together with libraries that are introspected.
7116 </para>
7117
7118 <para>
7119 The data is generated when building such a library, by linking
7120 the library with a small executable binary that asks the library
7121 to describe itself, and then executing the binary and
7122 processing its output.
7123 </para>
7124
7125 <para>
7126 Generating this data in a cross-compilation environment
7127 is difficult because the library is produced for the target
7128 architecture, but its code needs to be executed on the build host.
7129 This problem is solved with the OpenEmbedded build system by
7130 running the code through QEMU, which allows precisely that.
7131 Unfortunately, QEMU does not always work perfectly as mentioned
Brad Bishop96ff1982019-08-19 13:50:42 -04007132 in the
7133 "<link linkend='known-issues'>Known Issues</link>" section.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007134 </para>
7135
7136 <section id='enabling-the-generation-of-introspection-data'>
7137 <title>Enabling the Generation of Introspection Data</title>
7138
7139 <para>
7140 Enabling the generation of introspection data (GIR files)
7141 in your library package involves the following:
7142 <orderedlist>
7143 <listitem><para>
7144 Inherit the
7145 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink>
7146 class.
7147 </para></listitem>
7148 <listitem><para>
7149 Make sure introspection is not disabled anywhere in
7150 the recipe or from anything the recipe includes.
7151 Also, make sure that "gobject-introspection-data" is
7152 not in
7153 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7154 and that "qemu-usermode" is not in
7155 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7156 If either of these conditions exist, nothing will
7157 happen.
7158 </para></listitem>
7159 <listitem><para>
7160 Try to build the recipe.
7161 If you encounter build errors that look like
7162 something is unable to find
7163 <filename>.so</filename> libraries, check where these
7164 libraries are located in the source tree and add
7165 the following to the recipe:
7166 <literallayout class='monospaced'>
7167 GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs"
7168 </literallayout>
7169 <note>
7170 See recipes in the <filename>oe-core</filename>
7171 repository that use that
7172 <filename>GIR_EXTRA_LIBS_PATH</filename> variable
7173 as an example.
7174 </note>
7175 </para></listitem>
7176 <listitem><para>
7177 Look for any other errors, which probably mean that
7178 introspection support in a package is not entirely
7179 standard, and thus breaks down in a cross-compilation
7180 environment.
7181 For such cases, custom-made fixes are needed.
7182 A good place to ask and receive help in these cases
7183 is the
7184 <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>.
7185 </para></listitem>
7186 </orderedlist>
7187 <note>
7188 Using a library that no longer builds against the latest
7189 Yocto Project release and prints introspection related
7190 errors is a good candidate for the previous procedure.
7191 </note>
7192 </para>
7193 </section>
7194
7195 <section id='disabling-the-generation-of-introspection-data'>
7196 <title>Disabling the Generation of Introspection Data</title>
7197
7198 <para>
7199 You might find that you do not want to generate
7200 introspection data.
7201 Or, perhaps QEMU does not work on your build host and
7202 target architecture combination.
7203 If so, you can use either of the following methods to
7204 disable GIR file generations:
7205 <itemizedlist>
7206 <listitem><para>
7207 Add the following to your distro configuration:
7208 <literallayout class='monospaced'>
7209 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
7210 </literallayout>
7211 Adding this statement disables generating
7212 introspection data using QEMU but will still enable
7213 building introspection tools and libraries
7214 (i.e. building them does not require the use of QEMU).
7215 </para></listitem>
7216 <listitem><para>
7217 Add the following to your machine configuration:
7218 <literallayout class='monospaced'>
7219 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
7220 </literallayout>
7221 Adding this statement disables the use of QEMU
7222 when building packages for your machine.
7223 Currently, this feature is used only by introspection
7224 recipes and has the same effect as the previously
7225 described option.
7226 <note>
7227 Future releases of the Yocto Project might have
7228 other features affected by this option.
7229 </note>
7230 </para></listitem>
7231 </itemizedlist>
7232 If you disable introspection data, you can still
7233 obtain it through other means such as copying the data
7234 from a suitable sysroot, or by generating it on the
7235 target hardware.
7236 The OpenEmbedded build system does not currently
7237 provide specific support for these techniques.
7238 </para>
7239 </section>
7240
7241 <section id='testing-that-introspection-works-in-an-image'>
7242 <title>Testing that Introspection Works in an Image</title>
7243
7244 <para>
7245 Use the following procedure to test if generating
7246 introspection data is working in an image:
7247 <orderedlist>
7248 <listitem><para>
7249 Make sure that "gobject-introspection-data" is not in
7250 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>
7251 and that "qemu-usermode" is not in
7252 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
7253 </para></listitem>
7254 <listitem><para>
7255 Build <filename>core-image-sato</filename>.
7256 </para></listitem>
7257 <listitem><para>
7258 Launch a Terminal and then start Python in the
7259 terminal.
7260 </para></listitem>
7261 <listitem><para>
7262 Enter the following in the terminal:
7263 <literallayout class='monospaced'>
7264 >>> from gi.repository import GLib
7265 >>> GLib.get_host_name()
7266 </literallayout>
7267 </para></listitem>
7268 <listitem><para>
7269 For something a little more advanced, enter the
7270 following:
7271 <literallayout class='monospaced'>
7272 http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html
7273 </literallayout>
7274 </para></listitem>
7275 </orderedlist>
7276 </para>
7277 </section>
7278
7279 <section id='known-issues'>
7280 <title>Known Issues</title>
7281
7282 <para>
7283 The following know issues exist for
7284 GObject Introspection Support:
7285 <itemizedlist>
7286 <listitem><para>
7287 <filename>qemu-ppc64</filename> immediately crashes.
7288 Consequently, you cannot build introspection data on
7289 that architecture.
7290 </para></listitem>
7291 <listitem><para>
7292 x32 is not supported by QEMU.
7293 Consequently, introspection data is disabled.
7294 </para></listitem>
7295 <listitem><para>
7296 musl causes transient GLib binaries to crash on
7297 assertion failures.
7298 Consequently, generating introspection data is
7299 disabled.
7300 </para></listitem>
7301 <listitem><para>
7302 Because QEMU is not able to run the binaries correctly,
7303 introspection is disabled for some specific packages
7304 under specific architectures (e.g.
7305 <filename>gcr</filename>,
7306 <filename>libsecret</filename>, and
7307 <filename>webkit</filename>).
7308 </para></listitem>
7309 <listitem><para>
7310 QEMU usermode might not work properly when running
7311 64-bit binaries under 32-bit host machines.
7312 In particular, "qemumips64" is known to not work under
7313 i686.
7314 </para></listitem>
7315 </itemizedlist>
7316 </para>
7317 </section>
7318 </section>
7319
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007320 <section id='dev-optionally-using-an-external-toolchain'>
7321 <title>Optionally Using an External Toolchain</title>
7322
7323 <para>
7324 You might want to use an external toolchain as part of your
7325 development.
7326 If this is the case, the fundamental steps you need to accomplish
7327 are as follows:
7328 <itemizedlist>
7329 <listitem><para>
7330 Understand where the installed toolchain resides.
7331 For cases where you need to build the external toolchain,
7332 you would need to take separate steps to build and install
7333 the toolchain.
7334 </para></listitem>
7335 <listitem><para>
7336 Make sure you add the layer that contains the toolchain to
7337 your <filename>bblayers.conf</filename> file through the
7338 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
7339 variable.
7340 </para></listitem>
7341 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007342 Set the <filename>EXTERNAL_TOOLCHAIN</filename>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007343 variable in your <filename>local.conf</filename> file
7344 to the location in which you installed the toolchain.
7345 </para></listitem>
7346 </itemizedlist>
7347 A good example of an external toolchain used with the Yocto Project
7348 is <trademark class='registered'>Mentor Graphics</trademark>
7349 Sourcery G++ Toolchain.
7350 You can see information on how to use that particular layer in the
7351 <filename>README</filename> file at
7352 <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>.
7353 You can find further information by reading about the
7354 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink>
7355 variable in the Yocto Project Reference Manual's variable glossary.
7356 </para>
7357 </section>
7358
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007359 <section id='creating-partitioned-images-using-wic'>
7360 <title>Creating Partitioned Images Using Wic</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007361
7362 <para>
7363 Creating an image for a particular hardware target using the
7364 OpenEmbedded build system does not necessarily mean you can boot
7365 that image as is on your device.
7366 Physical devices accept and boot images in various ways depending
7367 on the specifics of the device.
7368 Usually, information about the hardware can tell you what image
7369 format the device requires.
7370 Should your device require multiple partitions on an SD card, flash,
7371 or an HDD, you can use the OpenEmbedded Image Creator,
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007372 Wic, to create the properly partitioned image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007373 </para>
7374
7375 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007376 The <filename>wic</filename> command generates partitioned
7377 images from existing OpenEmbedded build artifacts.
7378 Image generation is driven by partitioning commands
7379 contained in an Openembedded kickstart file
7380 (<filename>.wks</filename>) specified either directly on
7381 the command line or as one of a selection of canned
7382 kickstart files as shown with the
7383 <filename>wic list images</filename> command in the
7384 "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>"
7385 section.
7386 When you apply the command to a given set of build
7387 artifacts, the result is an image or set of images that
7388 can be directly written onto media and used on a particular
7389 system.
7390 <note>
7391 For a kickstart file reference, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007392 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-kickstart'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007393 Chapter in the Yocto Project Reference Manual.
7394 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007395 </para>
7396
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007397 <para>
7398 The <filename>wic</filename> command and the infrastructure
7399 it is based on is by definition incomplete.
7400 The purpose of the command is to allow the generation of
7401 customized images, and as such, was designed to be
Brad Bishopc342db32019-05-15 21:57:59 -04007402 completely extensible through a plugin interface.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007403 See the
Brad Bishopc342db32019-05-15 21:57:59 -04007404 "<link linkend='wic-using-the-wic-plugin-interface'>Using the Wic PlugIn Interface</link>"
7405 section for information on these plugins.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007406 </para>
7407
7408 <para>
7409 This section provides some background information on Wic,
7410 describes what you need to have in
7411 place to run the tool, provides instruction on how to use
Brad Bishopc342db32019-05-15 21:57:59 -04007412 the Wic utility, provides information on using the Wic plugins
Brad Bishop316dfdd2018-06-25 12:45:53 -04007413 interface, and provides several examples that show how to use
7414 Wic.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007415 </para>
7416
7417 <section id='wic-background'>
7418 <title>Background</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007419
7420 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007421 This section provides some background on the Wic utility.
7422 While none of this information is required to use
7423 Wic, you might find it interesting.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007424 <itemizedlist>
7425 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007426 The name "Wic" is derived from OpenEmbedded
7427 Image Creator (oeic).
7428 The "oe" diphthong in "oeic" was promoted to the
7429 letter "w", because "oeic" is both difficult to
7430 remember and to pronounce.
7431 </para></listitem>
7432 <listitem><para>
7433 Wic is loosely based on the
7434 Meego Image Creator (<filename>mic</filename>)
7435 framework.
7436 The Wic implementation has been
7437 heavily modified to make direct use of OpenEmbedded
7438 build artifacts instead of package installation and
7439 configuration, which are already incorporated within
7440 the OpenEmbedded artifacts.
7441 </para></listitem>
7442 <listitem><para>
7443 Wic is a completely independent
7444 standalone utility that initially provides
7445 easier-to-use and more flexible replacements for an
Brad Bishop316dfdd2018-06-25 12:45:53 -04007446 existing functionality in OE-Core's
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007447 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007448 class.
7449 The difference between Wic and those examples is
7450 that with Wic the functionality of those scripts is
7451 implemented by a general-purpose partitioning language,
7452 which is based on Redhat kickstart syntax.
7453 </para></listitem>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007454 </itemizedlist>
7455 </para>
7456 </section>
7457
7458 <section id='wic-requirements'>
7459 <title>Requirements</title>
7460
7461 <para>
7462 In order to use the Wic utility with the OpenEmbedded Build
7463 system, your system needs to meet the following
7464 requirements:
7465 <itemizedlist>
7466 <listitem><para>
7467 The Linux distribution on your development host must
7468 support the Yocto Project.
7469 See the
7470 "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>"
7471 section in the Yocto Project Reference Manual for
7472 the list of distributions that support the
7473 Yocto Project.
7474 </para></listitem>
7475 <listitem><para>
7476 The standard system utilities, such as
7477 <filename>cp</filename>, must be installed on your
7478 development host system.
7479 </para></listitem>
7480 <listitem><para>
7481 You must have sourced the build environment
7482 setup script (i.e.
7483 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>)
7484 found in the
7485 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7486 </para></listitem>
7487 <listitem><para>
7488 You need to have the build artifacts already
7489 available, which typically means that you must
7490 have already created an image using the
7491 Openembedded build system (e.g.
7492 <filename>core-image-minimal</filename>).
7493 While it might seem redundant to generate an image
7494 in order to create an image using
7495 Wic, the current version of
7496 Wic requires the artifacts
7497 in the form generated by the OpenEmbedded build
7498 system.
7499 </para></listitem>
7500 <listitem><para>
7501 You must build several native tools, which are
7502 built to run on the build system:
7503 <literallayout class='monospaced'>
7504 $ bitbake parted-native dosfstools-native mtools-native
7505 </literallayout>
7506 </para></listitem>
7507 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007508 Include "wic" as part of the
7509 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
7510 variable.
7511 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007512 <listitem><para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007513 Include the name of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007514 <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007515 as part of the
7516 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink>
7517 variable
7518 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007519 </itemizedlist>
7520 </para>
7521 </section>
7522
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007523 <section id='wic-getting-help'>
7524 <title>Getting Help</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007525
7526 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007527 You can get general help for the <filename>wic</filename>
7528 command by entering the <filename>wic</filename> command
7529 by itself or by entering the command with a help argument
7530 as follows:
7531 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007532 $ wic -h
7533 $ wic --help
Brad Bishop316dfdd2018-06-25 12:45:53 -04007534 $ wic help
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007535 </literallayout>
7536 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007537
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007538 <para>
7539 Currently, Wic supports seven commands:
7540 <filename>cp</filename>, <filename>create</filename>,
7541 <filename>help</filename>, <filename>list</filename>,
7542 <filename>ls</filename>, <filename>rm</filename>, and
7543 <filename>write</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007544 You can get help for all these commands except "help" by
7545 using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007546 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007547 $ wic help <replaceable>command</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007548 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007549 For example, the following command returns help for the
7550 <filename>write</filename> command:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007551 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007552 $ wic help write
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007553 </literallayout>
7554 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007555
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007556 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007557 Wic supports help for three topics:
7558 <filename>overview</filename>,
7559 <filename>plugins</filename>, and
7560 <filename>kickstart</filename>.
7561 You can get help for any topic using the following form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007562 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007563 $ wic help <replaceable>topic</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007564 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007565 For example, the following returns overview help for Wic:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007566 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007567 $ wic help overview
7568 </literallayout>
7569 </para>
7570
7571 <para>
7572 One additional level of help exists for Wic.
7573 You can get help on individual images through the
7574 <filename>list</filename> command.
7575 You can use the <filename>list</filename> command to return the
7576 available Wic images as follows:
7577 <literallayout class='monospaced'>
7578 $ wic list images
7579 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7580 genericx86 Create an EFI disk image for genericx86*
7581 beaglebone-yocto Create SD card image for Beaglebone
7582 edgerouter Create SD card image for Edgerouter
7583 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7584 directdisk-gpt Create a 'pcbios' direct disk image
7585 mkefidisk Create an EFI disk image
7586 directdisk Create a 'pcbios' direct disk image
7587 systemd-bootdisk Create an EFI disk image with systemd-boot
7588 mkhybridiso Create a hybrid ISO image
7589 sdimage-bootpart Create SD card image with a boot partition
7590 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7591 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7592 </literallayout>
7593 Once you know the list of available Wic images, you can use
7594 <filename>help</filename> with the command to get help on a
7595 particular image.
7596 For example, the following command returns help on the
7597 "beaglebone-yocto" image:
7598 <literallayout class='monospaced'>
7599 $ wic list beaglebone-yocto help
7600
7601
7602 Creates a partitioned SD card image for Beaglebone.
7603 Boot files are located in the first vfat partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007604 </literallayout>
7605 </para>
7606 </section>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007607
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007608 <section id='operational-modes'>
7609 <title>Operational Modes</title>
7610
7611 <para>
7612 You can use Wic in two different
7613 modes, depending on how much control you need for
7614 specifying the Openembedded build artifacts that are
7615 used for creating the image: Raw and Cooked:
7616 <itemizedlist>
7617 <listitem><para>
7618 <emphasis>Raw Mode:</emphasis>
7619 You explicitly specify build artifacts through
Brad Bishop316dfdd2018-06-25 12:45:53 -04007620 Wic command-line arguments.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007621 </para></listitem>
7622 <listitem><para>
7623 <emphasis>Cooked Mode:</emphasis>
7624 The current
7625 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
7626 setting and image name are used to automatically
7627 locate and provide the build artifacts.
7628 You just supply a kickstart file and the name
7629 of the image from which to use artifacts.
7630 </para></listitem>
7631 </itemizedlist>
7632 </para>
7633
7634 <para>
7635 Regardless of the mode you use, you need to have the build
7636 artifacts ready and available.
7637 </para>
7638
7639 <section id='raw-mode'>
7640 <title>Raw Mode</title>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007641
7642 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007643 Running Wic in raw mode allows you to specify all the
7644 partitions through the <filename>wic</filename>
7645 command line.
7646 The primary use for raw mode is if you have built
7647 your kernel outside of the Yocto Project
7648 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
7649 In other words, you can point to arbitrary kernel,
7650 root filesystem locations, and so forth.
7651 Contrast this behavior with cooked mode where Wic
7652 looks in the Build Directory (e.g.
7653 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>).
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007654 </para>
7655
7656 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007657 The general form of the
7658 <filename>wic</filename> command in raw mode is:
7659 <literallayout class='monospaced'>
7660 $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007661
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007662 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007663
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007664 <replaceable>wks_file</replaceable>:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007665 An OpenEmbedded kickstart file. You can provide
7666 your own custom file or use a file from a set of
7667 existing files as described by further options.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007668
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007669 optional arguments:
7670 -h, --help show this help message and exit
7671 -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable>
7672 name of directory to create image in
7673 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7674 name of the image to use the artifacts from e.g. core-
7675 image-sato
7676 -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable>
7677 path to the /rootfs dir to use as the .wks rootfs
7678 source
7679 -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable>
7680 path to the dir containing the boot artifacts (e.g.
7681 /EFI or /syslinux dirs) to use as the .wks bootimg
7682 source
7683 -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable>
7684 path to the dir containing the kernel to use in the
7685 .wks bootimg
7686 -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable>
7687 path to the native sysroot containing the tools to use
7688 to build the image
7689 -s, --skip-build-check
7690 skip the build check
7691 -f, --build-rootfs build rootfs
7692 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
7693 compress image with specified compressor
7694 -m, --bmap generate .bmap
7695 --no-fstab-update Do not change fstab file.
7696 -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable>
7697 directory with &lt;image&gt;.env files that store bitbake
7698 variables
7699 -D, --debug output debug information
7700 </literallayout>
7701 <note>
7702 You do not need root privileges to run
7703 Wic.
7704 In fact, you should not run as root when using the
7705 utility.
7706 </note>
7707 </para>
7708 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007709
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007710 <section id='cooked-mode'>
7711 <title>Cooked Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007712
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007713 <para>
7714 Running Wic in cooked mode leverages off artifacts in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007715 the Build Directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007716 In other words, you do not have to specify kernel or
7717 root filesystem locations as part of the command.
7718 All you need to provide is a kickstart file and the
7719 name of the image from which to use artifacts by using
7720 the "-e" option.
7721 Wic looks in the Build Directory (e.g.
7722 <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>)
7723 for artifacts.
7724 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007725
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007726 <para>
7727 The general form of the <filename>wic</filename>
7728 command using Cooked Mode is as follows:
7729 <literallayout class='monospaced'>
7730 $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007731
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007732 Where:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007733
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007734 <replaceable>wks_file</replaceable>:
7735 An OpenEmbedded kickstart file. You can provide
7736 your own custom file or use a file from a set of
7737 existing files provided with the Yocto Project
7738 release.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007739
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007740 required argument:
7741 -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable>
7742 name of the image to use the artifacts from e.g. core-
7743 image-sato
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007744 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007745 </para>
7746 </section>
7747 </section>
7748
7749 <section id='using-a-provided-kickstart-file'>
7750 <title>Using an Existing Kickstart File</title>
7751
7752 <para>
7753 If you do not want to create your own kickstart file, you
7754 can use an existing file provided by the Wic installation.
7755 As shipped, kickstart files can be found in the
7756 Yocto Project
Brad Bishop316dfdd2018-06-25 12:45:53 -04007757 <ulink url='&YOCTO_DOCS_OM_URL;#source-repositories'>Source Repositories</ulink>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007758 in the following two locations:
7759 <literallayout class='monospaced'>
7760 poky/meta-yocto-bsp/wic
7761 poky/scripts/lib/wic/canned-wks
7762 </literallayout>
7763 Use the following command to list the available kickstart
7764 files:
7765 <literallayout class='monospaced'>
7766 $ wic list images
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007767 mpc8315e-rdb Create SD card image for MPC8315E-RDB
7768 genericx86 Create an EFI disk image for genericx86*
Brad Bishop316dfdd2018-06-25 12:45:53 -04007769 beaglebone-yocto Create SD card image for Beaglebone
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007770 edgerouter Create SD card image for Edgerouter
7771 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
7772 directdisk-gpt Create a 'pcbios' direct disk image
7773 mkefidisk Create an EFI disk image
7774 directdisk Create a 'pcbios' direct disk image
7775 systemd-bootdisk Create an EFI disk image with systemd-boot
7776 mkhybridiso Create a hybrid ISO image
7777 sdimage-bootpart Create SD card image with a boot partition
7778 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
7779 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
7780 </literallayout>
7781 When you use an existing file, you do not have to use the
7782 <filename>.wks</filename> extension.
7783 Here is an example in Raw Mode that uses the
7784 <filename>directdisk</filename> file:
7785 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007786 $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \
7787 -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007788 </literallayout>
7789 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007790
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007791 <para>
7792 Here are the actual partition language commands
7793 used in the <filename>genericx86.wks</filename> file to
7794 generate an image:
7795 <literallayout class='monospaced'>
7796 # short-description: Create an EFI disk image for genericx86*
7797 # long-description: Creates a partitioned EFI disk image for genericx86* machines
7798 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
7799 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007800 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
7801
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007802 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
7803 </literallayout>
7804 </para>
7805 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007806
Brad Bishopc342db32019-05-15 21:57:59 -04007807 <section id='wic-using-the-wic-plugin-interface'>
7808 <title>Using the Wic Plugin Interface</title>
Brad Bishop316dfdd2018-06-25 12:45:53 -04007809
7810 <para>
7811 You can extend and specialize Wic functionality by using
Brad Bishopc342db32019-05-15 21:57:59 -04007812 Wic plugins.
7813 This section explains the Wic plugin interface.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007814 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007815 Wic plugins consist of "source" and "imager" plugins.
7816 Imager plugins are beyond the scope of this section.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007817 </note>
7818 </para>
7819
7820 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007821 Source plugins provide a mechanism to customize partition
Brad Bishop316dfdd2018-06-25 12:45:53 -04007822 content during the Wic image generation process.
Brad Bishopc342db32019-05-15 21:57:59 -04007823 You can use source plugins to map values that you specify
Brad Bishop316dfdd2018-06-25 12:45:53 -04007824 using <filename>--source</filename> commands in kickstart
Brad Bishopc342db32019-05-15 21:57:59 -04007825 files (i.e. <filename>*.wks</filename>) to a plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007826 implementation used to populate a given partition.
7827 <note>
Brad Bishopc342db32019-05-15 21:57:59 -04007828 If you use plugins that have build-time dependencies
Brad Bishop316dfdd2018-06-25 12:45:53 -04007829 (e.g. native tools, bootloaders, and so forth)
7830 when building a Wic image, you need to specify those
7831 dependencies using the
7832 <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></ulink>
7833 variable.
7834 </note>
7835 </para>
7836
7837 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007838 Source plugins are subclasses defined in plugin files.
7839 As shipped, the Yocto Project provides several plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007840 files.
Brad Bishopc342db32019-05-15 21:57:59 -04007841 You can see the source plugin files that ship with the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007842 Yocto Project
7843 <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
Brad Bishopc342db32019-05-15 21:57:59 -04007844 Each of these plugin files contains source plugins that
Brad Bishop316dfdd2018-06-25 12:45:53 -04007845 are designed to populate a specific Wic image partition.
7846 </para>
7847
7848 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007849 Source plugins are subclasses of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007850 <filename>SourcePlugin</filename> class, which is
7851 defined in the
7852 <filename>poky/scripts/lib/wic/pluginbase.py</filename>
7853 file.
7854 For example, the <filename>BootimgEFIPlugin</filename>
Brad Bishopc342db32019-05-15 21:57:59 -04007855 source plugin found in the
Brad Bishop316dfdd2018-06-25 12:45:53 -04007856 <filename>bootimg-efi.py</filename> file is a subclass of
7857 the <filename>SourcePlugin</filename> class, which is found
7858 in the <filename>pluginbase.py</filename> file.
7859 </para>
7860
7861 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007862 You can also implement source plugins in a layer outside
Brad Bishop316dfdd2018-06-25 12:45:53 -04007863 of the Source Repositories (external layer).
Brad Bishopc342db32019-05-15 21:57:59 -04007864 To do so, be sure that your plugin files are located in
Brad Bishop316dfdd2018-06-25 12:45:53 -04007865 a directory whose path is
7866 <filename>scripts/lib/wic/plugins/source/</filename>
7867 within your external layer.
Brad Bishopc342db32019-05-15 21:57:59 -04007868 When the plugin files are located there, the source
7869 plugins they contain are made available to Wic.
Brad Bishop316dfdd2018-06-25 12:45:53 -04007870 </para>
7871
7872 <para>
7873 When the Wic implementation needs to invoke a
Brad Bishopc342db32019-05-15 21:57:59 -04007874 partition-specific implementation, it looks for the plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007875 with the same name as the <filename>--source</filename>
7876 parameter used in the kickstart file given to that
7877 partition.
7878 For example, if the partition is set up using the following
7879 command in a kickstart file:
7880 <literallayout class='monospaced'>
7881 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7882 </literallayout>
7883 The methods defined as class members of the matching
Brad Bishopc342db32019-05-15 21:57:59 -04007884 source plugin (i.e. <filename>bootimg-pcbios</filename>)
7885 in the <filename>bootimg-pcbios.py</filename> plugin file
Brad Bishop316dfdd2018-06-25 12:45:53 -04007886 are used.
7887 </para>
7888
7889 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007890 To be more concrete, here is the corresponding plugin
Brad Bishop316dfdd2018-06-25 12:45:53 -04007891 definition from the <filename>bootimg-pcbios.py</filename>
7892 file for the previous command along with an example
7893 method called by the Wic implementation when it needs to
7894 prepare a partition using an implementation-specific
7895 function:
7896 <literallayout class='monospaced'>
7897 .
7898 .
7899 .
7900 class BootimgPcbiosPlugin(SourcePlugin):
7901 """
7902 Create MBR boot partition and install syslinux on it.
7903 """
7904
7905 name = 'bootimg-pcbios'
7906 .
7907 .
7908 .
7909 @classmethod
7910 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
7911 oe_builddir, bootimg_dir, kernel_dir,
7912 rootfs_dir, native_sysroot):
7913 """
7914 Called to do the actual content population for a partition i.e. it
7915 'prepares' the partition to be incorporated into the image.
7916 In this case, prepare content for legacy bios boot partition.
7917 """
7918 .
7919 .
7920 .
7921 </literallayout>
Brad Bishopc342db32019-05-15 21:57:59 -04007922 If a subclass (plugin) itself does not implement a
Brad Bishop316dfdd2018-06-25 12:45:53 -04007923 particular function, Wic locates and uses the default
7924 version in the superclass.
Brad Bishopc342db32019-05-15 21:57:59 -04007925 It is for this reason that all source plugins are derived
Brad Bishop316dfdd2018-06-25 12:45:53 -04007926 from the <filename>SourcePlugin</filename> class.
7927 </para>
7928
7929 <para>
7930 The <filename>SourcePlugin</filename> class defined in
7931 the <filename>pluginbase.py</filename> file defines
Brad Bishopc342db32019-05-15 21:57:59 -04007932 a set of methods that source plugins can implement or
Brad Bishop316dfdd2018-06-25 12:45:53 -04007933 override.
Brad Bishopc342db32019-05-15 21:57:59 -04007934 Any plugins (subclass of
Brad Bishop316dfdd2018-06-25 12:45:53 -04007935 <filename>SourcePlugin</filename>) that do not implement
7936 a particular method inherit the implementation of the
7937 method from the <filename>SourcePlugin</filename> class.
7938 For more information, see the
7939 <filename>SourcePlugin</filename> class in the
7940 <filename>pluginbase.py</filename> file for details:
7941 </para>
7942
7943 <para>
7944 The following list describes the methods implemented in the
7945 <filename>SourcePlugin</filename> class:
7946 <itemizedlist>
7947 <listitem><para>
7948 <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
7949 Called to populate a partition with actual content.
7950 In other words, the method prepares the final
7951 partition image that is incorporated into the
7952 disk image.
7953 </para></listitem>
7954 <listitem><para>
7955 <emphasis><filename>do_configure_partition()</filename>:</emphasis>
7956 Called before
7957 <filename>do_prepare_partition()</filename> to
7958 create custom configuration files for a partition
7959 (e.g. syslinux or grub configuration files).
7960 </para></listitem>
7961 <listitem><para>
7962 <emphasis><filename>do_install_disk()</filename>:</emphasis>
7963 Called after all partitions have been prepared and
7964 assembled into a disk image.
7965 This method provides a hook to allow finalization
7966 of a disk image (e.g. writing an MBR).
7967 </para></listitem>
7968 <listitem><para>
7969 <emphasis><filename>do_stage_partition()</filename>:</emphasis>
7970 Special content-staging hook called before
7971 <filename>do_prepare_partition()</filename>.
7972 This method is normally empty.</para>
7973
7974 <para>Typically, a partition just uses the passed-in
7975 parameters (e.g. the unmodified value of
7976 <filename>bootimg_dir</filename>).
7977 However, in some cases, things might need to be
7978 more tailored.
7979 As an example, certain files might additionally
7980 need to be taken from
7981 <filename>bootimg_dir + /boot</filename>.
7982 This hook allows those files to be staged in a
7983 customized fashion.
7984 <note>
7985 <filename>get_bitbake_var()</filename>
7986 allows you to access non-standard variables
7987 that you might want to use for this
7988 behavior.
7989 </note>
7990 </para></listitem>
7991 </itemizedlist>
7992 </para>
7993
7994 <para>
Brad Bishopc342db32019-05-15 21:57:59 -04007995 You can extend the source plugin mechanism.
7996 To add more hooks, create more source plugin methods
Brad Bishop316dfdd2018-06-25 12:45:53 -04007997 within <filename>SourcePlugin</filename> and the
7998 corresponding derived subclasses.
Brad Bishopc342db32019-05-15 21:57:59 -04007999 The code that calls the plugin methods uses the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008000 <filename>plugin.get_source_plugin_methods()</filename>
8001 function to find the method or methods needed by the call.
8002 Retrieval of those methods is accomplished by filling up
8003 a dict with keys that contain the method names of interest.
8004 On success, these will be filled in with the actual
8005 methods.
8006 See the Wic implementation for examples and details.
8007 </para>
8008 </section>
8009
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008010 <section id='wic-usage-examples'>
8011 <title>Examples</title>
8012
8013 <para>
8014 This section provides several examples that show how to use
8015 the Wic utility.
8016 All the examples assume the list of requirements in the
8017 "<link linkend='wic-requirements'>Requirements</link>"
8018 section have been met.
8019 The examples assume the previously generated image is
8020 <filename>core-image-minimal</filename>.
8021 </para>
8022
8023 <section id='generate-an-image-using-a-provided-kickstart-file'>
8024 <title>Generate an Image using an Existing Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008025
8026 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008027 This example runs in Cooked Mode and uses the
8028 <filename>mkefidisk</filename> kickstart file:
8029 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008030 $ wic create mkefidisk -e core-image-minimal
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008031 INFO: Building wic-tools...
8032 .
8033 .
8034 .
8035 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008036 ./mkefidisk-201804191017-sda.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008037
8038 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008039 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8040 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8041 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8042 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 -05008043
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008044 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008045 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008046 </literallayout>
8047 The previous example shows the easiest way to create
8048 an image by running in cooked mode and supplying
8049 a kickstart file and the "-e" option to point to the
8050 existing build artifacts.
8051 Your <filename>local.conf</filename> file needs to have
8052 the
8053 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8054 variable set to the machine you are using, which is
8055 "qemux86" in this example.
8056 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008057
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008058 <para>
8059 Once the image builds, the output provides image
8060 location, artifact use, and kickstart file information.
8061 <note>
8062 You should always verify the details provided in the
8063 output to make sure that the image was indeed
8064 created exactly as expected.
8065 </note>
8066 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008067
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008068 <para>
8069 Continuing with the example, you can now write the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008070 image from the Build Directory onto a USB stick, or
8071 whatever media for which you built your image, and boot
8072 from the media.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008073 You can write the image by using
8074 <filename>bmaptool</filename> or
8075 <filename>dd</filename>:
8076 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008077 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008078 </literallayout>
8079 or
8080 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008081 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sd<replaceable>X</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008082 </literallayout>
8083 <note>
8084 For more information on how to use the
8085 <filename>bmaptool</filename> to flash a device
8086 with an image, see the
8087 "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>"
8088 section.
8089 </note>
8090 </para>
8091 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008092
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008093 <section id='using-a-modified-kickstart-file'>
8094 <title>Using a Modified Kickstart File</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008095
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008096 <para>
8097 Because partitioned image creation is driven by the
8098 kickstart file, it is easy to affect image creation by
8099 changing the parameters in the file.
8100 This next example demonstrates that through modification
8101 of the <filename>directdisk-gpt</filename> kickstart
8102 file.
8103 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008104
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008105 <para>
8106 As mentioned earlier, you can use the command
8107 <filename>wic list images</filename> to show the list
8108 of existing kickstart files.
8109 The directory in which the
8110 <filename>directdisk-gpt.wks</filename> file resides is
8111 <filename>scripts/lib/image/canned-wks/</filename>,
8112 which is located in the
8113 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
8114 (e.g. <filename>poky</filename>).
8115 Because available files reside in this directory,
8116 you can create and add your own custom files to the
8117 directory.
8118 Subsequent use of the
8119 <filename>wic list images</filename> command would then
8120 include your kickstart files.
8121 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008122
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008123 <para>
8124 In this example, the existing
8125 <filename>directdisk-gpt</filename> file already does
8126 most of what is needed.
8127 However, for the hardware in this example, the image
8128 will need to boot from <filename>sdb</filename> instead
8129 of <filename>sda</filename>, which is what the
8130 <filename>directdisk-gpt</filename> kickstart file
8131 uses.
8132 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008133
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008134 <para>
8135 The example begins by making a copy of the
8136 <filename>directdisk-gpt.wks</filename> file in the
8137 <filename>scripts/lib/image/canned-wks</filename>
8138 directory and then by changing the lines that specify
8139 the target disk from which to boot.
8140 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008141 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
8142 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008143 </literallayout>
8144 Next, the example modifies the
8145 <filename>directdisksdb-gpt.wks</filename> file and
8146 changes all instances of
8147 "<filename>--ondisk sda</filename>" to
8148 "<filename>--ondisk sdb</filename>".
8149 The example changes the following two lines and leaves
8150 the remaining lines untouched:
8151 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008152 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008153 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
8154 </literallayout>
8155 Once the lines are changed, the example generates the
8156 <filename>directdisksdb-gpt</filename> image.
8157 The command points the process at the
8158 <filename>core-image-minimal</filename> artifacts for
8159 the Next Unit of Computing (nuc)
8160 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8161 the <filename>local.conf</filename>.
8162 <literallayout class='monospaced'>
8163 $ wic create directdisksdb-gpt -e core-image-minimal
8164 INFO: Building wic-tools...
8165 .
8166 .
8167 .
8168 Initialising tasks: 100% |#######################################| Time: 0:00:01
8169 NOTE: Executing SetScene Tasks
8170 NOTE: Executing RunQueue Tasks
8171 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
8172 INFO: Creating image(s)...
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008173
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008174 INFO: The new image(s) can be found here:
8175 ./directdisksdb-gpt-201710090938-sdb.direct
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008176
8177 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008178 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8179 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8180 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8181 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 -05008182
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008183 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008184 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008185 </literallayout>
8186 Continuing with the example, you can now directly
8187 <filename>dd</filename> the image to a USB stick, or
8188 whatever media for which you built your image,
8189 and boot the resulting media:
8190 <literallayout class='monospaced'>
8191 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
8192 140966+0 records in
8193 140966+0 records out
8194 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
8195 $ sudo eject /dev/sdb
8196 </literallayout>
8197 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008198 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008199
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008200 <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'>
8201 <title>Using a Modified Kickstart File and Running in Raw Mode</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008202
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008203 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008204 This next example manually specifies each build artifact
8205 (runs in Raw Mode) and uses a modified kickstart file.
8206 The example also uses the <filename>-o</filename> option
8207 to cause Wic to create the output
8208 somewhere other than the default output directory,
8209 which is the current directory:
8210 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008211 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
8212 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
8213 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
8214 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
8215 --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 -05008216
8217 INFO: Creating image(s)...
8218
8219 INFO: The new image(s) can be found here:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008220 /home/stephano/testwic/test-201710091445-sdb.direct
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008221
8222 The following build artifacts were used to create the image(s):
Brad Bishop316dfdd2018-06-25 12:45:53 -04008223 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
8224 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
8225 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
8226 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 -05008227
8228 INFO: The image(s) were created using OE kickstart file:
Brad Bishop316dfdd2018-06-25 12:45:53 -04008229 /home/stephano/my_yocto/test.wks
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008230 </literallayout>
8231 For this example,
8232 <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
8233 did not have to be specified in the
8234 <filename>local.conf</filename> file since the
8235 artifact is manually specified.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008236 </para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008237 </section>
8238
8239 <section id='using-wic-to-manipulate-an-image'>
8240 <title>Using Wic to Manipulate an Image</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008241
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008242 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008243 Wic image manipulation allows you to shorten turnaround
8244 time during image development.
8245 For example, you can use Wic to delete the kernel partition
8246 of a Wic image and then insert a newly built kernel.
8247 This saves you time from having to rebuild the entire image
8248 each time you modify the kernel.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008249 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008250 In order to use Wic to manipulate a Wic image as in
8251 this example, your development machine must have the
8252 <filename>mtools</filename> package installed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008253 </note>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008254 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008255
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008256 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008257 The following example examines the contents of the Wic
8258 image, deletes the existing kernel, and then inserts a
8259 new kernel:
8260 <orderedlist>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008261 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008262 <emphasis>List the Partitions:</emphasis>
8263 Use the <filename>wic ls</filename> command to list
8264 all the partitions in the Wic image:
8265 <literallayout class='monospaced'>
8266 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
8267 Num Start End Size Fstype
8268 1 1048576 25041919 23993344 fat16
8269 2 25165824 72157183 46991360 ext4
8270 </literallayout>
8271 The previous output shows two partitions in the
8272 <filename>core-image-minimal-qemux86.wic</filename>
8273 image.
8274 </para></listitem>
8275 <listitem><para>
8276 <emphasis>Examine a Particular Partition:</emphasis>
8277 Use the <filename>wic ls</filename> command again
8278 but in a different form to examine a particular
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008279 partition.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008280 <note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008281 You can get command usage on any Wic command
8282 using the following form:
8283 <literallayout class='monospaced'>
8284 $ wic help <replaceable>command</replaceable>
8285 </literallayout>
8286 For example, the following command shows you
8287 the various ways to use the
8288 <filename>wic ls</filename> command:
8289 <literallayout class='monospaced'>
8290 $ wic help ls
8291 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008292 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008293 The following command shows what is in Partition
8294 one:
8295 <literallayout class='monospaced'>
8296 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
8297 Volume in drive : is boot
8298 Volume Serial Number is E894-1809
8299 Directory for ::/
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008300
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008301 libcom32 c32 186500 2017-10-09 16:06
8302 libutil c32 24148 2017-10-09 16:06
8303 syslinux cfg 220 2017-10-09 16:06
8304 vesamenu c32 27104 2017-10-09 16:06
8305 vmlinuz 6904608 2017-10-09 16:06
8306 5 files 7 142 580 bytes
8307 16 582 656 bytes free
8308 </literallayout>
8309 The previous output shows five files, with the
8310 <filename>vmlinuz</filename> being the kernel.
8311 <note>
8312 If you see the following error, you need to
8313 update or create a
8314 <filename>~/.mtoolsrc</filename> file and
8315 be sure to have the line “mtools_skip_check=1“
8316 in the file.
8317 Then, run the Wic command again:
8318 <literallayout class='monospaced'>
8319 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
8320 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
8321 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
8322 </literallayout>
8323 </note>
8324 </para></listitem>
8325 <listitem><para>
8326 <emphasis>Remove the Old Kernel:</emphasis>
8327 Use the <filename>wic rm</filename> command to
8328 remove the <filename>vmlinuz</filename> file
8329 (kernel):
8330 <literallayout class='monospaced'>
8331 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8332 </literallayout>
8333 </para></listitem>
8334 <listitem><para>
8335 <emphasis>Add In the New Kernel:</emphasis>
8336 Use the <filename>wic cp</filename> command to
8337 add the updated kernel to the Wic image.
8338 Depending on how you built your kernel, it could
8339 be in different places.
8340 If you used <filename>devtool</filename> and
8341 an SDK to build your kernel, it resides in the
8342 <filename>tmp/work</filename> directory of the
8343 extensible SDK.
8344 If you used <filename>make</filename> to build the
8345 kernel, the kernel will be in the
8346 <filename>workspace/sources</filename> area.
8347 </para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008348
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008349 <para>The following example assumes
8350 <filename>devtool</filename> was used to build
8351 the kernel:
8352 <literallayout class='monospaced'>
8353 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 \
8354 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
8355 </literallayout>
8356 Once the new kernel is added back into the image,
8357 you can use the <filename>dd</filename>
8358 command or
8359 <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link>
8360 to flash your wic image onto an SD card
8361 or USB stick and test your target.
8362 <note>
8363 Using <filename>bmaptool</filename> is
8364 generally 10 to 20 times faster than using
8365 <filename>dd</filename>.
8366 </note>
8367 </para></listitem>
8368 </orderedlist>
8369 </para>
8370 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008371 </section>
8372 </section>
8373
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008374 <section id='flashing-images-using-bmaptool'>
8375 <title>Flashing Images Using <filename>bmaptool</filename></title>
8376
8377 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008378 A fast and easy way to flash an image to a bootable device
8379 is to use Bmaptool, which is integrated into the OpenEmbedded
8380 build system.
8381 Bmaptool is a generic tool that creates a file's block map (bmap)
8382 and then uses that map to copy the file.
8383 As compared to traditional tools such as dd or cp, Bmaptool
8384 can copy (or flash) large files like raw system image files
8385 much faster.
8386 <note><title>Notes</title>
8387 <itemizedlist>
8388 <listitem><para>
8389 If you are using Ubuntu or Debian distributions, you
8390 can install the <filename>bmap-tools</filename> package
8391 using the following command and then use the tool
8392 without specifying <filename>PATH</filename> even from
8393 the root account:
8394 <literallayout class='monospaced'>
8395 $ sudo apt-get install bmap-tools
8396 </literallayout>
8397 </para></listitem>
8398 <listitem><para>
8399 If you are unable to install the
8400 <filename>bmap-tools</filename> package, you will
8401 need to build Bmaptool before using it.
8402 Use the following command:
8403 <literallayout class='monospaced'>
8404 $ bitbake bmap-tools-native
8405 </literallayout>
8406 </para></listitem>
8407 </itemizedlist>
8408 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008409 </para>
8410
8411 <para>
8412 Following, is an example that shows how to flash a Wic image.
Brad Bishop316dfdd2018-06-25 12:45:53 -04008413 Realize that while this example uses a Wic image, you can use
8414 Bmaptool to flash any type of image.
8415 Use these steps to flash an image using Bmaptool:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008416 <orderedlist>
8417 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008418 <emphasis>Update your <filename>local.conf</filename> File:</emphasis>
8419 You need to have the following set in your
8420 <filename>local.conf</filename> file before building
8421 your image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008422 <literallayout class='monospaced'>
8423 IMAGE_FSTYPES += "wic wic.bmap"
8424 </literallayout>
8425 </para></listitem>
8426 <listitem><para>
8427 <emphasis>Get Your Image:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008428 Either have your image ready (pre-built with the
8429 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink>
8430 setting previously mentioned) or take the step to build
8431 the image:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008432 <literallayout class='monospaced'>
8433 $ bitbake <replaceable>image</replaceable>
8434 </literallayout>
8435 </para></listitem>
8436 <listitem><para>
8437 <emphasis>Flash the Device:</emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008438 Flash the device with the image by using Bmaptool
8439 depending on your particular setup.
8440 The following commands assume the image resides in the
8441 Build Directory's <filename>deploy/images/</filename>
8442 area:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008443 <itemizedlist>
8444 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008445 If you have write access to the media, use this
8446 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008447 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008448 $ 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 -05008449 </literallayout>
8450 </para></listitem>
8451 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008452 If you do not have write access to the media, set
8453 your permissions first and then use the same
8454 command form:
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008455 <literallayout class='monospaced'>
8456 $ sudo chmod 666 /dev/sd<replaceable>X</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008457 $ 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 -05008458 </literallayout>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008459 </para></listitem>
8460 </itemizedlist>
8461 </para></listitem>
8462 </orderedlist>
8463 </para>
8464
8465 <para>
8466 For help on the <filename>bmaptool</filename> command, use the
8467 following command:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008468 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008469 $ bmaptool --help
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008470 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05008471 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008472 </section>
8473
8474 <section id='making-images-more-secure'>
8475 <title>Making Images More Secure</title>
8476
8477 <para>
8478 Security is of increasing concern for embedded devices.
8479 Consider the issues and problems discussed in just this
8480 sampling of work found across the Internet:
8481 <itemizedlist>
8482 <listitem><para><emphasis>
8483 "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis>
8484 by Bruce Schneier
8485 </para></listitem>
8486 <listitem><para><emphasis>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008487 "<ulink url='http://census2012.sourceforge.net/paper.html'>Internet Census 2012</ulink>"</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008488 by Carna Botnet</para></listitem>
8489 <listitem><para><emphasis>
8490 "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis>
8491 by Jake Edge
8492 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008493 </itemizedlist>
8494 </para>
8495
8496 <para>
8497 When securing your image is of concern, there are steps, tools,
8498 and variables that you can consider to help you reach the
8499 security goals you need for your particular device.
8500 Not all situations are identical when it comes to making an
8501 image secure.
8502 Consequently, this section provides some guidance and suggestions
8503 for consideration when you want to make your image more secure.
8504 <note>
8505 Because the security requirements and risks are
8506 different for every type of device, this section cannot
8507 provide a complete reference on securing your custom OS.
8508 It is strongly recommended that you also consult other sources
8509 of information on embedded Linux system hardening and on
8510 security.
8511 </note>
8512 </para>
8513
8514 <section id='general-considerations'>
8515 <title>General Considerations</title>
8516
8517 <para>
8518 General considerations exist that help you create more
8519 secure images.
8520 You should consider the following suggestions to help
8521 make your device more secure:
8522 <itemizedlist>
8523 <listitem><para>
8524 Scan additional code you are adding to the system
8525 (e.g. application code) by using static analysis
8526 tools.
8527 Look for buffer overflows and other potential
8528 security problems.
8529 </para></listitem>
8530 <listitem><para>
8531 Pay particular attention to the security for
8532 any web-based administration interface.
8533 </para>
8534 <para>Web interfaces typically need to perform
8535 administrative functions and tend to need to run with
8536 elevated privileges.
8537 Thus, the consequences resulting from the interface's
8538 security becoming compromised can be serious.
8539 Look for common web vulnerabilities such as
8540 cross-site-scripting (XSS), unvalidated inputs,
8541 and so forth.</para>
8542 <para>As with system passwords, the default credentials
8543 for accessing a web-based interface should not be the
8544 same across all devices.
8545 This is particularly true if the interface is enabled
8546 by default as it can be assumed that many end-users
8547 will not change the credentials.
8548 </para></listitem>
8549 <listitem><para>
8550 Ensure you can update the software on the device to
8551 mitigate vulnerabilities discovered in the future.
8552 This consideration especially applies when your
8553 device is network-enabled.
8554 </para></listitem>
8555 <listitem><para>
8556 Ensure you remove or disable debugging functionality
8557 before producing the final image.
8558 For information on how to do this, see the
8559 "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>"
8560 section.
8561 </para></listitem>
8562 <listitem><para>
8563 Ensure you have no network services listening that
8564 are not needed.
8565 </para></listitem>
8566 <listitem><para>
8567 Remove any software from the image that is not needed.
8568 </para></listitem>
8569 <listitem><para>
8570 Enable hardware support for secure boot functionality
8571 when your device supports this functionality.
8572 </para></listitem>
8573 </itemizedlist>
8574 </para>
8575 </section>
8576
8577 <section id='security-flags'>
8578 <title>Security Flags</title>
8579
8580 <para>
8581 The Yocto Project has security flags that you can enable that
8582 help make your build output more secure.
8583 The security flags are in the
8584 <filename>meta/conf/distro/include/security_flags.inc</filename>
8585 file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008586 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008587 (e.g. <filename>poky</filename>).
8588 <note>
8589 Depending on the recipe, certain security flags are enabled
8590 and disabled by default.
8591 </note>
8592 </para>
8593
8594 <para>
8595<!--
8596 The GCC/LD flags in <filename>security_flags.inc</filename>
8597 enable more secure code generation.
8598 By including the <filename>security_flags.inc</filename>
8599 file, you enable flags to the compiler and linker that cause
8600 them to generate more secure code.
8601 <note>
8602 The GCC/LD flags are enabled by default in the
8603 <filename>poky-lsb</filename> distribution.
8604 </note>
8605-->
8606 Use the following line in your
8607 <filename>local.conf</filename> file or in your custom
8608 distribution configuration file to enable the security
8609 compiler and linker flags for your build:
8610 <literallayout class='monospaced'>
8611 require conf/distro/include/security_flags.inc
8612 </literallayout>
8613 </para>
8614 </section>
8615
8616 <section id='considerations-specific-to-the-openembedded-build-system'>
8617 <title>Considerations Specific to the OpenEmbedded Build System</title>
8618
8619 <para>
8620 You can take some steps that are specific to the
8621 OpenEmbedded build system to make your images more secure:
8622 <itemizedlist>
8623 <listitem><para>
8624 Ensure "debug-tweaks" is not one of your selected
8625 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>.
8626 When creating a new project, the default is to provide you
8627 with an initial <filename>local.conf</filename> file that
8628 enables this feature using the
8629 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line:
8630 <literallayout class='monospaced'>
8631 EXTRA_IMAGE_FEATURES = "debug-tweaks"
8632 </literallayout>
8633 To disable that feature, simply comment out that line in your
8634 <filename>local.conf</filename> file, or
8635 make sure <filename>IMAGE_FEATURES</filename> does not contain
8636 "debug-tweaks" before producing your final image.
8637 Among other things, leaving this in place sets the
8638 root password as blank, which makes logging in for
8639 debugging or inspection easy during
8640 development but also means anyone can easily log in
8641 during production.
8642 </para></listitem>
8643 <listitem><para>
8644 It is possible to set a root password for the image
8645 and also to set passwords for any extra users you might
8646 add (e.g. administrative or service type users).
8647 When you set up passwords for multiple images or
8648 users, you should not duplicate passwords.
8649 </para>
8650 <para>
8651 To set up passwords, use the
8652 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink>
8653 class, which is the preferred method.
8654 For an example on how to set up both root and user
8655 passwords, see the
8656 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>"
8657 section.
8658 <note>
8659 When adding extra user accounts or setting a
8660 root password, be cautious about setting the
8661 same password on every device.
8662 If you do this, and the password you have set
8663 is exposed, then every device is now potentially
8664 compromised.
8665 If you need this access but want to ensure
8666 security, consider setting a different,
8667 random password for each device.
8668 Typically, you do this as a separate step after
8669 you deploy the image onto the device.
8670 </note>
8671 </para></listitem>
8672 <listitem><para>
8673 Consider enabling a Mandatory Access Control (MAC)
8674 framework such as SMACK or SELinux and tuning it
8675 appropriately for your device's usage.
8676 You can find more information in the
8677 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink>
8678 layer.
8679 </para></listitem>
8680 </itemizedlist>
8681 </para>
8682
8683 <para>
8684 </para>
8685 </section>
8686
8687 <section id='tools-for-hardening-your-image'>
8688 <title>Tools for Hardening Your Image</title>
8689
8690 <para>
8691 The Yocto Project provides tools for making your image
8692 more secure.
8693 You can find these tools in the
8694 <filename>meta-security</filename> layer of the
Brad Bishop316dfdd2018-06-25 12:45:53 -04008695 <ulink url='&YOCTO_GIT_URL;'>Yocto Project Source Repositories</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008696 </para>
8697 </section>
8698 </section>
8699
8700 <section id='creating-your-own-distribution'>
8701 <title>Creating Your Own Distribution</title>
8702
8703 <para>
8704 When you build an image using the Yocto Project and
8705 do not alter any distribution
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008706 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>,
8707 you are creating a Poky distribution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008708 If you wish to gain more control over package alternative
8709 selections, compile-time options, and other low-level
8710 configurations, you can create your own distribution.
8711 </para>
8712
8713 <para>
8714 To create your own distribution, the basic steps consist of
8715 creating your own distribution layer, creating your own
8716 distribution configuration file, and then adding any needed
8717 code and Metadata to the layer.
8718 The following steps provide some more detail:
8719 <itemizedlist>
8720 <listitem><para><emphasis>Create a layer for your new distro:</emphasis>
8721 Create your distribution layer so that you can keep your
8722 Metadata and code for the distribution separate.
8723 It is strongly recommended that you create and use your own
8724 layer for configuration and code.
8725 Using your own layer as compared to just placing
8726 configurations in a <filename>local.conf</filename>
8727 configuration file makes it easier to reproduce the same
8728 build configuration when using multiple build machines.
8729 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008730 "<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 -05008731 section for information on how to quickly set up a layer.
8732 </para></listitem>
8733 <listitem><para><emphasis>Create the distribution configuration file:</emphasis>
8734 The distribution configuration file needs to be created in
8735 the <filename>conf/distro</filename> directory of your
8736 layer.
8737 You need to name it using your distribution name
8738 (e.g. <filename>mydistro.conf</filename>).
8739 <note>
8740 The
8741 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8742 variable in your
8743 <filename>local.conf</filename> file determines the
8744 name of your distribution.
8745 </note></para>
8746 <para>You can split out parts of your configuration file
8747 into include files and then "require" them from within
8748 your distribution configuration file.
8749 Be sure to place the include files in the
8750 <filename>conf/distro/include</filename> directory of
8751 your layer.
8752 A common example usage of include files would be to
8753 separate out the selection of desired version and revisions
8754 for individual recipes.
8755</para>
8756 <para>Your configuration file needs to set the following
8757 required variables:
8758 <literallayout class='monospaced'>
8759 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink>
8760 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink>
8761 </literallayout>
8762 These following variables are optional and you typically
8763 set them from the distribution configuration file:
8764 <literallayout class='monospaced'>
8765 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
8766 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink>
8767 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink>
8768 <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink>
8769 </literallayout>
8770 <tip>
8771 If you want to base your distribution configuration file
8772 on the very basic configuration from OE-Core, you
8773 can use
8774 <filename>conf/distro/defaultsetup.conf</filename> as
8775 a reference and just include variables that differ
8776 as compared to <filename>defaultsetup.conf</filename>.
8777 Alternatively, you can create a distribution
8778 configuration file from scratch using the
8779 <filename>defaultsetup.conf</filename> file
8780 or configuration files from other distributions
8781 such as Poky or Angstrom as references.
8782 </tip></para></listitem>
8783 <listitem><para><emphasis>Provide miscellaneous variables:</emphasis>
8784 Be sure to define any other variables for which you want to
8785 create a default or enforce as part of the distribution
8786 configuration.
8787 You can include nearly any variable from the
8788 <filename>local.conf</filename> file.
8789 The variables you use are not limited to the list in the
8790 previous bulleted item.</para></listitem>
8791 <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis>
8792 In your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008793 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008794 set your
8795 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink>
8796 variable to point to your distribution's configuration file.
8797 For example, if your distribution's configuration file is
8798 named <filename>mydistro.conf</filename>, then you point
8799 to it as follows:
8800 <literallayout class='monospaced'>
8801 DISTRO = "mydistro"
8802 </literallayout></para></listitem>
8803 <listitem><para><emphasis>Add more to the layer if necessary:</emphasis>
8804 Use your layer to hold other information needed for the
8805 distribution:
8806 <itemizedlist>
8807 <listitem><para>Add recipes for installing
8808 distro-specific configuration files that are not
8809 already installed by another recipe.
8810 If you have distro-specific configuration files
8811 that are included by an existing recipe, you should
8812 add an append file (<filename>.bbappend</filename>)
8813 for those.
8814 For general information and recommendations
8815 on how to add recipes to your layer, see the
8816 "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>"
8817 and
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008818 "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008819 sections.</para></listitem>
8820 <listitem><para>Add any image recipes that are specific
8821 to your distribution.</para></listitem>
8822 <listitem><para>Add a <filename>psplash</filename>
8823 append file for a branded splash screen.
8824 For information on append files, see the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008825 "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008826 section.</para></listitem>
8827 <listitem><para>Add any other append files to make
8828 custom changes that are specific to individual
8829 recipes.</para></listitem>
8830 </itemizedlist></para></listitem>
8831 </itemizedlist>
8832 </para>
8833 </section>
8834
8835 <section id='creating-a-custom-template-configuration-directory'>
8836 <title>Creating a Custom Template Configuration Directory</title>
8837
8838 <para>
8839 If you are producing your own customized version
8840 of the build system for use by other users, you might
8841 want to customize the message shown by the setup script or
8842 you might want to change the template configuration files (i.e.
8843 <filename>local.conf</filename> and
8844 <filename>bblayers.conf</filename>) that are created in
8845 a new build directory.
8846 </para>
8847
8848 <para>
8849 The OpenEmbedded build system uses the environment variable
8850 <filename>TEMPLATECONF</filename> to locate the directory
8851 from which it gathers configuration information that ultimately
8852 ends up in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008853 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008854 <filename>conf</filename> directory.
8855 By default, <filename>TEMPLATECONF</filename> is set as
8856 follows in the <filename>poky</filename> repository:
8857 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008858 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008859 </literallayout>
8860 This is the directory used by the build system to find templates
8861 from which to build some key configuration files.
8862 If you look at this directory, you will see the
8863 <filename>bblayers.conf.sample</filename>,
8864 <filename>local.conf.sample</filename>, and
8865 <filename>conf-notes.txt</filename> files.
8866 The build system uses these files to form the respective
8867 <filename>bblayers.conf</filename> file,
8868 <filename>local.conf</filename> file, and display the list of
8869 BitBake targets when running the setup script.
8870 </para>
8871
8872 <para>
8873 To override these default configuration files with
8874 configurations you want used within every new
8875 Build Directory, simply set the
8876 <filename>TEMPLATECONF</filename> variable to your directory.
8877 The <filename>TEMPLATECONF</filename> variable is set in the
8878 <filename>.templateconf</filename> file, which is in the
8879 top-level
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008880 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008881 folder (e.g. <filename>poky</filename>).
8882 Edit the <filename>.templateconf</filename> so that it can locate
8883 your directory.
8884 </para>
8885
8886 <para>
8887 Best practices dictate that you should keep your
8888 template configuration directory in your custom distribution layer.
8889 For example, suppose you have a layer named
8890 <filename>meta-mylayer</filename> located in your home directory
8891 and you want your template configuration directory named
8892 <filename>myconf</filename>.
8893 Changing the <filename>.templateconf</filename> as follows
8894 causes the OpenEmbedded build system to look in your directory
8895 and base its configuration files on the
8896 <filename>*.sample</filename> configuration files it finds.
8897 The final configuration files (i.e.
8898 <filename>local.conf</filename> and
8899 <filename>bblayers.conf</filename> ultimately still end up in
8900 your Build Directory, but they are based on your
8901 <filename>*.sample</filename> files.
8902 <literallayout class='monospaced'>
8903 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
8904 </literallayout>
8905 </para>
8906
8907 <para>
8908 Aside from the <filename>*.sample</filename> configuration files,
8909 the <filename>conf-notes.txt</filename> also resides in the
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008910 default <filename>meta-poky/conf</filename> directory.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008911 The script that sets up the build environment
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008912 (i.e.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008913 <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>)
8914 uses this file to display BitBake targets as part of the script
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008915 output.
8916 Customizing this <filename>conf-notes.txt</filename> file is a
8917 good way to make sure your list of custom targets appears
8918 as part of the script's output.
8919 </para>
8920
8921 <para>
8922 Here is the default list of targets displayed as a result of
8923 running either of the setup scripts:
8924 <literallayout class='monospaced'>
8925 You can now run 'bitbake &lt;target&gt;'
8926
8927 Common targets are:
8928 core-image-minimal
8929 core-image-sato
8930 meta-toolchain
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008931 meta-ide-support
8932 </literallayout>
8933 </para>
8934
8935 <para>
8936 Changing the listed common targets is as easy as editing your
8937 version of <filename>conf-notes.txt</filename> in your
8938 custom template configuration directory and making sure you
8939 have <filename>TEMPLATECONF</filename> set to your directory.
8940 </para>
8941 </section>
8942
Brad Bishop316dfdd2018-06-25 12:45:53 -04008943 <section id='dev-saving-memory-during-a-build'>
8944 <title>Conserving Disk Space During Builds</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008945
8946 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04008947 To help conserve disk space during builds, you can add the
8948 following statement to your project's
8949 <filename>local.conf</filename> configuration file found in the
8950 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
8951 <literallayout class='monospaced'>
8952 INHERIT += "rm_work"
8953 </literallayout>
8954 Adding this statement deletes the work directory used for building
8955 a recipe once the recipe is built.
8956 For more information on "rm_work", see the
8957 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
8958 class in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008959 </para>
8960 </section>
8961
8962 <section id='working-with-packages'>
8963 <title>Working with Packages</title>
8964
8965 <para>
8966 This section describes a few tasks that involve packages:
8967 <itemizedlist>
8968 <listitem><para>
8969 <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link>
8970 </para></listitem>
8971 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008972 <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008973 </para></listitem>
8974 <listitem><para>
8975 <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link>
8976 </para></listitem>
8977 <listitem><para>
Brad Bishop15ae2502019-06-18 21:44:24 -04008978 <link linkend='using-runtime-package-management'>Using runtime package management</link>
8979 </para></listitem>
8980 <listitem><para>
8981 <link linkend='generating-and-using-signed-packages'>Generating and using signed packages</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008982 </para></listitem>
8983 <listitem><para>
8984 <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link>
8985 </para></listitem>
Brad Bishop15ae2502019-06-18 21:44:24 -04008986 <listitem><para>
8987 <link linkend='creating-node-package-manager-npm-packages'>Creating node package manager (NPM) packages</link>
8988 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008989 </itemizedlist>
8990 </para>
8991
8992 <section id='excluding-packages-from-an-image'>
8993 <title>Excluding Packages from an Image</title>
8994
8995 <para>
8996 You might find it necessary to prevent specific packages
8997 from being installed into an image.
8998 If so, you can use several variables to direct the build
8999 system to essentially ignore installing recommended packages
9000 or to not install a package at all.
9001 </para>
9002
9003 <para>
9004 The following list introduces variables you can use to
9005 prevent packages from being installed into your image.
9006 Each of these variables only works with IPK and RPM
9007 package types.
9008 Support for Debian packages does not exist.
9009 Also, you can use these variables from your
9010 <filename>local.conf</filename> file or attach them to a
9011 specific image recipe by using a recipe name override.
9012 For more detail on the variables, see the descriptions in the
9013 Yocto Project Reference Manual's glossary chapter.
9014 <itemizedlist>
9015 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>:
9016 Use this variable to specify "recommended-only"
9017 packages that you do not want installed.
9018 </para></listitem>
9019 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>:
9020 Use this variable to prevent all "recommended-only"
9021 packages from being installed.
9022 </para></listitem>
9023 <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>:
9024 Use this variable to prevent specific packages from
9025 being installed regardless of whether they are
9026 "recommended-only" or not.
9027 You need to realize that the build process could
9028 fail with an error when you
9029 prevent the installation of a package whose presence
9030 is required by an installed package.
9031 </para></listitem>
9032 </itemizedlist>
9033 </para>
9034 </section>
9035
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009036 <section id='incrementing-a-binary-package-version'>
9037 <title>Incrementing a Package Version</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009038
9039 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009040 This section provides some background on how binary package
9041 versioning is accomplished and presents some of the services,
9042 variables, and terminology involved.
9043 </para>
9044
9045 <para>
9046 In order to understand binary package versioning, you need
9047 to consider the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009048 <itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009049 <listitem><para>
9050 Binary Package: The binary package that is eventually
9051 built and installed into an image.
9052 </para></listitem>
9053 <listitem><para>
9054 Binary Package Version: The binary package version
9055 is composed of two components - a version and a
9056 revision.
9057 <note>
9058 Technically, a third component, the "epoch" (i.e.
9059 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>)
9060 is involved but this discussion for the most part
9061 ignores <filename>PE</filename>.
9062 </note>
9063 The version and revision are taken from the
9064 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
9065 and
9066 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9067 variables, respectively.
9068 </para></listitem>
9069 <listitem><para>
9070 <filename>PV</filename>: The recipe version.
9071 <filename>PV</filename> represents the version of the
9072 software being packaged.
9073 Do not confuse <filename>PV</filename> with the
9074 binary package version.
9075 </para></listitem>
9076 <listitem><para>
9077 <filename>PR</filename>: The recipe revision.
9078 </para></listitem>
9079 <listitem><para>
9080 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>:
9081 The OpenEmbedded build system uses this string
9082 to help define the value of <filename>PV</filename>
9083 when the source code revision needs to be included
9084 in it.
9085 </para></listitem>
9086 <listitem><para>
9087 <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>:
9088 A network-based service that helps automate keeping
9089 package feeds compatible with existing package
9090 manager applications such as RPM, APT, and OPKG.
9091 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009092 </itemizedlist>
9093 </para>
9094
9095 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009096 Whenever the binary package content changes, the binary package
9097 version must change.
9098 Changing the binary package version is accomplished by changing
9099 or "bumping" the <filename>PR</filename> and/or
9100 <filename>PV</filename> values.
9101 Increasing these values occurs one of two ways:
9102 <itemizedlist>
9103 <listitem><para>Automatically using a Package Revision
9104 Service (PR Service).
9105 </para></listitem>
9106 <listitem><para>Manually incrementing the
9107 <filename>PR</filename> and/or
9108 <filename>PV</filename> variables.
9109 </para></listitem>
9110 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009111 </para>
9112
9113 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009114 Given a primary challenge of any build system and its users
9115 is how to maintain a package feed that is compatible with
9116 existing package manager applications such as RPM, APT, and
9117 OPKG, using an automated system is much preferred over a
9118 manual system.
9119 In either system, the main requirement is that binary package
9120 version numbering increases in a linear fashion and that a
9121 number of version components exist that support that linear
9122 progression.
9123 For information on how to ensure package revisioning remains
9124 linear, see the
9125 "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>"
9126 section.
9127 </para>
9128
9129 <para>
9130 The following three sections provide related information on the
9131 PR Service, the manual method for "bumping"
9132 <filename>PR</filename> and/or <filename>PV</filename>, and
9133 on how to ensure binary package revisioning remains linear.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009134 </para>
9135
9136 <section id='working-with-a-pr-service'>
9137 <title>Working With a PR Service</title>
9138
9139 <para>
9140 As mentioned, attempting to maintain revision numbers in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009141 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009142 is error prone, inaccurate, and causes problems for people
9143 submitting recipes.
9144 Conversely, the PR Service automatically generates
9145 increasing numbers, particularly the revision field,
9146 which removes the human element.
9147 <note>
9148 For additional information on using a PR Service, you
9149 can see the
9150 <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink>
9151 wiki page.
9152 </note>
9153 </para>
9154
9155 <para>
9156 The Yocto Project uses variables in order of
9157 decreasing priority to facilitate revision numbering (i.e.
9158 <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>,
9159 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and
9160 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9161 for epoch, version, and revision, respectively).
9162 The values are highly dependent on the policies and
9163 procedures of a given distribution and package feed.
9164 </para>
9165
9166 <para>
9167 Because the OpenEmbedded build system uses
Brad Bishop316dfdd2018-06-25 12:45:53 -04009168 "<ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>signatures</ulink>",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009169 which are unique to a given build, the build system
9170 knows when to rebuild packages.
9171 All the inputs into a given task are represented by a
9172 signature, which can trigger a rebuild when different.
9173 Thus, the build system itself does not rely on the
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009174 <filename>PR</filename>, <filename>PV</filename>, and
9175 <filename>PE</filename> numbers to trigger a rebuild.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009176 The signatures, however, can be used to generate
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009177 these values.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009178 </para>
9179
9180 <para>
9181 The PR Service works with both
9182 <filename>OEBasic</filename> and
9183 <filename>OEBasicHash</filename> generators.
9184 The value of <filename>PR</filename> bumps when the
9185 checksum changes and the different generator mechanisms
9186 change signatures under different circumstances.
9187 </para>
9188
9189 <para>
9190 As implemented, the build system includes values from
9191 the PR Service into the <filename>PR</filename> field as
9192 an addition using the form "<filename>.x</filename>" so
9193 <filename>r0</filename> becomes <filename>r0.1</filename>,
9194 <filename>r0.2</filename> and so forth.
9195 This scheme allows existing <filename>PR</filename> values
9196 to be used for whatever reasons, which include manual
9197 <filename>PR</filename> bumps, should it be necessary.
9198 </para>
9199
9200 <para>
9201 By default, the PR Service is not enabled or running.
9202 Thus, the packages generated are just "self consistent".
9203 The build system adds and removes packages and
9204 there are no guarantees about upgrade paths but images
9205 will be consistent and correct with the latest changes.
9206 </para>
9207
9208 <para>
9209 The simplest form for a PR Service is for it to exist
9210 for a single host development system that builds the
9211 package feed (building system).
9212 For this scenario, you can enable a local PR Service by
9213 setting
9214 <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink>
9215 in your <filename>local.conf</filename> file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009216 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009217 <literallayout class='monospaced'>
9218 PRSERV_HOST = "localhost:0"
9219 </literallayout>
9220 Once the service is started, packages will automatically
9221 get increasing <filename>PR</filename> values and
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009222 BitBake takes care of starting and stopping the server.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009223 </para>
9224
9225 <para>
9226 If you have a more complex setup where multiple host
9227 development systems work against a common, shared package
9228 feed, you have a single PR Service running and it is
9229 connected to each building system.
9230 For this scenario, you need to start the PR Service using
9231 the <filename>bitbake-prserv</filename> command:
9232 <literallayout class='monospaced'>
9233 bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start
9234 </literallayout>
9235 In addition to hand-starting the service, you need to
9236 update the <filename>local.conf</filename> file of each
9237 building system as described earlier so each system
9238 points to the server and port.
9239 </para>
9240
9241 <para>
9242 It is also recommended you use build history, which adds
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009243 some sanity checks to binary package versions, in
9244 conjunction with the server that is running the PR Service.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009245 To enable build history, add the following to each building
9246 system's <filename>local.conf</filename> file:
9247 <literallayout class='monospaced'>
9248 # It is recommended to activate "buildhistory" for testing the PR service
9249 INHERIT += "buildhistory"
9250 BUILDHISTORY_COMMIT = "1"
9251 </literallayout>
9252 For information on build history, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009253 "<link linkend='maintaining-build-output-quality'>Maintaining Build Output Quality</link>"
9254 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009255 </para>
9256
9257 <note>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009258 <para>
9259 The OpenEmbedded build system does not maintain
9260 <filename>PR</filename> information as part of the
9261 shared state (sstate) packages.
9262 If you maintain an sstate feed, its expected that either
9263 all your building systems that contribute to the sstate
9264 feed use a shared PR Service, or you do not run a PR
9265 Service on any of your building systems.
9266 Having some systems use a PR Service while others do
9267 not leads to obvious problems.
9268 </para>
9269
9270 <para>
9271 For more information on shared state, see the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009272 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>Shared State Cache</ulink>"
9273 section in the Yocto Project Overview and Concepts
9274 Manual.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009275 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009276 </note>
9277 </section>
9278
9279 <section id='manually-bumping-pr'>
9280 <title>Manually Bumping PR</title>
9281
9282 <para>
9283 The alternative to setting up a PR Service is to manually
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009284 "bump" the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009285 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>
9286 variable.
9287 </para>
9288
9289 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009290 If a committed change results in changing the package
9291 output, then the value of the PR variable needs to be
9292 increased (or "bumped") as part of that commit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009293 For new recipes you should add the <filename>PR</filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009294 variable and set its initial value equal to "r0", which is
9295 the default.
9296 Even though the default value is "r0", the practice of
9297 adding it to a new recipe makes it harder to forget to bump
9298 the variable when you make changes to the recipe in future.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009299 </para>
9300
9301 <para>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009302 If you are sharing a common <filename>.inc</filename> file
9303 with multiple recipes, you can also use the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009304 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename>
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009305 variable to ensure that the recipes sharing the
9306 <filename>.inc</filename> file are rebuilt when the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009307 <filename>.inc</filename> file itself is changed.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009308 The <filename>.inc</filename> file must set
9309 <filename>INC_PR</filename> (initially to "r0"), and all
9310 recipes referring to it should set <filename>PR</filename>
9311 to "${INC_PR}.0" initially, incrementing the last number
9312 when the recipe is changed.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009313 If the <filename>.inc</filename> file is changed then its
9314 <filename>INC_PR</filename> should be incremented.
9315 </para>
9316
9317 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009318 When upgrading the version of a binary package, assuming the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009319 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename>
9320 changes, the <filename>PR</filename> variable should be
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009321 reset to "r0" (or "${INC_PR}.0" if you are using
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009322 <filename>INC_PR</filename>).
9323 </para>
9324
9325 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009326 Usually, version increases occur only to binary packages.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009327 However, if for some reason <filename>PV</filename> changes
9328 but does not increase, you can increase the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009329 <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename>
9330 variable (Package Epoch).
9331 The <filename>PE</filename> variable defaults to "0".
9332 </para>
9333
9334 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009335 Binary package version numbering strives to follow the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009336 <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'>
9337 Debian Version Field Policy Guidelines</ulink>.
Brad Bishop37a0e4d2017-12-04 01:01:44 -05009338 These guidelines define how versions are compared and what
9339 "increasing" a version means.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009340 </para>
9341 </section>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009342
9343 <section id='automatically-incrementing-a-binary-package-revision-number'>
9344 <title>Automatically Incrementing a Package Version Number</title>
9345
9346 <para>
9347 When fetching a repository, BitBake uses the
9348 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
9349 variable to determine the specific source code revision
9350 from which to build.
9351 You set the <filename>SRCREV</filename> variable to
9352 <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>
9353 to cause the OpenEmbedded build system to automatically use the
9354 latest revision of the software:
9355 <literallayout class='monospaced'>
9356 SRCREV = "${AUTOREV}"
9357 </literallayout>
9358 </para>
9359
9360 <para>
9361 Furthermore, you need to reference <filename>SRCPV</filename>
9362 in <filename>PV</filename> in order to automatically update
9363 the version whenever the revision of the source code
9364 changes.
9365 Here is an example:
9366 <literallayout class='monospaced'>
9367 PV = "1.0+git${SRCPV}"
9368 </literallayout>
9369 The OpenEmbedded build system substitutes
9370 <filename>SRCPV</filename> with the following:
9371 <literallayout class='monospaced'>
9372 AUTOINC+<replaceable>source_code_revision</replaceable>
9373 </literallayout>
9374 The build system replaces the <filename>AUTOINC</filename> with
9375 a number.
9376 The number used depends on the state of the PR Service:
9377 <itemizedlist>
9378 <listitem><para>
9379 If PR Service is enabled, the build system increments
9380 the number, which is similar to the behavior of
9381 <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>.
9382 This behavior results in linearly increasing package
9383 versions, which is desirable.
9384 Here is an example:
9385 <literallayout class='monospaced'>
9386 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9387 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
9388 </literallayout>
9389 </para></listitem>
9390 <listitem><para>
9391 If PR Service is not enabled, the build system
9392 replaces the <filename>AUTOINC</filename>
9393 placeholder with zero (i.e. "0").
9394 This results in changing the package version since
9395 the source revision is included.
9396 However, package versions are not increased linearly.
9397 Here is an example:
9398 <literallayout class='monospaced'>
9399 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
9400 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
9401 </literallayout>
9402 </para></listitem>
9403 </itemizedlist>
9404 </para>
9405
9406 <para>
9407 In summary, the OpenEmbedded build system does not track the
9408 history of binary package versions for this purpose.
9409 <filename>AUTOINC</filename>, in this case, is comparable to
9410 <filename>PR</filename>.
9411 If PR server is not enabled, <filename>AUTOINC</filename>
9412 in the package version is simply replaced by "0".
9413 If PR server is enabled, the build system keeps track of the
9414 package versions and bumps the number when the package
9415 revision changes.
9416 </para>
9417 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009418 </section>
9419
9420 <section id='handling-optional-module-packaging'>
9421 <title>Handling Optional Module Packaging</title>
9422
9423 <para>
9424 Many pieces of software split functionality into optional
Brad Bishopc342db32019-05-15 21:57:59 -04009425 modules (or plugins) and the plugins that are built
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009426 might depend on configuration options.
9427 To avoid having to duplicate the logic that determines what
9428 modules are available in your recipe or to avoid having
9429 to package each module by hand, the OpenEmbedded build system
9430 provides functionality to handle module packaging dynamically.
9431 </para>
9432
9433 <para>
9434 To handle optional module packaging, you need to do two things:
9435 <itemizedlist>
9436 <listitem><para>Ensure the module packaging is actually
9437 done.</para></listitem>
9438 <listitem><para>Ensure that any dependencies on optional
9439 modules from other recipes are satisfied by your recipe.
9440 </para></listitem>
9441 </itemizedlist>
9442 </para>
9443
9444 <section id='making-sure-the-packaging-is-done'>
9445 <title>Making Sure the Packaging is Done</title>
9446
9447 <para>
9448 To ensure the module packaging actually gets done, you use
9449 the <filename>do_split_packages</filename> function within
9450 the <filename>populate_packages</filename> Python function
9451 in your recipe.
9452 The <filename>do_split_packages</filename> function
9453 searches for a pattern of files or directories under a
9454 specified path and creates a package for each one it finds
9455 by appending to the
9456 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
9457 variable and setting the appropriate values for
9458 <filename>FILES_packagename</filename>,
9459 <filename>RDEPENDS_packagename</filename>,
9460 <filename>DESCRIPTION_packagename</filename>, and so forth.
9461 Here is an example from the <filename>lighttpd</filename>
9462 recipe:
9463 <literallayout class='monospaced'>
9464 python populate_packages_prepend () {
9465 lighttpd_libdir = d.expand('${libdir}')
9466 do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$',
9467 'lighttpd-module-%s', 'Lighttpd module for %s',
9468 extra_depends='')
9469 }
9470 </literallayout>
9471 The previous example specifies a number of things in the
9472 call to <filename>do_split_packages</filename>.
9473 <itemizedlist>
9474 <listitem><para>A directory within the files installed
9475 by your recipe through <filename>do_install</filename>
9476 in which to search.</para></listitem>
9477 <listitem><para>A regular expression used to match module
9478 files in that directory.
9479 In the example, note the parentheses () that mark
9480 the part of the expression from which the module
9481 name should be derived.</para></listitem>
9482 <listitem><para>A pattern to use for the package names.
9483 </para></listitem>
9484 <listitem><para>A description for each package.
9485 </para></listitem>
9486 <listitem><para>An empty string for
9487 <filename>extra_depends</filename>, which disables
9488 the default dependency on the main
9489 <filename>lighttpd</filename> package.
9490 Thus, if a file in <filename>${libdir}</filename>
9491 called <filename>mod_alias.so</filename> is found,
9492 a package called <filename>lighttpd-module-alias</filename>
9493 is created for it and the
9494 <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink>
9495 is set to "Lighttpd module for alias".</para></listitem>
9496 </itemizedlist>
9497 </para>
9498
9499 <para>
9500 Often, packaging modules is as simple as the previous
9501 example.
9502 However, more advanced options exist that you can use
9503 within <filename>do_split_packages</filename> to modify its
9504 behavior.
9505 And, if you need to, you can add more logic by specifying
9506 a hook function that is called for each package.
9507 It is also perfectly acceptable to call
9508 <filename>do_split_packages</filename> multiple times if
9509 you have more than one set of modules to package.
9510 </para>
9511
9512 <para>
9513 For more examples that show how to use
9514 <filename>do_split_packages</filename>, see the
9515 <filename>connman.inc</filename> file in the
9516 <filename>meta/recipes-connectivity/connman/</filename>
9517 directory of the <filename>poky</filename>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009518 <ulink url='&YOCTO_DOCS_OM_URL;#yocto-project-repositories'>source repository</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009519 You can also find examples in
9520 <filename>meta/classes/kernel.bbclass</filename>.
9521 </para>
9522
9523 <para>
9524 Following is a reference that shows
9525 <filename>do_split_packages</filename> mandatory and
9526 optional arguments:
9527 <literallayout class='monospaced'>
9528 Mandatory arguments
9529
9530 root
9531 The path in which to search
9532 file_regex
9533 Regular expression to match searched files.
9534 Use parentheses () to mark the part of this
9535 expression that should be used to derive the
9536 module name (to be substituted where %s is
9537 used in other function arguments as noted below)
9538 output_pattern
9539 Pattern to use for the package names. Must
9540 include %s.
9541 description
9542 Description to set for each package. Must
9543 include %s.
9544
9545 Optional arguments
9546
9547 postinst
9548 Postinstall script to use for all packages
9549 (as a string)
9550 recursive
9551 True to perform a recursive search - default
9552 False
9553 hook
9554 A hook function to be called for every match.
9555 The function will be called with the following
9556 arguments (in the order listed):
9557
9558 f
9559 Full path to the file/directory match
9560 pkg
9561 The package name
9562 file_regex
9563 As above
9564 output_pattern
9565 As above
9566 modulename
9567 The module name derived using file_regex
9568
9569 extra_depends
9570 Extra runtime dependencies (RDEPENDS) to be
9571 set for all packages. The default value of None
9572 causes a dependency on the main package
9573 (${PN}) - if you do not want this, pass empty
9574 string '' for this parameter.
9575 aux_files_pattern
9576 Extra item(s) to be added to FILES for each
9577 package. Can be a single string item or a list
9578 of strings for multiple items. Must include %s.
9579 postrm
9580 postrm script to use for all packages (as a
9581 string)
9582 allow_dirs
9583 True to allow directories to be matched -
9584 default False
9585 prepend
9586 If True, prepend created packages to PACKAGES
9587 instead of the default False which appends them
9588 match_path
9589 match file_regex on the whole relative path to
9590 the root rather than just the file name
9591 aux_files_pattern_verbatim
9592 Extra item(s) to be added to FILES for each
9593 package, using the actual derived module name
9594 rather than converting it to something legal
9595 for a package name. Can be a single string item
9596 or a list of strings for multiple items. Must
9597 include %s.
9598 allow_links
9599 True to allow symlinks to be matched - default
9600 False
9601 summary
9602 Summary to set for each package. Must include %s;
9603 defaults to description if not set.
9604 </literallayout>
9605 </para>
9606 </section>
9607
9608 <section id='satisfying-dependencies'>
9609 <title>Satisfying Dependencies</title>
9610
9611 <para>
9612 The second part for handling optional module packaging
9613 is to ensure that any dependencies on optional modules
9614 from other recipes are satisfied by your recipe.
9615 You can be sure these dependencies are satisfied by
9616 using the
9617 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable.
9618 Here is an example that continues with the
9619 <filename>lighttpd</filename> recipe shown earlier:
9620 <literallayout class='monospaced'>
9621 PACKAGES_DYNAMIC = "lighttpd-module-.*"
9622 </literallayout>
9623 The name specified in the regular expression can of
9624 course be anything.
9625 In this example, it is <filename>lighttpd-module-</filename>
9626 and is specified as the prefix to ensure that any
9627 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
9628 and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>
9629 on a package name starting with the prefix are satisfied
9630 during build time.
9631 If you are using <filename>do_split_packages</filename>
9632 as described in the previous section, the value you put in
9633 <filename>PACKAGES_DYNAMIC</filename> should correspond to
9634 the name pattern specified in the call to
9635 <filename>do_split_packages</filename>.
9636 </para>
9637 </section>
9638 </section>
9639
9640 <section id='using-runtime-package-management'>
9641 <title>Using Runtime Package Management</title>
9642
9643 <para>
9644 During a build, BitBake always transforms a recipe into one or
9645 more packages.
9646 For example, BitBake takes the <filename>bash</filename> recipe
Brad Bishop316dfdd2018-06-25 12:45:53 -04009647 and produces a number of packages (e.g.
9648 <filename>bash</filename>, <filename>bash-bashbug</filename>,
9649 <filename>bash-completion</filename>,
9650 <filename>bash-completion-dbg</filename>,
9651 <filename>bash-completion-dev</filename>,
9652 <filename>bash-completion-extra</filename>,
9653 <filename>bash-dbg</filename>, and so forth).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009654 Not all generated packages are included in an image.
9655 </para>
9656
9657 <para>
9658 In several situations, you might need to update, add, remove,
9659 or query the packages on a target device at runtime
9660 (i.e. without having to generate a new image).
9661 Examples of such situations include:
9662 <itemizedlist>
9663 <listitem><para>
9664 You want to provide in-the-field updates to deployed
9665 devices (e.g. security updates).
9666 </para></listitem>
9667 <listitem><para>
9668 You want to have a fast turn-around development cycle
9669 for one or more applications that run on your device.
9670 </para></listitem>
9671 <listitem><para>
9672 You want to temporarily install the "debug" packages
9673 of various applications on your device so that
9674 debugging can be greatly improved by allowing
9675 access to symbols and source debugging.
9676 </para></listitem>
9677 <listitem><para>
9678 You want to deploy a more minimal package selection of
9679 your device but allow in-the-field updates to add a
9680 larger selection for customization.
9681 </para></listitem>
9682 </itemizedlist>
9683 </para>
9684
9685 <para>
9686 In all these situations, you have something similar to a more
9687 traditional Linux distribution in that in-field devices
9688 are able to receive pre-compiled packages from a server for
9689 installation or update.
9690 Being able to install these packages on a running,
9691 in-field device is what is termed "runtime package
9692 management".
9693 </para>
9694
9695 <para>
9696 In order to use runtime package management, you
Brad Bishop316dfdd2018-06-25 12:45:53 -04009697 need a host or server machine that serves up the pre-compiled
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009698 packages plus the required metadata.
9699 You also need package manipulation tools on the target.
9700 The build machine is a likely candidate to act as the server.
9701 However, that machine does not necessarily have to be the
9702 package server.
9703 The build machine could push its artifacts to another machine
9704 that acts as the server (e.g. Internet-facing).
Brad Bishop316dfdd2018-06-25 12:45:53 -04009705 In fact, doing so is advantageous for a production
9706 environment as getting the packages away from the
9707 development system's build directory prevents accidental
9708 overwrites.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009709 </para>
9710
9711 <para>
9712 A simple build that targets just one device produces
9713 more than one package database.
9714 In other words, the packages produced by a build are separated
9715 out into a couple of different package groupings based on
9716 criteria such as the target's CPU architecture, the target
9717 board, or the C library used on the target.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009718 For example, a build targeting the <filename>qemux86</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009719 device produces the following three package databases:
Brad Bishop316dfdd2018-06-25 12:45:53 -04009720 <filename>noarch</filename>, <filename>i586</filename>, and
9721 <filename>qemux86</filename>.
9722 If you wanted your <filename>qemux86</filename> device to be
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009723 aware of all the packages that were available to it,
9724 you would need to point it to each of these databases
9725 individually.
9726 In a similar way, a traditional Linux distribution usually is
9727 configured to be aware of a number of software repositories
9728 from which it retrieves packages.
9729 </para>
9730
9731 <para>
9732 Using runtime package management is completely optional and
9733 not required for a successful build or deployment in any
9734 way.
9735 But if you want to make use of runtime package management,
9736 you need to do a couple things above and beyond the basics.
9737 The remainder of this section describes what you need to do.
9738 </para>
9739
9740 <section id='runtime-package-management-build'>
9741 <title>Build Considerations</title>
9742
9743 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009744 This section describes build considerations of which you
9745 need to be aware in order to provide support for runtime
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009746 package management.
9747 </para>
9748
9749 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009750 When BitBake generates packages, it needs to know
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009751 what format or formats to use.
9752 In your configuration, you use the
9753 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009754 variable to specify the format:
9755 <orderedlist>
9756 <listitem><para>
9757 Open the <filename>local.conf</filename> file
9758 inside your
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009759 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009760 (e.g. <filename>~/poky/build/conf/local.conf</filename>).
9761 </para></listitem>
9762 <listitem><para>
9763 Select the desired package format as follows:
9764 <literallayout class='monospaced'>
9765 PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>
9766 </literallayout>
9767 where <replaceable>packageformat</replaceable>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009768 can be "ipk", "rpm", "deb", or "tar" which are the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009769 supported package formats.
9770 <note>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009771 Because the Yocto Project supports four
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009772 different package formats, you can set the
9773 variable with more than one argument.
9774 However, the OpenEmbedded build system only
9775 uses the first argument when creating an image
9776 or Software Development Kit (SDK).
9777 </note>
9778 </para></listitem>
9779 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009780 </para>
9781
9782 <para>
9783 If you would like your image to start off with a basic
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009784 package database containing the packages in your current
9785 build as well as to have the relevant tools available on the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009786 target for runtime package management, you can include
9787 "package-management" in the
9788 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
9789 variable.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009790 Including "package-management" in this configuration
9791 variable ensures that when the image is assembled for your
9792 target, the image includes the currently-known package
9793 databases as well as the target-specific tools required
9794 for runtime package management to be performed on the
9795 target.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009796 However, this is not strictly necessary.
9797 You could start your image off without any databases
9798 but only include the required on-target package
9799 tool(s).
9800 As an example, you could include "opkg" in your
9801 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>
9802 variable if you are using the IPK package format.
9803 You can then initialize your target's package database(s)
9804 later once your image is up and running.
9805 </para>
9806
9807 <para>
9808 Whenever you perform any sort of build step that can
Brad Bishop316dfdd2018-06-25 12:45:53 -04009809 potentially generate a package or modify existing
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009810 package, it is always a good idea to re-generate the
Brad Bishop316dfdd2018-06-25 12:45:53 -04009811 package index after the build by using the following
9812 command:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009813 <literallayout class='monospaced'>
9814 $ bitbake package-index
9815 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009816 It might be tempting to build the package and the
9817 package index at the same time with a command such as
9818 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009819 <literallayout class='monospaced'>
9820 $ bitbake <replaceable>some-package</replaceable> package-index
9821 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009822 Do not do this as BitBake does not schedule the package
9823 index for after the completion of the package you are
9824 building.
9825 Consequently, you cannot be sure of the package index
9826 including information for the package you just built.
9827 Thus, be sure to run the package update step separately
9828 after building any packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009829 </para>
9830
9831 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009832 You can use the
9833 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9834 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9835 and
9836 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9837 variables to pre-configure target images to use a package
9838 feed.
9839 If you do not define these variables, then manual steps
9840 as described in the subsequent sections are necessary to
9841 configure the target.
9842 You should set these variables before building the image
9843 in order to produce a correctly configured image.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009844 </para>
9845
9846 <para>
9847 When your build is complete, your packages reside in the
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009848 <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009849 directory.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009850 For example, if
9851 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009852 is <filename>tmp</filename> and your selected package type
Brad Bishop316dfdd2018-06-25 12:45:53 -04009853 is RPM, then your RPM packages are available in
9854 <filename>tmp/deploy/rpm</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009855 </para>
9856 </section>
9857
9858 <section id='runtime-package-management-server'>
9859 <title>Host or Server Machine Setup</title>
9860
9861 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009862 Although other protocols are possible, a server using HTTP
9863 typically serves packages.
9864 If you want to use HTTP, then set up and configure a
9865 web server such as Apache 2, lighttpd, or
9866 SimpleHTTPServer on the machine serving the packages.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009867 </para>
9868
9869 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009870 To keep things simple, this section describes how to set
9871 up a SimpleHTTPServer web server to share package feeds
9872 from the developer's machine.
9873 Although this server might not be the best for a production
9874 environment, the setup is simple and straight forward.
9875 Should you want to use a different server more suited for
9876 production (e.g. Apache 2, Lighttpd, or Nginx), take the
9877 appropriate steps to do so.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009878 </para>
9879
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009880 <para>
9881 From within the build directory where you have built an
9882 image based on your packaging choice (i.e. the
9883 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink>
9884 setting), simply start the server.
9885 The following example assumes a build directory of
9886 <filename>~/poky/build/tmp/deploy/rpm</filename> and a
9887 <filename>PACKAGE_CLASSES</filename> setting of
9888 "package_rpm":
9889 <literallayout class='monospaced'>
9890 $ cd ~/poky/build/tmp/deploy/rpm
9891 $ python -m SimpleHTTPServer
9892 </literallayout>
9893 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009894 </section>
9895
9896 <section id='runtime-package-management-target'>
9897 <title>Target Setup</title>
9898
9899 <para>
9900 Setting up the target differs depending on the
9901 package management system.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009902 This section provides information for RPM, IPK, and DEB.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009903 </para>
9904
9905 <section id='runtime-package-management-target-rpm'>
9906 <title>Using RPM</title>
9907
9908 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04009909 The
9910 <ulink url='https://en.wikipedia.org/wiki/DNF_(software)'>Dandified Packaging Tool</ulink>
9911 (DNF) performs runtime package management of RPM
9912 packages.
9913 In order to use DNF for runtime package management,
9914 you must perform an initial setup on the target
9915 machine for cases where the
9916 <filename>PACKAGE_FEED_*</filename> variables were not
9917 set as part of the image that is running on the
9918 target.
9919 This means if you built your image and did not not use
9920 these variables as part of the build and your image is
9921 now running on the target, you need to perform the
9922 steps in this section if you want to use runtime
9923 package management.
9924 <note>
9925 For information on the
9926 <filename>PACKAGE_FEED_*</filename> variables, see
9927 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
9928 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>,
9929 and
9930 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
9931 in the Yocto Project Reference Manual variables
9932 glossary.
9933 </note>
9934 </para>
9935
9936 <para>
9937 On the target, you must inform DNF that package
9938 databases are available.
9939 You do this by creating a file named
9940 <filename>/etc/yum.repos.d/oe-packages.repo</filename>
9941 and defining the <filename>oe-packages</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009942 </para>
9943
9944 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009945 As an example, assume the target is able to use the
9946 following package databases:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009947 <filename>all</filename>, <filename>i586</filename>,
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009948 and <filename>qemux86</filename> from a server named
9949 <filename>my.server</filename>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04009950 The specifics for setting up the web server are up to
9951 you.
9952 The critical requirement is that the URIs in the
9953 target repository configuration point to the
9954 correct remote location for the feeds.
9955 <note><title>Tip</title>
9956 For development purposes, you can point the web
9957 server to the build system's
9958 <filename>deploy</filename> directory.
9959 However, for production use, it is better to copy
9960 the package directories to a location outside of
9961 the build area and use that location.
9962 Doing so avoids situations where the build system
9963 overwrites or changes the
9964 <filename>deploy</filename> directory.
9965 </note>
9966 </para>
9967
9968 <para>
9969 When telling DNF where to look for the package
9970 databases, you must declare individual locations
9971 per architecture or a single location used for all
9972 architectures.
9973 You cannot do both:
9974 <itemizedlist>
9975 <listitem><para>
9976 <emphasis>Create an Explicit List of Architectures:</emphasis>
9977 Define individual base URLs to identify where
9978 each package database is located:
9979 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009980 [oe-packages]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009981 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
Brad Bishop316dfdd2018-06-25 12:45:53 -04009982 </literallayout>
9983 This example informs DNF about individual
9984 package databases for all three architectures.
9985 </para></listitem>
9986 <listitem><para>
9987 <emphasis>Create a Single (Full) Package Index:</emphasis>
9988 Define a single base URL that identifies where
9989 a full package database is located:
9990 <literallayout class='monospaced'>
9991 [oe-packages]
9992 baseurl=http://my.server/rpm
9993 </literallayout>
9994 This example informs DNF about a single package
9995 database that contains all the package index
9996 information for all supported architectures.
9997 </para></listitem>
9998 </itemizedlist>
9999 </para>
10000
10001 <para>
10002 Once you have informed DNF where to find the package
10003 databases, you need to fetch them:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010004 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010005 # dnf makecache
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010006 </literallayout>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010007 DNF is now able to find, install, and upgrade packages
10008 from the specified repository or repositories.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010009 <note>
10010 See the
10011 <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink>
10012 for additional information.
10013 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010014 </para>
10015 </section>
10016
10017 <section id='runtime-package-management-target-ipk'>
10018 <title>Using IPK</title>
10019
10020 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010021 The <filename>opkg</filename> application performs
10022 runtime package management of IPK packages.
10023 You must perform an initial setup for
10024 <filename>opkg</filename> on the target machine
10025 if the
10026 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10027 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10028 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10029 variables have not been set or the target image was
10030 built before the variables were set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010031 </para>
10032
10033 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010034 The <filename>opkg</filename> application uses
10035 configuration files to find available package
10036 databases.
10037 Thus, you need to create a configuration file inside
10038 the <filename>/etc/opkg/</filename> direction, which
10039 informs <filename>opkg</filename> of any repository
10040 you want to use.
10041 </para>
10042
10043 <para>
10044 As an example, suppose you are serving packages from a
10045 <filename>ipk/</filename> directory containing the
10046 <filename>i586</filename>,
10047 <filename>all</filename>, and
10048 <filename>qemux86</filename> databases through an
10049 HTTP server named <filename>my.server</filename>.
10050 On the target, create a configuration file
10051 (e.g. <filename>my_repo.conf</filename>) inside the
10052 <filename>/etc/opkg/</filename> directory containing
10053 the following:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010054 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010055 src/gz all http://my.server/ipk/all
10056 src/gz i586 http://my.server/ipk/i586
10057 src/gz qemux86 http://my.server/ipk/qemux86
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010058 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010059 Next, instruct <filename>opkg</filename> to fetch
10060 the repository information:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010061 <literallayout class='monospaced'>
10062 # opkg update
10063 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010064 The <filename>opkg</filename> application is now able
10065 to find, install, and upgrade packages from the
10066 specified repository.
10067 </para>
10068 </section>
10069
10070 <section id='runtime-package-management-target-deb'>
10071 <title>Using DEB</title>
10072
10073 <para>
10074 The <filename>apt</filename> application performs
10075 runtime package management of DEB packages.
10076 This application uses a source list file to find
10077 available package databases.
10078 You must perform an initial setup for
10079 <filename>apt</filename> on the target machine
10080 if the
10081 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>,
10082 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and
10083 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink>
10084 variables have not been set or the target image was
10085 built before the variables were set.
10086 </para>
10087
10088 <para>
10089 To inform <filename>apt</filename> of the repository
10090 you want to use, you might create a list file (e.g.
10091 <filename>my_repo.list</filename>) inside the
10092 <filename>/etc/apt/sources.list.d/</filename>
10093 directory.
10094 As an example, suppose you are serving packages from a
10095 <filename>deb/</filename> directory containing the
10096 <filename>i586</filename>,
10097 <filename>all</filename>, and
10098 <filename>qemux86</filename> databases through an
10099 HTTP server named <filename>my.server</filename>.
10100 The list file should contain:
10101 <literallayout class='monospaced'>
10102 deb http://my.server/deb/all ./
10103 deb http://my.server/deb/i586 ./
10104 deb http://my.server/deb/qemux86 ./
10105 </literallayout>
10106 Next, instruct the <filename>apt</filename>
10107 application to fetch the repository information:
10108 <literallayout class='monospaced'>
10109 # apt-get update
10110 </literallayout>
10111 After this step, <filename>apt</filename> is able
10112 to find, install, and upgrade packages from the
10113 specified repository.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010114 </para>
10115 </section>
10116 </section>
10117 </section>
10118
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010119 <section id='generating-and-using-signed-packages'>
10120 <title>Generating and Using Signed Packages</title>
10121 <para>
10122 In order to add security to RPM packages used during a build,
10123 you can take steps to securely sign them.
10124 Once a signature is verified, the OpenEmbedded build system
10125 can use the package in the build.
10126 If security fails for a signed package, the build system
10127 aborts the build.
10128 </para>
10129
10130 <para>
10131 This section describes how to sign RPM packages during a build
10132 and how to use signed package feeds (repositories) when
10133 doing a build.
10134 </para>
10135
10136 <section id='signing-rpm-packages'>
10137 <title>Signing RPM Packages</title>
10138
10139 <para>
10140 To enable signing RPM packages, you must set up the
10141 following configurations in either your
10142 <filename>local.config</filename> or
10143 <filename>distro.config</filename> file:
10144 <literallayout class='monospaced'>
10145 # Inherit sign_rpm.bbclass to enable signing functionality
10146 INHERIT += " sign_rpm"
10147 # Define the GPG key that will be used for signing.
10148 RPM_GPG_NAME = "<replaceable>key_name</replaceable>"
10149 # Provide passphrase for the key
10150 RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>"
10151 </literallayout>
10152 <note>
10153 Be sure to supply appropriate values for both
10154 <replaceable>key_name</replaceable> and
10155 <replaceable>passphrase</replaceable>
10156 </note>
10157 Aside from the
10158 <filename>RPM_GPG_NAME</filename> and
10159 <filename>RPM_GPG_PASSPHRASE</filename> variables in the
10160 previous example, two optional variables related to signing
10161 exist:
10162 <itemizedlist>
10163 <listitem><para>
10164 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10165 Specifies a <filename>gpg</filename> binary/wrapper
10166 that is executed when the package is signed.
10167 </para></listitem>
10168 <listitem><para>
10169 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10170 Specifies the <filename>gpg</filename> home
10171 directory used when the package is signed.
10172 </para></listitem>
10173 </itemizedlist>
10174 </para>
10175 </section>
10176
10177 <section id='processing-package-feeds'>
10178 <title>Processing Package Feeds</title>
10179
10180 <para>
10181 In addition to being able to sign RPM packages, you can
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010182 also enable signed package feeds for IPK and RPM packages.
10183 </para>
10184
10185 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010186 The steps you need to take to enable signed package feed
10187 use are similar to the steps used to sign RPM packages.
10188 You must define the following in your
10189 <filename>local.config</filename> or
10190 <filename>distro.config</filename> file:
10191 <literallayout class='monospaced'>
10192 INHERIT += "sign_package_feed"
10193 PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>"
10194 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>"
10195 </literallayout>
10196 For signed package feeds, the passphrase must exist in a
10197 separate file, which is pointed to by the
10198 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10199 variable.
10200 Regarding security, keeping a plain text passphrase out of
10201 the configuration is more secure.
10202 </para>
10203
10204 <para>
10205 Aside from the
10206 <filename>PACKAGE_FEED_GPG_NAME</filename> and
10207 <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename>
10208 variables, three optional variables related to signed
10209 package feeds exist:
10210 <itemizedlist>
10211 <listitem><para>
10212 <emphasis><filename>GPG_BIN</filename>:</emphasis>
10213 Specifies a <filename>gpg</filename> binary/wrapper
10214 that is executed when the package is signed.
10215 </para></listitem>
10216 <listitem><para>
10217 <emphasis><filename>GPG_PATH</filename>:</emphasis>
10218 Specifies the <filename>gpg</filename> home
10219 directory used when the package is signed.
10220 </para></listitem>
10221 <listitem><para>
10222 <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis>
10223 Specifies the type of <filename>gpg</filename>
10224 signature.
10225 This variable applies only to RPM and IPK package
10226 feeds.
10227 Allowable values for the
10228 <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>
10229 are "ASC", which is the default and specifies ascii
10230 armored, and "BIN", which specifies binary.
10231 </para></listitem>
10232 </itemizedlist>
10233 </para>
10234 </section>
10235 </section>
10236
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010237 <section id='testing-packages-with-ptest'>
10238 <title>Testing Packages With ptest</title>
10239
10240 <para>
10241 A Package Test (ptest) runs tests against packages built
10242 by the OpenEmbedded build system on the target machine.
10243 A ptest contains at least two items: the actual test, and
10244 a shell script (<filename>run-ptest</filename>) that starts
10245 the test.
10246 The shell script that starts the test must not contain
10247 the actual test - the script only starts the test.
10248 On the other hand, the test can be anything from a simple
10249 shell script that runs a binary and checks the output to
10250 an elaborate system of test binaries and data files.
10251 </para>
10252
10253 <para>
10254 The test generates output in the format used by
10255 Automake:
10256 <literallayout class='monospaced'>
10257 <replaceable>result</replaceable>: <replaceable>testname</replaceable>
10258 </literallayout>
10259 where the result can be <filename>PASS</filename>,
10260 <filename>FAIL</filename>, or <filename>SKIP</filename>,
10261 and the testname can be any identifying string.
10262 </para>
10263
10264 <para>
10265 For a list of Yocto Project recipes that are already
10266 enabled with ptest, see the
10267 <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink>
10268 wiki page.
10269 <note>
10270 A recipe is "ptest-enabled" if it inherits the
10271 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10272 class.
10273 </note>
10274 </para>
10275
10276 <section id='adding-ptest-to-your-build'>
10277 <title>Adding ptest to Your Build</title>
10278
10279 <para>
10280 To add package testing to your build, add the
10281 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>
10282 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>
10283 variables to your <filename>local.conf</filename> file,
10284 which is found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010285 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010286 <literallayout class='monospaced'>
10287 DISTRO_FEATURES_append = " ptest"
10288 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
10289 </literallayout>
10290 Once your build is complete, the ptest files are installed
10291 into the
10292 <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename>
10293 directory within the image, where
10294 <filename><replaceable>package</replaceable></filename>
10295 is the name of the package.
10296 </para>
10297 </section>
10298
10299 <section id='running-ptest'>
10300 <title>Running ptest</title>
10301
10302 <para>
10303 The <filename>ptest-runner</filename> package installs a
10304 shell script that loops through all installed ptest test
10305 suites and runs them in sequence.
10306 Consequently, you might want to add this package to
10307 your image.
10308 </para>
10309 </section>
10310
10311 <section id='getting-your-package-ready'>
10312 <title>Getting Your Package Ready</title>
10313
10314 <para>
10315 In order to enable a recipe to run installed ptests
10316 on target hardware,
10317 you need to prepare the recipes that build the packages
10318 you want to test.
10319 Here is what you have to do for each recipe:
10320 <itemizedlist>
10321 <listitem><para><emphasis>Be sure the recipe
10322 inherits the
10323 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink>
10324 class:</emphasis>
10325 Include the following line in each recipe:
10326 <literallayout class='monospaced'>
10327 inherit ptest
10328 </literallayout>
10329 </para></listitem>
10330 <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis>
10331 This script starts your test.
10332 Locate the script where you will refer to it
10333 using
10334 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>.
10335 Here is an example that starts a test for
10336 <filename>dbus</filename>:
10337 <literallayout class='monospaced'>
10338 #!/bin/sh
10339 cd test
10340 make -k runtest-TESTS
10341 </literallayout>
10342 </para></listitem>
10343 <listitem><para><emphasis>Ensure dependencies are
10344 met:</emphasis>
10345 If the test adds build or runtime dependencies
10346 that normally do not exist for the package
10347 (such as requiring "make" to run the test suite),
10348 use the
10349 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
10350 and
10351 <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>
10352 variables in your recipe in order for the package
10353 to meet the dependencies.
10354 Here is an example where the package has a runtime
10355 dependency on "make":
10356 <literallayout class='monospaced'>
10357 RDEPENDS_${PN}-ptest += "make"
10358 </literallayout>
10359 </para></listitem>
10360 <listitem><para><emphasis>Add a function to build the
10361 test suite:</emphasis>
10362 Not many packages support cross-compilation of
10363 their test suites.
10364 Consequently, you usually need to add a
10365 cross-compilation function to the package.
10366 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010367
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010368 <para>Many packages based on Automake compile and
10369 run the test suite by using a single command
10370 such as <filename>make check</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010371 However, the host <filename>make check</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010372 builds and runs on the same computer, while
10373 cross-compiling requires that the package is built
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010374 on the host but executed for the target
10375 architecture (though often, as in the case for
10376 ptest, the execution occurs on the host).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010377 The built version of Automake that ships with the
10378 Yocto Project includes a patch that separates
10379 building and execution.
10380 Consequently, packages that use the unaltered,
10381 patched version of <filename>make check</filename>
10382 automatically cross-compiles.</para>
10383 <para>Regardless, you still must add a
10384 <filename>do_compile_ptest</filename> function to
10385 build the test suite.
10386 Add a function similar to the following to your
10387 recipe:
10388 <literallayout class='monospaced'>
10389 do_compile_ptest() {
10390 oe_runmake buildtest-TESTS
10391 }
10392 </literallayout>
10393 </para></listitem>
10394 <listitem><para><emphasis>Ensure special configurations
10395 are set:</emphasis>
10396 If the package requires special configurations
10397 prior to compiling the test code, you must
10398 insert a <filename>do_configure_ptest</filename>
10399 function into the recipe.
10400 </para></listitem>
10401 <listitem><para><emphasis>Install the test
10402 suite:</emphasis>
10403 The <filename>ptest</filename> class
10404 automatically copies the file
10405 <filename>run-ptest</filename> to the target and
10406 then runs make <filename>install-ptest</filename>
10407 to run the tests.
10408 If this is not enough, you need to create a
10409 <filename>do_install_ptest</filename> function and
10410 make sure it gets called after the
10411 "make install-ptest" completes.
10412 </para></listitem>
10413 </itemizedlist>
10414 </para>
10415 </section>
10416 </section>
Brad Bishop15ae2502019-06-18 21:44:24 -040010417
10418 <section id='creating-node-package-manager-npm-packages'>
10419 <title>Creating Node Package Manager (NPM) Packages</title>
10420
10421 <para>
10422 <ulink url='https://en.wikipedia.org/wiki/Npm_(software)'>NPM</ulink>
10423 is a package manager for the JavaScript programming
10424 language.
10425 The Yocto Project supports the NPM
10426 <ulink url='&YOCTO_DOCS_BB_URL;#bb-fetchers'>fetcher</ulink>.
10427 You can use this fetcher in combination with
10428 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>
10429 to create recipes that produce NPM packages.
10430 </para>
10431
10432 <para>
10433 Two workflows exist that allow you to create NPM packages
10434 using <filename>devtool</filename>: the NPM registry modules
10435 method and the NPM project code method.
10436 <note>
10437 While it is possible to create NPM recipes manually,
10438 using <filename>devtool</filename> is far simpler.
10439 </note>
10440 Additionally, some requirements and caveats exist.
10441 </para>
10442
10443 <section id='npm-package-creation-requirements'>
10444 <title>Requirements and Caveats</title>
10445
10446 <para>
10447 You need to be aware of the following before using
10448 <filename>devtool</filename> to create NPM packages:
10449 <itemizedlist>
10450 <listitem><para>
10451 Of the two methods that you can use
10452 <filename>devtool</filename> to create NPM
10453 packages, the registry approach is slightly
10454 simpler.
10455 However, you might consider the project
10456 approach because you do not have to publish
10457 your module in the NPM registry
10458 (<ulink url='https://docs.npmjs.com/misc/registry'><filename>npm-registry</filename></ulink>),
10459 which is NPM's public registry.
10460 </para></listitem>
10461 <listitem><para>
10462 Be familiar with
10463 <ulink url='&YOCTO_DOCS_REF_URL;#ref-devtool-reference'><filename>devtool</filename></ulink>.
10464 </para></listitem>
10465 <listitem><para>
10466 The NPM host tools need the native
10467 <filename>nodejs-npm</filename> package, which
10468 is part of the OpenEmbedded environment.
10469 You need to get the package by cloning the
10470 <ulink url='https://github.com/openembedded/meta-openembedded'></ulink>
10471 repository out of GitHub.
10472 Be sure to add the path to your local copy to
10473 your <filename>bblayers.conf</filename> file.
10474 </para></listitem>
10475 <listitem><para>
10476 <filename>devtool</filename> cannot detect
10477 native libraries in module dependencies.
10478 Consequently, you must manually add packages
10479 to your recipe.
10480 </para></listitem>
10481 <listitem><para>
10482 While deploying NPM packages,
10483 <filename>devtool</filename> cannot determine
10484 which dependent packages are missing on the
10485 target (e.g. the node runtime
10486 <filename>nodejs</filename>).
10487 Consequently, you need to find out what
10488 files are missing and be sure they are on the
10489 target.
10490 </para></listitem>
10491 <listitem><para>
10492 Although you might not need NPM to run your
10493 node package, it is useful to have NPM on your
10494 target.
10495 The NPM package name is
10496 <filename>nodejs-npm</filename>.
10497 </para></listitem>
10498 </itemizedlist>
10499 </para>
10500 </section>
10501
10502 <section id='npm-using-the-registry-modules-method'>
10503 <title>Using the Registry Modules Method</title>
10504
10505 <para>
10506 This section presents an example that uses the
10507 <filename>cute-files</filename> module, which is a
10508 file browser web application.
10509 <note>
10510 You must know the <filename>cute-files</filename>
10511 module version.
10512 </note>
10513 </para>
10514
10515 <para>
10516 The first thing you need to do is use
10517 <filename>devtool</filename> and the NPM fetcher to
10518 create the recipe:
10519 <literallayout class='monospaced'>
10520 $ devtool add "npm://registry.npmjs.org;name=cute-files;version=1.0.2"
10521 </literallayout>
10522 The <filename>devtool add</filename> command runs
10523 <filename>recipetool create</filename> and uses the
10524 same fetch URI to download each dependency and capture
10525 license details where possible.
10526 The result is a generated recipe.
10527 </para>
10528
10529 <para>
10530 The recipe file is fairly simple and contains every
10531 license that <filename>recipetool</filename> finds
10532 and includes the licenses in the recipe's
10533 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
10534 variables.
10535 You need to examine the variables and look for those
10536 with "unknown" in the
10537 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
10538 field.
10539 You need to track down the license information for
10540 "unknown" modules and manually add the information to the
10541 recipe.
10542 </para>
10543
10544 <para>
10545 <filename>recipetool</filename> creates "shrinkwrap" and
10546 "lockdown" files for your recipe.
10547 Shrinkwrap files capture the version of all dependent
10548 modules.
10549 Many packages do not provide shrinkwrap files.
10550 <filename>recipetool</filename> create a shrinkwrap
10551 file as it runs.
10552 You can replace the shrinkwrap file with your own file
10553 by setting the <filename>NPM_SHRINKWRAP</filename>
10554 variable.
10555 </para>
10556
10557 <para>
10558 Lockdown files contain the checksum for each module
10559 to determine if your users download the same files when
10560 building with a recipe.
10561 Lockdown files ensure that dependencies have not been
10562 changed and that your NPM registry is still providing
10563 the same file.
10564 <note>
10565 A package is created for each sub-module.
10566 This policy is the only practical way to have the
10567 licenses for all of the dependencies represented
10568 in the license manifest of the image.
10569 </note>
10570 </para>
10571
10572 <para>
10573 The <filename>devtool edit-recipe</filename> command
10574 lets you take a look at the recipe:
10575 <literallayout class='monospaced'>
10576 $ devtool edit-recipe cute-files
10577 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
10578 LICENSE = "BSD-3-Clause &amp; Unknown &amp; MIT &amp; ISC"
10579 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
10580 file://node_modules/content-disposition/LICENSE;md5=c6e0ce1e688c5ff16db06b7259e9cd20 \
10581 file://node_modules/express/LICENSE;md5=5513c00a5c36cd361da863dd9aa8875d \
10582 ...
10583
10584 SRC_URI = "npm://registry.npmjs.org;name=cute-files;version=${PV}"
10585 NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json"
10586 NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"
10587 inherit npm
10588 # Must be set after inherit npm since that itself sets S
10589 S = "${WORKDIR}/npmpkg"
10590
10591 LICENSE_${PN}-content-disposition = "MIT"
10592 ...
10593 LICENSE_${PN}-express = "MIT"
10594 LICENSE_${PN} = "MIT"
10595 </literallayout>
10596 Three key points exist in the previous example:
10597 <itemizedlist>
10598 <listitem><para>
10599 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10600 uses the NPM scheme so that the NPM fetcher
10601 is used.
10602 </para></listitem>
10603 <listitem><para>
10604 <filename>recipetool</filename> collects all
10605 the license information.
10606 If a sub-module's license is unavailable,
10607 the sub-module's name appears in the comments.
10608 </para></listitem>
10609 <listitem><para>
10610 The <filename>inherit npm</filename> statement
10611 causes the
10612 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-npm'><filename>npm</filename></ulink>
10613 class to package up all the modules.
10614 </para></listitem>
10615 </itemizedlist>
10616 </para>
10617
10618 <para>
10619 You can run the following command to build the
10620 <filename>cute-files</filename> package:
10621 <literallayout class='monospaced'>
10622 $ devtool build cute-files
10623 </literallayout>
10624 Remember that <filename>nodejs</filename> must be
10625 installed on the target before your package.
10626 </para>
10627
10628 <para>
10629 Assuming 192.168.7.2 for the target's IP address, use
10630 the following command to deploy your package:
10631 <literallayout class='monospaced'>
10632 $ devtool deploy-target -s cute-files root@192.168.7.2
10633 </literallayout>
10634 Once the package is installed on the target, you can
10635 test the application:
10636 <note>
10637 Because of a know issue, you cannot simply run
10638 <filename>cute-files</filename> as you would if you
10639 had run <filename>npm install</filename>.
10640 </note>
10641 <literallayout class='monospaced'>
10642 $ cd /usr/lib/node_modules/cute-files
10643 $ node cute-files.js
10644 </literallayout>
10645 On a browser, go to
10646 <filename>http://192.168.7.2:3000</filename> and you
10647 see the following:
10648 <imagedata fileref="figures/cute-files-npm-example.png" align="center" width="6in" depth="4in" />
10649 </para>
10650
10651 <para>
10652 You can find the recipe in
10653 <filename>workspace/recipes/cute-files</filename>.
10654 You can use the recipe in any layer you choose.
10655 </para>
10656 </section>
10657
10658 <section id='npm-using-the-npm-projects-method'>
10659 <title>Using the NPM Projects Code Method</title>
10660
10661 <para>
10662 Although it is useful to package modules already in the
10663 NPM registry, adding <filename>node.js</filename> projects
10664 under development is a more common developer use case.
10665 </para>
10666
10667 <para>
10668 This section covers the NPM projects code method, which is
10669 very similar to the "registry" approach described in the
10670 previous section.
10671 In the NPM projects method, you provide
10672 <filename>devtool</filename> with an URL that points to the
10673 source files.
10674 </para>
10675
10676 <para>
10677 Replicating the same example, (i.e.
10678 <filename>cute-files</filename>) use the following command:
10679 <literallayout class='monospaced'>
10680 $ devtool add https://github.com/martinaglv/cute-files.git
10681 </literallayout>
10682 The recipe this command generates is very similar to the
10683 recipe created in the previous section.
10684 However, the <filename>SRC_URI</filename> looks like the
10685 following:
10686 <literallayout class='monospaced'>
10687 SRC_URI = "git://github.com/martinaglv/cute-files.git;protocol=https \
10688 npm://registry.npmjs.org;name=commander;version=2.9.0;subdir=node_modules/commander \
10689 npm://registry.npmjs.org;name=express;version=4.14.0;subdir=node_modules/express \
10690 npm://registry.npmjs.org;name=content-disposition;version=0.3.0;subdir=node_modules/content-disposition \
10691 "
10692 </literallayout>
10693 In this example, the main module is taken from the Git
10694 repository and dependents are taken from the NPM registry.
10695 Other than those differences, the recipe is basically the
10696 same between the two methods.
10697 You can build and deploy the package exactly as described
10698 in the previous section that uses the registry modules
10699 method.
10700 </para>
10701 </section>
10702 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010703 </section>
10704
Brad Bishop316dfdd2018-06-25 12:45:53 -040010705 <section id='efficiently-fetching-source-files-during-a-build'>
10706 <title>Efficiently Fetching Source Files During a Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010707
10708 <para>
10709 The OpenEmbedded build system works with source files located
10710 through the
10711 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
10712 variable.
10713 When you build something using BitBake, a big part of the operation
10714 is locating and downloading all the source tarballs.
10715 For images, downloading all the source for various packages can
10716 take a significant amount of time.
10717 </para>
10718
10719 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010720 This section shows you how you can use mirrors to speed up
10721 fetching source files and how you can pre-fetch files all of which
10722 leads to more efficient use of resources and time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010723 </para>
10724
10725 <section id='setting-up-effective-mirrors'>
10726 <title>Setting up Effective Mirrors</title>
10727
10728 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010729 A good deal that goes into a Yocto Project
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010730 build is simply downloading all of the source tarballs.
10731 Maybe you have been working with another build system
10732 (OpenEmbedded or Angstrom) for which you have built up a
10733 sizable directory of source tarballs.
10734 Or, perhaps someone else has such a directory for which you
10735 have read access.
10736 If so, you can save time by adding statements to your
10737 configuration file so that the build process checks local
10738 directories first for existing tarballs before checking the
10739 Internet.
10740 </para>
10741
10742 <para>
10743 Here is an efficient way to set it up in your
10744 <filename>local.conf</filename> file:
10745 <literallayout class='monospaced'>
10746 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
10747 INHERIT += "own-mirrors"
10748 BB_GENERATE_MIRROR_TARBALLS = "1"
10749 # BB_NO_NETWORK = "1"
10750 </literallayout>
10751 </para>
10752
10753 <para>
10754 In the previous example, the
10755 <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink>
10756 variable causes the OpenEmbedded build system to generate
10757 tarballs of the Git repositories and store them in the
10758 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
10759 directory.
10760 Due to performance reasons, generating and storing these
10761 tarballs is not the build system's default behavior.
10762 </para>
10763
10764 <para>
10765 You can also use the
10766 <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink>
10767 variable.
10768 For an example, see the variable's glossary entry in the
10769 Yocto Project Reference Manual.
10770 </para>
10771 </section>
10772
10773 <section id='getting-source-files-and-suppressing-the-build'>
10774 <title>Getting Source Files and Suppressing the Build</title>
10775
10776 <para>
10777 Another technique you can use to ready yourself for a
10778 successive string of build operations, is to pre-fetch
10779 all the source files without actually starting a build.
10780 This technique lets you work through any download issues
10781 and ultimately gathers all the source files into your
10782 download directory
10783 <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>,
10784 which is located with
10785 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>.
10786 </para>
10787
10788 <para>
10789 Use the following BitBake command form to fetch all the
10790 necessary sources without starting the build:
10791 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040010792 $ bitbake -c <replaceable>target</replaceable> runall="fetch"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010793 </literallayout>
10794 This variation of the BitBake command guarantees that you
10795 have all the sources for that BitBake target should you
10796 disconnect from the Internet and want to do the build
10797 later offline.
10798 </para>
10799 </section>
10800 </section>
10801
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010802 <section id="selecting-an-initialization-manager">
10803 <title>Selecting an Initialization Manager</title>
10804
10805 <para>
10806 By default, the Yocto Project uses SysVinit as the initialization
10807 manager.
10808 However, support also exists for systemd,
10809 which is a full replacement for init with
10810 parallel starting of services, reduced shell overhead and other
10811 features that are used by many distributions.
10812 </para>
10813
10814 <para>
10815 If you want to use SysVinit, you do
10816 not have to do anything.
10817 But, if you want to use systemd, you must
10818 take some steps as described in the following sections.
10819 </para>
10820
10821 <section id='using-systemd-exclusively'>
10822 <title>Using systemd Exclusively</title>
10823
10824 <para>
Brad Bishop15ae2502019-06-18 21:44:24 -040010825 Set these variables in your distribution configuration
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010826 file as follows:
10827 <literallayout class='monospaced'>
10828 DISTRO_FEATURES_append = " systemd"
10829 VIRTUAL-RUNTIME_init_manager = "systemd"
10830 </literallayout>
10831 You can also prevent the SysVinit
10832 distribution feature from
10833 being automatically enabled as follows:
10834 <literallayout class='monospaced'>
10835 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
10836 </literallayout>
10837 Doing so removes any redundant SysVinit scripts.
10838 </para>
10839
10840 <para>
10841 To remove initscripts from your image altogether,
10842 set this variable also:
10843 <literallayout class='monospaced'>
10844 VIRTUAL-RUNTIME_initscripts = ""
10845 </literallayout>
10846 </para>
10847
10848 <para>
10849 For information on the backfill variable, see
10850 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>.
10851 </para>
10852 </section>
10853
10854 <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'>
10855 <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title>
10856
10857 <para>
10858 Set these variables in your distribution configuration
10859 file as follows:
10860 <literallayout class='monospaced'>
10861 DISTRO_FEATURES_append = " systemd"
10862 VIRTUAL-RUNTIME_init_manager = "systemd"
10863 </literallayout>
10864 Doing so causes your main image to use the
10865 <filename>packagegroup-core-boot.bb</filename> recipe and
10866 systemd.
10867 The rescue/minimal image cannot use this package group.
10868 However, it can install SysVinit
10869 and the appropriate packages will have support for both
10870 systemd and SysVinit.
10871 </para>
10872 </section>
10873 </section>
10874
10875 <section id="selecting-dev-manager">
10876 <title>Selecting a Device Manager</title>
10877
10878 <para>
10879 The Yocto Project provides multiple ways to manage the device
10880 manager (<filename>/dev</filename>):
10881 <itemizedlist>
10882 <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis>
10883 For this case, the <filename>/dev</filename> directory
10884 is persistent and the required device nodes are created
10885 during the build.
10886 </para></listitem>
10887 <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis>
10888 For this case, the <filename>/dev</filename> directory
10889 is provided by the kernel as an in-memory file system and
10890 is automatically populated by the kernel at runtime.
10891 Additional configuration of device nodes is done in user
10892 space by a device manager like
10893 <filename>udev</filename> or
10894 <filename>busybox-mdev</filename>.
10895 </para></listitem>
10896 </itemizedlist>
10897 </para>
10898
10899 <section id="static-dev-management">
10900 <title>Using Persistent and Pre-Populated<filename>/dev</filename></title>
10901
10902 <para>
10903 To use the static method for device population, you need to
10904 set the
10905 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10906 variable to "0" as follows:
10907 <literallayout class='monospaced'>
10908 USE_DEVFS = "0"
10909 </literallayout>
10910 </para>
10911
10912 <para>
10913 The content of the resulting <filename>/dev</filename>
10914 directory is defined in a Device Table file.
10915 The
10916 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink>
10917 variable defines the Device Table to use and should be set
10918 in the machine or distro configuration file.
10919 Alternatively, you can set this variable in your
10920 <filename>local.conf</filename> configuration file.
10921 </para>
10922
10923 <para>
10924 If you do not define the
10925 <filename>IMAGE_DEVICE_TABLES</filename> variable, the default
10926 <filename>device_table-minimal.txt</filename> is used:
10927 <literallayout class='monospaced'>
10928 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
10929 </literallayout>
10930 </para>
10931
10932 <para>
10933 The population is handled by the <filename>makedevs</filename>
10934 utility during image creation:
10935 </para>
10936 </section>
10937
10938 <section id="devtmpfs-dev-management">
10939 <title>Using <filename>devtmpfs</filename> and a Device Manager</title>
10940
10941 <para>
10942 To use the dynamic method for device population, you need to
10943 use (or be sure to set) the
10944 <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink>
10945 variable to "1", which is the default:
10946 <literallayout class='monospaced'>
10947 USE_DEVFS = "1"
10948 </literallayout>
10949 With this setting, the resulting <filename>/dev</filename>
10950 directory is populated by the kernel using
10951 <filename>devtmpfs</filename>.
10952 Make sure the corresponding kernel configuration variable
10953 <filename>CONFIG_DEVTMPFS</filename> is set when building
10954 you build a Linux kernel.
10955 </para>
10956
10957 <para>
10958 All devices created by <filename>devtmpfs</filename> will be
10959 owned by <filename>root</filename> and have permissions
10960 <filename>0600</filename>.
10961 </para>
10962
10963 <para>
10964 To have more control over the device nodes, you can use a
10965 device manager like <filename>udev</filename> or
10966 <filename>busybox-mdev</filename>.
10967 You choose the device manager by defining the
10968 <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable
10969 in your machine or distro configuration file.
10970 Alternatively, you can set this variable in your
10971 <filename>local.conf</filename> configuration file:
10972 <literallayout class='monospaced'>
10973 VIRTUAL-RUNTIME_dev_manager = "udev"
10974
10975 # Some alternative values
10976 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
10977 # VIRTUAL-RUNTIME_dev_manager = "systemd"
10978 </literallayout>
10979 </para>
10980 </section>
10981 </section>
10982
10983 <section id="platdev-appdev-srcrev">
10984 <title>Using an External SCM</title>
10985
10986 <para>
10987 If you're working on a recipe that pulls from an external Source
10988 Code Manager (SCM), it is possible to have the OpenEmbedded build
10989 system notice new recipe changes added to the SCM and then build
10990 the resulting packages that depend on the new recipes by using
10991 the latest versions.
10992 This only works for SCMs from which it is possible to get a
10993 sensible revision number for changes.
10994 Currently, you can do this with Apache Subversion (SVN), Git, and
10995 Bazaar (BZR) repositories.
10996 </para>
10997
10998 <para>
10999 To enable this behavior, the
11000 <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>
11001 of the recipe needs to reference
11002 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>.
11003 Here is an example:
11004 <literallayout class='monospaced'>
11005 PV = "1.2.3+git${SRCPV}"
11006 </literallayout>
11007 Then, you can add the following to your
11008 <filename>local.conf</filename>:
11009 <literallayout class='monospaced'>
11010 SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}"
11011 </literallayout>
11012 <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>
11013 is the name of the recipe for which you want to enable automatic source
11014 revision updating.
11015 </para>
11016
11017 <para>
11018 If you do not want to update your local configuration file, you can
11019 add the following directly to the recipe to finish enabling
11020 the feature:
11021 <literallayout class='monospaced'>
11022 SRCREV = "${AUTOREV}"
11023 </literallayout>
11024 </para>
11025
11026 <para>
11027 The Yocto Project provides a distribution named
11028 <filename>poky-bleeding</filename>, whose configuration
11029 file contains the line:
11030 <literallayout class='monospaced'>
11031 require conf/distro/include/poky-floating-revisions.inc
11032 </literallayout>
11033 This line pulls in the listed include file that contains
11034 numerous lines of exactly that form:
11035 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011036 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
11037 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
11038 #SRCREV_pn-opkg ?= "${AUTOREV}"
11039 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
11040 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011041 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
11042 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
11043 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
11044 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
11045 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011046 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
11047 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
11048 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
11049 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011050 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
11051 SRCREV_pn-screenshot ?= "${AUTOREV}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011052 .
11053 .
11054 .
11055 </literallayout>
11056 These lines allow you to experiment with building a
11057 distribution that tracks the latest development source
11058 for numerous packages.
11059 <note><title>Caution</title>
11060 The <filename>poky-bleeding</filename> distribution
11061 is not tested on a regular basis.
11062 Keep this in mind if you use it.
11063 </note>
11064 </para>
11065 </section>
11066
11067 <section id='creating-a-read-only-root-filesystem'>
11068 <title>Creating a Read-Only Root Filesystem</title>
11069
11070 <para>
11071 Suppose, for security reasons, you need to disable
11072 your target device's root filesystem's write permissions
11073 (i.e. you need a read-only root filesystem).
11074 Or, perhaps you are running the device's operating system
11075 from a read-only storage device.
11076 For either case, you can customize your image for
11077 that behavior.
11078 </para>
11079
11080 <note>
11081 Supporting a read-only root filesystem requires that the system and
11082 applications do not try to write to the root filesystem.
11083 You must configure all parts of the target system to write
11084 elsewhere, or to gracefully fail in the event of attempting to
11085 write to the root filesystem.
11086 </note>
11087
11088 <section id='creating-the-root-filesystem'>
11089 <title>Creating the Root Filesystem</title>
11090
11091 <para>
11092 To create the read-only root filesystem, simply add the
11093 "read-only-rootfs" feature to your image.
11094 Using either of the following statements in your
11095 image recipe or from within the
11096 <filename>local.conf</filename> file found in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011097 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011098 causes the build system to create a read-only root filesystem:
11099 <literallayout class='monospaced'>
11100 IMAGE_FEATURES = "read-only-rootfs"
11101 </literallayout>
11102 or
11103 <literallayout class='monospaced'>
11104 EXTRA_IMAGE_FEATURES += "read-only-rootfs"
11105 </literallayout>
11106 </para>
11107
11108 <para>
11109 For more information on how to use these variables, see the
11110 "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>"
11111 section.
11112 For information on the variables, see
11113 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
11114 and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>.
11115 </para>
11116 </section>
11117
11118 <section id='post-installation-scripts'>
11119 <title>Post-Installation Scripts</title>
11120
11121 <para>
11122 It is very important that you make sure all
11123 post-Installation (<filename>pkg_postinst</filename>) scripts
11124 for packages that are installed into the image can be run
11125 at the time when the root filesystem is created during the
11126 build on the host system.
11127 These scripts cannot attempt to run during first-boot on the
11128 target device.
11129 With the "read-only-rootfs" feature enabled,
11130 the build system checks during root filesystem creation to make
11131 sure all post-installation scripts succeed.
11132 If any of these scripts still need to be run after the root
11133 filesystem is created, the build immediately fails.
11134 These build-time checks ensure that the build fails
11135 rather than the target device fails later during its
11136 initial boot operation.
11137 </para>
11138
11139 <para>
11140 Most of the common post-installation scripts generated by the
11141 build system for the out-of-the-box Yocto Project are engineered
11142 so that they can run during root filesystem creation
11143 (e.g. post-installation scripts for caching fonts).
11144 However, if you create and add custom scripts, you need
11145 to be sure they can be run during this file system creation.
11146 </para>
11147
11148 <para>
11149 Here are some common problems that prevent
11150 post-installation scripts from running during root filesystem
11151 creation:
11152 <itemizedlist>
11153 <listitem><para>
11154 <emphasis>Not using $D in front of absolute
11155 paths:</emphasis>
11156 The build system defines
11157 <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink>
11158 when the root filesystem is created.
11159 Furthermore, <filename>$D</filename> is blank when the
11160 script is run on the target device.
11161 This implies two purposes for <filename>$D</filename>:
11162 ensuring paths are valid in both the host and target
11163 environments, and checking to determine which
11164 environment is being used as a method for taking
11165 appropriate actions.
11166 </para></listitem>
11167 <listitem><para>
11168 <emphasis>Attempting to run processes that are
11169 specific to or dependent on the target
11170 architecture:</emphasis>
11171 You can work around these attempts by using native
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011172 tools, which run on the host system,
11173 to accomplish the same tasks, or
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011174 by alternatively running the processes under QEMU,
11175 which has the <filename>qemu_run_binary</filename>
11176 function.
11177 For more information, see the
11178 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink>
11179 class.</para></listitem>
11180 </itemizedlist>
11181 </para>
11182 </section>
11183
11184 <section id='areas-with-write-access'>
11185 <title>Areas With Write Access</title>
11186
11187 <para>
11188 With the "read-only-rootfs" feature enabled,
11189 any attempt by the target to write to the root filesystem at
11190 runtime fails.
11191 Consequently, you must make sure that you configure processes
11192 and applications that attempt these types of writes do so
11193 to directories with write access (e.g.
11194 <filename>/tmp</filename> or <filename>/var/run</filename>).
11195 </para>
11196 </section>
11197 </section>
11198
Brad Bishop316dfdd2018-06-25 12:45:53 -040011199
11200
11201
11202 <section id='maintaining-build-output-quality'>
11203 <title>Maintaining Build Output Quality</title>
11204
11205 <para>
11206 Many factors can influence the quality of a build.
11207 For example, if you upgrade a recipe to use a new version of an
11208 upstream software package or you experiment with some new
11209 configuration options, subtle changes can occur that you might
11210 not detect until later.
11211 Consider the case where your recipe is using a newer version of
11212 an upstream package.
11213 In this case, a new version of a piece of software might
11214 introduce an optional dependency on another library, which is
11215 auto-detected.
11216 If that library has already been built when the software is
11217 building, the software will link to the built library and that
11218 library will be pulled into your image along with the new
11219 software even if you did not want the library.
11220 </para>
11221
11222 <para>
11223 The
11224 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-buildhistory'><filename>buildhistory</filename></ulink>
11225 class exists to help you maintain the quality of your build
11226 output.
11227 You can use the class to highlight unexpected and possibly
11228 unwanted changes in the build output.
11229 When you enable build history, it records information about the
11230 contents of each package and image and then commits that
11231 information to a local Git repository where you can examine
11232 the information.
11233 </para>
11234
11235 <para>
11236 The remainder of this section describes the following:
11237 <itemizedlist>
11238 <listitem><para>
11239 How you can enable and disable build history
11240 </para></listitem>
11241 <listitem><para>
11242 How to understand what the build history contains
11243 </para></listitem>
11244 <listitem><para>
11245 How to limit the information used for build history
11246 </para></listitem>
11247 <listitem><para>
11248 How to examine the build history from both a
11249 command-line and web interface
11250 </para></listitem>
11251 </itemizedlist>
11252 </para>
11253
11254 <section id='enabling-and-disabling-build-history'>
11255 <title>Enabling and Disabling Build History</title>
11256
11257 <para>
11258 Build history is disabled by default.
11259 To enable it, add the following <filename>INHERIT</filename>
11260 statement and set the
11261 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink>
11262 variable to "1" at the end of your
11263 <filename>conf/local.conf</filename> file found in the
11264 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11265 <literallayout class='monospaced'>
11266 INHERIT += "buildhistory"
11267 BUILDHISTORY_COMMIT = "1"
11268 </literallayout>
11269 Enabling build history as previously described causes the
11270 OpenEmbedded build system to collect build output information
11271 and commit it as a single commit to a local
11272 <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>
11273 repository.
11274 <note>
11275 Enabling build history increases your build times slightly,
11276 particularly for images, and increases the amount of disk
11277 space used during the build.
11278 </note>
11279 </para>
11280
11281 <para>
11282 You can disable build history by removing the previous
11283 statements from your <filename>conf/local.conf</filename>
11284 file.
11285 </para>
11286 </section>
11287
11288 <section id='understanding-what-the-build-history-contains'>
11289 <title>Understanding What the Build History Contains</title>
11290
11291 <para>
11292 Build history information is kept in
11293 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TOPDIR'><filename>TOPDIR</filename></ulink><filename>}/buildhistory</filename>
11294 in the Build Directory as defined by the
11295 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_DIR'><filename>BUILDHISTORY_DIR</filename></ulink>
11296 variable.
11297 The following is an example abbreviated listing:
11298 <imagedata fileref="figures/buildhistory.png" align="center" width="6in" depth="4in" />
11299 </para>
11300
11301 <para>
11302 At the top level, a <filename>metadata-revs</filename>
11303 file exists that lists the revisions of the repositories for
11304 the enabled layers when the build was produced.
11305 The rest of the data splits into separate
11306 <filename>packages</filename>, <filename>images</filename>
11307 and <filename>sdk</filename> directories, the contents of
11308 which are described as follows.
11309 </para>
11310
11311 <section id='build-history-package-information'>
11312 <title>Build History Package Information</title>
11313
11314 <para>
11315 The history for each package contains a text file that has
11316 name-value pairs with information about the package.
11317 For example,
11318 <filename>buildhistory/packages/i586-poky-linux/busybox/busybox/latest</filename>
11319 contains the following:
11320 <literallayout class='monospaced'>
11321 PV = 1.22.1
11322 PR = r32
11323 RPROVIDES =
11324 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
11325 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
11326 PKGSIZE = 540168
11327 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
11328 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
11329 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
11330 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
11331 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
11332 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
11333 /etc/busybox.links.nosuid /etc/busybox.links.suid
11334 </literallayout>
11335 Most of these name-value pairs correspond to variables
11336 used to produce the package.
11337 The exceptions are <filename>FILELIST</filename>, which
11338 is the actual list of files in the package, and
11339 <filename>PKGSIZE</filename>, which is the total size of
11340 files in the package in bytes.
11341 </para>
11342
11343 <para>
11344 A file also exists that corresponds to the recipe from
11345 which the package came (e.g.
11346 <filename>buildhistory/packages/i586-poky-linux/busybox/latest</filename>):
11347 <literallayout class='monospaced'>
11348 PV = 1.22.1
11349 PR = r32
11350 DEPENDS = initscripts kern-tools-native update-rc.d-native \
11351 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
11352 virtual/libc virtual/update-alternatives
11353 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
11354 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
11355 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
11356 </literallayout>
11357 </para>
11358
11359 <para>
11360 Finally, for those recipes fetched from a version control
11361 system (e.g., Git), a file exists that lists source
11362 revisions that are specified in the recipe and lists
11363 the actual revisions used during the build.
11364 Listed and actual revisions might differ when
11365 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>
11366 is set to
11367 ${<ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink>}.
11368 Here is an example assuming
11369 <filename>buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev</filename>):
11370 <literallayout class='monospaced'>
11371 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11372 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11373 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11374 SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
11375 </literallayout>
11376 You can use the
11377 <filename>buildhistory-collect-srcrevs</filename>
11378 command with the <filename>-a</filename> option to
11379 collect the stored <filename>SRCREV</filename> values
11380 from build history and report them in a format suitable for
11381 use in global configuration (e.g.,
11382 <filename>local.conf</filename> or a distro include file)
11383 to override floating <filename>AUTOREV</filename> values
11384 to a fixed set of revisions.
11385 Here is some example output from this command:
11386 <literallayout class='monospaced'>
11387 $ buildhistory-collect-srcrevs -a
11388 # i586-poky-linux
11389 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
11390 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
11391 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
11392 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11393 # x86_64-linux
11394 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
11395 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
11396 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
11397 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
11398 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
11399 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
11400 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
11401 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
11402 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
11403 # qemux86-poky-linux
11404 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
11405 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
11406 # all-poky-linux
11407 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
11408 </literallayout>
11409 <note>
11410 Here are some notes on using the
11411 <filename>buildhistory-collect-srcrevs</filename>
11412 command:
11413 <itemizedlist>
11414 <listitem><para>
11415 By default, only values where the
11416 <filename>SRCREV</filename> was not hardcoded
11417 (usually when <filename>AUTOREV</filename>
11418 is used) are reported.
11419 Use the <filename>-a</filename> option to
11420 see all <filename>SRCREV</filename> values.
11421 </para></listitem>
11422 <listitem><para>
11423 The output statements might not have any effect
11424 if overrides are applied elsewhere in the
11425 build system configuration.
11426 Use the <filename>-f</filename> option to add
11427 the <filename>forcevariable</filename> override
11428 to each output line if you need to work around
11429 this restriction.
11430 </para></listitem>
11431 <listitem><para>
11432 The script does apply special handling when
11433 building for multiple machines.
11434 However, the script does place a comment before
11435 each set of values that specifies which
11436 triplet to which they belong as previously
11437 shown (e.g.,
11438 <filename>i586-poky-linux</filename>).
11439 </para></listitem>
11440 </itemizedlist>
11441 </note>
11442 </para>
11443 </section>
11444
11445 <section id='build-history-image-information'>
11446 <title>Build History Image Information</title>
11447
11448 <para>
11449 The files produced for each image are as follows:
11450 <itemizedlist>
11451 <listitem><para>
11452 <filename>image-files:</filename>
11453 A directory containing selected files from the root
11454 filesystem.
11455 The files are defined by
11456 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_IMAGE_FILES'><filename>BUILDHISTORY_IMAGE_FILES</filename></ulink>.
11457 </para></listitem>
11458 <listitem><para>
11459 <filename>build-id.txt:</filename>
11460 Human-readable information about the build
11461 configuration and metadata source revisions.
11462 This file contains the full build header as printed
11463 by BitBake.
11464 </para></listitem>
11465 <listitem><para>
11466 <filename>*.dot:</filename>
11467 Dependency graphs for the image that are
11468 compatible with <filename>graphviz</filename>.
11469 </para></listitem>
11470 <listitem><para>
11471 <filename>files-in-image.txt:</filename>
11472 A list of files in the image with permissions,
11473 owner, group, size, and symlink information.
11474 </para></listitem>
11475 <listitem><para>
11476 <filename>image-info.txt:</filename>
11477 A text file containing name-value pairs with
11478 information about the image.
11479 See the following listing example for more
11480 information.
11481 </para></listitem>
11482 <listitem><para>
11483 <filename>installed-package-names.txt:</filename>
11484 A list of installed packages by name only.
11485 </para></listitem>
11486 <listitem><para>
11487 <filename>installed-package-sizes.txt:</filename>
11488 A list of installed packages ordered by size.
11489 </para></listitem>
11490 <listitem><para>
11491 <filename>installed-packages.txt:</filename>
11492 A list of installed packages with full package
11493 filenames.
11494 </para></listitem>
11495 </itemizedlist>
11496 <note>
11497 Installed package information is able to be gathered
11498 and produced even if package management is disabled
11499 for the final image.
11500 </note>
11501 </para>
11502
11503 <para>
11504 Here is an example of <filename>image-info.txt</filename>:
11505 <literallayout class='monospaced'>
11506 DISTRO = poky
11507 DISTRO_VERSION = 1.7
11508 USER_CLASSES = buildstats image-mklibs image-prelink
11509 IMAGE_CLASSES = image_types
11510 IMAGE_FEATURES = debug-tweaks
11511 IMAGE_LINGUAS =
11512 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
11513 BAD_RECOMMENDATIONS =
11514 NO_RECOMMENDATIONS =
11515 PACKAGE_EXCLUDE =
11516 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
11517 write_image_manifest ; buildhistory_list_installed_image ; \
11518 buildhistory_get_image_installed ; ssh_allow_empty_password; \
11519 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
11520 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
11521 IMAGESIZE = 6900
11522 </literallayout>
11523 Other than <filename>IMAGESIZE</filename>, which is the
11524 total size of the files in the image in Kbytes, the
11525 name-value pairs are variables that may have influenced the
11526 content of the image.
11527 This information is often useful when you are trying to
11528 determine why a change in the package or file
11529 listings has occurred.
11530 </para>
11531 </section>
11532
11533 <section id='using-build-history-to-gather-image-information-only'>
11534 <title>Using Build History to Gather Image Information Only</title>
11535
11536 <para>
11537 As you can see, build history produces image information,
11538 including dependency graphs, so you can see why something
11539 was pulled into the image.
11540 If you are just interested in this information and not
11541 interested in collecting specific package or SDK
11542 information, you can enable writing only image information
11543 without any history by adding the following to your
11544 <filename>conf/local.conf</filename> file found in the
11545 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
11546 <literallayout class='monospaced'>
11547 INHERIT += "buildhistory"
11548 BUILDHISTORY_COMMIT = "0"
11549 BUILDHISTORY_FEATURES = "image"
11550 </literallayout>
11551 Here, you set the
11552 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_FEATURES'><filename>BUILDHISTORY_FEATURES</filename></ulink>
11553 variable to use the image feature only.
11554 </para>
11555 </section>
11556
11557 <section id='build-history-sdk-information'>
11558 <title>Build History SDK Information</title>
11559
11560 <para>
11561 Build history collects similar information on the contents
11562 of SDKs
11563 (e.g. <filename>bitbake -c populate_sdk imagename</filename>)
11564 as compared to information it collects for images.
11565 Furthermore, this information differs depending on whether
11566 an extensible or standard SDK is being produced.
11567 </para>
11568
11569 <para>
11570 The following list shows the files produced for SDKs:
11571 <itemizedlist>
11572 <listitem><para>
11573 <filename>files-in-sdk.txt:</filename>
11574 A list of files in the SDK with permissions,
11575 owner, group, size, and symlink information.
11576 This list includes both the host and target parts
11577 of the SDK.
11578 </para></listitem>
11579 <listitem><para>
11580 <filename>sdk-info.txt:</filename>
11581 A text file containing name-value pairs with
11582 information about the SDK.
11583 See the following listing example for more
11584 information.
11585 </para></listitem>
11586 <listitem><para>
11587 <filename>sstate-task-sizes.txt:</filename>
11588 A text file containing name-value pairs with
11589 information about task group sizes
11590 (e.g. <filename>do_populate_sysroot</filename>
11591 tasks have a total size).
11592 The <filename>sstate-task-sizes.txt</filename> file
11593 exists only when an extensible SDK is created.
11594 </para></listitem>
11595 <listitem><para>
11596 <filename>sstate-package-sizes.txt:</filename>
11597 A text file containing name-value pairs with
11598 information for the shared-state packages and
11599 sizes in the SDK.
11600 The <filename>sstate-package-sizes.txt</filename>
11601 file exists only when an extensible SDK is created.
11602 </para></listitem>
11603 <listitem><para>
11604 <filename>sdk-files:</filename>
11605 A folder that contains copies of the files
11606 mentioned in
11607 <filename>BUILDHISTORY_SDK_FILES</filename> if the
11608 files are present in the output.
11609 Additionally, the default value of
11610 <filename>BUILDHISTORY_SDK_FILES</filename> is
11611 specific to the extensible SDK although you can
11612 set it differently if you would like to pull in
11613 specific files from the standard SDK.</para>
11614
11615 <para>The default files are
11616 <filename>conf/local.conf</filename>,
11617 <filename>conf/bblayers.conf</filename>,
11618 <filename>conf/auto.conf</filename>,
11619 <filename>conf/locked-sigs.inc</filename>, and
11620 <filename>conf/devtool.conf</filename>.
11621 Thus, for an extensible SDK, these files get
11622 copied into the <filename>sdk-files</filename>
11623 directory.
11624 </para></listitem>
11625 <listitem><para>
11626 The following information appears under
11627 each of the <filename>host</filename>
11628 and <filename>target</filename> directories
11629 for the portions of the SDK that run on the host
11630 and on the target, respectively:
11631 <note>
11632 The following files for the most part are empty
11633 when producing an extensible SDK because this
11634 type of SDK is not constructed from packages
11635 as is the standard SDK.
11636 </note>
11637 <itemizedlist>
11638 <listitem><para>
11639 <filename>depends.dot:</filename>
11640 Dependency graph for the SDK that is
11641 compatible with
11642 <filename>graphviz</filename>.
11643 </para></listitem>
11644 <listitem><para>
11645 <filename>installed-package-names.txt:</filename>
11646 A list of installed packages by name only.
11647 </para></listitem>
11648 <listitem><para>
11649 <filename>installed-package-sizes.txt:</filename>
11650 A list of installed packages ordered by size.
11651 </para></listitem>
11652 <listitem><para>
11653 <filename>installed-packages.txt:</filename>
11654 A list of installed packages with full
11655 package filenames.
11656 </para></listitem>
11657 </itemizedlist>
11658 </para></listitem>
11659 </itemizedlist>
11660 </para>
11661
11662 <para>
11663 Here is an example of <filename>sdk-info.txt</filename>:
11664 <literallayout class='monospaced'>
11665 DISTRO = poky
11666 DISTRO_VERSION = 1.3+snapshot-20130327
11667 SDK_NAME = poky-glibc-i686-arm
11668 SDK_VERSION = 1.3+snapshot
11669 SDKMACHINE =
11670 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
11671 BAD_RECOMMENDATIONS =
11672 SDKSIZE = 352712
11673 </literallayout>
11674 Other than <filename>SDKSIZE</filename>, which is the
11675 total size of the files in the SDK in Kbytes, the
11676 name-value pairs are variables that might have influenced
11677 the content of the SDK.
11678 This information is often useful when you are trying to
11679 determine why a change in the package or file listings
11680 has occurred.
11681 </para>
11682 </section>
11683
11684 <section id='examining-build-history-information'>
11685 <title>Examining Build History Information</title>
11686
11687 <para>
11688 You can examine build history output from the command
11689 line or from a web interface.
11690 </para>
11691
11692 <para>
11693 To see any changes that have occurred (assuming you have
11694 <ulink url='&YOCTO_DOCS_REF_URL;#var-BUILDHISTORY_COMMIT'><filename>BUILDHISTORY_COMMIT</filename></ulink><filename>&nbsp;= "1"</filename>),
11695 you can simply use any Git command that allows you to
11696 view the history of a repository.
11697 Here is one method:
11698 <literallayout class='monospaced'>
11699 $ git log -p
11700 </literallayout>
11701 You need to realize, however, that this method does show
11702 changes that are not significant (e.g. a package's size
11703 changing by a few bytes).
11704 </para>
11705
11706 <para>
11707 A command-line tool called
11708 <filename>buildhistory-diff</filename> does exist, though,
11709 that queries the Git repository and prints just the
11710 differences that might be significant in human-readable
11711 form.
11712 Here is an example:
11713 <literallayout class='monospaced'>
11714 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
11715 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
11716 /etc/anotherpkg.conf was added
11717 /sbin/anotherpkg was added
11718 * (installed-package-names.txt):
11719 * anotherpkg was added
11720 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
11721 anotherpkg was added
11722 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
11723 * PR changed from "r0" to "r1"
11724 * PV changed from "0.1.10" to "0.1.12"
11725 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
11726 * PR changed from "r0" to "r1"
11727 * PV changed from "0.1.10" to "0.1.12"
11728 </literallayout>
11729 <note>
11730 The <filename>buildhistory-diff</filename> tool
11731 requires the <filename>GitPython</filename> package.
11732 Be sure to install it using Pip3 as follows:
11733 <literallayout class='monospaced'>
11734 $ pip3 install GitPython --user
11735 </literallayout>
11736 Alternatively, you can install
11737 <filename>python3-git</filename> using the appropriate
11738 distribution package manager (e.g.
11739 <filename>apt-get</filename>, <filename>dnf</filename>,
11740 or <filename>zipper</filename>).
11741 </note>
11742 </para>
11743
11744 <para>
11745 To see changes to the build history using a web interface,
11746 follow the instruction in the <filename>README</filename>
11747 file here.
11748 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/buildhistory-web/'></ulink>.
11749 </para>
11750
11751 <para>
11752 Here is a sample screenshot of the interface:
11753 <imagedata fileref="figures/buildhistory-web.png" align="center" scalefit="1" width="130%" contentdepth="130%" />
11754 </para>
11755 </section>
11756 </section>
11757 </section>
11758
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011759 <section id="performing-automated-runtime-testing">
11760 <title>Performing Automated Runtime Testing</title>
11761
11762 <para>
11763 The OpenEmbedded build system makes available a series of automated
11764 tests for images to verify runtime functionality.
11765 You can run these tests on either QEMU or actual target hardware.
11766 Tests are written in Python making use of the
11767 <filename>unittest</filename> module, and the majority of them
11768 run commands on the target system over SSH.
11769 This section describes how you set up the environment to use these
11770 tests, run available tests, and write and add your own tests.
11771 </para>
11772
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011773 <para>
11774 For information on the test and QA infrastructure available
11775 within the Yocto Project, see the
11776 "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>"
11777 section in the Yocto Project Reference Manual.
11778 </para>
11779
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011780 <section id='enabling-tests'>
11781 <title>Enabling Tests</title>
11782
11783 <para>
11784 Depending on whether you are planning to run tests using
11785 QEMU or on the hardware, you have to take
11786 different steps to enable the tests.
11787 See the following subsections for information on how to
11788 enable both types of tests.
11789 </para>
11790
11791 <section id='qemu-image-enabling-tests'>
11792 <title>Enabling Runtime Tests on QEMU</title>
11793
11794 <para>
11795 In order to run tests, you need to do the following:
11796 <itemizedlist>
11797 <listitem><para><emphasis>Set up to avoid interaction
11798 with <filename>sudo</filename> for networking:</emphasis>
11799 To accomplish this, you must do one of the
11800 following:
11801 <itemizedlist>
11802 <listitem><para>Add
11803 <filename>NOPASSWD</filename> for your user
11804 in <filename>/etc/sudoers</filename> either for
11805 all commands or just for
11806 <filename>runqemu-ifup</filename>.
11807 You must provide the full path as that can
11808 change if you are using multiple clones of the
11809 source repository.
11810 <note>
11811 On some distributions, you also need to
11812 comment out "Defaults requiretty" in
11813 <filename>/etc/sudoers</filename>.
11814 </note></para></listitem>
11815 <listitem><para>Manually configure a tap interface
11816 for your system.</para></listitem>
11817 <listitem><para>Run as root the script in
11818 <filename>scripts/runqemu-gen-tapdevs</filename>,
11819 which should generate a list of tap devices.
11820 This is the option typically chosen for
11821 Autobuilder-type environments.
Brad Bishop316dfdd2018-06-25 12:45:53 -040011822 <note><title>Notes</title>
11823 <itemizedlist>
11824 <listitem><para>
11825 Be sure to use an absolute path
11826 when calling this script
11827 with sudo.
11828 </para></listitem>
11829 <listitem><para>
11830 The package recipe
11831 <filename>qemu-helper-native</filename>
11832 is required to run this script.
11833 Build the package using the
11834 following command:
11835 <literallayout class='monospaced'>
11836 $ bitbake qemu-helper-native
11837 </literallayout>
11838 </para></listitem>
11839 </itemizedlist>
11840 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011841 </para></listitem>
11842 </itemizedlist></para></listitem>
11843 <listitem><para><emphasis>Set the
11844 <filename>DISPLAY</filename> variable:</emphasis>
11845 You need to set this variable so that you have an X
11846 server available (e.g. start
11847 <filename>vncserver</filename> for a headless machine).
11848 </para></listitem>
11849 <listitem><para><emphasis>Be sure your host's firewall
11850 accepts incoming connections from
11851 192.168.7.0/24:</emphasis>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011852 Some of the tests (in particular DNF tests) start
11853 an HTTP server on a random high number port,
11854 which is used to serve files to the target.
11855 The DNF module serves
11856 <filename>${WORKDIR}/oe-rootfs-repo</filename>
11857 so it can run DNF channel commands.
11858 That means your host's firewall
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011859 must accept incoming connections from 192.168.7.0/24,
11860 which is the default IP range used for tap devices
11861 by <filename>runqemu</filename>.</para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011862 <listitem><para><emphasis>Be sure your host has the
11863 correct packages installed:</emphasis>
11864 Depending your host's distribution, you need
11865 to have the following packages installed:
11866 <itemizedlist>
11867 <listitem><para>Ubuntu and Debian:
11868 <filename>sysstat</filename> and
11869 <filename>iproute2</filename>
11870 </para></listitem>
11871 <listitem><para>OpenSUSE:
11872 <filename>sysstat</filename> and
11873 <filename>iproute2</filename>
11874 </para></listitem>
11875 <listitem><para>Fedora:
11876 <filename>sysstat</filename> and
11877 <filename>iproute</filename>
11878 </para></listitem>
11879 <listitem><para>CentOS:
11880 <filename>sysstat</filename> and
11881 <filename>iproute</filename>
11882 </para></listitem>
11883 </itemizedlist>
11884 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011885 </itemizedlist>
11886 </para>
11887
11888 <para>
11889 Once you start running the tests, the following happens:
11890 <orderedlist>
11891 <listitem><para>A copy of the root filesystem is written
11892 to <filename>${WORKDIR}/testimage</filename>.
11893 </para></listitem>
11894 <listitem><para>The image is booted under QEMU using the
11895 standard <filename>runqemu</filename> script.
11896 </para></listitem>
11897 <listitem><para>A default timeout of 500 seconds occurs
11898 to allow for the boot process to reach the login prompt.
11899 You can change the timeout period by setting
11900 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink>
11901 in the <filename>local.conf</filename> file.
11902 </para></listitem>
11903 <listitem><para>Once the boot process is reached and the
11904 login prompt appears, the tests run.
11905 The full boot log is written to
11906 <filename>${WORKDIR}/testimage/qemu_boot_log</filename>.
11907 </para></listitem>
11908 <listitem><para>Each test module loads in the order found
11909 in <filename>TEST_SUITES</filename>.
11910 You can find the full output of the commands run over
11911 SSH in
11912 <filename>${WORKDIR}/testimgage/ssh_target_log</filename>.
11913 </para></listitem>
11914 <listitem><para>If no failures occur, the task running the
11915 tests ends successfully.
11916 You can find the output from the
11917 <filename>unittest</filename> in the task log at
11918 <filename>${WORKDIR}/temp/log.do_testimage</filename>.
11919 </para></listitem>
11920 </orderedlist>
11921 </para>
11922 </section>
11923
11924 <section id='hardware-image-enabling-tests'>
11925 <title>Enabling Runtime Tests on Hardware</title>
11926
11927 <para>
11928 The OpenEmbedded build system can run tests on real
11929 hardware, and for certain devices it can also deploy
11930 the image to be tested onto the device beforehand.
11931 </para>
11932
11933 <para>
11934 For automated deployment, a "master image" is installed
11935 onto the hardware once as part of setup.
11936 Then, each time tests are to be run, the following
11937 occurs:
11938 <orderedlist>
11939 <listitem><para>The master image is booted into and
11940 used to write the image to be tested to
11941 a second partition.
11942 </para></listitem>
11943 <listitem><para>The device is then rebooted using an
11944 external script that you need to provide.
11945 </para></listitem>
11946 <listitem><para>The device boots into the image to be
11947 tested.
11948 </para></listitem>
11949 </orderedlist>
11950 </para>
11951
11952 <para>
11953 When running tests (independent of whether the image
11954 has been deployed automatically or not), the device is
11955 expected to be connected to a network on a
11956 pre-determined IP address.
11957 You can either use static IP addresses written into
11958 the image, or set the image to use DHCP and have your
11959 DHCP server on the test network assign a known IP address
11960 based on the MAC address of the device.
11961 </para>
11962
11963 <para>
11964 In order to run tests on hardware, you need to set
11965 <filename>TEST_TARGET</filename> to an appropriate value.
11966 For QEMU, you do not have to change anything, the default
11967 value is "QemuTarget".
11968 For running tests on hardware, the following options exist:
11969 <itemizedlist>
11970 <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis>
11971 Choose "SimpleRemoteTarget" if you are going to
11972 run tests on a target system that is already
11973 running the image to be tested and is available
11974 on the network.
11975 You can use "SimpleRemoteTarget" in conjunction
11976 with either real hardware or an image running
11977 within a separately started QEMU or any
11978 other virtual machine manager.
11979 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011980 <listitem><para><emphasis>"SystemdbootTarget":</emphasis>
11981 Choose "SystemdbootTarget" if your hardware is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011982 an EFI-based machine with
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011983 <filename>systemd-boot</filename> as bootloader and
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011984 <filename>core-image-testmaster</filename>
11985 (or something similar) is installed.
11986 Also, your hardware under test must be in a
11987 DHCP-enabled network that gives it the same IP
11988 address for each reboot.</para>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011989 <para>If you choose "SystemdbootTarget", there are
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011990 additional requirements and considerations.
11991 See the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011992 "<link linkend='selecting-systemdboottarget'>Selecting SystemdbootTarget</link>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011993 section, which follows, for more information.
11994 </para></listitem>
11995 <listitem><para><emphasis>"BeagleBoneTarget":</emphasis>
11996 Choose "BeagleBoneTarget" if you are deploying
11997 images and running tests on the BeagleBone
11998 "Black" or original "White" hardware.
11999 For information on how to use these tests, see the
12000 comments at the top of the BeagleBoneTarget
12001 <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename>
12002 file.
12003 </para></listitem>
12004 <listitem><para><emphasis>"EdgeRouterTarget":</emphasis>
12005 Choose "EdgeRouterTarget" is you are deploying
12006 images and running tests on the Ubiquiti Networks
12007 EdgeRouter Lite.
12008 For information on how to use these tests, see the
12009 comments at the top of the EdgeRouterTarget
12010 <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename>
12011 file.
12012 </para></listitem>
12013 <listitem><para><emphasis>"GrubTarget":</emphasis>
12014 Choose the "supports deploying images and running
12015 tests on any generic PC that boots using GRUB.
12016 For information on how to use these tests, see the
12017 comments at the top of the GrubTarget
12018 <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename>
12019 file.
12020 </para></listitem>
12021 <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis>
12022 Create your own custom target if you want to run
12023 tests when you are deploying images and running
12024 tests on a custom machine within your BSP layer.
12025 To do this, you need to add a Python unit that
12026 defines the target class under
12027 <filename>lib/oeqa/controllers/</filename> within
12028 your layer.
12029 You must also provide an empty
12030 <filename>__init__.py</filename>.
12031 For examples, see files in
12032 <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>.
12033 </para></listitem>
12034 </itemizedlist>
12035 </para>
12036 </section>
12037
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012038 <section id='selecting-systemdboottarget'>
12039 <title>Selecting SystemdbootTarget</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012040
12041 <para>
12042 If you did not set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012043 "SystemdbootTarget", then you do not need any information
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012044 in this section.
12045 You can skip down to the
12046 "<link linkend='qemu-image-running-tests'>Running Tests</link>"
12047 section.
12048 </para>
12049
12050 <para>
12051 If you did set <filename>TEST_TARGET</filename> to
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012052 "SystemdbootTarget", you also need to perform a one-time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012053 setup of your master image by doing the following:
12054 <orderedlist>
12055 <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis>
12056 Be sure that <filename>EFI_PROVIDER</filename>
12057 is as follows:
12058 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012059 EFI_PROVIDER = "systemd-boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012060 </literallayout>
12061 </para></listitem>
12062 <listitem><para><emphasis>Build the master image:</emphasis>
12063 Build the <filename>core-image-testmaster</filename>
12064 image.
12065 The <filename>core-image-testmaster</filename>
12066 recipe is provided as an example for a
12067 "master" image and you can customize the image
12068 recipe as you would any other recipe.
12069 </para>
12070 <para>Here are the image recipe requirements:
12071 <itemizedlist>
12072 <listitem><para>Inherits
12073 <filename>core-image</filename>
12074 so that kernel modules are installed.
12075 </para></listitem>
12076 <listitem><para>Installs normal linux utilities
12077 not busybox ones (e.g.
12078 <filename>bash</filename>,
12079 <filename>coreutils</filename>,
12080 <filename>tar</filename>,
12081 <filename>gzip</filename>, and
12082 <filename>kmod</filename>).
12083 </para></listitem>
12084 <listitem><para>Uses a custom
12085 Initial RAM Disk (initramfs) image with a
12086 custom installer.
12087 A normal image that you can install usually
12088 creates a single rootfs partition.
12089 This image uses another installer that
12090 creates a specific partition layout.
12091 Not all Board Support Packages (BSPs)
12092 can use an installer.
12093 For such cases, you need to manually create
12094 the following partition layout on the
12095 target:
12096 <itemizedlist>
12097 <listitem><para>First partition mounted
12098 under <filename>/boot</filename>,
12099 labeled "boot".
12100 </para></listitem>
12101 <listitem><para>The main rootfs
12102 partition where this image gets
12103 installed, which is mounted under
12104 <filename>/</filename>.
12105 </para></listitem>
12106 <listitem><para>Another partition
12107 labeled "testrootfs" where test
12108 images get deployed.
12109 </para></listitem>
12110 </itemizedlist>
12111 </para></listitem>
12112 </itemizedlist>
12113 </para></listitem>
12114 <listitem><para><emphasis>Install image:</emphasis>
12115 Install the image that you just built on the target
12116 system.
12117 </para></listitem>
12118 </orderedlist>
12119 </para>
12120
12121 <para>
12122 The final thing you need to do when setting
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012123 <filename>TEST_TARGET</filename> to "SystemdbootTarget" is
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012124 to set up the test image:
12125 <orderedlist>
12126 <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis>
12127 Make sure you have the following statements in
12128 your <filename>local.conf</filename> file:
12129 <literallayout class='monospaced'>
12130 IMAGE_FSTYPES += "tar.gz"
12131 INHERIT += "testimage"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012132 TEST_TARGET = "SystemdbootTarget"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012133 TEST_TARGET_IP = "192.168.2.3"
12134 </literallayout>
12135 </para></listitem>
12136 <listitem><para><emphasis>Build your test image:</emphasis>
12137 Use BitBake to build the image:
12138 <literallayout class='monospaced'>
12139 $ bitbake core-image-sato
12140 </literallayout>
12141 </para></listitem>
12142 </orderedlist>
12143 </para>
12144 </section>
12145
12146 <section id='power-control'>
12147 <title>Power Control</title>
12148
12149 <para>
12150 For most hardware targets other than SimpleRemoteTarget,
12151 you can control power:
12152 <itemizedlist>
12153 <listitem><para>
12154 You can use
12155 <filename>TEST_POWERCONTROL_CMD</filename>
12156 together with
12157 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12158 as a command that runs on the host and does power
12159 cycling.
12160 The test code passes one argument to that command:
12161 off, on or cycle (off then on).
12162 Here is an example that could appear in your
12163 <filename>local.conf</filename> file:
12164 <literallayout class='monospaced'>
12165 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
12166 </literallayout>
12167 In this example, the expect script does the
12168 following:
12169 <literallayout class='monospaced'>
12170 ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>"
12171 </literallayout>
12172 It then runs a Python script that controls power
12173 for a label called <filename>nuc1</filename>.
12174 <note>
12175 You need to customize
12176 <filename>TEST_POWERCONTROL_CMD</filename>
12177 and
12178 <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename>
12179 for your own setup.
12180 The one requirement is that it accepts
12181 "on", "off", and "cycle" as the last argument.
12182 </note>
12183 </para></listitem>
12184 <listitem><para>
12185 When no command is defined, it connects to the
12186 device over SSH and uses the classic reboot command
12187 to reboot the device.
12188 Classic reboot is fine as long as the machine
12189 actually reboots (i.e. the SSH test has not
12190 failed).
12191 It is useful for scenarios where you have a simple
12192 setup, typically with a single board, and where
12193 some manual interaction is okay from time to time.
12194 </para></listitem>
12195 </itemizedlist>
12196 If you have no hardware to automatically perform power
12197 control but still wish to experiment with automated
12198 hardware testing, you can use the dialog-power-control
12199 script that shows a dialog prompting you to perform the
12200 required power action.
12201 This script requires either KDialog or Zenity to be
12202 installed.
12203 To use this script, set the
12204 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink>
12205 variable as follows:
12206 <literallayout class='monospaced'>
12207 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
12208 </literallayout>
12209 </para>
12210 </section>
12211
12212 <section id='serial-console-connection'>
12213 <title>Serial Console Connection</title>
12214
12215 <para>
12216 For test target classes requiring a serial console
12217 to interact with the bootloader (e.g. BeagleBoneTarget,
12218 EdgeRouterTarget, and GrubTarget), you need to
12219 specify a command to use to connect to the serial console
12220 of the target machine by using the
12221 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink>
12222 variable and optionally the
12223 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink>
12224 variable.
12225 </para>
12226
12227 <para>
12228 These cases could be a serial terminal program if the
12229 machine is connected to a local serial port, or a
12230 <filename>telnet</filename> or
12231 <filename>ssh</filename> command connecting to a remote
12232 console server.
12233 Regardless of the case, the command simply needs to
12234 connect to the serial console and forward that connection
12235 to standard input and output as any normal terminal
12236 program does.
12237 For example, to use the picocom terminal program on
12238 serial device <filename>/dev/ttyUSB0</filename>
12239 at 115200bps, you would set the variable as follows:
12240 <literallayout class='monospaced'>
12241 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
12242 </literallayout>
12243 For local devices where the serial port device disappears
12244 when the device reboots, an additional "serdevtry" wrapper
12245 script is provided.
12246 To use this wrapper, simply prefix the terminal command
12247 with
12248 <filename>${COREBASE}/scripts/contrib/serdevtry</filename>:
12249 <literallayout class='monospaced'>
12250 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b
12251115200 /dev/ttyUSB0"
12252 </literallayout>
12253 </para>
12254 </section>
12255 </section>
12256
12257 <section id="qemu-image-running-tests">
12258 <title>Running Tests</title>
12259
12260 <para>
12261 You can start the tests automatically or manually:
12262 <itemizedlist>
12263 <listitem><para><emphasis>Automatically running tests:</emphasis>
12264 To run the tests automatically after the
12265 OpenEmbedded build system successfully creates an image,
12266 first set the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012267 <ulink url='&YOCTO_DOCS_REF_URL;#var-TESTIMAGE_AUTO'><filename>TESTIMAGE_AUTO</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012268 variable to "1" in your <filename>local.conf</filename>
12269 file in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012270 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012271 <literallayout class='monospaced'>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012272 TESTIMAGE_AUTO = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012273 </literallayout>
12274 Next, build your image.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012275 If the image successfully builds, the tests run:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012276 <literallayout class='monospaced'>
12277 bitbake core-image-sato
12278 </literallayout></para></listitem>
12279 <listitem><para><emphasis>Manually running tests:</emphasis>
12280 To manually run the tests, first globally inherit the
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012281 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012282 class by editing your <filename>local.conf</filename>
12283 file:
12284 <literallayout class='monospaced'>
12285 INHERIT += "testimage"
12286 </literallayout>
12287 Next, use BitBake to run the tests:
12288 <literallayout class='monospaced'>
12289 bitbake -c testimage <replaceable>image</replaceable>
12290 </literallayout></para></listitem>
12291 </itemizedlist>
12292 </para>
12293
12294 <para>
12295 All test files reside in
12296 <filename>meta/lib/oeqa/runtime</filename> in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012297 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012298 A test name maps directly to a Python module.
12299 Each test module may contain a number of individual tests.
12300 Tests are usually grouped together by the area
12301 tested (e.g tests for systemd reside in
12302 <filename>meta/lib/oeqa/runtime/systemd.py</filename>).
12303 </para>
12304
12305 <para>
12306 You can add tests to any layer provided you place them in the
12307 proper area and you extend
12308 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12309 in the <filename>local.conf</filename> file as normal.
12310 Be sure that tests reside in
12311 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>.
12312 <note>
12313 Be sure that module names do not collide with module names
12314 used in the default set of test modules in
12315 <filename>meta/lib/oeqa/runtime</filename>.
12316 </note>
12317 </para>
12318
12319 <para>
12320 You can change the set of tests run by appending or overriding
12321 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>
12322 variable in <filename>local.conf</filename>.
12323 Each name in <filename>TEST_SUITES</filename> represents a
12324 required test for the image.
12325 Test modules named within <filename>TEST_SUITES</filename>
12326 cannot be skipped even if a test is not suitable for an image
12327 (e.g. running the RPM tests on an image without
12328 <filename>rpm</filename>).
12329 Appending "auto" to <filename>TEST_SUITES</filename> causes the
12330 build system to try to run all tests that are suitable for the
12331 image (i.e. each test module may elect to skip itself).
12332 </para>
12333
12334 <para>
12335 The order you list tests in <filename>TEST_SUITES</filename>
12336 is important and influences test dependencies.
12337 Consequently, tests that depend on other tests should be added
12338 after the test on which they depend.
12339 For example, since the <filename>ssh</filename> test
12340 depends on the
12341 <filename>ping</filename> test, "ssh" needs to come after
12342 "ping" in the list.
12343 The test class provides no re-ordering or dependency handling.
12344 <note>
12345 Each module can have multiple classes with multiple test
12346 methods.
12347 And, Python <filename>unittest</filename> rules apply.
12348 </note>
12349 </para>
12350
12351 <para>
12352 Here are some things to keep in mind when running tests:
12353 <itemizedlist>
12354 <listitem><para>The default tests for the image are defined
12355 as:
12356 <literallayout class='monospaced'>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012357 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 -050012358 </literallayout></para></listitem>
12359 <listitem><para>Add your own test to the list of the
12360 by using the following:
12361 <literallayout class='monospaced'>
12362 TEST_SUITES_append = " mytest"
12363 </literallayout></para></listitem>
12364 <listitem><para>Run a specific list of tests as follows:
12365 <literallayout class='monospaced'>
12366 TEST_SUITES = "test1 test2 test3"
12367 </literallayout>
12368 Remember, order is important.
12369 Be sure to place a test that is dependent on another test
12370 later in the order.</para></listitem>
12371 </itemizedlist>
12372 </para>
12373 </section>
12374
12375 <section id="exporting-tests">
12376 <title>Exporting Tests</title>
12377
12378 <para>
12379 You can export tests so that they can run independently of
12380 the build system.
12381 Exporting tests is required if you want to be able to hand
12382 the test execution off to a scheduler.
12383 You can only export tests that are defined in
12384 <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>.
12385 </para>
12386
12387 <para>
12388 If your image is already built, make sure the following are set
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012389 in your <filename>local.conf</filename> file:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012390 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012391 INHERIT +="testexport"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012392 TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>"
12393 TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012394 </literallayout>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012395 You can then export the tests with the following BitBake
12396 command form:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012397 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012398 $ bitbake <replaceable>image</replaceable> -c testexport
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012399 </literallayout>
12400 Exporting the tests places them in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012401 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12402 in
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012403 <filename>tmp/testexport/</filename><replaceable>image</replaceable>,
12404 which is controlled by the
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012405 <filename>TEST_EXPORT_DIR</filename> variable.
12406 </para>
12407
12408 <para>
12409 You can now run the tests outside of the build environment:
12410 <literallayout class='monospaced'>
Brad Bishop37a0e4d2017-12-04 01:01:44 -050012411 $ cd tmp/testexport/<replaceable>image</replaceable>
12412 $ ./runexported.py testdata.json
12413 </literallayout>
12414 </para>
12415
12416 <para>
12417 Here is a complete example that shows IP addresses and uses
12418 the <filename>core-image-sato</filename> image:
12419 <literallayout class='monospaced'>
12420 INHERIT +="testexport"
12421 TEST_TARGET_IP = "192.168.7.2"
12422 TEST_SERVER_IP = "192.168.7.1"
12423 </literallayout>
12424 Use BitBake to export the tests:
12425 <literallayout class='monospaced'>
12426 $ bitbake core-image-sato -c testexport
12427 </literallayout>
12428 Run the tests outside of the build environment using the
12429 following:
12430 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012431 $ cd tmp/testexport/core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012432 $ ./runexported.py testdata.json
12433 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012434 </para>
12435 </section>
12436
12437 <section id="qemu-image-writing-new-tests">
12438 <title>Writing New Tests</title>
12439
12440 <para>
12441 As mentioned previously, all new test files need to be in the
12442 proper place for the build system to find them.
12443 New tests for additional functionality outside of the core
12444 should be added to the layer that adds the functionality, in
12445 <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>
12446 (as long as
12447 <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>
12448 is extended in the layer's
12449 <filename>layer.conf</filename> file as normal).
12450 Just remember the following:
12451 <itemizedlist>
12452 <listitem><para>Filenames need to map directly to test
12453 (module) names.
12454 </para></listitem>
12455 <listitem><para>Do not use module names that
12456 collide with existing core tests.
12457 </para></listitem>
12458 <listitem><para>Minimally, an empty
12459 <filename>__init__.py</filename> file must exist
12460 in the runtime directory.
12461 </para></listitem>
12462 </itemizedlist>
12463 </para>
12464
12465 <para>
12466 To create a new test, start by copying an existing module
12467 (e.g. <filename>syslog.py</filename> or
12468 <filename>gcc.py</filename> are good ones to use).
12469 Test modules can use code from
12470 <filename>meta/lib/oeqa/utils</filename>, which are helper
12471 classes.
12472 </para>
12473
12474 <note>
12475 Structure shell commands such that you rely on them and they
12476 return a single code for success.
12477 Be aware that sometimes you will need to parse the output.
12478 See the <filename>df.py</filename> and
12479 <filename>date.py</filename> modules for examples.
12480 </note>
12481
12482 <para>
12483 You will notice that all test classes inherit
12484 <filename>oeRuntimeTest</filename>, which is found in
12485 <filename>meta/lib/oetest.py</filename>.
12486 This base class offers some helper attributes, which are
12487 described in the following sections:
12488 </para>
12489
12490 <section id='qemu-image-writing-tests-class-methods'>
12491 <title>Class Methods</title>
12492
12493 <para>
12494 Class methods are as follows:
12495 <itemizedlist>
12496 <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis>
12497 Returns "True" if <filename>pkg</filename> is in the
12498 installed package list of the image, which is based
12499 on the manifest file that is generated during the
12500 <filename>do_rootfs</filename> task.
12501 </para></listitem>
12502 <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis>
12503 Returns "True" if the feature is in
12504 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>
12505 or
12506 <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>.
12507 </para></listitem>
12508 </itemizedlist>
12509 </para>
12510 </section>
12511
12512 <section id='qemu-image-writing-tests-class-attributes'>
12513 <title>Class Attributes</title>
12514
12515 <para>
12516 Class attributes are as follows:
12517 <itemizedlist>
12518 <listitem><para><emphasis><filename>pscmd</filename>:</emphasis>
12519 Equals "ps -ef" if <filename>procps</filename> is
12520 installed in the image.
12521 Otherwise, <filename>pscmd</filename> equals
12522 "ps" (busybox).
12523 </para></listitem>
12524 <listitem><para><emphasis><filename>tc</filename>:</emphasis>
12525 The called test context, which gives access to the
12526 following attributes:
12527 <itemizedlist>
12528 <listitem><para><emphasis><filename>d</filename>:</emphasis>
12529 The BitBake datastore, which allows you to
12530 use stuff such as
12531 <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>.
12532 </para></listitem>
12533 <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis>
12534 Used internally.
12535 The tests do not need these.
12536 </para></listitem>
12537 <listitem><para><emphasis><filename>filesdir</filename>:</emphasis>
12538 The absolute path to
12539 <filename>meta/lib/oeqa/runtime/files</filename>,
12540 which contains helper files for tests meant
12541 for copying on the target such as small
12542 files written in C for compilation.
12543 </para></listitem>
12544 <listitem><para><emphasis><filename>target</filename>:</emphasis>
12545 The target controller object used to deploy
12546 and start an image on a particular target
12547 (e.g. QemuTarget, SimpleRemote, and
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012548 SystemdbootTarget).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012549 Tests usually use the following:
12550 <itemizedlist>
12551 <listitem><para><emphasis><filename>ip</filename>:</emphasis>
12552 The target's IP address.
12553 </para></listitem>
12554 <listitem><para><emphasis><filename>server_ip</filename>:</emphasis>
12555 The host's IP address, which is
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012556 usually used by the DNF test
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012557 suite.
12558 </para></listitem>
12559 <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis>
12560 The single, most used method.
12561 This command is a wrapper for:
12562 <filename>ssh root@host "cmd"</filename>.
12563 The command returns a tuple:
12564 (status, output), which are what
12565 their names imply - the return code
12566 of "cmd" and whatever output
12567 it produces.
12568 The optional timeout argument
12569 represents the number of seconds the
12570 test should wait for "cmd" to
12571 return.
12572 If the argument is "None", the
12573 test uses the default instance's
12574 timeout period, which is 300
12575 seconds.
12576 If the argument is "0", the test
12577 runs until the command returns.
12578 </para></listitem>
12579 <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis>
12580 <filename>scp localpath root@ip:remotepath</filename>.
12581 </para></listitem>
12582 <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis>
12583 <filename>scp root@host:remotepath localpath</filename>.
12584 </para></listitem>
12585 </itemizedlist></para></listitem>
12586 </itemizedlist></para></listitem>
12587 </itemizedlist>
12588 </para>
12589 </section>
12590
12591 <section id='qemu-image-writing-tests-instance-attributes'>
12592 <title>Instance Attributes</title>
12593
12594 <para>
12595 A single instance attribute exists, which is
12596 <filename>target</filename>.
12597 The <filename>target</filename> instance attribute is
12598 identical to the class attribute of the same name, which
12599 is described in the previous section.
12600 This attribute exists as both an instance and class
12601 attribute so tests can use
12602 <filename>self.target.run(cmd)</filename> in instance
12603 methods instead of
12604 <filename>oeRuntimeTest.tc.target.run(cmd)</filename>.
12605 </para>
12606 </section>
12607 </section>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012608
12609 <section id='installing-packages-in-the-dut-without-the-package-manager'>
12610 <title>Installing Packages in the DUT Without the Package Manager</title>
12611
12612 <para>
12613 When a test requires a package built by BitBake, it is possible
12614 to install that package.
12615 Installing the package does not require a package manager be
12616 installed in the device under test (DUT).
12617 It does, however, require an SSH connection and the target must
12618 be using the <filename>sshcontrol</filename> class.
12619 <note>
12620 This method uses <filename>scp</filename> to copy files
12621 from the host to the target, which causes permissions and
12622 special attributes to be lost.
12623 </note>
12624 </para>
12625
12626 <para>
12627 A JSON file is used to define the packages needed by a test.
12628 This file must be in the same path as the file used to define
12629 the tests.
12630 Furthermore, the filename must map directly to the test
12631 module name with a <filename>.json</filename> extension.
12632 </para>
12633
12634 <para>
12635 The JSON file must include an object with the test name as
12636 keys of an object or an array.
12637 This object (or array of objects) uses the following data:
12638 <itemizedlist>
12639 <listitem><para>"pkg" - A mandatory string that is the
12640 name of the package to be installed.
12641 </para></listitem>
12642 <listitem><para>"rm" - An optional boolean, which defaults
12643 to "false", that specifies to remove the package after
12644 the test.
12645 </para></listitem>
12646 <listitem><para>"extract" - An optional boolean, which
12647 defaults to "false", that specifies if the package must
12648 be extracted from the package format.
12649 When set to "true", the package is not automatically
12650 installed into the DUT.
12651 </para></listitem>
12652 </itemizedlist>
12653 </para>
12654
12655 <para>
12656 Following is an example JSON file that handles test "foo"
12657 installing package "bar" and test "foobar" installing
12658 packages "foo" and "bar".
12659 Once the test is complete, the packages are removed from the
12660 DUT.
12661 <literallayout class='monospaced'>
12662 {
12663 "foo": {
12664 "pkg": "bar"
12665 },
12666 "foobar": [
12667 {
12668 "pkg": "foo",
12669 "rm": true
12670 },
12671 {
12672 "pkg": "bar",
12673 "rm": true
12674 }
12675 ]
12676 }
12677 </literallayout>
12678 </para>
12679 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012680 </section>
12681
Brad Bishop316dfdd2018-06-25 12:45:53 -040012682 <section id='usingpoky-debugging-tools-and-techniques'>
12683 <title>Debugging Tools and Techniques</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012684
12685 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012686 The exact method for debugging build failures depends on the nature
12687 of the problem and on the system's area from which the bug
12688 originates.
12689 Standard debugging practices such as comparison against the last
12690 known working version with examination of the changes and the
12691 re-application of steps to identify the one causing the problem are
12692 valid for the Yocto Project just as they are for any other system.
12693 Even though it is impossible to detail every possible potential
12694 failure, this section provides some general tips to aid in
12695 debugging given a variety of situations.
12696 <note><title>Tip</title>
12697 A useful feature for debugging is the error reporting tool.
12698 Configuring the Yocto Project to use this tool causes the
12699 OpenEmbedded build system to produce error reporting commands as
12700 part of the console output.
12701 You can enter the commands after the build completes to log
12702 error information into a common database, that can help you
12703 figure out what might be going wrong.
12704 For information on how to enable and use this feature, see the
12705 "<link linkend='using-the-error-reporting-tool'>Using the Error Reporting Tool</link>"
12706 section.
12707 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012708 </para>
12709
12710 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012711 The following list shows the debugging topics in the remainder of
12712 this section:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012713 <itemizedlist>
12714 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012715 "<link linkend='dev-debugging-viewing-logs-from-failed-tasks'>Viewing Logs from Failed Tasks</link>"
12716 describes how to find and view logs from tasks that
12717 failed during the build process.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012718 </para></listitem>
12719 <listitem><para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012720 "<link linkend='dev-debugging-viewing-variable-values'>Viewing Variable Values</link>"
12721 describes how to use the BitBake <filename>-e</filename>
12722 option to examine variable values after a recipe has been
12723 parsed.
12724 </para></listitem>
12725 <listitem><para>
12726 "<link linkend='viewing-package-information-with-oe-pkgdata-util'>Viewing Package Information with <filename>oe-pkgdata-util</filename></link>"
12727 describes how to use the
12728 <filename>oe-pkgdata-util</filename> utility to query
12729 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12730 and display package-related information for built
12731 packages.
12732 </para></listitem>
12733 <listitem><para>
12734 "<link linkend='dev-viewing-dependencies-between-recipes-and-tasks'>Viewing Dependencies Between Recipes and Tasks</link>"
12735 describes how to use the BitBake <filename>-g</filename>
12736 option to display recipe dependency information used
12737 during the build.
12738 </para></listitem>
12739 <listitem><para>
12740 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
12741 describes how to use the
12742 <filename>bitbake-dumpsig</filename> command in
12743 conjunction with key subdirectories in the
12744 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
12745 to determine variable dependencies.
12746 </para></listitem>
12747 <listitem><para>
12748 "<link linkend='dev-debugging-taskrunning'>Running Specific Tasks</link>"
12749 describes how to use several BitBake options (e.g.
12750 <filename>-c</filename>, <filename>-C</filename>, and
12751 <filename>-f</filename>) to run specific tasks in the
12752 build chain.
12753 It can be useful to run tasks "out-of-order" when trying
12754 isolate build issues.
12755 </para></listitem>
12756 <listitem><para>
12757 "<link linkend='dev-debugging-bitbake'>General BitBake Problems</link>"
12758 describes how to use BitBake's <filename>-D</filename>
12759 debug output option to reveal more about what BitBake is
12760 doing during the build.
12761 </para></listitem>
12762 <listitem><para>
12763 "<link linkend='dev-debugging-buildfile'>Building with No Dependencies</link>"
12764 describes how to use the BitBake <filename>-b</filename>
12765 option to build a recipe while ignoring dependencies.
12766 </para></listitem>
12767 <listitem><para>
12768 "<link linkend='recipe-logging-mechanisms'>Recipe Logging Mechanisms</link>"
12769 describes how to use the many recipe logging functions
12770 to produce debugging output and report errors and warnings.
12771 </para></listitem>
12772 <listitem><para>
12773 "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>"
12774 describes how to debug situations where the build consists
12775 of several parts that are run simultaneously and when the
12776 output or result of one part is not ready for use with a
12777 different part of the build that depends on that output.
12778 </para></listitem>
12779 <listitem><para>
12780 "<link linkend='platdev-gdb-remotedebug'>Debugging With the GNU Project Debugger (GDB) Remotely</link>"
12781 describes how to use GDB to allow you to examine running
12782 programs, which can help you fix problems.
12783 </para></listitem>
12784 <listitem><para>
12785 "<link linkend='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>Debugging with the GNU Project Debugger (GDB) on the Target</link>"
12786 describes how to use GDB directly on target hardware for
12787 debugging.
12788 </para></listitem>
12789 <listitem><para>
12790 "<link linkend='dev-other-debugging-others'>Other Debugging Tips</link>"
12791 describes miscellaneous debugging tips that can be useful.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012792 </para></listitem>
12793 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012794 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012795
Brad Bishop316dfdd2018-06-25 12:45:53 -040012796 <section id='dev-debugging-viewing-logs-from-failed-tasks'>
12797 <title>Viewing Logs from Failed Tasks</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012798
12799 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012800 You can find the log for a task in the file
12801 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp/log.do_</filename><replaceable>taskname</replaceable>.
12802 For example, the log for the
12803 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>
12804 task of the QEMU minimal image for the x86 machine
12805 (<filename>qemux86</filename>) might be in
12806 <filename>tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile</filename>.
12807 To see the commands
12808 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
12809 ran to generate a log, look at the corresponding
12810 <filename>run.do_</filename><replaceable>taskname</replaceable>
12811 file in the same directory.
12812 </para>
12813
12814 <para>
12815 <filename>log.do_</filename><replaceable>taskname</replaceable>
12816 and
12817 <filename>run.do_</filename><replaceable>taskname</replaceable>
12818 are actually symbolic links to
12819 <filename>log.do_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>
12820 and
12821 <filename>log.run_</filename><replaceable>taskname</replaceable><filename>.</filename><replaceable>pid</replaceable>,
12822 where <replaceable>pid</replaceable> is the PID the task had
12823 when it ran.
12824 The symlinks always point to the files corresponding to the most
12825 recent run.
12826 </para>
12827 </section>
12828
12829 <section id='dev-debugging-viewing-variable-values'>
12830 <title>Viewing Variable Values</title>
12831
12832 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040012833 Sometimes you need to know the value of a variable as a
12834 result of BitBake's parsing step.
12835 This could be because some unexpected behavior occurred
12836 in your project.
12837 Perhaps an attempt to
12838 <ulink url='&YOCTO_DOCS_BB_URL;#modifying-existing-variables'>modify a variable</ulink>
12839 did not work out as expected.
12840 </para>
12841
12842 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012843 BitBake's <filename>-e</filename> option is used to display
12844 variable values after parsing.
12845 The following command displays the variable values after the
12846 configuration files (i.e. <filename>local.conf</filename>,
12847 <filename>bblayers.conf</filename>,
12848 <filename>bitbake.conf</filename> and so forth) have been
12849 parsed:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012850 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040012851 $ bitbake -e
12852 </literallayout>
12853 The following command displays variable values after a specific
12854 recipe has been parsed.
12855 The variables include those from the configuration as well:
12856 <literallayout class='monospaced'>
12857 $ bitbake -e recipename
12858 </literallayout>
12859 <note><para>
12860 Each recipe has its own private set of variables
12861 (datastore).
12862 Internally, after parsing the configuration, a copy of the
12863 resulting datastore is made prior to parsing each recipe.
12864 This copying implies that variables set in one recipe will
12865 not be visible to other recipes.</para>
12866
12867 <para>Likewise, each task within a recipe gets a private
12868 datastore based on the recipe datastore, which means that
12869 variables set within one task will not be visible to
12870 other tasks.</para>
12871 </note>
12872 </para>
12873
12874 <para>
12875 In the output of <filename>bitbake -e</filename>, each
12876 variable is preceded by a description of how the variable
12877 got its value, including temporary values that were later
12878 overriden.
12879 This description also includes variable flags (varflags) set on
12880 the variable.
12881 The output can be very helpful during debugging.
12882 </para>
12883
12884 <para>
12885 Variables that are exported to the environment are preceded by
12886 <filename>export</filename> in the output of
12887 <filename>bitbake -e</filename>.
12888 See the following example:
12889 <literallayout class='monospaced'>
12890 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
12891 </literallayout>
12892 </para>
12893
12894 <para>
12895 In addition to variable values, the output of the
12896 <filename>bitbake -e</filename> and
12897 <filename>bitbake -e</filename>&nbsp;<replaceable>recipe</replaceable>
12898 commands includes the following information:
12899 <itemizedlist>
12900 <listitem><para>
12901 The output starts with a tree listing all configuration
12902 files and classes included globally, recursively listing
12903 the files they include or inherit in turn.
12904 Much of the behavior of the OpenEmbedded build system
12905 (including the behavior of the
12906 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>)
12907 is implemented in the
12908 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
12909 class and the classes it inherits, rather than being
12910 built into BitBake itself.
12911 </para></listitem>
12912 <listitem><para>
12913 After the variable values, all functions appear in the
12914 output.
12915 For shell functions, variables referenced within the
12916 function body are expanded.
12917 If a function has been modified using overrides or
12918 using override-style operators like
12919 <filename>_append</filename> and
12920 <filename>_prepend</filename>, then the final assembled
12921 function body appears in the output.
12922 </para></listitem>
12923 </itemizedlist>
12924 </para>
12925 </section>
12926
12927 <section id='viewing-package-information-with-oe-pkgdata-util'>
12928 <title>Viewing Package Information with <filename>oe-pkgdata-util</filename></title>
12929
12930 <para>
12931 You can use the <filename>oe-pkgdata-util</filename>
12932 command-line utility to query
12933 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></ulink>
12934 and display various package-related information.
12935 When you use the utility, you must use it to view information
12936 on packages that have already been built.
12937 </para>
12938
12939 <para>
12940 Following are a few of the available
12941 <filename>oe-pkgdata-util</filename> subcommands.
12942 <note>
12943 You can use the standard * and ? globbing wildcards as part
12944 of package names and paths.
12945 </note>
12946 <itemizedlist>
12947 <listitem><para>
12948 <filename>oe-pkgdata-util list-pkgs [</filename><replaceable>pattern</replaceable><filename>]</filename>:
12949 Lists all packages that have been built, optionally
12950 limiting the match to packages that match
12951 <replaceable>pattern</replaceable>.
12952 </para></listitem>
12953 <listitem><para>
12954 <filename>oe-pkgdata-util list-pkg-files&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12955 Lists the files and directories contained in the given
12956 packages.
12957 <note>
12958 <para>
12959 A different way to view the contents of a package is
12960 to look at the
12961 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename>
12962 directory of the recipe that generates the
12963 package.
12964 This directory is created by the
12965 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
12966 task and has one subdirectory for each package the
12967 recipe generates, which contains the files stored in
12968 that package.</para>
12969 <para>
12970 If you want to inspect the
12971 <filename>${WORKDIR}/packages-split</filename>
12972 directory, make sure that
12973 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-rm-work'><filename>rm_work</filename></ulink>
12974 is not enabled when you build the recipe.
12975 </para>
12976 </note>
12977 </para></listitem>
12978 <listitem><para>
12979 <filename>oe-pkgdata-util find-path&nbsp;</filename><replaceable>path</replaceable><filename>&nbsp;...</filename>:
12980 Lists the names of the packages that contain the given
12981 paths.
12982 For example, the following tells us that
12983 <filename>/usr/share/man/man1/make.1</filename>
12984 is contained in the <filename>make-doc</filename>
12985 package:
12986 <literallayout class='monospaced'>
12987 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
12988 make-doc: /usr/share/man/man1/make.1
12989 </literallayout>
12990 </para></listitem>
12991 <listitem><para>
12992 <filename>oe-pkgdata-util lookup-recipe&nbsp;</filename><replaceable>package</replaceable><filename>&nbsp;...</filename>:
12993 Lists the name of the recipes that
12994 produce the given packages.
12995 </para></listitem>
12996 </itemizedlist>
12997 </para>
12998
12999 <para>
13000 For more information on the <filename>oe-pkgdata-util</filename>
13001 command, use the help facility:
13002 <literallayout class='monospaced'>
13003 $ oe-pkgdata-util &dash;&dash;help
13004 $ oe-pkgdata-util <replaceable>subcommand</replaceable> --help
13005 </literallayout>
13006 </para>
13007 </section>
13008
13009 <section id='dev-viewing-dependencies-between-recipes-and-tasks'>
13010 <title>Viewing Dependencies Between Recipes and Tasks</title>
13011
13012 <para>
13013 Sometimes it can be hard to see why BitBake wants to build other
13014 recipes before the one you have specified.
13015 Dependency information can help you understand why a recipe is
13016 built.
13017 </para>
13018
13019 <para>
13020 To generate dependency information for a recipe, run the
13021 following command:
13022 <literallayout class='monospaced'>
13023 $ bitbake -g <replaceable>recipename</replaceable>
13024 </literallayout>
13025 This command writes the following files in the current
13026 directory:
13027 <itemizedlist>
13028 <listitem><para>
13029 <filename>pn-buildlist</filename>: A list of
13030 recipes/targets involved in building
13031 <replaceable>recipename</replaceable>.
13032 "Involved" here means that at least one task from the
13033 recipe needs to run when building
13034 <replaceable>recipename</replaceable> from scratch.
13035 Targets that are in
13036 <ulink url='&YOCTO_DOCS_REF_URL;#var-ASSUME_PROVIDED'><filename>ASSUME_PROVIDED</filename></ulink>
13037 are not listed.
13038 </para></listitem>
13039 <listitem><para>
13040 <filename>task-depends.dot</filename>: A graph showing
13041 dependencies between tasks.
13042 </para></listitem>
13043 </itemizedlist>
13044 </para>
13045
13046 <para>
13047 The graphs are in
13048 <ulink url='https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29'>DOT</ulink>
13049 format and can be converted to images (e.g. using the
13050 <filename>dot</filename> tool from
13051 <ulink url='http://www.graphviz.org/'>Graphviz</ulink>).
13052 <note><title>Notes</title>
13053 <itemizedlist>
13054 <listitem><para>
13055 DOT files use a plain text format.
13056 The graphs generated using the
13057 <filename>bitbake -g</filename> command are often so
13058 large as to be difficult to read without special
13059 pruning (e.g. with Bitbake's
13060 <filename>-I</filename> option) and processing.
13061 Despite the form and size of the graphs, the
13062 corresponding <filename>.dot</filename> files can
13063 still be possible to read and provide useful
13064 information.
13065 </para>
13066
13067 <para>As an example, the
13068 <filename>task-depends.dot</filename> file contains
13069 lines such as the following:
13070 <literallayout class='monospaced'>
13071 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
13072 </literallayout>
13073 The above example line reveals that the
13074 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>
13075 task in <filename>libxslt</filename> depends on the
13076 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink>
13077 task in <filename>libxml2</filename>, which is a
13078 normal
13079 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
13080 dependency between the two recipes.
13081 </para></listitem>
13082 <listitem><para>
13083 For an example of how <filename>.dot</filename>
13084 files can be processed, see the
13085 <filename>scripts/contrib/graph-tool</filename>
13086 Python script, which finds and displays paths
13087 between graph nodes.
13088 </para></listitem>
13089 </itemizedlist>
13090 </note>
13091 </para>
13092
13093 <para>
13094 You can use a different method to view dependency information
13095 by using the following command:
13096 <literallayout class='monospaced'>
13097 $ bitbake -g -u taskexp <replaceable>recipename</replaceable>
13098 </literallayout>
13099 This command displays a GUI window from which you can view
13100 build-time and runtime dependencies for the recipes involved in
13101 building <replaceable>recipename</replaceable>.
13102 </para>
13103 </section>
13104
13105 <section id='dev-viewing-task-variable-dependencies'>
13106 <title>Viewing Task Variable Dependencies</title>
13107
13108 <para>
13109 As mentioned in the
13110 "<ulink url='&YOCTO_DOCS_BB_URL;#checksums'>Checksums (Signatures)</ulink>"
13111 section of the BitBake User Manual, BitBake tries to
13112 automatically determine what variables a task depends on so
13113 that it can rerun the task if any values of the variables
13114 change.
13115 This determination is usually reliable.
13116 However, if you do things like construct variable names at
13117 runtime, then you might have to manually declare dependencies
13118 on those variables using <filename>vardeps</filename> as
13119 described in the
13120 "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
13121 section of the BitBake User Manual.
13122 </para>
13123
13124 <para>
13125 If you are unsure whether a variable dependency is being
13126 picked up automatically for a given task, you can list the
13127 variable dependencies BitBake has determined by doing the
13128 following:
13129 <orderedlist>
13130 <listitem><para>
13131 Build the recipe containing the task:
13132 <literallayout class='monospaced'>
13133 $ bitbake <replaceable>recipename</replaceable>
13134 </literallayout>
13135 </para></listitem>
13136 <listitem><para>
13137 Inside the
13138 <ulink url='&YOCTO_DOCS_REF_URL;#var-STAMPS_DIR'><filename>STAMPS_DIR</filename></ulink>
13139 directory, find the signature data
13140 (<filename>sigdata</filename>) file that corresponds
13141 to the task.
13142 The <filename>sigdata</filename> files contain a pickled
13143 Python database of all the metadata that went into
13144 creating the input checksum for the task.
13145 As an example, for the
13146 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>
13147 task of the <filename>db</filename> recipe, the
13148 <filename>sigdata</filename> file might be found in the
13149 following location:
13150 <literallayout class='monospaced'>
13151 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13152 </literallayout>
13153 For tasks that are accelerated through the shared state
13154 (<ulink url='&YOCTO_DOCS_OM_URL;#shared-state-cache'>sstate</ulink>)
13155 cache, an additional <filename>siginfo</filename> file
13156 is written into
13157 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
13158 along with the cached task output.
13159 The <filename>siginfo</filename> files contain exactly
13160 the same information as <filename>sigdata</filename>
13161 files.
13162 </para></listitem>
13163 <listitem><para>
13164 Run <filename>bitbake-dumpsig</filename> on the
13165 <filename>sigdata</filename> or
13166 <filename>siginfo</filename> file.
13167 Here is an example:
13168 <literallayout class='monospaced'>
13169 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
13170 </literallayout>
13171 In the output of the above command, you will find a
13172 line like the following, which lists all the (inferred)
13173 variable dependencies for the task.
13174 This list also includes indirect dependencies from
13175 variables depending on other variables, recursively.
13176 <literallayout class='monospaced'>
13177 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
13178 </literallayout>
13179 <note>
13180 Functions (e.g. <filename>base_do_fetch</filename>)
13181 also count as variable dependencies.
13182 These functions in turn depend on the variables they
13183 reference.
13184 </note>
13185 The output of <filename>bitbake-dumpsig</filename> also
13186 includes the value each variable had, a list of
13187 dependencies for each variable, and
13188 <ulink url='&YOCTO_DOCS_BB_URL;#var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></ulink>
13189 information.
13190 </para></listitem>
13191 </orderedlist>
13192 </para>
13193
13194 <para>
13195 There is also a <filename>bitbake-diffsigs</filename> command
13196 for comparing two <filename>siginfo</filename> or
13197 <filename>sigdata</filename> files.
13198 This command can be helpful when trying to figure out what
13199 changed between two versions of a task.
13200 If you call <filename>bitbake-diffsigs</filename> with just one
13201 file, the command behaves like
13202 <filename>bitbake-dumpsig</filename>.
13203 </para>
13204
13205 <para>
13206 You can also use BitBake to dump out the signature construction
13207 information without executing tasks by using either of the
13208 following BitBake command-line options:
13209 <literallayout class='monospaced'>
13210 &dash;&dash;dump-signatures=<replaceable>SIGNATURE_HANDLER</replaceable>
13211 -S <replaceable>SIGNATURE_HANDLER</replaceable>
13212 </literallayout>
13213 <note>
13214 Two common values for
13215 <replaceable>SIGNATURE_HANDLER</replaceable> are "none" and
13216 "printdiff", which dump only the signature or compare the
13217 dumped signature with the cached one, respectively.
13218 </note>
13219 Using BitBake with either of these options causes BitBake to
13220 dump out <filename>sigdata</filename> files in the
13221 <filename>stamps</filename> directory for every task it would
13222 have executed instead of building the specified target package.
13223 </para>
13224 </section>
13225
13226 <section id='dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task'>
13227 <title>Viewing Metadata Used to Create the Input Signature of a Shared State Task</title>
13228
13229 <para>
13230 Seeing what metadata went into creating the input signature
13231 of a shared state (sstate) task can be a useful debugging
13232 aid.
13233 This information is available in signature information
13234 (<filename>siginfo</filename>) files in
13235 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>.
13236 For information on how to view and interpret information in
13237 <filename>siginfo</filename> files, see the
13238 "<link linkend='dev-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
13239 section.
13240 </para>
13241
13242 <para>
13243 For conceptual information on shared state, see the
13244 "<ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>Shared State</ulink>"
13245 section in the Yocto Project Overview and Concepts Manual.
13246 </para>
13247 </section>
13248
13249 <section id='dev-invalidating-shared-state-to-force-a-task-to-run'>
13250 <title>Invalidating Shared State to Force a Task to Run</title>
13251
13252 <para>
13253 The OpenEmbedded build system uses
13254 <ulink url='&YOCTO_DOCS_OM_URL;#overview-checksums'>checksums</ulink>
13255 and
13256 <ulink url='&YOCTO_DOCS_OM_URL;#shared-state'>shared state</ulink>
13257 cache to avoid unnecessarily rebuilding tasks.
13258 Collectively, this scheme is known as "shared state code."
13259 </para>
13260
13261 <para>
13262 As with all schemes, this one has some drawbacks.
13263 It is possible that you could make implicit changes to your
13264 code that the checksum calculations do not take into
13265 account.
13266 These implicit changes affect a task's output but do not
13267 trigger the shared state code into rebuilding a recipe.
13268 Consider an example during which a tool changes its output.
13269 Assume that the output of <filename>rpmdeps</filename>
13270 changes.
13271 The result of the change should be that all the
13272 <filename>package</filename> and
13273 <filename>package_write_rpm</filename> shared state cache
13274 items become invalid.
13275 However, because the change to the output is
13276 external to the code and therefore implicit,
13277 the associated shared state cache items do not become
13278 invalidated.
13279 In this case, the build process uses the cached items
13280 rather than running the task again.
13281 Obviously, these types of implicit changes can cause
13282 problems.
13283 </para>
13284
13285 <para>
13286 To avoid these problems during the build, you need to
13287 understand the effects of any changes you make.
13288 Realize that changes you make directly to a function
13289 are automatically factored into the checksum calculation.
13290 Thus, these explicit changes invalidate the associated
13291 area of shared state cache.
13292 However, you need to be aware of any implicit changes that
13293 are not obvious changes to the code and could affect
13294 the output of a given task.
13295 </para>
13296
13297 <para>
13298 When you identify an implicit change, you can easily
13299 take steps to invalidate the cache and force the tasks
13300 to run.
13301 The steps you can take are as simple as changing a
13302 function's comments in the source code.
13303 For example, to invalidate package shared state files,
13304 change the comment statements of
13305 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
13306 or the comments of one of the functions it calls.
13307 Even though the change is purely cosmetic, it causes the
13308 checksum to be recalculated and forces the build system to
13309 run the task again.
13310 <note>
13311 For an example of a commit that makes a cosmetic
13312 change to invalidate shared state, see this
13313 <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
13314 </note>
13315 </para>
13316 </section>
13317
13318 <section id='dev-debugging-taskrunning'>
13319 <title>Running Specific Tasks</title>
13320
13321 <para>
13322 Any given recipe consists of a set of tasks.
13323 The standard BitBake behavior in most cases is:
13324 <filename>do_fetch</filename>,
13325 <filename>do_unpack</filename>,
13326 <filename>do_patch</filename>,
13327 <filename>do_configure</filename>,
13328 <filename>do_compile</filename>,
13329 <filename>do_install</filename>,
13330 <filename>do_package</filename>,
13331 <filename>do_package_write_*</filename>, and
13332 <filename>do_build</filename>.
13333 The default task is <filename>do_build</filename> and any tasks
13334 on which it depends build first.
13335 Some tasks, such as <filename>do_devshell</filename>, are not
13336 part of the default build chain.
13337 If you wish to run a task that is not part of the default build
13338 chain, you can use the <filename>-c</filename> option in
13339 BitBake.
13340 Here is an example:
13341 <literallayout class='monospaced'>
13342 $ bitbake matchbox-desktop -c devshell
13343 </literallayout>
13344 </para>
13345
13346 <para>
13347 The <filename>-c</filename> option respects task dependencies,
13348 which means that all other tasks (including tasks from other
13349 recipes) that the specified task depends on will be run before
13350 the task.
13351 Even when you manually specify a task to run with
13352 <filename>-c</filename>, BitBake will only run the task if it
13353 considers it "out of date".
13354 See the
13355 "<ulink url='&YOCTO_DOCS_OM_URL;#stamp-files-and-the-rerunning-of-tasks'>Stamp Files and the Rerunning of Tasks</ulink>"
13356 section in the Yocto Project Overview and Concepts Manual for
13357 how BitBake determines whether a task is "out of date".
13358 </para>
13359
13360 <para>
13361 If you want to force an up-to-date task to be rerun (e.g.
13362 because you made manual modifications to the recipe's
13363 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>
13364 that you want to try out), then you can use the
13365 <filename>-f</filename> option.
13366 <note>
13367 The reason <filename>-f</filename> is never required when
13368 running the
13369 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-devshell'><filename>do_devshell</filename></ulink>
13370 task is because the
13371 <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>nostamp</filename></ulink><filename>]</filename>
13372 variable flag is already set for the task.
13373 </note>
13374 The following example shows one way you can use the
13375 <filename>-f</filename> option:
13376 <literallayout class='monospaced'>
13377 $ bitbake matchbox-desktop
13378 .
13379 .
13380 make some changes to the source code in the work directory
13381 .
13382 .
13383 $ bitbake matchbox-desktop -c compile -f
13384 $ bitbake matchbox-desktop
13385 </literallayout>
13386 </para>
13387
13388 <para>
13389 This sequence first builds and then recompiles
13390 <filename>matchbox-desktop</filename>.
13391 The last command reruns all tasks (basically the packaging
13392 tasks) after the compile.
13393 BitBake recognizes that the <filename>do_compile</filename>
13394 task was rerun and therefore understands that the other tasks
13395 also need to be run again.
13396 </para>
13397
13398 <para>
13399 Another, shorter way to rerun a task and all
13400 <ulink url='&YOCTO_DOCS_REF_URL;#normal-recipe-build-tasks'>normal recipe build tasks</ulink>
13401 that depend on it is to use the <filename>-C</filename>
13402 option.
13403 <note>
13404 This option is upper-cased and is separate from the
13405 <filename>-c</filename> option, which is lower-cased.
13406 </note>
13407 Using this option invalidates the given task and then runs the
13408 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-build'><filename>do_build</filename></ulink>
13409 task, which is the default task if no task is given, and the
13410 tasks on which it depends.
13411 You could replace the final two commands in the previous example
13412 with the following single command:
13413 <literallayout class='monospaced'>
13414 $ bitbake matchbox-desktop -C compile
13415 </literallayout>
13416 Internally, the <filename>-f</filename> and
13417 <filename>-C</filename> options work by tainting (modifying) the
13418 input checksum of the specified task.
13419 This tainting indirectly causes the task and its
13420 dependent tasks to be rerun through the normal task dependency
13421 mechanisms.
13422 <note>
13423 BitBake explicitly keeps track of which tasks have been
13424 tainted in this fashion, and will print warnings such as the
13425 following for builds involving such tasks:
13426 <literallayout class='monospaced'>
13427 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
13428 </literallayout>
13429 The purpose of the warning is to let you know that the work
13430 directory and build output might not be in the clean state
13431 they would be in for a "normal" build, depending on what
13432 actions you took.
13433 To get rid of such warnings, you can remove the work
13434 directory and rebuild the recipe, as follows:
13435 <literallayout class='monospaced'>
13436 $ bitbake matchbox-desktop -c clean
13437 $ bitbake matchbox-desktop
13438 </literallayout>
13439 </note>
13440 </para>
13441
13442 <para>
13443 You can view a list of tasks in a given package by running the
13444 <filename>do_listtasks</filename> task as follows:
13445 <literallayout class='monospaced'>
13446 $ bitbake matchbox-desktop -c listtasks
13447 </literallayout>
13448 The results appear as output to the console and are also in the
13449 file <filename>${WORKDIR}/temp/log.do_listtasks</filename>.
13450 </para>
13451 </section>
13452
13453 <section id='dev-debugging-bitbake'>
13454 <title>General BitBake Problems</title>
13455
13456 <para>
13457 You can see debug output from BitBake by using the
13458 <filename>-D</filename> option.
13459 The debug output gives more information about what BitBake
13460 is doing and the reason behind it.
13461 Each <filename>-D</filename> option you use increases the
13462 logging level.
13463 The most common usage is <filename>-DDD</filename>.
13464 </para>
13465
13466 <para>
13467 The output from
13468 <filename>bitbake -DDD -v</filename> <replaceable>targetname</replaceable>
13469 can reveal why BitBake chose a certain version of a package or
13470 why BitBake picked a certain provider.
13471 This command could also help you in a situation where you think
13472 BitBake did something unexpected.
13473 </para>
13474 </section>
13475
13476 <section id='dev-debugging-buildfile'>
13477 <title>Building with No Dependencies</title>
13478
13479 <para>
13480 To build a specific recipe (<filename>.bb</filename> file),
13481 you can use the following command form:
13482 <literallayout class='monospaced'>
13483 $ bitbake -b <replaceable>somepath</replaceable>/<replaceable>somerecipe</replaceable>.bb
13484 </literallayout>
13485 This command form does not check for dependencies.
13486 Consequently, you should use it only when you know existing
13487 dependencies have been met.
13488 <note>
13489 You can also specify fragments of the filename.
13490 In this case, BitBake checks for a unique match.
13491 </note>
13492 </para>
13493 </section>
13494
13495 <section id='recipe-logging-mechanisms'>
13496 <title>Recipe Logging Mechanisms</title>
13497
13498 <para>
13499 The Yocto Project provides several logging functions for
13500 producing debugging output and reporting errors and warnings.
13501 For Python functions, the following logging functions exist.
13502 All of these functions log to
13503 <filename>${T}/log.do_</filename><replaceable>task</replaceable>,
13504 and can also log to standard output (stdout) with the right
13505 settings:
13506 <itemizedlist>
13507 <listitem><para>
13508 <filename>bb.plain(</filename><replaceable>msg</replaceable><filename>)</filename>:
13509 Writes <replaceable>msg</replaceable> as is to the
13510 log while also logging to stdout.
13511 </para></listitem>
13512 <listitem><para>
13513 <filename>bb.note(</filename><replaceable>msg</replaceable><filename>)</filename>:
13514 Writes "NOTE: <replaceable>msg</replaceable>" to the
13515 log.
13516 Also logs to stdout if BitBake is called with "-v".
13517 </para></listitem>
13518 <listitem><para>
13519 <filename>bb.debug(</filename><replaceable>level</replaceable><filename>,&nbsp;</filename><replaceable>msg</replaceable><filename>)</filename>:
13520 Writes "DEBUG: <replaceable>msg</replaceable>" to the
13521 log.
13522 Also logs to stdout if the log level is greater than or
13523 equal to <replaceable>level</replaceable>.
13524 See the
13525 "<ulink url='&YOCTO_DOCS_BB_URL;#usage-and-syntax'>-D</ulink>"
13526 option in the BitBake User Manual for more information.
13527 </para></listitem>
13528 <listitem><para>
13529 <filename>bb.warn(</filename><replaceable>msg</replaceable><filename>)</filename>:
13530 Writes "WARNING: <replaceable>msg</replaceable>" to the
13531 log while also logging to stdout.
13532 </para></listitem>
13533 <listitem><para>
13534 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>:
13535 Writes "ERROR: <replaceable>msg</replaceable>" to the
13536 log while also logging to standard out (stdout).
13537 <note>
13538 Calling this function does not cause the task to fail.
13539 </note>
13540 </para></listitem>
13541 <listitem><para>
13542 <filename>bb.fatal(</filename><replaceable>msg</replaceable><filename>)</filename>:
13543 This logging function is similar to
13544 <filename>bb.error(</filename><replaceable>msg</replaceable><filename>)</filename>
13545 but also causes the calling task to fail.
13546 <note>
13547 <filename>bb.fatal()</filename> raises an exception,
13548 which means you do not need to put a "return"
13549 statement after the function.
13550 </note>
13551 </para></listitem>
13552 </itemizedlist>
13553 </para>
13554
13555 <para>
13556 The same logging functions are also available in shell
13557 functions, under the names
13558 <filename>bbplain</filename>, <filename>bbnote</filename>,
13559 <filename>bbdebug</filename>, <filename>bbwarn</filename>,
13560 <filename>bberror</filename>, and <filename>bbfatal</filename>.
13561 The
13562 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-logging'><filename>logging</filename></ulink>
13563 class implements these functions.
13564 See that class in the
13565 <filename>meta/classes</filename> folder of the
13566 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13567 for information.
13568 </para>
13569
13570 <section id='logging-with-python'>
13571 <title>Logging With Python</title>
13572
13573 <para>
13574 When creating recipes using Python and inserting code that
13575 handles build logs, keep in mind the goal is to have
13576 informative logs while keeping the console as "silent" as
13577 possible.
13578 Also, if you want status messages in the log, use the
13579 "debug" loglevel.
13580 </para>
13581
13582 <para>
13583 Following is an example written in Python.
13584 The code handles logging for a function that determines the
13585 number of tasks needed to be run.
13586 See the
13587 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-listtasks'><filename>do_listtasks</filename></ulink>"
13588 section for additional information:
13589 <literallayout class='monospaced'>
13590 python do_listtasks() {
13591 bb.debug(2, "Starting to figure out the task list")
13592 if noteworthy_condition:
13593 bb.note("There are 47 tasks to run")
13594 bb.debug(2, "Got to point xyz")
13595 if warning_trigger:
13596 bb.warn("Detected warning_trigger, this might be a problem later.")
13597 if recoverable_error:
13598 bb.error("Hit recoverable_error, you really need to fix this!")
13599 if fatal_error:
13600 bb.fatal("fatal_error detected, unable to print the task list")
13601 bb.plain("The tasks present are abc")
13602 bb.debug(2, "Finished figuring out the tasklist")
13603 }
13604 </literallayout>
13605 </para>
13606 </section>
13607
13608 <section id='logging-with-bash'>
13609 <title>Logging With Bash</title>
13610
13611 <para>
13612 When creating recipes using Bash and inserting code that
13613 handles build logs, you have the same goals - informative
13614 with minimal console output.
13615 The syntax you use for recipes written in Bash is similar
13616 to that of recipes written in Python described in the
13617 previous section.
13618 </para>
13619
13620 <para>
13621 Following is an example written in Bash.
13622 The code logs the progress of the <filename>do_my_function</filename> function.
13623 <literallayout class='monospaced'>
13624 do_my_function() {
13625 bbdebug 2 "Running do_my_function"
13626 if [ exceptional_condition ]; then
13627 bbnote "Hit exceptional_condition"
13628 fi
13629 bbdebug 2 "Got to point xyz"
13630 if [ warning_trigger ]; then
13631 bbwarn "Detected warning_trigger, this might cause a problem later."
13632 fi
13633 if [ recoverable_error ]; then
13634 bberror "Hit recoverable_error, correcting"
13635 fi
13636 if [ fatal_error ]; then
13637 bbfatal "fatal_error detected"
13638 fi
13639 bbdebug 2 "Completed do_my_function"
13640 }
13641 </literallayout>
13642 </para>
13643 </section>
13644 </section>
13645
13646 <section id='debugging-parallel-make-races'>
13647 <title>Debugging Parallel Make Races</title>
13648
13649 <para>
13650 A parallel <filename>make</filename> race occurs when the build
13651 consists of several parts that are run simultaneously and
13652 a situation occurs when the output or result of one
13653 part is not ready for use with a different part of the build
13654 that depends on that output.
13655 Parallel make races are annoying and can sometimes be difficult
13656 to reproduce and fix.
13657 However, some simple tips and tricks exist that can help
13658 you debug and fix them.
13659 This section presents a real-world example of an error
13660 encountered on the Yocto Project autobuilder and the process
13661 used to fix it.
13662 <note>
13663 If you cannot properly fix a <filename>make</filename> race
13664 condition, you can work around it by clearing either the
13665 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13666 or
13667 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink>
13668 variables.
13669 </note>
13670 </para>
13671
13672 <section id='the-failure'>
13673 <title>The Failure</title>
13674
13675 <para>
13676 For this example, assume that you are building an image that
13677 depends on the "neard" package.
13678 And, during the build, BitBake runs into problems and
13679 creates the following output.
13680 <note>
13681 This example log file has longer lines artificially
13682 broken to make the listing easier to read.
13683 </note>
13684 If you examine the output or the log file, you see the
13685 failure during <filename>make</filename>:
13686 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013687 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
13688 | DEBUG: Executing shell function do_compile
13689 | NOTE: make -j 16
13690 | make --no-print-directory all-am
13691 | /bin/mkdir -p include/near
13692 | /bin/mkdir -p include/near
13693 | /bin/mkdir -p include/near
13694 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13695 0.14-r0/neard-0.14/include/types.h include/near/types.h
13696 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13697 0.14-r0/neard-0.14/include/log.h include/near/log.h
13698 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13699 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
13700 | /bin/mkdir -p include/near
13701 | /bin/mkdir -p include/near
13702 | /bin/mkdir -p include/near
13703 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13704 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
13705 | /bin/mkdir -p include/near
13706 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13707 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
13708 | /bin/mkdir -p include/near
13709 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13710 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
13711 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13712 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
13713 | /bin/mkdir -p include/near
13714 | /bin/mkdir -p include/near
13715 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13716 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
13717 | /bin/mkdir -p include/near
13718 | /bin/mkdir -p include/near
13719 | /bin/mkdir -p include/near
13720 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13721 0.14-r0/neard-0.14/include/device.h include/near/device.h
13722 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13723 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
13724 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13725 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
13726 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13727 0.14-r0/neard-0.14/include/version.h include/near/version.h
13728 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
13729 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
13730 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
13731 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
13732 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
13733 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
13734 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
13735 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
13736 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
13737 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
13738 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
13739 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
13740 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
13741 -o tools/snep-send.o tools/snep-send.c
13742 | In file included from tools/snep-send.c:16:0:
13743 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13744 | #include &lt;near/dbus.h&gt;
13745 | ^
13746 | compilation terminated.
13747 | make[1]: *** [tools/snep-send.o] Error 1
13748 | make[1]: *** Waiting for unfinished jobs....
13749 | make: *** [all] Error 2
13750 | ERROR: oe_runmake failed
Brad Bishop316dfdd2018-06-25 12:45:53 -040013751 </literallayout>
13752 </para>
13753 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013754
Brad Bishop316dfdd2018-06-25 12:45:53 -040013755 <section id='reproducing-the-error'>
13756 <title>Reproducing the Error</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013757
Brad Bishop316dfdd2018-06-25 12:45:53 -040013758 <para>
13759 Because race conditions are intermittent, they do not
13760 manifest themselves every time you do the build.
13761 In fact, most times the build will complete without problems
13762 even though the potential race condition exists.
13763 Thus, once the error surfaces, you need a way to reproduce
13764 it.
13765 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013766
Brad Bishop316dfdd2018-06-25 12:45:53 -040013767 <para>
13768 In this example, compiling the "neard" package is causing
13769 the problem.
13770 So the first thing to do is build "neard" locally.
13771 Before you start the build, set the
13772 <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink>
13773 variable in your <filename>local.conf</filename> file to
13774 a high number (e.g. "-j 20").
13775 Using a high value for <filename>PARALLEL_MAKE</filename>
13776 increases the chances of the race condition showing up:
13777 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013778 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013779 </literallayout>
13780 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013781
Brad Bishop316dfdd2018-06-25 12:45:53 -040013782 <para>
13783 Once the local build for "neard" completes, start a
13784 <filename>devshell</filename> build:
13785 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013786 $ bitbake neard -c devshell
Brad Bishop316dfdd2018-06-25 12:45:53 -040013787 </literallayout>
13788 For information on how to use a
13789 <filename>devshell</filename>, see the
13790 "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>"
13791 section.
13792 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013793
Brad Bishop316dfdd2018-06-25 12:45:53 -040013794 <para>
13795 In the <filename>devshell</filename>, do the following:
13796 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013797 $ make clean
13798 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013799 </literallayout>
13800 The <filename>devshell</filename> commands cause the failure
13801 to clearly be visible.
13802 In this case, a missing dependency exists for the "neard"
13803 Makefile target.
13804 Here is some abbreviated, sample output with the
13805 missing dependency clearly visible at the end:
13806 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013807 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
13808 .
13809 .
13810 .
13811 tools/snep-send.c
13812 In file included from tools/snep-send.c:16:0:
13813 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
13814 #include &lt;near/dbus.h&gt;
13815 ^
13816 compilation terminated.
13817 make: *** [tools/snep-send.o] Error 1
13818 $
Brad Bishop316dfdd2018-06-25 12:45:53 -040013819 </literallayout>
13820 </para>
13821 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013822
Brad Bishop316dfdd2018-06-25 12:45:53 -040013823 <section id='creating-a-patch-for-the-fix'>
13824 <title>Creating a Patch for the Fix</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013825
Brad Bishop316dfdd2018-06-25 12:45:53 -040013826 <para>
13827 Because there is a missing dependency for the Makefile
13828 target, you need to patch the
13829 <filename>Makefile.am</filename> file, which is generated
13830 from <filename>Makefile.in</filename>.
13831 You can use Quilt to create the patch:
13832 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013833 $ quilt new parallelmake.patch
13834 Patch patches/parallelmake.patch is now on top
13835 $ quilt add Makefile.am
13836 File Makefile.am added to patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013837 </literallayout>
13838 For more information on using Quilt, see the
13839 "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>"
13840 section.
13841 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013842
Brad Bishop316dfdd2018-06-25 12:45:53 -040013843 <para>
13844 At this point you need to make the edits to
13845 <filename>Makefile.am</filename> to add the missing
13846 dependency.
13847 For our example, you have to add the following line
13848 to the file:
13849 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013850 tools/snep-send.$(OBJEXT): include/near/dbus.h
Brad Bishop316dfdd2018-06-25 12:45:53 -040013851 </literallayout>
13852 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013853
Brad Bishop316dfdd2018-06-25 12:45:53 -040013854 <para>
13855 Once you have edited the file, use the
13856 <filename>refresh</filename> command to create the patch:
13857 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013858 $ quilt refresh
13859 Refreshed patch patches/parallelmake.patch
Brad Bishop316dfdd2018-06-25 12:45:53 -040013860 </literallayout>
13861 Once the patch file exists, you need to add it back to the
13862 originating recipe folder.
13863 Here is an example assuming a top-level
13864 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
13865 named <filename>poky</filename>:
13866 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013867 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013868 </literallayout>
13869 The final thing you need to do to implement the fix in the
13870 build is to update the "neard" recipe (i.e.
13871 <filename>neard-0.14.bb</filename>) so that the
13872 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
13873 statement includes the patch file.
13874 The recipe file is in the folder above the patch.
13875 Here is what the edited <filename>SRC_URI</filename>
13876 statement would look like:
13877 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013878 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
13879 file://neard.in \
13880 file://neard.service.in \
13881 file://parallelmake.patch \
13882 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040013883 </literallayout>
13884 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013885
Brad Bishop316dfdd2018-06-25 12:45:53 -040013886 <para>
13887 With the patch complete and moved to the correct folder and
13888 the <filename>SRC_URI</filename> statement updated, you can
13889 exit the <filename>devshell</filename>:
13890 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013891 $ exit
Brad Bishop316dfdd2018-06-25 12:45:53 -040013892 </literallayout>
13893 </para>
13894 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013895
Brad Bishop316dfdd2018-06-25 12:45:53 -040013896 <section id='testing-the-build'>
13897 <title>Testing the Build</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013898
Brad Bishop316dfdd2018-06-25 12:45:53 -040013899 <para>
13900 With everything in place, you can get back to trying the
13901 build again locally:
13902 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013903 $ bitbake neard
Brad Bishop316dfdd2018-06-25 12:45:53 -040013904 </literallayout>
13905 This build should succeed.
13906 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013907
Brad Bishop316dfdd2018-06-25 12:45:53 -040013908 <para>
13909 Now you can open up a <filename>devshell</filename> again
13910 and repeat the clean and make operations as follows:
13911 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013912 $ bitbake neard -c devshell
13913 $ make clean
13914 $ make tools/snep-send.o
Brad Bishop316dfdd2018-06-25 12:45:53 -040013915 </literallayout>
13916 The build should work without issue.
13917 </para>
13918
13919 <para>
13920 As with all solved problems, if they originated upstream,
13921 you need to submit the fix for the recipe in OE-Core and
13922 upstream so that the problem is taken care of at its
13923 source.
13924 See the
13925 "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>"
13926 section for more information.
13927 </para>
13928 </section>
13929 </section>
13930
13931 <section id="platdev-gdb-remotedebug">
13932 <title>Debugging With the GNU Project Debugger (GDB) Remotely</title>
13933
13934 <para>
13935 GDB allows you to examine running programs, which in turn helps
13936 you to understand and fix problems.
13937 It also allows you to perform post-mortem style analysis of
13938 program crashes.
13939 GDB is available as a package within the Yocto Project and is
13940 installed in SDK images by default.
13941 See the
13942 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>"
13943 chapter in the Yocto Project Reference Manual for a description of
13944 these images.
13945 You can find information on GDB at
13946 <ulink url="http://sourceware.org/gdb/"/>.
13947 <note><title>Tip</title>
13948 For best results, install debug (<filename>-dbg</filename>)
13949 packages for the applications you are going to debug.
13950 Doing so makes extra debug symbols available that give you
13951 more meaningful output.
13952 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013953 </para>
13954
13955 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013956 Sometimes, due to memory or disk space constraints, it is not
13957 possible to use GDB directly on the remote target to debug
13958 applications.
13959 These constraints arise because GDB needs to load the debugging
13960 information and the binaries of the process being debugged.
13961 Additionally, GDB needs to perform many computations to locate
13962 information such as function names, variable names and values,
13963 stack traces and so forth - even before starting the debugging
13964 process.
13965 These extra computations place more load on the target system
13966 and can alter the characteristics of the program being debugged.
13967 </para>
13968
13969 <para>
13970 To help get past the previously mentioned constraints, you can
13971 use gdbserver, which runs on the remote target and does not
13972 load any debugging information from the debugged process.
13973 Instead, a GDB instance processes the debugging information that
13974 is run on a remote computer - the host GDB.
13975 The host GDB then sends control commands to gdbserver to make
13976 it stop or start the debugged program, as well as read or write
13977 memory regions of that debugged program.
13978 All the debugging information loaded and processed as well
13979 as all the heavy debugging is done by the host GDB.
13980 Offloading these processes gives the gdbserver running on the
13981 target a chance to remain small and fast.
13982 </para>
13983
13984 <para>
13985 Because the host GDB is responsible for loading the debugging
13986 information and for doing the necessary processing to make
13987 actual debugging happen, you have to make sure the host can
13988 access the unstripped binaries complete with their debugging
13989 information and also be sure the target is compiled with no
13990 optimizations.
13991 The host GDB must also have local access to all the libraries
13992 used by the debugged program.
13993 Because gdbserver does not need any local debugging information,
13994 the binaries on the remote target can remain stripped.
13995 However, the binaries must also be compiled without optimization
13996 so they match the host's binaries.
13997 </para>
13998
13999 <para>
14000 To remain consistent with GDB documentation and terminology,
14001 the binary being debugged on the remote target machine is
14002 referred to as the "inferior" binary.
14003 For documentation on GDB see the
14004 <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>.
14005 </para>
14006
14007 <para>
14008 The following steps show you how to debug using the GNU project
14009 debugger.
14010 <orderedlist>
14011 <listitem><para>
14012 <emphasis>Configure your build system to construct the
14013 companion debug filesystem:</emphasis></para>
14014
14015 <para>In your <filename>local.conf</filename> file, set
14016 the following:
14017 <literallayout class='monospaced'>
14018 IMAGE_GEN_DEBUGFS = "1"
14019 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
14020 </literallayout>
14021 These options cause the OpenEmbedded build system
14022 to generate a special companion filesystem fragment,
14023 which contains the matching source and debug symbols to
14024 your deployable filesystem.
14025 The build system does this by looking at what is in the
14026 deployed filesystem, and pulling the corresponding
14027 <filename>-dbg</filename> packages.</para>
14028
14029 <para>The companion debug filesystem is not a complete
14030 filesystem, but only contains the debug fragments.
14031 This filesystem must be combined with the full filesystem
14032 for debugging.
14033 Subsequent steps in this procedure show how to combine
14034 the partial filesystem with the full filesystem.
14035 </para></listitem>
14036 <listitem><para>
14037 <emphasis>Configure the system to include gdbserver in
14038 the target filesystem:</emphasis></para>
14039
14040 <para>Make the following addition in either your
14041 <filename>local.conf</filename> file or in an image
14042 recipe:
14043 <literallayout class='monospaced'>
14044 IMAGE_INSTALL_append = “ gdbserver"
14045 </literallayout>
14046 The change makes sure the <filename>gdbserver</filename>
14047 package is included.
14048 </para></listitem>
14049 <listitem><para>
14050 <emphasis>Build the environment:</emphasis></para>
14051
14052 <para>Use the following command to construct the image
14053 and the companion Debug Filesystem:
14054 <literallayout class='monospaced'>
14055 $ bitbake <replaceable>image</replaceable>
14056 </literallayout>
14057 Build the cross GDB component and make it available
14058 for debugging.
14059 Build the SDK that matches the image.
14060 Building the SDK is best for a production build
14061 that can be used later for debugging, especially
14062 during long term maintenance:
14063 <literallayout class='monospaced'>
14064 $ bitbake -c populate_sdk <replaceable>image</replaceable>
14065 </literallayout></para>
14066
14067 <para>Alternatively, you can build the minimal
14068 toolchain components that match the target.
14069 Doing so creates a smaller than typical SDK and only
14070 contains a minimal set of components with which to
14071 build simple test applications, as well as run the
14072 debugger:
14073 <literallayout class='monospaced'>
14074 $ bitbake meta-toolchain
14075 </literallayout></para>
14076
14077 <para>A final method is to build Gdb itself within
14078 the build system:
14079 <literallayout class='monospaced'>
14080 $ bitbake gdb-cross-<replaceable>architecture</replaceable>
14081 </literallayout>
14082 Doing so produces a temporary copy of
14083 <filename>cross-gdb</filename> you can use for
14084 debugging during development.
14085 While this is the quickest approach, the two previous
14086 methods in this step are better when considering
14087 long-term maintenance strategies.
14088 <note>
14089 If you run
14090 <filename>bitbake gdb-cross</filename>, the
14091 OpenEmbedded build system suggests the actual
14092 image (e.g. <filename>gdb-cross-i586</filename>).
14093 The suggestion is usually the actual name you want
14094 to use.
14095 </note>
14096 </para></listitem>
14097 <listitem><para>
14098 <emphasis>Set up the</emphasis>&nbsp;<filename>debugfs</filename></para>
14099
14100 <para>Run the following commands to set up the
14101 <filename>debugfs</filename>:
14102 <literallayout class='monospaced'>
14103 $ mkdir debugfs
14104 $ cd debugfs
14105 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2
14106 $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2
14107 </literallayout>
14108 </para></listitem>
14109 <listitem><para>
14110 <emphasis>Set up GDB</emphasis></para>
14111
14112 <para>Install the SDK (if you built one) and then
14113 source the correct environment file.
14114 Sourcing the environment file puts the SDK in your
14115 <filename>PATH</filename> environment variable.</para>
14116
14117 <para>If you are using the build system, Gdb is
14118 located in
14119 <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb
14120 </para></listitem>
14121 <listitem><para>
14122 <emphasis>Boot the target:</emphasis></para>
14123
14124 <para>For information on how to run QEMU, see the
14125 <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>.
14126 <note>
14127 Be sure to verify that your host can access the
14128 target via TCP.
14129 </note>
14130 </para></listitem>
14131 <listitem><para>
14132 <emphasis>Debug a program:</emphasis></para>
14133
14134 <para>Debugging a program involves running gdbserver
14135 on the target and then running Gdb on the host.
14136 The example in this step debugs
14137 <filename>gzip</filename>:
14138 <literallayout class='monospaced'>
14139 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
14140 </literallayout>
14141 For additional gdbserver options, see the
14142 <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>.
14143 </para>
14144
14145 <para>After running gdbserver on the target, you need
14146 to run Gdb on the host and configure it and connect to
14147 the target.
14148 Use these commands:
14149 <literallayout class='monospaced'>
14150 $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable>
14151 $ <replaceable>arch</replaceable>-gdb
14152
14153 (gdb) set sysroot debugfs
14154 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
14155 (gdb) target remote <replaceable>IP-of-target</replaceable>:1234
14156 </literallayout>
14157 At this point, everything should automatically load
14158 (i.e. matching binaries, symbols and headers).
14159 <note>
14160 The Gdb <filename>set</filename> commands in the
14161 previous example can be placed into the users
14162 <filename>~/.gdbinit</filename> file.
14163 Upon starting, Gdb automatically runs whatever
14164 commands are in that file.
14165 </note>
14166 </para></listitem>
14167 <listitem><para>
14168 <emphasis>Deploying without a full image
14169 rebuild:</emphasis></para>
14170
14171 <para>In many cases, during development you want a
14172 quick method to deploy a new binary to the target and
14173 debug it, without waiting for a full image build.
14174 </para>
14175
14176 <para>One approach to solving this situation is to
14177 just build the component you want to debug.
14178 Once you have built the component, copy the
14179 executable directly to both the target and the
14180 host <filename>debugfs</filename>.</para>
14181
14182 <para>If the binary is processed through the debug
14183 splitting in OpenEmbedded, you should also
14184 copy the debug items (i.e. <filename>.debug</filename>
14185 contents and corresponding
14186 <filename>/usr/src/debug</filename> files)
14187 from the work directory.
14188 Here is an example:
14189 <literallayout class='monospaced'>
14190 $ bitbake bash
14191 $ bitbake -c devshell bash
14192 $ cd ..
14193 $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash
14194 $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs
14195 </literallayout>
14196 </para></listitem>
14197 </orderedlist>
14198 </para>
14199 </section>
14200
14201 <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'>
14202 <title>Debugging with the GNU Project Debugger (GDB) on the Target</title>
14203
14204 <para>
14205 The previous section addressed using GDB remotely for debugging
14206 purposes, which is the most usual case due to the inherent
14207 hardware limitations on many embedded devices.
14208 However, debugging in the target hardware itself is also
14209 possible with more powerful devices.
14210 This section describes what you need to do in order to support
14211 using GDB to debug on the target hardware.
14212 </para>
14213
14214 <para>
14215 To support this kind of debugging, you need do the following:
14216 <itemizedlist>
14217 <listitem><para>
14218 Ensure that GDB is on the target.
14219 You can do this by adding "gdb" to
14220 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>:
14221 <literallayout class='monospaced'>
14222 IMAGE_INSTALL_append = " gdb"
14223 </literallayout>
14224 Alternatively, you can add "tools-debug" to
14225 <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>:
14226 <literallayout class='monospaced'>
14227 IMAGE_FEATURES_append = " tools-debug"
14228 </literallayout>
14229 </para></listitem>
14230 <listitem><para>
14231 Ensure that debug symbols are present.
14232 You can make sure these symbols are present by
14233 installing <filename>-dbg</filename>:
14234 <literallayout class='monospaced'>
14235 IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg"
14236 </literallayout>
14237 Alternatively, you can do the following to include all
14238 the debug symbols:
14239 <literallayout class='monospaced'>
14240 IMAGE_FEATURES_append = " dbg-pkgs"
14241 </literallayout>
14242 </para></listitem>
14243 </itemizedlist>
14244 <note>
14245 To improve the debug information accuracy, you can reduce
14246 the level of optimization used by the compiler.
14247 For example, when adding the following line to your
14248 <filename>local.conf</filename> file, you will reduce
14249 optimization from
14250 <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink>
14251 of "-O2" to
14252 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink>
14253 of "-O -fno-omit-frame-pointer":
14254 <literallayout class='monospaced'>
14255 DEBUG_BUILD = "1"
14256 </literallayout>
14257 Consider that this will reduce the application's performance
14258 and is recommended only for debugging purposes.
14259 </note>
14260 </para>
14261 </section>
14262
14263 <section id='dev-other-debugging-others'>
14264 <title>Other Debugging Tips</title>
14265
14266 <para>
14267 Here are some other tips that you might find useful:
14268 <itemizedlist>
14269 <listitem><para>
14270 When adding new packages, it is worth watching for
14271 undesirable items making their way into compiler command
14272 lines.
14273 For example, you do not want references to local system
14274 files like
14275 <filename>/usr/lib/</filename> or
14276 <filename>/usr/include/</filename>.
14277 </para></listitem>
14278 <listitem><para>
14279 If you want to remove the <filename>psplash</filename>
14280 boot splashscreen,
14281 add <filename>psplash=false</filename> to the kernel
14282 command line.
14283 Doing so prevents <filename>psplash</filename> from
14284 loading and thus allows you to see the console.
14285 It is also possible to switch out of the splashscreen by
14286 switching the virtual console (e.g. Fn+Left or Fn+Right
14287 on a Zaurus).
14288 </para></listitem>
14289 <listitem><para>
14290 Removing
14291 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>
14292 (usually <filename>tmp/</filename>, within the
14293 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>)
14294 can often fix temporary build issues.
14295 Removing <filename>TMPDIR</filename> is usually a
14296 relatively cheap operation, because task output will be
14297 cached in
14298 <ulink url='&YOCTO_DOCS_REF_URL;#var-SSTATE_DIR'><filename>SSTATE_DIR</filename></ulink>
14299 (usually <filename>sstate-cache/</filename>, which is
14300 also in the Build Directory).
14301 <note>
14302 Removing <filename>TMPDIR</filename> might be a
14303 workaround rather than a fix.
14304 Consequently, trying to determine the underlying
14305 cause of an issue before removing the directory is
14306 a good idea.
14307 </note>
14308 </para></listitem>
14309 <listitem><para>
14310 Understanding how a feature is used in practice within
14311 existing recipes can be very helpful.
14312 It is recommended that you configure some method that
14313 allows you to quickly search through files.</para>
14314
14315 <para>Using GNU Grep, you can use the following shell
14316 function to recursively search through common
14317 recipe-related files, skipping binary files,
14318 <filename>.git</filename> directories, and the
14319 Build Directory (assuming its name starts with
14320 "build"):
14321 <literallayout class='monospaced'>
14322 g() {
14323 grep -Ir \
14324 --exclude-dir=.git \
14325 --exclude-dir='build*' \
14326 --include='*.bb*' \
14327 --include='*.inc*' \
14328 --include='*.conf*' \
14329 --include='*.py*' \
14330 "$@"
14331 }
14332 </literallayout>
14333 Following are some usage examples:
14334 <literallayout class='monospaced'>
14335 $ g FOO # Search recursively for "FOO"
14336 $ g -i foo # Search recursively for "foo", ignoring case
14337 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
14338 </literallayout>
14339 If figuring out how some feature works requires a lot of
14340 searching, it might indicate that the documentation
14341 should be extended or improved.
14342 In such cases, consider filing a documentation bug using
14343 the Yocto Project implementation of
14344 <ulink url='https://bugzilla.yoctoproject.org/'>Bugzilla</ulink>.
14345 For information on how to submit a bug against
14346 the Yocto Project, see the Yocto Project Bugzilla
14347 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>wiki page</ulink>
14348 and the
14349 "<link linkend='submitting-a-defect-against-the-yocto-project'>Submitting a Defect Against the Yocto Project</link>"
14350 section.
14351 <note>
14352 The manuals might not be the right place to document
14353 variables that are purely internal and have a
14354 limited scope (e.g. internal variables used to
14355 implement a single <filename>.bbclass</filename>
14356 file).
14357 </note>
14358 </para></listitem>
14359 </itemizedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014360 </para>
14361 </section>
14362 </section>
14363
Brad Bishop316dfdd2018-06-25 12:45:53 -040014364 <section id='making-changes-to-the-yocto-project'>
14365 <title>Making Changes to the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014366
14367 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014368 Because the Yocto Project is an open-source, community-based
14369 project, you can effect changes to the project.
14370 This section presents procedures that show you how to submit
14371 a defect against the project and how to submit a change.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014372 </para>
14373
Brad Bishop316dfdd2018-06-25 12:45:53 -040014374 <section id='submitting-a-defect-against-the-yocto-project'>
14375 <title>Submitting a Defect Against the Yocto Project</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014376
14377 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014378 Use the Yocto Project implementation of
14379 <ulink url='http://www.bugzilla.org/about/'>Bugzilla</ulink>
14380 to submit a defect (bug) against the Yocto Project.
14381 For additional information on this implementation of Bugzilla see the
14382 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-bugtracker'>Yocto Project Bugzilla</ulink>"
14383 section in the Yocto Project Reference Manual.
14384 For more detail on any of the following steps, see the Yocto Project
14385 <ulink url='&YOCTO_WIKI_URL;/wiki/Bugzilla_Configuration_and_Bug_Tracking'>Bugzilla wiki page</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014386 </para>
14387
14388 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014389 Use the following general steps to submit a bug"
14390
14391 <orderedlist>
14392 <listitem><para>
14393 Open the Yocto Project implementation of
14394 <ulink url='&YOCTO_BUGZILLA_URL;'>Bugzilla</ulink>.
14395 </para></listitem>
14396 <listitem><para>
14397 Click "File a Bug" to enter a new bug.
14398 </para></listitem>
14399 <listitem><para>
14400 Choose the appropriate "Classification", "Product", and
14401 "Component" for which the bug was found.
14402 Bugs for the Yocto Project fall into one of several
14403 classifications, which in turn break down into several
14404 products and components.
14405 For example, for a bug against the
14406 <filename>meta-intel</filename> layer, you would choose
14407 "Build System, Metadata &amp; Runtime", "BSPs", and
14408 "bsps-meta-intel", respectively.
14409 </para></listitem>
14410 <listitem><para>
14411 Choose the "Version" of the Yocto Project for which you found
14412 the bug (e.g. &DISTRO;).
14413 </para></listitem>
14414 <listitem><para>
14415 Determine and select the "Severity" of the bug.
14416 The severity indicates how the bug impacted your work.
14417 </para></listitem>
14418 <listitem><para>
14419 Choose the "Hardware" that the bug impacts.
14420 </para></listitem>
14421 <listitem><para>
14422 Choose the "Architecture" that the bug impacts.
14423 </para></listitem>
14424 <listitem><para>
14425 Choose a "Documentation change" item for the bug.
14426 Fixing a bug might or might not affect the Yocto Project
14427 documentation.
14428 If you are unsure of the impact to the documentation, select
14429 "Don't Know".
14430 </para></listitem>
14431 <listitem><para>
14432 Provide a brief "Summary" of the bug.
14433 Try to limit your summary to just a line or two and be sure
14434 to capture the essence of the bug.
14435 </para></listitem>
14436 <listitem><para>
14437 Provide a detailed "Description" of the bug.
14438 You should provide as much detail as you can about the context,
14439 behavior, output, and so forth that surrounds the bug.
14440 You can even attach supporting files for output from logs by
14441 using the "Add an attachment" button.
14442 </para></listitem>
14443 <listitem><para>
14444 Click the "Submit Bug" button submit the bug.
14445 A new Bugzilla number is assigned to the bug and the defect
14446 is logged in the bug tracking system.
14447 </para></listitem>
14448 </orderedlist>
14449 Once you file a bug, the bug is processed by the Yocto Project Bug
14450 Triage Team and further details concerning the bug are assigned
14451 (e.g. priority and owner).
14452 You are the "Submitter" of the bug and any further categorization,
14453 progress, or comments on the bug result in Bugzilla sending you an
14454 automated email concerning the particular change or progress to the
14455 bug.
14456 </para>
14457 </section>
14458
14459 <section id='how-to-submit-a-change'>
14460 <title>Submitting a Change to the Yocto Project</title>
14461
14462 <para>
14463 Contributions to the Yocto Project and OpenEmbedded are very welcome.
14464 Because the system is extremely configurable and flexible, we recognize
14465 that developers will want to extend, configure or optimize it for
14466 their specific uses.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014467 </para>
14468
14469 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014470 The Yocto Project uses a mailing list and a patch-based workflow
14471 that is similar to the Linux kernel but contains important
14472 differences.
14473 In general, a mailing list exists through which you can submit
14474 patches.
14475 You should send patches to the appropriate mailing list so that they
14476 can be reviewed and merged by the appropriate maintainer.
14477 The specific mailing list you need to use depends on the
14478 location of the code you are changing.
14479 Each component (e.g. layer) should have a
14480 <filename>README</filename> file that indicates where to send
14481 the changes and which process to follow.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014482 </para>
14483
14484 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014485 You can send the patch to the mailing list using whichever approach
14486 you feel comfortable with to generate the patch.
14487 Once sent, the patch is usually reviewed by the community at large.
14488 If somebody has concerns with the patch, they will usually voice
14489 their concern over the mailing list.
14490 If a patch does not receive any negative reviews, the maintainer of
14491 the affected layer typically takes the patch, tests it, and then
14492 based on successful testing, merges the patch.
14493 </para>
14494
14495 <para id='figuring-out-the-mailing-list-to-use'>
14496 The "poky" repository, which is the Yocto Project's reference build
14497 environment, is a hybrid repository that contains several
14498 individual pieces (e.g. BitBake, Metadata, documentation,
14499 and so forth) built using the combo-layer tool.
14500 The upstream location used for submitting changes varies by
14501 component:
14502 <itemizedlist>
14503 <listitem><para>
14504 <emphasis>Core Metadata:</emphasis>
14505 Send your patch to the
14506 <ulink url='http://lists.openembedded.org/mailman/listinfo/openembedded-core'>openembedded-core</ulink>
14507 mailing list. For example, a change to anything under
14508 the <filename>meta</filename> or
14509 <filename>scripts</filename> directories should be sent
14510 to this mailing list.
14511 </para></listitem>
14512 <listitem><para>
14513 <emphasis>BitBake:</emphasis>
14514 For changes to BitBake (i.e. anything under the
14515 <filename>bitbake</filename> directory), send your patch
14516 to the
14517 <ulink url='http://lists.openembedded.org/mailman/listinfo/bitbake-devel'>bitbake-devel</ulink>
14518 mailing list.
14519 </para></listitem>
14520 <listitem><para>
14521 <emphasis>"meta-*" trees:</emphasis>
14522 These trees contain Metadata.
14523 Use the
14524 <ulink url='https://lists.yoctoproject.org/listinfo/poky'>poky</ulink>
14525 mailing list.
14526 </para></listitem>
14527 </itemizedlist>
14528 </para>
14529
14530 <para>
14531 For changes to other layers hosted in the Yocto Project source
14532 repositories (i.e. <filename>yoctoproject.org</filename>), tools,
14533 and the Yocto Project documentation, use the
14534 <ulink url='https://lists.yoctoproject.org/listinfo/yocto'>Yocto Project</ulink>
14535 general mailing list.
14536 <note>
14537 Sometimes a layer's documentation specifies to use a
14538 particular mailing list.
14539 If so, use that list.
14540 </note>
14541 For additional recipes that do not fit into the core Metadata, you
14542 should determine which layer the recipe should go into and submit
14543 the change in the manner recommended by the documentation (e.g.
14544 the <filename>README</filename> file) supplied with the layer.
14545 If in doubt, please ask on the Yocto general mailing list or on
14546 the openembedded-devel mailing list.
14547 </para>
14548
14549 <para>
14550 You can also push a change upstream and request a maintainer to
14551 pull the change into the component's upstream repository.
14552 You do this by pushing to a contribution repository that is upstream.
14553 See the
14554 "<ulink url='&YOCTO_DOCS_OM_URL;#gs-git-workflows-and-the-yocto-project'>Git Workflows and the Yocto Project</ulink>"
14555 section in the Yocto Project Overview and Concepts Manual for additional
14556 concepts on working in the Yocto Project development environment.
14557 </para>
14558
14559 <para>
14560 Two commonly used testing repositories exist for
14561 OpenEmbedded-Core:
14562 <itemizedlist>
14563 <listitem><para>
14564 <emphasis>"ross/mut" branch:</emphasis>
14565 The "mut" (master-under-test) tree
14566 exists in the <filename>poky-contrib</filename> repository
14567 in the
14568 <ulink url='&YOCTO_GIT_URL;'>Yocto Project source repositories</ulink>.
14569 </para></listitem>
14570 <listitem><para>
14571 <emphasis>"master-next" branch:</emphasis>
14572 This branch is part of the main
14573 "poky" repository in the Yocto Project source repositories.
14574 </para></listitem>
14575 </itemizedlist>
14576 Maintainers use these branches to test submissions prior to merging
14577 patches.
14578 Thus, you can get an idea of the status of a patch based on
14579 whether the patch has been merged into one of these branches.
14580 <note>
14581 This system is imperfect and changes can sometimes get lost in the
14582 flow.
14583 Asking about the status of a patch or change is reasonable if the
14584 change has been idle for a while with no feedback.
14585 The Yocto Project does have plans to use
14586 <ulink url='https://en.wikipedia.org/wiki/Patchwork_(software)'>Patchwork</ulink>
14587 to track the status of patches and also to automatically preview
14588 patches.
14589 </note>
14590 </para>
14591
14592 <para>
14593 The following sections provide procedures for submitting a change.
14594 </para>
14595
14596 <section id='pushing-a-change-upstream'>
14597 <title>Using Scripts to Push a Change Upstream and Request a Pull</title>
14598
14599 <para>
14600 Follow this procedure to push a change to an upstream "contrib"
14601 Git repository:
14602 <note>
14603 You can find general Git information on how to push a change
14604 upstream in the
14605 <ulink url='http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows'>Git Community Book</ulink>.
14606 </note>
14607 <orderedlist>
14608 <listitem><para>
14609 <emphasis>Make Your Changes Locally:</emphasis>
14610 Make your changes in your local Git repository.
14611 You should make small, controlled, isolated changes.
14612 Keeping changes small and isolated aids review,
14613 makes merging/rebasing easier and keeps the change
14614 history clean should anyone need to refer to it in
14615 future.
14616 </para></listitem>
14617 <listitem><para>
14618 <emphasis>Stage Your Changes:</emphasis>
14619 Stage your changes by using the <filename>git add</filename>
14620 command on each file you changed.
14621 </para></listitem>
14622 <listitem><para id='making-sure-you-have-correct-commit-information'>
14623 <emphasis>Commit Your Changes:</emphasis>
14624 Commit the change by using the
14625 <filename>git commit</filename> command.
14626 Make sure your commit information follows standards by
14627 following these accepted conventions:
14628 <itemizedlist>
14629 <listitem><para>
14630 Be sure to include a "Signed-off-by:" line in the
14631 same style as required by the Linux kernel.
14632 Adding this line signifies that you, the submitter,
14633 have agreed to the Developer's Certificate of
14634 Origin 1.1 as follows:
14635 <literallayout class='monospaced'>
14636 Developer's Certificate of Origin 1.1
14637
14638 By making a contribution to this project, I certify that:
14639
14640 (a) The contribution was created in whole or in part by me and I
14641 have the right to submit it under the open source license
14642 indicated in the file; or
14643
14644 (b) The contribution is based upon previous work that, to the best
14645 of my knowledge, is covered under an appropriate open source
14646 license and I have the right under that license to submit that
14647 work with modifications, whether created in whole or in part
14648 by me, under the same open source license (unless I am
14649 permitted to submit under a different license), as indicated
14650 in the file; or
14651
14652 (c) The contribution was provided directly to me by some other
14653 person who certified (a), (b) or (c) and I have not modified
14654 it.
14655
14656 (d) I understand and agree that this project and the contribution
14657 are public and that a record of the contribution (including all
14658 personal information I submit with it, including my sign-off) is
14659 maintained indefinitely and may be redistributed consistent with
14660 this project or the open source license(s) involved.
14661 </literallayout>
14662 </para></listitem>
14663 <listitem><para>
14664 Provide a single-line summary of the change.
14665 and,
14666 if more explanation is needed, provide more
14667 detail in the body of the commit.
14668 This summary is typically viewable in the
14669 "shortlist" of changes.
14670 Thus, providing something short and descriptive
14671 that gives the reader a summary of the change is
14672 useful when viewing a list of many commits.
14673 You should prefix this short description with the
14674 recipe name (if changing a recipe), or else with
14675 the short form path to the file being changed.
14676 </para></listitem>
14677 <listitem><para>
14678 For the body of the commit message, provide
14679 detailed information that describes what you
14680 changed, why you made the change, and the approach
14681 you used.
14682 It might also be helpful if you mention how you
14683 tested the change.
14684 Provide as much detail as you can in the body of
14685 the commit message.
14686 <note>
14687 You do not need to provide a more detailed
14688 explanation of a change if the change is
14689 minor to the point of the single line
14690 summary providing all the information.
14691 </note>
14692 </para></listitem>
14693 <listitem><para>
14694 If the change addresses a specific bug or issue
14695 that is associated with a bug-tracking ID,
14696 include a reference to that ID in your detailed
14697 description.
14698 For example, the Yocto Project uses a specific
14699 convention for bug references - any commit that
14700 addresses a specific bug should use the following
14701 form for the detailed description.
14702 Be sure to use the actual bug-tracking ID from
14703 Bugzilla for
14704 <replaceable>bug-id</replaceable>:
14705 <literallayout class='monospaced'>
14706 Fixes [YOCTO #<replaceable>bug-id</replaceable>]
14707
14708 <replaceable>detailed description of change</replaceable>
14709 </literallayout>
14710 </para></listitem>
14711 </itemizedlist>
14712 </para></listitem>
14713 <listitem><para>
14714 <emphasis>Push Your Commits to a "Contrib" Upstream:</emphasis>
14715 If you have arranged for permissions to push to an
14716 upstream contrib repository, push the change to that
14717 repository:
14718 <literallayout class='monospaced'>
14719 $ git push <replaceable>upstream_remote_repo</replaceable> <replaceable>local_branch_name</replaceable>
14720 </literallayout>
14721 For example, suppose you have permissions to push into the
14722 upstream <filename>meta-intel-contrib</filename>
14723 repository and you are working in a local branch named
14724 <replaceable>your_name</replaceable><filename>/README</filename>.
14725 The following command pushes your local commits to the
14726 <filename>meta-intel-contrib</filename> upstream
14727 repository and puts the commit in a branch named
14728 <replaceable>your_name</replaceable><filename>/README</filename>:
14729 <literallayout class='monospaced'>
14730 $ git push meta-intel-contrib <replaceable>your_name</replaceable>/README
14731 </literallayout>
14732 </para></listitem>
14733 <listitem><para id='push-determine-who-to-notify'>
14734 <emphasis>Determine Who to Notify:</emphasis>
14735 Determine the maintainer or the mailing list
14736 that you need to notify for the change.</para>
14737
14738 <para>Before submitting any change, you need to be sure
14739 who the maintainer is or what mailing list that you need
14740 to notify.
14741 Use either these methods to find out:
14742 <itemizedlist>
14743 <listitem><para>
14744 <emphasis>Maintenance File:</emphasis>
14745 Examine the <filename>maintainers.inc</filename>
14746 file, which is located in the
14747 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14748 at
14749 <filename>meta/conf/distro/include</filename>,
14750 to see who is responsible for code.
14751 </para></listitem>
14752 <listitem><para>
14753 <emphasis>Search by File:</emphasis>
14754 Using <ulink url='&YOCTO_DOCS_OM_URL;#git'>Git</ulink>,
14755 you can enter the following command to bring up a
14756 short list of all commits against a specific file:
14757 <literallayout class='monospaced'>
14758 git shortlog -- <replaceable>filename</replaceable>
14759 </literallayout>
14760 Just provide the name of the file for which you
14761 are interested.
14762 The information returned is not ordered by history
14763 but does include a list of everyone who has
14764 committed grouped by name.
14765 From the list, you can see who is responsible for
14766 the bulk of the changes against the file.
14767 </para></listitem>
14768 <listitem><para>
14769 <emphasis>Examine the List of Mailing Lists:</emphasis>
14770 For a list of the Yocto Project and related mailing
14771 lists, see the
14772 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing lists</ulink>"
14773 section in the Yocto Project Reference Manual.
14774 </para></listitem>
14775 </itemizedlist>
14776 </para></listitem>
14777 <listitem><para>
14778 <emphasis>Make a Pull Request:</emphasis>
14779 Notify the maintainer or the mailing list that you have
14780 pushed a change by making a pull request.</para>
14781
14782 <para>The Yocto Project provides two scripts that
14783 conveniently let you generate and send pull requests to the
14784 Yocto Project.
14785 These scripts are <filename>create-pull-request</filename>
14786 and <filename>send-pull-request</filename>.
14787 You can find these scripts in the
14788 <filename>scripts</filename> directory within the
14789 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
14790 (e.g. <filename>~/poky/scripts</filename>).
14791 </para>
14792
14793 <para>Using these scripts correctly formats the requests
14794 without introducing any whitespace or HTML formatting.
14795 The maintainer that receives your patches either directly
14796 or through the mailing list needs to be able to save and
14797 apply them directly from your emails.
14798 Using these scripts is the preferred method for sending
14799 patches.</para>
14800
14801 <para>First, create the pull request.
14802 For example, the following command runs the script,
14803 specifies the upstream repository in the contrib directory
14804 into which you pushed the change, and provides a subject
14805 line in the created patch files:
14806 <literallayout class='monospaced'>
14807 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
14808 </literallayout>
14809 Running this script forms
14810 <filename>*.patch</filename> files in a folder named
14811 <filename>pull-</filename><replaceable>PID</replaceable>
14812 in the current directory.
14813 One of the patch files is a cover letter.</para>
14814
14815 <para>Before running the
14816 <filename>send-pull-request</filename> script, you must
14817 edit the cover letter patch to insert information about
14818 your change.
14819 After editing the cover letter, send the pull request.
14820 For example, the following command runs the script and
14821 specifies the patch directory and email address.
14822 In this example, the email address is a mailing list:
14823 <literallayout class='monospaced'>
14824 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
14825 </literallayout>
14826 You need to follow the prompts as the script is
14827 interactive.
14828 <note>
14829 For help on using these scripts, simply provide the
14830 <filename>-h</filename> argument as follows:
14831 <literallayout class='monospaced'>
14832 $ poky/scripts/create-pull-request -h
14833 $ poky/scripts/send-pull-request -h
14834 </literallayout>
14835 </note>
14836 </para></listitem>
14837 </orderedlist>
14838 </para>
14839 </section>
14840
14841 <section id='submitting-a-patch'>
14842 <title>Using Email to Submit a Patch</title>
14843
14844 <para>
14845 You can submit patches without using the
14846 <filename>create-pull-request</filename> and
14847 <filename>send-pull-request</filename> scripts described in the
14848 previous section.
14849 However, keep in mind, the preferred method is to use the scripts.
14850 </para>
14851
14852 <para>
14853 Depending on the components changed, you need to submit the email
14854 to a specific mailing list.
14855 For some guidance on which mailing list to use, see the
14856 <link linkend='figuring-out-the-mailing-list-to-use'>list</link>
14857 at the beginning of this section.
14858 For a description of all the available mailing lists, see the
14859 "<ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Mailing Lists</ulink>"
14860 section in the Yocto Project Reference Manual.
14861 </para>
14862
14863 <para>
14864 Here is the general procedure on how to submit a patch through
14865 email without using the scripts:
14866 <orderedlist>
14867 <listitem><para>
14868 <emphasis>Make Your Changes Locally:</emphasis>
14869 Make your changes in your local Git repository.
14870 You should make small, controlled, isolated changes.
14871 Keeping changes small and isolated aids review,
14872 makes merging/rebasing easier and keeps the change
14873 history clean should anyone need to refer to it in
14874 future.
14875 </para></listitem>
14876 <listitem><para>
14877 <emphasis>Stage Your Changes:</emphasis>
14878 Stage your changes by using the <filename>git add</filename>
14879 command on each file you changed.
14880 </para></listitem>
14881 <listitem><para>
14882 <emphasis>Commit Your Changes:</emphasis>
14883 Commit the change by using the
14884 <filename>git commit --signoff</filename> command.
14885 Using the <filename>--signoff</filename> option identifies
14886 you as the person making the change and also satisfies
14887 the Developer's Certificate of Origin (DCO) shown earlier.
14888 </para>
14889
14890 <para>When you form a commit, you must follow certain
14891 standards established by the Yocto Project development
14892 team.
14893 See
14894 <link linkend='making-sure-you-have-correct-commit-information'>Step 3</link>
14895 in the previous section for information on how to
14896 provide commit information that meets Yocto Project
14897 commit message standards.
14898 </para></listitem>
14899 <listitem><para>
14900 <emphasis>Format the Commit:</emphasis>
14901 Format the commit into an email message.
14902 To format commits, use the
14903 <filename>git format-patch</filename> command.
14904 When you provide the command, you must include a revision
14905 list or a number of patches as part of the command.
14906 For example, either of these two commands takes your most
14907 recent single commit and formats it as an email message in
14908 the current directory:
14909 <literallayout class='monospaced'>
14910 $ git format-patch -1
14911 </literallayout>
14912 or
14913 <literallayout class='monospaced'>
14914 $ git format-patch HEAD~
14915 </literallayout></para>
14916
14917 <para>After the command is run, the current directory
14918 contains a numbered <filename>.patch</filename> file for
14919 the commit.</para>
14920
14921 <para>If you provide several commits as part of the
14922 command, the <filename>git format-patch</filename> command
14923 produces a series of numbered files in the current
14924 directory – one for each commit.
14925 If you have more than one patch, you should also use the
14926 <filename>--cover</filename> option with the command,
14927 which generates a cover letter as the first "patch" in
14928 the series.
14929 You can then edit the cover letter to provide a
14930 description for the series of patches.
14931 For information on the
14932 <filename>git format-patch</filename> command,
14933 see <filename>GIT_FORMAT_PATCH(1)</filename> displayed
14934 using the <filename>man git-format-patch</filename>
14935 command.
14936 <note>
14937 If you are or will be a frequent contributor to the
14938 Yocto Project or to OpenEmbedded, you might consider
14939 requesting a contrib area and the necessary associated
14940 rights.
14941 </note>
14942 </para></listitem>
14943 <listitem><para>
14944 <emphasis>Import the Files Into Your Mail Client:</emphasis>
14945 Import the files into your mail client by using the
14946 <filename>git send-email</filename> command.
14947 <note>
14948 In order to use <filename>git send-email</filename>,
14949 you must have the proper Git packages installed on
14950 your host.
14951 For Ubuntu, Debian, and Fedora the package is
14952 <filename>git-email</filename>.
14953 </note></para>
14954
14955 <para>The <filename>git send-email</filename> command
14956 sends email by using a local or remote Mail Transport Agent
14957 (MTA) such as <filename>msmtp</filename>,
14958 <filename>sendmail</filename>, or through a direct
14959 <filename>smtp</filename> configuration in your Git
14960 <filename>~/.gitconfig</filename> file.
14961 If you are submitting patches through email only, it is
14962 very important that you submit them without any whitespace
14963 or HTML formatting that either you or your mailer
14964 introduces.
14965 The maintainer that receives your patches needs to be able
14966 to save and apply them directly from your emails.
14967 A good way to verify that what you are sending will be
14968 applicable by the maintainer is to do a dry run and send
14969 them to yourself and then save and apply them as the
14970 maintainer would.</para>
14971
14972 <para>The <filename>git send-email</filename> command is
14973 the preferred method for sending your patches using
14974 email since there is no risk of compromising whitespace
14975 in the body of the message, which can occur when you use
14976 your own mail client.
14977 The command also has several options that let you
14978 specify recipients and perform further editing of the
14979 email message.
14980 For information on how to use the
14981 <filename>git send-email</filename> command,
14982 see <filename>GIT-SEND-EMAIL(1)</filename> displayed using
14983 the <filename>man git-send-email</filename> command.
14984 </para></listitem>
14985 </orderedlist>
14986 </para>
14987 </section>
14988 </section>
14989 </section>
14990
14991 <section id='working-with-licenses'>
14992 <title>Working With Licenses</title>
14993
14994 <para>
14995 As mentioned in the
14996 "<ulink url='&YOCTO_DOCS_OM_URL;#licensing'>Licensing</ulink>"
14997 section in the Yocto Project Overview and Concepts Manual,
14998 open source projects are open to the public and they
14999 consequently have different licensing structures in place.
15000 This section describes the mechanism by which the
15001 <ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>
15002 tracks changes to licensing text and covers how to maintain open
15003 source license compliance during your project's lifecycle.
15004 The section also describes how to enable commercially licensed
15005 recipes, which by default are disabled.
15006 </para>
15007
15008 <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
15009 <title>Tracking License Changes</title>
15010
15011 <para>
15012 The license of an upstream project might change in the future.
15013 In order to prevent these changes going unnoticed, the
15014 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
15015 variable tracks changes to the license text. The checksums are
15016 validated at the end of the configure step, and if the
15017 checksums do not match, the build will fail.
15018 </para>
15019
15020 <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
15021 <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
15022
15023 <para>
15024 The <filename>LIC_FILES_CHKSUM</filename>
15025 variable contains checksums of the license text in the
15026 source code for the recipe.
15027 Following is an example of how to specify
15028 <filename>LIC_FILES_CHKSUM</filename>:
15029 <literallayout class='monospaced'>
15030 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
15031 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
15032 file://licfile2.txt;endline=50;md5=zzzz \
15033 ..."
15034 </literallayout>
15035 <note><title>Notes</title>
15036 <itemizedlist>
15037 <listitem><para>
15038 When using "beginline" and "endline", realize
15039 that line numbering begins with one and not
15040 zero.
15041 Also, the included lines are inclusive (i.e.
15042 lines five through and including 29 in the
15043 previous example for
15044 <filename>licfile1.txt</filename>).
15045 </para></listitem>
15046 <listitem><para>
15047 When a license check fails, the selected license
15048 text is included as part of the QA message.
15049 Using this output, you can determine the exact
15050 start and finish for the needed license text.
15051 </para></listitem>
15052 </itemizedlist>
15053 </note>
15054 </para>
15055
15056 <para>
15057 The build system uses the
15058 <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
15059 variable as the default directory when searching files
15060 listed in <filename>LIC_FILES_CHKSUM</filename>.
15061 The previous example employs the default directory.
15062 </para>
15063
15064 <para>
15065 Consider this next example:
15066 <literallayout class='monospaced'>
15067 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
15068 md5=bb14ed3c4cda583abc85401304b5cd4e"
15069 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
15070 </literallayout>
15071 </para>
15072
15073 <para>
15074 The first line locates a file in
15075 <filename>${S}/src/ls.c</filename> and isolates lines five
15076 through 16 as license text.
15077 The second line refers to a file in
15078 <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>.
15079 </para>
15080
15081 <para>
15082 Note that <filename>LIC_FILES_CHKSUM</filename> variable is
15083 mandatory for all recipes, unless the
15084 <filename>LICENSE</filename> variable is set to "CLOSED".
15085 </para>
15086 </section>
15087
15088 <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
15089 <title>Explanation of Syntax</title>
15090
15091 <para>
15092 As mentioned in the previous section, the
15093 <filename>LIC_FILES_CHKSUM</filename> variable lists all
15094 the important files that contain the license text for the
15095 source code.
15096 It is possible to specify a checksum for an entire file,
15097 or a specific section of a file (specified by beginning and
15098 ending line numbers with the "beginline" and "endline"
15099 parameters, respectively).
15100 The latter is useful for source files with a license
15101 notice header, README documents, and so forth.
15102 If you do not use the "beginline" parameter, then it is
15103 assumed that the text begins on the first line of the file.
15104 Similarly, if you do not use the "endline" parameter,
15105 it is assumed that the license text ends with the last
15106 line of the file.
15107 </para>
15108
15109 <para>
15110 The "md5" parameter stores the md5 checksum of the license
15111 text.
15112 If the license text changes in any way as compared to
15113 this parameter then a mismatch occurs.
15114 This mismatch triggers a build failure and notifies
15115 the developer.
15116 Notification allows the developer to review and address
15117 the license text changes.
15118 Also note that if a mismatch occurs during the build,
15119 the correct md5 checksum is placed in the build log and
15120 can be easily copied to the recipe.
15121 </para>
15122
15123 <para>
15124 There is no limit to how many files you can specify using
15125 the <filename>LIC_FILES_CHKSUM</filename> variable.
15126 Generally, however, every project requires a few
15127 specifications for license tracking.
15128 Many projects have a "COPYING" file that stores the
15129 license information for all the source code files.
15130 This practice allows you to just track the "COPYING"
15131 file as long as it is kept up to date.
15132 <note><title>Tips</title>
15133 <itemizedlist>
15134 <listitem><para>
15135 If you specify an empty or invalid "md5"
15136 parameter,
15137 <ulink url='&YOCTO_DOCS_REF_URL;#bitbake-term'>BitBake</ulink>
15138 returns an md5 mis-match
15139 error and displays the correct "md5" parameter
15140 value during the build.
15141 The correct parameter is also captured in
15142 the build log.
15143 </para></listitem>
15144 <listitem><para>
15145 If the whole file contains only license text,
15146 you do not need to use the "beginline" and
15147 "endline" parameters.
15148 </para></listitem>
15149 </itemizedlist>
15150 </note>
15151 </para>
15152 </section>
15153 </section>
15154
15155 <section id="enabling-commercially-licensed-recipes">
15156 <title>Enabling Commercially Licensed Recipes</title>
15157
15158 <para>
15159 By default, the OpenEmbedded build system disables
15160 components that have commercial or other special licensing
15161 requirements.
15162 Such requirements are defined on a
15163 recipe-by-recipe basis through the
15164 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></ulink>
15165 variable definition in the affected recipe.
15166 For instance, the
15167 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15168 recipe contains the following statement:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015169 <literallayout class='monospaced'>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015170 LICENSE_FLAGS = "commercial"
15171 </literallayout>
15172 Here is a slightly more complicated example that contains both
15173 an explicit recipe name and version (after variable expansion):
15174 <literallayout class='monospaced'>
15175 LICENSE_FLAGS = "license_${PN}_${PV}"
15176 </literallayout>
15177 In order for a component restricted by a
15178 <filename>LICENSE_FLAGS</filename> definition to be enabled and
15179 included in an image, it needs to have a matching entry in the
15180 global
15181 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></ulink>
15182 variable, which is a variable typically defined in your
15183 <filename>local.conf</filename> file.
15184 For example, to enable the
15185 <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
15186 package, you could add either the string
15187 "commercial_gst-plugins-ugly" or the more general string
15188 "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
15189 See the
15190 "<link linkend='license-flag-matching'>License Flag Matching</link>"
15191 section for a full
15192 explanation of how <filename>LICENSE_FLAGS</filename> matching
15193 works.
15194 Here is the example:
15195 <literallayout class='monospaced'>
15196 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
15197 </literallayout>
15198 Likewise, to additionally enable the package built from the
15199 recipe containing
15200 <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>,
15201 and assuming that the actual recipe name was
15202 <filename>emgd_1.10.bb</filename>, the following string would
15203 enable that package as well as the original
15204 <filename>gst-plugins-ugly</filename> package:
15205 <literallayout class='monospaced'>
15206 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
15207 </literallayout>
15208 As a convenience, you do not need to specify the complete
15209 license string in the whitelist for every package.
15210 You can use an abbreviated form, which consists
15211 of just the first portion or portions of the license
15212 string before the initial underscore character or characters.
15213 A partial string will match any license that contains the
15214 given string as the first portion of its license.
15215 For example, the following whitelist string will also match
15216 both of the packages previously mentioned as well as any other
15217 packages that have licenses starting with "commercial" or
15218 "license".
15219 <literallayout class='monospaced'>
15220 LICENSE_FLAGS_WHITELIST = "commercial license"
15221 </literallayout>
15222 </para>
15223
15224 <section id="license-flag-matching">
15225 <title>License Flag Matching</title>
15226
15227 <para>
15228 License flag matching allows you to control what recipes
15229 the OpenEmbedded build system includes in the build.
15230 Fundamentally, the build system attempts to match
15231 <filename>LICENSE_FLAGS</filename> strings found in recipes
15232 against <filename>LICENSE_FLAGS_WHITELIST</filename>
15233 strings found in the whitelist.
15234 A match causes the build system to include a recipe in the
15235 build, while failure to find a match causes the build
15236 system to exclude a recipe.
15237 </para>
15238
15239 <para>
15240 In general, license flag matching is simple.
15241 However, understanding some concepts will help you
15242 correctly and effectively use matching.
15243 </para>
15244
15245 <para>
15246 Before a flag
15247 defined by a particular recipe is tested against the
15248 contents of the whitelist, the expanded string
15249 <filename>_${PN}</filename> is appended to the flag.
15250 This expansion makes each
15251 <filename>LICENSE_FLAGS</filename> value recipe-specific.
15252 After expansion, the string is then matched against the
15253 whitelist.
15254 Thus, specifying
15255 <filename>LICENSE_FLAGS = "commercial"</filename>
15256 in recipe "foo", for example, results in the string
15257 <filename>"commercial_foo"</filename>.
15258 And, to create a match, that string must appear in the
15259 whitelist.
15260 </para>
15261
15262 <para>
15263 Judicious use of the <filename>LICENSE_FLAGS</filename>
15264 strings and the contents of the
15265 <filename>LICENSE_FLAGS_WHITELIST</filename> variable
15266 allows you a lot of flexibility for including or excluding
15267 recipes based on licensing.
15268 For example, you can broaden the matching capabilities by
15269 using license flags string subsets in the whitelist.
15270 <note>
15271 When using a string subset, be sure to use the part of
15272 the expanded string that precedes the appended
15273 underscore character (e.g.
15274 <filename>usethispart_1.3</filename>,
15275 <filename>usethispart_1.4</filename>, and so forth).
15276 </note>
15277 For example, simply specifying the string "commercial" in
15278 the whitelist matches any expanded
15279 <filename>LICENSE_FLAGS</filename> definition that starts
15280 with the string "commercial" such as "commercial_foo" and
15281 "commercial_bar", which are the strings the build system
15282 automatically generates for hypothetical recipes named
15283 "foo" and "bar" assuming those recipes simply specify the
15284 following:
15285 <literallayout class='monospaced'>
15286 LICENSE_FLAGS = "commercial"
15287 </literallayout>
15288 Thus, you can choose to exhaustively
15289 enumerate each license flag in the whitelist and
15290 allow only specific recipes into the image, or
15291 you can use a string subset that causes a broader range of
15292 matches to allow a range of recipes into the image.
15293 </para>
15294
15295 <para>
15296 This scheme works even if the
15297 <filename>LICENSE_FLAGS</filename> string already
15298 has <filename>_${PN}</filename> appended.
15299 For example, the build system turns the license flag
15300 "commercial_1.2_foo" into "commercial_1.2_foo_foo" and
15301 would match both the general "commercial" and the specific
15302 "commercial_1.2_foo" strings found in the whitelist, as
15303 expected.
15304 </para>
15305
15306 <para>
15307 Here are some other scenarios:
15308 <itemizedlist>
15309 <listitem><para>
15310 You can specify a versioned string in the recipe
15311 such as "commercial_foo_1.2" in a "foo" recipe.
15312 The build system expands this string to
15313 "commercial_foo_1.2_foo".
15314 Combine this license flag with a whitelist that has
15315 the string "commercial" and you match the flag
15316 along with any other flag that starts with the
15317 string "commercial".
15318 </para></listitem>
15319 <listitem><para>
15320 Under the same circumstances, you can use
15321 "commercial_foo" in the whitelist and the build
15322 system not only matches "commercial_foo_1.2" but
15323 also matches any license flag with the string
15324 "commercial_foo", regardless of the version.
15325 </para></listitem>
15326 <listitem><para>
15327 You can be very specific and use both the
15328 package and version parts in the whitelist (e.g.
15329 "commercial_foo_1.2") to specifically match a
15330 versioned recipe.
15331 </para></listitem>
15332 </itemizedlist>
15333 </para>
15334 </section>
15335
15336 <section id="other-variables-related-to-commercial-licenses">
15337 <title>Other Variables Related to Commercial Licenses</title>
15338
15339 <para>
15340 Other helpful variables related to commercial
15341 license handling exist and are defined in the
15342 <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
15343 <literallayout class='monospaced'>
15344 COMMERCIAL_AUDIO_PLUGINS ?= ""
15345 COMMERCIAL_VIDEO_PLUGINS ?= ""
15346 </literallayout>
15347 If you want to enable these components, you can do so by
15348 making sure you have statements similar to the following
15349 in your <filename>local.conf</filename> configuration file:
15350 <literallayout class='monospaced'>
15351 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
15352 gst-plugins-ugly-mpegaudioparse"
15353 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
15354 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
15355 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
15356 </literallayout>
15357 Of course, you could also create a matching whitelist
15358 for those components using the more general "commercial"
15359 in the whitelist, but that would also enable all the
15360 other packages with <filename>LICENSE_FLAGS</filename>
15361 containing "commercial", which you may or may not want:
15362 <literallayout class='monospaced'>
15363 LICENSE_FLAGS_WHITELIST = "commercial"
15364 </literallayout>
15365 </para>
15366
15367 <para>
Brad Bishopc342db32019-05-15 21:57:59 -040015368 Specifying audio and video plugins as part of the
Brad Bishop316dfdd2018-06-25 12:45:53 -040015369 <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
15370 <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
15371 (along with the enabling
15372 <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
Brad Bishopc342db32019-05-15 21:57:59 -040015373 plugins or components into built images, thus adding
Brad Bishop316dfdd2018-06-25 12:45:53 -040015374 support for media formats or components.
15375 </para>
15376 </section>
15377 </section>
15378
15379 <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'>
15380 <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title>
15381
15382 <para>
15383 One of the concerns for a development organization using open source
15384 software is how to maintain compliance with various open source
15385 licensing during the lifecycle of the product.
15386 While this section does not provide legal advice or
15387 comprehensively cover all scenarios, it does
15388 present methods that you can use to
15389 assist you in meeting the compliance requirements during a software
15390 release.
15391 </para>
15392
15393 <para>
15394 With hundreds of different open source licenses that the Yocto
15395 Project tracks, it is difficult to know the requirements of each
15396 and every license.
15397 However, the requirements of the major FLOSS licenses can begin
15398 to be covered by
15399 assuming that three main areas of concern exist:
15400 <itemizedlist>
15401 <listitem><para>Source code must be provided.</para></listitem>
15402 <listitem><para>License text for the software must be
15403 provided.</para></listitem>
15404 <listitem><para>Compilation scripts and modifications to the
15405 source code must be provided.
15406 </para></listitem>
15407 </itemizedlist>
15408 There are other requirements beyond the scope of these
15409 three and the methods described in this section
15410 (e.g. the mechanism through which source code is distributed).
15411 </para>
15412
15413 <para>
15414 As different organizations have different methods of complying with
15415 open source licensing, this section is not meant to imply that
15416 there is only one single way to meet your compliance obligations,
15417 but rather to describe one method of achieving compliance.
15418 The remainder of this section describes methods supported to meet the
15419 previously mentioned three requirements.
15420 Once you take steps to meet these requirements,
15421 and prior to releasing images, sources, and the build system,
15422 you should audit all artifacts to ensure completeness.
15423 <note>
15424 The Yocto Project generates a license manifest during
15425 image creation that is located
15426 in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename>
15427 to assist with any audits.
15428 </note>
15429 </para>
15430
15431 <section id='providing-the-source-code'>
15432 <title>Providing the Source Code</title>
15433
15434 <para>
15435 Compliance activities should begin before you generate the
15436 final image.
15437 The first thing you should look at is the requirement that
15438 tops the list for most compliance groups - providing
15439 the source.
15440 The Yocto Project has a few ways of meeting this
15441 requirement.
15442 </para>
15443
15444 <para>
15445 One of the easiest ways to meet this requirement is
15446 to provide the entire
15447 <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>
15448 used by the build.
15449 This method, however, has a few issues.
15450 The most obvious is the size of the directory since it includes
15451 all sources used in the build and not just the source used in
15452 the released image.
15453 It will include toolchain source, and other artifacts, which
15454 you would not generally release.
15455 However, the more serious issue for most companies is accidental
15456 release of proprietary software.
15457 The Yocto Project provides an
15458 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink>
15459 class to help avoid some of these concerns.
15460 </para>
15461
15462 <para>
15463 Before you employ <filename>DL_DIR</filename> or the
15464 <filename>archiver</filename> class, you need to decide how
15465 you choose to provide source.
15466 The source <filename>archiver</filename> class can generate
15467 tarballs and SRPMs and can create them with various levels of
15468 compliance in mind.
15469 </para>
15470
15471 <para>
15472 One way of doing this (but certainly not the only way) is to
15473 release just the source as a tarball.
15474 You can do this by adding the following to the
15475 <filename>local.conf</filename> file found in the
15476 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>:
15477 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015478 INHERIT += "archiver"
15479 ARCHIVER_MODE[src] = "original"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015480 </literallayout>
15481 During the creation of your image, the source from all
15482 recipes that deploy packages to the image is placed within
15483 subdirectories of
15484 <filename>DEPLOY_DIR/sources</filename> based on the
15485 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
15486 for each recipe.
15487 Releasing the entire directory enables you to comply with
15488 requirements concerning providing the unmodified source.
15489 It is important to note that the size of the directory can
15490 get large.
15491 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015492
Brad Bishop316dfdd2018-06-25 12:45:53 -040015493 <para>
15494 A way to help mitigate the size issue is to only release
15495 tarballs for licenses that require the release of
15496 source.
15497 Let us assume you are only concerned with GPL code as
15498 identified by running the following script:
15499 <literallayout class='monospaced'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015500 # Script to archive a subset of packages matching specific license(s)
15501 # Source and license files are copied into sub folders of package folder
15502 # Must be run from build folder
15503 #!/bin/bash
15504 src_release_dir="source-release"
15505 mkdir -p $src_release_dir
15506 for a in tmp/deploy/sources/*; do
15507 for d in $a/*; do
15508 # Get package name from path
15509 p=`basename $d`
15510 p=${p%-*}
15511 p=${p%-*}
15512 # Only archive GPL packages (update *GPL* regex for your license check)
15513 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
15514 if [ $numfiles -gt 1 ]; then
15515 echo Archiving $p
15516 mkdir -p $src_release_dir/$p/source
15517 cp $d/* $src_release_dir/$p/source 2> /dev/null
15518 mkdir -p $src_release_dir/$p/license
15519 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
15520 fi
15521 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040015522 done
15523 </literallayout>
15524 At this point, you could create a tarball from the
15525 <filename>gpl_source_release</filename> directory and
15526 provide that to the end user.
15527 This method would be a step toward achieving compliance
15528 with section 3a of GPLv2 and with section 6 of GPLv3.
15529 </para>
15530 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015531
Brad Bishop316dfdd2018-06-25 12:45:53 -040015532 <section id='providing-license-text'>
15533 <title>Providing License Text</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015534
Brad Bishop316dfdd2018-06-25 12:45:53 -040015535 <para>
15536 One requirement that is often overlooked is inclusion
15537 of license text.
15538 This requirement also needs to be dealt with prior to
15539 generating the final image.
15540 Some licenses require the license text to accompany
15541 the binary.
15542 You can achieve this by adding the following to your
15543 <filename>local.conf</filename> file:
15544 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015545 COPY_LIC_MANIFEST = "1"
15546 COPY_LIC_DIRS = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015547 LICENSE_CREATE_PACKAGE = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040015548 </literallayout>
15549 Adding these statements to the configuration file ensures
15550 that the licenses collected during package generation
15551 are included on your image.
15552 <note>
15553 <para>Setting all three variables to "1" results in the
15554 image having two copies of the same license file.
15555 One copy resides in
15556 <filename>/usr/share/common-licenses</filename> and
15557 the other resides in
15558 <filename>/usr/share/license</filename>.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015559
Brad Bishop316dfdd2018-06-25 12:45:53 -040015560 <para>The reason for this behavior is because
15561 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink>
15562 and
15563 <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink>
15564 add a copy of the license when the image is built but do
15565 not offer a path for adding licenses for newly installed
15566 packages to an image.
15567 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink>
15568 adds a separate package and an upgrade path for adding
15569 licenses to an image.</para>
15570 </note>
15571 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015572
Brad Bishop316dfdd2018-06-25 12:45:53 -040015573 <para>
15574 As the source <filename>archiver</filename> class has already
15575 archived the original
15576 unmodified source that contains the license files,
15577 you would have already met the requirements for inclusion
15578 of the license information with source as defined by the GPL
15579 and other open source licenses.
15580 </para>
15581 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015582
Brad Bishop316dfdd2018-06-25 12:45:53 -040015583 <section id='providing-compilation-scripts-and-source-code-modifications'>
15584 <title>Providing Compilation Scripts and Source Code Modifications</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015585
Brad Bishop316dfdd2018-06-25 12:45:53 -040015586 <para>
15587 At this point, we have addressed all we need to
15588 prior to generating the image.
15589 The next two requirements are addressed during the final
15590 packaging of the release.
15591 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015592
Brad Bishop316dfdd2018-06-25 12:45:53 -040015593 <para>
15594 By releasing the version of the OpenEmbedded build system
15595 and the layers used during the build, you will be providing both
15596 compilation scripts and the source code modifications in one
15597 step.
15598 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015599
Brad Bishop316dfdd2018-06-25 12:45:53 -040015600 <para>
15601 If the deployment team has a
15602 <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink>
15603 and a distro layer, and those those layers are used to patch,
15604 compile, package, or modify (in any way) any open source
15605 software included in your released images, you
15606 might be required to release those layers under section 3 of
15607 GPLv2 or section 1 of GPLv3.
15608 One way of doing that is with a clean
15609 checkout of the version of the Yocto Project and layers used
15610 during your build.
15611 Here is an example:
15612 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015613 # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo
15614 $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015615 $ cd poky
15616 # We built using the release_branch for our layers
15617 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
15618 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
15619 # clean up the .git repos
15620 $ find . -name ".git" -type d -exec rm -rf {} \;
Brad Bishop316dfdd2018-06-25 12:45:53 -040015621 </literallayout>
15622 One thing a development organization might want to consider
15623 for end-user convenience is to modify
15624 <filename>meta-poky/conf/bblayers.conf.sample</filename> to
15625 ensure that when the end user utilizes the released build
15626 system to build an image, the development organization's
15627 layers are included in the <filename>bblayers.conf</filename>
15628 file automatically:
15629 <literallayout class='monospaced'>
15630 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015631 # changes incompatibly
Brad Bishop316dfdd2018-06-25 12:45:53 -040015632 POKY_BBLAYERS_CONF_VERSION = "2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015633
15634 BBPATH = "${TOPDIR}"
15635 BBFILES ?= ""
15636
15637 BBLAYERS ?= " \
15638 ##OEROOT##/meta \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050015639 ##OEROOT##/meta-poky \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015640 ##OEROOT##/meta-yocto-bsp \
15641 ##OEROOT##/meta-mylayer \
15642 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040015643 </literallayout>
15644 Creating and providing an archive of the
15645 <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>
15646 layers (recipes, configuration files, and so forth)
15647 enables you to meet your
15648 requirements to include the scripts to control compilation
15649 as well as any modifications to the original source.
15650 </para>
15651 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015652 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015653
15654 <section id='copying-licenses-that-do-not-exist'>
15655 <title>Copying Licenses that Do Not Exist</title>
15656
15657 <para>
15658 Some packages, such as the linux-firmware package, have many
15659 licenses that are not in any way common.
15660 You can avoid adding a lot of these types of common license
15661 files, which are only applicable to a specific package, by using
15662 the
15663 <ulink url='&YOCTO_DOCS_REF_URL;#var-NO_GENERIC_LICENSE'><filename>NO_GENERIC_LICENSE</filename></ulink>
15664 variable.
15665 Using this variable also avoids QA errors when you use a
15666 non-common, non-CLOSED license in a recipe.
15667 </para>
15668
15669 <para>
15670 The following is an example that uses the
15671 <filename>LICENSE.Abilis.txt</filename>
15672 file as the license from the fetched source:
15673 <literallayout class='monospaced'>
15674 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
15675 </literallayout>
15676 </para>
15677 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015678 </section>
15679
15680 <section id='using-the-error-reporting-tool'>
15681 <title>Using the Error Reporting Tool</title>
15682
15683 <para>
15684 The error reporting tool allows you to
15685 submit errors encountered during builds to a central database.
15686 Outside of the build environment, you can use a web interface to
15687 browse errors, view statistics, and query for errors.
15688 The tool works using a client-server system where the client
15689 portion is integrated with the installed Yocto Project
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015690 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015691 (e.g. <filename>poky</filename>).
15692 The server receives the information collected and saves it in a
15693 database.
15694 </para>
15695
15696 <para>
15697 A live instance of the error reporting server exists at
15698 <ulink url='http://errors.yoctoproject.org'></ulink>.
15699 This server exists so that when you want to get help with
15700 build failures, you can submit all of the information on the
15701 failure easily and then point to the URL in your bug report
15702 or send an email to the mailing list.
15703 <note>
15704 If you send error reports to this server, the reports become
15705 publicly visible.
15706 </note>
15707 </para>
15708
15709 <section id='enabling-and-using-the-tool'>
15710 <title>Enabling and Using the Tool</title>
15711
15712 <para>
15713 By default, the error reporting tool is disabled.
15714 You can enable it by inheriting the
15715 <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink>
15716 class by adding the following statement to the end of
15717 your <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015718 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015719 <literallayout class='monospaced'>
15720 INHERIT += "report-error"
15721 </literallayout>
15722 </para>
15723
15724 <para>
15725 By default, the error reporting feature stores information in
15726 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>.
15727 However, you can specify a directory to use by adding the following
15728 to your <filename>local.conf</filename> file:
15729 <literallayout class='monospaced'>
15730 ERR_REPORT_DIR = "path"
15731 </literallayout>
15732 Enabling error reporting causes the build process to collect
15733 the errors and store them in a file as previously described.
15734 When the build system encounters an error, it includes a
15735 command as part of the console output.
15736 You can run the command to send the error file to the server.
15737 For example, the following command sends the errors to an
15738 upstream server:
15739 <literallayout class='monospaced'>
15740 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
15741 </literallayout>
15742 In the previous example, the errors are sent to a public
15743 database available at
15744 <ulink url='http://errors.yoctoproject.org'></ulink>, which is
15745 used by the entire community.
15746 If you specify a particular server, you can send the errors
15747 to a different database.
15748 Use the following command for more information on available
15749 options:
15750 <literallayout class='monospaced'>
15751 $ send-error-report --help
15752 </literallayout>
15753 </para>
15754
15755 <para>
15756 When sending the error file, you are prompted to review the
15757 data being sent as well as to provide a name and optional
15758 email address.
15759 Once you satisfy these prompts, the command returns a link
15760 from the server that corresponds to your entry in the database.
15761 For example, here is a typical link:
15762 <literallayout class='monospaced'>
15763 http://errors.yoctoproject.org/Errors/Details/9522/
15764 </literallayout>
15765 Following the link takes you to a web interface where you can
15766 browse, query the errors, and view statistics.
15767 </para>
15768 </section>
15769
15770 <section id='disabling-the-tool'>
15771 <title>Disabling the Tool</title>
15772
15773 <para>
15774 To disable the error reporting feature, simply remove or comment
15775 out the following statement from the end of your
15776 <filename>local.conf</filename> file in your
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015777 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015778 <literallayout class='monospaced'>
15779 INHERIT += "report-error"
15780 </literallayout>
15781 </para>
15782 </section>
15783
15784 <section id='setting-up-your-own-error-reporting-server'>
15785 <title>Setting Up Your Own Error Reporting Server</title>
15786
15787 <para>
15788 If you want to set up your own error reporting server, you
15789 can obtain the code from the Git repository at
15790 <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>.
15791 Instructions on how to set it up are in the README document.
15792 </para>
15793 </section>
15794 </section>
Brad Bishop316dfdd2018-06-25 12:45:53 -040015795
15796 <section id="dev-using-wayland-and-weston">
15797 <title>Using Wayland and Weston</title>
15798
15799 <para>
15800 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
15801 is a computer display server protocol that
15802 provides a method for compositing window managers to communicate
15803 directly with applications and video hardware and expects them to
15804 communicate with input hardware using other libraries.
15805 Using Wayland with supporting targets can result in better control
15806 over graphics frame rendering than an application might otherwise
15807 achieve.
15808 </para>
15809
15810 <para>
15811 The Yocto Project provides the Wayland protocol libraries and the
15812 reference
15813 <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
15814 compositor as part of its release.
15815 You can find the integrated packages in the
15816 <filename>meta</filename> layer of the
15817 <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>.
15818 Specifically, you can find the recipes that build both Wayland
15819 and Weston at <filename>meta/recipes-graphics/wayland</filename>.
15820 </para>
15821
15822 <para>
15823 You can build both the Wayland and Weston packages for use only
15824 with targets that accept the
15825 <ulink url='https://en.wikipedia.org/wiki/Mesa_(computer_graphics)'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
15826 which is also known as Mesa DRI.
15827 This implies that you cannot build and use the packages if your
15828 target uses, for example, the
15829 <trademark class='registered'>Intel</trademark> Embedded Media
15830 and Graphics Driver
15831 (<trademark class='registered'>Intel</trademark> EMGD) that
15832 overrides Mesa DRI.
15833 <note>
15834 Due to lack of EGL support, Weston 1.0.3 will not run
15835 directly on the emulated QEMU hardware.
15836 However, this version of Weston will run under X emulation
15837 without issues.
15838 </note>
15839 </para>
15840
15841 <para>
15842 This section describes what you need to do to implement Wayland and
15843 use the Weston compositor when building an image for a supporting
15844 target.
15845 </para>
15846
15847 <section id="enabling-wayland-in-an-image">
15848 <title>Enabling Wayland in an Image</title>
15849
15850 <para>
15851 To enable Wayland, you need to enable it to be built and enable
15852 it to be included (installed) in the image.
15853 </para>
15854
15855 <section id="enable-building">
15856 <title>Building</title>
15857
15858 <para>
15859 To cause Mesa to build the <filename>wayland-egl</filename>
15860 platform and Weston to build Wayland with Kernel Mode
15861 Setting
15862 (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
15863 support, include the "wayland" flag in the
15864 <ulink url="&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></ulink>
15865 statement in your <filename>local.conf</filename> file:
15866 <literallayout class='monospaced'>
15867 DISTRO_FEATURES_append = " wayland"
15868 </literallayout>
15869 <note>
15870 If X11 has been enabled elsewhere, Weston will build
15871 Wayland with X11 support
15872 </note>
15873 </para>
15874 </section>
15875
15876 <section id="enable-installation-in-an-image">
15877 <title>Installing</title>
15878
15879 <para>
15880 To install the Wayland feature into an image, you must
15881 include the following
15882 <ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></ulink>
15883 statement in your <filename>local.conf</filename> file:
15884 <literallayout class='monospaced'>
15885 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
15886 </literallayout>
15887 </para>
15888 </section>
15889 </section>
15890
15891 <section id="running-weston">
15892 <title>Running Weston</title>
15893
15894 <para>
15895 To run Weston inside X11, enabling it as described earlier and
15896 building a Sato image is sufficient.
15897 If you are running your image under Sato, a Weston Launcher
15898 appears in the "Utility" category.
15899 </para>
15900
15901 <para>
15902 Alternatively, you can run Weston through the command-line
15903 interpretor (CLI), which is better suited for development work.
15904 To run Weston under the CLI, you need to do the following after
15905 your image is built:
15906 <orderedlist>
15907 <listitem><para>
15908 Run these commands to export
15909 <filename>XDG_RUNTIME_DIR</filename>:
15910 <literallayout class='monospaced'>
15911 mkdir -p /tmp/$USER-weston
15912 chmod 0700 /tmp/$USER-weston
15913 export XDG_RUNTIME_DIR=/tmp/$USER-weston
15914 </literallayout>
15915 </para></listitem>
15916 <listitem><para>
15917 Launch Weston in the shell:
15918 <literallayout class='monospaced'>
15919 weston
15920 </literallayout></para></listitem>
15921 </orderedlist>
15922 </para>
15923 </section>
15924 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015925</chapter>
15926
15927<!--
15928vim: expandtab tw=80 ts=4
15929-->