blob: d401d3b4ee7c8317194fb82189416429f26d1238 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
2
3************
4Common Tasks
5************
6
7This chapter describes fundamental procedures such as creating layers,
8adding new software packages, extending or customizing images, porting
9work to new hardware (adding a new machine), and so forth. You will find
10that the procedures documented here occur often in the development cycle
11using the Yocto Project.
12
13Understanding and Creating Layers
14=================================
15
16The OpenEmbedded build system supports organizing
17:term:`Metadata` into multiple layers.
18Layers allow you to isolate different types of customizations from each
19other. For introductory information on the Yocto Project Layer Model,
20see the
21":ref:`overview-manual/overview-manual-yp-intro:the yocto project layer model`"
22section in the Yocto Project Overview and Concepts Manual.
23
24Creating Your Own Layer
25-----------------------
26
27It is very easy to create your own layers to use with the OpenEmbedded
28build system. The Yocto Project ships with tools that speed up creating
29layers. This section describes the steps you perform by hand to create
30layers so that you can better understand them. For information about the
31layer-creation tools, see the
32":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
33section in the Yocto Project Board Support Package (BSP) Developer's
34Guide and the ":ref:`dev-manual/dev-manual-common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
35section further down in this manual.
36
37Follow these general steps to create your layer without using tools:
38
391. *Check Existing Layers:* Before creating a new layer, you should be
40 sure someone has not already created a layer containing the Metadata
41 you need. You can see the `OpenEmbedded Metadata
42 Index <https://layers.openembedded.org/layerindex/layers/>`__ for a
43 list of layers from the OpenEmbedded community that can be used in
44 the Yocto Project. You could find a layer that is identical or close
45 to what you need.
46
472. *Create a Directory:* Create the directory for your layer. When you
48 create the layer, be sure to create the directory in an area not
49 associated with the Yocto Project :term:`Source Directory`
50 (e.g. the cloned ``poky`` repository).
51
52 While not strictly required, prepend the name of the directory with
53 the string "meta-". For example:
54 ::
55
56 meta-mylayer
57 meta-GUI_xyz
58 meta-mymachine
59
60 With rare exceptions, a layer's name follows this form:
61 ::
62
63 meta-root_name
64
65 Following this layer naming convention can save
66 you trouble later when tools, components, or variables "assume" your
67 layer name begins with "meta-". A notable example is in configuration
68 files as shown in the following step where layer names without the
69 "meta-" string are appended to several variables used in the
70 configuration.
71
723. *Create a Layer Configuration File:* Inside your new layer folder,
73 you need to create a ``conf/layer.conf`` file. It is easiest to take
74 an existing layer configuration file and copy that to your layer's
75 ``conf`` directory and then modify the file as needed.
76
77 The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
78 :yocto_git:`Source Repositories </cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf>`
79 demonstrates the required syntax. For your layer, you need to replace
80 "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
81 for a layer named "meta-machinexyz"):
82 ::
83
84 # We have a conf and classes directory, add to BBPATH
85 BBPATH .= ":${LAYERDIR}"
86
87 # We have recipes-* directories, add to BBFILES
88 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
89 ${LAYERDIR}/recipes-*/*/*.bbappend"
90
91 BBFILE_COLLECTIONS += "yoctobsp"
92 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
93 BBFILE_PRIORITY_yoctobsp = "5"
94 LAYERVERSION_yoctobsp = "4"
95 LAYERSERIES_COMPAT_yoctobsp = "dunfell"
96
97 Following is an explanation of the layer configuration file:
98
99 - :term:`BBPATH`: Adds the layer's
100 root directory to BitBake's search path. Through the use of the
101 ``BBPATH`` variable, BitBake locates class files (``.bbclass``),
102 configuration files, and files that are included with ``include``
103 and ``require`` statements. For these cases, BitBake uses the
104 first file that matches the name found in ``BBPATH``. This is
105 similar to the way the ``PATH`` variable is used for binaries. It
106 is recommended, therefore, that you use unique class and
107 configuration filenames in your custom layer.
108
109 - :term:`BBFILES`: Defines the
110 location for all recipes in the layer.
111
112 - :term:`BBFILE_COLLECTIONS`:
113 Establishes the current layer through a unique identifier that is
114 used throughout the OpenEmbedded build system to refer to the
115 layer. In this example, the identifier "yoctobsp" is the
116 representation for the container layer named "meta-yocto-bsp".
117
118 - :term:`BBFILE_PATTERN`:
119 Expands immediately during parsing to provide the directory of the
120 layer.
121
122 - :term:`BBFILE_PRIORITY`:
123 Establishes a priority to use for recipes in the layer when the
124 OpenEmbedded build finds recipes of the same name in different
125 layers.
126
127 - :term:`LAYERVERSION`:
128 Establishes a version number for the layer. You can use this
129 version number to specify this exact version of the layer as a
130 dependency when using the
131 :term:`LAYERDEPENDS`
132 variable.
133
134 - :term:`LAYERDEPENDS`:
135 Lists all layers on which this layer depends (if any).
136
137 - :term:`LAYERSERIES_COMPAT`:
138 Lists the :yocto_wiki:`Yocto Project </wiki/Releases>`
139 releases for which the current version is compatible. This
140 variable is a good way to indicate if your particular layer is
141 current.
142
1434. *Add Content:* Depending on the type of layer, add the content. If
144 the layer adds support for a machine, add the machine configuration
145 in a ``conf/machine/`` file within the layer. If the layer adds
146 distro policy, add the distro configuration in a ``conf/distro/``
147 file within the layer. If the layer introduces new recipes, put the
148 recipes you need in ``recipes-*`` subdirectories within the layer.
149
150 .. note::
151
152 For an explanation of layer hierarchy that is compliant with the
153 Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
154 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
155
1565. *Optionally Test for Compatibility:* If you want permission to use
157 the Yocto Project Compatibility logo with your layer or application
158 that uses your layer, perform the steps to apply for compatibility.
159 See the "`Making Sure Your Layer is Compatible With Yocto
160 Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
161 section for more information.
162
163.. _best-practices-to-follow-when-creating-layers:
164
165Following Best Practices When Creating Layers
166---------------------------------------------
167
168To create layers that are easier to maintain and that will not impact
169builds for other machines, you should consider the information in the
170following list:
171
172- *Avoid "Overlaying" Entire Recipes from Other Layers in Your
173 Configuration:* In other words, do not copy an entire recipe into
174 your layer and then modify it. Rather, use an append file
175 (``.bbappend``) to override only those parts of the original recipe
176 you need to modify.
177
178- *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
179 for each recipe that uses an include file. Or, if you are introducing
180 a new recipe that requires the included file, use the path relative
181 to the original layer directory to refer to the file. For example,
182 use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
183 of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
184 the include file, it could indicate a deficiency in the include file
185 in the layer to which it originally belongs. If this is the case, you
186 should try to address that deficiency instead of overlaying the
187 include file. For example, you could address this by getting the
188 maintainer of the include file to add a variable or variables to make
189 it easy to override the parts needing to be overridden.
190
191- *Structure Your Layers:* Proper use of overrides within append files
192 and placement of machine-specific files within your layer can ensure
193 that a build is not using the wrong Metadata and negatively impacting
194 a build for a different machine. Following are some examples:
195
196 - *Modify Variables to Support a Different Machine:* Suppose you
197 have a layer named ``meta-one`` that adds support for building
198 machine "one". To do so, you use an append file named
199 ``base-files.bbappend`` and create a dependency on "foo" by
200 altering the :term:`DEPENDS`
201 variable:
202 ::
203
204 DEPENDS = "foo"
205
206 The dependency is created during any
207 build that includes the layer ``meta-one``. However, you might not
208 want this dependency for all machines. For example, suppose you
209 are building for machine "two" but your ``bblayers.conf`` file has
210 the ``meta-one`` layer included. During the build, the
211 ``base-files`` for machine "two" will also have the dependency on
212 ``foo``.
213
214 To make sure your changes apply only when building machine "one",
215 use a machine override with the ``DEPENDS`` statement:
216 ::
217
218 DEPENDS_one = "foo"
219
220 You should follow the same strategy when using ``_append``
221 and ``_prepend`` operations:
222 ::
223
224 DEPENDS_append_one = " foo"
225 DEPENDS_prepend_one = "foo "
226
227 As an actual example, here's a
228 snippet from the generic kernel include file ``linux-yocto.inc``,
229 wherein the kernel compile and link options are adjusted in the
230 case of a subset of the supported architectures:
231 ::
232
233 DEPENDS_append_aarch64 = " libgcc"
234 KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
235 KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
236
237 DEPENDS_append_nios2 = " libgcc"
238 KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
239 KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
240
241 DEPENDS_append_arc = " libgcc"
242 KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
243 KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
244
245 KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
246
247 .. note::
248
249 Avoiding "+=" and "=+" and using machine-specific ``_append``
250 and ``_prepend`` operations is recommended as well.
251
252 - *Place Machine-Specific Files in Machine-Specific Locations:* When
253 you have a base recipe, such as ``base-files.bb``, that contains a
254 :term:`SRC_URI` statement to a
255 file, you can use an append file to cause the build to use your
256 own version of the file. For example, an append file in your layer
257 at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
258 extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:
259 ::
260
261 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
262
263 The build for machine "one" will pick up your machine-specific file as
264 long as you have the file in
265 ``meta-one/recipes-core/base-files/base-files/``. However, if you
266 are building for a different machine and the ``bblayers.conf``
267 file includes the ``meta-one`` layer and the location of your
268 machine-specific file is the first location where that file is
269 found according to ``FILESPATH``, builds for all machines will
270 also use that machine-specific file.
271
272 You can make sure that a machine-specific file is used for a
273 particular machine by putting the file in a subdirectory specific
274 to the machine. For example, rather than placing the file in
275 ``meta-one/recipes-core/base-files/base-files/`` as shown above,
276 put it in ``meta-one/recipes-core/base-files/base-files/one/``.
277 Not only does this make sure the file is used only when building
278 for machine "one", but the build process locates the file more
279 quickly.
280
281 In summary, you need to place all files referenced from
282 ``SRC_URI`` in a machine-specific subdirectory within the layer in
283 order to restrict those files to machine-specific builds.
284
285- *Perform Steps to Apply for Yocto Project Compatibility:* If you want
286 permission to use the Yocto Project Compatibility logo with your
287 layer or application that uses your layer, perform the steps to apply
288 for compatibility. See the "`Making Sure Your Layer is Compatible
289 With Yocto
290 Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
291 section for more information.
292
293- *Follow the Layer Naming Convention:* Store custom layers in a Git
294 repository that use the ``meta-layer_name`` format.
295
296- *Group Your Layers Locally:* Clone your repository alongside other
297 cloned ``meta`` directories from the :term:`Source Directory`.
298
299Making Sure Your Layer is Compatible With Yocto Project
300-------------------------------------------------------
301
302When you create a layer used with the Yocto Project, it is advantageous
303to make sure that the layer interacts well with existing Yocto Project
304layers (i.e. the layer is compatible with the Yocto Project). Ensuring
305compatibility makes the layer easy to be consumed by others in the Yocto
306Project community and could allow you permission to use the Yocto
307Project Compatible Logo.
308
309.. note::
310
311 Only Yocto Project member organizations are permitted to use the
312 Yocto Project Compatible Logo. The logo is not available for general
313 use. For information on how to become a Yocto Project member
314 organization, see the :yocto_home:`Yocto Project Website <>`.
315
316The Yocto Project Compatibility Program consists of a layer application
317process that requests permission to use the Yocto Project Compatibility
318Logo for your layer and application. The process consists of two parts:
319
3201. Successfully passing a script (``yocto-check-layer``) that when run
321 against your layer, tests it against constraints based on experiences
322 of how layers have worked in the real world and where pitfalls have
323 been found. Getting a "PASS" result from the script is required for
324 successful compatibility registration.
325
3262. Completion of an application acceptance form, which you can find at
327 https://www.yoctoproject.org/webform/yocto-project-compatible-registration.
328
329To be granted permission to use the logo, you need to satisfy the
330following:
331
332- Be able to check the box indicating that you got a "PASS" when
333 running the script against your layer.
334
335- Answer "Yes" to the questions on the form or have an acceptable
336 explanation for any questions answered "No".
337
338- Be a Yocto Project Member Organization.
339
340The remainder of this section presents information on the registration
341form and on the ``yocto-check-layer`` script.
342
343Yocto Project Compatible Program Application
344~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345
346Use the form to apply for your layer's approval. Upon successful
347application, you can use the Yocto Project Compatibility Logo with your
348layer and the application that uses your layer.
349
350To access the form, use this link:
351https://www.yoctoproject.org/webform/yocto-project-compatible-registration.
352Follow the instructions on the form to complete your application.
353
354The application consists of the following sections:
355
356- *Contact Information:* Provide your contact information as the fields
357 require. Along with your information, provide the released versions
358 of the Yocto Project for which your layer is compatible.
359
360- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
361 items in the checklist. Space exists at the bottom of the form for
362 any explanations for items for which you answered "No".
363
364- *Recommendations:* Provide answers for the questions regarding Linux
365 kernel use and build success.
366
367``yocto-check-layer`` Script
368~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369
370The ``yocto-check-layer`` script provides you a way to assess how
371compatible your layer is with the Yocto Project. You should run this
372script prior to using the form to apply for compatibility as described
373in the previous section. You need to achieve a "PASS" result in order to
374have your application form successfully processed.
375
376The script divides tests into three areas: COMMON, BSP, and DISTRO. For
377example, given a distribution layer (DISTRO), the layer must pass both
378the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
379layer, the layer must pass the COMMON and BSP set of tests.
380
381To execute the script, enter the following commands from your build
382directory:
383::
384
385 $ source oe-init-build-env
386 $ yocto-check-layer your_layer_directory
387
388Be sure to provide the actual directory for your
389layer as part of the command.
390
391Entering the command causes the script to determine the type of layer
392and then to execute a set of specific tests against the layer. The
393following list overviews the test:
394
395- ``common.test_readme``: Tests if a ``README`` file exists in the
396 layer and the file is not empty.
397
398- ``common.test_parse``: Tests to make sure that BitBake can parse the
399 files without error (i.e. ``bitbake -p``).
400
401- ``common.test_show_environment``: Tests that the global or per-recipe
402 environment is in order without errors (i.e. ``bitbake -e``).
403
404- ``common.test_world``: Verifies that ``bitbake world`` works.
405
406- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
407 layers do not come with recipes that change signatures.
408
409- ``common.test_layerseries_compat``: Verifies layer compatibility is
410 set properly.
411
412- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
413 configurations.
414
415- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
416 set the machine when the layer is added.
417
418- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
419 regardless of which machine is selected.
420
421- ``bsp.test_machine_signatures``: Verifies that building for a
422 particular machine affects only the signature of tasks specific to
423 that machine.
424
425- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
426 distro configurations.
427
428- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
429 does not set the distribution when the layer is added.
430
431Enabling Your Layer
432-------------------
433
434Before the OpenEmbedded build system can use your new layer, you need to
435enable it. To enable your layer, simply add your layer's path to the
436``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
437found in the :term:`Build Directory`.
438The following example shows how to enable a layer named
439``meta-mylayer``:
440::
441
442 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
443 # changes incompatibly
444 POKY_BBLAYERS_CONF_VERSION = "2"
445 BBPATH = "${TOPDIR}"
446 BBFILES ?= ""
447 BBLAYERS ?= " \
448 /home/user/poky/meta \
449 /home/user/poky/meta-poky \
450 /home/user/poky/meta-yocto-bsp \
451 /home/user/poky/meta-mylayer \
452 "
453
454BitBake parses each ``conf/layer.conf`` file from the top down as
455specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
456file. During the processing of each ``conf/layer.conf`` file, BitBake
457adds the recipes, classes and configurations contained within the
458particular layer to the source directory.
459
460.. _using-bbappend-files:
461
462Using .bbappend Files in Your Layer
463-----------------------------------
464
465A recipe that appends Metadata to another recipe is called a BitBake
466append file. A BitBake append file uses the ``.bbappend`` file type
467suffix, while the corresponding recipe to which Metadata is being
468appended uses the ``.bb`` file type suffix.
469
470You can use a ``.bbappend`` file in your layer to make additions or
471changes to the content of another layer's recipe without having to copy
472the other layer's recipe into your layer. Your ``.bbappend`` file
473resides in your layer, while the main ``.bb`` recipe file to which you
474are appending Metadata resides in a different layer.
475
476Being able to append information to an existing recipe not only avoids
477duplication, but also automatically applies recipe changes from a
478different layer into your layer. If you were copying recipes, you would
479have to manually merge changes as they occur.
480
481When you create an append file, you must use the same root name as the
482corresponding recipe file. For example, the append file
483``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
484means the original recipe and append file names are version
485number-specific. If the corresponding recipe is renamed to update to a
486newer version, you must also rename and possibly update the
487corresponding ``.bbappend`` as well. During the build process, BitBake
488displays an error on starting if it detects a ``.bbappend`` file that
489does not have a corresponding recipe with a matching name. See the
490:term:`BB_DANGLINGAPPENDS_WARNONLY`
491variable for information on how to handle this error.
492
493As an example, consider the main formfactor recipe and a corresponding
494formfactor append file both from the :term:`Source Directory`.
495Here is the main
496formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
497the "meta" layer at ``meta/recipes-bsp/formfactor``:
498::
499
500 SUMMARY = "Device formfactor information"
501 DESCRIPTION = "A formfactor configuration file provides information about the \
502 target hardware for which the image is being built and information that the \
503 build system cannot obtain from other sources such as the kernel."
504 SECTION = "base"
505 LICENSE = "MIT"
506 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
507 PR = "r45"
508
509 SRC_URI = "file://config file://machconfig"
510 S = "${WORKDIR}"
511
512 PACKAGE_ARCH = "${MACHINE_ARCH}"
513 INHIBIT_DEFAULT_DEPS = "1"
514
515 do_install() {
516 # Install file only if it has contents
517 install -d ${D}${sysconfdir}/formfactor/
518 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
519 if [ -s "${S}/machconfig" ]; then
520 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
521 fi
522 }
523
524In the main recipe, note the :term:`SRC_URI`
525variable, which tells the OpenEmbedded build system where to find files
526during the build.
527
528Following is the append file, which is named ``formfactor_0.0.bbappend``
529and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
530file is in the layer at ``recipes-bsp/formfactor``:
531::
532
533 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
534
535By default, the build system uses the
536:term:`FILESPATH` variable to
537locate files. This append file extends the locations by setting the
538:term:`FILESEXTRAPATHS`
539variable. Setting this variable in the ``.bbappend`` file is the most
540reliable and recommended method for adding directories to the search
541path used by the build system to find files.
542
543The statement in this example extends the directories to include
544``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
545which resolves to a directory named ``formfactor`` in the same directory
546in which the append file resides (i.e.
547``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
548have the supporting directory structure set up that will contain any
549files or patches you will be including from the layer.
550
551Using the immediate expansion assignment operator ``:=`` is important
552because of the reference to ``THISDIR``. The trailing colon character is
553important as it ensures that items in the list remain colon-separated.
554
555.. note::
556
557 BitBake automatically defines the ``THISDIR`` variable. You should
558 never set this variable yourself. Using "_prepend" as part of the
559 ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
560 paths in the final list.
561
562 Also, not all append files add extra files. Many append files simply
563 exist to add build options (e.g. ``systemd``). For these cases, your
564 append file would not even use the ``FILESEXTRAPATHS`` statement.
565
566Prioritizing Your Layer
567-----------------------
568
569Each layer is assigned a priority value. Priority values control which
570layer takes precedence if there are recipe files with the same name in
571multiple layers. For these cases, the recipe file from the layer with a
572higher priority number takes precedence. Priority values also affect the
573order in which multiple ``.bbappend`` files for the same recipe are
574applied. You can either specify the priority manually, or allow the
575build system to calculate it based on the layer's dependencies.
576
577To specify the layer's priority manually, use the
578:term:`BBFILE_PRIORITY`
579variable and append the layer's root name:
580::
581
582 BBFILE_PRIORITY_mylayer = "1"
583
584.. note::
585
586 It is possible for a recipe with a lower version number
587 :term:`PV` in a layer that has a higher
588 priority to take precedence.
589
590 Also, the layer priority does not currently affect the precedence
591 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
592 might address this.
593
594Managing Layers
595---------------
596
597You can use the BitBake layer management tool ``bitbake-layers`` to
598provide a view into the structure of recipes across a multi-layer
599project. Being able to generate output that reports on configured layers
600with their paths and priorities and on ``.bbappend`` files and their
601applicable recipes can help to reveal potential problems.
602
603For help on the BitBake layer management tool, use the following
604command:
605::
606
607 $ bitbake-layers --help
608 NOTE: Starting bitbake server...
609 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
610
611 BitBake layers utility
612
613 optional arguments:
614 -d, --debug Enable debug output
615 -q, --quiet Print only errors
616 -F, --force Force add without recipe parse verification
617 --color COLOR Colorize output (where COLOR is auto, always, never)
618 -h, --help show this help message and exit
619
620 subcommands:
621 <subcommand>
622 layerindex-fetch Fetches a layer from a layer index along with its
623 dependent layers, and adds them to conf/bblayers.conf.
624 layerindex-show-depends
625 Find layer dependencies from layer index.
626 add-layer Add one or more layers to bblayers.conf.
627 remove-layer Remove one or more layers from bblayers.conf.
628 flatten flatten layer configuration into a separate output
629 directory.
630 show-layers show current configured layers.
631 show-overlayed list overlayed recipes (where the same recipe exists
632 in another layer)
633 show-recipes list available recipes, showing the layer they are
634 provided by
635 show-appends list bbappend files and recipe files they apply to
636 show-cross-depends Show dependencies between recipes that cross layer
637 boundaries.
638 create-layer Create a basic layer
639
640 Use bitbake-layers <subcommand> --help to get help on a specific command
641
642The following list describes the available commands:
643
644- ``help:`` Displays general help or help on a specified command.
645
646- ``show-layers:`` Shows the current configured layers.
647
648- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
649 when a recipe with the same name exists in another layer that has a
650 higher layer priority.
651
652- ``show-recipes:`` Lists available recipes and the layers that
653 provide them.
654
655- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
656 which they apply.
657
658- ``show-cross-depends:`` Lists dependency relationships between
659 recipes that cross layer boundaries.
660
661- ``add-layer:`` Adds a layer to ``bblayers.conf``.
662
663- ``remove-layer:`` Removes a layer from ``bblayers.conf``
664
665- ``flatten:`` Flattens the layer configuration into a separate
666 output directory. Flattening your layer configuration builds a
667 "flattened" directory that contains the contents of all layers, with
668 any overlayed recipes removed and any ``.bbappend`` files appended to
669 the corresponding recipes. You might have to perform some manual
670 cleanup of the flattened layer as follows:
671
672 - Non-recipe files (such as patches) are overwritten. The flatten
673 command shows a warning for these files.
674
675 - Anything beyond the normal layer setup has been added to the
676 ``layer.conf`` file. Only the lowest priority layer's
677 ``layer.conf`` is used.
678
679 - Overridden and appended items from ``.bbappend`` files need to be
680 cleaned up. The contents of each ``.bbappend`` end up in the
681 flattened recipe. However, if there are appended or changed
682 variable values, you need to tidy these up yourself. Consider the
683 following example. Here, the ``bitbake-layers`` command adds the
684 line ``#### bbappended ...`` so that you know where the following
685 lines originate:
686 ::
687
688 ...
689 DESCRIPTION = "A useful utility"
690 ...
691 EXTRA_OECONF = "--enable-something"
692 ...
693
694 #### bbappended from meta-anotherlayer ####
695
696 DESCRIPTION = "Customized utility"
697 EXTRA_OECONF += "--enable-somethingelse"
698
699
700 Ideally, you would tidy up these utilities as follows:
701 ::
702
703 ...
704 DESCRIPTION = "Customized utility"
705 ...
706 EXTRA_OECONF = "--enable-something --enable-somethingelse"
707 ...
708
709- ``layerindex-fetch``: Fetches a layer from a layer index, along
710 with its dependent layers, and adds the layers to the
711 ``conf/bblayers.conf`` file.
712
713- ``layerindex-show-depends``: Finds layer dependencies from the
714 layer index.
715
716- ``create-layer``: Creates a basic layer.
717
718Creating a General Layer Using the ``bitbake-layers`` Script
719------------------------------------------------------------
720
721The ``bitbake-layers`` script with the ``create-layer`` subcommand
722simplifies creating a new general layer.
723
724.. note::
725
726 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
727 section in the Yocto
728 Project Board Specific (BSP) Developer's Guide.
729
730 - In order to use a layer with the OpenEmbedded build system, you
731 need to add the layer to your ``bblayers.conf`` configuration
732 file. See the ":ref:`dev-manual/dev-manual-common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
733 section for more information.
734
735The default mode of the script's operation with this subcommand is to
736create a layer with the following:
737
738- A layer priority of 6.
739
740- A ``conf`` subdirectory that contains a ``layer.conf`` file.
741
742- A ``recipes-example`` subdirectory that contains a further
743 subdirectory named ``example``, which contains an ``example.bb``
744 recipe file.
745
746- A ``COPYING.MIT``, which is the license statement for the layer. The
747 script assumes you want to use the MIT license, which is typical for
748 most layers, for the contents of the layer itself.
749
750- A ``README`` file, which is a file describing the contents of your
751 new layer.
752
753In its simplest form, you can use the following command form to create a
754layer. The command creates a layer whose name corresponds to
755"your_layer_name" in the current directory:
756::
757
758 $ bitbake-layers create-layer your_layer_name
759
760As an example, the following command creates a layer named ``meta-scottrif``
761in your home directory:
762::
763
764 $ cd /usr/home
765 $ bitbake-layers create-layer meta-scottrif
766 NOTE: Starting bitbake server...
767 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
768
769If you want to set the priority of the layer to other than the default
770value of "6", you can either use the ``--priority`` option or you
771can edit the
772:term:`BBFILE_PRIORITY` value
773in the ``conf/layer.conf`` after the script creates it. Furthermore, if
774you want to give the example recipe file some name other than the
775default, you can use the ``--example-recipe-name`` option.
776
777The easiest way to see how the ``bitbake-layers create-layer`` command
778works is to experiment with the script. You can also read the usage
779information by entering the following:
780::
781
782 $ bitbake-layers create-layer --help
783 NOTE: Starting bitbake server...
784 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
785 [--example-recipe-name EXAMPLERECIPE]
786 layerdir
787
788 Create a basic layer
789
790 positional arguments:
791 layerdir Layer directory to create
792
793 optional arguments:
794 -h, --help show this help message and exit
795 --priority PRIORITY, -p PRIORITY
796 Layer directory to create
797 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
798 Filename of the example recipe
799
800Adding a Layer Using the ``bitbake-layers`` Script
801--------------------------------------------------
802
803Once you create your general layer, you must add it to your
804``bblayers.conf`` file. Adding the layer to this configuration file
805makes the OpenEmbedded build system aware of your layer so that it can
806search it for metadata.
807
808Add your layer by using the ``bitbake-layers add-layer`` command:
809::
810
811 $ bitbake-layers add-layer your_layer_name
812
813Here is an example that adds a
814layer named ``meta-scottrif`` to the configuration file. Following the
815command that adds the layer is another ``bitbake-layers`` command that
816shows the layers that are in your ``bblayers.conf`` file:
817::
818
819 $ bitbake-layers add-layer meta-scottrif
820 NOTE: Starting bitbake server...
821 Parsing recipes: 100% |##########################################################| Time: 0:00:49
822 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
823 $ bitbake-layers show-layers
824 NOTE: Starting bitbake server...
825 layer path priority
826 ==========================================================================
827 meta /home/scottrif/poky/meta 5
828 meta-poky /home/scottrif/poky/meta-poky 5
829 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
830 workspace /home/scottrif/poky/build/workspace 99
831 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
832
833
834Adding the layer to this file
835enables the build system to locate the layer during the build.
836
837.. note::
838
839 During a build, the OpenEmbedded build system looks in the layers
840 from the top of the list down to the bottom in that order.
841
842.. _usingpoky-extend-customimage:
843
844Customizing Images
845==================
846
847You can customize images to satisfy particular requirements. This
848section describes several methods and provides guidelines for each.
849
850.. _usingpoky-extend-customimage-localconf:
851
852Customizing Images Using ``local.conf``
853---------------------------------------
854
855Probably the easiest way to customize an image is to add a package by
856way of the ``local.conf`` configuration file. Because it is limited to
857local use, this method generally only allows you to add packages and is
858not as flexible as creating your own customized image. When you add
859packages using local variables this way, you need to realize that these
860variable changes are in effect for every build and consequently affect
861all images, which might not be what you require.
862
863To add a package to your image using the local configuration file, use
864the ``IMAGE_INSTALL`` variable with the ``_append`` operator:
865::
866
867 IMAGE_INSTALL_append = " strace"
868
869Use of the syntax is important -
870specifically, the space between the quote and the package name, which is
871``strace`` in this example. This space is required since the ``_append``
872operator does not add the space.
873
874Furthermore, you must use ``_append`` instead of the ``+=`` operator if
875you want to avoid ordering issues. The reason for this is because doing
876so unconditionally appends to the variable and avoids ordering problems
877due to the variable being set in image recipes and ``.bbclass`` files
878with operators like ``?=``. Using ``_append`` ensures the operation
879takes effect.
880
881As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
882images. It is possible to extend the syntax so that the variable applies
883to a specific image only. Here is an example:
884::
885
886 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
887
888This example adds ``strace`` to the ``core-image-minimal`` image only.
889
890You can add packages using a similar approach through the
891``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
892``core-image-*`` images are affected.
893
894.. _usingpoky-extend-customimage-imagefeatures:
895
896Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
897-------------------------------------------------------------------------------
898
899Another method for customizing your image is to enable or disable
900high-level image features by using the
901:term:`IMAGE_FEATURES` and
902:term:`EXTRA_IMAGE_FEATURES`
903variables. Although the functions for both variables are nearly
904equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
905a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
906``local.conf`` file, which is found in the
907:term:`Build Directory`.
908
909To understand how these features work, the best reference is
910``meta/classes/core-image.bbclass``. This class lists out the available
911``IMAGE_FEATURES`` of which most map to package groups while some, such
912as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
913configuration settings.
914
915In summary, the file looks at the contents of the ``IMAGE_FEATURES``
916variable and then maps or configures the feature accordingly. Based on
917this information, the build system automatically adds the appropriate
918packages or configurations to the
919:term:`IMAGE_INSTALL` variable.
920Effectively, you are enabling extra features by extending the class or
921creating a custom class for use with specialized image ``.bb`` files.
922
923Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
924configuration file. Using a separate area from which to enable features
925with this variable helps you avoid overwriting the features in the image
926recipe that are enabled with ``IMAGE_FEATURES``. The value of
927``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
928``meta/conf/bitbake.conf``.
929
930To illustrate how you can use these variables to modify your image,
931consider an example that selects the SSH server. The Yocto Project ships
932with two SSH servers you can use with your images: Dropbear and OpenSSH.
933Dropbear is a minimal SSH server appropriate for resource-constrained
934environments, while OpenSSH is a well-known standard SSH server
935implementation. By default, the ``core-image-sato`` image is configured
936to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
937images both include OpenSSH. The ``core-image-minimal`` image does not
938contain an SSH server.
939
940You can customize your image and change these defaults. Edit the
941``IMAGE_FEATURES`` variable in your recipe or use the
942``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
943configures the image you are working with to include
944``ssh-server-dropbear`` or ``ssh-server-openssh``.
945
946.. note::
947
948 See the ":ref:`ref-manual/ref-features:image features`" section in the Yocto
949 Project Reference Manual for a complete list of image features that ship
950 with the Yocto Project.
951
952.. _usingpoky-extend-customimage-custombb:
953
954Customizing Images Using Custom .bb Files
955-----------------------------------------
956
957You can also customize an image by creating a custom recipe that defines
958additional software as part of the image. The following example shows
959the form for the two lines you need:
960::
961
962 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
963 inherit core-image
964
965Defining the software using a custom recipe gives you total control over
966the contents of the image. It is important to use the correct names of
967packages in the ``IMAGE_INSTALL`` variable. You must use the
968OpenEmbedded notation and not the Debian notation for the names (e.g.
969``glibc-dev`` instead of ``libc6-dev``).
970
971The other method for creating a custom image is to base it on an
972existing image. For example, if you want to create an image based on
973``core-image-sato`` but add the additional package ``strace`` to the
974image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
975``.bb`` and add the following line to the end of the copy:
976::
977
978 IMAGE_INSTALL += "strace"
979
980.. _usingpoky-extend-customimage-customtasks:
981
982Customizing Images Using Custom Package Groups
983----------------------------------------------
984
985For complex custom images, the best approach for customizing an image is
986to create a custom package group recipe that is used to build the image
987or images. A good example of a package group recipe is
988``meta/recipes-core/packagegroups/packagegroup-base.bb``.
989
990If you examine that recipe, you see that the ``PACKAGES`` variable lists
991the package group packages to produce. The ``inherit packagegroup``
992statement sets appropriate default values and automatically adds
993``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
994package specified in the ``PACKAGES`` statement.
995
996.. note::
997
998 The ``inherit packagegroup`` line should be located near the top of the
999 recipe, certainly before the ``PACKAGES`` statement.
1000
1001For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
1002and ``RRECOMMENDS`` entries to provide a list of packages the parent
1003task package should contain. You can see examples of these further down
1004in the ``packagegroup-base.bb`` recipe.
1005
1006Here is a short, fabricated example showing the same basic pieces for a
1007hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
1008the variable ``PN`` is the standard way to abbreviate the reference to
1009the full packagegroup name ``packagegroup-custom``:
1010::
1011
1012 DESCRIPTION = "My Custom Package Groups"
1013
1014 inherit packagegroup
1015
1016 PACKAGES = "\
1017 ${PN}-apps \
1018 ${PN}-tools \
1019 "
1020
1021 RDEPENDS_${PN}-apps = "\
1022 dropbear \
1023 portmap \
1024 psplash"
1025
1026 RDEPENDS_${PN}-tools = "\
1027 oprofile \
1028 oprofileui-server \
1029 lttng-tools"
1030
1031 RRECOMMENDS_${PN}-tools = "\
1032 kernel-module-oprofile"
1033
1034In the previous example, two package group packages are created with
1035their dependencies and their recommended package dependencies listed:
1036``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1037build an image using these package group packages, you need to add
1038``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
1039``IMAGE_INSTALL``. For other forms of image dependencies see the other
1040areas of this section.
1041
1042.. _usingpoky-extend-customimage-image-name:
1043
1044Customizing an Image Hostname
1045-----------------------------
1046
1047By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1048is the same as the machine name. For example, if
1049:term:`MACHINE` equals "qemux86", the
1050configured hostname written to ``/etc/hostname`` is "qemux86".
1051
1052You can customize this name by altering the value of the "hostname"
1053variable in the ``base-files`` recipe using either an append file or a
1054configuration file. Use the following in an append file:
1055::
1056
1057 hostname = "myhostname"
1058
1059Use the following in a configuration file:
1060::
1061
1062 hostname_pn-base-files = "myhostname"
1063
1064Changing the default value of the variable "hostname" can be useful in
1065certain situations. For example, suppose you need to do extensive
1066testing on an image and you would like to easily identify the image
1067under test from existing images with typical default hostnames. In this
1068situation, you could change the default hostname to "testme", which
1069results in all the images using the name "testme". Once testing is
1070complete and you do not need to rebuild the image for test any longer,
1071you can easily reset the default hostname.
1072
1073Another point of interest is that if you unset the variable, the image
1074will have no default hostname in the filesystem. Here is an example that
1075unsets the variable in a configuration file:
1076::
1077
1078 hostname_pn-base-files = ""
1079
1080Having no default hostname in the filesystem is suitable for
1081environments that use dynamic hostnames such as virtual machines.
1082
1083.. _new-recipe-writing-a-new-recipe:
1084
1085Writing a New Recipe
1086====================
1087
1088Recipes (``.bb`` files) are fundamental components in the Yocto Project
1089environment. Each software component built by the OpenEmbedded build
1090system requires a recipe to define the component. This section describes
1091how to create, write, and test a new recipe.
1092
1093.. note::
1094
1095 For information on variables that are useful for recipes and for
1096 information about recipe naming issues, see the
1097 ":ref:`ref-manual/ref-varlocality:recipes`" section of the Yocto Project
1098 Reference Manual.
1099
1100.. _new-recipe-overview:
1101
1102Overview
1103--------
1104
1105The following figure shows the basic process for creating a new recipe.
1106The remainder of the section provides details for the steps.
1107
1108.. image:: figures/recipe-workflow.png
1109 :align: center
1110
1111.. _new-recipe-locate-or-automatically-create-a-base-recipe:
1112
1113Locate or Automatically Create a Base Recipe
1114--------------------------------------------
1115
1116You can always write a recipe from scratch. However, three choices exist
1117that can help you quickly get a start on a new recipe:
1118
1119- ``devtool add``: A command that assists in creating a recipe and an
1120 environment conducive to development.
1121
1122- ``recipetool create``: A command provided by the Yocto Project that
1123 automates creation of a base recipe based on the source files.
1124
1125- *Existing Recipes:* Location and modification of an existing recipe
1126 that is similar in function to the recipe you need.
1127
1128.. note::
1129
1130 For information on recipe syntax, see the
1131 ":ref:`dev-manual/dev-manual-common-tasks:recipe syntax`" section.
1132
1133.. _new-recipe-creating-the-base-recipe-using-devtool:
1134
1135Creating the Base Recipe Using ``devtool add``
1136~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1137
1138The ``devtool add`` command uses the same logic for auto-creating the
1139recipe as ``recipetool create``, which is listed below. Additionally,
1140however, ``devtool add`` sets up an environment that makes it easy for
1141you to patch the source and to make changes to the recipe as is often
1142necessary when adding a recipe to build a new piece of software to be
1143included in a build.
1144
1145You can find a complete description of the ``devtool add`` command in
1146the ":ref:`sdk-a-closer-look-at-devtool-add`" section
1147in the Yocto Project Application Development and the Extensible Software
1148Development Kit (eSDK) manual.
1149
1150.. _new-recipe-creating-the-base-recipe-using-recipetool:
1151
1152Creating the Base Recipe Using ``recipetool create``
1153~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1154
1155``recipetool create`` automates creation of a base recipe given a set of
1156source code files. As long as you can extract or point to the source
1157files, the tool will construct a recipe and automatically configure all
1158pre-build information into the recipe. For example, suppose you have an
1159application that builds using Autotools. Creating the base recipe using
1160``recipetool`` results in a recipe that has the pre-build dependencies,
1161license requirements, and checksums configured.
1162
1163To run the tool, you just need to be in your
1164:term:`Build Directory` and have sourced the
1165build environment setup script (i.e.
1166:ref:`structure-core-script`).
1167To get help on the tool, use the following command:
1168::
1169
1170 $ recipetool -h
1171 NOTE: Starting bitbake server...
1172 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1173
1174 OpenEmbedded recipe tool
1175
1176 options:
1177 -d, --debug Enable debug output
1178 -q, --quiet Print only errors
1179 --color COLOR Colorize output (where COLOR is auto, always, never)
1180 -h, --help show this help message and exit
1181
1182 subcommands:
1183 create Create a new recipe
1184 newappend Create a bbappend for the specified target in the specified
1185 layer
1186 setvar Set a variable within a recipe
1187 appendfile Create/update a bbappend to replace a target file
1188 appendsrcfiles Create/update a bbappend to add or replace source files
1189 appendsrcfile Create/update a bbappend to add or replace a source file
1190 Use recipetool <subcommand> --help to get help on a specific command
1191
1192Running ``recipetool create -o OUTFILE`` creates the base recipe and
1193locates it properly in the layer that contains your source files.
1194Following are some syntax examples:
1195
1196 - Use this syntax to generate a recipe based on source. Once generated,
1197 the recipe resides in the existing source code layer:
1198 ::
1199
1200 recipetool create -o OUTFILE source
1201
1202 - Use this syntax to generate a recipe using code that
1203 you extract from source. The extracted code is placed in its own layer
1204 defined by ``EXTERNALSRC``.
1205 ::
1206
1207 recipetool create -o OUTFILE -x EXTERNALSRC source
1208
1209 - Use this syntax to generate a recipe based on source. The options
1210 direct ``recipetool`` to generate debugging information. Once generated,
1211 the recipe resides in the existing source code layer:
1212 ::
1213
1214 recipetool create -d -o OUTFILE source
1215
1216.. _new-recipe-locating-and-using-a-similar-recipe:
1217
1218Locating and Using a Similar Recipe
1219~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1220
1221Before writing a recipe from scratch, it is often useful to discover
1222whether someone else has already written one that meets (or comes close
1223to meeting) your needs. The Yocto Project and OpenEmbedded communities
1224maintain many recipes that might be candidates for what you are doing.
1225You can find a good central index of these recipes in the `OpenEmbedded
1226Layer Index <https://layers.openembedded.org>`__.
1227
1228Working from an existing recipe or a skeleton recipe is the best way to
1229get started. Here are some points on both methods:
1230
1231- *Locate and modify a recipe that is close to what you want to do:*
1232 This method works when you are familiar with the current recipe
1233 space. The method does not work so well for those new to the Yocto
1234 Project or writing recipes.
1235
1236 Some risks associated with this method are using a recipe that has
1237 areas totally unrelated to what you are trying to accomplish with
1238 your recipe, not recognizing areas of the recipe that you might have
1239 to add from scratch, and so forth. All these risks stem from
1240 unfamiliarity with the existing recipe space.
1241
1242- *Use and modify the following skeleton recipe:* If for some reason
1243 you do not want to use ``recipetool`` and you cannot find an existing
1244 recipe that is close to meeting your needs, you can use the following
1245 structure to provide the fundamental areas of a new recipe.
1246 ::
1247
1248 DESCRIPTION = ""
1249 HOMEPAGE = ""
1250 LICENSE = ""
1251 SECTION = ""
1252 DEPENDS = ""
1253 LIC_FILES_CHKSUM = ""
1254
1255 SRC_URI = ""
1256
1257.. _new-recipe-storing-and-naming-the-recipe:
1258
1259Storing and Naming the Recipe
1260-----------------------------
1261
1262Once you have your base recipe, you should put it in your own layer and
1263name it appropriately. Locating it correctly ensures that the
1264OpenEmbedded build system can find it when you use BitBake to process
1265the recipe.
1266
1267- *Storing Your Recipe:* The OpenEmbedded build system locates your
1268 recipe through the layer's ``conf/layer.conf`` file and the
1269 :term:`BBFILES` variable. This
1270 variable sets up a path from which the build system can locate
1271 recipes. Here is the typical use:
1272 ::
1273
1274 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1275 ${LAYERDIR}/recipes-*/*/*.bbappend"
1276
1277 Consequently, you need to be sure you locate your new recipe inside
1278 your layer such that it can be found.
1279
1280 You can find more information on how layers are structured in the
1281 "`Understanding and Creating
1282 Layers <#understanding-and-creating-layers>`__" section.
1283
1284- *Naming Your Recipe:* When you name your recipe, you need to follow
1285 this naming convention:
1286 ::
1287
1288 basename_version.bb
1289
1290 Use lower-cased characters and do not include the reserved suffixes
1291 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1292 them as part of your recipe name unless the string applies). Here are some
1293 examples:
1294
1295 .. code-block:: none
1296
1297 cups_1.7.0.bb
1298 gawk_4.0.2.bb
1299 irssi_0.8.16-rc1.bb
1300
1301.. _new-recipe-running-a-build-on-the-recipe:
1302
1303Running a Build on the Recipe
1304-----------------------------
1305
1306Creating a new recipe is usually an iterative process that requires
1307using BitBake to process the recipe multiple times in order to
1308progressively discover and add information to the recipe file.
1309
1310Assuming you have sourced the build environment setup script (i.e.
1311:ref:`structure-core-script`) and you are in
1312the :term:`Build Directory`, use
1313BitBake to process your recipe. All you need to provide is the
1314``basename`` of the recipe as described in the previous section:
1315::
1316
1317 $ bitbake basename
1318
1319During the build, the OpenEmbedded build system creates a temporary work
1320directory for each recipe
1321(``${``\ :term:`WORKDIR`\ ``}``)
1322where it keeps extracted source files, log files, intermediate
1323compilation and packaging files, and so forth.
1324
1325The path to the per-recipe temporary work directory depends on the
1326context in which it is being built. The quickest way to find this path
1327is to have BitBake return it by running the following:
1328::
1329
1330 $ bitbake -e basename | grep ^WORKDIR=
1331
1332As an example, assume a Source Directory
1333top-level folder named ``poky``, a default Build Directory at
1334``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1335Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1336case, the work directory the build system uses to build the package
1337would be as follows:
1338::
1339
1340 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1341
1342Inside this directory you can find sub-directories such as ``image``,
1343``packages-split``, and ``temp``. After the build, you can examine these
1344to determine how well the build went.
1345
1346.. note::
1347
1348 You can find log files for each task in the recipe's ``temp``
1349 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1350 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1351 ``log.do_fetch``, and ``log.do_compile``).
1352
1353You can find more information about the build process in
1354":doc:`../overview-manual/overview-manual-development-environment`"
1355chapter of the Yocto Project Overview and Concepts Manual.
1356
1357.. _new-recipe-fetching-code:
1358
1359Fetching Code
1360-------------
1361
1362The first thing your recipe must do is specify how to fetch the source
1363files. Fetching is controlled mainly through the
1364:term:`SRC_URI` variable. Your recipe
1365must have a ``SRC_URI`` variable that points to where the source is
1366located. For a graphical representation of source locations, see the
1367":ref:`sources-dev-environment`" section in
1368the Yocto Project Overview and Concepts Manual.
1369
1370The :ref:`ref-tasks-fetch` task uses
1371the prefix of each entry in the ``SRC_URI`` variable value to determine
1372which :ref:`fetcher <bitbake:bb-fetchers>` to use to get your
1373source files. It is the ``SRC_URI`` variable that triggers the fetcher.
1374The :ref:`ref-tasks-patch` task uses
1375the variable after source is fetched to apply patches. The OpenEmbedded
1376build system uses
1377:term:`FILESOVERRIDES` for
1378scanning directory locations for local files in ``SRC_URI``.
1379
1380The ``SRC_URI`` variable in your recipe must define each unique location
1381for your source files. It is good practice to not hard-code version
1382numbers in a URL used in ``SRC_URI``. Rather than hard-code these
1383values, use ``${``\ :term:`PV`\ ``}``,
1384which causes the fetch process to use the version specified in the
1385recipe filename. Specifying the version in this manner means that
1386upgrading the recipe to a future version is as simple as renaming the
1387recipe to match the new version.
1388
1389Here is a simple example from the
1390``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1391comes from a single tarball. Notice the use of the
1392:term:`PV` variable:
1393::
1394
1395 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
1396
1397Files mentioned in ``SRC_URI`` whose names end in a typical archive
1398extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1399forth), are automatically extracted during the
1400:ref:`ref-tasks-unpack` task. For
1401another example that specifies these types of files, see the
1402"`Autotooled Package <#new-recipe-autotooled-package>`__" section.
1403
1404Another way of specifying source is from an SCM. For Git repositories,
1405you must specify :term:`SRCREV` and
1406you should specify :term:`PV` to include
1407the revision with :term:`SRCPV`. Here
1408is an example from the recipe
1409``meta/recipes-kernel/blktrace/blktrace_git.bb``:
1410::
1411
1412 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1413
1414 PR = "r6"
1415 PV = "1.0.5+git${SRCPV}"
1416
1417 SRC_URI = "git://git.kernel.dk/blktrace.git \
1418 file://ldflags.patch"
1419
1420If your ``SRC_URI`` statement includes URLs pointing to individual files
1421fetched from a remote server other than a version control system,
1422BitBake attempts to verify the files against checksums defined in your
1423recipe to ensure they have not been tampered with or otherwise modified
1424since the recipe was written. Two checksums are used:
1425``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1426
1427If your ``SRC_URI`` variable points to more than a single URL (excluding
1428SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1429each URL. For these cases, you provide a name for each URL as part of
1430the ``SRC_URI`` and then reference that name in the subsequent checksum
1431statements. Here is an example combining lines from the files
1432``git.inc`` and ``git_2.24.1.bb``:
1433::
1434
1435 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1436 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1437
1438 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1439 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1440 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1441 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1442
1443Proper values for ``md5`` and ``sha256`` checksums might be available
1444with other signatures on the download page for the upstream source (e.g.
1445``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1446OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1447you should verify all the signatures you find by hand.
1448
1449If no ``SRC_URI`` checksums are specified when you attempt to build the
1450recipe, or you provide an incorrect checksum, the build will produce an
1451error for each missing or incorrect checksum. As part of the error
1452message, the build system provides the checksum string corresponding to
1453the fetched file. Once you have the correct checksums, you can copy and
1454paste them into your recipe and then run the build again to continue.
1455
1456.. note::
1457
1458 As mentioned, if the upstream source provides signatures for
1459 verifying the downloaded source code, you should verify those
1460 manually before setting the checksum values in the recipe and
1461 continuing with the build.
1462
1463This final example is a bit more complicated and is from the
1464``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
1465example's ``SRC_URI`` statement identifies multiple files as the source
1466files for the recipe: a tarball, a patch file, a desktop file, and an
1467icon.
1468::
1469
1470 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1471 file://xwc.patch \
1472 file://rxvt.desktop \
1473 file://rxvt.png"
1474
1475When you specify local files using the ``file://`` URI protocol, the
1476build system fetches files from the local machine. The path is relative
1477to the :term:`FILESPATH` variable
1478and searches specific directories in a certain order:
1479``${``\ :term:`BP`\ ``}``,
1480``${``\ :term:`BPN`\ ``}``, and
1481``files``. The directories are assumed to be subdirectories of the
1482directory in which the recipe or append file resides. For another
1483example that specifies these types of files, see the "`Single .c File
1484Package (Hello
1485World!) <#new-recipe-single-c-file-package-hello-world>`__" section.
1486
1487The previous example also specifies a patch file. Patch files are files
1488whose names usually end in ``.patch`` or ``.diff`` but can end with
1489compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1490The build system automatically applies patches as described in the
1491"`Patching Code <#new-recipe-patching-code>`__" section.
1492
1493.. _new-recipe-unpacking-code:
1494
1495Unpacking Code
1496--------------
1497
1498During the build, the
1499:ref:`ref-tasks-unpack` task unpacks
1500the source with ``${``\ :term:`S`\ ``}``
1501pointing to where it is unpacked.
1502
1503If you are fetching your source files from an upstream source archived
1504tarball and the tarball's internal structure matches the common
1505convention of a top-level subdirectory named
1506``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
1507then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
1508fetch source from an archive that does not use this convention, or from
1509an SCM like Git or Subversion, your recipe needs to define ``S``.
1510
1511If processing your recipe using BitBake successfully unpacks the source
1512files, you need to be sure that the directory pointed to by ``${S}``
1513matches the structure of the source.
1514
1515.. _new-recipe-patching-code:
1516
1517Patching Code
1518-------------
1519
1520Sometimes it is necessary to patch code after it has been fetched. Any
1521files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
1522``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1523treated as patches. The
1524:ref:`ref-tasks-patch` task
1525automatically applies these patches.
1526
1527The build system should be able to apply patches with the "-p1" option
1528(i.e. one directory level in the path will be stripped off). If your
1529patch needs to have more directory levels stripped off, specify the
1530number of levels using the "striplevel" option in the ``SRC_URI`` entry
1531for the patch. Alternatively, if your patch needs to be applied in a
1532specific subdirectory that is not specified in the patch file, use the
1533"patchdir" option in the entry.
1534
1535As with all local files referenced in
1536:term:`SRC_URI` using ``file://``,
1537you should place patch files in a directory next to the recipe either
1538named the same as the base name of the recipe
1539(:term:`BP` and
1540:term:`BPN`) or "files".
1541
1542.. _new-recipe-licensing:
1543
1544Licensing
1545---------
1546
1547Your recipe needs to have both the
1548:term:`LICENSE` and
1549:term:`LIC_FILES_CHKSUM`
1550variables:
1551
1552- ``LICENSE``: This variable specifies the license for the software.
1553 If you do not know the license under which the software you are
1554 building is distributed, you should go to the source code and look
1555 for that information. Typical files containing this information
1556 include ``COPYING``, ``LICENSE``, and ``README`` files. You could
1557 also find the information near the top of a source file. For example,
1558 given a piece of software licensed under the GNU General Public
1559 License version 2, you would set ``LICENSE`` as follows:
1560 ::
1561
1562 LICENSE = "GPLv2"
1563
1564 The licenses you specify within ``LICENSE`` can have any name as long
1565 as you do not use spaces, since spaces are used as separators between
1566 license names. For standard licenses, use the names of the files in
1567 ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
1568 defined in ``meta/conf/licenses.conf``.
1569
1570- ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
1571 variable to make sure the license text has not changed. If it has,
1572 the build produces an error and it affords you the chance to figure
1573 it out and correct the problem.
1574
1575 You need to specify all applicable licensing files for the software.
1576 At the end of the configuration step, the build process will compare
1577 the checksums of the files to be sure the text has not changed. Any
1578 differences result in an error with the message containing the
1579 current checksum. For more explanation and examples of how to set the
1580 ``LIC_FILES_CHKSUM`` variable, see the
1581 ":ref:`dev-manual/dev-manual-common-tasks:tracking license changes`" section.
1582
1583 To determine the correct checksum string, you can list the
1584 appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
1585 md5 strings, attempt to build the software, and then note the
1586 resulting error messages that will report the correct md5 strings.
1587 See the "`Fetching Code <#new-recipe-fetching-code>`__" section for
1588 additional information.
1589
1590 Here is an example that assumes the software has a ``COPYING`` file:
1591 ::
1592
1593 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1594
1595 When you try to build the
1596 software, the build system will produce an error and give you the
1597 correct string that you can substitute into the recipe file for a
1598 subsequent build.
1599
1600.. _new-dependencies:
1601
1602Dependencies
1603------------
1604
1605Most software packages have a short list of other packages that they
1606require, which are called dependencies. These dependencies fall into two
1607main categories: build-time dependencies, which are required when the
1608software is built; and runtime dependencies, which are required to be
1609installed on the target in order for the software to run.
1610
1611Within a recipe, you specify build-time dependencies using the
1612:term:`DEPENDS` variable. Although
1613nuances exist, items specified in ``DEPENDS`` should be names of other
1614recipes. It is important that you specify all build-time dependencies
1615explicitly.
1616
1617Another consideration is that configure scripts might automatically
1618check for optional dependencies and enable corresponding functionality
1619if those dependencies are found. If you wish to make a recipe that is
1620more generally useful (e.g. publish the recipe in a layer for others to
1621use), instead of hard-disabling the functionality, you can use the
1622:term:`PACKAGECONFIG` variable to allow functionality and the
1623corresponding dependencies to be enabled and disabled easily by other
1624users of the recipe.
1625
1626Similar to build-time dependencies, you specify runtime dependencies
1627through a variable -
1628:term:`RDEPENDS`, which is
1629package-specific. All variables that are package-specific need to have
1630the name of the package added to the end as an override. Since the main
1631package for a recipe has the same name as the recipe, and the recipe's
1632name can be found through the
1633``${``\ :term:`PN`\ ``}`` variable, then
1634you specify the dependencies for the main package by setting
1635``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
1636would set ``RDEPENDS_${PN}-tools``, and so forth.
1637
1638Some runtime dependencies will be set automatically at packaging time.
1639These dependencies include any shared library dependencies (i.e. if a
1640package "example" contains "libexample" and another package "mypackage"
1641contains a binary that links to "libexample" then the OpenEmbedded build
1642system will automatically add a runtime dependency to "mypackage" on
1643"example"). See the
1644":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`"
1645section in the Yocto Project Overview and Concepts Manual for further
1646details.
1647
1648.. _new-recipe-configuring-the-recipe:
1649
1650Configuring the Recipe
1651----------------------
1652
1653Most software provides some means of setting build-time configuration
1654options before compilation. Typically, setting these options is
1655accomplished by running a configure script with options, or by modifying
1656a build configuration file.
1657
1658.. note::
1659
1660 As of Yocto Project Release 1.7, some of the core recipes that
1661 package binary configuration scripts now disable the scripts due to
1662 the scripts previously requiring error-prone path substitution. The
1663 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1664 robust. You can find a list of the ``*-config`` scripts that are disabled
1665 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1666 in the Yocto Project Reference Manual.
1667
1668A major part of build-time configuration is about checking for
1669build-time dependencies and possibly enabling optional functionality as
1670a result. You need to specify any build-time dependencies for the
1671software you are building in your recipe's
1672:term:`DEPENDS` value, in terms of
1673other recipes that satisfy those dependencies. You can often find
1674build-time or runtime dependencies described in the software's
1675documentation.
1676
1677The following list provides configuration items of note based on how
1678your software is built:
1679
1680- *Autotools:* If your source files have a ``configure.ac`` file, then
1681 your software is built using Autotools. If this is the case, you just
1682 need to worry about modifying the configuration.
1683
1684 When using Autotools, your recipe needs to inherit the
1685 :ref:`autotools <ref-classes-autotools>` class
1686 and your recipe does not have to contain a
1687 :ref:`ref-tasks-configure` task.
1688 However, you might still want to make some adjustments. For example,
1689 you can set
1690 :term:`EXTRA_OECONF` or
1691 :term:`PACKAGECONFIG_CONFARGS`
1692 to pass any needed configure options that are specific to the recipe.
1693
1694- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1695 your software is built using CMake. If this is the case, you just
1696 need to worry about modifying the configuration.
1697
1698 When you use CMake, your recipe needs to inherit the
1699 :ref:`cmake <ref-classes-cmake>` class and your
1700 recipe does not have to contain a
1701 :ref:`ref-tasks-configure` task.
1702 You can make some adjustments by setting
1703 :term:`EXTRA_OECMAKE` to
1704 pass any needed configure options that are specific to the recipe.
1705
1706 .. note::
1707
1708 If you need to install one or more custom CMake toolchain files
1709 that are supplied by the application you are building, install the
1710 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
1711
1712- *Other:* If your source files do not have a ``configure.ac`` or
1713 ``CMakeLists.txt`` file, then your software is built using some
1714 method other than Autotools or CMake. If this is the case, you
1715 normally need to provide a
1716 :ref:`ref-tasks-configure` task
1717 in your recipe unless, of course, there is nothing to configure.
1718
1719 Even if your software is not being built by Autotools or CMake, you
1720 still might not need to deal with any configuration issues. You need
1721 to determine if configuration is even a required step. You might need
1722 to modify a Makefile or some configuration file used for the build to
1723 specify necessary build options. Or, perhaps you might need to run a
1724 provided, custom configure script with the appropriate options.
1725
1726 For the case involving a custom configure script, you would run
1727 ``./configure --help`` and look for the options you need to set.
1728
1729Once configuration succeeds, it is always good practice to look at the
1730``log.do_configure`` file to ensure that the appropriate options have
1731been enabled and no additional build-time dependencies need to be added
1732to ``DEPENDS``. For example, if the configure script reports that it
1733found something not mentioned in ``DEPENDS``, or that it did not find
1734something that it needed for some desired optional functionality, then
1735you would need to add those to ``DEPENDS``. Looking at the log might
1736also reveal items being checked for, enabled, or both that you do not
1737want, or items not being found that are in ``DEPENDS``, in which case
1738you would need to look at passing extra options to the configure script
1739as needed. For reference information on configure options specific to
1740the software you are building, you can consult the output of the
1741``./configure --help`` command within ``${S}`` or consult the software's
1742upstream documentation.
1743
1744.. _new-recipe-using-headers-to-interface-with-devices:
1745
1746Using Headers to Interface with Devices
1747---------------------------------------
1748
1749If your recipe builds an application that needs to communicate with some
1750device or needs an API into a custom kernel, you will need to provide
1751appropriate header files. Under no circumstances should you ever modify
1752the existing
1753``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1754These headers are used to build ``libc`` and must not be compromised
1755with custom or machine-specific header information. If you customize
1756``libc`` through modified headers all other applications that use
1757``libc`` thus become affected.
1758
1759.. note::
1760
1761 Never copy and customize the ``libc`` header file (i.e.
1762 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
1763
1764The correct way to interface to a device or custom kernel is to use a
1765separate package that provides the additional headers for the driver or
1766other unique interfaces. When doing so, your application also becomes
1767responsible for creating a dependency on that specific provider.
1768
1769Consider the following:
1770
1771- Never modify ``linux-libc-headers.inc``. Consider that file to be
1772 part of the ``libc`` system, and not something you use to access the
1773 kernel directly. You should access ``libc`` through specific ``libc``
1774 calls.
1775
1776- Applications that must talk directly to devices should either provide
1777 necessary headers themselves, or establish a dependency on a special
1778 headers package that is specific to that driver.
1779
1780For example, suppose you want to modify an existing header that adds I/O
1781control or network support. If the modifications are used by a small
1782number programs, providing a unique version of a header is easy and has
1783little impact. When doing so, bear in mind the guidelines in the
1784previous list.
1785
1786.. note::
1787
1788 If for some reason your changes need to modify the behavior of the ``libc``,
1789 and subsequently all other applications on the system, use a ``.bbappend``
1790 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1791 make the changes machine specific.
1792
1793Consider a case where your kernel is older and you need an older
1794``libc`` ABI. The headers installed by your recipe should still be a
1795standard mainline kernel, not your own custom one.
1796
1797When you use custom kernel headers you need to get them from
1798:term:`STAGING_KERNEL_DIR`,
1799which is the directory with kernel headers that are required to build
1800out-of-tree modules. Your recipe will also need the following:
1801::
1802
1803 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1804
1805.. _new-recipe-compilation:
1806
1807Compilation
1808-----------
1809
1810During a build, the ``do_compile`` task happens after source is fetched,
1811unpacked, and configured. If the recipe passes through ``do_compile``
1812successfully, nothing needs to be done.
1813
1814However, if the compile step fails, you need to diagnose the failure.
1815Here are some common issues that cause failures.
1816
1817.. note::
1818
1819 For cases where improper paths are detected for configuration files
1820 or for when libraries/headers cannot be found, be sure you are using
1821 the more robust ``pkg-config``. See the note in section
1822 ":ref:`new-recipe-configuring-the-recipe`" for additional information.
1823
1824- *Parallel build failures:* These failures manifest themselves as
1825 intermittent errors, or errors reporting that a file or directory
1826 that should be created by some other part of the build process could
1827 not be found. This type of failure can occur even if, upon
1828 inspection, the file or directory does exist after the build has
1829 failed, because that part of the build process happened in the wrong
1830 order.
1831
1832 To fix the problem, you need to either satisfy the missing dependency
1833 in the Makefile or whatever script produced the Makefile, or (as a
1834 workaround) set :term:`PARALLEL_MAKE` to an empty string:
1835 ::
1836
1837 PARALLEL_MAKE = ""
1838
1839 For information on parallel Makefile issues, see the "`Debugging
1840 Parallel Make Races <#debugging-parallel-make-races>`__" section.
1841
1842- *Improper host path usage:* This failure applies to recipes building
1843 for the target or ``nativesdk`` only. The failure occurs when the
1844 compilation process uses improper headers, libraries, or other files
1845 from the host system when cross-compiling for the target.
1846
1847 To fix the problem, examine the ``log.do_compile`` file to identify
1848 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1849 so forth) and then either add configure options, apply a patch, or do
1850 both.
1851
1852- *Failure to find required libraries/headers:* If a build-time
1853 dependency is missing because it has not been declared in
1854 :term:`DEPENDS`, or because the
1855 dependency exists but the path used by the build process to find the
1856 file is incorrect and the configure step did not detect it, the
1857 compilation process could fail. For either of these failures, the
1858 compilation process notes that files could not be found. In these
1859 cases, you need to go back and add additional options to the
1860 configure script as well as possibly add additional build-time
1861 dependencies to ``DEPENDS``.
1862
1863 Occasionally, it is necessary to apply a patch to the source to
1864 ensure the correct paths are used. If you need to specify paths to
1865 find files staged into the sysroot from other recipes, use the
1866 variables that the OpenEmbedded build system provides (e.g.
1867 ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
1868 forth).
1869
1870.. _new-recipe-installing:
1871
1872Installing
1873----------
1874
1875During ``do_install``, the task copies the built files along with their
1876hierarchy to locations that would mirror their locations on the target
1877device. The installation process copies files from the
1878``${``\ :term:`S`\ ``}``,
1879``${``\ :term:`B`\ ``}``, and
1880``${``\ :term:`WORKDIR`\ ``}``
1881directories to the ``${``\ :term:`D`\ ``}``
1882directory to create the structure as it should appear on the target
1883system.
1884
1885How your software is built affects what you must do to be sure your
1886software is installed correctly. The following list describes what you
1887must do for installation depending on the type of build system used by
1888the software being built:
1889
1890- *Autotools and CMake:* If the software your recipe is building uses
1891 Autotools or CMake, the OpenEmbedded build system understands how to
1892 install the software. Consequently, you do not have to have a
1893 ``do_install`` task as part of your recipe. You just need to make
1894 sure the install portion of the build completes with no issues.
1895 However, if you wish to install additional files not already being
1896 installed by ``make install``, you should do this using a
1897 ``do_install_append`` function using the install command as described
1898 in the "Manual" bulleted item later in this list.
1899
1900- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
1901 function in your recipe. The function should call
1902 ``oe_runmake install`` and will likely need to pass in the
1903 destination directory as well. How you pass that path is dependent on
1904 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1905 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1906
1907 For an example recipe using ``make install``, see the
1908 "`Makefile-Based Package <#new-recipe-makefile-based-package>`__"
1909 section.
1910
1911- *Manual:* You need to define a ``do_install`` function in your
1912 recipe. The function must first use ``install -d`` to create the
1913 directories under
1914 ``${``\ :term:`D`\ ``}``. Once the
1915 directories exist, your function can use ``install`` to manually
1916 install the built software into the directories.
1917
1918 You can find more information on ``install`` at
1919 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
1920
1921For the scenarios that do not use Autotools or CMake, you need to track
1922the installation and diagnose and fix any issues until everything
1923installs correctly. You need to look in the default location of
1924``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1925installed correctly.
1926
1927.. note::
1928
1929 - During the installation process, you might need to modify some of
1930 the installed files to suit the target layout. For example, you
1931 might need to replace hard-coded paths in an initscript with
1932 values of variables provided by the build system, such as
1933 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1934 modifications during ``do_install``, be sure to modify the
1935 destination file after copying rather than before copying.
1936 Modifying after copying ensures that the build system can
1937 re-execute ``do_install`` if needed.
1938
1939 - ``oe_runmake install``, which can be run directly or can be run
1940 indirectly by the
1941 :ref:`autotools <ref-classes-autotools>` and
1942 :ref:`cmake <ref-classes-cmake>` classes,
1943 runs ``make install`` in parallel. Sometimes, a Makefile can have
1944 missing dependencies between targets that can result in race
1945 conditions. If you experience intermittent failures during
1946 ``do_install``, you might be able to work around them by disabling
1947 parallel Makefile installs by adding the following to the recipe:
1948 ::
1949
1950 PARALLEL_MAKEINST = ""
1951
1952 See :term:`PARALLEL_MAKEINST` for additional information.
1953
1954 - If you need to install one or more custom CMake toolchain files
1955 that are supplied by the application you are building, install the
1956 files to ``${D}${datadir}/cmake/Modules`` during
1957 :ref:`ref-tasks-install`.
1958
1959.. _new-recipe-enabling-system-services:
1960
1961Enabling System Services
1962------------------------
1963
1964If you want to install a service, which is a process that usually starts
1965on boot and runs in the background, then you must include some
1966additional definitions in your recipe.
1967
1968If you are adding services and the service initialization script or the
1969service file itself is not installed, you must provide for that
1970installation in your recipe using a ``do_install_append`` function. If
1971your recipe already has a ``do_install`` function, update the function
1972near its end rather than adding an additional ``do_install_append``
1973function.
1974
1975When you create the installation for your services, you need to
1976accomplish what is normally done by ``make install``. In other words,
1977make sure your installation arranges the output similar to how it is
1978arranged on the target system.
1979
1980The OpenEmbedded build system provides support for starting services two
1981different ways:
1982
1983- *SysVinit:* SysVinit is a system and service manager that manages the
1984 init system used to control the very basic functions of your system.
1985 The init program is the first program started by the Linux kernel
1986 when the system boots. Init then controls the startup, running and
1987 shutdown of all other programs.
1988
1989 To enable a service using SysVinit, your recipe needs to inherit the
1990 :ref:`update-rc.d <ref-classes-update-rc.d>`
1991 class. The class helps facilitate safely installing the package on
1992 the target.
1993
1994 You will need to set the
1995 :term:`INITSCRIPT_PACKAGES`,
1996 :term:`INITSCRIPT_NAME`,
1997 and
1998 :term:`INITSCRIPT_PARAMS`
1999 variables within your recipe.
2000
2001- *systemd:* System Management Daemon (systemd) was designed to replace
2002 SysVinit and to provide enhanced management of services. For more
2003 information on systemd, see the systemd homepage at
2004 https://freedesktop.org/wiki/Software/systemd/.
2005
2006 To enable a service using systemd, your recipe needs to inherit the
2007 :ref:`systemd <ref-classes-systemd>` class. See
2008 the ``systemd.bbclass`` file located in your :term:`Source Directory`
2009 section for
2010 more information.
2011
2012.. _new-recipe-packaging:
2013
2014Packaging
2015---------
2016
2017Successful packaging is a combination of automated processes performed
2018by the OpenEmbedded build system and some specific steps you need to
2019take. The following list describes the process:
2020
2021- *Splitting Files*: The ``do_package`` task splits the files produced
2022 by the recipe into logical components. Even software that produces a
2023 single binary might still have debug symbols, documentation, and
2024 other logical components that should be split out. The ``do_package``
2025 task ensures that files are split up and packaged correctly.
2026
2027- *Running QA Checks*: The
2028 :ref:`insane <ref-classes-insane>` class adds a
2029 step to the package generation process so that output quality
2030 assurance checks are generated by the OpenEmbedded build system. This
2031 step performs a range of checks to be sure the build's output is free
2032 of common problems that show up during runtime. For information on
2033 these checks, see the
2034 :ref:`insane <ref-classes-insane>` class and
2035 the ":ref:`ref-manual/ref-qa-checks:qa error and warning messages`"
2036 chapter in the Yocto Project Reference Manual.
2037
2038- *Hand-Checking Your Packages*: After you build your software, you
2039 need to be sure your packages are correct. Examine the
2040 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
2041 directory and make sure files are where you expect them to be. If you
2042 discover problems, you can set
2043 :term:`PACKAGES`,
2044 :term:`FILES`,
2045 ``do_install(_append)``, and so forth as needed.
2046
2047- *Splitting an Application into Multiple Packages*: If you need to
2048 split an application into several packages, see the "`Splitting an
2049 Application into Multiple
2050 Packages <#splitting-an-application-into-multiple-packages>`__"
2051 section for an example.
2052
2053- *Installing a Post-Installation Script*: For an example showing how
2054 to install a post-installation script, see the "`Post-Installation
2055 Scripts <#new-recipe-post-installation-scripts>`__" section.
2056
2057- *Marking Package Architecture*: Depending on what your recipe is
2058 building and how it is configured, it might be important to mark the
2059 packages produced as being specific to a particular machine, or to
2060 mark them as not being specific to a particular machine or
2061 architecture at all.
2062
2063 By default, packages apply to any machine with the same architecture
2064 as the target machine. When a recipe produces packages that are
2065 machine-specific (e.g. the
2066 :term:`MACHINE` value is passed
2067 into the configure script or a patch is applied only for a particular
2068 machine), you should mark them as such by adding the following to the
2069 recipe:
2070 ::
2071
2072 PACKAGE_ARCH = "${MACHINE_ARCH}"
2073
2074 On the other hand, if the recipe produces packages that do not
2075 contain anything specific to the target machine or architecture at
2076 all (e.g. recipes that simply package script files or configuration
2077 files), you should use the
2078 :ref:`allarch <ref-classes-allarch>` class to
2079 do this for you by adding this to your recipe:
2080 ::
2081
2082 inherit allarch
2083
2084 Ensuring that the package architecture is correct is not critical
2085 while you are doing the first few builds of your recipe. However, it
2086 is important in order to ensure that your recipe rebuilds (or does
2087 not rebuild) appropriately in response to changes in configuration,
2088 and to ensure that you get the appropriate packages installed on the
2089 target machine, particularly if you run separate builds for more than
2090 one target machine.
2091
2092.. _new-sharing-files-between-recipes:
2093
2094Sharing Files Between Recipes
2095-----------------------------
2096
2097Recipes often need to use files provided by other recipes on the build
2098host. For example, an application linking to a common library needs
2099access to the library itself and its associated headers. The way this
2100access is accomplished is by populating a sysroot with files. Each
2101recipe has two sysroots in its work directory, one for target files
2102(``recipe-sysroot``) and one for files that are native to the build host
2103(``recipe-sysroot-native``).
2104
2105.. note::
2106
2107 You could find the term "staging" used within the Yocto project
2108 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
2109 variable).
2110
2111Recipes should never populate the sysroot directly (i.e. write files
2112into sysroot). Instead, files should be installed into standard
2113locations during the
2114:ref:`ref-tasks-install` task within
2115the ``${``\ :term:`D`\ ``}`` directory. The
2116reason for this limitation is that almost all files that populate the
2117sysroot are cataloged in manifests in order to ensure the files can be
2118removed later when a recipe is either modified or removed. Thus, the
2119sysroot is able to remain free from stale files.
2120
2121A subset of the files installed by the
2122:ref:`ref-tasks-install` task are
2123used by the
2124:ref:`ref-tasks-populate_sysroot`
2125task as defined by the the
2126:term:`SYSROOT_DIRS` variable to
2127automatically populate the sysroot. It is possible to modify the list of
2128directories that populate the sysroot. The following example shows how
2129you could add the ``/opt`` directory to the list of directories within a
2130recipe:
2131::
2132
2133 SYSROOT_DIRS += "/opt"
2134
2135For a more complete description of the
2136:ref:`ref-tasks-populate_sysroot`
2137task and its associated functions, see the
2138:ref:`staging <ref-classes-staging>` class.
2139
2140.. _metadata-virtual-providers:
2141
2142Using Virtual Providers
2143-----------------------
2144
2145Prior to a build, if you know that several different recipes provide the
2146same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2147as a placeholder for the actual provider. The actual provider is
2148determined at build-time.
2149
2150A common scenario where a virtual provider is used would be for the
2151kernel recipe. Suppose you have three kernel recipes whose
2152:term:`PN` values map to ``kernel-big``,
2153``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2154in some way uses a :term:`PROVIDES`
2155statement that essentially identifies itself as being able to provide
2156``virtual/kernel``. Here is one way through the
2157:ref:`kernel <ref-classes-kernel>` class:
2158::
2159
2160 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
2161
2162Any recipe that inherits the ``kernel`` class is
2163going to utilize a ``PROVIDES`` statement that identifies that recipe as
2164being able to provide the ``virtual/kernel`` item.
2165
2166Now comes the time to actually build an image and you need a kernel
2167recipe, but which one? You can configure your build to call out the
2168kernel recipe you want by using the
2169:term:`PREFERRED_PROVIDER`
2170variable. As an example, consider the
2171`x86-base.inc <https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc>`_
2172include file, which is a machine (i.e.
2173:term:`MACHINE`) configuration file.
2174This include file is the reason all x86-based machines use the
2175``linux-yocto`` kernel. Here are the relevant lines from the include
2176file:
2177::
2178
2179 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2180 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2181
2182When you use a virtual provider, you do not have to "hard code" a recipe
2183name as a build dependency. You can use the
2184:term:`DEPENDS` variable to state the
2185build is dependent on ``virtual/kernel`` for example:
2186::
2187
2188 DEPENDS = "virtual/kernel"
2189
2190During the build, the OpenEmbedded build system picks
2191the correct recipe needed for the ``virtual/kernel`` dependency based on
2192the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
2193mentioned at the beginning of this section, configure your build as
2194follows:
2195::
2196
2197 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
2198
2199.. note::
2200
2201 Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
2202 selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
2203 recipes from building is usually the desired behavior since this mechanism's
2204 purpose is to select between mutually exclusive alternative providers.
2205
2206The following lists specific examples of virtual providers:
2207
2208- ``virtual/kernel``: Provides the name of the kernel recipe to use
2209 when building a kernel image.
2210
2211- ``virtual/bootloader``: Provides the name of the bootloader to use
2212 when building an image.
2213
2214- ``virtual/libgbm``: Provides ``gbm.pc``.
2215
2216- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2217
2218- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2219
2220- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2221
2222- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2223
2224.. note::
2225
2226 Virtual providers only apply to build time dependencies specified with
2227 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2228 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2229
2230Properly Versioning Pre-Release Recipes
2231---------------------------------------
2232
2233Sometimes the name of a recipe can lead to versioning problems when the
2234recipe is upgraded to a final release. For example, consider the
2235``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
2236the "`Storing and Naming the
2237Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This
2238recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
2239released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2240change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2241build system and package managers, so the resulting packages will not
2242correctly trigger an upgrade.
2243
2244In order to ensure the versions compare properly, the recommended
2245convention is to set :term:`PV` within the
2246recipe to "previous_version+current_version". You can use an additional
2247variable so that you can use the current version elsewhere. Here is an
2248example:
2249::
2250
2251 REALPV = "0.8.16-rc1"
2252 PV = "0.8.15+${REALPV}"
2253
2254.. _new-recipe-post-installation-scripts:
2255
2256Post-Installation Scripts
2257-------------------------
2258
2259Post-installation scripts run immediately after installing a package on
2260the target or during image creation when a package is included in an
2261image. To add a post-installation script to a package, add a
2262``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
2263(``.bb``) and replace `PACKAGENAME` with the name of the package you want
2264to attach to the ``postinst`` script. To apply the post-installation
2265script to the main package for the recipe, which is usually what is
2266required, specify
2267``${``\ :term:`PN`\ ``}`` in place of
2268PACKAGENAME.
2269
2270A post-installation function has the following structure:
2271::
2272
2273 pkg_postinst_PACKAGENAME() {
2274 # Commands to carry out
2275 }
2276
2277The script defined in the post-installation function is called when the
2278root filesystem is created. If the script succeeds, the package is
2279marked as installed.
2280
2281.. note::
2282
2283 Any RPM post-installation script that runs on the target should
2284 return a 0 exit code. RPM does not allow non-zero exit codes for
2285 these scripts, and the RPM package manager will cause the package to
2286 fail installation on the target.
2287
2288Sometimes it is necessary for the execution of a post-installation
2289script to be delayed until the first boot. For example, the script might
2290need to be executed on the device itself. To delay script execution
2291until boot time, you must explicitly mark post installs to defer to the
2292target. You can use ``pkg_postinst_ontarget()`` or call
2293``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2294failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2295error during the
2296:ref:`ref-tasks-rootfs` task.
2297
2298If you have recipes that use ``pkg_postinst`` function and they require
2299the use of non-standard native tools that have dependencies during
2300rootfs construction, you need to use the
2301:term:`PACKAGE_WRITE_DEPS`
2302variable in your recipe to list these tools. If you do not use this
2303variable, the tools might be missing and execution of the
2304post-installation script is deferred until first boot. Deferring the
2305script to first boot is undesirable and for read-only rootfs impossible.
2306
2307.. note::
2308
2309 Equivalent support for pre-install, pre-uninstall, and post-uninstall
2310 scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
2311 respectively. These scrips work in exactly the same way as does
2312 ``pkg_postinst`` with the exception that they run at different times. Also,
2313 because of when they run, they are not applicable to being run at image
2314 creation time like ``pkg_postinst``.
2315
2316.. _new-recipe-testing:
2317
2318Testing
2319-------
2320
2321The final step for completing your recipe is to be sure that the
2322software you built runs correctly. To accomplish runtime testing, add
2323the build's output packages to your image and test them on the target.
2324
2325For information on how to customize your image by adding specific
2326packages, see the "`Customizing
2327Images <#usingpoky-extend-customimage>`__" section.
2328
2329.. _new-recipe-testing-examples:
2330
2331Examples
2332--------
2333
2334To help summarize how to write a recipe, this section provides some
2335examples given various scenarios:
2336
2337- Recipes that use local files
2338
2339- Using an Autotooled package
2340
2341- Using a Makefile-based package
2342
2343- Splitting an application into multiple packages
2344
2345- Adding binaries to an image
2346
2347.. _new-recipe-single-c-file-package-hello-world:
2348
2349Single .c File Package (Hello World!)
2350~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2351
2352Building an application from a single file that is stored locally (e.g.
2353under ``files``) requires a recipe that has the file listed in the
2354``SRC_URI`` variable. Additionally, you need to manually write the
2355``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
2356directory containing the source code, which is set to
2357:term:`WORKDIR` in this case - the
2358directory BitBake uses for the build.
2359::
2360
2361 SUMMARY = "Simple helloworld application"
2362 SECTION = "examples"
2363 LICENSE = "MIT"
2364 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2365
2366 SRC_URI = "file://helloworld.c"
2367
2368 S = "${WORKDIR}"
2369
2370 do_compile() {
2371 ${CC} helloworld.c -o helloworld
2372 }
2373
2374 do_install() {
2375 install -d ${D}${bindir}
2376 install -m 0755 helloworld ${D}${bindir}
2377 }
2378
2379By default, the ``helloworld``, ``helloworld-dbg``, and
2380``helloworld-dev`` packages are built. For information on how to
2381customize the packaging process, see the "`Splitting an Application into
2382Multiple Packages <#splitting-an-application-into-multiple-packages>`__"
2383section.
2384
2385.. _new-recipe-autotooled-package:
2386
2387Autotooled Package
2388~~~~~~~~~~~~~~~~~~
2389
2390Applications that use Autotools such as ``autoconf`` and ``automake``
2391require a recipe that has a source archive listed in ``SRC_URI`` and
2392also inherit the
2393:ref:`autotools <ref-classes-autotools>` class,
2394which contains the definitions of all the steps needed to build an
2395Autotool-based application. The result of the build is automatically
2396packaged. And, if the application uses NLS for localization, packages
2397with local information are generated (one package per language).
2398Following is one example: (``hello_2.3.bb``)
2399::
2400
2401 SUMMARY = "GNU Helloworld application"
2402 SECTION = "examples"
2403 LICENSE = "GPLv2+"
2404 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2405
2406 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2407
2408 inherit autotools gettext
2409
2410The variable ``LIC_FILES_CHKSUM`` is used to track source license
2411changes as described in the
2412":ref:`dev-manual/dev-manual-common-tasks:tracking license changes`" section in
2413the Yocto Project Overview and Concepts Manual. You can quickly create
2414Autotool-based recipes in a manner similar to the previous example.
2415
2416.. _new-recipe-makefile-based-package:
2417
2418Makefile-Based Package
2419~~~~~~~~~~~~~~~~~~~~~~
2420
2421Applications that use GNU ``make`` also require a recipe that has the
2422source archive listed in ``SRC_URI``. You do not need to add a
2423``do_compile`` step since by default BitBake starts the ``make`` command
2424to compile the application. If you need additional ``make`` options, you
2425should store them in the
2426:term:`EXTRA_OEMAKE` or
2427:term:`PACKAGECONFIG_CONFARGS`
2428variables. BitBake passes these options into the GNU ``make``
2429invocation. Note that a ``do_install`` task is still required.
2430Otherwise, BitBake runs an empty ``do_install`` task by default.
2431
2432Some applications might require extra parameters to be passed to the
2433compiler. For example, the application might need an additional header
2434path. You can accomplish this by adding to the ``CFLAGS`` variable. The
2435following example shows this:
2436::
2437
2438 CFLAGS_prepend = "-I ${S}/include "
2439
2440In the following example, ``mtd-utils`` is a makefile-based package:
2441::
2442
2443 SUMMARY = "Tools for managing memory technology devices"
2444 SECTION = "base"
2445 DEPENDS = "zlib lzo e2fsprogs util-linux"
2446 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
2447 LICENSE = "GPLv2+"
2448 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
2449 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
2450
2451 # Use the latest version at 26 Oct, 2013
2452 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
2453 SRC_URI = "git://git.infradead.org/mtd-utils.git \
2454 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
2455 "
2456
2457 PV = "1.5.1+git${SRCPV}"
2458
2459 S = "${WORKDIR}/git"
2460
2461 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
2462
2463 do_install () {
2464 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
2465 }
2466
2467 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
2468
2469 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
2470 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
2471 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
2472
2473 PARALLEL_MAKE = ""
2474
2475 BBCLASSEXTEND = "native"
2476
2477Splitting an Application into Multiple Packages
2478~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2479
2480You can use the variables ``PACKAGES`` and ``FILES`` to split an
2481application into multiple packages.
2482
2483Following is an example that uses the ``libxpm`` recipe. By default,
2484this recipe generates a single package that contains the library along
2485with a few binaries. You can modify the recipe to split the binaries
2486into separate packages:
2487::
2488
2489 require xorg-lib-common.inc
2490
2491 SUMMARY = "Xpm: X Pixmap extension library"
2492 LICENSE = "BSD"
2493 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2494 DEPENDS += "libxext libsm libxt"
2495 PE = "1"
2496
2497 XORG_PN = "libXpm"
2498
2499 PACKAGES =+ "sxpm cxpm"
2500 FILES_cxpm = "${bindir}/cxpm"
2501 FILES_sxpm = "${bindir}/sxpm"
2502
2503In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2504binaries in separate packages. Since ``bindir`` would be packaged into
2505the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
2506so additional package names are added to the start of list. This results
2507in the extra ``FILES_*`` variables then containing information that
2508define which files and directories go into which packages. Files
2509included by earlier packages are skipped by latter packages. Thus, the
2510main ``PN`` package does not include the above listed files.
2511
2512Packaging Externally Produced Binaries
2513~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2514
2515Sometimes, you need to add pre-compiled binaries to an image. For
2516example, suppose that binaries for proprietary code exist, which are
2517created by a particular division of a company. Your part of the company
2518needs to use those binaries as part of an image that you are building
2519using the OpenEmbedded build system. Since you only have the binaries
2520and not the source code, you cannot use a typical recipe that expects to
2521fetch the source specified in
2522:term:`SRC_URI` and then compile it.
2523
2524One method is to package the binaries and then install them as part of
2525the image. Generally, it is not a good idea to package binaries since,
2526among other things, it can hinder the ability to reproduce builds and
2527could lead to compatibility problems with ABI in the future. However,
2528sometimes you have no choice.
2529
2530The easiest solution is to create a recipe that uses the
2531:ref:`bin_package <ref-classes-bin-package>` class
2532and to be sure that you are using default locations for build artifacts.
2533In most cases, the ``bin_package`` class handles "skipping" the
2534configure and compile steps as well as sets things up to grab packages
2535from the appropriate area. In particular, this class sets ``noexec`` on
2536both the :ref:`ref-tasks-configure`
2537and :ref:`ref-tasks-compile` tasks,
2538sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
2539:ref:`ref-tasks-install` task, which
2540effectively copies all files from ``${S}`` to ``${D}``. The
2541``bin_package`` class works well when the files extracted into ``${S}``
2542are already laid out in the way they should be laid out on the target.
2543For more information on these variables, see the
2544:term:`FILES`,
2545:term:`PN`,
2546:term:`S`, and
2547:term:`D` variables in the Yocto Project
2548Reference Manual's variable glossary.
2549
2550.. note::
2551
2552 - Using :term:`DEPENDS` is a good
2553 idea even for components distributed in binary form, and is often
2554 necessary for shared libraries. For a shared library, listing the
2555 library dependencies in ``DEPENDS`` makes sure that the libraries
2556 are available in the staging sysroot when other recipes link
2557 against the library, which might be necessary for successful
2558 linking.
2559
2560 - Using ``DEPENDS`` also allows runtime dependencies between
2561 packages to be added automatically. See the
2562 ":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`"
2563 section in the Yocto Project Overview and Concepts Manual for more
2564 information.
2565
2566If you cannot use the ``bin_package`` class, you need to be sure you are
2567doing the following:
2568
2569- Create a recipe where the
2570 :ref:`ref-tasks-configure` and
2571 :ref:`ref-tasks-compile` tasks do
2572 nothing: It is usually sufficient to just not define these tasks in
2573 the recipe, because the default implementations do nothing unless a
2574 Makefile is found in
2575 ``${``\ :term:`S`\ ``}``.
2576
2577 If ``${S}`` might contain a Makefile, or if you inherit some class
2578 that replaces ``do_configure`` and ``do_compile`` with custom
2579 versions, then you can use the
2580 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
2581 flag to turn the tasks into no-ops, as follows:
2582 ::
2583
2584 do_configure[noexec] = "1"
2585 do_compile[noexec] = "1"
2586
2587 Unlike
2588 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2589 using the flag preserves the dependency chain from the
2590 :ref:`ref-tasks-fetch`,
2591 :ref:`ref-tasks-unpack`, and
2592 :ref:`ref-tasks-patch` tasks to the
2593 :ref:`ref-tasks-install` task.
2594
2595- Make sure your ``do_install`` task installs the binaries
2596 appropriately.
2597
2598- Ensure that you set up :term:`FILES`
2599 (usually
2600 ``FILES_${``\ :term:`PN`\ ``}``) to
2601 point to the files you have installed, which of course depends on
2602 where you have installed them and whether those files are in
2603 different locations than the defaults.
2604
2605.. note::
2606
2607 If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
2608 which it is by default), prelink will change the binaries in the generated images
2609 and this often catches people out. Remove that class to ensure binaries are
2610 preserved exactly if that is necessary.
2611
2612Following Recipe Style Guidelines
2613---------------------------------
2614
2615When writing recipes, it is good to conform to existing style
2616guidelines. The :oe_home:`OpenEmbedded Styleguide </wiki/Styleguide>` wiki page
2617provides rough guidelines for preferred recipe style.
2618
2619It is common for existing recipes to deviate a bit from this style.
2620However, aiming for at least a consistent style is a good idea. Some
2621practices, such as omitting spaces around ``=`` operators in assignments
2622or ordering recipe components in an erratic way, are widely seen as poor
2623style.
2624
2625Recipe Syntax
2626-------------
2627
2628Understanding recipe file syntax is important for writing recipes. The
2629following list overviews the basic items that make up a BitBake recipe
2630file. For more complete BitBake syntax descriptions, see the
2631":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
2632chapter of the BitBake User Manual.
2633
2634- *Variable Assignments and Manipulations:* Variable assignments allow
2635 a value to be assigned to a variable. The assignment can be static
2636 text or might include the contents of other variables. In addition to
2637 the assignment, appending and prepending operations are also
2638 supported.
2639
2640 The following example shows some of the ways you can use variables in
2641 recipes:
2642 ::
2643
2644 S = "${WORKDIR}/postfix-${PV}"
2645 CFLAGS += "-DNO_ASM"
2646 SRC_URI_append = " file://fixup.patch"
2647
2648- *Functions:* Functions provide a series of actions to be performed.
2649 You usually use functions to override the default implementation of a
2650 task function or to complement a default function (i.e. append or
2651 prepend to an existing function). Standard functions use ``sh`` shell
2652 syntax, although access to OpenEmbedded variables and internal
2653 methods are also available.
2654
2655 The following is an example function from the ``sed`` recipe:
2656 ::
2657
2658 do_install () {
2659 autotools_do_install
2660 install -d ${D}${base_bindir}
2661 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2662 rmdir ${D}${bindir}/
2663 }
2664
2665 It is
2666 also possible to implement new functions that are called between
2667 existing tasks as long as the new functions are not replacing or
2668 complementing the default functions. You can implement functions in
2669 Python instead of shell. Both of these options are not seen in the
2670 majority of recipes.
2671
2672- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2673 to include common functions (``inherit``), load parts of a recipe
2674 from other files (``include`` and ``require``) and export variables
2675 to the environment (``export``).
2676
2677 The following example shows the use of some of these keywords:
2678 ::
2679
2680 export POSTCONF = "${STAGING_BINDIR}/postconf"
2681 inherit autoconf
2682 require otherfile.inc
2683
2684- *Comments (#):* Any lines that begin with the hash character (``#``)
2685 are treated as comment lines and are ignored:
2686 ::
2687
2688 # This is a comment
2689
2690This next list summarizes the most important and most commonly used
2691parts of the recipe syntax. For more information on these parts of the
2692syntax, you can reference the
2693:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
2694in the BitBake User Manual.
2695
2696- *Line Continuation (\\):* Use the backward slash (``\``) character to
2697 split a statement over multiple lines. Place the slash character at
2698 the end of the line that is to be continued on the next line:
2699 ::
2700
2701 VAR = "A really long \
2702 line"
2703
2704 .. note::
2705
2706 You cannot have any characters including spaces or tabs after the
2707 slash character.
2708
2709- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
2710 access the contents of a variable:
2711 ::
2712
2713 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2714
2715 .. note::
2716
2717 It is important to understand that the value of a variable
2718 expressed in this form does not get substituted automatically. The
2719 expansion of these expressions happens on-demand later (e.g.
2720 usually when a function that makes reference to the variable
2721 executes). This behavior ensures that the values are most
2722 appropriate for the context in which they are finally used. On the
2723 rare occasion that you do need the variable expression to be
2724 expanded immediately, you can use the
2725 :=
2726 operator instead of
2727 =
2728 when you make the assignment, but this is not generally needed.
2729
2730- *Quote All Assignments ("value"):* Use double quotes around values in
2731 all variable assignments (e.g. ``"value"``). Following is an example:
2732 ::
2733
2734 VAR1 = "${OTHERVAR}"
2735 VAR2 = "The version is ${PV}"
2736
2737- *Conditional Assignment (?=):* Conditional assignment is used to
2738 assign a value to a variable, but only when the variable is currently
2739 unset. Use the question mark followed by the equal sign (``?=``) to
2740 make a "soft" assignment used for conditional assignment. Typically,
2741 "soft" assignments are used in the ``local.conf`` file for variables
2742 that are allowed to come through from the external environment.
2743
2744 Here is an example where ``VAR1`` is set to "New value" if it is
2745 currently empty. However, if ``VAR1`` has already been set, it
2746 remains unchanged:
2747 ::
2748
2749 VAR1 ?= "New value"
2750
2751 In this next example, ``VAR1`` is left with the value "Original value":
2752 ::
2753
2754 VAR1 = "Original value"
2755 VAR1 ?= "New value"
2756
2757- *Appending (+=):* Use the plus character followed by the equals sign
2758 (``+=``) to append values to existing variables.
2759
2760 .. note::
2761
2762 This operator adds a space between the existing content of the
2763 variable and the new content.
2764
2765 Here is an example:
2766 ::
2767
2768 SRC_URI += "file://fix-makefile.patch"
2769
2770- *Prepending (=+):* Use the equals sign followed by the plus character
2771 (``=+``) to prepend values to existing variables.
2772
2773 .. note::
2774
2775 This operator adds a space between the new content and the
2776 existing content of the variable.
2777
2778 Here is an example:
2779 ::
2780
2781 VAR =+ "Starts"
2782
2783- *Appending (_append):* Use the ``_append`` operator to append values
2784 to existing variables. This operator does not add any additional
2785 space. Also, the operator is applied after all the ``+=``, and ``=+``
2786 operators have been applied and after all ``=`` assignments have
2787 occurred.
2788
2789 The following example shows the space being explicitly added to the
2790 start to ensure the appended value is not merged with the existing
2791 value:
2792 ::
2793
2794 SRC_URI_append = " file://fix-makefile.patch"
2795
2796 You can also use
2797 the ``_append`` operator with overrides, which results in the actions
2798 only being performed for the specified target or machine:
2799 ::
2800
2801 SRC_URI_append_sh4 = " file://fix-makefile.patch"
2802
2803- *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
2804 values to existing variables. This operator does not add any
2805 additional space. Also, the operator is applied after all the ``+=``,
2806 and ``=+`` operators have been applied and after all ``=``
2807 assignments have occurred.
2808
2809 The following example shows the space being explicitly added to the
2810 end to ensure the prepended value is not merged with the existing
2811 value:
2812 ::
2813
2814 CFLAGS_prepend = "-I${S}/myincludes "
2815
2816 You can also use the
2817 ``_prepend`` operator with overrides, which results in the actions
2818 only being performed for the specified target or machine:
2819 ::
2820
2821 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
2822
2823- *Overrides:* You can use overrides to set a value conditionally,
2824 typically based on how the recipe is being built. For example, to set
2825 the :term:`KBRANCH` variable's
2826 value to "standard/base" for any target
2827 :term:`MACHINE`, except for
2828 qemuarm where it should be set to "standard/arm-versatile-926ejs",
2829 you would do the following:
2830 ::
2831
2832 KBRANCH = "standard/base"
2833 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
2834
2835 Overrides are also used to separate
2836 alternate values of a variable in other situations. For example, when
2837 setting variables such as
2838 :term:`FILES` and
2839 :term:`RDEPENDS` that are
2840 specific to individual packages produced by a recipe, you should
2841 always use an override that specifies the name of the package.
2842
2843- *Indentation:* Use spaces for indentation rather than tabs. For
2844 shell functions, both currently work. However, it is a policy
2845 decision of the Yocto Project to use tabs in shell functions. Realize
2846 that some layers have a policy to use spaces for all indentation.
2847
2848- *Using Python for Complex Operations:* For more advanced processing,
2849 it is possible to use Python code during variable assignments (e.g.
2850 search and replacement on a variable).
2851
2852 You indicate Python code using the ``${@python_code}`` syntax for the
2853 variable assignment:
2854 ::
2855
2856 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2857
2858- *Shell Function Syntax:* Write shell functions as if you were writing
2859 a shell script when you describe a list of actions to take. You
2860 should ensure that your script works with a generic ``sh`` and that
2861 it does not require any ``bash`` or other shell-specific
2862 functionality. The same considerations apply to various system
2863 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2864 might wish to use. If in doubt, you should check with multiple
2865 implementations - including those from BusyBox.
2866
2867.. _platdev-newmachine:
2868
2869Adding a New Machine
2870====================
2871
2872Adding a new machine to the Yocto Project is a straightforward process.
2873This section describes how to add machines that are similar to those
2874that the Yocto Project already supports.
2875
2876.. note::
2877
2878 Although well within the capabilities of the Yocto Project, adding a
2879 totally new architecture might require changes to ``gcc``/``glibc``
2880 and to the site information, which is beyond the scope of this
2881 manual.
2882
2883For a complete example that shows how to add a new machine, see the
2884":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2885section in the Yocto Project Board Support Package (BSP) Developer's
2886Guide.
2887
2888.. _platdev-newmachine-conffile:
2889
2890Adding the Machine Configuration File
2891-------------------------------------
2892
2893To add a new machine, you need to add a new machine configuration file
2894to the layer's ``conf/machine`` directory. This configuration file
2895provides details about the device you are adding.
2896
2897The OpenEmbedded build system uses the root name of the machine
2898configuration file to reference the new machine. For example, given a
2899machine configuration file named ``crownbay.conf``, the build system
2900recognizes the machine as "crownbay".
2901
2902The most important variables you must set in your machine configuration
2903file or include from a lower-level configuration file are as follows:
2904
2905- ``TARGET_ARCH`` (e.g. "arm")
2906
2907- ``PREFERRED_PROVIDER_virtual/kernel``
2908
2909- ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
2910
2911You might also need these variables:
2912
2913- ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
2914
2915- ``KERNEL_IMAGETYPE`` (e.g. "zImage")
2916
2917- ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
2918
2919You can find full details on these variables in the reference section.
2920You can leverage existing machine ``.conf`` files from
2921``meta-yocto-bsp/conf/machine/``.
2922
2923.. _platdev-newmachine-kernel:
2924
2925Adding a Kernel for the Machine
2926-------------------------------
2927
2928The OpenEmbedded build system needs to be able to build a kernel for the
2929machine. You need to either create a new kernel recipe for this machine,
2930or extend an existing kernel recipe. You can find several kernel recipe
2931examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2932you can use as references.
2933
2934If you are creating a new kernel recipe, normal recipe-writing rules
2935apply for setting up a ``SRC_URI``. Thus, you need to specify any
2936necessary patches and set ``S`` to point at the source code. You need to
2937create a ``do_configure`` task that configures the unpacked kernel with
2938a ``defconfig`` file. You can do this by using a ``make defconfig``
2939command or, more commonly, by copying in a suitable ``defconfig`` file
2940and then running ``make oldconfig``. By making use of ``inherit kernel``
2941and potentially some of the ``linux-*.inc`` files, most other
2942functionality is centralized and the defaults of the class normally work
2943well.
2944
2945If you are extending an existing kernel recipe, it is usually a matter
2946of adding a suitable ``defconfig`` file. The file needs to be added into
2947a location similar to ``defconfig`` files used for other machines in a
2948given kernel recipe. A possible way to do this is by listing the file in
2949the ``SRC_URI`` and adding the machine to the expression in
2950``COMPATIBLE_MACHINE``:
2951::
2952
2953 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2954
2955For more information on ``defconfig`` files, see the
2956":ref:`kernel-dev/kernel-dev-common:changing the configuration`"
2957section in the Yocto Project Linux Kernel Development Manual.
2958
2959.. _platdev-newmachine-formfactor:
2960
2961Adding a Formfactor Configuration File
2962--------------------------------------
2963
2964A formfactor configuration file provides information about the target
2965hardware for which the image is being built and information that the
2966build system cannot obtain from other sources such as the kernel. Some
2967examples of information contained in a formfactor configuration file
2968include framebuffer orientation, whether or not the system has a
2969keyboard, the positioning of the keyboard in relation to the screen, and
2970the screen resolution.
2971
2972The build system uses reasonable defaults in most cases. However, if
2973customization is necessary, you need to create a ``machconfig`` file in
2974the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2975contains directories for specific machines such as ``qemuarm`` and
2976``qemux86``. For information about the settings available and the
2977defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2978found in the same area.
2979
2980Following is an example for "qemuarm" machine:
2981::
2982
2983 HAVE_TOUCHSCREEN=1
2984 HAVE_KEYBOARD=1
2985 DISPLAY_CAN_ROTATE=0
2986 DISPLAY_ORIENTATION=0
2987 #DISPLAY_WIDTH_PIXELS=640
2988 #DISPLAY_HEIGHT_PIXELS=480
2989 #DISPLAY_BPP=16
2990 DISPLAY_DPI=150
2991 DISPLAY_SUBPIXEL_ORDER=vrgb
2992
2993.. _gs-upgrading-recipes:
2994
2995Upgrading Recipes
2996=================
2997
2998Over time, upstream developers publish new versions for software built
2999by layer recipes. It is recommended to keep recipes up-to-date with
3000upstream version releases.
3001
3002While several methods exist that allow you upgrade a recipe, you might
3003consider checking on the upgrade status of a recipe first. You can do so
3004using the ``devtool check-upgrade-status`` command. See the
3005":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
3006section in the Yocto Project Reference Manual for more information.
3007
3008The remainder of this section describes three ways you can upgrade a
3009recipe. You can use the Automated Upgrade Helper (AUH) to set up
3010automatic version upgrades. Alternatively, you can use
3011``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
3012you can manually upgrade a recipe by editing the recipe itself.
3013
3014.. _gs-using-the-auto-upgrade-helper:
3015
3016Using the Auto Upgrade Helper (AUH)
3017-----------------------------------
3018
3019The AUH utility works in conjunction with the OpenEmbedded build system
3020in order to automatically generate upgrades for recipes based on new
3021versions being published upstream. Use AUH when you want to create a
3022service that performs the upgrades automatically and optionally sends
3023you an email with the results.
3024
3025AUH allows you to update several recipes with a single use. You can also
3026optionally perform build and integration tests using images with the
3027results saved to your hard drive and emails of results optionally sent
3028to recipe maintainers. Finally, AUH creates Git commits with appropriate
3029commit messages in the layer's tree for the changes made to recipes.
3030
3031.. note::
3032
3033 Conditions do exist when you should not use AUH to upgrade recipes
3034 and you should instead use either ``devtool upgrade`` or upgrade your
3035 recipes manually:
3036
3037 - When AUH cannot complete the upgrade sequence. This situation
3038 usually results because custom patches carried by the recipe
3039 cannot be automatically rebased to the new version. In this case,
3040 ``devtool upgrade`` allows you to manually resolve conflicts.
3041
3042 - When for any reason you want fuller control over the upgrade
3043 process. For example, when you want special arrangements for
3044 testing.
3045
3046The following steps describe how to set up the AUH utility:
3047
30481. *Be Sure the Development Host is Set Up:* You need to be sure that
3049 your development host is set up to use the Yocto Project. For
3050 information on how to set up your host, see the
3051 ":ref:`dev-preparing-the-build-host`" section.
3052
30532. *Make Sure Git is Configured:* The AUH utility requires Git to be
3054 configured because AUH uses Git to save upgrades. Thus, you must have
3055 Git user and email configured. The following command shows your
3056 configurations:
3057 ::
3058
3059 $ git config --list
3060
3061 If you do not have the user and
3062 email configured, you can use the following commands to do so:
3063 ::
3064
3065 $ git config --global user.name some_name
3066 $ git config --global user.email username@domain.com
3067
30683. *Clone the AUH Repository:* To use AUH, you must clone the repository
3069 onto your development host. The following command uses Git to create
3070 a local copy of the repository on your system:
3071 ::
3072
3073 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
3074 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
3075 remote: Compressing objects: 100% (300/300), done.
3076 remote: Total 768 (delta 499), reused 703 (delta 434)
3077 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
3078 Resolving deltas: 100% (499/499), done.
3079 Checking connectivity... done.
3080
3081 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
3082 :term:`Poky` repositories.
3083
30844. *Create a Dedicated Build Directory:* Run the
3085 :ref:`structure-core-script`
3086 script to create a fresh build directory that you use exclusively for
3087 running the AUH utility:
3088 ::
3089
3090 $ cd ~/poky
3091 $ source oe-init-build-env your_AUH_build_directory
3092
3093 Re-using an existing build directory and its configurations is not
3094 recommended as existing settings could cause AUH to fail or behave
3095 undesirably.
3096
30975. *Make Configurations in Your Local Configuration File:* Several
3098 settings need to exist in the ``local.conf`` file in the build
3099 directory you just created for AUH. Make these following
3100 configurations:
3101
3102 - If you want to enable :ref:`Build
3103 History <dev-manual/dev-manual-common-tasks:maintaining build output quality>`,
3104 which is optional, you need the following lines in the
3105 ``conf/local.conf`` file:
3106 ::
3107
3108 INHERIT =+ "buildhistory"
3109 BUILDHISTORY_COMMIT = "1"
3110
3111 With this configuration and a successful
3112 upgrade, a build history "diff" file appears in the
3113 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
3114 your build directory.
3115
3116 - If you want to enable testing through the
3117 :ref:`testimage <ref-classes-testimage*>`
3118 class, which is optional, you need to have the following set in
3119 your ``conf/local.conf`` file:
3120 ::
3121
3122 INHERIT += "testimage"
3123
3124 .. note::
3125
3126 If your distro does not enable by default ptest, which Poky
3127 does, you need the following in your ``local.conf`` file:
3128 ::
3129
3130 DISTRO_FEATURES_append = " ptest"
3131
3132
31336. *Optionally Start a vncserver:* If you are running in a server
3134 without an X11 session, you need to start a vncserver:
3135 ::
3136
3137 $ vncserver :1
3138 $ export DISPLAY=:1
3139
31407. *Create and Edit an AUH Configuration File:* You need to have the
3141 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
3142 build directory. You can find a sample configuration file in the
3143 :yocto_git:`AUH source repository </cgit/cgit.cgi/auto-upgrade-helper/tree/>`.
3144
3145 Read through the sample file and make configurations as needed. For
3146 example, if you enabled build history in your ``local.conf`` as
3147 described earlier, you must enable it in ``upgrade-helper.conf``.
3148
3149 Also, if you are using the default ``maintainers.inc`` file supplied
3150 with Poky and located in ``meta-yocto`` and you do not set a
3151 "maintainers_whitelist" or "global_maintainer_override" in the
3152 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3153 the AUH command-line, the utility automatically sends out emails to
3154 all the default maintainers. Please avoid this.
3155
3156This next set of examples describes how to use the AUH:
3157
3158- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
3159 following form:
3160 ::
3161
3162 $ upgrade-helper.py recipe_name
3163
3164 For example, this command upgrades the ``xmodmap`` recipe:
3165 ::
3166
3167 $ upgrade-helper.py xmodmap
3168
3169- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
3170 specific recipe to a particular version, use the following form:
3171 ::
3172
3173 $ upgrade-helper.py recipe_name -t version
3174
3175 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:
3176 ::
3177
3178 $ upgrade-helper.py xmodmap -t 1.2.3
3179
3180- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3181 Notifications:* To upgrade all recipes to their most recent versions
3182 and suppress the email notifications, use the following command:
3183 ::
3184
3185 $ upgrade-helper.py all
3186
3187- *Upgrading all Recipes to the Latest Versions and Send Email
3188 Notifications:* To upgrade all recipes to their most recent versions
3189 and send email messages to maintainers for each attempted recipe as
3190 well as a status email, use the following command:
3191 ::
3192
3193 $ upgrade-helper.py -e all
3194
3195Once you have run the AUH utility, you can find the results in the AUH
3196build directory:
3197::
3198
3199 ${BUILDDIR}/upgrade-helper/timestamp
3200
3201The AUH utility
3202also creates recipe update commits from successful upgrade attempts in
3203the layer tree.
3204
3205You can easily set up to run the AUH utility on a regular basis by using
3206a cron job. See the
3207:yocto_git:`weeklyjob.sh </cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh>`
3208file distributed with the utility for an example.
3209
3210.. _gs-using-devtool-upgrade:
3211
3212Using ``devtool upgrade``
3213-------------------------
3214
3215As mentioned earlier, an alternative method for upgrading recipes to
3216newer versions is to use
3217:doc:`devtool upgrade <../ref-manual/ref-devtool-reference>`.
3218You can read about ``devtool upgrade`` in general in the
3219":ref:`sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software`"
3220section in the Yocto Project Application Development and the Extensible
3221Software Development Kit (eSDK) Manual.
3222
3223To see all the command-line options available with ``devtool upgrade``,
3224use the following help command:
3225::
3226
3227 $ devtool upgrade -h
3228
3229If you want to find out what version a recipe is currently at upstream
3230without any attempt to upgrade your local version of the recipe, you can
3231use the following command:
3232::
3233
3234 $ devtool latest-version recipe_name
3235
3236As mentioned in the previous section describing AUH, ``devtool upgrade``
3237works in a less-automated manner than AUH. Specifically,
3238``devtool upgrade`` only works on a single recipe that you name on the
3239command line, cannot perform build and integration testing using images,
3240and does not automatically generate commits for changes in the source
3241tree. Despite all these "limitations", ``devtool upgrade`` updates the
3242recipe file to the new upstream version and attempts to rebase custom
3243patches contained by the recipe as needed.
3244
3245.. note::
3246
3247 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3248 of a "wrapper" application for ``devtool upgrade``.
3249
3250A typical scenario involves having used Git to clone an upstream
3251repository that you use during build operations. Because you have built the
3252recipe in the past, the layer is likely added to your
3253configuration already. If for some reason, the layer is not added, you
3254could add it easily using the
3255":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3256script. For example, suppose you use the ``nano.bb`` recipe from the
3257``meta-oe`` layer in the ``meta-openembedded`` repository. For this
3258example, assume that the layer has been cloned into following area:
3259::
3260
3261 /home/scottrif/meta-openembedded
3262
3263The following command from your
3264:term:`Build Directory` adds the layer to
3265your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):
3266::
3267
3268 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3269 NOTE: Starting bitbake server...
3270 Parsing recipes: 100% |##########################################| Time: 0:00:55
3271 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3272 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3273 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3274 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3275 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3276
3277For this example, assume that the ``nano.bb`` recipe that
3278is upstream has a 2.9.3 version number. However, the version in the
3279local repository is 2.7.4. The following command from your build
3280directory automatically upgrades the recipe for you:
3281
3282.. note::
3283
3284 Using the ``-V`` option is not necessary. Omitting the version number causes
3285 ``devtool upgrade`` to upgrade the recipe to the most recent version.
3286
3287::
3288
3289 $ devtool upgrade nano -V 2.9.3
3290 NOTE: Starting bitbake server...
3291 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3292 Parsing recipes: 100% |##########################################| Time: 0:00:46
3293 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3294 NOTE: Extracting current version source...
3295 NOTE: Resolving any missing task queue dependencies
3296 .
3297 .
3298 .
3299 NOTE: Executing SetScene Tasks
3300 NOTE: Executing RunQueue Tasks
3301 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3302 Adding changed files: 100% |#####################################| Time: 0:00:00
3303 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3304 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3305
3306Continuing with this example, you can use ``devtool build`` to build the
3307newly upgraded recipe:
3308::
3309
3310 $ devtool build nano
3311 NOTE: Starting bitbake server...
3312 Loading cache: 100% |################################################################################################| Time: 0:00:01
3313 Loaded 2040 entries from dependency cache.
3314 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3315 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3316 NOTE: Resolving any missing task queue dependencies
3317 .
3318 .
3319 .
3320 NOTE: Executing SetScene Tasks
3321 NOTE: Executing RunQueue Tasks
3322 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3323 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3324
3325Within the ``devtool upgrade`` workflow, opportunity
3326exists to deploy and test your rebuilt software. For this example,
3327however, running ``devtool finish`` cleans up the workspace once the
3328source in your workspace is clean. This usually means using Git to stage
3329and submit commits for the changes generated by the upgrade process.
3330
3331Once the tree is clean, you can clean things up in this example with the
3332following command from the ``${BUILDDIR}/workspace/sources/nano``
3333directory:
3334::
3335
3336 $ devtool finish nano meta-oe
3337 NOTE: Starting bitbake server...
3338 Loading cache: 100% |################################################################################################| Time: 0:00:00
3339 Loaded 2040 entries from dependency cache.
3340 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3341 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3342 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3343 NOTE: Updating recipe nano_2.9.3.bb
3344 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3345 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3346 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3347
3348
3349Using the ``devtool finish`` command cleans up the workspace and creates a patch
3350file based on your commits. The tool puts all patch files back into the
3351source directory in a sub-directory named ``nano`` in this case.
3352
3353.. _dev-manually-upgrading-a-recipe:
3354
3355Manually Upgrading a Recipe
3356---------------------------
3357
3358If for some reason you choose not to upgrade recipes using
3359:ref:`gs-using-the-auto-upgrade-helper` or by :ref:`gs-using-devtool-upgrade`,
3360you can manually edit the recipe files to upgrade the versions.
3361
3362.. note::
3363
3364 Manually updating multiple recipes scales poorly and involves many
3365 steps. The recommendation to upgrade recipe versions is through AUH
3366 or ``devtool upgrade``, both of which automate some steps and provide
3367 guidance for others needed for the manual process.
3368
3369To manually upgrade recipe versions, follow these general steps:
3370
33711. *Change the Version:* Rename the recipe such that the version (i.e.
3372 the :term:`PV` part of the recipe name)
3373 changes appropriately. If the version is not part of the recipe name,
3374 change the value as it is set for ``PV`` within the recipe itself.
3375
33762. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
3377 is fetched from Git or some other version control system, update
3378 :term:`SRCREV` to point to the
3379 commit hash that matches the new version.
3380
33813. *Build the Software:* Try to build the recipe using BitBake. Typical
3382 build failures include the following:
3383
3384 - License statements were updated for the new version. For this
3385 case, you need to review any changes to the license and update the
3386 values of :term:`LICENSE` and
3387 :term:`LIC_FILES_CHKSUM`
3388 as needed.
3389
3390 .. note::
3391
3392 License changes are often inconsequential. For example, the
3393 license text's copyright year might have changed.
3394
3395 - Custom patches carried by the older version of the recipe might
3396 fail to apply to the new version. For these cases, you need to
3397 review the failures. Patches might not be necessary for the new
3398 version of the software if the upgraded version has fixed those
3399 issues. If a patch is necessary and failing, you need to rebase it
3400 into the new version.
3401
34024. *Optionally Attempt to Build for Several Architectures:* Once you
3403 successfully build the new software for a given architecture, you
3404 could test the build for other architectures by changing the
3405 :term:`MACHINE` variable and
3406 rebuilding the software. This optional step is especially important
3407 if the recipe is to be released publicly.
3408
34095. *Check the Upstream Change Log or Release Notes:* Checking both these
3410 reveals if new features exist that could break
3411 backwards-compatibility. If so, you need to take steps to mitigate or
3412 eliminate that situation.
3413
34146. *Optionally Create a Bootable Image and Test:* If you want, you can
3415 test the new software by booting it onto actual hardware.
3416
34177. *Create a Commit with the Change in the Layer Repository:* After all
3418 builds work and any testing is successful, you can create commits for
3419 any changes in the layer holding your upgraded recipe.
3420
3421.. _finding-the-temporary-source-code:
3422
3423Finding Temporary Source Code
3424=============================
3425
3426You might find it helpful during development to modify the temporary
3427source code used by recipes to build packages. For example, suppose you
3428are developing a patch and you need to experiment a bit to figure out
3429your solution. After you have initially built the package, you can
3430iteratively tweak the source code, which is located in the
3431:term:`Build Directory`, and then you can
3432force a re-compile and quickly test your altered code. Once you settle
3433on a solution, you can then preserve your changes in the form of
3434patches.
3435
3436During a build, the unpacked temporary source code used by recipes to
3437build packages is available in the Build Directory as defined by the
3438:term:`S` variable. Below is the default
3439value for the ``S`` variable as defined in the
3440``meta/conf/bitbake.conf`` configuration file in the
3441:term:`Source Directory`:
3442::
3443
3444 S = "${WORKDIR}/${BP}"
3445
3446You should be aware that many recipes override the
3447``S`` variable. For example, recipes that fetch their source from Git
3448usually set ``S`` to ``${WORKDIR}/git``.
3449
3450.. note::
3451
3452 The :term:`BP` represents the base recipe name, which consists of the name
3453 and version:
3454 ::
3455
3456 BP = "${BPN}-${PV}"
3457
3458
3459The path to the work directory for the recipe
3460(:term:`WORKDIR`) is defined as
3461follows:
3462::
3463
3464 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3465
3466The actual directory depends on several things:
3467
3468- :term:`TMPDIR`: The top-level build
3469 output directory.
3470
3471- :term:`MULTIMACH_TARGET_SYS`:
3472 The target system identifier.
3473
3474- :term:`PN`: The recipe name.
3475
3476- :term:`EXTENDPE`: The epoch - (if
3477 :term:`PE` is not specified, which is
3478 usually the case for most recipes, then ``EXTENDPE`` is blank).
3479
3480- :term:`PV`: The recipe version.
3481
3482- :term:`PR`: The recipe revision.
3483
3484As an example, assume a Source Directory top-level folder named
3485``poky``, a default Build Directory at ``poky/build``, and a
3486``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3487recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
3488build system uses to build the package would be as follows:
3489::
3490
3491 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3492
3493.. _using-a-quilt-workflow:
3494
3495Using Quilt in Your Workflow
3496============================
3497
3498`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
3499that allows you to capture source code changes without having a clean
3500source tree. This section outlines the typical workflow you can use to
3501modify source code, test changes, and then preserve the changes in the
3502form of a patch all using Quilt.
3503
3504.. note::
3505
3506 With regard to preserving changes to source files, if you clean a
3507 recipe or have ``rm_work`` enabled, the
3508 :ref:`devtool workflow <sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow>`
3509 as described in the Yocto Project Application Development and the
3510 Extensible Software Development Kit (eSDK) manual is a safer
3511 development flow than the flow that uses Quilt.
3512
3513Follow these general steps:
3514
35151. *Find the Source Code:* Temporary source code used by the
3516 OpenEmbedded build system is kept in the
3517 :term:`Build Directory`. See the
3518 "`Finding Temporary Source
3519 Code <#finding-the-temporary-source-code>`__" section to learn how to
3520 locate the directory that has the temporary source code for a
3521 particular package.
3522
35232. *Change Your Working Directory:* You need to be in the directory that
3524 has the temporary source code. That directory is defined by the
3525 :term:`S` variable.
3526
35273. *Create a New Patch:* Before modifying source code, you need to
3528 create a new patch. To create a new patch file, use ``quilt new`` as
3529 below:
3530 ::
3531
3532 $ quilt new my_changes.patch
3533
35344. *Notify Quilt and Add Files:* After creating the patch, you need to
3535 notify Quilt about the files you plan to edit. You notify Quilt by
3536 adding the files to the patch you just created:
3537 ::
3538
3539 $ quilt add file1.c file2.c file3.c
3540
35415. *Edit the Files:* Make your changes in the source code to the files
3542 you added to the patch.
3543
35446. *Test Your Changes:* Once you have modified the source code, the
3545 easiest way to test your changes is by calling the ``do_compile``
3546 task as shown in the following example:
3547 ::
3548
3549 $ bitbake -c compile -f package
3550
3551 The ``-f`` or ``--force`` option forces the specified task to
3552 execute. If you find problems with your code, you can just keep
3553 editing and re-testing iteratively until things work as expected.
3554
3555 .. note::
3556
3557 All the modifications you make to the temporary source code disappear
3558 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3559 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3560 Modifications will also disappear if you use the ``rm_work`` feature as
3561 described in the
3562 ":ref:`dev-manual/dev-manual-common-tasks:conserving disk space during builds`"
3563 section.
3564
35657. *Generate the Patch:* Once your changes work as expected, you need to
3566 use Quilt to generate the final patch that contains all your
3567 modifications.
3568 ::
3569
3570 $ quilt refresh
3571
3572 At this point, the
3573 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3574 ``file2.c``, and ``file3.c`` files.
3575
3576 You can find the resulting patch file in the ``patches/``
3577 subdirectory of the source (``S``) directory.
3578
35798. *Copy the Patch File:* For simplicity, copy the patch file into a
3580 directory named ``files``, which you can create in the same directory
3581 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3582 file. Placing the patch here guarantees that the OpenEmbedded build
3583 system will find the patch. Next, add the patch into the ``SRC_URI``
3584 of the recipe. Here is an example:
3585 ::
3586
3587 SRC_URI += "file://my_changes.patch"
3588
3589.. _platdev-appdev-devshell:
3590
3591Using a Development Shell
3592=========================
3593
3594When debugging certain commands or even when just editing packages,
3595``devshell`` can be a useful tool. When you invoke ``devshell``, all
3596tasks up to and including
3597:ref:`ref-tasks-patch` are run for the
3598specified target. Then, a new terminal is opened and you are placed in
3599``${``\ :term:`S`\ ``}``, the source
3600directory. In the new terminal, all the OpenEmbedded build-related
3601environment variables are still defined so you can use commands such as
3602``configure`` and ``make``. The commands execute just as if the
3603OpenEmbedded build system were executing them. Consequently, working
3604this way can be helpful when debugging a build or preparing software to
3605be used with the OpenEmbedded build system.
3606
3607Following is an example that uses ``devshell`` on a target named
3608``matchbox-desktop``:
3609::
3610
3611 $ bitbake matchbox-desktop -c devshell
3612
3613This command spawns a terminal with a shell prompt within the
3614OpenEmbedded build environment. The
3615:term:`OE_TERMINAL` variable
3616controls what type of shell is opened.
3617
3618For spawned terminals, the following occurs:
3619
3620- The ``PATH`` variable includes the cross-toolchain.
3621
3622- The ``pkgconfig`` variables find the correct ``.pc`` files.
3623
3624- The ``configure`` command finds the Yocto Project site files as well
3625 as any other necessary files.
3626
3627Within this environment, you can run configure or compile commands as if
3628they were being run by the OpenEmbedded build system itself. As noted
3629earlier, the working directory also automatically changes to the Source
3630Directory (:term:`S`).
3631
3632To manually run a specific task using ``devshell``, run the
3633corresponding ``run.*`` script in the
3634``${``\ :term:`WORKDIR`\ ``}/temp``
3635directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
3636not exist, which would be the case if the task was skipped by way of the
3637sstate cache, you can create the task by first running it outside of the
3638``devshell``:
3639::
3640
3641 $ bitbake -c task
3642
3643.. note::
3644
3645 - Execution of a task's ``run.*`` script and BitBake's execution of
3646 a task are identical. In other words, running the script re-runs
3647 the task just as it would be run using the ``bitbake -c`` command.
3648
3649 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3650 symbolic link (symlink) to the most recent version of that file.
3651
3652Remember, that the ``devshell`` is a mechanism that allows you to get
3653into the BitBake task execution environment. And as such, all commands
3654must be called just as BitBake would call them. That means you need to
3655provide the appropriate options for cross-compilation and so forth as
3656applicable.
3657
3658When you are finished using ``devshell``, exit the shell or close the
3659terminal window.
3660
3661.. note::
3662
3663 - It is worth remembering that when using ``devshell`` you need to
3664 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3665 instead of just using ``gcc``. The same applies to other
3666 applications such as ``binutils``, ``libtool`` and so forth.
3667 BitBake sets up environment variables such as ``CC`` to assist
3668 applications, such as ``make`` to find the correct tools.
3669
3670 - It is also worth noting that ``devshell`` still works over X11
3671 forwarding and similar situations.
3672
3673.. _platdev-appdev-devpyshell:
3674
3675Using a Development Python Shell
3676================================
3677
3678Similar to working within a development shell as described in the
3679previous section, you can also spawn and work within an interactive
3680Python development shell. When debugging certain commands or even when
3681just editing packages, ``devpyshell`` can be a useful tool. When you
3682invoke ``devpyshell``, all tasks up to and including
3683:ref:`ref-tasks-patch` are run for the
3684specified target. Then a new terminal is opened. Additionally, key
3685Python objects and code are available in the same way they are to
3686BitBake tasks, in particular, the data store 'd'. So, commands such as
3687the following are useful when exploring the data store and running
3688functions:
3689::
3690
3691 pydevshell> d.getVar("STAGING_DIR")
3692 '/media/build1/poky/build/tmp/sysroots'
3693 pydevshell> d.getVar("STAGING_DIR")
3694 '${TMPDIR}/sysroots'
3695 pydevshell> d.setVar("FOO", "bar")
3696 pydevshell> d.getVar("FOO")
3697 'bar'
3698 pydevshell> d.delVar("FOO")
3699 pydevshell> d.getVar("FOO")
3700 pydevshell> bb.build.exec_func("do_unpack", d)
3701 pydevshell>
3702
3703The commands execute just as if the OpenEmbedded build
3704system were executing them. Consequently, working this way can be
3705helpful when debugging a build or preparing software to be used with the
3706OpenEmbedded build system.
3707
3708Following is an example that uses ``devpyshell`` on a target named
3709``matchbox-desktop``:
3710::
3711
3712 $ bitbake matchbox-desktop -c devpyshell
3713
3714This command spawns a terminal and places you in an interactive Python
3715interpreter within the OpenEmbedded build environment. The
3716:term:`OE_TERMINAL` variable
3717controls what type of shell is opened.
3718
3719When you are finished using ``devpyshell``, you can exit the shell
3720either by using Ctrl+d or closing the terminal window.
3721
3722.. _dev-building:
3723
3724Building
3725========
3726
3727This section describes various build procedures. For example, the steps
3728needed for a simple build, a target that uses multiple configurations,
3729building an image for more than one machine, and so forth.
3730
3731.. _dev-building-a-simple-image:
3732
3733Building a Simple Image
3734-----------------------
3735
3736In the development environment, you need to build an image whenever you
3737change hardware support, add or change system libraries, or add or
3738change services that have dependencies. Several methods exist that allow
3739you to build an image within the Yocto Project. This section presents
3740the basic steps you need to build a simple image using BitBake from a
3741build host running Linux.
3742
3743.. note::
3744
3745 - For information on how to build an image using
3746 :term:`Toaster`, see the
3747 :doc:`../toaster-manual/toaster-manual`.
3748
3749 - For information on how to use ``devtool`` to build images, see the
3750 ":ref:`sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow`"
3751 section in the Yocto Project Application Development and the
3752 Extensible Software Development Kit (eSDK) manual.
3753
3754 - For a quick example on how to build an image using the
3755 OpenEmbedded build system, see the
3756 :doc:`../brief-yoctoprojectqs/brief-yoctoprojectqs` document.
3757
3758The build process creates an entire Linux distribution from source and
3759places it in your :term:`Build Directory` under
3760``tmp/deploy/images``. For detailed information on the build process
3761using BitBake, see the ":ref:`images-dev-environment`" section in the
3762Yocto Project Overview and Concepts Manual.
3763
3764The following figure and list overviews the build process:
3765
3766.. image:: figures/bitbake-build-flow.png
3767 :align: center
3768
37691. *Set up Your Host Development System to Support Development Using the
3770 Yocto Project*: See the ":doc:`dev-manual-start`" section for options on how to get a
3771 build host ready to use the Yocto Project.
3772
37732. *Initialize the Build Environment:* Initialize the build environment
3774 by sourcing the build environment script (i.e.
3775 :ref:`structure-core-script`):
3776 ::
3777
3778 $ source oe-init-build-env [build_dir]
3779
3780 When you use the initialization script, the OpenEmbedded build system
3781 uses ``build`` as the default :term:`Build Directory` in your current work
3782 directory. You can use a `build_dir` argument with the script to
3783 specify a different build directory.
3784
3785 .. note::
3786
3787 A common practice is to use a different Build Directory for
3788 different targets. For example, ``~/build/x86`` for a ``qemux86``
3789 target, and ``~/build/arm`` for a ``qemuarm`` target.
3790
37913. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
3792 ``conf/local.conf`` configuration file, which is found in the Build
3793 Directory, is set up how you want it. This file defines many aspects
3794 of the build environment including the target machine architecture
3795 through the ``MACHINE`` variable, the packaging format used during
3796 the build
3797 (:term:`PACKAGE_CLASSES`),
3798 and a centralized tarball download directory through the
3799 :term:`DL_DIR` variable.
3800
38014. *Build the Image:* Build the image using the ``bitbake`` command:
3802 ::
3803
3804 $ bitbake target
3805
3806 .. note::
3807
3808 For information on BitBake, see the :doc:`bitbake:index`.
3809
3810 The target is the name of the recipe you want to build. Common
3811 targets are the images in ``meta/recipes-core/images``,
3812 ``meta/recipes-sato/images``, and so forth all found in the
3813 :term:`Source Directory`. Or, the target
3814 can be the name of a recipe for a specific piece of software such as
3815 BusyBox. For more details about the images the OpenEmbedded build
3816 system supports, see the
3817 ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto
3818 Project Reference Manual.
3819
3820 As an example, the following command builds the
3821 ``core-image-minimal`` image:
3822 ::
3823
3824 $ bitbake core-image-minimal
3825
3826 Once an
3827 image has been built, it often needs to be installed. The images and
3828 kernels built by the OpenEmbedded build system are placed in the
3829 Build Directory in ``tmp/deploy/images``. For information on how to
3830 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
3831 :doc:`../sdk-manual/sdk-manual` manual. For
3832 information about how to install these images, see the documentation
3833 for your particular board or machine.
3834
3835.. _dev-building-images-for-multiple-targets-using-multiple-configurations:
3836
3837Building Images for Multiple Targets Using Multiple Configurations
3838------------------------------------------------------------------
3839
3840You can use a single ``bitbake`` command to build multiple images or
3841packages for different targets where each image or package requires a
3842different configuration (multiple configuration builds). The builds, in
3843this scenario, are sometimes referred to as "multiconfigs", and this
3844section uses that term throughout.
3845
3846This section describes how to set up for multiple configuration builds
3847and how to account for cross-build dependencies between the
3848multiconfigs.
3849
3850.. _dev-setting-up-and-running-a-multiple-configuration-build:
3851
3852Setting Up and Running a Multiple Configuration Build
3853~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3854
3855To accomplish a multiple configuration build, you must define each
3856target's configuration separately using a parallel configuration file in
3857the :term:`Build Directory`, and you
3858must follow a required file hierarchy. Additionally, you must enable the
3859multiple configuration builds in your ``local.conf`` file.
3860
3861Follow these steps to set up and execute multiple configuration builds:
3862
3863- *Create Separate Configuration Files*: You need to create a single
3864 configuration file for each build target (each multiconfig).
3865 Minimally, each configuration file must define the machine and the
3866 temporary directory BitBake uses for the build. Suggested practice
3867 dictates that you do not overlap the temporary directories used
3868 during the builds. However, it is possible that you can share the
3869 temporary directory
3870 (:term:`TMPDIR`). For example,
3871 consider a scenario with two different multiconfigs for the same
3872 :term:`MACHINE`: "qemux86" built
3873 for two distributions such as "poky" and "poky-lsb". In this case,
3874 you might want to use the same ``TMPDIR``.
3875
3876 Here is an example showing the minimal statements needed in a
3877 configuration file for a "qemux86" target whose temporary build
3878 directory is ``tmpmultix86``:
3879 ::
3880
3881 MACHINE = "qemux86"
3882 TMPDIR = "${TOPDIR}/tmpmultix86"
3883
3884 The location for these multiconfig configuration files is specific.
3885 They must reside in the current build directory in a sub-directory of
3886 ``conf`` named ``multiconfig``. Following is an example that defines
3887 two configuration files for the "x86" and "arm" multiconfigs:
3888
3889 .. image:: figures/multiconfig_files.png
3890 :align: center
3891
3892 The reason for this required file hierarchy is because the ``BBPATH``
3893 variable is not constructed until the layers are parsed.
3894 Consequently, using the configuration file as a pre-configuration
3895 file is not possible unless it is located in the current working
3896 directory.
3897
3898- *Add the BitBake Multi-configuration Variable to the Local
3899 Configuration File*: Use the
3900 :term:`BBMULTICONFIG`
3901 variable in your ``conf/local.conf`` configuration file to specify
3902 each multiconfig. Continuing with the example from the previous
3903 figure, the ``BBMULTICONFIG`` variable needs to enable two
3904 multiconfigs: "x86" and "arm" by specifying each configuration file:
3905 ::
3906
3907 BBMULTICONFIG = "x86 arm"
3908
3909 .. note::
3910
3911 A "default" configuration already exists by definition. This
3912 configuration is named: "" (i.e. empty string) and is defined by
3913 the variables coming from your ``local.conf``
3914 file. Consequently, the previous example actually adds two
3915 additional configurations to your build: "arm" and "x86" along
3916 with "".
3917
3918- *Launch BitBake*: Use the following BitBake command form to launch
3919 the multiple configuration build:
3920 ::
3921
3922 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3923
3924 For the example in this section, the following command applies:
3925 ::
3926
3927 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3928
3929 The previous BitBake command builds a ``core-image-minimal`` image
3930 that is configured through the ``x86.conf`` configuration file, a
3931 ``core-image-sato`` image that is configured through the ``arm.conf``
3932 configuration file and a ``core-image-base`` that is configured
3933 through your ``local.conf`` configuration file.
3934
3935.. note::
3936
3937 Support for multiple configuration builds in the Yocto Project &DISTRO;
3938 (&DISTRO_NAME;) Release does not include Shared State (sstate)
3939 optimizations. Consequently, if a build uses the same object twice
3940 in, for example, two different ``TMPDIR``
3941 directories, the build either loads from an existing sstate cache for
3942 that build at the start or builds the object fresh.
3943
3944.. _dev-enabling-multiple-configuration-build-dependencies:
3945
3946Enabling Multiple Configuration Build Dependencies
3947~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3948
3949Sometimes dependencies can exist between targets (multiconfigs) in a
3950multiple configuration build. For example, suppose that in order to
3951build a ``core-image-sato`` image for an "x86" multiconfig, the root
3952filesystem of an "arm" multiconfig must exist. This dependency is
3953essentially that the
3954:ref:`ref-tasks-image` task in the
3955``core-image-sato`` recipe depends on the completion of the
3956:ref:`ref-tasks-rootfs` task of the
3957``core-image-minimal`` recipe.
3958
3959To enable dependencies in a multiple configuration build, you must
3960declare the dependencies in the recipe using the following statement
3961form:
3962::
3963
3964 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3965
3966To better show how to use this statement, consider the example scenario
3967from the first paragraph of this section. The following statement needs
3968to be added to the recipe that builds the ``core-image-sato`` image:
3969::
3970
3971 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3972
3973In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
3974task on which the ``do_image`` task in the recipe depends is the
3975``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3976with the "arm" multiconfig.
3977
3978Once you set up this dependency, you can build the "x86" multiconfig
3979using a BitBake command as follows:
3980::
3981
3982 $ bitbake mc:x86:core-image-sato
3983
3984This command executes all the tasks needed to create the
3985``core-image-sato`` image for the "x86" multiconfig. Because of the
3986dependency, BitBake also executes through the ``do_rootfs`` task for the
3987"arm" multiconfig build.
3988
3989Having a recipe depend on the root filesystem of another build might not
3990seem that useful. Consider this change to the statement in the
3991``core-image-sato`` recipe:
3992::
3993
3994 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3995
3996In this case, BitBake must
3997create the ``core-image-minimal`` image for the "arm" build since the
3998"x86" build depends on it.
3999
4000Because "x86" and "arm" are enabled for multiple configuration builds
4001and have separate configuration files, BitBake places the artifacts for
4002each build in the respective temporary build directories (i.e.
4003:term:`TMPDIR`).
4004
4005.. _building-an-initramfs-image:
4006
4007Building an Initial RAM Filesystem (initramfs) Image
4008----------------------------------------------------
4009
4010An initial RAM filesystem (initramfs) image provides a temporary root
4011filesystem used for early system initialization (e.g. loading of modules
4012needed to locate and mount the "real" root filesystem).
4013
4014.. note::
4015
4016 The initramfs image is the successor of initial RAM disk (initrd). It
4017 is a "copy in and out" (cpio) archive of the initial filesystem that
4018 gets loaded into memory during the Linux startup process. Because
4019 Linux uses the contents of the archive during initialization, the
4020 initramfs image needs to contain all of the device drivers and tools
4021 needed to mount the final root filesystem.
4022
4023Follow these steps to create an initramfs image:
4024
40251. *Create the initramfs Image Recipe:* You can reference the
4026 ``core-image-minimal-initramfs.bb`` recipe found in the
4027 ``meta/recipes-core`` directory of the :term:`Source Directory`
4028 as an example
4029 from which to work.
4030
40312. *Decide if You Need to Bundle the initramfs Image Into the Kernel
4032 Image:* If you want the initramfs image that is built to be bundled
4033 in with the kernel image, set the
4034 :term:`INITRAMFS_IMAGE_BUNDLE`
4035 variable to "1" in your ``local.conf`` configuration file and set the
4036 :term:`INITRAMFS_IMAGE`
4037 variable in the recipe that builds the kernel image.
4038
4039 .. note::
4040
4041 It is recommended that you do bundle the initramfs image with the
4042 kernel image to avoid circular dependencies between the kernel
4043 recipe and the initramfs recipe should the initramfs image include
4044 kernel modules.
4045
4046 Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
4047 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
4048 initramfs image is then passed to the kernel's ``Makefile`` using the
4049 :term:`CONFIG_INITRAMFS_SOURCE`
4050 variable, allowing the initramfs image to be built into the kernel
4051 normally.
4052
4053 .. note::
4054
4055 If you choose to not bundle the initramfs image with the kernel
4056 image, you are essentially using an
4057 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
4058 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
4059 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
4060 information, see the :ref:`ref-classes-image-live` file.
4061
40623. *Optionally Add Items to the initramfs Image Through the initramfs
4063 Image Recipe:* If you add items to the initramfs image by way of its
4064 recipe, you should use
4065 :term:`PACKAGE_INSTALL`
4066 rather than
4067 :term:`IMAGE_INSTALL`.
4068 ``PACKAGE_INSTALL`` gives more direct control of what is added to the
4069 image as compared to the defaults you might not necessarily want that
4070 are set by the :ref:`image <ref-classes-image>`
4071 or :ref:`core-image <ref-classes-core-image>`
4072 classes.
4073
40744. *Build the Kernel Image and the initramfs Image:* Build your kernel
4075 image using BitBake. Because the initramfs image recipe is a
4076 dependency of the kernel image, the initramfs image is built as well
4077 and bundled with the kernel image if you used the
4078 :term:`INITRAMFS_IMAGE_BUNDLE`
4079 variable described earlier.
4080
4081Building a Tiny System
4082----------------------
4083
4084Very small distributions have some significant advantages such as
4085requiring less on-die or in-package memory (cheaper), better performance
4086through efficient cache usage, lower power requirements due to less
4087memory, faster boot times, and reduced development overhead. Some
4088real-world examples where a very small distribution gives you distinct
4089advantages are digital cameras, medical devices, and small headless
4090systems.
4091
4092This section presents information that shows you how you can trim your
4093distribution to even smaller sizes than the ``poky-tiny`` distribution,
4094which is around 5 Mbytes, that can be built out-of-the-box using the
4095Yocto Project.
4096
4097.. _tiny-system-overview:
4098
4099Tiny System Overview
4100~~~~~~~~~~~~~~~~~~~~
4101
4102The following list presents the overall steps you need to consider and
4103perform to create distributions with smaller root filesystems, achieve
4104faster boot times, maintain your critical functionality, and avoid
4105initial RAM disks:
4106
4107- `Determine your goals and guiding
4108 principles. <#goals-and-guiding-principles>`__
4109
4110- `Understand what contributes to your image
4111 size. <#understand-what-gives-your-image-size>`__
4112
4113- `Reduce the size of the root
4114 filesystem. <#trim-the-root-filesystem>`__
4115
4116- `Reduce the size of the kernel. <#trim-the-kernel>`__
4117
4118- `Eliminate packaging
4119 requirements. <#remove-package-management-requirements>`__
4120
4121- `Look for other ways to minimize
4122 size. <#look-for-other-ways-to-minimize-size>`__
4123
4124- `Iterate on the process. <#iterate-on-the-process>`__
4125
4126Goals and Guiding Principles
4127~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4128
4129Before you can reach your destination, you need to know where you are
4130going. Here is an example list that you can use as a guide when creating
4131very small distributions:
4132
4133- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4134 less and a root filesystem that is 3 Mbytes or less).
4135
4136- Find the areas that are currently taking 90% of the space and
4137 concentrate on reducing those areas.
4138
4139- Do not create any difficult "hacks" to achieve your goals.
4140
4141- Leverage the device-specific options.
4142
4143- Work in a separate layer so that you keep changes isolated. For
4144 information on how to create layers, see the "`Understanding and
4145 Creating Layers <#understanding-and-creating-layers>`__" section.
4146
4147.. _understand-what-gives-your-image-size:
4148
4149Understand What Contributes to Your Image Size
4150~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4151
4152It is easiest to have something to start with when creating your own
4153distribution. You can use the Yocto Project out-of-the-box to create the
4154``poky-tiny`` distribution. Ultimately, you will want to make changes in
4155your own distribution that are likely modeled after ``poky-tiny``.
4156
4157.. note::
4158
4159 To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
4160 ``local.conf`` file to "poky-tiny" as described in the
4161 ":ref:`dev-manual/dev-manual-common-tasks:creating your own distribution`"
4162 section.
4163
4164Understanding some memory concepts will help you reduce the system size.
4165Memory consists of static, dynamic, and temporary memory. Static memory
4166is the TEXT (code), DATA (initialized data in the code), and BSS
4167(uninitialized data) sections. Dynamic memory represents memory that is
4168allocated at runtime: stacks, hash tables, and so forth. Temporary
4169memory is recovered after the boot process. This memory consists of
4170memory used for decompressing the kernel and for the ``__init__``
4171functions.
4172
4173To help you see where you currently are with kernel and root filesystem
4174sizes, you can use two tools found in the :term:`Source Directory`
4175in the
4176``scripts/tiny/`` directory:
4177
4178- ``ksize.py``: Reports component sizes for the kernel build objects.
4179
4180- ``dirsize.py``: Reports component sizes for the root filesystem.
4181
4182This next tool and command help you organize configuration fragments and
4183view file dependencies in a human-readable form:
4184
4185- ``merge_config.sh``: Helps you manage configuration files and
4186 fragments within the kernel. With this tool, you can merge individual
4187 configuration fragments together. The tool allows you to make
4188 overrides and warns you of any missing configuration options. The
4189 tool is ideal for allowing you to iterate on configurations, create
4190 minimal configurations, and create configuration files for different
4191 machines without having to duplicate your process.
4192
4193 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4194 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4195 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4196 directory.
4197
4198 For more information on configuration fragments, see the
4199 ":ref:`creating-config-fragments`"
4200 section in the Yocto Project Linux Kernel Development Manual.
4201
4202- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4203 with these options brings up a Dependency Explorer from which you can
4204 view file dependencies. Understanding these dependencies allows you
4205 to make informed decisions when cutting out various pieces of the
4206 kernel and root filesystem.
4207
4208Trim the Root Filesystem
4209~~~~~~~~~~~~~~~~~~~~~~~~
4210
4211The root filesystem is made up of packages for booting, libraries, and
4212applications. To change things, you can configure how the packaging
4213happens, which changes the way you build them. You can also modify the
4214filesystem itself or select a different filesystem.
4215
4216First, find out what is hogging your root filesystem by running the
4217``dirsize.py`` script from your root directory:
4218::
4219
4220 $ cd root-directory-of-image
4221 $ dirsize.py 100000 > dirsize-100k.log
4222 $ cat dirsize-100k.log
4223
4224You can apply a filter to the script to ignore files
4225under a certain size. The previous example filters out any files below
4226100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4227will be smaller by a relatively constant factor in a compressed root
4228filesystem. When you examine your log file, you can focus on areas of
4229the root filesystem that take up large amounts of memory.
4230
4231You need to be sure that what you eliminate does not cripple the
4232functionality you need. One way to see how packages relate to each other
4233is by using the Dependency Explorer UI with the BitBake command:
4234::
4235
4236 $ cd image-directory
4237 $ bitbake -u taskexp -g image
4238
4239Use the interface to
4240select potential packages you wish to eliminate and see their dependency
4241relationships.
4242
4243When deciding how to reduce the size, get rid of packages that result in
4244minimal impact on the feature set. For example, you might not need a VGA
4245display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4246instead of ``udev``.
4247
4248Use your ``local.conf`` file to make changes. For example, to eliminate
4249``udev`` and ``glib``, set the following in the local configuration
4250file:
4251::
4252
4253 VIRTUAL-RUNTIME_dev_manager = ""
4254
4255Finally, you should consider exactly the type of root filesystem you
4256need to meet your needs while also reducing its size. For example,
4257consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4258``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4259Mbyte journal. If you are okay with running read-only, you do not need
4260this journal.
4261
4262.. note::
4263
4264 After each round of elimination, you need to rebuild your system and
4265 then use the tools to see the effects of your reductions.
4266
4267Trim the Kernel
4268~~~~~~~~~~~~~~~
4269
4270The kernel is built by including policies for hardware-independent
4271aspects. What subsystems do you enable? For what architecture are you
4272building? Which drivers do you build by default?
4273
4274.. note::
4275
4276 You can modify the kernel source if you want to help with boot time.
4277
4278Run the ``ksize.py`` script from the top-level Linux build directory to
4279get an idea of what is making up the kernel:
4280::
4281
4282 $ cd top-level-linux-build-directory
4283 $ ksize.py > ksize.log
4284 $ cat ksize.log
4285
4286When you examine the log, you will see how much space is taken up with
4287the built-in ``.o`` files for drivers, networking, core kernel files,
4288filesystem, sound, and so forth. The sizes reported by the tool are
4289uncompressed, and thus will be smaller by a relatively constant factor
4290in a compressed kernel image. Look to reduce the areas that are large
4291and taking up around the "90% rule."
4292
4293To examine, or drill down, into any particular area, use the ``-d``
4294option with the script:
4295::
4296
4297 $ ksize.py -d > ksize.log
4298
4299Using this option
4300breaks out the individual file information for each area of the kernel
4301(e.g. drivers, networking, and so forth).
4302
4303Use your log file to see what you can eliminate from the kernel based on
4304features you can let go. For example, if you are not going to need
4305sound, you do not need any drivers that support sound.
4306
4307After figuring out what to eliminate, you need to reconfigure the kernel
4308to reflect those changes during the next build. You could run
4309``menuconfig`` and make all your changes at once. However, that makes it
4310difficult to see the effects of your individual eliminations and also
4311makes it difficult to replicate the changes for perhaps another target
4312device. A better method is to start with no configurations using
4313``allnoconfig``, create configuration fragments for individual changes,
4314and then manage the fragments into a single configuration file using
4315``merge_config.sh``. The tool makes it easy for you to iterate using the
4316configuration change and build cycle.
4317
4318Each time you make configuration changes, you need to rebuild the kernel
4319and check to see what impact your changes had on the overall size.
4320
4321Remove Package Management Requirements
4322~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4323
4324Packaging requirements add size to the image. One way to reduce the size
4325of the image is to remove all the packaging requirements from the image.
4326This reduction includes both removing the package manager and its unique
4327dependencies as well as removing the package management data itself.
4328
4329To eliminate all the packaging requirements for an image, be sure that
4330"package-management" is not part of your
4331:term:`IMAGE_FEATURES`
4332statement for the image. When you remove this feature, you are removing
4333the package manager as well as its dependencies from the root
4334filesystem.
4335
4336Look for Other Ways to Minimize Size
4337~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4338
4339Depending on your particular circumstances, other areas that you can
4340trim likely exist. The key to finding these areas is through tools and
4341methods described here combined with experimentation and iteration. Here
4342are a couple of areas to experiment with:
4343
4344- ``glibc``: In general, follow this process:
4345
4346 1. Remove ``glibc`` features from
4347 :term:`DISTRO_FEATURES`
4348 that you think you do not need.
4349
4350 2. Build your distribution.
4351
4352 3. If the build fails due to missing symbols in a package, determine
4353 if you can reconfigure the package to not need those features. For
4354 example, change the configuration to not support wide character
4355 support as is done for ``ncurses``. Or, if support for those
4356 characters is needed, determine what ``glibc`` features provide
4357 the support and restore the configuration.
4358
4359 4. Rebuild and repeat the process.
4360
4361- ``busybox``: For BusyBox, use a process similar as described for
4362 ``glibc``. A difference is you will need to boot the resulting system
4363 to see if you are able to do everything you expect from the running
4364 system. You need to be sure to integrate configuration fragments into
4365 Busybox because BusyBox handles its own core features and then allows
4366 you to add configuration fragments on top.
4367
4368Iterate on the Process
4369~~~~~~~~~~~~~~~~~~~~~~
4370
4371If you have not reached your goals on system size, you need to iterate
4372on the process. The process is the same. Use the tools and see just what
4373is taking up 90% of the root filesystem and the kernel. Decide what you
4374can eliminate without limiting your device beyond what you need.
4375
4376Depending on your system, a good place to look might be Busybox, which
4377provides a stripped down version of Unix tools in a single, executable
4378file. You might be able to drop virtual terminal services or perhaps
4379ipv6.
4380
4381Building Images for More than One Machine
4382-----------------------------------------
4383
4384A common scenario developers face is creating images for several
4385different machines that use the same software environment. In this
4386situation, it is tempting to set the tunings and optimization flags for
4387each build specifically for the targeted hardware (i.e. "maxing out" the
4388tunings). Doing so can considerably add to build times and package feed
4389maintenance collectively for the machines. For example, selecting tunes
4390that are extremely specific to a CPU core used in a system might enable
4391some micro optimizations in GCC for that particular system but would
4392otherwise not gain you much of a performance difference across the other
4393systems as compared to using a more general tuning across all the builds
4394(e.g. setting :term:`DEFAULTTUNE`
4395specifically for each machine's build). Rather than "max out" each
4396build's tunings, you can take steps that cause the OpenEmbedded build
4397system to reuse software across the various machines where it makes
4398sense.
4399
4400If build speed and package feed maintenance are considerations, you
4401should consider the points in this section that can help you optimize
4402your tunings to best consider build times and package feed maintenance.
4403
4404- *Share the Build Directory:* If at all possible, share the
4405 :term:`TMPDIR` across builds. The
4406 Yocto Project supports switching between different
4407 :term:`MACHINE` values in the same
4408 ``TMPDIR``. This practice is well supported and regularly used by
4409 developers when building for multiple machines. When you use the same
4410 ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
4411 can reuse the existing native and often cross-recipes for multiple
4412 machines. Thus, build time decreases.
4413
4414 .. note::
4415
4416 If :term:`DISTRO` settings change or fundamental configuration settings
4417 such as the filesystem layout, you need to work with a clean ``TMPDIR``.
4418 Sharing ``TMPDIR`` under these circumstances might work but since it is
4419 not guaranteed, you should use a clean ``TMPDIR``.
4420
4421- *Enable the Appropriate Package Architecture:* By default, the
4422 OpenEmbedded build system enables three levels of package
4423 architectures: "all", "tune" or "package", and "machine". Any given
4424 recipe usually selects one of these package architectures (types) for
4425 its output. Depending for what a given recipe creates packages,
4426 making sure you enable the appropriate package architecture can
4427 directly impact the build time.
4428
4429 A recipe that just generates scripts can enable "all" architecture
4430 because there are no binaries to build. To specifically enable "all"
4431 architecture, be sure your recipe inherits the
4432 :ref:`allarch <ref-classes-allarch>` class.
4433 This class is useful for "all" architectures because it configures
4434 many variables so packages can be used across multiple architectures.
4435
4436 If your recipe needs to generate packages that are machine-specific
4437 or when one of the build or runtime dependencies is already
4438 machine-architecture dependent, which makes your recipe also
4439 machine-architecture dependent, make sure your recipe enables the
4440 "machine" package architecture through the
4441 :term:`MACHINE_ARCH`
4442 variable:
4443 ::
4444
4445 PACKAGE_ARCH = "${MACHINE_ARCH}"
4446
4447 When you do not
4448 specifically enable a package architecture through the
4449 :term:`PACKAGE_ARCH`, The
4450 OpenEmbedded build system defaults to the
4451 :term:`TUNE_PKGARCH` setting:
4452 ::
4453
4454 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4455
4456- *Choose a Generic Tuning File if Possible:* Some tunes are more
4457 generic and can run on multiple targets (e.g. an ``armv5`` set of
4458 packages could run on ``armv6`` and ``armv7`` processors in most
4459 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4460 higher processors. You should realize, however, that advances on
4461 newer processor versions would not be used.
4462
4463 If you select the same tune for several different machines, the
4464 OpenEmbedded build system reuses software previously built, thus
4465 speeding up the overall build time. Realize that even though a new
4466 sysroot for each machine is generated, the software is not recompiled
4467 and only one package feed exists.
4468
4469- *Manage Granular Level Packaging:* Sometimes cases exist where
4470 injecting another level of package architecture beyond the three
4471 higher levels noted earlier can be useful. For example, consider how
4472 NXP (formerly Freescale) allows for the easy reuse of binary packages
4473 in their layer
4474 :yocto_git:`meta-freescale </cgit/cgit.cgi/meta-freescale/>`.
4475 In this example, the
4476 :yocto_git:`fsl-dynamic-packagearch </cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
4477 class shares GPU packages for i.MX53 boards because all boards share
4478 the AMD GPU. The i.MX6-based boards can do the same because all
4479 boards share the Vivante GPU. This class inspects the BitBake
4480 datastore to identify if the package provides or depends on one of
4481 the sub-architecture values. If so, the class sets the
4482 :term:`PACKAGE_ARCH` value
4483 based on the ``MACHINE_SUBARCH`` value. If the package does not
4484 provide or depend on one of the sub-architecture values but it
4485 matches a value in the machine-specific filter, it sets
4486 :term:`MACHINE_ARCH`. This
4487 behavior reduces the number of packages built and saves build time by
4488 reusing binaries.
4489
4490- *Use Tools to Debug Issues:* Sometimes you can run into situations
4491 where software is being rebuilt when you think it should not be. For
4492 example, the OpenEmbedded build system might not be using shared
4493 state between machines when you think it should be. These types of
4494 situations are usually due to references to machine-specific
4495 variables such as :term:`MACHINE`,
4496 :term:`SERIAL_CONSOLES`,
4497 :term:`XSERVER`,
4498 :term:`MACHINE_FEATURES`,
4499 and so forth in code that is supposed to only be tune-specific or
4500 when the recipe depends
4501 (:term:`DEPENDS`,
4502 :term:`RDEPENDS`,
4503 :term:`RRECOMMENDS`,
4504 :term:`RSUGGESTS`, and so forth)
4505 on some other recipe that already has
4506 :term:`PACKAGE_ARCH` defined
4507 as "${MACHINE_ARCH}".
4508
4509 .. note::
4510
4511 Patches to fix any issues identified are most welcome as these
4512 issues occasionally do occur.
4513
4514 For such cases, you can use some tools to help you sort out the
4515 situation:
4516
4517 - ``state-diff-machines.sh``*:* You can find this tool in the
4518 ``scripts`` directory of the Source Repositories. See the comments
4519 in the script for information on how to use the tool.
4520
4521 - *BitBake's "-S printdiff" Option:* Using this option causes
4522 BitBake to try to establish the closest signature match it can
4523 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4524 over the matches to determine the stamps and delta where these two
4525 stamp trees diverge.
4526
4527Building Software from an External Source
4528-----------------------------------------
4529
4530By default, the OpenEmbedded build system uses the
4531:term:`Build Directory` when building source
4532code. The build process involves fetching the source files, unpacking
4533them, and then patching them if necessary before the build takes place.
4534
4535Situations exist where you might want to build software from source
4536files that are external to and thus outside of the OpenEmbedded build
4537system. For example, suppose you have a project that includes a new BSP
4538with a heavily customized kernel. And, you want to minimize exposing the
4539build system to the development team so that they can focus on their
4540project and maintain everyone's workflow as much as possible. In this
4541case, you want a kernel source directory on the development machine
4542where the development occurs. You want the recipe's
4543:term:`SRC_URI` variable to point to
4544the external directory and use it as is, not copy it.
4545
4546To build from software that comes from an external source, all you need
4547to do is inherit the
4548:ref:`externalsrc <ref-classes-externalsrc>` class
4549and then set the
4550:term:`EXTERNALSRC` variable to
4551point to your external source code. Here are the statements to put in
4552your ``local.conf`` file:
4553::
4554
4555 INHERIT += "externalsrc"
4556 EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
4557
4558This next example shows how to accomplish the same thing by setting
4559``EXTERNALSRC`` in the recipe itself or in the recipe's append file:
4560::
4561
4562 EXTERNALSRC = "path"
4563 EXTERNALSRC_BUILD = "path"
4564
4565.. note::
4566
4567 In order for these settings to take effect, you must globally or
4568 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
4569 class.
4570
4571By default, ``externalsrc.bbclass`` builds the source code in a
4572directory separate from the external source directory as specified by
4573:term:`EXTERNALSRC`. If you need
4574to have the source built in the same directory in which it resides, or
4575some other nominated directory, you can set
4576:term:`EXTERNALSRC_BUILD`
4577to point to that directory:
4578::
4579
4580 EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
4581
4582Replicating a Build Offline
4583---------------------------
4584
4585It can be useful to take a "snapshot" of upstream sources used in a
4586build and then use that "snapshot" later to replicate the build offline.
4587To do so, you need to first prepare and populate your downloads
4588directory your "snapshot" of files. Once your downloads directory is
4589ready, you can use it at any time and from any machine to replicate your
4590build.
4591
4592Follow these steps to populate your Downloads directory:
4593
45941. *Create a Clean Downloads Directory:* Start with an empty downloads
4595 directory (:term:`DL_DIR`). You
4596 start with an empty downloads directory by either removing the files
4597 in the existing directory or by setting ``DL_DIR`` to point to either
4598 an empty location or one that does not yet exist.
4599
46002. *Generate Tarballs of the Source Git Repositories:* Edit your
4601 ``local.conf`` configuration file as follows:
4602 ::
4603
4604 DL_DIR = "/home/your-download-dir/"
4605 BB_GENERATE_MIRROR_TARBALLS = "1"
4606
4607 During
4608 the fetch process in the next step, BitBake gathers the source files
4609 and creates tarballs in the directory pointed to by ``DL_DIR``. See
4610 the
4611 :term:`BB_GENERATE_MIRROR_TARBALLS`
4612 variable for more information.
4613
46143. *Populate Your Downloads Directory Without Building:* Use BitBake to
4615 fetch your sources but inhibit the build:
4616 ::
4617
4618 $ bitbake target --runonly=fetch
4619
4620 The downloads directory (i.e. ``${DL_DIR}``) now has
4621 a "snapshot" of the source files in the form of tarballs, which can
4622 be used for the build.
4623
46244. *Optionally Remove Any Git or other SCM Subdirectories From the
4625 Downloads Directory:* If you want, you can clean up your downloads
4626 directory by removing any Git or other Source Control Management
4627 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4628 already contain these subdirectories.
4629
4630Once your downloads directory has everything it needs regarding source
4631files, you can create your "own-mirror" and build your target.
4632Understand that you can use the files to build the target offline from
4633any machine and at any time.
4634
4635Follow these steps to build your target using the files in the downloads
4636directory:
4637
46381. *Using Local Files Only:* Inside your ``local.conf`` file, add the
4639 :term:`SOURCE_MIRROR_URL`
4640 variable, inherit the
4641 :ref:`own-mirrors <ref-classes-own-mirrors>`
4642 class, and use the
4643 :term:`bitbake:BB_NO_NETWORK`
4644 variable to your ``local.conf``.
4645 ::
4646
4647 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4648 INHERIT += "own-mirrors"
4649 BB_NO_NETWORK = "1"
4650
4651 The ``SOURCE_MIRROR_URL`` and ``own-mirror``
4652 class set up the system to use the downloads directory as your "own
4653 mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
4654 BitBake's fetching process in step 3 stays local, which means files
4655 from your "own-mirror" are used.
4656
46572. *Start With a Clean Build:* You can start with a clean build by
4658 removing the
4659 ``${``\ :term:`TMPDIR`\ ``}``
4660 directory or using a new :term:`Build Directory`.
4661
46623. *Build Your Target:* Use BitBake to build your target:
4663 ::
4664
4665 $ bitbake target
4666
4667 The build completes using the known local "snapshot" of source
4668 files from your mirror. The resulting tarballs for your "snapshot" of
4669 source files are in the downloads directory.
4670
4671 .. note::
4672
4673 The offline build does not work if recipes attempt to find the
4674 latest version of software by setting
4675 :term:`SRCREV` to
4676 ``${``\ :term:`AUTOREV`\ ``}``:
4677 ::
4678
4679 SRCREV = "${AUTOREV}"
4680
4681 When a recipe sets ``SRCREV`` to
4682 ``${AUTOREV}``, the build system accesses the network in an
4683 attempt to determine the latest version of software from the SCM.
4684 Typically, recipes that use ``AUTOREV`` are custom or modified
4685 recipes. Recipes that reside in public repositories usually do not
4686 use ``AUTOREV``.
4687
4688 If you do have recipes that use ``AUTOREV``, you can take steps to
4689 still use the recipes in an offline build. Do the following:
4690
4691 1. Use a configuration generated by enabling `build
4692 history <#maintaining-build-output-quality>`__.
4693
4694 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
4695 stored ``SRCREV`` values from the build's history. For more
4696 information on collecting these values, see the "`Build History
4697 Package Information <#build-history-package-information>`__"
4698 section.
4699
4700 3. Once you have the correct source revisions, you can modify
4701 those recipes to to set ``SRCREV`` to specific versions of the
4702 software.
4703
4704Speeding Up a Build
4705===================
4706
4707Build time can be an issue. By default, the build system uses simple
4708controls to try and maximize build efficiency. In general, the default
4709settings for all the following variables result in the most efficient
4710build times when dealing with single socket systems (i.e. a single CPU).
4711If you have multiple CPUs, you might try increasing the default values
4712to gain more speed. See the descriptions in the glossary for each
4713variable for more information:
4714
4715- :term:`BB_NUMBER_THREADS`:
4716 The maximum number of threads BitBake simultaneously executes.
4717
4718- :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
4719 The number of threads BitBake uses during parsing.
4720
4721- :term:`PARALLEL_MAKE`: Extra
4722 options passed to the ``make`` command during the
4723 :ref:`ref-tasks-compile` task in
4724 order to specify parallel compilation on the local build host.
4725
4726- :term:`PARALLEL_MAKEINST`:
4727 Extra options passed to the ``make`` command during the
4728 :ref:`ref-tasks-install` task in
4729 order to specify parallel installation on the local build host.
4730
4731As mentioned, these variables all scale to the number of processor cores
4732available on the build system. For single socket systems, this
4733auto-scaling ensures that the build system fundamentally takes advantage
4734of potential parallel operations during the build based on the build
4735machine's capabilities.
4736
4737Following are additional factors that can affect build speed:
4738
4739- File system type: The file system type that the build is being
4740 performed on can also influence performance. Using ``ext4`` is
4741 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4742 improved features such as extents.
4743
4744- Disabling the updating of access time using ``noatime``: The
4745 ``noatime`` mount option prevents the build system from updating file
4746 and directory access times.
4747
4748- Setting a longer commit: Using the "commit=" mount option increases
4749 the interval in seconds between disk cache writes. Changing this
4750 interval from the five second default to something longer increases
4751 the risk of data loss but decreases the need to write to the disk,
4752 thus increasing the build performance.
4753
4754- Choosing the packaging backend: Of the available packaging backends,
4755 IPK is the fastest. Additionally, selecting a singular packaging
4756 backend also helps.
4757
4758- Using ``tmpfs`` for :term:`TMPDIR`
4759 as a temporary file system: While this can help speed up the build,
4760 the benefits are limited due to the compiler using ``-pipe``. The
4761 build system goes to some lengths to avoid ``sync()`` calls into the
4762 file system on the principle that if there was a significant failure,
4763 the :term:`Build Directory`
4764 contents could easily be rebuilt.
4765
4766- Inheriting the
4767 :ref:`rm_work <ref-classes-rm-work>` class:
4768 Inheriting this class has shown to speed up builds due to
4769 significantly lower amounts of data stored in the data cache as well
4770 as on disk. Inheriting this class also makes cleanup of
4771 :term:`TMPDIR` faster, at the
4772 expense of being easily able to dive into the source code. File
4773 system maintainers have recommended that the fastest way to clean up
4774 large numbers of files is to reformat partitions rather than delete
4775 files due to the linear nature of partitions. This, of course,
4776 assumes you structure the disk partitions and file systems in a way
4777 that this is practical.
4778
4779Aside from the previous list, you should keep some trade offs in mind
4780that can help you speed up the build:
4781
4782- Remove items from
4783 :term:`DISTRO_FEATURES`
4784 that you might not need.
4785
4786- Exclude debug symbols and other debug information: If you do not need
4787 these symbols and other debug information, disabling the ``*-dbg``
4788 package generation can speed up the build. You can disable this
4789 generation by setting the
4790 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4791 variable to "1".
4792
4793- Disable static library generation for recipes derived from
4794 ``autoconf`` or ``libtool``: Following is an example showing how to
4795 disable static libraries and still provide an override to handle
4796 exceptions:
4797 ::
4798
4799 STATICLIBCONF = "--disable-static"
4800 STATICLIBCONF_sqlite3-native = ""
4801 EXTRA_OECONF += "${STATICLIBCONF}"
4802
4803 .. note::
4804
4805 - Some recipes need static libraries in order to work correctly
4806 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4807 as in the previous example, account for these kinds of
4808 exceptions.
4809
4810 - Some packages have packaging code that assumes the presence of
4811 the static libraries. If so, you might need to exclude them as
4812 well.
4813
4814.. _platdev-working-with-libraries:
4815
4816Working With Libraries
4817======================
4818
4819Libraries are an integral part of your system. This section describes
4820some common practices you might find helpful when working with libraries
4821to build your system:
4822
4823- `How to include static library
4824 files <#including-static-library-files>`__
4825
4826- `How to use the Multilib feature to combine multiple versions of
4827 library files into a single
4828 image <#combining-multiple-versions-library-files-into-one-image>`__
4829
4830- `How to install multiple versions of the same library in parallel on
4831 the same
4832 system <#installing-multiple-versions-of-the-same-library>`__
4833
4834Including Static Library Files
4835------------------------------
4836
4837If you are building a library and the library offers static linking, you
4838can control which static library files (``*.a`` files) get included in
4839the built library.
4840
4841The :term:`PACKAGES` and
4842:term:`FILES_* <FILES>` variables in the
4843``meta/conf/bitbake.conf`` configuration file define how files installed
4844by the ``do_install`` task are packaged. By default, the ``PACKAGES``
4845variable includes ``${PN}-staticdev``, which represents all static
4846library files.
4847
4848.. note::
4849
4850 Some previously released versions of the Yocto Project defined the
4851 static library files through ``${PN}-dev``.
4852
4853Following is part of the BitBake configuration file, where you can see
4854how the static library files are defined:
4855::
4856
4857 PACKAGE_BEFORE_PN ?= ""
4858 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
4859 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4860 FILES = ""
4861
4862 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
4863 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4864 ${base_bindir}/* ${base_sbindir}/* \
4865 ${base_libdir}/*${SOLIBS} \
4866 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
4867 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4868 ${datadir}/pixmaps ${datadir}/applications \
4869 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4870 ${libdir}/bonobo/servers"
4871
4872 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
4873
4874 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
4875 ${datadir}/gnome/help"
4876 SECTION_${PN}-doc = "doc"
4877
4878 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
4879 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
4880 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4881 ${datadir}/aclocal ${base_libdir}/*.o \
4882 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
4883 SECTION_${PN}-dev = "devel"
4884 ALLOW_EMPTY_${PN}-dev = "1"
4885 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
4886
4887 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4888 SECTION_${PN}-staticdev = "devel"
4889 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
4890
4891.. _combining-multiple-versions-library-files-into-one-image:
4892
4893Combining Multiple Versions of Library Files into One Image
4894-----------------------------------------------------------
4895
4896The build system offers the ability to build libraries with different
4897target optimizations or architecture formats and combine these together
4898into one system image. You can link different binaries in the image
4899against the different libraries as needed for specific use cases. This
4900feature is called "Multilib".
4901
4902An example would be where you have most of a system compiled in 32-bit
4903mode using 32-bit libraries, but you have something large, like a
4904database engine, that needs to be a 64-bit application and uses 64-bit
4905libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4906libraries.
4907
4908While the Multilib feature is most commonly used for 32 and 64-bit
4909differences, the approach the build system uses facilitates different
4910target optimizations. You could compile some binaries to use one set of
4911libraries and other binaries to use a different set of libraries. The
4912libraries could differ in architecture, compiler options, or other
4913optimizations.
4914
4915Several examples exist in the ``meta-skeleton`` layer found in the
4916:term:`Source Directory`:
4917
4918- ``conf/multilib-example.conf`` configuration file
4919
4920- ``conf/multilib-example2.conf`` configuration file
4921
4922- ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
4923
4924Preparing to Use Multilib
4925~~~~~~~~~~~~~~~~~~~~~~~~~
4926
4927User-specific requirements drive the Multilib feature. Consequently,
4928there is no one "out-of-the-box" configuration that likely exists to
4929meet your needs.
4930
4931In order to enable Multilib, you first need to ensure your recipe is
4932extended to support multiple libraries. Many standard recipes are
4933already extended and support multiple libraries. You can check in the
4934``meta/conf/multilib.conf`` configuration file in the
4935:term:`Source Directory` to see how this is
4936done using the
4937:term:`BBCLASSEXTEND` variable.
4938Eventually, all recipes will be covered and this list will not be
4939needed.
4940
4941For the most part, the Multilib class extension works automatically to
4942extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
4943``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
4944Standard variables such as
4945:term:`DEPENDS`,
4946:term:`RDEPENDS`,
4947:term:`RPROVIDES`,
4948:term:`RRECOMMENDS`,
4949:term:`PACKAGES`, and
4950:term:`PACKAGES_DYNAMIC` are
4951automatically extended by the system. If you are extending any manual
4952code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
4953those names are extended correctly. This automatic extension code
4954resides in ``multilib.bbclass``.
4955
4956Using Multilib
4957~~~~~~~~~~~~~~
4958
4959After you have set up the recipes, you need to define the actual
4960combination of multiple libraries you want to build. You accomplish this
4961through your ``local.conf`` configuration file in the
4962:term:`Build Directory`. An example
4963configuration would be as follows:
4964::
4965
4966 MACHINE = "qemux86-64"
4967 require conf/multilib.conf
4968 MULTILIBS = "multilib:lib32"
4969 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
4970 IMAGE_INSTALL_append = "lib32-glib-2.0"
4971
4972This example enables an additional library named
4973``lib32`` alongside the normal target packages. When combining these
4974"lib32" alternatives, the example uses "x86" for tuning. For information
4975on this particular tuning, see
4976``meta/conf/machine/include/ia32/arch-ia32.inc``.
4977
4978The example then includes ``lib32-glib-2.0`` in all the images, which
4979illustrates one method of including a multiple library dependency. You
4980can use a normal image build to include this dependency, for example:
4981::
4982
4983 $ bitbake core-image-sato
4984
4985You can also build Multilib packages
4986specifically with a command like this:
4987::
4988
4989 $ bitbake lib32-glib-2.0
4990
4991Additional Implementation Details
4992~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4993
4994Generic implementation details as well as details that are specific to
4995package management systems exist. Following are implementation details
4996that exist regardless of the package management system:
4997
4998- The typical convention used for the class extension code as used by
4999 Multilib assumes that all package names specified in
5000 :term:`PACKAGES` that contain
5001 ``${PN}`` have ``${PN}`` at the start of the name. When that
5002 convention is not followed and ``${PN}`` appears at the middle or the
5003 end of a name, problems occur.
5004
5005- The :term:`TARGET_VENDOR`
5006 value under Multilib will be extended to "-vendormlmultilib" (e.g.
5007 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
5008 slightly unwieldy contraction is that any "-" characters in the
5009 vendor string presently break Autoconf's ``config.sub``, and other
5010 separators are problematic for different reasons.
5011
5012For the RPM Package Management System, the following implementation
5013details exist:
5014
5015- A unique architecture is defined for the Multilib packages, along
5016 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
5017 :term:`Build Directory`. For
5018 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
5019 architectures in the system are "all", "qemux86_64",
5020 "lib32_qemux86_64", and "lib32_x86".
5021
5022- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
5023 packaging. The naming for a normal RPM package and a Multilib RPM
5024 package in a ``qemux86-64`` system resolves to something similar to
5025 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
5026 respectively.
5027
5028- When installing a Multilib image, the RPM backend first installs the
5029 base image and then installs the Multilib libraries.
5030
5031- The build system relies on RPM to resolve the identical files in the
5032 two (or more) Multilib packages.
5033
5034For the IPK Package Management System, the following implementation
5035details exist:
5036
5037- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
5038 packaging. The naming for a normal RPM package and a Multilib IPK
5039 package in a ``qemux86-64`` system resolves to something like
5040 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
5041 respectively.
5042
5043- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
5044 packages with and without the Multilib feature can exist in the same
5045 folder due to the ``${PN}`` differences.
5046
5047- IPK defines a sanity check for Multilib installation using certain
5048 rules for file comparison, overridden, etc.
5049
5050Installing Multiple Versions of the Same Library
5051------------------------------------------------
5052
5053Situations can exist where you need to install and use multiple versions
5054of the same library on the same system at the same time. These
5055situations almost always exist when a library API changes and you have
5056multiple pieces of software that depend on the separate versions of the
5057library. To accommodate these situations, you can install multiple
5058versions of the same library in parallel on the same system.
5059
5060The process is straightforward as long as the libraries use proper
5061versioning. With properly versioned libraries, all you need to do to
5062individually specify the libraries is create separate, appropriately
5063named recipes where the :term:`PN` part of
5064the name includes a portion that differentiates each library version
5065(e.g. the major part of the version number). Thus, instead of having a
5066single recipe that loads one version of a library (e.g. ``clutter``),
5067you provide multiple recipes that result in different versions of the
5068libraries you want. As an example, the following two recipes would allow
5069the two separate versions of the ``clutter`` library to co-exist on the
5070same system:
5071
5072.. code-block:: none
5073
5074 clutter-1.6_1.6.20.bb
5075 clutter-1.8_1.8.4.bb
5076
5077Additionally, if
5078you have other recipes that depend on a given library, you need to use
5079the :term:`DEPENDS` variable to
5080create the dependency. Continuing with the same example, if you want to
5081have a recipe depend on the 1.8 version of the ``clutter`` library, use
5082the following in your recipe:
5083::
5084
5085 DEPENDS = "clutter-1.8"
5086
5087Using x32 psABI
5088===============
5089
5090x32 processor-specific Application Binary Interface (`x32
5091psABI <https://software.intel.com/en-us/node/628948>`__) is a native
509232-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
5093ABI defines the calling conventions between functions in a processing
5094environment. The interface determines what registers are used and what
5095the sizes are for various C data types.
5096
5097Some processing environments prefer using 32-bit applications even when
5098running on Intel 64-bit platforms. Consider the i386 psABI, which is a
5099very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
5100provide efficient use and access of the Intel 64-bit processor
5101resources, leaving the system underutilized. Now consider the x86_64
5102psABI. This ABI is newer and uses 64-bits for data sizes and program
5103pointers. The extra bits increase the footprint size of the programs,
5104libraries, and also increases the memory and file system size
5105requirements. Executing under the x32 psABI enables user programs to
5106utilize CPU and system resources more efficiently while keeping the
5107memory footprint of the applications low. Extra bits are used for
5108registers but not for addressing mechanisms.
5109
5110The Yocto Project supports the final specifications of x32 psABI as
5111follows:
5112
5113- You can create packages and images in x32 psABI format on x86_64
5114 architecture targets.
5115
5116- You can successfully build recipes with the x32 toolchain.
5117
5118- You can create and boot ``core-image-minimal`` and
5119 ``core-image-sato`` images.
5120
5121- RPM Package Manager (RPM) support exists for x32 binaries.
5122
5123- Support for large images exists.
5124
5125To use the x32 psABI, you need to edit your ``conf/local.conf``
5126configuration file as follows:
5127::
5128
5129 MACHINE = "qemux86-64"
5130 DEFAULTTUNE = "x86-64-x32"
5131 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
5132 or 'INVALID')) or 'lib'}"
5133
5134Once you have set
5135up your configuration file, use BitBake to build an image that supports
5136the x32 psABI. Here is an example:
5137::
5138
5139 $ bitbake core-image-sato
5140
5141Enabling GObject Introspection Support
5142======================================
5143
5144`GObject
5145introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
5146is the standard mechanism for accessing GObject-based software from
5147runtime environments. GObject is a feature of the GLib library that
5148provides an object framework for the GNOME desktop and related software.
5149GObject Introspection adds information to GObject that allows objects
5150created within it to be represented across different programming
5151languages. If you want to construct GStreamer pipelines using Python, or
5152control UPnP infrastructure using Javascript and GUPnP, GObject
5153introspection is the only way to do it.
5154
5155This section describes the Yocto Project support for generating and
5156packaging GObject introspection data. GObject introspection data is a
5157description of the API provided by libraries built on top of GLib
5158framework, and, in particular, that framework's GObject mechanism.
5159GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5160``typelib`` files go to main packages as they are packaged together with
5161libraries that are introspected.
5162
5163The data is generated when building such a library, by linking the
5164library with a small executable binary that asks the library to describe
5165itself, and then executing the binary and processing its output.
5166
5167Generating this data in a cross-compilation environment is difficult
5168because the library is produced for the target architecture, but its
5169code needs to be executed on the build host. This problem is solved with
5170the OpenEmbedded build system by running the code through QEMU, which
5171allows precisely that. Unfortunately, QEMU does not always work
5172perfectly as mentioned in the "`Known Issues <#known-issues>`__"
5173section.
5174
5175Enabling the Generation of Introspection Data
5176---------------------------------------------
5177
5178Enabling the generation of introspection data (GIR files) in your
5179library package involves the following:
5180
51811. Inherit the
5182 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5183 class.
5184
51852. Make sure introspection is not disabled anywhere in the recipe or
5186 from anything the recipe includes. Also, make sure that
5187 "gobject-introspection-data" is not in
5188 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5189 and that "qemu-usermode" is not in
5190 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5191 If either of these conditions exist, nothing will happen.
5192
51933. Try to build the recipe. If you encounter build errors that look like
5194 something is unable to find ``.so`` libraries, check where these
5195 libraries are located in the source tree and add the following to the
5196 recipe:
5197 ::
5198
5199 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5200
5201 .. note::
5202
5203 See recipes in the ``oe-core`` repository that use that
5204 ``GIR_EXTRA_LIBS_PATH`` variable as an example.
5205
52064. Look for any other errors, which probably mean that introspection
5207 support in a package is not entirely standard, and thus breaks down
5208 in a cross-compilation environment. For such cases, custom-made fixes
5209 are needed. A good place to ask and receive help in these cases is
5210 the :ref:`Yocto Project mailing
5211 lists <resources-mailinglist>`.
5212
5213.. note::
5214
5215 Using a library that no longer builds against the latest Yocto
5216 Project release and prints introspection related errors is a good
5217 candidate for the previous procedure.
5218
5219Disabling the Generation of Introspection Data
5220----------------------------------------------
5221
5222You might find that you do not want to generate introspection data. Or,
5223perhaps QEMU does not work on your build host and target architecture
5224combination. If so, you can use either of the following methods to
5225disable GIR file generations:
5226
5227- Add the following to your distro configuration:
5228 ::
5229
5230 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5231
5232 Adding this statement disables generating introspection data using
5233 QEMU but will still enable building introspection tools and libraries
5234 (i.e. building them does not require the use of QEMU).
5235
5236- Add the following to your machine configuration:
5237 ::
5238
5239 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5240
5241 Adding this statement disables the use of QEMU when building packages for your
5242 machine. Currently, this feature is used only by introspection
5243 recipes and has the same effect as the previously described option.
5244
5245 .. note::
5246
5247 Future releases of the Yocto Project might have other features
5248 affected by this option.
5249
5250If you disable introspection data, you can still obtain it through other
5251means such as copying the data from a suitable sysroot, or by generating
5252it on the target hardware. The OpenEmbedded build system does not
5253currently provide specific support for these techniques.
5254
5255Testing that Introspection Works in an Image
5256--------------------------------------------
5257
5258Use the following procedure to test if generating introspection data is
5259working in an image:
5260
52611. Make sure that "gobject-introspection-data" is not in
5262 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5263 and that "qemu-usermode" is not in
5264 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5265
52662. Build ``core-image-sato``.
5267
52683. Launch a Terminal and then start Python in the terminal.
5269
52704. Enter the following in the terminal:
5271 ::
5272
5273 >>> from gi.repository import GLib
5274 >>> GLib.get_host_name()
5275
52765. For something a little more advanced, enter the following see:
5277 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
5278
5279Known Issues
5280------------
5281
5282The following know issues exist for GObject Introspection Support:
5283
5284- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5285 introspection data on that architecture.
5286
5287- x32 is not supported by QEMU. Consequently, introspection data is
5288 disabled.
5289
5290- musl causes transient GLib binaries to crash on assertion failures.
5291 Consequently, generating introspection data is disabled.
5292
5293- Because QEMU is not able to run the binaries correctly, introspection
5294 is disabled for some specific packages under specific architectures
5295 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5296
5297- QEMU usermode might not work properly when running 64-bit binaries
5298 under 32-bit host machines. In particular, "qemumips64" is known to
5299 not work under i686.
5300
5301.. _dev-optionally-using-an-external-toolchain:
5302
5303Optionally Using an External Toolchain
5304======================================
5305
5306You might want to use an external toolchain as part of your development.
5307If this is the case, the fundamental steps you need to accomplish are as
5308follows:
5309
5310- Understand where the installed toolchain resides. For cases where you
5311 need to build the external toolchain, you would need to take separate
5312 steps to build and install the toolchain.
5313
5314- Make sure you add the layer that contains the toolchain to your
5315 ``bblayers.conf`` file through the
5316 :term:`BBLAYERS` variable.
5317
5318- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5319 to the location in which you installed the toolchain.
5320
5321A good example of an external toolchain used with the Yocto Project is
5322Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5323to use that particular layer in the ``README`` file at
5324https://github.com/MentorEmbedded/meta-sourcery/. You can find
5325further information by reading about the
5326:term:`TCMODE` variable in the Yocto
5327Project Reference Manual's variable glossary.
5328
5329Creating Partitioned Images Using Wic
5330=====================================
5331
5332Creating an image for a particular hardware target using the
5333OpenEmbedded build system does not necessarily mean you can boot that
5334image as is on your device. Physical devices accept and boot images in
5335various ways depending on the specifics of the device. Usually,
5336information about the hardware can tell you what image format the device
5337requires. Should your device require multiple partitions on an SD card,
5338flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5339create the properly partitioned image.
5340
5341The ``wic`` command generates partitioned images from existing
5342OpenEmbedded build artifacts. Image generation is driven by partitioning
5343commands contained in an Openembedded kickstart file (``.wks``)
5344specified either directly on the command line or as one of a selection
5345of canned kickstart files as shown with the ``wic list images`` command
5346in the "`Using an Existing Kickstart
5347File <#using-a-provided-kickstart-file>`__" section. When you apply the
5348command to a given set of build artifacts, the result is an image or set
5349of images that can be directly written onto media and used on a
5350particular system.
5351
5352.. note::
5353
5354 For a kickstart file reference, see the
5355 ":ref:`ref-manual/ref-kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
5356 Chapter in the Yocto Project Reference Manual.
5357
5358The ``wic`` command and the infrastructure it is based on is by
5359definition incomplete. The purpose of the command is to allow the
5360generation of customized images, and as such, was designed to be
5361completely extensible through a plugin interface. See the "`Using the
5362Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section
5363for information on these plugins.
5364
5365This section provides some background information on Wic, describes what
5366you need to have in place to run the tool, provides instruction on how
5367to use the Wic utility, provides information on using the Wic plugins
5368interface, and provides several examples that show how to use Wic.
5369
5370.. _wic-background:
5371
5372Background
5373----------
5374
5375This section provides some background on the Wic utility. While none of
5376this information is required to use Wic, you might find it interesting.
5377
5378- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5379 "oe" diphthong in "oeic" was promoted to the letter "w", because
5380 "oeic" is both difficult to remember and to pronounce.
5381
5382- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5383 The Wic implementation has been heavily modified to make direct use
5384 of OpenEmbedded build artifacts instead of package installation and
5385 configuration, which are already incorporated within the OpenEmbedded
5386 artifacts.
5387
5388- Wic is a completely independent standalone utility that initially
5389 provides easier-to-use and more flexible replacements for an existing
5390 functionality in OE-Core's
5391 :ref:`image-live <ref-classes-image-live>`
5392 class. The difference between Wic and those examples is that with Wic
5393 the functionality of those scripts is implemented by a
5394 general-purpose partitioning language, which is based on Redhat
5395 kickstart syntax.
5396
5397.. _wic-requirements:
5398
5399Requirements
5400------------
5401
5402In order to use the Wic utility with the OpenEmbedded Build system, your
5403system needs to meet the following requirements:
5404
5405- The Linux distribution on your development host must support the
5406 Yocto Project. See the ":ref:`detailed-supported-distros`"
5407 section in the Yocto Project Reference Manual for the list of
5408 distributions that support the Yocto Project.
5409
5410- The standard system utilities, such as ``cp``, must be installed on
5411 your development host system.
5412
5413- You must have sourced the build environment setup script (i.e.
5414 :ref:`structure-core-script`) found in the
5415 :term:`Build Directory`.
5416
5417- You need to have the build artifacts already available, which
5418 typically means that you must have already created an image using the
5419 Openembedded build system (e.g. ``core-image-minimal``). While it
5420 might seem redundant to generate an image in order to create an image
5421 using Wic, the current version of Wic requires the artifacts in the
5422 form generated by the OpenEmbedded build system.
5423
5424- You must build several native tools, which are built to run on the
5425 build system:
5426 ::
5427
5428 $ bitbake parted-native dosfstools-native mtools-native
5429
5430- Include "wic" as part of the
5431 :term:`IMAGE_FSTYPES`
5432 variable.
5433
5434- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
5435 as part of the :term:`WKS_FILE` variable
5436
5437.. _wic-getting-help:
5438
5439Getting Help
5440------------
5441
5442You can get general help for the ``wic`` command by entering the ``wic``
5443command by itself or by entering the command with a help argument as
5444follows:
5445::
5446
5447 $ wic -h
5448 $ wic --help
5449 $ wic help
5450
5451Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5452``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
5453commands except "help" by using the following form:
5454::
5455
5456 $ wic help command
5457
5458For example, the following command returns help for the ``write``
5459command:
5460::
5461
5462 $ wic help write
5463
5464Wic supports help for three topics: ``overview``, ``plugins``, and
5465``kickstart``. You can get help for any topic using the following form:
5466::
5467
5468 $ wic help topic
5469
5470For example, the following returns overview help for Wic:
5471::
5472
5473 $ wic help overview
5474
5475One additional level of help exists for Wic. You can get help on
5476individual images through the ``list`` command. You can use the ``list``
5477command to return the available Wic images as follows:
5478::
5479
5480 $ wic list images
5481 genericx86 Create an EFI disk image for genericx86*
5482 beaglebone-yocto Create SD card image for Beaglebone
5483 edgerouter Create SD card image for Edgerouter
5484 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
5485 directdisk-gpt Create a 'pcbios' direct disk image
5486 mkefidisk Create an EFI disk image
5487 directdisk Create a 'pcbios' direct disk image
5488 systemd-bootdisk Create an EFI disk image with systemd-boot
5489 mkhybridiso Create a hybrid ISO image
5490 sdimage-bootpart Create SD card image with a boot partition
5491 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5492 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5493
5494Once you know the list of available
5495Wic images, you can use ``help`` with the command to get help on a
5496particular image. For example, the following command returns help on the
5497"beaglebone-yocto" image:
5498::
5499
5500 $ wic list beaglebone-yocto help
5501
5502 Creates a partitioned SD card image for Beaglebone.
5503 Boot files are located in the first vfat partition.
5504
5505Operational Modes
5506-----------------
5507
5508You can use Wic in two different modes, depending on how much control
5509you need for specifying the Openembedded build artifacts that are used
5510for creating the image: Raw and Cooked:
5511
5512- *Raw Mode:* You explicitly specify build artifacts through Wic
5513 command-line arguments.
5514
5515- *Cooked Mode:* The current
5516 :term:`MACHINE` setting and image
5517 name are used to automatically locate and provide the build
5518 artifacts. You just supply a kickstart file and the name of the image
5519 from which to use artifacts.
5520
5521Regardless of the mode you use, you need to have the build artifacts
5522ready and available.
5523
5524Raw Mode
5525~~~~~~~~
5526
5527Running Wic in raw mode allows you to specify all the partitions through
5528the ``wic`` command line. The primary use for raw mode is if you have
5529built your kernel outside of the Yocto Project
5530:term:`Build Directory`. In other words, you
5531can point to arbitrary kernel, root filesystem locations, and so forth.
5532Contrast this behavior with cooked mode where Wic looks in the Build
5533Directory (e.g. ``tmp/deploy/images/``\ machine).
5534
5535The general form of the ``wic`` command in raw mode is:
5536::
5537
5538 $ wic create wks_file options ...
5539
5540 Where:
5541
5542 wks_file:
5543 An OpenEmbedded kickstart file. You can provide
5544 your own custom file or use a file from a set of
5545 existing files as described by further options.
5546
5547 optional arguments:
5548 -h, --help show this help message and exit
5549 -o OUTDIR, --outdir OUTDIR
5550 name of directory to create image in
5551 -e IMAGE_NAME, --image-name IMAGE_NAME
5552 name of the image to use the artifacts from e.g. core-
5553 image-sato
5554 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5555 path to the /rootfs dir to use as the .wks rootfs
5556 source
5557 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5558 path to the dir containing the boot artifacts (e.g.
5559 /EFI or /syslinux dirs) to use as the .wks bootimg
5560 source
5561 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5562 path to the dir containing the kernel to use in the
5563 .wks bootimg
5564 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5565 path to the native sysroot containing the tools to use
5566 to build the image
5567 -s, --skip-build-check
5568 skip the build check
5569 -f, --build-rootfs build rootfs
5570 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5571 compress image with specified compressor
5572 -m, --bmap generate .bmap
5573 --no-fstab-update Do not change fstab file.
5574 -v VARS_DIR, --vars VARS_DIR
5575 directory with <image>.env files that store bitbake
5576 variables
5577 -D, --debug output debug information
5578
5579.. note::
5580
5581 You do not need root privileges to run Wic. In fact, you should not
5582 run as root when using the utility.
5583
5584Cooked Mode
5585~~~~~~~~~~~
5586
5587Running Wic in cooked mode leverages off artifacts in the Build
5588Directory. In other words, you do not have to specify kernel or root
5589filesystem locations as part of the command. All you need to provide is
5590a kickstart file and the name of the image from which to use artifacts
5591by using the "-e" option. Wic looks in the Build Directory (e.g.
5592``tmp/deploy/images/``\ machine) for artifacts.
5593
5594The general form of the ``wic`` command using Cooked Mode is as follows:
5595::
5596
5597 $ wic create wks_file -e IMAGE_NAME
5598
5599 Where:
5600
5601 wks_file:
5602 An OpenEmbedded kickstart file. You can provide
5603 your own custom file or use a file from a set of
5604 existing files provided with the Yocto Project
5605 release.
5606
5607 required argument:
5608 -e IMAGE_NAME, --image-name IMAGE_NAME
5609 name of the image to use the artifacts from e.g. core-
5610 image-sato
5611
5612.. _using-a-provided-kickstart-file:
5613
5614Using an Existing Kickstart File
5615--------------------------------
5616
5617If you do not want to create your own kickstart file, you can use an
5618existing file provided by the Wic installation. As shipped, kickstart
5619files can be found in the :ref:`overview-manual/overview-manual-development-environment:yocto project source repositories` in the
5620following two locations:
5621::
5622
5623 poky/meta-yocto-bsp/wic
5624 poky/scripts/lib/wic/canned-wks
5625
5626Use the following command to list the available kickstart files:
5627::
5628
5629 $ wic list images
5630 genericx86 Create an EFI disk image for genericx86*
5631 beaglebone-yocto Create SD card image for Beaglebone
5632 edgerouter Create SD card image for Edgerouter
5633 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
5634 directdisk-gpt Create a 'pcbios' direct disk image
5635 mkefidisk Create an EFI disk image
5636 directdisk Create a 'pcbios' direct disk image
5637 systemd-bootdisk Create an EFI disk image with systemd-boot
5638 mkhybridiso Create a hybrid ISO image
5639 sdimage-bootpart Create SD card image with a boot partition
5640 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5641 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5642
5643When you use an existing file, you
5644do not have to use the ``.wks`` extension. Here is an example in Raw
5645Mode that uses the ``directdisk`` file:
5646::
5647
5648 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5649 -k kernel_dir -n native_sysroot
5650
5651Here are the actual partition language commands used in the
5652``genericx86.wks`` file to generate an image:
5653::
5654
5655 # short-description: Create an EFI disk image for genericx86*
5656 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5657 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5658 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5659 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5660
5661 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5662
5663.. _wic-using-the-wic-plugin-interface:
5664
5665Using the Wic Plugin Interface
5666------------------------------
5667
5668You can extend and specialize Wic functionality by using Wic plugins.
5669This section explains the Wic plugin interface.
5670
5671.. note::
5672
5673 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5674 are beyond the scope of this section.
5675
5676Source plugins provide a mechanism to customize partition content during
5677the Wic image generation process. You can use source plugins to map
5678values that you specify using ``--source`` commands in kickstart files
5679(i.e. ``*.wks``) to a plugin implementation used to populate a given
5680partition.
5681
5682.. note::
5683
5684 If you use plugins that have build-time dependencies (e.g. native
5685 tools, bootloaders, and so forth) when building a Wic image, you need
5686 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
5687 variable.
5688
5689Source plugins are subclasses defined in plugin files. As shipped, the
5690Yocto Project provides several plugin files. You can see the source
5691plugin files that ship with the Yocto Project
5692:yocto_git:`here </cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source>`.
5693Each of these plugin files contains source plugins that are designed to
5694populate a specific Wic image partition.
5695
5696Source plugins are subclasses of the ``SourcePlugin`` class, which is
5697defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5698the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5699file is a subclass of the ``SourcePlugin`` class, which is found in the
5700``pluginbase.py`` file.
5701
5702You can also implement source plugins in a layer outside of the Source
5703Repositories (external layer). To do so, be sure that your plugin files
5704are located in a directory whose path is
5705``scripts/lib/wic/plugins/source/`` within your external layer. When the
5706plugin files are located there, the source plugins they contain are made
5707available to Wic.
5708
5709When the Wic implementation needs to invoke a partition-specific
5710implementation, it looks for the plugin with the same name as the
5711``--source`` parameter used in the kickstart file given to that
5712partition. For example, if the partition is set up using the following
5713command in a kickstart file:
5714::
5715
5716 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5717
5718The methods defined as class
5719members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5720``bootimg-pcbios.py`` plugin file are used.
5721
5722To be more concrete, here is the corresponding plugin definition from
5723the ``bootimg-pcbios.py`` file for the previous command along with an
5724example method called by the Wic implementation when it needs to prepare
5725a partition using an implementation-specific function:
5726::
5727
5728 .
5729 .
5730 .
5731 class BootimgPcbiosPlugin(SourcePlugin):
5732 """
5733 Create MBR boot partition and install syslinux on it.
5734 """
5735
5736 name = 'bootimg-pcbios'
5737 .
5738 .
5739 .
5740 @classmethod
5741 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5742 oe_builddir, bootimg_dir, kernel_dir,
5743 rootfs_dir, native_sysroot):
5744 """
5745 Called to do the actual content population for a partition i.e. it
5746 'prepares' the partition to be incorporated into the image.
5747 In this case, prepare content for legacy bios boot partition.
5748 """
5749 .
5750 .
5751 .
5752
5753If a
5754subclass (plugin) itself does not implement a particular function, Wic
5755locates and uses the default version in the superclass. It is for this
5756reason that all source plugins are derived from the ``SourcePlugin``
5757class.
5758
5759The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5760a set of methods that source plugins can implement or override. Any
5761plugins (subclass of ``SourcePlugin``) that do not implement a
5762particular method inherit the implementation of the method from the
5763``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5764class in the ``pluginbase.py`` file for details:
5765
5766The following list describes the methods implemented in the
5767``SourcePlugin`` class:
5768
5769- ``do_prepare_partition()``: Called to populate a partition with
5770 actual content. In other words, the method prepares the final
5771 partition image that is incorporated into the disk image.
5772
5773- ``do_configure_partition()``: Called before
5774 ``do_prepare_partition()`` to create custom configuration files for a
5775 partition (e.g. syslinux or grub configuration files).
5776
5777- ``do_install_disk()``: Called after all partitions have been
5778 prepared and assembled into a disk image. This method provides a hook
5779 to allow finalization of a disk image (e.g. writing an MBR).
5780
5781- ``do_stage_partition()``: Special content-staging hook called
5782 before ``do_prepare_partition()``. This method is normally empty.
5783
5784 Typically, a partition just uses the passed-in parameters (e.g. the
5785 unmodified value of ``bootimg_dir``). However, in some cases, things
5786 might need to be more tailored. As an example, certain files might
5787 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5788 allows those files to be staged in a customized fashion.
5789
5790 .. note::
5791
5792 ``get_bitbake_var()`` allows you to access non-standard variables that
5793 you might want to use for this behavior.
5794
5795You can extend the source plugin mechanism. To add more hooks, create
5796more source plugin methods within ``SourcePlugin`` and the corresponding
5797derived subclasses. The code that calls the plugin methods uses the
5798``plugin.get_source_plugin_methods()`` function to find the method or
5799methods needed by the call. Retrieval of those methods is accomplished
5800by filling up a dict with keys that contain the method names of
5801interest. On success, these will be filled in with the actual methods.
5802See the Wic implementation for examples and details.
5803
5804.. _wic-usage-examples:
5805
5806Wic Examples
5807------------
5808
5809This section provides several examples that show how to use the Wic
5810utility. All the examples assume the list of requirements in the
5811"`Requirements <#wic-requirements>`__" section have been met. The
5812examples assume the previously generated image is
5813``core-image-minimal``.
5814
5815.. _generate-an-image-using-a-provided-kickstart-file:
5816
5817Generate an Image using an Existing Kickstart File
5818~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5819
5820This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
5821file:
5822::
5823
5824 $ wic create mkefidisk -e core-image-minimal
5825 INFO: Building wic-tools...
5826 .
5827 .
5828 .
5829 INFO: The new image(s) can be found here:
5830 ./mkefidisk-201804191017-sda.direct
5831
5832 The following build artifacts were used to create the image(s):
5833 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5834 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5835 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5836 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5837
5838 INFO: The image(s) were created using OE kickstart file:
5839 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
5840
5841The previous example shows the easiest way to create an image by running
5842in cooked mode and supplying a kickstart file and the "-e" option to
5843point to the existing build artifacts. Your ``local.conf`` file needs to
5844have the :term:`MACHINE` variable set
5845to the machine you are using, which is "qemux86" in this example.
5846
5847Once the image builds, the output provides image location, artifact use,
5848and kickstart file information.
5849
5850.. note::
5851
5852 You should always verify the details provided in the output to make
5853 sure that the image was indeed created exactly as expected.
5854
5855Continuing with the example, you can now write the image from the Build
5856Directory onto a USB stick, or whatever media for which you built your
5857image, and boot from the media. You can write the image by using
5858``bmaptool`` or ``dd``:
5859::
5860
5861 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
5862
5863or ::
5864
5865 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5866
5867.. note::
5868
5869 For more information on how to use the ``bmaptool``
5870 to flash a device with an image, see the
5871 ":ref:`dev-manual/dev-manual-common-tasks:flashing images using \`\`bmaptool\`\``"
5872 section.
5873
5874Using a Modified Kickstart File
5875~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5876
5877Because partitioned image creation is driven by the kickstart file, it
5878is easy to affect image creation by changing the parameters in the file.
5879This next example demonstrates that through modification of the
5880``directdisk-gpt`` kickstart file.
5881
5882As mentioned earlier, you can use the command ``wic list images`` to
5883show the list of existing kickstart files. The directory in which the
5884``directdisk-gpt.wks`` file resides is
5885``scripts/lib/image/canned-wks/``, which is located in the
5886:term:`Source Directory` (e.g. ``poky``).
5887Because available files reside in this directory, you can create and add
5888your own custom files to the directory. Subsequent use of the
5889``wic list images`` command would then include your kickstart files.
5890
5891In this example, the existing ``directdisk-gpt`` file already does most
5892of what is needed. However, for the hardware in this example, the image
5893will need to boot from ``sdb`` instead of ``sda``, which is what the
5894``directdisk-gpt`` kickstart file uses.
5895
5896The example begins by making a copy of the ``directdisk-gpt.wks`` file
5897in the ``scripts/lib/image/canned-wks`` directory and then by changing
5898the lines that specify the target disk from which to boot.
5899::
5900
5901 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5902 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5903
5904Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5905changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5906example changes the following two lines and leaves the remaining lines
5907untouched:
5908::
5909
5910 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5911 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5912
5913Once the lines are changed, the
5914example generates the ``directdisksdb-gpt`` image. The command points
5915the process at the ``core-image-minimal`` artifacts for the Next Unit of
5916Computing (nuc) :term:`MACHINE` the
5917``local.conf``.
5918::
5919
5920 $ wic create directdisksdb-gpt -e core-image-minimal
5921 INFO: Building wic-tools...
5922 .
5923 .
5924 .
5925 Initialising tasks: 100% |#######################################| Time: 0:00:01
5926 NOTE: Executing SetScene Tasks
5927 NOTE: Executing RunQueue Tasks
5928 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5929 INFO: Creating image(s)...
5930
5931 INFO: The new image(s) can be found here:
5932 ./directdisksdb-gpt-201710090938-sdb.direct
5933
5934 The following build artifacts were used to create the image(s):
5935 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5936 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5937 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5938 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5939
5940 INFO: The image(s) were created using OE kickstart file:
5941 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5942
5943Continuing with the example, you can now directly ``dd`` the image to a
5944USB stick, or whatever media for which you built your image, and boot
5945the resulting media:
5946::
5947
5948 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5949 140966+0 records in
5950 140966+0 records out
5951 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5952 $ sudo eject /dev/sdb
5953
5954Using a Modified Kickstart File and Running in Raw Mode
5955~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5956
5957This next example manually specifies each build artifact (runs in Raw
5958Mode) and uses a modified kickstart file. The example also uses the
5959``-o`` option to cause Wic to create the output somewhere other than the
5960default output directory, which is the current directory:
5961::
5962
5963 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
5964 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5965 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5966 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
5967 --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
5968
5969 INFO: Creating image(s)...
5970
5971 INFO: The new image(s) can be found here:
5972 /home/stephano/testwic/test-201710091445-sdb.direct
5973
5974 The following build artifacts were used to create the image(s):
5975 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5976 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5977 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5978 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5979
5980 INFO: The image(s) were created using OE kickstart file:
5981 /home/stephano/my_yocto/test.wks
5982
5983For this example,
5984:term:`MACHINE` did not have to be
5985specified in the ``local.conf`` file since the artifact is manually
5986specified.
5987
5988Using Wic to Manipulate an Image
5989~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5990
5991Wic image manipulation allows you to shorten turnaround time during
5992image development. For example, you can use Wic to delete the kernel
5993partition of a Wic image and then insert a newly built kernel. This
5994saves you time from having to rebuild the entire image each time you
5995modify the kernel.
5996
5997.. note::
5998
5999 In order to use Wic to manipulate a Wic image as in this example,
6000 your development machine must have the ``mtools`` package installed.
6001
6002The following example examines the contents of the Wic image, deletes
6003the existing kernel, and then inserts a new kernel:
6004
60051. *List the Partitions:* Use the ``wic ls`` command to list all the
6006 partitions in the Wic image:
6007 ::
6008
6009 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
6010 Num Start End Size Fstype
6011 1 1048576 25041919 23993344 fat16
6012 2 25165824 72157183 46991360 ext4
6013
6014 The previous output shows two partitions in the
6015 ``core-image-minimal-qemux86.wic`` image.
6016
60172. *Examine a Particular Partition:* Use the ``wic ls`` command again
6018 but in a different form to examine a particular partition.
6019
6020 .. note::
6021
6022 You can get command usage on any Wic command using the following
6023 form:
6024 ::
6025
6026 $ wic help command
6027
6028
6029 For example, the following command shows you the various ways to
6030 use the
6031 wic ls
6032 command:
6033 ::
6034
6035 $ wic help ls
6036
6037
6038 The following command shows what is in Partition one:
6039 ::
6040
6041 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
6042 Volume in drive : is boot
6043 Volume Serial Number is E894-1809
6044 Directory for ::/
6045
6046 libcom32 c32 186500 2017-10-09 16:06
6047 libutil c32 24148 2017-10-09 16:06
6048 syslinux cfg 220 2017-10-09 16:06
6049 vesamenu c32 27104 2017-10-09 16:06
6050 vmlinuz 6904608 2017-10-09 16:06
6051 5 files 7 142 580 bytes
6052 16 582 656 bytes free
6053
6054 The previous output shows five files, with the
6055 ``vmlinuz`` being the kernel.
6056
6057 .. note::
6058
6059 If you see the following error, you need to update or create a
6060 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
6061 in the file. Then, run the Wic command again:
6062 ::
6063
6064 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
6065 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
6066 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
6067
6068
60693. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
6070 ``vmlinuz`` file (kernel):
6071 ::
6072
6073 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6074
60754. *Add In the New Kernel:* Use the ``wic cp`` command to add the
6076 updated kernel to the Wic image. Depending on how you built your
6077 kernel, it could be in different places. If you used ``devtool`` and
6078 an SDK to build your kernel, it resides in the ``tmp/work`` directory
6079 of the extensible SDK. If you used ``make`` to build the kernel, the
6080 kernel will be in the ``workspace/sources`` area.
6081
6082 The following example assumes ``devtool`` was used to build the
6083 kernel:
6084 ::
6085
6086 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 \
6087 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6088
6089 Once the new kernel is added back into the image, you can use the
6090 ``dd`` command or :ref:`bmaptool
6091 <dev-manual/dev-manual-common-tasks:flashing images using \`\`bmaptool\`\`>`
6092 to flash your wic image onto an SD card or USB stick and test your
6093 target.
6094
6095 .. note::
6096
6097 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
6098
6099Flashing Images Using ``bmaptool``
6100==================================
6101
6102A fast and easy way to flash an image to a bootable device is to use
6103Bmaptool, which is integrated into the OpenEmbedded build system.
6104Bmaptool is a generic tool that creates a file's block map (bmap) and
6105then uses that map to copy the file. As compared to traditional tools
6106such as dd or cp, Bmaptool can copy (or flash) large files like raw
6107system image files much faster.
6108
6109.. note::
6110
6111 - If you are using Ubuntu or Debian distributions, you can install
6112 the ``bmap-tools`` package using the following command and then
6113 use the tool without specifying ``PATH`` even from the root
6114 account:
6115 ::
6116
6117 $ sudo apt-get install bmap-tools
6118
6119 - If you are unable to install the ``bmap-tools`` package, you will
6120 need to build Bmaptool before using it. Use the following command:
6121 ::
6122
6123 $ bitbake bmap-tools-native
6124
6125Following, is an example that shows how to flash a Wic image. Realize
6126that while this example uses a Wic image, you can use Bmaptool to flash
6127any type of image. Use these steps to flash an image using Bmaptool:
6128
61291. *Update your local.conf File:* You need to have the following set
6130 in your ``local.conf`` file before building your image:
6131 ::
6132
6133 IMAGE_FSTYPES += "wic wic.bmap"
6134
61352. *Get Your Image:* Either have your image ready (pre-built with the
6136 :term:`IMAGE_FSTYPES`
6137 setting previously mentioned) or take the step to build the image:
6138 ::
6139
6140 $ bitbake image
6141
61423. *Flash the Device:* Flash the device with the image by using Bmaptool
6143 depending on your particular setup. The following commands assume the
6144 image resides in the Build Directory's ``deploy/images/`` area:
6145
6146 - If you have write access to the media, use this command form:
6147 ::
6148
6149 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6150
6151 - If you do not have write access to the media, set your permissions
6152 first and then use the same command form:
6153 ::
6154
6155 $ sudo chmod 666 /dev/sdX
6156 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6157
6158For help on the ``bmaptool`` command, use the following command:
6159::
6160
6161 $ bmaptool --help
6162
6163Making Images More Secure
6164=========================
6165
6166Security is of increasing concern for embedded devices. Consider the
6167issues and problems discussed in just this sampling of work found across
6168the Internet:
6169
6170- *"*\ `Security Risks of Embedded
6171 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6172 by Bruce Schneier
6173
6174- *"*\ `Internet Census
6175 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6176 Botnet
6177
6178- *"*\ `Security Issues for Embedded
6179 Devices <http://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
6180 by Jake Edge
6181
6182When securing your image is of concern, there are steps, tools, and
6183variables that you can consider to help you reach the security goals you
6184need for your particular device. Not all situations are identical when
6185it comes to making an image secure. Consequently, this section provides
6186some guidance and suggestions for consideration when you want to make
6187your image more secure.
6188
6189.. note::
6190
6191 Because the security requirements and risks are different for every
6192 type of device, this section cannot provide a complete reference on
6193 securing your custom OS. It is strongly recommended that you also
6194 consult other sources of information on embedded Linux system
6195 hardening and on security.
6196
6197General Considerations
6198----------------------
6199
6200General considerations exist that help you create more secure images.
6201You should consider the following suggestions to help make your device
6202more secure:
6203
6204- Scan additional code you are adding to the system (e.g. application
6205 code) by using static analysis tools. Look for buffer overflows and
6206 other potential security problems.
6207
6208- Pay particular attention to the security for any web-based
6209 administration interface.
6210
6211 Web interfaces typically need to perform administrative functions and
6212 tend to need to run with elevated privileges. Thus, the consequences
6213 resulting from the interface's security becoming compromised can be
6214 serious. Look for common web vulnerabilities such as
6215 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6216
6217 As with system passwords, the default credentials for accessing a
6218 web-based interface should not be the same across all devices. This
6219 is particularly true if the interface is enabled by default as it can
6220 be assumed that many end-users will not change the credentials.
6221
6222- Ensure you can update the software on the device to mitigate
6223 vulnerabilities discovered in the future. This consideration
6224 especially applies when your device is network-enabled.
6225
6226- Ensure you remove or disable debugging functionality before producing
6227 the final image. For information on how to do this, see the
6228 "`Considerations Specific to the OpenEmbedded Build
6229 System <#considerations-specific-to-the-openembedded-build-system>`__"
6230 section.
6231
6232- Ensure you have no network services listening that are not needed.
6233
6234- Remove any software from the image that is not needed.
6235
6236- Enable hardware support for secure boot functionality when your
6237 device supports this functionality.
6238
6239Security Flags
6240--------------
6241
6242The Yocto Project has security flags that you can enable that help make
6243your build output more secure. The security flags are in the
6244``meta/conf/distro/include/security_flags.inc`` file in your
6245:term:`Source Directory` (e.g. ``poky``).
6246
6247.. note::
6248
6249 Depending on the recipe, certain security flags are enabled and
6250 disabled by default.
6251
6252Use the following line in your ``local.conf`` file or in your custom
6253distribution configuration file to enable the security compiler and
6254linker flags for your build:
6255::
6256
6257 require conf/distro/include/security_flags.inc
6258
6259Considerations Specific to the OpenEmbedded Build System
6260--------------------------------------------------------
6261
6262You can take some steps that are specific to the OpenEmbedded build
6263system to make your images more secure:
6264
6265- Ensure "debug-tweaks" is not one of your selected
6266 :term:`IMAGE_FEATURES`.
6267 When creating a new project, the default is to provide you with an
6268 initial ``local.conf`` file that enables this feature using the
6269 :term:`EXTRA_IMAGE_FEATURES`
6270 variable with the line:
6271 ::
6272
6273 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6274
6275 To disable that feature, simply comment out that line in your
6276 ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
6277 "debug-tweaks" before producing your final image. Among other things,
6278 leaving this in place sets the root password as blank, which makes
6279 logging in for debugging or inspection easy during development but
6280 also means anyone can easily log in during production.
6281
6282- It is possible to set a root password for the image and also to set
6283 passwords for any extra users you might add (e.g. administrative or
6284 service type users). When you set up passwords for multiple images or
6285 users, you should not duplicate passwords.
6286
6287 To set up passwords, use the
6288 :ref:`extrausers <ref-classes-extrausers>`
6289 class, which is the preferred method. For an example on how to set up
6290 both root and user passwords, see the
6291 ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
6292 section.
6293
6294 .. note::
6295
6296 When adding extra user accounts or setting a root password, be
6297 cautious about setting the same password on every device. If you
6298 do this, and the password you have set is exposed, then every
6299 device is now potentially compromised. If you need this access but
6300 want to ensure security, consider setting a different, random
6301 password for each device. Typically, you do this as a separate
6302 step after you deploy the image onto the device.
6303
6304- Consider enabling a Mandatory Access Control (MAC) framework such as
6305 SMACK or SELinux and tuning it appropriately for your device's usage.
6306 You can find more information in the
6307 :yocto_git:`meta-selinux </cgit/cgit.cgi/meta-selinux/>` layer.
6308
6309Tools for Hardening Your Image
6310------------------------------
6311
6312The Yocto Project provides tools for making your image more secure. You
6313can find these tools in the ``meta-security`` layer of the
6314:yocto_git:`Yocto Project Source Repositories <>`.
6315
6316Creating Your Own Distribution
6317==============================
6318
6319When you build an image using the Yocto Project and do not alter any
6320distribution :term:`Metadata`, you are
6321creating a Poky distribution. If you wish to gain more control over
6322package alternative selections, compile-time options, and other
6323low-level configurations, you can create your own distribution.
6324
6325To create your own distribution, the basic steps consist of creating
6326your own distribution layer, creating your own distribution
6327configuration file, and then adding any needed code and Metadata to the
6328layer. The following steps provide some more detail:
6329
6330- *Create a layer for your new distro:* Create your distribution layer
6331 so that you can keep your Metadata and code for the distribution
6332 separate. It is strongly recommended that you create and use your own
6333 layer for configuration and code. Using your own layer as compared to
6334 just placing configurations in a ``local.conf`` configuration file
6335 makes it easier to reproduce the same build configuration when using
6336 multiple build machines. See the
6337 ":ref:`dev-manual/dev-manual-common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
6338 section for information on how to quickly set up a layer.
6339
6340- *Create the distribution configuration file:* The distribution
6341 configuration file needs to be created in the ``conf/distro``
6342 directory of your layer. You need to name it using your distribution
6343 name (e.g. ``mydistro.conf``).
6344
6345 .. note::
6346
6347 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6348 name of your distribution.
6349
6350 You can split out parts of your configuration file into include files
6351 and then "require" them from within your distribution configuration
6352 file. Be sure to place the include files in the
6353 ``conf/distro/include`` directory of your layer. A common example
6354 usage of include files would be to separate out the selection of
6355 desired version and revisions for individual recipes.
6356
6357 Your configuration file needs to set the following required
6358 variables:
6359
6360 - :term:`DISTRO_NAME`
6361
6362 - :term:`DISTRO_VERSION`
6363
6364 These following variables are optional and you typically set them
6365 from the distribution configuration file:
6366
6367 - :term:`DISTRO_FEATURES`
6368
6369 - :term:`DISTRO_EXTRA_RDEPENDS`
6370
6371 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6372
6373 - :term:`TCLIBC`
6374
6375 .. tip::
6376
6377 If you want to base your distribution configuration file on the
6378 very basic configuration from OE-Core, you can use
6379 ``conf/distro/defaultsetup.conf`` as a reference and just include
6380 variables that differ as compared to ``defaultsetup.conf``.
6381 Alternatively, you can create a distribution configuration file
6382 from scratch using the ``defaultsetup.conf`` file or configuration files
6383 from other distributions such as Poky or Angstrom as references.
6384
6385- *Provide miscellaneous variables:* Be sure to define any other
6386 variables for which you want to create a default or enforce as part
6387 of the distribution configuration. You can include nearly any
6388 variable from the ``local.conf`` file. The variables you use are not
6389 limited to the list in the previous bulleted item.
6390
6391- *Point to Your distribution configuration file:* In your
6392 ``local.conf`` file in the :term:`Build Directory`,
6393 set your
6394 :term:`DISTRO` variable to point to
6395 your distribution's configuration file. For example, if your
6396 distribution's configuration file is named ``mydistro.conf``, then
6397 you point to it as follows:
6398 ::
6399
6400 DISTRO = "mydistro"
6401
6402- *Add more to the layer if necessary:* Use your layer to hold other
6403 information needed for the distribution:
6404
6405 - Add recipes for installing distro-specific configuration files
6406 that are not already installed by another recipe. If you have
6407 distro-specific configuration files that are included by an
6408 existing recipe, you should add an append file (``.bbappend``) for
6409 those. For general information and recommendations on how to add
6410 recipes to your layer, see the "`Creating Your Own
6411 Layer <#creating-your-own-layer>`__" and "`Following Best
6412 Practices When Creating
6413 Layers <#best-practices-to-follow-when-creating-layers>`__"
6414 sections.
6415
6416 - Add any image recipes that are specific to your distribution.
6417
6418 - Add a ``psplash`` append file for a branded splash screen. For
6419 information on append files, see the "`Using .bbappend Files in
6420 Your Layer <#using-bbappend-files>`__" section.
6421
6422 - Add any other append files to make custom changes that are
6423 specific to individual recipes.
6424
6425Creating a Custom Template Configuration Directory
6426==================================================
6427
6428If you are producing your own customized version of the build system for
6429use by other users, you might want to customize the message shown by the
6430setup script or you might want to change the template configuration
6431files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
6432new build directory.
6433
6434The OpenEmbedded build system uses the environment variable
6435``TEMPLATECONF`` to locate the directory from which it gathers
6436configuration information that ultimately ends up in the
6437:term:`Build Directory` ``conf`` directory.
6438By default, ``TEMPLATECONF`` is set as follows in the ``poky``
6439repository:
6440::
6441
6442 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
6443
6444This is the
6445directory used by the build system to find templates from which to build
6446some key configuration files. If you look at this directory, you will
6447see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6448``conf-notes.txt`` files. The build system uses these files to form the
6449respective ``bblayers.conf`` file, ``local.conf`` file, and display the
6450list of BitBake targets when running the setup script.
6451
6452To override these default configuration files with configurations you
6453want used within every new Build Directory, simply set the
6454``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
6455variable is set in the ``.templateconf`` file, which is in the top-level
6456:term:`Source Directory` folder
6457(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
6458directory.
6459
6460Best practices dictate that you should keep your template configuration
6461directory in your custom distribution layer. For example, suppose you
6462have a layer named ``meta-mylayer`` located in your home directory and
6463you want your template configuration directory named ``myconf``.
6464Changing the ``.templateconf`` as follows causes the OpenEmbedded build
6465system to look in your directory and base its configuration files on the
6466``*.sample`` configuration files it finds. The final configuration files
6467(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
6468your Build Directory, but they are based on your ``*.sample`` files.
6469::
6470
6471 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
6472
6473Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
6474also resides in the default ``meta-poky/conf`` directory. The script
6475that sets up the build environment (i.e.
6476:ref:`structure-core-script`) uses this file to
6477display BitBake targets as part of the script output. Customizing this
6478``conf-notes.txt`` file is a good way to make sure your list of custom
6479targets appears as part of the script's output.
6480
6481Here is the default list of targets displayed as a result of running
6482either of the setup scripts:
6483::
6484
6485 You can now run 'bitbake <target>'
6486
6487 Common targets are:
6488 core-image-minimal
6489 core-image-sato
6490 meta-toolchain
6491 meta-ide-support
6492
6493Changing the listed common targets is as easy as editing your version of
6494``conf-notes.txt`` in your custom template configuration directory and
6495making sure you have ``TEMPLATECONF`` set to your directory.
6496
6497.. _dev-saving-memory-during-a-build:
6498
6499Conserving Disk Space During Builds
6500===================================
6501
6502To help conserve disk space during builds, you can add the following
6503statement to your project's ``local.conf`` configuration file found in
6504the :term:`Build Directory`:
6505::
6506
6507 INHERIT += "rm_work"
6508
6509Adding this statement deletes the work directory used for
6510building a recipe once the recipe is built. For more information on
6511"rm_work", see the
6512:ref:`rm_work <ref-classes-rm-work>` class in the
6513Yocto Project Reference Manual.
6514
6515Working with Packages
6516=====================
6517
6518This section describes a few tasks that involve packages:
6519
6520- `Excluding packages from an
6521 image <#excluding-packages-from-an-image>`__
6522
6523- `Incrementing a binary package
6524 version <#incrementing-a-binary-package-version>`__
6525
6526- `Handling optional module
6527 packaging <#handling-optional-module-packaging>`__
6528
6529- `Using runtime package
6530 management <#using-runtime-package-management>`__
6531
6532- `Generating and using signed
6533 packages <#generating-and-using-signed-packages>`__
6534
6535- `Setting up and running package test
6536 (ptest) <#testing-packages-with-ptest>`__
6537
6538- `Creating node package manager (NPM)
6539 packages <#creating-node-package-manager-npm-packages>`__
6540
6541- `Adding custom metadata to
6542 packages <#adding-custom-metadata-to-packages>`__
6543
6544Excluding Packages from an Image
6545--------------------------------
6546
6547You might find it necessary to prevent specific packages from being
6548installed into an image. If so, you can use several variables to direct
6549the build system to essentially ignore installing recommended packages
6550or to not install a package at all.
6551
6552The following list introduces variables you can use to prevent packages
6553from being installed into your image. Each of these variables only works
6554with IPK and RPM package types. Support for Debian packages does not
6555exist. Also, you can use these variables from your ``local.conf`` file
6556or attach them to a specific image recipe by using a recipe name
6557override. For more detail on the variables, see the descriptions in the
6558Yocto Project Reference Manual's glossary chapter.
6559
6560- :term:`BAD_RECOMMENDATIONS`:
6561 Use this variable to specify "recommended-only" packages that you do
6562 not want installed.
6563
6564- :term:`NO_RECOMMENDATIONS`:
6565 Use this variable to prevent all "recommended-only" packages from
6566 being installed.
6567
6568- :term:`PACKAGE_EXCLUDE`:
6569 Use this variable to prevent specific packages from being installed
6570 regardless of whether they are "recommended-only" or not. You need to
6571 realize that the build process could fail with an error when you
6572 prevent the installation of a package whose presence is required by
6573 an installed package.
6574
6575.. _incrementing-a-binary-package-version:
6576
6577Incrementing a Package Version
6578------------------------------
6579
6580This section provides some background on how binary package versioning
6581is accomplished and presents some of the services, variables, and
6582terminology involved.
6583
6584In order to understand binary package versioning, you need to consider
6585the following:
6586
6587- Binary Package: The binary package that is eventually built and
6588 installed into an image.
6589
6590- Binary Package Version: The binary package version is composed of two
6591 components - a version and a revision.
6592
6593 .. note::
6594
6595 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
6596 but this discussion for the most part ignores ``PE``.
6597
6598 The version and revision are taken from the
6599 :term:`PV` and
6600 :term:`PR` variables, respectively.
6601
6602- ``PV``: The recipe version. ``PV`` represents the version of the
6603 software being packaged. Do not confuse ``PV`` with the binary
6604 package version.
6605
6606- ``PR``: The recipe revision.
6607
6608- :term:`SRCPV`: The OpenEmbedded
6609 build system uses this string to help define the value of ``PV`` when
6610 the source code revision needs to be included in it.
6611
6612- :yocto_wiki:`PR Service </wiki/PR_Service>`: A
6613 network-based service that helps automate keeping package feeds
6614 compatible with existing package manager applications such as RPM,
6615 APT, and OPKG.
6616
6617Whenever the binary package content changes, the binary package version
6618must change. Changing the binary package version is accomplished by
6619changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
6620values occurs one of two ways:
6621
6622- Automatically using a Package Revision Service (PR Service).
6623
6624- Manually incrementing the ``PR`` and/or ``PV`` variables.
6625
6626Given a primary challenge of any build system and its users is how to
6627maintain a package feed that is compatible with existing package manager
6628applications such as RPM, APT, and OPKG, using an automated system is
6629much preferred over a manual system. In either system, the main
6630requirement is that binary package version numbering increases in a
6631linear fashion and that a number of version components exist that
6632support that linear progression. For information on how to ensure
6633package revisioning remains linear, see the "`Automatically Incrementing
6634a Binary Package Revision
6635Number <#automatically-incrementing-a-binary-package-revision-number>`__"
6636section.
6637
6638The following three sections provide related information on the PR
6639Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
6640how to ensure binary package revisioning remains linear.
6641
6642Working With a PR Service
6643~~~~~~~~~~~~~~~~~~~~~~~~~
6644
6645As mentioned, attempting to maintain revision numbers in the
6646:term:`Metadata` is error prone, inaccurate,
6647and causes problems for people submitting recipes. Conversely, the PR
6648Service automatically generates increasing numbers, particularly the
6649revision field, which removes the human element.
6650
6651.. note::
6652
6653 For additional information on using a PR Service, you can see the
6654 :yocto_wiki:`PR Service </wiki/PR_Service>` wiki page.
6655
6656The Yocto Project uses variables in order of decreasing priority to
6657facilitate revision numbering (i.e.
6658:term:`PE`,
6659:term:`PV`, and
6660:term:`PR` for epoch, version, and
6661revision, respectively). The values are highly dependent on the policies
6662and procedures of a given distribution and package feed.
6663
6664Because the OpenEmbedded build system uses
6665":ref:`signatures <overview-checksums>`", which are
6666unique to a given build, the build system knows when to rebuild
6667packages. All the inputs into a given task are represented by a
6668signature, which can trigger a rebuild when different. Thus, the build
6669system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
6670trigger a rebuild. The signatures, however, can be used to generate
6671these values.
6672
6673The PR Service works with both ``OEBasic`` and ``OEBasicHash``
6674generators. The value of ``PR`` bumps when the checksum changes and the
6675different generator mechanisms change signatures under different
6676circumstances.
6677
6678As implemented, the build system includes values from the PR Service
6679into the ``PR`` field as an addition using the form "``.x``" so ``r0``
6680becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
6681``PR`` values to be used for whatever reasons, which include manual
6682``PR`` bumps, should it be necessary.
6683
6684By default, the PR Service is not enabled or running. Thus, the packages
6685generated are just "self consistent". The build system adds and removes
6686packages and there are no guarantees about upgrade paths but images will
6687be consistent and correct with the latest changes.
6688
6689The simplest form for a PR Service is for it to exist for a single host
6690development system that builds the package feed (building system). For
6691this scenario, you can enable a local PR Service by setting
6692:term:`PRSERV_HOST` in your
6693``local.conf`` file in the :term:`Build Directory`:
6694::
6695
6696 PRSERV_HOST = "localhost:0"
6697
6698Once the service is started, packages will automatically
6699get increasing ``PR`` values and BitBake takes care of starting and
6700stopping the server.
6701
6702If you have a more complex setup where multiple host development systems
6703work against a common, shared package feed, you have a single PR Service
6704running and it is connected to each building system. For this scenario,
6705you need to start the PR Service using the ``bitbake-prserv`` command:
6706::
6707
6708 bitbake-prserv --host ip --port port --start
6709
6710In addition to
6711hand-starting the service, you need to update the ``local.conf`` file of
6712each building system as described earlier so each system points to the
6713server and port.
6714
6715It is also recommended you use build history, which adds some sanity
6716checks to binary package versions, in conjunction with the server that
6717is running the PR Service. To enable build history, add the following to
6718each building system's ``local.conf`` file:
6719::
6720
6721 # It is recommended to activate "buildhistory" for testing the PR service
6722 INHERIT += "buildhistory"
6723 BUILDHISTORY_COMMIT = "1"
6724
6725For information on build
6726history, see the "`Maintaining Build Output
6727Quality <#maintaining-build-output-quality>`__" section.
6728
6729.. note::
6730
6731 The OpenEmbedded build system does not maintain ``PR`` information as
6732 part of the shared state (sstate) packages. If you maintain an sstate
6733 feed, its expected that either all your building systems that
6734 contribute to the sstate feed use a shared PR Service, or you do not
6735 run a PR Service on any of your building systems. Having some systems
6736 use a PR Service while others do not leads to obvious problems.
6737
6738 For more information on shared state, see the
6739 ":ref:`overview-manual/overview-manual-concepts:shared state cache`"
6740 section in the Yocto Project Overview and Concepts Manual.
6741
6742Manually Bumping PR
6743~~~~~~~~~~~~~~~~~~~
6744
6745The alternative to setting up a PR Service is to manually "bump" the
6746:term:`PR` variable.
6747
6748If a committed change results in changing the package output, then the
6749value of the PR variable needs to be increased (or "bumped") as part of
6750that commit. For new recipes you should add the ``PR`` variable and set
6751its initial value equal to "r0", which is the default. Even though the
6752default value is "r0", the practice of adding it to a new recipe makes
6753it harder to forget to bump the variable when you make changes to the
6754recipe in future.
6755
6756If you are sharing a common ``.inc`` file with multiple recipes, you can
6757also use the ``INC_PR`` variable to ensure that the recipes sharing the
6758``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
6759``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
6760referring to it should set ``PR`` to "${INC_PR}.0" initially,
6761incrementing the last number when the recipe is changed. If the ``.inc``
6762file is changed then its ``INC_PR`` should be incremented.
6763
6764When upgrading the version of a binary package, assuming the ``PV``
6765changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
6766if you are using ``INC_PR``).
6767
6768Usually, version increases occur only to binary packages. However, if
6769for some reason ``PV`` changes but does not increase, you can increase
6770the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
6771"0".
6772
6773Binary package version numbering strives to follow the `Debian Version
6774Field Policy
6775Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
6776These guidelines define how versions are compared and what "increasing"
6777a version means.
6778
6779.. _automatically-incrementing-a-binary-package-revision-number:
6780
6781Automatically Incrementing a Package Version Number
6782~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6783
6784When fetching a repository, BitBake uses the
6785:term:`SRCREV` variable to determine
6786the specific source code revision from which to build. You set the
6787``SRCREV`` variable to
6788:term:`AUTOREV` to cause the
6789OpenEmbedded build system to automatically use the latest revision of
6790the software:
6791::
6792
6793 SRCREV = "${AUTOREV}"
6794
6795Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
6796automatically update the version whenever the revision of the source
6797code changes. Here is an example:
6798::
6799
6800 PV = "1.0+git${SRCPV}"
6801
6802The OpenEmbedded build system substitutes ``SRCPV`` with the following:
6803
6804.. code-block:: none
6805
6806 AUTOINC+source_code_revision
6807
6808The build system replaces the ``AUTOINC``
6809with a number. The number used depends on the state of the PR Service:
6810
6811- If PR Service is enabled, the build system increments the number,
6812 which is similar to the behavior of
6813 :term:`PR`. This behavior results in
6814 linearly increasing package versions, which is desirable. Here is an
6815 example:
6816
6817 .. code-block:: none
6818
6819 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6820 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6821
6822- If PR Service is not enabled, the build system replaces the
6823 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6824 changing the package version since the source revision is included.
6825 However, package versions are not increased linearly. Here is an
6826 example:
6827
6828 .. code-block:: none
6829
6830 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6831 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6832
6833In summary, the OpenEmbedded build system does not track the history of
6834binary package versions for this purpose. ``AUTOINC``, in this case, is
6835comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
6836package version is simply replaced by "0". If PR server is enabled, the
6837build system keeps track of the package versions and bumps the number
6838when the package revision changes.
6839
6840Handling Optional Module Packaging
6841----------------------------------
6842
6843Many pieces of software split functionality into optional modules (or
6844plugins) and the plugins that are built might depend on configuration
6845options. To avoid having to duplicate the logic that determines what
6846modules are available in your recipe or to avoid having to package each
6847module by hand, the OpenEmbedded build system provides functionality to
6848handle module packaging dynamically.
6849
6850To handle optional module packaging, you need to do two things:
6851
6852- Ensure the module packaging is actually done.
6853
6854- Ensure that any dependencies on optional modules from other recipes
6855 are satisfied by your recipe.
6856
6857Making Sure the Packaging is Done
6858~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6859
6860To ensure the module packaging actually gets done, you use the
6861``do_split_packages`` function within the ``populate_packages`` Python
6862function in your recipe. The ``do_split_packages`` function searches for
6863a pattern of files or directories under a specified path and creates a
6864package for each one it finds by appending to the
6865:term:`PACKAGES` variable and
6866setting the appropriate values for ``FILES_packagename``,
6867``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
6868Here is an example from the ``lighttpd`` recipe:
6869::
6870
6871 python populate_packages_prepend () {
6872 lighttpd_libdir = d.expand('${libdir}')
6873 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6874 'lighttpd-module-%s', 'Lighttpd module for %s',
6875 extra_depends='')
6876 }
6877
6878The previous example specifies a number of things in the call to
6879``do_split_packages``.
6880
6881- A directory within the files installed by your recipe through
6882 ``do_install`` in which to search.
6883
6884- A regular expression used to match module files in that directory. In
6885 the example, note the parentheses () that mark the part of the
6886 expression from which the module name should be derived.
6887
6888- A pattern to use for the package names.
6889
6890- A description for each package.
6891
6892- An empty string for ``extra_depends``, which disables the default
6893 dependency on the main ``lighttpd`` package. Thus, if a file in
6894 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6895 ``lighttpd-module-alias`` is created for it and the
6896 :term:`DESCRIPTION` is set to
6897 "Lighttpd module for alias".
6898
6899Often, packaging modules is as simple as the previous example. However,
6900more advanced options exist that you can use within
6901``do_split_packages`` to modify its behavior. And, if you need to, you
6902can add more logic by specifying a hook function that is called for each
6903package. It is also perfectly acceptable to call ``do_split_packages``
6904multiple times if you have more than one set of modules to package.
6905
6906For more examples that show how to use ``do_split_packages``, see the
6907``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
6908directory of the ``poky`` :ref:`source repository <yocto-project-repositories>`. You can
6909also find examples in ``meta/classes/kernel.bbclass``.
6910
6911Following is a reference that shows ``do_split_packages`` mandatory and
6912optional arguments:
6913::
6914
6915 Mandatory arguments
6916
6917 root
6918 The path in which to search
6919 file_regex
6920 Regular expression to match searched files.
6921 Use parentheses () to mark the part of this
6922 expression that should be used to derive the
6923 module name (to be substituted where %s is
6924 used in other function arguments as noted below)
6925 output_pattern
6926 Pattern to use for the package names. Must
6927 include %s.
6928 description
6929 Description to set for each package. Must
6930 include %s.
6931
6932 Optional arguments
6933
6934 postinst
6935 Postinstall script to use for all packages
6936 (as a string)
6937 recursive
6938 True to perform a recursive search - default
6939 False
6940 hook
6941 A hook function to be called for every match.
6942 The function will be called with the following
6943 arguments (in the order listed):
6944
6945 f
6946 Full path to the file/directory match
6947 pkg
6948 The package name
6949 file_regex
6950 As above
6951 output_pattern
6952 As above
6953 modulename
6954 The module name derived using file_regex
6955 extra_depends
6956 Extra runtime dependencies (RDEPENDS) to be
6957 set for all packages. The default value of None
6958 causes a dependency on the main package
6959 (${PN}) - if you do not want this, pass empty
6960 string '' for this parameter.
6961 aux_files_pattern
6962 Extra item(s) to be added to FILES for each
6963 package. Can be a single string item or a list
6964 of strings for multiple items. Must include %s.
6965 postrm
6966 postrm script to use for all packages (as a
6967 string)
6968 allow_dirs
6969 True to allow directories to be matched -
6970 default False
6971 prepend
6972 If True, prepend created packages to PACKAGES
6973 instead of the default False which appends them
6974 match_path
6975 match file_regex on the whole relative path to
6976 the root rather than just the file name
6977 aux_files_pattern_verbatim
6978 Extra item(s) to be added to FILES for each
6979 package, using the actual derived module name
6980 rather than converting it to something legal
6981 for a package name. Can be a single string item
6982 or a list of strings for multiple items. Must
6983 include %s.
6984 allow_links
6985 True to allow symlinks to be matched - default
6986 False
6987 summary
6988 Summary to set for each package. Must include %s;
6989 defaults to description if not set.
6990
6991
6992
6993Satisfying Dependencies
6994~~~~~~~~~~~~~~~~~~~~~~~
6995
6996The second part for handling optional module packaging is to ensure that
6997any dependencies on optional modules from other recipes are satisfied by
6998your recipe. You can be sure these dependencies are satisfied by using
6999the :term:`PACKAGES_DYNAMIC`
7000variable. Here is an example that continues with the ``lighttpd`` recipe
7001shown earlier:
7002::
7003
7004 PACKAGES_DYNAMIC = "lighttpd-module-.*"
7005
7006The name
7007specified in the regular expression can of course be anything. In this
7008example, it is ``lighttpd-module-`` and is specified as the prefix to
7009ensure that any :term:`RDEPENDS` and
7010:term:`RRECOMMENDS` on a package
7011name starting with the prefix are satisfied during build time. If you
7012are using ``do_split_packages`` as described in the previous section,
7013the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
7014pattern specified in the call to ``do_split_packages``.
7015
7016Using Runtime Package Management
7017--------------------------------
7018
7019During a build, BitBake always transforms a recipe into one or more
7020packages. For example, BitBake takes the ``bash`` recipe and produces a
7021number of packages (e.g. ``bash``, ``bash-bashbug``,
7022``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
7023``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
7024generated packages are included in an image.
7025
7026In several situations, you might need to update, add, remove, or query
7027the packages on a target device at runtime (i.e. without having to
7028generate a new image). Examples of such situations include:
7029
7030- You want to provide in-the-field updates to deployed devices (e.g.
7031 security updates).
7032
7033- You want to have a fast turn-around development cycle for one or more
7034 applications that run on your device.
7035
7036- You want to temporarily install the "debug" packages of various
7037 applications on your device so that debugging can be greatly improved
7038 by allowing access to symbols and source debugging.
7039
7040- You want to deploy a more minimal package selection of your device
7041 but allow in-the-field updates to add a larger selection for
7042 customization.
7043
7044In all these situations, you have something similar to a more
7045traditional Linux distribution in that in-field devices are able to
7046receive pre-compiled packages from a server for installation or update.
7047Being able to install these packages on a running, in-field device is
7048what is termed "runtime package management".
7049
7050In order to use runtime package management, you need a host or server
7051machine that serves up the pre-compiled packages plus the required
7052metadata. You also need package manipulation tools on the target. The
7053build machine is a likely candidate to act as the server. However, that
7054machine does not necessarily have to be the package server. The build
7055machine could push its artifacts to another machine that acts as the
7056server (e.g. Internet-facing). In fact, doing so is advantageous for a
7057production environment as getting the packages away from the development
7058system's build directory prevents accidental overwrites.
7059
7060A simple build that targets just one device produces more than one
7061package database. In other words, the packages produced by a build are
7062separated out into a couple of different package groupings based on
7063criteria such as the target's CPU architecture, the target board, or the
7064C library used on the target. For example, a build targeting the
7065``qemux86`` device produces the following three package databases:
7066``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
7067device to be aware of all the packages that were available to it, you
7068would need to point it to each of these databases individually. In a
7069similar way, a traditional Linux distribution usually is configured to
7070be aware of a number of software repositories from which it retrieves
7071packages.
7072
7073Using runtime package management is completely optional and not required
7074for a successful build or deployment in any way. But if you want to make
7075use of runtime package management, you need to do a couple things above
7076and beyond the basics. The remainder of this section describes what you
7077need to do.
7078
7079.. _runtime-package-management-build:
7080
7081Build Considerations
7082~~~~~~~~~~~~~~~~~~~~
7083
7084This section describes build considerations of which you need to be
7085aware in order to provide support for runtime package management.
7086
7087When BitBake generates packages, it needs to know what format or formats
7088to use. In your configuration, you use the
7089:term:`PACKAGE_CLASSES`
7090variable to specify the format:
7091
70921. Open the ``local.conf`` file inside your
7093 :term:`Build Directory` (e.g.
7094 ``~/poky/build/conf/local.conf``).
7095
70962. Select the desired package format as follows:
7097 ::
7098
7099 PACKAGE_CLASSES ?= "package_packageformat"
7100
7101 where packageformat can be "ipk", "rpm",
7102 "deb", or "tar" which are the supported package formats.
7103
7104 .. note::
7105
7106 Because the Yocto Project supports four different package formats,
7107 you can set the variable with more than one argument. However, the
7108 OpenEmbedded build system only uses the first argument when
7109 creating an image or Software Development Kit (SDK).
7110
7111If you would like your image to start off with a basic package database
7112containing the packages in your current build as well as to have the
7113relevant tools available on the target for runtime package management,
7114you can include "package-management" in the
7115:term:`IMAGE_FEATURES`
7116variable. Including "package-management" in this configuration variable
7117ensures that when the image is assembled for your target, the image
7118includes the currently-known package databases as well as the
7119target-specific tools required for runtime package management to be
7120performed on the target. However, this is not strictly necessary. You
7121could start your image off without any databases but only include the
7122required on-target package tool(s). As an example, you could include
7123"opkg" in your
7124:term:`IMAGE_INSTALL` variable
7125if you are using the IPK package format. You can then initialize your
7126target's package database(s) later once your image is up and running.
7127
7128Whenever you perform any sort of build step that can potentially
7129generate a package or modify existing package, it is always a good idea
7130to re-generate the package index after the build by using the following
7131command:
7132::
7133
7134 $ bitbake package-index
7135
7136It might be tempting to build the
7137package and the package index at the same time with a command such as
7138the following:
7139::
7140
7141 $ bitbake some-package package-index
7142
7143Do not do this as
7144BitBake does not schedule the package index for after the completion of
7145the package you are building. Consequently, you cannot be sure of the
7146package index including information for the package you just built.
7147Thus, be sure to run the package update step separately after building
7148any packages.
7149
7150You can use the
7151:term:`PACKAGE_FEED_ARCHS`,
7152:term:`PACKAGE_FEED_BASE_PATHS`,
7153and
7154:term:`PACKAGE_FEED_URIS`
7155variables to pre-configure target images to use a package feed. If you
7156do not define these variables, then manual steps as described in the
7157subsequent sections are necessary to configure the target. You should
7158set these variables before building the image in order to produce a
7159correctly configured image.
7160
7161When your build is complete, your packages reside in the
7162``${TMPDIR}/deploy/packageformat`` directory. For example, if
7163``${``\ :term:`TMPDIR`\ ``}`` is
7164``tmp`` and your selected package type is RPM, then your RPM packages
7165are available in ``tmp/deploy/rpm``.
7166
7167.. _runtime-package-management-server:
7168
7169Host or Server Machine Setup
7170~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7171
7172Although other protocols are possible, a server using HTTP typically
7173serves packages. If you want to use HTTP, then set up and configure a
7174web server such as Apache 2, lighttpd, or Python web server on the
7175machine serving the packages.
7176
7177To keep things simple, this section describes how to set up a
7178Python web server to share package feeds from the developer's
7179machine. Although this server might not be the best for a production
7180environment, the setup is simple and straight forward. Should you want
7181to use a different server more suited for production (e.g. Apache 2,
7182Lighttpd, or Nginx), take the appropriate steps to do so.
7183
7184From within the build directory where you have built an image based on
7185your packaging choice (i.e. the
7186:term:`PACKAGE_CLASSES`
7187setting), simply start the server. The following example assumes a build
7188directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
7189setting of "package_rpm":
7190::
7191
7192 $ cd ~/poky/build/tmp/deploy/rpm
7193 $ python3 -m http.server
7194
7195.. _runtime-package-management-target:
7196
7197Target Setup
7198~~~~~~~~~~~~
7199
7200Setting up the target differs depending on the package management
7201system. This section provides information for RPM, IPK, and DEB.
7202
7203.. _runtime-package-management-target-rpm:
7204
7205Using RPM
7206^^^^^^^^^
7207
7208The `Dandified Packaging
7209Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
7210runtime package management of RPM packages. In order to use DNF for
7211runtime package management, you must perform an initial setup on the
7212target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7213set as part of the image that is running on the target. This means if
7214you built your image and did not not use these variables as part of the
7215build and your image is now running on the target, you need to perform
7216the steps in this section if you want to use runtime package management.
7217
7218.. note::
7219
7220 For information on the ``PACKAGE_FEED_*`` variables, see
7221 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7222 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7223 glossary.
7224
7225On the target, you must inform DNF that package databases are available.
7226You do this by creating a file named
7227``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7228
7229As an example, assume the target is able to use the following package
7230databases: ``all``, ``i586``, and ``qemux86`` from a server named
7231``my.server``. The specifics for setting up the web server are up to
7232you. The critical requirement is that the URIs in the target repository
7233configuration point to the correct remote location for the feeds.
7234
7235.. note::
7236
7237 For development purposes, you can point the web server to the build
7238 system's ``deploy`` directory. However, for production use, it is better to
7239 copy the package directories to a location outside of the build area and use
7240 that location. Doing so avoids situations where the build system
7241 overwrites or changes the ``deploy`` directory.
7242
7243When telling DNF where to look for the package databases, you must
7244declare individual locations per architecture or a single location used
7245for all architectures. You cannot do both:
7246
7247- *Create an Explicit List of Architectures:* Define individual base
7248 URLs to identify where each package database is located:
7249
7250 .. code-block:: none
7251
7252 [oe-packages]
7253 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7254
7255 This example
7256 informs DNF about individual package databases for all three
7257 architectures.
7258
7259- *Create a Single (Full) Package Index:* Define a single base URL that
7260 identifies where a full package database is located:
7261 ::
7262
7263 [oe-packages]
7264 baseurl=http://my.server/rpm
7265
7266 This example informs DNF about a single
7267 package database that contains all the package index information for
7268 all supported architectures.
7269
7270Once you have informed DNF where to find the package databases, you need
7271to fetch them:
7272
7273.. code-block:: none
7274
7275 # dnf makecache
7276
7277DNF is now able to find, install, and
7278upgrade packages from the specified repository or repositories.
7279
7280.. note::
7281
7282 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7283 additional information.
7284
7285.. _runtime-package-management-target-ipk:
7286
7287Using IPK
7288^^^^^^^^^
7289
7290The ``opkg`` application performs runtime package management of IPK
7291packages. You must perform an initial setup for ``opkg`` on the target
7292machine if the
7293:term:`PACKAGE_FEED_ARCHS`,
7294:term:`PACKAGE_FEED_BASE_PATHS`,
7295and
7296:term:`PACKAGE_FEED_URIS`
7297variables have not been set or the target image was built before the
7298variables were set.
7299
7300The ``opkg`` application uses configuration files to find available
7301package databases. Thus, you need to create a configuration file inside
7302the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
7303you want to use.
7304
7305As an example, suppose you are serving packages from a ``ipk/``
7306directory containing the ``i586``, ``all``, and ``qemux86`` databases
7307through an HTTP server named ``my.server``. On the target, create a
7308configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7309directory containing the following:
7310
7311.. code-block:: none
7312
7313 src/gz all http://my.server/ipk/all
7314 src/gz i586 http://my.server/ipk/i586
7315 src/gz qemux86 http://my.server/ipk/qemux86
7316
7317Next, instruct ``opkg`` to fetch the
7318repository information:
7319
7320.. code-block:: none
7321
7322 # opkg update
7323
7324The ``opkg`` application is now able to find, install, and upgrade packages
7325from the specified repository.
7326
7327.. _runtime-package-management-target-deb:
7328
7329Using DEB
7330^^^^^^^^^
7331
7332The ``apt`` application performs runtime package management of DEB
7333packages. This application uses a source list file to find available
7334package databases. You must perform an initial setup for ``apt`` on the
7335target machine if the
7336:term:`PACKAGE_FEED_ARCHS`,
7337:term:`PACKAGE_FEED_BASE_PATHS`,
7338and
7339:term:`PACKAGE_FEED_URIS`
7340variables have not been set or the target image was built before the
7341variables were set.
7342
7343To inform ``apt`` of the repository you want to use, you might create a
7344list file (e.g. ``my_repo.list``) inside the
7345``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7346serving packages from a ``deb/`` directory containing the ``i586``,
7347``all``, and ``qemux86`` databases through an HTTP server named
7348``my.server``. The list file should contain:
7349
7350.. code-block:: none
7351
7352 deb http://my.server/deb/all ./
7353 deb http://my.server/deb/i586 ./
7354 deb http://my.server/deb/qemux86 ./
7355
7356Next, instruct the ``apt`` application
7357to fetch the repository information:
7358
7359.. code-block:: none
7360
7361 # apt-get update
7362
7363After this step,
7364``apt`` is able to find, install, and upgrade packages from the
7365specified repository.
7366
7367Generating and Using Signed Packages
7368------------------------------------
7369
7370In order to add security to RPM packages used during a build, you can
7371take steps to securely sign them. Once a signature is verified, the
7372OpenEmbedded build system can use the package in the build. If security
7373fails for a signed package, the build system aborts the build.
7374
7375This section describes how to sign RPM packages during a build and how
7376to use signed package feeds (repositories) when doing a build.
7377
7378Signing RPM Packages
7379~~~~~~~~~~~~~~~~~~~~
7380
7381To enable signing RPM packages, you must set up the following
7382configurations in either your ``local.config`` or ``distro.config``
7383file:
7384::
7385
7386 # Inherit sign_rpm.bbclass to enable signing functionality
7387 INHERIT += " sign_rpm"
7388 # Define the GPG key that will be used for signing.
7389 RPM_GPG_NAME = "key_name"
7390 # Provide passphrase for the key
7391 RPM_GPG_PASSPHRASE = "passphrase"
7392
7393.. note::
7394
7395 Be sure to supply appropriate values for both `key_name` and
7396 `passphrase`.
7397
7398Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
7399the previous example, two optional variables related to signing exist:
7400
7401- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7402 when the package is signed.
7403
7404- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7405 package is signed.
7406
7407Processing Package Feeds
7408~~~~~~~~~~~~~~~~~~~~~~~~
7409
7410In addition to being able to sign RPM packages, you can also enable
7411signed package feeds for IPK and RPM packages.
7412
7413The steps you need to take to enable signed package feed use are similar
7414to the steps used to sign RPM packages. You must define the following in
7415your ``local.config`` or ``distro.config`` file:
7416::
7417
7418 INHERIT += "sign_package_feed"
7419 PACKAGE_FEED_GPG_NAME = "key_name"
7420 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7421
7422For signed package feeds, the passphrase must exist in a separate file,
7423which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7424variable. Regarding security, keeping a plain text passphrase out of the
7425configuration is more secure.
7426
7427Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7428``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
7429related to signed package feeds exist:
7430
7431- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7432 when the package is signed.
7433
7434- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7435 package is signed.
7436
7437- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7438 signature. This variable applies only to RPM and IPK package feeds.
7439 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7440 "ASC", which is the default and specifies ascii armored, and "BIN",
7441 which specifies binary.
7442
7443Testing Packages With ptest
7444---------------------------
7445
7446A Package Test (ptest) runs tests against packages built by the
7447OpenEmbedded build system on the target machine. A ptest contains at
7448least two items: the actual test, and a shell script (``run-ptest``)
7449that starts the test. The shell script that starts the test must not
7450contain the actual test - the script only starts the test. On the other
7451hand, the test can be anything from a simple shell script that runs a
7452binary and checks the output to an elaborate system of test binaries and
7453data files.
7454
7455The test generates output in the format used by Automake:
7456::
7457
7458 result: testname
7459
7460where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7461the testname can be any identifying string.
7462
7463For a list of Yocto Project recipes that are already enabled with ptest,
7464see the :yocto_wiki:`Ptest </wiki/Ptest>` wiki page.
7465
7466.. note::
7467
7468 A recipe is "ptest-enabled" if it inherits the
7469 :ref:`ptest <ref-classes-ptest>` class.
7470
7471Adding ptest to Your Build
7472~~~~~~~~~~~~~~~~~~~~~~~~~~
7473
7474To add package testing to your build, add the
7475:term:`DISTRO_FEATURES` and
7476:term:`EXTRA_IMAGE_FEATURES`
7477variables to your ``local.conf`` file, which is found in the
7478:term:`Build Directory`:
7479::
7480
7481 DISTRO_FEATURES_append = " ptest"
7482 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7483
7484Once your build is complete, the ptest files are installed into the
7485``/usr/lib/package/ptest`` directory within the image, where ``package``
7486is the name of the package.
7487
7488Running ptest
7489~~~~~~~~~~~~~
7490
7491The ``ptest-runner`` package installs a shell script that loops through
7492all installed ptest test suites and runs them in sequence. Consequently,
7493you might want to add this package to your image.
7494
7495Getting Your Package Ready
7496~~~~~~~~~~~~~~~~~~~~~~~~~~
7497
7498In order to enable a recipe to run installed ptests on target hardware,
7499you need to prepare the recipes that build the packages you want to
7500test. Here is what you have to do for each recipe:
7501
7502- *Be sure the recipe inherits
7503 the* :ref:`ptest <ref-classes-ptest>` *class:*
7504 Include the following line in each recipe:
7505 ::
7506
7507 inherit ptest
7508
7509- *Create run-ptest:* This script starts your test. Locate the
7510 script where you will refer to it using
7511 :term:`SRC_URI`. Here is an
7512 example that starts a test for ``dbus``:
7513 ::
7514
7515 #!/bin/sh
7516 cd test
7517 make -k runtest-TESTS
7518
7519- *Ensure dependencies are met:* If the test adds build or runtime
7520 dependencies that normally do not exist for the package (such as
7521 requiring "make" to run the test suite), use the
7522 :term:`DEPENDS` and
7523 :term:`RDEPENDS` variables in
7524 your recipe in order for the package to meet the dependencies. Here
7525 is an example where the package has a runtime dependency on "make":
7526 ::
7527
7528 RDEPENDS_${PN}-ptest += "make"
7529
7530- *Add a function to build the test suite:* Not many packages support
7531 cross-compilation of their test suites. Consequently, you usually
7532 need to add a cross-compilation function to the package.
7533
7534 Many packages based on Automake compile and run the test suite by
7535 using a single command such as ``make check``. However, the host
7536 ``make check`` builds and runs on the same computer, while
7537 cross-compiling requires that the package is built on the host but
7538 executed for the target architecture (though often, as in the case
7539 for ptest, the execution occurs on the host). The built version of
7540 Automake that ships with the Yocto Project includes a patch that
7541 separates building and execution. Consequently, packages that use the
7542 unaltered, patched version of ``make check`` automatically
7543 cross-compiles.
7544
7545 Regardless, you still must add a ``do_compile_ptest`` function to
7546 build the test suite. Add a function similar to the following to your
7547 recipe:
7548 ::
7549
7550 do_compile_ptest() {
7551 oe_runmake buildtest-TESTS
7552 }
7553
7554- *Ensure special configurations are set:* If the package requires
7555 special configurations prior to compiling the test code, you must
7556 insert a ``do_configure_ptest`` function into the recipe.
7557
7558- *Install the test suite:* The ``ptest`` class automatically copies
7559 the file ``run-ptest`` to the target and then runs make
7560 ``install-ptest`` to run the tests. If this is not enough, you need
7561 to create a ``do_install_ptest`` function and make sure it gets
7562 called after the "make install-ptest" completes.
7563
7564Creating Node Package Manager (NPM) Packages
7565--------------------------------------------
7566
7567`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7568manager for the JavaScript programming language. The Yocto Project
7569supports the NPM :ref:`fetcher <bitbake:bb-fetchers>`. You can
7570use this fetcher in combination with
7571:doc:`devtool <../ref-manual/ref-devtool-reference>` to create
7572recipes that produce NPM packages.
7573
7574Two workflows exist that allow you to create NPM packages using
7575``devtool``: the NPM registry modules method and the NPM project code
7576method.
7577
7578.. note::
7579
7580 While it is possible to create NPM recipes manually, using
7581 ``devtool`` is far simpler.
7582
7583Additionally, some requirements and caveats exist.
7584
7585.. _npm-package-creation-requirements:
7586
7587Requirements and Caveats
7588~~~~~~~~~~~~~~~~~~~~~~~~
7589
7590You need to be aware of the following before using ``devtool`` to create
7591NPM packages:
7592
7593- Of the two methods that you can use ``devtool`` to create NPM
7594 packages, the registry approach is slightly simpler. However, you
7595 might consider the project approach because you do not have to
7596 publish your module in the NPM registry
7597 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7598 is NPM's public registry.
7599
7600- Be familiar with
7601 :doc:`devtool <../ref-manual/ref-devtool-reference>`.
7602
7603- The NPM host tools need the native ``nodejs-npm`` package, which is
7604 part of the OpenEmbedded environment. You need to get the package by
7605 cloning the https://github.com/openembedded/meta-openembedded
7606 repository out of GitHub. Be sure to add the path to your local copy
7607 to your ``bblayers.conf`` file.
7608
7609- ``devtool`` cannot detect native libraries in module dependencies.
7610 Consequently, you must manually add packages to your recipe.
7611
7612- While deploying NPM packages, ``devtool`` cannot determine which
7613 dependent packages are missing on the target (e.g. the node runtime
7614 ``nodejs``). Consequently, you need to find out what files are
7615 missing and be sure they are on the target.
7616
7617- Although you might not need NPM to run your node package, it is
7618 useful to have NPM on your target. The NPM package name is
7619 ``nodejs-npm``.
7620
7621.. _npm-using-the-registry-modules-method:
7622
7623Using the Registry Modules Method
7624~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7625
7626This section presents an example that uses the ``cute-files`` module,
7627which is a file browser web application.
7628
7629.. note::
7630
7631 You must know the ``cute-files`` module version.
7632
7633The first thing you need to do is use ``devtool`` and the NPM fetcher to
7634create the recipe:
7635::
7636
7637 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7638
7639The
7640``devtool add`` command runs ``recipetool create`` and uses the same
7641fetch URI to download each dependency and capture license details where
7642possible. The result is a generated recipe.
7643
7644The recipe file is fairly simple and contains every license that
7645``recipetool`` finds and includes the licenses in the recipe's
7646:term:`LIC_FILES_CHKSUM`
7647variables. You need to examine the variables and look for those with
7648"unknown" in the :term:`LICENSE`
7649field. You need to track down the license information for "unknown"
7650modules and manually add the information to the recipe.
7651
7652``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7653files capture the version of all dependent modules. Many packages do not
7654provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
7655runs.
7656
7657.. note::
7658
7659 A package is created for each sub-module. This policy is the only
7660 practical way to have the licenses for all of the dependencies
7661 represented in the license manifest of the image.
7662
7663The ``devtool edit-recipe`` command lets you take a look at the recipe:
7664::
7665
7666 $ devtool edit-recipe cute-files
7667 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7668 LICENSE = "MIT & ISC & Unknown"
7669 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
7670 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
7671 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
7672 ...
7673 SRC_URI = " \
7674 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7675 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7676 "
7677 S = "${WORKDIR}/npm"
7678 inherit npm LICENSE_${PN} = "MIT"
7679 LICENSE_${PN}-accepts = "MIT"
7680 LICENSE_${PN}-array-flatten = "MIT"
7681 ...
7682 LICENSE_${PN}-vary = "MIT"
7683
7684Three key points exist in the previous example:
7685
7686- :term:`SRC_URI` uses the NPM
7687 scheme so that the NPM fetcher is used.
7688
7689- ``recipetool`` collects all the license information. If a
7690 sub-module's license is unavailable, the sub-module's name appears in
7691 the comments.
7692
7693- The ``inherit npm`` statement causes the
7694 :ref:`npm <ref-classes-npm>` class to package
7695 up all the modules.
7696
7697You can run the following command to build the ``cute-files`` package:
7698::
7699
7700 $ devtool build cute-files
7701
7702Remember that ``nodejs`` must be installed on
7703the target before your package.
7704
7705Assuming 192.168.7.2 for the target's IP address, use the following
7706command to deploy your package:
7707::
7708
7709 $ devtool deploy-target -s cute-files root@192.168.7.2
7710
7711Once the package is installed on the target, you can
7712test the application:
7713
7714.. note::
7715
7716 Because of a known issue, you cannot simply run ``cute-files`` as you would
7717 if you had run ``npm install``.
7718
7719::
7720
7721 $ cd /usr/lib/node_modules/cute-files
7722 $ node cute-files.js
7723
7724On a browser,
7725go to ``http://192.168.7.2:3000`` and you see the following:
7726
7727.. image:: figures/cute-files-npm-example.png
7728 :align: center
7729
7730You can find the recipe in ``workspace/recipes/cute-files``. You can use
7731the recipe in any layer you choose.
7732
7733.. _npm-using-the-npm-projects-method:
7734
7735Using the NPM Projects Code Method
7736~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7737
7738Although it is useful to package modules already in the NPM registry,
7739adding ``node.js`` projects under development is a more common developer
7740use case.
7741
7742This section covers the NPM projects code method, which is very similar
7743to the "registry" approach described in the previous section. In the NPM
7744projects method, you provide ``devtool`` with an URL that points to the
7745source files.
7746
7747Replicating the same example, (i.e. ``cute-files``) use the following
7748command:
7749::
7750
7751 $ devtool add https://github.com/martinaglv/cute-files.git
7752
7753The
7754recipe this command generates is very similar to the recipe created in
7755the previous section. However, the ``SRC_URI`` looks like the following:
7756::
7757
7758 SRC_URI = " \
7759 git://github.com/martinaglv/cute-files.git;protocol=https \
7760 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7761 "
7762
7763In this example,
7764the main module is taken from the Git repository and dependencies are
7765taken from the NPM registry. Other than those differences, the recipe is
7766basically the same between the two methods. You can build and deploy the
7767package exactly as described in the previous section that uses the
7768registry modules method.
7769
7770Adding custom metadata to packages
7771----------------------------------
7772
7773The variable
7774:term:`PACKAGE_ADD_METADATA`
7775can be used to add additional metadata to packages. This is reflected in
7776the package control/spec file. To take the ipk format for example, the
7777CONTROL file stored inside would contain the additional metadata as
7778additional lines.
7779
7780The variable can be used in multiple ways, including using suffixes to
7781set it for a specific package type and/or package. Note that the order
7782of precedence is the same as this list:
7783
7784- ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
7785
7786- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7787
7788- ``PACKAGE_ADD_METADATA_<PN>``
7789
7790- ``PACKAGE_ADD_METADATA``
7791
7792`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
7793package type:
7794
7795- IPK for .ipk packages
7796
7797- DEB for .deb packages
7798
7799- RPM for .rpm packages
7800
7801`<PN>` is a parameter and expected to be a package name.
7802
7803The variable can contain multiple [one-line] metadata fields separated
7804by the literal sequence '\\n'. The separator can be redefined using the
7805variable flag ``separator``.
7806
7807The following is an example that adds two custom fields for ipk
7808packages:
7809::
7810
7811 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
7812
7813Efficiently Fetching Source Files During a Build
7814================================================
7815
7816The OpenEmbedded build system works with source files located through
7817the :term:`SRC_URI` variable. When
7818you build something using BitBake, a big part of the operation is
7819locating and downloading all the source tarballs. For images,
7820downloading all the source for various packages can take a significant
7821amount of time.
7822
7823This section shows you how you can use mirrors to speed up fetching
7824source files and how you can pre-fetch files all of which leads to more
7825efficient use of resources and time.
7826
7827Setting up Effective Mirrors
7828----------------------------
7829
7830A good deal that goes into a Yocto Project build is simply downloading
7831all of the source tarballs. Maybe you have been working with another
7832build system (OpenEmbedded or Angstrom) for which you have built up a
7833sizable directory of source tarballs. Or, perhaps someone else has such
7834a directory for which you have read access. If so, you can save time by
7835adding statements to your configuration file so that the build process
7836checks local directories first for existing tarballs before checking the
7837Internet.
7838
7839Here is an efficient way to set it up in your ``local.conf`` file:
7840::
7841
7842 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7843 INHERIT += "own-mirrors"
7844 BB_GENERATE_MIRROR_TARBALLS = "1"
7845 # BB_NO_NETWORK = "1"
7846
7847In the previous example, the
7848:term:`BB_GENERATE_MIRROR_TARBALLS`
7849variable causes the OpenEmbedded build system to generate tarballs of
7850the Git repositories and store them in the
7851:term:`DL_DIR` directory. Due to
7852performance reasons, generating and storing these tarballs is not the
7853build system's default behavior.
7854
7855You can also use the
7856:term:`PREMIRRORS` variable. For
7857an example, see the variable's glossary entry in the Yocto Project
7858Reference Manual.
7859
7860Getting Source Files and Suppressing the Build
7861----------------------------------------------
7862
7863Another technique you can use to ready yourself for a successive string
7864of build operations, is to pre-fetch all the source files without
7865actually starting a build. This technique lets you work through any
7866download issues and ultimately gathers all the source files into your
7867download directory :ref:`structure-build-downloads`,
7868which is located with :term:`DL_DIR`.
7869
7870Use the following BitBake command form to fetch all the necessary
7871sources without starting the build:
7872::
7873
7874 $ bitbake target --runall=fetch
7875
7876This
7877variation of the BitBake command guarantees that you have all the
7878sources for that BitBake target should you disconnect from the Internet
7879and want to do the build later offline.
7880
7881Selecting an Initialization Manager
7882===================================
7883
7884By default, the Yocto Project uses SysVinit as the initialization
7885manager. However, support also exists for systemd, which is a full
7886replacement for init with parallel starting of services, reduced shell
7887overhead and other features that are used by many distributions.
7888
7889Within the system, SysVinit treats system components as services. These
7890services are maintained as shell scripts stored in the ``/etc/init.d/``
7891directory. Services organize into different run levels. This
7892organization is maintained by putting links to the services in the
7893``/etc/rcN.d/`` directories, where `N/` is one of the following options:
7894"S", "0", "1", "2", "3", "4", "5", or "6".
7895
7896.. note::
7897
7898 Each runlevel has a dependency on the previous runlevel. This
7899 dependency allows the services to work properly.
7900
7901In comparison, systemd treats components as units. Using units is a
7902broader concept as compared to using a service. A unit includes several
7903different types of entities. Service is one of the types of entities.
7904The runlevel concept in SysVinit corresponds to the concept of a target
7905in systemd, where target is also a type of supported unit.
7906
7907In a SysVinit-based system, services load sequentially (i.e. one by one)
7908during init and parallelization is not supported. With systemd, services
7909start in parallel. Needless to say, the method can have an impact on
7910system startup performance.
7911
7912If you want to use SysVinit, you do not have to do anything. But, if you
7913want to use systemd, you must take some steps as described in the
7914following sections.
7915
7916Using systemd Exclusively
7917-------------------------
7918
7919Set these variables in your distribution configuration file as follows:
7920::
7921
7922 DISTRO_FEATURES_append = " systemd"
7923 VIRTUAL-RUNTIME_init_manager = "systemd"
7924
7925You can also prevent the SysVinit distribution feature from
7926being automatically enabled as follows:
7927::
7928
7929 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7930
7931Doing so removes any
7932redundant SysVinit scripts.
7933
7934To remove initscripts from your image altogether, set this variable
7935also:
7936::
7937
7938 VIRTUAL-RUNTIME_initscripts = ""
7939
7940For information on the backfill variable, see
7941:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7942
7943Using systemd for the Main Image and Using SysVinit for the Rescue Image
7944------------------------------------------------------------------------
7945
7946Set these variables in your distribution configuration file as follows:
7947::
7948
7949 DISTRO_FEATURES_append = " systemd"
7950 VIRTUAL-RUNTIME_init_manager = "systemd"
7951
7952Doing so causes your main image to use the
7953``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7954image cannot use this package group. However, it can install SysVinit
7955and the appropriate packages will have support for both systemd and
7956SysVinit.
7957
7958.. _selecting-dev-manager:
7959
7960Selecting a Device Manager
7961==========================
7962
7963The Yocto Project provides multiple ways to manage the device manager
7964(``/dev``):
7965
7966- Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
7967 directory is persistent and the required device nodes are created
7968 during the build.
7969
7970- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7971 directory is provided by the kernel as an in-memory file system and
7972 is automatically populated by the kernel at runtime. Additional
7973 configuration of device nodes is done in user space by a device
7974 manager like ``udev`` or ``busybox-mdev``.
7975
7976.. _static-dev-management:
7977
7978Using Persistent and Pre-Populated\ ``/dev``
7979--------------------------------------------
7980
7981To use the static method for device population, you need to set the
7982:term:`USE_DEVFS` variable to "0"
7983as follows:
7984::
7985
7986 USE_DEVFS = "0"
7987
7988The content of the resulting ``/dev`` directory is defined in a Device
7989Table file. The
7990:term:`IMAGE_DEVICE_TABLES`
7991variable defines the Device Table to use and should be set in the
7992machine or distro configuration file. Alternatively, you can set this
7993variable in your ``local.conf`` configuration file.
7994
7995If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
7996``device_table-minimal.txt`` is used:
7997::
7998
7999 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
8000
8001The population is handled by the ``makedevs`` utility during image
8002creation:
8003
8004.. _devtmpfs-dev-management:
8005
8006Using ``devtmpfs`` and a Device Manager
8007---------------------------------------
8008
8009To use the dynamic method for device population, you need to use (or be
8010sure to set) the :term:`USE_DEVFS`
8011variable to "1", which is the default:
8012::
8013
8014 USE_DEVFS = "1"
8015
8016With this
8017setting, the resulting ``/dev`` directory is populated by the kernel
8018using ``devtmpfs``. Make sure the corresponding kernel configuration
8019variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
8020kernel.
8021
8022All devices created by ``devtmpfs`` will be owned by ``root`` and have
8023permissions ``0600``.
8024
8025To have more control over the device nodes, you can use a device manager
8026like ``udev`` or ``busybox-mdev``. You choose the device manager by
8027defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
8028distro configuration file. Alternatively, you can set this variable in
8029your ``local.conf`` configuration file:
8030::
8031
8032 VIRTUAL-RUNTIME_dev_manager = "udev"
8033
8034 # Some alternative values
8035 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
8036 # VIRTUAL-RUNTIME_dev_manager = "systemd"
8037
8038.. _platdev-appdev-srcrev:
8039
8040Using an External SCM
8041=====================
8042
8043If you're working on a recipe that pulls from an external Source Code
8044Manager (SCM), it is possible to have the OpenEmbedded build system
8045notice new recipe changes added to the SCM and then build the resulting
8046packages that depend on the new recipes by using the latest versions.
8047This only works for SCMs from which it is possible to get a sensible
8048revision number for changes. Currently, you can do this with Apache
8049Subversion (SVN), Git, and Bazaar (BZR) repositories.
8050
8051To enable this behavior, the :term:`PV` of
8052the recipe needs to reference
8053:term:`SRCPV`. Here is an example:
8054::
8055
8056 PV = "1.2.3+git${SRCPV}"
8057
8058Then, you can add the following to your
8059``local.conf``:
8060::
8061
8062 SRCREV_pn-PN = "${AUTOREV}"
8063
8064:term:`PN` is the name of the recipe for
8065which you want to enable automatic source revision updating.
8066
8067If you do not want to update your local configuration file, you can add
8068the following directly to the recipe to finish enabling the feature:
8069::
8070
8071 SRCREV = "${AUTOREV}"
8072
8073The Yocto Project provides a distribution named ``poky-bleeding``, whose
8074configuration file contains the line:
8075::
8076
8077 require conf/distro/include/poky-floating-revisions.inc
8078
8079This line pulls in the
8080listed include file that contains numerous lines of exactly that form:
8081::
8082
8083 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
8084 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
8085 #SRCREV_pn-opkg ?= "${AUTOREV}"
8086 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
8087 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
8088 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
8089 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
8090 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
8091 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
8092 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
8093 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
8094 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
8095 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
8096 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
8097 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
8098 SRCREV_pn-screenshot ?= "${AUTOREV}"
8099 . . .
8100
8101These lines allow you to
8102experiment with building a distribution that tracks the latest
8103development source for numerous packages.
8104
8105.. note::
8106
8107 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
8108 this in mind if you use it.
8109
8110Creating a Read-Only Root Filesystem
8111====================================
8112
8113Suppose, for security reasons, you need to disable your target device's
8114root filesystem's write permissions (i.e. you need a read-only root
8115filesystem). Or, perhaps you are running the device's operating system
8116from a read-only storage device. For either case, you can customize your
8117image for that behavior.
8118
8119.. note::
8120
8121 Supporting a read-only root filesystem requires that the system and
8122 applications do not try to write to the root filesystem. You must
8123 configure all parts of the target system to write elsewhere, or to
8124 gracefully fail in the event of attempting to write to the root
8125 filesystem.
8126
8127Creating the Root Filesystem
8128----------------------------
8129
8130To create the read-only root filesystem, simply add the
8131"read-only-rootfs" feature to your image, normally in one of two ways.
8132The first way is to add the "read-only-rootfs" image feature in the
8133image's recipe file via the ``IMAGE_FEATURES`` variable:
8134::
8135
8136 IMAGE_FEATURES += "read-only-rootfs"
8137
8138As an alternative, you can add the same feature
8139from within your build directory's ``local.conf`` file with the
8140associated ``EXTRA_IMAGE_FEATURES`` variable, as in:
8141::
8142
8143 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
8144
8145For more information on how to use these variables, see the
8146":ref:`usingpoky-extend-customimage-imagefeatures`"
8147section. For information on the variables, see
8148:term:`IMAGE_FEATURES` and
8149:term:`EXTRA_IMAGE_FEATURES`.
8150
8151Post-Installation Scripts and Read-Only Root Filesystem
8152-------------------------------------------------------
8153
8154It is very important that you make sure all post-Installation
8155(``pkg_postinst``) scripts for packages that are installed into the
8156image can be run at the time when the root filesystem is created during
8157the build on the host system. These scripts cannot attempt to run during
8158first-boot on the target device. With the "read-only-rootfs" feature
8159enabled, the build system checks during root filesystem creation to make
8160sure all post-installation scripts succeed. If any of these scripts
8161still need to be run after the root filesystem is created, the build
8162immediately fails. These build-time checks ensure that the build fails
8163rather than the target device fails later during its initial boot
8164operation.
8165
8166Most of the common post-installation scripts generated by the build
8167system for the out-of-the-box Yocto Project are engineered so that they
8168can run during root filesystem creation (e.g. post-installation scripts
8169for caching fonts). However, if you create and add custom scripts, you
8170need to be sure they can be run during this file system creation.
8171
8172Here are some common problems that prevent post-installation scripts
8173from running during root filesystem creation:
8174
8175- *Not using $D in front of absolute paths:* The build system defines
8176 ``$``\ :term:`D` when the root
8177 filesystem is created. Furthermore, ``$D`` is blank when the script
8178 is run on the target device. This implies two purposes for ``$D``:
8179 ensuring paths are valid in both the host and target environments,
8180 and checking to determine which environment is being used as a method
8181 for taking appropriate actions.
8182
8183- *Attempting to run processes that are specific to or dependent on the
8184 target architecture:* You can work around these attempts by using
8185 native tools, which run on the host system, to accomplish the same
8186 tasks, or by alternatively running the processes under QEMU, which
8187 has the ``qemu_run_binary`` function. For more information, see the
8188 :ref:`qemu <ref-classes-qemu>` class.
8189
8190Areas With Write Access
8191-----------------------
8192
8193With the "read-only-rootfs" feature enabled, any attempt by the target
8194to write to the root filesystem at runtime fails. Consequently, you must
8195make sure that you configure processes and applications that attempt
8196these types of writes do so to directories with write access (e.g.
8197``/tmp`` or ``/var/run``).
8198
8199Maintaining Build Output Quality
8200================================
8201
8202Many factors can influence the quality of a build. For example, if you
8203upgrade a recipe to use a new version of an upstream software package or
8204you experiment with some new configuration options, subtle changes can
8205occur that you might not detect until later. Consider the case where
8206your recipe is using a newer version of an upstream package. In this
8207case, a new version of a piece of software might introduce an optional
8208dependency on another library, which is auto-detected. If that library
8209has already been built when the software is building, the software will
8210link to the built library and that library will be pulled into your
8211image along with the new software even if you did not want the library.
8212
8213The :ref:`buildhistory <ref-classes-buildhistory>`
8214class exists to help you maintain the quality of your build output. You
8215can use the class to highlight unexpected and possibly unwanted changes
8216in the build output. When you enable build history, it records
8217information about the contents of each package and image and then
8218commits that information to a local Git repository where you can examine
8219the information.
8220
8221The remainder of this section describes the following:
8222
8223- :ref:`How you can enable and disable build history <dev-manual/dev-manual-common-tasks:enabling and disabling build history>`
8224
8225- :ref:`How to understand what the build history contains <dev-manual/dev-manual-common-tasks:understanding what the build history contains>`
8226
8227- :ref:`How to limit the information used for build history <dev-manual/dev-manual-common-tasks:using build history to gather image information only>`
8228
8229- :ref:`How to examine the build history from both a command-line and web interface <dev-manual/dev-manual-common-tasks:examining build history information>`
8230
8231Enabling and Disabling Build History
8232------------------------------------
8233
8234Build history is disabled by default. To enable it, add the following
8235``INHERIT`` statement and set the
8236:term:`BUILDHISTORY_COMMIT`
8237variable to "1" at the end of your ``conf/local.conf`` file found in the
8238:term:`Build Directory`:
8239::
8240
8241 INHERIT += "buildhistory"
8242 BUILDHISTORY_COMMIT = "1"
8243
8244Enabling build history as
8245previously described causes the OpenEmbedded build system to collect
8246build output information and commit it as a single commit to a local
8247:ref:`overview-manual/overview-manual-development-environment:git` repository.
8248
8249.. note::
8250
8251 Enabling build history increases your build times slightly,
8252 particularly for images, and increases the amount of disk space used
8253 during the build.
8254
8255You can disable build history by removing the previous statements from
8256your ``conf/local.conf`` file.
8257
8258Understanding What the Build History Contains
8259---------------------------------------------
8260
8261Build history information is kept in
8262``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8263in the Build Directory as defined by the
8264:term:`BUILDHISTORY_DIR`
8265variable. The following is an example abbreviated listing:
8266
8267.. image:: figures/buildhistory.png
8268 :align: center
8269
8270At the top level, a ``metadata-revs`` file exists that lists the
8271revisions of the repositories for the enabled layers when the build was
8272produced. The rest of the data splits into separate ``packages``,
8273``images`` and ``sdk`` directories, the contents of which are described
8274as follows.
8275
8276Build History Package Information
8277~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8278
8279The history for each package contains a text file that has name-value
8280pairs with information about the package. For example,
8281``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8282contains the following:
8283
8284.. code-block:: none
8285
8286 PV = 1.22.1
8287 PR = r32
8288 RPROVIDES =
8289 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8290 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8291 PKGSIZE = 540168
8292 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8293 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8294 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8295 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8296 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8297 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8298 /etc/busybox.links.nosuid /etc/busybox.links.suid
8299
8300Most of these
8301name-value pairs correspond to variables used to produce the package.
8302The exceptions are ``FILELIST``, which is the actual list of files in
8303the package, and ``PKGSIZE``, which is the total size of files in the
8304package in bytes.
8305
8306A file also exists that corresponds to the recipe from which the package
8307came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
8308
8309.. code-block:: none
8310
8311 PV = 1.22.1
8312 PR = r32
8313 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8314 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8315 virtual/libc virtual/update-alternatives
8316 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8317 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8318 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8319
8320Finally, for those recipes fetched from a version control system (e.g.,
8321Git), a file exists that lists source revisions that are specified in
8322the recipe and lists the actual revisions used during the build. Listed
8323and actual revisions might differ when
8324:term:`SRCREV` is set to
8325${:term:`AUTOREV`}. Here is an
8326example assuming
8327``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):
8328::
8329
8330 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8331 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8332 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8333 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8334
8335You can use the
8336``buildhistory-collect-srcrevs`` command with the ``-a`` option to
8337collect the stored ``SRCREV`` values from build history and report them
8338in a format suitable for use in global configuration (e.g.,
8339``local.conf`` or a distro include file) to override floating
8340``AUTOREV`` values to a fixed set of revisions. Here is some example
8341output from this command:
8342::
8343
8344 $ buildhistory-collect-srcrevs -a
8345 # i586-poky-linux
8346 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
8347 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
8348 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
8349 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8350 # x86_64-linux
8351 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
8352 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
8353 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
8354 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
8355 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
8356 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
8357 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
8358 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
8359 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8360 # qemux86-poky-linux
8361 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8362 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
8363 # all-poky-linux
8364 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
8365
8366.. note::
8367
8368 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
8369
8370 - By default, only values where the ``SRCREV`` was not hardcoded
8371 (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
8372 option to see all ``SRCREV`` values.
8373
8374 - The output statements might not have any effect if overrides are
8375 applied elsewhere in the build system configuration. Use the
8376 ``-f`` option to add the ``forcevariable`` override to each output
8377 line if you need to work around this restriction.
8378
8379 - The script does apply special handling when building for multiple
8380 machines. However, the script does place a comment before each set
8381 of values that specifies which triplet to which they belong as
8382 previously shown (e.g., ``i586-poky-linux``).
8383
8384Build History Image Information
8385~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8386
8387The files produced for each image are as follows:
8388
8389- ``image-files:`` A directory containing selected files from the root
8390 filesystem. The files are defined by
8391 :term:`BUILDHISTORY_IMAGE_FILES`.
8392
8393- ``build-id.txt:`` Human-readable information about the build
8394 configuration and metadata source revisions. This file contains the
8395 full build header as printed by BitBake.
8396
8397- ``*.dot:`` Dependency graphs for the image that are compatible with
8398 ``graphviz``.
8399
8400- ``files-in-image.txt:`` A list of files in the image with
8401 permissions, owner, group, size, and symlink information.
8402
8403- ``image-info.txt:`` A text file containing name-value pairs with
8404 information about the image. See the following listing example for
8405 more information.
8406
8407- ``installed-package-names.txt:`` A list of installed packages by name
8408 only.
8409
8410- ``installed-package-sizes.txt:`` A list of installed packages ordered
8411 by size.
8412
8413- ``installed-packages.txt:`` A list of installed packages with full
8414 package filenames.
8415
8416.. note::
8417
8418 Installed package information is able to be gathered and produced
8419 even if package management is disabled for the final image.
8420
8421Here is an example of ``image-info.txt``:
8422
8423.. code-block:: none
8424
8425 DISTRO = poky
8426 DISTRO_VERSION = 1.7
8427 USER_CLASSES = buildstats image-mklibs image-prelink
8428 IMAGE_CLASSES = image_types
8429 IMAGE_FEATURES = debug-tweaks
8430 IMAGE_LINGUAS =
8431 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
8432 BAD_RECOMMENDATIONS =
8433 NO_RECOMMENDATIONS =
8434 PACKAGE_EXCLUDE =
8435 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
8436 write_image_manifest ; buildhistory_list_installed_image ; \
8437 buildhistory_get_image_installed ; ssh_allow_empty_password; \
8438 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
8439 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8440 IMAGESIZE = 6900
8441
8442Other than ``IMAGESIZE``,
8443which is the total size of the files in the image in Kbytes, the
8444name-value pairs are variables that may have influenced the content of
8445the image. This information is often useful when you are trying to
8446determine why a change in the package or file listings has occurred.
8447
8448Using Build History to Gather Image Information Only
8449~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8450
8451As you can see, build history produces image information, including
8452dependency graphs, so you can see why something was pulled into the
8453image. If you are just interested in this information and not interested
8454in collecting specific package or SDK information, you can enable
8455writing only image information without any history by adding the
8456following to your ``conf/local.conf`` file found in the
8457:term:`Build Directory`:
8458::
8459
8460 INHERIT += "buildhistory"
8461 BUILDHISTORY_COMMIT = "0"
8462 BUILDHISTORY_FEATURES = "image"
8463
8464Here, you set the
8465:term:`BUILDHISTORY_FEATURES`
8466variable to use the image feature only.
8467
8468Build History SDK Information
8469~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8470
8471Build history collects similar information on the contents of SDKs (e.g.
8472``bitbake -c populate_sdk imagename``) as compared to information it
8473collects for images. Furthermore, this information differs depending on
8474whether an extensible or standard SDK is being produced.
8475
8476The following list shows the files produced for SDKs:
8477
8478- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8479 owner, group, size, and symlink information. This list includes both
8480 the host and target parts of the SDK.
8481
8482- ``sdk-info.txt:`` A text file containing name-value pairs with
8483 information about the SDK. See the following listing example for more
8484 information.
8485
8486- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8487 with information about task group sizes (e.g. ``do_populate_sysroot``
8488 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8489 only when an extensible SDK is created.
8490
8491- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8492 with information for the shared-state packages and sizes in the SDK.
8493 The ``sstate-package-sizes.txt`` file exists only when an extensible
8494 SDK is created.
8495
8496- ``sdk-files:`` A folder that contains copies of the files mentioned
8497 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8498 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8499 specific to the extensible SDK although you can set it differently if
8500 you would like to pull in specific files from the standard SDK.
8501
8502 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8503 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8504 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8505 copied into the ``sdk-files`` directory.
8506
8507- The following information appears under each of the ``host`` and
8508 ``target`` directories for the portions of the SDK that run on the
8509 host and on the target, respectively:
8510
8511 .. note::
8512
8513 The following files for the most part are empty when producing an
8514 extensible SDK because this type of SDK is not constructed from
8515 packages as is the standard SDK.
8516
8517 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8518 with ``graphviz``.
8519
8520 - ``installed-package-names.txt:`` A list of installed packages by
8521 name only.
8522
8523 - ``installed-package-sizes.txt:`` A list of installed packages
8524 ordered by size.
8525
8526 - ``installed-packages.txt:`` A list of installed packages with full
8527 package filenames.
8528
8529Here is an example of ``sdk-info.txt``:
8530
8531.. code-block:: none
8532
8533 DISTRO = poky
8534 DISTRO_VERSION = 1.3+snapshot-20130327
8535 SDK_NAME = poky-glibc-i686-arm
8536 SDK_VERSION = 1.3+snapshot
8537 SDKMACHINE =
8538 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8539 BAD_RECOMMENDATIONS =
8540 SDKSIZE = 352712
8541
8542Other than ``SDKSIZE``, which is
8543the total size of the files in the SDK in Kbytes, the name-value pairs
8544are variables that might have influenced the content of the SDK. This
8545information is often useful when you are trying to determine why a
8546change in the package or file listings has occurred.
8547
8548Examining Build History Information
8549~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8550
8551You can examine build history output from the command line or from a web
8552interface.
8553
8554To see any changes that have occurred (assuming you have
8555:term:`BUILDHISTORY_COMMIT` = "1"),
8556you can simply use any Git command that allows you to view the history
8557of a repository. Here is one method:
8558::
8559
8560 $ git log -p
8561
8562You need to realize,
8563however, that this method does show changes that are not significant
8564(e.g. a package's size changing by a few bytes).
8565
8566A command-line tool called ``buildhistory-diff`` does exist, though,
8567that queries the Git repository and prints just the differences that
8568might be significant in human-readable form. Here is an example:
8569::
8570
8571 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
8572 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8573 /etc/anotherpkg.conf was added
8574 /sbin/anotherpkg was added
8575 * (installed-package-names.txt):
8576 * anotherpkg was added
8577 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8578 anotherpkg was added
8579 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8580 * PR changed from "r0" to "r1"
8581 * PV changed from "0.1.10" to "0.1.12"
8582 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8583 * PR changed from "r0" to "r1"
8584 * PV changed from "0.1.10" to "0.1.12"
8585
8586.. note::
8587
8588 The ``buildhistory-diff`` tool requires the ``GitPython``
8589 package. Be sure to install it using Pip3 as follows:
8590 ::
8591
8592 $ pip3 install GitPython --user
8593
8594
8595 Alternatively, you can install ``python3-git`` using the appropriate
8596 distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
8597
8598To see changes to the build history using a web interface, follow the
8599instruction in the ``README`` file
8600:yocto_git:`here </cgit/cgit.cgi/buildhistory-web/>`.
8601
8602Here is a sample screenshot of the interface:
8603
8604.. image:: figures/buildhistory-web.png
8605 :align: center
8606
8607Performing Automated Runtime Testing
8608====================================
8609
8610The OpenEmbedded build system makes available a series of automated
8611tests for images to verify runtime functionality. You can run these
8612tests on either QEMU or actual target hardware. Tests are written in
8613Python making use of the ``unittest`` module, and the majority of them
8614run commands on the target system over SSH. This section describes how
8615you set up the environment to use these tests, run available tests, and
8616write and add your own tests.
8617
8618For information on the test and QA infrastructure available within the
8619Yocto Project, see the ":ref:`ref-manual/ref-release-process:testing and quality assurance`"
8620section in the Yocto Project Reference Manual.
8621
8622Enabling Tests
8623--------------
8624
8625Depending on whether you are planning to run tests using QEMU or on the
8626hardware, you have to take different steps to enable the tests. See the
8627following subsections for information on how to enable both types of
8628tests.
8629
8630.. _qemu-image-enabling-tests:
8631
8632Enabling Runtime Tests on QEMU
8633~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8634
8635In order to run tests, you need to do the following:
8636
8637- *Set up to avoid interaction with sudo for networking:* To
8638 accomplish this, you must do one of the following:
8639
8640 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8641 commands or just for ``runqemu-ifup``. You must provide the full
8642 path as that can change if you are using multiple clones of the
8643 source repository.
8644
8645 .. note::
8646
8647 On some distributions, you also need to comment out "Defaults
8648 requiretty" in ``/etc/sudoers``.
8649
8650 - Manually configure a tap interface for your system.
8651
8652 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8653 should generate a list of tap devices. This is the option
8654 typically chosen for Autobuilder-type environments.
8655
8656 .. note::
8657
8658 - Be sure to use an absolute path when calling this script
8659 with sudo.
8660
8661 - The package recipe ``qemu-helper-native`` is required to run
8662 this script. Build the package using the following command:
8663 ::
8664
8665 $ bitbake qemu-helper-native
8666
8667- *Set the DISPLAY variable:* You need to set this variable so that
8668 you have an X server available (e.g. start ``vncserver`` for a
8669 headless machine).
8670
8671- *Be sure your host's firewall accepts incoming connections from
8672 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8673 HTTP server on a random high number port, which is used to serve
8674 files to the target. The DNF module serves
8675 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8676 That means your host's firewall must accept incoming connections from
8677 192.168.7.0/24, which is the default IP range used for tap devices by
8678 ``runqemu``.
8679
8680- *Be sure your host has the correct packages installed:* Depending
8681 your host's distribution, you need to have the following packages
8682 installed:
8683
8684 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8685
8686 - OpenSUSE: ``sysstat`` and ``iproute2``
8687
8688 - Fedora: ``sysstat`` and ``iproute``
8689
8690 - CentOS: ``sysstat`` and ``iproute``
8691
8692Once you start running the tests, the following happens:
8693
86941. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8695
86962. The image is booted under QEMU using the standard ``runqemu`` script.
8697
86983. A default timeout of 500 seconds occurs to allow for the boot process
8699 to reach the login prompt. You can change the timeout period by
8700 setting
8701 :term:`TEST_QEMUBOOT_TIMEOUT`
8702 in the ``local.conf`` file.
8703
87044. Once the boot process is reached and the login prompt appears, the
8705 tests run. The full boot log is written to
8706 ``${WORKDIR}/testimage/qemu_boot_log``.
8707
87085. Each test module loads in the order found in ``TEST_SUITES``. You can
8709 find the full output of the commands run over SSH in
8710 ``${WORKDIR}/testimgage/ssh_target_log``.
8711
87126. If no failures occur, the task running the tests ends successfully.
8713 You can find the output from the ``unittest`` in the task log at
8714 ``${WORKDIR}/temp/log.do_testimage``.
8715
8716.. _hardware-image-enabling-tests:
8717
8718Enabling Runtime Tests on Hardware
8719~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8720
8721The OpenEmbedded build system can run tests on real hardware, and for
8722certain devices it can also deploy the image to be tested onto the
8723device beforehand.
8724
8725For automated deployment, a "master image" is installed onto the
8726hardware once as part of setup. Then, each time tests are to be run, the
8727following occurs:
8728
87291. The master image is booted into and used to write the image to be
8730 tested to a second partition.
8731
87322. The device is then rebooted using an external script that you need to
8733 provide.
8734
87353. The device boots into the image to be tested.
8736
8737When running tests (independent of whether the image has been deployed
8738automatically or not), the device is expected to be connected to a
8739network on a pre-determined IP address. You can either use static IP
8740addresses written into the image, or set the image to use DHCP and have
8741your DHCP server on the test network assign a known IP address based on
8742the MAC address of the device.
8743
8744In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
8745appropriate value. For QEMU, you do not have to change anything, the
8746default value is "qemu". For running tests on hardware, the following
8747options exist:
8748
8749- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8750 on a target system that is already running the image to be tested and
8751 is available on the network. You can use "simpleremote" in
8752 conjunction with either real hardware or an image running within a
8753 separately started QEMU or any other virtual machine manager.
8754
8755- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8756 an EFI-based machine with ``systemd-boot`` as bootloader and
8757 ``core-image-testmaster`` (or something similar) is installed. Also,
8758 your hardware under test must be in a DHCP-enabled network that gives
8759 it the same IP address for each reboot.
8760
8761 If you choose "SystemdbootTarget", there are additional requirements
8762 and considerations. See the "`Selecting
8763 SystemdbootTarget <#selecting-systemdboottarget>`__" section, which
8764 follows, for more information.
8765
8766- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8767 images and running tests on the BeagleBone "Black" or original
8768 "White" hardware. For information on how to use these tests, see the
8769 comments at the top of the BeagleBoneTarget
8770 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8771
8772- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
8773 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8774 For information on how to use these tests, see the comments at the
8775 top of the EdgeRouterTarget
8776 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8777
8778- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
8779 tests on any generic PC that boots using GRUB. For information on how
8780 to use these tests, see the comments at the top of the GrubTarget
8781 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8782
8783- *"your-target":* Create your own custom target if you want to run
8784 tests when you are deploying images and running tests on a custom
8785 machine within your BSP layer. To do this, you need to add a Python
8786 unit that defines the target class under ``lib/oeqa/controllers/``
8787 within your layer. You must also provide an empty ``__init__.py``.
8788 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8789
8790Selecting SystemdbootTarget
8791~~~~~~~~~~~~~~~~~~~~~~~~~~~
8792
8793If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
8794not need any information in this section. You can skip down to the
8795"`Running Tests <#qemu-image-running-tests>`__" section.
8796
8797If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
8798perform a one-time setup of your master image by doing the following:
8799
88001. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows:
8801 ::
8802
8803 EFI_PROVIDER = "systemd-boot"
8804
88052. *Build the master image:* Build the ``core-image-testmaster`` image.
8806 The ``core-image-testmaster`` recipe is provided as an example for a
8807 "master" image and you can customize the image recipe as you would
8808 any other recipe.
8809
8810 Here are the image recipe requirements:
8811
8812 - Inherits ``core-image`` so that kernel modules are installed.
8813
8814 - Installs normal linux utilities not busybox ones (e.g. ``bash``,
8815 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8816
8817 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8818 installer. A normal image that you can install usually creates a
8819 single rootfs partition. This image uses another installer that
8820 creates a specific partition layout. Not all Board Support
8821 Packages (BSPs) can use an installer. For such cases, you need to
8822 manually create the following partition layout on the target:
8823
8824 - First partition mounted under ``/boot``, labeled "boot".
8825
8826 - The main rootfs partition where this image gets installed,
8827 which is mounted under ``/``.
8828
8829 - Another partition labeled "testrootfs" where test images get
8830 deployed.
8831
88323. *Install image:* Install the image that you just built on the target
8833 system.
8834
8835The final thing you need to do when setting ``TEST_TARGET`` to
8836"SystemdbootTarget" is to set up the test image:
8837
88381. *Set up your local.conf file:* Make sure you have the following
8839 statements in your ``local.conf`` file:
8840 ::
8841
8842 IMAGE_FSTYPES += "tar.gz"
8843 INHERIT += "testimage"
8844 TEST_TARGET = "SystemdbootTarget"
8845 TEST_TARGET_IP = "192.168.2.3"
8846
88472. *Build your test image:* Use BitBake to build the image:
8848 ::
8849
8850 $ bitbake core-image-sato
8851
8852Power Control
8853~~~~~~~~~~~~~
8854
8855For most hardware targets other than "simpleremote", you can control
8856power:
8857
8858- You can use ``TEST_POWERCONTROL_CMD`` together with
8859 ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
8860 and does power cycling. The test code passes one argument to that
8861 command: off, on or cycle (off then on). Here is an example that
8862 could appear in your ``local.conf`` file:
8863 ::
8864
8865 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8866
8867 In this example, the expect
8868 script does the following:
8869
8870 .. code-block:: shell
8871
8872 ssh test@10.11.12.1 "pyctl nuc1 arg"
8873
8874 It then runs a Python script that controls power for a label called
8875 ``nuc1``.
8876
8877 .. note::
8878
8879 You need to customize ``TEST_POWERCONTROL_CMD`` and
8880 ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
8881 is that it accepts "on", "off", and "cycle" as the last argument.
8882
8883- When no command is defined, it connects to the device over SSH and
8884 uses the classic reboot command to reboot the device. Classic reboot
8885 is fine as long as the machine actually reboots (i.e. the SSH test
8886 has not failed). It is useful for scenarios where you have a simple
8887 setup, typically with a single board, and where some manual
8888 interaction is okay from time to time.
8889
8890If you have no hardware to automatically perform power control but still
8891wish to experiment with automated hardware testing, you can use the
8892``dialog-power-control`` script that shows a dialog prompting you to perform
8893the required power action. This script requires either KDialog or Zenity
8894to be installed. To use this script, set the
8895:term:`TEST_POWERCONTROL_CMD`
8896variable as follows:
8897::
8898
8899 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8900
8901Serial Console Connection
8902~~~~~~~~~~~~~~~~~~~~~~~~~
8903
8904For test target classes requiring a serial console to interact with the
8905bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8906you need to specify a command to use to connect to the serial console of
8907the target machine by using the
8908:term:`TEST_SERIALCONTROL_CMD`
8909variable and optionally the
8910:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8911variable.
8912
8913These cases could be a serial terminal program if the machine is
8914connected to a local serial port, or a ``telnet`` or ``ssh`` command
8915connecting to a remote console server. Regardless of the case, the
8916command simply needs to connect to the serial console and forward that
8917connection to standard input and output as any normal terminal program
8918does. For example, to use the picocom terminal program on serial device
8919``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:
8920::
8921
8922 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8923
8924For local
8925devices where the serial port device disappears when the device reboots,
8926an additional "serdevtry" wrapper script is provided. To use this
8927wrapper, simply prefix the terminal command with
8928``${COREBASE}/scripts/contrib/serdevtry``:
8929::
8930
8931 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8932
8933.. _qemu-image-running-tests:
8934
8935Running Tests
8936-------------
8937
8938You can start the tests automatically or manually:
8939
8940- *Automatically running tests:* To run the tests automatically after
8941 the OpenEmbedded build system successfully creates an image, first
8942 set the
8943 :term:`TESTIMAGE_AUTO`
8944 variable to "1" in your ``local.conf`` file in the
8945 :term:`Build Directory`:
8946 ::
8947
8948 TESTIMAGE_AUTO = "1"
8949
8950 Next, build your image. If the image successfully builds, the
8951 tests run:
8952 ::
8953
8954 bitbake core-image-sato
8955
8956- *Manually running tests:* To manually run the tests, first globally
8957 inherit the
8958 :ref:`testimage <ref-classes-testimage*>` class
8959 by editing your ``local.conf`` file:
8960 ::
8961
8962 INHERIT += "testimage"
8963
8964 Next, use BitBake to run the tests:
8965 ::
8966
8967 bitbake -c testimage image
8968
8969All test files reside in ``meta/lib/oeqa/runtime`` in the
8970:term:`Source Directory`. A test name maps
8971directly to a Python module. Each test module may contain a number of
8972individual tests. Tests are usually grouped together by the area tested
8973(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8974
8975You can add tests to any layer provided you place them in the proper
8976area and you extend :term:`BBPATH` in
8977the ``local.conf`` file as normal. Be sure that tests reside in
8978``layer/lib/oeqa/runtime``.
8979
8980.. note::
8981
8982 Be sure that module names do not collide with module names used in
8983 the default set of test modules in ``meta/lib/oeqa/runtime``.
8984
8985You can change the set of tests run by appending or overriding
8986:term:`TEST_SUITES` variable in
8987``local.conf``. Each name in ``TEST_SUITES`` represents a required test
8988for the image. Test modules named within ``TEST_SUITES`` cannot be
8989skipped even if a test is not suitable for an image (e.g. running the
8990RPM tests on an image without ``rpm``). Appending "auto" to
8991``TEST_SUITES`` causes the build system to try to run all tests that are
8992suitable for the image (i.e. each test module may elect to skip itself).
8993
8994The order you list tests in ``TEST_SUITES`` is important and influences
8995test dependencies. Consequently, tests that depend on other tests should
8996be added after the test on which they depend. For example, since the
8997``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8998"ping" in the list. The test class provides no re-ordering or dependency
8999handling.
9000
9001.. note::
9002
9003 Each module can have multiple classes with multiple test methods.
9004 And, Python ``unittest`` rules apply.
9005
9006Here are some things to keep in mind when running tests:
9007
9008- The default tests for the image are defined as:
9009 ::
9010
9011 DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
9012
9013- Add your own test to the list of the by using the following:
9014 ::
9015
9016 TEST_SUITES_append = " mytest"
9017
9018- Run a specific list of tests as follows:
9019 ::
9020
9021 TEST_SUITES = "test1 test2 test3"
9022
9023 Remember, order is important. Be sure to place a test that is
9024 dependent on another test later in the order.
9025
9026Exporting Tests
9027---------------
9028
9029You can export tests so that they can run independently of the build
9030system. Exporting tests is required if you want to be able to hand the
9031test execution off to a scheduler. You can only export tests that are
9032defined in :term:`TEST_SUITES`.
9033
9034If your image is already built, make sure the following are set in your
9035``local.conf`` file:
9036::
9037
9038 INHERIT += "testexport"
9039 TEST_TARGET_IP = "IP-address-for-the-test-target"
9040 TEST_SERVER_IP = "IP-address-for-the-test-server"
9041
9042You can then export the tests with the
9043following BitBake command form:
9044::
9045
9046 $ bitbake image -c testexport
9047
9048Exporting the tests places them in the
9049:term:`Build Directory` in
9050``tmp/testexport/``\ image, which is controlled by the
9051``TEST_EXPORT_DIR`` variable.
9052
9053You can now run the tests outside of the build environment:
9054::
9055
9056 $ cd tmp/testexport/image
9057 $ ./runexported.py testdata.json
9058
9059Here is a complete example that shows IP addresses and uses the
9060``core-image-sato`` image:
9061::
9062
9063 INHERIT += "testexport"
9064 TEST_TARGET_IP = "192.168.7.2"
9065 TEST_SERVER_IP = "192.168.7.1"
9066
9067Use BitBake to export the tests:
9068::
9069
9070 $ bitbake core-image-sato -c testexport
9071
9072Run the tests outside of
9073the build environment using the following:
9074::
9075
9076 $ cd tmp/testexport/core-image-sato
9077 $ ./runexported.py testdata.json
9078
9079.. _qemu-image-writing-new-tests:
9080
9081Writing New Tests
9082-----------------
9083
9084As mentioned previously, all new test files need to be in the proper
9085place for the build system to find them. New tests for additional
9086functionality outside of the core should be added to the layer that adds
9087the functionality, in ``layer/lib/oeqa/runtime`` (as long as
9088:term:`BBPATH` is extended in the
9089layer's ``layer.conf`` file as normal). Just remember the following:
9090
9091- Filenames need to map directly to test (module) names.
9092
9093- Do not use module names that collide with existing core tests.
9094
9095- Minimally, an empty ``__init__.py`` file must exist in the runtime
9096 directory.
9097
9098To create a new test, start by copying an existing module (e.g.
9099``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
9100code from ``meta/lib/oeqa/utils``, which are helper classes.
9101
9102.. note::
9103
9104 Structure shell commands such that you rely on them and they return a
9105 single code for success. Be aware that sometimes you will need to
9106 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
9107
9108You will notice that all test classes inherit ``oeRuntimeTest``, which
9109is found in ``meta/lib/oetest.py``. This base class offers some helper
9110attributes, which are described in the following sections:
9111
9112.. _qemu-image-writing-tests-class-methods:
9113
9114Class Methods
9115~~~~~~~~~~~~~
9116
9117Class methods are as follows:
9118
9119- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
9120 package list of the image, which is based on the manifest file that
9121 is generated during the ``do_rootfs`` task.
9122
9123- *hasFeature(feature):* Returns "True" if the feature is in
9124 :term:`IMAGE_FEATURES` or
9125 :term:`DISTRO_FEATURES`.
9126
9127.. _qemu-image-writing-tests-class-attributes:
9128
9129Class Attributes
9130~~~~~~~~~~~~~~~~
9131
9132Class attributes are as follows:
9133
9134- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
9135 Otherwise, ``pscmd`` equals "ps" (busybox).
9136
9137- *tc:* The called test context, which gives access to the
9138 following attributes:
9139
9140 - *d:* The BitBake datastore, which allows you to use stuff such
9141 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
9142
9143 - *testslist and testsrequired:* Used internally. The tests
9144 do not need these.
9145
9146 - *filesdir:* The absolute path to
9147 ``meta/lib/oeqa/runtime/files``, which contains helper files for
9148 tests meant for copying on the target such as small files written
9149 in C for compilation.
9150
9151 - *target:* The target controller object used to deploy and
9152 start an image on a particular target (e.g. Qemu, SimpleRemote,
9153 and SystemdbootTarget). Tests usually use the following:
9154
9155 - *ip:* The target's IP address.
9156
9157 - *server_ip:* The host's IP address, which is usually used
9158 by the DNF test suite.
9159
9160 - *run(cmd, timeout=None):* The single, most used method.
9161 This command is a wrapper for: ``ssh root@host "cmd"``. The
9162 command returns a tuple: (status, output), which are what their
9163 names imply - the return code of "cmd" and whatever output it
9164 produces. The optional timeout argument represents the number
9165 of seconds the test should wait for "cmd" to return. If the
9166 argument is "None", the test uses the default instance's
9167 timeout period, which is 300 seconds. If the argument is "0",
9168 the test runs until the command returns.
9169
9170 - *copy_to(localpath, remotepath):*
9171 ``scp localpath root@ip:remotepath``.
9172
9173 - *copy_from(remotepath, localpath):*
9174 ``scp root@host:remotepath localpath``.
9175
9176.. _qemu-image-writing-tests-instance-attributes:
9177
9178Instance Attributes
9179~~~~~~~~~~~~~~~~~~~
9180
9181A single instance attribute exists, which is ``target``. The ``target``
9182instance attribute is identical to the class attribute of the same name,
9183which is described in the previous section. This attribute exists as
9184both an instance and class attribute so tests can use
9185``self.target.run(cmd)`` in instance methods instead of
9186``oeRuntimeTest.tc.target.run(cmd)``.
9187
9188Installing Packages in the DUT Without the Package Manager
9189----------------------------------------------------------
9190
9191When a test requires a package built by BitBake, it is possible to
9192install that package. Installing the package does not require a package
9193manager be installed in the device under test (DUT). It does, however,
9194require an SSH connection and the target must be using the
9195``sshcontrol`` class.
9196
9197.. note::
9198
9199 This method uses ``scp`` to copy files from the host to the target, which
9200 causes permissions and special attributes to be lost.
9201
9202A JSON file is used to define the packages needed by a test. This file
9203must be in the same path as the file used to define the tests.
9204Furthermore, the filename must map directly to the test module name with
9205a ``.json`` extension.
9206
9207The JSON file must include an object with the test name as keys of an
9208object or an array. This object (or array of objects) uses the following
9209data:
9210
9211- "pkg" - A mandatory string that is the name of the package to be
9212 installed.
9213
9214- "rm" - An optional boolean, which defaults to "false", that specifies
9215 to remove the package after the test.
9216
9217- "extract" - An optional boolean, which defaults to "false", that
9218 specifies if the package must be extracted from the package format.
9219 When set to "true", the package is not automatically installed into
9220 the DUT.
9221
9222Following is an example JSON file that handles test "foo" installing
9223package "bar" and test "foobar" installing packages "foo" and "bar".
9224Once the test is complete, the packages are removed from the DUT.
9225::
9226
9227 {
9228 "foo": {
9229 "pkg": "bar"
9230 },
9231 "foobar": [
9232 {
9233 "pkg": "foo",
9234 "rm": true
9235 },
9236 {
9237 "pkg": "bar",
9238 "rm": true
9239 }
9240 ]
9241 }
9242
9243.. _usingpoky-debugging-tools-and-techniques:
9244
9245Debugging Tools and Techniques
9246==============================
9247
9248The exact method for debugging build failures depends on the nature of
9249the problem and on the system's area from which the bug originates.
9250Standard debugging practices such as comparison against the last known
9251working version with examination of the changes and the re-application
9252of steps to identify the one causing the problem are valid for the Yocto
9253Project just as they are for any other system. Even though it is
9254impossible to detail every possible potential failure, this section
9255provides some general tips to aid in debugging given a variety of
9256situations.
9257
9258.. note::
9259
9260 A useful feature for debugging is the error reporting tool.
9261 Configuring the Yocto Project to use this tool causes the
9262 OpenEmbedded build system to produce error reporting commands as part
9263 of the console output. You can enter the commands after the build
9264 completes to log error information into a common database, that can
9265 help you figure out what might be going wrong. For information on how
9266 to enable and use this feature, see the
9267 ":ref:`dev-manual/dev-manual-common-tasks:using the error reporting tool`"
9268 section.
9269
9270The following list shows the debugging topics in the remainder of this
9271section:
9272
9273- "`Viewing Logs from Failed
9274 Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes
9275 how to find and view logs from tasks that failed during the build
9276 process.
9277
9278- "`Viewing Variable
9279 Values <#dev-debugging-viewing-variable-values>`__" describes how to
9280 use the BitBake ``-e`` option to examine variable values after a
9281 recipe has been parsed.
9282
9283- ":ref:`dev-manual/dev-manual-common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
9284 describes how to use the ``oe-pkgdata-util`` utility to query
9285 :term:`PKGDATA_DIR` and
9286 display package-related information for built packages.
9287
9288- "`Viewing Dependencies Between Recipes and
9289 Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__"
9290 describes how to use the BitBake ``-g`` option to display recipe
9291 dependency information used during the build.
9292
9293- "`Viewing Task Variable
9294 Dependencies <#dev-viewing-task-variable-dependencies>`__" describes
9295 how to use the ``bitbake-dumpsig`` command in conjunction with key
9296 subdirectories in the
9297 :term:`Build Directory` to determine
9298 variable dependencies.
9299
9300- "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes
9301 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9302 to run specific tasks in the build chain. It can be useful to run
9303 tasks "out-of-order" when trying isolate build issues.
9304
9305- "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how
9306 to use BitBake's ``-D`` debug output option to reveal more about what
9307 BitBake is doing during the build.
9308
9309- "`Building with No Dependencies <#dev-debugging-buildfile>`__"
9310 describes how to use the BitBake ``-b`` option to build a recipe
9311 while ignoring dependencies.
9312
9313- "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__"
9314 describes how to use the many recipe logging functions to produce
9315 debugging output and report errors and warnings.
9316
9317- "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__"
9318 describes how to debug situations where the build consists of several
9319 parts that are run simultaneously and when the output or result of
9320 one part is not ready for use with a different part of the build that
9321 depends on that output.
9322
9323- "`Debugging With the GNU Project Debugger (GDB)
9324 Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to
9325 allow you to examine running programs, which can help you fix
9326 problems.
9327
9328- "`Debugging with the GNU Project Debugger (GDB) on the
9329 Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__"
9330 describes how to use GDB directly on target hardware for debugging.
9331
9332- "`Other Debugging Tips <#dev-other-debugging-others>`__" describes
9333 miscellaneous debugging tips that can be useful.
9334
9335.. _dev-debugging-viewing-logs-from-failed-tasks:
9336
9337Viewing Logs from Failed Tasks
9338------------------------------
9339
9340You can find the log for a task in the file
9341``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
9342For example, the log for the
9343:ref:`ref-tasks-compile` task of the
9344QEMU minimal image for the x86 machine (``qemux86``) might be in
9345``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9346To see the commands :term:`BitBake` ran
9347to generate a log, look at the corresponding ``run.do_``\ `taskname` file
9348in the same directory.
9349
9350``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9351links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9352``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
9353when it ran. The symlinks always point to the files corresponding to the
9354most recent run.
9355
9356.. _dev-debugging-viewing-variable-values:
9357
9358Viewing Variable Values
9359-----------------------
9360
9361Sometimes you need to know the value of a variable as a result of
9362BitBake's parsing step. This could be because some unexpected behavior
9363occurred in your project. Perhaps an attempt to :ref:`modify a variable
9364<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9365variables>` did not work out as expected.
9366
9367BitBake's ``-e`` option is used to display variable values after
9368parsing. The following command displays the variable values after the
9369configuration files (i.e. ``local.conf``, ``bblayers.conf``,
9370``bitbake.conf`` and so forth) have been parsed:
9371::
9372
9373 $ bitbake -e
9374
9375The following command displays variable values after a specific recipe has
9376been parsed. The variables include those from the configuration as well:
9377::
9378
9379 $ bitbake -e recipename
9380
9381.. note::
9382
9383 Each recipe has its own private set of variables (datastore).
9384 Internally, after parsing the configuration, a copy of the resulting
9385 datastore is made prior to parsing each recipe. This copying implies
9386 that variables set in one recipe will not be visible to other
9387 recipes.
9388
9389 Likewise, each task within a recipe gets a private datastore based on
9390 the recipe datastore, which means that variables set within one task
9391 will not be visible to other tasks.
9392
9393In the output of ``bitbake -e``, each variable is preceded by a
9394description of how the variable got its value, including temporary
9395values that were later overridden. This description also includes
9396variable flags (varflags) set on the variable. The output can be very
9397helpful during debugging.
9398
9399Variables that are exported to the environment are preceded by
9400``export`` in the output of ``bitbake -e``. See the following example:
9401::
9402
9403 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9404
9405In addition to variable values, the output of the ``bitbake -e`` and
9406``bitbake -e`` recipe commands includes the following information:
9407
9408- The output starts with a tree listing all configuration files and
9409 classes included globally, recursively listing the files they include
9410 or inherit in turn. Much of the behavior of the OpenEmbedded build
9411 system (including the behavior of the :ref:`ref-manual/ref-tasks:normal recipe build tasks`) is
9412 implemented in the
9413 :ref:`base <ref-classes-base>` class and the
9414 classes it inherits, rather than being built into BitBake itself.
9415
9416- After the variable values, all functions appear in the output. For
9417 shell functions, variables referenced within the function body are
9418 expanded. If a function has been modified using overrides or using
9419 override-style operators like ``_append`` and ``_prepend``, then the
9420 final assembled function body appears in the output.
9421
9422Viewing Package Information with ``oe-pkgdata-util``
9423----------------------------------------------------
9424
9425You can use the ``oe-pkgdata-util`` command-line utility to query
9426:term:`PKGDATA_DIR` and display
9427various package-related information. When you use the utility, you must
9428use it to view information on packages that have already been built.
9429
9430Following are a few of the available ``oe-pkgdata-util`` subcommands.
9431
9432.. note::
9433
9434 You can use the standard \* and ? globbing wildcards as part of
9435 package names and paths.
9436
9437- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9438 that have been built, optionally limiting the match to packages that
9439 match pattern.
9440
9441- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9442 files and directories contained in the given packages.
9443
9444 .. note::
9445
9446 A different way to view the contents of a package is to look at
9447 the
9448 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9449 directory of the recipe that generates the package. This directory
9450 is created by the
9451 :ref:`ref-tasks-package` task
9452 and has one subdirectory for each package the recipe generates,
9453 which contains the files stored in that package.
9454
9455 If you want to inspect the ``${WORKDIR}/packages-split``
9456 directory, make sure that
9457 :ref:`rm_work <ref-classes-rm-work>` is not
9458 enabled when you build the recipe.
9459
9460- ``oe-pkgdata-util find-path path ...``: Lists the names of
9461 the packages that contain the given paths. For example, the following
9462 tells us that ``/usr/share/man/man1/make.1`` is contained in the
9463 ``make-doc`` package:
9464 ::
9465
9466 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9467 make-doc: /usr/share/man/man1/make.1
9468
9469- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9470 of the recipes that produce the given packages.
9471
9472For more information on the ``oe-pkgdata-util`` command, use the help
9473facility:
9474::
9475
9476 $ oe-pkgdata-util --help
9477 $ oe-pkgdata-util subcommand --help
9478
9479.. _dev-viewing-dependencies-between-recipes-and-tasks:
9480
9481Viewing Dependencies Between Recipes and Tasks
9482----------------------------------------------
9483
9484Sometimes it can be hard to see why BitBake wants to build other recipes
9485before the one you have specified. Dependency information can help you
9486understand why a recipe is built.
9487
9488To generate dependency information for a recipe, run the following
9489command:
9490::
9491
9492 $ bitbake -g recipename
9493
9494This command writes the following files in the current directory:
9495
9496- ``pn-buildlist``: A list of recipes/targets involved in building
9497 `recipename`. "Involved" here means that at least one task from the
9498 recipe needs to run when building `recipename` from scratch. Targets
9499 that are in
9500 :term:`ASSUME_PROVIDED`
9501 are not listed.
9502
9503- ``task-depends.dot``: A graph showing dependencies between tasks.
9504
9505The graphs are in
9506`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9507format and can be converted to images (e.g. using the ``dot`` tool from
9508`Graphviz <https://www.graphviz.org/>`__).
9509
9510.. note::
9511
9512 - DOT files use a plain text format. The graphs generated using the
9513 ``bitbake -g`` command are often so large as to be difficult to
9514 read without special pruning (e.g. with Bitbake's ``-I`` option)
9515 and processing. Despite the form and size of the graphs, the
9516 corresponding ``.dot`` files can still be possible to read and
9517 provide useful information.
9518
9519 As an example, the ``task-depends.dot`` file contains lines such
9520 as the following:
9521 ::
9522
9523 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9524
9525 The above example line reveals that the
9526 :ref:`ref-tasks-configure`
9527 task in ``libxslt`` depends on the
9528 :ref:`ref-tasks-populate_sysroot`
9529 task in ``libxml2``, which is a normal
9530 :term:`DEPENDS` dependency
9531 between the two recipes.
9532
9533 - For an example of how ``.dot`` files can be processed, see the
9534 ``scripts/contrib/graph-tool`` Python script, which finds and
9535 displays paths between graph nodes.
9536
9537You can use a different method to view dependency information by using
9538the following command:
9539::
9540
9541 $ bitbake -g -u taskexp recipename
9542
9543This command
9544displays a GUI window from which you can view build-time and runtime
9545dependencies for the recipes involved in building recipename.
9546
9547.. _dev-viewing-task-variable-dependencies:
9548
9549Viewing Task Variable Dependencies
9550----------------------------------
9551
9552As mentioned in the
9553":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9554User Manual, BitBake tries to automatically determine what variables a
9555task depends on so that it can rerun the task if any values of the
9556variables change. This determination is usually reliable. However, if
9557you do things like construct variable names at runtime, then you might
9558have to manually declare dependencies on those variables using
9559``vardeps`` as described in the
9560":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9561User Manual.
9562
9563If you are unsure whether a variable dependency is being picked up
9564automatically for a given task, you can list the variable dependencies
9565BitBake has determined by doing the following:
9566
95671. Build the recipe containing the task:
9568::
9569
9570 $ bitbake recipename
9571
95722. Inside the :term:`STAMPS_DIR`
9573 directory, find the signature data (``sigdata``) file that
9574 corresponds to the task. The ``sigdata`` files contain a pickled
9575 Python database of all the metadata that went into creating the input
9576 checksum for the task. As an example, for the
9577 :ref:`ref-tasks-fetch` task of the
9578 ``db`` recipe, the ``sigdata`` file might be found in the following
9579 location:
9580 ::
9581
9582 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9583
9584 For tasks that are accelerated through the shared state
9585 (:ref:`sstate <overview-manual/overview-manual-concepts:shared state cache>`) cache, an
9586 additional ``siginfo`` file is written into
9587 :term:`SSTATE_DIR` along with
9588 the cached task output. The ``siginfo`` files contain exactly the
9589 same information as ``sigdata`` files.
9590
95913. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
9592 is an example:
9593 ::
9594
9595 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9596
9597 In the output of the above command, you will find a line like the
9598 following, which lists all the (inferred) variable dependencies for
9599 the task. This list also includes indirect dependencies from
9600 variables depending on other variables, recursively.
9601 ::
9602
9603 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9604
9605 .. note::
9606
9607 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9608 These functions in turn depend on the variables they reference.
9609
9610 The output of ``bitbake-dumpsig`` also includes the value each
9611 variable had, a list of dependencies for each variable, and
9612 :term:`bitbake:BB_HASHBASE_WHITELIST`
9613 information.
9614
9615There is also a ``bitbake-diffsigs`` command for comparing two
9616``siginfo`` or ``sigdata`` files. This command can be helpful when
9617trying to figure out what changed between two versions of a task. If you
9618call ``bitbake-diffsigs`` with just one file, the command behaves like
9619``bitbake-dumpsig``.
9620
9621You can also use BitBake to dump out the signature construction
9622information without executing tasks by using either of the following
9623BitBake command-line options:
9624::
9625
9626 ‐‐dump-signatures=SIGNATURE_HANDLER
9627 -S SIGNATURE_HANDLER
9628
9629
9630.. note::
9631
9632 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9633 dump only the signature or compare the dumped signature with the cached one,
9634 respectively.
9635
9636Using BitBake with either of these options causes BitBake to dump out
9637``sigdata`` files in the ``stamps`` directory for every task it would
9638have executed instead of building the specified target package.
9639
9640.. _dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task:
9641
9642Viewing Metadata Used to Create the Input Signature of a Shared State Task
9643--------------------------------------------------------------------------
9644
9645Seeing what metadata went into creating the input signature of a shared
9646state (sstate) task can be a useful debugging aid. This information is
9647available in signature information (``siginfo``) files in
9648:term:`SSTATE_DIR`. For
9649information on how to view and interpret information in ``siginfo``
9650files, see the "`Viewing Task Variable
9651Dependencies <#dev-viewing-task-variable-dependencies>`__" section.
9652
9653For conceptual information on shared state, see the
9654":ref:`overview-manual/overview-manual-concepts:shared state`"
9655section in the Yocto Project Overview and Concepts Manual.
9656
9657.. _dev-invalidating-shared-state-to-force-a-task-to-run:
9658
9659Invalidating Shared State to Force a Task to Run
9660------------------------------------------------
9661
9662The OpenEmbedded build system uses
9663:ref:`checksums <overview-checksums>` and
9664:ref:`overview-manual/overview-manual-concepts:shared state` cache to avoid unnecessarily
9665rebuilding tasks. Collectively, this scheme is known as "shared state
9666code".
9667
9668As with all schemes, this one has some drawbacks. It is possible that
9669you could make implicit changes to your code that the checksum
9670calculations do not take into account. These implicit changes affect a
9671task's output but do not trigger the shared state code into rebuilding a
9672recipe. Consider an example during which a tool changes its output.
9673Assume that the output of ``rpmdeps`` changes. The result of the change
9674should be that all the ``package`` and ``package_write_rpm`` shared
9675state cache items become invalid. However, because the change to the
9676output is external to the code and therefore implicit, the associated
9677shared state cache items do not become invalidated. In this case, the
9678build process uses the cached items rather than running the task again.
9679Obviously, these types of implicit changes can cause problems.
9680
9681To avoid these problems during the build, you need to understand the
9682effects of any changes you make. Realize that changes you make directly
9683to a function are automatically factored into the checksum calculation.
9684Thus, these explicit changes invalidate the associated area of shared
9685state cache. However, you need to be aware of any implicit changes that
9686are not obvious changes to the code and could affect the output of a
9687given task.
9688
9689When you identify an implicit change, you can easily take steps to
9690invalidate the cache and force the tasks to run. The steps you can take
9691are as simple as changing a function's comments in the source code. For
9692example, to invalidate package shared state files, change the comment
9693statements of
9694:ref:`ref-tasks-package` or the
9695comments of one of the functions it calls. Even though the change is
9696purely cosmetic, it causes the checksum to be recalculated and forces
9697the build system to run the task again.
9698
9699.. note::
9700
9701 For an example of a commit that makes a cosmetic change to invalidate
9702 shared state, see this
9703 :yocto_git:`commit </cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
9704
9705.. _dev-debugging-taskrunning:
9706
9707Running Specific Tasks
9708----------------------
9709
9710Any given recipe consists of a set of tasks. The standard BitBake
9711behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9712``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9713``do_package_write_*``, and ``do_build``. The default task is
9714``do_build`` and any tasks on which it depends build first. Some tasks,
9715such as ``do_devshell``, are not part of the default build chain. If you
9716wish to run a task that is not part of the default build chain, you can
9717use the ``-c`` option in BitBake. Here is an example:
9718::
9719
9720 $ bitbake matchbox-desktop -c devshell
9721
9722The ``-c`` option respects task dependencies, which means that all other
9723tasks (including tasks from other recipes) that the specified task
9724depends on will be run before the task. Even when you manually specify a
9725task to run with ``-c``, BitBake will only run the task if it considers
9726it "out of date". See the
9727":ref:`overview-manual/overview-manual-concepts:stamp files and the rerunning of tasks`"
9728section in the Yocto Project Overview and Concepts Manual for how
9729BitBake determines whether a task is "out of date".
9730
9731If you want to force an up-to-date task to be rerun (e.g. because you
9732made manual modifications to the recipe's
9733:term:`WORKDIR` that you want to try
9734out), then you can use the ``-f`` option.
9735
9736.. note::
9737
9738 The reason ``-f`` is never required when running the
9739 :ref:`ref-tasks-devshell` task is because the
9740 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
9741 variable flag is already set for the task.
9742
9743The following example shows one way you can use the ``-f`` option:
9744::
9745
9746 $ bitbake matchbox-desktop
9747 .
9748 .
9749 make some changes to the source code in the work directory
9750 .
9751 .
9752 $ bitbake matchbox-desktop -c compile -f
9753 $ bitbake matchbox-desktop
9754
9755This sequence first builds and then recompiles ``matchbox-desktop``. The
9756last command reruns all tasks (basically the packaging tasks) after the
9757compile. BitBake recognizes that the ``do_compile`` task was rerun and
9758therefore understands that the other tasks also need to be run again.
9759
9760Another, shorter way to rerun a task and all
9761:ref:`ref-manual/ref-tasks:normal recipe build tasks`
9762that depend on it is to use the ``-C`` option.
9763
9764.. note::
9765
9766 This option is upper-cased and is separate from the ``-c``
9767 option, which is lower-cased.
9768
9769Using this option invalidates the given task and then runs the
9770:ref:`ref-tasks-build` task, which is
9771the default task if no task is given, and the tasks on which it depends.
9772You could replace the final two commands in the previous example with
9773the following single command:
9774::
9775
9776 $ bitbake matchbox-desktop -C compile
9777
9778Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9779the input checksum of the specified task. This tainting indirectly
9780causes the task and its dependent tasks to be rerun through the normal
9781task dependency mechanisms.
9782
9783.. note::
9784
9785 BitBake explicitly keeps track of which tasks have been tainted in
9786 this fashion, and will print warnings such as the following for
9787 builds involving such tasks:
9788
9789 .. code-block:: none
9790
9791 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9792
9793
9794 The purpose of the warning is to let you know that the work directory
9795 and build output might not be in the clean state they would be in for
9796 a "normal" build, depending on what actions you took. To get rid of
9797 such warnings, you can remove the work directory and rebuild the
9798 recipe, as follows:
9799 ::
9800
9801 $ bitbake matchbox-desktop -c clean
9802 $ bitbake matchbox-desktop
9803
9804
9805You can view a list of tasks in a given package by running the
9806``do_listtasks`` task as follows:
9807::
9808
9809 $ bitbake matchbox-desktop -c listtasks
9810
9811The results appear as output to the console and are also in
9812the file ``${WORKDIR}/temp/log.do_listtasks``.
9813
9814.. _dev-debugging-bitbake:
9815
9816General BitBake Problems
9817------------------------
9818
9819You can see debug output from BitBake by using the ``-D`` option. The
9820debug output gives more information about what BitBake is doing and the
9821reason behind it. Each ``-D`` option you use increases the logging
9822level. The most common usage is ``-DDD``.
9823
9824The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
9825chose a certain version of a package or why BitBake picked a certain
9826provider. This command could also help you in a situation where you
9827think BitBake did something unexpected.
9828
9829.. _dev-debugging-buildfile:
9830
9831Building with No Dependencies
9832-----------------------------
9833
9834To build a specific recipe (``.bb`` file), you can use the following
9835command form:
9836::
9837
9838 $ bitbake -b somepath/somerecipe.bb
9839
9840This command form does
9841not check for dependencies. Consequently, you should use it only when
9842you know existing dependencies have been met.
9843
9844.. note::
9845
9846 You can also specify fragments of the filename. In this case, BitBake
9847 checks for a unique match.
9848
9849Recipe Logging Mechanisms
9850-------------------------
9851
9852The Yocto Project provides several logging functions for producing
9853debugging output and reporting errors and warnings. For Python
9854functions, the following logging functions exist. All of these functions
9855log to ``${T}/log.do_``\ `task`, and can also log to standard output
9856(stdout) with the right settings:
9857
9858- ``bb.plain(msg)``: Writes msg as is to the log while also
9859 logging to stdout.
9860
9861- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9862 stdout if BitBake is called with "-v".
9863
9864- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9865 log. Also logs to stdout if the log level is greater than or equal to
9866 level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
9867 in the BitBake User Manual for more information.
9868
9869- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9870 logging to stdout.
9871
9872- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9873 logging to standard out (stdout).
9874
9875 .. note::
9876
9877 Calling this function does not cause the task to fail.
9878
9879- ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
9880 ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
9881
9882 .. note::
9883
9884 ``bb.fatal()`` raises an exception, which means you do not need to put a
9885 "return" statement after the function.
9886
9887The same logging functions are also available in shell functions, under
9888the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9889and ``bbfatal``. The
9890:ref:`logging <ref-classes-logging>` class
9891implements these functions. See that class in the ``meta/classes``
9892folder of the :term:`Source Directory` for information.
9893
9894Logging With Python
9895~~~~~~~~~~~~~~~~~~~
9896
9897When creating recipes using Python and inserting code that handles build
9898logs, keep in mind the goal is to have informative logs while keeping
9899the console as "silent" as possible. Also, if you want status messages
9900in the log, use the "debug" loglevel.
9901
9902Following is an example written in Python. The code handles logging for
9903a function that determines the number of tasks needed to be run. See the
9904":ref:`ref-tasks-listtasks`"
9905section for additional information:
9906::
9907
9908 python do_listtasks() {
9909 bb.debug(2, "Starting to figure out the task list")
9910 if noteworthy_condition:
9911 bb.note("There are 47 tasks to run")
9912 bb.debug(2, "Got to point xyz")
9913 if warning_trigger:
9914 bb.warn("Detected warning_trigger, this might be a problem later.")
9915 if recoverable_error:
9916 bb.error("Hit recoverable_error, you really need to fix this!")
9917 if fatal_error:
9918 bb.fatal("fatal_error detected, unable to print the task list")
9919 bb.plain("The tasks present are abc")
9920 bb.debug(2, "Finished figuring out the tasklist")
9921 }
9922
9923Logging With Bash
9924~~~~~~~~~~~~~~~~~
9925
9926When creating recipes using Bash and inserting code that handles build
9927logs, you have the same goals - informative with minimal console output.
9928The syntax you use for recipes written in Bash is similar to that of
9929recipes written in Python described in the previous section.
9930
9931Following is an example written in Bash. The code logs the progress of
9932the ``do_my_function`` function.
9933::
9934
9935 do_my_function() {
9936 bbdebug 2 "Running do_my_function"
9937 if [ exceptional_condition ]; then
9938 bbnote "Hit exceptional_condition"
9939 fi
9940 bbdebug 2 "Got to point xyz"
9941 if [ warning_trigger ]; then
9942 bbwarn "Detected warning_trigger, this might cause a problem later."
9943 fi
9944 if [ recoverable_error ]; then
9945 bberror "Hit recoverable_error, correcting"
9946 fi
9947 if [ fatal_error ]; then
9948 bbfatal "fatal_error detected"
9949 fi
9950 bbdebug 2 "Completed do_my_function"
9951 }
9952
9953
9954Debugging Parallel Make Races
9955-----------------------------
9956
9957A parallel ``make`` race occurs when the build consists of several parts
9958that are run simultaneously and a situation occurs when the output or
9959result of one part is not ready for use with a different part of the
9960build that depends on that output. Parallel make races are annoying and
9961can sometimes be difficult to reproduce and fix. However, some simple
9962tips and tricks exist that can help you debug and fix them. This section
9963presents a real-world example of an error encountered on the Yocto
9964Project autobuilder and the process used to fix it.
9965
9966.. note::
9967
9968 If you cannot properly fix a ``make`` race condition, you can work around it
9969 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
9970 variables.
9971
9972The Failure
9973~~~~~~~~~~~
9974
9975For this example, assume that you are building an image that depends on
9976the "neard" package. And, during the build, BitBake runs into problems
9977and creates the following output.
9978
9979.. note::
9980
9981 This example log file has longer lines artificially broken to make
9982 the listing easier to read.
9983
9984If you examine the output or the log file, you see the failure during
9985``make``:
9986
9987.. code-block:: none
9988
9989 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9990 | DEBUG: Executing shell function do_compile
9991 | NOTE: make -j 16
9992 | make --no-print-directory all-am
9993 | /bin/mkdir -p include/near
9994 | /bin/mkdir -p include/near
9995 | /bin/mkdir -p include/near
9996 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9997 0.14-r0/neard-0.14/include/types.h include/near/types.h
9998 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9999 0.14-r0/neard-0.14/include/log.h include/near/log.h
10000 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10001 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
10002 | /bin/mkdir -p include/near
10003 | /bin/mkdir -p include/near
10004 | /bin/mkdir -p include/near
10005 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10006 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
10007 | /bin/mkdir -p include/near
10008 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10009 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
10010 | /bin/mkdir -p include/near
10011 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10012 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
10013 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10014 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
10015 | /bin/mkdir -p include/near
10016 | /bin/mkdir -p include/near
10017 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10018 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
10019 | /bin/mkdir -p include/near
10020 | /bin/mkdir -p include/near
10021 | /bin/mkdir -p include/near
10022 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10023 0.14-r0/neard-0.14/include/device.h include/near/device.h
10024 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10025 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
10026 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10027 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
10028 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10029 0.14-r0/neard-0.14/include/version.h include/near/version.h
10030 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10031 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
10032 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
10033 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
10034 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
10035 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
10036 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
10037 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
10038 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
10039 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
10040 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
10041 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
10042 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
10043 -o tools/snep-send.o tools/snep-send.c
10044 | In file included from tools/snep-send.c:16:0:
10045 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
10046 | #include <near/dbus.h>
10047 | ^
10048 | compilation terminated.
10049 | make[1]: *** [tools/snep-send.o] Error 1
10050 | make[1]: *** Waiting for unfinished jobs....
10051 | make: *** [all] Error 2
10052 | ERROR: oe_runmake failed
10053
10054Reproducing the Error
10055~~~~~~~~~~~~~~~~~~~~~
10056
10057Because race conditions are intermittent, they do not manifest
10058themselves every time you do the build. In fact, most times the build
10059will complete without problems even though the potential race condition
10060exists. Thus, once the error surfaces, you need a way to reproduce it.
10061
10062In this example, compiling the "neard" package is causing the problem.
10063So the first thing to do is build "neard" locally. Before you start the
10064build, set the
10065:term:`PARALLEL_MAKE` variable
10066in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
10067high value for ``PARALLEL_MAKE`` increases the chances of the race
10068condition showing up:
10069::
10070
10071 $ bitbake neard
10072
10073Once the local build for "neard" completes, start a ``devshell`` build:
10074::
10075
10076 $ bitbake neard -c devshell
10077
10078For information on how to use a
10079``devshell``, see the "`Using a Development
10080Shell <#platdev-appdev-devshell>`__" section.
10081
10082In the ``devshell``, do the following:
10083::
10084
10085 $ make clean
10086 $ make tools/snep-send.o
10087
10088The ``devshell`` commands cause the failure to clearly
10089be visible. In this case, a missing dependency exists for the "neard"
10090Makefile target. Here is some abbreviated, sample output with the
10091missing dependency clearly visible at the end:
10092::
10093
10094 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
10095 .
10096 .
10097 .
10098 tools/snep-send.c
10099 In file included from tools/snep-send.c:16:0:
10100 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
10101 #include <near/dbus.h>
10102 ^
10103 compilation terminated.
10104 make: *** [tools/snep-send.o] Error 1
10105 $
10106
10107
10108Creating a Patch for the Fix
10109~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10110
10111Because there is a missing dependency for the Makefile target, you need
10112to patch the ``Makefile.am`` file, which is generated from
10113``Makefile.in``. You can use Quilt to create the patch:
10114::
10115
10116 $ quilt new parallelmake.patch
10117 Patch patches/parallelmake.patch is now on top
10118 $ quilt add Makefile.am
10119 File Makefile.am added to patch patches/parallelmake.patch
10120
10121For more information on using Quilt, see the
10122"`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section.
10123
10124At this point you need to make the edits to ``Makefile.am`` to add the
10125missing dependency. For our example, you have to add the following line
10126to the file:
10127::
10128
10129 tools/snep-send.$(OBJEXT): include/near/dbus.h
10130
10131Once you have edited the file, use the ``refresh`` command to create the
10132patch:
10133::
10134
10135 $ quilt refresh
10136 Refreshed patch patches/parallelmake.patch
10137
10138Once
10139the patch file exists, you need to add it back to the originating recipe
10140folder. Here is an example assuming a top-level
10141:term:`Source Directory` named ``poky``:
10142::
10143
10144 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
10145
10146The final thing you need to do to implement the fix in the build is to
10147update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
10148:term:`SRC_URI` statement includes
10149the patch file. The recipe file is in the folder above the patch. Here
10150is what the edited ``SRC_URI`` statement would look like:
10151::
10152
10153 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
10154 file://neard.in \
10155 file://neard.service.in \
10156 file://parallelmake.patch \
10157 "
10158
10159With the patch complete and moved to the correct folder and the
10160``SRC_URI`` statement updated, you can exit the ``devshell``:
10161::
10162
10163 $ exit
10164
10165Testing the Build
10166~~~~~~~~~~~~~~~~~
10167
10168With everything in place, you can get back to trying the build again
10169locally:
10170::
10171
10172 $ bitbake neard
10173
10174This build should succeed.
10175
10176Now you can open up a ``devshell`` again and repeat the clean and make
10177operations as follows:
10178::
10179
10180 $ bitbake neard -c devshell
10181 $ make clean
10182 $ make tools/snep-send.o
10183
10184The build should work without issue.
10185
10186As with all solved problems, if they originated upstream, you need to
10187submit the fix for the recipe in OE-Core and upstream so that the
10188problem is taken care of at its source. See the "`Submitting a Change to
10189the Yocto Project <#how-to-submit-a-change>`__" section for more
10190information.
10191
10192.. _platdev-gdb-remotedebug:
10193
10194Debugging With the GNU Project Debugger (GDB) Remotely
10195------------------------------------------------------
10196
10197GDB allows you to examine running programs, which in turn helps you to
10198understand and fix problems. It also allows you to perform post-mortem
10199style analysis of program crashes. GDB is available as a package within
10200the Yocto Project and is installed in SDK images by default. See the
10201":ref:`ref-manual/ref-images:Images`" chapter in the Yocto
10202Project Reference Manual for a description of these images. You can find
10203information on GDB at https://sourceware.org/gdb/.
10204
10205.. note::
10206
10207 For best results, install debug (``-dbg``) packages for the applications you
10208 are going to debug. Doing so makes extra debug symbols available that give
10209 you more meaningful output.
10210
10211Sometimes, due to memory or disk space constraints, it is not possible
10212to use GDB directly on the remote target to debug applications. These
10213constraints arise because GDB needs to load the debugging information
10214and the binaries of the process being debugged. Additionally, GDB needs
10215to perform many computations to locate information such as function
10216names, variable names and values, stack traces and so forth - even
10217before starting the debugging process. These extra computations place
10218more load on the target system and can alter the characteristics of the
10219program being debugged.
10220
10221To help get past the previously mentioned constraints, you can use
10222gdbserver, which runs on the remote target and does not load any
10223debugging information from the debugged process. Instead, a GDB instance
10224processes the debugging information that is run on a remote computer -
10225the host GDB. The host GDB then sends control commands to gdbserver to
10226make it stop or start the debugged program, as well as read or write
10227memory regions of that debugged program. All the debugging information
10228loaded and processed as well as all the heavy debugging is done by the
10229host GDB. Offloading these processes gives the gdbserver running on the
10230target a chance to remain small and fast.
10231
10232Because the host GDB is responsible for loading the debugging
10233information and for doing the necessary processing to make actual
10234debugging happen, you have to make sure the host can access the
10235unstripped binaries complete with their debugging information and also
10236be sure the target is compiled with no optimizations. The host GDB must
10237also have local access to all the libraries used by the debugged
10238program. Because gdbserver does not need any local debugging
10239information, the binaries on the remote target can remain stripped.
10240However, the binaries must also be compiled without optimization so they
10241match the host's binaries.
10242
10243To remain consistent with GDB documentation and terminology, the binary
10244being debugged on the remote target machine is referred to as the
10245"inferior" binary. For documentation on GDB see the `GDB
10246site <https://sourceware.org/gdb/documentation/>`__.
10247
10248The following steps show you how to debug using the GNU project
10249debugger.
10250
102511. *Configure your build system to construct the companion debug
10252 filesystem:*
10253
10254 In your ``local.conf`` file, set the following:
10255 ::
10256
10257 IMAGE_GEN_DEBUGFS = "1"
10258 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10259
10260 These options cause the
10261 OpenEmbedded build system to generate a special companion filesystem
10262 fragment, which contains the matching source and debug symbols to
10263 your deployable filesystem. The build system does this by looking at
10264 what is in the deployed filesystem, and pulling the corresponding
10265 ``-dbg`` packages.
10266
10267 The companion debug filesystem is not a complete filesystem, but only
10268 contains the debug fragments. This filesystem must be combined with
10269 the full filesystem for debugging. Subsequent steps in this procedure
10270 show how to combine the partial filesystem with the full filesystem.
10271
102722. *Configure the system to include gdbserver in the target filesystem:*
10273
10274 Make the following addition in either your ``local.conf`` file or in
10275 an image recipe:
10276 ::
10277
10278 IMAGE_INSTALL_append = " gdbserver"
10279
10280 The change makes
10281 sure the ``gdbserver`` package is included.
10282
102833. *Build the environment:*
10284
10285 Use the following command to construct the image and the companion
10286 Debug Filesystem:
10287 ::
10288
10289 $ bitbake image
10290
10291 Build the cross GDB component and
10292 make it available for debugging. Build the SDK that matches the
10293 image. Building the SDK is best for a production build that can be
10294 used later for debugging, especially during long term maintenance:
10295 ::
10296
10297 $ bitbake -c populate_sdk image
10298
10299 Alternatively, you can build the minimal toolchain components that
10300 match the target. Doing so creates a smaller than typical SDK and
10301 only contains a minimal set of components with which to build simple
10302 test applications, as well as run the debugger:
10303 ::
10304
10305 $ bitbake meta-toolchain
10306
10307 A final method is to build Gdb itself within the build system:
10308 ::
10309
10310 $ bitbake gdb-cross-<architecture>
10311
10312 Doing so produces a temporary copy of
10313 ``cross-gdb`` you can use for debugging during development. While
10314 this is the quickest approach, the two previous methods in this step
10315 are better when considering long-term maintenance strategies.
10316
10317 .. note::
10318
10319 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10320 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10321 actual name you want to use.
10322
103234. *Set up the* ``debugfs``\ *:*
10324
10325 Run the following commands to set up the ``debugfs``:
10326 ::
10327
10328 $ mkdir debugfs
10329 $ cd debugfs
10330 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
10331 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
10332
103335. *Set up GDB:*
10334
10335 Install the SDK (if you built one) and then source the correct
10336 environment file. Sourcing the environment file puts the SDK in your
10337 ``PATH`` environment variable.
10338
10339 If you are using the build system, Gdb is located in
10340 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
10341
103426. *Boot the target:*
10343
10344 For information on how to run QEMU, see the `QEMU
10345 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
10346
10347 .. note::
10348
10349 Be sure to verify that your host can access the target via TCP.
10350
103517. *Debug a program:*
10352
10353 Debugging a program involves running gdbserver on the target and then
10354 running Gdb on the host. The example in this step debugs ``gzip``:
10355
10356 .. code-block:: shell
10357
10358 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10359
10360 For
10361 additional gdbserver options, see the `GDB Server
10362 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10363
10364 After running gdbserver on the target, you need to run Gdb on the
10365 host and configure it and connect to the target. Use these commands:
10366 ::
10367
10368 $ cd directory-holding-the-debugfs-directory
10369 $ arch-gdb
10370 (gdb) set sysroot debugfs
10371 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10372 (gdb) target remote IP-of-target:1234
10373
10374 At this
10375 point, everything should automatically load (i.e. matching binaries,
10376 symbols and headers).
10377
10378 .. note::
10379
10380 The Gdb ``set`` commands in the previous example can be placed into the
10381 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10382 commands are in that file.
10383
103848. *Deploying without a full image rebuild:*
10385
10386 In many cases, during development you want a quick method to deploy a
10387 new binary to the target and debug it, without waiting for a full
10388 image build.
10389
10390 One approach to solving this situation is to just build the component
10391 you want to debug. Once you have built the component, copy the
10392 executable directly to both the target and the host ``debugfs``.
10393
10394 If the binary is processed through the debug splitting in
10395 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10396 contents and corresponding ``/usr/src/debug`` files) from the work
10397 directory. Here is an example:
10398 ::
10399
10400 $ bitbake bash
10401 $ bitbake -c devshell bash
10402 $ cd ..
10403 $ scp packages-split/bash/bin/bash target:/bin/bash
10404 $ cp -a packages-split/bash-dbg/\* path/debugfs
10405
10406Debugging with the GNU Project Debugger (GDB) on the Target
10407-----------------------------------------------------------
10408
10409The previous section addressed using GDB remotely for debugging
10410purposes, which is the most usual case due to the inherent hardware
10411limitations on many embedded devices. However, debugging in the target
10412hardware itself is also possible with more powerful devices. This
10413section describes what you need to do in order to support using GDB to
10414debug on the target hardware.
10415
10416To support this kind of debugging, you need do the following:
10417
10418- Ensure that GDB is on the target. You can do this by adding "gdb" to
10419 :term:`IMAGE_INSTALL`:
10420 ::
10421
10422 IMAGE_INSTALL_append = " gdb"
10423
10424 Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:
10425 ::
10426
10427 IMAGE_FEATURES_append = " tools-debug"
10428
10429- Ensure that debug symbols are present. You can make sure these
10430 symbols are present by installing ``-dbg``:
10431 ::
10432
10433 IMAGE_INSTALL_append = "packagename-dbg"
10434
10435 Alternatively, you can do the following to include
10436 all the debug symbols:
10437 ::
10438
10439 IMAGE_FEATURES_append = " dbg-pkgs"
10440
10441.. note::
10442
10443 To improve the debug information accuracy, you can reduce the level
10444 of optimization used by the compiler. For example, when adding the
10445 following line to your ``local.conf`` file, you will reduce optimization
10446 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
10447 of "-O -fno-omit-frame-pointer":
10448 ::
10449
10450 DEBUG_BUILD = "1"
10451
10452 Consider that this will reduce the application's performance and is
10453 recommended only for debugging purposes.
10454
10455.. _dev-other-debugging-others:
10456
10457Other Debugging Tips
10458--------------------
10459
10460Here are some other tips that you might find useful:
10461
10462- When adding new packages, it is worth watching for undesirable items
10463 making their way into compiler command lines. For example, you do not
10464 want references to local system files like ``/usr/lib/`` or
10465 ``/usr/include/``.
10466
10467- If you want to remove the ``psplash`` boot splashscreen, add
10468 ``psplash=false`` to the kernel command line. Doing so prevents
10469 ``psplash`` from loading and thus allows you to see the console. It
10470 is also possible to switch out of the splashscreen by switching the
10471 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10472
10473- Removing :term:`TMPDIR` (usually
10474 ``tmp/``, within the
10475 :term:`Build Directory`) can often fix
10476 temporary build issues. Removing ``TMPDIR`` is usually a relatively
10477 cheap operation, because task output will be cached in
10478 :term:`SSTATE_DIR` (usually
10479 ``sstate-cache/``, which is also in the Build Directory).
10480
10481 .. note::
10482
10483 Removing ``TMPDIR`` might be a workaround rather than a fix.
10484 Consequently, trying to determine the underlying cause of an issue before
10485 removing the directory is a good idea.
10486
10487- Understanding how a feature is used in practice within existing
10488 recipes can be very helpful. It is recommended that you configure
10489 some method that allows you to quickly search through files.
10490
10491 Using GNU Grep, you can use the following shell function to
10492 recursively search through common recipe-related files, skipping
10493 binary files, ``.git`` directories, and the Build Directory (assuming
10494 its name starts with "build"):
10495 ::
10496
10497 g() {
10498 grep -Ir \
10499 --exclude-dir=.git \
10500 --exclude-dir='build*' \
10501 --include='*.bb*' \
10502 --include='*.inc*' \
10503 --include='*.conf*' \
10504 --include='*.py*' \
10505 "$@"
10506 }
10507
10508 Following are some usage examples:
10509 ::
10510
10511 $ g FOO # Search recursively for "FOO"
10512 $ g -i foo # Search recursively for "foo", ignoring case
10513 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10514
10515 If figuring
10516 out how some feature works requires a lot of searching, it might
10517 indicate that the documentation should be extended or improved. In
10518 such cases, consider filing a documentation bug using the Yocto
10519 Project implementation of
10520 :yocto_bugs:`Bugzilla <>`. For information on
10521 how to submit a bug against the Yocto Project, see the Yocto Project
10522 Bugzilla :yocto_wiki:`wiki page </wiki/Bugzilla_Configuration_and_Bug_Tracking>`
10523 and the "`Submitting a Defect Against the Yocto
10524 Project <#submitting-a-defect-against-the-yocto-project>`__" section.
10525
10526 .. note::
10527
10528 The manuals might not be the right place to document variables
10529 that are purely internal and have a limited scope (e.g. internal
10530 variables used to implement a single ``.bbclass`` file).
10531
10532Making Changes to the Yocto Project
10533===================================
10534
10535Because the Yocto Project is an open-source, community-based project,
10536you can effect changes to the project. This section presents procedures
10537that show you how to submit a defect against the project and how to
10538submit a change.
10539
10540Submitting a Defect Against the Yocto Project
10541---------------------------------------------
10542
10543Use the Yocto Project implementation of
10544`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
10545against the Yocto Project. For additional information on this
10546implementation of Bugzilla see the ":ref:`Yocto Project
10547Bugzilla <resources-bugtracker>`" section in the
10548Yocto Project Reference Manual. For more detail on any of the following
10549steps, see the Yocto Project
10550:yocto_wiki:`Bugzilla wiki page </wiki/Bugzilla_Configuration_and_Bug_Tracking>`.
10551
10552Use the following general steps to submit a bug:
10553
105541. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10555
105562. Click "File a Bug" to enter a new bug.
10557
105583. Choose the appropriate "Classification", "Product", and "Component"
10559 for which the bug was found. Bugs for the Yocto Project fall into
10560 one of several classifications, which in turn break down into
10561 several products and components. For example, for a bug against the
10562 ``meta-intel`` layer, you would choose "Build System, Metadata &
10563 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10564
105654. Choose the "Version" of the Yocto Project for which you found the
10566 bug (e.g. &DISTRO;).
10567
105685. Determine and select the "Severity" of the bug. The severity
10569 indicates how the bug impacted your work.
10570
105716. Choose the "Hardware" that the bug impacts.
10572
105737. Choose the "Architecture" that the bug impacts.
10574
105758. Choose a "Documentation change" item for the bug. Fixing a bug might
10576 or might not affect the Yocto Project documentation. If you are
10577 unsure of the impact to the documentation, select "Don't Know".
10578
105799. Provide a brief "Summary" of the bug. Try to limit your summary to
10580 just a line or two and be sure to capture the essence of the bug.
10581
1058210. Provide a detailed "Description" of the bug. You should provide as
10583 much detail as you can about the context, behavior, output, and so
10584 forth that surrounds the bug. You can even attach supporting files
10585 for output from logs by using the "Add an attachment" button.
10586
1058711. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10588 is assigned to the bug and the defect is logged in the bug tracking
10589 system.
10590
10591Once you file a bug, the bug is processed by the Yocto Project Bug
10592Triage Team and further details concerning the bug are assigned (e.g.
10593priority and owner). You are the "Submitter" of the bug and any further
10594categorization, progress, or comments on the bug result in Bugzilla
10595sending you an automated email concerning the particular change or
10596progress to the bug.
10597
10598.. _how-to-submit-a-change:
10599
10600Submitting a Change to the Yocto Project
10601----------------------------------------
10602
10603Contributions to the Yocto Project and OpenEmbedded are very welcome.
10604Because the system is extremely configurable and flexible, we recognize
10605that developers will want to extend, configure or optimize it for their
10606specific uses.
10607
10608The Yocto Project uses a mailing list and a patch-based workflow that is
10609similar to the Linux kernel but contains important differences. In
10610general, a mailing list exists through which you can submit patches. You
10611should send patches to the appropriate mailing list so that they can be
10612reviewed and merged by the appropriate maintainer. The specific mailing
10613list you need to use depends on the location of the code you are
10614changing. Each component (e.g. layer) should have a ``README`` file that
10615indicates where to send the changes and which process to follow.
10616
10617You can send the patch to the mailing list using whichever approach you
10618feel comfortable with to generate the patch. Once sent, the patch is
10619usually reviewed by the community at large. If somebody has concerns
10620with the patch, they will usually voice their concern over the mailing
10621list. If a patch does not receive any negative reviews, the maintainer
10622of the affected layer typically takes the patch, tests it, and then
10623based on successful testing, merges the patch.
10624
10625The "poky" repository, which is the Yocto Project's reference build
10626environment, is a hybrid repository that contains several individual
10627pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10628the combo-layer tool. The upstream location used for submitting changes
10629varies by component:
10630
10631- *Core Metadata:* Send your patch to the
10632 :oe_lists:`openembedded-core </g/openembedded-core>`
10633 mailing list. For example, a change to anything under the ``meta`` or
10634 ``scripts`` directories should be sent to this mailing list.
10635
10636- *BitBake:* For changes to BitBake (i.e. anything under the
10637 ``bitbake`` directory), send your patch to the
10638 :oe_lists:`bitbake-devel </g/bitbake-devel>`
10639 mailing list.
10640
10641- *"meta-\*" trees:* These trees contain Metadata. Use the
10642 :yocto_lists:`poky </g/poky>` mailing list.
10643
10644- *Documentation*: For changes to the Yocto Project documentation, use the
10645 :yocto_lists:`docs </g/docs>` mailing list.
10646
10647For changes to other layers hosted in the Yocto Project source
10648repositories (i.e. ``yoctoproject.org``) and tools use the
10649:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
10650
10651.. note::
10652
10653 Sometimes a layer's documentation specifies to use a particular
10654 mailing list. If so, use that list.
10655
10656For additional recipes that do not fit into the core Metadata, you
10657should determine which layer the recipe should go into and submit the
10658change in the manner recommended by the documentation (e.g. the
10659``README`` file) supplied with the layer. If in doubt, please ask on the
10660Yocto general mailing list or on the openembedded-devel mailing list.
10661
10662You can also push a change upstream and request a maintainer to pull the
10663change into the component's upstream repository. You do this by pushing
10664to a contribution repository that is upstream. See the ":ref:`gs-git-workflows-and-the-yocto-project`"
10665section in the Yocto Project Overview and Concepts Manual for additional
10666concepts on working in the Yocto Project development environment.
10667
10668Two commonly used testing repositories exist for OpenEmbedded-Core:
10669
10670- *"ross/mut" branch:* The "mut" (master-under-test) tree exists in the
10671 ``poky-contrib`` repository in the
10672 :yocto_git:`Yocto Project source repositories <>`.
10673
10674- *"master-next" branch:* This branch is part of the main "poky"
10675 repository in the Yocto Project source repositories.
10676
10677Maintainers use these branches to test submissions prior to merging
10678patches. Thus, you can get an idea of the status of a patch based on
10679whether the patch has been merged into one of these branches.
10680
10681.. note::
10682
10683 This system is imperfect and changes can sometimes get lost in the
10684 flow. Asking about the status of a patch or change is reasonable if
10685 the change has been idle for a while with no feedback. The Yocto
10686 Project does have plans to use
10687 `Patchwork <https://en.wikipedia.org/wiki/Patchwork_(software)>`__
10688 to track the status of patches and also to automatically preview
10689 patches.
10690
10691The following sections provide procedures for submitting a change.
10692
10693.. _pushing-a-change-upstream:
10694
10695Using Scripts to Push a Change Upstream and Request a Pull
10696~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10697
10698Follow this procedure to push a change to an upstream "contrib" Git
10699repository:
10700
10701.. note::
10702
10703 You can find general Git information on how to push a change upstream
10704 in the
10705 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10706
107071. *Make Your Changes Locally:* Make your changes in your local Git
10708 repository. You should make small, controlled, isolated changes.
10709 Keeping changes small and isolated aids review, makes
10710 merging/rebasing easier and keeps the change history clean should
10711 anyone need to refer to it in future.
10712
107132. *Stage Your Changes:* Stage your changes by using the ``git add``
10714 command on each file you changed.
10715
107163. *Commit Your Changes:* Commit the change by using the ``git commit``
10717 command. Make sure your commit information follows standards by
10718 following these accepted conventions:
10719
10720 - Be sure to include a "Signed-off-by:" line in the same style as
10721 required by the Linux kernel. Adding this line signifies that you,
10722 the submitter, have agreed to the Developer's Certificate of
10723 Origin 1.1 as follows:
10724
10725 .. code-block:: none
10726
10727 Developer's Certificate of Origin 1.1
10728
10729 By making a contribution to this project, I certify that:
10730
10731 (a) The contribution was created in whole or in part by me and I
10732 have the right to submit it under the open source license
10733 indicated in the file; or
10734
10735 (b) The contribution is based upon previous work that, to the best
10736 of my knowledge, is covered under an appropriate open source
10737 license and I have the right under that license to submit that
10738 work with modifications, whether created in whole or in part
10739 by me, under the same open source license (unless I am
10740 permitted to submit under a different license), as indicated
10741 in the file; or
10742
10743 (c) The contribution was provided directly to me by some other
10744 person who certified (a), (b) or (c) and I have not modified
10745 it.
10746
10747 (d) I understand and agree that this project and the contribution
10748 are public and that a record of the contribution (including all
10749 personal information I submit with it, including my sign-off) is
10750 maintained indefinitely and may be redistributed consistent with
10751 this project or the open source license(s) involved.
10752
10753 - Provide a single-line summary of the change and, if more
10754 explanation is needed, provide more detail in the body of the
10755 commit. This summary is typically viewable in the "shortlist" of
10756 changes. Thus, providing something short and descriptive that
10757 gives the reader a summary of the change is useful when viewing a
10758 list of many commits. You should prefix this short description
10759 with the recipe name (if changing a recipe), or else with the
10760 short form path to the file being changed.
10761
10762 - For the body of the commit message, provide detailed information
10763 that describes what you changed, why you made the change, and the
10764 approach you used. It might also be helpful if you mention how you
10765 tested the change. Provide as much detail as you can in the body
10766 of the commit message.
10767
10768 .. note::
10769
10770 You do not need to provide a more detailed explanation of a
10771 change if the change is minor to the point of the single line
10772 summary providing all the information.
10773
10774 - If the change addresses a specific bug or issue that is associated
10775 with a bug-tracking ID, include a reference to that ID in your
10776 detailed description. For example, the Yocto Project uses a
10777 specific convention for bug references - any commit that addresses
10778 a specific bug should use the following form for the detailed
10779 description. Be sure to use the actual bug-tracking ID from
10780 Bugzilla for bug-id:
10781 ::
10782
10783 Fixes [YOCTO #bug-id]
10784
10785 detailed description of change
10786
107874. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
10788 permissions to push to an upstream contrib repository, push the
10789 change to that repository:
10790 ::
10791
10792 $ git push upstream_remote_repo local_branch_name
10793
10794 For example, suppose you have permissions to push
10795 into the upstream ``meta-intel-contrib`` repository and you are
10796 working in a local branch named `your_name`\ ``/README``. The following
10797 command pushes your local commits to the ``meta-intel-contrib``
10798 upstream repository and puts the commit in a branch named
10799 `your_name`\ ``/README``:
10800 ::
10801
10802 $ git push meta-intel-contrib your_name/README
10803
108045. *Determine Who to Notify:* Determine the maintainer or the mailing
10805 list that you need to notify for the change.
10806
10807 Before submitting any change, you need to be sure who the maintainer
10808 is or what mailing list that you need to notify. Use either these
10809 methods to find out:
10810
10811 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10812 located in the :term:`Source Directory` at
10813 ``meta/conf/distro/include``, to see who is responsible for code.
10814
10815 - *Search by File:* Using :ref:`overview-manual/overview-manual-development-environment:git`, you can
10816 enter the following command to bring up a short list of all
10817 commits against a specific file:
10818 ::
10819
10820 git shortlog -- filename
10821
10822 Just provide the name of the file for which you are interested. The
10823 information returned is not ordered by history but does include a
10824 list of everyone who has committed grouped by name. From the list,
10825 you can see who is responsible for the bulk of the changes against
10826 the file.
10827
10828 - *Examine the List of Mailing Lists:* For a list of the Yocto
10829 Project and related mailing lists, see the ":ref:`Mailing
10830 lists <resources-mailinglist>`" section in
10831 the Yocto Project Reference Manual.
10832
108336. *Make a Pull Request:* Notify the maintainer or the mailing list that
10834 you have pushed a change by making a pull request.
10835
10836 The Yocto Project provides two scripts that conveniently let you
10837 generate and send pull requests to the Yocto Project. These scripts
10838 are ``create-pull-request`` and ``send-pull-request``. You can find
10839 these scripts in the ``scripts`` directory within the
10840 :term:`Source Directory` (e.g.
10841 ``~/poky/scripts``).
10842
10843 Using these scripts correctly formats the requests without
10844 introducing any whitespace or HTML formatting. The maintainer that
10845 receives your patches either directly or through the mailing list
10846 needs to be able to save and apply them directly from your emails.
10847 Using these scripts is the preferred method for sending patches.
10848
10849 First, create the pull request. For example, the following command
10850 runs the script, specifies the upstream repository in the contrib
10851 directory into which you pushed the change, and provides a subject
10852 line in the created patch files:
10853 ::
10854
10855 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
10856
10857 Running this script forms ``*.patch`` files in a folder named
10858 ``pull-``\ `PID` in the current directory. One of the patch files is a
10859 cover letter.
10860
10861 Before running the ``send-pull-request`` script, you must edit the
10862 cover letter patch to insert information about your change. After
10863 editing the cover letter, send the pull request. For example, the
10864 following command runs the script and specifies the patch directory
10865 and email address. In this example, the email address is a mailing
10866 list:
10867 ::
10868
10869 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
10870
10871 You need to follow the prompts as the script is interactive.
10872
10873 .. note::
10874
10875 For help on using these scripts, simply provide the ``-h``
10876 argument as follows:
10877 ::
10878
10879 $ poky/scripts/create-pull-request -h
10880 $ poky/scripts/send-pull-request -h
10881
10882
10883.. _submitting-a-patch:
10884
10885Using Email to Submit a Patch
10886~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10887
10888You can submit patches without using the ``create-pull-request`` and
10889``send-pull-request`` scripts described in the previous section.
10890However, keep in mind, the preferred method is to use the scripts.
10891
10892Depending on the components changed, you need to submit the email to a
10893specific mailing list. For some guidance on which mailing list to use,
10894see the `list <#figuring-out-the-mailing-list-to-use>`__ at the
10895beginning of this section. For a description of all the available
10896mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10897Yocto Project Reference Manual.
10898
10899Here is the general procedure on how to submit a patch through email
10900without using the scripts:
10901
109021. *Make Your Changes Locally:* Make your changes in your local Git
10903 repository. You should make small, controlled, isolated changes.
10904 Keeping changes small and isolated aids review, makes
10905 merging/rebasing easier and keeps the change history clean should
10906 anyone need to refer to it in future.
10907
109082. *Stage Your Changes:* Stage your changes by using the ``git add``
10909 command on each file you changed.
10910
109113. *Commit Your Changes:* Commit the change by using the
10912 ``git commit --signoff`` command. Using the ``--signoff`` option
10913 identifies you as the person making the change and also satisfies the
10914 Developer's Certificate of Origin (DCO) shown earlier.
10915
10916 When you form a commit, you must follow certain standards established
10917 by the Yocto Project development team. See :ref:`Step 3
10918 <dev-manual/dev-manual-common-tasks:using scripts to push a change upstream and request a pull>`
10919 in the previous section for information on how to provide commit information
10920 that meets Yocto Project commit message standards.
10921
109224. *Format the Commit:* Format the commit into an email message. To
10923 format commits, use the ``git format-patch`` command. When you
10924 provide the command, you must include a revision list or a number of
10925 patches as part of the command. For example, either of these two
10926 commands takes your most recent single commit and formats it as an
10927 email message in the current directory:
10928 ::
10929
10930 $ git format-patch -1
10931
10932 or ::
10933
10934 $ git format-patch HEAD~
10935
10936 After the command is run, the current directory contains a numbered
10937 ``.patch`` file for the commit.
10938
10939 If you provide several commits as part of the command, the
10940 ``git format-patch`` command produces a series of numbered files in
10941 the current directory – one for each commit. If you have more than
10942 one patch, you should also use the ``--cover`` option with the
10943 command, which generates a cover letter as the first "patch" in the
10944 series. You can then edit the cover letter to provide a description
10945 for the series of patches. For information on the
10946 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10947 using the ``man git-format-patch`` command.
10948
10949 .. note::
10950
10951 If you are or will be a frequent contributor to the Yocto Project
10952 or to OpenEmbedded, you might consider requesting a contrib area
10953 and the necessary associated rights.
10954
109555. *Import the Files Into Your Mail Client:* Import the files into your
10956 mail client by using the ``git send-email`` command.
10957
10958 .. note::
10959
10960 In order to use ``git send-email``, you must have the proper Git packages
10961 installed on your host.
10962 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10963
10964 The ``git send-email`` command sends email by using a local or remote
10965 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10966 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10967 file. If you are submitting patches through email only, it is very
10968 important that you submit them without any whitespace or HTML
10969 formatting that either you or your mailer introduces. The maintainer
10970 that receives your patches needs to be able to save and apply them
10971 directly from your emails. A good way to verify that what you are
10972 sending will be applicable by the maintainer is to do a dry run and
10973 send them to yourself and then save and apply them as the maintainer
10974 would.
10975
10976 The ``git send-email`` command is the preferred method for sending
10977 your patches using email since there is no risk of compromising
10978 whitespace in the body of the message, which can occur when you use
10979 your own mail client. The command also has several options that let
10980 you specify recipients and perform further editing of the email
10981 message. For information on how to use the ``git send-email``
10982 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10983 ``man git-send-email`` command.
10984
10985Working With Licenses
10986=====================
10987
10988As mentioned in the ":ref:`overview-manual/overview-manual-development-environment:licensing`"
10989section in the Yocto Project Overview and Concepts Manual, open source
10990projects are open to the public and they consequently have different
10991licensing structures in place. This section describes the mechanism by
10992which the :term:`OpenEmbedded Build System`
10993tracks changes to
10994licensing text and covers how to maintain open source license compliance
10995during your project's lifecycle. The section also describes how to
10996enable commercially licensed recipes, which by default are disabled.
10997
10998.. _usingpoky-configuring-LIC_FILES_CHKSUM:
10999
11000Tracking License Changes
11001------------------------
11002
11003The license of an upstream project might change in the future. In order
11004to prevent these changes going unnoticed, the
11005:term:`LIC_FILES_CHKSUM`
11006variable tracks changes to the license text. The checksums are validated
11007at the end of the configure step, and if the checksums do not match, the
11008build will fail.
11009
11010.. _usingpoky-specifying-LIC_FILES_CHKSUM:
11011
11012Specifying the ``LIC_FILES_CHKSUM`` Variable
11013~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11014
11015The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
11016in the source code for the recipe. Following is an example of how to
11017specify ``LIC_FILES_CHKSUM``:
11018::
11019
11020 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
11021 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
11022 file://licfile2.txt;endline=50;md5=zzzz \
11023 ..."
11024
11025.. note::
11026
11027 - When using "beginline" and "endline", realize that line numbering
11028 begins with one and not zero. Also, the included lines are
11029 inclusive (i.e. lines five through and including 29 in the
11030 previous example for ``licfile1.txt``).
11031
11032 - When a license check fails, the selected license text is included
11033 as part of the QA message. Using this output, you can determine
11034 the exact start and finish for the needed license text.
11035
11036The build system uses the :term:`S`
11037variable as the default directory when searching files listed in
11038``LIC_FILES_CHKSUM``. The previous example employs the default
11039directory.
11040
11041Consider this next example:
11042::
11043
11044 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
11045 md5=bb14ed3c4cda583abc85401304b5cd4e"
11046 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
11047
11048The first line locates a file in ``${S}/src/ls.c`` and isolates lines
11049five through 16 as license text. The second line refers to a file in
11050:term:`WORKDIR`.
11051
11052Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
11053unless the ``LICENSE`` variable is set to "CLOSED".
11054
11055.. _usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax:
11056
11057Explanation of Syntax
11058~~~~~~~~~~~~~~~~~~~~~
11059
11060As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
11061lists all the important files that contain the license text for the
11062source code. It is possible to specify a checksum for an entire file, or
11063a specific section of a file (specified by beginning and ending line
11064numbers with the "beginline" and "endline" parameters, respectively).
11065The latter is useful for source files with a license notice header,
11066README documents, and so forth. If you do not use the "beginline"
11067parameter, then it is assumed that the text begins on the first line of
11068the file. Similarly, if you do not use the "endline" parameter, it is
11069assumed that the license text ends with the last line of the file.
11070
11071The "md5" parameter stores the md5 checksum of the license text. If the
11072license text changes in any way as compared to this parameter then a
11073mismatch occurs. This mismatch triggers a build failure and notifies the
11074developer. Notification allows the developer to review and address the
11075license text changes. Also note that if a mismatch occurs during the
11076build, the correct md5 checksum is placed in the build log and can be
11077easily copied to the recipe.
11078
11079There is no limit to how many files you can specify using the
11080``LIC_FILES_CHKSUM`` variable. Generally, however, every project
11081requires a few specifications for license tracking. Many projects have a
11082"COPYING" file that stores the license information for all the source
11083code files. This practice allows you to just track the "COPYING" file as
11084long as it is kept up to date.
11085
11086.. note::
11087
11088 - If you specify an empty or invalid "md5" parameter,
11089 :term:`BitBake` returns an md5
11090 mis-match error and displays the correct "md5" parameter value
11091 during the build. The correct parameter is also captured in the
11092 build log.
11093
11094 - If the whole file contains only license text, you do not need to
11095 use the "beginline" and "endline" parameters.
11096
11097Enabling Commercially Licensed Recipes
11098--------------------------------------
11099
11100By default, the OpenEmbedded build system disables components that have
11101commercial or other special licensing requirements. Such requirements
11102are defined on a recipe-by-recipe basis through the
11103:term:`LICENSE_FLAGS` variable
11104definition in the affected recipe. For instance, the
11105``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
11106contains the following statement:
11107::
11108
11109 LICENSE_FLAGS = "commercial"
11110
11111Here is a
11112slightly more complicated example that contains both an explicit recipe
11113name and version (after variable expansion):
11114::
11115
11116 LICENSE_FLAGS = "license_${PN}_${PV}"
11117
11118In order for a component restricted by a
11119``LICENSE_FLAGS`` definition to be enabled and included in an image, it
11120needs to have a matching entry in the global
11121:term:`LICENSE_FLAGS_WHITELIST`
11122variable, which is a variable typically defined in your ``local.conf``
11123file. For example, to enable the
11124``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
11125could add either the string "commercial_gst-plugins-ugly" or the more
11126general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
11127"`License Flag Matching <#license-flag-matching>`__" section for a full
11128explanation of how ``LICENSE_FLAGS`` matching works. Here is the
11129example:
11130::
11131
11132 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
11133
11134Likewise, to additionally enable the package built from the recipe
11135containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11136the actual recipe name was ``emgd_1.10.bb``, the following string would
11137enable that package as well as the original ``gst-plugins-ugly``
11138package:
11139::
11140
11141 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
11142
11143As a convenience, you do not need to specify the
11144complete license string in the whitelist for every package. You can use
11145an abbreviated form, which consists of just the first portion or
11146portions of the license string before the initial underscore character
11147or characters. A partial string will match any license that contains the
11148given string as the first portion of its license. For example, the
11149following whitelist string will also match both of the packages
11150previously mentioned as well as any other packages that have licenses
11151starting with "commercial" or "license".
11152::
11153
11154 LICENSE_FLAGS_WHITELIST = "commercial license"
11155
11156License Flag Matching
11157~~~~~~~~~~~~~~~~~~~~~
11158
11159License flag matching allows you to control what recipes the
11160OpenEmbedded build system includes in the build. Fundamentally, the
11161build system attempts to match ``LICENSE_FLAGS`` strings found in
11162recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
11163whitelist. A match causes the build system to include a recipe in the
11164build, while failure to find a match causes the build system to exclude
11165a recipe.
11166
11167In general, license flag matching is simple. However, understanding some
11168concepts will help you correctly and effectively use matching.
11169
11170Before a flag defined by a particular recipe is tested against the
11171contents of the whitelist, the expanded string ``_${PN}`` is appended to
11172the flag. This expansion makes each ``LICENSE_FLAGS`` value
11173recipe-specific. After expansion, the string is then matched against the
11174whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
11175"foo", for example, results in the string ``"commercial_foo"``. And, to
11176create a match, that string must appear in the whitelist.
11177
11178Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
11179``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
11180including or excluding recipes based on licensing. For example, you can
11181broaden the matching capabilities by using license flags string subsets
11182in the whitelist.
11183
11184.. note::
11185
11186 When using a string subset, be sure to use the part of the expanded
11187 string that precedes the appended underscore character (e.g.
11188 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
11189
11190For example, simply specifying the string "commercial" in the whitelist
11191matches any expanded ``LICENSE_FLAGS`` definition that starts with the
11192string "commercial" such as "commercial_foo" and "commercial_bar", which
11193are the strings the build system automatically generates for
11194hypothetical recipes named "foo" and "bar" assuming those recipes simply
11195specify the following:
11196::
11197
11198 LICENSE_FLAGS = "commercial"
11199
11200Thus, you can choose
11201to exhaustively enumerate each license flag in the whitelist and allow
11202only specific recipes into the image, or you can use a string subset
11203that causes a broader range of matches to allow a range of recipes into
11204the image.
11205
11206This scheme works even if the ``LICENSE_FLAGS`` string already has
11207``_${PN}`` appended. For example, the build system turns the license
11208flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11209both the general "commercial" and the specific "commercial_1.2_foo"
11210strings found in the whitelist, as expected.
11211
11212Here are some other scenarios:
11213
11214- You can specify a versioned string in the recipe such as
11215 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11216 string to "commercial_foo_1.2_foo". Combine this license flag with a
11217 whitelist that has the string "commercial" and you match the flag
11218 along with any other flag that starts with the string "commercial".
11219
11220- Under the same circumstances, you can use "commercial_foo" in the
11221 whitelist and the build system not only matches "commercial_foo_1.2"
11222 but also matches any license flag with the string "commercial_foo",
11223 regardless of the version.
11224
11225- You can be very specific and use both the package and version parts
11226 in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
11227 versioned recipe.
11228
11229Other Variables Related to Commercial Licenses
11230~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11231
11232Other helpful variables related to commercial license handling exist and
11233are defined in the
11234``poky/meta/conf/distro/include/default-distrovars.inc`` file:
11235::
11236
11237 COMMERCIAL_AUDIO_PLUGINS ?= ""
11238 COMMERCIAL_VIDEO_PLUGINS ?= ""
11239
11240If you
11241want to enable these components, you can do so by making sure you have
11242statements similar to the following in your ``local.conf`` configuration
11243file:
11244::
11245
11246 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11247 gst-plugins-ugly-mpegaudioparse"
11248 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11249 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
11250 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
11251
11252
11253Of course, you could also create a matching whitelist for those
11254components using the more general "commercial" in the whitelist, but
11255that would also enable all the other packages with ``LICENSE_FLAGS``
11256containing "commercial", which you may or may not want:
11257::
11258
11259 LICENSE_FLAGS_WHITELIST = "commercial"
11260
11261Specifying audio and video plugins as part of the
11262``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
11263(along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
11264plugins or components into built images, thus adding support for media
11265formats or components.
11266
11267Maintaining Open Source License Compliance During Your Product's Lifecycle
11268--------------------------------------------------------------------------
11269
11270One of the concerns for a development organization using open source
11271software is how to maintain compliance with various open source
11272licensing during the lifecycle of the product. While this section does
11273not provide legal advice or comprehensively cover all scenarios, it does
11274present methods that you can use to assist you in meeting the compliance
11275requirements during a software release.
11276
11277With hundreds of different open source licenses that the Yocto Project
11278tracks, it is difficult to know the requirements of each and every
11279license. However, the requirements of the major FLOSS licenses can begin
11280to be covered by assuming that three main areas of concern exist:
11281
11282- Source code must be provided.
11283
11284- License text for the software must be provided.
11285
11286- Compilation scripts and modifications to the source code must be
11287 provided.
11288
11289There are other requirements beyond the scope of these three and the
11290methods described in this section (e.g. the mechanism through which
11291source code is distributed).
11292
11293As different organizations have different methods of complying with open
11294source licensing, this section is not meant to imply that there is only
11295one single way to meet your compliance obligations, but rather to
11296describe one method of achieving compliance. The remainder of this
11297section describes methods supported to meet the previously mentioned
11298three requirements. Once you take steps to meet these requirements, and
11299prior to releasing images, sources, and the build system, you should
11300audit all artifacts to ensure completeness.
11301
11302.. note::
11303
11304 The Yocto Project generates a license manifest during image creation
11305 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
11306 to assist with any audits.
11307
11308Providing the Source Code
11309~~~~~~~~~~~~~~~~~~~~~~~~~
11310
11311Compliance activities should begin before you generate the final image.
11312The first thing you should look at is the requirement that tops the list
11313for most compliance groups - providing the source. The Yocto Project has
11314a few ways of meeting this requirement.
11315
11316One of the easiest ways to meet this requirement is to provide the
11317entire :term:`DL_DIR` used by the
11318build. This method, however, has a few issues. The most obvious is the
11319size of the directory since it includes all sources used in the build
11320and not just the source used in the released image. It will include
11321toolchain source, and other artifacts, which you would not generally
11322release. However, the more serious issue for most companies is
11323accidental release of proprietary software. The Yocto Project provides
11324an :ref:`archiver <ref-classes-archiver>` class to
11325help avoid some of these concerns.
11326
11327Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
11328decide how you choose to provide source. The source ``archiver`` class
11329can generate tarballs and SRPMs and can create them with various levels
11330of compliance in mind.
11331
11332One way of doing this (but certainly not the only way) is to release
11333just the source as a tarball. You can do this by adding the following to
11334the ``local.conf`` file found in the
11335:term:`Build Directory`:
11336::
11337
11338 INHERIT += "archiver"
11339 ARCHIVER_MODE[src] = "original"
11340
11341During the creation of your
11342image, the source from all recipes that deploy packages to the image is
11343placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11344:term:`LICENSE` for each recipe.
11345Releasing the entire directory enables you to comply with requirements
11346concerning providing the unmodified source. It is important to note that
11347the size of the directory can get large.
11348
11349A way to help mitigate the size issue is to only release tarballs for
11350licenses that require the release of source. Let us assume you are only
11351concerned with GPL code as identified by running the following script:
11352
11353.. code-block:: shell
11354
11355 # Script to archive a subset of packages matching specific license(s)
11356 # Source and license files are copied into sub folders of package folder
11357 # Must be run from build folder
11358 #!/bin/bash
11359 src_release_dir="source-release"
11360 mkdir -p $src_release_dir
11361 for a in tmp/deploy/sources/*; do
11362 for d in $a/*; do
11363 # Get package name from path
11364 p=`basename $d`
11365 p=${p%-*}
11366 p=${p%-*}
11367 # Only archive GPL packages (update *GPL* regex for your license check)
11368 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
11369 if [ $numfiles -gt 1 ]; then
11370 echo Archiving $p
11371 mkdir -p $src_release_dir/$p/source
11372 cp $d/* $src_release_dir/$p/source 2> /dev/null
11373 mkdir -p $src_release_dir/$p/license
11374 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11375 fi
11376 done
11377 done
11378
11379At this point, you
11380could create a tarball from the ``gpl_source_release`` directory and
11381provide that to the end user. This method would be a step toward
11382achieving compliance with section 3a of GPLv2 and with section 6 of
11383GPLv3.
11384
11385Providing License Text
11386~~~~~~~~~~~~~~~~~~~~~~
11387
11388One requirement that is often overlooked is inclusion of license text.
11389This requirement also needs to be dealt with prior to generating the
11390final image. Some licenses require the license text to accompany the
11391binary. You can achieve this by adding the following to your
11392``local.conf`` file:
11393::
11394
11395 COPY_LIC_MANIFEST = "1"
11396 COPY_LIC_DIRS = "1"
11397 LICENSE_CREATE_PACKAGE = "1"
11398
11399Adding these statements to the
11400configuration file ensures that the licenses collected during package
11401generation are included on your image.
11402
11403.. note::
11404
11405 Setting all three variables to "1" results in the image having two
11406 copies of the same license file. One copy resides in
11407 ``/usr/share/common-licenses`` and the other resides in
11408 ``/usr/share/license``.
11409
11410 The reason for this behavior is because
11411 :term:`COPY_LIC_DIRS` and
11412 :term:`COPY_LIC_MANIFEST`
11413 add a copy of the license when the image is built but do not offer a
11414 path for adding licenses for newly installed packages to an image.
11415 :term:`LICENSE_CREATE_PACKAGE`
11416 adds a separate package and an upgrade path for adding licenses to an
11417 image.
11418
11419As the source ``archiver`` class has already archived the original
11420unmodified source that contains the license files, you would have
11421already met the requirements for inclusion of the license information
11422with source as defined by the GPL and other open source licenses.
11423
11424Providing Compilation Scripts and Source Code Modifications
11425~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11426
11427At this point, we have addressed all we need to prior to generating the
11428image. The next two requirements are addressed during the final
11429packaging of the release.
11430
11431By releasing the version of the OpenEmbedded build system and the layers
11432used during the build, you will be providing both compilation scripts
11433and the source code modifications in one step.
11434
11435If the deployment team has a :ref:`overview-manual/overview-manual-concepts:bsp layer`
11436and a distro layer, and those
11437those layers are used to patch, compile, package, or modify (in any way)
11438any open source software included in your released images, you might be
11439required to release those layers under section 3 of GPLv2 or section 1
11440of GPLv3. One way of doing that is with a clean checkout of the version
11441of the Yocto Project and layers used during your build. Here is an
11442example:
11443
11444.. code-block:: shell
11445
11446 # We built using the dunfell branch of the poky repo
11447 $ git clone -b dunfell git://git.yoctoproject.org/poky
11448 $ cd poky
11449 # We built using the release_branch for our layers
11450 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11451 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11452 # clean up the .git repos
11453 $ find . -name ".git" -type d -exec rm -rf {} \;
11454
11455One
11456thing a development organization might want to consider for end-user
11457convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
11458ensure that when the end user utilizes the released build system to
11459build an image, the development organization's layers are included in
11460the ``bblayers.conf`` file automatically:
11461::
11462
11463 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11464 # changes incompatibly
11465 POKY_BBLAYERS_CONF_VERSION = "2"
11466
11467 BBPATH = "${TOPDIR}"
11468 BBFILES ?= ""
11469
11470 BBLAYERS ?= " \
11471 ##OEROOT##/meta \
11472 ##OEROOT##/meta-poky \
11473 ##OEROOT##/meta-yocto-bsp \
11474 ##OEROOT##/meta-mylayer \
11475 "
11476
11477Creating and
11478providing an archive of the :term:`Metadata`
11479layers (recipes, configuration files, and so forth) enables you to meet
11480your requirements to include the scripts to control compilation as well
11481as any modifications to the original source.
11482
11483Copying Licenses that Do Not Exist
11484----------------------------------
11485
11486Some packages, such as the linux-firmware package, have many licenses
11487that are not in any way common. You can avoid adding a lot of these
11488types of common license files, which are only applicable to a specific
11489package, by using the
11490:term:`NO_GENERIC_LICENSE`
11491variable. Using this variable also avoids QA errors when you use a
11492non-common, non-CLOSED license in a recipe.
11493
11494The following is an example that uses the ``LICENSE.Abilis.txt`` file as
11495the license from the fetched source:
11496::
11497
11498 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11499
11500Using the Error Reporting Tool
11501==============================
11502
11503The error reporting tool allows you to submit errors encountered during
11504builds to a central database. Outside of the build environment, you can
11505use a web interface to browse errors, view statistics, and query for
11506errors. The tool works using a client-server system where the client
11507portion is integrated with the installed Yocto Project
11508:term:`Source Directory` (e.g. ``poky``).
11509The server receives the information collected and saves it in a
11510database.
11511
11512A live instance of the error reporting server exists at
11513https://errors.yoctoproject.org. This server exists so that when
11514you want to get help with build failures, you can submit all of the
11515information on the failure easily and then point to the URL in your bug
11516report or send an email to the mailing list.
11517
11518.. note::
11519
11520 If you send error reports to this server, the reports become publicly
11521 visible.
11522
11523Enabling and Using the Tool
11524---------------------------
11525
11526By default, the error reporting tool is disabled. You can enable it by
11527inheriting the
11528:ref:`report-error <ref-classes-report-error>`
11529class by adding the following statement to the end of your
11530``local.conf`` file in your
11531:term:`Build Directory`.
11532::
11533
11534 INHERIT += "report-error"
11535
11536By default, the error reporting feature stores information in
11537``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11538However, you can specify a directory to use by adding the following to
11539your ``local.conf`` file:
11540::
11541
11542 ERR_REPORT_DIR = "path"
11543
11544Enabling error
11545reporting causes the build process to collect the errors and store them
11546in a file as previously described. When the build system encounters an
11547error, it includes a command as part of the console output. You can run
11548the command to send the error file to the server. For example, the
11549following command sends the errors to an upstream server:
11550::
11551
11552 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11553
11554In the previous example, the errors are sent to a public database
11555available at https://errors.yoctoproject.org, which is used by the
11556entire community. If you specify a particular server, you can send the
11557errors to a different database. Use the following command for more
11558information on available options:
11559::
11560
11561 $ send-error-report --help
11562
11563When sending the error file, you are prompted to review the data being
11564sent as well as to provide a name and optional email address. Once you
11565satisfy these prompts, the command returns a link from the server that
11566corresponds to your entry in the database. For example, here is a
11567typical link: https://errors.yoctoproject.org/Errors/Details/9522/
11568
11569Following the link takes you to a web interface where you can browse,
11570query the errors, and view statistics.
11571
11572Disabling the Tool
11573------------------
11574
11575To disable the error reporting feature, simply remove or comment out the
11576following statement from the end of your ``local.conf`` file in your
11577:term:`Build Directory`.
11578::
11579
11580 INHERIT += "report-error"
11581
11582Setting Up Your Own Error Reporting Server
11583------------------------------------------
11584
11585If you want to set up your own error reporting server, you can obtain
11586the code from the Git repository at :yocto_git:`/cgit/cgit.cgi/error-report-web/`.
11587Instructions on how to set it up are in the README document.
11588
11589.. _dev-using-wayland-and-weston:
11590
11591Using Wayland and Weston
11592========================
11593
11594`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
11595is a computer display server protocol that provides a method for
11596compositing window managers to communicate directly with applications
11597and video hardware and expects them to communicate with input hardware
11598using other libraries. Using Wayland with supporting targets can result
11599in better control over graphics frame rendering than an application
11600might otherwise achieve.
11601
11602The Yocto Project provides the Wayland protocol libraries and the
11603reference
11604`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
11605compositor as part of its release. You can find the integrated packages
11606in the ``meta`` layer of the :term:`Source Directory`.
11607Specifically, you
11608can find the recipes that build both Wayland and Weston at
11609``meta/recipes-graphics/wayland``.
11610
11611You can build both the Wayland and Weston packages for use only with
11612targets that accept the `Mesa 3D and Direct Rendering
11613Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11614which is also known as Mesa DRI. This implies that you cannot build and
11615use the packages if your target uses, for example, the Intel Embedded
11616Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11617
11618.. note::
11619
11620 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11621 emulated QEMU hardware. However, this version of Weston will run
11622 under X emulation without issues.
11623
11624This section describes what you need to do to implement Wayland and use
11625the Weston compositor when building an image for a supporting target.
11626
11627Enabling Wayland in an Image
11628----------------------------
11629
11630To enable Wayland, you need to enable it to be built and enable it to be
11631included (installed) in the image.
11632
11633.. _enable-building:
11634
11635Building Wayland
11636~~~~~~~~~~~~~~~~
11637
11638To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11639Wayland with Kernel Mode Setting
11640(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11641support, include the "wayland" flag in the
11642:term:`DISTRO_FEATURES`
11643statement in your ``local.conf`` file:
11644::
11645
11646 DISTRO_FEATURES_append = " wayland"
11647
11648.. note::
11649
11650 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11651 support
11652
11653.. _enable-installation-in-an-image:
11654
11655Installing Wayland and Weston
11656~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11657
11658To install the Wayland feature into an image, you must include the
11659following
11660:term:`CORE_IMAGE_EXTRA_INSTALL`
11661statement in your ``local.conf`` file:
11662::
11663
11664 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11665
11666Running Weston
11667--------------
11668
11669To run Weston inside X11, enabling it as described earlier and building
11670a Sato image is sufficient. If you are running your image under Sato, a
11671Weston Launcher appears in the "Utility" category.
11672
11673Alternatively, you can run Weston through the command-line interpretor
11674(CLI), which is better suited for development work. To run Weston under
11675the CLI, you need to do the following after your image is built:
11676
116771. Run these commands to export ``XDG_RUNTIME_DIR``:
11678 ::
11679
11680 mkdir -p /tmp/$USER-weston
11681 chmod 0700 /tmp/$USER-weston
11682 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11683
116842. Launch Weston in the shell:
11685 ::
11686
11687 weston